diff mbox series

[FFmpeg-devel,1/2] lavf: fall back to a more meaningful log instance name

Message ID 20230330093809.22687-1-anton@khirnov.net
State Accepted
Commit dffb058f3b1f9a9b681d7e923eee77c170c5bf54
Headers show
Series [FFmpeg-devel,1/2] lavf: fall back to a more meaningful log instance name | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov March 30, 2023, 9:38 a.m. UTC
An uninitialized AVFormatContext instance with neither iformat nor
oformat set will currently log as 'NULL', which is confusing and
unhelpful. Print 'AVFormatContext' instead, which provides more
information.

This happens e.g. if choosing an output format fails in
avformat_alloc_output_context2().
---
 libavformat/options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Sabatini April 2, 2023, 7:06 p.m. UTC | #1
On date Thursday 2023-03-30 11:38:07 +0200, Anton Khirnov wrote:
> An uninitialized AVFormatContext instance with neither iformat nor
> oformat set will currently log as 'NULL', which is confusing and
> unhelpful. Print 'AVFormatContext' instead, which provides more
> information.
> 
> This happens e.g. if choosing an output format fails in
> avformat_alloc_output_context2().
> ---
>  libavformat/options.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/options.c b/libavformat/options.c
> index 22ad523b2d..e4a3aceed0 100644
> --- a/libavformat/options.c
> +++ b/libavformat/options.c
> @@ -44,7 +44,7 @@ static const char* format_to_name(void* ptr)
>      AVFormatContext* fc = (AVFormatContext*) ptr;
>      if(fc->iformat) return fc->iformat->name;
>      else if(fc->oformat) return fc->oformat->name;
> -    else return "NULL";
> +    else return fc->av_class->class_name;
>  }

Do you have an example to show? Anyway LGTM.
Anton Khirnov April 3, 2023, 10:16 a.m. UTC | #2
Quoting Stefano Sabatini (2023-04-02 21:06:35)
> On date Thursday 2023-03-30 11:38:07 +0200, Anton Khirnov wrote:
> > An uninitialized AVFormatContext instance with neither iformat nor
> > oformat set will currently log as 'NULL', which is confusing and
> > unhelpful. Print 'AVFormatContext' instead, which provides more
> > information.
> > 
> > This happens e.g. if choosing an output format fails in
> > avformat_alloc_output_context2().
> > ---
> >  libavformat/options.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/options.c b/libavformat/options.c
> > index 22ad523b2d..e4a3aceed0 100644
> > --- a/libavformat/options.c
> > +++ b/libavformat/options.c
> > @@ -44,7 +44,7 @@ static const char* format_to_name(void* ptr)
> >      AVFormatContext* fc = (AVFormatContext*) ptr;
> >      if(fc->iformat) return fc->iformat->name;
> >      else if(fc->oformat) return fc->oformat->name;
> > -    else return "NULL";
> > +    else return fc->av_class->class_name;
> >  }
> 
> Do you have an example to show? Anyway LGTM.

./ffmpeg -i /tmp/s.mkv -f foobar -y /dev/null
before: [NULL @ 0x5580377834c0] Requested output format 'foobar' is not a suitable output format
after:  [AVFormatContext @ 0x55fa15bb34c0] Requested output format 'foobar' is not a suitable output format
diff mbox series

Patch

diff --git a/libavformat/options.c b/libavformat/options.c
index 22ad523b2d..e4a3aceed0 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -44,7 +44,7 @@  static const char* format_to_name(void* ptr)
     AVFormatContext* fc = (AVFormatContext*) ptr;
     if(fc->iformat) return fc->iformat->name;
     else if(fc->oformat) return fc->oformat->name;
-    else return "NULL";
+    else return fc->av_class->class_name;
 }
 
 static void *format_child_next(void *obj, void *prev)