refine flv codec, rename fast encoder to flv vod stream decoder
正在显示
4 个修改的文件
包含
238 行增加
和
225 行删除
@@ -304,7 +304,7 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string | @@ -304,7 +304,7 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string | ||
304 | return ret; | 304 | return ret; |
305 | } | 305 | } |
306 | 306 | ||
307 | - SrsFlvFastDecoder ffd; | 307 | + SrsFlvVodStreamDecoder ffd; |
308 | 308 | ||
309 | // open fast decoder | 309 | // open fast decoder |
310 | if ((ret = ffd.initialize(&fs)) != ERROR_SUCCESS) { | 310 | if ((ret = ffd.initialize(&fs)) != ERROR_SUCCESS) { |
@@ -225,18 +225,123 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s | @@ -225,18 +225,123 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s | ||
225 | return ret; | 225 | return ret; |
226 | } | 226 | } |
227 | 227 | ||
228 | -SrsFlvFastDecoder::SrsFlvFastDecoder() | 228 | +SrsFlvDecoder::SrsFlvDecoder() |
229 | +{ | ||
230 | + _fs = NULL; | ||
231 | + tag_stream = new SrsStream(); | ||
232 | +} | ||
233 | + | ||
234 | +SrsFlvDecoder::~SrsFlvDecoder() | ||
235 | +{ | ||
236 | + srs_freep(tag_stream); | ||
237 | +} | ||
238 | + | ||
239 | +int SrsFlvDecoder::initialize(SrsFileReader* fs) | ||
240 | +{ | ||
241 | + int ret = ERROR_SUCCESS; | ||
242 | + | ||
243 | + _fs = fs; | ||
244 | + | ||
245 | + return ret; | ||
246 | +} | ||
247 | + | ||
248 | +int SrsFlvDecoder::read_header(char header[9]) | ||
249 | +{ | ||
250 | + int ret = ERROR_SUCCESS; | ||
251 | + | ||
252 | + if ((ret = _fs->read(header, 9, NULL)) != ERROR_SUCCESS) { | ||
253 | + return ret; | ||
254 | + } | ||
255 | + | ||
256 | + char* h = header; | ||
257 | + if (h[0] != 'F' || h[1] != 'L' || h[2] != 'V') { | ||
258 | + ret = ERROR_SYSTEM_FLV_HEADER; | ||
259 | + srs_warn("flv header must start with FLV. ret=%d", ret); | ||
260 | + return ret; | ||
261 | + } | ||
262 | + | ||
263 | + return ret; | ||
264 | +} | ||
265 | + | ||
266 | +int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* ptime) | ||
267 | +{ | ||
268 | + int ret = ERROR_SUCCESS; | ||
269 | + | ||
270 | + char th[11]; // tag header | ||
271 | + | ||
272 | + // read tag header | ||
273 | + if ((ret = _fs->read(th, 11, NULL)) != ERROR_SUCCESS) { | ||
274 | + if (ret != ERROR_SYSTEM_FILE_EOF) { | ||
275 | + srs_error("read flv tag header failed. ret=%d", ret); | ||
276 | + } | ||
277 | + return ret; | ||
278 | + } | ||
279 | + | ||
280 | + // Reserved UB [2] | ||
281 | + // Filter UB [1] | ||
282 | + // TagType UB [5] | ||
283 | + *ptype = (int)(th[0] & 0x1F); | ||
284 | + | ||
285 | + // DataSize UI24 | ||
286 | + char* pp = (char*)pdata_size; | ||
287 | + pp[2] = th[1]; | ||
288 | + pp[1] = th[2]; | ||
289 | + pp[0] = th[3]; | ||
290 | + | ||
291 | + // Timestamp UI24 | ||
292 | + pp = (char*)ptime; | ||
293 | + pp[2] = th[4]; | ||
294 | + pp[1] = th[5]; | ||
295 | + pp[0] = th[6]; | ||
296 | + | ||
297 | + // TimestampExtended UI8 | ||
298 | + pp[3] = th[7]; | ||
299 | + | ||
300 | + return ret; | ||
301 | +} | ||
302 | + | ||
303 | +int SrsFlvDecoder::read_tag_data(char* data, int32_t size) | ||
304 | +{ | ||
305 | + int ret = ERROR_SUCCESS; | ||
306 | + | ||
307 | + if ((ret = _fs->read(data, size, NULL)) != ERROR_SUCCESS) { | ||
308 | + if (ret != ERROR_SYSTEM_FILE_EOF) { | ||
309 | + srs_error("read flv tag header failed. ret=%d", ret); | ||
310 | + } | ||
311 | + return ret; | ||
312 | + } | ||
313 | + | ||
314 | + return ret; | ||
315 | + | ||
316 | +} | ||
317 | + | ||
318 | +int SrsFlvDecoder::read_previous_tag_size(char ts[4]) | ||
319 | +{ | ||
320 | + int ret = ERROR_SUCCESS; | ||
321 | + | ||
322 | + // ignore 4bytes tag size. | ||
323 | + if ((ret = _fs->read(ts, 4, NULL)) != ERROR_SUCCESS) { | ||
324 | + if (ret != ERROR_SYSTEM_FILE_EOF) { | ||
325 | + srs_error("read flv previous tag size failed. ret=%d", ret); | ||
326 | + } | ||
327 | + return ret; | ||
328 | + } | ||
329 | + | ||
330 | + return ret; | ||
331 | +} | ||
332 | + | ||
333 | +SrsFlvVodStreamDecoder::SrsFlvVodStreamDecoder() | ||
229 | { | 334 | { |
230 | _fs = NULL; | 335 | _fs = NULL; |
231 | tag_stream = new SrsStream(); | 336 | tag_stream = new SrsStream(); |
232 | } | 337 | } |
233 | 338 | ||
234 | -SrsFlvFastDecoder::~SrsFlvFastDecoder() | 339 | +SrsFlvVodStreamDecoder::~SrsFlvVodStreamDecoder() |
235 | { | 340 | { |
236 | srs_freep(tag_stream); | 341 | srs_freep(tag_stream); |
237 | } | 342 | } |
238 | 343 | ||
239 | -int SrsFlvFastDecoder::initialize(SrsFileReader* fs) | 344 | +int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fs) |
240 | { | 345 | { |
241 | int ret = ERROR_SUCCESS; | 346 | int ret = ERROR_SUCCESS; |
242 | 347 | ||
@@ -245,7 +350,7 @@ int SrsFlvFastDecoder::initialize(SrsFileReader* fs) | @@ -245,7 +350,7 @@ int SrsFlvFastDecoder::initialize(SrsFileReader* fs) | ||
245 | return ret; | 350 | return ret; |
246 | } | 351 | } |
247 | 352 | ||
248 | -int SrsFlvFastDecoder::read_header(char** pdata, int* psize) | 353 | +int SrsFlvVodStreamDecoder::read_header(char** pdata, int* psize) |
249 | { | 354 | { |
250 | *pdata = NULL; | 355 | *pdata = NULL; |
251 | *psize = 0; | 356 | *psize = 0; |
@@ -268,7 +373,7 @@ int SrsFlvFastDecoder::read_header(char** pdata, int* psize) | @@ -268,7 +373,7 @@ int SrsFlvFastDecoder::read_header(char** pdata, int* psize) | ||
268 | return ret; | 373 | return ret; |
269 | } | 374 | } |
270 | 375 | ||
271 | -int SrsFlvFastDecoder::read_sequence_header(int64_t* pstart, int* psize) | 376 | +int SrsFlvVodStreamDecoder::read_sequence_header(int64_t* pstart, int* psize) |
272 | { | 377 | { |
273 | *pstart = 0; | 378 | *pstart = 0; |
274 | *psize = 0; | 379 | *psize = 0; |
@@ -361,7 +466,7 @@ int SrsFlvFastDecoder::read_sequence_header(int64_t* pstart, int* psize) | @@ -361,7 +466,7 @@ int SrsFlvFastDecoder::read_sequence_header(int64_t* pstart, int* psize) | ||
361 | return ret; | 466 | return ret; |
362 | } | 467 | } |
363 | 468 | ||
364 | -int SrsFlvFastDecoder::lseek(int64_t offset) | 469 | +int SrsFlvVodStreamDecoder::lseek(int64_t offset) |
365 | { | 470 | { |
366 | int ret = ERROR_SUCCESS; | 471 | int ret = ERROR_SUCCESS; |
367 | 472 | ||
@@ -386,108 +491,3 @@ int SrsFlvFastDecoder::lseek(int64_t offset) | @@ -386,108 +491,3 @@ int SrsFlvFastDecoder::lseek(int64_t offset) | ||
386 | return ret; | 491 | return ret; |
387 | } | 492 | } |
388 | 493 | ||
389 | -SrsFlvDecoder::SrsFlvDecoder() | ||
390 | -{ | ||
391 | - _fs = NULL; | ||
392 | - tag_stream = new SrsStream(); | ||
393 | -} | ||
394 | - | ||
395 | -SrsFlvDecoder::~SrsFlvDecoder() | ||
396 | -{ | ||
397 | - srs_freep(tag_stream); | ||
398 | -} | ||
399 | - | ||
400 | -int SrsFlvDecoder::initialize(SrsFileReader* fs) | ||
401 | -{ | ||
402 | - int ret = ERROR_SUCCESS; | ||
403 | - | ||
404 | - _fs = fs; | ||
405 | - | ||
406 | - return ret; | ||
407 | -} | ||
408 | - | ||
409 | -int SrsFlvDecoder::read_header(char header[9]) | ||
410 | -{ | ||
411 | - int ret = ERROR_SUCCESS; | ||
412 | - | ||
413 | - if ((ret = _fs->read(header, 9, NULL)) != ERROR_SUCCESS) { | ||
414 | - return ret; | ||
415 | - } | ||
416 | - | ||
417 | - char* h = header; | ||
418 | - if (h[0] != 'F' || h[1] != 'L' || h[2] != 'V') { | ||
419 | - ret = ERROR_SYSTEM_FLV_HEADER; | ||
420 | - srs_warn("flv header must start with FLV. ret=%d", ret); | ||
421 | - return ret; | ||
422 | - } | ||
423 | - | ||
424 | - return ret; | ||
425 | -} | ||
426 | - | ||
427 | -int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* ptime) | ||
428 | -{ | ||
429 | - int ret = ERROR_SUCCESS; | ||
430 | - | ||
431 | - char th[11]; // tag header | ||
432 | - | ||
433 | - // read tag header | ||
434 | - if ((ret = _fs->read(th, 11, NULL)) != ERROR_SUCCESS) { | ||
435 | - if (ret != ERROR_SYSTEM_FILE_EOF) { | ||
436 | - srs_error("read flv tag header failed. ret=%d", ret); | ||
437 | - } | ||
438 | - return ret; | ||
439 | - } | ||
440 | - | ||
441 | - // Reserved UB [2] | ||
442 | - // Filter UB [1] | ||
443 | - // TagType UB [5] | ||
444 | - *ptype = (int)(th[0] & 0x1F); | ||
445 | - | ||
446 | - // DataSize UI24 | ||
447 | - char* pp = (char*)pdata_size; | ||
448 | - pp[2] = th[1]; | ||
449 | - pp[1] = th[2]; | ||
450 | - pp[0] = th[3]; | ||
451 | - | ||
452 | - // Timestamp UI24 | ||
453 | - pp = (char*)ptime; | ||
454 | - pp[2] = th[4]; | ||
455 | - pp[1] = th[5]; | ||
456 | - pp[0] = th[6]; | ||
457 | - | ||
458 | - // TimestampExtended UI8 | ||
459 | - pp[3] = th[7]; | ||
460 | - | ||
461 | - return ret; | ||
462 | -} | ||
463 | - | ||
464 | -int SrsFlvDecoder::read_tag_data(char* data, int32_t size) | ||
465 | -{ | ||
466 | - int ret = ERROR_SUCCESS; | ||
467 | - | ||
468 | - if ((ret = _fs->read(data, size, NULL)) != ERROR_SUCCESS) { | ||
469 | - if (ret != ERROR_SYSTEM_FILE_EOF) { | ||
470 | - srs_error("read flv tag header failed. ret=%d", ret); | ||
471 | - } | ||
472 | - return ret; | ||
473 | - } | ||
474 | - | ||
475 | - return ret; | ||
476 | - | ||
477 | -} | ||
478 | - | ||
479 | -int SrsFlvDecoder::read_previous_tag_size(char ts[4]) | ||
480 | -{ | ||
481 | - int ret = ERROR_SUCCESS; | ||
482 | - | ||
483 | - // ignore 4bytes tag size. | ||
484 | - if ((ret = _fs->read(ts, 4, NULL)) != ERROR_SUCCESS) { | ||
485 | - if (ret != ERROR_SYSTEM_FILE_EOF) { | ||
486 | - srs_error("read flv previous tag size failed. ret=%d", ret); | ||
487 | - } | ||
488 | - return ret; | ||
489 | - } | ||
490 | - | ||
491 | - return ret; | ||
492 | -} | ||
493 | - |
@@ -49,8 +49,9 @@ public: | @@ -49,8 +49,9 @@ public: | ||
49 | virtual ~SrsFlvEncoder(); | 49 | virtual ~SrsFlvEncoder(); |
50 | public: | 50 | public: |
51 | /** | 51 | /** |
52 | - * initialize the underlayer file stream, | ||
53 | - * user can initialize multiple times to encode multiple flv files. | 52 | + * initialize the underlayer file stream. |
53 | + * @remark user can initialize multiple times to encode multiple flv files. | ||
54 | + * @remark, user must free the fs, flv encoder never close/free it. | ||
54 | */ | 55 | */ |
55 | virtual int initialize(SrsFileWriter* fs); | 56 | virtual int initialize(SrsFileWriter* fs); |
56 | public: | 57 | public: |
@@ -85,62 +86,66 @@ private: | @@ -85,62 +86,66 @@ private: | ||
85 | }; | 86 | }; |
86 | 87 | ||
87 | /** | 88 | /** |
88 | -* decode flv fast by only decoding the header and tag. | 89 | +* decode flv file. |
89 | */ | 90 | */ |
90 | -class SrsFlvFastDecoder | 91 | +class SrsFlvDecoder |
91 | { | 92 | { |
92 | private: | 93 | private: |
93 | SrsFileReader* _fs; | 94 | SrsFileReader* _fs; |
94 | private: | 95 | private: |
95 | SrsStream* tag_stream; | 96 | SrsStream* tag_stream; |
96 | public: | 97 | public: |
97 | - SrsFlvFastDecoder(); | ||
98 | - virtual ~SrsFlvFastDecoder(); | 98 | + SrsFlvDecoder(); |
99 | + virtual ~SrsFlvDecoder(); | ||
99 | public: | 100 | public: |
100 | /** | 101 | /** |
101 | - * initialize the underlayer file stream, | ||
102 | - * user can initialize multiple times to encode multiple flv files. | 102 | + * initialize the underlayer file stream |
103 | + * @remark user can initialize multiple times to decode multiple flv files. | ||
104 | + * @remark, user must free the fs, flv decoder never close/free it. | ||
103 | */ | 105 | */ |
104 | virtual int initialize(SrsFileReader* fs); | 106 | virtual int initialize(SrsFileReader* fs); |
105 | public: | 107 | public: |
106 | - /** | ||
107 | - * read the flv header and size. | ||
108 | - */ | ||
109 | - virtual int read_header(char** pdata, int* psize); | ||
110 | - /** | ||
111 | - * read the sequence header and size. | ||
112 | - */ | ||
113 | - virtual int read_sequence_header(int64_t* pstart, int* psize); | ||
114 | -public: | ||
115 | - /** | ||
116 | - * for start offset, seed to this position and response flv stream. | ||
117 | - */ | ||
118 | - virtual int lseek(int64_t offset); | 108 | + virtual int read_header(char header[9]); |
109 | + virtual int read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* ptime); | ||
110 | + virtual int read_tag_data(char* data, int32_t size); | ||
111 | + virtual int read_previous_tag_size(char ts[4]); | ||
119 | }; | 112 | }; |
120 | 113 | ||
121 | /** | 114 | /** |
122 | -* decode flv file. | 115 | +* decode flv fast by only decoding the header and tag. |
116 | +* used for vod flv stream to read the header and sequence header, | ||
117 | +* then seek to specified offset. | ||
123 | */ | 118 | */ |
124 | -class SrsFlvDecoder | 119 | +class SrsFlvVodStreamDecoder |
125 | { | 120 | { |
126 | private: | 121 | private: |
127 | SrsFileReader* _fs; | 122 | SrsFileReader* _fs; |
128 | private: | 123 | private: |
129 | SrsStream* tag_stream; | 124 | SrsStream* tag_stream; |
130 | public: | 125 | public: |
131 | - SrsFlvDecoder(); | ||
132 | - virtual ~SrsFlvDecoder(); | 126 | + SrsFlvVodStreamDecoder(); |
127 | + virtual ~SrsFlvVodStreamDecoder(); | ||
133 | public: | 128 | public: |
134 | /** | 129 | /** |
135 | - * initialize the underlayer file stream, | ||
136 | - * user can initialize multiple times to decode multiple flv files. | 130 | + * initialize the underlayer file stream |
131 | + * @remark user can initialize multiple times to decode multiple flv files. | ||
132 | + * @remark, user must free the fs, flv decoder never close/free it. | ||
137 | */ | 133 | */ |
138 | virtual int initialize(SrsFileReader* fs); | 134 | virtual int initialize(SrsFileReader* fs); |
139 | public: | 135 | public: |
140 | - virtual int read_header(char header[9]); | ||
141 | - virtual int read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* ptime); | ||
142 | - virtual int read_tag_data(char* data, int32_t size); | ||
143 | - virtual int read_previous_tag_size(char ts[4]); | 136 | + /** |
137 | + * read the flv header and size. | ||
138 | + */ | ||
139 | + virtual int read_header(char** pdata, int* psize); | ||
140 | + /** | ||
141 | + * read the sequence header and size. | ||
142 | + */ | ||
143 | + virtual int read_sequence_header(int64_t* pstart, int* psize); | ||
144 | +public: | ||
145 | + /** | ||
146 | + * for start offset, seed to this position and response flv stream. | ||
147 | + */ | ||
148 | + virtual int lseek(int64_t offset); | ||
144 | }; | 149 | }; |
145 | 150 | ||
146 | #endif | 151 | #endif |
@@ -26,88 +26,7 @@ using namespace std; | @@ -26,88 +26,7 @@ using namespace std; | ||
26 | 26 | ||
27 | #include <srs_kernel_error.hpp> | 27 | #include <srs_kernel_error.hpp> |
28 | #include <srs_kernel_codec.hpp> | 28 | #include <srs_kernel_codec.hpp> |
29 | - | ||
30 | -VOID TEST(KernelCodecTest, IsKeyFrame) | ||
31 | -{ | ||
32 | - int8_t data; | ||
33 | - | ||
34 | - data = 0x10; | ||
35 | - EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1)); | ||
36 | - EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 0)); | ||
37 | - | ||
38 | - data = 0x20; | ||
39 | - EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 1)); | ||
40 | -} | ||
41 | - | ||
42 | -VOID TEST(KernelCodecTest, IsH264) | ||
43 | -{ | ||
44 | - int8_t data; | ||
45 | - | ||
46 | - EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0)); | ||
47 | - | ||
48 | - data = 0x17; | ||
49 | - EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1)); | ||
50 | - | ||
51 | - data = 0x07; | ||
52 | - EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1)); | ||
53 | - | ||
54 | - data = 0x08; | ||
55 | - EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 1)); | ||
56 | -} | ||
57 | - | ||
58 | -VOID TEST(KernelCodecTest, IsSequenceHeader) | ||
59 | -{ | ||
60 | - int16_t data; | ||
61 | - char* pp = (char*)&data; | ||
62 | - | ||
63 | - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 0)); | ||
64 | - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 1)); | ||
65 | - | ||
66 | - pp[0] = 0x17; | ||
67 | - pp[1] = 0x00; | ||
68 | - EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
69 | - pp[0] = 0x18; | ||
70 | - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
71 | - pp[0] = 0x27; | ||
72 | - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
73 | - pp[0] = 0x17; | ||
74 | - pp[1] = 0x01; | ||
75 | - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
76 | -} | ||
77 | - | ||
78 | -VOID TEST(KernelCodecTest, IsAAC) | ||
79 | -{ | ||
80 | - int8_t data; | ||
81 | - | ||
82 | - EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0)); | ||
83 | - | ||
84 | - data = 0xa0; | ||
85 | - EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1)); | ||
86 | - | ||
87 | - data = 0xa7; | ||
88 | - EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1)); | ||
89 | - | ||
90 | - data = 0x00; | ||
91 | - EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 1)); | ||
92 | -} | ||
93 | - | ||
94 | -VOID TEST(KernelCodecTest, IsAudioSequenceHeader) | ||
95 | -{ | ||
96 | - int16_t data; | ||
97 | - char* pp = (char*)&data; | ||
98 | - | ||
99 | - EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 0)); | ||
100 | - EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 1)); | ||
101 | - | ||
102 | - pp[0] = 0xa0; | ||
103 | - pp[1] = 0x00; | ||
104 | - EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 2)); | ||
105 | - pp[0] = 0x00; | ||
106 | - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
107 | - pp[0] = 0xa0; | ||
108 | - pp[1] = 0x01; | ||
109 | - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
110 | -} | 29 | +#include <srs_kernel_flv.hpp> |
111 | 30 | ||
112 | MockSrsFileWriter::MockSrsFileWriter() | 31 | MockSrsFileWriter::MockSrsFileWriter() |
113 | { | 32 | { |
@@ -194,3 +113,92 @@ int MockSrsFileReader::read(void* buf, size_t count, ssize_t* pnread) | @@ -194,3 +113,92 @@ int MockSrsFileReader::read(void* buf, size_t count, ssize_t* pnread) | ||
194 | int ret = ERROR_SUCCESS; | 113 | int ret = ERROR_SUCCESS; |
195 | return ret; | 114 | return ret; |
196 | } | 115 | } |
116 | + | ||
117 | +VOID TEST(KernelCodecTest, IsKeyFrame) | ||
118 | +{ | ||
119 | + int8_t data; | ||
120 | + | ||
121 | + data = 0x10; | ||
122 | + EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1)); | ||
123 | + EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 0)); | ||
124 | + | ||
125 | + data = 0x20; | ||
126 | + EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 1)); | ||
127 | +} | ||
128 | + | ||
129 | +VOID TEST(KernelCodecTest, IsH264) | ||
130 | +{ | ||
131 | + int8_t data; | ||
132 | + | ||
133 | + EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0)); | ||
134 | + | ||
135 | + data = 0x17; | ||
136 | + EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1)); | ||
137 | + | ||
138 | + data = 0x07; | ||
139 | + EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1)); | ||
140 | + | ||
141 | + data = 0x08; | ||
142 | + EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 1)); | ||
143 | +} | ||
144 | + | ||
145 | +VOID TEST(KernelCodecTest, IsSequenceHeader) | ||
146 | +{ | ||
147 | + int16_t data; | ||
148 | + char* pp = (char*)&data; | ||
149 | + | ||
150 | + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 0)); | ||
151 | + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 1)); | ||
152 | + | ||
153 | + pp[0] = 0x17; | ||
154 | + pp[1] = 0x00; | ||
155 | + EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
156 | + pp[0] = 0x18; | ||
157 | + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
158 | + pp[0] = 0x27; | ||
159 | + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
160 | + pp[0] = 0x17; | ||
161 | + pp[1] = 0x01; | ||
162 | + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
163 | +} | ||
164 | + | ||
165 | +VOID TEST(KernelCodecTest, IsAAC) | ||
166 | +{ | ||
167 | + int8_t data; | ||
168 | + | ||
169 | + EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0)); | ||
170 | + | ||
171 | + data = 0xa0; | ||
172 | + EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1)); | ||
173 | + | ||
174 | + data = 0xa7; | ||
175 | + EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1)); | ||
176 | + | ||
177 | + data = 0x00; | ||
178 | + EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 1)); | ||
179 | +} | ||
180 | + | ||
181 | +VOID TEST(KernelCodecTest, IsAudioSequenceHeader) | ||
182 | +{ | ||
183 | + int16_t data; | ||
184 | + char* pp = (char*)&data; | ||
185 | + | ||
186 | + EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 0)); | ||
187 | + EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 1)); | ||
188 | + | ||
189 | + pp[0] = 0xa0; | ||
190 | + pp[1] = 0x00; | ||
191 | + EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 2)); | ||
192 | + pp[0] = 0x00; | ||
193 | + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
194 | + pp[0] = 0xa0; | ||
195 | + pp[1] = 0x01; | ||
196 | + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); | ||
197 | +} | ||
198 | + | ||
199 | +VOID TEST(KernelFlvTest, IsAudioSequenceHeader) | ||
200 | +{ | ||
201 | + MockSrsFileWriter fs; | ||
202 | + SrsFlvEncoder enc; | ||
203 | + ASSERT_TRUE(ERROR_SUCCESS == enc.initialize(&fs)); | ||
204 | +} |
-
请 注册 或 登录 后发表评论