[FFmpeg-cvslog] dnn_backend_native_layer_mathbinary: add floormod support

2020-08-23 Thread Mingyu Yin
ffmpeg | branch: master | Mingyu Yin  | Sun Aug 23 
23:12:13 2020 +0800| [3477feb6431c1d437acac7b845bb3427ef165d45] | committer: 
Guo, Yejun

dnn_backend_native_layer_mathbinary: add floormod support

Signed-off-by: Mingyu Yin 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3477feb6431c1d437acac7b845bb3427ef165d45
---

 libavfilter/dnn/dnn_backend_native_layer_mathbinary.c | 7 +++
 libavfilter/dnn/dnn_backend_native_layer_mathbinary.h | 1 +
 tests/dnn/dnn-layer-mathbinary-test.c | 5 +
 tools/python/convert_from_tensorflow.py   | 2 +-
 tools/python/convert_header.py| 2 +-
 5 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c 
b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
index 38742db7a6..7d81694288 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
+++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
@@ -50,6 +50,10 @@ static float minimum(float src0, float src1)
 {
 return FFMIN(src0, src1);
 }
+static float floormod(float src0, float src1)
+{
+return (float)((int)(src0) % (int)(src1));
+}
 
 static void math_binary_commutative(FunType pfun, const 
DnnLayerMathBinaryParams *params, const DnnOperand *input, DnnOperand *output, 
DnnOperand *operands, const int32_t *input_operand_indexes)
 {
@@ -178,6 +182,9 @@ int dnn_execute_layer_math_binary(DnnOperand *operands, 
const int32_t *input_ope
 case DMBO_MINIMUM:
 math_binary_commutative(minimum, params, input, output, operands, 
input_operand_indexes);
 return 0;
+case DMBO_FLOORMOD:
+math_binary_not_commutative(floormod, params, input, output, operands, 
input_operand_indexes);
+return 0;
 default:
 return -1;
 }
diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h 
b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h
index 0acf3b0ea0..9525685afa 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h
+++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h
@@ -36,6 +36,7 @@ typedef enum {
 DMBO_MUL = 2,
 DMBO_REALDIV = 3,
 DMBO_MINIMUM = 4,
+DMBO_FLOORMOD = 5,
 DMBO_COUNT
 } DNNMathBinaryOperation;
 
diff --git a/tests/dnn/dnn-layer-mathbinary-test.c 
b/tests/dnn/dnn-layer-mathbinary-test.c
index e7f8f8557c..5422b2a207 100644
--- a/tests/dnn/dnn-layer-mathbinary-test.c
+++ b/tests/dnn/dnn-layer-mathbinary-test.c
@@ -40,6 +40,8 @@ static float get_expected(float f1, float f2, 
DNNMathBinaryOperation op)
 return f1 / f2;
 case DMBO_MINIMUM:
 return (f1 < f2) ? f1 : f2;
+case DMBO_FLOORMOD:
+return (float)((int)(f1) % (int)(f2));
 default:
 av_assert0(!"not supported yet");
 return 0.f;
@@ -205,5 +207,8 @@ int main(int argc, char **argv)
 if (test(DMBO_MINIMUM))
 return 1;
 
+if (test(DMBO_FLOORMOD))
+return 1;
+
 return 0;
 }
diff --git a/tools/python/convert_from_tensorflow.py 
b/tools/python/convert_from_tensorflow.py
index 3c14bed487..1762091fdd 100644
--- a/tools/python/convert_from_tensorflow.py
+++ b/tools/python/convert_from_tensorflow.py
@@ -73,7 +73,7 @@ class TFConverter:
 self.conv2d_scopename_inputname_dict = {}
 self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3, 
'Maximum':4,
 'MathBinary':5, 'MathUnary':6, 'AvgPool':7}
-self.mathbin2code = {'Sub':0, 'Add':1, 'Mul':2, 'RealDiv':3, 
'Minimum':4}
+self.mathbin2code = {'Sub':0, 'Add':1, 'Mul':2, 'RealDiv':3, 
'Minimum':4, 'FloorMod':5}
 self.mathun2code  = {'Abs':0, 'Sin':1, 'Cos':2, 'Tan':3, 'Asin':4,
 'Acos':5, 'Atan':6, 'Sinh':7, 'Cosh':8, 'Tanh':9, 'Asinh':10,
 'Acosh':11, 'Atanh':12, 'Ceil':13, 'Floor':14, 'Round':15}
diff --git a/tools/python/convert_header.py b/tools/python/convert_header.py
index 747c8776eb..782a6341f9 100644
--- a/tools/python/convert_header.py
+++ b/tools/python/convert_header.py
@@ -23,4 +23,4 @@ str = 'FFMPEGDNNNATIVE'
 major = 1
 
 # increase minor when we don't have to re-convert the model file
-minor = 21
+minor = 22

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

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

[FFmpeg-cvslog] dnn_backend_native_layer_mathbinary: change to function pointer

2020-08-23 Thread Mingyu Yin
ffmpeg | branch: master | Mingyu Yin  | Sun Aug 23 
23:12:12 2020 +0800| [37ef1acedb27e037e394600272317fdafa448743] | committer: 
Guo, Yejun

dnn_backend_native_layer_mathbinary: change to function pointer

Signed-off-by: Mingyu Yin 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=37ef1acedb27e037e394600272317fdafa448743
---

 .../dnn/dnn_backend_native_layer_mathbinary.c  | 143 +++--
 1 file changed, 73 insertions(+), 70 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c 
b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
index dd42c329a9..38742db7a6 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
+++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
@@ -27,6 +27,74 @@
 #include "libavutil/avassert.h"
 #include "dnn_backend_native_layer_mathbinary.h"
 
+typedef float (*FunType)(float src0, float src1);
+FunType pfun;
+
+static float sub(float src0, float src1)
+{
+return src0 - src1;
+}
+static float add(float src0, float src1)
+{
+return src0 + src1;
+}
+static float mul(float src0, float src1)
+{
+return src0 * src1;
+}
+static float realdiv(float src0, float src1)
+{
+return src0 / src1;
+}
+static float minimum(float src0, float src1)
+{
+return FFMIN(src0, src1);
+}
+
+static void math_binary_commutative(FunType pfun, const 
DnnLayerMathBinaryParams *params, const DnnOperand *input, DnnOperand *output, 
DnnOperand *operands, const int32_t *input_operand_indexes)
+{
+int dims_count;
+const float *src;
+float *dst;
+dims_count = calculate_operand_dims_count(output);
+src = input->data;
+dst = output->data;
+if (params->input0_broadcast || params->input1_broadcast) {
+for (int i = 0; i < dims_count; ++i) {
+dst[i] = pfun(params->v, src[i]);
+}
+} else {
+const DnnOperand *input1 = [input_operand_indexes[1]];
+const float *src1 = input1->data;
+for (int i = 0; i < dims_count; ++i) {
+dst[i] = pfun(src[i], src1[i]);
+}
+}
+}
+static void math_binary_not_commutative(FunType pfun, const 
DnnLayerMathBinaryParams *params, const DnnOperand *input, DnnOperand *output, 
DnnOperand *operands, const int32_t *input_operand_indexes)
+{
+int dims_count;
+const float *src;
+float *dst;
+dims_count = calculate_operand_dims_count(output);
+src = input->data;
+dst = output->data;
+if (params->input0_broadcast) {
+for (int i = 0; i < dims_count; ++i) {
+dst[i] = pfun(params->v, src[i]);
+}
+} else if (params->input1_broadcast) {
+for (int i = 0; i < dims_count; ++i) {
+dst[i] = pfun(src[i], params->v);
+}
+} else {
+const DnnOperand *input1 = [input_operand_indexes[1]];
+const float *src1 = input1->data;
+for (int i = 0; i < dims_count; ++i) {
+dst[i] = pfun(src[i], src1[i]);
+}
+}
+}
 int dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, 
int file_size, int operands_num)
 {
 DnnLayerMathBinaryParams *params;
@@ -82,9 +150,6 @@ int dnn_execute_layer_math_binary(DnnOperand *operands, 
const int32_t *input_ope
 const DnnOperand *input = [input_operand_indexes[0]];
 DnnOperand *output = [output_operand_index];
 const DnnLayerMathBinaryParams *params = (const DnnLayerMathBinaryParams 
*)parameters;
-int dims_count;
-const float *src;
-float *dst;
 
 for (int i = 0; i < 4; ++i)
 output->dims[i] = input->dims[i];
@@ -97,83 +162,21 @@ int dnn_execute_layer_math_binary(DnnOperand *operands, 
const int32_t *input_ope
 if (!output->data)
 return DNN_ERROR;
 
-dims_count = calculate_operand_dims_count(output);
-src = input->data;
-dst = output->data;
-
 switch (params->bin_op) {
 case DMBO_SUB:
-if (params->input0_broadcast) {
-for (int i = 0; i < dims_count; ++i) {
-dst[i] = params->v - src[i];
-}
-} else if (params->input1_broadcast) {
-for (int i = 0; i < dims_count; ++i) {
-dst[i] = src[i] - params->v;
-}
-} else {
-const DnnOperand *input1 = [input_operand_indexes[1]];
-const float *src1 = input1->data;
-for (int i = 0; i < dims_count; ++i) {
-dst[i] = src[i] - src1[i];
-}
-}
+math_binary_not_commutative(sub, params, input, output, operands, 
input_operand_indexes);
 return 0;
 case DMBO_ADD:
-if (params->input0_broadcast || params->input1_broadcast) {
-for (int i = 0; i < dims_count; ++i) {
-dst[i] = params->v + src[i];
-}
-} else {
-const DnnOperand *input1 = [input_operand_indexes[1]];
-const float *src1 = input1->data;
-for (int i = 0; i < dims_count; ++i) {
-dst[i] = src[i] 

[FFmpeg-cvslog] avcodec/av1_parser: read frame properties directly from AV1RawFrameHeader

2020-08-23 Thread James Almer
ffmpeg | branch: master | James Almer  | Sun Aug 23 16:23:57 
2020 -0300| [c8716b5029693f2d02fd2bffe18867c677fa3630] | committer: James Almer

avcodec/av1_parser: read frame properties directly from AV1RawFrameHeader

Simplifies code

Reviewed-by: Mark Thompson 
Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c8716b5029693f2d02fd2bffe18867c677fa3630
---

 libavcodec/av1_parser.c | 28 ++--
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
index cd426a2b0f..1b9868d364 100644
--- a/libavcodec/av1_parser.c
+++ b/libavcodec/av1_parser.c
@@ -99,7 +99,6 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
 CodedBitstreamUnit *unit = >units[i];
 AV1RawOBU *obu = unit->content;
 AV1RawFrameHeader *frame;
-int frame_type;
 
 if (unit->type == AV1_OBU_FRAME)
 frame = >obu.frame.header;
@@ -111,30 +110,15 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
 if (obu->header.spatial_id > 0)
 continue;
 
-if (frame->show_existing_frame) {
-AV1ReferenceFrameState *ref = 
>ref[frame->frame_to_show_map_idx];
-
-if (!ref->valid) {
-av_log(avctx, AV_LOG_ERROR, "Invalid reference frame\n");
-goto end;
-}
-
-ctx->width  = ref->frame_width;
-ctx->height = ref->frame_height;
-frame_type  = ref->frame_type;
-
-ctx->key_frame = 0;
-} else if (!frame->show_frame) {
+if (!frame->show_frame)
 continue;
-} else {
-ctx->width  = av1->frame_width;
-ctx->height = av1->frame_height;
-frame_type  = frame->frame_type;
 
-ctx->key_frame = frame_type == AV1_FRAME_KEY;
-}
+ctx->width  = frame->frame_width_minus_1 + 1;
+ctx->height = frame->frame_height_minus_1 + 1;
+
+ctx->key_frame = frame->frame_type == AV1_FRAME_KEY && 
!frame->show_existing_frame;
 
-switch (frame_type) {
+switch (frame->frame_type) {
 case AV1_FRAME_KEY:
 case AV1_FRAME_INTRA_ONLY:
 ctx->pict_type = AV_PICTURE_TYPE_I;

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

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

[FFmpeg-cvslog] avcodec/cbs_av1: infer frame_type when parsing a show_existing_frame frame

2020-08-23 Thread James Almer
ffmpeg | branch: master | James Almer  | Sun Aug 23 16:23:56 
2020 -0300| [6c20207dceefa0452c65c719f0326cbc0177e827] | committer: James Almer

avcodec/cbs_av1: infer frame_type when parsing a show_existing_frame frame

Reviewed-by: Mark Thompson 
Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6c20207dceefa0452c65c719f0326cbc0177e827
---

 libavcodec/cbs_av1_syntax_template.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/cbs_av1_syntax_template.c 
b/libavcodec/cbs_av1_syntax_template.c
index dedd549572..28d9ab9817 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1299,6 +1299,7 @@ static int 
FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
 else
 infer(refresh_frame_flags, 0);
 
+infer(frame_type,frame->frame_type);
 infer(frame_width_minus_1,   frame->upscaled_width - 1);
 infer(frame_height_minus_1,  frame->frame_height - 1);
 infer(render_width_minus_1,  frame->render_width - 1);

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

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

[FFmpeg-cvslog] avcodec/cbs_av1: infer frame sizes when not coded in the bitstream

2020-08-23 Thread James Almer
ffmpeg | branch: master | James Almer  | Sun Aug 23 16:17:12 
2020 -0300| [f1e92ee36b5e6bda6bf748e802fcda64aa5bab20] | committer: James Almer

avcodec/cbs_av1: infer frame sizes when not coded in the bitstream

This makes them available for all frames within a Temporal Unit.

Reviewed-by: Mark Thompson 
Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f1e92ee36b5e6bda6bf748e802fcda64aa5bab20
---

 libavcodec/cbs_av1_syntax_template.c | 43 +++-
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/libavcodec/cbs_av1_syntax_template.c 
b/libavcodec/cbs_av1_syntax_template.c
index 3a832c3ca0..dedd549572 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -492,14 +492,14 @@ static int FUNC(frame_size)(CodedBitstreamContext *ctx, 
RWContext *rw,
 if (current->frame_size_override_flag) {
 fb(seq->frame_width_bits_minus_1 + 1,  frame_width_minus_1);
 fb(seq->frame_height_bits_minus_1 + 1, frame_height_minus_1);
-
-priv->frame_width  = current->frame_width_minus_1  + 1;
-priv->frame_height = current->frame_height_minus_1 + 1;
 } else {
-priv->frame_width  = seq->max_frame_width_minus_1  + 1;
-priv->frame_height = seq->max_frame_height_minus_1 + 1;
+infer(frame_width_minus_1,  seq->max_frame_width_minus_1);
+infer(frame_height_minus_1, seq->max_frame_height_minus_1);
 }
 
+priv->frame_width  = current->frame_width_minus_1  + 1;
+priv->frame_height = current->frame_height_minus_1 + 1;
+
 CHECK(FUNC(superres_params)(ctx, rw, current));
 
 return 0;
@@ -516,14 +516,14 @@ static int FUNC(render_size)(CodedBitstreamContext *ctx, 
RWContext *rw,
 if (current->render_and_frame_size_different) {
 fb(16, render_width_minus_1);
 fb(16, render_height_minus_1);
-
-priv->render_width  = current->render_width_minus_1  + 1;
-priv->render_height = current->render_height_minus_1 + 1;
 } else {
-priv->render_width  = priv->upscaled_width;
-priv->render_height = priv->frame_height;
+infer(render_width_minus_1,  current->frame_width_minus_1);
+infer(render_height_minus_1, current->frame_height_minus_1);
 }
 
+priv->render_width  = current->render_width_minus_1  + 1;
+priv->render_height = current->render_height_minus_1 + 1;
+
 return 0;
 }
 
@@ -547,6 +547,11 @@ static int 
FUNC(frame_size_with_refs)(CodedBitstreamContext *ctx, RWContext *rw,
 return AVERROR_INVALIDDATA;
 }
 
+infer(frame_width_minus_1,   ref->upscaled_width - 1);
+infer(frame_height_minus_1,  ref->frame_height - 1);
+infer(render_width_minus_1,  ref->render_width - 1);
+infer(render_height_minus_1, ref->render_height - 1);
+
 priv->upscaled_width = ref->upscaled_width;
 priv->frame_width= ref->frame_width;
 priv->frame_height   = ref->frame_height;
@@ -1273,6 +1278,13 @@ static int 
FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
 fb(3, frame_to_show_map_idx);
 frame = >ref[current->frame_to_show_map_idx];
 
+if (!frame->valid) {
+av_log(ctx->log_ctx, AV_LOG_ERROR, "Missing reference frame 
needed for "
+   "show_existing_frame (frame_to_show_map_idx = %d).\n",
+   current->frame_to_show_map_idx);
+return AVERROR_INVALIDDATA;
+}
+
 if (seq->decoder_model_info_present_flag &&
 !seq->timing_info.equal_picture_interval) {
 
fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1,
@@ -1287,6 +1299,17 @@ static int 
FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
 else
 infer(refresh_frame_flags, 0);
 
+infer(frame_width_minus_1,   frame->upscaled_width - 1);
+infer(frame_height_minus_1,  frame->frame_height - 1);
+infer(render_width_minus_1,  frame->render_width - 1);
+infer(render_height_minus_1, frame->render_height - 1);
+
+priv->upscaled_width = frame->upscaled_width;
+priv->frame_width= frame->frame_width;
+priv->frame_height   = frame->frame_height;
+priv->render_width   = frame->render_width;
+priv->render_height  = frame->render_height;
+
 return 0;
 }
 

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

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

[FFmpeg-cvslog] avfilter/vf_overlay: Fix double-free of AVFilterFormats on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 14:42:57 2020 +0200| [a86ee5fd79840dc4af3e3f5c90ff8ce19b9ae993] | 
committer: Andreas Rheinhardt

avfilter/vf_overlay: Fix double-free of AVFilterFormats on error

The query_formats function of the overlay filter tries to allocate
two lists (only one in a special case) of formats which on success
are attached to more permanent objects (AVFilterLinks) for storage
afterwards. If attaching a list to an AVFilterLink succeeds, it is
in turn owned by the AVFilterLink (or more exactly, the AVFilterLink
becomes one of the common owners of the list). Yet if attaching a list
to one of its links succeeds and an error happens lateron, both lists
were manually freed, whic is wrong if the list is already owned by one
or more links; these links' pointers to their lists will become dangling
and there will be a double-free/use-after-free when these links are
cleaned up automatically.

This commit fixes this by removing the custom freeing code; this will
temporarily add a leaking codepath (if attaching a list not already
owned by a link to a link fails, the list will leak), but this will
be fixed soon by making sure that an AVFilterFormats without owner will
be automatically freed when attaching it to an AVFilterLink fails.
Notice that at most one list leaks because a new list is only allocated
after the old list has been successfully attached to a link.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a86ee5fd79840dc4af3e3f5c90ff8ce19b9ae993
---

 libavfilter/vf_overlay.c | 84 +---
 1 file changed, 23 insertions(+), 61 deletions(-)

diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 79c654bb2d..5f6ca2b9e2 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -221,90 +221,52 @@ static int query_formats(AVFilterContext *ctx)
 AV_PIX_FMT_NONE
 };
 
-AVFilterFormats *main_formats = NULL;
-AVFilterFormats *overlay_formats = NULL;
+const enum AVPixelFormat *main_formats, *overlay_formats;
+AVFilterFormats *formats;
 int ret;
 
 switch (s->format) {
 case OVERLAY_FORMAT_YUV420:
-if (!(main_formats= ff_make_format_list(main_pix_fmts_yuv420)) ||
-!(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420))) 
{
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+main_formats= main_pix_fmts_yuv420;
+overlay_formats = overlay_pix_fmts_yuv420;
 break;
 case OVERLAY_FORMAT_YUV420P10:
-if (!(main_formats= ff_make_format_list(main_pix_fmts_yuv420p10)) 
||
-!(overlay_formats = 
ff_make_format_list(overlay_pix_fmts_yuv420p10))) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+main_formats= main_pix_fmts_yuv420p10;
+overlay_formats = overlay_pix_fmts_yuv420p10;
 break;
 case OVERLAY_FORMAT_YUV422:
-if (!(main_formats= ff_make_format_list(main_pix_fmts_yuv422)) ||
-!(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422))) 
{
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+main_formats= main_pix_fmts_yuv422;
+overlay_formats = overlay_pix_fmts_yuv422;
 break;
 case OVERLAY_FORMAT_YUV422P10:
-if (!(main_formats= ff_make_format_list(main_pix_fmts_yuv422p10)) 
||
-!(overlay_formats = 
ff_make_format_list(overlay_pix_fmts_yuv422p10))) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+main_formats= main_pix_fmts_yuv422p10;
+overlay_formats = overlay_pix_fmts_yuv422p10;
 break;
 case OVERLAY_FORMAT_YUV444:
-if (!(main_formats= ff_make_format_list(main_pix_fmts_yuv444)) ||
-!(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444))) 
{
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+main_formats= main_pix_fmts_yuv444;
+overlay_formats = overlay_pix_fmts_yuv444;
 break;
 case OVERLAY_FORMAT_RGB:
-if (!(main_formats= ff_make_format_list(main_pix_fmts_rgb)) ||
-!(overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb))) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+main_formats= main_pix_fmts_rgb;
+overlay_formats = overlay_pix_fmts_rgb;
 break;
 case OVERLAY_FORMAT_GBRP:
-if (!(main_formats= ff_make_format_list(main_pix_fmts_gbrp)) ||
-!(overlay_formats = ff_make_format_list(overlay_pix_fmts_gbrp))) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+main_formats= main_pix_fmts_gbrp;
+overlay_formats = overlay_pix_fmts_gbrp;
 break;
 case 

[FFmpeg-cvslog] avfilter/vf_vpp_qsv: Fix leak of AVFilterFormats on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 05:54:34 2020 +0200| [c4beb0783bd2470edbcc8da9e264c7fe1c10d7cc] | 
committer: Andreas Rheinhardt

avfilter/vf_vpp_qsv: Fix leak of AVFilterFormats on error

The vpp_qsv's query_formats function allocated two AVFilterFormats,
before storing them permanently. If storing the first of them fails,
the function simply returns and the second leaks. This has been fixed by
only allocating the second AVFilterFormats structure after the first one
has been successfully stored.

Fixes Coverity issue #1422231.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c4beb0783bd2470edbcc8da9e264c7fe1c10d7cc
---

 libavfilter/vf_vpp_qsv.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 3194295f5f..12023af2d7 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -489,7 +489,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*picref)
 static int query_formats(AVFilterContext *ctx)
 {
 int ret;
-AVFilterFormats *in_fmts, *out_fmts;
 static const enum AVPixelFormat in_pix_fmts[] = {
 AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_NV12,
@@ -505,16 +504,12 @@ static int query_formats(AVFilterContext *ctx)
 AV_PIX_FMT_NONE
 };
 
-in_fmts  = ff_make_format_list(in_pix_fmts);
-out_fmts = ff_make_format_list(out_pix_fmts);
-ret = ff_formats_ref(in_fmts, >inputs[0]->out_formats);
+ret = ff_formats_ref(ff_make_format_list(in_pix_fmts),
+ >inputs[0]->out_formats);
 if (ret < 0)
 return ret;
-ret = ff_formats_ref(out_fmts, >outputs[0]->in_formats);
-if (ret < 0)
-return ret;
-
-return 0;
+return ff_formats_ref(ff_make_format_list(out_pix_fmts),
+  >outputs[0]->in_formats);
 }
 
 static av_cold void vpp_uninit(AVFilterContext *ctx)

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

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

[FFmpeg-cvslog] avfilter/af_amix: Fix double-free of AVFilterChannelLayouts on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 17:31:11 2020 +0200| [44e376500fd0a5e6b9ca1611e645feeb50de1ac5] | 
committer: Andreas Rheinhardt

avfilter/af_amix: Fix double-free of AVFilterChannelLayouts on error

The query_formats function of the amix filter tries to allocate a list
of channel layouts which are attached to more permanent objects
(an AVFilter's links) for storage afterwards on success. If attaching
a list to a link succeeds, the link becomes one of the common owners
of the list. Yet if a list has been successfully attached to links (or if
there were no links to attach it to in which case
ff_set_common_channel_layouts() already frees the list) and an error
happens lateron, the list was manually freed, which is wrong, because
the list has either already been freed or it is owned by its links in
which case these links' pointers to their list will become dangling and
there will be double-frees/uses-after-free when these links are cleaned
up automatically.

This commit fixes this by removing the custom freeing code; this is made
possible by using the list in ff_set_common_channel_layouts() directly
after its allocation (without anything that can fail in between).

Notice that ff_set_common_channel_layouts() is buggy itself which can
lead to double-frees on error. This is not fixed in this commit.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=44e376500fd0a5e6b9ca1611e645feeb50de1ac5
---

 libavfilter/af_amix.c | 18 +++---
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index 6a4ef8d944..cae9d4585a 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -593,25 +593,13 @@ static int query_formats(AVFilterContext *ctx)
 AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBLP,
 AV_SAMPLE_FMT_NONE
 };
-AVFilterChannelLayouts *layouts;
 int ret;
 
-layouts = ff_all_channel_counts();
-if (!layouts) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
 if ((ret = ff_set_common_formats(ctx, ff_make_format_list(sample_fmts))) < 
0 ||
-(ret = ff_set_common_channel_layouts(ctx, layouts))  < 0 ||
 (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
-goto fail;
-return 0;
-fail:
-if (layouts)
-av_freep(>channel_layouts);
-av_freep();
-return ret;
+return ret;
+
+return ff_set_common_channel_layouts(ctx, ff_all_channel_counts());
 }
 
 static int process_command(AVFilterContext *ctx, const char *cmd, const char 
*args,

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

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

[FFmpeg-cvslog] avfilter/vf_remap: Fix double-free of AVFilterFormats on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 14:21:56 2020 +0200| [07240c36c2912cea96dd9d11c8e3ed27995a2b3c] | 
committer: Andreas Rheinhardt

avfilter/vf_remap: Fix double-free of AVFilterFormats on error

The query_formats function of the remap filter tries to allocate
two lists of formats which on success are attached to more permanent objects
(AVFilterLinks) for storage afterwards. If attaching a list to an
AVFilterLink succeeds, it is in turn owned by the AVFilterLink (or more
exactly, the AVFilterLink becomes one of the common owners of the list).
Yet if attaching a list to one of its links succeeds and an error happens
lateron, both lists were manually freed, which means that is wrong if the
list is already owned by one or more links; these links' pointers to
their lists will become dangling and there will be a double-free/use-after-
free when these links are cleaned up automatically.

This commit fixes this by removing the custom free code; this will
temporarily add a leaking codepath (if attaching a list not already
owned by a link to a link fails, the list will leak), but this will
be fixed soon by making sure that an AVFilterFormats without owner will
be automatically freed when attaching it to an AVFilterLink fails.
Notice at most one list leaks because a new list is only allocated
after the old list has been successfully attached to a link.

Reviewed-by: Nicolas George 
Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07240c36c2912cea96dd9d11c8e3ed27995a2b3c
---

 libavfilter/vf_remap.c | 24 +++-
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/libavfilter/vf_remap.c b/libavfilter/vf_remap.c
index 6d5d75225b..41a2409f21 100644
--- a/libavfilter/vf_remap.c
+++ b/libavfilter/vf_remap.c
@@ -115,25 +115,15 @@ static int query_formats(AVFilterContext *ctx)
 AVFilterFormats *pix_formats = NULL, *map_formats = NULL;
 int ret;
 
-if (!(pix_formats = ff_make_format_list(s->format ? gray_pix_fmts : 
pix_fmts)) ||
-!(map_formats = ff_make_format_list(map_fmts))) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+pix_formats = ff_make_format_list(s->format ? gray_pix_fmts : pix_fmts);
 if ((ret = ff_formats_ref(pix_formats, >inputs[0]->out_formats)) < 0 
||
-(ret = ff_formats_ref(map_formats, >inputs[1]->out_formats)) < 0 
||
-(ret = ff_formats_ref(map_formats, >inputs[2]->out_formats)) < 0 
||
 (ret = ff_formats_ref(pix_formats, >outputs[0]->in_formats)) < 0)
-goto fail;
-return 0;
-fail:
-if (pix_formats)
-av_freep(_formats->formats);
-av_freep(_formats);
-if (map_formats)
-av_freep(_formats->formats);
-av_freep(_formats);
-return ret;
+return ret;
+
+map_formats = ff_make_format_list(map_fmts);
+if ((ret = ff_formats_ref(map_formats, >inputs[1]->out_formats)) < 0)
+return ret;
+return ff_formats_ref(map_formats, >inputs[2]->out_formats);
 }
 
 /**

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

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

[FFmpeg-cvslog] avfilter/af_amix: Don't needlessly reallocate table

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 16:08:42 2020 +0200| [27f35fd121e38b28daafb4f1ad47cf55b5e5ab71] | 
committer: Andreas Rheinhardt

avfilter/af_amix: Don't needlessly reallocate table

Replace using ff_add_format() repeatedly by a single call to
ff_make_format_list(). (Right now this also fixes a memleak: If the
first ff_add_format() succeeds and a subsequent call fails, the list
leaks.)

Reviewed-by: Paul B Mahol 
Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=27f35fd121e38b28daafb4f1ad47cf55b5e5ab71
---

 libavfilter/af_amix.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index 0826fc118c..6a4ef8d944 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -588,7 +588,11 @@ static av_cold void uninit(AVFilterContext *ctx)
 
 static int query_formats(AVFilterContext *ctx)
 {
-AVFilterFormats *formats = NULL;
+static const enum AVSampleFormat sample_fmts[] = {
+AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
+AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBLP,
+AV_SAMPLE_FMT_NONE
+};
 AVFilterChannelLayouts *layouts;
 int ret;
 
@@ -598,11 +602,7 @@ static int query_formats(AVFilterContext *ctx)
 goto fail;
 }
 
-if ((ret = ff_add_format(, AV_SAMPLE_FMT_FLT ))  < 0 ||
-(ret = ff_add_format(, AV_SAMPLE_FMT_FLTP))  < 0 ||
-(ret = ff_add_format(, AV_SAMPLE_FMT_DBL ))  < 0 ||
-(ret = ff_add_format(, AV_SAMPLE_FMT_DBLP))  < 0 ||
-(ret = ff_set_common_formats(ctx, formats))  < 0 ||
+if ((ret = ff_set_common_formats(ctx, ff_make_format_list(sample_fmts))) < 
0 ||
 (ret = ff_set_common_channel_layouts(ctx, layouts))  < 0 ||
 (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
 goto fail;

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

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

[FFmpeg-cvslog] avfilter/af_aformat: Add uninit function

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug  9 16:42:37 2020 +0200| [a7bd37927628df3672488e07f718b3549bea717d] | 
committer: Andreas Rheinhardt

avfilter/af_aformat: Add uninit function

Fixes memleaks in case init fails (e.g. because of invalid parameters
like 'aformat=sample_fmts=s16:cl=wtf') or also if query_formats is never
called.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a7bd37927628df3672488e07f718b3549bea717d
---

 libavfilter/af_aformat.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
index 0ea470014c..e669f2de83 100644
--- a/libavfilter/af_aformat.c
+++ b/libavfilter/af_aformat.c
@@ -111,6 +111,15 @@ static av_cold int init(AVFilterContext *ctx)
 return 0;
 }
 
+static av_cold void uninit(AVFilterContext *ctx)
+{
+AFormatContext *s = ctx->priv;
+
+ff_formats_unref(>formats);
+ff_formats_unref(>sample_rates);
+ff_channel_layouts_unref(>channel_layouts);
+}
+
 static int query_formats(AVFilterContext *ctx)
 {
 AFormatContext *s = ctx->priv;
@@ -118,14 +127,18 @@ static int query_formats(AVFilterContext *ctx)
 
 ret = ff_set_common_formats(ctx, s->formats ? s->formats :
 
ff_all_formats(AVMEDIA_TYPE_AUDIO));
+s->formats = NULL;
 if (ret < 0)
 return ret;
 ret = ff_set_common_samplerates(ctx, s->sample_rates ? s->sample_rates :
  ff_all_samplerates());
+s->sample_rates = NULL;
 if (ret < 0)
 return ret;
-return ff_set_common_channel_layouts(ctx, s->channel_layouts ? 
s->channel_layouts :
+ret = ff_set_common_channel_layouts(ctx, s->channel_layouts ? 
s->channel_layouts :
 
ff_all_channel_counts());
+s->channel_layouts = NULL;
+return ret;
 }
 
 static const AVFilterPad avfilter_af_aformat_inputs[] = {
@@ -148,6 +161,7 @@ AVFilter ff_af_aformat = {
 .name  = "aformat",
 .description   = NULL_IF_CONFIG_SMALL("Convert the input audio to one of 
the specified formats."),
 .init  = init,
+.uninit= uninit,
 .query_formats = query_formats,
 .priv_size = sizeof(AFormatContext),
 .priv_class= _class,

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

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

[FFmpeg-cvslog] avfilter: Remove redundant ff_formats/channel_layouts_unref()

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 23:46:33 2020 +0200| [e013a71fe3cd8b544d1288a2ed80521fa35e44c1] | 
committer: Andreas Rheinhardt

avfilter: Remove redundant ff_formats/channel_layouts_unref()

ff_add_format() and ff_add_channel_layout() already unref the list upon
error.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e013a71fe3cd8b544d1288a2ed80521fa35e44c1
---

 libavfilter/af_aformat.c   | 9 -
 libavfilter/vf_shuffleplanes.c | 1 -
 libavfilter/vf_weave.c | 1 -
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
index 1a702778c3..0ea470014c 100644
--- a/libavfilter/af_aformat.c
+++ b/libavfilter/af_aformat.c
@@ -60,7 +60,7 @@ static const AVOption aformat_options[] = {
 
 AVFILTER_DEFINE_CLASS(aformat);
 
-#define PARSE_FORMATS(str, type, list, add_to_list, unref_fn, get_fmt, none, 
desc)\
+#define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc)\
 do {\
 char *next, *cur = str, sep;\
 int ret;\
@@ -83,7 +83,6 @@ do {  
  \
 return AVERROR(EINVAL); \
 }   \
 if ((ret = add_to_list(, fmt)) < 0) {  \
-unref_fn();\
 return ret; \
 }   \
 \
@@ -102,11 +101,11 @@ static av_cold int init(AVFilterContext *ctx)
 AFormatContext *s = ctx->priv;
 
 PARSE_FORMATS(s->formats_str, enum AVSampleFormat, s->formats,
-  ff_add_format, ff_formats_unref, av_get_sample_fmt, 
AV_SAMPLE_FMT_NONE, "sample format");
-PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format, 
ff_formats_unref,
+  ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, 
"sample format");
+PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
   get_sample_rate, 0, "sample rate");
 PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
-  ff_add_channel_layout, ff_channel_layouts_unref, 
av_get_channel_layout, 0,
+  ff_add_channel_layout, av_get_channel_layout, 0,
   "channel layout");
 
 return 0;
diff --git a/libavfilter/vf_shuffleplanes.c b/libavfilter/vf_shuffleplanes.c
index 6c718893ce..c5a376d50b 100644
--- a/libavfilter/vf_shuffleplanes.c
+++ b/libavfilter/vf_shuffleplanes.c
@@ -64,7 +64,6 @@ static int query_formats(AVFilterContext *ctx)
 if (i != 4)
 continue;
 if ((ret = ff_add_format(, fmt)) < 0) {
-ff_formats_unref();
 return ret;
 }
 }
diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
index 8951b09095..8d4eb3d5a4 100644
--- a/libavfilter/vf_weave.c
+++ b/libavfilter/vf_weave.c
@@ -60,7 +60,6 @@ static int query_formats(AVFilterContext *ctx)
 if (!(desc->flags & AV_PIX_FMT_FLAG_PAL) &&
 !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
 if ((ret = ff_add_format(, fmt)) < 0) {
-ff_formats_unref();
 return ret;
 }
 }

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

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

[FFmpeg-cvslog] avfilter/vf_hwdownload: Fix leak of formats list upon error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 23:40:43 2020 +0200| [257cd5fa389465032b2b222fff5ada9dfebeb4d0] | 
committer: Andreas Rheinhardt

avfilter/vf_hwdownload: Fix leak of formats list upon error

If adding the list of input formats to its AVFilterLink fails, the list
of output formats (which has not been attached to permanent storage yet)
leaks. This has been fixed by not creating the lists of in- and output
formats simultaneously. Instead creating said lists is relegated to
ff_formats_pixdesc_filter() (this also avoids the reallocations implicit
in using ff_add_format()) and the second list is only created after (and
if) the first list has been permanently attached to its AVFilterLink.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=257cd5fa389465032b2b222fff5ada9dfebeb4d0
---

 libavfilter/vf_hwdownload.c | 23 +--
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/libavfilter/vf_hwdownload.c b/libavfilter/vf_hwdownload.c
index 33af30cf40..faf2ea8c0e 100644
--- a/libavfilter/vf_hwdownload.c
+++ b/libavfilter/vf_hwdownload.c
@@ -37,26 +37,13 @@ typedef struct HWDownloadContext {
 
 static int hwdownload_query_formats(AVFilterContext *avctx)
 {
-AVFilterFormats  *infmts = NULL;
-AVFilterFormats *outfmts = NULL;
-const AVPixFmtDescriptor *desc;
+AVFilterFormats *fmts;
 int err;
 
-for (desc = av_pix_fmt_desc_next(NULL); desc;
- desc = av_pix_fmt_desc_next(desc)) {
-if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
-err = ff_add_format(,  av_pix_fmt_desc_get_id(desc));
-else
-err = ff_add_format(, av_pix_fmt_desc_get_id(desc));
-if (err) {
-ff_formats_unref();
-ff_formats_unref();
-return err;
-}
-}
-
-if ((err = ff_formats_ref(infmts,  >inputs[0]->out_formats)) < 0 ||
-(err = ff_formats_ref(outfmts, >outputs[0]->in_formats)) < 0)
+if ((err = ff_formats_pixdesc_filter(, AV_PIX_FMT_FLAG_HWACCEL, 0)) ||
+(err = ff_formats_ref(fmts, >inputs[0]->out_formats)) ||
+(err = ff_formats_pixdesc_filter(, 0, AV_PIX_FMT_FLAG_HWACCEL)) ||
+(err = ff_formats_ref(fmts, >outputs[0]->in_formats)))
 return err;
 
 return 0;

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

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

[FFmpeg-cvslog] avfilter/formats: Fix double frees and memleaks on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 19:43:20 2020 +0200| [2a471af50aab02e8bb062c84a5779c7de1952fc0] | 
committer: Andreas Rheinhardt

avfilter/formats: Fix double frees and memleaks on error

The formats API deals with lists of channel layouts, sample rates,
pixel formats and sample formats. These lists are refcounted in a way in
which the list structure itself contains pointers to all of its owners.
Furthermore, it is possible for a list to be not owned by anyone yet;
this status is temporary until the list has been attached to an owner.
Adding an owner to a list involves reallocating the list's list of
owners and can therefore fail.

In order to reduce the amount of checks and cleanup code for the users
of this API, the API is supposed to be lenient when faced with input
lists that are NULL and it is supposed to clean up if adding an owner
to a list fails, so that a simple use case like

list = ff_make_format_list(foo_fmts);
if ((ret = ff_formats_ref(list, >inputs[0]->out_formats)) < 0)
return ret;

needn't check whether list could be successfully allocated
(ff_formats_ref() return AVERROR(ENOMEM) if it couldn't) and it also
needn't free list if ff_formats_ref() couldn't add an owner for it.

But the cleaning up after itself was broken. The root cause was that
the refcount was decremented during unreferencing whether or not the
element to be unreferenced was actually an owner of the list or not.
This means that if the above sample code is continued by

if ((ret = ff_formats_ref(list, >inputs[1]->out_formats)) < 0)
return ret;

and that if an error happens at the second ff_formats_ref() call, the
automatic cleaning of list will decrement the refcount from 1 (the sole
owner of list at this moment is ctx->input[0]->out_formats) to 0 and so
the list will be freed; yet ctx->input[0]->out_formats still points to
the list and this will lead to a double free/use-after-free when
ctx->input[0] is freed later.

Presumably in order to work around such an issue, commit
93afb338a405eac0f9e7b092bc26603378bfcca6 restricted unreferencing to
lists with owners. This does not solve the root cause (the above example
is not fixed by this) at all, but it solves some crashs.

This commit fixes the API: The list's refcount is only decremented if
an owner is removed from the list of owners and not if the
unref-function is called with a pointer that is not among the owners of
the list. Furtermore, the requirement for the list to have owners is
dropped.

This implies that if the first call to ff_formats_ref() in the above
example fails, the refcount which is initially zero during unreferencing
is not modified, so that the list will be freed automatically in said
call to ff_formats_ref() as every list whose refcount reaches zero is.

If on the other hand, the second call to ff_formats_ref() is the first
to fail, the refcount would stay at one during the automatic
unreferencing in ff_formats_ref(). The list would later be freed when
its last (and in this case sole) owner (namely
ctx->inputs[0]->out_formats) gets unreferenced.

The issues described here for ff_formats_ref() also affected the other
functions of this API. E.g. ff_add_format() failed to clean up after
itself if adding an entry to an already existing list failed (the case
of a freshly allocated list was handled specially and this commit also
removes said code). E.g. ff_all_formats() inherited the flaw.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2a471af50aab02e8bb062c84a5779c7de1952fc0
---

 libavfilter/formats.c | 32 ++--
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index d2edf832e9..7410a306f2 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -314,7 +314,6 @@ AVFilterChannelLayouts *avfilter_make_format64_list(const 
int64_t *fmts)
 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)\
 do {\
 type *fmts; \
-void *oldf = *f;\
 \
 if (!(*f) && !(*f = av_mallocz(sizeof(**f { \
 return AVERROR(ENOMEM); \
@@ -324,8 +323,6 @@ do {
\
 sizeof(*(*f)->list));   \
 if (!fmts) {\
 unref_fn(f);\
-if (!oldf)  \
-av_freep(f);\
 return AVERROR(ENOMEM); \
 }   \
 \
@@ 

[FFmpeg-cvslog] avfilter/vf_alphamerge: Fix double-free of AVFilterFormats on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 15:04:41 2020 +0200| [fd1a2a54a478462212b25753e7106c13af1e33c6] | 
committer: Andreas Rheinhardt

avfilter/vf_alphamerge: Fix double-free of AVFilterFormats on error

The query_formats function of the alphamerge filter tries to allocate
two lists of formats which on success are attached to more permanent
objects (AVFilterLinks) for storage afterwards. If attaching a list
to an AVFilterLink succeeds, the link becomes one of the owners of
the list. Yet if attaching a list to one of its links succeeds and
an error happens lateron, both lists were manually freed, which is wrong
if the list is already owned by one or more links; these links' pointers
to their lists will become dangling and there will be a double-free/use-
after-free when these links are cleaned up automatically.

This commit fixes this by removing the custom freeing code; this will
temporarily add a leaking codepath (if attaching a list not already
owned by a link to a link fails, the list will leak), but this will
be fixed soon by making sure that an AVFilterFormats without owner will
be automatically freed when attaching it to an AVFilterLink fails.
At most one list leaks because as of this commit a new list is only
allocated after the old list has been successfully attached to a link.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fd1a2a54a478462212b25753e7106c13af1e33c6
---

 libavfilter/vf_alphamerge.c | 26 +++---
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_alphamerge.c b/libavfilter/vf_alphamerge.c
index 85b6d9b61a..a509f10103 100644
--- a/libavfilter/vf_alphamerge.c
+++ b/libavfilter/vf_alphamerge.c
@@ -55,27 +55,15 @@ static int query_formats(AVFilterContext *ctx)
 AV_PIX_FMT_NONE
 };
 static const enum AVPixelFormat alpha_fmts[] = { AV_PIX_FMT_GRAY8, 
AV_PIX_FMT_NONE };
-AVFilterFormats *main_formats = NULL, *alpha_formats = NULL;
+AVFilterFormats *main_formats = ff_make_format_list(main_fmts);
 int ret;
 
-if (!(main_formats = ff_make_format_list(main_fmts)) ||
-!(alpha_formats = ff_make_format_list(alpha_fmts))) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-if ((ret = ff_formats_ref(main_formats , >inputs[0]->out_formats)) < 
0 ||
-(ret = ff_formats_ref(alpha_formats, >inputs[1]->out_formats)) < 
0 ||
-(ret = ff_formats_ref(main_formats , >outputs[0]->in_formats)) < 
0)
-goto fail;
-return 0;
-fail:
-if (main_formats)
-av_freep(_formats->formats);
-av_freep(_formats);
-if (alpha_formats)
-av_freep(_formats->formats);
-av_freep(_formats);
-return ret;
+if ((ret = ff_formats_ref(main_formats, >inputs[0]->out_formats)) < 0 
||
+(ret = ff_formats_ref(main_formats, >outputs[0]->in_formats)) < 0)
+return ret;
+
+return ff_formats_ref(ff_make_format_list(alpha_fmts),
+  >inputs[1]->out_formats);
 }
 
 static int config_input_main(AVFilterLink *inlink)

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

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

[FFmpeg-cvslog] avfilter/af_channelmap: Fix double-free of AVFilterChannelLayouts on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 18:54:18 2020 +0200| [44bcd6f74922ba490e680e79eae897b249c29d62] | 
committer: Andreas Rheinhardt

avfilter/af_channelmap: Fix double-free of AVFilterChannelLayouts on error

The query_formats function of the channelmap filter tries to allocate
a list of channel layouts which on success are attached to more permanent
objects (an AVFilterLink) for storage afterwards. If attaching succeeds,
the link becomes one of the common owners (in this case, the only owner)
of the list. Yet if the list has been successfully attached to the link
and an error happens lateron, the list was manually freed, which is wrong,
because it is owned by its link so that the link's pointer to the list will
become dangling and there will be a double-free/use-after-free when the link
is later cleaned up automatically.

This commit fixes this by removing the custom freeing code; this will
temporarily add a leaking codepath (if attaching the list fails, the list
will leak), but this will be fixed soon by making sure that an
AVFilterChannelLayouts without owner will be automatically freed when
attaching it to an AVFilterLink fails.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=44bcd6f74922ba490e680e79eae897b249c29d62
---

 libavfilter/af_channelmap.c | 24 +++-
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c
index 285d76a3ef..1f79f89ce3 100644
--- a/libavfilter/af_channelmap.c
+++ b/libavfilter/af_channelmap.c
@@ -280,28 +280,18 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
 static int channelmap_query_formats(AVFilterContext *ctx)
 {
 ChannelMapContext *s = ctx->priv;
-AVFilterChannelLayouts *layouts;
 AVFilterChannelLayouts *channel_layouts = NULL;
 int ret;
 
-layouts = ff_all_channel_counts();
-if (!layouts) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-if ((ret = ff_add_channel_layout (_layouts, s->output_layout   
 )) < 0 ||
-(ret = ff_set_common_formats (ctx , 
ff_planar_sample_fmts() )) < 0 ||
+if ((ret = ff_set_common_formats(ctx,  ff_planar_sample_fmts()))  < 0 
||
 (ret = ff_set_common_samplerates (ctx , 
ff_all_samplerates())) < 0 ||
-(ret = ff_channel_layouts_ref(layouts , 
>inputs[0]->out_channel_layouts)) < 0 ||
-(ret = ff_channel_layouts_ref(channel_layouts , 
>outputs[0]->in_channel_layouts)) < 0)
-goto fail;
+(ret = ff_add_channel_layout(_layouts, s->output_layout)) < 0 
||
+(ret = ff_channel_layouts_ref(channel_layouts,
+  >outputs[0]->in_channel_layouts)) < 
0)
+return ret;
 
-return 0;
-fail:
-if (layouts)
-av_freep(>channel_layouts);
-av_freep();
-return ret;
+return ff_channel_layouts_ref(ff_all_channel_counts(),
+  >inputs[0]->out_channel_layouts);
 }
 
 static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf)

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

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

[FFmpeg-cvslog] avfilter/vf_paletteuse: Fix leaks of AVFilterFormats on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 06:09:59 2020 +0200| [6a65449954d466e76c1166f524d2f6cde28c3c96] | 
committer: Andreas Rheinhardt

avfilter/vf_paletteuse: Fix leaks of AVFilterFormats on error

The paletteuse's query_formats function allocated three AVFilterFormats
before storing them permanently. If allocating one of them failed, the
three AVFilterFormats structures would be freed with av_freep() which
does not free separately allocated subelements (namely the formats
array) which leak.

Furthermore, if storing one of the first two fails, the function simply
returns and the ones not yet stored leak.

These leaks have been fixed by only creating a new AVFilterFormats after
the last one has already been permanently stored. Furthermore, it is
enough to check whether the elements have been properly stored as
ff_formats_ref() by design returns AVERROR(ENOMEM) if it is provided a
NULL AVFilterFormats *.

Fixes Coverity issues #1270818 and #1270819.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6a65449954d466e76c1166f524d2f6cde28c3c96
---

 libavfilter/vf_paletteuse.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c
index b32ff817d0..80e2ba583a 100644
--- a/libavfilter/vf_paletteuse.c
+++ b/libavfilter/vf_paletteuse.c
@@ -142,18 +142,12 @@ static int query_formats(AVFilterContext *ctx)
 static const enum AVPixelFormat inpal_fmts[] = {AV_PIX_FMT_RGB32, 
AV_PIX_FMT_NONE};
 static const enum AVPixelFormat out_fmts[]   = {AV_PIX_FMT_PAL8,  
AV_PIX_FMT_NONE};
 int ret;
-AVFilterFormats *in= ff_make_format_list(in_fmts);
-AVFilterFormats *inpal = ff_make_format_list(inpal_fmts);
-AVFilterFormats *out   = ff_make_format_list(out_fmts);
-if (!in || !inpal || !out) {
-av_freep();
-av_freep();
-av_freep();
-return AVERROR(ENOMEM);
-}
-if ((ret = ff_formats_ref(in   , >inputs[0]->out_formats)) < 0 ||
-(ret = ff_formats_ref(inpal, >inputs[1]->out_formats)) < 0 ||
-(ret = ff_formats_ref(out  , >outputs[0]->in_formats)) < 0)
+if ((ret = ff_formats_ref(ff_make_format_list(in_fmts),
+  >inputs[0]->out_formats)) < 0 ||
+(ret = ff_formats_ref(ff_make_format_list(inpal_fmts),
+  >inputs[1]->out_formats)) < 0 ||
+(ret = ff_formats_ref(ff_make_format_list(out_fmts),
+  >outputs[0]->in_formats)) < 0)
 return ret;
 return 0;
 }

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

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

[FFmpeg-cvslog] avfilter/vf_showpalette: Fix double-free of AVFilterFormats on error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Aug  7 13:23:30 2020 +0200| [76909c97c68c79d3c0353de83418a112595e9798] | 
committer: Andreas Rheinhardt

avfilter/vf_showpalette: Fix double-free of AVFilterFormats on error

The query_formats function of the showpalette filter tries to allocate
two lists of formats which on success are attached to more permanent objects
(AVFilterLinks) for storage afterwards. If attaching a list to an
AVFilterLink succeeds, the link becomes one (in this case the only one)
of the owners of the list. Yet if attaching the first list to its link
succeeds and attaching the second list fails, both lists were manually
freed, which means that the first link's pointer to the first list
becomes dangling and there will be a double-free when the first link is
cleaned up automatically.

This commit fixes this by removing the custom free code; this will
temporarily add a leaking codepath (if attaching a list to a link fails,
the list will leak), but this will be fixed shortly by making sure that
an AVFilterFormats without owner will be automatically freed when
attaching it to an AVFilterLink fails. Notice at most one list leaks
because as of this commit a new list is only allocated after the old list
has been successfully attached to a link.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=76909c97c68c79d3c0353de83418a112595e9798
---

 libavfilter/vf_showpalette.c | 25 ++---
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_showpalette.c b/libavfilter/vf_showpalette.c
index f715d6bc2c..c32dbd5b5d 100644
--- a/libavfilter/vf_showpalette.c
+++ b/libavfilter/vf_showpalette.c
@@ -46,26 +46,13 @@ static int query_formats(AVFilterContext *ctx)
 {
 static const enum AVPixelFormat in_fmts[]  = {AV_PIX_FMT_PAL8,  
AV_PIX_FMT_NONE};
 static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, 
AV_PIX_FMT_NONE};
-int ret;
-AVFilterFormats *in  = ff_make_format_list(in_fmts);
-AVFilterFormats *out = ff_make_format_list(out_fmts);
-if (!in || !out) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
+int ret = ff_formats_ref(ff_make_format_list(in_fmts),
+ >inputs[0]->out_formats);
+if (ret < 0)
+return ret;
 
-if ((ret = ff_formats_ref(in , >inputs[0]->out_formats)) < 0 ||
-(ret = ff_formats_ref(out, >outputs[0]->in_formats)) < 0)
-goto fail;
-return 0;
-fail:
-if (in)
-av_freep(>formats);
-av_freep();
-if (out)
-av_freep(>formats);
-av_freep();
-return ret;
+return ff_formats_ref(ff_make_format_list(out_fmts),
+  >outputs[0]->in_formats);
 }
 
 static int config_output(AVFilterLink *outlink)

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

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

[FFmpeg-cvslog] avfilter/avfiltergraph: Remove unused macro parameter

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug  9 15:21:25 2020 +0200| [eaa6c08f356d6b4ae2676b4eb813de1751100883] | 
committer: Andreas Rheinhardt

avfilter/avfiltergraph: Remove unused macro parameter

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=eaa6c08f356d6b4ae2676b4eb813de1751100883
---

 libavfilter/avfiltergraph.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 746708d95c..7f5798f6bf 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -687,7 +687,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink 
*ref)
 return 0;
 }
 
-#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format, 
unref_format) \
+#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
 do {   \
 for (i = 0; i < filter->nb_inputs; i++) {  \
 AVFilterLink *link = filter->inputs[i];\
@@ -729,9 +729,9 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
 int i, j, k, ret = 0;
 
 REDUCE_FORMATS(int,  AVFilterFormats,formats, formats,
-   nb_formats, ff_add_format, ff_formats_unref);
+   nb_formats, ff_add_format);
 REDUCE_FORMATS(int,  AVFilterFormats,samplerates, formats,
-   nb_formats, ff_add_format, ff_formats_unref);
+   nb_formats, ff_add_format);
 
 /* reduce channel layouts */
 for (i = 0; i < filter->nb_inputs; i++) {

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

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

[FFmpeg-cvslog] avfilter/graphparser: Don't set pointer to one beyond '\0' of string

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 23 00:31:17 2020 +0200| [f33faa5b9bfb288f83db034fa1f8719ab8a994c6] | 
committer: Andreas Rheinhardt

avfilter/graphparser: Don't set pointer to one beyond '\0' of string

This happened in parse_link_name() if there was a '[' without matching
']'. While this is not undefined behaviour (pointer arithmetic one
beyond the end of an array works fine as long as there are no accesses),
it is potentially dangerous. It currently isn't (all callers of
parse_link_name() treat this as an error and don't access the string any
more), but making sure that this will never cause trouble in the future
seems nevertheless worthwhile.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f33faa5b9bfb288f83db034fa1f8719ab8a994c6
---

 libavfilter/graphparser.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index dfb94788e1..e96b20418e 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -63,7 +63,7 @@ static char *parse_link_name(const char **buf, void *log_ctx)
 
 name = av_get_token(buf, "]");
 if (!name)
-goto fail;
+return NULL;
 
 if (!name[0]) {
 av_log(log_ctx, AV_LOG_ERROR,
@@ -71,12 +71,14 @@ static char *parse_link_name(const char **buf, void 
*log_ctx)
 goto fail;
 }
 
-if (*(*buf)++ != ']') {
+if (**buf != ']') {
 av_log(log_ctx, AV_LOG_ERROR,
"Mismatched '[' found in the following: \"%s\".\n", start);
 fail:
 av_freep();
+return NULL;
 }
+(*buf)++;
 
 return name;
 }

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

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

[FFmpeg-cvslog] avfilter/graphparser: Check allocations for success

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 23 01:51:22 2020 +0200| [95b8df687cc0182a4ec7666c2bbc2826c9ef0852] | 
committer: Andreas Rheinhardt

avfilter/graphparser: Check allocations for success

parse_filter() did not check the return value of av_get_token() for
success; in case name (the name of a filter) was NULL, one got a
segfault in av_strlcpy() (called from create_filter()).

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=95b8df687cc0182a4ec7666c2bbc2826c9ef0852
---

 libavfilter/graphparser.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index e96b20418e..a52916a146 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -186,9 +186,16 @@ static int parse_filter(AVFilterContext **filt_ctx, const 
char **buf, AVFilterGr
 char *name = av_get_token(buf, "=,;[");
 int ret;
 
+if (!name)
+return AVERROR(ENOMEM);
+
 if (**buf == '=') {
 (*buf)++;
 opts = av_get_token(buf, "[],;");
+if (!opts) {
+av_free(name);
+return AVERROR(ENOMEM);
+}
 }
 
 ret = create_filter(filt_ctx, graph, index, name, opts, log_ctx);

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

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

[FFmpeg-cvslog] avfilter/graphparser: Fix memleak when linking filters fails

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 23 11:12:30 2020 +0200| [deb6476fd8bc3a3c2b134704ecb804269843ed89] | 
committer: Andreas Rheinhardt

avfilter/graphparser: Fix memleak when linking filters fails

Parsing labeled outputs involves a check for an already known match
(a labeled input with the same name) to pair them together. If yes,
it is attempted to create a link between the two filters; in this case
the AVFilterInOuts have fulfilled their purpose and are freed. Yet if
creating the link fails, these AVFilterInOuts have up until now not been
freed, although they had already been removed from their respective lists
(which means that they are not freed automatically). In other words:
They leak. This commit fixes this.

This fixes ticket #7084. Said ticket contains an example program to
reproduce a leak. It can also be reproduced with ffmpeg alone, e.g. with
the complex filters "[0]null[1],[2]anull[0]" or with "[0]abitscope[0]".
All of these three examples involve media type mismatches which make it
impossible to create the links. The bug could also be triggered by other
means, e.g. failure to allocate the necessary AVFilterLink.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=deb6476fd8bc3a3c2b134704ecb804269843ed89
---

 libavfilter/graphparser.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index a52916a146..1385c3ae71 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -372,15 +372,14 @@ static int parse_outputs(const char **buf, AVFilterInOut 
**curr_inputs,
 match = extract_inout(name, open_inputs);
 
 if (match) {
-if ((ret = link_filter(input->filter_ctx, input->pad_idx,
-   match->filter_ctx, match->pad_idx, 
log_ctx)) < 0) {
-av_free(name);
-return ret;
-}
+ret = link_filter(input->filter_ctx, input->pad_idx,
+  match->filter_ctx, match->pad_idx, log_ctx);
 av_freep(>name);
 av_freep();
 av_freep();
 av_freep();
+if (ret < 0)
+return ret;
 } else {
 /* Not in the list, so add the first input as an open_output */
 input->name = name;

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

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

[FFmpeg-cvslog] fftools/ffmpeg: Fix leak of AVFilterInOut in case of error

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 23 03:49:48 2020 +0200| [426c16d61a9b5056a157a1a2a057a4e4d13eef84] | 
committer: Andreas Rheinhardt

fftools/ffmpeg: Fix leak of AVFilterInOut in case of error

The AVFilterInOuts normally get freed in init_output_filter() when
the corresponding streams get created; yet if an error happens before
one reaches said point, they leak. Therefore this commit makes
ffmpeg_cleanup free them, too.

Fixes ticket #8267.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=426c16d61a9b5056a157a1a2a057a4e4d13eef84
---

 fftools/ffmpeg.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 173ac3c9a0..84306818a2 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -528,6 +528,7 @@ static void ffmpeg_cleanup(int ret)
 for (j = 0; j < fg->nb_outputs; j++) {
 OutputFilter *ofilter = fg->outputs[j];
 
+avfilter_inout_free(>out_tmp);
 av_freep(>name);
 av_freep(>formats);
 av_freep(>channel_layouts);

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

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

[FFmpeg-cvslog] avfilter/graphparser: Fix leaks when parsing inputs fails

2020-08-23 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sat Aug 22 23:54:13 2020 +0200| [b3f6dee728c2741388638f8343379bf0f0ef5946] | 
committer: Andreas Rheinhardt

avfilter/graphparser: Fix leaks when parsing inputs fails

parse_inputs() uses a temporary linked list to parse the labeled inputs
of a filter; said linked list owns its elements (and their names). On
success, the list of unlabeled inputs is appened to the end of the list
of labeled inputs and the new list is returned; yet on failures, nothing
frees the already existing elements of the temporary linked list, leading
to a leak.

This can be triggered by e.g. using '-vf [v][' in the FFmpeg
command-line tool.

This leak seems to exist since 4e781c25b7b1955d1a9a0b0771c3ce1acb0957bd.

Reviewed-by: Nicolas George 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b3f6dee728c2741388638f8343379bf0f0ef5946
---

 libavfilter/graphparser.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index d92b5360a6..dfb94788e1 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -303,8 +303,10 @@ static int parse_inputs(const char **buf, AVFilterInOut 
**curr_inputs,
 char *name = parse_link_name(buf, log_ctx);
 AVFilterInOut *match;
 
-if (!name)
+if (!name) {
+avfilter_inout_free(_inputs);
 return AVERROR(EINVAL);
+}
 
 /* First check if the label is not in the open_outputs list */
 match = extract_inout(name, open_outputs);
@@ -314,6 +316,7 @@ static int parse_inputs(const char **buf, AVFilterInOut 
**curr_inputs,
 } else {
 /* Not in the list, so add it as an input */
 if (!(match = av_mallocz(sizeof(AVFilterInOut {
+avfilter_inout_free(_inputs);
 av_free(name);
 return AVERROR(ENOMEM);
 }

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

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

[FFmpeg-cvslog] cbs_av1: Fix test for presence of buffer_removal_time element

2020-08-23 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Aug 23 17:06:06 
2020 +0100| [b567cb8d0b664775201d843ab985f49fefeb25d5] | committer: Mark 
Thompson

cbs_av1: Fix test for presence of buffer_removal_time element

The frame must be in both the spatial and temporal layers for the
operating point, not just one of them.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b567cb8d0b664775201d843ab985f49fefeb25d5
---

 libavcodec/cbs_av1_syntax_template.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/cbs_av1_syntax_template.c 
b/libavcodec/cbs_av1_syntax_template.c
index 240fa188e4..3a832c3ca0 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1388,7 +1388,7 @@ static int 
FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
 int in_temporal_layer = (op_pt_idc >>  priv->temporal_id   
 ) & 1;
 int in_spatial_layer  = (op_pt_idc >> (priv->spatial_id + 
8)) & 1;
 if (seq->operating_point_idc[i] == 0 ||
-in_temporal_layer || in_spatial_layer) {
+(in_temporal_layer && in_spatial_layer)) {
 
fbs(seq->decoder_model_info.buffer_removal_time_length_minus_1 + 1,
 buffer_removal_time[i], 1, i);
 }

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

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

[FFmpeg-cvslog] avcodec/v4l2_m2m_enc: reindent after previous commit

2020-08-23 Thread Andriy Gelman
ffmpeg | branch: master | Andriy Gelman  | Sun Aug 23 
13:34:01 2020 -0400| [58b8541330aa088d02df82962589357b6e5f8f28] | committer: 
Andriy Gelman

avcodec/v4l2_m2m_enc: reindent after previous commit

Signed-off-by: Andriy Gelman 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=58b8541330aa088d02df82962589357b6e5f8f28
---

 libavcodec/v4l2_m2m_enc.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 4230a415fd..f644b50133 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -296,12 +296,12 @@ static int v4l2_receive_packet(AVCodecContext *avctx, 
AVPacket *avpkt)
 goto dequeue;
 
 if (!frame->buf[0]) {
-ret = ff_encode_get_frame(avctx, frame);
-if (ret < 0 && ret != AVERROR_EOF)
-return ret;
+ret = ff_encode_get_frame(avctx, frame);
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;
 
-if (ret == AVERROR_EOF)
-frame = NULL;
+if (ret == AVERROR_EOF)
+frame = NULL;
 }
 
 ret = v4l2_send_frame(avctx, frame);

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

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

[FFmpeg-cvslog] avcodec/v4l2_m2m_enc: buffer frame if it cannot be enqueued

2020-08-23 Thread Andriy Gelman
ffmpeg | branch: master | Andriy Gelman  | Sun Aug 23 
13:33:37 2020 -0400| [8bc7f69cefbcbb265b41717608dc8436dc864a55] | committer: 
Andriy Gelman

avcodec/v4l2_m2m_enc: buffer frame if it cannot be enqueued

Currently if the frame buffers are full, the frame is unrefed and
dropped.  Instead buffer the frame so that it is enqueued in the
next v4l2_receive_packet() call.  The behavior was observed on
DragonBoard 410c.

Signed-off-by: Andriy Gelman 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8bc7f69cefbcbb265b41717608dc8436dc864a55
---

 libavcodec/v4l2_m2m.c | 1 +
 libavcodec/v4l2_m2m_enc.c | 8 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index 31600617fd..cdfd579810 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -329,6 +329,7 @@ static void v4l2_m2m_destroy_context(void *opaque, uint8_t 
*context)
 sem_destroy(>refsync);
 
 close(s->fd);
+av_frame_unref(s->frame);
 av_frame_free(>frame);
 av_packet_unref(>buf_pkt);
 
diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index af0ed1e306..4230a415fd 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -295,16 +295,20 @@ static int v4l2_receive_packet(AVCodecContext *avctx, 
AVPacket *avpkt)
 if (s->draining)
 goto dequeue;
 
+if (!frame->buf[0]) {
 ret = ff_encode_get_frame(avctx, frame);
 if (ret < 0 && ret != AVERROR_EOF)
 return ret;
 
 if (ret == AVERROR_EOF)
 frame = NULL;
+}
 
 ret = v4l2_send_frame(avctx, frame);
-av_frame_unref(frame);
-if (ret < 0)
+if (ret != AVERROR(EAGAIN))
+av_frame_unref(frame);
+
+if (ret < 0 && ret != AVERROR(EAGAIN))
 return ret;
 
 if (!output->streamon) {

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

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

[FFmpeg-cvslog] avcodec/cbs_av1: always store temporal_id and spatial_id in CodedBitstreamAV1Context

2020-08-23 Thread James Almer
ffmpeg | branch: master | James Almer  | Sun Aug 23 14:30:23 
2020 -0300| [994d2567f13c11422aeb6506b6afca42a900d620] | committer: James Almer

avcodec/cbs_av1: always store temporal_id and spatial_id in 
CodedBitstreamAV1Context

Also infer them when not coded in the bitstream.

Reviewed-by: jkqxz
Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=994d2567f13c11422aeb6506b6afca42a900d620
---

 libavcodec/cbs_av1.c | 6 --
 libavcodec/cbs_av1_syntax_template.c | 7 +++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 75e9cb78df..72ad18151e 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -920,9 +920,6 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
 start_pos = get_bits_count();
 
 if (obu->header.obu_extension_flag) {
-priv->temporal_id = obu->header.temporal_id;
-priv->spatial_id  = obu->header.spatial_id;
-
 if (obu->header.obu_type != AV1_OBU_SEQUENCE_HEADER &&
 obu->header.obu_type != AV1_OBU_TEMPORAL_DELIMITER &&
 priv->operating_point_idc) {
@@ -934,9 +931,6 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
 // Decoding will drop this OBU at this operating point.
 }
 }
-} else {
-priv->temporal_id = 0;
-priv->spatial_id  = 0;
 }
 
 switch (obu->header.obu_type) {
diff --git a/libavcodec/cbs_av1_syntax_template.c 
b/libavcodec/cbs_av1_syntax_template.c
index a315e8868a..240fa188e4 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -19,6 +19,7 @@
 static int FUNC(obu_header)(CodedBitstreamContext *ctx, RWContext *rw,
 AV1RawOBUHeader *current)
 {
+CodedBitstreamAV1Context *priv = ctx->priv_data;
 int err;
 
 HEADER("OBU header");
@@ -35,8 +36,14 @@ static int FUNC(obu_header)(CodedBitstreamContext *ctx, 
RWContext *rw,
 fb(3, temporal_id);
 fb(2, spatial_id);
 fc(3, extension_header_reserved_3bits, 0, 0);
+} else {
+infer(temporal_id, 0);
+infer(spatial_id, 0);
 }
 
+priv->temporal_id = current->temporal_id;
+priv->spatial_id  = current->spatial_id;
+
 return 0;
 }
 

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

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

[FFmpeg-cvslog] avfilter/af_afir: make use of vector_fmac_scalar() too

2020-08-23 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Aug 23 17:50:00 
2020 +0200| [e2589ac65010f86fc2e6c3b4419cb1dc62f82d1a] | committer: Paul B Mahol

avfilter/af_afir: make use of vector_fmac_scalar() too

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e2589ac65010f86fc2e6c3b4419cb1dc62f82d1a
---

 libavfilter/af_afir.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index 6cbc7a00a1..4e76bda4a3 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -64,6 +64,16 @@ static void direct(const float *in, const FFTComplex *ir, 
int len, float *out)
 out[n] += ir[m].re * in[n - m];
 }
 
+static void fir_fadd(AudioFIRContext *s, float *dst, const float *src, int 
nb_samples)
+{
+if ((nb_samples & 15) == 0 && nb_samples >= 16) {
+s->fdsp->vector_fmac_scalar(dst, src, 1.f, nb_samples);
+} else {
+for (int n = 0; n < nb_samples; n++)
+dst[n] += src[n];
+}
+}
+
 static int fir_quantum(AVFilterContext *ctx, AVFrame *out, int ch, int offset)
 {
 AudioFIRContext *s = ctx->priv;
@@ -93,9 +103,7 @@ static int fir_quantum(AVFilterContext *ctx, AVFrame *out, 
int ch, int offset)
 memmove(src, src + s->min_part_size, (seg->input_size - 
s->min_part_size) * sizeof(*src));
 
 dst += seg->output_offset[ch];
-for (n = 0; n < nb_samples; n++) {
-ptr[n] += dst[n];
-}
+fir_fadd(s, ptr, dst, nb_samples);
 continue;
 }
 
@@ -153,9 +161,7 @@ static int fir_quantum(AVFilterContext *ctx, AVFrame *out, 
int ch, int offset)
 av_rdft_calc(seg->irdft[ch], sum);
 
 buf = (float *)seg->buffer->extended_data[ch];
-for (n = 0; n < seg->part_size; n++) {
-buf[n] += sum[n];
-}
+fir_fadd(s, buf, sum, seg->part_size);
 
 memcpy(dst, buf, seg->part_size * sizeof(*dst));
 
@@ -166,9 +172,7 @@ static int fir_quantum(AVFilterContext *ctx, AVFrame *out, 
int ch, int offset)
 
 memmove(src, src + s->min_part_size, (seg->input_size - 
s->min_part_size) * sizeof(*src));
 
-for (n = 0; n < nb_samples; n++) {
-ptr[n] += dst[n];
-}
+fir_fadd(s, ptr, dst, nb_samples);
 }
 
 if (s->min_part_size >= 8) {

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

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

[FFmpeg-cvslog] avcodec/cbs_av1: fix storage size for render_{width,height}_minus_1

2020-08-23 Thread James Almer
ffmpeg | branch: master | James Almer  | Sun Aug 23 12:20:07 
2020 -0300| [751f2a27f7d2efe5091ef54d73e5428160a85578] | committer: James Almer

avcodec/cbs_av1: fix storage size for render_{width,height}_minus_1

Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=751f2a27f7d2efe5091ef54d73e5428160a85578
---

 libavcodec/cbs_av1.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index f5fed220a5..704a231209 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -158,8 +158,8 @@ typedef struct AV1RawFrameHeader {
 uint8_t  use_superres;
 uint8_t  coded_denom;
 uint8_t  render_and_frame_size_different;
-uint8_t  render_width_minus_1;
-uint8_t  render_height_minus_1;
+uint16_t render_width_minus_1;
+uint16_t render_height_minus_1;
 
 uint8_t found_ref[AV1_REFS_PER_FRAME];
 

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

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

[FFmpeg-cvslog] avcodec/notchlc: add initial alpha support

2020-08-23 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Aug 23 11:40:40 
2020 +0200| [1c3a3a4ec66f66306013d5038b13dabffcf9f5d9] | committer: Paul B Mahol

avcodec/notchlc: add initial alpha support

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1c3a3a4ec66f66306013d5038b13dabffcf9f5d9
---

 libavcodec/notchlc.c | 83 +---
 1 file changed, 73 insertions(+), 10 deletions(-)

diff --git a/libavcodec/notchlc.c b/libavcodec/notchlc.c
index 9e6534339f..f9e03fdded 100644
--- a/libavcodec/notchlc.c
+++ b/libavcodec/notchlc.c
@@ -51,7 +51,7 @@ typedef struct NotchLCContext {
 unsigned y_data_offset;
 unsigned uv_data_offset;
 unsigned y_data_size;
-unsigned uv_count_size;
+unsigned a_data_offset;
 unsigned uv_count_offset;
 unsigned a_count_size;
 unsigned data_end;
@@ -62,7 +62,7 @@ typedef struct NotchLCContext {
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
-avctx->pix_fmt = AV_PIX_FMT_YUV444P12;
+avctx->pix_fmt = AV_PIX_FMT_YUVA444P12;
 avctx->color_range = AVCOL_RANGE_JPEG;
 avctx->colorspace = AVCOL_SPC_RGB;
 avctx->color_primaries = AVCOL_PRI_BT709;
@@ -196,11 +196,11 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame 
*p, ThreadFrame *frame,
 if (s->y_data_size >= UINT_MAX / 4)
 return AVERROR_INVALIDDATA;
 
-s->uv_count_size = bytestream2_get_le32(gb);
-if (s->uv_count_size >= UINT_MAX / 4)
+s->a_data_offset = bytestream2_get_le32(gb);
+if (s->a_data_offset >= UINT_MAX / 4)
 return AVERROR_INVALIDDATA;
-s->uv_count_size *= 4;
-if (s->uv_count_size >= uncompressed_size)
+s->a_data_offset *= 4;
+if (s->a_data_offset >= uncompressed_size)
 return AVERROR_INVALIDDATA;
 
 s->a_count_size = bytestream2_get_le32(gb);
@@ -218,9 +218,9 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame *p, 
ThreadFrame *frame,
 if (s->data_end <= s->y_data_size)
 return AVERROR_INVALIDDATA;
 s->y_data_offset = s->data_end - s->y_data_size;
-if (s->y_data_offset <= s->uv_count_size)
+if (s->y_data_offset <= s->a_data_offset)
 return AVERROR_INVALIDDATA;
-s->uv_count_offset = s->y_data_offset - s->uv_count_size;
+s->uv_count_offset = s->y_data_offset - s->a_data_offset;
 
 if ((ret = ff_thread_get_buffer(avctx, frame, 0)) < 0)
 return ret;
@@ -266,13 +266,76 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame 
*p, ThreadFrame *frame,
 }
 
 dsty += 4 * ylinesize;
-dsta += 4 * alinesize;
 }
 
 rgb = *gb;
 dgb = *gb;
-bytestream2_seek(, s->uv_offset_data_offset, SEEK_SET);
 bytestream2_seek(gb, s->a_control_word_offset, SEEK_SET);
+if (s->uv_count_offset == s->a_control_word_offset) {
+for (int y = 0; y < avctx->height; y++) {
+for (int x = 0; x < avctx->width; x++)
+dsta[x] = 4095;
+dsta += alinesize;
+}
+} else {
+for (int y = 0; y < avctx->height; y += 16) {
+for (int x = 0; x < avctx->width; x += 16) {
+unsigned m = bytestream2_get_le32(gb);
+unsigned offset = bytestream2_get_le32(gb);
+unsigned alpha0, alpha1;
+uint64_t control;
+
+if (offset >= UINT_MAX / 4)
+return AVERROR_INVALIDDATA;
+offset = offset * 4 + s->uv_data_offset + s->a_data_offset;
+if (offset >= s->data_end)
+return AVERROR_INVALIDDATA;
+
+bytestream2_seek(, offset, SEEK_SET);
+control = bytestream2_get_le64();
+alpha0 = control & 0xFF;
+alpha1 = (control >> 8) & 0xFF;
+control = control >> 16;
+
+for (int by = 0; by < 4; by++) {
+for (int bx = 0; bx < 4; bx++) {
+switch (m & 3) {
+case 0:
+for (int i = 0; i < 4; i++) {
+for (int j = 0; j < 4; j++) {
+dsta[x + (i + by * 4) * alinesize + bx * 4 
+ j] = 0;
+}
+}
+break;
+case 1:
+for (int i = 0; i < 4; i++) {
+for (int j = 0; j < 4; j++) {
+dsta[x + (i + by * 4) * alinesize + bx * 4 
+ j] = 4095;
+}
+}
+break;
+case 2:
+for (int i = 0; i < 4; i++) {
+for (int j = 0; j < 4; j++) {
+dsta[x + (i + by * 4) * alinesize + bx * 4 
+ j] = (alpha0 + (alpha1 - alpha0) * (control & 7)) << 4;
+}
+

[FFmpeg-cvslog] avcodec/gif: fix disposal method for first frame and transparent gifs

2020-08-23 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Aug 23 15:05:24 
2020 +0200| [568b7b2777231cc0be823f270a916f951dcbf0a8] | committer: Paul B Mahol

avcodec/gif: fix disposal method for first frame and transparent gifs

Fixes #7902

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=568b7b2777231cc0be823f270a916f951dcbf0a8
---

 libavcodec/gif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index e92dfa65d7..65a76cfde4 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -267,7 +267,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
 int bcid = -1, honor_transparency = (s->flags & GF_TRANSDIFF) && 
s->last_frame && !palette;
 const uint8_t *ptr;
 
-if (!s->image && avctx->frame_number && is_image_translucent(avctx, buf, 
linesize)) {
+if (!s->image && is_image_translucent(avctx, buf, linesize)) {
 gif_crop_translucent(avctx, buf, linesize, , , _start, 
_start);
 honor_transparency = 0;
 disposal = GCE_DISPOSAL_BACKGROUND;

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

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

[FFmpeg-cvslog] avfilter: remove useless cast

2020-08-23 Thread Zhao Zhili
ffmpeg | branch: master | Zhao Zhili  | Mon Oct 28 
00:02:36 2019 +0800| [26f81e5e83a015578c4c0c1d121a5e5f6c72bf8a] | committer: 
Andreas Rheinhardt

avfilter: remove useless cast

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=26f81e5e83a015578c4c0c1d121a5e5f6c72bf8a
---

 libavfilter/allfilters.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 3f70153986..fa91e608e4 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -528,7 +528,7 @@ const AVFilter *avfilter_get_by_name(const char *name)
 
 while ((f = av_filter_iterate()))
 if (!strcmp(f->name, name))
-return (AVFilter *)f;
+return f;
 
 return NULL;
 }

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

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