[FFmpeg-devel] [PATCH 10/35] fftools: provide media type info for devices

Diederick Niehorster dcnieho at gmail.com
Tue Jun 8 02:03:49 EEST 2021


fftools now print info about what media type(s), if any, are provided by sink and source avdevices. Furthermore, printing is done with av_log instead of printf as the latter doesn't handle characters in some device names correctly (e.g. "Microphone Array (Intel® Smart Sound Technology (Intel® SST))" is printed incorrectly).

Signed-off-by: Diederick Niehorster <dcnieho at gmail.com>
---
 fftools/cmdutils.c | 41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4148285971..b7018b7dab 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -2205,9 +2205,36 @@ double get_rotation(AVStream *st)
 }
 
 #if CONFIG_AVDEVICE
+static void print_device_list(AVDeviceInfoList *device_list)
+{
+    int i, error_level = av_log_get_level();
+    // reset log level such that info messages are displayed
+    // we need to use av_log instead of printf as it handles
+    // unicode better
+    av_log_set_level(AV_LOG_INFO);
+    // print devices
+    for (i = 0; i < device_list->nb_devices; i++) {
+        av_log(NULL, AV_LOG_INFO, "%s %s [%s]", device_list->default_device == i ? "*" : " ",
+            device_list->devices[i]->device_name, device_list->devices[i]->device_description);
+        if (device_list->devices[i]->nb_media_types > 0 && device_list->devices[i]->media_types) {
+            const char* media_type = av_get_media_type_string(device_list->devices[i]->media_types[0]);
+            av_log(NULL, AV_LOG_INFO, " (%s", media_type ? media_type : "unknown");
+            for (int i = 1; i < device_list->devices[i]->nb_media_types; ++i) {
+                media_type = av_get_media_type_string(device_list->devices[i]->media_types[i]);
+                av_log(NULL, AV_LOG_INFO, ", %s", media_type ? media_type : "unknown");
+            }
+            av_log(NULL, AV_LOG_INFO, ")");
+        } else {
+            av_log(NULL, AV_LOG_INFO, " (none)");
+        }
+        av_log(NULL, AV_LOG_INFO, "\n");
+    }
+
+    av_log_set_level(error_level);
+}
 static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts)
 {
-    int ret, i;
+    int ret;
     AVDeviceInfoList *device_list = NULL;
 
     if (!fmt || !fmt->priv_class  || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
@@ -2225,10 +2252,7 @@ static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts)
         goto fail;
     }
 
-    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);
-    }
+    print_device_list(device_list);
 
   fail:
     avdevice_free_list_devices(&device_list);
@@ -2237,7 +2261,7 @@ static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts)
 
 static int print_device_sinks(const AVOutputFormat *fmt, AVDictionary *opts)
 {
-    int ret, i;
+    int ret;
     AVDeviceInfoList *device_list = NULL;
 
     if (!fmt || !fmt->priv_class  || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
@@ -2255,10 +2279,7 @@ static int print_device_sinks(const AVOutputFormat *fmt, AVDictionary *opts)
         goto fail;
     }
 
-    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);
-    }
+    print_device_list(device_list);
 
   fail:
     avdevice_free_list_devices(&device_list);
-- 
2.28.0.windows.1



More information about the ffmpeg-devel mailing list