1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine code, use decoder to parse flv stream

This commit is contained in:
winlin 2015-05-04 18:28:41 +08:00
parent ea1e015a4e
commit ba6c3132e3
3 changed files with 112 additions and 0 deletions

View file

@ -36,6 +36,7 @@ using namespace std;
#include <srs_app_http.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_flv.hpp>
#define SRS_HTTP_FLV_STREAM_BUFFER 4096
@ -92,6 +93,13 @@ int SrsAppCasterFlv::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
SrsAutoFree(char, buffer);
ISrsHttpResponseReader* rr = r->body_reader();
SrsHttpFileReader reader(rr);
SrsFlvDecoder dec;
if ((ret = dec.initialize(&reader)) != ERROR_SUCCESS) {
return ret;
}
while (!rr->eof()) {
int nb_read = 0;
if ((ret = rr->read(buffer, SRS_HTTP_FLV_STREAM_BUFFER, &nb_read)) != ERROR_SUCCESS) {
@ -118,4 +126,68 @@ int SrsDynamicHttpConn::on_got_http_message(SrsHttpMessage* msg)
return ret;
}
SrsHttpFileReader::SrsHttpFileReader(ISrsHttpResponseReader* h)
{
http = h;
}
SrsHttpFileReader::~SrsHttpFileReader()
{
}
int SrsHttpFileReader::open(std::string /*file*/)
{
return ERROR_SUCCESS;
}
void SrsHttpFileReader::close()
{
}
bool SrsHttpFileReader::is_open()
{
return false;
}
int64_t SrsHttpFileReader::tellg()
{
return 0;
}
void SrsHttpFileReader::skip(int64_t /*size*/)
{
}
int64_t SrsHttpFileReader::lseek(int64_t offset)
{
return offset;
}
int64_t SrsHttpFileReader::filesize()
{
return 0;
}
int SrsHttpFileReader::read(void* buf, size_t count, ssize_t* pnread)
{
int ret = ERROR_SUCCESS;
if (http->eof()) {
ret = ERROR_HTTP_REQUEST_EOF;
srs_error("flv: encoder EOF. ret=%d", ret);
return ret;
}
int nread = 0;
if ((ret = http->read((char*)buf, (int)count, &nread)) != ERROR_SUCCESS) {
return ret;
}
if (pnread) {
*pnread = nread;
}
return ret;
}
#endif