diff --git a/src/input/r_mpeg_ts.cpp b/src/input/r_mpeg_ts.cpp index f32038a39..c50fa9b76 100644 --- a/src/input/r_mpeg_ts.cpp +++ b/src/input/r_mpeg_ts.cpp @@ -28,6 +28,7 @@ #include "common/mpeg1_2.h" #include "common/mpeg4_p2.h" #include "common/strings/formatting.h" +#include "input/aac_framing_packet_converter.h" #include "input/r_mpeg_ts.h" #include "input/teletext_to_srt_packet_converter.h" #include "output/p_aac.h" @@ -217,13 +218,17 @@ int mpeg_ts_track_c::new_stream_a_aac() { add_pes_payload_to_probe_data(); - if (0 > find_aac_header(m_probe_data->get_buffer(), m_probe_data->get_size(), &m_aac_header, false)) + auto parser = aac::parser_c{}; + parser.add_bytes(m_probe_data->get_buffer(), m_probe_data->get_size()); + if (!parser.frames_available()) return FILE_STATUS_MOREDATA; - mxdebug_if(reader.m_debug_aac, boost::format("first AAC header: %1%\n") % m_aac_header.to_string()); + m_aac_frame = parser.get_frame(); - a_channels = m_aac_header.channels; - a_sample_rate = m_aac_header.sample_rate; + mxdebug_if(reader.m_debug_aac, boost::format("first AAC header: %1%\n") % m_aac_frame.to_string()); + + a_channels = m_aac_frame.m_channels; + a_sample_rate = m_aac_frame.m_sample_rate; return 0; } @@ -1241,12 +1246,7 @@ mpeg_ts_reader_c::create_packetizer(int64_t id) { show_packetizer_info(id, PTZR(track->ptzr)); } else if (track->codec.is(CT_A_AAC)) { - aac_packetizer_c *aac_packetizer = new aac_packetizer_c(this, m_ti, track->m_aac_header.id, track->m_aac_header.profile, track->m_aac_header.sample_rate, track->m_aac_header.channels, false); - track->ptzr = add_packetizer(aac_packetizer); - - if (AAC_PROFILE_SBR == track->m_aac_header.profile) - aac_packetizer->set_audio_output_sampling_freq(track->m_aac_header.sample_rate * 2); - show_packetizer_info(id, aac_packetizer); + create_aac_audio_packetizer(track); } else if (track->codec.is(CT_A_AC3)) { track->ptzr = add_packetizer(new ac3_packetizer_c(this, m_ti, track->a_sample_rate, track->a_channels, track->a_bsid)); @@ -1285,6 +1285,17 @@ mpeg_ts_reader_c::create_packetizer(int64_t id) { m_ptzr_to_track_map[PTZR(track->ptzr)] = track; } +void +mpeg_ts_reader_c::create_aac_audio_packetizer(mpeg_ts_track_ptr const &track) { + auto aac_packetizer = new aac_packetizer_c(this, m_ti, track->m_aac_frame.m_id, track->m_aac_frame.m_profile, track->m_aac_frame.m_sample_rate, track->m_aac_frame.m_channels, false, true); + track->ptzr = add_packetizer(aac_packetizer); + track->converter.reset(new aac_framing_packet_converter_c{PTZR(track->ptzr)}); + + if (AAC_PROFILE_SBR == track->m_aac_frame.m_profile) + aac_packetizer->set_audio_output_sampling_freq(track->m_aac_frame.m_sample_rate * 2); + show_packetizer_info(m_ti.m_id, aac_packetizer); +} + void mpeg_ts_reader_c::create_mpeg1_2_video_packetizer(mpeg_ts_track_ptr &track) { m_ti.m_private_data = track->raw_seq_hdr; diff --git a/src/input/r_mpeg_ts.h b/src/input/r_mpeg_ts.h index 07a28db4e..a2374f26e 100644 --- a/src/input/r_mpeg_ts.h +++ b/src/input/r_mpeg_ts.h @@ -291,7 +291,7 @@ public: // audio related parameters int a_channels, a_sample_rate, a_bits_per_sample, a_bsid; dts_header_t a_dts_header; - aac_header_c m_aac_header; + aac::frame_c m_aac_frame; bool m_apply_dts_timecode_fix, m_use_dts, m_timecodes_wrapped; @@ -433,6 +433,7 @@ private: void create_mpeg1_2_video_packetizer(mpeg_ts_track_ptr &track); void create_mpeg4_p10_es_video_packetizer(mpeg_ts_track_ptr &track); void create_vc1_video_packetizer(mpeg_ts_track_ptr &track); + void create_aac_audio_packetizer(mpeg_ts_track_ptr const &track); void create_hdmv_pgs_subtitles_packetizer(mpeg_ts_track_ptr &track); void create_srt_subtitles_packetizer(mpeg_ts_track_ptr const &track);