Re: [FFmpeg-devel] [PATCH 1/1] libavdevice/decklink: configurablity to set max queue size

2017-08-21 Thread Patagar, Ravindra
Hi Matthias,
 
Thanks for that question. Yes, it is our company’s policy to add that 
copyright. It says, “All work submitted is copyright Akamai Technologies, Inc. 
released under the project’s license”. Since it is in the policy, I can’t add 
my name either.
But I would like to inform that we are planning to submit many more patches to 
this plugin, for support for Closed captions(CEA608), Digital program insertion 
(SCTE 104) etc., so that the overall changes will be much higher than this 
little patch.
Also I would like to inform that, as long as this project is active within our 
company, myself and colleagues in my team will actively support any inadvertent 
issues arising out of our patches.
 
Regards,
Ravindra

On 8/18/17, 4:38 PM, "Matthias Hunstock"  wrote:

Am 14.08.2017 um 06:55 schrieb Patagar, Ravindra:
> + * Copyright (c) 2017 Akamai Technologies, Inc.

Isn't this kind of exaggerated for this little patch? Or is it company
policy to do it?

Beside that I'd prefer the person over the employer or at least both.

Matthias
___
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 02/18] h264: Add stream constraint values to the common header

2017-08-21 Thread Mark Thompson
On 21/08/17 02:09, Michael Niedermayer wrote:
> On Sun, Aug 20, 2017 at 11:41:30PM +0100, Mark Thompson wrote:
>> With comments describing the derivation of each value.
>>
>> (cherry picked from commit aaf441465080b9bc57f5ca8dea656f9b2c5dc821)
>> ---
>>  libavcodec/h264.h | 45 +
>>  1 file changed, 45 insertions(+)
>>
>> diff --git a/libavcodec/h264.h b/libavcodec/h264.h
>> index 86df5eb9b3..650580bf3a 100644
>> --- a/libavcodec/h264.h
>> +++ b/libavcodec/h264.h
>> @@ -44,4 +44,49 @@ enum {
>>  H264_NAL_AUXILIARY_SLICE = 19,
>>  };
>>  
>> +
>> +enum {
> 
> why is this a enum ?

I believe that compile-time symbolic constants are preferable to preprocessor 
string replacement.

>> +// 7.4.2.1.1: seq_parameter_set_id is in [0, 31].
>> +H264_MAX_SPS_COUNT = 32,
> 
> Could be doxygen comment compatible

Would that have any value?  The comments are explaining the derivation for 
verification purposes rather than anything to do with the actual use.

>> +// A.3: in table A-1 the highest level allows a MaxFS of 139264.
>> +H264_MAX_MB_PIC_SIZE = 139264,
>> +// A.3.1, A.3.2: PicWidthInMbs and PicHeightInMbs are constrained
>> +// to be not greater than sqrt(MaxFS * 8).  Hence height/width are
>> +// bounded above by sqrt(139264 * 8) = 1055.5 macroblocks.
>> +H264_MAX_MB_WIDTH= 1055,
>> +H264_MAX_MB_HEIGHT   = 1055,
>> +H264_MAX_WIDTH   = H264_MAX_MB_WIDTH  * 16,
>> +H264_MAX_HEIGHT  = H264_MAX_MB_HEIGHT * 16,
> 
> There should be no problem with files outside these limits. They would
> be valid H.264 files, just not within the level and profile constraints
> of the currently defined profiles and levels.
> or do i miss something ?
Currently these values are used for some fixed-size tables in cbs (e.g. 
H264_MAX_MB_PIC_SIZE is needed for slice_group_id[]).  More generally, I don't 
want to consider files which don't conform to some level limits - once you 
allow MaxDPBFrames to exceed 16 the world is a terrible place.

(I am not intending to add this constraint to the existing decoder.)

Thanks,

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


Re: [FFmpeg-devel] [PATCH]lavc/g726: Add a little-endian G.726 encoder

2017-08-21 Thread Carl Eugen Hoyos
2017-08-18 21:00 GMT+02:00 Carl Eugen Hoyos :
> Hi!
>
> Attached patch allows to encode samples that the binary decoder
> attached to ticket #6596 can decode, they have the same format as the
> ITU reference samples ("right-justified").

Patch applied, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH]lavc/put_bits: Remove usage of BITSTREAM_WRITER_LE.

2017-08-21 Thread Carl Eugen Hoyos
Hi!

Attached patch tries to slightly simplify and clean up the usage of
put_bits* in libavcodec: put_bits_le() functions exist for the
little-endian G.726 encoder, so the define makes less sense now.

Fate passes here, please review, Carl Eugen
From 6bad007ad31c8466bcddd093c1d46cb69f75681f Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Mon, 21 Aug 2017 17:10:35 +0200
Subject: [PATCH] lavc/put_bits: Remove usage of BITSTREAM_WRITER_LE.

Specific functions for little endian put_bits exist for the
little-endian G.726 encoder.
---
 libavcodec/g723_1enc.c  |   47 ++---
 libavcodec/gif.c|5 +-
 libavcodec/put_bits.h   |   80 -
 libavcodec/ttaenc.c |   15 ++--
 libavcodec/vorbisenc.c  |  179 +++
 libavcodec/wavpackenc.c |   56 +++
 6 files changed, 178 insertions(+), 204 deletions(-)

diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c
index 4a4525e..0d2c1fb 100644
--- a/libavcodec/g723_1enc.c
+++ b/libavcodec/g723_1enc.c
@@ -37,7 +37,6 @@
 #include "g723_1.h"
 #include "internal.h"
 
-#define BITSTREAM_WRITER_LE
 #include "put_bits.h"
 
 static av_cold int g723_1_encode_init(AVCodecContext *avctx)
@@ -1003,16 +1002,16 @@ static int pack_bitstream(G723_1_Context *p, AVPacket *avpkt)
 
 init_put_bits(&pb, avpkt->data, avpkt->size);
 
-put_bits(&pb, 2, info_bits);
+put_bits_le(&pb, 2, info_bits);
 
-put_bits(&pb, 8, p->lsp_index[2]);
-put_bits(&pb, 8, p->lsp_index[1]);
-put_bits(&pb, 8, p->lsp_index[0]);
+put_bits_le(&pb, 8, p->lsp_index[2]);
+put_bits_le(&pb, 8, p->lsp_index[1]);
+put_bits_le(&pb, 8, p->lsp_index[0]);
 
-put_bits(&pb, 7, p->pitch_lag[0] - PITCH_MIN);
-put_bits(&pb, 2, p->subframe[1].ad_cb_lag);
-put_bits(&pb, 7, p->pitch_lag[1] - PITCH_MIN);
-put_bits(&pb, 2, p->subframe[3].ad_cb_lag);
+put_bits_le(&pb, 7, p->pitch_lag[0] - PITCH_MIN);
+put_bits_le(&pb, 2, p->subframe[1].ad_cb_lag);
+put_bits_le(&pb, 7, p->pitch_lag[1] - PITCH_MIN);
+put_bits_le(&pb, 2, p->subframe[3].ad_cb_lag);
 
 /* Write 12 bit combined gain */
 for (i = 0; i < SUBFRAMES; i++) {
@@ -1020,13 +1019,13 @@ static int pack_bitstream(G723_1_Context *p, AVPacket *avpkt)
p->subframe[i].amp_index;
 if (p->cur_rate == RATE_6300)
 temp += p->subframe[i].dirac_train << 11;
-put_bits(&pb, 12, temp);
+put_bits_le(&pb, 12, temp);
 }
 
-put_bits(&pb, 1, p->subframe[0].grid_index);
-put_bits(&pb, 1, p->subframe[1].grid_index);
-put_bits(&pb, 1, p->subframe[2].grid_index);
-put_bits(&pb, 1, p->subframe[3].grid_index);
+put_bits_le(&pb, 1, p->subframe[0].grid_index);
+put_bits_le(&pb, 1, p->subframe[1].grid_index);
+put_bits_le(&pb, 1, p->subframe[2].grid_index);
+put_bits_le(&pb, 1, p->subframe[3].grid_index);
 
 if (p->cur_rate == RATE_6300) {
 skip_put_bits(&pb, 1); /* reserved bit */
@@ -1036,20 +1035,20 @@ static int pack_bitstream(G723_1_Context *p, AVPacket *avpkt)
(p->subframe[1].pulse_pos >> 14) *  90 +
(p->subframe[2].pulse_pos >> 16) *   9 +
(p->subframe[3].pulse_pos >> 14);
-put_bits(&pb, 13, temp);
+put_bits_le(&pb, 13, temp);
 
-put_bits(&pb, 16, p->subframe[0].pulse_pos & 0x);
-put_bits(&pb, 14, p->subframe[1].pulse_pos & 0x3fff);
-put_bits(&pb, 16, p->subframe[2].pulse_pos & 0x);
-put_bits(&pb, 14, p->subframe[3].pulse_pos & 0x3fff);
+put_bits_le(&pb, 16, p->subframe[0].pulse_pos & 0x);
+put_bits_le(&pb, 14, p->subframe[1].pulse_pos & 0x3fff);
+put_bits_le(&pb, 16, p->subframe[2].pulse_pos & 0x);
+put_bits_le(&pb, 14, p->subframe[3].pulse_pos & 0x3fff);
 
-put_bits(&pb, 6, p->subframe[0].pulse_sign);
-put_bits(&pb, 5, p->subframe[1].pulse_sign);
-put_bits(&pb, 6, p->subframe[2].pulse_sign);
-put_bits(&pb, 5, p->subframe[3].pulse_sign);
+put_bits_le(&pb, 6, p->subframe[0].pulse_sign);
+put_bits_le(&pb, 5, p->subframe[1].pulse_sign);
+put_bits_le(&pb, 6, p->subframe[2].pulse_sign);
+put_bits_le(&pb, 5, p->subframe[3].pulse_sign);
 }
 
-flush_put_bits(&pb);
+flush_put_bits_le(&pb);
 return frame_size[info_bits];
 }
 
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index d9c99d5..2cb1f73 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -28,7 +28,6 @@
  * @see http://www.w3.org/Graphics/GIF/spec-gif89a.txt
  */
 
-#define BITSTREAM_WRITER_LE
 #include "libavutil/opt.h"
 #include "libavutil/imgutils.h"
 #include "avcodec.h"
@@ -176,7 +175,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
 bytestream_put_byte(bytestream, 0x08);
 
 ff_lzw_encode_init(s->lzw, s->buf, s->buf_size,
-   12, FF_LZW_GIF, put_bits);
+   12, FF_LZW_GIF, put_bits_le);
 
 ptr = buf + y_s

Re: [FFmpeg-devel] [PATCH]lavf/g726: Add a raw little-endian G.726 demuxer

2017-08-21 Thread Carl Eugen Hoyos
2017-08-18 19:25 GMT+02:00 Carl Eugen Hoyos :
> Hi!
>
> Attached patch allows to read files produced by the "ITU compatible
> binary G726 encoder" attached to ticket #6596.

New patch attached that also allows reading an old sample found on
ubuntuusers.de containing big-endian G.726 from "SEG Mp3-Player".

Searching the FFmpeg user mailing list shows several requests for
this demuxer(s) over the last decade.

Please comment, Carl Eugen
From ac3a91bb750ab719286fd2d3cf3607558d034310 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Mon, 21 Aug 2017 16:17:17 +0200
Subject: [PATCH] lavf/g726: Demuxer for raw G.726 streams, both left- and
 right-justified.

Compatible with the binary encoder attached to ticket #6596 (right-aligned)
and a sample from a SEG Mp3-Player (left-aligned).
---
 Changelog|1 +
 doc/general.texi |1 +
 libavformat/Makefile |2 +
 libavformat/allformats.c |2 +
 libavformat/g726.c   |  105 ++
 libavformat/version.h|2 +-
 6 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/g726.c

diff --git a/Changelog b/Changelog
index 7a6987a..f5dc1da 100644
--- a/Changelog
+++ b/Changelog
@@ -33,6 +33,7 @@ version :
 - tlut2 video filter
 - floodfill video filter
 - pseudocolor video filter
+- raw G.726 demuxer, left- and right-justified
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/general.texi b/doc/general.texi
index 036c8c2..49eb969 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -341,6 +341,7 @@ library:
 @item FunCom ISS@tab   @tab X
 @tab Audio format used in various games from FunCom like The Longest Journey.
 @item G.723.1   @tab X @tab X
+@item G.726 @tab   @tab X
 @item G.729 BIT @tab X @tab X
 @item G.729 raw @tab   @tab X
 @item GENH  @tab   @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index b0ef82c..8e2afb7 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -188,6 +188,8 @@ OBJS-$(CONFIG_GSM_MUXER) += rawenc.o
 OBJS-$(CONFIG_GXF_DEMUXER)   += gxf.o
 OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o
 OBJS-$(CONFIG_G722_DEMUXER)  += g722.o rawdec.o
+OBJS-$(CONFIG_G726_DEMUXER)  += g726.o
+OBJS-$(CONFIG_G726LE_DEMUXER)+= g726.o
 OBJS-$(CONFIG_G722_MUXER)+= rawenc.o
 OBJS-$(CONFIG_G723_1_DEMUXER)+= g723_1.o
 OBJS-$(CONFIG_G723_1_MUXER)  += rawenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1ebc142..78ff2eb 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -132,6 +132,8 @@ static void register_all(void)
 REGISTER_DEMUXER (FRM,  frm);
 REGISTER_DEMUXER (FSB,  fsb);
 REGISTER_MUXDEMUX(G722, g722);
+REGISTER_DEMUXER (G726, g726);
+REGISTER_DEMUXER (G726LE,   g726le);
 REGISTER_MUXDEMUX(G723_1,   g723_1);
 REGISTER_DEMUXER (G729, g729);
 REGISTER_DEMUXER (GDV,  gdv);
diff --git a/libavformat/g726.c b/libavformat/g726.c
new file mode 100644
index 000..eca9404
--- /dev/null
+++ b/libavformat/g726.c
@@ -0,0 +1,105 @@
+/*
+ * G.726 raw demuxer
+ * Copyright 2017 Carl Eugen Hoyos
+ *
+ * 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 "avformat.h"
+#include "internal.h"
+#include "libavutil/opt.h"
+
+typedef struct G726Context {
+AVClass *class;
+int code_size;
+int sample_rate;
+} G726Context;
+
+static int g726_read_header(AVFormatContext *s)
+{
+G726Context *c = s->priv_data;
+AVStream *st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+
+st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+st->codecpar->codec_id   = s->iformat->raw_codec_id;
+
+st->codecpar->sample_rate   = c->sample_rate;
+st->codecpar->bits_per_coded_sample = c->code_size;
+st->codecpar->bit_rate  = ((int[]){ 16000, 24000, 32000, 4 })[c->code_size - 2];
+st->codecpar->channels  = 1;
+
+return 0;
+}
+

Re: [FFmpeg-devel] [PATCH 02/18] h264: Add stream constraint values to the common header

2017-08-21 Thread Michael Niedermayer
On Mon, Aug 21, 2017 at 11:56:11AM +0100, Mark Thompson wrote:
> On 21/08/17 02:09, Michael Niedermayer wrote:
> > On Sun, Aug 20, 2017 at 11:41:30PM +0100, Mark Thompson wrote:
> >> With comments describing the derivation of each value.
> >>
> >> (cherry picked from commit aaf441465080b9bc57f5ca8dea656f9b2c5dc821)
> >> ---
> >>  libavcodec/h264.h | 45 +
> >>  1 file changed, 45 insertions(+)
> >>
> >> diff --git a/libavcodec/h264.h b/libavcodec/h264.h
> >> index 86df5eb9b3..650580bf3a 100644
> >> --- a/libavcodec/h264.h
> >> +++ b/libavcodec/h264.h
> >> @@ -44,4 +44,49 @@ enum {
> >>  H264_NAL_AUXILIARY_SLICE = 19,
> >>  };
> >>  
> >> +
> >> +enum {
> > 
> > why is this a enum ?
> 
> I believe that compile-time symbolic constants are preferable to preprocessor 
> string replacement.

I dont mind, but there are many more #defines in the codebase for
which this argument should apply too.


> 
> >> +// 7.4.2.1.1: seq_parameter_set_id is in [0, 31].
> >> +H264_MAX_SPS_COUNT = 32,
> > 
> > Could be doxygen comment compatible
> 
> Would that have any value?  The comments are explaining the derivation for 
> verification purposes rather than anything to do with the actual use.

It would put the value into the doxygen on the webpage. Would make
the comment easy machine associatable to the constant.

Not sure thats enough "value", I just noticed that you seem to have
quite exhaustivly documented these constants, it appeared odd that
if you go to the troubble to do that that they arent doxygen parsable.


> 
> >> +// A.3: in table A-1 the highest level allows a MaxFS of 139264.
> >> +H264_MAX_MB_PIC_SIZE = 139264,
> >> +// A.3.1, A.3.2: PicWidthInMbs and PicHeightInMbs are constrained
> >> +// to be not greater than sqrt(MaxFS * 8).  Hence height/width are
> >> +// bounded above by sqrt(139264 * 8) = 1055.5 macroblocks.
> >> +H264_MAX_MB_WIDTH= 1055,
> >> +H264_MAX_MB_HEIGHT   = 1055,
> >> +H264_MAX_WIDTH   = H264_MAX_MB_WIDTH  * 16,
> >> +H264_MAX_HEIGHT  = H264_MAX_MB_HEIGHT * 16,
> > 
> > There should be no problem with files outside these limits. They would
> > be valid H.264 files, just not within the level and profile constraints
> > of the currently defined profiles and levels.
> > or do i miss something ?
> Currently these values are used for some fixed-size tables in cbs (e.g. 
> H264_MAX_MB_PIC_SIZE is needed for slice_group_id[]).  More generally, I 
> don't want to consider files which don't conform to some level limits - once 
> you allow MaxDPBFrames to exceed 16 the world is a terrible place.
> 

> (I am not intending to add this constraint to the existing decoder.)

but some of the newly added code uses the resolution limits IIRC.

We never previosuly limited resolution based on profile/level.
Can you summarize what features would be restricted to 1055 MBs
resolution ?

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] all: avoid data imports across DLL boundaries

2017-08-21 Thread wm4
From: Pedro Pombeiro 

DLL data imports cause problems on Windows. They normally require
each variable to be correctly marked with dllimport/dllexport
declspecs. For MSVC, we define av_export to dllimport declspec. This
is not entirely correct - depending on which sub-lib is built, they
should be marked to dllexport instead. It happens to work with MSVC,
because it supports exports incorrectly marked as imports. Trying to
use this breaks on MinGW and results in linker errors.

On MinGW, not using any import/export specifiers happens to work,
because binutils and the MinGW runtime provide "pseudo relocations",
which manually fix these imports at load time. This does not work with
MinGW WinRT builds: the relocations cannot be performed because this
would require writing to the code section, which is not allowed.

Get rid of all these issues by not using data exports/imports. The
public API is already free of them, but avpriv_ symbols make extensive
use of them. Replace them all with getters.

Signed-off-by: wm4 
---
 libavcodec/aacadtsdec.c|  4 +--
 libavcodec/aacenc.c|  4 +--
 libavcodec/ac3_parser.c|  2 +-
 libavcodec/ac3dec.c|  2 +-
 libavcodec/ac3tab.c|  7 -
 libavcodec/ac3tab.h|  2 +-
 libavcodec/ansi.c  | 12 -
 libavcodec/bintext.c   |  4 +--
 libavcodec/dca.c   |  9 +--
 libavcodec/dca.h   |  2 +-
 libavcodec/dca_core.c  |  2 +-
 libavcodec/dca_parser.c|  2 +-
 libavcodec/g2meet.c| 16 +--
 libavcodec/jpegtables.c| 49 +-
 libavcodec/jpegtables.h| 14 +-
 libavcodec/ljpegenc.c  |  8 +++---
 libavcodec/mjpeg2jpeg_bsf.c| 12 -
 libavcodec/mjpegdec.c  | 24 -
 libavcodec/mjpegenc.c  | 16 +--
 libavcodec/mjpegenc_common.c   | 18 ++---
 libavcodec/mp3_header_decompress_bsf.c |  4 +--
 libavcodec/mpeg4audio.c| 14 --
 libavcodec/mpeg4audio.h|  4 ++-
 libavcodec/mpegaudiodata.c | 19 +++--
 libavcodec/mpegaudiodata.h |  6 +++--
 libavcodec/mpegaudiodecheader.c|  6 ++---
 libavcodec/mpegaudioenc_template.c | 10 +++
 libavcodec/raw.c   | 10 +++
 libavcodec/raw.h   |  4 +--
 libavcodec/rawdec.c|  6 ++---
 libavcodec/tmv.c   |  2 +-
 libavcodec/vaapi_encode_mjpeg.c| 16 +--
 libavfilter/avf_showcqt.c  |  3 ++-
 libavfilter/avf_showspectrum.c |  2 +-
 libavfilter/avf_showvolume.c   |  2 +-
 libavfilter/f_ebur128.c|  4 +--
 libavfilter/vf_datascope.c |  2 +-
 libavfilter/vf_vectorscope.c   |  4 +--
 libavfilter/vf_waveform.c  |  8 +++---
 libavfilter/vsrc_testsrc.c |  2 +-
 libavformat/avienc.c   |  2 +-
 libavformat/isom.c |  4 +--
 libavformat/matroskadec.c  |  4 +--
 libavformat/mov.c  |  4 +--
 libavformat/movenc.c   |  2 +-
 libavformat/mp3enc.c   |  8 +++---
 libavformat/nutenc.c   |  4 +--
 libavformat/rtpdec_jpeg.c  | 16 +--
 libavformat/rtpenc_jpeg.c  | 16 +--
 libavformat/sdp.c  |  4 +--
 libavformat/spdifenc.c |  2 +-
 libavutil/internal.h   |  6 -
 libavutil/xga_font_data.c  | 14 --
 libavutil/xga_font_data.h  |  4 +--
 54 files changed, 258 insertions(+), 169 deletions(-)

diff --git a/libavcodec/aacadtsdec.c b/libavcodec/aacadtsdec.c
index d0814ac27e..9a6b5d8784 100644
--- a/libavcodec/aacadtsdec.c
+++ b/libavcodec/aacadtsdec.c
@@ -39,7 +39,7 @@ int avpriv_aac_parse_header(GetBitContext *gbc, 
AACADTSHeaderInfo *hdr)
 crc_abs = get_bits1(gbc);/* protection_absent */
 aot = get_bits(gbc, 2);  /* profile_objecttype */
 sr  = get_bits(gbc, 4);  /* sample_frequency_index */
-if (!avpriv_mpeg4audio_sample_rates[sr])
+if (!avpriv_get_mpeg4audio_sample_rate(sr))
 return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
 skip_bits1(gbc); /* private_bit */
 ch = get_bits(gbc, 3);   /* channel_configuration */
@@ -62,7 +62,7 @@ int avpriv_aac_parse_header(GetBitContext *gbc, 
AACADTSHeaderInfo *hdr)
 hdr->crc_absent = crc_abs;
 hdr->num_aac_frames = rdb + 1;
 hdr->sampling_index = sr;
-hdr->sample_rate= avpriv_mpeg4audio_sample_rates[sr];
+hdr->sample_rate= avpriv_get_mpeg4audio_sample_rate(sr);
 hdr->samples= (rdb + 1) * 1024;
 hdr->bit_rate   = size * 8 * hdr->sample_rate /

Re: [FFmpeg-devel] [PATCH 13/18] lavc: Add mpeg2_metadata bitstream filter

2017-08-21 Thread Michael Niedermayer
On Sun, Aug 20, 2017 at 11:41:41PM +0100, Mark Thompson wrote:
> (cherry picked from commit b78c30d7ec26af67c00ce2002709a189f6a87a7e)
> ---
>  configure   |   1 +
>  doc/bitstream_filters.texi  |  36 
>  libavcodec/Makefile |   1 +
>  libavcodec/bitstream_filters.c  |   1 +
>  libavcodec/mpeg2_metadata_bsf.c | 360 
> 
>  5 files changed, 399 insertions(+)
>  create mode 100644 libavcodec/mpeg2_metadata_bsf.c
> 
> diff --git a/configure b/configure
> index 7641bd98d4..1e99038dca 100755
> --- a/configure
> +++ b/configure
> @@ -2836,6 +2836,7 @@ h264_metadata_bsf_select="cbs_h264"
>  h264_redundant_pps_bsf_select="cbs_h264"
>  hevc_metadata_bsf_select="cbs_h265"
>  mjpeg2jpeg_bsf_select="jpegtables"
> +mpeg2_metadata_bsf_select="cbs_mpeg2"
>  trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
>  
>  # external libraries
> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> index 71c307f2e2..8a8756bdcc 100644
> --- a/doc/bitstream_filters.texi
> +++ b/doc/bitstream_filters.texi
> @@ -324,6 +324,42 @@ See also the @ref{text2movsub} filter.
>  
>  Decompress non-standard compressed MP3 audio headers.
>  
> +@section mpeg2_metadata
> +
> +Modify metadata embedded in an MPEG-2 stream.
> +
> +@table @option
> +@item display_aspect_ratio
> +Set the display aspect ratio in the stream.
> +
> +The following fixed values are supported:
> +@table @option
> +@item 4/3
> +@item 16/9
> +@item 221/100
> +@end table
> +Any other value will result in square pixels being signalled instead
> +(see H.262 section 6.3.3 and table 6-3).
> +
> +@item frame_rate
> +Set the frame rate in the stream.  This is constructed from a table
> +of known values combined with a small multiplier and divisor - if
> +the supplied value is not exactly representable, the nearest
> +representable value will be used instead (see H.262 section 6.3.3
> +and table 6-4).
> +
> +@item video_format
> +Set the video format in the stream (see H.262 section 6.3.6 and
> +table 6-6).
> +
> +@item colour_primaries
> +@item transfer_characteristics
> +@item matrix_coefficients
> +Set the colour description in the stream (see H.262 section 6.3.6
> +and tables 6-7, 6-8 and 6-9).
> +
> +@end table
> +
>  @section mpeg4_unpack_bframes
>  
>  Unpack DivX-style packed B-frames.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 72f2bb2a12..3da7b9b508 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1002,6 +1002,7 @@ OBJS-$(CONFIG_MPEG4_UNPACK_BFRAMES_BSF)   += 
> mpeg4_unpack_bframes_bsf.o
>  OBJS-$(CONFIG_MOV2TEXTSUB_BSF)+= movsub_bsf.o
>  OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += mp3_header_decompress_bsf.o \
>   mpegaudiodata.o
> +OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
>  OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
>  OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
>  OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
> diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
> index 6e6b894e7f..7b0cb5032a 100644
> --- a/libavcodec/bitstream_filters.c
> +++ b/libavcodec/bitstream_filters.c
> @@ -38,6 +38,7 @@ extern const AVBitStreamFilter ff_imx_dump_header_bsf;
>  extern const AVBitStreamFilter ff_mjpeg2jpeg_bsf;
>  extern const AVBitStreamFilter ff_mjpega_dump_header_bsf;
>  extern const AVBitStreamFilter ff_mp3_header_decompress_bsf;
> +extern const AVBitStreamFilter ff_mpeg2_metadata_bsf;
>  extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
>  extern const AVBitStreamFilter ff_mov2textsub_bsf;
>  extern const AVBitStreamFilter ff_noise_bsf;
> diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
> new file mode 100644
> index 00..b4449eac71
> --- /dev/null
> +++ b/libavcodec/mpeg2_metadata_bsf.c
> @@ -0,0 +1,360 @@
> +/*
> + * 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/avstring.h"
> +#include "libavutil/common.h"
> +#include "libavutil/opt.h"
> +
> +#include "bsf.h"
> +#include "cbs.h"
> +#include "cbs_mpeg2.h"
> +
> +typedef struct MPEG2MetadataContext {
> +const AVC

Re: [FFmpeg-devel] [PATCH] avcodec/me_cmp: Fix crashes on ARM due to misalignment

2017-08-21 Thread Michael Niedermayer
On Sat, Aug 19, 2017 at 11:38:58PM +0200, Michael Niedermayer wrote:
> Adds a diff_pixels_unaligned()
> 
> Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=872503
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/me_cmp.c   | 10 +-
>  libavcodec/pixblockdsp.c  |  1 +
>  libavcodec/pixblockdsp.h  |  5 +
>  libavcodec/x86/pixblockdsp_init.c |  2 ++
>  4 files changed, 13 insertions(+), 5 deletions(-)

applied

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] libavdevice/decklink: configurablity to set max queue size

2017-08-21 Thread Matthias Hunstock
Am 21.08.2017 um 11:03 schrieb Patagar, Ravindra:
> But I would like to inform that we are planning to submit many more patches 
> to this plugin, for support for Closed captions(CEA608), Digital program 
> insertion (SCTE 104) etc., so that the overall changes will be much higher 
> than this little patch.


That sounds great! Thank you for the detailled answer.

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/aacdec_template: Fix running cleanup in decode_ics_info()

2017-08-21 Thread Alex Converse
On Sun, Aug 20, 2017 at 5:15 PM, Michael Niedermayer
 wrote:
>
> Fixes: out of array read
> Fixes: 2873/clusterfuzz-testcase-minimized-5924145713905664
>
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/aacdec_template.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
> index a539f74e6f..e7fa27e8db 100644
> --- a/libavcodec/aacdec_template.c
> +++ b/libavcodec/aacdec_template.c
> @@ -1332,7 +1332,7 @@ static int decode_ics_info(AACContext *ac, 
> IndividualChannelStream *ics,
>  ics->tns_max_bands =  ff_tns_max_bands_512[sampling_index];
>  }
>  if (!ics->num_swb || !ics->swb_offset)
> -return AVERROR_BUG;
> +goto fail;
>  } else {
>  ics->swb_offset=ff_swb_offset_1024[sampling_index];
>  ics->num_swb   =   ff_aac_num_swb_1024[sampling_index];

okay

> @@ -1356,7 +1356,7 @@ static int decode_ics_info(AACContext *ac, 
> IndividualChannelStream *ics,
>  if (aot == AOT_ER_AAC_LD) {
>  av_log(ac->avctx, AV_LOG_ERROR,
> "LTP in ER AAC LD not yet implemented.\n");
> -return AVERROR_PATCHWELCOME;
> +goto fail;
>  }
>  if ((ics->ltp.present = get_bits(gb, 1)))
>  decode_ltp(&ics->ltp, gb, ics->max_sfb);

I'm not sure if it matters to anyone, but this is a missing decoder
feature and returning AVERROR_INVALIDDATA is semantically wrong.

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


[FFmpeg-devel] [PATCH 2/2] fate: add test vector aac-al04sf_48

2017-08-21 Thread Alex Converse
---
 tests/fate/aac.mak | 4 
 1 file changed, 4 insertions(+)

diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak
index 5ef8ddc2b9..e8cbcef54d 100644
--- a/tests/fate/aac.mak
+++ b/tests/fate/aac.mak
@@ -2,6 +2,10 @@ FATE_AAC += fate-aac-al04_44
 fate-aac-al04_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al04_44.mp4
 fate-aac-al04_44: REF = $(SAMPLES)/aac/al04_44.s16
 
+FATE_AAC += fate-aac-al04sf_48
+fate-aac-al04sf_48: CMD = pcm -i $(TARGET_SAMPLES)/aac/al04sf_48.mp4
+fate-aac-al04sf_48: REF = $(SAMPLES)/aac/al04sf_48.s16
+
 FATE_AAC += fate-aac-al05_44
 fate-aac-al05_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al05_44.mp4
 fate-aac-al05_44: REF = $(SAMPLES)/aac/al05_44.s16
-- 
2.13.3

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


[FFmpeg-devel] [PATCH 1/2] avcodec/aac: Add floating point 960/120 MDCT window

2017-08-21 Thread Alex Converse
From: Paul B Mahol 

Co-Authored-By: Alex Converse 
---
 libavcodec/aac.h  |   3 +
 libavcodec/aacdec_template.c  | 124 +++---
 libavcodec/aactab.c   | 120 
 libavcodec/aactab.h   |   6 ++
 libavcodec/sinewin.h  |   4 +-
 libavcodec/sinewin_tablegen.h |   5 +-
 6 files changed, 253 insertions(+), 9 deletions(-)

diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index 97a2df6b86..4910c661d6 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -327,7 +327,9 @@ struct AACContext {
 #if USE_FIXED
 AVFixedDSPContext *fdsp;
 #else
+MDCT15Context *mdct120;
 MDCT15Context *mdct480;
+MDCT15Context *mdct960;
 AVFloatDSPContext *fdsp;
 #endif /* USE_FIXED */
 int random_state;
@@ -353,6 +355,7 @@ struct AACContext {
 
 OutputConfiguration oc[2];
 int warned_num_aac_frames;
+int warned_960_sbr;
 
 /* aacdec functions pointers */
 void (*imdct_and_windowing)(AACContext *ac, SingleChannelElement *sce);
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index a539f74e6f..e76e824fbb 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -811,11 +811,21 @@ static int decode_ga_specific_config(AACContext *ac, 
AVCodecContext *avctx,
 uint8_t layout_map[MAX_ELEM_ID*4][3];
 int tags = 0;
 
+#if USE_FIXED
 if (get_bits1(gb)) { // frameLengthFlag
-avpriv_request_sample(avctx, "960/120 MDCT window");
+avpriv_report_missing_feature(avctx, "Fixed point 960/120 MDCT 
window");
 return AVERROR_PATCHWELCOME;
 }
 m4ac->frame_length_short = 0;
+#else
+m4ac->frame_length_short = get_bits1(gb);
+if (m4ac->frame_length_short && m4ac->sbr == 1) {
+  avpriv_report_missing_feature(avctx, "SBR with 960 frame length");
+  if (ac) ac->warned_960_sbr = 1;
+  m4ac->sbr = 0;
+  m4ac->ps = 0;
+}
+#endif
 
 if (get_bits1(gb))   // dependsOnCoreCoder
 skip_bits(gb, 14);   // coreCoderDelay
@@ -1126,6 +1136,12 @@ static av_cold void aac_static_table_init(void)
 // window initialization
 AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_long_1024), 4.0, 
1024);
 AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_short_128), 6.0, 128);
+#if !USE_FIXED
+AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_long_960), 4.0, 960);
+AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_short_120), 6.0, 120);
+AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_960), 960);
+AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_120), 120);
+#endif
 AAC_RENAME(ff_init_ff_sine_windows)(10);
 AAC_RENAME(ff_init_ff_sine_windows)( 9);
 AAC_RENAME(ff_init_ff_sine_windows)( 7);
@@ -1211,9 +1227,15 @@ 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_mdct15_init(&ac->mdct120, 1, 3, 1.0f/(16*1024*120*2));
+if (ret < 0)
+return ret;
 ret = ff_mdct15_init(&ac->mdct480, 1, 5, 1.0f/(16*1024*960));
 if (ret < 0)
 return ret;
+ret = ff_mdct15_init(&ac->mdct960, 1, 6, 1.0f/(16*1024*960*2));
+if (ret < 0)
+return ret;
 #endif
 
 return 0;
@@ -1314,8 +1336,13 @@ static int decode_ics_info(AACContext *ac, 
IndividualChannelStream *ics,
 }
 }
 ics->num_windows   = 8;
-ics->swb_offset=ff_swb_offset_128[sampling_index];
-ics->num_swb   =   ff_aac_num_swb_128[sampling_index];
+if (m4ac->frame_length_short) {
+ics->swb_offset=  ff_swb_offset_120[sampling_index];
+ics->num_swb   = ff_aac_num_swb_120[sampling_index];
+} else {
+ics->swb_offset=  ff_swb_offset_128[sampling_index];
+ics->num_swb   = ff_aac_num_swb_128[sampling_index];
+}
 ics->tns_max_bands = ff_tns_max_bands_128[sampling_index];
 ics->predictor_present = 0;
 } else {
@@ -1334,8 +1361,13 @@ static int decode_ics_info(AACContext *ac, 
IndividualChannelStream *ics,
 if (!ics->num_swb || !ics->swb_offset)
 return AVERROR_BUG;
 } else {
-ics->swb_offset=ff_swb_offset_1024[sampling_index];
-ics->num_swb   =   ff_aac_num_swb_1024[sampling_index];
+if (m4ac->frame_length_short) {
+ics->num_swb= ff_aac_num_swb_960[sampling_index];
+ics->swb_offset = ff_swb_offset_960[sampling_index];
+} else {
+ics->num_swb= ff_aac_num_swb_1024[sampling_index];
+ics->swb_offset = ff_swb_offset_1024[sampling_index];
+}
 ics->tns_max_bands = ff_tns_max_bands_1024[sampling_index];
 }
 if (aot != AOT_ER_AAC_E

[FFmpeg-devel] [PATCH 0/6] avcodec: Vorbis encoder improvements

2017-08-21 Thread Tyler Jones
Please see the following patches.

The first two patches are identical to my latest pending changes sent to the
mailing list on July 28. Changelogs are included regardless. The clipping 
avoidance patch should remove most clicking that had been noticed by
atomnuker in previous versions.

Thanks in advance.

Tyler Jones (5):
  avcodec/vorbisenc: Add pre-echo detection
   V4: Use AVFloatDSPContext for variance calculation
Correctly change quality factors to const
Remove unnecessary malloc and free for VorbisPsyContext

   V3: Use normal float notation
Don't check before freeing NULL pointers
Remove unnecessary includes

   V2: Provide proper prefix for non-static function 
  
  avcodec/vorbisenc: Apply dynamic frame lengths
   V4: No changes
   V3: Switch 'bits[p] == 0' to '!bits[p]' in vlc gen
   V2: Fix double arithmetic in window scale
  avcodec/vorbisenc: Add clipping avoidance
  avcodec/vorbisenc: Move encoder structures and macros to separate file
  avcodec/vorbisenc: Separate floor and residue configurations
  avcodec/vorbisenc: Add support for mono streams

 libavcodec/Makefile  |   2 +-
 libavcodec/vorbis.c  |  10 +-
 libavcodec/vorbis_enc_data.h | 576 ++---
 libavcodec/vorbisenc.c   | 666 ++-
 libavcodec/vorbisenc.h   | 145 ++
 libavcodec/vorbispsy.c   | 164 +++
 libavcodec/vorbispsy.h   |  92 ++
 tests/fate/vorbis.mak|   2 +-
 8 files changed, 1220 insertions(+), 437 deletions(-)
 create mode 100644 libavcodec/vorbisenc.h
 create mode 100644 libavcodec/vorbispsy.c
 create mode 100644 libavcodec/vorbispsy.h

-- 
2.14.1

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


[FFmpeg-devel] [PATCH 3/6] avcodec/vorbisenc: Add clipping avoidance

2017-08-21 Thread Tyler Jones
Clipping is avoided by taking the maximum value of each frame before
window application, and scaling down the entire frame by a scalar
factor.

Signed-off-by: Tyler Jones 
---
 libavcodec/vorbisenc.c |  8 
 libavcodec/vorbispsy.c | 17 +
 libavcodec/vorbispsy.h | 10 ++
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index c968956794..73182c6356 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -1037,10 +1037,10 @@ static int residue_encode(vorbis_enc_context *venc, 
vorbis_enc_residue *rc,
  * See Vorbis I spec Fig. 2, 3 for examples.
  */
 static void apply_window(vorbis_enc_context *venc, const int *blockflags,
- float *out, float* in)
+ float *out, float* in, const float clip_factor)
 {
 int prev_size, curr_size, next_size, bound;
-float scale = 1.0f / (float) (1 << (venc->log2_blocksize[blockflags[1]] - 
2));
+float scale = clip_factor / (float) (1 << 
(venc->log2_blocksize[blockflags[1]] - 2));
 const float *prev_win, *next_win;
 AVFloatDSPContext *fdsp = venc->fdsp;
 
@@ -1098,9 +1098,9 @@ static int apply_window_and_mdct(vorbis_enc_context 
*venc, int next_type)
 for (channel = 0; channel < venc->channels; channel++) {
 float *out = venc->scratch;
 float *in  = venc->samples + channel * 2 * long_len + transient_offset;
+float clip_factor = ff_psy_vorbis_avoid_clip(in, curr_len, curr_type);
 
-apply_window(venc, blockflags, out, in);
-
+apply_window(venc, blockflags, out, in, clip_factor);
 venc->mdct[curr_type].mdct_calc(&venc->mdct[curr_type],
 venc->coeffs + channel * curr_len, 
out);
 }
diff --git a/libavcodec/vorbispsy.c b/libavcodec/vorbispsy.c
index ab2d41f62f..56e23dea5e 100644
--- a/libavcodec/vorbispsy.c
+++ b/libavcodec/vorbispsy.c
@@ -140,6 +140,23 @@ int ff_psy_vorbis_block_frame(VorbisPsyContext *vpctx, 
float *audio,
 return block_flag;
 }
 
+float ff_psy_vorbis_avoid_clip(float *audio, int window_len, int blockflag)
+{
+int i;
+float max = 0, clip = 1.0f;
+/* Due to how the mdct scaling works in the vorbis encoder, short blocks 
are
+ * more likely to clip. This serves as more fine-grained control */
+const float avoidance_factor = blockflag ? 0.95f : 0.75f;
+
+for (i = 0; i < window_len; i++)
+max = FFMAX(max, fabsf(audio[i]));
+
+if (max > avoidance_factor)
+clip = avoidance_factor / max;
+
+return clip;
+}
+
 av_cold void ff_psy_vorbis_close(VorbisPsyContext *vpctx)
 {
 av_freep(&vpctx->filter_delay);
diff --git a/libavcodec/vorbispsy.h b/libavcodec/vorbispsy.h
index 93a03fd8ca..e632e8ad1d 100644
--- a/libavcodec/vorbispsy.h
+++ b/libavcodec/vorbispsy.h
@@ -75,6 +75,16 @@ av_cold int ff_psy_vorbis_init(VorbisPsyContext *vpctx, int 
sample_rate,
  */
 int ff_psy_vorbis_block_frame(VorbisPsyContext *vpctx, float *audio,
   int ch, int frame_size, int block_size);
+
+/**
+ * Provide a scalar coefficient to avoid clipping.
+ *
+ * @param audio  Raw audio sample input for one channel
+ * @param window_len Chosen window length for the given frame
+ * @return Coefficient to be applied alongside the window function
+ */
+float ff_psy_vorbis_avoid_clip(float *audio, int window_len, int blockflag);
+
 /**
  * Closes and frees the memory used by the psychoacoustic model
  */
-- 
2.14.1

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


[FFmpeg-devel] [PATCH 5/6] avcodec/vorbisenc: Separate floor and residue configurations

2017-08-21 Thread Tyler Jones
The settings used for initializing the floor and residue codebooks are
separated so that they aren't coupled for later changes for arbitrary
channel configurations.

Signed-off-by: Tyler Jones 
---
 libavcodec/vorbis_enc_data.h | 112 ++---
 libavcodec/vorbisenc.c   | 167 ---
 2 files changed, 166 insertions(+), 113 deletions(-)

diff --git a/libavcodec/vorbis_enc_data.h b/libavcodec/vorbis_enc_data.h
index eca43dfded..6f2b10feb9 100644
--- a/libavcodec/vorbis_enc_data.h
+++ b/libavcodec/vorbis_enc_data.h
@@ -23,6 +23,26 @@
 
 #include 
 
+typedef const struct {
+int dim;
+int len;
+int real_len;
+const uint8_t *clens;
+int lookup;
+float min;
+float delta;
+const uint8_t *quant;
+} codebook_setup;
+
+typedef const struct {
+const int type;
+const int end[2];
+const int classifications;
+const int nbooks;
+const codebook_setup *config;
+const int8_t books[10][8];
+} res_setup;
+
 static const uint8_t floor_128_c0[] = {
 10,  7,  8, 13,  9,  6,  7, 11, 10,  8,  8, 12, 17, 17, 17,
 17,  7,  5,  5,  9,  6,  4,  4,  8,  8,  5,  5,  8, 16, 14,
@@ -219,7 +239,7 @@ static const uint8_t floor_1024_4sub3[] = {
 11, 11, 10, 10, 10, 10, 10, 10,
 };
 
-static const uint8_t res_long_master[] = {
+static const uint8_t res_stereo_long_master[] = {
  5,  6, 11, 11, 11, 11, 10, 10, 12, 11,  5,  2, 11,  5,  6,
  6,  7,  9, 11, 13, 13, 10,  7, 11,  6,  7,  8,  9, 10, 12,
 11,  5, 11,  6,  8,  7,  9, 11, 14, 15, 11,  6,  6,  8,  4,
@@ -229,7 +249,7 @@ static const uint8_t res_long_master[] = {
 11, 13, 12, 15, 12, 11,  9,  8,  8,  8,
 };
 
-static const uint8_t res_short_master[] = {
+static const uint8_t res_stereo_short_master[] = {
 10,  9, 13, 11, 14, 10, 12, 13, 13, 14,  7,  2, 12,  5, 10,
  5,  7, 10, 12, 14, 12,  6,  9,  8,  7,  7,  9, 11, 13, 16,
 10,  4, 12,  5, 10,  6,  8, 12, 14, 16, 12,  6,  8,  7,  6,
@@ -239,7 +259,7 @@ static const uint8_t res_short_master[] = {
 15, 13, 11, 10,  6,  5,  6,  8,  9, 11,
 };
 
-static const uint8_t res_p1_0[] = {
+static const uint8_t res_stereo_p1_0[] = {
  2,  4,  4,  0,  0,  0,  0,  0,  0,  5,  6,  6,  0,  0,  0,
  0,  0,  0,  5,  6,  6,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
@@ -352,7 +372,7 @@ static const uint8_t res_p1_0[] = {
  0,  0,  0,  8,  9,  8,
 };
 
-static const uint8_t res_p2_0[] = {
+static const uint8_t res_stereo_p2_0[] = {
  2,  5,  5,  0,  0,  0,  5,  5,  0,  0,  0,  5,  5,  0,  0,
  0,  7,  8,  0,  0,  0,  0,  0,  0,  0,  5,  6,  6,  0,  0,
  0,  7,  7,  0,  0,  0,  7,  7,  0,  0,  0, 10, 10,  0,  0,
@@ -385,7 +405,7 @@ static const uint8_t res_p2_0[] = {
  0,  9,  9,  0,  0,  0, 10, 10,
 };
 
-static const uint8_t res_p3_0[] = {
+static const uint8_t res_stereo_p3_0[] = {
  2,  4,  3,  6,  6,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  4,  4,  4,  6,  6,
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
@@ -395,7 +415,7 @@ static const uint8_t res_p3_0[] = {
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  6,  6,  7,  9,  9,
 };
 
-static const uint8_t res_p4_0[] = {
+static const uint8_t res_stereo_p4_0[] = {
  2,  3,  3,  6,  6,  0,  0,  0,  0,  0,  4,  4,  6,  6,  0,
  0,  0,  0,  0,  4,  4,  6,  6,  0,  0,  0,  0,  0,  5,  5,
  6,  6,  0,  0,  0,  0,  0,  0,  0,  6,  6,  0,  0,  0,  0,
@@ -403,7 +423,7 @@ static const uint8_t res_p4_0[] = {
  0,  0,  0,  0,  0,  0,  9,  9,
 };
 
-static const uint8_t res_p5_0[] = {
+static const uint8_t res_stereo_p5_0[] = {
  1,  3,  4,  6,  6,  7,  7,  9,  9,  0,  5,  5,  7,  7,  7,
  8,  9,  9,  0,  5,  5,  7,  7,  8,  8,  9,  9,  0,  7,  7,
  8,  8,  8,  8, 10, 10,  0,  0,  0,  8,  8,  8,  8, 10, 10,
@@ -412,7 +432,7 @@ static const uint8_t res_p5_0[] = {
  0,  0, 10, 10, 11, 11,
 };
 
-static const uint8_t res_p6_0[] = {
+static const uint8_t res_stereo_p6_0[] = {
  2,  3,  3,  6,  6,  7,  7,  8,  8,  8,  8,  9,  9, 10, 10,
 11, 10,  0,  5,  5,  7,  7,  8,  8,  9,  9,  9,  9, 10, 10,
 10, 10, 11, 11,  0,  5,  5,  7,  7,  8,  8,  9,  9,  9,  9,
@@ -435,7 +455,7 @@ static const uint8_t res_p6_0[] = {
 13, 13, 13, 13,
 };
 
-static const uint8_t res_p7_0[] = {
+static const uint8_t res_stereo_p7_0[] = {
  1,  4,  4,  7,  6,  6,  7,  6,  6,  4,  7,  7, 10,  9,  9,
 11,  9,  9,  4,  7,  7, 10,  9,  9, 11,  9,  9,  7, 10, 10,
 11, 11, 10, 12, 11, 11,  6,  9,  9, 11, 10, 10, 11, 10, 10,
@@ -444,7 +464,7 @@ static const uint8_t res_p7_0[] = {
 11, 10, 10, 11, 10, 10,
 };
 
-static const uint8_t res_p7_1[] = {
+static const uint8_t res_stereo_p7_1[] = {
  2,  4,  4,  6,  6,  7,  7,  7,  7,  8,  8, 10,  5,  5,  6,
  6,  7,  7,  8,  8,  8,  8, 10,  5,  5,  6,  6,  7,  7,  8,
  8,  8,  8, 10,  6,  6,  7,  7,  8,  8,  8,  8,  8,  8, 10,
@@ -45

[FFmpeg-devel] [PATCH 1/6] avcodec/vorbisenc: Add pre-echo detection

2017-08-21 Thread Tyler Jones
The encoder will attempt to determine the existence of transient
signals by applying a 4th order highpass filter to remove dominant
low frequency waveforms. Frames are then split up into blocks
where the variance is calculated and compared with blocks from
the previous frame. A preecho is only likely to be noticeable when
relatively quiet audio is followed by a loud transient signal.

Signed-off-by: Tyler Jones 
---
V4: Use AVFloatDSPContext for variance calculation
Correctly change quality factors to const
Remove unnecessary malloc and free for VorbisPsyContext

V3: Use normal float notation
Don't check before freeing NULL pointers
Remove unnecessary includes

V2: Provide proper prefix for non-static function

 libavcodec/Makefile|   2 +-
 libavcodec/vorbisenc.c |  27 +++--
 libavcodec/vorbispsy.c | 147 +
 libavcodec/vorbispsy.h |  82 +++
 4 files changed, 253 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/vorbispsy.c
 create mode 100644 libavcodec/vorbispsy.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 982d7f5179..315c403c9c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -611,7 +611,7 @@ OBJS-$(CONFIG_VMNC_DECODER)+= vmnc.o
 OBJS-$(CONFIG_VORBIS_DECODER)  += vorbisdec.o vorbisdsp.o vorbis.o \
   vorbis_data.o
 OBJS-$(CONFIG_VORBIS_ENCODER)  += vorbisenc.o vorbis.o \
-  vorbis_data.o
+  vorbis_data.o vorbispsy.o
 OBJS-$(CONFIG_VP3_DECODER) += vp3.o
 OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vp56rac.o
 OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o \
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index bf21a3b1ff..6da5f012c2 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -33,6 +33,7 @@
 #include "mathops.h"
 #include "vorbis.h"
 #include "vorbis_enc_data.h"
+#include "vorbispsy.h"
 
 #include "audio_frame_queue.h"
 #include "libavfilter/bufferqueue.h"
@@ -136,6 +137,7 @@ typedef struct vorbis_enc_context {
 int64_t next_pts;
 
 AVFloatDSPContext *fdsp;
+VorbisPsyContext vpctx;
 } vorbis_enc_context;
 
 #define MAX_CHANNELS 2
@@ -272,11 +274,12 @@ static int create_vorbis_context(vorbis_enc_context *venc,
 vorbis_enc_floor   *fc;
 vorbis_enc_residue *rc;
 vorbis_enc_mapping *mc;
-int i, book, ret;
+int i, book, ret, blocks;
 
 venc->channels= avctx->channels;
 venc->sample_rate = avctx->sample_rate;
-venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
+venc->log2_blocksize[0] = 8;
+venc->log2_blocksize[1] = 11;
 
 venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
 venc->codebooks  = av_malloc(sizeof(vorbis_enc_codebook) * 
venc->ncodebooks);
@@ -464,6 +467,11 @@ static int create_vorbis_context(vorbis_enc_context *venc,
 if ((ret = dsp_init(avctx, venc)) < 0)
 return ret;
 
+blocks = 1 << (venc->log2_blocksize[1] - venc->log2_blocksize[0]);
+if ((ret = ff_psy_vorbis_init(&venc->vpctx, venc->sample_rate,
+  venc->channels, blocks, venc->fdsp)) < 0)
+return ret;
+
 return 0;
 }
 
@@ -1078,15 +1086,17 @@ static void move_audio(vorbis_enc_context *venc, int 
sf_size)
 av_frame_free(&cur);
 }
 venc->have_saved = 1;
-memcpy(venc->scratch, venc->samples, 2 * venc->channels * frame_size);
+memcpy(venc->scratch, venc->samples, sizeof(float) * venc->channels * 2 * 
frame_size);
 }
 
 static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
 {
 vorbis_enc_context *venc = avctx->priv_data;
-int i, ret, need_more;
+int i, ret, need_more, ch;
+int curr_win = 1;
 int frame_size = 1 << (venc->log2_blocksize[1] - 1);
+int block_size = 1 << (venc->log2_blocksize[0] - 1);
 vorbis_enc_mode *mode;
 vorbis_enc_mapping *mapping;
 PutBitContext pb;
@@ -1121,6 +1131,14 @@ static int vorbis_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 
 move_audio(venc, avctx->frame_size);
 
+for (ch = 0; ch < venc->channels; ch++) {
+float *scratch = venc->scratch + 2 * ch * frame_size + frame_size;
+
+if (!ff_psy_vorbis_block_frame(&venc->vpctx, scratch, ch,
+   frame_size, block_size))
+curr_win = 0;
+}
+
 if (!apply_window_and_mdct(venc))
 return 0;
 
@@ -1252,6 +1270,7 @@ static av_cold int vorbis_encode_close(AVCodecContext 
*avctx)
 ff_mdct_end(&venc->mdct[1]);
 ff_af_queue_close(&venc->afq);
 ff_bufqueue_discard_all(&venc->bufqueue);
+ff_psy_vorbis_close(&venc->vpctx);
 
 av_freep(&avctx->extradata);
 
diff --git a/libavcodec/vorbispsy.c b/libavcodec/vorbispsy.c
new file mode 1

[FFmpeg-devel] [PATCH 6/6] avcodec/vorbisenc: Add support for mono streams

2017-08-21 Thread Tyler Jones
Signed-off-by: Tyler Jones 
---
 libavcodec/vorbis_enc_data.h | 245 ++-
 libavcodec/vorbisenc.c   |  46 
 2 files changed, 267 insertions(+), 24 deletions(-)

diff --git a/libavcodec/vorbis_enc_data.h b/libavcodec/vorbis_enc_data.h
index 6f2b10feb9..32750da803 100644
--- a/libavcodec/vorbis_enc_data.h
+++ b/libavcodec/vorbis_enc_data.h
@@ -23,6 +23,9 @@
 
 #include 
 
+#define RES_PASSES   8
+#define RES_MAX_CLASSIF 10
+
 typedef const struct {
 int dim;
 int len;
@@ -35,12 +38,11 @@ typedef const struct {
 } codebook_setup;
 
 typedef const struct {
-const int type;
 const int end[2];
 const int classifications;
 const int nbooks;
 const codebook_setup *config;
-const int8_t books[10][8];
+const int8_t books[RES_MAX_CLASSIF][RES_PASSES];
 } res_setup;
 
 static const uint8_t floor_128_c0[] = {
@@ -552,6 +554,209 @@ static const uint8_t res_stereo_p9_2[] = {
  9, 10, 10, 10,
 };
 
+static const uint8_t res_mono_long_master[] = {
+ 6,  9, 13, 12, 14, 11, 10, 13,  8,  4,  5,  7,  8,  7,  8,
+12, 11,  4,  3,  5,  5,  7,  9, 14, 11,  6,  5,  6,  6,  6,
+ 7, 13, 13,  7,  5,  6,  4,  5,  7, 14, 11,  7,  6,  6,  5,
+ 5,  6, 13,  9,  7,  8,  6,  7,  5,  3,  9,  9, 12, 13, 12,
+14, 10,  6,  7,
+};
+
+static const uint8_t res_mono_short_master[] = {
+14, 14, 14, 15, 13, 15, 12, 16, 10,  8,  7,  9,  9,  8, 12,
+16, 10,  5,  4,  6,  5,  6,  9, 16, 14,  8,  6,  8,  7,  8,
+10, 16, 14,  7,  4,  6,  3,  5,  8, 16, 15,  9,  5,  7,  4,
+ 4,  7, 16, 13, 10,  6,  7,  4,  3,  4, 13, 13, 12,  7,  9,
+ 5,  5,  6, 12,
+};
+
+static const uint8_t res_mono_p1_0[] = {
+ 1,  4,  4,  5,  8,  7,  5,  7,  8,  5,  8,  8,  8, 10, 11,
+ 8, 10, 11,  5,  8,  8,  8, 11, 10,  8, 11, 11,  4,  8,  8,
+ 8, 11, 11,  8, 11, 11,  8, 11, 11, 11, 13, 14, 11, 14, 14,
+ 8, 11, 11, 10, 14, 12, 11, 14, 14,  4,  8,  8,  8, 11, 11,
+ 8, 11, 11,  7, 11, 11, 11, 14, 14, 10, 12, 14,  8, 11, 11,
+11, 14, 14, 11, 14, 13,
+};
+
+static const uint8_t res_mono_p2_0[] = {
+ 2,  5,  4,  5,  6,  6,  5,  6,  6,  5,  6,  6,  7,  8,  8,
+ 6,  8,  8,  5,  6,  6,  6,  8,  8,  7,  8,  8,  5,  7,  6,
+ 7,  8,  8,  6,  8,  8,  7,  8,  8,  8,  9, 10,  8, 10, 10,
+ 6,  8,  8,  8, 10,  8,  8, 10, 10,  5,  6,  6,  6,  8,  8,
+ 7,  8,  8,  6,  8,  8,  8, 10, 10,  8,  8, 10,  7,  8,  8,
+ 8, 10, 10,  8, 10,  9,
+};
+
+static const uint8_t res_mono_p3_0[] = {
+ 2,  4,  4,  7,  7,  5,  7,  7,  9,  9,  5,  7,  7,  9,  9,
+ 8,  9,  9, 12, 12,  8,  9,  9, 11, 12,  5,  7,  7, 10, 10,
+ 7,  9,  9, 11, 11,  7,  9,  9, 10, 11, 10, 11, 11, 13, 13,
+ 9, 10, 11, 13, 13,  5,  7,  7, 10, 10,  7,  9,  9, 11, 10,
+ 7,  9,  9, 11, 11,  9, 11, 10, 13, 13, 10, 11, 11, 14, 13,
+ 8, 10, 10, 14, 13, 10, 11, 11, 15, 14,  9, 11, 11, 14, 14,
+13, 14, 13, 16, 16, 12, 13, 13, 15, 15,  8, 10, 10, 13, 14,
+ 9, 11, 11, 14, 14, 10, 11, 11, 14, 15, 12, 13, 13, 15, 15,
+13, 14, 14, 15, 16,  5,  7,  7, 10, 10,  7,  9,  9, 11, 11,
+ 7,  9,  9, 11, 12, 10, 11, 11, 14, 14, 10, 11, 11, 14, 14,
+ 7,  9,  9, 12, 12,  9, 11, 11, 13, 13,  9, 11, 11, 13, 13,
+12, 12, 13, 15, 15, 11, 12, 13, 15, 16,  7,  9,  9, 11, 11,
+ 8, 11, 10, 13, 12,  9, 11, 11, 13, 13, 11, 13, 12, 15, 13,
+11, 13, 13, 15, 16,  9, 12, 11, 15, 14, 11, 12, 13, 16, 15,
+11, 13, 13, 15, 16, 14, 14, 15, 17, 16, 13, 15, 16,  0, 17,
+ 9, 11, 11, 15, 15, 10, 13, 12, 15, 15, 11, 13, 13, 15, 16,
+13, 15, 13, 16, 15, 14, 16, 15,  0, 19,  5,  7,  7, 10, 10,
+ 7,  9,  9, 11, 11,  7,  9,  9, 11, 11, 10, 12, 11, 14, 14,
+10, 11, 12, 14, 14,  7,  9,  9, 12, 12,  9, 11, 11, 14, 13,
+ 9, 10, 11, 12, 13, 11, 13, 13, 16, 16, 11, 12, 13, 13, 16,
+ 7,  9,  9, 12, 12,  9, 11, 11, 13, 13,  9, 11, 11, 13, 13,
+11, 13, 13, 15, 15, 12, 13, 12, 15, 14,  9, 11, 11, 15, 14,
+11, 13, 12, 16, 16, 10, 12, 12, 15, 15, 13, 15, 15, 17, 19,
+13, 14, 15, 16, 17, 10, 12, 12, 15, 15, 11, 13, 13, 16, 16,
+11, 13, 13, 15, 16, 13, 15, 15,  0,  0, 14, 15, 15, 16, 16,
+ 8, 10, 10, 14, 14, 10, 12, 12, 15, 15, 10, 12, 11, 15, 16,
+14, 15, 15, 19, 20, 13, 14, 14, 18, 16,  9, 11, 11, 15, 15,
+11, 13, 13, 17, 16, 11, 13, 13, 16, 16, 15, 17, 17, 20, 20,
+14, 15, 16, 17, 20,  9, 11, 11, 15, 15, 10, 13, 12, 16, 15,
+11, 13, 13, 15, 17, 14, 16, 15, 18,  0, 14, 16, 15, 18, 20,
+12, 14, 14,  0,  0, 14, 14, 16,  0,  0, 13, 16, 15,  0,  0,
+17, 17, 18,  0,  0, 16, 17, 19, 19,  0, 12, 14, 14, 18,  0,
+12, 16, 14,  0, 17, 13, 15, 15, 18,  0, 16, 18, 17,  0, 17,
+16, 18, 17,  0,  0,  7, 10, 10, 14, 14, 10, 12, 11, 15, 15,
+10, 12, 12, 16, 15, 13, 15, 15, 18,  0, 14, 15, 15, 17,  0,
+ 9, 11, 11, 15, 15, 11, 13, 13, 16, 16, 11, 12, 13, 16, 16,
+14, 15, 16, 17, 17, 14, 16, 16, 16, 18,  9, 11, 12, 16, 16,
+11, 13, 13, 17, 17, 11, 14, 13, 20, 17, 15, 16, 16, 19,  0,
+15, 16, 17,  0,

[FFmpeg-devel] [PATCH 2/6] avcodec/vorbisenc: Apply dynamic frame lengths

2017-08-21 Thread Tyler Jones
Additional codebooks are added for shorter 128-sample frames. Changes in
codeword generation are made to handle valid values of 0 that prepend some
codebooks, otherwise books are classified incorrectly and cause unreadable
streams.

A second residue, floor, and mapping is created for short window lengths
so that values are partitioned correctly for transient frames.

Signed-off-by: Tyler Jones 
---
V4: No changes
V3: Switch 'bits[p] == 0' to '!bits[p]' in vlc gen
V2: Fix double arithmetic in window scale

 libavcodec/vorbis.c  |  10 +-
 libavcodec/vorbis_enc_data.h | 289 +++--
 libavcodec/vorbisenc.c   | 424 ++-
 tests/fate/vorbis.mak|   2 +-
 4 files changed, 454 insertions(+), 271 deletions(-)

diff --git a/libavcodec/vorbis.c b/libavcodec/vorbis.c
index 399020eec5..d8c4b006e7 100644
--- a/libavcodec/vorbis.c
+++ b/libavcodec/vorbis.c
@@ -59,7 +59,7 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, 
unsigned num)
 unsigned i, j, p, code;
 
 for (p = 0; (bits[p] == 0) && (p < num); ++p)
-;
+codes[p] = 0;
 if (p == num)
 return 0;
 
@@ -78,9 +78,11 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, 
unsigned num)
 
 for (; p < num; ++p) {
 if (bits[p] > 32)
- return AVERROR_INVALIDDATA;
-if (bits[p] == 0)
- continue;
+return AVERROR_INVALIDDATA;
+if (!bits[p]) {
+codes[p] = 0;
+continue;
+}
 // find corresponding exit(node which the tree can grow further from)
 for (i = bits[p]; i > 0; --i)
 if (exit_at_level[i])
diff --git a/libavcodec/vorbis_enc_data.h b/libavcodec/vorbis_enc_data.h
index a51aaec978..eca43dfded 100644
--- a/libavcodec/vorbis_enc_data.h
+++ b/libavcodec/vorbis_enc_data.h
@@ -23,15 +23,78 @@
 
 #include 
 
-static const uint8_t codebook0[] = {
+static const uint8_t floor_128_c0[] = {
+10,  7,  8, 13,  9,  6,  7, 11, 10,  8,  8, 12, 17, 17, 17,
+17,  7,  5,  5,  9,  6,  4,  4,  8,  8,  5,  5,  8, 16, 14,
+13, 16,  7,  5,  5,  7,  6,  3,  3,  5,  8,  5,  4,  7, 14,
+12, 12, 15, 10,  7,  8,  9,  7,  5,  5,  6,  9,  6,  5,  5,
+15, 12,  9, 10,
+};
+
+static const uint8_t floor_128_c1[] = {
+ 8, 13, 17, 17,  8, 11, 17, 17, 11, 13, 17, 17, 17, 17, 17,
+17,  6, 10, 16, 17,  6, 10, 15, 17,  8, 10, 16, 17, 17, 17,
+17, 17,  9, 13, 15, 17,  8, 11, 17, 17, 10, 12, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17,  6, 11, 15, 17,  7, 10, 15, 17,  8, 10, 17,
+17, 17, 15, 17, 17,  4,  8, 13, 17,  4,  7, 13, 17,  6,  8,
+15, 17, 16, 15, 17, 17,  6, 11, 15, 17,  6,  9, 13, 17,  8,
+10, 17, 17, 15, 17, 17, 17, 16, 17, 17, 17, 12, 14, 15, 17,
+13, 14, 15, 17, 17, 17, 17, 17,  5, 10, 14, 17,  5,  9, 14,
+17,  7,  9, 15, 17, 15, 15, 17, 17,  3,  7, 12, 17,  3,  6,
+11, 17,  5,  7, 13, 17, 12, 12, 17, 17,  5,  9, 14, 17,  3,
+ 7, 11, 17,  5,  8, 13, 17, 13, 11, 16, 17, 12, 17, 17, 17,
+ 9, 14, 15, 17, 10, 11, 14, 17, 16, 14, 17, 17,  8, 12, 17,
+17,  8, 12, 17, 17, 10, 12, 17, 17, 17, 17, 17, 17,  5, 10,
+17, 17,  5,  9, 15, 17,  7,  9, 17, 17, 13, 13, 17, 17,  7,
+11, 17, 17,  6, 10, 15, 17,  7,  9, 15, 17, 12, 11, 17, 17,
+12, 15, 17, 17, 11, 14, 17, 17, 11, 10, 15, 17, 17, 16, 17,
+17,
+};
+
+static const uint8_t floor_128_0sub1[] = {
+ 0,  3,  3,  3,  3,  3,  3,  3,  3,
+};
+
+static const uint8_t floor_128_0sub2[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  3,  3,  4,  4,  4,
+ 4,  5,  4,  5,  4,  5,  4,  6,  4,  6,
+};
+
+static const uint8_t floor_128_0sub3[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  5,  3,  5,  3,
+ 5,  4,  5,  4,  5,  5,  5,  5,  6,  5,  6,  5,  6,  5,  6,
+ 5,  6,  5,  7,  8,  9, 11, 13, 13, 13, 13, 13, 13, 13, 13,
+13, 13, 13, 13,
+};
+
+static const uint8_t floor_128_1sub1[] = {
+ 0,  3,  3,  2,  3,  3,  4,  3,  4,
+};
+
+static const uint8_t floor_128_1sub2[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  4,  3,  6,  3,  6,
+ 3,  6,  3,  7,  3,  8,  4,  9,  4,  9,
+};
+
+static const uint8_t floor_128_1sub3[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  7,  2,  7,  3,
+ 8,  4,  9,  5,  9,  8, 10, 11, 11, 12, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+13, 13, 13, 13,
+};
+
+static const uint8_t floor_1024_c1[] = {
 2, 10,  8, 14,  7, 12, 11, 14,  1,  5,  3,  7,  4,  9,  7, 13,
 };
 
-static const uint8_t codebook1[] = {
+static const uint8_t floor_1024_c2[] = {
 1,  4,  2,  6,  3,  7,  5,  7,
 };
 
-static const uint8_t codebook2[] = {
+static const uint8_t floor_1024_c3[] = {
  1,  5,  7, 21,  5,  8,  9, 21, 10,  9, 12, 20, 20, 16, 20,
 20,  4,  8, 

[FFmpeg-devel] [PATCH 4/6] avcodec/vorbisenc: Move encoder structures and macros to separate file

2017-08-21 Thread Tyler Jones
Encoder structures are moved to a separate header file to improve
readability.

Signed-off-by: Tyler Jones 
---
 libavcodec/vorbisenc.c | 118 +---
 libavcodec/vorbisenc.h | 145 +
 2 files changed, 146 insertions(+), 117 deletions(-)
 create mode 100644 libavcodec/vorbisenc.h

diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 73182c6356..fae90c4a30 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -25,18 +25,12 @@
  */
 
 #include 
-#include "libavutil/float_dsp.h"
 
+#include "vorbisenc.h"
 #include "avcodec.h"
 #include "internal.h"
-#include "fft.h"
 #include "mathops.h"
-#include "vorbis.h"
 #include "vorbis_enc_data.h"
-#include "vorbispsy.h"
-
-#include "audio_frame_queue.h"
-#include "libavfilter/bufferqueue.h"
 
 #define BITSTREAM_WRITER_LE
 #include "put_bits.h"
@@ -44,116 +38,6 @@
 #undef NDEBUG
 #include 
 
-typedef struct vorbis_enc_codebook {
-int nentries;
-uint8_t *lens;
-uint32_t *codewords;
-int ndimensions;
-float min;
-float delta;
-int seq_p;
-int lookup;
-int *quantlist;
-float *dimensions;
-float *pow2;
-} vorbis_enc_codebook;
-
-typedef struct vorbis_enc_floor_class {
-int dim;
-int subclass;
-int masterbook;
-int *books;
-} vorbis_enc_floor_class;
-
-typedef struct vorbis_enc_floor {
-int partitions;
-int *partition_to_class;
-int nclasses;
-vorbis_enc_floor_class *classes;
-int multiplier;
-int rangebits;
-int values;
-vorbis_floor1_entry *list;
-} vorbis_enc_floor;
-
-typedef struct vorbis_enc_residue {
-int type;
-int begin;
-int end;
-int partition_size;
-int classifications;
-int classbook;
-int8_t (*books)[8];
-float (*maxes)[2];
-} vorbis_enc_residue;
-
-typedef struct vorbis_enc_mapping {
-int submaps;
-int *mux;
-int *floor;
-int *residue;
-int coupling_steps;
-int *magnitude;
-int *angle;
-} vorbis_enc_mapping;
-
-typedef struct vorbis_enc_mode {
-int blockflag;
-int mapping;
-} vorbis_enc_mode;
-
-typedef struct vorbis_enc_context {
-int channels;
-int sample_rate;
-int log2_blocksize[2];
-int blockflags[3]; ///< Flags used for the previous, current, next windows
-int transient; ///< Negative if a series of transients are not being 
encoded
-int num_transient; ///< Number of short blocks for each frame
-FFTContext mdct[2];
-const float *win[2];
-int have_saved;
-float *saved;
-float *samples;
-float *floor;  // also used for tmp values for mdct
-float *coeffs; // also used for residue after floor
-float *scratch; //< Used for temp values for psy model and window 
application
-float quality;
-
-AudioFrameQueue afq;
-struct FFBufQueue bufqueue;
-
-int ncodebooks;
-vorbis_enc_codebook *codebooks;
-
-int nfloors;
-vorbis_enc_floor *floors;
-
-int nresidues;
-vorbis_enc_residue *residues;
-
-int nmappings;
-vorbis_enc_mapping *mappings;
-
-int nmodes;
-vorbis_enc_mode *modes;
-
-int64_t next_pts;
-
-AVFloatDSPContext *fdsp;
-VorbisPsyContext vpctx;
-} vorbis_enc_context;
-
-#define MAX_CHANNELS 2
-#define MAX_CODEBOOK_DIM 8
-
-#define MAX_FLOOR_CLASS_DIM  4
-#define NUM_FLOOR_PARTITIONS 8
-#define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2)
-
-#define RESIDUE_SIZE   1600
-#define RESIDUE_PART_SIZE  32
-#define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE)
-
 static inline int put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb,
int entry)
 {
diff --git a/libavcodec/vorbisenc.h b/libavcodec/vorbisenc.h
new file mode 100644
index 00..15ee02dfa6
--- /dev/null
+++ b/libavcodec/vorbisenc.h
@@ -0,0 +1,145 @@
+/*
+ * Vorbis encoder
+ * Copyright (C) 2017 Tyler Jones
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_VORBISENC_H
+#define AVCODEC_VORBISENC_H
+
+#define MAX_CHANNELS 2
+#define MAX_CODEBOOK_DIM 8
+
+#define MAX_FLOOR_CLASS_DIM  4
+#define NUM_FLOOR_PARTITIONS 8
+#define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2)
+
+#define RES

[FFmpeg-devel] [PATCH] avcodec/dvbsubdec: Check for duplicate regions in dvbsub_parse_page_segment()

2017-08-21 Thread Michael Niedermayer
Fixes: OOM
Fixes: 3051/clusterfuzz-testcase-minimized-5745818336231424

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/dvbsubdec.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 98619f9631..b683109643 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -1302,6 +1302,15 @@ static int dvbsub_parse_page_segment(AVCodecContext 
*avctx,
 region_id = *buf++;
 buf += 1;
 
+display = ctx->display_list;
+while (display && display->region_id != region_id) {
+display = display->next;
+}
+if (display) {
+av_log(avctx, AV_LOG_ERROR, "duplicate region\n");
+break;
+}
+
 display = tmp_display_list;
 tmp_ptr = &tmp_display_list;
 
-- 
2.14.1

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


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: move free fmp4_init_filename after hls_window operation

2017-08-21 Thread Steven Liu
2017-08-20 21:19 GMT+08:00 Steven Liu :
> fix ticket id: 6599
>
> Signed-off-by: Steven Liu 
> ---
>  libavformat/hlsenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 74a3249b73..4a90886331 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1745,7 +1745,6 @@ static int hls_write_trailer(struct AVFormatContext *s)
>  hls->size = avio_tell(hls->vtt_avf->pb) - hls->start_pos;
>  ff_format_io_close(s, &vtt_oc->pb);
>  }
> -av_freep(&hls->fmp4_init_filename);
>  av_freep(&hls->basename);
>  av_freep(&hls->base_output_dirname);
>  av_freep(&hls->key_basename);
> @@ -1754,6 +1753,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
>  hls->avf = NULL;
>  hls_window(s, 1);
>
> +av_freep(&hls->fmp4_init_filename);
>  if (vtt_oc) {
>  av_freep(&hls->vtt_basename);
>  av_freep(&hls->vtt_m3u8_name);
> --
> 2.11.0 (Apple Git-81)
>
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] vp9: set color range to MPEG for intraonly profile 0

2017-08-21 Thread James Zern
On Sat, Aug 19, 2017 at 8:04 AM, Ronald S. Bultje  wrote:
> Hi,
>
> On Fri, Aug 18, 2017 at 11:31 PM, James Zern  wrote:
>>
>> this is undocumented in the vp9 bitstream and decoding specification
>> doc, but matches libvpx
>>
>> Signed-off-by: James Zern 
>> ---
>>  libavcodec/vp9.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
>> index 7d8aced8c8..94430db9a3 100644
>> --- a/libavcodec/vp9.c
>> +++ b/libavcodec/vp9.c
>> @@ -459,7 +459,7 @@ static int decode_frame_header(AVCodecContext *avctx,
>>  s->bytesperpixel = 1;
>>  s->pix_fmt = AV_PIX_FMT_YUV420P;
>>  avctx->colorspace = AVCOL_SPC_BT470BG;
>> -avctx->color_range = AVCOL_RANGE_JPEG;
>> +avctx->color_range = AVCOL_RANGE_MPEG;
>
>
> OK.
>

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