[FFmpeg-devel] [PATCH] avformat/avisynth: remove framedata variable

2022-02-19 Thread Stephen Hutchinson
It's just a simple index.

Addresses Coverity issue 1500290

Signed-off-by: Stephen Hutchinson 
---
 libavformat/avisynth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 03489f180f..318588ff52 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -244,7 +244,7 @@ static int avisynth_create_stream_video(AVFormatContext *s, 
AVStream *st)
 AviSynthContext *avs = s->priv_data;
 const AVS_Map *avsmap;
 AVS_VideoFrame *frame;
-int framedata, error;
+int error;
 int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: 
Planar RGBA
 
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -507,7 +507,7 @@ static int avisynth_create_stream_video(AVFormatContext *s, 
AVStream *st)
 
 if (avs_library.avs_get_version(avs->clip) >= 9) {
 
-frame  = avs_library.avs_get_frame(avs->clip, framedata);
+frame  = avs_library.avs_get_frame(avs->clip, 0);
 avsmap = avs_library.avs_get_frame_props_ro(avs->env, frame);
 
 /* Field order */
-- 
2.32.0

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

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


Re: [FFmpeg-devel] [PATCH 2/2] avformat/avisynth: make sure framedata variable is initialized

2022-02-19 Thread Stephen Hutchinson

On 2/19/22 5:45 PM, Andreas Rheinhardt wrote:

Stephen Hutchinson:

Addresses Coverity issue 1500290

Signed-off-by: Stephen Hutchinson 
---
  libavformat/avisynth.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 03489f180f..cfb7b2a783 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -244,7 +244,8 @@ static int avisynth_create_stream_video(AVFormatContext *s, 
AVStream *st)
  AviSynthContext *avs = s->priv_data;
  const AVS_Map *avsmap;
  AVS_VideoFrame *frame;
-int framedata, error;
+int framedata = 0;
+int error;
  int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: 
Planar RGBA
  
  st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;


Looking at the naming in
https://github.com/AviSynth/AviSynthPlus/blob/master/avs_core/core/avisynth_c.cpp#L828
makes me believe that this variable is actually a frame number. If so,
it is misnamed and this could be fixed easily by just removing this
variable. Am I right?



It seems so.  I think I was just going off of the way avs_get_frame was 
used in avisynth_read_packet_video (as I was also trying to see whether 
some of the other properties* should be read per-frame from within 
read_packet_video), but there's no need to do that with the simpler ones 
in avisynth_create_stream_video.


*related to timestamps or to HDR mastering information, but I'm thinking 
that's going to require adding an entire function to the demuxer to be 
able to set side metadata (at least for the HDR stuff, anyway).

___
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/avisynth: make sure framedata variable is initialized

2022-02-19 Thread Andreas Rheinhardt
Stephen Hutchinson:
> Addresses Coverity issue 1500290
> 
> Signed-off-by: Stephen Hutchinson 
> ---
>  libavformat/avisynth.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
> index 03489f180f..cfb7b2a783 100644
> --- a/libavformat/avisynth.c
> +++ b/libavformat/avisynth.c
> @@ -244,7 +244,8 @@ static int avisynth_create_stream_video(AVFormatContext 
> *s, AVStream *st)
>  AviSynthContext *avs = s->priv_data;
>  const AVS_Map *avsmap;
>  AVS_VideoFrame *frame;
> -int framedata, error;
> +int framedata = 0;
> +int error;
>  int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: 
> Planar RGBA
>  
>  st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;

Looking at the naming in
https://github.com/AviSynth/AviSynthPlus/blob/master/avs_core/core/avisynth_c.cpp#L828
makes me believe that this variable is actually a frame number. If so,
it is misnamed and this could be fixed easily by just removing this
variable. Am I right?

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

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


Re: [FFmpeg-devel] [PATCH 2/3] avisynth: use AviSynth+'s frame properties to set various fields

2022-02-19 Thread Stephen Hutchinson

On 2/19/22 3:39 PM, Andreas Rheinhardt wrote:

+if (frameprop = true) {
+
+frame  = avs_library.avs_get_frame(avs->clip, framedata);


framedata is completely uninitialized here. I presume it should be zero
(for the first frame)? (This is Coverity issue 1500290.)



I don't remember why I left that uninitialized (there's a vague memory 
of something, almost certainly unrelated since it works now, but it was 
months ago at this point).


Patch sent.
___
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] swscale: Take the destination range into account for yuv->rgb->yuv conversions

2022-02-19 Thread Martin Storsjö

On Sat, 19 Feb 2022, Michael Niedermayer wrote:


On Fri, Feb 18, 2022 at 04:45:46PM +0200, Martin Storsjö wrote:

The range parameters need to be set up before calling
sws_init_context (which selects which fastpaths can be used;
this gets called by sws_getContext); solely passing them via
sws_setColorspaceDetails isn't enough.

This fixes producing full range YUV range output when doing
YUV->YUV conversions between different YUV color spaces.

Signed-off-by: Martin Storsjö 
---
 libswscale/utils.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)


Probably ok

please add a fate test for this


Sure. I'm not offhand familiar with what kinds of tests we have for 
swscale right now, and where a test for this would fit in best. (It's 
reproducible by converting from e.g. BT601 to BT709 or vice versa, when 
the output is supposed to be full range.)


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

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


[FFmpeg-devel] [PATCH 2/2] avformat/avisynth: make sure framedata variable is initialized

2022-02-19 Thread Stephen Hutchinson
Addresses Coverity issue 1500290

Signed-off-by: Stephen Hutchinson 
---
 libavformat/avisynth.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 03489f180f..cfb7b2a783 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -244,7 +244,8 @@ static int avisynth_create_stream_video(AVFormatContext *s, 
AVStream *st)
 AviSynthContext *avs = s->priv_data;
 const AVS_Map *avsmap;
 AVS_VideoFrame *frame;
-int framedata, error;
+int framedata = 0;
+int error;
 int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: 
Planar RGBA
 
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 1/2] avformat/avisynth: remove unused variable 'frameprop'

2022-02-19 Thread Stephen Hutchinson
Since the check got simplified and stdbool was no longer necessary
to include, neither is that variable.  Silences a warning.

Signed-off-by: Stephen Hutchinson 
---
 libavformat/avisynth.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 2bd0c6949b..03489f180f 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -245,7 +245,6 @@ static int avisynth_create_stream_video(AVFormatContext *s, 
AVStream *st)
 const AVS_Map *avsmap;
 AVS_VideoFrame *frame;
 int framedata, error;
-bool frameprop;
 int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: 
Planar RGBA
 
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
-- 
2.32.0

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

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


Re: [FFmpeg-devel] [PATCH 1/2] lavfi: add ff_inoutlink_check_flow()

2022-02-19 Thread Paul B Mahol
OK for the set.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 2/3] avisynth: use AviSynth+'s frame properties to set various fields

2022-02-19 Thread Andreas Rheinhardt
Stephen Hutchinson:
> * Field Order
> * Chroma Location
> * Color Transfer Characteristics
> * Color Range
> * Color Primaries
> * Matrix Coefficients
> 
> The existing TFF/BFF detection is retained as a fallback for
> older versions of AviSynth that can't access frame properties.
> The other properties have no legacy equivalent to detect them.
> 
> Signed-off-by: Stephen Hutchinson 
> ---
>  libavformat/avisynth.c | 263 +++--
>  1 file changed, 250 insertions(+), 13 deletions(-)
> 
> diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
> index 1e862a6a85..8bc39869a3 100644
> --- a/libavformat/avisynth.c
> +++ b/libavformat/avisynth.c
> @@ -19,6 +19,8 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>  
> +#include 
> +
>  #include "libavutil/attributes.h"
>  #include "libavutil/internal.h"
>  
> @@ -76,6 +78,9 @@ typedef struct AviSynthLibrary {
>  AVSC_DECLARE_FUNC(avs_get_row_size_p);
>  AVSC_DECLARE_FUNC(avs_is_planar_rgb);
>  AVSC_DECLARE_FUNC(avs_is_planar_rgba);
> +AVSC_DECLARE_FUNC(avs_get_frame_props_ro);
> +AVSC_DECLARE_FUNC(avs_prop_get_int);
> +AVSC_DECLARE_FUNC(avs_get_env_property);
>  #undef AVSC_DECLARE_FUNC
>  } AviSynthLibrary;
>  
> @@ -153,6 +158,9 @@ static av_cold int avisynth_load_library(void)
>  LOAD_AVS_FUNC(avs_get_row_size_p, 1);
>  LOAD_AVS_FUNC(avs_is_planar_rgb, 1);
>  LOAD_AVS_FUNC(avs_is_planar_rgba, 1);
> +LOAD_AVS_FUNC(avs_get_frame_props_ro, 1);
> +LOAD_AVS_FUNC(avs_prop_get_int, 1);
> +LOAD_AVS_FUNC(avs_get_env_property, 1);
>  #undef LOAD_AVS_FUNC
>  
>  atexit(avisynth_atexit_handler);
> @@ -236,6 +244,10 @@ static av_cold void avisynth_atexit_handler(void)
>  static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
>  {
>  AviSynthContext *avs = s->priv_data;
> +const AVS_Map *avsmap;
> +AVS_VideoFrame *frame;
> +int framedata, error;
> +bool frameprop;
>  int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: 
> Planar RGBA
>  
>  st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> @@ -251,19 +263,6 @@ static int avisynth_create_stream_video(AVFormatContext 
> *s, AVStream *st)
>  avpriv_set_pts_info(st, 32, avs->vi->fps_denominator, 
> avs->vi->fps_numerator);
>  
>  
> -st->codecpar->field_order = AV_FIELD_UNKNOWN;
> -/* AviSynth works with frame-based video, detecting field order can
> - * only work when avs_is_field_based returns 'false'. */
> -av_log(s, AV_LOG_TRACE, "avs_is_field_based: %d\n", 
> avs_is_field_based(avs->vi));
> -if (avs_is_field_based(avs->vi) == 0) {
> -if (avs_is_tff(avs->vi)) {
> -st->codecpar->field_order = AV_FIELD_TT;
> -}
> -else if (avs_is_bff(avs->vi)) {
> -st->codecpar->field_order = AV_FIELD_BB;
> -}
> -}
> -
>  switch (avs->vi->pixel_type) {
>  /* 10~16-bit YUV pix_fmts (AviSynth+) */
>  case AVS_CS_YUV444P10:
> @@ -499,6 +498,244 @@ static int avisynth_create_stream_video(AVFormatContext 
> *s, AVStream *st)
>  avs->n_planes = 1;
>  avs->planes   = avs_planes_packed;
>  }
> +
> +/* Read AviSynth+'s frame properties to set additional info.
> + *
> + * Due to a bug preventing the C interface from accessing frame
> + * properties in earlier versions of interface version 8, only
> + * enable this if we detect version 8.1 at the minimum. */
> +
> +if (!avs_library.avs_get_env_property) {
> +av_log(s, AV_LOG_TRACE, "%s\n",
> +   "avs_get_env_property does not exist in AviSynth library; 
> frame properties won't be checked.");
> +frameprop = false;
> +} else {
> +if (avs_library.avs_get_env_property(avs->env, 
> AVS_AEP_INTERFACE_BUGFIX)) {
> +av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.1 or 
> higher, reading frame properties.");
> +frameprop = true;
> +} else {
> +av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.0, 
> need 8.1+ to read frame properties.");
> +frameprop = false;
> +}
> +}
> +
> +if (frameprop = true) {
> +
> +frame  = avs_library.avs_get_frame(avs->clip, framedata);

framedata is completely uninitialized here. I presume it should be zero
(for the first frame)? (This is Coverity issue 1500290.)

> +avsmap = avs_library.avs_get_frame_props_ro(avs->env, frame);
> +
> +/* Field order */
> +switch (avs_library.avs_prop_get_int(avs->env, avsmap, 
> "_FieldBased", 0, &error)) {
> +case 0:
> +st->codecpar->field_order = AV_FIELD_PROGRESSIVE;
> +break;
> +case 1:
> +st->codecpar->field_order = AV_FIELD_BB;
> +break;
> +case 2:
> +st->codecpar->field_order = AV_FIELD_TT;
> +break;
> +default:
> +st->codecpar->field

Re: [FFmpeg-devel] [PATCH] avfilter/vf_fps: only give frame as soon as possible if really requested by output

2022-02-19 Thread Nicolas George
Nicolas George (12022-02-19):
> This would break input-driven filtering I think. I am looking into it.

See:

https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293240.html
https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293241.html

Regards,

-- 
  Nicolas George


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

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


[FFmpeg-devel] [PATCH 2/2] lavfi/vf_fps: check flow before sending more frames

2022-02-19 Thread Nicolas George
Analyzed by Paul B Mahol .

Fixes OOM in #9081.

Signed-off-by: Nicolas George 
---
 libavfilter/vf_fps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index 99e679441e..0e5a1fec35 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -351,7 +351,7 @@ static int activate(AVFilterContext *ctx)
 if (s->frames_count > 0) {
 ret = write_frame(ctx, s, outlink, &again);
 /* Couldn't generate a frame, so schedule us to perform another step */
-if (again)
+if (again && ff_inoutlink_check_flow(inlink, outlink))
 ff_filter_set_ready(ctx, 100);
 return ret;
 }
-- 
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 1/2] lavfi: add ff_inoutlink_check_flow()

2022-02-19 Thread Nicolas George
Signed-off-by: Nicolas George 
---
 libavfilter/avfilter.c | 8 
 libavfilter/filters.h  | 8 
 2 files changed, 16 insertions(+)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..1f37a70179 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -1559,6 +1559,14 @@ int ff_outlink_get_status(AVFilterLink *link)
 return link->status_in;
 }
 
+int ff_inoutlink_check_flow(AVFilterLink *inlink, AVFilterLink *outlink)
+{
+return ff_outlink_frame_wanted(outlink) ||
+   ff_inlink_check_available_frame(inlink) ||
+   inlink->status_out;
+}
+
+
 const AVClass *avfilter_get_class(void)
 {
 return &avfilter_class;
diff --git a/libavfilter/filters.h b/libavfilter/filters.h
index 1157755403..86bc49d459 100644
--- a/libavfilter/filters.h
+++ b/libavfilter/filters.h
@@ -258,4 +258,12 @@ static inline void ff_outlink_set_status(AVFilterLink 
*link, int status, int64_t
 } \
 } while (0)
 
+/**
+ * Check for flow control between input and output.
+ * This is necessary for filters that may produce several output frames for
+ * a single input event, otherwise they may produce them all at once,
+ * causing excessive memory consumption.
+ */
+int ff_inoutlink_check_flow(AVFilterLink *inlink, AVFilterLink *outlink);
+
 #endif /* AVFILTER_FILTERS_H */
-- 
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".


Re: [FFmpeg-devel] [PATCH] swscale: Take the destination range into account for yuv->rgb->yuv conversions

2022-02-19 Thread Michael Niedermayer
On Fri, Feb 18, 2022 at 04:45:46PM +0200, Martin Storsjö wrote:
> The range parameters need to be set up before calling
> sws_init_context (which selects which fastpaths can be used;
> this gets called by sws_getContext); solely passing them via
> sws_setColorspaceDetails isn't enough.
> 
> This fixes producing full range YUV range output when doing
> YUV->YUV conversions between different YUV color spaces.
> 
> Signed-off-by: Martin Storsjö 
> ---
>  libswscale/utils.c | 11 ---
>  1 file changed, 8 insertions(+), 3 deletions(-)

Probably ok

please add a fate test for this

thx

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

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued


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

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


[FFmpeg-devel] [PATCH 2/2] fftools/ffprobe: Remove redundant checks

2022-02-19 Thread Andreas Rheinhardt
A decoder is only opened if there is a decoder for the codec,
so every AVCodecContext here has AVCodecContext.codec set.

Signed-off-by: Andreas Rheinhardt 
---
 fftools/ffprobe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 4205ddedda..38b7e7e00f 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2561,7 +2561,7 @@ static av_always_inline int process_frame(WriterContext 
*w,
 int ret = 0, got_frame = 0;
 
 clear_log(1);
-if (dec_ctx && dec_ctx->codec) {
+if (dec_ctx) {
 switch (par->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
 case AVMEDIA_TYPE_AUDIO:
@@ -2901,7 +2901,7 @@ static int show_stream(WriterContext *w, AVFormatContext 
*fmt_ctx, int stream_id
 break;
 }
 
-if (dec_ctx && dec_ctx->codec && dec_ctx->codec->priv_class && 
show_private_data) {
+if (dec_ctx && dec_ctx->codec->priv_class && show_private_data) {
 const AVOption *opt = NULL;
 while (opt = av_opt_next(dec_ctx->priv_data,opt)) {
 uint8_t *str;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 1/2] fftools/ffprobe: Flush decoder after draining

2022-02-19 Thread Andreas Rheinhardt
This is a prerequisite to continue using the decoder at all
to decode the next interval (if any).
This fixes a regression introduced in commit
2a88ebd096f3c748a2d99ed1b60b22879b3c567c and reported in ticket #8657.

Signed-off-by: Andreas Rheinhardt 
---
I wonder whether it would not be simpler to let users reuse a decoder
after draining simply by sending new packets (without flushing).

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

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 8a8e3de540..4205ddedda 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2730,8 +2730,11 @@ static int read_interval_packets(WriterContext *w, 
InputFile *ifile,
 //Flush remaining frames that are cached in the decoder
 for (i = 0; i < fmt_ctx->nb_streams; i++) {
 pkt->stream_index = i;
-if (do_read_frames)
+if (do_read_frames) {
 while (process_frame(w, ifile, frame, pkt, &(int){1}) > 0);
+if (ifile->streams[i].dec_ctx)
+avcodec_flush_buffers(ifile->streams[i].dec_ctx);
+}
 }
 
 end:
-- 
2.32.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] libavfilter: zscale performance optimization >4x

2022-02-19 Thread Victoria Zhislina
By ffmpeg threading support implementation via frame slicing and doing
zimg_filter_graph_build that used to take 30-60% of each frame processig
only if necessary (some parameters changed)
the performance increase vs original version
in video downscale and color conversion  >4x is seen
on 64 cores Intel Xeon, 3x on i7-6700K (4 cores with HT)

Signed-off-by: Victoria Zhislina 
---
 libavfilter/vf_zscale.c | 417 +++-
 1 file changed, 288 insertions(+), 129 deletions(-)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 1288c5efc1..61418d4a4a 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2015 Paul B Mahol
- *
+ * 2022 Victoria Zhislina, Intel
+
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -44,6 +45,8 @@
 #include "libavutil/imgutils.h"
 
 #define ZIMG_ALIGNMENT 32
+#define MIN_TILESIZE 64
+#define MAX_THREADS 64
 
 static const char *const var_names[] = {
 "in_w",   "iw",
@@ -113,13 +116,17 @@ typedef struct ZScaleContext {
 
 int force_original_aspect_ratio;
 
-void *tmp;
-size_t tmp_size;
+void *tmp[MAX_THREADS]; //separate for each thread;
+int nb_threads;
+int slice_h;
 
 zimg_image_format src_format, dst_format;
 zimg_image_format alpha_src_format, alpha_dst_format;
+zimg_image_format src_format_tmp, dst_format_tmp;
+zimg_image_format alpha_src_format_tmp, alpha_dst_format_tmp;
 zimg_graph_builder_params alpha_params, params;
-zimg_filter_graph *alpha_graph, *graph;
+zimg_graph_builder_params alpha_params_tmp, params_tmp;
+zimg_filter_graph *alpha_graph[MAX_THREADS], *graph[MAX_THREADS];
 
 enum AVColorSpace in_colorspace, out_colorspace;
 enum AVColorTransferCharacteristic in_trc, out_trc;
@@ -128,10 +135,36 @@ typedef struct ZScaleContext {
 enum AVChromaLocation in_chromal, out_chromal;
 } ZScaleContext;
 
+typedef struct ThreadData {
+const AVPixFmtDescriptor *desc, *odesc;
+AVFrame *in, *out;
+} ThreadData;
+
 static av_cold int init(AVFilterContext *ctx)
 {
 ZScaleContext *s = ctx->priv;
 int ret;
+int i;
+
+for (i = 0; i < MAX_THREADS; i++) {
+s->tmp[i] = NULL;
+s->graph[i] = NULL;
+s->alpha_graph[i] = NULL;
+}
+zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
+zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
+zimg_image_format_default(&s->src_format_tmp, ZIMG_API_VERSION);
+zimg_image_format_default(&s->dst_format_tmp, ZIMG_API_VERSION);
+
+zimg_image_format_default(&s->alpha_src_format, ZIMG_API_VERSION);
+zimg_image_format_default(&s->alpha_dst_format, ZIMG_API_VERSION);
+zimg_image_format_default(&s->alpha_src_format_tmp, ZIMG_API_VERSION);
+zimg_image_format_default(&s->alpha_dst_format_tmp, ZIMG_API_VERSION);
+
+zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
+zimg_graph_builder_params_default(&s->params_tmp, ZIMG_API_VERSION);
+zimg_graph_builder_params_default(&s->alpha_params, ZIMG_API_VERSION);
+zimg_graph_builder_params_default(&s->alpha_params_tmp, ZIMG_API_VERSION);
 
 if (s->size_str && (s->w_expr || s->h_expr)) {
 av_log(ctx, AV_LOG_ERROR,
@@ -158,7 +191,6 @@ static av_cold int init(AVFilterContext *ctx)
 av_opt_set(s, "w", "iw", 0);
 if (!s->h_expr)
 av_opt_set(s, "h", "ih", 0);
-
 return 0;
 }
 
@@ -471,6 +503,51 @@ static enum AVColorRange convert_range_from_zimg(enum 
zimg_pixel_range_e color_r
 return AVCOL_RANGE_UNSPECIFIED;
 }
 
+/* returns 0 if image formats are the same and 1 otherwise */
+static int compare_zimg_image_formats(zimg_image_format *img_fmt0, 
zimg_image_format *img_fmt1)
+{
+return ((img_fmt0->chroma_location != img_fmt1->chroma_location) ||
+#if ZIMG_API_VERSION >= 0x204
+(img_fmt0->alpha != img_fmt1->alpha) ||
+#endif
+(img_fmt0->color_family != img_fmt1->color_family) ||
+(img_fmt0->color_primaries != img_fmt1->color_primaries) ||
+(img_fmt0->depth != img_fmt1->depth) ||
+(img_fmt0->field_parity != img_fmt1->field_parity) ||
+(img_fmt0->height != img_fmt1->height) ||
+(img_fmt0->matrix_coefficients != img_fmt1->matrix_coefficients) ||
+(img_fmt0->pixel_range != img_fmt1->pixel_range) ||
+(img_fmt0->pixel_type != img_fmt1->pixel_type) ||
+(img_fmt0->subsample_h != img_fmt1->subsample_h) ||
+(img_fmt0->subsample_w != img_fmt1->subsample_w) ||
+(img_fmt0->transfer_characteristics != 
img_fmt1->transfer_characteristics) ||
+(img_fmt0->width != img_fmt1->width));
+}
+
+/* returns 0 if graph builder parameters are the same and 1 otherwise */
+static int compare_zimg_graph_builder_params(zimg_graph_builder_params *parm0, 
zimg_graph_builder_params *parm1)
+{
+/* the parameters that could be changed inside a single ffmpeg zscale 
invocation  

Re: [FFmpeg-devel] [PATCH] avfilter/vf_fps: only give frame as soon as possible if really requested by output

2022-02-19 Thread Nicolas George
Paul B Mahol (12022-02-19):
> Fixes OOM in #9081.
> 
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/vf_fps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

This would break input-driven filtering I think. I am looking into it.

Regards,

-- 
  Nicolas George


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

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


Re: [FFmpeg-devel] [PATCH 3/7] tools/target_dem_fuzzer: Force interrupt for HLS

2022-02-19 Thread Michael Niedermayer
On Sun, Dec 05, 2021 at 10:19:03PM +0100, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 
> 41580/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-5059099224571904
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  tools/target_dem_fuzzer.c | 4 
>  1 file changed, 4 insertions(+)

will apply

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

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire


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

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


Re: [FFmpeg-devel] [PATCH 2/7] tools/target_dem_fuzzer: Test interrupt callback

2022-02-19 Thread Michael Niedermayer
On Sun, Dec 05, 2021 at 10:19:02PM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  tools/target_dem_fuzzer.c | 10 ++
>  1 file changed, 10 insertions(+)

will apply

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

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


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

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


Re: [FFmpeg-devel] [PATCH v3 4/5] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-19 Thread nil-admirari
> Ok, well maybe we should change that too, to use wchar paths (or utf8->whcar 
> routines?).

Changed to wchartoutf8, and replaced fopen with av_fopen_utf8 throughout the 
file. See https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293229.html.

> doesn't use UTF-8 like everything else.

 This is not the only place where plain fopen is used.

grep -RP '\bfopen\(' | wc -l

gives 66 occurrences.



___
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 v7 6/6] fftools: Use UTF-8 on Windows

2022-02-19 Thread Nil Admirari
---
 fftools/fftools.manifest | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
index 30b7d8f..d1ac1e4 100644
--- a/fftools/fftools.manifest
+++ b/fftools/fftools.manifest
@@ -3,8 +3,10 @@
 
   
   
-http://schemas.microsoft.com/SMI/2016/WindowsSettings";>
+http://schemas.microsoft.com/SMI/2016/WindowsSettings";
+ 
xmlns:ws2019="http://schemas.microsoft.com/SMI/2019/WindowsSettings";>
   true
+  UTF-8
 
   
 
-- 
2.32.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 v7 2/6] libavformat/avisynth.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-19 Thread Nil Admirari
---
 libavformat/avisynth.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 2bd0c69..e28d832 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -34,6 +34,7 @@
 /* Platform-specific directives. */
 #ifdef _WIN32
   #include "compat/w32dlfcn.h"
+  #include "libavutil/wchar_filename.h"
   #undef EXTERN_C
   #define AVISYNTH_LIB "avisynth"
 #else
@@ -793,8 +794,7 @@ static int avisynth_open_file(AVFormatContext *s)
 AVS_Value arg, val;
 int ret;
 #ifdef _WIN32
-char filename_ansi[MAX_PATH * 4];
-wchar_t filename_wc[MAX_PATH * 4];
+char *filename_ansi = NULL;
 #endif
 
 if (ret = avisynth_context_create(s))
@@ -802,10 +802,12 @@ static int avisynth_open_file(AVFormatContext *s)
 
 #ifdef _WIN32
 /* Convert UTF-8 to ANSI code page */
-MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4);
-WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
-MAX_PATH * 4, NULL, NULL);
+if (utf8toansi(s->url, &filename_ansi)) {
+ret = AVERROR_UNKNOWN;
+goto fail;
+}
 arg = avs_new_value_string(filename_ansi);
+av_free(filename_ansi);
 #else
 arg = avs_new_value_string(s->url);
 #endif
-- 
2.32.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 v7 4/6] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones, and fopen with av_fopen_utf8

2022-02-19 Thread Nil Admirari
---
 fftools/cmdutils.c | 40 ++--
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15..e87601e 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -40,6 +40,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
+#include "libavutil/avutil.h"
 #include "libavutil/bprint.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/display.h"
@@ -62,6 +63,7 @@
 #endif
 #ifdef _WIN32
 #include 
+#include "compat/w32dlfcn.h"
 #endif
 
 static int init_report(const char *env);
@@ -1032,7 +1034,7 @@ static int init_report(const char *env)
 if (!envlevel)
 report_file_level = FFMAX(report_file_level, prog_loglevel);
 
-report_file = fopen(filename.str, "w");
+report_file = av_fopen_utf8(filename.str, "w");
 if (!report_file) {
 int ret = AVERROR(errno);
 av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
@@ -2065,28 +2067,43 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 {
 FILE *f = NULL;
 int i;
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+char *datadir = NULL;
+#endif
 const char *base[3] = { getenv("FFMPEG_DATADIR"),
 getenv("HOME"),
 FFMPEG_DATADIR, };
 
 if (is_path) {
 av_strlcpy(filename, preset_name, filename_size);
-f = fopen(filename, "r");
+f = av_fopen_utf8(filename, "r");
 } else {
 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
-char datadir[MAX_PATH], *ls;
+wchar_t *datadir_w = get_module_filename(NULL);
 base[2] = NULL;
 
-if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, 
sizeof(datadir) - 1))
+if (wchartoutf8(datadir_w, &datadir))
+datadir = NULL;
+av_free(datadir_w);
+
+if (datadir)
 {
-for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+char *ls;
+for (ls = datadir; *ls; ls++)
 if (*ls == '\\') *ls = '/';
 
 if (ls = strrchr(datadir, '/'))
 {
-*ls = 0;
-strncat(datadir, "/ffpresets",  sizeof(datadir) - 1 - 
strlen(datadir));
-base[2] = datadir;
+const int datadir_len = ls - datadir;
+const int desired_size = datadir_len + strlen("/ffpresets") + 
1;
+char *new_datadir = av_realloc_array(
+datadir, desired_size, sizeof *datadir);
+if (new_datadir) {
+datadir = new_datadir;
+datadir[datadir_len] = 0;
+strncat(datadir, "/ffpresets",  desired_size - 1 - 
datadir_len);
+base[2] = datadir;
+}
 }
 }
 #endif
@@ -2095,17 +2112,20 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 continue;
 snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
  i != 1 ? "" : "/.ffmpeg", preset_name);
-f = fopen(filename, "r");
+f = av_fopen_utf8(filename, "r");
 if (!f && codec_name) {
 snprintf(filename, filename_size,
  "%s%s/%s-%s.ffpreset",
  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
  preset_name);
-f = fopen(filename, "r");
+f = av_fopen_utf8(filename, "r");
 }
 }
 }
 
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+av_free(datadir);
+#endif
 return f;
 }
 
-- 
2.32.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 v7 5/6] fftools: Enable long path support on Windows (fixes #8885)

2022-02-19 Thread Nil Admirari
---
 fftools/Makefile |  5 +
 fftools/fftools.manifest | 10 ++
 fftools/manifest.rc  |  3 +++
 3 files changed, 18 insertions(+)
 create mode 100644 fftools/fftools.manifest
 create mode 100644 fftools/manifest.rc

diff --git a/fftools/Makefile b/fftools/Makefile
index da42078..b221155 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -11,6 +11,11 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
 
 OBJS-ffmpeg+= fftools/ffmpeg_opt.o 
fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o
 
+# Windows resource files
+OBJS-ffmpeg-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffplay-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffprobe-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes)
 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
new file mode 100644
index 000..30b7d8f
--- /dev/null
+++ b/fftools/fftools.manifest
@@ -0,0 +1,10 @@
+
+
+
+  
+  
+http://schemas.microsoft.com/SMI/2016/WindowsSettings";>
+  true
+
+  
+
diff --git a/fftools/manifest.rc b/fftools/manifest.rc
new file mode 100644
index 000..e436fa7
--- /dev/null
+++ b/fftools/manifest.rc
@@ -0,0 +1,3 @@
+#include 
+
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "fftools.manifest"
-- 
2.32.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 v7 3/6] compat/w32dlfcn.h: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-19 Thread Nil Admirari
Also replaces a call to LoadLibraryExA with LoadLibraryExW
since ANSI functions do not support long paths.
---
 compat/w32dlfcn.h | 74 ++-
 1 file changed, 61 insertions(+), 13 deletions(-)

diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
index 52a94ef..a8ac780 100644
--- a/compat/w32dlfcn.h
+++ b/compat/w32dlfcn.h
@@ -25,6 +25,30 @@
 #if (_WIN32_WINNT < 0x0602) || HAVE_WINRT
 #include "libavutil/wchar_filename.h"
 #endif
+
+static inline wchar_t *get_module_filename(const HMODULE module)
+{
+wchar_t *path = NULL;
+int path_size = 0, path_len = 0;
+
+do {
+path_size = path_size ? 1.5 * path_size : MAX_PATH;
+wchar_t *new_path = av_realloc_array(path, path_size, sizeof *path);
+if (!new_path) {
+av_free(path);
+return NULL;
+}
+path = new_path;
+path_len = GetModuleFileNameW(module, path, path_size);
+} while (path_len && path_size <= 32768 && path_size <= path_len);
+
+if (!path_len) {
+av_free(path);
+return NULL;
+}
+return path;
+}
+
 /**
  * Safe function used to open dynamic libs. This attempts to improve program 
security
  * by removing the current directory from the dll search path. Only dll's 
found in the
@@ -34,28 +58,50 @@
  */
 static inline HMODULE win32_dlopen(const char *name)
 {
+wchar_t *name_w = NULL;
+if (utf8towchar(name, &name_w))
+name_w = NULL;
 #if _WIN32_WINNT < 0x0602
 // Need to check if KB2533623 is available
 if (!GetProcAddress(GetModuleHandleW(L"kernel32.dll"), 
"SetDefaultDllDirectories")) {
 HMODULE module = NULL;
-wchar_t *path = NULL, *name_w = NULL;
-DWORD pathlen;
-if (utf8towchar(name, &name_w))
+wchar_t *path = NULL, *new_path = NULL;
+DWORD pathlen, pathsize, namelen;
+if (!name_w)
 goto exit;
-path = (wchar_t *)av_calloc(MAX_PATH, sizeof(wchar_t));
+namelen = wcslen(name_w);
 // Try local directory first
-pathlen = GetModuleFileNameW(NULL, path, MAX_PATH);
-pathlen = wcsrchr(path, '\\') - path;
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+path = get_module_filename(NULL);
+if (!path)
 goto exit;
-path[pathlen] = '\\';
+new_path = wcsrchr(path, '\\');
+if (!new_path)
+goto exit;
+pathlen = new_path - path;
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
 if (module == NULL) {
 // Next try System32 directory
-pathlen = GetSystemDirectoryW(path, MAX_PATH);
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
 goto exit;
+if (pathlen + namelen + 2 > pathsize) {
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
+// The buffer might have been not enough for system directory
+// in the first place.
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
+goto exit;
+}
 path[pathlen] = '\\';
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -73,15 +119,17 @@ exit:
 #   define LOAD_LIBRARY_SEARCH_SYSTEM320x0800
 #endif
 #if HAVE_WINRT
-wchar_t *name_w = NULL;
 int ret;
-if (utf8towchar(name, &name_w))
+if (!name_w)
 return NULL;
 ret = LoadPackagedLibrary(name_w, 0);
 av_free(name_w);
 return ret;
 #else
-return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
+/* filename may be be in CP_ACP */
+if (!name_w)
+return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR 
| LOAD_LIBRARY_SEARCH_SYSTEM32);
+return LoadLibraryExW(name_w, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
 #endif
 }
 #define dlopen(name, flags) win32_dlopen(name)
-- 
2.32.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 v7 1/6] libavutil/wchar_filename.h: Add whcartoutf8, wchartoansi and utf8toansi

2022-02-19 Thread Nil Admirari
These functions are going to be used in libavformat/avisynth.c
and fftools/cmdutils.c when replacing MAX_PATH-sized buffers
with dynamically sized ones.
---
 libavutil/wchar_filename.h | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h
index 90f0824..70cd5a4 100644
--- a/libavutil/wchar_filename.h
+++ b/libavutil/wchar_filename.h
@@ -40,6 +40,57 @@ static inline int utf8towchar(const char *filename_utf8, 
wchar_t **filename_w)
 MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
 return 0;
 }
+
+av_warn_unused_result
+static inline int wchartocp(const unsigned int code_page, const wchar_t 
*filename_w,
+char **filename)
+{
+const int flags = code_page == CP_UTF8 ? MB_ERR_INVALID_CHARS : 0;
+const int num_chars = WideCharToMultiByte(code_page, flags, filename_w, -1,
+  NULL, 0, NULL, NULL);
+if (num_chars <= 0) {
+*filename = NULL;
+return 0;
+}
+*filename = av_calloc(num_chars, sizeof(char));
+if (!*filename) {
+errno = ENOMEM;
+return -1;
+}
+WideCharToMultiByte(code_page, flags, filename_w, -1,
+*filename, num_chars, NULL, NULL);
+return 0;
+}
+
+av_warn_unused_result
+static inline int wchartoutf8(const wchar_t *filename_w, char **filename)
+{
+return wchartocp(CP_UTF8, filename_w, filename);
+}
+
+av_warn_unused_result
+static inline int wchartoansi(const wchar_t *filename_w, char **filename)
+{
+return wchartocp(CP_THREAD_ACP, filename_w, filename);
+}
+
+av_warn_unused_result
+static inline int utf8toansi(const char *filename_utf8, char **filename)
+{
+wchar_t *filename_w = NULL;
+int ret = -1;
+if (utf8towchar(filename_utf8, &filename_w))
+return -1;
+
+if (!filename_w) {
+*filename = NULL;
+return 0;
+}
+
+ret = wchartoansi(filename_w, filename);
+av_free(filename_w);
+return ret;
+}
 #endif
 
 #endif /* AVUTIL_WCHAR_FILENAME_H */
-- 
2.32.0



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

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


Re: [FFmpeg-devel] [PATCH 1/2] avdevice/avfoundation: fix memleak

2022-02-19 Thread zhilizhao(赵志立)



> On Feb 8, 2022, at 9:05 PM, Andreas Rheinhardt 
>  wrote:
> 
> Thilo Borgmann:
>> Am 08.02.22 um 13:50 schrieb Andreas Rheinhardt:
>>> Thilo Borgmann:
 Am 04.02.22 um 17:19 schrieb Zhao Zhili:
> ---
>libavdevice/avfoundation.m | 10 ++
>1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
> index 0cd6e646d5..2078c4879c 100644
> --- a/libavdevice/avfoundation.m
> +++ b/libavdevice/avfoundation.m
> @@ -106,6 +106,7 @@ typedef struct
>int audio_device_index;
>int audio_stream_index;
>+char*url;
>char*video_filename;
>char*audio_filename;
>@@ -299,6 +300,7 @@ static void destroy_context(AVFContext* ctx)
>ctx->avf_delegate= NULL;
>ctx->avf_audio_delegate = NULL;
>+av_freep(&ctx->url);
>av_freep(&ctx->audio_buffer);
 
 Why carry it in the context instead of adding the missing av_freep() in
 parse_device_name() ?
 
>>> 
>>> Because video_filename and audio_filename point into it.
>> 
>> Wondering if we couldn't skip av_strdup() and operate on s->url directly
>> then.
>> 
> 
> This would trash s->url.

Ping. Can this patch set be applied?

> 
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel 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".