正在显示
2 个修改的文件
包含
18 行增加
和
12 行删除
| @@ -38,9 +38,6 @@ using namespace std; | @@ -38,9 +38,6 @@ using namespace std; | ||
| 38 | #include <srs_kernel_file.hpp> | 38 | #include <srs_kernel_file.hpp> |
| 39 | #include <srs_kernel_codec.hpp> | 39 | #include <srs_kernel_codec.hpp> |
| 40 | 40 | ||
| 41 | -#define SRS_FLV_TAG_HEADER_SIZE 11 | ||
| 42 | -#define SRS_FLV_PREVIOUS_TAG_SIZE 4 | ||
| 43 | - | ||
| 44 | SrsFlvEncoder::SrsFlvEncoder() | 41 | SrsFlvEncoder::SrsFlvEncoder() |
| 45 | { | 42 | { |
| 46 | _fs = NULL; | 43 | _fs = NULL; |
| @@ -119,19 +116,22 @@ int SrsFlvEncoder::write_metadata(char type, char* data, int size) | @@ -119,19 +116,22 @@ int SrsFlvEncoder::write_metadata(char type, char* data, int size) | ||
| 119 | srs_assert(data); | 116 | srs_assert(data); |
| 120 | 117 | ||
| 121 | // 11 bytes tag header | 118 | // 11 bytes tag header |
| 122 | - char tag_header[] = { | 119 | + /*char tag_header[] = { |
| 123 | (char)type, // TagType UB [5], 18 = script data | 120 | (char)type, // TagType UB [5], 18 = script data |
| 124 | (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. | 121 | (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. |
| 125 | (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. | 122 | (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. |
| 126 | (char)0x00, // TimestampExtended UI8 | 123 | (char)0x00, // TimestampExtended UI8 |
| 127 | (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. | 124 | (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. |
| 128 | - }; | 125 | + };*/ |
| 129 | 126 | ||
| 130 | // write data size. | 127 | // write data size. |
| 131 | - if ((ret = tag_stream->initialize(tag_header + 1, 3)) != ERROR_SUCCESS) { | 128 | + if ((ret = tag_stream->initialize(tag_header, 8)) != ERROR_SUCCESS) { |
| 132 | return ret; | 129 | return ret; |
| 133 | } | 130 | } |
| 131 | + tag_stream->write_1bytes(type); | ||
| 134 | tag_stream->write_3bytes(size); | 132 | tag_stream->write_3bytes(size); |
| 133 | + tag_stream->write_3bytes(0x00); | ||
| 134 | + tag_stream->write_1bytes(0x00); | ||
| 135 | 135 | ||
| 136 | if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) { | 136 | if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) { |
| 137 | if (!srs_is_client_gracefully_close(ret)) { | 137 | if (!srs_is_client_gracefully_close(ret)) { |
| @@ -152,18 +152,19 @@ int SrsFlvEncoder::write_audio(int64_t timestamp, char* data, int size) | @@ -152,18 +152,19 @@ int SrsFlvEncoder::write_audio(int64_t timestamp, char* data, int size) | ||
| 152 | timestamp &= 0x7fffffff; | 152 | timestamp &= 0x7fffffff; |
| 153 | 153 | ||
| 154 | // 11bytes tag header | 154 | // 11bytes tag header |
| 155 | - char tag_header[] = { | 155 | + /*char tag_header[] = { |
| 156 | (char)SrsCodecFlvTagAudio, // TagType UB [5], 8 = audio | 156 | (char)SrsCodecFlvTagAudio, // TagType UB [5], 8 = audio |
| 157 | (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. | 157 | (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. |
| 158 | (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. | 158 | (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. |
| 159 | (char)0x00, // TimestampExtended UI8 | 159 | (char)0x00, // TimestampExtended UI8 |
| 160 | (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. | 160 | (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. |
| 161 | - }; | 161 | + };*/ |
| 162 | 162 | ||
| 163 | // write data size. | 163 | // write data size. |
| 164 | - if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) { | 164 | + if ((ret = tag_stream->initialize(tag_header, 8)) != ERROR_SUCCESS) { |
| 165 | return ret; | 165 | return ret; |
| 166 | } | 166 | } |
| 167 | + tag_stream->write_1bytes(SrsCodecFlvTagAudio); | ||
| 167 | tag_stream->write_3bytes(size); | 168 | tag_stream->write_3bytes(size); |
| 168 | tag_stream->write_3bytes((int32_t)timestamp); | 169 | tag_stream->write_3bytes((int32_t)timestamp); |
| 169 | // default to little-endian | 170 | // default to little-endian |
| @@ -188,18 +189,19 @@ int SrsFlvEncoder::write_video(int64_t timestamp, char* data, int size) | @@ -188,18 +189,19 @@ int SrsFlvEncoder::write_video(int64_t timestamp, char* data, int size) | ||
| 188 | timestamp &= 0x7fffffff; | 189 | timestamp &= 0x7fffffff; |
| 189 | 190 | ||
| 190 | // 11bytes tag header | 191 | // 11bytes tag header |
| 191 | - char tag_header[] = { | 192 | + /*char tag_header[] = { |
| 192 | (char)SrsCodecFlvTagVideo, // TagType UB [5], 9 = video | 193 | (char)SrsCodecFlvTagVideo, // TagType UB [5], 9 = video |
| 193 | (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. | 194 | (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. |
| 194 | (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. | 195 | (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. |
| 195 | (char)0x00, // TimestampExtended UI8 | 196 | (char)0x00, // TimestampExtended UI8 |
| 196 | (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. | 197 | (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. |
| 197 | - }; | 198 | + };*/ |
| 198 | 199 | ||
| 199 | // write data size. | 200 | // write data size. |
| 200 | - if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) { | 201 | + if ((ret = tag_stream->initialize(tag_header, 8)) != ERROR_SUCCESS) { |
| 201 | return ret; | 202 | return ret; |
| 202 | } | 203 | } |
| 204 | + tag_stream->write_1bytes(SrsCodecFlvTagVideo); | ||
| 203 | tag_stream->write_3bytes(size); | 205 | tag_stream->write_3bytes(size); |
| 204 | tag_stream->write_3bytes((int32_t)timestamp); | 206 | tag_stream->write_3bytes((int32_t)timestamp); |
| 205 | // default to little-endian | 207 | // default to little-endian |
| @@ -35,6 +35,9 @@ class SrsStream; | @@ -35,6 +35,9 @@ class SrsStream; | ||
| 35 | class SrsFileWriter; | 35 | class SrsFileWriter; |
| 36 | class SrsFileReader; | 36 | class SrsFileReader; |
| 37 | 37 | ||
| 38 | +#define SRS_FLV_TAG_HEADER_SIZE 11 | ||
| 39 | +#define SRS_FLV_PREVIOUS_TAG_SIZE 4 | ||
| 40 | + | ||
| 38 | /** | 41 | /** |
| 39 | * encode data to flv file. | 42 | * encode data to flv file. |
| 40 | */ | 43 | */ |
| @@ -44,6 +47,7 @@ private: | @@ -44,6 +47,7 @@ private: | ||
| 44 | SrsFileWriter* _fs; | 47 | SrsFileWriter* _fs; |
| 45 | private: | 48 | private: |
| 46 | SrsStream* tag_stream; | 49 | SrsStream* tag_stream; |
| 50 | + char tag_header[SRS_FLV_TAG_HEADER_SIZE]; | ||
| 47 | public: | 51 | public: |
| 48 | SrsFlvEncoder(); | 52 | SrsFlvEncoder(); |
| 49 | virtual ~SrsFlvEncoder(); | 53 | virtual ~SrsFlvEncoder(); |
-
请 注册 或 登录 后发表评论