Re: [libav-devel] [PATCH 2/3] dca: Support for XLL (lossless extension)

2015-03-16 Thread James Almer
On 16/03/15 5:00 AM, Niels Möller wrote:
 James Almer jamr...@gmail.com writes:
 
 Valgrind is complaining about this code (Conditional jump or move
 depends on uninitialised
 value error), as seen here
 https://fate.libav.org/x86_64-linux-gcc-valgrind/20150316044429

 Zero initializing the param_state[16] struct from
 ff_dca_xll_decode_audio() with { { 0 } }
 fixes it, but it's possible it may instead be hiding the real bug in the 
 code.
 
 If I read the code correctly, it looks like params-pancABIT0 is read
 from the stream for the first segment (seg == 0) only, and used for
 decoding params-nSamplePart0 samples. And that the latter value ought
 to be always zero when seg != 0.
 
 The logic is a bit complex, and since it many months since I wrote that
 code, I don't quite remember how it is supposed to work... But I suspect
 the problem is that the value, which is a loop invariant, is read and
 tested up-front, even in the case that the loop using it runs for zero
 iterations.
 
 Can you test if the below patch solves the problem? It reads
 params-pancABIT0 only when it's going to be used.
 
 Regards,
 /Niels
 
 diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
 index 0c32d6e..5a558b8 100644
 --- a/libavcodec/dca_xll.c
 +++ b/libavcodec/dca_xll.c
 @@ -514,8 +514,8 @@ int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame)
  }
  for (i = 0; i  chset-channels; i++) {
  int param_index = params-seg_type ? 0 : i;
 -int bits= params-pancABIT0[param_index];
  int part0   = params-nSamplPart0[param_index];
 +int bits= part0 ? params-pancABIT0[param_index] : 0;
  int *sample_buf = s-xll_sample_buf +
(in_channel + i) * s-xll_smpl_in_seg;

Yes, it fixes it on my end.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/3] dca: Support for XLL (lossless extension)

2015-03-16 Thread Niels Möller
James Almer jamr...@gmail.com writes:

 Valgrind is complaining about this code (Conditional jump or move
 depends on uninitialised
 value error), as seen here
 https://fate.libav.org/x86_64-linux-gcc-valgrind/20150316044429

 Zero initializing the param_state[16] struct from
 ff_dca_xll_decode_audio() with { { 0 } }
 fixes it, but it's possible it may instead be hiding the real bug in the 
 code.

If I read the code correctly, it looks like params-pancABIT0 is read
from the stream for the first segment (seg == 0) only, and used for
decoding params-nSamplePart0 samples. And that the latter value ought
to be always zero when seg != 0.

The logic is a bit complex, and since it many months since I wrote that
code, I don't quite remember how it is supposed to work... But I suspect
the problem is that the value, which is a loop invariant, is read and
tested up-front, even in the case that the loop using it runs for zero
iterations.

Can you test if the below patch solves the problem? It reads
params-pancABIT0 only when it's going to be used.

Regards,
/Niels

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 0c32d6e..5a558b8 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -514,8 +514,8 @@ int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame)
 }
 for (i = 0; i  chset-channels; i++) {
 int param_index = params-seg_type ? 0 : i;
-int bits= params-pancABIT0[param_index];
 int part0   = params-nSamplPart0[param_index];
+int bits= part0 ? params-pancABIT0[param_index] : 0;
 int *sample_buf = s-xll_sample_buf +
   (in_channel + i) * s-xll_smpl_in_seg;
 


-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/3] dca: Support for XLL (lossless extension)

2015-03-15 Thread James Almer
On 13/03/15 12:24 PM, Luca Barbato wrote:
 On 13/03/15 16:17, Diego Biurrun wrote:
 From: Niels Möller ni...@lysator.liu.se

 ---

 Changes since last round:

 - XLL disabled by default.
 - Return error on too many downmix coefficients

 This has survived Oracle, so it's good to go IMO and will hit the
 tree very soon, barring last minute comments/objections.

 
 Fine for me.
 
 lu

Valgrind is complaining about this code (Conditional jump or move depends on 
uninitialised 
value error), as seen here 
https://fate.libav.org/x86_64-linux-gcc-valgrind/20150316044429

Zero initializing the param_state[16] struct from ff_dca_xll_decode_audio() 
with { { 0 } } 
fixes it, but it's possible it may instead be hiding the real bug in the code.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 2/3] dca: Support for XLL (lossless extension)

2015-03-13 Thread Diego Biurrun
From: Niels Möller ni...@lysator.liu.se

---

Changes since last round:

- XLL disabled by default.
- Return error on too many downmix coefficients

This has survived Oracle, so it's good to go IMO and will hit the
tree very soon, barring last minute comments/objections.

 Changelog |   1 +
 doc/general.texi  |   1 +
 libavcodec/Makefile   |   2 +-
 libavcodec/dca.h  | 101 ++-
 libavcodec/dca_exss.c |  57 +++-
 libavcodec/dca_xll.c  | 747 ++
 libavcodec/dcadata.c  | 630 +-
 libavcodec/dcadata.h  |  10 +-
 libavcodec/dcadec.c   | 199 --
 libavcodec/version.h  |   2 +-
 10 files changed, 1718 insertions(+), 32 deletions(-)
 create mode 100644 libavcodec/dca_xll.c

diff --git a/Changelog b/Changelog
index 31a550d..0d913a4 100644
--- a/Changelog
+++ b/Changelog
@@ -22,6 +22,7 @@ version next:
 - Canopus HQX decoder
 - RTP depacketization of T.140 text (RFC 4103)
 - VP9 RTP payload format (draft 0) experimental depacketizer
+- DTS lossless extension (XLL) decoding (not lossless, disabled by default)
 
 
 version 11:
diff --git a/doc/general.texi b/doc/general.texi
index 21e5fe8..008b7e1 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -827,6 +827,7 @@ following image formats are supported:
 @item COOK   @tab @tab  X
 @tab All versions except 5.1 are supported.
 @item DCA (DTS Coherent Acoustics)  @tab @tab  X
+@tab XCh and XLL extensions supported
 @item DPCM id RoQ@tab  X  @tab  X
 @tab Used in Quake III, Jedi Knight 2, other computer games.
 @item DPCM Interplay @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1c50f99..65dc3f3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -161,7 +161,7 @@ OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o
 OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o
 OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadsp.o  \
   dcadata.o dca_exss.o \
-  synth_filter.o
+  dca_xll.o synth_filter.o
 OBJS-$(CONFIG_DFA_DECODER) += dfa.o
 OBJS-$(CONFIG_DNXHD_DECODER)   += dnxhddec.o dnxhddata.o
 OBJS-$(CONFIG_DNXHD_ENCODER)   += dnxhdenc.o dnxhddata.o
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index 54643c9..845cd5d 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -42,6 +42,21 @@
 #define DCA_BLOCKS_MAX(16)
 #define DCA_LFE_MAX(3)
 
+#define DCA_PRIM_CHANNELS_MAX  (7)
+#define DCA_ABITS_MAX (32)  /* Should be 28 */
+#define DCA_SUBSUBFRAMES_MAX   (4)
+#define DCA_SUBFRAMES_MAX (16)
+#define DCA_BLOCKS_MAX(16)
+#define DCA_LFE_MAX(3)
+#define DCA_XLL_FBANDS_MAX (4)
+#define DCA_XLL_SEGMENTS_MAX  (16)
+#define DCA_XLL_CHSETS_MAX(16)
+#define DCA_XLL_CHANNELS_MAX  (16)
+#define DCA_XLL_AORDER_MAX(15)
+
+/* Arbitrary limit; not sure what the maximum really is, but much larger. */
+#define DCA_XLL_DMIX_NCOEFFS_MAX (18)
+
 #define DCA_MAX_FRAME_SIZE   16384
 #define DCA_MAX_EXSS_HEADER_SIZE  4096
 
@@ -60,6 +75,61 @@ enum DCAExtensionMask {
 DCA_EXT_EXSS_XLL   = 0x200, /// lossless extension in ExSS
 };
 
+typedef struct XllChSetSubHeader {
+int channels;   /// number of channels in channel set, at 
most 16
+int residual_encode;/// residual channel encoding
+int bit_resolution; /// input sample bit-width
+int bit_width;  /// original input sample bit-width
+int sampling_frequency; /// sampling frequency
+int samp_freq_interp;   /// sampling frequency interpolation 
multiplier
+int replacement_set;/// replacement channel set group
+int active_replace_set; /// current channel set is active channel set
+int primary_ch_set;
+int downmix_coeff_code_embedded;
+int downmix_embedded;
+int downmix_type;
+int hier_chset; /// hierarchical channel set
+int downmix_ncoeffs;
+int downmix_coeffs[DCA_XLL_DMIX_NCOEFFS_MAX];
+int ch_mask_enabled;
+int ch_mask;
+int mapping_coeffs_present;
+int num_freq_bands;
+
+/* m_nOrigChanOrder */
+uint8_t orig_chan_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+uint8_t orig_chan_order_inv[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+/* Coefficients for channel pairs (at most 8), m_anPWChPairsCoeffs */
+int8_t pw_ch_pairs_coeffs[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX/2];
+/* m_nCurrHighestLPCOrder */
+uint8_t adapt_order_max[DCA_XLL_FBANDS_MAX];
+/* m_pnAdaptPredOrder */
+uint8_t adapt_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+/* m_pnFixedPredOrder */
+uint8_t fixed_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+/* m_pnLPCReflCoeffsQInd, unsigned version */
+uint8_t 

Re: [libav-devel] [PATCH 2/3] dca: Support for XLL (lossless extension)

2015-03-13 Thread Luca Barbato

On 13/03/15 16:17, Diego Biurrun wrote:

From: Niels Möller ni...@lysator.liu.se

---

Changes since last round:

- XLL disabled by default.
- Return error on too many downmix coefficients

This has survived Oracle, so it's good to go IMO and will hit the
tree very soon, barring last minute comments/objections.



Fine for me.

lu

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

Re: [libav-devel] [PATCH 2/3] dca: Support for XLL (lossless extension)

2015-02-19 Thread Vittorio Giovara
On Wed, Feb 18, 2015 at 6:21 PM, Diego Biurrun di...@biurrun.de wrote:
 From: Niels Möller ni...@lysator.liu.se

 Cleanup by Diego Biurrun.

 Signed-off-by: Diego Biurrun di...@biurrun.de
 ---

 Not quite lossless yet ...

  libavcodec/dca.h  | 102 +-
  libavcodec/dca_exss.c |  56 ++-
  libavcodec/dcadata.c  | 656 ++-
  libavcodec/dcadata.h  |   5 +
  libavcodec/dcadec.c   | 926 
 --
  5 files changed, 1717 insertions(+), 28 deletions(-)


No DCA expert, just reporting that Coverity didn't find anything on this code.
I'd add Changelog, docs and version bump.
-- 
Vittorio
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 2/3] dca: Support for XLL (lossless extension)

2015-02-18 Thread Diego Biurrun
From: Niels Möller ni...@lysator.liu.se

Cleanup by Diego Biurrun.

Signed-off-by: Diego Biurrun di...@biurrun.de
---

Not quite lossless yet ...

 libavcodec/dca.h  | 102 +-
 libavcodec/dca_exss.c |  56 ++-
 libavcodec/dcadata.c  | 656 ++-
 libavcodec/dcadata.h  |   5 +
 libavcodec/dcadec.c   | 926 --
 5 files changed, 1717 insertions(+), 28 deletions(-)

diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index e3ec5ca..6f33b29 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -51,6 +51,21 @@
 #define DCA_BLOCKS_MAX(16)
 #define DCA_LFE_MAX(3)
 
+#define DCA_PRIM_CHANNELS_MAX  (7)
+#define DCA_ABITS_MAX (32)  /* Should be 28 */
+#define DCA_SUBSUBFRAMES_MAX   (4)
+#define DCA_SUBFRAMES_MAX (16)
+#define DCA_BLOCKS_MAX(16)
+#define DCA_LFE_MAX(3)
+#define DCA_XLL_FBANDS_MAX (4)
+#define DCA_XLL_SEGMENTS_MAX  (16)
+#define DCA_XLL_CHSETS_MAX(16)
+#define DCA_XLL_CHANNELS_MAX  (16)
+#define DCA_XLL_AORDER_MAX(15)
+
+/* Arbitrary limit; not sure what the maximum really is, but much larger. */
+#define DCA_XLL_DMIX_NCOEFFS_MAX (18)
+
 #define DCA_MAX_FRAME_SIZE   16384
 #define DCA_MAX_EXSS_HEADER_SIZE  4096
 
@@ -69,6 +84,61 @@ enum DCAExtensionMask {
 DCA_EXT_EXSS_XLL   = 0x200, /// lossless extension in ExSS
 };
 
+typedef struct XllChSetSubHeader {
+int channels;   /// number of channels in channel set, at 
most 16
+int residual_encode;/// residual channel encoding
+int bit_resolution; /// input sample bit-width
+int bit_width;  /// original input sample bit-width
+int sampling_frequency; /// sampling frequency
+int fs_interpolate; /// sampling frequency interpolation 
multiplier
+int replacement_set;/// replacement channel set group
+int active_replace_set; /// current channel set is active channel set
+int primary_ch_set;
+int downmix_coeff_code_embedded;
+int downmix_embedded;
+int downmix_type;
+int hier_chset;
+int downmix_ncoeffs;
+int downmix_coeffs[DCA_XLL_DMIX_NCOEFFS_MAX];
+int ch_mask_enabled;
+int ch_mask;
+int mapping_coeffs_present;
+int num_freq_bands;
+
+/* m_nOrigChanOrder */
+uint8_t orig_chan_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+uint8_t orig_chan_order_inv[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+/* Coefficients for channel pairs (at most 8), m_anPWChPairsCoeffs */
+int8_t pw_ch_pairs_coeffs[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX/2];
+/* m_nCurrHighestLPCOrder */
+uint8_t adapt_order_max[DCA_XLL_FBANDS_MAX];
+/* m_pnAdaptPredOrder */
+uint8_t adapt_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+/* m_pnFixedPredOrder */
+uint8_t fixed_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+/* m_pnLPCReflCoeffsQInd, unsigned version */
+uint8_t lpc_refl_coeffs_q_ind[DCA_XLL_FBANDS_MAX]
+ [DCA_XLL_CHANNELS_MAX][DCA_XLL_AORDER_MAX];
+
+int lsb_fsize[DCA_XLL_FBANDS_MAX];
+int8_t scalable_lsbs[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+int8_t bit_width_adj_per_ch[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
+} XllChSetSubHeader;
+
+typedef struct XllNavi {
+GetBitContext gb;  // Context for parsing the data segments
+unsigned band_size[DCA_XLL_FBANDS_MAX];
+unsigned segment_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX];
+unsigned 
chset_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX][DCA_XLL_CHSETS_MAX];
+} XllNavi;
+
+typedef struct QMF64_table {
+float dct4_coeff[32][32];
+float dct2_coeff[32][32];
+float rcos[32];
+float rsin[32];
+} QMF64_table;
+
 typedef struct DCAContext {
 AVClass *class; /// class for AVOptions
 AVCodecContext *avctx;
@@ -141,8 +211,10 @@ typedef struct DCAContext {
 
 /* Subband samples history (for ADPCM) */
 DECLARE_ALIGNED(16, float, 
subband_samples_hist)[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
-DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512];
-DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32];
+/* Half size is sufficient for core decoding, but for 96 kHz data
+ * we need qmf with 64 subbands and 1024 samples. */
+DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][1024];
+DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][64];
 int hist_index[DCA_PRIM_CHANNELS_MAX];
 DECLARE_ALIGNED(32, float, raXin)[32];
 
@@ -164,12 +236,31 @@ typedef struct DCAContext {
 int current_subsubframe;
 
 int core_ext_mask;  /// present extensions in the core substream
+int exss_ext_mask;  //   Non-core extensions
 
 /* XCh extension information */
 int xch_present;/// XCh extension present and valid
 int xch_base_channel;   /// index of first