[FFmpeg-devel] Autotools full recompilation

2017-08-24 Thread Yan
High!

I'm using latest ffmpeg from this mirror (https://github.com/FFmpeg)

I was building it with different options:

./configure

./configure --libdir=$dev/FFmpeg/libavcodec/

./configure --enable-shared

./configure --enable-shared --enable-pic

And after each time the whole project got recompiled. I guess you cook
autotools wrong. (Personally I hate this build system cause it's ugly
and slw)


After all I still didn't manage to build shared libraries, I had to
build 4 files by myself, they needed fPIC option


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


[FFmpeg-devel] [PATCH] libavcodec/vp9: fix ref-frame size judging method

2019-04-29 Thread Yan Cen
From: Yan Cen 

There is no need all reference frame demension is valid in libvpx.

So this change contains three part:
1. Change each judgement's loglevel from "ERROR" to "WARNING"
2. Make sure at least one of frames that this frame references has valid 
dimension.
3. All judgements fail would report "ERROR".

Signed-off-by: Yan Cen
---
 libavcodec/vp9.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acf3ffc..8dd14e0 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -790,6 +790,7 @@ static int decode_frame_header(AVCodecContext *avctx,
 
 /* check reference frames */
 if (!s->s.h.keyframe && !s->s.h.intraonly) {
+int has_valid_ref_frame = 0;
 for (i = 0; i < 3; i++) {
 AVFrame *ref = s->s.refs[s->s.h.refidx[i]].f;
 int refw = ref->width, refh = ref->height;
@@ -802,12 +803,14 @@ static int decode_frame_header(AVCodecContext *avctx,
 return AVERROR_INVALIDDATA;
 } else if (refw == w && refh == h) {
 s->mvscale[i][0] = s->mvscale[i][1] = 0;
+has_valid_ref_frame = 1;
 } else {
-if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * 
refh) {
-av_log(avctx, AV_LOG_ERROR,
+int is_ref_frame_invalid = (w * 2 < refw || h * 2 < refh || w 
> 16 * refw || h > 16 * refh);
+has_valid_ref_frame |= !is_ref_frame_invalid;
+if (is_ref_frame_invalid) {
+av_log(avctx, AV_LOG_WARNING,
"Invalid ref frame dimensions %dx%d for frame size 
%dx%d\n",
refw, refh, w, h);
-return AVERROR_INVALIDDATA;
 }
 s->mvscale[i][0] = (refw << 14) / w;
 s->mvscale[i][1] = (refh << 14) / h;
@@ -815,6 +818,11 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
 }
 }
+if (!has_valid_ref_frame) {
+av_log(avctx, AV_LOG_ERROR,
+   "Referenced frame has invalid size\n");
+return AVERROR_INVALIDDATA;
+}
 }
 
 if (s->s.h.keyframe || s->s.h.errorres || (s->s.h.intraonly && 
s->s.h.resetctx == 3)) {
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v2] libavcodec/vp9: fix ref-frame size judging method

2019-05-19 Thread Yan Cen
From: yancen 

There is no need all reference frame demension is valid in libvpx.

So this change contains three part:
1. Change each judgement's loglevel from "ERROR" to "WARNING"
2. Make sure at least one of frames that this frame references has valid 
dimension.
3. All judgements fail would report "ERROR".

Signed-off-by: Xiang Haihao 
Signed-off-by: Li Zhong 
Signed-off-by: Yan Cen 
---
 libavcodec/vp9.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acf3ffc..849c1a6 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -790,6 +790,7 @@ static int decode_frame_header(AVCodecContext *avctx,
 
 /* check reference frames */
 if (!s->s.h.keyframe && !s->s.h.intraonly) {
+int has_valid_ref_frame = 0;
 for (i = 0; i < 3; i++) {
 AVFrame *ref = s->s.refs[s->s.h.refidx[i]].f;
 int refw = ref->width, refh = ref->height;
@@ -802,12 +803,15 @@ static int decode_frame_header(AVCodecContext *avctx,
 return AVERROR_INVALIDDATA;
 } else if (refw == w && refh == h) {
 s->mvscale[i][0] = s->mvscale[i][1] = 0;
+has_valid_ref_frame = 1;
 } else {
-if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * 
refh) {
-av_log(avctx, AV_LOG_ERROR,
+int is_ref_frame_invalid = (w * 2 < refw || h * 2 < refh || w 
> 16 * refw || h > 16 * refh);
+if (is_ref_frame_invalid) {
+av_log(avctx, AV_LOG_WARNING,
"Invalid ref frame dimensions %dx%d for frame size 
%dx%d\n",
refw, refh, w, h);
-return AVERROR_INVALIDDATA;
+} else {
+has_valid_ref_frame = 1;
 }
 s->mvscale[i][0] = (refw << 14) / w;
 s->mvscale[i][1] = (refh << 14) / h;
@@ -815,6 +819,11 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
 }
 }
+if (!has_valid_ref_frame) {
+av_log(avctx, AV_LOG_ERROR,
+   "Referenced frame has invalid size\n");
+return AVERROR_INVALIDDATA;
+}
 }
 
 if (s->s.h.keyframe || s->s.h.errorres || (s->s.h.intraonly && 
s->s.h.resetctx == 3)) {
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH] libavcodec/vp9: Fix VP9 dynamic resolution changing decoding on VAAPI.

2019-05-27 Thread Yan Wang
When the format change, the VAAPI context cannot be destroyed.
Otherwise, the reference frame surface will lost.

Signed-off-by: Yan Wang 
---
 libavcodec/decode.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6c31166ec2..3eda1dc42c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1397,7 +1397,9 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)
 
 for (;;) {
 // Remove the previous hwaccel, if there was one.
+#if !CONFIG_VP9_VAAPI_HWACCEL
 hwaccel_uninit(avctx);
+#endif
 
 user_choice = avctx->get_format(avctx, choices);
 if (user_choice == AV_PIX_FMT_NONE) {
@@ -1479,7 +1481,11 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)
"missing configuration.\n", desc->name);
 goto try_again;
 }
+#if CONFIG_VP9_VAAPI_HWACCEL
+if (hw_config->hwaccel && !avctx->hwaccel) {
+#else
 if (hw_config->hwaccel) {
+#endif
 av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
"initialisation.\n", desc->name);
 err = hwaccel_init(avctx, hw_config);
-- 
2.17.2

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

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

Re: [FFmpeg-devel] [PATCH] libavcodec/vp9: Fix VP9 dynamic resolution changing decoding on VAAPI.

2019-05-28 Thread Yan Wang


On 5/28/2019 3:16 PM, Hendrik Leppkes wrote:

On Tue, May 28, 2019 at 8:57 AM Yan Wang  wrote:

When the format change, the VAAPI context cannot be destroyed.
Otherwise, the reference frame surface will lost.

Signed-off-by: Yan Wang 
---
  libavcodec/decode.c | 6 ++
  1 file changed, 6 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6c31166ec2..3eda1dc42c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1397,7 +1397,9 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)

  for (;;) {
  // Remove the previous hwaccel, if there was one.
+#if !CONFIG_VP9_VAAPI_HWACCEL
  hwaccel_uninit(avctx);
+#endif

  user_choice = avctx->get_format(avctx, choices);
  if (user_choice == AV_PIX_FMT_NONE) {
@@ -1479,7 +1481,11 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)
 "missing configuration.\n", desc->name);
  goto try_again;
  }
+#if CONFIG_VP9_VAAPI_HWACCEL
+if (hw_config->hwaccel && !avctx->hwaccel) {
+#else
  if (hw_config->hwaccel) {
+#endif
  av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
 "initialisation.\n", desc->name);
  err = hwaccel_init(avctx, hw_config);
--
2.17.2


This change feels just wrong. First of all, preprocessors are
absolutely the wrong way to go about this.


Sorry for this. I am new guy for ffmpeg development. What way should be

better? I can refine it.


Secondly, if the frames need to change size, or surface format, then
this absolutely needs to be called, doesn't it?


Based on VP9 spec, the frame resolution can be changed per frame. But 
current


frame will need refer to previous frame still. So if destroy the VAAPI 
context, it


will cause reference frame surface in VAAPI driver lost.

In fact, this patch is for the issue:

https://github.com/intel/media-driver/issues/629

its 2nd frame (128x128) will refer to the 1st frame (256x256).

Thanks.

Yan Wang



- Hendrik
___
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] libavcodec/vp9: Fix VP9 dynamic resolution changing decoding on VAAPI.

2019-05-28 Thread Yan Wang


On 5/28/2019 4:43 PM, Hendrik Leppkes wrote:

On Tue, May 28, 2019 at 9:46 AM Yan Wang  wrote:


On 5/28/2019 3:16 PM, Hendrik Leppkes wrote:

On Tue, May 28, 2019 at 8:57 AM Yan Wang  wrote:

When the format change, the VAAPI context cannot be destroyed.
Otherwise, the reference frame surface will lost.

Signed-off-by: Yan Wang 
---
   libavcodec/decode.c | 6 ++
   1 file changed, 6 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6c31166ec2..3eda1dc42c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1397,7 +1397,9 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)

   for (;;) {
   // Remove the previous hwaccel, if there was one.
+#if !CONFIG_VP9_VAAPI_HWACCEL
   hwaccel_uninit(avctx);
+#endif

   user_choice = avctx->get_format(avctx, choices);
   if (user_choice == AV_PIX_FMT_NONE) {
@@ -1479,7 +1481,11 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)
  "missing configuration.\n", desc->name);
   goto try_again;
   }
+#if CONFIG_VP9_VAAPI_HWACCEL
+if (hw_config->hwaccel && !avctx->hwaccel) {
+#else
   if (hw_config->hwaccel) {
+#endif
   av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
  "initialisation.\n", desc->name);
   err = hwaccel_init(avctx, hw_config);
--
2.17.2


This change feels just wrong. First of all, preprocessors are
absolutely the wrong way to go about this.

Sorry for this. I am new guy for ffmpeg development. What way should be

better? I can refine it.


Secondly, if the frames need to change size, or surface format, then
this absolutely needs to be called, doesn't it?

Based on VP9 spec, the frame resolution can be changed per frame. But
current

frame will need refer to previous frame still. So if destroy the VAAPI
context, it

will cause reference frame surface in VAAPI driver lost.

In fact, this patch is for the issue:

https://github.com/intel/media-driver/issues/629

its 2nd frame (128x128) will refer to the 1st frame (256x256).


This may work if the frame size decreases, but what if it increases?
Then the frame buffers in the pool are too small, and anything could
go wrong.
This won't be an easy issue to solve, and needs very careful design.


Agree. I should add [RFC] for this patch.

I can investigate frame buffer management of ffmpeg and submit new patch 
for covering this situation.


Thanks for comments.

Yan Wang



- Hendrik
___
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] libavcodec/vp9: Fix VP9 dynamic resolution changing decoding on VAAPI.

2019-05-30 Thread Yan Wang


On 5/30/2019 7:39 AM, Mark Thompson wrote:

On 28/05/2019 08:46, Yan Wang wrote:

On 5/28/2019 3:16 PM, Hendrik Leppkes wrote:

On Tue, May 28, 2019 at 8:57 AM Yan Wang  wrote:

When the format change, the VAAPI context cannot be destroyed.
Otherwise, the reference frame surface will lost.

Signed-off-by: Yan Wang 
---
   libavcodec/decode.c | 6 ++
   1 file changed, 6 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6c31166ec2..3eda1dc42c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1397,7 +1397,9 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)

   for (;;) {
   // Remove the previous hwaccel, if there was one.
+#if !CONFIG_VP9_VAAPI_HWACCEL
   hwaccel_uninit(avctx);
+#endif

   user_choice = avctx->get_format(avctx, choices);
   if (user_choice == AV_PIX_FMT_NONE) {
@@ -1479,7 +1481,11 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)
  "missing configuration.\n", desc->name);
   goto try_again;
   }
+#if CONFIG_VP9_VAAPI_HWACCEL
+    if (hw_config->hwaccel && !avctx->hwaccel) {
+#else
   if (hw_config->hwaccel) {
+#endif
   av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
  "initialisation.\n", desc->name);
   err = hwaccel_init(avctx, hw_config);
--
2.17.2


This change feels just wrong. First of all, preprocessors are
absolutely the wrong way to go about this.

Sorry for this. I am new guy for ffmpeg development. What way should be

better? I can refine it.


Secondly, if the frames need to change size, or surface format, then
this absolutely needs to be called, doesn't it?

Based on VP9 spec, the frame resolution can be changed per frame. But current

frame will need refer to previous frame still. So if destroy the VAAPI context, 
it

will cause reference frame surface in VAAPI driver lost.

In fact, this patch is for the issue:

https://github.com/intel/media-driver/issues/629

its 2nd frame (128x128) will refer to the 1st frame (256x256).

Can you explain exactly what is going wrong here?  The surface is definitely 
still present - the reference frame list entry holds a reference to it.


IMHO,

for one VP9 clips with dynamic resolution changing which is legal based 
on VP9 spec.


After the 1st frame (256x256) is decoded with vaapi-hw acceleration, 
ffmpeg will parse and decode the frame header of the 2nd frame (128x128).


It will call update_size() when ffmpeg finds the resolution is changed 
and destroy/recreate vaapi-hw context which will also destroy and 
release the previous decoded 1st frame (256x256) saved in driver. The 
saved 1st frame surface should be as reference frame normally.


So when ffmpeg ask vaapi-hw to decode the 2nd frame, it cannot find the 
the 1st frame surface as reference frame and has to use dummy reference 
frame although the reference frame index is right.


I am newbie for ffmpeg code. I am studying ffmpeg related code and hope 
to compare libvpx path for looking for a better solution.


Thanks.

Yan Wang



- Mark
___
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] lavc/vaapi_decode: recreate hw_frames_ctx without destroy va_context

2019-07-07 Thread Yan Wang


On 7/7/2019 9:49 PM, Fu, Linjie wrote:

-Original Message-
From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
Of Mark Thompson
Sent: Sunday, July 7, 2019 19:51
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_decode: recreate
hw_frames_ctx without destroy va_context

On 07/07/2019 17:38, Linjie Fu wrote:

VP9 allows resolution changes per frame. Currently in VAAPI, resolution
changes leads to va context destroy and reinit.

Which is correct - it needs to remake the context because the old one is for
the wrong resolution.

It seems that we don't need to remake context, remaking the surface is enough
for resolution changing.
Currently in libva, surface is able to be recreated separately without remaking 
context.
And this way is used in libyami to cope with resolution changing cases.


 This will cause
reference frame surface lost and produce garbage.

This isn't right - the reference frame surfaces aren't lost.  See
VP9Context.s.refs[], which holds references to the frames (including their
hardware frame contexts) until the stream indicates that they can be
discarded by overwriting their reference frame slots.

I'm not quite sure about this, at least the result shows they are not used 
correctly
in current way.
Will look deeper into it.


In vaapi_vp9_start_frame() of libavcodec/vaapi_vp9.c, it only passes 
VASurfaceID into pic_param.reference_frames[i].


But when destroy va_context, the surface/render target based on this 
VASurfaceID has been destroyed.


So the new va_context cannot find the corresponding surface based on 
this surface ID.


IMHO, one possible solution is to create one the VA surfaces including 
VP9Context.s.refs[] data which is AVFrame in fact and pass them into 
libva when re-creating new va_context.


Thanks.

Yan Wang




As libva allows re-create surface separately without changing the
context, this issue could be handled by only recreating hw_frames_ctx.

Could be verified by:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -i
./resolutions.ivf
-pix_fmt p010le -f rawvideo -vframes 20 -y vaapi.yuv

Signed-off-by: Linjie Fu 
---
  libavcodec/decode.c   |  8 
  libavcodec/vaapi_decode.c | 40 ++

--

  2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0863b82..a81b857 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1254,7 +1254,6 @@ int

ff_decode_get_hw_frames_ctx(AVCodecContext *avctx,

  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;

-
  if (frames_ctx->initial_pool_size) {
  // We guarantee 4 base work surfaces. The function above guarantees

1

  // (the absolute minimum), so add the missing count.
@@ -1333,7 +1332,7 @@ static int hwaccel_init(AVCodecContext *avctx,
  return AVERROR_PATCHWELCOME;
  }

-if (hwaccel->priv_data_size) {
+if (hwaccel->priv_data_size && !avctx->internal->hwaccel_priv_data) {
  avctx->internal->hwaccel_priv_data =
  av_mallocz(hwaccel->priv_data_size);
  if (!avctx->internal->hwaccel_priv_data)
@@ -1397,8 +1396,9 @@ int ff_get_format(AVCodecContext *avctx, const

enum AVPixelFormat *fmt)

  for (;;) {
  // Remove the previous hwaccel, if there was one.
-hwaccel_uninit(avctx);
-
+// VAAPI allows reinit hw_frames_ctx only
+if (choices[0] != AV_PIX_FMT_VAAPI_VLD)

Including codec-specific conditions in the generic code suggests that
something very shady is going on.

Yes, will try to avoid this.


+hwaccel_uninit(avctx);>  user_choice = avctx-
get_format(avctx, choices);
  if (user_choice == AV_PIX_FMT_NONE) {
  // Explicitly chose nothing, give up.
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 69512e1..13f0cf0 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -613,8 +613,10 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
  VAStatus vas;
  int err;

-ctx->va_config  = VA_INVALID_ID;
-ctx->va_context = VA_INVALID_ID;
+if (!ctx->va_config && !ctx->va_context){
+ctx->va_config  = VA_INVALID_ID;
+ctx->va_context = VA_INVALID_ID;
+}

  #if FF_API_STRUCT_VAAPI_CONTEXT
  if (avctx->hwaccel_context) {
@@ -642,7 +644,6 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
  // present, so set it here to avoid the behaviour changing.
  ctx->hwctx->driver_quirks =
  AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS;
-
  }
  #endif

@@ -655,7 +656,8 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
 "context: %#x/%#x.\n", ctx->va_config, ctx->va_context);
  } else {
  #endif
-
+// Get a new hw_frames_ctx even 

Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_decode: recreate hw_frames_ctx without destroy va_context

2019-07-08 Thread Yan Wang


On 7/8/2019 2:45 PM, Yan Wang wrote:


On 7/7/2019 9:49 PM, Fu, Linjie wrote:

-Original Message-
From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
Of Mark Thompson
Sent: Sunday, July 7, 2019 19:51
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_decode: recreate
hw_frames_ctx without destroy va_context

On 07/07/2019 17:38, Linjie Fu wrote:
VP9 allows resolution changes per frame. Currently in VAAPI, 
resolution

changes leads to va context destroy and reinit.
Which is correct - it needs to remake the context because the old 
one is for

the wrong resolution.
It seems that we don't need to remake context, remaking the surface 
is enough

for resolution changing.
Currently in libva, surface is able to be recreated separately 
without remaking context.

And this way is used in libyami to cope with resolution changing cases.


This will cause
reference frame surface lost and produce garbage.

This isn't right - the reference frame surfaces aren't lost. See
VP9Context.s.refs[], which holds references to the frames (including 
their

hardware frame contexts) until the stream indicates that they can be
discarded by overwriting their reference frame slots.
I'm not quite sure about this, at least the result shows they are not 
used correctly

in current way.
Will look deeper into it.


In vaapi_vp9_start_frame() of libavcodec/vaapi_vp9.c, it only passes 
VASurfaceID into pic_param.reference_frames[i].


But when destroy va_context, the surface/render target based on this 
VASurfaceID has been destroyed.


Update: the surface isn't destroyed when destroy va_context. But every 
va_context maintains one independent map table: m_ddiDecodeCtx->RTtbl.


So the new context cannot find this surface in its map table.

My previous suggested solution should be available still.

Thanks.

Yan Wang



So the new va_context cannot find the corresponding surface based on 
this surface ID.


IMHO, one possible solution is to create one the VA surfaces including 
VP9Context.s.refs[] data which is AVFrame in fact and pass them into 
libva when re-creating new va_context.


Thanks.

Yan Wang




As libva allows re-create surface separately without changing the
context, this issue could be handled by only recreating hw_frames_ctx.

Could be verified by:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -i
./resolutions.ivf
-pix_fmt p010le -f rawvideo -vframes 20 -y vaapi.yuv

Signed-off-by: Linjie Fu 
---
  libavcodec/decode.c   |  8 
  libavcodec/vaapi_decode.c | 40 
++

--

  2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0863b82..a81b857 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1254,7 +1254,6 @@ int

ff_decode_get_hw_frames_ctx(AVCodecContext *avctx,

  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;

-
  if (frames_ctx->initial_pool_size) {
  // We guarantee 4 base work surfaces. The function above 
guarantees

1

  // (the absolute minimum), so add the missing count.
@@ -1333,7 +1332,7 @@ static int hwaccel_init(AVCodecContext *avctx,
  return AVERROR_PATCHWELCOME;
  }

-    if (hwaccel->priv_data_size) {
+    if (hwaccel->priv_data_size && 
!avctx->internal->hwaccel_priv_data) {

  avctx->internal->hwaccel_priv_data =
  av_mallocz(hwaccel->priv_data_size);
  if (!avctx->internal->hwaccel_priv_data)
@@ -1397,8 +1396,9 @@ int ff_get_format(AVCodecContext *avctx, const

enum AVPixelFormat *fmt)

  for (;;) {
  // Remove the previous hwaccel, if there was one.
-    hwaccel_uninit(avctx);
-
+    // VAAPI allows reinit hw_frames_ctx only
+    if (choices[0] != AV_PIX_FMT_VAAPI_VLD)

Including codec-specific conditions in the generic code suggests that
something very shady is going on.

Yes, will try to avoid this.


+ hwaccel_uninit(avctx);>  user_choice = avctx-
get_format(avctx, choices);
  if (user_choice == AV_PIX_FMT_NONE) {
  // Explicitly chose nothing, give up.
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 69512e1..13f0cf0 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -613,8 +613,10 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
  VAStatus vas;
  int err;

-    ctx->va_config  = VA_INVALID_ID;
-    ctx->va_context = VA_INVALID_ID;
+    if (!ctx->va_config && !ctx->va_context){
+    ctx->va_config  = VA_INVALID_ID;
+    ctx->va_context = VA_INVALID_ID;
+    }

  #if FF_API_STRUCT_VAAPI_CONTEXT
  if (avctx->hwaccel_context) {
@@ -642,7 +644,6 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
  // present, so set it here to avoid the behaviour changing.
  ctx->hwctx->driver_quirks =

[FFmpeg-devel] [PATCH v3] libavcodec/vp9: fix ref-frame size judging method

2019-07-08 Thread Yan Cen
From: yancen 

There is no need all reference frame demension is valid in libvpx.

So this change contains three part:
1. Change each judgement's loglevel from "ERROR" to "WARNING"
2. Make sure at least one of frames that this frame references has valid 
dimension.
3. All judgements fail would report "ERROR".

Signed-off-by: Xiang Haihao 
Signed-off-by: Li Zhong 
Signed-off-by: Yan Cen 
---
 libavcodec/vp9.c | 51 +++
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acf3ffc..58e7312 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -555,11 +555,37 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->s.h.signbias[1]= get_bits1(&s->gb) && !s->s.h.errorres;
 s->s.h.refidx[2]  = get_bits(&s->gb, 3);
 s->s.h.signbias[2]= get_bits1(&s->gb) && !s->s.h.errorres;
-if (!s->s.refs[s->s.h.refidx[0]].f->buf[0] ||
-!s->s.refs[s->s.h.refidx[1]].f->buf[0] ||
-!s->s.refs[s->s.h.refidx[2]].f->buf[0]) {
-av_log(avctx, AV_LOG_ERROR, "Not all references are 
available\n");
-return AVERROR_INVALIDDATA;
+if (0 == sizeof(s->s.refs[s->s.h.refidx[0]])) {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[1]].f->buf[0])) {
+if (0 == s->s.refs[s->s.h.refidx[2]].f->buf[0]) {
+av_log(avctx, AV_LOG_ERROR, "All references are 
unavailable\n");
+return AVERROR_INVALIDDATA;
+} else {
+
av_frame_copy(s->s.refs[s->s.h.refidx[1]].f,s->s.refs[s->s.h.refidx[2]].f);
+
av_frame_copy(s->s.refs[s->s.h.refidx[0]].f,s->s.refs[s->s.h.refidx[2]].f);
+}
+} else {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[2]].f->buf[0])) {
+
av_frame_copy(s->s.refs[s->s.h.refidx[0]].f,s->s.refs[s->s.h.refidx[1]].f);
+
av_frame_copy(s->s.refs[s->s.h.refidx[2]].f,s->s.refs[s->s.h.refidx[1]].f);
+} else {
+
av_frame_copy(s->s.refs[s->s.h.refidx[0]].f,s->s.refs[s->s.h.refidx[1]].f);
+}
+}
+} else {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[1]].f->buf[0])) {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[2]].f->buf[0])) {
+s->s.refs[s->s.h.refidx[1]].f = 
s->s.refs[s->s.h.refidx[2]].f = s->s.refs[s->s.h.refidx[0]].f;
+
av_frame_copy(s->s.refs[s->s.h.refidx[1]].f,s->s.refs[s->s.h.refidx[0]].f);
+
av_frame_copy(s->s.refs[s->s.h.refidx[2]].f,s->s.refs[s->s.h.refidx[0]].f);
+} else {
+
av_frame_copy(s->s.refs[s->s.h.refidx[1]].f,s->s.refs[s->s.h.refidx[0]].f);
+}
+} else {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[2]].f->buf[0])) {
+
av_frame_copy(s->s.refs[s->s.h.refidx[2]].f,s->s.refs[s->s.h.refidx[1]].f);
+}
+}
 }
 if (get_bits1(&s->gb)) {
 w = s->s.refs[s->s.h.refidx[0]].f->width;
@@ -790,6 +816,7 @@ static int decode_frame_header(AVCodecContext *avctx,
 
 /* check reference frames */
 if (!s->s.h.keyframe && !s->s.h.intraonly) {
+int has_valid_ref_frame = 0;
 for (i = 0; i < 3; i++) {
 AVFrame *ref = s->s.refs[s->s.h.refidx[i]].f;
 int refw = ref->width, refh = ref->height;
@@ -802,12 +829,15 @@ static int decode_frame_header(AVCodecContext *avctx,
 return AVERROR_INVALIDDATA;
 } else if (refw == w && refh == h) {
 s->mvscale[i][0] = s->mvscale[i][1] = 0;
+has_valid_ref_frame = 1;
 } else {
-if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * 
refh) {
-av_log(avctx, AV_LOG_ERROR,
+int is_ref_frame_invalid = (w * 2 < refw || h * 2 < refh || w 
> 16 * refw || h > 16 * refh);
+if (is_ref_frame_invalid) {
+av_log(avctx, AV_LOG_WARNING,
"Invalid ref frame dimensions %dx%d for frame size 
%dx%d\n",
refw, refh, w, h);
-return AVERROR_INVALIDDATA;
+} else {
+has_valid_ref_frame

[FFmpeg-devel] Help mixing live audio streams

2016-11-23 Thread Yan Brenman
All FFMPEG gurus!

Can somebody please suggest a format of FFMPEG command to mix several audio
live
streams on Windows. Let my just make it very clear - live audio streams and
not existing
audio files. Just to put it in the context - lets say audio stream from the
microphone and
Stereo Mix.

With so many parameters and mixing capabilities one would think it got to
be a way.
But unfortunately was not able to figure it yet, no matter what I tried.

Greatly appreciate any help or even advise or comment.
Vlad
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] mpeg2_metadata: support inverse (soft) telecine

2020-12-29 Thread Tom Yan
Signed-off-by: Tom Yan 
---
 doc/bitstream_filters.texi  |  5 +
 libavcodec/mpeg2_metadata_bsf.c | 30 ++
 2 files changed, 35 insertions(+)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8a2f55cc41..7831abc120 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -499,6 +499,11 @@ table 6-6).
 Set the colour description in the stream (see H.262 section 6.3.6
 and tables 6-7, 6-8 and 6-9).
 
+@item ivtc
+Inverse (soft) telecine, i.e. mark the sequences as progressive
+and clear the repeat_first_field and top_field_first bits in
+the Picture Coding Extension Data.
+
 @end table
 
 @section mpeg4_unpack_bframes
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
index d0048c0e25..735680a28b 100644
--- a/libavcodec/mpeg2_metadata_bsf.c
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -43,6 +43,8 @@ typedef struct MPEG2MetadataContext {
 int transfer_characteristics;
 int matrix_coefficients;
 
+int ivtc;
+
 int mpeg1_warned;
 } MPEG2MetadataContext;
 
@@ -54,7 +56,10 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
 MPEG2RawSequenceHeader*sh = NULL;
 MPEG2RawSequenceExtension *se = NULL;
 MPEG2RawSequenceDisplayExtension *sde = NULL;
+MPEG2RawPictureCodingExtension   *pce = NULL;
 int i, se_pos;
+int last_code = -1;
+int prog_seq = 1;
 
 for (i = 0; i < frag->nb_units; i++) {
 if (frag->units[i].type == MPEG2_START_SEQUENCE_HEADER) {
@@ -68,8 +73,26 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
 } else if (ext->extension_start_code_identifier ==
 MPEG2_EXTENSION_SEQUENCE_DISPLAY) {
 sde = &ext->data.sequence_display;
+} else if (ext->extension_start_code_identifier ==
+MPEG2_EXTENSION_PICTURE_CODING && last_code ==
+MPEG2_START_PICTURE) {
+pce = &ext->data.picture_coding;
+if (ctx->ivtc) {
+pce->repeat_first_field = 0;
+pce->top_field_first = 0;
+if (!pce->frame_pred_frame_dct) {
+if (pce->progressive_frame) {
+pce->frame_pred_frame_dct = 1;
+} else if (prog_seq) {
+av_log(bsf, AV_LOG_ERROR, "applying ivtc "
+   "to non-progressive sequence\n");
+prog_seq = 0;
+}
+}
+}
 }
 }
+last_code = frag->units[i].type;
 }
 
 if (!sh || !se) {
@@ -167,6 +190,9 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
 }
 }
 
+if (ctx->ivtc)
+se->progressive_sequence = 1;
+
 return 0;
 }
 
@@ -288,6 +314,10 @@ static const AVOption mpeg2_metadata_options[] = {
 OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
 { .i64 = -1 }, -1, 255, FLAGS },
 
+{ "ivtc", "Inverse (soft) Telecine",
+OFFSET(ivtc), AV_OPT_TYPE_BOOL,
+{ .i64 = 0 }, 0, 1, FLAGS },
+
 { NULL }
 };
 
-- 
2.29.2

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

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

[FFmpeg-devel] [PATCH v2] mpeg2_metadata: support inverse (soft) telecine

2020-12-30 Thread Tom Yan
Signed-off-by: Tom Yan 
---
 doc/bitstream_filters.texi  |  6 ++
 libavcodec/mpeg2_metadata_bsf.c | 27 +++
 2 files changed, 33 insertions(+)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8a2f55cc41..7e178a6912 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -499,6 +499,12 @@ table 6-6).
 Set the colour description in the stream (see H.262 section 6.3.6
 and tables 6-7, 6-8 and 6-9).
 
+@item ivtc
+Inverse (soft) telecine, i.e. mark the sequences as progressive
+and clear the repeat_first_field and top_field_first bits in
+the Picture Coding Extension Data. Works only with sequences
+that are entirely progressive in nature.
+
 @end table
 
 @section mpeg4_unpack_bframes
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
index d0048c0e25..8f89ef4f88 100644
--- a/libavcodec/mpeg2_metadata_bsf.c
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -43,6 +43,8 @@ typedef struct MPEG2MetadataContext {
 int transfer_characteristics;
 int matrix_coefficients;
 
+int ivtc;
+
 int mpeg1_warned;
 } MPEG2MetadataContext;
 
@@ -55,6 +57,7 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
 MPEG2RawSequenceExtension *se = NULL;
 MPEG2RawSequenceDisplayExtension *sde = NULL;
 int i, se_pos;
+int last_code = -1;
 
 for (i = 0; i < frag->nb_units; i++) {
 if (frag->units[i].type == MPEG2_START_SEQUENCE_HEADER) {
@@ -68,8 +71,25 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
 } else if (ext->extension_start_code_identifier ==
 MPEG2_EXTENSION_SEQUENCE_DISPLAY) {
 sde = &ext->data.sequence_display;
+} else if (ext->extension_start_code_identifier ==
+MPEG2_EXTENSION_PICTURE_CODING && last_code ==
+MPEG2_START_PICTURE) {
+if (ctx->ivtc) {
+MPEG2RawPictureCodingExtension *pce = 
&ext->data.picture_coding;
+pce->repeat_first_field = 0;
+pce->top_field_first = 0;
+if (!pce->frame_pred_frame_dct) {
+av_log(bsf, AV_LOG_ERROR, "invalid 
frame_pred_frame_dct\n");
+return -1;
+}
+if (!pce->progressive_frame) {
+av_log(bsf, AV_LOG_ERROR, "interlaced frame found\n");
+return -1;
+}
+}
 }
 }
+last_code = frag->units[i].type;
 }
 
 if (!sh || !se) {
@@ -167,6 +187,9 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
 }
 }
 
+if (ctx->ivtc)
+se->progressive_sequence = 1;
+
 return 0;
 }
 
@@ -288,6 +311,10 @@ static const AVOption mpeg2_metadata_options[] = {
 OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
 { .i64 = -1 }, -1, 255, FLAGS },
 
+{ "ivtc", "Inverse (soft) Telecine",
+OFFSET(ivtc), AV_OPT_TYPE_BOOL,
+{ .i64 = 0 }, 0, 1, FLAGS },
+
 { NULL }
 };
 
-- 
2.30.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] avformat/wavenc: allow WAVEFORMATEXTENSIBLE to be suppressed

2021-12-27 Thread Tom Yan
While WAVEFORMATEX sort of mandates WAVEFORMATEXTENSIBLE to be
used for audio with sample size other than 8 or 16,
PCMWAVEFORMAT does not practically have any limitation in
supporting higher sample size that is a multiple of 8 (or sample
rate higher than 48000).

In terms of sample size, the only real reason that the extension
exists is that it allows both an actual sample size and a
multiple-of-8 container size to be stored. However, such facility
is of no use when the actual sample size is a multiple of 8, let
alone that muxer never made use of it (since it never actually
supported sample size like 20 anyway; at least not in the way it
is supposed to.)

Although WAVEFORMATEXTENSIBLE has been around for more than two
decades, apparently programs and libraries that do not support
the format still exist.

Therefore, adding an option that allows the WAVEFORMATEXTENSIBLE
"extensions" to be suppressed and the format tag field to be set
to WAVE_FORMAT_PCM (0x0001) for audio with sample size higher than
16 (or sample rate higher than 48000).

Signed-off-by: Tom Yan 
---
 libavformat/riff.h| 5 +
 libavformat/riffenc.c | 4 ++--
 libavformat/wavenc.c  | 5 -
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/riff.h b/libavformat/riff.h
index 85d6786663..5794857f53 100644
--- a/libavformat/riff.h
+++ b/libavformat/riff.h
@@ -57,6 +57,11 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters 
*par, int for_asf, int
  */
 #define FF_PUT_WAV_HEADER_SKIP_CHANNELMASK  0x0002
 
+/**
+ * Tell ff_put_wav_header() not to write WAVEFORMATEXTENSIBLE extensions if 
possible.
+ */
+#define FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT  0x0004
+
 /**
  * Write WAVEFORMAT header structure.
  *
diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index ffccfa3d48..4dc8ca6e0f 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -80,9 +80,9 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
 waveformatextensible = (par->channels > 2 && par->channel_layout) ||
par->channels == 1 && par->channel_layout && 
par->channel_layout != AV_CH_LAYOUT_MONO ||
par->channels == 2 && par->channel_layout && 
par->channel_layout != AV_CH_LAYOUT_STEREO ||
-   par->sample_rate > 48000 ||
par->codec_id == AV_CODEC_ID_EAC3 ||
-   av_get_bits_per_sample(par->codec_id) > 16;
+   ((par->sample_rate > 48000 || 
av_get_bits_per_sample(par->codec_id) > 16) &&
+!(flags & FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT));
 
 if (waveformatextensible)
 avio_wl16(pb, 0xfffe);
diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
index 2317700be1..bd41d6eeb3 100644
--- a/libavformat/wavenc.c
+++ b/libavformat/wavenc.c
@@ -83,6 +83,7 @@ typedef struct WAVMuxContext {
 int peak_block_pos;
 int peak_ppv;
 int peak_bps;
+int extensible;
 } WAVMuxContext;
 
 #if CONFIG_WAV_MUXER
@@ -324,9 +325,10 @@ static int wav_write_header(AVFormatContext *s)
 }
 
 if (wav->write_peak != PEAK_ONLY) {
+int flags = !wav->extensible ? FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT : 
0;
 /* format header */
 fmt = ff_start_tag(pb, "fmt ");
-if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0) < 0) {
+if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, flags) < 0) {
 av_log(s, AV_LOG_ERROR, "Codec %s not supported in WAVE format\n",
avcodec_get_name(s->streams[0]->codecpar->codec_id));
 return AVERROR(ENOSYS);
@@ -494,6 +496,7 @@ static const AVOption options[] = {
 { "peak_block_size", "Number of audio samples used to generate each peak 
frame.",   OFFSET(peak_block_size), AV_OPT_TYPE_INT, { .i64 = 256 }, 0, 65536, 
ENC },
 { "peak_format", "The format of the peak envelope data (1: uint8, 2: 
uint16).", OFFSET(peak_format), AV_OPT_TYPE_INT, { .i64 = 
PEAK_FORMAT_UINT16 }, PEAK_FORMAT_UINT8, PEAK_FORMAT_UINT16, ENC },
 { "peak_ppv","Number of peak points per peak value (1 or 2).", 
 OFFSET(peak_ppv), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, 2, ENC },
+{ "extensible",  "Write WAVEFORMATEXTENSIBLE extensions.", 
 OFFSET(extensible), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
 { NULL },
 };
 
-- 
2.34.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] avformat/wavenc: allow WAVEFORMATEXTENSIBLE to be suppressed

2022-01-23 Thread Tom Yan
While WAVEFORMATEX sort of mandates WAVEFORMATEXTENSIBLE to be
used for audio with sample size other than 8 or 16,
PCMWAVEFORMAT does not practically have any limitation in
supporting higher sample size that is a multiple of 8 (or sample
rate higher than 48000).

In terms of sample size, the only real reason that the extension
exists is that it allows both an actual sample size and a
multiple-of-8 container size to be stored. However, such facility
is of no use when the actual sample size is a multiple of 8, let
alone that muxer never made use of it (since it never actually
supported sample size like 20 anyway; at least not in the way it
is supposed to.)

Although WAVEFORMATEXTENSIBLE has been around for more than two
decades, apparently programs and libraries that do not support
the format still exist.

Therefore, adding an option that allows the WAVEFORMATEXTENSIBLE
"extensions" to be suppressed and the format tag field to be set
to WAVE_FORMAT_PCM (0x0001) for audio with sample size higher than
16 (or sample rate higher than 48000).

Signed-off-by: Tom Yan 
---
 libavformat/riff.h| 5 +
 libavformat/riffenc.c | 4 ++--
 libavformat/wavenc.c  | 5 -
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/riff.h b/libavformat/riff.h
index 85d6786663..5794857f53 100644
--- a/libavformat/riff.h
+++ b/libavformat/riff.h
@@ -57,6 +57,11 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters 
*par, int for_asf, int
  */
 #define FF_PUT_WAV_HEADER_SKIP_CHANNELMASK  0x0002
 
+/**
+ * Tell ff_put_wav_header() not to write WAVEFORMATEXTENSIBLE extensions if 
possible.
+ */
+#define FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT  0x0004
+
 /**
  * Write WAVEFORMAT header structure.
  *
diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index ffccfa3d48..4dc8ca6e0f 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -80,9 +80,9 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
 waveformatextensible = (par->channels > 2 && par->channel_layout) ||
par->channels == 1 && par->channel_layout && 
par->channel_layout != AV_CH_LAYOUT_MONO ||
par->channels == 2 && par->channel_layout && 
par->channel_layout != AV_CH_LAYOUT_STEREO ||
-   par->sample_rate > 48000 ||
par->codec_id == AV_CODEC_ID_EAC3 ||
-   av_get_bits_per_sample(par->codec_id) > 16;
+   ((par->sample_rate > 48000 || 
av_get_bits_per_sample(par->codec_id) > 16) &&
+!(flags & FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT));
 
 if (waveformatextensible)
 avio_wl16(pb, 0xfffe);
diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
index 2317700be1..bd41d6eeb3 100644
--- a/libavformat/wavenc.c
+++ b/libavformat/wavenc.c
@@ -83,6 +83,7 @@ typedef struct WAVMuxContext {
 int peak_block_pos;
 int peak_ppv;
 int peak_bps;
+int extensible;
 } WAVMuxContext;
 
 #if CONFIG_WAV_MUXER
@@ -324,9 +325,10 @@ static int wav_write_header(AVFormatContext *s)
 }
 
 if (wav->write_peak != PEAK_ONLY) {
+int flags = !wav->extensible ? FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT : 
0;
 /* format header */
 fmt = ff_start_tag(pb, "fmt ");
-if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0) < 0) {
+if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, flags) < 0) {
 av_log(s, AV_LOG_ERROR, "Codec %s not supported in WAVE format\n",
avcodec_get_name(s->streams[0]->codecpar->codec_id));
 return AVERROR(ENOSYS);
@@ -494,6 +496,7 @@ static const AVOption options[] = {
 { "peak_block_size", "Number of audio samples used to generate each peak 
frame.",   OFFSET(peak_block_size), AV_OPT_TYPE_INT, { .i64 = 256 }, 0, 65536, 
ENC },
 { "peak_format", "The format of the peak envelope data (1: uint8, 2: 
uint16).", OFFSET(peak_format), AV_OPT_TYPE_INT, { .i64 = 
PEAK_FORMAT_UINT16 }, PEAK_FORMAT_UINT8, PEAK_FORMAT_UINT16, ENC },
 { "peak_ppv","Number of peak points per peak value (1 or 2).", 
 OFFSET(peak_ppv), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, 2, ENC },
+{ "extensible",  "Write WAVEFORMATEXTENSIBLE extensions.", 
 OFFSET(extensible), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
 { NULL },
 };
 
-- 
2.34.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] mpegvideo_parser: check picture_structure for field order

2022-02-05 Thread Tom Yan
the top_field_first bit is only used to indicate the field order
when the picture is a frame picture (which consists of two fields)
but not when it is a field picture (which consists of one single
top or bottom field).

Signed-off-by: Tom Yan 
---
 libavcodec/mpegvideo_parser.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index c5dc867d24..2ddcdb0f37 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -108,7 +108,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext 
*s,
 uint32_t start_code;
 int frame_rate_index, ext_type, bytes_left;
 int frame_rate_ext_n, frame_rate_ext_d;
-int top_field_first, repeat_first_field, progressive_frame;
+int picture_structure, top_field_first, repeat_first_field, 
progressive_frame;
 int horiz_size_ext, vert_size_ext, bit_rate_ext;
 int did_set_size=0;
 int set_dim_ret = 0;
@@ -181,6 +181,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext 
*s,
 break;
 case 0x8: /* picture coding extension */
 if (bytes_left >= 5) {
+picture_structure = buf[2] & 0x3;
 top_field_first = buf[3] & (1 << 7);
 repeat_first_field = buf[3] & (1 << 1);
 progressive_frame = buf[4] & (1 << 7);
@@ -199,7 +200,9 @@ static void mpegvideo_extract_headers(AVCodecParserContext 
*s,
 }
 
 if (!pc->progressive_sequence && !progressive_frame) {
-if (top_field_first)
+/* top_field_first is mandated to be 0 when
+   picture_structure is not 3 (i.e. not a frame 
picture) */
+if (top_field_first || picture_structure == 1)
 s->field_order = AV_FIELD_TT;
 else
 s->field_order = AV_FIELD_BB;
-- 
2.35.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] mpegvideo_parser: check picture_structure for field order

2022-02-05 Thread Tom Yan
It can probably be simplified to this:

...
if (progressive_frame)
s->field_order = AV_FIELD_PROGRESSIVE;
/* top_field_first is mandated to be 0 when
   picture_structure is not 3 (i.e. not a frame picture) */
else if (top_field_first || picture_structure == 1)
s->field_order = AV_FIELD_TT;
else
s->field_order = AV_FIELD_BB;
...

since progressive_sequence == 1 is illegal anyway if not all the
pictures/frames in the sequence are marked with progressive_frame ==
1.

If we consider commit 88e2dc7 proper, i.e. we should set
s->field_order to AV_FIELD_PROGRESSIVE when (processive_sequence == 0
and progressive_frame == 1), there's not really a point to check
processive_sequence at all.

On Sat, 5 Feb 2022 at 20:51, Tom Yan  wrote:
>
> the top_field_first bit is only used to indicate the field order
> when the picture is a frame picture (which consists of two fields)
> but not when it is a field picture (which consists of one single
> top or bottom field).
>
> Signed-off-by: Tom Yan 
> ---
>  libavcodec/mpegvideo_parser.c | 7 +--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
> index c5dc867d24..2ddcdb0f37 100644
> --- a/libavcodec/mpegvideo_parser.c
> +++ b/libavcodec/mpegvideo_parser.c
> @@ -108,7 +108,7 @@ static void 
> mpegvideo_extract_headers(AVCodecParserContext *s,
>  uint32_t start_code;
>  int frame_rate_index, ext_type, bytes_left;
>  int frame_rate_ext_n, frame_rate_ext_d;
> -int top_field_first, repeat_first_field, progressive_frame;
> +int picture_structure, top_field_first, repeat_first_field, 
> progressive_frame;
>  int horiz_size_ext, vert_size_ext, bit_rate_ext;
>  int did_set_size=0;
>  int set_dim_ret = 0;
> @@ -181,6 +181,7 @@ static void 
> mpegvideo_extract_headers(AVCodecParserContext *s,
>  break;
>  case 0x8: /* picture coding extension */
>  if (bytes_left >= 5) {
> +picture_structure = buf[2] & 0x3;
>  top_field_first = buf[3] & (1 << 7);
>  repeat_first_field = buf[3] & (1 << 1);
>  progressive_frame = buf[4] & (1 << 7);
> @@ -199,7 +200,9 @@ static void 
> mpegvideo_extract_headers(AVCodecParserContext *s,
>  }
>
>  if (!pc->progressive_sequence && !progressive_frame) 
> {
> -if (top_field_first)
> +/* top_field_first is mandated to be 0 when
> +   picture_structure is not 3 (i.e. not a frame 
> picture) */
> +if (top_field_first || picture_structure == 1)
>  s->field_order = AV_FIELD_TT;
>  else
>  s->field_order = AV_FIELD_BB;
> --
> 2.35.1
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v2] mpegvideo_parser: check picture_structure for field order

2022-02-05 Thread Tom Yan
the top_field_first bit is only used to indicate the field order
when the picture is a frame picture (which consists of two fields)
but not when it is a field picture (which consists of one single
top or bottom field).

also removing the unnecessary progressive_sequence check (the bit
is mandated to be 0 if progressive_frame is 0 on any picture in the
sequence).

Signed-off-by: Tom Yan 
---
 libavcodec/mpegvideo_parser.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index c5dc867d24..004ff602f6 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -181,6 +181,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext 
*s,
 break;
 case 0x8: /* picture coding extension */
 if (bytes_left >= 5) {
+s->picture_structure = buf[2] & 0x3;
 top_field_first = buf[3] & (1 << 7);
 repeat_first_field = buf[3] & (1 << 1);
 progressive_frame = buf[4] & (1 << 7);
@@ -198,13 +199,15 @@ static void 
mpegvideo_extract_headers(AVCodecParserContext *s,
 }
 }
 
-if (!pc->progressive_sequence && !progressive_frame) {
-if (top_field_first)
-s->field_order = AV_FIELD_TT;
-else
-s->field_order = AV_FIELD_BB;
-} else
+if (progressive_frame)
 s->field_order = AV_FIELD_PROGRESSIVE;
+else if (top_field_first ||
+ /* top_field_first is mandated to be 0 when
+the picture is not a frame picture) */
+ s->picture_structure == 
AV_PICTURE_STRUCTURE_TOP_FIELD)
+s->field_order = AV_FIELD_TT;
+else
+s->field_order = AV_FIELD_BB;
 }
 break;
 }
-- 
2.35.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 v2] mpegvideo_parser: check picture_structure for field order

2022-02-06 Thread Tom Yan
This is really just a matter of choice. If you don't care about
spec-conformance in this particular case, top_field_first *could* be 1
and/or picture_structure *could* be not 3 even when
progressive_sequence is 1, so which one do you choose to believe? The
truth is, it doesn't even matter.

If you insist on making it more clumsy and silly, I can resend.

On Sun, 6 Feb 2022 at 13:46, Andreas Rheinhardt
 wrote:
>
> Tom Yan:
> > the top_field_first bit is only used to indicate the field order
> > when the picture is a frame picture (which consists of two fields)
> > but not when it is a field picture (which consists of one single
> > top or bottom field).
> >
> > also removing the unnecessary progressive_sequence check (the bit
> > is mandated to be 0 if progressive_frame is 0 on any picture in the
> > sequence).
> >
>
> Just because something is mandated does not mean that it is so;
> spec-incompliant files exist.
>
> > Signed-off-by: Tom Yan 
> > ---
> >  libavcodec/mpegvideo_parser.c | 15 +--
> >  1 file changed, 9 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
> > index c5dc867d24..004ff602f6 100644
> > --- a/libavcodec/mpegvideo_parser.c
> > +++ b/libavcodec/mpegvideo_parser.c
> > @@ -181,6 +181,7 @@ static void 
> > mpegvideo_extract_headers(AVCodecParserContext *s,
> >  break;
> >  case 0x8: /* picture coding extension */
> >  if (bytes_left >= 5) {
> > +s->picture_structure = buf[2] & 0x3;
> >  top_field_first = buf[3] & (1 << 7);
> >  repeat_first_field = buf[3] & (1 << 1);
> >  progressive_frame = buf[4] & (1 << 7);
> > @@ -198,13 +199,15 @@ static void 
> > mpegvideo_extract_headers(AVCodecParserContext *s,
> >  }
> >  }
> >
> > -if (!pc->progressive_sequence && 
> > !progressive_frame) {
> > -if (top_field_first)
> > -s->field_order = AV_FIELD_TT;
> > -else
> > -s->field_order = AV_FIELD_BB;
> > -} else
> > +if (progressive_frame)
> >  s->field_order = AV_FIELD_PROGRESSIVE;
> > +else if (top_field_first ||
> > + /* top_field_first is mandated to be 0 
> > when
> > +the picture is not a frame picture) */
> > + s->picture_structure == 
> > AV_PICTURE_STRUCTURE_TOP_FIELD)
> > +s->field_order = AV_FIELD_TT;
> > +else
> > +s->field_order = AV_FIELD_BB;
> >  }
> >  break;
> >  }
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v3] mpegvideo_parser: check picture_structure for field order

2022-02-06 Thread Tom Yan
the top_field_first bit is only used to indicate the field order
when the picture is a frame picture (which consists of two fields)
but not when it is a field picture (which consists of one single
top or bottom field).

Signed-off-by: Tom Yan 
---
 libavcodec/mpegvideo_parser.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index c5dc867d24..26f3aac9da 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -181,6 +181,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext 
*s,
 break;
 case 0x8: /* picture coding extension */
 if (bytes_left >= 5) {
+s->picture_structure = buf[2] & 0x3;
 top_field_first = buf[3] & (1 << 7);
 repeat_first_field = buf[3] & (1 << 1);
 progressive_frame = buf[4] & (1 << 7);
@@ -198,13 +199,15 @@ static void 
mpegvideo_extract_headers(AVCodecParserContext *s,
 }
 }
 
-if (!pc->progressive_sequence && !progressive_frame) {
-if (top_field_first)
-s->field_order = AV_FIELD_TT;
-else
-s->field_order = AV_FIELD_BB;
-} else
+/* picture_structure > progressive bits > 
top_field_first */
+if (s->picture_structure == 
AV_PICTURE_STRUCTURE_TOP_FIELD)
+s->field_order = AV_FIELD_TT;
+else if (s->picture_structure == 
AV_PICTURE_STRUCTURE_BOTTOM_FIELD)
+s->field_order = AV_FIELD_BB;
+else if (pc->progressive_sequence || progressive_frame)
 s->field_order = AV_FIELD_PROGRESSIVE;
+else
+s->field_order = top_field_first ? AV_FIELD_TT : 
AV_FIELD_BB;
 }
 break;
 }
-- 
2.35.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] avformat/riffdec: fix support for WAVEFORMAT

2022-07-25 Thread Tom Yan
WAVEFORMAT can be used for 16-bit PCM as well.

Signed-off-by: Tom Yan 
---
 libavformat/riffdec.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index 3946ecb72f..8289438f08 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -94,7 +94,7 @@ static void parse_waveformatex(AVFormatContext *s, 
AVIOContext *pb, AVCodecParam
 int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
   AVCodecParameters *par, int size, int big_endian)
 {
-int id, channels;
+int id, channels = 0;
 uint64_t bitrate = 0;
 
 if (size < 14) {
@@ -118,15 +118,15 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
 bitrate= avio_rb32(pb) * 8LL;
 par->block_align = avio_rb16(pb);
 }
-if (size == 14) {  /* We're dealing with plain vanilla WAVEFORMAT */
-par->bits_per_coded_sample = 8;
-} else {
+if (size >= 16) {  /* We're dealing with PCMWAVEFORMAT */
 if (!big_endian) {
 par->bits_per_coded_sample = avio_rl16(pb);
 } else {
 par->bits_per_coded_sample = avio_rb16(pb);
 }
-}
+} else if (channels && par->sample_rate) {  /* We're dealing with 
WAVEFORMAT */
+par->bits_per_coded_sample = bitrate / channels / par->sample_rate;
+}  /* Apparently size would be >= 32 if id == 0x0165; see below */
 if (id == 0xFFFE) {
 par->codec_tag = 0;
 } else {
-- 
2.37.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] libavformat/dashdec: Fix buffer overflow in segment URL resolution

2025-04-15 Thread jing yan
Thanks for the review!
that can't be null and I found another mistake.
I will fix this issue and send a v2 patch soon.

Michael Niedermayer  于2025年4月16日周三 07:33写道:

> Hi
>
> On Fri, Apr 11, 2025 at 03:48:08PM +0800, xiaohuan...@gmail.com wrote:
> > From: xiaohuanshu 
> >
> > Problem:
> > The max_url_size calculation for DASH segment URLs only considered the
> base URL
> > length, leading to buffer overflow when the segment's sourceURL exceeded
> the
> > pre-allocated buffer. This triggered the log error:
> > "DASH request for url 'invalid:truncated'".
> >
> > Reproduce:
> > 1. A test sample "long-sourceurl-sample.mpd" (deliberately designed with
> a long
> >sourceURL) was uploaded to VideoLAN's repository.
> > 2. Reproduce with short base path:
> >ffmpeg -i /tmp/short_path/long-sourceurl-sample.mpd
> >-> Triggers "invalid:truncated" error
> > 3. With artificially lengthened base path (e.g. /aaa/../bbb/../...):
> >ffmpeg -i
> /long/../path/../with/../many/../segments/long-sourceurl-sample.mpd
> >-> URL resolves correctly (though HTTP fetch fails due to fake URL)
> >
> > Fix:
> > Recalculate max_url_size by considering both base URL and sourceURL
> lengths,
> > ensuring sufficient buffer allocation during URL concatenation.
> >
> > Signed-off-by: xiaohuanshu 
> > ---
> >  libavformat/dashdec.c | 14 +-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> > index c3f3d7f3f8..f604d363c4 100644
> > --- a/libavformat/dashdec.c
> > +++ b/libavformat/dashdec.c
> > @@ -606,7 +606,7 @@ static int
> parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
> >  char *initialization_val = NULL;
> >  char *media_val = NULL;
> >  char *range_val = NULL;
> > -int max_url_size = c ? c->max_url_size: MAX_URL_SIZE;
> > +int max_url_size = 0;
> >  int err;
> >
> >  if (!av_strcasecmp(fragmenturl_node->name, "Initialization")) {
> > @@ -620,6 +620,12 @@ static int
> parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
> >  xmlFree(initialization_val);
> >  return AVERROR(ENOMEM);
> >  }
> > +max_url_size = FFMAX(
>
> > +c ? c->max_url_size : 0,
>
> how can c be NULL here ?
>
>
> > +initialization_val ? aligned(strlen(initialization_val)
> +
> > + (rep_id_val ?
> strlen(rep_id_val) : 0) +
> > + (rep_bandwidth_val ?
> strlen(rep_bandwidth_val) : 0)) : 0);
> > +max_url_size = max_url_size ? max_url_size : MAX_URL_SIZE;
> >  rep->init_section->url = get_content_url(baseurl_nodes, 4,
> >   max_url_size,
> >   rep_id_val,
> > @@ -641,6 +647,12 @@ static int
> parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
> >  xmlFree(media_val);
> >  return AVERROR(ENOMEM);
> >  }
> > +max_url_size = FFMAX(
> > +c ? c->max_url_size : 0,
>
> > +initialization_val ? aligned(strlen(initialization_val)
> +
>
> how can initialization_val be non NULL here ?
>
> thx
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I have often repented speaking, but never of holding my tongue.
> -- Xenocrates
> ___
> 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 v3] libavformat/dashdec: Fix buffer overflow in segment URL resolution

2025-05-14 Thread jing yan
Hi, just a gentle ping on this patch.

Let me know if anything else is needed.


Thanks!

 于2025年4月16日周三 14:56写道:

> From: xiaohuanshu 
>
> Problem:
> The max_url_size calculation for DASH segment URLs only considered the
> base URL
> length, leading to buffer overflow when the segment's sourceURL exceeded
> the
> pre-allocated buffer. This triggered the log error:
> "DASH request for url 'invalid:truncated'".
>
> Reproduce:
> 1. A test sample "long-sourceurl-sample.mpd" (deliberately designed with a
> long
>sourceURL) was uploaded to VideoLAN's repository.
> 2. Reproduce with short base path:
>ffmpeg -i /tmp/short_path/long-sourceurl-sample.mpd
>-> Triggers "invalid:truncated" error
> 3. With artificially lengthened base path (e.g. /aaa/../bbb/../...):
>ffmpeg -i
> /long/../path/../with/../many/../segments/long-sourceurl-sample.mpd
>-> URL resolves correctly (though HTTP fetch fails due to fake URL)
>
> Fix:
> Recalculate max_url_size by considering both base URL and sourceURL
> lengths,
> ensuring sufficient buffer allocation during URL concatenation.
>
> V2:
> 1. no need to determine whether initialization_val is null.
> 2. fix the incorrect variable name.
>
> V3:
> 1. change `max_url_size` scope into `Initialization` and `Media` blocks.
>
> Signed-off-by: xiaohuanshu 
> ---
>  libavformat/dashdec.c | 12 +++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index c3f3d7f3f8..31a84bd184 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -606,7 +606,6 @@ static int
> parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
>  char *initialization_val = NULL;
>  char *media_val = NULL;
>  char *range_val = NULL;
> -int max_url_size = c ? c->max_url_size: MAX_URL_SIZE;
>  int err;
>
>  if (!av_strcasecmp(fragmenturl_node->name, "Initialization")) {
> @@ -620,6 +619,12 @@ static int
> parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
>  xmlFree(initialization_val);
>  return AVERROR(ENOMEM);
>  }
> +int max_url_size = FFMAX(
> +c ? c->max_url_size : 0,
> +aligned(strlen(initialization_val) +
> +(rep_id_val ? strlen(rep_id_val) : 0) +
> +(rep_bandwidth_val ? strlen(rep_bandwidth_val) :
> 0)));
> +max_url_size = max_url_size ? max_url_size : MAX_URL_SIZE;
>  rep->init_section->url = get_content_url(baseurl_nodes, 4,
>   max_url_size,
>   rep_id_val,
> @@ -641,6 +646,11 @@ static int
> parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
>  xmlFree(media_val);
>  return AVERROR(ENOMEM);
>  }
> +int max_url_size = FFMAX(
> +c ? c->max_url_size : 0,
> +aligned(strlen(media_val) + (rep_id_val ?
> strlen(rep_id_val) : 0) +
> +(rep_bandwidth_val ? strlen(rep_bandwidth_val) :
> 0)));
> +max_url_size = max_url_size ? max_url_size : MAX_URL_SIZE;
>  seg->url = get_content_url(baseurl_nodes, 4,
> max_url_size,
> rep_id_val,
> --
> 2.39.5 (Apple Git-154)
>
>
___
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/4] fix multiple memory leaks

2025-06-17 Thread Lidong Yan
This patch series fixes multiple memory leaks in the following files:
libavformat/rtmpproto.c, libavfilter/asrc_sinc.c, libavformat/sbgdec.c,
and libavformat/sapenc.c.

-BEGIN PGP PUBLIC KEY BLOCK-

mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-END PGP PUBLIC KEY BLOCK-

Lidong Yan (4):
  libavformat/rtmpproto: fix rmtp packet leak in gen_connect()
  avfilter/asrc_sinc: fix leak in config_input()
  avformat/sbgdec: fix leak in sbg_read_header()
  avformat/sapenc: fix leak in sap_write_header()

 libavfilter/asrc_sinc.c | 4 +++-
 libavformat/rtmpproto.c | 2 ++
 libavformat/sapenc.c| 6 ++
 libavformat/sbgdec.c| 6 --
 4 files changed, 15 insertions(+), 3 deletions(-)

-- 
2.50.0-rc1

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

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


[FFmpeg-devel] [PATCH 4/4] avformat/sapenc: fix leak in sap_write_header()

2025-06-17 Thread Lidong Yan
In sap_write_header(), ff_format_set_url() assign new allocated new_url
to contexts[i]->url but forgot to free it later. Add two loops to free
contexts[i]->url before av_free(context).

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/sapenc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 87a834a8d8..3ba7f16022 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -233,6 +233,9 @@ static int sap_write_header(AVFormatContext *s)
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
+for (i = 0; i < s->nb_streams; i++)
+if (contexts[i])
+av_free(contexts[i]->url);
 av_freep(&contexts);
 av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", &sap->ann[pos]);
 pos += strlen(&sap->ann[pos]);
@@ -247,6 +250,9 @@ static int sap_write_header(AVFormatContext *s)
 return 0;
 
 fail:
+for (i = 0; i < s->nb_streams; i++)
+if (contexts[i])
+av_free(contexts[i]->url);
 av_free(contexts);
 sap_write_close(s);
 return ret;
-- 
2.50.0-rc1

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

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


[FFmpeg-devel] [PATCH 2/4] avfilter/asrc_sinc: fix leak in config_input()

2025-06-17 Thread Lidong Yan
In config_input(), fir_to_phase() allocates memory in h[longer].
But if av_calloc() to s->coeffs failed, memory in h[longer] would
leak. Add av_free(h[longer]) in !s->coeffs path.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavfilter/asrc_sinc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index 6ff3303316..198c322665 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -370,8 +370,10 @@ static int config_output(AVFilterLink *outlink)
 s->n = 1 << (av_log2(n) + 1);
 s->rdft_len = 1 << av_log2(n);
 s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
-if (!s->coeffs)
+if (!s->coeffs) {
+av_free(h[longer]);
 return AVERROR(ENOMEM);
+}
 
 for (i = 0; i < n; i++)
 s->coeffs[i] = h[longer][i];
-- 
2.50.0-rc1

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

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


[FFmpeg-devel] [PATCH 1/4] libavformat/rtmpproto: fix rmtp packet leak in gen_connect()

2025-06-17 Thread Lidong Yan
In libavformat/rtmpproto.c:gen_connect(), if check on string length
or check on codec fourcc failed, ff_rtmp_packet_create() allocated
data in pkt would leak. Add ff_rtmp_packet_destory before return error
code.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/rtmpproto.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 846376e668..dd850f72ed 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -347,6 +347,7 @@ static int gen_connect(URLContext *s, RTMPContext *rt)
 if ((fourcc_str_len + 1) % 5 != 0) {
 av_log(s, AV_LOG_ERROR, "Malformed rtmp_enhanched_codecs, "
"should be of the form hvc1[,av01][,vp09][,...]\n");
+ff_rtmp_packet_destroy(&pkt);
 return AVERROR(EINVAL);
 }
 
@@ -370,6 +371,7 @@ static int gen_connect(URLContext *s, RTMPContext *rt)
 ff_amf_write_string(&p, fourcc);
 } else {
 av_log(s, AV_LOG_ERROR, "Unsupported codec fourcc, 
%.*s\n", 4, fourcc_data);
+ff_rtmp_packet_destroy(&pkt);
 return AVERROR_PATCHWELCOME;
 }
 
-- 
2.50.0-rc1

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

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


[FFmpeg-devel] [PATCH 3/4] avformat/sbgdec: fix leak in sbg_read_header()

2025-06-17 Thread Lidong Yan
In sbg_read_header(), if avformat_new_stream() failed, it returns
without cleanup, which may cause memory leaks. Replace return statement
with goto so that we would first clean up then return.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/sbgdec.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c
index bf319be228..4afb51b844 100644
--- a/libavformat/sbgdec.c
+++ b/libavformat/sbgdec.c
@@ -1434,8 +1434,10 @@ static av_cold int sbg_read_header(AVFormatContext *avf)
 }
 
 st = avformat_new_stream(avf, NULL);
-if (!st)
-return AVERROR(ENOMEM);
+if (!st) {
+r = AVERROR(ENOMEM);
+goto fail;
+}
 sti = ffstream(st);
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codecpar->codec_id   = AV_CODEC_ID_FFWAVESYNTH;
-- 
2.50.0-rc1

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

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


[FFmpeg-devel] [PATCH] avformat/rtmpproto: fix rmtp packet leak in gen_connect()

2025-06-14 Thread Lidong Yan
In libavformat/rtmpproto.c:gen_connect(), if check on string length
or check on codec fourcc failed, ff_rtmp_packet_create() allocated
data in pkt would leak. Add ff_rtmp_packet_destory before return error
code.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>

-BEGIN PGP PUBLIC KEY BLOCK-

mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-END PGP PUBLIC KEY BLOCK-

---
 libavformat/rtmpproto.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 846376e668..dd850f72ed 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -347,6 +347,7 @@ static int gen_connect(URLContext *s, RTMPContext *rt)
 if ((fourcc_str_len + 1) % 5 != 0) {
 av_log(s, AV_LOG_ERROR, "Malformed rtmp_enhanched_codecs, "
"should be of the form hvc1[,av01][,vp09][,...]\n");
+ff_rtmp_packet_destroy(&pkt);
 return AVERROR(EINVAL);
 }
 
@@ -370,6 +371,7 @@ static int gen_connect(URLContext *s, RTMPContext *rt)
 ff_amf_write_string(&p, fourcc);
 } else {
 av_log(s, AV_LOG_ERROR, "Unsupported codec fourcc, 
%.*s\n", 4, fourcc_data);
+ff_rtmp_packet_destroy(&pkt);
 return AVERROR_PATCHWELCOME;
 }
 
-- 
2.50.0.rc0.47.g9cc88feafa.dirty

___
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/2] fix multiple memory leaks

2025-06-25 Thread Lidong Yan
This patch improves code in
  https://ffmpeg.org/pipermail/ffmpeg-devel/2025-June/345435.html

-BEGIN PGP PUBLIC KEY BLOCK-

mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-END PGP PUBLIC KEY BLOCK-

Lidong Yan (2):
  avfilter/asrc_sinc: fix leak in config_input()
  avformat/sapenc: fix leak in sap_write_header()

 libavfilter/asrc_sinc.c |  4 +++-
 libavformat/sapenc.c| 35 +++
 2 files changed, 22 insertions(+), 17 deletions(-)

-- 
2.50.0.108.g6ae0c543ae

___
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] avformat/sapenc: fix leak in sap_write_header()

2025-06-25 Thread Lidong Yan
In sap_write_header(), ff_format_set_url() assign new allocated new_url
to contexts[i]->url but forgot to free it later. Add for loop to free
contexts[i]->url before av_free(context).

To prevent from writing free-for-loop in every return point, replace
`return 0` with `ret = 0` so normal execution can fall through cleanup
code. Since normal code execution now go through code after fail label,
replace fail label with cleanup label.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/sapenc.c | 35 +++
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 87a834a8d8..810ba4adf6 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -113,7 +113,7 @@ static int sap_write_header(AVFormatContext *s)
 if (getaddrinfo(host, NULL, &hints, &ai)) {
 av_log(s, AV_LOG_ERROR, "Unable to resolve %s\n", host);
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 if (ai->ai_family == AF_INET) {
 /* Also known as sap.mcast.net */
@@ -130,7 +130,7 @@ static int sap_write_header(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Host %s resolved to unsupported "
 "address family\n", host);
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 freeaddrinfo(ai);
 }
@@ -138,7 +138,7 @@ static int sap_write_header(AVFormatContext *s)
 contexts = av_calloc(s->nb_streams, sizeof(*contexts));
 if (!contexts) {
 ret = AVERROR(ENOMEM);
-goto fail;
+goto cleanup;
 }
 
 if (s->start_time_realtime == 0  ||  s->start_time_realtime == 
AV_NOPTS_VALUE)
@@ -156,17 +156,17 @@ static int sap_write_header(AVFormatContext *s)
s->protocol_whitelist, 
s->protocol_blacklist, NULL);
 if (ret) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 ret = ff_rtp_chain_mux_open(&contexts[i], s, s->streams[i], fd, 0, i);
 if (ret < 0)
-goto fail;
+goto cleanup;
 s->streams[i]->priv_data = contexts[i];
 s->streams[i]->time_base = contexts[i]->streams[0]->time_base;
 new_url = av_strdup(url);
 if (!new_url) {
 ret = AVERROR(ENOMEM);
-goto fail;
+goto cleanup;
 }
 ff_format_set_url(contexts[i], new_url);
 }
@@ -181,13 +181,13 @@ static int sap_write_header(AVFormatContext *s)
s->protocol_whitelist, s->protocol_blacklist, 
NULL);
 if (ret) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 
 udp_fd = ffurl_get_file_handle(sap->ann_fd);
 if (getsockname(udp_fd, (struct sockaddr*) &localaddr, &addrlen)) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 if (localaddr.ss_family != AF_INET
 #if HAVE_STRUCT_SOCKADDR_IN6
@@ -196,13 +196,13 @@ static int sap_write_header(AVFormatContext *s)
 ) {
 av_log(s, AV_LOG_ERROR, "Unsupported protocol family\n");
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 sap->ann_size = 8192;
 sap->ann = av_mallocz(sap->ann_size);
 if (!sap->ann) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 sap->ann[pos] = (1 << 5);
 #if HAVE_STRUCT_SOCKADDR_IN6
@@ -231,9 +231,8 @@ static int sap_write_header(AVFormatContext *s)
 if (av_sdp_create(contexts, s->nb_streams, &sap->ann[pos],
   sap->ann_size - pos)) {
 ret = AVERROR_INVALIDDATA;
-goto fail;
+goto cleanup;
 }
-av_freep(&contexts);
 av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", &sap->ann[pos]);
 pos += strlen(&sap->ann[pos]);
 sap->ann_size = pos;
@@ -241,14 +240,18 @@ static int sap_write_header(AVFormatContext *s)
 if (sap->ann_size > sap->ann_fd->max_packet_size) {
 av_log(s, AV_LOG_ERROR, "Announcement too large to send in one "
 "packet\n");
-goto fail;
+goto cleanup;
 }
 
-return 0;
+ret = 0;
 
-fail:
+cleanup:
+for (i = 0; i < s->nb_streams; i++)
+if (contexts[i])
+av_free(contexts[i]->url);
 av_free(contexts);
-sap_write_close(s);
+if (ret < 0)
+sap_write_close(s);
 return ret;
 }
 
-- 
2.50.0.108.g6ae0c543ae

___
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] avformat/sapenc: fix leak in sap_write_header()

2025-06-28 Thread Lidong Yan
Michael Niedermayer  writes:

> please do the rename in a seperate patch
> so there are 2 patches, this makes the changes clearer
>

Got it. Thanks for your review.
Lidong
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 4/4] avformat/iamf_writer: fix leaks of avio_open_dyn_buf() allocated memory

2025-06-27 Thread Lidong Yan
In iamf_write_codec_config(), if codec_id equals to AV_CODEC_ID_AAC,
avio_open_dyn_buf() allocated memory would leak. Add ffio_free_dyn_buf()
to free dyn_bc before return.

In iamf_write_audio_element(), multiple places returns without free
dyn_bc, replace return AVERROR* with goto cleanup and add cleanup code
to free dyn_bc. Do the same thing for iamf_write_audio_element() and
write_parameter_block().

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/iamf_writer.c | 47 +--
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index f88987790d..2e8df602b1 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -523,6 +523,7 @@ static int iamf_write_codec_config(const IAMFContext *iamf,
 avio_write(dyn_bc, codec_config->extradata, 
codec_config->extradata_size);
 break;
 case AV_CODEC_ID_AAC:
+ffio_free_dyn_buf(&dyn_bc);
 return AVERROR_PATCHWELCOME;
 case AV_CODEC_ID_FLAC:
 avio_w8(dyn_bc, 0x80);
@@ -774,7 +775,8 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
 if (layout == 3 || layout == 4 || layout == 6 || layout == 7) {
 av_log(log_ctx, AV_LOG_ERROR, "demixing_info needed but 
not set in Stream Group #%u\n",
audio_element->audio_element_id);
-return AVERROR(EINVAL);
+ret = AVERROR(EINVAL);
+goto cleanup;
 }
 }
 param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING;
@@ -794,7 +796,7 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
 param_def = ff_iamf_get_param_definition(iamf, param->parameter_id);
 ret = param_definition(iamf, param_def, dyn_bc, log_ctx);
 if (ret < 0)
-return ret;
+goto cleanup;
 
 avio_w8(dyn_bc, demix->dmixp_mode << 5); // dmixp_mode
 avio_w8(dyn_bc, element->default_w << 4); // default_w
@@ -806,24 +808,25 @@ static int iamf_write_audio_element(const IAMFContext 
*iamf,
 if (!param) {
 av_log(log_ctx, AV_LOG_ERROR, "recon_gain_info needed but not set 
in Stream Group #%u\n",
audio_element->audio_element_id);
-return AVERROR(EINVAL);
+ret = AVERROR(EINVAL);
+goto cleanup;
 }
 ffio_write_leb(dyn_bc, AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN); // 
type
 
 param_def = ff_iamf_get_param_definition(iamf, param->parameter_id);
 ret = param_definition(iamf, param_def, dyn_bc, log_ctx);
 if (ret < 0)
-return ret;
+goto cleanup;
 }
 
 if (element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL) {
 ret = scalable_channel_layout_config(audio_element, dyn_bc);
 if (ret < 0)
-return ret;
+goto cleanup;
 } else {
 ret = ambisonics_config(audio_element, dyn_bc);
 if (ret < 0)
-return ret;
+goto cleanup;
 }
 
 init_put_bits(&pbc, header, sizeof(header));
@@ -835,9 +838,11 @@ static int iamf_write_audio_element(const IAMFContext 
*iamf,
 avio_write(pb, header, put_bytes_count(&pbc, 1));
 ffio_write_leb(pb, dyn_size);
 avio_write(pb, dyn_buf, dyn_size);
-ffio_free_dyn_buf(&dyn_bc);
+ret = 0;
 
-return 0;
+cleanup:
+ffio_free_dyn_buf(&dyn_bc);
+return ret;
 }
 
 static int iamf_write_mixing_presentation(const IAMFContext *iamf,
@@ -886,7 +891,8 @@ static int iamf_write_mixing_presentation(const IAMFContext 
*iamf,
 if (av_dict_count(submix_element->annotations) != 
av_dict_count(mix->annotations)) {
 av_log(log_ctx, AV_LOG_ERROR, "Inconsistent amount of labels 
in submix %d from Mix Presentation id #%u\n",
j, audio_element->audio_element_id);
-return AVERROR(EINVAL);
+ret = AVERROR(EINVAL);
+goto cleanup;
 }
 while ((tag = av_dict_iterate(submix_element->annotations, tag)))
 avio_put_str(dyn_bc, tag->value);
@@ -901,7 +907,7 @@ static int iamf_write_mixing_presentation(const IAMFContext 
*iamf,
 param_def = ff_iamf_get_param_definition(iamf, 
submix_element->element_mix_config->parameter_id);
 ret = param_definition(iamf, param_def, dyn_bc, log_ctx);
 if (ret < 0)
-return ret;
+goto cleanup;
 
 avio_wb16(dyn_bc, 
rescale_rational(submix_element->default_mix_gain, 1 << 8));
 }
@@ -909,7 +915,7 @@ static int iamf_write_mixing_presentation(const IAMFContext 
*iamf,
 param_def = ff_iamf_get_param_defi

[FFmpeg-devel] [PATCH 2/4] avcodec/vorbisenc: fix leak if av_mallocz failed

2025-06-27 Thread Lidong Yan
In put_main_header(), av_mallocz() allocates memory to local variable
buffer, buffer leaks if av_mallocz() to *out failed. Add av_free(buffer)
before return error code.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavcodec/vorbisenc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 99ac72c910..b4680a11ed 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -740,8 +740,10 @@ static int put_main_header(vorbis_enc_context *venc, 
uint8_t **out)
 
 len = hlens[0] + hlens[1] + hlens[2];
 p = *out = av_mallocz(64 + len + len/255);
-if (!p)
+if (!p) {
+av_freep(&buffer);
 return AVERROR(ENOMEM);
+}
 
 *p++ = 2;
 p += av_xiphlacing(p, hlens[0]);
-- 
2.50.0.108.g6ae0c543ae

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

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


[FFmpeg-devel] [PATCH 1/4] avformat/movenc: fix multiple leaks in error paths

2025-06-27 Thread Lidong Yan
In mov_write_iacb_tag(), avio_open_dyn_buf() allocates a buffer
but we forgot to free it when ff_iamf_write_descriptors() failed. Add
cleanup code and goto cleanup if error happened.

In mov_preroll_write_stbl_atoms(), av_malloc_array() allocates an
array and it leaks if packets distance > 32. Add av_free(sgpd_entries)
before return.

In mov_write_track_udta_tag(), avio_open_dyn_buf() allocates a buffer,
and this buffer leaks if mov_write_track_kinds() failed. Add cleanup
code and goto cleanup if error happened.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/movenc.c | 22 +++---
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index a651d6d618..c9a55c1817 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -337,14 +337,18 @@ static int mov_write_iacb_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra
 
 ret = ff_iamf_write_descriptors(track->iamf, dyn_bc, s);
 if (ret < 0)
-return ret;
+goto cleanup;
 
 dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
 ffio_write_leb(pb, dyn_size);
 avio_write(pb, dyn_buf, dyn_size);
-av_free(dyn_buf);
+ret = update_size(pb, pos);
 
-return update_size(pb, pos);
+cleanup:
+if (!dyn_buf)
+avio_close_dyn_buf(dyn_bc, &dyn_buf);
+av_free(dyn_buf);
+return ret;
 }
 #endif
 
@@ -3173,8 +3177,10 @@ static int mov_preroll_write_stbl_atoms(AVIOContext *pb, 
MOVTrack *track)
 if (roll_samples_remaining > 0)
 distance = 0;
 /* Verify distance is a maximum of 32 (2.5ms) packets. */
-if (distance > 32)
+if (distance > 32) {
+av_free(sgpd_entries);
 return AVERROR_INVALIDDATA;
+}
 if (i && distance == sgpd_entries[entries].roll_distance) {
 sgpd_entries[entries].count++;
 } else {
@@ -4186,7 +4192,7 @@ static int mov_write_track_udta_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 
 if (mov->mode & MODE_MP4) {
 if ((ret = mov_write_track_kinds(pb_buf, st)) < 0)
-return ret;
+goto cleanup;
 }
 
 if ((size = avio_get_dyn_buf(pb_buf, &buf)) > 0) {
@@ -4194,9 +4200,11 @@ static int mov_write_track_udta_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 ffio_wfourcc(pb, "udta");
 avio_write(pb, buf, size);
 }
-ffio_free_dyn_buf(&pb_buf);
+ret = 0;
 
-return 0;
+cleanup:
+ffio_free_dyn_buf(&pb_buf);
+return ret;
 }
 
 static int mov_write_trak_tag(AVFormatContext *s, AVIOContext *pb, 
MOVMuxContext *mov,
-- 
2.50.0.108.g6ae0c543ae

___
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/4] fix leaks in movenc, vorbisenc, lut3d and iamf_writer

2025-06-27 Thread Lidong Yan
Fix multiple leaks in error paths. Simply add av_free() in error path or
replace return AVERROR* with goto cleanup to prevent from leaks.

Lidong Yan (4):
  avformat/movenc: fix multiple leaks in error paths
  avcodec/vorbisenc: fix leak if av_mallocz failed
  avfilter/vf_lut3d: fix leak if allocate_3dlut failed
  avformat/iamf_writer: fix leaks of avio_open_dyn_buf() allocated
memory

 libavcodec/vorbisenc.c|  4 +++-
 libavfilter/vf_lut3d.c|  2 +-
 libavformat/iamf_writer.c | 47 +--
 libavformat/movenc.c  | 22 --
 4 files changed, 49 insertions(+), 26 deletions(-)

-- 
2.50.0.108.g6ae0c543ae

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

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


[FFmpeg-devel] [PATCH 3/4] avfilter/vf_lut3d: fix leak if allocate_3dlut failed

2025-06-27 Thread Lidong Yan
In parse_cinespace(), memory allocated in in_prelut[] and out_prelut[]
would leak if allocate_3dlut() failed. Replace return ret with goto end
to free memory before return error code.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavfilter/vf_lut3d.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c
index 5f6bfc65b3..46afe36f6c 100644
--- a/libavfilter/vf_lut3d.c
+++ b/libavfilter/vf_lut3d.c
@@ -1006,7 +1006,7 @@ static int parse_cinespace(AVFilterContext *ctx, FILE *f)
 
 ret = allocate_3dlut(ctx, size, prelut);
 if (ret < 0)
-return ret;
+goto end;
 
 for (int k = 0; k < size; k++) {
 for (int j = 0; j < size; j++) {
-- 
2.50.0.108.g6ae0c543ae

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

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


[FFmpeg-devel] [PATCH v2 2/3] avformat/iamf_writer: fix leaks of avio_open_dyn_buf() allocated memory

2025-07-09 Thread Lidong Yan
In iamf_write_codec_config(), if codec_id equals to AV_CODEC_ID_AAC,
avio_open_dyn_buf() allocated memory would leak. Add ffio_free_dyn_buf()
to free dyn_bc before return.

In iamf_write_audio_element(), multiple places returns without free
dyn_bc, replace return AVERROR* with goto cleanup and add cleanup code
to free dyn_bc. Do the same thing for iamf_write_audio_element() and
write_parameter_block().

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/iamf_writer.c | 47 +--
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index f88987790d..2e8df602b1 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -523,6 +523,7 @@ static int iamf_write_codec_config(const IAMFContext *iamf,
 avio_write(dyn_bc, codec_config->extradata, 
codec_config->extradata_size);
 break;
 case AV_CODEC_ID_AAC:
+ffio_free_dyn_buf(&dyn_bc);
 return AVERROR_PATCHWELCOME;
 case AV_CODEC_ID_FLAC:
 avio_w8(dyn_bc, 0x80);
@@ -774,7 +775,8 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
 if (layout == 3 || layout == 4 || layout == 6 || layout == 7) {
 av_log(log_ctx, AV_LOG_ERROR, "demixing_info needed but 
not set in Stream Group #%u\n",
audio_element->audio_element_id);
-return AVERROR(EINVAL);
+ret = AVERROR(EINVAL);
+goto cleanup;
 }
 }
 param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING;
@@ -794,7 +796,7 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
 param_def = ff_iamf_get_param_definition(iamf, param->parameter_id);
 ret = param_definition(iamf, param_def, dyn_bc, log_ctx);
 if (ret < 0)
-return ret;
+goto cleanup;
 
 avio_w8(dyn_bc, demix->dmixp_mode << 5); // dmixp_mode
 avio_w8(dyn_bc, element->default_w << 4); // default_w
@@ -806,24 +808,25 @@ static int iamf_write_audio_element(const IAMFContext 
*iamf,
 if (!param) {
 av_log(log_ctx, AV_LOG_ERROR, "recon_gain_info needed but not set 
in Stream Group #%u\n",
audio_element->audio_element_id);
-return AVERROR(EINVAL);
+ret = AVERROR(EINVAL);
+goto cleanup;
 }
 ffio_write_leb(dyn_bc, AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN); // 
type
 
 param_def = ff_iamf_get_param_definition(iamf, param->parameter_id);
 ret = param_definition(iamf, param_def, dyn_bc, log_ctx);
 if (ret < 0)
-return ret;
+goto cleanup;
 }
 
 if (element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL) {
 ret = scalable_channel_layout_config(audio_element, dyn_bc);
 if (ret < 0)
-return ret;
+goto cleanup;
 } else {
 ret = ambisonics_config(audio_element, dyn_bc);
 if (ret < 0)
-return ret;
+goto cleanup;
 }
 
 init_put_bits(&pbc, header, sizeof(header));
@@ -835,9 +838,11 @@ static int iamf_write_audio_element(const IAMFContext 
*iamf,
 avio_write(pb, header, put_bytes_count(&pbc, 1));
 ffio_write_leb(pb, dyn_size);
 avio_write(pb, dyn_buf, dyn_size);
-ffio_free_dyn_buf(&dyn_bc);
+ret = 0;
 
-return 0;
+cleanup:
+ffio_free_dyn_buf(&dyn_bc);
+return ret;
 }
 
 static int iamf_write_mixing_presentation(const IAMFContext *iamf,
@@ -886,7 +891,8 @@ static int iamf_write_mixing_presentation(const IAMFContext 
*iamf,
 if (av_dict_count(submix_element->annotations) != 
av_dict_count(mix->annotations)) {
 av_log(log_ctx, AV_LOG_ERROR, "Inconsistent amount of labels 
in submix %d from Mix Presentation id #%u\n",
j, audio_element->audio_element_id);
-return AVERROR(EINVAL);
+ret = AVERROR(EINVAL);
+goto cleanup;
 }
 while ((tag = av_dict_iterate(submix_element->annotations, tag)))
 avio_put_str(dyn_bc, tag->value);
@@ -901,7 +907,7 @@ static int iamf_write_mixing_presentation(const IAMFContext 
*iamf,
 param_def = ff_iamf_get_param_definition(iamf, 
submix_element->element_mix_config->parameter_id);
 ret = param_definition(iamf, param_def, dyn_bc, log_ctx);
 if (ret < 0)
-return ret;
+goto cleanup;
 
 avio_wb16(dyn_bc, 
rescale_rational(submix_element->default_mix_gain, 1 << 8));
 }
@@ -909,7 +915,7 @@ static int iamf_write_mixing_presentation(const IAMFContext 
*iamf,
 param_def = ff_iamf_get_param_defi

[FFmpeg-devel] [PATCH v2 3/3] swscale/graph: fix leak in adapt_colors()

2025-07-09 Thread Lidong Yan
In adapt_colors(), ff_sws_lut3d_generate() allocates memory in lut.
However if add_legacy_sws_pass() failed, lut leaks. free lut before
return ret.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libswscale/graph.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libswscale/graph.c b/libswscale/graph.c
index dc7784aa49..975a2b6065 100644
--- a/libswscale/graph.c
+++ b/libswscale/graph.c
@@ -523,8 +523,10 @@ static int adapt_colors(SwsGraph *graph, SwsFormat src, 
SwsFormat dst,
 SwsFormat tmp = src;
 tmp.format = fmt_in;
 ret = add_legacy_sws_pass(graph, src, tmp, input, &input);
-if (ret < 0)
+if (ret < 0) {
+ff_sws_lut3d_free(&lut);
 return ret;
+}
 }
 
 ret = ff_sws_lut3d_generate(lut, fmt_in, fmt_out, &map);
-- 
2.50.0.107.g33b6ec8c79

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

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


[FFmpeg-devel] [PATCH v2 0/3] resend fixes for leaks

2025-07-09 Thread Lidong Yan
I am resending patches:
  https://ffmpeg.org/pipermail/ffmpeg-devel/2025-June/345974.html
  https://ffmpeg.org/pipermail/ffmpeg-devel/2025-June/345897.html

Since these patches haven't been noticed for a long time.

I also revised my patch in avformat/sapenc according to Michael's request.

-BEGIN PGP PUBLIC KEY BLOCK-

mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-END PGP PUBLIC KEY BLOCK-

Lidong Yan (3):
  avformat/sapenc: fix leak in sap_write_header()
  avformat/iamf_writer: fix leaks of avio_open_dyn_buf() allocated
memory
  swscale/graph: fix leak in adapt_colors()

 libavformat/iamf_writer.c | 47 +--
 libavformat/sapenc.c  | 13 +++
 libswscale/graph.c|  4 +++-
 3 files changed, 42 insertions(+), 22 deletions(-)

-- 
2.50.0.107.g33b6ec8c79

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

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


[FFmpeg-devel] [PATCH v2 1/3] avformat/sapenc: fix leak in sap_write_header()

2025-07-09 Thread Lidong Yan
In sap_write_header(), ff_format_set_url() assign new allocated new_url
to contexts[i]->url but forgot to free it later. Add for loop to free
contexts[i]->url before av_free(context).

To prevent from writing free-for-loop in every return point, replace
`return 0` with `ret = 0` so normal execution can fall through fail
code.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/sapenc.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 87a834a8d8..0567a754e2 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -233,7 +233,6 @@ static int sap_write_header(AVFormatContext *s)
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
-av_freep(&contexts);
 av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", &sap->ann[pos]);
 pos += strlen(&sap->ann[pos]);
 sap->ann_size = pos;
@@ -244,11 +243,17 @@ static int sap_write_header(AVFormatContext *s)
 goto fail;
 }
 
-return 0;
+ret = 0;
 
 fail:
-av_free(contexts);
-sap_write_close(s);
+if (contexts) {
+for (i = 0; i < s->nb_streams; i++)
+if (contexts[i])
+av_free(contexts[i]->url);
+av_free(contexts);
+}
+if (ret < 0)
+sap_write_close(s);
 return ret;
 }
 
-- 
2.50.0.107.g33b6ec8c79

___
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 1/3] avformat/sapenc: fix leak in sap_write_header()

2025-07-12 Thread Lidong Yan
Michael Niedermayer  write:

> On Thu, Jul 10, 2025 at 10:20:45AM +0800, Lidong Yan wrote:
> > In sap_write_header(), ff_format_set_url() assign new allocated new_url
> > to contexts[i]->url but forgot to free it later. Add for loop to free
> > contexts[i]->url before av_free(context).
> >
> > To prevent from writing free-for-loop in every return point, replace
> > `return 0` with `ret = 0` so normal execution can fall through fail
> > code.
> >
> > Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
> > ---
> >  libavformat/sapenc.c | 13 +
> >  1 file changed, 9 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
> > index 87a834a8d8..0567a754e2 100644
> > --- a/libavformat/sapenc.c
> > +++ b/libavformat/sapenc.c
> > @@ -233,7 +233,6 @@ static int sap_write_header(AVFormatContext *s)
> >  ret = AVERROR_INVALIDDATA;
> >  goto fail;
> >  }
> > -av_freep(&contexts);
> >  av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", &sap->ann[pos]);
> >  pos += strlen(&sap->ann[pos]);
> >  sap->ann_size = pos;
> > @@ -244,11 +243,17 @@ static int sap_write_header(AVFormatContext *s)
> >  goto fail;
> >  }
> >
> > -return 0;
> > +ret = 0;
> >
> >  fail:
> > -av_free(contexts);
> > -sap_write_close(s);
> > +if (contexts) {
> > +for (i = 0; i < s->nb_streams; i++)
> > +if (contexts[i])
> > +av_free(contexts[i]->url);
> > +av_free(contexts);
> > +}
>
> contexts is an array of AVFormatContext, this does not look right
> also freeing the url of the AVFormatContexts that have been stored
> in priv_data a few lines earlier looks wrong
>

I am not sure how to fix then. Maybe I should leave this code alone.

Thanks,
Lidong
___
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] avfilter/asrc_sinc: fix leak in config_input()

2025-06-25 Thread Lidong Yan
In config_input(), fir_to_phase() allocates memory in h[longer].
But if av_calloc() to s->coeffs failed, memory in h[longer] would
leak. Also noticed that after fir_to_phase() there are three return
point, two of them didn't free h[longer]. However, the first return
points means fir_to_phase() failed, which in turn means that memory
in h[longer] has not been allocated yet. To fix this leak, add
av_free(h[longer]) in av_calloc() failed branch would be enough.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavfilter/asrc_sinc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index 6ff3303316..198c322665 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -370,8 +370,10 @@ static int config_output(AVFilterLink *outlink)
 s->n = 1 << (av_log2(n) + 1);
 s->rdft_len = 1 << av_log2(n);
 s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
-if (!s->coeffs)
+if (!s->coeffs) {
+av_free(h[longer]);
 return AVERROR(ENOMEM);
+}
 
 for (i = 0; i < n; i++)
 s->coeffs[i] = h[longer][i];
-- 
2.50.0.108.g6ae0c543ae

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

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


Re: [FFmpeg-devel] [PATCH v4 2/3] avformat/sapenc: fix leak in sap_write_header()

2025-07-06 Thread Lidong Yan
Michael Niedermayer  writes:

>
> contexts will be NULL so i would assume contexts[i] will segfault
>
> thx
>

Sorry and you are right. Gonna fix.

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

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


Re: [FFmpeg-devel] [PATCH 1/5] avcodec/utvideodec: fix leaks in decode_plane() and decode_plane10()

2025-06-29 Thread Lidong Yan
Michael Niedermayer  writes:

> This is not correct
>
> build_huff() does not set these when fsym >= 0
>
> your patch runs free() on random uninitialized variables
>
> before submitting memleak fixes, please verify that
> 1. there is actually a leak
> 2. your patch does not introduce a new anomaly
>

Got it, I will be more careful.

Thanks for your review,
Lidong
___
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 v4 0/3] fix leak in avfilter/asrc_sinc and avformat/sapenc

2025-06-30 Thread Lidong Yan
This patch series fixes memory leaks in `avfilter/asrc_sinc` and
`avformat/sapenc`.

-BEGIN PGP PUBLIC KEY BLOCK-

mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-END PGP PUBLIC KEY BLOCK-

Lidong Yan (3):
  avfilter/asrc_sinc: fix leak in config_input()
  avformat/sapenc: fix leak in sap_write_header()
  avformat/sapenc: reword fail to cleanup in sap_write_header()

 libavfilter/asrc_sinc.c | 18 +++---
 libavformat/sapenc.c| 34 +++---
 2 files changed, 30 insertions(+), 22 deletions(-)

-- 
2.50.0.106.gf0135a9047.dirty

___
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 v4 1/3] avfilter/asrc_sinc: fix leak in config_input()

2025-06-30 Thread Lidong Yan
In config_input(), fir_to_phase() allocates memory in h[longer], which
would leak if av_calloc() to s->coeffs failed. lpf() allocates memory
in h[0] and h[1], which would leak if fir_to_phase() failed. To fix
this leak, add av_free(h[longer]) in as cleanup code, and replace
return AVERROR* with goto cleanup to prevent from leaks.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavfilter/asrc_sinc.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index 6ff3303316..05cf53fed8 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -329,7 +329,7 @@ static int config_output(AVFilterLink *outlink)
 SincContext *s = ctx->priv;
 float Fn = s->sample_rate * .5f;
 float *h[2];
-int i, n, post_peak, longer;
+int i, n, post_peak, longer, ret;
 
 outlink->sample_rate = s->sample_rate;
 s->pts = 0;
@@ -360,9 +360,9 @@ static int config_output(AVFilterLink *outlink)
 }
 
 if (s->phase != 50.f) {
-int ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase);
+ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase);
 if (ret < 0)
-return ret;
+goto cleanup;
 } else {
 post_peak = n >> 1;
 }
@@ -370,17 +370,21 @@ static int config_output(AVFilterLink *outlink)
 s->n = 1 << (av_log2(n) + 1);
 s->rdft_len = 1 << av_log2(n);
 s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
-if (!s->coeffs)
-return AVERROR(ENOMEM);
+if (!s->coeffs) {
+ret = AVERROR(ENOMEM);
+goto cleanup;
+}
 
 for (i = 0; i < n; i++)
 s->coeffs[i] = h[longer][i];
-av_free(h[longer]);
 
 av_tx_uninit(&s->tx);
 av_tx_uninit(&s->itx);
+ret = 0;
 
-return 0;
+cleanup:
+av_free(h[longer]);
+return ret;
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
-- 
2.50.0.106.gf0135a9047.dirty

___
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 v4 2/3] avformat/sapenc: fix leak in sap_write_header()

2025-06-30 Thread Lidong Yan
In sap_write_header(), ff_format_set_url() assign new allocated new_url
to contexts[i]->url but forgot to free it later. Add for loop to free
contexts[i]->url before av_free(context).

To prevent from writing free-for-loop in every return point, replace
`return 0` with `ret = 0` so normal execution can fall through cleanup
code.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/sapenc.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 87a834a8d8..0882690ba5 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -244,11 +244,15 @@ static int sap_write_header(AVFormatContext *s)
 goto fail;
 }
 
-return 0;
+ret = 0;
 
 fail:
+for (i = 0; i < s->nb_streams; i++)
+if (contexts[i])
+av_free(contexts[i]->url);
 av_free(contexts);
-sap_write_close(s);
+if (ret < 0)
+sap_write_close(s);
 return ret;
 }
 
-- 
2.50.0.106.gf0135a9047.dirty

___
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 v4 3/3] avformat/sapenc: reword fail to cleanup in sap_write_header()

2025-06-30 Thread Lidong Yan
In sap_write_header(), normal execution would fall through to fail
labeled code, thus cleanup would be a better name compared to fail.
Replace the use of fail label with cleanup label.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/sapenc.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 0882690ba5..63436b9667 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -113,7 +113,7 @@ static int sap_write_header(AVFormatContext *s)
 if (getaddrinfo(host, NULL, &hints, &ai)) {
 av_log(s, AV_LOG_ERROR, "Unable to resolve %s\n", host);
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 if (ai->ai_family == AF_INET) {
 /* Also known as sap.mcast.net */
@@ -130,7 +130,7 @@ static int sap_write_header(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Host %s resolved to unsupported "
 "address family\n", host);
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 freeaddrinfo(ai);
 }
@@ -138,7 +138,7 @@ static int sap_write_header(AVFormatContext *s)
 contexts = av_calloc(s->nb_streams, sizeof(*contexts));
 if (!contexts) {
 ret = AVERROR(ENOMEM);
-goto fail;
+goto cleanup;
 }
 
 if (s->start_time_realtime == 0  ||  s->start_time_realtime == 
AV_NOPTS_VALUE)
@@ -156,17 +156,17 @@ static int sap_write_header(AVFormatContext *s)
s->protocol_whitelist, 
s->protocol_blacklist, NULL);
 if (ret) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 ret = ff_rtp_chain_mux_open(&contexts[i], s, s->streams[i], fd, 0, i);
 if (ret < 0)
-goto fail;
+goto cleanup;
 s->streams[i]->priv_data = contexts[i];
 s->streams[i]->time_base = contexts[i]->streams[0]->time_base;
 new_url = av_strdup(url);
 if (!new_url) {
 ret = AVERROR(ENOMEM);
-goto fail;
+goto cleanup;
 }
 ff_format_set_url(contexts[i], new_url);
 }
@@ -181,13 +181,13 @@ static int sap_write_header(AVFormatContext *s)
s->protocol_whitelist, s->protocol_blacklist, 
NULL);
 if (ret) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 
 udp_fd = ffurl_get_file_handle(sap->ann_fd);
 if (getsockname(udp_fd, (struct sockaddr*) &localaddr, &addrlen)) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 if (localaddr.ss_family != AF_INET
 #if HAVE_STRUCT_SOCKADDR_IN6
@@ -196,13 +196,13 @@ static int sap_write_header(AVFormatContext *s)
 ) {
 av_log(s, AV_LOG_ERROR, "Unsupported protocol family\n");
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 sap->ann_size = 8192;
 sap->ann = av_mallocz(sap->ann_size);
 if (!sap->ann) {
 ret = AVERROR(EIO);
-goto fail;
+goto cleanup;
 }
 sap->ann[pos] = (1 << 5);
 #if HAVE_STRUCT_SOCKADDR_IN6
@@ -231,7 +231,7 @@ static int sap_write_header(AVFormatContext *s)
 if (av_sdp_create(contexts, s->nb_streams, &sap->ann[pos],
   sap->ann_size - pos)) {
 ret = AVERROR_INVALIDDATA;
-goto fail;
+goto cleanup;
 }
 av_freep(&contexts);
 av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", &sap->ann[pos]);
@@ -241,12 +241,12 @@ static int sap_write_header(AVFormatContext *s)
 if (sap->ann_size > sap->ann_fd->max_packet_size) {
 av_log(s, AV_LOG_ERROR, "Announcement too large to send in one "
 "packet\n");
-goto fail;
+goto cleanup;
 }
 
 ret = 0;
 
-fail:
+cleanup:
 for (i = 0; i < s->nb_streams; i++)
 if (contexts[i])
 av_free(contexts[i]->url);
-- 
2.50.0.106.gf0135a9047.dirty

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

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


[FFmpeg-devel] [PATCH v3 2/2] bloom: optimize multiple pathspec items in revision traversal

2025-06-27 Thread Lidong Yan
To enable optimize multiple pathspec items in revision traversal,
return 0 if all pathspec item is literal in forbid_bloom_filters().
Add code to initialize and check each pathspec item's bloom_keyvec.

Add new function release_revisions_bloom_keyvecs() to free all bloom
keyvec owned by rev_info.

Add new test cases in t/t4216-log-bloom.sh to ensure
  - consistent results between the optimization for multiple pathspec
items using bloom filter and the case without bloom filter
optimization.
  - does not use bloom filter if any pathspec item is not literal.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 revision.c   | 126 ---
 t/t4216-log-bloom.sh |  23 
 2 files changed, 85 insertions(+), 64 deletions(-)

diff --git a/revision.c b/revision.c
index 3aa544c137..8d73395f26 100644
--- a/revision.c
+++ b/revision.c
@@ -675,16 +675,17 @@ static int forbid_bloom_filters(struct pathspec *spec)
 {
if (spec->has_wildcard)
return 1;
-   if (spec->nr > 1)
-   return 1;
if (spec->magic & ~PATHSPEC_LITERAL)
return 1;
-   if (spec->nr && (spec->items[0].magic & ~PATHSPEC_LITERAL))
-   return 1;
+   for (size_t nr = 0; nr < spec->nr; nr++)
+   if (spec->items[nr].magic & ~PATHSPEC_LITERAL)
+   return 1;
 
return 0;
 }
 
+static void release_revisions_bloom_keyvecs(struct rev_info *revs);
+
 static void prepare_to_use_bloom_filter(struct rev_info *revs)
 {
struct pathspec_item *pi;
@@ -692,7 +693,7 @@ static void prepare_to_use_bloom_filter(struct rev_info 
*revs)
char *path_alloc = NULL;
const char *path, *p;
size_t len;
-   int path_component_nr = 1;
+   int path_component_nr;
 
if (!revs->commits)
return;
@@ -709,50 +710,53 @@ static void prepare_to_use_bloom_filter(struct rev_info 
*revs)
if (!revs->pruning.pathspec.nr)
return;
 
-   pi = &revs->pruning.pathspec.items[0];
-
-   /* remove single trailing slash from path, if needed */
-   if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
-   path_alloc = xmemdupz(pi->match, pi->len - 1);
-   path = path_alloc;
-   } else
-   path = pi->match;
-
-   len = strlen(path);
-   if (!len) {
-   revs->bloom_filter_settings = NULL;
-   free(path_alloc);
-   return;
-   }
-
-   p = path;
-   while (*p) {
-   /*
-* At this point, the path is normalized to use Unix-style
-* path separators. This is required due to how the
-* changed-path Bloom filters store the paths.
-*/
-   if (*p == '/')
-   path_component_nr++;
-   p++;
-   }
-
-   revs->bloom_keyvecs_nr = 1;
-   CALLOC_ARRAY(revs->bloom_keyvecs, 1);
-   bloom_keyvec = create_bloom_keyvec(path_component_nr);
-   revs->bloom_keyvecs[0] = bloom_keyvec;
+   revs->bloom_keyvecs_nr = revs->pruning.pathspec.nr;
+   CALLOC_ARRAY(revs->bloom_keyvecs, revs->bloom_keyvecs_nr);
+   for (int i = 0; i < revs->pruning.pathspec.nr; i++) {
+   pi = &revs->pruning.pathspec.items[i];
+   path_component_nr = 1;
+
+   /* remove single trailing slash from path, if needed */
+   if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
+   path_alloc = xmemdupz(pi->match, pi->len - 1);
+   path = path_alloc;
+   } else
+   path = pi->match;
+
+   len = strlen(path);
+   if (!len)
+   goto fail;
+
+   p = path;
+   while (*p) {
+   /*
+* At this point, the path is normalized to use
+* Unix-style path separators. This is required due to
+* how the changed-path Bloom filters store the paths.
+*/
+   if (*p == '/')
+   path_component_nr++;
+   p++;
+   }
 
-   fill_bloom_keyvec_key(path, len, bloom_keyvec, 0,
- revs->bloom_filter_settings);
-   path_component_nr = 1;
+   bloom_keyvec = create_bloom_keyvec(path_component_nr);
+   revs->bloom_keyvecs[i] = bloom_keyvec;
+
+   fill_bloom_keyvec_key(path, len, bloom_keyvec, 0,
+  revs->bloom_filter_settings);
+   path_component_nr = 1;
+
+   p = path

[FFmpeg-devel] [PATCH v3 1/2] bloom: replace struct bloom_key * with struct bloom_keyvec

2025-06-27 Thread Lidong Yan
The revision traversal limited by pathspec has optimization when
the pathspec has only one element. To support optimization for
multiple pathspec items, we need to modify the data structures
in struct rev_info.

struct rev_info uses bloom_keys and bloom_nr to store the bloom keys
corresponding to a single pathspec item. To allow struct rev_info
to store bloom keys for multiple pathspec items, a new data structure
`struct bloom_keyvec` is introduced. Each `struct bloom_keyvec`
corresponds to a single pathspec item.

In `struct rev_info`, replace bloom_keys and bloom_nr with bloom_keyvecs
and bloom_keyvec_nr. This commit still optimize one pathspec item, thus
bloom_keyvec_nr can only be 0 or 1.

New *_bloom_keyvec functions are added to create and destroy a keyvec.
bloom_filter_contains_vec() is added to check if all key in keyvec is
contained in a bloom filter. fill_bloom_keyvec_key() is added to
initialize a key in keyvec.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 bloom.c| 31 +++
 bloom.h| 20 
 revision.c | 36 ++--
 revision.h |  6 +++---
 4 files changed, 72 insertions(+), 21 deletions(-)

diff --git a/bloom.c b/bloom.c
index 0c8d2cebf9..8259cfce51 100644
--- a/bloom.c
+++ b/bloom.c
@@ -280,6 +280,25 @@ void deinit_bloom_filters(void)
deep_clear_bloom_filter_slab(&bloom_filters, free_one_bloom_filter);
 }
 
+struct bloom_keyvec *create_bloom_keyvec(size_t count)
+{
+   struct bloom_keyvec *vec;
+   size_t sz = sizeof(struct bloom_keyvec);
+   sz += count * sizeof(struct bloom_key);
+   vec = (struct bloom_keyvec *)xcalloc(1, sz);
+   vec->count = count;
+   return vec;
+}
+
+void destroy_bloom_keyvec(struct bloom_keyvec *vec)
+{
+   if (!vec)
+   return;
+   for (size_t nr = 0; nr < vec->count; nr++)
+   clear_bloom_key(&vec->key[nr]);
+   free(vec);
+}
+
 static int pathmap_cmp(const void *hashmap_cmp_fn_data UNUSED,
   const struct hashmap_entry *eptr,
   const struct hashmap_entry *entry_or_key,
@@ -540,3 +559,15 @@ int bloom_filter_contains(const struct bloom_filter 
*filter,
 
return 1;
 }
+
+int bloom_filter_contains_vec(const struct bloom_filter *filter,
+ const struct bloom_keyvec *vec,
+ const struct bloom_filter_settings *settings)
+{
+   int ret = 1;
+
+   for (size_t nr = 0; ret > 0 && nr < vec->count; nr++)
+   ret = bloom_filter_contains(filter, &vec->key[nr], settings);
+
+   return ret;
+}
diff --git a/bloom.h b/bloom.h
index 6e46489a20..9e4e832c8c 100644
--- a/bloom.h
+++ b/bloom.h
@@ -74,6 +74,11 @@ struct bloom_key {
uint32_t *hashes;
 };
 
+struct bloom_keyvec {
+   size_t count;
+   struct bloom_key key[FLEX_ARRAY];
+};
+
 int load_bloom_filter_from_graph(struct commit_graph *g,
 struct bloom_filter *filter,
 uint32_t graph_pos);
@@ -100,6 +105,17 @@ void add_key_to_filter(const struct bloom_key *key,
 void init_bloom_filters(void);
 void deinit_bloom_filters(void);
 
+struct bloom_keyvec *create_bloom_keyvec(size_t count);
+void destroy_bloom_keyvec(struct bloom_keyvec *vec);
+
+static inline void fill_bloom_keyvec_key(const char *data, size_t len,
+struct bloom_keyvec *vec, size_t nr,
+const struct bloom_filter_settings 
*settings)
+{
+   assert(nr < vec->count);
+   fill_bloom_key(data, len, &vec->key[nr], settings);
+}
+
 enum bloom_filter_computed {
BLOOM_NOT_COMPUTED = (1 << 0),
BLOOM_COMPUTED = (1 << 1),
@@ -137,4 +153,8 @@ int bloom_filter_contains(const struct bloom_filter *filter,
  const struct bloom_key *key,
  const struct bloom_filter_settings *settings);
 
+int bloom_filter_contains_vec(const struct bloom_filter *filter,
+ const struct bloom_keyvec *v,
+ const struct bloom_filter_settings *settings);
+
 #endif
diff --git a/revision.c b/revision.c
index afee96..3aa544c137 100644
--- a/revision.c
+++ b/revision.c
@@ -688,6 +688,7 @@ static int forbid_bloom_filters(struct pathspec *spec)
 static void prepare_to_use_bloom_filter(struct rev_info *revs)
 {
struct pathspec_item *pi;
+   struct bloom_keyvec *bloom_keyvec;
char *path_alloc = NULL;
const char *path, *p;
size_t len;
@@ -736,19 +737,21 @@ static void prepare_to_use_bloom_filter(struct rev_info 
*revs)
p++;
}
 
-   revs->bloom_keys_nr = path_component_nr;
-   ALLOC_ARRAY(revs->bloom_keys, revs->bloom_keys_nr);
+   revs->bloom_keyvecs_nr = 1;
+   CALLOC_ARRA

[FFmpeg-devel] [PATCH v3 0/2] bloom: enable bloom filter optimization for multiple pathspec elements in revision traversal

2025-06-27 Thread Lidong Yan
This series enables bloom filter optimization for multiple pathspec
elements. Compared to v2, v3 fixed bugs in forbid_bloom_filter() and
add one more test case in t/t4216-log-bloom.sh.

Lidong Yan (2):
  bloom: replace struct bloom_key * with struct bloom_keyvec
  bloom: optimize multiple pathspec items in revision traversal

 bloom.c  |  31 +++
 bloom.h  |  20 +++
 revision.c   | 126 ---
 revision.h   |   6 +--
 t/t4216-log-bloom.sh |  23 
 5 files changed, 139 insertions(+), 67 deletions(-)

-- 
2.50.0.108.g6ae0c543ae

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

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


Re: [FFmpeg-devel] [PATCH v3 2/2] bloom: optimize multiple pathspec items in revision traversal

2025-06-27 Thread Lidong Yan
Sorry, I filled in the wrong recipient address. Please forgive me and ignore
this email.
___
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] fix multiple memory leaks

2025-06-28 Thread Lidong Yan
This patch series fix multiple memory leaks in error path and early
return point.

-BEGIN PGP PUBLIC KEY BLOCK-

mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-END PGP PUBLIC KEY BLOCK-

Lidong Yan (5):
  avcodec/utvideodec: fix leaks in decode_plane() and decode_plane10()
  avformat/rtpdec_latm: fix leak in parse_fmtp_config()
  swscale/graph: fix leak in adapt_colors()
  avcodec/sunrast: fix leak in sunrast_decode_frame()
  avformat/rtpdec_asf: fix leak in ff_wms_parse_sdp_a_line()

 libavcodec/sunrast.c  | 4 +++-
 libavcodec/utvideodec.c   | 6 --
 libavformat/rtpdec_asf.c  | 4 +++-
 libavformat/rtpdec_latm.c | 2 +-
 libswscale/graph.c| 4 +++-
 5 files changed, 14 insertions(+), 6 deletions(-)

-- 
2.50.0.106.gf0135a9047.dirty

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

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


[FFmpeg-devel] [PATCH 1/5] avcodec/utvideodec: fix leaks in decode_plane() and decode_plane10()

2025-06-28 Thread Lidong Yan
In decode_plane() and decode_plane10(), both of these two functions use
build_buff() which allocates memory in vlc and multi. And both of them
forget to release vlc and multi when build_buff report a symbol to fill
slices with. Add cleanup label and goto cleanup first before return 0.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavcodec/utvideodec.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index 4c0fa2ca67..f15d623462 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -179,7 +179,7 @@ static int decode_plane10(UtvideoContext *c, int plane_no,
 dest += stride;
 }
 }
-return 0;
+goto cleanup;
 }
 
 send = 0;
@@ -216,6 +216,7 @@ static int decode_plane10(UtvideoContext *c, int plane_no,
"%d bits left after decoding slice\n", get_bits_left(&gb));
 }
 
+cleanup:
 ff_vlc_free(&vlc);
 ff_vlc_free_multi(&multi);
 
@@ -322,7 +323,7 @@ static int decode_plane(UtvideoContext *c, int plane_no,
 dest += stride;
 }
 }
-return 0;
+goto cleanup;
 }
 
 src  += 256;
@@ -361,6 +362,7 @@ static int decode_plane(UtvideoContext *c, int plane_no,
"%d bits left after decoding slice\n", get_bits_left(&gb));
 }
 
+cleanup:
 ff_vlc_free(&vlc);
 ff_vlc_free_multi(&multi);
 
-- 
2.50.0.106.gf0135a9047.dirty

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

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


[FFmpeg-devel] [PATCH 2/5] avformat/rtpdec_latm: fix leak in parse_fmtp_config()

2025-06-28 Thread Lidong Yan
av_mallocz() allocates memory in config, but we forget to free it
if init_get_bits() failed. Replace return ret with goto end.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/rtpdec_latm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c
index 2b4478289e..74523c167d 100644
--- a/libavformat/rtpdec_latm.c
+++ b/libavformat/rtpdec_latm.c
@@ -104,7 +104,7 @@ static int parse_fmtp_config(AVStream *st, const char 
*value)
 ff_hex_to_data(config, value);
 ret = init_get_bits(&gb, config, len*8);
 if (ret < 0)
-return ret;
+goto end;
 audio_mux_version = get_bits(&gb, 1);
 same_time_framing = get_bits(&gb, 1);
 skip_bits(&gb, 6); /* num_sub_frames */
-- 
2.50.0.106.gf0135a9047.dirty

___
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] fix multiple memory leaks

2025-06-28 Thread Lidong Yan
This patch series fix multiple memory leaks in error path and early
return point.

Lidong Yan (5):
  avcodec/utvideodec: fix leaks in decode_plane() and decode_plane10()
  avformat/rtpdec_latm: fix leak in parse_fmtp_config()
  swscale/graph: fix leak in adapt_colors()
  avcodec/sunrast: fix leak in sunrast_decode_frame()
  avformat/rtpdec_asf: fix leak in ff_wms_parse_sdp_a_line()

 libavcodec/sunrast.c  | 4 +++-
 libavcodec/utvideodec.c   | 6 --
 libavformat/rtpdec_asf.c  | 4 +++-
 libavformat/rtpdec_latm.c | 2 +-
 libswscale/graph.c| 4 +++-
 5 files changed, 14 insertions(+), 6 deletions(-)

-- 
2.50.0.106.gf0135a9047.dirty

___
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] swscale/graph: fix leak in adapt_colors()

2025-06-28 Thread Lidong Yan
In adapt_colors(), ff_sws_lut3d_generate() allocates memory in lut.
However if add_legacy_sws_pass() failed, lut leaks. free lut before
return ret.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libswscale/graph.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libswscale/graph.c b/libswscale/graph.c
index dc7784aa49..975a2b6065 100644
--- a/libswscale/graph.c
+++ b/libswscale/graph.c
@@ -523,8 +523,10 @@ static int adapt_colors(SwsGraph *graph, SwsFormat src, 
SwsFormat dst,
 SwsFormat tmp = src;
 tmp.format = fmt_in;
 ret = add_legacy_sws_pass(graph, src, tmp, input, &input);
-if (ret < 0)
+if (ret < 0) {
+ff_sws_lut3d_free(&lut);
 return ret;
+}
 }
 
 ret = ff_sws_lut3d_generate(lut, fmt_in, fmt_out, &map);
-- 
2.50.0.106.gf0135a9047.dirty

___
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] avcodec/sunrast: fix leak in sunrast_decode_frame()

2025-06-28 Thread Lidong Yan
In sunrast_decode_frame(), we use av_malloc_array() allocates memory
to ptr and ptr2. However if buf_end - buf < 1, this function returns
error code without freeing this memory thus cause a leak. Add av_freep()
before return.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavcodec/sunrast.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
index 9e49c4f275..cc27838f5b 100644
--- a/libavcodec/sunrast.c
+++ b/libavcodec/sunrast.c
@@ -163,8 +163,10 @@ static int sunrast_decode_frame(AVCodecContext *avctx, 
AVFrame *p,
 x = 0;
 while (ptr != end && buf < buf_end) {
 run = 1;
-if (buf_end - buf < 1)
+if (buf_end - buf < 1) {
+av_freep(&ptr2);
 return AVERROR_INVALIDDATA;
+}
 
 if ((value = *buf++) == RLE_TRIGGER) {
 run = *buf++ + 1;
-- 
2.50.0.106.gf0135a9047.dirty

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

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


[FFmpeg-devel] [PATCH 5/5] avformat/rtpdec_asf: fix leak in ff_wms_parse_sdp_a_line()

2025-06-28 Thread Lidong Yan
In ff_wms_parse_sdp_a_line(), it allocates memory in buf, but doesn't
free buf when avformat_alloc_context() failed. Add av_free(buf) before
return to prevent from leak.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>
---
 libavformat/rtpdec_asf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c
index 9664623e57..b3b346f3cc 100644
--- a/libavformat/rtpdec_asf.c
+++ b/libavformat/rtpdec_asf.c
@@ -120,8 +120,10 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char 
*p)
 avformat_close_input(&rt->asf_ctx);
 }
 
-if (!(iformat = av_find_input_format("asf")))
+if (!(iformat = av_find_input_format("asf"))) {
+av_free(buf);
 return AVERROR_DEMUXER_NOT_FOUND;
+}
 
 rt->asf_ctx = avformat_alloc_context();
 if (!rt->asf_ctx) {
-- 
2.50.0.106.gf0135a9047.dirty

___
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/4] avfilter/asrc_sinc: fix leak in config_input()

2025-06-28 Thread Lidong Yan
Michael Niedermayer  writes:

> failure of av_tx_init() with your patch results in a leak:
>

I send a new patch in
https://ffmpeg.org/pipermail/ffmpeg-devel/2025-June/345932.html
___
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/4] avfilter/asrc_sinc: fix leak in config_input()

2025-06-27 Thread Lidong Yan
Michael Niedermayer  wrote:

> failure of av_tx_init() with your patch results in a leak:
>
> ==3653806== 1,260 bytes in 1 blocks are definitely lost in loss record 6
> of 14
> ==3653806==at 0x483E0F0: memalign (in
> /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==3653806==by 0x483E212: posix_memalign (in
> /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==3653806==by 0x148AE90: av_malloc (mem.c:107)
> ==3653806==by 0x148B2A4: av_mallocz (mem.c:258)
> ==3653806==by 0x148B31B: av_calloc (mem.c:269)
> ==3653806==by 0x2AD864: make_lpf (asrc_sinc.c:101)
> ==3653806==by 0x2AE052: lpf (asrc_sinc.c:183)
> ==3653806==by 0x2AEFD4: config_output (asrc_sinc.c:344)
> ==3653806==by 0x2DD0C6: ff_filter_config_links (avfilter.c:384)
> ==3653806==by 0x2E0FBD: graph_config_links (avfiltergraph.c:255)
> ==3653806==by 0x2E4DFA: avfilter_graph_config (avfiltergraph.c:1303)
> ==3653806==by 0x297A39: lavfi_read_header (lavfi.c:282)
> ==3653806==by 0x667DF2: avformat_open_input (demux.c:309)
> ==3653806==by 0x2512DD: ifile_open (ffmpeg_demux.c:1773)
> ==3653806==by 0x272B02: open_files (ffmpeg_opt.c:1366)
> ==3653806==by 0x272D72: ffmpeg_parse_options (ffmpeg_opt.c:1415)
> ==3653806==by 0x292489: main (ffmpeg.c:991)
>

Sorry about that, I just being stupid. failure of fir_to_phase() would
leave the origin memory
allocated by lpf() in h[longer] unchanged thus cause a leak. I will replace
return ret with
goto fail.

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

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


[FFmpeg-devel] [PATCH v3] avfilter/asrc_sinc: fix leak in config_input()

2025-06-28 Thread Lidong Yan
In config_input(), fir_to_phase() allocates memory in h[longer], which
would leak if av_calloc() to s->coeffs failed. lpf() allocates memory
in h[0] and h[1], which would leak if fir_to_phase() failed. To fix
this leak, add av_free(h[longer]) in as cleanup code, and replace
return AVERROR* with goto cleanup to prevent from leaks.

Signed-off-by: Lidong Yan <502024330...@smail.nju.edu.cn>

-BEGIN PGP PUBLIC KEY BLOCK-

mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-END PGP PUBLIC KEY BLOCK-

---
 libavfilter/asrc_sinc.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index 6ff3303316..63cb04d444 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -329,7 +329,7 @@ static int config_output(AVFilterLink *outlink)
 SincContext *s = ctx->priv;
 float Fn = s->sample_rate * .5f;
 float *h[2];
-int i, n, post_peak, longer;
+int i, n, post_peak, longer, ret;
 
 outlink->sample_rate = s->sample_rate;
 s->pts = 0;
@@ -360,9 +360,9 @@ static int config_output(AVFilterLink *outlink)
 }
 
 if (s->phase != 50.f) {
-int ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase);
+ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase);
 if (ret < 0)
-return ret;
+goto cleanup;
 } else {
 post_peak = n >> 1;
 }
@@ -370,16 +370,20 @@ static int config_output(AVFilterLink *outlink)
 s->n = 1 << (av_log2(n) + 1);
 s->rdft_len = 1 << av_log2(n);
 s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
-if (!s->coeffs)
-return AVERROR(ENOMEM);
+if (!s->coeffs) {
+ret = AVERROR(ENOMEM);
+goto cleanup;
+}
 
 for (i = 0; i < n; i++)
 s->coeffs[i] = h[longer][i];
-av_free(h[longer]);
 
 av_tx_uninit(&s->tx);
 av_tx_uninit(&s->itx);
+ret = 0;
 
+cleanup:
+av_free(h[longer]);
 return 0;
 }
 
-- 
2.50.0.108.g6ae0c543ae

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

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


Re: [FFmpeg-devel] [PATCH v3] avfilter/asrc_sinc: fix leak in config_input()

2025-06-29 Thread Lidong Yan
Michael Niedermayer  writes:

> > +cleanup:
> > +av_free(h[longer]);
> >  return 0;
>
> this is not the correct return code
>

Sorry about that, gonna fix.

Thanks,
Lidong
___
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".