[FFmpeg-cvslog] MAINTAINERS: add myself as mdct/opus maintainer

2017-02-13 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Sat Feb 
11 21:49:04 2017 +| [965503d3543c10d4dbbb3ae21e52296453e13b69] | committer: 
Rostislav Pehlivanov

MAINTAINERS: add myself as mdct/opus maintainer

Signed-off-by: Rostislav Pehlivanov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=965503d3543c10d4dbbb3ae21e52296453e13b69
---

 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 80721e1..93a30ec 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -115,6 +115,8 @@ Generic Parts:
 lzw.*   Michael Niedermayer
   floating point AAN DCT:
 faandct.c, faandct.hMichael Niedermayer
+  Non-power-of-two MDCT:
+mdct15.c, mdct15.h  Rostislav Pehlivanov
   Golomb coding:
 golomb.c, golomb.h  Michael Niedermayer
   motion estimation:
@@ -209,6 +211,7 @@ Codecs:
   msvideo1.cMike Melanson
   nuv.c Reimar Doeffinger
   nvenc*Timo Rothenpieler
+  opus* Rostislav Pehlivanov
   paf.* Paul B Mahol
   pcx.c Ivo van Poorten
   pgssubdec.c   Reimar Doeffinger

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


[FFmpeg-cvslog] opus_rc: add entropy encoding functions

2017-02-13 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Wed Feb  
1 03:13:05 2017 +| [373ee2c61871369c05efb1f7db5b723924a4b840] | committer: 
Rostislav Pehlivanov

opus_rc: add entropy encoding functions

Mostly used the RFC document, the decoding functions and
the reference encoder's implmenentation as a reference.

Signed-off-by: Rostislav Pehlivanov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=373ee2c61871369c05efb1f7db5b723924a4b840
---

 libavcodec/opus_rc.c | 182 ++-
 libavcodec/opus_rc.h |  35 --
 2 files changed, 212 insertions(+), 5 deletions(-)

diff --git a/libavcodec/opus_rc.c b/libavcodec/opus_rc.c
index b0e72f6..85268bd 100644
--- a/libavcodec/opus_rc.c
+++ b/libavcodec/opus_rc.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2012 Andrew D'Addesio
  * Copyright (c) 2013-2014 Mozilla Corporation
- * Copyright (c) 2016 Rostislav Pehlivanov 
+ * Copyright (c) 2017 Rostislav Pehlivanov 
  *
  * This file is part of FFmpeg.
  *
@@ -29,6 +29,21 @@
 #define OPUS_RC_BOT (OPUS_RC_TOP >> OPUS_RC_SYM)
 #define OPUS_RC_SHIFT (OPUS_RC_BITS - OPUS_RC_SYM - 1)
 
+static av_always_inline void opus_rc_enc_carryout(OpusRangeCoder *rc, int cbuf)
+{
+const int cb = cbuf >> OPUS_RC_SYM, mb = (OPUS_RC_CEIL + cb) & 
OPUS_RC_CEIL;
+if (cbuf == OPUS_RC_CEIL) {
+rc->ext++;
+return;
+}
+rc->rng_cur[0] = rc->rem + cb;
+rc->rng_cur += (rc->rem >= 0);
+for (; rc->ext > 0; rc->ext--)
+*rc->rng_cur++ = mb;
+av_assert0(rc->rng_cur < rc->rb.position);
+rc->rem = cbuf & OPUS_RC_CEIL; /* Propagate */
+}
+
 static av_always_inline void opus_rc_dec_normalize(OpusRangeCoder *rc)
 {
 while (rc->range <= OPUS_RC_BOT) {
@@ -38,6 +53,16 @@ static av_always_inline void 
opus_rc_dec_normalize(OpusRangeCoder *rc)
 }
 }
 
+static av_always_inline void opus_rc_enc_normalize(OpusRangeCoder *rc)
+{
+while (rc->range <= OPUS_RC_BOT) {
+opus_rc_enc_carryout(rc, rc->value >> OPUS_RC_SHIFT);
+rc->value = (rc->value << OPUS_RC_SYM) & (OPUS_RC_TOP - 1);
+rc->range <<= OPUS_RC_SYM;
+rc->total_bits += OPUS_RC_SYM;
+}
+}
+
 static av_always_inline void opus_rc_dec_update(OpusRangeCoder *rc, uint32_t 
scale,
 uint32_t low, uint32_t high,
 uint32_t total)
@@ -48,6 +73,20 @@ static av_always_inline void 
opus_rc_dec_update(OpusRangeCoder *rc, uint32_t sca
 opus_rc_dec_normalize(rc);
 }
 
+/* Main encoding function, this needs to go fast */
+static av_always_inline void opus_rc_enc_update(OpusRangeCoder *rc, uint32_t 
b, uint32_t p,
+uint32_t p_tot, const int ptwo)
+{
+uint32_t rscaled, cnd = !!b;
+if (ptwo) /* Whole function is inlined so hopefully branch is optimized 
out */
+rscaled = rc->range >> ff_log2(p_tot);
+else
+rscaled = rc->range/p_tot;
+rc->value +=cnd*(rc->range - rscaled*(p_tot - b));
+rc->range  = (!cnd)*(rc->range - rscaled*(p_tot - p)) + cnd*rscaled*(p - 
b);
+opus_rc_enc_normalize(rc);
+}
+
 uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf)
 {
 unsigned int k, scale, total, symbol, low, high;
@@ -67,6 +106,11 @@ uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const 
uint16_t *cdf)
 return k;
 }
 
+void ff_opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf)
+{
+opus_rc_enc_update(rc, cdf[val], cdf[val + 1], cdf[0], 1);
+}
+
 uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
 {
 uint32_t k, scale;
@@ -84,6 +128,12 @@ uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t 
bits)
 return k;
 }
 
+void ff_opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits)
+{
+bits = (1 << bits) - 1;
+opus_rc_enc_update(rc, (!!val)*bits, bits + !!val, bits + 1, 1);
+}
+
 /**
  * CELT: read 1-25 raw bits at the end of the frame, backwards byte-wise
  */
@@ -106,6 +156,27 @@ uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t 
count)
 }
 
 /**
+ * CELT: write 0 - 31 bits to the rawbits buffer
+ */
+void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count)
+{
+const int to_write = FFMIN(32 - rc->rb.cachelen, count);
+
+rc->total_bits += count;
+rc->rb.cacheval |= av_mod_uintp2(val, to_write) << rc->rb.cachelen;
+rc->rb.cachelen = (rc->rb.cachelen + to_write) % 32;
+
+if (!rc->rb.cachelen && count) {
+AV_WB32(rc->rb.position, rc->rb.cacheval);
+rc->rb.bytes+= 4;
+rc->rb.position -= 4;
+rc->rb.cachelen = count - to_write;
+rc->rb.cacheval = av_mod_uintp2(val >> to_write, rc->rb.cachelen);
+av_assert0(rc->rng_cur < rc->rb.position);
+}
+}
+
+/**
  * CELT: read a uniform distribution
  */
 uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
@@ -127,6 +198,16 @@ uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t 

[FFmpeg-cvslog] imdct15: rename to mdct15 and add a forward transform

2017-02-13 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Wed Feb  
1 03:13:06 2017 +| [d2119f624d392f53f80c3d36ffaadca23aef8a10] | committer: 
Rostislav Pehlivanov

imdct15: rename to mdct15 and add a forward transform

Handles strides (needed for Opus transients), does pre-reindexing and folding
without needing a copy.

Signed-off-by: Rostislav Pehlivanov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d2119f624d392f53f80c3d36ffaadca23aef8a10
---

 configure  |  6 +--
 libavcodec/Makefile|  2 +-
 libavcodec/aac.h   |  4 +-
 libavcodec/aacdec.c|  2 +-
 libavcodec/aacdec_template.c   |  4 +-
 libavcodec/{imdct15.c => mdct15.c} | 90 +++---
 libavcodec/{imdct15.h => mdct15.h} | 28 +++-
 libavcodec/opus_celt.c | 10 ++---
 8 files changed, 105 insertions(+), 41 deletions(-)

diff --git a/configure b/configure
index 72b86bc..a7cd3a2 100755
--- a/configure
+++ b/configure
@@ -2107,7 +2107,7 @@ CONFIG_EXTRA="
 huffyuvencdsp
 idctdsp
 iirfilter
-imdct15
+mdct15
 intrax8
 iso_media
 ividsp
@@ -2349,7 +2349,7 @@ vc1dsp_select="h264chroma qpeldsp startcode"
 rdft_select="fft"
 
 # decoders / encoders
-aac_decoder_select="imdct15 mdct sinewin"
+aac_decoder_select="mdct15 mdct sinewin"
 aac_fixed_decoder_select="mdct sinewin"
 aac_encoder_select="audio_frame_queue iirfilter lpc mdct sinewin"
 aac_latm_decoder_select="aac_decoder aac_latm_parser"
@@ -2491,7 +2491,7 @@ nellymoser_encoder_select="audio_frame_queue mdct sinewin"
 nuv_decoder_select="idctdsp lzo"
 on2avc_decoder_select="mdct"
 opus_decoder_deps="swresample"
-opus_decoder_select="imdct15"
+opus_decoder_select="mdct15"
 png_decoder_select="zlib"
 png_encoder_select="llvidencdsp zlib"
 prores_decoder_select="blockdsp idctdsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5c2940e..d5c36ff 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -84,7 +84,7 @@ OBJS-$(CONFIG_HUFFYUVDSP)  += huffyuvdsp.o
 OBJS-$(CONFIG_HUFFYUVENCDSP)   += huffyuvencdsp.o
 OBJS-$(CONFIG_IDCTDSP) += idctdsp.o simple_idct.o jrevdct.o
 OBJS-$(CONFIG_IIRFILTER)   += iirfilter.o
-OBJS-$(CONFIG_IMDCT15) += imdct15.o
+OBJS-$(CONFIG_MDCT15)  += mdct15.o
 OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o
 OBJS-$(CONFIG_IVIDSP)  += ivi_dsp.o
 OBJS-$(CONFIG_JNI) += ffjni.o jni.o
diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index b1f4aa7..97a2df6 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -36,7 +36,7 @@
 #include "libavutil/fixed_dsp.h"
 #include "avcodec.h"
 #if !USE_FIXED
-#include "imdct15.h"
+#include "mdct15.h"
 #endif
 #include "fft.h"
 #include "mpeg4audio.h"
@@ -327,7 +327,7 @@ struct AACContext {
 #if USE_FIXED
 AVFixedDSPContext *fdsp;
 #else
-IMDCT15Context *mdct480;
+MDCT15Context *mdct480;
 AVFloatDSPContext *fdsp;
 #endif /* USE_FIXED */
 int random_state;
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 08d92fe..726ea03 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -42,7 +42,7 @@
 #include "internal.h"
 #include "get_bits.h"
 #include "fft.h"
-#include "imdct15.h"
+#include "mdct15.h"
 #include "lpc.h"
 #include "kbdwin.h"
 #include "sinewin.h"
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index fd6a0f1..4e0a952 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1207,7 +1207,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
 AAC_RENAME_32(ff_mdct_init)(&ac->mdct_small,  8, 1, 1.0 / RANGE15(128.0));
 AAC_RENAME_32(ff_mdct_init)(&ac->mdct_ltp,   11, 0, RANGE15(-2.0));
 #if !USE_FIXED
-ret = ff_imdct15_init(&ac->mdct480, 5);
+ret = ff_mdct15_init(&ac->mdct480, 1, 5, -1.0f);
 if (ret < 0)
 return ret;
 #endif
@@ -3217,7 +3217,7 @@ static av_cold int aac_decode_close(AVCodecContext *avctx)
 ff_mdct_end(&ac->mdct_ld);
 ff_mdct_end(&ac->mdct_ltp);
 #if !USE_FIXED
-ff_imdct15_uninit(&ac->mdct480);
+ff_mdct15_uninit(&ac->mdct480);
 #endif
 av_freep(&ac->fdsp);
 return 0;
diff --git a/libavcodec/imdct15.c b/libavcodec/mdct15.c
similarity index 73%
rename from libavcodec/imdct15.c
rename to libavcodec/mdct15.c
index a6d4249..a6bea2d 100644
--- a/libavcodec/imdct15.c
+++ b/libavcodec/mdct15.c
@@ -33,7 +33,8 @@
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
 
-#include "imdct15.h"
+#include "avfft.h"
+#include "mdct15.h"
 
 // complex c = a * b
 #define CMUL3(cre, cim, are, aim, bre, bim)  \
@@ -44,9 +45,9 @@ do { \
 
 #define CMUL(c, a, b) CMUL3((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
 
-av_cold void ff_imdct15_uninit(IMDCT15Context **ps)
+av_cold void ff_mdct15_uninit(MDCT15Context **ps)
 {
-IMDCT15Context

[FFmpeg-cvslog] opus_celt: rename structures to better names and reorganize them

2017-02-13 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Sat Feb 
11 00:25:07 2017 +| [07b78340dd1e6a8147585e31b2dae106d608eca2] | committer: 
Rostislav Pehlivanov

opus_celt: rename structures to better names and reorganize them

This is meant to be applied on top of my previous patch which
split PVQ into celt_pvq.c and made opus_celt.h

Essentially nothing has been changed other than renaming CeltFrame
to CeltBlock (CeltFrame had absolutely nothing at all to do with
a frame) and CeltContext to CeltFrame.
3 variables have been put in CeltFrame as they make more sense
there rather than being passed around as arguments.
The coefficients have been moved to the CeltBlock structure
(why the hell were they in CeltContext and not in CeltFrame??).

Now the encoder would be able to use the exact context the decoder
uses (plus a couple of extra fields in there).

FATE passes, no slowdowns, etc.

Signed-off-by: Rostislav Pehlivanov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07b78340dd1e6a8147585e31b2dae106d608eca2
---

 libavcodec/opus.h  |  22 +-
 libavcodec/opus_celt.c | 722 -
 libavcodec/opus_celt.h |  89 +++---
 libavcodec/opus_pvq.c  |  50 ++--
 libavcodec/opus_pvq.h  |   2 +-
 libavcodec/opusdec.c   |   7 +-
 libavcodec/opustab.c   |   4 +
 libavcodec/opustab.h   |   4 +
 8 files changed, 458 insertions(+), 442 deletions(-)

diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index be04249..c3cbaec 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -62,7 +62,9 @@ static const uint8_t opus_default_extradata[30] = {
 enum OpusMode {
 OPUS_MODE_SILK,
 OPUS_MODE_HYBRID,
-OPUS_MODE_CELT
+OPUS_MODE_CELT,
+
+OPUS_MODE_NB
 };
 
 enum OpusBandwidth {
@@ -70,12 +72,14 @@ enum OpusBandwidth {
 OPUS_BANDWIDTH_MEDIUMBAND,
 OPUS_BANDWIDTH_WIDEBAND,
 OPUS_BANDWIDTH_SUPERWIDEBAND,
-OPUS_BANDWIDTH_FULLBAND
+OPUS_BANDWIDTH_FULLBAND,
+
+OPUS_BANDWITH_NB
 };
 
 typedef struct SilkContext SilkContext;
 
-typedef struct CeltContext CeltContext;
+typedef struct CeltFrame CeltFrame;
 
 typedef struct OpusPacket {
 int packet_size;/**< packet size */
@@ -100,7 +104,7 @@ typedef struct OpusStreamContext {
 OpusRangeCoder rc;
 OpusRangeCoder redundancy_rc;
 SilkContext *silk;
-CeltContext *celt;
+CeltFrame *celt;
 AVFloatDSPContext *fdsp;
 
 float silk_buf[2][960];
@@ -185,14 +189,4 @@ int ff_silk_decode_superframe(SilkContext *s, 
OpusRangeCoder *rc,
   enum OpusBandwidth bandwidth, int coded_channels,
   int duration_ms);
 
-int ff_celt_init(AVCodecContext *avctx, CeltContext **s, int output_channels);
-
-void ff_celt_free(CeltContext **s);
-
-void ff_celt_flush(CeltContext *s);
-
-int ff_celt_decode_frame(CeltContext *s, OpusRangeCoder *rc,
- float **output, int coded_channels, int frame_size,
- int startband,  int endband);
-
 #endif /* AVCODEC_OPUS_H */
diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c
index 71ef896..af3c100 100644
--- a/libavcodec/opus_celt.c
+++ b/libavcodec/opus_celt.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2012 Andrew D'Addesio
  * Copyright (c) 2013-2014 Mozilla Corporation
+ * Copyright (c) 2016 Rostislav Pehlivanov 
  *
  * This file is part of FFmpeg.
  *
@@ -28,7 +29,7 @@
 #include "opustab.h"
 #include "opus_pvq.h"
 
-static void celt_decode_coarse_energy(CeltContext *s, OpusRangeCoder *rc)
+static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc)
 {
 int i, j;
 float prev[2] = {0};
@@ -38,29 +39,29 @@ static void celt_decode_coarse_energy(CeltContext *s, 
OpusRangeCoder *rc)
 /* use the 2D z-transform to apply prediction in both */
 /* the time domain (alpha) and the frequency domain (beta) */
 
-if (opus_rc_tell(rc)+3 <= s->framebits && ff_opus_rc_dec_log(rc, 3)) {
+if (opus_rc_tell(rc)+3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) {
 /* intra frame */
 alpha = 0;
 beta  = 1.0f - 4915.0f/32768.0f;
-model = ff_celt_coarse_energy_dist[s->duration][1];
+model = ff_celt_coarse_energy_dist[f->size][1];
 } else {
-alpha = ff_celt_alpha_coef[s->duration];
-beta  = 1.0f - ff_celt_beta_coef[s->duration];
-model = ff_celt_coarse_energy_dist[s->duration][0];
+alpha = ff_celt_alpha_coef[f->size];
+beta  = 1.0f - ff_celt_beta_coef[f->size];
+model = ff_celt_coarse_energy_dist[f->size][0];
 }
 
 for (i = 0; i < CELT_MAX_BANDS; i++) {
-for (j = 0; j < s->coded_channels; j++) {
-CeltFrame *frame = &s->frame[j];
+for (j = 0; j < f->channels; j++) {
+CeltBlock *block = &f->block[j];
 float value;
 int available;
 
-if (i < s->startband || i >= s->endband) {
-frame->energy[i] = 0.0;
+if (i < f->start_band |

[FFmpeg-cvslog] opus_celt: move quantization and band decoding to opus_pvq.c

2017-02-13 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Sat Feb 
11 00:25:06 2017 +| [e538108c219d7b3628a9ec33d85bf252ee70c957] | committer: 
Rostislav Pehlivanov

opus_celt: move quantization and band decoding to opus_pvq.c

A huge amount can be reused by the encoder, as the only thing
which needs to be done would be to add a 10 line celt_icwrsi,
a wrapper around it (celt_alg_quant) and templating the
ff_celt_decode_band to replace entropy decoding functions
with entropy encoding.

There is no performance loss but in fact a performance gain of
around 6% which is caused by the compiler being able to optimize
the decoding more efficiently.

Signed-off-by: Rostislav Pehlivanov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e538108c219d7b3628a9ec33d85bf252ee70c957
---

 libavcodec/Makefile|   2 +-
 libavcodec/opus.h  |  10 -
 libavcodec/opus_celt.c | 828 +
 libavcodec/opus_celt.h | 133 
 libavcodec/opus_pvq.c  | 729 +++
 libavcodec/opus_pvq.h  |  35 +++
 6 files changed, 909 insertions(+), 828 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index d5c36ff..e1f83a0 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -443,7 +443,7 @@ OBJS-$(CONFIG_NELLYMOSER_ENCODER)  += nellymoserenc.o 
nellymoser.o
 OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o
 OBJS-$(CONFIG_ON2AVC_DECODER)  += on2avc.o on2avcdata.o
 OBJS-$(CONFIG_OPUS_DECODER)+= opusdec.o opus.o opus_celt.o 
opus_rc.o \
-  opus_silk.o opustab.o vorbis_data.o
+  opus_pvq.o opus_silk.o opustab.o 
vorbis_data.o
 OBJS-$(CONFIG_PAF_AUDIO_DECODER)   += pafaudio.o
 OBJS-$(CONFIG_PAF_VIDEO_DECODER)   += pafvideo.o
 OBJS-$(CONFIG_PAM_DECODER) += pnmdec.o pnm.o
diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 2c3d63a..be04249 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -43,16 +43,6 @@
 #define CELT_MAX_LOG_BLOCKS  3
 #define CELT_MAX_FRAME_SIZE  (CELT_SHORT_BLOCKSIZE * (1 << 
CELT_MAX_LOG_BLOCKS))
 #define CELT_MAX_BANDS   21
-#define CELT_VECTORS 11
-#define CELT_ALLOC_STEPS 6
-#define CELT_FINE_OFFSET 21
-#define CELT_MAX_FINE_BITS   8
-#define CELT_NORM_SCALE  16384
-#define CELT_QTHETA_OFFSET   4
-#define CELT_QTHETA_OFFSET_TWOPHASE  16
-#define CELT_DEEMPH_COEFF0.85000610f
-#define CELT_POSTFILTER_MINPERIOD15
-#define CELT_ENERGY_SILENCE  (-28.0f)
 
 #define SILK_HISTORY 322
 #define SILK_MAX_LPC 16
diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c
index a0f018e..71ef896 100644
--- a/libavcodec/opus_celt.c
+++ b/libavcodec/opus_celt.c
@@ -24,109 +24,9 @@
  * Opus CELT decoder
  */
 
-#include 
-
-#include "libavutil/float_dsp.h"
-#include "libavutil/libm.h"
-
-#include "mdct15.h"
-#include "opus.h"
+#include "opus_celt.h"
 #include "opustab.h"
-
-enum CeltSpread {
-CELT_SPREAD_NONE,
-CELT_SPREAD_LIGHT,
-CELT_SPREAD_NORMAL,
-CELT_SPREAD_AGGRESSIVE
-};
-
-typedef struct CeltFrame {
-float energy[CELT_MAX_BANDS];
-float prev_energy[2][CELT_MAX_BANDS];
-
-uint8_t collapse_masks[CELT_MAX_BANDS];
-
-/* buffer for mdct output + postfilter */
-DECLARE_ALIGNED(32, float, buf)[2048];
-
-/* postfilter parameters */
-int pf_period_new;
-float pf_gains_new[3];
-int pf_period;
-float pf_gains[3];
-int pf_period_old;
-float pf_gains_old[3];
-
-float deemph_coeff;
-} CeltFrame;
-
-struct CeltContext {
-// constant values that do not change during context lifetime
-AVCodecContext*avctx;
-MDCT15Context *imdct[4];
-AVFloatDSPContext  *dsp;
-int output_channels;
-
-// values that have inter-frame effect and must be reset on flush
-CeltFrame frame[2];
-uint32_t seed;
-int flushed;
-
-// values that only affect a single frame
-int coded_channels;
-int framebits;
-int duration;
-
-/* number of iMDCT blocks in the frame */
-int blocks;
-/* size of each block */
-int blocksize;
-
-int startband;
-int endband;
-int codedbands;
-
-int anticollapse_bit;
-
-int intensitystereo;
-int dualstereo;
-enum CeltSpread spread;
-
-int remaining;
-int remaining2;
-int fine_bits[CELT_MAX_BANDS];
-int fine_priority[CELT_MAX_BANDS];
-int pulses   [CELT_MAX_BANDS];
-int tf_change[CELT_MAX_BANDS];
-
-DECLARE_ALIGNED(32, float, coeffs)[2][CELT_MAX_FRAME_SIZE];
-DECLARE_ALIGNED(32, float, scratch)[22 * 8]; // MAX(ff_celt_freq_range) * 
1<> 13;
-x = (32767-x) + ROUND_MUL16(x, (-7651 + ROUND_MUL16(x, (8277 + 
ROUND_MUL16(-626, x);
-return 1+x;
-}
-
-static inline int celt_log2tan(int isin, int icos)
-{
-int lc, ls;
-lc 

[FFmpeg-cvslog] opus: add a native Opus encoder

2017-02-13 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Sat Feb 
11 00:25:08 2017 +| [5f47c85e5c961d5985a01e16697439d179b03a0e] | committer: 
Rostislav Pehlivanov

opus: add a native Opus encoder

This marks the first time anyone has written an Opus encoder without
using any libopus code. The aim of the encoder is to prove how far
the format can go by writing the craziest encoder for it.

Right now the encoder's basic, it only supports CBR encoding, however
internally every single feature the CELT layer has is implemented
(except the pitch pre-filter which needs to work well with the rest of
whatever gets implemented). Psychoacoustic and rate control systems are
under development.

The encoder takes in frames of 120 samples and depending on the value of
opus_delay the plan is to use the extra buffered frames as lookahead.
Right now the encoder will pick the nearest largest legal frame size and
won't use the lookahead, but that'll change once there's a
psychoacoustic system.

Even though its a pretty basic encoder its already outperforming
any other native encoder FFmpeg has by a huge amount.

The PVQ search algorithm is faster and more accurate than libopus's
algorithm so the encoder's performance is close to that of libopus
at zero complexity (libopus has more SIMD).
The algorithm might be ported to libopus or other codecs using PVQ in
the future.

The encoder still has a few minor bugs, like desyncs at ultra low
bitrates (below 9kbps with 20ms frames).

Signed-off-by: Rostislav Pehlivanov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5f47c85e5c961d5985a01e16697439d179b03a0e
---

 configure  |1 +
 libavcodec/Makefile|1 +
 libavcodec/allcodecs.c |2 +-
 libavcodec/opus_celt.h |   16 +
 libavcodec/opus_pvq.c  |  444 ++-
 libavcodec/opus_pvq.h  |6 +
 libavcodec/opusenc.c   | 1130 
 7 files changed, 1591 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index a7cd3a2..2f761c3 100755
--- a/configure
+++ b/configure
@@ -2492,6 +2492,7 @@ nuv_decoder_select="idctdsp lzo"
 on2avc_decoder_select="mdct"
 opus_decoder_deps="swresample"
 opus_decoder_select="mdct15"
+opus_encoder_select="audio_frame_queue audiodsp mdct15"
 png_decoder_select="zlib"
 png_encoder_select="llvidencdsp zlib"
 prores_decoder_select="blockdsp idctdsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e1f83a0..a1ce264 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -444,6 +444,7 @@ OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o
 OBJS-$(CONFIG_ON2AVC_DECODER)  += on2avc.o on2avcdata.o
 OBJS-$(CONFIG_OPUS_DECODER)+= opusdec.o opus.o opus_celt.o 
opus_rc.o \
   opus_pvq.o opus_silk.o opustab.o 
vorbis_data.o
+OBJS-$(CONFIG_OPUS_ENCODER)+= opusenc.o opus_rc.o opustab.o 
opus_pvq.o
 OBJS-$(CONFIG_PAF_AUDIO_DECODER)   += pafaudio.o
 OBJS-$(CONFIG_PAF_VIDEO_DECODER)   += pafvideo.o
 OBJS-$(CONFIG_PAM_DECODER) += pnmdec.o pnm.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 3680129..f12a54d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -449,7 +449,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(MPC8,  mpc8);
 REGISTER_ENCDEC (NELLYMOSER,nellymoser);
 REGISTER_DECODER(ON2AVC,on2avc);
-REGISTER_DECODER(OPUS,  opus);
+REGISTER_ENCDEC (OPUS,  opus);
 REGISTER_DECODER(PAF_AUDIO, paf_audio);
 REGISTER_DECODER(QCELP, qcelp);
 REGISTER_DECODER(QDM2,  qdm2);
diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
index 7b46a51..23c2089 100644
--- a/libavcodec/opus_celt.h
+++ b/libavcodec/opus_celt.h
@@ -61,14 +61,23 @@ enum CeltBlockSize {
 
 typedef struct CeltBlock {
 float energy[CELT_MAX_BANDS];
+float lin_energy[CELT_MAX_BANDS];
+float error_energy[CELT_MAX_BANDS];
 float prev_energy[2][CELT_MAX_BANDS];
 
 uint8_t collapse_masks[CELT_MAX_BANDS];
 
+int band_bins[CELT_MAX_BANDS]; /* MDCT bins per band */
+float *band_coeffs[CELT_MAX_BANDS];
+
 /* buffer for mdct output + postfilter */
 DECLARE_ALIGNED(32, float, buf)[2048];
 DECLARE_ALIGNED(32, float, coeffs)[CELT_MAX_FRAME_SIZE];
 
+/* Used by the encoder */
+DECLARE_ALIGNED(32, float, overlap)[120];
+DECLARE_ALIGNED(32, float, samples)[CELT_MAX_FRAME_SIZE];
+
 /* postfilter parameters */
 int   pf_period_new;
 float pf_gains_new[3];
@@ -94,6 +103,12 @@ struct CeltFrame {
 int end_band;
 int coded_bands;
 int transient;
+int intra;
+int pfilter;
+int skip_band_floor;
+int tf_select;
+int alloc_trim;
+int alloc_boost[CELT_MAX_BANDS];
 int blocks;/* number of iMDCT blocks in the frame, depends on 
transient */
 int blocksize; /* size of each block */
 int silence;  

[FFmpeg-cvslog] doc/encoders: add documentation for the Opus encoder

2017-02-13 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Tue Feb 
14 06:14:15 2017 +| [3a7f0055b445d0e9bf7f8037739d218b8acc982e] | committer: 
Rostislav Pehlivanov

doc/encoders: add documentation for the Opus encoder

Signed-off-by: Rostislav Pehlivanov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3a7f0055b445d0e9bf7f8037739d218b8acc982e
---

 doc/encoders.texi | 21 +
 1 file changed, 21 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 2026a9f..430f9f8 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -616,6 +616,27 @@ and slightly improves compression.
 
 @end table
 
+@anchor{opusenc}
+@section opus
+
+Opus encoder.
+
+This is a native FFmpeg encoder for the Opus format. Currently its in 
development and
+only implements the CELT part of the codec. Its quality is usually worse and 
at best
+is equal to the libopus encoder.
+
+@subsection Options
+
+@table @option
+@item b
+Set bit rate in bits/s. If unspecified it uses the number of channels and the 
layout
+to make a good guess.
+
+@item opus_delay
+Sets the maximum delay in milliseconds. Lower delays than 20ms will very 
quickly
+decrease quality.
+@end table
+
 @anchor{libfdk-aac-enc}
 @section libfdk_aac
 

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


[FFmpeg-cvslog] avformat/http: Check for truncated buffers in http_connect()

2017-02-13 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Mon 
Feb 13 12:47:49 2017 +0100| [8fa18e042ad2c078f759692f1db5629d16d70595] | 
committer: Michael Niedermayer

avformat/http: Check for truncated buffers in http_connect()

Reported-by: SleepProgger 
Reviewed-by: Steven Liu 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8fa18e042ad2c078f759692f1db5629d16d70595
---

 libavformat/http.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 944a6cf..bd1be3f 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1011,6 +1011,7 @@ static int http_connect(URLContext *h, const char *path, 
const char *local_path,
 int len = 0;
 const char *method;
 int send_expect_100 = 0;
+int ret;
 
 /* send http header */
 post = h->flags & AVIO_FLAG_WRITE;
@@ -1107,7 +1108,7 @@ static int http_connect(URLContext *h, const char *path, 
const char *local_path,
 if (s->headers)
 av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
 
-snprintf(s->buffer, sizeof(s->buffer),
+ret = snprintf(s->buffer, sizeof(s->buffer),
  "%s %s HTTP/1.1\r\n"
  "%s"
  "%s"
@@ -1123,6 +1124,14 @@ static int http_connect(URLContext *h, const char *path, 
const char *local_path,
 
 av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer);
 
+if (strlen(headers) + 1 == sizeof(headers) ||
+ret >= sizeof(s->buffer)) {
+av_log(h, AV_LOG_ERROR, "overlong headers\n");
+err = AVERROR(EINVAL);
+goto done;
+}
+
+
 if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
 goto done;
 

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


[FFmpeg-cvslog] doc/ffmpeg: document trailing "?" in map option

2017-02-13 Thread Lou Logan
ffmpeg | branch: master | Lou Logan  | Mon Feb 13 15:26:43 2017 
-0900| [1c049d5ffe08b3af36844cdbe7a5950879122b8b] | committer: Lou Logan

doc/ffmpeg: document trailing "?" in map option

This feature was added in 2375a85c36c4941042e6ee58a31d6560bde91d37.

Signed-off-by: Lou Logan 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1c049d5ffe08b3af36844cdbe7a5950879122b8b
---

 doc/ffmpeg.texi | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 11b527d..8b08e22 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -871,7 +871,7 @@ Set the size of the canvas used to render subtitles.
 @section Advanced options
 
 @table @option
-@item -map 
[-]@var{input_file_id}[:@var{stream_specifier}][,@var{sync_file_id}[:@var{stream_specifier}]]
 | @var{[linklabel]} (@emph{output})
+@item -map 
[-]@var{input_file_id}[:@var{stream_specifier}][?][,@var{sync_file_id}[:@var{stream_specifier}]]
 | @var{[linklabel]} (@emph{output})
 
 Designate one or more input streams as a source for the output file. Each input
 stream is identified by the input file index @var{input_file_id} and
@@ -887,6 +887,11 @@ the source for output stream 1, etc.
 A @code{-} character before the stream identifier creates a "negative" mapping.
 It disables matching streams from already created mappings.
 
+A trailing @code{?} after the stream index will allow the map to be
+optional: if the map matches no streams the map will be ignored instead
+of failing. Note the map will still fail if an invalid input file index
+is used; such as if the map refers to a non-existant input.
+
 An alternative @var{[linklabel]} form will map outputs from complex filter
 graphs (see the @option{-filter_complex} option) to the output file.
 @var{linklabel} must correspond to a defined output link label in the graph.
@@ -924,6 +929,13 @@ To map all the streams except the second audio, use 
negative mappings
 ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT
 @end example
 
+To map the video and audio streams from the first input, and using the
+trailing @code{?}, ignore the audio mapping if no audio streams exist in
+the first input:
+@example
+ffmpeg -i INPUT -map 0:v -map 0:a? OUTPUT
+@end example
+
 To pick the English audio stream:
 @example
 ffmpeg -i INPUT -map 0:m:language:eng OUTPUT

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


[FFmpeg-cvslog] lavc: Add device context field to AVCodecContext

2017-02-13 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Thu Feb  9 00:23:36 
2017 +| [c1a5fca06f75cc0e7b9b2808fecaa0c1b424da50] | committer: Mark 
Thompson

lavc: Add device context field to AVCodecContext

For use by codec implementations which can allocate frames internally.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c1a5fca06f75cc0e7b9b2808fecaa0c1b424da50
---

 doc/APIchanges   |  3 +++
 libavcodec/avcodec.h | 24 +++-
 libavcodec/utils.c   |  1 +
 libavcodec/version.h |  2 +-
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 81e49c2..d739895 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2015-08-28
 
 API changes, most recent first:
 
+2017-02-13 - xxx - lavc 57.80.100 - avcodec.h
+  Add AVCodecContext.hw_device_ctx.
+
 2017-02-11 - xxx - lavu 55.47.100 - frame.h
   Add AVFrame.opaque_ref.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3e161ea..5616fb0 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3536,7 +3536,8 @@ typedef struct AVCodecContext {
 /**
  * A reference to the AVHWFramesContext describing the input (for encoding)
  * or output (decoding) frames. The reference is set by the caller and
- * afterwards owned (and freed) by libavcodec.
+ * afterwards owned (and freed) by libavcodec - it should never be read by
+ * the caller after being set.
  *
  * - decoding: This field should be set by the caller from the get_format()
  * callback. The previous reference (if any) will always be
@@ -3586,6 +3587,27 @@ typedef struct AVCodecContext {
  */
 int64_t max_pixels;
 
+/**
+ * A reference to the AVHWDeviceContext describing the device which will
+ * be used by a hardware encoder/decoder.  The reference is set by the
+ * caller and afterwards owned (and freed) by libavcodec.
+ *
+ * This should be used if either the codec device does not require
+ * hardware frames or any that are used are to be allocated internally by
+ * libavcodec.  If the user wishes to supply any of the frames used as
+ * encoder input or decoder output then hw_frames_ctx should be used
+ * instead.  When hw_frames_ctx is set in get_format() for a decoder, this
+ * field will be ignored while decoding the associated stream segment, but
+ * may again be used on a following one after another get_format() call.
+ *
+ * For both encoders and decoders this field should be set before
+ * avcodec_open2() is called and must not be written to thereafter.
+ *
+ * Note that some decoders may require this field to be set initially in
+ * order to support hw_frames_ctx at all - in that case, all frames
+ * contexts used must be created on the same device.
+ */
+AVBufferRef *hw_device_ctx;
 } AVCodecContext;
 
 AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index f8ec4c1..f4085bf 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3067,6 +3067,7 @@ av_cold int avcodec_close(AVCodecContext *avctx)
 avctx->nb_coded_side_data = 0;
 
 av_buffer_unref(&avctx->hw_frames_ctx);
+av_buffer_unref(&avctx->hw_device_ctx);
 
 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
 av_opt_free(avctx->priv_data);
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 5fb8794..49089db 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  79
+#define LIBAVCODEC_VERSION_MINOR  80
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

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


[FFmpeg-cvslog] avfilter/vf_lut: make it possible to clip pixel values that are out of valid range

2017-02-13 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Mon Feb 13 22:49:41 
2017 +0100| [aa234698e92fa856013a1391fac3526b06c4d533] | committer: Paul B Mahol

avfilter/vf_lut: make it possible to clip pixel values that are out of valid 
range

Previous behavior was not useful at all as such pixels where all mapped to 0.

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=aa234698e92fa856013a1391fac3526b06c4d533
---

 libavfilter/vf_lut.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index 2472673..d005afa 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -310,7 +310,7 @@ static int config_props(AVFilterLink *inlink)
 s->var_values[VAR_MAXVAL] = max[color];
 s->var_values[VAR_MINVAL] = min[color];
 
-for (val = 0; val < (1 << desc->comp[0].depth); val++) {
+for (val = 0; val < FF_ARRAY_ELEMS(s->lut[comp]); val++) {
 s->var_values[VAR_VAL] = val;
 s->var_values[VAR_CLIPVAL] = av_clip(val, min[color], max[color]);
 s->var_values[VAR_NEGVAL] =

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


[FFmpeg-cvslog] avfilter/vf_lut: do not always explicitly clip pixels

2017-02-13 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Mon Feb 13 21:52:51 
2017 +0100| [72864547f91f2864f75b2829d0c11317ef7b390b] | committer: Paul B Mahol

avfilter/vf_lut: do not always explicitly clip pixels

Old behaviour was not useful at all. New behaviour only emulate
old behaviour with default options.

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=72864547f91f2864f75b2829d0c11317ef7b390b
---

 libavfilter/vf_lut.c  | 26 +-
 tests/ref/fate/filter-pixfmts-lut | 58 +++
 2 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index 312bb37..2472673 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -84,17 +84,17 @@ typedef struct LutContext {
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
 static const AVOption options[] = {
-{ "c0", "set component #0 expression", OFFSET(comp_expr_str[0]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "c1", "set component #1 expression", OFFSET(comp_expr_str[1]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "c2", "set component #2 expression", OFFSET(comp_expr_str[2]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "c3", "set component #3 expression", OFFSET(comp_expr_str[3]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "y",  "set Y expression",OFFSET(comp_expr_str[Y]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "u",  "set U expression",OFFSET(comp_expr_str[U]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "v",  "set V expression",OFFSET(comp_expr_str[V]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "r",  "set R expression",OFFSET(comp_expr_str[R]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "g",  "set G expression",OFFSET(comp_expr_str[G]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "b",  "set B expression",OFFSET(comp_expr_str[B]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
-{ "a",  "set A expression",OFFSET(comp_expr_str[A]),  
AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
+{ "c0", "set component #0 expression", OFFSET(comp_expr_str[0]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "c1", "set component #1 expression", OFFSET(comp_expr_str[1]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "c2", "set component #2 expression", OFFSET(comp_expr_str[2]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "c3", "set component #3 expression", OFFSET(comp_expr_str[3]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "y",  "set Y expression",OFFSET(comp_expr_str[Y]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "u",  "set U expression",OFFSET(comp_expr_str[U]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "v",  "set V expression",OFFSET(comp_expr_str[V]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "r",  "set R expression",OFFSET(comp_expr_str[R]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "g",  "set G expression",OFFSET(comp_expr_str[G]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "b",  "set B expression",OFFSET(comp_expr_str[B]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
+{ "a",  "set A expression",OFFSET(comp_expr_str[A]),  
AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
 { NULL }
 };
 
@@ -265,7 +265,7 @@ static int config_props(AVFilterLink *inlink)
 max[Y] = 235 * (1 << (desc->comp[0].depth - 8));
 max[U] = 240 * (1 << (desc->comp[1].depth - 8));
 max[V] = 240 * (1 << (desc->comp[2].depth - 8));
-max[A] = (1 << desc->comp[3].depth) - 1;
+max[A] = (1 << desc->comp[0].depth) - 1;
 break;
 case AV_PIX_FMT_RGB48LE:
 case AV_PIX_FMT_RGBA64LE:
@@ -324,7 +324,7 @@ static int config_props(AVFilterLink *inlink)
s->comp_expr_str[color], val, comp);
 return AVERROR(EINVAL);
 }
-s->lut[comp][val] = av_clip((int)res, min[color], max[color]);
+s->lut[comp][val] = av_clip((int)res, 0, max[A]);
 av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, 
s->lut[comp][val]);
 }
 }
diff --git a/tests/ref/fate/filter-pixfmts-lut 
b/tests/ref/fate/filter-pixfmts-lut
index 7a43994..876568e 100644
--- a/tests/ref/fate/filter-pixfmts-lut
+++ b/tests/ref/fate/filter-pixfmts-lut
@@ -15,35 +15,35 @@ rgb24   a356171207723a580e7d277078072005
 rgb48le 5c7dd8575836d18c91e09f1915cf9aa9
 rgba7bc

[FFmpeg-cvslog] doc/protocols: add option usage description

2017-02-13 Thread Lou Logan
ffmpeg | branch: master | Lou Logan  | Mon Feb 13 12:23:03 2017 
-0900| [fb32c561c3820f3bc8833d0c3629388539fe4798] | committer: Lou Logan

doc/protocols: add option usage description

Fixes ticket #6148.

Signed-off-by: Lou Logan 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fb32c561c3820f3bc8833d0c3629388539fe4798
---

 doc/protocols.texi | 5 +
 1 file changed, 5 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index e887b75..a7968ff 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -5,6 +5,11 @@ The libavformat library provides some generic global options, 
which
 can be set on all the protocols. In addition each protocol may support
 so-called private options, which are specific for that component.
 
+Options may be set by specifying -@var{option} @var{value} in the
+FFmpeg tools, or by setting the value explicitly in the
+@code{AVFormatContext} options or using the @file{libavutil/opt.h} API
+for programmatic use.
+
 The list of supported options follows:
 
 @table @option

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


[FFmpeg-cvslog] aac_latm: Allow unaligned AudioSpecificConfig

2017-02-13 Thread Alex Converse
ffmpeg | branch: master | Alex Converse  | Thu Feb  9 
08:22:20 2017 -0800| [3f1a38c9194d0d1e47469504000997b7bfbcf3b0] | committer: 
Alex Converse

aac_latm: Allow unaligned AudioSpecificConfig

Fixes ticket 4730

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3f1a38c9194d0d1e47469504000997b7bfbcf3b0
---

 libavcodec/aacdec.c  | 26 --
 libavcodec/aacdec_template.c | 82 
 libavcodec/mpeg4audio.c  | 76 ++--
 libavcodec/mpeg4audio.h  | 12 ++-
 4 files changed, 120 insertions(+), 76 deletions(-)

diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index ee9b4eb..709ac7c 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -284,9 +284,10 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
 AACContext *ac= &latmctx->aac_ctx;
 AVCodecContext *avctx = ac->avctx;
 MPEG4AudioConfig m4ac = { 0 };
+GetBitContext gbc;
 int config_start_bit  = get_bits_count(gb);
 int sync_extension= 0;
-int bits_consumed, esize;
+int bits_consumed, esize, i;
 
 if (asclen) {
 sync_extension = 1;
@@ -294,19 +295,19 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
 } else
 asclen = get_bits_left(gb);
 
-if (config_start_bit % 8) {
-avpriv_request_sample(latmctx->aac_ctx.avctx,
-  "Non-byte-aligned audio-specific config");
-return AVERROR_PATCHWELCOME;
-}
 if (asclen <= 0)
 return AVERROR_INVALIDDATA;
-bits_consumed = decode_audio_specific_config(NULL, avctx, &m4ac,
- gb->buffer + (config_start_bit / 8),
- asclen, sync_extension);
 
-if (bits_consumed < 0)
+init_get_bits(&gbc, gb->buffer, config_start_bit + asclen);
+skip_bits_long(&gbc, config_start_bit);
+
+bits_consumed = decode_audio_specific_config_gb(NULL, avctx, &m4ac,
+&gbc, config_start_bit,
+sync_extension);
+
+if (bits_consumed < config_start_bit)
 return AVERROR_INVALIDDATA;
+bits_consumed -= config_start_bit;
 
 if (!latmctx->initialized ||
 ac->oc[1].m4ac.sample_rate != m4ac.sample_rate ||
@@ -329,7 +330,10 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
 }
 
 avctx->extradata_size = esize;
-memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize);
+gbc = *gb;
+for (i = 0; i < esize; i++) {
+  avctx->extradata[i] = get_bits(&gbc, 8);
+}
 memset(avctx->extradata+esize, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 }
 skip_bits_long(gb, bits_consumed);
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 83e9fb5..e230c87 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -715,6 +715,13 @@ static void decode_channel_map(uint8_t layout_map[][3],
 }
 }
 
+static inline void relative_align_get_bits(GetBitContext *gb,
+   int reference_position) {
+int n = (reference_position - get_bits_count(gb) & 7);
+if (n)
+skip_bits(gb, n);
+}
+
 /**
  * Decode program configuration element; reference: table 4.2.
  *
@@ -722,7 +729,7 @@ static void decode_channel_map(uint8_t layout_map[][3],
  */
 static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
   uint8_t (*layout_map)[3],
-  GetBitContext *gb)
+  GetBitContext *gb, int byte_align_ref)
 {
 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
 int sampling_index;
@@ -770,7 +777,7 @@ static int decode_pce(AVCodecContext *avctx, 
MPEG4AudioConfig *m4ac,
 decode_channel_map(layout_map + tags, AAC_CHANNEL_CC,gb, num_cc);
 tags += num_cc;
 
-align_get_bits(gb);
+relative_align_get_bits(gb, byte_align_ref);
 
 /* comment field, first byte is length */
 comment_len = get_bits(gb, 8) * 8;
@@ -792,6 +799,7 @@ static int decode_pce(AVCodecContext *avctx, 
MPEG4AudioConfig *m4ac,
  */
 static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
  GetBitContext *gb,
+ int get_bit_alignment,
  MPEG4AudioConfig *m4ac,
  int channel_config)
 {
@@ -815,7 +823,7 @@ static int decode_ga_specific_config(AACContext *ac, 
AVCodecContext *avctx,
 
 if (channel_config == 0) {
 skip_bits(gb, 4);  // element_instance_tag
-tags = decode_pce(avctx, m4ac, layout_map, gb);
+tags = decode_pce(avctx, m4ac, layout_map, gb, get_bit_alignment);
 if (tags < 0)
 return tags;
 }

[FFmpeg-cvslog] aac_latm: Copy whole AudioSpecificConfig when it is sized.

2017-02-13 Thread Alex Converse
ffmpeg | branch: master | Alex Converse  | Thu Feb  9 
08:57:33 2017 -0800| [20ea8bf9390b3a68e43bbe666154aa8b5150cad3] | committer: 
Alex Converse

aac_latm: Copy whole AudioSpecificConfig when it is sized.

This preserves sync extensions.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=20ea8bf9390b3a68e43bbe666154aa8b5150cad3
---

 libavcodec/aacdec.c | 27 +++
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 709ac7c..08d92fe 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -289,17 +289,19 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
 int sync_extension= 0;
 int bits_consumed, esize, i;
 
-if (asclen) {
+if (asclen > 0) {
 sync_extension = 1;
 asclen = FFMIN(asclen, get_bits_left(gb));
-} else
-asclen = get_bits_left(gb);
-
-if (asclen <= 0)
+init_get_bits(&gbc, gb->buffer, config_start_bit + asclen);
+skip_bits_long(&gbc, config_start_bit);
+} else if (asclen == 0) {
+gbc = *gb;
+} else {
 return AVERROR_INVALIDDATA;
+}
 
-init_get_bits(&gbc, gb->buffer, config_start_bit + asclen);
-skip_bits_long(&gbc, config_start_bit);
+if (get_bits_left(gb) <= 0)
+return AVERROR_INVALIDDATA;
 
 bits_consumed = decode_audio_specific_config_gb(NULL, avctx, &m4ac,
 &gbc, config_start_bit,
@@ -309,6 +311,9 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
 return AVERROR_INVALIDDATA;
 bits_consumed -= config_start_bit;
 
+if (asclen == 0)
+  asclen = bits_consumed;
+
 if (!latmctx->initialized ||
 ac->oc[1].m4ac.sample_rate != m4ac.sample_rate ||
 ac->oc[1].m4ac.chan_config != m4ac.chan_config) {
@@ -320,7 +325,7 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
 }
 latmctx->initialized = 0;
 
-esize = (bits_consumed+7) / 8;
+esize = (asclen + 7) / 8;
 
 if (avctx->extradata_size < esize) {
 av_free(avctx->extradata);
@@ -336,9 +341,9 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
 }
 memset(avctx->extradata+esize, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 }
-skip_bits_long(gb, bits_consumed);
+skip_bits_long(gb, asclen);
 
-return bits_consumed;
+return 0;
 }
 
 static int read_stream_mux_config(struct LATMContext *latmctx,
@@ -379,8 +384,6 @@ static int read_stream_mux_config(struct LATMContext 
*latmctx,
 int ascLen = latm_get_value(gb);
 if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) 
< 0)
 return ret;
-ascLen -= ret;
-skip_bits_long(gb, ascLen);
 }
 
 latmctx->frame_length_type = get_bits(gb, 3);

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


[FFmpeg-cvslog] aac_latm: Align inband PCE to the start of the payload

2017-02-13 Thread Alex Converse
ffmpeg | branch: master | Alex Converse  | Thu Feb  9 
08:58:47 2017 -0800| [1fce67d6403a4540181f6ed05abf5b3edd4ef014] | committer: 
Alex Converse

aac_latm: Align inband PCE to the start of the payload

A strict reading of the spec seems to imply that it should be aligned to
the start of the element instance tag, but that would break all of the
samples with PCEs.

It seems like a well formed LATM stream should have its PCE in the ASC
rather than inband.

Fixes ticket 4544

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1fce67d6403a4540181f6ed05abf5b3edd4ef014
---

 libavcodec/aacdec_template.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index d980ae0..fd6a0f1 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -2949,6 +2949,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, 
void *data,
 int err, elem_id;
 int samples = 0, multiplier, audio_found = 0, pce_found = 0;
 int is_dmono, sce_count = 0;
+int payload_alignment;
 
 ac->frame = data;
 
@@ -2971,6 +2972,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, 
void *data,
 // This may lead to an undefined profile being signaled
 ac->avctx->profile = ac->oc[1].m4ac.object_type - 1;
 
+payload_alignment = get_bits_count(gb);
 ac->tags_mapped = 0;
 // parse
 while ((elem_type = get_bits(gb, 3)) != TYPE_END) {
@@ -3025,7 +3027,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, 
void *data,
 uint8_t layout_map[MAX_ELEM_ID*4][3];
 int tags;
 push_output_configuration(ac);
-tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb, 0);
+tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb,
+  payload_alignment);
 if (tags < 0) {
 err = tags;
 break;

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


[FFmpeg-cvslog] aacsbr: Associate SBR data with AAC elements on init

2017-02-13 Thread Alex Converse
ffmpeg | branch: master | Alex Converse  | Thu Feb  9 
08:28:30 2017 -0800| [3bb24fc344f0e8448b3c6826193e8ee43f7d984d] | committer: 
Alex Converse

aacsbr: Associate SBR data with AAC elements on init

Quiets some log spam on pure upsampling mode.

Fixes ticket 5163.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3bb24fc344f0e8448b3c6826193e8ee43f7d984d
---

 libavcodec/aacdec_template.c | 2 +-
 libavcodec/aacsbr.h  | 2 +-
 libavcodec/aacsbr_template.c | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index e230c87..d980ae0 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -134,7 +134,7 @@ static av_cold int che_configure(AACContext *ac,
 if (!ac->che[type][id]) {
 if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement
 return AVERROR(ENOMEM);
-AAC_RENAME(ff_aac_sbr_ctx_init)(ac, &ac->che[type][id]->sbr);
+AAC_RENAME(ff_aac_sbr_ctx_init)(ac, &ac->che[type][id]->sbr, type);
 }
 if (type != TYPE_CCE) {
 if (*channels >= MAX_CHANNELS - (type == TYPE_CPE || (type == 
TYPE_SCE && ac->oc[1].m4ac.ps == 1))) {
diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h
index 88c4d8a..dd8b66c 100644
--- a/libavcodec/aacsbr.h
+++ b/libavcodec/aacsbr.h
@@ -81,7 +81,7 @@ static const int8_t vlc_sbr_lav[10] =
 /** Initialize SBR. */
 void AAC_RENAME(ff_aac_sbr_init)(void);
 /** Initialize one SBR context. */
-void AAC_RENAME(ff_aac_sbr_ctx_init)(AACContext *ac, SpectralBandReplication 
*sbr);
+void AAC_RENAME(ff_aac_sbr_ctx_init)(AACContext *ac, SpectralBandReplication 
*sbr, int id_aac);
 /** Close one SBR context. */
 void AAC_RENAME(ff_aac_sbr_ctx_close)(SpectralBandReplication *sbr);
 /** Decode one SBR element. */
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index 5110542..f8aa485 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -81,11 +81,12 @@ static void sbr_turnoff(SpectralBandReplication *sbr) {
 memset(&sbr->spectrum_params, -1, sizeof(SpectrumParameters));
 }
 
-av_cold void AAC_RENAME(ff_aac_sbr_ctx_init)(AACContext *ac, 
SpectralBandReplication *sbr)
+av_cold void AAC_RENAME(ff_aac_sbr_ctx_init)(AACContext *ac, 
SpectralBandReplication *sbr, int id_aac)
 {
 if(sbr->mdct.mdct_bits)
 return;
 sbr->kx[0] = sbr->kx[1];
+sbr->id_aac = id_aac;
 sbr_turnoff(sbr);
 sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE 
- (1280 - 128);
 sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE 
- (1280 - 128);

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


[FFmpeg-cvslog] avcodec/nvenc: set frame buffer format for mapped frames

2017-02-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Fri Feb 
10 15:00:21 2017 +0100| [8a3fea14ae94f715fc508098aa7d8ad89ee80054] | committer: 
Timo Rothenpieler

avcodec/nvenc: set frame buffer format for mapped frames

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8a3fea14ae94f715fc508098aa7d8ad89ee80054
---

 libavcodec/nvenc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 7005465..51e794e 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1421,6 +1421,7 @@ static int nvenc_upload_frame(AVCodecContext *avctx, 
const AVFrame *frame,
 ctx->registered_frames[reg_idx].mapped = 1;
 nvenc_frame->reg_idx   = reg_idx;
 nvenc_frame->input_surface = 
nvenc_frame->in_map.mappedResource;
+nvenc_frame->format= 
nvenc_frame->in_map.mappedBufferFmt;
 nvenc_frame->pitch = frame->linesize[0];
 return 0;
 } else {

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