for #310, workaround to force to LC/MAIN, donot support SSR above. 2.0.113
正在显示
5 个修改的文件
包含
96 行增加
和
43 行删除
@@ -309,6 +309,12 @@ int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsSimpleBuffer* ab) | @@ -309,6 +309,12 @@ int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsSimpleBuffer* ab) | ||
309 | { | 309 | { |
310 | int ret = ERROR_SUCCESS; | 310 | int ret = ERROR_SUCCESS; |
311 | 311 | ||
312 | + // if flushed yet, ignore. | ||
313 | + if (ab->length() == 0) { | ||
314 | + srs_info("ignore hls segment audio flushed yet."); | ||
315 | + return ret; | ||
316 | + } | ||
317 | + | ||
312 | // if current is NULL, segment is not open, ignore the flush event. | 318 | // if current is NULL, segment is not open, ignore the flush event. |
313 | if (!current) { | 319 | if (!current) { |
314 | srs_warn("flush audio ignored, for segment is not open."); | 320 | srs_warn("flush audio ignored, for segment is not open."); |
@@ -336,6 +342,12 @@ int SrsHlsMuxer::flush_video(SrsMpegtsFrame* /*af*/, SrsSimpleBuffer* /*ab*/, Sr | @@ -336,6 +342,12 @@ int SrsHlsMuxer::flush_video(SrsMpegtsFrame* /*af*/, SrsSimpleBuffer* /*ab*/, Sr | ||
336 | { | 342 | { |
337 | int ret = ERROR_SUCCESS; | 343 | int ret = ERROR_SUCCESS; |
338 | 344 | ||
345 | + // if flushed yet, ignore. | ||
346 | + if (vb->length() == 0) { | ||
347 | + srs_info("ignore hls segment video flushed yet."); | ||
348 | + return ret; | ||
349 | + } | ||
350 | + | ||
339 | // if current is NULL, segment is not open, ignore the flush event. | 351 | // if current is NULL, segment is not open, ignore the flush event. |
340 | if (!current) { | 352 | if (!current) { |
341 | srs_warn("flush video ignored, for segment is not open."); | 353 | srs_warn("flush video ignored, for segment is not open."); |
@@ -776,6 +788,13 @@ int SrsHlsCache::reap_segment(string log_desc, SrsHlsMuxer* muxer, int64_t segme | @@ -776,6 +788,13 @@ int SrsHlsCache::reap_segment(string log_desc, SrsHlsMuxer* muxer, int64_t segme | ||
776 | } | 788 | } |
777 | 789 | ||
778 | // TODO: flush audio before or after segment? | 790 | // TODO: flush audio before or after segment? |
791 | + | ||
792 | + // segment open, flush video first. | ||
793 | + if ((ret = muxer->flush_video(cache->af, cache->ab, cache->vf, cache->vb)) != ERROR_SUCCESS) { | ||
794 | + srs_error("m3u8 muxer flush video failed. ret=%d", ret); | ||
795 | + return ret; | ||
796 | + } | ||
797 | + | ||
779 | // segment open, flush the audio. | 798 | // segment open, flush the audio. |
780 | // @see: ngx_rtmp_hls_open_fragment | 799 | // @see: ngx_rtmp_hls_open_fragment |
781 | /* start fragment with audio to make iPhone happy */ | 800 | /* start fragment with audio to make iPhone happy */ |
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | // current release version | 31 | // current release version |
32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
34 | -#define VERSION_REVISION 112 | 34 | +#define VERSION_REVISION 113 |
35 | 35 | ||
36 | // server info. | 36 | // server info. |
37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
@@ -289,17 +289,33 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample | @@ -289,17 +289,33 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample | ||
289 | srs_error("audio codec decode aac sequence header failed. ret=%d", ret); | 289 | srs_error("audio codec decode aac sequence header failed. ret=%d", ret); |
290 | return ret; | 290 | return ret; |
291 | } | 291 | } |
292 | - aac_profile = stream->read_1bytes(); | ||
293 | - aac_sample_rate = stream->read_1bytes(); | ||
294 | - | ||
295 | - aac_channels = (aac_sample_rate >> 3) & 0x0f; | ||
296 | - aac_sample_rate = ((aac_profile << 1) & 0x0e) | ((aac_sample_rate >> 7) & 0x01); | ||
297 | - aac_profile = (aac_profile >> 3) & 0x1f; | ||
298 | - | ||
299 | - if (aac_profile == 0 || aac_profile == 0x1f) { | 292 | + u_int8_t profile_ObjectType = stream->read_1bytes(); |
293 | + u_int8_t samplingFrequencyIndex = stream->read_1bytes(); | ||
294 | + | ||
295 | + aac_channels = (samplingFrequencyIndex >> 3) & 0x0f; | ||
296 | + samplingFrequencyIndex = ((profile_ObjectType << 1) & 0x0e) | ((samplingFrequencyIndex >> 7) & 0x01); | ||
297 | + profile_ObjectType = (profile_ObjectType >> 3) & 0x1f; | ||
298 | + | ||
299 | + // set the aac sample rate. | ||
300 | + aac_sample_rate = samplingFrequencyIndex; | ||
301 | + | ||
302 | + // the profile = object_id + 1 | ||
303 | + // @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78, | ||
304 | + // Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types | ||
305 | + aac_profile = profile_ObjectType + 1; | ||
306 | + | ||
307 | + // the valid aac profile: | ||
308 | + // MPEG-2 profile | ||
309 | + // Main profile (ID == 1) | ||
310 | + // Low Complexity profile (LC) (ID == 2) | ||
311 | + // Scalable Sampling Rate profile (SSR) (ID == 3) | ||
312 | + // (reserved) (ID == 4) | ||
313 | + // @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78, | ||
314 | + // Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types | ||
315 | + if (aac_profile > 4) { | ||
300 | ret = ERROR_HLS_DECODE_ERROR; | 316 | ret = ERROR_HLS_DECODE_ERROR; |
301 | srs_error("audio codec decode aac sequence header failed, " | 317 | srs_error("audio codec decode aac sequence header failed, " |
302 | - "adts object=%d invalid. ret=%d", aac_profile, ret); | 318 | + "adts object=%d invalid. ret=%d", profile_ObjectType, ret); |
303 | return ret; | 319 | return ret; |
304 | } | 320 | } |
305 | 321 |
@@ -1990,6 +1990,20 @@ int SrsTsCache::do_cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1990,6 +1990,20 @@ int SrsTsCache::do_cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
1990 | return ret; | 1990 | return ret; |
1991 | } | 1991 | } |
1992 | 1992 | ||
1993 | + // the profile = object_id + 1 | ||
1994 | + // @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78, | ||
1995 | + // Table 1. A.9 C MPEG-2 Audio profiles and MPEG-4 Audio object types | ||
1996 | + // the valid object type: | ||
1997 | + // AAC Main(ID == 0) | ||
1998 | + // AAC LC(ID == 1) | ||
1999 | + // AAC SSR(ID == 2) | ||
2000 | + // AAC LTP(ID == 3) | ||
2001 | + u_int8_t profile_ObjectType = codec->aac_profile - 1; | ||
2002 | + | ||
2003 | + // TODO: FIXME: only support Main or LC. | ||
2004 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/310 | ||
2005 | + profile_ObjectType = srs_min(1, profile_ObjectType); | ||
2006 | + | ||
1993 | // the frame length is the AAC raw data plus the adts header size. | 2007 | // the frame length is the AAC raw data plus the adts header size. |
1994 | int32_t frame_length = size + 7; | 2008 | int32_t frame_length = size + 7; |
1995 | 2009 | ||
@@ -2022,7 +2036,7 @@ int SrsTsCache::do_cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -2022,7 +2036,7 @@ int SrsTsCache::do_cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
2022 | int8_t number_of_raw_data_blocks_in_frame; //2bits, 0 indicating 1 raw_data_block() | 2036 | int8_t number_of_raw_data_blocks_in_frame; //2bits, 0 indicating 1 raw_data_block() |
2023 | */ | 2037 | */ |
2024 | // profile, 2bits | 2038 | // profile, 2bits |
2025 | - adts_header[2] = (codec->aac_profile << 6) & 0xc0; | 2039 | + adts_header[2] = (profile_ObjectType << 6) & 0xc0; |
2026 | // sampling_frequency_index 4bits | 2040 | // sampling_frequency_index 4bits |
2027 | adts_header[2] |= (codec->aac_sample_rate << 2) & 0x3c; | 2041 | adts_header[2] |= (codec->aac_sample_rate << 2) & 0x3c; |
2028 | // channel_configuration 3bits | 2042 | // channel_configuration 3bits |
@@ -375,10 +375,10 @@ int SrsRawAacStream::adts_demux(SrsStream* stream, char** pframe, int* pnb_frame | @@ -375,10 +375,10 @@ int SrsRawAacStream::adts_demux(SrsStream* stream, char** pframe, int* pnb_frame | ||
375 | // channel_configuration 3 uimsbf | 375 | // channel_configuration 3 uimsbf |
376 | // original/copy 1 bslbf | 376 | // original/copy 1 bslbf |
377 | // home 1 bslbf | 377 | // home 1 bslbf |
378 | - int8_t fh_Profile_ObjectType = (fh1 >> 14) & 0x03; | ||
379 | - int8_t fh_sampling_frequency_index = (fh1 >> 10) & 0x0f; | 378 | + int8_t audioObjectType = (fh1 >> 14) & 0x03; |
379 | + int8_t samplingFrequencyIndex = (fh1 >> 10) & 0x0f; | ||
380 | /*int8_t fh_private_bit = (fh1 >> 9) & 0x01;*/ | 380 | /*int8_t fh_private_bit = (fh1 >> 9) & 0x01;*/ |
381 | - int8_t fh_channel_configuration = (fh1 >> 6) & 0x07; | 381 | + int8_t channelConfiguration = (fh1 >> 6) & 0x07; |
382 | /*int8_t fh_original = (fh1 >> 5) & 0x01;*/ | 382 | /*int8_t fh_original = (fh1 >> 5) & 0x01;*/ |
383 | /*int8_t fh_home = (fh1 >> 4) & 0x01;*/ | 383 | /*int8_t fh_home = (fh1 >> 4) & 0x01;*/ |
384 | // @remark, Emphasis is removed, | 384 | // @remark, Emphasis is removed, |
@@ -412,8 +412,8 @@ int SrsRawAacStream::adts_demux(SrsStream* stream, char** pframe, int* pnb_frame | @@ -412,8 +412,8 @@ int SrsRawAacStream::adts_demux(SrsStream* stream, char** pframe, int* pnb_frame | ||
412 | /*int16_t crc_check = */stream->read_2bytes(); | 412 | /*int16_t crc_check = */stream->read_2bytes(); |
413 | } | 413 | } |
414 | 414 | ||
415 | - // TODO: check the fh_sampling_frequency_index | ||
416 | - // TODO: check the fh_channel_configuration | 415 | + // TODO: check the samplingFrequencyIndex |
416 | + // TODO: check the channelConfiguration | ||
417 | 417 | ||
418 | // raw_data_blocks | 418 | // raw_data_blocks |
419 | int adts_header_size = stream->pos() - adts_header_start; | 419 | int adts_header_size = stream->pos() - adts_header_start; |
@@ -425,34 +425,34 @@ int SrsRawAacStream::adts_demux(SrsStream* stream, char** pframe, int* pnb_frame | @@ -425,34 +425,34 @@ int SrsRawAacStream::adts_demux(SrsStream* stream, char** pframe, int* pnb_frame | ||
425 | // the profile = object_id + 1 | 425 | // the profile = object_id + 1 |
426 | // @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78, | 426 | // @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78, |
427 | // Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types | 427 | // Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types |
428 | - char aac_profile = fh_Profile_ObjectType + 1; | 428 | + char aac_profile = audioObjectType + 1; |
429 | 429 | ||
430 | // the codec info. | 430 | // the codec info. |
431 | codec.protection_absent = fh_protection_absent; | 431 | codec.protection_absent = fh_protection_absent; |
432 | - codec.Profile_ObjectType = fh_Profile_ObjectType; | ||
433 | - codec.sampling_frequency_index = fh_sampling_frequency_index; | ||
434 | - codec.channel_configuration = fh_channel_configuration; | 432 | + codec.Profile_ObjectType = audioObjectType; |
433 | + codec.sampling_frequency_index = samplingFrequencyIndex; | ||
434 | + codec.channel_configuration = channelConfiguration; | ||
435 | codec.aac_frame_length = fh_aac_frame_length; | 435 | codec.aac_frame_length = fh_aac_frame_length; |
436 | 436 | ||
437 | codec.aac_profile = aac_profile; | 437 | codec.aac_profile = aac_profile; |
438 | - codec.aac_samplerate = fh_sampling_frequency_index; | ||
439 | - codec.aac_channel = fh_channel_configuration; | 438 | + codec.aac_samplerate = samplingFrequencyIndex; |
439 | + codec.aac_channel = channelConfiguration; | ||
440 | 440 | ||
441 | // @see srs_audio_write_raw_frame(). | 441 | // @see srs_audio_write_raw_frame(). |
442 | codec.sound_format = 10; // AAC | 442 | codec.sound_format = 10; // AAC |
443 | - if (fh_sampling_frequency_index <= 0x0c && fh_sampling_frequency_index > 0x0a) { | 443 | + if (samplingFrequencyIndex <= 0x0c && samplingFrequencyIndex > 0x0a) { |
444 | codec.sound_rate = SrsCodecAudioSampleRate5512; | 444 | codec.sound_rate = SrsCodecAudioSampleRate5512; |
445 | - } else if (fh_sampling_frequency_index <= 0x0a && fh_sampling_frequency_index > 0x07) { | 445 | + } else if (samplingFrequencyIndex <= 0x0a && samplingFrequencyIndex > 0x07) { |
446 | codec.sound_rate = SrsCodecAudioSampleRate11025; | 446 | codec.sound_rate = SrsCodecAudioSampleRate11025; |
447 | - } else if (fh_sampling_frequency_index <= 0x07 && fh_sampling_frequency_index > 0x04) { | 447 | + } else if (samplingFrequencyIndex <= 0x07 && samplingFrequencyIndex > 0x04) { |
448 | codec.sound_rate = SrsCodecAudioSampleRate22050; | 448 | codec.sound_rate = SrsCodecAudioSampleRate22050; |
449 | - } else if (fh_sampling_frequency_index <= 0x04) { | 449 | + } else if (samplingFrequencyIndex <= 0x04) { |
450 | codec.sound_rate = SrsCodecAudioSampleRate44100; | 450 | codec.sound_rate = SrsCodecAudioSampleRate44100; |
451 | } else { | 451 | } else { |
452 | codec.sound_rate = SrsCodecAudioSampleRate44100; | 452 | codec.sound_rate = SrsCodecAudioSampleRate44100; |
453 | - srs_warn("adts invalid sample rate for flv, rate=%#x", fh_sampling_frequency_index); | 453 | + srs_warn("adts invalid sample rate for flv, rate=%#x", samplingFrequencyIndex); |
454 | } | 454 | } |
455 | - codec.sound_size = srs_max(0, srs_min(1, fh_channel_configuration - 1)); | 455 | + codec.sound_size = srs_max(0, srs_min(1, channelConfiguration - 1)); |
456 | // TODO: FIXME: finger it out the sound size by adts. | 456 | // TODO: FIXME: finger it out the sound size by adts. |
457 | codec.sound_size = 1; // 0(8bits) or 1(16bits). | 457 | codec.sound_size = 1; // 0(8bits) or 1(16bits). |
458 | 458 | ||
@@ -471,19 +471,27 @@ int SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, string& sh | @@ -471,19 +471,27 @@ int SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, string& sh | ||
471 | { | 471 | { |
472 | int ret = ERROR_SUCCESS; | 472 | int ret = ERROR_SUCCESS; |
473 | 473 | ||
474 | - char aac_channel = codec->aac_channel; | ||
475 | - char aac_profile = codec->aac_profile; | ||
476 | - char aac_samplerate = codec->aac_samplerate; | 474 | + // only support aac profile 1-4. |
475 | + if (codec->aac_profile < 1 || codec->aac_profile > 4) { | ||
476 | + return ERROR_AAC_DATA_INVALID; | ||
477 | + } | ||
478 | + | ||
479 | + // the profile = object_id + 1 | ||
480 | + // @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78, | ||
481 | + // Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types | ||
482 | + char profile_ObjectType = codec->aac_profile - 1; | ||
483 | + char channelConfiguration = codec->aac_channel; | ||
484 | + char samplingFrequencyIndex = codec->aac_samplerate; | ||
477 | 485 | ||
478 | // override the aac samplerate by user specified. | 486 | // override the aac samplerate by user specified. |
479 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/212#issuecomment-64146899 | 487 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/212#issuecomment-64146899 |
480 | switch (codec->sound_rate) { | 488 | switch (codec->sound_rate) { |
481 | case SrsCodecAudioSampleRate11025: | 489 | case SrsCodecAudioSampleRate11025: |
482 | - aac_samplerate = 0x0a; break; | 490 | + samplingFrequencyIndex = 0x0a; break; |
483 | case SrsCodecAudioSampleRate22050: | 491 | case SrsCodecAudioSampleRate22050: |
484 | - aac_samplerate = 0x07; break; | 492 | + samplingFrequencyIndex = 0x07; break; |
485 | case SrsCodecAudioSampleRate44100: | 493 | case SrsCodecAudioSampleRate44100: |
486 | - aac_samplerate = 0x04; break; | 494 | + samplingFrequencyIndex = 0x04; break; |
487 | default: | 495 | default: |
488 | break; | 496 | break; |
489 | } | 497 | } |
@@ -495,26 +503,22 @@ int SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, string& sh | @@ -495,26 +503,22 @@ int SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, string& sh | ||
495 | // AudioSpecificConfig (), page 33 | 503 | // AudioSpecificConfig (), page 33 |
496 | // 1.6.2.1 AudioSpecificConfig | 504 | // 1.6.2.1 AudioSpecificConfig |
497 | // audioObjectType; 5 bslbf | 505 | // audioObjectType; 5 bslbf |
498 | - ch = (aac_profile << 3) & 0xf8; | 506 | + ch = (profile_ObjectType << 3) & 0xf8; |
499 | // 3bits left. | 507 | // 3bits left. |
500 | 508 | ||
501 | // samplingFrequencyIndex; 4 bslbf | 509 | // samplingFrequencyIndex; 4 bslbf |
502 | - ch |= (aac_samplerate >> 1) & 0x07; | 510 | + ch |= (samplingFrequencyIndex >> 1) & 0x07; |
503 | sh += ch; | 511 | sh += ch; |
504 | - ch = (aac_samplerate << 7) & 0x80; | ||
505 | - if (aac_samplerate == 0x0f) { | 512 | + ch = (samplingFrequencyIndex << 7) & 0x80; |
513 | + if (samplingFrequencyIndex == 0x0f) { | ||
506 | return ERROR_AAC_DATA_INVALID; | 514 | return ERROR_AAC_DATA_INVALID; |
507 | } | 515 | } |
508 | // 7bits left. | 516 | // 7bits left. |
509 | 517 | ||
510 | // channelConfiguration; 4 bslbf | 518 | // channelConfiguration; 4 bslbf |
511 | - ch |= (aac_channel << 3) & 0x78; | 519 | + ch |= (channelConfiguration << 3) & 0x78; |
512 | // 3bits left. | 520 | // 3bits left. |
513 | 521 | ||
514 | - // only support aac profile 1-4. | ||
515 | - if (aac_profile < 1 || aac_profile > 4) { | ||
516 | - return ERROR_AAC_DATA_INVALID; | ||
517 | - } | ||
518 | // GASpecificConfig(), page 451 | 522 | // GASpecificConfig(), page 451 |
519 | // 4.4.1 Decoder configuration (GASpecificConfig) | 523 | // 4.4.1 Decoder configuration (GASpecificConfig) |
520 | // frameLengthFlag; 1 bslbf | 524 | // frameLengthFlag; 1 bslbf |
-
请 注册 或 登录 后发表评论