From: Jerome Martinez <jerome@mediaarea.net> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH] avformat: add DAT (Digital Audio Tape) demuxer Date: Sat, 8 Feb 2025 23:56:28 +0100 Message-ID: <261d7d61-11ae-4630-a536-cf11304d78b9@mediaarea.net> (raw) In-Reply-To: <20250201021301.GL4991@pb2> [-- Attachment #1: Type: text/plain, Size: 611 bytes --] Le 01/02/2025 à 03:13, Michael Niedermayer a écrit : > [...] > yes, this is the 2nd such dumb mistake i make in the last few days > the whole (still ongoing) "mobbing" compaign against me seems to > affect the quality of my reviews and work Sorry to read that, I hope that this will stop soon. > [...] > duplicate variable Stupid mistake while removing the planned next step (12-bit support, I'll send the corresponding patch when I more real files for tests for confirming that all is OK). Attached is the right patch. This 2/2 patch should be appended to the initial patch from this thread. Jérôme [-- Attachment #2: 0002-avformat-dat-improve-DAT-demuxer.patch --] [-- Type: text/plain, Size: 4189 bytes --] From 1b9a050a899dd8db96d544afcc30c493ff74279f Mon Sep 17 00:00:00 2001 From: Jerome Martinez <jerome@mediaarea.net> Date: Wed, 22 Jan 2025 16:08:18 +0100 Subject: [PATCH 2/2] avformat/dat: improve DAT demuxer Less false positive detection Better computation of data size with 12-bit or 4-ch --- libavformat/dat.c | 48 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/libavformat/dat.c b/libavformat/dat.c index 37548a8a73..c044fc7c2c 100644 --- a/libavformat/dat.c +++ b/libavformat/dat.c @@ -26,8 +26,9 @@ #define DAT_PACKET_SIZE 5822 #define DAT_OFFSET 5760 -static const uint32_t encoded_rate[] = { 48000, 44100, 32000, 0 }; -static const uint16_t encoded_size[] = { 5760, 5292, 3840, 0 }; +static const uint16_t encoded_samples[] = { 1440, 1323, 960, 0 }; +static const uint8_t encoded_samples_mul[] = { 1, 2, 0, 0 }; +static const uint8_t encoded_quantization[] = { 16, 12, 0, 0 }; static const uint8_t encoded_chans[] = { 2, 4, 0, 0 }; static const enum AVCodecID encoded_codec[] = { AV_CODEC_ID_PCM_S16LE, @@ -41,12 +42,26 @@ static int valid_frame(uint8_t *frame) uint8_t *mainid = subid+4; int chan_index = (mainid[0] >> 0) & 0x3; int rate_index = (mainid[0] >> 2) & 0x3; + int fmtid = (mainid[0] >> 6) & 0x3; + int trackpitch = (mainid[1] >> 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 numpacks = (subid[1] >> 0) & 0xf; + int pno1 = (subid[1] >> 4) & 0xf; + int pno3 = (subid[2] >> 0) & 0xf; + int pno2 = (subid[2] >> 4) & 0xf; + int pno = (pno1 << 8) | (pno2 << 4) | pno3; + int encoded_size = encoded_samples[rate_index] * encoded_samples_mul[trackpitch] * encoded_chans[chan_index] * encoded_quantization[enc_index] / 8; + + if (dataid != 0 || + numpacks > 7 || + pno == 0 || encoded_chans[chan_index] == 0 || - encoded_rate[rate_index] == 0) + encoded_samples[rate_index] == 0 || + fmtid != 0 || + encoded_samples_mul[trackpitch] == 0 || + encoded_quantization[enc_index] == 0 || + encoded_size > DAT_OFFSET) return 0; return 1; @@ -62,7 +77,7 @@ static int read_probe(const AVProbeData *p) score += ret; if (ret == 0) - break; + return 0; } return FFMIN(score, AVPROBE_SCORE_MAX); @@ -82,21 +97,28 @@ static int parse_frame(uint8_t *frame, AVCodecParameters *par) uint8_t *mainid = subid+4; int chan_index = (mainid[0] >> 0) & 0x3; int rate_index = (mainid[0] >> 2) & 0x3; + int fmtid = (mainid[0] >> 6) & 0x3; + int trackpitch = (mainid[1] >> 2) & 0x3; int enc_index = (mainid[1] >> 6) & 0x3; int dataid = (subid[0] >> 0) & 0xf; + int encoded_size = encoded_samples[rate_index] * encoded_samples_mul[trackpitch] * encoded_chans[chan_index] * encoded_quantization[enc_index] / 8; par->codec_type = AVMEDIA_TYPE_AUDIO; par->codec_id = encoded_codec[enc_index]; av_channel_layout_default(&par->ch_layout, encoded_chans[chan_index]); - par->sample_rate = encoded_rate[rate_index]; - par->bit_rate = (8LL * DAT_PACKET_SIZE * par->sample_rate) / FFMAX(1, av_get_audio_frame_duration2(par, encoded_size[rate_index])); - - if (dataid != 0 || par->codec_id == AV_CODEC_ID_NONE || - par->ch_layout.nb_channels <= 0 || - par->sample_rate <= 0) + par->sample_rate = encoded_samples[rate_index] * 100 / 3; + par->bit_rate = (8LL * DAT_PACKET_SIZE * par->sample_rate) / FFMAX(1, av_get_audio_frame_duration2(par, encoded_size)); + + if (dataid != 0 || + par->ch_layout.nb_channels == 0 || + par->sample_rate == 0 || + fmtid != 0 || + encoded_samples_mul[trackpitch] == 0 || + encoded_quantization[enc_index] == 0 || + encoded_size > DAT_OFFSET) return AVERROR_INVALIDDATA; - return encoded_size[rate_index]; + return encoded_size; } static int read_packet(AVFormatContext *s, AVPacket *pkt) -- 2.46.0.windows.1 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2025-02-08 22:56 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <a2f813dd-06db-43dc-b64a-22c8038ce1fa@mediaarea.net> [not found] ` <20250117204315.GO4991@pb2> 2025-01-22 11:26 ` Jerome Martinez 2025-01-25 0:46 ` Michael Niedermayer 2025-01-29 17:02 ` Jerome Martinez 2025-02-01 2:13 ` Michael Niedermayer 2025-02-08 22:56 ` Jerome Martinez [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=261d7d61-11ae-4630-a536-cf11304d78b9@mediaarea.net \ --to=jerome@mediaarea.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git