summaryrefslogtreecommitdiff
blob: c2cacc3bff7a1b93cd890ea84330d296de1a0925 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
commit 614efea3e67a435f3330820c3dc8b402535641e8
Author: wm4 <wm4@nowhere>
Date:   Fri Jul 1 15:51:34 2016 +0200

ad_lavc: work around braindead ffmpeg behavior

The libavcodec wmapro decoder will skip some bytes at the start of the
first packet and return each time. It will not return any audio data in
this state.

Our own code as well as libavcodec's new API handling
(avcodec_send_packet() etc.) discard the PTS on the first return, which
means the PTS is never known for the first packet. This results in a
"Failed audio resync." message.

Fixy it by remember the PTS in next_pts. This field is used only if the
decoder outputs no PTS, and is updated after each frame - and thus
should be safe to set.

(Possibly this should be fixed in libavcodec new API handling by not
setting the PTS to NOPTS as long as no real data has been output. It
could even interpolate the PTS if the timebase is known.)

Fixes the failure message seen in #3297.

diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index f48993f..0316f6b 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -186,6 +186,12 @@ static int decode_packet(struct dec_audio *da, struct demux_packet *mpkt,
     struct priv *priv = da->priv;
     AVCodecContext *avctx = priv->avctx;

+    // If the decoder discards the timestamp for some reason, we use the
+    // interpolated PTS. Initialize it so that it works for the initial
+    // packet as well.
+    if (mpkt && priv->next_pts == MP_NOPTS_VALUE)
+        priv->next_pts = mpkt->pts;
+
     int in_len = mpkt ? mpkt->len : 0;

     AVPacket pkt;