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

complete the normal kernel flv utest. 0.9.147

This commit is contained in:
winlin 2014-07-05 11:10:42 +08:00
parent 010eb09a30
commit d219a7b67e
11 changed files with 691 additions and 172 deletions

View file

@ -119,8 +119,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_SYSTEM_FILE_RENAME 429
#define ERROR_SYSTEM_CREATE_PIPE 430
#define ERROR_SYSTEM_FILE_SEEK 431
#define ERROR_SYSTEM_FLV_HEADER 432
#define ERROR_SYSTEM_IO_INVALID 433
#define ERROR_SYSTEM_IO_INVALID 432
// see librtmp.
// failed when open ssl create the dh
@ -189,12 +188,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_HTTP_FLV_SEQUENCE_HEADER 806
#define ERROR_HTTP_FLV_OFFSET_OVERFLOW 807
#define ERROR_KERNEL_FLV_HEADER 900
#define ERROR_KERNEL_FLV_STREAM_CLOSED 901
// system control message,
// not an error, but special control logic.
// sys ctl: rtmp close stream, support replay.
#define ERROR_CONTROL_RTMP_CLOSE 900
#define ERROR_CONTROL_RTMP_CLOSE 2000
// FMLE stop publish and republish.
#define ERROR_CONTROL_REPUBLISH 901
#define ERROR_CONTROL_REPUBLISH 2001
/**
* whether the error code is an system control error.

View file

@ -53,6 +53,12 @@ int SrsFlvEncoder::initialize(SrsFileWriter* fs)
{
int ret = ERROR_SUCCESS;
if (!fs->is_open()) {
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
srs_warn("stream is not open for decoder. ret=%d", ret);
return ret;
}
_fs = fs;
return ret;
@ -92,7 +98,7 @@ int SrsFlvEncoder::write_header(char flv_header[9])
return ret;
}
char pts[] = { 0x00, 0x00, 0x00, 0x00 };
char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)0x00 };
if ((ret = _fs->write(pts, 4, NULL)) != ERROR_SUCCESS) {
return ret;
}
@ -104,6 +110,7 @@ int SrsFlvEncoder::write_metadata(char* data, int size)
{
int ret = ERROR_SUCCESS;
// 11 bytes tag header
static char tag_header[] = {
(char)18, // TagType UB [5], 18 = script data
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
@ -240,6 +247,12 @@ int SrsFlvDecoder::initialize(SrsFileReader* fs)
{
int ret = ERROR_SUCCESS;
if (!fs->is_open()) {
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
srs_warn("stream is not open for decoder. ret=%d", ret);
return ret;
}
_fs = fs;
return ret;
@ -255,7 +268,7 @@ int SrsFlvDecoder::read_header(char header[9])
char* h = header;
if (h[0] != 'F' || h[1] != 'L' || h[2] != 'V') {
ret = ERROR_SYSTEM_FLV_HEADER;
ret = ERROR_KERNEL_FLV_HEADER;
srs_warn("flv header must start with FLV. ret=%d", ret);
return ret;
}
@ -345,35 +358,37 @@ int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fs)
{
int ret = ERROR_SUCCESS;
if (!fs->is_open()) {
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
srs_warn("stream is not open for decoder. ret=%d", ret);
return ret;
}
_fs = fs;
return ret;
}
int SrsFlvVodStreamDecoder::read_header(char** pdata, int* psize)
int SrsFlvVodStreamDecoder::read_header_ext(char header[13])
{
*pdata = NULL;
*psize = 0;
int ret = ERROR_SUCCESS;
srs_assert(_fs);
// @remark, always false, for sizeof(char[13]) equals to sizeof(char*)
//srs_assert(13 == sizeof(header));
// 9bytes header and 4bytes first previous-tag-size
int size = 13;
char* buf = new char[size];
if ((ret = _fs->read(buf, size, NULL)) != ERROR_SUCCESS) {
if ((ret = _fs->read(header, size, NULL)) != ERROR_SUCCESS) {
return ret;
}
*pdata = buf;
*psize = size;
return ret;
}
int SrsFlvVodStreamDecoder::read_sequence_header(int64_t* pstart, int* psize)
int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* psize)
{
*pstart = 0;
*psize = 0;

View file

@ -66,7 +66,7 @@ public:
virtual int write_header(char flv_header[9]);
/**
* write flv metadata.
* serialize from:
* @param data, the amf0 metadata which serialize from:
* AMF0 string: onMetaData,
* AMF0 object: the metadata object.
*/
@ -76,6 +76,7 @@ public:
*/
virtual int write_audio(int64_t timestamp, char* data, int size);
virtual int write_video(int64_t timestamp, char* data, int size);
public:
/**
* get the tag size,
* including the tag header, body, and 4bytes previous tag size.
@ -134,13 +135,17 @@ public:
virtual int initialize(SrsFileReader* fs);
public:
/**
* read the flv header and size.
* read the flv header and its size.
* @param header, fill it 13bytes(9bytes header, 4bytes previous tag size).
*/
virtual int read_header(char** pdata, int* psize);
virtual int read_header_ext(char header[13]);
/**
* read the sequence header and size.
* read the sequence header tags offset and its size.
* @param pstart, the start offset of sequence header.
* @param psize, output the size, (tag header)+(tag body)+(4bytes previous tag size).
* @remark we think the first audio/video is sequence header.
*/
virtual int read_sequence_header(int64_t* pstart, int* psize);
virtual int read_sequence_header_summary(int64_t* pstart, int* psize);
public:
/**
* for start offset, seed to this position and response flv stream.