mirror of
https://github.com/mpv-player/mpv
synced 2024-12-25 16:33:02 +00:00
audio: change values from bytes-per-second to bits-per-second
The i_bps members of the sh_audio and dev_video structs are mostly used for displaying the average audio and video bitrates. Keeping them in bits-per-second avoids truncating them to bytes-per-second and changing them back lateron.
This commit is contained in:
parent
b442b522f6
commit
6e58b20cce
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user