From: Diederick Niehorster <dcnieho@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Diederick Niehorster <dcnieho@gmail.com> Subject: [FFmpeg-devel] [PATCH v5 07/13] avdevice/dshow: implement get_device_list Date: Sun, 19 Dec 2021 20:21:28 +0100 Message-ID: <20211219192134.1296-8-dcnieho@gmail.com> (raw) In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> Needed to enable programmatic discovery of DirectShow devices Signed-off-by: Diederick Niehorster <dcnieho@gmail.com> --- libavdevice/dshow.c | 80 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 0ef3b3d13e..8c257ca8e7 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -202,11 +202,14 @@ fail: * retrieve the device with type specified by devtype and return the * pointer to the object found in *pfilter. * If pfilter is NULL, list all device names. + * If device_list is not NULL, populate it with found devices instead of + * outputting device names to log */ static int dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, - IBaseFilter **pfilter, char **device_unique_name) + IBaseFilter **pfilter, char **device_unique_name, + AVDeviceInfoList **device_list) { struct dshow_ctx *ctx = avctx->priv_data; IBaseFilter *device_filter = NULL; @@ -238,6 +241,7 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, IBindCtx *bind_ctx = NULL; LPOLESTR olestr = NULL; LPMALLOC co_malloc = NULL; + AVDeviceInfo *device = NULL; int i; r = CoGetMalloc(1, &co_malloc); @@ -282,11 +286,39 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, // success, loop will end now } } else { - av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name); - av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); + if (device_list) { + device = av_mallocz(sizeof(AVDeviceInfo)); + if (!device) + goto fail1; + + device->device_name = av_strdup(friendly_name); + device->device_description = av_strdup(unique_name); + if (!device->device_name || !device->device_description) + goto fail1; + + // store to device_list output + if (av_reallocp_array(&(*device_list)->devices, + (*device_list)->nb_devices + 1, + sizeof(*(*device_list)->devices)) < 0) + goto fail1; + (*device_list)->devices[(*device_list)->nb_devices] = device; + (*device_list)->nb_devices++; + device = NULL; // copied into array, make sure not freed below + } + else { + av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name); + av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); + } } fail1: + if (device) { + if (device->device_name) + av_freep(&device->device_name); + if (device->device_name) + av_freep(&device->device_description); + av_free(device); + } if (olestr && co_malloc) IMalloc_Free(co_malloc, olestr); if (bind_ctx) @@ -312,6 +344,39 @@ fail1: return 0; } +static int dshow_get_device_list(AVFormatContext *avctx, AVDeviceInfoList *device_list) +{ + struct dshow_ctx *ctx = avctx->priv_data; + ICreateDevEnum *devenum = NULL; + int r; + int ret = AVERROR(EIO); + + if (!device_list) + return AVERROR(EINVAL); + + CoInitialize(0); + + r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, + &IID_ICreateDevEnum, (void**)&devenum); + if (r != S_OK) { + av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); + goto error; + } + + ret = dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL, &device_list); + if (ret < S_OK) + goto error; + ret = dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL, &device_list); + +error: + if (devenum) + ICreateDevEnum_Release(devenum); + + CoUninitialize(); + + return ret; +} + /** * Cycle through available formats using the specified pin, * try to set parameters specified through AVOptions and if successful @@ -705,7 +770,7 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, char *device_unique_name = NULL; int r; - if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name)) < 0) + if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0) return r; ctx->device_filter[devtype] = device_filter; ctx->device_unique_name[devtype] = device_unique_name; @@ -765,7 +830,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, av_log(avctx, AV_LOG_INFO, "Capture filter loaded successfully from file \"%s\".\n", filename); } else { - if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_filter_unique_name)) < 0) { + if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_filter_unique_name, NULL)) < 0) { ret = r; goto error; } @@ -1122,9 +1187,9 @@ static int dshow_read_header(AVFormatContext *avctx) if (ctx->list_devices) { av_log(avctx, AV_LOG_INFO, "DirectShow video devices (some may be both video and audio devices)\n"); - dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL); + dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL, NULL); av_log(avctx, AV_LOG_INFO, "DirectShow audio devices\n"); - dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL); + dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL, NULL); ret = AVERROR_EXIT; goto error; } @@ -1329,6 +1394,7 @@ const AVInputFormat ff_dshow_demuxer = { .read_header = dshow_read_header, .read_packet = dshow_read_packet, .read_close = dshow_read_close, + .get_device_list= dshow_get_device_list, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; -- 2.28.0.windows.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2021-12-19 19:23 UTC|newest] Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-19 19:21 [FFmpeg-devel] [PATCH v5 00/13] dshow enhancements Diederick Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 01/13] avdevice/dshow: prevent NULL access Diederick Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 02/13] avdevice/dshow: implement option to use device video timestamps Diederick Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 03/13] avdevice/dshow: add use_video_device_timestamps to docs Diederick Niehorster 2021-12-20 0:42 ` Andreas Rheinhardt 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 04/13] avdevice/dshow: query graph and sample time only once Diederick Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 05/13] avdevice/dshow: handle unknown sample time Diederick Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 06/13] avdevice/dshow: set no-seek flags Diederick Niehorster 2021-12-19 19:21 ` Diederick Niehorster [this message] 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 08/13] avdevice/dshow: list_devices: show media type(s) per device Diederick Niehorster 2021-12-20 0:55 ` Andreas Rheinhardt 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 09/13] avdevice: add info about media types(s) to AVDeviceInfo Diederick Niehorster 2021-12-20 0:59 ` Andreas Rheinhardt 2021-12-20 9:54 ` Diederick C. Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 10/13] avdevice/dshow: add media type info to get_device_list Diederick Niehorster 2021-12-20 1:04 ` Andreas Rheinhardt 2021-12-20 8:01 ` Diederick C. Niehorster 2021-12-21 11:55 ` Diederick C. Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 11/13] fftools: provide media type info for devices Diederick Niehorster 2021-12-20 1:22 ` Andreas Rheinhardt 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 12/13] avdevice/dshow: discover source color range/space/etc Diederick Niehorster 2021-12-20 1:27 ` Andreas Rheinhardt 2021-12-20 8:10 ` Diederick C. Niehorster 2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 13/13] avdevice/dshow: select format with extended color info Diederick Niehorster 2021-12-20 1:32 ` Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211219192134.1296-8-dcnieho@gmail.com \ --to=dcnieho@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git