Re: [FFmpeg-devel] [PATCH] avcodec/avpacket: add av_packet_remove_side_data()

2020-09-08 Thread Guangxin Xu
On Wed, Sep 9, 2020 at 6:36 AM James Almer  wrote:

> This helper removes a side data entry from the packet, maintaining the
> integrity and order of the remaining entries, if any.
>
> Signed-off-by: James Almer 
> ---
> Missing APIChanges entry and version bump.
>
> Couldn't find a place in the tree where it could be used right now, but
> it makes the API be more in line with the AVFrame one, so i decided to
> write it.
>
>  libavcodec/avpacket.c | 24 
>  libavcodec/packet.h   |  8 
>  2 files changed, 32 insertions(+)
>
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 4801163227..61ea81698c 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -367,6 +367,30 @@ uint8_t *av_packet_get_side_data(const AVPacket *pkt,
> enum AVPacketSideDataType
>  return NULL;
>  }
>
> +void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType
> type)
> +{
> +int i, elems;
> +
> +for (i = 0; i < pkt->side_data_elems; i++) {
> +if (pkt->side_data[i].type != type)
> +continue;
> +
> +elems = pkt->side_data_elems - 1;
> +av_freep(&pkt->side_data[i].data);
> +pkt->side_data[i].size = 0;
>

Nit: This not needed since we will overwrite pkg->side_data[i] or shrink
the  side_data_elems later.


> +
> +if (i < elems) {
> +memmove(&pkt->side_data[i], &pkt->side_data[i + 1],
> +(elems - i) * sizeof(*pkt->side_data));
> +}
> +if (!elems)
> +av_freep(&pkt->side_data);
> +pkt->side_data_elems = elems;
> +
> +break;
> +}
> +}
> +
>  const char *av_packet_side_data_name(enum AVPacketSideDataType type)
>  {
>  switch(type) {
> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> index 0a19a0eff3..6ce3c91c07 100644
> --- a/libavcodec/packet.h
> +++ b/libavcodec/packet.h
> @@ -595,6 +595,14 @@ int av_packet_shrink_side_data(AVPacket *pkt, enum
> AVPacketSideDataType type,
>  uint8_t* av_packet_get_side_data(const AVPacket *pkt, enum
> AVPacketSideDataType type,
>   int *size);
>
> +/**
> + * Remove and free a side data entry of the given type.
> + *
> + * @param pkt packet
> + * @param type side data type to be removed
> + */
> +void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType
> type);
> +
>  #if FF_API_MERGE_SD_API
>  attribute_deprecated
>  int av_packet_merge_side_data(AVPacket *pkt);
> --
> 2.27.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 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/libopusenc: add option to set inband FEC

2020-09-08 Thread Gyan Doshi

Pushed as 1e5b3f77d9f6f6827b5755763ef041d360969d0c

On 08-09-2020 10:32 am, Gyan Doshi wrote:

Plan to push in a day.

On 06-09-2020 12:27 pm, Gyan Doshi wrote:

---
  doc/encoders.texi   | 5 +
  libavcodec/libopusenc.c | 9 +
  2 files changed, 14 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 69bf742c2d..a48b15eb1b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -953,6 +953,11 @@ The default is 20ms.
  @item packet_loss (@emph{expect-loss})
  Set expected packet loss percentage. The default is 0.
  +@item fec (@emph{n/a})
+Enable inband forward error correction. @option{packet_loss} must be 
non-zero
+to take advantage - frequency of FEC 'side-data' is proportional to 
expected packet loss.

+Default is disabled.
+
  @item application (N.A.)
  Set intended application type. Valid options are listed below:
  diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 13017ac323..bf2d04b4fb 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -34,6 +34,7 @@ typedef struct LibopusEncOpts {
  int vbr;
  int application;
  int packet_loss;
+    int fec;
  int complexity;
  float frame_duration;
  int packet_size;
@@ -149,6 +150,13 @@ static int 
libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,

 "Unable to set expected packet loss percentage: %s\n",
 opus_strerror(ret));
  +    ret = opus_multistream_encoder_ctl(enc,
+ OPUS_SET_INBAND_FEC(opts->fec));
+    if (ret != OPUS_OK)
+    av_log(avctx, AV_LOG_WARNING,
+   "Unable to set inband FEC: %s\n",
+   opus_strerror(ret));
+
  if (avctx->cutoff) {
  ret = opus_multistream_encoder_ctl(enc,
OPUS_SET_MAX_BANDWIDTH(opts->max_bandwidth));
@@ -544,6 +552,7 @@ static const AVOption libopus_options[] = {
  { "lowdelay",   "Restrict to only the lowest delay 
modes", 0, AV_OPT_TYPE_CONST, { .i64 = 
OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0, FLAGS, "application" },
  { "frame_duration", "Duration of a frame in milliseconds", 
OFFSET(frame_duration), AV_OPT_TYPE_FLOAT, { .dbl = 20.0 }, 2.5, 
120.0, FLAGS },
  { "packet_loss",    "Expected packet loss percentage", 
OFFSET(packet_loss),    AV_OPT_TYPE_INT,   { .i64 = 0 },    0, 100,  
FLAGS },
+    { "fec", "Enable inband FEC. Expected packet loss 
must be non-zero", OFFSET(fec),    AV_OPT_TYPE_BOOL, { .i64 = 0 
}, 0, 1, FLAGS },
  { "vbr",    "Variable bit rate mode", 
OFFSET(vbr),    AV_OPT_TYPE_INT,   { .i64 = 1 },    0, 2,    
FLAGS, "vbr" },
  { "off",    "Use constant bit rate", 0, 
AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, "vbr" },
  { "on", "Use variable bit rate", 0, 
AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "vbr" },


___
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] examples/decode_video: flush parser to fix missing frame

2020-09-08 Thread Guangxin Xu
On Tue, Aug 18, 2020 at 8:05 PM  wrote:

> From: Zhao Zhili 
>
> To reproduce, run decode_video with a single frame sample. No frame
> was decoded before the patch.
> ---
>  doc/examples/decode_video.c | 12 +++-
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
> index 169188a4b9..ba753c6dc1 100644
> --- a/doc/examples/decode_video.c
> +++ b/doc/examples/decode_video.c
> @@ -92,6 +92,7 @@ int main(int argc, char **argv)
>  uint8_t *data;
>  size_t   data_size;
>  int ret;
> +int eof;
>  AVPacket *pkt;
>
>  if (argc <= 2) {
> @@ -150,15 +151,14 @@ int main(int argc, char **argv)
>  exit(1);
>  }
>
> -while (!feof(f)) {
> +do {
>  /* read raw data from the input file */
>  data_size = fread(inbuf, 1, INBUF_SIZE, f);
> -if (!data_size)
> -break;
> +eof = !data_size;
>
>  /* use the parser to split the data into frames */
>  data = inbuf;
> -while (data_size > 0) {
> +while (data_size > 0 || eof) {
>  ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size,
> data, data_size, AV_NOPTS_VALUE,
> AV_NOPTS_VALUE, 0);
>  if (ret < 0) {
> @@ -170,8 +170,10 @@ int main(int argc, char **argv)
>
>  if (pkt->size)
>  decode(c, frame, pkt, outfilename);
> +if (eof)
> +break;
>
what if the parser cached more than one frame at the eof?

>  }
> -}
> +} while (!eof);
>
>  /* flush the decoder */
>  decode(c, frame, NULL, outfilename);
> --
> 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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/hevcdec: fix stat_coeff save/load for persistent_rice_adaptation_enabled_flag

2020-09-08 Thread Guangxin Xu
Hi Mickaël & all,
any suggestions?

On Sat, Aug 29, 2020 at 1:52 PM Xu Guangxin  wrote:

> It's required by 9.3.1. following clips have this feature:
>
> WPP_HIGH_TP_444_8BIT_RExt_Apple_2.bit
> Bitdepth_A_RExt_Sony_1.bin
> Bitdepth_B_RExt_Sony_1.bin
> EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_10BIT_RExt_Sony_1.bit
> EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_12BIT_RExt_Sony_1.bit
> EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_8BIT_RExt_Sony_1.bit
> EXTPREC_MAIN_444_16_INTRA_10BIT_RExt_Sony_1.bit
> EXTPREC_MAIN_444_16_INTRA_12BIT_RExt_Sony_1.bit
> EXTPREC_MAIN_444_16_INTRA_8BIT_RExt_Sony_1.bit
> WPP_AND_TILE_10Bit422Test_HIGH_TP_444_10BIT_RExt_Apple_2.bit
> WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_0_HIGH_TP_444_14BIT_RExt_Apple_2.bit
> WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_1_HIGH_TP_444_14BIT_RExt_Apple_2.bit
> WPP_AND_TILE_HIGH_TP_444_8BIT_RExt_Apple_2.bit
>
> you can download them from:
>
> https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/RExt/
>
> Signed-off-by: Xu Guangxin 
> ---
>  libavcodec/hevc_cabac.c | 6 ++
>  libavcodec/hevcdec.h| 4 +++-
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
> index 3dc0987dad..635b4edef3 100644
> --- a/libavcodec/hevc_cabac.c
> +++ b/libavcodec/hevc_cabac.c
> @@ -454,12 +454,18 @@ void ff_hevc_save_states(HEVCContext *s, int
> ctb_addr_ts)
>   (s->ps.sps->ctb_width == 2 &&
>ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
>  memcpy(s->cabac_state, s->HEVClc->cabac_state, HEVC_CONTEXTS);
> +if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
> +memcpy(s->stat_coeff, s->HEVClc->stat_coeff,
> HEVC_STAT_COEFFS);
> +}
>  }
>  }
>
>  static void load_states(HEVCContext *s)
>  {
>  memcpy(s->HEVClc->cabac_state, s->cabac_state, HEVC_CONTEXTS);
> +if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
> +memcpy(s->HEVClc->stat_coeff, s->stat_coeff, HEVC_STAT_COEFFS);
> +}
>  }
>
>  static int cabac_reinit(HEVCLocalContext *lc)
> diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
> index 39c5c7f89f..d41aed4556 100644
> --- a/libavcodec/hevcdec.h
> +++ b/libavcodec/hevcdec.h
> @@ -53,6 +53,7 @@
>  #define DEFAULT_INTRA_TC_OFFSET 2
>
>  #define HEVC_CONTEXTS 199
> +#define HEVC_STAT_COEFFS 4
>
>  #define MRG_MAX_NUM_CANDS 5
>
> @@ -424,7 +425,7 @@ typedef struct HEVCFrame {
>  typedef struct HEVCLocalContext {
>  uint8_t cabac_state[HEVC_CONTEXTS];
>
> -uint8_t stat_coeff[4];
> +uint8_t stat_coeff[HEVC_STAT_COEFFS];
>
>  uint8_t first_qp_group;
>
> @@ -480,6 +481,7 @@ typedef struct HEVCContext {
>  int height;
>
>  uint8_t *cabac_state;
> +uint8_t stat_coeff[HEVC_STAT_COEFFS];
>
>  /** 1 if the independent slice segment header was successfully parsed
> */
>  uint8_t slice_initialized;
> --
> 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 V3 1/2] avcodec: add av1 hardware acceleration decoder

2020-09-08 Thread Fei Wang
This av1 decoder is now only used for av1 hardware acceleration
decoder. Consider it can be extend to a local decoder like hevc
or vp9 in the future, so define its name as "av1" and put it into
external libraries codec list.

Signed-off-by: Fei Wang 
---
update:
1. reuse buffer for tile_group_info.
2. set avctx/frame props from sequence and frame header.
3. refine ref/unref for s->seq_ref/s->header_ref.
4. refine av1_decode_frame to reduce duplicated code.

 Changelog  |   1 +
 configure  |   1 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/av1dec.c| 860 +
 libavcodec/av1dec.h|  70 
 libavcodec/version.h   |   2 +-
 7 files changed, 935 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/av1dec.c
 create mode 100644 libavcodec/av1dec.h

diff --git a/Changelog b/Changelog
index ff9ff2fcb8..a89010d7e1 100644
--- a/Changelog
+++ b/Changelog
@@ -21,6 +21,7 @@ version :
 - MOFLEX demuxer
 - MODS demuxer
 - PhotoCD decoder
+- AV1 decoder (Hardware acceleration used only)
 
 
 version 4.3:
diff --git a/configure b/configure
index f13d1a8c9a..5893ae3473 100755
--- a/configure
+++ b/configure
@@ -2685,6 +2685,7 @@ atrac3al_decoder_select="mdct"
 atrac3p_decoder_select="mdct sinewin"
 atrac3pal_decoder_select="mdct sinewin"
 atrac9_decoder_select="mdct"
+av1_decoder_select="cbs_av1"
 avrn_decoder_select="exif jpegtables"
 bink_decoder_select="blockdsp hpeldsp"
 binkaudio_dct_decoder_select="mdct rdft dct sinewin wma_freqs"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 98f31e246b..5729cdd8e7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -768,6 +768,7 @@ OBJS-$(CONFIG_ZLIB_DECODER)+= lcldec.o
 OBJS-$(CONFIG_ZLIB_ENCODER)+= lclenc.o
 OBJS-$(CONFIG_ZMBV_DECODER)+= zmbv.o
 OBJS-$(CONFIG_ZMBV_ENCODER)+= zmbvenc.o
+OBJS-$(CONFIG_AV1_DECODER) += av1dec.o
 
 # (AD)PCM decoders/encoders
 OBJS-$(CONFIG_PCM_ALAW_DECODER)   += pcm.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f3572a47e3..1e374c99f2 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -766,6 +766,7 @@ extern AVCodec ff_idf_decoder;
  * above is available */
 extern AVCodec ff_aac_mf_encoder;
 extern AVCodec ff_ac3_mf_encoder;
+extern AVCodec ff_av1_decoder;
 extern AVCodec ff_h263_v4l2m2m_encoder;
 extern AVCodec ff_libaom_av1_decoder;
 extern AVCodec ff_libopenh264_encoder;
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
new file mode 100644
index 00..c2ca32
--- /dev/null
+++ b/libavcodec/av1dec.c
@@ -0,0 +1,860 @@
+/*
+ * AV1video decoder
+ *
+ * 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 "get_bits.h"
+#include "hwconfig.h"
+#include "internal.h"
+#include "profiles.h"
+#include "libavutil/pixdesc.h"
+#include "av1dec.h"
+
+static void setup_past_independence(AV1Frame *f)
+{
+f->loop_filter_delta_enabled = 1;
+
+f->loop_filter_ref_deltas[AV1_REF_FRAME_INTRA] = 1;
+f->loop_filter_ref_deltas[AV1_REF_FRAME_LAST] = 0;
+f->loop_filter_ref_deltas[AV1_REF_FRAME_LAST2] = 0;
+f->loop_filter_ref_deltas[AV1_REF_FRAME_LAST3] = 0;
+f->loop_filter_ref_deltas[AV1_REF_FRAME_GOLDEN] = -1;
+f->loop_filter_ref_deltas[AV1_REF_FRAME_BWDREF] = 0;
+f->loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF2] = -1;
+f->loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF] = -1;
+
+f->loop_filter_mode_deltas[0] = 0;
+f->loop_filter_mode_deltas[1] = 0;
+}
+
+static void load_previous_and_update(AV1DecContext *s)
+{
+uint8_t primary_frame, prev_frame;
+
+primary_frame = s->raw_frame_header->primary_ref_frame;
+prev_frame = s->raw_frame_header->ref_frame_idx[primary_frame];
+memcpy(s->cur_frame.loop_filter_ref_deltas,
+   s->ref[prev_frame].loop_filter_ref_deltas,
+   AV1_NUM_REF_FRAMES * sizeof(int8_t));
+memcpy(s->cur_frame.loop_filter_mode_deltas,
+   s->ref[prev_frame].loop_filter_mode_deltas,
+   2 * sizeof(int8_t));
+
+if (s->raw_frame_header->loop_filter_delta_update) {
+for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
+if (s->raw_frame_header->update_ref_delta[i])
+s->cur_fra

[FFmpeg-devel] [PATCH V3 2/2] avcodec: add av1 VAAPI decoder

2020-09-08 Thread Fei Wang
Example cmdline:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -v verbose \
-c:v av1 -i input.ivf -pix_fmt yuv420p -vsync passthrough -f md5 \
-y out.md5

Signed-off-by: Fei Wang 
---
 Changelog |   1 +
 configure |   3 +
 libavcodec/Makefile   |   1 +
 libavcodec/av1dec.c   |  23 ++-
 libavcodec/hwaccels.h |   1 +
 libavcodec/vaapi_av1.c| 285 ++
 libavcodec/vaapi_decode.c |   8 ++
 libavcodec/version.h  |   2 +-
 8 files changed, 322 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/vaapi_av1.c

diff --git a/Changelog b/Changelog
index a89010d7e1..fb1fd55571 100644
--- a/Changelog
+++ b/Changelog
@@ -22,6 +22,7 @@ version :
 - MODS demuxer
 - PhotoCD decoder
 - AV1 decoder (Hardware acceleration used only)
+- AV1 VAAPI decoder
 
 
 version 4.3:
diff --git a/configure b/configure
index 5893ae3473..81f3c80e8e 100755
--- a/configure
+++ b/configure
@@ -2917,6 +2917,8 @@ videotoolbox_hwaccel_deps="videotoolbox pthreads"
 videotoolbox_hwaccel_extralibs="-framework QuartzCore"
 xvmc_deps="X11_extensions_XvMClib_h"
 
+av1_vaapi_hwaccel_deps="vaapi_1_8"
+av1_vaapi_hwaccel_select="av1_decoder"
 h263_vaapi_hwaccel_deps="vaapi"
 h263_vaapi_hwaccel_select="h263_decoder"
 h263_videotoolbox_hwaccel_deps="videotoolbox"
@@ -6680,6 +6682,7 @@ if enabled vaapi; then
 fi
 
 check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
+check_cpp_condition vaapi_1_8 "va/va.h" "VA_CHECK_VERSION(1, 8, 0)"
 
 check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
 check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5729cdd8e7..4d54ddc684 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -954,6 +954,7 @@ OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
 OBJS-$(CONFIG_VP8_QSV_HWACCEL)+= qsvdec_other.o
+OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 
 # libavformat dependencies
 OBJS-$(CONFIG_ISO_MEDIA)   += mpeg4audio.o mpegaudiodata.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index c2ca32..4098cbb655 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -262,7 +262,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 uint8_t bit_depth;
 int ret;
 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
-#define HWACCEL_MAX (0)
+#define HWACCEL_MAX (CONFIG_AV1_VAAPI_HWACCEL)
 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 1], *fmtp = pix_fmts;
 
 if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
@@ -323,6 +323,24 @@ static int get_pixel_format(AVCodecContext *avctx)
 return -1;
 s->pix_fmt = pix_fmt;
 
+switch (s->pix_fmt) {
+case AV_PIX_FMT_YUV420P:
+#if CONFIG_AV1_VAAPI_HWACCEL
+*fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+break;
+case AV_PIX_FMT_YUV420P10:
+#if CONFIG_AV1_VAAPI_HWACCEL
+*fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+break;
+case AV_PIX_FMT_YUV420P12:
+#if CONFIG_AV1_VAAPI_HWACCEL
+*fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+break;
+}
+
 *fmtp = AV_PIX_FMT_NONE;
 avctx->sw_pix_fmt = s->pix_fmt;
 ret = ff_thread_get_format(avctx, pix_fmts);
@@ -855,6 +873,9 @@ AVCodec ff_av1_decoder = {
 .flush = av1_decode_flush,
 .profiles  = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
 .hw_configs= (const AVCodecHWConfigInternal * []) {
+#if CONFIG_AV1_VAAPI_HWACCEL
+HWACCEL_VAAPI(av1),
+#endif
 NULL
 },
 };
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 6109c89bd6..18e9079c55 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -21,6 +21,7 @@
 
 #include "avcodec.h"
 
+extern const AVHWAccel ff_av1_vaapi_hwaccel;
 extern const AVHWAccel ff_h263_vaapi_hwaccel;
 extern const AVHWAccel ff_h263_videotoolbox_hwaccel;
 extern const AVHWAccel ff_h264_d3d11va_hwaccel;
diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
new file mode 100644
index 00..c5aeaf8b21
--- /dev/null
+++ b/libavcodec/vaapi_av1.c
@@ -0,0 +1,285 @@
+/*
+ * AV1 HW decode acceleration through VA API
+ *
+ * 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 

[FFmpeg-devel] [PATCH 1/2] dnn/openvino: support run inference via GPU

2020-09-08 Thread Ting Fu
for enabling OpenVINO GPU please:
1. install required OpenCL drivers, see: 
https://github.com/intel/compute-runtime/releases/tag/19.41.14441
2. build OpenVINO c lib with GPU enabled: use cmake config with: 
-DENABLE_CLDNN=ON
3. then make, and include the OpenVINO c lib in environment variables
detailed steps please refer: 
https://github.com/openvinotoolkit/openvino/blob/master/build-instruction.md

inference model with GPU please add: optioins=device=GPU

Signed-off-by: Ting Fu 
---
 libavfilter/dnn/dnn_backend_openvino.c | 52 ++
 1 file changed, 44 insertions(+), 8 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 5d6d3ed542..2f0998046a 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -26,10 +26,18 @@
 #include "dnn_backend_openvino.h"
 #include "libavformat/avio.h"
 #include "libavutil/avassert.h"
+#include "libavutil/opt.h"
+#include "libavutil/avstring.h"
+#include "../internal.h"
 #include 
 
+typedef struct OVOptions{
+char *device_type;
+} OVOptions;
+
 typedef struct OVContext {
 const AVClass *class;
+OVOptions options;
 } OVContext;
 
 typedef struct OVModel{
@@ -41,14 +49,19 @@ typedef struct OVModel{
 ie_blob_t *input_blob;
 } OVModel;
 
-static const AVClass dnn_openvino_class = {
-.class_name = "dnn_openvino",
-.item_name  = av_default_item_name,
-.option = NULL,
-.version= LIBAVUTIL_VERSION_INT,
-.category   = AV_CLASS_CATEGORY_FILTER,
+#define APPEND_STRING(generated_string, iterate_string)
\
+generated_string = generated_string ? av_asprintf("%s %s", 
generated_string, iterate_string) : \
+  av_asprintf("%s", iterate_string);
+
+#define OFFSET(x) offsetof(OVContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM
+static const AVOption dnn_openvino_options[] = {
+{ "device", "device to run model", OFFSET(options.device_type), 
AV_OPT_TYPE_STRING, { .str = "CPU" }, 0, 0, FLAGS },
+{ NULL }
 };
 
+AVFILTER_DEFINE_CLASS(dnn_openvino);
+
 static DNNDataType precision_to_datatype(precision_e precision)
 {
 switch (precision)
@@ -159,10 +172,13 @@ err:
 
 DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
 {
+char *all_dev_names = NULL;
 DNNModel *model = NULL;
 OVModel *ov_model = NULL;
+OVContext *ctx = NULL;
 IEStatusCode status;
 ie_config_t config = {NULL, NULL, NULL};
+ie_available_devices_t a_dev;
 
 model = av_malloc(sizeof(DNNModel));
 if (!model){
@@ -173,6 +189,14 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, 
const char *options)
 if (!ov_model)
 goto err;
 ov_model->ctx.class = &dnn_openvino_class;
+ctx = &ov_model->ctx;
+
+//parse options
+av_opt_set_defaults(ctx);
+if (av_opt_set_from_string(ctx, options, NULL, "=", "&") < 0) {
+av_log(ctx, AV_LOG_ERROR, "Failed to parse options \"%s\"\n", options);
+goto err;
+}
 
 status = ie_core_create("", &ov_model->core);
 if (status != OK)
@@ -182,9 +206,21 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, 
const char *options)
 if (status != OK)
 goto err;
 
-status = ie_core_load_network(ov_model->core, ov_model->network, "CPU", 
&config, &ov_model->exe_network);
-if (status != OK)
+status = ie_core_load_network(ov_model->core, ov_model->network, 
ctx->options.device_type, &config, &ov_model->exe_network);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to init OpenVINO model\n");
+status = ie_core_get_available_devices(ov_model->core, &a_dev);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to get available devices\n");
+goto err;
+}
+for (int i = 0; i < a_dev.num_devices; i++) {
+APPEND_STRING(all_dev_names, a_dev.devices[i])
+}
+av_log(ctx, AV_LOG_ERROR,"device %s may not be supported, all 
available devices are: \"%s\"\n",
+   ctx->options.device_type, all_dev_names);
 goto err;
+}
 
 model->model = (void *)ov_model;
 model->set_input = &set_input_ov;
-- 
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/2] dnn/openvino: add input/output name info

2020-09-08 Thread Ting Fu
show all input/output names when the input or output name not correct

Signed-off-by: Ting Fu 
---
 libavfilter/dnn/dnn_backend_openvino.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 2f0998046a..e5842906d1 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -79,6 +79,7 @@ static DNNReturnType get_input_ov(void *model, DNNData 
*input, const char *input
 OVModel *ov_model = (OVModel *)model;
 OVContext *ctx = &ov_model->ctx;
 char *model_input_name = NULL;
+char *all_input_names = NULL;
 IEStatusCode status;
 size_t model_input_count = 0;
 dimensions_t dims;
@@ -118,12 +119,15 @@ static DNNReturnType get_input_ov(void *model, DNNData 
*input, const char *input
 input->width= dims.dims[3];
 input->dt   = precision_to_datatype(precision);
 return DNN_SUCCESS;
+} else {
+//incorrect input name
+APPEND_STRING(all_input_names, model_input_name)
 }
 
 ie_network_name_free(&model_input_name);
 }
 
-av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", 
model_input_name);
+av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model, all input(s) 
are: \"%s\"\n", input_name, all_input_names);
 return DNN_ERROR;
 }
 
@@ -246,12 +250,15 @@ err:
 
 DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNData *outputs, 
const char **output_names, uint32_t nb_output)
 {
+char *model_output_name = NULL;
+char *all_output_names = NULL;
 dimensions_t dims;
 precision_e precision;
 ie_blob_buffer_t blob_buffer;
 OVModel *ov_model = (OVModel *)model->model;
 OVContext *ctx = &ov_model->ctx;
 IEStatusCode status = ie_infer_request_infer(ov_model->infer_request);
+size_t model_output_count = 0;
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model 
inference\n");
 return DNN_ERROR;
@@ -262,7 +269,16 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel 
*model, DNNData *outputs, c
 ie_blob_t *output_blob = NULL;
 status = ie_infer_request_get_blob(ov_model->infer_request, 
output_name, &output_blob);
 if (status != OK) {
+//incorrect output name
 av_log(ctx, AV_LOG_ERROR, "Failed to get model output data\n");
+status = ie_network_get_outputs_number(ov_model->network, 
&model_output_count);
+for (size_t i = 0; i < model_output_count; i++) {
+status = ie_network_get_output_name(ov_model->network, i, 
&model_output_name);
+APPEND_STRING(all_output_names, model_output_name)
+}
+av_log(ctx, AV_LOG_ERROR,
+   "output \"%s\" may not correct, all output(s) are: 
\"%s\"\n",
+   output_name, all_output_names);
 return DNN_ERROR;
 }
 
-- 
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".

Re: [FFmpeg-devel] [PATCH 25/25] avfilter/af_headphone: Don't check for clipping in separate loop

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:56PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
> More patches will be coming later.
> 
>  libavfilter/af_headphone.c | 10 ++
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 

Actually on second look, it does not hurt at all.
___
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 24/25] avfilter/af_headphone: Remove pointless additions

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:55PM +0200, Andreas Rheinhardt wrote:
> buffer_length is a power-of-two and modulo is buffer_length - 1, so that
> buffer_length & modulo is zero.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

fine
___
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 23/25] avfilter/af_headphone: Use more appropriate variable name

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:54PM +0200, Andreas Rheinhardt wrote:
> Also unify incrementing the variable containing the pointer
> to the currently used HRIR data.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 

probably ok
___
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 22/25] avfilter/af_headphone: Avoid indirection for function pointer

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:53PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 15 +--
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 

probably useful
___
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 20/25] avfilter/af_headphone: Don't allocate unused element in array

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:51PM +0200, Andreas Rheinhardt wrote:
> The headphone filter uses an array with as many elements as the
> filter has inputs to store some per-input information; yet actually it
> only stores information for all inputs except the very first one (which
> is special for this filter). Therefore this commit modifies the code to
> remove this unused element.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 50 +++---
>  1 file changed, 25 insertions(+), 25 deletions(-)
> 

should be fine if does not break anything.
___
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 19/25] avfilter/af_headphone: Only keep one AVFrame at a time

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:50PM +0200, Andreas Rheinhardt wrote:
> Despite the headphone filter only using one AVFrame at a time, it kept
> an array each of whose entries contained a pointer to an AVFrame at all
> times; the pointers were mostly NULL. This commit instead replaces them
> by using a single pointer to an AVFrame on the stack of the only
> function that actually uses them.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 14 --
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 

should be fine if properly tested.
___
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 18/25] avfilter/af_headphone: Avoid intermediate buffer III

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:49PM +0200, Andreas Rheinhardt wrote:
> The headphone filter allocates a pair of buffers to be used as
> intermediate buffers lateron: Before every use they are zeroed, then
> some elements of the buffer are set and lateron the complete buffers are
> copied into another, bigger buffer. These intermediate buffers are
> unnecessary as the data can be directly written into the bigger buffer.
> Furthermore, the whole buffer has been zeroed initially and because no
> piece of this buffer is set twice (due to the fact that duplicate
> channel map entries are skipped), it is unnecessary to rezero the part
> of the big buffer that is about to be written to.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 28 +---
>  1 file changed, 5 insertions(+), 23 deletions(-)
> 

should be fine if properly tested.
___
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 17/25] avfilter/af_headphone: Simplify finding channel index

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:48PM +0200, Andreas Rheinhardt wrote:
> Before this commit, the headphone filter called
> av_channel_layout_extract_channel() in a loop in order to find out
> the index of a channel (given via its AV_CH_* value) in a channel layout.
> This commit changes this to av_get_channel_layout_channel_index()
> instead.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 32 
>  1 file changed, 8 insertions(+), 24 deletions(-)
> 

should be fine if does not break usage.
___
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 16/25] avfilter/af_headphone: Fix channel assignment

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:47PM +0200, Andreas Rheinhardt wrote:
> The documentation of the map argument of the headphone filter states:
> 
> "Set mapping of input streams for convolution. The argument is a
> ’|’-separated list of channel names in order as they are given as
> additional stream inputs for filter."
> 
> Yet this has not been honoured at all. Instead for the kth given HRIR
> channel pair it was checked whether there was a kth mapping and if the
> channel position so given was present in the channel layout of the main
> input; if so, then the given HRIR channel pair was matched to the kth
> channel of the main input. It should actually have been matched to the
> channel given by the kth mapping. A consequence of the current algorithm
> is that if N additional HRIR channel pairs are given, a permutation of
> the first N entries of the mapping does not affect the output at all.
> 
> The old code might even set arrays belonging to streams that don't exist
> (i.e. whose index is >= the number of channels of the main input
> stream); these parts were not read lateron at all. The new code doesn't
> do this any longer and therefore the number of elements of some of the
> allocated arrays has been reduced (in case the number of mappings was
> bigger than the number of channels of the first input stream).
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 21 +++--
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 

should be fine if properly tested.
___
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/extract_extradata: Consolidate zeroing extradata padding

2020-09-08 Thread James Almer
On 9/7/2020 10:17 AM, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/extract_extradata_bsf.c | 6 +-
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/libavcodec/extract_extradata_bsf.c 
> b/libavcodec/extract_extradata_bsf.c
> index 1fead74b57..6e80076522 100644
> --- a/libavcodec/extract_extradata_bsf.c
> +++ b/libavcodec/extract_extradata_bsf.c
> @@ -103,7 +103,6 @@ static int extract_extradata_av1(AVBSFContext *ctx, 
> AVPacket *pkt,
>  av_buffer_unref(&filtered_buf);
>  return AVERROR(ENOMEM);
>  }
> -memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  
>  *data = extradata;
>  *size = extradata_size;
> @@ -198,7 +197,6 @@ static int extract_extradata_h2645(AVBSFContext *ctx, 
> AVPacket *pkt,
>  av_buffer_unref(&filtered_buf);
>  return AVERROR(ENOMEM);
>  }
> -memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  
>  *data = extradata;
>  *size = extradata_size;
> @@ -254,7 +252,6 @@ static int extract_extradata_vc1(AVBSFContext *ctx, 
> AVPacket *pkt,
>  return AVERROR(ENOMEM);
>  
>  memcpy(*data, pkt->data, extradata_size);
> -memset(*data + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  *size = extradata_size;
>  
>  if (s->remove) {
> @@ -285,7 +282,6 @@ static int extract_extradata_mpeg12(AVBSFContext *ctx, 
> AVPacket *pkt,
>  return AVERROR(ENOMEM);
>  
>  memcpy(*data, pkt->data, *size);
> -memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  
>  if (s->remove) {
>  pkt->data += *size;
> @@ -315,7 +311,6 @@ static int extract_extradata_mpeg4(AVBSFContext *ctx, 
> AVPacket *pkt,
>  return AVERROR(ENOMEM);
>  
>  memcpy(*data, pkt->data, *size);
> -memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  
>  if (s->remove) {
>  pkt->data += *size;
> @@ -377,6 +372,7 @@ static int extract_extradata_filter(AVBSFContext *ctx, 
> AVPacket *pkt)
>  goto fail;
>  
>  if (extradata) {
> +memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  ret = av_packet_add_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
>extradata, extradata_size);
>  if (ret < 0) {

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

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

Re: [FFmpeg-devel] [PATCH 15/25] avfilter/af_headphone: Avoid intermediate buffers II

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:46PM +0200, Andreas Rheinhardt wrote:
> When the headphone filter is configured to perform its processing in the
> frequency domain, it allocates (among other things) two pairs of
> buffers, all of the same size. One pair is used to store data in it
> during the initialization of the filter; the other pair is only
> allocated lateron. It is zero-initialized and yet its data is
> immediately overwritten by the content of the other pair of buffers
> mentioned above; the latter pair is then freed.
> 
> This commit eliminates the pair of intermediate buffers.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 33 +++--
>  1 file changed, 7 insertions(+), 26 deletions(-)
> 

should be fine if does not break usage.
___
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 14/25] avfilter/af_headphone: Avoid intermediate buffers I

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:45PM +0200, Andreas Rheinhardt wrote:
> The headphone filter has two modes; in one of them (say A), it needs
> certain buffers to store data. But it allocated them in both modes.
> Furthermore when in mode A it also allocated intermediate buffers of the
> same size, initialized them, copied their contents into the permanent
> buffers and freed them.
> 
> This commit changes this: The permanent buffer is only allocated when
> needed; the temporary buffer has been completely avoided.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 38 +++---
>  1 file changed, 15 insertions(+), 23 deletions(-)
> 

should be fine if does not break usage.
___
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 12/25] avfilter/af_headphone: Remove unused arrays

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:43PM +0200, Andreas Rheinhardt wrote:
> The delay arrays were never properly initialized, only zero-initialized;
> furthermore these arrays duplicate fields in the headphone_inputs
> struct. So remove them.
> (Btw: The allocations for them have not been checked.)
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 11 ++-
>  1 file changed, 2 insertions(+), 9 deletions(-)
> 

probably fine
___
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 13/25] avfilter/af_headphone: Remove delay fields

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:44PM +0200, Andreas Rheinhardt wrote:
> They seem to exist for an option that was never implemented.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 12 
>  1 file changed, 4 insertions(+), 8 deletions(-)

I would prefer if this is kept.

> 
> diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
> index f9799d8548..f862181cbb 100644
> --- a/libavfilter/af_headphone.c
> +++ b/libavfilter/af_headphone.c
> @@ -79,8 +79,6 @@ typedef struct HeadphoneContext {
>  struct headphone_inputs {
>  AVFrame *frame;
>  int  ir_len;
> -int  delay_l;
> -int  delay_r;
>  int  eof;
>  } *in;
>  uint64_t mapping[64];
> @@ -457,8 +455,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
> AVFilterLink *inlink)
>  
>  for (i = 0; i < s->nb_inputs - 1; i++) {
>  int len = s->in[i + 1].ir_len;
> -int delay_l = s->in[i + 1].delay_l;
> -int delay_r = s->in[i + 1].delay_r;
>  float *ptr;
>  
>  ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, 
> &s->in[i + 1].frame);
> @@ -490,8 +486,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
> AVFilterLink *inlink)
>  
>  offset = idx * n_fft;
>  for (j = 0; j < len; j++) {
> -fft_in_l[delay_l + j].re = ptr[j * 2] * gain_lin;
> -fft_in_r[delay_r + j].re = ptr[j * 2 + 1] * gain_lin;
> +fft_in_l[j].re = ptr[j * 2] * gain_lin;
> +fft_in_r[j].re = ptr[j * 2 + 1] * gain_lin;
>  }
>  
>  av_fft_permute(s->fft[0], fft_in_l);
> @@ -529,8 +525,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
> AVFilterLink *inlink)
>  
>  offset = idx * n_fft;
>  for (j = 0; j < len; j++) {
> -fft_in_l[delay_l + j].re = ptr[j * N + I] * 
> gain_lin;
> -fft_in_r[delay_r + j].re = ptr[j * N + I + 1] * 
> gain_lin;
> +fft_in_l[j].re = ptr[j * N + I] * gain_lin;
> +fft_in_r[j].re = ptr[j * N + I + 1] * gain_lin;
>  }
>  
>  av_fft_permute(s->fft[0], fft_in_l);
> -- 
> 2.20.1
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel 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 11/25] avfilter/af_headphone: Avoid duplicating string needlessly

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:42PM +0200, Andreas Rheinhardt wrote:
> The string given by an AVOption that contains the channel assignment
> is used only once; ergo it doesn't matter that parsing the string via
> av_strtok() is destructive. There is no need to make a copy.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 9 ++---
>  1 file changed, 2 insertions(+), 7 deletions(-)

Copy is needed to keep options state always known and reusable.

> 
> diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
> index 32939af854..967f8ed5a6 100644
> --- a/libavfilter/af_headphone.c
> +++ b/libavfilter/af_headphone.c
> @@ -100,16 +100,13 @@ static int parse_channel_name(const char *arg, uint64_t 
> *rchannel)
>  static void parse_map(AVFilterContext *ctx)
>  {
>  HeadphoneContext *s = ctx->priv;
> -char *arg, *tokenizer, *p, *args = av_strdup(s->map);
> +char *arg, *tokenizer, *p;
>  uint64_t used_channels = 0;
>  
> -if (!args)
> -return;
> -p = args;
> -
>  s->lfe_channel = -1;
>  s->nb_inputs = 1;
>  
> +p = s->map;
>  while ((arg = av_strtok(p, "|", &tokenizer))) {
>  uint64_t out_channel;
>  
> @@ -133,8 +130,6 @@ static void parse_map(AVFilterContext *ctx)
>  s->nb_inputs = 2;
>  else
>  s->nb_inputs = s->nb_irs + 1;
> -
> -av_free(args);
>  }
>  
>  typedef struct ThreadData {
> -- 
> 2.20.1
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel 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 10/25] avfilter/af_headphone: Simplify parsing channel mapping string

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:41PM +0200, Andreas Rheinhardt wrote:
> When parsing the channel mapping string (a string containing '|'
> delimited tokens each of which is supposed to contain a channel name
> like "FR"), the old code would at each step read up to seven uppercase
> characters from the input string and give this to
> av_get_channel_layout() to parse. The returned layout is then checked
> for being a layout with a single channel set by computing its logarithm.
> 
> Besides being overtly complicated this also has the drawback of relying
> on the assumption that every channel name consists of at most seven
> uppercase letters only; but said assumption is wrong: The abbreviation
> of the second low frequency channel is LFE2. Furthermore it treats
> garbage like "FRfoo" as valid channel.
> 
> This commit changes this by using av_get_channel_layout() directly;
> furthermore, av_get_channel_layout_nb_channels() (which uses popcount)
> is used to find out the number of channels instead of the custom code
> to calculate the logarithm.
> 
> (As a consequence, certain other formats to specify the channel layouts
> are now accepted (like the hex versions of av_get_channel_layout()); but
> this is actually not bad at all.)
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 31 +--
>  1 file changed, 9 insertions(+), 22 deletions(-)
> 
> diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
> index 8db712e9a0..32939af854 100644
> --- a/libavfilter/af_headphone.c
> +++ b/libavfilter/af_headphone.c
> @@ -87,26 +87,14 @@ typedef struct HeadphoneContext {
>  uint64_t mapping[64];
>  } HeadphoneContext;
>  

probably ok
___
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 09/25] avfilter/af_headphone: Use uint64_t for channel mapping

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:40PM +0200, Andreas Rheinhardt wrote:
> The headphone filter has an option for the user to specify an assignment
> of inputs to channels (or from pairs of channels of the second input to
> channels). Up until now, these channels were stored in an int containing
> the logarithm of the channel layout. Yet it is not the logarithm that is
> used lateron and so a retransformation was necessary. Therefore this
> commit simply stores the uint64_t as is, avoiding the retransformation.
> 
> This also has the advantage that unset channels (whose corresponding
> entry is zero) can't be mistaken for valid channels any more; the old
> code had to initialize the channels to -1 to solve this problem and had
> to check for whether a channel is set before the retransformation
> (because 1 << -1 is UB).
> 
> The only downside of this approach is that the size of the context
> increases (by 256 bytes); but this is not exceedingly much.
> 
> Finally, the array has been moved to the end of the context; it is only
> used a few times during the initialization process and moving it
> decreased the offsets of lots of other entries, reducing codesize.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 40 +-
>  1 file changed, 13 insertions(+), 27 deletions(-)
> 

ok, if does not break usage.
___
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 01/25] avfilter/af_headphone: Don't use uninitialized buffer in log message

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:32PM +0200, Andreas Rheinhardt wrote:
> This buffer was supposed to be initialized by sscanf(input, "%7[A-Z]%n",
> buf, &len), yet if the first input character is not in the A-Z range,
> buf is not touched (in particular it needn't be zero-terminated if the
> failure happened when parsing the first channel and it still contains
> the last channel name if the failure happened when one channel name
> could be successfully parsed). This is treated as error in which case
> buf is used directly in the log message. This commit fixes this by
> actually using the string that could not be matched in the log message
> instead.
> 

ok
___
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 21/25] avfilter/af_headphone: Avoid allocating array

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:52PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 7 +--
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 

ok
___
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 25/25] avfilter/af_headphone: Don't check for clipping in separate loop

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:56PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
> More patches will be coming later.
> 
>  libavfilter/af_headphone.c | 10 ++
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
> index 03ef88c4a4..edf8e773d7 100644
> --- a/libavfilter/af_headphone.c
> +++ b/libavfilter/af_headphone.c
> @@ -281,6 +281,8 @@ static int headphone_fast_convolute(AVFilterContext *ctx, 
> void *arg, int jobnr,
>  
>  for (j = 0; j < in->nb_samples; j++) {
>  dst[2 * j] += fft_acc[j].re * fft_scale;
> +if (fabsf(dst[2 * j]) > 1)
> +n_clippings[0]++;
>  }
>  
>  for (j = 0; j < ir_len - 1; j++) {
> @@ -289,14 +291,6 @@ static int headphone_fast_convolute(AVFilterContext 
> *ctx, void *arg, int jobnr,
>  *(ringbuffer + write_pos) += fft_acc[in->nb_samples + j].re * 
> fft_scale;
>  }
>  
> -for (i = 0; i < out->nb_samples; i++) {
> -if (fabsf(dst[0]) > 1) {
> -n_clippings[0]++;
> -}
> -
> -dst += 2;
> -}
> -
>  *write = wr;

This patch is wrong and uneeded.
See, this filter use slice threading, and thus if multiple threads are used in 
multichannel audio
it will report incorrect results.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 2/3] avcodec/fastaudio: Remove redundant % 32

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:29:20PM +0200, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/fastaudio.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

ok
___
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/fastaudio: Check channels

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:29:19PM +0200, Michael Niedermayer wrote:
> Fixes: division by 0
> Fixes: 
> 25419/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-5632544761184256
> Fixes: 
> 25433/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-6215671900536832
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/fastaudio.c | 3 +++
>  1 file changed, 3 insertions(+)
> 

This should be in generic path somehow. There are decoders that does not need 
this check
as they store number of channels in bitstream, but there are others that do 
not, and thus adding
this check for each and every one of them is not nice.
___
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 06/25] avfilter/af_headphone: Fix stack buffer overflow

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:37PM +0200, Andreas Rheinhardt wrote:
> The number of channels can be up to 64, not only 16.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

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

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

Re: [FFmpeg-devel] [PATCH 05/25] avfilter/af_headphone: Don't overrun array

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:36PM +0200, Andreas Rheinhardt wrote:
> The headphone filter stores the channel position of the ith HRIR stream
> in the ith element of an array of 64 elements; but because there is no
> check for duplicate channels, it is easy to write beyond the end of the
> array by simply repeating channels.
> 
> This commit adds a check for duplicate channels to rule this out.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 14 ++
>  1 file changed, 10 insertions(+), 4 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".

Re: [FFmpeg-devel] [PATCH 04/25] avfilter/af_headphone: Fix segfault when using very short streams

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 11:18:35PM +0200, Andreas Rheinhardt wrote:
> When the headphone filter does its processing in the time domain,
> the lengths of the buffers involved are determined by three parameters,
> only two of which are relevant here: ir_len and air_len. The former is
> the length (in samples) of the longest HRIR input stream and the latter
> is the smallest power-of-two bigger than ir_len.
> 
> Using optimized functions to calculate the convolution places
> restrictions on the alignment of the length of the vectors whose scalar
> product is calculated. Therefore said length, namely ir_len, is aligned
> on 32; but the number of elements of the buffers used is given by air_len
> and for ir_len < 16 a buffer overflow happens.
> 
> This commit fixes this by ensuring that air_len is always >= 32 if
> processing happens in the time domain.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_headphone.c | 3 +++
>  1 file changed, 3 insertions(+)
> 

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 v2 2/4] avformat/argo_asf: split functionality into a header

2020-09-08 Thread Zane van Iperen
For future use by the argo_brp demuxer.

Adds:
  - void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t 
*buf);
  - int  ff_argo_asf_validate_file_header(AVFormatContext *s, const 
ArgoASFFileHeader *hdr);
  - void ff_argo_asf_parse_chunk_header(ArgoASFChunkHeader *hdr, const uint8_t 
*buf);
  - int  ff_argo_asf_fill_stream(AVStream *st, const ArgoASFChunkHeader *ckhdr);
Signed-off-by: Zane van Iperen 
---
 libavformat/argo_asf.c | 204 +++--
 libavformat/argo_asf.h |  67 ++
 2 files changed, 159 insertions(+), 112 deletions(-)
 create mode 100644 libavformat/argo_asf.h

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index 208280b4d9..ee8c85f735 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -24,39 +24,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avassert.h"
 #include "libavutil/opt.h"
-
-#define ASF_TAG MKTAG('A', 'S', 'F', '\0')
-#define ASF_FILE_HEADER_SIZE24
-#define ASF_CHUNK_HEADER_SIZE   20
-#define ASF_SAMPLE_COUNT32
-
-typedef struct ArgoASFFileHeader {
-uint32_tmagic;  /*< Magic Number, {'A', 'S', 'F', '\0'} */
-uint16_tversion_major;  /*< File Major Version. */
-uint16_tversion_minor;  /*< File Minor Version. */
-uint32_tnum_chunks; /*< No. chunks in the file. */
-uint32_tchunk_offset;   /*< Offset to the first chunk from the start 
of the file. */
-int8_t  name[8];/*< Name. */
-} ArgoASFFileHeader;
-
-typedef struct ArgoASFChunkHeader {
-uint32_tnum_blocks; /*< No. blocks in the chunk. */
-uint32_tnum_samples;/*< No. samples per channel in a block. Always 
32. */
-uint32_tunk1;   /*< Unknown */
-uint16_tsample_rate;/*< Sample rate. */
-uint16_tunk2;   /*< Unknown. */
-uint32_tflags;  /*< Stream flags. */
-} ArgoASFChunkHeader;
-
-enum {
-ASF_CF_BITS_PER_SAMPLE  = (1 << 0), /*< 16-bit if set, 8 otherwise.  */
-ASF_CF_STEREO   = (1 << 1), /*< Stereo if set, mono otherwise.   */
-ASF_CF_ALWAYS1_1= (1 << 2), /*< Unknown, always seems to be set. */
-ASF_CF_ALWAYS1_2= (1 << 3), /*< Unknown, always seems to be set. */
-
-ASF_CF_ALWAYS1  = ASF_CF_ALWAYS1_1 | ASF_CF_ALWAYS1_2,
-ASF_CF_ALWAYS0  = ~(ASF_CF_BITS_PER_SAMPLE | ASF_CF_STEREO | 
ASF_CF_ALWAYS1)
-};
+#include "argo_asf.h"
 
 typedef struct ArgoASFDemuxContext {
 ArgoASFFileHeader   fhdr;
@@ -71,8 +39,7 @@ typedef struct ArgoASFMuxContext {
 const char*name;
 } ArgoASFMuxContext;
 
-#if CONFIG_ARGO_ASF_DEMUXER
-static void argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t 
*buf)
+void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t *buf)
 {
 hdr->magic  = AV_RL32(buf + 0);
 hdr->version_major  = AV_RL16(buf + 4);
@@ -83,7 +50,23 @@ static void argo_asf_parse_file_header(ArgoASFFileHeader 
*hdr, const uint8_t *bu
 hdr->name[i]= AV_RL8(buf + 16 + i);
 }
 
-static void argo_asf_parse_chunk_header(ArgoASFChunkHeader *hdr, const uint8_t 
*buf)
+int ff_argo_asf_validate_file_header(AVFormatContext *s, const 
ArgoASFFileHeader *hdr)
+{
+if (hdr->magic != ASF_TAG || hdr->num_chunks == 0)
+return AVERROR_INVALIDDATA;
+
+if (hdr->num_chunks > 1) {
+avpriv_request_sample(s, ">1 chunk");
+return AVERROR_PATCHWELCOME;
+}
+
+if (hdr->chunk_offset < ASF_FILE_HEADER_SIZE)
+return AVERROR_INVALIDDATA;
+
+return 0;
+}
+
+void ff_argo_asf_parse_chunk_header(ArgoASFChunkHeader *hdr, const uint8_t 
*buf)
 {
 hdr->num_blocks = AV_RL32(buf + 0);
 hdr->num_samples= AV_RL32(buf + 4);
@@ -93,6 +76,73 @@ static void argo_asf_parse_chunk_header(ArgoASFChunkHeader 
*hdr, const uint8_t *
 hdr->flags  = AV_RL32(buf + 16);
 }
 
+int ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr,
+const ArgoASFChunkHeader *ckhdr)
+{
+if (ckhdr->num_samples != ASF_SAMPLE_COUNT) {
+av_log(st, AV_LOG_ERROR, "Invalid sample count. Got %u, expected %d\n",
+   ckhdr->num_samples, ASF_SAMPLE_COUNT);
+return AVERROR_INVALIDDATA;
+}
+
+if ((ckhdr->flags & ASF_CF_ALWAYS1) != ASF_CF_ALWAYS1 || (ckhdr->flags & 
ASF_CF_ALWAYS0) != 0) {
+avpriv_request_sample(st, "Nonstandard flags (0x%08X)", ckhdr->flags);
+return AVERROR_PATCHWELCOME;
+}
+
+st->codecpar->codec_type= AVMEDIA_TYPE_AUDIO;
+st->codecpar->codec_id  = AV_CODEC_ID_ADPCM_ARGO;
+st->codecpar->format= AV_SAMPLE_FMT_S16P;
+
+if (ckhdr->flags & ASF_CF_STEREO) {
+st->codecpar->channel_layout= AV_CH_LAYOUT_STEREO;
+st->codecpar->channels  = 2;
+} else {
+st->codecpar->channel_layout= AV_CH_LAYOUT_MONO;
+   

[FFmpeg-devel] [PATCH v2 4/4] avformat: add Argonaut Games BRP demuxer

2020-09-08 Thread Zane van Iperen
Used in FMVs for FX Fighter and Croc. Supports BVID and BASF streams,
requests samples for anything else.

Due to the way BASF streams are contained in the file, only one is
supported. I have yet to see a BRP file with multiple.

Signed-off-by: Zane van Iperen 
---
 Changelog|   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/argo_brp.c   | 449 +++
 libavformat/version.h|   2 +-
 5 files changed, 453 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/argo_brp.c

diff --git a/Changelog b/Changelog
index ff9ff2fcb8..2ccecfbcc9 100644
--- a/Changelog
+++ b/Changelog
@@ -21,6 +21,7 @@ version :
 - MOFLEX demuxer
 - MODS demuxer
 - PhotoCD decoder
+- Argonaut Games BRP demuxer
 
 
 version 4.3:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2368bc15ac..062f3bd9c2 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -104,6 +104,7 @@ OBJS-$(CONFIG_APTX_HD_MUXER) += rawenc.o
 OBJS-$(CONFIG_AQTITLE_DEMUXER)   += aqtitledec.o subtitles.o
 OBJS-$(CONFIG_ARGO_ASF_DEMUXER)  += argo_asf.o
 OBJS-$(CONFIG_ARGO_ASF_MUXER)+= argo_asf.o
+OBJS-$(CONFIG_ARGO_BRP_DEMUXER)  += argo_brp.o argo_asf.o
 OBJS-$(CONFIG_ASF_DEMUXER)   += asfdec_f.o asf.o asfcrypt.o \
 avlanguage.o
 OBJS-$(CONFIG_ASF_O_DEMUXER) += asfdec_o.o asf.o asfcrypt.o \
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 3438a14141..8e7556e529 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -65,6 +65,7 @@ extern AVOutputFormat ff_aptx_hd_muxer;
 extern AVInputFormat  ff_aqtitle_demuxer;
 extern AVInputFormat  ff_argo_asf_demuxer;
 extern AVOutputFormat ff_argo_asf_muxer;
+extern AVInputFormat  ff_argo_brp_demuxer;
 extern AVInputFormat  ff_asf_demuxer;
 extern AVOutputFormat ff_asf_muxer;
 extern AVInputFormat  ff_asf_o_demuxer;
diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
new file mode 100644
index 00..122f616ecc
--- /dev/null
+++ b/libavformat/argo_brp.c
@@ -0,0 +1,449 @@
+/*
+ * Argonaut Games BRP Demuxer
+ *
+ * Copyright (C) 2020 Zane van Iperen (z...@zanevaniperen.com)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avassert.h"
+#include "libavutil/internal.h"
+#include "argo_asf.h"
+
+#define BRP_TAG MKTAG('B', 'R', 'P', 'P')
+#define BRP_FILE_HEADER_SIZE12
+#define BRP_BLOCK_HEADER_SIZE   12
+#define BRP_STREAM_HEADER_SIZE  20
+#define BRP_MAX_STREAMS 32 /* Soft cap, but even this is overkill. */
+#define BVID_HEADER_SIZE16
+#define BRP_MIN_BUFFER_SIZE FFMAX(FFMAX3(BRP_FILE_HEADER_SIZE,\
+ BRP_BLOCK_HEADER_SIZE,   \
+ BRP_STREAM_HEADER_SIZE), \
+  BVID_HEADER_SIZE)
+
+#define BRP_CODEC_ID_BVID   MKTAG('B', 'V', 'I', 'D')
+#define BRP_CODEC_ID_BASF   MKTAG('B', 'A', 'S', 'F')
+
+typedef struct ArgoBRPFileHeader {
+uint32_t magic;
+uint32_t num_streams;
+uint32_t byte_rate;
+} ArgoBRPFileHeader;
+
+typedef struct ArgoBRPBlockHeader {
+int32_t  stream_id;
+uint32_t start_ms;
+uint32_t size;
+} ArgoBRPBlockHeader;
+
+typedef struct ArgoBVIDHeader {
+uint32_t num_frames;
+uint32_t width;
+uint32_t height;
+uint32_t depth;
+} ArgoBVIDHeader;
+
+typedef struct ArgoBRPStreamHeader {
+uint32_t codec_id;
+uint32_t id;
+uint32_t duration_ms;
+uint32_t byte_rate;
+uint32_t extradata_size;
+union
+{
+/* If codec_id == BRP_CODEC_ID_BVID */
+ArgoBVIDHeaderbvid;
+/* If codec_id == BRP_CODEC_ID_BASF */
+ArgoASFFileHeader basf;
+} extradata;
+} ArgoBRPStreamHeader;
+
+typedef struct ArgoBRPDemuxContext {
+ArgoBRPFileHeader   fhdr;
+ArgoBRPStreamHeader *streams;
+/* To know how much of a BASF to give. */
+int64_t lastpts;
+int hit_eof;
+
+/* BASF-specific fields. */
+struct {
+int index;

[FFmpeg-devel] [PATCH v2 3/4] avformat/argo_asf: add ASF_MIN_BUFFER_SIZE #define

2020-09-08 Thread Zane van Iperen
For future use by the argo_brp demuxer

Signed-off-by: Zane van Iperen 
---
 libavformat/argo_asf.c | 2 +-
 libavformat/argo_asf.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index ee8c85f735..c131207aa1 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -182,7 +182,7 @@ static int argo_asf_read_header(AVFormatContext *s)
 AVIOContext *pb = s->pb;
 AVStream *st;
 ArgoASFDemuxContext *asf = s->priv_data;
-uint8_t buf[FFMAX(ASF_FILE_HEADER_SIZE, ASF_CHUNK_HEADER_SIZE)];
+uint8_t buf[ASF_MIN_BUFFER_SIZE];
 
 if (!(st = avformat_new_stream(s, NULL)))
 return AVERROR(ENOMEM);
diff --git a/libavformat/argo_asf.h b/libavformat/argo_asf.h
index 905769dafe..8b1c6d5e2f 100644
--- a/libavformat/argo_asf.h
+++ b/libavformat/argo_asf.h
@@ -24,11 +24,13 @@
 #define AVFORMAT_ARGO_ASF_H
 
 #include 
+#include "libavutil/common.h"
 
 #define ASF_TAG MKTAG('A', 'S', 'F', '\0')
 #define ASF_FILE_HEADER_SIZE24
 #define ASF_CHUNK_HEADER_SIZE   20
 #define ASF_SAMPLE_COUNT32
+#define ASF_MIN_BUFFER_SIZE FFMAX(ASF_FILE_HEADER_SIZE, 
ASF_CHUNK_HEADER_SIZE)
 
 typedef struct ArgoASFFileHeader {
 uint32_tmagic;  /*< Magic Number, {'A', 'S', 'F', '\0'} */
-- 
2.25.4


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

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

[FFmpeg-devel] [PATCH v2 1/4] avformat/argo_asf: bail if invalid tag

2020-09-08 Thread Zane van Iperen
Signed-off-by: Zane van Iperen 
---
 libavformat/argo_asf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index bf9b5d0c0a..208280b4d9 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -144,6 +144,9 @@ static int argo_asf_read_header(AVFormatContext *s)
 
 argo_asf_parse_file_header(&asf->fhdr, buf);
 
+if (asf->fhdr.magic != ASF_TAG)
+return AVERROR_INVALIDDATA;
+
 if (asf->fhdr.num_chunks == 0) {
 return AVERROR_INVALIDDATA;
 } else if (asf->fhdr.num_chunks > 1) {
-- 
2.25.4


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

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

[FFmpeg-devel] [PATCH v2 0/4] Add demuxer for Argonaut Games BRP files

2020-09-08 Thread Zane van Iperen
Adds support for demuxing BRP files from Argonaut Games' games.
Used to store the FMVs.

v2: [1]
- Don't add AV_CODEC_ID_ARGO descriptor, use AV_CODEC_ID_NONE instead.

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-September/269332.html

Zane van Iperen (4):
  avformat/argo_asf: bail if invalid tag
  avformat/argo_asf: split functionality into a header
  avformat/argo_asf: add ASF_MIN_BUFFER_SIZE #define
  avformat: add Argonaut Games BRP demuxer

 Changelog|   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/argo_asf.c   | 203 --
 libavformat/argo_asf.h   |  69 ++
 libavformat/argo_brp.c   | 449 +++
 libavformat/version.h|   2 +-
 7 files changed, 615 insertions(+), 111 deletions(-)
 create mode 100644 libavformat/argo_asf.h
 create mode 100644 libavformat/argo_brp.c

-- 
2.25.4


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

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

Re: [FFmpeg-devel] [PATCH] avcodec/avpacket: add av_packet_remove_side_data()

2020-09-08 Thread James Almer
On 9/8/2020 7:42 PM, Andreas Rheinhardt wrote:
> James Almer:
>> This helper removes a side data entry from the packet, maintaining the
>> integrity and order of the remaining entries, if any.
>>
>> Signed-off-by: James Almer 
>> ---
>> Missing APIChanges entry and version bump.
>>
>> Couldn't find a place in the tree where it could be used right now, but
>> it makes the API be more in line with the AVFrame one, so i decided to
>> write it.
>>
>>  libavcodec/avpacket.c | 24 
>>  libavcodec/packet.h   |  8 
>>  2 files changed, 32 insertions(+)
>>
>> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
>> index 4801163227..61ea81698c 100644
>> --- a/libavcodec/avpacket.c
>> +++ b/libavcodec/avpacket.c
>> @@ -367,6 +367,30 @@ uint8_t *av_packet_get_side_data(const AVPacket *pkt, 
>> enum AVPacketSideDataType
>>  return NULL;
>>  }
>>  
>> +void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType 
>> type)
>> +{
>> +int i, elems;
>> +
>> +for (i = 0; i < pkt->side_data_elems; i++) {
>> +if (pkt->side_data[i].type != type)
>> +continue;
>> +
>> +elems = pkt->side_data_elems - 1;
>> +av_freep(&pkt->side_data[i].data);
>> +pkt->side_data[i].size = 0;
>> +
>> +if (i < elems) {
>> +memmove(&pkt->side_data[i], &pkt->side_data[i + 1],
>> +(elems - i) * sizeof(*pkt->side_data));
>> +}
>> +if (!elems)
>> +av_freep(&pkt->side_data);
>> +pkt->side_data_elems = elems;
>> +
>> +break;
>> +}
>> +}
>> +
>>  const char *av_packet_side_data_name(enum AVPacketSideDataType type)
>>  {
>>  switch(type) {
>> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
>> index 0a19a0eff3..6ce3c91c07 100644
>> --- a/libavcodec/packet.h
>> +++ b/libavcodec/packet.h
>> @@ -595,6 +595,14 @@ int av_packet_shrink_side_data(AVPacket *pkt, enum 
>> AVPacketSideDataType type,
>>  uint8_t* av_packet_get_side_data(const AVPacket *pkt, enum 
>> AVPacketSideDataType type,
>>   int *size);
>>  
>> +/**
>> + * Remove and free a side data entry of the given type.
>> + *
>> + * @param pkt packet
>> + * @param type side data type to be removed
>> + */
>> +void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType 
>> type);
> 
> How about extending the functionality to optionally pass the side data
> to the caller instead of freeing it? All it needs are two pointer
> parameters for data and size. Then this function could be used to
> simplify
> https://ffmpeg.org/pipermail/ffmpeg-devel/2020-September/269319.html

I thought about it, but doing so would be tailoring the function for
this specific scenario, turning it into a combination of get and remove
rather than a simple and API consistent (with AVFrame) fire-and-forget
call to remove a side data type if present in the packet.

That one case above is also discarding the packet altogether immediately
after stealing its side data, so it will not even gain anything from the
extra measures to rearrange the resulting array post removal.

> 
> - 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] avcodec/avpacket: add av_packet_remove_side_data()

2020-09-08 Thread Andreas Rheinhardt
James Almer:
> This helper removes a side data entry from the packet, maintaining the
> integrity and order of the remaining entries, if any.
> 
> Signed-off-by: James Almer 
> ---
> Missing APIChanges entry and version bump.
> 
> Couldn't find a place in the tree where it could be used right now, but
> it makes the API be more in line with the AVFrame one, so i decided to
> write it.
> 
>  libavcodec/avpacket.c | 24 
>  libavcodec/packet.h   |  8 
>  2 files changed, 32 insertions(+)
> 
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 4801163227..61ea81698c 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -367,6 +367,30 @@ uint8_t *av_packet_get_side_data(const AVPacket *pkt, 
> enum AVPacketSideDataType
>  return NULL;
>  }
>  
> +void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType 
> type)
> +{
> +int i, elems;
> +
> +for (i = 0; i < pkt->side_data_elems; i++) {
> +if (pkt->side_data[i].type != type)
> +continue;
> +
> +elems = pkt->side_data_elems - 1;
> +av_freep(&pkt->side_data[i].data);
> +pkt->side_data[i].size = 0;
> +
> +if (i < elems) {
> +memmove(&pkt->side_data[i], &pkt->side_data[i + 1],
> +(elems - i) * sizeof(*pkt->side_data));
> +}
> +if (!elems)
> +av_freep(&pkt->side_data);
> +pkt->side_data_elems = elems;
> +
> +break;
> +}
> +}
> +
>  const char *av_packet_side_data_name(enum AVPacketSideDataType type)
>  {
>  switch(type) {
> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> index 0a19a0eff3..6ce3c91c07 100644
> --- a/libavcodec/packet.h
> +++ b/libavcodec/packet.h
> @@ -595,6 +595,14 @@ int av_packet_shrink_side_data(AVPacket *pkt, enum 
> AVPacketSideDataType type,
>  uint8_t* av_packet_get_side_data(const AVPacket *pkt, enum 
> AVPacketSideDataType type,
>   int *size);
>  
> +/**
> + * Remove and free a side data entry of the given type.
> + *
> + * @param pkt packet
> + * @param type side data type to be removed
> + */
> +void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType 
> type);

How about extending the functionality to optionally pass the side data
to the caller instead of freeing it? All it needs are two pointer
parameters for data and size. Then this function could be used to
simplify
https://ffmpeg.org/pipermail/ffmpeg-devel/2020-September/269319.html

- 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] avcodec/avpacket: add av_packet_remove_side_data()

2020-09-08 Thread James Almer
This helper removes a side data entry from the packet, maintaining the
integrity and order of the remaining entries, if any.

Signed-off-by: James Almer 
---
Missing APIChanges entry and version bump.

Couldn't find a place in the tree where it could be used right now, but
it makes the API be more in line with the AVFrame one, so i decided to
write it.

 libavcodec/avpacket.c | 24 
 libavcodec/packet.h   |  8 
 2 files changed, 32 insertions(+)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 4801163227..61ea81698c 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -367,6 +367,30 @@ uint8_t *av_packet_get_side_data(const AVPacket *pkt, enum 
AVPacketSideDataType
 return NULL;
 }
 
+void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType type)
+{
+int i, elems;
+
+for (i = 0; i < pkt->side_data_elems; i++) {
+if (pkt->side_data[i].type != type)
+continue;
+
+elems = pkt->side_data_elems - 1;
+av_freep(&pkt->side_data[i].data);
+pkt->side_data[i].size = 0;
+
+if (i < elems) {
+memmove(&pkt->side_data[i], &pkt->side_data[i + 1],
+(elems - i) * sizeof(*pkt->side_data));
+}
+if (!elems)
+av_freep(&pkt->side_data);
+pkt->side_data_elems = elems;
+
+break;
+}
+}
+
 const char *av_packet_side_data_name(enum AVPacketSideDataType type)
 {
 switch(type) {
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 0a19a0eff3..6ce3c91c07 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -595,6 +595,14 @@ int av_packet_shrink_side_data(AVPacket *pkt, enum 
AVPacketSideDataType type,
 uint8_t* av_packet_get_side_data(const AVPacket *pkt, enum 
AVPacketSideDataType type,
  int *size);
 
+/**
+ * Remove and free a side data entry of the given type.
+ *
+ * @param pkt packet
+ * @param type side data type to be removed
+ */
+void av_packet_remove_side_data(AVPacket *pkt, enum AVPacketSideDataType type);
+
 #if FF_API_MERGE_SD_API
 attribute_deprecated
 int av_packet_merge_side_data(AVPacket *pkt);
-- 
2.27.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 0/3] avcodec/fastaudio: Bugfixes

2020-09-08 Thread Amon Gibson Albuquerque Nunes
here are some mobiclib files for you to shake a stick at.
mobiclip_files
___
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/3] avcodec/fastaudio: Bugfixes

2020-09-08 Thread Michael Niedermayer
These patches fix a few bugs found by the fuzzer or while fixing
such bugs.
The changes are not tested against any fastaudio data as i failed to
find any looking at the fate samples, sample archive and patches
adding fastaudi support 

If you have samples, please provide links so i can test this

thx


___
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] avcodec/fastaudio: Fix invalid shift exponent

2020-09-08 Thread Michael Niedermayer
Fixes: shift exponent 32 is too large for 32-bit type 'unsigned int'
Fixes: 
25434/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-6252363168612352

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

diff --git a/libavcodec/fastaudio.c b/libavcodec/fastaudio.c
index 16f44790f5..e37d4f8425 100644
--- a/libavcodec/fastaudio.c
+++ b/libavcodec/fastaudio.c
@@ -92,7 +92,7 @@ static int read_bits(int bits, int *ppos, unsigned *src)
 
 pos = *ppos;
 pos += bits;
-r = src[(pos - 1) / 32] >> (32 - pos % 32);
+r = src[(pos - 1) / 32] >> ((-pos) & 31);
 *ppos = pos;
 
 return r & ((1 << bits) - 1);
-- 
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] avcodec/fastaudio: Remove redundant % 32

2020-09-08 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/fastaudio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/fastaudio.c b/libavcodec/fastaudio.c
index 34857d1b88..16f44790f5 100644
--- a/libavcodec/fastaudio.c
+++ b/libavcodec/fastaudio.c
@@ -95,7 +95,7 @@ static int read_bits(int bits, int *ppos, unsigned *src)
 r = src[(pos - 1) / 32] >> (32 - pos % 32);
 *ppos = pos;
 
-return r & ((1 << (bits % 32)) - 1);
+return r & ((1 << bits) - 1);
 }
 
 static const uint8_t bits[8] = { 6, 6, 5, 5, 4, 0, 3, 3, };
-- 
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 1/3] avcodec/fastaudio: Check channels

2020-09-08 Thread Michael Niedermayer
Fixes: division by 0
Fixes: 
25419/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-5632544761184256
Fixes: 
25433/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-6215671900536832

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

diff --git a/libavcodec/fastaudio.c b/libavcodec/fastaudio.c
index de006acd9b..34857d1b88 100644
--- a/libavcodec/fastaudio.c
+++ b/libavcodec/fastaudio.c
@@ -41,6 +41,9 @@ static av_cold int fastaudio_init(AVCodecContext *avctx)
 {
 FastAudioContext *s = avctx->priv_data;
 
+if (avctx->channels <= 0)
+return AVERROR_INVALIDDATA;
+
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
 for (int i = 0; i < 8; i++)
-- 
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 23/25] avfilter/af_headphone: Use more appropriate variable name

2020-09-08 Thread Andreas Rheinhardt
Also unify incrementing the variable containing the pointer
to the currently used HRIR data.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 8b0a431c45..8db546adbf 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -163,19 +163,18 @@ static int headphone_convolute(AVFilterContext *ctx, void 
*arg, int jobnr, int n
 }
 
 for (i = 0; i < in->nb_samples; i++) {
-const float *temp_ir = ir;
+const float *cur_ir = ir;
 
 *dst = 0;
 for (l = 0; l < in_channels; l++) {
 *(buffer[l] + wr) = src[l];
 }
 
-for (l = 0; l < in_channels; l++) {
+for (l = 0; l < in_channels; cur_ir += air_len, l++) {
 const float *const bptr = buffer[l];
 
 if (l == s->lfe_channel) {
 *dst += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;
-temp_ir += air_len;
 continue;
 }
 
@@ -190,8 +189,7 @@ static int headphone_convolute(AVFilterContext *ctx, void 
*arg, int jobnr, int n
 memcpy(temp_src + len, bptr, (air_len - len) * 
sizeof(*temp_src));
 }
 
-dst[0] += s->scalarproduct_float(temp_ir, temp_src, 
FFALIGN(ir_len, 32));
-temp_ir += air_len;
+dst[0] += s->scalarproduct_float(cur_ir, temp_src, FFALIGN(ir_len, 
32));
 }
 
 if (fabsf(dst[0]) > 1)
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 24/25] avfilter/af_headphone: Remove pointless additions

2020-09-08 Thread Andreas Rheinhardt
buffer_length is a power-of-two and modulo is buffer_length - 1, so that
buffer_length & modulo is zero.

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

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 8db546adbf..03ef88c4a4 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -178,7 +178,7 @@ static int headphone_convolute(AVFilterContext *ctx, void 
*arg, int jobnr, int n
 continue;
 }
 
-read = (wr - (ir_len - 1) + buffer_length) & modulo;
+read = (wr - (ir_len - 1)) & modulo;
 
 if (read + ir_len < buffer_length) {
 memcpy(temp_src, bptr + read, ir_len * sizeof(*temp_src));
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 25/25] avfilter/af_headphone: Don't check for clipping in separate loop

2020-09-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
More patches will be coming later.

 libavfilter/af_headphone.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 03ef88c4a4..edf8e773d7 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -281,6 +281,8 @@ static int headphone_fast_convolute(AVFilterContext *ctx, 
void *arg, int jobnr,
 
 for (j = 0; j < in->nb_samples; j++) {
 dst[2 * j] += fft_acc[j].re * fft_scale;
+if (fabsf(dst[2 * j]) > 1)
+n_clippings[0]++;
 }
 
 for (j = 0; j < ir_len - 1; j++) {
@@ -289,14 +291,6 @@ static int headphone_fast_convolute(AVFilterContext *ctx, 
void *arg, int jobnr,
 *(ringbuffer + write_pos) += fft_acc[in->nb_samples + j].re * 
fft_scale;
 }
 
-for (i = 0; i < out->nb_samples; i++) {
-if (fabsf(dst[0]) > 1) {
-n_clippings[0]++;
-}
-
-dst += 2;
-}
-
 *write = wr;
 
 return 0;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 20/25] avfilter/af_headphone: Don't allocate unused element in array

2020-09-08 Thread Andreas Rheinhardt
The headphone filter uses an array with as many elements as the
filter has inputs to store some per-input information; yet actually it
only stores information for all inputs except the very first one (which
is special for this filter). Therefore this commit modifies the code to
remove this unused element.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 50 +++---
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index c84142e1ce..bbbe32a475 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -52,7 +52,7 @@ typedef struct HeadphoneContext {
 int ir_len;
 int air_len;
 
-int nb_inputs;
+int nb_hrir_inputs;
 
 int nb_irs;
 
@@ -76,10 +76,10 @@ typedef struct HeadphoneContext {
 FFTComplex *data_hrtf[2];
 
 AVFloatDSPContext *fdsp;
-struct headphone_inputs {
+struct hrir_inputs {
 int  ir_len;
 int  eof;
-} *in;
+} *hrir_in;
 uint64_t mapping[64];
 } HeadphoneContext;
 
@@ -99,8 +99,6 @@ static void parse_map(AVFilterContext *ctx)
 char *arg, *tokenizer, *p;
 uint64_t used_channels = 0;
 
-s->nb_inputs = 1;
-
 p = s->map;
 while ((arg = av_strtok(p, "|", &tokenizer))) {
 uint64_t out_channel;
@@ -120,9 +118,9 @@ static void parse_map(AVFilterContext *ctx)
 }
 
 if (s->hrir_fmt == HRIR_MULTI)
-s->nb_inputs = 2;
+s->nb_hrir_inputs = 1;
 else
-s->nb_inputs = s->nb_irs + 1;
+s->nb_hrir_inputs = s->nb_irs;
 }
 
 typedef struct ThreadData {
@@ -318,7 +316,7 @@ static int check_ir(AVFilterLink *inlink, int input_number)
 av_log(ctx, AV_LOG_ERROR, "Too big length of IRs: %d > %d.\n", ir_len, 
max_ir_len);
 return AVERROR(EINVAL);
 }
-s->in[input_number].ir_len = ir_len;
+s->hrir_in[input_number].ir_len = ir_len;
 s->ir_len = FFMAX(ir_len, s->ir_len);
 
 return 0;
@@ -432,8 +430,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 }
 }
 
-for (i = 0; i < s->nb_inputs - 1; av_frame_free(&frame), i++) {
-int len = s->in[i + 1].ir_len;
+for (i = 0; i < s->nb_hrir_inputs; av_frame_free(&frame), i++) {
+int len = s->hrir_in[i].ir_len;
 float *ptr;
 
 ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &frame);
@@ -521,23 +519,25 @@ static int activate(AVFilterContext *ctx)
 FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
 if (!s->eof_hrirs) {
 int eof = 1;
-for (i = 1; i < s->nb_inputs; i++) {
-if (s->in[i].eof)
+for (i = 0; i < s->nb_hrir_inputs; i++) {
+AVFilterLink *input = ctx->inputs[i + 1];
+
+if (s->hrir_in[i].eof)
 continue;
 
-if ((ret = check_ir(ctx->inputs[i], i)) < 0)
+if ((ret = check_ir(input, i)) < 0)
 return ret;
 
-if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF) {
-if (!ff_inlink_queued_samples(ctx->inputs[i])) {
+if (ff_outlink_get_status(input) == AVERROR_EOF) {
+if (!ff_inlink_queued_samples(input)) {
 av_log(ctx, AV_LOG_ERROR, "No samples provided for "
-   "HRIR stream %d.\n", i - 1);
+   "HRIR stream %d.\n", i);
 return AVERROR_INVALIDDATA;
 }
-s->in[i].eof = 1;
+s->hrir_in[i].eof = 1;
 } else {
 if (ff_outlink_frame_wanted(ctx->outputs[0]))
-ff_inlink_request_frame(ctx->inputs[i]);
+ff_inlink_request_frame(input);
 eof = 0;
 }
 }
@@ -606,7 +606,7 @@ static int query_formats(AVFilterContext *ctx)
 if (ret)
 return ret;
 } else {
-for (i = 1; i < s->nb_inputs; i++) {
+for (i = 1; i <= s->nb_hrir_inputs; i++) {
 ret = ff_channel_layouts_ref(stereo_layout, 
&ctx->inputs[i]->outcfg.channel_layouts);
 if (ret)
 return ret;
@@ -654,19 +654,19 @@ static av_cold int init(AVFilterContext *ctx)
 
 parse_map(ctx);
 
-s->in = av_calloc(s->nb_inputs, sizeof(*s->in));
-if (!s->in)
+s->hrir_in = av_calloc(s->nb_hrir_inputs, sizeof(*s->hrir_in));
+if (!s->hrir_in)
 return AVERROR(ENOMEM);
 
-for (i = 1; i < s->nb_inputs; i++) {
-char *name = av_asprintf("hrir%d", i - 1);
+for (i = 0; i < s->nb_hrir_inputs; i++) {
+char *name = av_asprintf("hrir%d", i);
 AVFilterPad pad = {
 .name = name,
 .type = AVMEDIA_TYPE_AUDIO,
 };
 if (!name)
 return AVERROR(ENOMEM);
-if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) {
+if ((ret = ff_insert_inpad(ctx, i + 1, &pad

[FFmpeg-devel] [PATCH 22/25] avfilter/af_headphone: Avoid indirection for function pointer

2020-09-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 2d2b57d819..8b0a431c45 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -75,7 +75,7 @@ typedef struct HeadphoneContext {
 FFTContext *fft[2], *ifft[2];
 FFTComplex *data_hrtf[2];
 
-AVFloatDSPContext *fdsp;
+float (*scalarproduct_float)(const float *v1, const float *v2, int len);
 struct hrir_inputs {
 int  ir_len;
 int  eof;
@@ -190,7 +190,7 @@ static int headphone_convolute(AVFilterContext *ctx, void 
*arg, int jobnr, int n
 memcpy(temp_src + len, bptr, (air_len - len) * 
sizeof(*temp_src));
 }
 
-dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, 
FFALIGN(ir_len, 32));
+dst[0] += s->scalarproduct_float(temp_ir, temp_src, 
FFALIGN(ir_len, 32));
 temp_ir += air_len;
 }
 
@@ -668,9 +668,13 @@ static av_cold int init(AVFilterContext *ctx)
 }
 }
 
-s->fdsp = avpriv_float_dsp_alloc(0);
-if (!s->fdsp)
-return AVERROR(ENOMEM);
+if (s->type == TIME_DOMAIN) {
+AVFloatDSPContext *fdsp = avpriv_float_dsp_alloc(0);
+if (!fdsp)
+return AVERROR(ENOMEM);
+s->scalarproduct_float = fdsp->scalarproduct_float;
+av_free(fdsp);
+}
 
 return 0;
 }
@@ -715,7 +719,6 @@ static av_cold void uninit(AVFilterContext *ctx)
 av_freep(&s->temp_afft[1]);
 av_freep(&s->data_hrtf[0]);
 av_freep(&s->data_hrtf[1]);
-av_freep(&s->fdsp);
 
 for (unsigned i = 1; i < ctx->nb_inputs; i++)
 av_freep(&ctx->input_pads[i].name);
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 21/25] avfilter/af_headphone: Avoid allocating array

2020-09-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index bbbe32a475..2d2b57d819 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -79,7 +79,7 @@ typedef struct HeadphoneContext {
 struct hrir_inputs {
 int  ir_len;
 int  eof;
-} *hrir_in;
+} hrir_in[64];
 uint64_t mapping[64];
 } HeadphoneContext;
 
@@ -654,10 +654,6 @@ static av_cold int init(AVFilterContext *ctx)
 
 parse_map(ctx);
 
-s->hrir_in = av_calloc(s->nb_hrir_inputs, sizeof(*s->hrir_in));
-if (!s->hrir_in)
-return AVERROR(ENOMEM);
-
 for (i = 0; i < s->nb_hrir_inputs; i++) {
 char *name = av_asprintf("hrir%d", i);
 AVFilterPad pad = {
@@ -721,7 +717,6 @@ static av_cold void uninit(AVFilterContext *ctx)
 av_freep(&s->data_hrtf[1]);
 av_freep(&s->fdsp);
 
-av_freep(&s->hrir_in);
 for (unsigned i = 1; i < ctx->nb_inputs; i++)
 av_freep(&ctx->input_pads[i].name);
 }
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 19/25] avfilter/af_headphone: Only keep one AVFrame at a time

2020-09-08 Thread Andreas Rheinhardt
Despite the headphone filter only using one AVFrame at a time, it kept
an array each of whose entries contained a pointer to an AVFrame at all
times; the pointers were mostly NULL. This commit instead replaces them
by using a single pointer to an AVFrame on the stack of the only
function that actually uses them.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index d57ecb1f50..c84142e1ce 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -77,7 +77,6 @@ typedef struct HeadphoneContext {
 
 AVFloatDSPContext *fdsp;
 struct headphone_inputs {
-AVFrame *frame;
 int  ir_len;
 int  eof;
 } *in;
@@ -367,6 +366,7 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 const int ir_len = s->ir_len;
 int nb_input_channels = ctx->inputs[0]->channels;
 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
+AVFrame *frame;
 int ret = 0;
 int n_fft;
 int i, j, k;
@@ -432,14 +432,14 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 }
 }
 
-for (i = 0; i < s->nb_inputs - 1; i++) {
+for (i = 0; i < s->nb_inputs - 1; av_frame_free(&frame), i++) {
 int len = s->in[i + 1].ir_len;
 float *ptr;
 
-ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &s->in[i 
+ 1].frame);
+ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &frame);
 if (ret < 0)
 goto fail;
-ptr = (float *)s->in[i + 1].frame->extended_data[0];
+ptr = (float *)frame->extended_data[0];
 
 if (s->hrir_fmt == HRIR_STEREO) {
 int idx = 
av_get_channel_layout_channel_index(inlink->channel_layout,
@@ -502,17 +502,11 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 }
 }
 }
-
-av_frame_free(&s->in[i + 1].frame);
 }
 
 s->have_hrirs = 1;
 
 fail:
-
-for (i = 0; i < s->nb_inputs - 1; i++)
-av_frame_free(&s->in[i + 1].frame);
-
 return ret;
 }
 
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 15/25] avfilter/af_headphone: Avoid intermediate buffers II

2020-09-08 Thread Andreas Rheinhardt
When the headphone filter is configured to perform its processing in the
frequency domain, it allocates (among other things) two pairs of
buffers, all of the same size. One pair is used to store data in it
during the initialization of the filter; the other pair is only
allocated lateron. It is zero-initialized and yet its data is
immediately overwritten by the content of the other pair of buffers
mentioned above; the latter pair is then freed.

This commit eliminates the pair of intermediate buffers.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 33 +++--
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 359174d4b4..fb6af7a966 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -371,8 +371,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 int nb_irs = s->nb_irs;
 int nb_input_channels = ctx->inputs[0]->channels;
 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
-FFTComplex *data_hrtf_l = NULL;
-FFTComplex *data_hrtf_r = NULL;
 FFTComplex *fft_in_l = NULL;
 FFTComplex *fft_in_r = NULL;
 int offset = 0, ret = 0;
@@ -439,9 +437,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 goto fail;
 }
 } else {
-data_hrtf_l = av_calloc(n_fft, sizeof(*data_hrtf_l) * nb_irs);
-data_hrtf_r = av_calloc(n_fft, sizeof(*data_hrtf_r) * nb_irs);
-if (!data_hrtf_r || !data_hrtf_l) {
+s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_irs);
+s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_irs);
+if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
@@ -488,10 +486,10 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 av_fft_permute(s->fft[0], fft_in_l);
 av_fft_calc(s->fft[0], fft_in_l);
-memcpy(data_hrtf_l + offset, fft_in_l, n_fft * 
sizeof(*fft_in_l));
+memcpy(s->data_hrtf[0] + offset, fft_in_l, n_fft * 
sizeof(*fft_in_l));
 av_fft_permute(s->fft[0], fft_in_r);
 av_fft_calc(s->fft[0], fft_in_r);
-memcpy(data_hrtf_r + offset, fft_in_r, n_fft * 
sizeof(*fft_in_r));
+memcpy(s->data_hrtf[1] + offset, fft_in_r, n_fft * 
sizeof(*fft_in_r));
 }
 } else {
 int I, N = ctx->inputs[1]->channels;
@@ -529,10 +527,10 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 av_fft_permute(s->fft[0], fft_in_l);
 av_fft_calc(s->fft[0], fft_in_l);
-memcpy(data_hrtf_l + offset, fft_in_l, n_fft * 
sizeof(*fft_in_l));
+memcpy(s->data_hrtf[0] + offset, fft_in_l, n_fft * 
sizeof(*fft_in_l));
 av_fft_permute(s->fft[0], fft_in_r);
 av_fft_calc(s->fft[0], fft_in_r);
-memcpy(data_hrtf_r + offset, fft_in_r, n_fft * 
sizeof(*fft_in_r));
+memcpy(s->data_hrtf[1] + offset, fft_in_r, n_fft * 
sizeof(*fft_in_r));
 }
 }
 }
@@ -540,20 +538,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 av_frame_free(&s->in[i + 1].frame);
 }
 
-if (s->type == FREQUENCY_DOMAIN) {
-s->data_hrtf[0] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
-s->data_hrtf[1] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
-if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
-memcpy(s->data_hrtf[0], data_hrtf_l,
-sizeof(FFTComplex) * nb_irs * n_fft);
-memcpy(s->data_hrtf[1], data_hrtf_r,
-sizeof(FFTComplex) * nb_irs * n_fft);
-}
-
 s->have_hrirs = 1;
 
 fail:
@@ -561,9 +545,6 @@ fail:
 for (i = 0; i < s->nb_inputs - 1; i++)
 av_frame_free(&s->in[i + 1].frame);
 
-av_freep(&data_hrtf_l);
-av_freep(&data_hrtf_r);
-
 av_freep(&fft_in_l);
 av_freep(&fft_in_r);
 
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 14/25] avfilter/af_headphone: Avoid intermediate buffers I

2020-09-08 Thread Andreas Rheinhardt
The headphone filter has two modes; in one of them (say A), it needs
certain buffers to store data. But it allocated them in both modes.
Furthermore when in mode A it also allocated intermediate buffers of the
same size, initialized them, copied their contents into the permanent
buffers and freed them.

This commit changes this: The permanent buffer is only allocated when
needed; the temporary buffer has been completely avoided.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 38 +++---
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index f862181cbb..359174d4b4 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -375,8 +375,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 FFTComplex *data_hrtf_r = NULL;
 FFTComplex *fft_in_l = NULL;
 FFTComplex *fft_in_r = NULL;
-float *data_ir_l = NULL;
-float *data_ir_r = NULL;
 int offset = 0, ret = 0;
 int n_fft;
 int i, j, k;
@@ -408,9 +406,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 }
 }
 
-s->data_ir[0] = av_calloc(s->air_len, sizeof(float) * s->nb_irs);
-s->data_ir[1] = av_calloc(s->air_len, sizeof(float) * s->nb_irs);
-
 if (s->type == TIME_DOMAIN) {
 s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * 
nb_input_channels);
 s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float) * 
nb_input_channels);
@@ -428,8 +423,7 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 }
 }
 
-if (!s->data_ir[0] || !s->data_ir[1] ||
-!s->ringbuffer[0] || !s->ringbuffer[1]) {
+if (!s->ringbuffer[0] || !s->ringbuffer[1]) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
@@ -438,9 +432,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 s->temp_src[0] = av_calloc(s->air_len, sizeof(float));
 s->temp_src[1] = av_calloc(s->air_len, sizeof(float));
 
-data_ir_l = av_calloc(nb_irs * s->air_len, sizeof(*data_ir_l));
-data_ir_r = av_calloc(nb_irs * s->air_len, sizeof(*data_ir_r));
-if (!data_ir_r || !data_ir_l || !s->temp_src[0] || !s->temp_src[1]) {
+s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0]));
+s->data_ir[1] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[1]));
+if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || 
!s->temp_src[1]) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
@@ -475,10 +469,12 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 if (idx == -1)
 continue;
 if (s->type == TIME_DOMAIN) {
-offset = idx * s->air_len;
+float *data_ir_l = s->data_ir[0] + idx * s->air_len;
+float *data_ir_r = s->data_ir[1] + idx * s->air_len;
+
 for (j = 0; j < len; j++) {
-data_ir_l[offset + j] = ptr[len * 2 - j * 2 - 2] * 
gain_lin;
-data_ir_r[offset + j] = ptr[len * 2 - j * 2 - 1] * 
gain_lin;
+data_ir_l[j] = ptr[len * 2 - j * 2 - 2] * gain_lin;
+data_ir_r[j] = ptr[len * 2 - j * 2 - 1] * gain_lin;
 }
 } else {
 memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
@@ -514,10 +510,12 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 I = idx * 2;
 if (s->type == TIME_DOMAIN) {
-offset = idx * s->air_len;
+float *data_ir_l = s->data_ir[0] + idx * s->air_len;
+float *data_ir_r = s->data_ir[1] + idx * s->air_len;
+
 for (j = 0; j < len; j++) {
-data_ir_l[offset + j] = ptr[len * N - j * N - N + I
] * gain_lin;
-data_ir_r[offset + j] = ptr[len * N - j * N - N + I + 
1] * gain_lin;
+data_ir_l[j] = ptr[len * N - j * N - N + I] * 
gain_lin;
+data_ir_r[j] = ptr[len * N - j * N - N + I + 1] * 
gain_lin;
 }
 } else {
 memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
@@ -542,10 +540,7 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 av_frame_free(&s->in[i + 1].frame);
 }
 
-if (s->type == TIME_DOMAIN) {
-memcpy(s->data_ir[0], data_ir_l, sizeof(float) * nb_irs * s->air_len);
-memcpy(s->data_ir[1], data_ir_r, sizeof(float) * nb_irs * s->air_len);
-} else {
+if (s->type == FREQUENCY_DOMAIN) {
 s->data_hrtf[0] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
 s->data_hrtf[1] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
 if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
@@ -566,9 

[FFmpeg-devel] [PATCH 17/25] avfilter/af_headphone: Simplify finding channel index

2020-09-08 Thread Andreas Rheinhardt
Before this commit, the headphone filter called
av_channel_layout_extract_channel() in a loop in order to find out
the index of a channel (given via its AV_CH_* value) in a channel layout.
This commit changes this to av_get_channel_layout_channel_index()
instead.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 32 
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index d6647ff80b..b5c2bd6121 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -100,7 +100,6 @@ static void parse_map(AVFilterContext *ctx)
 char *arg, *tokenizer, *p;
 uint64_t used_channels = 0;
 
-s->lfe_channel = -1;
 s->nb_inputs = 1;
 
 p = s->map;
@@ -452,18 +451,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 ptr = (float *)s->in[i + 1].frame->extended_data[0];
 
 if (s->hrir_fmt == HRIR_STEREO) {
-int idx = -1;
-
-for (j = 0; j < inlink->channels; j++) {
-if ((av_channel_layout_extract_channel(inlink->channel_layout, 
j)) == s->mapping[i]) {
-idx = j;
-if (s->mapping[i] == AV_CH_LOW_FREQUENCY)
-s->lfe_channel = j;
-break;
-}
-}
-
-if (idx == -1)
+int idx = 
av_get_channel_layout_channel_index(inlink->channel_layout,
+  s->mapping[i]);
+if (idx < 0)
 continue;
 if (s->type == TIME_DOMAIN) {
 float *data_ir_l = s->data_ir[0] + idx * s->air_len;
@@ -494,17 +484,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 int I, N = ctx->inputs[1]->channels;
 
 for (k = 0; k < N / 2; k++) {
-int idx = -1;
-
-for (j = 0; j < inlink->channels; j++) {
-if 
((av_channel_layout_extract_channel(inlink->channel_layout, j)) == 
s->mapping[k]) {
-idx = j;
-if (s->mapping[k] == AV_CH_LOW_FREQUENCY)
-s->lfe_channel = j;
-break;
-}
-}
-if (idx == -1)
+int idx = 
av_get_channel_layout_channel_index(inlink->channel_layout,
+  s->mapping[k]);
+if (idx < 0)
 continue;
 
 I = k * 2;
@@ -671,6 +653,8 @@ static int config_input(AVFilterLink *inlink)
 return AVERROR(EINVAL);
 }
 
+s->lfe_channel = 
av_get_channel_layout_channel_index(inlink->channel_layout,
+ AV_CH_LOW_FREQUENCY);
 return 0;
 }
 
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 16/25] avfilter/af_headphone: Fix channel assignment

2020-09-08 Thread Andreas Rheinhardt
The documentation of the map argument of the headphone filter states:

"Set mapping of input streams for convolution. The argument is a
’|’-separated list of channel names in order as they are given as
additional stream inputs for filter."

Yet this has not been honoured at all. Instead for the kth given HRIR
channel pair it was checked whether there was a kth mapping and if the
channel position so given was present in the channel layout of the main
input; if so, then the given HRIR channel pair was matched to the kth
channel of the main input. It should actually have been matched to the
channel given by the kth mapping. A consequence of the current algorithm
is that if N additional HRIR channel pairs are given, a permutation of
the first N entries of the mapping does not affect the output at all.

The old code might even set arrays belonging to streams that don't exist
(i.e. whose index is >= the number of channels of the main input
stream); these parts were not read lateron at all. The new code doesn't
do this any longer and therefore the number of elements of some of the
allocated arrays has been reduced (in case the number of mappings was
bigger than the number of channels of the first input stream).

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index fb6af7a966..d6647ff80b 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -117,8 +117,6 @@ static void parse_map(AVFilterContext *ctx)
 continue;
 }
 used_channels|= out_channel;
-if (out_channel == AV_CH_LOW_FREQUENCY)
-s->lfe_channel = s->nb_irs;
 s->mapping[s->nb_irs] = out_channel;
 s->nb_irs++;
 }
@@ -368,7 +366,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 {
 struct HeadphoneContext *s = ctx->priv;
 const int ir_len = s->ir_len;
-int nb_irs = s->nb_irs;
 int nb_input_channels = ctx->inputs[0]->channels;
 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
 FFTComplex *fft_in_l = NULL;
@@ -430,15 +427,15 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 s->temp_src[0] = av_calloc(s->air_len, sizeof(float));
 s->temp_src[1] = av_calloc(s->air_len, sizeof(float));
 
-s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0]));
-s->data_ir[1] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[1]));
+s->data_ir[0] = av_calloc(nb_input_channels * s->air_len, 
sizeof(*s->data_ir[0]));
+s->data_ir[1] = av_calloc(nb_input_channels * s->air_len, 
sizeof(*s->data_ir[1]));
 if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || 
!s->temp_src[1]) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
 } else {
-s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_irs);
-s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_irs);
+s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * 
nb_input_channels);
+s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * 
nb_input_channels);
 if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
 ret = AVERROR(ENOMEM);
 goto fail;
@@ -459,7 +456,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 for (j = 0; j < inlink->channels; j++) {
 if ((av_channel_layout_extract_channel(inlink->channel_layout, 
j)) == s->mapping[i]) {
-idx = i;
+idx = j;
+if (s->mapping[i] == AV_CH_LOW_FREQUENCY)
+s->lfe_channel = j;
 break;
 }
 }
@@ -499,14 +498,16 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 for (j = 0; j < inlink->channels; j++) {
 if 
((av_channel_layout_extract_channel(inlink->channel_layout, j)) == 
s->mapping[k]) {
-idx = k;
+idx = j;
+if (s->mapping[k] == AV_CH_LOW_FREQUENCY)
+s->lfe_channel = j;
 break;
 }
 }
 if (idx == -1)
 continue;
 
-I = idx * 2;
+I = k * 2;
 if (s->type == TIME_DOMAIN) {
 float *data_ir_l = s->data_ir[0] + idx * s->air_len;
 float *data_ir_r = s->data_ir[1] + idx * s->air_len;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 13/25] avfilter/af_headphone: Remove delay fields

2020-09-08 Thread Andreas Rheinhardt
They seem to exist for an option that was never implemented.

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

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index f9799d8548..f862181cbb 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -79,8 +79,6 @@ typedef struct HeadphoneContext {
 struct headphone_inputs {
 AVFrame *frame;
 int  ir_len;
-int  delay_l;
-int  delay_r;
 int  eof;
 } *in;
 uint64_t mapping[64];
@@ -457,8 +455,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 for (i = 0; i < s->nb_inputs - 1; i++) {
 int len = s->in[i + 1].ir_len;
-int delay_l = s->in[i + 1].delay_l;
-int delay_r = s->in[i + 1].delay_r;
 float *ptr;
 
 ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &s->in[i 
+ 1].frame);
@@ -490,8 +486,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 offset = idx * n_fft;
 for (j = 0; j < len; j++) {
-fft_in_l[delay_l + j].re = ptr[j * 2] * gain_lin;
-fft_in_r[delay_r + j].re = ptr[j * 2 + 1] * gain_lin;
+fft_in_l[j].re = ptr[j * 2] * gain_lin;
+fft_in_r[j].re = ptr[j * 2 + 1] * gain_lin;
 }
 
 av_fft_permute(s->fft[0], fft_in_l);
@@ -529,8 +525,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 offset = idx * n_fft;
 for (j = 0; j < len; j++) {
-fft_in_l[delay_l + j].re = ptr[j * N + I] * 
gain_lin;
-fft_in_r[delay_r + j].re = ptr[j * N + I + 1] * 
gain_lin;
+fft_in_l[j].re = ptr[j * N + I] * gain_lin;
+fft_in_r[j].re = ptr[j * N + I + 1] * gain_lin;
 }
 
 av_fft_permute(s->fft[0], fft_in_l);
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 18/25] avfilter/af_headphone: Avoid intermediate buffer III

2020-09-08 Thread Andreas Rheinhardt
The headphone filter allocates a pair of buffers to be used as
intermediate buffers lateron: Before every use they are zeroed, then
some elements of the buffer are set and lateron the complete buffers are
copied into another, bigger buffer. These intermediate buffers are
unnecessary as the data can be directly written into the bigger buffer.
Furthermore, the whole buffer has been zeroed initially and because no
piece of this buffer is set twice (due to the fact that duplicate
channel map entries are skipped), it is unnecessary to rezero the part
of the big buffer that is about to be written to.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 28 +---
 1 file changed, 5 insertions(+), 23 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index b5c2bd6121..d57ecb1f50 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -367,9 +367,7 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 const int ir_len = s->ir_len;
 int nb_input_channels = ctx->inputs[0]->channels;
 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
-FFTComplex *fft_in_l = NULL;
-FFTComplex *fft_in_r = NULL;
-int offset = 0, ret = 0;
+int ret = 0;
 int n_fft;
 int i, j, k;
 
@@ -381,13 +379,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 s->n_fft = n_fft = 1 << (32 - ff_clz(ir_len + s->size));
 
 if (s->type == FREQUENCY_DOMAIN) {
-fft_in_l = av_calloc(n_fft, sizeof(*fft_in_l));
-fft_in_r = av_calloc(n_fft, sizeof(*fft_in_r));
-if (!fft_in_l || !fft_in_r) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
 s->fft[0] = av_fft_init(av_log2(s->n_fft), 0);
 s->fft[1] = av_fft_init(av_log2(s->n_fft), 0);
 s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1);
@@ -464,10 +455,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 data_ir_r[j] = ptr[len * 2 - j * 2 - 1] * gain_lin;
 }
 } else {
-memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
-memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
+FFTComplex *fft_in_l = s->data_hrtf[0] + idx * n_fft;
+FFTComplex *fft_in_r = s->data_hrtf[1] + idx * n_fft;
 
-offset = idx * n_fft;
 for (j = 0; j < len; j++) {
 fft_in_l[j].re = ptr[j * 2] * gain_lin;
 fft_in_r[j].re = ptr[j * 2 + 1] * gain_lin;
@@ -475,10 +465,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 av_fft_permute(s->fft[0], fft_in_l);
 av_fft_calc(s->fft[0], fft_in_l);
-memcpy(s->data_hrtf[0] + offset, fft_in_l, n_fft * 
sizeof(*fft_in_l));
 av_fft_permute(s->fft[0], fft_in_r);
 av_fft_calc(s->fft[0], fft_in_r);
-memcpy(s->data_hrtf[1] + offset, fft_in_r, n_fft * 
sizeof(*fft_in_r));
 }
 } else {
 int I, N = ctx->inputs[1]->channels;
@@ -499,10 +487,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 data_ir_r[j] = ptr[len * N - j * N - N + I + 1] * 
gain_lin;
 }
 } else {
-memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
-memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
+FFTComplex *fft_in_l = s->data_hrtf[0] + idx * n_fft;
+FFTComplex *fft_in_r = s->data_hrtf[1] + idx * n_fft;
 
-offset = idx * n_fft;
 for (j = 0; j < len; j++) {
 fft_in_l[j].re = ptr[j * N + I] * gain_lin;
 fft_in_r[j].re = ptr[j * N + I + 1] * gain_lin;
@@ -510,10 +497,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 av_fft_permute(s->fft[0], fft_in_l);
 av_fft_calc(s->fft[0], fft_in_l);
-memcpy(s->data_hrtf[0] + offset, fft_in_l, n_fft * 
sizeof(*fft_in_l));
 av_fft_permute(s->fft[0], fft_in_r);
 av_fft_calc(s->fft[0], fft_in_r);
-memcpy(s->data_hrtf[1] + offset, fft_in_r, n_fft * 
sizeof(*fft_in_r));
 }
 }
 }
@@ -528,9 +513,6 @@ fail:
 for (i = 0; i < s->nb_inputs - 1; i++)
 av_frame_free(&s->in[i + 1].frame);
 
-av_freep(&fft_in_l);
-av_freep(&fft_in_r);
-
 return ret;
 }
 
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 11/25] avfilter/af_headphone: Avoid duplicating string needlessly

2020-09-08 Thread Andreas Rheinhardt
The string given by an AVOption that contains the channel assignment
is used only once; ergo it doesn't matter that parsing the string via
av_strtok() is destructive. There is no need to make a copy.

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

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 32939af854..967f8ed5a6 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -100,16 +100,13 @@ static int parse_channel_name(const char *arg, uint64_t 
*rchannel)
 static void parse_map(AVFilterContext *ctx)
 {
 HeadphoneContext *s = ctx->priv;
-char *arg, *tokenizer, *p, *args = av_strdup(s->map);
+char *arg, *tokenizer, *p;
 uint64_t used_channels = 0;
 
-if (!args)
-return;
-p = args;
-
 s->lfe_channel = -1;
 s->nb_inputs = 1;
 
+p = s->map;
 while ((arg = av_strtok(p, "|", &tokenizer))) {
 uint64_t out_channel;
 
@@ -133,8 +130,6 @@ static void parse_map(AVFilterContext *ctx)
 s->nb_inputs = 2;
 else
 s->nb_inputs = s->nb_irs + 1;
-
-av_free(args);
 }
 
 typedef struct ThreadData {
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 12/25] avfilter/af_headphone: Remove unused arrays

2020-09-08 Thread Andreas Rheinhardt
The delay arrays were never properly initialized, only zero-initialized;
furthermore these arrays duplicate fields in the headphone_inputs
struct. So remove them.
(Btw: The allocations for them have not been checked.)

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 967f8ed5a6..f9799d8548 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -67,7 +67,6 @@ typedef struct HeadphoneContext {
 int size;
 int hrir_fmt;
 
-int *delay[2];
 float *data_ir[2];
 float *temp_src[2];
 FFTComplex *temp_fft[2];
@@ -135,7 +134,6 @@ static void parse_map(AVFilterContext *ctx)
 typedef struct ThreadData {
 AVFrame *in, *out;
 int *write;
-int **delay;
 float **ir;
 int *n_clippings;
 float **ringbuffer;
@@ -151,7 +149,6 @@ static int headphone_convolute(AVFilterContext *ctx, void 
*arg, int jobnr, int n
 AVFrame *in = td->in, *out = td->out;
 int offset = jobnr;
 int *write = &td->write[jobnr];
-const int *const delay = td->delay[jobnr];
 const float *const ir = td->ir[jobnr];
 int *n_clippings = &td->n_clippings[jobnr];
 float *ringbuffer = td->ringbuffer[jobnr];
@@ -190,7 +187,7 @@ static int headphone_convolute(AVFilterContext *ctx, void 
*arg, int jobnr, int n
 continue;
 }
 
-read = (wr - *(delay + l) - (ir_len - 1) + buffer_length) & modulo;
+read = (wr - (ir_len - 1) + buffer_length) & modulo;
 
 if (read + ir_len < buffer_length) {
 memcpy(temp_src, bptr + read, ir_len * sizeof(*temp_src));
@@ -348,7 +345,7 @@ static int headphone_frame(HeadphoneContext *s, AVFrame 
*in, AVFilterLink *outli
 out->pts = in->pts;
 
 td.in = in; td.out = out; td.write = s->write;
-td.delay = s->delay; td.ir = s->data_ir; td.n_clippings = n_clippings;
+td.ir = s->data_ir; td.n_clippings = n_clippings;
 td.ringbuffer = s->ringbuffer; td.temp_src = s->temp_src;
 td.temp_fft = s->temp_fft;
 td.temp_afft = s->temp_afft;
@@ -415,8 +412,6 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 
 s->data_ir[0] = av_calloc(s->air_len, sizeof(float) * s->nb_irs);
 s->data_ir[1] = av_calloc(s->air_len, sizeof(float) * s->nb_irs);
-s->delay[0] = av_calloc(s->nb_irs, sizeof(float));
-s->delay[1] = av_calloc(s->nb_irs, sizeof(float));
 
 if (s->type == TIME_DOMAIN) {
 s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * 
nb_input_channels);
@@ -782,8 +777,6 @@ static av_cold void uninit(AVFilterContext *ctx)
 av_fft_end(s->ifft[1]);
 av_fft_end(s->fft[0]);
 av_fft_end(s->fft[1]);
-av_freep(&s->delay[0]);
-av_freep(&s->delay[1]);
 av_freep(&s->data_ir[0]);
 av_freep(&s->data_ir[1]);
 av_freep(&s->ringbuffer[0]);
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 10/25] avfilter/af_headphone: Simplify parsing channel mapping string

2020-09-08 Thread Andreas Rheinhardt
When parsing the channel mapping string (a string containing '|'
delimited tokens each of which is supposed to contain a channel name
like "FR"), the old code would at each step read up to seven uppercase
characters from the input string and give this to
av_get_channel_layout() to parse. The returned layout is then checked
for being a layout with a single channel set by computing its logarithm.

Besides being overtly complicated this also has the drawback of relying
on the assumption that every channel name consists of at most seven
uppercase letters only; but said assumption is wrong: The abbreviation
of the second low frequency channel is LFE2. Furthermore it treats
garbage like "FRfoo" as valid channel.

This commit changes this by using av_get_channel_layout() directly;
furthermore, av_get_channel_layout_nb_channels() (which uses popcount)
is used to find out the number of channels instead of the custom code
to calculate the logarithm.

(As a consequence, certain other formats to specify the channel layouts
are now accepted (like the hex versions of av_get_channel_layout()); but
this is actually not bad at all.)

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 31 +--
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 8db712e9a0..32939af854 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -87,26 +87,14 @@ typedef struct HeadphoneContext {
 uint64_t mapping[64];
 } HeadphoneContext;
 
-static int parse_channel_name(char **arg, uint64_t *rchannel, char *buf)
+static int parse_channel_name(const char *arg, uint64_t *rchannel)
 {
-int len, i, channel_id = 0;
-uint64_t layout, layout0;
-
-if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
-layout0 = layout = av_get_channel_layout(buf);
-for (i = 32; i > 0; i >>= 1) {
-if (layout >= 1LL << i) {
-channel_id += i;
-layout >>= i;
-}
-}
-if (channel_id >= 64 || layout0 != 1ULL << channel_id)
-return AVERROR(EINVAL);
-*rchannel = layout0;
-*arg += len;
-return 0;
-}
-return AVERROR(EINVAL);
+uint64_t layout = av_get_channel_layout(arg);
+
+if (av_get_channel_layout_nb_channels(layout) != 1)
+return AVERROR(EINVAL);
+*rchannel = layout;
+return 0;
 }
 
 static void parse_map(AVFilterContext *ctx)
@@ -124,15 +112,14 @@ static void parse_map(AVFilterContext *ctx)
 
 while ((arg = av_strtok(p, "|", &tokenizer))) {
 uint64_t out_channel;
-char buf[8];
 
 p = NULL;
-if (parse_channel_name(&arg, &out_channel, buf)) {
+if (parse_channel_name(arg, &out_channel)) {
 av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel 
name.\n", arg);
 continue;
 }
 if (used_channels & out_channel) {
-av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", 
buf);
+av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", 
arg);
 continue;
 }
 used_channels|= out_channel;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 09/25] avfilter/af_headphone: Use uint64_t for channel mapping

2020-09-08 Thread Andreas Rheinhardt
The headphone filter has an option for the user to specify an assignment
of inputs to channels (or from pairs of channels of the second input to
channels). Up until now, these channels were stored in an int containing
the logarithm of the channel layout. Yet it is not the logarithm that is
used lateron and so a retransformation was necessary. Therefore this
commit simply stores the uint64_t as is, avoiding the retransformation.

This also has the advantage that unset channels (whose corresponding
entry is zero) can't be mistaken for valid channels any more; the old
code had to initialize the channels to -1 to solve this problem and had
to check for whether a channel is set before the retransformation
(because 1 << -1 is UB).

The only downside of this approach is that the size of the context
increases (by 256 bytes); but this is not exceedingly much.

Finally, the array has been moved to the end of the context; it is only
used a few times during the initialization process and moving it
decreased the offsets of lots of other entries, reducing codesize.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 40 +-
 1 file changed, 13 insertions(+), 27 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 4a68d35e66..8db712e9a0 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -52,8 +52,6 @@ typedef struct HeadphoneContext {
 int ir_len;
 int air_len;
 
-int mapping[64];
-
 int nb_inputs;
 
 int nb_irs;
@@ -86,12 +84,13 @@ typedef struct HeadphoneContext {
 int  delay_r;
 int  eof;
 } *in;
+uint64_t mapping[64];
 } HeadphoneContext;
 
-static int parse_channel_name(char **arg, int *rchannel, char *buf)
+static int parse_channel_name(char **arg, uint64_t *rchannel, char *buf)
 {
 int len, i, channel_id = 0;
-int64_t layout, layout0;
+uint64_t layout, layout0;
 
 if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
 layout0 = layout = av_get_channel_layout(buf);
@@ -101,9 +100,9 @@ static int parse_channel_name(char **arg, int *rchannel, 
char *buf)
 layout >>= i;
 }
 }
-if (channel_id >= 64 || layout0 != 1LL << channel_id)
+if (channel_id >= 64 || layout0 != 1ULL << channel_id)
 return AVERROR(EINVAL);
-*rchannel = channel_id;
+*rchannel = layout0;
 *arg += len;
 return 0;
 }
@@ -115,7 +114,6 @@ static void parse_map(AVFilterContext *ctx)
 HeadphoneContext *s = ctx->priv;
 char *arg, *tokenizer, *p, *args = av_strdup(s->map);
 uint64_t used_channels = 0;
-int i;
 
 if (!args)
 return;
@@ -124,27 +122,23 @@ static void parse_map(AVFilterContext *ctx)
 s->lfe_channel = -1;
 s->nb_inputs = 1;
 
-for (i = 0; i < 64; i++) {
-s->mapping[i] = -1;
-}
-
 while ((arg = av_strtok(p, "|", &tokenizer))) {
-int out_ch_id;
+uint64_t out_channel;
 char buf[8];
 
 p = NULL;
-if (parse_channel_name(&arg, &out_ch_id, buf)) {
+if (parse_channel_name(&arg, &out_channel, buf)) {
 av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel 
name.\n", arg);
 continue;
 }
-if (used_channels & (1ULL << out_ch_id)) {
+if (used_channels & out_channel) {
 av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", 
buf);
 continue;
 }
-used_channels |= 1ULL << out_ch_id;
-if (out_ch_id == av_log2(AV_CH_LOW_FREQUENCY))
+used_channels|= out_channel;
+if (out_channel == AV_CH_LOW_FREQUENCY)
 s->lfe_channel = s->nb_irs;
-s->mapping[s->nb_irs] = out_ch_id;
+s->mapping[s->nb_irs] = out_channel;
 s->nb_irs++;
 }
 
@@ -499,11 +493,7 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 int idx = -1;
 
 for (j = 0; j < inlink->channels; j++) {
-if (s->mapping[i] < 0) {
-continue;
-}
-
-if ((av_channel_layout_extract_channel(inlink->channel_layout, 
j)) == (1LL << s->mapping[i])) {
+if ((av_channel_layout_extract_channel(inlink->channel_layout, 
j)) == s->mapping[i]) {
 idx = i;
 break;
 }
@@ -541,11 +531,7 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 int idx = -1;
 
 for (j = 0; j < inlink->channels; j++) {
-if (s->mapping[k] < 0) {
-continue;
-}
-
-if 
((av_channel_layout_extract_channel(inlink->channel_layout, j)) == (1LL << 
s->mapping[k])) {
+if 
((av_channel_layout_extract_channel(inlink->channel_layout, j)) == 
s->mapping[k]) {
 

[FFmpeg-devel] [PATCH 04/25] avfilter/af_headphone: Fix segfault when using very short streams

2020-09-08 Thread Andreas Rheinhardt
When the headphone filter does its processing in the time domain,
the lengths of the buffers involved are determined by three parameters,
only two of which are relevant here: ir_len and air_len. The former is
the length (in samples) of the longest HRIR input stream and the latter
is the smallest power-of-two bigger than ir_len.

Using optimized functions to calculate the convolution places
restrictions on the alignment of the length of the vectors whose scalar
product is calculated. Therefore said length, namely ir_len, is aligned
on 32; but the number of elements of the buffers used is given by air_len
and for ir_len < 16 a buffer overflow happens.

This commit fixes this by ensuring that air_len is always >= 32 if
processing happens in the time domain.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index f488e0e28d..54b5dfec4c 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -405,6 +405,9 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 int i, j, k;
 
 s->air_len = 1 << (32 - ff_clz(ir_len));
+if (s->type == TIME_DOMAIN) {
+s->air_len = FFALIGN(s->air_len, 32);
+}
 s->buffer_length = 1 << (32 - ff_clz(s->air_len));
 s->n_fft = n_fft = 1 << (32 - ff_clz(ir_len + s->size));
 
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 06/25] avfilter/af_headphone: Fix stack buffer overflow

2020-09-08 Thread Andreas Rheinhardt
The number of channels can be up to 64, not only 16.

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

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 99bdefbcff..42adc82df8 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -187,7 +187,7 @@ static int headphone_convolute(AVFilterContext *ctx, void 
*arg, int jobnr, int n
 const int in_channels = in->channels;
 const int buffer_length = s->buffer_length;
 const uint32_t modulo = (uint32_t)buffer_length - 1;
-float *buffer[16];
+float *buffer[64];
 int wr = *write;
 int read;
 int i, l;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 08/25] avfilter/af_headphone: Only attempt once to init coeffs

2020-09-08 Thread Andreas Rheinhardt
The headphone filter does most of its initialization after its init
function, because it can perform certain tasks only after all but its
first input streams have reached eof. When this happens, it allocates
certain buffers and errors out if an allocation fails.

Yet the filter didn't check whether some of these buffers already exist
(which may happen if an earlier attempt has been interrupted in the
middle (due to an allocation error)) in which case the old buffers leak.

This commit makes sure that initializing the buffers is only attempted
once; if not successfull at the first attempt, future calls to the
filter will error out. Trying to support resuming initialization doesn't
seem worthwhile.

Notice that some allocations were freed before a new allocation was
performed; yet this effort was incomplete. Said code has been removed.

Signed-off-by: Andreas Rheinhardt 
---
While I am sure about the aim of this patch, I am not sure if simply
returning EOF is enough or if I have to use one of those FF_FILTER
status macros to return that this filter is finished.

 libavfilter/af_headphone.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index c71f43c5c8..4a68d35e66 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -425,12 +425,8 @@ static int convert_coeffs(AVFilterContext *ctx, 
AVFilterLink *inlink)
 goto fail;
 }
 
-av_fft_end(s->fft[0]);
-av_fft_end(s->fft[1]);
 s->fft[0] = av_fft_init(av_log2(s->n_fft), 0);
 s->fft[1] = av_fft_init(av_log2(s->n_fft), 0);
-av_fft_end(s->ifft[0]);
-av_fft_end(s->ifft[1]);
 s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1);
 s->ifft[1] = av_fft_init(av_log2(s->n_fft), 1);
 
@@ -657,13 +653,12 @@ static int activate(AVFilterContext *ctx)
 if (!eof)
 return 0;
 s->eof_hrirs = 1;
-}
 
-if (!s->have_hrirs && s->eof_hrirs) {
 ret = convert_coeffs(ctx, inlink);
 if (ret < 0)
 return ret;
-}
+} else if (!s->have_hrirs)
+return AVERROR_EOF;
 
 if ((ret = ff_inlink_consume_samples(ctx->inputs[0], s->size, s->size, 
&in)) > 0) {
 ret = headphone_frame(s, in, outlink);
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 02/25] avfilter/af_headphone: Remove always true check

2020-09-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index e590d02eff..1024ff57b1 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -631,10 +631,8 @@ static int activate(AVFilterContext *ctx)
 if ((ret = check_ir(ctx->inputs[i], i)) < 0)
 return ret;
 
-if (!s->in[i].eof) {
 if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF)
 s->in[i].eof = 1;
-}
 }
 
 for (i = 1; i < s->nb_inputs; i++) {
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 03/25] avfilter/af_headphone: Check for the existence of samples

2020-09-08 Thread Andreas Rheinhardt
Not providing any samples makes no sense at all. And if no samples
were provided for one of the HRIR streams, one would either run into
an av_assert1 in ff_inlink_consume_samples() or into a segfault in
take_samples() in avfilter.c.

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

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 1024ff57b1..f488e0e28d 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -631,8 +631,14 @@ static int activate(AVFilterContext *ctx)
 if ((ret = check_ir(ctx->inputs[i], i)) < 0)
 return ret;
 
-if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF)
+if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF) {
+if (!ff_inlink_queued_samples(ctx->inputs[i])) {
+av_log(ctx, AV_LOG_ERROR, "No samples provided for "
+   "HRIR stream %d.\n", i - 1);
+return AVERROR_INVALIDDATA;
+}
 s->in[i].eof = 1;
+}
 }
 
 for (i = 1; i < s->nb_inputs; i++) {
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 01/25] avfilter/af_headphone: Don't use uninitialized buffer in log message

2020-09-08 Thread Andreas Rheinhardt
This buffer was supposed to be initialized by sscanf(input, "%7[A-Z]%n",
buf, &len), yet if the first input character is not in the A-Z range,
buf is not touched (in particular it needn't be zero-terminated if the
failure happened when parsing the first channel and it still contains
the last channel name if the failure happened when one channel name
could be successfully parsed). This is treated as error in which case
buf is used directly in the log message. This commit fixes this by
actually using the string that could not be matched in the log message
instead.

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

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 58d82ac41d..e590d02eff 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -135,7 +135,7 @@ static void parse_map(AVFilterContext *ctx)
 
 p = NULL;
 if (parse_channel_name(s, s->nb_irs, &arg, &out_ch_id, buf)) {
-av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel 
name.\n", buf);
+av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel 
name.\n", arg);
 continue;
 }
 s->mapping[s->nb_irs] = out_ch_id;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 07/25] avfilter/af_headphone: Combine several loops when checking for EOF

2020-09-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 24 +++-
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 42adc82df8..c71f43c5c8 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -633,6 +633,7 @@ static int activate(AVFilterContext *ctx)
 
 FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
 if (!s->eof_hrirs) {
+int eof = 1;
 for (i = 1; i < s->nb_inputs; i++) {
 if (s->in[i].eof)
 continue;
@@ -647,26 +648,15 @@ static int activate(AVFilterContext *ctx)
 return AVERROR_INVALIDDATA;
 }
 s->in[i].eof = 1;
+} else {
+if (ff_outlink_frame_wanted(ctx->outputs[0]))
+ff_inlink_request_frame(ctx->inputs[i]);
+eof = 0;
 }
 }
-
-for (i = 1; i < s->nb_inputs; i++) {
-if (!s->in[i].eof)
-break;
-}
-
-if (i != s->nb_inputs) {
-if (ff_outlink_frame_wanted(ctx->outputs[0])) {
-for (i = 1; i < s->nb_inputs; i++) {
-if (!s->in[i].eof)
-ff_inlink_request_frame(ctx->inputs[i]);
-}
-}
-
+if (!eof)
 return 0;
-} else {
-s->eof_hrirs = 1;
-}
+s->eof_hrirs = 1;
 }
 
 if (!s->have_hrirs && s->eof_hrirs) {
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 05/25] avfilter/af_headphone: Don't overrun array

2020-09-08 Thread Andreas Rheinhardt
The headphone filter stores the channel position of the ith HRIR stream
in the ith element of an array of 64 elements; but because there is no
check for duplicate channels, it is easy to write beyond the end of the
array by simply repeating channels.

This commit adds a check for duplicate channels to rule this out.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/af_headphone.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 54b5dfec4c..99bdefbcff 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -88,15 +88,13 @@ typedef struct HeadphoneContext {
 } *in;
 } HeadphoneContext;
 
-static int parse_channel_name(HeadphoneContext *s, int x, char **arg, int 
*rchannel, char *buf)
+static int parse_channel_name(char **arg, int *rchannel, char *buf)
 {
 int len, i, channel_id = 0;
 int64_t layout, layout0;
 
 if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
 layout0 = layout = av_get_channel_layout(buf);
-if (layout == AV_CH_LOW_FREQUENCY)
-s->lfe_channel = x;
 for (i = 32; i > 0; i >>= 1) {
 if (layout >= 1LL << i) {
 channel_id += i;
@@ -116,6 +114,7 @@ static void parse_map(AVFilterContext *ctx)
 {
 HeadphoneContext *s = ctx->priv;
 char *arg, *tokenizer, *p, *args = av_strdup(s->map);
+uint64_t used_channels = 0;
 int i;
 
 if (!args)
@@ -134,10 +133,17 @@ static void parse_map(AVFilterContext *ctx)
 char buf[8];
 
 p = NULL;
-if (parse_channel_name(s, s->nb_irs, &arg, &out_ch_id, buf)) {
+if (parse_channel_name(&arg, &out_ch_id, buf)) {
 av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel 
name.\n", arg);
 continue;
 }
+if (used_channels & (1ULL << out_ch_id)) {
+av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", 
buf);
+continue;
+}
+used_channels |= 1ULL << out_ch_id;
+if (out_ch_id == av_log2(AV_CH_LOW_FREQUENCY))
+s->lfe_channel = s->nb_irs;
 s->mapping[s->nb_irs] = out_ch_id;
 s->nb_irs++;
 }
-- 
2.20.1

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

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

Re: [FFmpeg-devel] [PATCH] lavfi/buffersink: cast to uint64_t before shifting.

2020-09-08 Thread James Almer
On 9/8/2020 3:36 PM, Nicolas George wrote:
> James Almer (12020-09-08):
>> You should use the stdint.h UINT64_C macro then, instead of casting.
> 
> I probably *could*. But I find casting more readable. What benefit do
> you see to them compared to casting?

It's a macro designed for this specific purpose. Figured it would be
proper, and we're using them in other parts of the code to shift the
values by more than 32 bits, like you're doing here. But yes, i should
have said could, not should.

I don't consider it less readable, and it's just as long as using a
cast, but of course it's up to you.
___
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] lavfi/buffersink: cast to uint64_t before shifting.

2020-09-08 Thread Nicolas George
James Almer (12020-09-08):
> You should use the stdint.h UINT64_C macro then, instead of casting.

I probably *could*. But I find casting more readable. What benefit do
you see to them compared to casting?

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] [PATCH] lavfi/buffersink: cast to uint64_t before shifting.

2020-09-08 Thread James Almer
On 9/8/2020 3:19 PM, Nicolas George wrote:
> Andreas Rheinhardt (12020-09-08):
>> Using ULL would be shorter.
> 
> But it would be wrong, it could be more than 64 bits. For modern C,
> using longs and shorts directly is a mistake (or the consequence of
> dealing with an obsolescent library), these types are used internally to
> implement the sane types from stdint.h. I know we use ULL like this all
> over the place, but I will not use it in my code.

You should use the stdint.h UINT64_C macro then, instead of casting.

> 
> Regards,
> 
> 
> ___
> 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] lavfi/buffersink: cast to uint64_t before shifting.

2020-09-08 Thread Nicolas George
Andreas Rheinhardt (12020-09-08):
> Using ULL would be shorter.

But it would be wrong, it could be more than 64 bits. For modern C,
using longs and shorts directly is a mistake (or the consequence of
dealing with an obsolescent library), these types are used internally to
implement the sane types from stdint.h. I know we use ULL like this all
over the place, but I will not use it in my code.

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] [PATCH] lavfi/buffersink: cast to uint64_t before shifting.

2020-09-08 Thread Andreas Rheinhardt
Nicolas George:
> Fix CID 146.
> 
> Signed-off-by: Nicolas George 
> ---
>  libavfilter/buffersink.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
> index 9338969bf1..58848941d4 100644
> --- a/libavfilter/buffersink.c
> +++ b/libavfilter/buffersink.c
> @@ -72,10 +72,10 @@ static void cleanup_redundant_layouts(AVFilterContext 
> *ctx)
>  
>  for (i = 0; i < nb_counts; i++)
>  if (buf->channel_counts[i] < 64)
> -counts |= 1 << buf->channel_counts[i];
> +counts |= (uint64_t)1 << buf->channel_counts[i];
>  for (i = lc = 0; i < nb_layouts; i++) {
>  n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]);
> -if (n < 64 && (counts & (1 << n)))
> +if (n < 64 && (counts & ((uint64_t)1 << n)))
>  av_log(ctx, AV_LOG_WARNING,
> "Removing channel layout 0x%"PRIx64", redundant with %d 
> channels\n",
> buf->channel_layouts[i], n);
> 
Using ULL would be shorter.

- 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] lavfi/buffersink: cast to uint64_t before shifting.

2020-09-08 Thread Nicolas George
Fix CID 146.

Signed-off-by: Nicolas George 
---
 libavfilter/buffersink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 9338969bf1..58848941d4 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -72,10 +72,10 @@ static void cleanup_redundant_layouts(AVFilterContext *ctx)
 
 for (i = 0; i < nb_counts; i++)
 if (buf->channel_counts[i] < 64)
-counts |= 1 << buf->channel_counts[i];
+counts |= (uint64_t)1 << buf->channel_counts[i];
 for (i = lc = 0; i < nb_layouts; i++) {
 n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]);
-if (n < 64 && (counts & (1 << n)))
+if (n < 64 && (counts & ((uint64_t)1 << n)))
 av_log(ctx, AV_LOG_WARNING,
"Removing channel layout 0x%"PRIx64", redundant with %d 
channels\n",
buf->channel_layouts[i], n);
-- 
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] ffplay: fix autoexit doesn't work in the case of pb->error

2020-09-08 Thread Marton Balint



On Mon, 7 Sep 2020, Zhao Zhili wrote:





On Aug 27, 2020, at 4:20 PM, Marton Balint  wrote:



On Thu, 27 Aug 2020, Zhao Zhili wrote:


---
Goto fail will make ffplay exit immediately. I'm not sure
it is the expected behavior. How about just remove the
check on pb->error so decoders can drain normally?


I think it is fine as is, if we simply ignored the error, then looping would 
start at the place of the error. Also probably it is not good practice to keep 
using an IO context which already had an IO error.



fftools/ffplay.c | 8 ++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 6c9c041e9a..9ff0425163 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3028,8 +3028,12 @@ static int read_thread(void *arg)
   packet_queue_put_nullpacket(&is->subtitleq, 
is->subtitle_stream);
   is->eof = 1;
   }
-if (ic->pb && ic->pb->error)
-break;
+if (ic->pb && ic->pb->error) {
+if (autoexit)
+goto fail;
+else
+break;
+}
   SDL_LockMutex(wait_mutex);
   SDL_CondWaitTimeout(is->continue_read_thread, wait_mutex, 10);
   SDL_UnlockMutex(wait_mutex);


LGTM, thanks.


Ping for further review or merge, thanks.


Will apply.

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

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

Re: [FFmpeg-devel] [PATCH 7/8] avfilter/vf_showinfo: use av_timecode_make_smpte_tc_string2

2020-09-08 Thread Marton Balint



On Sun, 6 Sep 2020, lance.lmw...@gmail.com wrote:


On Sat, Sep 05, 2020 at 08:22:16PM +0200, Marton Balint wrote:

Signed-off-by: Marton Balint 
---
 libavfilter/vf_showinfo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 1be939614d..c63e6f075f 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -114,7 +114,7 @@ static void dump_stereo3d(AVFilterContext *ctx, 
AVFrameSideData *sd)
 av_log(ctx, AV_LOG_INFO, " (inverted)");
 }

-static void dump_s12m_timecode(AVFilterContext *ctx, AVFrameSideData *sd)
+static void dump_s12m_timecode(AVFilterContext *ctx, AVFilterLink *link, 
AVFrameSideData *sd)


use framerate direclty instead of link for input?


Sure, OK, changed locally.

Thanks,
Marton




 {
 const uint32_t *tc = (const uint32_t *)sd->data;

@@ -125,7 +125,7 @@ static void dump_s12m_timecode(AVFilterContext *ctx, 
AVFrameSideData *sd)

 for (int j = 1; j <= tc[0]; j++) {
 char tcbuf[AV_TIMECODE_STR_SIZE];
-av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0);
+av_timecode_make_smpte_tc_string2(tcbuf, link->frame_rate, tc[j], 0, 
0);
 av_log(ctx, AV_LOG_INFO, "timecode - %s%s", tcbuf, j != tc[0]  ? ", " : 
"");
 }
 }
@@ -380,7 +380,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 dump_stereo3d(ctx, sd);
 break;
 case AV_FRAME_DATA_S12M_TIMECODE: {
-dump_s12m_timecode(ctx, sd);
+dump_s12m_timecode(ctx, inlink, sd);
 break;
 }
 case AV_FRAME_DATA_DISPLAYMATRIX:
--
2.26.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".


--
Thanks,
Limin Wang
___
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 4/4] avdevice/decklink_dec: add support for querying RP188 High Frame Rate timecode

2020-09-08 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 doc/indevs.texi | 4 ++--
 libavdevice/decklink_common.h   | 5 +
 libavdevice/decklink_common_c.h | 2 ++
 libavdevice/decklink_dec_c.c| 5 -
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 7748232b26..3d554bc8d8 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -350,8 +350,8 @@ Defaults to @samp{unset}.
 @item timecode_format
 Timecode type to include in the frame and video stream metadata. Must be
 @samp{none}, @samp{rp188vitc}, @samp{rp188vitc2}, @samp{rp188ltc},
-@samp{rp188any}, @samp{vitc}, @samp{vitc2}, or @samp{serial}. Defaults to
-@samp{none} (not included).
+@samp{rp188hfr}, @samp{rp188any}, @samp{vitc}, @samp{vitc2}, or @samp{serial}.
+Defaults to @samp{none} (not included).
 
 @item video_input
 Sets the video input source. Must be @samp{unset}, @samp{sdi}, @samp{hdmi},
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 9f69054e64..f35bd9ae6f 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -191,6 +191,11 @@ static const BMDTimecodeFormat 
decklink_timecode_format_map[] = {
 bmdTimecodeVITC,
 bmdTimecodeVITCField2,
 bmdTimecodeSerial,
+#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b00
+bmdTimecodeRP188HighFrameRate,
+#else
+(BMDTimecodeFormat)0,
+#endif
 };
 
 int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t 
direction);
diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h
index a78262aaac..68978fa855 100644
--- a/libavdevice/decklink_common_c.h
+++ b/libavdevice/decklink_common_c.h
@@ -23,6 +23,8 @@
 #ifndef AVDEVICE_DECKLINK_COMMON_C_H
 #define AVDEVICE_DECKLINK_COMMON_C_H
 
+#include 
+
 typedef enum DecklinkPtsSource {
 PTS_SRC_AUDIO = 1,
 PTS_SRC_VIDEO = 2,
diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
index 54cd681710..f3fdcd339d 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -49,7 +49,7 @@ static const AVOption options[] = {
 { "unset", NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 0}, 0, 0,DEC, "duplex_mode"},
 { "half",  NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 1}, 0, 0,DEC, "duplex_mode"},
 { "full",  NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 2}, 0, 0,DEC, "duplex_mode"},
-{ "timecode_format", "timecode format",   OFFSET(tc_format),  
AV_OPT_TYPE_INT,   { .i64 = 0}, 0, 7,DEC, "tc_format"},
+{ "timecode_format", "timecode format",   OFFSET(tc_format),  
AV_OPT_TYPE_INT,   { .i64 = 0}, 0, 8,DEC, "tc_format"},
 { "none",  NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 0}, 0, 0,DEC, "tc_format"},
 { "rp188vitc", NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 1}, 0, 0,DEC, "tc_format"},
 { "rp188vitc2",NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 2}, 0, 0,DEC, "tc_format"},
@@ -58,6 +58,9 @@ static const AVOption options[] = {
 { "vitc",  NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 5}, 0, 0,DEC, "tc_format"},
 { "vitc2", NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 6}, 0, 0,DEC, "tc_format"},
 { "serial",NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 7}, 0, 0,DEC, "tc_format"},
+#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b00
+{ "rp188hfr",  NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 8}, 0, 0,DEC, "tc_format"},
+#endif
 { "video_input",  "video input",  OFFSET(video_input),
AV_OPT_TYPE_INT,   { .i64 = 0}, 0, 6,DEC, "video_input"},
 { "unset", NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 0}, 0, 0,DEC, "video_input"},
 { "sdi",   NULL,  0,  
AV_OPT_TYPE_CONST, { .i64 = 1}, 0, 0,DEC, "video_input"},
-- 
2.26.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 1/4] avdevice/decklink_commoh.h: remove unsupported decklink version ifdef

2020-09-08 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavdevice/decklink_common.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index bd68c7ba77..9f69054e64 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -156,11 +156,7 @@ struct decklink_ctx {
 typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
 
 #ifdef _WIN32
-#if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a04
-typedef unsigned long buffercount_type;
-#else
 typedef unsigned int buffercount_type;
-#endif
 IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
 #else
 typedef uint32_t buffercount_type;
-- 
2.26.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 3/4] avdevice/decklink_dec: add support for rgb/yuv pixel format autodetection

2020-09-08 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 doc/indevs.texi  | 15 +++
 libavdevice/decklink_dec.cpp |  8 +++-
 libavdevice/decklink_dec_c.c |  3 ++-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 4d2312e201..7748232b26 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -296,16 +296,31 @@ supports it.
 Set the pixel format of the captured video.
 Available values are:
 @table @samp
+@item auto
+
+This is the default which means 8-bit YUV 422 or 8-bit ARGB if format
+autodetection is used, 8-bit YUV 422 otherwise.
+
 @item uyvy422
 
+8-bit YUV 422.
+
 @item yuv422p10
 
+10-bit YUV 422.
+
 @item argb
 
+8-bit RGB.
+
 @item bgra
 
+8-bit RGB.
+
 @item rgb10
 
+10-bit RGB.
+
 @end table
 
 @item teletext_lines
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index af0ef04c56..92b8feed14 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -1044,9 +1044,13 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 
 HRESULT decklink_input_callback::VideoInputFormatChanged(
 BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *mode,
-BMDDetectedVideoInputFormatFlags)
+BMDDetectedVideoInputFormatFlags formatFlags)
 {
+struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data;
 ctx->bmd_mode = mode->GetDisplayMode();
+// check the C context member to make sure we set both raw_format and 
bmd_mode with data from the same format change callback
+if (!cctx->raw_format)
+ctx->raw_format = (formatFlags & bmdDetectedVideoInputRGB444) ? 
bmdFormat8BitARGB : bmdFormat8BitYUV;
 return S_OK;
 }
 
@@ -1228,6 +1232,8 @@ av_cold int ff_decklink_read_header(AVFormatContext 
*avctx)
 }
 av_log(avctx, AV_LOG_INFO, "Autodetected the input mode\n");
 }
+if (ctx->raw_format == bmdFormatUnspecified)
+ctx->raw_format = bmdFormat8BitYUV;
 if (ff_decklink_set_format(avctx, DIRECTION_IN) < 0) {
 av_log(avctx, AV_LOG_ERROR, "Could not set format code %s for %s\n",
 cctx->format_code ? cctx->format_code : "(unset)", avctx->url);
diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
index 9f4b32088c..54cd681710 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -33,7 +33,8 @@ static const AVOption options[] = {
 { "list_devices", "list available devices"  , OFFSET(list_devices), 
AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, DEC },
 { "list_formats", "list supported formats"  , OFFSET(list_formats), 
AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, DEC },
 { "format_code",  "set format by fourcc", OFFSET(format_code),  
AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, DEC },
-{ "raw_format",   "pixel format to be returned by the card when capturing" 
, OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = MKBETAG('2','v','u','y')}, 0, 
UINT_MAX, DEC, "raw_format" },
+{ "raw_format",   "pixel format to be returned by the card when capturing" 
, OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = 0}, 0, UINT_MAX, DEC, 
"raw_format" },
+{ "auto",  NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 0   
 }, 0, 0, DEC, "raw_format"},
 { "uyvy422",   NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 
MKBETAG('2','v','u','y') }, 0, 0, DEC, "raw_format"},
 { "yuv422p10", NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 
MKBETAG('v','2','1','0') }, 0, 0, DEC, "raw_format"},
 { "argb",  NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 32  
 }, 0, 0, DEC, "raw_format"},
-- 
2.26.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 2/4] avdevice/decklink_dec: use decklink_ctx->raw_format as bmdPixelFormat

2020-09-08 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavdevice/decklink_common.cpp | 6 +++---
 libavdevice/decklink_dec.cpp| 9 ++---
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 53b57ffe4e..8b58ede1ef 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -272,7 +272,7 @@ int ff_decklink_set_format(AVFormatContext *avctx,
 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b05
 if (direction == DIRECTION_IN) {
 BMDDisplayMode actualMode = ctx->bmd_mode;
-if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, 
(BMDPixelFormat) cctx->raw_format,
+if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, 
ctx->raw_format,
bmdNoVideoInputConversion, 
bmdSupportedVideoModeDefault,
&actualMode, &support) != S_OK || 
!support || ctx->bmd_mode != actualMode)
 return -1;
@@ -286,7 +286,7 @@ int ff_decklink_set_format(AVFormatContext *avctx,
 return 0;
 #elif BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b00
 if (direction == DIRECTION_IN) {
-if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, 
(BMDPixelFormat) cctx->raw_format,
+if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, 
ctx->raw_format,
bmdSupportedVideoModeDefault,
&support) != S_OK)
 return -1;
@@ -303,7 +303,7 @@ int ff_decklink_set_format(AVFormatContext *avctx,
 return 0;
 #else
 if (direction == DIRECTION_IN) {
-if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, (BMDPixelFormat) 
cctx->raw_format,
+if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format,
bmdVideoOutputFlagDefault,
&support, NULL) != S_OK)
 return -1;
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index dde68ffddc..af0ef04c56 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -1148,6 +1148,7 @@ av_cold int ff_decklink_read_header(AVFormatContext 
*avctx)
 ctx->video_pts_source = cctx->video_pts_source;
 ctx->draw_bars = cctx->draw_bars;
 ctx->audio_depth = cctx->audio_depth;
+ctx->raw_format = (BMDPixelFormat)cctx->raw_format;
 cctx->ctx = ctx;
 
 /* Check audio channel option for valid values: 2, 8 or 16 */
@@ -1270,7 +1271,7 @@ av_cold int ff_decklink_read_header(AVFormatContext 
*avctx)
 st->time_base.num  = ctx->bmd_tb_num;
 st->r_frame_rate   = av_make_q(st->time_base.den, st->time_base.num);
 
-switch((BMDPixelFormat)cctx->raw_format) {
+switch(ctx->raw_format) {
 case bmdFormat8BitYUV:
 st->codecpar->codec_id= AV_CODEC_ID_RAWVIDEO;
 st->codecpar->codec_tag   = MKTAG('U', 'Y', 'V', 'Y');
@@ -1303,7 +1304,9 @@ av_cold int ff_decklink_read_header(AVFormatContext 
*avctx)
 st->codecpar->bits_per_coded_sample = 10;
 break;
 default:
-av_log(avctx, AV_LOG_ERROR, "Raw Format %.4s not supported\n", (char*) 
&cctx->raw_format);
+char fourcc_str[AV_FOURCC_MAX_STRING_SIZE] = {0};
+av_fourcc_make_string(fourcc_str, ctx->raw_format);
+av_log(avctx, AV_LOG_ERROR, "Raw Format %s not supported\n", 
fourcc_str);
 ret = AVERROR(EINVAL);
 goto error;
 }
@@ -1364,7 +1367,7 @@ av_cold int ff_decklink_read_header(AVFormatContext 
*avctx)
 }
 
 result = ctx->dli->EnableVideoInput(ctx->bmd_mode,
-(BMDPixelFormat) cctx->raw_format,
+ctx->raw_format,
 bmdVideoInputFlagDefault);
 
 if (result != S_OK) {
-- 
2.26.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".

Re: [FFmpeg-devel] [PATCH] lavc/qsvdec: allow qsv decoders to use initialized device

2020-09-08 Thread Rogozhkin, Dmitry V
On Sun, 2020-09-06 at 15:25 +0100, Mark Thompson wrote:
> On 04/09/2020 19:24, Rogozhkin, Dmitry V wrote:
> > On Thu, 2020-09-03 at 01:02 +, Rogozhkin, Dmitry V wrote:
> > > > 
> > > > (If you do implement it then you can delete all of the ad-hoc
> > > > treatment in ffmpeg, like has been done for the other hardware
> > > > codecs.)
> > > 
> > > I like deleting code:). Ok, this sounds good. Let's try to
> > > understand
> > > what might be missing in the current implementation since I
> > > honestly
> > > don't see any gaps - it just works.
> > 
> > @Mark. We did internal review and believe that DEVICE_CTX path is
> > actually ready to be used and just needs to be activated. Can you,
> > please, let me know how you would like to proceed:
> > 1. We can either consider review and apply the fix first (this
> > patch)
> > then deal with ad_hoc in non-related patch series
> > 2. Or we can go with the bigger patch series right away and address
> > both device_ctx + ad_hoc
> > 
> > 2nd variant might require longer time to verify and review which
> > would
> > hold the fix. What are your thoughts?
> 
> I'm not sure what you have tested, because it definitely doesn't
> work.

I was testing transcode and indeed I overlooked that it falls into
using system memory instead of HW frames. My fault.

> 
> If you return the hardware surface format from get_format() with
> METHOD_HW_DEVICE_CTX then it just ignores you and gives you software
> frames anyway, because it only supports that case with
> METHOD_HW_FRAMES_CTX.

Can you, please, guide me towards what should be implemented/fixed in
qsv path? I afraid that implementing this fully on my own is beyond of
my current knowledge of qsv path in ffmpeg. Some guidance would be
appreciated. Maybe there is implementation for some other accel type I
can refer to?

> 
> For example, with below patch to test it in the hw_decode example:
> 
> $ doc/examples/hw_decode qsv test.264 /dev/null
> Assertion frame->format == AV_PIX_FMT_QSV failed at
> src/doc/examples/hw_decode.c:108
> Aborted
> 
> (It incorrectly returned an NV12 frame.)
> 
> - Mark
> 
> 
> diff --git a/doc/examples/hw_decode.c b/doc/examples/hw_decode.c
> index 71be6e6709..45f401a179 100644
> --- a/doc/examples/hw_decode.c
> +++ b/doc/examples/hw_decode.c
> @@ -105,6 +105,8 @@ static int decode_write(AVCodecContext *avctx,
> AVPacket *packet)
>   goto fail;
>   }
> 
> +av_assert0(frame->format == AV_PIX_FMT_QSV);
> +
>   if (frame->format == hw_pix_fmt) {
>   /* retrieve data from GPU to CPU */
>   if ((ret = av_hwframe_transfer_data(sw_frame, frame,
> 0)) < 0) {
> @@ -191,6 +193,8 @@ int main(int argc, char *argv[])
>   }
>   video_stream = ret;
> 
> +decoder = avcodec_find_decoder_by_name("h264_qsv");
> +
>   for (i = 0;; i++) {
>   const AVCodecHWConfig *config =
> avcodec_get_hw_config(decoder, i);
>   if (!config) {
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index fc25dc73e5..f2fac17354 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -47,7 +47,8 @@ const AVCodecHWConfigInternal *ff_qsv_hw_configs[]
> = {
>   &(const AVCodecHWConfigInternal) {
>   .public = {
>   .pix_fmt = AV_PIX_FMT_QSV,
> -.methods = AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX |
> +.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX |
> +   AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX |
>  AV_CODEC_HW_CONFIG_METHOD_AD_HOC,
>   .device_type = AV_HWDEVICE_TYPE_QSV,
>   },
> ___
> 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] tools/make_chlayout_test: use newer pan syntax.

2020-09-08 Thread Nicolas George
The syntax with : was deprecated and no longer works.

Signed-off-by: Nicolas George 
---
 tools/make_chlayout_test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/make_chlayout_test b/tools/make_chlayout_test
index fcdbda3b73..c310def850 100755
--- a/tools/make_chlayout_test
+++ b/tools/make_chlayout_test
@@ -105,7 +105,7 @@ for my $i (0 .. $#channels) {
   my $descr = $channel_label_to_descr{$label}
 or die "Channel $label not found\n";
   $graph .= "flite=text='${descr}', aformat=channel_layouts=mono, " .
-"pan=${layout}:${label}=c0 [ch$i] ;\n";
+"pan=${layout}|${label}=c0 [ch$i] ;\n";
   $concat_in .= "[ch$i] ";
 }
 $graph .= "${concat_in}concat=v=0:a=1:n=" . scalar(@channels);
-- 
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] Support HDR10+ metadata for HEVC.

2020-09-08 Thread Mohammad Izadi
I will add the test by the end of this week.
Thanks,
Mohammad


On Mon, Sep 7, 2020 at 2:56 AM Jan Ekström  wrote:

> On Sat, Jul 25, 2020 at 12:09 AM Mohammad Izadi
>  wrote:
> >
> > On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
> > andreas.rheinha...@gmail.com> wrote:
> >
> > > 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.
> > > > ---
> > > >  libavcodec/avpacket.c |   1 +
> > > >  libavcodec/decode.c   |   1 +
> > > >  libavcodec/hevc_sei.c |  39 ++---
> > > >  libavcodec/hevc_sei.h |   5 ++
> > > >  libavcodec/hevcdec.c  |  16 
> > > >  libavcodec/internal.h |   9 +++
> > > >  libavcodec/packet.h   |   8 ++
> > > >  libavcodec/utils.c| 180
> ++
> > > >  libavcodec/version.h  |   2 +-
> > > >  9 files changed, 248 insertions(+), 13 deletions(-)
> > > >
> > > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > > > index dce26cb31a..8307032335 <(830)%20703-2335> <(830)%20703-2335>
> 100644
> > > > --- a/libavcodec/avpacket.c
> > > > +++ b/libavcodec/avpacket.c
> > > > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> > > AVPacketSideDataType type)
> > > >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content
> light
> > > level metadata";
> > > >  case AV_PKT_DATA_SPHERICAL:  return "Spherical
> > > Mapping";
> > > >  case AV_PKT_DATA_A53_CC: return "A53 Closed
> > > Captions";
> > > > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+
> Dynamic
> > > Metadata (SMPTE 2094-40)";
> > > >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption
> > > initialization data";
> > > >  case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption
> > > info";
> > > >  case AV_PKT_DATA_AFD:return "Active
> Format
> > > Description data";
> > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > > > index de9c079f9d..cd3286f7fb 100644
> > > > --- a/libavcodec/decode.c
> > > > +++ b/libavcodec/decode.c
> > > > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext
> *avctx,
> > > AVFrame *frame)
> > > >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> > > AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> > > >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> > > AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> > > >  { AV_PKT_DATA_A53_CC,
>  AV_FRAME_DATA_A53_CC
> > > },
> > > > +{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,
> > >  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> > > >  { AV_PKT_DATA_ICC_PROFILE,
> > > AV_FRAME_DATA_ICC_PROFILE },
> > > >  };
> > > >
> > > > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > > > index a4ec65dc1a..a490e752dd 100644
> > > > --- a/libavcodec/hevc_sei.c
> > > > +++ b/libavcodec/hevc_sei.c
> > > > @@ -25,6 +25,7 @@
> > > >  #include "golomb.h"
> > > >  #include "hevc_ps.h"
> > > >  #include "hevc_sei.h"
> > > > +#include "internal.h"
> > > >
> > > >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash
> *s,
> > > GetBitContext *gb)
> > > >  {
> > > > @@ -242,8 +243,8 @@ static int
> > > decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
> > > >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> > > GetBitContext *gb,
> > > >   int size)
> > > >  {
> > > > -uint32_t country_code;
> > > > -uint32_t user_identifier;
> > > > +uint8_t country_code;
> > > > +uint16_t provider_code;
> > > >
> > > >  if (size < 7)
> > > >  return AVERROR(EINVAL);
> > > > @@ -255,18 +256,31 @@ static int
> > > decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
> > > >  size--;
> > > >  }
> > > >
> > > > -skip_bits(gb, 8);
> > > > -skip_bits(gb, 8);
> > > > -
> > > > -user_identifier = get_bits_long(gb, 32);
> > > > -
> > > > -switch (user_identifier) {
> > > > -case MKBETAG('G', 'A', '9', '4'):
> > > > +provider_code = get_bits(gb, 16);
> > > > +
> > > > +const uint8_t usa_country_code = 0xB5;
> > > > +const uint16_t smpte_provider_code = 0x003C;
> > > > +if (country_code == usa_country_code &&
> > > > +provider_code == smpte_provider_code) {
> > > > +// A/341 Amendment – 2094-40
> > > > +uint16_t provider_oriented_code = get_bits(gb, 16);
> > > > +uint8_t application_identifier = get_bits(gb, 8);
> > > > +const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> > > > +const uint16_t smpte2094_40_application_identifier = 0x04;
> > > > +if (provider_oriented_code ==
> > > smpte2094_40_provider_oriented_code &&
> > > > +application_identifier ==
> > > smpte2094_40_application_identi

Re: [FFmpeg-devel] Request for immediate take of action

2020-09-08 Thread Nicolas George
Jean-Baptiste Kempf (12020-09-08):
> I think the explanation is quite aggressive and has absolutely nothing
> to do inside a git log, to be honest.
> 
> The fact that you disagree on the commit is fine, but being passive
> aggressive on a commit log is not OK, in my humble opinion. Especially
> when it will be in the history forever, and cannot be removed.

I can agree with that. I do not perceive what I have written to be
passive aggressive; if it is, it is the least to express the reasons for
the revert.

And yes, I will admit without dissimulation my frustration with Paul's
attitude towards me and towards other people in the project. Not taking
them into account would be tantamount to validating them. If it tainted
the wording of the commit message, then I am to blame, but so are Paul
and everybody who let him do much worse for a long time.

> Moreover, a revert should go through the mailing list like normal
> patches, and that's again, my opinion.

Under ideal circumstances, I would agree, but these are not normal
circumstances. But these are not normal circumstances, this commit was
pushed without review (I was about to review it when I noticed it has
already been pushed), by somebody who repeatedly threatens to abuse
their commit rights to push without approval, but will gladly leverage
rules we have in place to protect themselves.

Under these circumstances, an immediate revert was the only viable path.
This commit is harmful, it takes us farther from a proper implementation
of the movie source and would have delayed proper work on it. Despite
your remark, I still consider an immediate revert was the best choice.

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] Request for immediate take of action

2020-09-08 Thread Jean-Baptiste Kempf
On Tue, 8 Sep 2020, at 15:17, Nicolas George wrote:
> Paul B Mahol (12020-09-08):
> > Nicolas George reverted one of my reviewed commits without proper
> > explanation why it is faulty.
> 
> The explanation is in the commit message, and your patch was not
> reviewed and you should never have pushed it in the first place.

I think the explanation is quite aggressive and has absolutely nothing to do 
inside a git log, to be honest.

The fact that you disagree on the commit is fine, but being passive aggressive 
on a commit log is not OK, in my humble opinion. Especially when it will be in 
the history forever, and cannot be removed.

Moreover, a revert should go through the mailing list like normal patches, and 
that's again, my opinion.

Best,

--
Jean-Baptiste Kempf -  President
+33 672 704 734
 

___
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] examples/decode_video: flush parser to fix missing frame

2020-09-08 Thread Zhao Zhili
Please help review the patch, thanks.

> On Aug 18, 2020, at 7:59 PM, quinkbl...@foxmail.com wrote:
> 
> From: Zhao Zhili 
> 
> To reproduce, run decode_video with a single frame sample. No frame
> was decoded before the patch.
> ---
> doc/examples/decode_video.c | 12 +++-
> 1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
> index 169188a4b9..ba753c6dc1 100644
> --- a/doc/examples/decode_video.c
> +++ b/doc/examples/decode_video.c
> @@ -92,6 +92,7 @@ int main(int argc, char **argv)
> uint8_t *data;
> size_t   data_size;
> int ret;
> +int eof;
> AVPacket *pkt;
> 
> if (argc <= 2) {
> @@ -150,15 +151,14 @@ int main(int argc, char **argv)
> exit(1);
> }
> 
> -while (!feof(f)) {
> +do {
> /* read raw data from the input file */
> data_size = fread(inbuf, 1, INBUF_SIZE, f);
> -if (!data_size)
> -break;
> +eof = !data_size;
> 
> /* use the parser to split the data into frames */
> data = inbuf;
> -while (data_size > 0) {
> +while (data_size > 0 || eof) {
> ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size,
>data, data_size, AV_NOPTS_VALUE, 
> AV_NOPTS_VALUE, 0);
> if (ret < 0) {
> @@ -170,8 +170,10 @@ int main(int argc, char **argv)
> 
> if (pkt->size)
> decode(c, frame, pkt, outfilename);
> +if (eof)
> +break;
> }
> -}
> +} while (!eof);
> 
> /* flush the decoder */
> decode(c, frame, NULL, outfilename);
> -- 
> 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 v2 2/2] avformat/rtsp: fix parse_rtsp_message

2020-09-08 Thread Zhao Zhili
1. Remove the assumption that the message method is TEARDOWN.
2. Don't ignore the error code of ff_rtsp_parse_streaming_commands.
---
 libavformat/rtsp.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 597413803f..3e69ab7287 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1964,11 +1964,7 @@ static int parse_rtsp_message(AVFormatContext *s)
 
 if (rt->rtsp_flags & RTSP_FLAG_LISTEN) {
 if (rt->state == RTSP_STATE_STREAMING) {
-if (!ff_rtsp_parse_streaming_commands(s))
-return AVERROR_EOF;
-else
-av_log(s, AV_LOG_WARNING,
-   "Unable to answer to TEARDOWN\n");
+return ff_rtsp_parse_streaming_commands(s);
 } else
 return 0;
 } else {
-- 
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 v2 1/2] avformat/rtsp: fix infinite loop with udp transport

2020-09-08 Thread Zhao Zhili
sender:
./ffmpeg -i test.mp4 -c copy -f rtsp -rtsp_transport udp  
rtsp://localhost:12345/live.sdp

receiver:
./ffmpeg_g -y -rtsp_flags listen -timeout 100 -i 
rtsp://localhost:12345/live.sdp -c copy test.mp4
---
 libavformat/rtsp.c| 2 ++
 libavformat/rtsp.h| 1 +
 libavformat/rtspdec.c | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5d8491b74b..597413803f 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2051,6 +2051,8 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream 
**prtsp_st,
 if ((ret = parse_rtsp_message(s)) < 0) {
 return ret;
 }
+if (rt->state == RTSP_STATE_TEARDOWN)
+return AVERROR_EOF;
 }
 #endif
 } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 54a9a30c16..481cc0c3ce 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -198,6 +198,7 @@ enum RTSPClientState {
 RTSP_STATE_STREAMING, /**< initialized and sending/receiving data */
 RTSP_STATE_PAUSED,  /**< initialized, but not receiving data */
 RTSP_STATE_SEEKING, /**< initialized, requesting a seek */
+RTSP_STATE_TEARDOWN,/**< initialized, in teardown state */
 };
 
 /**
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index dfa29913bf..ec786a469a 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -494,7 +494,7 @@ int ff_rtsp_parse_streaming_commands(AVFormatContext *s)
   "Public: ANNOUNCE, PAUSE, SETUP, TEARDOWN, "
   "RECORD\r\n", request.seq);
 } else if (methodcode == TEARDOWN) {
-rt->state = RTSP_STATE_IDLE;
+rt->state = RTSP_STATE_TEARDOWN;
 ret   = rtsp_send_reply(s, RTSP_STATUS_OK, NULL , request.seq);
 }
 return ret;
-- 
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 v3 3/4] lavfi: check the validity of formats lists.

2020-09-08 Thread Andreas Rheinhardt
Nicolas George:
> Moritz Barsnick (12020-08-28):
>> "case" indentation is too large.
> 
> Thanks.
> 
> Fixed, rebased and series pushed.
> 
> Regards,
> 
> 
Seems like this patchset broke compilation with some old versions of
GCC. See
http://fate.ffmpeg.org/history.cgi?slot=x86_64-openbsd5.6-gcc4.2-conf2
and http://fate.ffmpeg.org/history.cgi?slot=x86_64-openbsd5.6-gcc4.2. I
don't get why providing the typedef for AVFilterChannelLayouts in
avfilter.h is bad, but doing the same for AVFilterFormats is not.

- 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] libavcodec/options_table: Add missing colorspace options

2020-09-08 Thread Harry Mallon


> On 8 Sep 2020, at 14:29, Gyan Doshi  wrote:
> 
> On 08-09-2020 06:23 pm, Harry Mallon wrote:
>> 
>> 
>>> On 8 Sep 2020, at 13:08, Gyan Doshi  wrote:
>>> 
>>> Hi Harry,
>>> 
>>> On 06-09-2020 04:24 pm, Gyan Doshi wrote:
 
 On 06-09-2020 02:59 pm, Harry Mallon wrote:
> Is there anything I need to do to move this forwards? I think it is 
> relatively uncontroversial?
 Agreed. Will push in 3 days if there are no objections.
>>> Can you link to some doc references for the entries you added?
>>> 
>> I'm not 100% sure what you mean, do you mean add some links to the 
>> doc/codecs.texi file, or just for the mailing list? ICtCp is definitely in 
>> ITU-R Rec 2100, I'm not sure about the others. It just seemed to me that 
>> they were missing from the command line arguments (and I needed to manually 
>> set ICtCp for something).
> 
> For the ML, at present. Ideally, the canonical standard docs. Avoid 
> Wikipedia, forum posts..etc
> 

Well ICtCp (which is the one I am interested in) is in ITU-R BT.2100 
https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf
I am not sure where the chroma-derived ones come from. They are all already 
supported in ffmpeg 
(https://github.com/FFmpeg/FFmpeg/commit/f3571048669bf876681499f49e9df492f05f73c6),
 just they were missing from this specific command line option.

Best,
Harry

___
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] libavcodec/options_table: Add missing colorspace options

2020-09-08 Thread Gyan Doshi



On 08-09-2020 06:23 pm, Harry Mallon wrote:




On 8 Sep 2020, at 13:08, Gyan Doshi  wrote:

Hi Harry,

On 06-09-2020 04:24 pm, Gyan Doshi wrote:


On 06-09-2020 02:59 pm, Harry Mallon wrote:

Is there anything I need to do to move this forwards? I think it is relatively 
uncontroversial?

Agreed. Will push in 3 days if there are no objections.

Can you link to some doc references for the entries you added?


I'm not 100% sure what you mean, do you mean add some links to the 
doc/codecs.texi file, or just for the mailing list? ICtCp is definitely in 
ITU-R Rec 2100, I'm not sure about the others. It just seemed to me that they 
were missing from the command line arguments (and I needed to manually set 
ICtCp for something).


For the ML, at present. Ideally, the canonical standard docs. Avoid 
Wikipedia, forum posts..etc


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

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

Re: [FFmpeg-devel] Request for immediate take of action

2020-09-08 Thread Nicolas George
Paul B Mahol (12020-09-08):
> It was reviewed on IRC. Nobody complained about it.

Show the relevant excerpt of log. Non-trivial reviews should happen on
the mailing-list anyway.

> The explanation in commit log is very cryptic.

I do not owe you my time. All the information is there. Ask specific
question if you want help understanding it.

> Are you saying that switch to .activate API for src_movie filter
> is not possible at all at current time?

It is possible. Just more complicated than you did, and for a result
that should be simpler than the current code.

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] Request for immediate take of action

2020-09-08 Thread Paul B Mahol
On Tue, Sep 08, 2020 at 03:17:15PM +0200, Nicolas George wrote:
> Paul B Mahol (12020-09-08):
> > Nicolas George reverted one of my reviewed commits without proper
> > explanation why it is faulty.
> 
> The explanation is in the commit message, and your patch was not
> reviewed and you should never have pushed it in the first place.

It was reviewed on IRC. Nobody complained about it.

The explanation in commit log is very cryptic.

Are you saying that switch to .activate API for src_movie filter
is not possible at all at current time?

In my testing I have not encountered any issues.
What issue(s) my patch have?
___
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 v4 1/2] libavcodec/webp: add support for animated WebP decoding

2020-09-08 Thread Moritz Barsnick
On Fri, Sep 04, 2020 at 00:59:46 +0200, Lynne wrote:
> > Fixes: 4907
> >
> > Adds support for decoding of animated WebP.

> Sorry it took me so long to get to this.
> Took a look and the patch looks fine to me.
> Will apply in a few days unless someone else has comments or I find something 
> I
> missed. Its not a small patch after all.

Missing version bumps. And perhaps an explanation why fate changed.
(Can be here, not in the commit message, if obvious. Was WebP
previously set to 10 fps by default?)

Moritz
___
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] Request for immediate take of action

2020-09-08 Thread Nicolas George
Paul B Mahol (12020-09-08):
> Nicolas George reverted one of my reviewed commits without proper
> explanation why it is faulty.

The explanation is in the commit message, and your patch was not
reviewed and you should never have pushed it in the first place.

-- 
  Nicolas George


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

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

[FFmpeg-devel] Request for immediate take of action

2020-09-08 Thread Paul B Mahol
Hi,

Nicolas George reverted one of my reviewed commits without proper explanation 
why it
is faulty.

I kindly ask Nicolas George to review this patch
and explain what is wrong with it.

If not, I will be forced to either revert this revert or take more
actions to Technical Committee.

Regards.
___
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] lavfi/vsrc_testsrc: switch to activate.

2020-09-08 Thread Nicolas George
Paul B Mahol (12020-07-07):
> Why this was never applied?

I don't know. Did you bother to review it?

-- 
  Nicolas George


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

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

  1   2   >