summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/decode/ad_lavc.c6
-rw-r--r--audio/decode/ad_mpg123.c12
-rw-r--r--demux/demux_lavf.c4
-rw-r--r--demux/demux_raw.c2
-rw-r--r--demux/stheader.h4
-rw-r--r--player/command.c2
-rw-r--r--stream/tv.c9
-rw-r--r--video/decode/dec_video.c4
-rw-r--r--video/decode/dec_video.h2
9 files changed, 24 insertions, 21 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index 802683bf7b..b013400cab 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -229,7 +229,7 @@ static int init(struct dec_audio *da, const char *decoder)
lavc_context->codec_tag = sh->format;
lavc_context->sample_rate = sh_audio->samplerate;
- lavc_context->bit_rate = sh_audio->i_bps * 8;
+ lavc_context->bit_rate = sh_audio->i_bps;
lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels);
if (sh_audio->wf)
@@ -270,9 +270,9 @@ static int init(struct dec_audio *da, const char *decoder)
}
}
- da->i_bps = lavc_context->bit_rate / 8;
+ da->i_bps = lavc_context->bit_rate;
if (sh_audio->wf && sh_audio->wf->nAvgBytesPerSec)
- da->i_bps = sh_audio->wf->nAvgBytesPerSec;
+ da->i_bps = sh_audio->wf->nAvgBytesPerSec * 8;
return 1;
}
diff --git a/audio/decode/ad_mpg123.c b/audio/decode/ad_mpg123.c
index 4d4fd52862..3c76eb51b3 100644
--- a/audio/decode/ad_mpg123.c
+++ b/audio/decode/ad_mpg123.c
@@ -254,7 +254,7 @@ static int compute_bitrate(struct mpg123_frameinfo *i)
{-1, 384, 1152, 576}, /* MPEG 2.5 */
{-1, -1, -1, -1}, /* Unknown */
};
- return (int) ((i->framesize + 4) * 8 * i->rate * 0.001 /
+ return (int) ((i->framesize + 4) * 8 * i->rate /
samples_per_frame[i->version][i->layer] + 0.5);
}
@@ -267,6 +267,9 @@ static void update_info(struct dec_audio *da)
if (mpg123_info(con->handle, &finfo) != MPG123_OK)
return;
+ /* finfo.bitrate is expressed in kilobits */
+ const int bitrate = finfo.bitrate * 1000;
+
if (finfo.vbr != MPG123_CBR) {
if (--con->delay < 1) {
if (++con->mean_count > ((unsigned int) -1) / 2)
@@ -274,14 +277,13 @@ static void update_info(struct dec_audio *da)
/* Might not be numerically optimal, but works fine enough. */
con->mean_rate = ((con->mean_count - 1) * con->mean_rate +
- finfo.bitrate) / con->mean_count;
- da->i_bps = (int) (con->mean_rate * 1000 / 8);
+ bitrate) / con->mean_count;
+ da->i_bps = (int) (con->mean_rate + 0.5);
con->delay = 10;
}
} else {
- da->i_bps = (finfo.bitrate ? finfo.bitrate : compute_bitrate(&finfo))
- * 1000 / 8;
+ da->i_bps = bitrate ? bitrate : compute_bitrate(&finfo);
con->delay = 1;
con->mean_rate = 0.;
con->mean_count = 0;
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 2b43f4f27f..75e6cb41f0 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -433,7 +433,7 @@ static void handle_stream(demuxer_t *demuxer, int i)
if (codec->channel_layout)
mp_chmap_from_lavc(&sh_audio->channels, codec->channel_layout);
sh_audio->samplerate = codec->sample_rate;
- sh_audio->i_bps = codec->bit_rate / 8;
+ sh_audio->i_bps = codec->bit_rate;
export_replaygain(demuxer, st);
@@ -477,7 +477,7 @@ static void handle_stream(demuxer_t *demuxer, int i)
else
sh_video->aspect = codec->width * codec->sample_aspect_ratio.num
/ (float)(codec->height * codec->sample_aspect_ratio.den);
- sh_video->i_bps = codec->bit_rate / 8;
+ sh_video->i_bps = codec->bit_rate;
AVDictionaryEntry *rot = av_dict_get(st->metadata, "rotate", NULL, 0);
if (rot && rot->value) {
diff --git a/demux/demux_raw.c b/demux/demux_raw.c
index 3c605e3f96..ceb5d7bf30 100644
--- a/demux/demux_raw.c
+++ b/demux/demux_raw.c
@@ -179,7 +179,7 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check)
sh_video->fps = fps;
sh_video->disp_w = width;
sh_video->disp_h = height;
- sh_video->i_bps = fps * imgsize;
+ sh_video->i_bps = fps * imgsize * 8;
struct priv *p = talloc_ptrtype(demuxer, p);
demuxer->priv = p;
diff --git a/demux/stheader.h b/demux/stheader.h
index 99dc35832a..c8a72795b0 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -67,7 +67,7 @@ struct sh_stream {
typedef struct sh_audio {
int samplerate;
struct mp_chmap channels;
- int i_bps; // == bitrate (compressed bytes/sec)
+ int i_bps; // == bitrate (compressed bits/sec)
// win32-compatible codec parameters:
MP_WAVEFORMATEX *wf;
// note codec extradata may be either under "wf" or "codecdata"
@@ -79,7 +79,7 @@ typedef struct sh_video {
bool avi_dts; // use DTS timing; first frame and DTS is 0
float fps; // frames per second (set only if constant fps)
float aspect; // aspect ratio stored in the file (for prescaling)
- int i_bps; // == bitrate (compressed bytes/sec)
+ int i_bps; // == bitrate (compressed bits/sec)
int disp_w, disp_h; // display size
int rotate; // intended display rotation, in degrees, [0, 359]
MP_BITMAPINFOHEADER *bih;
diff --git a/player/command.c b/player/command.c
index 29137024ee..7e391e673f 100644
--- a/player/command.c
+++ b/player/command.c
@@ -105,7 +105,7 @@ static void mark_seek(struct MPContext *mpctx)
static char *format_bitrate(int rate)
{
- return talloc_asprintf(NULL, "%d kbps", rate * 8 / 1000);
+ return talloc_asprintf(NULL, "%d kbps", rate / 1000);
}
static char *format_file_size(int64_t size)
diff --git a/stream/tv.c b/stream/tv.c
index aa7367f276..9d7e17a871 100644
--- a/stream/tv.c
+++ b/stream/tv.c
@@ -803,9 +803,10 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
sh_a->format = audio_format;
int samplesize = af_fmt2bits(audio_format) / 8;
+ int block_align = samplesize * sh_audio->channels.num;
+ int bytes_per_second = sh_audio->samplerate * block_align;
- sh_audio->i_bps =
- sh_audio->samplerate * samplesize * sh_audio->channels.num;
+ sh_audio->i_bps = bytes_per_second * 8;
// emulate WF for win32 codecs:
sh_audio->wf = talloc_zero(sh_audio, MP_WAVEFORMATEX);
@@ -813,8 +814,8 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
sh_audio->wf->nChannels = sh_audio->channels.num;
sh_audio->wf->wBitsPerSample = samplesize * 8;
sh_audio->wf->nSamplesPerSec = sh_audio->samplerate;
- sh_audio->wf->nBlockAlign = samplesize * sh_audio->channels.num;
- sh_audio->wf->nAvgBytesPerSec = sh_audio->i_bps;
+ sh_audio->wf->nBlockAlign = block_align;
+ sh_audio->wf->nAvgBytesPerSec = bytes_per_second;
MP_VERBOSE(tvh, " TV audio: %d channels, %d bits, %d Hz\n",
sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample,
diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c
index dcadb5e491..57307b7399 100644
--- a/video/decode/dec_video.c
+++ b/video/decode/dec_video.c
@@ -388,8 +388,8 @@ int video_reconfig_filters(struct dec_video *d_video,
struct sh_video *sh = d_video->header->video;
MP_VERBOSE(d_video, "VIDEO: %dx%d %5.3f fps %5.1f kbps (%4.1f kB/s)\n",
- p.w, p.h, sh->fps, sh->i_bps * 0.008,
- sh->i_bps / 1000.0);
+ p.w, p.h, sh->fps, sh->i_bps / 1000.0,
+ sh->i_bps / 8000.0);
MP_VERBOSE(d_video, "VDec: vo config request - %d x %d (%s)\n",
p.w, p.h, vo_format_name(p.imgfmt));
diff --git a/video/decode/dec_video.h b/video/decode/dec_video.h
index 58ec99a86b..e0f07e0531 100644
--- a/video/decode/dec_video.h
+++ b/video/decode/dec_video.h
@@ -73,7 +73,7 @@ struct dec_video {
double decoded_pts;
float stream_aspect; // aspect ratio in media headers (DVD IFO files)
- int i_bps; // == bitrate (compressed bytes/sec)
+ int i_bps; // == bitrate (compressed bits/sec)
float fps; // FPS from demuxer or from user override
float initial_decoder_aspect;