[FFmpeg-devel] [PATCH v4 07/22] avdevice/dshow: add config dialog command for crossbar and tv tuner
Diederick Niehorster
dcnieho at gmail.com
Fri Mar 25 16:10:26 EET 2022
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.
Bumping avdevice version.
Signed-off-by: Diederick Niehorster <dcnieho at gmail.com>
---
libavdevice/dshow.c | 51 ++++++++++++++++++--
libavdevice/dshow_capture.h | 10 ++++
libavdevice/dshow_crossbar.c | 91 +++++++++++++++++++++++-------------
libavdevice/version.h | 2 +-
4 files changed, 115 insertions(+), 39 deletions(-)
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 78194406b5..a780351170 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -240,6 +240,11 @@ dshow_read_close(AVFormatContext *s)
struct dshow_ctx *ctx = s->priv_data;
PacketListEntry *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);
@@ -1464,6 +1469,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");
@@ -1488,9 +1494,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);
@@ -1536,10 +1539,48 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s
ff_dshow_show_filter_properties(ctx->device_filter[devtype], avctx);
} else if (dialog & 1<<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 & 1<<3) {
// 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;
}
diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h
index d0dd35a670..94ba9896b7 100644
--- a/libavdevice/dshow_capture.h
+++ b/libavdevice/dshow_capture.h
@@ -318,6 +318,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
@@ -352,6 +353,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);
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 96347a3893..feb15ba9c8 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -31,7 +31,7 @@
#include "version_major.h"
#define LIBAVDEVICE_VERSION_MINOR 8
-#define LIBAVDEVICE_VERSION_MICRO 100
+#define LIBAVDEVICE_VERSION_MICRO 101
#define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
LIBAVDEVICE_VERSION_MINOR, \
--
2.28.0.windows.1
More information about the ffmpeg-devel
mailing list