Allows to list sources/sinks of the devices that implement that functionality.
Signed-off-by: Lukasz Marek <lukasz.m.lu...@gmail.com> --- cmdutils.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ cmdutils.h | 12 +++++++ cmdutils_common_opts.h | 6 ++++ 3 files changed, 107 insertions(+) diff --git a/cmdutils.c b/cmdutils.c index 67bb66e..defcf0a 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -2050,3 +2050,92 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) } return array; } + + +int show_sources(void *optctx, const char *opt, const char *arg) +{ +#if CONFIG_AVDEVICE + AVDeviceInfoList *device_list = NULL; + AVFormatContext *dev = NULL; + AVInputFormat *fmt; + int ret, i; + + if (!arg) { + printf("Device name is missing.\n"); + return AVERROR(EINVAL); + } + + fmt = av_find_input_format(arg); + if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category)) { + printf("No such device: %s\n", arg); + return AVERROR(EINVAL); + } + + if ((ret = avformat_open_input(&dev, NULL, fmt, NULL)) < 0) { + printf("Cannot open device: %s\n", arg); + goto fail; + } + + if ((ret = avdevice_list_devices(dev, &device_list)) < 0) { + printf("Cannot list devices\n"); + goto fail; + } + printf("Audo-detected sinks for %s:\n", arg); + for (i = 0; i < device_list->nb_devices; i++) { + printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ", + device_list->devices[i]->device_name, device_list->devices[i]->device_description); + } + + fail: + avdevice_free_list_devices(&device_list); + avformat_close_input(&dev); + return ret; +#else + printf("Configured without libavdevice\n"); + return AVERROR(ENOSYS); +#endif +} + +int show_sinks(void *optctx, const char *opt, const char *arg) +{ +#if CONFIG_AVDEVICE + AVDeviceInfoList *device_list = NULL; + AVFormatContext *dev = NULL; + AVOutputFormat *fmt; + int ret, i; + + if (!arg) { + printf("Device name is missing.\n"); + return AVERROR(EINVAL); + } + + fmt = av_guess_format(arg, NULL, NULL); + if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category)) { + printf("No such device: %s\n", arg); + return AVERROR(EINVAL); + } + + if ((ret = avformat_alloc_output_context2(&dev, fmt, NULL, NULL)) < 0) { + printf("Cannot open device: %s\n", arg); + goto fail; + } + + if ((ret = avdevice_list_devices(dev, &device_list)) < 0) { + printf("Cannot list devices\n"); + goto fail; + } + printf("Audo-detected sinks for %s:\n", arg); + for (i = 0; i < device_list->nb_devices; i++) { + printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ", + device_list->devices[i]->device_name, device_list->devices[i]->device_description); + } + + fail: + avdevice_free_list_devices(&device_list); + avformat_close_input(&dev); + return ret; +#else + printf("Configured without libavdevice\n"); + return AVERROR(ENOSYS); +#endif +} diff --git a/cmdutils.h b/cmdutils.h index 76d11a5..cb34876 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -444,6 +444,18 @@ int show_formats(void *optctx, const char *opt, const char *arg); int show_devices(void *optctx, const char *opt, const char *arg); /** + * Print a listing containing audodetected sinks of the output device. + * Device name must be passed as an argument. + */ +int show_sinks(void *optctx, const char *opt, const char *arg); + +/** + * Print a listing containing audodetected sources of the input device. + * Device name must be passed as an argument. + */ +int show_sources(void *optctx, const char *opt, const char *arg); + +/** * Print a listing containing all the codecs supported by the * program. * This option processing function does not utilize the arguments. diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 49b5180..758dac1 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -27,3 +27,9 @@ { "opencl_bench", OPT_EXIT, {.func_arg = opt_opencl_bench}, "run benchmark on all OpenCL devices and show results" }, { "opencl_options", HAS_ARG, {.func_arg = opt_opencl}, "set OpenCL environment options" }, #endif +#if CONFIG_AVDEVICE + { "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources }, + "list sources of the input device", "device" }, + { "sinks" , OPT_EXIT | HAS_ARG, { .func_arg = show_sinks }, + "list sinks of the output device", "device" }, +#endif -- 1.9.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel