[FFmpeg-cvslog] avprobe: add local per-file state

Anton Khirnov git at videolan.org
Mon Apr 11 17:33:28 CEST 2016


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Feb 24 14:56:15 2016 +0100| [c9478410c68c04261f9cfcd80474607e50bd1852] | committer: Anton Khirnov

avprobe: add local per-file state

Do not pass just a bare AVFormatContext pointer around, wrap it in
struct. This will be useful in the following commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c9478410c68c04261f9cfcd80474607e50bd1852
---

 avprobe.c |   38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/avprobe.c b/avprobe.c
index 1fdcd01..b395e93 100644
--- a/avprobe.c
+++ b/avprobe.c
@@ -32,6 +32,10 @@
 #include "libavdevice/avdevice.h"
 #include "cmdutils.h"
 
+typedef struct InputFile {
+    AVFormatContext *fmt_ctx;
+} InputFile;
+
 const char program_name[] = "avprobe";
 const int program_birth_year = 2007;
 
@@ -583,8 +587,9 @@ static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
     probe_object_footer("packet");
 }
 
-static void show_packets(AVFormatContext *fmt_ctx)
+static void show_packets(InputFile *ifile)
 {
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
     AVPacket pkt;
 
     av_init_packet(&pkt);
@@ -596,8 +601,9 @@ static void show_packets(AVFormatContext *fmt_ctx)
     probe_array_footer("packets", 0);
 }
 
-static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
+static void show_stream(InputFile *ifile, int stream_idx)
 {
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
     AVStream *stream = fmt_ctx->streams[stream_idx];
     AVCodecContext *dec_ctx;
     const AVCodecDescriptor *codec_desc;
@@ -726,8 +732,9 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
     probe_object_footer("stream");
 }
 
-static void show_format(AVFormatContext *fmt_ctx)
+static void show_format(InputFile *ifile)
 {
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
     char val_str[128];
     int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
 
@@ -755,7 +762,7 @@ static void show_format(AVFormatContext *fmt_ctx)
     probe_object_footer("format");
 }
 
-static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
+static int open_input_file(InputFile *ifile, const char *filename)
 {
     int err, i;
     AVFormatContext *fmt_ctx = NULL;
@@ -798,14 +805,14 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
         }
     }
 
-    *fmt_ctx_ptr = fmt_ctx;
+    ifile->fmt_ctx = fmt_ctx;
     return 0;
 }
 
-static void close_input_file(AVFormatContext **ctx_ptr)
+static void close_input_file(InputFile *ifile)
 {
     int i;
-    AVFormatContext *fmt_ctx = *ctx_ptr;
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
 
     /* close decoder for each stream */
     for (i = 0; i < fmt_ctx->nb_streams; i++) {
@@ -813,31 +820,32 @@ static void close_input_file(AVFormatContext **ctx_ptr)
 
         avcodec_close(stream->codec);
     }
-    avformat_close_input(ctx_ptr);
+    avformat_close_input(&ifile->fmt_ctx);
 }
 
 static int probe_file(const char *filename)
 {
-    AVFormatContext *fmt_ctx;
+    InputFile ifile;
     int ret, i;
 
-    if ((ret = open_input_file(&fmt_ctx, filename)))
+    ret = open_input_file(&ifile, filename);
+    if (ret < 0)
         return ret;
 
     if (do_show_format)
-        show_format(fmt_ctx);
+        show_format(&ifile);
 
     if (do_show_streams) {
         probe_array_header("streams", 0);
-        for (i = 0; i < fmt_ctx->nb_streams; i++)
-            show_stream(fmt_ctx, i);
+        for (i = 0; i < ifile.fmt_ctx->nb_streams; i++)
+            show_stream(&ifile, i);
         probe_array_footer("streams", 0);
     }
 
     if (do_show_packets)
-        show_packets(fmt_ctx);
+        show_packets(&ifile);
 
-    close_input_file(&fmt_ctx);
+    close_input_file(&ifile);
     return 0;
 }
 



More information about the ffmpeg-cvslog mailing list