Commit 2c28a8c9aa for ffmpeg

commit 2c28a8c9aae2e2fbcea959c7102922808a835b01
Author: Yalda <marth64@proxyid.net>
Date:   Sat Mar 7 19:35:37 2026 -0600

    avformat/dvdvideodec: do not drop out-of-order AC3 packets

    Resolves audio drop outs in very early generation DVD-R/ROM discs.
    This filtering was originally added to smooth out seeking and
    chapter cutpoints, but after robust testing (>1000 discs), it was
    discovered that certain encoders from 1997-era did produce valid
    AC3 streams this way. Beside the point, it is an archival accuracy
    concern.

    Signed-off-by: Yalda <marth64@proxyid.net>

diff --git a/libavformat/dvdvideodec.c b/libavformat/dvdvideodec.c
index a796010e0f..199afc1633 100644
--- a/libavformat/dvdvideodec.c
+++ b/libavformat/dvdvideodec.c
@@ -168,7 +168,6 @@ typedef struct DVDVideoDemuxContext {
     int                         nb_angles;          /* number of angles in the current title */
     int                         play_started;       /* signal that playback has started */
     DVDVideoPlaybackState       play_state;         /* the active playback state */
-    int64_t                     *prev_pts;          /* track the previous PTS emitted per stream */
     int64_t                     pts_offset;         /* PTS discontinuity offset (ex. VOB change) */
     int                         seek_warned;        /* signal that we warned about seeking limits */
     int                         subdemux_reset;     /* signal that subdemuxer should be reset */
@@ -1589,7 +1588,7 @@ static int dvdvideo_read_header(AVFormatContext *s)
             (ret = dvdvideo_subdemux_open(s)) < 0)
         return ret;

-        goto end_ready;
+        return 0;
     }

     if (c->opt_pgc && (c->opt_chapter_start > 1 || c->opt_chapter_end > 0 || c->opt_preindex)) {
@@ -1626,14 +1625,6 @@ static int dvdvideo_read_header(AVFormatContext *s)
         (ret = dvdvideo_subdemux_open(s)) < 0)
         return ret;

-end_ready:
-    c->prev_pts = av_malloc(s->nb_streams * sizeof(int64_t));
-    if (!c->prev_pts)
-        return AVERROR(ENOMEM);
-
-    for (int i = 0; i < s->nb_streams; i++)
-        c->prev_pts[i] = AV_NOPTS_VALUE;
-
     return 0;
 }

@@ -1694,13 +1685,10 @@ static int dvdvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (pkt->pts < 0)
         goto discard;

-    /* clean up after DVD muxers which end seamless PGs on duplicate or partial AC3 samples */
+    /* clean up after DVD muxers which end seamless PGs on partial AC3 samples */
     if (st_subdemux->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
         st_subdemux->codecpar->codec_id == AV_CODEC_ID_AC3) {

-        if (pkt->pts <= c->prev_pts[pkt->stream_index])
-            goto discard;
-
         ret = av_ac3_parse_header(pkt->buf->data, pkt->size,
                                   &ac3_bitstream_id, &ac3_frame_size);

@@ -1713,8 +1701,6 @@ static int dvdvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
                             pkt->stream_index, pkt->pts, pkt->dts,
                             c->pts_offset, c->first_pts);

-    c->prev_pts[pkt->stream_index] = pkt->pts;
-
     return 0;

 discard:
@@ -1722,9 +1708,6 @@ discard:
            "Discarding frame @ st=%d pts=%" PRId64 " dts=%" PRId64 " is_key=%d st_mapped=%d\n",
            st_mapped ? pkt->stream_index : -1, pkt->pts, pkt->dts, is_key, st_mapped);

-    if (st_mapped)
-        c->prev_pts[pkt->stream_index] = pkt->pts;
-
     return FFERROR_REDO;
 }

@@ -1741,9 +1724,6 @@ static int dvdvideo_close(AVFormatContext *s)

     dvdvideo_ifo_close(s);

-    if (c->prev_pts)
-        av_freep(&c->prev_pts);
-
     return 0;
 }