Re: [FFmpeg-devel] [PATCH] avfilter/scale.c: factorize ff_scale_eval_dimensions

2019-12-06 Thread Gyan



On 07-12-2019 12:36 am, Michael Niedermayer wrote:

On Wed, Dec 04, 2019 at 02:14:35PM +0530, Gyan wrote:

Will help reduce code duplication when adding animation support to vf_scale.
See Michael's last comment in https://patchwork.ffmpeg.org/patch/16272/

Gyan
  doc/filters.texi |   40 +
  libavfilter/scale.c  |   59 
++-
  libavfilter/scale.h  |4 ++
  libavfilter/vf_scale.c   |   28 ++--
  libavfilter/vf_scale_cuda.c  |   11 
  libavfilter/vf_scale_npp.c   |   11 
  libavfilter/vf_scale_vaapi.c |   11 
  7 files changed, 128 insertions(+), 36 deletions(-)
380bf799c14d6286cc625afe019aa553614a7d53  
0001-avfilter-scale.c-factorize-ff_scale_eval_dimensions.patch
 From 138a8dba766674a1b017614c58fa99aeca98e9e5 Mon Sep 17 00:00:00 2001
From: Gyan Doshi 
Date: Mon, 2 Dec 2019 21:11:21 +0530
Subject: [PATCH] avfilter/scale.c: factorize ff_scale_eval_dimensions

Adjustment of evaluated values shifted to ff_adjust_scale_dimensions
Shifted code for force_original_aspect_ratio and force_divisble_by from
vf_scale so it is now available for scale_cuda, scale_npp and
scale_vaapi as well.
---
  doc/filters.texi | 40 
  libavfilter/scale.c  | 59 +---
  libavfilter/scale.h  |  4 +++
  libavfilter/vf_scale.c   | 28 ++---
  libavfilter/vf_scale_cuda.c  | 11 +++
  libavfilter/vf_scale_npp.c   | 11 +++
  libavfilter/vf_scale_vaapi.c | 11 +++
  7 files changed, 128 insertions(+), 36 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 5fdec6f015..9129f7e3a5 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -16210,6 +16210,46 @@ Supersampling
  @item lanczos
  @end table
  
+@item force_original_aspect_ratio

+Enable decreasing or increasing output video width or height if necessary to
+keep the original aspect ratio. Possible values:
+
+@table @samp
+@item disable
+Scale the video as specified and disable this feature.
+
+@item decrease
+The output video dimensions will automatically be decreased if needed.
+
+@item increase
+The output video dimensions will automatically be increased if needed.
+
+@end table
+
+One useful instance of this option is that when you know a specific device's
+maximum allowed resolution, you can use this to limit the output video to
+that, while retaining the aspect ratio. For example, device A allows
+1280x720 playback, and your video is 1920x800. Using this option (set it to
+decrease) and specifying 1280x720 to the command line makes the output
+1280x533.
+
+Please note that this is a different thing than specifying -1 for @option{w}
+or @option{h}, you still need to specify the output resolution for this option
+to work.
+
+@item force_divisible_by
+Ensures that both the output dimensions, width and height, are divisible by the
+given integer when used together with @option{force_original_aspect_ratio}. 
This
+works similar to using @code{-n} in the @option{w} and @option{h} options.
+
+This option respects the value set for @option{force_original_aspect_ratio},
+increasing or decreasing the resolution accordingly. The video's aspect ratio
+may be slightly modified.
+
+This option can be handy if you need to have a video fit within or exceed
+a defined resolution using @option{force_original_aspect_ratio} but also have
+encoder restrictions on width or height divisibility.
+
  @end table
  
  @section scale2ref

diff --git a/libavfilter/scale.c b/libavfilter/scale.c
index eaee95fac6..5e9f97230c 100644
--- a/libavfilter/scale.c
+++ b/libavfilter/scale.c
@@ -111,8 +111,6 @@ int ff_scale_eval_dimensions(void *log_ctx,
  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
  const char *expr;
-int w, h;
-int factor_w, factor_h;
  int eval_w, eval_h;
  int ret;
  const char scale2ref = outlink->src->nb_inputs == 2 && 
outlink->src->inputs[1] == inlink;
@@ -172,8 +170,28 @@ int ff_scale_eval_dimensions(void *log_ctx,
  goto fail;
  eval_w = (int) res == 0 ? inlink->w : (int) res;
  
-w = eval_w;

-h = eval_h;
+*ret_w = eval_w;
+*ret_h = eval_h;
+
+return 0;
+
+fail:
+av_log(log_ctx, AV_LOG_ERROR,
+   "Error when evaluating the expression '%s'.\n"
+   "Maybe the expression for out_w:'%s' or for out_h:'%s' is 
self-referencing.\n",
+   expr, w_expr, h_expr);
+return ret;
+}
+
+int ff_scale_adjust_dimensions(AVFilterLink *inlink,
+int *ret_w, int *ret_h,
+int force_original_aspect_ratio, int force_divisible_by)
+{
+int w, h;
+int factor_w, factor_h;
+
+w = *ret_w;
+h = *ret_h;
  
  /* Check if it is requested that the result has to be divisible by a some

   * factor (w or h = -n with n being the factor). */
@

Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: add Tiles encode support for HEVC

2019-12-06 Thread linjie fu
Hi,

On Fri, Nov 29, 2019 at 2:42 PM Fu, Linjie  wrote:

> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of
> > Zhong Li
> > Sent: Friday, November 29, 2019 13:13
> > To: FFmpeg development discussions and patches  > de...@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: add Tiles encode support
> > for HEVC
> >
> > Linjie Fu  于2019年11月26日周二 下午12:04写道:
> > >
> > > Add -tile_rows and -tile_cols option to specify the number of tile rows
> > > and columns for ICL+ (gen 11) platform.
> > >
> > > A tile must wholly contain all the slices within it. Slices cannot
> cross
> > > tile boundaries. So the slice number would be implicitly resized to the
> > > max(nSlice, nTile).
> >
> > I would like to the check in the code too, instead of  just commit
> message.
>
> Thanks, code link in MSDK should have been attached too:
>
> https://github.com/Intel-Media-SDK/MediaSDK/blob/5a84af5fa61823a84f32e4b26d864730a927f48c/_studio/mfx_lib/encode_hw/h265/src/mfx_h265_encode_hw_par.cpp#L503
>
> This is merged in:
>
> https://github.com/Intel-Media-SDK/MediaSDK/commit/f8ba11a5b7d61422b117bec2b5b88e4a22bbd294
>
> >
> > > Example:
> > > ffmpeg -v verbose -hwaccel qsv -init_hw_device qsv=hw
> > > -filter_hw_device hw -f rawvideo -s:v 1920x1080 -i ./input.nv12 -vf
> > > format=nv12,hwupload=extra_hw_frames=64 -c:v hevc_qsv -tile_rows 2
> > > -tile_cols 2 -slices 4 -y output.h265
> > >
> > > Also dump the actual quantity of encoded tiled rows and columns in run
> > > time.
> > >
> > > Fix the enhancement #8400.
> > >
> > > Signed-off-by: Linjie Fu 
> > > ---
> > >  libavcodec/qsvenc.c  | 32 +++-
> > >  libavcodec/qsvenc.h  |  7 +++
> > >  libavcodec/qsvenc_hevc.c |  3 +++
> > >  3 files changed, 41 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > > index e176d57..64814fc 100644
> > > --- a/libavcodec/qsvenc.c
> > > +++ b/libavcodec/qsvenc.c
> > > @@ -139,6 +139,9 @@ static void dump_video_param(AVCodecContext
> > *avctx, QSVEncContext *q,
> > >  #if QSV_HAVE_CO3
> > >  mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2];
> > >  #endif
> > > +#if QSV_HAVE_EXT_HEVC_TILES
> > > +mfxExtHEVCTiles *exthevctiles = (mfxExtHEVCTiles *)coding_opts[3 +
> > QSV_HAVE_CO_VPS];
> >
> > Should change QSV_HAVE_CO_VPS to QSV_HAVE_EXT_HEVC_TILES?
>
> There is possibility(MSDK version between 1.13 and 1.17) that MSDK has
> MFX_EXTBUFF_HEVC_TILES buffer but has no MFX_EXT_BUFF_CODING_OPTION_VPS
> buffer.
>
> ext_buffers[]:
> BUF_CO | BUF_CO2 | BUF_CO3 | BUF_VPS | BUF_TILE |...
>
> Hence I'd like to check QSV_HAVE_CO_VPS to get the exact address of
> BUF_TILE
> to dump the truly set values.
>
> >
> > > +#endif
> > >
> > >  av_log(avctx, AV_LOG_VERBOSE, "profile: %s; level: %"PRIu16"\n",
> > > print_profile(info->CodecProfile), info->CodecLevel);
> > > @@ -204,6 +207,12 @@ static void dump_video_param(AVCodecContext
> > *avctx, QSVEncContext *q,
> > >  av_log(avctx, AV_LOG_VERBOSE, "RateDistortionOpt: %s\n",
> > > print_threestate(co->RateDistortionOpt));
> > >
> > > +#if QSV_HAVE_EXT_HEVC_TILES
> > > +if (avctx->codec_id == AV_CODEC_ID_HEVC)
> > > +av_log(avctx, AV_LOG_VERBOSE, "NumTileColumns: %"PRIu16";
> > NumTileRows: %"PRIu16"\n",
> > > +   exthevctiles->NumTileColumns,
> exthevctiles->NumTileRows);
> > > +#endif
> > > +
> > >  #if QSV_HAVE_CO2
> > >  av_log(avctx, AV_LOG_VERBOSE,
> > > "RecoveryPointSEI: %s IntRefType: %"PRIu16";
> > IntRefCycleSize: %"PRIu16"; IntRefQPDelta: %"PRId16"\n",
> > > @@ -771,6 +780,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
> > >  }
> > >  #endif
> > >
> > > +#if QSV_HAVE_EXT_HEVC_TILES
> > > +if (avctx->codec_id == AV_CODEC_ID_HEVC) {
> > > +q->exthevctiles.Header.BufferId = MFX_EXTBUFF_HEVC_TILES;
> > > +q->exthevctiles.Header.BufferSz = sizeof(q->exthevctiles);
> > > +q->exthevctiles.NumTileColumns  = q->tile_cols;
> > > +q->exthevctiles.NumTileRows = q->tile_rows;
> > > +q->extparam_internal[q->nb_extparam_internal++] =
> (mfxExtBuffer
> > *)&q->exthevctiles;
> > > +}
> > > +#endif
> > > +
> > >  if (!check_enc_param(avctx,q)) {
> > >  av_log(avctx, AV_LOG_ERROR,
> > > "some encoding parameters are not supported by the QSV
> "
> > > @@ -887,7 +906,14 @@ static int
> > qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
> > >  };
> > >  #endif
> > >
> > > -mfxExtBuffer *ext_buffers[2 + QSV_HAVE_CO2 + QSV_HAVE_CO3 +
> > QSV_HAVE_CO_VPS];
> > > +#if QSV_HAVE_EXT_HEVC_TILES
> > > +mfxExtHEVCTiles hevc_tile_buf = {
> > > + .Header.BufferId = MFX_EXTBUFF_HEVC_TILES,
> > > + .Header.BufferSz = sizeof(hevc_tile_buf),
> > > +};
> > > +#endif
> > > +
> > > +mfxExtBuffer *ext_buffers[2 + QSV_HAVE_CO2 + QSV_HAVE_CO3 +
> > QSV_HAVE_CO_VPS + QSV_HAVE_EXT_HEVC_TILES];
> > >
> > >

[FFmpeg-devel] [PATCH v1 1/2] avfilter/vsrc_cellauto: fix the print argument mismatch

2019-12-06 Thread lance . lmwang
From: Limin Wang 

Fix CID 1456556

Signed-off-by: Limin Wang 
---
 libavfilter/vsrc_cellauto.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vsrc_cellauto.c b/libavfilter/vsrc_cellauto.c
index c754603..03bdaba 100644
--- a/libavfilter/vsrc_cellauto.c
+++ b/libavfilter/vsrc_cellauto.c
@@ -182,14 +182,17 @@ static av_cold int init(AVFilterContext *ctx)
 } else {
 /* fill the first row randomly */
 int i;
+uint32_t seed;
 
 s->buf = av_mallocz_array(sizeof(uint8_t) * s->w, s->h);
 if (!s->buf)
 return AVERROR(ENOMEM);
 if (s->random_seed == -1)
 s->random_seed = av_get_random_seed();
+seed = s->random_seed;
+av_log(ctx, AV_LOG_VERBOSE, "random seed: 0x%08"PRIx32"\n", seed);
 
-av_lfg_init(&s->lfg, s->random_seed);
+av_lfg_init(&s->lfg, seed);
 
 for (i = 0; i < s->w; i++) {
 double r = (double)av_lfg_get(&s->lfg) / UINT32_MAX;
@@ -199,10 +202,9 @@ static av_cold int init(AVFilterContext *ctx)
 }
 
 av_log(ctx, AV_LOG_VERBOSE,
-   "s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d 
seed:%"PRIu32"\n",
+   "s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d\n",
s->w, s->h, s->frame_rate.num, s->frame_rate.den,
-   s->rule, s->stitch, s->scroll, s->start_full,
-   s->random_seed);
+   s->rule, s->stitch, s->scroll, s->start_full);
 return 0;
 }
 
-- 
2.9.5

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

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

[FFmpeg-devel] [PATCH v1 2/2] avfilter/vsrc_life: fix the print argument mismatch

2019-12-06 Thread lance . lmwang
From: Limin Wang 

Fix CID 1456556

Signed-off-by: Limin Wang 
---
 libavfilter/vsrc_life.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vsrc_life.c b/libavfilter/vsrc_life.c
index 4c0ea73..01b060a 100644
--- a/libavfilter/vsrc_life.c
+++ b/libavfilter/vsrc_life.c
@@ -236,6 +236,7 @@ static av_cold int init(AVFilterContext *ctx)
 if (!life->filename) {
 /* fill the grid randomly */
 int i;
+uint32_t seed;
 
 if (!(life->buf[0] = av_calloc(life->h * life->w, 
sizeof(*life->buf[0]))) ||
 !(life->buf[1] = av_calloc(life->h * life->w, 
sizeof(*life->buf[1] {
@@ -245,8 +246,10 @@ static av_cold int init(AVFilterContext *ctx)
 }
 if (life->random_seed == -1)
 life->random_seed = av_get_random_seed();
+seed = life->random_seed;
+av_log(ctx, AV_LOG_VERBOSE, "random seed: 0x%08"PRIx32"\n", seed);
 
-av_lfg_init(&life->lfg, life->random_seed);
+av_lfg_init(&life->lfg, seed);
 
 for (i = 0; i < life->w * life->h; i++) {
 double r = (double)av_lfg_get(&life->lfg) / UINT32_MAX;
@@ -260,10 +263,9 @@ static av_cold int init(AVFilterContext *ctx)
 }
 
 av_log(ctx, AV_LOG_VERBOSE,
-   "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d 
seed:%"PRIu32"\n",
+   "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d\n",
life->w, life->h, life->frame_rate.num, life->frame_rate.den,
-   life->rule_str, life->stay_rule, life->born_rule, life->stitch,
-   life->random_seed);
+   life->rule_str, life->stay_rule, life->born_rule, life->stitch);
 return 0;
 }
 
-- 
2.9.5

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

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

Re: [FFmpeg-devel] [PATCH] tools/target_dec_fuzzer: set request_channel_layout

2019-12-06 Thread James Almer
On 12/6/2019 8:08 PM, Michael Niedermayer wrote:
> On Fri, Dec 06, 2019 at 11:56:13AM -0300, James Almer wrote:
>> Should increase coverage of some decoders.
>>
>> Signed-off-by: James Almer 
>> ---
>> Passing 6 to av_get_default_channel_layout() will return the 5.1 layout but
>> never 5.1(side), which is for example what the dts decoder actually looks 
>> for.
>> Any suggestion on how to make the fuzzer pick one of the non default layouts
>> using a given amount of channels?
> 
> did you try:
> 
> diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
> index 691a79329f..d53dccdcf5 100644
> --- a/tools/target_dec_fuzzer.c
> +++ b/tools/target_dec_fuzzer.c
> @@ -212,6 +212,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
> size) {
>  ctx->codec_tag  = bytestream2_get_le32(&gbc);
>  keyframes   = bytestream2_get_le64(&gbc);
>  flushpattern= bytestream2_get_le64(&gbc);
> +ctx->request_channel_layout = bytestream2_get_le64(&gbc);

I guess it'll going to get a hit at some point whereas my approach will
not, so LGTM.

>  
>  if (extradata_size < size) {
>  ctx->extradata = av_mallocz(extradata_size + 
> AV_INPUT_BUFFER_PADDING_SIZE);
> 
> 
> 
>>
>>  tools/target_dec_fuzzer.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
>> index dcf47b0f4d..fbfbbbc7ac 100644
>> --- a/tools/target_dec_fuzzer.c
>> +++ b/tools/target_dec_fuzzer.c
>> @@ -47,6 +47,7 @@
>>  
>>  #include "config.h"
>>  #include "libavutil/avassert.h"
>> +#include "libavutil/channel_layout.h"
>>  #include "libavutil/imgutils.h"
>>  #include "libavutil/intreadwrite.h"
>>  
>> @@ -207,6 +208,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
>> size) {
>>  
>>  ctx->sample_rate= 
>> bytestream2_get_le32(&gbc);
>>  ctx->channels   = 
>> (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS;
>> +ctx->request_channel_layout = 
>> av_get_default_channel_layout((unsigned)bytestream2_get_le32(&gbc) % 
>> FF_SANE_NB_CHANNELS);
>>  ctx->block_align= 
>> bytestream2_get_le32(&gbc);
>>  ctx->codec_tag  = 
>> bytestream2_get_le32(&gbc);
>>  keyframes   = 
>> bytestream2_get_le64(&gbc);
> 
> 
> Its better to add reading at the end so as to minimize disruption to existing
> testcases
> 
> Thanks
> 
> [...]
> 
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

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

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

Re: [FFmpeg-devel] [PATCH] tools/target_dec_bsf: call avcodec_flush_buffers() on random keyframes

2019-12-06 Thread James Almer
On 12/6/2019 7:59 PM, Michael Niedermayer wrote:
> On Fri, Dec 06, 2019 at 04:16:23PM -0300, James Almer wrote:
>> This should increase coverage on some decoders by executing flushing code.
>>
>> Signed-off-by: James Almer 
>> ---
>>  tools/target_dec_fuzzer.c | 4 
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
>> index dcf47b0f4d..3c2f9125bb 100644
>> --- a/tools/target_dec_fuzzer.c
>> +++ b/tools/target_dec_fuzzer.c
>> @@ -256,6 +256,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
>> size) {
>>  error("Failed memory allocation");
>>  memcpy(parsepkt.data, last, data - last);
>>  parsepkt.flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + 
>> (!!(keyframes & 2)) * AV_PKT_FLAG_KEY;
>> +int flush = !!(keyframes & 4);
>>  keyframes = (keyframes >> 2) + (keyframes<<62);
>>  data += sizeof(fuzz_tag);
>>  last = data;
>> @@ -289,6 +290,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
>> size) {
>>  av_packet_move_ref(&avpkt, &parsepkt);
>>  }
>>  
>> +  if (avpkt.flags & AV_PKT_FLAG_KEY && flush)
>> +  avcodec_flush_buffers(ctx);
>> +
>>// Iterate through all data
>>while (avpkt.size > 0 && it++ < maxiteration) {
>>  av_frame_unref(frame);
> 
> This would call flush in a pattern locked onto the keyframe and discard flags.
> Not sure if that could affect coverage
> An alternative would be to use a seperate pattern for flush. (see patch below)
> 
> That said, both these patches will disrupt existing test cases
> 
> 
> commit 1a1f747a7afd181f6b763d4dca59cd848e7acb20 (HEAD -> master)
> Author: Michael Niedermayer 
> Date:   Fri Dec 6 23:42:28 2019 +0100
> 
> tools/target_dec_fuzzer: Call avcodec_flush_buffers() in a fuzzer choosen 
> pattern
> 
> This should increase coverage
> 
> Signed-off-by: Michael Niedermayer 
> 
> diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
> index dcf47b0f4d..c11a11514c 100644
> --- a/tools/target_dec_fuzzer.c
> +++ b/tools/target_dec_fuzzer.c
> @@ -110,6 +110,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
> size) {
>const AVPacket *avpkt) = NULL;
>  AVCodecParserContext *parser = NULL;
>  uint64_t keyframes = 0;
> +uint64_t flushpattern = -1;
>  
>  
>  if (!c) {
> @@ -210,6 +211,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
> size) {
>  ctx->block_align= bytestream2_get_le32(&gbc);
>  ctx->codec_tag  = bytestream2_get_le32(&gbc);
>  keyframes   = bytestream2_get_le64(&gbc);
> +flushpattern= bytestream2_get_le64(&gbc);
>  
>  if (extradata_size < size) {
>  ctx->extradata = av_mallocz(extradata_size + 
> AV_INPUT_BUFFER_PADDING_SIZE);
> @@ -289,6 +291,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
> size) {
>  av_packet_move_ref(&avpkt, &parsepkt);
>  }
>  
> +  if (!(flushpattern & 7))
> +  avcodec_flush_buffers(ctx);
> +  flushpattern = (flushpattern >> 3) + (flushpattern<<61);
> +
>// Iterate through all data
>while (avpkt.size > 0 && it++ < maxiteration) {
>  av_frame_unref(frame);

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

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

[FFmpeg-devel] [PATCH 4/6] avformat/matroskadec: Cache whether a track needs to be decoded

2019-12-06 Thread Andreas Rheinhardt
There is no need to recheck this for every frame.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d1a0a07782..a7226ee810 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -249,6 +249,7 @@ typedef struct MatroskaTrack {
 AVStream *stream;
 int64_t end_timecode;
 int ms_compat;
+int needs_decoding;
 uint64_t max_block_additional_id;
 
 uint32_t palette[AVPALETTE_COUNT];
@@ -2385,6 +2386,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
 }
 }
 }
+track->needs_decoding = encodings && !encodings[0].type &&
+encodings[0].scope & 1  &&
+(encodings[0].compression.algo !=
+   MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP ||
+ encodings[0].compression.settings.size);
 
 for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
 if (!strncmp(ff_mkv_codec_tags[j].str, track->codec_id,
@@ -3381,12 +3387,11 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 uint8_t *additional, uint64_t additional_id, 
int additional_size,
 int64_t discard_padding)
 {
-MatroskaTrackEncoding *encodings = track->encodings.elem;
 uint8_t *pkt_data = data;
 int res;
 AVPacket pktl, *pkt = &pktl;
 
-if (encodings && !encodings->type && encodings->scope & 1) {
+if (track->needs_decoding) {
 res = matroska_decode_buffer(&pkt_data, &pkt_size, track);
 if (res < 0)
 return res;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 6/6] avformat/matroskadec: Reindent after previous commit

2019-12-06 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 982dfdec39..5c10862d48 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3250,14 +3250,14 @@ static int matroska_parse_prores(MatroskaTrack *track,
 uint8_t *dst;
 int dstlen = *size + 8;
 
-dst = av_malloc(dstlen + AV_INPUT_BUFFER_PADDING_SIZE);
-if (!dst)
-return AVERROR(ENOMEM);
+dst = av_malloc(dstlen + AV_INPUT_BUFFER_PADDING_SIZE);
+if (!dst)
+return AVERROR(ENOMEM);
 
-AV_WB32(dst, dstlen);
-AV_WB32(dst + 4, MKBETAG('i', 'c', 'p', 'f'));
-memcpy(dst + 8, *data, dstlen - 8);
-memset(dst + dstlen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+AV_WB32(dst, dstlen);
+AV_WB32(dst + 4, MKBETAG('i', 'c', 'p', 'f'));
+memcpy(dst + 8, *data, dstlen - 8);
+memset(dst + dstlen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
 *data = dst;
 *size = dstlen;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 2/6] avformat/matroskadec: Reject SIPR flavor > 3

2019-12-06 Thread Andreas Rheinhardt
rmdec does it, too. And it allows to simplify the check for whether one
should use the Real Audio parsing mode.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 908ad097cb..080a839b6a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2587,6 +2587,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
 track->audio.frame_size  = avio_rb16(&b);
 track->audio.sub_packet_size = avio_rb16(&b);
 if (flavor< 0 ||
+flavor > 3 && codec_id == AV_CODEC_ID_SIPR ||
 track->audio.coded_framesize <= 0 ||
 track->audio.sub_packet_h<= 0 ||
 track->audio.frame_size  <= 0 ||
@@ -2600,7 +2601,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
 st->codecpar->block_align = track->audio.coded_framesize;
 track->codec_priv.size = 0;
 } else {
-if (codec_id == AV_CODEC_ID_SIPR && flavor < 4) {
+if (codec_id == AV_CODEC_ID_SIPR) {
 static const int sipr_bit_rate[4] = { 6504, 8496, 5000, 
16000 };
 track->audio.sub_packet_size = ff_sipr_subpk_size[flavor];
 st->codecpar->bit_rate  = sipr_bit_rate[flavor];
@@ -3593,8 +3594,7 @@ static int matroska_parse_block(MatroskaDemuxContext 
*matroska, AVBufferRef *buf
 for (n = 0; n < laces; n++) {
 int64_t lace_duration = block_duration*(n+1) / laces - 
block_duration*n / laces;
 
-if (track->audio.buf &&
-st->codecpar->block_align && track->audio.sub_packet_size) {
+if (track->audio.buf) {
 res = matroska_parse_rm_audio(matroska, track, st, data,
   lace_size[n],
   timecode, pos);
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: Fix use-after-free when demuxing ProRes

2019-12-06 Thread Andreas Rheinhardt
ProRes in Matroska is supposed to not contain the first atom header
(containing a size field and the tag "icpf") and therefore the Matroska
demuxer has to recreate it; this involves an allocation and copy, of
course. Whether the old buffer (containing the data without the atom
header) needs to be freed or not depends upon whether it is what was
directly read (in which case it is owned by an AVBuffer) or whether it
has been allocated when reversing the track's content compression (e.g.
zlib compression) that Matroska supports.

So there are three pointers involved: The one pointing to the directly
read data (owned by the AVBuffer), the one pointing to the currently
valid data (which coincides with the former if no content compression
needed to be reverted) and the one pointing to the new data with the
first atom header. The check for whether to free the second of these is
simply whether the first two are different.

This works mostly, but there is a complication: Some muxers don't strip
the first atom header away and in this case, it is also not reinserted
and no new buffer is allocated; instead, the second and the third
pointers agree. In this case, one must never free the second buffer.
Yet it is currently done if the track is e.g. zlib compressed.
This commit fixes this.

This is a regression since b8e75a2a.

Signed-off-by: Andreas Rheinhardt 
---
A sample can be easily created by compressing ProRes_FromHaali.mkv
(see https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket3434/) with zlib
with mkvmerge.

 libavformat/matroskadec.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 080a839b6a..d1a0a07782 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3240,11 +3240,8 @@ fail:
 static int matroska_parse_prores(MatroskaTrack *track, uint8_t *src,
  uint8_t **pdst, int *size)
 {
-uint8_t *dst = src;
-int dstlen = *size;
-
-if (AV_RB32(&src[4]) != MKBETAG('i', 'c', 'p', 'f')) {
-dstlen += 8;
+uint8_t *dst;
+int dstlen = *size + 8;
 
 dst = av_malloc(dstlen + AV_INPUT_BUFFER_PADDING_SIZE);
 if (!dst)
@@ -3254,7 +3251,6 @@ static int matroska_parse_prores(MatroskaTrack *track, 
uint8_t *src,
 AV_WB32(dst + 4, MKBETAG('i', 'c', 'p', 'f'));
 memcpy(dst + 8, src, dstlen - 8);
 memset(dst + dstlen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
-}
 
 *pdst = dst;
 *size = dstlen;
@@ -3409,7 +3405,8 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 pkt_data = wv_data;
 }
 
-if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) {
+if (st->codecpar->codec_id == AV_CODEC_ID_PRORES &&
+AV_RB32(pkt_data + 4)  != MKBETAG('i', 'c', 'p', 'f')) {
 uint8_t *pr_data;
 res = matroska_parse_prores(track, pkt_data, &pr_data, &pkt_size);
 if (res < 0) {
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 5/6] avformat/matroskadec: Extend support of ContentCompression to all codecs

2019-12-06 Thread Andreas Rheinhardt
The Matroska demuxer has three functions for creating packets out of the
data read: One for certain Real audio codecs (atrac3, cook, sipr,
ra_288), one for WebVTT (actually, the WebM flavour of it) and one for
all the others. Only the last function supported Matroska's
ContentCompression (i.e. it reversed zlib compression or added the
removed headers to the packets). But in Matroska, all tracks are allowed
to be compressed. This commit adds support for this.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 78 +--
 1 file changed, 43 insertions(+), 35 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index a7226ee810..982dfdec39 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3161,10 +3161,11 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext 
*matroska,
 }
 
 /* reconstruct full wavpack blocks from mangled matroska ones */
-static int matroska_parse_wavpack(MatroskaTrack *track, uint8_t *src,
-  uint8_t **pdst, int *size)
+static int matroska_parse_wavpack(MatroskaTrack *track,
+  uint8_t **data, int *size)
 {
 uint8_t *dst = NULL;
+uint8_t *src = *data;
 int dstlen   = 0;
 int srclen   = *size;
 uint32_t samples;
@@ -3233,7 +3234,7 @@ static int matroska_parse_wavpack(MatroskaTrack *track, 
uint8_t *src,
 
 memset(dst + dstlen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
-*pdst = dst;
+*data = dst;
 *size = dstlen;
 
 return 0;
@@ -3243,8 +3244,8 @@ fail:
 return ret;
 }
 
-static int matroska_parse_prores(MatroskaTrack *track, uint8_t *src,
- uint8_t **pdst, int *size)
+static int matroska_parse_prores(MatroskaTrack *track,
+ uint8_t **data, int *size)
 {
 uint8_t *dst;
 int dstlen = *size + 8;
@@ -3255,10 +3256,10 @@ static int matroska_parse_prores(MatroskaTrack *track, 
uint8_t *src,
 
 AV_WB32(dst, dstlen);
 AV_WB32(dst + 4, MKBETAG('i', 'c', 'p', 'f'));
-memcpy(dst + 8, src, dstlen - 8);
+memcpy(dst + 8, *data, dstlen - 8);
 memset(dst + dstlen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
-*pdst = dst;
+*data = dst;
 *size = dstlen;
 
 return 0;
@@ -3381,51 +3382,43 @@ static int matroska_parse_webvtt(MatroskaDemuxContext 
*matroska,
 
 static int matroska_parse_frame(MatroskaDemuxContext *matroska,
 MatroskaTrack *track, AVStream *st,
-AVBufferRef *buf, uint8_t *data, int pkt_size,
+AVBufferRef *buf, uint8_t **data, int pkt_size,
 uint64_t timecode, uint64_t lace_duration,
 int64_t pos, int is_keyframe,
 uint8_t *additional, uint64_t additional_id, 
int additional_size,
 int64_t discard_padding)
 {
-uint8_t *pkt_data = data;
+uint8_t *pkt_data = *data;
 int res;
 AVPacket pktl, *pkt = &pktl;
 
-if (track->needs_decoding) {
-res = matroska_decode_buffer(&pkt_data, &pkt_size, track);
-if (res < 0)
-return res;
-}
-
 if (st->codecpar->codec_id == AV_CODEC_ID_WAVPACK) {
-uint8_t *wv_data;
-res = matroska_parse_wavpack(track, pkt_data, &wv_data, &pkt_size);
+res = matroska_parse_wavpack(track, &pkt_data, &pkt_size);
 if (res < 0) {
 av_log(matroska->ctx, AV_LOG_ERROR,
"Error parsing a wavpack block.\n");
 goto fail;
 }
-if (pkt_data != data)
-av_freep(&pkt_data);
-pkt_data = wv_data;
+if (!buf)
+av_freep(data);
+buf = NULL;
 }
 
 if (st->codecpar->codec_id == AV_CODEC_ID_PRORES &&
 AV_RB32(pkt_data + 4)  != MKBETAG('i', 'c', 'p', 'f')) {
-uint8_t *pr_data;
-res = matroska_parse_prores(track, pkt_data, &pr_data, &pkt_size);
+res = matroska_parse_prores(track, &pkt_data, &pkt_size);
 if (res < 0) {
 av_log(matroska->ctx, AV_LOG_ERROR,
"Error parsing a prores block.\n");
 goto fail;
 }
-if (pkt_data != data)
-av_freep(&pkt_data);
-pkt_data = pr_data;
+if (!buf)
+av_freep(data);
+buf = NULL;
 }
 
 av_init_packet(pkt);
-if (pkt_data != data)
+if (!buf)
 pkt->buf = av_buffer_create(pkt_data, pkt_size + 
AV_INPUT_BUFFER_PADDING_SIZE,
 NULL, NULL, 0);
 else
@@ -3495,8 +3488,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return 0;
 
 fail:
-if (pkt_data != data)
-av_freep(&pkt_data);
+if (!buf)
+av_freep(data);
 return res;
 }
 
@@ -3595,25 +3588,40 @@ static int matroska_parse_block(MatroskaDemuxContext 
*matroska, AVBufferRef

[FFmpeg-devel] [PATCH 1/6] avformat/matroskadec: Simplify check for real audio

2019-12-06 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 162697ff12..908ad097cb 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3593,10 +3593,7 @@ static int matroska_parse_block(MatroskaDemuxContext 
*matroska, AVBufferRef *buf
 for (n = 0; n < laces; n++) {
 int64_t lace_duration = block_duration*(n+1) / laces - 
block_duration*n / laces;
 
-if ((st->codecpar->codec_id == AV_CODEC_ID_RA_288 ||
- st->codecpar->codec_id == AV_CODEC_ID_COOK   ||
- st->codecpar->codec_id == AV_CODEC_ID_SIPR   ||
- st->codecpar->codec_id == AV_CODEC_ID_ATRAC3) &&
+if (track->audio.buf &&
 st->codecpar->block_align && track->audio.sub_packet_size) {
 res = matroska_parse_rm_audio(matroska, track, st, data,
   lace_size[n],
-- 
2.20.1

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

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

Re: [FFmpeg-devel] [PATCH] tools/target_dec_fuzzer: set request_channel_layout

2019-12-06 Thread Michael Niedermayer
On Fri, Dec 06, 2019 at 11:56:13AM -0300, James Almer wrote:
> Should increase coverage of some decoders.
> 
> Signed-off-by: James Almer 
> ---
> Passing 6 to av_get_default_channel_layout() will return the 5.1 layout but
> never 5.1(side), which is for example what the dts decoder actually looks for.
> Any suggestion on how to make the fuzzer pick one of the non default layouts
> using a given amount of channels?

did you try:

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index 691a79329f..d53dccdcf5 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -212,6 +212,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 ctx->codec_tag  = bytestream2_get_le32(&gbc);
 keyframes   = bytestream2_get_le64(&gbc);
 flushpattern= bytestream2_get_le64(&gbc);
+ctx->request_channel_layout = bytestream2_get_le64(&gbc);
 
 if (extradata_size < size) {
 ctx->extradata = av_mallocz(extradata_size + 
AV_INPUT_BUFFER_PADDING_SIZE);



> 
>  tools/target_dec_fuzzer.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
> index dcf47b0f4d..fbfbbbc7ac 100644
> --- a/tools/target_dec_fuzzer.c
> +++ b/tools/target_dec_fuzzer.c
> @@ -47,6 +47,7 @@
>  
>  #include "config.h"
>  #include "libavutil/avassert.h"
> +#include "libavutil/channel_layout.h"
>  #include "libavutil/imgutils.h"
>  #include "libavutil/intreadwrite.h"
>  
> @@ -207,6 +208,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
> size) {
>  
>  ctx->sample_rate= bytestream2_get_le32(&gbc);
>  ctx->channels   = 
> (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS;
> +ctx->request_channel_layout = 
> av_get_default_channel_layout((unsigned)bytestream2_get_le32(&gbc) % 
> FF_SANE_NB_CHANNELS);
>  ctx->block_align= bytestream2_get_le32(&gbc);
>  ctx->codec_tag  = bytestream2_get_le32(&gbc);
>  keyframes   = bytestream2_get_le64(&gbc);


Its better to add reading at the end so as to minimize disruption to existing
testcases

Thanks

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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus


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

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

Re: [FFmpeg-devel] [PATCH] tools/target_dec_bsf: call avcodec_flush_buffers() on random keyframes

2019-12-06 Thread Michael Niedermayer
On Fri, Dec 06, 2019 at 04:16:23PM -0300, James Almer wrote:
> This should increase coverage on some decoders by executing flushing code.
> 
> Signed-off-by: James Almer 
> ---

>  tools/target_dec_fuzzer.c | 4 

"[PATCH] tools/target_dec_bsf:"

this isnt matching

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

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato


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

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

Re: [FFmpeg-devel] [PATCH] tools/target_dec_bsf: call avcodec_flush_buffers() on random keyframes

2019-12-06 Thread Michael Niedermayer
On Fri, Dec 06, 2019 at 04:16:23PM -0300, James Almer wrote:
> This should increase coverage on some decoders by executing flushing code.
> 
> Signed-off-by: James Almer 
> ---
>  tools/target_dec_fuzzer.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
> index dcf47b0f4d..3c2f9125bb 100644
> --- a/tools/target_dec_fuzzer.c
> +++ b/tools/target_dec_fuzzer.c
> @@ -256,6 +256,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
> size) {
>  error("Failed memory allocation");
>  memcpy(parsepkt.data, last, data - last);
>  parsepkt.flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + 
> (!!(keyframes & 2)) * AV_PKT_FLAG_KEY;
> +int flush = !!(keyframes & 4);
>  keyframes = (keyframes >> 2) + (keyframes<<62);
>  data += sizeof(fuzz_tag);
>  last = data;
> @@ -289,6 +290,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
> size) {
>  av_packet_move_ref(&avpkt, &parsepkt);
>  }
>  
> +  if (avpkt.flags & AV_PKT_FLAG_KEY && flush)
> +  avcodec_flush_buffers(ctx);
> +
>// Iterate through all data
>while (avpkt.size > 0 && it++ < maxiteration) {
>  av_frame_unref(frame);

This would call flush in a pattern locked onto the keyframe and discard flags.
Not sure if that could affect coverage
An alternative would be to use a seperate pattern for flush. (see patch below)

That said, both these patches will disrupt existing test cases


commit 1a1f747a7afd181f6b763d4dca59cd848e7acb20 (HEAD -> master)
Author: Michael Niedermayer 
Date:   Fri Dec 6 23:42:28 2019 +0100

tools/target_dec_fuzzer: Call avcodec_flush_buffers() in a fuzzer choosen 
pattern

This should increase coverage

Signed-off-by: Michael Niedermayer 

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index dcf47b0f4d..c11a11514c 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -110,6 +110,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
   const AVPacket *avpkt) = NULL;
 AVCodecParserContext *parser = NULL;
 uint64_t keyframes = 0;
+uint64_t flushpattern = -1;
 
 
 if (!c) {
@@ -210,6 +211,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 ctx->block_align= bytestream2_get_le32(&gbc);
 ctx->codec_tag  = bytestream2_get_le32(&gbc);
 keyframes   = bytestream2_get_le64(&gbc);
+flushpattern= bytestream2_get_le64(&gbc);
 
 if (extradata_size < size) {
 ctx->extradata = av_mallocz(extradata_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
@@ -289,6 +291,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 av_packet_move_ref(&avpkt, &parsepkt);
 }
 
+  if (!(flushpattern & 7))
+  avcodec_flush_buffers(ctx);
+  flushpattern = (flushpattern >> 3) + (flushpattern<<61);
+
   // Iterate through all data
   while (avpkt.size > 0 && it++ < maxiteration) {
 av_frame_unref(frame);

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.


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

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

[FFmpeg-devel] [PATCH 2/4] avfilter/vf_tinterlace: add support for bypassing already interlaced frames

2019-12-06 Thread Marton Balint
The old interlace filter worked this way before it was merged with tinterlace.

Signed-off-by: Marton Balint 
---
 doc/filters.texi|  6 --
 libavfilter/tinterlace.h|  1 +
 libavfilter/vf_tinterlace.c | 11 +++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 6c14030c8d..673e01ad2f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -18079,10 +18079,12 @@ Enable complex vertical low-pass filtering.
 This will slightly less reduce interlace 'twitter' and Moire
 patterning but better retain detail and subjective sharpness impression.
 
+@item bypass_il
+Bypass already interlaced frames, only adjust the frame rate.
 @end table
 
-Vertical low-pass filtering can only be enabled for @option{mode}
-@var{interleave_top} and @var{interleave_bottom}.
+Vertical low-pass filtering and bypassing already interlaced frames can only be
+enabled for @option{mode} @var{interleave_top} and @var{interleave_bottom}.
 
 @end table
 
diff --git a/libavfilter/tinterlace.h b/libavfilter/tinterlace.h
index e204b61aa0..020887ff34 100644
--- a/libavfilter/tinterlace.h
+++ b/libavfilter/tinterlace.h
@@ -36,6 +36,7 @@
 #define TINTERLACE_FLAG_VLPF 01
 #define TINTERLACE_FLAG_CVLPF 2
 #define TINTERLACE_FLAG_EXACT_TB 4
+#define TINTERLACE_FLAG_BYPASS_IL 8
 
 enum VLPFilter {
 VLPF_OFF = 0,
diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c
index 32b2ff9f5a..0ee40ffce6 100644
--- a/libavfilter/vf_tinterlace.c
+++ b/libavfilter/vf_tinterlace.c
@@ -53,6 +53,7 @@ static const AVOption tinterlace_options[] = {
 {"complex_filter","enable complex vertical low-pass filter",  0, 
AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_CVLPF},INT_MIN, INT_MAX, FLAGS, 
"flags" },
 {"cvlpf", "enable complex vertical low-pass filter",  0, 
AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_CVLPF},INT_MIN, INT_MAX, FLAGS, 
"flags" },
 {"exact_tb",  "force a timebase which can represent timestamps 
exactly", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_EXACT_TB}, INT_MIN, 
INT_MAX, FLAGS, "flags" },
+{"bypass_il", "bypass already interlaced frames", 0, 
AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_BYPASS_IL}, INT_MIN, INT_MAX, FLAGS, 
"flags" },
 
 {NULL}
 };
@@ -439,6 +440,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*picref)
  * halving the frame rate and preserving image height */
 case MODE_INTERLEAVE_TOP:/* topfield first */
 case MODE_INTERLEAVE_BOTTOM: /* bottom field first */
+if ((tinterlace->flags & TINTERLACE_FLAG_BYPASS_IL) && 
cur->interlaced_frame) {
+av_log(ctx, AV_LOG_WARNING,
+   "video is already interlaced, adjusting framerate only\n");
+out = av_frame_clone(cur);
+if (!out)
+return AVERROR(ENOMEM);
+out->pts /= 2;  // adjust pts to new framerate
+ret = ff_filter_frame(outlink, out);
+return ret;
+}
 tff = tinterlace->mode == MODE_INTERLEAVE_TOP;
 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 if (!out)
-- 
2.16.4

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

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

[FFmpeg-devel] [PATCH 1/4] avfilter/vf_interlace: restore lowpass mode constants

2019-12-06 Thread Marton Balint
The documentation still mentions numerical constants in addition to textual
ones. It is also wrong to use distinct modes as flags and it disallows us to
actually use the flags field for real flags in the future.

Signed-off-by: Marton Balint 
---
 libavfilter/tinterlace.h|  7 +++
 libavfilter/vf_tinterlace.c | 13 +
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/libavfilter/tinterlace.h b/libavfilter/tinterlace.h
index 5bcb9a583a..e204b61aa0 100644
--- a/libavfilter/tinterlace.h
+++ b/libavfilter/tinterlace.h
@@ -37,6 +37,12 @@
 #define TINTERLACE_FLAG_CVLPF 2
 #define TINTERLACE_FLAG_EXACT_TB 4
 
+enum VLPFilter {
+VLPF_OFF = 0,
+VLPF_LIN = 1,
+VLPF_CMP = 2,
+};
+
 enum TInterlaceMode {
 MODE_MERGE = 0,
 MODE_DROP_EVEN,
@@ -59,6 +65,7 @@ typedef struct TInterlaceContext {
 int mode;   ///< TInterlaceMode, interlace mode selected
 AVRational preout_time_base;
 int flags;  ///< flags affecting interlacing algorithm
+int lowpass;///< legacy interlace filter lowpass mode
 int frame;  ///< number of the output frame
 int vsub;   ///< chroma vertical subsampling
 AVFrame *cur;
diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c
index fc5d11e053..32b2ff9f5a 100644
--- a/libavfilter/vf_tinterlace.c
+++ b/libavfilter/vf_tinterlace.c
@@ -63,10 +63,10 @@ static const AVOption interlace_options[] = {
{ "scan",  "scanning mode", OFFSET(mode), AV_OPT_TYPE_INT, 
{.i64 = MODE_TFF}, 0, 1, FLAGS, "mode"},
{ "tff",   "top field first",  0, 
AV_OPT_TYPE_CONST, {.i64 = MODE_TFF}, INT_MIN, INT_MAX, FLAGS, .unit = "mode"},
{ "bff",   "bottom field first",   0, 
AV_OPT_TYPE_CONST, {.i64 = MODE_BFF}, INT_MIN, INT_MAX, FLAGS, .unit = "mode"},
-   { "lowpass",   "set vertical low-pass filter", OFFSET(flags), 
AV_OPT_TYPE_FLAGS,   {.i64 = TINTERLACE_FLAG_VLPF}, 0, 2, FLAGS, "flags" },
-   { "off",   "disable vertical low-pass filter", 0, 
AV_OPT_TYPE_CONST, {.i64 = 0}, INT_MIN, INT_MAX, FLAGS, "flags" },
-   { "linear","linear vertical low-pass filter",  0, 
AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, 
"flags" },
-   { "complex",   "complex vertical low-pass filter", 0, 
AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_CVLPF},INT_MIN, INT_MAX, FLAGS, 
"flags" },
+   { "lowpass",   "set vertical low-pass filter", OFFSET(lowpass), 
AV_OPT_TYPE_INT,   {.i64 = VLPF_LIN}, 0, 2, FLAGS, "lowpass" },
+   { "off",   "disable vertical low-pass filter", 0, 
AV_OPT_TYPE_CONST, {.i64 = VLPF_OFF}, INT_MIN, INT_MAX, FLAGS, "lowpass" },
+   { "linear","linear vertical low-pass filter",  0, 
AV_OPT_TYPE_CONST, {.i64 = VLPF_LIN}, INT_MIN, INT_MAX, FLAGS, "lowpass" },
+   { "complex",   "complex vertical low-pass filter", 0, 
AV_OPT_TYPE_CONST, {.i64 = VLPF_CMP}, INT_MIN, INT_MAX, FLAGS, "lowpass" },
 
{ NULL }
 };
@@ -518,6 +518,11 @@ static int init_interlace(AVFilterContext *ctx)
 if (tinterlace->mode <= MODE_BFF)
 tinterlace->mode += MODE_INTERLEAVE_TOP;
 
+if (tinterlace->lowpass == VLPF_LIN)
+tinterlace->flags |= TINTERLACE_FLAG_VLPF;
+if (tinterlace->lowpass == VLPF_CMP)
+tinterlace->flags |= TINTERLACE_FLAG_CVLPF;
+
 return 0;
 }
 
-- 
2.16.4

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

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

[FFmpeg-devel] [PATCH 4/4] avfilter/x86/vf_interlace: always use unaligned movs

2019-12-06 Thread Marton Balint
Fixes crashes in command lines such as:

ffmpeg -f lavfi -i testsrc2=704x576:r=50,interlace,pad=720:576:8 -f null none

Related to ticket #6491.

Signed-off-by: Marton Balint 
---
 libavfilter/x86/vf_interlace.asm | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavfilter/x86/vf_interlace.asm b/libavfilter/x86/vf_interlace.asm
index a6c65b805d..f4a405c754 100644
--- a/libavfilter/x86/vf_interlace.asm
+++ b/libavfilter/x86/vf_interlace.asm
@@ -49,7 +49,7 @@ SECTION .text
 pxor m2, m6, [srcq+hq]
 pavg%1 m0, m2
 pxor m0, m6
-mova [dstq+hq], m0
+movu [dstq+hq], m0
 add hq, mmsize
 jge .end
 
@@ -66,8 +66,8 @@ SECTION .text
 pavg%1 m1, m3
 pxor m0, m6
 pxor m1, m6
-mova [dstq+hq], m0
-mova [dstq+hq+mmsize], m1
+movu [dstq+hq], m0
+movu [dstq+hq+mmsize], m1
 
 add hq, 2*mmsize
 jl .loop
@@ -140,7 +140,7 @@ cglobal lowpass_line_complex, 5, 5, 8, dst, h, src, mref, 
pref
 pand m0, m6
 pandn m6, m1
 por m0, m6
-mova [dstq], m0
+movu [dstq], m0
 
 add dstq, mmsize
 add srcq, mmsize
@@ -201,8 +201,8 @@ cglobal lowpass_line_complex_12, 5, 5, 8, 16, dst, h, src, 
mref, pref, clip_max
 pandn m7, m3
 por m0, m6
 por m1, m7
-mova [dstq], m0
-mova [dstq+mmsize], m1
+movu [dstq], m0
+movu [dstq+mmsize], m1
 
 add dstq, 2*mmsize
 add srcq, 2*mmsize
-- 
2.16.4

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

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

[FFmpeg-devel] [PATCH 3/4] avfilter/vf_interlace: do not interlace already interlaced frames

2019-12-06 Thread Marton Balint
The filter used to work this way before it was merged into tinterlace.

Signed-off-by: Marton Balint 
---
 libavfilter/vf_tinterlace.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c
index 0ee40ffce6..a77753775c 100644
--- a/libavfilter/vf_tinterlace.c
+++ b/libavfilter/vf_tinterlace.c
@@ -529,6 +529,7 @@ static int init_interlace(AVFilterContext *ctx)
 if (tinterlace->mode <= MODE_BFF)
 tinterlace->mode += MODE_INTERLEAVE_TOP;
 
+tinterlace->flags |= TINTERLACE_FLAG_BYPASS_IL;
 if (tinterlace->lowpass == VLPF_LIN)
 tinterlace->flags |= TINTERLACE_FLAG_VLPF;
 if (tinterlace->lowpass == VLPF_CMP)
-- 
2.16.4

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

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

Re: [FFmpeg-devel] [PATCH] lavc/cbs_h265_syntax_template: Fix memleak

2019-12-06 Thread Andriy Gelman
On Fri, 06. Dec 18:01, Andreas Rheinhardt wrote:
> Andriy Gelman:
> > From: Andriy Gelman 
> > 
> > payload_count is used to track the number of SEI payloads. It is also
> > used to free the SEIs in cbs_h265_free_sei().
> > 
> > Currently, payload_count is set after for loop is completed. Hence if
> > there is an error and the function exits, the payload_remains zero
> > causing a memleak.
> > 
> > This commit keeps track of payload_count inside the for loop to fix the
> > issue. Note that that the contents of current are initialized with
> > av_mallocz so there is no need to zero initialize payload_count.
> > 
> > Found-by: libFuzzer
> > Signed-off-by: Andriy Gelman 
> > ---
> >  libavcodec/cbs_h265_syntax_template.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/cbs_h265_syntax_template.c 
> > b/libavcodec/cbs_h265_syntax_template.c
> > index 54570929ec7..57fb2f3aa6a 100644
> > --- a/libavcodec/cbs_h265_syntax_template.c
> > +++ b/libavcodec/cbs_h265_syntax_template.c
> > @@ -2167,6 +2167,7 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
> > RWContext *rw,
> >  uint32_t payload_size = 0;
> >  uint32_t tmp;
> >  
> > +current->payload_count++;
> >  while (show_bits(rw, 8) == 0xff) {
> >  fixed(8, ff_byte, 0xff);
> >  payload_type += 255;
> > @@ -2194,7 +2195,6 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
> > RWContext *rw,
> > "SEI message: found %d.\n", k);
> >  return AVERROR_INVALIDDATA;
> >  }
> > -current->payload_count = k + 1;
> >  #else
> >  for (k = 0; k < current->payload_count; k++) {
> >  PutBitContext start_state;
> > 

> Good catch. But you should only increment payload_count directly
> before CHECK(FUNC(sei_payload)(ctx, rw, ¤t->payload[k], prefix))
> -- there are after all no allocations performed before it.
> And cbs_h264 suffers from the same problem; it should probably be in
> the same commit.
> 

Thanks, I've made the changes and resent.

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

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

Re: [FFmpeg-devel] [PATCH] lavc/cbs_h2645: Fix incorrect max size of nalu unit

2019-12-06 Thread Andriy Gelman
On Fri, 06. Dec 17:47, Andreas Rheinhardt wrote:
> Andriy Gelman:
> > From: Andriy Gelman 
> > 
> > In the worst case the startcode prefix has 4 bytes.
> > 
> > This fixes a trigerred assertion:
> > Assertion dp <= max_size failed at libavcodec/cbs_h2645.c:1451
> > 
> > Found-by:libFuzzer
> > Signed-off-by: Andriy Gelman 
> > ---
> >  libavcodec/cbs_h2645.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> > index 88fa0029cd6..5f71d805848 100644
> > --- a/libavcodec/cbs_h2645.c
> > +++ b/libavcodec/cbs_h2645.c
> > @@ -1395,7 +1395,7 @@ static int 
> > cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
> >  max_size = 0;
> >  for (i = 0; i < frag->nb_units; i++) {
> >  // Start code + content with worst-case emulation prevention.
> > -max_size += 3 + frag->units[i].data_size * 3 / 2;
> > +max_size += 4 + frag->units[i].data_size * 3 / 2;
> >  }
> >  
> >  data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE);
> > 

> LGTM. I presume you used a NAL unit of size 1?

Yes, nal unit size 1 caused the problem.

> 
> (I found this out, too, when I tried (and postponed) to add mp4
> writing support for H.264.)

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

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

[FFmpeg-devel] [PATCH v2] lavc/cbs_h2645_syntax_template: Fix memleak

2019-12-06 Thread Andriy Gelman
From: Andriy Gelman 

payload_count is used to track the number of SEI payloads. It is also
used to free the SEIs in cbs_h264_free_sei()/cbs_h265_free_sei().

Currently, payload_count is set after for loop is completed. Hence if
there is an error and the function exits, the payload remains zero
causing a memleak.

This commit keeps track of payload_count inside the for loop to fix the
issue. Note that that the contents of current are initialized with
av_mallocz() so there is no need to zero initialize payload_count.

Found-by: libFuzzer
Signed-off-by: Andriy Gelman 
---
 libavcodec/cbs_h264_syntax_template.c | 2 +-
 libavcodec/cbs_h265_syntax_template.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index 1671a15d330..878d348b948 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -954,6 +954,7 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext 
*rw,
 current->payload[k].payload_type = payload_type;
 current->payload[k].payload_size = payload_size;
 
+current->payload_count++;
 CHECK(FUNC(sei_payload)(ctx, rw, ¤t->payload[k]));
 
 if (!cbs_h2645_read_more_rbsp_data(rw))
@@ -964,7 +965,6 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext 
*rw,
"SEI message: found %d.\n", k);
 return AVERROR_INVALIDDATA;
 }
-current->payload_count = k + 1;
 #else
 for (k = 0; k < current->payload_count; k++) {
 PutBitContext start_state;
diff --git a/libavcodec/cbs_h265_syntax_template.c 
b/libavcodec/cbs_h265_syntax_template.c
index 54570929ec7..15114548c60 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_syntax_template.c
@@ -2184,6 +2184,7 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
RWContext *rw,
 current->payload[k].payload_type = payload_type;
 current->payload[k].payload_size = payload_size;
 
+current->payload_count++;
 CHECK(FUNC(sei_payload)(ctx, rw, ¤t->payload[k], prefix));
 
 if (!cbs_h2645_read_more_rbsp_data(rw))
@@ -2194,7 +2195,6 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
RWContext *rw,
"SEI message: found %d.\n", k);
 return AVERROR_INVALIDDATA;
 }
-current->payload_count = k + 1;
 #else
 for (k = 0; k < current->payload_count; k++) {
 PutBitContext start_state;
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH] tools/target_dec_bsf: call avcodec_flush_buffers() on random keyframes

2019-12-06 Thread James Almer
This should increase coverage on some decoders by executing flushing code.

Signed-off-by: James Almer 
---
 tools/target_dec_fuzzer.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index dcf47b0f4d..3c2f9125bb 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -256,6 +256,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 error("Failed memory allocation");
 memcpy(parsepkt.data, last, data - last);
 parsepkt.flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes 
& 2)) * AV_PKT_FLAG_KEY;
+int flush = !!(keyframes & 4);
 keyframes = (keyframes >> 2) + (keyframes<<62);
 data += sizeof(fuzz_tag);
 last = data;
@@ -289,6 +290,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 av_packet_move_ref(&avpkt, &parsepkt);
 }
 
+  if (avpkt.flags & AV_PKT_FLAG_KEY && flush)
+  avcodec_flush_buffers(ctx);
+
   // Iterate through all data
   while (avpkt.size > 0 && it++ < maxiteration) {
 av_frame_unref(frame);
-- 
2.24.0

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

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

Re: [FFmpeg-devel] [PATCH] avfilter/scale.c: factorize ff_scale_eval_dimensions

2019-12-06 Thread Michael Niedermayer
On Wed, Dec 04, 2019 at 02:14:35PM +0530, Gyan wrote:
> Will help reduce code duplication when adding animation support to vf_scale.
> See Michael's last comment in https://patchwork.ffmpeg.org/patch/16272/
> 
> Gyan

>  doc/filters.texi |   40 +
>  libavfilter/scale.c  |   59 
> ++-
>  libavfilter/scale.h  |4 ++
>  libavfilter/vf_scale.c   |   28 ++--
>  libavfilter/vf_scale_cuda.c  |   11 
>  libavfilter/vf_scale_npp.c   |   11 
>  libavfilter/vf_scale_vaapi.c |   11 
>  7 files changed, 128 insertions(+), 36 deletions(-)
> 380bf799c14d6286cc625afe019aa553614a7d53  
> 0001-avfilter-scale.c-factorize-ff_scale_eval_dimensions.patch
> From 138a8dba766674a1b017614c58fa99aeca98e9e5 Mon Sep 17 00:00:00 2001
> From: Gyan Doshi 
> Date: Mon, 2 Dec 2019 21:11:21 +0530
> Subject: [PATCH] avfilter/scale.c: factorize ff_scale_eval_dimensions
> 
> Adjustment of evaluated values shifted to ff_adjust_scale_dimensions
> Shifted code for force_original_aspect_ratio and force_divisble_by from
> vf_scale so it is now available for scale_cuda, scale_npp and
> scale_vaapi as well.
> ---
>  doc/filters.texi | 40 
>  libavfilter/scale.c  | 59 +---
>  libavfilter/scale.h  |  4 +++
>  libavfilter/vf_scale.c   | 28 ++---
>  libavfilter/vf_scale_cuda.c  | 11 +++
>  libavfilter/vf_scale_npp.c   | 11 +++
>  libavfilter/vf_scale_vaapi.c | 11 +++
>  7 files changed, 128 insertions(+), 36 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 5fdec6f015..9129f7e3a5 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -16210,6 +16210,46 @@ Supersampling
>  @item lanczos
>  @end table
>  
> +@item force_original_aspect_ratio
> +Enable decreasing or increasing output video width or height if necessary to
> +keep the original aspect ratio. Possible values:
> +
> +@table @samp
> +@item disable
> +Scale the video as specified and disable this feature.
> +
> +@item decrease
> +The output video dimensions will automatically be decreased if needed.
> +
> +@item increase
> +The output video dimensions will automatically be increased if needed.
> +
> +@end table
> +
> +One useful instance of this option is that when you know a specific device's
> +maximum allowed resolution, you can use this to limit the output video to
> +that, while retaining the aspect ratio. For example, device A allows
> +1280x720 playback, and your video is 1920x800. Using this option (set it to
> +decrease) and specifying 1280x720 to the command line makes the output
> +1280x533.
> +
> +Please note that this is a different thing than specifying -1 for @option{w}
> +or @option{h}, you still need to specify the output resolution for this 
> option
> +to work.
> +
> +@item force_divisible_by
> +Ensures that both the output dimensions, width and height, are divisible by 
> the
> +given integer when used together with @option{force_original_aspect_ratio}. 
> This
> +works similar to using @code{-n} in the @option{w} and @option{h} options.
> +
> +This option respects the value set for @option{force_original_aspect_ratio},
> +increasing or decreasing the resolution accordingly. The video's aspect ratio
> +may be slightly modified.
> +
> +This option can be handy if you need to have a video fit within or exceed
> +a defined resolution using @option{force_original_aspect_ratio} but also have
> +encoder restrictions on width or height divisibility.
> +
>  @end table
>  
>  @section scale2ref
> diff --git a/libavfilter/scale.c b/libavfilter/scale.c
> index eaee95fac6..5e9f97230c 100644
> --- a/libavfilter/scale.c
> +++ b/libavfilter/scale.c
> @@ -111,8 +111,6 @@ int ff_scale_eval_dimensions(void *log_ctx,
>  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
>  const AVPixFmtDescriptor *out_desc = 
> av_pix_fmt_desc_get(outlink->format);
>  const char *expr;
> -int w, h;
> -int factor_w, factor_h;
>  int eval_w, eval_h;
>  int ret;
>  const char scale2ref = outlink->src->nb_inputs == 2 && 
> outlink->src->inputs[1] == inlink;
> @@ -172,8 +170,28 @@ int ff_scale_eval_dimensions(void *log_ctx,
>  goto fail;
>  eval_w = (int) res == 0 ? inlink->w : (int) res;
>  
> -w = eval_w;
> -h = eval_h;
> +*ret_w = eval_w;
> +*ret_h = eval_h;
> +
> +return 0;
> +
> +fail:
> +av_log(log_ctx, AV_LOG_ERROR,
> +   "Error when evaluating the expression '%s'.\n"
> +   "Maybe the expression for out_w:'%s' or for out_h:'%s' is 
> self-referencing.\n",
> +   expr, w_expr, h_expr);
> +return ret;
> +}
> +
> +int ff_scale_adjust_dimensions(AVFilterLink *inlink,
> +int *ret_w, int *ret_h,
> +int force_original_aspect_ratio, int force_divisible_by)
> +{
> +int w, h;
> +int factor_w, factor_h;
> +
> + 

Re: [FFmpeg-devel] [PATCH] avfilter/vf_yaepblur: add yaepblur filter

2019-12-06 Thread Paul B Mahol
On 12/5/19, Paul B Mahol  wrote:
> On 12/5/19, Tao Zhang  wrote:
>> Hello everyone,
>> Can I assume this patch is ok if no comments or objections?
>
> Yes, give some time for it to be applied.
> I'm busy with other stuff right now. So this patch LGTM (Note to
> committer to bump minor of libavfiter upon pushing).

I do not get anywhere near output of this filter with either
avgblur/gblur/boxblur?

How should output of this filter look like?

>
>>
>> Tao Zhang  于2019年12月3日周二 下午5:26写道:
>>>
>>> ping:)
>>>
>>> leozhang  于2019年11月25日周一 下午5:53写道:
>>> >
>>> > Signed-off-by: leozhang 
>>> > ---
>>> > This filter blur the input while preserving edges, with slice threads
>>> > speed up.
>>> > My test speed is about 100fps on 1080p video with 16 threads, on my
>>> > test
>>> > machine whose cpu is E5-2660 v4 2.0GHz using 16 threads.
>>> > I gauss that i7-9700K 3.6GHz can run faster more.
>>> > The test command is
>>> > ffmpeg -s 1920x1080 -r 30 -i your_test_file.yuv -filter_threads 16 -vf
>>> > yaepblur -f null -
>>> >
>>> >  doc/filters.texi  |  22 +++
>>> >  libavfilter/Makefile  |   1 +
>>> >  libavfilter/allfilters.c  |   1 +
>>> >  libavfilter/vf_yaepblur.c | 349
>>> > ++
>>> >  4 files changed, 373 insertions(+)
>>> >  create mode 100644 libavfilter/vf_yaepblur.c
>>> >
>>> > diff --git a/doc/filters.texi b/doc/filters.texi
>>> > index c04421b..61e93d5 100644
>>> > --- a/doc/filters.texi
>>> > +++ b/doc/filters.texi
>>> > @@ -19775,6 +19775,28 @@ Only deinterlace frames marked as interlaced.
>>> >  The default value is @code{all}.
>>> >  @end table
>>> >
>>> > +@section yaepblur
>>> > +
>>> > +Apply blur filter while preserving edges ("yaepblur" means "yet
>>> > another
>>> > edge preserving blur filter").
>>> > +The algorithm is described in
>>> > +"J. S. Lee, Digital image enhancement and noise filtering by use of
>>> > local statistics, IEEE Trans. Pattern Anal. Mach. Intell. PAMI-2,
>>> > 1980."
>>> > +
>>> > +It accepts the following parameters:
>>> > +
>>> > +@table @option
>>> > +@item radius, r
>>> > +Set the window radius. Default value is 3.
>>> > +
>>> > +@item planes, p
>>> > +Set which planes to filter. Default is only the first plane.
>>> > +
>>> > +@item sigma, s
>>> > +Set blur strength. Default value is 128.
>>> > +@end table
>>> > +
>>> > +@subsection Commands
>>> > +This filter supports same @ref{commands} as options.
>>> > +
>>> >  @section zoompan
>>> >
>>> >  Apply Zoom & Pan effect.
>>> > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
>>> > index 6838d5c..b490a44 100644
>>> > --- a/libavfilter/Makefile
>>> > +++ b/libavfilter/Makefile
>>> > @@ -442,6 +442,7 @@ OBJS-$(CONFIG_XSTACK_FILTER) +=
>>> > vf_stack.o framesync.o
>>> >  OBJS-$(CONFIG_YADIF_FILTER)  += vf_yadif.o
>>> > yadif_common.o
>>> >  OBJS-$(CONFIG_YADIF_CUDA_FILTER) += vf_yadif_cuda.o
>>> > vf_yadif_cuda.ptx.o \
>>> >  yadif_common.o
>>> > +OBJS-$(CONFIG_YAEPBLUR_FILTER)   += vf_yaepblur.o
>>> >  OBJS-$(CONFIG_ZMQ_FILTER)+= f_zmq.o
>>> >  OBJS-$(CONFIG_ZOOMPAN_FILTER)+= vf_zoompan.o
>>> >  OBJS-$(CONFIG_ZSCALE_FILTER) += vf_zscale.o
>>> > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
>>> > index 7c1e19e..8f41186 100644
>>> > --- a/libavfilter/allfilters.c
>>> > +++ b/libavfilter/allfilters.c
>>> > @@ -420,6 +420,7 @@ extern AVFilter ff_vf_xmedian;
>>> >  extern AVFilter ff_vf_xstack;
>>> >  extern AVFilter ff_vf_yadif;
>>> >  extern AVFilter ff_vf_yadif_cuda;
>>> > +extern AVFilter ff_vf_yaepblur;
>>> >  extern AVFilter ff_vf_zmq;
>>> >  extern AVFilter ff_vf_zoompan;
>>> >  extern AVFilter ff_vf_zscale;
>>> > diff --git a/libavfilter/vf_yaepblur.c b/libavfilter/vf_yaepblur.c
>>> > new file mode 100644
>>> > index 000..ef6fbc9
>>> > --- /dev/null
>>> > +++ b/libavfilter/vf_yaepblur.c
>>> > @@ -0,0 +1,349 @@
>>> > +/*
>>> > + * Copyright (C) 2019 Leo Zhang 
>>> > +
>>> > + * This file is part of FFmpeg.
>>> > + *
>>> > + * FFmpeg is free software; you can redistribute it and/or
>>> > + * modify it under the terms of the GNU Lesser General Public
>>> > + * License as published by the Free Software Foundation; either
>>> > + * version 2.1 of the License, or (at your option) any later version.
>>> > + *
>>> > + * FFmpeg is distributed in the hope that it will be useful,
>>> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> > + * Lesser General Public License for more details.
>>> > + *
>>> > + * You should have received a copy of the GNU Lesser General Public
>>> > + * License along with FFmpeg; if not, write to the Free Software
>>> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>>> > 02110-1301 USA
>>> > + */
>>> > +
>>> > +/**
>>> > + * @file
>>> > + * yaep(yet another 

Re: [FFmpeg-devel] [PATCH] lavc/cbs_h2645: Fix incorrect max size of nalu unit

2019-12-06 Thread James Almer
On 12/6/2019 2:47 PM, Andreas Rheinhardt wrote:
> Andriy Gelman:
>> From: Andriy Gelman 
>>
>> In the worst case the startcode prefix has 4 bytes.
>>
>> This fixes a trigerred assertion:
>> Assertion dp <= max_size failed at libavcodec/cbs_h2645.c:1451
>>
>> Found-by:libFuzzer
>> Signed-off-by: Andriy Gelman 
>> ---
>>  libavcodec/cbs_h2645.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>> index 88fa0029cd6..5f71d805848 100644
>> --- a/libavcodec/cbs_h2645.c
>> +++ b/libavcodec/cbs_h2645.c
>> @@ -1395,7 +1395,7 @@ static int 
>> cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
>>  max_size = 0;
>>  for (i = 0; i < frag->nb_units; i++) {
>>  // Start code + content with worst-case emulation prevention.
>> -max_size += 3 + frag->units[i].data_size * 3 / 2;
>> +max_size += 4 + frag->units[i].data_size * 3 / 2;
>>  }
>>  
>>  data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE);
>>
> LGTM. I presume you used a NAL unit of size 1?

Pushed then. Thanks.

> 
> (I found this out, too, when I tried (and postponed) to add mp4
> writing support for H.264.)
> 
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

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

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

Re: [FFmpeg-devel] [PATCH] lavc/cbs_h265_syntax_template: Fix memleak

2019-12-06 Thread Andreas Rheinhardt
Andriy Gelman:
> From: Andriy Gelman 
> 
> payload_count is used to track the number of SEI payloads. It is also
> used to free the SEIs in cbs_h265_free_sei().
> 
> Currently, payload_count is set after for loop is completed. Hence if
> there is an error and the function exits, the payload_remains zero
> causing a memleak.
> 
> This commit keeps track of payload_count inside the for loop to fix the
> issue. Note that that the contents of current are initialized with
> av_mallocz so there is no need to zero initialize payload_count.
> 
> Found-by: libFuzzer
> Signed-off-by: Andriy Gelman 
> ---
>  libavcodec/cbs_h265_syntax_template.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/cbs_h265_syntax_template.c 
> b/libavcodec/cbs_h265_syntax_template.c
> index 54570929ec7..57fb2f3aa6a 100644
> --- a/libavcodec/cbs_h265_syntax_template.c
> +++ b/libavcodec/cbs_h265_syntax_template.c
> @@ -2167,6 +2167,7 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
> RWContext *rw,
>  uint32_t payload_size = 0;
>  uint32_t tmp;
>  
> +current->payload_count++;
>  while (show_bits(rw, 8) == 0xff) {
>  fixed(8, ff_byte, 0xff);
>  payload_type += 255;
> @@ -2194,7 +2195,6 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
> RWContext *rw,
> "SEI message: found %d.\n", k);
>  return AVERROR_INVALIDDATA;
>  }
> -current->payload_count = k + 1;
>  #else
>  for (k = 0; k < current->payload_count; k++) {
>  PutBitContext start_state;
> 
Good catch. But you should only increment payload_count directly
before CHECK(FUNC(sei_payload)(ctx, rw, ¤t->payload[k], prefix))
-- there are after all no allocations performed before it.
And cbs_h264 suffers from the same problem; it should probably be in
the same commit.

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

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

Re: [FFmpeg-devel] [PATCH] lavc/cbs_h2645: Fix incorrect max size of nalu unit

2019-12-06 Thread Andreas Rheinhardt
Andriy Gelman:
> From: Andriy Gelman 
> 
> In the worst case the startcode prefix has 4 bytes.
> 
> This fixes a trigerred assertion:
> Assertion dp <= max_size failed at libavcodec/cbs_h2645.c:1451
> 
> Found-by:libFuzzer
> Signed-off-by: Andriy Gelman 
> ---
>  libavcodec/cbs_h2645.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 88fa0029cd6..5f71d805848 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1395,7 +1395,7 @@ static int 
> cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
>  max_size = 0;
>  for (i = 0; i < frag->nb_units; i++) {
>  // Start code + content with worst-case emulation prevention.
> -max_size += 3 + frag->units[i].data_size * 3 / 2;
> +max_size += 4 + frag->units[i].data_size * 3 / 2;
>  }
>  
>  data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE);
> 
LGTM. I presume you used a NAL unit of size 1?

(I found this out, too, when I tried (and postponed) to add mp4
writing support for H.264.)

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

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

[FFmpeg-devel] [PATCH] lavc/cbs_h265_syntax_template: Fix memleak

2019-12-06 Thread Andriy Gelman
From: Andriy Gelman 

payload_count is used to track the number of SEI payloads. It is also
used to free the SEIs in cbs_h265_free_sei().

Currently, payload_count is set after for loop is completed. Hence if
there is an error and the function exits, the payload_remains zero
causing a memleak.

This commit keeps track of payload_count inside the for loop to fix the
issue. Note that that the contents of current are initialized with
av_mallocz so there is no need to zero initialize payload_count.

Found-by: libFuzzer
Signed-off-by: Andriy Gelman 
---
 libavcodec/cbs_h265_syntax_template.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/cbs_h265_syntax_template.c 
b/libavcodec/cbs_h265_syntax_template.c
index 54570929ec7..57fb2f3aa6a 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_syntax_template.c
@@ -2167,6 +2167,7 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
RWContext *rw,
 uint32_t payload_size = 0;
 uint32_t tmp;
 
+current->payload_count++;
 while (show_bits(rw, 8) == 0xff) {
 fixed(8, ff_byte, 0xff);
 payload_type += 255;
@@ -2194,7 +2195,6 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
RWContext *rw,
"SEI message: found %d.\n", k);
 return AVERROR_INVALIDDATA;
 }
-current->payload_count = k + 1;
 #else
 for (k = 0; k < current->payload_count; k++) {
 PutBitContext start_state;
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH v2] avfilter/formats: optimize ff_all_formats

2019-12-06 Thread Zhao Zhili
This is a micro-optimization. Saving almost 200 reallocations makes it
worth a try.
---
fix commit message typo: relocations -> reallocations

 libavfilter/formats.c | 35 +--
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 33c64668a0..1af7a1cedd 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -348,23 +348,30 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, 
uint64_t channel_layout)
 
 AVFilterFormats *ff_all_formats(enum AVMediaType type)
 {
-AVFilterFormats *ret = NULL;
+AVFilterFormats *ret;
+int i, count;
 
-if (type == AVMEDIA_TYPE_VIDEO) {
-const AVPixFmtDescriptor *desc = NULL;
-while ((desc = av_pix_fmt_desc_next(desc))) {
-if (ff_add_format(&ret, av_pix_fmt_desc_get_id(desc)) < 0)
-return NULL;
-}
-} else if (type == AVMEDIA_TYPE_AUDIO) {
-enum AVSampleFormat fmt = 0;
-while (av_get_sample_fmt_name(fmt)) {
-if (ff_add_format(&ret, fmt) < 0)
-return NULL;
-fmt++;
-}
+if (type == AVMEDIA_TYPE_VIDEO)
+count = AV_PIX_FMT_NB;
+else if (type == AVMEDIA_TYPE_AUDIO)
+count = AV_SAMPLE_FMT_NB;
+else
+return NULL;
+
+ret = av_mallocz(sizeof(*ret));
+if (!ret)
+return NULL;
+
+ret->nb_formats = count;
+ret->formats = av_malloc_array(count, sizeof(*ret->formats));
+if (!ret->formats) {
+av_free(ret);
+return NULL;
 }
 
+for (i = 0; i < count; i++)
+ret->formats[i] = i;
+
 return ret;
 }
 
-- 
2.24.0



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

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

[FFmpeg-devel] [PATCH] avfilter/formats: optimize ff_all_formats

2019-12-06 Thread Zhao Zhili
This is a micro-optimization. Saving almost 200 relocations makes it
worth a try.
---
Can lavf depends on the sequential properties of AVPixelFormat and
AVSampleFormat? Or should limited to pixdesc.h/samplefmt.h API?

 libavfilter/formats.c | 35 +--
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 33c64668a0..1af7a1cedd 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -348,23 +348,30 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, 
uint64_t channel_layout)
 
 AVFilterFormats *ff_all_formats(enum AVMediaType type)
 {
-AVFilterFormats *ret = NULL;
+AVFilterFormats *ret;
+int i, count;
 
-if (type == AVMEDIA_TYPE_VIDEO) {
-const AVPixFmtDescriptor *desc = NULL;
-while ((desc = av_pix_fmt_desc_next(desc))) {
-if (ff_add_format(&ret, av_pix_fmt_desc_get_id(desc)) < 0)
-return NULL;
-}
-} else if (type == AVMEDIA_TYPE_AUDIO) {
-enum AVSampleFormat fmt = 0;
-while (av_get_sample_fmt_name(fmt)) {
-if (ff_add_format(&ret, fmt) < 0)
-return NULL;
-fmt++;
-}
+if (type == AVMEDIA_TYPE_VIDEO)
+count = AV_PIX_FMT_NB;
+else if (type == AVMEDIA_TYPE_AUDIO)
+count = AV_SAMPLE_FMT_NB;
+else
+return NULL;
+
+ret = av_mallocz(sizeof(*ret));
+if (!ret)
+return NULL;
+
+ret->nb_formats = count;
+ret->formats = av_malloc_array(count, sizeof(*ret->formats));
+if (!ret->formats) {
+av_free(ret);
+return NULL;
 }
 
+for (i = 0; i < count; i++)
+ret->formats[i] = i;
+
 return ret;
 }
 
-- 
2.24.0



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

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

Re: [FFmpeg-devel] [PATCH] avfilter/scale.c: factorize ff_scale_eval_dimensions

2019-12-06 Thread Gyan



On 04-12-2019 02:14 pm, Gyan wrote:
Will help reduce code duplication when adding animation support to 
vf_scale.

See Michael's last comment in https://patchwork.ffmpeg.org/patch/16272/


Ping.

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

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

[FFmpeg-devel] [PATCH 2/3] avfilter/vf_geq: Add NB_PLANES

2019-12-06 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavfilter/vf_geq.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_geq.c b/libavfilter/vf_geq.c
index e3267e331f..c965204a1c 100644
--- a/libavfilter/vf_geq.c
+++ b/libavfilter/vf_geq.c
@@ -33,6 +33,8 @@
 #include "libavutil/pixdesc.h"
 #include "internal.h"
 
+#define NB_PLANES 4
+
 enum InterpolationMethods {
 INTERP_NEAREST,
 INTERP_BILINEAR,
@@ -44,7 +46,7 @@ enum   { VAR_X, VAR_Y, VAR_W, 
VAR_H, VAR_N, VAR_
 
 typedef struct GEQContext {
 const AVClass *class;
-AVExpr *e[4];   ///< expressions for each plane
+AVExpr *e[NB_PLANES];   ///< expressions for each plane
 char *expr_str[4+3];///< expression strings for each plane
 AVFrame *picref;///< current input buffer
 uint8_t *dst;   ///< reference pointer to the 8bits output
@@ -188,7 +190,7 @@ static av_cold int geq_init(AVFilterContext *ctx)
 goto end;
 }
 
-for (plane = 0; plane < 4; plane++) {
+for (plane = 0; plane < NB_PLANES; plane++) {
 static double (*p[])(void *, double, double) = { lum, cb, cr, alpha };
 static const char *const func2_yuv_names[]= { "lum", "cb", "cr", 
"alpha", "p", NULL };
 static const char *const func2_rgb_names[]= { "g", "b", "r", 
"alpha", "p", NULL };
-- 
2.23.0

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

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

[FFmpeg-devel] [PATCH 3/3] avfilter/vf_geq: Add support for reading sample sums and means of rectangles

2019-12-06 Thread Michael Niedermayer
This allows integrating box blur style filters in geq.

Without this computing the mean of an area in geq would have been excessivly 
slow

Signed-off-by: Michael Niedermayer 
---
 libavfilter/vf_geq.c | 107 +--
 1 file changed, 103 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_geq.c b/libavfilter/vf_geq.c
index c965204a1c..f722f422c5 100644
--- a/libavfilter/vf_geq.c
+++ b/libavfilter/vf_geq.c
@@ -57,6 +57,9 @@ typedef struct GEQContext {
 int interpolation;
 int is_rgb;
 int bps;
+
+double *pixel_sums[NB_PLANES];
+int needs_sum[NB_PLANES];
 } GEQContext;
 
 enum { Y = 0, U, V, A, G, B, R };
@@ -135,6 +138,76 @@ static inline double getpix(void *priv, double x, double 
y, int plane)
 }
 }
 
+static int calculate_sums(GEQContext *geq, int plane, int w, int h)
+{
+int xi, yi;
+AVFrame *picref = geq->picref;
+const uint8_t *src = picref->data[plane];
+int linesize = picref->linesize[plane];
+
+if (!geq->pixel_sums[plane])
+geq->pixel_sums[plane] = av_malloc_array(w, h * sizeof 
(*geq->pixel_sums[plane]));
+if (!geq->pixel_sums[plane])
+return AVERROR(ENOMEM);
+if (geq->bps > 8)
+linesize /= 2;
+for (yi = 0; yi < h; yi ++) {
+if (geq->bps > 8) {
+const uint16_t *src16 = (const uint16_t*)src;
+double linesum = 0;
+
+for (xi = 0; xi < w; xi ++) {
+linesum += src16[xi + yi * linesize];
+geq->pixel_sums[plane][xi + yi * w] = linesum;
+}
+} else {
+double linesum = 0;
+
+for (xi = 0; xi < w; xi ++) {
+linesum += src[xi + yi * linesize];
+geq->pixel_sums[plane][xi + yi * w] = linesum;
+}
+}
+if (yi)
+for (xi = 0; xi < w; xi ++) {
+geq->pixel_sums[plane][xi + yi * w] += 
geq->pixel_sums[plane][xi + yi * w - w];
+}
+}
+return 0;
+}
+
+static inline double getpix_integrate_internal(GEQContext *geq, int x, int y, 
int plane, int w, int h)
+{
+if (x > w - 1) {
+double boundary =   getpix_integrate_internal(geq, w - 1, y, plane, w, 
h);
+return 2*boundary - getpix_integrate_internal(geq, 2*(w - 1) - x, y, 
plane, w, h);
+} else if (y > h - 1) {
+double boundary =   getpix_integrate_internal(geq, x, h - 1, plane, w, 
h);
+return 2*boundary - getpix_integrate_internal(geq, x, 2*(h - 1) - y, 
plane, w, h);
+} else if (x < 0) {
+if (x == -1) return 0;
+return - getpix_integrate_internal(geq, -x-2, y, plane, w, h);
+} else if (y < 0) {
+if (y == -1) return 0;
+return - getpix_integrate_internal(geq, x, -y-2, plane, w, h);
+}
+
+return geq->pixel_sums[plane][x + y * w];
+}
+
+static inline double getpix_integrate(void *priv, double x, double y, int 
plane) {
+GEQContext *geq = priv;
+AVFrame *picref = geq->picref;
+const uint8_t *src = picref->data[plane];
+const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width,  
geq->hsub) : picref->width;
+const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, 
geq->vsub) : picref->height;
+
+if (!src)
+return 0;
+
+return getpix_integrate_internal(geq, lrint(av_clipd(x, -w, 2*w)), 
lrint(av_clipd(y, -h, 2*h)), plane, w, h);
+}
+
 //TODO: cubic interpolate
 //TODO: keep the last few frames
 static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 
0); }
@@ -142,6 +215,11 @@ static double  cb(void *priv, double x, double y) { return 
getpix(priv, x, y, 1)
 static double  cr(void *priv, double x, double y) { return getpix(priv, x, y, 
2); }
 static double alpha(void *priv, double x, double y) { return getpix(priv, x, 
y, 3); }
 
+static double   lumsum(void *priv, double x, double y) { return 
getpix_integrate(priv, x, y, 0); }
+static doublecbsum(void *priv, double x, double y) { return 
getpix_integrate(priv, x, y, 1); }
+static doublecrsub(void *priv, double x, double y) { return 
getpix_integrate(priv, x, y, 2); }
+static double alphasum(void *priv, double x, double y) { return 
getpix_integrate(priv, x, y, 3); }
+
 static av_cold int geq_init(AVFilterContext *ctx)
 {
 GEQContext *geq = ctx->priv;
@@ -191,16 +269,32 @@ static av_cold int geq_init(AVFilterContext *ctx)
 }
 
 for (plane = 0; plane < NB_PLANES; plane++) {
-static double (*p[])(void *, double, double) = { lum, cb, cr, alpha };
-static const char *const func2_yuv_names[]= { "lum", "cb", "cr", 
"alpha", "p", NULL };
-static const char *const func2_rgb_names[]= { "g", "b", "r", 
"alpha", "p", NULL };
+static double (*p[])(void *, double, double) = {
+lum   , cb   , cr   , alpha   ,
+lumsum, cbsum, crsub, alphasum,
+};
+static const char *const func2_yuv_names[]= {
+"lum"   , "cb"   ,

[FFmpeg-devel] [PATCH 1/3] avutil/eval: Add av_expr_count_func() similar to av_expr_count_vars()

2019-12-06 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavutil/eval.c | 28 
 libavutil/eval.h | 11 +++
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/libavutil/eval.c b/libavutil/eval.c
index 62d2ae938b..d527f6a9d0 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -166,8 +166,8 @@ struct AVExpr {
 e_sgn,
 } type;
 double value; // is sign in other types
+int const_index;
 union {
-int const_index;
 double (*func0)(double);
 double (*func1)(void *, double);
 double (*func2)(void *, double, double);
@@ -185,7 +185,7 @@ static double eval_expr(Parser *p, AVExpr *e)
 {
 switch (e->type) {
 case e_value:  return e->value;
-case e_const:  return e->value * p->const_values[e->a.const_index];
+case e_const:  return e->value * p->const_values[e->const_index];
 case e_func0:  return e->value * e->a.func0(eval_expr(p, e->param[0]));
 case e_func1:  return e->value * e->a.func1(p->opaque, eval_expr(p, 
e->param[0]));
 case e_func2:  return e->value * e->a.func2(p->opaque, eval_expr(p, 
e->param[0]), eval_expr(p, e->param[1]));
@@ -367,7 +367,7 @@ static int parse_primary(AVExpr **e, Parser *p)
 if (strmatch(p->s, p->const_names[i])) {
 p->s+= strlen(p->const_names[i]);
 d->type = e_const;
-d->a.const_index = i;
+d->const_index = i;
 *e = d;
 return 0;
 }
@@ -478,6 +478,7 @@ static int parse_primary(AVExpr **e, Parser *p)
 if (strmatch(next, p->func1_names[i])) {
 d->a.func1 = p->funcs1[i];
 d->type = e_func1;
+d->const_index = i;
 *e = d;
 return 0;
 }
@@ -487,6 +488,7 @@ static int parse_primary(AVExpr **e, Parser *p)
 if (strmatch(next, p->func2_names[i])) {
 d->a.func2 = p->funcs2[i];
 d->type = e_func2;
+d->const_index = i;
 *e = d;
 return 0;
 }
@@ -735,22 +737,32 @@ end:
 return ret;
 }
 
-int av_expr_count_vars(AVExpr *e, unsigned *counter, int size)
+static int expr_count(AVExpr *e, unsigned *counter, int size, int type)
 {
 int i;
 
 if (!e || !counter || !size)
 return AVERROR(EINVAL);
 
-for (i = 0; e->type != e_const && i < 3 && e->param[i]; i++)
-av_expr_count_vars(e->param[i], counter, size);
+for (i = 0; e->type != type && i < 3 && e->param[i]; i++)
+expr_count(e->param[i], counter, size, type);
 
-if (e->type == e_const && e->a.const_index < size)
-counter[e->a.const_index]++;
+if (e->type == type && e->const_index < size)
+counter[e->const_index]++;
 
 return 0;
 }
 
+int av_expr_count_vars(AVExpr *e, unsigned *counter, int size)
+{
+return expr_count(e, counter, size, e_const);
+}
+
+int av_expr_count_func(AVExpr *e, unsigned *counter, int size, int arg)
+{
+return expr_count(e, counter, size, ((int[]){e_const, e_func1, 
e_func2})[arg]);
+}
+
 double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
 {
 Parser p = { 0 };
diff --git a/libavutil/eval.h b/libavutil/eval.h
index 9bdb10cca2..688c523fbe 100644
--- a/libavutil/eval.h
+++ b/libavutil/eval.h
@@ -96,6 +96,17 @@ double av_expr_eval(AVExpr *e, const double *const_values, 
void *opaque);
  */
 int av_expr_count_vars(AVExpr *e, unsigned *counter, int size);
 
+/**
+ * Track the presence of functions and their number of occurrences in a parsed 
expression
+ *
+ * @param counter a zero-initialized array where the count of each function 
will be stored
+ * @param size size of array
+ * @param arg number of arguments the counted functions have
+ * @return 0 on success, a negative value indicates that no expression or 
array was passed
+ * or size was zero
+ */
+int av_expr_count_func(AVExpr *e, unsigned *counter, int size, int arg);
+
 /**
  * Free a parsed expression previously created with av_expr_parse().
  */
-- 
2.23.0

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

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

[FFmpeg-devel] [PATCH] lavc/cbs_h2645: Fix incorrect max size of nalu unit

2019-12-06 Thread Andriy Gelman
From: Andriy Gelman 

In the worst case the startcode prefix has 4 bytes.

This fixes a trigerred assertion:
Assertion dp <= max_size failed at libavcodec/cbs_h2645.c:1451

Found-by:libFuzzer
Signed-off-by: Andriy Gelman 
---
 libavcodec/cbs_h2645.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 88fa0029cd6..5f71d805848 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1395,7 +1395,7 @@ static int 
cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
 max_size = 0;
 for (i = 0; i < frag->nb_units; i++) {
 // Start code + content with worst-case emulation prevention.
-max_size += 3 + frag->units[i].data_size * 3 / 2;
+max_size += 4 + frag->units[i].data_size * 3 / 2;
 }
 
 data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE);
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH] tools/target_dec_fuzzer: set request_channel_layout

2019-12-06 Thread James Almer
Should increase coverage of some decoders.

Signed-off-by: James Almer 
---
Passing 6 to av_get_default_channel_layout() will return the 5.1 layout but
never 5.1(side), which is for example what the dts decoder actually looks for.
Any suggestion on how to make the fuzzer pick one of the non default layouts
using a given amount of channels?

 tools/target_dec_fuzzer.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index dcf47b0f4d..fbfbbbc7ac 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -47,6 +47,7 @@
 
 #include "config.h"
 #include "libavutil/avassert.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
 
@@ -207,6 +208,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 
 ctx->sample_rate= bytestream2_get_le32(&gbc);
 ctx->channels   = 
(unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS;
+ctx->request_channel_layout = 
av_get_default_channel_layout((unsigned)bytestream2_get_le32(&gbc) % 
FF_SANE_NB_CHANNELS);
 ctx->block_align= bytestream2_get_le32(&gbc);
 ctx->codec_tag  = bytestream2_get_le32(&gbc);
 keyframes   = bytestream2_get_le64(&gbc);
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH v3 2/2] lavc/hevc_mp4toannexb: Exit earlier if there is no nalu payload remaining

2019-12-06 Thread Andriy Gelman
From: Andriy Gelman 

Since the nal unit payload is located after the length prefix, there is
no reason to continue reading if there is no nal unit payload remaining.
---
 libavcodec/hevc_mp4toannexb_bsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index f1e1a45abd1..3ed527d8ac0 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -136,7 +136,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 
 bytestream2_init(&gb, in->data, in->size);
 
-while (bytestream2_get_bytes_left(&gb)) {
+while (bytestream2_get_bytes_left(&gb) > s->length_size) {
 uint32_t nalu_size = 0;
 int  nalu_type;
 int is_irap, add_extradata, extra_size, prev_size;
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH v3 1/2] lavc/hevc_mp4toannexb: Fix integer overflow

2019-12-06 Thread Andriy Gelman
From: Andriy Gelman 

Fixes a check where the grow_by packet size cannot exceed INT_MAX.

Although the complete heap allocation check should ensure that
(uint64_t)nalu_size + extra_size + 4 + out->size + AV_INPUT_BUFFER_PADDING_SIZE 
<= INT_MAX,

it suffices to only check that the grow_by size does exceed INT_MAX. The
final memory check is done internally in av_packet_grow(). This approach
means that no casts to uint64_t are needed.

Also, note that extra_size < INT_MAX - 4, because from 
hevc_extradata_to_annexb():
extra_size <= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE.

Found with libFuzzer:
4294967044 cannot be represented as int.

Signed-off-by: Andriy Gelman 
---
 libavcodec/hevc_mp4toannexb_bsf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index 09bce5b34c2..f1e1a45abd1 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -66,7 +66,7 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx)
 for (j = 0; j < cnt; j++) {
 int nalu_len = bytestream2_get_be16(&gb);
 
-if (4 + AV_INPUT_BUFFER_PADDING_SIZE + nalu_len > SIZE_MAX - 
new_extradata_size) {
+if (4 + AV_INPUT_BUFFER_PADDING_SIZE + nalu_len > INT_MAX - 
new_extradata_size) {
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
@@ -152,8 +152,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 extra_size= add_extradata * ctx->par_out->extradata_size;
 got_irap |= is_irap;
 
-if (SIZE_MAX - nalu_size < 4 ||
-SIZE_MAX - 4 - nalu_size < extra_size) {
+if (INT_MAX - 4 - extra_size < nalu_size) {
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
-- 
2.24.0

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

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/atrac9dec: Check q_unit_cnt more completely before using it to access at9_tab_band_ext_group

2019-12-06 Thread Lynne
Dec 3, 2019, 21:23 by mich...@niedermayer.cc:

> Fixes: index 8 out of bounds for type 'const uint8_t [8][3]'
> Fixes: 
> 19127/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ATRAC9_fuzzer-5709394985091072
>
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
>

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

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

Re: [FFmpeg-devel] [PATCH] MAINTAINERS: add myself as libxavs2 maintainer

2019-12-06 Thread hwren
Ping.


Thanks,
Huiwen Ren

At 2019-10-12 11:15:55, "Steven Liu"  wrote:
>
>
>> 在 2019年10月12日,09:28,hwren  写道:
>> 
>> From: hwrenx 
>> 
>> Signed-off-by: hwrenx 
>> ---
>> MAINTAINERS | 1 +
>> 1 file changed, 1 insertion(+)
>> 
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 7f60ef0..928f4ee 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -198,6 +198,7 @@ Codecs:
>>   libvorbis.c   David Conrad
>>   libvpx*   James Zern
>>   libxavs.c Stefan Gehrer
>> +  libxavs2.cHuiwen Ren
>>   libzvbi-teletextdec.c Marton Balint
>>   lzo.h, lzo.c  Reimar Doeffinger
>>   mdec.cMichael Niedermayer
>> -- 
>> 2.7.4
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe”.
>
>LGTM
>
>Huiwen is come from AVS2 team. 
>
>Thanks
>Steven
>
>
>
>
>
>___
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>To unsubscribe, visit link above, or email
>ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 004/244] avframe: switch to the new channel layout API

2019-12-06 Thread Anton Khirnov
Signed-off-by: Vittorio Giovara 
---
 libavutil/frame.c | 113 ++
 libavutil/frame.h |  12 -
 2 files changed, 104 insertions(+), 21 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index e4038096c2..600f82bbeb 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -267,18 +267,27 @@ fail:
 
 static int get_audio_buffer(AVFrame *frame, int align)
 {
-int channels;
 int planar   = av_sample_fmt_is_planar(frame->format);
-int planes;
+int channels, planes;
 int ret, i;
 
-if (!frame->channels)
-frame->channels = 
av_get_channel_layout_nb_channels(frame->channel_layout);
-
-channels = frame->channels;
-planes = planar ? channels : 1;
-
-CHECK_CHANNELS_CONSISTENCY(frame);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (!frame->ch_layout.nb_channels) {
+if (frame->channel_layout) {
+av_channel_layout_from_mask(&frame->ch_layout, 
frame->channel_layout);
+} else {
+frame->ch_layout.nb_channels = frame->channels;
+frame->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+}
+}
+frame->channels = frame->ch_layout.nb_channels;
+frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+frame->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+channels = frame->ch_layout.nb_channels;
+planes   = planar ? channels : 1;
 if (!frame->linesize[0]) {
 ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
  frame->nb_samples, frame->format,
@@ -326,10 +335,17 @@ int av_frame_get_buffer(AVFrame *frame, int align)
 if (frame->format < 0)
 return AVERROR(EINVAL);
 
+FF_DISABLE_DEPRECATION_WARNINGS
 if (frame->width > 0 && frame->height > 0)
 return get_video_buffer(frame, align);
-else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+else if (frame->nb_samples > 0 &&
+ (av_channel_layout_check(&frame->ch_layout)
+#if FF_API_OLD_CHANNEL_LAYOUT
+  || frame->channel_layout || frame->channels > 0
+#endif
+ ))
 return get_audio_buffer(frame, align);
+FF_ENABLE_DEPRECATION_WARNINGS
 
 return AVERROR(EINVAL);
 }
@@ -450,14 +466,33 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
 dst->format = src->format;
 dst->width  = src->width;
 dst->height = src->height;
+dst->nb_samples = src->nb_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 dst->channels   = src->channels;
 dst->channel_layout = src->channel_layout;
-dst->nb_samples = src->nb_samples;
+if (!av_channel_layout_check(&src->ch_layout)) {
+if (src->channel_layout)
+av_channel_layout_from_mask(&dst->ch_layout, src->channel_layout);
+else {
+dst->ch_layout.nb_channels = src->channels;
+dst->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+}
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 ret = frame_copy_props(dst, src, 0);
 if (ret < 0)
 return ret;
 
+// this check is needed only until FF_API_OLD_CHANNEL_LAYOUT is out
+if (av_channel_layout_check(&src->ch_layout)) {
+ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
+if (ret < 0)
+goto fail;
+}
+
 /* duplicate the frame data if it's not refcounted */
 if (!src->buf[0]) {
 ret = av_frame_get_buffer(dst, 32);
@@ -510,13 +545,12 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
 
 /* duplicate extended data */
 if (src->extended_data != src->data) {
-int ch = src->channels;
+int ch = dst->ch_layout.nb_channels;
 
 if (!ch) {
 ret = AVERROR(EINVAL);
 goto fail;
 }
-CHECK_CHANNELS_CONSISTENCY(src);
 
 dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
 if (!dst->extended_data) {
@@ -576,6 +610,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_buffer_unref(&frame->opaque_ref);
 av_buffer_unref(&frame->private_ref);
 
+av_channel_layout_uninit(&frame->ch_layout);
+
 get_frame_defaults(frame);
 }
 
@@ -623,9 +659,19 @@ int av_frame_make_writable(AVFrame *frame)
 tmp.format = frame->format;
 tmp.width  = frame->width;
 tmp.height = frame->height;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 tmp.channels   = frame->channels;
 tmp.channel_layout = frame->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 tmp.nb_samples = frame->nb_samples;
+ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout);
+if (ret < 0) {
+av_frame_unref(&tmp);
+return ret;
+}
+
 ret = av_frame_get_buffer(&tmp, 32);
 if (ret < 0)
 return r

[FFmpeg-devel] [PATCH 016/244] aea: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
---
 libavformat/aea.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/aea.c b/libavformat/aea.c
index bdeed64254..8acfbce4fc 100644
--- a/libavformat/aea.c
+++ b/libavformat/aea.c
@@ -62,12 +62,13 @@ static int aea_read_probe(const AVProbeData *p)
 static int aea_read_header(AVFormatContext *s)
 {
 AVStream *st = avformat_new_stream(s, NULL);
+int channels;
 if (!st)
 return AVERROR(ENOMEM);
 
 /* Parse the amount of channels and skip to pos 2048(0x800) */
 avio_skip(s->pb, 264);
-st->codecpar->channels = avio_r8(s->pb);
+channels = avio_r8(s->pb);
 avio_skip(s->pb, 1783);
 
 
@@ -76,14 +77,14 @@ static int aea_read_header(AVFormatContext *s)
 st->codecpar->sample_rate= 44100;
 st->codecpar->bit_rate   = 292000;
 
-if (st->codecpar->channels != 1 && st->codecpar->channels != 2) {
-av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", 
st->codecpar->channels);
+if (channels != 1 && channels != 2) {
+av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", channels);
 return AVERROR_INVALIDDATA;
 }
 
-st->codecpar->channel_layout = (st->codecpar->channels == 1) ? 
AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+av_channel_layout_default(&st->codecpar->ch_layout, channels);
 
-st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->channels;
+st->codecpar->block_align = AT1_SU_SIZE * 
st->codecpar->ch_layout.nb_channels;
 return 0;
 }
 
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 013/244] adp: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
---
 libavformat/adp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/adp.c b/libavformat/adp.c
index 56f302acfd..ac80c7809f 100644
--- a/libavformat/adp.c
+++ b/libavformat/adp.c
@@ -55,8 +55,7 @@ static int adp_read_header(AVFormatContext *s)
 
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codecpar->codec_id   = AV_CODEC_ID_ADPCM_DTK;
-st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-st->codecpar->channels   = 2;
+st->codecpar->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 st->codecpar->sample_rate= 48000;
 st->start_time= 0;
 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 014/244] ads: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
---
 libavformat/ads.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/ads.c b/libavformat/ads.c
index f25141b3c6..20be40f499 100644
--- a/libavformat/ads.c
+++ b/libavformat/ads.c
@@ -47,11 +47,12 @@ static int ads_read_header(AVFormatContext *s)
 st->codecpar->sample_rate = avio_rl32(s->pb);
 if (st->codecpar->sample_rate <= 0)
 return AVERROR_INVALIDDATA;
-st->codecpar->channels= avio_rl32(s->pb);
-if (st->codecpar->channels <= 0)
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
+if (st->codecpar->ch_layout.nb_channels <= 0)
 return AVERROR_INVALIDDATA;
 align  = avio_rl32(s->pb);
-if (align <= 0 || align > INT_MAX / st->codecpar->channels)
+if (align <= 0 || align > INT_MAX / st->codecpar->ch_layout.nb_channels)
 return AVERROR_INVALIDDATA;
 
 if (codec == 1)
@@ -59,11 +60,11 @@ static int ads_read_header(AVFormatContext *s)
 else
 st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;
 
-st->codecpar->block_align = st->codecpar->channels * align;
+st->codecpar->block_align = st->codecpar->ch_layout.nb_channels * align;
 avio_skip(s->pb, 12);
 size = avio_rl32(s->pb);
 if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_PSX)
-st->duration = (size - 0x40) / 16 / st->codecpar->channels * 28;
+st->duration = (size - 0x40) / 16 / 
st->codecpar->ch_layout.nb_channels * 28;
 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
 return 0;
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 001/244] Add a new channel layout API

2019-12-06 Thread Anton Khirnov
The new API is more extensible and allows for custom layouts.
More accurate information is exported, eg for decoders that do not
set a channel layout, lavc will not make one up for them.

Deprecate the old API working with just uint64_t bitmasks.

Expanded and completed by Vittorio Giovara .
Signed-off-by: Vittorio Giovara 
---
 libavutil/channel_layout.c | 393 +--
 libavutil/channel_layout.h | 415 ++---
 libavutil/version.h|   3 +
 3 files changed, 719 insertions(+), 92 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index 3bd5ee29b7..b7077ed5fd 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -37,75 +37,89 @@ struct channel_name {
 };
 
 static const struct channel_name channel_names[] = {
- [0] = { "FL","front left"},
- [1] = { "FR","front right"   },
- [2] = { "FC","front center"  },
- [3] = { "LFE",   "low frequency" },
- [4] = { "BL","back left" },
- [5] = { "BR","back right"},
- [6] = { "FLC",   "front left-of-center"  },
- [7] = { "FRC",   "front right-of-center" },
- [8] = { "BC","back center"   },
- [9] = { "SL","side left" },
-[10] = { "SR","side right"},
-[11] = { "TC","top center"},
-[12] = { "TFL",   "top front left"},
-[13] = { "TFC",   "top front center"  },
-[14] = { "TFR",   "top front right"   },
-[15] = { "TBL",   "top back left" },
-[16] = { "TBC",   "top back center"   },
-[17] = { "TBR",   "top back right"},
-[29] = { "DL","downmix left"  },
-[30] = { "DR","downmix right" },
-[31] = { "WL","wide left" },
-[32] = { "WR","wide right"},
-[33] = { "SDL",   "surround direct left"  },
-[34] = { "SDR",   "surround direct right" },
-[35] = { "LFE2",  "low frequency 2"   },
+[AV_CHAN_FRONT_LEFT   ] = { "FL","front left"},
+[AV_CHAN_FRONT_RIGHT  ] = { "FR","front right"   },
+[AV_CHAN_FRONT_CENTER ] = { "FC","front center"  },
+[AV_CHAN_LOW_FREQUENCY] = { "LFE",   "low frequency" },
+[AV_CHAN_BACK_LEFT] = { "BL","back left" },
+[AV_CHAN_BACK_RIGHT   ] = { "BR","back right"},
+[AV_CHAN_FRONT_LEFT_OF_CENTER ] = { "FLC",   "front left-of-center"  },
+[AV_CHAN_FRONT_RIGHT_OF_CENTER] = { "FRC",   "front right-of-center" },
+[AV_CHAN_BACK_CENTER  ] = { "BC","back center"   },
+[AV_CHAN_SIDE_LEFT] = { "SL","side left" },
+[AV_CHAN_SIDE_RIGHT   ] = { "SR","side right"},
+[AV_CHAN_TOP_CENTER   ] = { "TC","top center"},
+[AV_CHAN_TOP_FRONT_LEFT   ] = { "TFL",   "top front left"},
+[AV_CHAN_TOP_FRONT_CENTER ] = { "TFC",   "top front center"  },
+[AV_CHAN_TOP_FRONT_RIGHT  ] = { "TFR",   "top front right"   },
+[AV_CHAN_TOP_BACK_LEFT] = { "TBL",   "top back left" },
+[AV_CHAN_TOP_BACK_CENTER  ] = { "TBC",   "top back center"   },
+[AV_CHAN_TOP_BACK_RIGHT   ] = { "TBR",   "top back right"},
+[AV_CHAN_STEREO_LEFT  ] = { "DL","downmix left"  },
+[AV_CHAN_STEREO_RIGHT ] = { "DR","downmix right" },
+[AV_CHAN_WIDE_LEFT] = { "WL","wide left" },
+[AV_CHAN_WIDE_RIGHT   ] = { "WR","wide right"},
+[AV_CHAN_SURROUND_DIRECT_LEFT ] = { "SDL",   "surround direct left"  },
+[AV_CHAN_SURROUND_DIRECT_RIGHT] = { "SDR",   "surround direct right" },
+[AV_CHAN_LOW_FREQUENCY_2  ] = { "LFE2",  "low frequency 2"   },
+[AV_CHAN_SILENCE  ] = { "PAD",   "silence"   },
 };
 
-static const char *get_channel_name(int channel_id)
+const char *av_channel_name(enum AVChannel channel_id)
 {
-if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names))
-return NULL;
+if ((unsigned) channel_id >= FF_ARRAY_ELEMS(channel_names) ||
+!channel_names[channel_id].name)
+return "?";
 return channel_names[channel_id].name;
 }
 
+int av_channel_from_string(const char *str)
+{
+int i;
+for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
+if (channel_names[i].name && !strcmp(str, channel_names[i].name))
+return i;
+}
+return AVERROR(EINVAL);
+}
+
 static const struct {
 const char *name;
-int 

[FFmpeg-devel] [PATCH 003/244] lavc: deprecate channel count/layout changing side data

2019-12-06 Thread Anton Khirnov
They are incompatible with the new channel layout scheme and no decoder
uses them.

Signed-off-by: Vittorio Giovara 
---
 libavcodec/avcodec.h | 5 +
 libavcodec/decode.c  | 4 
 libavformat/dump.c   | 9 -
 libavformat/nutenc.c | 2 ++
 libavformat/utils.c  | 9 +
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 735a3c2d76..43fa7d8292 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1534,8 +1534,13 @@ typedef struct AVPacket {
 
 
 enum AVSideDataParamChangeFlags {
+#if FF_API_OLD_CHANNEL_LAYOUT
+/**
+ * @deprecated those are not used by any decoder
+ */
 AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT  = 0x0001,
 AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
+#endif
 AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE= 0x0004,
 AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
 };
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0883c7209c..809f309b8c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -69,6 +69,8 @@ static int apply_param_change(AVCodecContext *avctx, const 
AVPacket *avpkt)
 flags = bytestream_get_le32(&data);
 size -= 4;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
 if (size < 4)
 goto fail;
@@ -87,6 +89,8 @@ static int apply_param_change(AVCodecContext *avctx, const 
AVPacket *avpkt)
 avctx->channel_layout = bytestream_get_le64(&data);
 size -= 8;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
 if (size < 4)
 goto fail;
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 56814ff7d2..5dd3b1a87e 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -161,8 +161,11 @@ static void dump_paramchange(void *ctx, AVPacketSideData 
*sd)
 {
 int size = sd->size;
 const uint8_t *data = sd->data;
-uint32_t flags, channels, sample_rate, width, height;
+uint32_t flags, sample_rate, width, height;
+#if FF_API_OLD_CHANNEL_LAYOUT
+uint32_t channels;
 uint64_t layout;
+#endif
 
 if (!data || sd->size < 4)
 goto fail;
@@ -171,6 +174,8 @@ static void dump_paramchange(void *ctx, AVPacketSideData 
*sd)
 data += 4;
 size -= 4;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
 if (size < 4)
 goto fail;
@@ -188,6 +193,8 @@ static void dump_paramchange(void *ctx, AVPacketSideData 
*sd)
 av_log(ctx, AV_LOG_INFO,
"channel layout: %s, ", av_get_channel_name(layout));
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif /* FF_API_OLD_CHANNEL_LAYOUT */
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
 if (size < 4)
 goto fail;
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 46dce7722d..94d2e65a37 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -888,6 +888,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext 
*bc, AVPacket *pkt, int
 break;
 case AV_PKT_DATA_PARAM_CHANGE:
 flags = bytestream_get_le32(&data);
+#if FF_API_OLD_CHANNEL_LAYOUT
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
 put_str(dyn_bc, "Channels");
 put_s(dyn_bc, bytestream_get_le32(&data));
@@ -901,6 +902,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext 
*bc, AVPacket *pkt, int
 avio_write(dyn_bc, data, 8); data+=8;
 sm_data_count++;
 }
+#endif
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
 put_str(dyn_bc, "SampleRate");
 put_s(dyn_bc, bytestream_get_le32(&data));
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4d18880acb..b6b5f0f308 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -5067,6 +5067,9 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
 uint8_t *data;
 if (!pkt)
 return AVERROR(EINVAL);
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 if (channels) {
 size  += 4;
 flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT;
@@ -5075,6 +5078,8 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
 size  += 8;
 flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 if (sample_rate) {
 size  += 4;
 flags |= AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE;
@@ -5087,10 +5092,14 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
 if (!data)
 return AVERROR(ENOMEM);
 bytestream_put_le32(&data, flags);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 if (channels)
 bytestream_put_le32(&data, channels);
 if (channel_layout)

[FFmpeg-devel] [PATCH 006/244] lavf: add a temporary compat layer for the channel layout API change

2019-12-06 Thread Anton Khirnov
Mediates between old-style (de)muxers and new-style callers. Will be
removed once all the (de)muxers are converted to the new API.
---
 libavformat/mux.c   | 10 ++
 libavformat/utils.c | 12 
 2 files changed, 22 insertions(+)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 411cca3fb2..ae1f26c3da 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -323,6 +323,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
 ret = AVERROR(EINVAL);
 goto fail;
 }
+
+/* if the new-style channel layout is set, convert it to old one
+ * for old-style muxers */
+if (par->ch_layout.nb_channels &&
+!par->channels) {
+par->channels   = par->ch_layout.nb_channels;
+par->channel_layout = par->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
+  par->ch_layout.u.mask : 0;
+}
+
 if (!par->block_align)
 par->block_align = par->channels *
av_get_bits_per_sample(par->codec_id) >> 3;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index b6b5f0f308..13eadbbfd0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -516,6 +516,18 @@ static int update_stream_avctx(AVFormatContext *s)
 st->parser = NULL;
 }
 
+/* if the demuxer exports old channel layouts, convert it to new */
+if (!st->codecpar->ch_layout.nb_channels &&
+st->codecpar->channels) {
+if (st->codecpar->channel_layout) {
+av_channel_layout_from_mask(&st->codecpar->ch_layout,
+st->codecpar->channel_layout);
+} else {
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = st->codecpar->channels;
+}
+}
+
 /* update internal codec context, for the parser */
 ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar);
 if (ret < 0)
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 002/244] lavu: support AVChannelLayout AVOptions

2019-12-06 Thread Anton Khirnov
Signed-off-by: Vittorio Giovara 
---
 libavutil/opt.c | 66 -
 libavutil/opt.h | 14 ++-
 2 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 9081a593a1..3e776804a6 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -39,6 +39,7 @@
 #include "opt.h"
 #include "samplefmt.h"
 #include "bprint.h"
+#include "version.h"
 
 #include 
 
@@ -71,7 +72,9 @@ static int read_number(const AVOption *o, const void *dst, 
double *num, int *den
 case AV_OPT_TYPE_INT:
 *intnum = *(int *)dst;
 return 0;
+#if FF_API_OLD_CHANNEL_LAYOUT
 case AV_OPT_TYPE_CHANNEL_LAYOUT:
+#endif
 case AV_OPT_TYPE_DURATION:
 case AV_OPT_TYPE_INT64:
 case AV_OPT_TYPE_UINT64:
@@ -126,7 +129,9 @@ static int write_number(void *obj, const AVOption *o, void 
*dst, double num, int
 *(int *)dst = llrint(num / den) * intnum;
 break;
 case AV_OPT_TYPE_DURATION:
+#if FF_API_OLD_CHANNEL_LAYOUT
 case AV_OPT_TYPE_CHANNEL_LAYOUT:
+#endif
 case AV_OPT_TYPE_INT64:{
 double d = num / den;
 if (intnum == 1 && d == (double)INT64_MAX) {
@@ -446,6 +451,16 @@ static int set_string_sample_fmt(void *obj, const AVOption 
*o, const char *val,
   AV_SAMPLE_FMT_NB, av_get_sample_fmt, "sample 
format");
 }
 
+static int set_string_channel_layout(void *obj, const AVOption *o,
+ const char *val, void *dst)
+{
+AVChannelLayout *channel_layout = dst;
+av_channel_layout_uninit(channel_layout);
+if (!val)
+return 0;
+return av_channel_layout_from_string(channel_layout, val);
+}
+
 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
 {
 int ret = 0;
@@ -457,7 +472,10 @@ int av_opt_set(void *obj, const char *name, const char 
*val, int search_flags)
  o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != 
AV_OPT_TYPE_SAMPLE_FMT &&
  o->type != AV_OPT_TYPE_IMAGE_SIZE && o->type != 
AV_OPT_TYPE_VIDEO_RATE &&
  o->type != AV_OPT_TYPE_DURATION && o->type != 
AV_OPT_TYPE_COLOR &&
- o->type != AV_OPT_TYPE_CHANNEL_LAYOUT && o->type != 
AV_OPT_TYPE_BOOL))
+#if FF_API_OLD_CHANNEL_LAYOUT
+ o->type != AV_OPT_TYPE_CHANNEL_LAYOUT &&
+#endif
+ o->type != AV_OPT_TYPE_BOOL))
 return AVERROR(EINVAL);
 
 if (o->flags & AV_OPT_FLAG_READONLY)
@@ -514,6 +532,7 @@ int av_opt_set(void *obj, const char *name, const char 
*val, int search_flags)
 }
 case AV_OPT_TYPE_COLOR:
 return set_string_color(obj, o, val, dst);
+#if FF_API_OLD_CHANNEL_LAYOUT
 case AV_OPT_TYPE_CHANNEL_LAYOUT:
 if (!val || !strcmp(val, "none")) {
 *(int64_t *)dst = 0;
@@ -527,6 +546,9 @@ int av_opt_set(void *obj, const char *name, const char 
*val, int search_flags)
 return ret;
 }
 break;
+#endif
+case AV_OPT_TYPE_CHLAYOUT:
+return set_string_channel_layout(obj, o, val, dst);
 }
 
 av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
@@ -688,6 +710,7 @@ int av_opt_set_sample_fmt(void *obj, const char *name, enum 
AVSampleFormat fmt,
 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, 
"sample", AV_SAMPLE_FMT_NB);
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int 
search_flags)
 {
 void *target_obj;
@@ -703,6 +726,7 @@ int av_opt_set_channel_layout(void *obj, const char *name, 
int64_t cl, int searc
 *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
 return 0;
 }
+#endif
 
 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
 int search_flags)
@@ -723,6 +747,22 @@ int av_opt_set_dict_val(void *obj, const char *name, const 
AVDictionary *val,
 return 0;
 }
 
+int av_opt_set_chlayout(void *obj, const char *name,
+const AVChannelLayout *channel_layout,
+int search_flags)
+{
+void *target_obj;
+const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, 
&target_obj);
+AVChannelLayout *dst;
+
+if (!o || !target_obj)
+return AVERROR_OPTION_NOT_FOUND;
+
+dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset);
+
+return av_channel_layout_copy(dst, channel_layout);
+}
+
 static void format_duration(char *buf, size_t size, int64_t d)
 {
 char *e;
@@ -851,10 +891,15 @@ int av_opt_get(void *obj, const char *name, int 
search_flags, uint8_t **out_val)
(int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
(int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
 break;
+#if FF_API_OLD_CHANNEL_LAYOUT
 case AV_OPT_TYPE_CHANNEL_LAYOUT:
 i64 = *(int64_t *)dst;
 ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
 break;
+#endif
+case AV_OP

[FFmpeg-devel] [PATCH 008/244] 3dostr: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
---
 libavformat/3dostr.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c
index 6c49f7589c..bfa52c0da5 100644
--- a/libavformat/3dostr.c
+++ b/libavformat/3dostr.c
@@ -63,15 +63,16 @@ static int threedostr_read_header(AVFormatContext *s)
 
 st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
 st->codecpar->sample_rate = avio_rb32(s->pb);
-st->codecpar->channels= avio_rb32(s->pb);
-if (st->codecpar->channels <= 0)
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = avio_rb32(s->pb);
+if (st->codecpar->ch_layout.nb_channels <= 0)
 return AVERROR_INVALIDDATA;
 codec  = avio_rl32(s->pb);
 avio_skip(s->pb, 4);
 if (ctrl_size == 20 || ctrl_size == 3 || ctrl_size == -1)
-st->duration   = (avio_rb32(s->pb) - 1) / 
st->codecpar->channels;
+st->duration   = (avio_rb32(s->pb) - 1) / 
st->codecpar->ch_layout.nb_channels;
 else
-st->duration   = avio_rb32(s->pb) * 16 / 
st->codecpar->channels;
+st->duration   = avio_rb32(s->pb) * 16 / 
st->codecpar->ch_layout.nb_channels;
 size -= 56;
 found_shdr = 1;
 break;
@@ -96,7 +97,7 @@ static int threedostr_read_header(AVFormatContext *s)
 switch (codec) {
 case MKTAG('S','D','X','2'):
 st->codecpar->codec_id= AV_CODEC_ID_SDX2_DPCM;
-st->codecpar->block_align = 1 * st->codecpar->channels;
+st->codecpar->block_align = 1 * st->codecpar->ch_layout.nb_channels;
 break;
 default:
 avpriv_request_sample(s, "codec %X", codec);
@@ -142,7 +143,7 @@ static int threedostr_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 ret = av_get_packet(s->pb, pkt, size);
 pkt->pos = pos;
 pkt->stream_index = 0;
-pkt->duration = size / st->codecpar->channels;
+pkt->duration = size / st->codecpar->ch_layout.nb_channels;
 size = 0;
 found_ssmp = 1;
 break;
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 009/244] 4xm: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
---
 libavformat/4xm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index a6101a92ec..864e525e09 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -184,13 +184,14 @@ static int parse_strk(AVFormatContext *s,
 
 st->codecpar->codec_type= AVMEDIA_TYPE_AUDIO;
 st->codecpar->codec_tag = 0;
-st->codecpar->channels  = fourxm->tracks[track].channels;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = fourxm->tracks[track].channels;
 st->codecpar->sample_rate   = fourxm->tracks[track].sample_rate;
 st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits;
-st->codecpar->bit_rate  = (int64_t)st->codecpar->channels *
+st->codecpar->bit_rate  = 
(int64_t)st->codecpar->ch_layout.nb_channels *
   st->codecpar->sample_rate *
   st->codecpar->bits_per_coded_sample;
-st->codecpar->block_align   = st->codecpar->channels *
+st->codecpar->block_align   = st->codecpar->ch_layout.nb_channels *
   st->codecpar->bits_per_coded_sample;
 
 if (fourxm->tracks[track].adpcm){
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 010/244] aa: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
---
 libavformat/aadec.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/aadec.c b/libavformat/aadec.c
index b9dd51ebfc..adf0869a65 100644
--- a/libavformat/aadec.c
+++ b/libavformat/aadec.c
@@ -188,7 +188,8 @@ static int aa_read_header(AVFormatContext *s)
 } else if (!strcmp(codec_name, "acelp85")) {
 st->codecpar->codec_id = AV_CODEC_ID_SIPR;
 st->codecpar->block_align = 19;
-st->codecpar->channels = 1;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = 1;
 st->codecpar->sample_rate = 8500;
 st->codecpar->bit_rate = 8500;
 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
@@ -196,7 +197,8 @@ static int aa_read_header(AVFormatContext *s)
 } else if (!strcmp(codec_name, "acelp16")) {
 st->codecpar->codec_id = AV_CODEC_ID_SIPR;
 st->codecpar->block_align = 20;
-st->codecpar->channels = 1;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = 1;
 st->codecpar->sample_rate = 16000;
 st->codecpar->bit_rate = 16000;
 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 012/244] act: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
---
 libavformat/act.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/act.c b/libavformat/act.c
index 26425ca1bb..2ba2673998 100644
--- a/libavformat/act.c
+++ b/libavformat/act.c
@@ -87,7 +87,8 @@ static int read_header(AVFormatContext *s)
 }
 
 st->codecpar->frame_size=80;
-st->codecpar->channels=1;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = 1;
 avpriv_set_pts_info(st, 64, 1, 100);
 
 st->codecpar->codec_id=AV_CODEC_ID_G729;
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 011/244] acm: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
---
 libavformat/acm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/acm.c b/libavformat/acm.c
index 5e03cf8bff..30086198dc 100644
--- a/libavformat/acm.c
+++ b/libavformat/acm.c
@@ -48,12 +48,13 @@ static int acm_read_header(AVFormatContext *s)
 if (ret < 0)
 return ret;
 
-st->codecpar->channels= AV_RL16(st->codecpar->extradata +  8);
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = AV_RL16(st->codecpar->extradata +  
8);
 st->codecpar->sample_rate = AV_RL16(st->codecpar->extradata + 10);
-if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0)
+if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate 
<= 0)
 return AVERROR_INVALIDDATA;
 st->start_time = 0;
-st->duration   = AV_RL32(st->codecpar->extradata +  4) / 
st->codecpar->channels;
+st->duration   = AV_RL32(st->codecpar->extradata +  4) / 
st->codecpar->ch_layout.nb_channels;
 st->need_parsing   = AVSTREAM_PARSE_FULL_RAW;
 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 007/244] lavf: convert the generic layer to the new channel layout

2019-12-06 Thread Anton Khirnov
---
 libavformat/mux.c   | 13 -
 libavformat/utils.c | 18 +-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index ae1f26c3da..dc4dc4518c 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -333,8 +333,19 @@ FF_ENABLE_DEPRECATION_WARNINGS
   par->ch_layout.u.mask : 0;
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+/* if the caller is using the deprecated channel layout API,
+ * convert it to the new style */
+if (!par->ch_layout.nb_channels) {
+par->ch_layout.order   = par->channel_layout ? 
AV_CHANNEL_ORDER_NATIVE : AV_CHANNEL_ORDER_UNSPEC;
+par->ch_layout.nb_channels = par->channels;
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 if (!par->block_align)
-par->block_align = par->channels *
+par->block_align = par->ch_layout.nb_channels *
av_get_bits_per_sample(par->codec_id) >> 3;
 break;
 case AVMEDIA_TYPE_VIDEO:
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 13eadbbfd0..4eaeba2fb5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -528,6 +528,18 @@ static int update_stream_avctx(AVFormatContext *s)
 }
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (st->codecpar->ch_layout.nb_channels &&
+!st->codecpar->channels) {
+st->codecpar->channels = st->codecpar->ch_layout.nb_channels;
+st->codecpar->channel_layout = st->codecpar->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
+   st->codecpar->ch_layout.u.mask : 0;
+
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 /* update internal codec context, for the parser */
 ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar);
 if (ret < 0)
@@ -1695,8 +1707,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return ret;
 st->codecpar->sample_rate = st->internal->avctx->sample_rate;
 st->codecpar->bit_rate = st->internal->avctx->bit_rate;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 st->codecpar->channels = st->internal->avctx->channels;
 st->codecpar->channel_layout = st->internal->avctx->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 st->codecpar->codec_id = st->internal->avctx->codec_id;
 } else {
 /* free packet */
@@ -4263,7 +4279,7 @@ int av_find_best_stream(AVFormatContext *ic, enum 
AVMediaType type,
 continue;
 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
 continue;
-if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate))
+if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && 
par->sample_rate))
 continue;
 if (decoder_ret) {
 decoder = find_decoder(ic, st, par->codec_id);
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 015/244] adxdec: convert to new channel layout API

2019-12-06 Thread Anton Khirnov
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
---
 libavformat/adxdec.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c
index 1038a0d67e..5bbd6a901f 100644
--- a/libavformat/adxdec.c
+++ b/libavformat/adxdec.c
@@ -53,12 +53,12 @@ static int adx_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 AVCodecParameters *par = s->streams[0]->codecpar;
 int ret, size;
 
-if (par->channels <= 0) {
-av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", 
par->channels);
+if (par->ch_layout.nb_channels <= 0) {
+av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", 
par->ch_layout.nb_channels);
 return AVERROR_INVALIDDATA;
 }
 
-size = BLOCK_SIZE * par->channels;
+size = BLOCK_SIZE * par->ch_layout.nb_channels;
 
 pkt->pos = avio_tell(s->pb);
 pkt->stream_index = 0;
@@ -83,6 +83,7 @@ static int adx_read_header(AVFormatContext *s)
 {
 ADXDemuxerContext *c = s->priv_data;
 AVCodecParameters *par;
+int channels;
 
 AVStream *st = avformat_new_stream(s, NULL);
 if (!st)
@@ -101,11 +102,13 @@ static int adx_read_header(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Invalid extradata size.\n");
 return AVERROR_INVALIDDATA;
 }
-par->channels= AV_RB8 (par->extradata + 7);
+channels = AV_RB8 (par->extradata + 7);
+par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+par->ch_layout.nb_channels = channels;
 par->sample_rate = AV_RB32(par->extradata + 8);
 
-if (par->channels <= 0) {
-av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", 
par->channels);
+if (channels <= 0) {
+av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", channels);
 return AVERROR_INVALIDDATA;
 }
 
@@ -116,7 +119,7 @@ static int adx_read_header(AVFormatContext *s)
 
 par->codec_type  = AVMEDIA_TYPE_AUDIO;
 par->codec_id= s->iformat->raw_codec_id;
-par->bit_rate= (int64_t)par->sample_rate * par->channels * BLOCK_SIZE 
* 8LL / BLOCK_SAMPLES;
+par->bit_rate= (int64_t)par->sample_rate * par->ch_layout.nb_channels 
* BLOCK_SIZE * 8LL / BLOCK_SAMPLES;
 
 avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, par->sample_rate);
 
-- 
2.24.0

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

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

[FFmpeg-devel] [PATCH 005/244] avcodecpar: switch to the new channel layout API

2019-12-06 Thread Anton Khirnov
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
---
 libavcodec/avcodec.h | 11 +++
 libavcodec/utils.c   | 46 +++-
 2 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 43fa7d8292..e049f61c5b 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4064,6 +4064,7 @@ typedef struct AVCodecParameters {
 enum AVColorSpace  color_space;
 enum AVChromaLocation  chroma_location;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 /**
  * Video only. Number of delayed frames.
  */
@@ -4073,12 +4074,17 @@ typedef struct AVCodecParameters {
  * Audio only. The channel layout bitmask. May be 0 if the channel layout 
is
  * unknown or unspecified, otherwise the number of bits set must be equal 
to
  * the channels field.
+ * @deprecated use ch_layout
  */
+attribute_deprecated
 uint64_t channel_layout;
 /**
  * Audio only. The number of audio channels.
+ * @deprecated use ch_layout.nb_channels
  */
+attribute_deprecated
 int  channels;
+#endif
 /**
  * Audio only. The number of audio samples per second.
  */
@@ -4113,6 +4119,11 @@ typedef struct AVCodecParameters {
  * Audio only. Number of samples to skip after a discontinuity.
  */
 int seek_preroll;
+
+/**
+ * Audio only. The channel layout and number of channels.
+ */
+AVChannelLayout ch_layout;
 } AVCodecParameters;
 
 /**
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 75e7035b8a..16d48413d4 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1745,8 +1745,15 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, 
int frame_bytes)
 
 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
 {
+int channels = par->ch_layout.nb_channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (!channels)
+channels = par->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 return get_audio_frame_duration(par->codec_id, par->sample_rate,
-par->channels, par->block_align,
+channels, par->block_align,
 par->codec_tag, par->bits_per_coded_sample,
 par->bit_rate, par->extradata, 
par->frame_size,
 frame_bytes);
@@ -1999,6 +2006,7 @@ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext 
*avctx)
 static void codec_parameters_reset(AVCodecParameters *par)
 {
 av_freep(&par->extradata);
+av_channel_layout_uninit(&par->ch_layout);
 
 memset(par, 0, sizeof(*par));
 
@@ -2039,6 +2047,8 @@ void avcodec_parameters_free(AVCodecParameters **ppar)
 
 int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters 
*src)
 {
+int ret;
+
 codec_parameters_reset(dst);
 memcpy(dst, src, sizeof(*dst));
 
@@ -2052,6 +2062,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, 
const AVCodecParameters *src
 dst->extradata_size = src->extradata_size;
 }
 
+ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
+if (ret < 0)
+return ret;
+
 return 0;
 }
 
@@ -2086,8 +2100,19 @@ int avcodec_parameters_from_context(AVCodecParameters 
*par,
 break;
 case AVMEDIA_TYPE_AUDIO:
 par->format   = codec->sample_fmt;
-par->channel_layout   = codec->channel_layout;
-par->channels = codec->channels;
+if (codec->channel_layout)
+av_channel_layout_from_mask(&par->ch_layout, 
codec->channel_layout);
+else {
+par->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+par->ch_layout.nb_channels = codec->channels;
+}
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+par->channel_layout  = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE 
?
+   par->ch_layout.u.mask : 0;
+par->channels= par->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 par->sample_rate  = codec->sample_rate;
 par->block_align  = codec->block_align;
 par->frame_size   = codec->frame_size;
@@ -2141,8 +2166,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
 break;
 case AVMEDIA_TYPE_AUDIO:
 codec->sample_fmt   = par->format;
-codec->channel_layout   = par->channel_layout;
-codec->channels = par->channels;
+if (par->ch_layout.nb_channels) {
+codec->channel_layout = par->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
+par->ch_layout.u.mask : 0;
+codec->channels   = par->ch_layout.nb_channels;
+}
+#if FF_API_OLD_CHANNEL_LAYOUT
+else {
+FF_DISABLE_DEPRECATION_WARNINGS
+  

Re: [FFmpeg-devel] [PATCH v6 1/2] lavf/isom: support for demuxing and remuxing of MPEG-H 3D Audio in MP4

2019-12-06 Thread Tsuchiya, Yuki (SHES)
Is there any comments?

On 2019/11/27 18:34, "ffmpeg-devel on behalf of Tsuchiya, Yuki (SHES)" 
 wrote:

Hi,

Could you merge this patch if there is no objection?

> -Original Message-
> From: Tsuchiya, Yuki (SHES) 
> 
> Implemented according to the specification at
> https://www.iso.org/standard/69561.html
> The 'mhm1' sample entry is registered with MP4RA, which is defined as MHAS
> encapsulated single stream MPEG-H 3D Audio.
> 'MHAS' stands for MPEG-H audio stream, which contains encoded audio data
> and corresponds metadata for decoding.
> This patch enables extracting the MHAS bitstream from MP4 and remuxing
> into MP4.
> 



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

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

Re: [FFmpeg-devel] [PATCH v1 1/2] avformat/libsrt: change tlpktdrop, nakreport, messageapi options to boolean type

2019-12-06 Thread Michael Niedermayer
On Fri, Sep 20, 2019 at 07:17:27PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavformat/libsrt.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

will apply

thx

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

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell


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

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

Re: [FFmpeg-devel] [PATCH v1 2/2] avformat/libsrt: fix for the memory leak if passphrase has been configured by option

2019-12-06 Thread Michael Niedermayer
On Fri, Sep 20, 2019 at 07:17:28PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavformat/libsrt.c | 1 +
>  1 file changed, 1 insertion(+)

will apply

thx

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

No snowflake in an avalanche ever feels responsible. -- Voltaire


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

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

Re: [FFmpeg-devel] [PATCH] libswscale/swscale_unscaled.c: remove redundant code

2019-12-06 Thread Michael Niedermayer
On Thu, Dec 05, 2019 at 11:10:43AM +0800, Ting Fu wrote:
> Signed-off-by: Ting Fu 
> ---
>  libswscale/swscale_unscaled.c | 2 --
>  1 file changed, 2 deletions(-)

will apply

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.


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

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

Re: [FFmpeg-devel] [PATCH] avfilter/vf_yaepblur: add yaepblur filter

2019-12-06 Thread Michael Niedermayer
On Thu, Dec 05, 2019 at 11:39:48AM +0100, Paul B Mahol wrote:
> On 12/5/19, Tao Zhang  wrote:
> > Hello everyone,
> > Can I assume this patch is ok if no comments or objections?
> 
> Yes, give some time for it to be applied.
> I'm busy with other stuff right now. So this patch LGTM (Note to
> committer to bump minor of libavfiter upon pushing).

will apply

thx

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

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued


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

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

Re: [FFmpeg-devel] [PATCH v2 1/3] avfilter/vf_elbg: Fix for the seed type

2019-12-06 Thread Michael Niedermayer
On Thu, Dec 05, 2019 at 09:54:44PM +0800, Limin Wang wrote:
> On Wed, Dec 04, 2019 at 08:31:15PM +0100, Michael Niedermayer wrote:
> > On Fri, Nov 22, 2019 at 09:50:36AM +0800, lance.lmw...@gmail.com wrote:
> > > From: Limin Wang 
> > > 
> > > Signed-off-by: Limin Wang 
> > > ---
> > >  libavfilter/vf_elbg.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > will apply
> 
> Thanks, please help to review the PATCH v2 2/3 and 3/3 also, 
> they're fix the same typo.

will apply them too

thanks

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

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope


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

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

Re: [FFmpeg-devel] [PATCH] avdevice/xcbgrab: Improve non-shm performance

2019-12-06 Thread Marton Balint



On Thu, 5 Dec 2019, Kusanagi Kouichi wrote:


On 2019-12-04 22:32:52 +0100, Marton Balint wrote:



On Wed, 4 Dec 2019, Kusanagi Kouichi wrote:

> On 2019-12-03 21:25:37 +0100, Marton Balint wrote:
> > 
> > 
> > On Tue, 3 Dec 2019, Kusanagi Kouichi wrote:
> > 
> > > On 2019-11-19 22:59:56 +0900, Kusanagi Kouichi wrote:

> > > > Use AVBufferPool.
> > 
> > You don't need a buffer pool for the non-shm case, you should wrap the XCB

> > data in a buffer ref instead. I will reply with a patch that shows how it is
> > done, please check if it works correctly, as I am not 100% sure how xcb data
> > structures should be allocated/freed.
> > 
> 
> Is it safe to omit AV_INPUT_BUFFER_PADDING_SIZE bytes padding? My first

> version is identical to yours. Valgrind reported no error. But I'm not sure.

Strictly speaking it is against the API, but the performance gains IMHO are
too big to respect the API requirement blindly. Also I see little chance
that it will cause issues, because typically avcodec/rawdec.c will simply
reassign the buffer ref to an AVFrame and keep the data untouched. And
AVFrame data does not have this requirement. If something breaks, we can
always reconsider this or find another solution.

Regards,
Marton


OK, Then can you commit your patch?


Sure, applied with some minor changes.

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

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

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/mvha: Check remaining space when reading VLC table probabilities

2019-12-06 Thread Michael Niedermayer
On Fri, Dec 06, 2019 at 12:37:36AM +0100, Paul B Mahol wrote:
> LGTM

will apply

thx

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

Never trust a computer, one day, it may think you are the virus. -- Compn


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

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