diff options
author | Stefan Sauer <ensonic@users.sf.net> | 2013-10-03 22:23:22 +0200 |
---|---|---|
committer | Stefan Sauer <ensonic@users.sf.net> | 2013-10-03 22:24:35 +0200 |
commit | c011ec4dd498e7954e8825694d9abe992d5335e4 (patch) | |
tree | ea7c9ac3bb1910afd18017db92232a3534d8418b /mediainfo | |
parent | faa74e09b93fb8b6e976accb96d730bb3bcff544 (diff) |
mi-info: add a helper to format bit-rates
Print bit-rates in kbit/sec. Add handling for unknown values and ranges.
Diffstat (limited to 'mediainfo')
-rw-r--r-- | mediainfo/src/mi-info.vala | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/mediainfo/src/mi-info.vala b/mediainfo/src/mi-info.vala index 9669706..ef509c2 100644 --- a/mediainfo/src/mi-info.vala +++ b/mediainfo/src/mi-info.vala @@ -602,8 +602,7 @@ public class MediaInfo.Info : Box add_table_rows_for_caps (table, row, "Codec:", sinfo.get_caps ()); row+=2; - str = "%u / %u bits/second".printf (vinfo.get_bitrate(), vinfo.get_max_bitrate()); - add_table_row_for_string (table, row, "Bitrate:", str); + add_table_row_for_bitrates (table, row, vinfo.get_bitrate(), vinfo.get_max_bitrate()); row++; // add named resolutions: (640x480=VGA) @@ -654,8 +653,7 @@ public class MediaInfo.Info : Box add_table_rows_for_caps (table, row, "Codec:", sinfo.get_caps ()); row+=2; - str = "%u / %u bits/second".printf (ainfo.get_bitrate(),ainfo.get_max_bitrate()); - add_table_row_for_string (table, row, "Bitrate:", str); + add_table_row_for_bitrates (table, row, ainfo.get_bitrate(), ainfo.get_max_bitrate()); row++; str = "%u samples/second".printf (ainfo.get_sample_rate()); @@ -761,6 +759,25 @@ public class MediaInfo.Info : Box table.attach (label, 1, 2, row, row+1, fill_exp, 0, 3, 1); } + private void add_table_row_for_bitrates (Table table, uint row, uint br, uint mbr) { + string str; + + if (br == mbr) { + mbr = 0; // no point in printing this as a range + } + + if (mbr != 0) { + str = "%.2f ... %.2f kbit/second".printf (br/1024.0, mbr/1024.0); + } else { + if (br != 0) { + str = "%.2f kbit/second".printf (br/1024.0); + } else { + str = "unknown"; + } + } + add_table_row_for_string (table, row, "Bitrate:", str); + } + private void add_table_row_for_string (Table table, uint row, string title, string? str) { AttachOptions fill = AttachOptions.FILL; AttachOptions fill_exp = AttachOptions.EXPAND|AttachOptions.FILL; |