Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-21 Thread Jeyapal, Karthick
>On 11/22/17, 5:06 AM, "Marton Balint"  wrote:
>
>Ok, applied the series with some minor whitespace/comment fixes.
Great! Thanks.
>
>Thanks,
>Marton

Regards,
Karthick

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-21 Thread Marton Balint



On Mon, 20 Nov 2017, Jeyapal, Karthick wrote:


On 11/20/17, 12:39 AM, "Marton Balint"  wrote:



Thanks, there is one more thing I still don't get:


[...]

+// 1 second timeout
+for (i = 0; i < 10; i++) {
+av_usleep(10);
+// Sometimes VideoInputFrameArrived is called before 
VideoInputFormatChanged
+// So don't break for bmd_mode == AUTODETECT_DEFAULT_MODE



Even if you get a frame for the default mode, and
VideoInputFrameArrived is called early, the bmdFrameHasNoInputSource
flag should be set, so ctx->bmd_mode remains unknown, therefore you don't
have to handle it specially.

Are you saying that the Decklink drivers are buggy, and there are cases
where you get a frame without the bmdFrameHasNoInputSource flag, and then
a VideoInputFormatChanged callback later?


Yes, there are cases where you get a frame without the bmdFrameHasNoInputSource
flag, and then a VideoInputFormatChanged called later. And it is random.
But I don’t know if it could be called as a driver bug, since the getWidth and 
getHeight would return the correct values.
During my testing, I observed a 1080p30 would randomly get detected as,
AUTODETECT_DEFAULT_MODE because of VideoInputFrameArrived called early.
Hence I added that extra condition to handle it specially.


Ok, applied the series with some minor whitespace/comment fixes.

Thanks,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-20 Thread Jeyapal, Karthick
>On 11/20/17, 12:39 AM, "Marton Balint"  wrote:

>Thanks, there is one more thing I still don't get:

[...]
>> +// 1 second timeout
>> +for (i = 0; i < 10; i++) {
>> +av_usleep(10);
>> +// Sometimes VideoInputFrameArrived is called before 
>> VideoInputFormatChanged
>> +// So don't break for bmd_mode == AUTODETECT_DEFAULT_MODE

>Even if you get a frame for the default mode, and 
>VideoInputFrameArrived is called early, the bmdFrameHasNoInputSource 
>flag should be set, so ctx->bmd_mode remains unknown, therefore you don't 
>have to handle it specially.
>
>Are you saying that the Decklink drivers are buggy, and there are cases 
>where you get a frame without the bmdFrameHasNoInputSource flag, and then 
>a VideoInputFormatChanged callback later?

Yes, there are cases where you get a frame without the bmdFrameHasNoInputSource
flag, and then a VideoInputFormatChanged called later. And it is random.
But I don’t know if it could be called as a driver bug, since the getWidth and 
getHeight would return the correct values.
During my testing, I observed a 1080p30 would randomly get detected as,
AUTODETECT_DEFAULT_MODE because of VideoInputFrameArrived called early.
Hence I added that extra condition to handle it specially.

>> +if (ctx->bmd_mode != bmdModeUnknown &&
>> +ctx->bmd_mode != AUTODETECT_DEFAULT_MODE)
>> +break;
>> +}
>> +

[...]

>Regards,
>Marton

regards,
Karthick


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-19 Thread Marton Balint


On Thu, 16 Nov 2017, Jeyapal, Karthick wrote:


On 11/16/17, 1:11 AM, "Marton Balint"  wrote:


Thanks for the reply.


For the first patch, I think you forgot to call ff_decklink_set_configs in
decklink_enc.

ff_decklink_set_configs is not doing anything related to decklink_enc
In any case I have added the same and have attached the new patch


For the second patch here are some comments:

I have done all suggested modifications and the new patch is attached.


Thanks, there is one more thing I still don't get:

[...]


-static HRESULT decklink_start_input(AVFormatContext *avctx)
-{
-struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
+static int decklink_autodetect(struct decklink_cctx *cctx) {
 struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
+DECKLINK_BOOL autodetect_supported = false;
+int i;
+
+if (ctx->attr->GetFlag(BMDDeckLinkSupportsInputFormatDetection, 
&autodetect_supported) != S_OK)
+return -1;
+if (autodetect_supported == false)
+return -1;
+
+ctx->autodetect = 1;
+ctx->bmd_mode  = bmdModeUnknown;
+if (ctx->dli->EnableVideoInput(AUTODETECT_DEFAULT_MODE,
+   bmdFormat8BitYUV,
+   bmdVideoInputEnableFormatDetection) != 
S_OK) {
+return -1;
+}
+
+if (ctx->dli->StartStreams() != S_OK) {
+return -1;
+}
+
+// 1 second timeout
+for (i = 0; i < 10; i++) {
+av_usleep(10);
+// Sometimes VideoInputFrameArrived is called before 
VideoInputFormatChanged
+// So don't break for bmd_mode == AUTODETECT_DEFAULT_MODE


Even if you get a frame for the default mode, and 
VideoInputFrameArrived is called early, the bmdFrameHasNoInputSource 
flag should be set, so ctx->bmd_mode remains unknown, therefore you don't 
have to handle it specially.


Are you saying that the Decklink drivers are buggy, and there are cases 
where you get a frame without the bmdFrameHasNoInputSource flag, and then 
a VideoInputFormatChanged callback later?



+if (ctx->bmd_mode != bmdModeUnknown &&
+ctx->bmd_mode != AUTODETECT_DEFAULT_MODE)
+break;
+}
+


[...]

Regards,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-16 Thread Jeyapal, Karthick
>On 11/16/17, 1:11 AM, "Marton Balint"  wrote:

Thanks for the reply.

>For the first patch, I think you forgot to call ff_decklink_set_configs in 
>decklink_enc.
ff_decklink_set_configs is not doing anything related to decklink_enc
In any case I have added the same and have attached the new patch

>For the second patch here are some comments:
I have done all suggested modifications and the new patch is attached.

>Regards,
>Marton

Regards,
Karthick



0001-libavdevice-decklink-Refactored-ff_decklink_set_form.patch
Description: 0001-libavdevice-decklink-Refactored-ff_decklink_set_form.patch


0002-libavdevice-decklink_dec-Autodetect-the-video-input-.patch
Description: 0002-libavdevice-decklink_dec-Autodetect-the-video-input-.patch
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-15 Thread Marton Balint


On Tue, 7 Nov 2017, Jeyapal, Karthick wrote:


On 11/6/17, 6:19 AM, "Marton Balint"  wrote:


On Fri, 27 Oct 2017, Jeyapal, Karthick wrote:



Please find the patch attached.



Thanks, below some comments:


Thanks a lot for your detailed comments. I have incorporated all your comments 
in this new patch(es).
Also, I have split it as two patches as you suggested. Please find them 
attached.


For the first patch, I think you forgot to call ff_decklink_set_configs in 
decklink_enc.


For the second patch here are some comments:


From 041bed1ef07e59419f1befda3f064f0fe3f8e30b Mon Sep 17 00:00:00 2001
From: Karthick J 
Date: Fri, 27 Oct 2017 12:00:23 +0530
Subject: [PATCH 2/2] libavdevice/decklink_dec: Autodetect the video input
 format

When -format_code is not specified autodetection will happen
---
 doc/indevs.texi |  2 ++
 libavdevice/decklink_common.cpp |  3 --
 libavdevice/decklink_common.h   |  1 +
 libavdevice/decklink_common_c.h |  6 
 libavdevice/decklink_dec.cpp| 78 ++---
 5 files changed, 74 insertions(+), 16 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index d308bbf..56066bf 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -238,6 +238,8 @@ This sets the input video format to the format given by the 
FourCC. To see
 the supported values of your device(s) use @option{list_formats}.
 Note that there is a FourCC @option{'pal '} that can also be used
 as @option{pal} (3 letters).
+Default behavior is autodetection of the input video format, if the hardware
+supports it.

 @item bm_v210
 This is a deprecated option, you can use @option{raw_format} instead.
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index b952e74..6ef2c52 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -75,7 +75,6 @@ static char *dup_wchar_to_utf8(wchar_t *w)
 #define DECKLINK_STROLECHAR *
 #define DECKLINK_STRDUP dup_wchar_to_utf8
 #define DECKLINK_FREE(s) SysFreeString(s)
-#define DECKLINK_BOOL BOOL
 #elif defined(__APPLE__)
 static char *dup_cfstring_to_utf8(CFStringRef w)
 {
@@ -86,13 +85,11 @@ static char *dup_cfstring_to_utf8(CFStringRef w)
 #define DECKLINK_STRconst __CFString *
 #define DECKLINK_STRDUP dup_cfstring_to_utf8
 #define DECKLINK_FREE(s) CFRelease(s)
-#define DECKLINK_BOOL bool
 #else
 #define DECKLINK_STRconst char *
 #define DECKLINK_STRDUP av_strdup
 /* free() is needed for a string returned by the DeckLink SDL. */
 #define DECKLINK_FREE(s) free((void *) s)
-#define DECKLINK_BOOL bool
 #endif

 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 4345156..d18b643 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -95,6 +95,7 @@ struct decklink_ctx {
 pthread_mutex_t mutex;
 pthread_cond_t cond;
 int frames_buffer_available_spots;
+int autodetect;

 int channels;
 int audio_depth;
diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h
index 368ac25..4e4c369 100644
--- a/libavdevice/decklink_common_c.h
+++ b/libavdevice/decklink_common_c.h
@@ -23,6 +23,12 @@
 #ifndef AVDEVICE_DECKLINK_COMMON_C_H
 #define AVDEVICE_DECKLINK_COMMON_C_H

+#ifdef _WIN32
+#define DECKLINK_BOOL BOOL
+#else
+#define DECKLINK_BOOL bool
+#endif
+


This rather belongs to decklink_common.h.


 typedef enum DecklinkPtsSource {
 PTS_SRC_AUDIO = 1,
 PTS_SRC_VIDEO = 2,
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 242a194..60017e4 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -36,6 +36,7 @@ extern "C" {
 #include "libavutil/avutil.h"
 #include "libavutil/common.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/time.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/reverse.h"
@@ -49,6 +50,7 @@ extern "C" {
 #include "decklink_dec.h"

 #define MAX_WIDTH_VANC 1920
+const BMDDisplayMode AUTODETECT_DEFAULT_MODE = bmdModeNTSC;

 typedef struct VANCLineNumber {
 BMDDisplayMode mode;
@@ -634,6 +636,17 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 BMDTimeValue frameDuration;
 int64_t wallclock = 0;

+if (ctx->autodetect) {
+pthread_mutex_lock(&ctx->mutex);


Do you still need a mutex? VideoInputFrameArrived and
VideoInputFormatChanged are called from the same thread, no?


+if (videoFrame && !(videoFrame->GetFlags() & bmdFrameHasNoInputSource) 
&&
+ctx->bmd_mode == bmdModeUnknown)
+{
+ctx->bmd_mode = AUTODETECT_DEFAULT_MODE;
+}
+pthread_mutex_unlock(&ctx->mutex);
+return S_OK;
+}
+
 ctx->frameCount++;
 if (ctx->audio_pts_source == PTS_SRC_WALLCLOCK || ctx->video_pts_source == 
PTS_SRC_WALLCLOCK)
 wallclock = av_gettime_relative();
@@ -794,17 +807,47 @@

Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-06 Thread Jeyapal, Karthick
>On 11/6/17, 6:19 AM, "Marton Balint"  wrote:
>
>>On Fri, 27 Oct 2017, Jeyapal, Karthick wrote:
>
>> Please find the patch attached.
>>
>
>Thanks, below some comments:

Thanks a lot for your detailed comments. I have incorporated all your comments 
in this new patch(es).
Also, I have split it as two patches as you suggested. Please find them 
attached.

Regards,
Karthick




0001-libavdevice-decklink-Refactored-ff_decklink_set_form.patch
Description: 0001-libavdevice-decklink-Refactored-ff_decklink_set_form.patch


0002-libavdevice-decklink_dec-Autodetect-the-video-input-.patch
Description: 0002-libavdevice-decklink_dec-Autodetect-the-video-input-.patch
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-05 Thread Aaron Levinson

See comments below.

Aaron Levinson

On 11/5/2017 4:49 PM, Marton Balint wrote:


On Fri, 27 Oct 2017, Jeyapal, Karthick wrote:


Please find the patch attached.



Thanks, below some comments:


From b18679b91a79f5e23a5ad23ae70f3862a34ddfb8 Mon Sep 17 00:00:00 2001
From: Karthick J 
Date: Fri, 27 Oct 2017 12:00:23 +0530
Subject: [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input 
format


When -format_code is not specified autodetection will happen
---
 doc/indevs.texi |  1 +
 libavdevice/decklink_common.cpp | 33 ++-
 libavdevice/decklink_common.h   |  8 +
 libavdevice/decklink_dec.cpp    | 70 
+++--

 4 files changed, 89 insertions(+), 23 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index d308bbf..74bfcc5 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -238,6 +238,7 @@ This sets the input video format to the format 
given by the FourCC. To see

 the supported values of your device(s) use @option{list_formats}.
 Note that there is a FourCC @option{'pal '} that can also be used
 as @option{pal} (3 letters).
+Default behavior is autodetection of the input video format


... video format, if the hardware supports it.



 @item bm_v210
 This is a deprecated option, you can use @option{raw_format} instead.
diff --git a/libavdevice/decklink_common.cpp 
b/libavdevice/decklink_common.cpp

index 2bd63ac..757f419 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -148,23 +148,10 @@ static DECKLINK_BOOL field_order_eq(enum 
AVFieldOrder field_order, BMDFieldDomin

 return false;
 }

-int ff_decklink_set_format(AVFormatContext *avctx,
-   int width, int height,
-   int tb_num, int tb_den,
-   enum AVFieldOrder field_order,
-   decklink_direction_t direction, int num)
-{
+void ff_decklink_set_duplex_mode(AVFormatContext *avctx) {
 struct decklink_cctx *cctx = (struct decklink_cctx 
*)avctx->priv_data;

 struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
-    BMDDisplayModeSupport support;
-    IDeckLinkDisplayModeIterator *itermode;
-    IDeckLinkDisplayMode *mode;
-    int i = 1;
 HRESULT res;
-
-    av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size 
%dx%d, frame timing %d/%d, field order %d, direction %d, mode number 
%d, format code %s\n",
-    width, height, tb_num, tb_den, field_order, direction, num, 
(cctx->format_code) ? cctx->format_code : "(unset)");

-
 if (ctx->duplex_mode) {
 DECKLINK_BOOL duplex_supported = false;

@@ -181,6 +168,24 @@ int ff_decklink_set_format(AVFormatContext *avctx,
 av_log(avctx, AV_LOG_WARNING, "Unable to set duplex mode, 
because it is not supported.\n");

 }
 }
+}


You factorized this out, but keep in mind that decklink_enc might also 
use this
to set duplex mode. (even if there is no option to do that at the 
moment). Also

it would make sense to rename the function and also put the input selection
logic here, because even if you autodetect, you should select the input
(sdi/hdmi/etc) first.

This factorization should be a separate patch for easier review.


+
+int ff_decklink_set_format(AVFormatContext *avctx,
+   int width, int height,
+   int tb_num, int tb_den,
+   enum AVFieldOrder field_order,
+   decklink_direction_t direction, int num)
+{
+    struct decklink_cctx *cctx = (struct decklink_cctx 
*)avctx->priv_data;

+    struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
+    BMDDisplayModeSupport support;
+    IDeckLinkDisplayModeIterator *itermode;
+    IDeckLinkDisplayMode *mode;
+    int i = 1;
+    HRESULT res;
+
+    av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size 
%dx%d, frame timing %d/%d, field order %d, direction %d, mode number 
%d, format code %s\n",
+    width, height, tb_num, tb_den, field_order, direction, num, 
(cctx->format_code) ? cctx->format_code : "(unset)");


 if (direction == DIRECTION_IN) {
 int ret;
diff --git a/libavdevice/decklink_common.h 
b/libavdevice/decklink_common.h

index b6acb01..f38fc14 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -31,6 +31,12 @@
 class decklink_output_callback;
 class decklink_input_callback;

+typedef enum autodetect_state {
+    AUTODETECT_RESET = 0,


Maybe something like AUTODETECT_INACTIVE is a better name?


+    AUTODETECT_START,
+    AUTODETECT_DONE,
+} autodetect_state;
+
 typedef struct AVPacketQueue {
 AVPacketList *first_pkt, *last_pkt;
 int nb_packets;
@@ -95,6 +101,7 @@ struct decklink_ctx {
 pthread_mutex_t mutex;
 pthread_cond_t cond;
 int frames_buffer_available_spots;
+    autodetect_state autodetect;

 int channels;
 int audio_depth;
@@ -134,6 +141,7 @@ stati

Re: [FFmpeg-devel] [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

2017-11-05 Thread Marton Balint


On Fri, 27 Oct 2017, Jeyapal, Karthick wrote:


Please find the patch attached.



Thanks, below some comments:


From b18679b91a79f5e23a5ad23ae70f3862a34ddfb8 Mon Sep 17 00:00:00 2001
From: Karthick J 
Date: Fri, 27 Oct 2017 12:00:23 +0530
Subject: [PATCH 1/1] avdevice/decklink_dec: Autodetect the video input format

When -format_code is not specified autodetection will happen
---
 doc/indevs.texi |  1 +
 libavdevice/decklink_common.cpp | 33 ++-
 libavdevice/decklink_common.h   |  8 +
 libavdevice/decklink_dec.cpp| 70 +++--
 4 files changed, 89 insertions(+), 23 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index d308bbf..74bfcc5 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -238,6 +238,7 @@ This sets the input video format to the format given by the 
FourCC. To see
 the supported values of your device(s) use @option{list_formats}.
 Note that there is a FourCC @option{'pal '} that can also be used
 as @option{pal} (3 letters).
+Default behavior is autodetection of the input video format


... video format, if the hardware supports it.



 @item bm_v210
 This is a deprecated option, you can use @option{raw_format} instead.
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 2bd63ac..757f419 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -148,23 +148,10 @@ static DECKLINK_BOOL field_order_eq(enum AVFieldOrder 
field_order, BMDFieldDomin
 return false;
 }

-int ff_decklink_set_format(AVFormatContext *avctx,
-   int width, int height,
-   int tb_num, int tb_den,
-   enum AVFieldOrder field_order,
-   decklink_direction_t direction, int num)
-{
+void ff_decklink_set_duplex_mode(AVFormatContext *avctx) {
 struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
 struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
-BMDDisplayModeSupport support;
-IDeckLinkDisplayModeIterator *itermode;
-IDeckLinkDisplayMode *mode;
-int i = 1;
 HRESULT res;
-
-av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame 
timing %d/%d, field order %d, direction %d, mode number %d, format code %s\n",
-width, height, tb_num, tb_den, field_order, direction, num, (cctx->format_code) ? 
cctx->format_code : "(unset)");
-
 if (ctx->duplex_mode) {
 DECKLINK_BOOL duplex_supported = false;

@@ -181,6 +168,24 @@ int ff_decklink_set_format(AVFormatContext *avctx,
 av_log(avctx, AV_LOG_WARNING, "Unable to set duplex mode, because it is 
not supported.\n");
 }
 }
+}


You factorized this out, but keep in mind that decklink_enc might also use this
to set duplex mode. (even if there is no option to do that at the moment). Also
it would make sense to rename the function and also put the input selection
logic here, because even if you autodetect, you should select the input
(sdi/hdmi/etc) first.

This factorization should be a separate patch for easier review.


+
+int ff_decklink_set_format(AVFormatContext *avctx,
+   int width, int height,
+   int tb_num, int tb_den,
+   enum AVFieldOrder field_order,
+   decklink_direction_t direction, int num)
+{
+struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
+struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
+BMDDisplayModeSupport support;
+IDeckLinkDisplayModeIterator *itermode;
+IDeckLinkDisplayMode *mode;
+int i = 1;
+HRESULT res;
+
+av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame 
timing %d/%d, field order %d, direction %d, mode number %d, format code %s\n",
+width, height, tb_num, tb_den, field_order, direction, num, (cctx->format_code) ? 
cctx->format_code : "(unset)");

 if (direction == DIRECTION_IN) {
 int ret;
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index b6acb01..f38fc14 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -31,6 +31,12 @@
 class decklink_output_callback;
 class decklink_input_callback;

+typedef enum autodetect_state {
+AUTODETECT_RESET = 0,


Maybe something like AUTODETECT_INACTIVE is a better name?


+AUTODETECT_START,
+AUTODETECT_DONE,
+} autodetect_state;
+
 typedef struct AVPacketQueue {
 AVPacketList *first_pkt, *last_pkt;
 int nb_packets;
@@ -95,6 +101,7 @@ struct decklink_ctx {
 pthread_mutex_t mutex;
 pthread_cond_t cond;
 int frames_buffer_available_spots;
+autodetect_state autodetect;

 int channels;
 int audio_depth;
@@ -134,6 +141,7 @@ static const BMDVideoConnection 
decklink_video_connection_map[] = {
 };

 HRESULT ff_decklink_get_display_n