diff mbox series

[FFmpeg-devel,v2,10/33] fftools: provide media type info for devices

Message ID 20210611203104.1692-11-dcnieho@gmail.com
State Superseded, archived
Headers show
Series avdevice (mostly dshow) enhancements | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Diederick C. Niehorster June 11, 2021, 8:30 p.m. UTC
fftools now print info about what media type(s), if any, are provided by
sink and source avdevices.

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

Comments

Andreas Rheinhardt June 17, 2021, 1:18 a.m. UTC | #1
Diederick Niehorster:
> fftools now print info about what media type(s), if any, are provided by
> sink and source avdevices.
> 
> Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> ---
>  fftools/cmdutils.c | 34 ++++++++++++++++++++++++----------
>  1 file changed, 24 insertions(+), 10 deletions(-)
> 
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 4148285971..e7bd9f2644 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -2205,9 +2205,29 @@ double get_rotation(AVStream *st)
>  }
>  
>  #if CONFIG_AVDEVICE
> +static void print_device_list(AVDeviceInfoList *device_list)

Missing const.

> +{
> +    // print devices
> +    for (int i = 0; i < device_list->nb_devices; i++) {

Accessing this via "const AVDeviceInfo *device =
&device_list->devices[i];" would improve readability.

> +        printf("%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]);
> +            printf(" (%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]);
> +                printf(", %s", media_type ? media_type : "unknown");
> +            }
> +            printf(")");
> +        } else {
> +            printf(" (none)");
> +        }
> +        printf("\n");
> +    }
> +}
>  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 +2245,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 +2254,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 +2272,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);
>
Andreas Rheinhardt June 17, 2021, 1:41 a.m. UTC | #2
Diederick Niehorster:
> fftools now print info about what media type(s), if any, are provided by
> sink and source avdevices.
> 
> Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> ---
>  fftools/cmdutils.c | 34 ++++++++++++++++++++++++----------
>  1 file changed, 24 insertions(+), 10 deletions(-)
> 
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 4148285971..e7bd9f2644 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -2205,9 +2205,29 @@ double get_rotation(AVStream *st)
>  }
>  
>  #if CONFIG_AVDEVICE
> +static void print_device_list(AVDeviceInfoList *device_list)
> +{
> +    // print devices
> +    for (int i = 0; i < device_list->nb_devices; i++) {
> +        printf("%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]);
> +            printf(" (%s", media_type ? media_type : "unknown");
> +            for (int i = 1; i < device_list->devices[i]->nb_media_types; ++i) {

You are shadowing the external counter variable here and are using a
different device for every iteration. Has this code actually been tested?

> +                media_type = av_get_media_type_string(device_list->devices[i]->media_types[i]);
> +                printf(", %s", media_type ? media_type : "unknown");
> +            }
> +            printf(")");
> +        } else {
> +            printf(" (none)");
> +        }
> +        printf("\n");
> +    }
> +}
>  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 +2245,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 +2254,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 +2272,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);
>
Diederick C. Niehorster June 18, 2021, 9:26 p.m. UTC | #3
On Thu, Jun 17, 2021 at 3:41 AM Andreas Rheinhardt
<andreas.rheinhardt@outlook.com> wrote:
>
> Diederick Niehorster:
> > fftools now print info about what media type(s), if any, are provided by
> > sink and source avdevices.
> >
> > Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> > ---
> >  fftools/cmdutils.c | 34 ++++++++++++++++++++++++----------
> >  1 file changed, 24 insertions(+), 10 deletions(-)
> >
> > diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> > index 4148285971..e7bd9f2644 100644
> > --- a/fftools/cmdutils.c
> > +++ b/fftools/cmdutils.c
> > @@ -2205,9 +2205,29 @@ double get_rotation(AVStream *st)
> >  }
> >
> >  #if CONFIG_AVDEVICE
> > +static void print_device_list(AVDeviceInfoList *device_list)
> > +{
> > +    // print devices
> > +    for (int i = 0; i < device_list->nb_devices; i++) {
> > +        printf("%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]);
> > +            printf(" (%s", media_type ? media_type : "unknown");
> > +            for (int i = 1; i < device_list->devices[i]->nb_media_types; ++i) {
>
> You are shadowing the external counter variable here and are using a
> different device for every iteration. Has this code actually been tested?

Fixed both from your first mail. Yes, i have tested this, but only
with zero or one media type per device since thats all i had. I could
of course jury-rig the code to output that a device has two media
types and then this didn't work (and it brought to the surface a bug
in an earlier commit too). Thanks!

Cheers,
Dee
diff mbox series

Patch

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4148285971..e7bd9f2644 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -2205,9 +2205,29 @@  double get_rotation(AVStream *st)
 }
 
 #if CONFIG_AVDEVICE
+static void print_device_list(AVDeviceInfoList *device_list)
+{
+    // print devices
+    for (int i = 0; i < device_list->nb_devices; i++) {
+        printf("%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]);
+            printf(" (%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]);
+                printf(", %s", media_type ? media_type : "unknown");
+            }
+            printf(")");
+        } else {
+            printf(" (none)");
+        }
+        printf("\n");
+    }
+}
 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 +2245,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 +2254,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 +2272,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);