Re: [FFmpeg-devel] [PATCH 1/3] avformat/matroskadec: Beautify matroska_parse_laces()

2020-05-25 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libavformat/matroskadec.c | 27 +++
>>  1 file changed, 11 insertions(+), 16 deletions(-)
>>
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index 4fa32365c3..c02c2561c1 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -3035,9 +3035,9 @@ static int matroska_parse_laces(MatroskaDemuxContext 
>> *matroska, uint8_t **buf,
>>  if (size <= 0)
>>  return AVERROR_INVALIDDATA;
>>  
>> -*laces= *data + 1;
>> -data += 1;
>> -size -= 1;
>> +*laces = *data + 1;
>> +data  += 1;
>> +size  -= 1;
>>  
>>  switch (type) {
>>  case 0x1: /* Xiph lacing */
>> @@ -3047,31 +3047,26 @@ static int matroska_parse_laces(MatroskaDemuxContext 
>> *matroska, uint8_t **buf,
>>  for (n = 0; n < *laces - 1; n++) {
>>  lace_size[n] = 0;
>>  
>> -while (1) {
>> -if (size <= total) {
>> +do {
>> +if (size <= total)
>>  return AVERROR_INVALIDDATA;
>> -}
>>  temp  = *data;
>>  total+= temp;
>>  lace_size[n] += temp;
>>  data += 1;
>>  size -= 1;
>> -if (temp != 0xff)
>> -break;
>> -}
>> +} while (temp ==  0xff);
>>  }
>> -if (size < total) {
>> +if (size < total)
>>  return AVERROR_INVALIDDATA;
>> -}
>>  
>>  lace_size[n] = size - total;
>>  break;
>>  }
>>  
>>  case 0x2: /* fixed-size lacing */
>> -if (size % (*laces)) {
>> +if (size % (*laces))
>>  return AVERROR_INVALIDDATA;
>> -}
>>  for (n = 0; n < *laces; n++)
>>  lace_size[n] = size / *laces;
>>  break;
>> @@ -3107,15 +3102,15 @@ static int matroska_parse_laces(MatroskaDemuxContext 
>> *matroska, uint8_t **buf,
>>  }
>>  data += offset;
>>  size -= offset;
>> -if (size < total) {
>> +if (size < total)
>>  return AVERROR_INVALIDDATA;
>> -}
>> +
>>  lace_size[*laces - 1] = size - total;
>>  break;
>>  }
>>  }
>>  
>> -*buf  = data;
>> +*buf = data;
>>  
>>  return 0;
>>  }
>>
> Will apply the rest of this patchset tomorrow if there are no objections.
> 
> - Andreas
> 
Applied.

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

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

[FFmpeg-devel] [PATCH 1/2] dnn: add openvino as one of dnn backend

2020-05-25 Thread Guo, Yejun
OpenVINO is a Deep Learning Deployment Toolkit at
https://github.com/openvinotoolkit/openvino, it supports CPU, GPU
and heterogeneous plugins to accelerate deep learning inferencing.

Please refer to 
https://github.com/openvinotoolkit/openvino/blob/master/build-instruction.md
to build openvino (c library is built at the same time). Please add
option -DENABLE_MKL_DNN=ON for cmake to enable CPU path. The header
files and libraries are installed to 
/usr/local/deployment_tools/inference_engine/
with default options on my system.

To build FFmpeg with openvion, take my system as an example, run with:
$ ../ffmpeg/configure --enable-libopenvino 
--extra-cflags=-I/usr/local/deployment_tools/inference_engine/include/ 
--extra-ldflags=-L/usr/local/deployment_tools/inference_engine/lib/intel64
$ make

As dnn module maintainer, I do want to see it is utilized by customers,
so the dnn module can be improved on the right direction with 
developers/customers
collaboration, but I seldomly receive feedbacks.

On the other hand, I know that there are video analytics projects
accepted by customers based on FFmpeg + openvino, see more detail
at https://github.com/VCDP/FFmpeg-patch, but the code bypasses the
dnn interface layer and could not be upstreamed directly.

So, I introduce openvino as one of the dnn backend as a preparation
for later usage.

Signed-off-by: Guo, Yejun 
---
 configure  |   6 +-
 libavfilter/dnn/Makefile   |   1 +
 libavfilter/dnn/dnn_backend_openvino.c | 261 +
 libavfilter/dnn/dnn_backend_openvino.h |  38 +
 libavfilter/dnn/dnn_interface.c|  11 ++
 libavfilter/dnn_interface.h|   2 +-
 6 files changed, 317 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/dnn/dnn_backend_openvino.c
 create mode 100644 libavfilter/dnn/dnn_backend_openvino.h

diff --git a/configure b/configure
index f97cad0..6a50351 100755
--- a/configure
+++ b/configure
@@ -253,6 +253,8 @@ External library support:
   --enable-libopenh264 enable H.264 encoding via OpenH264 [no]
   --enable-libopenjpeg enable JPEG 2000 de/encoding via OpenJPEG [no]
   --enable-libopenmpt  enable decoding tracked files via libopenmpt [no]
+  --enable-libopenvino enable OpenVINO as a DNN module backend
+   for DNN based filters like dnn_processing [no]
   --enable-libopus enable Opus de/encoding via libopus [no]
   --enable-libpulseenable Pulseaudio input via libpulse [no]
   --enable-librabbitmq enable RabbitMQ library [no]
@@ -1790,6 +1792,7 @@ EXTERNAL_LIBRARY_LIST="
 libopenh264
 libopenjpeg
 libopenmpt
+libopenvino
 libopus
 libpulse
 librabbitmq
@@ -2620,7 +2623,7 @@ cbs_mpeg2_select="cbs"
 cbs_vp9_select="cbs"
 dct_select="rdft"
 dirac_parse_select="golomb"
-dnn_suggest="libtensorflow"
+dnn_suggest="libtensorflow libopenvino"
 error_resilience_select="me_cmp"
 faandct_deps="faan"
 faandct_select="fdctdsp"
@@ -6346,6 +6349,7 @@ enabled libopenh264   && require_pkg_config 
libopenh264 openh264 wels/codec_
 enabled libopenjpeg   && { check_pkg_config libopenjpeg "libopenjp2 >= 
2.1.0" openjpeg.h opj_version ||
{ require_pkg_config libopenjpeg "libopenjp2 >= 
2.1.0" openjpeg.h opj_version -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } }
 enabled libopenmpt&& require_pkg_config libopenmpt "libopenmpt >= 
0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create -lstdc++ && append 
libopenmpt_extralibs "-lstdc++"
+enabled libopenvino   && require libopenvino c_api/ie_c_api.h 
ie_c_api_version -linference_engine_c_api
 enabled libopus   && {
 enabled libopus_decoder && {
 require_pkg_config libopus opus opus_multistream.h 
opus_multistream_decoder_create
diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index ce52958..a4900f6 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -8,5 +8,6 @@ OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_max
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_mathbinary.o
 
 DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
+DNN-OBJS-$(CONFIG_LIBOPENVINO)   += dnn/dnn_backend_openvino.o
 
 OBJS-$(CONFIG_DNN)   += $(DNN-OBJS-yes)
diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
new file mode 100644
index 000..f048bc2
--- /dev/null
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2020
+ *
+ * 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 

[FFmpeg-devel] [PATCH 2/2] vf_dnn_processing.c: add dnn backend openvino

2020-05-25 Thread Guo, Yejun
We can try with the srcnn model from sr filter.
1) get srcnn.pb model file, see filter sr
2) convert srcnn.pb into openvino model with command:
python mo_tf.py --input_model srcnn.pb --data_type=FP32 --input_shape 
[1,960,1440,1] --keep_shape_ops

See the script at 
https://github.com/openvinotoolkit/openvino/tree/master/model-optimizer
We'll see srcnn.xml and srcnn.bin at current path, copy them to the
directory where ffmpeg is.

I have also uploaded the model files at 
https://github.com/guoyejun/dnn_processing/tree/master/models

3) run with openvino backend:
ffmpeg -i input.jpg -vf 
format=yuv420p,scale=w=iw*2:h=ih*2,dnn_processing=dnn_backend=openvino:model=srcnn.xml:input=x:output=srcnn/Maximum
 -y srcnn.ov.jpg
(The input.jpg resolution is 720*480)

Signed-off-by: Guo, Yejun 
---
 doc/filters.texi| 10 +-
 libavfilter/vf_dnn_processing.c |  5 -
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 85a511b..b64a4a7 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9260,13 +9260,21 @@ TensorFlow backend. To enable this backend you
 need to install the TensorFlow for C library (see
 @url{https://www.tensorflow.org/install/install_c}) and configure FFmpeg with
 @code{--enable-libtensorflow}
+
+@item openvino
+OpenVINO backend. To enable this backend you
+need to build and install the OpenVINO for C library (see
+@url{https://github.com/openvinotoolkit/openvino/blob/master/build-instruction.md})
 and configure FFmpeg with
+@code{--enable-libopenvino} (--extra-cflags=-I... --extra-ldflags=-L... might
+be needed if the header files and libraries are not installed into system path)
+
 @end table
 
 Default value is @samp{native}.
 
 @item model
 Set path to model file specifying network architecture and its parameters.
-Note that different backends use different file formats. TensorFlow and native
+Note that different backends use different file formats. TensorFlow, OpenVINO 
and native
 backend can load files for only its format.
 
 Native model file (.model) can be generated from TensorFlow model file (.pb) 
by using tools/python/convert.py
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index cf589ac..4b31808 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -58,11 +58,14 @@ typedef struct DnnProcessingContext {
 #define OFFSET(x) offsetof(DnnProcessingContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption dnn_processing_options[] = {
-{ "dnn_backend", "DNN backend",OFFSET(backend_type), 
AV_OPT_TYPE_INT,   { .i64 = 0 },0, 1, FLAGS, "backend" },
+{ "dnn_backend", "DNN backend",OFFSET(backend_type), 
AV_OPT_TYPE_INT,   { .i64 = 0 },INT_MIN, INT_MAX, FLAGS, "backend" },
 { "native",  "native backend flag",0,
AV_OPT_TYPE_CONST, { .i64 = 0 },0, 0, FLAGS, "backend" },
 #if (CONFIG_LIBTENSORFLOW == 1)
 { "tensorflow",  "tensorflow backend flag",0,
AV_OPT_TYPE_CONST, { .i64 = 1 },0, 0, FLAGS, "backend" },
 #endif
+#if (CONFIG_LIBOPENVINO == 1)
+{ "openvino","openvino backend flag",  0,
AV_OPT_TYPE_CONST, { .i64 = 2 },0, 0, FLAGS, "backend" },
+#endif
 { "model",   "path to model file", OFFSET(model_filename),   
AV_OPT_TYPE_STRING,{ .str = NULL }, 0, 0, FLAGS },
 { "input",   "input name of the model",OFFSET(model_inputname),  
AV_OPT_TYPE_STRING,{ .str = NULL }, 0, 0, FLAGS },
 { "output",  "output name of the model",   OFFSET(model_outputname), 
AV_OPT_TYPE_STRING,{ .str = NULL }, 0, 0, FLAGS },
-- 
2.7.4

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

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

Re: [FFmpeg-devel] [PATCH 1/2] avformat/oggparsevorbis: Error out on double init of vp

2020-05-25 Thread Michael Niedermayer
On Sun, Apr 19, 2020 at 05:05:52PM +0200, Michael Niedermayer wrote:
> Fixes: memleak
> Fixes: 
> 19949/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5743636058210304
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/oggparsevorbis.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

will apply

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

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


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

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

Re: [FFmpeg-devel] [PATCH 3/3] lavf/dashdec: avoid reading the first data segment in read_header

2020-05-25 Thread Ridley Combs


> On May 25, 2020, at 08:43, Gorilla Maguila  wrote:
> 
> These lines:
> 
> +if (pls->init_sec_data_len > 0)
> +pls->ctx->probesize = FFMIN(pls->ctx->probesize,
> pls->init_sec_data_len);
> pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ?
> s->max_analyze_duration : 4 * AV_TIME_BASE;
> -ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0, 0);
> +ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0,
> pls->ctx->probesize);
> 
> 
> cause an Error in av_probe_input_buffer when pls->init_sec_data_len
> or pls->ctx->probesize are < 2048 due to the following line in
> av_probe_input_buffer:
> 
> https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/format.c#L236

Apply the patch series in the order it was sent: 
http://ffmpeg.org/pipermail/ffmpeg-devel/2020-May/263099.html 

> 
> El vie., 22 may. 2020 a las 9:22, Steven Liu ()
> escribió:
> 
>> 
>> 
>>> 2020年5月22日 下午1:42,rcombs  写道:
>>> 
>>> This reduces the number of requests that have to be made during startup.
>>> ---
>>> libavformat/dashdec.c | 41 ++---
>>> 1 file changed, 26 insertions(+), 15 deletions(-)
>>> 
>>> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
>>> index ec2aadcee3..1bd070c7cb 100644
>>> --- a/libavformat/dashdec.c
>>> +++ b/libavformat/dashdec.c
>>> @@ -1798,6 +1798,19 @@ static int read_data(void *opaque, uint8_t *buf,
>> int buf_size)
>>>DASHContext *c = v->parent->priv_data;
>>> 
>>> restart:
>>> +/* load/update Media Initialization Section, if any */
>>> +if ((ret = update_init_section(v)) < 0)
>>> +goto end;
>>> +
>>> +if (v->init_sec_buf_read_offset < v->init_sec_data_len) {
>>> +/* Push init section out first before first actual fragment */
>>> +int copy_size = FFMIN(v->init_sec_data_len -
>> v->init_sec_buf_read_offset, buf_size);
>>> +memcpy(buf, v->init_sec_buf, copy_size);
>>> +v->init_sec_buf_read_offset += copy_size;
>>> +ret = copy_size;
>>> +goto end;
>>> +}
>>> +
>>>if (!v->input) {
>>>free_fragment(>cur_seg);
>>>v->cur_seg = get_current_fragment(v);
>>> @@ -1806,11 +1819,6 @@ restart:
>>>goto end;
>>>}
>>> 
>>> -/* load/update Media Initialization Section, if any */
>>> -ret = update_init_section(v);
>>> -if (ret)
>>> -goto end;
>>> -
>>>ret = open_input(c, v, v->cur_seg);
>>>if (ret < 0) {
>>>if (ff_check_interrupt(c->interrupt_callback)) {
>>> @@ -1823,15 +1831,6 @@ restart:
>>>}
>>>}
>>> 
>>> -if (v->init_sec_buf_read_offset < v->init_sec_data_len) {
>>> -/* Push init section out first before first actual fragment */
>>> -int copy_size = FFMIN(v->init_sec_data_len -
>> v->init_sec_buf_read_offset, buf_size);
>>> -memcpy(buf, v->init_sec_buf, copy_size);
>>> -v->init_sec_buf_read_offset += copy_size;
>>> -ret = copy_size;
>>> -goto end;
>>> -}
>>> -
>>>/* check the v->cur_seg, if it is null, get current and double check
>> if the new v->cur_seg*/
>>>if (!v->cur_seg) {
>>>v->cur_seg = get_current_fragment(v);
>>> @@ -1940,10 +1939,19 @@ static int
>> reopen_demux_for_component(AVFormatContext *s, struct representation
>>>if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
>>>goto fail;
>>> 
>>> +
>>> +if (pls->init_sec_data_len <= 0) {
>>> +/* load/update Media Initialization Section, if any */
>>> +if ((ret = update_init_section(pls)) < 0)
>>> +goto fail;
>>> +}
>>> +
>>>pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO;
>>>pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
>>> +if (pls->init_sec_data_len > 0)
>>> +pls->ctx->probesize = FFMIN(pls->ctx->probesize,
>> pls->init_sec_data_len);
>>>pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ?
>> s->max_analyze_duration : 4 * AV_TIME_BASE;
>>> -ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0, 0);
>>> +ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0,
>> pls->ctx->probesize);
>>>if (ret < 0) {
>>>av_log(s, AV_LOG_ERROR, "Error when loading first fragment,
>> playlist %d\n", (int)pls->rep_idx);
>>>avformat_free_context(pls->ctx);
>>> @@ -1954,6 +1962,9 @@ static int
>> reopen_demux_for_component(AVFormatContext *s, struct representation
>>>pls->ctx->pb = >pb;
>>>pls->ctx->io_open  = nested_io_open;
>>> 
>>> +if (pls->init_sec_data_len > 0)
>>> +av_dict_set_int(_fmt_opts, "header_size",
>> pls->init_sec_data_len, 0);
>>> +
>>>// provide additional information from mpd if available
>>>ret = avformat_open_input(>ctx, "", in_fmt, _fmt_opts);
>> //pls->init_section->url
>>>av_dict_free(_fmt_opts);
>>> --
>>> 2.26.2
>>> 
>>> ___
>>> ffmpeg-devel mailing list
>>> 

Re: [FFmpeg-devel] [PATCH v3] avcodec/v4l2_m2m_dec: Remove redundant packet and fix double free

2020-05-25 Thread Andriy Gelman
On Sat, 16. May 11:53, Andriy Gelman wrote:
> On Sat, 09. May 13:35, Andriy Gelman wrote:
> > From: Andriy Gelman 
> > 
> > v4l2_receive_frame() uses two packets s->buf_pkt and avpkt. If avpkt
> > cannot be enqueued, the packet is buffered in s->buf_pkt and enqueued in
> > the next call. Currently the ownership transfer between the two packets
> > is not properly handled. A double free occurs if
> > ff_v4l2_context_enqueue_packet() returns EAGAIN and v4l2_try_start
> > returns EINVAL.
> > 
> > In fact, having two AVPackets is not needed and everything can be
> > handled by s->buf_pkt.
> > 
> > This commit removes the local avpkt from v4l2_receive_frame(), meaning
> > that the ownership transfer doesn't need to be handled and the double
> > free is fixed.
> > 
> > Signed-off-by: Andriy Gelman 
> > ---
> > 
> > Sorry, forgot to squash the commit from v1 so v2 didn't apply. This is 
> > correct version.
> > 
> > Supersedes:
> > https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200505055454.28683-1-andriy.gel...@gmail.com/
> > 
> > 
> >  libavcodec/v4l2_m2m_dec.c | 37 +++--
> >  1 file changed, 15 insertions(+), 22 deletions(-)
> > 
> > diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
> > index 3e17e0fcac..b038efed9c 100644
> > --- a/libavcodec/v4l2_m2m_dec.c
> > +++ b/libavcodec/v4l2_m2m_dec.c
> > @@ -138,14 +138,10 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
> > AVFrame *frame)
> >  V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context;
> >  V4L2Context *const capture = >capture;
> >  V4L2Context *const output = >output;
> > -AVPacket avpkt = {0};
> >  int ret;
> >  
> > -if (s->buf_pkt.size) {
> > -avpkt = s->buf_pkt;
> > -memset(>buf_pkt, 0, sizeof(AVPacket));
> > -} else {
> > -ret = ff_decode_get_packet(avctx, );
> > +if (!s->buf_pkt.size) {
> > +ret = ff_decode_get_packet(avctx, >buf_pkt);
> >  if (ret < 0 && ret != AVERROR_EOF)
> >  return ret;
> >  }
> > @@ -153,32 +149,29 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
> > AVFrame *frame)
> >  if (s->draining)
> >  goto dequeue;
> >  
> > -ret = ff_v4l2_context_enqueue_packet(output, );
> > -if (ret < 0) {
> > -if (ret != AVERROR(EAGAIN))
> > -   return ret;
> > +ret = ff_v4l2_context_enqueue_packet(output, >buf_pkt);
> > +if (ret < 0 && ret != AVERROR(EAGAIN))
> > +goto fail;
> >  
> > -s->buf_pkt = avpkt;
> > -/* no input buffers available, continue dequeing */
> > -}
> > +/* if EAGAIN don't unref packet and try to enqueue in the next 
> > iteration */
> > +if (ret != AVERROR(EAGAIN))
> > +av_packet_unref(>buf_pkt);
> >  
> > -if (avpkt.size) {
> > +if (!s->draining) {
> >  ret = v4l2_try_start(avctx);
> >  if (ret) {
> > -av_packet_unref();
> > -
> >  /* cant recover */
> > -if (ret == AVERROR(ENOMEM))
> > -return ret;
> > -
> > -return 0;
> > +if (ret != AVERROR(ENOMEM))
> > +ret = 0;
> > +goto fail;
> >  }
> >  }
> >  
> >  dequeue:
> > -if (!s->buf_pkt.size)
> > -av_packet_unref();
> >  return ff_v4l2_context_dequeue_frame(capture, frame, -1);
> > +fail:
> > +av_packet_unref(>buf_pkt);
> > +return ret;
> >  }
> >  
> >  static av_cold int v4l2_decode_init(AVCodecContext *avctx)
> > -- 
> > 2.25.1
> > 
> 
> ping
> 

ping

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

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

[FFmpeg-devel] [PATCH 3/4] avformat/hlsenc: Avoid duplicating strings when parsing

2020-05-25 Thread Andreas Rheinhardt
Up until now, the HLS muxer uses av_strtok() to split an input string
controlling parameters of the VariantStreams and then duplicates
parts of this string containing parameters such as the language or the
name of the VariantStream. But these parts are proper zero-terminated
strings of their own that are never modified lateron, so one can simply
use the substring as-is without creating a copy. This commit implements
this.

The same also happened for the string controlling the closed caption
groups.

Furthermore, add const to indicate that the pointers to these substrings
are not used to modify them and also to indicate that these strings are
not allocated on their own.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hlsenc.c | 77 +++-
 1 file changed, 19 insertions(+), 58 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 77e49b44b1..02bd5c3528 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -173,17 +173,17 @@ typedef struct VariantStream {
 unsigned int nb_streams;
 int m3u8_created; /* status of media play-list creation */
 int is_default; /* default status of audio group */
-char *language; /* audio lauguage name */
-char *agroup; /* audio group name */
-char *sgroup; /* subtitle group name */
-char *ccgroup; /* closed caption group name */
-char *varname; // variant name
+const char *language; /* audio lauguage name */
+const char *agroup;   /* audio group name */
+const char *sgroup;   /* subtitle group name */
+const char *ccgroup;  /* closed caption group name */
+const char *varname;  /* variant name */
 } VariantStream;
 
 typedef struct ClosedCaptionsStream {
-char *ccgroup; /* closed caption group name */
-char *instreamid; /* closed captions INSTREAM-ID */
-char *language; /* closed captions langauge */
+const char *ccgroup;/* closed caption group name */
+const char *instreamid; /* closed captions INSTREAM-ID */
+const char *language;   /* closed captions langauge */
 } ClosedCaptionsStream;
 
 typedef struct HLSContext {
@@ -1290,8 +1290,8 @@ static int create_master_playlist(AVFormatContext *s,
 int ret, bandwidth;
 const char *m3u8_rel_name = NULL;
 const char *vtt_m3u8_rel_name = NULL;
-char *ccgroup;
-char *sgroup = NULL;
+const char *ccgroup;
+const char *sgroup = NULL;
 ClosedCaptionsStream *ccs;
 const char *proto = avio_find_protocol_name(hls->master_m3u8_url);
 int is_file_proto = proto && !strcmp(proto, "file");
@@ -1962,10 +1962,7 @@ static int 
parse_variant_stream_mapstring(AVFormatContext *s)
 char *end;
 varstr = NULL;
 if (av_strstart(keyval, "language:", )) {
-av_free(vs->language);
-vs->language = av_strdup(val);
-if (!vs->language)
-return AVERROR(ENOMEM);
+vs->language = val;
 continue;
 } else if (av_strstart(keyval, "default:", )) {
 vs->is_default = (!av_strncasecmp(val, "YES", strlen("YES")) ||
@@ -1973,28 +1970,16 @@ static int 
parse_variant_stream_mapstring(AVFormatContext *s)
 hls->has_default_key = 1;
 continue;
 } else if (av_strstart(keyval, "name:", )) {
-av_free(vs->varname);
-vs->varname = av_strdup(val);
-if (!vs->varname)
-return AVERROR(ENOMEM);
+vs->varname  = val;
 continue;
 } else if (av_strstart(keyval, "agroup:", )) {
-av_free(vs->agroup);
-vs->agroup = av_strdup(val);
-if (!vs->agroup)
-return AVERROR(ENOMEM);
+vs->agroup   = val;
 continue;
 } else if (av_strstart(keyval, "sgroup:", )) {
-av_free(vs->sgroup);
-vs->sgroup = av_strdup(val);
-if (!vs->sgroup)
-return AVERROR(ENOMEM);
+vs->sgroup   = val;
 continue;
 } else if (av_strstart(keyval, "ccgroup:", )) {
-av_free(vs->ccgroup);
-vs->ccgroup = av_strdup(val);
-if (!vs->ccgroup)
-return AVERROR(ENOMEM);
+vs->ccgroup  = val;
 continue;
 } else if (av_strstart(keyval, "v:", )) {
 codec_type = AVMEDIA_TYPE_VIDEO;
@@ -2085,20 +2070,11 @@ static int parse_cc_stream_mapstring(AVFormatContext *s)
 ccstr = NULL;
 
 if (av_strstart(keyval, "ccgroup:", )) {
-av_free(ccs->ccgroup);
-ccs->ccgroup = av_strdup(val);
-if (!ccs->ccgroup)
-return AVERROR(ENOMEM);
+ccs->ccgroup= val;
 } else if (av_strstart(keyval, 

[FFmpeg-devel] [PATCH 2/4] avformat/hlsenc: Don't unnecessarily duplicate baseurl string

2020-05-25 Thread Andreas Rheinhardt
Up until now, the HLS muxer duplicated a string for every VariantStream,
although neither the original nor the copies are ever modified. So use
the original directly and stop copying.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hlsenc.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 1bc3cb210b..77e49b44b1 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -177,7 +177,6 @@ typedef struct VariantStream {
 char *agroup; /* audio group name */
 char *sgroup; /* subtitle group name */
 char *ccgroup; /* closed caption group name */
-char *baseurl;
 char *varname; // variant name
 } VariantStream;
 
@@ -1525,7 +1524,7 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 
 ret = ff_hls_write_file_entry(byterange_mode ? hls->m3u8_out : 
vs->out, en->discont, byterange_mode,
   en->duration, hls->flags & 
HLS_ROUND_DURATIONS,
-  en->size, en->pos, vs->baseurl,
+  en->size, en->pos, hls->baseurl,
   en->filename, prog_date_time_p, 
en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY);
 if (ret < 0) {
 av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n");
@@ -1547,7 +1546,7 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 for (en = vs->segments; en; en = en->next) {
 ret = ff_hls_write_file_entry(hls->sub_m3u8_out, 0, byterange_mode,
   en->duration, 0, en->size, en->pos,
-  vs->baseurl, en->sub_filename, NULL, 
0, 0, 0);
+  hls->baseurl, en->sub_filename, 
NULL, 0, 0, 0);
 if (ret < 0) {
 av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get 
error\n");
 }
@@ -2581,7 +2580,6 @@ static void hls_deinit(AVFormatContext *s)
 av_freep(>sgroup);
 av_freep(>language);
 av_freep(>ccgroup);
-av_freep(>baseurl);
 av_freep(>varname);
 }
 
@@ -2956,12 +2954,6 @@ static int hls_init(AVFormatContext *s)
 *p = '.';
 }
 
-if (hls->baseurl) {
-vs->baseurl = av_strdup(hls->baseurl);
-if (!vs->baseurl)
-return AVERROR(ENOMEM);
-}
-
 if ((ret = hls_mux_init(s, vs)) < 0)
 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 4/4] avformat/hlsenc, hlsplaylist: Cosmetics

2020-05-25 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hlsenc.c  |  5 ++---
 libavformat/hlsplaylist.c | 22 ++
 libavformat/hlsplaylist.h |  9 +
 3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 02bd5c3528..18256cbf91 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2137,9 +2137,8 @@ static int update_variant_stream_info(AVFormatContext *s)
 return AVERROR(ENOMEM);
 
 //by default, the first available ccgroup is mapped to the variant 
stream
-if (hls->nb_ccstreams) {
+if (hls->nb_ccstreams)
 hls->var_streams[0].ccgroup = hls->cc_streams[0].ccgroup;
-}
 
 for (i = 0; i < s->nb_streams; i++)
 hls->var_streams[0].streams[i] = s->streams[i];
@@ -2320,7 +2319,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 vs->start_pts_from_audio = 0;
 }
 
-   if (vs->has_video) {
+if (vs->has_video) {
 can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
 ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & 
HLS_SPLIT_BY_TIME));
 is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && 
(pkt->stream_index == vs->reference_stream_index);
diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c
index 7a89846369..0e1dcc087f 100644
--- a/libavformat/hlsplaylist.c
+++ b/libavformat/hlsplaylist.c
@@ -28,7 +28,8 @@
 #include "avformat.h"
 #include "hlsplaylist.h"
 
-void ff_hls_write_playlist_version(AVIOContext *out, int version) {
+void ff_hls_write_playlist_version(AVIOContext *out, int version)
+{
 if (!out)
 return;
 avio_printf(out, "#EXTM3U\n");
@@ -96,7 +97,8 @@ void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, 
int bandwidth,
 
 void ff_hls_write_playlist_header(AVIOContext *out, int version, int 
allowcache,
   int target_duration, int64_t sequence,
-  uint32_t playlist_type, int iframe_mode) {
+  uint32_t playlist_type, int iframe_mode)
+{
 if (!out)
 return;
 ff_hls_write_playlist_version(out, version);
@@ -118,7 +120,8 @@ void ff_hls_write_playlist_header(AVIOContext *out, int 
version, int allowcache,
 }
 
 void ff_hls_write_init_file(AVIOContext *out, const char *filename,
-int byterange_mode, int64_t size, int64_t pos) {
+int byterange_mode, int64_t size, int64_t pos)
+{
 avio_printf(out, "#EXT-X-MAP:URI=\"%s\"", filename);
 if (byterange_mode) {
 avio_printf(out, ",BYTERANGE=\"%"PRId64"@%"PRId64"\"", size, pos);
@@ -127,12 +130,14 @@ void ff_hls_write_init_file(AVIOContext *out, const char 
*filename,
 }
 
 int ff_hls_write_file_entry(AVIOContext *out, int insert_discont,
- int byterange_mode,
- double duration, int round_duration,
- int64_t size, int64_t pos, //Used only if 
HLS_SINGLE_FILE flag is set
+int byterange_mode, double duration,
+int round_duration, int64_t size,
+int64_t pos /* Used only if HLS_SINGLE_FILE flag 
is set */,
 const char *baseurl /* Ignored if NULL */,
 const char *filename, double *prog_date_time,
- int64_t video_keyframe_size, int64_t 
video_keyframe_pos, int iframe_mode) {
+int64_t video_keyframe_size, int64_t 
video_keyframe_pos,
+int iframe_mode)
+{
 if (!out || !filename)
 return AVERROR(EINVAL);
 
@@ -181,7 +186,8 @@ int ff_hls_write_file_entry(AVIOContext *out, int 
insert_discont,
 return 0;
 }
 
-void ff_hls_write_end_list (AVIOContext *out) {
+void ff_hls_write_end_list(AVIOContext *out)
+{
 if (!out)
 return;
 avio_printf(out, "#EXT-X-ENDLIST\n");
diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h
index 4348a26c75..29487da3ed 100644
--- a/libavformat/hlsplaylist.h
+++ b/libavformat/hlsplaylist.h
@@ -53,12 +53,13 @@ void ff_hls_write_playlist_header(AVIOContext *out, int 
version, int allowcache,
 void ff_hls_write_init_file(AVIOContext *out, const char *filename,
 int byterange_mode, int64_t size, int64_t pos);
 int ff_hls_write_file_entry(AVIOContext *out, int insert_discont,
- int byterange_mode,
- double duration, int round_duration,
- int64_t size, int64_t pos, //Used only if 
HLS_SINGLE_FILE flag is set
+int byterange_mode, double duration,
+int round_duration, int64_t size,
+int64_t pos /* Used only if HLS_SINGLE_FILE flag 
is set */,
 

[FFmpeg-devel] [PATCH 1/4] avformat/hlsplaylist: Add const where appropriate

2020-05-25 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hlsplaylist.c | 27 ---
 libavformat/hlsplaylist.h | 23 +--
 2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c
index 43f9d281ba..7a89846369 100644
--- a/libavformat/hlsplaylist.c
+++ b/libavformat/hlsplaylist.c
@@ -35,8 +35,10 @@ void ff_hls_write_playlist_version(AVIOContext *out, int 
version) {
 avio_printf(out, "#EXT-X-VERSION:%d\n", version);
 }
 
-void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup,
-  const char *filename, char *language, int 
name_id, int is_default) {
+void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup,
+  const char *filename, const char *language,
+  int name_id, int is_default)
+{
 if (!out || !agroup || !filename)
 return;
 
@@ -48,8 +50,10 @@ void ff_hls_write_audio_rendition(AVIOContext *out, char 
*agroup,
 avio_printf(out, "URI=\"%s\"\n", filename);
 }
 
-void ff_hls_write_subtitle_rendition(AVIOContext *out, char *sgroup,
-  const char *filename, char *language, int 
name_id, int is_default) {
+void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup,
+ const char *filename, const char 
*language,
+ int name_id, int is_default)
+{
 if (!out || !filename)
 return;
 
@@ -61,10 +65,11 @@ void ff_hls_write_subtitle_rendition(AVIOContext *out, char 
*sgroup,
 avio_printf(out, "URI=\"%s\"\n", filename);
 }
 
-void ff_hls_write_stream_info(AVStream *st, AVIOContext *out,
-  int bandwidth, const char *filename, char 
*agroup,
-  char *codecs, char *ccgroup, char *sgroup) {
-
+void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth,
+  const char *filename, const char *agroup,
+  const char *codecs, const char *ccgroup,
+  const char *sgroup)
+{
 if (!out || !filename)
 return;
 
@@ -112,7 +117,7 @@ void ff_hls_write_playlist_header(AVIOContext *out, int 
version, int allowcache,
 }
 }
 
-void ff_hls_write_init_file(AVIOContext *out, char *filename,
+void ff_hls_write_init_file(AVIOContext *out, const char *filename,
 int byterange_mode, int64_t size, int64_t pos) {
 avio_printf(out, "#EXT-X-MAP:URI=\"%s\"", filename);
 if (byterange_mode) {
@@ -125,8 +130,8 @@ int ff_hls_write_file_entry(AVIOContext *out, int 
insert_discont,
  int byterange_mode,
  double duration, int round_duration,
  int64_t size, int64_t pos, //Used only if 
HLS_SINGLE_FILE flag is set
- char *baseurl, //Ignored if NULL
- char *filename, double *prog_date_time,
+const char *baseurl /* Ignored if NULL */,
+const char *filename, double *prog_date_time,
  int64_t video_keyframe_size, int64_t 
video_keyframe_pos, int iframe_mode) {
 if (!out || !filename)
 return AVERROR(EINVAL);
diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h
index a124bdcffb..4348a26c75 100644
--- a/libavformat/hlsplaylist.h
+++ b/libavformat/hlsplaylist.h
@@ -37,24 +37,27 @@ typedef enum {
 } PlaylistType;
 
 void ff_hls_write_playlist_version(AVIOContext *out, int version);
-void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup,
-  const char *filename, char *language, int 
name_id, int is_default);
-void ff_hls_write_subtitle_rendition(AVIOContext *out, char *sgroup,
-  const char *filename, char *language, int 
name_id, int is_default);
-void ff_hls_write_stream_info(AVStream *st, AVIOContext *out,
-  int bandwidth, const char *filename, char 
*agroup,
-  char *codecs, char *ccgroup, char *sgroup);
+void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup,
+  const char *filename, const char *language,
+  int name_id, int is_default);
+void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup,
+ const char *filename, const char 
*language,
+ int name_id, int is_default);
+void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth,
+  const char *filename, const char *agroup,
+  const char *codecs, const char *ccgroup,
+  const char *sgroup);
 void 

Re: [FFmpeg-devel] [PATCH 1/2 v4] avcodec/encode: restructure the core encoding code

2020-05-25 Thread Andreas Rheinhardt
James Almer:
> This commit follows the same logic as 061a0c14bb, but for the encode API: The
> new public encoding API will no longer be a wrapper around the old deprecated
> one, and the internal API used by the encoders now consists of a single
> receive_packet() callback that pulls frames as required.
> 
> amf encoders adapted by James Almer
> librav1e encoder adapted by James Almer
> nvidia encoders adapted by James Almer
> MediaFoundation encoders adapted by James Almer
> vaapi encoders adapted by Linjie Fu
> v4l2_m2m encoders adapted by Andriy Gelman
> 
> Signed-off-by: James Almer 
> ---
> @@ -328,6 +328,9 @@ typedef struct VAAPIEncodeContext {
>  // If the driver does not support ROI then warn the first time we
>  // encounter a frame with ROI side data.
>  int roi_warned;
> +
> +// Adapt to the new internal encode API

This comment won't age well.

> +AVFrame *frame;
>  } VAAPIEncodeContext;
>  

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

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

[FFmpeg-devel] [PATCH 1/2 v4] avcodec/encode: restructure the core encoding code

2020-05-25 Thread James Almer
This commit follows the same logic as 061a0c14bb, but for the encode API: The
new public encoding API will no longer be a wrapper around the old deprecated
one, and the internal API used by the encoders now consists of a single
receive_packet() callback that pulls frames as required.

amf encoders adapted by James Almer
librav1e encoder adapted by James Almer
nvidia encoders adapted by James Almer
MediaFoundation encoders adapted by James Almer
vaapi encoders adapted by Linjie Fu
v4l2_m2m encoders adapted by Andriy Gelman

Signed-off-by: James Almer 
---
Rebased the old set didn't apply anymore, and now including all the changes to
the affected encoders, so it's ready to commit, but preferably after 4.3 is
released.

 libavcodec/amfenc.c |  43 ++---
 libavcodec/amfenc.h |   2 -
 libavcodec/amfenc_h264.c|   1 -
 libavcodec/amfenc_hevc.c|   1 -
 libavcodec/avcodec.h|  12 +-
 libavcodec/encode.c | 283 
 libavcodec/encode.h |  39 +
 libavcodec/internal.h   |   7 +-
 libavcodec/librav1e.c   |  51 --
 libavcodec/mfenc.c  |  58 ---
 libavcodec/nvenc.c  |  72 
 libavcodec/nvenc.h  |   9 +-
 libavcodec/nvenc_h264.c |   6 -
 libavcodec/nvenc_hevc.c |   4 -
 libavcodec/utils.c  |  10 +-
 libavcodec/v4l2_m2m.c   |   8 +
 libavcodec/v4l2_m2m.h   |   3 +
 libavcodec/v4l2_m2m_enc.c   |  15 +-
 libavcodec/vaapi_encode.c   |  26 ++-
 libavcodec/vaapi_encode.h   |   4 +-
 libavcodec/vaapi_encode_h264.c  |   1 -
 libavcodec/vaapi_encode_h265.c  |   1 -
 libavcodec/vaapi_encode_mjpeg.c |   1 -
 libavcodec/vaapi_encode_mpeg2.c |   1 -
 libavcodec/vaapi_encode_vp8.c   |   1 -
 libavcodec/vaapi_encode_vp9.c   |   1 -
 26 files changed, 440 insertions(+), 220 deletions(-)
 create mode 100644 libavcodec/encode.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 876fddd2b6..da0652943d 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -33,6 +33,7 @@
 #include "libavutil/time.h"
 
 #include "amfenc.h"
+#include "encode.h"
 #include "internal.h"
 
 #if CONFIG_D3D11VA
@@ -588,17 +589,27 @@ static void amf_release_buffer_with_frame_ref(AMFBuffer 
*frame_ref_storage_buffe
 frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
 }
 
-int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
+int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
 {
 AmfContext *ctx = avctx->priv_data;
 AMFSurface *surface;
 AMF_RESULT  res;
 int ret;
+AMF_RESULT  res_query;
+AMFData*data = NULL;
+AVFrame*frame = ctx->delayed_frame;
+int block_and_wait;
 
 if (!ctx->encoder)
 return AVERROR(EINVAL);
 
-if (!frame) { // submit drain
+if (!frame->buf[0]) {
+ret = ff_encode_get_frame(avctx, frame);
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;
+}
+
+if (!frame->buf[0]) { // submit drain
 if (!ctx->eof) { // submit drain one time only
 if (ctx->delayed_surface != NULL) {
 ctx->delayed_drain = 1; // input queue is full: resubmit 
Drain() in ff_amf_receive_packet
@@ -613,15 +624,10 @@ int ff_amf_send_frame(AVCodecContext *avctx, const 
AVFrame *frame)
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"Drain() failed with error %d\n", res);
 }
 }
-} else{
-return AVERROR_EOF;
 }
-} else { // submit frame
+} else if (!ctx->delayed_surface) { // submit frame
 int hw_surface = 0;
 
-if (ctx->delayed_surface != NULL) {
-return AVERROR(EAGAIN); // should not happen when called from 
ffmpeg, other clients may resubmit
-}
 // prepare surface from frame
 switch (frame->format) {
 #if CONFIG_D3D11VA
@@ -693,38 +699,23 @@ int ff_amf_send_frame(AVCodecContext *avctx, const 
AVFrame *frame)
 break;
 }
 
-
 // submit surface
 res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, 
(AMFData*)surface);
 if (res == AMF_INPUT_FULL) { // handle full queue
 //store surface for later submission
 ctx->delayed_surface = surface;
-if (surface->pVtbl->GetMemoryType(surface) == AMF_MEMORY_DX11) {
-av_frame_ref(ctx->delayed_frame, frame);
-}
 } else {
+int64_t pts = frame->pts;
 surface->pVtbl->Release(surface);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"SubmitInput() failed with error %d\n", res);
 
-if ((ret = timestamp_queue_enqueue(avctx, frame->pts)) < 0) {
+av_frame_unref(frame);
+if ((ret = timestamp_queue_enqueue(avctx, pts)) < 0) {
 return ret;
 }
-
 }
 }
-   

[FFmpeg-devel] [PATCH 2/2 v4] avcodec/encode: restructure the old encode API

2020-05-25 Thread James Almer
Following the same logic as 061a0c14bb, this commit turns the old encode API
into a wrapper for the new one.

Signed-off-by: James Almer 
---
 libavcodec/encode.c   | 370 +-
 libavcodec/internal.h |   1 +
 libavcodec/utils.c|   8 +-
 3 files changed, 116 insertions(+), 263 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 69a6f47b62..6b40ae0a5a 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -32,43 +32,28 @@
 
 int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, 
int64_t min_size)
 {
-if (avpkt->size < 0) {
-av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", 
avpkt->size);
-return AVERROR(EINVAL);
-}
 if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
 av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size 
%"PRId64" (max allowed is %d)\n",
size, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
 return AVERROR(EINVAL);
 }
 
+av_assert0(!avpkt->data);
+
 if (avctx && 2*min_size < size) { // FIXME The factor needs to be finetuned
-av_assert0(!avpkt->data || avpkt->data != 
avctx->internal->byte_buffer);
-if (!avpkt->data || avpkt->size < size) {
-av_fast_padded_malloc(>internal->byte_buffer, 
>internal->byte_buffer_size, size);
-avpkt->data = avctx->internal->byte_buffer;
-avpkt->size = avctx->internal->byte_buffer_size;
-}
+av_fast_padded_malloc(>internal->byte_buffer, 
>internal->byte_buffer_size, size);
+avpkt->data = avctx->internal->byte_buffer;
+avpkt->size = size;
 }
 
-if (avpkt->data) {
-AVBufferRef *buf = avpkt->buf;
-
-if (avpkt->size < size) {
-av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < 
%"PRId64")\n", avpkt->size, size);
-return AVERROR(EINVAL);
-}
-
-av_init_packet(avpkt);
-avpkt->buf  = buf;
-avpkt->size = size;
-return 0;
-} else {
+if (!avpkt->data) {
 int ret = av_new_packet(avpkt, size);
 if (ret < 0)
 av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size 
%"PRId64"\n", size);
 return ret;
 }
+
+return 0;
 }
 
 int ff_alloc_packet(AVPacket *avpkt, int size)
@@ -110,244 +95,6 @@ fail:
 return ret;
 }
 
-int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
-  AVPacket *avpkt,
-  const AVFrame *frame,
-  int *got_packet_ptr)
-{
-AVFrame *extended_frame = NULL;
-AVFrame *padded_frame = NULL;
-int ret;
-AVPacket user_pkt = *avpkt;
-int needs_realloc = !user_pkt.data;
-
-*got_packet_ptr = 0;
-
-if (!avctx->codec->encode2) {
-av_log(avctx, AV_LOG_ERROR, "This encoder requires using the 
avcodec_send_frame() API.\n");
-return AVERROR(ENOSYS);
-}
-
-if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
-av_packet_unref(avpkt);
-return 0;
-}
-
-/* ensure that extended_data is properly set */
-if (frame && !frame->extended_data) {
-if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
-avctx->channels > AV_NUM_DATA_POINTERS) {
-av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
-"with more than %d channels, but 
extended_data is not set.\n",
-   AV_NUM_DATA_POINTERS);
-return AVERROR(EINVAL);
-}
-av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
-
-extended_frame = av_frame_alloc();
-if (!extended_frame)
-return AVERROR(ENOMEM);
-
-memcpy(extended_frame, frame, sizeof(AVFrame));
-extended_frame->extended_data = extended_frame->data;
-frame = extended_frame;
-}
-
-/* extract audio service type metadata */
-if (frame) {
-AVFrameSideData *sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
-if (sd && sd->size >= sizeof(enum AVAudioServiceType))
-avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
-}
-
-/* check for valid frame size */
-if (frame) {
-if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
-if (frame->nb_samples > avctx->frame_size) {
-av_log(avctx, AV_LOG_ERROR, "more samples than frame size 
(avcodec_encode_audio2)\n");
-ret = AVERROR(EINVAL);
-goto end;
-}
-} else if (!(avctx->codec->capabilities & 
AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
-/* if we already got an undersized frame, that must have been the 
last */
-if (avctx->internal->last_audio_frame) {
-av_log(avctx, 

Re: [FFmpeg-devel] [PATCH] avcodec/mediacodec_common: use MediaFormat to probe frame color characteristics

2020-05-25 Thread Matthieu Bouron
On Wed, May 20, 2020 at 10:07:03AM +0200, Matthieu Bouron wrote:
> On Sat, May 09, 2020 at 09:45:05AM +0200, Matthieu Bouron wrote:
> > On Tue, Mar 31, 2020 at 10:03:08AM +0200, Matthieu Bouron wrote:
> > > ---
> > >  libavcodec/mediacodecdec_common.c | 100 ++
> > >  1 file changed, 100 insertions(+)
> > > 
> > > diff --git a/libavcodec/mediacodecdec_common.c 
> > > b/libavcodec/mediacodecdec_common.c
> > > index f0752fa6261..404ed282275 100644
> > > --- a/libavcodec/mediacodecdec_common.c
> > > +++ b/libavcodec/mediacodecdec_common.c
> > > @@ -85,6 +85,85 @@
> > >  #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
> > >  #define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US 100
> > >  
> > > +enum {
> > > +COLOR_RANGE_FULL= 0x1,
> > > +COLOR_RANGE_LIMITED = 0x2,
> > > +};
> > > +
> > > +static enum AVColorRange mcdec_get_color_range(int color_range)
> > > +{
> > > +switch (color_range) {
> > > +case COLOR_RANGE_FULL:
> > > +return AVCOL_RANGE_JPEG;
> > > +case COLOR_RANGE_LIMITED:
> > > +return AVCOL_RANGE_MPEG;
> > > +default:
> > > +return AVCOL_RANGE_UNSPECIFIED;
> > > +}
> > > +}
> > > +
> > > +enum {
> > > +COLOR_STANDARD_BT709  = 0x1,
> > > +COLOR_STANDARD_BT601_PAL  = 0x2,
> > > +COLOR_STANDARD_BT601_NTSC = 0x4,
> > > +COLOR_STANDARD_BT2020 = 0x6,
> > > +};
> > > +
> > > +static enum AVColorSpace mcdec_get_color_space(int color_standard)
> > > +{
> > > +switch (color_standard) {
> > > +case COLOR_STANDARD_BT709:
> > > +return AVCOL_SPC_BT709;
> > > +case COLOR_STANDARD_BT601_PAL:
> > > +return AVCOL_SPC_BT470BG;
> > > +case COLOR_STANDARD_BT601_NTSC:
> > > +return AVCOL_SPC_SMPTE170M;
> > > +case COLOR_STANDARD_BT2020:
> > > +return AVCOL_SPC_BT2020_NCL;
> > > +default:
> > > +return AVCOL_SPC_UNSPECIFIED;
> > > +}
> > > +}
> > > +
> > > +static enum AVColorPrimaries mcdec_get_color_pri(int color_standard)
> > > +{
> > > +switch (color_standard) {
> > > +case COLOR_STANDARD_BT709:
> > > +return AVCOL_PRI_BT709;
> > > +case COLOR_STANDARD_BT601_PAL:
> > > +return AVCOL_PRI_BT470BG;
> > > +case COLOR_STANDARD_BT601_NTSC:
> > > +return AVCOL_PRI_SMPTE170M;
> > > +case COLOR_STANDARD_BT2020:
> > > +return AVCOL_PRI_BT2020;
> > > +default:
> > > +return AVCOL_PRI_UNSPECIFIED;
> > > +}
> > > +}
> > > +
> > > +enum {
> > > +COLOR_TRANSFER_LINEAR= 0x1,
> > > +COLOR_TRANSFER_SDR_VIDEO = 0x3,
> > > +COLOR_TRANSFER_ST2084= 0x6,
> > > +COLOR_TRANSFER_HLG   = 0x7,
> > > +};
> > > +
> > > +static enum AVColorTransferCharacteristic mcdec_get_color_trc(int 
> > > color_transfer)
> > > +{
> > > +switch (color_transfer) {
> > > +case COLOR_TRANSFER_LINEAR:
> > > +return AVCOL_TRC_LINEAR;
> > > +case COLOR_TRANSFER_SDR_VIDEO:
> > > +return AVCOL_TRC_SMPTE170M;
> > > +case COLOR_TRANSFER_ST2084:
> > > +return AVCOL_TRC_SMPTEST2084;
> > > +case COLOR_TRANSFER_HLG:
> > > +return AVCOL_TRC_ARIB_STD_B67;
> > > +default:
> > > +return AVCOL_TRC_UNSPECIFIED;
> > > +}
> > > +}
> > > +
> > >  enum {
> > >  COLOR_FormatYUV420Planar  = 0x13,
> > >  COLOR_FormatYUV420SemiPlanar  = 0x15,
> > > @@ -220,6 +299,10 @@ FF_DISABLE_DEPRECATION_WARNINGS
> > >  FF_ENABLE_DEPRECATION_WARNINGS
> > >  #endif
> > >  frame->pkt_dts = AV_NOPTS_VALUE;
> > > +frame->color_range = avctx->color_range;
> > > +frame->color_primaries = avctx->color_primaries;
> > > +frame->color_trc = avctx->color_trc;
> > > +frame->colorspace = avctx->colorspace;
> > >  
> > >  buffer = av_mallocz(sizeof(AVMediaCodecBuffer));
> > >  if (!buffer) {
> > > @@ -368,6 +451,9 @@ static int mediacodec_dec_parse_format(AVCodecContext 
> > > *avctx, MediaCodecDecConte
> > >  int ret = 0;
> > >  int width = 0;
> > >  int height = 0;
> > > +int color_range = 0;
> > > +int color_standard = 0;
> > > +int color_transfer = 0;
> > >  char *format = NULL;
> > >  
> > >  if (!s->format) {
> > > @@ -426,6 +512,20 @@ static int 
> > > mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte
> > >  ff_set_sar(avctx, sar);
> > >  }
> > >  
> > > +AMEDIAFORMAT_GET_INT32(color_range, "color-range", 0);
> > > +if (color_range)
> > > +avctx->color_range = mcdec_get_color_range(color_range);
> > > +
> > > +AMEDIAFORMAT_GET_INT32(color_standard, "color-standard", 0);
> > > +if (color_standard) {
> > > +avctx->colorspace = mcdec_get_color_space(color_standard);
> > > +avctx->color_primaries = mcdec_get_color_pri(color_standard);
> > > +}
> > > +
> > > +AMEDIAFORMAT_GET_INT32(color_transfer, "color-transfer", 0);
> > > +if (color_transfer)
> > > +avctx->color_trc = 

Re: [FFmpeg-devel] [PATCH 4/5] avformat/aviobuf: Return better error codes

2020-05-25 Thread Michael Niedermayer
On Mon, May 25, 2020 at 04:08:00PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/aviobuf.c | 14 --
>  1 file changed, 8 insertions(+), 6 deletions(-)

probably ok

thx

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

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes


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 1/5] avformat/aviobuf: Don't check for overflow after it happened

2020-05-25 Thread Andreas Rheinhardt
James Almer:
> On 5/25/2020 11:07 AM, Andreas Rheinhardt wrote:
>> If adding two ints overflows, it doesn't matter whether the result will
>> be stored in an unsigned or not; and checking afterwards does not make it
>> retroactively defined.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libavformat/aviobuf.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
>> index eb0387bdf7..33c2d6f037 100644
>> --- a/libavformat/aviobuf.c
>> +++ b/libavformat/aviobuf.c
>> @@ -1275,7 +1275,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, 
>> int buf_size)
>>  unsigned new_size, new_allocated_size;
>>  
>>  /* reallocate buffer if needed */
>> -new_size = d->pos + buf_size;
>> +new_size = (unsigned)d->pos + buf_size;
>>  new_allocated_size = d->allocated_size;
>>  if (new_size < d->pos || new_size > INT_MAX/2)
>>  return -1;
> 
> You could instead do
> 
> if (d->pos > INT_MAX / 2 - buf_size)
> return -1;
> new_size = d->pos + buf_size;
> 
> Should also work fine with the changes in 3/5 adapted to it.

This would drop the check for whether buf_size is negative. While I am
not opposed to this (such a check should be made generically, so that
every AVIOContext.write_packet() can rely on buf_size being >= 0 (0
could probably be also dealt with generically)), I intended to do this
only later (in a future patchset). This implied for my/the current
version that one could drop the check for new_size < d->pos. And with
this change your proposal loses its advantage.
(Also notice that if buf_size is negative, INT_MAX / 2 - buf_size might
overflow and INT_MAX - buf_size does overflow.)

- 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] avfilter: add iir video filter

2020-05-25 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  18 ++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_iir.c | 410 +++
 4 files changed, 430 insertions(+)
 create mode 100644 libavfilter/vf_iir.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 773473f721..7675a0e9b1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -12500,6 +12500,24 @@ further computations. This allows inserting the idet 
filter as a low computation
 method to clean up the interlaced flag
 @end table
 
+@section iir
+Apply 2D Infinite Impulse Response filter to input video stream.
+
+The filter accepts the following options:
+
+@table @option
+@item hn
+@item vn
+Set horizontal and vertical numerator coefficients of transfer function.
+
+@item hd
+@item vd
+Set horizontal and vertical denominator coefficients of transfer function.
+
+@item planes
+Set which planes to filter. Default is all. Allowed range is from 0 to 15.
+@end table
+
 @section il
 
 Deinterleave or interleave fields.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 994a4172a3..5344eb8ca9 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -281,6 +281,7 @@ OBJS-$(CONFIG_HWUPLOAD_CUDA_FILTER)  += 
vf_hwupload_cuda.o
 OBJS-$(CONFIG_HWUPLOAD_FILTER)   += vf_hwupload.o
 OBJS-$(CONFIG_HYSTERESIS_FILTER) += vf_hysteresis.o framesync.o
 OBJS-$(CONFIG_IDET_FILTER)   += vf_idet.o
+OBJS-$(CONFIG_IIR_FILTER)+= vf_iir.o
 OBJS-$(CONFIG_IL_FILTER) += vf_il.o
 OBJS-$(CONFIG_INFLATE_FILTER)+= vf_neighbor.o
 OBJS-$(CONFIG_INTERLACE_FILTER)  += vf_tinterlace.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index f2a44b0090..f6ecf96b9b 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -266,6 +266,7 @@ extern AVFilter ff_vf_hwupload;
 extern AVFilter ff_vf_hwupload_cuda;
 extern AVFilter ff_vf_hysteresis;
 extern AVFilter ff_vf_idet;
+extern AVFilter ff_vf_iir;
 extern AVFilter ff_vf_il;
 extern AVFilter ff_vf_inflate;
 extern AVFilter ff_vf_interlace;
diff --git a/libavfilter/vf_iir.c b/libavfilter/vf_iir.c
new file mode 100644
index 00..193856adf3
--- /dev/null
+++ b/libavfilter/vf_iir.c
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 2020 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/avstring.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct IIRContext {
+const AVClass *class;
+
+char *h_num_str;
+char *h_den_str;
+char *v_num_str;
+char *v_den_str;
+
+int h_nb_num;
+int h_nb_den;
+int v_nb_num;
+int v_nb_den;
+
+float *hnum;
+float *hden;
+float *vnum;
+float *vden;
+
+float **honum;
+float **hoden;
+float **vonum;
+float **voden;
+
+int planes;
+int nb_planes;
+int nb_threads;
+
+int planewidth[4];
+int planeheight[4];
+} IIRContext;
+
+#define OFFSET(x) offsetof(IIRContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption iir_options[] = {
+{ "hn", "set horizontal numerator",   OFFSET(h_num_str), 
AV_OPT_TYPE_STRING,   {.str=0}, 0,   0, FLAGS },
+{ "hd", "set horizotnal denominator", OFFSET(h_den_str), 
AV_OPT_TYPE_STRING,   {.str=0}, 0,   0, FLAGS },
+{ "vn", "set vertical numerator", OFFSET(v_num_str), 
AV_OPT_TYPE_STRING,   {.str=0}, 0,   0, FLAGS },
+{ "vd", "set vertical denominator",   OFFSET(v_den_str), 
AV_OPT_TYPE_STRING,   {.str=0}, 0,   0, FLAGS },
+{ "planes", "set planes to filter",   OFFSET(planes),
AV_OPT_TYPE_INT,  {.i64=0xF},   0, 0xF, FLAGS },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(iir);
+
+typedef struct ThreadData {
+int height;
+int width;
+
+float *dst;
+float *src;
+int dst_linesize;
+int src_linesize;
+} ThreadData;
+
+static void horiz_slice(float *dst, float *src,
+int dst_linesize, int src_linesize,
+

Re: [FFmpeg-devel] [PATCH 3/3] avcodec.h: move avcodec_get_{type, name} to codec_id.h

2020-05-25 Thread James Almer
On 5/25/2020 10:12 AM, Anton Khirnov wrote:
> ---
>  libavcodec/avcodec.h  | 11 ---
>  libavcodec/codec_id.h | 12 
>  2 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 4f46a1fb2e..01099bc8cd 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -4115,17 +4115,6 @@ attribute_deprecated
>  int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
>  #endif
>  
> -/**
> - * Get the type of the given codec.
> - */
> -enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
> -
> -/**
> - * Get the name of a codec.
> - * @return  a static string identifying the codec; never NULL
> - */
> -const char *avcodec_get_name(enum AVCodecID id);
> -
>  /**
>   * @return a positive value if s is open (i.e. avcodec_open2() was called on 
> it
>   * with no corresponding avcodec_close()), 0 otherwise.
> diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
> index e95737c0a2..f7cb0a6056 100644
> --- a/libavcodec/codec_id.h
> +++ b/libavcodec/codec_id.h
> @@ -21,6 +21,8 @@
>  #ifndef AVCODEC_CODEC_ID_H
>  #define AVCODEC_CODEC_ID_H
>  
> +#include "libavutil/avutil.h"
> +
>  /**
>   * @addtogroup lavc_core
>   * @{
> @@ -556,6 +558,16 @@ enum AVCodecID {
>  AV_CODEC_ID_WRAPPED_AVFRAME = 0x21001, ///< Passthrough codec, AVFrames 
> wrapped in AVPacket
>  };
>  
> +/**
> + * Get the type of the given codec.
> + */
> +enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
> +
> +/**
> + * Get the name of a codec.
> + * @return  a static string identifying the codec; never NULL
> + */
> +const char *avcodec_get_name(enum AVCodecID id);
>  
>  /**
>   * @}

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 1/2] dnn_backend_native_layer_mathunary: add abs support

2020-05-25 Thread Ting Fu
more math unary operations will be added here

It can be tested with the model file generated with below python scripy:

import tensorflow as tf
import numpy as np
import imageio

in_img = imageio.imread('input.jpeg')
in_img = in_img.astype(np.float32)/255.0
in_data = in_img[np.newaxis, :]

x = tf.placeholder(tf.float32, shape=[1, None, None, 3], name='dnn_in')
x1 = tf.subtract(x, 0.5)
x2 = tf.abs(x1)
y = tf.identity(x2, name='dnn_out')

sess=tf.Session()
sess.run(tf.global_variables_initializer())

graph_def = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, 
['dnn_out'])
tf.train.write_graph(graph_def, '.', 'image_process.pb', as_text=False)

print("image_process.pb generated, please use \
path_to_ffmpeg/tools/python/convert.py to generate image_process.model\n")

output = sess.run(y, feed_dict={x: in_data})
imageio.imsave("out.jpg", np.squeeze(output))

Signed-off-by: Ting Fu 
---
 libavfilter/dnn/Makefile  |  1 +
 libavfilter/dnn/dnn_backend_native.h  |  1 +
 .../dnn/dnn_backend_native_layer_mathunary.c  | 80 +++
 .../dnn/dnn_backend_native_layer_mathunary.h  | 45 +++
 libavfilter/dnn/dnn_backend_native_layers.c   |  2 +
 tools/python/convert_from_tensorflow.py   | 16 +++-
 tools/python/convert_header.py|  2 +-
 7 files changed, 145 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/dnn/dnn_backend_native_layer_mathunary.c
 create mode 100644 libavfilter/dnn/dnn_backend_native_layer_mathunary.h

diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index ce529587e1..bb37298b58 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -6,6 +6,7 @@ OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_con
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_depth2space.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_maximum.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_mathbinary.o
+OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_mathunary.o
 
 DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
 
diff --git a/libavfilter/dnn/dnn_backend_native.h 
b/libavfilter/dnn/dnn_backend_native.h
index 5d76d87915..61f0cb202f 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -42,6 +42,7 @@ typedef enum {
 DLT_MIRROR_PAD = 3,
 DLT_MAXIMUM = 4,
 DLT_MATH_BINARY = 5,
+DLT_MATH_UNARY = 6,
 DLT_COUNT
 } DNNLayerType;
 
diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathunary.c 
b/libavfilter/dnn/dnn_backend_native_layer_mathunary.c
new file mode 100644
index 00..d65af151cd
--- /dev/null
+++ b/libavfilter/dnn/dnn_backend_native_layer_mathunary.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2020
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * DNN native backend implementation.
+ */
+
+#include "dnn_backend_native.h"
+#include "libavutil/avassert.h"
+#include "dnn_backend_native_layer_mathunary.h"
+
+int dnn_load_layer_math_unary(Layer *layer, AVIOContext *model_file_context, 
int file_size)
+{
+DnnLayerMathUnaryParams *params;
+int dnn_size = 0;
+params = av_malloc(sizeof(*params));
+if(!params)
+return 0;
+
+params->un_op = (int32_t)avio_rl32(model_file_context);
+dnn_size += 4;
+layer->params = params;
+layer->input_operand_indexes[0] = (int32_t)avio_rl32(model_file_context);
+layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
+dnn_size += 8;
+
+return dnn_size;
+
+}
+
+int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t 
*input_operand_indexes,
+int32_t output_operand_index, const void 
*parameters)
+{
+const DnnOperand *input = [input_operand_indexes[0]];
+DnnOperand *output = [output_operand_index];
+const DnnLayerMathUnaryParams *params = (const DnnLayerMathUnaryParams 
*)parameters;
+int dims_count;
+const float *src;
+float *dst;
+
+for (int i = 0; i < 4; ++i)
+output->dims[i] = input->dims[i];
+
+output->data_type = input->data_type;
+output->length = 

[FFmpeg-devel] [PATCH 2/2] dnn-layer-mathunary-test: add unit test for abs

2020-05-25 Thread Ting Fu
Signed-off-by: Ting Fu 
---
 tests/dnn/.gitignore |  1 +
 tests/dnn/Makefile   |  1 +
 tests/dnn/dnn-layer-mathunary-test.c | 81 
 tests/fate/dnn.mak   |  5 ++
 4 files changed, 88 insertions(+)
 create mode 100644 tests/dnn/dnn-layer-mathunary-test.c

diff --git a/tests/dnn/.gitignore b/tests/dnn/.gitignore
index d78c5c1aec..1fcd2410b4 100644
--- a/tests/dnn/.gitignore
+++ b/tests/dnn/.gitignore
@@ -3,3 +3,4 @@
 /dnn-layer-maximum-test
 /dnn-layer-pad-test
 /dnn-layer-mathbinary-test
+/dnn-layer-mathunary-test
diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile
index 1f96710821..64591b7851 100644
--- a/tests/dnn/Makefile
+++ b/tests/dnn/Makefile
@@ -3,6 +3,7 @@ DNNTESTPROGS += dnn-layer-conv2d
 DNNTESTPROGS += dnn-layer-depth2space
 DNNTESTPROGS += dnn-layer-mathbinary
 DNNTESTPROGS += dnn-layer-maximum
+DNNTESTPROGS += dnn-layer-mathunary
 
 DNNTESTOBJS  := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) 
$(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
 DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
diff --git a/tests/dnn/dnn-layer-mathunary-test.c 
b/tests/dnn/dnn-layer-mathunary-test.c
new file mode 100644
index 00..f032ca0684
--- /dev/null
+++ b/tests/dnn/dnn-layer-mathunary-test.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2020
+ *
+ * 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 
+#include 
+#include 
+#include "libavfilter/dnn/dnn_backend_native_layer_mathunary.h"
+#include "libavutil/avassert.h"
+
+#define EPS 0.1
+
+static float get_expected(float f, DNNMathUnaryOperation op)
+{
+switch (op)
+{
+case DMUO_ABS:
+return (f >= 0) ? f : -f;
+default:
+av_assert0(!"not supported yet");
+return 0.f;
+}
+}
+
+static int test(DNNMathUnaryOperation op)
+{
+DnnLayerMathUnaryParams params;
+DnnOperand operands[2];
+int32_t input_indexes[1];
+float input[1*1*2*3] = {
+-3, 2.5, 2, -2.1, 7.8, 100};
+float *output;
+
+params.un_op = op;
+
+operands[0].data = input;
+operands[0].dims[0] = 1;
+operands[0].dims[1] = 1;
+operands[0].dims[2] = 2;
+operands[0].dims[3] = 3;
+operands[1].data = NULL;
+
+input_indexes[0] = 0;
+dnn_execute_layer_math_unary(operands, input_indexes, 1, );
+
+output = operands[1].data;
+for (int i = 0; i < sizeof(input) / sizeof(float); ++i) {
+float expected_output = get_expected(input[i], op);
+if(fabs(output[i] - expected_output) > EPS) {
+printf("at index %d, output: %f, expected_output: %f\n", i, 
output[i], expected_output);
+av_freep();
+return 1;
+}
+}
+
+av_freep();
+return 0;
+}
+
+int main(int agrc, char **argv)
+{
+if (test(DMUO_ABS))
+return 1;
+return 0;
+}
diff --git a/tests/fate/dnn.mak b/tests/fate/dnn.mak
index 5a8e6296a6..4a50b16382 100644
--- a/tests/fate/dnn.mak
+++ b/tests/fate/dnn.mak
@@ -23,6 +23,11 @@ fate-dnn-layer-maximum: 
$(DNNTESTSDIR)/dnn-layer-maximum-test$(EXESUF)
 fate-dnn-layer-maximum: CMD = run 
$(DNNTESTSDIR)/dnn-layer-maximum-test$(EXESUF)
 fate-dnn-layer-maximum: CMP = null
 
+FATE_DNN += fate-dnn-layer-mathunary
+fate-dnn-layer-mathunary: $(DNNTESTSDIR)/dnn-layer-mathunary-test$(EXESUF)
+fate-dnn-layer-mathunary: CMD = run 
$(DNNTESTSDIR)/dnn-layer-mathunary-test$(EXESUF)
+fate-dnn-layer-mathunary: CMP = null
+
 FATE-yes += $(FATE_DNN)
 
 fate-dnn: $(FATE_DNN)
-- 
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 1/5] avformat/aviobuf: Don't check for overflow after it happened

2020-05-25 Thread James Almer
On 5/25/2020 11:07 AM, Andreas Rheinhardt wrote:
> If adding two ints overflows, it doesn't matter whether the result will
> be stored in an unsigned or not; and checking afterwards does not make it
> retroactively defined.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/aviobuf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index eb0387bdf7..33c2d6f037 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -1275,7 +1275,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, 
> int buf_size)
>  unsigned new_size, new_allocated_size;
>  
>  /* reallocate buffer if needed */
> -new_size = d->pos + buf_size;
> +new_size = (unsigned)d->pos + buf_size;
>  new_allocated_size = d->allocated_size;
>  if (new_size < d->pos || new_size > INT_MAX/2)
>  return -1;

You could instead do

if (d->pos > INT_MAX / 2 - buf_size)
return -1;
new_size = d->pos + buf_size;

Should also work fine with the changes in 3/5 adapted to it.
___
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.h: split AVCodec API into its own header

2020-05-25 Thread James Almer
On 5/25/2020 10:31 AM, Anton Khirnov wrote:
> Quoting James Almer (2020-05-25 15:21:12)
>> On 5/25/2020 10:12 AM, Anton Khirnov wrote:
>>> -/**
>>> - * Iterate over all registered codecs.
>>> - *
>>> - * @param opaque a pointer where libavcodec will store the iteration 
>>> state. Must
>>> - *   point to NULL to start the iteration.
>>> - *
>>> - * @return the next registered codec or NULL when the iteration is
>>> - * finished
>>> - */
>>> -const AVCodec *av_codec_iterate(void **opaque);
>>> -
>>>  #if FF_API_NEXT
>>
>> Why are you not moving the deprecated functions as well? They are
>> AVCodec related and should remain with the rest until they are
>> effectively removed.
> 
> Why?
> Seems better to me to make the new headers "clean", since new users
> should only use the non-deprecated API. No need to distract them with
> obsolete cruft.

Ok, that's reasonable. But why did you move the AVPacket ones, then? If
anything, those should be hidden since they are the most confusing, like
av_packet_free() and av_free_packet() in the same header, or pretty much
broken and potentially dangerous, like av_dup_packet().

Also I see you didn't move the bsf ones, which i agree 100% with since
we definitely want people to stop using those.

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

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

[FFmpeg-devel] [PATCH 5/5] avformat/aviobuf: Also return truncated buffer in avio_get_dyn_buf()

2020-05-25 Thread Andreas Rheinhardt
Two kinds of errors can happen when working with dynamic buffers:
(Re)allocation errors or truncation errors (one has to truncate the
buffer to a size of INT_MAX because avio_close_dyn_buf() and
avio_get_dyn_buf() both return an int). Right now, avio_get_dyn_buf()
returns an empty buffer in either case. But given that
avio_get_dyn_buf() does not destroy the dynamic buffer, one can return
the buffer in case of truncation and let the user check the error flags
and decide for himself instead of hardcoding a single way to proceed
in case of truncation.

(This actually restores the behaviour from before commit
163bb9ac0af495a5cb95441bdb5c02170440d28c.)

Signed-off-by: Andreas Rheinhardt 
---
Unfortunately the "let the user decide" approach is not possible for
avio_close_dyn_buf(). Said function has many more deficits:

On allocation failure it returns a size of
-AV_INPUT_BUFFER_PADDING_SIZE, although the documentation does not even
allow negative return values at all.
On truncation, the padding is not really written, yet it is subtracted
from the size (or to put it another way: the padding is not zeroed in
this case).
It does not return the actual size of the buffer, but rather the last
position (which can be different in case a backward seek had been
performed). In this case, it is not the end of the buffer that is padded,
but rather the position when calling avio_close_dyn_buf().

There is no documented way to check for errors; checking whether the
returned buffer is NULL works in case of allocation failures, but not
for truncation. If we returned NULL on truncation, too, callers could
check for errors. But a real solution would involve deprecating
avio_close_dyn_buf() and maybe the rest of the current dynamic buffer API.

 libavformat/aviobuf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index a13c677875..66cc8c7adc 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1370,13 +1370,13 @@ int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
 {
 DynBuffer *d;
 
-if (!s || s->error) {
+if (!s) {
 *pbuffer = NULL;
 return 0;
 }
 d = s->opaque;
 
-if (!d->size) {
+if (!s->error && !d->size) {
 *pbuffer = d->io_buffer;
 return FFMAX(s->buf_ptr, s->buf_ptr_max) - s->buffer;
 }
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 2/5] avformat/aviobuf: Simplify dyn_buf_write() a bit

2020-05-25 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/aviobuf.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 33c2d6f037..fcde7e8510 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1272,22 +1272,19 @@ typedef struct DynBuffer {
 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
 {
 DynBuffer *d = opaque;
-unsigned new_size, new_allocated_size;
+unsigned new_size;
 
 /* reallocate buffer if needed */
 new_size = (unsigned)d->pos + buf_size;
-new_allocated_size = d->allocated_size;
 if (new_size < d->pos || new_size > INT_MAX/2)
 return -1;
-while (new_size > new_allocated_size) {
-if (!new_allocated_size)
-new_allocated_size = new_size;
-else
+if (new_size > d->allocated_size) {
+unsigned new_allocated_size = d->allocated_size ? d->allocated_size
+: new_size;
+int err;
+while (new_size > new_allocated_size)
 new_allocated_size += new_allocated_size / 2 + 1;
-}
 
-if (new_allocated_size > d->allocated_size) {
-int err;
 if ((err = av_reallocp(>buffer, new_allocated_size)) < 0) {
 d->allocated_size = 0;
 d->size = 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 4/5] avformat/aviobuf: Return better error codes

2020-05-25 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/aviobuf.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 688c7c50fd..a13c677875 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -696,7 +696,7 @@ int avio_read_partial(AVIOContext *s, unsigned char *buf, 
int size)
 int len;
 
 if (size < 0)
-return -1;
+return AVERROR(EINVAL);
 
 if (s->read_packet && s->write_flag) {
 len = read_packet_wrapper(s, buf, size);
@@ -1277,7 +1277,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int 
buf_size)
 /* reallocate buffer if needed */
 new_size = (unsigned)d->pos + buf_size;
 if (new_size < d->pos || new_size > INT_MAX)
-return -1;
+return AVERROR(ERANGE);
 if (new_size > d->allocated_size) {
 unsigned new_allocated_size = d->allocated_size ? d->allocated_size
 : new_size;
@@ -1324,8 +1324,10 @@ static int64_t dyn_buf_seek(void *opaque, int64_t 
offset, int whence)
 offset += d->pos;
 else if (whence == SEEK_END)
 offset += d->size;
-if (offset < 0 || offset > 0x7fffLL)
-return -1;
+if (offset < 0)
+return AVERROR(EINVAL);
+if (offset > INT_MAX)
+return AVERROR(ERANGE);
 d->pos = offset;
 return 0;
 }
@@ -1336,7 +1338,7 @@ static int url_open_dyn_buf_internal(AVIOContext **s, int 
max_packet_size)
 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
 
 if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
-return -1;
+return AVERROR(ERANGE);
 d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
 if (!d)
 return AVERROR(ENOMEM);
@@ -1360,7 +1362,7 @@ int avio_open_dyn_buf(AVIOContext **s)
 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
 {
 if (max_packet_size <= 0)
-return -1;
+return AVERROR(EINVAL);
 return url_open_dyn_buf_internal(s, max_packet_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 3/5] avformat/aviobuf: Stop restricting dynamic buffer sizes to INT_MAX/2

2020-05-25 Thread Andreas Rheinhardt
This has originally been done in 568e18b15e2ddf494fd8926707d34ca08c8edce5
as a precaution against integer overflows, but it is actually easy to
support the full range of int without overflows.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/aviobuf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index fcde7e8510..688c7c50fd 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1276,7 +1276,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int 
buf_size)
 
 /* reallocate buffer if needed */
 new_size = (unsigned)d->pos + buf_size;
-if (new_size < d->pos || new_size > INT_MAX/2)
+if (new_size < d->pos || new_size > INT_MAX)
 return -1;
 if (new_size > d->allocated_size) {
 unsigned new_allocated_size = d->allocated_size ? d->allocated_size
@@ -1285,6 +1285,8 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int 
buf_size)
 while (new_size > new_allocated_size)
 new_allocated_size += new_allocated_size / 2 + 1;
 
+new_allocated_size = FFMIN(new_allocated_size, INT_MAX);
+
 if ((err = av_reallocp(>buffer, new_allocated_size)) < 0) {
 d->allocated_size = 0;
 d->size = 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 1/5] avformat/aviobuf: Don't check for overflow after it happened

2020-05-25 Thread Andreas Rheinhardt
If adding two ints overflows, it doesn't matter whether the result will
be stored in an unsigned or not; and checking afterwards does not make it
retroactively defined.

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

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index eb0387bdf7..33c2d6f037 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1275,7 +1275,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int 
buf_size)
 unsigned new_size, new_allocated_size;
 
 /* reallocate buffer if needed */
-new_size = d->pos + buf_size;
+new_size = (unsigned)d->pos + buf_size;
 new_allocated_size = d->allocated_size;
 if (new_size < d->pos || new_size > INT_MAX/2)
 return -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".

Re: [FFmpeg-devel] [PATCH 3/3] lavf/dashdec: avoid reading the first data segment in read_header

2020-05-25 Thread Gorilla Maguila
These lines:

+if (pls->init_sec_data_len > 0)
+pls->ctx->probesize = FFMIN(pls->ctx->probesize,
pls->init_sec_data_len);
 pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ?
s->max_analyze_duration : 4 * AV_TIME_BASE;
-ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0, 0);
+ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0,
pls->ctx->probesize);


cause an Error in av_probe_input_buffer when pls->init_sec_data_len
or pls->ctx->probesize are < 2048 due to the following line in
av_probe_input_buffer:

https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/format.c#L236

El vie., 22 may. 2020 a las 9:22, Steven Liu ()
escribió:

>
>
> > 2020年5月22日 下午1:42,rcombs  写道:
> >
> > This reduces the number of requests that have to be made during startup.
> > ---
> > libavformat/dashdec.c | 41 ++---
> > 1 file changed, 26 insertions(+), 15 deletions(-)
> >
> > diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> > index ec2aadcee3..1bd070c7cb 100644
> > --- a/libavformat/dashdec.c
> > +++ b/libavformat/dashdec.c
> > @@ -1798,6 +1798,19 @@ static int read_data(void *opaque, uint8_t *buf,
> int buf_size)
> > DASHContext *c = v->parent->priv_data;
> >
> > restart:
> > +/* load/update Media Initialization Section, if any */
> > +if ((ret = update_init_section(v)) < 0)
> > +goto end;
> > +
> > +if (v->init_sec_buf_read_offset < v->init_sec_data_len) {
> > +/* Push init section out first before first actual fragment */
> > +int copy_size = FFMIN(v->init_sec_data_len -
> v->init_sec_buf_read_offset, buf_size);
> > +memcpy(buf, v->init_sec_buf, copy_size);
> > +v->init_sec_buf_read_offset += copy_size;
> > +ret = copy_size;
> > +goto end;
> > +}
> > +
> > if (!v->input) {
> > free_fragment(>cur_seg);
> > v->cur_seg = get_current_fragment(v);
> > @@ -1806,11 +1819,6 @@ restart:
> > goto end;
> > }
> >
> > -/* load/update Media Initialization Section, if any */
> > -ret = update_init_section(v);
> > -if (ret)
> > -goto end;
> > -
> > ret = open_input(c, v, v->cur_seg);
> > if (ret < 0) {
> > if (ff_check_interrupt(c->interrupt_callback)) {
> > @@ -1823,15 +1831,6 @@ restart:
> > }
> > }
> >
> > -if (v->init_sec_buf_read_offset < v->init_sec_data_len) {
> > -/* Push init section out first before first actual fragment */
> > -int copy_size = FFMIN(v->init_sec_data_len -
> v->init_sec_buf_read_offset, buf_size);
> > -memcpy(buf, v->init_sec_buf, copy_size);
> > -v->init_sec_buf_read_offset += copy_size;
> > -ret = copy_size;
> > -goto end;
> > -}
> > -
> > /* check the v->cur_seg, if it is null, get current and double check
> if the new v->cur_seg*/
> > if (!v->cur_seg) {
> > v->cur_seg = get_current_fragment(v);
> > @@ -1940,10 +1939,19 @@ static int
> reopen_demux_for_component(AVFormatContext *s, struct representation
> > if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
> > goto fail;
> >
> > +
> > +if (pls->init_sec_data_len <= 0) {
> > +/* load/update Media Initialization Section, if any */
> > +if ((ret = update_init_section(pls)) < 0)
> > +goto fail;
> > +}
> > +
> > pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO;
> > pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
> > +if (pls->init_sec_data_len > 0)
> > +pls->ctx->probesize = FFMIN(pls->ctx->probesize,
> pls->init_sec_data_len);
> > pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ?
> s->max_analyze_duration : 4 * AV_TIME_BASE;
> > -ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0, 0);
> > +ret = av_probe_input_buffer(>pb, _fmt, "", NULL, 0,
> pls->ctx->probesize);
> > if (ret < 0) {
> > av_log(s, AV_LOG_ERROR, "Error when loading first fragment,
> playlist %d\n", (int)pls->rep_idx);
> > avformat_free_context(pls->ctx);
> > @@ -1954,6 +1962,9 @@ static int
> reopen_demux_for_component(AVFormatContext *s, struct representation
> > pls->ctx->pb = >pb;
> > pls->ctx->io_open  = nested_io_open;
> >
> > +if (pls->init_sec_data_len > 0)
> > +av_dict_set_int(_fmt_opts, "header_size",
> pls->init_sec_data_len, 0);
> > +
> > // provide additional information from mpd if available
> > ret = avformat_open_input(>ctx, "", in_fmt, _fmt_opts);
> //pls->init_section->url
> > av_dict_free(_fmt_opts);
> > --
> > 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".
>
> Patchset LGTM
>
> Thanks
>
> Steven Liu
>
>
>
> 

Re: [FFmpeg-devel] [PATCH 2/3] avcodec.h: split AVCodec API into its own header

2020-05-25 Thread Anton Khirnov
Quoting James Almer (2020-05-25 15:21:12)
> On 5/25/2020 10:12 AM, Anton Khirnov wrote:
> > -/**
> > - * Iterate over all registered codecs.
> > - *
> > - * @param opaque a pointer where libavcodec will store the iteration 
> > state. Must
> > - *   point to NULL to start the iteration.
> > - *
> > - * @return the next registered codec or NULL when the iteration is
> > - * finished
> > - */
> > -const AVCodec *av_codec_iterate(void **opaque);
> > -
> >  #if FF_API_NEXT
> 
> Why are you not moving the deprecated functions as well? They are
> AVCodec related and should remain with the rest until they are
> effectively removed.

Why?
Seems better to me to make the new headers "clean", since new users
should only use the non-deprecated API. No need to distract them with
obsolete cruft.

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

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

Re: [FFmpeg-devel] [PATCH 2/3] avcodec.h: split AVCodec API into its own header

2020-05-25 Thread James Almer
On 5/25/2020 10:12 AM, Anton Khirnov wrote:
> -/**
> - * Iterate over all registered codecs.
> - *
> - * @param opaque a pointer where libavcodec will store the iteration state. 
> Must
> - *   point to NULL to start the iteration.
> - *
> - * @return the next registered codec or NULL when the iteration is
> - * finished
> - */
> -const AVCodec *av_codec_iterate(void **opaque);
> -
>  #if FF_API_NEXT

Why are you not moving the deprecated functions as well? They are
AVCodec related and should remain with the rest until they are
effectively removed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 3/3] avformat/prompeg: use av_dict_set_int() instead

2020-05-25 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavformat/prompeg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/prompeg.c b/libavformat/prompeg.c
index 9770a916a2..7b2e5e8344 100644
--- a/libavformat/prompeg.c
+++ b/libavformat/prompeg.c
@@ -291,8 +291,7 @@ static int prompeg_open(URLContext *h, const char *uri, int 
flags) {
 }
 
 if (s->ttl > 0) {
-snprintf(buf, sizeof (buf), "%d", s->ttl);
-av_dict_set(_opts, "ttl", buf, 0);
+av_dict_set_int(_opts, "ttl", s->ttl, 0);
 }
 
 ff_url_join(buf, sizeof (buf), "udp", NULL, hostname, rtp_port + 2, NULL);
-- 
2.21.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 1/3] doc/APIchanges: fix typo in version number

2020-05-25 Thread James Almer
On 5/25/2020 10:12 AM, Anton Khirnov wrote:
> ---
>  doc/APIchanges | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 56ec9f8ac3..6a03686068 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -31,7 +31,7 @@ API changes, most recent first:
>Move AVBitstreamFilter-related public API to new header bsf.h.
>Move AVCodecParameters-related public API to new header codec_par.h.
>  
> -2020-05-xx - xx - lavc 56.86.101 - avcodec.h
> +2020-05-xx - xx - lavc 58.86.101 - avcodec.h
>Deprecated AV_CODEC_CAP_INTRA_ONLY and AV_CODEC_CAP_LOSSLESS.

Sorry, copy paste mistake from the line below.

LGTM of course, thanks.

>  
>  2020-05-xx - xx - lavu 56.46.100 - common.h
> 

___
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.h: split AVCodec API into its own header

2020-05-25 Thread Anton Khirnov
---
 doc/APIchanges   |   3 +
 libavcodec/Makefile  |   1 +
 libavcodec/avcodec.h | 415 +-
 libavcodec/codec.h   | 462 +++
 libavcodec/version.h |   4 +-
 5 files changed, 469 insertions(+), 416 deletions(-)
 create mode 100644 libavcodec/codec.h

diff --git a/doc/APIchanges b/doc/APIchanges
index 6a03686068..fb5534b5f5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-xx-xx - xx - lavc 58.88.100 - avcodec.h codec.h
+  Move AVCodec-related public API to new header codec.h.
+
 2020-05-23 - xx - lavu 56.49.100 - video_enc_params.h
   Add AV_VIDEO_ENC_PARAMS_H264.
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3d38b4a05d..6d816308c7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -7,6 +7,7 @@ HEADERS = ac3_parser.h  
\
   avdct.h   \
   avfft.h   \
   bsf.h \
+  codec.h   \
   codec_desc.h  \
   codec_id.h\
   codec_par.h   \
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index f10b7a06ec..4f46a1fb2e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -42,6 +42,7 @@
 #include "libavutil/rational.h"
 
 #include "bsf.h"
+#include "codec.h"
 #include "codec_desc.h"
 #include "codec_par.h"
 #include "codec_id.h"
@@ -393,138 +394,6 @@ typedef struct RcOverride{
 /* /Fx */
 /* codec capabilities */
 
-/**
- * Decoder can use draw_horiz_band callback.
- */
-#define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 <<  0)
-/**
- * Codec uses get_buffer() for allocating buffers and supports custom 
allocators.
- * If not set, it might not use get_buffer() at all or use operations that
- * assume the buffer was allocated by avcodec_default_get_buffer.
- */
-#define AV_CODEC_CAP_DR1 (1 <<  1)
-#define AV_CODEC_CAP_TRUNCATED   (1 <<  3)
-/**
- * Encoder or decoder requires flushing with NULL input at the end in order to
- * give the complete and correct output.
- *
- * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
- *   with NULL data. The user can still send NULL data to the public encode
- *   or decode function, but libavcodec will not pass it along to the codec
- *   unless this flag is set.
- *
- * Decoders:
- * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
- * avpkt->size=0 at the end to get the delayed data until the decoder no longer
- * returns frames.
- *
- * Encoders:
- * The encoder needs to be fed with NULL data at the end of encoding until the
- * encoder no longer returns data.
- *
- * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
- *   flag also means that the encoder must set the pts and duration for
- *   each output packet. If this flag is not set, the pts and duration will
- *   be determined by libavcodec from the input frame.
- */
-#define AV_CODEC_CAP_DELAY   (1 <<  5)
-/**
- * Codec can be fed a final frame with a smaller size.
- * This can be used to prevent truncation of the last audio samples.
- */
-#define AV_CODEC_CAP_SMALL_LAST_FRAME(1 <<  6)
-
-/**
- * Codec can output multiple frames per AVPacket
- * Normally demuxers return one frame at a time, demuxers which do not do
- * are connected to a parser to split what they return into proper frames.
- * This flag is reserved to the very rare category of codecs which have a
- * bitstream that cannot be split into frames without timeconsuming
- * operations like full decoding. Demuxers carrying such bitstreams thus
- * may return multiple frames in a packet. This has many disadvantages like
- * prohibiting stream copy in many cases thus it should only be considered
- * as a last resort.
- */
-#define AV_CODEC_CAP_SUBFRAMES   (1 <<  8)
-/**
- * Codec is experimental and is thus avoided in favor of non experimental
- * encoders
- */
-#define AV_CODEC_CAP_EXPERIMENTAL(1 <<  9)
-/**
- * Codec should fill in channel configuration and samplerate instead of 
container
- */
-#define AV_CODEC_CAP_CHANNEL_CONF(1 << 10)
-/**
- * Codec supports frame-level multithreading.
- */
-#define AV_CODEC_CAP_FRAME_THREADS   (1 << 12)
-/**
- * Codec supports slice-based (or partition-based) multithreading.
- */
-#define AV_CODEC_CAP_SLICE_THREADS   (1 << 13)
-/**
- * Codec supports changed parameters at any point.
- */
-#define AV_CODEC_CAP_PARAM_CHANGE(1 << 14)
-/**
- * Codec supports avctx->thread_count 

[FFmpeg-devel] [PATCH 1/3] doc/APIchanges: fix typo in version number

2020-05-25 Thread Anton Khirnov
---
 doc/APIchanges | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 56ec9f8ac3..6a03686068 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -31,7 +31,7 @@ API changes, most recent first:
   Move AVBitstreamFilter-related public API to new header bsf.h.
   Move AVCodecParameters-related public API to new header codec_par.h.
 
-2020-05-xx - xx - lavc 56.86.101 - avcodec.h
+2020-05-xx - xx - lavc 58.86.101 - avcodec.h
   Deprecated AV_CODEC_CAP_INTRA_ONLY and AV_CODEC_CAP_LOSSLESS.
 
 2020-05-xx - xx - lavu 56.46.100 - common.h
-- 
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/3] avcodec.h: move avcodec_get_{type, name} to codec_id.h

2020-05-25 Thread Anton Khirnov
---
 libavcodec/avcodec.h  | 11 ---
 libavcodec/codec_id.h | 12 
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 4f46a1fb2e..01099bc8cd 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4115,17 +4115,6 @@ attribute_deprecated
 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
 #endif
 
-/**
- * Get the type of the given codec.
- */
-enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
-
-/**
- * Get the name of a codec.
- * @return  a static string identifying the codec; never NULL
- */
-const char *avcodec_get_name(enum AVCodecID id);
-
 /**
  * @return a positive value if s is open (i.e. avcodec_open2() was called on it
  * with no corresponding avcodec_close()), 0 otherwise.
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index e95737c0a2..f7cb0a6056 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -21,6 +21,8 @@
 #ifndef AVCODEC_CODEC_ID_H
 #define AVCODEC_CODEC_ID_H
 
+#include "libavutil/avutil.h"
+
 /**
  * @addtogroup lavc_core
  * @{
@@ -556,6 +558,16 @@ enum AVCodecID {
 AV_CODEC_ID_WRAPPED_AVFRAME = 0x21001, ///< Passthrough codec, AVFrames 
wrapped in AVPacket
 };
 
+/**
+ * Get the type of the given codec.
+ */
+enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
+
+/**
+ * Get the name of a codec.
+ * @return  a static string identifying the codec; never NULL
+ */
+const char *avcodec_get_name(enum AVCodecID id);
 
 /**
  * @}
-- 
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/3] avformat/rtpproto: use av_dict_set_int() instead

2020-05-25 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavformat/rtpproto.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 1f0a82ac7e..8b6c895222 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -301,8 +301,7 @@ static int rtp_open(URLContext *h, const char *uri, int 
flags)
 goto fail;
 }
 if (s->ttl > 0) {
-snprintf(buf, sizeof (buf), "%d", s->ttl);
-av_dict_set(_opts, "ttl", buf, 0);
+av_dict_set_int(_opts, "ttl", s->ttl, 0);
 }
 }
 
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 1/3] avformat/rtspdec: use av_dict_set_int() instead

2020-05-25 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavformat/rtspdec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index bd2e8f47f1..dfa29913bf 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -289,9 +289,7 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, 
char *controlurl)
 } else {
 do {
 AVDictionary *opts = NULL;
-char buf[256];
-snprintf(buf, sizeof(buf), "%d", rt->buffer_size);
-av_dict_set(, "buffer_size", buf, 0);
+av_dict_set_int(, "buffer_size", rt->buffer_size, 0);
 ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL);
 av_log(s, AV_LOG_TRACE, "Opening: %s", url);
 ret = ffurl_open_whitelist(_st->rtp_handle, url, 
AVIO_FLAG_READ_WRITE,
-- 
2.21.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] avformat: Replace ffurl_close() by ffurl_closep() where appropriate

2020-05-25 Thread Andreas Rheinhardt
Anton Khirnov:
> Quoting Andreas Rheinhardt (2020-05-25 08:27:44)
>> It avoids leaving dangling pointers behind in memory.
>>
>> Also remove redundant checks for whether the URLContext to be closed is
>> already NULL.
>>
>> Signed-off-by: Andreas Rheinhardt 
> 
> Looks very nice.
> 
Applied. Thanks.

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

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

[FFmpeg-devel] [PATCH 1/2] mfenc: Remove an unused include

2020-05-25 Thread Martin Storsjö
This might have been used originally for the decoder parts of
the MediaFoundation wrapper, which aren't merged yet.
---
 libavcodec/mfenc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 83f26b3cc6..3432d48f30 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -26,9 +26,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/time.h"
-
-// Include after mf_utils.h due to Windows include mess.
-#include "mpeg4audio.h"
+#include "internal.h"
 
 typedef struct MFContext {
 AVClass *av_class;
-- 
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] mfenc: Avoid including codecapi.h, fix building in UWP mode with clang

2020-05-25 Thread Martin Storsjö
Including codecapi.h and uuids.h in UWP mode doesn't define all defines
properly, ending up with constructs that MSVC silently tolerates, but
that clang errors out on, like this:
DEFINE_GUIDEX(CODECAPI_AVEncCommonFormatConstraint);

Just avoid including codecapi.h completely and hardcode the last few
enum values we use from there. We already use local versions of most
enums from there, due to older mingw-w64 headers being incomplete.
---
 libavcodec/mf_utils.h | 15 +++
 libavcodec/mfenc.c|  6 +++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mf_utils.h b/libavcodec/mf_utils.h
index 4373e62ed2..d514723c3b 100644
--- a/libavcodec/mf_utils.h
+++ b/libavcodec/mf_utils.h
@@ -28,15 +28,12 @@
 // of including it though, through strmif.h via dshow.h. And on mingw, the
 // mf*.h headers below indirectly include strmif.h.)
 #include 
-// Clang in MSVC mode fails on codecapi.h if we haven't included uuids.h
-// before, while it seems to work fine with MSVC itself.
-#include 
 #else
 #include 
-#endif
 // Older versions of mingw-w64 need codecapi.h explicitly included, while newer
 // ones include it implicitly from dshow.h (via uuids.h).
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -134,6 +131,16 @@ enum {
 ff_METransformMarker,
 };
 
+// These do exist in all supported headers, but are manually defined here
+// to avoid having to include codecapi.h, as there's problems including that
+// header when targeting UWP (where including it with MSVC seems to work,
+// but fails when built with clang in MSVC mode).
+enum ff_eAVEncH264VProfile {
+   ff_eAVEncH264VProfile_Base = 66,
+   ff_eAVEncH264VProfile_Main = 77,
+   ff_eAVEncH264VProfile_High = 100,
+};
+
 char *ff_hr_str_buf(char *buf, size_t size, HRESULT hr);
 #define ff_hr_str(hr) ff_hr_str_buf((char[80]){0}, 80, hr)
 
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 3432d48f30..ee3c164e69 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -651,13 +651,13 @@ static int mf_encv_output_adjust(AVCodecContext *avctx, 
IMFMediaType *type)
 
 // (MS HEVC supports eAVEncH265VProfile_Main_420_8 only.)
 if (avctx->codec_id == AV_CODEC_ID_H264) {
-UINT32 profile = eAVEncH264VProfile_Base;
+UINT32 profile = ff_eAVEncH264VProfile_Base;
 switch (avctx->profile) {
 case FF_PROFILE_H264_MAIN:
-profile = eAVEncH264VProfile_Main;
+profile = ff_eAVEncH264VProfile_Main;
 break;
 case FF_PROFILE_H264_HIGH:
-profile = eAVEncH264VProfile_High;
+profile = ff_eAVEncH264VProfile_High;
 break;
 }
 IMFAttributes_SetUINT32(type, _MT_MPEG2_PROFILE, profile);
-- 
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] avformat: Replace ffurl_close() by ffurl_closep() where appropriate

2020-05-25 Thread Anton Khirnov
Quoting Andreas Rheinhardt (2020-05-25 08:27:44)
> It avoids leaving dangling pointers behind in memory.
> 
> Also remove redundant checks for whether the URLContext to be closed is
> already NULL.
> 
> Signed-off-by: Andreas Rheinhardt 

Looks very nice.

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

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

Re: [FFmpeg-devel] [PATCH v5] libavformat/flacdec: Workaround for truncated metadata picture size

2020-05-25 Thread Mattias Wadman
Hello, ok to merge?

On Tue, May 19, 2020 at 11:27 AM Mattias Wadman
 wrote:
>
> Some flac muxers write truncated metadata picture size if the picture
> data do not fit in 24 bits. Detect this by truncting the size found inside
> the picture block and if it matches the block size use it and read rest
> of picture data.
>
> This workaround is only for flac files and not ogg files with flac
> METADATA_BLOCK_PICTURE comments and it can be disabled with strict level
> above normal. Currently there is a 500MB limit on truncate size to protect
> from large memory allocations.
>
> The truncation bug in lavf flacenc was fixed in 
> e447a4d112bcfee10126c54eb4481fa8712957c8
> but based on existing broken files other unknown flac muxers seems to 
> truncate also.
> Before the fix a broken flac file for reproduction could be generated with:
> ffmpeg -f lavfi -i sine -f lavfi -i color=red:size=2400x2400 -map 0:0 -map 
> 1:0 -c:v:0 bmp -disposition:1 attached_pic -t 1 test.flac
>
> Fixes ticket 6333
> ---
>  libavformat/flac_picture.c   | 47 ++--
>  libavformat/flac_picture.h   |  2 +-
>  libavformat/flacdec.c|  2 +-
>  libavformat/oggparsevorbis.c |  2 +-
>  4 files changed, 42 insertions(+), 11 deletions(-)
>
> diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
> index 81ddf80465..53e24b28b7 100644
> --- a/libavformat/flac_picture.c
> +++ b/libavformat/flac_picture.c
> @@ -27,7 +27,9 @@
>  #include "id3v2.h"
>  #include "internal.h"
>
> -int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
> +#define MAX_TRUNC_PICTURE_SIZE (500 * 1024 * 1024)
> +
> +int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, 
> int truncate_workaround)
>  {
>  const CodecMime *mime = ff_id3v2_mime_tags;
>  enum AVCodecID id = AV_CODEC_ID_NONE;
> @@ -36,7 +38,8 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, 
> int buf_size)
>  GetByteContext g;
>  AVStream *st;
>  int width, height, ret = 0;
> -unsigned int len, type;
> +unsigned int type;
> +uint32_t len, left, trunclen = 0;
>
>  if (buf_size < 34) {
>  av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> short\n");
> @@ -114,16 +117,44 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t 
> *buf, int buf_size)
>
>  /* picture data */
>  len = bytestream2_get_be32u();
> -if (len <= 0 || len > bytestream2_get_bytes_left()) {
> -av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> short\n");
> -if (s->error_recognition & AV_EF_EXPLODE)
> -ret = AVERROR_INVALIDDATA;
> -goto fail;
> +
> +left = bytestream2_get_bytes_left();
> +if (len <= 0 || len > left) {
> +if (len > MAX_TRUNC_PICTURE_SIZE || len >= INT_MAX - 
> AV_INPUT_BUFFER_PADDING_SIZE) {
> +av_log(s, AV_LOG_ERROR, "Attached picture metadata block too big 
> %u\n", len);
> +if (s->error_recognition & AV_EF_EXPLODE)
> +ret = AVERROR_INVALIDDATA;
> +goto fail;
> +}
> +
> +// Workaround bug for flac muxers that writs truncated metadata 
> picture block size if
> +// the picture size do not fit in 24 bits. lavf flacenc used to have 
> the issue and based
> +// on existing broken files other unknown flac muxers seems to 
> truncate also.
> +if (truncate_workaround &&
> +s->strict_std_compliance <= FF_COMPLIANCE_NORMAL &&
> +len > left && (len & 0xff) == left) {
> +av_log(s, AV_LOG_INFO, "Correcting truncated metadata picture 
> size from %u to %u\n", left, len);
> +trunclen = len - left;
> +} else {
> +av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> short\n");
> +if (s->error_recognition & AV_EF_EXPLODE)
> +ret = AVERROR_INVALIDDATA;
> +goto fail;
> +}
>  }
>  if (!(data = av_buffer_alloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
>  RETURN_ERROR(AVERROR(ENOMEM));
>  }
> -bytestream2_get_bufferu(, data->data, len);
> +
> +if (trunclen == 0) {
> +bytestream2_get_bufferu(, data->data, len);
> +} else {
> +// If truncation was detected copy all data from block and read 
> missing bytes
> +// not included in the block size
> +bytestream2_get_bufferu(, data->data, left);
> +if (avio_read(s->pb, data->data + len - trunclen, trunclen) < 
> trunclen)
> +RETURN_ERROR(AVERROR_INVALIDDATA);
> +}
>  memset(data->data + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>
>  if (AV_RB64(data->data) == PNGSIG)
> diff --git a/libavformat/flac_picture.h b/libavformat/flac_picture.h
> index 4374b6f4f6..61fd0c8806 100644
> --- a/libavformat/flac_picture.h
> +++ b/libavformat/flac_picture.h
> @@ -26,6 +26,6 @@
>
>  #define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0)
>
> -int 

[FFmpeg-devel] [PATCH v2 2/2] lavfi/aiir: Refine the pad/vpad related operation

2020-05-25 Thread Jun Zhao
From: Jun Zhao 

move the pad/vpad related operation with more natural
coding style.

Signed-off-by: Jun Zhao 
---
 libavfilter/af_aiir.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavfilter/af_aiir.c b/libavfilter/af_aiir.c
index 92ff348..7971cf2 100644
--- a/libavfilter/af_aiir.c
+++ b/libavfilter/af_aiir.c
@@ -1153,6 +1153,10 @@ static av_cold int init(AVFilterContext *ctx)
 if (!pad.name)
 return AVERROR(ENOMEM);
 
+ret = ff_insert_outpad(ctx, 0, );
+if (ret < 0)
+return ret;
+
 if (s->response) {
 vpad = (AVFilterPad){
 .name = av_strdup("filter_response"),
@@ -1161,13 +1165,7 @@ static av_cold int init(AVFilterContext *ctx)
 };
 if (!vpad.name)
 return AVERROR(ENOMEM);
-}
 
-ret = ff_insert_outpad(ctx, 0, );
-if (ret < 0)
-return ret;
-
-if (s->response) {
 ret = ff_insert_outpad(ctx, 1, );
 if (ret < 0)
 return ret;
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v2 1/2] lavfi/afir: fix vpad.name leak

2020-05-25 Thread Jun Zhao
From: Jun Zhao 

Fix vpad.name leak in error path, move the vpad related operation
only if enabled show IR frequency response.

Signed-off-by: Jun Zhao 
---
 libavfilter/af_afir.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index 7c7e845..5ba880f 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -876,6 +876,12 @@ static av_cold int init(AVFilterContext *ctx)
 if (!pad.name)
 return AVERROR(ENOMEM);
 
+ret = ff_insert_outpad(ctx, 0, );
+if (ret < 0) {
+av_freep();
+return ret;
+}
+
 if (s->response) {
 vpad = (AVFilterPad){
 .name = av_strdup("filter_response"),
@@ -884,15 +890,7 @@ static av_cold int init(AVFilterContext *ctx)
 };
 if (!vpad.name)
 return AVERROR(ENOMEM);
-}
 
-ret = ff_insert_outpad(ctx, 0, );
-if (ret < 0) {
-av_freep();
-return ret;
-}
-
-if (s->response) {
 ret = ff_insert_outpad(ctx, 1, );
 if (ret < 0) {
 av_freep();
-- 
2.7.4

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

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

Re: [FFmpeg-devel] [PATCH] lavfi/afir: fix vpad.name leak

2020-05-25 Thread myp...@gmail.com
On Mon, May 25, 2020 at 3:51 PM Paul B Mahol  wrote:
>
> typo in commit message.
Will fix, tks
>
> On 5/25/20, Jun Zhao  wrote:
> > From: Jun Zhao 
> >
> > Fixed vpad.name leak in error path, move the vpad related operation
> > only if enabeled show IR frequency response.
> >
> > Signed-off-by: Jun Zhao 
> > ---
> >  libavfilter/af_afir.c | 14 ++
> >  1 file changed, 6 insertions(+), 8 deletions(-)
> >
> > diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
> > index 7c7e845..5ba880f 100644
> > --- a/libavfilter/af_afir.c
> > +++ b/libavfilter/af_afir.c
> > @@ -876,6 +876,12 @@ static av_cold int init(AVFilterContext *ctx)
> >  if (!pad.name)
> >  return AVERROR(ENOMEM);
> >
> > +ret = ff_insert_outpad(ctx, 0, );
> > +if (ret < 0) {
> > +av_freep();
> > +return ret;
> > +}
> > +
> >  if (s->response) {
> >  vpad = (AVFilterPad){
> >  .name = av_strdup("filter_response"),
> > @@ -884,15 +890,7 @@ static av_cold int init(AVFilterContext *ctx)
> >  };
> >  if (!vpad.name)
> >  return AVERROR(ENOMEM);
> > -}
> >
> > -ret = ff_insert_outpad(ctx, 0, );
> > -if (ret < 0) {
> > -av_freep();
> > -return ret;
> > -}
> > -
> > -if (s->response) {
> >  ret = ff_insert_outpad(ctx, 1, );
> >  if (ret < 0) {
> >  av_freep();
> > --
> > 2.7.4
> >
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] lavfi/afir: fix vpad.name leak

2020-05-25 Thread Paul B Mahol
typo in commit message.

On 5/25/20, Jun Zhao  wrote:
> From: Jun Zhao 
>
> Fixed vpad.name leak in error path, move the vpad related operation
> only if enabeled show IR frequency response.
>
> Signed-off-by: Jun Zhao 
> ---
>  libavfilter/af_afir.c | 14 ++
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
> index 7c7e845..5ba880f 100644
> --- a/libavfilter/af_afir.c
> +++ b/libavfilter/af_afir.c
> @@ -876,6 +876,12 @@ static av_cold int init(AVFilterContext *ctx)
>  if (!pad.name)
>  return AVERROR(ENOMEM);
>
> +ret = ff_insert_outpad(ctx, 0, );
> +if (ret < 0) {
> +av_freep();
> +return ret;
> +}
> +
>  if (s->response) {
>  vpad = (AVFilterPad){
>  .name = av_strdup("filter_response"),
> @@ -884,15 +890,7 @@ static av_cold int init(AVFilterContext *ctx)
>  };
>  if (!vpad.name)
>  return AVERROR(ENOMEM);
> -}
>
> -ret = ff_insert_outpad(ctx, 0, );
> -if (ret < 0) {
> -av_freep();
> -return ret;
> -}
> -
> -if (s->response) {
>  ret = ff_insert_outpad(ctx, 1, );
>  if (ret < 0) {
>  av_freep();
> --
> 2.7.4
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH] avformat: Replace ffurl_close() by ffurl_closep() where appropriate

2020-05-25 Thread Andreas Rheinhardt
It avoids leaving dangling pointers behind in memory.

Also remove redundant checks for whether the URLContext to be closed is
already NULL.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/async.c   |  4 ++--
 libavformat/cache.c   |  2 +-
 libavformat/concat.c  |  2 +-
 libavformat/crypto.c  |  3 +--
 libavformat/gopher.c  |  5 +
 libavformat/hlsproto.c|  5 ++---
 libavformat/icecast.c |  3 +--
 libavformat/mmsh.c|  5 ++---
 libavformat/mmst.c|  2 +-
 libavformat/rtmpcrypt.c   |  2 +-
 libavformat/rtmphttp.c|  2 +-
 libavformat/rtmpproto.c   |  5 ++---
 libavformat/rtpproto.c| 10 --
 libavformat/rtsp.c| 17 +++--
 libavformat/sapdec.c  |  3 +--
 libavformat/sapenc.c  |  3 +--
 libavformat/smoothstreamingenc.c  | 19 ++-
 libavformat/srtpproto.c   |  3 +--
 libavformat/subfile.c |  4 ++--
 libavformat/tls_gnutls.c  |  3 +--
 libavformat/tls_libtls.c  |  3 +--
 libavformat/tls_openssl.c |  3 +--
 libavformat/tls_schannel.c|  3 +--
 libavformat/tls_securetransport.c |  3 +--
 24 files changed, 43 insertions(+), 71 deletions(-)

diff --git a/libavformat/async.c b/libavformat/async.c
index 4e295b5e10..a0bdfa2ee3 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -293,7 +293,7 @@ cond_wakeup_background_fail:
 cond_wakeup_main_fail:
 pthread_mutex_destroy(>mutex);
 mutex_fail:
-ffurl_close(c->inner);
+ffurl_closep(>inner);
 url_fail:
 ring_destroy(>ring);
 fifo_fail:
@@ -317,7 +317,7 @@ static int async_close(URLContext *h)
 pthread_cond_destroy(>cond_wakeup_background);
 pthread_cond_destroy(>cond_wakeup_main);
 pthread_mutex_destroy(>mutex);
-ffurl_close(c->inner);
+ffurl_closep(>inner);
 ring_destroy(>ring);
 
 return 0;
diff --git a/libavformat/cache.c b/libavformat/cache.c
index 09e5d5f832..1e19dafc6a 100644
--- a/libavformat/cache.c
+++ b/libavformat/cache.c
@@ -310,7 +310,7 @@ static int cache_close(URLContext *h)
 av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename);
 av_freep(>filename);
 }
-ffurl_close(c->inner);
+ffurl_closep(>inner);
 av_tree_enumerate(c->root, NULL, NULL, enu_free);
 av_tree_destroy(c->root);
 
diff --git a/libavformat/concat.c b/libavformat/concat.c
index cfe14760eb..418405dd50 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -49,7 +49,7 @@ static av_cold int concat_close(URLContext *h)
 struct concat_nodes *nodes = data->nodes;
 
 for (i = 0; i != data->length; i++)
-err |= ffurl_close(nodes[i].uc);
+err |= ffurl_closep([i].uc);
 
 av_freep(>nodes);
 
diff --git a/libavformat/crypto.c b/libavformat/crypto.c
index 9a48f2e6f5..31f9ac0ab9 100644
--- a/libavformat/crypto.c
+++ b/libavformat/crypto.c
@@ -385,8 +385,7 @@ static int crypto_close(URLContext *h)
 ret = ffurl_write(c->hd, out_buf, BLOCKSIZE);
 }
 
-if (c->hd)
-ffurl_close(c->hd);
+ffurl_closep(>hd);
 av_freep(>aes_decrypt);
 av_freep(>aes_encrypt);
 av_freep(>write_buf);
diff --git a/libavformat/gopher.c b/libavformat/gopher.c
index 3070b24caf..8b6d14a1f7 100644
--- a/libavformat/gopher.c
+++ b/libavformat/gopher.c
@@ -68,10 +68,7 @@ static int gopher_connect(URLContext *h, const char *path)
 static int gopher_close(URLContext *h)
 {
 GopherContext *s = h->priv_data;
-if (s->hd) {
-ffurl_close(s->hd);
-s->hd = NULL;
-}
+ffurl_closep(>hd);
 return 0;
 }
 
diff --git a/libavformat/hlsproto.c b/libavformat/hlsproto.c
index e5673e5e03..de45f771d6 100644
--- a/libavformat/hlsproto.c
+++ b/libavformat/hlsproto.c
@@ -178,7 +178,7 @@ static int hls_close(URLContext *h)
 
 free_segment_list(s);
 free_variant_list(s);
-ffurl_close(s->seg_hd);
+ffurl_closep(>seg_hd);
 return 0;
 }
 
@@ -260,8 +260,7 @@ start:
 return ret;
 }
 if (s->seg_hd) {
-ffurl_close(s->seg_hd);
-s->seg_hd = NULL;
+ffurl_closep(>seg_hd);
 s->cur_seq_no++;
 }
 reload_interval = s->n_segments > 0 ?
diff --git a/libavformat/icecast.c b/libavformat/icecast.c
index 7d8f92fe73..38af16b99e 100644
--- a/libavformat/icecast.c
+++ b/libavformat/icecast.c
@@ -75,8 +75,7 @@ static void cat_header(AVBPrint *bp, const char key[], const 
char value[])
 static int icecast_close(URLContext *h)
 {
 IcecastContext *s = h->priv_data;
-if (s->hd)
-ffurl_close(s->hd);
+ffurl_closep(>hd);
 return 0;
 }
 
diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c
index 13c0ffe438..495d7fb73b 100644
--- a/libavformat/mmsh.c
+++ b/libavformat/mmsh.c
@@ -65,8 +65,7 @@ static int mmsh_close(URLContext *h)
 {
 MMSHContext *mmsh = (MMSHContext *)h->priv_data;
 MMSContext *mms   =