Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2024-01-16 Thread Roy Funderburk

Updated to latest master changes.--- Begin Message ---
Signed-off-by: Roy Funderburk 
---
 Changelog |   1 +
 configure |   1 +
 doc/general_contents.texi |   1 +
 libavformat/Makefile  |   1 +
 libavformat/allformats.c  |   1 +
 libavformat/dtshddec.c|   2 +-
 libavformat/dtsuhddec.c   | 216 ++
 libavformat/movenc.c  |  32 ++
 libavformat/version.h |   2 +-
 9 files changed, 255 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/dtsuhddec.c

diff --git a/Changelog b/Changelog
index 4e7c1ce2c1..d1f19d7047 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ version :
 - VVC decoder
 - fsync filter
 - Raw Captions with Time (RCWT) closed caption muxer
+- DTS-UHD demuxer
 
 version 6.1:
 - libaribcaption decoder
diff --git a/configure b/configure
index c8ae0a061d..70f511827e 100755
--- a/configure
+++ b/configure
@@ -3517,6 +3517,7 @@ dash_demuxer_deps="libxml2"
 dirac_demuxer_select="dirac_parser"
 dts_demuxer_select="dca_parser"
 dtshd_demuxer_select="dca_parser"
+dtsuhd_demuxer_select="dtsuhd_parser"
 dv_demuxer_select="dvprofile"
 dv_muxer_select="dvprofile"
 dxa_demuxer_select="riffdec"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..2c6d008039 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -613,6 +613,7 @@ library:
 @item raw DNxHD @tab X @tab X
 @item raw DTS   @tab X @tab X
 @item raw DTS-HD@tab   @tab X
+@item raw DTS-UHD   @tab   @tab
 @item raw E-AC-3@tab X @tab X
 @item raw EVC   @tab X @tab X
 @item raw FLAC  @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index dcc99eeac4..f98f157ab0 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -188,6 +188,7 @@ OBJS-$(CONFIG_DSICIN_DEMUXER)+= dsicin.o
 OBJS-$(CONFIG_DSS_DEMUXER)   += dss.o
 OBJS-$(CONFIG_DTSHD_DEMUXER) += dtshddec.o
 OBJS-$(CONFIG_DTS_DEMUXER)   += dtsdec.o rawdec.o
+OBJS-$(CONFIG_DTSUHD_DEMUXER)+= dtsuhddec.o
 OBJS-$(CONFIG_DTS_MUXER) += rawenc.o
 OBJS-$(CONFIG_DV_MUXER)  += dvenc.o
 OBJS-$(CONFIG_DVBSUB_DEMUXER)+= dvbsub.o rawdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index b04b43cab3..5e0608de7f 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -146,6 +146,7 @@ extern const AVInputFormat  ff_dss_demuxer;
 extern const AVInputFormat  ff_dts_demuxer;
 extern const FFOutputFormat ff_dts_muxer;
 extern const AVInputFormat  ff_dtshd_demuxer;
+extern const AVInputFormat  ff_dtsuhd_demuxer;
 extern const AVInputFormat  ff_dv_demuxer;
 extern const FFOutputFormat ff_dv_muxer;
 extern const AVInputFormat  ff_dvbsub_demuxer;
diff --git a/libavformat/dtshddec.c b/libavformat/dtshddec.c
index a3dea0668f..6e9e78a335 100644
--- a/libavformat/dtshddec.c
+++ b/libavformat/dtshddec.c
@@ -46,7 +46,7 @@ typedef struct DTSHDDemuxContext {
 static int dtshd_probe(const AVProbeData *p)
 {
 if (AV_RB64(p->buf) == DTSHDHDR)
-return AVPROBE_SCORE_MAX;
+return AVPROBE_SCORE_MAX - 4; // DTSUHD (.dtsx) files also have this 
signature.
 return 0;
 }
 
diff --git a/libavformat/dtsuhddec.c b/libavformat/dtsuhddec.c
new file mode 100644
index 00..d840c0a033
--- /dev/null
+++ b/libavformat/dtsuhddec.c
@@ -0,0 +1,216 @@
+/*
+ * DTS-UHD audio demuxer
+ * Copyright (c) 2023 Xperi Corporation / DTS, Inc.
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Report DTS-UHD audio stream configuration and extract raw packet data.
+ */
+
+#include "internal.h"
+#include "libavcodec/dtsuhd_common.h"
+#include "libavcodec/put_bits.h"
+#include "libavutil/intreadwrite.h"
+
+#define DTSUHD_BUFFER_SIZE (1024 * 1024)
+
+typedef struct DTSUHDDemuxContext {
+size_t data_end;
+struct DTSUHD *dtsuhd;
+uint8_t *buf;
+} DTSUHDDemuxContext;
+
+static int probe(const AVProbeData *p)
+{
+int offset = av_dtsuhd_strmdata_payload(p->buf, p->buf_size, NULL);
+int score = 0;
+struct DTSUHD *h = av_dtsuhd_create();
+
+if (h && offset >= 0) {
+ 

Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-08-17 Thread Roy Funderburk


On 8/17/23 3:31 PM, Paul B Mahol wrote:
> Is decoder part still missing or?

This is just intended to read audio from a .dtsx file and output an mp4/mov 
file. There will not be a .dtsx to PCM decoder.

Thanks,
-Roy
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-08-17 Thread Paul B Mahol
Is decoder part still missing or?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-08-17 Thread Roy Funderburk
Updated for master branch changes.

--- Begin Message ---
Parsing of DTS-UHD input files per ETSI TS 102 114 is added
as parser for codec id AV_CODEC_ID_DTSUHD.

Signed-off-by: Roy Funderburk 
---
 libavcodec/Makefile|   1 +
 libavcodec/codec_desc.c|   7 +
 libavcodec/codec_id.h  |   1 +
 libavcodec/dtsuhd_common.c | 982 +
 libavcodec/dtsuhd_common.h |  83 
 libavcodec/dtsuhd_parser.c | 141 ++
 libavcodec/parsers.c   |   1 +
 libavcodec/version.h   |   2 +-
 8 files changed, 1217 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/dtsuhd_common.c
 create mode 100644 libavcodec/dtsuhd_common.h
 create mode 100644 libavcodec/dtsuhd_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3c16b51462..583abd1f88 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1167,6 +1167,7 @@ OBJS-$(CONFIG_DIRAC_PARSER)+= dirac_parser.o
 OBJS-$(CONFIG_DNXHD_PARSER)+= dnxhd_parser.o dnxhddata.o
 OBJS-$(CONFIG_DOLBY_E_PARSER)  += dolby_e_parser.o dolby_e_parse.o
 OBJS-$(CONFIG_DPX_PARSER)  += dpx_parser.o
+OBJS-$(CONFIG_DTSUHD_PARSER)   += dtsuhd_parser.o dtsuhd_common.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 4406dd8318..e6af7f2e99 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3413,6 +3413,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("AC-4"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_DTSUHD,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "dtsuhd",
+.long_name = NULL_IF_CONFIG_SMALL("DTSUHD (DTS-UHD Audio Format)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index a5a0cb8525..3e87aa1fe5 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -543,6 +543,7 @@ enum AVCodecID {
 AV_CODEC_ID_WAVARC,
 AV_CODEC_ID_RKA,
 AV_CODEC_ID_AC4,
+AV_CODEC_ID_DTSUHD,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/dtsuhd_common.c b/libavcodec/dtsuhd_common.c
new file mode 100644
index 00..3d6b4ab4e0
--- /dev/null
+++ b/libavcodec/dtsuhd_common.c
@@ -0,0 +1,982 @@
+/*
+ * DTS-UHD common audio frame parsing code
+ * Copyright (c) 2023 Xperi Corporation / DTS, Inc.
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Parse DTS-UHD audio frame headers, report frame sizes and configuration.
+ * Specification: ETSI TS 103 491 V1.2.1
+ */
+
+#include 
+
+#include "dtsuhd_common.h"
+#include "get_bits.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/crc.h"
+
+#define DTSUHD_ALLOC_INCREMENT 16
+#define DTSUHD_CHUNK_HEADER16
+#define DTSUHD_CRC_SEED 0x
+
+enum RepType {
+REP_TYPE_CH_MASK_BASED,
+REP_TYPE_MTRX2D_CH_MASK_BASED,
+REP_TYPE_MTRX3D_CH_MASK_BASED,
+REP_TYPE_BINAURAL,
+REP_TYPE_AMBISONIC,
+REP_TYPE_AUDIO_TRACKS,
+REP_TYPE_3D_OBJECT_SINGLE_SRC_PER_WF,
+REP_TYPE_3D_MONO_OBJECT_SINGLE_SRC_PER_WF,
+};
+
+typedef struct MDObject {
+int started;  /* Object seen since last reset. */
+int pres_index;
+int rep_type;
+int ch_activity_mask;
+} MDObject;
+
+typedef struct MD01 {
+GetBitContext gb;
+MDObject object[257]; /* object id max value is 256 */
+int chunk_id;
+int object_list[256]; int object_list_count;
+int packets_acquired;
+int static_md_extracted;
+int static_md_packets;
+int static_md_packet_size;
+int static_md_update_flag;
+uint8_t *buf; int buf_bytes; /* temporary buffer to accumulate static data 
*/
+} MD01;
+
+typedef struct NAVI {
+int bytes;
+int id;
+int index;
+int present;
+} NAVI;
+
+typedef struct UHDAudio {
+int mask;
+int selectable;
+} UHDAudio;
+
+typedef struct UHDChunk {
+int crc_flag;
+

Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-20 Thread Roy Funderburk

On 6/18/23 5:18 AM, Paul B Mahol wrote:
> Well, just keep that part as is currently, until someone else cleans it up.
> 
> Can probing in new demuxer be smarter than just decreasing score of another
> demuxer?


A new patch is attached where the dtshddec.c probe function change is updated 
to no longer just decrease the score.

Regards,
-Roy
--- Begin Message ---
Parsing of DTS-UHD input files per ETSI TS 102 114 is added
as parser for codec id AV_CODEC_ID_DTSUHD.

Signed-off-by: Roy Funderburk 
---
 libavcodec/Makefile|1 +
 libavcodec/codec_desc.c|7 +
 libavcodec/codec_id.h  |1 +
 libavcodec/dtsuhd_common.c | 1079 
 libavcodec/dtsuhd_common.h |   87 +++
 libavcodec/dtsuhd_parser.c |  141 +
 libavcodec/parsers.c   |1 +
 libavcodec/version.h   |2 +-
 8 files changed, 1318 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/dtsuhd_common.c
 create mode 100644 libavcodec/dtsuhd_common.h
 create mode 100644 libavcodec/dtsuhd_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2efab60d7d..0b49984902 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1164,6 +1164,7 @@ OBJS-$(CONFIG_DIRAC_PARSER)+= dirac_parser.o
 OBJS-$(CONFIG_DNXHD_PARSER)+= dnxhd_parser.o dnxhddata.o
 OBJS-$(CONFIG_DOLBY_E_PARSER)  += dolby_e_parser.o dolby_e_parse.o
 OBJS-$(CONFIG_DPX_PARSER)  += dpx_parser.o
+OBJS-$(CONFIG_DTSUHD_PARSER)   += dtsuhd_parser.o dtsuhd_common.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 3e31a1eed6..63dc939905 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3406,6 +3406,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("RKA (RK Audio)"),
 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY | 
AV_CODEC_PROP_LOSSLESS,
 },
+{
+.id= AV_CODEC_ID_DTSUHD,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "dtsuhd",
+.long_name = NULL_IF_CONFIG_SMALL("DTSUHD (DTS-UHD Audio Format)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index d23549d7e0..a5d580169b 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -542,6 +542,7 @@ enum AVCodecID {
 AV_CODEC_ID_FTR,
 AV_CODEC_ID_WAVARC,
 AV_CODEC_ID_RKA,
+AV_CODEC_ID_DTSUHD,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/dtsuhd_common.c b/libavcodec/dtsuhd_common.c
new file mode 100644
index 00..4d91172b33
--- /dev/null
+++ b/libavcodec/dtsuhd_common.c
@@ -0,0 +1,1079 @@
+/*
+ * DTS-UHD common audio frame parsing code
+ * Copyright (c) 2023 Xperi Corporation / DTS, Inc.
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Parse DTS-UHD audio frame headers, report frame sizes and configuration.
+ * Specification: ETSI TS 103 491 V1.2.1
+ */
+
+#include 
+
+#include "dtsuhd_common.h"
+#include "get_bits.h"
+#include "put_bits.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/crc.h"
+
+#define DTSUHD_ALLOC_INCREMENT 16
+#define DTSUHD_CHUNK_HEADER16
+#define DTSUHD_CRC_SEED0x
+#define DTSUHD_UDTS_BUFFER 32 // work buffer to construct 'udts' box
+
+enum RepType {
+REP_TYPE_CH_MASK_BASED,
+REP_TYPE_MTRX2D_CH_MASK_BASED,
+REP_TYPE_MTRX3D_CH_MASK_BASED,
+REP_TYPE_BINAURAL,
+REP_TYPE_AMBISONIC,
+REP_TYPE_AUDIO_TRACKS,
+REP_TYPE_3D_OBJECT_SINGLE_SRC_PER_WF,
+REP_TYPE_3D_MONO_OBJECT_SINGLE_SRC_PER_WF,
+};
+
+typedef struct MDObject {
+int started;  /* Object seen since last reset. */
+int pres_index;
+int rep_type;
+int ch_activity_mask;
+} MDObject;
+
+typedef struct MD01 {
+GetBitContext gb;
+MDObject object[257]; /* object id max value is 256 */
+int chunk_id;
+int object_list[256]; int 

Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-18 Thread Paul B Mahol
On Thu, Jun 15, 2023 at 8:45 PM Roy Funderburk 
wrote:

>
>
> On 6/15/23 8:46 AM, Paul B Mahol wrote:
> > get_vlc2 can be made for get_bits_var(), first table bits (that are still
> > int and not uint8_t), the code that picks table index from which to take
> > bits.
> >
> > It is also possible to make it take both first index and rest of it and
> > build bigger tables but that is very very advanced step for new
> > contributors.
> >
> > Use INIT_VLC_SPARSE_STATIC, there are myriad examples in libavcodec, one
> of
> > them being imm4 decoder.
> >
>
> I will change that table bits array to uint8_t.
>
> I encountered an issue when trying to set up the VLC table with
> INIT_VLC_SPARSE_STATIC.
>
> The current get_bits_var:
>
> static int get_bits_var(GetBitContext *gb, const VarBits *var_bits)
> {
> static const uint8_t bits_used[8] = { 1, 1, 1, 1, 2, 2, 3, 3 };
> int code = show_bits(gb, 3); /* value range is [0, 7] */
>
> skip_bits(gb, bits_used[code]);
> if (var_bits->bits[code] == 0)
> return 0;
> return get_bits_long(gb, var_bits->bits[code]) +
> var_bits->add[code];
> }
>
> Changed to use get_vlc2 would be:
>
> static int get_bits_var(GetBitContext *gb, const VarBits *var_bits)
> {
> int code = get_vlc2(, vlc.table, 3, 1);
> if (var_bits->bits[code] == 0)
> return 0;
> return get_bits_long(gb, var_bits->bits[code]) +
> var_bits->add[code];
> }
>
> The "vlc.table" that INIT_VLC_SPARSE_STATIC needs to output is:
>
> len: 1, 1, 1, 1, 2, 2, 3, 3
> sym: 4, 4, 4, 4, 8, 8, 16, 32
>
> INIT_VLC_SPARSE_STATIC would get the same len and sym and this code table
> as input:
> code: 0, 1, 2, 3, 4, 5, 6, 7
>
> INIT_VLC_SPARSE_STATIC rejects the "len" and "code" because the code
> of "2" will not fit into one bit.  Regardless of the fact that the desired
> output table is not a valid table according to VLC functions, that invalid
> table is what is needed.
>
> This goes back to how get_bits_var decodes the bit context.
> get_bits_var looks at three bits to get an index in the range of 0-7.
> But it may not skip all of those bits.  One or two of those bits may also
> be
> read by the final get_bits_long.
>
> code = show_bits(gb, 3);
> skip_bits(gb, bits_used[code]);
> get_bits_long(gb,...);
>
> The VLC functions to construct tables have validation in place that
> prevents
> the construction of the table needed for get_vlc2() to work with
> get_bits_var.
>
> So the only way I can find to use get_vlc2() is to not use any of the vlc.h
> initialization functions, and instead hard-code the tables to be used by
> get_vlc2() like this:
>
> VLCElem table[8] = { {4,1}, {4,1}, {4,1}, {4,1}, {8,2}, {8,2}, {16,3},
> {32,3} };
>
> Before I do that, I wanted to verify this would be acceptable. Would
> this be a use of get_vlc2() that could lead to issues in the future
> if the GET_VLC macro changed so that it would not skip fewer bits than the
> code length?
>
> What is your opinion on this?
>

Well, just keep that part as is currently, until someone else cleans it up.

Can probing in new demuxer be smarter than just decreasing score of another
demuxer?



>
> Thanks,
> -Roy
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-15 Thread Roy Funderburk


On 6/15/23 8:46 AM, Paul B Mahol wrote:
> get_vlc2 can be made for get_bits_var(), first table bits (that are still
> int and not uint8_t), the code that picks table index from which to take
> bits.
> 
> It is also possible to make it take both first index and rest of it and
> build bigger tables but that is very very advanced step for new
> contributors.
> 
> Use INIT_VLC_SPARSE_STATIC, there are myriad examples in libavcodec, one of
> them being imm4 decoder.
> 

I will change that table bits array to uint8_t.

I encountered an issue when trying to set up the VLC table with
INIT_VLC_SPARSE_STATIC.

The current get_bits_var:

static int get_bits_var(GetBitContext *gb, const VarBits *var_bits)
{
static const uint8_t bits_used[8] = { 1, 1, 1, 1, 2, 2, 3, 3 };
int code = show_bits(gb, 3); /* value range is [0, 7] */

skip_bits(gb, bits_used[code]);
if (var_bits->bits[code] == 0)
return 0;
return get_bits_long(gb, var_bits->bits[code]) + var_bits->add[code];
}

Changed to use get_vlc2 would be:

static int get_bits_var(GetBitContext *gb, const VarBits *var_bits)
{
int code = get_vlc2(, vlc.table, 3, 1);
if (var_bits->bits[code] == 0)
return 0;
return get_bits_long(gb, var_bits->bits[code]) + var_bits->add[code];
}

The "vlc.table" that INIT_VLC_SPARSE_STATIC needs to output is:

len: 1, 1, 1, 1, 2, 2, 3, 3
sym: 4, 4, 4, 4, 8, 8, 16, 32

INIT_VLC_SPARSE_STATIC would get the same len and sym and this code table as 
input:
code: 0, 1, 2, 3, 4, 5, 6, 7

INIT_VLC_SPARSE_STATIC rejects the "len" and "code" because the code
of "2" will not fit into one bit.  Regardless of the fact that the desired
output table is not a valid table according to VLC functions, that invalid
table is what is needed.

This goes back to how get_bits_var decodes the bit context.
get_bits_var looks at three bits to get an index in the range of 0-7.
But it may not skip all of those bits.  One or two of those bits may also be
read by the final get_bits_long.

code = show_bits(gb, 3);
skip_bits(gb, bits_used[code]);
get_bits_long(gb,...);

The VLC functions to construct tables have validation in place that prevents
the construction of the table needed for get_vlc2() to work with
get_bits_var.

So the only way I can find to use get_vlc2() is to not use any of the vlc.h
initialization functions, and instead hard-code the tables to be used by
get_vlc2() like this:

VLCElem table[8] = { {4,1}, {4,1}, {4,1}, {4,1}, {8,2}, {8,2}, {16,3}, {32,3} };

Before I do that, I wanted to verify this would be acceptable. Would
this be a use of get_vlc2() that could lead to issues in the future
if the GET_VLC macro changed so that it would not skip fewer bits than the
code length?

What is your opinion on this?

Thanks,
-Roy
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-15 Thread Paul B Mahol
On Wed, Jun 14, 2023 at 10:01 PM Roy Funderburk 
wrote:

> Hi,
>
> I updated the libavcodec patch per Paul Mahol's reviews:
>
> dtsuhd_common.c:496 get_bits_long instead of get_bits used for reading 36
> bits
>
> dtsuhd_common.c:224 get_bits_var changed to accept arrays in VarBits
> structure, allowing arrays with all values less than 256 to use uint8_t
> arrays.
>
> Also removed bitfields from structures.
>


get_vlc2 can be made for get_bits_var(), first table bits (that are still
int and not uint8_t), the code that picks table index from which to take
bits.

It is also possible to make it take both first index and rest of it and
build bigger tables but that is very very advanced step for new
contributors.

Use INIT_VLC_SPARSE_STATIC, there are myriad examples in libavcodec, one of
them being imm4 decoder.


>
> Regards,
> -Roy
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-14 Thread Roy Funderburk
Hi,

I updated the libavcodec patch per Paul Mahol's reviews:

dtsuhd_common.c:496 get_bits_long instead of get_bits used for reading 36 bits

dtsuhd_common.c:224 get_bits_var changed to accept arrays in VarBits structure, 
allowing arrays with all values less than 256 to use uint8_t arrays.

Also removed bitfields from structures.

Regards,
-Roy
--- Begin Message ---
Parsing of DTS-UHD input files per ETSI TS 102 114 is added
as parser for codec id AV_CODEC_ID_DTSUHD.

Signed-off-by: Roy Funderburk 
---
 libavcodec/Makefile|1 +
 libavcodec/codec_desc.c|7 +
 libavcodec/codec_id.h  |1 +
 libavcodec/dtsuhd_common.c | 1079 
 libavcodec/dtsuhd_common.h |   87 +++
 libavcodec/dtsuhd_parser.c |  141 +
 libavcodec/parsers.c   |1 +
 libavcodec/version.h   |2 +-
 8 files changed, 1318 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/dtsuhd_common.c
 create mode 100644 libavcodec/dtsuhd_common.h
 create mode 100644 libavcodec/dtsuhd_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2efab60d7d..0b49984902 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1164,6 +1164,7 @@ OBJS-$(CONFIG_DIRAC_PARSER)+= dirac_parser.o
 OBJS-$(CONFIG_DNXHD_PARSER)+= dnxhd_parser.o dnxhddata.o
 OBJS-$(CONFIG_DOLBY_E_PARSER)  += dolby_e_parser.o dolby_e_parse.o
 OBJS-$(CONFIG_DPX_PARSER)  += dpx_parser.o
+OBJS-$(CONFIG_DTSUHD_PARSER)   += dtsuhd_parser.o dtsuhd_common.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 3e31a1eed6..63dc939905 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3406,6 +3406,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("RKA (RK Audio)"),
 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY | 
AV_CODEC_PROP_LOSSLESS,
 },
+{
+.id= AV_CODEC_ID_DTSUHD,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "dtsuhd",
+.long_name = NULL_IF_CONFIG_SMALL("DTSUHD (DTS-UHD Audio Format)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index d23549d7e0..a5d580169b 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -542,6 +542,7 @@ enum AVCodecID {
 AV_CODEC_ID_FTR,
 AV_CODEC_ID_WAVARC,
 AV_CODEC_ID_RKA,
+AV_CODEC_ID_DTSUHD,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/dtsuhd_common.c b/libavcodec/dtsuhd_common.c
new file mode 100644
index 00..246dfacfac
--- /dev/null
+++ b/libavcodec/dtsuhd_common.c
@@ -0,0 +1,1079 @@
+/*
+ * DTS-UHD common audio frame parsing code
+ * Copyright (c) 2023 Xperi Corporation / DTS, Inc.
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Parse DTS-UHD audio frame headers, report frame sizes and configuration.
+ * Specification: ETSI TS 103 491 V1.2.1
+ */
+
+#include 
+
+#include "dtsuhd_common.h"
+#include "get_bits.h"
+#include "put_bits.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/crc.h"
+
+#define DTSUHD_ALLOC_INCREMENT 16
+#define DTSUHD_CHUNK_HEADER16
+#define DTSUHD_CRC_SEED0x
+#define DTSUHD_UDTS_BUFFER 32 // work buffer to construct 'udts' box
+
+enum RepType {
+REP_TYPE_CH_MASK_BASED,
+REP_TYPE_MTRX2D_CH_MASK_BASED,
+REP_TYPE_MTRX3D_CH_MASK_BASED,
+REP_TYPE_BINAURAL,
+REP_TYPE_AMBISONIC,
+REP_TYPE_AUDIO_TRACKS,
+REP_TYPE_3D_OBJECT_SINGLE_SRC_PER_WF,
+REP_TYPE_3D_MONO_OBJECT_SINGLE_SRC_PER_WF,
+};
+
+typedef struct MDObject {
+int started;  /* Object seen since last reset. */
+int pres_index;
+int rep_type;
+int ch_activity_mask;
+} MDObject;
+
+typedef struct MD01 {
+GetBitContext gb;
+MDObject object[257]; /* object id max value is 256 */
+int chunk_id;
+int object_list[256]; int 

Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-14 Thread Roy Funderburk


On 6/13/23 11:01 PM, Paul B Mahol wrote:
> On Wed, Jun 14, 2023 at 7:37 AM Paul B Mahol  wrote:
> Also there is no reason to use int for elements in tables when max value
> can be lower.
> Current table reading/handling code should be completely rewritten to use
> get_vlc2().
> And tables split so length of codes use uint8_t type.


I will split the tables into two arrays and make the first array uint8_t.

I was looking over the get_vlc2() function, and I don't believe it will be
able to replace the current dtsuhd_common.c's get_bits_var.

The current dtsuhd_common function and a sample table parameter:

static const int uhd_table[2][8] = {
// TABLE_BITS TABLE_ADD
{ 4, 4, 4, 4, 8, 8, 16, 32 }, { 0, 0, 0, 0, 16, 16, 272, 65808 } };
static int get_bits_var(GetBitContext *gb, const int uhd_table[2][8])
{
static const int bits_used[8] = { 1, 1, 1, 1, 2, 2, 3, 3 };
int code = show_bits(gb, 3); /* value range is [0, 7] */

skip_bits(gb, bits_used[code]);
if (uhd_table[TABLE_BITS][code] == 0)
return 0;
return get_bits_long(gb, uhd_table[TABLE_BITS][code]) + 
uhd_table[TABLE_ADD][code];
}


It peeks ahead 3 bits, and uses them to read the three 8 element tables: 
bits_used,
uhd_table[0], uhd_table[1].  Skips "bits_used" bits, reads "uhd_table[0]" bits 
and
adds to that value the value from "uhd_table[1]"

get_vlc2 uses the GET_VLC macro which goes like this:

#define GET_VLC(code, name, gb, table, bits, max_depth) \
do {\
int n, nb_bits; \
unsigned int index; \
\
index = SHOW_UBITS(name, gb, bits); \
code  = table[index].sym;   \
n = table[index].len;   \
\
if (max_depth > 1 && n < 0) {   \
...
nb_bits = -n;   \
\
index = SHOW_UBITS(name, gb, nb_bits) + code;   \
code  = table[index].sym;   \
n = table[index].len;   \
...
}   \
SKIP_BITS(name, gb, n); \


The end result from this function is "code".  It needs to be the result of
reading "uhd_table[0][x]" bits added to the value from "uhd_table[1][x]".
But, that only way to get to that value would be in the last read of
"index = SHOW_UBITS(name, gb, nb_bits) + code;"
And "index" is not returned from that macro.
Further, index has a maximum size of 32 bits, which is a problem for the next
line "code  = table[index].sym;".  That table would be 4Gigs, and we don't
even want the value from that table.

So that means we can't use the "if" block at all.

This means the best get_vlc2 could do is replace the "show_bits" and "skip_bits"
of the original dtsuhd get_bits_var function.  The last get_bits_long would
still be needed.

In that case, "table[index].len" would have to be from the table "bits_used"
and "table[index].sym would have to be from that table "uhd_table[0]".
get_vlc2() would return the bits to read for the call to get_bits_long.

But, when building the table using ff_init_vlc_from_lengths, there is this line
from that function in vlc.c:
code += 1U << (32 - len);
if (code > UINT32_MAX + 1ULL) {
av_log(logctx, AV_LOG_ERROR, "Overdetermined VLC tree\n");

"len" comes from the an input table to that function "bits_used[8]" and that
table has duplicate entries.  Specifically several values of "1".  And that
quickly causes the "overdetermined" error.  Looking over the other functions
in vlc.c, those do not look as if they would work well with the dtsuhd_common
tables either.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-14 Thread Paul B Mahol
On Wed, Jun 14, 2023 at 8:06 AM Paul B Mahol  wrote:

>
>
> On Wed, Jun 14, 2023 at 8:01 AM Paul B Mahol  wrote:
>
>>
>>
>> On Wed, Jun 14, 2023 at 7:37 AM Paul B Mahol  wrote:
>>
>>>
>>>
>>> On Wed, Jun 14, 2023 at 2:00 AM Roy Funderburk 
>>> wrote:
>>>

 On 6/13/23 11:35 AM, Paul B Mahol wrote:
 > Doing allocation in probe?
 > Probing should be very fast.

 In line 143 of the avformat patch, memory allocation is removed from
 the probe

 >>+int dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
 >>+DTSUHDFrameInfo *fi, DTSUHDDescriptorInfo *di)
 >>+{
 >>+gb = >gb;
 >>+init_get_bits(gb, data, data_bytes * 8);
 > init_get_bits8, and check return code.

 In line 986 of the avcodec patch, changed to using init_get_bits8 and
 added return code check.

 >>+fi->sync = h->is_sync_frame;
 >>+fi->frame_bytes = h->frame_bytes;
 >>+fi->sample_rate = h->sample_rate;
 >>+fi->sample_count = (h->frame_duration * fi->sample_rate)
 /(h->clock_rate * fraction);
 >>+fi->duration = (double)fi->sample_count / fi->sample_rate;
 >Please  no double  type.
 >Also make use of av_rescale.

 Around line 1108 of the avcodec patch, I found the duration was not
 needed and removed it.


 On 6/13/23 12:04 PM, Anton Khirnov wrote:
 > Also do note that sharing structs across libraries opens you to
 various
 > compatibility questions [2]. It might be easier to sidestep them by
 > having a function in libavcodec that accepts AVCodecParameters and
 fills
 > them according to the data, rather than pass codec-specific structs
 > between libavformat and libavcodec.

 In line 1061 of the avcodec patch, changed the function to:
   int av_dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
 AVCodecParameters *codecpar, uint8_t **udts, int *udts_size)



>>> Usually libavcodec code does use get_vlc2() for variable length codes,
>>> instead of
>>> usage of show_bits/skip_bits/get_bits.
>>>
>>>
>> Also there is no reason to use int for elements in tables when max value
>> can be lower.
>> Current table reading/handling code should be completely rewritten to use
>> get_vlc2().
>> And tables split so length of codes use uint8_t type.
>>
>
> In parse_stream_params() function, there is skip_bits(gb,
> 36*get_bits1(gb))
>
> but skip_bits can read usually max 25 bits.
> Use skip_bits_long().
>

Also please remove from structs ':1' suffix and similar if that is not
really required to have exactly single bit max usage signaled per item in
struct.


>
>
>
>>
>>>
>>>
>>>

 Thank you for reviewing this,
 -Roy___
 ffmpeg-devel mailing list
 ffmpeg-devel@ffmpeg.org
 https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

 To unsubscribe, visit link above, or email
 ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

>>>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-14 Thread Paul B Mahol
On Wed, Jun 14, 2023 at 8:01 AM Paul B Mahol  wrote:

>
>
> On Wed, Jun 14, 2023 at 7:37 AM Paul B Mahol  wrote:
>
>>
>>
>> On Wed, Jun 14, 2023 at 2:00 AM Roy Funderburk 
>> wrote:
>>
>>>
>>> On 6/13/23 11:35 AM, Paul B Mahol wrote:
>>> > Doing allocation in probe?
>>> > Probing should be very fast.
>>>
>>> In line 143 of the avformat patch, memory allocation is removed from the
>>> probe
>>>
>>> >>+int dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
>>> >>+DTSUHDFrameInfo *fi, DTSUHDDescriptorInfo *di)
>>> >>+{
>>> >>+gb = >gb;
>>> >>+init_get_bits(gb, data, data_bytes * 8);
>>> > init_get_bits8, and check return code.
>>>
>>> In line 986 of the avcodec patch, changed to using init_get_bits8 and
>>> added return code check.
>>>
>>> >>+fi->sync = h->is_sync_frame;
>>> >>+fi->frame_bytes = h->frame_bytes;
>>> >>+fi->sample_rate = h->sample_rate;
>>> >>+fi->sample_count = (h->frame_duration * fi->sample_rate)
>>> /(h->clock_rate * fraction);
>>> >>+fi->duration = (double)fi->sample_count / fi->sample_rate;
>>> >Please  no double  type.
>>> >Also make use of av_rescale.
>>>
>>> Around line 1108 of the avcodec patch, I found the duration was not
>>> needed and removed it.
>>>
>>>
>>> On 6/13/23 12:04 PM, Anton Khirnov wrote:
>>> > Also do note that sharing structs across libraries opens you to various
>>> > compatibility questions [2]. It might be easier to sidestep them by
>>> > having a function in libavcodec that accepts AVCodecParameters and
>>> fills
>>> > them according to the data, rather than pass codec-specific structs
>>> > between libavformat and libavcodec.
>>>
>>> In line 1061 of the avcodec patch, changed the function to:
>>>   int av_dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
>>> AVCodecParameters *codecpar, uint8_t **udts, int *udts_size)
>>>
>>>
>>>
>> Usually libavcodec code does use get_vlc2() for variable length codes,
>> instead of
>> usage of show_bits/skip_bits/get_bits.
>>
>>
> Also there is no reason to use int for elements in tables when max value
> can be lower.
> Current table reading/handling code should be completely rewritten to use
> get_vlc2().
> And tables split so length of codes use uint8_t type.
>

In parse_stream_params() function, there is skip_bits(gb, 36*get_bits1(gb))

but skip_bits can read usually max 25 bits.
Use skip_bits_long().



>
>>
>>
>>
>>>
>>> Thank you for reviewing this,
>>> -Roy___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>>
>>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-14 Thread Paul B Mahol
On Wed, Jun 14, 2023 at 7:37 AM Paul B Mahol  wrote:

>
>
> On Wed, Jun 14, 2023 at 2:00 AM Roy Funderburk 
> wrote:
>
>>
>> On 6/13/23 11:35 AM, Paul B Mahol wrote:
>> > Doing allocation in probe?
>> > Probing should be very fast.
>>
>> In line 143 of the avformat patch, memory allocation is removed from the
>> probe
>>
>> >>+int dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
>> >>+DTSUHDFrameInfo *fi, DTSUHDDescriptorInfo *di)
>> >>+{
>> >>+gb = >gb;
>> >>+init_get_bits(gb, data, data_bytes * 8);
>> > init_get_bits8, and check return code.
>>
>> In line 986 of the avcodec patch, changed to using init_get_bits8 and
>> added return code check.
>>
>> >>+fi->sync = h->is_sync_frame;
>> >>+fi->frame_bytes = h->frame_bytes;
>> >>+fi->sample_rate = h->sample_rate;
>> >>+fi->sample_count = (h->frame_duration * fi->sample_rate)
>> /(h->clock_rate * fraction);
>> >>+fi->duration = (double)fi->sample_count / fi->sample_rate;
>> >Please  no double  type.
>> >Also make use of av_rescale.
>>
>> Around line 1108 of the avcodec patch, I found the duration was not
>> needed and removed it.
>>
>>
>> On 6/13/23 12:04 PM, Anton Khirnov wrote:
>> > Also do note that sharing structs across libraries opens you to various
>> > compatibility questions [2]. It might be easier to sidestep them by
>> > having a function in libavcodec that accepts AVCodecParameters and fills
>> > them according to the data, rather than pass codec-specific structs
>> > between libavformat and libavcodec.
>>
>> In line 1061 of the avcodec patch, changed the function to:
>>   int av_dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
>> AVCodecParameters *codecpar, uint8_t **udts, int *udts_size)
>>
>>
>>
> Usually libavcodec code does use get_vlc2() for variable length codes,
> instead of
> usage of show_bits/skip_bits/get_bits.
>
>
Also there is no reason to use int for elements in tables when max value
can be lower.
Current table reading/handling code should be completely rewritten to use
get_vlc2().
And tables split so length of codes use uint8_t type.


>
>
>
>>
>> Thank you for reviewing this,
>> -Roy___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-13 Thread Paul B Mahol
On Wed, Jun 14, 2023 at 2:00 AM Roy Funderburk 
wrote:

>
> On 6/13/23 11:35 AM, Paul B Mahol wrote:
> > Doing allocation in probe?
> > Probing should be very fast.
>
> In line 143 of the avformat patch, memory allocation is removed from the
> probe
>
> >>+int dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
> >>+DTSUHDFrameInfo *fi, DTSUHDDescriptorInfo *di)
> >>+{
> >>+gb = >gb;
> >>+init_get_bits(gb, data, data_bytes * 8);
> > init_get_bits8, and check return code.
>
> In line 986 of the avcodec patch, changed to using init_get_bits8 and
> added return code check.
>
> >>+fi->sync = h->is_sync_frame;
> >>+fi->frame_bytes = h->frame_bytes;
> >>+fi->sample_rate = h->sample_rate;
> >>+fi->sample_count = (h->frame_duration * fi->sample_rate)
> /(h->clock_rate * fraction);
> >>+fi->duration = (double)fi->sample_count / fi->sample_rate;
> >Please  no double  type.
> >Also make use of av_rescale.
>
> Around line 1108 of the avcodec patch, I found the duration was not needed
> and removed it.
>
>
> On 6/13/23 12:04 PM, Anton Khirnov wrote:
> > Also do note that sharing structs across libraries opens you to various
> > compatibility questions [2]. It might be easier to sidestep them by
> > having a function in libavcodec that accepts AVCodecParameters and fills
> > them according to the data, rather than pass codec-specific structs
> > between libavformat and libavcodec.
>
> In line 1061 of the avcodec patch, changed the function to:
>   int av_dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
> AVCodecParameters *codecpar, uint8_t **udts, int *udts_size)
>
>
>
Usually libavcodec code does use get_vlc2() for variable length codes,
instead of
usage of show_bits/skip_bits/get_bits.




>
> Thank you for reviewing this,
> -Roy___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-13 Thread Roy Funderburk

On 6/13/23 11:35 AM, Paul B Mahol wrote:
> Doing allocation in probe?
> Probing should be very fast.

In line 143 of the avformat patch, memory allocation is removed from the probe

>>+int dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
>>+DTSUHDFrameInfo *fi, DTSUHDDescriptorInfo *di)
>>+{
>>+gb = >gb;
>>+init_get_bits(gb, data, data_bytes * 8);
> init_get_bits8, and check return code.

In line 986 of the avcodec patch, changed to using init_get_bits8 and added 
return code check.

>>+fi->sync = h->is_sync_frame;
>>+fi->frame_bytes = h->frame_bytes;
>>+fi->sample_rate = h->sample_rate;
>>+fi->sample_count = (h->frame_duration * fi->sample_rate) 
>>/(h->clock_rate * fraction);
>>+fi->duration = (double)fi->sample_count / fi->sample_rate;
>Please  no double  type.
>Also make use of av_rescale.

Around line 1108 of the avcodec patch, I found the duration was not needed and 
removed it.


On 6/13/23 12:04 PM, Anton Khirnov wrote:
> Also do note that sharing structs across libraries opens you to various
> compatibility questions [2]. It might be easier to sidestep them by
> having a function in libavcodec that accepts AVCodecParameters and fills
> them according to the data, rather than pass codec-specific structs
> between libavformat and libavcodec.

In line 1061 of the avcodec patch, changed the function to: 
  int av_dtsuhd_frame(DTSUHD *h, const uint8_t *data, size_t data_bytes,
AVCodecParameters *codecpar, uint8_t **udts, int *udts_size)



Thank you for reviewing this,
-Roy--- Begin Message ---
Parsing of DTS-UHD input files per ETSI TS 102 114 is added
as parser for codec id AV_CODEC_ID_DTSUHD.

Signed-off-by: Roy Funderburk 
---
 libavcodec/Makefile|1 +
 libavcodec/codec_desc.c|7 +
 libavcodec/codec_id.h  |1 +
 libavcodec/dtsuhd_common.c | 1075 
 libavcodec/dtsuhd_common.h |   87 +++
 libavcodec/dtsuhd_parser.c |  141 +
 libavcodec/parsers.c   |1 +
 libavcodec/version.h   |2 +-
 8 files changed, 1314 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/dtsuhd_common.c
 create mode 100644 libavcodec/dtsuhd_common.h
 create mode 100644 libavcodec/dtsuhd_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2efab60d7d..0b49984902 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1164,6 +1164,7 @@ OBJS-$(CONFIG_DIRAC_PARSER)+= dirac_parser.o
 OBJS-$(CONFIG_DNXHD_PARSER)+= dnxhd_parser.o dnxhddata.o
 OBJS-$(CONFIG_DOLBY_E_PARSER)  += dolby_e_parser.o dolby_e_parse.o
 OBJS-$(CONFIG_DPX_PARSER)  += dpx_parser.o
+OBJS-$(CONFIG_DTSUHD_PARSER)   += dtsuhd_parser.o dtsuhd_common.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 3e31a1eed6..63dc939905 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3406,6 +3406,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("RKA (RK Audio)"),
 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY | 
AV_CODEC_PROP_LOSSLESS,
 },
+{
+.id= AV_CODEC_ID_DTSUHD,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "dtsuhd",
+.long_name = NULL_IF_CONFIG_SMALL("DTSUHD (DTS-UHD Audio Format)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index d23549d7e0..a5d580169b 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -542,6 +542,7 @@ enum AVCodecID {
 AV_CODEC_ID_FTR,
 AV_CODEC_ID_WAVARC,
 AV_CODEC_ID_RKA,
+AV_CODEC_ID_DTSUHD,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/dtsuhd_common.c b/libavcodec/dtsuhd_common.c
new file mode 100644
index 00..0199219e87
--- /dev/null
+++ b/libavcodec/dtsuhd_common.c
@@ -0,0 +1,1075 @@
+/*
+ * DTS-UHD common audio frame parsing code
+ * Copyright (c) 2023 Xperi Corporation / DTS, Inc.
+ *
+ * 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 

Re: [FFmpeg-devel] [PATCH] avformat/avcodec: Add DTS-UHD demuxer and parser, movenc support.

2023-06-13 Thread Paul B Mahol
On Fri, Apr 14, 2023 at 6:01 PM Roy Funderburk 
wrote:

> Parsing and demuxing of DTS-UHD input files per ETSI TS 102 114 is added
> as demuxer "dtsuhd".  movenc supports DTS-UHD audio track.
>
> 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
>
> diff --git a/Changelog b/Changelog
> index a40f32c23f..f683b49bb2 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -3,6 +3,7 @@ releases are sorted from youngest to oldest.
>version :
>   - libaribcaption decoder
> +- DTS-UHD demuxer
>version 6.0:
>   - Radiance HDR image support
> diff --git a/configure b/configure
> index 033db7442d..557821ceef 100755
> --- a/configure
> +++ b/configure
> @@ -3425,6 +3425,7 @@ dash_demuxer_deps="libxml2"
>   dirac_demuxer_select="dirac_parser"
>   dts_demuxer_select="dca_parser"
>   dtshd_demuxer_select="dca_parser"
> +dtsuhd_demuxer_select="dtsuhd_parser"
>   dv_demuxer_select="dvprofile"
>   dv_muxer_select="dvprofile"
>   dxa_demuxer_select="riffdec"
> diff --git a/doc/general_contents.texi b/doc/general_contents.texi
> index 2eeebd847d..e1ba9c4597 100644
> --- a/doc/general_contents.texi
> +++ b/doc/general_contents.texi
> @@ -597,6 +597,7 @@ library:
>   @item raw DNxHD @tab X @tab X
>   @item raw DTS   @tab X @tab X
>   @item raw DTS-HD@tab   @tab X
> +@item raw DTS-UHD   @tab   @tab
>   @item raw E-AC-3@tab X @tab X
>   @item raw FLAC  @tab X @tab X
>   @item raw GSM   @tab   @tab X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index aa10fbfcf8..f57564e9eb 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1155,6 +1155,7 @@ OBJS-$(CONFIG_DIRAC_PARSER)+=
> dirac_parser.o
>   OBJS-$(CONFIG_DNXHD_PARSER)+= dnxhd_parser.o dnxhddata.o
>   OBJS-$(CONFIG_DOLBY_E_PARSER)  += dolby_e_parser.o
> dolby_e_parse.o
>   OBJS-$(CONFIG_DPX_PARSER)  += dpx_parser.o
> +OBJS-$(CONFIG_DTSUHD_PARSER)   += dtsuhd_parser.o dtsuhd_common.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 efdcb59bc9..a58315f46b 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -3369,6 +3369,13 @@ static const AVCodecDescriptor codec_descriptors[]
> = {
>   .long_name = NULL_IF_CONFIG_SMALL("RKA (RK Audio)"),
>   .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> AV_CODEC_PROP_LOSSLESS,
>   },
> +{
> +.id= AV_CODEC_ID_DTSUHD,
> +.type  = AVMEDIA_TYPE_AUDIO,
> +.name  = "dtsuhd",
> +.long_name = NULL_IF_CONFIG_SMALL("DTSUHD (DTS-UHD Audio
> Format)"),
> +.props = AV_CODEC_PROP_LOSSY,
> +},
>/* subtitle codecs */
>   {
> diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
> index 64df9699f4..6d8b145ee3 100644
> --- a/libavcodec/codec_id.h
> +++ b/libavcodec/codec_id.h
> @@ -538,6 +538,7 @@ enum AVCodecID {
>   AV_CODEC_ID_FTR,
>   AV_CODEC_ID_WAVARC,
>   AV_CODEC_ID_RKA,
> +AV_CODEC_ID_DTSUHD,
>/* subtitle codecs */
>   AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID
> pointing at the start of subtitle codecs.
> diff --git a/libavcodec/dtsuhd_common.c b/libavcodec/dtsuhd_common.c
> new file mode 100644
> index 00..110cb0c371
> --- /dev/null
> +++ b/libavcodec/dtsuhd_common.c
> @@ -0,0 +1,991 @@
> +/*
> + * DTS-UHD common audio frame parsing code
> + * Copyright (c) 2023 Xperi Corporation / DTS, Inc.
> + *
> + * 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