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:
wm4 2015-11-08 17:22:56 +01:00
parent 03013e0fd7
commit d91434756b
4 changed files with 16 additions and 18 deletions

View File

@ -37,6 +37,8 @@ struct mp_audio {
int num_planes; // number of planes
int bps; // size of sub-samples (af_fmt_to_bytes(format))
double pts; // currently invalid within the filter chain
// --- private
// These do not necessarily map directly to planes[]. They can have
// different order or count. There shouldn't be more buffers than planes.

View File

@ -191,12 +191,6 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
AVPacket pkt;
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;
av_frame_unref(priv->avframe);
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;
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);
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);
mpframe->pts = out_pts;
#if HAVE_AVFRAME_SKIP_SAMPLES
AVFrameSideData *sd =
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);
if (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;
}
if (pad <= mpframe->samples)

View File

@ -253,13 +253,11 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
if (!mpkt)
return AD_EOF;
double pts = mpkt->pts;
AVPacket pkt;
mp_set_av_packet(&pkt, mpkt, NULL);
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 (init_filter(da, &pkt) < 0)
return AD_ERR;
@ -276,6 +274,7 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
return AD_ERR;
memcpy((*out)->planes[0], spdif_ctx->out_buffer, spdif_ctx->out_buffer_len);
(*out)->pts = pts;
return 0;
}

View File

@ -170,14 +170,18 @@ static int decode_new_frame(struct dec_audio *da)
if (ret < 0)
return ret;
if (da->pts == MP_NOPTS_VALUE && da->header->missing_timestamps)
da->pts = 0;
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->decode_format = *da->waiting;
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;
}