From 4b74b43fdb2153e48de8141a48b7990aad6671b5 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 6 Jul 2021 09:23:04 +0200 Subject: [PATCH] Ogg/OGM reader: use rationals for calculation of display dimensions & frame rate --- src/input/r_ogm.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/input/r_ogm.cpp b/src/input/r_ogm.cpp index 541ce1986..0dfcde2db 100644 --- a/src/input/r_ogm.cpp +++ b/src/input/r_ogm.cpp @@ -1487,8 +1487,8 @@ generic_packetizer_c * ogm_v_theora_demuxer_c::create_packetizer() { m_ti.m_private_data = lace_memory_xiph(packet_data); - double fps = (double)theora.frn / (double)theora.frd; - generic_packetizer_c *ptzr_obj = new theora_video_packetizer_c(reader, m_ti, static_cast(1'000'000'000.0 / fps), theora.fmbw, theora.fmbh); + auto frame_rate = mtx::rational(theora.frn, theora.frd); + auto ptzr_obj = new theora_video_packetizer_c(reader, m_ti, mtx::to_int(1'000'000'000 / frame_rate), theora.fmbw, theora.fmbh); reader->show_packetizer_info(m_ti.m_id, *ptzr_obj); @@ -1555,12 +1555,12 @@ ogm_v_vp8_demuxer_c::initialize() { unsigned int par_den = get_uint16_be(&vp8_header.par_den); if ((0 != par_num) && (0 != par_den)) { - if ((static_cast(pixel_width) / static_cast(pixel_height)) < (static_cast(par_num) / static_cast(par_den))) { - display_width = std::llround(static_cast(pixel_width) * par_num / par_den); + if (mtx::rational(pixel_width, pixel_height) < mtx::rational(par_num, par_den)) { + display_width = mtx::to_int_rounded(mtx::rational(pixel_width * par_num, par_den)); display_height = pixel_height; } else { display_width = pixel_width; - display_height = std::llround(static_cast(pixel_height) * par_den / par_num); + display_height = mtx::to_int_rounded(mtx::rational(pixel_height * par_den, par_num)); } } else { @@ -1570,7 +1570,7 @@ ogm_v_vp8_demuxer_c::initialize() { frame_rate_num = static_cast(get_uint32_be(&vp8_header.frame_rate_num)); frame_rate_den = static_cast(get_uint32_be(&vp8_header.frame_rate_den)); - default_duration = frame_rate_den * 1000000000ull / frame_rate_num; + default_duration = mtx::to_int(mtx::rational(frame_rate_den, frame_rate_num) * 1'000'000'000); } generic_packetizer_c *