* commit 'c9478410c68c04261f9cfcd80474607e50bd1852':
avprobe: add local per-file state
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
... | ... |
@@ -49,6 +49,10 @@ |
49 | 49 |
#include "libpostproc/postprocess.h" |
50 | 50 |
#include "cmdutils.h" |
51 | 51 |
|
52 |
+typedef struct InputFile { |
|
53 |
+ AVFormatContext *fmt_ctx; |
|
54 |
+} InputFile; |
|
55 |
+ |
|
52 | 56 |
const char program_name[] = "ffprobe"; |
53 | 57 |
const int program_birth_year = 2007; |
54 | 58 |
|
... | ... |
@@ -2105,8 +2109,9 @@ end: |
2105 | 2105 |
return ret; |
2106 | 2106 |
} |
2107 | 2107 |
|
2108 |
-static int read_packets(WriterContext *w, AVFormatContext *fmt_ctx) |
|
2108 |
+static int read_packets(WriterContext *w, InputFile *ifile) |
|
2109 | 2109 |
{ |
2110 |
+ AVFormatContext *fmt_ctx = ifile->fmt_ctx; |
|
2110 | 2111 |
int i, ret = 0; |
2111 | 2112 |
int64_t cur_ts = fmt_ctx->start_time; |
2112 | 2113 |
|
... | ... |
@@ -2355,8 +2360,9 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id |
2355 | 2355 |
return ret; |
2356 | 2356 |
} |
2357 | 2357 |
|
2358 |
-static int show_streams(WriterContext *w, AVFormatContext *fmt_ctx) |
|
2358 |
+static int show_streams(WriterContext *w, InputFile *ifile) |
|
2359 | 2359 |
{ |
2360 |
+ AVFormatContext *fmt_ctx = ifile->fmt_ctx; |
|
2360 | 2361 |
int i, ret = 0; |
2361 | 2362 |
|
2362 | 2363 |
writer_print_section_header(w, SECTION_ID_STREAMS); |
... | ... |
@@ -2405,8 +2411,9 @@ end: |
2405 | 2405 |
return ret; |
2406 | 2406 |
} |
2407 | 2407 |
|
2408 |
-static int show_programs(WriterContext *w, AVFormatContext *fmt_ctx) |
|
2408 |
+static int show_programs(WriterContext *w, InputFile *ifile) |
|
2409 | 2409 |
{ |
2410 |
+ AVFormatContext *fmt_ctx = ifile->fmt_ctx; |
|
2410 | 2411 |
int i, ret = 0; |
2411 | 2412 |
|
2412 | 2413 |
writer_print_section_header(w, SECTION_ID_PROGRAMS); |
... | ... |
@@ -2422,8 +2429,9 @@ static int show_programs(WriterContext *w, AVFormatContext *fmt_ctx) |
2422 | 2422 |
return ret; |
2423 | 2423 |
} |
2424 | 2424 |
|
2425 |
-static int show_chapters(WriterContext *w, AVFormatContext *fmt_ctx) |
|
2425 |
+static int show_chapters(WriterContext *w, InputFile *ifile) |
|
2426 | 2426 |
{ |
2427 |
+ AVFormatContext *fmt_ctx = ifile->fmt_ctx; |
|
2427 | 2428 |
int i, ret = 0; |
2428 | 2429 |
|
2429 | 2430 |
writer_print_section_header(w, SECTION_ID_CHAPTERS); |
... | ... |
@@ -2446,8 +2454,9 @@ static int show_chapters(WriterContext *w, AVFormatContext *fmt_ctx) |
2446 | 2446 |
return ret; |
2447 | 2447 |
} |
2448 | 2448 |
|
2449 |
-static int show_format(WriterContext *w, AVFormatContext *fmt_ctx) |
|
2449 |
+static int show_format(WriterContext *w, InputFile *ifile) |
|
2450 | 2450 |
{ |
2451 |
+ AVFormatContext *fmt_ctx = ifile->fmt_ctx; |
|
2451 | 2452 |
char val_str[128]; |
2452 | 2453 |
int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1; |
2453 | 2454 |
int ret = 0; |
... | ... |
@@ -2490,7 +2499,7 @@ static void show_error(WriterContext *w, int err) |
2490 | 2490 |
writer_print_section_footer(w); |
2491 | 2491 |
} |
2492 | 2492 |
|
2493 |
-static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) |
|
2493 |
+static int open_input_file(InputFile *ifile, const char *filename) |
|
2494 | 2494 |
{ |
2495 | 2495 |
int err, i, orig_nb_streams; |
2496 | 2496 |
AVFormatContext *fmt_ctx = NULL; |
... | ... |
@@ -2507,7 +2516,7 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) |
2507 | 2507 |
print_error(filename, err); |
2508 | 2508 |
return err; |
2509 | 2509 |
} |
2510 |
- *fmt_ctx_ptr = fmt_ctx; |
|
2510 |
+ ifile->fmt_ctx = fmt_ctx; |
|
2511 | 2511 |
if (scan_all_pmts_set) |
2512 | 2512 |
av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); |
2513 | 2513 |
if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) { |
... | ... |
@@ -2560,47 +2569,47 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) |
2560 | 2560 |
} |
2561 | 2561 |
} |
2562 | 2562 |
|
2563 |
- *fmt_ctx_ptr = fmt_ctx; |
|
2563 |
+ ifile->fmt_ctx = fmt_ctx; |
|
2564 | 2564 |
return 0; |
2565 | 2565 |
} |
2566 | 2566 |
|
2567 |
-static void close_input_file(AVFormatContext **ctx_ptr) |
|
2567 |
+static void close_input_file(InputFile *ifile) |
|
2568 | 2568 |
{ |
2569 | 2569 |
int i; |
2570 |
- AVFormatContext *fmt_ctx = *ctx_ptr; |
|
2570 |
+ AVFormatContext *fmt_ctx = ifile->fmt_ctx; |
|
2571 | 2571 |
|
2572 | 2572 |
/* close decoder for each stream */ |
2573 | 2573 |
for (i = 0; i < fmt_ctx->nb_streams; i++) |
2574 | 2574 |
if (fmt_ctx->streams[i]->codec->codec_id != AV_CODEC_ID_NONE) |
2575 | 2575 |
avcodec_close(fmt_ctx->streams[i]->codec); |
2576 | 2576 |
|
2577 |
- avformat_close_input(ctx_ptr); |
|
2577 |
+ avformat_close_input(&ifile->fmt_ctx); |
|
2578 | 2578 |
} |
2579 | 2579 |
|
2580 | 2580 |
static int probe_file(WriterContext *wctx, const char *filename) |
2581 | 2581 |
{ |
2582 |
- AVFormatContext *fmt_ctx = NULL; |
|
2582 |
+ InputFile ifile = { 0 }; |
|
2583 | 2583 |
int ret, i; |
2584 | 2584 |
int section_id; |
2585 | 2585 |
|
2586 | 2586 |
do_read_frames = do_show_frames || do_count_frames; |
2587 | 2587 |
do_read_packets = do_show_packets || do_count_packets; |
2588 | 2588 |
|
2589 |
- ret = open_input_file(&fmt_ctx, filename); |
|
2589 |
+ ret = open_input_file(&ifile, filename); |
|
2590 | 2590 |
if (ret < 0) |
2591 | 2591 |
goto end; |
2592 | 2592 |
|
2593 | 2593 |
#define CHECK_END if (ret < 0) goto end |
2594 | 2594 |
|
2595 |
- nb_streams = fmt_ctx->nb_streams; |
|
2596 |
- REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,fmt_ctx->nb_streams); |
|
2597 |
- REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,fmt_ctx->nb_streams); |
|
2598 |
- REALLOCZ_ARRAY_STREAM(selected_streams,0,fmt_ctx->nb_streams); |
|
2595 |
+ nb_streams = ifile.fmt_ctx->nb_streams; |
|
2596 |
+ REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams); |
|
2597 |
+ REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams); |
|
2598 |
+ REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams); |
|
2599 | 2599 |
|
2600 |
- for (i = 0; i < fmt_ctx->nb_streams; i++) { |
|
2600 |
+ for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) { |
|
2601 | 2601 |
if (stream_specifier) { |
2602 |
- ret = avformat_match_stream_specifier(fmt_ctx, |
|
2603 |
- fmt_ctx->streams[i], |
|
2602 |
+ ret = avformat_match_stream_specifier(ifile.fmt_ctx, |
|
2603 |
+ ifile.fmt_ctx->streams[i], |
|
2604 | 2604 |
stream_specifier); |
2605 | 2605 |
CHECK_END; |
2606 | 2606 |
else |
... | ... |
@@ -2621,33 +2630,33 @@ static int probe_file(WriterContext *wctx, const char *filename) |
2621 | 2621 |
section_id = SECTION_ID_FRAMES; |
2622 | 2622 |
if (do_show_frames || do_show_packets) |
2623 | 2623 |
writer_print_section_header(wctx, section_id); |
2624 |
- ret = read_packets(wctx, fmt_ctx); |
|
2624 |
+ ret = read_packets(wctx, &ifile); |
|
2625 | 2625 |
if (do_show_frames || do_show_packets) |
2626 | 2626 |
writer_print_section_footer(wctx); |
2627 | 2627 |
CHECK_END; |
2628 | 2628 |
} |
2629 | 2629 |
|
2630 | 2630 |
if (do_show_programs) { |
2631 |
- ret = show_programs(wctx, fmt_ctx); |
|
2631 |
+ ret = show_programs(wctx, &ifile); |
|
2632 | 2632 |
CHECK_END; |
2633 | 2633 |
} |
2634 | 2634 |
|
2635 | 2635 |
if (do_show_streams) { |
2636 |
- ret = show_streams(wctx, fmt_ctx); |
|
2636 |
+ ret = show_streams(wctx, &ifile); |
|
2637 | 2637 |
CHECK_END; |
2638 | 2638 |
} |
2639 | 2639 |
if (do_show_chapters) { |
2640 |
- ret = show_chapters(wctx, fmt_ctx); |
|
2640 |
+ ret = show_chapters(wctx, &ifile); |
|
2641 | 2641 |
CHECK_END; |
2642 | 2642 |
} |
2643 | 2643 |
if (do_show_format) { |
2644 |
- ret = show_format(wctx, fmt_ctx); |
|
2644 |
+ ret = show_format(wctx, &ifile); |
|
2645 | 2645 |
CHECK_END; |
2646 | 2646 |
} |
2647 | 2647 |
|
2648 | 2648 |
end: |
2649 |
- if (fmt_ctx) |
|
2650 |
- close_input_file(&fmt_ctx); |
|
2649 |
+ if (ifile.fmt_ctx) |
|
2650 |
+ close_input_file(&ifile); |
|
2651 | 2651 |
av_freep(&nb_streams_frames); |
2652 | 2652 |
av_freep(&nb_streams_packets); |
2653 | 2653 |
av_freep(&selected_streams); |