mirror of https://github.com/mpv-player/mpv
audio: move PTS setting out of the decoder
Instead of requiring the decoder to set the PTS directly on the dec_audio context (including handling absence of PTS etc.), transfer the packet PTS to the decoded audio frame. Marginally simpler, and gives more control to the generic code.
This commit is contained in:
parent
03013e0fd7
commit
d91434756b
|
@ -37,6 +37,8 @@ struct mp_audio {
|
||||||
int num_planes; // number of planes
|
int num_planes; // number of planes
|
||||||
int bps; // size of sub-samples (af_fmt_to_bytes(format))
|
int bps; // size of sub-samples (af_fmt_to_bytes(format))
|
||||||
|
|
||||||
|
double pts; // currently invalid within the filter chain
|
||||||
|
|
||||||
// --- private
|
// --- private
|
||||||
// These do not necessarily map directly to planes[]. They can have
|
// These do not necessarily map directly to planes[]. They can have
|
||||||
// different order or count. There shouldn't be more buffers than planes.
|
// different order or count. There shouldn't be more buffers than planes.
|
||||||
|
|
|
@ -191,12 +191,6 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
|
||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
mp_set_av_packet(&pkt, mpkt, NULL);
|
mp_set_av_packet(&pkt, mpkt, NULL);
|
||||||
|
|
||||||
// If we don't have a PTS yet, use the first packet PTS we can get.
|
|
||||||
if (da->pts == MP_NOPTS_VALUE && mpkt && mpkt->pts != MP_NOPTS_VALUE) {
|
|
||||||
da->pts = mpkt->pts;
|
|
||||||
da->pts_offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
av_frame_unref(priv->avframe);
|
av_frame_unref(priv->avframe);
|
||||||
int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt);
|
int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt);
|
||||||
|
@ -225,10 +219,6 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
|
||||||
return mpkt ? AD_OK : AD_EOF;
|
return mpkt ? AD_OK : AD_EOF;
|
||||||
|
|
||||||
double out_pts = mp_pts_from_av(priv->avframe->pkt_pts, NULL);
|
double out_pts = mp_pts_from_av(priv->avframe->pkt_pts, NULL);
|
||||||
if (out_pts != MP_NOPTS_VALUE) {
|
|
||||||
da->pts = out_pts;
|
|
||||||
da->pts_offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct mp_audio *mpframe = mp_audio_from_avframe(priv->avframe);
|
struct mp_audio *mpframe = mp_audio_from_avframe(priv->avframe);
|
||||||
if (!mpframe)
|
if (!mpframe)
|
||||||
|
@ -244,6 +234,8 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
|
||||||
}
|
}
|
||||||
mp_audio_set_channels(mpframe, &lavc_chmap);
|
mp_audio_set_channels(mpframe, &lavc_chmap);
|
||||||
|
|
||||||
|
mpframe->pts = out_pts;
|
||||||
|
|
||||||
#if HAVE_AVFRAME_SKIP_SAMPLES
|
#if HAVE_AVFRAME_SKIP_SAMPLES
|
||||||
AVFrameSideData *sd =
|
AVFrameSideData *sd =
|
||||||
av_frame_get_side_data(priv->avframe, AV_FRAME_DATA_SKIP_SAMPLES);
|
av_frame_get_side_data(priv->avframe, AV_FRAME_DATA_SKIP_SAMPLES);
|
||||||
|
@ -254,7 +246,8 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
|
||||||
uint32_t skip = MPMIN(priv->skip_samples, mpframe->samples);
|
uint32_t skip = MPMIN(priv->skip_samples, mpframe->samples);
|
||||||
if (skip) {
|
if (skip) {
|
||||||
mp_audio_skip_samples(mpframe, skip);
|
mp_audio_skip_samples(mpframe, skip);
|
||||||
da->pts_offset += skip;
|
if (mpframe->pts != MP_NOPTS_VALUE)
|
||||||
|
mpframe->pts += skip / (double)mpframe->rate;
|
||||||
priv->skip_samples -= skip;
|
priv->skip_samples -= skip;
|
||||||
}
|
}
|
||||||
if (pad <= mpframe->samples)
|
if (pad <= mpframe->samples)
|
||||||
|
|
|
@ -253,13 +253,11 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
|
||||||
if (!mpkt)
|
if (!mpkt)
|
||||||
return AD_EOF;
|
return AD_EOF;
|
||||||
|
|
||||||
|
double pts = mpkt->pts;
|
||||||
|
|
||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
mp_set_av_packet(&pkt, mpkt, NULL);
|
mp_set_av_packet(&pkt, mpkt, NULL);
|
||||||
pkt.pts = pkt.dts = 0;
|
pkt.pts = pkt.dts = 0;
|
||||||
if (mpkt->pts != MP_NOPTS_VALUE) {
|
|
||||||
da->pts = mpkt->pts;
|
|
||||||
da->pts_offset = 0;
|
|
||||||
}
|
|
||||||
if (!spdif_ctx->lavf_ctx) {
|
if (!spdif_ctx->lavf_ctx) {
|
||||||
if (init_filter(da, &pkt) < 0)
|
if (init_filter(da, &pkt) < 0)
|
||||||
return AD_ERR;
|
return AD_ERR;
|
||||||
|
@ -276,6 +274,7 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
|
||||||
return AD_ERR;
|
return AD_ERR;
|
||||||
|
|
||||||
memcpy((*out)->planes[0], spdif_ctx->out_buffer, spdif_ctx->out_buffer_len);
|
memcpy((*out)->planes[0], spdif_ctx->out_buffer, spdif_ctx->out_buffer_len);
|
||||||
|
(*out)->pts = pts;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,14 +170,18 @@ static int decode_new_frame(struct dec_audio *da)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (da->pts == MP_NOPTS_VALUE && da->header->missing_timestamps)
|
|
||||||
da->pts = 0;
|
|
||||||
|
|
||||||
if (da->waiting) {
|
if (da->waiting) {
|
||||||
|
if (da->waiting->pts != MP_NOPTS_VALUE) {
|
||||||
|
da->pts = da->waiting->pts;
|
||||||
|
da->pts_offset = 0;
|
||||||
|
}
|
||||||
da->pts_offset += da->waiting->samples;
|
da->pts_offset += da->waiting->samples;
|
||||||
da->decode_format = *da->waiting;
|
da->decode_format = *da->waiting;
|
||||||
mp_audio_set_null_data(&da->decode_format);
|
mp_audio_set_null_data(&da->decode_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (da->pts == MP_NOPTS_VALUE && da->header->missing_timestamps)
|
||||||
|
da->pts = 0;
|
||||||
}
|
}
|
||||||
return mp_audio_config_valid(da->waiting) ? AD_OK : AD_ERR;
|
return mp_audio_config_valid(da->waiting) ? AD_OK : AD_ERR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue