From 8a9dbaefb790f2e780e6d6dcf42f6745c8be5795 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 24 May 2015 23:16:56 +0800 Subject: [PATCH] use cache for flv tag header. --- trunk/src/kernel/srs_kernel_flv.cpp | 26 ++++++++++++++------------ trunk/src/kernel/srs_kernel_flv.hpp | 4 ++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/trunk/src/kernel/srs_kernel_flv.cpp b/trunk/src/kernel/srs_kernel_flv.cpp index 04602845b..b0b4bd04f 100644 --- a/trunk/src/kernel/srs_kernel_flv.cpp +++ b/trunk/src/kernel/srs_kernel_flv.cpp @@ -38,9 +38,6 @@ using namespace std; #include #include -#define SRS_FLV_TAG_HEADER_SIZE 11 -#define SRS_FLV_PREVIOUS_TAG_SIZE 4 - SrsFlvEncoder::SrsFlvEncoder() { _fs = NULL; @@ -119,19 +116,22 @@ int SrsFlvEncoder::write_metadata(char type, char* data, int size) srs_assert(data); // 11 bytes tag header - char tag_header[] = { + /*char tag_header[] = { (char)type, // TagType UB [5], 18 = script data (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. (char)0x00, // TimestampExtended UI8 (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. - }; + };*/ // write data size. - if ((ret = tag_stream->initialize(tag_header + 1, 3)) != ERROR_SUCCESS) { + if ((ret = tag_stream->initialize(tag_header, 8)) != ERROR_SUCCESS) { return ret; } + tag_stream->write_1bytes(type); tag_stream->write_3bytes(size); + tag_stream->write_3bytes(0x00); + tag_stream->write_1bytes(0x00); if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) { if (!srs_is_client_gracefully_close(ret)) { @@ -152,18 +152,19 @@ int SrsFlvEncoder::write_audio(int64_t timestamp, char* data, int size) timestamp &= 0x7fffffff; // 11bytes tag header - char tag_header[] = { + /*char tag_header[] = { (char)SrsCodecFlvTagAudio, // TagType UB [5], 8 = audio (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. (char)0x00, // TimestampExtended UI8 (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. - }; + };*/ // write data size. - if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) { + if ((ret = tag_stream->initialize(tag_header, 8)) != ERROR_SUCCESS) { return ret; } + tag_stream->write_1bytes(SrsCodecFlvTagAudio); tag_stream->write_3bytes(size); tag_stream->write_3bytes((int32_t)timestamp); // default to little-endian @@ -188,18 +189,19 @@ int SrsFlvEncoder::write_video(int64_t timestamp, char* data, int size) timestamp &= 0x7fffffff; // 11bytes tag header - char tag_header[] = { + /*char tag_header[] = { (char)SrsCodecFlvTagVideo, // TagType UB [5], 9 = video (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. (char)0x00, // TimestampExtended UI8 (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. - }; + };*/ // write data size. - if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) { + if ((ret = tag_stream->initialize(tag_header, 8)) != ERROR_SUCCESS) { return ret; } + tag_stream->write_1bytes(SrsCodecFlvTagVideo); tag_stream->write_3bytes(size); tag_stream->write_3bytes((int32_t)timestamp); // default to little-endian diff --git a/trunk/src/kernel/srs_kernel_flv.hpp b/trunk/src/kernel/srs_kernel_flv.hpp index e3564f7db..848d247c7 100644 --- a/trunk/src/kernel/srs_kernel_flv.hpp +++ b/trunk/src/kernel/srs_kernel_flv.hpp @@ -35,6 +35,9 @@ class SrsStream; class SrsFileWriter; class SrsFileReader; +#define SRS_FLV_TAG_HEADER_SIZE 11 +#define SRS_FLV_PREVIOUS_TAG_SIZE 4 + /** * encode data to flv file. */ @@ -44,6 +47,7 @@ private: SrsFileWriter* _fs; private: SrsStream* tag_stream; + char tag_header[SRS_FLV_TAG_HEADER_SIZE]; public: SrsFlvEncoder(); virtual ~SrsFlvEncoder();