From 188436f9814551d1a8a69abbea76d151acd54224 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 6 Jul 2021 09:37:21 +0200 Subject: [PATCH] AVC & HEVC packetizers: use rationals for calculation of display dimensions --- src/output/p_avc.cpp | 6 +++--- src/output/p_avc_es.cpp | 2 +- src/output/p_hevc.cpp | 6 +++--- src/output/p_hevc_es.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/output/p_avc.cpp b/src/output/p_avc.cpp index ad8623e16..d751f522b 100644 --- a/src/output/p_avc.cpp +++ b/src/output/p_avc.cpp @@ -91,10 +91,10 @@ avc_video_packetizer_c::extract_aspect_ratio() { if (!result.is_valid() || display_dimensions_or_aspect_ratio_set()) return; - auto par = static_cast(result.numerator) / static_cast(result.denominator); + auto par = mtx::rational(result.numerator, result.denominator); - set_video_display_dimensions(1 <= par ? std::llround(m_width * par) : m_width, - 1 <= par ? m_height : std::llround(m_height / par), + set_video_display_dimensions(1 <= par ? mtx::to_int_rounded(m_width * par) : m_width, + 1 <= par ? m_height : mtx::to_int_rounded(m_height / par), generic_packetizer_c::ddu_pixels, OPTION_SOURCE_BITSTREAM); diff --git a/src/output/p_avc_es.cpp b/src/output/p_avc_es.cpp index 3d1a6b03a..c00fe999e 100644 --- a/src/output/p_avc_es.cpp +++ b/src/output/p_avc_es.cpp @@ -141,7 +141,7 @@ avc_es_video_packetizer_c::handle_aspect_ratio() { mxdebug_if(m_debug_aspect_ratio, fmt::format("PAR {0} pixel_width/hgith {1}/{2} display_width/height {3}/{4}\n", - static_cast(m_parser.get_par()), m_hvideo_pixel_width, m_hvideo_pixel_height, m_ti.m_display_width, m_ti.m_display_height)); + m_parser.get_par(), m_hvideo_pixel_width, m_hvideo_pixel_height, m_ti.m_display_width, m_ti.m_display_height)); } void diff --git a/src/output/p_hevc.cpp b/src/output/p_hevc.cpp index 6cbbd9fc7..01f4c4d00 100644 --- a/src/output/p_hevc.cpp +++ b/src/output/p_hevc.cpp @@ -99,10 +99,10 @@ hevc_video_packetizer_c::extract_aspect_ratio() { if (!result.is_valid() || display_dimensions_or_aspect_ratio_set()) return; - auto par = static_cast(result.numerator) / static_cast(result.denominator); + auto par = mtx::rational(result.numerator, result.denominator); - set_video_display_dimensions(1 <= par ? std::llround(m_width * par) : m_width, - 1 <= par ? m_height : std::llround(m_height / par), + set_video_display_dimensions(1 <= par ? mtx::to_int_rounded(m_width * par) : m_width, + 1 <= par ? m_height : mtx::to_int_rounded(m_height / par), generic_packetizer_c::ddu_pixels, OPTION_SOURCE_BITSTREAM); diff --git a/src/output/p_hevc_es.cpp b/src/output/p_hevc_es.cpp index 027d431f8..d3b2a8093 100644 --- a/src/output/p_hevc_es.cpp +++ b/src/output/p_hevc_es.cpp @@ -128,7 +128,7 @@ hevc_es_video_packetizer_c::handle_aspect_ratio() { mxdebug_if(m_debug_aspect_ratio, fmt::format("PAR {0} pixel_width/hgith {1}/{2} display_width/height {3}/{4}\n", - static_cast(m_parser.get_par()), m_hvideo_pixel_width, m_hvideo_pixel_height, m_ti.m_display_width, m_ti.m_display_height)); + m_parser.get_par(), m_hvideo_pixel_width, m_hvideo_pixel_height, m_ti.m_display_width, m_ti.m_display_height)); } void