Browse code

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.

Anton Khirnov authored on 2016/02/24 22:56:15
Showing 1 changed files
... ...
@@ -32,6 +32,10 @@
32 32
 #include "libavdevice/avdevice.h"
33 33
 #include "cmdutils.h"
34 34
 
35
+typedef struct InputFile {
36
+    AVFormatContext *fmt_ctx;
37
+} InputFile;
38
+
35 39
 const char program_name[] = "avprobe";
36 40
 const int program_birth_year = 2007;
37 41
 
... ...
@@ -583,8 +587,9 @@ static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
583 583
     probe_object_footer("packet");
584 584
 }
585 585
 
586
-static void show_packets(AVFormatContext *fmt_ctx)
586
+static void show_packets(InputFile *ifile)
587 587
 {
588
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
588 589
     AVPacket pkt;
589 590
 
590 591
     av_init_packet(&pkt);
... ...
@@ -596,8 +601,9 @@ static void show_packets(AVFormatContext *fmt_ctx)
596 596
     probe_array_footer("packets", 0);
597 597
 }
598 598
 
599
-static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
599
+static void show_stream(InputFile *ifile, int stream_idx)
600 600
 {
601
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
601 602
     AVStream *stream = fmt_ctx->streams[stream_idx];
602 603
     AVCodecContext *dec_ctx;
603 604
     const AVCodecDescriptor *codec_desc;
... ...
@@ -726,8 +732,9 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
726 726
     probe_object_footer("stream");
727 727
 }
728 728
 
729
-static void show_format(AVFormatContext *fmt_ctx)
729
+static void show_format(InputFile *ifile)
730 730
 {
731
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
731 732
     char val_str[128];
732 733
     int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
733 734
 
... ...
@@ -755,7 +762,7 @@ static void show_format(AVFormatContext *fmt_ctx)
755 755
     probe_object_footer("format");
756 756
 }
757 757
 
758
-static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
758
+static int open_input_file(InputFile *ifile, const char *filename)
759 759
 {
760 760
     int err, i;
761 761
     AVFormatContext *fmt_ctx = NULL;
... ...
@@ -798,14 +805,14 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
798 798
         }
799 799
     }
800 800
 
801
-    *fmt_ctx_ptr = fmt_ctx;
801
+    ifile->fmt_ctx = fmt_ctx;
802 802
     return 0;
803 803
 }
804 804
 
805
-static void close_input_file(AVFormatContext **ctx_ptr)
805
+static void close_input_file(InputFile *ifile)
806 806
 {
807 807
     int i;
808
-    AVFormatContext *fmt_ctx = *ctx_ptr;
808
+    AVFormatContext *fmt_ctx = ifile->fmt_ctx;
809 809
 
810 810
     /* close decoder for each stream */
811 811
     for (i = 0; i < fmt_ctx->nb_streams; i++) {
... ...
@@ -813,31 +820,32 @@ static void close_input_file(AVFormatContext **ctx_ptr)
813 813
 
814 814
         avcodec_close(stream->codec);
815 815
     }
816
-    avformat_close_input(ctx_ptr);
816
+    avformat_close_input(&ifile->fmt_ctx);
817 817
 }
818 818
 
819 819
 static int probe_file(const char *filename)
820 820
 {
821
-    AVFormatContext *fmt_ctx;
821
+    InputFile ifile;
822 822
     int ret, i;
823 823
 
824
-    if ((ret = open_input_file(&fmt_ctx, filename)))
824
+    ret = open_input_file(&ifile, filename);
825
+    if (ret < 0)
825 826
         return ret;
826 827
 
827 828
     if (do_show_format)
828
-        show_format(fmt_ctx);
829
+        show_format(&ifile);
829 830
 
830 831
     if (do_show_streams) {
831 832
         probe_array_header("streams", 0);
832
-        for (i = 0; i < fmt_ctx->nb_streams; i++)
833
-            show_stream(fmt_ctx, i);
833
+        for (i = 0; i < ifile.fmt_ctx->nb_streams; i++)
834
+            show_stream(&ifile, i);
834 835
         probe_array_footer("streams", 0);
835 836
     }
836 837
 
837 838
     if (do_show_packets)
838
-        show_packets(fmt_ctx);
839
+        show_packets(&ifile);
839 840
 
840
-    close_input_file(&fmt_ctx);
841
+    close_input_file(&ifile);
841 842
     return 0;
842 843
 }
843 844