[FFmpeg-devel] [PATCH 6/6] avdevice/dshow: add config dialog command for crossbar and tv tuner

Diederick Niehorster dcnieho at gmail.com
Wed Jun 2 14:29:01 EEST 2021


The "show config dialog" command message can now also trigger dialog boxes for the crossbar connecting pins filter the analog tuner audio / analog tuner filters. _Untested_ as I do not have either device.

Signed-off-by: Diederick Niehorster <dcnieho at gmail.com>
---
 libavdevice/dshow.c          | 78 +++++++++++++++++++++++++------
 libavdevice/dshow_capture.h  | 10 ++++
 libavdevice/dshow_crossbar.c | 91 +++++++++++++++++++++++-------------
 3 files changed, 132 insertions(+), 47 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 561b85f4e0..d274d93dc3 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -60,6 +60,11 @@ dshow_read_close(AVFormatContext *s)
     struct dshow_ctx *ctx = s->priv_data;
     PacketList *pktl;
 
+    if (ctx->graph_builder2[VideoDevice])
+        ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]);
+    if (ctx->graph_builder2[AudioDevice])
+        ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]);
+
     if (ctx->control) {
         IMediaControl_Stop(ctx->control);
         IMediaControl_Release(ctx->control);
@@ -873,6 +878,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
         av_log(avctx, AV_LOG_ERROR, "Could not create CaptureGraphBuilder2\n");
         goto error;
     }
+    ctx->graph_builder2[devtype] = graph_builder2;
     ICaptureGraphBuilder2_SetFiltergraph(graph_builder2, graph);
     if (r != S_OK) {
         av_log(avctx, AV_LOG_ERROR, "Could not set graph for CaptureGraphBuilder2\n");
@@ -897,9 +903,6 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
     ret = 0;
 
 error:
-    if (graph_builder2 != NULL)
-        ICaptureGraphBuilder2_Release(graph_builder2);
-
     if (pers_stream)
         IPersistStream_Release(pers_stream);
 
@@ -912,11 +915,11 @@ error:
     return ret;
 }
 
-static int dshow_control_message(AVFormatContext* avctx, int type, void* data, size_t data_size)
+static int dshow_control_message(AVFormatContext *avctx, int type, void *data, size_t data_size)
 {
-    struct dshow_ctx* ctx = avctx->priv_data;
+    struct dshow_ctx *ctx = avctx->priv_data;
     int run_state = ctx->is_running;
-    int r;
+    HRESULT hr;
 
     switch (type) {
     case AV_APP_TO_DEV_PAUSE:
@@ -930,7 +933,14 @@ static int dshow_control_message(AVFormatContext* avctx, int type, void* data, s
         break;
     case AV_APP_TO_DEV_CONFIG:
     {
-        int dialog = *(int*)data;
+        /*
+         * Documentation of dialog variable:
+         * 1st bit: if set, audio device, if not set, video device
+         * 2nd bit: if set, show property dialog for audio/video capture device
+         * 3rd bit: if set, show property dialog for crossbar connecting pins filter on audio/video device
+         * 4th bit: if set, show property dialog for analog tuner audio / analog tuner filter
+         */
+        int dialog = *(int *) data;
         enum dshowDeviceType devtype = (dialog & 1) ? AudioDevice : VideoDevice;
         if (dialog & 2) {
             // device_dialog
@@ -939,27 +949,67 @@ static int dshow_control_message(AVFormatContext* avctx, int type, void* data, s
         }
         else if (dialog & 2) {
             // crossbar_connection_dialog
-            // TODO
+            if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) {
+                IAMCrossbar *cross_bar = NULL;
+                IBaseFilter *cross_bar_base_filter = NULL;
+                hr = ff_dshow_get_crossbar_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], cross_bar, &cross_bar_base_filter);
+
+                if (hr == S_OK && cross_bar_base_filter)
+                    ff_dshow_show_filter_properties(cross_bar_base_filter, avctx);
+
+                if (cross_bar)
+                    IAMCrossbar_Release(cross_bar);
+                if (cross_bar_base_filter)
+                    IBaseFilter_Release(cross_bar_base_filter);
+            }
         }
         else if (dialog & 4) {
             // tv_tuner_dialog
-            // TODO
+            if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) {
+                if (devtype == VideoDevice) {
+                    IAMTVTuner *tv_tuner_filter = NULL;
+                    IBaseFilter *tv_tuner_base_filter = NULL;
+                    hr = ff_dshow_get_tvtuner_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], tv_tuner_filter, tv_tuner_base_filter);
+
+                    if (hr == S_OK && tv_tuner_base_filter)
+                        ff_dshow_show_filter_properties(tv_tuner_base_filter, avctx);
+
+                    if (tv_tuner_filter)
+                        IAMTVTuner_Release(tv_tuner_filter);
+                    if (tv_tuner_base_filter)
+                        IBaseFilter_Release(tv_tuner_base_filter);
+                }
+                else {
+                    IAMAudioInputMixer *tv_audio_filter = NULL;
+                    IBaseFilter *tv_audio_base_filter = NULL;
+                    hr = ff_dshow_get_audiomixer_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], tv_audio_filter, tv_audio_base_filter);
+
+                    if (hr == S_OK && tv_audio_base_filter)
+                        ff_dshow_show_filter_properties(tv_audio_base_filter, avctx);
+
+                    if (tv_audio_filter)
+                        IAMAudioInputMixer_Release(tv_audio_filter);
+                    if (tv_audio_base_filter)
+                        IBaseFilter_Release(tv_audio_base_filter);
+                }
+            }
         }
         break;
     }
     }
 
+    // if play state change requested, apply
     if (run_state != ctx->is_running) {
         if (run_state)
-            r = IMediaControl_Run(ctx->control);
+            hr = IMediaControl_Run(ctx->control);
         else
-            r = IMediaControl_Pause(ctx->control);
+            hr = IMediaControl_Pause(ctx->control);
 
-        if (r == S_FALSE) {
+        if (hr == S_FALSE) {
             OAFilterState pfs;
-            r = IMediaControl_GetState(ctx->control, 0, &pfs);
+            hr = IMediaControl_GetState(ctx->control, 0, &pfs);
         }
-        if (r != S_OK) {
+        if (hr != S_OK) {
             av_log(avctx, AV_LOG_ERROR, "Could not run/pause graph\n");
             return AVERROR(EIO);
         }
diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h
index b7ef3770df..5a665d0ee0 100644
--- a/libavdevice/dshow_capture.h
+++ b/libavdevice/dshow_capture.h
@@ -317,6 +317,7 @@ struct dshow_ctx {
     IPin        *device_pin[2];
     DShowFilter *capture_filter[2];
     DShowPin    *capture_pin[2];
+    ICaptureGraphBuilder2 *graph_builder2[2];
 
     HANDLE mutex;
     HANDLE event[2]; /* event[0] is set by DirectShow
@@ -351,6 +352,15 @@ struct dshow_ctx {
 HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2,
     IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx);
 
+HRESULT ff_dshow_get_crossbar_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter,
+    IAMCrossbar *cross_bar, IBaseFilter **cross_bar_base_filter);
+
+HRESULT ff_dshow_get_tvtuner_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter,
+    IAMTVTuner *tv_tuner_filter, IBaseFilter *tv_tuner_base_filter);
+
+HRESULT ff_dshow_get_audiomixer_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter,
+    IAMAudioInputMixer *tv_audio_filter, IBaseFilter *tv_audio_base_filter);
+
 void ff_dshow_show_filter_properties(IBaseFilter *pFilter, AVFormatContext *avctx);
 
 #endif /* AVDEVICE_DSHOW_CAPTURE_H */
diff --git a/libavdevice/dshow_crossbar.c b/libavdevice/dshow_crossbar.c
index 961defe690..6b714e849c 100644
--- a/libavdevice/dshow_crossbar.c
+++ b/libavdevice/dshow_crossbar.c
@@ -133,6 +133,44 @@ setup_crossbar_options(IAMCrossbar *cross_bar, enum dshowDeviceType devtype, AVF
     return S_OK;
 }
 
+HRESULT
+ff_dshow_get_crossbar_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter,
+    IAMCrossbar *cross_bar, IBaseFilter **cross_bar_base_filter)
+{
+    HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, (const GUID *) NULL,
+        device_filter, &IID_IAMCrossbar, (void **) &cross_bar);
+    if (hr != S_OK)
+        /* no crossbar found */
+        return hr;
+
+    if (cross_bar_base_filter)
+        hr = IAMCrossbar_QueryInterface(cross_bar, &IID_IBaseFilter, (void**)cross_bar_base_filter);
+
+    return hr;
+}
+
+HRESULT
+ff_dshow_get_tvtuner_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter,
+    IAMTVTuner *tv_tuner_filter, IBaseFilter *tv_tuner_base_filter)
+{
+    HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL,
+        device_filter, &IID_IAMTVTuner, (void **) &tv_tuner_filter);
+    if (hr == S_OK)
+        hr = IAMCrossbar_QueryInterface(tv_tuner_filter, &IID_IBaseFilter, (void **) &tv_tuner_base_filter);
+    return hr;
+}
+
+HRESULT
+ff_dshow_get_audiomixer_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter,
+    IAMAudioInputMixer *tv_audio_filter, IBaseFilter *tv_audio_base_filter)
+{
+    HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL,
+        device_filter, &IID_IAMTVAudio, (void **) &tv_audio_filter);
+    if (hr == S_OK)
+        hr = IAMCrossbar_QueryInterface(tv_audio_filter, &IID_IBaseFilter, (void **) &tv_audio_base_filter);
+    return hr;
+}
+
 /**
  * Given a fully constructed graph, check if there is a cross bar filter, and configure its pins if so.
  */
@@ -140,55 +178,42 @@ HRESULT
 ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2,
     IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx)
 {
-    struct dshow_ctx *ctx = avctx->priv_data;
-    IAMCrossbar *cross_bar = NULL;
-    IBaseFilter *cross_bar_base_filter = NULL;
-    IAMTVTuner *tv_tuner_filter = NULL;
-    IBaseFilter *tv_tuner_base_filter = NULL;
-    IAMAudioInputMixer *tv_audio_filter = NULL;
-    IBaseFilter *tv_audio_base_filter = NULL;
+    struct dshow_ctx    *ctx = avctx->priv_data;
+    IAMCrossbar         *cross_bar              = NULL;
+    IBaseFilter         *cross_bar_base_filter  = NULL;
+    IAMTVTuner          *tv_tuner_filter        = NULL;
+    IBaseFilter         *tv_tuner_base_filter   = NULL;
+    IAMAudioInputMixer  *tv_audio_filter        = NULL;
+    IBaseFilter         *tv_audio_base_filter   = NULL;
     HRESULT hr;
+    int should_show_crossbar_properties = (devtype == VideoDevice) ? ctx->show_video_crossbar_connection_dialog : ctx->show_audio_crossbar_connection_dialog;
 
-    hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, (const GUID *) NULL,
-            device_filter, &IID_IAMCrossbar, (void**) &cross_bar);
+    hr = ff_dshow_get_crossbar_and_filter(graph_builder2, device_filter, cross_bar, should_show_crossbar_properties ? &cross_bar_base_filter : NULL);
     if (hr != S_OK) {
-        /* no crossbar found */
-        hr = S_OK;
+        if (!cross_bar)
+            /* no crossbar found */
+            hr = S_OK;
         goto end;
     }
+
     /* TODO some TV tuners apparently have multiple crossbars? */
 
-    if (devtype == VideoDevice && ctx->show_video_crossbar_connection_dialog ||
-        devtype == AudioDevice && ctx->show_audio_crossbar_connection_dialog) {
-        hr = IAMCrossbar_QueryInterface(cross_bar, &IID_IBaseFilter, (void **) &cross_bar_base_filter);
-        if (hr != S_OK)
-            goto end;
+    if (should_show_crossbar_properties && cross_bar_base_filter)
         ff_dshow_show_filter_properties(cross_bar_base_filter, avctx);
-    }
 
     if (devtype == VideoDevice && ctx->show_analog_tv_tuner_dialog) {
-        hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL,
-             device_filter, &IID_IAMTVTuner, (void**) &tv_tuner_filter);
-        if (hr == S_OK) {
-            hr = IAMCrossbar_QueryInterface(tv_tuner_filter, &IID_IBaseFilter, (void **) &tv_tuner_base_filter);
-            if (hr != S_OK)
-                goto end;
+        hr = ff_dshow_get_tvtuner_and_filter(graph_builder2, device_filter, tv_tuner_filter, tv_tuner_base_filter);
+        if (hr == S_OK && tv_tuner_base_filter)
             ff_dshow_show_filter_properties(tv_tuner_base_filter, avctx);
-        } else {
+        else
             av_log(avctx, AV_LOG_WARNING, "unable to find a tv tuner to display dialog for!");
-        }
     }
     if (devtype == AudioDevice && ctx->show_analog_tv_tuner_audio_dialog) {
-        hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL,
-             device_filter, &IID_IAMTVAudio, (void**) &tv_audio_filter);
-        if (hr == S_OK) {
-            hr = IAMCrossbar_QueryInterface(tv_audio_filter, &IID_IBaseFilter, (void **) &tv_audio_base_filter);
-            if (hr != S_OK)
-                goto end;
+        hr = ff_dshow_get_audiomixer_and_filter(graph_builder2, device_filter, tv_audio_filter, tv_audio_base_filter);
+        if (hr == S_OK && tv_audio_base_filter)
             ff_dshow_show_filter_properties(tv_audio_base_filter, avctx);
-        } else {
+        else
             av_log(avctx, AV_LOG_WARNING, "unable to find a tv audio tuner to display dialog for!");
-        }
     }
 
     hr = setup_crossbar_options(cross_bar, devtype, avctx);
-- 
2.28.0.windows.1



More information about the ffmpeg-devel mailing list