From f2121dd897548d29d5ba73aff4493f2cca3fc6c7 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 23 Aug 2021 23:03:08 +0200 Subject: [PATCH] AVC/HEVC ES: re-order functions --- src/common/avc/es_parser.cpp | 64 +++++++++++++++++------------------ src/common/hevc/es_parser.cpp | 22 ++++++------ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/common/avc/es_parser.cpp b/src/common/avc/es_parser.cpp index 234ac56f9..90d531d1b 100644 --- a/src/common/avc/es_parser.cpp +++ b/src/common/avc/es_parser.cpp @@ -95,6 +95,38 @@ es_parser_c::clear() { m_parsed_position = 0; } +void +es_parser_c::flush_incomplete_frame() { + if (!m_have_incomplete_frame || !m_configuration_record_ready) + return; + + m_frames.push_back(m_incomplete_frame); + m_incomplete_frame.clear(); + m_have_incomplete_frame = false; +} + +void +es_parser_c::add_sps_and_pps_to_extra_data() { + mxdebug_if(m_debug_sps_pps_changes, fmt::format("avc: adding all SPS & PPS before key frame due to changes from AVCC\n")); + + m_extra_data.erase(std::remove_if(m_extra_data.begin(), m_extra_data.end(), [this](memory_cptr const &nalu) -> bool { + if (nalu->get_size() < static_cast(m_nalu_size_length + 1)) + return true; + + auto const type = *(nalu->get_buffer() + m_nalu_size_length) & 0x1f; + return (type == NALU_TYPE_SEQ_PARAM) || (type == NALU_TYPE_PIC_PARAM); + }), m_extra_data.end()); + + std::vector tmp; + tmp.reserve(m_extra_data.size() + m_sps_list.size() + m_pps_list.size()); + + std::transform(m_sps_list.begin(), m_sps_list.end(), std::back_inserter(tmp), [this](memory_cptr const &nalu) { return create_nalu_with_size(nalu); }); + std::transform(m_pps_list.begin(), m_pps_list.end(), std::back_inserter(tmp), [this](memory_cptr const &nalu) { return create_nalu_with_size(nalu); }); + tmp.insert(tmp.end(), m_extra_data.begin(), m_extra_data.end()); + + m_extra_data = std::move(tmp); +} + bool es_parser_c::flush_decision(mtx::avc_hevc::slice_info_t &si, mtx::avc_hevc::slice_info_t &ref) { @@ -133,38 +165,6 @@ es_parser_c::flush_decision(mtx::avc_hevc::slice_info_t &si, return false; } -void -es_parser_c::flush_incomplete_frame() { - if (!m_have_incomplete_frame || !m_configuration_record_ready) - return; - - m_frames.push_back(m_incomplete_frame); - m_incomplete_frame.clear(); - m_have_incomplete_frame = false; -} - -void -es_parser_c::add_sps_and_pps_to_extra_data() { - mxdebug_if(m_debug_sps_pps_changes, fmt::format("avc: adding all SPS & PPS before key frame due to changes from AVCC\n")); - - m_extra_data.erase(std::remove_if(m_extra_data.begin(), m_extra_data.end(), [this](memory_cptr const &nalu) -> bool { - if (nalu->get_size() < static_cast(m_nalu_size_length + 1)) - return true; - - auto const type = *(nalu->get_buffer() + m_nalu_size_length) & 0x1f; - return (type == NALU_TYPE_SEQ_PARAM) || (type == NALU_TYPE_PIC_PARAM); - }), m_extra_data.end()); - - std::vector tmp; - tmp.reserve(m_extra_data.size() + m_sps_list.size() + m_pps_list.size()); - - std::transform(m_sps_list.begin(), m_sps_list.end(), std::back_inserter(tmp), [this](memory_cptr const &nalu) { return create_nalu_with_size(nalu); }); - std::transform(m_pps_list.begin(), m_pps_list.end(), std::back_inserter(tmp), [this](memory_cptr const &nalu) { return create_nalu_with_size(nalu); }); - tmp.insert(tmp.end(), m_extra_data.begin(), m_extra_data.end()); - - m_extra_data = std::move(tmp); -} - void es_parser_c::handle_slice_nalu(memory_cptr const &nalu, uint64_t nalu_pos) { diff --git a/src/common/hevc/es_parser.cpp b/src/common/hevc/es_parser.cpp index 71fc48d03..eb571e6aa 100644 --- a/src/common/hevc/es_parser.cpp +++ b/src/common/hevc/es_parser.cpp @@ -107,6 +107,17 @@ es_parser_c::clear() { m_parsed_position = 0; } +void +es_parser_c::flush_incomplete_frame() { + if (m_pending_frame_data.empty() || !m_configuration_record_ready) + return; + + build_frame_data(); + + m_frames.push_back(m_incomplete_frame); + m_incomplete_frame.clear(); +} + void es_parser_c::add_parameter_sets_to_extra_data() { std::unordered_map is_in_extra_data; @@ -139,17 +150,6 @@ es_parser_c::add_parameter_sets_to_extra_data() { m_extra_data_initial.clear(); } -void -es_parser_c::flush_incomplete_frame() { - if (m_pending_frame_data.empty() || !m_configuration_record_ready) - return; - - build_frame_data(); - - m_frames.push_back(m_incomplete_frame); - m_incomplete_frame.clear(); -} - void es_parser_c::add_nalu_to_extra_data(memory_cptr const &nalu, extra_data_position_e position) {