Re: [FFmpeg-devel] [PATCH] avfilter/af_afir: add AArch64 SIMD for fcmul_add

2020-01-24 Thread Zhao Zhili
Ping for review, thanks!

> On Jan 18, 2020, at 10:35 PM, Zhao Zhili  wrote:
> 
> ./ffmpeg -threads 1 -f lavfi -i anoisesrc -f lavfi -t 30 -i anoisesrc  -t 600 
>  -lavfi afir -benchmark  -f null -
> 
> Test results on Snapdragon 845:
>Without SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=32.2x
>   bench: utime=21.900s stime=1.000s rtime=18.607s
>   bench: maxrss=46708kB
>With SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=46.6x
>   bench: utime=16.150s stime=1.040s rtime=12.867s
>   bench: maxrss=46608kB
> 
> Test results on HiSilicon Kirin 970:
>Without SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=20.7x
>   bench: utime=32.292s stime=1.032s rtime=28.963s
>   bench: maxrss=42412kB
>With SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=27.6x
>   bench: utime=24.964s stime=0.952s rtime=21.703s
>   bench: maxrss=42368kB
> 
> ---
> libavfilter/aarch64/Makefile   |  2 ++
> libavfilter/aarch64/af_afir_init.c | 31 +
> libavfilter/aarch64/af_afir_neon.S | 43 ++
> libavfilter/af_afir.c  |  2 ++
> libavfilter/af_afir.h  |  1 +
> 5 files changed, 79 insertions(+)
> create mode 100644 libavfilter/aarch64/af_afir_init.c
> create mode 100644 libavfilter/aarch64/af_afir_neon.S
> 
> diff --git a/libavfilter/aarch64/Makefile b/libavfilter/aarch64/Makefile
> index b58daa3a3f..f52d7a4842 100644
> --- a/libavfilter/aarch64/Makefile
> +++ b/libavfilter/aarch64/Makefile
> @@ -1,3 +1,5 @@
> +OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/af_afir_init.o
> OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/vf_nlmeans_init.o
> 
> +NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/af_afir_neon.o
> NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/vf_nlmeans_neon.o
> diff --git a/libavfilter/aarch64/af_afir_init.c 
> b/libavfilter/aarch64/af_afir_init.c
> new file mode 100644
> index 00..db06536380
> --- /dev/null
> +++ b/libavfilter/aarch64/af_afir_init.c
> @@ -0,0 +1,31 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "libavutil/aarch64/cpu.h"
> +#include "libavfilter/af_afir.h"
> +
> +void ff_fcmul_add_neon(float *sum, const float *t, const float *c,
> +  ptrdiff_t len);
> +
> +av_cold void ff_afir_init_aarch64(AudioFIRDSPContext *s)
> +{
> +int cpu_flags = av_get_cpu_flags();
> +
> +if (have_neon(cpu_flags))
> +s->fcmul_add = ff_fcmul_add_neon;
> +}
> diff --git a/libavfilter/aarch64/af_afir_neon.S 
> b/libavfilter/aarch64/af_afir_neon.S
> new file mode 100644
> index 00..60583f9591
> --- /dev/null
> +++ b/libavfilter/aarch64/af_afir_neon.S
> @@ -0,0 +1,43 @@
> +/*
> + * Copyright (c) 2020 Zhao Zhili
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "libavutil/aarch64/asm.S"
> +
> +// void ff_fcmul_add_neon(float *sum, const float *t, const float *c, 
> ptrdiff_t len);
> +function ff_fcmul_add_neon, export=1
> +1:
> + ld2 {v0.4S, v1.4S}, [x1], #32   // load t
> + ld2 {v2.4S, v3.4S}, [x2], #32   // load c
> + ld2 {v4.4S, v5.4S}, [x0]// load sum
> + fmlav4.4S, v0.4S, v2.4S
> + fmlsv4.4S, v1.4S, v3.4S
> + fmlav5.4S, v0.4S, v3.4S
> + fmlav5.4S, v1.4S, v2.4S
> + st2 {v4.4S, v5.4S}, [x0], #32   // store sum
> + subsx3, x3, #4
> + b.ne1b
> + ldr   

[FFmpeg-devel] [PATCH] avfilter/af_anlmdn: add AArch64 SIMD for compute_distance_ssd

2020-01-24 Thread Zhao Zhili
./ffmpeg -threads 1  -f lavfi -t 60 -i anoisesrc -af 'anlmdn' -f null 
-benchmark -

Test results on Snapdragon 845:
Before:
size=N/A time=00:01:00.00 bitrate=N/A speed=11.2x
video:0kB audio:5625kB subtitle:0kB other streams:0kB global 
headers:0kB muxing overhead: unknown
bench: utime=5.320s stime=0.010s rtime=5.358s
bench: maxrss=14172kB

After:
size=N/A time=00:01:00.00 bitrate=N/A speed=15.4x
video:0kB audio:5625kB subtitle:0kB other streams:0kB global 
headers:0kB muxing overhead: unknown
bench: utime=3.870s stime=0.000s rtime=3.902s
bench: maxrss=14036kB
---
 libavfilter/aarch64/Makefile |   2 +
 libavfilter/aarch64/af_anlmdn_init.c |  31 
 libavfilter/aarch64/af_anlmdn_neon.S | 112 +++
 libavfilter/af_anlmdn.c  |   3 +
 libavfilter/af_anlmdndsp.h   |   1 +
 5 files changed, 149 insertions(+)
 create mode 100644 libavfilter/aarch64/af_anlmdn_init.c
 create mode 100644 libavfilter/aarch64/af_anlmdn_neon.S

diff --git a/libavfilter/aarch64/Makefile b/libavfilter/aarch64/Makefile
index f52d7a4842..6c727f9859 100644
--- a/libavfilter/aarch64/Makefile
+++ b/libavfilter/aarch64/Makefile
@@ -1,5 +1,7 @@
 OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/af_afir_init.o
+OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/af_anlmdn_init.o
 OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/vf_nlmeans_init.o
 
 NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/af_afir_neon.o
+NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/af_anlmdn_neon.o
 NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/vf_nlmeans_neon.o
diff --git a/libavfilter/aarch64/af_anlmdn_init.c 
b/libavfilter/aarch64/af_anlmdn_init.c
new file mode 100644
index 00..e28a152e04
--- /dev/null
+++ b/libavfilter/aarch64/af_anlmdn_init.c
@@ -0,0 +1,31 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/aarch64/cpu.h"
+#include "libavfilter/af_anlmdndsp.h"
+
+float ff_compute_distance_ssd_neon(const float *f1, const float *f2,
+   ptrdiff_t len);
+
+av_cold void ff_anlmdn_init_aarch64(AudioNLMDNDSPContext *s)
+{
+int cpu_flags = av_get_cpu_flags();
+
+if (have_neon(cpu_flags))
+s->compute_distance_ssd = ff_compute_distance_ssd_neon;
+}
diff --git a/libavfilter/aarch64/af_anlmdn_neon.S 
b/libavfilter/aarch64/af_anlmdn_neon.S
new file mode 100644
index 00..3ad985b476
--- /dev/null
+++ b/libavfilter/aarch64/af_anlmdn_neon.S
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2020 Zhao Zhili
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/aarch64/asm.S"
+
+// float ff_compute_distance_ssd_neon(const float *f1, const float *f2, 
ptrdiff_t len);
+function ff_compute_distance_ssd_neon, export=1
+   fmovs0, wzr
+   add x3, x0, x2, lsl #2  // end of f1
+   sub x0, x0, x2, lsl #2  // begin of f1
+   sub x1, x1, x2, lsl #2  // begin of f2
+   add x3, x3, #4  // end + 1 of f1
+
+   // process 32 pairs of data per loop
+   add x4, x0, #128
+   cmp x4, x3
+   b.gt2f
+1: ld1 {v16.4S, v17.4S, v18.4S, v19.4S}, [x0], #64
+   ld1 {v20.4S, v21.4S, v22.4S, v23.4S}, [x1], #64
+   ld1 {v24.4S, v25.4S, v26.4S, v27.4S}, [x0], #64
+   ld1 {v28.4S, v29.4S, v30.4S, v31.4S}, [x1], #64
+
+   fsubv16.4S, v16.4S, v20.4S
+
+   fs

[FFmpeg-devel] [PATCH 1/5] mlpenc: fix lossless check error in number_sbits

2020-01-24 Thread Jai Luthra
we need two bits instead of one bit to represent -1 in bitstream

Signed-off-by: Jai Luthra 
---
 libavcodec/mlpenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index deb171645c..f4948451f1 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -466,7 +466,7 @@ static void default_decoding_params(MLPEncodeContext *ctx,
  */
 static int inline number_sbits(int number)
 {
-if (number < 0)
+if (number < -1)
 number++;
 
 return av_log2(FFABS(number)) + 1 + !!number;
-- 
2.25.0

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

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

[FFmpeg-devel] [PATCH 3/5] mlpenc: prevent negative lsb_bits lshift

2020-01-24 Thread Jai Luthra
Fixes Coverity CID 1396239.

Signed-off-by: Jai Luthra 
---
 libavcodec/mlpenc.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index 1cee38c82f..41030f6f07 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -1,6 +1,7 @@
 /**
  * MLP encoder
  * Copyright (c) 2008 Ramiro Polla
+ * Copyright (c) 2016-2019 Jai Luthra
  *
  * This file is part of FFmpeg.
  *
@@ -1562,7 +1563,7 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx,
 BestOffset *bo)
 {
 DecodingParams *dp = ctx->cur_decoding_params;
-int32_t unsign;
+int32_t unsign = 0;
 int lsb_bits;
 
 min -= offset;
@@ -1572,7 +1573,8 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx,
 
 lsb_bits += !!lsb_bits;
 
-unsign = 1 << (lsb_bits - 1);
+if (lsb_bits > 0)
+unsign = 1 << (lsb_bits - 1);
 
 bo->offset   = offset;
 bo->lsb_bits = lsb_bits;
@@ -1591,7 +1593,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx,
 {
 DecodingParams *dp = ctx->cur_decoding_params;
 int16_t offset;
-int32_t unsign;
+int32_t unsign = 0;
 uint32_t diff;
 int lsb_bits;
 
@@ -1607,7 +1609,8 @@ static void no_codebook_bits(MLPEncodeContext *ctx,
 
 lsb_bits = number_sbits(diff) - 1;
 
-unsign = 1 << (lsb_bits - 1);
+if (lsb_bits > 0)
+unsign = 1 << (lsb_bits - 1);
 
 /* If all samples are the same (lsb_bits == 0), offset must be
  * adjusted because of sign_shift. */
-- 
2.25.0

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

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

[FFmpeg-devel] [PATCH 4/5] mlpenc: improve lpc filtering

2020-01-24 Thread Jai Luthra
* fix a possible memory leak (apply_filter returned before freeing)
* use apply_filters in process_major_frame
* revert back to checking bounds with 24 bitdepth, as huff offset takes
care of it

Signed-off-by: Jai Luthra 
---
 libavcodec/mlpenc.c | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index 41030f6f07..0e7a9b7640 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -1799,20 +1799,20 @@ static void determine_bits(MLPEncodeContext *ctx)
 
 /** Applies the filter to the current samples, and saves the residual back
  *  into the samples buffer. If the filter is too bad and overflows the
- *  maximum amount of bits allowed (16 or 24), the samples buffer is left as 
is and
+ *  maximum amount of bits allowed (24), the samples buffer is left as is and
  *  the function returns -1.
  */
 static int apply_filter(MLPEncodeContext *ctx, unsigned int channel)
 {
 FilterParams *fp[NUM_FILTERS] = { 
&ctx->cur_channel_params[channel].filter_params[FIR],
   
&ctx->cur_channel_params[channel].filter_params[IIR], };
-int32_t *filter_state_buffer[NUM_FILTERS];
+int32_t *filter_state_buffer[NUM_FILTERS] = { NULL };
 int32_t mask = 
MSB_MASK(ctx->cur_decoding_params->quant_step_size[channel]);
 int32_t *sample_buffer = ctx->sample_buffer + channel;
 unsigned int number_of_samples = ctx->number_of_samples;
 unsigned int filter_shift = fp[FIR]->shift;
 int filter;
-int i;
+int i, ret = 0;
 
 for (i = 0; i < NUM_FILTERS; i++) {
 unsigned int size = ctx->number_of_samples;
@@ -1835,7 +1835,7 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned 
int channel)
 int32_t sample = *sample_buffer;
 unsigned int order;
 int64_t accum = 0;
-int32_t residual;
+int64_t residual;
 
 for (filter = 0; filter < NUM_FILTERS; filter++) {
 int32_t *fcoeff = ctx->cur_channel_params[channel].coeff[filter];
@@ -1847,11 +1847,13 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned 
int channel)
 accum  >>= filter_shift;
 residual = sample - (accum & mask);
 
-if (residual < SAMPLE_MIN(ctx->wordlength) || residual > 
SAMPLE_MAX(ctx->wordlength))
-return -1;
+if (residual < SAMPLE_MIN(24) || residual > SAMPLE_MAX(24)) {
+ret = -1;
+goto free_and_return;
+}
 
 filter_state_buffer[FIR][i] = sample;
-filter_state_buffer[IIR][i] = residual;
+filter_state_buffer[IIR][i] = (int32_t) residual;
 
 sample_buffer += ctx->num_channels;
 }
@@ -1863,11 +1865,12 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned 
int channel)
 sample_buffer += ctx->num_channels;
 }
 
+free_and_return:
 for (i = 0; i < NUM_FILTERS; i++) {
 av_freep(&filter_state_buffer[i]);
 }
 
-return 0;
+return ret;
 }
 
 static void apply_filters(MLPEncodeContext *ctx)
@@ -2198,9 +2201,6 @@ static void process_major_frame(MLPEncodeContext *ctx)
 ctx->number_of_samples = ctx->major_frame_size;
 
 for (substr = 0; substr < ctx->num_substreams; substr++) {
-RestartHeader *rh = ctx->cur_restart_header;
-unsigned int channel;
-
 ctx->cur_restart_header = &ctx->restart_header[substr];
 
 ctx->cur_decoding_params = &ctx->major_decoding_params[1][substr];
@@ -2209,8 +2209,7 @@ static void process_major_frame(MLPEncodeContext *ctx)
 generate_2_noise_channels(ctx);
 rematrix_channels(ctx);
 
-for (channel = rh->min_channel; channel <= rh->max_channel; channel++)
-apply_filter(ctx, channel);
+apply_filters(ctx);
 }
 }
 
-- 
2.25.0

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

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

[FFmpeg-devel] [PATCH 0/5] mlpenc: fix lossless check failures for 16-bit encoding

2020-01-24 Thread Jai Luthra
This patchset fixes lossless check failures for 16-bit mlp/truehd encoding. 
Please check with more samples and let me know if you find any lossless 
failures.

Bug 6216 https://trac.ffmpeg.org/ticket/6216 still cannot be closed as last 
few frames aren't encoded, thus output is not bit-exact.
I will continue on the WIP patch Paul posted earlier and try to fix this.

32-bit encoding still has many lossless failures, so keeping it disabled for 
now. Will work on it later.

Jai Luthra (5):
  mlpenc: fix lossless check error in number_sbits
  mlpenc: fix huff offset calculation
  mlpenc: prevent negative lsb_bits lshift
  mlpenc: improve lpc filtering
  mlpenc: clean up

 libavcodec/mlpenc.c | 74 +
 1 file changed, 35 insertions(+), 39 deletions(-)

-- 
2.25.0

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

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

[FFmpeg-devel] [PATCH] avfilter: add xfade opencl filter

2020-01-24 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 configure |   1 +
 doc/filters.texi  |  97 
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/opencl/xfade.cl   | 150 
 libavfilter/opencl_source.h   |   1 +
 libavfilter/vf_xfade_opencl.c | 427 ++
 7 files changed, 678 insertions(+)
 create mode 100644 libavfilter/opencl/xfade.cl
 create mode 100644 libavfilter/vf_xfade_opencl.c

diff --git a/configure b/configure
index 1f3d0fdd4b..7da9f486b8 100755
--- a/configure
+++ b/configure
@@ -3595,6 +3595,7 @@ zscale_filter_deps="libzimg const_nan"
 scale_vaapi_filter_deps="vaapi"
 vpp_qsv_filter_deps="libmfx"
 vpp_qsv_filter_select="qsvvpp"
+xfade_opencl_filter_deps="opencl"
 yadif_cuda_filter_deps="ffnvcodec"
 yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
 
diff --git a/doc/filters.texi b/doc/filters.texi
index a9ae75f0c0..1b787c51d7 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -21341,6 +21341,103 @@ Apply a strong blur of both luma and chroma 
parameters:
 @end example
 @end itemize
 
+@section xfade_opencl
+
+Cross fade two videos with custom transition effect by using OpenCL.
+
+It accepts the following options:
+
+@table @option
+@item transition
+Set one of possible transition effects.
+
+@table @option
+@item custom
+Select custom transition effect, the actual transition description
+will be picked from source and kernel options.
+
+@item fade
+@item wipeleft
+@item wiperight
+@item wipeup
+@item wipedown
+@item slideleft
+@item slideright
+@item slideup
+@item slidedown
+
+Default transtition is fade.
+@end table
+
+@item source
+OpenCL program source file for custom transition.
+
+@item kernel
+Set name of kernel to use for custom transition from program source file.
+
+@item duration
+Set duration of video transition.
+
+@item offset
+Set time of start of transition relative to first video.
+@end table
+
+The program source file must contain a kernel function with the given name,
+which will be run once for each plane of the output.  Each run on a plane
+gets enqueued as a separate 2D global NDRange with one work-item for each
+pixel to be generated.  The global ID offset for each work-item is therefore
+the coordinates of a pixel in the destination image.
+
+The kernel function needs to take the following arguments:
+@itemize
+@item
+Destination image, @var{__write_only image2d_t}.
+
+This image will become the output; the kernel should write all of it.
+
+@item
+First Source image, @var{__read_only image2d_t}.
+Second Source image, @var{__read_only image2d_t}.
+
+These are the most recent images on each input.  The kernel may read from
+them to generate the output, but they can't be written to.
+
+@item
+Transition progress, @var{float}. This value is always between 0 and 1 
inclusive.
+@end itemize
+
+Example programs:
+
+@itemize
+@item
+Apply dots curtain transition effect:
+@verbatim
+__kernel void blend_images(__write_only image2d_t dst,
+   __read_only  image2d_t src1,
+   __read_only  image2d_t src2,
+   float progress)
+{
+const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
+   CLK_FILTER_LINEAR);
+int2  p = (int2)(get_global_id(0), get_global_id(1));
+float2 rp = (float2)(get_global_id(0), get_global_id(1));
+float2 dim = (float2)(get_image_dim(src1).x, get_image_dim(src1).y);
+rp = rp / dim;
+
+float2 dots = (float2)(20.0, 20.0);
+float2 center = (float2)(0,0);
+float2 unused;
+
+float4 val1 = read_imagef(src1, sampler, p);
+float4 val2 = read_imagef(src2, sampler, p);
+bool next = distance(fract(rp * dots, &unused), (float2)(0.5, 0.5)) < 
(progress / distance(rp, center));
+
+write_imagef(dst, p, next ? val1 : val2);
+}
+@end verbatim
+
+@end itemize
+
 @c man end OPENCL VIDEO FILTERS
 
 @chapter VAAPI Video Filters
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 58b3077dec..a5ee9c8e88 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -441,6 +441,7 @@ OBJS-$(CONFIG_W3FDIF_FILTER) += vf_w3fdif.o
 OBJS-$(CONFIG_WAVEFORM_FILTER)   += vf_waveform.o
 OBJS-$(CONFIG_WEAVE_FILTER)  += vf_weave.o
 OBJS-$(CONFIG_XBR_FILTER)+= vf_xbr.o
+OBJS-$(CONFIG_XFADE_OPENCL_FILTER)   += vf_xfade_opencl.o opencl.o 
opencl/xfade.o
 OBJS-$(CONFIG_XMEDIAN_FILTER)+= vf_xmedian.o framesync.o
 OBJS-$(CONFIG_XSTACK_FILTER) += vf_stack.o framesync.o
 OBJS-$(CONFIG_YADIF_FILTER)  += vf_yadif.o yadif_common.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 6270c18ae2..8a7eac3757 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -420,6 +420,7 @@ extern AVFilter ff_vf_w3fdif;
 extern AVFilter ff_vf_waveform;
 extern AVFilter ff_vf_weave;
 extern AVFilter ff_vf_xbr

Re: [FFmpeg-devel] [PATCH] avfilter/af_afir: add AArch64 SIMD for fcmul_add

2020-01-24 Thread Paul B Mahol
Seems very trivial.

On 1/18/20, Zhao Zhili  wrote:
> ./ffmpeg -threads 1 -f lavfi -i anoisesrc -f lavfi -t 30 -i anoisesrc  -t
> 600  -lavfi afir -benchmark  -f null -
>
> Test results on Snapdragon 845:
> Without SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=32.2x
>   bench: utime=21.900s stime=1.000s rtime=18.607s
>   bench: maxrss=46708kB
> With SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=46.6x
>   bench: utime=16.150s stime=1.040s rtime=12.867s
>   bench: maxrss=46608kB
>
> Test results on HiSilicon Kirin 970:
> Without SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=20.7x
>   bench: utime=32.292s stime=1.032s rtime=28.963s
>   bench: maxrss=42412kB
> With SIMD:
>   size=N/A time=00:10:00.00 bitrate=N/A speed=27.6x
>   bench: utime=24.964s stime=0.952s rtime=21.703s
>   bench: maxrss=42368kB
>
> ---
>  libavfilter/aarch64/Makefile   |  2 ++
>  libavfilter/aarch64/af_afir_init.c | 31 +
>  libavfilter/aarch64/af_afir_neon.S | 43 ++
>  libavfilter/af_afir.c  |  2 ++
>  libavfilter/af_afir.h  |  1 +
>  5 files changed, 79 insertions(+)
>  create mode 100644 libavfilter/aarch64/af_afir_init.c
>  create mode 100644 libavfilter/aarch64/af_afir_neon.S
>
> diff --git a/libavfilter/aarch64/Makefile b/libavfilter/aarch64/Makefile
> index b58daa3a3f..f52d7a4842 100644
> --- a/libavfilter/aarch64/Makefile
> +++ b/libavfilter/aarch64/Makefile
> @@ -1,3 +1,5 @@
> +OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/af_afir_init.o
>  OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/vf_nlmeans_init.o
>
> +NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/af_afir_neon.o
>  NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/vf_nlmeans_neon.o
> diff --git a/libavfilter/aarch64/af_afir_init.c
> b/libavfilter/aarch64/af_afir_init.c
> new file mode 100644
> index 00..db06536380
> --- /dev/null
> +++ b/libavfilter/aarch64/af_afir_init.c
> @@ -0,0 +1,31 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +#include "libavutil/aarch64/cpu.h"
> +#include "libavfilter/af_afir.h"
> +
> +void ff_fcmul_add_neon(float *sum, const float *t, const float *c,
> +  ptrdiff_t len);
> +
> +av_cold void ff_afir_init_aarch64(AudioFIRDSPContext *s)
> +{
> +int cpu_flags = av_get_cpu_flags();
> +
> +if (have_neon(cpu_flags))
> +s->fcmul_add = ff_fcmul_add_neon;
> +}
> diff --git a/libavfilter/aarch64/af_afir_neon.S
> b/libavfilter/aarch64/af_afir_neon.S
> new file mode 100644
> index 00..60583f9591
> --- /dev/null
> +++ b/libavfilter/aarch64/af_afir_neon.S
> @@ -0,0 +1,43 @@
> +/*
> + * Copyright (c) 2020 Zhao Zhili
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +#include "libavutil/aarch64/asm.S"
> +
> +// void ff_fcmul_add_neon(float *sum, const float *t, const float *c,
> ptrdiff_t len);
> +function ff_fcmul_add_neon, export=1
> +1:
> + ld2 {v0.4S, v1.4S}, [x1], #32   // load t
> + ld2 {v2.4S, v3.4S}, [x2], #32   // load c
> + ld2 {v4.4S, v5.4S}, [x0]// load sum
> + fmlav4.4S, v0.4S, v2.4S
> + fmlsv4.4S, v1.4S, v3.4S
> + fmlav5.4S, v0.4S, v3.4S
> + fmlav5.4S, v1.4S, v2.4S
> + st2 {v4.4S, v5.4S}, [x0], #32   // store sum
> + subsx3, x3, #4
> + b.ne1b
> + ldr s0, [x1]// load

[FFmpeg-devel] [PATCH 2/5] mlpenc: fix huff offset calculation

2020-01-24 Thread Jai Luthra
huff offset wasn't always within the bounds before, which lead to
corrupt encoding that didn't always trigger lossless check failures

Signed-off-by: Jai Luthra 
---
 libavcodec/mlpenc.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index f4948451f1..1cee38c82f 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -1699,7 +1699,7 @@ static inline void codebook_bits(MLPEncodeContext *ctx,
 offset_min = FFMAX(min, HUFF_OFFSET_MIN);
 offset_max = FFMIN(max, HUFF_OFFSET_MAX);
 
-for (;;) {
+while (offset <= offset_max && offset >= offset_min) {
 BestOffset temp_bo;
 
 codebook_bits_offset(ctx, channel, codebook,
@@ -1718,12 +1718,8 @@ static inline void codebook_bits(MLPEncodeContext *ctx,
 
 if (direction) {
 offset = temp_bo.max + 1;
-if (offset > offset_max)
-break;
 } else {
 offset = temp_bo.min - 1;
-if (offset < offset_min)
-break;
 }
 }
 }
-- 
2.25.0

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

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

[FFmpeg-devel] [PATCH 5/5] mlpenc: clean up

2020-01-24 Thread Jai Luthra
Signed-off-by: Jai Luthra 
---
 libavcodec/mlpenc.c | 30 ++
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index 0e7a9b7640..40872c42fa 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -94,8 +94,8 @@ typedef struct BestOffset {
 int16_t max;
 } BestOffset;
 
-#define HUFF_OFFSET_MIN-16384
-#define HUFF_OFFSET_MAX 16383
+#define HUFF_OFFSET_MIN(-16384)
+#define HUFF_OFFSET_MAX( 16383)
 
 /** Number of possible codebooks (counting "no codebooks") */
 #define NUM_CODEBOOKS   4
@@ -808,7 +808,7 @@ static void write_major_sync(MLPEncodeContext *ctx, uint8_t 
*buf, int buf_size)
 static void write_restart_header(MLPEncodeContext *ctx, PutBitContext *pb)
 {
 RestartHeader *rh = ctx->cur_restart_header;
-int32_t lossless_check = xor_32_to_8(rh->lossless_check_data);
+uint8_t lossless_check = xor_32_to_8(rh->lossless_check_data);
 unsigned int start_count = put_bits_count(pb);
 PutBitContext tmpb;
 uint8_t checksum;
@@ -1017,12 +1017,10 @@ static void write_block_data(MLPEncodeContext *ctx, 
PutBitContext *pb)
 codebook_index  [ch] = cp->codebook  - 1;
 sign_huff_offset[ch] = cp->huff_offset;
 
-sign_shift = lsb_bits[ch] - 1;
+sign_shift = lsb_bits[ch] + (cp->codebook ? 2 - cp->codebook : -1);
 
-if (cp->codebook > 0) {
+if (cp->codebook > 0)
 sign_huff_offset[ch] -= 7 << lsb_bits[ch];
-sign_shift += 3 - cp->codebook;
-}
 
 /* Unsign if needed. */
 if (sign_shift >= 0)
@@ -1032,7 +1030,6 @@ static void write_block_data(MLPEncodeContext *ctx, 
PutBitContext *pb)
 for (i = 0; i < dp->blocksize; i++) {
 for (ch = rh->min_channel; ch <= rh->max_channel; ch++) {
 int32_t sample = *sample_buffer++ >> dp->quant_step_size[ch];
-
 sample -= sign_huff_offset[ch];
 
 if (codebook_index[ch] >= 0) {
@@ -1252,7 +1249,7 @@ static void input_data_internal(MLPEncodeContext *ctx, 
const uint8_t *samples,
 uint32_t abs_sample;
 int32_t sample;
 
-sample = is24 ? *samples_32++ >> 8 : *samples_16++ << 8;
+sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256U;
 
 /* TODO Find out if number_sbits can be used for negative 
values. */
 abs_sample = FFABS(sample);
@@ -1795,7 +1792,7 @@ static void determine_bits(MLPEncodeContext *ctx)
 #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1)
 #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth))
 
-#define MSB_MASK(bits)  (-1u << bits)
+#define MSB_MASK(bits)  (-(1u << (bits)))
 
 /** Applies the filter to the current samples, and saves the residual back
  *  into the samples buffer. If the filter is too bad and overflows the
@@ -1899,8 +1896,8 @@ static void generate_2_noise_channels(MLPEncodeContext 
*ctx)
 
 for (i = 0; i < ctx->number_of_samples; i++) {
 uint16_t seed_shr7 = seed >> 7;
-*sample_buffer++ = ((int8_t)(seed >> 15)) << rh->noise_shift;
-*sample_buffer++ = ((int8_t) seed_shr7)   << rh->noise_shift;
+*sample_buffer++ = ((int8_t)(seed >> 15)) * (1 << rh->noise_shift);
+*sample_buffer++ = ((int8_t) seed_shr7)   * (1 << rh->noise_shift);
 
 seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
 
@@ -2071,9 +2068,10 @@ static void set_best_codebook(MLPEncodeContext *ctx)
 best_codebook = *best_path++ - ZERO_PATH;
 cur_bo = &ctx->best_offset[index][channel][best_codebook];
 
-cp->huff_offset = cur_bo->offset;
-cp->huff_lsbs   = cur_bo->lsb_bits + dp->quant_step_size[channel];
-cp->codebook= best_codebook;
+cp->huff_offset  = cur_bo->offset;
+cp->sign_huff_offset = -(1 << 23);
+cp->huff_lsbs= cur_bo->lsb_bits + 
dp->quant_step_size[channel];
+cp->codebook = best_codebook;
 }
 }
 }
@@ -2275,7 +2273,7 @@ static int mlp_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 if (restart_frame) {
 set_major_params(ctx);
 if (ctx->min_restart_interval != ctx->max_restart_interval)
-process_major_frame(ctx);
+process_major_frame(ctx);
 }
 
 if (ctx->min_restart_interval == ctx->max_restart_interval)
-- 
2.25.0

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

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

Re: [FFmpeg-devel] [PATCH 1/2] avutil/log: Add av_log_once() for printing a message just once per instance

2020-01-24 Thread Michael Niedermayer
On Tue, Jan 21, 2020 at 07:44:46PM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2020-01-21 15:43:48)
> > On Tue, Jan 21, 2020 at 12:24:50PM +0100, Anton Khirnov wrote:
> > > Quoting Michael Niedermayer (2020-01-16 17:51:28)
> > > > Compared to ad-hoc if(printed) ... code this allows the user to disable
> > > > it with a flag and see all repeated messages, it is also simpler
> > > 
> > > That flag is global state - it should be deprecated and removed, not
> > > embedded further into the API.
> > 
> > When the flag is replaced by a non global solution every of its uses
> > would be replaced too.
> > 
> > Until such a non global API exists, this is the only way the user can
> > indicate her choice of which log messages to print.
> > Code should honor the existing API and user preferrance.
> 
> The problem is that right now, flags is only used by the default log
> callback. The behaviour of the default log callback is not specified by
> the API, so it can be changed later without much trouble. With this
> patch, the function of flags is hardcoded into the API, making its
> future removal significantly harder.

I dont really see this concern. Because if you disable the flag "today"
you break the API as it is documented, the flag is documented to
affect the message repeation.
With this patch, disabling it still breaks a bunch of message repeating
behavior, so to me this looks like its basically the same.

But what do you suggest ?

We could send all the repeated _once() messages to the callback and leave it
to the callback to drop them. Just needs a way to tag them as repeats

We could move the (no)repeat flag to each context but this feels unwieldy
and feels like it solves a problem noone had. Because noone ever asked
AFAIR that they wanted to change repeating behavior on a per context base.
This is probably mostly used by developers wanting to check for "all"
messages. Or users produding bug reports which also would ideally have
no dropped messages.

I can also just drop the use of the flag entirely from the patch and just
leave this as a unconditional _once() log. It feels a bit like a missing
feature though because as a devleoper for debuging a simple switch to
see all repeats seems usefull.

Thanks


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

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides


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

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

[FFmpeg-devel] [PATCH 2/2] avcodec/dnxhdenc: properly store colorspace info

2020-01-24 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/dnxhdenc.c | 10 +-
 libavcodec/dnxhdenc.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 2feb8baf21..c1b493a604 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -406,6 +406,14 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
 }
 
 ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444;
+
+switch (avctx->colorspace) {
+case AVCOL_SPC_BT709:  ctx->colorspace = 0; break;
+case AVCOL_SPC_BT2020_NCL: ctx->colorspace = 1; break;
+case AVCOL_SPC_BT2020_CL:  ctx->colorspace = 2; break;
+default:   ctx->colorspace = 3; break;
+}
+
 avctx->profile = ctx->profile;
 ctx->cid = ff_dnxhd_find_cid(avctx, ctx->bit_depth);
 if (!ctx->cid) {
@@ -576,7 +584,7 @@ static int dnxhd_write_header(AVCodecContext *avctx, 
uint8_t *buf)
 buf[0x21] = ctx->bit_depth == 10 ? 0x58 : 0x38;
 buf[0x22] = 0x88 + (ctx->interlaced << 2);
 AV_WB32(buf + 0x28, ctx->cid); // CID
-buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | (avctx->pix_fmt 
== AV_PIX_FMT_YUV444P10);
+buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | 
(ctx->colorspace << 1) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
 
 buf[0x5f] = 0x01; // UDL
 
diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h
index 7b0d862e28..4d5f457e33 100644
--- a/libavcodec/dnxhdenc.h
+++ b/libavcodec/dnxhdenc.h
@@ -50,6 +50,7 @@ typedef struct DNXHDEncContext {
 int profile;
 int bit_depth;
 int is_444;
+int colorspace;
 const CIDEntry *cid_table;
 uint8_t *msip; ///< Macroblock Scan Indexes Payload
 uint32_t *slice_size;
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 1/2] avcodec/dnxhddec: properly set colorspace

2020-01-24 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/dnxhddec.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 1e95086696..2ec004333f 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -235,7 +235,14 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame 
*frame,
 av_log(ctx->avctx, AV_LOG_WARNING,
"Adaptive MB interlace flag in an unsupported profile.\n");
 
-ctx->act = buf[0x2C] & 7;
+switch ((buf[0x2C] >> 1) & 3) {
+case 0: frame->colorspace = AVCOL_SPC_BT709;   break;
+case 1: frame->colorspace = AVCOL_SPC_BT2020_NCL;  break;
+case 2: frame->colorspace = AVCOL_SPC_BT2020_CL;   break;
+case 3: frame->colorspace = AVCOL_SPC_UNSPECIFIED; break;
+}
+
+ctx->act = buf[0x2C] & 1;
 if (ctx->act && ctx->cid_table->cid != 1256 && ctx->cid_table->cid != 1270)
 av_log(ctx->avctx, AV_LOG_WARNING,
"Adaptive color transform in an unsupported profile.\n");
-- 
2.17.1

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

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

Re: [FFmpeg-devel] [PATCH 5/5] mlpenc: clean up

2020-01-24 Thread Paul B Mahol
On 1/24/20, Jai Luthra  wrote:
> Signed-off-by: Jai Luthra 
> ---
>  libavcodec/mlpenc.c | 30 ++
>  1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
> index 0e7a9b7640..40872c42fa 100644
> --- a/libavcodec/mlpenc.c
> +++ b/libavcodec/mlpenc.c
> @@ -94,8 +94,8 @@ typedef struct BestOffset {
>  int16_t max;
>  } BestOffset;
>
> -#define HUFF_OFFSET_MIN-16384
> -#define HUFF_OFFSET_MAX 16383
> +#define HUFF_OFFSET_MIN(-16384)
> +#define HUFF_OFFSET_MAX( 16383)
>
>  /** Number of possible codebooks (counting "no codebooks") */
>  #define NUM_CODEBOOKS   4
> @@ -808,7 +808,7 @@ static void write_major_sync(MLPEncodeContext *ctx,
> uint8_t *buf, int buf_size)
>  static void write_restart_header(MLPEncodeContext *ctx, PutBitContext *pb)
>  {
>  RestartHeader *rh = ctx->cur_restart_header;
> -int32_t lossless_check = xor_32_to_8(rh->lossless_check_data);
> +uint8_t lossless_check = xor_32_to_8(rh->lossless_check_data);
>  unsigned int start_count = put_bits_count(pb);
>  PutBitContext tmpb;
>  uint8_t checksum;
> @@ -1017,12 +1017,10 @@ static void write_block_data(MLPEncodeContext *ctx,
> PutBitContext *pb)
>  codebook_index  [ch] = cp->codebook  - 1;
>  sign_huff_offset[ch] = cp->huff_offset;
>
> -sign_shift = lsb_bits[ch] - 1;
> +sign_shift = lsb_bits[ch] + (cp->codebook ? 2 - cp->codebook : -1);
>
> -if (cp->codebook > 0) {
> +if (cp->codebook > 0)
>  sign_huff_offset[ch] -= 7 << lsb_bits[ch];
> -sign_shift += 3 - cp->codebook;
> -}
>
>  /* Unsign if needed. */
>  if (sign_shift >= 0)
> @@ -1032,7 +1030,6 @@ static void write_block_data(MLPEncodeContext *ctx,
> PutBitContext *pb)
>  for (i = 0; i < dp->blocksize; i++) {
>  for (ch = rh->min_channel; ch <= rh->max_channel; ch++) {
>  int32_t sample = *sample_buffer++ >> dp->quant_step_size[ch];
> -
>  sample -= sign_huff_offset[ch];
>
>  if (codebook_index[ch] >= 0) {
> @@ -1252,7 +1249,7 @@ static void input_data_internal(MLPEncodeContext *ctx,
> const uint8_t *samples,
>  uint32_t abs_sample;
>  int32_t sample;
>
> -sample = is24 ? *samples_32++ >> 8 : *samples_16++ << 8;
> +sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256U;
>
>  /* TODO Find out if number_sbits can be used for negative
> values. */
>  abs_sample = FFABS(sample);
> @@ -1795,7 +1792,7 @@ static void determine_bits(MLPEncodeContext *ctx)
>  #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1)
>  #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth))
>
> -#define MSB_MASK(bits)  (-1u << bits)
> +#define MSB_MASK(bits)  (-(1u << (bits)))
>
>  /** Applies the filter to the current samples, and saves the residual back
>   *  into the samples buffer. If the filter is too bad and overflows the
> @@ -1899,8 +1896,8 @@ static void generate_2_noise_channels(MLPEncodeContext
> *ctx)
>
>  for (i = 0; i < ctx->number_of_samples; i++) {
>  uint16_t seed_shr7 = seed >> 7;
> -*sample_buffer++ = ((int8_t)(seed >> 15)) << rh->noise_shift;
> -*sample_buffer++ = ((int8_t) seed_shr7)   << rh->noise_shift;
> +*sample_buffer++ = ((int8_t)(seed >> 15)) * (1 << rh->noise_shift);
> +*sample_buffer++ = ((int8_t) seed_shr7)   * (1 << rh->noise_shift);
>
>  seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
>
> @@ -2071,9 +2068,10 @@ static void set_best_codebook(MLPEncodeContext *ctx)
>  best_codebook = *best_path++ - ZERO_PATH;
>  cur_bo = &ctx->best_offset[index][channel][best_codebook];
>
> -cp->huff_offset = cur_bo->offset;
> -cp->huff_lsbs   = cur_bo->lsb_bits +
> dp->quant_step_size[channel];
> -cp->codebook= best_codebook;
> +cp->huff_offset  = cur_bo->offset;
> +cp->sign_huff_offset = -(1 << 23);

This is not cleanup, this adds new line of code without proper explanation.

> +cp->huff_lsbs= cur_bo->lsb_bits +
> dp->quant_step_size[channel];
> +cp->codebook = best_codebook;
>  }
>  }
>  }
> @@ -2275,7 +2273,7 @@ static int mlp_encode_frame(AVCodecContext *avctx,
> AVPacket *avpkt,
>  if (restart_frame) {
>  set_major_params(ctx);
>  if (ctx->min_restart_interval != ctx->max_restart_interval)
> -process_major_frame(ctx);
> +process_major_frame(ctx);
>  }
>
>  if (ctx->min_restart_interval == ctx->max_restart_interval)
> --
> 2.25.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Fix potential double-free when adding unit fails

2020-01-24 Thread Andreas Rheinhardt
On Mon, Nov 18, 2019 at 8:48 AM Andreas Rheinhardt <
andreas.rheinha...@gmail.com> wrote:

> ff_cbs_insert_unit_data() has two modes of operation: It can insert a
> unit with a newly created reference to an already existing AVBuffer; or
> it can take a buffer and create an AVBuffer for it. Said buffer will
> then become owned by the unit lateron.
>
> A potential memleak/double-free exists in the second case, because if
> creating the AVBuffer fails, the function immediately returns, but when
> it fails lateron, the supplied buffer will be freed. The caller has no
> way to distinguish between these two outcomes. The only such caller
> (cbs_jpeg_split_fragment() in cbs_jpeg.c) opted for a potential
> double-free.
>
> This commit changes this by explicitly stating that a non-refcounted
> buffer will be freed on error. The aforementioned caller has been
> brought in line with this.
>
> Fixes CID 1452623.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
> Actually CID 1452623 is a false positive: Coverity thinks that the
> frsgment's data buffer is NULL, which it never is (or we wouldn't be
> here).
>
>  libavcodec/cbs.c  | 5 -
>  libavcodec/cbs.h  | 3 ++-
>  libavcodec/cbs_jpeg.c | 5 +
>  3 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
> index 0badb192d9..0bd5e1ac5d 100644
> --- a/libavcodec/cbs.c
> +++ b/libavcodec/cbs.c
> @@ -775,8 +775,11 @@ int ff_cbs_insert_unit_data(CodedBitstreamContext
> *ctx,
>  data_ref = av_buffer_ref(data_buf);
>  else
>  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
> -if (!data_ref)
> +if (!data_ref) {
> +if (!data_buf)
> +av_free(data);
>  return AVERROR(ENOMEM);
> +}
>
>  err = cbs_insert_unit(ctx, frag, position);
>  if (err < 0) {
> diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
> index cdb777d111..9ca1fbd609 100644
> --- a/libavcodec/cbs.h
> +++ b/libavcodec/cbs.h
> @@ -376,7 +376,8 @@ int ff_cbs_insert_unit_content(CodedBitstreamContext
> *ctx,
>   * Insert a new unit into a fragment with the given data bitstream.
>   *
>   * If data_buf is not supplied then data must have been allocated with
> - * av_malloc() and will become owned by the unit after this call.
> + * av_malloc() and will on success become owned by the unit after this
> + * call or freed on error.
>   */
>  int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx,
>  CodedBitstreamFragment *frag,
> diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
> index b189cbd9b7..b52e5c5823 100644
> --- a/libavcodec/cbs_jpeg.c
> +++ b/libavcodec/cbs_jpeg.c
> @@ -225,11 +225,8 @@ static int
> cbs_jpeg_split_fragment(CodedBitstreamContext *ctx,
>
>  err = ff_cbs_insert_unit_data(ctx, frag, unit, marker,
>data, data_size, data_ref);
> -if (err < 0) {
> -if (!data_ref)
> -av_freep(&data);
> +if (err < 0)
>  return err;
> -}
>
>  if (next_marker == -1)
>  break;
> --
>

Ping.

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

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

[FFmpeg-devel] [PATCH 2/2] avcodec/dnxhdenc: properly store colorspace info

2020-01-24 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/dnxhdenc.c | 11 ++-
 libavcodec/dnxhdenc.h |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 2feb8baf21..03835fa794 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -406,6 +406,15 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
 }
 
 ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444;
+
+switch (avctx->colorspace) {
+case AVCOL_SPC_UNSPECIFIED:
+case AVCOL_SPC_BT709:  ctx->colorspace = 0; break;
+case AVCOL_SPC_BT2020_NCL: ctx->colorspace = 1; break;
+case AVCOL_SPC_BT2020_CL:  ctx->colorspace = 2; break;
+default:   ctx->colorspace = 3; break;
+}
+
 avctx->profile = ctx->profile;
 ctx->cid = ff_dnxhd_find_cid(avctx, ctx->bit_depth);
 if (!ctx->cid) {
@@ -576,7 +585,7 @@ static int dnxhd_write_header(AVCodecContext *avctx, 
uint8_t *buf)
 buf[0x21] = ctx->bit_depth == 10 ? 0x58 : 0x38;
 buf[0x22] = 0x88 + (ctx->interlaced << 2);
 AV_WB32(buf + 0x28, ctx->cid); // CID
-buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | (avctx->pix_fmt 
== AV_PIX_FMT_YUV444P10);
+buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | 
(ctx->colorspace << 1) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
 
 buf[0x5f] = 0x01; // UDL
 
diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h
index 7b0d862e28..4d5f457e33 100644
--- a/libavcodec/dnxhdenc.h
+++ b/libavcodec/dnxhdenc.h
@@ -50,6 +50,7 @@ typedef struct DNXHDEncContext {
 int profile;
 int bit_depth;
 int is_444;
+int colorspace;
 const CIDEntry *cid_table;
 uint8_t *msip; ///< Macroblock Scan Indexes Payload
 uint32_t *slice_size;
-- 
2.17.1

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

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/dnxhdenc: properly store colorspace info

2020-01-24 Thread James Almer
On 1/24/2020 11:14 AM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/dnxhdenc.c | 11 ++-
>  libavcodec/dnxhdenc.h |  1 +
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
> index 2feb8baf21..03835fa794 100644
> --- a/libavcodec/dnxhdenc.c
> +++ b/libavcodec/dnxhdenc.c
> @@ -406,6 +406,15 @@ static av_cold int dnxhd_encode_init(AVCodecContext 
> *avctx)
>  }
>  
>  ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444;
> +
> +switch (avctx->colorspace) {
> +case AVCOL_SPC_UNSPECIFIED:

Isn't 3 meant to be unspecified? If not, what is it for?

> +case AVCOL_SPC_BT709:  ctx->colorspace = 0; break;
> +case AVCOL_SPC_BT2020_NCL: ctx->colorspace = 1; break;
> +case AVCOL_SPC_BT2020_CL:  ctx->colorspace = 2; break;
> +default:   ctx->colorspace = 3; break;
> +}
> +
>  avctx->profile = ctx->profile;
>  ctx->cid = ff_dnxhd_find_cid(avctx, ctx->bit_depth);
>  if (!ctx->cid) {
> @@ -576,7 +585,7 @@ static int dnxhd_write_header(AVCodecContext *avctx, 
> uint8_t *buf)
>  buf[0x21] = ctx->bit_depth == 10 ? 0x58 : 0x38;
>  buf[0x22] = 0x88 + (ctx->interlaced << 2);
>  AV_WB32(buf + 0x28, ctx->cid); // CID
> -buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | 
> (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
> +buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | 
> (ctx->colorspace << 1) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
>  
>  buf[0x5f] = 0x01; // UDL
>  
> diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h
> index 7b0d862e28..4d5f457e33 100644
> --- a/libavcodec/dnxhdenc.h
> +++ b/libavcodec/dnxhdenc.h
> @@ -50,6 +50,7 @@ typedef struct DNXHDEncContext {
>  int profile;
>  int bit_depth;
>  int is_444;
> +int colorspace;
>  const CIDEntry *cid_table;
>  uint8_t *msip; ///< Macroblock Scan Indexes Payload
>  uint32_t *slice_size;
> 

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

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/dnxhdenc: properly store colorspace info

2020-01-24 Thread Paul B Mahol
On 1/24/20, James Almer  wrote:
> On 1/24/2020 11:14 AM, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavcodec/dnxhdenc.c | 11 ++-
>>  libavcodec/dnxhdenc.h |  1 +
>>  2 files changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
>> index 2feb8baf21..03835fa794 100644
>> --- a/libavcodec/dnxhdenc.c
>> +++ b/libavcodec/dnxhdenc.c
>> @@ -406,6 +406,15 @@ static av_cold int dnxhd_encode_init(AVCodecContext
>> *avctx)
>>  }
>>
>>  ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444;
>> +
>> +switch (avctx->colorspace) {
>> +case AVCOL_SPC_UNSPECIFIED:
>
> Isn't 3 meant to be unspecified? If not, what is it for?

This is to keep old behavior same. Where encoder would store
unspecified as bt709.
Mainly to not need to modify fate tests.

>
>> +case AVCOL_SPC_BT709:  ctx->colorspace = 0; break;
>> +case AVCOL_SPC_BT2020_NCL: ctx->colorspace = 1; break;
>> +case AVCOL_SPC_BT2020_CL:  ctx->colorspace = 2; break;
>> +default:   ctx->colorspace = 3; break;
>> +}
>> +
>>  avctx->profile = ctx->profile;
>>  ctx->cid = ff_dnxhd_find_cid(avctx, ctx->bit_depth);
>>  if (!ctx->cid) {
>> @@ -576,7 +585,7 @@ static int dnxhd_write_header(AVCodecContext *avctx,
>> uint8_t *buf)
>>  buf[0x21] = ctx->bit_depth == 10 ? 0x58 : 0x38;
>>  buf[0x22] = 0x88 + (ctx->interlaced << 2);
>>  AV_WB32(buf + 0x28, ctx->cid); // CID
>> -buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) |
>> (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
>> +buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) |
>> (ctx->colorspace << 1) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
>>
>>  buf[0x5f] = 0x01; // UDL
>>
>> diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h
>> index 7b0d862e28..4d5f457e33 100644
>> --- a/libavcodec/dnxhdenc.h
>> +++ b/libavcodec/dnxhdenc.h
>> @@ -50,6 +50,7 @@ typedef struct DNXHDEncContext {
>>  int profile;
>>  int bit_depth;
>>  int is_444;
>> +int colorspace;
>>  const CIDEntry *cid_table;
>>  uint8_t *msip; ///< Macroblock Scan Indexes Payload
>>  uint32_t *slice_size;
>>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/dnxhdenc: properly store colorspace info

2020-01-24 Thread James Almer
On 1/24/2020 12:59 PM, Paul B Mahol wrote:
> On 1/24/20, James Almer  wrote:
>> On 1/24/2020 11:14 AM, Paul B Mahol wrote:
>>> Signed-off-by: Paul B Mahol 
>>> ---
>>>  libavcodec/dnxhdenc.c | 11 ++-
>>>  libavcodec/dnxhdenc.h |  1 +
>>>  2 files changed, 11 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
>>> index 2feb8baf21..03835fa794 100644
>>> --- a/libavcodec/dnxhdenc.c
>>> +++ b/libavcodec/dnxhdenc.c
>>> @@ -406,6 +406,15 @@ static av_cold int dnxhd_encode_init(AVCodecContext
>>> *avctx)
>>>  }
>>>
>>>  ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444;
>>> +
>>> +switch (avctx->colorspace) {
>>> +case AVCOL_SPC_UNSPECIFIED:
>>
>> Isn't 3 meant to be unspecified? If not, what is it for?
> 
> This is to keep old behavior same. Where encoder would store
> unspecified as bt709.
> Mainly to not need to modify fate tests.

The proper thing to do is adapt the tests to the new correct behavior,
not keeping an encoder doing things technically wrong just to not update
the tests.

> 
>>
>>> +case AVCOL_SPC_BT709:  ctx->colorspace = 0; break;
>>> +case AVCOL_SPC_BT2020_NCL: ctx->colorspace = 1; break;
>>> +case AVCOL_SPC_BT2020_CL:  ctx->colorspace = 2; break;
>>> +default:   ctx->colorspace = 3; break;
>>> +}
>>> +
>>>  avctx->profile = ctx->profile;
>>>  ctx->cid = ff_dnxhd_find_cid(avctx, ctx->bit_depth);
>>>  if (!ctx->cid) {
>>> @@ -576,7 +585,7 @@ static int dnxhd_write_header(AVCodecContext *avctx,
>>> uint8_t *buf)
>>>  buf[0x21] = ctx->bit_depth == 10 ? 0x58 : 0x38;
>>>  buf[0x22] = 0x88 + (ctx->interlaced << 2);
>>>  AV_WB32(buf + 0x28, ctx->cid); // CID
>>> -buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) |
>>> (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
>>> +buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) |
>>> (ctx->colorspace << 1) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
>>>
>>>  buf[0x5f] = 0x01; // UDL
>>>
>>> diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h
>>> index 7b0d862e28..4d5f457e33 100644
>>> --- a/libavcodec/dnxhdenc.h
>>> +++ b/libavcodec/dnxhdenc.h
>>> @@ -50,6 +50,7 @@ typedef struct DNXHDEncContext {
>>>  int profile;
>>>  int bit_depth;
>>>  int is_444;
>>> +int colorspace;
>>>  const CIDEntry *cid_table;
>>>  uint8_t *msip; ///< Macroblock Scan Indexes Payload
>>>  uint32_t *slice_size;
>>>
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

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

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

Re: [FFmpeg-devel] [PATCH] avfilter/af_anlmdn: add AArch64 SIMD for compute_distance_ssd

2020-01-24 Thread Carl Eugen Hoyos
Am Fr., 24. Jan. 2020 um 10:15 Uhr schrieb Zhao Zhili :
>
> ./ffmpeg -threads 1  -f lavfi -t 60 -i anoisesrc -af 'anlmdn' -f null 
> -benchmark -
>
> Test results on Snapdragon 845:
> Before:
> size=N/A time=00:01:00.00 bitrate=N/A speed=11.2x
> video:0kB audio:5625kB subtitle:0kB other streams:0kB global 
> headers:0kB muxing overhead: unknown
> bench: utime=5.320s stime=0.010s rtime=5.358s
> bench: maxrss=14172kB
>
> After:
> size=N/A time=00:01:00.00 bitrate=N/A speed=15.4x
> video:0kB audio:5625kB subtitle:0kB other streams:0kB global 
> headers:0kB muxing overhead: unknown
> bench: utime=3.870s stime=0.000s rtime=3.902s
> bench: maxrss=14036kB

In case anybody is curious:
This is a higher speedup than the x86 asm optimization offers.

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

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/dnxhdenc: properly store colorspace info

2020-01-24 Thread Carl Eugen Hoyos
Am Fr., 24. Jan. 2020 um 17:05 Uhr schrieb James Almer :
>
> On 1/24/2020 12:59 PM, Paul B Mahol wrote:
> > On 1/24/20, James Almer  wrote:
> >> On 1/24/2020 11:14 AM, Paul B Mahol wrote:
> >>> Signed-off-by: Paul B Mahol 
> >>> ---
> >>>  libavcodec/dnxhdenc.c | 11 ++-
> >>>  libavcodec/dnxhdenc.h |  1 +
> >>>  2 files changed, 11 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
> >>> index 2feb8baf21..03835fa794 100644
> >>> --- a/libavcodec/dnxhdenc.c
> >>> +++ b/libavcodec/dnxhdenc.c
> >>> @@ -406,6 +406,15 @@ static av_cold int dnxhd_encode_init(AVCodecContext
> >>> *avctx)
> >>>  }
> >>>
> >>>  ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444;
> >>> +
> >>> +switch (avctx->colorspace) {
> >>> +case AVCOL_SPC_UNSPECIFIED:
> >>
> >> Isn't 3 meant to be unspecified? If not, what is it for?
> >
> > This is to keep old behavior same. Where encoder would store
> > unspecified as bt709.
> > Mainly to not need to modify fate tests.
>
> The proper thing to do is adapt the tests to the new correct behavior,
> not keeping an encoder doing things technically wrong just to not update
> the tests.

But this could be an independent patch which would be better.

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

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

[FFmpeg-devel] [PATCH] lavc/dvdsubenc: accept palette from options

2020-01-24 Thread Michael Kuron



0001-lavc-dvdsubenc-accept-palette-from-options.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH] lavc/dvdsubenc: accept palette from options

2020-01-24 Thread Michael Kuron
Previously, the default palette would always be used.
Now, we can accept a custom palette, just like dvdsubdec does.

Signed-off-by: Michael Kuron 
---
 doc/encoders.texi  |  9 +
 libavcodec/dvdsubenc.c | 19 ++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index eefd124751..f8d5ecb5f9 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3115,6 +3115,15 @@ and they can also be used in Matroska files.
 
 @subsection Options
 
+@table @option
+@item palette
+Specify the global palette used by the bitmaps.
+
+The format for this option is a string containing 16 24-bits hexadecimal
+numbers (without 0x prefix) separated by comas, for example @code{0d00ee,
+ee450d, 101010, eaeaea, 0ce60b, ec14ed, ebff0b, 0d617a, 7b7b7b, d1d1d1,
+7b2a0e, 0d950c, 0f007b, cf0dec, cfa80c, 7c127b}.
+
 @table @option
 @item even_rows_fix
 When set to 1, enable a work-around that makes the number of pixel rows
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index ff95ed2002..674d97ab9b 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -29,6 +29,7 @@
 typedef struct {
 AVClass *class;
 uint32_t global_palette[16];
+char*palette_str;
 int even_rows_fix;
 } DVDSubtitleContext;
 
@@ -423,6 +424,17 @@ fail:
 return ret;
 }
 
+static void parse_palette(DVDSubtitleContext *ctx, char *p)
+{
+int i;
+
+for (i=0; i<16; i++) {
+ctx->global_palette[i] = strtoul(p, &p, 16);
+while (*p == ',' || av_isspace(*p))
+p++;
+}
+}
+
 static int dvdsub_init(AVCodecContext *avctx)
 {
 DVDSubtitleContext *dvdc = avctx->priv_data;
@@ -436,7 +448,11 @@ static int dvdsub_init(AVCodecContext *avctx)
 int i, ret;
 
 av_assert0(sizeof(dvdc->global_palette) == sizeof(default_palette));
-memcpy(dvdc->global_palette, default_palette, 
sizeof(dvdc->global_palette));
+if (dvdc->palette_str) {
+parse_palette(dvdc, dvdc->palette_str);
+} else {
+memcpy(dvdc->global_palette, default_palette, 
sizeof(dvdc->global_palette));
+}
 
 av_bprint_init(&extradata, 0, AV_BPRINT_SIZE_AUTOMATIC);
 if (avctx->width && avctx->height)
@@ -467,6 +483,7 @@ static int dvdsub_encode(AVCodecContext *avctx,
 #define OFFSET(x) offsetof(DVDSubtitleContext, x)
 #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
+{"palette", "set the global palette", OFFSET(palette_str), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SE },
 {"even_rows_fix", "Make number of rows even (workaround for some 
players)", OFFSET(even_rows_fix), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, SE},
 { NULL },
 };
-- 
2.21.1 (Apple Git-122.3)

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

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

Re: [FFmpeg-devel] [PATCH] checkasm: Check HAVE_GETSTDHANDLE here as well

2020-01-24 Thread Martin Storsjö

On Fri, 24 Jan 2020, Martin Storsjö wrote:


This was missed in 63418e374fcf26.
---
tests/checkasm/checkasm.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)


Will push this one now, as it's just completing the earlier pushed commit 
and there hasn't been any complaints.


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

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

Re: [FFmpeg-devel] [PATCH v2] lavc/qsv: adding DX11 support

2020-01-24 Thread Artem Galin
On Fri, 24 Jan 2020 at 00:46, Mark Thompson  wrote:

> On 23/01/2020 15:18, Artem Galin wrote:
> > This enables DX11 support for QSV with higher priority than DX9.
> > In case of multiple GPUs configuration, DX9 API does not allow to get
> > access to QSV device in some cases - headless.
> > Implementation based on DX11 resolves that restriction by enumerating
> list of available GPUs and finding device with QSV support.
> >
> > Signed-off-by: Artem Galin 
> > ---
> >  libavcodec/qsv.c  |  38 
> >  libavcodec/qsv_internal.h |   5 +
> >  libavcodec/version.h  |   2 +-
> >  libavfilter/qsvvpp.c  |  19 +---
> >  libavutil/hwcontext_d3d11va.c |  57 +++-
> >  libavutil/hwcontext_qsv.c | 169 +-
> >  libavutil/hwcontext_qsv.h |  13 ++-
> >  libavutil/version.h   |   2 +-
> >  8 files changed, 242 insertions(+), 63 deletions(-)
>
> This should be split into separate commits for the three libraries you
> touch.
>
> These changes are logically one piece of code and do not work
independently.

> ...
> > diff --git a/libavutil/hwcontext_d3d11va.c
> b/libavutil/hwcontext_d3d11va.c
> > index 6670c47579..a08479fd96 100644
> > --- a/libavutil/hwcontext_d3d11va.c
> > +++ b/libavutil/hwcontext_d3d11va.c
> > @@ -244,7 +244,7 @@ static int d3d11va_frames_init(AVHWFramesContext
> *ctx)
> >  return AVERROR(EINVAL);
> >  }
> >
> > -texDesc = (D3D11_TEXTURE2D_DESC){
> > +texDesc = (D3D11_TEXTURE2D_DESC) {
>
> Unrelated whitespace change.
>
> >  .Width  = ctx->width,
> >  .Height = ctx->height,
> >  .MipLevels  = 1,
> > @@ -510,6 +510,46 @@ static void d3d11va_device_uninit(AVHWDeviceContext
> *hwdev)
> >  }
> >  }
> >
> > +static int d3d11va_device_find_qsv_adapter(AVHWDeviceContext *ctx, UINT
> creationFlags)
> > +{
> > +HRESULT hr;
> > +IDXGIAdapter *adapter = NULL;
> > +int adapter_id = 0;
> > +int vendor_id = 0x8086;
> > +IDXGIFactory2 *factory;
> > +hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&factory);
> > +while (IDXGIFactory2_EnumAdapters(factory, adapter_id++, &adapter)
> != DXGI_ERROR_NOT_FOUND)
> > +{
> > +ID3D11Device* device = NULL;
> > +DXGI_ADAPTER_DESC adapter_desc;
> > +
> > +hr = mD3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL,
> creationFlags, NULL, 0, D3D11_SDK_VERSION, &device, NULL, NULL);
> > +if (FAILED(hr)) {
> > +av_log(ctx, AV_LOG_ERROR, "D3D11CreateDevice returned
> error\n");
> > +continue;
> > +}
> > +
> > +hr = IDXGIAdapter2_GetDesc(adapter, &adapter_desc);
> > +if (FAILED(hr)) {
> > +av_log(ctx, AV_LOG_ERROR, "IDXGIAdapter2_GetDesc returned
> error\n");
> > +continue;
> > +}
> > +
> > +if(device)
> > +ID3D11Device_Release(device);
> > +
> > +if (adapter)
> > +IDXGIAdapter_Release(adapter);
> > +
> > +if (adapter_desc.VendorId == vendor_id) {
> > +IDXGIFactory2_Release(factory);
> > +return adapter_id - 1;
> > +}
> > +}
> > +IDXGIFactory2_Release(factory);
> > +return -1;
> > +}
> > +
> >  static int d3d11va_device_create(AVHWDeviceContext *ctx, const char
> *device,
> >   AVDictionary *opts, int flags)
> >  {
> > @@ -519,7 +559,9 @@ static int d3d11va_device_create(AVHWDeviceContext
> *ctx, const char *device,
> >  IDXGIAdapter   *pAdapter = NULL;
> >  ID3D10Multithread  *pMultithread;
> >  UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
> > +int adapter = -1;
> >  int is_debug   = !!av_dict_get(opts, "debug", NULL, 0);
> > +int is_qsv = !!av_dict_get(opts, "d3d11va_qsv", NULL, 0);
>
> The only constraint you actually check here is the vendor ID, right?  I
> think it would make more sense to add code which goes looking for a device
> given the vendor ID rather than hard-coding a special function doing this
> specific case in here - compare with how VAAPI does exactly the same thing.
>
> Agree to change interface to support given vendor id.


> (That is, make "ffmpeg -init_hw_device d3d11va=,vendor=0x8086" do what
> you  would expect rather than hacking in a special libmfx case here.)
>

Agree that your proposal to have option to choose vendor by given vendor id
via command line is nice to have optionally and could be added later. This
patch is about enabling DX11 for qsv at the moment.


> >  int ret;
> >
> >  // (On UWP we can't check this.)
> > @@ -538,11 +580,22 @@ static int d3d11va_device_create(AVHWDeviceContext
> *ctx, const char *device,
> >  return AVERROR_UNKNOWN;
> >  }
> >
> > +if (is_qsv) {
> > +adapter = d3d11va_device_find_qsv_adapter(ctx, creationFlags);
> > +if (adapter < 0) {
> > +av_log(ctx, AV_LOG_ERROR, "Failed to find DX11 adapter with
> QS

Re: [FFmpeg-devel] [PATCH] lavc/dvdsubenc: accept palette from options

2020-01-24 Thread Andreas Rheinhardt
On Fri, Jan 24, 2020 at 7:26 PM Michael Kuron 
wrote:

> Previously, the default palette would always be used.
> Now, we can accept a custom palette, just like dvdsubdec does.
>
> Signed-off-by: Michael Kuron 
> ---
>  doc/encoders.texi  |  9 +
>  libavcodec/dvdsubenc.c | 19 ++-
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index eefd124751..f8d5ecb5f9 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3115,6 +3115,15 @@ and they can also be used in Matroska files.
>
>  @subsection Options
>
> +@table @option
> +@item palette
> +Specify the global palette used by the bitmaps.
> +
> +The format for this option is a string containing 16 24-bits hexadecimal
> +numbers (without 0x prefix) separated by comas, for example @code{0d00ee,
> +ee450d, 101010, eaeaea, 0ce60b, ec14ed, ebff0b, 0d617a, 7b7b7b, d1d1d1,
> +7b2a0e, 0d950c, 0f007b, cf0dec, cfa80c, 7c127b}.
> +
>

You are adding another table (that you don't close), whereas you should
only add an item to the already existing table. As a consequence, building
fails when one also builds the documentation
.

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

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

[FFmpeg-devel] [PATCH 08/12] avformat/avc, hevc: Check the allocations implicit in dynamic buffers

2020-01-24 Thread Andreas Rheinhardt
Dynamic buffers involve implicit allocations that are currently usually
unchecked; ff_avc_parse_nal_units_buf() and ff_hevc_annexb2mp4buf() are
no exceptions to this. So add checks for them.

Signed-off-by: Andreas Rheinhardt 
---
One might argue that this should also check for whether the size returned
by ff_hevc_annexb2mp4() resp. ff_avc_parse_nal_units() equals the size
of the buffer (dynamic buffers have an implicit INT_MAX/2 allocation
limit and if it is hit, no further writes are performed, but the already
written data is not discarded); given that I prefer to drop this limit
(and replace it by INT_MAX) later I have not added such a check here.

(In case of an unchecked allocation failure in which the returned buffer
is NULL, the returned size is -AV_INPUT_BUFFER_PADDING_SIZE. This is
something that put_ebml_num() (the int is converted to uint64_t for it)
doesn't like at all (it should assert, yet it actually runs into an
infinite loop in ebml_num_size()).)

 libavformat/avc.c  | 3 +++
 libavformat/hevc.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/libavformat/avc.c b/libavformat/avc.c
index cd15ac3cdb..aef5d3c35d 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -102,6 +102,9 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, 
uint8_t **buf, int *size)
 ff_avc_parse_nal_units(pb, buf_in, *size);
 
 *size = avio_close_dyn_buf(pb, buf);
+if (!*buf)
+return AVERROR(ENOMEM);
+
 return 0;
 }
 
diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index f621cb2f19..a4e53bc4ab 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -1061,6 +1061,8 @@ int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t 
**buf_out,
 }
 
 *size = avio_close_dyn_buf(pb, buf_out);
+if (!*buf_out)
+return AVERROR(ENOMEM);
 
 return 0;
 }
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 09/12] avformat/hevc: Defer initializations in ff_isom_write_hvcc()

2020-01-24 Thread Andreas Rheinhardt
Saves initialization of an HEVCDecoderConfigurationRecord when
the data is already in ISOBMFF-format or if it is plainly invalid.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hevc.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index a4e53bc4ab..616e9ed49a 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -1070,29 +1070,27 @@ int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, 
uint8_t **buf_out,
 int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data,
int size, int ps_array_completeness)
 {
-int ret = 0;
-uint8_t *buf, *end, *start = NULL;
 HEVCDecoderConfigurationRecord hvcc;
-
-hvcc_init(&hvcc);
+uint8_t *buf, *end, *start;
+int ret;
 
 if (size < 6) {
 /* We can't write a valid hvcC from the provided data */
-ret = AVERROR_INVALIDDATA;
-goto end;
+return AVERROR_INVALIDDATA;
 } else if (*data == 1) {
 /* Data is already hvcC-formatted */
 avio_write(pb, data, size);
-goto end;
+return 0;
 } else if (!(AV_RB24(data) == 1 || AV_RB32(data) == 1)) {
 /* Not a valid Annex B start code prefix */
-ret = AVERROR_INVALIDDATA;
-goto end;
+return AVERROR_INVALIDDATA;
 }
 
 ret = ff_avc_parse_nal_units_buf(data, &start, &size);
 if (ret < 0)
-goto end;
+return ret;
+
+hvcc_init(&hvcc);
 
 buf = start;
 end = start + size;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 10/12] avformat/av1: Fix nits in the documentation of ff_av1_filter_obus_buf()

2020-01-24 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/av1.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavformat/av1.h b/libavformat/av1.h
index 52d0814e86..6cc3fcaad2 100644
--- a/libavformat/av1.h
+++ b/libavformat/av1.h
@@ -59,15 +59,13 @@ int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, 
int size);
  * Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and write
  * the resulting bitstream to a newly allocated data buffer.
  *
- * @param pb pointer to the AVIOContext where the filtered bitstream shall be
- *   written
  * @param in input data buffer
  * @param out pointer to pointer that will hold the allocated data buffer
  * @param size size of the input data buffer. The size of the resulting output
-   data buffer will be written here
+ * data buffer will be written here
  *
  * @return 0 in case of success, a negative AVERROR code in case of failure.
- * On failure, out and size are unchanged
+ * On failure, *out and *size are unchanged
  * @note *out will be treated as unintialized on input and will not be freed.
  */
 int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, int *size);
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 07/12] avformat/av1, avc, hevc: Remove av_freep()

2020-01-24 Thread Andreas Rheinhardt
ff_av1_filter_obus_buf() and ff_avc_parse_nal_units_buf() both have a
pointer-to-pointer parameter which they use to pass a newly allocated
buffer to the caller. And both functions freed what this pointer points to
before overwriting it. But no caller of these functions used this feature,
but some had to initialize the pointer just because of this. So remove
it and update the documentation of ff_av1_filter_obus_buf() wrt this fact.

ff_hevc_annexb2mp4_buf in contrast did not free the pointer. This has been
documented, too.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/av1.c  | 1 -
 libavformat/av1.h  | 1 +
 libavformat/avc.c  | 3 +--
 libavformat/hevc.h | 1 +
 4 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/av1.c b/libavformat/av1.c
index 80c049f62f..07b399efcc 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -82,7 +82,6 @@ int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, 
int *size)
 
 memset(buf + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
-av_freep(out);
 *out  = buf;
 *size = len;
 
diff --git a/libavformat/av1.h b/libavformat/av1.h
index acba12612c..52d0814e86 100644
--- a/libavformat/av1.h
+++ b/libavformat/av1.h
@@ -68,6 +68,7 @@ int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, 
int size);
  *
  * @return 0 in case of success, a negative AVERROR code in case of failure.
  * On failure, out and size are unchanged
+ * @note *out will be treated as unintialized on input and will not be freed.
  */
 int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, int *size);
 
diff --git a/libavformat/avc.c b/libavformat/avc.c
index e4e82e1864..cd15ac3cdb 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -101,7 +101,6 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, 
uint8_t **buf, int *size)
 
 ff_avc_parse_nal_units(pb, buf_in, *size);
 
-av_freep(buf);
 *size = avio_close_dyn_buf(pb, buf);
 return 0;
 }
@@ -109,7 +108,7 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, 
uint8_t **buf, int *size)
 int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
 {
 AVIOContext *sps_pb = NULL, *pps_pb = NULL, *sps_ext_pb = NULL;
-uint8_t *buf = NULL, *end, *start = NULL;
+uint8_t *buf, *end, *start;
 uint8_t *sps, *pps, *sps_ext;
 uint32_t sps_size = 0, pps_size = 0, sps_ext_size = 0;
 int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0;
diff --git a/libavformat/hevc.h b/libavformat/hevc.h
index bb144397c0..0f56325c1c 100644
--- a/libavformat/hevc.h
+++ b/libavformat/hevc.h
@@ -73,6 +73,7 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
  *parameter set NAL units shall be written, may be NULL
  * @return 0 in case of success, a negative value corresponding to an AVERROR
  * code in case of failure
+ * @note *buf_out will be treated as uninitialized on input and won't be freed.
  */
 int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
int *size, int filter_ps, int *ps_count);
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 12/12] avformat/av1: Avoid allocation + copying when filtering OBUs

2020-01-24 Thread Andreas Rheinhardt
Certain types of OBUs are stripped away before muxing into Matroska and
ISOBMFF; there are two functions to do this: One that outputs by
directly writing in an AVIOContext and one that returns a freshly
allocated buffer with the units not stripped away copied into it.

The latter option is bad for performance, especially when the input
does already not contain any of the units intended to be stripped away
(this covers typical remuxing scenarios). Therefore this commit changes
this by avoiding allocating and copying when possible; it is possible if
the OBUs to be retained are consecutively in the input buffer (without
an OBU to be discarded between them). In this case, the caller receives
the offset as well as the length of the part of the buffer that contains
the units to be kept. This also avoids copying when e.g. the only unit
to be discarded is a temporal delimiter at the front.

For a 22.7mb/s file with average framesize 113 kB this improved the time
for the calls to ff_av1_filter_obus_buf() when writing Matroska from
313319 decicycles to 2368 decicycles; for another file with 1.5mb/s
(average framesize 7.3 kB) it improved from 34539 decicycles to 1922
decicyles. For these files the only units that needed to be stripped
away were temporal unit delimiters at the front.

Signed-off-by: Andreas Rheinhardt 
---
If it is desired, I can add a commit to switch ff_mov_write_packet() to
not use a pointer just for reformatted_data (that is of course
initialized to NULL), but to replace it by a data buffer that gets
initialized to pkt->data and modified so that data + offset always
points to the current data. (This is possible now that the av_freep()
have been removed from the reformatting functions.)

 libavformat/av1.c | 50 ---
 libavformat/av1.h | 13 ++
 libavformat/matroskaenc.c |  2 +-
 libavformat/movenc.c  | 11 +
 4 files changed, 58 insertions(+), 18 deletions(-)

diff --git a/libavformat/av1.c b/libavformat/av1.c
index 07b399efcc..fef8e96f8d 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -29,13 +29,20 @@
 #include "avio.h"
 #include "avio_internal.h"
 
-int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
+static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf,
+   int size, int *offset)
 {
-const uint8_t *end = buf + size;
+const uint8_t *start = buf, *end = buf + size;
 int64_t obu_size;
-int start_pos, type, temporal_id, spatial_id;
-
-size = 0;
+int off, start_pos, type, temporal_id, spatial_id;
+enum {
+START_NOT_FOUND,
+START_FOUND,
+END_FOUND,
+OFFSET_IMPOSSIBLE,
+} state = START_NOT_FOUND;
+
+off = size = 0;
 while (buf < end) {
 int len = parse_obu_header(buf, end - buf, &obu_size, &start_pos,
&type, &temporal_id, &spatial_id);
@@ -47,8 +54,16 @@ int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, 
int size)
 case AV1_OBU_REDUNDANT_FRAME_HEADER:
 case AV1_OBU_TILE_LIST:
 case AV1_OBU_PADDING:
+if (state == START_FOUND)
+state = END_FOUND;
 break;
 default:
+if (state == START_NOT_FOUND) {
+off   = buf - start;
+state = START_FOUND;
+} else if (state == END_FOUND) {
+state = OFFSET_IMPOSSIBLE;
+}
 if (pb)
 avio_write(pb, buf, len);
 size += len;
@@ -57,19 +72,35 @@ int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, 
int size)
 buf += len;
 }
 
+if (offset)
+*offset = state != OFFSET_IMPOSSIBLE ? off : -1;
+
 return size;
 }
 
-int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, int *size)
+int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
+{
+return av1_filter_obus(pb, buf, size, NULL);
+}
+
+int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out,
+   int *size, int *offset)
 {
 AVIOContext pb;
 uint8_t *buf;
-int len, ret;
+int len, off, ret;
 
-len = ret = ff_av1_filter_obus(NULL, in, *size);
+len = ret = av1_filter_obus(NULL, in, *size, &off);
 if (ret < 0) {
 return ret;
 }
+if (off >= 0) {
+*out= (uint8_t *)in;
+*size   = len;
+*offset = off;
+
+return 0;
+}
 
 buf = av_malloc((size_t)len + AV_INPUT_BUFFER_PADDING_SIZE);
 if (!buf)
@@ -77,13 +108,14 @@ int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t 
**out, int *size)
 
 ffio_init_context(&pb, buf, len, 1, NULL, NULL, NULL, NULL);
 
-ret = ff_av1_filter_obus(&pb, in, *size);
+ret = av1_filter_obus(&pb, in, *size, NULL);
 av_assert1(ret == len);
 
 memset(buf + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
 *out  = buf;
 *size = len;
+*offset = 0;
 
 return 0;
 }
diff --git a

[FFmpeg-devel] [PATCH] lavc/dvdsubenc: accept palette from options

2020-01-24 Thread Michael Kuron
Previously, the default palette would always be used.
Now, we can accept a custom palette, just like dvdsubdec does.

Signed-off-by: Michael Kuron 
---
 doc/encoders.texi  |  8 
 libavcodec/dvdsubenc.c | 19 ++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index eefd124751..a04f9f1b62 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3116,6 +3116,14 @@ and they can also be used in Matroska files.
 @subsection Options
 
 @table @option
+@item palette
+Specify the global palette used by the bitmaps.
+
+The format for this option is a string containing 16 24-bits hexadecimal
+numbers (without 0x prefix) separated by commas, for example @code{0d00ee,
+ee450d, 101010, eaeaea, 0ce60b, ec14ed, ebff0b, 0d617a, 7b7b7b, d1d1d1,
+7b2a0e, 0d950c, 0f007b, cf0dec, cfa80c, 7c127b}.
+
 @item even_rows_fix
 When set to 1, enable a work-around that makes the number of pixel rows
 even in all subtitles.  This fixes a problem with some players that
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index ff95ed2002..674d97ab9b 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -29,6 +29,7 @@
 typedef struct {
 AVClass *class;
 uint32_t global_palette[16];
+char*palette_str;
 int even_rows_fix;
 } DVDSubtitleContext;
 
@@ -423,6 +424,17 @@ fail:
 return ret;
 }
 
+static void parse_palette(DVDSubtitleContext *ctx, char *p)
+{
+int i;
+
+for (i=0; i<16; i++) {
+ctx->global_palette[i] = strtoul(p, &p, 16);
+while (*p == ',' || av_isspace(*p))
+p++;
+}
+}
+
 static int dvdsub_init(AVCodecContext *avctx)
 {
 DVDSubtitleContext *dvdc = avctx->priv_data;
@@ -436,7 +448,11 @@ static int dvdsub_init(AVCodecContext *avctx)
 int i, ret;
 
 av_assert0(sizeof(dvdc->global_palette) == sizeof(default_palette));
-memcpy(dvdc->global_palette, default_palette, 
sizeof(dvdc->global_palette));
+if (dvdc->palette_str) {
+parse_palette(dvdc, dvdc->palette_str);
+} else {
+memcpy(dvdc->global_palette, default_palette, 
sizeof(dvdc->global_palette));
+}
 
 av_bprint_init(&extradata, 0, AV_BPRINT_SIZE_AUTOMATIC);
 if (avctx->width && avctx->height)
@@ -467,6 +483,7 @@ static int dvdsub_encode(AVCodecContext *avctx,
 #define OFFSET(x) offsetof(DVDSubtitleContext, x)
 #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
+{"palette", "set the global palette", OFFSET(palette_str), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SE },
 {"even_rows_fix", "Make number of rows even (workaround for some 
players)", OFFSET(even_rows_fix), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, SE},
 { NULL },
 };
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 11/12] avformat/hevc: Clarify documentation of filter_ps

2020-01-24 Thread Andreas Rheinhardt
and use it to avoid unnecessary initializations and frees in
ff_hevc_annexb2mp4() and ff_hevc_annexb2mp4_buf(): Even if the caller
does not want to strip HEVC parameter sets away when converting from
Annex B to mp4, a pointer has been initialized to NULL and later freed
while still being NULL despite having not been used at all.

The reason for this is that there is still a jump to the end of the
function in order to set a variable (returned via a pointer argument)
containing the number of parameter set NAL units stripped away to zero.
But if the caller does not want to strip these parameter sets away, it
is pointless to set this variable. Document this behaviour and remove
the jump.

Also document that said number won't be set on error (in case of
ff_hevc_annexb2mp4_buf(), this was actually the behaviour anyway) and
remove the jump to the end on error, too; this also allows to avoid
initializing the pointer mentioned above.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hevc.c |  8 +++-
 libavformat/hevc.h | 14 --
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 616e9ed49a..b07897d9a5 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -1000,16 +1000,15 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t 
*buf_in,
int size, int filter_ps, int *ps_count)
 {
 int num_ps = 0, ret = 0;
-uint8_t *buf, *end, *start = NULL;
+uint8_t *buf, *end, *start;
 
 if (!filter_ps) {
-ret = ff_avc_parse_nal_units(pb, buf_in, size);
-goto end;
+return ff_avc_parse_nal_units(pb, buf_in, size);
 }
 
 ret = ff_avc_parse_nal_units_buf(buf_in, &start, &size);
 if (ret < 0)
-goto end;
+return ret;
 
 ret = 0;
 buf = start;
@@ -1037,7 +1036,6 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t 
*buf_in,
 buf += len;
 }
 
-end:
 av_free(start);
 if (ps_count)
 *ps_count = num_ps;
diff --git a/libavformat/hevc.h b/libavformat/hevc.h
index 0f56325c1c..3ff4614022 100644
--- a/libavformat/hevc.h
+++ b/libavformat/hevc.h
@@ -42,9 +42,10 @@
  * @param buf_in address of the buffer holding the input data
  * @param size size (in bytes) of the input buffer
  * @param filter_ps whether to write parameter set NAL units to the output (0)
- *or to discard them (non-zero)
- * @param ps_count address of the variable where the number of discarded
- *parameter set NAL units shall be written, may be NULL
+ *or to count but discard them (non-zero)
+ * @param ps_count if filter_ps is nonzero, address of the variable where the
+ *number of discarded parameter set NAL units shall be written
+ *on success; otherwise ignored; may be NULL
  * @return the amount (in bytes) of data written in case of success, a negative
  * value corresponding to an AVERROR code in case of failure
  */
@@ -68,9 +69,10 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t 
*buf_in,
  * @param buf_out on success, address of the variable holding the address of
  *the output buffer
  * @param filter_ps whether to write parameter set NAL units to the output (0)
- *or to discard them (non-zero)
- * @param ps_count address of the variable where the number of discarded
- *parameter set NAL units shall be written, may be NULL
+ *or to count but discard them (non-zero)
+ * @param ps_count if filter_ps is nonzero, address of the variable where the
+ *number of discarded parameter set NAL units shall be written
+ *on success; otherwise ignored; may be NULL
  * @return 0 in case of success, a negative value corresponding to an AVERROR
  * code in case of failure
  * @note *buf_out will be treated as uninitialized on input and won't be freed.
-- 
2.20.1

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

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

Re: [FFmpeg-devel] [PATCH 4/4] avformat/udp: do not use thread cancellation when receiving data

2020-01-24 Thread Marton Balint



On Thu, 23 Jan 2020, Matt Oliver wrote:


On Thu, 23 Jan 2020 at 08:12, Marton Balint  wrote:




On Wed, 22 Jan 2020, Nicolas George wrote:


Marton Balint (12020-01-16):

It is not supported by every threading implementation, and the only

thing we

gain with it is an immediate shutdown of receiving packets on close and
avoiding the poll call before reading the data.

I don't think it is a big issue if it takes 0.1 sec of delay to close

an udp

stream. Back when this was introduced the delay was 1 sec, which was

indeed

noticable.


I don't like this. 0.1 s is less noticeable than 1 s for interactive
human users, but for applications it may be way too much.


pthread_cancel is not implemented properly on Win32, also it is generally
not considered a good practice. 0.1 sec delay is still the lesser evil
than a lockup as shown in ticket #5717.

An alternate approach might be to call shutdown() from the main thread and
hope that this interrupts the recvfrom() call in the receiver thread. It
tends to work for linux, I am not sure how other platforms would react,
what do you think?



I actually had an old patch for that too. On Win32 the shutdown function
will cause any existing recv calls in other threads to instantly return
with an error code.


I tested this on Windows7/10 and it does not seem to work. closesocket() 
indeed aborts the pending recv() call, but not shutdown(). CancelIoEx() 
seems to work though.


Regards,
Marton

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

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

Re: [FFmpeg-devel] [PATCH 4/4] avformat/udp: do not use thread cancellation when receiving data

2020-01-24 Thread Nicolas George
Marton Balint (12020-01-24):
> I tested this on Windows7/10 and it does not seem to work. closesocket()
> indeed aborts the pending recv() call, but not shutdown(). CancelIoEx()
> seems to work though.

Using one of these to implement a pthread_cancel() that works for our
situation seems like the best option, then, does it not?

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/cbs_av1_syntax_template: Remove unused variable

2020-01-24 Thread James Almer
On 11/18/2019 4:47 AM, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cbs_av1_syntax_template.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavcodec/cbs_av1_syntax_template.c 
> b/libavcodec/cbs_av1_syntax_template.c
> index c843cfa02b..c00982f74f 100644
> --- a/libavcodec/cbs_av1_syntax_template.c
> +++ b/libavcodec/cbs_av1_syntax_template.c
> @@ -20,7 +20,6 @@ static int FUNC(obu_header)(CodedBitstreamContext *ctx, 
> RWContext *rw,
>  AV1RawOBUHeader *current)
>  {
>  int err;
> -av_unused int zero = 0;
>  
>  HEADER("OBU header");

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

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

Re: [FFmpeg-devel] [PATCH] lavc/dvdsubenc: accept palette from options

2020-01-24 Thread Carl Eugen Hoyos
Am Fr., 24. Jan. 2020 um 23:49 Uhr schrieb Michael Kuron
:
>
> Previously, the default palette would always be used.
> Now, we can accept a custom palette, just like dvdsubdec does.
>
> Signed-off-by: Michael Kuron 
> ---
>  doc/encoders.texi  |  8 
>  libavcodec/dvdsubenc.c | 19 ++-
>  2 files changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index eefd124751..a04f9f1b62 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3116,6 +3116,14 @@ and they can also be used in Matroska files.
>  @subsection Options
>
>  @table @option
> +@item palette
> +Specify the global palette used by the bitmaps.
> +
> +The format for this option is a string containing 16 24-bits hexadecimal
> +numbers (without 0x prefix) separated by commas, for example @code{0d00ee,
> +ee450d, 101010, eaeaea, 0ce60b, ec14ed, ebff0b, 0d617a, 7b7b7b, d1d1d1,
> +7b2a0e, 0d950c, 0f007b, cf0dec, cfa80c, 7c127b}.
> +
>  @item even_rows_fix
>  When set to 1, enable a work-around that makes the number of pixel rows
>  even in all subtitles.  This fixes a problem with some players that
> diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
> index ff95ed2002..674d97ab9b 100644
> --- a/libavcodec/dvdsubenc.c
> +++ b/libavcodec/dvdsubenc.c
> @@ -29,6 +29,7 @@
>  typedef struct {
>  AVClass *class;
>  uint32_t global_palette[16];
> +char*palette_str;
>  int even_rows_fix;
>  } DVDSubtitleContext;
>
> @@ -423,6 +424,17 @@ fail:
>  return ret;
>  }
>
> +static void parse_palette(DVDSubtitleContext *ctx, char *p)
> +{
> +int i;
> +
> +for (i=0; i<16; i++) {
> +ctx->global_palette[i] = strtoul(p, &p, 16);
> +while (*p == ',' || av_isspace(*p))
> +p++;
> +}
> +}
> +
>  static int dvdsub_init(AVCodecContext *avctx)
>  {
>  DVDSubtitleContext *dvdc = avctx->priv_data;
> @@ -436,7 +448,11 @@ static int dvdsub_init(AVCodecContext *avctx)
>  int i, ret;
>
>  av_assert0(sizeof(dvdc->global_palette) == sizeof(default_palette));
> -memcpy(dvdc->global_palette, default_palette, 
> sizeof(dvdc->global_palette));
> +if (dvdc->palette_str) {
> +parse_palette(dvdc, dvdc->palette_str);
> +} else {
> +memcpy(dvdc->global_palette, default_palette, 
> sizeof(dvdc->global_palette));
> +}
>
>  av_bprint_init(&extradata, 0, AV_BPRINT_SIZE_AUTOMATIC);
>  if (avctx->width && avctx->height)
> @@ -467,6 +483,7 @@ static int dvdsub_encode(AVCodecContext *avctx,
>  #define OFFSET(x) offsetof(DVDSubtitleContext, x)
>  #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
>  static const AVOption options[] = {
> +{"palette", "set the global palette", OFFSET(palette_str), 
> AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SE },

What happens if invalid values are passed as palette?

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

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

[FFmpeg-devel] [PATCH 01/13] lavc/ass: realign ff_ass_subtitle_header_default

2020-01-24 Thread rcombs
---
 libavcodec/ass.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index b4f081c819..da05a83d69 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -80,14 +80,14 @@ int ff_ass_subtitle_header(AVCodecContext *avctx,
 int ff_ass_subtitle_header_default(AVCodecContext *avctx)
 {
 return ff_ass_subtitle_header(avctx, ASS_DEFAULT_FONT,
-   ASS_DEFAULT_FONT_SIZE,
-   ASS_DEFAULT_COLOR,
-   ASS_DEFAULT_BACK_COLOR,
-   ASS_DEFAULT_BOLD,
-   ASS_DEFAULT_ITALIC,
-   ASS_DEFAULT_UNDERLINE,
-   ASS_DEFAULT_BORDERSTYLE,
-   ASS_DEFAULT_ALIGNMENT);
+  ASS_DEFAULT_FONT_SIZE,
+  ASS_DEFAULT_COLOR,
+  ASS_DEFAULT_BACK_COLOR,
+  ASS_DEFAULT_BOLD,
+  ASS_DEFAULT_ITALIC,
+  ASS_DEFAULT_UNDERLINE,
+  ASS_DEFAULT_BORDERSTYLE,
+  ASS_DEFAULT_ALIGNMENT);
 }
 
 char *ff_ass_get_dialog(int readorder, int layer, const char *style,
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 02/13] lavc/ass: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/ass.c | 154 ++-
 libavcodec/ass.h | 106 +++-
 2 files changed, 215 insertions(+), 45 deletions(-)

diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index da05a83d69..65942a2567 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -24,57 +24,119 @@
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
+#include "libavutil/bswap.h"
 #include "libavutil/common.h"
 
+static int invert_ass_alpha(uint32_t c)
+{
+uint32_t a = c >> 24;
+return ((255 - a) << 24) | (c & 0xff);
+}
+
+#define CL_FF2ASS(c) invert_ass_alpha(av_le2ne32(c))
+#define CL_ASS2FF(c) av_le2ne32(invert_ass_alpha(c))
+
+int ff_ass_bprint_style(AVBPrint *buf, const FFASSStyle *style)
+{
+av_bprintf(buf,
+   "Style: "
+   "%s,"  /* Name */
+   "%s,%g,"   /* Font{name,size} */
+   "&H%x,&H%x,&H%x,&H%x," /* 
{Primary,Secondary,Outline,Back}Colour */
+   "%d,%d,%d,%d," /* Bold, Italic, Underline, StrikeOut */
+   "%g,%g,"   /* Scale{X,Y} */
+   "%g,%g,"   /* Spacing, Angle */
+   "%d,%g,%g,"/* BorderStyle, Outline, Shadow */
+   "%d,%d,%d,%d," /* Alignment, Margin[LRV] */
+   "0\r\n",   /* Encoding */
+   style->name ? style->name : "Default",
+   style->font ? style->font : ASS_DEFAULT_FONT, style->font_size,
+   CL_FF2ASS(style->color), CL_FF2ASS(style->color2),
+   CL_FF2ASS(style->outline_color), CL_FF2ASS(style->back_color),
+   style->bold, style->italic, style->underline, style->strikeout,
+   style->scale_x, style->scale_y,
+   style->spacing, style->angle,
+   style->border_style, style->outline, style->shadow,
+   style->alignment, style->margin_l, style->margin_r, 
style->margin_v);
+
+return 0; // Not currently possible to detect bprintf errors
+}
+
+int ff_ass_subtitle_header2(AVCodecContext *avctx, int res_x, int res_y, const 
FFASSStyle *style)
+{
+int ret = 0;
+AVBPrint buf;
+av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
+av_bprintf(&buf,
+   "[Script Info]\r\n"
+   "; Script generated by FFmpeg/Lavc%s\r\n"
+   "ScriptType: v4.00+\r\n"
+   "PlayResX: %d\r\n"
+   "PlayResY: %d\r\n"
+   "\r\n"
+   "[V4+ Styles]\r\n"
+
+   /* ASSv4+ header */
+   "Format: Name, "
+   "Fontname, Fontsize, "
+   "PrimaryColour, SecondaryColour, OutlineColour, BackColour, "
+   "Bold, Italic, Underline, StrikeOut, "
+   "ScaleX, ScaleY, "
+   "Spacing, Angle, "
+   "BorderStyle, Outline, Shadow, "
+   "Alignment, MarginL, MarginR, MarginV, "
+   "Encoding\r\n",
+   !(avctx->flags & AV_CODEC_FLAG_BITEXACT) ? 
AV_STRINGIFY(LIBAVCODEC_VERSION) : "",
+   res_x, res_y);
+
+if ((ret = ff_ass_bprint_style(&buf, style) < 0))
+goto fail;
+
+av_bprintf(&buf,
+   "\r\n"
+   "[Events]\r\n"
+   "Format: Layer, Start, End, Style, Name, MarginL, MarginR, 
MarginV, Effect, Text\r\n");
+
+if ((ret = av_bprint_finalize(&buf, (char**)&avctx->subtitle_header)) < 0)
+return ret;
+
+avctx->subtitle_header_size = buf.len;
+return 0;
+
+fail:
+av_bprint_finalize(&buf, NULL);
+return ret;
+}
+
+int ff_ass_subtitle_header_from_opts(AVCodecContext *avctx, const 
FFASSHeaderOptions *opts)
+{
+return ff_ass_subtitle_header2(avctx, opts->res_x, opts->res_y, 
&opts->style);
+}
+
 int ff_ass_subtitle_header(AVCodecContext *avctx,
const char *font, int font_size,
int color, int back_color,
int bold, int italic, int underline,
int border_style, int alignment)
 {
-avctx->subtitle_header = av_asprintf(
- "[Script Info]\r\n"
- "; Script generated by FFmpeg/Lavc%s\r\n"
- "ScriptType: v4.00+\r\n"
- "PlayResX: %d\r\n"
- "PlayResY: %d\r\n"
- "\r\n"
- "[V4+ Styles]\r\n"
-
- /* ASSv4 header */
- "Format: Name, "
- "Fontname, Fontsize, "
- "PrimaryColour, SecondaryColour, OutlineColour, BackColour, "
- "Bold, Italic, Underline, StrikeOut, "
- "ScaleX, ScaleY, "
- "Spacing, Angle, "
- "BorderStyle, Outline, Shadow, "
- "Alignment, MarginL, MarginR, MarginV, "
- "Encoding\r\n"
-
- "Style: "
- "Default," /* Name */
- "%s,%d,"   /* Font{nam

[FFmpeg-devel] [PATCH 03/13] lavc/srtdec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/srtdec.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index ecc0801595..8d3b3cfc9e 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -85,6 +85,8 @@ static int srt_decode_frame(AVCodecContext *avctx,
 return avpkt->size;
 }
 
+ASS_GENERIC_CLASS(srt, SubRip)
+
 #if CONFIG_SRT_DECODER
 /* deprecated decoder */
 AVCodec ff_srt_decoder = {
@@ -96,18 +98,22 @@ AVCodec ff_srt_decoder = {
 .decode   = srt_decode_frame,
 .flush= ff_ass_decoder_flush,
 .priv_data_size = sizeof(FFASSDecoderContext),
+.priv_class   = &srt_decoder_class,
 };
 #endif
 
+ASS_GENERIC_CLASS(subrip, SubRip)
+
 #if CONFIG_SUBRIP_DECODER
 AVCodec ff_subrip_decoder = {
 .name = "subrip",
 .long_name= NULL_IF_CONFIG_SMALL("SubRip subtitle"),
 .type = AVMEDIA_TYPE_SUBTITLE,
 .id   = AV_CODEC_ID_SUBRIP,
-.init = ff_ass_subtitle_header_default,
+.init = ff_ass_subtitle_header_options,
 .decode   = srt_decode_frame,
 .flush= ff_ass_decoder_flush,
 .priv_data_size = sizeof(FFASSDecoderContext),
+.priv_class   = &subrip_decoder_class,
 };
 #endif
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 04/13] lavc/webvttdec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/webvttdec.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/webvttdec.c b/libavcodec/webvttdec.c
index 7b2d1750de..494de08884 100644
--- a/libavcodec/webvttdec.c
+++ b/libavcodec/webvttdec.c
@@ -98,13 +98,16 @@ static int webvtt_decode_frame(AVCodecContext *avctx,
 return avpkt->size;
 }
 
+ASS_GENERIC_CLASS(webvtt, WebVTT)
+
 AVCodec ff_webvtt_decoder = {
 .name   = "webvtt",
 .long_name  = NULL_IF_CONFIG_SMALL("WebVTT subtitle"),
 .type   = AVMEDIA_TYPE_SUBTITLE,
 .id = AV_CODEC_ID_WEBVTT,
 .decode = webvtt_decode_frame,
-.init   = ff_ass_subtitle_header_default,
+.init   = ff_ass_subtitle_header_options,
 .flush  = ff_ass_decoder_flush,
 .priv_data_size = sizeof(FFASSDecoderContext),
+.priv_class = &webvtt_decoder_class,
 };
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 11/13] lavc/samidec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/samidec.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c
index e32f238c62..8804210700 100644
--- a/libavcodec/samidec.c
+++ b/libavcodec/samidec.c
@@ -30,12 +30,14 @@
 #include "htmlsubtitles.h"
 
 typedef struct {
+AVClass *class;
+int readorder;
+FFASSHeaderOptions common;
 AVBPrint source;
 AVBPrint content;
 AVBPrint encoded_source;
 AVBPrint encoded_content;
 AVBPrint full;
-int readorder;
 } SAMIContext;
 
 static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
@@ -159,7 +161,7 @@ static av_cold int sami_init(AVCodecContext *avctx)
 av_bprint_init(&sami->encoded_source,  0, 2048);
 av_bprint_init(&sami->encoded_content, 0, 2048);
 av_bprint_init(&sami->full,0, 2048);
-return ff_ass_subtitle_header_default(avctx);
+return ff_ass_subtitle_header_from_opts(avctx, &sami->common);
 }
 
 static av_cold int sami_close(AVCodecContext *avctx)
@@ -180,6 +182,8 @@ static void sami_flush(AVCodecContext *avctx)
 sami->readorder = 0;
 }
 
+ASS_GENERIC_CLASS(sami, SAMI)
+
 AVCodec ff_sami_decoder = {
 .name   = "sami",
 .long_name  = NULL_IF_CONFIG_SMALL("SAMI subtitle"),
@@ -190,4 +194,5 @@ AVCodec ff_sami_decoder = {
 .close  = sami_close,
 .decode = sami_decode_frame,
 .flush  = sami_flush,
+.priv_class = &sami_decoder_class,
 };
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 07/13] lavc/subviewerdec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/subviewerdec.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/subviewerdec.c b/libavcodec/subviewerdec.c
index 805c7dd547..7fbcf54d4c 100644
--- a/libavcodec/subviewerdec.c
+++ b/libavcodec/subviewerdec.c
@@ -65,13 +65,16 @@ static int subviewer_decode_frame(AVCodecContext *avctx,
 return avpkt->size;
 }
 
+ASS_GENERIC_CLASS(subviewer, SubViewer)
+
 AVCodec ff_subviewer_decoder = {
 .name   = "subviewer",
 .long_name  = NULL_IF_CONFIG_SMALL("SubViewer subtitle"),
 .type   = AVMEDIA_TYPE_SUBTITLE,
 .id = AV_CODEC_ID_SUBVIEWER,
 .decode = subviewer_decode_frame,
-.init   = ff_ass_subtitle_header_default,
+.init   = ff_ass_subtitle_header_options,
 .flush  = ff_ass_decoder_flush,
 .priv_data_size = sizeof(FFASSDecoderContext),
+.priv_class = &subviewer_decoder_class,
 };
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 09/13] lavc/mpl2dec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/mpl2dec.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mpl2dec.c b/libavcodec/mpl2dec.c
index 409e4b3708..f426f3080b 100644
--- a/libavcodec/mpl2dec.c
+++ b/libavcodec/mpl2dec.c
@@ -81,13 +81,16 @@ static int mpl2_decode_frame(AVCodecContext *avctx, void 
*data,
 return avpkt->size;
 }
 
+ASS_GENERIC_CLASS(mpl2, MPL2)
+
 AVCodec ff_mpl2_decoder = {
 .name   = "mpl2",
 .long_name  = NULL_IF_CONFIG_SMALL("MPL2 subtitle"),
 .type   = AVMEDIA_TYPE_SUBTITLE,
 .id = AV_CODEC_ID_MPL2,
 .decode = mpl2_decode_frame,
-.init   = ff_ass_subtitle_header_default,
+.init   = ff_ass_subtitle_header_options,
 .flush  = ff_ass_decoder_flush,
 .priv_data_size = sizeof(FFASSDecoderContext),
+.priv_class = &mpl2_decoder_class,
 };
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 06/13] lavc/jacosubdec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/jacosubdec.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c
index cdb372af58..b0d8327b35 100644
--- a/libavcodec/jacosubdec.c
+++ b/libavcodec/jacosubdec.c
@@ -193,13 +193,16 @@ end:
 return avpkt->size;
 }
 
+ASS_GENERIC_CLASS(jacosub, JACOsub)
+
 AVCodec ff_jacosub_decoder = {
 .name   = "jacosub",
 .long_name  = NULL_IF_CONFIG_SMALL("JACOsub subtitle"),
 .type   = AVMEDIA_TYPE_SUBTITLE,
 .id = AV_CODEC_ID_JACOSUB,
-.init   = ff_ass_subtitle_header_default,
+.init   = ff_ass_subtitle_header_options,
 .decode = jacosub_decode_frame,
 .flush  = ff_ass_decoder_flush,
 .priv_data_size = sizeof(FFASSDecoderContext),
+.priv_class = &jacosub_decoder_class,
 };
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 13/13] lavc: bump micro version

2020-01-24 Thread rcombs
---
 libavcodec/version.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/version.h b/libavcodec/version.h
index 195e21bfbe..d11beb7885 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  52
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 12/13] lavc/libzvbi-teletextdec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/libzvbi-teletextdec.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c
index 3515f33924..018b350511 100644
--- a/libavcodec/libzvbi-teletextdec.c
+++ b/libavcodec/libzvbi-teletextdec.c
@@ -78,11 +78,14 @@ typedef struct TeletextContext
 int last_pgno;
 int last_p5;
 int last_ass_alignment;
+
+FFASSHeaderOptions common;
 } TeletextContext;
 
 static int my_ass_subtitle_header(AVCodecContext *avctx)
 {
-int ret = ff_ass_subtitle_header_default(avctx);
+TeletextContext *ctx = avctx->priv_data;
+int ret = ff_ass_subtitle_header_from_opts(avctx, &ctx->common);
 char *new_header;
 uint8_t *event_pos;
 
@@ -756,7 +759,7 @@ static int teletext_init_decoder(AVCodecContext *avctx)
 case 0:
 return 0;
 case 1:
-return ff_ass_subtitle_header_default(avctx);
+return ff_ass_subtitle_header_from_opts(avctx, &ctx->common);
 case 2:
 return my_ass_subtitle_header(avctx);
 }
@@ -803,6 +806,7 @@ static const AVOption options[] = {
 {"txt_duration","display duration of teletext pages in msecs",   
OFFSET(sub_duration),   AV_OPT_TYPE_INT,{.i64 = -1},  -1, 8640, SD},
 {"txt_transparent", "force transparent background of the teletext",  
OFFSET(transparent_bg), AV_OPT_TYPE_INT,{.i64 = 0},0, 1,SD},
 {"txt_opacity", "set opacity of the transparent background", 
OFFSET(opacity),AV_OPT_TYPE_INT,{.i64 = -1},  -1, 255,  SD},
+ASS_HEADER_AVOPTIONS(TeletextContext, common)
 { NULL },
 };
 
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 05/13] lavc/realtextdec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/realtextdec.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/realtextdec.c b/libavcodec/realtextdec.c
index 5084781123..e888946f13 100644
--- a/libavcodec/realtextdec.c
+++ b/libavcodec/realtextdec.c
@@ -74,13 +74,16 @@ static int realtext_decode_frame(AVCodecContext *avctx,
 return avpkt->size;
 }
 
+ASS_GENERIC_CLASS(realtext, RealText)
+
 AVCodec ff_realtext_decoder = {
 .name   = "realtext",
 .long_name  = NULL_IF_CONFIG_SMALL("RealText subtitle"),
 .type   = AVMEDIA_TYPE_SUBTITLE,
 .id = AV_CODEC_ID_REALTEXT,
 .decode = realtext_decode_frame,
-.init   = ff_ass_subtitle_header_default,
+.init   = ff_ass_subtitle_header_options,
 .flush  = ff_ass_decoder_flush,
 .priv_data_size = sizeof(FFASSDecoderContext),
+.priv_class = &realtext_decoder_class,
 };
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 08/13] lavc/samidec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/textdec.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/textdec.c b/libavcodec/textdec.c
index 964da72ad5..72eb7c4795 100644
--- a/libavcodec/textdec.c
+++ b/libavcodec/textdec.c
@@ -30,15 +30,17 @@
 
 typedef struct {
 AVClass *class;
+int readorder;
+FFASSHeaderOptions common;
 const char *linebreaks;
 int keep_ass_markup;
-int readorder;
 } TextContext;
 
 #define OFFSET(x) offsetof(TextContext, x)
 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
 { "keep_ass_markup", "Set if ASS tags must be escaped", 
OFFSET(keep_ass_markup), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags=SD },
+ASS_HEADER_AVOPTIONS(TextContext, common)
 { NULL }
 };
 
@@ -88,7 +90,7 @@ AVCodec ff_text_decoder = {
 .type   = AVMEDIA_TYPE_SUBTITLE,
 .id = AV_CODEC_ID_TEXT,
 .decode = text_decode_frame,
-.init   = ff_ass_subtitle_header_default,
+.init   = ff_ass_subtitle_header_options,
 .priv_class = &text_decoder_class,
 .flush  = text_flush,
 };
@@ -100,7 +102,7 @@ static int linebreak_init(AVCodecContext *avctx)
 {
 TextContext *text = avctx->priv_data;
 text->linebreaks = "|";
-return ff_ass_subtitle_header_default(avctx);
+return ff_ass_subtitle_header_from_opts(avctx, &text->common);
 }
 
 #if CONFIG_VPLAYER_DECODER
-- 
2.24.1

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

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

[FFmpeg-devel] [PATCH 10/13] lavc/movtextdec: add support for configuring default style via AVOptions

2020-01-24 Thread rcombs
---
 libavcodec/movtextdec.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index c38c5edce6..0bb03fc141 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -86,6 +86,9 @@ typedef struct {
 } TextWrapBox;
 
 typedef struct {
+AVClass *class;
+int readorder;
+FFASSHeaderOptions common;
 StyleBox **s;
 StyleBox *s_temp;
 HighlightBox h;
@@ -99,7 +102,6 @@ typedef struct {
 uint64_t tracksize;
 int size_var;
 int count_s, count_f;
-int readorder;
 } MovTextContext;
 
 typedef struct {
@@ -453,7 +455,7 @@ static int mov_text_init(AVCodecContext *avctx) {
 m->d.underline, ASS_DEFAULT_BORDERSTYLE,
 m->d.alignment);
 } else
-return ff_ass_subtitle_header_default(avctx);
+return ff_ass_subtitle_header_from_opts(avctx, &m->common);
 }
 
 static int mov_text_decode_frame(AVCodecContext *avctx,
@@ -567,6 +569,8 @@ static void mov_text_flush(AVCodecContext *avctx)
 m->readorder = 0;
 }
 
+ASS_GENERIC_CLASS(mov_text, "3GPP Timed Text")
+
 AVCodec ff_movtext_decoder = {
 .name = "mov_text",
 .long_name= NULL_IF_CONFIG_SMALL("3GPP Timed Text subtitle"),
@@ -577,4 +581,5 @@ AVCodec ff_movtext_decoder = {
 .decode   = mov_text_decode_frame,
 .close= mov_text_decode_close,
 .flush= mov_text_flush,
+.priv_class   = &mov_text_decoder_class,
 };
-- 
2.24.1

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

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

Re: [FFmpeg-devel] [PATCH] avformat/movenc: allow ISMV timescale to be user-set

2020-01-24 Thread Gyan



On 23-01-2020 05:56 pm, Gyan Doshi wrote:

As per the PIFF standard, the timescale of 1000
is recommended but not mandatory, so don't override
the user-set value.

A warning is shown for non-recommended values.
---
  libavformat/movenc.c | 14 ++
  1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index fb44ee2c71..5bf434c325 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6389,6 +6389,8 @@ static int mov_init(AVFormatContext *s)
  }
  if (mov->video_track_timescale) {
  track->timescale = mov->video_track_timescale;
+if (mov->mode == MODE_ISM && mov->video_track_timescale != 
1000)
+av_log(s, AV_LOG_WARNING, "Warning: some tools, like mp4split, 
assume a timescale of 1000 for ISMV.\n");
  } else {
  track->timescale = st->time_base.den;
  while(track->timescale < 1)
@@ -6486,10 +6488,14 @@ static int mov_init(AVFormatContext *s)
  }
  if (!track->height)
  track->height = st->codecpar->height;
-/* The ism specific timescale isn't mandatory, but is assumed by
- * some tools, such as mp4split. */
-if (mov->mode == MODE_ISM)
-track->timescale = 1000;
+/* The Protected Interoperable File Format (PIFF) standard, used by 
ISMV recommends but
+   doesn't mandate a track timescale of 10,000,000. The muxer allows a 
custom timescale
+   for video tracks, so if user-set, it isn't overwritten */
+if (mov->mode == MODE_ISM &&
+(st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ||
+(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && 
!mov->video_track_timescale))) {
+ track->timescale = 1000;
+}
  
  avpriv_set_pts_info(st, 64, 1, track->timescale);
  


Will push tonight.

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

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