Re: [FFmpeg-devel] [PATCH] avcodec/dca: return standard error codes in avpriv_dca_parse_core_frame_header()

2017-11-01 Thread foo86
On Tue, Oct 31, 2017 at 05:27:35PM -0300, James Almer wrote:
> This prevents making the DCAParseError enum part of the ABI.
> 
> Signed-off-by: James Almer 
> ---
> Now actually paying attention to -Wempty-body warnings.
> 
>  libavcodec/dca.c | 11 ---
>  libavcodec/dca.h | 12 ++--
>  2 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/dca.c b/libavcodec/dca.c
> index 942fe6c3c9..a0729e61ab 100644
> --- a/libavcodec/dca.c
> +++ b/libavcodec/dca.c
> @@ -149,9 +149,14 @@ int ff_dca_parse_core_frame_header(DCACoreFrameHeader 
> *h, GetBitContext *gb)
>  int avpriv_dca_parse_core_frame_header(DCACoreFrameHeader *h, const uint8_t 
> *buf, int size)
>  {
>  GetBitContext gb;
> +int ret;
>  
> -if (init_get_bits8(, buf, size) < 0)
> -return DCA_PARSE_ERROR_INVALIDDATA;
> +ret = init_get_bits8(, buf, size);
> +if (ret < 0)
> +return ret;
>  
> -return ff_dca_parse_core_frame_header(h, );
> +if (ff_dca_parse_core_frame_header(h, ) < 0)
> +return AVERROR_INVALIDDATA;
> +
> +return 0;
>  }
> diff --git a/libavcodec/dca.h b/libavcodec/dca.h
> index c70598af92..b05e5f896e 100644
> --- a/libavcodec/dca.h
> +++ b/libavcodec/dca.h
> @@ -46,7 +46,6 @@ enum DCAParseError {
>  DCA_PARSE_ERROR_RESERVED_BIT= -7,
>  DCA_PARSE_ERROR_LFE_FLAG= -8,
>  DCA_PARSE_ERROR_PCM_RES = -9,
> -DCA_PARSE_ERROR_INVALIDDATA = -10,
>  };
>  
>  typedef struct DCACoreFrameHeader {
> @@ -211,10 +210,19 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, 
> int src_size, uint8_t *dst,
>  
>  /**
>   * Parse and validate core frame header
> - * @return 0 on success, negative DCA_PARSE_ERROR_ code on failure
> + * @param[out] hPointer to struct where header info is written.
> + * @param[in]  buf  Pointer to the data buffer
> + * @param[in]  size Size of the data buffer
> + * @return 0 on success, negative AVERROR code on failure
>   */
>  int avpriv_dca_parse_core_frame_header(DCACoreFrameHeader *h, const uint8_t 
> *buf, int size);
>  
> +/**
> + * Parse and validate core frame header
> + * @param[out] h   Pointer to struct where header info is written.
> + * @param[in]  gbc BitContext containing the first 54 bits of the frame.

Should be "the first 120 bits".

> + * @return 0 on success, negative DCA_PARSE_ERROR_ code on failure
> + */
>  int ff_dca_parse_core_frame_header(DCACoreFrameHeader *h, GetBitContext *gb);
>  
>  #endif /* AVCODEC_DCA_H */

Patch otherwise OK.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] coverage: filter /usr/include*, not entire /usr*

2017-07-31 Thread foo86
On Mon, Jul 31, 2017 at 11:06:01PM +0200, Nicolas George wrote:
> Le tridi 13 thermidor, an CCXXV, foo86 a écrit :
> > /usr* filters all sources when building in /usr/src, which is probably
> > not intended.
> 
> This is leaving /usr/local/include, and many less known directories,
> like compiler-specific includes.

I see. Consider this patch withdrawn then.

> 
> Regards,
> 
> -- 
>   Nicolas George
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] fate: add more DCA tests

2017-07-31 Thread foo86
On Mon, Jul 31, 2017 at 05:14:01PM -0400, Ronald S. Bultje wrote:
> Hi,
> 
> On Mon, Jul 31, 2017 at 4:46 PM, foo86 <fooba...@gmail.com> wrote:
> 
> > Oops, meant to include this comment in previous email:
> >
> > Improves code coverage:
> > old%new%
> > dca_core76.581.3
> > dca_exss56.565.6
> > dca_lbr  2.280.5
> > dca_parser  86.298.6
> > dca_xll 81.287.2
> > dcadec  75.083.0
> > dcadsp  64.083.8
> >
> > Samples are here: https://0x0.st/key.xz
> 
> 
> Is the remainder error handling? Or is a subset of features untested? (If
> so, do you know which?)

This is mostly error handling, but there are some untested features
which are either never used (mixing metadata in EXSS) or very rare (5.1
LBR).

> 
> Nice work!
> 
> Ronald
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] fate: add more DCA tests

2017-07-31 Thread foo86
On Mon, Jul 31, 2017 at 11:48:09PM +0200, Michael Niedermayer wrote:
> On Mon, Jul 31, 2017 at 11:46:33PM +0300, foo86 wrote:
> > Oops, meant to include this comment in previous email:
> > 
> > Improves code coverage:
> > old%new%
> > dca_core76.581.3
> > dca_exss56.565.6
> > dca_lbr  2.280.5
> > dca_parser  86.298.6
> > dca_xll 81.287.2
> > dcadec  75.083.0
> > dcadsp  64.083.8
> > 
> 
> great
> 
> 
> > Samples are here: https://0x0.st/key.xz
> 
> am i correct in assuming that this cannot be made smaller easily ?
> 
> if so ill upload the files
> 
> thx

I think size of some files can be reduced, so if space is of concern,
please don't upload them yet.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] fate: add more DCA tests

2017-07-31 Thread foo86
On Mon, Jul 31, 2017 at 06:50:44PM -0300, James Almer wrote:
> On 7/31/2017 5:33 PM, foo86 wrote:
> > ---
> >  tests/fate/dca.mak   |  36 ++
> >  tests/ref/fate/dca-core-14be |   1 +
> >  tests/ref/fate/dca-core-14le |   1 +
> >  tests/ref/fate/dca-core-16be |   1 +
> >  tests/ref/fate/dca-core-16le |   1 +
> >  tests/ref/fate/dca-core-dmix |   1 +
> >  tests/ref/fate/dca-core-size |   1 +
> >  tests/ref/fate/dca-core-x96  |   1 +
> >  tests/ref/fate/dca-core-xch  |   1 +
> >  tests/ref/fate/dca-core-xxch |   1 +
> >  tests/ref/fate/dca-xll-ltrt  |   1 +
> >  tests/ref/fate/dca-xll-pbr   | 836 
> > +++
> >  tests/ref/fate/dca-xll-read  | 510 ++
> >  tests/ref/fate/dca-xll-sync  | 810 
> > +
> >  14 files changed, 2202 insertions(+)
> >  create mode 100644 tests/ref/fate/dca-core-14be
> >  create mode 100644 tests/ref/fate/dca-core-14le
> >  create mode 100644 tests/ref/fate/dca-core-16be
> >  create mode 100644 tests/ref/fate/dca-core-16le
> >  create mode 100644 tests/ref/fate/dca-core-dmix
> >  create mode 100644 tests/ref/fate/dca-core-size
> >  create mode 100644 tests/ref/fate/dca-core-x96
> >  create mode 100644 tests/ref/fate/dca-core-xch
> >  create mode 100644 tests/ref/fate/dca-core-xxch
> >  create mode 100644 tests/ref/fate/dca-xll-ltrt
> >  create mode 100644 tests/ref/fate/dca-xll-pbr
> >  create mode 100644 tests/ref/fate/dca-xll-read
> >  create mode 100644 tests/ref/fate/dca-xll-sync
> > 
> > diff --git a/tests/fate/dca.mak b/tests/fate/dca.mak
> > index b1681c6b59..563b83695f 100644
> > --- a/tests/fate/dca.mak
> > +++ b/tests/fate/dca.mak
> > @@ -67,9 +67,45 @@ fate-dca-core: CMD = pcm -i $(TARGET_SAMPLES)/dts/dts.ts
> >  fate-dca-core: CMP = oneoff
> >  fate-dca-core: REF = $(SAMPLES)/dts/dts.pcm
> >  
> > +# lossy fixed point tests
> > +DCA_FIXED_POINT = dca-core-14be dca-core-14le dca-core-16be dca-core-16le 
> > dca-core-size dca-core-x96 dca-core-xch dca-core-xxch
> > +
> > +define FATE_DCA_FIXED_POINT
> > +FATE_DCA-$(call DEMDEC, DTS, DCA) += fate-$(1)
> > +fate-$(1): CMD = md5 -flags +bitexact -i $(TARGET_SAMPLES)/dts/$(1) -f 
> > s24le
> > +endef
> > +
> > +$(foreach N,$(DCA_FIXED_POINT),$(eval $(call FATE_DCA_FIXED_POINT,$(N
> > +
> > +# lossy fixed point downmix test
> > +FATE_DCA-$(call DEMDEC, DTS, DCA) += fate-dca-core-dmix
> > +fate-dca-core-dmix: CMD = md5 -flags +bitexact -request_channel_layout 0x3 
> > -i $(TARGET_SAMPLES)/dts/dca-core-xxch -f s24le
> > +
> >  FATE_DCA-$(call DEMDEC, DTS, DCA) += fate-dca-xll
> >  fate-dca-xll: CMD = md5 -i 
> > $(TARGET_SAMPLES)/dts/master_audio_7.1_24bit.dts -f s24le
> >  
> > +FATE_DCA-$(call DEMDEC, DTS, DCA) += fate-dca-xll-ltrt
> > +fate-dca-xll-ltrt: CMD = md5 -err_detect crccheck -i 
> > $(TARGET_SAMPLES)/dts/dca-xll-ltrt -f s16le
> 
> Any reason why these are using md5 instead of framemd5?

To save space, because I didn't expect individual frame checksums to be
interesting in these tests.

> > +
> > +FATE_DCA-$(call DEMDEC, DTS, DCA) += fate-dca-xll-pbr
> > +fate-dca-xll-pbr: CMD = framemd5 -err_detect crccheck -i 
> > $(TARGET_SAMPLES)/dts/dca-xll-pbr -c:a pcm_s16le
> > +
> > +FATE_DCA-$(call DEMDEC, DTS, DCA) += fate-dca-xll-read
> > +fate-dca-xll-read: CMD = framemd5 -err_detect crccheck -i 
> > $(TARGET_SAMPLES)/dts/dca-xll-read -c:a pcm_s24le
> > +
> > +FATE_DCA-$(call DEMDEC, DTS, DCA) += fate-dca-xll-sync
> > +fate-dca-xll-sync: CMD = framemd5 -err_detect crccheck -i 
> > $(TARGET_SAMPLES)/dts/dca-xll-sync -c:a pcm_s24le
> 
> Can you limit these to only a bunch of audio frames, the minimum amount
> necessary to get the intended code coverage, in order to avoid big
> samples and ref files with hundreds of lines? Also because calculating
> md5 is expensive.
> Notice how the first tests added using your samples (dcadec-suite
> folder) are all like six frames each.

fate-dca-xll-read test can be possibly reduced to a few frames, but -pbr
and -sync tests cannot (these need to encompass entire bitrate-managed
section of audio track, which can be quite lengthy). I can change those
to md5 if size of reference files is of concern.

> Also, the naming scheme is different and you're placing them outside of
> the dcadec-suite folder. But that's not as important as the above.

These files are not part of the original dcadec test suite, therefore
different naming scheme. How do you prefer them to be named?

> > +
> > +FA

Re: [FFmpeg-devel] [PATCH 1/2] fate: add more DCA tests

2017-07-31 Thread foo86
Oops, meant to include this comment in previous email:

Improves code coverage:
old%new%
dca_core76.581.3
dca_exss56.565.6
dca_lbr  2.280.5
dca_parser  86.298.6
dca_xll 81.287.2
dcadec  75.083.0
dcadsp  64.083.8

Samples are here: https://0x0.st/key.xz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] fate: add Dolby E test

2017-07-31 Thread foo86
---

Samples are here: https://0x0.st/ket.xz

 tests/fate/audio.mak | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tests/fate/audio.mak b/tests/fate/audio.mak
index 40c4ca7b75..4fab472f90 100644
--- a/tests/fate/audio.mak
+++ b/tests/fate/audio.mak
@@ -19,6 +19,11 @@ fate-bmv-audio: CMD = framecrc -i 
$(TARGET_SAMPLES)/bmv/SURFING-partial.BMV -vn
 FATE_SAMPLES_AUDIO-$(call DEMDEC, DSICIN, DSICINAUDIO) += 
fate-delphine-cin-audio
 fate-delphine-cin-audio: CMD = framecrc -i 
$(TARGET_SAMPLES)/delphine-cin/LOGO-partial.CIN -vn
 
+FATE_SAMPLES_AUDIO-$(call DEMDEC, S337M, DOLBY_E) += fate-dolby-e
+fate-dolby-e: CMD = pcm -i $(TARGET_SAMPLES)/dolby_e/16-11
+fate-dolby-e: CMP = oneoff
+fate-dolby-e: REF = $(SAMPLES)/dolby_e/16-11.pcm
+
 FATE_SAMPLES_AUDIO-$(call DEMDEC, DSS, DSS_SP) += fate-dss-lp fate-dss-sp
 fate-dss-lp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/lp.dss -frames 30
 fate-dss-sp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/sp.dss -frames 30
-- 
2.11.0

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


[FFmpeg-devel] [PATCH] coverage: filter /usr/include*, not entire /usr*

2017-07-31 Thread foo86
/usr* filters all sources when building in /usr/src, which is probably
not intended.
---
 tests/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile
index ab83ae855d..2c67095052 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -228,7 +228,7 @@ coverage.info: TAG = LCOV
 coverage.info:
$(M)lcov -q -d $(CURDIR) -b $(patsubst src%,./,$(SRC_LINK)) --capture | 
\
sed "s,$(CURDIR)/\./,$(CURDIR)/," > $@.in
-   $(M)lcov -q --remove $@.in "/usr*" > $@
+   $(M)lcov -q --remove $@.in "/usr/include*" > $@
$(Q)$(RM) $@.in
 
 lcov:  TAG = GENHTML
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH 3/3] avformat/s337m: fix potentially undefined pointer arithmetic

2017-07-26 Thread foo86
On Mon, Jul 24, 2017 at 03:27:06PM +0300, foo86 wrote:
> 
> Use integer position instead of pointer for loop variable. Also only
> skip header fields after header has been fully validated.
> ---
>  libavformat/s337m.c | 20 ++--
>  1 file changed, 10 insertions(+), 10 deletions(-)

Patchset pushed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/dcaenc: fix memory leaks on init failure

2017-07-24 Thread foo86
---
 libavcodec/dcaenc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 37095674f5..1740c16432 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -145,8 +145,8 @@ static int subband_bufer_alloc(DCAEncContext *c)
 
 static void subband_bufer_free(DCAEncContext *c)
 {
-int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
-av_freep();
+if (c->subband[0][0])
+av_free(c->subband[0][0] - DCA_ADPCM_COEFFS);
 }
 
 static int encode_init(AVCodecContext *avctx)
@@ -1298,4 +1298,5 @@ AVCodec ff_dca_encoder = {
   0 },
 .defaults  = defaults,
 .priv_class= _class,
+.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 1/2] avcodec/dcaadpcm: remove unreachable code

2017-07-24 Thread foo86
Arguments passed to these functions are never NULL.
---
 libavcodec/dcaadpcm.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/libavcodec/dcaadpcm.c b/libavcodec/dcaadpcm.c
index 9f615e3793..d9f53441b0 100644
--- a/libavcodec/dcaadpcm.c
+++ b/libavcodec/dcaadpcm.c
@@ -211,9 +211,6 @@ int ff_dcaadpcm_do_real(int pred_vq_index,
 
 av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
 {
-if (!s)
-return -1;
-
 s->private_data = av_malloc(sizeof(premultiplied_coeffs) * 
DCA_ADPCM_VQCODEBOOK_SZ);
 if (!s->private_data)
 return AVERROR(ENOMEM);
@@ -224,8 +221,5 @@ av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
 
 av_cold void ff_dcaadpcm_free(DCAADPCMEncContext *s)
 {
-if (!s)
-return;
-
 av_freep(>private_data);
 }
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 2/2] avcodec/dcaenc: propagate errors

2017-07-24 Thread foo86
---
 libavcodec/dcaenc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index c1d72bfd16..fea67bf37c 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -129,7 +129,7 @@ static int subband_bufer_alloc(DCAEncContext *c)
(SUBBAND_SAMPLES + DCA_ADPCM_COEFFS),
sizeof(int32_t));
 if (!bufer)
-return -1;
+return AVERROR(ENOMEM);
 
 /* we need a place for DCA_ADPCM_COEFF samples from previous frame
  * to calc prediction coefficients for each subband */
@@ -153,10 +153,10 @@ static int encode_init(AVCodecContext *avctx)
 {
 DCAEncContext *c = avctx->priv_data;
 uint64_t layout = avctx->channel_layout;
-int i, j, min_frame_bits;
+int i, j, ret, min_frame_bits;
 
-if (subband_bufer_alloc(c))
-return AVERROR(ENOMEM);
+if ((ret = subband_bufer_alloc(c)) < 0)
+return ret;
 
 c->fullband_channels = c->channels = avctx->channels;
 c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
@@ -166,8 +166,8 @@ static int encode_init(AVCodecContext *avctx)
 c->worst_noise_ever = -2047;
 c->consumed_adpcm_bits = 0;
 
-if (ff_dcaadpcm_init(>adpcm_ctx))
-return AVERROR(ENOMEM);
+if ((ret = ff_dcaadpcm_init(>adpcm_ctx)) < 0)
+return ret;
 
 if (!layout) {
 av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 3/3] avformat/s337m: fix potentially undefined pointer arithmetic

2017-07-24 Thread foo86
Use integer position instead of pointer for loop variable. Also only
skip header fields after header has been fully validated.
---
 libavformat/s337m.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavformat/s337m.c b/libavformat/s337m.c
index 1f4ba5edaf..2e85d487b5 100644
--- a/libavformat/s337m.c
+++ b/libavformat/s337m.c
@@ -86,22 +86,21 @@ static int s337m_probe(AVProbeData *p)
 {
 uint64_t state = 0;
 int markers[3] = { 0 };
-int i, sum, max, data_type, data_size, offset;
+int i, pos, sum, max, data_type, data_size, offset;
 uint8_t *buf;
 
-for (buf = p->buf; buf < p->buf + p->buf_size; buf++) {
-state = (state << 8) | *buf;
+for (pos = 0; pos < p->buf_size; pos++) {
+state = (state << 8) | p->buf[pos];
 if (!IS_LE_MARKER(state))
 continue;
 
+buf = p->buf + pos + 1;
 if (IS_16LE_MARKER(state)) {
-data_type = AV_RL16(buf + 1);
-data_size = AV_RL16(buf + 3);
-buf += 4;
+data_type = AV_RL16(buf);
+data_size = AV_RL16(buf + 2);
 } else {
-data_type = AV_RL24(buf + 1);
-data_size = AV_RL24(buf + 4);
-buf += 6;
+data_type = AV_RL24(buf);
+data_size = AV_RL24(buf + 3);
 }
 
 if (s337m_get_offset_and_codec(NULL, state, data_type, data_size, 
, NULL))
@@ -110,7 +109,8 @@ static int s337m_probe(AVProbeData *p)
 i = IS_16LE_MARKER(state) ? 0 : IS_20LE_MARKER(state) ? 1 : 2;
 markers[i]++;
 
-buf  += offset;
+pos  += IS_16LE_MARKER(state) ? 4 : 6;
+pos  += offset;
 state = 0;
 }
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 2/3] avcodec/dolby_e: fix potentially undefined pointer arithmetic

2017-07-24 Thread foo86
Avoid undefined behavior in skip_input() by checking that enough data is
available before incrementing input pointer.

Check return values of parse_key() and skip_input() and exit early with
error if there is not enough data.
---
 libavcodec/dolby_e.c | 45 -
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index f811db4d8e..91a00ce878 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -28,21 +28,28 @@
 #include "dolby_e.h"
 #include "fft.h"
 
-static void skip_input(DBEContext *s, int nb_words)
+static int skip_input(DBEContext *s, int nb_words)
 {
+if (nb_words > s->input_size) {
+av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n");
+return AVERROR_INVALIDDATA;
+}
+
 s->input  += nb_words * s->word_bytes;
 s->input_size -= nb_words;
+return 0;
 }
 
 static int parse_key(DBEContext *s)
 {
-int key = 0;
-
-if (s->key_present && s->input_size > 0)
-key = AV_RB24(s->input) >> 24 - s->word_bits;
-
-skip_input(s, s->key_present);
-return key;
+if (s->key_present) {
+uint8_t *key = s->input;
+int  ret = skip_input(s, 1);
+if (ret < 0)
+return ret;
+return AV_RB24(key) >> 24 - s->word_bits;
+}
+return 0;
 }
 
 static int convert_input(DBEContext *s, int nb_words, int key)
@@ -83,8 +90,10 @@ static int convert_input(DBEContext *s, int nb_words, int 
key)
 
 static int parse_metadata(DBEContext *s)
 {
-int i, ret, key = parse_key(s), mtd_size;
+int i, ret, key, mtd_size;
 
+if ((key = parse_key(s)) < 0)
+return key;
 if ((ret = convert_input(s, 1, key)) < 0)
 return ret;
 
@@ -135,14 +144,13 @@ static int parse_metadata(DBEContext *s)
 return AVERROR_INVALIDDATA;
 }
 
-skip_input(s, mtd_size + 1);
-return 0;
+return skip_input(s, mtd_size + 1);
 }
 
 static int parse_metadata_ext(DBEContext *s)
 {
 if (s->mtd_ext_size)
-skip_input(s, s->key_present + s->mtd_ext_size + 1);
+return skip_input(s, s->key_present + s->mtd_ext_size + 1);
 return 0;
 }
 
@@ -455,7 +463,10 @@ static int parse_channel(DBEContext *s, int ch, int seg_id)
 
 static int parse_audio(DBEContext *s, int start, int end, int seg_id)
 {
-int ch, ret, key = parse_key(s);
+int ch, ret, key;
+
+if ((key = parse_key(s)) < 0)
+return key;
 
 for (ch = start; ch < end; ch++) {
 if (!s->ch_size[ch]) {
@@ -469,17 +480,17 @@ static int parse_audio(DBEContext *s, int start, int end, 
int seg_id)
 return ret;
 s->channels[seg_id][ch].nb_groups = 0;
 }
-skip_input(s, s->ch_size[ch]);
+if ((ret = skip_input(s, s->ch_size[ch])) < 0)
+return ret;
 }
 
-skip_input(s, 1);
-return 0;
+return skip_input(s, 1);
 }
 
 static int parse_meter(DBEContext *s)
 {
 if (s->meter_size)
-skip_input(s, s->key_present + s->meter_size + 1);
+return skip_input(s, s->key_present + s->meter_size + 1);
 return 0;
 }
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 1/3] avcodec/dolby_e: add AV_CODEC_CAP_CHANNEL_CONF capability

2017-07-24 Thread foo86
---
 libavcodec/dolby_e.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 6f390d959f..f811db4d8e 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -701,7 +701,7 @@ AVCodec ff_dolby_e_decoder = {
 .decode = dolby_e_decode_frame,
 .close  = dolby_e_close,
 .flush  = dolby_e_flush,
-.capabilities   = AV_CODEC_CAP_DR1,
+.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
 .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, 
AV_SAMPLE_FMT_NONE },
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/dcaadpcm: fix use of uninitialized variable

2017-07-22 Thread foo86
On Sat, Jul 22, 2017 at 07:36:04PM +0100, Rostislav Pehlivanov wrote:
> On 22 July 2017 at 18:50, foo86 <fooba...@gmail.com> wrote:
> 
> > Fixes CID 1409924.
> > ---
> >  libavcodec/dcaadpcm.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/dcaadpcm.c b/libavcodec/dcaadpcm.c
> > index e00f81f011..99cbb40172 100644
> > --- a/libavcodec/dcaadpcm.c
> > +++ b/libavcodec/dcaadpcm.c
> > @@ -80,7 +80,7 @@ static int64_t find_best_filter(const DCAADPCMEncContext
> > *s, const int32_t *in,
> >  {
> >  const premultiplied_coeffs *precalc_data = s->private_data;
> >  int i, j, k = 0;
> > -int vq;
> > +int vq = -1;
> >  int64_t err;
> >  int64_t min_err = 1ll << 62;
> >  int64_t corr[15];
> > --
> > 2.11.0
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> Patch LGTM, tracing what it would do if it fails is it'll just disable
> adpcm encoding.

Pushed, thanks.

> For small patches like these that you're confident with, just push them
> directly, no point in waiting for days when you're a maintainer (though
> dcheredn1k wrote that code, you should ping him on IRC for patches to the
> encoder).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/dcaadpcm: check for av_malloc() failure

2017-07-22 Thread foo86
On Sat, Jul 22, 2017 at 03:33:18PM -0300, James Almer wrote:
> On 7/22/2017 2:50 PM, foo86 wrote:
> > Fixes CID 1409915.
> > ---
> >  libavcodec/dcaadpcm.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/libavcodec/dcaadpcm.c b/libavcodec/dcaadpcm.c
> > index 8742c7ccf6..e00f81f011 100644
> > --- a/libavcodec/dcaadpcm.c
> > +++ b/libavcodec/dcaadpcm.c
> > @@ -215,6 +215,9 @@ av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
> >  return -1;
> >  
> >  s->private_data = av_malloc(sizeof(premultiplied_coeffs) * 
> > DCA_ADPCM_VQCODEBOOK_SZ);
> > +if (!s->private_data)
> > +return -1;
> 
> AVERROR(ENOMEM)

Changed.

> You could while at it change the call to ff_dcaadpcm_init() in dcaenc.c
> to actually look and propagate this value.

I think this needs to be in a separate patch since it is not directly
related to fixing Coverity issue.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/dcaadpcm: check for av_malloc() failure

2017-07-22 Thread foo86
On Sat, Jul 22, 2017 at 07:55:05PM +0200, Nicolas George wrote:
> Le quartidi 4 thermidor, an CCXXV, foo86 a écrit :
> > Fixes CID 1409915.
> > ---
> >  libavcodec/dcaadpcm.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/libavcodec/dcaadpcm.c b/libavcodec/dcaadpcm.c
> > index 8742c7ccf6..e00f81f011 100644
> > --- a/libavcodec/dcaadpcm.c
> > +++ b/libavcodec/dcaadpcm.c
> > @@ -215,6 +215,9 @@ av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
> >  return -1;
> >  
> >  s->private_data = av_malloc(sizeof(premultiplied_coeffs) * 
> > DCA_ADPCM_VQCODEBOOK_SZ);
> > +if (!s->private_data)
> 
> > +return -1;
> 
> Proper return code please. Even if it is unused by the surrounding code,
> it will make maintenance easier.

Changed to AVERROR(ENOMEM) and pushed, thanks.

> (There is another -1 just above, wrong too. It should be replaced by
> "av_assert1(s);", but that is not important since it cannot be reached.)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] avcodec/dcaadpcm: check for av_malloc() failure

2017-07-22 Thread foo86
Fixes CID 1409915.
---
 libavcodec/dcaadpcm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/dcaadpcm.c b/libavcodec/dcaadpcm.c
index 8742c7ccf6..e00f81f011 100644
--- a/libavcodec/dcaadpcm.c
+++ b/libavcodec/dcaadpcm.c
@@ -215,6 +215,9 @@ av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
 return -1;
 
 s->private_data = av_malloc(sizeof(premultiplied_coeffs) * 
DCA_ADPCM_VQCODEBOOK_SZ);
+if (!s->private_data)
+return -1;
+
 precalc(s->private_data);
 return 0;
 }
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 2/2] avcodec/dcaadpcm: fix use of uninitialized variable

2017-07-22 Thread foo86
Fixes CID 1409924.
---
 libavcodec/dcaadpcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dcaadpcm.c b/libavcodec/dcaadpcm.c
index e00f81f011..99cbb40172 100644
--- a/libavcodec/dcaadpcm.c
+++ b/libavcodec/dcaadpcm.c
@@ -80,7 +80,7 @@ static int64_t find_best_filter(const DCAADPCMEncContext *s, 
const int32_t *in,
 {
 const premultiplied_coeffs *precalc_data = s->private_data;
 int i, j, k = 0;
-int vq;
+int vq = -1;
 int64_t err;
 int64_t min_err = 1ll << 62;
 int64_t corr[15];
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH] MAINTAINERS: add myself

2017-07-22 Thread foo86
On Fri, Jul 21, 2017 at 12:22:25PM -0300, James Almer wrote:
> Applied.
> 
> Send your public ssh key privately to Michael Niedermayer to get push
> rights to the git repo.

Key sent, thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/2] avcodec: add Dolby E decoder

2017-07-21 Thread foo86
On Wed, Jul 19, 2017 at 01:48:47PM +0200, Moritz Barsnick wrote:
> On Sat, Jul 01, 2017 at 17:03:46 +0300, foo86 wrote:
> > +static av_cold void init_tables(void)
> > +{
> > +int i, j;
> > +
> > +for (i = 1; i < 17; i++)
> > +mantissa_tab1[i][0] = 1.0 / (1 << i - 1);
> > +
> > +for (i = 2; i < 16; i++) {
> > +mantissa_tab1[i][1] = 1.0  / ((1 << i) - 1);
> > +mantissa_tab1[i][2] = 0.5  / ((1 << i) - 1);
> > +mantissa_tab1[i][3] = 0.25 / ((1 << i) - 1);
> > +}
> > +
> > +mantissa_tab1[i][1] = 0.5   / (1 << 15);
> > +mantissa_tab1[i][2] = 0.75  / (1 << 15);
> > +mantissa_tab1[i][3] = 0.875 / (1 << 15);
> > +
> > +for (i = 1; i < 17; i++) {
> > +mantissa_tab2[i][1] = mantissa_tab1[i][0] * 0.5;
> > +mantissa_tab2[i][2] = mantissa_tab1[i][0] * 0.75;
> > +mantissa_tab2[i][3] = mantissa_tab1[i][0] * 0.875;
> > +for (j = 1; j < 4; j++)
> > +mantissa_tab3[i][j] = 1.0 / (1 << i) + 1.0 / (1 << j) - 1.0 / 
> > (1 << i + j);
> > +}
> > +
> > +mantissa_tab3[1][3] = 0.6875;
> > +
> > +for (i = 0; i < 25; i++) {
> > +exponent_tab[i * 2] = 1.0   / (1 << i);
> > +exponent_tab[i * 2 + 1] = M_SQRT1_2 / (1 << i);
> > +}
> 
> The literal numerical constants used in the quoted section should
> probably get 'f' suffixes, to force single precision operations. (Not
> that it matters much in the init code.)

I can send a patch to add 'f' suffixes if that's preferred.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] MAINTAINERS: add myself

2017-07-21 Thread foo86
---
 MAINTAINERS | 4 
 1 file changed, 4 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 60aae12faa..ae0e08d121 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -159,8 +159,10 @@ Codecs:
   crystalhd.c   Philip Langdale
   cscd.cReimar Doeffinger
   cuvid.c   Timo Rothenpieler
+  dca*  foo86
   dirac*Rostislav Pehlivanov
   dnxhd*Baptiste Coudurier
+  dolby_e*  foo86
   dpcm.cMike Melanson
   dss_sp.c  Oleksij Rempel
   dv.c  Roman Shaposhnik
@@ -394,6 +396,7 @@ Muxers/Demuxers:
   crc.c Michael Niedermayer
   daud.cReimar Doeffinger
   dss.c Oleksij Rempel
+  dtsdec.c  foo86
   dtshddec.cPaul B Mahol
   dv.c  Roman Shaposhnik
   electronicarts.c  Peter Ross
@@ -465,6 +468,7 @@ Muxers/Demuxers:
   rtpdec_vc2hq.*, rtpenc_vc2hq.*Thomas Volkert
   rtpdec_vp9.c  Thomas Volkert
   rtpenc_mpv.*, rtpenc_aac.*Martin Storsjo
+  s337m.c   foo86
   sbgdec.c  Nicolas George
   sdp.c Martin Storsjo
   segafilm.cMike Melanson
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH] avcodec/dca: remove GetBitContext usage from avpriv_dca_parse_core_frame_header()

2017-07-21 Thread foo86
On Fri, Jul 21, 2017 at 01:02:41AM -0300, James Almer wrote:
> Will apply soon.

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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/get_bits: add cached bitstream reader

2017-07-14 Thread foo86
On Fri, Jul 14, 2017 at 05:12:25PM +0200, Hendrik Leppkes wrote:
> On Fri, Jul 14, 2017 at 4:08 PM, foo86 <fooba...@gmail.com> wrote:
> > On Thu, Jul 13, 2017 at 12:27:03PM +0200, Paul B Mahol wrote:
> >> +static inline unsigned int get_bits(GetBitContext *s, int n)
> >>  {
> >> +#ifdef CACHED_BITSTREAM_READER
> >> +register int tmp = 0;
> >> +#ifdef BITSTREAM_READER_LE
> >> +uint64_t left = 0;
> >> +#endif
> >> +
> >> +av_assert2(n>0 && n<=32);
> >> +if (n > s->bits_left) {
> >> +n -= s->bits_left;
> >> +#ifdef BITSTREAM_READER_LE
> >> +left = s->bits_left;
> >> +#endif
> >> +tmp = get_val(s, s->bits_left);
> > This triggers an assert in get_val() if s->bits_left == 0.
> >
> >> +refill_32(s);
> >> +}
> >> +
> >> +#ifdef BITSTREAM_READER_LE
> >> +tmp = get_val(s, n) << left | tmp;
> >> +#else
> >> +tmp = get_val(s, n) | tmp << n;
> > This causes undefined behavior if n > 30.
> 
> get_bits is only valid until n = 25 in the "non-cached" case, so its
> not a problem to impose the same limitation on the cached reader.
> In fact, if they are to share the exact same API, it should probably
> follow that they also share the same constraints, so that we can do
> proper performance comparisons between the two, instead of having to
> re-write the using code.

Cached bitstream reader currently uses get_bits() to implement
get_bits_long(), which means cached get_bits() must support reading
values up to 32 bits.

I agree however that cached/uncached bistream readers should have the
same API contraints. That means cached get_bits_long() should probably
have a separate implementation.

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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/get_bits: add cached bitstream reader

2017-07-14 Thread foo86
On Thu, Jul 13, 2017 at 12:27:03PM +0200, Paul B Mahol wrote:
> +static inline unsigned int get_bits(GetBitContext *s, int n)
>  {
> +#ifdef CACHED_BITSTREAM_READER
> +register int tmp = 0;
> +#ifdef BITSTREAM_READER_LE
> +uint64_t left = 0;
> +#endif
> +
> +av_assert2(n>0 && n<=32);
> +if (n > s->bits_left) {
> +n -= s->bits_left;
> +#ifdef BITSTREAM_READER_LE
> +left = s->bits_left;
> +#endif
> +tmp = get_val(s, s->bits_left);
This triggers an assert in get_val() if s->bits_left == 0.

> +refill_32(s);
> +}
> +
> +#ifdef BITSTREAM_READER_LE
> +tmp = get_val(s, n) << left | tmp;
> +#else
> +tmp = get_val(s, n) | tmp << n;
This causes undefined behavior if n > 30.

> +#endif
> +
> +#else
>  register int tmp;
>  OPEN_READER(re, s);
>  av_assert2(n>0 && n<=25);
>  UPDATE_CACHE(re, s);
> -tmp = SHOW_SBITS(re, s, n);
> +tmp = SHOW_UBITS(re, s, n);
>  LAST_SKIP_BITS(re, s, n);
>  CLOSE_READER(re, s);
> +#endif
>  return tmp;
>  }

The code under #ifdef CACHED_BITSTREAM_READER can probably be simplified
like this (analogous to show_bits()):

if (n > s->bits_left)
refill_32(s);

tmp = get_val(s, n);

This avoids UB and is simpler/faster. Or am I missing something here?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 10/10] avcodec/dca: avoid using bitstream reader in a non-standard way

2017-07-10 Thread foo86
Use proper get_bits.h functions instead of directly accessing index.
---
 libavcodec/dca_core.c | 12 +++-
 libavcodec/dca_core.h |  1 +
 libavcodec/dca_xll.c  |  2 +-
 libavcodec/dcadec.h   |  4 ++--
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 4a7ea4e3f3..3add9f812b 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1804,6 +1804,7 @@ int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, 
int size)
 
 if ((ret = init_get_bits8(>gb, data, size)) < 0)
 return ret;
+s->gb_in = s->gb;
 
 if ((ret = parse_frame_header(s)) < 0)
 return ret;
@@ -1831,7 +1832,6 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t 
*data, DCAExssAsset *asset
 {
 AVCodecContext *avctx = s->avctx;
 DCAContext *dca = avctx->priv_data;
-GetBitContext gb = s->gb;
 int exss_mask = asset ? asset->extension_mask : 0;
 int ret = 0, ext = 0;
 
@@ -1843,11 +1843,13 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t 
*data, DCAExssAsset *asset
 ret = parse_xxch_frame(s);
 ext = DCA_EXSS_XXCH;
 } else if (s->xxch_pos) {
-s->gb.index = s->xxch_pos;
+s->gb = s->gb_in;
+skip_bits_long(>gb, s->xxch_pos);
 ret = parse_xxch_frame(s);
 ext = DCA_CSS_XXCH;
 } else if (s->xch_pos) {
-s->gb.index = s->xch_pos;
+s->gb = s->gb_in;
+skip_bits_long(>gb, s->xch_pos);
 ret = parse_xch_frame(s);
 ext = DCA_CSS_XCH;
 }
@@ -1889,8 +1891,8 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t 
*data, DCAExssAsset *asset
 s->ext_audio_mask |= DCA_EXSS_X96;
 }
 } else if (s->x96_pos) {
-s->gb = gb;
-s->gb.index = s->x96_pos;
+s->gb = s->gb_in;
+skip_bits_long(>gb, s->x96_pos);
 if ((ret = parse_x96_frame(s)) < 0) {
 if (ret == AVERROR(ENOMEM) || (avctx->err_recognition & 
AV_EF_EXPLODE))
 return ret;
diff --git a/libavcodec/dca_core.h b/libavcodec/dca_core.h
index cce0ffd7b1..10128d1e32 100644
--- a/libavcodec/dca_core.h
+++ b/libavcodec/dca_core.h
@@ -101,6 +101,7 @@ typedef struct DCADSPData {
 typedef struct DCACoreDecoder {
 AVCodecContext  *avctx;
 GetBitContext   gb;
+GetBitContext   gb_in;
 
 // Bit stream header
 int crc_present;///< CRC present flag
diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 38a1999fc8..d265cab8df 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -1028,7 +1028,7 @@ static int parse_band_data(DCAXllDecoder *s)
 return ret;
 chs_clear_band_data(s, c, band, seg);
 }
-s->gb.index = navi_pos;
+skip_bits_long(>gb, navi_pos - get_bits_count(>gb));
 }
 navi_ptr++;
 }
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 456f3c433b..9da8d3b444 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -88,9 +88,9 @@ static inline int ff_dca_check_crc(AVCodecContext *avctx, 
GetBitContext *s,
 
 static inline int ff_dca_seek_bits(GetBitContext *s, int p)
 {
-if (p < s->index || p > s->size_in_bits)
+if (p < get_bits_count(s) || p > s->size_in_bits)
 return -1;
-s->index = p;
+skip_bits_long(s, p - get_bits_count(s));
 return 0;
 }
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 08/10] avcodec/dca_parser: avoid use of magic values

2017-07-10 Thread foo86
Duration computation can be simplified because number of PCM blocks is
only allowed to be a multiple of 8.
---
 libavcodec/dca_parser.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 390f7975f9..7e99b16bf0 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -25,6 +25,7 @@
 #include "dca.h"
 #include "dca_core.h"
 #include "dca_exss.h"
+#include "dca_lbr.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
 #include "parser.h"
@@ -214,9 +215,9 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 return AVERROR_INVALIDDATA;
 
 switch (get_bits(, 8)) {
-case 2:
+case DCA_LBR_HEADER_DECODER_INIT:
 pc1->sr_code = get_bits(, 8);
-case 1:
+case DCA_LBR_HEADER_SYNC_ONLY:
 break;
 default:
 return AVERROR_INVALIDDATA;
@@ -267,7 +268,7 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 if (avpriv_dca_parse_core_frame_header(, ) < 0)
 return AVERROR_INVALIDDATA;
 
-*duration = 256 * (h.npcmblocks / 8);
+*duration = h.npcmblocks * DCA_PCMBLOCK_SAMPLES;
 *sample_rate = avpriv_dca_sample_rates[h.sr_code];
 if (*profile != FF_PROFILE_UNKNOWN)
 return 0;
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 03/10] avcodec: add avpriv_dca_parse_core_frame_header()

2017-07-10 Thread foo86
There are 3 different places where DCA core frame header is parsed:
decoder, parser and demuxer. Each one uses ad-hoc code. Add common core
frame header parsing function that will be used in all places.
---
 libavcodec/dca.c | 60 
 libavcodec/dca.h | 49 ++
 libavcodec/version.h |  4 ++--
 3 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index fb796191d6..39f8f3d81c 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -28,7 +28,9 @@
 #include "libavutil/error.h"
 
 #include "dca.h"
+#include "dca_core.h"
 #include "dca_syncwords.h"
+#include "get_bits.h"
 #include "put_bits.h"
 
 const uint32_t avpriv_dca_sample_rates[16] = {
@@ -85,3 +87,61 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, int 
src_size, uint8_t *dst,
 return AVERROR_INVALIDDATA;
 }
 }
+
+int avpriv_dca_parse_core_frame_header(GetBitContext *gb, DCACoreFrameHeader 
*h)
+{
+if (get_bits_long(gb, 32) != DCA_SYNCWORD_CORE_BE)
+return DCA_PARSE_ERROR_SYNC_WORD;
+
+h->normal_frame = get_bits1(gb);
+h->deficit_samples = get_bits(gb, 5) + 1;
+if (h->deficit_samples != DCA_PCMBLOCK_SAMPLES)
+return DCA_PARSE_ERROR_DEFICIT_SAMPLES;
+
+h->crc_present = get_bits1(gb);
+h->npcmblocks = get_bits(gb, 7) + 1;
+if (h->npcmblocks & (DCA_SUBBAND_SAMPLES - 1))
+return DCA_PARSE_ERROR_PCM_BLOCKS;
+
+h->frame_size = get_bits(gb, 14) + 1;
+if (h->frame_size < 96)
+return DCA_PARSE_ERROR_FRAME_SIZE;
+
+h->audio_mode = get_bits(gb, 6);
+if (h->audio_mode >= DCA_AMODE_COUNT)
+return DCA_PARSE_ERROR_AMODE;
+
+h->sr_code = get_bits(gb, 4);
+if (!avpriv_dca_sample_rates[h->sr_code])
+return DCA_PARSE_ERROR_SAMPLE_RATE;
+
+h->br_code = get_bits(gb, 5);
+if (get_bits1(gb))
+return DCA_PARSE_ERROR_RESERVED_BIT;
+
+h->drc_present = get_bits1(gb);
+h->ts_present = get_bits1(gb);
+h->aux_present = get_bits1(gb);
+h->hdcd_master = get_bits1(gb);
+h->ext_audio_type = get_bits(gb, 3);
+h->ext_audio_present = get_bits1(gb);
+h->sync_ssf = get_bits1(gb);
+h->lfe_present = get_bits(gb, 2);
+if (h->lfe_present == DCA_LFE_FLAG_INVALID)
+return DCA_PARSE_ERROR_LFE_FLAG;
+
+h->predictor_history = get_bits1(gb);
+if (h->crc_present)
+skip_bits(gb, 16);
+h->filter_perfect = get_bits1(gb);
+h->encoder_rev = get_bits(gb, 4);
+h->copy_hist = get_bits(gb, 2);
+h->pcmr_code = get_bits(gb, 3);
+if (!ff_dca_bits_per_sample[h->pcmr_code])
+return DCA_PARSE_ERROR_PCM_RES;
+
+h->sumdiff_front = get_bits1(gb);
+h->sumdiff_surround = get_bits1(gb);
+h->dn_code = get_bits(gb, 4);
+return 0;
+}
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index 1d10de4b94..cf6204e554 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -32,6 +32,49 @@
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 
+#include "get_bits.h"
+
+#define DCA_CORE_FRAME_HEADER_SIZE  18
+
+enum DCAParseError {
+DCA_PARSE_ERROR_SYNC_WORD   = -1,
+DCA_PARSE_ERROR_DEFICIT_SAMPLES = -2,
+DCA_PARSE_ERROR_PCM_BLOCKS  = -3,
+DCA_PARSE_ERROR_FRAME_SIZE  = -4,
+DCA_PARSE_ERROR_AMODE   = -5,
+DCA_PARSE_ERROR_SAMPLE_RATE = -6,
+DCA_PARSE_ERROR_RESERVED_BIT= -7,
+DCA_PARSE_ERROR_LFE_FLAG= -8,
+DCA_PARSE_ERROR_PCM_RES = -9
+};
+
+typedef struct DCACoreFrameHeader {
+uint8_t normal_frame;   ///< Frame type
+uint8_t deficit_samples;///< Deficit sample count
+uint8_t crc_present;///< CRC present flag
+uint8_t npcmblocks; ///< Number of PCM sample blocks
+uint16_tframe_size; ///< Primary frame byte size
+uint8_t audio_mode; ///< Audio channel arrangement
+uint8_t sr_code;///< Core audio sampling frequency
+uint8_t br_code;///< Transmission bit rate
+uint8_t drc_present;///< Embedded dynamic range flag
+uint8_t ts_present; ///< Embedded time stamp flag
+uint8_t aux_present;///< Auxiliary data flag
+uint8_t hdcd_master;///< HDCD mastering flag
+uint8_t ext_audio_type; ///< Extension audio descriptor flag
+uint8_t ext_audio_present;  ///< Extended coding flag
+uint8_t sync_ssf;   ///< Audio sync word insertion flag
+uint8_t lfe_present;///< Low frequency effects flag
+uint8_t predictor_history;  ///< Predictor history flag switch
+uint8_t filter_perfect; ///< Multirate interpolator switch
+uint8_t encoder_rev;///< Encoder software revision
+uint8_t copy_hist;  ///< Copy history
+uint8_t pcmr_code;  ///< Source PCM resolution
+uint8_t 

[FFmpeg-devel] [PATCH 06/10] avformat/dtsdec: switch to common frame header parsing function

2017-07-10 Thread foo86
This makes probing for regular DTS more strict because more header
fields are checked and values not supported by decoder are now rejected.

Also fixes an issue original code had with 14-bit streams: 96 bits of
header were expected, however only 84 bits were converted, which was not
enough to parse LFE flag.
---
 libavformat/dtsdec.c | 39 +--
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index 8c985b8877..6e0048f9bc 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -35,13 +35,13 @@ static int dts_probe(AVProbeData *p)
 uint32_t state = -1;
 int markers[4*16] = {0};
 int exss_markers = 0, exss_nextpos = 0;
-int sum, max, pos, i;
+int sum, max, pos, ret, i;
 int64_t diff = 0;
-uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+uint8_t hdr[DCA_CORE_FRAME_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = { 
0 };
 
 for (pos = FFMIN(4096, p->buf_size); pos < p->buf_size - 2; pos += 2) {
-int marker, sample_blocks, sample_rate, sr_code, framesize;
-int lfe, wide_hdr, hdr_size;
+int marker, wide_hdr, hdr_size, framesize;
+DCACoreFrameHeader h;
 GetBitContext gb;
 
 bufp = buf = p->buf + pos;
@@ -98,36 +98,15 @@ static int dts_probe(AVProbeData *p)
 else
 continue;
 
-if (avpriv_dca_convert_bitstream(buf-2, 12, hdr, 12) < 0)
+if ((ret = avpriv_dca_convert_bitstream(buf - 2, 
DCA_CORE_FRAME_HEADER_SIZE,
+hdr, 
DCA_CORE_FRAME_HEADER_SIZE)) < 0)
 continue;
-
-init_get_bits(, hdr, 96);
-skip_bits_long(, 39);
-
-sample_blocks = get_bits(, 7) + 1;
-if (sample_blocks < 8)
+if (init_get_bits8(, hdr, ret) < 0)
 continue;
-
-framesize = get_bits(, 14) + 1;
-if (framesize < 95)
-continue;
-
-skip_bits(, 6);
-sr_code = get_bits(, 4);
-sample_rate = avpriv_dca_sample_rates[sr_code];
-if (sample_rate == 0)
-continue;
-
-get_bits(, 5);
-if (get_bits(, 1))
-continue;
-
-skip_bits_long(, 9);
-lfe = get_bits(, 2);
-if (lfe > 2)
+if (avpriv_dca_parse_core_frame_header(, ) < 0)
 continue;
 
-marker += 4* sr_code;
+marker += 4 * h.sr_code;
 
 markers[marker] ++;
 }
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 07/10] avcodec/dca_parser: export profile information

2017-07-10 Thread foo86
Permits applications to access DTS profile information without having to
decode a frame.
---
 libavcodec/dca_parser.c | 44 +++-
 1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 6107358773..390f7975f9 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -23,6 +23,7 @@
  */
 
 #include "dca.h"
+#include "dca_core.h"
 #include "dca_exss.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
@@ -189,19 +190,19 @@ static av_cold int dca_parse_init(AVCodecParserContext *s)
 }
 
 static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf,
-int buf_size, int *duration, int *sample_rate)
+int buf_size, int *duration, int *sample_rate,
+int *profile)
 {
+DCAExssAsset *asset = >exss.assets[0];
 GetBitContext gb;
 DCACoreFrameHeader h;
 uint8_t hdr[DCA_CORE_FRAME_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = { 
0 };
-int ret;
+int ret, frame_size;
 
 if (buf_size < DCA_CORE_FRAME_HEADER_SIZE)
 return AVERROR_INVALIDDATA;
 
 if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) {
-DCAExssAsset *asset = >exss.assets[0];
-
 if ((ret = ff_dca_exss_parse(>exss, buf, buf_size)) < 0)
 return ret;
 
@@ -226,6 +227,7 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 
 *sample_rate = ff_dca_sampling_freqs[pc1->sr_code];
 *duration = 1024 << ff_dca_freq_ranges[pc1->sr_code];
+*profile = FF_PROFILE_DTS_EXPRESS;
 return 0;
 }
 
@@ -250,6 +252,7 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 
 *sample_rate = asset->max_sample_rate;
 *duration = (1 + (*sample_rate > 96000)) << nsamples_log2;
+*profile = FF_PROFILE_DTS_HD_MA;
 return 0;
 }
 
@@ -266,6 +269,37 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 
 *duration = 256 * (h.npcmblocks / 8);
 *sample_rate = avpriv_dca_sample_rates[h.sr_code];
+if (*profile != FF_PROFILE_UNKNOWN)
+return 0;
+
+*profile = FF_PROFILE_DTS;
+if (h.ext_audio_present) {
+switch (h.ext_audio_type) {
+case DCA_EXT_AUDIO_XCH:
+case DCA_EXT_AUDIO_XXCH:
+*profile = FF_PROFILE_DTS_ES;
+break;
+case DCA_EXT_AUDIO_X96:
+*profile = FF_PROFILE_DTS_96_24;
+break;
+}
+}
+
+frame_size = FFALIGN(h.frame_size, 4);
+if (buf_size - 4 < frame_size)
+return 0;
+
+buf  += frame_size;
+buf_size -= frame_size;
+if (AV_RB32(buf) != DCA_SYNCWORD_SUBSTREAM)
+return 0;
+if (ff_dca_exss_parse(>exss, buf, buf_size) < 0)
+return 0;
+
+if (asset->extension_mask & DCA_EXSS_XLL)
+*profile = FF_PROFILE_DTS_HD_MA;
+else if (asset->extension_mask & (DCA_EXSS_XBR | DCA_EXSS_XXCH | 
DCA_EXSS_X96))
+*profile = FF_PROFILE_DTS_HD_HRA;
 
 return 0;
 }
@@ -298,7 +332,7 @@ static int dca_parse(AVCodecParserContext *s, 
AVCodecContext *avctx,
 }
 
 /* read the duration and sample rate from the frame header */
-if (!dca_parse_params(pc1, buf, buf_size, , _rate)) {
+if (!dca_parse_params(pc1, buf, buf_size, , _rate, 
>profile)) {
 if (!avctx->sample_rate)
 avctx->sample_rate = sample_rate;
 s->duration = av_rescale(duration, avctx->sample_rate, sample_rate);
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 01/10] avcodec/dca: move some enumeration typedefs into headers

2017-07-10 Thread foo86
These values will be used by the parser. Prefix them with DCA_
appropriately.
---
 libavcodec/dca_core.c | 68 +++
 libavcodec/dca_core.h | 28 +
 libavcodec/dca_lbr.c  |  9 ++-
 libavcodec/dca_lbr.h  |  5 
 4 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 36040f6f9d..16210b89f8 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -35,35 +35,7 @@ enum HeaderType {
 HEADER_XXCH
 };
 
-enum AudioMode {
-AMODE_MONO, // Mode 0: A (mono)
-AMODE_MONO_DUAL,// Mode 1: A + B (dual mono)
-AMODE_STEREO,   // Mode 2: L + R (stereo)
-AMODE_STEREO_SUMDIFF,   // Mode 3: (L+R) + (L-R) (sum-diff)
-AMODE_STEREO_TOTAL, // Mode 4: LT + RT (left and right total)
-AMODE_3F,   // Mode 5: C + L + R
-AMODE_2F1R, // Mode 6: L + R + S
-AMODE_3F1R, // Mode 7: C + L + R + S
-AMODE_2F2R, // Mode 8: L + R + SL + SR
-AMODE_3F2R, // Mode 9: C + L + R + SL + SR
-
-AMODE_COUNT
-};
-
-enum ExtAudioType {
-EXT_AUDIO_XCH   = 0,
-EXT_AUDIO_X96   = 2,
-EXT_AUDIO_XXCH  = 6
-};
-
-enum LFEFlag {
-LFE_FLAG_NONE,
-LFE_FLAG_128,
-LFE_FLAG_64,
-LFE_FLAG_INVALID
-};
-
-static const int8_t prm_ch_to_spkr_map[AMODE_COUNT][5] = {
+static const int8_t prm_ch_to_spkr_map[DCA_AMODE_COUNT][5] = {
 { DCA_SPEAKER_C,-1, -1, -1,
 -1 },
 { DCA_SPEAKER_L, DCA_SPEAKER_R, -1, -1,
 -1 },
 { DCA_SPEAKER_L, DCA_SPEAKER_R, -1, -1,
 -1 },
@@ -76,7 +48,7 @@ static const int8_t prm_ch_to_spkr_map[AMODE_COUNT][5] = {
 { DCA_SPEAKER_C, DCA_SPEAKER_L, DCA_SPEAKER_R,  DCA_SPEAKER_Ls, 
DCA_SPEAKER_Rs }
 };
 
-static const uint8_t audio_mode_ch_mask[AMODE_COUNT] = {
+static const uint8_t audio_mode_ch_mask[DCA_AMODE_COUNT] = {
 DCA_SPEAKER_LAYOUT_MONO,
 DCA_SPEAKER_LAYOUT_STEREO,
 DCA_SPEAKER_LAYOUT_STEREO,
@@ -139,7 +111,7 @@ static int parse_frame_header(DCACoreDecoder *s)
 
 // Audio channel arrangement
 s->audio_mode = get_bits(>gb, 6);
-if (s->audio_mode >= AMODE_COUNT) {
+if (s->audio_mode >= DCA_AMODE_COUNT) {
 av_log(s->avctx, AV_LOG_ERROR, "Unsupported audio channel arrangement 
(%d)\n", s->audio_mode);
 return AVERROR_PATCHWELCOME;
 }
@@ -180,7 +152,7 @@ static int parse_frame_header(DCACoreDecoder *s)
 
 // Low frequency effects flag
 s->lfe_present = get_bits(>gb, 2);
-if (s->lfe_present == LFE_FLAG_INVALID) {
+if (s->lfe_present == DCA_LFE_FLAG_INVALID) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid low frequency effects flag\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1783,7 +1755,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 // must be done backwards from the end of core frame to work around
 // sync word aliasing issues.
 switch (s->ext_audio_type) {
-case EXT_AUDIO_XCH:
+case DCA_EXT_AUDIO_XCH:
 if (dca->request_channel_layout)
 break;
 
@@ -1813,7 +1785,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 }
 break;
 
-case EXT_AUDIO_X96:
+case DCA_EXT_AUDIO_X96:
 // The distance between X96 sync word and end of the core frame
 // must be equal to X96 frame size. Minimum X96 frame size is 96
 // bytes.
@@ -1836,7 +1808,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 }
 break;
 
-case EXT_AUDIO_XXCH:
+case DCA_EXT_AUDIO_XXCH:
 if (dca->request_channel_layout)
 break;
 
@@ -2102,7 +2074,7 @@ int ff_dca_core_filter_fixed(DCACoreDecoder *s, int 
x96_synth)
 int nlfesamples = s->npcmblocks >> 1;
 
 // Check LFF
-if (s->lfe_present == LFE_FLAG_128) {
+if (s->lfe_present == DCA_LFE_FLAG_128) {
 av_log(s->avctx, AV_LOG_ERROR, "Fixed point mode doesn't support 
LFF=1\n");
 return AVERROR(EINVAL);
 }
@@ -2152,7 +2124,7 @@ static int filter_frame_fixed(DCACoreDecoder *s, AVFrame 
*frame)
 
 // Undo embedded XCH downmix
 if (s->es_format && (s->ext_audio_mask & DCA_CSS_XCH)
-&& s->audio_mode >= AMODE_2F2R) {
+&& s->audio_mode >= DCA_AMODE_2F2R) {
 s->dcadsp->dmix_sub_xch(s->output_samples[DCA_SPEAKER_Ls],
 s->output_samples[DCA_SPEAKER_Rs],
 s->output_samples[DCA_SPEAKER_Cs],
@@ -2196,15 +2168,15 @@ static int filter_frame_fixed(DCACoreDecoder *s, 
AVFrame *frame)
 
 if (!(s->ext_audio_mask & (DCA_CSS_XXCH | DCA_CSS_XCH | DCA_EXSS_XXCH))) {
 // Front sum/difference decoding
-if ((s->sumdiff_front && s->audio_mode > AMODE_MONO)
-|| 

[FFmpeg-devel] [PATCH 02/10] avcodec/dca: move bits per sample array to dca.c

2017-07-10 Thread foo86
It will be used by the parser. This change avoids unwanted parser
dependency on dcadata.
---
 libavcodec/dca.c | 4 
 libavcodec/dca.h | 2 ++
 libavcodec/dcadata.c | 4 
 libavcodec/dcadata.h | 2 --
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index 58f340e6da..fb796191d6 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -45,6 +45,10 @@ const uint8_t ff_dca_freq_ranges[16] = {
 0, 1, 2, 3, 4, 1, 2, 3, 4, 4, 0, 1, 2, 3, 4, 4
 };
 
+const uint8_t ff_dca_bits_per_sample[8] = {
+16, 16, 20, 20, 0, 24, 24, 0
+};
+
 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t 
*dst,
  int max_size)
 {
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index bd96bc9ee3..1d10de4b94 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -156,6 +156,8 @@ extern av_export const uint32_t avpriv_dca_sample_rates[16];
 
 extern const uint32_t ff_dca_sampling_freqs[16];
 extern const uint8_t ff_dca_freq_ranges[16];
+extern const uint8_t ff_dca_bits_per_sample[8];
+
 
 /**
  * Convert bitstream to one representation based on sync marker
diff --git a/libavcodec/dcadata.c b/libavcodec/dcadata.c
index eaef01875a..1b646a7aa6 100644
--- a/libavcodec/dcadata.c
+++ b/libavcodec/dcadata.c
@@ -42,10 +42,6 @@ const uint8_t ff_dca_channels[16] = {
 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8
 };
 
-const uint8_t ff_dca_bits_per_sample[8] = {
-16, 16, 20, 20, 0, 24, 24, 0
-};
-
 const uint8_t ff_dca_dmix_primary_nch[8] = {
 1, 2, 2, 3, 3, 4, 4, 0
 };
diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h
index 9dd6eba7f1..5aa85b3414 100644
--- a/libavcodec/dcadata.h
+++ b/libavcodec/dcadata.h
@@ -32,8 +32,6 @@ extern const uint32_t ff_dca_bit_rates[32];
 
 extern const uint8_t ff_dca_channels[16];
 
-extern const uint8_t ff_dca_bits_per_sample[8];
-
 extern const uint8_t ff_dca_dmix_primary_nch[8];
 
 extern const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS];
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 09/10] avcodec/dca_core: probe extension headers directly

2017-07-10 Thread foo86
Avoid using bitstream reader in a non-standard way by directly accessing
index. Use bit shifting/masking operations instead.
---
 libavcodec/dca_core.c | 31 ---
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 090191dfa9..4a7ea4e3f3 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1704,6 +1704,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 int sync_pos = FFMIN(s->frame_size / 4, s->gb.size_in_bits / 32) - 1;
 int last_pos = get_bits_count(>gb) / 32;
 int size, dist;
+uint32_t w1, w2 = 0;
 
 // Search for extension sync words aligned on 4-byte boundary. Search
 // must be done backwards from the end of core frame to work around
@@ -1718,15 +1719,15 @@ static int parse_optional_info(DCACoreDecoder *s)
 // compatibility with legacy bitstreams. Minimum XCH frame size is
 // 96 bytes. AMODE and PCHS are further checked to reduce
 // probability of alias sync detection.
-for (; sync_pos >= last_pos; sync_pos--) {
-if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_XCH) {
-s->gb.index = (sync_pos + 1) * 32;
-size = get_bits(>gb, 10) + 1;
+for (; sync_pos >= last_pos; sync_pos--, w2 = w1) {
+w1 = AV_RB32(s->gb.buffer + sync_pos * 4);
+if (w1 == DCA_SYNCWORD_XCH) {
+size = (w2 >> 22) + 1;
 dist = s->frame_size - sync_pos * 4;
 if (size >= 96
 && (size == dist || size - 1 == dist)
-&& get_bits(>gb, 7) == 0x08) {
-s->xch_pos = get_bits_count(>gb);
+&& (w2 >> 15 & 0x7f) == 0x08) {
+s->xch_pos = sync_pos * 32 + 49;
 break;
 }
 }
@@ -1743,13 +1744,13 @@ static int parse_optional_info(DCACoreDecoder *s)
 // The distance between X96 sync word and end of the core frame
 // must be equal to X96 frame size. Minimum X96 frame size is 96
 // bytes.
-for (; sync_pos >= last_pos; sync_pos--) {
-if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_X96) {
-s->gb.index = (sync_pos + 1) * 32;
-size = get_bits(>gb, 12) + 1;
+for (; sync_pos >= last_pos; sync_pos--, w2 = w1) {
+w1 = AV_RB32(s->gb.buffer + sync_pos * 4);
+if (w1 == DCA_SYNCWORD_X96) {
+size = (w2 >> 20) + 1;
 dist = s->frame_size - sync_pos * 4;
 if (size >= 96 && size == dist) {
-s->x96_pos = get_bits_count(>gb);
+s->x96_pos = sync_pos * 32 + 44;
 break;
 }
 }
@@ -1768,10 +1769,10 @@ static int parse_optional_info(DCACoreDecoder *s)
 
 // XXCH frame header CRC must be valid. Minimum XXCH frame header
 // size is 11 bytes.
-for (; sync_pos >= last_pos; sync_pos--) {
-if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_XXCH) 
{
-s->gb.index = (sync_pos + 1) * 32;
-size = get_bits(>gb, 6) + 1;
+for (; sync_pos >= last_pos; sync_pos--, w2 = w1) {
+w1 = AV_RB32(s->gb.buffer + sync_pos * 4);
+if (w1 == DCA_SYNCWORD_XXCH) {
+size = (w2 >> 26) + 1;
 dist = s->gb.size_in_bits / 8 - sync_pos * 4;
 if (size >= 11 && size <= dist &&
 !av_crc(dca->crctab, 0x, s->gb.buffer +
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 04/10] avcodec/dca_core: switch to common frame header parsing function

2017-07-10 Thread foo86
---
 libavcodec/dca_core.c | 167 ++
 1 file changed, 60 insertions(+), 107 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 16210b89f8..090191dfa9 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -81,114 +81,68 @@ static void get_array(GetBitContext *s, int32_t *array, 
int size, int n)
 // 5.3.1 - Bit stream header
 static int parse_frame_header(DCACoreDecoder *s)
 {
-int normal_frame, pcmr_index;
-
-// Frame type
-normal_frame = get_bits1(>gb);
-
-// Deficit sample count
-if (get_bits(>gb, 5) != DCA_PCMBLOCK_SAMPLES - 1) {
-av_log(s->avctx, AV_LOG_ERROR, "Deficit samples are not supported\n");
-return normal_frame ? AVERROR_INVALIDDATA : AVERROR_PATCHWELCOME;
-}
-
-// CRC present flag
-s->crc_present = get_bits1(>gb);
-
-// Number of PCM sample blocks
-s->npcmblocks = get_bits(>gb, 7) + 1;
-if (s->npcmblocks & (DCA_SUBBAND_SAMPLES - 1)) {
-av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of PCM sample 
blocks (%d)\n", s->npcmblocks);
-return (s->npcmblocks < 6 || normal_frame) ? AVERROR_INVALIDDATA : 
AVERROR_PATCHWELCOME;
-}
-
-// Primary frame byte size
-s->frame_size = get_bits(>gb, 14) + 1;
-if (s->frame_size < 96) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid core frame size (%d bytes)\n", 
s->frame_size);
-return AVERROR_INVALIDDATA;
-}
-
-// Audio channel arrangement
-s->audio_mode = get_bits(>gb, 6);
-if (s->audio_mode >= DCA_AMODE_COUNT) {
-av_log(s->avctx, AV_LOG_ERROR, "Unsupported audio channel arrangement 
(%d)\n", s->audio_mode);
-return AVERROR_PATCHWELCOME;
-}
-
-// Core audio sampling frequency
-s->sample_rate = avpriv_dca_sample_rates[get_bits(>gb, 4)];
-if (!s->sample_rate) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid core audio sampling 
frequency\n");
-return AVERROR_INVALIDDATA;
+DCACoreFrameHeader h = { 0 };
+int err = avpriv_dca_parse_core_frame_header(>gb, );
+
+if (err < 0) {
+switch (err) {
+case DCA_PARSE_ERROR_DEFICIT_SAMPLES:
+av_log(s->avctx, AV_LOG_ERROR, "Deficit samples are not 
supported\n");
+return h.normal_frame ? AVERROR_INVALIDDATA : AVERROR_PATCHWELCOME;
+
+case DCA_PARSE_ERROR_PCM_BLOCKS:
+av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of PCM sample 
blocks (%d)\n", h.npcmblocks);
+return (h.npcmblocks < 6 || h.normal_frame) ? AVERROR_INVALIDDATA 
: AVERROR_PATCHWELCOME;
+
+case DCA_PARSE_ERROR_FRAME_SIZE:
+av_log(s->avctx, AV_LOG_ERROR, "Invalid core frame size (%d 
bytes)\n", h.frame_size);
+return AVERROR_INVALIDDATA;
+
+case DCA_PARSE_ERROR_AMODE:
+av_log(s->avctx, AV_LOG_ERROR, "Unsupported audio channel 
arrangement (%d)\n", h.audio_mode);
+return AVERROR_PATCHWELCOME;
+
+case DCA_PARSE_ERROR_SAMPLE_RATE:
+av_log(s->avctx, AV_LOG_ERROR, "Invalid core audio sampling 
frequency\n");
+return AVERROR_INVALIDDATA;
+
+case DCA_PARSE_ERROR_RESERVED_BIT:
+av_log(s->avctx, AV_LOG_ERROR, "Reserved bit set\n");
+return AVERROR_INVALIDDATA;
+
+case DCA_PARSE_ERROR_LFE_FLAG:
+av_log(s->avctx, AV_LOG_ERROR, "Invalid low frequency effects 
flag\n");
+return AVERROR_INVALIDDATA;
+
+case DCA_PARSE_ERROR_PCM_RES:
+av_log(s->avctx, AV_LOG_ERROR, "Invalid source PCM resolution\n");
+return AVERROR_INVALIDDATA;
+
+default:
+av_log(s->avctx, AV_LOG_ERROR, "Unknown core frame header 
error\n");
+return AVERROR_INVALIDDATA;
+}
 }
 
-// Transmission bit rate
-s->bit_rate = ff_dca_bit_rates[get_bits(>gb, 5)];
-
-// Reserved field
-skip_bits1(>gb);
-
-// Embedded dynamic range flag
-s->drc_present = get_bits1(>gb);
-
-// Embedded time stamp flag
-s->ts_present = get_bits1(>gb);
-
-// Auxiliary data flag
-s->aux_present = get_bits1(>gb);
-
-// HDCD mastering flag
-skip_bits1(>gb);
-
-// Extension audio descriptor flag
-s->ext_audio_type = get_bits(>gb, 3);
-
-// Extended coding flag
-s->ext_audio_present = get_bits1(>gb);
-
-// Audio sync word insertion flag
-s->sync_ssf = get_bits1(>gb);
-
-// Low frequency effects flag
-s->lfe_present = get_bits(>gb, 2);
-if (s->lfe_present == DCA_LFE_FLAG_INVALID) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid low frequency effects flag\n");
-return AVERROR_INVALIDDATA;
-}
-
-// Predictor history flag switch
-s->predictor_history = get_bits1(>gb);
-
-// Header CRC check bytes
-if (s->crc_present)
-skip_bits(>gb, 16);
-
-// Multirate interpolator switch
-s->filter_perfect = get_bits1(>gb);
-
-// Encoder software revision
-

[FFmpeg-devel] [PATCH 05/10] avcodec/dca_parser: switch to common frame header parsing function

2017-07-10 Thread foo86
---
 libavcodec/dca_parser.c | 26 +++---
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index e5bea3347c..6107358773 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -192,10 +192,11 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 int buf_size, int *duration, int *sample_rate)
 {
 GetBitContext gb;
-uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
-int ret, sample_blocks;
+DCACoreFrameHeader h;
+uint8_t hdr[DCA_CORE_FRAME_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = { 
0 };
+int ret;
 
-if (buf_size < 12)
+if (buf_size < DCA_CORE_FRAME_HEADER_SIZE)
 return AVERROR_INVALIDDATA;
 
 if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) {
@@ -255,21 +256,16 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 return AVERROR_INVALIDDATA;
 }
 
-if ((ret = avpriv_dca_convert_bitstream(buf, 12, hdr, 12)) < 0)
+if ((ret = avpriv_dca_convert_bitstream(buf, DCA_CORE_FRAME_HEADER_SIZE,
+hdr, DCA_CORE_FRAME_HEADER_SIZE)) 
< 0)
 return ret;
-
-init_get_bits(, hdr, 96);
-
-skip_bits_long(, 39);
-sample_blocks = get_bits(, 7) + 1;
-if (sample_blocks < 8)
+if ((ret = init_get_bits8(, hdr, ret)) < 0)
+return ret;
+if (avpriv_dca_parse_core_frame_header(, ) < 0)
 return AVERROR_INVALIDDATA;
-*duration = 256 * (sample_blocks / 8);
 
-skip_bits(, 20);
-*sample_rate = avpriv_dca_sample_rates[get_bits(, 4)];
-if (*sample_rate == 0)
-return AVERROR_INVALIDDATA;
+*duration = 256 * (h.npcmblocks / 8);
+*sample_rate = avpriv_dca_sample_rates[h.sr_code];
 
 return 0;
 }
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/get_bits: add cached bitstream reader

2017-07-08 Thread foo86
On Sat, Jul 08, 2017 at 08:07:49PM +0200, Hendrik Leppkes wrote:
> On Sat, Jul 8, 2017 at 7:09 PM, foo86 <fooba...@gmail.com> wrote:
> >> +static inline void skip_bits_long(GetBitContext *s, int n)
> >> +{
> >> +#ifdef CACHED_BITSTREAM_READER
> >> +skip_bits(s, n);
> >> +#else
> >> +#if UNCHECKED_BITSTREAM_READER
> >> +s->index += n;
> >> +#else
> >> +s->index += av_clip(n, -s->index, s->size_in_bits_plus8 - s->index);
> > Uncached bitstream reader allows seeking back by passing negative n
> > here. If cached bitstream reader disallows this, there should be a
> > comment saying so (and possibly an assert).
> 
> This seems like an undocumented and possibly insecure/invalid use of
> the API, maybe we should just generally discourage such use.

If skip_bits_long() is not supposed to seek backward, then it's fine by
me. (I thought it was looking at its implementation which allows
negative n).

> Why would you need to skip backwards anyway? Usually code uses
> show_bits, or creates a copy of the reader so it can revert to the
> original if needed.

DCA XLL decoder needs to seek backward to recover from segment overread.
I will probably change it to create a copy of the GetBitContext as you
suggested, seems to be a better solution. 

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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/get_bits: add cached bitstream reader

2017-07-08 Thread foo86
On Sat, Jul 08, 2017 at 07:25:52PM +0200, Paul B Mahol wrote:
> On 7/8/17, foo86 <fooba...@gmail.com> wrote:
> > On Sat, Jul 08, 2017 at 11:12:06AM +0200, Paul B Mahol wrote:
> >> [...]
> >
> >>  static inline void skip_bits(GetBitContext *s, int n)
> >>  {
> >> +#ifdef CACHED_BITSTREAM_READER
> >> +if (n <= s->bits_left)
> >> +skip_remaining(s, n);
> >> +else {
> >> +n -= s->bits_left;
> >> +skip_remaining(s, s->bits_left);
> > This causes undefined behavior if s->bits_left == 64.
> 
> Could you elaborate?, it looks to me Libav have same issue.

Calling skip_bits_long() with n > 64 after init_get_bits() causes this
error:

libavcodec/get_bits.h:309:14: runtime error: shift exponent 64 is too
large for 64-bit type 'long unsigned int'
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/get_bits: add cached bitstream reader

2017-07-08 Thread foo86
On Sat, Jul 08, 2017 at 11:12:06AM +0200, Paul B Mahol wrote:
> [...]

>  static inline void skip_bits(GetBitContext *s, int n)
>  {
> +#ifdef CACHED_BITSTREAM_READER
> +if (n <= s->bits_left)
> +skip_remaining(s, n);
> +else {
> +n -= s->bits_left;
> +skip_remaining(s, s->bits_left);
This causes undefined behavior if s->bits_left == 64.

> +if (n >= 64) {
> +unsigned skip = n;
> +
> +n -= skip;
> +s->index += skip;
> +}
This block looks strange.

> +refill_32(s);
> +if (n)
> +skip_remaining(s, n);
> +}
> +#else
>  OPEN_READER(re, s);
>  LAST_SKIP_BITS(re, s, n);
>  CLOSE_READER(re, s);
> +#endif
> +}
> +
> +static inline void skip_bits_long(GetBitContext *s, int n)
> +{
> +#ifdef CACHED_BITSTREAM_READER
> +skip_bits(s, n);
> +#else
> +#if UNCHECKED_BITSTREAM_READER
> +s->index += n;
> +#else
> +s->index += av_clip(n, -s->index, s->size_in_bits_plus8 - s->index);
Uncached bitstream reader allows seeking back by passing negative n
here. If cached bitstream reader disallows this, there should be a
comment saying so (and possibly an assert).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2 1/2] avcodec: add Dolby E decoder

2017-07-01 Thread foo86
---
 configure   |   1 +
 doc/general.texi|   1 +
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/avcodec.h|   1 +
 libavcodec/codec_desc.c |   7 +
 libavcodec/dolby_e.c| 707 ++
 libavcodec/dolby_e.h| 733 
 libavcodec/version.h|   4 +-
 9 files changed, 1454 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dolby_e.c
 create mode 100644 libavcodec/dolby_e.h

diff --git a/configure b/configure
index 282114d268..03fd42b91c 100755
--- a/configure
+++ b/configure
@@ -2400,6 +2400,7 @@ dds_decoder_select="texturedsp"
 dirac_decoder_select="dirac_parse dwt golomb videodsp mpegvideoenc"
 dnxhd_decoder_select="blockdsp idctdsp"
 dnxhd_encoder_select="aandcttables blockdsp fdctdsp idctdsp mpegvideoenc 
pixblockdsp"
+dolby_e_decoder_select="mdct"
 dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_select="zlib"
diff --git a/doc/general.texi b/doc/general.texi
index 8f582d586f..d95ef31fde 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1001,6 +1001,7 @@ following image formats are supported:
 @tab All versions except 5.1 are supported.
 @item DCA (DTS Coherent Acoustics)  @tab  X  @tab  X
 @tab supported extensions: XCh, XXCH, X96, XBR, XLL, LBR (partially)
+@item Dolby E  @tab @tab  X
 @item DPCM id RoQ@tab  X  @tab  X
 @tab Used in Quake III, Jedi Knight 2 and other computer games.
 @item DPCM Interplay @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b440a00746..4e8d5a2527 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -252,6 +252,7 @@ OBJS-$(CONFIG_DIRAC_DECODER)   += diracdec.o 
dirac.o diracdsp.o diractab
 OBJS-$(CONFIG_DFA_DECODER) += dfa.o
 OBJS-$(CONFIG_DNXHD_DECODER)   += dnxhddec.o dnxhddata.o
 OBJS-$(CONFIG_DNXHD_ENCODER)   += dnxhdenc.o dnxhddata.o
+OBJS-$(CONFIG_DOLBY_E_DECODER) += dolby_e.o kbdwin.o
 OBJS-$(CONFIG_DPX_DECODER) += dpx.o
 OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o
 OBJS-$(CONFIG_DSD_LSBF_DECODER)+= dsddec.o dsd.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 0243f47358..4712592a5f 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -423,6 +423,7 @@ static void register_all(void)
 REGISTER_DECODER(BMV_AUDIO, bmv_audio);
 REGISTER_DECODER(COOK,  cook);
 REGISTER_ENCDEC (DCA,   dca);
+REGISTER_DECODER(DOLBY_E,   dolby_e);
 REGISTER_DECODER(DSD_LSBF,  dsd_lsbf);
 REGISTER_DECODER(DSD_MSBF,  dsd_msbf);
 REGISTER_DECODER(DSD_LSBF_PLANAR,   dsd_lsbf_planar);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b697afa0ae..ca1dd54eb0 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -622,6 +622,7 @@ enum AVCodecID {
 AV_CODEC_ID_PAF_AUDIO,
 AV_CODEC_ID_ON2AVC,
 AV_CODEC_ID_DSS_SP,
+AV_CODEC_ID_DOLBY_E,
 
 AV_CODEC_ID_FFWAVESYNTH = 0x15800,
 AV_CODEC_ID_SONIC,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index cf1246e431..26c03e9df6 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2671,6 +2671,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .props = AV_CODEC_PROP_LOSSY,
 },
 {
+.id= AV_CODEC_ID_DOLBY_E,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "dolby_e",
+.long_name = NULL_IF_CONFIG_SMALL("Dolby E"),
+.props = AV_CODEC_PROP_LOSSY,
+},
+{
 .id= AV_CODEC_ID_G729,
 .type  = AVMEDIA_TYPE_AUDIO,
 .name  = "g729",
diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
new file mode 100644
index 00..63187e9977
--- /dev/null
+++ b/libavcodec/dolby_e.c
@@ -0,0 +1,707 @@
+/*
+ * Copyright (C) 2017 foo86
+ *
+ * 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
+ */
+
+#include "libavutil/float_dsp.h"
+#include "libavutil/thread.h"

[FFmpeg-devel] [PATCH v2 2/2] avformat: add SMPTE 337M demuxer

2017-07-01 Thread foo86
---
 Changelog|   1 +
 doc/general.texi |   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/s337m.c  | 206 +++
 libavformat/version.h|   2 +-
 6 files changed, 211 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/s337m.c

diff --git a/Changelog b/Changelog
index a8726c6736..a909031849 100644
--- a/Changelog
+++ b/Changelog
@@ -26,6 +26,7 @@ version :
   --x86asmexe=yasm to configure to restore the old behavior.
 - additional frame format support for Interplay MVE movies
 - support for decoding through D3D11VA in ffmpeg
+- Dolby E decoder and SMPTE 337M demuxer
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/general.texi b/doc/general.texi
index d95ef31fde..036c8c25d4 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -520,6 +520,7 @@ library:
 @tab Multimedia format used by many games.
 @item SMJPEG@tab X @tab X
 @tab Used in certain Loki game ports.
+@item SMPTE 337M encapsulation  @tab   @tab X
 @item Smush @tab   @tab X
 @tab Multimedia format used in some LucasArts games.
 @item Sony OpenMG (OMA) @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 80aeed22c0..b0ef82cdd4 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -432,6 +432,7 @@ OBJS-$(CONFIG_RTSP_DEMUXER)  += rtsp.o 
rtspdec.o httpauth.o \
 urldecode.o
 OBJS-$(CONFIG_RTSP_MUXER)+= rtsp.o rtspenc.o httpauth.o \
 urldecode.o
+OBJS-$(CONFIG_S337M_DEMUXER) += s337m.o spdif.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index a0e2fb8c85..1ebc14231c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -267,6 +267,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(RTP,  rtp);
 REGISTER_MUXER   (RTP_MPEGTS,   rtp_mpegts);
 REGISTER_MUXDEMUX(RTSP, rtsp);
+REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
 REGISTER_DEMUXER (SBG,  sbg);
diff --git a/libavformat/s337m.c b/libavformat/s337m.c
new file mode 100644
index 00..1f4ba5edaf
--- /dev/null
+++ b/libavformat/s337m.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2017 foo86
+ *
+ * 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
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "spdif.h"
+
+#define MARKER_16LE 0x72F81F4E
+#define MARKER_20LE 0x20876FF0E154
+#define MARKER_24LE 0x72F8961F4EA5
+
+#define IS_16LE_MARKER(state)   ((state & 0x) == MARKER_16LE)
+#define IS_20LE_MARKER(state)   ((state & 0xF0F0) == MARKER_20LE)
+#define IS_24LE_MARKER(state)   ((state & 0x) == MARKER_24LE)
+#define IS_LE_MARKER(state) (IS_16LE_MARKER(state) || 
IS_20LE_MARKER(state) || IS_24LE_MARKER(state))
+
+static int s337m_get_offset_and_codec(AVFormatContext *s,
+  uint64_t state,
+  int data_type, int data_size,
+  int *offset, enum AVCodecID *codec)
+{
+int word_bits;
+
+if (IS_16LE_MARKER(state)) {
+word_bits = 16;
+} else if (IS_20LE_MARKER(state)) {
+data_type >>= 8;
+data_size >>= 4;
+word_bits = 20;
+} else {
+data_type >>= 8;
+word_bits = 24;
+}
+
+if ((data_type & 0x1F) != 0x1C) {
+if (s)
+avpriv_report_missing_feature(s, "Data type %#x in SMPTE 337M", 
data_type & 0x1F);
+return AVERROR_PATCHWELCOME;
+}
+
+if (codec)
+*codec = AV_CODEC_ID_DOLBY_E;
+
+switch (data_size / word_bits) {
+case 3648:
+*offset = 1920;
+break;
+case 3644:
+*offset =

[FFmpeg-devel] [PATCH 2/3] avcodec: add Dolby E decoder

2017-06-27 Thread foo86
---
 configure   |1 +
 doc/general.texi|1 +
 libavcodec/Makefile |1 +
 libavcodec/allcodecs.c  |1 +
 libavcodec/avcodec.h|1 +
 libavcodec/codec_desc.c |7 +
 libavcodec/dolby_e.c|  716 +
 libavcodec/dolby_e.h| 1153 +++
 libavcodec/version.h|4 +-
 9 files changed, 1883 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dolby_e.c
 create mode 100644 libavcodec/dolby_e.h

diff --git a/configure b/configure
index 6ca919be4a..4a97be23df 100755
--- a/configure
+++ b/configure
@@ -2401,6 +2401,7 @@ dds_decoder_select="texturedsp"
 dirac_decoder_select="dirac_parse dwt golomb videodsp mpegvideoenc"
 dnxhd_decoder_select="blockdsp idctdsp"
 dnxhd_encoder_select="aandcttables blockdsp fdctdsp idctdsp mpegvideoenc 
pixblockdsp"
+dolby_e_decoder_select="mdct"
 dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_select="zlib"
diff --git a/doc/general.texi b/doc/general.texi
index 8f582d586f..d95ef31fde 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1001,6 +1001,7 @@ following image formats are supported:
 @tab All versions except 5.1 are supported.
 @item DCA (DTS Coherent Acoustics)  @tab  X  @tab  X
 @tab supported extensions: XCh, XXCH, X96, XBR, XLL, LBR (partially)
+@item Dolby E  @tab @tab  X
 @item DPCM id RoQ@tab  X  @tab  X
 @tab Used in Quake III, Jedi Knight 2 and other computer games.
 @item DPCM Interplay @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index f0cba8843d..e12878de0d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -252,6 +252,7 @@ OBJS-$(CONFIG_DIRAC_DECODER)   += diracdec.o 
dirac.o diracdsp.o diractab
 OBJS-$(CONFIG_DFA_DECODER) += dfa.o
 OBJS-$(CONFIG_DNXHD_DECODER)   += dnxhddec.o dnxhddata.o
 OBJS-$(CONFIG_DNXHD_ENCODER)   += dnxhdenc.o dnxhddata.o
+OBJS-$(CONFIG_DOLBY_E_DECODER) += dolby_e.o
 OBJS-$(CONFIG_DPX_DECODER) += dpx.o
 OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o
 OBJS-$(CONFIG_DSD_LSBF_DECODER)+= dsddec.o dsd.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 54a9e8c42e..4101d340dd 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -417,6 +417,7 @@ static void register_all(void)
 REGISTER_DECODER(BMV_AUDIO, bmv_audio);
 REGISTER_DECODER(COOK,  cook);
 REGISTER_ENCDEC (DCA,   dca);
+REGISTER_DECODER(DOLBY_E,   dolby_e);
 REGISTER_DECODER(DSD_LSBF,  dsd_lsbf);
 REGISTER_DECODER(DSD_MSBF,  dsd_msbf);
 REGISTER_DECODER(DSD_LSBF_PLANAR,   dsd_lsbf_planar);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b697afa0ae..ca1dd54eb0 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -622,6 +622,7 @@ enum AVCodecID {
 AV_CODEC_ID_PAF_AUDIO,
 AV_CODEC_ID_ON2AVC,
 AV_CODEC_ID_DSS_SP,
+AV_CODEC_ID_DOLBY_E,
 
 AV_CODEC_ID_FFWAVESYNTH = 0x15800,
 AV_CODEC_ID_SONIC,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index cf1246e431..26c03e9df6 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2671,6 +2671,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .props = AV_CODEC_PROP_LOSSY,
 },
 {
+.id= AV_CODEC_ID_DOLBY_E,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "dolby_e",
+.long_name = NULL_IF_CONFIG_SMALL("Dolby E"),
+.props = AV_CODEC_PROP_LOSSY,
+},
+{
 .id= AV_CODEC_ID_G729,
 .type  = AVMEDIA_TYPE_AUDIO,
 .name  = "g729",
diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
new file mode 100644
index 00..ba1fe1c5d0
--- /dev/null
+++ b/libavcodec/dolby_e.c
@@ -0,0 +1,716 @@
+/*
+ * Copyright (C) 2017 foo86
+ *
+ * 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
+ */
+
+#include "libavutil/mem.h"
+#include "libavutil/float_dsp.h"
+#include &quo

[FFmpeg-devel] [PATCH 3/3] avformat: add SMPTE 337M demuxer

2017-06-27 Thread foo86
---
 Changelog|   1 +
 doc/general.texi |   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/s337m.c  | 205 +++
 libavformat/version.h|   2 +-
 6 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/s337m.c

diff --git a/Changelog b/Changelog
index 4f46edaddb..c872137792 100644
--- a/Changelog
+++ b/Changelog
@@ -24,6 +24,7 @@ version :
 - roberts video filter
 - The x86 assembler default switched from yasm to nasm, pass
   --x86asmexe=yasm to configure to restore the old behavior.
+- Dolby E decoder and SMPTE 337M demuxer
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/general.texi b/doc/general.texi
index d95ef31fde..036c8c25d4 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -520,6 +520,7 @@ library:
 @tab Multimedia format used by many games.
 @item SMJPEG@tab X @tab X
 @tab Used in certain Loki game ports.
+@item SMPTE 337M encapsulation  @tab   @tab X
 @item Smush @tab   @tab X
 @tab Multimedia format used in some LucasArts games.
 @item Sony OpenMG (OMA) @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 80aeed22c0..b0ef82cdd4 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -432,6 +432,7 @@ OBJS-$(CONFIG_RTSP_DEMUXER)  += rtsp.o 
rtspdec.o httpauth.o \
 urldecode.o
 OBJS-$(CONFIG_RTSP_MUXER)+= rtsp.o rtspenc.o httpauth.o \
 urldecode.o
+OBJS-$(CONFIG_S337M_DEMUXER) += s337m.o spdif.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index a0e2fb8c85..1ebc14231c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -267,6 +267,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(RTP,  rtp);
 REGISTER_MUXER   (RTP_MPEGTS,   rtp_mpegts);
 REGISTER_MUXDEMUX(RTSP, rtsp);
+REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
 REGISTER_DEMUXER (SBG,  sbg);
diff --git a/libavformat/s337m.c b/libavformat/s337m.c
new file mode 100644
index 00..3175a9fb87
--- /dev/null
+++ b/libavformat/s337m.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2017 foo86
+ *
+ * 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
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "spdif.h"
+
+#define MARKER_16LE 0x72F81F4E
+#define MARKER_20LE 0x20876FF0E154
+#define MARKER_24LE 0x72F8961F4EA5
+
+#define IS_16LE_MARKER(state)   ((state & 0x) == MARKER_16LE)
+#define IS_20LE_MARKER(state)   ((state & 0xF0F0) == MARKER_20LE)
+#define IS_24LE_MARKER(state)   ((state & 0x) == MARKER_24LE)
+#define IS_LE_MARKER(state) (IS_16LE_MARKER(state) || 
IS_20LE_MARKER(state) || IS_24LE_MARKER(state))
+
+static int s337m_get_offset_and_codec(AVFormatContext *s,
+  uint64_t state,
+  int data_type, int data_size,
+  int *offset, int *codec)
+{
+int word_bits;
+
+if (IS_16LE_MARKER(state)) {
+word_bits = 16;
+} else if (IS_20LE_MARKER(state)) {
+data_type >>= 8;
+data_size >>= 4;
+word_bits = 20;
+} else {
+data_type >>= 8;
+word_bits = 24;
+}
+
+if ((data_type & 0x1F) != 0x1C) {
+if (s)
+avpriv_report_missing_feature(s, "Data type %#x in SMPTE 337M", 
data_type & 0x1F);
+return AVERROR_PATCHWELCOME;
+}
+
+if (codec)
+*codec = AV_CODEC_ID_DOLBY_E;
+
+switch (data_size / word_bits) {
+case 3648:
+*offset = 1920;
+break;
+case 3644:
+*offset = 2002;
+break;
+case 3640:
+ 

[FFmpeg-devel] [PATCH 1/3] avcodec/s302m: fix AVOption flags

2017-06-27 Thread foo86
---
 libavcodec/s302m.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index a68ac79f2c..4350d97f0a 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -201,7 +201,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void 
*data,
 return avpkt->size;
 }
 
-#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_DECODING_PARAM
 static const AVOption s302m_options[] = {
 {"non_pcm_mode", "Chooses what to do with NON-PCM", offsetof(S302Context, 
non_pcm_mode), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 3, FLAGS, "non_pcm_mode"},
 {"copy", "Pass NON-PCM through unchanged" , 0, 
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 3, FLAGS, "non_pcm_mode"},
-- 
2.11.0

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


[FFmpeg-devel] [PATCH] avcodec/dca: add support for 20-bit XLL

2017-01-07 Thread foo86
Fixes ticket #6063.
---
 libavcodec/dca_xll.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 1d616c298c..1320aaf28f 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -143,7 +143,7 @@ static int chs_parse_header(DCAXllDecoder *s, DCAXllChSet 
*c, DCAExssAsset *asse
 
 // Storage unit width
 c->storage_bit_res = get_bits(>gb, 5) + 1;
-if (c->storage_bit_res != 16 && c->storage_bit_res != 24) {
+if (c->storage_bit_res != 16 && c->storage_bit_res != 20 && 
c->storage_bit_res != 24) {
 avpriv_request_sample(s->avctx, "%d-bit XLL storage resolution", 
c->storage_bit_res);
 return AVERROR_PATCHWELCOME;
 }
@@ -1415,9 +1415,12 @@ int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame 
*frame)
 switch (p->storage_bit_res) {
 case 16:
 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
+shift = 16 - p->pcm_bit_res;
 break;
+case 20:
 case 24:
 avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
+shift = 24 - p->pcm_bit_res;
 break;
 default:
 return AVERROR(EINVAL);
@@ -1438,7 +1441,6 @@ int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame 
*frame)
s->output_mask);
 }
 
-shift = p->storage_bit_res - p->pcm_bit_res;
 for (i = 0; i < avctx->channels; i++) {
 int32_t *samples = s->output_samples[ch_remap[i]];
 if (frame->format == AV_SAMPLE_FMT_S16P) {
-- 
2.11.0

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


[FFmpeg-devel] [PATCH] avcodec/dca: set initial sample_fmt to FLTP

2016-12-24 Thread foo86
Fixes regression introduced in 39f7620d76c7a133535ed7a535f7a74fefa6e435.

Not setting default sample_fmt can result in failed transcode when audio
stream starts later in a file.

Set initial sample_fmt to FLTP, which is the "baseline" format decoder
produces.

Fixes ticket #5998.
---
 libavcodec/dcadec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 4146a85ec5..f772406691 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -362,6 +362,8 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
 break;
 }
 
+avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
+
 return 0;
 }
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 1/2] avcodec/dca_parser: simplify state machine

2016-05-31 Thread foo86
---
 libavcodec/dca_parser.c | 34 +++---
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index d76b548..1521a5b 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -109,25 +109,25 @@ static int dca_find_frame_end(DCAParseContext *pc1, const 
uint8_t *buf,
 case DCA_SYNCWORD_CORE_LE:
 if (size == 2) {
 pc1->framesize = CORE_FRAMESIZE(STATE_LE(state));
-start_found= 2;
+start_found= 4;
 }
 break;
 case DCA_SYNCWORD_CORE_14B_BE:
 if (size == 4) {
 pc1->framesize = CORE_FRAMESIZE(STATE_14(state)) * 8 / 
14 * 2;
-start_found= 2;
+start_found= 4;
 }
 break;
 case DCA_SYNCWORD_CORE_14B_LE:
 if (size == 4) {
 pc1->framesize = 
CORE_FRAMESIZE(STATE_14(STATE_LE(state))) * 8 / 14 * 2;
-start_found= 2;
+start_found= 4;
 }
 break;
 case DCA_SYNCWORD_SUBSTREAM:
 if (size == 6) {
 pc1->framesize = EXSS_FRAMESIZE(state);
-start_found= 2;
+start_found= 4;
 }
 break;
 default:
@@ -136,23 +136,19 @@ static int dca_find_frame_end(DCAParseContext *pc1, const 
uint8_t *buf,
 continue;
 }
 
-if (pc1->lastmarker == DCA_SYNCWORD_CORE_BE) {
-if (pc1->framesize > size + 2)
-continue;
-
-if (start_found == 2 && IS_EXSS_MARKER(state)) {
-pc1->framesize = size + 2;
-start_found= 3;
-continue;
-}
+if (start_found == 2 && IS_EXSS_MARKER(state) &&
+pc1->framesize <= size + 2) {
+pc1->framesize  = size + 2;
+start_found = 3;
+continue;
+}
 
-if (start_found == 3) {
-if (size == pc1->framesize + 4) {
-pc1->framesize += EXSS_FRAMESIZE(state);
-start_found = 4;
-}
-continue;
+if (start_found == 3) {
+if (size == pc1->framesize + 4) {
+pc1->framesize += EXSS_FRAMESIZE(state);
+start_found = 4;
 }
+continue;
 }
 
 if (pc1->framesize > size)
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 2/2] avcodec/dca_parser: skip initial padding

2016-05-31 Thread foo86
Padding before the first sync word can be very large for DTS-in-WAV
streams. There is no reason to include this padding in parsed packet.
---
 libavcodec/dca_parser.c | 41 -
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 1521a5b..e5bea33 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -33,6 +33,7 @@ typedef struct DCAParseContext {
 uint32_t lastmarker;
 int size;
 int framesize;
+unsigned int startpos;
 DCAExssParser exss;
 unsigned int sr_code;
 } DCAParseContext;
@@ -75,20 +76,27 @@ static int dca_find_frame_end(DCAParseContext *pc1, const 
uint8_t *buf,
 
 i = 0;
 if (!start_found) {
-for (i = 0; i < buf_size; i++) {
+for (; i < buf_size; i++) {
+size++;
 state = (state << 8) | buf[i];
-if (IS_MARKER(state)) {
-if (!pc1->lastmarker ||
-pc1->lastmarker == CORE_MARKER(state) ||
-pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM) {
-start_found = 1;
-if (IS_EXSS_MARKER(state))
-pc1->lastmarker = EXSS_MARKER(state);
-else
-pc1->lastmarker = CORE_MARKER(state);
-i++;
-break;
-}
+
+if (IS_MARKER(state) &&
+(!pc1->lastmarker ||
+  pc1->lastmarker == CORE_MARKER(state) ||
+  pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM)) {
+if (!pc1->lastmarker)
+pc1->startpos = IS_EXSS_MARKER(state) ? size - 4 : size - 
6;
+
+if (IS_EXSS_MARKER(state))
+pc1->lastmarker = EXSS_MARKER(state);
+else
+pc1->lastmarker = CORE_MARKER(state);
+
+start_found = 1;
+size= 0;
+
+i++;
+break;
 }
 }
 }
@@ -284,6 +292,13 @@ static int dca_parse(AVCodecParserContext *s, 
AVCodecContext *avctx,
 *poutbuf_size = 0;
 return buf_size;
 }
+
+/* skip initial padding */
+if (buf_size  > pc1->startpos) {
+buf  += pc1->startpos;
+buf_size -= pc1->startpos;
+}
+pc1->startpos = 0;
 }
 
 /* read the duration and sample rate from the frame header */
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH 09/10] avcodec/dca: support EXSS marker in avpriv_dca_convert_bitstream()

2016-05-31 Thread foo86
On Fri, May 13, 2016 at 12:48:31PM +0300, foo86 wrote:
> This is now required by dcadec_decode_frame(). All remaining users of
> avpriv_dca_convert_bitstream() have been updated to expect EXSS marker.
> ---
>  libavcodec/dca.c | 1 +
>  1 file changed, 1 insertion(+)

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


Re: [FFmpeg-devel] [PATCH 08/10] avcodec/dca: require checked bitstream reader

2016-05-31 Thread foo86
On Fri, May 13, 2016 at 12:48:30PM +0300, foo86 wrote:
> Remove half-working attempt at supporting unchecked bitstream reader by
> always copying input data into intermediate buffer with large amount of
> padding at the end.
> 
> Convert LBR decoder to checked bitstream reader. Convert
> dcadec_decode_frame() to parse input data directly if possible.
> ---
>  libavcodec/dca_lbr.c |  1 -
>  libavcodec/dca_xll.c |  2 +-
>  libavcodec/dcadec.c  | 44 
>  libavcodec/dcadec.h  |  2 --
>  4 files changed, 17 insertions(+), 32 deletions(-)

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


[FFmpeg-devel] [PATCH] avcodec/dca: move EXSS sampling frequency arrays to dca.c

2016-05-26 Thread foo86
Avoids unwanted parser dependency on dcadata.
---
 libavcodec/Makefile | 2 +-
 libavcodec/dca.c| 9 +
 libavcodec/dca.h| 3 +++
 libavcodec/dca_exss.c   | 1 -
 libavcodec/dca_parser.c | 1 -
 libavcodec/dcadata.c| 9 -
 libavcodec/dcadata.h| 3 ---
 7 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 224ccf7..46dd9e1 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -900,7 +900,7 @@ OBJS-$(CONFIG_ADX_PARSER)  += adx_parser.o adx.o
 OBJS-$(CONFIG_BMP_PARSER)  += bmp_parser.o
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)+= cavs_parser.o
 OBJS-$(CONFIG_COOK_PARSER) += cook_parser.o
-OBJS-$(CONFIG_DCA_PARSER)  += dca_parser.o dca_exss.o dcadata.o 
dca.o
+OBJS-$(CONFIG_DCA_PARSER)  += dca_parser.o dca_exss.o dca.o
 OBJS-$(CONFIG_DIRAC_PARSER)+= dirac_parser.o
 OBJS-$(CONFIG_DNXHD_PARSER)+= dnxhd_parser.o
 OBJS-$(CONFIG_DPX_PARSER)  += dpx_parser.o
diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index 714509b..f11c73c 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -36,6 +36,15 @@ const uint32_t avpriv_dca_sample_rates[16] = {
 12000, 24000, 48000, 96000, 192000
 };
 
+const uint32_t ff_dca_sampling_freqs[16] = {
+  8000,  16000, 32000, 64000, 128000, 22050,  44100,  88200,
+176400, 352800, 12000, 24000,  48000, 96000, 192000, 384000,
+};
+
+const uint8_t ff_dca_freq_ranges[16] = {
+0, 1, 2, 3, 4, 1, 2, 3, 4, 4, 0, 1, 2, 3, 4, 4
+};
+
 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t 
*dst,
  int max_size)
 {
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index a1ac763..bd96bc9 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -154,6 +154,9 @@ enum DCADownMixType {
 
 extern av_export const uint32_t avpriv_dca_sample_rates[16];
 
+extern const uint32_t ff_dca_sampling_freqs[16];
+extern const uint8_t ff_dca_freq_ranges[16];
+
 /**
  * Convert bitstream to one representation based on sync marker
  */
diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index fcabd07..e873088 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -19,7 +19,6 @@
  */
 
 #include "dcadec.h"
-#include "dcadata.h"
 
 static void parse_xll_parameters(DCAExssParser *s, DCAExssAsset *asset)
 {
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 6c84575..e5bea33 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -23,7 +23,6 @@
  */
 
 #include "dca.h"
-#include "dcadata.h"
 #include "dca_exss.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
diff --git a/libavcodec/dcadata.c b/libavcodec/dcadata.c
index 2d533d0..39aea73 100644
--- a/libavcodec/dcadata.c
+++ b/libavcodec/dcadata.c
@@ -8725,15 +8725,6 @@ const int32_t ff_dca_xll_band_coeff[20] = {
  3259333, -5074941,  6928550, -8204883
 };
 
-const uint32_t ff_dca_sampling_freqs[16] = {
-  8000,  16000, 32000, 64000, 128000, 22050,  44100,  88200,
-176400, 352800, 12000, 24000,  48000, 96000, 192000, 384000,
-};
-
-const uint8_t ff_dca_freq_ranges[16] = {
-0, 1, 2, 3, 4, 1, 2, 3, 4, 4, 0, 1, 2, 3, 4, 4
-};
-
 const uint16_t ff_dca_avg_g3_freqs[3] = { 16000, 18000, 24000 };
 
 const uint16_t ff_dca_fst_amp[44] = {
diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h
index 1ef1342..17aa712 100644
--- a/libavcodec/dcadata.h
+++ b/libavcodec/dcadata.h
@@ -71,9 +71,6 @@ extern const uint16_t ff_dca_xll_refl_coeff[128];
 
 extern const int32_t ff_dca_xll_band_coeff[20];
 
-extern const uint32_t ff_dca_sampling_freqs[16];
-extern const uint8_t ff_dca_freq_ranges[16];
-
 extern const uint16_t ff_dca_avg_g3_freqs[3];
 
 extern const uint16_t ff_dca_fst_amp[44];
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH v2 2/2] avcodec/dca_parser: set duration for core-less streams

2016-05-25 Thread foo86
On Wed, May 25, 2016 at 04:31:10PM -0300, James Almer wrote:
> On 5/25/2016 3:35 PM, foo86 wrote:
> > On Wed, May 25, 2016 at 11:34:13AM -0300, James Almer wrote:
> >> On 5/23/2016 11:58 AM, foo86 wrote:
> >>> ---
> >>> Updated version of the patch: don't set avctx field in DCAExssParser 
> >>> structure
> >>> to indicate that ff_dca_exss_parse() is being called from parser context.
> >>>
> >>>  libavcodec/dca_parser.c | 68 
> >>> ++---
> >>>  1 file changed, 65 insertions(+), 3 deletions(-)
> >>>
> >>
> >> Added the new dependencies on dca_exss.o and dcadata.o to dca_parser and
> >> applied. Thanks!
> > 
> > Oh, I missed parser dependencies. Thanks for fixing that.
> > 
> > Would it be better to move ff_dca_sampling_freqs/freq_ranges arrays to
> > dca.c so that parser dependency on dcadata.o can be avoided? I can send
> > a patch for that. dcadata is huge and someone may want to build the
> > demuxer/parser, but not the decoder.
> 
> Alternatively you could move it to dcadata.h and make it static const.

Won't this bloat the resulting binary by including multiple copies of
array from different object files?

> But yeah, moving them outside of dcadata.c is a good idea in any case.

> The above could also be done for avpriv_dca_sample_rates, but for this
> one the symbol will have to be scheduled for removal with the next major
> bump since, even if it's not public, it's still exported.
> Wrapping it with a LIBAVCODEC_VERSION_MAJOR preprocessor check should
> suffice.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 2/2] avcodec/dca_parser: set duration for core-less streams

2016-05-25 Thread foo86
On Wed, May 25, 2016 at 11:34:13AM -0300, James Almer wrote:
> On 5/23/2016 11:58 AM, foo86 wrote:
> > ---
> > Updated version of the patch: don't set avctx field in DCAExssParser 
> > structure
> > to indicate that ff_dca_exss_parse() is being called from parser context.
> > 
> >  libavcodec/dca_parser.c | 68 
> > ++---
> >  1 file changed, 65 insertions(+), 3 deletions(-)
> > 
> 
> Added the new dependencies on dca_exss.o and dcadata.o to dca_parser and
> applied. Thanks!

Oh, I missed parser dependencies. Thanks for fixing that.

Would it be better to move ff_dca_sampling_freqs/freq_ranges arrays to
dca.c so that parser dependency on dcadata.o can be avoided? I can send
a patch for that. dcadata is huge and someone may want to build the
demuxer/parser, but not the decoder.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/dca_exss: always update downmix flags

2016-05-23 Thread foo86
Fixes potential parsing failure when total number of channels indicated
by EXSS asset descriptor decreases mid-stream and stale embedded downmix
flags are referenced.
---
 libavcodec/dca_exss.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 87b2f42..28f138f 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -112,12 +112,10 @@ static int parse_descriptor(DCAExssParser *s, 
DCAExssAsset *asset)
 int nspeakers[8];
 
 // Embedded stereo flag
-if (asset->nchannels_total > 2)
-asset->embedded_stereo = get_bits1(>gb);
+asset->embedded_stereo = asset->nchannels_total > 2 && 
get_bits1(>gb);
 
 // Embedded 6 channels flag
-if (asset->nchannels_total > 6)
-asset->embedded_6ch = get_bits1(>gb);
+asset->embedded_6ch = asset->nchannels_total > 6 && 
get_bits1(>gb);
 
 // Speaker mask enabled flag
 if (asset->spkr_mask_enabled = get_bits1(>gb)) {
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH 06/10] avcodec/dca_parser: improve frame end search

2016-05-20 Thread foo86
On Fri, May 20, 2016 at 08:51:53PM -0300, James Almer wrote:
> "ffmpeg -i q4G.dts -c:a copy -f framecrc -" gave me the following
> before the patch
> 
> #software: Lavf57.36.100
> #tb 0: 1/9
> #media_type 0: audio
> #codec_id 0: dts
> #sample_rate 0: 192000
> #channel_layout 0: 60f
> 0,  0,  0,  960,15520, 0x4e922c28
> 0,960,960,  960,15620, 0x0aa208ee
> 0,   1920,   1920,  960,15604, 0x5ff63a0b
> 0,   2880,   2880,  960,15516, 0xeeabf0c9
> 0,   3840,   3840,  960,15476, 0x53f46290
> 0,   4800,   4800,  960,15348, 0x477e8987
> 0,   5760,   5760,  960,15252, 0x2b20725b
> 0,   6720,   6720,  960,15304, 0x9d60b356
> 0,   7680,   7680,  960,15172, 0x19e359e4
> 0,   8640,   8640,  960,15092, 0x1dc6f776
> 0,   9600,   9600,  960,15064, 0xc2385e65
> 0,  10560,  10560,  960,15048, 0x50d75a33
> 0,  11520,  11520,  960,15132, 0x3eb47e67
> 0,  12480,  12480,  960,15188, 0x6f16aad6
> 0,  13440,  13440,  960,15360, 0xc481d7c6
> 0,  14400,  14400,  960,15508, 0x2da8a9f4
> 0,  15360,  15360,  960,15380, 0x036fe8c8
> 0,  16320,  16320,  960,15372, 0xa815aa65
> 0,  17280,  17280,  960,15352, 0xc9f7b3db
> 0,  18240,  18240,  960,15288, 0x62a15e11
> 0,  19200,  19200,  960,12746, 0x44ee1fa5
> 0,  20160,  20160, 1920, 2530, 0xf4a2af4c

Yeah, this may look like combined frame due to doubled duration, but in
fact this 2530 byte frame is a fragment that belongs to the previous
frame (you can tell that the previous frame is shorter by approximately
the same number of bytes). Doubled duration actually comes from
misinterpreted core frame header (parser interprets arbitrary EXSS data
as core frame header).

> 0,  22080,  22080,  960,15244, 0xa8948fa5
> 0,  23040,  23040,  960,15264, 0x47539652
> 0,  24000,  24000,  960,15300, 0x10adf509
> 0,  24960,  24960,  960,15356, 0x3403a586
> 0,  25920,  25920,  960,15436, 0xcbea18b7
> 0,  26880,  26880,  960,15424, 0x2ce91378
> 0,  27840,  27840,  960,15524, 0xf3ba523c
> 0,  28800,  28800,  960,15544, 0xa1504354
> 0,  29760,  29760,  960,15528, 0x6bc826fd
> 0,  30720,  30720,  960,15492, 0x4f89f07a
> 0,  31680,  31680,  960,15456, 0x002c4ac0
> 0,  32640,  32640,  960,15388, 0x78c854be
> 0,  33600,  33600,  960,15372, 0xce9954e5
> 0,  34560,  34560,  960,15268, 0x1c5bceda
> 0,  35520,  35520,  960,15288, 0x60acfb3d
> 0,  36480,  36480,  960,15240, 0xb42d7f7b
> 0,  37440,  37440,  960,15316, 0xd6080d5a
> 0,  38400,  38400,  960,15368, 0xc2b65528
> 0,  39360,  39360,  960,15476, 0xa01f2806
> 0,  40320,  40320,  960,15448, 0x2e0121ef
> 0,  41280,  41280,  960,15384, 0x891dd887
> 0,  42240,  42240,  960,15384, 0x31cea7b0
> 0,  43200,  43200,  960,15316, 0xaa040ae8
> 0,  44160,  44160,  960,15356, 0xa13cfd43
> 0,  45120,  45120,  960,15388, 0xf6a81182
> 0,  46080,  46080,  960,15324, 0x72e4de3f
> 0,  47040,  47040,  960,15252, 0x5d84b107
> 0,  48000,  48000,  960,15216, 0xe9656c9b
> 0,  48960,  48960,  960,15232, 0x6930b4a3
> 
> But you're right that it was also failing during decoding. Not sure how
> i missed or why i thought the framecrc output was the same. So nevermind
> my previous comment.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 06/10] avcodec/dca_parser: improve frame end search

2016-05-20 Thread foo86
On Fri, May 20, 2016 at 04:46:31PM -0300, James Almer wrote:
> On 5/20/2016 2:40 PM, foo86 wrote:
> > On Fri, May 13, 2016 at 12:48:28PM +0300, foo86 wrote:
> >> Parse core frame size directly when searching for frame end instead of
> >> using value extracted from previous frame.
> >>
> >> Account for unused bits when calculating sync word distance for 14-bit
> >> streams to avoid alias sync detection.
> >>
> >> Parse EXSS frame size and skip over EXSS frame to avoid alias sync
> >> detection.
> >> ---
> >>  libavcodec/dca_parser.c | 94 
> >> +
> >>  1 file changed, 80 insertions(+), 14 deletions(-)
> > 
> > Fixes parser failure with the following sample: https://0x0.st/q4G.dts
> 
> Seems to happen with codec copy only, two frames were being treated as one.
> Decoding doesn't seem affected by this patch. framecrc output looks the same
> before and after.

For me it is the opposite: alias sync word in EXSS area at frame 21
results in a frame split in two without this patch (the second split
"frame" fails to decode).

This causes errors printed during decoding, and resulting framecrc
output is different (see attached files).
#software: Lavf57.36.100
#tb 0: 1/192000
#media_type 0: audio
#codec_id 0: pcm_s24le
#sample_rate 0: 192000
#channel_layout 0: 60f
0,  0,  0, 2048,36864, 0x60a47074
0,   2048,   2048, 2048,36864, 0xbd114c5c
0,   4096,   4096, 2048,36864, 0x0b7243ce
0,   6144,   6144, 2048,36864, 0x7f8c5b6c
0,   8192,   8192, 2048,36864, 0x02f96b0a
0,  10240,  10240, 2048,36864, 0xccf6f3fe
0,  12288,  12288, 2048,36864, 0x8c06a646
0,  14336,  14336, 2048,36864, 0x0dce889c
0,  16384,  16384, 2048,36864, 0xa650826b
0,  18432,  18432, 2048,36864, 0x9bb45a74
0,  20480,  20480, 2048,36864, 0xf011921f
0,  22528,  22528, 2048,36864, 0xb6b4db5b
0,  24576,  24576, 2048,36864, 0x51e3283f
0,  26624,  26624, 2048,36864, 0xe58e7024
0,  28672,  28672, 2048,36864, 0x2088d810
0,  30720,  30720, 2048,36864, 0xba88dd19
0,  32768,  32768, 2048,36864, 0xe72278cb
0,  34816,  34816, 2048,36864, 0x5096ec0e
0,  36864,  36864, 2048,36864, 0x1faddc6f
0,  38912,  38912, 2048,36864, 0xa7cb41d5
0,  40960,  40960, 1984,35712, 0x7fbd6605
0,  47104,  47104, 2048,36864, 0x18cb02c9
0,  49152,  49152, 2048,36864, 0x8290b628
0,  51200,  51200, 2048,36864, 0x00065519
0,  53248,  53248, 2048,36864, 0x26302fd0
0,  55296,  55296, 2048,36864, 0x0fc5652c
0,  57344,  57344, 2048,36864, 0x80f992f5
0,  59392,  59392, 2048,36864, 0x770d7bd3
0,  61440,  61440, 2048,36864, 0xf06ff731
0,  63488,  63488, 2048,36864, 0xf42f36a2
0,  65536,  65536, 2048,36864, 0x40496db9
0,  67584,  67584, 2048,36864, 0x88e3c586
0,  69632,  69632, 2048,36864, 0x4027756f
0,  71680,  71680, 2048,36864, 0x30e1e2af
0,  73728,  73728, 2048,36864, 0x794f500e
0,  75776,  75776, 2048,36864, 0x1388d154
0,  77824,  77824, 2048,36864, 0x55fef3fa
0,  79872,  79872, 2048,36864, 0x631de608
0,  81920,  81920, 2048,36864, 0xa479ecfe
0,  83968,  83968, 2048,36864, 0xe561fe79
0,  86016,  86016, 2048,36864, 0x806ae121
0,  88064,  88064, 2048,36864, 0xfa832f7d
0,  90112,  90112, 2048,36864, 0x4ba72c89
0,  92160,  92160, 2048,36864, 0xb107a5d9
0,  94208,  94208, 2048,36864, 0x0871c610
0,  96256,  96256, 2048,36864, 0xc74e0148
0,  98304,  98304, 2048,36864, 0x1134ce2e
0, 100352, 100352, 2048,36864, 0x4bf46961
0, 102400, 102400, 2048,36864, 0xee4c58ea
0, 104448, 104448, 2048,36864, 0x84cb078e
#software: Lavf57.36.100
#tb 0: 1/192000
#media_type 0: audio
#codec_id 0: pcm_s24le
#sample_rate 0: 192000
#channel_layout 0: 60f
0,  0,  0, 2048,36864, 0x60a47074
0,   2048,   2048, 2048,36864, 0xbd114c5c
0,   4096,   4096, 2048,36864, 0x0b7243ce
0,   6144,   6144, 2048,36864, 0x7f8c5b6c
0,   8192,   8192, 2048,36864, 0x02f96b0a
0,  10240,  10240, 2048,36864, 0xccf6f3fe
0,  12288,  12288, 2048,36864, 0x8c06a646
0,  14336,  14336, 2048,36864, 0x0dce889c
0,  16384,  1638

Re: [FFmpeg-devel] [PATCH 06/10] avcodec/dca_parser: improve frame end search

2016-05-20 Thread foo86
On Fri, May 13, 2016 at 12:48:28PM +0300, foo86 wrote:
> Parse core frame size directly when searching for frame end instead of
> using value extracted from previous frame.
> 
> Account for unused bits when calculating sync word distance for 14-bit
> streams to avoid alias sync detection.
> 
> Parse EXSS frame size and skip over EXSS frame to avoid alias sync
> detection.
> ---
>  libavcodec/dca_parser.c | 94 
> +
>  1 file changed, 80 insertions(+), 14 deletions(-)

Fixes parser failure with the following sample: https://0x0.st/q4G.dts
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/10] avcodec/dca: remove Rice code length limit

2016-05-20 Thread foo86
On Fri, May 20, 2016 at 03:13:22PM +0200, Christophe Gisquet wrote:
> > This is for valid bitstreams. There is no indication of limit on maximum
> > Rice code length in the XLL spec, hence existing constant is not
> > strictly "valid" (but it always worked in practice with existing
> > encoders). Reference decoder also loops indefinitely until it sees stop
> > bit here.
> 
> OK. Out of curiosity, what are classical values there? "common" and max 
> (128?).

Common values should be just a few bits. Maximum value seen in practice
was 64, hence the limit 128 I've picked initially (before I realized
get_unary(..., get_bits_left()) idiom is better).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/10] avcodec/dca: remove Rice code length limit

2016-05-20 Thread foo86
On Fri, May 20, 2016 at 02:35:53PM +0200, Christophe Gisquet wrote:
> 2016-05-13 11:48 GMT+02:00 foo86 <fooba...@gmail.com>:
> > -unsigned int v = get_unary(gb, 1, 128);
> > +unsigned int v = get_unary(gb, 1, get_bits_left(gb));
> 
> Not that the patch is not ok, but I have a few uneducated questions:
> 1) Given the get_bits_long(gb, k) afterwards, won't that code cause
> overreads for corrupted bitstreams?

This will cause overread, but that should not be a problem for checked
bitstream reader.

> 2) I haven't checked the calling code, but consequently, wouldn't it
> be better to first check that at least k+1 bits are available?

I don't think this is necessarry. Fixed length overread is safe; adding
explicit check will make code less readable IMO (and possibly slower).

> 3) 128 is already fairly large; is the new code for valid bitstreams
> (in the sense of specs and actually generated) or for corrupted
> bitstreams? I don't know where the parsing is validated afterwards
> (e.g. if there have been overreads or invalid values parsed)

This is for valid bitstreams. There is no indication of limit on maximum
Rice code length in the XLL spec, hence existing constant is not
strictly "valid" (but it always worked in practice with existing
encoders). Reference decoder also loops indefinitely until it sees stop
bit here.

Parsing is validated at the end of chs_parse_band_data(), there is an
explicit check whether overread has occured (and if it has, entire
segment is zeroed out).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/10] avcodec/dca: remove Rice code length limit

2016-05-20 Thread foo86
Ping.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 04/10] avcodec/dca: don't set initial sample_fmt

2016-05-14 Thread foo86
On Fri, May 13, 2016 at 12:00:24PM +0200, Hendrik Leppkes wrote:
> On Fri, May 13, 2016 at 11:48 AM, foo86 <fooba...@gmail.com> wrote:
> > Valid sample_fmt will be set by dcadec_decode_frame() based on stream
> > type.
> > ---
> >  libavcodec/dcadec.c | 3 ---
> >  1 file changed, 3 deletions(-)
> >
> > diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
> > index e3a4b0d..565242d 100644
> > --- a/libavcodec/dcadec.c
> > +++ b/libavcodec/dcadec.c
> > @@ -374,9 +374,6 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
> >  break;
> >  }
> >
> > -avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
> > -avctx->bits_per_raw_sample = 24;
> > -
> >  return 0;
> >  }
> >
> 
> Having an initial format for the most "common" types of streams is
> generally sensible.

Do you suggest it should be changed to AV_SAMPLE_FMT_FLTP then? Core
streams are probably the most "common".

I don't have a strong prefenence on this, but I thought that not having
initial sample_fmt set will serve as useful indication to API user that
sample_fmt can (and will) change after the frame is decoded.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 06/10] avcodec/dca_parser: improve frame end search

2016-05-13 Thread foo86
Parse core frame size directly when searching for frame end instead of
using value extracted from previous frame.

Account for unused bits when calculating sync word distance for 14-bit
streams to avoid alias sync detection.

Parse EXSS frame size and skip over EXSS frame to avoid alias sync
detection.
---
 libavcodec/dca_parser.c | 94 +
 1 file changed, 80 insertions(+), 14 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index bde7dfe..0b09ba5 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -47,6 +47,14 @@ typedef struct DCAParseContext {
 #define CORE_MARKER(state)  ((state >> 16) & 0x)
 #define EXSS_MARKER(state)  (state & 0x)
 
+#define STATE_LE(state) (((state & 0xFF00FF00) >> 8) | ((state & 
0x00FF00FF) << 8))
+#define STATE_14(state) (((state & 0x3FFF) >> 8) | ((state & 
0x3FFF) >> 6))
+
+#define CORE_FRAMESIZE(state)   (((state >> 4) & 0x3FFF) + 1)
+#define EXSS_FRAMESIZE(state)   ((state & 0x20) ? \
+ ((state >>  5) & 0xF) + 1 : \
+ ((state >> 13) & 0x0) + 1)
+
 /**
  * Find the end of the current frame in the bitstream.
  * @return the position of the first byte of the next frame, or -1
@@ -54,12 +62,13 @@ typedef struct DCAParseContext {
 static int dca_find_frame_end(DCAParseContext *pc1, const uint8_t *buf,
   int buf_size)
 {
-int start_found, i;
+int start_found, size, i;
 uint64_t state;
 ParseContext *pc = >pc;
 
 start_found = pc->frame_start_found;
 state   = pc->state64;
+size= pc1->size;
 
 i = 0;
 if (!start_found) {
@@ -80,15 +89,75 @@ static int dca_find_frame_end(DCAParseContext *pc1, const 
uint8_t *buf,
 }
 }
 }
+
 if (start_found) {
 for (; i < buf_size; i++) {
-pc1->size++;
+size++;
 state = (state << 8) | buf[i];
+
+if (start_found == 1) {
+switch (pc1->lastmarker) {
+case DCA_SYNCWORD_CORE_BE:
+if (size == 2) {
+pc1->framesize = CORE_FRAMESIZE(state);
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_CORE_LE:
+if (size == 2) {
+pc1->framesize = CORE_FRAMESIZE(STATE_LE(state));
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_CORE_14B_BE:
+if (size == 4) {
+pc1->framesize = CORE_FRAMESIZE(STATE_14(state)) * 8 / 
14 * 2;
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_CORE_14B_LE:
+if (size == 4) {
+pc1->framesize = 
CORE_FRAMESIZE(STATE_14(STATE_LE(state))) * 8 / 14 * 2;
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_SUBSTREAM:
+if (size == 6) {
+pc1->framesize = EXSS_FRAMESIZE(state);
+start_found= 2;
+}
+break;
+default:
+av_assert0(0);
+}
+continue;
+}
+
+if (pc1->lastmarker == DCA_SYNCWORD_CORE_BE) {
+if (pc1->framesize > size + 2)
+continue;
+
+if (start_found == 2 && IS_EXSS_MARKER(state)) {
+pc1->framesize = size + 2;
+start_found= 3;
+continue;
+}
+
+if (start_found == 3) {
+if (size == pc1->framesize + 4) {
+pc1->framesize += EXSS_FRAMESIZE(state);
+start_found = 4;
+}
+continue;
+}
+}
+
+if (pc1->framesize > size)
+continue;
+
 if (IS_MARKER(state) &&
 (pc1->lastmarker == CORE_MARKER(state) ||
  pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM)) {
-if (pc1->framesize > pc1->size)
-continue;
 pc->frame_start_found = 0;
 pc->state64   = -1;
 pc1->size = 0;
@@ -96,8 +165,10 @@ static int dca_find_frame_end(DCAParseContext *pc1, const 
uint8_t *buf,
 }
 }
 }
+
 pc->frame_start_found = start_found;
 pc->state64   = state;
+pc1->size = size;
 return END_NOT_FOUND;
 }
 
@@ -110,11 +181,11 @@ static av_cold int dca_parse_init(AVCodecParserContext *s)
 }
 
 static int 

[FFmpeg-devel] [PATCH 05/10] avcodec/dca: use LUT for LBR frequency ranges

2016-05-13 Thread foo86
Values for unsupported frequencies > 48000 Hz are still included (parser
will make use of them).

Also convert sampling frequencies array to unsigned.
---
 libavcodec/dca_lbr.c | 15 +--
 libavcodec/dcadata.c |  6 +-
 libavcodec/dcadata.h |  3 ++-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 9a7f4cd..f116ab9 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -1000,15 +1000,15 @@ static int parse_decoder_init(DCALbrDecoder *s, 
GetByteContext *gb)
 int old_band_limit = s->band_limit;
 int old_nchannels = s->nchannels;
 int version, bit_rate_hi;
-unsigned int code;
+unsigned int sr_code;
 
 // Sample rate of LBR audio
-code = bytestream2_get_byte(gb);
-if (code >= FF_ARRAY_ELEMS(ff_dca_sampling_freqs)) {
+sr_code = bytestream2_get_byte(gb);
+if (sr_code >= FF_ARRAY_ELEMS(ff_dca_sampling_freqs)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid LBR sample rate\n");
 return AVERROR_INVALIDDATA;
 }
-s->sample_rate = ff_dca_sampling_freqs[code];
+s->sample_rate = ff_dca_sampling_freqs[sr_code];
 if (s->sample_rate > 48000) {
 avpriv_report_missing_feature(s->avctx, "%d Hz LBR sample rate", 
s->sample_rate);
 return AVERROR_PATCHWELCOME;
@@ -1076,12 +1076,7 @@ static int parse_decoder_init(DCALbrDecoder *s, 
GetByteContext *gb)
 }
 
 // Setup frequency range
-if (s->sample_rate < 14000)
-s->freq_range = 0;
-else if (s->sample_rate < 28000)
-s->freq_range = 1;
-else
-s->freq_range = 2;
+s->freq_range = ff_dca_freq_ranges[sr_code];
 
 // Setup resolution profile
 if (s->bit_rate_orig >= 44000 * (s->nchannels_total + 2))
diff --git a/libavcodec/dcadata.c b/libavcodec/dcadata.c
index 53be01d..2d533d0 100644
--- a/libavcodec/dcadata.c
+++ b/libavcodec/dcadata.c
@@ -8725,11 +8725,15 @@ const int32_t ff_dca_xll_band_coeff[20] = {
  3259333, -5074941,  6928550, -8204883
 };
 
-const int32_t ff_dca_sampling_freqs[16] = {
+const uint32_t ff_dca_sampling_freqs[16] = {
   8000,  16000, 32000, 64000, 128000, 22050,  44100,  88200,
 176400, 352800, 12000, 24000,  48000, 96000, 192000, 384000,
 };
 
+const uint8_t ff_dca_freq_ranges[16] = {
+0, 1, 2, 3, 4, 1, 2, 3, 4, 4, 0, 1, 2, 3, 4, 4
+};
+
 const uint16_t ff_dca_avg_g3_freqs[3] = { 16000, 18000, 24000 };
 
 const uint16_t ff_dca_fst_amp[44] = {
diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h
index 0c54225..1ef1342 100644
--- a/libavcodec/dcadata.h
+++ b/libavcodec/dcadata.h
@@ -71,7 +71,8 @@ extern const uint16_t ff_dca_xll_refl_coeff[128];
 
 extern const int32_t ff_dca_xll_band_coeff[20];
 
-extern const int32_t ff_dca_sampling_freqs[16];
+extern const uint32_t ff_dca_sampling_freqs[16];
+extern const uint8_t ff_dca_freq_ranges[16];
 
 extern const uint16_t ff_dca_avg_g3_freqs[3];
 
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 08/10] avcodec/dca: require checked bitstream reader

2016-05-13 Thread foo86
Remove half-working attempt at supporting unchecked bitstream reader by
always copying input data into intermediate buffer with large amount of
padding at the end.

Convert LBR decoder to checked bitstream reader. Convert
dcadec_decode_frame() to parse input data directly if possible.
---
 libavcodec/dca_lbr.c |  1 -
 libavcodec/dca_xll.c |  2 +-
 libavcodec/dcadec.c  | 44 
 libavcodec/dcadec.h  |  2 --
 4 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index f116ab9..342603c 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define UNCHECKED_BITSTREAM_READER  1
 #define BITSTREAM_READER_LE
 
 #include "libavutil/channel_layout.h"
diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index e43ee6a..1d616c2 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -1070,7 +1070,7 @@ static int copy_to_pbr(DCAXllDecoder *s, uint8_t *data, 
int size, int delay)
 if (size > DCA_XLL_PBR_BUFFER_MAX)
 return AVERROR(ENOSPC);
 
-if (!s->pbr_buffer && !(s->pbr_buffer = av_malloc(DCA_XLL_PBR_BUFFER_MAX + 
DCA_BUFFER_PADDING_SIZE)))
+if (!s->pbr_buffer && !(s->pbr_buffer = av_malloc(DCA_XLL_PBR_BUFFER_MAX + 
AV_INPUT_BUFFER_PADDING_SIZE)))
 return AVERROR(ENOMEM);
 
 memcpy(s->pbr_buffer, data, size);
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 565242d..4146a85 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -141,22 +141,6 @@ void ff_dca_downmix_to_stereo_float(AVFloatDSPContext 
*fdsp, float **samples,
 }
 }
 
-static int convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, 
int max_size)
-{
-switch (AV_RB32(src)) {
-case DCA_SYNCWORD_CORE_BE:
-case DCA_SYNCWORD_SUBSTREAM:
-memcpy(dst, src, src_size);
-return src_size;
-case DCA_SYNCWORD_CORE_LE:
-case DCA_SYNCWORD_CORE_14B_BE:
-case DCA_SYNCWORD_CORE_14B_LE:
-return avpriv_dca_convert_bitstream(src, src_size, dst, max_size);
-default:
-return AVERROR_INVALIDDATA;
-}
-}
-
 static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
 {
@@ -165,27 +149,31 @@ static int dcadec_decode_frame(AVCodecContext *avctx, 
void *data,
 uint8_t *input = avpkt->data;
 int input_size = avpkt->size;
 int i, ret, prev_packet = s->packet;
+uint32_t mrk;
 
 if (input_size < MIN_PACKET_SIZE || input_size > MAX_PACKET_SIZE) {
 av_log(avctx, AV_LOG_ERROR, "Invalid packet size\n");
 return AVERROR_INVALIDDATA;
 }
 
-av_fast_malloc(>buffer, >buffer_size,
-   FFALIGN(input_size, 4096) + DCA_BUFFER_PADDING_SIZE);
-if (!s->buffer)
-return AVERROR(ENOMEM);
+// Convert input to BE format
+mrk = AV_RB32(input);
+if (mrk != DCA_SYNCWORD_CORE_BE && mrk != DCA_SYNCWORD_SUBSTREAM) {
+av_fast_padded_malloc(>buffer, >buffer_size, input_size);
+if (!s->buffer)
+return AVERROR(ENOMEM);
 
-for (i = 0, ret = AVERROR_INVALIDDATA; i < input_size - MIN_PACKET_SIZE + 
1 && ret < 0; i++)
-ret = convert_bitstream(input + i, input_size - i, s->buffer, 
s->buffer_size);
+for (i = 0, ret = AVERROR_INVALIDDATA; i < input_size - 
MIN_PACKET_SIZE + 1 && ret < 0; i++)
+ret = avpriv_dca_convert_bitstream(input + i, input_size - i, 
s->buffer, s->buffer_size);
 
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
-return ret;
-}
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
+return ret;
+}
 
-input  = s->buffer;
-input_size = ret;
+input  = s->buffer;
+input_size = ret;
+}
 
 s->packet = 0;
 
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index f52d9f7..0fe4042 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -34,8 +34,6 @@
 #include "dca_xll.h"
 #include "dca_lbr.h"
 
-#define DCA_BUFFER_PADDING_SIZE 1024
-
 #define DCA_PACKET_CORE 0x01
 #define DCA_PACKET_EXSS 0x02
 #define DCA_PACKET_XLL  0x04
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 10/10] avcodec/dca: remove useless debug message

2016-05-13 Thread foo86
Most DTS-in-WAV streams trigger this, making debug output hard to read.
---
 libavcodec/dca_core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index f6c22ca..46825ed 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1921,10 +1921,8 @@ int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, 
int size)
 return ret;
 
 // Workaround for DTS in WAV
-if (s->frame_size > size && s->frame_size < size + 4) {
-av_log(s->avctx, AV_LOG_DEBUG, "Working around excessive core frame 
size (%d > %d)\n", s->frame_size, size);
+if (s->frame_size > size && s->frame_size < size + 4)
 s->frame_size = size;
-}
 
 if (ff_dca_seek_bits(>gb, s->frame_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Read past end of core frame\n");
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 07/10] avcodec/dca_parser: set duration for core-less streams

2016-05-13 Thread foo86
This requires parsing EXSS in dca_parse(). Adapt ff_dca_exss_parse()
signature and disable header CRC check when avctx->priv_data is NULL.
---
 libavcodec/dca_exss.c   |  2 +-
 libavcodec/dca_exss.h   |  2 +-
 libavcodec/dca_parser.c | 70 ++---
 libavcodec/dcadec.h |  2 ++
 4 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 87b2f42..8d0b63f 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -375,7 +375,7 @@ static int set_exss_offsets(DCAExssAsset *asset)
 return 0;
 }
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size)
 {
 int i, ret, offset, wide_hdr, header_size;
 
diff --git a/libavcodec/dca_exss.h b/libavcodec/dca_exss.h
index 323063a..208fae1 100644
--- a/libavcodec/dca_exss.h
+++ b/libavcodec/dca_exss.h
@@ -87,6 +87,6 @@ typedef struct DCAExssParser {
 DCAExssAsset   assets[1];///< Audio asset descriptors
 } DCAExssParser;
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size);
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size);
 
 #endif
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 0b09ba5..02e8322 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -23,6 +23,8 @@
  */
 
 #include "dca.h"
+#include "dcadata.h"
+#include "dca_exss.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
 #include "parser.h"
@@ -32,6 +34,8 @@ typedef struct DCAParseContext {
 uint32_t lastmarker;
 int size;
 int framesize;
+DCAExssParser exss;
+unsigned int sr_code;
 } DCAParseContext;
 
 #define IS_CORE_MARKER(state) \
@@ -177,11 +181,12 @@ static av_cold int dca_parse_init(AVCodecParserContext *s)
 DCAParseContext *pc1 = s->priv_data;
 
 pc1->lastmarker = 0;
+pc1->sr_code = -1;
 return 0;
 }
 
-static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
-int *sample_rate)
+static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf,
+int buf_size, int *duration, int *sample_rate)
 {
 GetBitContext gb;
 uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
@@ -190,6 +195,63 @@ static int dca_parse_params(const uint8_t *buf, int 
buf_size, int *duration,
 if (buf_size < 12)
 return AVERROR_INVALIDDATA;
 
+if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) {
+DCAExssAsset *asset = >exss.assets[0];
+
+if ((ret = ff_dca_exss_parse(>exss, buf, buf_size)) < 0)
+return ret;
+
+if (asset->extension_mask & DCA_EXSS_LBR) {
+if ((ret = init_get_bits8(, buf + asset->lbr_offset, 
asset->lbr_size)) < 0)
+return ret;
+
+if (get_bits_long(, 32) != DCA_SYNCWORD_LBR)
+return AVERROR_INVALIDDATA;
+
+switch (get_bits(, 8)) {
+case 2:
+pc1->sr_code = get_bits(, 8);
+case 1:
+break;
+default:
+return AVERROR_INVALIDDATA;
+}
+
+if (pc1->sr_code >= FF_ARRAY_ELEMS(ff_dca_sampling_freqs))
+return AVERROR_INVALIDDATA;
+
+*sample_rate = ff_dca_sampling_freqs[pc1->sr_code];
+*duration = 1024 << ff_dca_freq_ranges[pc1->sr_code];
+return 0;
+}
+
+if (asset->extension_mask & DCA_EXSS_XLL) {
+int nsamples_log2;
+
+if ((ret = init_get_bits8(, buf + asset->xll_offset, 
asset->xll_size)) < 0)
+return ret;
+
+if (get_bits_long(, 32) != DCA_SYNCWORD_XLL)
+return AVERROR_INVALIDDATA;
+
+if (get_bits(, 4))
+return AVERROR_INVALIDDATA;
+
+skip_bits(, 8);
+skip_bits_long(, get_bits(, 5) + 1);
+skip_bits(, 4);
+nsamples_log2 = get_bits(, 4) + get_bits(, 4);
+if (nsamples_log2 > 24)
+return AVERROR_INVALIDDATA;
+
+*sample_rate = asset->max_sample_rate;
+*duration = (1 + (*sample_rate > 96000)) << nsamples_log2;
+return 0;
+}
+
+return AVERROR_INVALIDDATA;
+}
+
 if ((ret = avpriv_dca_convert_bitstream(buf, 12, hdr, 12)) < 0)
 return ret;
 
@@ -229,8 +291,10 @@ static int dca_parse(AVCodecParserContext *s, 
AVCodecContext *avctx,
 }
 }
 
+pc1->exss.avctx = avctx;
+
 /* read the duration and sample rate from the frame header */
-if (!dca_parse_params(buf, buf_size, , _rate)) {
+if (!dca_parse_params(pc1, buf, buf_size, , _rate)) {
 if (!avctx->sample_rate)
 avctx->sample_rate = sample_rate;
 s->duration = av_rescale(duration, avctx->sample_rate, sample_rate);
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 8528332..f52d9f7 100644
--- 

[FFmpeg-devel] [PATCH 02/10] avcodec/dca: simplify 'residual ok' flag tracking

2016-05-13 Thread foo86
Move this from separate structure field to a packet flag.

Behavior should be equivalent, except that residual flag is now properly
cleared when packet has no core frame at all.

Also print a message when forcing recovery mode due to invalid residual
to make debugging easier.
---
 libavcodec/dcadec.c | 32 ++--
 libavcodec/dcadec.h |  7 ---
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 303b0c2..dac86eb 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -191,10 +191,8 @@ static int dcadec_decode_frame(AVCodecContext *avctx, void 
*data,
 if (AV_RB32(input) == DCA_SYNCWORD_CORE_BE) {
 int frame_size;
 
-if ((ret = ff_dca_core_parse(>core, input, input_size)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_parse(>core, input, input_size)) < 0)
 return ret;
-}
 
 s->packet |= DCA_PACKET_CORE;
 
@@ -263,19 +261,20 @@ static int dcadec_decode_frame(AVCodecContext *avctx, 
void *data,
 if (s->xll.chset[0].freq == 96000 && s->core.sample_rate == 48000)
 x96_synth = 1;
 
-if ((ret = ff_dca_core_filter_fixed(>core, x96_synth)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_filter_fixed(>core, x96_synth)) < 0)
 return ret;
-}
 
 // Force lossy downmixed output on the first core frame filtered.
 // This prevents audible clicks when seeking and is consistent with
 // what reference decoder does when there are multiple channel 
sets.
-if (!s->core_residual_valid) {
-if (s->xll.nreschsets > 0 && s->xll.nchsets > 1)
-s->packet |= DCA_PACKET_RECOVERY;
-s->core_residual_valid = 1;
+if (!(prev_packet & DCA_PACKET_RESIDUAL) && s->xll.nreschsets > 0
+&& s->xll.nchsets > 1) {
+av_log(avctx, AV_LOG_VERBOSE, "Forcing XLL recovery mode\n");
+s->packet |= DCA_PACKET_RECOVERY;
 }
+
+// Set 'residual ok' flag for the next frame
+s->packet |= DCA_PACKET_RESIDUAL;
 }
 
 if ((ret = ff_dca_xll_filter_frame(>xll, frame)) < 0) {
@@ -284,17 +283,14 @@ static int dcadec_decode_frame(AVCodecContext *avctx, 
void *data,
 return ret;
 if (ret != AVERROR_INVALIDDATA || (avctx->err_recognition & 
AV_EF_EXPLODE))
 return ret;
-if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0)
 return ret;
-}
 }
 } else if (s->packet & DCA_PACKET_CORE) {
-if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0)
 return ret;
-}
-s->core_residual_valid = !!(s->core.filter_mode & 
DCA_FILTER_MODE_FIXED);
+if (s->core.filter_mode & DCA_FILTER_MODE_FIXED)
+s->packet |= DCA_PACKET_RESIDUAL;
 } else {
 return AVERROR_INVALIDDATA;
 }
@@ -312,7 +308,7 @@ static av_cold void dcadec_flush(AVCodecContext *avctx)
 ff_dca_xll_flush(>xll);
 ff_dca_lbr_flush(>lbr);
 
-s->core_residual_valid = 0;
+s->packet &= DCA_PACKET_MASK;
 }
 
 static av_cold int dcadec_close(AVCodecContext *avctx)
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 5e47077..8528332 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -40,7 +40,10 @@
 #define DCA_PACKET_EXSS 0x02
 #define DCA_PACKET_XLL  0x04
 #define DCA_PACKET_LBR  0x08
-#define DCA_PACKET_RECOVERY 0x10
+#define DCA_PACKET_MASK 0x0f
+
+#define DCA_PACKET_RECOVERY 0x10///< Sync error recovery flag
+#define DCA_PACKET_RESIDUAL 0x20///< Core valid for residual decoding
 
 typedef struct DCAContext {
 const AVClass   *class;   ///< class for AVOptions
@@ -60,8 +63,6 @@ typedef struct DCAContext {
 
 int packet; ///< Packet flags
 
-int core_residual_valid;///< Core valid for residual decoding
-
 int request_channel_layout; ///< Converted from 
avctx.request_channel_layout
 int core_only;  ///< Core only decoding flag
 } DCAContext;
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 01/10] avcodec/dca: remove Rice code length limit

2016-05-13 Thread foo86
Limit the maximum length of unary part of Rice code by the number of
available bits instead of using an arbitrary constant that happens to be
just large enough to work.
---
 libavcodec/dca_xll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 316af27..e43ee6a 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -32,7 +32,7 @@ static int get_linear(GetBitContext *gb, int n)
 
 static int get_rice_un(GetBitContext *gb, int k)
 {
-unsigned int v = get_unary(gb, 1, 128);
+unsigned int v = get_unary(gb, 1, get_bits_left(gb));
 return (v << k) | get_bits_long(gb, k);
 }
 
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH v2 0/3] DTS Express (LBR) decoder

2016-05-09 Thread foo86
On Sun, May 01, 2016 at 03:30:27PM -0300, James Almer wrote:
> With the samples you shared and with a random lbr-in-wav mono sample i found
> in the wild i get the following when i try to do a codec copy.
> Core and every other DTS extension in contrast seem to set timestamps just
> fine.
> 
> #tb 0: 1/9
> #media_type 0: audio
> #codec_id 0: dts
> #sample_rate 0: 48000
> #channel_layout 0: 60f
> Output #0, framecrc, to 'pipe:':
> Stream #0:0: Audio: dts (DTS Express), 48000 Hz, 5.1(side), 505 kb/s
> Stream mapping:
>   Stream #0:0 -> #0:0 (copy)
> Press [q] to stop, [?] for help
> [framecrc @ 00670100] Timestamps are unset in a packet for stream 0. 
> This is deprecated and will stop working in the future. Fix your code to set 
> the timestamps properly
> 0,  0,  0,0, 5440, 0xdc73e46d
> 0,  0,  0,0, 5440, 0x7f66bd99
> 0,  0,  0,0, 5440, 0x116f2d31
> 0,  0,  0,0, 5440, 0x37a82646
> 0,  0,  0,0, 5440, 0xcc294e39
> 0,  0,  0,0, 5440, 0x2293455d
> 0,  0,  0,0, 5440, 0xbd9b25d3
> 0,  0,  0,0, 5440, 0xf9331333
> 0,  0,  0,0, 5440, 0xb96d5581
> 0,  0,  0,0, 5440, 0x56f55088
> 0,  0,  0,0, 5440, 0x32f81f50
> 0,  0,  0,0, 5440, 0x8a0c986d
> 0,  0,  0,0, 5440, 0x21615dea
> 0,  0,  0,0, 5440, 0x5adc77e9
> 0,  0,  0,0, 5440, 0x228e5088
> 0,  0,  0,0, 5440, 0xd0029e27
> 0,  0,  0,0, 5440, 0x472d4f33
> 0,  0,  0,0, 5440, 0xdaff4ac1
> size=   1kB time=00:00:00.00 bitrate=N/A speed=   0x
> video:0kB audio:96kB subtitle:0kB other streams:0kB global headers:0kB muxing 
> overhead: unknown

Attached patch fixes timestamps for core-less DTS for me.
commit 49f02f6422e84cf381eb100b510680ecf46f7a76
Author: foo86 <fooba...@gmail.com>
Date:   Mon May 9 20:08:21 2016 +0300

avcodec/dca_parser: set duration for core-less streams

diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 87b2f42..8d0b63f 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -375,7 +375,7 @@ static int set_exss_offsets(DCAExssAsset *asset)
 return 0;
 }
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size)
 {
 int i, ret, offset, wide_hdr, header_size;
 
diff --git a/libavcodec/dca_exss.h b/libavcodec/dca_exss.h
index 323063a..208fae1 100644
--- a/libavcodec/dca_exss.h
+++ b/libavcodec/dca_exss.h
@@ -87,6 +87,6 @@ typedef struct DCAExssParser {
 DCAExssAsset   assets[1];///< Audio asset descriptors
 } DCAExssParser;
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size);
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size);
 
 #endif
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index bde7dfe..83e011c 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -23,6 +23,8 @@
  */
 
 #include "dca.h"
+#include "dcadata.h"
+#include "dca_exss.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
 #include "parser.h"
@@ -32,6 +34,8 @@ typedef struct DCAParseContext {
 uint32_t lastmarker;
 int size;
 int framesize;
+DCAExssParser exss;
+unsigned int sr_code;
 } DCAParseContext;
 
 #define IS_CORE_MARKER(state) \
@@ -106,11 +110,12 @@ static av_cold int dca_parse_init(AVCodecParserContext *s)
 DCAParseContext *pc1 = s->priv_data;
 
 pc1->lastmarker = 0;
+pc1->sr_code = -1;
 return 0;
 }
 
 static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
-int *sample_rate, int *framesize)
+int *sample_rate, DCAParseContext *pc)
 {
 GetBitContext gb;
 uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
@@ -119,6 +124,65 @@ static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
 if (buf_size < 12)
 return AVERROR_INVALIDDATA;
 
+if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) {
+DCAExssAsset *asset = >exss.assets[0];
+
+if ((ret = ff_dca_exss_parse(>exss, buf, buf_size)) < 0)
+return ret;
+
+pc->framesize = 0;
+
+if (asset->extension_mask & DCA_EXSS_LBR) {
+if ((ret = init_get_bits8(, buf + asset->lbr_offset, asset->lbr_size)) < 0)
+return ret;
+
+if (get_bits_long(, 32) != DCA_SYNCWORD_LBR)
+

[FFmpeg-devel] [PATCH v3 2/2] avformat/dtsdec: detect core-less streams

2016-05-03 Thread foo86
---

Updated detection algorithm.

 libavformat/dtsdec.c | 47 ---
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index ef28391..702a417 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/crc.h"
+
 #include "libavcodec/bytestream.h"
 #include "libavcodec/dca.h"
 #include "libavcodec/dca_syncwords.h"
@@ -32,23 +34,51 @@ static int dts_probe(AVProbeData *p)
 const uint8_t *buf, *bufp;
 uint32_t state = -1;
 int markers[4*16] = {0};
-int sum, max, i;
+int exss_markers = 0, exss_nextpos = 0;
+int sum, max, pos, i;
 int64_t diff = 0;
 uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+const AVCRC *crctab = av_crc_get_table(AV_CRC_16_CCITT);
 
-buf = p->buf + FFMIN(4096, p->buf_size);
-
-for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
+for (pos = FFMIN(4096, p->buf_size); pos < p->buf_size - 2; pos += 2) {
 int marker, sample_blocks, sample_rate, sr_code, framesize;
-int lfe;
+int lfe, wide_hdr, hdr_size;
 GetBitContext gb;
 
-bufp = buf;
+bufp = buf = p->buf + pos;
 state = (state << 16) | bytestream_get_be16();
 
-if (buf - p->buf >= 4)
+if (pos >= 4)
 diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4));
 
+/* extension substream (EXSS) */
+if (state == DCA_SYNCWORD_SUBSTREAM) {
+if (pos < exss_nextpos)
+continue;
+
+init_get_bits(, buf - 2, 96);
+skip_bits_long(, 42);
+
+wide_hdr  = get_bits1();
+hdr_size  = get_bits(,  8 + 4 * wide_hdr) + 1;
+framesize = get_bits(, 16 + 4 * wide_hdr) + 1;
+if (hdr_size & 3 || framesize & 3)
+continue;
+if (hdr_size < 16 || framesize < hdr_size)
+continue;
+if (pos - 2 + hdr_size > p->buf_size)
+continue;
+if (av_crc(crctab, 0x, buf + 3, hdr_size - 5))
+continue;
+
+if (pos == exss_nextpos)
+exss_markers++;
+else
+exss_markers = FFMAX(1, exss_markers - 1);
+exss_nextpos = pos + framesize;
+continue;
+}
+
 /* regular bitstream */
 if (state == DCA_SYNCWORD_CORE_BE &&
 (bytestream_get_be16() & 0xFC00) == 0xFC00)
@@ -103,6 +133,9 @@ static int dts_probe(AVProbeData *p)
 markers[marker] ++;
 }
 
+if (exss_markers > 3)
+return AVPROBE_SCORE_EXTENSION + 1;
+
 sum = max = 0;
 for (i=0; i

[FFmpeg-devel] [PATCH v2 1/2] avcodec/dca: convert to AVCRC

2016-05-02 Thread foo86
---
 libavcodec/dca_core.c | 25 ++---
 libavcodec/dca_exss.c |  3 +--
 libavcodec/dca_xll.c  |  9 +++--
 libavcodec/dcadec.c   | 29 ++---
 libavcodec/dcadec.h   | 19 +--
 5 files changed, 33 insertions(+), 52 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 58c78f7..f6c22ca 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -269,8 +269,7 @@ static int parse_coding_header(DCACoreDecoder *s, enum 
HeaderType header, int xc
 
 // Check CRC
 if (s->xxch_crc_present
-&& (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos, header_pos + header_size * 
8)) {
+&& ff_dca_check_crc(s->avctx, >gb, header_pos, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid XXCH channel set header 
checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -977,8 +976,7 @@ static int parse_xxch_frame(DCACoreDecoder *s)
 header_size = get_bits(>gb, 6) + 1;
 
 // Check XXCH frame header CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos + 32, header_pos + header_size 
* 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, header_pos + 32, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid XXCH frame header checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1193,8 +1191,7 @@ static int parse_xbr_frame(DCACoreDecoder *s)
 header_size = get_bits(>gb, 6) + 1;
 
 // Check XBR frame header CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos + 32, header_pos + header_size 
* 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, header_pos + 32, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid XBR frame header checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1509,8 +1506,7 @@ static int parse_x96_coding_header(DCACoreDecoder *s, int 
exss, int xch_base)
 
 // Check CRC
 if (s->x96_crc_present
-&& (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos, header_pos + header_size * 
8)) {
+&& ff_dca_check_crc(s->avctx, >gb, header_pos, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid X96 channel set header 
checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1665,8 +1661,7 @@ static int parse_x96_frame_exss(DCACoreDecoder *s)
 header_size = get_bits(>gb, 6) + 1;
 
 // Check X96 frame header CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos + 32, header_pos + header_size 
* 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, header_pos + 32, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid X96 frame header checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1785,8 +1780,7 @@ static int parse_aux_data(DCACoreDecoder *s)
 skip_bits(>gb, 16);
 
 // Check CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, aux_pos, get_bits_count(>gb))) {
+if (ff_dca_check_crc(s->avctx, >gb, aux_pos, get_bits_count(>gb))) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid auxiliary data checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1884,9 +1878,10 @@ static int parse_optional_info(DCACoreDecoder *s)
 if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_XXCH) 
{
 s->gb.index = (sync_pos + 1) * 32;
 size = get_bits(>gb, 6) + 1;
-if (size >= 11 &&
-!ff_dca_check_crc(>gb, (sync_pos + 1) * 32,
-  sync_pos * 32 + size * 8)) {
+dist = s->gb.size_in_bits / 8 - sync_pos * 4;
+if (size >= 11 && size <= dist &&
+!av_crc(dca->crctab, 0x, s->gb.buffer +
+(sync_pos + 1) * 4, size - 4)) {
 s->xxch_pos = sync_pos * 32;
 break;
 }
diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 36314c2..87b2f42 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -398,8 +398,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int 
size)
 header_size = get_bits(>gb, 8 + 4 * wide_hdr) + 1;
 
 // Check CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, 32 + 8, header_size * 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, 32 + 8, header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid EXSS header checksum\n");
 return AVERROR_INVALIDDATA;
 }

[FFmpeg-devel] [PATCH 3/3] avformat/dtsdec: detect core-less streams

2016-05-02 Thread foo86
---
 libavformat/dtsdec.c | 42 +++---
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index ef28391..b54b6ef 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -32,23 +32,48 @@ static int dts_probe(AVProbeData *p)
 const uint8_t *buf, *bufp;
 uint32_t state = -1;
 int markers[4*16] = {0};
-int sum, max, i;
+int exss_markers = 0, exss_crcsize = 0, exss_nextpos = 0;
+int sum, max, pos, i;
 int64_t diff = 0;
 uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
 
-buf = p->buf + FFMIN(4096, p->buf_size);
-
-for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
+for (pos = FFMIN(4096, p->buf_size); pos < p->buf_size - 2; pos += 2) {
 int marker, sample_blocks, sample_rate, sr_code, framesize;
-int lfe;
+int lfe, wide_hdr, hdr_size;
 GetBitContext gb;
 
-bufp = buf;
+bufp = buf = p->buf + pos;
 state = (state << 16) | bytestream_get_be16();
 
-if (buf - p->buf >= 4)
+if (pos >= 4)
 diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4));
 
+/* extension substream (EXSS) */
+if (state == DCA_SYNCWORD_SUBSTREAM) {
+if (pos < exss_nextpos)
+continue;
+
+init_get_bits(, buf - 2, 96);
+skip_bits_long(, 42);
+
+wide_hdr  = get_bits1();
+hdr_size  = get_bits(,  8 + 4 * wide_hdr) + 1;
+framesize = get_bits(, 16 + 4 * wide_hdr) + 1;
+if (hdr_size & 3 || framesize & 3)
+continue;
+if (hdr_size < 16 || framesize < hdr_size)
+continue;
+if (pos - 2 + hdr_size > p->buf_size)
+continue;
+if (avpriv_dca_compute_crc(buf + 3, hdr_size - 5))
+continue;
+
+exss_markers++;
+exss_crcsize += hdr_size - 5;
+exss_nextpos  = pos + framesize;
+continue;
+}
+
 /* regular bitstream */
 if (state == DCA_SYNCWORD_CORE_BE &&
 (bytestream_get_be16() & 0xFC00) == 0xFC00)
@@ -103,6 +128,9 @@ static int dts_probe(AVProbeData *p)
 markers[marker] ++;
 }
 
+if (exss_markers > 3 && exss_crcsize > 100)
+return AVPROBE_SCORE_EXTENSION + 1;
+
 sum = max = 0;
 for (i=0; i

[FFmpeg-devel] [PATCH 2/3] avcodec/dca: inline ff_dca_check_crc()

2016-05-02 Thread foo86
---
 libavcodec/dca_core.c | 25 ++---
 libavcodec/dca_exss.c |  3 +--
 libavcodec/dca_xll.c  |  9 +++--
 libavcodec/dcadec.c   |  9 -
 libavcodec/dcadec.h   | 12 ++--
 5 files changed, 24 insertions(+), 34 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 58c78f7..c2485e3 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -269,8 +269,7 @@ static int parse_coding_header(DCACoreDecoder *s, enum 
HeaderType header, int xc
 
 // Check CRC
 if (s->xxch_crc_present
-&& (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos, header_pos + header_size * 
8)) {
+&& ff_dca_check_crc(s->avctx, >gb, header_pos, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid XXCH channel set header 
checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -977,8 +976,7 @@ static int parse_xxch_frame(DCACoreDecoder *s)
 header_size = get_bits(>gb, 6) + 1;
 
 // Check XXCH frame header CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos + 32, header_pos + header_size 
* 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, header_pos + 32, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid XXCH frame header checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1193,8 +1191,7 @@ static int parse_xbr_frame(DCACoreDecoder *s)
 header_size = get_bits(>gb, 6) + 1;
 
 // Check XBR frame header CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos + 32, header_pos + header_size 
* 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, header_pos + 32, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid XBR frame header checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1509,8 +1506,7 @@ static int parse_x96_coding_header(DCACoreDecoder *s, int 
exss, int xch_base)
 
 // Check CRC
 if (s->x96_crc_present
-&& (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos, header_pos + header_size * 
8)) {
+&& ff_dca_check_crc(s->avctx, >gb, header_pos, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid X96 channel set header 
checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1665,8 +1661,7 @@ static int parse_x96_frame_exss(DCACoreDecoder *s)
 header_size = get_bits(>gb, 6) + 1;
 
 // Check X96 frame header CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, header_pos + 32, header_pos + header_size 
* 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, header_pos + 32, header_pos + 
header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid X96 frame header checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1785,8 +1780,7 @@ static int parse_aux_data(DCACoreDecoder *s)
 skip_bits(>gb, 16);
 
 // Check CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, aux_pos, get_bits_count(>gb))) {
+if (ff_dca_check_crc(s->avctx, >gb, aux_pos, get_bits_count(>gb))) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid auxiliary data checksum\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1884,9 +1878,10 @@ static int parse_optional_info(DCACoreDecoder *s)
 if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_XXCH) 
{
 s->gb.index = (sync_pos + 1) * 32;
 size = get_bits(>gb, 6) + 1;
-if (size >= 11 &&
-!ff_dca_check_crc(>gb, (sync_pos + 1) * 32,
-  sync_pos * 32 + size * 8)) {
+dist = s->gb.size_in_bits / 8 - sync_pos * 4;
+if (size >= 11 && size <= dist &&
+!avpriv_dca_compute_crc(s->gb.buffer +
+(sync_pos + 1) * 4, size - 4)) 
{
 s->xxch_pos = sync_pos * 32;
 break;
 }
diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 36314c2..87b2f42 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -398,8 +398,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int 
size)
 header_size = get_bits(>gb, 8 + 4 * wide_hdr) + 1;
 
 // Check CRC
-if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
-&& ff_dca_check_crc(>gb, 32 + 8, header_size * 8)) {
+if (ff_dca_check_crc(s->avctx, >gb, 32 + 8, header_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid EXSS header checksum\n");
 return AVERROR_INVALIDDATA;
 }
diff --git 

[FFmpeg-devel] [PATCH 1/3] avcodec: add avpriv_dca_compute_crc()

2016-05-02 Thread foo86
---
 libavcodec/dca.c | 18 ++
 libavcodec/dca.h |  5 +
 libavcodec/dcadec.c  | 20 +---
 libavcodec/version.h |  2 +-
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index 714509b..be89d0d 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -71,3 +71,21 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, int 
src_size, uint8_t *dst,
 return AVERROR_INVALIDDATA;
 }
 }
+
+int avpriv_dca_compute_crc(const uint8_t *data, int size)
+{
+static const uint16_t crctab[16] = {
+0x, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+};
+
+uint16_t res = 0x;
+int i;
+
+for (i = 0; i < size; i++) {
+res = (res << 4) ^ crctab[(data[i] >> 4) ^ (res >> 12)];
+res = (res << 4) ^ crctab[(data[i] & 15) ^ (res >> 12)];
+}
+
+return res;
+}
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index a1ac763..ebf9f32 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -160,4 +160,9 @@ extern av_export const uint32_t avpriv_dca_sample_rates[16];
 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t 
*dst,
  int max_size);
 
+/**
+ * Compute DCA-style CRC16 of input data
+ */
+int avpriv_dca_compute_crc(const uint8_t *data, int size);
+
 #endif /* AVCODEC_DCA_H */
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 0f50412..0a58782 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -76,29 +76,11 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int 
*ch_remap, int dca_mask
 return nchannels;
 }
 
-static uint16_t crc16(const uint8_t *data, int size)
-{
-static const uint16_t crctab[16] = {
-0x, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
-0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
-};
-
-uint16_t res = 0x;
-int i;
-
-for (i = 0; i < size; i++) {
-res = (res << 4) ^ crctab[(data[i] >> 4) ^ (res >> 12)];
-res = (res << 4) ^ crctab[(data[i] & 15) ^ (res >> 12)];
-}
-
-return res;
-}
-
 int ff_dca_check_crc(GetBitContext *s, int p1, int p2)
 {
 if (((p1 | p2) & 7) || p1 < 0 || p2 > s->size_in_bits || p2 - p1 < 16)
 return -1;
-if (crc16(s->buffer + p1 / 8, (p2 - p1) / 8))
+if (avpriv_dca_compute_crc(s->buffer + p1 / 8, (p2 - p1) / 8))
 return -1;
 return 0;
 }
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 084ae55..5840cf6 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  57
-#define LIBAVCODEC_VERSION_MINOR  38
+#define LIBAVCODEC_VERSION_MINOR  39
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.8.1

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


[FFmpeg-devel] [PATCH] avcodec/dca: fix sync word search error condition

2016-05-02 Thread foo86
This didn't actually check if sync word was found and always errored out
with "-err_detect explode" option enabled.
---
 libavcodec/dca_core.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index fc4fdf4..58c78f7 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1844,9 +1844,10 @@ static int parse_optional_info(DCACoreDecoder *s)
 }
 }
 
-if (s->avctx->err_recognition & AV_EF_EXPLODE) {
+if (!s->xch_pos) {
 av_log(s->avctx, AV_LOG_ERROR, "XCH sync word not found\n");
-return AVERROR_INVALIDDATA;
+if (s->avctx->err_recognition & AV_EF_EXPLODE)
+return AVERROR_INVALIDDATA;
 }
 break;
 
@@ -1866,9 +1867,10 @@ static int parse_optional_info(DCACoreDecoder *s)
 }
 }
 
-if (s->avctx->err_recognition & AV_EF_EXPLODE) {
+if (!s->x96_pos) {
 av_log(s->avctx, AV_LOG_ERROR, "X96 sync word not found\n");
-return AVERROR_INVALIDDATA;
+if (s->avctx->err_recognition & AV_EF_EXPLODE)
+return AVERROR_INVALIDDATA;
 }
 break;
 
@@ -1891,9 +1893,10 @@ static int parse_optional_info(DCACoreDecoder *s)
 }
 }
 
-if (s->avctx->err_recognition & AV_EF_EXPLODE) {
+if (!s->xxch_pos) {
 av_log(s->avctx, AV_LOG_ERROR, "XXCH sync word not found\n");
-return AVERROR_INVALIDDATA;
+if (s->avctx->err_recognition & AV_EF_EXPLODE)
+return AVERROR_INVALIDDATA;
 }
 break;
 }
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH v2 1/3] avcodec/dca: move huffman data into separate object file

2016-05-02 Thread foo86
On Sun, May 01, 2016 at 08:18:45PM -0300, James Almer wrote:
> On 5/1/2016 12:41 PM, foo86 wrote:
> > ---
> >  libavcodec/Makefile   |2 +-
> >  libavcodec/dca_core.c |   70 +---
> >  libavcodec/dca_core.h |2 +-
> >  libavcodec/dcadata.c  |9 -
> >  libavcodec/dcadata.h  |2 -
> >  libavcodec/dcadec.c   |4 +-
> >  libavcodec/dcahuff.c  | 1099 
> > +
> >  libavcodec/dcahuff.h  | 1023 +
> >  8 files changed, 1124 insertions(+), 1087 deletions(-)
> >  create mode 100644 libavcodec/dcahuff.c
> 
> Applied, thanks.
> 
> Next time if you notice that git format-patch doesn't recognize renames try
> using the -B option (Break or detect rewrites).

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


Re: [FFmpeg-devel] [PATCH v2 0/3] DTS Express (LBR) decoder

2016-05-02 Thread foo86
On Mon, May 02, 2016 at 10:35:29AM +0200, Hendrik Leppkes wrote:
> On Sun, May 1, 2016 at 11:43 PM, Hendrik Leppkes  wrote:
> > On Sun, May 1, 2016 at 8:30 PM, James Almer  wrote:
> >> With the samples you shared and with a random lbr-in-wav mono sample i 
> >> found
> >> in the wild i get the following when i try to do a codec copy.
> >> Core and every other DTS extension in contrast seem to set timestamps just
> >> fine.
> >>
> >
> > Thats probably because DTS Express streams do not have a core stream,
> > and without it the parser doesn't know the frame size, hence no
> > duration and no timestamps.
> >
> 
> On an additional note, this should be entirely independent of being
> able to decode it. This behavior should be like this before applying
> this, no?

Yes, this only adds LBR decoder and doesn't change anything in the
parser.

LBR (or other core-less DTS stream like HD MA) should still work when
put into container, though.

> Unfortunately parsing the EXSS header in the parser to find the
> required info would be rather annoying, because the EXSS headers are
> much more complex than the dts core headers.

There is an easily accessible duration field in EXSS, but that gives
frame duration in clock cycles, while parser context seems to require
duration in samples and sample rate to be set.

Unfortunately, that makes duration calculation rather fragile, since
sample rate may change in decoder for various reasons (e.g. sample rate
extension fails to decode, core_only is enabled, etc). Not sure how to
fix this properly.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2 2/3] avcodec/dca: move channel counter utility into dca.h

2016-05-01 Thread foo86
Also add actual speaker pair definitions.
---
 libavcodec/dca.h  | 28 
 libavcodec/dca_exss.c |  9 ++---
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index ccb02af..a1ac763 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -28,6 +28,7 @@
 
 #include 
 
+#include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 
@@ -90,6 +91,33 @@ enum DCASpeakerMask {
 #define DCA_HAS_STEREO(mask) \
 ((mask & DCA_SPEAKER_LAYOUT_STEREO) == DCA_SPEAKER_LAYOUT_STEREO)
 
+enum DCASpeakerPair {
+DCA_SPEAKER_PAIR_C  = 0x0001,
+DCA_SPEAKER_PAIR_LR = 0x0002,
+DCA_SPEAKER_PAIR_LsRs   = 0x0004,
+DCA_SPEAKER_PAIR_LFE1   = 0x0008,
+DCA_SPEAKER_PAIR_Cs = 0x0010,
+DCA_SPEAKER_PAIR_LhRh   = 0x0020,
+DCA_SPEAKER_PAIR_LsrRsr = 0x0040,
+DCA_SPEAKER_PAIR_Ch = 0x0080,
+DCA_SPEAKER_PAIR_Oh = 0x0100,
+DCA_SPEAKER_PAIR_LcRc   = 0x0200,
+DCA_SPEAKER_PAIR_LwRw   = 0x0400,
+DCA_SPEAKER_PAIR_LssRss = 0x0800,
+DCA_SPEAKER_PAIR_LFE2   = 0x1000,
+DCA_SPEAKER_PAIR_LhsRhs = 0x2000,
+DCA_SPEAKER_PAIR_Chr= 0x4000,
+DCA_SPEAKER_PAIR_LhrRhr = 0x8000
+};
+
+/**
+ * Return number of individual channels in DCASpeakerPair mask
+ */
+static inline int ff_dca_count_chs_for_mask(unsigned int mask)
+{
+return av_popcount((mask & 0x) | ((mask & 0xae66) << 16));
+}
+
 enum DCARepresentationType {
 DCA_REPR_TYPE_LtRt = 2,
 DCA_REPR_TYPE_LhRh = 3
diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 4579f23..36314c2 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -21,11 +21,6 @@
 #include "dcadec.h"
 #include "dcadata.h"
 
-static int count_chs_for_mask(int mask)
-{
-return av_popcount(mask) + av_popcount(mask & 0xae66);
-}
-
 static void parse_xll_parameters(DCAExssParser *s, DCAExssAsset *asset)
 {
 // Size of XLL data in extension substream
@@ -141,7 +136,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset 
*asset)
 
 // Standard loudspeaker layout mask
 for (i = 0; i < spkr_remap_nsets; i++)
-nspeakers[i] = count_chs_for_mask(get_bits(>gb, 
spkr_mask_nbits));
+nspeakers[i] = ff_dca_count_chs_for_mask(get_bits(>gb, 
spkr_mask_nbits));
 
 for (i = 0; i < spkr_remap_nsets; i++) {
 // Number of channels to be decoded for speaker remapping
@@ -470,7 +465,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int 
size)
 
 // Speaker layout mask for mixer output channels
 for (i = 0; i < s->nmixoutconfigs; i++)
-s->nmixoutchs[i] = count_chs_for_mask(get_bits(>gb, 
spkr_mask_nbits));
+s->nmixoutchs[i] = ff_dca_count_chs_for_mask(get_bits(>gb, 
spkr_mask_nbits));
 }
 } else {
 s->npresents = 1;
-- 
2.8.1

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


[FFmpeg-devel] [PATCH v2 1/3] avcodec/dca: move huffman data into separate object file

2016-05-01 Thread foo86
---
 libavcodec/Makefile   |2 +-
 libavcodec/dca_core.c |   70 +---
 libavcodec/dca_core.h |2 +-
 libavcodec/dcadata.c  |9 -
 libavcodec/dcadata.h  |2 -
 libavcodec/dcadec.c   |4 +-
 libavcodec/dcahuff.c  | 1099 +
 libavcodec/dcahuff.h  | 1023 +
 8 files changed, 1124 insertions(+), 1087 deletions(-)
 create mode 100644 libavcodec/dcahuff.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8f63261..2fd43a0 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -230,7 +230,7 @@ OBJS-$(CONFIG_COMFORTNOISE_ENCODER)+= cngenc.o
 OBJS-$(CONFIG_CPIA_DECODER)+= cpia.o
 OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o
 OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o
-OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadata.o\
+OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadata.o dcahuff.o \
   dca_core.o dca_exss.o dca_xll.o \
   dcadsp.o dcadct.o synth_filter.o
 OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o dcadata.o
diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index d9f1a4c..fc4fdf4 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -100,62 +100,6 @@ static const uint8_t 
quant_index_group_size[DCA_CODE_BOOKS] = {
 1, 3, 3, 3, 3, 7, 7, 7, 7, 7
 };
 
-typedef struct DCAVLC {
-int offset; ///< Code values offset
-int max_depth;  ///< Parameter for get_vlc2()
-VLC vlc[7]; ///< Actual codes
-} DCAVLC;
-
-static DCAVLC   vlc_bit_allocation;
-static DCAVLC   vlc_transition_mode;
-static DCAVLC   vlc_scale_factor;
-static DCAVLC   vlc_quant_index[DCA_CODE_BOOKS];
-
-static av_cold void dca_init_vlcs(void)
-{
-static VLC_TYPE dca_table[23622][2];
-static int vlcs_initialized = 0;
-int i, j, k;
-
-if (vlcs_initialized)
-return;
-
-#define DCA_INIT_VLC(vlc, a, b, c, d)  \
-do {   \
-vlc.table   = _table[ff_dca_vlc_offs[k]];  \
-vlc.table_allocated = ff_dca_vlc_offs[k + 1] - ff_dca_vlc_offs[k]; \
-init_vlc(, a, b, c, 1, 1, d, 2, 2, INIT_VLC_USE_NEW_STATIC);   \
-} while (0)
-
-vlc_bit_allocation.offset= 1;
-vlc_bit_allocation.max_depth = 2;
-for (i = 0, k = 0; i < 5; i++, k++)
-DCA_INIT_VLC(vlc_bit_allocation.vlc[i], bitalloc_12_vlc_bits[i], 12,
- bitalloc_12_bits[i], bitalloc_12_codes[i]);
-
-vlc_scale_factor.offset= -64;
-vlc_scale_factor.max_depth = 2;
-for (i = 0; i < 5; i++, k++)
-DCA_INIT_VLC(vlc_scale_factor.vlc[i], SCALES_VLC_BITS, 129,
- scales_bits[i], scales_codes[i]);
-
-vlc_transition_mode.offset= 0;
-vlc_transition_mode.max_depth = 1;
-for (i = 0; i < 4; i++, k++)
-DCA_INIT_VLC(vlc_transition_mode.vlc[i], tmode_vlc_bits[i], 4,
- tmode_bits[i], tmode_codes[i]);
-
-for (i = 0; i < DCA_CODE_BOOKS; i++) {
-vlc_quant_index[i].offset= bitalloc_offsets[i];
-vlc_quant_index[i].max_depth = 1 + (i > 4);
-for (j = 0; j < quant_index_group_size[i]; j++, k++)
-DCA_INIT_VLC(vlc_quant_index[i].vlc[j], bitalloc_maxbits[i][j],
- bitalloc_sizes[i], bitalloc_bits[i][j], 
bitalloc_codes[i][j]);
-}
-
-vlcs_initialized = 1;
-}
-
 static int dca_get_vlc(GetBitContext *s, DCAVLC *v, int i)
 {
 return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, v->max_depth) + 
v->offset;
@@ -498,7 +442,7 @@ static inline int parse_scale(DCACoreDecoder *s, int 
*scale_index, int sel)
 
 // If Huffman code was used, the difference of scales was encoded
 if (sel < 5)
-*scale_index += dca_get_vlc(>gb, _scale_factor, sel);
+*scale_index += dca_get_vlc(>gb, _dca_vlc_scale_factor, sel);
 else
 *scale_index = get_bits(>gb, sel + 1);
 
@@ -517,7 +461,7 @@ static inline int parse_joint_scale(DCACoreDecoder *s, int 
sel)
 
 // Absolute value was encoded even when Huffman code was used
 if (sel < 5)
-scale_index = dca_get_vlc(>gb, _scale_factor, sel);
+scale_index = dca_get_vlc(>gb, _dca_vlc_scale_factor, sel);
 else
 scale_index = get_bits(>gb, sel + 1);
 
@@ -569,7 +513,7 @@ static int parse_subframe_header(DCACoreDecoder *s, int sf,
 int abits;
 
 if (sel < 5)
-abits = dca_get_vlc(>gb, _bit_allocation, sel);
+abits = dca_get_vlc(>gb, _dca_vlc_bit_allocation, sel);
 else
 abits = get_bits(>gb, sel - 1);
 
@@ -592,7 +536,7 @@ static int parse_subframe_header(DCACoreDecoder *s, int sf,
 int sel = s->transition_mode_sel[ch];
 for (band = 0; band < s->subband_vq_start[ch]; 

[FFmpeg-devel] [PATCH v2 0/3] DTS Express (LBR) decoder

2016-05-01 Thread foo86
This adds decoder for DTS Express (LBR) format that is typically used for
secondary audio tracks on BDs.

Changes since the previous version:
  - dropped merged patches
  - changed avpriv_ prefix to ff_ on inline function in a header
  - replaced LOCAL_ALIGNED(32, ...) with LOCAL_ALIGNED_32(...)
  - moved first stage of LBR filterbank to dcadsp
  - changed several inline constants to float from double
  - reduced number of grid 2 subbands allocated in structure (3 vs 6)

Sample files that can be added to FATE: https://0x0.st/NsN.zip

foo86 (3):
  avcodec/dca: move huffman data into separate object file
  avcodec/dca: move channel counter utility into dca.h
  avcodec/dca: add DTS Express (LBR) decoder

 Changelog |1 +
 libavcodec/Makefile   |4 +-
 libavcodec/dca.h  |   28 +
 libavcodec/dca_core.c |   70 +-
 libavcodec/dca_core.h |2 +-
 libavcodec/dca_exss.c |9 +-
 libavcodec/dca_lbr.c  | 1825 +
 libavcodec/dca_lbr.h  |  130 
 libavcodec/dcadata.c  |  471 -
 libavcodec/dcadata.h  |   47 +-
 libavcodec/dcadec.c   |   26 +-
 libavcodec/dcadec.h   |5 +-
 libavcodec/dcadsp.c   |   74 ++
 libavcodec/dcadsp.h   |7 +
 libavcodec/dcahuff.c  | 1337 
 libavcodec/dcahuff.h  | 1046 +---
 16 files changed, 3983 insertions(+), 1099 deletions(-)
 create mode 100644 libavcodec/dca_lbr.c
 create mode 100644 libavcodec/dca_lbr.h
 create mode 100644 libavcodec/dcahuff.c

-- 
2.8.1

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


[FFmpeg-devel] [PATCH 0/5] DTS Express (LBR) decoder

2016-04-27 Thread foo86
This moves several DCA tables around in preparation and adds decoder for DTS
Express (LBR) format that is typically used for secondary audio tracks on BDs.

Current implementation supports decoding mono, stereo and 5.1 tracks at maximum
sampling rate of 48 kHz. LFE decoding is only supported for 48 kHz tracks. 5.1
tracks with embedded stereo downmix only decode the downmix because embedded
channel set (ECS) processing is not supported (too annoying to implement for
such obscure feature).

Decoder works reasonably well for various samples I've tested and is already
quite fast: mono LBR track decodes around 1.8k times faster that realtime here.

foo86 (5):
  avcodec/dcaenc: reuse shared quant levels table
  avcodec/dcaenc: move channel reordering tables to dcaenc.h
  avcodec/dca: move huffman data into separate object file
  avcodec/dca: move channel counter utility into dca.h
  avcodec/dca: add DTS Express (LBR) decoder

 Changelog |1 +
 libavcodec/Makefile   |4 +-
 libavcodec/dca.h  |   28 +
 libavcodec/dca_core.c |   70 +-
 libavcodec/dca_core.h |2 +-
 libavcodec/dca_exss.c |9 +-
 libavcodec/dca_lbr.c  | 1858 +
 libavcodec/dca_lbr.h  |  130 
 libavcodec/dcadata.c  |  495 +++--
 libavcodec/dcadata.h  |   47 +-
 libavcodec/dcadec.c   |   26 +-
 libavcodec/dcadec.h   |5 +-
 libavcodec/dcadsp.c   |   27 +
 libavcodec/dcadsp.h   |4 +
 libavcodec/dcaenc.c   |   14 +-
 libavcodec/dcaenc.h   |   45 +-
 libavcodec/dcahuff.c  | 1337 +++
 libavcodec/dcahuff.h  | 1046 +---
 18 files changed, 3998 insertions(+), 1150 deletions(-)
 create mode 100644 libavcodec/dca_lbr.c
 create mode 100644 libavcodec/dca_lbr.h
 create mode 100644 libavcodec/dcahuff.c

-- 
2.8.0.rc3

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


[FFmpeg-devel] [PATCH 5/5] avcodec/dca: add DTS Express (LBR) decoder

2016-04-27 Thread foo86
---
 Changelog|1 +
 libavcodec/Makefile  |2 +-
 libavcodec/dca_lbr.c | 1858 ++
 libavcodec/dca_lbr.h |  130 
 libavcodec/dcadata.c |  460 +
 libavcodec/dcadata.h |   46 ++
 libavcodec/dcadec.c  |   22 +-
 libavcodec/dcadec.h  |5 +-
 libavcodec/dcadsp.c  |   27 +
 libavcodec/dcadsp.h  |4 +
 libavcodec/dcahuff.c |  245 ++-
 libavcodec/dcahuff.h |   13 +
 12 files changed, 2807 insertions(+), 6 deletions(-)
 create mode 100644 libavcodec/dca_lbr.c
 create mode 100644 libavcodec/dca_lbr.h

diff --git a/Changelog b/Changelog
index 328ba46..b34d5d6 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,7 @@ version :
 - VAAPI-accelerated format conversion and scaling
 - libnpp/CUDA-accelerated format conversion and scaling
 - Duck TrueMotion 2.0 Real Time decoder
+- DTS Express (LBR) decoder
 
 version 3.0:
 - Common Encryption (CENC) MP4 encoding and decoding support
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2fd43a0..46b4668 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -231,7 +231,7 @@ OBJS-$(CONFIG_CPIA_DECODER)+= cpia.o
 OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o
 OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o
 OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadata.o dcahuff.o \
-  dca_core.o dca_exss.o dca_xll.o \
+  dca_core.o dca_exss.o dca_xll.o 
dca_lbr.o \
   dcadsp.o dcadct.o synth_filter.o
 OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o dcadata.o
 OBJS-$(CONFIG_DDS_DECODER) += dds.o
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
new file mode 100644
index 000..686d37b
--- /dev/null
+++ b/libavcodec/dca_lbr.c
@@ -0,0 +1,1858 @@
+/*
+ * Copyright (C) 2016 foo86
+ *
+ * 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
+ */
+
+#define UNCHECKED_BITSTREAM_READER  1
+#define BITSTREAM_READER_LE
+
+#include "libavutil/channel_layout.h"
+
+#include "dcadec.h"
+#include "dcadata.h"
+#include "dcahuff.h"
+#include "dca_syncwords.h"
+#include "bytestream.h"
+
+#define AMP_MAX 56
+
+enum LBRHeader {
+LBR_HEADER_SYNC_ONLY= 1,
+LBR_HEADER_DECODER_INIT = 2
+};
+
+enum LBRFlags {
+LBR_FLAG_24_BIT = 0x01,
+LBR_FLAG_LFE_PRESENT= 0x02,
+LBR_FLAG_BAND_LIMIT_2_3 = 0x04,
+LBR_FLAG_BAND_LIMIT_1_2 = 0x08,
+LBR_FLAG_BAND_LIMIT_1_3 = 0x0c,
+LBR_FLAG_BAND_LIMIT_1_4 = 0x10,
+LBR_FLAG_BAND_LIMIT_1_8 = 0x18,
+LBR_FLAG_BAND_LIMIT_NONE= 0x14,
+LBR_FLAG_BAND_LIMIT_MASK= 0x1c,
+LBR_FLAG_DMIX_STEREO= 0x20,
+LBR_FLAG_DMIX_MULTI_CH  = 0x40
+};
+
+enum LBRChunkTypes {
+LBR_CHUNK_NULL  = 0x00,
+LBR_CHUNK_PAD   = 0x01,
+LBR_CHUNK_FRAME = 0x04,
+LBR_CHUNK_FRAME_NO_CSUM = 0x06,
+LBR_CHUNK_LFE   = 0x0a,
+LBR_CHUNK_ECS   = 0x0b,
+LBR_CHUNK_RESERVED_1= 0x0c,
+LBR_CHUNK_RESERVED_2= 0x0d,
+LBR_CHUNK_SCF   = 0x0e,
+LBR_CHUNK_TONAL = 0x10,
+LBR_CHUNK_TONAL_GRP_1   = 0x11,
+LBR_CHUNK_TONAL_GRP_2   = 0x12,
+LBR_CHUNK_TONAL_GRP_3   = 0x13,
+LBR_CHUNK_TONAL_GRP_4   = 0x14,
+LBR_CHUNK_TONAL_GRP_5   = 0x15,
+LBR_CHUNK_TONAL_SCF = 0x16,
+LBR_CHUNK_TONAL_SCF_GRP_1   = 0x17,
+LBR_CHUNK_TONAL_SCF_GRP_2   = 0x18,
+LBR_CHUNK_TONAL_SCF_GRP_3   = 0x19,
+LBR_CHUNK_TONAL_SCF_GRP_4   = 0x1a,
+LBR_CHUNK_TONAL_SCF_GRP_5   = 0x1b,
+LBR_CHUNK_RES_GRID_LR   = 0x30,
+LBR_CHUNK_RES_GRID_LR_LAST  = 0x3f,
+LBR_CHUNK_RES_GRID_HR   = 0x40,
+LBR_CHUNK_RES_GRID_HR_LAST  = 0x4f,
+LBR_CHUNK_RES_TS_1  = 0x50,
+LBR_CHUNK_RES_TS_1_LAST = 0x5f,
+LBR_CHUNK_RES_TS_2  = 0x60,
+LBR_CHUNK_RES_TS_2_LAST = 0x6f,
+LBR_CHUNK_EXTENSION = 0x7f
+};
+
+typedef struct LBRChunk {
+int id, len;
+const uint8_t *data;
+} LBRChunk;
+
+static const int8_t channel_reorder_nolfe[7][5] = {
+{ 0, -1, -1, -1, -1 },  // C

[FFmpeg-devel] [PATCH 4/5] avcodec/dca: move channel counter utility into dca.h

2016-04-27 Thread foo86
Also add actual speaker pair definitions.
---
 libavcodec/dca.h  | 28 
 libavcodec/dca_exss.c |  9 ++---
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index ccb02af..1b90d40 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -28,6 +28,7 @@
 
 #include 
 
+#include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 
@@ -90,6 +91,33 @@ enum DCASpeakerMask {
 #define DCA_HAS_STEREO(mask) \
 ((mask & DCA_SPEAKER_LAYOUT_STEREO) == DCA_SPEAKER_LAYOUT_STEREO)
 
+enum DCASpeakerPair {
+DCA_SPEAKER_PAIR_C  = 0x0001,
+DCA_SPEAKER_PAIR_LR = 0x0002,
+DCA_SPEAKER_PAIR_LsRs   = 0x0004,
+DCA_SPEAKER_PAIR_LFE1   = 0x0008,
+DCA_SPEAKER_PAIR_Cs = 0x0010,
+DCA_SPEAKER_PAIR_LhRh   = 0x0020,
+DCA_SPEAKER_PAIR_LsrRsr = 0x0040,
+DCA_SPEAKER_PAIR_Ch = 0x0080,
+DCA_SPEAKER_PAIR_Oh = 0x0100,
+DCA_SPEAKER_PAIR_LcRc   = 0x0200,
+DCA_SPEAKER_PAIR_LwRw   = 0x0400,
+DCA_SPEAKER_PAIR_LssRss = 0x0800,
+DCA_SPEAKER_PAIR_LFE2   = 0x1000,
+DCA_SPEAKER_PAIR_LhsRhs = 0x2000,
+DCA_SPEAKER_PAIR_Chr= 0x4000,
+DCA_SPEAKER_PAIR_LhrRhr = 0x8000
+};
+
+/**
+ * Return number of individual channels in DCASpeakerPair mask
+ */
+static inline int avpriv_dca_count_chs_for_mask(unsigned int mask)
+{
+return av_popcount((mask & 0x) | ((mask & 0xae66) << 16));
+}
+
 enum DCARepresentationType {
 DCA_REPR_TYPE_LtRt = 2,
 DCA_REPR_TYPE_LhRh = 3
diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 4579f23..d59d0dd 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -21,11 +21,6 @@
 #include "dcadec.h"
 #include "dcadata.h"
 
-static int count_chs_for_mask(int mask)
-{
-return av_popcount(mask) + av_popcount(mask & 0xae66);
-}
-
 static void parse_xll_parameters(DCAExssParser *s, DCAExssAsset *asset)
 {
 // Size of XLL data in extension substream
@@ -141,7 +136,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset 
*asset)
 
 // Standard loudspeaker layout mask
 for (i = 0; i < spkr_remap_nsets; i++)
-nspeakers[i] = count_chs_for_mask(get_bits(>gb, 
spkr_mask_nbits));
+nspeakers[i] = avpriv_dca_count_chs_for_mask(get_bits(>gb, 
spkr_mask_nbits));
 
 for (i = 0; i < spkr_remap_nsets; i++) {
 // Number of channels to be decoded for speaker remapping
@@ -470,7 +465,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int 
size)
 
 // Speaker layout mask for mixer output channels
 for (i = 0; i < s->nmixoutconfigs; i++)
-s->nmixoutchs[i] = count_chs_for_mask(get_bits(>gb, 
spkr_mask_nbits));
+s->nmixoutchs[i] = 
avpriv_dca_count_chs_for_mask(get_bits(>gb, spkr_mask_nbits));
 }
 } else {
 s->npresents = 1;
-- 
2.8.0.rc3

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


[FFmpeg-devel] [PATCH 2/5] avcodec/dcaenc: move channel reordering tables to dcaenc.h

2016-04-27 Thread foo86
DCA core decoder no longer uses fixed tables for channel reordering.
Move them into private encoder header (and drop ff_dca_ prefix).
---
 libavcodec/dcadata.c | 42 --
 libavcodec/dcadata.h |  5 -
 libavcodec/dcaenc.c  |  6 +++---
 libavcodec/dcaenc.h  | 42 ++
 4 files changed, 45 insertions(+), 50 deletions(-)

diff --git a/libavcodec/dcadata.c b/libavcodec/dcadata.c
index e991134..3f8d8e9 100644
--- a/libavcodec/dcadata.c
+++ b/libavcodec/dcadata.c
@@ -8730,48 +8730,6 @@ const int32_t ff_dca_sampling_freqs[16] = {
 176400, 352800, 12000, 24000,  48000, 96000, 192000, 384000,
 };
 
-const int8_t ff_dca_lfe_index[16] = {
-1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
-};
-
-const int8_t ff_dca_channel_reorder_lfe[16][9] = {
-{ 0, -1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 2,  0,  1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1,  3, -1, -1, -1, -1, -1, -1 },
-{ 2,  0,  1,  4, -1, -1, -1, -1, -1 },
-{ 0,  1,  3,  4, -1, -1, -1, -1, -1 },
-{ 2,  0,  1,  4,  5, -1, -1, -1, -1 },
-{ 3,  4,  0,  1,  5,  6, -1, -1, -1 },
-{ 2,  0,  1,  4,  5,  6, -1, -1, -1 },
-{ 0,  6,  4,  5,  2,  3, -1, -1, -1 },
-{ 4,  2,  5,  0,  1,  6,  7, -1, -1 },
-{ 5,  6,  0,  1,  7,  3,  8,  4, -1 },
-{ 4,  2,  5,  0,  1,  6,  8,  7, -1 },
-};
-
-const int8_t ff_dca_channel_reorder_nolfe[16][9] = {
-{ 0, -1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
-{ 2,  0,  1, -1, -1, -1, -1, -1, -1 },
-{ 0,  1,  2, -1, -1, -1, -1, -1, -1 },
-{ 2,  0,  1,  3, -1, -1, -1, -1, -1 },
-{ 0,  1,  2,  3, -1, -1, -1, -1, -1 },
-{ 2,  0,  1,  3,  4, -1, -1, -1, -1 },
-{ 2,  3,  0,  1,  4,  5, -1, -1, -1 },
-{ 2,  0,  1,  3,  4,  5, -1, -1, -1 },
-{ 0,  5,  3,  4,  1,  2, -1, -1, -1 },
-{ 3,  2,  4,  0,  1,  5,  6, -1, -1 },
-{ 4,  5,  0,  1,  6,  2,  7,  3, -1 },
-{ 3,  2,  4,  0,  1,  5,  7,  6, -1 },
-};
-
 const uint16_t ff_dca_vlc_offs[63] = {
 0,   512,   640,   768,  1282,  1794,  2436,  3080,  3770,  4454,  
5364,
  5372,  5380,  5388,  5392,  5396,  5412,  5420,  5428,  5460,  5492,  
5508,
diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h
index d864251..83c2ce8 100644
--- a/libavcodec/dcadata.h
+++ b/libavcodec/dcadata.h
@@ -73,11 +73,6 @@ extern const int32_t ff_dca_xll_band_coeff[20];
 
 extern const int32_t ff_dca_sampling_freqs[16];
 
-extern const int8_t ff_dca_lfe_index[16];
-
-extern const int8_t ff_dca_channel_reorder_lfe[16][9];
-extern const int8_t ff_dca_channel_reorder_nolfe[16][9];
-
 extern const uint16_t ff_dca_vlc_offs[63];
 
 #endif /* AVCODEC_DCADATA_H */
diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index d562a27..6bb7d29 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -137,9 +137,9 @@ static int encode_init(AVCodecContext *avctx)
 
 if (c->lfe_channel) {
 c->fullband_channels--;
-c->channel_order_tab = ff_dca_channel_reorder_lfe[c->channel_config];
+c->channel_order_tab = channel_reorder_lfe[c->channel_config];
 } else {
-c->channel_order_tab = ff_dca_channel_reorder_nolfe[c->channel_config];
+c->channel_order_tab = channel_reorder_nolfe[c->channel_config];
 }
 
 for (i = 0; i < 9; i++) {
@@ -303,7 +303,7 @@ static void subband_transform(DCAEncContext *c, const 
int32_t *input)
 static void lfe_downsample(DCAEncContext *c, const int32_t *input)
 {
 /* FIXME: make 128x LFE downsampling possible */
-const int lfech = ff_dca_lfe_index[c->channel_config];
+const int lfech = lfe_index[c->channel_config];
 int i, j, lfes;
 int32_t hist[512];
 int32_t accum;
diff --git a/libavcodec/dcaenc.h b/libavcodec/dcaenc.h
index bafc3c0..eccfb42 100644
--- a/libavcodec/dcaenc.h
+++ b/libavcodec/dcaenc.h
@@ -103,4 +103,46 @@ static const int bit_consumption[27] = {
 272, 288, 304, 320, 336, 352, 368,
 };
 
+static const int8_t lfe_index[16] = {
+1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
+};
+
+static const int8_t channel_reorder_lfe[16][9] = {
+{ 0, -1, -1, -1, -1, -1, -1, -1, -1 },
+{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
+{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
+{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
+{ 0,  1, -1, -1, -1, -1, -1, -1, -1 },
+{ 2,  0,  1, -1, -1, -1, -1, -1, -1 },
+{ 0,  1,  3, -1, -1, -1, -1, -1, -1 },
+{ 2,  0,  1,  4, -1, -1, -1, -1, -1 },
+{ 0,  1,  3,  4, -1, -1, -1, -1, -1 },
+{ 2,  0,  1,  4,  5, -1, -1, -1, -1 },
+{ 3,  4,  0,  1,  5,  6, -1, -1, -1 },
+{ 2,  0,  1,  4,  5,  6, -1, -1, -1 },
+{ 0,  6,  4,  5,  2,  3, -1, -1, -1 },
+{ 

[FFmpeg-devel] [PATCH 1/5] avcodec/dcaenc: reuse shared quant levels table

2016-04-27 Thread foo86
---
 libavcodec/dcaenc.c | 8 
 libavcodec/dcaenc.h | 7 ---
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index ab40e37..d562a27 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -683,7 +683,7 @@ static int calc_one_scale(int32_t peak_cb, int abits, 
softfloat *quant)
 continue;
 our_quant.m = mul32(scalefactor_inv[our_nscale - try_remove].m, 
stepsize_inv[abits].m);
 our_quant.e = scalefactor_inv[our_nscale - try_remove].e + 
stepsize_inv[abits].e - 17;
-if ((quant_levels[abits] - 1) / 2 < quantize_value(peak, our_quant))
+if ((ff_dca_quant_levels[abits] - 1) / 2 < quantize_value(peak, 
our_quant))
 continue;
 our_nscale -= try_remove;
 }
@@ -693,7 +693,7 @@ static int calc_one_scale(int32_t peak_cb, int abits, 
softfloat *quant)
 
 quant->m = mul32(scalefactor_inv[our_nscale].m, stepsize_inv[abits].m);
 quant->e = scalefactor_inv[our_nscale].e + stepsize_inv[abits].e - 17;
-av_assert0((quant_levels[abits] - 1) / 2 >= quantize_value(peak, *quant));
+av_assert0((ff_dca_quant_levels[abits] - 1) / 2 >= quantize_value(peak, 
*quant));
 
 return our_nscale;
 }
@@ -858,9 +858,9 @@ static void put_subframe_samples(DCAEncContext *c, int ss, 
int band, int ch)
 for (i = 0; i < 8; i += 4) {
 sum = 0;
 for (j = 3; j >= 0; j--) {
-sum *= quant_levels[c->abits[band][ch]];
+sum *= ff_dca_quant_levels[c->abits[band][ch]];
 sum += c->quantized[ss * 8 + i + j][band][ch];
-sum += (quant_levels[c->abits[band][ch]] - 1) / 2;
+sum += (ff_dca_quant_levels[c->abits[band][ch]] - 1) / 2;
 }
 put_bits(>pb, bit_consumption[c->abits[band][ch]] / 4, sum);
 }
diff --git a/libavcodec/dcaenc.h b/libavcodec/dcaenc.h
index 0443ca6..bafc3c0 100644
--- a/libavcodec/dcaenc.h
+++ b/libavcodec/dcaenc.h
@@ -103,11 +103,4 @@ static const int bit_consumption[27] = {
 272, 288, 304, 320, 336, 352, 368,
 };
 
-/* Table B.5: Selection of quantization levels and codebooks */
-static const int quant_levels[27] = {
-1, 3, 5, 7, 9, 13, 17, 25, 32, 64,
-128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
-131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608,
-};
-
 #endif /* AVCODEC_DCAENC_H */
-- 
2.8.0.rc3

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


Re: [FFmpeg-devel] [PATCH 4/4] avcodec/dca: make reading past end of buffer safe

2016-03-03 Thread foo86
On Thu, Mar 03, 2016 at 12:56:42AM +0100, Hendrik Leppkes wrote:
> On Thu, Mar 3, 2016 at 12:37 AM, Ronald S. Bultje  wrote:
> > Completely random comment, but isn't it easier to just enable the safe
> > bitstream reader?
> >
> 
> This is actually enabled by default, so it probably should never have
> overread anywhere, but if the code can be made a bit safer in itself
> it probably does no harm either way.

Interesting. I assumed it was the opposite (safe bitstream reader
disabled by default). In this case the issue this patch addresses
doesn't seem to have as much impact as I initially thought.

But still I think it is a nice change to have since it makes code more
robust overall while not introducing significant performance penalty.
More importantly, it also gets rid of artificial limit on the length of
unary part of Rice codes, which may improve correctness of the decoder.

I'll change the commit message accordingly and resend the patch.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/4] avcodec/dca: improve band data parsing robustness

2016-03-03 Thread foo86
Limit the maximum length of unary part of Rice code by the number of
available bits instead of using an arbitrary constant that happens to be
just large enough to work.

This effectively limits amount of data that can be overread per segment
by maximum length of binary code per sample multiplied by maximum
segment size.

Increase size of padding area after the end of input buffer according to
this limit and add some extra overread checks to make reading past end
of buffer safe even when internal overread checks are disabled in
bitstream reader code.
---
 libavcodec/dca_xll.c | 25 +++--
 libavcodec/dcadec.h  |  2 +-
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 5e6cf35..46bef3d 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -32,7 +32,7 @@ static int get_linear(GetBitContext *gb, int n)
 
 static int get_rice_un(GetBitContext *gb, int k)
 {
-unsigned int v = get_unary(gb, 1, 128);
+unsigned int v = get_unary(gb, 1, get_bits_left(gb));
 return (v << k) | get_bits_long(gb, k);
 }
 
@@ -512,7 +512,7 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 nsamples_part_b = s->nsegsamples - c->nsamples_part_a[k];
 
 if (get_bits_left(>gb) < 0)
-return AVERROR_INVALIDDATA;
+goto overread;
 
 if (!c->rice_code_flag[k]) {
 // Linear codes
@@ -534,6 +534,9 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 // Unpack the number of isolated samples
 int nisosamples = get_bits(>gb, s->nsegsamples_log2);
 
+if (get_bits_left(>gb) < nisosamples * s->nsegsamples_log2)
+goto overread;
+
 // Set all locations to 0
 memset(part_b, 0, sizeof(*part_b) * nsamples_part_b);
 
@@ -573,14 +576,14 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 // Start unpacking LSB portion of the segment
 if (b->lsb_section_size) {
 // Skip to the start of LSB portion
-if (ff_dca_seek_bits(>gb, band_data_end - b->lsb_section_size * 8)) 
{
-av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
-return AVERROR_INVALIDDATA;
-}
+if (ff_dca_seek_bits(>gb, band_data_end - b->lsb_section_size * 8))
+goto overread;
 
 // Unpack all LSB parts of residuals of this segment
 for (i = 0; i < c->nchannels; i++) {
 if (b->nscalablelsbs[i]) {
+if (get_bits_left(>gb) < 0)
+goto overread;
 get_array(>gb,
   b->lsb_sample_buffer[i] + seg * s->nsegsamples,
   s->nsegsamples, b->nscalablelsbs[i]);
@@ -589,12 +592,14 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 }
 
 // Skip to the end of band data
-if (ff_dca_seek_bits(>gb, band_data_end)) {
-av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
-return AVERROR_INVALIDDATA;
-}
+if (ff_dca_seek_bits(>gb, band_data_end))
+goto overread;
 
 return 0;
+
+overread:
+av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
+return AVERROR_INVALIDDATA;
 }
 
 static av_cold void chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int 
band, int seg)
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 6726121..2805a0e 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -32,7 +32,7 @@
 #include "dca_exss.h"
 #include "dca_xll.h"
 
-#define DCA_BUFFER_PADDING_SIZE 1024
+#define DCA_BUFFER_PADDING_SIZE 2048
 
 #define DCA_PACKET_CORE 0x01
 #define DCA_PACKET_EXSS 0x02
-- 
2.1.4

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


[FFmpeg-devel] [PATCH 1/4] avcodec/dca: clear X96 channels if nothing was decoded

2016-03-02 Thread foo86
The first X96 channel set can have more channels than core, causing X96
decoding to be skipped. Clear the number of decoded X96 channels to zero
in this rudimentary case.
---
 libavcodec/dca_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 48a8f61..d9f1a4c 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1760,6 +1760,7 @@ static int parse_x96_frame_exss(DCACoreDecoder *s)
 return ret;
 
 // Channel set data
+s->x96_nchannels = 0;
 for (i = 0, x96_base_ch = 0; i < x96_nchsets; i++) {
 header_pos = get_bits_count(>gb);
 
-- 
2.1.4

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


[FFmpeg-devel] [PATCH 4/4] avcodec/dca: make reading past end of buffer safe

2016-03-02 Thread foo86
Limit the maximum length of unary part of Rice code by the number of
available bits instead of using an arbitrary constant that happens to be
just large enough to work.

This effectively limits amount of data that can be overread per segment
by maximum length of binary code per sample multiplied by maximum
segment size.

Increase size of padding area after the end of input buffer according to
this limit and add some extra overread checks to make reading past end
of buffer safe.
---
 libavcodec/dca_xll.c | 25 +++--
 libavcodec/dcadec.h  |  2 +-
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 5e6cf35..46bef3d 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -32,7 +32,7 @@ static int get_linear(GetBitContext *gb, int n)
 
 static int get_rice_un(GetBitContext *gb, int k)
 {
-unsigned int v = get_unary(gb, 1, 128);
+unsigned int v = get_unary(gb, 1, get_bits_left(gb));
 return (v << k) | get_bits_long(gb, k);
 }
 
@@ -512,7 +512,7 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 nsamples_part_b = s->nsegsamples - c->nsamples_part_a[k];
 
 if (get_bits_left(>gb) < 0)
-return AVERROR_INVALIDDATA;
+goto overread;
 
 if (!c->rice_code_flag[k]) {
 // Linear codes
@@ -534,6 +534,9 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 // Unpack the number of isolated samples
 int nisosamples = get_bits(>gb, s->nsegsamples_log2);
 
+if (get_bits_left(>gb) < nisosamples * s->nsegsamples_log2)
+goto overread;
+
 // Set all locations to 0
 memset(part_b, 0, sizeof(*part_b) * nsamples_part_b);
 
@@ -573,14 +576,14 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 // Start unpacking LSB portion of the segment
 if (b->lsb_section_size) {
 // Skip to the start of LSB portion
-if (ff_dca_seek_bits(>gb, band_data_end - b->lsb_section_size * 8)) 
{
-av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
-return AVERROR_INVALIDDATA;
-}
+if (ff_dca_seek_bits(>gb, band_data_end - b->lsb_section_size * 8))
+goto overread;
 
 // Unpack all LSB parts of residuals of this segment
 for (i = 0; i < c->nchannels; i++) {
 if (b->nscalablelsbs[i]) {
+if (get_bits_left(>gb) < 0)
+goto overread;
 get_array(>gb,
   b->lsb_sample_buffer[i] + seg * s->nsegsamples,
   s->nsegsamples, b->nscalablelsbs[i]);
@@ -589,12 +592,14 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 }
 
 // Skip to the end of band data
-if (ff_dca_seek_bits(>gb, band_data_end)) {
-av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
-return AVERROR_INVALIDDATA;
-}
+if (ff_dca_seek_bits(>gb, band_data_end))
+goto overread;
 
 return 0;
+
+overread:
+av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
+return AVERROR_INVALIDDATA;
 }
 
 static av_cold void chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int 
band, int seg)
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 6726121..2805a0e 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -32,7 +32,7 @@
 #include "dca_exss.h"
 #include "dca_xll.h"
 
-#define DCA_BUFFER_PADDING_SIZE 1024
+#define DCA_BUFFER_PADDING_SIZE 2048
 
 #define DCA_PACKET_CORE 0x01
 #define DCA_PACKET_EXSS 0x02
-- 
2.1.4

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


[FFmpeg-devel] [PATCH 2/4] avcodec/dca: fix av_cold placement in declarations

2016-03-02 Thread foo86
---
 libavcodec/dca_xll.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index cd1af81..ffe8ef3 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -602,7 +602,7 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 return 0;
 }
 
-static void av_cold chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int 
band, int seg)
+static av_cold void chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int 
band, int seg)
 {
 DCAXllBand *b = >bands[band];
 int i, offset, nsamples;
@@ -1242,7 +1242,7 @@ static void scale_down_mix(DCAXllDecoder *s, DCAXllChSet 
*o, int band)
 
 // Clear all band data and replace non-residual encoded channels with lossy
 // counterparts
-static void av_cold force_lossy_output(DCAXllDecoder *s, DCAXllChSet *c)
+static av_cold void force_lossy_output(DCAXllDecoder *s, DCAXllChSet *c)
 {
 DCAContext *dca = s->avctx->priv_data;
 int band, ch;
-- 
2.1.4

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


[FFmpeg-devel] [PATCH 3/4] avcodec/dca: simplify condition

2016-03-02 Thread foo86
---
 libavcodec/dca_xll.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index ffe8ef3..5e6cf35 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -460,19 +460,14 @@ static int chs_parse_band_data(DCAXllDecoder *s, 
DCAXllChSet *c, int band, int s
 // Unpack Rice coding flag
 // 0 - linear code, 1 - Rice code
 c->rice_code_flag[i] = get_bits1(>gb);
-if (!c->seg_common && c->rice_code_flag[i]) {
-// Unpack Hybrid Rice coding flag
-// 0 - Rice code, 1 - Hybrid Rice code
-if (get_bits1(>gb))
-// Unpack binary code length for isolated samples
-c->bitalloc_hybrid_linear[i] = get_bits(>gb, c->nabits) 
+ 1;
-else
-// 0 indicates no Hybrid Rice coding
-c->bitalloc_hybrid_linear[i] = 0;
-} else {
+// Unpack Hybrid Rice coding flag
+// 0 - Rice code, 1 - Hybrid Rice code
+if (!c->seg_common && c->rice_code_flag[i] && get_bits1(>gb))
+// Unpack binary code length for isolated samples
+c->bitalloc_hybrid_linear[i] = get_bits(>gb, c->nabits) + 1;
+else
 // 0 indicates no Hybrid Rice coding
 c->bitalloc_hybrid_linear[i] = 0;
-}
 }
 
 // Unpack coding parameters
-- 
2.1.4

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


[FFmpeg-devel] [PATCH 0/4] DCA decoder fixes

2016-03-02 Thread foo86
This fixes some potential issues I've identified within new DCA decoder. It is
probably a good idea to backport these patches into 3.0 release branch.

foo86 (4):
  avcodec/dca: clear X96 channels if nothing was decoded
  avcodec/dca: fix av_cold placement in declarations
  avcodec/dca: simplify condition
  avcodec/dca: make reading past end of buffer safe

 libavcodec/dca_core.c |  1 +
 libavcodec/dca_xll.c  | 46 +++---
 libavcodec/dcadec.h   |  2 +-
 3 files changed, 25 insertions(+), 24 deletions(-)

-- 
2.1.4

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


[FFmpeg-devel] [PATCH v2 12/16] avcodec/dca: add generic defines

2016-01-21 Thread foo86
---
 libavcodec/dca.h | 94 
 1 file changed, 94 insertions(+)

diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index ea3f9c5..ccb02af 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -4,6 +4,7 @@
  * Copyright (C) 2004 Benjamin Zores
  * Copyright (C) 2006 Benjamin Larsson
  * Copyright (C) 2007 Konstantin Shishkov
+ * Copyright (C) 2016 foo86
  *
  * This file is part of FFmpeg.
  *
@@ -30,6 +31,99 @@
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 
+enum DCASpeaker {
+DCA_SPEAKER_C,DCA_SPEAKER_L,DCA_SPEAKER_R,DCA_SPEAKER_Ls,
+DCA_SPEAKER_Rs,   DCA_SPEAKER_LFE1, DCA_SPEAKER_Cs,   DCA_SPEAKER_Lsr,
+DCA_SPEAKER_Rsr,  DCA_SPEAKER_Lss,  DCA_SPEAKER_Rss,  DCA_SPEAKER_Lc,
+DCA_SPEAKER_Rc,   DCA_SPEAKER_Lh,   DCA_SPEAKER_Ch,   DCA_SPEAKER_Rh,
+DCA_SPEAKER_LFE2, DCA_SPEAKER_Lw,   DCA_SPEAKER_Rw,   DCA_SPEAKER_Oh,
+DCA_SPEAKER_Lhs,  DCA_SPEAKER_Rhs,  DCA_SPEAKER_Chr,  DCA_SPEAKER_Lhr,
+DCA_SPEAKER_Rhr,  DCA_SPEAKER_Cl,   DCA_SPEAKER_Ll,   DCA_SPEAKER_Rl,
+DCA_SPEAKER_RSV1, DCA_SPEAKER_RSV2, DCA_SPEAKER_RSV3, DCA_SPEAKER_RSV4,
+
+DCA_SPEAKER_COUNT
+};
+
+enum DCASpeakerMask {
+DCA_SPEAKER_MASK_C = 0x0001,
+DCA_SPEAKER_MASK_L = 0x0002,
+DCA_SPEAKER_MASK_R = 0x0004,
+DCA_SPEAKER_MASK_Ls= 0x0008,
+DCA_SPEAKER_MASK_Rs= 0x0010,
+DCA_SPEAKER_MASK_LFE1  = 0x0020,
+DCA_SPEAKER_MASK_Cs= 0x0040,
+DCA_SPEAKER_MASK_Lsr   = 0x0080,
+DCA_SPEAKER_MASK_Rsr   = 0x0100,
+DCA_SPEAKER_MASK_Lss   = 0x0200,
+DCA_SPEAKER_MASK_Rss   = 0x0400,
+DCA_SPEAKER_MASK_Lc= 0x0800,
+DCA_SPEAKER_MASK_Rc= 0x1000,
+DCA_SPEAKER_MASK_Lh= 0x2000,
+DCA_SPEAKER_MASK_Ch= 0x4000,
+DCA_SPEAKER_MASK_Rh= 0x8000,
+DCA_SPEAKER_MASK_LFE2  = 0x0001,
+DCA_SPEAKER_MASK_Lw= 0x0002,
+DCA_SPEAKER_MASK_Rw= 0x0004,
+DCA_SPEAKER_MASK_Oh= 0x0008,
+DCA_SPEAKER_MASK_Lhs   = 0x0010,
+DCA_SPEAKER_MASK_Rhs   = 0x0020,
+DCA_SPEAKER_MASK_Chr   = 0x0040,
+DCA_SPEAKER_MASK_Lhr   = 0x0080,
+DCA_SPEAKER_MASK_Rhr   = 0x0100,
+DCA_SPEAKER_MASK_Cl= 0x0200,
+DCA_SPEAKER_MASK_Ll= 0x0400,
+DCA_SPEAKER_MASK_Rl= 0x0800,
+};
+
+#define DCA_SPEAKER_LAYOUT_MONO (DCA_SPEAKER_MASK_C)
+#define DCA_SPEAKER_LAYOUT_STEREO   (DCA_SPEAKER_MASK_L | 
DCA_SPEAKER_MASK_R)
+#define DCA_SPEAKER_LAYOUT_2POINT1  (DCA_SPEAKER_LAYOUT_STEREO | 
DCA_SPEAKER_MASK_LFE1)
+#define DCA_SPEAKER_LAYOUT_3_0  (DCA_SPEAKER_LAYOUT_STEREO | 
DCA_SPEAKER_MASK_C)
+#define DCA_SPEAKER_LAYOUT_2_1  (DCA_SPEAKER_LAYOUT_STEREO | 
DCA_SPEAKER_MASK_Cs)
+#define DCA_SPEAKER_LAYOUT_3_1  (DCA_SPEAKER_LAYOUT_3_0 | 
DCA_SPEAKER_MASK_Cs)
+#define DCA_SPEAKER_LAYOUT_2_2  (DCA_SPEAKER_LAYOUT_STEREO | 
DCA_SPEAKER_MASK_Ls | DCA_SPEAKER_MASK_Rs)
+#define DCA_SPEAKER_LAYOUT_5POINT0  (DCA_SPEAKER_LAYOUT_3_0 | 
DCA_SPEAKER_MASK_Ls | DCA_SPEAKER_MASK_Rs)
+#define DCA_SPEAKER_LAYOUT_5POINT1  (DCA_SPEAKER_LAYOUT_5POINT0 | 
DCA_SPEAKER_MASK_LFE1)
+#define DCA_SPEAKER_LAYOUT_7POINT0_WIDE (DCA_SPEAKER_LAYOUT_5POINT0 | 
DCA_SPEAKER_MASK_Lw | DCA_SPEAKER_MASK_Rw)
+#define DCA_SPEAKER_LAYOUT_7POINT1_WIDE (DCA_SPEAKER_LAYOUT_7POINT0_WIDE | 
DCA_SPEAKER_MASK_LFE1)
+
+#define DCA_HAS_STEREO(mask) \
+((mask & DCA_SPEAKER_LAYOUT_STEREO) == DCA_SPEAKER_LAYOUT_STEREO)
+
+enum DCARepresentationType {
+DCA_REPR_TYPE_LtRt = 2,
+DCA_REPR_TYPE_LhRh = 3
+};
+
+enum DCAExtensionMask {
+DCA_CSS_CORE   = 0x001,
+DCA_CSS_XXCH   = 0x002,
+DCA_CSS_X96= 0x004,
+DCA_CSS_XCH= 0x008,
+DCA_CSS_MASK   = 0x00f,
+DCA_EXSS_CORE  = 0x010,
+DCA_EXSS_XBR   = 0x020,
+DCA_EXSS_XXCH  = 0x040,
+DCA_EXSS_X96   = 0x080,
+DCA_EXSS_LBR   = 0x100,
+DCA_EXSS_XLL   = 0x200,
+DCA_EXSS_RSV1  = 0x400,
+DCA_EXSS_RSV2  = 0x800,
+DCA_EXSS_MASK  = 0xff0,
+};
+
+enum DCADownMixType {
+DCA_DMIX_TYPE_1_0,
+DCA_DMIX_TYPE_LoRo,
+DCA_DMIX_TYPE_LtRt,
+DCA_DMIX_TYPE_3_0,
+DCA_DMIX_TYPE_2_1,
+DCA_DMIX_TYPE_2_2,
+DCA_DMIX_TYPE_3_1,
+
+DCA_DMIX_TYPE_COUNT
+};
+
 extern av_export const uint32_t avpriv_dca_sample_rates[16];
 
 /**
-- 
2.1.4

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


[FFmpeg-devel] [PATCH v2 11/16] avcodec/dca: add DSP implementation

2016-01-21 Thread foo86
---
 libavcodec/dcadsp.c | 413 
 libavcodec/dcadsp.h |  91 
 2 files changed, 504 insertions(+)
 create mode 100644 libavcodec/dcadsp.c
 create mode 100644 libavcodec/dcadsp.h

diff --git a/libavcodec/dcadsp.c b/libavcodec/dcadsp.c
new file mode 100644
index 000..cee3d60
--- /dev/null
+++ b/libavcodec/dcadsp.c
@@ -0,0 +1,413 @@
+/*
+ * Copyright (C) 2016 foo86
+ *
+ * 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
+ */
+
+#include "libavutil/mem.h"
+
+#include "dcadsp.h"
+#include "dcamath.h"
+
+static void decode_hf_c(int32_t **dst,
+const int32_t *vq_index,
+const int8_t hf_vq[1024][32],
+int32_t scale_factors[32][2],
+intptr_t sb_start, intptr_t sb_end,
+intptr_t ofs, intptr_t len)
+{
+int i, j;
+
+for (i = sb_start; i < sb_end; i++) {
+const int8_t *coeff = hf_vq[vq_index[i]];
+int32_t scale = scale_factors[i][0];
+for (j = 0; j < len; j++)
+dst[i][j + ofs] = clip23(coeff[j] * scale + (1 << 3) >> 4);
+}
+}
+
+static void decode_joint_c(int32_t **dst, int32_t **src,
+   const int32_t *scale_factors,
+   intptr_t sb_start, intptr_t sb_end,
+   intptr_t ofs, intptr_t len)
+{
+int i, j;
+
+for (i = sb_start; i < sb_end; i++) {
+int32_t scale = scale_factors[i];
+for (j = 0; j < len; j++)
+dst[i][j + ofs] = clip23(mul17(src[i][j + ofs], scale));
+}
+}
+
+static void lfe_fir_float_c(float *pcm_samples, int32_t *lfe_samples,
+const float *filter_coeff, intptr_t npcmblocks,
+int dec_select)
+{
+// Select decimation factor
+int factor = 64 << dec_select;
+int ncoeffs = 8 >> dec_select;
+int nlfesamples = npcmblocks >> (dec_select + 1);
+int i, j, k;
+
+for (i = 0; i < nlfesamples; i++) {
+// One decimated sample generates 64 or 128 interpolated ones
+for (j = 0; j < factor / 2; j++) {
+float a = 0;
+float b = 0;
+
+for (k = 0; k < ncoeffs; k++) {
+a += filter_coeff[  j * ncoeffs + k] * lfe_samples[-k];
+b += filter_coeff[255 - j * ncoeffs - k] * lfe_samples[-k];
+}
+
+pcm_samples[ j] = a;
+pcm_samples[factor / 2 + j] = b;
+}
+
+lfe_samples++;
+pcm_samples += factor;
+}
+}
+
+static void lfe_fir1_float_c(float *pcm_samples, int32_t *lfe_samples,
+ const float *filter_coeff, intptr_t npcmblocks)
+{
+lfe_fir_float_c(pcm_samples, lfe_samples, filter_coeff, npcmblocks, 0);
+}
+
+static void lfe_fir2_float_c(float *pcm_samples, int32_t *lfe_samples,
+ const float *filter_coeff, intptr_t npcmblocks)
+{
+lfe_fir_float_c(pcm_samples, lfe_samples, filter_coeff, npcmblocks, 1);
+}
+
+static void lfe_x96_float_c(float *dst, const float *src,
+float *hist, intptr_t len)
+{
+float prev = *hist;
+int i;
+
+for (i = 0; i < len; i++) {
+float a = 0.25f * src[i] + 0.75f * prev;
+float b = 0.75f * src[i] + 0.25f * prev;
+prev = src[i];
+*dst++ = a;
+*dst++ = b;
+}
+
+*hist = prev;
+}
+
+static void sub_qmf32_float_c(SynthFilterContext *synth,
+  FFTContext *imdct,
+  float *pcm_samples,
+  int32_t **subband_samples_lo,
+  int32_t **subband_samples_hi,
+  float *hist1, int *offset, float *hist2,
+  const float *filter_coeff, intptr_t npcmblocks,
+  float scale)
+{
+LOCAL_ALIGNED(32, float, input, [32]);
+int i, j;
+
+for (j = 0; j < npcmblocks; j++) {
+// Load in one sample from each subband
+for (i = 0; i < 32; i++) {
+if ((i - 1) & 2)
+input[i] = -su

[FFmpeg-devel] [PATCH v2 15/16] avcodec/dca: add XLL decoder

2016-01-21 Thread foo86
---
 libavcodec/dca_xll.c | 1499 ++
 libavcodec/dca_xll.h |  149 +
 2 files changed, 1648 insertions(+)
 create mode 100644 libavcodec/dca_xll.c
 create mode 100644 libavcodec/dca_xll.h

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
new file mode 100644
index 000..cd1af81
--- /dev/null
+++ b/libavcodec/dca_xll.c
@@ -0,0 +1,1499 @@
+/*
+ * Copyright (C) 2016 foo86
+ *
+ * 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
+ */
+
+#include "dcadec.h"
+#include "dcadata.h"
+#include "dcamath.h"
+#include "dca_syncwords.h"
+#include "unary.h"
+
+static int get_linear(GetBitContext *gb, int n)
+{
+unsigned int v = get_bits_long(gb, n);
+return (v >> 1) ^ -(v & 1);
+}
+
+static int get_rice_un(GetBitContext *gb, int k)
+{
+unsigned int v = get_unary(gb, 1, 128);
+return (v << k) | get_bits_long(gb, k);
+}
+
+static int get_rice(GetBitContext *gb, int k)
+{
+unsigned int v = get_rice_un(gb, k);
+return (v >> 1) ^ -(v & 1);
+}
+
+static void get_array(GetBitContext *gb, int32_t *array, int size, int n)
+{
+int i;
+
+for (i = 0; i < size; i++)
+array[i] = get_bits(gb, n);
+}
+
+static void get_linear_array(GetBitContext *gb, int32_t *array, int size, int 
n)
+{
+int i;
+
+if (n == 0)
+memset(array, 0, sizeof(*array) * size);
+else for (i = 0; i < size; i++)
+array[i] = get_linear(gb, n);
+}
+
+static void get_rice_array(GetBitContext *gb, int32_t *array, int size, int k)
+{
+int i;
+
+for (i = 0; i < size; i++)
+array[i] = get_rice(gb, k);
+}
+
+static int parse_dmix_coeffs(DCAXllDecoder *s, DCAXllChSet *c)
+{
+// Size of downmix coefficient matrix
+int m = c->primary_chset ? ff_dca_dmix_primary_nch[c->dmix_type] : 
c->hier_ofs;
+int i, j, *coeff_ptr = c->dmix_coeff;
+
+for (i = 0; i < m; i++) {
+int code, sign, coeff, scale, scale_inv = 0;
+unsigned int index;
+
+// Downmix scale (only for non-primary channel sets)
+if (!c->primary_chset) {
+code = get_bits(>gb, 9);
+sign = (code >> 8) - 1;
+index = (code & 0xff) - FF_DCA_DMIXTABLE_OFFSET;
+if (index >= FF_DCA_INV_DMIXTABLE_SIZE) {
+av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL downmix scale 
index\n");
+return AVERROR_INVALIDDATA;
+}
+scale = ff_dca_dmixtable[index + FF_DCA_DMIXTABLE_OFFSET];
+scale_inv = ff_dca_inv_dmixtable[index];
+c->dmix_scale[i] = (scale ^ sign) - sign;
+c->dmix_scale_inv[i] = (scale_inv ^ sign) - sign;
+}
+
+// Downmix coefficients
+for (j = 0; j < c->nchannels; j++) {
+code = get_bits(>gb, 9);
+sign = (code >> 8) - 1;
+index = code & 0xff;
+if (index >= FF_DCA_DMIXTABLE_SIZE) {
+av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL downmix 
coefficient index\n");
+return AVERROR_INVALIDDATA;
+}
+coeff = ff_dca_dmixtable[index];
+if (!c->primary_chset)
+// Multiply by |InvDmixScale| to get |UndoDmixScale|
+coeff = mul16(scale_inv, coeff);
+*coeff_ptr++ = (coeff ^ sign) - sign;
+}
+}
+
+return 0;
+}
+
+static int chs_parse_header(DCAXllDecoder *s, DCAXllChSet *c, DCAExssAsset 
*asset)
+{
+int i, j, k, ret, band, header_size, header_pos = get_bits_count(>gb);
+DCAXllChSet *p = >chset[0];
+DCAXllBand *b;
+
+// Size of channel set sub-header
+header_size = get_bits(>gb, 10) + 1;
+
+// Check CRC
+if ((s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL))
+&& ff_dca_check_crc(>gb, header_pos, header_pos + header_size * 8)) 
{
+av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL sub-header checksum\n");
+return AVERROR_INVALIDDATA;
+}
+
+// Number of channels in the channel set
+c->nchannels = get_bits(>gb, 4) + 1;
+if (c->ncha

[FFmpeg-devel] [PATCH v2 16/16] avcodec/dca: add new decoder based on libdcadec

2016-01-21 Thread foo86
---
 configure  |   1 +
 libavcodec/Makefile|   3 +
 libavcodec/allcodecs.c |   2 +-
 libavcodec/dcadec.c| 417 +
 libavcodec/dcadec.h|  80 ++
 5 files changed, 502 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/dcadec.c
 create mode 100644 libavcodec/dcadec.h

diff --git a/configure b/configure
index edbac99..30ac716 100755
--- a/configure
+++ b/configure
@@ -2276,6 +2276,7 @@ comfortnoise_encoder_select="lpc"
 cook_decoder_select="audiodsp mdct sinewin"
 cscd_decoder_select="lzo"
 cscd_decoder_suggest="zlib"
+dca_decoder_select="mdct"
 dds_decoder_select="texturedsp"
 dirac_decoder_select="dirac_parse dwt golomb videodsp mpegvideoenc"
 dnxhd_decoder_select="blockdsp idctdsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 20d26e5..6a37083 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -221,6 +221,9 @@ OBJS-$(CONFIG_COMFORTNOISE_ENCODER)+= cngenc.o
 OBJS-$(CONFIG_CPIA_DECODER)+= cpia.o
 OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o
 OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o
+OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadata.o\
+  dca_core.o dca_exss.o dca_xll.o \
+  dcadsp.o dcadct.o synth_filter.o
 OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o dcadata.o
 OBJS-$(CONFIG_DDS_DECODER) += dds.o
 OBJS-$(CONFIG_DIRAC_DECODER)   += diracdec.o dirac.o diracdsp.o \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8b42098..2128546 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -387,7 +387,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(BINKAUDIO_RDFT,binkaudio_rdft);
 REGISTER_DECODER(BMV_AUDIO, bmv_audio);
 REGISTER_DECODER(COOK,  cook);
-REGISTER_ENCODER(DCA,   dca);
+REGISTER_ENCDEC (DCA,   dca);
 REGISTER_DECODER(DSD_LSBF,  dsd_lsbf);
 REGISTER_DECODER(DSD_MSBF,  dsd_msbf);
 REGISTER_DECODER(DSD_LSBF_PLANAR,   dsd_lsbf_planar);
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
new file mode 100644
index 000..f3c3972
--- /dev/null
+++ b/libavcodec/dcadec.c
@@ -0,0 +1,417 @@
+/*
+ * Copyright (C) 2016 foo86
+ *
+ * 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
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/channel_layout.h"
+
+#include "dcadec.h"
+#include "dcamath.h"
+#include "dca_syncwords.h"
+#include "profiles.h"
+
+#define MIN_PACKET_SIZE 16
+#define MAX_PACKET_SIZE 0x104000
+
+int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int 
dca_mask)
+{
+static const uint8_t dca2wav_norm[28] = {
+ 2,  0, 1, 9, 10,  3,  8,  4,  5,  9, 10, 6, 7, 12,
+13, 14, 3, 6,  7, 11, 12, 14, 16, 15, 17, 8, 4,  5,
+};
+
+static const uint8_t dca2wav_wide[28] = {
+ 2,  0, 1, 4,  5,  3,  8,  4,  5,  9, 10, 6, 7, 12,
+13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4,  5,
+};
+
+int dca_ch, wav_ch, nchannels = 0;
+
+if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
+for (dca_ch = 0; dca_ch < DCA_SPEAKER_COUNT; dca_ch++)
+if (dca_mask & (1U << dca_ch))
+ch_remap[nchannels++] = dca_ch;
+avctx->channel_layout = dca_mask;
+} else {
+int wav_mask = 0;
+int wav_map[18];
+const uint8_t *dca2wav;
+if (dca_mask == DCA_SPEAKER_LAYOUT_7POINT0_WIDE ||
+dca_mask == DCA_SPEAKER_LAYOUT_7POINT1_WIDE)
+dca2wav = dca2wav_wide;
+else
+dca2wav = dca2wav_norm;
+for (dca_ch = 0; dca_ch < 28; dca_ch++) {
+if (dca_mask & (1 << dca_ch)) {
+wav_ch = dca2wav[dca_ch];
+if (!(wav_mask & (1 << wav_ch))) {
+wav_map[wav_ch] = dca_ch;
+wav_mask |= 1 << wav_ch;
+}
+}
+}
+for (wav_ch = 0; wav_

[FFmpeg-devel] [PATCH v2 04/16] tests/fate/audio: remove dca-xll test

2016-01-21 Thread foo86
This test was made for non-bitexact XLL decoder implementation and is no
longer valid for new decoder.
---
 tests/fate/audio.mak | 5 -
 1 file changed, 5 deletions(-)

diff --git a/tests/fate/audio.mak b/tests/fate/audio.mak
index 493bb8c..93c19a0 100644
--- a/tests/fate/audio.mak
+++ b/tests/fate/audio.mak
@@ -21,11 +21,6 @@ fate-dca-core: CMD = pcm -i $(TARGET_SAMPLES)/dts/dts.ts
 fate-dca-core: CMP = oneoff
 fate-dca-core: REF = $(SAMPLES)/dts/dts.pcm
 
-FATE_DCA-$(CONFIG_DTS_DEMUXER) += fate-dca-xll
-fate-dca-xll: CMD = pcm -disable_xll 0 -i 
$(TARGET_SAMPLES)/dts/master_audio_7.1_24bit.dts
-fate-dca-xll: CMP = oneoff
-fate-dca-xll: REF = $(SAMPLES)/dts/master_audio_7.1_24bit_2.pcm
-
 FATE_SAMPLES_AUDIO-$(CONFIG_DCA_DECODER) += $(FATE_DCA-yes)
 fate-dca: $(FATE_DCA-yes)
 
-- 
2.1.4

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


[FFmpeg-devel] [PATCH v2 08/16] avcodec/dca: add math helpers and fixed point DCT

2016-01-21 Thread foo86
---
 libavcodec/dcadct.c  | 362 +++
 libavcodec/dcadct.h  |  32 +
 libavcodec/dcamath.h |  54 
 3 files changed, 448 insertions(+)
 create mode 100644 libavcodec/dcadct.c
 create mode 100644 libavcodec/dcadct.h
 create mode 100644 libavcodec/dcamath.h

diff --git a/libavcodec/dcadct.c b/libavcodec/dcadct.c
new file mode 100644
index 000..1082aa8
--- /dev/null
+++ b/libavcodec/dcadct.c
@@ -0,0 +1,362 @@
+/*
+ * Copyright (C) 2016 foo86
+ *
+ * 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
+ */
+
+#include "libavutil/common.h"
+
+#include "dcadct.h"
+#include "dcamath.h"
+
+static void sum_a(const int *input, int *output, int len)
+{
+int i;
+
+for (i = 0; i < len; i++)
+output[i] = input[2 * i] + input[2 * i + 1];
+}
+
+static void sum_b(const int *input, int *output, int len)
+{
+int i;
+
+output[0] = input[0];
+for (i = 1; i < len; i++)
+output[i] = input[2 * i] + input[2 * i - 1];
+}
+
+static void sum_c(const int *input, int *output, int len)
+{
+int i;
+
+for (i = 0; i < len; i++)
+output[i] = input[2 * i];
+}
+
+static void sum_d(const int *input, int *output, int len)
+{
+int i;
+
+output[0] = input[1];
+for (i = 1; i < len; i++)
+output[i] = input[2 * i - 1] + input[2 * i + 1];
+}
+
+static void dct_a(const int *input, int *output)
+{
+static const int cos_mod[8][8] = {
+ { 8348215,  8027397,  7398092,  6484482,  5321677,  3954362,  
2435084,   87 },
+ { 8027397,  5321677,   87, -3954362, -7398092, -8348215, 
-6484482, -2435084 },
+ { 7398092,   87, -6484482, -8027397, -2435084,  5321677,  
8348215,  3954362 },
+ { 6484482, -3954362, -8027397,   87,  8348215,  2435084, 
-7398092, -5321677 },
+ { 5321677, -7398092, -2435084,  8348215,  -87, -8027397,  
3954362,  6484482 },
+ { 3954362, -8348215,  5321677,  2435084, -8027397,  6484482,   
87, -7398092 },
+ { 2435084, -6484482,  8348215, -7398092,  3954362,   87, 
-5321677,  8027397 },
+ {  87, -2435084,  3954362, -5321677,  6484482, -7398092,  
8027397, -8348215 }
+};
+
+int i, j;
+
+for (i = 0; i < 8; i++) {
+int64_t res = 0;
+for (j = 0; j < 8; j++)
+res += (int64_t)cos_mod[i][j] * input[j];
+output[i] = norm23(res);
+}
+}
+
+static void dct_b(const int *input, int *output)
+{
+static const int cos_mod[8][7] = {
+{  8227423,  7750063,  6974873,  5931642,  4660461,  3210181,  1636536 
},
+{  6974873,  3210181, -1636536, -5931642, -8227423, -7750063, -4660461 
},
+{  4660461, -3210181, -8227423, -5931642,  1636536,  7750063,  6974873 
},
+{  1636536, -7750063, -4660461,  5931642,  6974873, -3210181, -8227423 
},
+{ -1636536, -7750063,  4660461,  5931642, -6974873, -3210181,  8227423 
},
+{ -4660461, -3210181,  8227423, -5931642, -1636536,  7750063, -6974873 
},
+{ -6974873,  3210181,  1636536, -5931642,  8227423, -7750063,  4660461 
},
+{ -8227423,  7750063, -6974873,  5931642, -4660461,  3210181, -1636536 
}
+};
+
+int i, j;
+
+for (i = 0; i < 8; i++) {
+int64_t res = input[0] * (INT64_C(1) << 23);
+for (j = 0; j < 7; j++)
+res += (int64_t)cos_mod[i][j] * input[1 + j];
+output[i] = norm23(res);
+}
+}
+
+static void mod_a(const int *input, int *output)
+{
+static const int cos_mod[16] = {
+  4199362,   4240198,   4323885,   4454708,
+  4639772,   4890013,   5221943,   5660703,
+ -6245623,  -7040975,  -8158494,  -9809974,
+-12450076, -17261920, -28585092, -85479984
+};
+
+int i, k;
+
+for (i = 0; i < 8; i++)
+output[i] = mul23(cos_mod[i], input[i] + input[8 + i]);
+
+for (i = 8, k = 7; i < 16; i++, k--)
+output[i] = mul23(cos_mod[i], input[k] - input[8 + k]);
+}
+
+static void mod_b(int *input, int *output)
+{
+static const int cos_mod[8] = {
+4214598,  4383036,  4755871,  5425934,
+6611520,  8897610, 14448934, 42791536
+};
+
+int i, k;
+
+for (i = 0; i < 8; i++)
+input[

[FFmpeg-devel] [PATCH v2 05/16] tests/checkasm: remove dcadsp test

2016-01-21 Thread foo86
---
 tests/checkasm/Makefile   |  2 +-
 tests/checkasm/checkasm.c |  1 -
 tests/checkasm/checkasm.h |  1 -
 tests/checkasm/dcadsp.c   | 92 ---
 4 files changed, 1 insertion(+), 95 deletions(-)
 delete mode 100644 tests/checkasm/dcadsp.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 301c2e2..07fe5bc 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -1,7 +1,7 @@
 # libavcodec tests
 AVCODECOBJS-$(CONFIG_ALAC_DECODER) += alacdsp.o
 AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o
-AVCODECOBJS-$(CONFIG_DCA_DECODER) += dcadsp.o synth_filter.o
+AVCODECOBJS-$(CONFIG_DCA_DECODER) += synth_filter.o
 AVCODECOBJS-$(CONFIG_FLACDSP)  += flacdsp.o
 AVCODECOBJS-$(CONFIG_FMTCONVERT)   += fmtconvert.o
 AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index dd37649..49fd2af 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -72,7 +72,6 @@ static const struct {
 { "bswapdsp", checkasm_check_bswapdsp },
 #endif
 #if CONFIG_DCA_DECODER
-{ "dcadsp", checkasm_check_dcadsp },
 { "synth_filter", checkasm_check_synth_filter },
 #endif
 #if CONFIG_FLACDSP
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 2100023..98c0216 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -32,7 +32,6 @@
 
 void checkasm_check_alacdsp(void);
 void checkasm_check_bswapdsp(void);
-void checkasm_check_dcadsp(void);
 void checkasm_check_flacdsp(void);
 void checkasm_check_fmtconvert(void);
 void checkasm_check_h264pred(void);
diff --git a/tests/checkasm/dcadsp.c b/tests/checkasm/dcadsp.c
deleted file mode 100644
index 5c7ff6f..000
--- a/tests/checkasm/dcadsp.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2015 Janne Grunau
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- */
-
-#include 
-#include 
-#include 
-
-#include "libavutil/internal.h"
-#include "libavutil/intfloat.h"
-#include "libavcodec/dca.h"
-#include "libavcodec/dcadsp.h"
-#include "libavcodec/dcadata.h"
-
-#include "checkasm.h"
-
-#define randomize_lfe_fir(size) \
-do {\
-int i;  \
-for (i = 0; i < size; i++) {\
-float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f;\
-in[i] = f;  \
-}   \
-for (i = 0; i < 256; i++) { \
-float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f;\
-coeffs[i] = f;  \
-}   \
-} while (0)
-
-#define check_lfe_fir(decifactor, eps)  \
-do {\
-LOCAL_ALIGNED_16(float, in, [256 / decifactor]);\
-LOCAL_ALIGNED_16(float, out0,   [decifactor * 2]);  \
-LOCAL_ALIGNED_16(float, out1,   [decifactor * 2]);  \
-LOCAL_ALIGNED_16(float, coeffs, [256]); \
-int i;  \
-const float * in_ptr = in + (256 / decifactor) - 1; \
-declare_func(void, float *out, const float *in, const float *coeffs); \
-/* repeat the test several times */ \
-for (i = 0; i < 32; i++) {  \
-int j;  \
-memset(out0,0, sizeof(*out0) * 2 * decifactor); \
-memset(out1, 0xFF, sizeof(*out1) * 2 * decifactor); \
-randomize_lfe_fir(256 / decifactor);\
-call_ref(out0, in_ptr, coeffs); \
-call_new(out1, in_ptr, coeffs); \
-for (j = 0; j < 2 * decifactor; j++) {  \
-if 

[FFmpeg-devel] [PATCH v2 06/16] avcodec/dca: add REV1AUX sync word

2016-01-21 Thread foo86
---
 libavcodec/dca_syncwords.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/dca_syncwords.h b/libavcodec/dca_syncwords.h
index 6981cb8..4d2cd5f 100644
--- a/libavcodec/dca_syncwords.h
+++ b/libavcodec/dca_syncwords.h
@@ -31,5 +31,6 @@
 #defineDCA_SYNCWORD_XLL  0x41A29547U
 #defineDCA_SYNCWORD_SUBSTREAM0x64582025U
 #defineDCA_SYNCWORD_SUBSTREAM_CORE   0x02B09261U
+#defineDCA_SYNCWORD_REV1AUX  0x9A1105A0U
 
 #endif /* AVCODEC_DCA_SYNCWORDS_H */
-- 
2.1.4

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


  1   2   >