Re: [FFmpeg-devel] [PATCH] avutil/frame: Add av_frame_transfer_side_data() function

2021-12-07 Thread Anton Khirnov
Quoting Lynne (2021-12-06 20:12:31)
> 6 Dec 2021, 19:37 by an...@khirnov.net:
> 
> 
> I think av_frame_copy_side_data() makes more sense. Transfer
> implies that it strips the source frame of side data.

The whole point is that it makes refs, not copies (except when it
doesn't). I am open to alternative names, but copy is a bad one IMO.

-- 
Anton Khirnov
___
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] avcodec/vpp_qsv: Copy side data from input to output frame

2021-12-07 Thread Anton Khirnov
Quoting Soft Works (2021-12-03 08:58:31)
> Signed-off-by: softworkz 
> ---
>  libavfilter/qsvvpp.c |  5 +
>  libavfilter/vf_overlay_qsv.c | 19 +++
>  2 files changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index d1218355c7..b291216292 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -849,6 +849,11 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, 
> AVFilterLink *inlink, AVFrame *picr
>  return AVERROR(EAGAIN);
>  break;
>  }
> +
> +ret = av_frame_copy_side_data(out_frame->frame, in_frame->frame, 0);
> +if (ret < 0)
> +return ret;
> +
>  out_frame->frame->pts = 
> av_rescale_q(out_frame->surface.Data.TimeStamp,
>   default_tb, outlink->time_base);
>  
> diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> index 7e76b39aa9..02518e020c 100644
> --- a/libavfilter/vf_overlay_qsv.c
> +++ b/libavfilter/vf_overlay_qsv.c
> @@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs)
>  {
>  AVFilterContext  *ctx = fs->parent;
>  QSVOverlayContext  *s = fs->opaque;
> +AVFrame   *frame0 = NULL;
>  AVFrame*frame = NULL;
> -int   ret = 0, i;
> +int   ret = 0;
>  
> -for (i = 0; i < ctx->nb_inputs; i++) {
> +for (unsigned i = 0; i < ctx->nb_inputs; i++) {
>  ret = ff_framesync_get_frame(fs, i, &frame, 0);
> -if (ret == 0)
> -ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame);
> +
> +if (ret == 0) {
> +AVFrame *temp;
> +
> +if (i == 0)
> +frame0 = frame;
> +else
> +ret = av_frame_copy_side_data(frame, frame0, 0);
> +
> +ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv, 
> ctx->inputs[i], frame);

I don't quite understand the ownership semantics here. This function
does not free frame, so I assume ff_qsvvpp_filter_frame() takes
ownership of it. That would mean you're not allowed to keep a pointer to
it and access it later, because it might have already been freed.

-- 
Anton Khirnov
___
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/1] avcodec/vpp_qsv: Copy side data from input to output frame

2021-12-07 Thread Anton Khirnov
Quoting Soft Works (2021-12-03 09:51:13)
> > I'm concerned that this behavior will become hardcoded into this new API
> > and we won't be able to get rid of it in the future.
> 
> I understand your concern from an abstract point of view. But the point
> about which you want to be concerned has already happened 7 years ago
> and now there exist more than 200 usages of av_frame_copy_props(), all
> of which are possibly expecting the special treatment of PANSCAN.
> That makes me wonder, whether there might be any practical use for 
> a function av_frame_copy_side_data() that behaves differently?

I suspect the overwhelming majority of these calls are done between the
frames with the same resolution, so the relevant code is not executed.
The places where it does matter should be quite few.

And more generally, there's a lot of stuff in our codebase that
shouldn't be there. We shouldn't give up on improving things just
because they have been around for a long time.

-- 
Anton Khirnov
___
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] avformat/4xm: Check for duplicate track ids

2021-12-07 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/4xm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index 848991af5b8..e3075600142 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -149,6 +149,9 @@ static int parse_strk(AVFormatContext *s,
 memset(&fourxm->tracks[fourxm->track_count], 0,
sizeof(AudioTrack) * (track + 1 - fourxm->track_count));
 fourxm->track_count = track + 1;
+} else {
+if (fourxm->tracks[track].bits)
+return AVERROR_INVALIDDATA;
 }
 fourxm->tracks[track].adpcm   = AV_RL32(buf + 12);
 fourxm->tracks[track].channels= AV_RL32(buf + 36);
-- 
2.17.1

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

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


[FFmpeg-devel] [PATCH 1/4] avformat/4xm: Consider max_streams on reallocating tracks array

2021-12-07 Thread Michael Niedermayer
Fixes: OOM
Fixes: 
41595/clusterfuzz-testcase-minimized-ffmpeg_dem_FOURXM_fuzzer-6355979363549184

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/4xm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index f918b1fc572..848991af5b8 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -137,7 +137,8 @@ static int parse_strk(AVFormatContext *s,
 return AVERROR_INVALIDDATA;
 
 track = AV_RL32(buf + 8);
-if ((unsigned)track >= UINT_MAX / sizeof(AudioTrack) - 1) {
+if ((unsigned)track >= UINT_MAX / sizeof(AudioTrack) - 1 ||
+track >= s->max_streams) {
 av_log(s, AV_LOG_ERROR, "current_track too large\n");
 return AVERROR_INVALIDDATA;
 }
-- 
2.17.1

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

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


[FFmpeg-devel] [PATCH 4/4] avformat/vivo: Favor setting fps from explicit fractions

2021-12-07 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/vivo.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/vivo.c b/libavformat/vivo.c
index 6447ec7ee84..2a08e1df033 100644
--- a/libavformat/vivo.c
+++ b/libavformat/vivo.c
@@ -121,7 +121,7 @@ static int vivo_get_packet_header(AVFormatContext *s)
 static int vivo_read_header(AVFormatContext *s)
 {
 VivoContext *vivo = s->priv_data;
-AVRational fps = { 1, 25};
+AVRational fps = { 0 };
 AVStream *ast, *vst;
 unsigned char *line, *line_end, *key, *value;
 long value_int;
@@ -212,13 +212,16 @@ static int vivo_read_header(AVFormatContext *s)
 return AVERROR_INVALIDDATA;
 
 value_used = 1;
-fps = av_inv_q(av_d2q(d, 1));
+if (!fps.num && !fps.den)
+fps = av_inv_q(av_d2q(d, 1));
 }
 
 if (!value_used)
 av_dict_set(&s->metadata, key, value, 0);
 }
 }
+if (!fps.num || !fps.den)
+fps = (AVRational){ 1, 25 };
 
 avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate);
 avpriv_set_pts_info(vst, 64, fps.num, fps.den);
-- 
2.17.1

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

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


[FFmpeg-devel] [PATCH 3/4] avformat/vivo: Do not use the general expression evaluator for parsing a floating point value

2021-12-07 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
41564/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVO_fuzzer-6309014024093696

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/vivo.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/vivo.c b/libavformat/vivo.c
index b2904cd25a7..6447ec7ee84 100644
--- a/libavformat/vivo.c
+++ b/libavformat/vivo.c
@@ -26,6 +26,7 @@
  * @sa http://wiki.multimedia.cx/index.php?title=Vivo
  */
 
+#include "libavutil/avstring.h"
 #include "libavutil/parseutils.h"
 #include "avformat.h"
 #include "internal.h"
@@ -206,11 +207,12 @@ static int vivo_read_header(AVFormatContext *s)
 return AVERROR_INVALIDDATA;
 value_used = 1;
 } else if (!strcmp(key, "FPS")) {
-AVRational tmp;
+double d;
+if (av_sscanf(value, "%f", &d) != 1)
+return AVERROR_INVALIDDATA;
 
 value_used = 1;
-if (!av_parse_ratio(&tmp, value, 1, AV_LOG_WARNING, s))
-fps = av_inv_q(tmp);
+fps = av_inv_q(av_d2q(d, 1));
 }
 
 if (!value_used)
-- 
2.17.1

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

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


[FFmpeg-devel] [PATCH v3] fftools/opts: Avoid crash when opts could not be allocated

2021-12-07 Thread Yu Yang
If 'opts' could not be allocated, exiting the program to avoid crash when 
release it. 
Before setup_find_stream_info_opts(), checking 'orig_nb_streams' is > 0.
If 'orig_nb_streams' == 0, it doesn't need 'opts' to getting streams info. So 
directly 
execute avformat_find_stream_info().

Reported-by: TOTE Robot 
Signed-off-by: Yu Yang 
---
 fftools/cmdutils.c   |  5 ++---
 fftools/ffmpeg_opt.c | 20 ++--
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 3c8e5a82cd..823cc8a632 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -2181,13 +2181,12 @@ AVDictionary 
**setup_find_stream_info_opts(AVFormatContext *s,
 int i;
 AVDictionary **opts;
 
-if (!s->nb_streams)
-return NULL;
 opts = av_calloc(s->nb_streams, sizeof(*opts));
 if (!opts) {
 av_log(NULL, AV_LOG_ERROR,
"Could not alloc memory for stream options.\n");
-return NULL;
+avformat_close_input(&s);
+exit_program(1);
 }
 for (i = 0; i < s->nb_streams; i++)
 opts[i] = filter_codec_opts(codec_opts, 
s->streams[i]->codecpar->codec_id,
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index a703798586..453f3a21dc 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1191,17 +1191,17 @@ static int open_input_file(OptionsContext *o, const 
char *filename)
 choose_decoder(o, ic, ic->streams[i]);
 
 if (find_stream_info) {
-AVDictionary **opts = setup_find_stream_info_opts(ic, 
o->g->codec_opts);
 int orig_nb_streams = ic->nb_streams;
-
-/* If not enough info to get the stream parameters, we decode the
-   first frames to get it. (used in mpeg case for example) */
-ret = avformat_find_stream_info(ic, opts);
-
-for (i = 0; i < orig_nb_streams; i++)
-av_dict_free(&opts[i]);
-av_freep(&opts);
-
+if (orig_nb_streams > 0) {
+AVDictionary **opts = setup_find_stream_info_opts(ic, 
o->g->codec_opts);
+/* If not enough info to get the stream parameters, we decode the
+first frames to get it. (used in mpeg case for example) */
+ret = avformat_find_stream_info(ic, opts);
+for (i = 0; i < orig_nb_streams; i++)
+av_dict_free(&opts[i]);
+av_freep(&opts);
+} else
+ret = avformat_find_stream_info(ic, NULL);
 if (ret < 0) {
 av_log(NULL, AV_LOG_FATAL, "%s: could not find codec 
parameters\n", filename);
 if (ic->nb_streams == 0) {
-- 
2.33.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 v3 2/2] avcodec/vpp_qsv: Copy side data from input to output frame

2021-12-07 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Anton
> Khirnov
> Sent: Tuesday, December 7, 2021 9:04 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec/vpp_qsv: Copy side data
> from input to output frame
> 
> Quoting Soft Works (2021-12-03 08:58:31)
> > Signed-off-by: softworkz 
> > ---
> >  libavfilter/qsvvpp.c |  5 +
> >  libavfilter/vf_overlay_qsv.c | 19 +++
> >  2 files changed, 20 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> > index d1218355c7..b291216292 100644
> > --- a/libavfilter/qsvvpp.c
> > +++ b/libavfilter/qsvvpp.c
> > @@ -849,6 +849,11 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s,
> AVFilterLink *inlink, AVFrame *picr
> >  return AVERROR(EAGAIN);
> >  break;
> >  }
> > +
> > +ret = av_frame_copy_side_data(out_frame->frame, in_frame->frame,
> 0);
> > +if (ret < 0)
> > +return ret;
> > +
> >  out_frame->frame->pts = av_rescale_q(out_frame-
> >surface.Data.TimeStamp,
> >   default_tb, outlink-
> >time_base);
> >
> > diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> > index 7e76b39aa9..02518e020c 100644
> > --- a/libavfilter/vf_overlay_qsv.c
> > +++ b/libavfilter/vf_overlay_qsv.c
> > @@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs)
> >  {
> >  AVFilterContext  *ctx = fs->parent;
> >  QSVOverlayContext  *s = fs->opaque;
> > +AVFrame   *frame0 = NULL;
> >  AVFrame*frame = NULL;
> > -int   ret = 0, i;
> > +int   ret = 0;
> >
> > -for (i = 0; i < ctx->nb_inputs; i++) {
> > +for (unsigned i = 0; i < ctx->nb_inputs; i++) {
> >  ret = ff_framesync_get_frame(fs, i, &frame, 0);
> > -if (ret == 0)
> > -ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame);
> > +
> > +if (ret == 0) {
> > +AVFrame *temp;
> > +
> > +if (i == 0)
> > +frame0 = frame;
> > +else
> > +ret = av_frame_copy_side_data(frame, frame0, 0);
> > +
> > +ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv, ctx-
> >inputs[i], frame);
> 
> I don't quite understand the ownership semantics here. This function
> does not free frame, so I assume ff_qsvvpp_filter_frame() takes
> ownership of it. That would mean you're not allowed to keep a pointer to
> it and access it later, because it might have already been freed.

The filter is using framesync, which is taking care of the ownership.
ff_qsvvpp_filter_frame() clones or copies the frame, depending on case.
Other than with the normal overlay filter, the frame from input0 is
not used for output. But the regular overlay filter has established the
convention that side data from input0 is being kept at the output.

This patch is making sure that overlay_qsv behaves in the same way.
The problem is that (due to the async nature of processing in qsvvpp)
it can't always take the side data from the input0-frame, because there's
no output frame at this stage. So we copy the side data to the frame from
input1, to make sure that the "right" side data is copied (transferred) in
either case.

Thanks for looking at this,
softworkz 

___
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/3] lavf/sdp: add const qualifiers where appropriate

2021-12-07 Thread Martin Storsjö

On Sat, 4 Dec 2021, Anton Khirnov wrote:


Declares that these structs are read-only for this code.
---
libavformat/internal.h |  2 +-
libavformat/rtp.c  |  4 ++--
libavformat/rtp.h  |  4 ++--
libavformat/sdp.c  | 21 +++--
4 files changed, 16 insertions(+), 15 deletions(-)


LGTM

// Martin

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

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


Re: [FFmpeg-devel] [PATCH v3] fftools/opts: Avoid crash when opts could not be allocated

2021-12-07 Thread Andreas Rheinhardt
Yu Yang:
> If 'opts' could not be allocated, exiting the program to avoid crash when 
> release it. 
> Before setup_find_stream_info_opts(), checking 'orig_nb_streams' is > 0.
> If 'orig_nb_streams' == 0, it doesn't need 'opts' to getting streams info. So 
> directly 
> execute avformat_find_stream_info().
> 
> Reported-by: TOTE Robot 
> Signed-off-by: Yu Yang 
> ---
>  fftools/cmdutils.c   |  5 ++---
>  fftools/ffmpeg_opt.c | 20 ++--
>  2 files changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 3c8e5a82cd..823cc8a632 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -2181,13 +2181,12 @@ AVDictionary 
> **setup_find_stream_info_opts(AVFormatContext *s,
>  int i;
>  AVDictionary **opts;
>  
> -if (!s->nb_streams)
> -return NULL;
>  opts = av_calloc(s->nb_streams, sizeof(*opts));
>  if (!opts) {
>  av_log(NULL, AV_LOG_ERROR,
> "Could not alloc memory for stream options.\n");
> -return NULL;
> +avformat_close_input(&s);
> +exit_program(1);

You went the easy route and exited instead of returning the error; I am
not against this, but notice that you do not need to close s here,
because we are exiting the program anyway; given that this function is
not supposed to receive ownership of s at all, you should not free it.

>  }
>  for (i = 0; i < s->nb_streams; i++)
>  opts[i] = filter_codec_opts(codec_opts, 
> s->streams[i]->codecpar->codec_id,
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index a703798586..453f3a21dc 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1191,17 +1191,17 @@ static int open_input_file(OptionsContext *o, const 
> char *filename)
>  choose_decoder(o, ic, ic->streams[i]);
>  
>  if (find_stream_info) {
> -AVDictionary **opts = setup_find_stream_info_opts(ic, 
> o->g->codec_opts);
>  int orig_nb_streams = ic->nb_streams;
> -
> -/* If not enough info to get the stream parameters, we decode the
> -   first frames to get it. (used in mpeg case for example) */
> -ret = avformat_find_stream_info(ic, opts);
> -
> -for (i = 0; i < orig_nb_streams; i++)
> -av_dict_free(&opts[i]);
> -av_freep(&opts);
> -
> +if (orig_nb_streams > 0) {
> +AVDictionary **opts = setup_find_stream_info_opts(ic, 
> o->g->codec_opts);
> +/* If not enough info to get the stream parameters, we decode the
> +first frames to get it. (used in mpeg case for example) */
> +ret = avformat_find_stream_info(ic, opts);
> +for (i = 0; i < orig_nb_streams; i++)
> +av_dict_free(&opts[i]);
> +av_freep(&opts);
> +} else
> +ret = avformat_find_stream_info(ic, NULL);

This change makes the code way more uglier than it is.

>  if (ret < 0) {
>  av_log(NULL, AV_LOG_FATAL, "%s: could not find codec 
> parameters\n", filename);
>  if (ic->nb_streams == 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 v2 1/1] avcodec/vpp_qsv: Copy side data from input to output frame

2021-12-07 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Anton
> Khirnov
> Sent: Tuesday, December 7, 2021 9:08 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v2 1/1] avcodec/vpp_qsv: Copy side data
> from input to output frame
> 
> Quoting Soft Works (2021-12-03 09:51:13)
> > > I'm concerned that this behavior will become hardcoded into this new API
> > > and we won't be able to get rid of it in the future.
> >
> > I understand your concern from an abstract point of view. But the point
> > about which you want to be concerned has already happened 7 years ago
> > and now there exist more than 200 usages of av_frame_copy_props(), all
> > of which are possibly expecting the special treatment of PANSCAN.
> > That makes me wonder, whether there might be any practical use for
> > a function av_frame_copy_side_data() that behaves differently?
> 
> I suspect the overwhelming majority of these calls are done between the
> frames with the same resolution, so the relevant code is not executed.
> The places where it does matter should be quite few.
> 
> And more generally, there's a lot of stuff in our codebase that
> shouldn't be there. We shouldn't give up on improving things just
> because they have been around for a long time.

I'm totally with you. I mean, I've gone over 4 patch versions just for improving
the documentation of the linesize[] parameter ;-)

You didn't quote the other part where I said that it might more sense to
investigate the PANSCAN story directly.
Anyway, I think the solution with the flags is good now.

softworkz
___
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] avutil/frame: Add av_frame_transfer_side_data() function

2021-12-07 Thread Hendrik Leppkes
On Tue, Dec 7, 2021 at 9:00 AM Anton Khirnov  wrote:
>
> Quoting Lynne (2021-12-06 20:12:31)
> > 6 Dec 2021, 19:37 by an...@khirnov.net:
> >
> >
> > I think av_frame_copy_side_data() makes more sense. Transfer
> > implies that it strips the source frame of side data.
>
> The whole point is that it makes refs, not copies (except when it
> doesn't). I am open to alternative names, but copy is a bad one IMO.

How about staying close to avframe, and using av_frame_side_data_ref
or such (analogous to av_frame_ref)?

- 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".


Re: [FFmpeg-devel] [PATCH 2/3] lavf/sdp: reindent switch() according to our conventions

2021-12-07 Thread Martin Storsjö

On Sat, 4 Dec 2021, Anton Khirnov wrote:


---
libavformat/sdp.c | 504 +++---
1 file changed, 252 insertions(+), 252 deletions(-)


Ok

// 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 V6 1/5] hwcontext_vaapi: Use PRIME_2 memory type for modifiers.

2021-12-07 Thread Wenbin Chen
From: Bas Nieuwenhuizen 

This way we can pass explicit modifiers in. Sometimes the
modifier matters for the number of memory planes that
libva accepts, in particular when dealing with
driver-compressed textures. Furthermore the driver might
not actually be able to determine the implicit modifier
if all the buffer-passing has used explicit modifier.
All these issues should be resolved by passing in the
modifier, and for that we switch to using the PRIME_2
memory type.

Tested with experimental radeonsi patches for modifiers
and kmsgrab. Also tested with radeonsi without the
patches to double-check it works without PRIME_2 support.

v2:
  Cache PRIME_2 support to avoid doing two calls every time on
  libva drivers that do not support it.

v3:
  Remove prime2_vas usage.

Signed-off-by: Bas Nieuwenhuizen 
---
 libavutil/hwcontext_vaapi.c | 158 ++--
 1 file changed, 114 insertions(+), 44 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 83e542876d..75acc851d6 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -79,6 +79,9 @@ typedef struct VAAPIFramesContext {
 unsigned int rt_format;
 // Whether vaDeriveImage works.
 int derive_works;
+// Caches whether VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 is unsupported for
+// surface imports.
+int prime_2_import_unsupported;
 } VAAPIFramesContext;
 
 typedef struct VAAPIMapping {
@@ -1022,32 +1025,17 @@ static void vaapi_unmap_from_drm(AVHWFramesContext 
*dst_fc,
 static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst,
   const AVFrame *src, int flags)
 {
+VAAPIFramesContext *src_vafc = src_fc->internal->priv;
 AVHWFramesContext  *dst_fc =
 (AVHWFramesContext*)dst->hw_frames_ctx->data;
 AVVAAPIDeviceContext  *dst_dev = dst_fc->device_ctx->hwctx;
 const AVDRMFrameDescriptor *desc;
 const VAAPIFormatDescriptor *format_desc;
 VASurfaceID surface_id;
-VAStatus vas;
+VAStatus vas = VA_STATUS_SUCCESS;
+int use_prime2;
 uint32_t va_fourcc;
-int err, i, j, k;
-
-unsigned long buffer_handle;
-VASurfaceAttribExternalBuffers buffer_desc;
-VASurfaceAttrib attrs[2] = {
-{
-.type  = VASurfaceAttribMemoryType,
-.flags = VA_SURFACE_ATTRIB_SETTABLE,
-.value.type= VAGenericValueTypeInteger,
-.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
-},
-{
-.type  = VASurfaceAttribExternalBufferDescriptor,
-.flags = VA_SURFACE_ATTRIB_SETTABLE,
-.value.type= VAGenericValueTypePointer,
-.value.value.p = &buffer_desc,
-}
-};
+int err, i, j;
 
 desc = (AVDRMFrameDescriptor*)src->data[0];
 
@@ -1083,35 +1071,117 @@ static int vaapi_map_from_drm(AVHWFramesContext 
*src_fc, AVFrame *dst,
 format_desc = vaapi_format_from_fourcc(va_fourcc);
 av_assert0(format_desc);
 
-buffer_handle = desc->objects[0].fd;
-buffer_desc.pixel_format = va_fourcc;
-buffer_desc.width= src_fc->width;
-buffer_desc.height   = src_fc->height;
-buffer_desc.data_size= desc->objects[0].size;
-buffer_desc.buffers  = &buffer_handle;
-buffer_desc.num_buffers  = 1;
-buffer_desc.flags= 0;
-
-k = 0;
-for (i = 0; i < desc->nb_layers; i++) {
-for (j = 0; j < desc->layers[i].nb_planes; j++) {
-buffer_desc.pitches[k] = desc->layers[i].planes[j].pitch;
-buffer_desc.offsets[k] = desc->layers[i].planes[j].offset;
-++k;
+use_prime2 = !src_vafc->prime_2_import_unsupported &&
+ desc->objects[0].format_modifier != DRM_FORMAT_MOD_INVALID;
+if (use_prime2) {
+VADRMPRIMESurfaceDescriptor prime_desc;
+VASurfaceAttrib prime_attrs[2] = {
+{
+.type  = VASurfaceAttribMemoryType,
+.flags = VA_SURFACE_ATTRIB_SETTABLE,
+.value.type= VAGenericValueTypeInteger,
+.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
+},
+{
+.type  = VASurfaceAttribExternalBufferDescriptor,
+.flags = VA_SURFACE_ATTRIB_SETTABLE,
+.value.type= VAGenericValueTypePointer,
+.value.value.p = &prime_desc,
+}
+};
+prime_desc.fourcc = va_fourcc;
+prime_desc.width = src_fc->width;
+prime_desc.height = src_fc->height;
+prime_desc.num_objects = desc->nb_objects;
+for (i = 0; i < desc->nb_objects; ++i) {
+prime_desc.objects[i].fd = desc->objects[i].fd;
+prime_desc.objects[i].size = desc->objects[i].size;
+prime_desc.objects[i].drm_format_modifier =
+desc->objects[i].format_modifier;
 }
-}
-buffer_desc.num_planes = k;
 
-if (format_desc->chroma_planes

[FFmpeg-devel] [PATCH V6 2/5] libavutil/hwcontext_vaapi: Add a new nv12 format map to support vulkan frame

2021-12-07 Thread Wenbin Chen
Vulkan will map nv12 to R8 and GR88, so add this map to vaapi to support
vulkan frame.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vaapi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 75acc851d6..994b744e4d 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -992,6 +992,7 @@ static const struct {
 } vaapi_drm_format_map[] = {
 #ifdef DRM_FORMAT_R8
 DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_RG88),
+DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_GR88),
 #endif
 DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
 #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16)
-- 
2.25.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 V6 3/5] libavutil/hwcontext_vulkan: Allocate vkFrame in one memory

2021-12-07 Thread Wenbin Chen
The vaapi can import external frame, but the planes of the external
frames should be in the same drm object. A new option "contiguous_planes"
is added to device. This flag tells device to allocate places in one
memory. When device is derived from vaapi this flag will be enabled.
A new flag frame_flag is also added to AVVulkanFramesContext. User
can use this flag to force enable or disable this behaviour.
A new variable "offset "is added to AVVKFrame. It describe describe the
offset from the memory currently bound to the VkImage.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vulkan.c | 68 +++-
 libavutil/hwcontext_vulkan.h | 24 +
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index a0437c9661..eef9009ae1 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -103,8 +103,14 @@ typedef struct VulkanDevicePriv {
 /* Settings */
 int use_linear_images;
 
+/* allocate planes in a contiguous memory */
+int contiguous_planes;
+
 /* Nvidia */
 int dev_is_nvidia;
+
+/* Intel */
+int dev_is_intel;
 } VulkanDevicePriv;
 
 typedef struct VulkanFramesPriv {
@@ -153,6 +159,8 @@ typedef struct AVVkFrameInternal {
 av_free((void *)props);
\
 }
 
+#define VKF_FLAG(x, f) (((x) & (~AV_VK_FRAME_FLAG_NONE)) & (f))
+
 static const struct {
 enum AVPixelFormat pixfmt;
 const VkFormat vkfmts[4];
@@ -1374,6 +1382,13 @@ static int 
vulkan_device_create_internal(AVHWDeviceContext *ctx,
 if (opt_d)
 p->use_linear_images = strtol(opt_d->value, NULL, 10);
 
+opt_d = av_dict_get(opts, "contiguous_planes", NULL, 0);
+if (opt_d)
+p->contiguous_planes = strtol(opt_d->value, NULL, 10);
+else
+p->contiguous_planes = -1;
+
+
 hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames;
 hwctx->nb_enabled_dev_extensions = dev_info.enabledExtensionCount;
 
@@ -1425,6 +1440,8 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
 
 p->dev_is_nvidia = (p->props.properties.vendorID == 0x10de);
 
+p->dev_is_intel = (p->props.properties.vendorID == 0x8086);
+
 vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, 
NULL);
 if (!queue_num) {
 av_log(ctx, AV_LOG_ERROR, "Failed to get queues!\n");
@@ -1742,8 +1759,12 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 AVHWDeviceContext *ctx = hwfc->device_ctx;
 VulkanDevicePriv *p = ctx->internal->priv;
 FFVulkanFunctions *vk = &p->vkfn;
+AVVulkanFramesContext *hwfctx = hwfc->hwctx;
 const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
 VkBindImageMemoryInfo bind_info[AV_NUM_DATA_POINTERS] = { { 0 } };
+VkMemoryRequirements memory_requirements = { 0 };
+int mem_size = 0;
+int mem_size_list[AV_NUM_DATA_POINTERS] = { 0 };
 
 AVVulkanDeviceContext *hwctx = ctx->hwctx;
 
@@ -1771,6 +1792,19 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 req.memoryRequirements.size = FFALIGN(req.memoryRequirements.size,
   
p->props.properties.limits.minMemoryMapAlignment);
 
+if (VKF_FLAG(hwfctx->flags, AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY)) {
+if (memory_requirements.size == 0) {
+memory_requirements = req.memoryRequirements;
+} else if (memory_requirements.memoryTypeBits != 
req.memoryRequirements.memoryTypeBits) {
+av_log(hwfc, AV_LOG_ERROR, "the param for each planes are not 
the same\n");
+return AVERROR(EINVAL);
+}
+
+mem_size_list[i] = req.memoryRequirements.size;
+mem_size += mem_size_list[i];
+continue;
+}
+
 /* In case the implementation prefers/requires dedicated allocation */
 use_ded_mem = ded_req.prefersDedicatedAllocation |
   ded_req.requiresDedicatedAllocation;
@@ -1792,6 +1826,29 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 bind_info[i].memory = f->mem[i];
 }
 
+if (VKF_FLAG(hwfctx->flags, AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY)) {
+memory_requirements.size = mem_size;
+
+/* Allocate memory */
+if ((err = alloc_mem(ctx, &memory_requirements,
+f->tiling == VK_IMAGE_TILING_LINEAR ?
+VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT :
+VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+(void *)(((uint8_t *)alloc_pnext)),
+&f->flags, &f->mem[0])))
+return err;
+
+f->size[0] = memory_requirements.size;
+
+for (int i = 0; i < planes; i++) {
+bind_info[i].sType  = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
+bind_inf

[FFmpeg-devel] [PATCH V6 4/5] libavutil/hwcontext_vulkan: Add support to hwmap to software frame when using contiguous_planes flag.

2021-12-07 Thread Wenbin Chen
Add support to map vulkan frames to software frames when
using contiguous_planes flag.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vulkan.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index eef9009ae1..f980b72720 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2327,9 +2327,10 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext 
*hwfc, AVFrame *dst,
const AVFrame *src, int flags)
 {
 VkResult ret;
-int err, mapped_mem_count = 0;
+int err, mapped_mem_count = 0, loop = 0;
 AVVkFrame *f = (AVVkFrame *)src->data[0];
 AVVulkanDeviceContext *hwctx = hwfc->device_ctx->hwctx;
+AVVulkanFramesContext *hwfctx = hwfc->hwctx;
 const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
 VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
 FFVulkanFunctions *vk = &p->vkfn;
@@ -2356,7 +2357,9 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext 
*hwfc, AVFrame *dst,
 dst->width  = src->width;
 dst->height = src->height;
 
-for (int i = 0; i < planes; i++) {
+loop = VKF_FLAG(hwfctx->flags, AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) ?
+   1 : planes;
+for (int i = 0; i < loop; i++) {
 ret = vk->MapMemory(hwctx->act_dev, f->mem[i], 0,
 VK_WHOLE_SIZE, 0, (void **)&dst->data[i]);
 if (ret != VK_SUCCESS) {
@@ -2367,6 +2370,10 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext 
*hwfc, AVFrame *dst,
 }
 mapped_mem_count++;
 }
+if (VKF_FLAG(hwfctx->flags, AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY)) {
+for (int i = 0; i < planes; i++)
+dst->data[i] = dst->data[0] + f->offset[i];
+}
 
 /* Check if the memory contents matter */
 if (((flags & AV_HWFRAME_MAP_READ) || !(flags & AV_HWFRAME_MAP_OVERWRITE)) 
&&
-- 
2.25.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 V6 5/5] libavutil/hwcontext_vulkan: specify the modifier to create VKImage

2021-12-07 Thread Wenbin Chen
When vulkan image exports to drm, the tilling need to be
VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT. Now add code to create vulkan
image using this format.

Now the following command line works:

ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 
-hwaccel_output_format \
vaapi -i input_1080p.264 -vf "hwmap=derive_device=vulkan,format=vulkan, \
scale_vulkan=1920:1080,hwmap=derive_device=vaapi,format=vaapi" -c:v h264_vaapi 
output.264

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vulkan.c | 133 +--
 1 file changed, 127 insertions(+), 6 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index f980b72720..11c4260e86 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -120,6 +120,9 @@ typedef struct VulkanFramesPriv {
 /* Image transfers */
 VulkanExecCtx upload_ctx;
 VulkanExecCtx download_ctx;
+
+/*modifier info*/
+VkImageDrmFormatModifierListCreateInfoEXT *modifier_info;
 } VulkanFramesPriv;
 
 typedef struct AVVkFrameInternal {
@@ -242,6 +245,31 @@ const VkFormat *av_vkfmt_from_pixfmt(enum AVPixelFormat p)
 return NULL;
 }
 
+static const void *vk_find_struct(const void *chain, VkStructureType stype)
+{
+const VkBaseInStructure *in = chain;
+while (in) {
+if (in->sType == stype)
+return in;
+
+in = in->pNext;
+}
+
+return NULL;
+}
+
+static void vk_link_struct(void *chain, void *in)
+{
+VkBaseOutStructure *out = chain;
+if (!in)
+return;
+
+while (out->pNext)
+out = out->pNext;
+
+out->pNext = in;
+}
+
 static int pixfmt_is_supported(AVHWDeviceContext *dev_ctx, enum AVPixelFormat 
p,
int linear)
 {
@@ -2094,6 +2122,10 @@ static void try_export_flags(AVHWFramesContext *hwfc,
 AVVulkanDeviceContext *dev_hwctx = hwfc->device_ctx->hwctx;
 VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
 FFVulkanFunctions *vk = &p->vkfn;
+const int has_modifiers = hwctx->tiling == 
VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT;
+int loop_count;
+const VkImageDrmFormatModifierListCreateInfoEXT *modifier_info = 
vk_find_struct(hwctx->create_pnext,
+
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT);
 VkExternalImageFormatProperties eprops = {
 .sType = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR,
 };
@@ -2101,9 +2133,18 @@ static void try_export_flags(AVHWFramesContext *hwfc,
 .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
 .pNext = &eprops,
 };
+VkPhysicalDeviceImageDrmFormatModifierInfoEXT phy_dev_mod_info = {
+.sType = 
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT,
+.pNext = NULL,
+.pQueueFamilyIndices   = p->qfs,
+.queueFamilyIndexCount = p->num_qfs,
+.sharingMode   = p->num_qfs > 1 ? VK_SHARING_MODE_CONCURRENT :
+  VK_SHARING_MODE_EXCLUSIVE,
+};
 VkPhysicalDeviceExternalImageFormatInfo enext = {
 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO,
 .handleType = exp,
+.pNext = has_modifiers && modifier_info ? &phy_dev_mod_info : NULL,
 };
 VkPhysicalDeviceImageFormatInfo2 pinfo = {
 .sType  = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
@@ -2115,11 +2156,16 @@ static void try_export_flags(AVHWFramesContext *hwfc,
 .flags  = VK_IMAGE_CREATE_ALIAS_BIT,
 };
 
-ret = vk->GetPhysicalDeviceImageFormatProperties2(dev_hwctx->phys_dev,
-  &pinfo, &props);
-if (ret == VK_SUCCESS) {
-*iexp |= exp;
-*comp_handle_types |= 
eprops.externalMemoryProperties.compatibleHandleTypes;
+loop_count = has_modifiers && modifier_info ? 
modifier_info->drmFormatModifierCount : 1;
+for (int i = 0; i < loop_count; i++) {
+if (has_modifiers && modifier_info)
+phy_dev_mod_info.drmFormatModifier = 
modifier_info->pDrmFormatModifiers[i];
+ret = vk->GetPhysicalDeviceImageFormatProperties2(dev_hwctx->phys_dev,
+&pinfo, &props);
+if (ret == VK_SUCCESS) {
+*iexp |= exp;
+*comp_handle_types |= 
eprops.externalMemoryProperties.compatibleHandleTypes;
+}
 }
 }
 
@@ -2190,6 +2236,12 @@ static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
 {
 VulkanFramesPriv *fp = hwfc->internal->priv;
 
+if (fp->modifier_info) {
+if (fp->modifier_info->pDrmFormatModifiers)
+av_freep(&fp->modifier_info->pDrmFormatModifiers);
+av_freep(&fp->modifier_info);
+}
+
 free_exec_ctx(hwfc, &fp->conv_ctx);
 free_exec_ctx(hwfc, &fp->upload_ctx);
 free_exec_ctx(hwfc, &fp->download_ctx);
@@ -2203,9 +2255,12 @@ static int vulkan_frames_init(AVHWFramesCont

Re: [FFmpeg-devel] [PATCH 3/3] lavf/sdp: add more thorough error handling

2021-12-07 Thread Martin Storsjö

On Sat, 4 Dec 2021, Anton Khirnov wrote:


Return error codes when constructing a stream config fails, rather than
just disregarding the failure and continuing.
Propagate the error codes from av_sdp_create().
---
libavformat/internal.h |   7 +-
libavformat/sdp.c  | 189 +
2 files changed, 120 insertions(+), 76 deletions(-)



@@ -867,9 +910,9 @@ int av_sdp_create(AVFormatContext *ac[], int n_files, char 
*buf, int size)
return AVERROR(ENOSYS);
}

-void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
-const char *dest_addr, const char *dest_type,
-int port, int ttl, AVFormatContext *fmt)
+int ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
+   const char *dest_addr, const char *dest_type,
+   int port, int ttl, AVFormatContext *fmt)
{
}
#endif


This dummy function (which only is compiled if some things are disabled) 
needs a "return 0" too.


Other than that, the patch looks good to me. Thanks!

// Martin

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

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


Re: [FFmpeg-devel] [PATCH v2 1/6] avformat/rtsp: remove redundant assignment

2021-12-07 Thread Martin Storsjö

On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
libavformat/rtsp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index deaed34..47120fd 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1178,8 +1178,8 @@ int ff_rtsp_read_reply(AVFormatContext *s, 
RTSPMessageHeader *reply,
char buf[MAX_URL_SIZE], buf1[MAX_URL_SIZE], *q;
unsigned char ch;
const char *p;
-int ret, content_length, line_count = 0, request = 0;
-unsigned char *content = NULL;
+int ret, content_length, line_count, request;
+unsigned char *content;

start:
line_count = 0;
--
1.8.3.1


LGTM

// Martin

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

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


Re: [FFmpeg-devel] [PATCH v2 2/6] avformat/rtsp: free the alloc memory if failed

2021-12-07 Thread Martin Storsjö

On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
libavformat/rtsp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 47120fd..5cffe0b 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1245,8 +1245,10 @@ start:
content = av_malloc(content_length + 1);
if (!content)
return AVERROR(ENOMEM);
-if (ffurl_read_complete(rt->rtsp_hd, content, content_length) != 
content_length)
+if (ffurl_read_complete(rt->rtsp_hd, content, content_length) != 
content_length) {
+av_freep(&content);
return AVERROR(EIO);
+}
content[content_length] = '\0';
}
if (content_ptr)
--
1.8.3.1


OK

// Martin

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

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


Re: [FFmpeg-devel] [PATCH v2 3/6] avformat/rtsp: use MAX_URL_SIZE for one line parse

2021-12-07 Thread Martin Storsjö

On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

The buf is used for one line of sdp parsing, so it's ok to use MAX_URL_SIZE

Signed-off-by: Limin Wang 
---
libavformat/rtsp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5cffe0b..3e4a68a 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -709,7 +709,7 @@ int ff_sdp_parse(AVFormatContext *s, const char *content)
{
const char *p;
int letter, i;
-char buf[SDP_MAX_SIZE], *q;
+char buf[MAX_URL_SIZE], *q;
SDPParseState sdp_parse_state = { { 0 } }, *s1 = &sdp_parse_state;


No, this is not ok.

For the cases where a SDP is really big (vorbis, theora), then you have 
the majority of the size of the SDP in one line (the format specific fmtp 
line). I just tested generating a RTP stream with libvorbis, and the fmtp 
line ended up at 5194 bytes.


// Martin

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

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


Re: [FFmpeg-devel] [PATCH v2 4/6] avformat/rtsp: check content_ptr before memory allocate

2021-12-07 Thread Martin Storsjö

On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
libavformat/rtsp.c | 7 ++-
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 3e4a68a..b3d1e91 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1240,7 +1240,7 @@ start:
av_strlcpy(rt->session_id, reply->session_id, sizeof(rt->session_id));

content_length = reply->content_length;
-if (content_length > 0) {
+if (content_ptr && content_length > 0) {
/* leave some room for a trailing '\0' (useful for simple parsing) */
content = av_malloc(content_length + 1);
if (!content)
@@ -1250,11 +1250,8 @@ start:
return AVERROR(EIO);
}
content[content_length] = '\0';
-}
-if (content_ptr)
*content_ptr = content;
-else
-av_freep(&content);
+}


I don't think this is right.

If the reply that we read contain a body of contents, but the caller 
didn't pass any content_ptr, then we still need to read and consume the 
body of contents from the stream, even if we don't pass it to the caller. 
(Maybe we should warn in this case, that there was some potentially 
relevant data that the caller didn't care about?) But if we don't read it, 
like this patch does, we would end up desynced from the protocol stream.


// Martin

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

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


Re: [FFmpeg-devel] [PATCH v2 5/6] avformat/rtsp: add error code handling for ff_rtsp_skip_packet()

2021-12-07 Thread Martin Storsjö

On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
libavformat/rtsp.c| 15 ++-
libavformat/rtsp.h|  4 +++-
libavformat/rtspenc.c |  7 +--
3 files changed, 18 insertions(+), 8 deletions(-)

This should be fine.

// Martin

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

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


Re: [FFmpeg-devel] [PATCH v2 6/6] avformat/rtsp: fix the error code from ffurl_read_complete()

2021-12-07 Thread Martin Storsjö

On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
libavformat/rtsp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 4ae810d..c591664 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1197,7 +1197,7 @@ start:
ret = ffurl_read_complete(rt->rtsp_hd, &ch, 1);
av_log(s, AV_LOG_TRACE, "ret=%d c=%02x [%c]\n", ret, ch, ch);
if (ret != 1)
-return AVERROR_EOF;
+return ret < 0 ? ret : AVERROR(EIO);
if (ch == '\n')
break;
if (ch == '$' && q == buf) {
@@ -1250,9 +1250,9 @@ start:
content = av_malloc(content_length + 1);
if (!content)
return AVERROR(ENOMEM);
-if (ffurl_read_complete(rt->rtsp_hd, content, content_length) != 
content_length) {
+if ((ret = ffurl_read_complete(rt->rtsp_hd, content, content_length)) 
!= content_length) {
av_freep(&content);
-return AVERROR(EIO);
+return ret < 0 ? ret : AVERROR(EIO);
}
content[content_length] = '\0';
*content_ptr = content;
--
1.8.3.1


Ok

// 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 1/4] avfilter: add a transpose_vulkan filter

2021-12-07 Thread Wu Jianhua
The following command is on how to apply transpose_vulkan filter:
ffmpeg -init_hw_device vulkan -i input.264 -vf \
hwupload=extra_hw_frames=16,transpose_vulkan,hwdownload,format=yuv420p 
output.264

Signed-off-by: Wu Jianhua 
---
 configure |   1 +
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_transpose_vulkan.c | 316 ++
 4 files changed, 319 insertions(+)
 create mode 100644 libavfilter/vf_transpose_vulkan.c

diff --git a/configure b/configure
index a98a18abaa..12cb49e877 100755
--- a/configure
+++ b/configure
@@ -3718,6 +3718,7 @@ tonemap_vaapi_filter_deps="vaapi 
VAProcFilterParameterBufferHDRToneMapping"
 tonemap_opencl_filter_deps="opencl const_nan"
 transpose_opencl_filter_deps="opencl"
 transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags"
+transpose_vulkan_filter_deps="vulkan spirv_compiler"
 unsharp_opencl_filter_deps="opencl"
 uspp_filter_deps="gpl avcodec"
 vaguedenoiser_filter_deps="gpl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index c8082c4a2f..8744cc3c63 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -483,6 +483,7 @@ OBJS-$(CONFIG_TRANSPOSE_FILTER)  += 
vf_transpose.o
 OBJS-$(CONFIG_TRANSPOSE_NPP_FILTER)  += vf_transpose_npp.o
 OBJS-$(CONFIG_TRANSPOSE_OPENCL_FILTER)   += vf_transpose_opencl.o opencl.o 
opencl/transpose.o
 OBJS-$(CONFIG_TRANSPOSE_VAAPI_FILTER)+= vf_transpose_vaapi.o 
vaapi_vpp.o
+OBJS-$(CONFIG_TRANSPOSE_VULKAN_FILTER)   += vf_transpose_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_TRIM_FILTER)   += trim.o
 OBJS-$(CONFIG_UNPREMULTIPLY_FILTER)  += vf_premultiply.o framesync.o
 OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b1af2cbcc8..9e16b4e71e 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -462,6 +462,7 @@ extern const AVFilter ff_vf_transpose;
 extern const AVFilter ff_vf_transpose_npp;
 extern const AVFilter ff_vf_transpose_opencl;
 extern const AVFilter ff_vf_transpose_vaapi;
+extern const AVFilter ff_vf_transpose_vulkan;
 extern const AVFilter ff_vf_trim;
 extern const AVFilter ff_vf_unpremultiply;
 extern const AVFilter ff_vf_unsharp;
diff --git a/libavfilter/vf_transpose_vulkan.c 
b/libavfilter/vf_transpose_vulkan.c
new file mode 100644
index 00..c9bae413c3
--- /dev/null
+++ b/libavfilter/vf_transpose_vulkan.c
@@ -0,0 +1,316 @@
+/*
+ * copyright (c) 2021 Wu Jianhua 
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/random_seed.h"
+#include "libavutil/opt.h"
+#include "vulkan_filter.h"
+#include "internal.h"
+
+#define CGS 32
+
+typedef struct TransposeVulkanContext {
+FFVulkanContext vkctx;
+FFVkQueueFamilyCtx qf;
+FFVkExecContext *exec;
+FFVulkanPipeline *pl;
+
+VkDescriptorImageInfo input_images[3];
+VkDescriptorImageInfo output_images[3];
+
+int initialized;
+} TransposeVulkanContext;
+
+static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
+{
+int err = 0;
+FFVkSPIRVShader *shd;
+TransposeVulkanContext *s = ctx->priv;
+FFVulkanContext *vkctx = &s->vkctx;
+const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
+
+FFVulkanDescriptorSetBinding image_descs[] = {
+{
+.name   = "input_images",
+.type   = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+.dimensions = 2,
+.elems  = planes,
+.stages = VK_SHADER_STAGE_COMPUTE_BIT,
+.updater= s->input_images,
+},
+{
+.name   = "output_images",
+.type   = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
+.mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format),
+.mem_quali  = "writeonly",
+.dimensions = 2,
+.elems  = planes,
+.stages = VK_SHADER_STAGE_COMPUTE_BIT,
+.updater= s->output_images,
+},
+};
+
+image_descs[0].sampler = ff_vk_init_sampler(vkctx, 1, VK_FILTER_LINEAR);
+if (!image_descs[0].sampler)
+return AVERROR_EXTERNAL;
+
+ff_vk_qf

[FFmpeg-devel] [PATCH 2/4] avfilter/vf_transpose: fix un-checked potential memory allocation failure

2021-12-07 Thread Wu Jianhua
Signed-off-by: Wu Jianhua 
---
 libavfilter/vf_transpose.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index f9f0d70cd5..b964daeee3 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -328,6 +328,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, 
int jobnr,
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
+int err = 0;
 AVFilterContext *ctx = inlink->dst;
 TransContext *s = ctx->priv;
 AVFilterLink *outlink = ctx->outputs[0];
@@ -339,10 +340,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 if (!out) {
-av_frame_free(&in);
-return AVERROR(ENOMEM);
+err = AVERROR(ENOMEM);
+goto fail;
 }
-av_frame_copy_props(out, in);
+
+err = av_frame_copy_props(out, in);
+if (err < 0)
+goto fail;
 
 if (in->sample_aspect_ratio.num == 0) {
 out->sample_aspect_ratio = in->sample_aspect_ratio;
@@ -356,6 +360,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
   FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
 av_frame_free(&in);
 return ff_filter_frame(outlink, out);
+
+fail:
+av_frame_free(&in);
+av_frame_free(&out);
+return err;
 }
 
 #define OFFSET(x) offsetof(TransContext, x)
-- 
2.25.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 3/4] avfilter/gblur_vulkan: fix incorrect sematic

2021-12-07 Thread Wu Jianhua
The input and output are arrays of images, so it's better to use the plural
to align them to the variable name of VkDescriptorImageInfo.

Signed-off-by: Wu Jianhua 
---
 libavfilter/vf_gblur_vulkan.c | 60 +--
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/libavfilter/vf_gblur_vulkan.c b/libavfilter/vf_gblur_vulkan.c
index a2e33d1c90..2dbbbd0965 100644
--- a/libavfilter/vf_gblur_vulkan.c
+++ b/libavfilter/vf_gblur_vulkan.c
@@ -50,31 +50,31 @@ typedef struct GBlurVulkanContext {
 } GBlurVulkanContext;
 
 static const char gblur_horizontal[] = {
-C(0, void gblur(const ivec2 pos, const int index)  
)
-C(0, { 
)
-C(1, vec4 sum = texture(input_image[index], pos) * kernel[0];  
)
-C(0,   
)
-C(1, for(int i = 1; i < kernel.length(); i++) {
)
-C(2, sum += texture(input_image[index], pos + vec2(i, 0.0)) * 
kernel[i];   )
-C(2, sum += texture(input_image[index], pos - vec2(i, 0.0)) * 
kernel[i];   )
-C(1, } 
)
-C(0,   
)
-C(1, imageStore(output_image[index], pos, sum);
)
-C(0, } 
)
+C(0, void gblur(const ivec2 pos, const int index)  
 )
+C(0, { 
 )
+C(1, vec4 sum = texture(input_images[index], pos) * kernel[0]; 
 )
+C(0,   
 )
+C(1, for (int i = 1; i < kernel.length(); i++) {   
 )
+C(2, sum += texture(input_images[index], pos + vec2(i, 0.0)) * 
kernel[i];   )
+C(2, sum += texture(input_images[index], pos - vec2(i, 0.0)) * 
kernel[i];   )
+C(1, } 
 )
+C(0,   
 )
+C(1, imageStore(output_images[index], pos, sum);   
 )
+C(0, } 
 )
 };
 
 static const char gblur_vertical[] = {
-C(0, void gblur(const ivec2 pos, const int index)  
)
-C(0, { 
)
-C(1, vec4 sum = texture(input_image[index], pos) * kernel[0];  
)
-C(0,   
)
-C(1, for(int i = 1; i < kernel.length(); i++) {
)
-C(2, sum += texture(input_image[index], pos + vec2(0.0, i)) * 
kernel[i];   )
-C(2, sum += texture(input_image[index], pos - vec2(0.0, i)) * 
kernel[i];   )
-C(1, } 
)
-C(0,   
)
-C(1, imageStore(output_image[index], pos, sum);
)
-C(0, } 
)
+C(0, void gblur(const ivec2 pos, const int index)  
 )
+C(0, { 
 )
+C(1, vec4 sum = texture(input_images[index], pos) * kernel[0]; 
 )
+C(0,   
 )
+C(1, for (int i = 1; i < kernel.length(); i++) {   
 )
+C(2, sum += texture(input_images[index], pos + vec2(0.0, i)) * 
kernel[i];   )
+C(2, sum += texture(input_images[index], pos - vec2(0.0, i)) * 
kernel[i];   )
+C(1, } 
 )
+C(0,   
 )
+C(1, imageStore(output_images[index], pos, sum);   
 )
+C(0, } 
 )
 };
 
 static inline float gaussian(float sigma, float x)
@@ -133,14 +133,14 @@ static av_cold int init_filter(AVFilterContext *ctx, 
AVFrame *in)
 
 FFVulkanDescriptorSetBinding image_descs[] = {
 {
-.name   = "input_image",
+.name   = "input_images",
 .type   = VK_D

[FFmpeg-devel] [PATCH 4/4] avfilter/flip_vulkan: fix incorrect sematic

2021-12-07 Thread Wu Jianhua
The input and output are arrays of images, so it's better to use the plural
to align them to the variable name of VkDescriptorImageInfo.

Signed-off-by: Wu Jianhua 
---
 libavfilter/vf_flip_vulkan.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavfilter/vf_flip_vulkan.c b/libavfilter/vf_flip_vulkan.c
index 0223786ef1..6a6709e79b 100644
--- a/libavfilter/vf_flip_vulkan.c
+++ b/libavfilter/vf_flip_vulkan.c
@@ -52,7 +52,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame 
*in, enum FlipType
 
 FFVulkanDescriptorSetBinding image_descs[] = {
 {
-.name   = "input_image",
+.name   = "input_images",
 .type   = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
 .dimensions = 2,
 .elems  = planes,
@@ -60,7 +60,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame 
*in, enum FlipType
 .updater= s->input_images,
 },
 {
-.name   = "output_image",
+.name   = "output_images",
 .type   = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
 .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format),
 .mem_quali  = "writeonly",
@@ -89,33 +89,33 @@ static av_cold int init_filter(AVFilterContext *ctx, 
AVFrame *in, enum FlipType
 ff_vk_set_compute_shader_sizes(shd, (int [3]){ CGS, 1, 1 });
 RET(ff_vk_add_descriptor_set(vkctx, s->pl, shd, image_descs, 
FF_ARRAY_ELEMS(image_descs), 0));
 
-GLSLC(0, void main()   
 );
-GLSLC(0, { 
 );
-GLSLC(1, ivec2 size;   
 );
-GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
 );
+GLSLC(0, void main()   
  );
+GLSLC(0, { 
  );
+GLSLC(1, ivec2 size;   
  );
+GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
  );
 for (int i = 0; i < planes; i++) {
-GLSLC(0,   
 );
-GLSLF(1, size = imageSize(output_image[%i]);   
   ,i);
-GLSLC(1, if (IS_WITHIN(pos, size)) {   
 );
+GLSLC(0,   
  );
+GLSLF(1, size = imageSize(output_images[%i]);  
,i);
+GLSLC(1, if (IS_WITHIN(pos, size)) {   
  );
 switch (type)
 {
 case FLIP_HORIZONTAL:
-GLSLF(2, vec4 res = texture(input_image[%i], ivec2(size.x - 
pos.x, pos.y));   ,i);
+GLSLF(2, vec4 res = texture(input_images[%i], ivec2(size.x - 
pos.x, pos.y));   ,i);
 break;
 case FLIP_VERTICAL:
-GLSLF(2, vec4 res = texture(input_image[%i], ivec2(pos.x, 
size.y - pos.y));   ,i);
+GLSLF(2, vec4 res = texture(input_images[%i], ivec2(pos.x, 
size.y - pos.y));   ,i);
 break;
 case FLIP_BOTH:
-GLSLF(2, vec4 res = texture(input_image[%i], ivec2(size.xy - 
pos.xy));, i);
+GLSLF(2, vec4 res = texture(input_images[%i], ivec2(size.xy - 
pos.xy));,i);
 break;
 default:
-GLSLF(2, vec4 res = texture(input_image[%i], pos); 
   ,i);
+GLSLF(2, vec4 res = texture(input_images[%i], pos);
,i);
 break;
 }
-GLSLF(2, imageStore(output_image[%i], pos, res);   
   ,i);
-GLSLC(1, } 
 );
+GLSLF(2, imageStore(output_images[%i], pos, res);  
,i);
+GLSLC(1, } 
  );
 }
-GLSLC(0, } 
 );
+GLSLC(0, } 
  );
 
 RET(ff_vk_compile_shader(vkctx, shd, "main"));
 RET(ff_vk_init_pipeline_layout(vkctx, s->pl));
-- 
2.25.1

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

[FFmpeg-devel] [PATCH 1/2] avformat/utils: Fix wrong indentation

2021-12-07 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/utils.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7840e8717c..827e7c8d5a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1479,23 +1479,23 @@ static int match_stream_specifier(AVFormatContext *s, 
AVStream *st,
 int ret;
 
 if (match) {
-   spec += 2;
-   val = strchr(spec, ':');
-
-   key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
-   if (!key)
-   return AVERROR(ENOMEM);
-
-   tag = av_dict_get(st->metadata, key, NULL, 0);
-   if (tag) {
-   if (!val || !strcmp(tag->value, val + 1))
-   ret = 1;
-   else
-   ret = 0;
-   } else
-   ret = 0;
-
-   av_freep(&key);
+spec += 2;
+val = strchr(spec, ':');
+
+key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
+if (!key)
+return AVERROR(ENOMEM);
+
+tag = av_dict_get(st->metadata, key, NULL, 0);
+if (tag) {
+if (!val || !strcmp(tag->value, val + 1))
+ret = 1;
+else
+ret = 0;
+} else
+ret = 0;
+
+av_freep(&key);
 }
 return match && ret;
 } else if (*spec == 'u' && *(spec + 1) == '\0') {
-- 
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 2/2] avformat/utils: Add const where appropriate

2021-12-07 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/internal.h |  2 +-
 libavformat/utils.c| 15 ---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 20e93d9267..cdc398c49e 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -619,7 +619,7 @@ void ff_parse_key_value(const char *str, 
ff_parse_key_val_cb callback_get_buf,
  * Find stream index based on format-specific stream ID
  * @return stream index, or < 0 on error
  */
-int ff_find_stream_index(AVFormatContext *s, int id);
+int ff_find_stream_index(const AVFormatContext *s, int id);
 
 /**
  * Internal version of av_index_search_timestamp
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 827e7c8d5a..fe1699136c 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1263,7 +1263,7 @@ void ff_parse_key_value(const char *str, 
ff_parse_key_val_cb callback_get_buf,
 }
 }
 
-int ff_find_stream_index(AVFormatContext *s, int id)
+int ff_find_stream_index(const AVFormatContext *s, int id)
 {
 for (unsigned i = 0; i < s->nb_streams; i++)
 if (s->streams[i]->id == id)
@@ -1406,8 +1406,9 @@ AVRational av_guess_frame_rate(AVFormatContext *format, 
AVStream *st, AVFrame *f
  * 0  if st is NOT a matching stream
  * >0 if st is a matching stream
  */
-static int match_stream_specifier(AVFormatContext *s, AVStream *st,
-  const char *spec, const char **indexptr, 
AVProgram **p)
+static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
+  const char *spec, const char **indexptr,
+  const AVProgram **p)
 {
 int match = 1;  /* Stores if the specifier matches so 
far. */
 while (*spec) {
@@ -1474,7 +1475,7 @@ static int match_stream_specifier(AVFormatContext *s, 
AVStream *st,
 return AVERROR(EINVAL);
 return match && (stream_id == st->id);
 } else if (*spec == 'm' && *(spec + 1) == ':') {
-AVDictionaryEntry *tag;
+const AVDictionaryEntry *tag;
 char *key, *val;
 int ret;
 
@@ -1499,7 +1500,7 @@ static int match_stream_specifier(AVFormatContext *s, 
AVStream *st,
 }
 return match && ret;
 } else if (*spec == 'u' && *(spec + 1) == '\0') {
-AVCodecParameters *par = st->codecpar;
+const AVCodecParameters *par = st->codecpar;
 int val;
 switch (par->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
@@ -1535,7 +1536,7 @@ int avformat_match_stream_specifier(AVFormatContext *s, 
AVStream *st,
 int ret, index;
 char *endptr;
 const char *indexptr = NULL;
-AVProgram *p = NULL;
+const AVProgram *p = NULL;
 int nb_streams;
 
 ret = match_stream_specifier(s, st, spec, &indexptr, &p);
@@ -1558,7 +1559,7 @@ int avformat_match_stream_specifier(AVFormatContext *s, 
AVStream *st,
 /* If we requested a matching stream index, we have to ensure st is that. 
*/
 nb_streams = p ? p->nb_stream_indexes : s->nb_streams;
 for (int i = 0; i < nb_streams && index >= 0; i++) {
-AVStream *candidate = p ? s->streams[p->stream_index[i]] : 
s->streams[i];
+const AVStream *candidate = s->streams[p ? p->stream_index[i] : i];
 ret = match_stream_specifier(s, candidate, spec, NULL, NULL);
 if (ret < 0)
 goto error;
-- 
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 3/3] lavf/sdp: add more thorough error handling

2021-12-07 Thread Anton Khirnov
Quoting lance.lmw...@gmail.com (2021-12-05 12:12:54)
> On Sat, Dec 04, 2021 at 06:33:00PM +0100, Anton Khirnov wrote:
> > Return error codes when constructing a stream config fails, rather than
> > just disregarding the failure and continuing.
> > Propagate the error codes from av_sdp_create().
> > ---
> >  libavformat/internal.h |   7 +-
> >  libavformat/sdp.c  | 189 +
> >  2 files changed, 120 insertions(+), 76 deletions(-)
> > 
> > diff --git a/libavformat/internal.h b/libavformat/internal.h
> > index 528ff7e017..db1d83be17 100644
> > --- a/libavformat/internal.h
> > +++ b/libavformat/internal.h
> > @@ -545,10 +545,11 @@ uint64_t ff_parse_ntp_time(uint64_t ntp_ts);
> >   * @param ttl the time to live of the stream, 0 if not multicast
> >   * @param fmt the AVFormatContext, which might contain options modifying
> >   *the generated SDP
> > + * @return 0 on success, a negative error code on failure
> >   */
> > -void ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx,
> > -const char *dest_addr, const char *dest_type,
> > -int port, int ttl, AVFormatContext *fmt);
> > +int ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx,
> > +   const char *dest_addr, const char *dest_type,
> > +   int port, int ttl, AVFormatContext *fmt);
> >  
> 
> ff_sdp_write_media() is used by movenc.c also, maybe it's better to add the 
> error check there also.

It didn't appear to be completely trivial, so I judged it to be outside
the scope of this patch.

-- 
Anton Khirnov
___
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/3] lavf/sdp: add more thorough error handling

2021-12-07 Thread Anton Khirnov
Quoting Martin Storsjö (2021-12-07 10:14:59)
> On Sat, 4 Dec 2021, Anton Khirnov wrote:
> 
> > Return error codes when constructing a stream config fails, rather than
> > just disregarding the failure and continuing.
> > Propagate the error codes from av_sdp_create().
> > ---
> > libavformat/internal.h |   7 +-
> > libavformat/sdp.c  | 189 +
> > 2 files changed, 120 insertions(+), 76 deletions(-)
> 
> > @@ -867,9 +910,9 @@ int av_sdp_create(AVFormatContext *ac[], int n_files, 
> > char *buf, int size)
> > return AVERROR(ENOSYS);
> > }
> >
> > -void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
> > -const char *dest_addr, const char *dest_type,
> > -int port, int ttl, AVFormatContext *fmt)
> > +int ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
> > +   const char *dest_addr, const char *dest_type,
> > +   int port, int ttl, AVFormatContext *fmt)
> > {
> > }
> > #endif
> 
> This dummy function (which only is compiled if some things are disabled) 
> needs a "return 0" too.

Should it really be 0 rather than AVERROR(ENOSYS)?

-- 
Anton Khirnov
___
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 3/6] avformat/rtsp: use MAX_URL_SIZE for one line parse

2021-12-07 Thread lance . lmwang
On Tue, Dec 07, 2021 at 11:27:32AM +0200, Martin Storsjö wrote:
> On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > The buf is used for one line of sdp parsing, so it's ok to use MAX_URL_SIZE
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavformat/rtsp.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> > index 5cffe0b..3e4a68a 100644
> > --- a/libavformat/rtsp.c
> > +++ b/libavformat/rtsp.c
> > @@ -709,7 +709,7 @@ int ff_sdp_parse(AVFormatContext *s, const char 
> > *content)
> > {
> > const char *p;
> > int letter, i;
> > -char buf[SDP_MAX_SIZE], *q;
> > +char buf[MAX_URL_SIZE], *q;
> > SDPParseState sdp_parse_state = { { 0 } }, *s1 = &sdp_parse_state;
> 
> No, this is not ok.
> 
> For the cases where a SDP is really big (vorbis, theora), then you have the
> majority of the size of the SDP in one line (the format specific fmtp line).
> I just tested generating a RTP stream with libvorbis, and the fmtp line
> ended up at 5194 bytes.

This makes sense, please ignore the change.

> 
> // Martin
> 

-- 
Thanks,
Limin Wang
___
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/3] lavf/sdp: add more thorough error handling

2021-12-07 Thread Martin Storsjö

On Tue, 7 Dec 2021, Anton Khirnov wrote:


Quoting Martin Storsjö (2021-12-07 10:14:59)

On Sat, 4 Dec 2021, Anton Khirnov wrote:

> Return error codes when constructing a stream config fails, rather than
> just disregarding the failure and continuing.
> Propagate the error codes from av_sdp_create().
> ---
> libavformat/internal.h |   7 +-
> libavformat/sdp.c  | 189 +
> 2 files changed, 120 insertions(+), 76 deletions(-)

> @@ -867,9 +910,9 @@ int av_sdp_create(AVFormatContext *ac[], int n_files, 
char *buf, int size)
> return AVERROR(ENOSYS);
> }
>
> -void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
> -const char *dest_addr, const char *dest_type,
> -int port, int ttl, AVFormatContext *fmt)
> +int ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
> +   const char *dest_addr, const char *dest_type,
> +   int port, int ttl, AVFormatContext *fmt)
> {
> }
> #endif

This dummy function (which only is compiled if some things are disabled) 
needs a "return 0" too.


Should it really be 0 rather than AVERROR(ENOSYS)?


Oh right, yeah that'd be more correct indeed.

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

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


Re: [FFmpeg-devel] [PATCH v2 4/6] avformat/rtsp: check content_ptr before memory allocate

2021-12-07 Thread lance . lmwang
On Tue, Dec 07, 2021 at 11:30:11AM +0200, Martin Storsjö wrote:
> On Mon, 6 Dec 2021, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavformat/rtsp.c | 7 ++-
> > 1 file changed, 2 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> > index 3e4a68a..b3d1e91 100644
> > --- a/libavformat/rtsp.c
> > +++ b/libavformat/rtsp.c
> > @@ -1240,7 +1240,7 @@ start:
> > av_strlcpy(rt->session_id, reply->session_id, 
> > sizeof(rt->session_id));
> > 
> > content_length = reply->content_length;
> > -if (content_length > 0) {
> > +if (content_ptr && content_length > 0) {
> > /* leave some room for a trailing '\0' (useful for simple parsing) 
> > */
> > content = av_malloc(content_length + 1);
> > if (!content)
> > @@ -1250,11 +1250,8 @@ start:
> > return AVERROR(EIO);
> > }
> > content[content_length] = '\0';
> > -}
> > -if (content_ptr)
> > *content_ptr = content;
> > -else
> > -av_freep(&content);
> > +}
> 
> I don't think this is right.
> 
> If the reply that we read contain a body of contents, but the caller didn't
> pass any content_ptr, then we still need to read and consume the body of
> contents from the stream, even if we don't pass it to the caller. (Maybe we
> should warn in this case, that there was some potentially relevant data that
> the caller didn't care about?) But if we don't read it, like this patch
> does, we would end up desynced from the protocol stream.

Yes, I haven't realized your valid case, ignore this change anyway. 

> 
> // Martin
> 

-- 
Thanks,
Limin Wang
___
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] avutil/frame: Add av_frame_transfer_side_data() function

2021-12-07 Thread Anton Khirnov
Quoting Hendrik Leppkes (2021-12-07 10:04:47)
> On Tue, Dec 7, 2021 at 9:00 AM Anton Khirnov  wrote:
> >
> > Quoting Lynne (2021-12-06 20:12:31)
> > > 6 Dec 2021, 19:37 by an...@khirnov.net:
> > >
> > >
> > > I think av_frame_copy_side_data() makes more sense. Transfer
> > > implies that it strips the source frame of side data.
> >
> > The whole point is that it makes refs, not copies (except when it
> > doesn't). I am open to alternative names, but copy is a bad one IMO.
> 
> How about staying close to avframe, and using av_frame_side_data_ref
> or such (analogous to av_frame_ref)?

Possible I guess, but it still has the same problem that it doesn't
always create refs, only if you don't pass the relevant flag.

-- 
Anton Khirnov
___
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] libswresample/swresamplec: Err num(negative-size) was used as a function parameter

2021-12-07 Thread Michael Niedermayer
On Mon, Dec 06, 2021 at 08:21:42PM +0800, Yu Yang wrote:
> If cannot allocate memory, ERROR(ENOMEM) '-12' as a parameter will be 
> constantly being returned.
> When run resample() firstly, negative size param would cause buffer-overflow 
> and SEGV in swri_rematrix(). 
> When run swri_rematrix() firstly, resample() would not cause error but Err 
> num as a wrong parameter passing.
> Err num should be returned immediately. And remove assert to ensure the 
> return of the error code.
> 
> coredump info:
> #0 0x499517 in posix_memalign (/home/r1/ffmpeg/ffmpeg_4.4.1+0x499517)
> #1 0x6c1f0b4 in av_malloc 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:86:9
> #2 0x6c208fe in av_mallocz 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:239:17
> #3 0x6c207ad in av_mallocz_array 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:195:12
> #4 0x654b2e5 in swri_realloc_audio 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:418:14
> #5 0x654f9a1 in swr_convert_internal 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:601:17
> #6 0x654d2c0 in swr_convert 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:766:19
> #7 0x186cf56 in flush_frame 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:251:13
> #8 0x186a454 in request_frame 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:288:20
> #9 0x787d9c in ff_request_frame_to_filter 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:459:15
> #10 0x7877f1 in forward_status_change 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1257:19
> #11 0x77ed7e in ff_filter_activate_default 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1288:20
> #12 0x77e4e1 in ff_filter_activate 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1441:11
> #13 0x793b3f in ff_filter_graph_run_once 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1403:12
> #14 0x7a7bee in get_frame_internal 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:131:19
> #15 0x7a7287 in av_buffersink_get_frame_flags 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:142:12
> #16 0x792888 in avfilter_graph_request_oldest 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1356:17
> #17 0x5d07df in transcode_from_filter 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4639:11
> #18 0x59e557 in transcode_step 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4729:20
> #19 0x593970 in transcode 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4805:15
> #20 0x58f7a4 in main 
> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:5010:9
> #21 0x7f6fd2dee0b2 in __libc_start_main 
> /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
> 
> SUMMARY: AddressSanitizer: negative-size-param 
> (/home/r1/ffmpeg/ffmpeg_4.4.1+0x497e67) in __asan_memcpy
> 
> Reported-by: TOTE Robot 
> Signed-off-by: Yu Yang 
> ---
>  libswresample/swresample.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
> index c03fe5528f..92ab6a9148 100644
> --- a/libswresample/swresample.c
> +++ b/libswresample/swresample.c
> @@ -644,6 +644,8 @@ static int swr_convert_internal(struct SwrContext *s, 
> AudioData *out, int out_co
>  if(s->resample_first){

>  if(postin != midbuf)
>  out_count= resample(s, midbuf, out_count, postin, in_count);
> +if (out_count < 0)
> +return out_count;

this doesnt look right

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

No snowflake in an avalanche ever feels responsible. -- 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 v2 1/1] avcodec/vpp_qsv: Copy side data from input to output frame

2021-12-07 Thread Anton Khirnov
Quoting Soft Works (2021-12-07 10:03:28)
> 
> 
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of Anton
> > Khirnov
> > Sent: Tuesday, December 7, 2021 9:08 AM
> > To: FFmpeg development discussions and patches 
> > Subject: Re: [FFmpeg-devel] [PATCH v2 1/1] avcodec/vpp_qsv: Copy side data
> > from input to output frame
> > 
> > Quoting Soft Works (2021-12-03 09:51:13)
> > > > I'm concerned that this behavior will become hardcoded into this new API
> > > > and we won't be able to get rid of it in the future.
> > >
> > > I understand your concern from an abstract point of view. But the point
> > > about which you want to be concerned has already happened 7 years ago
> > > and now there exist more than 200 usages of av_frame_copy_props(), all
> > > of which are possibly expecting the special treatment of PANSCAN.
> > > That makes me wonder, whether there might be any practical use for
> > > a function av_frame_copy_side_data() that behaves differently?
> > 
> > I suspect the overwhelming majority of these calls are done between the
> > frames with the same resolution, so the relevant code is not executed.
> > The places where it does matter should be quite few.
> > 
> > And more generally, there's a lot of stuff in our codebase that
> > shouldn't be there. We shouldn't give up on improving things just
> > because they have been around for a long time.
> 
> I'm totally with you. I mean, I've gone over 4 patch versions just for 
> improving
> the documentation of the linesize[] parameter ;-)
> 
> You didn't quote the other part where I said that it might more sense to
> investigate the PANSCAN story directly.
> Anyway, I think the solution with the flags is good now.

I had nothing to add there. You are correct, the reason that code was
added should be investigated and we should find a better solution to the
problem. But that's for whenever somebody feels motivated enough to do
it.

-- 
Anton Khirnov
___
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] avutil/frame: Add av_frame_transfer_side_data() function

2021-12-07 Thread Andreas Rheinhardt
Anton Khirnov:
> From: Soft Works 
> 
> Signed-off-by: softworkz 
> Signed-off-by: Anton Khirnov 
> ---
>  doc/APIchanges  |  4 +++
>  libavutil/frame.c   | 63 ++---
>  libavutil/frame.h   | 20 ++
>  libavutil/version.h |  4 +--
>  4 files changed, 63 insertions(+), 28 deletions(-)
> 
> - renamed the function to av_frame_transfer_side_data(), since actually
>   copying side data is only one of the two possible modes of behavior
>   (and not even the default one)
> - renamed flags accordingly
> - added the AV_FRAME_TRANSFER_SD_FILTER flags as discussed
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 2914ad6734..79cfea00b8 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,10 @@ libavutil: 2021-04-27
>  
>  API changes, most recent first:
>  
> +2021-12-02 - xx - lavu 57.11.100 - frame.h
> +  Add av_frame_transfer_side_data(), AV_FRAME_TRANSFER_SD_COPY, and
> +  AV_FRAME_TRANSFER_SD_FILTER.
> +
>  2021-11-xx - xx - lavfi 8.19.100 - avfilter.h
>Add AVFILTER_FLAG_METADATA_ONLY.
>  
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 0912ad9131..0b087cc4c9 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -253,9 +253,40 @@ int av_frame_get_buffer(AVFrame *frame, int align)
>  return AVERROR(EINVAL);
>  }
>  
> +int av_frame_transfer_side_data(AVFrame *dst, const AVFrame *src, int flags)
> +{
> +for (unsigned i = 0; i < src->nb_side_data; i++) {
> +const AVFrameSideData *sd_src = src->side_data[i];
> +AVFrameSideData *sd_dst;
> +if ((flags & AV_FRAME_TRANSFER_SD_FILTER) &&
> +sd_src->type == AV_FRAME_DATA_PANSCAN  &&

Weird whitespace.

> +(src->width != dst->width || src->height != dst->height))
> +continue;
> +if (flags & AV_FRAME_TRANSFER_SD_COPY) {
> +sd_dst = av_frame_new_side_data(dst, sd_src->type,
> +sd_src->size);
> +if (!sd_dst) {
> +wipe_side_data(dst);
> +return AVERROR(ENOMEM);
> +}
> +memcpy(sd_dst->data, sd_src->data, sd_src->size);
> +} else {
> +AVBufferRef *ref = av_buffer_ref(sd_src->buf);
> +sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
> +if (!sd_dst) {
> +av_buffer_unref(&ref);
> +wipe_side_data(dst);
> +return AVERROR(ENOMEM);
> +}
> +}
> +av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
> +}
> +return 0;
> +}
> +
>  static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
>  {
> -int ret, i;
> +int ret;
>  
>  dst->key_frame  = src->key_frame;
>  dst->pict_type  = src->pict_type;
> @@ -291,31 +322,11 @@ static int frame_copy_props(AVFrame *dst, const AVFrame 
> *src, int force_copy)
>  
>  av_dict_copy(&dst->metadata, src->metadata, 0);
>  
> -for (i = 0; i < src->nb_side_data; i++) {
> -const AVFrameSideData *sd_src = src->side_data[i];
> -AVFrameSideData *sd_dst;
> -if (   sd_src->type == AV_FRAME_DATA_PANSCAN
> -&& (src->width != dst->width || src->height != dst->height))
> -continue;
> -if (force_copy) {
> -sd_dst = av_frame_new_side_data(dst, sd_src->type,
> -sd_src->size);
> -if (!sd_dst) {
> -wipe_side_data(dst);
> -return AVERROR(ENOMEM);
> -}
> -memcpy(sd_dst->data, sd_src->data, sd_src->size);
> -} else {
> -AVBufferRef *ref = av_buffer_ref(sd_src->buf);
> -sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
> -if (!sd_dst) {
> -av_buffer_unref(&ref);
> -wipe_side_data(dst);
> -return AVERROR(ENOMEM);
> -}
> -}
> -av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
> -}
> +ret = av_frame_transfer_side_data(dst, src,
> +(force_copy ? AV_FRAME_TRANSFER_SD_COPY : 0) |
> +AV_FRAME_TRANSFER_SD_FILTER);
> +if (ret < 0)
> +return ret;
>  
>  ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
>  ret |= av_buffer_replace(&dst->private_ref, src->private_ref);
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 3f295f6b9e..deb399f1da 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -873,6 +873,26 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame 
> *frame,
>   */
>  void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType 
> type);
>  
> +/**
> + * Copy side data, rather than creating new references.
> + */
> +#define AV_FRAME_TRANSFER_SD_COPY  (1 << 0)
> +/**
> + * Filter out side data that does not match dst properties.

Re: [FFmpeg-devel] [PATCH 01/10] avformat/utils: Make ff_data_to_hex() zero-terminate the string

2021-12-07 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Most callers want it that way anyway.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/hls.c   |  2 --
>  libavformat/hlsenc.c|  1 -
>  libavformat/httpauth.c  |  5 -
>  libavformat/internal.h  | 11 +++
>  libavformat/movenc.c|  1 -
>  libavformat/omadec.c|  1 -
>  libavformat/rtmpproto.c |  2 --
>  libavformat/sdp.c   |  3 ---
>  libavformat/takdec.c|  1 -
>  libavformat/utils.c |  1 +
>  10 files changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 52a031ed54..557faf8e8d 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -1284,7 +1284,6 @@ static int open_input(HLSContext *c, struct playlist 
> *pls, struct segment *seg,
>  char iv[33], key[33], url[MAX_URL_SIZE];
>  ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0);
>  ff_data_to_hex(key, pls->key, sizeof(pls->key), 0);
> -iv[32] = key[32] = '\0';
>  if (strstr(seg->url, "://"))
>  snprintf(url, sizeof(url), "crypto+%s", seg->url);
>  else
> @@ -2074,7 +2073,6 @@ static int hls_read_header(AVFormatContext *s)
>  if (strstr(in_fmt->name, "mov")) {
>  char key[33];
>  ff_data_to_hex(key, pls->key, sizeof(pls->key), 0);
> -key[32] = '\0';
>  av_dict_set(&options, "decryption_key", key, 
> AV_OPT_FLAG_DECODING_PARAM);
>  } else if (!c->crypto_ctx.aes_ctx) {
>  c->crypto_ctx.aes_ctx = av_aes_alloc();
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index cfd0c036d1..1c2a556375 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -745,7 +745,6 @@ static int do_encrypt(AVFormatContext *s, VariantStream 
> *vs)
>  memcpy(iv, hls->iv, sizeof(iv));
>  }
>  ff_data_to_hex(buf, iv, sizeof(iv), 0);
> -buf[32] = '\0';
>  memcpy(hls->iv_string, buf, sizeof(hls->iv_string));
>  }
>  
> diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c
> index 4f79c78edc..0a98ff80a5 100644
> --- a/libavformat/httpauth.c
> +++ b/libavformat/httpauth.c
> @@ -156,7 +156,6 @@ static char *make_digest_auth(HTTPAuthState *state, const 
> char *username,
>  for (i = 0; i < 2; i++)
>  cnonce_buf[i] = av_get_random_seed();
>  ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 
> 1);
> -cnonce[2*sizeof(cnonce_buf)] = 0;
>  
>  md5ctx = av_md5_alloc();
>  if (!md5ctx)
> @@ -166,7 +165,6 @@ static char *make_digest_auth(HTTPAuthState *state, const 
> char *username,
>  update_md5_strings(md5ctx, username, ":", state->realm, ":", password, 
> NULL);
>  av_md5_final(md5ctx, hash);
>  ff_data_to_hex(A1hash, hash, 16, 1);
> -A1hash[32] = 0;
>  
>  if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) 
> {
>  } else if (!strcmp(digest->algorithm, "MD5-sess")) {
> @@ -174,7 +172,6 @@ static char *make_digest_auth(HTTPAuthState *state, const 
> char *username,
>  update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, 
> NULL);
>  av_md5_final(md5ctx, hash);
>  ff_data_to_hex(A1hash, hash, 16, 1);
> -A1hash[32] = 0;
>  } else {
>  /* Unsupported algorithm */
>  av_free(md5ctx);
> @@ -185,7 +182,6 @@ static char *make_digest_auth(HTTPAuthState *state, const 
> char *username,
>  update_md5_strings(md5ctx, method, ":", uri, NULL);
>  av_md5_final(md5ctx, hash);
>  ff_data_to_hex(A2hash, hash, 16, 1);
> -A2hash[32] = 0;
>  
>  av_md5_init(md5ctx);
>  update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL);
> @@ -195,7 +191,6 @@ static char *make_digest_auth(HTTPAuthState *state, const 
> char *username,
>  update_md5_strings(md5ctx, ":", A2hash, NULL);
>  av_md5_final(md5ctx, hash);
>  ff_data_to_hex(response, hash, 16, 1);
> -response[32] = 0;
>  
>  av_free(md5ctx);
>  
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 20e93d9267..f43e408548 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -484,6 +484,17 @@ void ff_flush_packet_queue(AVFormatContext *s);
>   */
>  int ff_mkdir_p(const char *path);
>  
> +/**
> + * Write hexadecimal string corresponding to given binary data. The string
> + * is zero-terminated.
> + *
> + * @param buf   the output string is written here;
> + *  needs to be at least 2 * size + 1 bytes long.
> + * @param src   the input data to be transformed.
> + * @param size  the size (in byte) of src.
> + * @param lowercase determines whether to use the range [0-9a-f] or [0-9A-F].
> + * @return buf.
> + */
>  char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
>  
>  /**
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 38ff90833a..0f912dd012 100644
> --- a/libavformat/movenc.c
> +++ b/liba

Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec/vpp_qsv: Copy side data from input to output frame

2021-12-07 Thread Anton Khirnov
Quoting Soft Works (2021-12-07 09:55:37)
> 
> 
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of Anton
> > Khirnov
> > Sent: Tuesday, December 7, 2021 9:04 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec/vpp_qsv: Copy side data
> > from input to output frame
> > 
> > Quoting Soft Works (2021-12-03 08:58:31)
> > > Signed-off-by: softworkz 
> > > ---
> > >  libavfilter/qsvvpp.c |  5 +
> > >  libavfilter/vf_overlay_qsv.c | 19 +++
> > >  2 files changed, 20 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> > > index d1218355c7..b291216292 100644
> > > --- a/libavfilter/qsvvpp.c
> > > +++ b/libavfilter/qsvvpp.c
> > > @@ -849,6 +849,11 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s,
> > AVFilterLink *inlink, AVFrame *picr
> > >  return AVERROR(EAGAIN);
> > >  break;
> > >  }
> > > +
> > > +ret = av_frame_copy_side_data(out_frame->frame, in_frame->frame,
> > 0);
> > > +if (ret < 0)
> > > +return ret;
> > > +
> > >  out_frame->frame->pts = av_rescale_q(out_frame-
> > >surface.Data.TimeStamp,
> > >   default_tb, outlink-
> > >time_base);
> > >
> > > diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> > > index 7e76b39aa9..02518e020c 100644
> > > --- a/libavfilter/vf_overlay_qsv.c
> > > +++ b/libavfilter/vf_overlay_qsv.c
> > > @@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs)
> > >  {
> > >  AVFilterContext  *ctx = fs->parent;
> > >  QSVOverlayContext  *s = fs->opaque;
> > > +AVFrame   *frame0 = NULL;
> > >  AVFrame*frame = NULL;
> > > -int   ret = 0, i;
> > > +int   ret = 0;
> > >
> > > -for (i = 0; i < ctx->nb_inputs; i++) {
> > > +for (unsigned i = 0; i < ctx->nb_inputs; i++) {
> > >  ret = ff_framesync_get_frame(fs, i, &frame, 0);
> > > -if (ret == 0)
> > > -ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame);
> > > +
> > > +if (ret == 0) {
> > > +AVFrame *temp;
> > > +
> > > +if (i == 0)
> > > +frame0 = frame;
> > > +else
> > > +ret = av_frame_copy_side_data(frame, frame0, 0);
> > > +
> > > +ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv, ctx-
> > >inputs[i], frame);
> > 
> > I don't quite understand the ownership semantics here. This function
> > does not free frame, so I assume ff_qsvvpp_filter_frame() takes
> > ownership of it. That would mean you're not allowed to keep a pointer to
> > it and access it later, because it might have already been freed.
> 
> The filter is using framesync, which is taking care of the ownership.
> ff_qsvvpp_filter_frame() clones or copies the frame, depending on case.
> Other than with the normal overlay filter, the frame from input0 is
> not used for output. But the regular overlay filter has established the
> convention that side data from input0 is being kept at the output.

Okay, if you're sure that framesync guarantees the frame remaining valid
then I have no objections.

But note that temp is unused and should be removed.

-- 
Anton Khirnov
___
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] fftools/opts: Avoid crash when opts could not be allocated

2021-12-07 Thread Yy


> 2021年12月7日 下午5:00,Andreas Rheinhardt  写道:
> 
> Yu Yang:
>> If 'opts' could not be allocated, exiting the program to avoid crash when 
>> release it. 
>> Before setup_find_stream_info_opts(), checking 'orig_nb_streams' is > 0.
>> If 'orig_nb_streams' == 0, it doesn't need 'opts' to getting streams info. 
>> So directly 
>> execute avformat_find_stream_info().
>> 
>> Reported-by: TOTE Robot 
>> Signed-off-by: Yu Yang 
>> ---
>> fftools/cmdutils.c   |  5 ++---
>> fftools/ffmpeg_opt.c | 20 ++--
>> 2 files changed, 12 insertions(+), 13 deletions(-)
>> 
>> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
>> index 3c8e5a82cd..823cc8a632 100644
>> --- a/fftools/cmdutils.c
>> +++ b/fftools/cmdutils.c
>> @@ -2181,13 +2181,12 @@ AVDictionary 
>> **setup_find_stream_info_opts(AVFormatContext *s,
>> int i;
>> AVDictionary **opts;
>> 
>> -if (!s->nb_streams)
>> -return NULL;
>> opts = av_calloc(s->nb_streams, sizeof(*opts));
>> if (!opts) {
>> av_log(NULL, AV_LOG_ERROR,
>>"Could not alloc memory for stream options.\n");
>> -return NULL;
>> +avformat_close_input(&s);
>> +exit_program(1);
> 
> You went the easy route and exited instead of returning the error;
Yes. We can found log_error has been written in setup_find_stream_info_opts().
If returning the error, it need add a ‘ret’ to receive and judge. I think may 
be it is unnecessary. 
And error msg ’not alloc memory for stream options’ should be printed where the 
error occurred.
Of course, this part of code also has ret for receive the return of 
avformat_find_stream_info(). 
Maybe it can be reused. But I think judging the value of ret twice not a good 
idea. 
May I ask your idea is to return ‘AVERROR(ENOMEM)’ ?it need to change value 
returned.
> I am not against this, but notice that you do not need to close s here,
> because we are exiting the program anyway; given that this function is
> not supposed to receive ownership of s at all, you should not free it.
Thx. I learn more.
> 
>> }
>> for (i = 0; i < s->nb_streams; i++)
>> opts[i] = filter_codec_opts(codec_opts, 
>> s->streams[i]->codecpar->codec_id,
>> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
>> index a703798586..453f3a21dc 100644
>> --- a/fftools/ffmpeg_opt.c
>> +++ b/fftools/ffmpeg_opt.c
>> @@ -1191,17 +1191,17 @@ static int open_input_file(OptionsContext *o, const 
>> char *filename)
>> choose_decoder(o, ic, ic->streams[i]);
>> 
>> if (find_stream_info) {
>> -AVDictionary **opts = setup_find_stream_info_opts(ic, 
>> o->g->codec_opts);
>> int orig_nb_streams = ic->nb_streams;
>> -
>> -/* If not enough info to get the stream parameters, we decode the
>> -   first frames to get it. (used in mpeg case for example) */
>> -ret = avformat_find_stream_info(ic, opts);
>> -
>> -for (i = 0; i < orig_nb_streams; i++)
>> -av_dict_free(&opts[i]);
>> -av_freep(&opts);
>> -
>> +if (orig_nb_streams > 0) {
>> +AVDictionary **opts = setup_find_stream_info_opts(ic, 
>> o->g->codec_opts);
>> +/* If not enough info to get the stream parameters, we decode 
>> the
>> +first frames to get it. (used in mpeg case for example) */
>> +ret = avformat_find_stream_info(ic, opts);
>> +for (i = 0; i < orig_nb_streams; i++)
>> +av_dict_free(&opts[i]);
>> +av_freep(&opts);
>> +} else
>> +ret = avformat_find_stream_info(ic, NULL);
> 
> This change makes the code way more uglier than it is.
Yes, I found this change is unnecessary. If orig_nb_streams == 0, it doesn’t 
enter 
for loop to free ‘ops’.  
> 
>> if (ret < 0) {
>> av_log(NULL, AV_LOG_FATAL, "%s: could not find codec 
>> parameters\n", filename);
>> if (ic->nb_streams == 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 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/concatf: ignore trailing whitespaces

2021-12-07 Thread Gyan Doshi
The concatf protocol returns an opaque error on open if
concatf list file contains trailing newlines.
---
 libavformat/concat.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavformat/concat.c b/libavformat/concat.c
index 2560811ff9..faeba2293a 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -245,6 +245,10 @@ static av_cold int concatf_open(URLContext *h, const char 
*uri, int flags)
 char *node_uri;
 int64_t size;
 size_t len = i;
+int leading_spaces = strspn(cursor, " \n\t\r");
+
+if (!cursor[leading_spaces])
+break;
 
 node_uri = av_get_token(&cursor, "\r\n");
 if (!node_uri) {
-- 
2.33.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] avformat/concatf: ignore trailing whitespaces

2021-12-07 Thread James Almer




On 12/7/2021 9:00 AM, Gyan Doshi wrote:

The concatf protocol returns an opaque error on open if
concatf list file contains trailing newlines.
---
  libavformat/concat.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/libavformat/concat.c b/libavformat/concat.c
index 2560811ff9..faeba2293a 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -245,6 +245,10 @@ static av_cold int concatf_open(URLContext *h, const char 
*uri, int flags)
  char *node_uri;
  int64_t size;
  size_t len = i;
+int leading_spaces = strspn(cursor, " \n\t\r");
+
+if (!cursor[leading_spaces])
+break;
  
  node_uri = av_get_token(&cursor, "\r\n");

  if (!node_uri) {


Seems to work, so LGTM.
___
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] libswresample/swresamplec: Err num(negative-size) was used as a function parameter

2021-12-07 Thread Yy


> 2021年12月7日 下午7:25,Michael Niedermayer  写道:
> 
> On Mon, Dec 06, 2021 at 08:21:42PM +0800, Yu Yang wrote:
>> If cannot allocate memory, ERROR(ENOMEM) '-12' as a parameter will be 
>> constantly being returned.
>> When run resample() firstly, negative size param would cause buffer-overflow 
>> and SEGV in swri_rematrix(). 
>> When run swri_rematrix() firstly, resample() would not cause error but Err 
>> num as a wrong parameter passing.
>> Err num should be returned immediately. And remove assert to ensure the 
>> return of the error code.
>> 
>> coredump info:
>>#0 0x499517 in posix_memalign (/home/r1/ffmpeg/ffmpeg_4.4.1+0x499517)
>>#1 0x6c1f0b4 in av_malloc 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:86:9
>>#2 0x6c208fe in av_mallocz 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:239:17
>>#3 0x6c207ad in av_mallocz_array 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:195:12
>>#4 0x654b2e5 in swri_realloc_audio 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:418:14
>>#5 0x654f9a1 in swr_convert_internal 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:601:17
>>#6 0x654d2c0 in swr_convert 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:766:19
>>#7 0x186cf56 in flush_frame 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:251:13
>>#8 0x186a454 in request_frame 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:288:20
>>#9 0x787d9c in ff_request_frame_to_filter 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:459:15
>>#10 0x7877f1 in forward_status_change 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1257:19
>>#11 0x77ed7e in ff_filter_activate_default 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1288:20
>>#12 0x77e4e1 in ff_filter_activate 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1441:11
>>#13 0x793b3f in ff_filter_graph_run_once 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1403:12
>>#14 0x7a7bee in get_frame_internal 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:131:19
>>#15 0x7a7287 in av_buffersink_get_frame_flags 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:142:12
>>#16 0x792888 in avfilter_graph_request_oldest 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1356:17
>>#17 0x5d07df in transcode_from_filter 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4639:11
>>#18 0x59e557 in transcode_step 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4729:20
>>#19 0x593970 in transcode 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4805:15
>>#20 0x58f7a4 in main 
>> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:5010:9
>>#21 0x7f6fd2dee0b2 in __libc_start_main 
>> /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
>> 
>> SUMMARY: AddressSanitizer: negative-size-param 
>> (/home/r1/ffmpeg/ffmpeg_4.4.1+0x497e67) in __asan_memcpy
>> 
>> Reported-by: TOTE Robot 
>> Signed-off-by: Yu Yang 
>> ---
>> libswresample/swresample.c | 6 +-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
>> index c03fe5528f..92ab6a9148 100644
>> --- a/libswresample/swresample.c
>> +++ b/libswresample/swresample.c
>> @@ -644,6 +644,8 @@ static int swr_convert_internal(struct SwrContext *s, 
>> AudioData *out, int out_co
>> if(s->resample_first){
> 
>> if(postin != midbuf)
>> out_count= resample(s, midbuf, out_count, postin, in_count);
>> +if (out_count < 0)
>> +return out_count;
> 
> this doesnt look right
I could not understand your relpy. Do you mean this bug not exist, or this 
patch not good ? 
> 
> [...]
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> No snowflake in an avalanche ever feels responsible. -- Voltaire
> ___
> 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] avformat/concatf: ignore trailing whitespaces

2021-12-07 Thread Gyan Doshi



On 2021-12-07 05:39 pm, James Almer wrote:



On 12/7/2021 9:00 AM, Gyan Doshi wrote:

The concatf protocol returns an opaque error on open if
concatf list file contains trailing newlines.
---
  libavformat/concat.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/libavformat/concat.c b/libavformat/concat.c
index 2560811ff9..faeba2293a 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -245,6 +245,10 @@ static av_cold int concatf_open(URLContext *h, 
const char *uri, int flags)

  char *node_uri;
  int64_t size;
  size_t len = i;
+    int leading_spaces = strspn(cursor, " \n\t\r");
+
+    if (!cursor[leading_spaces])
+    break;
    node_uri = av_get_token(&cursor, "\r\n");
  if (!node_uri) {


Seems to work, so LGTM.


Thanks.

Pushed as a454dfacd560e40fa5fea796f0d5b437f78e54e4

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

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


Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec/vpp_qsv: Copy side data from input to output frame

2021-12-07 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Anton
> Khirnov
> Sent: Tuesday, December 7, 2021 12:51 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec/vpp_qsv: Copy side data
> from input to output frame
> 
> Quoting Soft Works (2021-12-07 09:55:37)
> >
> >
> > > -Original Message-
> > > From: ffmpeg-devel  On Behalf Of Anton
> > > Khirnov
> > > Sent: Tuesday, December 7, 2021 9:04 AM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec/vpp_qsv: Copy side
> data
> > > from input to output frame
> > >
> > > Quoting Soft Works (2021-12-03 08:58:31)
> > > > Signed-off-by: softworkz 
> > > > ---
> > > >  libavfilter/qsvvpp.c |  5 +
> > > >  libavfilter/vf_overlay_qsv.c | 19 +++
> > > >  2 files changed, 20 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> > > > index d1218355c7..b291216292 100644
> > > > --- a/libavfilter/qsvvpp.c
> > > > +++ b/libavfilter/qsvvpp.c
> > > > @@ -849,6 +849,11 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s,
> > > AVFilterLink *inlink, AVFrame *picr
> > > >  return AVERROR(EAGAIN);
> > > >  break;
> > > >  }
> > > > +
> > > > +ret = av_frame_copy_side_data(out_frame->frame, in_frame-
> >frame,
> > > 0);
> > > > +if (ret < 0)
> > > > +return ret;
> > > > +
> > > >  out_frame->frame->pts = av_rescale_q(out_frame-
> > > >surface.Data.TimeStamp,
> > > >   default_tb, outlink-
> > > >time_base);
> > > >
> > > > diff --git a/libavfilter/vf_overlay_qsv.c
> b/libavfilter/vf_overlay_qsv.c
> > > > index 7e76b39aa9..02518e020c 100644
> > > > --- a/libavfilter/vf_overlay_qsv.c
> > > > +++ b/libavfilter/vf_overlay_qsv.c
> > > > @@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs)
> > > >  {
> > > >  AVFilterContext  *ctx = fs->parent;
> > > >  QSVOverlayContext  *s = fs->opaque;
> > > > +AVFrame   *frame0 = NULL;
> > > >  AVFrame*frame = NULL;
> > > > -int   ret = 0, i;
> > > > +int   ret = 0;
> > > >
> > > > -for (i = 0; i < ctx->nb_inputs; i++) {
> > > > +for (unsigned i = 0; i < ctx->nb_inputs; i++) {
> > > >  ret = ff_framesync_get_frame(fs, i, &frame, 0);
> > > > -if (ret == 0)
> > > > -ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i],
> frame);
> > > > +
> > > > +if (ret == 0) {
> > > > +AVFrame *temp;
> > > > +
> > > > +if (i == 0)
> > > > +frame0 = frame;
> > > > +else
> > > > +ret = av_frame_copy_side_data(frame, frame0, 0);
> > > > +
> > > > +ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv, ctx-
> > > >inputs[i], frame);
> > >
> > > I don't quite understand the ownership semantics here. This function
> > > does not free frame, so I assume ff_qsvvpp_filter_frame() takes
> > > ownership of it. That would mean you're not allowed to keep a pointer to
> > > it and access it later, because it might have already been freed.
> >
> > The filter is using framesync, which is taking care of the ownership.
> > ff_qsvvpp_filter_frame() clones or copies the frame, depending on case.
> > Other than with the normal overlay filter, the frame from input0 is
> > not used for output. But the regular overlay filter has established the
> > convention that side data from input0 is being kept at the output.
> 
> Okay, if you're sure that framesync guarantees the frame remaining valid
> then I have no objections.
> 
> But note that temp is unused and should be removed.

OK, thanks. Let's see what Haihao says, he's closest to the subject at the
moment.

softworkz

___
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] libswresample/swresamplec: Err num(negative-size) was used as a function parameter

2021-12-07 Thread Michael Niedermayer
On Tue, Dec 07, 2021 at 08:12:53PM +0800, Yy wrote:
> 
> 
> > 2021年12月7日 下午7:25,Michael Niedermayer  写道:
> > 
> > On Mon, Dec 06, 2021 at 08:21:42PM +0800, Yu Yang wrote:
> >> If cannot allocate memory, ERROR(ENOMEM) '-12' as a parameter will be 
> >> constantly being returned.
> >> When run resample() firstly, negative size param would cause 
> >> buffer-overflow and SEGV in swri_rematrix(). 
> >> When run swri_rematrix() firstly, resample() would not cause error but Err 
> >> num as a wrong parameter passing.
> >> Err num should be returned immediately. And remove assert to ensure the 
> >> return of the error code.
> >> 
> >> coredump info:
> >>#0 0x499517 in posix_memalign (/home/r1/ffmpeg/ffmpeg_4.4.1+0x499517)
> >>#1 0x6c1f0b4 in av_malloc 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:86:9
> >>#2 0x6c208fe in av_mallocz 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:239:17
> >>#3 0x6c207ad in av_mallocz_array 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:195:12
> >>#4 0x654b2e5 in swri_realloc_audio 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:418:14
> >>#5 0x654f9a1 in swr_convert_internal 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:601:17
> >>#6 0x654d2c0 in swr_convert 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:766:19
> >>#7 0x186cf56 in flush_frame 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:251:13
> >>#8 0x186a454 in request_frame 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:288:20
> >>#9 0x787d9c in ff_request_frame_to_filter 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:459:15
> >>#10 0x7877f1 in forward_status_change 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1257:19
> >>#11 0x77ed7e in ff_filter_activate_default 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1288:20
> >>#12 0x77e4e1 in ff_filter_activate 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1441:11
> >>#13 0x793b3f in ff_filter_graph_run_once 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1403:12
> >>#14 0x7a7bee in get_frame_internal 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:131:19
> >>#15 0x7a7287 in av_buffersink_get_frame_flags 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:142:12
> >>#16 0x792888 in avfilter_graph_request_oldest 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1356:17
> >>#17 0x5d07df in transcode_from_filter 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4639:11
> >>#18 0x59e557 in transcode_step 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4729:20
> >>#19 0x593970 in transcode 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4805:15
> >>#20 0x58f7a4 in main 
> >> /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:5010:9
> >>#21 0x7f6fd2dee0b2 in __libc_start_main 
> >> /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
> >> 
> >> SUMMARY: AddressSanitizer: negative-size-param 
> >> (/home/r1/ffmpeg/ffmpeg_4.4.1+0x497e67) in __asan_memcpy
> >> 
> >> Reported-by: TOTE Robot 
> >> Signed-off-by: Yu Yang 
> >> ---
> >> libswresample/swresample.c | 6 +-
> >> 1 file changed, 5 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
> >> index c03fe5528f..92ab6a9148 100644
> >> --- a/libswresample/swresample.c
> >> +++ b/libswresample/swresample.c
> >> @@ -644,6 +644,8 @@ static int swr_convert_internal(struct SwrContext *s, 
> >> AudioData *out, int out_co
> >> if(s->resample_first){
> > 
> >> if(postin != midbuf)
> >> out_count= resample(s, midbuf, out_count, postin, in_count);
> >> +if (out_count < 0)
> >> +return out_count;
> > 
> > this doesnt look right
> I could not understand your relpy. Do you mean this bug not exist, or this 
> patch not good ? 

The patch looks wrong
Do you see the difference between teh 3 pieces of code below:

if(postin != midbuf)
out_count= resample(s, midbuf, out_count, postin, in_count);
if (out_count < 0)
return out_count;


if(postin != midbuf)
out_count= resample(s, midbuf, out_count, postin, in_count);
if (out_count < 0)
return out_count;


if(postin != midbuf) {
out_count= resample(s, midbuf, out_count, postin, in_count);
if (out_count < 0)
return out_count;
}


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

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list

Re: [FFmpeg-devel] [PATCH] libswresample/swresamplec: Err num(negative-size) was used as a function parameter

2021-12-07 Thread Yy


> 2021年12月7日 下午8:42,Michael Niedermayer  写道:
> 
> On Tue, Dec 07, 2021 at 08:12:53PM +0800, Yy wrote:
>> 
>> 
>>> 2021年12月7日 下午7:25,Michael Niedermayer  写道:
>>> 
>>> On Mon, Dec 06, 2021 at 08:21:42PM +0800, Yu Yang wrote:
 If cannot allocate memory, ERROR(ENOMEM) '-12' as a parameter will be 
 constantly being returned.
 When run resample() firstly, negative size param would cause 
 buffer-overflow and SEGV in swri_rematrix(). 
 When run swri_rematrix() firstly, resample() would not cause error but Err 
 num as a wrong parameter passing.
 Err num should be returned immediately. And remove assert to ensure the 
 return of the error code.
 
 coredump info:
   #0 0x499517 in posix_memalign (/home/r1/ffmpeg/ffmpeg_4.4.1+0x499517)
   #1 0x6c1f0b4 in av_malloc 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:86:9
   #2 0x6c208fe in av_mallocz 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:239:17
   #3 0x6c207ad in av_mallocz_array 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavutil/mem.c:195:12
   #4 0x654b2e5 in swri_realloc_audio 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:418:14
   #5 0x654f9a1 in swr_convert_internal 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:601:17
   #6 0x654d2c0 in swr_convert 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libswresample/swresample.c:766:19
   #7 0x186cf56 in flush_frame 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:251:13
   #8 0x186a454 in request_frame 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/af_aresample.c:288:20
   #9 0x787d9c in ff_request_frame_to_filter 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:459:15
   #10 0x7877f1 in forward_status_change 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1257:19
   #11 0x77ed7e in ff_filter_activate_default 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1288:20
   #12 0x77e4e1 in ff_filter_activate 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfilter.c:1441:11
   #13 0x793b3f in ff_filter_graph_run_once 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1403:12
   #14 0x7a7bee in get_frame_internal 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:131:19
   #15 0x7a7287 in av_buffersink_get_frame_flags 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/buffersink.c:142:12
   #16 0x792888 in avfilter_graph_request_oldest 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/libavfilter/avfiltergraph.c:1356:17
   #17 0x5d07df in transcode_from_filter 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4639:11
   #18 0x59e557 in transcode_step 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4729:20
   #19 0x593970 in transcode 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:4805:15
   #20 0x58f7a4 in main 
 /home/r1/ffmpeg/ffmpeg-4.4.1/build/src/fftools/ffmpeg.c:5010:9
   #21 0x7f6fd2dee0b2 in __libc_start_main 
 /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
 
 SUMMARY: AddressSanitizer: negative-size-param 
 (/home/r1/ffmpeg/ffmpeg_4.4.1+0x497e67) in __asan_memcpy
 
 Reported-by: TOTE Robot 
 Signed-off-by: Yu Yang 
 ---
 libswresample/swresample.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)
 
 diff --git a/libswresample/swresample.c b/libswresample/swresample.c
 index c03fe5528f..92ab6a9148 100644
 --- a/libswresample/swresample.c
 +++ b/libswresample/swresample.c
 @@ -644,6 +644,8 @@ static int swr_convert_internal(struct SwrContext *s, 
 AudioData *out, int out_co
if(s->resample_first){
>>> 
if(postin != midbuf)
out_count= resample(s, midbuf, out_count, postin, in_count);
 +if (out_count < 0)
 +return out_count;
>>> 
>>> this doesnt look right
>> I could not understand your relpy. Do you mean this bug not exist, or this 
>> patch not good ? 
> 
> The patch looks wrong
> Do you see the difference between teh 3 pieces of code below:
> 
> if(postin != midbuf)
>out_count= resample(s, midbuf, out_count, postin, in_count);
>if (out_count < 0)
>return out_count;
> 
> 
> if(postin != midbuf)
>out_count= resample(s, midbuf, out_count, postin, in_count);
> if (out_count < 0)
>return out_count;
> 
> 
> if(postin != midbuf) {
>out_count= resample(s, midbuf, out_count, postin, in_count);
>if (out_count < 0)
>return out_count;
> }
O, my god. It is my fault. The indentation here is misleading.
This is the second time that I made this mistake. Your case above is so 
wonderful.
I would remember not to make this mistake again.
It seems like ‘out_count’ > 0 when it correct. I will check this part code 
again.
Thank you very muc

Re: [FFmpeg-devel] [PATCH] libavdevice/avfoundation.m: use AudioConvert, extend supported formats

2021-12-07 Thread Thilo Borgmann
Hi,

will look at this soon (tm), ping me if I don‘t. 

Thanks,
Thilo

> Am 02.12.2021 um 00:08 schrieb Romain Beauxis :
> 
> Hi there!
> 
> Anyone interested in the patch below? It fixes an issue with some
> macos avfoundation input devices that return formats currently not
> supported by the implementation. I also have another important bugfix
> in the concurrency model of the implementation waiting for this to be
> merged first.
> 
> Otherwise, is there any appropriate step to help getting this merged?
> 
> Thanks for any insight!
> -- Romain
> 
>> On Nov 30, 2021, at 12:02 AM, Romain Beauxis  
>> wrote:
>> 
>> * Implement support for AudioConverter
>> * Switch to AudioConverter's API to convert unsupported PCM
>> formats (non-interleaved, non-packed) to supported formats
>> * Minimize data copy.
>> 
>> This fixes: https://trac.ffmpeg.org/ticket/9502
>> 
>> API ref: 
>> https://developer.apple.com/documentation/audiotoolbox/audio_converter_services
>> 
>> Signed-off-by: Romain Beauxis 
>> ---
>> libavdevice/avfoundation.m | 250 +
>> 1 file changed, 144 insertions(+), 106 deletions(-)
>> 
>> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
>> index 0cd6e646d5..79c9207cfa 100644
>> --- a/libavdevice/avfoundation.m
>> +++ b/libavdevice/avfoundation.m
>> @@ -111,16 +111,10 @@
>> 
>>   int num_video_devices;
>> 
>> -int audio_channels;
>> -int audio_bits_per_sample;
>> -int audio_float;
>> -int audio_be;
>> -int audio_signed_integer;
>> -int audio_packed;
>> -int audio_non_interleaved;
>> -
>> -int32_t *audio_buffer;
>> -int audio_buffer_size;
>> +UInt32audio_buffers;
>> +UInt32audio_channels;
>> +UInt32bytes_per_sample;
>> +AudioConverterRef audio_converter;
>> 
>>   enum AVPixelFormat pixel_format;
>> 
>> @@ -299,7 +293,10 @@ static void destroy_context(AVFContext* ctx)
>>   ctx->avf_delegate= NULL;
>>   ctx->avf_audio_delegate = NULL;
>> 
>> -av_freep(&ctx->audio_buffer);
>> +if (ctx->audio_converter) {
>> +  AudioConverterDispose(ctx->audio_converter);
>> +  ctx->audio_converter = NULL;
>> +}
>> 
>>   pthread_mutex_destroy(&ctx->frame_lock);
>> 
>> @@ -673,6 +670,10 @@ static int get_audio_config(AVFormatContext *s)
>>   AVFContext *ctx = (AVFContext*)s->priv_data;
>>   CMFormatDescriptionRef format_desc;
>>   AVStream* stream = avformat_new_stream(s, NULL);
>> +AudioStreamBasicDescription output_format = {0};
>> +int audio_bits_per_sample, audio_float, audio_be;
>> +int audio_signed_integer, audio_packed, audio_non_interleaved;
>> +int must_convert = 0;
>> 
>>   if (!stream) {
>>   return 1;
>> @@ -690,60 +691,95 @@ static int get_audio_config(AVFormatContext *s)
>>   avpriv_set_pts_info(stream, 64, 1, avf_time_base);
>> 
>>   format_desc = CMSampleBufferGetFormatDescription(ctx->current_audio_frame);
>> -const AudioStreamBasicDescription *basic_desc = 
>> CMAudioFormatDescriptionGetStreamBasicDescription(format_desc);
>> +const AudioStreamBasicDescription *input_format = 
>> CMAudioFormatDescriptionGetStreamBasicDescription(format_desc);
>> 
>> -if (!basic_desc) {
>> +if (!input_format) {
>>   unlock_frames(ctx);
>>   av_log(s, AV_LOG_ERROR, "audio format not available\n");
>>   return 1;
>>   }
>> 
>> +if (input_format->mFormatID != kAudioFormatLinearPCM) {
>> +unlock_frames(ctx);
>> +av_log(s, AV_LOG_ERROR, "only PCM audio format are supported at the 
>> moment\n");
>> +return 1;
>> +}
>> +
>>   stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
>> -stream->codecpar->sample_rate= basic_desc->mSampleRate;
>> -stream->codecpar->channels   = basic_desc->mChannelsPerFrame;
>> +stream->codecpar->sample_rate= input_format->mSampleRate;
>> +stream->codecpar->channels   = input_format->mChannelsPerFrame;
>>   stream->codecpar->channel_layout = 
>> av_get_default_channel_layout(stream->codecpar->channels);
>> 
>> -ctx->audio_channels= basic_desc->mChannelsPerFrame;
>> -ctx->audio_bits_per_sample = basic_desc->mBitsPerChannel;
>> -ctx->audio_float   = basic_desc->mFormatFlags & 
>> kAudioFormatFlagIsFloat;
>> -ctx->audio_be  = basic_desc->mFormatFlags & 
>> kAudioFormatFlagIsBigEndian;
>> -ctx->audio_signed_integer  = basic_desc->mFormatFlags & 
>> kAudioFormatFlagIsSignedInteger;
>> -ctx->audio_packed  = basic_desc->mFormatFlags & 
>> kAudioFormatFlagIsPacked;
>> -ctx->audio_non_interleaved = basic_desc->mFormatFlags & 
>> kAudioFormatFlagIsNonInterleaved;
>> -
>> -if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
>> -ctx->audio_float &&
>> -ctx->audio_bits_per_sample == 32 &&
>> -ctx->audio_packed) {
>> -stream->

Re: [FFmpeg-devel] [PATCH 5/5] avcodec/bitpacked_enc: suppport for frame thread encode

2021-12-07 Thread lance . lmwang
On Wed, Dec 01, 2021 at 09:39:14PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
> multi-thread is active, but I'm not sure why the performance isn't getting 
> better.

plan to push the patchset in the next two day unless there are objection. About
performance, it's caused by the testsrc is single thread in fact. After using
real input for testing, the multi-thread performance will be better.

> 
>  libavcodec/bitpacked_enc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/bitpacked_enc.c b/libavcodec/bitpacked_enc.c
> index 3e0ba00..6f540f1 100644
> --- a/libavcodec/bitpacked_enc.c
> +++ b/libavcodec/bitpacked_enc.c
> @@ -109,7 +109,7 @@ const AVCodec ff_bitpacked_encoder = {
>  .type   = AVMEDIA_TYPE_VIDEO,
>  .id = AV_CODEC_ID_BITPACKED,
>  .priv_data_size = sizeof(struct BitpackedContext),
> -.capabilities   = AV_CODEC_CAP_DR1,
> +.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
>  .init   = encode_init,
>  .encode2= encode_frame,
>  .pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV422P10,
> -- 
> 1.8.3.1
> 

-- 
Thanks,
Limin Wang
___
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] libavcodec/vaapi_decode: fix the problem that init_pool_size < nb_surface

2021-12-07 Thread Anton Khirnov
Quoting Wenbin Chen (2021-11-30 09:44:04)
> For vaapi if the init_pool_size is not zero, the pool size is fixed.
> This means max surfaces is init_pool_size, but when mapping vaapi
> frame to qsv frame, the init_pool_size < nb_surface. The cause is that
> vaapi_decode_make_config() config the init_pool_size and it is called
> twice. The first time is to init frame_context and the second time is to
> init codec. On the second time the init_pool_size is changed to original
> value so the init_pool_size is lower than the reall size because
> pool_size used to initialize frame_context need to plus thread_count and
> 3 (guarantee 4 base work surfaces). Now add code to make sure
> init_pool_size is only set once. Now the following commandline works:
> 
> ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \
> -hwaccel_output_format vaapi -i input.264 \
> -vf "hwmap=derive_device=qsv,format=qsv" \
> -c:v h264_qsv output.264
> 
> Signed-off-by: Wenbin Chen 
> ---
>  libavcodec/vaapi_decode.c | 34 ++
>  1 file changed, 18 insertions(+), 16 deletions(-)
> 
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 665af370ed..aab8162989 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -572,22 +572,24 @@ static int vaapi_decode_make_config(AVCodecContext 
> *avctx,
>  if (err < 0)
>  goto fail;
>  
> -frames->initial_pool_size = 1;
> -// Add per-codec number of surfaces used for storing reference 
> frames.
> -switch (avctx->codec_id) {
> -case AV_CODEC_ID_H264:
> -case AV_CODEC_ID_HEVC:
> -case AV_CODEC_ID_AV1:
> -frames->initial_pool_size += 16;
> -break;
> -case AV_CODEC_ID_VP9:
> -frames->initial_pool_size += 8;
> -break;
> -case AV_CODEC_ID_VP8:
> -frames->initial_pool_size += 3;
> -break;
> -default:
> -frames->initial_pool_size += 2;
> +if (!frames->initial_pool_size) {
> +frames->initial_pool_size = 1;
> +// Add per-codec number of surfaces used for storing reference 
> frames.
> +switch (avctx->codec_id) {
> +case AV_CODEC_ID_H264:
> +case AV_CODEC_ID_HEVC:
> +case AV_CODEC_ID_AV1:
> +frames->initial_pool_size += 16;
> +break;
> +case AV_CODEC_ID_VP9:
> +frames->initial_pool_size += 8;
> +break;
> +case AV_CODEC_ID_VP8:
> +frames->initial_pool_size += 3;
> +break;
> +default:
> +frames->initial_pool_size += 2;
> +}

Seems to me that ff_vaapi_decode_init() should not pass hw_frames_ctx to
vaapi_decode_make_config() at all, because it is already initialized and
must not be modified.

-- 
Anton Khirnov
___
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 v9 1/5] avformat/dovi_isom: Implement Dolby Vision configuration parsing/writing

2021-12-07 Thread lance . lmwang
On Sun, Dec 05, 2021 at 06:35:31PM +0100, quietvoid wrote:
> Both parse/write implementations are based on mov/movenc.
> 
> This only adds support for the "Dolby Vision configuration box".
> Other configuration boxes, such as
> "Dolby Vision enhancement layer configuration box" are not supported.
> 
> The new functions will be used to implement parsing/writing the DOVI config
> for Matroska, as well as to refactor both mov/movenc to use dovi_isom 
> functions.
> 
> Signed-off-by: quietvoid 
> ---
>  libavformat/dovi_isom.c | 118 
>  libavformat/dovi_isom.h |  35 
>  2 files changed, 153 insertions(+)
>  create mode 100644 libavformat/dovi_isom.c
>  create mode 100644 libavformat/dovi_isom.h
> 
> diff --git a/libavformat/dovi_isom.c b/libavformat/dovi_isom.c
> new file mode 100644
> index 00..262d7e37ba
> --- /dev/null
> +++ b/libavformat/dovi_isom.c
> @@ -0,0 +1,118 @@
> +/*
> + * DOVI ISO Media common code
> + *
> + * Copyright (c) 2020 Vacing Fang 
> + * Copyright (c) 2021 quietvoid
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "libavutil/dovi_meta.h"
> +
> +#include "libavcodec/put_bits.h"
> +
> +#include "avformat.h"
> +#include "dovi_isom.h"
> +
> +int ff_isom_parse_dvcc_dvvc(AVFormatContext *s, AVStream *st, const uint8_t 
> *buf_ptr, uint64_t size)
> +{
> +uint32_t buf;
> +AVDOVIDecoderConfigurationRecord *dovi;
> +size_t dovi_size;
> +int ret;
> +
> +if (size > (1 << 30) || size < 4)
> +return AVERROR_INVALIDDATA;
> +
> +dovi = av_dovi_alloc(&dovi_size);
> +if (!dovi)
> +return AVERROR(ENOMEM);
> +
> +dovi->dv_version_major = *buf_ptr++;// 8 bits
> +dovi->dv_version_minor = *buf_ptr++;// 8 bits
> +
> +buf = *buf_ptr++ << 8;
> +buf |= *buf_ptr++;
> +
> +dovi->dv_profile= (buf >> 9) & 0x7f;// 7 bits
> +dovi->dv_level  = (buf >> 3) & 0x3f;// 6 bits
> +dovi->rpu_present_flag  = (buf >> 2) & 0x01;// 1 bit
> +dovi->el_present_flag   = (buf >> 1) & 0x01;// 1 bit
> +dovi->bl_present_flag   =  buf   & 0x01;// 1 bit
> +
> +// Has enough remaining data
> +if (size >= 5) {
> +dovi->dv_bl_signal_compatibility_id = ((*buf_ptr++) >> 4) & 0x0f; // 
> 4 bits
> +} else {
> +// 0 stands for None
> +// Dolby Vision V1.2.93 profiles and levels
> +dovi->dv_bl_signal_compatibility_id = 0;
> +}
> +
> +ret = av_stream_add_side_data(st, AV_PKT_DATA_DOVI_CONF,
> +  (uint8_t *)dovi, dovi_size);
> +if (ret < 0) {
> +av_free(dovi);
> +return ret;
> +}
> +
> +av_log(s, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, 
> profile: %d, level: %d, "
> +   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
> +   dovi->dv_version_major, dovi->dv_version_minor,
> +   dovi->dv_profile, dovi->dv_level,
> +   dovi->rpu_present_flag,
> +   dovi->el_present_flag,
> +   dovi->bl_present_flag,
> +   dovi->dv_bl_signal_compatibility_id);
> +
> +return 0;
> +}
> +
> +void ff_isom_put_dvcc_dvvc(AVFormatContext *s, uint8_t 
> out[ISOM_DVCC_DVVC_SIZE],
> +   AVDOVIDecoderConfigurationRecord *dovi)
> +{
> +PutBitContext pb;
> +
> +init_put_bits(&pb, out, ISOM_DVCC_DVVC_SIZE);
> +
> +put_bits(&pb, 8, dovi->dv_version_major);
> +put_bits(&pb, 8, dovi->dv_version_minor);
> +put_bits(&pb, 7, dovi->dv_profile);
> +put_bits(&pb, 6, dovi->dv_level);
> +put_bits(&pb, 1, dovi->rpu_present_flag);
> +put_bits(&pb, 1, dovi->el_present_flag);
> +put_bits(&pb, 1, dovi->bl_present_flag);
> +put_bits(&pb, 4, dovi->dv_bl_signal_compatibility_id);
> +
> +put_bits(&pb, 28, 0); /* reserved */
> +put_bits32(&pb, 0); /* reserved */
> +put_bits32(&pb, 0); /* reserved */
> +put_bits32(&pb, 0); /* reserved */
> +put_bits32(&pb, 0); /* reserved */
> +
> +flush_put_bits(&pb);
> +
> +av_log(s, AV_LOG_DEBUG, "DOVI in %s box, version: %d.%d, profile: %d, 
> level: %d, "
> +   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility 

Re: [FFmpeg-devel] [PATCH v9 3/5] avformat/mov: Refactor mov_read_dvcc_dvvc to use ff_isom_parse_dvcc_dvvc

2021-12-07 Thread lance . lmwang
On Sun, Dec 05, 2021 at 06:35:33PM +0100, quietvoid wrote:
> To avoid duplicating code. The implementation in dovi_isom is identical.
> 
> Signed-off-by: quietvoid 
> ---
>  libavformat/mov.c | 50 +--
>  1 file changed, 9 insertions(+), 41 deletions(-)
> 
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 5c74d099da..b5f974fe05 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -55,6 +55,7 @@
>  #include "avformat.h"
>  #include "internal.h"
>  #include "avio_internal.h"
> +#include "dovi_isom.h"
>  #include "riff.h"
>  #include "isom.h"
>  #include "libavcodec/get_bits.h"
> @@ -7051,58 +7052,25 @@ static int mov_read_dmlp(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  static int mov_read_dvcc_dvvc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>  {
>  AVStream *st;
> -uint32_t buf;
> -AVDOVIDecoderConfigurationRecord *dovi;
> -size_t dovi_size;
> +uint8_t buf[ISOM_DVCC_DVVC_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
>  int ret;
> +int64_t read_size = atom.size;
>  
>  if (c->fc->nb_streams < 1)
>  return 0;
>  st = c->fc->streams[c->fc->nb_streams-1];
>  
> -if ((uint64_t)atom.size > (1<<30) || atom.size < 4)
> -return AVERROR_INVALIDDATA;
> -
> -dovi = av_dovi_alloc(&dovi_size);
> -if (!dovi)
> -return AVERROR(ENOMEM);
> -
> -dovi->dv_version_major = avio_r8(pb);
> -dovi->dv_version_minor = avio_r8(pb);
> -
> -buf = avio_rb16(pb);
> -dovi->dv_profile= (buf >> 9) & 0x7f;// 7 bits
> -dovi->dv_level  = (buf >> 3) & 0x3f;// 6 bits
> -dovi->rpu_present_flag  = (buf >> 2) & 0x01;// 1 bit
> -dovi->el_present_flag   = (buf >> 1) & 0x01;// 1 bit
> -dovi->bl_present_flag   =  buf   & 0x01;// 1 bit
> -if (atom.size >= 24) {  // 4 + 4 + 4 * 4
> -buf = avio_r8(pb);
> -dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 bits
> -} else {
> -// 0 stands for None
> -// Dolby Vision V1.2.93 profiles and levels
> -dovi->dv_bl_signal_compatibility_id = 0;
> +// At most 24 bytes
> +if (read_size > ISOM_DVCC_DVVC_SIZE) {
> +read_size = ISOM_DVCC_DVVC_SIZE;
>  }
>  
> -ret = av_stream_add_side_data(st, AV_PKT_DATA_DOVI_CONF,
> -  (uint8_t *)dovi, dovi_size);
> -if (ret < 0) {
> -av_free(dovi);
> +if ((ret = avio_read(pb, buf, read_size)) < 0)
>  return ret;
> -}
>  
> -av_log(c, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, 
> profile: %d, level: %d, "
> -   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
> -   dovi->dv_version_major, dovi->dv_version_minor,
> -   dovi->dv_profile, dovi->dv_level,
> -   dovi->rpu_present_flag,
> -   dovi->el_present_flag,
> -   dovi->bl_present_flag,
> -   dovi->dv_bl_signal_compatibility_id
> -);
> +read_size = ret;

I prefer to check ret ! = read_size before like below:
if ((ret = avio_read(pb, buf, read_size)) != read_size)
return ret < 0 ? ret : AVERROR(EIO);

>  
> -return 0;
> +return ff_isom_parse_dvcc_dvvc(c->fc, st, buf, read_size);
>  }
>  
>  static int mov_read_kind(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> -- 
> 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".

-- 
Thanks,
Limin Wang
___
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 v9 4/5] avformat/movenc: Refactor mov_write_dvcc_dvvc_tag to use ff_isom_put_dvcc_dvvc

2021-12-07 Thread lance . lmwang
On Sun, Dec 05, 2021 at 06:35:34PM +0100, quietvoid wrote:
> Improves code legibility by not using bit shifts.
> Also avoids duplicating the dvcC/dvvC ISOM box writing code.
> 
> Signed-off-by: quietvoid 
> ---
>  libavformat/movenc.c | 24 +++-
>  1 file changed, 7 insertions(+), 17 deletions(-)
> 
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 38ff90833a..208378fc11 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -27,6 +27,7 @@
>  #include "movenc.h"
>  #include "avformat.h"
>  #include "avio_internal.h"
> +#include "dovi_isom.h"
>  #include "riff.h"
>  #include "avio.h"
>  #include "isom.h"
> @@ -1911,6 +1912,8 @@ static int mov_write_sv3d_tag(AVFormatContext *s, 
> AVIOContext *pb, AVSphericalMa
>  
>  static int mov_write_dvcc_dvvc_tag(AVFormatContext *s, AVIOContext *pb, 
> AVDOVIDecoderConfigurationRecord *dovi)
>  {
> +uint8_t buf[ISOM_DVCC_DVVC_SIZE];
> +
>  avio_wb32(pb, 32); /* size = 8 + 24 */
>  if (dovi->dv_profile > 10)
>  ffio_wfourcc(pb, "dvwC");
> @@ -1918,23 +1921,10 @@ static int mov_write_dvcc_dvvc_tag(AVFormatContext 
> *s, AVIOContext *pb, AVDOVIDe
>  ffio_wfourcc(pb, "dvvC");
>  else
>  ffio_wfourcc(pb, "dvcC");
> -avio_w8(pb, dovi->dv_version_major);
> -avio_w8(pb, dovi->dv_version_minor);
> -avio_wb16(pb, (dovi->dv_profile << 9) | (dovi->dv_level << 3) |
> -  (dovi->rpu_present_flag << 2) | (dovi->el_present_flag << 1) |
> -  dovi->bl_present_flag);
> -avio_wb32(pb, (dovi->dv_bl_signal_compatibility_id << 28) | 0);
> -
> -ffio_fill(pb, 0, 4 * 4); /* reserved */
> -av_log(s, AV_LOG_DEBUG, "DOVI in %s box, version: %d.%d, profile: %d, 
> level: %d, "
> -   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
> -   dovi->dv_profile > 10 ? "dvwC" : (dovi->dv_profile > 7 ? "dvvC" : 
> "dvcC"),
> -   dovi->dv_version_major, dovi->dv_version_minor,
> -   dovi->dv_profile, dovi->dv_level,
> -   dovi->rpu_present_flag,
> -   dovi->el_present_flag,
> -   dovi->bl_present_flag,
> -   dovi->dv_bl_signal_compatibility_id);
> +
> +ff_isom_put_dvcc_dvvc(s, buf, dovi);
> +avio_write(pb, buf, sizeof(buf));
> +

LGTM

>  return 32; /* 8 + 24 */
>  }
>  
> -- 
> 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".

-- 
Thanks,
Limin Wang
___
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] python filter

2021-12-07 Thread Alex
Yes.
I wat to do filtering inside python script.

7 December 2021, 05:16:50, by "Steven Liu" :

Alex <3.1...@ukr.net> 于2021年12月7日周二 上午9:12写道:
>
> Is it possible to implement python backend as ffmpeg video filter, like 
> https://openvinotoolkit.github.io/dlstreamer_gst/ ?
Do you mean add a Python parser into libavfilter looks like a GLSL parser?
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

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


[FFmpeg-devel] [PATCH v2] webp: implement FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM

2021-12-07 Thread Alex Xu (Hello71)
Roughly doubles webp performance for common applications (ffmpeg,
ffprobe, mpv) due to speeding up avformat_find_stream_info.

Lossy needs no patches since vp8.c already implements skip_frame.
Lossless needs hook to understand skip_frame. Also the "image data not
found" message is fixed, which was already broken with manual
-skip_frame but would now be exposed in default operation.
---
 libavcodec/webp.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index d5a81fd527..e425bce3ff 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1126,6 +1126,9 @@ static int vp8_lossless_decode_frame(AVCodecContext 
*avctx, AVFrame *p,
 h = s->height;
 }
 
+if (avctx->skip_frame == AVDISCARD_ALL)
+return data_size;
+
 /* parse transformations */
 s->nb_transforms = 0;
 s->reduced_width = s->width;
@@ -1339,7 +1342,7 @@ static int webp_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 AVFrame * const p = data;
 WebPContext *s = avctx->priv_data;
 GetByteContext gb;
-int ret;
+int ret, got_frame_chunk = 0;
 uint32_t chunk_type, chunk_size;
 int vp8x_flags = 0;
 
@@ -1392,6 +1395,7 @@ static int webp_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
  chunk_size);
 if (ret < 0)
 return ret;
+got_frame_chunk = 1;
 }
 bytestream2_skip(&gb, chunk_size);
 break;
@@ -1403,6 +1407,7 @@ static int webp_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 if (ret < 0)
 return ret;
 avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
+got_frame_chunk = 1;
 }
 bytestream2_skip(&gb, chunk_size);
 break;
@@ -1524,7 +1529,7 @@ exif_end:
 }
 }
 
-if (!*got_frame) {
+if (!got_frame_chunk) {
 av_log(avctx, AV_LOG_ERROR, "image data not found\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1565,5 +1570,5 @@ const AVCodec ff_webp_decoder = {
 .decode = webp_decode_frame,
 .close  = webp_decode_close,
 .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
-.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | 
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
 };
-- 
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 v8 1/2] avformat/imf: Demuxer

2021-12-07 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
The IMF demuxer accepts as input an IMF CPL. The assets referenced by the 
CPL can be
contained in multiple deliveries, each defined by an ASSETMAP file:

ffmpeg -assetmaps ,,... -i 

If -assetmaps is not specified, FFMPEG looks for a file called ASSETMAP.xml 
in the same directory as the CPL.

EXAMPLE:
ffmpeg -i 
http://ffmpeg-imf-samples-public.s3-website-us-west-1.amazonaws.com/countdown/CPL_f5095caa-f204-4e1c-8a84-7af48c7ae16b.xml
 out.mp4

The Interoperable Master Format (IMF) is a file-based media format for the
delivery and storage of professional audio-visual masters.
An IMF Composition consists of an XML playlist (the Composition Playlist)
and a collection of MXF files (the Track Files). The Composition Playlist 
(CPL)
assembles the Track Files onto a timeline, which consists of multiple 
tracks.
The location of the Track Files referenced by the Composition Playlist is 
stored
in one or more XML documents called Asset Maps. More details at 
https://www.imfug.com/explainer.
The IMF standard was first introduced in 2013 and is managed by the SMPTE.

CHANGE NOTES:

- reduced line width
- use ff_ and FF prefixes for non-local functions and structures
- modified copyright header
- fixed rational initialization
- removed extraneous call to xmlCleanupParser()
- fix if/for single line braces
- replace av_realloc_f with av_fast_realloc when allocating CPL Resources 
and
  ASSETMAP assets

 MAINTAINERS  |   1 +
 configure|   3 +-
 doc/demuxers.texi|   6 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/imf.h| 207 +
 libavformat/imf_cpl.c| 782 ++
 libavformat/imfdec.c | 895 +++
 8 files changed, 1895 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/imf.h
 create mode 100644 libavformat/imf_cpl.c
 create mode 100644 libavformat/imfdec.c

diff --git a/MAINTAINERS b/MAINTAINERS
index dcac46003e..7a6972fe1a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -433,6 +433,7 @@ Muxers/Demuxers:
   idroqdec.cMike Melanson
   iff.c Jaikrishnan Menon
   img2*.c   Michael Niedermayer
+  imf*.cMarc-Antoine Arnaud, Pierre-Anthony 
Lemieux, Valentin Noël
   ipmovie.c Mike Melanson
   ircam*Paul B Mahol
   iss.c Stefan Gehrer
diff --git a/configure b/configure
index 04f319b197..4401069cb9 100755
--- a/configure
+++ b/configure
@@ -298,7 +298,7 @@ External library support:
   --enable-libxvid enable Xvid encoding via xvidcore,
native MPEG-4/Xvid encoder exists [no]
   --enable-libxml2 enable XML parsing using the C library libxml2, 
needed
-   for dash demuxing support [no]
+   for dash and imf demuxing support [no]
   --enable-libzimg enable z.lib, needed for zscale filter [no]
   --enable-libzmq  enable message passing via libzmq [no]
   --enable-libzvbi enable teletext support via libzvbi [no]
@@ -3400,6 +3400,7 @@ hls_muxer_select="mpegts_muxer"
 hls_muxer_suggest="gcrypt openssl"
 image2_alias_pix_demuxer_select="image2_demuxer"
 image2_brender_pix_demuxer_select="image2_demuxer"
+imf_demuxer_deps="libxml2"
 ipod_muxer_select="mov_muxer"
 ismv_muxer_select="mov_muxer"
 ivf_muxer_select="av1_metadata_bsf vp9_superframe_bsf"
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index cab8a7072c..655704d2c4 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -267,6 +267,12 @@ which streams to actually receive.
 Each stream mirrors the @code{id} and @code{bandwidth} properties from the
 @code{} as metadata keys named "id" and "variant_bitrate" 
respectively.
 
+@section imf
+
+Interoperable Master Format demuxer.
+
+This demuxer presents audio and video streams found in an IMF Composition.
+
 @section flv, live_flv, kux
 
 Adobe Flash Video Format demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2b5caf9d33..7f058f3ea0 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -285,6 +285,7 @@ OBJS-$(CONFIG_IMAGE_WEBP_PIPE_DEMUXER)+= img2dec.o 
img2.o
 OBJS-$(CONFIG_IMAGE_XBM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_XPM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_XWD_PIPE_DEMUXER) += img2dec.o img2.o
+OBJS-$(CONFIG_IMF_DEMUXER)   += imfdec.o imf_cpl.o
 OBJS-$(CONFIG_INGENIENT_DEMUXER) += ingenientdec.o rawdec.o
 OBJS-$(CONFIG_IPMOVIE_DEMUXER)   += ipmovie.o
 OBJS-$(CONFIG_IPU_DEMUXER)   += ipudec.o rawdec.o
diff --git a/libavforma

[FFmpeg-devel] [PATCH v8 2/2] avformat/imf: Tests

2021-12-07 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
Tests for the IMF demuxer.

 libavformat/Makefile|   1 +
 libavformat/tests/imf.c | 525 
 2 files changed, 526 insertions(+)
 create mode 100644 libavformat/tests/imf.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 7f058f3ea0..533bb67f31 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -697,6 +697,7 @@ TESTPROGS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh
 TESTPROGS-$(CONFIG_MOV_MUXER)+= movenc
 TESTPROGS-$(CONFIG_NETWORK)  += noproxy
 TESTPROGS-$(CONFIG_SRTP) += srtp
+TESTPROGS-$(CONFIG_IMF_DEMUXER)  += imf
 
 TOOLS = aviocat \
 ismindex\
diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
new file mode 100644
index 00..02ec5030ad
--- /dev/null
+++ b/libavformat/tests/imf.c
@@ -0,0 +1,525 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ *
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Tests for IMF CPL and ASSETMAP processing
+ * 
+ * @author Valentin Noel
+ * @author Pierre-Anthony Lemieux
+ * @file
+ * @ingroup lavu_imf
+ */
+
+#include "libavformat/imf_cpl.c"
+#include "libavformat/imfdec.c"
+#include "libavformat/mxf.h"
+
+#include 
+
+const char *cpl_doc =
+"http://www.smpte-ra.org/schemas/2067-3/2016\"";
+" xmlns:cc=\"http://www.smpte-ra.org/schemas/2067-2/2016\"";
+" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\";>"
+"urn:uuid:8713c020-2489-45f5-a9f7-87be539e20b5"
+"2021-07-13T17:06:22Z"
+"FFMPEG"
+"FFMPEG sample content"
+""
+"  "
+"urn:uuid:8e097bb0-cff7-4969-a692-bad47bfb528f"
+"  "
+""
+"24000 1001"
+""
+""
+"urn:uuid:81fed4e5-9722-400a-b9d1-7f2bd21df4b6"
+""
+""
+"urn:uuid:16327185-9205-47ef-a17b-ee28df251db7"
+"urn:uuid:461f5424-8f6e-48a9-a385-5eda46fda381"
+""
+""
+"urn:uuid:ea3d0f23-55d6-4e03-86ec-cfe0666f0e6a"
+"24"
+""
+"LFOA"
+"5"
+""
+""
+""
+""
+""
+"urn:uuid:6ae100b0-92d1-41be-9321-85e0933dfc42"
+"urn:uuid:e8ef9653-565c-479c-8039-82d4547973c5"
+""
+""
+"urn:uuid:7d418acb-07a3-4e57-984c-b8ea2f7de4ec"
+"24"
+
"urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751"
+"urn:uuid:6f768ca4-c89e-4dac-9056-a29425d40ba1"
+""
+""
+""
+""
+"urn:uuid:754dae53-c25f-4f3c-97e4-2bfe5463f83b"
+"urn:uuid:68e3fae5-d94b-44d2-92a6-b94877fbcdb5"
+""
+""
+"urn:uuid:61ce2a70-10a2-4521-850b-4218755ff3c9"
+"24"
+
"urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751"
+"urn:uuid:381dadd2-061e-46cc-a63a-e3d58ce7f488"
+""
+""
+""
+""
+"urn:uuid:d29b3884-6633-4dad-9c67-7154af342bc6"
+"urn:uuid:6978c106-95bc-424b-a17

Re: [FFmpeg-devel] [PATCH v7 1/2] avformat/imf: Demuxer

2021-12-07 Thread Pierre-Anthony Lemieux
On Mon, Dec 6, 2021 at 9:45 AM Lynne  wrote:
>
> 6 Dec 2021, 04:18 by p...@sandflow.com:
>
> > From: Pierre-Anthony Lemieux 
> > +
> > +/**
>
> Please don't NIH-parse UUIDs. They're more complicated
> than this. Use libuuid, it's stable, bug-free and universally
> available. I submitted a patch for it last month for an
> unrelated use, which I decided to drop, but you
> can see how it was done there.

libuuid might be overkill and not a great match in the case of the IMF demuxer:

- libuuid does not parse the URN-encoding of UUIDs, which is used in
the IMF CPL ("urn:uuid:017b57a3-c61e-4b50-8c62-4586ea8a7769")
- the IMF demuxer does not need to generate UUIDs
- the IMF demuxer does not depend about the internal fields/format of
UUIDs or need to manipulate UUIDs: it merely compares them
byte-by-byte

>
> Also, please follow the code style. We use snake_case
> for function names, which means there are no capital
> letters in them.

Addressed in patch v8.

> There are also still one or two one-line statements
> left that are wrapped in brackets.

Addressed in patch v8.

>
> We check every single allocation we make, since malloc()
> can fail on Windows. So that means all av_strdup calls,
> av_append_path_component calls and so on can
> return NULL, and result in a nasty crash.

Addressed in patch v8.

>
> Do not use strtok. It's not thread-safe at all. Use av_strtok,
> which is thread-safe.

Addressed in patch v8.

>
> ff_imf_cpl_free() has a weird branch that can just be
> done with a return if cpl is NULL.

Addressed in patch v8.

>
> There are places where you call av_free() and then
> set the pointer to NULL. We have a convenience
> function for this, av_freep().

Addressed in patch v8.
>
> Please use defined-length integers instead of "unsigned long".
> If something needs to be 64-bits, use (u)int64_t. If something
> doesn't need to be 64-bits, use uint32_t for unsigned, or plain
> int for signed. We always require plain ints to be 32-bits.

Addressed in patch v8.

>
> Also, instead of printing 64-bit ints via "%lu", use "%"PRIu64"
> and "%"PRIi64". MSVC has problems with %lu.

Addressed in patch v8.

> ___
> 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 v7 1/2] avformat/imf: Demuxer

2021-12-07 Thread Pierre-Anthony Lemieux
On Mon, Dec 6, 2021 at 12:55 PM Andreas Rheinhardt
 wrote:
>
> p...@sandflow.com:
> > From: Pierre-Anthony Lemieux 
> >
> > Signed-off-by: Pierre-Anthony Lemieux 
> > ---
> >
> > Notes:
> > The IMF demuxer accepts as input an IMF CPL. The assets referenced by 
> > the CPL can be
> > contained in multiple deliveries, each defined by an ASSETMAP file:
> >
> > ffmpeg -assetmaps ,,... -i  > of CPL>
> >
> > If -assetmaps is not specified, FFMPEG looks for a file called 
> > ASSETMAP.xml in the same directory as the CPL.
> >
> > EXAMPLE:
> > ffmpeg -i 
> > http://ffmpeg-imf-samples-public.s3-website-us-west-1.amazonaws.com/countdown/CPL_f5095caa-f204-4e1c-8a84-7af48c7ae16b.xml
> >  out.mp4
> >
> > The Interoperable Master Format (IMF) is a file-based media format for 
> > the
> > delivery and storage of professional audio-visual masters.
> > An IMF Composition consists of an XML playlist (the Composition 
> > Playlist)
> > and a collection of MXF files (the Track Files). The Composition 
> > Playlist (CPL)
> > assembles the Track Files onto a timeline, which consists of multiple 
> > tracks.
> > The location of the Track Files referenced by the Composition Playlist 
> > is stored
> > in one or more XML documents called Asset Maps. More details at 
> > https://www.imfug.com/explainer.
> > The IMF standard was first introduced in 2013 and is managed by the 
> > SMPTE.
> >
> > CHANGE NOTES:
> >
> > - reduced line width
> > - use ff_ and FF prefixes for non-local functions and structures
> > - modified copyright header
> > - fixed rational initialization
> > - removed extraneous call to xmlCleanupParser()
> > - fix if/for single line braces
> > - replace av_realloc_f with av_fast_realloc when allocating CPL 
> > Resources and
> >   ASSETMAP assets
> >
> >  MAINTAINERS  |   1 +
> >  configure|   3 +-
> >  doc/demuxers.texi|  19 +
> >  libavformat/Makefile |   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/imf.h| 206 +
> >  libavformat/imf_cpl.c| 769 +
> >  libavformat/imfdec.c | 907 +++
> >  8 files changed, 1906 insertions(+), 1 deletion(-)
> >  create mode 100644 libavformat/imf.h
> >  create mode 100644 libavformat/imf_cpl.c
> >  create mode 100644 libavformat/imfdec.c
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index dcac46003e..7a6972fe1a 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -433,6 +433,7 @@ Muxers/Demuxers:
> >idroqdec.cMike Melanson
> >iff.c Jaikrishnan Menon
> >img2*.c   Michael Niedermayer
> > +  imf*.cMarc-Antoine Arnaud, 
> > Pierre-Anthony Lemieux, Valentin Noël
> >ipmovie.c Mike Melanson
> >ircam*Paul B Mahol
> >iss.c Stefan Gehrer
> > diff --git a/configure b/configure
> > index a98a18abaa..022f17767b 100755
> > --- a/configure
> > +++ b/configure
> > @@ -298,7 +298,7 @@ External library support:
> >--enable-libxvid enable Xvid encoding via xvidcore,
> > native MPEG-4/Xvid encoder exists [no]
> >--enable-libxml2 enable XML parsing using the C library libxml2, 
> > needed
> > -   for dash demuxing support [no]
> > +   for dash and imf demuxing support [no]
> >--enable-libzimg enable z.lib, needed for zscale filter [no]
> >--enable-libzmq  enable message passing via libzmq [no]
> >--enable-libzvbi enable teletext support via libzvbi [no]
> > @@ -3400,6 +3400,7 @@ hls_muxer_select="mpegts_muxer"
> >  hls_muxer_suggest="gcrypt openssl"
> >  image2_alias_pix_demuxer_select="image2_demuxer"
> >  image2_brender_pix_demuxer_select="image2_demuxer"
> > +imf_demuxer_deps="libxml2"
> >  ipod_muxer_select="mov_muxer"
> >  ismv_muxer_select="mov_muxer"
> >  ivf_muxer_select="av1_metadata_bsf vp9_superframe_bsf"
> > diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> > index cab8a7072c..614f2e754a 100644
> > --- a/doc/demuxers.texi
> > +++ b/doc/demuxers.texi
> > @@ -267,6 +267,12 @@ which streams to actually receive.
> >  Each stream mirrors the @code{id} and @code{bandwidth} properties from the
> >  @code{} as metadata keys named "id" and "variant_bitrate" 
> > respectively.
> >
> > +@section imf
> > +
> > +Interoperable Master Format demuxer.
> > +
> > +This demuxer presents audio and video streams found in an IMF Composition.
> > +
> >  @section flv, live_flv, kux
> >
> >  Adobe Flash Video Format demuxer.
> > @@ -770,6 +776,19 @@ MJPEG stream. Turning this option on by setting it to 
> > 1 will result in a stricte
> >  of the boundary value.
> >  @end table
> >
> > +@section mxf
> > 

Re: [FFmpeg-devel] python filter

2021-12-07 Thread Ronald S. Bultje
Hi,

On Tue, Dec 7, 2021 at 12:53 PM Alex <3.1...@ukr.net> wrote:

> Yes.
> I wat to do filtering inside python script.
>

No, that is currently not possible.

Ronald
___
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] lavu/frame: Add Dolby Vision metadata side data type

2021-12-07 Thread Niklas Haas
From: Niklas Haas 

Signed-off-by: Niklas Haas 
---
 doc/APIchanges|   3 ++
 libavutil/dovi_meta.c |  23 
 libavutil/dovi_meta.h | 121 ++
 libavutil/frame.c |   1 +
 libavutil/frame.h |   9 +++-
 libavutil/version.h   |   2 +-
 6 files changed, 157 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 2914ad6734..422874e3b9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2021-12-06 - xx - lavu 57.11.100 - frame.h
+  Add AV_FRAME_DATA_DOVI_RESHAPING.
+
 2021-11-xx - xx - lavfi 8.19.100 - avfilter.h
   Add AVFILTER_FLAG_METADATA_ONLY.
 
diff --git a/libavutil/dovi_meta.c b/libavutil/dovi_meta.c
index 7bd08f6c54..e2ef8ac3a4 100644
--- a/libavutil/dovi_meta.c
+++ b/libavutil/dovi_meta.c
@@ -33,3 +33,26 @@ AVDOVIDecoderConfigurationRecord *av_dovi_alloc(size_t *size)
 
 return dovi;
 }
+
+/* based on guesswork, see mkvtoolnix and dovi_tool */
+int av_dovi_profile(const AVDOVIRpuDataHeader *hdr)
+{
+switch (hdr->vdr_rpu_profile) {
+case 0:
+if (hdr->bl_video_full_range_flag)
+return 5;
+break;
+case 1:
+if (hdr->el_spatial_resampling_filter_flag && 
!hdr->disable_residual_flag) {
+if (hdr->vdr_bit_depth == 12) {
+return 7;
+} else {
+return 4;
+}
+} else {
+return 8;
+}
+}
+
+return 0; /* unknown */
+}
diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
index 299911d434..02c414752c 100644
--- a/libavutil/dovi_meta.h
+++ b/libavutil/dovi_meta.h
@@ -29,6 +29,7 @@
 
 #include 
 #include 
+#include "rational.h"
 
 /*
  * DOVI configuration
@@ -67,4 +68,124 @@ typedef struct AVDOVIDecoderConfigurationRecord {
  */
 AVDOVIDecoderConfigurationRecord *av_dovi_alloc(size_t *size);
 
+/**
+ * Dolby Vision RPU data header.
+ */
+typedef struct AVDOVIRpuDataHeader {
+uint8_t rpu_type;
+uint16_t rpu_format;
+uint8_t vdr_rpu_profile;
+uint8_t vdr_rpu_level;
+int chroma_resampling_explicit_filter_flag;
+uint8_t coef_data_type; /* informative, lavc always converts to fixed */
+uint8_t coef_log2_denom;
+uint8_t vdr_rpu_normalized_idc;
+int bl_video_full_range_flag;
+uint8_t bl_bit_depth; /* [8, 16] */
+uint8_t el_bit_depth; /* [8, 16] */
+uint8_t vdr_bit_depth; /* [8, 16] */
+int spatial_resampling_filter_flag;
+int el_spatial_resampling_filter_flag;
+int disable_residual_flag;
+} AVDOVIRpuDataHeader;
+
+/**
+ * Return the Dolby Vision profile number derived from a given RPU data header,
+ * or 0 for unknown/unrecognized profiles.
+ */
+int av_dovi_profile(const AVDOVIRpuDataHeader *hdr);
+
+enum AVDOVIMappingMethod {
+AV_DOVI_MAPPING_POLYNOMIAL = 0,
+AV_DOVI_MAPPING_MMR = 1,
+};
+
+/**
+ * Coefficients of a piece-wise function. The pieces of the function span the
+ * value ranges between two adjacent pivot values.
+ */
+#define FF_DOVI_MAX_PIECES 8
+typedef struct AVDOVIReshapingCurve {
+uint8_t num_pivots; /* [2, 9], or 0 to skip this 
comp */
+uint16_t pivots[FF_DOVI_MAX_PIECES + 1];/* sorted ascending */
+enum AVDOVIMappingMethod mapping_idc[FF_DOVI_MAX_PIECES];
+/* AV_DOVI_MAPPING_POLYNOMIAL */
+uint8_t poly_order[FF_DOVI_MAX_PIECES]; /* [1, 2] */
+int64_t poly_coef[FF_DOVI_MAX_PIECES][3];   /* x^0, x^1, x^2 */
+/* AV_DOVI_MAPPING_MMR */
+uint8_t mmr_order[FF_DOVI_MAX_PIECES];  /* [1, 3] */
+int64_t mmr_constant[FF_DOVI_MAX_PIECES];
+int64_t mmr_coef[FF_DOVI_MAX_PIECES][3/* order - 1 */][7];
+} AVDOVIReshapingCurve;
+
+enum AVDOVINLQMethod {
+AV_DOVI_NLQ_LINEAR_DZ = 0,
+};
+
+/**
+ * Coefficients of the non-linear inverse quantization. For the interpretation
+ * of these, see ETSI GS CCM 001.
+ */
+typedef struct AVDOVINLQParams {
+uint64_t nlq_offset;
+uint64_t vdr_in_max;
+/* AV_DOVI_NLQ_LINEAR_DZ */
+uint64_t linear_deadzone_slope;
+uint64_t linear_deadzone_threshold;
+} AVDOVINLQParams;
+
+/**
+ * Dolby Vision RPU data mapping parameters.
+ */
+typedef struct AVDOVIDataMapping {
+uint8_t vdr_rpu_id;
+uint8_t mapping_color_space;
+uint8_t mapping_chroma_format_idc;
+AVDOVIReshapingCurve curves[3]; /* per component */
+
+/* Non-linear inverse quantization */
+enum AVDOVINLQMethod nlq_method_idc;
+uint32_t num_x_partitions;
+uint32_t num_y_partitions;
+AVDOVINLQParams nlq[3]; /* per component */
+} AVDOVIDataMapping;
+
+typedef struct AVDOVIColorMetadata {
+uint8_t dm_metadata_id;
+int scene_refresh_flag;
+
+/**
+ * Coefficients of the custom Dolby Vision IPT-PQ matrices. These are to be
+ * used instead of the matrices indicated by the frame's colorspace tags.
+ * The output of rgb_to_lms_matrix is to be fed into a BT.2020 LMS->RGB
+ * matrix base

[FFmpeg-devel] [PATCH 2/4] lavfi/showinfo: Support AV_FRAME_DATA_DOVI_METADATA

2021-12-07 Thread Niklas Haas
From: Niklas Haas 

Signed-off-by: Niklas Haas 
---
 libavfilter/vf_showinfo.c | 108 ++
 1 file changed, 108 insertions(+)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 62c7833247..79294f6891 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -27,6 +27,7 @@
 #include "libavutil/bswap.h"
 #include "libavutil/adler32.h"
 #include "libavutil/display.h"
+#include "libavutil/dovi_meta.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/film_grain_params.h"
@@ -429,6 +430,110 @@ static void 
dump_sei_film_grain_params_metadata(AVFilterContext *ctx, const AVFr
 }
 }
 
+static void dump_dovi_metadata(AVFilterContext *ctx, const AVFrameSideData *sd)
+{
+const AVDOVIMetadata *dovi = (const AVDOVIMetadata *) sd->data;
+const AVDOVIRpuDataHeader *hdr = &dovi->header;
+const AVDOVIDataMapping *mapping = &dovi->mapping;
+const AVDOVIColorMetadata *color = &dovi->color;
+
+av_log(ctx, AV_LOG_INFO, "Dolby Vision RPU metadata:\n");
+av_log(ctx, AV_LOG_INFO, "rpu_type=%"PRIu8"; ", hdr->rpu_type);
+av_log(ctx, AV_LOG_INFO, "rpu_format=%"PRIu16"; ", hdr->rpu_format);
+av_log(ctx, AV_LOG_INFO, "vdr_rpu_profile=%"PRIu8"; ", 
hdr->vdr_rpu_profile);
+av_log(ctx, AV_LOG_INFO, "vdr_rpu_level=%"PRIu8"; ", hdr->vdr_rpu_level);
+av_log(ctx, AV_LOG_INFO, "chroma_resampling_explicit_filter_flag=%d; ", 
hdr->chroma_resampling_explicit_filter_flag);
+av_log(ctx, AV_LOG_INFO, "coef_data_type=%"PRIu8"; ", hdr->coef_data_type);
+av_log(ctx, AV_LOG_INFO, "coef_log2_denom=%"PRIu8"; ", 
hdr->coef_log2_denom);
+av_log(ctx, AV_LOG_INFO, "vdr_rpu_normalized_idc=%"PRIu8"; ", 
hdr->vdr_rpu_normalized_idc);
+av_log(ctx, AV_LOG_INFO, "bl_video_full_range_flag=%d; ", 
hdr->bl_video_full_range_flag);
+av_log(ctx, AV_LOG_INFO, "bl_bit_depth=%"PRIu8"; ", hdr->bl_bit_depth);
+av_log(ctx, AV_LOG_INFO, "el_bit_depth=%"PRIu8"; ", hdr->el_bit_depth);
+av_log(ctx, AV_LOG_INFO, "vdr_bit_depth=%"PRIu8"; ", hdr->vdr_bit_depth);
+av_log(ctx, AV_LOG_INFO, "spatial_resampling_filter_flag=%d; ", 
hdr->spatial_resampling_filter_flag);
+av_log(ctx, AV_LOG_INFO, "el_spatial_resampling_filter_flag=%d; ", 
hdr->el_spatial_resampling_filter_flag);
+av_log(ctx, AV_LOG_INFO, "disable_residual_flag=%d\n", 
hdr->disable_residual_flag);
+
+av_log(ctx, AV_LOG_INFO, "data mapping: ");
+av_log(ctx, AV_LOG_INFO, "vdr_rpu_id=%"PRIu8"; ", mapping->vdr_rpu_id);
+av_log(ctx, AV_LOG_INFO, "mapping_color_space=%"PRIu8"; ", 
mapping->mapping_color_space);
+av_log(ctx, AV_LOG_INFO, "mapping_chroma_format_idc=%"PRIu8"; ", 
mapping->mapping_chroma_format_idc);
+av_log(ctx, AV_LOG_INFO, "nlq_method_idc=%d; ", (int) 
mapping->nlq_method_idc);
+av_log(ctx, AV_LOG_INFO, "num_x_partitions=%"PRIu32"; ", 
mapping->num_x_partitions);
+av_log(ctx, AV_LOG_INFO, "num_y_partitions=%"PRIu32"\n", 
mapping->num_y_partitions);
+
+for (int c = 0; c < 3; c++) {
+const AVDOVIReshapingCurve *curve = &mapping->curves[c];
+const AVDOVINLQParams *nlq = &mapping->nlq[c];
+av_log(ctx, AV_LOG_INFO, "  channel %d: ", c);
+av_log(ctx, AV_LOG_INFO, "pivots={ ");
+for (int i = 0; i < curve->num_pivots; i++)
+av_log(ctx, AV_LOG_INFO, "%"PRIu16" ", curve->pivots[i]);
+av_log(ctx, AV_LOG_INFO, "}; mapping_idc={ ");
+for (int i = 0; i < curve->num_pivots - 1; i++)
+av_log(ctx, AV_LOG_INFO, "%d ", (int) curve->mapping_idc[i]);
+av_log(ctx, AV_LOG_INFO, "}; poly_order={ ");
+for (int i = 0; i < curve->num_pivots - 1; i++)
+av_log(ctx, AV_LOG_INFO, "%"PRIu8" ", curve->poly_order[i]);
+av_log(ctx, AV_LOG_INFO, "}; poly_coef={ ");
+for (int i = 0; i < curve->num_pivots - 1; i++) {
+av_log(ctx, AV_LOG_INFO, "{%"PRIi64", %"PRIi64", %"PRIi64"} ",
+   curve->poly_coef[i][0],
+   curve->poly_coef[i][1],
+   curve->poly_coef[i][2]);
+}
+
+av_log(ctx, AV_LOG_INFO, "}; mmr_order={ ");
+for (int i = 0; i < curve->num_pivots - 1; i++)
+av_log(ctx, AV_LOG_INFO, "%"PRIu8" ", curve->mmr_order[i]);
+av_log(ctx, AV_LOG_INFO, "}; mmr_constant={ ");
+for (int i = 0; i < curve->num_pivots - 1; i++)
+av_log(ctx, AV_LOG_INFO, "%"PRIi64" ", curve->mmr_constant[i]);
+av_log(ctx, AV_LOG_INFO, "}; mmr_coef={ ");
+for (int i = 0; i < curve->num_pivots - 1; i++) {
+av_log(ctx, AV_LOG_INFO, "{");
+for (int j = 0; j < curve->mmr_order[i]; j++) {
+for (int k = 0; k < 7; k++)
+av_log(ctx, AV_LOG_INFO, "%"PRIi64" ", 
curve->mmr_coef[i][j][k]);
+}
+av_log(ctx, AV_LOG_INFO, "} ");
+}
+
+av_log(ctx, AV_LOG_INFO, "}; nlq_offset=%"PRIu64"; ", nlq->nlq_offset);

[FFmpeg-devel] [PATCH 3/4] lavc: Implement Dolby Vision RPU parsing

2021-12-07 Thread Niklas Haas
From: Niklas Haas 

Based on a mixture of guesswork, partial documentation in patents, and
reverse engineering of real-world samples. Confirmed working for all the
samples I've thrown at it.

Contains some annoying machinery to persist these values in between
frames, which is needed in theory even though I've never actually seen a
sample that relies on it in practice. May or may not work.

Notable omissions:
- CRC32 verificaiton. This is based on the MPEG2 CRC32 type, which does
  not seem to be implemented in lavc. (And I don't care enough to do so)
- Linear interpolation support. Nothing documents this (beyond its
  existence) and no samples use it, so impossible to implement.
- All of the extension metadata blocks, but these contain values that
  are basically congruent with ST2094, HDR10, or other existing forms of
  side data, so I will defer parsing/attaching them to a future commit.

Heavily influenced by https://github.com/quietvoid/dovi_tool
Documentation drawn from US Patent 10,701,399 B2 and ETSI GS CCM 001

Signed-off-by: Niklas Haas 
---
 libavcodec/Makefile |   2 +
 libavcodec/dovi.c   | 367 
 libavcodec/dovi.h   |  62 
 3 files changed, 431 insertions(+)
 create mode 100644 libavcodec/dovi.c
 create mode 100644 libavcodec/dovi.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4122a9b144..ece29ca0bd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -14,6 +14,7 @@ HEADERS = ac3_parser.h
  \
   d3d11va.h \
   defs.h\
   dirac.h   \
+  dovi.h\
   dv_profile.h  \
   dxva2.h   \
   jni.h \
@@ -40,6 +41,7 @@ OBJS = ac3_parser.o   
  \
d3d11va.o\
decode.o \
dirac.o  \
+   dovi.o   \
dv_profile.o \
encode.o \
imgconvert.o \
diff --git a/libavcodec/dovi.c b/libavcodec/dovi.c
new file mode 100644
index 00..7ac6d61aaf
--- /dev/null
+++ b/libavcodec/dovi.c
@@ -0,0 +1,367 @@
+/*
+ * Dolby Vision RPU decoder
+ *
+ * Copyright (C) 2021 Jan Ekström
+ * Copyright (C) 2021 Niklas Haas
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dovi.h"
+#include "golomb.h"
+#include "get_bits.h"
+
+enum {
+RPU_COEFF_FIXED = 0,
+RPU_COEFF_FLOAT = 1,
+};
+
+/**
+ * Private contents of vdr_ref.
+ */
+typedef struct DOVIVdrRef {
+AVDOVIDataMapping mapping;
+AVDOVIColorMetadata color;
+} DOVIVdrRef;
+
+void ff_dovi_ctx_unref(DOVIContext *s)
+{
+for (int i = 0; i < DOVI_MAX_DM_ID; i++)
+av_buffer_unref(&s->vdr_ref[i]);
+
+/* Preserve the AVCodecContext explicitly, reset everything else */
+*s = (DOVIContext) {
+.avctx = s->avctx,
+};
+}
+
+int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
+{
+int ret;
+for (int i = 0; i < DOVI_MAX_DM_ID; i++) {
+if ((ret = av_buffer_replace(&s->vdr_ref[i], s0->vdr_ref[i])) < 0) {
+s->mapping = NULL; /* sanity */
+s->color = NULL;
+return ret;
+}
+}
+
+s->mapping = s0->mapping;
+s->color = s0->color;
+return 0;
+}
+
+static inline uint64_t get_ue_coef(GetBitContext *gb, const 
AVDOVIRpuDataHeader *hdr)
+{
+uint64_t ipart;
+union { uint32_t u32; float f32; } fpart;
+
+switch (hdr->coef_data_type) {
+case RPU_COEFF_FIXED:
+ipart = get_ue_golomb_long(gb);
+fpart.u32 = get_bits_

[FFmpeg-devel] [PATCH 4/4] lavc/hevcdec: Parse DOVI RPU NALs

2021-12-07 Thread Niklas Haas
From: Niklas Haas 

And expose the parsed values as frame side data.

Signed-off-by: Niklas Haas 
---
 libavcodec/hevcdec.c | 32 ++--
 libavcodec/hevcdec.h |  2 ++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 46d9edf8eb..0561ff9e68 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -38,6 +38,7 @@
 #include "bswapdsp.h"
 #include "bytestream.h"
 #include "cabac_functions.h"
+#include "dovi.h"
 #include "golomb.h"
 #include "hevc.h"
 #include "hevc_data.h"
@@ -2967,6 +2968,19 @@ static int set_side_data(HEVCContext *s)
 s->rpu_buf = NULL;
 }
 
+if (s->dovi_ctx.mapping && s->dovi_ctx.color) {
+AVDOVIMetadata *dovi;
+AVFrameSideData *sd = av_frame_new_side_data(out, 
AV_FRAME_DATA_DOVI_METADATA,
+ sizeof(AVDOVIMetadata));
+if (!sd)
+return AVERROR(ENOMEM);
+
+dovi = (AVDOVIMetadata *) sd->data;
+memcpy(&dovi->header, &s->dovi_ctx.header, sizeof(dovi->header));
+memcpy(&dovi->mapping, s->dovi_ctx.mapping, sizeof(dovi->mapping));
+memcpy(&dovi->color, s->dovi_ctx.color, sizeof(dovi->color));
+}
+
 return 0;
 }
 
@@ -3298,16 +3312,23 @@ static int decode_nal_units(HEVCContext *s, const 
uint8_t *buf, int length)
 if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == 
HEVC_NAL_UNSPEC62 &&
 s->pkt.nals[s->pkt.nb_nals - 1].size > 2 && 
!s->pkt.nals[s->pkt.nb_nals - 1].nuh_layer_id
 && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) {
+H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1];
 if (s->rpu_buf) {
 av_buffer_unref(&s->rpu_buf);
 av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found 
in one AU. Skipping previous.\n");
 }
 
-s->rpu_buf = av_buffer_alloc(s->pkt.nals[s->pkt.nb_nals - 1].raw_size 
- 2);
+s->rpu_buf = av_buffer_alloc(nal->raw_size - 2);
 if (!s->rpu_buf)
 return AVERROR(ENOMEM);
 
-memcpy(s->rpu_buf->data, s->pkt.nals[s->pkt.nb_nals - 1].raw_data + 2, 
s->pkt.nals[s->pkt.nb_nals - 1].raw_size - 2);
+memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2);
+ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2);
+if (ret < 0) {
+av_buffer_unref(&s->rpu_buf);
+av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
+goto fail;
+}
 }
 
 /* decode the NAL units */
@@ -3553,6 +3574,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
 
 pic_arrays_free(s);
 
+ff_dovi_ctx_unref(&s->dovi_ctx);
 av_buffer_unref(&s->rpu_buf);
 
 av_freep(&s->md5_ctx);
@@ -3637,6 +3659,7 @@ static av_cold int hevc_init_context(AVCodecContext 
*avctx)
 
 ff_bswapdsp_init(&s->bdsp);
 
+s->dovi_ctx.avctx = avctx;
 s->context_initialized = 1;
 s->eos = 0;
 
@@ -3745,6 +3768,10 @@ static int hevc_update_thread_context(AVCodecContext 
*dst,
 if (ret < 0)
 return ret;
 
+ret = ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
+if (ret < 0)
+return ret;
+
 s->sei.frame_packing= s0->sei.frame_packing;
 s->sei.display_orientation  = s0->sei.display_orientation;
 s->sei.mastering_display= s0->sei.mastering_display;
@@ -3801,6 +3828,7 @@ static void hevc_decode_flush(AVCodecContext *avctx)
 HEVCContext *s = avctx->priv_data;
 ff_hevc_flush_dpb(s);
 ff_hevc_reset_sei(&s->sei);
+ff_dovi_ctx_unref(&s->dovi_ctx);
 av_buffer_unref(&s->rpu_buf);
 s->max_ra = INT_MAX;
 s->eos = 1;
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 870ff178d4..5b04a8ad83 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -32,6 +32,7 @@
 #include "avcodec.h"
 #include "bswapdsp.h"
 #include "cabac.h"
+#include "dovi.h"
 #include "get_bits.h"
 #include "hevcpred.h"
 #include "h2645_parse.h"
@@ -574,6 +575,7 @@ typedef struct HEVCContext {
 int nuh_layer_id;
 
 AVBufferRef *rpu_buf;   ///< 0 or 1 Dolby Vision RPUs.
+DOVIContext dovi_ctx;   ///< Dolby Vision decoding context
 } HEVCContext;
 
 /**
-- 
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 v9 3/5] avformat/mov: Refactor mov_read_dvcc_dvvc to use ff_isom_parse_dvcc_dvvc

2021-12-07 Thread quietvoid
On Tue, Dec 7, 2021 at 9:37 AM  wrote:
>
> On Sun, Dec 05, 2021 at 06:35:33PM +0100, quietvoid wrote:
> > To avoid duplicating code. The implementation in dovi_isom is identical.
> >
> > Signed-off-by: quietvoid 
> > ---
> >  libavformat/mov.c | 50 +--
> >  1 file changed, 9 insertions(+), 41 deletions(-)
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index 5c74d099da..b5f974fe05 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -55,6 +55,7 @@
> >  #include "avformat.h"
> >  #include "internal.h"
> >  #include "avio_internal.h"
> > +#include "dovi_isom.h"
> >  #include "riff.h"
> >  #include "isom.h"
> >  #include "libavcodec/get_bits.h"
> > @@ -7051,58 +7052,25 @@ static int mov_read_dmlp(MOVContext *c, AVIOContext 
> > *pb, MOVAtom atom)
> >  static int mov_read_dvcc_dvvc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> >  {
> >  AVStream *st;
> > -uint32_t buf;
> > -AVDOVIDecoderConfigurationRecord *dovi;
> > -size_t dovi_size;
> > +uint8_t buf[ISOM_DVCC_DVVC_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
> >  int ret;
> > +int64_t read_size = atom.size;
> >
> >  if (c->fc->nb_streams < 1)
> >  return 0;
> >  st = c->fc->streams[c->fc->nb_streams-1];
> >
> > -if ((uint64_t)atom.size > (1<<30) || atom.size < 4)
> > -return AVERROR_INVALIDDATA;
> > -
> > -dovi = av_dovi_alloc(&dovi_size);
> > -if (!dovi)
> > -return AVERROR(ENOMEM);
> > -
> > -dovi->dv_version_major = avio_r8(pb);
> > -dovi->dv_version_minor = avio_r8(pb);
> > -
> > -buf = avio_rb16(pb);
> > -dovi->dv_profile= (buf >> 9) & 0x7f;// 7 bits
> > -dovi->dv_level  = (buf >> 3) & 0x3f;// 6 bits
> > -dovi->rpu_present_flag  = (buf >> 2) & 0x01;// 1 bit
> > -dovi->el_present_flag   = (buf >> 1) & 0x01;// 1 bit
> > -dovi->bl_present_flag   =  buf   & 0x01;// 1 bit
> > -if (atom.size >= 24) {  // 4 + 4 + 4 * 4
> > -buf = avio_r8(pb);
> > -dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 bits
> > -} else {
> > -// 0 stands for None
> > -// Dolby Vision V1.2.93 profiles and levels
> > -dovi->dv_bl_signal_compatibility_id = 0;
> > +// At most 24 bytes
> > +if (read_size > ISOM_DVCC_DVVC_SIZE) {
> > +read_size = ISOM_DVCC_DVVC_SIZE;
> >  }
> >
> > -ret = av_stream_add_side_data(st, AV_PKT_DATA_DOVI_CONF,
> > -  (uint8_t *)dovi, dovi_size);
> > -if (ret < 0) {
> > -av_free(dovi);
> > +if ((ret = avio_read(pb, buf, read_size)) < 0)
> >  return ret;
> > -}
> >
> > -av_log(c, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, 
> > profile: %d, level: %d, "
> > -   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: 
> > %d\n",
> > -   dovi->dv_version_major, dovi->dv_version_minor,
> > -   dovi->dv_profile, dovi->dv_level,
> > -   dovi->rpu_present_flag,
> > -   dovi->el_present_flag,
> > -   dovi->bl_present_flag,
> > -   dovi->dv_bl_signal_compatibility_id
> > -);
> > +read_size = ret;
>
> I prefer to check ret ! = read_size before like below:
> if ((ret = avio_read(pb, buf, read_size)) != read_size)
> return ret < 0 ? ret : AVERROR(EIO);

Agreed. Will fix it.

> >
> > -return 0;
> > +return ff_isom_parse_dvcc_dvvc(c->fc, st, buf, read_size);
> >  }
> >
> >  static int mov_read_kind(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> > --
> > 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".
>
> --
> Thanks,
> Limin Wang
> ___
> 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 3/4] lavc: Implement Dolby Vision RPU parsing

2021-12-07 Thread James Almer




On 12/7/2021 4:59 PM, Niklas Haas wrote:

From: Niklas Haas 

Based on a mixture of guesswork, partial documentation in patents, and
reverse engineering of real-world samples. Confirmed working for all the
samples I've thrown at it.

Contains some annoying machinery to persist these values in between
frames, which is needed in theory even though I've never actually seen a
sample that relies on it in practice. May or may not work.

Notable omissions:
- CRC32 verificaiton. This is based on the MPEG2 CRC32 type, which does
   not seem to be implemented in lavc. (And I don't care enough to do so)
- Linear interpolation support. Nothing documents this (beyond its
   existence) and no samples use it, so impossible to implement.
- All of the extension metadata blocks, but these contain values that
   are basically congruent with ST2094, HDR10, or other existing forms of
   side data, so I will defer parsing/attaching them to a future commit.

Heavily influenced by https://github.com/quietvoid/dovi_tool
Documentation drawn from US Patent 10,701,399 B2 and ETSI GS CCM 001

Signed-off-by: Niklas Haas 
---
  libavcodec/Makefile |   2 +
  libavcodec/dovi.c   | 367 
  libavcodec/dovi.h   |  62 
  3 files changed, 431 insertions(+)
  create mode 100644 libavcodec/dovi.c
  create mode 100644 libavcodec/dovi.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4122a9b144..ece29ca0bd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -14,6 +14,7 @@ HEADERS = ac3_parser.h
  \
d3d11va.h \
defs.h\
dirac.h   \
+  dovi.h\


No need to add it to the installed headers list. It's internal.
___
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 v20 02/20] avutil/frame: Prepare AVFrame for subtitle handling

2021-12-07 Thread Michael Niedermayer
On Mon, Dec 06, 2021 at 02:42:58PM +0100, Nicolas George wrote:
> Hendrik Leppkes (12021-12-06):
> > You just keep re-iterating that avfilter internals need it. And I'll
> > just keep saying that avfilter internals shall not define public API
> > design. I have not heard anything that justifies yet another field
> > that has no benefit to the external public API - to the contrary even,
> > a user would assume pts is pts, and he would be wrong.
> 
> Thank you.
> 
> I need to add that libavfilter internals need it only because it was
> designed in a very naive way, by duplicating the frame instead of using
> dummy frames without content.
> 
> This is not the only part of these patch series that are improperly
> designed. 

> Having two different filters to overlay subs depending on
> whether they are text or bitmap is unacceptable. 

i do agree that is inconvenient i would not call it unacceptable


> Not having any utility
> filters (to shift or scale the times, to discard a segment, tu
> concatenate subtitles along with audio and video, to print diagnostic
> information, etc.) is also a big issue 

i agree too


[...]

> Now, if I knew I had the support of the core developers here, I could
> serenely get on with implementing FATE tests for the negotiation system
> and refactor it, which is the necessary first step before extending it
> for a third media type.

Anyone who does that without triggering hostilities and (either works
together with other developers OR finds any other solution all involved 
are happy with) has my support.
But i am a bit scared of more fights, hostilities between 2 cooks trying
to cook one soup.
And myself having more headaches from reading more escalating threads.
Basically i dont want to end up hiding depressed in a corner after some
quite hard headed developers fail to treat each other respectfully and
cooperate.

Also judging from your question here i guess that you have time and want
to work on FFmpeg ?
If you rather want to work on something else within FFmpeg.
I have both easy and hard things that need to be done
Easy one, fix ssl support on fate.ffmpeg.org (that is setup letsencrypt)

Hard one, can low latency support to libavfilter be improved?
consider a use case like realtime streaming, cloud gaming or some cloud
based metaverse any filtering done for these would benefit from really low 
latency.
Because the end user interacts with the remote and so any filtering
done adds top the latency of this loop

Is libavfilter optimal for this usecase ?
would some different threading be better, or maybe some information
exchange between filters about which lines from the previous filter 
are already available to the next to process

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If a bugfix only changes things apparently unrelated to the bug with no
further explanation, that is a good sign that the bugfix is wrong.


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] avformat/mxfenc: fix DNxHD GC ULs

2021-12-07 Thread Tomas Härdin
fre 2021-12-03 klockan 09:38 + skrev Nicolas Gaullier:
> > Please add a reference to the relevant SMPTE document in the
> > comment, or perhaps at the list of references at the start of the
> > file
> > 
> > /Tomas
> 
> I have added the reference to ST2019-4 for "VC3 mapping", so that
> should be ok for generic standard files.
> It seems redundant for me, but if you want, I could add the link to
> the online register where the container ul is public ?
> https://registry.smpte-ra.org/apps/pages/
> 
> Concerning the essence key, it is more tricky because of AVID in the
> place...
> To start with, apart AVID, all frame-wrapped samples I have (I can
> share them with you but not all of them publicly), do respect the
> standard
> - frame-wrapped : ARRI, Adobe Media Encoder, Harmonic : always 0x0C
> ("DNxHD" frame-mapping)
> There are up to date publicly available ARRI samples where 0x0C is
> used here:
> https://www.arri.com/en/learn-help/learn-help-camera-system/camera-sample-footage
> 
> But I also have an AVID Op1a file where the value 0x05 is used
> ("MPEG" frame-mapping, ie. s381m).
> And concerning OPAtom, Philip de Nier has an AVID sample where the
> value 0x06 is used ("MPEG" clip-wrapping).
> 
> So, what is apparent at the end is that :
> - apart from AVID, the standard values 0x0c/0x0d are used
> - AVID uses the values from the older "MPEG mapping" (ie smpte 381m)
> 
> Now :
> - currently ffmpeg uses 0x05 for OPatom which does not follow any
> implementation and seems bad
> - it seems there is a consensus (incl. AVID) to always use 0x05 or
> 0x0C for frame-wrapping and 0x06 or 0x0d for clip-wrapping (OPAtom)
> => follow either s381m or st2019-4
> - it seems clear ffmpeg shall take the "standard-flavor" for generic
> OP's, so 0x0C for frame-based wrapping
> - it is less clear about OPAtom which is rather an AVID-hack-thing,
> but it should be moved to either 0x06 or 0x0d
> - I have discussed this with philip de nier, and bmx (a reference
> software in my opinion) will stick to the AVID form, so 0x06. And I
> think it is reasonable, since OPAtom/Avid are almost the same damn
> thing
> 
> Note: no matter the essence key, the link between the tracks and the
> body with the TrackNumber always work, so it seems there are not much
> interoperability issues with it.

Seems I missed the reference to the VC-3 spec somehow, sorry. Since it
is Matthieu Bouron who added this initially, you should really talk to
him. I care less about mxfenc than I do mxfdec, since the latter can
more easily induce CVEs.

That said, if we want this to work correctly for everyone then we need
a proper set of tests. We also need to go over all the specs, and what
all implementations are currently doing. Which is a lot of work. Or a
lot of billable hours!

This is why I've said for years now that we should delete mxfenc and
just bring in bmx. We don't need what little free software people there
are who know MXF to keep maintaining two codebases.

We could just bring in bmx as a subtree and be done with it. Delete all
MXF code native to FFmpeg, put all effort into bmx. People in this
project suffer from the belief that code is valuable rather than a
liability. Worse is not better. Correct is better.

/Tomas

___
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] avcodec/movtextdec: Rename several structure elements

2021-12-07 Thread Andreas Rheinhardt
Giving elements of a structure called StyleBox names like
"style_start" or "style_end" is redundant, especially given
that the relevant variables are also called style.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/movtextdec.c | 54 -
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index 4e14ae5900..7021ad9e24 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -54,7 +54,7 @@
 #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 
0xff))
 
 typedef struct {
-uint16_t fontID;
+uint16_t font_id;
 const char *font;
 uint8_t fontsize;
 int color;
@@ -68,21 +68,21 @@ typedef struct {
 } MovTextDefault;
 
 typedef struct {
-uint16_t fontID;
+uint16_t font_id;
 char *font;
 } FontRecord;
 
 typedef struct {
-uint16_t style_start;
-uint16_t style_end;
-uint8_t style_flag;
+uint16_t start;
+uint16_t end;
+uint8_t flags;
 uint8_t bold;
 uint8_t italic;
 uint8_t underline;
 int color;
 uint8_t alpha;
 uint8_t fontsize;
-uint16_t style_fontID;
+uint16_t font_id;
 } StyleBox;
 
 typedef struct {
@@ -186,12 +186,12 @@ static int mov_text_tx3g(AVCodecContext *avctx, 
MovTextContext *m)
 // StyleRecord
 tx3g_ptr += 4;
 // fontID
-m->d.fontID = bytestream_get_be16(&tx3g_ptr);
+m->d.font_id   = bytestream_get_be16(&tx3g_ptr);
 // face-style-flags
-s_default.style_flag = bytestream_get_byte(&tx3g_ptr);
-m->d.bold = !!(s_default.style_flag & STYLE_FLAG_BOLD);
-m->d.italic = !!(s_default.style_flag & STYLE_FLAG_ITALIC);
-m->d.underline = !!(s_default.style_flag & STYLE_FLAG_UNDERLINE);
+s_default.flags = bytestream_get_byte(&tx3g_ptr);
+m->d.bold  = !!(s_default.flags & STYLE_FLAG_BOLD);
+m->d.italic= !!(s_default.flags & STYLE_FLAG_ITALIC);
+m->d.underline = !!(s_default.flags & STYLE_FLAG_UNDERLINE);
 // fontsize
 m->d.fontsize = bytestream_get_byte(&tx3g_ptr);
 // Primary color
@@ -218,8 +218,8 @@ static int mov_text_tx3g(AVCodecContext *avctx, 
MovTextContext *m)
 m->ftab_entries = ftab_entries;
 
 for (i = 0; i < m->ftab_entries; i++) {
-m->ftab[i].fontID = bytestream_get_be16(&tx3g_ptr);
-if (m->ftab[i].fontID == m->d.fontID)
+m->ftab[i].font_id = bytestream_get_be16(&tx3g_ptr);
+if (m->ftab[i].font_id == m->d.font_id)
 j = i;
 font_length = bytestream_get_byte(&tx3g_ptr);
 
@@ -283,14 +283,14 @@ static int decode_styl(const uint8_t *tsmb, 
MovTextContext *m, const AVPacket *a
 for(i = 0; i < m->style_entries; i++) {
 StyleBox *style = &m->s[i];
 
-style->style_start = bytestream_get_be16(&tsmb);
-style->style_end   = bytestream_get_be16(&tsmb);
-if (   style->style_end < style->style_start
-|| (i && style->style_start < m->s[i - 1].style_end)) {
+style->start = bytestream_get_be16(&tsmb);
+style->end   = bytestream_get_be16(&tsmb);
+if (style->end < style->start ||
+(i && style->start < m->s[i - 1].end)) {
 mov_text_cleanup(m);
 return AVERROR(ENOMEM);
 }
-if (style->style_start == style->style_end) {
+if (style->start == style->end) {
 /* Skip this style as it applies to no character */
 tsmb += 8;
 m->style_entries--;
@@ -298,11 +298,11 @@ static int decode_styl(const uint8_t *tsmb, 
MovTextContext *m, const AVPacket *a
 continue;
 }
 
-style->style_fontID = bytestream_get_be16(&tsmb);
-style->style_flag   = bytestream_get_byte(&tsmb);
-style->bold  = !!(style->style_flag & STYLE_FLAG_BOLD);
-style->italic= !!(style->style_flag & STYLE_FLAG_ITALIC);
-style->underline = !!(style->style_flag & STYLE_FLAG_UNDERLINE);
+style->font_id   = bytestream_get_be16(&tsmb);
+style->flags = bytestream_get_byte(&tsmb);
+style->bold  = !!(style->flags & STYLE_FLAG_BOLD);
+style->italic= !!(style->flags & STYLE_FLAG_ITALIC);
+style->underline = !!(style->flags & STYLE_FLAG_UNDERLINE);
 style->fontsize  = bytestream_get_byte(&tsmb);
 style->color = bytestream_get_be24(&tsmb);
 style->alpha = bytestream_get_byte(&tsmb);
@@ -355,13 +355,13 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 
 if ((m->box_flags & STYL_BOX) && entry < m->style_entries) {
 const StyleBox *style = &m->s[entry];
-if (text_pos == style->style_end) {
+if (text_pos == style->end) {
 av_bprintf(buf, "{\\r}");
 color = m->d.color;
 entry++;
 style++;
 }
-if (entry < m->style_entries && text_pos == style->style_start) {
+

[FFmpeg-devel] [PATCH 2/4] avcodec/movtextdec: Deduplicate parsing of StyleRecords

2021-12-07 Thread Andreas Rheinhardt
Both TextSampleEntry and TextSample can contain StyleRecords;
yet both the code as well as the structures for them were duplicated.
This commit changes this.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/movtextdec.c | 95 +++--
 1 file changed, 44 insertions(+), 51 deletions(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index 7021ad9e24..d3b15d07f8 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -53,20 +53,6 @@
 
 #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 
0xff))
 
-typedef struct {
-uint16_t font_id;
-const char *font;
-uint8_t fontsize;
-int color;
-uint8_t alpha;
-int back_color;
-uint8_t back_alpha;
-uint8_t bold;
-uint8_t italic;
-uint8_t underline;
-int alignment;
-} MovTextDefault;
-
 typedef struct {
 uint16_t font_id;
 char *font;
@@ -85,6 +71,14 @@ typedef struct {
 uint16_t font_id;
 } StyleBox;
 
+typedef struct {
+StyleBox style;
+const char *font;
+int back_color;
+uint8_t back_alpha;
+int alignment;
+} MovTextDefault;
+
 typedef struct {
 uint16_t hlit_start;
 uint16_t hlit_end;
@@ -137,13 +131,28 @@ static void mov_text_cleanup_ftab(MovTextContext *m)
 m->ftab_entries = 0;
 }
 
+static void mov_text_parse_style_record(StyleBox *style, const uint8_t **ptr)
+{
+// fontID
+style->font_id   = bytestream_get_be16(ptr);
+// face-style-flags
+style->flags = bytestream_get_byte(ptr);
+style->bold  = !!(style->flags & STYLE_FLAG_BOLD);
+style->italic= !!(style->flags & STYLE_FLAG_ITALIC);
+style->underline = !!(style->flags & STYLE_FLAG_UNDERLINE);
+// fontsize
+style->fontsize  = bytestream_get_byte(ptr);
+// Primary color
+style->color = bytestream_get_be24(ptr);
+style->alpha = bytestream_get_byte(ptr);
+}
+
 static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
 {
 const uint8_t *tx3g_ptr = avctx->extradata;
 int i, j = -1, font_length, remaining = avctx->extradata_size - 
BOX_SIZE_INITIAL;
 int8_t v_align, h_align;
 unsigned ftab_entries;
-StyleBox s_default;
 
 m->ftab_entries = 0;
 if (remaining < 0)
@@ -185,18 +194,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, 
MovTextContext *m)
 tx3g_ptr += 8;
 // StyleRecord
 tx3g_ptr += 4;
-// fontID
-m->d.font_id   = bytestream_get_be16(&tx3g_ptr);
-// face-style-flags
-s_default.flags = bytestream_get_byte(&tx3g_ptr);
-m->d.bold  = !!(s_default.flags & STYLE_FLAG_BOLD);
-m->d.italic= !!(s_default.flags & STYLE_FLAG_ITALIC);
-m->d.underline = !!(s_default.flags & STYLE_FLAG_UNDERLINE);
-// fontsize
-m->d.fontsize = bytestream_get_byte(&tx3g_ptr);
-// Primary color
-m->d.color = bytestream_get_be24(&tx3g_ptr);
-m->d.alpha = bytestream_get_byte(&tx3g_ptr);
+mov_text_parse_style_record(&m->d.style, &tx3g_ptr);
 // FontRecord
 // FontRecord Size
 tx3g_ptr += 4;
@@ -219,7 +217,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, 
MovTextContext *m)
 
 for (i = 0; i < m->ftab_entries; i++) {
 m->ftab[i].font_id = bytestream_get_be16(&tx3g_ptr);
-if (m->ftab[i].font_id == m->d.font_id)
+if (m->ftab[i].font_id == m->d.style.font_id)
 j = i;
 font_length = bytestream_get_byte(&tx3g_ptr);
 
@@ -298,14 +296,7 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext 
*m, const AVPacket *a
 continue;
 }
 
-style->font_id   = bytestream_get_be16(&tsmb);
-style->flags = bytestream_get_byte(&tsmb);
-style->bold  = !!(style->flags & STYLE_FLAG_BOLD);
-style->italic= !!(style->flags & STYLE_FLAG_ITALIC);
-style->underline = !!(style->flags & STYLE_FLAG_UNDERLINE);
-style->fontsize  = bytestream_get_byte(&tsmb);
-style->color = bytestream_get_be24(&tsmb);
-style->alpha = bytestream_get_byte(&tsmb);
+mov_text_parse_style_record(style, &tsmb);
 }
 return 0;
 }
@@ -337,10 +328,11 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
AVCodecContext *avctx)
 {
 MovTextContext *m = avctx->priv_data;
+const StyleBox *const default_style = &m->d.style;
 int i = 0;
 int text_pos = 0;
 int entry = 0;
-int color = m->d.color;
+int color = default_style->color;
 
 if (text < text_end && m->box_flags & TWRP_BOX) {
 if (m->w.wrap_flag == 1) {
@@ -357,29 +349,29 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 const StyleBox *style = &m->s[entry];
 if (text_pos == style->end) {
 av_bprintf(buf, "{\\r}");
-color = m->d.color;
+color = default_style->color;
 entry++;
 style++;
 }
  

[FFmpeg-devel] [PATCH 3/4] avcodec/movtextdec: Perform RGB->BGR color conversion early

2021-12-07 Thread Andreas Rheinhardt
Reduces the amount of conversions.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/movtextdec.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index d3b15d07f8..c50626c0b5 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -144,6 +144,7 @@ static void mov_text_parse_style_record(StyleBox *style, 
const uint8_t **ptr)
 style->fontsize  = bytestream_get_byte(ptr);
 // Primary color
 style->color = bytestream_get_be24(ptr);
+style->color = RGB_TO_BGR(style->color);
 style->alpha = bytestream_get_byte(ptr);
 }
 
@@ -189,6 +190,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, 
MovTextContext *m)
 }
 // Background Color
 m->d.back_color = bytestream_get_be24(&tx3g_ptr);
+m->d.back_color = RGB_TO_BGR(m->d.back_color);
 m->d.back_alpha = bytestream_get_byte(&tx3g_ptr);
 // BoxRecord
 tx3g_ptr += 8;
@@ -369,7 +371,7 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 }
 if (default_style->color != style->color) {
 color = style->color;
-av_bprintf(buf, "{\\1c&H%X&}", RGB_TO_BGR(color));
+av_bprintf(buf, "{\\1c&H%X&}", color);
 }
 if (default_style->alpha != style->alpha)
 av_bprintf(buf, "{\\1a&H%02X&}", 255 - style->alpha);
@@ -392,10 +394,10 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 }
 if (text_pos == m->h.hlit_end) {
 if (m->box_flags & HCLR_BOX) {
-av_bprintf(buf, "{\\2c&H%X&}", 
RGB_TO_BGR(default_style->color));
+av_bprintf(buf, "{\\2c&H%X&}", default_style->color);
 } else {
 av_bprintf(buf, "{\\1c&H%X&}{\\2c&H%X&}",
-   RGB_TO_BGR(color), 
RGB_TO_BGR(default_style->color));
+   color, default_style->color);
 }
 }
 }
@@ -441,10 +443,10 @@ static int mov_text_init(AVCodecContext *avctx) {
 return ff_ass_subtitle_header_full(avctx,
 m->frame_width, m->frame_height,
 m->d.font, default_style->fontsize,
-(255U - default_style->alpha) << 24 | 
RGB_TO_BGR(default_style->color),
-(255U - default_style->alpha) << 24 | 
RGB_TO_BGR(default_style->color),
-(255U - m->d.back_alpha) << 24 | 
RGB_TO_BGR(m->d.back_color),
-(255U - m->d.back_alpha) << 24 | 
RGB_TO_BGR(m->d.back_color),
+(255U - default_style->alpha) << 24 | default_style->color,
+(255U - default_style->alpha) << 24 | default_style->color,
+(255U - m->d.back_alpha) << 24 | m->d.back_color,
+(255U - m->d.back_alpha) << 24 | m->d.back_color,
 default_style->bold, default_style->italic, 
default_style->underline,
 ASS_DEFAULT_BORDERSTYLE, m->d.alignment);
 } else
-- 
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 4/4] avcodec/movtextdec: Sanitize style entries

2021-12-07 Thread Andreas Rheinhardt
There are three types of style entries which are redundant:
a) Entries with length zero. They are already discarded.
b) Entries that are equivalent to the default style:
They can be safely discarded.
c) Entries that are equivalent to the immediately preceding style
if the start of the current style coincides with the end of the
preceding style. In this case the styles can be merged.

This commit implements discarding/merging in cases b) and c).
This fixes ticket #9548. In said ticket each packet contained
exactly one style entry that covered the complete packet with
the exception of the last character (probably created by a tool
that didn't know that the style's end is exclusive). Said style
coincided with the default style, leading to a superfluous reset,
which is now gone.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/movtextdec.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index c50626c0b5..b0c54bf1d0 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -263,6 +263,14 @@ static int decode_hclr(const uint8_t *tsmb, MovTextContext 
*m, const AVPacket *a
 return 0;
 }
 
+static int styles_equivalent(const StyleBox *a, const StyleBox *b)
+{
+#define CMP(field) a->field == b->field
+return CMP(bold)  && CMP(italic)   && CMP(underline) && CMP(color) &&
+   CMP(alpha) && CMP(fontsize) && CMP(font_id);
+#undef CMP
+}
+
 static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket 
*avpkt)
 {
 int i;
@@ -299,6 +307,19 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext 
*m, const AVPacket *a
 }
 
 mov_text_parse_style_record(style, &tsmb);
+if (styles_equivalent(style, &m->d.style)) {
+/* Skip this style as it is equivalent to the default style */
+m->style_entries--;
+i--;
+continue;
+} else if (i && style->start == style[-1].end &&
+   styles_equivalent(style, &style[-1])) {
+/* Merge the two adjacent styles */
+style[-1].end = style->end;
+m->style_entries--;
+i--;
+continue;
+}
 }
 return 0;
 }
-- 
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 3/4] avformat/mxfdec: Check component_depth in mxf_get_color_range()

2021-12-07 Thread Tomas Härdin
lör 2021-12-04 klockan 22:32 +0100 skrev Michael Niedermayer:
> Fixes: shift exponent 4294967163 is too large for 32-bit type 'int'
> Fixes: 41449/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-
> 6183636217495552
> 
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfdec.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index af9d33f7969..c231c944c01 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -2274,12 +2274,12 @@ static enum AVColorRange
> mxf_get_color_range(MXFContext *mxf, MXFDescriptor *des
>  /* CDCI range metadata */
>  if (!descriptor->component_depth)
>  return AVCOL_RANGE_UNSPECIFIED;
> -    if (descriptor->black_ref_level == 0 &&
> +    if (descriptor->black_ref_level == 0 && descriptor-
> >component_depth < 31 &&
>  descriptor->white_ref_level == ((1< >component_depth) - 1) &&
>  (descriptor->color_range    == (1< >component_depth) ||
>   descriptor->color_range    == ((1< >component_depth) - 1)))
>  return AVCOL_RANGE_JPEG;
> -    if (descriptor->component_depth >= 8 &&
> +    if (descriptor->component_depth >= 8 && descriptor-
> >component_depth < 31 &&
>  descriptor->black_ref_level == (1  <<(descriptor-
> >component_depth - 4)) &&
>  descriptor->white_ref_level == (235<<(descriptor-
> >component_depth - 8)) &&
>  descriptor->color_range == ((14<<(descriptor-
> >component_depth - 4)) + 1))

Looks OK

/Tomas

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

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


Re: [FFmpeg-devel] [PATCH 5/7] avformat/mxfdec: Check for duplicate mxf_read_index_entry_array()

2021-12-07 Thread Tomas Härdin
sön 2021-12-05 klockan 22:19 +0100 skrev Michael Niedermayer:
> Fixes: memleak
> Fixes: 41596/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-
> 6439060204290048
> 
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfdec.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index c231c944c01..1d501982793 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -,6 +,9 @@ static int
> mxf_read_index_entry_array(AVIOContext *pb, MXFIndexTableSegment *seg
>  {
>  int i, length;
>  
> +    if (segment->temporal_offset_entries)
> +    return AVERROR_INVALIDDATA;
> +
>  segment->nb_index_entries = avio_rb32(pb);
>  
>  length = avio_rb32(pb);

Should be OK. Not sure if the spec allows multiple IndexEntryArrays per
index table, but this at least shouldn't break anything since it
wouldn't have been working correctly before either way.

/Tomas

___
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 000/279] New channel layout API

2021-12-07 Thread James Almer
This is an updated and rebased version of the API that was sent to this mailing
list about two years ago. It expands it with some new helpers, implements some
changes that allows further extensibility for new features down the line, and
finishes porting all missing modules and those introduced since 2019.

I'm sending a reduced amount of patches to not spam the ML too much. In total
it's 279 patches, the bulk being one per module ported, which it's what i'm
skipping.
This reduced set will obviously not apply as is, so you can find the entire set
in https://github.com/jamrial/FFmpeg/commits/channel_layout

Anton Khirnov (136):
  Add a new channel layout API
  lavu: support AVChannelLayout AVOptions
  lavc: deprecate channel count/layout changing side data
  avframe: switch to the new channel layout API
  lavf: add a temporary compat layer for the channel layout API change
  lavf: convert the generic layer to the new channel layout
  3dostr: convert to new channel layout API
  aa: convert to new channel layout API
  acm: convert to new channel layout API
  act: convert to new channel layout API
  adp: convert to new channel layout API
  ads: convert to new channel layout API
  afc: convert to new channel layout API
  aixdec: convert to new channel layout API
  aptxdec: convert to new channel layout API
  argo: convert to new channel layout API
  ast: convert to new channel layout API
  avr: convert to new channel layout API
  bit: convert to new channel layout API
  boa: convert to new channel layout API
  brstm: convert to new channel layout API
  codec2: convert to new channel layout API
  dcstr: convert to new channel layout API
  dhav: convert to new channel layout API
  dtshddec: convert to new channel layout API
  dsfdec: convert to new channel layout API
  epafdec: convert to new channel layout API
  framehash: convert to new channel layout API
  fsb: convert to new channel layout API
  g726: convert to new channel layout API
  gdv: convert to new channel layout API
  genh: convert to new channel layout API
  hcom: convert to new channel layout API
  ifv: convert to new channel layout API
  ircam: convert to new channel layout API
  jack: port to new channel layout API
  libcdio: port to new channel layout API
  lvf: convert to new channel layout API
  mpeg: convert to new channel layout API
  mpegtsenc: convert to new channel layout API
  msf: convert to new channel layout API
  mtaf: convert to new channel layout API
  musx: convert to new channel layout API
  nistspheredec: convert to new channel layout API
  nspdec: convert to new channel layout API
  oss: port to new channel layout API
  pvf: convert to new channel layout API
  rawenc: convert to new channel layout API
  redspark: convert to new channel layout API
  rsd: convert to new channel layout API
  sbg: convert to new channel layout API
  sdr2: convert to new channel layout API
  sds: convert to new channel layout API
  sdx: convert to new channel layout API
  svag: convert to new channel layout API
  vag: convert to new channel layout API
  vividas: convert to new channel layout API
  vivo: convert to new channel layout API
  vpk: convert to new channel layout API
  lavf: drop the channel layout compat layer for old-style (de)muxers
  8svx: convert to new channel layout API
  aac: convert to new channel layout API
  adpcm: convert to new channel layout API
  alac: convert to new channel layout API
  amr: convert to new channel layout API
  aptx: convert to new channel layout API
  atrac9: convert to new channel layout API
  apedec: convert to new channel layout API
  audiotoolbox: convert to new channel layout API
  binkaudio: convert to new channel layout API
  bmvaudio: convert to new channel layout API
  cng: convert to new channel layout API
  cook: convert to new channel layout API
  dca: convert to new channel layout API
  dolby_e: convert to new channel layout API
  dsd: convert to new channel layout API
  dsicinav: convert to new channel layout API
  dst: convert to new channel layout API
  dvaudio: convert to new channel layout API
  evrc: convert to new channel layout API
  ffwavesynth: convert to new channel layout API
  flac: convert to new channel layout API
  g722: convert to new channel layout API
  g723_1: convert to new channel layout API
  g726: convert to new channel layout API
  g729: convert to new channel layout API
  gsmdec: convert to new channel layout API
  hcom: convert to new channel layout API
  ilbc: convert to new channel layout API
  imc: convert to new channel layout API
  interplayacm: convert to new channel layout API
  libcelt: convert to new channel layout API
  libcodec2: convert to new channel layout API
  libilbc: convert to new channel layout API
  libgsm: convert to new channel layout API
  libmp3lame: convert to new channel layout API
  libopencore-amr: convert to new channel layout API
  libopus: convert to new channel layout API
  libshine: convert to new channel layout API
  libspeexdec: conv

[FFmpeg-devel] [PATCH 001/279] Add a new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

The new API is more extensible and allows for custom layouts.
More accurate information is exported, eg for decoders that do not
set a channel layout, lavc will not make one up for them.

Deprecate the old API working with just uint64_t bitmasks.

Expanded and completed by Vittorio Giovara 
and James Almer .
Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavutil/channel_layout.c | 498 ++--
 libavutil/channel_layout.h | 510 ++---
 libavutil/version.h|   1 +
 3 files changed, 906 insertions(+), 103 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index ac773a9e63..984255bfca 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -37,81 +37,132 @@ struct channel_name {
 };
 
 static const struct channel_name channel_names[] = {
- [0] = { "FL","front left"},
- [1] = { "FR","front right"   },
- [2] = { "FC","front center"  },
- [3] = { "LFE",   "low frequency" },
- [4] = { "BL","back left" },
- [5] = { "BR","back right"},
- [6] = { "FLC",   "front left-of-center"  },
- [7] = { "FRC",   "front right-of-center" },
- [8] = { "BC","back center"   },
- [9] = { "SL","side left" },
-[10] = { "SR","side right"},
-[11] = { "TC","top center"},
-[12] = { "TFL",   "top front left"},
-[13] = { "TFC",   "top front center"  },
-[14] = { "TFR",   "top front right"   },
-[15] = { "TBL",   "top back left" },
-[16] = { "TBC",   "top back center"   },
-[17] = { "TBR",   "top back right"},
-[29] = { "DL","downmix left"  },
-[30] = { "DR","downmix right" },
-[31] = { "WL","wide left" },
-[32] = { "WR","wide right"},
-[33] = { "SDL",   "surround direct left"  },
-[34] = { "SDR",   "surround direct right" },
-[35] = { "LFE2",  "low frequency 2"   },
-[36] = { "TSL",   "top side left" },
-[37] = { "TSR",   "top side right"},
-[38] = { "BFC",   "bottom front center"   },
-[39] = { "BFL",   "bottom front left" },
-[40] = { "BFR",   "bottom front right"},
+[AV_CHAN_FRONT_LEFT   ] = { "FL","front left"},
+[AV_CHAN_FRONT_RIGHT  ] = { "FR","front right"   },
+[AV_CHAN_FRONT_CENTER ] = { "FC","front center"  },
+[AV_CHAN_LOW_FREQUENCY] = { "LFE",   "low frequency" },
+[AV_CHAN_BACK_LEFT] = { "BL","back left" },
+[AV_CHAN_BACK_RIGHT   ] = { "BR","back right"},
+[AV_CHAN_FRONT_LEFT_OF_CENTER ] = { "FLC",   "front left-of-center"  },
+[AV_CHAN_FRONT_RIGHT_OF_CENTER] = { "FRC",   "front right-of-center" },
+[AV_CHAN_BACK_CENTER  ] = { "BC","back center"   },
+[AV_CHAN_SIDE_LEFT] = { "SL","side left" },
+[AV_CHAN_SIDE_RIGHT   ] = { "SR","side right"},
+[AV_CHAN_TOP_CENTER   ] = { "TC","top center"},
+[AV_CHAN_TOP_FRONT_LEFT   ] = { "TFL",   "top front left"},
+[AV_CHAN_TOP_FRONT_CENTER ] = { "TFC",   "top front center"  },
+[AV_CHAN_TOP_FRONT_RIGHT  ] = { "TFR",   "top front right"   },
+[AV_CHAN_TOP_BACK_LEFT] = { "TBL",   "top back left" },
+[AV_CHAN_TOP_BACK_CENTER  ] = { "TBC",   "top back center"   },
+[AV_CHAN_TOP_BACK_RIGHT   ] = { "TBR",   "top back right"},
+[AV_CHAN_STEREO_LEFT  ] = { "DL","downmix left"  },
+[AV_CHAN_STEREO_RIGHT ] = { "DR","downmix right" },
+[AV_CHAN_WIDE_LEFT] = { "WL","wide left" },
+[AV_CHAN_WIDE_RIGHT   ] = { "WR","wide right"},
+[AV_CHAN_SURROUND_DIRECT_LEFT ] = { "SDL",   "surround direct left"  },
+[AV_CHAN_SURROUND_DIRECT_RIGHT] = { "SDR",   "surround direct right" },
+[AV_CHAN_LOW_FREQUENCY_2  ] = { "LFE2",  "low frequency 2"   },
+[AV_CHAN_TOP_SIDE_LEFT] = { "TSL",   "top side left" },
+[AV_CHAN_TOP_SIDE_RIGHT   ] = { "TSR",   "top side right"},
+[AV_CHAN_BOTTOM_FRONT_CENTER  ] = { "BFC",   "bottom front center"   },
+[AV_CHAN_BOTTOM_FRONT_LEFT] = { "BFL",   "bottom front left" },
+[AV_CHAN_BOTTOM_FRONT_RIGHT   ] = { "BFR",   "bottom front right"},
 };
 
-static const char *get_channel_name(i

[FFmpeg-devel] [PATCH 002/279] fate: add a channel_layout API test

2021-12-07 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/Makefile   |   1 +
 libavutil/tests/channel_layout.c | 221 +++
 tests/fate/libavutil.mak |   4 +
 tests/ref/fate/channel_layout|  88 
 4 files changed, 314 insertions(+)
 create mode 100644 libavutil/tests/channel_layout.c
 create mode 100644 tests/ref/fate/channel_layout

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 529046dbc8..8915575cfa 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -219,6 +219,7 @@ TESTPROGS = adler32 
\
 bprint  \
 cast5   \
 camellia\
+channel_layout  \
 color_utils \
 cpu \
 crc \
diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c
new file mode 100644
index 00..60854cf203
--- /dev/null
+++ b/libavutil/tests/channel_layout.c
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2021 James Almer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/channel_layout.c"
+
+#define CHANNEL_LAYOUT_FROM_MASK(layout, x)\
+av_channel_layout_uninit(&layout); \
+buf[0] = 0;\
+if (!av_channel_layout_from_mask(&layout, x))  \
+av_channel_layout_describe(&layout, buf, sizeof(buf));
+
+#define CHANNEL_LAYOUT_FROM_STRING(layout, x)  \
+av_channel_layout_uninit(&layout); \
+buf[0] = 0;\
+if (!av_channel_layout_from_string(&layout, x)) \
+av_channel_layout_describe(&layout, buf, sizeof(buf));
+
+#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(layout, x)   \
+ret = av_channel_layout_channel_from_index(&layout, x);\
+if (ret < 0)   \
+ret = -1
+
+#define CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(layout, x)   \
+ret = av_channel_layout_index_from_channel(&layout, x);\
+if (ret < 0)   \
+ret = -1
+
+#define CHANNEL_LAYOUT_CHANNEL_FROM_STRING(layout, x)  \
+ret = av_channel_layout_channel_from_string(&layout, x);   \
+if (ret < 0)   \
+ret = -1
+
+#define CHANNEL_LAYOUT_INDEX_FROM_STRING(layout, x)\
+ret = av_channel_layout_index_from_string(&layout, x); \
+if (ret < 0)   \
+ret = -1
+
+int main(void)
+{
+AVChannelLayout surround = { 0 };
+AVChannelLayout custom = { 0 };
+char buf[64];
+int ret;
+
+printf("Testing av_channel_name\n");
+av_channel_name(buf, sizeof(buf), AV_CHAN_FRONT_LEFT);
+printf("With AV_CHAN_FRONT_LEFT: %27s\n", buf);
+av_channel_name(buf, sizeof(buf), AV_CHAN_FRONT_RIGHT);
+printf("With AV_CHAN_FRONT_RIGHT: %26s\n", buf);
+
+printf("Testing av_channel_description\n");
+av_channel_description(buf, sizeof(buf), AV_CHAN_FRONT_LEFT);
+printf("With AV_CHAN_FRONT_LEFT: %27s\n", buf);
+av_channel_description(buf, sizeof(buf), AV_CHAN_FRONT_RIGHT);
+printf("With AV_CHAN_FRONT_RIGHT: %26s\n", buf);
+
+printf("\nTesting av_channel_from_string\n");
+printf("With \"FL\": %41d\n", av_channel_from_string("FL"));
+printf("With \"FR\": %41d\n", av_channel_from_string("FR"));
+
+printf("\nTesting av_channel_layout_from_string\n");
+CHANNEL_LAYOUT_FROM_STRING(surround, "0x3f");
+printf("With \"0x3f\": %39s\

[FFmpeg-devel] [PATCH 003/279] lavu: support AVChannelLayout AVOptions

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavutil/opt.c   | 126 +-
 libavutil/opt.h   |  12 
 libavutil/tests/opt.c |   8 +--
 tests/ref/fate/opt|  16 +++---
 4 files changed, 149 insertions(+), 13 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index d951edca9d..445537fbad 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -39,6 +39,7 @@
 #include "opt.h"
 #include "samplefmt.h"
 #include "bprint.h"
+#include "version.h"
 
 #include 
 
@@ -71,7 +72,11 @@ static int read_number(const AVOption *o, const void *dst, 
double *num, int *den
 case AV_OPT_TYPE_INT:
 *intnum = *(int *)dst;
 return 0;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 case AV_OPT_TYPE_DURATION:
 case AV_OPT_TYPE_INT64:
 case AV_OPT_TYPE_UINT64:
@@ -126,7 +131,11 @@ static int write_number(void *obj, const AVOption *o, void 
*dst, double num, int
 *(int *)dst = llrint(num / den) * intnum;
 break;
 case AV_OPT_TYPE_DURATION:
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 case AV_OPT_TYPE_INT64:{
 double d = num / den;
 if (intnum == 1 && d == (double)INT64_MAX) {
@@ -465,6 +474,16 @@ static int set_string_dict(void *obj, const AVOption *o, 
const char *val, uint8_
 return 0;
 }
 
+static int set_string_channel_layout(void *obj, const AVOption *o,
+ const char *val, void *dst)
+{
+AVChannelLayout *channel_layout = dst;
+av_channel_layout_uninit(channel_layout);
+if (!val)
+return 0;
+return av_channel_layout_from_string(channel_layout, val);
+}
+
 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
 {
 int ret = 0;
@@ -472,12 +491,17 @@ int av_opt_set(void *obj, const char *name, const char 
*val, int search_flags)
 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, 
&target_obj);
 if (!o || !target_obj)
 return AVERROR_OPTION_NOT_FOUND;
+FF_DISABLE_DEPRECATION_WARNINGS
 if (!val && (o->type != AV_OPT_TYPE_STRING &&
  o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != 
AV_OPT_TYPE_SAMPLE_FMT &&
  o->type != AV_OPT_TYPE_IMAGE_SIZE &&
  o->type != AV_OPT_TYPE_DURATION && o->type != 
AV_OPT_TYPE_COLOR &&
- o->type != AV_OPT_TYPE_CHANNEL_LAYOUT && o->type != 
AV_OPT_TYPE_BOOL))
+#if FF_API_OLD_CHANNEL_LAYOUT
+ o->type != AV_OPT_TYPE_CHANNEL_LAYOUT &&
+#endif
+ o->type != AV_OPT_TYPE_BOOL))
 return AVERROR(EINVAL);
+FF_ENABLE_DEPRECATION_WARNINGS
 
 if (o->flags & AV_OPT_FLAG_READONLY)
 return AVERROR(EINVAL);
@@ -533,6 +557,8 @@ int av_opt_set(void *obj, const char *name, const char 
*val, int search_flags)
 }
 case AV_OPT_TYPE_COLOR:
 return set_string_color(obj, o, val, dst);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 case AV_OPT_TYPE_CHANNEL_LAYOUT:
 if (!val || !strcmp(val, "none")) {
 *(int64_t *)dst = 0;
@@ -546,6 +572,15 @@ int av_opt_set(void *obj, const char *name, const char 
*val, int search_flags)
 return ret;
 }
 break;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+case AV_OPT_TYPE_CHLAYOUT:
+ret = set_string_channel_layout(obj, o, val, dst);
+if (ret < 0) {
+av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as 
channel layout\n", val);
+ret = AVERROR(EINVAL);
+}
+return ret;
 case AV_OPT_TYPE_DICT:
 return set_string_dict(obj, o, val, dst);
 }
@@ -709,6 +744,8 @@ int av_opt_set_sample_fmt(void *obj, const char *name, enum 
AVSampleFormat fmt,
 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, 
"sample", AV_SAMPLE_FMT_NB);
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int 
search_flags)
 {
 void *target_obj;
@@ -724,6 +761,8 @@ int av_opt_set_channel_layout(void *obj, const char *name, 
int64_t cl, int searc
 *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
 return 0;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
 int search_flags)
@@ -744,6 +783,22 @@ int av_opt_set_dict_val(void *obj, const char *name, const 
AVDictionary *val,
 return 0;
 }
 
+int av_opt_set_chlayout(void *obj, const char *name,
+const AVChannelLayout *channel_layout,
+int search_flags)
+{
+void *target_obj;
+const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags,

[FFmpeg-devel] [PATCH 004/279] lavc: deprecate channel count/layout changing side data

2021-12-07 Thread James Almer
From: Anton Khirnov 

They are incompatible with the new channel layout scheme and no decoder
uses them.

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavcodec/decode.c  | 4 
 libavcodec/packet.h  | 5 +
 libavformat/dump.c   | 9 -
 libavformat/nutenc.c | 2 ++
 libavformat/utils.c  | 9 +
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 52bf5dcd33..01fea93c04 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -91,6 +91,8 @@ static int apply_param_change(AVCodecContext *avctx, const 
AVPacket *avpkt)
 flags = bytestream_get_le32(&data);
 size -= 4;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
 if (size < 4)
 goto fail;
@@ -109,6 +111,8 @@ static int apply_param_change(AVCodecContext *avctx, const 
AVPacket *avpkt)
 avctx->channel_layout = bytestream_get_le64(&data);
 size -= 8;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
 if (size < 4)
 goto fail;
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 4a349fe051..0c3729f32c 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -447,8 +447,13 @@ typedef struct AVPacketList {
 #define AV_PKT_FLAG_DISPOSABLE 0x0010
 
 enum AVSideDataParamChangeFlags {
+#if FF_API_OLD_CHANNEL_LAYOUT
+/**
+ * @deprecated those are not used by any decoder
+ */
 AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT  = 0x0001,
 AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
+#endif
 AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE= 0x0004,
 AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
 };
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 4824965ee9..69b838fbc7 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -164,8 +164,11 @@ static void dump_paramchange(void *ctx, const 
AVPacketSideData *sd)
 {
 int size = sd->size;
 const uint8_t *data = sd->data;
-uint32_t flags, channels, sample_rate, width, height;
+uint32_t flags, sample_rate, width, height;
+#if FF_API_OLD_CHANNEL_LAYOUT
+uint32_t channels;
 uint64_t layout;
+#endif
 
 if (!data || sd->size < 4)
 goto fail;
@@ -174,6 +177,8 @@ static void dump_paramchange(void *ctx, const 
AVPacketSideData *sd)
 data += 4;
 size -= 4;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
 if (size < 4)
 goto fail;
@@ -191,6 +196,8 @@ static void dump_paramchange(void *ctx, const 
AVPacketSideData *sd)
 av_log(ctx, AV_LOG_INFO,
"channel layout: %s, ", av_get_channel_name(layout));
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif /* FF_API_OLD_CHANNEL_LAYOUT */
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
 if (size < 4)
 goto fail;
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 7977980935..2479a3e9dd 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -894,6 +894,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext 
*bc, AVPacket *pkt, int
 break;
 case AV_PKT_DATA_PARAM_CHANGE:
 flags = bytestream_get_le32(&data);
+#if FF_API_OLD_CHANNEL_LAYOUT
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
 put_str(dyn_bc, "Channels");
 put_s(dyn_bc, bytestream_get_le32(&data));
@@ -907,6 +908,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext 
*bc, AVPacket *pkt, int
 avio_write(dyn_bc, data, 8); data+=8;
 sm_data_count++;
 }
+#endif
 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
 put_str(dyn_bc, "SampleRate");
 put_s(dyn_bc, bytestream_get_le32(&data));
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7840e8717c..7643e5ca10 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1319,6 +1319,9 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
 uint8_t *data;
 if (!pkt)
 return AVERROR(EINVAL);
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 if (channels) {
 size  += 4;
 flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT;
@@ -1327,6 +1330,8 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
 size  += 8;
 flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 if (sample_rate) {
 size  += 4;
 flags |= AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE;
@@ -1339,10 +1344,14 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
 if (!data)
 return AVERROR(ENOMEM);
 bytestream_put_le32(&data, flags);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WAR

[FFmpeg-devel] [PATCH 006/279] avcodecpar: switch to the new channel layout API

2021-12-07 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/codec_par.c | 37 +
 libavcodec/codec_par.h | 12 
 libavcodec/utils.c | 12 ++--
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index 1a5168a04b..9d43af1db4 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -31,6 +31,7 @@
 static void codec_parameters_reset(AVCodecParameters *par)
 {
 av_freep(&par->extradata);
+av_channel_layout_uninit(&par->ch_layout);
 
 memset(par, 0, sizeof(*par));
 
@@ -71,6 +72,8 @@ void avcodec_parameters_free(AVCodecParameters **ppar)
 
 int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters 
*src)
 {
+int ret;
+
 codec_parameters_reset(dst);
 memcpy(dst, src, sizeof(*dst));
 
@@ -84,6 +87,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const 
AVCodecParameters *src
 dst->extradata_size = src->extradata_size;
 }
 
+ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
+if (ret < 0)
+return ret;
+
 return 0;
 }
 
@@ -118,8 +125,19 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
 break;
 case AVMEDIA_TYPE_AUDIO:
 par->format   = codec->sample_fmt;
-par->channel_layout   = codec->channel_layout;
-par->channels = codec->channels;
+if (codec->channel_layout)
+av_channel_layout_from_mask(&par->ch_layout, 
codec->channel_layout);
+else {
+par->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+par->ch_layout.nb_channels = codec->channels;
+}
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+par->channel_layout  = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE 
?
+   par->ch_layout.u.mask : 0;
+par->channels= par->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 par->sample_rate  = codec->sample_rate;
 par->block_align  = codec->block_align;
 par->frame_size   = codec->frame_size;
@@ -173,8 +191,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
 break;
 case AVMEDIA_TYPE_AUDIO:
 codec->sample_fmt   = par->format;
-codec->channel_layout   = par->channel_layout;
-codec->channels = par->channels;
+if (par->ch_layout.nb_channels) {
+codec->channel_layout = par->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
+par->ch_layout.u.mask : 0;
+codec->channels   = par->ch_layout.nb_channels;
+}
+#if FF_API_OLD_CHANNEL_LAYOUT
+else {
+FF_DISABLE_DEPRECATION_WARNINGS
+codec->channel_layout = par->channel_layout;
+codec->channels   = par->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+}
+#endif
 codec->sample_rate  = par->sample_rate;
 codec->block_align  = par->block_align;
 codec->frame_size   = par->frame_size;
diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index 10cf79dff1..4cacfbf3b3 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -24,6 +24,7 @@
 #include 
 
 #include "libavutil/avutil.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/rational.h"
 #include "libavutil/pixfmt.h"
 
@@ -149,6 +150,7 @@ typedef struct AVCodecParameters {
 enum AVColorSpace  color_space;
 enum AVChromaLocation  chroma_location;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 /**
  * Video only. Number of delayed frames.
  */
@@ -158,12 +160,17 @@ typedef struct AVCodecParameters {
  * Audio only. The channel layout bitmask. May be 0 if the channel layout 
is
  * unknown or unspecified, otherwise the number of bits set must be equal 
to
  * the channels field.
+ * @deprecated use ch_layout
  */
+attribute_deprecated
 uint64_t channel_layout;
 /**
  * Audio only. The number of audio channels.
+ * @deprecated use ch_layout.nb_channels
  */
+attribute_deprecated
 int  channels;
+#endif
 /**
  * Audio only. The number of audio samples per second.
  */
@@ -198,6 +205,11 @@ typedef struct AVCodecParameters {
  * Audio only. Number of samples to skip after a discontinuity.
  */
 int seek_preroll;
+
+/**
+ * Audio only. The channel layout and number of channels.
+ */
+AVChannelLayout ch_layout;
 } AVCodecParameters;
 
 /**
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a91a54b0dc..dc5156210f 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -826,8 +826,16 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int 
frame_bytes)
 
 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
 {
-int du

[FFmpeg-devel] [PATCH 007/279] lavf: add a temporary compat layer for the channel layout API change

2021-12-07 Thread James Almer
From: Anton Khirnov 

Mediates between old-style (de)muxers and new-style callers. Will be
removed once all the (de)muxers are converted to the new API.

Signed-off-by: James Almer 
---
 libavformat/demux.c | 12 
 libavformat/mux.c   | 10 ++
 2 files changed, 22 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 745dc8687c..cb02c84f33 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -194,6 +194,18 @@ static int update_stream_avctx(AVFormatContext *s)
 sti->parser = NULL;
 }
 
+/* if the demuxer exports old channel layouts, convert it to new */
+if (!st->codecpar->ch_layout.nb_channels &&
+st->codecpar->channels) {
+if (st->codecpar->channel_layout) {
+av_channel_layout_from_mask(&st->codecpar->ch_layout,
+st->codecpar->channel_layout);
+} else {
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = st->codecpar->channels;
+}
+}
+
 /* update internal codec context, for the parser */
 ret = avcodec_parameters_to_context(sti->avctx, st->codecpar);
 if (ret < 0)
diff --git a/libavformat/mux.c b/libavformat/mux.c
index d93dc73f8e..fc9199230c 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -272,6 +272,16 @@ static int init_muxer(AVFormatContext *s, AVDictionary 
**options)
 ret = AVERROR(EINVAL);
 goto fail;
 }
+
+/* if the new-style channel layout is set, convert it to old one
+ * for old-style muxers */
+if (par->ch_layout.nb_channels &&
+!par->channels) {
+par->channels   = par->ch_layout.nb_channels;
+par->channel_layout = par->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
+  par->ch_layout.u.mask : 0;
+}
+
 if (!par->block_align)
 par->block_align = par->channels *
av_get_bits_per_sample(par->codec_id) >> 3;
-- 
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 005/279] avframe: switch to the new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavutil/frame.c | 112 +-
 libavutil/frame.h |  12 -
 2 files changed, 103 insertions(+), 21 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 0912ad9131..d07d6d7984 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -186,18 +186,27 @@ fail:
 
 static int get_audio_buffer(AVFrame *frame, int align)
 {
-int channels;
 int planar   = av_sample_fmt_is_planar(frame->format);
-int planes;
+int channels, planes;
 int ret, i;
 
-if (!frame->channels)
-frame->channels = 
av_get_channel_layout_nb_channels(frame->channel_layout);
-
-channels = frame->channels;
-planes = planar ? channels : 1;
-
-CHECK_CHANNELS_CONSISTENCY(frame);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (!frame->ch_layout.nb_channels) {
+if (frame->channel_layout) {
+av_channel_layout_from_mask(&frame->ch_layout, 
frame->channel_layout);
+} else {
+frame->ch_layout.nb_channels = frame->channels;
+frame->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+}
+}
+frame->channels = frame->ch_layout.nb_channels;
+frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+frame->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+channels = frame->ch_layout.nb_channels;
+planes   = planar ? channels : 1;
 if (!frame->linesize[0]) {
 ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
  frame->nb_samples, frame->format,
@@ -245,10 +254,17 @@ int av_frame_get_buffer(AVFrame *frame, int align)
 if (frame->format < 0)
 return AVERROR(EINVAL);
 
+FF_DISABLE_DEPRECATION_WARNINGS
 if (frame->width > 0 && frame->height > 0)
 return get_video_buffer(frame, align);
-else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+else if (frame->nb_samples > 0 &&
+ (av_channel_layout_check(&frame->ch_layout)
+#if FF_API_OLD_CHANNEL_LAYOUT
+  || frame->channel_layout || frame->channels > 0
+#endif
+ ))
 return get_audio_buffer(frame, align);
+FF_ENABLE_DEPRECATION_WARNINGS
 
 return AVERROR(EINVAL);
 }
@@ -332,14 +348,33 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
 dst->format = src->format;
 dst->width  = src->width;
 dst->height = src->height;
+dst->nb_samples = src->nb_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 dst->channels   = src->channels;
 dst->channel_layout = src->channel_layout;
-dst->nb_samples = src->nb_samples;
+if (!av_channel_layout_check(&src->ch_layout)) {
+if (src->channel_layout)
+av_channel_layout_from_mask(&dst->ch_layout, src->channel_layout);
+else {
+dst->ch_layout.nb_channels = src->channels;
+dst->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+}
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 ret = frame_copy_props(dst, src, 0);
 if (ret < 0)
 goto fail;
 
+// this check is needed only until FF_API_OLD_CHANNEL_LAYOUT is out
+if (av_channel_layout_check(&src->ch_layout)) {
+ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
+if (ret < 0)
+goto fail;
+}
+
 /* duplicate the frame data if it's not refcounted */
 if (!src->buf[0]) {
 ret = av_frame_get_buffer(dst, 0);
@@ -392,13 +427,12 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
 
 /* duplicate extended data */
 if (src->extended_data != src->data) {
-int ch = src->channels;
+int ch = dst->ch_layout.nb_channels;
 
 if (!ch) {
 ret = AVERROR(EINVAL);
 goto fail;
 }
-CHECK_CHANNELS_CONSISTENCY(src);
 
 dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
 if (!dst->extended_data) {
@@ -456,6 +490,8 @@ void av_frame_unref(AVFrame *frame)
 if (frame->extended_data != frame->data)
 av_freep(&frame->extended_data);
 
+av_channel_layout_uninit(&frame->ch_layout);
+
 get_frame_defaults(frame);
 }
 
@@ -502,9 +538,18 @@ int av_frame_make_writable(AVFrame *frame)
 tmp.format = frame->format;
 tmp.width  = frame->width;
 tmp.height = frame->height;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 tmp.channels   = frame->channels;
 tmp.channel_layout = frame->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 tmp.nb_samples = frame->nb_samples;
+ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout);
+if (ret < 0) {
+av_frame_unref(&tmp);
+return ret;
+}
 
 if (frame->hw_fr

[FFmpeg-devel] [PATCH 009/279] 3dostr: convert to new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavformat/3dostr.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c
index 0c136c9ea0..9b6a4d1d86 100644
--- a/libavformat/3dostr.c
+++ b/libavformat/3dostr.c
@@ -102,15 +102,16 @@ static int threedostr_read_header(AVFormatContext *s)
 
 st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
 st->codecpar->sample_rate = avio_rb32(s->pb);
-st->codecpar->channels= avio_rb32(s->pb);
-if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0)
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = avio_rb32(s->pb);
+if (st->codecpar->ch_layout.nb_channels <= 0 || 
st->codecpar->sample_rate <= 0)
 return AVERROR_INVALIDDATA;
 codec  = avio_rl32(s->pb);
 avio_skip(s->pb, 4);
 if (ctrl_size == 20 || ctrl_size == 3 || ctrl_size == -1)
-st->duration   = (avio_rb32(s->pb) - 1) / 
st->codecpar->channels;
+st->duration   = (avio_rb32(s->pb) - 1) / 
st->codecpar->ch_layout.nb_channels;
 else
-st->duration   = avio_rb32(s->pb) * 16 / 
st->codecpar->channels;
+st->duration   = avio_rb32(s->pb) * 16 / 
st->codecpar->ch_layout.nb_channels;
 size -= 56;
 found_shdr = 1;
 break;
@@ -135,7 +136,7 @@ static int threedostr_read_header(AVFormatContext *s)
 switch (codec) {
 case MKTAG('S','D','X','2'):
 st->codecpar->codec_id= AV_CODEC_ID_SDX2_DPCM;
-st->codecpar->block_align = 1 * st->codecpar->channels;
+st->codecpar->block_align = 1 * st->codecpar->ch_layout.nb_channels;
 break;
 default:
 avpriv_request_sample(s, "codec %X", codec);
@@ -178,7 +179,7 @@ static int threedostr_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 ret = av_get_packet(s->pb, pkt, size);
 pkt->pos = pos;
 pkt->stream_index = 0;
-pkt->duration = size / st->codecpar->channels;
+pkt->duration = size / st->codecpar->ch_layout.nb_channels;
 return ret;
 default:
 av_log(s, AV_LOG_DEBUG, "skipping unknown chunk: %X\n", chunk);
-- 
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 010/279] 4xm: convert to new channel layout API

2021-12-07 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: James Almer 
---
 libavformat/4xm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index f918b1fc57..243c22965e 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -186,13 +186,14 @@ static int parse_strk(AVFormatContext *s,
 
 st->codecpar->codec_type= AVMEDIA_TYPE_AUDIO;
 st->codecpar->codec_tag = 0;
-st->codecpar->channels  = fourxm->tracks[track].channels;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = fourxm->tracks[track].channels;
 st->codecpar->sample_rate   = fourxm->tracks[track].sample_rate;
 st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits;
-st->codecpar->bit_rate  = (int64_t)st->codecpar->channels *
+st->codecpar->bit_rate  = 
(int64_t)st->codecpar->ch_layout.nb_channels *
   st->codecpar->sample_rate *
   st->codecpar->bits_per_coded_sample;
-st->codecpar->block_align   = st->codecpar->channels *
+st->codecpar->block_align   = st->codecpar->ch_layout.nb_channels *
   st->codecpar->bits_per_coded_sample;
 
 if (fourxm->tracks[track].adpcm){
-- 
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 008/279] lavf: convert the generic layer to the new channel layout

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavformat/demux.c | 16 
 libavformat/mux.c   | 18 +-
 libavformat/utils.c |  4 ++--
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index cb02c84f33..3bfd753f64 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -206,6 +206,18 @@ static int update_stream_avctx(AVFormatContext *s)
 }
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (st->codecpar->ch_layout.nb_channels &&
+!st->codecpar->channels) {
+st->codecpar->channels = st->codecpar->ch_layout.nb_channels;
+st->codecpar->channel_layout = st->codecpar->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
+   st->codecpar->ch_layout.u.mask : 0;
+
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 /* update internal codec context, for the parser */
 ret = avcodec_parameters_to_context(sti->avctx, st->codecpar);
 if (ret < 0)
@@ -1335,8 +1347,12 @@ static int read_frame_internal(AVFormatContext *s, 
AVPacket *pkt)
 return ret;
 st->codecpar->sample_rate = sti->avctx->sample_rate;
 st->codecpar->bit_rate = sti->avctx->bit_rate;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 st->codecpar->channels = sti->avctx->channels;
 st->codecpar->channel_layout = sti->avctx->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 st->codecpar->codec_id = sti->avctx->codec_id;
 } else {
 /* free packet */
diff --git a/libavformat/mux.c b/libavformat/mux.c
index fc9199230c..9dd6b13ac8 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -282,8 +282,24 @@ static int init_muxer(AVFormatContext *s, AVDictionary 
**options)
   par->ch_layout.u.mask : 0;
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+/* if the caller is using the deprecated channel layout API,
+ * convert it to the new style */
+if (!par->ch_layout.nb_channels &&
+par->channels) {
+if (par->channel_layout) {
+av_channel_layout_from_mask(&par->ch_layout, 
par->channel_layout);
+} else {
+par->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+par->ch_layout.nb_channels = par->channels;
+}
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 if (!par->block_align)
-par->block_align = par->channels *
+par->block_align = par->ch_layout.nb_channels *
av_get_bits_per_sample(par->codec_id) >> 3;
 break;
 case AVMEDIA_TYPE_VIDEO:
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7643e5ca10..269223aaa8 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -526,7 +526,7 @@ int av_find_best_stream(AVFormatContext *ic, enum 
AVMediaType type,
 continue;
 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
 continue;
-if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate))
+if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && 
par->sample_rate))
 continue;
 if (decoder_ret) {
 decoder = ff_find_decoder(ic, st, par->codec_id);
@@ -1512,7 +1512,7 @@ static int match_stream_specifier(AVFormatContext *s, 
AVStream *st,
 int val;
 switch (par->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
-val = par->sample_rate && par->channels;
+val = par->sample_rate && par->ch_layout.nb_channels;
 if (par->format == AV_SAMPLE_FMT_NONE)
 return 0;
 break;
-- 
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 011/279] aa: convert to new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavformat/aadec.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/aadec.c b/libavformat/aadec.c
index 72f4b6f7cc..fbb9e0114e 100644
--- a/libavformat/aadec.c
+++ b/libavformat/aadec.c
@@ -190,7 +190,8 @@ static int aa_read_header(AVFormatContext *s)
 } else if (!strcmp(codec_name, "acelp85")) {
 st->codecpar->codec_id = AV_CODEC_ID_SIPR;
 st->codecpar->block_align = 19;
-st->codecpar->channels = 1;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = 1;
 st->codecpar->sample_rate = 8500;
 st->codecpar->bit_rate = 8500;
 sti->need_parsing = AVSTREAM_PARSE_FULL_RAW;
@@ -198,7 +199,8 @@ static int aa_read_header(AVFormatContext *s)
 } else if (!strcmp(codec_name, "acelp16")) {
 st->codecpar->codec_id = AV_CODEC_ID_SIPR;
 st->codecpar->block_align = 20;
-st->codecpar->channels = 1;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = 1;
 st->codecpar->sample_rate = 16000;
 st->codecpar->bit_rate = 16000;
 sti->need_parsing = AVSTREAM_PARSE_FULL_RAW;
-- 
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 012/279] aax: convert to new channel layout API

2021-12-07 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/aaxdec.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index b08ee036ed..8eb2540407 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -279,9 +279,10 @@ static int aax_read_header(AVFormatContext *s)
 ret = ff_get_extradata(s, par, pb, extradata_size);
 if (ret < 0)
 return ret;
-par->channels= AV_RB8 (par->extradata + 7);
+par->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+par->ch_layout.nb_channels = AV_RB8 (par->extradata + 7);
 par->sample_rate = AV_RB32(par->extradata + 8);
-if (!par->channels || !par->sample_rate)
+if (!par->ch_layout.nb_channels || !par->sample_rate)
 return AVERROR_INVALIDDATA;
 
 avpriv_set_pts_info(st, 64, 32, par->sample_rate);
@@ -299,7 +300,7 @@ static int aax_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 AAXContext *a = s->priv_data;
 AVCodecParameters *par = s->streams[0]->codecpar;
 AVIOContext *pb = s->pb;
-const int size = 18 * par->channels;
+const int size = 18 * par->ch_layout.nb_channels;
 int ret, extradata_size = 0;
 uint8_t *extradata = NULL;
 int skip = 0;
-- 
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 013/279] ace: convert to new channel layout API

2021-12-07 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/acedec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/acedec.c b/libavformat/acedec.c
index a52a0f0e54..74128e0a6a 100644
--- a/libavformat/acedec.c
+++ b/libavformat/acedec.c
@@ -74,7 +74,8 @@ static int ace_read_header(AVFormatContext *s)
 st->start_time = 0;
 par = st->codecpar;
 par->codec_type  = AVMEDIA_TYPE_AUDIO;
-par->channels= nb_channels;
+par->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+par->ch_layout.nb_channels = nb_channels;
 par->sample_rate = rate;
 par->block_align = (codec == 4 ? 0x60 : codec == 5 ? 0x98 : 0xC0) * 
nb_channels;
 st->duration = (size / par->block_align) * 1024LL;
@@ -85,7 +86,7 @@ static int ace_read_header(AVFormatContext *s)
 return ret;
 
 AV_WL16(st->codecpar->extradata, 1);
-AV_WL16(st->codecpar->extradata+2, 2048 * par->channels);
+AV_WL16(st->codecpar->extradata+2, 2048 * nb_channels);
 AV_WL16(st->codecpar->extradata+4, 0);
 AV_WL16(st->codecpar->extradata+6, codec == 4 ? 1 : 0);
 AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0);
-- 
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 014/279] acm: convert to new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavformat/acm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/acm.c b/libavformat/acm.c
index 0ee9114f70..a6da000130 100644
--- a/libavformat/acm.c
+++ b/libavformat/acm.c
@@ -48,12 +48,13 @@ static int acm_read_header(AVFormatContext *s)
 if (ret < 0)
 return ret;
 
-st->codecpar->channels= AV_RL16(st->codecpar->extradata +  8);
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = AV_RL16(st->codecpar->extradata +  
8);
 st->codecpar->sample_rate = AV_RL16(st->codecpar->extradata + 10);
-if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0)
+if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate 
<= 0)
 return AVERROR_INVALIDDATA;
 st->start_time = 0;
-st->duration   = AV_RL32(st->codecpar->extradata +  4) / 
st->codecpar->channels;
+st->duration   = AV_RL32(st->codecpar->extradata +  4) / 
st->codecpar->ch_layout.nb_channels;
 ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW;
 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-- 
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 015/279] act: convert to new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavformat/act.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/act.c b/libavformat/act.c
index a369157647..49639acfcc 100644
--- a/libavformat/act.c
+++ b/libavformat/act.c
@@ -88,7 +88,8 @@ static int read_header(AVFormatContext *s)
 }
 
 st->codecpar->frame_size=80;
-st->codecpar->channels=1;
+st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+st->codecpar->ch_layout.nb_channels = 1;
 avpriv_set_pts_info(st, 64, 1, 100);
 
 st->codecpar->codec_id=AV_CODEC_ID_G729;
-- 
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 016/279] adp: convert to new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: James Almer 
---
 libavformat/adp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/adp.c b/libavformat/adp.c
index 6d5f9d274e..c9a5a04507 100644
--- a/libavformat/adp.c
+++ b/libavformat/adp.c
@@ -55,8 +55,7 @@ static int adp_read_header(AVFormatContext *s)
 
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codecpar->codec_id   = AV_CODEC_ID_ADPCM_DTK;
-st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-st->codecpar->channels   = 2;
+st->codecpar->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 st->codecpar->sample_rate= 48000;
 st->start_time= 0;
 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
-- 
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 178/279] lavf: drop the channel layout compat layer for old-style (de)muxers

2021-12-07 Thread James Almer
From: Anton Khirnov 

All the (de)muxers have been converted to the new API.

Signed-off-by: James Almer 
---
 libavformat/demux.c | 12 
 libavformat/mux.c   |  9 -
 2 files changed, 21 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 3bfd753f64..a9670aeb34 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -194,18 +194,6 @@ static int update_stream_avctx(AVFormatContext *s)
 sti->parser = NULL;
 }
 
-/* if the demuxer exports old channel layouts, convert it to new */
-if (!st->codecpar->ch_layout.nb_channels &&
-st->codecpar->channels) {
-if (st->codecpar->channel_layout) {
-av_channel_layout_from_mask(&st->codecpar->ch_layout,
-st->codecpar->channel_layout);
-} else {
-st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
-st->codecpar->ch_layout.nb_channels = st->codecpar->channels;
-}
-}
-
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
 if (st->codecpar->ch_layout.nb_channels &&
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 9dd6b13ac8..510ede21db 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -273,15 +273,6 @@ static int init_muxer(AVFormatContext *s, AVDictionary 
**options)
 goto fail;
 }
 
-/* if the new-style channel layout is set, convert it to old one
- * for old-style muxers */
-if (par->ch_layout.nb_channels &&
-!par->channels) {
-par->channels   = par->ch_layout.nb_channels;
-par->channel_layout = par->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
-  par->ch_layout.u.mask : 0;
-}
-
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
 /* if the caller is using the deprecated channel layout API,
-- 
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 179/279] lavc: switch to the new channel layout API

2021-12-07 Thread James Almer
From: Vittorio Giovara 

Since the request_channel_layout is used only by a handful of codecs,
move the option to codec private contexts.

Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/avcodec.c   | 80 ++
 libavcodec/avcodec.h   | 23 +-
 libavcodec/codec.h | 11 +
 libavcodec/codec_par.c | 52 +-
 libavcodec/decode.c| 89 --
 libavcodec/encode.c| 36 ---
 libavcodec/options_table.h |  3 ++
 libavcodec/pthread_frame.c | 10 -
 libavcodec/utils.c | 12 -
 libavformat/demux.c|  2 +-
 10 files changed, 263 insertions(+), 55 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c00a9b2af8..4c576a848c 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -119,7 +119,7 @@ static int64_t get_bit_rate(AVCodecContext *ctx)
 case AVMEDIA_TYPE_AUDIO:
 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
 if (bits_per_sample) {
-bit_rate = ctx->sample_rate * (int64_t)ctx->channels;
+bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels;
 if (bit_rate > INT64_MAX / bits_per_sample) {
 bit_rate = 0;
 } else
@@ -137,6 +137,8 @@ static int64_t get_bit_rate(AVCodecContext *ctx)
 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec 
*codec, AVDictionary **options)
 {
 int ret = 0;
+int orig_channels;
+uint64_t orig_channel_layout;
 AVCodecInternal *avci;
 
 if (avcodec_is_open(avctx))
@@ -247,12 +249,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 }
 }
 
-if (avctx->channels > FF_SANE_NB_CHANNELS || avctx->channels < 0) {
-av_log(avctx, AV_LOG_ERROR, "Too many or invalid channels: %d\n", 
avctx->channels);
-ret = AVERROR(EINVAL);
-goto free_and_end;
-}
-
 if (avctx->sample_rate < 0) {
 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
 ret = AVERROR(EINVAL);
@@ -264,6 +260,38 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 goto free_and_end;
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+/* compat wrapper for old-style callers */
+if (avctx->channel_layout && !avctx->channels)
+avctx->channels = av_popcount64(avctx->channel_layout);
+
+if ((avctx->channels && avctx->channels != avctx->ch_layout.nb_channels) ||
+(avctx->channel_layout && avctx->ch_layout.order != 
AV_CHANNEL_ORDER_NATIVE)) {
+if (avctx->channel_layout) {
+av_channel_layout_from_mask(&avctx->ch_layout, 
avctx->channel_layout);
+} else {
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = avctx->channels;
+}
+}
+
+/* temporary compat wrapper for new-style callers and old-style codecs;
+ * to be removed once all the codecs have been converted */
+if (avctx->ch_layout.nb_channels) {
+avctx->channels = avctx->ch_layout.nb_channels;
+avctx->channel_layout = avctx->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
+avctx->ch_layout.u.mask : 0;
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
+av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", 
avctx->ch_layout.nb_channels);
+ret = AVERROR(EINVAL);
+goto free_and_end;
+}
+
 avctx->frame_number = 0;
 avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
 
@@ -317,6 +345,13 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
 avctx->thread_count = 1;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+orig_channels = avctx->channels;
+orig_channel_layout = avctx->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
 avci->frame_thread_encoder) {
 if (avctx->codec->init) {
@@ -334,6 +369,26 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 if (av_codec_is_decoder(avctx->codec)) {
 if (!avctx->bit_rate)
 avctx->bit_rate = get_bit_rate(avctx);
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+/* decoder setting the old-style fields */
+if (avctx->channels != orig_channels ||
+avctx->channel_layout != orig_channel_layout) {
+av_channel_layout_uninit(&avctx->ch_layout);
+if (avctx->channel_layout) {
+av_channel_layout_from_mask(&avctx->ch_layout, 
avctx->channel_layout);
+} else {
+  

[FFmpeg-devel] [PATCH 180/279] 8svx: convert to new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/8svx.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c
index 6ef8cd73fe..6ef7921274 100644
--- a/libavcodec/8svx.c
+++ b/libavcodec/8svx.c
@@ -88,38 +88,39 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, 
void *data,
 {
 EightSvxContext *esc = avctx->priv_data;
 AVFrame *frame   = data;
+int channels = avctx->ch_layout.nb_channels;
 int buf_size;
 int ch, ret;
 int hdr_size = 2;
 
 /* decode and interleave the first packet */
 if (!esc->data[0] && avpkt) {
-int chan_size = avpkt->size / avctx->channels - hdr_size;
+int chan_size = avpkt->size / channels - hdr_size;
 
-if (avpkt->size % avctx->channels) {
+if (avpkt->size % channels) {
 av_log(avctx, AV_LOG_WARNING, "Packet with odd size, ignoring last 
byte\n");
 }
-if (avpkt->size < (hdr_size + 1) * avctx->channels) {
+if (avpkt->size < (hdr_size + 1) * channels) {
 av_log(avctx, AV_LOG_ERROR, "packet size is too small\n");
 return AVERROR_INVALIDDATA;
 }
 
 esc->fib_acc[0] = avpkt->data[1] + 128;
-if (avctx->channels == 2)
+if (channels == 2)
 esc->fib_acc[1] = avpkt->data[2+chan_size+1] + 128;
 
 esc->data_idx  = 0;
 esc->data_size = chan_size;
 if (!(esc->data[0] = av_malloc(chan_size)))
 return AVERROR(ENOMEM);
-if (avctx->channels == 2) {
+if (channels == 2) {
 if (!(esc->data[1] = av_malloc(chan_size))) {
 av_freep(&esc->data[0]);
 return AVERROR(ENOMEM);
 }
 }
 memcpy(esc->data[0], &avpkt->data[hdr_size], chan_size);
-if (avctx->channels == 2)
+if (channels == 2)
 memcpy(esc->data[1], &avpkt->data[2*hdr_size+chan_size], 
chan_size);
 }
 if (!esc->data[0]) {
@@ -139,7 +140,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, 
void *data,
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 
-for (ch = 0; ch < avctx->channels; ch++) {
+for (ch = 0; ch < channels; ch++) {
 delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx],
  buf_size, &esc->fib_acc[ch], esc->table);
 }
@@ -148,14 +149,14 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, 
void *data,
 
 *got_frame_ptr = 1;
 
-return ((avctx->frame_number == 0)*hdr_size + buf_size)*avctx->channels;
+return ((avctx->frame_number == 0) * hdr_size + buf_size) * channels;
 }
 
 static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
 {
 EightSvxContext *esc = avctx->priv_data;
 
-if (avctx->channels < 1 || avctx->channels > 2) {
+if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
 av_log(avctx, AV_LOG_ERROR, "8SVX does not support more than 2 
channels\n");
 return AVERROR_INVALIDDATA;
 }
-- 
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 181/279] aac: convert to new channel layout API

2021-12-07 Thread James Almer
From: Anton Khirnov 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/aac.h  | 11 --
 libavcodec/aac_ac3_parser.c   |  9 +++--
 libavcodec/aaccoder.c | 10 +++---
 libavcodec/aaccoder_twoloop.h |  4 +--
 libavcodec/aacdec_template.c  | 59 
 libavcodec/aacenc.c   | 13 ---
 libavcodec/aacenc.h   | 64 ++-
 libavcodec/aacenctab.h| 16 -
 libavcodec/aacpsy.c   |  8 ++---
 libavcodec/psymodel.c |  8 ++---
 libavcodec/psymodel.h |  2 +-
 11 files changed, 125 insertions(+), 79 deletions(-)

diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index 1e82f56ca9..53be546857 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -32,6 +32,7 @@
 
 
 #include "aac_defines.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/fixed_dsp.h"
 #include "libavutil/mem_internal.h"
@@ -125,8 +126,7 @@ typedef struct OutputConfiguration {
 MPEG4AudioConfig m4ac;
 uint8_t layout_map[MAX_ELEM_ID*4][3];
 int layout_map_tags;
-int channels;
-uint64_t channel_layout;
+AVChannelLayout ch_layout;
 enum OCStatus status;
 } OutputConfiguration;
 
@@ -288,6 +288,11 @@ typedef struct ChannelElement {
 SpectralBandReplication sbr;
 } ChannelElement;
 
+enum AACOutputChannelOrder {
+CHANNEL_ORDER_DEFAULT,
+CHANNEL_ORDER_CODED,
+};
+
 /**
  * main AAC context
  */
@@ -352,6 +357,8 @@ struct AACContext {
 int dmono_mode;  ///< 0->not dmono, 1->use first channel, 2->use 
second channel
 /** @} */
 
+enum AACOutputChannelOrder output_channel_order;
+
 DECLARE_ALIGNED(32, INTFLOAT, temp)[128];
 
 OutputConfiguration oc[2];
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index e84d30aea2..cd54a0a3e2 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -90,8 +90,13 @@ get_next:
 if (avctx->codec_id != AV_CODEC_ID_AAC) {
 avctx->sample_rate = s->sample_rate;
 if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
-avctx->channels = s->channels;
-avctx->channel_layout = s->channel_layout;
+av_channel_layout_uninit(&avctx->ch_layout);
+if (s->channel_layout) {
+av_channel_layout_from_mask(&avctx->ch_layout, 
s->channel_layout);
+} else {
+avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+avctx->ch_layout.nb_channels = s->channels;
+}
 }
 s1->duration = s->samples;
 avctx->audio_service_type = s->service_type;
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 7bbd4d5b2e..f460479498 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -397,7 +397,7 @@ static void search_for_quantizers_fast(AVCodecContext 
*avctx, AACEncContext *s,
const float lambda)
 {
 int start = 0, i, w, w2, g;
-int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / 
avctx->channels * (lambda / 120.f);
+int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / 
avctx->ch_layout.nb_channels * (lambda / 120.f);
 float dists[128] = { 0 }, uplims[128] = { 0 };
 float maxvals[128];
 int fflag, minscaler;
@@ -556,7 +556,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext 
*avctx, SingleChanne
 const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f);
 
 int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate
-/ ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels)
+/ ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : 
avctx->ch_layout.nb_channels)
 * (lambda / 120.f);
 
 /** Keep this in sync with twoloop's cutoff selection */
@@ -564,7 +564,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext 
*avctx, SingleChanne
 int prev = -1000, prev_sf = -1;
 int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE)
 ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024)
-: (avctx->bit_rate / avctx->channels);
+: (avctx->bit_rate / avctx->ch_layout.nb_channels);
 
 frame_bit_rate *= 1.15f;
 
@@ -693,14 +693,14 @@ static void mark_pns(AACEncContext *s, AVCodecContext 
*avctx, SingleChannelEleme
 const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f);
 
 int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate
-/ ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels)
+/ ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : 
avctx->ch_layout.nb_channels)
 * (lambda / 120.f);
 
 /** Keep this in sync with twoloop's cutoff selection */
 float rate_bandwidth_multiplier = 1.5f;
 int frame_bit_rate = (avctx->flags & AV_CODEC_F

[FFmpeg-devel] [PATCH 182/279] ac3: convert to new channel layout API

2021-12-07 Thread James Almer
From: Vittorio Giovara 

Signed-off-by: Vittorio Giovara 
Signed-off-by: Anton Khirnov 
Signed-off-by: James Almer 
---
 libavcodec/aac_ac3_parser.c |  6 +++
 libavcodec/ac3dec.c | 57 +--
 libavcodec/ac3dec.h |  2 +
 libavcodec/ac3dec_fixed.c   |  1 +
 libavcodec/ac3dec_float.c   |  2 +
 libavcodec/ac3enc.c | 78 +
 libavcodec/ac3enc.h |  4 +-
 libavcodec/ac3enc_fixed.c   |  5 +++
 libavcodec/ac3enc_float.c   |  5 +++
 libavcodec/eac3enc.c|  5 +++
 tests/fate/ac3.mak  | 16 
 11 files changed, 135 insertions(+), 46 deletions(-)

diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index cd54a0a3e2..4ce7a73972 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -97,6 +97,12 @@ get_next:
 avctx->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
 avctx->ch_layout.nb_channels = s->channels;
 }
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->channels = avctx->ch_layout.nb_channels;
+avctx->channel_layout = s->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 }
 s1->duration = s->samples;
 avctx->audio_service_type = s->service_type;
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index c7deb56e1c..309f11cec2 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -32,6 +32,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/crc.h"
 #include "libavutil/downmix_info.h"
+#include "libavutil/intmath.h"
 #include "libavutil/opt.h"
 #include "libavutil/thread.h"
 #include "bswapdsp.h"
@@ -186,6 +187,8 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
 {
 static AVOnce init_static_once = AV_ONCE_INIT;
 AC3DecodeContext *s = avctx->priv_data;
+const AVChannelLayout mono   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 int i, ret;
 
 s->avctx = avctx;
@@ -214,12 +217,23 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
 /* allow downmixing to stereo or mono */
-if (avctx->channels > 1 &&
-avctx->request_channel_layout == AV_CH_LAYOUT_MONO)
-avctx->channels = 1;
-else if (avctx->channels > 2 &&
- avctx->request_channel_layout == AV_CH_LAYOUT_STEREO)
-avctx->channels = 2;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (avctx->request_channel_layout) {
+av_channel_layout_uninit(&s->downmix_layout);
+av_channel_layout_from_mask(&s->downmix_layout, 
avctx->request_channel_layout);
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+if (avctx->ch_layout.nb_channels > 1 &&
+!av_channel_layout_compare(&s->downmix_layout, &mono)) {
+av_channel_layout_uninit(&avctx->ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+} else if (avctx->ch_layout.nb_channels > 2 &&
+ !av_channel_layout_compare(&s->downmix_layout, &stereo)) {
+av_channel_layout_uninit(&avctx->ch_layout);
+avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+}
 s->downmixed = 1;
 
 for (i = 0; i < AC3_MAX_CHANNELS; i++) {
@@ -1480,6 +1494,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void 
*data,
 const SHORTFLOAT *output[AC3_MAX_CHANNELS];
 enum AVMatrixEncoding matrix_encoding;
 AVDownmixInfo *downmix_info;
+uint64_t mask;
 
 s->superframe_size = 0;
 
@@ -1590,11 +1605,11 @@ dependent_frame:
 if (s->lfe_on)
 s->output_mode |= AC3_OUTPUT_LFEON;
 if (s->channels > 1 &&
-avctx->request_channel_layout == AV_CH_LAYOUT_MONO) {
+!av_channel_layout_compare(&s->downmix_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) {
 s->out_channels = 1;
 s->output_mode  = AC3_CHMODE_MONO;
 } else if (s->channels > 2 &&
-   avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
+   !av_channel_layout_compare(&s->downmix_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) {
 s->out_channels = 2;
 s->output_mode  = AC3_CHMODE_STEREO;
 }
@@ -1615,10 +1630,13 @@ dependent_frame:
 av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n");
 return AVERROR_INVALIDDATA;
 }
-avctx->channels = s->out_channels;
-avctx->channel_layout = avpriv_ac3_channel_layout_tab[s->output_mode & 
~AC3_OUTPUT_LFEON];
+
+mask = avpriv_ac3_channel_layout_tab[s->output_mode & ~AC3_OUTPUT_LFEON];
 if (s->output_mode & AC3_OUTPUT_LFEON)
-avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
+mask |= AV_CH_LOW_FREQUENCY;
+
+av_channel_layout_uninit(&avctx->ch_layout);
+av_channel_layout_from_mask

  1   2   >