PR #26384 opened by yuygfgg
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26384
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26384.patch

# Summary of changes

This series adds support for demuxing Dynamic Resolution Adaptation (DRA) audio 
from raw files and broadcast MPEG-TS, as well as muxing it into MPEG-TS for 
stream copy.

## Demuxing and muxing

- **Raw and MPEG-TS demuxers:** The raw demuxer probes for consecutive DRA 
frame headers, while the MPEG-TS demuxer identifies DRA streams via the `DRA1` 
registration descriptor in the PMT. Both share a common parser to frame the 
bitstream and extract sample rate, channel configuration, and frame duration.
- **MPEG-TS muxer:** Packs complete frames into PES packets and writes the 
`DRA1` registration descriptor followed by the DRA audio stream descriptor in 
the PMT, in the order specified by GB/T 22726-2008.

## Parser and DRA+ auxiliary data

Under GB/T 22726-2008, the frame length field covers only the audio core. DRA+ 
appends enhancement data in a trailing auxiliary section starting with an 8-bit 
length field (with an optional 16-bit extension), followed by auxiliary blocks 
that each begin with a 12-bit length and a 4-bit type (see 
[CN110875046A](https://patents.google.com/patent/CN110875046A/en), figures 3 
and 4).

The parser reads the 8-bit auxiliary length field, but does not currently 
interpret the optional 16-bit extension:
- If the 12-bit block lengths sum to the 8-bit length, or if the boundary at 
that offset is confirmed by the next frame header or end of stream, the parser 
skips the entire auxiliary payload, including any embedded sync words.
- Otherwise, it falls back to scanning for the next frame header, which can be 
ambiguous if the payload contains bytes that resemble a valid header.

## Tests

- **Parser API & raw demuxer:** The parser API test covers fragmented input, 
timestamps, auxiliary data, and recovery from damaged streams. The raw demuxer 
test verifies format probing, frame timing, and payload hashes.
- **MPEG-TS (Shanghai DTMB sample):** The sample begins mid-frame and contains 
a frame spanning two PES packets. The tests verify that all 12 complete frames 
are recovered as 48 kHz stereo, and that frame timing and payloads are 
preserved across remuxing.
- **DRA+ (`fate-dra-plus-demux`):** Uses three consecutive frames from a DRA+ 
digital radio recording, each with an 8-bit auxiliary length and an embedded 
sync word (`0x7fff`) in the auxiliary payload, checking each frame's size and 
SHA-256 hash.

For additional verification, remuxing the full 1,590-frame recording (all using 
the 8-bit auxiliary length, with 61 containing embedded sync words) to MPEG-TS 
and extracting the audio again reproduces all 254,400 input bytes unchanged.

```fate-samples
dra/cdr-02bf.dra
dra/shanghai-522-dra.ts
```


>From a5ae80430daf4c84bdd18410e6ec31d021e4390f Mon Sep 17 00:00:00 2001
From: yuygfgg <[email protected]>
Date: Fri, 27 Nov 2026 00:11:57 +0800
Subject: [PATCH 1/5] avcodec: add a DRA audio parser

Read regular and extended GB/T 22726-2008 headers for the core size,
sample rate, channels and duration. Keep auxiliary data after the core
even when the speaker configuration flag is clear.

Skip short CDR payloads by byte count when their block lengths confirm
the boundary. For other auxiliary formats, look for the next frame.
Keep the timestamp of the packet containing the sync word when a
frame spans multiple input packets.

Signed-off-by: yuygfgg <[email protected]>
---
 doc/APIchanges                  |   3 +
 libavcodec/Makefile             |   1 +
 libavcodec/codec_desc.c         |   7 +
 libavcodec/codec_id.h           |   1 +
 libavcodec/dra.h                | 123 ++++++++++++
 libavcodec/dra_parser.c         | 326 ++++++++++++++++++++++++++++++++
 libavcodec/parsers.c            |   1 +
 libavcodec/version.h            |   2 +-
 tests/api/Makefile              |   1 +
 tests/api/api-dra-parser-test.c | 169 +++++++++++++++++
 tests/fate/api.mak              |   5 +
 11 files changed, 638 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/dra.h
 create mode 100644 libavcodec/dra_parser.c
 create mode 100644 tests/api/api-dra-parser-test.c

diff --git a/doc/APIchanges b/doc/APIchanges
index 33d895237c9..abfd26a04fd 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2026-06-23.
 
 API changes, most recent first:
 
+2026-11-xx - xxxxxxxxxx - lavc 63.29.100 - codec_id.h
+  Add AV_CODEC_ID_DRA.
+
 2026-11-xx - xxxxxxxxxx - lavu 61.21.100 - cpu.h
   Add AV_CPU_FLAG_AVXVNNI.
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c3da8412c60..e4715e56c78 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1277,6 +1277,7 @@ OBJS-$(CONFIG_DNXHD_PARSER)            += dnxhd_parser.o 
dnxhddata.o
 OBJS-$(CONFIG_DNXUC_PARSER)            += dnxuc_parser.o
 OBJS-$(CONFIG_DOLBY_E_PARSER)          += dolby_e_parser.o dolby_e_parse.o
 OBJS-$(CONFIG_DPX_PARSER)              += dpx_parser.o
+OBJS-$(CONFIG_DRA_PARSER)              += dra_parser.o
 OBJS-$(CONFIG_DVAUDIO_PARSER)          += dvaudio_parser.o
 OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsub_parser.o
 OBJS-$(CONFIG_DVD_NAV_PARSER)          += dvd_nav_parser.o
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index dd63c2194df..a2c82601a7b 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3611,6 +3611,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("Apple Positional Audio Codec"),
         .props     = AV_CODEC_PROP_LOSSY,
     },
+    {
+        .id        = AV_CODEC_ID_DRA,
+        .type      = AVMEDIA_TYPE_AUDIO,
+        .name      = "dra",
+        .long_name = NULL_IF_CONFIG_SMALL("Dynamic Resolution Adaptation"),
+        .props     = AV_CODEC_PROP_LOSSY,
+    },
 
     /* subtitle codecs */
     {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 8c78bbce379..d81e6bd88a2 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -566,6 +566,7 @@ enum AVCodecID {
     AV_CODEC_ID_G728,
     AV_CODEC_ID_AHX,
     AV_CODEC_ID_APPLE_APAC,
+    AV_CODEC_ID_DRA,
 
     /* subtitle codecs */
     AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,          ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/dra.h b/libavcodec/dra.h
new file mode 100644
index 00000000000..3c2c1e363df
--- /dev/null
+++ b/libavcodec/dra.h
@@ -0,0 +1,123 @@
+/*
+ * DRA audio parameters (GB/T 22726-2008)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_DRA_H
+#define AVCODEC_DRA_H
+
+#include <stdint.h>
+
+#include "libavutil/channel_layout.h"
+#include "libavutil/intreadwrite.h"
+
+/* GB/T 22726-2008, Table 10. The last three indices are reserved. */
+static const int ff_dra_sample_rates[16] = {
+     8000,  11025,  12000,  16000,  22050, 24000, 32000, 44100,
+    48000,  88200,  96000, 176400, 192000,
+};
+
+#define DRA_HEADER_SIZE 6
+
+typedef struct DRAHeader {
+    int core_size;
+    int samples;
+    int rate_index;
+    int normal_channels;
+    int lfe_channels;
+    int extended;
+    int aux_ch_layout;
+} DRAHeader;
+
+/* GB/T 22726-2008, 5.4. Read exactly six bytes, including the sync word. */
+static inline int ff_dra_read_header(const uint8_t *buf, int size, DRAHeader 
*h)
+{
+    uint32_t bits;
+
+    if (size < DRA_HEADER_SIZE || AV_RB16(buf) != 0x7fff)
+        return 0;
+    bits = AV_RB32(buf + 2);
+    h->extended = bits >> 31;
+    bits <<= 1;
+    if (h->extended) {
+        h->core_size = (bits >> 19) * 4;
+        bits <<= 13;
+    } else {
+        h->core_size = (bits >> 22) * 4;
+        bits <<= 10;
+    }
+    h->samples = 128 << (bits >> 30);
+    h->rate_index = (bits >> 26) & 15;
+    bits <<= 6;
+    if (h->extended) {
+        h->normal_channels = 1 + (bits >> 26);
+        h->lfe_channels = (bits >> 24) & 3;
+        bits <<= 8;
+    } else {
+        h->normal_channels = 1 + (bits >> 29);
+        h->lfe_channels = (bits >> 28) & 1;
+        bits <<= 4;
+    }
+    /* This flag signals speaker configuration data in the auxiliary payload. 
*/
+    h->aux_ch_layout = bits >> 31;
+    return h->core_size >= DRA_HEADER_SIZE && 
ff_dra_sample_rates[h->rate_index];
+}
+
+static inline int ff_dra_cdr_end(const uint8_t *buf, int size, const DRAHeader 
*h)
+{
+    return h->aux_ch_layout && size > h->core_size ? h->core_size + 1 + 
buf[h->core_size] : 0;
+}
+
+/* A core can be followed by application-defined auxiliary data (6.11).
+ * CDR recordings can carry a one-byte auxiliary length. Accept that
+ * interpretation only when a frame boundary confirms the length. */
+static inline int ff_dra_frame_size(const uint8_t *buf, int size, const 
DRAHeader *h,
+                                    int end_of_stream)
+{
+    DRAHeader next;
+    int end = h->core_size;
+    int cdr_end = ff_dra_cdr_end(buf, size, h);
+
+    if (end >= size)
+        return end_of_stream && end == size ? end : 0;
+    if (cdr_end) {
+        if ((end_of_stream && cdr_end == size) ||
+            (cdr_end < size && ff_dra_read_header(buf + cdr_end, size - 
cdr_end, &next)))
+            return cdr_end;
+        /* The length byte can itself be the first byte of a sync word. */
+        if (!end_of_stream && cdr_end + DRA_HEADER_SIZE > size)
+            return 0;
+    }
+    return ff_dra_read_header(buf + end, size - end, &next) ? end : 0;
+}
+
+static inline int ff_dra_count_lfe(const AVChannelLayout *layout)
+{
+    int lfe = 0;
+
+    if (layout->order == AV_CHANNEL_ORDER_UNSPEC)
+        return 0;
+
+    for (int i = 0; i < layout->nb_channels; i++) {
+        enum AVChannel ch = av_channel_layout_channel_from_index(layout, i);
+        lfe += ch == AV_CHAN_LOW_FREQUENCY || ch == AV_CHAN_LOW_FREQUENCY_2;
+    }
+    return lfe;
+}
+
+#endif /* AVCODEC_DRA_H */
diff --git a/libavcodec/dra_parser.c b/libavcodec/dra_parser.c
new file mode 100644
index 00000000000..ea0bf13fd79
--- /dev/null
+++ b/libavcodec/dra_parser.c
@@ -0,0 +1,326 @@
+/*
+ * DRA audio parser
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <string.h>
+
+#include "libavutil/fifo.h"
+#include "libavutil/mem.h"
+#include "dra.h"
+#include "parser_internal.h"
+
+/* Bound the search for the end of an application-defined auxiliary payload. */
+#define DRA_SYNC_WINDOW (1 << 20)
+#define DRA_MAX_CORE_SIZE (8191 * 4)
+
+typedef struct DRATimestamp {
+    int64_t begin, end;
+    int64_t pts, dts, pos;
+} DRATimestamp;
+
+typedef struct DRAParseContext {
+    uint8_t *buffer;
+    unsigned int capacity;
+    int size;
+    int begin;
+    int target;
+    int synced;
+    AVFifo *timestamps;
+} DRAParseContext;
+
+/* Short CDR payloads contain blocks with a 12-bit byte count (including
+ * the two-byte block header) and a four-bit type. Skip each block by size. */
+static int cdr_blocks_match(const uint8_t *buf, int available, int 
payload_size)
+{
+    while (available >= 2 && payload_size >= 2) {
+        int block_size = AV_RB16(buf) >> 4;
+        if (block_size == payload_size)
+            return 1;
+        if (block_size < 2 || block_size > payload_size || block_size > 
available)
+            break;
+        buf          += block_size;
+        available    -= block_size;
+        payload_size -= block_size;
+    }
+    return 0;
+}
+
+static int find_frame(const uint8_t *buf, int size, int synced, int flush,
+                      int *start, DRAHeader *header, int *needed)
+{
+    DRAHeader next;
+    int len, core_end, cdr_end, i;
+    int truncated = 0;
+
+    for (i = 0; i <= size - DRA_HEADER_SIZE; i++)
+        if (ff_dra_read_header(buf + i, size - i, header))
+            break;
+    *start = i;
+    buf  += i;
+    size -= i;
+    *needed = FFMIN(DRA_SYNC_WINDOW, FFMAX(64, size * 2));
+    if (size < DRA_HEADER_SIZE)
+        return 0;
+
+    core_end = header->core_size;
+    synced = synced && !*start;
+    cdr_end = ff_dra_cdr_end(buf, size, header);
+    if (cdr_end && cdr_blocks_match(buf + core_end + 1, size - core_end - 1, 
buf[core_end])) {
+        if (cdr_end <= size)
+            return cdr_end;
+        *needed = cdr_end;
+        return 0;
+    }
+    len = ff_dra_frame_size(buf, size, header, flush);
+    if (len)
+        return len;
+
+    if (!flush) {
+        /* Wait for the length byte, then skip the entire auxiliary payload. */
+        int target = core_end;
+        if (cdr_end) {
+            target = cdr_end;
+            if (target <= size)
+                target += DRA_HEADER_SIZE;
+        } else
+            target += header->aux_ch_layout ? 1 : DRA_HEADER_SIZE;
+        if (target > size) {
+            *needed = target;
+            return 0;
+        }
+    }
+
+    /* The word count excludes application-defined auxiliary data, even
+     * when the channel configuration flag is clear (6.3.2 and 6.3.7). */
+    for (i = synced && core_end <= size ? core_end : 1;
+         i <= size - DRA_HEADER_SIZE; i++) {
+        if (!ff_dra_read_header(buf + i, size - i, &next))
+            continue;
+        if (i >= core_end) {
+            if (next.core_size <= size - i)
+                return i;
+            if (!truncated)
+                truncated = i;
+            continue;
+        }
+        /* Recover from a false sync at the start of the stream. */
+        len = ff_dra_frame_size(buf + i, size - i, &next, flush);
+        if (!len)
+            continue;
+        *start += i;
+        *header = next;
+        return len;
+    }
+    if (!flush || core_end > size)
+        return 0;
+    if (truncated)
+        return truncated;
+    /* Check whether the remaining bytes could begin a truncated frame.
+     * Supply valid length and rate bits for the missing part of the header. */
+    for (i = FFMAX(i, core_end); i < size; i++) {
+        uint8_t tail[DRA_HEADER_SIZE] = { 0x7f, 0xff, 0x01, 0xe0 };
+        memcpy(tail, buf + i, size - i);
+        if (ff_dra_read_header(tail, sizeof(tail), &next))
+            return i;
+    }
+    return size;
+}
+
+static int dra_set_frame_info(AVCodecParserContext *s, AVCodecContext *avctx,
+                              const DRAHeader *header)
+{
+    /* Default speaker sets from Table 29. */
+    static const uint64_t layouts[] = {
+        AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_2_1,
+        AV_CH_LAYOUT_QUAD, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_HEXAGONAL,
+        AV_CH_LAYOUT_7POINT0, AV_CH_LAYOUT_OCTAGONAL,
+    };
+    AVChannelLayout *layout = &avctx->ch_layout;
+    int normal = header->normal_channels, lfe = header->lfe_channels;
+
+    if (!header->extended && !header->aux_ch_layout) {
+        av_channel_layout_uninit(layout);
+        av_channel_layout_from_mask(layout, layouts[normal - 1] | (lfe ? 
AV_CH_LOW_FREQUENCY : 0));
+    } else if (!lfe) {
+        av_channel_layout_uninit(layout);
+        layout->nb_channels = normal;
+    } else if (layout->order != AV_CHANNEL_ORDER_CUSTOM || layout->nb_channels 
!= normal + lfe ||
+               ff_dra_count_lfe(layout) != lfe) {
+        int ret;
+        av_channel_layout_uninit(layout);
+        ret = av_channel_layout_custom_init(layout, normal + lfe);
+        if (ret < 0)
+            return ret;
+        /* Speaker positions are application-defined. Keep the LFE count. */
+        for (int i = 0; i < lfe; i++)
+            layout->u.map[normal + i].id = i ? AV_CHAN_LOW_FREQUENCY_2 : 
AV_CHAN_LOW_FREQUENCY;
+    }
+
+    avctx->sample_rate = ff_dra_sample_rates[header->rate_index];
+    avctx->frame_size = s->duration = header->samples;
+    return 0;
+}
+
+/* Keep metadata for packets in which a sync word could start. A header
+ * can take more input packets than the generic parser timestamp history. */
+static int remember_timestamp(DRAParseContext *d, const AVCodecParserContext 
*s,
+                              const uint8_t *buf, int size)
+{
+    int i = s->cur_frame_start_index;
+    DRATimestamp stamp = { s->cur_frame_offset[i], s->cur_frame_end[i],
+                           s->cur_frame_pts[i], s->cur_frame_dts[i], 
s->cur_frame_pos[i] };
+
+    if (stamp.begin != s->cur_offset ||
+        (stamp.pts == AV_NOPTS_VALUE && stamp.dts == AV_NOPTS_VALUE && 
stamp.pos < 0) ||
+        !memchr(buf, 0x7f, size))
+        return 0;
+    return av_fifo_write(d->timestamps, &stamp, 1);
+}
+
+static void take_timestamp(DRAParseContext *d, AVCodecParserContext *s, 
int64_t offset)
+{
+    DRATimestamp stamp;
+
+    s->pts = s->dts = AV_NOPTS_VALUE;
+    s->pos = -1;
+    s->offset = 0;
+    while (av_fifo_peek(d->timestamps, &stamp, 1, 0) >= 0 && stamp.begin <= 
offset) {
+        av_fifo_drain2(d->timestamps, 1);
+        if (offset < stamp.end) {
+            s->pts = stamp.pts;
+            s->dts = stamp.dts;
+            s->pos = stamp.pos;
+            s->offset = offset - stamp.begin;
+        }
+    }
+}
+
+static int dra_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+                     const uint8_t **out, int *out_size,
+                     const uint8_t *buf, int size)
+{
+    DRAParseContext *d = s->priv_data;
+    DRAHeader h;
+    int used = 0;
+    const int flush = !size;
+
+    *out_size = 0;
+    if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+        if (ff_dra_read_header(buf, size, &h) && h.core_size <= size &&
+            dra_set_frame_info(s, avctx, &h) >= 0) {
+            *out = buf;
+            *out_size = size;
+        } else {
+            s->fetch_timestamp = 1;
+            s->next_frame_offset = s->cur_offset + size;
+        }
+        return size;
+    }
+
+    for (;;) {
+        int start, len;
+        uint8_t *buffer;
+
+        if (d->size && (flush || d->size >= d->target)) {
+            int64_t offset = s->cur_offset + used - d->size;
+            len = find_frame(d->buffer + d->begin, d->size, d->synced, flush,
+                             &start, &h, &d->target);
+            if (len && dra_set_frame_info(s, avctx, &h) >= 0) {
+                *out = d->buffer + d->begin + start;
+                *out_size = len;
+                s->next_frame_offset = offset + start;
+                take_timestamp(d, s, s->next_frame_offset);
+                d->begin += start + len;
+                d->size -= start + len;
+                d->synced = 1;
+                d->target = DRA_HEADER_SIZE;
+                return used;
+            }
+            if (len || flush) {
+                d->size = 0;
+                d->synced = 0;
+                av_fifo_reset2(d->timestamps);
+            } else if (start || d->size == DRA_SYNC_WINDOW) {
+                DRATimestamp stamp;
+                if (!start) {
+                    /* Keep every core that might still lack its successor. */
+                    start = d->size - (DRA_MAX_CORE_SIZE + 256 + 
DRA_HEADER_SIZE);
+                    av_log(avctx, AV_LOG_WARNING, "DRA sync lost, discarding 
%d bytes\n", start);
+                }
+                d->begin += start;
+                d->size -= start;
+                d->synced = 0;
+                while (av_fifo_peek(d->timestamps, &stamp, 1, 0) >= 0 && 
stamp.end <= offset + start)
+                    av_fifo_drain2(d->timestamps, 1);
+            }
+        }
+        if (used == size)
+            return used;
+        if (!d->size) {
+            d->begin = 0;
+            d->target = DRA_HEADER_SIZE;
+        }
+        len = FFMIN(size - used, d->target - d->size);
+        if (d->begin && d->begin + d->size + len + 
AV_INPUT_BUFFER_PADDING_SIZE > d->capacity) {
+            memmove(d->buffer, d->buffer + d->begin, d->size);
+            d->begin = 0;
+        }
+        buffer = av_fast_realloc(d->buffer, &d->capacity,
+                                 d->begin + d->size + len + 
AV_INPUT_BUFFER_PADDING_SIZE);
+        if (!buffer)
+            break;
+        d->buffer = buffer;
+        if (!used && remember_timestamp(d, s, buf, size) < 0)
+            break;
+        memcpy(buffer + d->begin + d->size, buf + used, len);
+        d->size += len;
+        memset(buffer + d->begin + d->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+        used += len;
+    }
+    av_log(avctx, AV_LOG_ERROR, "Cannot buffer DRA input\n");
+    d->size = 0;
+    d->synced = 0;
+    av_fifo_reset2(d->timestamps);
+    return size;
+}
+
+static av_cold int dra_init(AVCodecParserContext *s)
+{
+    DRAParseContext *d = s->priv_data;
+    d->timestamps = av_fifo_alloc2(4, sizeof(DRATimestamp), 
AV_FIFO_FLAG_AUTO_GROW);
+    if (!d->timestamps)
+        return AVERROR(ENOMEM);
+    av_fifo_auto_grow_limit(d->timestamps, DRA_SYNC_WINDOW);
+    return 0;
+}
+
+static av_cold void dra_close(AVCodecParserContext *s)
+{
+    DRAParseContext *d = s->priv_data;
+    av_fifo_freep2(&d->timestamps);
+    av_freep(&d->buffer);
+}
+
+const FFCodecParser ff_dra_parser = {
+    PARSER_CODEC_LIST(AV_CODEC_ID_DRA),
+    .priv_data_size = sizeof(DRAParseContext),
+    .init           = dra_init,
+    .parse          = dra_parse,
+    .close          = dra_close,
+};
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index 263b606407e..a98ec9b6ef0 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -41,6 +41,7 @@ extern const FFCodecParser ff_dnxhd_parser;
 extern const FFCodecParser ff_dnxuc_parser;
 extern const FFCodecParser ff_dolby_e_parser;
 extern const FFCodecParser ff_dpx_parser;
+extern const FFCodecParser ff_dra_parser;
 extern const FFCodecParser ff_dvaudio_parser;
 extern const FFCodecParser ff_dvbsub_parser;
 extern const FFCodecParser ff_dvdsub_parser;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 87b7284a953..5183deb68bd 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  28
+#define LIBAVCODEC_VERSION_MINOR  29
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/tests/api/Makefile b/tests/api/Makefile
index 75df91492d9..1480b42f358 100644
--- a/tests/api/Makefile
+++ b/tests/api/Makefile
@@ -1,5 +1,6 @@
 APITESTPROGS-$(call ALLYES, AC3_ENCODER AC3_DECODER EAC3_DECODER 
AC3_FIXED_DECODER) += api-ac3-flush
 APITESTPROGS-$(CONFIG_AMR_PARSER) += api-amr-parser
+APITESTPROGS-$(CONFIG_DRA_PARSER) += api-dra-parser
 APITESTPROGS-$(call ALLYES, LIBASTCENC_ENCODER LIBASTCENC_DECODER) += 
api-astc-profile
 APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac
 APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264
diff --git a/tests/api/api-dra-parser-test.c b/tests/api/api-dra-parser-test.c
new file mode 100644
index 00000000000..4891c4a0b2e
--- /dev/null
+++ b/tests/api/api-dra-parser-test.c
@@ -0,0 +1,169 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "libavcodec/avcodec.h"
+#include "libavutil/common.h"
+
+/* GB/T 22726-2008 regular headers with a 32-byte core and 1024 samples. */
+static const uint8_t mono[]   = { 0x7f, 0xff, 0x01, 0x1a, 0x84, 0 };
+static const uint8_t stereo[] = { 0x7f, 0xff, 0x01, 0x1c, 0x10, 0 };
+static const uint8_t false_sync[] = { 0x7f, 0xff, 0x7f, 0xfc, 0x10, 0 };
+
+typedef struct Frame {
+    int offset;
+    int size;
+    int mono;
+} Frame;
+
+static int test_parser(const uint8_t *input, int size, int chunk, int 
known_pos, int flags,
+                       const Frame *frames, int nb_frames)
+{
+    const int64_t first_pts = 123456, first_dts = 123400;
+    AVCodecParserContext *parser = av_parser_init(AV_CODEC_ID_DRA);
+    AVCodecContext *ctx = avcodec_alloc_context3(NULL);
+    int pos = 0, frame = 0;
+    int ret = 1;
+
+    if (!parser || !ctx)
+        goto end;
+    parser->flags |= flags;
+    ctx->codec_type = AVMEDIA_TYPE_AUDIO;
+    ctx->codec_id = AV_CODEC_ID_DRA;
+    for (;;) {
+        uint8_t *out;
+        int out_size, len = FFMIN(chunk, size - pos);
+        int has_ts = pos <= frames[0].offset && frames[0].offset < pos + len;
+        int used = av_parser_parse2(parser, ctx, &out, &out_size,
+                                    input + pos, len, has_ts ? first_pts : 
AV_NOPTS_VALUE,
+                                    has_ts ? first_dts : AV_NOPTS_VALUE, 
known_pos ? pos : -1);
+        pos += used;
+        if (out_size) {
+            if (frame >= nb_frames || out_size != frames[frame].size ||
+                memcmp(out, input + frames[frame].offset, out_size) ||
+                parser->frame_offset != frames[frame].offset - !known_pos ||
+                parser->duration != 1024 ||
+                ctx->sample_rate != (frames[frame].mono ? 24000 : 48000) ||
+                ctx->ch_layout.nb_channels != (frames[frame].mono ? 1 : 2) ||
+                parser->pts != (frame ? AV_NOPTS_VALUE : first_pts) ||
+                parser->dts != (frame ? AV_NOPTS_VALUE : first_dts))
+                goto end;
+            frame++;
+        } else if (!used) {
+            break;
+        }
+    }
+    ret = frame != nb_frames;
+end:
+    if (ret)
+        fprintf(stderr, "DRA parser failed at frame %d, chunk %d, input size 
%d\n",
+                frame, chunk, size);
+    av_parser_close(parser);
+    avcodec_free_context(&ctx);
+    return ret;
+}
+
+static int test_cdr(int chunk, int prefix, int known_pos)
+{
+    const Frame frames[] = {
+        { prefix, 160, 1 }, { prefix + 160, 32 },
+        { prefix + 192, 32 }, { prefix + 224, 32 },
+    };
+    uint8_t input[6 + 256 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+
+    if (prefix)
+        memcpy(input, false_sync, sizeof(false_sync));
+    memcpy(input + prefix, mono, sizeof(mono));
+    /* The 127-byte extension length is also the first byte of a false
+     * sync word. Two header-like patterns form a chain inside the extension. 
*/
+    memcpy(input + prefix + 32, stereo, sizeof(stereo));
+    memcpy(input + prefix + 64, stereo, sizeof(stereo));
+    for (int i = 1; i < FF_ARRAY_ELEMS(frames); i++)
+        memcpy(input + frames[i].offset, stereo, sizeof(stereo));
+    return test_parser(input, prefix + 256, chunk, known_pos, 0, frames, 
FF_ARRAY_ELEMS(frames));
+}
+
+static int test_cdr_blocks(void)
+{
+    static const Frame frames[] = { { 0, 160, 1 }, { 164, 32 }, { 196, 32 } };
+    uint8_t input[228 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+
+    memcpy(input, mono, sizeof(mono));
+    input[32] = 127;
+    /* Two CDR blocks cover the payload. The second contains two complete
+     * header-like patterns. Four damaged bytes follow the extension. */
+    memcpy(input + 33, "\x00\x31\x00\x07\xc1", 5);
+    memcpy(input + 48, stereo, sizeof(stereo));
+    memcpy(input + 80, stereo, sizeof(stereo));
+    memcpy(input + 164, stereo, sizeof(stereo));
+    memcpy(input + 196, stereo, sizeof(stereo));
+    return test_parser(input, 228, 1, 1, 0, frames, 3) ||
+           test_parser(input, 164, 164, 1, 0, frames, 1) ||
+           test_parser(input, 120, 11, 1, 0, frames, 0);
+}
+
+static int test_opaque_aux(void)
+{
+    static const Frame frames[] = { { 0, 40 }, { 40, 36, 1 }, { 76, 32 }, { 
108, 40 } };
+    uint8_t input[164 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(frames); i++) {
+        uint8_t *p = input + frames[i].offset;
+        memcpy(p, frames[i].mono ? mono : stereo, sizeof(stereo));
+        memcpy(p + 32, "TIMECODE", frames[i].size - 32);
+    }
+    /* The channel configuration flag is clear on the first and last frames.
+     * Both have auxiliary data. A following partial core is not part of it. */
+    memcpy(input + 144, "\x7f\xff\x00\x00", 4); /* Invalid zero word count. */
+    memcpy(input + 148, stereo, sizeof(stereo));
+    return test_parser(input, 148, 1, 1, 0, frames, FF_ARRAY_ELEMS(frames)) ||
+           test_parser(input, 148, 148, 1, 0, frames, FF_ARRAY_ELEMS(frames)) 
||
+           test_parser(input, 150, 17, 1, 0, frames, FF_ARRAY_ELEMS(frames)) ||
+           test_parser(input, 164, 17, 1, 0, frames, FF_ARRAY_ELEMS(frames));
+}
+
+static int test_damaged_stream(void)
+{
+    static const Frame frames[] = { { 0, 32 }, { 32, 32 }, { 96, 32 }, { 128, 
32 } };
+    uint8_t input[162 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(frames); i++)
+        memcpy(input + frames[i].offset, stereo, sizeof(stereo));
+    memcpy(input + 64, false_sync, sizeof(false_sync));
+    memcpy(input + 160, stereo, 2);
+    return test_parser(input, 162, 11, 1, 0, frames, FF_ARRAY_ELEMS(frames));
+}
+
+int main(void)
+{
+    static const uint8_t input[64 + AV_INPUT_BUFFER_PADDING_SIZE] = { [32] = 
0x7f, 0xff, 0x01, 0x1c, 0x10 };
+    static const Frame frame = { 0, 32 };
+    static const Frame after_invalid = { 32, 32 };
+
+    /* Timestamp the packet containing the first real sync word, including
+     * when a false header precedes it or the sync spans two packets. */
+    return test_cdr(1, 0, 1) || test_cdr(2, 0, 0) ||
+           test_cdr(1, 6, 0) || test_cdr(1, 6, 1) ||
+           test_cdr(160, 6, 1) || test_cdr(262, 6, 1) ||
+           test_cdr_blocks() || test_opaque_aux() || test_damaged_stream() ||
+           test_parser(input + 32, 32, 32, 1, PARSER_FLAG_COMPLETE_FRAMES, 
&frame, 1) ||
+           test_parser(input, 64, 32, 1, PARSER_FLAG_COMPLETE_FRAMES, 
&after_invalid, 1) ||
+           test_parser(input, 64, 32, 0, PARSER_FLAG_COMPLETE_FRAMES, 
&after_invalid, 1);
+}
diff --git a/tests/fate/api.mak b/tests/fate/api.mak
index 69df95b90d0..8a70224ac58 100644
--- a/tests/fate/api.mak
+++ b/tests/fate/api.mak
@@ -11,6 +11,11 @@ FATE_API_LIBAVCODEC-$(CONFIG_AMR_PARSER) += 
fate-api-amr-parser
 fate-api-amr-parser: $(APITESTSDIR)/api-amr-parser-test$(EXESUF)
 fate-api-amr-parser: CMD = run $(APITESTSDIR)/api-amr-parser-test$(EXESUF)
 
+FATE_API_LIBAVCODEC-$(CONFIG_DRA_PARSER) += fate-api-dra-parser
+fate-api-dra-parser: $(APITESTSDIR)/api-dra-parser-test$(EXESUF)
+fate-api-dra-parser: CMD = run $(APITESTSDIR)/api-dra-parser-test$(EXESUF)
+fate-api-dra-parser: CMP = null
+
 FATE_API_LIBAVCODEC-$(call ALLYES, LIBASTCENC_ENCODER LIBASTCENC_DECODER) += 
fate-api-astc-profile
 fate-api-astc-profile: $(APITESTSDIR)/api-astc-profile-test$(EXESUF)
 fate-api-astc-profile: CMD = run $(APITESTSDIR)/api-astc-profile-test$(EXESUF)
-- 
2.54.1


>From 58899329db8eff7fdaeacfa2c2c29e96ef990a90 Mon Sep 17 00:00:00 2001
From: yuygfgg <[email protected]>
Date: Fri, 27 Nov 2026 00:11:57 +0800
Subject: [PATCH 2/5] avformat: add a raw DRA demuxer

Probe for consecutive frames and use the DRA parser to split the input.
Use a 28.224 MHz time base to represent frame durations exactly at every
sample rate in GB/T 22726-2008.

Check content probing, timestamps and auxiliary data with a generated
44.1 kHz stream in fate-dra-demux.

Signed-off-by: yuygfgg <[email protected]>
---
 configure                 |  1 +
 doc/general_contents.texi |  1 +
 libavformat/Makefile      |  1 +
 libavformat/allformats.c  |  1 +
 libavformat/dradec.c      | 72 +++++++++++++++++++++++++++++++++++++++
 libavformat/version.h     |  2 +-
 tests/fate/demux.mak      | 13 +++++++
 tests/ref/fate/dra-demux  |  5 +++
 8 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/dradec.c
 create mode 100644 tests/ref/fate/dra-demux

diff --git a/configure b/configure
index eed7a76aa92..6afa6ca46af 100755
--- a/configure
+++ b/configure
@@ -3923,6 +3923,7 @@ dash_muxer_select="mp4_muxer"
 dash_demuxer_deps="libxml2"
 daud_muxer_select="pcm_rechunk_bsf"
 dirac_demuxer_select="dirac_parser"
+dra_demuxer_select="dra_parser"
 dts_demuxer_select="dca_parser"
 dtshd_demuxer_select="dca_parser"
 dv_demuxer_select="dvprofile"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8f7e07becb3..73074d7c418 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -754,6 +754,7 @@ library:
 @item raw DFPWM                 @tab X @tab X
 @item raw Dirac                 @tab X @tab X
 @item raw DNxHD                 @tab X @tab X
+@item raw DRA (Dynamic Resolution Adaptation) @tab @tab X
 @item raw DTS                   @tab X @tab X
 @item raw DTS-HD                @tab   @tab X
 @item raw E-AC-3                @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 9b5731d9593..f4d246845f6 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -205,6 +205,7 @@ OBJS-$(CONFIG_DIRAC_DEMUXER)             += diracdec.o 
rawdec.o
 OBJS-$(CONFIG_DIRAC_MUXER)               += rawenc.o
 OBJS-$(CONFIG_DNXHD_DEMUXER)             += dnxhddec.o rawdec.o
 OBJS-$(CONFIG_DNXHD_MUXER)               += rawenc.o
+OBJS-$(CONFIG_DRA_DEMUXER)               += dradec.o rawdec.o
 OBJS-$(CONFIG_DSF_DEMUXER)               += dsfdec.o
 OBJS-$(CONFIG_DSICIN_DEMUXER)            += dsicin.o
 OBJS-$(CONFIG_DSS_DEMUXER)               += dss.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index db5656c7dbc..5c5aabdb4a2 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -145,6 +145,7 @@ extern const FFInputFormat  ff_dirac_demuxer;
 extern const FFOutputFormat ff_dirac_muxer;
 extern const FFInputFormat  ff_dnxhd_demuxer;
 extern const FFOutputFormat ff_dnxhd_muxer;
+extern const FFInputFormat  ff_dra_demuxer;
 extern const FFInputFormat  ff_dsf_demuxer;
 extern const FFInputFormat  ff_dsicin_demuxer;
 extern const FFInputFormat  ff_dss_demuxer;
diff --git a/libavformat/dradec.c b/libavformat/dradec.c
new file mode 100644
index 00000000000..f46f1a5791d
--- /dev/null
+++ b/libavformat/dradec.c
@@ -0,0 +1,72 @@
+/*
+ * Raw DRA demuxer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/dra.h"
+
+#include "internal.h"
+#include "rawdec.h"
+
+static int dra_probe(const AVProbeData *p)
+{
+    DRAHeader h;
+    int score = 0;
+
+    for (int i = 0; i <= p->buf_size - DRA_HEADER_SIZE; i++) {
+        const uint8_t *buf = p->buf + i;
+        int size = p->buf_size - i;
+        for (int frames = 1; ff_dra_read_header(buf, size, &h) && h.core_size 
<= size; frames++) {
+            int len;
+            if (!i)
+                score = AVPROBE_SCORE_EXTENSION / 4;
+            if (frames == 3)
+                return AVPROBE_SCORE_EXTENSION + 1;
+            len = ff_dra_frame_size(buf, size, &h, 0);
+            if (!len)
+                break;
+            buf  += len;
+            size -= len;
+        }
+    }
+    return score;
+}
+
+static int dra_read_header(AVFormatContext *s)
+{
+    int ret = ff_raw_audio_read_header(s);
+    if (ret < 0)
+        return ret;
+
+    /* All GB/T 22726-2008 sample rates divide this clock rate. */
+    avpriv_set_pts_info(s->streams[0], 64, 1, 28224000);
+    return 0;
+}
+
+const FFInputFormat ff_dra_demuxer = {
+    .p.name         = "dra",
+    .p.long_name    = NULL_IF_CONFIG_SMALL("raw Dynamic Resolution 
Adaptation"),
+    .p.flags        = AVFMT_GENERIC_INDEX,
+    .p.extensions   = "dra",
+    .p.priv_class   = &ff_raw_demuxer_class,
+    .read_probe     = dra_probe,
+    .read_header    = dra_read_header,
+    .read_packet    = ff_raw_read_partial_packet,
+    .raw_codec_id   = AV_CODEC_ID_DRA,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index 683184d5da1..d8fc959f19b 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSION_MINOR  21
+#define LIBAVFORMAT_VERSION_MINOR  22
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index d8e9e8b48e2..a22d1a40158 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -277,6 +277,19 @@ fate-hls-webvtt-wrap-demux: tests/data/hls-webvtt-wrap.m3u8
 fate-hls-webvtt-wrap-demux: CLEANFILES = tests/data/hls-webvtt-wrap.m3u8 
tests/data/hls-webvtt-wrap-a.m3u8 tests/data/hls-webvtt-wrap-s.m3u8 
tests/data/hls-webvtt-wrap-a[0-9]*.ts tests/data/hls-webvtt-wrap-s[0-9]*.vtt
 fate-hls-webvtt-wrap-demux: CMD = framecrc -copyts -i 
$(TARGET_PATH)/tests/data/hls-webvtt-wrap.m3u8 -map 0:a -c copy -f null - -map 
0:s -c copy
 
+# Three 44.1 kHz DRA headers with core filler and length-prefixed auxiliary 
data.
+tests/data/fate/dra-44100: TAG = GEN
+tests/data/fate/dra-44100: $(SRC_PATH)/tests/fate/demux.mak | tests/data/fate
+       $(M)for frame in 1 2 3; do \
+           printf '\177\377\000\133\204\000\000\000\003DRA'; \
+       done > $@
+
+FATE_FFPROBE-$(call ALLYES, DRA_DEMUXER FILE_PROTOCOL) += fate-dra-demux
+fate-dra-demux: tests/data/fate/dra-44100
+fate-dra-demux: CMD = probe -of compact -show_data_hash sha256 \
+    -show_entries 
format=format_name:stream=codec_name,sample_rate,channels,time_base:packet=pts,dts,duration,size,pos,data_hash
 \
+    $(TARGET_PATH)/tests/data/fate/dra-44100
+
 tests/data/hls-self-variant.m3u8: TAG = GEN
 tests/data/hls-self-variant.m3u8: | tests/data
        $(Q)printf 
'#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=64000\nhls-self-variant.m3u8\n#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="s",NAME="en",URI="hls-self-variant-missing.m3u8"\n#EXTINF:2,\nhls-self-variant.vtt\n'
 > $@
diff --git a/tests/ref/fate/dra-demux b/tests/ref/fate/dra-demux
new file mode 100644
index 00000000000..9f8b4a39768
--- /dev/null
+++ b/tests/ref/fate/dra-demux
@@ -0,0 +1,5 @@
+packet|pts=0|dts=0|duration=655360|size=12|pos=0|data_hash=SHA256:33e9d8d8901ab67a611a9e5668c784fbd8855c69e0ca373d5e078d071faf3bf3
+packet|pts=655360|dts=655360|duration=655360|size=12|pos=12|data_hash=SHA256:33e9d8d8901ab67a611a9e5668c784fbd8855c69e0ca373d5e078d071faf3bf3
+packet|pts=1310720|dts=1310720|duration=655360|size=12|pos=24|data_hash=SHA256:33e9d8d8901ab67a611a9e5668c784fbd8855c69e0ca373d5e078d071faf3bf3
+stream|codec_name=dra|sample_rate=44100|channels=1|time_base=1/28224000
+format|format_name=dra
-- 
2.54.1


>From b9baaa5dce8b663c7c170694bd6ae3e4a4984705 Mon Sep 17 00:00:00 2001
From: yuygfgg <[email protected]>
Date: Fri, 27 Nov 2026 00:11:57 +0800
Subject: [PATCH 3/5] avformat/mpegts: recognize DRA audio

Map the DRA1 registration to AV_CODEC_ID_DRA. Let the existing
MPEG-TS audio parser path read the stream parameters and split
the PES payload into frames.

Test a Shanghai DTMB capture that starts inside a frame and whose
PMT advertises three channels for a stereo stream.

FATE sample: dra/shanghai-522-dra.ts

Signed-off-by: yuygfgg <[email protected]>
---
 libavformat/mpegts.c            |  1 +
 tests/fate/mpegts.mak           |  7 +++++++
 tests/ref/fate/mpegts-dra-demux | 13 +++++++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 tests/ref/fate/mpegts-dra-demux

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 8e6d175e9a6..995e23b21d9 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -930,6 +930,7 @@ static const StreamType REGD_types[] = {
     { MKTAG('A', 'C', '-', '3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3   },
     { MKTAG('A', 'C', '-', '4'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC4   },
     { MKTAG('B', 'S', 'S', 'D'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_S302M },
+    { MKTAG('D', 'R', 'A', '1'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DRA   },
     { MKTAG('D', 'T', 'S', '1'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS   },
     { MKTAG('D', 'T', 'S', '2'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS   },
     { MKTAG('D', 'T', 'S', '3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS   },
diff --git a/tests/fate/mpegts.mak b/tests/fate/mpegts.mak
index d9136c25c7c..9a777c63fc1 100644
--- a/tests/fate/mpegts.mak
+++ b/tests/fate/mpegts.mak
@@ -29,6 +29,13 @@ FATE_MPEGTS_PROBE-$(call DEMDEC, MPEGTS) += 
fate-mpegts-probe-pmt-merge
 fate-mpegts-probe-pmt-merge: SRC = $(TARGET_SAMPLES)/mpegts/pmtchange.ts
 fate-mpegts-probe-pmt-merge: CMD = run $(PROBE_CODEC_NAME_COMMAND) 
-merge_pmt_versions 1 -i "$(SRC)"
 
+# Shanghai DTMB 522, program 301. The first PES starts inside a frame.
+# A later frame spans two PES packets with the data alignment indicator clear.
+FATE_MPEGTS_PROBE-$(call PARSERDEM, DRA, MPEGTS) += fate-mpegts-dra-demux
+fate-mpegts-dra-demux: CMD = probe -v error -of compact -select_streams 
i:0x28a -show_data_hash sha256 \
+    -show_entries 
packet=pts,dts,duration,size,data_hash:stream=codec_name,codec_tag_string,sample_rate,channels,id,time_base
 \
+    $(TARGET_SAMPLES)/dra/shanghai-522-dra.ts
+
 FATE_MPEGTS_PROBE-$(call DEMDEC, MPEGTS, HEVC, LOAS_DEMUXER) += 
fate-mpegts-probe-program-compact
 fate-mpegts-probe-program-compact: SRC = $(TARGET_SAMPLES)/mpegts/loewe.ts
 fate-mpegts-probe-program-compact: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -v 0 
-bitexact -of compact \
diff --git a/tests/ref/fate/mpegts-dra-demux b/tests/ref/fate/mpegts-dra-demux
new file mode 100644
index 00000000000..ad7fff509ca
--- /dev/null
+++ b/tests/ref/fate/mpegts-dra-demux
@@ -0,0 +1,13 @@
+packet|pts=6047233432|dts=6047233432|duration=1920|size=340|data_hash=SHA256:17c6434d62132c51a9807af7473034080e63df69ffc0c8b262cf42054524a033
+packet|pts=6047235352|dts=6047235352|duration=1920|size=340|data_hash=SHA256:dd6ae3ebaf2da2c5772944d3b92b16372a471e31eeb61bbebf95522a8f184010
+packet|pts=6047237272|dts=6047237272|duration=1920|size=340|data_hash=SHA256:5db3c5c3e5a54c08e28f74098bf27a0b527e2be66cad59693309dd122db2245f
+packet|pts=6047239192|dts=6047239192|duration=1920|size=340|data_hash=SHA256:ceebd33ccc8f8586ea6a9e6600161de66ede0343143881d22ae318c766ef9958
+packet|pts=6047241112|dts=6047241112|duration=1920|size=340|data_hash=SHA256:e3e12ece0b011d348975b7f3b1ed73d8a1ecdd0b3f34597886ee34c5fd867880
+packet|pts=6047243032|dts=6047243032|duration=1920|size=340|data_hash=SHA256:5218fca1a3fe30db52a46a39a5673d4f27df24fb12c786bb9b595b0cddcd9daf
+packet|pts=6047244952|dts=6047244952|duration=1920|size=340|data_hash=SHA256:ba005c758852306d12c7598b775f32bc2ec68b4c0db2102598369b5362e6d6af
+packet|pts=6047246872|dts=6047246872|duration=1920|size=340|data_hash=SHA256:931cf0ad619a6aa4b28d4aa1a010e5fc2655c6b84efed1af84313b70f4d15799
+packet|pts=6047248792|dts=6047248792|duration=1920|size=340|data_hash=SHA256:16aa84a0fe911639dcc6543ebb22d4a3ad53a4f48d0b9665f3eef813a07d7c53
+packet|pts=6047250712|dts=6047250712|duration=1920|size=340|data_hash=SHA256:e57479ae5e781ab902b9a94a7361b29249a78c277a14ad837943b8cfae668f7d
+packet|pts=6047252632|dts=6047252632|duration=1920|size=340|data_hash=SHA256:c125b523a739b90c5b3bc2b9a1cf1143aaf09f7a90a76612465b41c79518f417
+packet|pts=6047254552|dts=6047254552|duration=1920|size=340|data_hash=SHA256:51c295cfe8e2a258575df0d5b739c9cc9d948f4d864611cc48daa1be0c1aaf08
+stream|codec_name=dra|codec_tag_string=DRA1|sample_rate=48000|channels=2|id=0x28a|time_base=1/90000
-- 
2.54.1


>From 5b738bb680ec4c32297ba4fc45e75cf4a8433179 Mon Sep 17 00:00:00 2001
From: yuygfgg <[email protected]>
Date: Fri, 27 Nov 2026 00:11:57 +0800
Subject: [PATCH 4/5] avformat/mpegtsenc: mux DRA audio

Write the DRA1 registration and audio stream descriptor required by
GB/T 22726-2008. Derive the descriptor from the sample rate and the
normal and LFE channel counts. Use the existing audio PES muxing path.

Test stream copy with a Shanghai DTMB sample. Check the output TS
checksum, the DRA1 registration and the recovered packet checksums
and timestamps.

Signed-off-by: yuygfgg <[email protected]>
---
 Changelog                       |  1 +
 libavformat/mpegts.h            |  3 +++
 libavformat/mpegtsenc.c         | 36 +++++++++++++++++++++++++++++++++
 tests/fate/mpegts.mak           |  4 ++++
 tests/ref/fate/mpegts-dra-remux | 20 ++++++++++++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 tests/ref/fate/mpegts-dra-remux

diff --git a/Changelog b/Changelog
index aaa3fe97ca8..0d78e57a419 100644
--- a/Changelog
+++ b/Changelog
@@ -11,6 +11,7 @@ version <next>:
 - DSS variable rate SP (format 1) support
 - Added the ability to derive an AMF hwdevice from a Vulkan hwdevice
 - MIGraphX execution provider support for the ONNX Runtime DNN backend
+- DRA parser, raw demuxer, and broadcast MPEG-TS carriage
 
 version 9.1:
 - ASTC image encoding and decoding via libastcenc, with .astc and KTX 1.0 
muxers and demuxers
diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 58ef24848b9..6e068f6819f 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -231,6 +231,9 @@ 
https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/
 #define SUPPLEMENTARY_AUDIO_DESCRIPTOR 0x06
 #define AC4_DESCRIPTOR 0x15
 
+/* GB/T 22726-2008, Annex C */
+#define DRA_AUDIO_DESCRIPTOR 0xa0
+
 /** see "Dolby Vision Streams Within the MPEG-2 Transport Stream Format"
 
https://professional.dolby.com/siteassets/content-creation/dolby-vision-for-content-creators/dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2.pdf
 */
 #define DOVI_VIDEO_STREAM_DESCRIPTOR 0xb0
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 582a9a3e605..c56bea17328 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -31,6 +31,7 @@
 #include "libavcodec/ac3_parser_internal.h"
 #include "libavcodec/bytestream.h"
 #include "libavcodec/defs.h"
+#include "libavcodec/dra.h"
 #include "libavcodec/h264.h"
 #include "libavcodec/hevc/hevc.h"
 #include "libavcodec/opus/tab.h"
@@ -435,6 +436,9 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
     case AV_CODEC_ID_TRUEHD:
         stream_type = STREAM_TYPE_BLURAY_AUDIO_TRUEHD; // should be 
STREAM_TYPE_PRIVATE_DATA (ETSI TS 101 154), needs a DTS-HD_descriptor() (ETSI 
EN 300 468)
         break;
+    case AV_CODEC_ID_DRA:
+        stream_type = STREAM_TYPE_PRIVATE_DATA;
+        break;
     case AV_CODEC_ID_OPUS:
         stream_type = STREAM_TYPE_PRIVATE_DATA;
         break;
@@ -524,6 +528,19 @@ static int get_m2ts_stream_type(AVFormatContext *s, 
AVStream *st)
     return stream_type;
 }
 
+static int get_dra_audio_config(const AVCodecParameters *par)
+{
+    int lfe = ff_dra_count_lfe(&par->ch_layout);
+    int normal = par->ch_layout.nb_channels - lfe;
+
+    if (par->sample_rate <= 0 || normal < 1 || normal > 64 || lfe > 3)
+        return AVERROR(EINVAL);
+    for (int i = 0; i < FF_ARRAY_ELEMS(ff_dra_sample_rates); i++)
+        if (ff_dra_sample_rates[i] == par->sample_rate)
+            return i << 12 | (normal - 1) << 6 | lfe << 4;
+    return AVERROR(EINVAL);
+}
+
 static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
 {
     MpegTSWrite *ts = s->priv_data;
@@ -587,6 +604,13 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
         /* write optional descriptors here */
         switch (st->codecpar->codec_type) {
         case AVMEDIA_TYPE_AUDIO:
+            if (codec_id == AV_CODEC_ID_DRA) {
+                /* GB/T 22726-2008 requires these descriptors first, in this 
order. */
+                put_registration_descriptor(&q, MKTAG('D', 'R', 'A', '1'));
+                *q++ = DRA_AUDIO_DESCRIPTOR;
+                *q++ = 2;
+                put16(&q, get_dra_audio_config(st->codecpar));
+            }
             if (codec_id == AV_CODEC_ID_AC3)
                 put_registration_descriptor(&q, MKTAG('A', 'C', '-', '3'));
             if (codec_id == AV_CODEC_ID_EAC3)
@@ -1247,6 +1271,18 @@ static int mpegts_init(AVFormatContext *s)
         }
         st->priv_data = ts_st;
 
+        if (st->codecpar->codec_id == AV_CODEC_ID_DRA) {
+            if (ts->m2ts_mode) {
+                av_log(s, AV_LOG_ERROR, "DRA is unsupported in Blu-ray 
mode\n");
+                return AVERROR(EINVAL);
+            }
+            if (get_dra_audio_config(st->codecpar) < 0) {
+                av_log(s, AV_LOG_ERROR, "Invalid DRA sample rate or channel 
configuration for stream %d\n",
+                       st->index);
+                return AVERROR(EINVAL);
+            }
+        }
+
         avpriv_set_pts_info(st, 33, 1, 90000);
 
         ts_st->payload = av_mallocz(ts->pes_payload_size);
diff --git a/tests/fate/mpegts.mak b/tests/fate/mpegts.mak
index 9a777c63fc1..087028f8595 100644
--- a/tests/fate/mpegts.mak
+++ b/tests/fate/mpegts.mak
@@ -36,6 +36,10 @@ fate-mpegts-dra-demux: CMD = probe -v error -of compact 
-select_streams i:0x28a
     -show_entries 
packet=pts,dts,duration,size,data_hash:stream=codec_name,codec_tag_string,sample_rate,channels,id,time_base
 \
     $(TARGET_SAMPLES)/dra/shanghai-522-dra.ts
 
+FATE_MPEGTS_FFMPEG_FFPROBE-$(call REMUX, MPEGTS, DRA_PARSER) += 
fate-mpegts-dra-remux
+fate-mpegts-dra-remux: CMD = stream_remux mpegts 
$(TARGET_SAMPLES)/dra/shanghai-522-dra.ts "" mpegts \
+    "-map 0:a:0" "" "-c:a copy" "-show_entries 
stream=codec_name,codec_tag_string -of compact"
+
 FATE_MPEGTS_PROBE-$(call DEMDEC, MPEGTS, HEVC, LOAS_DEMUXER) += 
fate-mpegts-probe-program-compact
 fate-mpegts-probe-program-compact: SRC = $(TARGET_SAMPLES)/mpegts/loewe.ts
 fate-mpegts-probe-program-compact: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -v 0 
-bitexact -of compact \
diff --git a/tests/ref/fate/mpegts-dra-remux b/tests/ref/fate/mpegts-dra-remux
new file mode 100644
index 00000000000..2b5f91e7e93
--- /dev/null
+++ b/tests/ref/fate/mpegts-dra-remux
@@ -0,0 +1,20 @@
+e61129f47dfbe3cc4c5b2b4ccb854efd *tests/data/fate/mpegts-dra-remux.mpegts
+5264 tests/data/fate/mpegts-dra-remux.mpegts
+#tb 0: 1/90000
+#media_type 0: audio
+#codec_id 0: dra
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0,          0,          0,     1920,      340, 0x9286b363, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       1920,       1920,     1920,      340, 0xfae6af34, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       3840,       3840,     1920,      340, 0x0397b143, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       5760,       5760,     1920,      340, 0xafadbc3a, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       7680,       7680,     1920,      340, 0x2dadb71e, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       9600,       9600,     1920,      340, 0x24d9abe4, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      11520,      11520,     1920,      340, 0x482bb1b4, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      13440,      13440,     1920,      340, 0x9cc8a1de, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      15360,      15360,     1920,      340, 0xee5baea5, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      17280,      17280,     1920,      340, 0x57b1aec4, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      19200,      19200,     1920,      340, 0x319fb55c, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      21120,      21120,     1920,      340, 0x561cb117, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+stream|codec_name=dra|codec_tag_string=DRA1
-- 
2.54.1


>From 6ca103f9a38e4cb57b2cd7875f88f07991223d78 Mon Sep 17 00:00:00 2001
From: yuygfgg <[email protected]>
Date: Fri, 27 Nov 2026 04:52:05 +0800
Subject: [PATCH 5/5] fate/demux: test DRA+ frames with sync words in auxiliary
 data

---
 tests/fate/demux.mak          | 5 +++++
 tests/ref/fate/dra-plus-demux | 3 +++
 2 files changed, 8 insertions(+)
 create mode 100644 tests/ref/fate/dra-plus-demux

diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index a22d1a40158..b6a9ebd0754 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -44,6 +44,11 @@ fate-cine-demux: CMD = crc -i 
$(TARGET_SAMPLES)/cine/bayer_gbrg8.cine -c copy
 FATE_SAMPLES_DEMUX-$(call FRAMECRC, DAUD) += fate-d-cinema-demux
 fate-d-cinema-demux: CMD = framecrc -i 
$(TARGET_SAMPLES)/d-cinema/THX_Science_FLT_1920-partial.302 -c:a copy
 
+# All three DRA+ frames in the sample contain a sync word inside the auxiliary 
payload.
+FATE_FFPROBE_DEMUX-$(call DEMDEC, DRA) += fate-dra-plus-demux
+fate-dra-plus-demux: CMD = probe -of compact -show_data_hash sha256 \
+    -show_entries packet=size,data_hash $(TARGET_SAMPLES)/dra/cdr-02bf.dra
+
 FATE_SAMPLES_DEMUX-$(call FRAMECRC, EA, VP6) += fate-d-eavp6-demux
 fate-d-eavp6-demux: CMD = framecrc -i $(TARGET_SAMPLES)/ea-vp6/SmallRing.vp6 
-map 0 -c:v copy
 
diff --git a/tests/ref/fate/dra-plus-demux b/tests/ref/fate/dra-plus-demux
new file mode 100644
index 00000000000..3a8946612c8
--- /dev/null
+++ b/tests/ref/fate/dra-plus-demux
@@ -0,0 +1,3 @@
+packet|size=160|data_hash=SHA256:867cab2ef1cc0e0cc74e3a491a8ea6a25df2d8929d5496434b26b06bd7c87bb8
+packet|size=160|data_hash=SHA256:83fbbdb4a391d2657d19dfd0ef5ff56a626e0ff552d267439600260d9b187b0f
+packet|size=160|data_hash=SHA256:6eb2c2c6949c2b5152954b4020183b915e026d4a1ee86792794642966d732107
-- 
2.54.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to