summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/audio.h2
-rw-r--r--audio/decode/ad_lavc.c15
-rw-r--r--audio/decode/ad_spdif.c7
-rw-r--r--audio/decode/dec_audio.c10
4 files changed, 16 insertions, 18 deletions
diff --git a/audio/audio.h b/audio/audio.h
index bf5358274a..c74d0f778c 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -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.
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)
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index 88f3f2ba2b..5e9dcf1c4f 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -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;
}
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index edf26951f7..623951eb22 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -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;
}