From 8288f254ddf95d3a6b830fa30e13f930fa623799 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 27 Apr 2013 13:08:48 +0200 Subject: [PATCH] Refactoring --- src/common/mpeg4_p10.cpp | 50 ++++++++++++++++++-------------------- src/common/mpeg4_p10.h | 10 +++++++- src/output/p_mpeg4_p10.cpp | 10 +++----- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/common/mpeg4_p10.cpp b/src/common/mpeg4_p10.cpp index c602642f3..65f5e4b43 100644 --- a/src/common/mpeg4_p10.cpp +++ b/src/common/mpeg4_p10.cpp @@ -213,6 +213,13 @@ static const struct { { 3, 2 }, { 2, 1 }, }; + +bool +par_extraction_t::is_valid() + const { + return successful && numerator && denominator; +} + }; }; @@ -761,28 +768,25 @@ mpeg4::p10::parse_pps(memory_cptr &buffer, /** Extract the pixel aspect ratio from the MPEG4 layer 10 (AVC) codec data - This function searches a buffer containing the MPEG4 layer 10 (AVC) codec - initialization for the pixel aspectc ratio. If it is found then the - numerator and the denominator are returned, and the aspect ratio - information is removed from the buffer. The new buffer is returned. + This function searches a buffer containing the MPEG4 layer 10 (AVC) + codec initialization for the pixel aspectc ratio. If it is found + then the numerator and the denominator are extracted, and the + aspect ratio information is removed from the buffer. A structure + containing the new buffer, the numerator/denominator and the + success status is returned. \param buffer The buffer containing the MPEG4 layer 10 codec data. - \param par_num The numerator, if found, is stored in this variable. - \param par_den The denominator, if found, is stored in this variable. - \return The new buffer. If the pixel aspect ratio was not found - then both \c par_num and \c par_den are set to 0. + \return A \c par_extraction_t structure. */ -memory_cptr -mpeg4::p10::extract_par(memory_cptr const &buffer, - uint32_t &par_num, - uint32_t &par_den) { +mpeg4::p10::par_extraction_t +mpeg4::p10::extract_par(memory_cptr const &buffer) { try { - auto avcc = avcc_c::unpack(buffer); - auto new_avcc = avcc; - par_num = 1; - par_den = 1; - bool ar_found = false; + auto avcc = avcc_c::unpack(buffer); + auto new_avcc = avcc; + bool ar_found = false; + unsigned int par_num = 1; + unsigned int par_den = 1; new_avcc.m_sps_list.clear(); @@ -810,18 +814,10 @@ mpeg4::p10::extract_par(memory_cptr const &buffer, auto packed_new_avcc = new_avcc.pack(); - if (!ar_found) { - par_num = 0; - par_den = 0; - } - - return packed_new_avcc; + return par_extraction_t{packed_new_avcc, ar_found ? par_num : 0, ar_found ? par_den : 0, ar_found}; } catch(...) { - par_num = 0; - par_den = 0; - - return buffer; + return par_extraction_t{buffer, 0, 0, false}; } } diff --git a/src/common/mpeg4_p10.h b/src/common/mpeg4_p10.h index 8d45efe90..7ffe2a51e 100644 --- a/src/common/mpeg4_p10.h +++ b/src/common/mpeg4_p10.h @@ -136,13 +136,21 @@ struct slice_info_t { } }; +struct par_extraction_t { + memory_cptr new_avcc; + unsigned int numerator, denominator; + bool successful; + + bool is_valid() const; +}; + void nalu_to_rbsp(memory_cptr &buffer); void rbsp_to_nalu(memory_cptr &buffer); bool parse_sps(memory_cptr &buffer, sps_info_t &sps, bool keep_ar_info = false, bool fix_bitstream_frame_rate = false, int64_t duration = -1); bool parse_pps(memory_cptr &buffer, pps_info_t &pps); -memory_cptr extract_par(memory_cptr const &buffer, uint32_t &par_num, uint32_t &par_den); +par_extraction_t extract_par(memory_cptr const &buffer); memory_cptr fix_sps_fps(memory_cptr const &buffer, int64_t duration); bool is_avc_fourcc(const char *fourcc); memory_cptr avcc_to_nalus(const unsigned char *buffer, size_t size); diff --git a/src/output/p_mpeg4_p10.cpp b/src/output/p_mpeg4_p10.cpp index 7f844e5da..6f139d128 100644 --- a/src/output/p_mpeg4_p10.cpp +++ b/src/output/p_mpeg4_p10.cpp @@ -58,16 +58,12 @@ mpeg4_p10_video_packetizer_c::set_headers() { void mpeg4_p10_video_packetizer_c::extract_aspect_ratio() { - uint32_t num = 0, den = 0; + auto result = mpeg4::p10::extract_par(m_ti.m_private_data); - if (!m_ti.m_private_data) + if (!result.is_valid() || display_dimensions_or_aspect_ratio_set()) return; - mpeg4::p10::extract_par(m_ti.m_private_data, num, den); - if (!num || !den || display_dimensions_or_aspect_ratio_set()) - return; - - auto par = static_cast(num) / static_cast(den); + auto par = static_cast(result.numerator) / static_cast(result.denominator); set_video_display_dimensions(1 <= par ? irnd(m_width * par) : m_width, 1 <= par ? m_height : irnd(m_height / par),