[FFmpeg-devel] [PATCH 1/2] lavc/qsv: use avpriv_ instead of ff_ as prefix for some functions

2020-11-23 Thread Haihao Xiang
ff_qsv_print_iopattern, ff_qsv_print_error and ff_qsv_print_warning can be
used outside of lavc. In addition, ff_qsv_map_error is used in
libavcodec/qsv.c only, so remove ff_ from ff_qsv_map_error and make it
static.

Signed-off-by: Haihao Xiang 
---
 libavcodec/Makefile|  2 +-
 libavcodec/qsv.c   | 46 +-
 libavcodec/qsv_core_internal.h | 43 +++
 libavcodec/qsv_internal.h  | 24 +-
 libavcodec/qsvdec.c| 16 ++--
 libavcodec/qsvenc.c| 36 +-
 6 files changed, 94 insertions(+), 73 deletions(-)
 create mode 100644 libavcodec/qsv_core_internal.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b4777be4d4..d1e744b954 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1193,7 +1193,7 @@ SKIPHEADERS-$(CONFIG_MEDIACODEC)   += 
mediacodecdec_common.h mediacodec_surf
 SKIPHEADERS-$(CONFIG_MEDIAFOUNDATION)  += mf_utils.h
 SKIPHEADERS-$(CONFIG_NVDEC)+= nvdec.h
 SKIPHEADERS-$(CONFIG_NVENC)+= nvenc.h
-SKIPHEADERS-$(CONFIG_QSV)  += qsv.h qsv_internal.h
+SKIPHEADERS-$(CONFIG_QSV)  += qsv.h qsv_internal.h 
qsv_core_internal.h
 SKIPHEADERS-$(CONFIG_QSVDEC)   += qsvdec.h
 SKIPHEADERS-$(CONFIG_QSVENC)   += qsvenc.h
 SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 6e3154e1a3..99ec1cab9e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -101,8 +101,8 @@ static const struct {
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
 };
 
-int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
-   const char *extra_string)
+int avpriv_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
+   const char *extra_string)
 {
 const char *desc = NULL;
 
@@ -158,7 +158,7 @@ static const struct {
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
 };
 
-int ff_qsv_map_error(mfxStatus mfx_err, const char **desc)
+static int qsv_map_error(mfxStatus mfx_err, const char **desc)
 {
 int i;
 for (i = 0; i < FF_ARRAY_ELEMS(qsv_errors); i++) {
@@ -173,22 +173,22 @@ int ff_qsv_map_error(mfxStatus mfx_err, const char **desc)
 return AVERROR_UNKNOWN;
 }
 
-int ff_qsv_print_error(void *log_ctx, mfxStatus err,
-   const char *error_string)
+int avpriv_qsv_print_error(void *log_ctx, mfxStatus err,
+   const char *error_string)
 {
 const char *desc;
 int ret;
-ret = ff_qsv_map_error(err, &desc);
+ret = qsv_map_error(err, &desc);
 av_log(log_ctx, AV_LOG_ERROR, "%s: %s (%d)\n", error_string, desc, err);
 return ret;
 }
 
-int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
- const char *warning_string)
+int avpriv_qsv_print_warning(void *log_ctx, mfxStatus err,
+ const char *warning_string)
 {
 const char *desc;
 int ret;
-ret = ff_qsv_map_error(err, &desc);
+ret = qsv_map_error(err, &desc);
 av_log(log_ctx, AV_LOG_WARNING, "%s: %s (%d)\n", warning_string, desc, 
err);
 return ret;
 }
@@ -331,7 +331,7 @@ static int qsv_load_plugins(mfxSession session, const char 
*load_plugins,
 char errorbuf[128];
 snprintf(errorbuf, sizeof(errorbuf),
  "Could not load the requested plugin '%s'", plugin);
-err = ff_qsv_print_error(logctx, ret, errorbuf);
+err = avpriv_qsv_print_error(logctx, ret, errorbuf);
 goto load_plugin_fail;
 }
 
@@ -372,7 +372,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
QSVSession *qs)
 ret = MFXVideoCORE_SetHandle(qs->session,
 (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)hwctx->display);
 if (ret < 0) {
-return ff_qsv_print_error(avctx, ret, "Error during set display 
handle\n");
+return avpriv_qsv_print_error(avctx, ret, "Error during set 
display handle\n");
 }
 }
 
@@ -397,8 +397,8 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
QSVSession *qs,
 init_par.Version= ver;
 ret = MFXInitEx(init_par, &qs->session);
 if (ret < 0)
-return ff_qsv_print_error(avctx, ret,
-  "Error initializing an internal MFX 
session");
+return avpriv_qsv_print_error(avctx, ret,
+  "Error initializing an internal MFX 
session");
 
 #ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
 ret = ff_qsv_set_display_handle(avctx, qs);
@@ -713,8 +713,8 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
 if (err == MFX_ERR_NONE)
 err = MFXQueryVersion(parent_session, &ver);
 if (err != MFX_ERR_NONE)
-return ff_qsv_print_error(avctx, err,
-  

[FFmpeg-devel] [PATCH 2/2] qsv: dump more info in error, debug and verbose mode

2020-11-23 Thread Haihao Xiang
Dump iopattern mode and the SDK error/warning desciptions for qsv based
filters and iopattern mode for qsvenc

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvenc.c  |  1 +
 libavfilter/qsvvpp.c | 21 +--
 libavfilter/qsvvpp.h | 10 +
 libavfilter/vf_deinterlace_qsv.c | 36 +++-
 libavfilter/vf_scale_qsv.c   | 30 +++---
 5 files changed, 65 insertions(+), 33 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index cdb527608b..4abd8e48a3 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1132,6 +1132,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext 
*q)
 if (!iopattern)
 iopattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
 q->param.IOPattern = iopattern;
+avpriv_qsv_print_iopattern(avctx, iopattern, "Encoder");
 
 ret = qsvenc_init_session(avctx, q);
 if (ret < 0)
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8d5ff2eb65..5c58571f07 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -505,15 +505,19 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 }
 }
 
-if (ret != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error getting the session handle\n");
+if (ret < 0)
+return avpriv_qsv_print_error(avctx, ret, "Error getting the session 
handle");
+else if (ret > 0) {
+avpriv_qsv_print_warning(avctx, ret, "Warning in getting the session 
handle");
 return AVERROR_UNKNOWN;
 }
 
 /* create a "slave" session with those same properties, to be used for vpp 
*/
 ret = MFXInit(impl, &ver, &s->session);
-if (ret != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error initializing a session for 
scaling\n");
+if (ret < 0)
+return avpriv_qsv_print_error(avctx, ret, "Error initializing a 
session");
+else if (ret > 0) {
+avpriv_qsv_print_warning(avctx, ret, "Warning in session 
initialization");
 return AVERROR_UNKNOWN;
 }
 
@@ -646,11 +650,16 @@ int ff_qsvvpp_create(AVFilterContext *avctx, 
QSVVPPContext **vpp, QSVVPPParam *p
 else if (IS_OPAQUE_MEMORY(s->out_mem_mode))
 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 
+/* Print input memory mode */
+avpriv_qsv_print_iopattern(avctx, s->vpp_param.IOPattern & 0x0F, "VPP");
+/* Print output memory mode */
+avpriv_qsv_print_iopattern(avctx, s->vpp_param.IOPattern & 0xF0, "VPP");
 ret = MFXVideoVPP_Init(s->session, &s->vpp_param);
 if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Failed to create a qsvvpp, ret = %d.\n", 
ret);
+ret = avpriv_qsv_print_error(avctx, ret, "Failed to create a qsvvpp");
 goto failed;
-}
+} else if (ret > 0)
+avpriv_qsv_print_warning(avctx, ret, "Warning When creating qsvvpp");
 
 *vpp = s;
 return 0;
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index c2bcce7548..da4ed56ce4 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -24,21 +24,13 @@
 #ifndef AVFILTER_QSVVPP_H
 #define AVFILTER_QSVVPP_H
 
-#include 
+#include "libavcodec/qsv_core_internal.h"
 
 #include "avfilter.h"
 
 #define FF_INLINK_IDX(link)  ((int)((link)->dstpad - (link)->dst->input_pads))
 #define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
 
-#define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
-(MFX_VERSION_MAJOR > (MAJOR) || \
- MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
-
-#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
-((MFX_VERSION.Major > (MAJOR)) ||   \
-(MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
-
 typedef struct QSVVPPContext QSVVPPContext;
 
 typedef struct QSVVPPCrop {
diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index 80217c8419..484fd93765 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -202,16 +202,20 @@ static int init_out_session(AVFilterContext *ctx)
 }
 }
 
-if (err != MFX_ERR_NONE) {
-av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n");
+if (err < 0)
+return avpriv_qsv_print_error(ctx, err, "Error getting the session 
handle");
+else if (err > 0) {
+avpriv_qsv_print_warning(ctx, err, "Warning in getting the session 
handle");
 return AVERROR_UNKNOWN;
 }
 
 /* create a "slave" session with those same properties, to be used for
  * actual deinterlacing */
 err = MFXInit(impl, &ver, &s->session);
-if (err != MFX_ERR_NONE) {
-av_log(ctx, AV_LOG_ERROR, "Error initializing a session for 
deinterlacing\n");
+if (err < 0)
+return avpriv_qsv_print_error(ctx, err, "Error initializing a session 
for deinterlacing");
+else if (err > 0) {
+avpriv_qsv_print_warning(ctx, err, "Warning in session 
initialization");

Re: [FFmpeg-devel] [PATCH v3] hlsenc: expand hls_fmp4_init_filename with strftime()

2020-11-23 Thread ffmpeg


> 2020年11月23日 下午3:23,Nikola Pajkovsky  写道:
> 
> Nikola Pajkovsky  writes:
> 
>> Nikola Pajkovsky  writes:
>> 
>> Ping?
> 
> Ping. Steven, Andreas, can you look at the the latest iteration of the
> path?
> 
>>> init.mp4 can be expanded with strftime() the same way as
>>> hls_segment_filename.
>>> 
>>> Signed-off-by: Nikola Pajkovsky 
>>> ---
>>> v2: fix memleak on strftime failure
>>> v3: use av_free() insted of free()
Ok to me
>>> 
>>> doc/muxers.texi  |  7 ++
>>> libavformat/hlsenc.c | 54 +++-
>>> 2 files changed, 50 insertions(+), 11 deletions(-)
>>> 
>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>> index 813b4678f409..179b9239517b 100644
>>> --- a/doc/muxers.texi
>>> +++ b/doc/muxers.texi
>>> @@ -859,6 +859,13 @@ fmp4 files may be used in HLS version 7 and above.
>>> @item hls_fmp4_init_filename @var{filename}
>>> Set filename to the fragment files header file, default filename is 
>>> @file{init.mp4}.
>>> 
>>> +Use @code{-strftime 1} on @var{filename} to expand the segment filename 
>>> with localtime.
>>> +@example
>>> +ffmpeg -i in.nut  -hls_segment_type fmp4 -strftime 1 
>>> -hls_fmp4_init_filename "%s_init.mp4" out.m3u8
>>> +@end example
>>> +This will produce init like this
>>> +@file{1602678741_init.mp4}
>>> +
>>> @item hls_fmp4_init_resend
>>> Resend init file after m3u8 file refresh every time, default is @var{0}.
>>> 
>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>> index cbfd8f7c0d41..3457ed5201bf 100644
>>> --- a/libavformat/hlsenc.c
>>> +++ b/libavformat/hlsenc.c
>>> @@ -259,6 +259,29 @@ typedef struct HLSContext {
>>> int has_video_m3u8; /* has video stream m3u8 list */
>>> } HLSContext;
>>> 
>>> +static int strftime_expand(const char *fmt, char **dest)
>>> +{
>>> +int r = 1;
>>> +time_t now0;
>>> +struct tm *tm, tmpbuf;
>>> +char *buf;
>>> +
>>> +buf = av_mallocz(MAX_URL_SIZE);
>>> +if (!buf)
>>> +return AVERROR(ENOMEM);
>>> +
>>> +time(&now0);
>>> +tm = localtime_r(&now0, &tmpbuf);
>>> +r = strftime(buf, MAX_URL_SIZE, fmt, tm);
>>> +if (!r) {
>>> +av_free(buf);
>>> +return AVERROR(EINVAL);
>>> +}
>>> +*dest = buf;
>>> +
>>> +return r;
>>> +}
>>> +
>>> static int hlsenc_io_open(AVFormatContext *s, AVIOContext **pb, char 
>>> *filename,
>>>   AVDictionary **options)
>>> {
>>> @@ -1660,19 +1683,15 @@ static int hls_start(AVFormatContext *s, 
>>> VariantStream *vs)
>>> ff_format_set_url(oc, filename);
>>> } else {
>>> if (c->use_localtime) {
>>> -time_t now0;
>>> -struct tm *tm, tmpbuf;
>>> -int bufsize = strlen(vs->basename) + MAX_URL_SIZE;
>>> -char *buf = av_mallocz(bufsize);
>>> -if (!buf)
>>> -return AVERROR(ENOMEM);
>>> -time(&now0);
>>> -tm = localtime_r(&now0, &tmpbuf);
>>> -ff_format_set_url(oc, buf);
>>> -if (!strftime(oc->url, bufsize, vs->basename, tm)) {
>>> +int r;
>>> +char *expanded = NULL;
>>> +
>>> +r = strftime_expand(vs->basename, &expanded);
>>> +if (r < 0) {
>>> av_log(oc, AV_LOG_ERROR, "Could not get segment filename 
>>> with strftime\n");
>>> -return AVERROR(EINVAL);
>>> +return r;
>>> }
>>> +ff_format_set_url(oc, expanded);
>>> 
>>> err = sls_flag_use_localtime_filename(oc, c, vs);
>>> if (err < 0) {
>>> @@ -2980,6 +2999,19 @@ static int hls_init(AVFormatContext *s)
>>> return ret;
>>> }
>>> 
>>> +if (hls->use_localtime) {
>>> +int r;
>>> +char *expanded = NULL;
>>> +
>>> +r = strftime_expand(vs->fmp4_init_filename, &expanded);
>>> +if (r < 0) {
>>> +  av_log(s, AV_LOG_ERROR, "Could not get segment 
>>> filename with strftime\n");
>>> +  return r;
>>> +   }
>>> +   av_free(vs->fmp4_init_filename);
>>> +   vs->fmp4_init_filename = expanded;
>>> +   }
>>> +
>>> p = strrchr(vs->m3u8_name, '/');
>>> if (p) {
>>> char tmp = *(++p);
> 
> -- 
> Nikola
> ___
> 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 v3] hlsenc: expand hls_fmp4_init_filename with strftime()

2020-11-23 Thread Nikola Pajkovsky
Nikola Pajkovsky  writes:

> Nikola Pajkovsky  writes:
>
> Ping?

Ping. Steven, Andreas, can you look at the the latest iteration of the
path?

>> init.mp4 can be expanded with strftime() the same way as
>> hls_segment_filename.
>>
>> Signed-off-by: Nikola Pajkovsky 
>> ---
>>  v2: fix memleak on strftime failure
>>  v3: use av_free() insted of free()
>>
>>  doc/muxers.texi  |  7 ++
>>  libavformat/hlsenc.c | 54 +++-
>>  2 files changed, 50 insertions(+), 11 deletions(-)
>>
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 813b4678f409..179b9239517b 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -859,6 +859,13 @@ fmp4 files may be used in HLS version 7 and above.
>>  @item hls_fmp4_init_filename @var{filename}
>>  Set filename to the fragment files header file, default filename is 
>> @file{init.mp4}.
>>  
>> +Use @code{-strftime 1} on @var{filename} to expand the segment filename 
>> with localtime.
>> +@example
>> +ffmpeg -i in.nut  -hls_segment_type fmp4 -strftime 1 
>> -hls_fmp4_init_filename "%s_init.mp4" out.m3u8
>> +@end example
>> +This will produce init like this
>> +@file{1602678741_init.mp4}
>> +
>>  @item hls_fmp4_init_resend
>>  Resend init file after m3u8 file refresh every time, default is @var{0}.
>>  
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index cbfd8f7c0d41..3457ed5201bf 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -259,6 +259,29 @@ typedef struct HLSContext {
>>  int has_video_m3u8; /* has video stream m3u8 list */
>>  } HLSContext;
>>  
>> +static int strftime_expand(const char *fmt, char **dest)
>> +{
>> +int r = 1;
>> +time_t now0;
>> +struct tm *tm, tmpbuf;
>> +char *buf;
>> +
>> +buf = av_mallocz(MAX_URL_SIZE);
>> +if (!buf)
>> +return AVERROR(ENOMEM);
>> +
>> +time(&now0);
>> +tm = localtime_r(&now0, &tmpbuf);
>> +r = strftime(buf, MAX_URL_SIZE, fmt, tm);
>> +if (!r) {
>> +av_free(buf);
>> +return AVERROR(EINVAL);
>> +}
>> +*dest = buf;
>> +
>> +return r;
>> +}
>> +
>>  static int hlsenc_io_open(AVFormatContext *s, AVIOContext **pb, char 
>> *filename,
>>AVDictionary **options)
>>  {
>> @@ -1660,19 +1683,15 @@ static int hls_start(AVFormatContext *s, 
>> VariantStream *vs)
>>  ff_format_set_url(oc, filename);
>>  } else {
>>  if (c->use_localtime) {
>> -time_t now0;
>> -struct tm *tm, tmpbuf;
>> -int bufsize = strlen(vs->basename) + MAX_URL_SIZE;
>> -char *buf = av_mallocz(bufsize);
>> -if (!buf)
>> -return AVERROR(ENOMEM);
>> -time(&now0);
>> -tm = localtime_r(&now0, &tmpbuf);
>> -ff_format_set_url(oc, buf);
>> -if (!strftime(oc->url, bufsize, vs->basename, tm)) {
>> +int r;
>> +char *expanded = NULL;
>> +
>> +r = strftime_expand(vs->basename, &expanded);
>> +if (r < 0) {
>>  av_log(oc, AV_LOG_ERROR, "Could not get segment filename 
>> with strftime\n");
>> -return AVERROR(EINVAL);
>> +return r;
>>  }
>> +ff_format_set_url(oc, expanded);
>>  
>>  err = sls_flag_use_localtime_filename(oc, c, vs);
>>  if (err < 0) {
>> @@ -2980,6 +2999,19 @@ static int hls_init(AVFormatContext *s)
>>  return ret;
>>  }
>>  
>> +if (hls->use_localtime) {
>> +int r;
>> +char *expanded = NULL;
>> +
>> +r = strftime_expand(vs->fmp4_init_filename, &expanded);
>> +if (r < 0) {
>> +  av_log(s, AV_LOG_ERROR, "Could not get segment 
>> filename with strftime\n");
>> +  return r;
>> +}
>> +av_free(vs->fmp4_init_filename);
>> +vs->fmp4_init_filename = expanded;
>> +}
>> +
>>  p = strrchr(vs->m3u8_name, '/');
>>  if (p) {
>>  char tmp = *(++p);

-- 
Nikola
___
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] avcodec/dxva2_av1: use correct grain parameters with update_grain = 0

2020-11-23 Thread Hendrik Leppkes
When update_grain is zero, the parameters should be taken from a
reference frame instead.
---
 libavcodec/dxva2_av1.c | 59 +-
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/libavcodec/dxva2_av1.c b/libavcodec/dxva2_av1.c
index c6cbd48f5f..35d0bdf319 100644
--- a/libavcodec/dxva2_av1.c
+++ b/libavcodec/dxva2_av1.c
@@ -215,46 +215,47 @@ static int fill_picture_parameters(const AVCodecContext 
*avctx, AVDXVAContext *c
 
 /* Film grain */
 if (frame_header->apply_grain) {
+const AV1RawFrameHeader *fg_header = frame_header->update_grain ? 
frame_header : h->ref[frame_header->film_grain_params_ref_idx].raw_frame_header;
 pp->film_grain.apply_grain  = 1;
-pp->film_grain.scaling_shift_minus8 = 
frame_header->grain_scaling_minus_8;
-pp->film_grain.chroma_scaling_from_luma = 
frame_header->chroma_scaling_from_luma;
-pp->film_grain.ar_coeff_lag = frame_header->ar_coeff_lag;
-pp->film_grain.ar_coeff_shift_minus6= 
frame_header->ar_coeff_shift_minus_6;
-pp->film_grain.grain_scale_shift= 
frame_header->grain_scale_shift;
-pp->film_grain.overlap_flag = frame_header->overlap_flag;
-pp->film_grain.clip_to_restricted_range = 
frame_header->clip_to_restricted_range;
+pp->film_grain.scaling_shift_minus8 = 
fg_header->grain_scaling_minus_8;
+pp->film_grain.chroma_scaling_from_luma = 
fg_header->chroma_scaling_from_luma;
+pp->film_grain.ar_coeff_lag = fg_header->ar_coeff_lag;
+pp->film_grain.ar_coeff_shift_minus6= 
fg_header->ar_coeff_shift_minus_6;
+pp->film_grain.grain_scale_shift= fg_header->grain_scale_shift;
+pp->film_grain.overlap_flag = fg_header->overlap_flag;
+pp->film_grain.clip_to_restricted_range = 
fg_header->clip_to_restricted_range;
 pp->film_grain.matrix_coeff_is_identity = 
(seq->color_config.matrix_coefficients == AVCOL_SPC_RGB);
 
 pp->film_grain.grain_seed   = frame_header->grain_seed;
-pp->film_grain.num_y_points = frame_header->num_y_points;
-for (i = 0; i < frame_header->num_y_points; i++) {
-pp->film_grain.scaling_points_y[i][0] = 
frame_header->point_y_value[i];
-pp->film_grain.scaling_points_y[i][1] = 
frame_header->point_y_scaling[i];
+pp->film_grain.num_y_points = fg_header->num_y_points;
+for (i = 0; i < fg_header->num_y_points; i++) {
+pp->film_grain.scaling_points_y[i][0] = 
fg_header->point_y_value[i];
+pp->film_grain.scaling_points_y[i][1] = 
fg_header->point_y_scaling[i];
 }
-pp->film_grain.num_cb_points= frame_header->num_cb_points;
-for (i = 0; i < frame_header->num_cb_points; i++) {
-pp->film_grain.scaling_points_cb[i][0] = 
frame_header->point_cb_value[i];
-pp->film_grain.scaling_points_cb[i][1] = 
frame_header->point_cb_scaling[i];
+pp->film_grain.num_cb_points= fg_header->num_cb_points;
+for (i = 0; i < fg_header->num_cb_points; i++) {
+pp->film_grain.scaling_points_cb[i][0] = 
fg_header->point_cb_value[i];
+pp->film_grain.scaling_points_cb[i][1] = 
fg_header->point_cb_scaling[i];
 }
-pp->film_grain.num_cr_points= frame_header->num_cr_points;
-for (i = 0; i < frame_header->num_cr_points; i++) {
-pp->film_grain.scaling_points_cr[i][0] = 
frame_header->point_cr_value[i];
-pp->film_grain.scaling_points_cr[i][1] = 
frame_header->point_cr_scaling[i];
+pp->film_grain.num_cr_points= fg_header->num_cr_points;
+for (i = 0; i < fg_header->num_cr_points; i++) {
+pp->film_grain.scaling_points_cr[i][0] = 
fg_header->point_cr_value[i];
+pp->film_grain.scaling_points_cr[i][1] = 
fg_header->point_cr_scaling[i];
 }
 for (i = 0; i < 24; i++) {
-pp->film_grain.ar_coeffs_y[i] = 
frame_header->ar_coeffs_y_plus_128[i];
+pp->film_grain.ar_coeffs_y[i] = fg_header->ar_coeffs_y_plus_128[i];
 }
 for (i = 0; i < 25; i++) {
-pp->film_grain.ar_coeffs_cb[i] = 
frame_header->ar_coeffs_cb_plus_128[i];
-pp->film_grain.ar_coeffs_cr[i] = 
frame_header->ar_coeffs_cr_plus_128[i];
+pp->film_grain.ar_coeffs_cb[i] = 
fg_header->ar_coeffs_cb_plus_128[i];
+pp->film_grain.ar_coeffs_cr[i] = 
fg_header->ar_coeffs_cr_plus_128[i];
 }
-pp->film_grain.cb_mult  = frame_header->cb_mult;
-pp->film_grain.cb_luma_mult = frame_header->cb_luma_mult;
-pp->film_grain.cr_mult  = frame_header->cr_mult;
-pp->film_grain.cr_luma_mult = frame_header->cr_luma_mult;
-pp->film_grain.cb_offset= frame_header->cb_offset;
-pp->film_grain.cr_offset= frame_he

Re: [FFmpeg-devel] [PATCH v2 1/3] libavutil: introduce AVFilmGrainParams side data

2020-11-23 Thread James Almer

On 11/23/2020 9:08 AM, Lynne wrote:



From e11df30e25f1b27a4ec3efb7dc894b8cf59113d2 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Thu, 12 Nov 2020 12:44:30 +0100
Subject: [PATCH v3 1/4] libavutil: introduce AVFilmGrainParams side data

This patch introduces a new frame side data type AVFilmGrainParams for use
with video codecs which are able to use it.

It is generalized rather than being AV1 specific as AV2 is expected to carry
the same data, as well as the fact there already exist rarely-used 
specifications
for both H.264 and HEVC.


This part of the commit message is no longer true, so remove it.


---
 doc/APIchanges|   4 +
 libavutil/Makefile|   2 +
 libavutil/film_grain_params.c |  42 +
 libavutil/film_grain_params.h | 156 ++
 libavutil/frame.c |   1 +
 libavutil/frame.h |   6 ++
 libavutil/version.h   |   2 +-
 7 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/film_grain_params.c
 create mode 100644 libavutil/film_grain_params.h

diff --git a/doc/APIchanges b/doc/APIchanges
index b70c78a483..41248724d9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-xx-xx - xx - lavu 56.61.100 - film_grain_params.h

+  Adds a new API for extracting codec film grain parameters as side data.
+  Adds a new AVFrameSideDataType entry AV_FRAME_DATA_FILM_GRAIN_PARAMS for it.
+
 2020-xx-xx - xx - lavf 58.64.100 - avformat.h
   Add AVSTREAM_EVENT_FLAG_NEW_PACKETS.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile

index 9b08372eb2..27bafe9e12 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -84,6 +84,7 @@ HEADERS = adler32.h   
  \
   xtea.h\
   tea.h \
   tx.h  \
+  film_grain_params.h   \
 
 HEADERS-$(CONFIG_LZO)   += lzo.h
 
@@ -170,6 +171,7 @@ OBJS = adler32.o\

tx_double.o  \
tx_int32.o   \
video_enc_params.o   \
+   film_grain_params.o  \
 
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o

diff --git a/libavutil/film_grain_params.c b/libavutil/film_grain_params.c
new file mode 100644
index 00..930d23c7fe
--- /dev/null
+++ b/libavutil/film_grain_params.c
@@ -0,0 +1,42 @@
+/**
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "film_grain_params.h"
+
+AVFilmGrainParams *av_film_grain_params_alloc(size_t *size)
+{
+AVFilmGrainParams *params = av_mallocz(sizeof(AVFilmGrainParams));
+
+if (size)
+*size = sizeof(*params);
+
+return params;
+}
+
+AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame)
+{
+AVFrameSideData *side_data = av_frame_new_side_data(frame,
+
AV_FRAME_DATA_FILM_GRAIN_PARAMS,
+
sizeof(AVFilmGrainParams));
+if (!side_data)
+return NULL;
+
+memset(side_data->data, 0, sizeof(AVFilmGrainParams));
+
+return (AVFilmGrainParams *)side_data->data;
+}
diff --git a/libavutil/film_grain_params.h b/libavutil/film_grain_params.h
new file mode 100644
index 00..978fc289c9
--- /dev/null
+++ b/libavutil/film_grain_params.h
@@ -0,0 +1,156 @@
+/*
+ * 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
+ * MERCHANTABILIT

Re: [FFmpeg-devel] [PATCH v2 1/3] libavutil: introduce AVFilmGrainParams side data

2020-11-23 Thread Lynne
Nov 22, 2020, 21:28 by jamr...@gmail.com:

> On 11/12/2020 4:28 PM, Lynne wrote:
>
>> Nov 12, 2020, 19:46 by jamr...@gmail.com:
>>
>>> On 11/12/2020 2:42 PM, Lynne wrote:
>>>
 This patch introduces a new frame side data type AVFilmGrainParams for use
 with video codecs which are able to use it.

 It is generalized rather than being AV1 specific as AV2 is expected to 
 carry
 the same data, as well as the fact there already exist rarely-used 
 specifications
 for both H.264 and HEVC.

 Patch attached.

  From 522e3a80f44129c98f0c564d44815dbe6a740568 Mon Sep 17 00:00:00 2001
 From: Lynne 
 Date: Thu, 12 Nov 2020 12:44:30 +0100
 Subject: [PATCH v2 1/3] libavutil: introduce AVFilmGrainParams side data

 This patch introduces a new frame side data type AVFilmGrainParams for use
 with video codecs which are able to use it.

 It is generalized rather than being AV1 specific as AV2 is expected to 
 carry
 the same data, as well as the fact there already exist rarely-used 
 specifications
 for both H.264 and HEVC.
 ---
  doc/APIchanges|   4 +
  libavutil/Makefile|   2 +
  libavutil/film_grain_params.c |  42 +
  libavutil/film_grain_params.h | 159 ++
  libavutil/frame.c |   1 +
  libavutil/frame.h |   6 ++
  libavutil/version.h   |   2 +-
  7 files changed, 215 insertions(+), 1 deletion(-)
  create mode 100644 libavutil/film_grain_params.c
  create mode 100644 libavutil/film_grain_params.h

 diff --git a/doc/APIchanges b/doc/APIchanges
 index b70c78a483..41248724d9 100644
 --- a/doc/APIchanges
 +++ b/doc/APIchanges
 @@ -15,6 +15,10 @@ libavutil: 2017-10-21
  API changes, most recent first:
  +2020-xx-xx - xx - lavu 56.61.100 - film_grain_params.h
 +  Adds a new API for extracting codec film grain parameters as side data.
 +  Adds a new AVFrameSideDataType entry AV_FRAME_DATA_FILM_GRAIN_PARAMS 
 for it.
 +
  2020-xx-xx - xx - lavf 58.64.100 - avformat.h
  Add AVSTREAM_EVENT_FLAG_NEW_PACKETS.
  diff --git a/libavutil/Makefile b/libavutil/Makefile
 index 9b08372eb2..27bafe9e12 100644
 --- a/libavutil/Makefile
 +++ b/libavutil/Makefile
 @@ -84,6 +84,7 @@ HEADERS = adler32.h  
\
  xtea.h\
  tea.h \
  tx.h  \
 +  film_grain_params.h   \
  HEADERS-$(CONFIG_LZO)   += lzo.h
  @@ -170,6 +171,7 @@ OBJS = adler32.o  
   \
  tx_double.o  \
  tx_int32.o   \
  video_enc_params.o   \
 +   film_grain_params.o  \
  OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 diff --git a/libavutil/film_grain_params.c b/libavutil/film_grain_params.c
 new file mode 100644
 index 00..930d23c7fe
 --- /dev/null
 +++ b/libavutil/film_grain_params.c
 @@ -0,0 +1,42 @@
 +/**
 + * This file is part of FFmpeg.
 + *
 + * FFmpeg is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2.1 of the License, or (at your option) any later version.
 + *
 + * FFmpeg is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with FFmpeg; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301 USA
 + */
 +
 +#include "film_grain_params.h"
 +
 +AVFilmGrainParams *av_film_grain_params_alloc(size_t *size)
 +{
 +AVFilmGrainParams *params = av_mallocz(sizeof(AVFilmGrainParams));
 +
 +if (size)
 +*size = sizeof(*params);
 +
 +return params;
 +}
 +
 +AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame)
 +{
 +AVFrameSideData *side_data = av_frame_new_side_data(frame,
 +
 AV_FRAME_DATA_FILM_GRAIN_PARAMS,
 +  

Re: [FFmpeg-devel] [PATCH] avformat/mov: adjust skip_samples according to seek timestamp

2020-11-23 Thread Matthieu Bouron
On Tue, Nov 17, 2020 at 02:18:46PM +0100, Matthieu Bouron wrote:
> On Mon, Nov 09, 2020 at 06:26:46PM +0100, Matthieu Bouron wrote:
> > On Mon, Nov 02, 2020 at 12:42:19PM +0100, Matthieu Bouron wrote:
> > > Currently skip_samples is set to start_pad if sample_time is lesser or
> > > equal to 0. This can cause issues if the stream starts with packets that
> > > have negative pts. Calling avformat_seek_file() with ts set to 0 on such
> > > streams makes the mov demuxer return the right corresponding packets
> > > (near the 0 timestamp) but set skip_samples to start_pad which is
> > > incorrect as the audio decoder will discard the returned samples
> > > according to skip_samples from the first packet it receives (which has
> > > its timestamp near 0).
> > > 
> > > For example, considering the following audio stream with start_pad=1344:
> > > 
> > >  [PKT pts=-1344] [PKT pts=-320] [PKT pts=704] [PKT pts=1728] [...]
> > > 
> > > Calling avformat_seek_file() with ts=0 makes the next call to
> > > av_read_frame() return the packet with pts=-320 and a skip samples
> > > side data set to 1344 (start_pad). This makes the audio decoder
> > > incorrectly discard (1344 - 320) samples.
> > > 
> > > This commit makes the move demuxer adjust skip_samples according to the
> > > stream start_pad, seek timestamp and first sample timestamp.
> > > 
> > > The above example will now result in av_read_frame() still returning the
> > > packet with pts=-320 but with a skip samples side data set to 320
> > > (src_pad - (seek_timestamp - first_timestamp)). This makes the audio
> > > decoder only discard 320 samples (from pts=-320 to pts=0).
> > > ---
> > >  libavformat/mov.c | 18 --
> > >  1 file changed, 16 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > > index dd0db6bca79..f99cb0df25a 100644
> > > --- a/libavformat/mov.c
> > > +++ b/libavformat/mov.c
> > > @@ -8098,20 +8098,34 @@ static int mov_read_seek(AVFormatContext *s, int 
> > > stream_index, int64_t sample_ti
> > >  return sample;
> > >  
> > >  if (mc->seek_individually) {
> > > +MOVStreamContext *sc = s->streams[stream_index]->priv_data;
> > > +
> > >  /* adjust seek timestamp to found sample timestamp */
> > > +int64_t first_timestamp = 
> > > st->internal->index_entries[0].timestamp;
> > >  int64_t seek_timestamp = 
> > > st->internal->index_entries[sample].timestamp;
> > >  
> > > +/* adjust skip samples according to stream start_pad, seek 
> > > timestamp and first timestamp */
> > > +int64_t skip_samples = FFMAX(sc->start_pad - (seek_timestamp - 
> > > first_timestamp), 0);
> > > +st->internal->skip_samples = skip_samples;
> > > +
> > >  for (i = 0; i < s->nb_streams; i++) {
> > >  int64_t timestamp;
> > >  MOVStreamContext *sc = s->streams[i]->priv_data;
> > >  st = s->streams[i];
> > > -st->internal->skip_samples = (sample_time <= 0) ? 
> > > sc->start_pad : 0;
> > >  
> > >  if (stream_index == i)
> > >  continue;
> > >  
> > >  timestamp = av_rescale_q(seek_timestamp, 
> > > s->streams[stream_index]->time_base, st->time_base);
> > > -mov_seek_stream(s, st, timestamp, flags);
> > > +sample = mov_seek_stream(s, st, timestamp, flags);
> > > +if (sample >= 0) {
> > > +first_timestamp = 
> > > st->internal->index_entries[0].timestamp;
> > > +seek_timestamp = 
> > > st->internal->index_entries[sample].timestamp;
> > > +
> > > +/* adjust skip samples according to stream start_pad, 
> > > seek timestamp and first timestamp */
> > > +skip_samples = FFMAX(sc->start_pad - (seek_timestamp - 
> > > first_timestamp), 0);
> > > +st->internal->skip_samples = skip_samples;
> > > +}
> > >  }
> > >  } else {
> > >  for (i = 0; i < s->nb_streams; i++) {
> > > -- 
> > > 2.29.2
> > > 
> > 
> > Ping.
> > 
> 
> Ping.
> 

Ping.

-- 
Matthieu B.
___
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: add asupcut filter

2020-11-23 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  15 +++
 libavfilter/Makefile |   1 +
 libavfilter/af_asupcut.c | 248 +++
 libavfilter/allfilters.c |   1 +
 4 files changed, 265 insertions(+)
 create mode 100644 libavfilter/af_asupcut.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 15acae9709..f8a8012b16 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2586,6 +2586,21 @@ Default value is 20.
 
 This filter supports the all above options as @ref{commands}.
 
+@section asupcut
+Cut super frequencies.
+
+The filter accepts the following options:
+
+@table @option
+@item cutoff
+Set cutoff frequency in herz. Allowed range is 2 to 192000.
+Default value is 2.
+@end table
+
+@subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section atempo
 
 Adjust audio tempo.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 36f3d2d0e4..47094b7157 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -90,6 +90,7 @@ OBJS-$(CONFIG_ASR_FILTER)+= af_asr.o
 OBJS-$(CONFIG_ASTATS_FILTER) += af_astats.o
 OBJS-$(CONFIG_ASTREAMSELECT_FILTER)  += f_streamselect.o framesync.o
 OBJS-$(CONFIG_ASUBBOOST_FILTER)  += af_asubboost.o
+OBJS-$(CONFIG_ASUPCUT_FILTER)+= af_asupcut.o
 OBJS-$(CONFIG_ATEMPO_FILTER) += af_atempo.o
 OBJS-$(CONFIG_ATRIM_FILTER)  += trim.o
 OBJS-$(CONFIG_AXCORRELATE_FILTER)+= af_axcorrelate.o
diff --git a/libavfilter/af_asupcut.c b/libavfilter/af_asupcut.c
new file mode 100644
index 00..4a25a12844
--- /dev/null
+++ b/libavfilter/af_asupcut.c
@@ -0,0 +1,248 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/channel_layout.h"
+#include "libavutil/ffmath.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "audio.h"
+#include "formats.h"
+
+typedef struct BiquadCoeffs {
+double a1, a2;
+double b0, b1, b2;
+} BiquadCoeffs;
+
+typedef struct ASupCutContext {
+const AVClass *class;
+
+double cutoff;
+
+int bypass;
+
+BiquadCoeffs coeffs[5];
+
+AVFrame *w;
+} ASupCutContext;
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats = NULL;
+AVFilterChannelLayouts *layouts = NULL;
+static const enum AVSampleFormat sample_fmts[] = {
+AV_SAMPLE_FMT_DBLP,
+AV_SAMPLE_FMT_NONE
+};
+int ret;
+
+formats = ff_make_format_list(sample_fmts);
+if (!formats)
+return AVERROR(ENOMEM);
+ret = ff_set_common_formats(ctx, formats);
+if (ret < 0)
+return ret;
+
+layouts = ff_all_channel_counts();
+if (!layouts)
+return AVERROR(ENOMEM);
+
+ret = ff_set_common_channel_layouts(ctx, layouts);
+if (ret < 0)
+return ret;
+
+formats = ff_all_samplerates();
+return ff_set_common_samplerates(ctx, formats);
+}
+
+static int get_coeffs(AVFilterContext *ctx)
+{
+ASupCutContext *s = ctx->priv;
+AVFilterLink *inlink = ctx->inputs[0];
+double w0 = s->cutoff / inlink->sample_rate;
+double K = tan(M_PI * w0);
+double q[5];
+
+if (w0 >= 0.5) {
+s->bypass = 1;
+return 0;
+}
+
+q[0] = 0.50623256;
+q[1] = 0.56116312;
+q[2] = 0.70710678;
+q[3] = 1.10134463;
+q[4] = 3.19622661;
+
+for (int b = 0; b < 5; b++) {
+BiquadCoeffs *coeffs = &s->coeffs[b];
+double norm = 1.0 / (1.0 + K / q[b] + K * K);
+
+coeffs->b0 = K * K * norm;
+coeffs->b1 = 2.0 * coeffs->b0;
+coeffs->b2 = coeffs->b0;
+coeffs->a1 = -2.0 * (K * K - 1.0) * norm;
+coeffs->a2 = -(1.0 - K / q[b] + K * K) * norm;
+}
+
+return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+AVFilterContext *ctx = inlink->dst;
+ASupCutContext *s = ctx->priv;
+
+s->w = ff_get_audio_buffer(inlink, 2 * 5);
+if (!s->w)
+return AVERROR(ENOMEM);
+
+return get_coeffs(ctx);
+}
+
+typedef struct ThreadData {
+AVFrame *in, *out;
+} ThreadData;
+
+static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+ASupCutContext *s = ctx->priv;
+ThreadData *td = arg;
+AVFram

[FFmpeg-devel] [PATCH] libavformat/avidec.c: remove duplicated conversion

2020-11-23 Thread Thierry Foucu
ff_riff_info_conv deals with riff metadata already, so, not need to add
those metadata in avi_metadata_conv
---
 libavformat/avidec.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 7e527e15ee..75a76b995d 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -110,14 +110,6 @@ static const char avi_headers[][8] = {
 
 static const AVMetadataConv avi_metadata_conv[] = {
 { "strn", "title" },
-{ "isbj", "subject" },
-{ "inam", "title" },
-{ "iart", "artist" },
-{ "icop", "copyright" },
-{ "icmt", "comment" },
-{ "ignr", "genre" },
-{ "iprd", "product" },
-{ "isft", "software" },
 
 { 0 },
 };
-- 
2.29.2.454.gaff20da3a2-goog

___
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/av1: add support for passing through MP4/Matroska av1c

2020-11-23 Thread Jan Ekström
---
 libavformat/av1.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavformat/av1.c b/libavformat/av1.c
index 0cbffb1fd8..5512c4e0f7 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -375,6 +375,20 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t 
*buf, int size)
 if (size <= 0)
 return AVERROR_INVALIDDATA;
 
+if (buf[0] & 0x80) {
+// first bit is nonzero, the passed data does not consist purely of
+// OBUs. Expect that the data is already in AV1CodecConfigurationRecord
+// format.
+int config_record_version = buf[0] & 0x7f;
+if (config_record_version != 1 || size < 4) {
+return AVERROR_INVALIDDATA;
+}
+
+avio_write(pb, buf, size);
+
+return 0;
+}
+
 ret = avio_open_dyn_buf(&meta_pb);
 if (ret < 0)
 return ret;
-- 
2.28.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 5/6] avformat/mov: remove special handling of av1c extradata

2020-11-23 Thread Jan Ekström
Libavcodec can now handle the AV1CodecConfigurationRecord structure
as-is when passed as extradata, so the standard behavior of
read-box-into-extradata should suffice, just like with AVC and HEVC.
---
 libavformat/mov.c | 30 +-
 1 file changed, 1 insertion(+), 29 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2b90e31170..2698269b4d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5324,34 +5324,6 @@ static int mov_read_tmcd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
-static int mov_read_av1c(MOVContext *c, AVIOContext *pb, MOVAtom atom)
-{
-AVStream *st;
-int ret;
-
-if (c->fc->nb_streams < 1)
-return 0;
-st = c->fc->streams[c->fc->nb_streams - 1];
-
-if (atom.size < 4) {
-av_log(c->fc, AV_LOG_ERROR, "Empty AV1 Codec Configuration Box\n");
-return AVERROR_INVALIDDATA;
-}
-
-/* For now, propagate only the OBUs, if any. Once libavcodec is
-   updated to handle isobmff style extradata this can be removed. */
-avio_skip(pb, 4);
-
-if (atom.size == 4)
-return 0;
-
-ret = ff_get_extradata(c->fc, st->codecpar, pb, atom.size - 4);
-if (ret < 0)
-return ret;
-
-return 0;
-}
-
 static int mov_read_vpcc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 AVStream *st;
@@ -6875,7 +6847,7 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('A','A','L','P'), mov_read_avid },
 { MKTAG('A','R','E','S'), mov_read_ares },
 { MKTAG('a','v','s','s'), mov_read_avss },
-{ MKTAG('a','v','1','C'), mov_read_av1c },
+{ MKTAG('a','v','1','C'), mov_read_glbl },
 { MKTAG('c','h','p','l'), mov_read_chpl },
 { MKTAG('c','o','6','4'), mov_read_stco },
 { MKTAG('c','o','l','r'), mov_read_colr },
-- 
2.28.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 0/6] Add support for utilizing av1c as extradata

2020-11-23 Thread Jan Ekström
Until now an API user with a non-libavformat MP4 or Matroska demuxer
would have had to manually filter the extradata to skip the first four
bytes when passing data to libavcodec, so that only the OBUs would
remain. Now the AV1CodecConfigurationRecord structure can be passed
to libavcodec as-is. This is lets it to be dealt with in a similar
manner to AVC or HEVC.

This is done in the following steps:
1. A nice helper by Mark is added so that it can be utilized in stead
   of ff_cbs_read from both the decoder and parser after the CBS gains
   the capability to handle AV1CodecConfigurationRecord structures.
2. Support is added to AV1 CBS for handling AV1CodecConfigurationRecord
   in a similar vein to AVC/HEVC's avcc/hvcc handling.
3. AV1 decoder and parser are switched to utilize the newly added
   helper functionality.
4. Support is added for writing out the passed AV1CodecConfigurationRecord
   in ff_isom_write_av1c, which is called from the MP4 and Matroska
   writers.
5. Finally, both MP4 and Matroska demuxers are changed to expose the
   full AV1CodecConfigurationRecord as extradata. 

Jan Ekström (5):
  avcodec/cbs_av1: add support for standard MP4/Matroska extradata
  avcodec/av1{dec,parser}: move to ff_cbs_read_extradata_from_codec
  avformat/av1: add support for passing through MP4/Matroska av1c
  avformat/mov: remove special handling of av1c extradata
  avformat/matroskadec: remove special handling of av1c extradata

Mark Thompson (1):
  cbs: Add function to read extradata from an AVCodecContext

 libavcodec/av1_parser.c   |  2 +-
 libavcodec/av1dec.c   |  5 ++-
 libavcodec/cbs.c  | 77 ---
 libavcodec/cbs.h  | 11 ++
 libavcodec/cbs_av1.c  | 34 +
 libavformat/av1.c | 14 +++
 libavformat/matroskadec.c |  4 --
 libavformat/mov.c | 30 +--
 8 files changed, 103 insertions(+), 74 deletions(-)

-- 
2.28.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 6/6] avformat/matroskadec: remove special handling of av1c extradata

2020-11-23 Thread Jan Ekström
Libavcodec can now handle the standard AV1CodecConfigurationRecord
extradata as-is.
---
 libavformat/matroskadec.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 44db2c8358..da0fadd47a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2661,10 +2661,6 @@ static int matroska_parse_tracks(AVFormatContext *s)
 /* we don't need any value stored in CodecPrivate.
make sure that it's not exported as extradata. */
 track->codec_priv.size = 0;
-} else if (codec_id == AV_CODEC_ID_AV1 && track->codec_priv.size) {
-/* For now, propagate only the OBUs, if any. Once libavcodec is
-   updated to handle isobmff style extradata this can be removed. 
*/
-extradata_offset = 4;
 }
 track->codec_priv.size -= extradata_offset;
 
-- 
2.28.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 1/6] cbs: Add function to read extradata from an AVCodecContext

2020-11-23 Thread Jan Ekström
From: Mark Thompson 

This is useful in decoders and parsers, matching the way that bitstream
filters read extradata from AVCodecParameters.
---
 libavcodec/cbs.c | 77 
 libavcodec/cbs.h | 11 +++
 2 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index c8c526ab12..f98531e131 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -223,66 +223,67 @@ static int cbs_fill_fragment_data(CodedBitstreamFragment 
*frag,
 return 0;
 }
 
-int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
-  CodedBitstreamFragment *frag,
-  const AVCodecParameters *par)
+static int cbs_read_data(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag,
+ AVBufferRef *buf,
+ const uint8_t *data, size_t size,
+ int header)
 {
 int err;
 
-err = cbs_fill_fragment_data(frag, par->extradata,
- par->extradata_size);
-if (err < 0)
-return err;
-
-err = ctx->codec->split_fragment(ctx, frag, 1);
-if (err < 0)
-return err;
-
-return cbs_read_fragment_content(ctx, frag);
-}
-
-int ff_cbs_read_packet(CodedBitstreamContext *ctx,
-   CodedBitstreamFragment *frag,
-   const AVPacket *pkt)
-{
-int err;
-
-if (pkt->buf) {
-frag->data_ref = av_buffer_ref(pkt->buf);
+if (buf) {
+frag->data_ref = av_buffer_ref(buf);
 if (!frag->data_ref)
 return AVERROR(ENOMEM);
 
-frag->data  = pkt->data;
-frag->data_size = pkt->size;
+frag->data  = (uint8_t *)data;
+frag->data_size = size;
 
 } else {
-err = cbs_fill_fragment_data(frag, pkt->data, pkt->size);
+err = cbs_fill_fragment_data(frag, data, size);
 if (err < 0)
 return err;
 }
 
-err = ctx->codec->split_fragment(ctx, frag, 0);
+err = ctx->codec->split_fragment(ctx, frag, header);
 if (err < 0)
 return err;
 
 return cbs_read_fragment_content(ctx, frag);
 }
 
-int ff_cbs_read(CodedBitstreamContext *ctx,
-CodedBitstreamFragment *frag,
-const uint8_t *data, size_t size)
+int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
+  CodedBitstreamFragment *frag,
+  const AVCodecParameters *par)
 {
-int err;
+return cbs_read_data(ctx, frag, NULL,
+ par->extradata,
+ par->extradata_size, 1);
+}
 
-err = cbs_fill_fragment_data(frag, data, size);
-if (err < 0)
-return err;
+int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag,
+ const AVCodecContext *avctx)
+{
+return cbs_read_data(ctx, frag, NULL,
+ avctx->extradata,
+ avctx->extradata_size, 1);
+}
 
-err = ctx->codec->split_fragment(ctx, frag, 0);
-if (err < 0)
-return err;
+int ff_cbs_read_packet(CodedBitstreamContext *ctx,
+   CodedBitstreamFragment *frag,
+   const AVPacket *pkt)
+{
+return cbs_read_data(ctx, frag, pkt->buf,
+ pkt->data, pkt->size, 0);
+}
 
-return cbs_read_fragment_content(ctx, frag);
+int ff_cbs_read(CodedBitstreamContext *ctx,
+CodedBitstreamFragment *frag,
+const uint8_t *data, size_t size)
+{
+return cbs_read_data(ctx, frag, NULL,
+ data, size, 0);
 }
 
 static int cbs_write_unit_data(CodedBitstreamContext *ctx,
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 635921b11e..3fd0a0ef33 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -262,6 +262,17 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
   CodedBitstreamFragment *frag,
   const AVCodecParameters *par);
 
+/**
+ * Read the extradata bitstream found in a codec context into a
+ * fragment, then split into units and decompose.
+ *
+ * This acts identical to ff_cbs_read_extradata() for the case where
+ * you already have a codec context.
+ */
+int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag,
+ const AVCodecContext *avctx);
+
 /**
  * Read the data bitstream from a packet into a fragment, then
  * split into units and decompose.
-- 
2.28.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/6] avcodec/av1{dec, parser}: move to ff_cbs_read_extradata_from_codec

2020-11-23 Thread Jan Ekström
This lets us re-utilize the extradata-related checks in the CBS
to add support for passing the AV1CodecConfigurationRecord
as extradata as-is without further filtering.
---
 libavcodec/av1_parser.c | 2 +-
 libavcodec/av1dec.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
index 14826d816e..181ff3a1be 100644
--- a/libavcodec/av1_parser.c
+++ b/libavcodec/av1_parser.c
@@ -73,7 +73,7 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
 if (avctx->extradata_size && !s->parsed_extradata) {
 s->parsed_extradata = 1;
 
-ret = ff_cbs_read(s->cbc, td, avctx->extradata, avctx->extradata_size);
+ret = ff_cbs_read_extradata_from_codec(s->cbc, td, avctx);
 if (ret < 0) {
 av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata.\n");
 }
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index c1967f03bd..ce051d4e6d 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -616,8 +616,9 @@ static av_cold int av1_decode_init(AVCodecContext *avctx)
 return ret;
 
 if (avctx->extradata && avctx->extradata_size) {
-ret = ff_cbs_read(s->cbc, &s->current_obu, avctx->extradata,
-  avctx->extradata_size);
+ret = ff_cbs_read_extradata_from_codec(s->cbc,
+   &s->current_obu,
+   avctx);
 if (ret < 0) {
 av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
 return ret;
-- 
2.28.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] libavformat/avidec: Extract more metadata from the header

2020-11-23 Thread Thierry Foucu
On Wed, Nov 11, 2020 at 7:39 AM Anton Khirnov  wrote:

> Quoting Thierry Foucu (2020-11-07 00:10:17)
> > ---
> >  libavformat/avidec.c | 17 +
> >  1 file changed, 17 insertions(+)
> >
> > diff --git a/libavformat/avidec.c b/libavformat/avidec.c
> > index 578cf68ce1..7e527e15ee 100644
> > --- a/libavformat/avidec.c
> > +++ b/libavformat/avidec.c
> > @@ -110,6 +110,15 @@ static const char avi_headers[][8] = {
> >
> >  static const AVMetadataConv avi_metadata_conv[] = {
> >  { "strn", "title" },
> > +{ "isbj", "subject" },
> > +{ "inam", "title" },
> > +{ "iart", "artist" },
> > +{ "icop", "copyright" },
> > +{ "icmt", "comment" },
> > +{ "ignr", "genre" },
> > +{ "iprd", "product" },
> > +{ "isft", "software" },
> > +
>
> This seems duplicated with ff_riff_info_conv.
>

Thanks for pointing this out.
I will send a Patch to remove them


>
> --
> Anton Khirnov
> ___
> 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".



-- 

Thierry Foucu
___
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] avcodec/cbs_av1: add support for standard MP4/Matroska extradata

2020-11-23 Thread Jan Ekström
This way API clients can just pass the AV1CodecConfigurationRecord
as extradata as-is without further filtering.
---
 libavcodec/cbs_av1.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 9badfe31e4..9ae2f59872 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -758,6 +758,39 @@ static int cbs_av1_split_fragment(CodedBitstreamContext 
*ctx,
 goto fail;
 }
 
+if (header && size && data[0] & 0x80) {
+// first bit is nonzero, the extradata does not consist purely of
+// OBUs. Expect MP4/Matroska AV1CodecConfigurationRecord
+int config_record_version = data[0] & 0x7f;
+
+if (config_record_version != 1) {
+av_log(ctx->log_ctx, AV_LOG_ERROR,
+   "Unknown version %d of AV1CodecConfigurationRecord "
+   "found!\n",
+   config_record_version);
+err = AVERROR_INVALIDDATA;
+goto fail;
+}
+
+if (size <= 4) {
+if (size < 4) {
+av_log(ctx->log_ctx, AV_LOG_WARNING,
+   "Undersized AV1CodecConfigurationRecord v%d found!\n",
+   config_record_version);
+err = AVERROR_INVALIDDATA;
+goto fail;
+}
+
+goto success;
+}
+
+// In AV1CodecConfigurationRecord v1, actual OBUs start after
+// four bytes. Thus set the offset as required for properly
+// parsing them.
+data += 4;
+size -= 4;
+}
+
 while (size > 0) {
 AV1RawOBUHeader header;
 uint64_t obu_size;
@@ -803,6 +836,7 @@ static int cbs_av1_split_fragment(CodedBitstreamContext 
*ctx,
 size -= obu_length;
 }
 
+success:
 err = 0;
 fail:
 ctx->trace_enable = trace;
-- 
2.28.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 165/191] avcodec/sinewin_tablegen: Use better check in assert

2020-11-23 Thread Andreas Rheinhardt
There are no ff_sine_windows for 2^i, 0 <= i < 5, so one should check
for the index being >= 5.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/sinewin_tablegen.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/sinewin_tablegen.h b/libavcodec/sinewin_tablegen.h
index dc52234ed0..3c11cb6282 100644
--- a/libavcodec/sinewin_tablegen.h
+++ b/libavcodec/sinewin_tablegen.h
@@ -74,7 +74,7 @@ av_cold void AAC_RENAME(ff_sine_window_init)(INTFLOAT 
*window, int n) {
 }
 
 av_cold void AAC_RENAME(ff_init_ff_sine_windows)(int index) {
-assert(index >= 0 && index < FF_ARRAY_ELEMS(AAC_RENAME(ff_sine_windows)));
+assert(index >= 5 && index < FF_ARRAY_ELEMS(AAC_RENAME(ff_sine_windows)));
 #if !CONFIG_HARDCODED_TABLES
 AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_windows)[index], 1 << 
index);
 #endif
-- 
2.25.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 166/191] avcodec/aacdec, sinewin: Move 120 and 960 point sine tables to aacdec

2020-11-23 Thread Andreas Rheinhardt
The floating point AAC decoder is the only user of these tables, so it
makes sense to move them there. Furthermore, initializing the ordinary
power-of-two sinetables is currently not thread-safe and if the 120- and
960-point sinetables were not moved, one would have to choose whether
to guard initializing these two tables with their own AVOnces or not.
Doing so would add unnecessary AVOnces as the AAC decoder already guards
initializing its static data by an AVOnce; not doing so would be fragile
if a second user of these tables were to be added.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/aacdec.c|  3 +++
 libavcodec/aacdec_template.c   | 10 +-
 libavcodec/sinewin.h   |  5 -
 libavcodec/sinewin_tablegen.h  |  4 
 libavcodec/sinewin_tablegen_template.c |  2 --
 5 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index d17852d8ba..fd4805f6eb 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -69,6 +69,9 @@
 #   include "mips/aacdec_mips.h"
 #endif
 
+DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(sine_120))[120];
+DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(sine_960))[960];
+
 static av_always_inline void reset_predict_state(PredictorState *ps)
 {
 ps->r0   = 0.0f;
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 186175e6e6..e6fe913a27 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1235,8 +1235,8 @@ static av_cold void aac_static_table_init(void)
 #if !USE_FIXED
 AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_long_960), 4.0, 960);
 AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_short_120), 6.0, 120);
-AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_960), 960);
-AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_120), 120);
+AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_960), 960);
+AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_120), 120);
 #endif
 AAC_RENAME(ff_init_ff_sine_windows)(10);
 AAC_RENAME(ff_init_ff_sine_windows)( 9);
@@ -2810,9 +2810,9 @@ static void imdct_and_windowing_960(AACContext *ac, 
SingleChannelElement *sce)
 INTFLOAT *in= sce->coeffs;
 INTFLOAT *out   = sce->ret;
 INTFLOAT *saved = sce->saved;
-const INTFLOAT *swindow  = ics->use_kb_window[0] ? 
AAC_RENAME(ff_aac_kbd_short_120) : AAC_RENAME(ff_sine_120);
-const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? 
AAC_RENAME(ff_aac_kbd_long_960) : AAC_RENAME(ff_sine_960);
-const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? 
AAC_RENAME(ff_aac_kbd_short_120) : AAC_RENAME(ff_sine_120);
+const INTFLOAT *swindow  = ics->use_kb_window[0] ? 
AAC_RENAME(ff_aac_kbd_short_120) : AAC_RENAME(sine_120);
+const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? 
AAC_RENAME(ff_aac_kbd_long_960) : AAC_RENAME(sine_960);
+const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? 
AAC_RENAME(ff_aac_kbd_short_120) : AAC_RENAME(sine_120);
 INTFLOAT *buf  = ac->buf_mdct;
 INTFLOAT *temp = ac->temp;
 int i;
diff --git a/libavcodec/sinewin.h b/libavcodec/sinewin.h
index 329e9bb5be..7b64096a71 100644
--- a/libavcodec/sinewin.h
+++ b/libavcodec/sinewin.h
@@ -38,9 +38,6 @@
 #define SINETABLE(size) \
 SINETABLE_CONST DECLARE_ALIGNED(32, INTFLOAT, 
AAC_RENAME(ff_sine_##size))[size]
 
-#define SINETABLE120960(size) \
-DECLARE_ALIGNED(32, INTFLOAT, AAC_RENAME(ff_sine_##size))[size]
-
 /**
  * Generate a sine window.
  * @param   window  pointer to half window
@@ -55,11 +52,9 @@ void AAC_RENAME(ff_init_ff_sine_windows)(int index);
 
 extern SINETABLE(  32);
 extern SINETABLE(  64);
-extern SINETABLE120960(120);
 extern SINETABLE( 128);
 extern SINETABLE( 256);
 extern SINETABLE( 512);
-extern SINETABLE120960(960);
 extern SINETABLE(1024);
 extern SINETABLE(2048);
 extern SINETABLE(4096);
diff --git a/libavcodec/sinewin_tablegen.h b/libavcodec/sinewin_tablegen.h
index 3c11cb6282..1959074189 100644
--- a/libavcodec/sinewin_tablegen.h
+++ b/libavcodec/sinewin_tablegen.h
@@ -31,10 +31,6 @@
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
 
-#if !USE_FIXED
-SINETABLE120960(120);
-SINETABLE120960(960);
-#endif
 #if !CONFIG_HARDCODED_TABLES
 SINETABLE(  32);
 SINETABLE(  64);
diff --git a/libavcodec/sinewin_tablegen_template.c 
b/libavcodec/sinewin_tablegen_template.c
index b8eb407bd8..43ce1ba82e 100644
--- a/libavcodec/sinewin_tablegen_template.c
+++ b/libavcodec/sinewin_tablegen_template.c
@@ -33,8 +33,6 @@
 #define SINETABLE_CONST
 #define SINETABLE(size) \
 INTFLOAT AAC_RENAME(ff_sine_##size)[size]
-#define SINETABLE120960(size) \
-INTFLOAT AAC_RENAME(ff_sine_##size)[size]
 #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
 #include "sinewin_tablegen.h"
 #include "tableprint.h"
-- 
2.25.1

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

[FFmpeg-devel] [PATCH 167/191] avcodec/sinewin_tablegen: Make initializing ff_sine_windows thread-safe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/sinewin_tablegen.h  | 43 ++
 libavcodec/sinewin_tablegen_template.c |  1 +
 2 files changed, 44 insertions(+)

diff --git a/libavcodec/sinewin_tablegen.h b/libavcodec/sinewin_tablegen.h
index 1959074189..ced3b7874c 100644
--- a/libavcodec/sinewin_tablegen.h
+++ b/libavcodec/sinewin_tablegen.h
@@ -32,6 +32,10 @@
 #include "libavutil/common.h"
 
 #if !CONFIG_HARDCODED_TABLES
+#ifndef BUILD_TABLES
+#include "libavutil/thread.h"
+#endif
+
 SINETABLE(  32);
 SINETABLE(  64);
 SINETABLE( 128);
@@ -69,10 +73,49 @@ av_cold void AAC_RENAME(ff_sine_window_init)(INTFLOAT 
*window, int n) {
 window[i] = SIN_FIX(sinf((i + 0.5) * (M_PI / (2.0 * n;
 }
 
+#if !CONFIG_HARDCODED_TABLES && !defined(BUILD_TABLES)
+#define INIT_FF_SINE_WINDOW_INIT_FUNC(index)\
+static void init_ff_sine_window_ ## index(void) \
+{   \
+AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_windows)[index], 1 << 
index);\
+}
+
+INIT_FF_SINE_WINDOW_INIT_FUNC(5)
+INIT_FF_SINE_WINDOW_INIT_FUNC(6)
+INIT_FF_SINE_WINDOW_INIT_FUNC(7)
+INIT_FF_SINE_WINDOW_INIT_FUNC(8)
+INIT_FF_SINE_WINDOW_INIT_FUNC(9)
+INIT_FF_SINE_WINDOW_INIT_FUNC(10)
+INIT_FF_SINE_WINDOW_INIT_FUNC(11)
+INIT_FF_SINE_WINDOW_INIT_FUNC(12)
+INIT_FF_SINE_WINDOW_INIT_FUNC(13)
+
+static void (*const sine_window_init_func_array[])(void) = {
+init_ff_sine_window_5,
+init_ff_sine_window_6,
+init_ff_sine_window_7,
+init_ff_sine_window_8,
+init_ff_sine_window_9,
+init_ff_sine_window_10,
+init_ff_sine_window_11,
+init_ff_sine_window_12,
+init_ff_sine_window_13,
+};
+
+static AVOnce init_sine_window_once[9] = {
+AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT,
+AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT
+};
+#endif
+
 av_cold void AAC_RENAME(ff_init_ff_sine_windows)(int index) {
 assert(index >= 5 && index < FF_ARRAY_ELEMS(AAC_RENAME(ff_sine_windows)));
 #if !CONFIG_HARDCODED_TABLES
+#ifdef BUILD_TABLES
 AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_windows)[index], 1 << 
index);
+#else
+ff_thread_once(&init_sine_window_once[index - 5], 
sine_window_init_func_array[index - 5]);
+#endif
 #endif
 }
 
diff --git a/libavcodec/sinewin_tablegen_template.c 
b/libavcodec/sinewin_tablegen_template.c
index 43ce1ba82e..7c3c1d8af2 100644
--- a/libavcodec/sinewin_tablegen_template.c
+++ b/libavcodec/sinewin_tablegen_template.c
@@ -23,6 +23,7 @@
 #include 
 #include "libavcodec/aac_defines.h"
 #define CONFIG_HARDCODED_TABLES 0
+#define BUILD_TABLES
 
 #if USE_FIXED
 #define WRITE_FUNC write_int32_t_array
-- 
2.25.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 168/191] avcodec/atrac1: Mark decoder as init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Possible because ff_init_ff_sine_windows() is now threadsafe.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/atrac1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c
index b2a2d5e6a1..31ec323370 100644
--- a/libavcodec/atrac1.c
+++ b/libavcodec/atrac1.c
@@ -392,5 +392,5 @@ AVCodec ff_atrac1_decoder = {
 .capabilities   = AV_CODEC_CAP_DR1,
 .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
   AV_SAMPLE_FMT_NONE },
-.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.25.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 169/191] avcodec/atrac3plus: Make decoder init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/atrac3plus.h|  4 ++--
 libavcodec/atrac3plusdec.c | 16 +++-
 libavcodec/atrac3plusdsp.c |  8 
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/libavcodec/atrac3plus.h b/libavcodec/atrac3plus.h
index 3c39e293c7..82fe0fe1f8 100644
--- a/libavcodec/atrac3plus.h
+++ b/libavcodec/atrac3plus.h
@@ -179,9 +179,9 @@ int ff_atrac3p_decode_channel_unit(GetBitContext *gb, 
Atrac3pChanUnitCtx *ctx,
 void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx);
 
 /**
- * Initialize sine waves synthesizer.
+ * Initialize sine waves synthesizer and ff_sine_* tables.
  */
-void ff_atrac3p_init_wave_synth(void);
+void ff_atrac3p_init_dsp_static(void);
 
 /**
  * Synthesize sine waves for a particular subband.
diff --git a/libavcodec/atrac3plusdec.c b/libavcodec/atrac3plusdec.c
index 4b008ba0ee..b75f7eab5e 100644
--- a/libavcodec/atrac3plusdec.c
+++ b/libavcodec/atrac3plusdec.c
@@ -39,6 +39,7 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/float_dsp.h"
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "get_bits.h"
 #include "internal.h"
@@ -144,8 +145,15 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx,
 return 0;
 }
 
+static av_cold void atrac3p_init_static(void)
+{
+ff_atrac3p_init_vlcs();
+ff_atrac3p_init_dsp_static();
+}
+
 static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
 {
+static AVOnce init_static_once = AV_ONCE_INIT;
 ATRAC3PContext *ctx = avctx->priv_data;
 int i, ch, ret;
 
@@ -154,8 +162,6 @@ static av_cold int atrac3p_decode_init(AVCodecContext 
*avctx)
 return AVERROR(EINVAL);
 }
 
-ff_atrac3p_init_vlcs();
-
 /* initialize IPQF */
 ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0);
 
@@ -163,8 +169,6 @@ static av_cold int atrac3p_decode_init(AVCodecContext 
*avctx)
 
 ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2);
 
-ff_atrac3p_init_wave_synth();
-
 if ((ret = set_channel_params(ctx, avctx)) < 0)
 return ret;
 
@@ -194,6 +198,8 @@ static av_cold int atrac3p_decode_init(AVCodecContext 
*avctx)
 
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
+ff_thread_once(&init_static_once, atrac3p_init_static);
+
 return 0;
 }
 
@@ -405,7 +411,7 @@ AVCodec ff_atrac3pal_decoder = {
 .type   = AVMEDIA_TYPE_AUDIO,
 .id = AV_CODEC_ID_ATRAC3PAL,
 .capabilities   = AV_CODEC_CAP_DR1,
-.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 .priv_data_size = sizeof(ATRAC3PContext),
 .init   = atrac3p_decode_init,
 .close  = atrac3p_decode_close,
diff --git a/libavcodec/atrac3plusdsp.c b/libavcodec/atrac3plusdsp.c
index ca3154e133..7af1fa2141 100644
--- a/libavcodec/atrac3plusdsp.c
+++ b/libavcodec/atrac3plusdsp.c
@@ -79,9 +79,6 @@ const float ff_atrac3p_mant_tab[8] = {
 
 av_cold void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
 {
-ff_init_ff_sine_windows(7);
-ff_init_ff_sine_windows(6);
-
 /* Initialize the MDCT transform. */
 ff_mdct_init(mdct_ctx, 8, 1, -1.0);
 }
@@ -94,7 +91,7 @@ static DECLARE_ALIGNED(32, float, sine_table)[2048]; ///< 
wave table
 static DECLARE_ALIGNED(32, float, hann_window)[256]; ///< Hann windowing 
function
 static float amp_sf_tab[64];   ///< scalefactors for quantized amplitudes
 
-av_cold void ff_atrac3p_init_wave_synth(void)
+av_cold void ff_atrac3p_init_dsp_static(void)
 {
 int i;
 
@@ -109,6 +106,9 @@ av_cold void ff_atrac3p_init_wave_synth(void)
 /* generate amplitude scalefactors table */
 for (i = 0; i < 64; i++)
 amp_sf_tab[i] = exp2f((i - 3) / 4.0f);
+
+ff_init_ff_sine_windows(7);
+ff_init_ff_sine_windows(6);
 }
 
 /**
-- 
2.25.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 174/191] avcodec/aacdec, aactab: Move kbd tables to their only user

2020-11-23 Thread Andreas Rheinhardt
The floating point kbd tables for 120 and 960 samples are only used by
the floating point decoder whereas the fixed point kbd tables for 128
and 1024 samples are only used by the fixed point AAC decoder. So move
these tables to their only users. This ensures that there are not
accidentally used somewhere else without ensuring that initializing
these tables stays thread-safe (as it is now because the only place from
where they are initialized is guarded by an AVOnce).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/aac_defines.h |  2 ++
 libavcodec/aacdec.c  |  2 ++
 libavcodec/aacdec_fixed.c|  3 +++
 libavcodec/aacdec_template.c | 32 
 libavcodec/aactab.c  |  4 
 libavcodec/aactab.h  |  2 --
 6 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/libavcodec/aac_defines.h b/libavcodec/aac_defines.h
index 438d78a7aa..74ac011785 100644
--- a/libavcodec/aac_defines.h
+++ b/libavcodec/aac_defines.h
@@ -34,6 +34,7 @@
 
 #define AAC_RENAME(x)   x ## _fixed
 #define AAC_RENAME_32(x)x ## _fixed_32
+#define AAC_KBD_RENAME(x)   aac_ ## x ## _fixed
 typedef int INTFLOAT;
 typedef unsignedUINTFLOAT;  ///< Equivalent to INTFLOAT, Used as 
temporal cast to avoid undefined sign overflow operations.
 typedef int64_t INT64FLOAT;
@@ -83,6 +84,7 @@ typedef int AAC_SIGNE;
 
 #define AAC_RENAME(x)   x
 #define AAC_RENAME_32(x)x
+#define AAC_KBD_RENAME(x)   ff_aac_ ## x
 typedef float   INTFLOAT;
 typedef float   UINTFLOAT;
 typedef float   INT64FLOAT;
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index fd4805f6eb..0174bf8d5b 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -71,6 +71,8 @@
 
 DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(sine_120))[120];
 DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(sine_960))[960];
+DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(aac_kbd_long_960))[960];
+DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(aac_kbd_short_120))[120];
 
 static av_always_inline void reset_predict_state(PredictorState *ps)
 {
diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
index daaf765e0c..4d82b7b1aa 100644
--- a/libavcodec/aacdec_fixed.c
+++ b/libavcodec/aacdec_fixed.c
@@ -86,6 +86,9 @@
 #include 
 #include 
 
+DECLARE_ALIGNED(32, static int, AAC_KBD_RENAME(kbd_long_1024))[1024];
+DECLARE_ALIGNED(32, static int, AAC_KBD_RENAME(kbd_short_128))[128];
+
 static av_always_inline void reset_predict_state(PredictorState *ps)
 {
 ps->r0.mant   = 0;
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index e6fe913a27..3bf271af54 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1230,11 +1230,11 @@ static av_cold void aac_static_table_init(void)
 352);
 
 // window initialization
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_long_1024), 4.0, 
1024);
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_short_128), 6.0, 128);
+AAC_RENAME(ff_kbd_window_init)(AAC_KBD_RENAME(kbd_long_1024), 4.0, 1024);
+AAC_RENAME(ff_kbd_window_init)(AAC_KBD_RENAME(kbd_short_128), 6.0, 128);
 #if !USE_FIXED
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_long_960), 4.0, 960);
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(ff_aac_kbd_short_120), 6.0, 120);
+AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960);
+AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_short_120), 6.0, 120);
 AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_960), 960);
 AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_120), 120);
 #endif
@@ -2642,10 +2642,10 @@ static void apply_tns(INTFLOAT coef_param[1024], 
TemporalNoiseShaping *tns,
 static void windowing_and_mdct_ltp(AACContext *ac, INTFLOAT *out,
INTFLOAT *in, IndividualChannelStream *ics)
 {
-const INTFLOAT *lwindow  = ics->use_kb_window[0] ? 
AAC_RENAME(ff_aac_kbd_long_1024) : AAC_RENAME(ff_sine_1024);
-const INTFLOAT *swindow  = ics->use_kb_window[0] ? 
AAC_RENAME(ff_aac_kbd_short_128) : AAC_RENAME(ff_sine_128);
-const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? 
AAC_RENAME(ff_aac_kbd_long_1024) : AAC_RENAME(ff_sine_1024);
-const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? 
AAC_RENAME(ff_aac_kbd_short_128) : AAC_RENAME(ff_sine_128);
+const INTFLOAT *lwindow  = ics->use_kb_window[0] ? 
AAC_KBD_RENAME(kbd_long_1024) : AAC_RENAME(ff_sine_1024);
+const INTFLOAT *swindow  = ics->use_kb_window[0] ? 
AAC_KBD_RENAME(kbd_short_128) : AAC_RENAME(ff_sine_128);
+const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? 
AAC_KBD_RENAME(kbd_long_1024) : AAC_RENAME(ff_sine_1024);
+const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? 
AAC_KBD_RENAME(kbd_short_128) : AAC_RENAME(ff_sine_128);
 
 if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
 ac->fd

[FFmpeg-devel] [PATCH 170/191] avcodec/nellymoserdec: Make decoder init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Easy now that initializing the ff_sine_* tables is thread-safe.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/nellymoserdec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index d667d9ce79..49a21b43ce 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -128,13 +128,12 @@ static av_cold int decode_init(AVCodecContext * avctx) {
 s->scale_bias = 1.0/(32768*8);
 avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
-/* Generate overlap window */
-if (!ff_sine_128[127])
-ff_init_ff_sine_windows(7);
-
 avctx->channels   = 1;
 avctx->channel_layout = AV_CH_LAYOUT_MONO;
 
+/* Generate overlap window */
+ff_init_ff_sine_windows(7);
+
 return 0;
 }
 
@@ -198,4 +197,5 @@ AVCodec ff_nellymoser_decoder = {
 .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_PARAM_CHANGE,
 .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
   AV_SAMPLE_FMT_NONE },
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.25.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 175/191] avcodec/aac: Share common init code of float decoder and encoder

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/aacdec_template.c | 10 ++
 libavcodec/aacenc.c  |  6 +-
 libavcodec/aactab.c  | 14 ++
 libavcodec/aactab.h  |  3 +++
 4 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 3bf271af54..fbe3074071 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1230,17 +1230,19 @@ static av_cold void aac_static_table_init(void)
 352);
 
 // window initialization
-AAC_RENAME(ff_kbd_window_init)(AAC_KBD_RENAME(kbd_long_1024), 4.0, 1024);
-AAC_RENAME(ff_kbd_window_init)(AAC_KBD_RENAME(kbd_short_128), 6.0, 128);
 #if !USE_FIXED
 AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960);
 AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_short_120), 6.0, 120);
 AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_960), 960);
 AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_120), 120);
-#endif
+ff_aac_float_common_init();
+#else
+AAC_RENAME(ff_kbd_window_init)(AAC_KBD_RENAME(kbd_long_1024), 4.0, 1024);
+AAC_RENAME(ff_kbd_window_init)(AAC_KBD_RENAME(kbd_short_128), 6.0, 128);
 AAC_RENAME(ff_init_ff_sine_windows)(10);
-AAC_RENAME(ff_init_ff_sine_windows)( 9);
 AAC_RENAME(ff_init_ff_sine_windows)( 7);
+#endif
+AAC_RENAME(ff_init_ff_sine_windows)( 9);
 
 AAC_RENAME(ff_cbrt_tableinit)();
 }
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 274e5ca294..070a2e706a 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -36,7 +36,6 @@
 #include "put_bits.h"
 #include "internal.h"
 #include "mpeg4audio.h"
-#include "kbdwin.h"
 #include "sinewin.h"
 #include "profiles.h"
 
@@ -922,10 +921,7 @@ static av_cold int dsp_init(AVCodecContext *avctx, 
AACEncContext *s)
 return AVERROR(ENOMEM);
 
 // window init
-ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
-ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
-ff_init_ff_sine_windows(10);
-ff_init_ff_sine_windows(7);
+ff_aac_float_common_init();
 
 if ((ret = ff_mdct_init(&s->mdct1024, 11, 0, 32768.0)) < 0)
 return ret;
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index e886642e66..b9d1336d97 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -27,6 +27,7 @@
  * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
  */
 
+#include "config.h"
 #include "libavutil/mem.h"
 #include "libavutil/thread.h"
 #include "aac.h"
@@ -37,9 +38,22 @@
 float ff_aac_pow2sf_tab[428];
 float ff_aac_pow34sf_tab[428];
 
+#if CONFIG_AAC_ENCODER || CONFIG_AAC_DECODER
+#include "kbdwin.h"
+#include "sinewin.h"
+
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_long_1024)[1024];
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_short_128)[128];
 
+av_cold void ff_aac_float_common_init(void)
+{
+ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
+ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
+ff_init_ff_sine_windows(10);
+ff_init_ff_sine_windows(7);
+}
+#endif
+
 const uint8_t ff_aac_num_swb_1024[] = {
 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40, 40
 };
diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h
index 04180b96fd..02f79a16c0 100644
--- a/libavcodec/aactab.h
+++ b/libavcodec/aactab.h
@@ -100,6 +100,9 @@ DECLARE_ALIGNED(32, extern const float, 
ff_aac_eld_window_480)[1800];
 DECLARE_ALIGNED(32, extern const int,   ff_aac_eld_window_480_fixed)[1800];
 // @}
 
+/* Initializes data shared between float decoder and encoder. */
+void ff_aac_float_common_init(void);
+
 /* @name number of scalefactor window bands for long and short transform 
windows respectively
  * @{
  */
-- 
2.25.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 171/191] avcodec/nellymoserenc: Cleanup generically on init failure

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/nellymoserenc.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 9d22ac8cca..e5c9806be8 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -170,12 +170,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
 ff_af_queue_init(avctx, &s->afq);
 s->avctx = avctx;
 if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0)
-goto error;
+return ret;
 s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
-if (!s->fdsp) {
-ret = AVERROR(ENOMEM);
-goto error;
-}
+if (!s->fdsp)
+return AVERROR(ENOMEM);
 
 /* Generate overlap window */
 ff_init_ff_sine_windows(7);
@@ -195,16 +193,11 @@ static av_cold int encode_init(AVCodecContext *avctx)
 if (s->avctx->trellis) {
 s->opt  = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float  ));
 s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t));
-if (!s->opt || !s->path) {
-ret = AVERROR(ENOMEM);
-goto error;
-}
+if (!s->opt || !s->path)
+return AVERROR(ENOMEM);
 }
 
 return 0;
-error:
-encode_end(avctx);
-return ret;
 }
 
 #define find_best(val, table, LUT, LUT_add, LUT_size) \
@@ -431,4 +424,5 @@ AVCodec ff_nellymoser_encoder = {
 .capabilities   = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY,
 .sample_fmts= (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
  AV_SAMPLE_FMT_NONE },
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.25.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 176/191] avcodec/aactab: Make AAC encoder and decoders actually init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Commit 1a29804558c13ef512d9ef73a9b0d782af4fa5f2 guarded several
initializations of static data in the AAC decoders with an AVOnce and
set the FF_CODEC_CAP_INIT_THREADSAFE flag, believing the former to be
sufficient for the latter. It wasn't, because several of these static
tables are shared with other components, so that there might be data
races if they are initialized from multiple threads. This affected
initializing the ff_sine_* tables as well as initializing the
ff_aac_pow*sf_tab tables (shared between both decoders and encoder) as
well as ff_aac_kbd_* tables (shared between encoder and floating point
decoder).

Commit 3d62e7a30fa552be52d12b31e3e0f79153aff891 set the
FF_CODEC_CAP_INIT_THREADSAFE flag for the AAC encoder. More explicitly,
this commit used the same AVOnce to guard initializing ff_aac_pow*sf_tab
in the encoder and to guard initializing the static data of each
decoder; the ensuing catastrophe was "fixed" in commit
ec0719264cb9a9d5cbaf225da48929aea24997a3 by using a single AVOnce
for each codec again. But the codec cap has not been removed and
therefore the encoder claimed to be init-threadsafe, but wasn't, because
of the same tables as above.

The ff_sine_* tables as well as ff_aac_pow*sf_tab tables have already
been fixed; this commit deals with the ff_aac_kbd_* tables, making the
encoder as well as the floating-point decoder init-threadsafe (the
fixed-point decoder is it already).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/aactab.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index b9d1336d97..abe5fd7567 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -45,13 +45,19 @@ float ff_aac_pow34sf_tab[428];
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_long_1024)[1024];
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_short_128)[128];
 
-av_cold void ff_aac_float_common_init(void)
+static av_cold void aac_float_common_init(void)
 {
 ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
 ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
 ff_init_ff_sine_windows(10);
 ff_init_ff_sine_windows(7);
 }
+
+av_cold void ff_aac_float_common_init(void)
+{
+static AVOnce init_static_once = AV_ONCE_INIT;
+ff_thread_once(&init_static_once, aac_float_common_init);
+}
 #endif
 
 const uint8_t ff_aac_num_swb_1024[] = {
-- 
2.25.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 172/191] avcodec/nellymoserenc: Make encoder init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/nellymoserenc.c | 41 ++
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index e5c9806be8..aea9fe286c 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -38,6 +38,7 @@
 #include "libavutil/common.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/thread.h"
 
 #include "audio_frame_queue.h"
 #include "avcodec.h"
@@ -147,10 +148,29 @@ static av_cold int encode_end(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold void nellymoser_init_static(void)
+{
+/* faster way of doing
+for (int i = 0; i < POW_TABLE_SIZE; i++)
+   pow_table[i] = 2^(-i / 2048.0 - 3.0 + POW_TABLE_OFFSET); */
+pow_table[0] = 1;
+pow_table[1024] = M_SQRT1_2;
+for (int i = 1; i < 513; i++) {
+double tmp = exp2(-i / 2048.0);
+pow_table[i] = tmp;
+pow_table[1024-i] = M_SQRT1_2 / tmp;
+pow_table[1024+i] = tmp * M_SQRT1_2;
+pow_table[2048-i] = 0.5 / tmp;
+}
+/* Generate overlap window */
+ff_init_ff_sine_windows(7);
+}
+
 static av_cold int encode_init(AVCodecContext *avctx)
 {
+static AVOnce init_static_once = AV_ONCE_INIT;
 NellyMoserEncodeContext *s = avctx->priv_data;
-int i, ret;
+int ret;
 
 if (avctx->channels != 1) {
 av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n");
@@ -175,21 +195,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
 if (!s->fdsp)
 return AVERROR(ENOMEM);
 
-/* Generate overlap window */
-ff_init_ff_sine_windows(7);
-/* faster way of doing
-for (i = 0; i < POW_TABLE_SIZE; i++)
-   pow_table[i] = 2^(-i / 2048.0 - 3.0 + POW_TABLE_OFFSET); */
-pow_table[0] = 1;
-pow_table[1024] = M_SQRT1_2;
-for (i = 1; i < 513; i++) {
-double tmp = exp2(-i / 2048.0);
-pow_table[i] = tmp;
-pow_table[1024-i] = M_SQRT1_2 / tmp;
-pow_table[1024+i] = tmp * M_SQRT1_2;
-pow_table[2048-i] = 0.5 / tmp;
-}
-
 if (s->avctx->trellis) {
 s->opt  = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float  ));
 s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t));
@@ -197,6 +202,8 @@ static av_cold int encode_init(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 }
 
+ff_thread_once(&init_static_once, nellymoser_init_static);
+
 return 0;
 }
 
@@ -424,5 +431,5 @@ AVCodec ff_nellymoser_encoder = {
 .capabilities   = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY,
 .sample_fmts= (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
  AV_SAMPLE_FMT_NONE },
-.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.25.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 177/191] avcodec/sinewin: Fix wrong number of elements of array declaration

2020-11-23 Thread Andreas Rheinhardt
There are actually only 14 elements in each ff_sine_windows array.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/sinewin.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/sinewin.h b/libavcodec/sinewin.h
index 7b64096a71..1348740905 100644
--- a/libavcodec/sinewin.h
+++ b/libavcodec/sinewin.h
@@ -60,6 +60,6 @@ extern SINETABLE(2048);
 extern SINETABLE(4096);
 extern SINETABLE(8192);
 
-extern SINETABLE_CONST INTFLOAT * const AAC_RENAME(ff_sine_windows)[16];
+extern SINETABLE_CONST INTFLOAT * const AAC_RENAME(ff_sine_windows)[];
 
 #endif /* AVCODEC_SINEWIN_H */
-- 
2.25.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 173/191] avcodec/aactab: Remove declaration of inexistent array

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/aactab.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h
index ce6a7ba1d2..f950c13eee 100644
--- a/libavcodec/aactab.h
+++ b/libavcodec/aactab.h
@@ -95,7 +95,6 @@ DECLARE_ALIGNED(32, extern float,  ff_aac_kbd_short_128)[128];
 DECLARE_ALIGNED(32, extern float,  ff_aac_kbd_long_960)[960];
 DECLARE_ALIGNED(32, extern float,  ff_aac_kbd_short_120)[120];
 DECLARE_ALIGNED(32, extern int,ff_aac_kbd_long_1024_fixed)[1024];
-DECLARE_ALIGNED(32, extern int,ff_aac_kbd_long_512_fixed)[512];
 DECLARE_ALIGNED(32, extern int,ff_aac_kbd_short_128_fixed)[128];
 DECLARE_ALIGNED(32, extern const float, ff_aac_eld_window_512)[1920];
 DECLARE_ALIGNED(32, extern const int,   ff_aac_eld_window_512_fixed)[1920];
-- 
2.25.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 178/191] avcodec/mpeg12: Make initializing VLCs thread-safe

2020-11-23 Thread Andreas Rheinhardt
This automatically makes the eamad, eatqi and mdec init-threadsafe.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/eamad.c  |  1 +
 libavcodec/eatqi.c  |  1 +
 libavcodec/mdec.c   |  1 +
 libavcodec/mpeg12.c | 15 ---
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 7f28abbafe..9dccddd6d3 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -349,4 +349,5 @@ AVCodec ff_eamad_decoder = {
 .close  = decode_end,
 .decode = decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1,
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/eatqi.c b/libavcodec/eatqi.c
index 96536b1a08..456bd3c563 100644
--- a/libavcodec/eatqi.c
+++ b/libavcodec/eatqi.c
@@ -189,4 +189,5 @@ AVCodec ff_eatqi_decoder = {
 .close  = tqi_decode_end,
 .decode = tqi_decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1,
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index b16cbb6a79..d0bb1162b6 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -258,4 +258,5 @@ AVCodec ff_mdec_decoder = {
 .close= decode_end,
 .decode   = decode_frame,
 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
+.caps_internal= FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index e4f007aec5..e5c611414b 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -30,6 +30,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/timecode.h"
+#include "libavutil/thread.h"
 
 #include "internal.h"
 #include "avcodec.h"
@@ -134,13 +135,8 @@ VLC ff_mb_ptype_vlc;
 VLC ff_mb_btype_vlc;
 VLC ff_mb_pat_vlc;
 
-av_cold void ff_mpeg12_init_vlcs(void)
+static av_cold void mpeg12_init_vlcs(void)
 {
-static int done = 0;
-
-if (!done) {
-done = 1;
-
 INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
 ff_mpeg12_vlc_dc_lum_bits, 1, 1,
 ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
@@ -168,7 +164,12 @@ av_cold void ff_mpeg12_init_vlcs(void)
 
 INIT_2D_VLC_RL(ff_rl_mpeg1, 680, 0);
 INIT_2D_VLC_RL(ff_rl_mpeg2, 674, 0);
-}
+}
+
+av_cold void ff_mpeg12_init_vlcs(void)
+{
+static AVOnce init_static_once = AV_ONCE_INIT;
+ff_thread_once(&init_static_once, mpeg12_init_vlcs);
 }
 
 /**
-- 
2.25.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 179/191] avcodec/mpeg12: Reindentation

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12.c | 54 ++---
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index e5c611414b..e9eff0c48e 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -137,33 +137,33 @@ VLC ff_mb_pat_vlc;
 
 static av_cold void mpeg12_init_vlcs(void)
 {
-INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
-ff_mpeg12_vlc_dc_lum_bits, 1, 1,
-ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
-INIT_VLC_STATIC(&ff_dc_chroma_vlc,  DC_VLC_BITS, 12,
-ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
-ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514);
-INIT_VLC_STATIC(&ff_mv_vlc, MV_VLC_BITS, 17,
-&ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
-&ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 266);
-INIT_VLC_STATIC(&ff_mbincr_vlc, MBINCR_VLC_BITS, 36,
-&ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
-&ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538);
-INIT_VLC_STATIC(&ff_mb_pat_vlc, MB_PAT_VLC_BITS, 64,
-&ff_mpeg12_mbPatTable[0][1], 2, 1,
-&ff_mpeg12_mbPatTable[0][0], 2, 1, 512);
-
-INIT_VLC_STATIC(&ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
-&table_mb_ptype[0][1], 2, 1,
-&table_mb_ptype[0][0], 2, 1, 64);
-INIT_VLC_STATIC(&ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
-&table_mb_btype[0][1], 2, 1,
-&table_mb_btype[0][0], 2, 1, 64);
-ff_rl_init(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
-ff_rl_init(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
-
-INIT_2D_VLC_RL(ff_rl_mpeg1, 680, 0);
-INIT_2D_VLC_RL(ff_rl_mpeg2, 674, 0);
+INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
+ff_mpeg12_vlc_dc_lum_bits, 1, 1,
+ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
+INIT_VLC_STATIC(&ff_dc_chroma_vlc,  DC_VLC_BITS, 12,
+ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
+ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514);
+INIT_VLC_STATIC(&ff_mv_vlc, MV_VLC_BITS, 17,
+&ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
+&ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 266);
+INIT_VLC_STATIC(&ff_mbincr_vlc, MBINCR_VLC_BITS, 36,
+&ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
+&ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538);
+INIT_VLC_STATIC(&ff_mb_pat_vlc, MB_PAT_VLC_BITS, 64,
+&ff_mpeg12_mbPatTable[0][1], 2, 1,
+&ff_mpeg12_mbPatTable[0][0], 2, 1, 512);
+
+INIT_VLC_STATIC(&ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
+&table_mb_ptype[0][1], 2, 1,
+&table_mb_ptype[0][0], 2, 1, 64);
+INIT_VLC_STATIC(&ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
+&table_mb_btype[0][1], 2, 1,
+&table_mb_btype[0][0], 2, 1, 64);
+ff_rl_init(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
+ff_rl_init(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
+
+INIT_2D_VLC_RL(ff_rl_mpeg1, 680, 0);
+INIT_2D_VLC_RL(ff_rl_mpeg2, 674, 0);
 }
 
 av_cold void ff_mpeg12_init_vlcs(void)
-- 
2.25.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 180/191] avcodec/h261enc: Remove unused function parameter

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h261enc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 909bc23bb4..af836e4b30 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -322,8 +322,7 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t 
block[6][64],
 }
 }
 
-static av_cold void init_uni_h261_rl_tab(RLTable *rl, uint32_t *bits_tab,
- uint8_t *len_tab)
+static av_cold void init_uni_h261_rl_tab(RLTable *rl, uint8_t *len_tab)
 {
 int slevel, run, last;
 
@@ -372,7 +371,7 @@ av_cold void ff_h261_encode_init(MpegEncContext *s)
 s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
 s->ac_esc_length= 6+6+8;
 
-init_uni_h261_rl_tab(&ff_h261_rl_tcoeff, NULL, uni_h261_rl_len);
+init_uni_h261_rl_tab(&ff_h261_rl_tcoeff, uni_h261_rl_len);
 
 s->intra_ac_vlc_length  = s->inter_ac_vlc_length  = 
uni_h261_rl_len;
 s->intra_ac_vlc_last_length = s->inter_ac_vlc_last_length = 
uni_h261_rl_len + 128*64;
-- 
2.25.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 181/191] avcodec/h261: Make ff_h261_common_init() thread-safe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h261.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavcodec/h261.c b/libavcodec/h261.c
index 47bad4e57f..9c848eb7e8 100644
--- a/libavcodec/h261.c
+++ b/libavcodec/h261.c
@@ -25,6 +25,8 @@
  * H.261 codec
  */
 
+#include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "h261.h"
 
@@ -80,13 +82,13 @@ void ff_h261_loop_filter(MpegEncContext *s)
 h261_loop_filter(dest_cr, uvlinesize);
 }
 
-av_cold void ff_h261_common_init(void)
+static av_cold void h261_common_init(void)
 {
-static int done = 0;
-
-if (done)
-return;
-
 ff_rl_init(&ff_h261_rl_tcoeff, ff_h261_rl_table_store);
-done = 1;
+}
+
+av_cold void ff_h261_common_init(void)
+{
+static AVOnce init_static_once = AV_ONCE_INIT;
+ff_thread_once(&init_static_once, h261_common_init);
 }
-- 
2.25.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 182/191] avcodec/h261dec: Make decoder init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h261dec.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 8a49e7d894..377842c6fb 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -26,6 +26,7 @@
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "mpeg_er.h"
 #include "mpegutils.h"
@@ -47,12 +48,8 @@ static VLC h261_mtype_vlc;
 static VLC h261_mv_vlc;
 static VLC h261_cbp_vlc;
 
-static av_cold void h261_decode_init_vlc(H261Context *h)
+static av_cold void h261_decode_init_static(void)
 {
-static int done = 0;
-
-if (!done) {
-done = 1;
 INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
 ff_h261_mba_bits, 1, 1,
 ff_h261_mba_code, 1, 1, 662);
@@ -66,11 +63,13 @@ static av_cold void h261_decode_init_vlc(H261Context *h)
 &ff_h261_cbp_tab[0][1], 2, 1,
 &ff_h261_cbp_tab[0][0], 2, 1, 512);
 INIT_VLC_RL(ff_h261_rl_tcoeff, 552);
-}
+
+ff_h261_common_init();
 }
 
 static av_cold int h261_decode_init(AVCodecContext *avctx)
 {
+static AVOnce init_static_once = AV_ONCE_INIT;
 H261Context *h  = avctx->priv_data;
 MpegEncContext *const s = &h->s;
 
@@ -82,11 +81,10 @@ static av_cold int h261_decode_init(AVCodecContext *avctx)
 s->low_delay   = 1;
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 
-ff_h261_common_init();
-h261_decode_init_vlc(h);
-
 h->gob_start_code_skipped = 0;
 
+ff_thread_once(&init_static_once, h261_decode_init_static);
+
 return 0;
 }
 
@@ -686,6 +684,6 @@ AVCodec ff_h261_decoder = {
 .close  = h261_decode_end,
 .decode = h261_decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1,
-.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 .max_lowres = 3,
 };
-- 
2.25.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 183/191] avcodec/h261dec: Reindentation

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h261dec.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 377842c6fb..e7e07240ae 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -50,19 +50,19 @@ static VLC h261_cbp_vlc;
 
 static av_cold void h261_decode_init_static(void)
 {
-INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
-ff_h261_mba_bits, 1, 1,
-ff_h261_mba_code, 1, 1, 662);
-INIT_VLC_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
-ff_h261_mtype_bits, 1, 1,
-ff_h261_mtype_code, 1, 1, 80);
-INIT_VLC_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
-&ff_h261_mv_tab[0][1], 2, 1,
-&ff_h261_mv_tab[0][0], 2, 1, 144);
-INIT_VLC_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
-&ff_h261_cbp_tab[0][1], 2, 1,
-&ff_h261_cbp_tab[0][0], 2, 1, 512);
-INIT_VLC_RL(ff_h261_rl_tcoeff, 552);
+INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
+ff_h261_mba_bits, 1, 1,
+ff_h261_mba_code, 1, 1, 662);
+INIT_VLC_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
+ff_h261_mtype_bits, 1, 1,
+ff_h261_mtype_code, 1, 1, 80);
+INIT_VLC_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
+&ff_h261_mv_tab[0][1], 2, 1,
+&ff_h261_mv_tab[0][0], 2, 1, 144);
+INIT_VLC_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
+&ff_h261_cbp_tab[0][1], 2, 1,
+&ff_h261_cbp_tab[0][0], 2, 1, 512);
+INIT_VLC_RL(ff_h261_rl_tcoeff, 552);
 
 ff_h261_common_init();
 }
-- 
2.25.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 184/191] avcodec/asvdec: Make decoders init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/asvdec.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index 6b6d7b3fa7..d40535bed4 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -25,6 +25,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/mem.h"
+#include "libavutil/thread.h"
 
 #include "asv.h"
 #include "avcodec.h"
@@ -45,13 +46,8 @@ static VLC dc_ccp_vlc;
 static VLC ac_ccp_vlc;
 static VLC asv2_level_vlc;
 
-static av_cold void init_vlcs(ASV1Context *a)
+static av_cold void init_vlcs(void)
 {
-static int done = 0;
-
-if (!done) {
-done = 1;
-
 INIT_VLC_STATIC(&ccp_vlc, CCP_VLC_BITS, 17,
 &ff_asv_ccp_tab[0][1], 2, 1,
 &ff_asv_ccp_tab[0][0], 2, 1, 32);
@@ -67,7 +63,6 @@ static av_cold void init_vlcs(ASV1Context *a)
 INIT_LE_VLC_STATIC(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
&ff_asv2_level_tab[0][1], 4, 2,
&ff_asv2_level_tab[0][0], 4, 2, 1024);
-}
 }
 
 static inline int asv1_get_level(GetBitContext *gb)
@@ -286,6 +281,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
+static AVOnce init_static_once = AV_ONCE_INIT;
 ASV1Context *const a = avctx->priv_data;
 const int scale  = avctx->codec_id == AV_CODEC_ID_ASV1 ? 1 : 2;
 int i;
@@ -297,7 +293,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
 ff_asv_common_init(avctx);
 ff_blockdsp_init(&a->bdsp, avctx);
 ff_idctdsp_init(&a->idsp, avctx);
-init_vlcs(a);
 ff_init_scantable(a->idsp.idct_permutation, &a->scantable, ff_asv_scantab);
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 
@@ -316,6 +311,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
  a->inv_qscale;
 }
 
+ff_thread_once(&init_static_once, init_vlcs);
+
 return 0;
 }
 
@@ -340,6 +337,7 @@ AVCodec ff_asv1_decoder = {
 .close  = decode_end,
 .decode = decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1,
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
 
@@ -353,5 +351,6 @@ AVCodec ff_asv2_decoder = {
 .init   = decode_init,
 .decode = decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1,
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
-- 
2.25.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 185/191] avcodec/asvdec: Reindentation

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/asvdec.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index d40535bed4..a72e11b848 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -48,21 +48,21 @@ static VLC asv2_level_vlc;
 
 static av_cold void init_vlcs(void)
 {
-INIT_VLC_STATIC(&ccp_vlc, CCP_VLC_BITS, 17,
-&ff_asv_ccp_tab[0][1], 2, 1,
-&ff_asv_ccp_tab[0][0], 2, 1, 32);
-INIT_LE_VLC_STATIC(&dc_ccp_vlc, DC_CCP_VLC_BITS, 8,
-   &ff_asv_dc_ccp_tab[0][1], 2, 1,
-   &ff_asv_dc_ccp_tab[0][0], 2, 1, 16);
-INIT_LE_VLC_STATIC(&ac_ccp_vlc, AC_CCP_VLC_BITS, 16,
-   &ff_asv_ac_ccp_tab[0][1], 2, 1,
-   &ff_asv_ac_ccp_tab[0][0], 2, 1, 64);
-INIT_VLC_STATIC(&level_vlc,  ASV1_LEVEL_VLC_BITS, 7,
-&ff_asv_level_tab[0][1], 2, 1,
-&ff_asv_level_tab[0][0], 2, 1, 16);
-INIT_LE_VLC_STATIC(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
-   &ff_asv2_level_tab[0][1], 4, 2,
-   &ff_asv2_level_tab[0][0], 4, 2, 1024);
+INIT_VLC_STATIC(&ccp_vlc, CCP_VLC_BITS, 17,
+&ff_asv_ccp_tab[0][1], 2, 1,
+&ff_asv_ccp_tab[0][0], 2, 1, 32);
+INIT_LE_VLC_STATIC(&dc_ccp_vlc, DC_CCP_VLC_BITS, 8,
+   &ff_asv_dc_ccp_tab[0][1], 2, 1,
+   &ff_asv_dc_ccp_tab[0][0], 2, 1, 16);
+INIT_LE_VLC_STATIC(&ac_ccp_vlc, AC_CCP_VLC_BITS, 16,
+   &ff_asv_ac_ccp_tab[0][1], 2, 1,
+   &ff_asv_ac_ccp_tab[0][0], 2, 1, 64);
+INIT_VLC_STATIC(&level_vlc, ASV1_LEVEL_VLC_BITS, 7,
+&ff_asv_level_tab[0][1], 2, 1,
+&ff_asv_level_tab[0][0], 2, 1, 16);
+INIT_LE_VLC_STATIC(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
+   &ff_asv2_level_tab[0][1], 4, 2,
+   &ff_asv2_level_tab[0][0], 4, 2, 1024);
 }
 
 static inline int asv1_get_level(GetBitContext *gb)
-- 
2.25.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 186/191] avcodec/wavpack: Fix leak on init failure

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wavpack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index 58122c948c..e02a56aa35 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1712,5 +1712,5 @@ AVCodec ff_wavpack_decoder = {
 .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
 .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
   AV_CODEC_CAP_SLICE_THREADS,
-.caps_internal  = FF_CODEC_CAP_ALLOCATE_PROGRESS,
+.caps_internal  = FF_CODEC_CAP_ALLOCATE_PROGRESS | 
FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.25.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 187/191] avcodec/dsd: Make initializing DSD tables thread-safe

2020-11-23 Thread Andreas Rheinhardt
This automatically makes the DSD formats as well as DST and WavPack
init-threadsafe.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dsd.c | 8 +++-
 libavcodec/dsddec.c  | 1 +
 libavcodec/dstdec.c  | 1 +
 libavcodec/wavpack.c | 3 ++-
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavcodec/dsd.c b/libavcodec/dsd.c
index d48f87fa0f..95aab61ea4 100644
--- a/libavcodec/dsd.c
+++ b/libavcodec/dsd.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/thread.h"
 #include "libavcodec/internal.h"
 #include "libavcodec/mathops.h"
 #include "avcodec.h"
@@ -45,11 +46,8 @@ static av_cold void dsd_ctables_tableinit(void)
 
 av_cold void ff_init_dsd_data(void)
 {
-static int done = 0;
-if (done)
-return;
-dsd_ctables_tableinit();
-done = 1;
+static AVOnce init_static_once = AV_ONCE_INIT;
+ff_thread_once(&init_static_once, dsd_ctables_tableinit);
 }
 
 void ff_dsd2pcm_translate(DSDContext* s, size_t samples, int lsbf,
diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c
index 39837a5ad9..375e49341f 100644
--- a/libavcodec/dsddec.c
+++ b/libavcodec/dsddec.c
@@ -125,6 +125,7 @@ AVCodec ff_##name_##_decoder = { \
 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS, \
 .sample_fmts  = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP, \
AV_SAMPLE_FMT_NONE }, \
+.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
 };
 
 DSD_DECODER(DSD_LSBF, dsd_lsbf, "DSD (Direct Stream Digital), least 
significant bit first")
diff --git a/libavcodec/dstdec.c b/libavcodec/dstdec.c
index 41e761d7e5..3fd710d2f6 100644
--- a/libavcodec/dstdec.c
+++ b/libavcodec/dstdec.c
@@ -389,4 +389,5 @@ AVCodec ff_dst_decoder = {
 .capabilities   = AV_CODEC_CAP_DR1,
 .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
   AV_SAMPLE_FMT_NONE },
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index e02a56aa35..8fdabce335 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1712,5 +1712,6 @@ AVCodec ff_wavpack_decoder = {
 .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
 .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
   AV_CODEC_CAP_SLICE_THREADS,
-.caps_internal  = FF_CODEC_CAP_ALLOCATE_PROGRESS | 
FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal  = FF_CODEC_CAP_ALLOCATE_PROGRESS | 
FF_CODEC_CAP_INIT_CLEANUP |
+  FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.25.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 188/191] avcodec/dsddec: Inline constant

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dsddec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c
index 375e49341f..9814c9eb82 100644
--- a/libavcodec/dsddec.c
+++ b/libavcodec/dsddec.c
@@ -27,11 +27,11 @@
  */
 
 #include "libavcodec/internal.h"
-#include "libavcodec/mathops.h"
 #include "avcodec.h"
 #include "dsd.h"
 
 #define DSD_SILENCE 0x69
+#define DSD_SILENCE_REVERSED 0x96
 /* 0x69 = 01101001
  * This pattern "on repeat" makes a low energy 352.8 kHz tone
  * and a high energy 1.0584 MHz tone which should be filtered
@@ -53,7 +53,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 if (!s)
 return AVERROR(ENOMEM);
 
-silence = avctx->codec_id == AV_CODEC_ID_DSD_LSBF || avctx->codec_id == 
AV_CODEC_ID_DSD_LSBF_PLANAR ? ff_reverse[DSD_SILENCE] : DSD_SILENCE;
+silence = avctx->codec_id == AV_CODEC_ID_DSD_LSBF || avctx->codec_id == 
AV_CODEC_ID_DSD_LSBF_PLANAR ? DSD_SILENCE_REVERSED : DSD_SILENCE;
 for (i = 0; i < avctx->channels; i++) {
 s[i].pos = 0;
 memset(s[i].buf, silence, sizeof(s[i].buf));
-- 
2.25.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 189/191] avcodec/ivi: Make initializing VLCs thread-safe

2020-11-23 Thread Andreas Rheinhardt
This automatically makes indeo4/5 init-threadsafe.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/indeo4.c |  1 +
 libavcodec/indeo5.c |  2 +-
 libavcodec/ivi.c| 13 -
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavcodec/indeo4.c b/libavcodec/indeo4.c
index 4bfc6cdd74..e2778af6ca 100644
--- a/libavcodec/indeo4.c
+++ b/libavcodec/indeo4.c
@@ -713,4 +713,5 @@ AVCodec ff_indeo4_decoder = {
 .close  = ff_ivi_decode_close,
 .decode = ff_ivi_decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1,
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/indeo5.c b/libavcodec/indeo5.c
index ac15d31fef..3ee7a0e1d6 100644
--- a/libavcodec/indeo5.c
+++ b/libavcodec/indeo5.c
@@ -693,5 +693,5 @@ AVCodec ff_indeo5_decoder = {
 .close  = ff_ivi_decode_close,
 .decode = ff_ivi_decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1,
-.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c
index 5e1180a5f0..a5074e9980 100644
--- a/libavcodec/ivi.c
+++ b/libavcodec/ivi.c
@@ -30,6 +30,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/thread.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
@@ -157,14 +158,11 @@ static int ivi_create_huff_from_desc(const IVIHuffDesc 
*cb, VLC *vlc, int flag)
 (flag ? INIT_VLC_USE_NEW_STATIC : 0) | INIT_VLC_OUTPUT_LE);
 }
 
-av_cold void ff_ivi_init_static_vlc(void)
+static av_cold void ivi_init_static_vlc(void)
 {
 int i;
 static VLC_TYPE table_data[8192 * 16][2];
-static int initialized_vlcs = 0;
 
-if (initialized_vlcs)
-return;
 for (i = 0; i < 8; i++) {
 ivi_mb_vlc_tabs[i].table = table_data + i * 2 * 8192;
 ivi_mb_vlc_tabs[i].table_allocated = 8192;
@@ -175,7 +173,12 @@ av_cold void ff_ivi_init_static_vlc(void)
 ivi_create_huff_from_desc(&ivi_blk_huff_desc[i],
   &ivi_blk_vlc_tabs[i], 1);
 }
-initialized_vlcs = 1;
+}
+
+av_cold void ff_ivi_init_static_vlc(void)
+{
+static AVOnce init_static_once = AV_ONCE_INIT;
+ff_thread_once(&init_static_once, ivi_init_static_vlc);
 }
 
 /*
-- 
2.25.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 190/191] avcodec/wmadec: Reduce the size of tables used to initialize VLC

2020-11-23 Thread Andreas Rheinhardt
By switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths() one
can replace a table of codes of type uint16_t by a table of symbols of
type uint8_t, saving space.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wma.h |  3 +--
 libavcodec/wmadata.h | 20 
 libavcodec/wmadec.c  |  6 +++---
 3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/libavcodec/wma.h b/libavcodec/wma.h
index c7fcf5047c..7935bcdb31 100644
--- a/libavcodec/wma.h
+++ b/libavcodec/wma.h
@@ -139,8 +139,7 @@ typedef struct WMACodecContext {
 #endif /* TRACE */
 } WMACodecContext;
 
-extern const uint16_t ff_wma_hgain_huffcodes[37];
-extern const uint8_t ff_wma_hgain_huffbits[37];
+extern const uint8_t ff_wma_hgain_hufftab[37][2];
 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
 extern const uint32_t ff_aac_scalefactor_code[121];
 extern const uint8_t  ff_aac_scalefactor_bits[121];
diff --git a/libavcodec/wmadata.h b/libavcodec/wmadata.h
index 641cb1813c..ca485a5663 100644
--- a/libavcodec/wmadata.h
+++ b/libavcodec/wmadata.h
@@ -51,18 +51,14 @@ static const uint8_t exponent_band_44100[3][25] = {
 { 17, 4, 8, 8, 4, 12, 12, 8, 8, 24, 16, 20, 24, 32, 40, 60, 80, 152, },
 };
 
-const uint16_t ff_wma_hgain_huffcodes[37] = {
-0x3, 0x002e7, 0x1, 0x005cd, 0x0005d, 0x005c9, 0x0005e, 0x3,
-0x00016, 0xb, 0x1, 0x6, 0x1, 0x6, 0x4, 0x5,
-0x4, 0x7, 0x3, 0x7, 0x4, 0xa, 0xa, 0x2,
-0x3, 0x0, 0x5, 0x2, 0x0005f, 0x4, 0x3, 0x2,
-0x005c8, 0x000b8, 0x005ca, 0x005cb, 0x005cc,
-};
-
-const uint8_t ff_wma_hgain_huffbits[37] = {
-10, 12, 10, 13,  9, 13, 9, 8, 7,  5, 5,  4, 4, 3, 3, 3,
- 4,  3,  4,  4,  5,  5, 6, 8, 7, 10, 8, 10, 9, 8, 9, 9,
-13, 10, 13, 13, 13,
+const uint8_t ff_wma_hgain_hufftab[37][2] = {
+{ 25, 10 }, {  2, 10 }, { 27, 10 }, {  0, 10 }, { 31,  9 }, { 30,  9 },
+{ 23,  8 }, {  7,  8 }, { 29,  8 }, { 26,  8 }, { 24,  7 }, { 10,  5 },
+{ 12,  4 }, { 20,  5 }, { 22,  6 }, {  8,  7 }, { 33, 10 }, { 32, 13 },
+{  5, 13 }, { 34, 13 }, { 35, 13 }, { 36, 13 }, {  3, 13 }, {  1, 12 },
+{  4,  9 }, {  6,  9 }, { 28,  9 }, { 18,  4 }, { 16,  4 }, { 21,  5 },
+{  9,  5 }, { 11,  4 }, { 19,  4 }, { 14,  3 }, { 15,  3 }, { 13,  3 },
+{ 17,  3 },
 };
 
 const float ff_wma_lsp_codebook[NB_LSP_COEFS][16] = {
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 8504d8d6c4..2b9499eba7 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -110,9 +110,9 @@ static av_cold int wma_decode_init(AVCodecContext *avctx)
 ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1, 1.0 / 
32768.0);
 
 if (s->use_noise_coding) {
-init_vlc(&s->hgain_vlc, HGAINVLCBITS, sizeof(ff_wma_hgain_huffbits),
- ff_wma_hgain_huffbits, 1, 1,
- ff_wma_hgain_huffcodes, 2, 2, 0);
+ff_init_vlc_from_lengths(&s->hgain_vlc, HGAINVLCBITS, 
FF_ARRAY_ELEMS(ff_wma_hgain_hufftab),
+ &ff_wma_hgain_hufftab[0][1], 2,
+ &ff_wma_hgain_hufftab[0][0], 2, 1, 0, 0, 
avctx);
 }
 
 if (s->use_exp_vlc)
-- 
2.25.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 191/191] avcodec/wmadec: Apply VLC offset during init

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wmadec.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 2b9499eba7..9c79556bb5 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -112,7 +112,7 @@ static av_cold int wma_decode_init(AVCodecContext *avctx)
 if (s->use_noise_coding) {
 ff_init_vlc_from_lengths(&s->hgain_vlc, HGAINVLCBITS, 
FF_ARRAY_ELEMS(ff_wma_hgain_hufftab),
  &ff_wma_hgain_hufftab[0][1], 2,
- &ff_wma_hgain_hufftab[0][0], 2, 1, 0, 0, 
avctx);
+ &ff_wma_hgain_hufftab[0][0], 2, 1, -18, 0, 
avctx);
 }
 
 if (s->use_exp_vlc)
@@ -545,7 +545,7 @@ static int wma_decode_block(WMACodecContext *s)
 }
 for (ch = 0; ch < s->avctx->channels; ch++) {
 if (s->channel_coded[ch]) {
-int i, n, val, code;
+int i, n, val;
 
 n   = s->exponent_high_sizes[bsize];
 val = (int) 0x8000;
@@ -554,9 +554,8 @@ static int wma_decode_block(WMACodecContext *s)
 if (val == (int) 0x8000) {
 val = get_bits(&s->gb, 7) - 19;
 } else {
-code = get_vlc2(&s->gb, s->hgain_vlc.table,
+val += get_vlc2(&s->gb, s->hgain_vlc.table,
 HGAINVLCBITS, HGAINMAX);
-val += code - 18;
 }
 s->high_band_values[ch][i] = val;
 }
-- 
2.25.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 163/191] avcodec/atrac: Make generating tables thread-safe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/atrac.c | 27 +++
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavcodec/atrac.c b/libavcodec/atrac.c
index 12e8997dbc..bf9878be45 100644
--- a/libavcodec/atrac.c
+++ b/libavcodec/atrac.c
@@ -30,6 +30,8 @@
 #include 
 #include 
 
+#include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "atrac.h"
 
@@ -45,22 +47,23 @@ static const float qmf_48tap_half[24] = {
-0.043596379,   -0.099384367,   0.13207909,0.46424159
 };
 
-av_cold void ff_atrac_generate_tables(void)
+static av_cold void atrac_generate_tables(void)
 {
-int i;
-float s;
-
 /* Generate scale factors */
-if (!ff_atrac_sf_table[63])
-for (i=0 ; i<64 ; i++)
-ff_atrac_sf_table[i] = pow(2.0, (i - 15) / 3.0);
+for (int i = 0; i < 64; i++)
+ff_atrac_sf_table[i] = pow(2.0, (i - 15) / 3.0);
 
 /* Generate the QMF window. */
-if (!qmf_window[47])
-for (i=0 ; i<24; i++) {
-s = qmf_48tap_half[i] * 2.0;
-qmf_window[i] = qmf_window[47 - i] = s;
-}
+for (int i = 0; i < 24; i++) {
+float s = qmf_48tap_half[i] * 2.0;
+qmf_window[i] = qmf_window[47 - i] = s;
+}
+}
+
+av_cold void ff_atrac_generate_tables(void)
+{
+static AVOnce init_static_once = AV_ONCE_INIT;
+ff_thread_once(&init_static_once, atrac_generate_tables);
 }
 
 av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int 
id2exp_offset,
-- 
2.25.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 1/3] avcodec/mlp: Make initializing CRCs thread-safe

2020-11-23 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/mlp.c | 17 ++---
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/mlp.c b/libavcodec/mlp.c
> index ddbab60c4e..74363c3b95 100644
> --- a/libavcodec/mlp.c
> +++ b/libavcodec/mlp.c
> @@ -23,6 +23,7 @@
>  
>  #include "libavutil/crc.h"
>  #include "libavutil/intreadwrite.h"
> +#include "libavutil/thread.h"
>  #include "mlp.h"
>  
>  const uint8_t ff_mlp_huffman_tables[3][18][2] = {
> @@ -62,7 +63,6 @@ const uint64_t ff_mlp_channel_layouts[12] = {
>  AV_CH_LAYOUT_4POINT1, AV_CH_LAYOUT_5POINT1_BACK, 0,
>  };
>  
> -static int crc_init = 0;
>  #if CONFIG_SMALL
>  #define CRC_TABLE_SIZE 257
>  #else
> @@ -72,14 +72,17 @@ static AVCRC crc_63[CRC_TABLE_SIZE];
>  static AVCRC crc_1D[CRC_TABLE_SIZE];
>  static AVCRC crc_2D[CRC_TABLE_SIZE];
>  
> +static av_cold void mlp_init_crc(void)
> +{
> +av_crc_init(crc_63, 0,  8,   0x63, sizeof(crc_63));
> +av_crc_init(crc_1D, 0,  8,   0x1D, sizeof(crc_1D));
> +av_crc_init(crc_2D, 0, 16, 0x002D, sizeof(crc_2D));
> +}
> +
>  av_cold void ff_mlp_init_crc(void)
>  {
> -if (!crc_init) {
> -av_crc_init(crc_63, 0,  8,   0x63, sizeof(crc_63));
> -av_crc_init(crc_1D, 0,  8,   0x1D, sizeof(crc_1D));
> -av_crc_init(crc_2D, 0, 16, 0x002D, sizeof(crc_2D));
> -crc_init = 1;
> -}
> +static AVOnce init_static_once = AV_ONCE_INIT;
> +ff_thread_once(&init_static_once, mlp_init_crc);
>  }
>  
>  uint16_t ff_mlp_checksum16(const uint8_t *buf, unsigned int buf_size)
> 
Will apply this patchset tomorrow unless there are objections.

- 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 v2 1/3] libavutil: introduce AVFilmGrainParams side data

2020-11-23 Thread Lynne
Nov 23, 2020, 15:06 by jamr...@gmail.com:

> On 11/23/2020 9:08 AM, Lynne wrote:
>
>
>> From e11df30e25f1b27a4ec3efb7dc894b8cf59113d2 Mon Sep 17 00:00:00 2001
>> From: Lynne 
>> Date: Thu, 12 Nov 2020 12:44:30 +0100
>> Subject: [PATCH v3 1/4] libavutil: introduce AVFilmGrainParams side data
>>
>> This patch introduces a new frame side data type AVFilmGrainParams for use
>> with video codecs which are able to use it.
>>
>> It is generalized rather than being AV1 specific as AV2 is expected to carry
>> the same data, as well as the fact there already exist rarely-used 
>> specifications
>> for both H.264 and HEVC.
>>
>
> This part of the commit message is no longer true, so remove it.
>

Done.


> Looking at the HEVC spec, film_grain_full_range_flag does not have the same 
> semantics as clip_to_restricted_range.
>
> If this field is going to be outside AVFilmGrain###Params, then it needs to 
> be generic enough for it. So maybe call it color_range and make it of type 
> AVColorRange?
> Alternatively, just put it in AVFilmGrainAOMParams and lets not try to 
> predict what other FG implementations are going to do in the future.
>

I've put it into AOM's struct. I think that's safer and I thought it somehow 
didn't
fit in into the main one.

I've added the comments you requested for both structs, fixed a few comments
that were wrong, and as discussed on IRC changed the data types to what is
smallest and matches best for the coefficients and generic ints for everything
else (#coeffs, shifts, offsets and multipliers).

Attached v4 and locally updated the libdav1d patch.

>From fcd1e3b1d8f4cbf9f0661717cd9ed4d95aa5e1a9 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Thu, 12 Nov 2020 12:44:30 +0100
Subject: [PATCH v4 1/4] libavutil: introduce AVFilmGrainParams side data

This patch introduces a new frame side data type AVFilmGrainParams for use
with video codecs which are able to use it.
---
 doc/APIchanges|   4 +
 libavutil/Makefile|   2 +
 libavutil/film_grain_params.c |  42 +
 libavutil/film_grain_params.h | 167 ++
 libavutil/frame.c |   1 +
 libavutil/frame.h |   6 ++
 libavutil/version.h   |   2 +-
 7 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/film_grain_params.c
 create mode 100644 libavutil/film_grain_params.h

diff --git a/doc/APIchanges b/doc/APIchanges
index b70c78a483..41248724d9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-xx-xx - xx - lavu 56.61.100 - film_grain_params.h
+  Adds a new API for extracting codec film grain parameters as side data.
+  Adds a new AVFrameSideDataType entry AV_FRAME_DATA_FILM_GRAIN_PARAMS for it.
+
 2020-xx-xx - xx - lavf 58.64.100 - avformat.h
   Add AVSTREAM_EVENT_FLAG_NEW_PACKETS.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 9b08372eb2..27bafe9e12 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -84,6 +84,7 @@ HEADERS = adler32.h \
   xtea.h\
   tea.h \
   tx.h  \
+  film_grain_params.h   \
 
 HEADERS-$(CONFIG_LZO)   += lzo.h
 
@@ -170,6 +171,7 @@ OBJS = adler32.o\
tx_double.o  \
tx_int32.o   \
video_enc_params.o   \
+   film_grain_params.o  \
 
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
diff --git a/libavutil/film_grain_params.c b/libavutil/film_grain_params.c
new file mode 100644
index 00..930d23c7fe
--- /dev/null
+++ b/libavutil/film_grain_params.c
@@ -0,0 +1,42 @@
+/**
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "film_grain_params.h"
+
+AVFilmGrainParams *av_film_grain_params_al

Re: [FFmpeg-devel] [PATCH 0/6] Add support for utilizing av1c as extradata

2020-11-23 Thread James Almer

On 11/23/2020 4:10 PM, Jan Ekström wrote:

Until now an API user with a non-libavformat MP4 or Matroska demuxer
would have had to manually filter the extradata to skip the first four
bytes when passing data to libavcodec, so that only the OBUs would
remain. Now the AV1CodecConfigurationRecord structure can be passed
to libavcodec as-is. This is lets it to be dealt with in a similar
manner to AVC or HEVC.

This is done in the following steps:
1. A nice helper by Mark is added so that it can be utilized in stead
of ff_cbs_read from both the decoder and parser after the CBS gains
the capability to handle AV1CodecConfigurationRecord structures.
2. Support is added to AV1 CBS for handling AV1CodecConfigurationRecord
in a similar vein to AVC/HEVC's avcc/hvcc handling.
3. AV1 decoder and parser are switched to utilize the newly added
helper functionality.
4. Support is added for writing out the passed AV1CodecConfigurationRecord
in ff_isom_write_av1c, which is called from the MP4 and Matroska
writers.
5. Finally, both MP4 and Matroska demuxers are changed to expose the
full AV1CodecConfigurationRecord as extradata.

Jan Ekström (5):
   avcodec/cbs_av1: add support for standard MP4/Matroska extradata
   avcodec/av1{dec,parser}: move to ff_cbs_read_extradata_from_codec
   avformat/av1: add support for passing through MP4/Matroska av1c
   avformat/mov: remove special handling of av1c extradata
   avformat/matroskadec: remove special handling of av1c extradata

Mark Thompson (1):
   cbs: Add function to read extradata from an AVCodecContext

  libavcodec/av1_parser.c   |  2 +-
  libavcodec/av1dec.c   |  5 ++-
  libavcodec/cbs.c  | 77 ---
  libavcodec/cbs.h  | 11 ++
  libavcodec/cbs_av1.c  | 34 +
  libavformat/av1.c | 14 +++
  libavformat/matroskadec.c |  4 --
  libavformat/mov.c | 30 +--
  8 files changed, 103 insertions(+), 74 deletions(-)


Patches 1 to 4 LGTM. Patches 5 and 6 should IMO wait until after a bump 
since they change what the demuxers export as extradata, and existing 
compiled software linking to for ex 4.3 should not have to deal with 
this change in behavior if you use a lavf from an hypothetical pre-bump 
4.4 release at runtime.

___
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] avcodec/dxva2_av1: use correct grain parameters with update_grain = 0

2020-11-23 Thread James Almer

On 11/23/2020 8:38 AM, Hendrik Leppkes wrote:

When update_grain is zero, the parameters should be taken from a
reference frame instead.
---
  libavcodec/dxva2_av1.c | 59 +-
  1 file changed, 30 insertions(+), 29 deletions(-)


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 164/191] avcodec/atrac3: Make decoders init-threadsafe

2020-11-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/atrac3.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index 48f0f20a0a..e80c39d492 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -39,6 +39,8 @@
 #include "libavutil/attributes.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/libm.h"
+#include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "bytestream.h"
 #include "fft.h"
@@ -870,7 +872,7 @@ static av_cold void atrac3_init_static_data(void)
 
 static av_cold int atrac3_decode_init(AVCodecContext *avctx)
 {
-static int static_init_done;
+static AVOnce init_static_once = AV_ONCE_INIT;
 int i, js_pair, ret;
 int version, delay, samples_per_frame, frame_factor;
 const uint8_t *edata_ptr = avctx->extradata;
@@ -882,10 +884,6 @@ static av_cold int atrac3_decode_init(AVCodecContext 
*avctx)
 return AVERROR(EINVAL);
 }
 
-if (!static_init_done)
-atrac3_init_static_data();
-static_init_done = 1;
-
 /* Take care of the codec-specific extradata. */
 if (avctx->codec_id == AV_CODEC_ID_ATRAC3AL) {
 version   = 4;
@@ -1009,6 +1007,8 @@ static av_cold int atrac3_decode_init(AVCodecContext 
*avctx)
 if (!q->units)
 return AVERROR(ENOMEM);
 
+ff_thread_once(&init_static_once, atrac3_init_static_data);
+
 return 0;
 }
 
@@ -1024,7 +1024,7 @@ AVCodec ff_atrac3_decoder = {
 .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
 .sample_fmts  = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
 AV_SAMPLE_FMT_NONE },
-.caps_internal= FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal= FF_CODEC_CAP_INIT_CLEANUP | 
FF_CODEC_CAP_INIT_THREADSAFE,
 };
 
 AVCodec ff_atrac3al_decoder = {
@@ -1039,5 +1039,5 @@ AVCodec ff_atrac3al_decoder = {
 .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
 .sample_fmts  = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
 AV_SAMPLE_FMT_NONE },
-.caps_internal= FF_CODEC_CAP_INIT_CLEANUP,
+.caps_internal= FF_CODEC_CAP_INIT_CLEANUP | 
FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.25.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] Support HDR10+ metadata for HEVC.

2020-11-23 Thread Mohammad Izadi
Thanks,
Mohammad


On Fri, Nov 20, 2020 at 5:44 AM Anton Khirnov  wrote:

> Quoting Mohammad Izadi (2020-11-20 04:57:11)
> > From: Mohammad Izadi 
> >
> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
> to side data packet to be used or passed through.
> > ---
> > The fate test file can be found here:
> https://drive.google.com/file/d/1vcT0ohzpoyVFcxQN32jKIhUrBaBwZweT/view?usp=sharing
> > The video file needs to be copied to fate-suite/mov/
>
> >  configure |   1 +
> >  fftools/ffprobe.c | 106 +
> >  libavcodec/Makefile   |   3 +
> >  libavcodec/avpacket.c |   1 +
> >  libavcodec/decode.c   |   1 +
> >  libavcodec/dynamic_hdr10_plus.c   | 223 ++
> >  .../dynamic_hdr10_plus.h  |  22 +-
> >  libavcodec/hevc_sei.c |  62 -
> >  libavcodec/hevc_sei.h |   5 +
> >  libavcodec/hevcdec.c  |  18 ++
> >  libavcodec/packet.h   |   8 +
> >  libavcodec/version.h  |   2 +-
> >  libavfilter/vf_showinfo.c | 106 -
> >  libavutil/Makefile|   2 -
> >  libavutil/hdr_dynamic_metadata.c  |  47 
> >  tests/fate/mov.mak|   3 +
> >  tests/ref/fate/mov-hdr10-plus-metadata|  90 +++
> >  17 files changed, 629 insertions(+), 71 deletions(-)
> >  create mode 100644 libavcodec/dynamic_hdr10_plus.c
> >  rename libavutil/hdr_dynamic_metadata.h =>
> libavcodec/dynamic_hdr10_plus.h (95%)
>
> You cannot move a public header like that, it breaks API.
>
Right reverted the change in the following patch.

> Also, the patch does way too many things at once, it should be split.

Some changes are asked to be added by reviewers just for being able to test
it. This CL has been hanging for a long time. I think Vittorio and Ian can
help on this to proceed with this CL.

>
> --
> Anton Khirnov
> ___
> 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] Support HDR10+ metadata for HEVC.

2020-11-23 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
The fate test file can be found here: 
https://drive.google.com/file/d/1vcT0ohzpoyVFcxQN32jKIhUrBaBwZweT/view?usp=sharing
The video file needs to be copied to fate-suite/mov/
configure  |   1 +
 fftools/ffprobe.c  | 106 +
 libavcodec/Makefile|   3 +
 libavcodec/avpacket.c  |   1 +
 libavcodec/decode.c|   1 +
 libavcodec/dynamic_hdr10_plus.c| 196 +
 libavcodec/dynamic_hdr10_plus.h|  34 +
 libavcodec/hevc_sei.c  |  62 ++--
 libavcodec/hevc_sei.h  |   5 +
 libavcodec/hevcdec.c   |  18 +++
 libavcodec/packet.h|   8 +
 libavcodec/version.h   |   2 +-
 libavfilter/vf_showinfo.c  | 106 -
 tests/fate/mov.mak |   3 +
 tests/ref/fate/mov-hdr10-plus-metadata |  90 
 15 files changed, 621 insertions(+), 15 deletions(-)
 create mode 100644 libavcodec/dynamic_hdr10_plus.c
 create mode 100644 libavcodec/dynamic_hdr10_plus.h
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/configure b/configure
index 51e43fbf66..a9f12a421e 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
 dirac_parse
 dnn
 dvprofile
+dynamic_hdr10_plus
 exif
 faandct
 faanidct
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..4cee4e8ec3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -35,6 +35,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
@@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w, 
AVDictionary *tags, int section_id
 return ret;
 }
 
+static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus 
*metadata)
+{
+if (!metadata)
+return;
+print_int("application version", metadata->application_version);
+print_int("num_windows", metadata->num_windows);
+for (int n = 1; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = &metadata->params[n];
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_q("window_lower_right_corner_x",
+params->window_lower_right_corner_x,'/');
+print_q("window_lower_right_corner_y",
+params->window_lower_right_corner_y,'/');
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_int("center_of_ellipse_x",
+  params->center_of_ellipse_x ) ;
+print_int("center_of_ellipse_y",
+  params->center_of_ellipse_y );
+print_int("rotation_angle",
+  params->rotation_angle);
+print_int("semimajor_axis_internal_ellipse",
+  params->semimajor_axis_internal_ellipse);
+print_int("semimajor_axis_external_ellipse",
+  params->semimajor_axis_external_ellipse);
+print_int("semiminor_axis_external_ellipse",
+  params->semiminor_axis_external_ellipse);
+print_int("overlap_process_option",
+  params->overlap_process_option);
+}
+print_q("targeted_system_display_maximum_luminance",
+metadata->targeted_system_display_maximum_luminance,'/');
+if (metadata->targeted_system_display_actual_peak_luminance_flag) {
+print_int("num_rows_targeted_system_display_actual_peak_luminance",
+  
metadata->num_rows_targeted_system_display_actual_peak_luminance);
+print_int("num_cols_targeted_system_display_actual_peak_luminance",
+  
metadata->num_cols_targeted_system_display_actual_peak_luminance);
+for (int i = 0; i < 
metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
+for (int j = 0; j < 
metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
+print_q("targeted_system_display_actual_peak_luminance",
+
metadata->targeted_system_display_actual_peak_luminance[i][j],'/');
+}
+}
+}
+for (int n = 0; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = &metadata->params[n];
+for (int i = 0; 

Re: [FFmpeg-devel] [PATCH 1/3] avcodec/mlp: Make initializing CRCs thread-safe

2020-11-23 Thread Jai Luthra
LGTM

On Tue, Nov 24, 2020, at 1:29 AM, Andreas Rheinhardt wrote:
> Andreas Rheinhardt:
> > Signed-off-by: Andreas Rheinhardt 
> > ---
> >  libavcodec/mlp.c | 17 ++---
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> > 
> > diff --git a/libavcodec/mlp.c b/libavcodec/mlp.c
> > index ddbab60c4e..74363c3b95 100644
> > --- a/libavcodec/mlp.c
> > +++ b/libavcodec/mlp.c
> > @@ -23,6 +23,7 @@
> >  
> >  #include "libavutil/crc.h"
> >  #include "libavutil/intreadwrite.h"
> > +#include "libavutil/thread.h"
> >  #include "mlp.h"
> >  
> >  const uint8_t ff_mlp_huffman_tables[3][18][2] = {
> > @@ -62,7 +63,6 @@ const uint64_t ff_mlp_channel_layouts[12] = {
> >  AV_CH_LAYOUT_4POINT1, AV_CH_LAYOUT_5POINT1_BACK, 0,
> >  };
> >  
> > -static int crc_init = 0;
> >  #if CONFIG_SMALL
> >  #define CRC_TABLE_SIZE 257
> >  #else
> > @@ -72,14 +72,17 @@ static AVCRC crc_63[CRC_TABLE_SIZE];
> >  static AVCRC crc_1D[CRC_TABLE_SIZE];
> >  static AVCRC crc_2D[CRC_TABLE_SIZE];
> >  
> > +static av_cold void mlp_init_crc(void)
> > +{
> > +av_crc_init(crc_63, 0,  8,   0x63, sizeof(crc_63));
> > +av_crc_init(crc_1D, 0,  8,   0x1D, sizeof(crc_1D));
> > +av_crc_init(crc_2D, 0, 16, 0x002D, sizeof(crc_2D));
> > +}
> > +
> >  av_cold void ff_mlp_init_crc(void)
> >  {
> > -if (!crc_init) {
> > -av_crc_init(crc_63, 0,  8,   0x63, sizeof(crc_63));
> > -av_crc_init(crc_1D, 0,  8,   0x1D, sizeof(crc_1D));
> > -av_crc_init(crc_2D, 0, 16, 0x002D, sizeof(crc_2D));
> > -crc_init = 1;
> > -}
> > +static AVOnce init_static_once = AV_ONCE_INIT;
> > +ff_thread_once(&init_static_once, mlp_init_crc);
> >  }
> >  
> >  uint16_t ff_mlp_checksum16(const uint8_t *buf, unsigned int buf_size)
> > 
> Will apply this patchset tomorrow unless there are objections.
> 
> - 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 v1] avcodec/libvpxenc: add a way to set VP9E_SET_SVC_REF_FRAME_CONFIG.

2020-11-23 Thread Wonkap Jang
Hi James,

On Wed, Nov 18, 2020 at 1:13 PM James Zern 
wrote:

> Hi,
>
> On Mon, Nov 16, 2020 at 2:36 PM Wonkap Jang
>  wrote:
> >
> > In order to fine-control referencing schemes in VP9 encoding, there
> > is a need to use VP9E_SET_SVC_REF_FRAME_CONFIG method. This commit
> > provides a way to use the API through frame metadata.
> > ---
> >  libavcodec/libvpxenc.c | 77 ++
>
> The documentation could use an update too. Maybe some of the earlier
> per-frame metadata was missed.
>
> >  1 file changed, 77 insertions(+)
> >
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index a7c76eb835..dbe399bf72 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -125,6 +125,11 @@ typedef struct VPxEncoderContext {
> >   * encounter a frame with ROI side data.
> >   */
> >  int roi_warned;
> > +
> > +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
> > +vpx_svc_ref_frame_config_t ref_frame_config;
> > +AVDictionary *vpx_ref_frame_config;
> > +#endif
> >  } VPxContext;
> >
> >  /** String mappings for enum vp8e_enc_control_id */
> > @@ -152,6 +157,7 @@ static const char *const ctlidstr[] = {
> >  [VP9E_SET_SVC_LAYER_ID]= "VP9E_SET_SVC_LAYER_ID",
> >  #if VPX_ENCODER_ABI_VERSION >= 12
>
> This check isn't sufficient since the vpx_svc_ref_frame_config_t
> struct was changed a few times after this point.
>
> >  [VP9E_SET_SVC_PARAMETERS]  = "VP9E_SET_SVC_PARAMETERS",
> > +[VP9E_SET_SVC_REF_FRAME_CONFIG]=
> "VP9E_SET_SVC_REF_FRAME_CONFIG",
> >  #endif
> >  [VP9E_SET_SVC] = "VP9E_SET_SVC",
> >  #if VPX_ENCODER_ABI_VERSION >= 11
> > @@ -394,6 +400,18 @@ static void vp8_ts_parse_int_array(int *dest, char
> *value, size_t value_len, int
> >  }
> >  }
> >
> > +static void vp8_ts_parse_int64_array(int64_t *dest, char *value, size_t
> value_len, int max_entries)
> > +{
> > +int dest_idx = 0;
> > +char *saveptr = NULL;
> > +char *token = av_strtok(value, ",", &saveptr);
> > +
> > +while (token && dest_idx < max_entries) {
> > +dest[dest_idx++] = strtoul(token, NULL, 10);
>
> int64 seems like it was overkill in the api, but you probably want
> strtoull here.
> ___
> 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".


I tried to figure out the right version number, but it seems that the
version number was not bumped when the change was made.
I tried to find a new #define that I could use, but cannot seem to find
one. Is there one that you could suggest I use? Or perhaps a way to find
one?
Need help.

Thank you,

Wonkap
___
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 000/162] VLC, esp. init_vlc patches

2020-11-23 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> This is the second version of my init_vlc patchset [1]. Given the
> feedback I received for the last version I stressed thread-safety of
> init functions of decoders. As a consequence, the amount of decoders
> with FF_CODEC_CAP_INIT_THREADSAFE increased by 25 (some of them were
> already thread-safe, just the flag was missing). I am not finished yet*,
> but I don't see a reason to postpone sending this patchset already.
> 
> It now saves 146KiB from the binary (and much more when using hardcoded
> tables).
> 
> [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-November/272127.html
> 
> Two patches of this patchset (#55 and #161) change MIPS code; this is
> untested as I don't have a MIPS. Would be nice if someone could test it. 
> 
> *: AAC needs much more work (e.g. these decoders claim to be
> init-threadsafe, but aren't).
> 
Will apply the patches that don't depend on ff_init_vlc_from_lengths()
tomorrow, namely:
avcodec/mpegaudiodec_template: Don't use unnecessarily many VLC bits
avcodec/mv30: Don't check for errors for complete VLCs
avcodec/imm4: Don't use too big VLC table
avcodec/aac*: Make initializing ff_aac_pow*sf_tab thread-safe
avcodec/aactab: Fix conflicting types for ff_aac_codebook*
avcodec/qdmc: Don't check for errors for complete VLCs
avcodec/hqx: Don't check for errors for complete VLCs
avcodec/hqx: Inline constants
avcodec/intrax8: Make ff_intrax8_common_init() thread-safe
avcodec/intrax8: Replace always-false check by assert
avcodec/atrac9tab: Add missing static to internal table
avcodec/atrac9dec: Replace av_free() by av_freep() in close function
avcodec/atrac9dec: Don't use unnecessarily large VLC tables
avcodec/atrac9dec: Use least max_depth in calls to get_vlc2()
avcodec/atrac9dec: Don't confuse max_depth of VLC with max codelength
avcodec/truemotion2: Mark decoder as init-threadsafe
avcodec/g2meet: Use least max_depth in get_vlc2()
avcodec/sheervideo: Add av_cold to build_vlc()
avcodec/mss4: Mark decoder as init-threadsafe
avcodec/rv40vlc2: Make VLC smaller
avcodec/qdm2: Remove outdated comment
avcodec/mpegaudiodsp: Make initializing synth windows thread-safe
avcodec/mpegaudiodsp: Make ff_mpadsp_init() thread-safe
avcodec/fft_template, fft_init_table: Make ff_fft_init() thread-safe
avcodec/mpegaudiodsp: Combine initializing float and int tables
avcodec/motionpixels: Make decoder init-threadsafe
avcodec/motionpixels: Use symbols table
avcodec/motionpixels: Don't check for errors for complete VLC
avcodec/motionpixels: Be more strict when parsing Huffman trees
avcodec/motionpixels: Only create VLC iff it is going to be used
avcodec/mimic: Mark decoder as init-threadsafe
avcodec/mimic: Cleanup generically upon init failure
avcodec/rv10: Make initializing static RV10 VLCs thread-safe
avcodec/smacker: Mark decoders as init-threadsafe
avcodec/tscc2: Mark tscc2 decoder as init-threadsafe

- 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 1/3] avformat/flvdec: Treat high ts byte as unsigned

2020-11-23 Thread Michael Niedermayer
Fixes: left shift of 255 by 24 places cannot be represented in type 'int'
Fixes: 
27516/clusterfuzz-testcase-minimized-ffmpeg_dem_KUX_fuzzer-5152854660349952

Signed-off-by: Michael Niedermayer 
---
 libavformat/flvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index ad6e7a3ca5..3edb16722b 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -1158,7 +1158,7 @@ retry_duration:
 avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
 if (size == avio_rb24(s->pb) + 11) {
 uint32_t ts = avio_rb24(s->pb);
-ts |= avio_r8(s->pb) << 24;
+ts |= (unsigned)avio_r8(s->pb) << 24;
 if (ts)
 s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
 else if (fsize >= 8 && fsize - 8 >= size) {
-- 
2.17.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/3] avformat/rmdec: Check remaining space in debug av_log() loop

2020-11-23 Thread Michael Niedermayer
Fixes: Timeout (long -> 2 ms)
Fixes: 
26709/clusterfuzz-testcase-minimized-ffmpeg_dem_IVR_fuzzer-5665833403285504
Fixes: 
27522/clusterfuzz-testcase-minimized-ffmpeg_dem_IVR_fuzzer-6321071221112832

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

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 004c62086d..3ccd4f1ab5 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -1290,8 +1290,11 @@ static int ivr_read_header(AVFormatContext *s)
 int j;
 
 av_log(s, AV_LOG_DEBUG, "%s = '0x", key);
-for (j = 0; j < len; j++)
+for (j = 0; j < len; j++) {
+if (avio_feof(pb))
+return AVERROR_INVALIDDATA;
 av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb));
+}
 av_log(s, AV_LOG_DEBUG, "'\n");
 } else if (len == 4 && type == 3 && !strncmp(key, "Duration", 
tlen)) {
 st->duration = avio_rb32(pb);
-- 
2.17.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/3] avformat/wavdec: Consider AV_INPUT_BUFFER_PADDING_SIZE in set_spdif()

2020-11-23 Thread Michael Niedermayer
The buffer is read by using the bit reader
Fixes: out of array read
Fixes: 
27539/clusterfuzz-testcase-minimized-ffmpeg_dem_WAV_fuzzer-5650565572591616

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/wavdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index df6030a42d..ef25544b1d 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -72,7 +72,7 @@ static void set_spdif(AVFormatContext *s, WAVDemuxContext 
*wav)
 int ret = ffio_ensure_seekback(s->pb, len);
 
 if (ret >= 0) {
-uint8_t *buf = av_malloc(len);
+uint8_t *buf = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE);
 if (!buf) {
 ret = AVERROR(ENOMEM);
 } else {
-- 
2.17.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] New Ticket #9006

2020-11-23 Thread Deep Thought
I have opened a ticket explaining a problem with the code for
merge_pmt_versions.

Attached is also a patch which fixes this problem. The main idea is the
following:


for the INITIAL pmt, the old code finds matching streams by
1) checking the stream_identifier. If the current stream has one,
and if an earlier processed stream has the same one, it is assumed
that the two streams should be merged (I am not sure what this really
means, but the result is playback problems).

This behavior is wrong for streams having multiple audio streams with the
same stream_identifier

2) for streams without a stream identifier, it will look for a stream which
has the same position in the pmt as the current stream and will obviously
not find one. This is correct

So the patch solves the problem in 1) as follows:
1) if a stream has a stream identifier, it first computes a new variable
pmt_stream_index which will equal for the first stream with that
identifier, 1 for the second one with that identifier and so on
2) if a stream has no stream_identifier, pmt_stream_index will equal 0 for
the first such stream, 1 for the second such stream ... This is the same
as 1) but with stream_identifier==-1

find_matching_stream then compares streams based on a DUAL criterion:
pmt_stream_index must match, and stream_type must match.

The result is that for the INITIAL pmt all audi streams will be considered
different. If later the PMT changes, streams will be matched based on
stream identifier as the primary criterion and based on pmt_stream_index as
the secondary criterion.



-- 
---Deep Thought
From 8d2b61cd85ba98edebae3cd2648fe7c4008d76b3 Mon Sep 17 00:00:00 2001
From: Deep Thought 
Date: Mon, 23 Nov 2020 23:57:17 +0100
Subject: [PATCH] Patch for ticket #9006 incorrect merge_pmt_versions behavior

---
 libavformat/mpegts.c | 59 +---
 1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a2003c6632..c4f1377d97 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2200,6 +2200,22 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 return 0;
 }
 
+
+#define MAX_NUM_STREAMS (32)
+
+
+static char compute_pmt_stream_idx(char stream_identifier,
+   
 char 
stream_identifiers[MAX_NUM_STREAMS], int num_stream_identifiers)
+{
+   int i;
+   int pmt_stream_idx =0;
+   for(i=0;i <  num_stream_identifiers && i < MAX_NUM_STREAMS; ++i)
+   if(stream_identifiers[i]== stream_identifier)
+   pmt_stream_idx++;
+   return pmt_stream_idx;
+
+}
+
 static AVStream *find_matching_stream(MpegTSContext *ts, int pid, unsigned int 
programid,
   int stream_identifier, int 
pmt_stream_idx)
 {
@@ -2210,17 +2226,14 @@ static AVStream *find_matching_stream(MpegTSContext 
*ts, int pid, unsigned int p
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
 if (st->program_num != programid)
-continue;
-if (stream_identifier != -1) { /* match based on "stream identifier 
descriptor" if present */
-if (st->stream_identifier == stream_identifier+1) {
-found = st;
-break;
-}
-} else if (st->pmt_stream_idx == pmt_stream_idx) { /* match based on 
position within the PMT */
-found = st;
-break;
-}
-}
+   continue;
+   if (st->stream_identifier == stream_identifier+1
+   && st->pmt_stream_idx == 
pmt_stream_idx) {
+   found = st;
+   break;
+   }
+   }
+
 
 if (found) {
 av_log(ts->stream, AV_LOG_VERBOSE,
@@ -2360,6 +2373,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 
 set_pmt_found(ts, h->id);
 
+   char stream_identifiers[MAX_NUM_STREAMS];
+   int pmt_stream_idx=-1;
 
 for (i = 0; ; i++) {
 st = 0;
@@ -2374,14 +2389,18 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 if (pid == ts->current_pid)
 goto out;
 
-if (ts->merge_pmt_versions)
-stream_identifier = parse_stream_identifier_desc(p, p_end);
+if (ts->merge_pmt_versions) {
+stream_identifier = parse_stream_identifier_desc(p, p_end);
+   pmt_stream_idx = 
compute_pmt_stream_idx(stream_identifier,stream_identifiers, i);
+   if(i< MAX_NUM_STREAMS)
+   stream_identifiers[i] =  
stream_identifier;
+  

[FFmpeg-devel] [PATCH] av_filter/vf_xfade: ensure metadata is copied to transition frames

2020-11-23 Thread Musee Ullah
I was having an issue where, using a filter chain of xfade -> ass, the
colors on the subtitles were incorrect only on the frames where xfade
was being used. This resolves that issue for me.

Signed-off-by: Musee Ullah 
---
 libavfilter/vf_xfade.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/vf_xfade.c b/libavfilter/vf_xfade.c
index 6b94cc7036..4e07d7b525 100644
--- a/libavfilter/vf_xfade.c
+++ b/libavfilter/vf_xfade.c
@@ -1830,6 +1830,7 @@ static int xfade_frame(AVFilterContext *ctx, AVFrame *a, 
AVFrame *b)
 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 if (!out)
 return AVERROR(ENOMEM);
+av_frame_copy_props(out, a);
 
 td.xf[0] = a, td.xf[1] = b, td.out = out, td.progress = progress;
 ctx->internal->execute(ctx, xfade_slice, &td, NULL, FFMIN(outlink->h, 
ff_filter_get_nb_threads(ctx)));
-- 
2.29.2

___
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] avformat/rtsp: prefer to use MAX_URL_SIZE for url and command buffer

2020-11-23 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavformat/rtsp.c| 22 +++---
 libavformat/rtsp.h|  5 +++--
 libavformat/rtspdec.c | 20 ++--
 libavformat/rtspenc.c |  4 ++--
 4 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 0be405a..c7ffa07 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1025,7 +1025,7 @@ static void handle_rtp_info(RTSPState *rt, const char 
*url,
 static void rtsp_parse_rtp_info(RTSPState *rt, const char *p)
 {
 int read = 0;
-char key[20], value[1024], url[1024] = "";
+char key[20], value[MAX_URL_SIZE], url[MAX_URL_SIZE] = "";
 uint32_t seq = 0, rtptime = 0;
 
 for (;;) {
@@ -1124,7 +1124,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s)
 {
 RTSPState *rt = s->priv_data;
 int ret, len, len1;
-uint8_t buf[1024];
+uint8_t buf[MAX_URL_SIZE];
 
 ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
 if (ret != 3)
@@ -1150,7 +1150,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, 
RTSPMessageHeader *reply,
int return_on_interleaved_data, const char *method)
 {
 RTSPState *rt = s->priv_data;
-char buf[4096], buf1[1024], *q;
+char buf[MAX_URL_SIZE], buf1[MAX_URL_SIZE], *q;
 unsigned char ch;
 const char *p;
 int ret, content_length, line_count = 0, request = 0;
@@ -1230,7 +1230,7 @@ start:
 av_freep(&content);
 
 if (request) {
-char buf[1024];
+char buf[MAX_URL_SIZE];
 char base64buf[AV_BASE64_SIZE(sizeof(buf))];
 const char* ptr = buf;
 
@@ -1306,7 +1306,7 @@ static int 
rtsp_send_cmd_with_content_async(AVFormatContext *s,
 int send_content_length)
 {
 RTSPState *rt = s->priv_data;
-char buf[4096], *out_buf;
+char buf[MAX_URL_SIZE], *out_buf;
 char base64buf[AV_BASE64_SIZE(sizeof(buf))];
 
 if (!rt->rtsp_hd_out)
@@ -1416,7 +1416,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const 
char *host, int port,
 int rtx = 0, j, i, err, interleave = 0, port_off;
 RTSPStream *rtsp_st;
 RTSPMessageHeader reply1, *reply = &reply1;
-char cmd[2048];
+char cmd[MAX_URL_SIZE];
 const char *trans_pref;
 
 if (rt->transport == RTSP_TRANSPORT_RDT)
@@ -1437,7 +1437,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const 
char *host, int port,
 port_off -= port_off & 0x01;
 
 for (j = rt->rtp_port_min + port_off, i = 0; i < rt->nb_rtsp_streams; ++i) 
{
-char transport[2048];
+char transport[MAX_URL_SIZE];
 
 /*
  * WMS serves all UDP data over a single connection, the RTX, which
@@ -1586,7 +1586,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const 
char *host, int port,
 break;
 
 case RTSP_LOWER_TRANSPORT_UDP: {
-char url[1024], options[30] = "";
+char url[MAX_URL_SIZE], options[30] = "";
 const char *peer = host;
 
 if (rt->rtsp_flags & RTSP_FLAG_FILTER_SRC)
@@ -1604,7 +1604,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const 
char *host, int port,
 break;
 }
 case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: {
-char url[1024], namebuf[50], optbuf[20] = "";
+char url[MAX_URL_SIZE], namebuf[50], optbuf[20] = "";
 struct sockaddr_storage addr;
 int port, ttl;
 AVDictionary *opts = map_to_opts(rt);
@@ -1666,7 +1666,7 @@ int ff_rtsp_connect(AVFormatContext *s)
 {
 RTSPState *rt = s->priv_data;
 char proto[128], host[1024], path[1024];
-char tcpname[1024], cmd[2048], auth[128];
+char tcpname[1024], cmd[MAX_URL_SIZE], auth[128];
 const char *lower_rtsp_proto = "tcp";
 int port, err, tcp_fd;
 RTSPMessageHeader reply1, *reply = &reply1;
@@ -2324,7 +2324,7 @@ static int sdp_read_header(AVFormatContext *s)
 RTSPStream *rtsp_st;
 int size, i, err;
 char *content;
-char url[1024];
+char url[MAX_URL_SIZE];
 
 if (!ff_network_init())
 return AVERROR(EIO);
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 251ed86..b74cdc1 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -27,6 +27,7 @@
 #include "rtpdec.h"
 #include "network.h"
 #include "httpauth.h"
+#include "internal.h"
 
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
@@ -316,7 +317,7 @@ typedef struct RTSPState {
 /** some MS RTSP streams contain a URL in the SDP that we need to use
  * for all subsequent RTSP requests, rather than the input URI; in
  * other cases, this is a copy of AVFormatContext->filename. */
-char control_uri[2048];
+char control_uri[MAX_URL_SIZE];
 
 /** The following are used for parsing raw mpegts in udp */
 //@{
@@ -444,7 +445,7 @@ typedef struct RTSPStream {
  * for the selected transport. Only used for TCP. */
 int interleaved_min, interleaved_max;
 
-char control_url[10

[FFmpeg-devel] [PATCH] ffbuild/libversion.sh: Add shebang

2020-11-23 Thread Yuta Sekiguchi
From: aYutaSekiguchi 

Signed-off-by: aYutaSekiguchi 
---
 ffbuild/libversion.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ffbuild/libversion.sh b/ffbuild/libversion.sh
index 990ce9f640..30046b1d25 100755
--- a/ffbuild/libversion.sh
+++ b/ffbuild/libversion.sh
@@ -1,3 +1,5 @@
+#!/bin/sh
+
 toupper(){
 echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
 }
-- 
2.24.3 (Apple Git-128)


-- 
.
___
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".