fix ts audio bug, aac adts header and PES_packet_length fixed
正在显示
2 个修改的文件
包含
15 行增加
和
6 行删除
@@ -1941,6 +1941,10 @@ public: | @@ -1941,6 +1941,10 @@ public: | ||
1941 | layer = (syncword >> 1) & 0x03; | 1941 | layer = (syncword >> 1) & 0x03; |
1942 | ID = (syncword >> 3) & 0x01; | 1942 | ID = (syncword >> 3) & 0x01; |
1943 | syncword = (syncword >> 4) & 0x0FFF; | 1943 | syncword = (syncword >> 4) & 0x0FFF; |
1944 | + if (syncword != 0xfff) { | ||
1945 | + trace("ts+aac invalid sync word. expect 0xfff, actual %#x", syncword); | ||
1946 | + return -1; | ||
1947 | + } | ||
1944 | 1948 | ||
1945 | // adts_variable_header | 1949 | // adts_variable_header |
1946 | int64_t temp = 0; | 1950 | int64_t temp = 0; |
@@ -2228,7 +2232,7 @@ int main(int argc, char** argv) | @@ -2228,7 +2232,7 @@ int main(int argc, char** argv) | ||
2228 | 2232 | ||
2229 | if ((ret = consume(msg, &aac_muxer)) != 0) { | 2233 | if ((ret = consume(msg, &aac_muxer)) != 0) { |
2230 | trace("demuxer+consume parse and consume message failed. ret=%d", ret); | 2234 | trace("demuxer+consume parse and consume message failed. ret=%d", ret); |
2231 | - break; | 2235 | + return -1; |
2232 | } | 2236 | } |
2233 | 2237 | ||
2234 | srs_freep(msg); | 2238 | srs_freep(msg); |
@@ -560,6 +560,9 @@ int SrsTSMuxer::write_audio(u_int32_t time, SrsCodec* codec, SrsCodecSample* sam | @@ -560,6 +560,9 @@ int SrsTSMuxer::write_audio(u_int32_t time, SrsCodec* codec, SrsCodecSample* sam | ||
560 | return ret; | 560 | return ret; |
561 | } | 561 | } |
562 | 562 | ||
563 | + // the frame length is the AAC raw data plus the adts header size. | ||
564 | + int32_t frame_length = size + 7; | ||
565 | + | ||
563 | // AAC-ADTS | 566 | // AAC-ADTS |
564 | // 6.2 Audio Data Transport Stream, ADTS | 567 | // 6.2 Audio Data Transport Stream, ADTS |
565 | // in aac-iso-13818-7.pdf, page 26. | 568 | // in aac-iso-13818-7.pdf, page 26. |
@@ -593,12 +596,14 @@ int SrsTSMuxer::write_audio(u_int32_t time, SrsCodec* codec, SrsCodecSample* sam | @@ -593,12 +596,14 @@ int SrsTSMuxer::write_audio(u_int32_t time, SrsCodec* codec, SrsCodecSample* sam | ||
593 | // sampling_frequency_index 4bits | 596 | // sampling_frequency_index 4bits |
594 | adts_header[2] |= (codec->aac_sample_rate << 2) & 0x3c; | 597 | adts_header[2] |= (codec->aac_sample_rate << 2) & 0x3c; |
595 | // channel_configuration 3bits | 598 | // channel_configuration 3bits |
596 | - adts_header[2] |= (codec->aac_channels >> 1) & 0x01; | ||
597 | - adts_header[3] = (codec->aac_channels << 5) & 0xc0; | 599 | + adts_header[2] |= (codec->aac_channels >> 2) & 0x01; |
600 | + adts_header[3] = (codec->aac_channels << 6) & 0xc0; | ||
598 | // frame_length 13bits | 601 | // frame_length 13bits |
599 | - adts_header[3] |= (size >> 11) & 0x03; | ||
600 | - adts_header[4] = (size >> 3) & 0xff; | ||
601 | - adts_header[5] = (size << 5) & 0xcf; | 602 | + adts_header[3] |= (frame_length >> 11) & 0x03; |
603 | + adts_header[4] = (frame_length >> 3) & 0xff; | ||
604 | + adts_header[5] = ((frame_length << 5) & 0xe0); | ||
605 | + // adts_buffer_fullness; //11bits | ||
606 | + adts_header[5] |= 0x1f; | ||
602 | 607 | ||
603 | // copy to audio buffer | 608 | // copy to audio buffer |
604 | audio_buffer->append(adts_header, sizeof(adts_header)); | 609 | audio_buffer->append(adts_header, sizeof(adts_header)); |
-
请 注册 或 登录 后发表评论