[FFmpeg-devel] [PATCH 2/2] decklink: enhancement: mode selection with AVRational

Matthias Hunstock atze at fem.tu-ilmenau.de
Sat Jul 9 20:36:22 EEST 2016


When finding a video mode based on frame size and frame rate,
use AVRational methods instead of simple comparison. Also fixes
a swap of num and den and add runtime debug level information.

Signed-off-by: Matthias Hunstock <atze at fem.tu-ilmenau.de>
---
 libavdevice/decklink_common.cpp | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index b0f245f..fcdbef8 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -143,6 +143,9 @@ int ff_decklink_set_format(AVFormatContext *avctx,
     int i = 1;
     HRESULT res;
 
+    av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame timing %d/%d, direction %d, mode number %d\n",
+        width, height, tb_num, tb_den, direction, num);
+
     if (ctx->duplex_mode) {
         DECKLINK_BOOL duplex_supported = false;
 
@@ -178,29 +181,26 @@ int ff_decklink_set_format(AVFormatContext *avctx,
             return AVERROR(EIO);
     }
 
-
-    if (tb_num == 1) {
-        tb_num *= 1000;
-        tb_den *= 1000;
-    }
+    AVRational target_tb = av_make_q(tb_num, tb_den);
     ctx->bmd_mode = bmdModeUnknown;
     while ((ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&mode) == S_OK) {
-        BMDTimeValue bmd_tb_num, bmd_tb_den;
+        BMDTimeValue bmd_tb_duration, bmd_tb_timescale;
         int bmd_width  = mode->GetWidth();
         int bmd_height = mode->GetHeight();
 
-        mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den);
+        mode->GetFrameRate(&bmd_tb_duration, &bmd_tb_timescale);
+        AVRational mode_tb = av_make_q(bmd_tb_timescale, bmd_tb_duration);
 
         if ((bmd_width == width && bmd_height == height &&
-            bmd_tb_num == tb_num && bmd_tb_den == tb_den) || i == num) {
+            (!av_cmp_q(mode_tb, target_tb))) || i == num) {
             ctx->bmd_mode   = mode->GetDisplayMode();
             ctx->bmd_width  = bmd_width;
             ctx->bmd_height = bmd_height;
-            ctx->bmd_tb_den = bmd_tb_den;
-            ctx->bmd_tb_num = bmd_tb_num;
+            ctx->bmd_tb_den = bmd_tb_duration;
+            ctx->bmd_tb_num = bmd_tb_timescale;
             ctx->bmd_field_dominance = mode->GetFieldDominance();
             av_log(avctx, AV_LOG_INFO, "Found Decklink mode %d x %d with rate %.2f%s\n",
-                bmd_width, bmd_height, (float)bmd_tb_den/(float)bmd_tb_num,
+                bmd_width, bmd_height, av_q2d(mode_tb),
                 (ctx->bmd_field_dominance==bmdLowerFieldFirst || ctx->bmd_field_dominance==bmdUpperFieldFirst)?"(i)":"");
         }
 
-- 
2.1.4



More information about the ffmpeg-devel mailing list