summaryrefslogtreecommitdiffstats
path: root/audio/decode/ad_lavc.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-11-08 17:22:56 +0100
committerwm4 <wm4@nowhere>2015-11-08 17:22:56 +0100
commitd91434756b1bd16d788d93e6b888c2d1a54f1968 (patch)
treea1960427fac54e8ecbf2f2309dafdefb2d663aaa /audio/decode/ad_lavc.c
parent03013e0fd73cde9b0dc7f2d65387491000ee894b (diff)
downloadmpv-d91434756b1bd16d788d93e6b888c2d1a54f1968.tar.bz2
mpv-d91434756b1bd16d788d93e6b888c2d1a54f1968.tar.xz
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.
Diffstat (limited to 'audio/decode/ad_lavc.c')
-rw-r--r--audio/decode/ad_lavc.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index ce628877be..3188834830 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -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)