mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add assert to flv.
This commit is contained in:
parent
034120c668
commit
1e395e7c10
3 changed files with 214 additions and 10 deletions
|
@ -53,6 +53,8 @@ int SrsFlvEncoder::initialize(SrsFileWriter* fs)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(fs);
|
||||
|
||||
if (!fs->is_open()) {
|
||||
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
|
||||
srs_warn("stream is not open for decoder. ret=%d", ret);
|
||||
|
@ -110,6 +112,8 @@ int SrsFlvEncoder::write_metadata(char* data, int size)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(data);
|
||||
|
||||
// 11 bytes tag header
|
||||
static char tag_header[] = {
|
||||
(char)18, // TagType UB [5], 18 = script data
|
||||
|
@ -137,6 +141,8 @@ int SrsFlvEncoder::write_audio(int64_t timestamp, char* data, int size)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(data);
|
||||
|
||||
timestamp &= 0x7fffffff;
|
||||
|
||||
// 11bytes tag header
|
||||
|
@ -169,6 +175,8 @@ int SrsFlvEncoder::write_video(int64_t timestamp, char* data, int size)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(data);
|
||||
|
||||
timestamp &= 0x7fffffff;
|
||||
|
||||
// 11bytes tag header
|
||||
|
@ -199,6 +207,7 @@ int SrsFlvEncoder::write_video(int64_t timestamp, char* data, int size)
|
|||
|
||||
int SrsFlvEncoder::size_tag(int data_size)
|
||||
{
|
||||
srs_assert(data_size >= 0);
|
||||
return SRS_FLV_TAG_HEADER_SIZE + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
|
||||
}
|
||||
|
||||
|
@ -247,6 +256,8 @@ int SrsFlvDecoder::initialize(SrsFileReader* fs)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(fs);
|
||||
|
||||
if (!fs->is_open()) {
|
||||
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
|
||||
srs_warn("stream is not open for decoder. ret=%d", ret);
|
||||
|
@ -262,6 +273,8 @@ int SrsFlvDecoder::read_header(char header[9])
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(header);
|
||||
|
||||
if ((ret = _fs->read(header, 9, NULL)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -280,6 +293,10 @@ int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t*
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(ptype);
|
||||
srs_assert(pdata_size);
|
||||
srs_assert(ptime);
|
||||
|
||||
char th[11]; // tag header
|
||||
|
||||
// read tag header
|
||||
|
@ -316,6 +333,8 @@ int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t*
|
|||
int SrsFlvDecoder::read_tag_data(char* data, int32_t size)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(data);
|
||||
|
||||
if ((ret = _fs->read(data, size, NULL)) != ERROR_SUCCESS) {
|
||||
if (ret != ERROR_SYSTEM_FILE_EOF) {
|
||||
|
@ -328,12 +347,14 @@ int SrsFlvDecoder::read_tag_data(char* data, int32_t size)
|
|||
|
||||
}
|
||||
|
||||
int SrsFlvDecoder::read_previous_tag_size(char ts[4])
|
||||
int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4])
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(previous_tag_size);
|
||||
|
||||
// ignore 4bytes tag size.
|
||||
if ((ret = _fs->read(ts, 4, NULL)) != ERROR_SUCCESS) {
|
||||
if ((ret = _fs->read(previous_tag_size, 4, NULL)) != ERROR_SUCCESS) {
|
||||
if (ret != ERROR_SYSTEM_FILE_EOF) {
|
||||
srs_error("read flv previous tag size failed. ret=%d", ret);
|
||||
}
|
||||
|
@ -358,6 +379,8 @@ int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fs)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(fs);
|
||||
|
||||
if (!fs->is_open()) {
|
||||
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
|
||||
srs_warn("stream is not open for decoder. ret=%d", ret);
|
||||
|
@ -373,7 +396,7 @@ int SrsFlvVodStreamDecoder::read_header_ext(char header[13])
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(_fs);
|
||||
srs_assert(header);
|
||||
|
||||
// @remark, always false, for sizeof(char[13]) equals to sizeof(char*)
|
||||
//srs_assert(13 == sizeof(header));
|
||||
|
@ -390,12 +413,10 @@ int SrsFlvVodStreamDecoder::read_header_ext(char header[13])
|
|||
|
||||
int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* psize)
|
||||
{
|
||||
*pstart = 0;
|
||||
*psize = 0;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(_fs);
|
||||
srs_assert(pstart);
|
||||
srs_assert(psize);
|
||||
|
||||
// simply, the first video/audio must be the sequence header.
|
||||
// and must be a sequence video and audio.
|
||||
|
@ -484,8 +505,6 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
|
|||
int SrsFlvVodStreamDecoder::lseek(int64_t offset)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(_fs);
|
||||
|
||||
if (offset >= _fs->filesize()) {
|
||||
ret = ERROR_SYSTEM_FILE_EOF;
|
||||
|
|
|
@ -69,10 +69,12 @@ public:
|
|||
* @param data, the amf0 metadata which serialize from:
|
||||
* AMF0 string: onMetaData,
|
||||
* AMF0 object: the metadata object.
|
||||
* @remark assert data is not NULL.
|
||||
*/
|
||||
virtual int write_metadata(char* data, int size);
|
||||
/**
|
||||
* write audio/video packet.
|
||||
* @remark assert data is not NULL.
|
||||
*/
|
||||
virtual int write_audio(int64_t timestamp, char* data, int size);
|
||||
virtual int write_video(int64_t timestamp, char* data, int size);
|
||||
|
@ -80,6 +82,7 @@ public:
|
|||
/**
|
||||
* get the tag size,
|
||||
* including the tag header, body, and 4bytes previous tag size.
|
||||
* @remark assert data_size is not negative.
|
||||
*/
|
||||
static int size_tag(int data_size);
|
||||
private:
|
||||
|
@ -106,10 +109,26 @@ public:
|
|||
*/
|
||||
virtual int initialize(SrsFileReader* fs);
|
||||
public:
|
||||
/**
|
||||
* read the flv header, donot including the 4bytes previous tag size.
|
||||
* @remark assert header not NULL.
|
||||
*/
|
||||
virtual int read_header(char header[9]);
|
||||
/**
|
||||
* read the tag header infos.
|
||||
* @remark assert ptype/pdata_size/ptime not NULL.
|
||||
*/
|
||||
virtual int read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* ptime);
|
||||
/**
|
||||
* read the tag data.
|
||||
* @remark assert data not NULL.
|
||||
*/
|
||||
virtual int read_tag_data(char* data, int32_t size);
|
||||
virtual int read_previous_tag_size(char ts[4]);
|
||||
/**
|
||||
* read the 4bytes previous tag size.
|
||||
* @remark assert previous_tag_size not NULL.
|
||||
*/
|
||||
virtual int read_previous_tag_size(char previous_tag_size[4]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -137,6 +156,7 @@ public:
|
|||
/**
|
||||
* read the flv header and its size.
|
||||
* @param header, fill it 13bytes(9bytes header, 4bytes previous tag size).
|
||||
* @remark assert header not NULL.
|
||||
*/
|
||||
virtual int read_header_ext(char header[13]);
|
||||
/**
|
||||
|
@ -144,6 +164,7 @@ public:
|
|||
* @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.
|
||||
* @remark assert pstart/psize not NULL.
|
||||
*/
|
||||
virtual int read_sequence_header_summary(int64_t* pstart, int* psize);
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue