Re: [FFmpeg-devel] [PATCH v2] lavu/frame: add QP side data

2018-03-14 Thread wm4
On Fri,  2 Mar 2018 12:16:37 +0100
wm4  wrote:

> This adds a way for an API user to transfer QP data and metadata without
> having to keep the reference to AVFrame, and without having to
> explicitly care about QP APIs. It might also provide a way to finally
> remove the deprecated QP related fields. In the end, the QP table should
> be handled in a very similar way to e.g. AV_FRAME_DATA_MOTION_VECTORS.
> 
> There are two side data types, because I didn't care about having to
> repack the QP data so the table and the metadata are in a single
> AVBufferRef. Otherwise it would have either required a copy on decoding
> (extra slowdown for something as obscure as the QP data), or would have
> required making intrusive changes to the codecs which support export of
> this data.
> 
> The new side data types are added under deprecation guards, because I
> don't intend to change the status of the QP export as being deprecated
> (as it was before this patch too).
> ---
>  libavutil/frame.c  | 59 
> ++
>  libavutil/frame.h  | 17 +++
>  tests/ref/fate/exif-image-embedded |  6 
>  tests/ref/fate/exif-image-jpg  | 34 +-
>  4 files changed, 96 insertions(+), 20 deletions(-)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 0db2a2d57b..ea13cd3ed6 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -46,8 +46,17 @@ MAKE_ACCESSORS(AVFrame, frame, enum AVColorRange, 
> color_range)
> av_get_channel_layout_nb_channels((frame)->channel_layout))
>  
>  #if FF_API_FRAME_QP
> +struct qp_properties {
> +int stride;
> +int type;
> +};
> +
>  int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int 
> qp_type)
>  {
> +struct qp_properties *p;
> +AVFrameSideData *sd;
> +AVBufferRef *ref;
> +
>  FF_DISABLE_DEPRECATION_WARNINGS
>  av_buffer_unref(&f->qp_table_buf);
>  
> @@ -57,20 +66,56 @@ FF_DISABLE_DEPRECATION_WARNINGS
>  f->qscale_type  = qp_type;
>  FF_ENABLE_DEPRECATION_WARNINGS
>  
> +av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES);
> +av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA);
> +
> +ref = av_buffer_ref(buf);
> +if (!av_frame_new_side_data_from_buf(f, AV_FRAME_DATA_QP_TABLE_DATA, 
> ref)) {
> +av_buffer_unref(&ref);
> +return AVERROR(ENOMEM);
> +}
> +
> +sd = av_frame_new_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES,
> +sizeof(struct qp_properties));
> +if (!sd)
> +return AVERROR(ENOMEM);
> +
> +p = (struct qp_properties *)sd->data;
> +p->stride = stride;
> +p->type = qp_type;
> +
>  return 0;
>  }
>  
>  int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
>  {
> -FF_DISABLE_DEPRECATION_WARNINGS
> -*stride = f->qstride;
> -*type   = f->qscale_type;
> +AVBufferRef *buf = NULL;
>  
> -if (!f->qp_table_buf)
> -return NULL;
> +*stride = 0;
> +*type   = 0;
>  
> -return f->qp_table_buf->data;
> +FF_DISABLE_DEPRECATION_WARNINGS
> +if (f->qp_table_buf) {
> +*stride = f->qstride;
> +*type   = f->qscale_type;
> +buf = f->qp_table_buf;
>  FF_ENABLE_DEPRECATION_WARNINGS
> +} else {
> +AVFrameSideData *sd;
> +struct qp_properties *p;
> +sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES);
> +if (!sd)
> +return NULL;
> +p = (struct qp_properties *)sd->data;
> +sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA);
> +if (!sd)
> +return NULL;
> +*stride = p->stride;
> +*type   = p->type;
> +buf = sd->buf;
> +}
> +
> +return buf ? buf->data : NULL;
>  }
>  #endif
>  
> @@ -787,6 +832,8 @@ const char *av_frame_side_data_name(enum 
> AVFrameSideDataType type)
>  case AV_FRAME_DATA_CONTENT_LIGHT_LEVEL: return "Content light 
> level metadata";
>  case AV_FRAME_DATA_GOP_TIMECODE:return "GOP timecode";
>  case AV_FRAME_DATA_ICC_PROFILE: return "ICC profile";
> +case AV_FRAME_DATA_QP_TABLE_PROPERTIES: return "QP table 
> properties";
> +case AV_FRAME_DATA_QP_TABLE_DATA:   return "QP table data";
>  }
>  return NULL;
>  }
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index ddbac3156d..9d57d6ce66 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -141,6 +141,23 @@ enum AVFrameSideDataType {
>   * metadata key entry "name".
>   */
>  AV_FRAME_DATA_ICC_PROFILE,
> +
> +#if FF_API_FRAME_QP
> +/**
> + * Implementation-specific description of the format of 
> AV_FRAME_QP_TABLE_DATA.
> + * The contents of this side data are undocumented and internal; use
> + * av_frame_set_qp_table() and av_frame_get_qp_table() to access this in 
> a
> + * meaningful way instead.
> + */
> +AV

[FFmpeg-devel] [PATCH] libavfilter/vf_avgblur_opencl.c: add openCL version of libavfilter/vf_avgblur.c filter

2018-03-14 Thread Dylan Fernando
[master 319e56f87c] lavfi: Add OpenCL avgblur filter
 6 files changed, 381 insertions(+)
 create mode 100644 libavfilter/opencl/avgblur.cl
 create mode 100644 libavfilter/vf_avgblur_opencl.c

diff --git a/configure b/configure
index fe81ba31b5..203737615c 100755
--- a/configure
+++ b/configure
@@ -3205,6 +3205,7 @@ aresample_filter_deps="swresample"
 ass_filter_deps="libass"
 atempo_filter_deps="avcodec"
 atempo_filter_select="rdft"
+avgblur_opencl_filter_deps="opencl"
 azmq_filter_deps="libzmq"
 blackframe_filter_deps="gpl"
 boxblur_filter_deps="gpl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 6a6083618d..6bf32ad260 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -138,6 +138,8 @@ OBJS-$(CONFIG_ALPHAMERGE_FILTER) +=
vf_alphamerge.o
 OBJS-$(CONFIG_ASS_FILTER)+= vf_subtitles.o
 OBJS-$(CONFIG_ATADENOISE_FILTER) += vf_atadenoise.o
 OBJS-$(CONFIG_AVGBLUR_FILTER)+= vf_avgblur.o
+OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o
opencl.o \
+opencl/avgblur.o
 OBJS-$(CONFIG_BBOX_FILTER)   += bbox.o vf_bbox.o
 OBJS-$(CONFIG_BENCH_FILTER)  += f_bench.o
 OBJS-$(CONFIG_BITPLANENOISE_FILTER)  += vf_bitplanenoise.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9adb1090b7..cb04d1b113 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -148,6 +148,7 @@ static void register_all(void)
 REGISTER_FILTER(ASS,ass,vf);
 REGISTER_FILTER(ATADENOISE, atadenoise, vf);
 REGISTER_FILTER(AVGBLUR,avgblur,vf);
+REGISTER_FILTER(AVGBLUR_OPENCL, avgblur_opencl, vf);
 REGISTER_FILTER(BBOX,   bbox,   vf);
 REGISTER_FILTER(BENCH,  bench,  vf);
 REGISTER_FILTER(BITPLANENOISE,  bitplanenoise,  vf);
diff --git a/libavfilter/opencl/avgblur.cl b/libavfilter/opencl/avgblur.cl
new file mode 100644
index 00..fff655529b
--- /dev/null
+++ b/libavfilter/opencl/avgblur.cl
@@ -0,0 +1,60 @@
+/*
+ * 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
+ */
+
+
+__kernel void avgblur_horiz(__write_only image2d_t dst,
+__read_only  image2d_t src,
+int rad)
+{
+const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
+   CLK_FILTER_NEAREST);
+int2 loc = (int2)(get_global_id(0), get_global_id(1));
+int2 size = (int2)(get_global_size(0), get_global_size(1));
+
+int count = 0;
+float4 acc = (float4)(0,0,0,0);
+
+for (int xx = max(0,loc.x-rad); xx < min(loc.x+rad+1,size.x); xx++)
+{
+count++;
+acc += read_imagef(src, sampler, (int2)(xx, loc.y));
+}
+
+write_imagef(dst, loc, acc / count);
+}
+
+__kernel void avgblur_vert(__write_only image2d_t dst,
+   __read_only  image2d_t src,
+   int radv)
+{
+const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
+   CLK_FILTER_NEAREST);
+int2 loc = (int2)(get_global_id(0), get_global_id(1));
+int2 size = (int2)(get_global_size(0), get_global_size(1));
+
+int count = 0;
+float4 acc = (float4)(0,0,0,0);
+
+for (int yy = max(0,loc.y-radv); yy < min(loc.y+radv+1,size.y); yy++)
+{
+count++;
+acc += read_imagef(src, sampler, (int2)(loc.x, yy));
+}
+
+write_imagef(dst, loc, acc / count);
+}
diff --git a/libavfilter/opencl_source.h b/libavfilter/opencl_source.h
index 23cdfc6ac9..02bc1723b0 100644
--- a/libavfilter/opencl_source.h
+++ b/libavfilter/opencl_source.h
@@ -19,6 +19,7 @@
 #ifndef AVFILTER_OPENCL_SOURCE_H
 #define AVFILTER_OPENCL_SOURCE_H

+extern const char *ff_opencl_source_avgblur;
 extern const char *ff_opencl_source_overlay;
 extern const char *ff_opencl_source_unsharp;

diff --git a/libavfilter/vf_avgblur_opencl.c b/libavfilter/vf_avgblur_
opencl.c
new file mode 100644
index 00..6e5ae4f32e
--- /dev/null
+++ b/libavfilter/vf_avgblur_opencl.c
@@ -0,0 +1,316 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU

Re: [FFmpeg-devel] GSoC

2018-03-14 Thread Dylan Fernando
On Sun, Mar 11, 2018 at 10:18 PM, Mark Thompson  wrote:

> On 11/03/18 04:36, Dylan Fernando wrote:
> > On Thu, Mar 8, 2018 at 8:57 AM, Mark Thompson  wrote:
> >
> >> On 07/03/18 03:56, Dylan Fernando wrote:
> >>> Thanks, it works now
> >>>
> >>> Would trying to implement an OpenCL version of vf_fade be a good idea
> >> for a
> >>> qualification task, or would it be a better idea to try a different
> >> filter?
> >>
> >> That sounds like a sensible choice to me, though if you haven't written
> a
> >> filter before you might find it helpful to write something simpler
> first to
> >> understand how it fits together (for example: vflip, which has trivial
> >> processing parts but still needs the surrounding boilerplate).
> >>
> >> - Mark
> >>
> >> (PS: be aware that top-posting is generally frowned upon on this mailing
> >> list.)
> >>
> >>
> >>> On Wed, Mar 7, 2018 at 1:20 AM, Mark Thompson  wrote:
> >>>
>  On 06/03/18 12:37, Dylan Fernando wrote:
> > Hi,
> >
> > I am Dylan Fernando. I am a Computer Science student from Australia.
> I
> >> am
> > new to FFmpeg and I wish to apply for GSoC this year.
> > I would like to do the Video filtering with OpenCL project and I
> have a
>  few
> > questions. Would trying to implement an opencl version of vf_fade be
> a
>  good
> > idea for the qualification task, or would I be better off using a
>  different
> > filter?
> >
> > Also, I’m having a bit of trouble with running unsharp_opencl. I
> tried
> > running:
> > ffmpeg -hide_banner -nostats -v verbose -init_hw_device
> opencl=ocl:0.1
> > -filter_hw_device ocl -i space.mpg -filter_complex unsharp_opencl
>  output.mp4
> >
> > but I got the error:
> > [AVHWDeviceContext @ 0x7fdac050c700] 0.1: Apple / Intel(R) Iris(TM)
> > Graphics 6100
> > [mpeg @ 0x7fdac3132600] max_analyze_duration 500 reached at
> 5005000
> > microseconds st:0
> > Input #0, mpeg, from 'space.mpg':
> >   Duration: 00:00:21.99, start: 0.387500, bitrate: 6108 kb/s
> > Stream #0:0[0x1e0]: Video: mpeg2video (Main), 1 reference frame,
> > yuv420p(tv, bt470bg, bottom first, left), 720x480 [SAR 8:9 DAR 4:3],
> >> 6000
> > kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
> > Stream mapping:
> >   Stream #0:0 (mpeg2video) -> unsharp_opencl
> >   unsharp_opencl -> Stream #0:0 (mpeg4)
> > Press [q] to stop, [?] for help
> > [graph 0 input from stream 0:0 @ 0x7fdac0418800] w:720 h:480
>  pixfmt:yuv420p
> > tb:1/9 fr:3/1001 sar:8/9 sws_param:flags=2
> > [auto_scaler_0 @ 0x7fdac05232c0] w:iw h:ih flags:'bilinear' interl:0
> > [Parsed_unsharp_opencl_0 @ 0x7fdac0715a80] auto-inserting filter
> > 'auto_scaler_0' between the filter 'graph 0 input from stream 0:0'
> and
>  the
> > filter 'Parsed_unsharp_opencl_0'
> > Impossible to convert between the formats supported by the filter
> >> 'graph
>  0
> > input from stream 0:0' and the filter 'auto_scaler_0'
> > Error reinitializing filters!
> > Failed to inject frame into filter network: Function not implemented
> > Error while processing the decoded data for stream #0:0
> > Conversion failed!
> >
> > How do I correctly run unsharp_opencl? Should I be running it on a
> > different video file?
> 
>  It's intended to be used in filter graphs where much of the activity
> is
>  already happening on the GPU, so the input and output are in the
>  AV_PIX_FMT_OPENCL format which contains GPU-side OpenCL images.
> 
>  If you want to use it standalone then you need hwupload and hwdownload
>  filters to move the frames between the CPU and GPU.  For your example,
> >> it
>  should work with:
> 
>  ffmpeg -init_hw_device opencl=ocl:0.1 -filter_hw_device ocl -i
> space.mpg
>  -filter_complex hwupload,unsharp_opencl,hwdownload output.mp4
> 
>  (There are constraints on what formats can be used and therefore
> >> suitable
>  files (or required format conversions), but I believe a normal yuv420p
>  video like this should work in all cases.)
> 
>  - Mark
> >>
> >
> > Thanks.
> >
> > How is AV_PIX_FMT_OPENCL formatted? When using read_imagef(), does xyzw
> > correspond to RGBA respectively, or to YUV? Would I have to account for
> > different formats? If so, how do I check the format of the input?
>
> See libavutil/hwcontext_opencl.c and in particular the functions
> opencl_get_buffer(), opencl_pool_alloc() and opencl_get_plane_format() for
> the code creating the AV_PIX_FMT_OPENCL images.
>
> It tries to support all formats which are representable as OpenCL images,
> so the component values are dependent on what the format of the underlying
> image is.  What can actually be represented does depends a bit on the
> implementation - for example, CL_R channel order is needed for all planar
> YUV images, and CL_RG is needed as well for NV12 and P010 support.  Th

Re: [FFmpeg-devel] GSoC

2018-03-14 Thread Dylan Fernando
On Thu, Mar 15, 2018 at 12:08 PM, Dylan Fernando 
wrote:

>
>
> On Sun, Mar 11, 2018 at 10:18 PM, Mark Thompson  wrote:
>
>> On 11/03/18 04:36, Dylan Fernando wrote:
>> > On Thu, Mar 8, 2018 at 8:57 AM, Mark Thompson  wrote:
>> >
>> >> On 07/03/18 03:56, Dylan Fernando wrote:
>> >>> Thanks, it works now
>> >>>
>> >>> Would trying to implement an OpenCL version of vf_fade be a good idea
>> >> for a
>> >>> qualification task, or would it be a better idea to try a different
>> >> filter?
>> >>
>> >> That sounds like a sensible choice to me, though if you haven't
>> written a
>> >> filter before you might find it helpful to write something simpler
>> first to
>> >> understand how it fits together (for example: vflip, which has trivial
>> >> processing parts but still needs the surrounding boilerplate).
>> >>
>> >> - Mark
>> >>
>> >> (PS: be aware that top-posting is generally frowned upon on this
>> mailing
>> >> list.)
>> >>
>> >>
>> >>> On Wed, Mar 7, 2018 at 1:20 AM, Mark Thompson  wrote:
>> >>>
>>  On 06/03/18 12:37, Dylan Fernando wrote:
>> > Hi,
>> >
>> > I am Dylan Fernando. I am a Computer Science student from
>> Australia. I
>> >> am
>> > new to FFmpeg and I wish to apply for GSoC this year.
>> > I would like to do the Video filtering with OpenCL project and I
>> have a
>>  few
>> > questions. Would trying to implement an opencl version of vf_fade
>> be a
>>  good
>> > idea for the qualification task, or would I be better off using a
>>  different
>> > filter?
>> >
>> > Also, I’m having a bit of trouble with running unsharp_opencl. I
>> tried
>> > running:
>> > ffmpeg -hide_banner -nostats -v verbose -init_hw_device
>> opencl=ocl:0.1
>> > -filter_hw_device ocl -i space.mpg -filter_complex unsharp_opencl
>>  output.mp4
>> >
>> > but I got the error:
>> > [AVHWDeviceContext @ 0x7fdac050c700] 0.1: Apple / Intel(R) Iris(TM)
>> > Graphics 6100
>> > [mpeg @ 0x7fdac3132600] max_analyze_duration 500 reached at
>> 5005000
>> > microseconds st:0
>> > Input #0, mpeg, from 'space.mpg':
>> >   Duration: 00:00:21.99, start: 0.387500, bitrate: 6108 kb/s
>> > Stream #0:0[0x1e0]: Video: mpeg2video (Main), 1 reference frame,
>> > yuv420p(tv, bt470bg, bottom first, left), 720x480 [SAR 8:9 DAR 4:3],
>> >> 6000
>> > kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
>> > Stream mapping:
>> >   Stream #0:0 (mpeg2video) -> unsharp_opencl
>> >   unsharp_opencl -> Stream #0:0 (mpeg4)
>> > Press [q] to stop, [?] for help
>> > [graph 0 input from stream 0:0 @ 0x7fdac0418800] w:720 h:480
>>  pixfmt:yuv420p
>> > tb:1/9 fr:3/1001 sar:8/9 sws_param:flags=2
>> > [auto_scaler_0 @ 0x7fdac05232c0] w:iw h:ih flags:'bilinear' interl:0
>> > [Parsed_unsharp_opencl_0 @ 0x7fdac0715a80] auto-inserting filter
>> > 'auto_scaler_0' between the filter 'graph 0 input from stream 0:0'
>> and
>>  the
>> > filter 'Parsed_unsharp_opencl_0'
>> > Impossible to convert between the formats supported by the filter
>> >> 'graph
>>  0
>> > input from stream 0:0' and the filter 'auto_scaler_0'
>> > Error reinitializing filters!
>> > Failed to inject frame into filter network: Function not implemented
>> > Error while processing the decoded data for stream #0:0
>> > Conversion failed!
>> >
>> > How do I correctly run unsharp_opencl? Should I be running it on a
>> > different video file?
>> 
>>  It's intended to be used in filter graphs where much of the activity
>> is
>>  already happening on the GPU, so the input and output are in the
>>  AV_PIX_FMT_OPENCL format which contains GPU-side OpenCL images.
>> 
>>  If you want to use it standalone then you need hwupload and
>> hwdownload
>>  filters to move the frames between the CPU and GPU.  For your
>> example,
>> >> it
>>  should work with:
>> 
>>  ffmpeg -init_hw_device opencl=ocl:0.1 -filter_hw_device ocl -i
>> space.mpg
>>  -filter_complex hwupload,unsharp_opencl,hwdownload output.mp4
>> 
>>  (There are constraints on what formats can be used and therefore
>> >> suitable
>>  files (or required format conversions), but I believe a normal
>> yuv420p
>>  video like this should work in all cases.)
>> 
>>  - Mark
>> >>
>> >
>> > Thanks.
>> >
>> > How is AV_PIX_FMT_OPENCL formatted? When using read_imagef(), does xyzw
>> > correspond to RGBA respectively, or to YUV? Would I have to account for
>> > different formats? If so, how do I check the format of the input?
>>
>> See libavutil/hwcontext_opencl.c and in particular the functions
>> opencl_get_buffer(), opencl_pool_alloc() and opencl_get_plane_format() for
>> the code creating the AV_PIX_FMT_OPENCL images.
>>
>> It tries to support all formats which are representable as OpenCL images,
>> so the component values are dependent on what the format of the underlying
>> image is.  What ca

Re: [FFmpeg-devel] [PATCH] libavfilter: Add OpenCL convolution filter v0.1

2018-03-14 Thread Mark Thompson
On 14/03/18 09:43, Danil Iashchenko wrote:
> Behaves like the existing convolution filter, except working on OpenCL
> hardware frames.
> Takes exactly the same options: 4 convolution matrices, 4 rdiv values, 4 bias 
> values.
> If not specified, default parameters are applied.
> Matrices can be different sizes.
> 
> NEW IN THIS PATCH:
> -fixed bug, if matrices have different dims.
> -renamed some variables due to readability.
> 
> filter applies:
> matrix0, rdiv0, bias0 to image plane0.
> matrix1, rdiv1, bias1 to image plane1.
> matrix2, rdiv2, bias2 to image plane2.
> matrix3, rdiv3, bias3 to image plane3.
> 
> About Kernel parameters:
> dst - destination image
> src - source image
> coef_matrices_dims - stores dimensions of matrix{0..3} consecutively one 
> after the other
> coef_matrices - stores matrices{0..3} consecutively one after the other
> rdivs - stores rdiv{0..3} parameters consecutively one after the other
> biases - stores bias{0..3} parameters consecutively one after the other
> 
> About sscanf. I had (!err_code) condition, because I would never get empty 
> line
> as option(if not specified, I always have default matrix), but changed to 
> (err_code != 1) due to read-ability.
> Also, before sscanf I split matrix with spaces, so I process each single value
> of matrix seperately from others and check if they are ok.

My logic here is that you want to make sure that exactly one argument has been 
converted, so checking for != 1 is the right thing to do for errors.  Even if 
you can argue that == 0 is the only possible error case and other error cases 
can't possibly happen, someone reading the code also has to think about that in 
the same way to be able to convince themselves that there isn't an error, where 
if you wrote != 1 they wouldn't need to think about it at all.

(To offer a counterexample to the suggestion that you couldn't get -1 from 
sscanf() in the previous code, note that it only split for ' ' so it would fail 
on other whitespace.  E.g. "1 2 3 4   6 7 8 9" (tab in the middle) would be 
accepted as a matrix and then invoke undefined behaviour reading the 
uninitialised value in the middle of the that matrix.)

> about rdiv_buffer, bias_buffer, dims_buffer objects: they should be buffer 
> objects, because they store sequence of values, not a single value

You only need to pass one value to each invocation of the kernel, since only 
one value is needed for each plane.

> ---
>  configure   |   1 +
>  libavfilter/Makefile|   1 +
>  libavfilter/allfilters.c|   1 +
>  libavfilter/opencl/convolution.cl   |  46 
>  libavfilter/opencl_source.h |   1 +
>  libavfilter/vf_convolution_opencl.c | 449 
> 
>  6 files changed, 499 insertions(+)
>  create mode 100644 libavfilter/opencl/convolution.cl
>  create mode 100644 libavfilter/vf_convolution_opencl.c
> 
> diff --git a/configure b/configure
> index 6916b45..bf5c312 100755
> --- a/configure
> +++ b/configure
> @@ -3210,6 +3210,7 @@ blackframe_filter_deps="gpl"
>  boxblur_filter_deps="gpl"
>  bs2b_filter_deps="libbs2b"
>  colormatrix_filter_deps="gpl"
> +convolution_opencl_filter_deps="opencl"
>  convolve_filter_deps="avcodec"
>  convolve_filter_select="fft"
>  coreimage_filter_deps="coreimage appkit"
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 6a60836..d005934 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -156,6 +156,7 @@ OBJS-$(CONFIG_COLORLEVELS_FILTER)+= 
> vf_colorlevels.o
>  OBJS-$(CONFIG_COLORMATRIX_FILTER)+= vf_colormatrix.o
>  OBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o 
> colorspacedsp.o
>  OBJS-$(CONFIG_CONVOLUTION_FILTER)+= vf_convolution.o
> +OBJS-$(CONFIG_CONVOLUTION_OPENCL_FILTER) += vf_convolution_opencl.o 
> opencl.o opencl/convolution.o
>  OBJS-$(CONFIG_CONVOLVE_FILTER)   += vf_convolve.o framesync.o
>  OBJS-$(CONFIG_COPY_FILTER)   += vf_copy.o
>  OBJS-$(CONFIG_COREIMAGE_FILTER)  += vf_coreimage.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 9adb109..f2dc55e 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -166,6 +166,7 @@ static void register_all(void)
>  REGISTER_FILTER(COLORMATRIX,colormatrix,vf);
>  REGISTER_FILTER(COLORSPACE, colorspace, vf);
>  REGISTER_FILTER(CONVOLUTION,convolution,vf);
> +REGISTER_FILTER(CONVOLUTION_OPENCL, convolution_opencl, vf);
>  REGISTER_FILTER(CONVOLVE,   convolve,   vf);
>  REGISTER_FILTER(COPY,   copy,   vf);
>  REGISTER_FILTER(COREIMAGE,  coreimage,  vf);
> diff --git a/libavfilter/opencl/convolution.cl 
> b/libavfilter/opencl/convolution.cl
> new file mode 100644
> index 000..192f1ef
> --- /dev/null
> +++ b/libavfilter/opencl/convolution.cl
> @@ -0,0 +1,46 @@
> +/*
> + * This file is part of FFmpeg

Re: [FFmpeg-devel] [PATCH] libavformat/movenc : Change MOV_TIMESCALE from 1000 to 600

2018-03-14 Thread Michael Niedermayer
On Sat, Mar 10, 2018 at 02:38:17PM +, Mark Burton wrote:
> On 9 Mar 2018, at 01:26, Carl Eugen Hoyos  wrote:
> > This breaks fate, our regression testing suite (my mistake).
> > To download the test-suite:
> > $ make SAMPLES=fate-suite fate-rsync
> > $ make SAMPLES=fate-suite GEN=1 fate
> > This changes the values for fate, then commit again with:
> > $ git commit tests libavformat
> 
> 
> Thanks Carl, I hope the below is now correct.
> 
> From 0c73563d06c05245ecf8bcaf64bc1c2809f375e4 Mon Sep 17 00:00:00 2001
> From: mwjburton 
> Date: Sat, 10 Mar 2018 14:33:02 +
> Subject: [PATCH] libavformat/movenc : Change MOV_TIMESCALE from 1000 to 600
> 
> Changing the MOV_TIMESCALE value from 1000 to 600 results in
> files that seek accurately in professional Quicktime software. This is
> due to the fact 600 is cleanly divisible by more frame rates than 1000, for
> example 24fps and 30fps. The Quicktime specification default is set to 600
> for this reason. When set to 1000 seeking can be inaccurate for these fame
> rates.

for other cases 600 is less accurate
for example input that uses timestamps in ms precission
like flv
but also 3/1001 will be less precisse

is there something that iam missing or can this simply
be computed from the input timebases instead of being
a fixed value ?
so its accurate for the inpiut when that is possible
and only some fixed value when that is not possible

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

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


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


Re: [FFmpeg-devel] [PATCH]lavfi/deshake: Check alignment before calling asm init function

2018-03-14 Thread Michael Niedermayer
On Sat, Mar 10, 2018 at 08:50:08PM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch fixes ticket #7078 for me.
> 
> Please comment, Carl Eugen

>  vf_deshake.c |8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 9f4517eae88416277aeb5bd5b677159914e9c451  
> 0001-lavfi-deshake-Check-alignment-before-calling-asm-ini.patch
> From 75ead282c3aa3c214d37e766690e2edd037307c0 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos 
> Date: Sat, 10 Mar 2018 20:46:21 +0100
> Subject: [PATCH] lavfi/deshake: Check alignment before calling asm init
>  function.
> 
> Do this for every frame to make sure dynamic filters do not
> cause crashes.
> 
> Fixes ticket #7078.
> ---
>  libavfilter/vf_deshake.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c
> index fb4eb35..75e9990 100644
> --- a/libavfilter/vf_deshake.c
> +++ b/libavfilter/vf_deshake.c
> @@ -342,10 +342,6 @@ static av_cold int init(AVFilterContext *ctx)
>  {
>  DeshakeContext *deshake = ctx->priv;
>  
> -deshake->sad = av_pixelutils_get_sad_fn(4, 4, 1, deshake); // 16x16, 2nd 
> source unaligned
> -if (!deshake->sad)
> -return AVERROR(EINVAL);
> -
>  deshake->refcount = 20; // XXX: add to options?
>  deshake->blocksize /= 2;
>  deshake->blocksize = av_clip(deshake->blocksize, 4, 128);
> @@ -432,6 +428,10 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  }
>  av_frame_copy_props(out, in);
>  
> +deshake->sad = av_pixelutils_get_sad_fn(4, 4, !((unsigned 
> long)in->data[0] & 15), deshake); // 16x16, 2nd source unaligned
> +if (!deshake->sad)
> +return AVERROR(EINVAL);

does this need to check linesize too ?

no more comments from me

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato


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


Re: [FFmpeg-devel] [PATCH v3] avcodec: fix atomics usage for h264/mpeg error_count

2018-03-14 Thread Michael Niedermayer
On Wed, Mar 14, 2018 at 08:11:35AM +0100, wm4 wrote:
> On Tue, 13 Mar 2018 19:07:33 +0100
> Michael Niedermayer  wrote:
> 
> > On Tue, Mar 13, 2018 at 04:02:57PM +, Aman Gupta wrote:
> > > On Tue, Mar 13, 2018 at 4:39 AM Michael Niedermayer 
> > > 
> > > wrote:
> > >   
> > > > On Mon, Mar 12, 2018 at 06:49:19PM -0700, Aman Gupta wrote:  
> > > > > From: Aman Gupta 
> > > > >
> > > > > ---
> > > > >  libavcodec/h264_slice.c|  5 +++--
> > > > >  libavcodec/mpeg12dec.c | 12 +++-
> > > > >  libavcodec/mpegvideo_enc.c |  3 ++-
> > > > >  3 files changed, 12 insertions(+), 8 deletions(-)  
> > > >
> > > > Iam a little bit confused, you write about "fixing" but not what this is
> > > > fixing and it appears there are several distinct types of changes  
> > > 
> > > 
> > > The type of error_count is already atomic_int. I don't know when that was
> > > changed.
> > > 
> > > The fix here is that these files do not compile on FreeBSD because of
> > > errors such as:
> > > 
> > > [2018-03-11 18:26:55.078686] [freebsd-x86_64] libavcodec/mpegvideo_enc.c:
> > > In function 'merge_context_after_encode':
> > > 
> > > [2018-03-11 18:26:55.081607] [freebsd-x86_64]
> > > libavcodec/mpegvideo_enc.c:3578:33: error: invalid operands to binary +
> > > (have 'atomic_int' and 'atomic_int')
> > > 
> > > 
> > > [2018-03-11 16:43:23.543072] [freebsd-x86_64] CClibavcodec/mpeg12dec.o
> > > 
> > > [2018-03-11 16:43:23.768864] [freebsd-x86_64] libavcodec/mpeg12dec.c: In
> > > function 'slice_decode_thread':
> > >   
> > 
> > > [2018-03-11 16:43:23.769713] [freebsd-x86_64]
> > > libavcodec/mpeg12dec.c:1996:23: error: incompatible types when assigning 
> > > to
> > > type 'atomic_int' from type 'int'  
> > 
> > what compiler is this ?
> > 6.5.16.1 Simple assignment
> > Constraints
> > One of the following shall hold: 114)
> > — the left operand has atomic, qualified, or unqualified arithmetic 
> > type, and the right has
> > arithmetic type;
> > 
> > Please someone correct me here if iam wrong but
> > To me this sounds like doing normal arithmetic operations between atomic and
> > non atomic arithmetic types is allowed.
> 
> It's true that C11 atomics allow direct access, but we also have
> some atomic wrappers that won't work correctly then. I haven't checked
> why this one fails, but the gcc compat wrappers use non-atomic types for
> the emulation, so this patch is justified and necessary.

The wrappers should be fixed if they do not work.
If they cannot be fixed and cannot implement the C11 spec correctly they 
should not use the standard C11 types but choose differnt function and type
names. And document these limitations and differences in that new API


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

If you drop bombs on a foreign country and kill a hundred thousand
innocent people, expect your government to call the consequence
"unprovoked inhuman terrorist attacks" and use it to justify dropping
more bombs and killing more people. The technology changed, the idea is old.


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


Re: [FFmpeg-devel] [PATCH]avfilter/astreamslect: fixing activating in some cases

2018-03-14 Thread Nicolas George
Bodecs Bela (2018-03-14):
> In case of some content, astreamselect filter remains in non active
> state.
> 
> please review this pacth. I am not sure this is the right fix of this.

I am not sure either. framesync was not designed for audio. I would like
to investigate: can you share the failing case?

Regards,

-- 
  Nicolas George


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


Re: [FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread wm4
On Wed, 14 Mar 2018 16:02:36 -0300
James Almer  wrote:

> On 3/14/2018 3:59 PM, wm4 wrote:
> > On Wed, 14 Mar 2018 14:45:33 -0300
> > James Almer  wrote:
> >   
> >> On 3/14/2018 1:41 PM, wm4 wrote:  
> >>> On Wed, 14 Mar 2018 13:30:28 -0300
> >>> James Almer  wrote:
> >>> 
>  On 3/14/2018 12:51 PM, wm4 wrote:
> > On Wed, 14 Mar 2018 12:30:04 -0300
> > James Almer  wrote:
> >   
> >> Same use case as av_fast_malloc(). If the buffer passed to it is
> >> writable and big enough it will be reused, otherwise a new one will
> >> be allocated instead.
> >>
> >> Signed-off-by: James Almer 
> >> ---
> >> TODO: Changelog and APIChanges entries, version bump.
> >>
> >>  libavutil/buffer.c | 33 +
> >>  libavutil/buffer.h | 42 ++
> >>  2 files changed, 75 insertions(+)
> >>
> >> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> >> index 8d1aa5fa84..26e015d7ee 100644
> >> --- a/libavutil/buffer.c
> >> +++ b/libavutil/buffer.c
> >> @@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int 
> >> size)
> >>  return 0;
> >>  }
> >>  
> >> +static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
> >> +AVBufferRef* (*buffer_alloc)(int 
> >> size))
> >> +{
> >> +AVBufferRef *buf = *pbuf;
> >> +
> >> +if (buf && av_buffer_is_writable(buf)
> >> +&& buf->data == buf->buffer->data
> >> +&& size <= buf->buffer->size) {
> >> +buf->size = FFMAX(0, size);
> >> +return 0;
> >> +}
> >> +
> >> +av_buffer_unref(pbuf);
> >> +
> >> +buf = buffer_alloc(size);
> >> +if (!buf)
> >> +return AVERROR(ENOMEM);
> >> +
> >> +*pbuf = buf;
> >> +
> >> +return 0;
> >> +}
> >> +
> >> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
> >> +{
> >> +return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
> >> +}
> >> +
> >> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
> >> +{
> >> +return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
> >> +}
> >> +
> >>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
> >> AVBufferRef* (*alloc)(void 
> >> *opaque, int size),
> >> void (*pool_free)(void *opaque))
> >> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
> >> index 73b6bd0b14..1166017d22 100644
> >> --- a/libavutil/buffer.h
> >> +++ b/libavutil/buffer.h
> >> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
> >>   */
> >>  int av_buffer_realloc(AVBufferRef **buf, int size);
> >>  
> >> +/**
> >> + * Allocate a buffer, reusing the given one if writable and large 
> >> enough.
> >> + *
> >> + * @code{.c}
> >> + * AVBufferRef *buf = ...;
> >> + * int ret = av_buffer_fast_alloc(&buf, size);
> >> + * if (ret < 0) {
> >> + * // Allocation failed; buf already freed
> >> + * return ret;
> >> + * }
> >> + * @endcode
> >> + *
> >> + * @param buf  A buffer reference. *buf may be NULL. On success, a 
> >> new buffer
> >> + * reference will be written in its place. On failure, it 
> >> will be
> >> + * unreferenced and set to NULL.
> >> + * @param size Required buffer size.
> >> + *
> >> + * @return 0 on success, a negative AVERROR on failure.
> >> + *
> >> + * @see av_buffer_realloc()
> >> + * @see av_buffer_fast_allocz()
> >> + */
> >> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
> >> +
> >> +/**
> >> + * Allocate and clear a buffer, reusing the given one if writable and 
> >> large
> >> + * enough.
> >> + *
> >> + * Like av_buffer_fast_alloc(), but all newly allocated space is 
> >> initially
> >> + * cleared. Reused buffer is not cleared.
> >> + *
> >> + * @param buf  A buffer reference. *buf may be NULL. On success, a 
> >> new buffer
> >> + * reference will be written in its place. On failure, it 
> >> will be
> >> + * unreferenced and set to NULL.
> >> + * @param size Required buffer size.
> >> + *
> >> + * @return 0 on success, a negative AVERROR on failure.
> >> + *
> >> + * @see av_buffer_fast_alloc()
> >> + */
> >> +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
> >> +
> >>  /**
> >>   * @}
> >>   */  
> >
> > LGTM
> >
> > Also some comment on the side: I think what you'd actually want is some
> > sort of flexible buffer pool. E.g. consider the allocated AVBufferRef
> > gets used and buffered by the consumer for 1 frame. Th

Re: [FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread James Almer
On 3/14/2018 3:59 PM, wm4 wrote:
> On Wed, 14 Mar 2018 14:45:33 -0300
> James Almer  wrote:
> 
>> On 3/14/2018 1:41 PM, wm4 wrote:
>>> On Wed, 14 Mar 2018 13:30:28 -0300
>>> James Almer  wrote:
>>>   
 On 3/14/2018 12:51 PM, wm4 wrote:  
> On Wed, 14 Mar 2018 12:30:04 -0300
> James Almer  wrote:
> 
>> Same use case as av_fast_malloc(). If the buffer passed to it is
>> writable and big enough it will be reused, otherwise a new one will
>> be allocated instead.
>>
>> Signed-off-by: James Almer 
>> ---
>> TODO: Changelog and APIChanges entries, version bump.
>>
>>  libavutil/buffer.c | 33 +
>>  libavutil/buffer.h | 42 ++
>>  2 files changed, 75 insertions(+)
>>
>> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>> index 8d1aa5fa84..26e015d7ee 100644
>> --- a/libavutil/buffer.c
>> +++ b/libavutil/buffer.c
>> @@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>>  return 0;
>>  }
>>  
>> +static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
>> +AVBufferRef* (*buffer_alloc)(int 
>> size))
>> +{
>> +AVBufferRef *buf = *pbuf;
>> +
>> +if (buf && av_buffer_is_writable(buf)
>> +&& buf->data == buf->buffer->data
>> +&& size <= buf->buffer->size) {
>> +buf->size = FFMAX(0, size);
>> +return 0;
>> +}
>> +
>> +av_buffer_unref(pbuf);
>> +
>> +buf = buffer_alloc(size);
>> +if (!buf)
>> +return AVERROR(ENOMEM);
>> +
>> +*pbuf = buf;
>> +
>> +return 0;
>> +}
>> +
>> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
>> +}
>> +
>> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
>> +}
>> +
>>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
>> AVBufferRef* (*alloc)(void *opaque, 
>> int size),
>> void (*pool_free)(void *opaque))
>> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
>> index 73b6bd0b14..1166017d22 100644
>> --- a/libavutil/buffer.h
>> +++ b/libavutil/buffer.h
>> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>>   */
>>  int av_buffer_realloc(AVBufferRef **buf, int size);
>>  
>> +/**
>> + * Allocate a buffer, reusing the given one if writable and large 
>> enough.
>> + *
>> + * @code{.c}
>> + * AVBufferRef *buf = ...;
>> + * int ret = av_buffer_fast_alloc(&buf, size);
>> + * if (ret < 0) {
>> + * // Allocation failed; buf already freed
>> + * return ret;
>> + * }
>> + * @endcode
>> + *
>> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>> buffer
>> + * reference will be written in its place. On failure, it 
>> will be
>> + * unreferenced and set to NULL.
>> + * @param size Required buffer size.
>> + *
>> + * @return 0 on success, a negative AVERROR on failure.
>> + *
>> + * @see av_buffer_realloc()
>> + * @see av_buffer_fast_allocz()
>> + */
>> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
>> +
>> +/**
>> + * Allocate and clear a buffer, reusing the given one if writable and 
>> large
>> + * enough.
>> + *
>> + * Like av_buffer_fast_alloc(), but all newly allocated space is 
>> initially
>> + * cleared. Reused buffer is not cleared.
>> + *
>> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>> buffer
>> + * reference will be written in its place. On failure, it 
>> will be
>> + * unreferenced and set to NULL.
>> + * @param size Required buffer size.
>> + *
>> + * @return 0 on success, a negative AVERROR on failure.
>> + *
>> + * @see av_buffer_fast_alloc()
>> + */
>> +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
>> +
>>  /**
>>   * @}
>>   */
>
> LGTM
>
> Also some comment on the side: I think what you'd actually want is some
> sort of flexible buffer pool. E.g. consider the allocated AVBufferRef
> gets used and buffered by the consumer for 1 frame. Then the
> AVBufferRef will always be not-writable, and will always be newly
> allocated, and this optimization via fast_alloc does not help. With a
> buffer pool, it would allocate a second AVBufferRef, but then always
> reuse it. Anyway, I might be overthinking it.

 No, that's a good idea, and it would come in handy in 

Re: [FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread wm4
On Wed, 14 Mar 2018 14:45:33 -0300
James Almer  wrote:

> On 3/14/2018 1:41 PM, wm4 wrote:
> > On Wed, 14 Mar 2018 13:30:28 -0300
> > James Almer  wrote:
> >   
> >> On 3/14/2018 12:51 PM, wm4 wrote:  
> >>> On Wed, 14 Mar 2018 12:30:04 -0300
> >>> James Almer  wrote:
> >>> 
>  Same use case as av_fast_malloc(). If the buffer passed to it is
>  writable and big enough it will be reused, otherwise a new one will
>  be allocated instead.
> 
>  Signed-off-by: James Almer 
>  ---
>  TODO: Changelog and APIChanges entries, version bump.
> 
>   libavutil/buffer.c | 33 +
>   libavutil/buffer.h | 42 ++
>   2 files changed, 75 insertions(+)
> 
>  diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>  index 8d1aa5fa84..26e015d7ee 100644
>  --- a/libavutil/buffer.c
>  +++ b/libavutil/buffer.c
>  @@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>   return 0;
>   }
>   
>  +static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
>  +AVBufferRef* (*buffer_alloc)(int 
>  size))
>  +{
>  +AVBufferRef *buf = *pbuf;
>  +
>  +if (buf && av_buffer_is_writable(buf)
>  +&& buf->data == buf->buffer->data
>  +&& size <= buf->buffer->size) {
>  +buf->size = FFMAX(0, size);
>  +return 0;
>  +}
>  +
>  +av_buffer_unref(pbuf);
>  +
>  +buf = buffer_alloc(size);
>  +if (!buf)
>  +return AVERROR(ENOMEM);
>  +
>  +*pbuf = buf;
>  +
>  +return 0;
>  +}
>  +
>  +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
>  +{
>  +return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
>  +}
>  +
>  +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
>  +{
>  +return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
>  +}
>  +
>   AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
>  AVBufferRef* (*alloc)(void *opaque, 
>  int size),
>  void (*pool_free)(void *opaque))
>  diff --git a/libavutil/buffer.h b/libavutil/buffer.h
>  index 73b6bd0b14..1166017d22 100644
>  --- a/libavutil/buffer.h
>  +++ b/libavutil/buffer.h
>  @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>    */
>   int av_buffer_realloc(AVBufferRef **buf, int size);
>   
>  +/**
>  + * Allocate a buffer, reusing the given one if writable and large 
>  enough.
>  + *
>  + * @code{.c}
>  + * AVBufferRef *buf = ...;
>  + * int ret = av_buffer_fast_alloc(&buf, size);
>  + * if (ret < 0) {
>  + * // Allocation failed; buf already freed
>  + * return ret;
>  + * }
>  + * @endcode
>  + *
>  + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>  buffer
>  + * reference will be written in its place. On failure, it 
>  will be
>  + * unreferenced and set to NULL.
>  + * @param size Required buffer size.
>  + *
>  + * @return 0 on success, a negative AVERROR on failure.
>  + *
>  + * @see av_buffer_realloc()
>  + * @see av_buffer_fast_allocz()
>  + */
>  +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
>  +
>  +/**
>  + * Allocate and clear a buffer, reusing the given one if writable and 
>  large
>  + * enough.
>  + *
>  + * Like av_buffer_fast_alloc(), but all newly allocated space is 
>  initially
>  + * cleared. Reused buffer is not cleared.
>  + *
>  + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>  buffer
>  + * reference will be written in its place. On failure, it 
>  will be
>  + * unreferenced and set to NULL.
>  + * @param size Required buffer size.
>  + *
>  + * @return 0 on success, a negative AVERROR on failure.
>  + *
>  + * @see av_buffer_fast_alloc()
>  + */
>  +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
>  +
>   /**
>    * @}
>    */
> >>>
> >>> LGTM
> >>>
> >>> Also some comment on the side: I think what you'd actually want is some
> >>> sort of flexible buffer pool. E.g. consider the allocated AVBufferRef
> >>> gets used and buffered by the consumer for 1 frame. Then the
> >>> AVBufferRef will always be not-writable, and will always be newly
> >>> allocated, and this optimization via fast_alloc does not help. With a
> >>> buffer pool, it would allocate a second AVBufferRef, but then always
> >>> reuse it. Anyway, I might be overthinking it.
> >>
> >> No, that's a good idea, and it would come in handy in a lot more places
> >> than this fast_al

[FFmpeg-devel] [PATCH]avfilter/astreamslect: fixing activating in some cases

2018-03-14 Thread Bodecs Bela

Dear All,

In case of some content, astreamselect filter remains in non active
state.

please review this pacth. I am not sure this is the right fix of this.

thank you, in advance!


Bela Bodecs

>From acd81c80b8b5b33b03e99adb3bad04bc291e4218 Mon Sep 17 00:00:00 2001
From: Bela Bodecs 
Date: Wed, 14 Mar 2018 19:22:03 +0100
Subject: [PATCH] avfilter/f_astreamselect: fixing activating in some cases

In case of some content, astreamselect filter remains in non active
state.

Signed-off-by: Bela Bodecs 
---
 libavfilter/f_streamselect.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavfilter/f_streamselect.c b/libavfilter/f_streamselect.c
index 923deb1..2aef3f4 100644
--- a/libavfilter/f_streamselect.c
+++ b/libavfilter/f_streamselect.c
@@ -25,6 +25,7 @@
 #include "framesync.h"
 #include "internal.h"
 #include "video.h"
+#include "filters.h"
 
 typedef struct StreamSelectContext {
 const AVClass *class;
@@ -66,8 +67,10 @@ static int process_frame(FFFrameSync *fs)
 AVFrame *out;
 
 if (s->is_audio && s->last_pts[j] == in[j]->pts &&
-ctx->outputs[i]->frame_count_in > 0)
+ctx->outputs[i]->frame_count_in > 0) {
+ff_filter_set_ready(ctx->outputs[i]->src, 200);
 continue;
+}
 out = av_frame_clone(in[j]);
 if (!out)
 return AVERROR(ENOMEM);
-- 
2.5.3.windows.1

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


Re: [FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread James Almer
On 3/14/2018 1:41 PM, wm4 wrote:
> On Wed, 14 Mar 2018 13:30:28 -0300
> James Almer  wrote:
> 
>> On 3/14/2018 12:51 PM, wm4 wrote:
>>> On Wed, 14 Mar 2018 12:30:04 -0300
>>> James Almer  wrote:
>>>   
 Same use case as av_fast_malloc(). If the buffer passed to it is
 writable and big enough it will be reused, otherwise a new one will
 be allocated instead.

 Signed-off-by: James Almer 
 ---
 TODO: Changelog and APIChanges entries, version bump.

  libavutil/buffer.c | 33 +
  libavutil/buffer.h | 42 ++
  2 files changed, 75 insertions(+)

 diff --git a/libavutil/buffer.c b/libavutil/buffer.c
 index 8d1aa5fa84..26e015d7ee 100644
 --- a/libavutil/buffer.c
 +++ b/libavutil/buffer.c
 @@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
  return 0;
  }
  
 +static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
 +AVBufferRef* (*buffer_alloc)(int 
 size))
 +{
 +AVBufferRef *buf = *pbuf;
 +
 +if (buf && av_buffer_is_writable(buf)
 +&& buf->data == buf->buffer->data
 +&& size <= buf->buffer->size) {
 +buf->size = FFMAX(0, size);
 +return 0;
 +}
 +
 +av_buffer_unref(pbuf);
 +
 +buf = buffer_alloc(size);
 +if (!buf)
 +return AVERROR(ENOMEM);
 +
 +*pbuf = buf;
 +
 +return 0;
 +}
 +
 +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
 +{
 +return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
 +}
 +
 +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
 +{
 +return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
 +}
 +
  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
 AVBufferRef* (*alloc)(void *opaque, 
 int size),
 void (*pool_free)(void *opaque))
 diff --git a/libavutil/buffer.h b/libavutil/buffer.h
 index 73b6bd0b14..1166017d22 100644
 --- a/libavutil/buffer.h
 +++ b/libavutil/buffer.h
 @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
   */
  int av_buffer_realloc(AVBufferRef **buf, int size);
  
 +/**
 + * Allocate a buffer, reusing the given one if writable and large enough.
 + *
 + * @code{.c}
 + * AVBufferRef *buf = ...;
 + * int ret = av_buffer_fast_alloc(&buf, size);
 + * if (ret < 0) {
 + * // Allocation failed; buf already freed
 + * return ret;
 + * }
 + * @endcode
 + *
 + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
 buffer
 + * reference will be written in its place. On failure, it 
 will be
 + * unreferenced and set to NULL.
 + * @param size Required buffer size.
 + *
 + * @return 0 on success, a negative AVERROR on failure.
 + *
 + * @see av_buffer_realloc()
 + * @see av_buffer_fast_allocz()
 + */
 +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
 +
 +/**
 + * Allocate and clear a buffer, reusing the given one if writable and 
 large
 + * enough.
 + *
 + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
 + * cleared. Reused buffer is not cleared.
 + *
 + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
 buffer
 + * reference will be written in its place. On failure, it 
 will be
 + * unreferenced and set to NULL.
 + * @param size Required buffer size.
 + *
 + * @return 0 on success, a negative AVERROR on failure.
 + *
 + * @see av_buffer_fast_alloc()
 + */
 +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
 +
  /**
   * @}
   */  
>>>
>>> LGTM
>>>
>>> Also some comment on the side: I think what you'd actually want is some
>>> sort of flexible buffer pool. E.g. consider the allocated AVBufferRef
>>> gets used and buffered by the consumer for 1 frame. Then the
>>> AVBufferRef will always be not-writable, and will always be newly
>>> allocated, and this optimization via fast_alloc does not help. With a
>>> buffer pool, it would allocate a second AVBufferRef, but then always
>>> reuse it. Anyway, I might be overthinking it.  
>>
>> No, that's a good idea, and it would come in handy in a lot more places
>> than this fast_alloc API. But it's probably not trivial to implement,
>> and would explain why the existing buffer pool API is for fixed sizes only.
>>
>> In any case, do you think it's better to try and implement your
>> suggestion instead of this patch? You're right that it's a matter of
>> creating one extra reference and this function would probably stop being
>> "fa

Re: [FFmpeg-devel] [PATCH] reitnerlace - tinterlace-like filter under LGPL

2018-03-14 Thread Thomas Mundt
2018-03-13 16:10 GMT+01:00 Vasile Toncu :

>
>
> On 06.03.2018 20:38, Thomas Mundt wrote:
>
>> Hi,
>>
>> 2018-03-05 13:48 GMT+01:00 Carl Eugen Hoyos :
>>
>> 2018-03-05 12:37 GMT+01:00, Paul B Mahol :
>>>
 On 3/5/18, Vasile Toncu  wrote:

> Hello,
>
> Thanks for the review. I've made changes according to your guidance.
>
> It would be great to know if the community will go on with our
> intention
> of adding reinterlace as a alternative for tinterlace.
>
> That being said, here is the new patch.
>
 As already said, this is not acceptable.

 There is no point in having 2 filters with near same funcionality.

>>> If you consider the new filter ok, the existing filter will be removed
>>> in the same push. I believe sending only the new filter makes
>>> reviewing easier.
>>>
>>> For me reviewing would be easier when Vasile sends a patchset that
>> includes
>> the replacement of tinterlace filter.
>> That way existing fate tests could be used which are fortunately pretty
>> extensive in this case.
>> Also it would be helpful when you and/or other experienced ffmpeg
>> developers would clarify first which parts of tinterlace have to be
>> rewritten for proper relicensing.
>> Being left in the dark makes working on patches frustrating.
>>
>> Another question is how to deal with vf_interlace? IMHO for the user there
>> should be no difference in output, speed and license.
>> Two options:
>> 1. Relicensing and slice threading will also be ported to vf_interlace
>> 2. The commands from vf_interlace will be included in the new tinterlace
>> filter. vf_interlace will be deleted together with old tinterlace filter
>>
>> I would prefer the second option, but maybe there are even better options
>> that don´t come to my mind.
>>
>> Please comment.
>> Thanks,
>> Thomas
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
> Hello everyone,
>
> sorry for a delayed response.
>
> From what has been discussed in here, I think the reinterlace will exist
> with tinterlace for a period of time, just after that the tinterlace can be
> removed.
>
> To have the reinterlace added, what is needed to be done from my side?
>
> Thanks,
> Vasile Toncu
>

Two filters with almost the same functionality won´t be accepted, as Paul
stated in this thread.
Also there is vf_interlace filter, which is a subset of vf_tinterlace and
should not differ in speed, output and license. As already said, I would
prefer to include vf_interlace options into vf_tinterlace and remove
vf_interlace.
Also you want several changes: Making tinterlace filter LGPL, adding new
options and adding slice threading.
This should be done in a patch set:

Patch 1/5: Include vf_interlace options into vf_tinterlace filter and
remove vf_interlace
Patch 2/5: Your new LGPL vf_reinterlace filter without the new options,
fixes and slice threading
Patch 3/5: Rename vf_reinterlace and replace vf_tinterlace by it
Patch 4/5: Add slice threading
Patch 5/5: Add the new options and fate tests for them

Please run fate. All tests should pass.
As already said, I don´t have the skills to suggest what has to be done
making the relicensing legal. So I can do a technical review only.
These are just my suggestions to the best of my knowledge! There might be
better ideas from more experienced developers.
Please comment.

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


Re: [FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread wm4
On Wed, 14 Mar 2018 13:30:28 -0300
James Almer  wrote:

> On 3/14/2018 12:51 PM, wm4 wrote:
> > On Wed, 14 Mar 2018 12:30:04 -0300
> > James Almer  wrote:
> >   
> >> Same use case as av_fast_malloc(). If the buffer passed to it is
> >> writable and big enough it will be reused, otherwise a new one will
> >> be allocated instead.
> >>
> >> Signed-off-by: James Almer 
> >> ---
> >> TODO: Changelog and APIChanges entries, version bump.
> >>
> >>  libavutil/buffer.c | 33 +
> >>  libavutil/buffer.h | 42 ++
> >>  2 files changed, 75 insertions(+)
> >>
> >> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> >> index 8d1aa5fa84..26e015d7ee 100644
> >> --- a/libavutil/buffer.c
> >> +++ b/libavutil/buffer.c
> >> @@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
> >>  return 0;
> >>  }
> >>  
> >> +static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
> >> +AVBufferRef* (*buffer_alloc)(int 
> >> size))
> >> +{
> >> +AVBufferRef *buf = *pbuf;
> >> +
> >> +if (buf && av_buffer_is_writable(buf)
> >> +&& buf->data == buf->buffer->data
> >> +&& size <= buf->buffer->size) {
> >> +buf->size = FFMAX(0, size);
> >> +return 0;
> >> +}
> >> +
> >> +av_buffer_unref(pbuf);
> >> +
> >> +buf = buffer_alloc(size);
> >> +if (!buf)
> >> +return AVERROR(ENOMEM);
> >> +
> >> +*pbuf = buf;
> >> +
> >> +return 0;
> >> +}
> >> +
> >> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
> >> +{
> >> +return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
> >> +}
> >> +
> >> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
> >> +{
> >> +return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
> >> +}
> >> +
> >>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
> >> AVBufferRef* (*alloc)(void *opaque, 
> >> int size),
> >> void (*pool_free)(void *opaque))
> >> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
> >> index 73b6bd0b14..1166017d22 100644
> >> --- a/libavutil/buffer.h
> >> +++ b/libavutil/buffer.h
> >> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
> >>   */
> >>  int av_buffer_realloc(AVBufferRef **buf, int size);
> >>  
> >> +/**
> >> + * Allocate a buffer, reusing the given one if writable and large enough.
> >> + *
> >> + * @code{.c}
> >> + * AVBufferRef *buf = ...;
> >> + * int ret = av_buffer_fast_alloc(&buf, size);
> >> + * if (ret < 0) {
> >> + * // Allocation failed; buf already freed
> >> + * return ret;
> >> + * }
> >> + * @endcode
> >> + *
> >> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
> >> buffer
> >> + * reference will be written in its place. On failure, it 
> >> will be
> >> + * unreferenced and set to NULL.
> >> + * @param size Required buffer size.
> >> + *
> >> + * @return 0 on success, a negative AVERROR on failure.
> >> + *
> >> + * @see av_buffer_realloc()
> >> + * @see av_buffer_fast_allocz()
> >> + */
> >> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
> >> +
> >> +/**
> >> + * Allocate and clear a buffer, reusing the given one if writable and 
> >> large
> >> + * enough.
> >> + *
> >> + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
> >> + * cleared. Reused buffer is not cleared.
> >> + *
> >> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
> >> buffer
> >> + * reference will be written in its place. On failure, it 
> >> will be
> >> + * unreferenced and set to NULL.
> >> + * @param size Required buffer size.
> >> + *
> >> + * @return 0 on success, a negative AVERROR on failure.
> >> + *
> >> + * @see av_buffer_fast_alloc()
> >> + */
> >> +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
> >> +
> >>  /**
> >>   * @}
> >>   */  
> > 
> > LGTM
> > 
> > Also some comment on the side: I think what you'd actually want is some
> > sort of flexible buffer pool. E.g. consider the allocated AVBufferRef
> > gets used and buffered by the consumer for 1 frame. Then the
> > AVBufferRef will always be not-writable, and will always be newly
> > allocated, and this optimization via fast_alloc does not help. With a
> > buffer pool, it would allocate a second AVBufferRef, but then always
> > reuse it. Anyway, I might be overthinking it.  
> 
> No, that's a good idea, and it would come in handy in a lot more places
> than this fast_alloc API. But it's probably not trivial to implement,
> and would explain why the existing buffer pool API is for fixed sizes only.
> 
> In any case, do you think it's better to try and implement your
> suggestion instead of this patch? You're right that it's a matter of
> creating one extra reference and this function would probably stop being
> "fast".

Depends what's even the point of the ne

Re: [FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread James Almer
On 3/14/2018 12:51 PM, wm4 wrote:
> On Wed, 14 Mar 2018 12:30:04 -0300
> James Almer  wrote:
> 
>> Same use case as av_fast_malloc(). If the buffer passed to it is
>> writable and big enough it will be reused, otherwise a new one will
>> be allocated instead.
>>
>> Signed-off-by: James Almer 
>> ---
>> TODO: Changelog and APIChanges entries, version bump.
>>
>>  libavutil/buffer.c | 33 +
>>  libavutil/buffer.h | 42 ++
>>  2 files changed, 75 insertions(+)
>>
>> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>> index 8d1aa5fa84..26e015d7ee 100644
>> --- a/libavutil/buffer.c
>> +++ b/libavutil/buffer.c
>> @@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>>  return 0;
>>  }
>>  
>> +static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
>> +AVBufferRef* (*buffer_alloc)(int size))
>> +{
>> +AVBufferRef *buf = *pbuf;
>> +
>> +if (buf && av_buffer_is_writable(buf)
>> +&& buf->data == buf->buffer->data
>> +&& size <= buf->buffer->size) {
>> +buf->size = FFMAX(0, size);
>> +return 0;
>> +}
>> +
>> +av_buffer_unref(pbuf);
>> +
>> +buf = buffer_alloc(size);
>> +if (!buf)
>> +return AVERROR(ENOMEM);
>> +
>> +*pbuf = buf;
>> +
>> +return 0;
>> +}
>> +
>> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
>> +}
>> +
>> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
>> +}
>> +
>>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
>> AVBufferRef* (*alloc)(void *opaque, int 
>> size),
>> void (*pool_free)(void *opaque))
>> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
>> index 73b6bd0b14..1166017d22 100644
>> --- a/libavutil/buffer.h
>> +++ b/libavutil/buffer.h
>> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>>   */
>>  int av_buffer_realloc(AVBufferRef **buf, int size);
>>  
>> +/**
>> + * Allocate a buffer, reusing the given one if writable and large enough.
>> + *
>> + * @code{.c}
>> + * AVBufferRef *buf = ...;
>> + * int ret = av_buffer_fast_alloc(&buf, size);
>> + * if (ret < 0) {
>> + * // Allocation failed; buf already freed
>> + * return ret;
>> + * }
>> + * @endcode
>> + *
>> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>> buffer
>> + * reference will be written in its place. On failure, it will 
>> be
>> + * unreferenced and set to NULL.
>> + * @param size Required buffer size.
>> + *
>> + * @return 0 on success, a negative AVERROR on failure.
>> + *
>> + * @see av_buffer_realloc()
>> + * @see av_buffer_fast_allocz()
>> + */
>> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
>> +
>> +/**
>> + * Allocate and clear a buffer, reusing the given one if writable and large
>> + * enough.
>> + *
>> + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
>> + * cleared. Reused buffer is not cleared.
>> + *
>> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>> buffer
>> + * reference will be written in its place. On failure, it will 
>> be
>> + * unreferenced and set to NULL.
>> + * @param size Required buffer size.
>> + *
>> + * @return 0 on success, a negative AVERROR on failure.
>> + *
>> + * @see av_buffer_fast_alloc()
>> + */
>> +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
>> +
>>  /**
>>   * @}
>>   */
> 
> LGTM
> 
> Also some comment on the side: I think what you'd actually want is some
> sort of flexible buffer pool. E.g. consider the allocated AVBufferRef
> gets used and buffered by the consumer for 1 frame. Then the
> AVBufferRef will always be not-writable, and will always be newly
> allocated, and this optimization via fast_alloc does not help. With a
> buffer pool, it would allocate a second AVBufferRef, but then always
> reuse it. Anyway, I might be overthinking it.

No, that's a good idea, and it would come in handy in a lot more places
than this fast_alloc API. But it's probably not trivial to implement,
and would explain why the existing buffer pool API is for fixed sizes only.

In any case, do you think it's better to try and implement your
suggestion instead of this patch? You're right that it's a matter of
creating one extra reference and this function would probably stop being
"fast".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread wm4
On Wed, 14 Mar 2018 12:30:04 -0300
James Almer  wrote:

> Same use case as av_fast_malloc(). If the buffer passed to it is
> writable and big enough it will be reused, otherwise a new one will
> be allocated instead.
> 
> Signed-off-by: James Almer 
> ---
> TODO: Changelog and APIChanges entries, version bump.
> 
>  libavutil/buffer.c | 33 +
>  libavutil/buffer.h | 42 ++
>  2 files changed, 75 insertions(+)
> 
> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> index 8d1aa5fa84..26e015d7ee 100644
> --- a/libavutil/buffer.c
> +++ b/libavutil/buffer.c
> @@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>  return 0;
>  }
>  
> +static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
> +AVBufferRef* (*buffer_alloc)(int size))
> +{
> +AVBufferRef *buf = *pbuf;
> +
> +if (buf && av_buffer_is_writable(buf)
> +&& buf->data == buf->buffer->data
> +&& size <= buf->buffer->size) {
> +buf->size = FFMAX(0, size);
> +return 0;
> +}
> +
> +av_buffer_unref(pbuf);
> +
> +buf = buffer_alloc(size);
> +if (!buf)
> +return AVERROR(ENOMEM);
> +
> +*pbuf = buf;
> +
> +return 0;
> +}
> +
> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
> +{
> +return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
> +}
> +
> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
> +{
> +return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
> +}
> +
>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
> AVBufferRef* (*alloc)(void *opaque, int 
> size),
> void (*pool_free)(void *opaque))
> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
> index 73b6bd0b14..1166017d22 100644
> --- a/libavutil/buffer.h
> +++ b/libavutil/buffer.h
> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>   */
>  int av_buffer_realloc(AVBufferRef **buf, int size);
>  
> +/**
> + * Allocate a buffer, reusing the given one if writable and large enough.
> + *
> + * @code{.c}
> + * AVBufferRef *buf = ...;
> + * int ret = av_buffer_fast_alloc(&buf, size);
> + * if (ret < 0) {
> + * // Allocation failed; buf already freed
> + * return ret;
> + * }
> + * @endcode
> + *
> + * @param buf  A buffer reference. *buf may be NULL. On success, a new buffer
> + * reference will be written in its place. On failure, it will be
> + * unreferenced and set to NULL.
> + * @param size Required buffer size.
> + *
> + * @return 0 on success, a negative AVERROR on failure.
> + *
> + * @see av_buffer_realloc()
> + * @see av_buffer_fast_allocz()
> + */
> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
> +
> +/**
> + * Allocate and clear a buffer, reusing the given one if writable and large
> + * enough.
> + *
> + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
> + * cleared. Reused buffer is not cleared.
> + *
> + * @param buf  A buffer reference. *buf may be NULL. On success, a new buffer
> + * reference will be written in its place. On failure, it will be
> + * unreferenced and set to NULL.
> + * @param size Required buffer size.
> + *
> + * @return 0 on success, a negative AVERROR on failure.
> + *
> + * @see av_buffer_fast_alloc()
> + */
> +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
> +
>  /**
>   * @}
>   */

LGTM

Also some comment on the side: I think what you'd actually want is some
sort of flexible buffer pool. E.g. consider the allocated AVBufferRef
gets used and buffered by the consumer for 1 frame. Then the
AVBufferRef will always be not-writable, and will always be newly
allocated, and this optimization via fast_alloc does not help. With a
buffer pool, it would allocate a second AVBufferRef, but then always
reuse it. Anyway, I might be overthinking it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread James Almer
On 3/14/2018 12:09 PM, wm4 wrote:
> On Wed, 14 Mar 2018 11:59:59 -0300
> James Almer  wrote:
> 
>> On 3/14/2018 11:35 AM, wm4 wrote:
>>> On Wed, 14 Mar 2018 11:13:52 -0300
>>> James Almer  wrote:
>>>   
 On 3/14/2018 4:14 AM, wm4 wrote:  
> On Tue, 13 Mar 2018 20:48:56 -0300
> James Almer  wrote:
> 
>> Same concept as av_fast_malloc(). If the buffer passed to it is writable
>> and big enough it will be reused, otherwise a new one will be allocated
>> instead.
>>
>> Signed-off-by: James Almer 
>> ---
>> TODO: Changelog and APIChanges entries, version bump.
>>
>>  libavutil/buffer.c | 63 
>> ++
>>  libavutil/buffer.h | 42 
>>  2 files changed, 105 insertions(+)
>>
>> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>> index 8d1aa5fa84..16ce1b82e2 100644
>> --- a/libavutil/buffer.c
>> +++ b/libavutil/buffer.c
>> @@ -215,6 +215,69 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>>  return 0;
>>  }
>>  
>> +static av_always_inline int buffer_fast_alloc(AVBufferRef **pbuf, int 
>> size, int zero_alloc)
>> +{
>> +AVBufferRef *buf = *pbuf;
>> +AVBuffer *b;
>> +uint8_t *data;
>> +
>> +if (!buf || !av_buffer_is_writable(buf) || buf->data != 
>> buf->buffer->data) {
>> +/* Buffer can't be reused, and neither can the entire 
>> AVBufferRef.
>> + * Unref the latter and alloc a new one. */
>> +av_buffer_unref(pbuf);
>> +
>> +buf = av_buffer_alloc(size);
>> +if (!buf)
>> +return AVERROR(ENOMEM);
>> +
>> +if (zero_alloc)
>> +memset(buf->data, 0, size);
>> +
>> +*pbuf = buf;
>> +return 0;
>> +}
>> +b = buf->buffer;
>> +
>> +if (size <= b->size) {
>> +/* Buffer can be reused. Update the size of AVBufferRef but 
>> leave the
>> + * AVBuffer untouched. */
>> +buf->size = FFMAX(0, size);
>> +return 0;
>> +}
>> +
>> +/* Buffer can't be reused, but there's no need to alloc new 
>> AVBuffer and
>> + * AVBufferRef structs. Free the existing buffer, allocate a new 
>> one, and
>> + * reset AVBuffer and AVBufferRef to default values. */
>> +b->free(b->opaque, b->data);
>> +b->free   = av_buffer_default_free;
>> +b->opaque = NULL;
>> +b->flags  = 0;
>> +
>> +data = av_malloc(size);
>> +if (!data) {
>> +av_buffer_unref(pbuf);
>> +return AVERROR(ENOMEM);
>> +}
>> +
>> +if (zero_alloc)
>> +memset(data, 0, size);
>> +
>> +b->data = buf->data = data;
>> +b->size = buf->size = size;
>> +
>> +return 0;
>> +}
>> +
>> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, 0);
>> +}
>> +
>> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, 1);
>> +}
>> +
>>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
>> AVBufferRef* (*alloc)(void *opaque, 
>> int size),
>> void (*pool_free)(void *opaque))
>> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
>> index 73b6bd0b14..1166017d22 100644
>> --- a/libavutil/buffer.h
>> +++ b/libavutil/buffer.h
>> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>>   */
>>  int av_buffer_realloc(AVBufferRef **buf, int size);
>>  
>> +/**
>> + * Allocate a buffer, reusing the given one if writable and large 
>> enough.
>> + *
>> + * @code{.c}
>> + * AVBufferRef *buf = ...;
>> + * int ret = av_buffer_fast_alloc(&buf, size);
>> + * if (ret < 0) {
>> + * // Allocation failed; buf already freed
>> + * return ret;
>> + * }
>> + * @endcode
>> + *
>> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>> buffer
>> + * reference will be written in its place. On failure, it 
>> will be
>> + * unreferenced and set to NULL.
>> + * @param size Required buffer size.
>> + *
>> + * @return 0 on success, a negative AVERROR on failure.
>> + *
>> + * @see av_buffer_realloc()
>> + * @see av_buffer_fast_allocz()
>> + */
>> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
>> +
>> +/**
>> + * Allocate and clear a buffer, reusing the given one if writable and 
>> large
>> + * enough.
>> + *
>> + * Like av_buffer_fast_alloc(), but all newly allocated space is 
>> initially
>> + * clea

[FFmpeg-devel] [PATCH v2] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread James Almer
Same use case as av_fast_malloc(). If the buffer passed to it is
writable and big enough it will be reused, otherwise a new one will
be allocated instead.

Signed-off-by: James Almer 
---
TODO: Changelog and APIChanges entries, version bump.

 libavutil/buffer.c | 33 +
 libavutil/buffer.h | 42 ++
 2 files changed, 75 insertions(+)

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 8d1aa5fa84..26e015d7ee 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -215,6 +215,39 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
 return 0;
 }
 
+static inline int buffer_fast_alloc(AVBufferRef **pbuf, int size,
+AVBufferRef* (*buffer_alloc)(int size))
+{
+AVBufferRef *buf = *pbuf;
+
+if (buf && av_buffer_is_writable(buf)
+&& buf->data == buf->buffer->data
+&& size <= buf->buffer->size) {
+buf->size = FFMAX(0, size);
+return 0;
+}
+
+av_buffer_unref(pbuf);
+
+buf = buffer_alloc(size);
+if (!buf)
+return AVERROR(ENOMEM);
+
+*pbuf = buf;
+
+return 0;
+}
+
+int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
+{
+return buffer_fast_alloc(pbuf, size, av_buffer_alloc);
+}
+
+int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
+{
+return buffer_fast_alloc(pbuf, size, av_buffer_allocz);
+}
+
 AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int 
size),
void (*pool_free)(void *opaque))
diff --git a/libavutil/buffer.h b/libavutil/buffer.h
index 73b6bd0b14..1166017d22 100644
--- a/libavutil/buffer.h
+++ b/libavutil/buffer.h
@@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
  */
 int av_buffer_realloc(AVBufferRef **buf, int size);
 
+/**
+ * Allocate a buffer, reusing the given one if writable and large enough.
+ *
+ * @code{.c}
+ * AVBufferRef *buf = ...;
+ * int ret = av_buffer_fast_alloc(&buf, size);
+ * if (ret < 0) {
+ * // Allocation failed; buf already freed
+ * return ret;
+ * }
+ * @endcode
+ *
+ * @param buf  A buffer reference. *buf may be NULL. On success, a new buffer
+ * reference will be written in its place. On failure, it will be
+ * unreferenced and set to NULL.
+ * @param size Required buffer size.
+ *
+ * @return 0 on success, a negative AVERROR on failure.
+ *
+ * @see av_buffer_realloc()
+ * @see av_buffer_fast_allocz()
+ */
+int av_buffer_fast_alloc(AVBufferRef **buf, int size);
+
+/**
+ * Allocate and clear a buffer, reusing the given one if writable and large
+ * enough.
+ *
+ * Like av_buffer_fast_alloc(), but all newly allocated space is initially
+ * cleared. Reused buffer is not cleared.
+ *
+ * @param buf  A buffer reference. *buf may be NULL. On success, a new buffer
+ * reference will be written in its place. On failure, it will be
+ * unreferenced and set to NULL.
+ * @param size Required buffer size.
+ *
+ * @return 0 on success, a negative AVERROR on failure.
+ *
+ * @see av_buffer_fast_alloc()
+ */
+int av_buffer_fast_allocz(AVBufferRef **buf, int size);
+
 /**
  * @}
  */
-- 
2.16.2

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


Re: [FFmpeg-devel] [PATCH] avcodec/hapqa_extract: remove the AVOption flags

2018-03-14 Thread James Almer
On 3/14/2018 3:32 AM, Martin Vignali wrote:
> 2018-03-14 2:09 GMT+01:00 James Almer :
> 
>> These two are not used for bitstream filters.
>>
>> Signed-off-by: James Almer 
>> ---
>>  libavcodec/hapqa_extract_bsf.c | 7 +++
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavcodec/hapqa_extract_bsf.c b/libavcodec/hapqa_extract_
>> bsf.c
>> index ee5dc191f7..652f79a7fe 100644
>> --- a/libavcodec/hapqa_extract_bsf.c
>> +++ b/libavcodec/hapqa_extract_bsf.c
>> @@ -110,11 +110,10 @@ static const enum AVCodecID codec_ids[] = {
>>  };
>>
>>  #define OFFSET(x) offsetof(HapqaExtractContext, x)
>> -#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
>>  static const AVOption options[] = {
>> -{ "texture", "texture to keep", OFFSET(texture), AV_OPT_TYPE_INT, {
>> .i64 = 0 }, 0, 1, FLAGS,  "texture" },
>> -{ "color", "keep HapQ texture", 0, AV_OPT_TYPE_CONST, { .i64 = 0
>> }, 0, 0, FLAGS, "texture" },
>> -{ "alpha", "keep HapAlphaOnly texture", 0, AV_OPT_TYPE_CONST, {
>> .i64 = 1 }, 0, 0, FLAGS, "texture" },
>> +{ "texture", "texture to keep", OFFSET(texture), AV_OPT_TYPE_INT, {
>> .i64 = 0 }, 0, 1, 0, "texture" },
>> +{ "color", "keep HapQ texture", 0, AV_OPT_TYPE_CONST, {
>> .i64 = 0 }, .unit = "texture" },
>> +{ "alpha", "keep HapAlphaOnly texture", 0, AV_OPT_TYPE_CONST, {
>> .i64 = 1 }, .unit = "texture" },
>>  { NULL },
>>  };
>>
>>
>>
> ok
> 
> Martin

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


Re: [FFmpeg-devel] [PATCH] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread wm4
On Wed, 14 Mar 2018 11:59:59 -0300
James Almer  wrote:

> On 3/14/2018 11:35 AM, wm4 wrote:
> > On Wed, 14 Mar 2018 11:13:52 -0300
> > James Almer  wrote:
> >   
> >> On 3/14/2018 4:14 AM, wm4 wrote:  
> >>> On Tue, 13 Mar 2018 20:48:56 -0300
> >>> James Almer  wrote:
> >>> 
>  Same concept as av_fast_malloc(). If the buffer passed to it is writable
>  and big enough it will be reused, otherwise a new one will be allocated
>  instead.
> 
>  Signed-off-by: James Almer 
>  ---
>  TODO: Changelog and APIChanges entries, version bump.
> 
>   libavutil/buffer.c | 63 
>  ++
>   libavutil/buffer.h | 42 
>   2 files changed, 105 insertions(+)
> 
>  diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>  index 8d1aa5fa84..16ce1b82e2 100644
>  --- a/libavutil/buffer.c
>  +++ b/libavutil/buffer.c
>  @@ -215,6 +215,69 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>   return 0;
>   }
>   
>  +static av_always_inline int buffer_fast_alloc(AVBufferRef **pbuf, int 
>  size, int zero_alloc)
>  +{
>  +AVBufferRef *buf = *pbuf;
>  +AVBuffer *b;
>  +uint8_t *data;
>  +
>  +if (!buf || !av_buffer_is_writable(buf) || buf->data != 
>  buf->buffer->data) {
>  +/* Buffer can't be reused, and neither can the entire 
>  AVBufferRef.
>  + * Unref the latter and alloc a new one. */
>  +av_buffer_unref(pbuf);
>  +
>  +buf = av_buffer_alloc(size);
>  +if (!buf)
>  +return AVERROR(ENOMEM);
>  +
>  +if (zero_alloc)
>  +memset(buf->data, 0, size);
>  +
>  +*pbuf = buf;
>  +return 0;
>  +}
>  +b = buf->buffer;
>  +
>  +if (size <= b->size) {
>  +/* Buffer can be reused. Update the size of AVBufferRef but 
>  leave the
>  + * AVBuffer untouched. */
>  +buf->size = FFMAX(0, size);
>  +return 0;
>  +}
>  +
>  +/* Buffer can't be reused, but there's no need to alloc new 
>  AVBuffer and
>  + * AVBufferRef structs. Free the existing buffer, allocate a new 
>  one, and
>  + * reset AVBuffer and AVBufferRef to default values. */
>  +b->free(b->opaque, b->data);
>  +b->free   = av_buffer_default_free;
>  +b->opaque = NULL;
>  +b->flags  = 0;
>  +
>  +data = av_malloc(size);
>  +if (!data) {
>  +av_buffer_unref(pbuf);
>  +return AVERROR(ENOMEM);
>  +}
>  +
>  +if (zero_alloc)
>  +memset(data, 0, size);
>  +
>  +b->data = buf->data = data;
>  +b->size = buf->size = size;
>  +
>  +return 0;
>  +}
>  +
>  +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
>  +{
>  +return buffer_fast_alloc(pbuf, size, 0);
>  +}
>  +
>  +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
>  +{
>  +return buffer_fast_alloc(pbuf, size, 1);
>  +}
>  +
>   AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
>  AVBufferRef* (*alloc)(void *opaque, 
>  int size),
>  void (*pool_free)(void *opaque))
>  diff --git a/libavutil/buffer.h b/libavutil/buffer.h
>  index 73b6bd0b14..1166017d22 100644
>  --- a/libavutil/buffer.h
>  +++ b/libavutil/buffer.h
>  @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>    */
>   int av_buffer_realloc(AVBufferRef **buf, int size);
>   
>  +/**
>  + * Allocate a buffer, reusing the given one if writable and large 
>  enough.
>  + *
>  + * @code{.c}
>  + * AVBufferRef *buf = ...;
>  + * int ret = av_buffer_fast_alloc(&buf, size);
>  + * if (ret < 0) {
>  + * // Allocation failed; buf already freed
>  + * return ret;
>  + * }
>  + * @endcode
>  + *
>  + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>  buffer
>  + * reference will be written in its place. On failure, it 
>  will be
>  + * unreferenced and set to NULL.
>  + * @param size Required buffer size.
>  + *
>  + * @return 0 on success, a negative AVERROR on failure.
>  + *
>  + * @see av_buffer_realloc()
>  + * @see av_buffer_fast_allocz()
>  + */
>  +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
>  +
>  +/**
>  + * Allocate and clear a buffer, reusing the given one if writable and 
>  large
>  + * enough.
>  + *
>  + * Like av_buffer_fast_alloc(), but all newly allocated space is 
>  initially
>  + * cleared. Reused buffer is not cleared.
> 

Re: [FFmpeg-devel] [PATCH] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread James Almer
On 3/14/2018 11:35 AM, wm4 wrote:
> On Wed, 14 Mar 2018 11:13:52 -0300
> James Almer  wrote:
> 
>> On 3/14/2018 4:14 AM, wm4 wrote:
>>> On Tue, 13 Mar 2018 20:48:56 -0300
>>> James Almer  wrote:
>>>   
 Same concept as av_fast_malloc(). If the buffer passed to it is writable
 and big enough it will be reused, otherwise a new one will be allocated
 instead.

 Signed-off-by: James Almer 
 ---
 TODO: Changelog and APIChanges entries, version bump.

  libavutil/buffer.c | 63 
 ++
  libavutil/buffer.h | 42 
  2 files changed, 105 insertions(+)

 diff --git a/libavutil/buffer.c b/libavutil/buffer.c
 index 8d1aa5fa84..16ce1b82e2 100644
 --- a/libavutil/buffer.c
 +++ b/libavutil/buffer.c
 @@ -215,6 +215,69 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
  return 0;
  }
  
 +static av_always_inline int buffer_fast_alloc(AVBufferRef **pbuf, int 
 size, int zero_alloc)
 +{
 +AVBufferRef *buf = *pbuf;
 +AVBuffer *b;
 +uint8_t *data;
 +
 +if (!buf || !av_buffer_is_writable(buf) || buf->data != 
 buf->buffer->data) {
 +/* Buffer can't be reused, and neither can the entire AVBufferRef.
 + * Unref the latter and alloc a new one. */
 +av_buffer_unref(pbuf);
 +
 +buf = av_buffer_alloc(size);
 +if (!buf)
 +return AVERROR(ENOMEM);
 +
 +if (zero_alloc)
 +memset(buf->data, 0, size);
 +
 +*pbuf = buf;
 +return 0;
 +}
 +b = buf->buffer;
 +
 +if (size <= b->size) {
 +/* Buffer can be reused. Update the size of AVBufferRef but leave 
 the
 + * AVBuffer untouched. */
 +buf->size = FFMAX(0, size);
 +return 0;
 +}
 +
 +/* Buffer can't be reused, but there's no need to alloc new AVBuffer 
 and
 + * AVBufferRef structs. Free the existing buffer, allocate a new one, 
 and
 + * reset AVBuffer and AVBufferRef to default values. */
 +b->free(b->opaque, b->data);
 +b->free   = av_buffer_default_free;
 +b->opaque = NULL;
 +b->flags  = 0;
 +
 +data = av_malloc(size);
 +if (!data) {
 +av_buffer_unref(pbuf);
 +return AVERROR(ENOMEM);
 +}
 +
 +if (zero_alloc)
 +memset(data, 0, size);
 +
 +b->data = buf->data = data;
 +b->size = buf->size = size;
 +
 +return 0;
 +}
 +
 +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
 +{
 +return buffer_fast_alloc(pbuf, size, 0);
 +}
 +
 +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
 +{
 +return buffer_fast_alloc(pbuf, size, 1);
 +}
 +
  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
 AVBufferRef* (*alloc)(void *opaque, 
 int size),
 void (*pool_free)(void *opaque))
 diff --git a/libavutil/buffer.h b/libavutil/buffer.h
 index 73b6bd0b14..1166017d22 100644
 --- a/libavutil/buffer.h
 +++ b/libavutil/buffer.h
 @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
   */
  int av_buffer_realloc(AVBufferRef **buf, int size);
  
 +/**
 + * Allocate a buffer, reusing the given one if writable and large enough.
 + *
 + * @code{.c}
 + * AVBufferRef *buf = ...;
 + * int ret = av_buffer_fast_alloc(&buf, size);
 + * if (ret < 0) {
 + * // Allocation failed; buf already freed
 + * return ret;
 + * }
 + * @endcode
 + *
 + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
 buffer
 + * reference will be written in its place. On failure, it 
 will be
 + * unreferenced and set to NULL.
 + * @param size Required buffer size.
 + *
 + * @return 0 on success, a negative AVERROR on failure.
 + *
 + * @see av_buffer_realloc()
 + * @see av_buffer_fast_allocz()
 + */
 +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
 +
 +/**
 + * Allocate and clear a buffer, reusing the given one if writable and 
 large
 + * enough.
 + *
 + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
 + * cleared. Reused buffer is not cleared.
 + *
 + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
 buffer
 + * reference will be written in its place. On failure, it 
 will be
 + * unreferenced and set to NULL.
 + * @param size Required buffer size.
 + *
 + * @return 0 on success, a negative AVERROR on failure.
 + *
 + * @see

Re: [FFmpeg-devel] [PATCH] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread wm4
On Wed, 14 Mar 2018 11:13:52 -0300
James Almer  wrote:

> On 3/14/2018 4:14 AM, wm4 wrote:
> > On Tue, 13 Mar 2018 20:48:56 -0300
> > James Almer  wrote:
> >   
> >> Same concept as av_fast_malloc(). If the buffer passed to it is writable
> >> and big enough it will be reused, otherwise a new one will be allocated
> >> instead.
> >>
> >> Signed-off-by: James Almer 
> >> ---
> >> TODO: Changelog and APIChanges entries, version bump.
> >>
> >>  libavutil/buffer.c | 63 
> >> ++
> >>  libavutil/buffer.h | 42 
> >>  2 files changed, 105 insertions(+)
> >>
> >> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> >> index 8d1aa5fa84..16ce1b82e2 100644
> >> --- a/libavutil/buffer.c
> >> +++ b/libavutil/buffer.c
> >> @@ -215,6 +215,69 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
> >>  return 0;
> >>  }
> >>  
> >> +static av_always_inline int buffer_fast_alloc(AVBufferRef **pbuf, int 
> >> size, int zero_alloc)
> >> +{
> >> +AVBufferRef *buf = *pbuf;
> >> +AVBuffer *b;
> >> +uint8_t *data;
> >> +
> >> +if (!buf || !av_buffer_is_writable(buf) || buf->data != 
> >> buf->buffer->data) {
> >> +/* Buffer can't be reused, and neither can the entire AVBufferRef.
> >> + * Unref the latter and alloc a new one. */
> >> +av_buffer_unref(pbuf);
> >> +
> >> +buf = av_buffer_alloc(size);
> >> +if (!buf)
> >> +return AVERROR(ENOMEM);
> >> +
> >> +if (zero_alloc)
> >> +memset(buf->data, 0, size);
> >> +
> >> +*pbuf = buf;
> >> +return 0;
> >> +}
> >> +b = buf->buffer;
> >> +
> >> +if (size <= b->size) {
> >> +/* Buffer can be reused. Update the size of AVBufferRef but leave 
> >> the
> >> + * AVBuffer untouched. */
> >> +buf->size = FFMAX(0, size);
> >> +return 0;
> >> +}
> >> +
> >> +/* Buffer can't be reused, but there's no need to alloc new AVBuffer 
> >> and
> >> + * AVBufferRef structs. Free the existing buffer, allocate a new one, 
> >> and
> >> + * reset AVBuffer and AVBufferRef to default values. */
> >> +b->free(b->opaque, b->data);
> >> +b->free   = av_buffer_default_free;
> >> +b->opaque = NULL;
> >> +b->flags  = 0;
> >> +
> >> +data = av_malloc(size);
> >> +if (!data) {
> >> +av_buffer_unref(pbuf);
> >> +return AVERROR(ENOMEM);
> >> +}
> >> +
> >> +if (zero_alloc)
> >> +memset(data, 0, size);
> >> +
> >> +b->data = buf->data = data;
> >> +b->size = buf->size = size;
> >> +
> >> +return 0;
> >> +}
> >> +
> >> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
> >> +{
> >> +return buffer_fast_alloc(pbuf, size, 0);
> >> +}
> >> +
> >> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
> >> +{
> >> +return buffer_fast_alloc(pbuf, size, 1);
> >> +}
> >> +
> >>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
> >> AVBufferRef* (*alloc)(void *opaque, 
> >> int size),
> >> void (*pool_free)(void *opaque))
> >> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
> >> index 73b6bd0b14..1166017d22 100644
> >> --- a/libavutil/buffer.h
> >> +++ b/libavutil/buffer.h
> >> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
> >>   */
> >>  int av_buffer_realloc(AVBufferRef **buf, int size);
> >>  
> >> +/**
> >> + * Allocate a buffer, reusing the given one if writable and large enough.
> >> + *
> >> + * @code{.c}
> >> + * AVBufferRef *buf = ...;
> >> + * int ret = av_buffer_fast_alloc(&buf, size);
> >> + * if (ret < 0) {
> >> + * // Allocation failed; buf already freed
> >> + * return ret;
> >> + * }
> >> + * @endcode
> >> + *
> >> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
> >> buffer
> >> + * reference will be written in its place. On failure, it 
> >> will be
> >> + * unreferenced and set to NULL.
> >> + * @param size Required buffer size.
> >> + *
> >> + * @return 0 on success, a negative AVERROR on failure.
> >> + *
> >> + * @see av_buffer_realloc()
> >> + * @see av_buffer_fast_allocz()
> >> + */
> >> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
> >> +
> >> +/**
> >> + * Allocate and clear a buffer, reusing the given one if writable and 
> >> large
> >> + * enough.
> >> + *
> >> + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
> >> + * cleared. Reused buffer is not cleared.
> >> + *
> >> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
> >> buffer
> >> + * reference will be written in its place. On failure, it 
> >> will be
> >> + * unreferenced and set to NULL.
> >> + * @param size Required buffer size.
> >> + *
> >> + * @return 0 on success, a negative AVERROR on failure.
> >> + *
> >> + * @see av_buffer_fast_alloc()
> >> + */
> >> +i

Re: [FFmpeg-devel] [PATCH] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread James Almer
On 3/14/2018 4:14 AM, wm4 wrote:
> On Tue, 13 Mar 2018 20:48:56 -0300
> James Almer  wrote:
> 
>> Same concept as av_fast_malloc(). If the buffer passed to it is writable
>> and big enough it will be reused, otherwise a new one will be allocated
>> instead.
>>
>> Signed-off-by: James Almer 
>> ---
>> TODO: Changelog and APIChanges entries, version bump.
>>
>>  libavutil/buffer.c | 63 
>> ++
>>  libavutil/buffer.h | 42 
>>  2 files changed, 105 insertions(+)
>>
>> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
>> index 8d1aa5fa84..16ce1b82e2 100644
>> --- a/libavutil/buffer.c
>> +++ b/libavutil/buffer.c
>> @@ -215,6 +215,69 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>>  return 0;
>>  }
>>  
>> +static av_always_inline int buffer_fast_alloc(AVBufferRef **pbuf, int size, 
>> int zero_alloc)
>> +{
>> +AVBufferRef *buf = *pbuf;
>> +AVBuffer *b;
>> +uint8_t *data;
>> +
>> +if (!buf || !av_buffer_is_writable(buf) || buf->data != 
>> buf->buffer->data) {
>> +/* Buffer can't be reused, and neither can the entire AVBufferRef.
>> + * Unref the latter and alloc a new one. */
>> +av_buffer_unref(pbuf);
>> +
>> +buf = av_buffer_alloc(size);
>> +if (!buf)
>> +return AVERROR(ENOMEM);
>> +
>> +if (zero_alloc)
>> +memset(buf->data, 0, size);
>> +
>> +*pbuf = buf;
>> +return 0;
>> +}
>> +b = buf->buffer;
>> +
>> +if (size <= b->size) {
>> +/* Buffer can be reused. Update the size of AVBufferRef but leave 
>> the
>> + * AVBuffer untouched. */
>> +buf->size = FFMAX(0, size);
>> +return 0;
>> +}
>> +
>> +/* Buffer can't be reused, but there's no need to alloc new AVBuffer and
>> + * AVBufferRef structs. Free the existing buffer, allocate a new one, 
>> and
>> + * reset AVBuffer and AVBufferRef to default values. */
>> +b->free(b->opaque, b->data);
>> +b->free   = av_buffer_default_free;
>> +b->opaque = NULL;
>> +b->flags  = 0;
>> +
>> +data = av_malloc(size);
>> +if (!data) {
>> +av_buffer_unref(pbuf);
>> +return AVERROR(ENOMEM);
>> +}
>> +
>> +if (zero_alloc)
>> +memset(data, 0, size);
>> +
>> +b->data = buf->data = data;
>> +b->size = buf->size = size;
>> +
>> +return 0;
>> +}
>> +
>> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, 0);
>> +}
>> +
>> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
>> +{
>> +return buffer_fast_alloc(pbuf, size, 1);
>> +}
>> +
>>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
>> AVBufferRef* (*alloc)(void *opaque, int 
>> size),
>> void (*pool_free)(void *opaque))
>> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
>> index 73b6bd0b14..1166017d22 100644
>> --- a/libavutil/buffer.h
>> +++ b/libavutil/buffer.h
>> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>>   */
>>  int av_buffer_realloc(AVBufferRef **buf, int size);
>>  
>> +/**
>> + * Allocate a buffer, reusing the given one if writable and large enough.
>> + *
>> + * @code{.c}
>> + * AVBufferRef *buf = ...;
>> + * int ret = av_buffer_fast_alloc(&buf, size);
>> + * if (ret < 0) {
>> + * // Allocation failed; buf already freed
>> + * return ret;
>> + * }
>> + * @endcode
>> + *
>> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>> buffer
>> + * reference will be written in its place. On failure, it will 
>> be
>> + * unreferenced and set to NULL.
>> + * @param size Required buffer size.
>> + *
>> + * @return 0 on success, a negative AVERROR on failure.
>> + *
>> + * @see av_buffer_realloc()
>> + * @see av_buffer_fast_allocz()
>> + */
>> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
>> +
>> +/**
>> + * Allocate and clear a buffer, reusing the given one if writable and large
>> + * enough.
>> + *
>> + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
>> + * cleared. Reused buffer is not cleared.
>> + *
>> + * @param buf  A buffer reference. *buf may be NULL. On success, a new 
>> buffer
>> + * reference will be written in its place. On failure, it will 
>> be
>> + * unreferenced and set to NULL.
>> + * @param size Required buffer size.
>> + *
>> + * @return 0 on success, a negative AVERROR on failure.
>> + *
>> + * @see av_buffer_fast_alloc()
>> + */
>> +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
>> +
>>  /**
>>   * @}
>>   */
> 
> Wouldn't it be better to avoid writing a lot of new allocation code
> (with possibly subtle problems), and just use av_buffer_realloc() to
> handle reallocation? (Possibly it could be moved to an internal
> function to avoid the memcpy() required by realloc.)

There are some d

Re: [FFmpeg-devel] [PATCH] doc/utils: document the "ms" and "us" suffixes for durations

2018-03-14 Thread Moritz Barsnick
On Sat, Mar 10, 2018 at 19:32:09 +0100, Moritz Barsnick wrote:
> These suffixes were recently introduced in 
> 61c972384d311508d07f9360d196909e27195655
> and completed in 8218249f1f04de65904f58519bde21948e5a0783.

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


Re: [FFmpeg-devel] [PATCH v2 1/1] libavformat/hlsenc: Option to set timeout for socket I/O operation

2018-03-14 Thread Dixit, Vishwanath


On 3/14/18 5:31 PM, Steven Liu wrote:
>
>
>> On 14 Mar 2018, at 19:57, Steven Liu  wrote:
>>
>>
>>
>>> On 14 Mar 2018, at 19:45, Dixit, Vishwanath  wrote:
>>>
>>>
>>> On 3/6/18 2:12 PM, Steven Liu wrote:


> On 5 Mar 2018, at 17:41, rpata...@akamai.com wrote:
>
> From: Ravindra 
>
> ---
> doc/muxers.texi  | 3 +++
> libavformat/hlsenc.c | 5 -
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index c156ec0..3a63da7 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -964,6 +964,9 @@ publishing it repeatedly every after 30 segments i.e. 
> every after 60s.
> @item http_persistent
> Use persistent HTTP connections. Applicable only for HTTP output.
>
> +@item timeout
> +Set timeout for socket I/O operations. Applicable only for HTTP output.
> +
> @end table
>
> @anchor{ico}
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 08fe0aa..5d462da 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -224,6 +224,7 @@ typedef struct HLSContext {
>   int http_persistent;
>   AVIOContext *m3u8_out;
>   AVIOContext *sub_m3u8_out;
> +int64_t timeout;
> } HLSContext;
>
> static int mkdir_p(const char *path) {
> @@ -305,7 +306,8 @@ static void set_http_options(AVFormatContext *s, 
> AVDictionary **options, HLSCont
>   av_dict_set(options, "user_agent", c->user_agent, 0);
>   if (c->http_persistent)
>   av_dict_set_int(options, "multiple_requests", 1, 0);
> -
> +if (c->timeout >= 0)
> +av_dict_set_int(options, "timeout", c->timeout, 0);
> }
>
> static void write_codec_attr(AVStream *st, VariantStream *vs) {
> @@ -2792,6 +2794,7 @@ static const AVOption options[] = {
>   {"master_pl_name", "Create HLS master playlist with this name", 
> OFFSET(master_pl_name), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
>   {"master_pl_publish_rate", "Publish master play list every after this 
> many segment intervals", OFFSET(master_publish_rate), AV_OPT_TYPE_INT, 
> {.i64 = 0}, 0, UINT_MAX, E},
>   {"http_persistent", "Use persistent HTTP connections", 
> OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
> +{"timeout", "set timeout for socket I/O operations", 
> OFFSET(timeout), AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags 
> = E },
>   { NULL },
> };
>
> -- 
> 1.9.1
>

 Will apply!

>>> Hi Steven,
>>>
>>> Could you please apply this patch. 
>> Oops, Sorry for delay apply this, i pushed it now.
> Done.
>>>
Thank you Steven…

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


Re: [FFmpeg-devel] [PATCH] avcodec/openh264enc.c: generate IDR frame in response to I frame pict_type

2018-03-14 Thread Moritz Barsnick
On Mon, Mar 12, 2018 at 14:38:21 -0800, Lou Logan wrote:

> But you don't necessarily need to make a new patch to address the
> minor whitespace issue. You can wait for other comments and include
> it with any other requested changes.

Another whitespace nit:

>  if (frame->pict_type==AV_PICTURE_TYPE_I) {

Please use single spaces around operators, i.e.
  if (frame->pict_type == AV_PICTURE_TYPE_I) {

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


Re: [FFmpeg-devel] [PATCH] Fix iterating of input and output devices

2018-03-14 Thread Felix Matouschek

My bad

Am 14.03.2018 13:25, schrieb Timo Rothenpieler:

-if (!(prev = ((AVOutputFormat *)prev)->next))
+if (!(prev = prev ? ((AVInputFormat *)prev)->next :

(void*)outdev_list[0]))

AVOutputFormat


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-develFrom cd8842ecf606d368832066fcda925c705e9e9205 Mon Sep 17 00:00:00 2001
From: Felix Matouschek 
Date: Wed, 14 Mar 2018 13:14:07 +0100
Subject: [PATCH] Fix iterating of input and output devices
To: ffmpeg-devel@ffmpeg.org

In the previous implementation the first input or output device
was skipped when device_next was called with prev = NULL

Signed-off-by: Felix Matouschek 
---
 libavdevice/alldevices.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 4c89649b97..39993354bc 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -126,16 +126,13 @@ static void *device_next(void *prev, int output,
 
 ff_thread_once(&av_device_next_init, av_device_init_next);
 
-if (!prev && !(prev = (output ? (void*)outdev_list[0] : (void*)indev_list[0])))
-return NULL;
-
 do {
 if (output) {
-if (!(prev = ((AVOutputFormat *)prev)->next))
+if (!(prev = prev ? ((AVOutputFormat *)prev)->next : (void*)outdev_list[0]))
 break;
 pc = ((AVOutputFormat *)prev)->priv_class;
 } else {
-if (!(prev = ((AVInputFormat *)prev)->next))
+if (!(prev = prev ? ((AVInputFormat *)prev)->next : (void*)indev_list[0]))
 break;
 pc = ((AVInputFormat *)prev)->priv_class;
 }
-- 
2.14.1.windows.1

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


Re: [FFmpeg-devel] [PATCH] Fix iterating of input and output devices

2018-03-14 Thread Timo Rothenpieler
>-if (!(prev = ((AVOutputFormat *)prev)->next))
>+if (!(prev = prev ? ((AVInputFormat *)prev)->next :
(void*)outdev_list[0]))

AVOutputFormat



smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Fix iterating of input and output devices

2018-03-14 Thread Felix Matouschek

This fixes the iterating of input and output devices

In the previous implementation the first input or output device
was skipped when device_next was called with prev = NULLFrom f90823e8dccf5751e88b8990f5789d8f67e7c496 Mon Sep 17 00:00:00 2001
From: Felix Matouschek 
Date: Wed, 14 Mar 2018 13:14:07 +0100
Subject: [PATCH] Fix iterating of input and output devices
To: ffmpeg-devel@ffmpeg.org

In the previous implementation the first input or output device
was skipped when device_next was called with prev = NULL

Signed-off-by: Felix Matouschek 
---
 libavdevice/alldevices.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 4c89649b97..271a3182a0 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -126,16 +126,13 @@ static void *device_next(void *prev, int output,
 
 ff_thread_once(&av_device_next_init, av_device_init_next);
 
-if (!prev && !(prev = (output ? (void*)outdev_list[0] : (void*)indev_list[0])))
-return NULL;
-
 do {
 if (output) {
-if (!(prev = ((AVOutputFormat *)prev)->next))
+if (!(prev = prev ? ((AVInputFormat *)prev)->next : (void*)outdev_list[0]))
 break;
 pc = ((AVOutputFormat *)prev)->priv_class;
 } else {
-if (!(prev = ((AVInputFormat *)prev)->next))
+if (!(prev = prev ? ((AVInputFormat *)prev)->next : (void*)indev_list[0]))
 break;
 pc = ((AVInputFormat *)prev)->priv_class;
 }
-- 
2.14.1.windows.1

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


Re: [FFmpeg-devel] [PATCH v2 1/1] libavformat/hlsenc: Option to set timeout for socket I/O operation

2018-03-14 Thread Steven Liu


> On 14 Mar 2018, at 19:57, Steven Liu  wrote:
> 
> 
> 
>> On 14 Mar 2018, at 19:45, Dixit, Vishwanath  wrote:
>> 
>> 
>> On 3/6/18 2:12 PM, Steven Liu wrote:
>>> 
>>> 
 On 5 Mar 2018, at 17:41, rpata...@akamai.com wrote:
 
 From: Ravindra 
 
 ---
 doc/muxers.texi  | 3 +++
 libavformat/hlsenc.c | 5 -
 2 files changed, 7 insertions(+), 1 deletion(-)
 
 diff --git a/doc/muxers.texi b/doc/muxers.texi
 index c156ec0..3a63da7 100644
 --- a/doc/muxers.texi
 +++ b/doc/muxers.texi
 @@ -964,6 +964,9 @@ publishing it repeatedly every after 30 segments i.e. 
 every after 60s.
 @item http_persistent
 Use persistent HTTP connections. Applicable only for HTTP output.
 
 +@item timeout
 +Set timeout for socket I/O operations. Applicable only for HTTP output.
 +
 @end table
 
 @anchor{ico}
 diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
 index 08fe0aa..5d462da 100644
 --- a/libavformat/hlsenc.c
 +++ b/libavformat/hlsenc.c
 @@ -224,6 +224,7 @@ typedef struct HLSContext {
   int http_persistent;
   AVIOContext *m3u8_out;
   AVIOContext *sub_m3u8_out;
 +int64_t timeout;
 } HLSContext;
 
 static int mkdir_p(const char *path) {
 @@ -305,7 +306,8 @@ static void set_http_options(AVFormatContext *s, 
 AVDictionary **options, HLSCont
   av_dict_set(options, "user_agent", c->user_agent, 0);
   if (c->http_persistent)
   av_dict_set_int(options, "multiple_requests", 1, 0);
 -
 +if (c->timeout >= 0)
 +av_dict_set_int(options, "timeout", c->timeout, 0);
 }
 
 static void write_codec_attr(AVStream *st, VariantStream *vs) {
 @@ -2792,6 +2794,7 @@ static const AVOption options[] = {
   {"master_pl_name", "Create HLS master playlist with this name", 
 OFFSET(master_pl_name), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
   {"master_pl_publish_rate", "Publish master play list every after this 
 many segment intervals", OFFSET(master_publish_rate), AV_OPT_TYPE_INT, 
 {.i64 = 0}, 0, UINT_MAX, E},
   {"http_persistent", "Use persistent HTTP connections", 
 OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
 +{"timeout", "set timeout for socket I/O operations", OFFSET(timeout), 
 AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags = E },
   { NULL },
 };
 
 -- 
 1.9.1
 
>>> 
>>> Will apply!
>>> 
>> Hi Steven,
>> 
>> Could you please apply this patch. 
> Oops, Sorry for delay apply this, i pushed it now.
Done.
>> 
>> PS: following up on behalf of Ravindra Patagar
>> 
>> Regards,
>> Vishwanath
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> Thanks
> Steven

Thanks
Steven





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


Re: [FFmpeg-devel] [PATCH]download: Use git.ffmpeg.org to browse repository

2018-03-14 Thread Carl Eugen Hoyos
2018-03-09 0:02 GMT+01:00, Lou Logan :
> On Thu, 8 Mar 2018 23:37:19 +0100
> Carl Eugen Hoyos  wrote:

>> diff --git a/src/download b/src/download
>> index 6783c35..b03e3d0 100644
>> --- a/src/download
>> +++ b/src/download
>> @@ -143,7 +143,7 @@
>>
>>Snapshot
>>    
>> -https://github.com/FFmpeg/FFmpeg"; class="btn
>> btn-success">
>> +https://git.ffmpeg.org/gitweb/ffmpeg.git"; class="btn
>> btn-success">
>>Browse
>>  
>>
>
> Fine with me.

Patch applied.

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


Re: [FFmpeg-devel] [PATCH v2 1/1] libavformat/hlsenc: Option to set timeout for socket I/O operation

2018-03-14 Thread Steven Liu


> On 14 Mar 2018, at 19:45, Dixit, Vishwanath  wrote:
> 
> 
> On 3/6/18 2:12 PM, Steven Liu wrote:
>> 
>> 
>>> On 5 Mar 2018, at 17:41, rpata...@akamai.com wrote:
>>> 
>>> From: Ravindra 
>>> 
>>> ---
>>> doc/muxers.texi  | 3 +++
>>> libavformat/hlsenc.c | 5 -
>>> 2 files changed, 7 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>> index c156ec0..3a63da7 100644
>>> --- a/doc/muxers.texi
>>> +++ b/doc/muxers.texi
>>> @@ -964,6 +964,9 @@ publishing it repeatedly every after 30 segments i.e. 
>>> every after 60s.
>>> @item http_persistent
>>> Use persistent HTTP connections. Applicable only for HTTP output.
>>> 
>>> +@item timeout
>>> +Set timeout for socket I/O operations. Applicable only for HTTP output.
>>> +
>>> @end table
>>> 
>>> @anchor{ico}
>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>> index 08fe0aa..5d462da 100644
>>> --- a/libavformat/hlsenc.c
>>> +++ b/libavformat/hlsenc.c
>>> @@ -224,6 +224,7 @@ typedef struct HLSContext {
>>>int http_persistent;
>>>AVIOContext *m3u8_out;
>>>AVIOContext *sub_m3u8_out;
>>> +int64_t timeout;
>>> } HLSContext;
>>> 
>>> static int mkdir_p(const char *path) {
>>> @@ -305,7 +306,8 @@ static void set_http_options(AVFormatContext *s, 
>>> AVDictionary **options, HLSCont
>>>av_dict_set(options, "user_agent", c->user_agent, 0);
>>>if (c->http_persistent)
>>>av_dict_set_int(options, "multiple_requests", 1, 0);
>>> -
>>> +if (c->timeout >= 0)
>>> +av_dict_set_int(options, "timeout", c->timeout, 0);
>>> }
>>> 
>>> static void write_codec_attr(AVStream *st, VariantStream *vs) {
>>> @@ -2792,6 +2794,7 @@ static const AVOption options[] = {
>>>{"master_pl_name", "Create HLS master playlist with this name", 
>>> OFFSET(master_pl_name), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
>>>{"master_pl_publish_rate", "Publish master play list every after this 
>>> many segment intervals", OFFSET(master_publish_rate), AV_OPT_TYPE_INT, 
>>> {.i64 = 0}, 0, UINT_MAX, E},
>>>{"http_persistent", "Use persistent HTTP connections", 
>>> OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
>>> +{"timeout", "set timeout for socket I/O operations", OFFSET(timeout), 
>>> AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags = E },
>>>{ NULL },
>>> };
>>> 
>>> -- 
>>> 1.9.1
>>> 
>> 
>> Will apply!
>> 
> Hi Steven,
> 
> Could you please apply this patch. 
Oops, Sorry for delay apply this, i pushed it now.
> 
> PS: following up on behalf of Ravindra Patagar
> 
> Regards,
> Vishwanath
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thanks
Steven





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


Re: [FFmpeg-devel] [PATCH v2 1/1] libavformat/hlsenc: Option to set timeout for socket I/O operation

2018-03-14 Thread Dixit, Vishwanath

On 3/6/18 2:12 PM, Steven Liu wrote:
>
>
>> On 5 Mar 2018, at 17:41, rpata...@akamai.com wrote:
>>
>> From: Ravindra 
>>
>> ---
>> doc/muxers.texi  | 3 +++
>> libavformat/hlsenc.c | 5 -
>> 2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index c156ec0..3a63da7 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -964,6 +964,9 @@ publishing it repeatedly every after 30 segments i.e. 
>> every after 60s.
>> @item http_persistent
>> Use persistent HTTP connections. Applicable only for HTTP output.
>>
>> +@item timeout
>> +Set timeout for socket I/O operations. Applicable only for HTTP output.
>> +
>> @end table
>>
>> @anchor{ico}
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index 08fe0aa..5d462da 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -224,6 +224,7 @@ typedef struct HLSContext {
>> int http_persistent;
>> AVIOContext *m3u8_out;
>> AVIOContext *sub_m3u8_out;
>> +int64_t timeout;
>> } HLSContext;
>>
>> static int mkdir_p(const char *path) {
>> @@ -305,7 +306,8 @@ static void set_http_options(AVFormatContext *s, 
>> AVDictionary **options, HLSCont
>> av_dict_set(options, "user_agent", c->user_agent, 0);
>> if (c->http_persistent)
>> av_dict_set_int(options, "multiple_requests", 1, 0);
>> -
>> +if (c->timeout >= 0)
>> +av_dict_set_int(options, "timeout", c->timeout, 0);
>> }
>>
>> static void write_codec_attr(AVStream *st, VariantStream *vs) {
>> @@ -2792,6 +2794,7 @@ static const AVOption options[] = {
>> {"master_pl_name", "Create HLS master playlist with this name", 
>> OFFSET(master_pl_name), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
>> {"master_pl_publish_rate", "Publish master play list every after this 
>> many segment intervals", OFFSET(master_publish_rate), AV_OPT_TYPE_INT, {.i64 
>> = 0}, 0, UINT_MAX, E},
>> {"http_persistent", "Use persistent HTTP connections", 
>> OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
>> +{"timeout", "set timeout for socket I/O operations", OFFSET(timeout), 
>> AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags = E },
>> { NULL },
>> };
>>
>> -- 
>> 1.9.1
>>
>
> Will apply!
>
Hi Steven,

Could you please apply this patch. 

PS: following up on behalf of Ravindra Patagar

Regards,
Vishwanath

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


Re: [FFmpeg-devel] [PATCH] libavfilter: Add OpenCL convolution filter v0.1

2018-03-14 Thread Carl Eugen Hoyos
2018-03-14 10:43 GMT+01:00, Danil Iashchenko :

> About sscanf. I had (!err_code) condition, because I would never
> get empty line as option (if not specified, I always have default
> matrix), but changed to (err_code != 1) due to read-ability.

Was this requested?
I ask because several developers believe the opposite is true...

[...]

> --- /dev/null
> +++ b/libavfilter/opencl/convolution.cl
> @@ -0,0 +1,46 @@
> +/*
> + * This file is part of FFmpeg.

Please add your name.

[...]

> +for (i = 0; i < 4; i++) {
> +p = ctx->matrix_str[i];
> +while (ctx->matrix_size[i] < 49) {

> +if (!(arg = av_strtok(p, " ", &saveptr)))

Please split this line.

And ask one of the mentors to add your name to the OpenCL project
on https://trac.ffmpeg.org/wiki/SponsoringPrograms/GSoC/2018 -
other potential students should know that you are interested in this
project and that you have (nearly) completed a qualification task.

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


[FFmpeg-devel] [PATCH] libavfilter: Add OpenCL convolution filter v0.1

2018-03-14 Thread Danil Iashchenko
Behaves like the existing convolution filter, except working on OpenCL
hardware frames.
Takes exactly the same options: 4 convolution matrices, 4 rdiv values, 4 bias 
values.
If not specified, default parameters are applied.
Matrices can be different sizes.

NEW IN THIS PATCH:
-fixed bug, if matrices have different dims.
-renamed some variables due to readability.

filter applies:
matrix0, rdiv0, bias0 to image plane0.
matrix1, rdiv1, bias1 to image plane1.
matrix2, rdiv2, bias2 to image plane2.
matrix3, rdiv3, bias3 to image plane3.

About Kernel parameters:
dst - destination image
src - source image
coef_matrices_dims - stores dimensions of matrix{0..3} consecutively one after 
the other
coef_matrices - stores matrices{0..3} consecutively one after the other
rdivs - stores rdiv{0..3} parameters consecutively one after the other
biases - stores bias{0..3} parameters consecutively one after the other

About sscanf. I had (!err_code) condition, because I would never get empty line
as option(if not specified, I always have default matrix), but changed to 
(err_code != 1) due to read-ability.
Also, before sscanf I split matrix with spaces, so I process each single value
of matrix seperately from others and check if they are ok.

about rdiv_buffer, bias_buffer, dims_buffer objects: they should be buffer 
objects, because they store sequence of values, not a single value

---
 configure   |   1 +
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/opencl/convolution.cl   |  46 
 libavfilter/opencl_source.h |   1 +
 libavfilter/vf_convolution_opencl.c | 449 
 6 files changed, 499 insertions(+)
 create mode 100644 libavfilter/opencl/convolution.cl
 create mode 100644 libavfilter/vf_convolution_opencl.c

diff --git a/configure b/configure
index 6916b45..bf5c312 100755
--- a/configure
+++ b/configure
@@ -3210,6 +3210,7 @@ blackframe_filter_deps="gpl"
 boxblur_filter_deps="gpl"
 bs2b_filter_deps="libbs2b"
 colormatrix_filter_deps="gpl"
+convolution_opencl_filter_deps="opencl"
 convolve_filter_deps="avcodec"
 convolve_filter_select="fft"
 coreimage_filter_deps="coreimage appkit"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 6a60836..d005934 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -156,6 +156,7 @@ OBJS-$(CONFIG_COLORLEVELS_FILTER)+= 
vf_colorlevels.o
 OBJS-$(CONFIG_COLORMATRIX_FILTER)+= vf_colormatrix.o
 OBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o colorspacedsp.o
 OBJS-$(CONFIG_CONVOLUTION_FILTER)+= vf_convolution.o
+OBJS-$(CONFIG_CONVOLUTION_OPENCL_FILTER) += vf_convolution_opencl.o 
opencl.o opencl/convolution.o
 OBJS-$(CONFIG_CONVOLVE_FILTER)   += vf_convolve.o framesync.o
 OBJS-$(CONFIG_COPY_FILTER)   += vf_copy.o
 OBJS-$(CONFIG_COREIMAGE_FILTER)  += vf_coreimage.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9adb109..f2dc55e 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -166,6 +166,7 @@ static void register_all(void)
 REGISTER_FILTER(COLORMATRIX,colormatrix,vf);
 REGISTER_FILTER(COLORSPACE, colorspace, vf);
 REGISTER_FILTER(CONVOLUTION,convolution,vf);
+REGISTER_FILTER(CONVOLUTION_OPENCL, convolution_opencl, vf);
 REGISTER_FILTER(CONVOLVE,   convolve,   vf);
 REGISTER_FILTER(COPY,   copy,   vf);
 REGISTER_FILTER(COREIMAGE,  coreimage,  vf);
diff --git a/libavfilter/opencl/convolution.cl 
b/libavfilter/opencl/convolution.cl
new file mode 100644
index 000..192f1ef
--- /dev/null
+++ b/libavfilter/opencl/convolution.cl
@@ -0,0 +1,46 @@
+/*
+ * 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
+ */
+
+__kernel void convolution_global(__write_only image2d_t dst,
+ __read_only  image2d_t src,
+ __constant int *coef_matrices_dims,
+ __constant float *coef_matrices,
+ __constant float *rdivs,
+ __constant float *biases)
+{
+const sampler_t sampler = (CLK_NORMALI

[FFmpeg-devel] [PATCH 1/2] fftools/cmdutils: add logflags option

2018-03-14 Thread Tobias Rapp
Allows to set the AV_LOG_PRINT_LEVEL and AV_LOG_SKIP_REPEATED flags
using a distinct command-line option, similar to other flag options.
Previously only the AV_LOG_SKIP_REPEATED flag was supported as a prefix
to the "loglevel" option value.

Signed-off-by: Tobias Rapp 
---
 doc/fftools-common-opts.texi | 13 +
 fftools/cmdutils.c   | 31 +++
 fftools/cmdutils.h   |  6 ++
 3 files changed, 50 insertions(+)

diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 185ec21..dd69741 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -209,6 +209,19 @@ the environment variable @env{AV_LOG_FORCE_COLOR}.
 The use of the environment variable @env{NO_COLOR} is deprecated and
 will be dropped in a future FFmpeg version.
 
+@item -logflags flags (@emph{global})
+Allows to set or clear logging flags.
+
+Possible flags for this option are:
+@table @option
+@item repeat
+Repeated log output will not be compressed to the first line and the "Last
+message repeated n times" line will be omitted.
+@item level
+Add a @code{[level]} prefix string to each log message. Can be used as an
+alternative to log coloring e.g. when dumping the log to file.
+@end table
+
 @item -report
 Dump full command line and console output to a file named
 @code{@var{program}-@var{MMDD}-@var{HHMMSS}.log} in the current
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 0c7d13c..11fe69a 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -514,6 +514,9 @@ void parse_loglevel(int argc, char **argv, const OptionDef 
*options)
 idx = locate_option(argc, argv, options, "v");
 if (idx && argv[idx + 1])
 opt_loglevel(NULL, "loglevel", argv[idx + 1]);
+idx = locate_option(argc, argv, options, "logflags");
+if (idx && argv[idx + 1])
+opt_logflags(NULL, "logflags", argv[idx + 1]);
 idx = locate_option(argc, argv, options, "report");
 if ((env = getenv("FFREPORT")) || idx) {
 init_report(env);
@@ -918,6 +921,34 @@ int opt_loglevel(void *optctx, const char *opt, const char 
*arg)
 return 0;
 }
 
+int opt_logflags(void *optctx, const char *opt, const char *arg)
+{
+static const AVOption logflags_opts[] = {
+{ "flags" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, 
INT64_MAX, .unit = "flags" },
+/* implement AV_LOG_SKIP_REPEATED using inverse logic for consistency 
with the -loglevel option */
+{ "repeat", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_LOG_SKIP_REPEATED 
},.unit = "flags" },
+{ "level" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_LOG_PRINT_LEVEL   
},.unit = "flags" },
+{ NULL },
+};
+static const AVClass class = {
+.class_name = "logflags",
+.item_name  = av_default_item_name,
+.option = logflags_opts,
+.version= LIBAVUTIL_VERSION_INT,
+};
+const AVClass *pclass = &class;
+int flags = av_log_get_flags();
+int ret;
+
+flags ^= AV_LOG_SKIP_REPEATED;
+if ((ret = av_opt_eval_flags(&pclass, &logflags_opts[0], arg, &flags)) < 0)
+return ret;
+flags ^= AV_LOG_SKIP_REPEATED;
+
+av_log_set_flags(flags);
+return 0;
+}
+
 static void expand_filename_template(AVBPrint *bp, const char *template,
  struct tm *tm)
 {
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 8724489..28735b2 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -99,6 +99,11 @@ int opt_default(void *optctx, const char *opt, const char 
*arg);
  */
 int opt_loglevel(void *optctx, const char *opt, const char *arg);
 
+/**
+ * Update the log flags of libav* libraries.
+ */
+int opt_logflags(void *optctx, const char *opt, const char *arg);
+
 int opt_report(const char *opt);
 
 int opt_max_alloc(void *optctx, const char *opt, const char *arg);
@@ -236,6 +241,7 @@ void show_help_options(const OptionDef *options, const char 
*msg, int req_flags,
 { "colors",  OPT_EXIT, { .func_arg = show_colors },  
"show available color names" },\
 { "loglevel",HAS_ARG,  { .func_arg = opt_loglevel }, 
"set logging level", "loglevel" }, \
 { "v",   HAS_ARG,  { .func_arg = opt_loglevel }, 
"set logging level", "loglevel" }, \
+{ "logflags",HAS_ARG,  { .func_arg = opt_logflags }, 
"set logging flags", "flags" },\
 { "report",  0,{ (void*)opt_report },
"generate a report" }, \
 { "max_alloc",   HAS_ARG,  { .func_arg = opt_max_alloc },
"set maximum size of a single allocated block", "bytes" }, \
 { "cpuflags",HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, 
"force specific cpu flags", "flags" }, \
-- 
2.7.4


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
h

[FFmpeg-devel] [PATCH 2/2] avutil/log: print level prefix also when no AVClass context is available

2018-03-14 Thread Tobias Rapp
Adds the level prefix to all log messages, except those with level <=
AV_LOG_QUIET as they seem to be used for flushing the log buffer.

Signed-off-by: Tobias Rapp 
---
 libavutil/log.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavutil/log.c b/libavutil/log.c
index bd47f2a..9b7d484 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -266,11 +266,11 @@ static void format_line(void *avcl, int level, const char 
*fmt, va_list vl,
 av_bprintf(part+1, "[%s @ %p] ",
  avc->item_name(avcl), avcl);
 if(type) type[1] = get_category(avcl);
-
-if (flags & AV_LOG_PRINT_LEVEL)
-av_bprintf(part+2, "[%s] ", get_level_str(level));
 }
 
+if (*print_prefix && (level > AV_LOG_QUIET) && (flags & 
AV_LOG_PRINT_LEVEL))
+av_bprintf(part+2, "[%s] ", get_level_str(level));
+
 av_vbprintf(part+3, fmt, vl);
 
 if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) {
-- 
2.7.4


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


Re: [FFmpeg-devel] [PATCH v2] Change cube faces order to match Youtube's

2018-03-14 Thread Paul B Mahol
On 3/14/18, Hazem Ashmawy  wrote:
> So I'm still looking into using bilinear instead of nearest. Most of
> the online discussions are in the context of computer graphics and
> using things like openGL shaders.
>
> One solution I found and may try to implement is to add padding pixels
> around each face tile in the input frame. This should help in handling
> sampling near cube edges and corners. However, I'm not sure about the
> complexity of this or its effect on the performance. WDYT?

Either that or doing it hard way, by picking different pixels for each face.
Anyway that (padding) solution doesn't sound that bad, and is much simpler than
above mentioned alternative.

>
> Meanwhile this is a hacky/lazy way to use bilinear, but I can barely
> notice any improvements
> over using nearest by my bare eyes, are there any systematic way to
> evaluate the quality?

Not realy. One could compare with another projection conversion utility,
there are at least two freely available AFAIK.

> https://github.com/HazemSamir/FFmpeg/commit/fcd82b9782b5f32072d9b0516b275fe3d4f4a163
>
> On 3/12/18, Paul B Mahol  wrote:
>> On 3/12/18, Hazem Ashmawy  wrote:
>>> On 3/12/18, Paul B Mahol  wrote:
 On 3/12/18, Hazem Ashmawy  wrote:
> Sorry about that! Here is github branch
>
> https://github.com/FFmpeg/FFmpeg/compare/master...HazemSamir:panorama_youtube

 Good, now can you look at how to use bilinear instead of nearest
 interpolation
 for cubemap to equirectangular conversion.

 Nearest is extremly ugly.

>>> Sure, will look into that. Just to take that into my consideration,
>>> why didn't you use it at the first place? Were there any obstacles?
>>
>> It was non-trivial to do.
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg_filter: enable stream_loop in HWAccel transcoding.

2018-03-14 Thread Jun Zhao

From 731b6cb1f3a13fa18cfe39c1ddba92050b999668 Mon Sep 17 00:00:00 2001
From: Jun Zhao 
Date: Wed, 14 Mar 2018 16:13:39 +0800
Subject: [PATCH] ffmpeg_filter: enable stream_loop in HWAccel transcoding.

use the cmd: ffmpeg -y -stream_loop 1 -hwaccel vaapi -hwaccel_device
/dev/dri/renderD128 -hwaccel_output_format vaapi -i
input.mp4 -c:v h264_vaapi output.mp4 can get the error like:

Error while decoding stream #0:1: Invalid data found when processing
input
Impossible to convert between the formats supported by the filter
'Parsed_null_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented

the root cause is can't insert software scale filter in the hwaccel
transcoding pipeline.

Signed-off-by: Jun Zhao 
---
 fftools/ffmpeg_filter.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 877fd670e6..c85dd7ae8d 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -452,6 +452,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
OutputFilter *ofilter,
 int pad_idx = out->pad_idx;
 int ret;
 char name[255];
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(ofilter->format);
 
 snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
 ret = avfilter_graph_create_filter(&ofilter->filter,
@@ -461,7 +462,8 @@ static int configure_output_video_filter(FilterGraph *fg, 
OutputFilter *ofilter,
 if (ret < 0)
 return ret;
 
-if (ofilter->width || ofilter->height) {
+if ((ofilter->width || ofilter->height) &&
+(!desc || (desc && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL {
 char args[255];
 AVFilterContext *filter;
 AVDictionaryEntry *e = NULL;
-- 
2.14.1

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


Re: [FFmpeg-devel] [PATCH v2] Change cube faces order to match Youtube's

2018-03-14 Thread Hazem Ashmawy
So I'm still looking into using bilinear instead of nearest. Most of
the online discussions are in the context of computer graphics and
using things like openGL shaders.

One solution I found and may try to implement is to add padding pixels
around each face tile in the input frame. This should help in handling
sampling near cube edges and corners. However, I'm not sure about the
complexity of this or its effect on the performance. WDYT?

Meanwhile this is a hacky/lazy way to use bilinear, but I can barely
notice any improvements
over using nearest by my bare eyes, are there any systematic way to
evaluate the quality?
https://github.com/HazemSamir/FFmpeg/commit/fcd82b9782b5f32072d9b0516b275fe3d4f4a163

On 3/12/18, Paul B Mahol  wrote:
> On 3/12/18, Hazem Ashmawy  wrote:
>> On 3/12/18, Paul B Mahol  wrote:
>>> On 3/12/18, Hazem Ashmawy  wrote:
 Sorry about that! Here is github branch

 https://github.com/FFmpeg/FFmpeg/compare/master...HazemSamir:panorama_youtube
>>>
>>> Good, now can you look at how to use bilinear instead of nearest
>>> interpolation
>>> for cubemap to equirectangular conversion.
>>>
>>> Nearest is extremly ugly.
>>>
>> Sure, will look into that. Just to take that into my consideration,
>> why didn't you use it at the first place? Were there any obstacles?
>
> It was non-trivial to do.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2018-03-14 Thread Sven Dueking
Updated patch according to latest feedback :

- spelling errors and capitalization
- renamed option "timeout" -> "rw_timeout"
- changed max values for duration parameters to INT64_MAX



0001-avformat-opensrt-add-Haivision-Open-SRT-protocol.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/buffer: add av_buffer_fast_alloc()

2018-03-14 Thread wm4
On Tue, 13 Mar 2018 20:48:56 -0300
James Almer  wrote:

> Same concept as av_fast_malloc(). If the buffer passed to it is writable
> and big enough it will be reused, otherwise a new one will be allocated
> instead.
> 
> Signed-off-by: James Almer 
> ---
> TODO: Changelog and APIChanges entries, version bump.
> 
>  libavutil/buffer.c | 63 
> ++
>  libavutil/buffer.h | 42 
>  2 files changed, 105 insertions(+)
> 
> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> index 8d1aa5fa84..16ce1b82e2 100644
> --- a/libavutil/buffer.c
> +++ b/libavutil/buffer.c
> @@ -215,6 +215,69 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
>  return 0;
>  }
>  
> +static av_always_inline int buffer_fast_alloc(AVBufferRef **pbuf, int size, 
> int zero_alloc)
> +{
> +AVBufferRef *buf = *pbuf;
> +AVBuffer *b;
> +uint8_t *data;
> +
> +if (!buf || !av_buffer_is_writable(buf) || buf->data != 
> buf->buffer->data) {
> +/* Buffer can't be reused, and neither can the entire AVBufferRef.
> + * Unref the latter and alloc a new one. */
> +av_buffer_unref(pbuf);
> +
> +buf = av_buffer_alloc(size);
> +if (!buf)
> +return AVERROR(ENOMEM);
> +
> +if (zero_alloc)
> +memset(buf->data, 0, size);
> +
> +*pbuf = buf;
> +return 0;
> +}
> +b = buf->buffer;
> +
> +if (size <= b->size) {
> +/* Buffer can be reused. Update the size of AVBufferRef but leave the
> + * AVBuffer untouched. */
> +buf->size = FFMAX(0, size);
> +return 0;
> +}
> +
> +/* Buffer can't be reused, but there's no need to alloc new AVBuffer and
> + * AVBufferRef structs. Free the existing buffer, allocate a new one, and
> + * reset AVBuffer and AVBufferRef to default values. */
> +b->free(b->opaque, b->data);
> +b->free   = av_buffer_default_free;
> +b->opaque = NULL;
> +b->flags  = 0;
> +
> +data = av_malloc(size);
> +if (!data) {
> +av_buffer_unref(pbuf);
> +return AVERROR(ENOMEM);
> +}
> +
> +if (zero_alloc)
> +memset(data, 0, size);
> +
> +b->data = buf->data = data;
> +b->size = buf->size = size;
> +
> +return 0;
> +}
> +
> +int av_buffer_fast_alloc(AVBufferRef **pbuf, int size)
> +{
> +return buffer_fast_alloc(pbuf, size, 0);
> +}
> +
> +int av_buffer_fast_allocz(AVBufferRef **pbuf, int size)
> +{
> +return buffer_fast_alloc(pbuf, size, 1);
> +}
> +
>  AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
> AVBufferRef* (*alloc)(void *opaque, int 
> size),
> void (*pool_free)(void *opaque))
> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
> index 73b6bd0b14..1166017d22 100644
> --- a/libavutil/buffer.h
> +++ b/libavutil/buffer.h
> @@ -197,6 +197,48 @@ int av_buffer_make_writable(AVBufferRef **buf);
>   */
>  int av_buffer_realloc(AVBufferRef **buf, int size);
>  
> +/**
> + * Allocate a buffer, reusing the given one if writable and large enough.
> + *
> + * @code{.c}
> + * AVBufferRef *buf = ...;
> + * int ret = av_buffer_fast_alloc(&buf, size);
> + * if (ret < 0) {
> + * // Allocation failed; buf already freed
> + * return ret;
> + * }
> + * @endcode
> + *
> + * @param buf  A buffer reference. *buf may be NULL. On success, a new buffer
> + * reference will be written in its place. On failure, it will be
> + * unreferenced and set to NULL.
> + * @param size Required buffer size.
> + *
> + * @return 0 on success, a negative AVERROR on failure.
> + *
> + * @see av_buffer_realloc()
> + * @see av_buffer_fast_allocz()
> + */
> +int av_buffer_fast_alloc(AVBufferRef **buf, int size);
> +
> +/**
> + * Allocate and clear a buffer, reusing the given one if writable and large
> + * enough.
> + *
> + * Like av_buffer_fast_alloc(), but all newly allocated space is initially
> + * cleared. Reused buffer is not cleared.
> + *
> + * @param buf  A buffer reference. *buf may be NULL. On success, a new buffer
> + * reference will be written in its place. On failure, it will be
> + * unreferenced and set to NULL.
> + * @param size Required buffer size.
> + *
> + * @return 0 on success, a negative AVERROR on failure.
> + *
> + * @see av_buffer_fast_alloc()
> + */
> +int av_buffer_fast_allocz(AVBufferRef **buf, int size);
> +
>  /**
>   * @}
>   */

Wouldn't it be better to avoid writing a lot of new allocation code
(with possibly subtle problems), and just use av_buffer_realloc() to
handle reallocation? (Possibly it could be moved to an internal
function to avoid the memcpy() required by realloc.)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3] avcodec: fix atomics usage for h264/mpeg error_count

2018-03-14 Thread wm4
On Tue, 13 Mar 2018 19:07:33 +0100
Michael Niedermayer  wrote:

> On Tue, Mar 13, 2018 at 04:02:57PM +, Aman Gupta wrote:
> > On Tue, Mar 13, 2018 at 4:39 AM Michael Niedermayer 
> > wrote:
> >   
> > > On Mon, Mar 12, 2018 at 06:49:19PM -0700, Aman Gupta wrote:  
> > > > From: Aman Gupta 
> > > >
> > > > ---
> > > >  libavcodec/h264_slice.c|  5 +++--
> > > >  libavcodec/mpeg12dec.c | 12 +++-
> > > >  libavcodec/mpegvideo_enc.c |  3 ++-
> > > >  3 files changed, 12 insertions(+), 8 deletions(-)  
> > >
> > > Iam a little bit confused, you write about "fixing" but not what this is
> > > fixing and it appears there are several distinct types of changes  
> > 
> > 
> > The type of error_count is already atomic_int. I don't know when that was
> > changed.
> > 
> > The fix here is that these files do not compile on FreeBSD because of
> > errors such as:
> > 
> > [2018-03-11 18:26:55.078686] [freebsd-x86_64] libavcodec/mpegvideo_enc.c:
> > In function 'merge_context_after_encode':
> > 
> > [2018-03-11 18:26:55.081607] [freebsd-x86_64]
> > libavcodec/mpegvideo_enc.c:3578:33: error: invalid operands to binary +
> > (have 'atomic_int' and 'atomic_int')
> > 
> > 
> > [2018-03-11 16:43:23.543072] [freebsd-x86_64] CClibavcodec/mpeg12dec.o
> > 
> > [2018-03-11 16:43:23.768864] [freebsd-x86_64] libavcodec/mpeg12dec.c: In
> > function 'slice_decode_thread':
> >   
> 
> > [2018-03-11 16:43:23.769713] [freebsd-x86_64]
> > libavcodec/mpeg12dec.c:1996:23: error: incompatible types when assigning to
> > type 'atomic_int' from type 'int'  
> 
> what compiler is this ?
> 6.5.16.1 Simple assignment
> Constraints
> One of the following shall hold: 114)
> — the left operand has atomic, qualified, or unqualified arithmetic type, 
> and the right has
> arithmetic type;
> 
> Please someone correct me here if iam wrong but
> To me this sounds like doing normal arithmetic operations between atomic and
> non atomic arithmetic types is allowed.

It's true that C11 atomics allow direct access, but we also have
some atomic wrappers that won't work correctly then. I haven't checked
why this one fails, but the gcc compat wrappers use non-atomic types for
the emulation, so this patch is justified and necessary.

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