summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-12-12 01:00:58 +0100
committerwm4 <wm4@nowhere>2014-12-12 01:00:58 +0100
commitd17c3b63c3f00e7c624be4b8f6b11096435ffb3d (patch)
tree850f251dc028ae92cb0e83ea4b15cf8baf941ae5 /player/command.c
parent47452443c50f34219ed0744eae9492f56b32b878 (diff)
downloadmpv-d17c3b63c3f00e7c624be4b8f6b11096435ffb3d.tar.bz2
mpv-d17c3b63c3f00e7c624be4b8f6b11096435ffb3d.tar.xz
command: add properties for current bitrate
Fixes #1192.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index 2387eb25d8..1b7156bb6c 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2970,6 +2970,23 @@ static int mp_property_ab_loop(void *ctx, struct m_property *prop,
return r;
}
+static int mp_property_packet_bitrate(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+ int type = (intptr_t)prop->priv;
+
+ if (!mpctx->demuxer)
+ return M_PROPERTY_UNAVAILABLE;
+
+ double r[STREAM_TYPE_COUNT];
+ if (demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_BITRATE_STATS, &r) < 1)
+ return M_PROPERTY_UNAVAILABLE;
+
+ // r[type] is in bytes/second -> kilobits
+ return m_property_int64_ro(action, arg, r[type] * 8 / 1000.0 + 0.5);
+}
+
static int mp_property_version(void *ctx, struct m_property *prop,
int action, void *arg)
{
@@ -3301,6 +3318,12 @@ static const struct m_property mp_properties[] = {
{"ab-loop-a", mp_property_ab_loop},
{"ab-loop-b", mp_property_ab_loop},
+#define PROPERTY_BITRATE(name, type) \
+ {name, mp_property_packet_bitrate, (void *)(intptr_t)type}
+ PROPERTY_BITRATE("packet-video-bitrate", STREAM_VIDEO),
+ PROPERTY_BITRATE("packet-audio-bitrate", STREAM_AUDIO),
+ PROPERTY_BITRATE("packet-sub-bitrate", STREAM_SUB),
+
#define PROPERTY_TV_COLOR(name, type) \
{name, mp_property_tv_color, (void *)(intptr_t)type}
PROPERTY_TV_COLOR("tv-brightness", TV_COLOR_BRIGHTNESS),