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 5BE0745ADB for ; Sun, 16 Apr 2023 19:55:59 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 80C9C680785; Sun, 16 Apr 2023 22:55:56 +0300 (EEST) Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3DFCA680785 for ; Sun, 16 Apr 2023 22:55:50 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 289A3240004 for ; Sun, 16 Apr 2023 19:55:48 +0000 (UTC) Date: Sun, 16 Apr 2023 21:55:46 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20230416195546.GG275832@pb2> References: <61fca341-57cc-abe5-225e-561f5e2a9b4b@funderburk.us> <20230415145640.GF275832@pb2> MIME-Version: 1.0 In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH v2] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc 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="===============4436080682581197148==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============4436080682581197148== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="p7qwJlK53pWzbayA" Content-Disposition: inline --p7qwJlK53pWzbayA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi On Sat, Apr 15, 2023 at 01:04:42PM -0700, Roy Funderburk wrote: >=20 > Parsing and demuxing of DTS-UHD input files per ETSI TS 102 114 is added > as demuxer "dtsuhd". movenc supports DTS-UHD audio track. >=20 > Signed-off-by: Roy Funderburk > --- > Changelog | 1 + > configure | 1 + > doc/general_contents.texi | 1 + > libavcodec/Makefile | 1 + > libavcodec/codec_desc.c | 7 + > libavcodec/codec_id.h | 1 + > libavcodec/dtsuhd_common.c | 991 +++++++++++++++++++++++++++++++++++++ > libavcodec/dtsuhd_common.h | 84 ++++ > libavcodec/dtsuhd_parser.c | 141 ++++++ > libavcodec/parsers.c | 1 + > libavformat/Makefile | 1 + > libavformat/allformats.c | 1 + > libavformat/dtshddec.c | 2 +- > libavformat/dtsuhddec.c | 214 ++++++++ > libavformat/movenc.c | 32 ++ > libavformat/version.h | 2 +- > 16 files changed, 1479 insertions(+), 2 deletions(-) > create mode 100644 libavcodec/dtsuhd_common.c > create mode 100644 libavcodec/dtsuhd_common.h > create mode 100644 libavcodec/dtsuhd_parser.c > create mode 100644 libavformat/dtsuhddec.c >=20 [...] > +/* In the specification, the pseudo code defaults the 'add' parameter to= true. > + Table 7-30 shows passing an explicit false, most other calls do not > + pass the extractAndAdd parameter. > + > + Function based on code in Table 5-2 > +*/ > +static int get_bits_var(GetBitContext *gb, const uint8_t table[], int ad= d) > +{ > + static const int bits_used[8] =3D { 1, 1, 1, 1, 2, 2, 3, 3 }; > + static const int index_table[8] =3D { 0, 0, 0, 0, 1, 1, 2, 3 }; > + int code =3D show_bits(gb, 3); /* value range is [0, 7] */ > + int i; > + int index =3D index_table[code]; > + int value =3D 0; > + > + skip_bits(gb, bits_used[code]); > + if (table[index] > 0) { > + if (add) { > + for (i =3D 0; i < index; i++) > + value +=3D 1 << table[i]; > + } > + value +=3D get_bits_long(gb, table[index]); > + } If the speed of this matters, you could remove the indirection by index_table and remove teh add code, th= at would add 12 entries to some of these tables something like: int code =3D show_bits(gb, 3); skip_bits(gb, bits_used[code]); if (table[code][0] =3D=3D 0) return 0; return get_bits_long(gb, table[code][0]) + table[code][1]; =20 OTOH if speed doesnt matter then this can probably be left as is [...] > + > +/* Table 6-9 p 38 */ > +static int check_crc(DTSUHD *h, int bit, int bytes) > +{ > + GetBitContext gb; > + int i; > + static const uint16_t lookup[16] =3D { > + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, > + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF > + }; > + uint16_t crc =3D 0xFFFF; > + > + init_get_bits(&gb, h->data, h->data_bytes * 8); > + skip_bits(&gb, bit); > + for (i =3D -bytes; i < bytes; i++) > + crc =3D (crc << 4) ^ lookup[(crc >> 12) ^ get_bits(&gb, 4)]; > + > + return crc !=3D 0; > +} likely should use libavutil/crc.h [...] > +/* Table 7-26 */ > +static void parse_ch_mask_params(DTSUHD *h, MD01 *md01, MDObject *object) > +{ > + GetBitContext *gb =3D &h->gb; > + const int ch_index =3D object->rep_type =3D=3D REP_TYPE_BINAURAL ? 1= : get_bits(gb, 4); > + static const int mask_table[14] =3D { /* Table 7-27 */ > + 0x000001, 0x000002, 0x000006, 0x00000F, 0x00001F, 0x00084B, 0x00= 002F, > + 0x00802F, 0x00486B, 0x00886B, 0x03FBFB, 0x000003, 0x000007, 0x00= 0843, > + }; > + > + if (ch_index =3D=3D 14) > + object->ch_activity_mask =3D get_bits(gb, 16); > + else if (ch_index =3D=3D 15) > + object->ch_activity_mask =3D get_bits(gb, 32); get_bits_long() [...] > +/** Allocate parsing handle. The parsing handle should be used to parse > + one DTS:X Profile 2 Audio stream, then freed by calling DTSUHD_destr= oy(). > + Do not use the same parsing handle to parse multiple audio streams. > + > + @return Parsing handle for use with other functions, or NULL on failur= e. > +*/ > +DTSUHD *dtsuhd_create(void) stuff needs av / avpriv prefixes when shared between libraries other symbol= s arent exported and will break build depending on build options also minor libavcodec version needs to be +1 when adding av* symbols and libavcodec and libavformat changes should be in 2 seperate patches [...] > + if (fi) { > + fi->sync =3D h->is_sync_frame; > + fi->frame_bytes =3D h->frame_bytes; > + fi->sample_rate =3D h->sample_rate; > + fi->sample_count =3D (h->frame_duration * fi->sample_rate) / (h-= >clock_rate * fraction); > + fi->duration =3D (double)fi->sample_count / fi->sample_rate; it feels as if double is not needed here Either AVRational or a simple integer type int / int64_t in samples instead= of seconds seem better as it would be exact and no odd platform rounding difference could happen [...] > + > +/** Return the offset of the first UHD audio frame. > + When supplied a buffer containing DTSHDHDR file content, the DTSHD > + headers are skipped and the offset to the first byte of the STRMDATA > + chunk is returned, along with the size of that chunk. > + > + @param[in] dataStart DTS:X Profile 2 file content to parse > + @param[in] dataSize Number of valid bytes in 'dataStart' > + @param[out] Number of leading DTS:X Profile 2 audio frames to discard, > + may be NULL > + @param[out] Size of STRMDATA payload, may be NULL > + @return STRMDATA payload offset or 0 if not a valid DTS:X Profile 2 fi= le > +*/ > +int dtsuhd_strmdata_payload(const uint8_t *data_start, int data_size, si= ze_t *strmdata_size) > +{ > + const uint8_t *data =3D data_start; > + const uint8_t *data_end =3D data + data_size; > + uint64_t chunk_size =3D 0; > + > + if (data + DTSUHD_CHUNK_HEADER >=3D data_end || memcmp(data, "DTSHDH= DR", 8)) > + return 0; > + > + for (; data + DTSUHD_CHUNK_HEADER + 4 <=3D data_end; data +=3D chunk= _size + DTSUHD_CHUNK_HEADER) { > + chunk_size =3D AV_RB64(data + 8); > + > + if (!memcmp(data, "STRMDATA", 8)) { > + if (strmdata_size) > + *strmdata_size =3D chunk_size; > + return (int)(data - data_start) + DTSUHD_CHUNK_HEADER; > + } > + } this can infinite loop undefined behavior for teh out of array pointers that can happen with the "right" chunk_size also data can decrease if one ignores that this is already undefined before [...] > + > + ffstream(st)->need_parsing =3D AVSTREAM_PARSE_FULL_RAW; > + st->codecpar->codec_type =3D AVMEDIA_TYPE_AUDIO; > + st->codecpar->codec_id =3D s->iformat->raw_codec_id; > + st->codecpar->ch_layout.order =3D AV_CHANNEL_ORDER_NATIVE; > + st->codecpar->ch_layout.nb_channels =3D di.channel_count; > + st->codecpar->ch_layout.u.mask =3D di.ffmpeg_channel_mask; > + st->codecpar->codec_tag =3D AV_RL32(di.coding_name); > + st->codecpar->frame_size =3D 512 << di.frame_duration_code; > + st->codecpar->sample_rate =3D di.sample_rate; you could align all the "=3D" below each other, that would make this look more pretty thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Complexity theory is the science of finding the exact solution to an approximation. Benchmarking OTOH is finding an approximation of the exact --p7qwJlK53pWzbayA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZDxSvgAKCRBhHseHBAsP q+NeAJ9G/BpwEpVrAlbQ0yhyIazlwpKwFQCfVgAIrfdhD6Ut2IRJfzOJ0h2i+CE= =lDbK -----END PGP SIGNATURE----- --p7qwJlK53pWzbayA-- --===============4436080682581197148== 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". --===============4436080682581197148==--