command: do not return 0 for bitrates if unknown

This makes the bitrate properties unavailable, instead of
returning 0 when:

1. No track is selected, or
2. Not enough packets have been read to have a bitrate estimate yet
This commit is contained in:
wm4 2015-10-23 14:53:19 +02:00
parent d1528e51d5
commit 955c6843b6
2 changed files with 5 additions and 2 deletions

View File

@ -1392,10 +1392,11 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg)
case DEMUXER_CTRL_GET_BITRATE_STATS: {
double *rates = arg;
for (int n = 0; n < STREAM_TYPE_COUNT; n++)
rates[n] = 0;
rates[n] = -1;
for (int n = 0; n < in->d_user->num_streams; n++) {
struct demux_stream *ds = in->d_user->streams[n]->ds;
rates[ds->type] += MPMAX(0, ds->bitrate);
if (ds->selected && ds->bitrate >= 0)
rates[ds->type] = MPMAX(0, rates[ds->type]) + ds->bitrate;
}
return DEMUXER_CTRL_OK;
}

View File

@ -3093,6 +3093,8 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop,
double r[STREAM_TYPE_COUNT];
if (demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_BITRATE_STATS, &r) < 1)
return M_PROPERTY_UNAVAILABLE;
if (r[type] < 0)
return M_PROPERTY_UNAVAILABLE;
// r[type] is in bytes/second -> bits
double rate = r[type] * 8;