From patchwork Sat Jul 22 19:29:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42916 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be1d:b0:130:ccc6:6c4b with SMTP id ge29csp1019371pzb; Sat, 22 Jul 2023 12:30:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEs778FxcwmuEs9iSZYAlP17xguVv33gT2pJfDSx+5oguj0rQWzs3Ejp8tZcQGy9ij0ae/g X-Received: by 2002:aa7:d04a:0:b0:518:7cf5:7ff8 with SMTP id n10-20020aa7d04a000000b005187cf57ff8mr4697735edo.12.1690054242264; Sat, 22 Jul 2023 12:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690054242; cv=none; d=google.com; s=arc-20160816; b=XHFTbvAGIWS0uzNjYYIA608hDjA/gsa+UFCXidfP2LabtrqX7iYO+CRFVJJGULn4n7 7OJ9wRpVognRxn4/J5lWwh6vGL4kgDAs6lDUNC92NrZdGyNcz5lWhG2qNezMA3sxgd9A tMNsS0zhoJGJZSqx2sZkM4JLH+giovXH7VK26y8jjMte+QU1Vri1wuAO2ojfbSShUXYy MdNOSGahwHJGu4ycQZk+Gu1MM23wf7NBxk/TLDJHRu3zuIlmcUEBhRyuLs0svT7h5bji D/Em1GrCi+v5OidYc3LQUoTVqbBYWJO+oDM0eYQ3RyWH1MQ4qcQDablksONfgWVzv5gr bmGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=5iqUKefuihovzy/Iibvgfk2snWey5ND2FWmqk1clsH8=; fh=YYwLYmpaV0Fpw/rxmSKNRLS2XzDkAlGbHATiKOPtZrY=; b=zRM/Xq4xe9A98XuNia7NTQMhzdJm33rKZxIqMGSkAFMAgh8RNuZtaIm0wW54USinIT TaXU7UYYu11RXoH2vL1FyZ6BXSUyF0CAUWvjAUOnlSxUb3wrpHMalLO0NY8msIogAPfr /Rb1yNTolfbRC+mKIkvWh/b5hj8k4sUZF6eISBeZa4bh3SRgS7lkKKNhu9PENsyIG7gk QvHMV0v7smaSkJZRM9DrZcChhTjFfuRGfifkn6hoDAb/SKkaAjuRqqujcsnojAgIF+Z8 RudyGWRC811v6+Lq1ra4lsAYHMbP2wx70E4xHYiNKMn0ItSW4XNaEuZr3K63cwAEjSXA pR3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w22-20020aa7da56000000b005217c6c827dsi4288459eds.231.2023.07.22.12.30.41; Sat, 22 Jul 2023 12:30:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EDEC968C688; Sat, 22 Jul 2023 22:30:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2832368C675 for ; Sat, 22 Jul 2023 22:30:04 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 84A6B240003 for ; Sat, 22 Jul 2023 19:30:03 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 22 Jul 2023 21:29:56 +0200 Message-Id: <20230722192957.703-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230722192957.703-1-michael@niedermayer.cc> References: <20230722192957.703-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 5/6] fftools: avradio support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yBMFTh7fQ5Zl This avoids keeping diffs to fftools in the libavradio repository --- fftools/ffmpeg.c | 7 +++++ fftools/ffplay.c | 6 ++++ fftools/ffprobe.c | 6 ++++ fftools/opt_common.c | 66 ++++++++++++++++++++++++++++++++++++++++---- fftools/opt_common.h | 27 ++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 6130fd06fc..e9fbc8b636 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -95,6 +95,10 @@ #include "libavdevice/avdevice.h" +#if CONFIG_AVRADIO +#include "libavradio/avradio.h" +#endif + #include "libswresample/swresample.h" #include "libavfilter/avfilter.h" @@ -1331,6 +1335,9 @@ int main(int argc, char **argv) #if CONFIG_AVDEVICE avdevice_register_all(); +#endif +#if CONFIG_AVRADIO + avradio_register_all(); #endif avformat_network_init(); diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 5212ad053e..f2e70b2de6 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -45,6 +45,9 @@ #include "libavutil/bprint.h" #include "libavformat/avformat.h" #include "libavdevice/avdevice.h" +#if CONFIG_AVRADIO +#include "libavradio/avradio.h" +#endif #include "libswscale/swscale.h" #include "libavutil/opt.h" #include "libavcodec/avfft.h" @@ -3651,6 +3654,9 @@ int main(int argc, char **argv) /* register all codecs, demux and protocols */ #if CONFIG_AVDEVICE avdevice_register_all(); +#endif +#if CONFIG_AVRADIO + avradio_register_all(); #endif avformat_network_init(); diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index a39185f6fe..51a0c2483b 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -56,6 +56,9 @@ #include "libavutil/timestamp.h" #include "libavdevice/avdevice.h" #include "libavdevice/version.h" +#if CONFIG_AVRADIO +#include "libavradio/avradio.h" +#endif #include "libswscale/swscale.h" #include "libswscale/version.h" #include "libswresample/swresample.h" @@ -4109,6 +4112,9 @@ int main(int argc, char **argv) #if CONFIG_AVDEVICE avdevice_register_all(); #endif +#if CONFIG_AVRADIO + avradio_register_all(); +#endif show_banner(argc, argv, options); ret = parse_options(NULL, argc, argv, options, opt_input_file); diff --git a/fftools/opt_common.c b/fftools/opt_common.c index 913932c914..f556d95afe 100644 --- a/fftools/opt_common.c +++ b/fftools/opt_common.c @@ -51,6 +51,11 @@ #include "libavdevice/avdevice.h" #include "libavdevice/version.h" +#if CONFIG_AVRADIO +#include "libavradio/avradio.h" +#include "libavradio/version.h" +#endif + #include "libavfilter/avfilter.h" #include "libavfilter/version.h" @@ -187,6 +192,9 @@ static void print_all_libs_info(int flags, int level) PRINT_LIB_INFO(avutil, AVUTIL, flags, level); PRINT_LIB_INFO(avcodec, AVCODEC, flags, level); PRINT_LIB_INFO(avformat, AVFORMAT, flags, level); +#if CONFIG_AVRADIO + PRINT_LIB_INFO(avradio, AVRADIO, flags, level); +#endif PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level); PRINT_LIB_INFO(avfilter, AVFILTER, flags, level); PRINT_LIB_INFO(swscale, SWSCALE, flags, level); @@ -844,6 +852,13 @@ static int is_device(const AVClass *avclass) return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category); } +static int is_radio(const AVClass *avclass) +{ + if (!avclass) + return 0; + return avclass->category == AV_CLASS_CATEGORY_RADIO_INPUT; +} + static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only, int muxdemuxers) { void *ifmt_opaque = NULL; @@ -851,12 +866,13 @@ static int show_formats_devices(void *optctx, const char *opt, const char *arg, void *ofmt_opaque = NULL; const AVOutputFormat *ofmt = NULL; const char *last_name; - int is_dev; + int is_dev, is_rad; + const char *name[3] = {"File formats:", "Devices:", "Radios:"}; printf("%s\n" " D. = Demuxing supported\n" " .E = Muxing supported\n" - " --\n", device_only ? "Devices:" : "File formats:"); + " --\n", name[device_only]); last_name = "000"; for (;;) { int decode = 0; @@ -868,7 +884,9 @@ static int show_formats_devices(void *optctx, const char *opt, const char *arg, ofmt_opaque = NULL; while ((ofmt = av_muxer_iterate(&ofmt_opaque))) { is_dev = is_device(ofmt->priv_class); - if (!is_dev && device_only) + if (!is_dev && device_only == 1) + continue; + if (device_only == 2) continue; if ((!name || strcmp(ofmt->name, name) < 0) && strcmp(ofmt->name, last_name) > 0) { @@ -882,7 +900,10 @@ static int show_formats_devices(void *optctx, const char *opt, const char *arg, ifmt_opaque = NULL; while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) { is_dev = is_device(ifmt->priv_class); - if (!is_dev && device_only) + is_rad = is_radio(ifmt->priv_class); + if (!is_dev && device_only == 1) + continue; + if (!is_rad && device_only == 2) continue; if ((!name || strcmp(ifmt->name, name) < 0) && strcmp(ifmt->name, last_name) > 0) { @@ -927,6 +948,11 @@ int show_devices(void *optctx, const char *opt, const char *arg) return show_formats_devices(optctx, opt, arg, 1, SHOW_DEFAULT); } +int show_radios(void *optctx, const char *opt, const char *arg) +{ + return show_formats_devices(optctx, opt, arg, 2, SHOW_DEFAULT); +} + int show_protocols(void *optctx, const char *opt, const char *arg) { void *opaque = NULL; @@ -1335,7 +1361,7 @@ static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts) int ret; AVDeviceInfoList *device_list = NULL; - if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category)) + if (!fmt || !fmt->priv_class || (!AV_IS_INPUT_DEVICE(fmt->priv_class->category) && fmt->priv_class->category != AV_CLASS_CATEGORY_RADIO_INPUT)) return AVERROR(EINVAL); printf("Auto-detected sources for %s:\n", fmt->name); @@ -1468,3 +1494,33 @@ int show_sinks(void *optctx, const char *opt, const char *arg) return ret; } #endif /* CONFIG_AVDEVICE */ + +#if CONFIG_AVRADIO +int show_radio_sources(void *optctx, const char *opt, const char *arg) +{ + const AVInputFormat *fmt = NULL; + char *dev = NULL; + AVDictionary *opts = NULL; + int ret = 0; + int error_level = av_log_get_level(); + + av_log_set_level(AV_LOG_WARNING); + + if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0) + goto fail; + + do { + fmt = av_input_radio_next(fmt); + if (fmt) { + if (dev && !av_match_name(dev, fmt->name)) + continue; + print_device_sources(fmt, opts); + } + } while (fmt); + fail: + av_dict_free(&opts); + av_free(dev); + av_log_set_level(error_level); + return ret; +} +#endif /* CONFIG_AVRADIO */ diff --git a/fftools/opt_common.h b/fftools/opt_common.h index ea1d16e769..b64ab07e10 100644 --- a/fftools/opt_common.h +++ b/fftools/opt_common.h @@ -39,6 +39,15 @@ int show_sinks(void *optctx, const char *opt, const char *arg); int show_sources(void *optctx, const char *opt, const char *arg); #endif +#if CONFIG_AVRADIO +/** + * Print a listing containing autodetected sources of the input radio. + * Device name with options may be passed as an argument to limit results. + */ +int show_radio_sources(void *optctx, const char *opt, const char *arg); +#endif + + #if CONFIG_AVDEVICE #define CMDUTILS_COMMON_OPTIONS_AVDEVICE \ { "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources }, \ @@ -50,6 +59,15 @@ int show_sources(void *optctx, const char *opt, const char *arg); #define CMDUTILS_COMMON_OPTIONS_AVDEVICE #endif +#if CONFIG_AVRADIO +#define CMDUTILS_COMMON_OPTIONS_AVRADIO \ + { "radio_sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_radio_sources }, \ + "list sources of the input device", "device" }, \ + +#else +#define CMDUTILS_COMMON_OPTIONS_AVRADIO +#endif + /** * Print the license of the program to stdout. The license depends on * the license of the libraries compiled into the program. @@ -105,6 +123,13 @@ int show_demuxers(void *optctx, const char *opt, const char *arg); */ int show_devices(void *optctx, const char *opt, const char *arg); +/** + * Print a listing containing all the radios supported by the + * program. + * This option processing function does not utilize the arguments. + */ +int show_radios(void *optctx, const char *opt, const char *arg); + /** * Print a listing containing all the codecs supported by the * program. @@ -208,6 +233,7 @@ int opt_cpucount(void *optctx, const char *opt, const char *arg); { "muxers", OPT_EXIT, { .func_arg = show_muxers }, "show available muxers" }, \ { "demuxers", OPT_EXIT, { .func_arg = show_demuxers }, "show available demuxers" }, \ { "devices", OPT_EXIT, { .func_arg = show_devices }, "show available devices" }, \ + { "radios", OPT_EXIT, { .func_arg = show_radios }, "show available radios" }, \ { "codecs", OPT_EXIT, { .func_arg = show_codecs }, "show available codecs" }, \ { "decoders", OPT_EXIT, { .func_arg = show_decoders }, "show available decoders" }, \ { "encoders", OPT_EXIT, { .func_arg = show_encoders }, "show available encoders" }, \ @@ -227,5 +253,6 @@ int opt_cpucount(void *optctx, const char *opt, const char *arg); { "cpucount", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpucount }, "force specific cpu count", "count" }, \ { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, \ CMDUTILS_COMMON_OPTIONS_AVDEVICE \ + CMDUTILS_COMMON_OPTIONS_AVRADIO \ #endif /* FFTOOLS_OPT_COMMON_H */