From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id AC59D468F7 for ; Thu, 24 Aug 2023 18:06:35 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A82E768C62E; Thu, 24 Aug 2023 21:06:32 +0300 (EEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A6CF468C02E for ; Thu, 24 Aug 2023 21:06:26 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id D26381BF204 for ; Thu, 24 Aug 2023 18:06:25 +0000 (UTC) Date: Thu, 24 Aug 2023 20:06:24 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20230824180624.GN7802@pb2> References: MIME-Version: 1.0 In-Reply-To: X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH] OSQ lossless audio format support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============2483478485216718304==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2483478485216718304== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CsRGQZqGVuBxe9XK" Content-Disposition: inline --CsRGQZqGVuBxe9XK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 24, 2023 at 11:52:45AM +0200, Paul B Mahol wrote: > Patches attached. >=20 > Stereo decoding have some issues with some predictors so not yet bitexact. >=20 > Please comment. [...] > diff --git a/libavformat/osq.c b/libavformat/osq.c > new file mode 100644 > index 0000000000..36ce25313f > --- /dev/null > +++ b/libavformat/osq.c > @@ -0,0 +1,117 @@ > +/* > + * OSQ demuxer > + * Copyright (c) 2023 Paul B Mahol > + * > + * 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-1= 301 USA > + */ > + > +#include "libavutil/intreadwrite.h" > +#include "avio_internal.h" > +#include "avformat.h" > +#include "demux.h" > +#include "internal.h" > +#include "rawdec.h" > + > +static int osq_probe(const AVProbeData *p) > +{ > + if (AV_RL32(p->buf) !=3D MKTAG('O','S','Q',' ')) > + return 0; > + if (AV_RL32(p->buf + 4) !=3D 48) > + return 0; > + if (AV_RL16(p->buf + 8) !=3D 1) > + return 0; this can be simplified to a single memcmp() with a 10 byte array > + if (!p->buf[10]) > + return 0; > + if (!p->buf[11]) > + return 0; > + if (AV_RL32(p->buf + 12) =3D=3D 0) > + return 0; > + if (AV_RL16(p->buf + 16) =3D=3D 0) > + return 0; inconsistant, you mix !x and =3D=3D 0 for the same kind of check > + > + return AVPROBE_SCORE_MAX; > +} > + > +static int osq_read_header(AVFormatContext *s) > +{ > + uint32_t t, size; > + AVStream *st; > + int ret; > + > + t =3D avio_rl32(s->pb); > + if (t !=3D MKTAG('O','S','Q',' ')) > + return AVERROR_INVALIDDATA; > + > + size =3D avio_rl32(s->pb); > + if (size !=3D 48) > + return AVERROR_INVALIDDATA; > + > + st =3D avformat_new_stream(s, NULL); > + if (!st) > + return AVERROR(ENOMEM); > + if ((ret =3D ff_get_extradata(s, st->codecpar, s->pb, size)) < 0) > + return ret; > + > + t =3D avio_rl32(s->pb); > + if (t !=3D MKTAG('R','I','F','F')) > + return AVERROR_INVALIDDATA; > + avio_skip(s->pb, 8); > + > + t =3D avio_rl32(s->pb); > + if (t !=3D MKTAG('f','m','t',' ')) > + return AVERROR_INVALIDDATA; > + size =3D avio_rl32(s->pb); > + avio_skip(s->pb, size); > + > + t =3D avio_rl32(s->pb); > + size =3D avio_rl32(s->pb); > + while (t !=3D MKTAG('d','a','t','a')) { > + avio_skip(s->pb, size); > + > + t =3D avio_rl32(s->pb); > + size =3D avio_rl32(s->pb); > + if (avio_feof(s->pb)) > + return AVERROR_INVALIDDATA; > + } This looks familiar, can code be shared with other RIFF based formats ? > + > + st->codecpar->codec_type =3D AVMEDIA_TYPE_AUDIO; > + st->codecpar->codec_id =3D AV_CODEC_ID_OSQ; > + st->codecpar->sample_rate =3D AV_RL32(st->codecpar->extradata + 4); > + if (st->codecpar->sample_rate =3D=3D 0) > + return AVERROR_INVALIDDATA; missing check for negative numbers [...] > diff --git a/libavcodec/osq.c b/libavcodec/osq.c > new file mode 100644 > index 0000000000..b6dc5c1bb4 > --- /dev/null > +++ b/libavcodec/osq.c > @@ -0,0 +1,435 @@ > +/* > + * OSQ audio decoder > + * Copyright (c) 2023 Paul B Mahol > + * > + * 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-1= 301 USA > + */ > + > +#define ASSERT_LEVEL 5 that looks strange assert level is set by the user building this, also there is no level 5 > +#include "libavutil/avassert.h" > +#include "libavutil/internal.h" > +#include "libavutil/intreadwrite.h" > +#include "avcodec.h" > +#include "codec_internal.h" > +#include "decode.h" > +#include "internal.h" > +#define BITSTREAM_READER_LE > +#include "get_bits.h" > +#include "unary.h" > + > +typedef struct OSQChannel { > + int prediction; > + int coding_mode; > + int residue_parameter; > + int residue_bits; > +} OSQChannel; > + > +typedef struct OSQContext { > + GetBitContext gb; > + OSQChannel ch[2]; > + > + uint8_t *bitstream; > + int64_t max_framesize; i think the max_framesize fits in 29bits currently so 64 should not be need= ed [...] > + > + s->bitstream =3D av_calloc(s->max_framesize + AV_INPUT_BUFFER_PADDIN= G_SIZE, sizeof(*s->bitstream)); > + if (!s->bitstream) > + return AVERROR(ENOMEM); > + > + for (int ch =3D 0; ch < avctx->ch_layout.nb_channels; ch++) { > + s->decode_buffer[ch] =3D av_calloc(s->frame_samples + 4, > + sizeof(*s->decode_buffer[ch])); > + if (!s->decode_buffer[ch]) > + return AVERROR(ENOMEM); > + } > + > + s->pkt =3D avctx->internal->in_pkt; > + > + return 0; > +} > + > +static uint32_t get_urice(GetBitContext *gb, int k) > +{ > + uint32_t z, x, b; > + > + x =3D get_unary(gb, 1, 512); > + b =3D get_bits_long(gb, k & 31); > + z =3D b | x << (k & 31); the k & 31 seems unneeded [...] > + } > + break; > + case AV_SAMPLE_FMT_S32P: > + for (int ch =3D 0; ch < avctx->ch_layout.nb_channels; ch++) { > + int32_t *dst =3D (int32_t *)frame->extended_data[ch]; > + int32_t *src =3D s->decode_buffer[ch] + 4; > + > + for (int n =3D 0; n < frame->nb_samples; n++) > + dst[n] =3D src[n]; memcpy() unless these can overlap thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB While the State exists there can be no freedom; when there is freedom there will be no State. -- Vladimir Lenin --CsRGQZqGVuBxe9XK Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZOecHQAKCRBhHseHBAsP qzgBAJkBuuhMcMA8XlGaWvjOIgpDxuNVBwCeM+NkqMaHyogZ0jtHd2X7g2hye6o= =/7R6 -----END PGP SIGNATURE----- --CsRGQZqGVuBxe9XK-- --===============2483478485216718304== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============2483478485216718304==--