[FFmpeg-devel] [PATCH] ffprobe: introduce print_val() macro, ease readability

Stefano Sabatini stefasab at gmail.com
Sun Nov 6 14:01:35 CET 2011


---
 ffprobe.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index a1a72c8..c2800f9 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -616,6 +616,7 @@ static void writer_register_all(void)
 #define print_str(k, v)         writer_print_string(w, k, v)
 #define print_ts(k, v)          writer_print_string(w, k, ts_value_string  (val_str, sizeof(val_str), v))
 #define print_time(k, v, tb)    writer_print_string(w, k, time_value_string(val_str, sizeof(val_str), v, tb))
+#define print_val(k, v, unit)   writer_print_string(w, k, value_string     (val_str, sizeof(val_str), v, unit))
 #define print_section_header(s) writer_print_section_header(w, s)
 #define print_section_footer(s) writer_print_section_footer(w, s)
 #define show_tags(metadata)     writer_show_tags(w, metadata)
@@ -635,7 +636,7 @@ static void show_packet(WriterContext *w, AVFormatContext *fmt_ctx, AVPacket *pk
     print_time("dts_time",        pkt->dts, &st->time_base);
     print_ts  ("duration",        pkt->duration);
     print_time("duration_time",   pkt->duration, &st->time_base);
-    print_str("size",             value_string     (val_str, sizeof(val_str), pkt->size, unit_byte_str));
+    print_val("size",             pkt->size, unit_byte_str);
     print_fmt("pos",   "%"PRId64, pkt->pos);
     print_fmt("flags", "%c",      pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
     print_section_footer("packet");
@@ -708,7 +709,7 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
         case AVMEDIA_TYPE_AUDIO:
             print_str("sample_fmt",
                       av_x_if_null(av_get_sample_fmt_name(dec_ctx->sample_fmt), "unknown"));
-            print_str("sample_rate",     value_string(val_str, sizeof(val_str), dec_ctx->sample_rate, unit_hertz_str));
+            print_val("sample_rate",     dec_ctx->sample_rate, unit_hertz_str);
             print_int("channels",        dec_ctx->channels);
             print_int("bits_per_sample", av_get_bits_per_sample(dec_ctx->codec_id));
             break;
@@ -766,8 +767,8 @@ static void show_format(WriterContext *w, AVFormatContext *fmt_ctx)
     print_time("start_time",      fmt_ctx->start_time, &AV_TIME_BASE_Q);
     print_time("duration",        fmt_ctx->duration,   &AV_TIME_BASE_Q);
     if (size >= 0)
-        print_str("size",         value_string(val_str, sizeof(val_str), size,               unit_byte_str));
-    print_str("bit_rate",         value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate,  unit_bit_per_second_str));
+        print_val("size",         size, unit_byte_str);
+    print_val("bit_rate",         fmt_ctx->bit_rate, unit_bit_per_second_str);
     show_tags(fmt_ctx->metadata);
     print_section_footer("format");
     av_free(pbuf.s);
-- 
1.7.4.1



More information about the ffmpeg-devel mailing list