[FFmpeg-devel] [PATCH 5/6] fftools: avradio support

Michael Niedermayer michael at niedermayer.cc
Sat Jul 22 22:29:56 EEST 2023


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 */
-- 
2.17.1



More information about the ffmpeg-devel mailing list