[FFmpeg-devel] [PATCH] avformat: add DAT (Digital Audio Tape) demuxer

Jerome Martinez jerome at mediaarea.net
Wed Jan 22 13:26:17 EET 2025


Le 17/01/2025 à 21:43, Michael Niedermayer a écrit :
> On Fri, Jan 17, 2025 at 12:38:02PM +0100, Jerome Martinez wrote:
>> [...]
>> Subject: [PATCH] avformat: add DAT demuxer
> breaks fate-cdxl-pal8-small
>
> I guess the probe function is not working as expected

cdxl parser provides a read_probe value of 1, difficult to compete there...
I added checks on extra metadata (not needed for decoding) for having a 
DAT parser read_probe value of 0 for the cdxl-pal8-small file, it works 
with all the DAT files I found while not changing the fate tests behavior.
Attached is an 2/2 patch to be added to the first one, I separate the 
fix patch from the initial patch in order to keep author name of each patch.
-------------- next part --------------
From 17e4ae0189fc60e4c69357b5324fd84b111a0ac3 Mon Sep 17 00:00:00 2001
From: Jerome Martinez <jerome at mediaarea.net>
Date: Tue, 21 Jan 2025 22:31:31 +0100
Subject: [PATCH 2/2] avformat: improve DAT demuxer read_probe"

---
 libavformat/dat.c | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/libavformat/dat.c b/libavformat/dat.c
index 37548a8a73..f7d2de44bc 100644
--- a/libavformat/dat.c
+++ b/libavformat/dat.c
@@ -39,14 +39,41 @@ static int valid_frame(uint8_t *frame)
     uint8_t *scode = frame+DAT_OFFSET;
     uint8_t *subid = scode+7*8;
     uint8_t *mainid = subid+4;
-    int chan_index = (mainid[0] >> 0) & 0x3;
-    int rate_index = (mainid[0] >> 2) & 0x3;
-    int enc_index  = (mainid[1] >> 6) & 0x3;
-    int dataid     = (subid[0] >> 0) & 0xf;
-
-    if (dataid != 0 || encoded_codec[enc_index] == AV_CODEC_ID_NONE ||
+    int pno = 0;
+    int subcode_parity_error = 0;
+    for (int i = 0; i < 7; i++) {
+        uint8_t *subcode = scode+i*8;
+        uint8_t subcode_parity = 0;
+        for (int j = 0; j < 8; j++)
+            subcode_parity ^= subcode[j];
+        if (subcode_parity)
+            subcode_parity_error = 1;
+    }
+    int dataid              = ( subid[0] >> 0) & 0xf;
+    int numpacks            = ( subid[1] >> 0) & 0xf;
+    int pno1                = ( subid[1] >> 4) & 0xf;
+    int pno3                = ( subid[2] >> 0) & 0xf;
+    int pno2                = ( subid[2] >> 4) & 0xf;
+    int chan_index          = (mainid[0] >> 0) & 0x3;
+    int rate_index          = (mainid[0] >> 2) & 0x3;
+    int emphasis_reserved   = (mainid[0] >> 5) & 0x1;
+    int fmtid               = (mainid[0] >> 6) & 0x3;
+    int trackpitch_reserved = (mainid[1] >> 3) & 0x1;
+    int copy_reserved       = (mainid[1] >> 4) & 0x1;
+    int enc_index           = (mainid[1] >> 6) & 0x3;
+    pno = (pno1 << 8) | (pno2 << 4) | pno3;
+
+    if (subcode_parity_error != 0 ||
+        dataid != 0 ||
         encoded_chans[chan_index] == 0 ||
-        encoded_rate[rate_index] == 0)
+        numpacks > 7 ||
+        !(pno == 0xAA || pno == 0xBB || pno == 0xEE || (pno != 0 && pno1 <= 7 && pno2 <= 9 && pno3 <= 9)) ||
+        encoded_rate[rate_index] == 0 ||
+        emphasis_reserved != 0 ||
+        fmtid != 0 ||
+        copy_reserved != 0 ||
+        trackpitch_reserved != 0 ||
+        encoded_codec[enc_index] == AV_CODEC_ID_NONE)
         return 0;
 
     return 1;
-- 
2.46.0.windows.1



More information about the ffmpeg-devel mailing list