Re: [FFmpeg-devel] [RFC] [PATCH] avfilter/avfilter: add flag to signal filters that support w/h change

2023-06-16 Thread Paul B Mahol
On Wed, Jun 14, 2023 at 7:33 PM Nicolas George  wrote:

> Paul B Mahol (12023-06-14):
> > To flag filters that can work with variable frame size changes
> > all the time in graph. So no rescalers are need to be inserted or
> > filtergraph reset.
> >
> > Once all such filters are flaged with such capability then code will be
> > added so auto inserted rescale filter is inserted where neccesarry to
> > filters in
> > filtergraph that do not support dynamic width/height changes.
>
> If you have a proof-of-concept patch series where this flag is actually
> useful, I will review it.
>
> As it is, it is dead code and not for commit.
>

More code will come later, no reasons to block this patch for no valid
reasons.


>
> --
>   Nicolas George
> ___
> 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] avcodec: Ignoring errors is only possible before the input end

2023-06-16 Thread Paul B Mahol
On Sat, Jun 3, 2023 at 9:44 PM Michael Niedermayer 
wrote:

> Fixes: out of array read
> Fixes: Ticket 10308
>

Did you forgot to apply this?


>
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/h263dec.c   | 2 +-
>  libavcodec/mpeg4videodec.c | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
> index f4e7048a5f..68a618a7ed 100644
> --- a/libavcodec/h263dec.c
> +++ b/libavcodec/h263dec.c
> @@ -281,7 +281,7 @@ static int decode_slice(MpegEncContext *s)
>  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
>  s->mb_x, s->mb_y, ER_MB_ERROR &
> part_mask);
>
> -if (s->avctx->err_recognition & AV_EF_IGNORE_ERR)
> +if ((s->avctx->err_recognition & AV_EF_IGNORE_ERR) &&
> get_bits_left(&s->gb) > 0)
>  continue;
>  return AVERROR_INVALIDDATA;
>  }
> diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> index d456e5dd11..30aec5e529 100644
> --- a/libavcodec/mpeg4videodec.c
> +++ b/libavcodec/mpeg4videodec.c
> @@ -1437,7 +1437,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext
> *ctx, int16_t *block,
>  if (SHOW_UBITS(re, &s->gb, 1) == 0) {
>  av_log(s->avctx, AV_LOG_ERROR,
> "1. marker bit missing in 3.
> esc\n");
> -if (!(s->avctx->err_recognition &
> AV_EF_IGNORE_ERR))
> +if (!(s->avctx->err_recognition &
> AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0)
>  return AVERROR_INVALIDDATA;
>  }
>  SKIP_CACHE(re, &s->gb, 1);
> @@ -1448,7 +1448,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext
> *ctx, int16_t *block,
>  if (SHOW_UBITS(re, &s->gb, 1) == 0) {
>  av_log(s->avctx, AV_LOG_ERROR,
> "2. marker bit missing in 3.
> esc\n");
> -if (!(s->avctx->err_recognition &
> AV_EF_IGNORE_ERR))
> +if (!(s->avctx->err_recognition &
> AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0)
>  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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] lavc/binkaudio: reset input packet on errors

2023-06-16 Thread Paul B Mahol
On Sat, Jun 17, 2023 at 4:54 AM Anton Khirnov  wrote:

> Make sure we don't repeatedly try to decode the same packet, making no
> progress and possibly causing an infinite loop.
>

Doesn't all error paths, bellow goto label in function, needs this (reset
of ch_offset to 0 and unref of pkt) ?


> ---
>  libavcodec/binkaudio.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
> index f28ecba760..265f93a822 100644
> --- a/libavcodec/binkaudio.c
> +++ b/libavcodec/binkaudio.c
> @@ -325,7 +325,7 @@ again:
>  if (s->ch_offset == 0) {
>  frame->nb_samples = s->frame_len;
>  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
> -return ret;
> +goto fail;
>  if (!new_pkt)
>  frame->pts = AV_NOPTS_VALUE;
>  }
> @@ -334,8 +334,8 @@ again:
>   avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT,
>   FFMIN(MAX_CHANNELS, s->channels - s->ch_offset),
> s->ch_offset)) {
>  av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
> -s->ch_offset = 0;
> -return AVERROR_INVALIDDATA;
> +ret = AVERROR_INVALIDDATA;
> +goto fail;
>  }
>  s->ch_offset += MAX_CHANNELS;
>  get_bits_align32(gb);
> --
> 2.40.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 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] avcodec: Align AVFrame memory to page size for access via Apple Metal

2023-06-16 Thread Paul B Mahol
On Thu, Jun 15, 2023 at 12:34 PM Iskandar Safarov 
wrote:

> Thanks for looking into this,
>
> The idea is to page-align the entire software-backed video pool allocation
> where video frames are being taken from – both for decoding and/or encoding
> (when done in software only).
>
> The default get_buffer2 (avcodec_default_get_buffer2) implementation
> contains code for both hardware-backed and software-backed frame
> allocations. Going down this path makes custom implementation a copy-paste
> of a large portion of the LGPL code into my app.
>
> Another thing to consider – it might not be a good idea to page-align every
> single AVFrame allocation because the alignment is not tiny – 16KB (for M1
> machine). I found that this patch is minimum required change to allow
> in-memory GPU post-processing of the AVFrame between software encode/decode
> cycles.
>
> Please advise
>

Top posting is forbidden on this mailing list.
As already advised use custom get_buffer2 calls, and not default ones.


>
> On Thu, 15 Jun 2023 at 19:40, Hendrik Leppkes  wrote:
>
> > On Thu, Jun 15, 2023 at 4:16 AM Iskandar Safarov 
> > wrote:
> > >
> > > ---
> > >  libavcodec/get_buffer.c | 52 -
> > >  1 file changed, 51 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c
> > > index a04fd878de..b18af3be4a 100644
> > > --- a/libavcodec/get_buffer.c
> > > +++ b/libavcodec/get_buffer.c
> > > @@ -33,6 +33,11 @@
> > >  #include "avcodec.h"
> > >  #include "internal.h"
> > >
> > > +#if __APPLE__
> > > +#import 
> > > +#import 
> > > +#endif
> > > +
> > >  typedef struct FramePool {
> > >  /**
> > >   * Pools for each data plane. For audio all the planes have the
> > same size,
> > > @@ -81,6 +86,51 @@ static AVBufferRef *frame_pool_alloc(void)
> > >  return buf;
> > >  }
> > >
> > > +#if __APPLE__
> > > +/*
> > > +When compiling for Apple platform the frame buffer data pointers
> > need to be
> > > +page-aligned for cases when in-place GPU processing may be
> required
> > > +
> >
> https://developer.apple.com/documentation/metal/mtldevice/1433382-newbufferwithbytesnocopy
> > > + */
> > > +#define POOL_BUFFER_ALLOCZ aapl_buffer_allocz
> > > +
> > > +static void aapl_buffer_free(void *opaque, uint8_t *data)
> > > +{
> > > +vm_deallocate((vm_map_t) mach_task_self(), (vm_address_t)data,
> > (size_t)opaque);
> > > +}
> > > +
> > > +static AVBufferRef *aapl_buffer_alloc(size_t size)
> > > +{
> > > +AVBufferRef *ret = NULL;
> > > +uint8_t*data = NULL;
> > > +
> > > +kern_return_t   err;
> > > +err = vm_allocate(  (vm_map_t) mach_task_self(),
> > > +(vm_address_t*) &data, size, VM_FLAGS_ANYWHERE);
> > > +if (err != KERN_SUCCESS || !data)
> > > +return NULL;
> > > +
> > > +ret = av_buffer_create(data, size, aapl_buffer_free, (void*)size,
> > 0);
> > > +if (!ret)
> > > +free(data);
> > > +
> > > +return ret;
> > > +}
> > > +
> > > +static AVBufferRef *aapl_buffer_allocz(size_t size)
> > > +{
> > > +AVBufferRef *ret = aapl_buffer_alloc(size);
> > > +if (!ret)
> > > +return NULL;
> > > +
> > > +memset(ret->data, 0, size);
> > > +return ret;
> > > +}
> > > +
> > > +#else
> > > +#define POOL_BUFFER_ALLOCZ av_buffer_allocz
> > > +#endif
> > > +
> > >  static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
> > >  {
> > >  FramePool *pool = avctx->internal->pool ?
> > > @@ -155,7 +205,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> > >  pool->pools[i] = av_buffer_pool_init(size[i] + 16 +
> > STRIDE_ALIGN - 1,
> > >
> >  CONFIG_MEMORY_POISONING ?
> > >  NULL :
> > > -
> > av_buffer_allocz);
> > > +
> > POOL_BUFFER_ALLOCZ);
> > >  if (!pool->pools[i]) {
> > >  ret = AVERROR(ENOMEM);
> > >  goto fail;
> > > --
> > > 2.39.2 (Apple Git-143)
> > >
> >
> > This is most definitely the wrong place to do this. Frames can be
> > allocated through various means and in various locations, and randomly
> > sprinkling new allocators all over is not how this should be
> > approached.
> >
> > I don't believe FFmpeg itself shares this requirement, so maybe your
> > application should just use a custom get_buffer2 callback to fullfill
> > it?
> > If others agree that FFmpeg should create frames with this property by
> > default (which I can't answer without knowing if those special
> > allocation functions have any other downsides etc), it should be done
> > more centrally, rather then only in the avcodec pool.
> >
> > - 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".
> >
>
>
> --
> Regards,
> Iskandar Safarov
> __

Re: [FFmpeg-devel] [PATCH 5/5] avformat: add sdr support

2023-06-16 Thread Paul B Mahol
Please no more pseudo demuxers.

Use libavfilter API.
___
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 16/21] fftools/ffmpeg_dec: move decoding to a separate thread

2023-06-16 Thread Anton Khirnov
Quoting Michael Niedermayer (2023-06-16 22:58:21)
> On Wed, Jun 14, 2023 at 06:49:03PM +0200, Anton Khirnov wrote:
> > This is only a preparatory step to a fully threaded architecture and
> > does not yet make decoding truly parallel - the main thread will
> > currently submit a packet and wait until it has been fully processed by
> > the decoding thread before moving on. Decoded behavior as observed by
> > the rest of the program should remain unchanged. That will change in
> > future commits after encoders and filters are moved to threads and a
> > thread-aware scheduler is added.
> > ---
> >  fftools/ffmpeg.c |  63 +---
> >  fftools/ffmpeg.h |  11 ++
> >  fftools/ffmpeg_dec.c | 365 ++-
> >  fftools/ffmpeg_mux.c |   5 -
> >  4 files changed, 382 insertions(+), 62 deletions(-)
> 
> This seems to break (infinite loop)
> 
> ffmpeg -i videos/bink/thps4/ACDC.smo -bitexact -t 1 -y ACDC.smo.avi
> 
> file seems there: on samples server: game-formats/bink/thps4/ACDC.smo

This is a bug in the binkaudio decoder, fixed by the patch I just sent.

-- 
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] lavc/binkaudio: reset input packet on errors

2023-06-16 Thread Anton Khirnov
Make sure we don't repeatedly try to decode the same packet, making no
progress and possibly causing an infinite loop.
---
 libavcodec/binkaudio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index f28ecba760..265f93a822 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -325,7 +325,7 @@ again:
 if (s->ch_offset == 0) {
 frame->nb_samples = s->frame_len;
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
-return ret;
+goto fail;
 if (!new_pkt)
 frame->pts = AV_NOPTS_VALUE;
 }
@@ -334,8 +334,8 @@ again:
  avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT,
  FFMIN(MAX_CHANNELS, s->channels - s->ch_offset), 
s->ch_offset)) {
 av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
-s->ch_offset = 0;
-return AVERROR_INVALIDDATA;
+ret = AVERROR_INVALIDDATA;
+goto fail;
 }
 s->ch_offset += MAX_CHANNELS;
 get_bits_align32(gb);
-- 
2.40.1

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

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


Re: [FFmpeg-devel] [PATCH] avformat/matroska: Add support for A_ATRAC/AT1

2023-06-16 Thread Andreas Rheinhardt
asivery:
> Hello, apologies for bothering you all with this, but if anyone could take a 
> look at this patch it would be great. The only other container that supports 
> ATRAC1 is AEA, and it's not that good of a format since it has no magic 
> number, and therefore is easily detected incorrectly.
> 
> Thank you in advance.

Sorry for having missed this. I will look at it tomorrow.

- Andreas

> 
> --- Original Message ---
> On Monday, April 17th, 2023 at 2:27 AM, asivery  
> wrote:
> 
> 
>> I'd appreciate it if someone took a look at this.
>> If there's anything I need to change to make this patch viable for merging, 
>> please let me know.
>>
>> Best regards,
>> asivery
>> --- Original Message ---
>> On Monday, March 6th, 2023 at 7:51 PM, asivery asiv...@protonmail.com wrote:
>>
>>
>>
>>> It's been added recently. Here's the definition: 
>>> https://github.com/ietf-wg-cellar/matroska-specification/blob/master/codec_specs.md#a_atracat1
>>>
>>> --- Original Message ---
>>> On Monday, March 6th, 2023 at 7:39 PM, Paul B Mahol one...@gmail.com wrote:
>>>
 On 3/6/23, asivery asiv...@protonmail.com wrote:

> Signed-off-by: asivery asiv...@protonmail.com
> ---
> libavformat/matroska.c | 1 +
> libavformat/matroskadec.c | 2 ++
> 2 files changed, 3 insertions(+)

 where is this defined?

> diff --git a/libavformat/matroska.c b/libavformat/matroska.c
> index 90d94b65bf..37305a523c 100644
> --- a/libavformat/matroska.c
> +++ b/libavformat/matroska.c
> @@ -55,6 +55,7 @@ const CodecTags ff_mkv_codec_tags[]={
> {"A_REAL/ATRC" , AV_CODEC_ID_ATRAC3},
> {"A_REAL/COOK" , AV_CODEC_ID_COOK},
> {"A_REAL/SIPR" , AV_CODEC_ID_SIPR},
> + {"A_ATRAC/AT1" , AV_CODEC_ID_ATRAC1},
> {"A_TRUEHD" , AV_CODEC_ID_TRUEHD},
> {"A_TTA1" , AV_CODEC_ID_TTA},
> {"A_VORBIS" , AV_CODEC_ID_VORBIS},
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index d582f566a2..0aa8e6f3b3 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2795,6 +2795,8 @@ static int matroska_parse_tracks(AVFormatContext s)
> track->audio.frame_size);
> if (!track->audio.buf)
> return AVERROR(ENOMEM);
> + } else if (codec_id == AV_CODEC_ID_ATRAC1) {
> + st->codecpar->block_align = track->audio.channels * 212; / Constant 
> ATRAC
> frame size */
> } else if (codec_id == AV_CODEC_ID_FLAC && track->codec_priv.size) {
> ret = matroska_parse_flac(s, track, &extradata_offset);
> if (ret < 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".


Re: [FFmpeg-devel] [PATCH] avformat/matroska: Add support for A_ATRAC/AT1

2023-06-16 Thread asivery
Hello, apologies for bothering you all with this, but if anyone could take a 
look at this patch it would be great. The only other container that supports 
ATRAC1 is AEA, and it's not that good of a format since it has no magic number, 
and therefore is easily detected incorrectly.

Thank you in advance.

--- Original Message ---
On Monday, April 17th, 2023 at 2:27 AM, asivery  wrote:


> I'd appreciate it if someone took a look at this.
> If there's anything I need to change to make this patch viable for merging, 
> please let me know.
> 
> Best regards,
> asivery
> --- Original Message ---
> On Monday, March 6th, 2023 at 7:51 PM, asivery asiv...@protonmail.com wrote:
> 
> 
> 
> > It's been added recently. Here's the definition: 
> > https://github.com/ietf-wg-cellar/matroska-specification/blob/master/codec_specs.md#a_atracat1
> > 
> > --- Original Message ---
> > On Monday, March 6th, 2023 at 7:39 PM, Paul B Mahol one...@gmail.com wrote:
> > 
> > > On 3/6/23, asivery asiv...@protonmail.com wrote:
> > > 
> > > > Signed-off-by: asivery asiv...@protonmail.com
> > > > ---
> > > > libavformat/matroska.c | 1 +
> > > > libavformat/matroskadec.c | 2 ++
> > > > 2 files changed, 3 insertions(+)
> > > 
> > > where is this defined?
> > > 
> > > > diff --git a/libavformat/matroska.c b/libavformat/matroska.c
> > > > index 90d94b65bf..37305a523c 100644
> > > > --- a/libavformat/matroska.c
> > > > +++ b/libavformat/matroska.c
> > > > @@ -55,6 +55,7 @@ const CodecTags ff_mkv_codec_tags[]={
> > > > {"A_REAL/ATRC" , AV_CODEC_ID_ATRAC3},
> > > > {"A_REAL/COOK" , AV_CODEC_ID_COOK},
> > > > {"A_REAL/SIPR" , AV_CODEC_ID_SIPR},
> > > > + {"A_ATRAC/AT1" , AV_CODEC_ID_ATRAC1},
> > > > {"A_TRUEHD" , AV_CODEC_ID_TRUEHD},
> > > > {"A_TTA1" , AV_CODEC_ID_TTA},
> > > > {"A_VORBIS" , AV_CODEC_ID_VORBIS},
> > > > diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> > > > index d582f566a2..0aa8e6f3b3 100644
> > > > --- a/libavformat/matroskadec.c
> > > > +++ b/libavformat/matroskadec.c
> > > > @@ -2795,6 +2795,8 @@ static int matroska_parse_tracks(AVFormatContext 
> > > > s)
> > > > track->audio.frame_size);
> > > > if (!track->audio.buf)
> > > > return AVERROR(ENOMEM);
> > > > + } else if (codec_id == AV_CODEC_ID_ATRAC1) {
> > > > + st->codecpar->block_align = track->audio.channels * 212; / Constant 
> > > > ATRAC
> > > > frame size */
> > > > } else if (codec_id == AV_CODEC_ID_FLAC && track->codec_priv.size) {
> > > > ret = matroska_parse_flac(s, track, &extradata_offset);
> > > > if (ret < 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 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] configure: use just the pkg-config for sndio

2023-06-16 Thread Brad Smith


---
 configure | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/configure b/configure
index 0c77d8e1fe..653aafb1ea 100755
--- a/configure
+++ b/configure
@@ -7009,8 +7009,7 @@ enabled alsa && { check_pkg_config alsa alsa 
"alsa/asoundlib.h" snd_pcm_htimesta
 enabled libjack &&
 require_pkg_config libjack jack jack/jack.h jack_port_get_latency_range
 
-enabled sndio && { check_pkg_config sndio sndio "sndio.h" sio_open ||
-   check_lib sndio sndio.h sio_open -lsndio; }
+enabled sndio && require_pkg_config sndio sndio sndio.h sio_open
 
 if enabled libcdio; then
 check_pkg_config libcdio libcdio_paranoia "cdio/cdda.h cdio/paranoia.h" 
cdio_cddap_open ||
-- 
2.41.0

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

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


[FFmpeg-devel] [PATCH 5/5] avformat: add sdr support

2023-06-16 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 configure|5 +
 doc/demuxers.texi|   71 ++
 libavformat/Makefile |2 +
 libavformat/allformats.c |2 +
 libavformat/sdrdemux.c   | 1710 ++
 5 files changed, 1790 insertions(+)
 create mode 100644 libavformat/sdrdemux.c

diff --git a/configure b/configure
index 4ac7cc6c0b..48b4693de5 100755
--- a/configure
+++ b/configure
@@ -269,6 +269,7 @@ External library support:
   --enable-libshineenable fixed-point MP3 encoding via libshine [no]
   --enable-libsmbclientenable Samba protocol via libsmbclient [no]
   --enable-libsnappy   enable Snappy compression, needed for hap encoding 
[no]
+  --enable-libsoapysdr enable SoapySDR, needed for connecting to SDR HW 
[no]
   --enable-libsoxr enable Include libsoxr resampling [no]
   --enable-libspeexenable Speex de/encoding via libspeex [no]
   --enable-libsrt  enable Haivision SRT protocol via libsrt [no]
@@ -1888,6 +1889,7 @@ EXTERNAL_LIBRARY_LIST="
 libshine
 libsmbclient
 libsnappy
+libsoapysdr
 libsoxr
 libspeex
 libsrt
@@ -3540,6 +3542,8 @@ rtsp_muxer_select="rtp_muxer http_protocol rtp_protocol 
rtpenc_chain"
 sap_demuxer_select="sdp_demuxer"
 sap_muxer_select="rtp_muxer rtp_protocol rtpenc_chain"
 sdp_demuxer_select="rtpdec"
+sdr_demuxer_deps="libsoapysdr"
+sdrfile_demuxer_deps="libsoapysdr"
 smoothstreaming_muxer_select="ismv_muxer"
 spdif_demuxer_select="adts_header"
 spdif_muxer_select="adts_header"
@@ -6776,6 +6780,7 @@ enabled libshine  && require_pkg_config libshine 
shine shine/layer3.h sh
 enabled libsmbclient  && { check_pkg_config libsmbclient smbclient 
libsmbclient.h smbc_init ||
require libsmbclient libsmbclient.h smbc_init 
-lsmbclient; }
 enabled libsnappy && require libsnappy snappy-c.h snappy_compress 
-lsnappy -lstdc++
+enabled libsoapysdr   && require libsoapysdr SoapySDR/Device.h 
SoapySDRDevice_enumerate -lSoapySDR
 enabled libsoxr   && require libsoxr soxr.h soxr_create -lsoxr
 enabled libssh&& require_pkg_config libssh libssh libssh/sftp.h 
sftp_init
 enabled libspeex  && require_pkg_config libspeex speex speex/speex.h 
speex_decoder_init
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 2d33b47a56..fa8da99911 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -899,6 +899,77 @@ the script is directly played, the actual times will match 
the absolute
 timestamps up to the sound controller's clock accuracy, but if the user
 somehow pauses the playback or seeks, all times will be shifted accordingly.
 
+@section sdr / sdrfile
+
+Software Defined Radio Demuxer. The sdr demuxer will demux radio streams
+through the use of a libsoapy compatible software defined radio. sdrfile
+will do the same from a file.
+The short seek forward and backward commands can be used to select the next and
+previous radio stations. Seeking to specific radio stations and similar will be
+supported in the future.
+
+@table @option
+
+@item block_size
+size of FFT to use, leave at 0 to choose automatically
+
+@item mode
+
+@table @samp
+
+@item single_mode
+Demodulate 1 station
+
+@item all_mode
+Demodulate all stations in view
+
+@end table
+
+@item station_freq
+Initial station to pick, if multiple are probed.
+
+@item driver
+libsoapy driver to use. Leave empty to attempt autodetection.
+
+@item sdr_sr
+SDR sample rate, this must be a value supported by the hardware. Leave 0 to 
attempt
+autodetection
+
+@item sdr_freq
+initial SDR center frequency, this must be a value supported by the hardware
+
+@item min_freq
+Minimum frequency, leave at 0 for autodetection
+
+@item max_freq
+Maximum frequency, leave at 0 for autodetection
+
+@item dumpurl
+URL to dump RAW SDR stream to, this can be played back later with sdrfile. 
Useful
+for debuging.
+
+@item kbd_alpha
+Kaiser Bessel derived window parameter
+
+@item am_mode
+AM Demodulation method. Several different methods are supported.
+@table @samp
+@item am_inphase
+Demodulate mono signal that is in phase with the carrier. This works well if 
there is one
+transmitter at the frequency and there is nothing disturbing the signal.
+
+@item am_midside
+Demodulate AM into a stereo signal so that the mid is from the in phase and 
side is from the
+quadrature signal. This can be used if there are Multiple transmitters that 
transmit at the same
+frequency. Or just for fun.
+
+@item am_envelope
+Demodulate mono signal that is basically the energy of the spectrum.
+
+@end table
+
+@end table
+
 @section tedcaptions
 
 JSON captions used for @url{http://www.ted.com/, TED Talks}.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 05434a0f82..1efb51c613 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -528,6 +528,8 @@ OBJS-$(CONFIG_SCC_MUXER) += sccenc.o
 OBJS-$(CONFIG_SCD_DEMUXER)   += scd.o
 OBJS-

[FFmpeg-devel] [PATCH 0/5] add sdr support

2023-06-16 Thread Michael Niedermayer


This patchset adds some basic SDR support to FFmpeg
ATM, this supports AM demodulation, i will add FM later
I have no immedeate plans to add DAB, DVB, ...
but these should be added too and would be very welcome 
if someone else wants to work on them.
The only dependancy this has is libsoapy which is a small
lightweight library to interface to basically all SDR hardware
In fact its not even needing libsoapy in principle if you have 
raw sdr data with a basic header in a file.
Iam posting this with just AM support as i have a bit of a
dislike for having patches in my local git for longer than needed.

This allows listening to AM radio stations, air traffic control
and anything else using AM with any player supporting libavformat
You can also demodulate and record all AM stations at the same time
if your sdr hw has the bandwidth.

ATM all the processing is done in the main thread, for me on my older
notebook its still usb bandwidth and sdr hw that hits the wall first.
But its easy to multithread. Most of the computation should be in the FFT
All stuff later processes only a subset of the data and does thus not matter
that much anymore. Its also possible to implement the demodulation with no FFT.
But this way it was kind of interresting as everything can be done
from teh FFT spectrum, vissualization, searching radio stations, and
demodulation.

Thx


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

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


[FFmpeg-devel] [PATCH 4/5] avcodec: Rename ff_kbd_window_init() as it will be needed from outside libavcodec

2023-06-16 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/aacdec_template.c | 8 
 libavcodec/aactab.c  | 4 ++--
 libavcodec/ac3dec.c  | 2 +-
 libavcodec/ac3enc_fixed.c| 2 +-
 libavcodec/ac3enc_float.c| 2 +-
 libavcodec/dolby_e.c | 4 ++--
 libavcodec/kbdwin.c  | 4 ++--
 libavcodec/kbdwin.h  | 6 +++---
 8 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 444dc4fa9d..2385ea58b0 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1159,8 +1159,8 @@ static av_cold void aac_static_table_init(void)
 352);
 
 // window initialization
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960);
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME(aac_kbd_short_120), 6.0, 120);
+AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960);
+AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME(aac_kbd_short_120), 6.0, 
120);
 
 #if !USE_FIXED
 AAC_RENAME(ff_sine_window_init)(AAC_RENAME(sine_960), 960);
@@ -1168,8 +1168,8 @@ static av_cold void aac_static_table_init(void)
 AAC_RENAME(ff_init_ff_sine_windows)(9);
 ff_aac_float_common_init();
 #else
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME2(aac_kbd_long_1024), 4.0, 1024);
-AAC_RENAME(ff_kbd_window_init)(AAC_RENAME2(aac_kbd_short_128), 6.0, 128);
+AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME2(aac_kbd_long_1024), 4.0, 
1024);
+AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME2(aac_kbd_short_128), 6.0, 
128);
 init_sine_windows_fixed();
 #endif
 
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index 0f4941d5df..d0006eac35 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -48,8 +48,8 @@ DECLARE_ALIGNED(32, float,  ff_aac_kbd_short_128)[128];
 
 static av_cold void aac_float_common_init(void)
 {
-ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
-ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
+avpriv_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
+avpriv_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
 ff_init_ff_sine_windows(10);
 ff_init_ff_sine_windows(7);
 }
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index fc0cbeb493..8c63f015f4 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -228,7 +228,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
 if ((ret = av_tx_init(&s->tx_256, &s->tx_fn_256, IMDCT_TYPE, 1, 256, 
&scale, 0)))
 return ret;
 
-AC3_RENAME(ff_kbd_window_init)(s->window, 5.0, 256);
+AC3_RENAME(avpriv_kbd_window_init)(s->window, 5.0, 256);
 ff_bswapdsp_init(&s->bdsp);
 
 #if (USE_FIXED)
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 88dfd66b91..079a43dc39 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -82,7 +82,7 @@ static av_cold int ac3_fixed_mdct_init(AC3EncodeContext *s)
 if (!iwin)
 return AVERROR(ENOMEM);
 
-ff_kbd_window_init(fwin, 5.0, AC3_BLOCK_SIZE);
+avpriv_kbd_window_init(fwin, 5.0, AC3_BLOCK_SIZE);
 for (int i = 0; i < AC3_BLOCK_SIZE; i++)
 iwin[i] = lrintf(fwin[i] * (1 << 22));
 
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index ae351a535e..9664adbf63 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -92,7 +92,7 @@ static av_cold int ac3_float_mdct_init(AC3EncodeContext *s)
 return AVERROR(ENOMEM);
 }
 
-ff_kbd_window_init(window, 5.0, AC3_BLOCK_SIZE);
+avpriv_kbd_window_init(window, 5.0, AC3_BLOCK_SIZE);
 s->mdct_window = window;
 
 return av_tx_init(&s->tx, &s->tx_fn, AV_TX_FLOAT_MDCT, 0,
diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 921c33f3ba..b8dac0fa3f 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -1200,7 +1200,7 @@ static av_cold void init_tables(void)
 gain_tab[i] = exp2f((i - 960) / 64.0f);
 
 // short 1
-ff_kbd_window_init(window, 3.0f, 128);
+avpriv_kbd_window_init(window, 3.0f, 128);
 for (i = 0; i < 128; i++)
 window[128 + i] = window[127 - i];
 
@@ -1227,7 +1227,7 @@ static av_cold void init_tables(void)
 window[1088 + i] = 1.0f;
 
 // long
-ff_kbd_window_init(window + 1408, 3.0f, 256);
+avpriv_kbd_window_init(window + 1408, 3.0f, 256);
 for (i = 0; i < 640; i++)
 window[1664 + i] = 1.0f;
 for (i = 0; i < 256; i++)
diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
index 82755874d4..eacdb46774 100644
--- a/libavcodec/kbdwin.c
+++ b/libavcodec/kbdwin.c
@@ -56,12 +56,12 @@ av_cold static int kbd_window_init(float *float_window, int 
*int_window, float a
return 0;
 }
 
-av_cold int ff_kbd_window_init(float *window, float alpha, int n)
+av_cold int avpriv_kbd_window_init(float *window, float alpha, int n)
 {
 return kbd_window_init(window, NULL, alpha, n);
 }
 
-av_cold int ff_kbd_window_init_fixed(int32_t *window, float alph

[FFmpeg-devel] [PATCH 3/5] avcodec/kbdwin: Support arbitrary sized windows

2023-06-16 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/kbdwin.c | 22 ++
 libavcodec/kbdwin.h |  8 +---
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
index 163f9d5251..82755874d4 100644
--- a/libavcodec/kbdwin.c
+++ b/libavcodec/kbdwin.c
@@ -19,20 +19,23 @@
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/attributes.h"
+#include "libavutil/mem.h"
 #include "kbdwin.h"
 
-av_cold static void kbd_window_init(float *float_window, int *int_window, 
float alpha, int n)
+av_cold static int kbd_window_init(float *float_window, int *int_window, float 
alpha, int n)
 {
int i;
double sum = 0.0, tmp;
double scale = 0.0;
-   double temp[FF_KBD_WINDOW_MAX / 2 + 1];
+   double temp_small[FF_KBD_WINDOW_MAX / 2 + 1];
+   double *temp= n<=FF_KBD_WINDOW_MAX ? temp_small : av_malloc((n/2+1) * 
sizeof(*temp));
double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n);
 
-   av_assert0(n <= FF_KBD_WINDOW_MAX);
+   if (!temp)
+   return AVERROR(ENOMEM);
 
for (i = 0; i <= n / 2; i++) {
-   tmp = i * (n - i) * alpha2;
+   tmp = alpha2 * i * (n - i);
temp[i] = av_bessel_i0(sqrt(tmp));
scale += temp[i] * (1 + (i && ihttps://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] avformat/jpegxl_anim_dec: avoid overrun with jxlp boxes in container

2023-06-16 Thread Leo Izen

On 6/16/23 15:00, Andreas Rheinhardt wrote:

Leo Izen:

This switches the jpegxl_collect_codestream_header function to use
avcodec/bytestream2, which better enforces barriers, and should avoid
overrunning buffers with jxlp boxes if the size is zero or if the size
is so small the box is invalid.

Signed-off-by: Leo Izen 
---
  libavformat/jpegxl_anim_dec.c | 56 +++
  1 file changed, 30 insertions(+), 26 deletions(-)

diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c
index 6ea6c46d8f..ec400c955c 100644
--- a/libavformat/jpegxl_anim_dec.c
+++ b/libavformat/jpegxl_anim_dec.c
@@ -28,6 +28,7 @@
  #include 
  #include 
  
+#include "libavcodec/bytestream.h"

  #define BITSTREAM_READER_LE
  #include "libavcodec/get_bits.h"
  
@@ -48,62 +49,65 @@ typedef struct JXLAnimDemuxContext {

   * returns the number of bytes consumed from input, may be greater than 
input_len
   * if the input doesn't end on an ISOBMFF-box boundary
   */
-static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int 
input_len, uint8_t *buffer, int buflen, int *copied) {
-const uint8_t *b = input_buffer;
+static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int 
input_len,
+uint8_t *buffer, int buflen, int 
*copied) {
+GetByteContext gb;
  *copied = 0;
+bytestream2_init(&gb, input_buffer, input_len);
  
  while (1) {

  uint64_t size;
  uint32_t tag;
  int head_size = 8;
  
-if (b - input_buffer >= input_len - 16)

+if (bytestream2_get_bytes_left(&gb) < 16)
  break;
  
-size = AV_RB32(b);

-b += 4;
+size = bytestream2_get_be32(&gb);
  if (size == 1) {
-size = AV_RB64(b);
-b += 8;
+size = bytestream2_get_be64(&gb);
  head_size = 16;
  }
  /* invalid ISOBMFF size */
-if (size > 0 && size <= head_size)
+if (size && size <= head_size)
  return AVERROR_INVALIDDATA;
-if (size > 0)
+if (size)
  size -= head_size;
  
-tag = AV_RL32(b);

-b += 4;
+tag = bytestream2_get_le32(&gb);
  if (tag == MKTAG('j', 'x', 'l', 'p')) {
-b += 4;
-size -= 4;
+if (bytestream2_get_bytes_left(&gb) < 4)
+break;
+bytestream2_skip(&gb, 4);
+if (size) {
+if (size <= 4)
+return AVERROR_INVALIDDATA;
+size -= 4;
+}
  }
+/*
+ * size = 0 means "until EOF". this is legal but uncommon
+ * here we just set it to the remaining size of the probe buffer
+ */
+if (!size)
+size = bytestream2_get_bytes_left(&gb);
  
  if (tag == MKTAG('j', 'x', 'l', 'c') || tag == MKTAG('j', 'x', 'l', 'p')) {

-/*
- * size = 0 means "until EOF". this is legal but uncommon
- * here we just set it to the remaining size of the probe buffer
- * which at this point should always be nonnegative
- */
-if (size == 0 || size > input_len - (b - input_buffer))
-size = input_len - (b - input_buffer);
-
  if (size > buflen - *copied)
  size = buflen - *copied;
  /*
   * arbitrary chunking of the payload makes this memcpy hard to 
avoid
   * in practice this will only be performed one or two times at 
most
   */
-memcpy(buffer + *copied, b, size);
-*copied += size;
+*copied += bytestream2_get_buffer(&gb, buffer + *copied, size);
+} else {
+bytestream2_skip(&gb, size);
  }
-b += size;
-if (b >= input_buffer + input_len || *copied >= buflen)
+if (bytestream2_get_bytes_left(&gb) <= 0 || *copied >= buflen)
  break;
  }
  
-return b - input_buffer;

+return bytestream2_tell(&gb);
  }
  
  static int jpegxl_anim_probe(const AVProbeData *p)


Is there an actual (potential) overrun or is this just a precaution?

- Andreas



Yea, michaelni sent a cvslog email about it earlier, mail ID 
<20230608002033.GF870501@pb2>. This fixes that and switches to 
bytestream2 at Anton's recommendation.


- Leo Izen

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

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


[FFmpeg-devel] [PATCH 2/5] avcodec/pcm: allow Changing parameters

2023-06-16 Thread Michael Niedermayer
SDR needs this for switching between mono and stereo stations

Signed-off-by: Michael Niedermayer 
---
 libavcodec/pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 23955ba2dd..467ecb4fe0 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -578,7 +578,7 @@ const FFCodec ff_ ## name_ ## _decoder = {  
\
 .priv_data_size = sizeof(PCMDecode),\
 .init   = pcm_decode_init,  \
 FF_CODEC_DECODE_CB(pcm_decode_frame),\
-.p.capabilities = AV_CODEC_CAP_DR1, \
+.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_PARAM_CHANGE, \
 .p.sample_fmts  = (const enum AVSampleFormat[]){ sample_fmt_,   \
  AV_SAMPLE_FMT_NONE },  \
 }
-- 
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/5] avutil/tx_template: extend to 2M

2023-06-16 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavutil/tx_template.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/libavutil/tx_template.c b/libavutil/tx_template.c
index 983de75a47..c4ec9502e0 100644
--- a/libavutil/tx_template.c
+++ b/libavutil/tx_template.c
@@ -43,6 +43,10 @@
 SR_TABLE(32768)\
 SR_TABLE(65536)\
 SR_TABLE(131072)   \
+SR_TABLE(262144)   \
+SR_TABLE(524288)   \
+SR_TABLE(1048576)   \
+SR_TABLE(2097152)   \
 
 #define SR_TABLE(len) \
 TABLE_DEF(len, len/4 + 1);
@@ -717,6 +721,10 @@ DECL_SR_CODELET(16384,8192,4096)
 DECL_SR_CODELET(32768,16384,8192)
 DECL_SR_CODELET(65536,32768,16384)
 DECL_SR_CODELET(131072,65536,32768)
+DECL_SR_CODELET(262144,131072,65536)
+DECL_SR_CODELET(524288,262144,131072)
+DECL_SR_CODELET(1048576,524288,262144)
+DECL_SR_CODELET(2097152,1048576,524288)
 
 static av_cold int TX_NAME(ff_tx_fft_init)(AVTXContext *s,
const FFTXCodelet *cd,
@@ -1947,6 +1955,10 @@ const FFTXCodelet * const TX_NAME(ff_tx_codelet_list)[] 
= {
 &TX_NAME(ff_tx_fft32768_ns_def),
 &TX_NAME(ff_tx_fft65536_ns_def),
 &TX_NAME(ff_tx_fft131072_ns_def),
+&TX_NAME(ff_tx_fft262144_ns_def),
+&TX_NAME(ff_tx_fft524288_ns_def),
+&TX_NAME(ff_tx_fft1048576_ns_def),
+&TX_NAME(ff_tx_fft2097152_ns_def),
 
 /* Prime factor codelets */
 &TX_NAME(ff_tx_fft3_ns_def),
-- 
2.17.1

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

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


Re: [FFmpeg-devel] [PATCH 1/5] avcodec: Add new side data type to contain original PTS value

2023-06-16 Thread Andreas Rheinhardt
Devin Heitmueller:
> In order to properly process SCTE-35 packets, we need the original
> PTS value from the demux (i.e. not mangled by the application or
> reclocked for the output).  This allows us to set the pts_adjustment
> field in an BSF on the output side.
> 
> Introduce a new side data type to store the original PTS.
> 
> Signed-off-by: Devin Heitmueller 
> ---
>  libavcodec/packet.h | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> index f28e7e7..a86a550 100644
> --- a/libavcodec/packet.h
> +++ b/libavcodec/packet.h
> @@ -300,6 +300,16 @@ enum AVPacketSideDataType {
>  AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  
>  /**
> + * Provides the original PTS when passed through the demux.  This can
> + * be used to offset any subsequent changes made by the caller to
> + * adjust PTS values (such as pts_offset).  We need this for SCTE-35,
> + * since by the time the packets reach the output the PTS values have
> + * already been re-written, and we cannot calculate pre-roll values
> + * using the PTS values embedded in the packet content
> + */
> +AV_PKT_DATA_ORIG_PTS,
> +
> +/**
>   * The number of side data types.
>   * This is not part of the public API/ABI in the sense that it may
>   * change when new side data types are added.

A timestamp without a timebase? Doesn't sound good to me. And it also
seems quite hacky.
Apart from that: It needs to specify that the data is a int64_t.

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH 4/5] bsf: Add new bitstream filter to set pts_adjustment when reclocking

2023-06-16 Thread Andreas Rheinhardt
Devin Heitmueller:
> Because SCTE-35 messages are represented in TS streams as sections
> rather than PES packets, we cannot rely on ffmpeg's standard
> mechanisms to adjust PTS values if reclocking the stream.
> This filter will leverage the SCTE-35 pts_adjust field to
> compensate for any change in the PTS values in the stream.
> 
> See SCTE-35 2019 Sec 9.6 for information about the use of
> the pts_adjust field.
> 
> This filter also tweaks the mpegtsenc mux to automatically
> add it so the user doesn't have to include it manually.
> 
> Signed-off-by: Devin Heitmueller 
> ---
>  libavcodec/Makefile  |   1 +
>  libavcodec/bitstream_filters.c   |   1 +
>  libavcodec/scte35ptsadjust_bsf.c | 114 
> +++
>  libavformat/mpegtsenc.c  |   2 +
>  4 files changed, 118 insertions(+)
>  create mode 100644 libavcodec/scte35ptsadjust_bsf.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 0ce8fe5..6944c82 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1250,6 +1250,7 @@ OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= 
> pcm_rechunk_bsf.o
>  OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o
>  OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
>  OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o 
> av1_parse.o
> +OBJS-$(CONFIG_SCTE35PTSADJUST_BSF)+= scte35ptsadjust_bsf.o
>  OBJS-$(CONFIG_SETTS_BSF)  += setts_bsf.o
>  OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
>  OBJS-$(CONFIG_TRACE_HEADERS_BSF)  += trace_headers_bsf.o
> diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
> index 7512fcc..d30dfbd 100644
> --- a/libavcodec/bitstream_filters.c
> +++ b/libavcodec/bitstream_filters.c
> @@ -57,6 +57,7 @@ extern const FFBitStreamFilter ff_pcm_rechunk_bsf;
>  extern const FFBitStreamFilter ff_pgs_frame_merge_bsf;
>  extern const FFBitStreamFilter ff_prores_metadata_bsf;
>  extern const FFBitStreamFilter ff_remove_extradata_bsf;
> +extern const FFBitStreamFilter ff_scte35ptsadjust_bsf;
>  extern const FFBitStreamFilter ff_setts_bsf;
>  extern const FFBitStreamFilter ff_text2movsub_bsf;
>  extern const FFBitStreamFilter ff_trace_headers_bsf;
> diff --git a/libavcodec/scte35ptsadjust_bsf.c 
> b/libavcodec/scte35ptsadjust_bsf.c
> new file mode 100644
> index 000..e6e9ec9
> --- /dev/null
> +++ b/libavcodec/scte35ptsadjust_bsf.c
> @@ -0,0 +1,114 @@
> +/*
> + * SCTE-35 PTS fixup bitstream filter
> + * Copyright (c) 2023 LTN Global Communications, Inc.
> + *
> + * Author: Devin Heitmueller 
> + *
> + * Because SCTE-35 messages are represented in TS streams as sections
> + * rather than PES packets, we cannot rely on ffmpeg's standard
> + * mechanisms to adjust PTS values if reclocking the stream.
> + * This filter will leverage the SCTE-35 pts_adjust field to
> + * compensate for any change in the PTS values in the stream.
> + *
> + * See SCTE-35 2019 Sec 9.6 for information about the use of
> + * the pts_adjust field.
> + *
> + * 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 "avcodec.h"

What is that for? The BSF API is separate from the AVCodecContext stuff.

> +#include "bsf.h"
> +#include "bsf_internal.h"
> +
> +static int scte35ptsadjust_filter(AVBSFContext *ctx, AVPacket *out)
> +{
> +AVPacket *in;
> +size_t size;

av_packet_get_side_data() can work with NULL for the size pointer.

> +const int64_t *orig_pts;
> +int64_t cur_pts_adjust;
> +int ret = 0;
> +
> +ret = ff_bsf_get_packet(ctx, &in);
> +if (ret < 0)
> +return ret;
> +
> +/* Retrieve the original PTS, which will be used to calculate the 
> pts_adjust */
> +orig_pts = (int64_t *) av_packet_get_side_data(in, AV_PKT_DATA_ORIG_PTS, 
> &size);
> +if (orig_pts == NULL) {
> +/* No original PTS specified, so just pass the packet through */
> +av_packet_move_ref(out, in);
> +av_packet_free(&in);
> +return 0;
> +}
> +
> +av_log(ctx, AV_LOG_DEBUG, "%s pts=%" PRId64 " orig_pts=%" PRId64 "\n", 
> __func__,
> +   in->pts, *orig_pts);
> +
> +/* The pts_adjust field is logically buf[4]-buf[8] of the payload */
> +

[FFmpeg-devel] [PATCH 5/5] mpegtsenc: Don't periodically announce PCR on SCTE-35 streams

2023-06-16 Thread Devin Heitmueller
Changes were made between in the last two years to periodically
send PCR-only packets on all PIDs, but for cases where the stream
may send packets very infrequently (like SCTE-35), this results in
extra TR101290 errors because it fails the PCR interval test.

I am not quite sure what the "right" fix should be for this, but
for now just disable all periodic sending of PCR-only packets on
SCTE-35 streams.

Signed-off-by: Devin Heitmueller 
---
 libavformat/mpegtsenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 48d7833..728057e 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1579,7 +1579,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream 
*st,
 int st2_index = i < st->index ? i : (i + 1 == 
s->nb_streams ? st->index : i + 1);
 AVStream *st2 = s->streams[st2_index];
 MpegTSWriteStream *ts_st2 = st2->priv_data;
-if (ts_st2->pcr_period) {
+if (ts_st2->pcr_period && st2->codecpar->codec_id != 
AV_CODEC_ID_SCTE_35) {
 if (pcr - ts_st2->last_pcr >= ts_st2->pcr_period) {
 ts_st2->last_pcr = FFMAX(pcr - ts_st2->pcr_period, 
ts_st2->last_pcr + ts_st2->pcr_period);
 if (st2 != st) {
-- 
1.8.3.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/5] bsf: Add new bitstream filter to set pts_adjustment when reclocking

2023-06-16 Thread Devin Heitmueller
Because SCTE-35 messages are represented in TS streams as sections
rather than PES packets, we cannot rely on ffmpeg's standard
mechanisms to adjust PTS values if reclocking the stream.
This filter will leverage the SCTE-35 pts_adjust field to
compensate for any change in the PTS values in the stream.

See SCTE-35 2019 Sec 9.6 for information about the use of
the pts_adjust field.

This filter also tweaks the mpegtsenc mux to automatically
add it so the user doesn't have to include it manually.

Signed-off-by: Devin Heitmueller 
---
 libavcodec/Makefile  |   1 +
 libavcodec/bitstream_filters.c   |   1 +
 libavcodec/scte35ptsadjust_bsf.c | 114 +++
 libavformat/mpegtsenc.c  |   2 +
 4 files changed, 118 insertions(+)
 create mode 100644 libavcodec/scte35ptsadjust_bsf.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0ce8fe5..6944c82 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1250,6 +1250,7 @@ OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= 
pcm_rechunk_bsf.o
 OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o av1_parse.o
+OBJS-$(CONFIG_SCTE35PTSADJUST_BSF)+= scte35ptsadjust_bsf.o
 OBJS-$(CONFIG_SETTS_BSF)  += setts_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
 OBJS-$(CONFIG_TRACE_HEADERS_BSF)  += trace_headers_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 7512fcc..d30dfbd 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -57,6 +57,7 @@ extern const FFBitStreamFilter ff_pcm_rechunk_bsf;
 extern const FFBitStreamFilter ff_pgs_frame_merge_bsf;
 extern const FFBitStreamFilter ff_prores_metadata_bsf;
 extern const FFBitStreamFilter ff_remove_extradata_bsf;
+extern const FFBitStreamFilter ff_scte35ptsadjust_bsf;
 extern const FFBitStreamFilter ff_setts_bsf;
 extern const FFBitStreamFilter ff_text2movsub_bsf;
 extern const FFBitStreamFilter ff_trace_headers_bsf;
diff --git a/libavcodec/scte35ptsadjust_bsf.c b/libavcodec/scte35ptsadjust_bsf.c
new file mode 100644
index 000..e6e9ec9
--- /dev/null
+++ b/libavcodec/scte35ptsadjust_bsf.c
@@ -0,0 +1,114 @@
+/*
+ * SCTE-35 PTS fixup bitstream filter
+ * Copyright (c) 2023 LTN Global Communications, Inc.
+ *
+ * Author: Devin Heitmueller 
+ *
+ * Because SCTE-35 messages are represented in TS streams as sections
+ * rather than PES packets, we cannot rely on ffmpeg's standard
+ * mechanisms to adjust PTS values if reclocking the stream.
+ * This filter will leverage the SCTE-35 pts_adjust field to
+ * compensate for any change in the PTS values in the stream.
+ *
+ * See SCTE-35 2019 Sec 9.6 for information about the use of
+ * the pts_adjust field.
+ *
+ * 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 "avcodec.h"
+#include "bsf.h"
+#include "bsf_internal.h"
+
+static int scte35ptsadjust_filter(AVBSFContext *ctx, AVPacket *out)
+{
+AVPacket *in;
+size_t size;
+const int64_t *orig_pts;
+int64_t cur_pts_adjust;
+int ret = 0;
+
+ret = ff_bsf_get_packet(ctx, &in);
+if (ret < 0)
+return ret;
+
+/* Retrieve the original PTS, which will be used to calculate the 
pts_adjust */
+orig_pts = (int64_t *) av_packet_get_side_data(in, AV_PKT_DATA_ORIG_PTS, 
&size);
+if (orig_pts == NULL) {
+/* No original PTS specified, so just pass the packet through */
+av_packet_move_ref(out, in);
+av_packet_free(&in);
+return 0;
+}
+
+av_log(ctx, AV_LOG_DEBUG, "%s pts=%" PRId64 " orig_pts=%" PRId64 "\n", 
__func__,
+   in->pts, *orig_pts);
+
+/* The pts_adjust field is logically buf[4]-buf[8] of the payload */
+if (in->size < 8)
+goto fail;
+
+/* Extract the current pts_adjust value from the packet */
+cur_pts_adjust = ((int64_t) in->data[4] & (int64_t) 0x01 << 32) |
+ ((int64_t) in->data[5] << 24) |
+ ((int64_t) in->data[6] << 16) |
+ ((int64_t) in->data[7] << 8) |
+ ((int64_t) in->data[8] );
+
+av_log(ctx, AV

[FFmpeg-devel] [PATCH 3/5] mpegtsenc: Add support for output of SCTE-35 streams over TS

2023-06-16 Thread Devin Heitmueller
Introduce the ability to pass through SCTE-35 packets when creating
MPEG transport streams.  Note that this patch makes no effort to
change the PTS values in the SCTE-35 packets, and thus only works
when not reclocking the stream (i.e. using -copyts).  A subsequent
patch includes a BSF to recompute the PTS values.

Signed-off-by: Devin Heitmueller 
---
 libavformat/mpegts.h|  1 +
 libavformat/mpegtsenc.c | 74 ++---
 libavformat/mux.c   |  6 ++--
 3 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index a48f14e..a7aaaba 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -137,6 +137,7 @@
 #define STREAM_TYPE_AUDIO_AC3   0x81
 #define STREAM_TYPE_AUDIO_DTS   0x82
 #define STREAM_TYPE_AUDIO_TRUEHD0x83
+#define STREAM_TYPE_SCTE_35 0x86
 #define STREAM_TYPE_AUDIO_EAC3  0x87
 
 /* ISO/IEC 13818-1 Table 2-22 */
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 700fc54..c6cd1fd 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -425,6 +425,9 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
 case AV_CODEC_ID_SMPTE_2038:
 stream_type = STREAM_TYPE_PRIVATE_DATA;
 break;
+case AV_CODEC_ID_SCTE_35:
+stream_type = STREAM_TYPE_SCTE_35;
+break;
 case AV_CODEC_ID_DVB_SUBTITLE:
 case AV_CODEC_ID_DVB_TELETEXT:
 case AV_CODEC_ID_ARIB_CAPTION:
@@ -522,6 +525,16 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
 *q++ = 0xfc;// private_data_byte
 }
 
+/* If there is an SCTE-35 stream, we need a registration descriptor
+   at the program level (SCTE 35 2016 Sec 8.1) */
+for (i = 0; i < s->nb_streams; i++) {
+AVStream *st = s->streams[i];
+if (st->codecpar->codec_id == AV_CODEC_ID_SCTE_35) {
+put_registration_descriptor(&q, MKTAG('C', 'U', 'E', 'I'));
+break;
+}
+}
+
 val = 0xf000 | (q - program_info_length_ptr - 2);
 program_info_length_ptr[0] = val >> 8;
 program_info_length_ptr[1] = val;
@@ -533,6 +546,14 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
 const char default_language[] = "und";
 const char *language = lang && strlen(lang->value) >= 3 ? lang->value 
: default_language;
 enum AVCodecID codec_id = st->codecpar->codec_id;
+uint16_t pid;
+
+if (st->codecpar->codec_id == AV_CODEC_ID_SCTE_35) {
+MpegTSSection *sect = st->priv_data;
+pid = sect->pid;
+} else {
+pid = ts_st->pid;
+}
 
 if (s->nb_programs) {
 int k, found = 0;
@@ -556,7 +577,7 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
 stream_type = ts->m2ts_mode ? get_m2ts_stream_type(s, st) : 
get_dvb_stream_type(s, st);
 
 *q++ = stream_type;
-put16(&q, 0xe000 | ts_st->pid);
+put16(&q, 0xe000 | pid);
 desc_length_ptr = q;
 q += 2; /* patched after */
 
@@ -819,6 +840,10 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
 putbuf(&q, tag, strlen(tag));
 *q++ = 0;/* metadata service ID */
 *q++ = 0xF;  /* 
metadata_locator_record_flag|MPEG_carriage_flags|reserved */
+} else if (st->codecpar->codec_id == AV_CODEC_ID_SCTE_35) {
+*q++ = 0x8a; /* Cue Identifier Descriptor */
+*q++ = 0x01; /* length */
+*q++ = 0x01; /* Cue Stream Type (see Sec 8.2) */
 }
 break;
 }
@@ -1159,6 +1184,33 @@ static int mpegts_init(AVFormatContext *s)
 AVStream *st = s->streams[i];
 MpegTSWriteStream *ts_st;
 
+if (st->codecpar->codec_id == AV_CODEC_ID_SCTE_35) {
+struct MpegTSSection *sect;
+sect = av_mallocz(sizeof(MpegTSSection));
+if (!sect) {
+ret = AVERROR(ENOMEM);
+continue;
+}
+
+if (st->id < 16) {
+sect->pid = ts->start_pid + i;
+} else if (st->id < 0x1FFF) {
+sect->pid = st->id;
+} else {
+av_log(s, AV_LOG_ERROR,
+   "Invalid stream id %d, must be less than 8191\n", 
st->id);
+ret = AVERROR(EINVAL);
+continue;
+}
+
+sect->write_packet = section_write_packet;
+sect->opaque   = s;
+sect->cc   = 15;
+sect->discontinuity= ts->flags & MPEGTS_FLAG_DISCONT;
+st->priv_data = sect;
+continue;
+}
+
 ts_st = av_mallocz(sizeof(MpegTSWriteStream));
 if (!ts_st) {
 return AVERROR(ENOMEM);
@@ -1877,6 +1929,19 @@ static int mpegts_write_packet_internal(AVFormatContext 
*s,

[FFmpeg-devel] [PATCH 2/5] mpegts: Stash original PTS for SCTE-35 sections for processing later

2023-06-16 Thread Devin Heitmueller
We need the original PTS value in order to do subsequent processing,
so set it as packet side data.

Signed-off-by: Devin Heitmueller 
---
 libavformat/mpegts.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 385d78b..b8f1d7d 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1782,8 +1782,15 @@ static void scte_data_cb(MpegTSFilter *filter, const 
uint8_t *section,
 prg = av_find_program_from_stream(ts->stream, NULL, idx);
 if (prg && prg->pcr_pid != -1 && prg->discard != AVDISCARD_ALL) {
 MpegTSFilter *f = ts->pids[prg->pcr_pid];
-if (f && f->last_pcr != -1)
+if (f && f->last_pcr != -1) {
+int64_t *orig_pts;
 ts->pkt->pts = ts->pkt->dts = f->last_pcr/300;
+orig_pts = (int64_t *) av_packet_new_side_data(ts->pkt,
+   
AV_PKT_DATA_ORIG_PTS,
+   sizeof(int64_t));
+if (orig_pts)
+*orig_pts = ts->pkt->pts;
+}
 }
 ts->stop_parse = 1;
 
-- 
1.8.3.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/5] avcodec: Add new side data type to contain original PTS value

2023-06-16 Thread Devin Heitmueller
In order to properly process SCTE-35 packets, we need the original
PTS value from the demux (i.e. not mangled by the application or
reclocked for the output).  This allows us to set the pts_adjustment
field in an BSF on the output side.

Introduce a new side data type to store the original PTS.

Signed-off-by: Devin Heitmueller 
---
 libavcodec/packet.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index f28e7e7..a86a550 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -300,6 +300,16 @@ enum AVPacketSideDataType {
 AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
 
 /**
+ * Provides the original PTS when passed through the demux.  This can
+ * be used to offset any subsequent changes made by the caller to
+ * adjust PTS values (such as pts_offset).  We need this for SCTE-35,
+ * since by the time the packets reach the output the PTS values have
+ * already been re-written, and we cannot calculate pre-roll values
+ * using the PTS values embedded in the packet content
+ */
+AV_PKT_DATA_ORIG_PTS,
+
+/**
  * The number of side data types.
  * This is not part of the public API/ABI in the sense that it may
  * change when new side data types are added.
-- 
1.8.3.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 0/5] Add passthrough support for SCTE-35

2023-06-16 Thread Devin Heitmueller
Properly set up the MPEG-TS mux and recalculate the pts_adjust field
in SCTE_35 packets, such that a user can transparently pass through
SCTE-35 streams when both the input and output are MPEG-TS.

Devin Heitmueller (5):
  avcodec: Add new side data type to contain original PTS value
  mpegts: Stash original PTS for SCTE-35 sections for processing later
  mpegtsenc: Add support for output of SCTE-35 streams over TS
  bsf: Add new bitstream filter to set pts_adjustment when reclocking
  mpegtsenc: Don't periodically announce PCR on SCTE-35 streams

 libavcodec/Makefile  |   1 +
 libavcodec/bitstream_filters.c   |   1 +
 libavcodec/packet.h  |  10 
 libavcodec/scte35ptsadjust_bsf.c | 114 +++
 libavformat/mpegts.c |   9 +++-
 libavformat/mpegts.h |   1 +
 libavformat/mpegtsenc.c  |  78 +--
 libavformat/mux.c|   6 ++-
 8 files changed, 212 insertions(+), 8 deletions(-)
 create mode 100644 libavcodec/scte35ptsadjust_bsf.c

-- 
1.8.3.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 16/21] fftools/ffmpeg_dec: move decoding to a separate thread

2023-06-16 Thread Michael Niedermayer
On Wed, Jun 14, 2023 at 06:49:03PM +0200, Anton Khirnov wrote:
> This is only a preparatory step to a fully threaded architecture and
> does not yet make decoding truly parallel - the main thread will
> currently submit a packet and wait until it has been fully processed by
> the decoding thread before moving on. Decoded behavior as observed by
> the rest of the program should remain unchanged. That will change in
> future commits after encoders and filters are moved to threads and a
> thread-aware scheduler is added.
> ---
>  fftools/ffmpeg.c |  63 +---
>  fftools/ffmpeg.h |  11 ++
>  fftools/ffmpeg_dec.c | 365 ++-
>  fftools/ffmpeg_mux.c |   5 -
>  4 files changed, 382 insertions(+), 62 deletions(-)

This seems to break (infinite loop)

ffmpeg -i videos/bink/thps4/ACDC.smo -bitexact -t 1 -y ACDC.smo.avi

file seems there: on samples server: game-formats/bink/thps4/ACDC.smo

thx

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

Elect your leaders based on what they did after the last election, not
based on what they say before an election.



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] avformat/jpegxl_anim_dec: avoid overrun with jxlp boxes in container

2023-06-16 Thread Andreas Rheinhardt
Leo Izen:
> This switches the jpegxl_collect_codestream_header function to use
> avcodec/bytestream2, which better enforces barriers, and should avoid
> overrunning buffers with jxlp boxes if the size is zero or if the size
> is so small the box is invalid.
> 
> Signed-off-by: Leo Izen 
> ---
>  libavformat/jpegxl_anim_dec.c | 56 +++
>  1 file changed, 30 insertions(+), 26 deletions(-)
> 
> diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c
> index 6ea6c46d8f..ec400c955c 100644
> --- a/libavformat/jpegxl_anim_dec.c
> +++ b/libavformat/jpegxl_anim_dec.c
> @@ -28,6 +28,7 @@
>  #include 
>  #include 
>  
> +#include "libavcodec/bytestream.h"
>  #define BITSTREAM_READER_LE
>  #include "libavcodec/get_bits.h"
>  
> @@ -48,62 +49,65 @@ typedef struct JXLAnimDemuxContext {
>   * returns the number of bytes consumed from input, may be greater than 
> input_len
>   * if the input doesn't end on an ISOBMFF-box boundary
>   */
> -static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int 
> input_len, uint8_t *buffer, int buflen, int *copied) {
> -const uint8_t *b = input_buffer;
> +static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int 
> input_len,
> +uint8_t *buffer, int buflen, int 
> *copied) {
> +GetByteContext gb;
>  *copied = 0;
> +bytestream2_init(&gb, input_buffer, input_len);
>  
>  while (1) {
>  uint64_t size;
>  uint32_t tag;
>  int head_size = 8;
>  
> -if (b - input_buffer >= input_len - 16)
> +if (bytestream2_get_bytes_left(&gb) < 16)
>  break;
>  
> -size = AV_RB32(b);
> -b += 4;
> +size = bytestream2_get_be32(&gb);
>  if (size == 1) {
> -size = AV_RB64(b);
> -b += 8;
> +size = bytestream2_get_be64(&gb);
>  head_size = 16;
>  }
>  /* invalid ISOBMFF size */
> -if (size > 0 && size <= head_size)
> +if (size && size <= head_size)
>  return AVERROR_INVALIDDATA;
> -if (size > 0)
> +if (size)
>  size -= head_size;
>  
> -tag = AV_RL32(b);
> -b += 4;
> +tag = bytestream2_get_le32(&gb);
>  if (tag == MKTAG('j', 'x', 'l', 'p')) {
> -b += 4;
> -size -= 4;
> +if (bytestream2_get_bytes_left(&gb) < 4)
> +break;
> +bytestream2_skip(&gb, 4);
> +if (size) {
> +if (size <= 4)
> +return AVERROR_INVALIDDATA;
> +size -= 4;
> +}
>  }
> +/*
> + * size = 0 means "until EOF". this is legal but uncommon
> + * here we just set it to the remaining size of the probe buffer
> + */
> +if (!size)
> +size = bytestream2_get_bytes_left(&gb);
>  
>  if (tag == MKTAG('j', 'x', 'l', 'c') || tag == MKTAG('j', 'x', 'l', 
> 'p')) {
> -/*
> - * size = 0 means "until EOF". this is legal but uncommon
> - * here we just set it to the remaining size of the probe buffer
> - * which at this point should always be nonnegative
> - */
> -if (size == 0 || size > input_len - (b - input_buffer))
> -size = input_len - (b - input_buffer);
> -
>  if (size > buflen - *copied)
>  size = buflen - *copied;
>  /*
>   * arbitrary chunking of the payload makes this memcpy hard to 
> avoid
>   * in practice this will only be performed one or two times at 
> most
>   */
> -memcpy(buffer + *copied, b, size);
> -*copied += size;
> +*copied += bytestream2_get_buffer(&gb, buffer + *copied, size);
> +} else {
> +bytestream2_skip(&gb, size);
>  }
> -b += size;
> -if (b >= input_buffer + input_len || *copied >= buflen)
> +if (bytestream2_get_bytes_left(&gb) <= 0 || *copied >= buflen)
>  break;
>  }
>  
> -return b - input_buffer;
> +return bytestream2_tell(&gb);
>  }
>  
>  static int jpegxl_anim_probe(const AVProbeData *p)

Is there an actual (potential) overrun or is this just a precaution?

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH v2] avformat/jpegxl_anim_dec: avoid overrun with jxlp boxes in container

2023-06-16 Thread Leo Izen

On 6/12/23 09:22, Leo Izen wrote:

This switches the jpegxl_collect_codestream_header function to use
avcodec/bytestream2, which better enforces barriers, and should avoid
overrunning buffers with jxlp boxes if the size is zero or if the size
is so small the box is invalid.

Signed-off-by: Leo Izen 
---
  libavformat/jpegxl_anim_dec.c | 56 +++
  1 file changed, 30 insertions(+), 26 deletions(-)


Will push soon if there's no objections, as this fixes a bug.

- Leo Izen

___
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 01/11] avformat/evcdec: set the demuxer as AVFMT_NOTIMESTAMPS

2023-06-16 Thread James Almer

On 6/15/2023 12:18 PM, James Almer wrote:

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

diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 89eda0f53e..807406885a 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -268,7 +268,7 @@ const AVInputFormat ff_evc_demuxer = {
  .read_packet= evc_read_packet, // annexb_read_packet
  .read_close = evc_read_close,
  .extensions = "evc",
-.flags  = AVFMT_GENERIC_INDEX,
+.flags  = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
  .flags_internal = FF_FMT_INIT_CLEANUP,
  .raw_codec_id   = AV_CODEC_ID_EVC,
  .priv_data_size = sizeof(EVCDemuxContext),


I'll apply the rest of this set soon.
___
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] avformat/http: copy only mime type from Content-Type

2023-06-16 Thread Kacper Michajlow
On Thu, 1 Jun 2023 at 21:44, Kacper Michajłow  wrote:
>
> Content-Type can include charset and boundary which is not a part of
> mime type and shouldn't be copied as such.
>
> Fixes HLS playback when the Content-Type includes additional fields.
>
> Signed-off-by: Kacper Michajłow 
> ---
>  libavformat/http.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/http.c b/libavformat/http.c
> index 0817aafb5b..fd931c2d8e 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -1205,7 +1205,7 @@ static int process_line(URLContext *h, char *line, int 
> line_count)
>  }
>  } else if (!av_strcasecmp(tag, "Content-Type")) {
>  av_free(s->mime_type);
> -s->mime_type = av_strdup(p);
> +s->mime_type = av_get_token((const char **)&p, ";");
>  } else if (!av_strcasecmp(tag, "Set-Cookie")) {
>  if (parse_cookie(s, p, &s->cookie_dict))
>  av_log(h, AV_LOG_WARNING, "Unable to parse '%s'\n", p);
> --
> 2.34.1
>

Bump. I would prefer this smal thing to be fixed upstream, than adding
workaround.

Thanks.
___
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] avfilter/scale_cuda: add support for rgb32/bgr32 conversions

2023-06-16 Thread Philip Langdale
As we are introducing two new formats and supporting conversions
between them, and also with the existing 0rgb32/0bgr32 formats, we get
a combinatorial explosion of kernels. I introduced a few new macros to
keep the things mostly managable.

The conversions are all simple, following existing patterns, with four
specific exceptions. When converting from 0rgb32/0bgr32 to rgb32/bgr32,
we need to ensure the alpha value is set to 1. In all other cases, it
can just be passed through, either to be used or ignored.
---
 libavfilter/vf_scale_cuda.c  |   2 +
 libavfilter/vf_scale_cuda.cu | 151 ---
 2 files changed, 122 insertions(+), 31 deletions(-)

diff --git a/libavfilter/vf_scale_cuda.c b/libavfilter/vf_scale_cuda.c
index 1c99befec8..370cb1d9cd 100644
--- a/libavfilter/vf_scale_cuda.c
+++ b/libavfilter/vf_scale_cuda.c
@@ -51,6 +51,8 @@ static const enum AVPixelFormat supported_formats[] = {
 AV_PIX_FMT_YUV444P16,
 AV_PIX_FMT_0RGB32,
 AV_PIX_FMT_0BGR32,
+AV_PIX_FMT_RGB32,
+AV_PIX_FMT_BGR32,
 };
 
 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
diff --git a/libavfilter/vf_scale_cuda.cu b/libavfilter/vf_scale_cuda.cu
index c9c6cafdb6..de06ba9433 100644
--- a/libavfilter/vf_scale_cuda.cu
+++ b/libavfilter/vf_scale_cuda.cu
@@ -853,9 +853,67 @@ struct Convert_yuv444p16le_yuv444p16le
 }
 };
 
-// bgr0->X
-
-struct Convert_bgr0_bgr0
+#define DEF_CONVERT_IDENTITY(fmt1, fmt2)\
+\
+struct Convert_##fmt1##_##fmt2  \
+{   \
+static const int in_bit_depth = 8;  \
+typedef uchar4 in_T;\
+typedef uchar in_T_uv;  \
+typedef uchar4 out_T;   \
+typedef uchar out_T_uv; \
+\
+DEF_F(Convert, out_T)   \
+{   \
+DEFAULT_DST(0) = SUB_F(y, 0);   \
+}   \
+\
+DEF_F(Convert_uv, out_T_uv) \
+{   \
+}   \
+};  \
+
+#define DEF_CONVERT_REORDER(fmt1, fmt2) \
+\
+struct Convert_##fmt1##_##fmt2  \
+{   \
+static const int in_bit_depth = 8;  \
+typedef uchar4 in_T;\
+typedef uchar in_T_uv;  \
+typedef uchar4 out_T;   \
+typedef uchar out_T_uv; \
+\
+DEF_F(Convert, out_T)   \
+{   \
+uchar4 res = SUB_F(y, 0);   \
+DEFAULT_DST(0) = make_uchar4(   \
+res.z,  \
+res.y,  \
+res.x,  \
+res.w   \
+);  \
+}   \
+\
+DEF_F(Convert_uv, out_T_uv) \
+{   \
+}   \
+};  \
+
+#define DEF_CONVERT_RGB(fmt1, fmt2) \
+\
+DEF_CONVERT_IDENTITY(fmt1, fmt1)\
+DEF_CONVERT_REORDER (fmt1, fmt2)\
+DEF_CONVERT_REORDER (fmt2, fmt1)\
+DEF_CONVERT_IDENTITY(fmt2, fmt2)
+
+DEF_CONVERT_RGB(rgb0, bgr0)
+DEF_CONVERT_RGB(rgba, bgra)
+DEF_CONVERT_IDENTITY(rgba, rgb0)
+DEF_CONVERT_IDENTITY(bgra, bgr0)
+DEF_CONVERT_REORDER(rgba, bgr0)
+DEF_CONVERT_REORDER(bgra, rgb0)
+
+struct Convert_bgr0_bgra
 {
 static const int in_bit_depth = 8;
 typedef uchar4 in_T;
@@ -865,7 +923,13 @@ struct Convert_bgr0_bgr0
 
 DEF_F(Convert, out_T)
 {
-DEFAULT_DST(0) = SUB_F(y, 0);
+uchar4 res = SUB_F(y, 0);
+DEFAULT_DST(0) = make_uchar4(
+res.x,
+res.y,
+res.z,
+1
+);
 }
 
 DEF_F(Convert_uv, out_T_uv)
@@ -873,7 +937,7 @@ struct Convert_bgr0_bgr0
 }
 };
 
-struct Convert_bgr0_rgb0
+struct Convert_bgr0_rgba
 {
 static const int in_bit_depth = 8;
 typedef uchar4 in_T;
@@ -888,7 +952,7 @@ struct Convert_bgr0_rgb0
 res.z,
 res.y,
 res.x,
-res.w
+1
 );
 }
 
@@ -897,9 +961,7 @@ struct Convert_bgr0_rgb0
 }
 };
 
-// rgb0->X
-
-struct Convert_rgb0_bgr0
+struct Convert_rgb0_bgra
 {
 static const int in_bit_depth = 8;
 typedef uchar4 in_T;
@@ -914,7 +976,7 @@ struct Convert_rgb0_bgr0
 res.z,
 res.y,
 res.x,
-res.w
+1
 );
 }
 
@@ -923,7 +985,7 @@ struct Convert_rgb0_bgr0
 }
 };
 
-struct Convert_rgb0_rgb0
+struct Convert_rgb0_rgba
 {
 static const int in_bit_depth = 

[FFmpeg-devel] [PATCH 3/3] Add Changelog entry

2023-06-16 Thread Tomas Härdin
Bumping with a forgotten Changelog entry
From 33045f32da50390e6d58c34e95b3d344a53b6968 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Fri, 16 Jun 2023 15:19:24 +0200
Subject: [PATCH 3/3] Add Changelog entry

---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index d51e03b8eb..2d6b63bfa2 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@ version :
 - nlmeans_vulkan filter
 - RivaTuner video decoder
 - xfade_vulkan filter
+- Microsoft RLE video encoder
 
 version 6.0:
 - Radiance HDR image support
-- 
2.30.2

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

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


Re: [FFmpeg-devel] [PATCH 09/22] lavfi/vf_libplacebo: replace s->input by dynamic array

2023-06-16 Thread Niklas Haas
On Fri, 16 Jun 2023 14:09:56 +0200 Andreas Rheinhardt 
 wrote:
> Niklas Haas:
> > From: Niklas Haas 
> > 
> > For now, hard-coded to 1 element.
> > ---
> >  libavfilter/vf_libplacebo.c | 18 +-
> >  1 file changed, 13 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> > index 408fb3918a..fbac1b0354 100644
> > --- a/libavfilter/vf_libplacebo.c
> > +++ b/libavfilter/vf_libplacebo.c
> > @@ -136,7 +136,8 @@ typedef struct LibplaceboContext {
> >  pl_tex tex[4];
> >  
> >  /* input state */
> > -LibplaceboInput input;
> > +LibplaceboInput *inputs;
> > +int nb_inputs;
> >  
> >  /* settings */
> >  char *out_format_string;
> > @@ -660,7 +661,12 @@ static int init_vulkan(AVFilterContext *avctx, const 
> > AVVulkanDeviceContext *hwct
> >  }
> >  
> >  /* Initialize inputs */
> > -RET(input_init(avctx, avctx->inputs[0], &s->input));
> > +s->nb_inputs = 1;
> > +s->inputs = av_calloc(s->nb_inputs, sizeof(*s->inputs));
> > +if (!s->inputs)
> > +return AVERROR(ENOMEM);
> > +for (int i = 0; i < s->nb_inputs; i++)
> > +RET(input_init(avctx, avctx->inputs[i], &s->inputs[i]));
> >  
> >  /* fall through */
> >  fail:
> > @@ -677,7 +683,9 @@ static void libplacebo_uninit(AVFilterContext *avctx)
> >  pl_tex_destroy(s->gpu, &s->tex[i]);
> >  for (int i = 0; i < s->num_hooks; i++)
> >  pl_mpv_user_shader_destroy(&s->hooks[i]);
> > -input_uninit(&s->input);
> > +for (int i = 0; i < s->nb_inputs && s->inputs; i++)
> > +input_uninit(&s->inputs[i]);
> > +av_freep(&s->inputs);
> 
> In case the allocation of s->inputs fails, nb_inputs is 1 and the above
> loop will try to uninit a non-existant input.

There's an extra `s->inputs` check in the loop condition. I'll make it more
explicit.
___
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] lavu/hwcontext_qsv: fix memory leak for d3d9 impl

2023-06-16 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavutil/hwcontext_qsv.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 931f905a51..4cbe8cc494 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -756,25 +756,28 @@ static int qsv_d3d9_update_config(void *ctx, mfxHDL 
handle, mfxConfig cfg)
 hr = IDirect3DDeviceManager9_LockDevice(devmgr, device_handle, &device, 
TRUE);
 if (FAILED(hr)) {
 av_log(ctx, AV_LOG_ERROR, "Error LockDevice %d\n", hr);
+IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
 goto fail;
 }
 
 hr = IDirect3DDevice9Ex_GetCreationParameters(device, ¶ms);
 if (FAILED(hr)) {
 av_log(ctx, AV_LOG_ERROR, "Error 
IDirect3DDevice9_GetCreationParameters %d\n", hr);
+IDirect3DDevice9Ex_Release(device);
 goto unlock;
 }
 
 hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9ex);
 if (FAILED(hr)) {
 av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9Ex_GetAdapterLUID 
%d\n", hr);
+IDirect3DDevice9Ex_Release(device);
 goto unlock;
 }
 
 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex, params.AdapterOrdinal, &luid);
 if (FAILED(hr)) {
 av_log(ctx, AV_LOG_ERROR, "Error IDirect3DDevice9Ex_GetAdapterLUID 
%d\n", hr);
-goto unlock;
+goto release;
 }
 
 impl_value.Type = MFX_VARIANT_TYPE_PTR;
@@ -784,13 +787,18 @@ static int qsv_d3d9_update_config(void *ctx, mfxHDL 
handle, mfxConfig cfg)
 if (sts != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error adding a MFX configuration"
"DeviceLUID property: %d.\n", sts);
-goto unlock;
+goto release;
 }
 
 ret = 0;
 
+release:
+IDirect3D9Ex_Release(d3d9ex);
+IDirect3DDevice9Ex_Release(device);
+
 unlock:
 IDirect3DDeviceManager9_UnlockDevice(devmgr, device_handle, FALSE);
+IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
 fail:
 #endif
 return ret;
-- 
2.41.0.windows.1

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

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


[FFmpeg-devel] [PATCH 1/2] lavu/hwcontext_qsv: fix memory leak for d3d11va impl

2023-06-16 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavutil/hwcontext_qsv.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 713dc90ffd..931f905a51 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -665,6 +665,7 @@ static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, 
mfxHDL *hdl)
 
 static int qsv_d3d11_update_config(void *ctx, mfxHDL handle, mfxConfig cfg)
 {
+int ret = AVERROR_UNKNOWN;
 #if CONFIG_D3D11VA
 mfxStatus sts;
 IDXGIAdapter *pDXGIAdapter;
@@ -679,7 +680,8 @@ static int qsv_d3d11_update_config(void *ctx, mfxHDL 
handle, mfxConfig cfg)
 hr = IDXGIDevice_GetAdapter(pDXGIDevice, &pDXGIAdapter);
 if (FAILED(hr)) {
 av_log(ctx, AV_LOG_ERROR, "Error IDXGIDevice_GetAdapter %d\n", hr);
-goto fail;
+IDXGIDevice_Release(pDXGIDevice);
+return ret;
 }
 
 hr = IDXGIAdapter_GetDesc(pDXGIAdapter, &adapterDesc);
@@ -689,7 +691,7 @@ static int qsv_d3d11_update_config(void *ctx, mfxHDL 
handle, mfxConfig cfg)
 }
 } else {
 av_log(ctx, AV_LOG_ERROR, "Error ID3D11Device_QueryInterface %d\n", 
hr);
-goto fail;
+return ret;
 }
 
 impl_value.Type = MFX_VARIANT_TYPE_U16;
@@ -722,11 +724,13 @@ static int qsv_d3d11_update_config(void *ctx, mfxHDL 
handle, mfxConfig cfg)
 goto fail;
 }
 
-return 0;
+ret = 0;
 
 fail:
+IDXGIDevice_Release(pDXGIDevice);
+IDXGIAdapter_Release(pDXGIAdapter);
 #endif
-return AVERROR_UNKNOWN;
+return ret;
 }
 
 static int qsv_d3d9_update_config(void *ctx, mfxHDL handle, mfxConfig cfg)
-- 
2.41.0.windows.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] [RFC] [PATCH 1/5] hwcontext: add a new AVHWFramesContext.opaque field

2023-06-16 Thread Lynne
Jun 13, 2023, 19:18 by d...@lynne.ee:

> Jun 13, 2023, 18:56 by andreas.rheinha...@outlook.com:
>
>> Lynne:
>>
>>> +dst->opaque= av_buffer_ref(src->opaque);
>>> +if (!dst->opaque) {
>>> +ret = AVERROR(ENOMEM);
>>> +goto fail;
>>> +}
>>>
>>
>> According to the doxy, opaque can be left unset (and will be given that
>> it is a new field), yet av_buffer_ref(NULL) will crash. We have
>> av_buffer_replace() for something like that.
>>
>
> Fixed.
>

Ping.
___
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/6] lavc/ac3dsp: RISC-V V ac3_sum_square_butterfly_int32

2023-06-16 Thread 沈佩婷

Hei,

> -原始邮件-发件人:"Rémi Denis-Courmont" 发送时间:2023-06-16 
> 03:25:07 (星期五)收件人:ffmpeg-devel@ffmpeg.org抄送:"Shen Peiting" 
> 主题:Re: [FFmpeg-devel] [PATCH 3/6] 
> lavc/ac3dsp: RISC-V V ac3_sum_square_butterfly_int32
> 
> Le torstaina 15. kesäkuuta 2023, 13.36.42 EEST Peiting Shen a écrit :
> > From: Shen Peiting 
> > 
> > Scalar calculating int32 sum_square optimized by using RVV instructions
> > 
> > Benchmarks on Spike(cycles):
> > len=128
> > ac3_sum_square_butterfly_int32_c: 8497
> > ac3_sum_square_butterfly_int32_rvv: 258
> > len=1280
> > ac3_sum_square_butterfly_int32_c: 84529
> > ac3_sum_square_butterfly_int32_rvv: 2274
> > 
> > Co-Authored by: Yang Xiaojun 
> > Co-Authored by: Huang Xing 
> > Co-Authored by: Zeng Fanchen 
> > Signed-off-by: Shen Peiting 
> > ---
> >  libavcodec/riscv/ac3dsp_init.c |  8 +
> >  libavcodec/riscv/ac3dsp_rvv.S  | 53 ++
> >  2 files changed, 61 insertions(+)
> > 
> > diff --git a/libavcodec/riscv/ac3dsp_init.c b/libavcodec/riscv/ac3dsp_init.c
> > index a4e75a7541..4fd4abe83e 100644
> > --- a/libavcodec/riscv/ac3dsp_init.c
> > +++ b/libavcodec/riscv/ac3dsp_init.c
> > @@ -26,6 +26,10 @@
> > 
> >  void ff_ac3_exponent_min_rvv(uint8_t *exp, int num_reuse_blocks, int
> > nb_coefs); void ff_float_to_fixed24_rvv(int32_t *dst, const float *src,
> > unsigned int len); +void ff_ac3_sum_square_butterfly_int32_rvv(int64_t
> > sum[4],
> > +const int32_t *coef0,
> > +const int32_t *coef1,
> > +int len);
> > 
> >  av_cold void ff_ac3dsp_init_riscv(AC3DSPContext *c)
> >  {
> > @@ -35,6 +39,10 @@ av_cold void ff_ac3dsp_init_riscv(AC3DSPContext *c)
> >  c->ac3_exponent_min = ff_ac3_exponent_min_rvv;
> >  c->float_to_fixed24 = ff_float_to_fixed24_rvv;
> >  }
> > +#if (__riscv_xlen >= 64)
> > +if (flags & AV_CPU_FLAG_RVV_I64)
> > +c->sum_square_butterfly_int32 =
> > ff_ac3_sum_square_butterfly_int32_rvv; +#endif
> >  #endif
> >  }
> > 
> > diff --git a/libavcodec/riscv/ac3dsp_rvv.S b/libavcodec/riscv/ac3dsp_rvv.S
> > index d98e72c12c..4e0d238f85 100644
> > --- a/libavcodec/riscv/ac3dsp_rvv.S
> > +++ b/libavcodec/riscv/ac3dsp_rvv.S
> > @@ -63,3 +63,56 @@ func ff_float_to_fixed24_rvv, zve32x
> >  bgtza2, 1b
> >  ret
> >  endfunc
> > +
> > +
> > +func ff_ac3_sum_square_butterfly_int32_rvv, zve64x
> > +vsetvli t0, a3, e32, m2
> > +vle32.v v0, (a1)
> > +vle32.v v2, (a2)
> > +vadd.vv v4, v0, v2
> > +vsub.vv v6, v0, v2
> > +vwmul.vvv8, v0, v0
> > +vwmul.vvv12, v2, v2
> > +vwmul.vvv16, v4, v4
> > +vwmul.vvv20, v6, v6
> > +sub a3, a3, t0
> > +sllit0, t0, 2
> > +add a1, a1, t0
> > +add a2, a2, t0
> > +beq a3, x0, 2f
> > +1:
> > +vsetvli t0, a3, e32, m2
> > +vle32.v v0, (a1)
> > +vle32.v v2, (a2)
> > +vadd.vv v4, v0, v2
> > +vsub.vv v6, v0, v2
> > +vwmacc.vv   v8, v0, v0
> > +vwmacc.vv   v12, v2, v2
> > +vwmacc.vv   v16, v4, v4
> > +vwmacc.vv   v20, v6, v6
> > +sub a3, a3, t0
> > +sllit0, t0, 2
> > +add a1, a1, t0
> > +add a2, a2, t0
> > +bneza3, 1b
> > +2:
> > +vsetvli t0, x0, e64, m4
> > +vmv.s.x v24, x0
> > +vmv.s.x v25, x0
> > +vmv.s.x v26, x0
> > +vmv.s.x v27, x0
> > +vredsum.vs  v24, v8, v24
> > +vredsum.vs  v25, v12, v25
> > +vredsum.vs  v26, v16, v26
> > +vredsum.vs  v27, v20, v27
> 
> As far as I can tell this is a reserved encoding (c.f. RVV 1.0 §3.4.2), and I 
> believe that QEMU throws an Illegal instruction in this case. (I would check 
> but there are no checkasm test case for this function.) Does this actual work 
> on your simulator? Because if so, then your simulator is probably broken/
> buggy.
> 
RVV 1.0 §14 
Vector reduction operations take a vector register group of elements and a 
scalar held in 
element 0 of a vector register, and perform a reduction using some binary 
operator, to produce
a scalar result in element 0 of a vector register. The scalar input and output 
operands 
are held in element 0 of a single vector register, not a vector register group, 
so any vector
register can be the scalar source or destination of a vector reduction 
regardless of LMUL setting.

RVV 1.0 §16.1. Integer Scalar Move Instructions
The integer scalar read/write instructions transfer a single value between a 
scalar x register and
element 0 of a vector register. The instructions ignore LMUL and vector 
register groups.

According to the above, I think this coding is legal.

Actually, we have passed all the fate tests on the qemu 6.

[FFmpeg-devel] [PATCH 19/22] lavfi/vf_libplacebo: skip cache selectively per-input

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

It may be the case that we want to skip the single frame cache for some
inputs but not others.
---
 libavfilter/vf_libplacebo.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index a30b244843..b78391441a 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -182,7 +182,6 @@ typedef struct LibplaceboContext {
 float antiringing;
 int sigmoid;
 int skip_aa;
-int skip_cache;
 float polar_cutoff;
 int disable_linear;
 int disable_builtin;
@@ -471,7 +470,6 @@ static int update_settings(AVFilterContext *ctx)
 .num_hooks = s->num_hooks,
 
 .skip_anti_aliasing = s->skip_aa,
-.skip_caching_single_frame = s->skip_cache,
 .polar_cutoff = s->polar_cutoff,
 .disable_linear_scaling = s->disable_linear,
 .disable_builtin_scalers = s->disable_builtin,
@@ -881,8 +879,10 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 s->params.blend_params = NULL;
 for (int i = 0; i < s->nb_inputs; i++) {
 LibplaceboInput *in = &s->inputs[i];
+int high_fps = av_cmp_q(in->link->frame_rate, outlink->frame_rate) > 0;
 if (in->qstatus != PL_QUEUE_OK)
 continue;
+s->params.skip_caching_single_frame = high_fps;
 update_crops(ctx, in, &target, out->pts * av_q2d(outlink->time_base));
 pl_render_image_mix(in->renderer, &in->mix, &target, &s->params);
 s->params.skip_target_clearing = true;
@@ -1196,9 +1196,6 @@ static int libplacebo_config_output(AVFilterLink *outlink)
 if (s->fps.num) {
 outlink->frame_rate = s->fps;
 outlink->time_base = av_inv_q(s->fps);
-s->skip_cache = av_cmp_q(inlink->frame_rate, s->fps) > 0;
-} else {
-s->skip_cache = true;
 }
 
 /* Static variables */
-- 
2.41.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 18/22] lavfi/vf_libplacebo: set format list for all inputs

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

---
 libavfilter/vf_libplacebo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 427a15dc47..a30b244843 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1129,7 +1129,8 @@ static int libplacebo_query_format(AVFilterContext *ctx)
 goto fail;
 }
 
-RET(ff_formats_ref(infmts, &ctx->inputs[0]->outcfg.formats));
+for (int i = 0; i < s->nb_inputs; i++)
+RET(ff_formats_ref(infmts, &ctx->inputs[i]->outcfg.formats));
 RET(ff_formats_ref(outfmts, &ctx->outputs[0]->incfg.formats));
 return 0;
 
-- 
2.41.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 13/22] lavfi/vf_libplacebo: determine PTS of next frame from any input

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

When combining multiple inputs with different PTS and durations, in
input-timed mode, we emit one output frame for every input frame PTS,
from *any* input. So when combining a low FPS stream with a high FPS
stream, the output framerate would match the higher FPS, independent of
which order they are specified in.
---
 libavfilter/vf_libplacebo.c | 33 -
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 08bb468c6b..5903bd5a01 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -971,11 +971,11 @@ static int handle_input(AVFilterContext *ctx, 
LibplaceboInput *input)
 
 static int libplacebo_activate(AVFilterContext *ctx)
 {
-int ret;
+int ret, retry = 0;
 LibplaceboContext *s = ctx->priv;
 LibplaceboInput *in = &s->inputs[0];
 AVFilterLink *outlink = ctx->outputs[0];
-int64_t pts;
+int64_t pts, out_pts;
 
 FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
 pl_log_level_update(s->log, get_log_level());
@@ -987,24 +987,31 @@ static int libplacebo_activate(AVFilterContext *ctx)
 
 if (ff_outlink_frame_wanted(outlink)) {
 if (s->fps.num) {
-pts = outlink->frame_count_out;
-} else if (av_fifo_peek(in->out_pts, &pts, 1, 0) < 0) {
-/* No frames queued */
-if (in->status) {
-pts = in->status_pts;
-} else {
-ff_inlink_request_frame(in->link);
-return 0;
+out_pts = outlink->frame_count_out;
+} else {
+/* Determine the PTS of the next frame from any active input */
+out_pts = INT64_MAX;
+for (int i = 0; i < s->nb_inputs; i++) {
+LibplaceboInput *in = &s->inputs[i];
+if (av_fifo_peek(in->out_pts, &pts, 1, 0) >= 0) {
+out_pts = FFMIN(out_pts, pts);
+} else if (!in->status) {
+ff_inlink_request_frame(in->link);
+retry = true;
+}
 }
+
+if (retry) /* some inputs are incomplete */
+return 0;
 }
 
-if (s->status && pts >= s->status_pts) {
+if (s->status && out_pts >= s->status_pts) {
 ff_outlink_set_status(outlink, s->status, s->status_pts);
 return 0;
 }
 
 in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params(
-.pts= pts * av_q2d(outlink->time_base),
+.pts= out_pts * av_q2d(outlink->time_base),
 .radius = pl_frame_mix_radius(&s->params),
 .vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)),
 ));
@@ -1016,7 +1023,7 @@ static int libplacebo_activate(AVFilterContext *ctx)
 case PL_QUEUE_OK:
 if (!s->fps.num)
 av_fifo_drain2(in->out_pts, 1);
-return output_frame(ctx, pts);
+return output_frame(ctx, out_pts);
 case PL_QUEUE_ERR:
 return AVERROR_EXTERNAL;
 }
-- 
2.41.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 22/22] lavfi/vf_libplacebo: add nb_inputs option

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

To control the number of inputs.
---
 doc/filters.texi|  5 +
 libavfilter/vf_libplacebo.c | 25 ++---
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 2ea4083c3e..41cf4976cb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -16101,6 +16101,11 @@ to preserve the source colorimetry and size as best as 
it can, but it will
 apply any embedded film grain, dolby vision metadata or anamorphic SAR present
 in source frames.
 @table @option
+@item inputs
+Set the number of inputs. This can be used, alongside the @code{idx} variable,
+to allow placing/blending multiple inputs inside the output frame. This
+effectively enables functionality similar to @ref{hstack}, @ref{overlay}, etc.
+
 @item w
 @item h
 Set the output video dimension expression. Default values are @code{iw} and
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 7840677b06..cd3a156731 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -502,6 +502,7 @@ static int parse_shader(AVFilterContext *avctx, const void 
*shader, size_t len)
 }
 
 static void libplacebo_uninit(AVFilterContext *avctx);
+static int libplacebo_config_input(AVFilterLink *inlink);
 
 static int libplacebo_init(AVFilterContext *avctx)
 {
@@ -530,6 +531,17 @@ static int libplacebo_init(AVFilterContext *avctx)
 s->out_format = AV_PIX_FMT_NONE;
 }
 
+for (int i = 0; i < s->nb_inputs; i++) {
+AVFilterPad pad = {
+.name = av_asprintf("input%d", i),
+.type = AVMEDIA_TYPE_VIDEO,
+.config_props = &libplacebo_config_input,
+};
+if (!pad.name)
+return AVERROR(ENOMEM);
+RET(ff_append_inpad_free_name(avctx, &pad));
+}
+
 RET(update_settings(avctx));
 RET(av_expr_parse(&s->crop_x_pexpr, s->crop_x_expr, var_names,
   NULL, NULL, NULL, NULL, 0, s));
@@ -665,7 +677,6 @@ static int init_vulkan(AVFilterContext *avctx, const 
AVVulkanDeviceContext *hwct
 }
 
 /* Initialize inputs */
-s->nb_inputs = 1;
 s->inputs = av_calloc(s->nb_inputs, sizeof(*s->inputs));
 if (!s->inputs)
 return AVERROR(ENOMEM);
@@ -1250,6 +1261,7 @@ fail:
 #define DYNAMIC (STATIC | AV_OPT_FLAG_RUNTIME_PARAM)
 
 static const AVOption libplacebo_options[] = {
+{ "inputs", "Number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64 
= 1}, 1, INT_MAX, .flags = STATIC },
 { "w", "Output video frame width",  OFFSET(w_expr), AV_OPT_TYPE_STRING, 
{.str = "iw"}, .flags = STATIC },
 { "h", "Output video frame height", OFFSET(h_expr), AV_OPT_TYPE_STRING, 
{.str = "ih"}, .flags = STATIC },
 { "fps", "Output video frame rate", OFFSET(fps_string), 
AV_OPT_TYPE_STRING, {.str = "none"}, .flags = STATIC },
@@ -1441,14 +1453,6 @@ static const AVOption libplacebo_options[] = {
 
 AVFILTER_DEFINE_CLASS(libplacebo);
 
-static const AVFilterPad libplacebo_inputs[] = {
-{
-.name = "default",
-.type = AVMEDIA_TYPE_VIDEO,
-.config_props = &libplacebo_config_input,
-},
-};
-
 static const AVFilterPad libplacebo_outputs[] = {
 {
 .name = "default",
@@ -1465,10 +1469,9 @@ const AVFilter ff_vf_libplacebo = {
 .uninit = &libplacebo_uninit,
 .activate   = &libplacebo_activate,
 .process_command = &libplacebo_process_command,
-FILTER_INPUTS(libplacebo_inputs),
 FILTER_OUTPUTS(libplacebo_outputs),
 FILTER_QUERY_FUNC(libplacebo_query_format),
 .priv_class = &libplacebo_class,
 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
-.flags  = AVFILTER_FLAG_HWDEVICE,
+.flags  = AVFILTER_FLAG_HWDEVICE | AVFILTER_FLAG_DYNAMIC_INPUTS,
 };
-- 
2.41.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 12/22] lavfi/vf_libplacebo: handle multiple inputs

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

This commit still relies on a single input for PTS determination, to be
changed in the next commit.
---
 libavfilter/vf_libplacebo.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 3d812569f1..08bb468c6b 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -977,11 +977,13 @@ static int libplacebo_activate(AVFilterContext *ctx)
 AVFilterLink *outlink = ctx->outputs[0];
 int64_t pts;
 
-FF_FILTER_FORWARD_STATUS_BACK(outlink, in->link);
+FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
 pl_log_level_update(s->log, get_log_level());
 
-if ((ret = handle_input(ctx, in)) < 0)
-return ret;
+for (int i = 0; i < s->nb_inputs; i++) {
+if ((ret = handle_input(ctx, &s->inputs[i])) < 0)
+return ret;
+}
 
 if (ff_outlink_frame_wanted(outlink)) {
 if (s->fps.num) {
-- 
2.41.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 10/22] lavfi/vf_libplacebo: keep track of latest status globally

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

This field will effectively hold the most recent status set by any
input. Currently functionally equivalent to input->status, but will
change soon.
---
 libavfilter/vf_libplacebo.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index fbac1b0354..d6f19f166d 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -138,6 +138,8 @@ typedef struct LibplaceboContext {
 /* input state */
 LibplaceboInput *inputs;
 int nb_inputs;
+int64_t status_pts; ///< tracks status of most recently used input
+int status;
 
 /* settings */
 char *out_format_string;
@@ -941,6 +943,11 @@ static int handle_input(AVFilterContext *ctx, 
LibplaceboInput *input)
 pl_queue_push(input->queue, NULL); /* Signal EOF to pl_queue */
 input->status = status;
 input->status_pts = pts;
+if (pts >= s->status_pts) {
+/* Also propagate to output unless overwritten by later status 
change */
+s->status = status;
+s->status_pts = pts;
+}
 }
 
 return 0;
@@ -973,8 +980,8 @@ static int libplacebo_activate(AVFilterContext *ctx)
 }
 }
 
-if (in->status && pts >= in->status_pts) {
-ff_outlink_set_status(outlink, in->status, in->status_pts);
+if (s->status && pts >= s->status_pts) {
+ff_outlink_set_status(outlink, s->status, s->status_pts);
 return 0;
 }
 
-- 
2.41.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 11/22] lavfi/vf_libplacebo: support blending multiple inputs

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Subsequent inputs required frame blending to be enable, in order to not
overwrite the existing frame contents.

For output metadata, we implicitly copy the metadata of the *first*
available stream (falling back to the second stream if the first has
already reached EOF, and so on). This is done to resolve any conflicts
between inputs with differing metadata. So when e.g. input 1 is HDR and
output 2 is SDR, the output will be HDR, and vice versa. This logic
could probablly be improved by dynamically determining some "superior"
set of metadata, but I don't want to handle that complexity in this
series.
---
 libavfilter/vf_libplacebo.c | 24 
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index d6f19f166d..3d812569f1 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -784,12 +784,18 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 {
 int err = 0, ok, changed_csp;
 LibplaceboContext *s = ctx->priv;
-LibplaceboInput *in = &s->inputs[0];
 AVFilterLink *outlink = ctx->outputs[0];
 const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format);
-const AVFrame *ref = ref_frame(&in->mix);
 struct pl_frame target;
+const AVFrame *ref = NULL;
 AVFrame *out;
+
+/* Use the first active input as metadata reference */
+for (int i = 0; i < s->nb_inputs; i++) {
+const LibplaceboInput *in = &s->inputs[i];
+if (in->qstatus == PL_QUEUE_OK && (ref = ref_frame(&in->mix)))
+break;
+}
 if (!ref)
 return 0;
 
@@ -860,8 +866,18 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 goto fail;
 }
 
-update_crops(ctx, in, &target, out->pts * av_q2d(outlink->time_base));
-pl_render_image_mix(in->renderer, &in->mix, &target, &s->params);
+/* Draw first frame opaque, others with blending */
+s->params.skip_target_clearing = false;
+s->params.blend_params = NULL;
+for (int i = 0; i < s->nb_inputs; i++) {
+LibplaceboInput *in = &s->inputs[i];
+if (in->qstatus != PL_QUEUE_OK)
+continue;
+update_crops(ctx, in, &target, out->pts * av_q2d(outlink->time_base));
+pl_render_image_mix(in->renderer, &in->mix, &target, &s->params);
+s->params.skip_target_clearing = true;
+s->params.blend_params = &pl_alpha_overlay;
+}
 
 if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
 pl_unmap_avframe(s->gpu, &target);
-- 
2.41.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 21/22] lavfi/vf_libplacebo: set time_base/frame_rate dynamically

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Use the gcd of all input timebases to ensure PTS accuracy. For the
framerate, just pick the highest of all the inputs, under the assumption
that we will render frames with approximately this frequency. Of course,
this is not 100% accurate, in particular if the input frames are badly
misaligned. But this field is informational to begin with.

Importantly, it covers the "common" case of combining high FPS and low
FPS streams with aligned frames.
---
 libavfilter/vf_libplacebo.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 9b1526f19e..7840677b06 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1156,6 +1156,11 @@ static int libplacebo_config_input(AVFilterLink *inlink)
 return 0;
 }
 
+static inline AVRational max_q(AVRational a, AVRational b)
+{
+return av_cmp_q(a, b) < 0 ? b : a;
+}
+
 static int libplacebo_config_output(AVFilterLink *outlink)
 {
 int err;
@@ -1196,6 +1201,16 @@ static int libplacebo_config_output(AVFilterLink 
*outlink)
 if (s->fps.num) {
 outlink->frame_rate = s->fps;
 outlink->time_base = av_inv_q(s->fps);
+} else {
+outlink->frame_rate = avctx->inputs[0]->frame_rate;
+outlink->time_base = avctx->inputs[0]->time_base;
+for (int i = 1; i < s->nb_inputs; i++) {
+outlink->frame_rate = max_q(outlink->frame_rate,
+avctx->inputs[i]->frame_rate);
+outlink->time_base = av_gcd_q(outlink->time_base,
+  avctx->inputs[i]->time_base,
+  AV_TIME_BASE / 2, AV_TIME_BASE_Q);
+}
 }
 
 /* Static variables */
-- 
2.41.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 20/22] lavfi/vf_libplacebo: also skip cache if in FPS == out FPS

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Fixes an oversight in the previous code which should have been >=, not >.
---
 libavfilter/vf_libplacebo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index b78391441a..9b1526f19e 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -879,7 +879,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 s->params.blend_params = NULL;
 for (int i = 0; i < s->nb_inputs; i++) {
 LibplaceboInput *in = &s->inputs[i];
-int high_fps = av_cmp_q(in->link->frame_rate, outlink->frame_rate) > 0;
+int high_fps = av_cmp_q(in->link->frame_rate, outlink->frame_rate) >= 
0;
 if (in->qstatus != PL_QUEUE_OK)
 continue;
 s->params.skip_caching_single_frame = high_fps;
-- 
2.41.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 08/22] lavfi/vf_libplacebo: use correct link in update_crops()

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Instead of hard-coding input 0, pass the per-input structure and use the
link contained inside it.
---
 libavfilter/vf_libplacebo.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index b83df24a84..408fb3918a 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -715,19 +715,18 @@ static const AVFrame *ref_frame(const struct pl_frame_mix 
*mix)
 return NULL;
 }
 
-static void update_crops(AVFilterContext *ctx,
- struct pl_frame_mix *mix, struct pl_frame *target,
- double target_pts)
+static void update_crops(AVFilterContext *ctx, LibplaceboInput *in,
+ struct pl_frame *target, double target_pts)
 {
 LibplaceboContext *s = ctx->priv;
-const AVFrame *ref = ref_frame(mix);
+const AVFrame *ref = ref_frame(&in->mix);
 
-for (int i = 0; i < mix->num_frames; i++) {
+for (int i = 0; i < in->mix.num_frames; i++) {
 // Mutate the `pl_frame.crop` fields in-place. This is fine because we
 // own the entire pl_queue, and hence, the pointed-at frames.
-struct pl_frame *image = (struct pl_frame *) mix->frames[i];
+struct pl_frame *image = (struct pl_frame *) in->mix.frames[i];
 const AVFrame *src = pl_get_mapped_avframe(image);
-double image_pts = src->pts * av_q2d(ctx->inputs[0]->time_base);
+double image_pts = src->pts * av_q2d(in->link->time_base);
 
 /* Update dynamic variables */
 s->var_values[VAR_IN_T]   = s->var_values[VAR_T]  = image_pts;
@@ -851,7 +850,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 goto fail;
 }
 
-update_crops(ctx, &in->mix, &target, out->pts * 
av_q2d(outlink->time_base));
+update_crops(ctx, in, &target, out->pts * av_q2d(outlink->time_base));
 pl_render_image_mix(in->renderer, &in->mix, &target, &s->params);
 
 if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
-- 
2.41.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 09/22] lavfi/vf_libplacebo: replace s->input by dynamic array

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

For now, hard-coded to 1 element.
---
 libavfilter/vf_libplacebo.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 408fb3918a..fbac1b0354 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -136,7 +136,8 @@ typedef struct LibplaceboContext {
 pl_tex tex[4];
 
 /* input state */
-LibplaceboInput input;
+LibplaceboInput *inputs;
+int nb_inputs;
 
 /* settings */
 char *out_format_string;
@@ -660,7 +661,12 @@ static int init_vulkan(AVFilterContext *avctx, const 
AVVulkanDeviceContext *hwct
 }
 
 /* Initialize inputs */
-RET(input_init(avctx, avctx->inputs[0], &s->input));
+s->nb_inputs = 1;
+s->inputs = av_calloc(s->nb_inputs, sizeof(*s->inputs));
+if (!s->inputs)
+return AVERROR(ENOMEM);
+for (int i = 0; i < s->nb_inputs; i++)
+RET(input_init(avctx, avctx->inputs[i], &s->inputs[i]));
 
 /* fall through */
 fail:
@@ -677,7 +683,9 @@ static void libplacebo_uninit(AVFilterContext *avctx)
 pl_tex_destroy(s->gpu, &s->tex[i]);
 for (int i = 0; i < s->num_hooks; i++)
 pl_mpv_user_shader_destroy(&s->hooks[i]);
-input_uninit(&s->input);
+for (int i = 0; i < s->nb_inputs && s->inputs; i++)
+input_uninit(&s->inputs[i]);
+av_freep(&s->inputs);
 pl_vulkan_destroy(&s->vulkan);
 pl_log_destroy(&s->log);
 ff_vk_uninit(&s->vkctx);
@@ -774,7 +782,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 {
 int err = 0, ok, changed_csp;
 LibplaceboContext *s = ctx->priv;
-LibplaceboInput *in = &s->input;
+LibplaceboInput *in = &s->inputs[0];
 AVFilterLink *outlink = ctx->outputs[0];
 const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format);
 const AVFrame *ref = ref_frame(&in->mix);
@@ -942,7 +950,7 @@ static int libplacebo_activate(AVFilterContext *ctx)
 {
 int ret;
 LibplaceboContext *s = ctx->priv;
-LibplaceboInput *in = &s->input;
+LibplaceboInput *in = &s->inputs[0];
 AVFilterLink *outlink = ctx->outputs[0];
 int64_t pts;
 
-- 
2.41.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 07/22] lavfi/vf_libplacebo: factor out ref frame logic

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Instead of finding the ref frame in output_frame() and then passing its
signature to update_crops(), pull out the logic and invoke it a second
time inside update_crops().

This may seem wasteful at present, but will actually become required in
the future, since update_crops() runs on *every* input, and needs values
specific to that input (which the signature isn't), while output_frame()
is only interested in a single input. It's much easier to just split the
logic cleanly.
---
 libavfilter/vf_libplacebo.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 0289187b46..b83df24a84 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -706,11 +706,21 @@ fail:
 return err;
 }
 
+static const AVFrame *ref_frame(const struct pl_frame_mix *mix)
+{
+for (int i = 0; i < mix->num_frames; i++) {
+if (i+1 == mix->num_frames || mix->timestamps[i+1] > 0)
+return pl_get_mapped_avframe(mix->frames[i]);
+}
+return NULL;
+}
+
 static void update_crops(AVFilterContext *ctx,
  struct pl_frame_mix *mix, struct pl_frame *target,
- uint64_t ref_sig, double target_pts)
+ double target_pts)
 {
 LibplaceboContext *s = ctx->priv;
+const AVFrame *ref = ref_frame(mix);
 
 for (int i = 0; i < mix->num_frames; i++) {
 // Mutate the `pl_frame.crop` fields in-place. This is fine because we
@@ -745,7 +755,7 @@ static void update_crops(AVFilterContext *ctx,
 image->crop.x1 = image->crop.x0 + s->var_values[VAR_CROP_W];
 image->crop.y1 = image->crop.y0 + s->var_values[VAR_CROP_H];
 
-if (mix->signatures[i] == ref_sig) {
+if (src == ref) {
 /* Only update the target crop once, for the 'reference' frame */
 target->crop.x0 = av_expr_eval(s->pos_x_pexpr, s->var_values, 
NULL);
 target->crop.y0 = av_expr_eval(s->pos_y_pexpr, s->var_values, 
NULL);
@@ -768,25 +778,16 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 LibplaceboInput *in = &s->input;
 AVFilterLink *outlink = ctx->outputs[0];
 const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format);
+const AVFrame *ref = ref_frame(&in->mix);
 struct pl_frame target;
-const AVFrame *ref;
 AVFrame *out;
-uint64_t ref_sig;
-if (!in->mix.num_frames)
+if (!ref)
 return 0;
 
 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 if (!out)
 return AVERROR(ENOMEM);
 
-/* Use the last frame before current PTS value as reference */
-for (int i = 0; i < in->mix.num_frames; i++) {
-if (i && in->mix.timestamps[i] > 0.0f)
-break;
-ref = pl_get_mapped_avframe(in->mix.frames[i]);
-ref_sig = in->mix.signatures[i];
-}
-
 RET(av_frame_copy_props(out, ref));
 out->pts = pts;
 out->width = outlink->w;
@@ -850,7 +851,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 goto fail;
 }
 
-update_crops(ctx, &in->mix, &target, ref_sig, out->pts * 
av_q2d(outlink->time_base));
+update_crops(ctx, &in->mix, &target, out->pts * 
av_q2d(outlink->time_base));
 pl_render_image_mix(in->renderer, &in->mix, &target, &s->params);
 
 if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
-- 
2.41.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 06/22] lavif/vf_libplacebo: remove pl_frame_mix from output_frame_mix

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Instead, rename this function to `output_frame` and make it pull the
`pl_frame_mix` from the input structure. Step towards handling multiple
inputs.
---
 libavfilter/vf_libplacebo.c | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 4baa766bac..0289187b46 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -760,20 +760,19 @@ static void update_crops(AVFilterContext *ctx,
 }
 }
 
-/* Construct and emit an output frame for a given frame mix */
-static int output_frame_mix(AVFilterContext *ctx,
-struct pl_frame_mix *mix,
-int64_t pts)
+/* Construct and emit an output frame for a given timestamp */
+static int output_frame(AVFilterContext *ctx, int64_t pts)
 {
 int err = 0, ok, changed_csp;
 LibplaceboContext *s = ctx->priv;
+LibplaceboInput *in = &s->input;
 AVFilterLink *outlink = ctx->outputs[0];
 const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format);
 struct pl_frame target;
 const AVFrame *ref;
 AVFrame *out;
 uint64_t ref_sig;
-if (!mix->num_frames)
+if (!in->mix.num_frames)
 return 0;
 
 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
@@ -781,11 +780,11 @@ static int output_frame_mix(AVFilterContext *ctx,
 return AVERROR(ENOMEM);
 
 /* Use the last frame before current PTS value as reference */
-for (int i = 0; i < mix->num_frames; i++) {
-if (i && mix->timestamps[i] > 0.0f)
+for (int i = 0; i < in->mix.num_frames; i++) {
+if (i && in->mix.timestamps[i] > 0.0f)
 break;
-ref = pl_get_mapped_avframe(mix->frames[i]);
-ref_sig = mix->signatures[i];
+ref = pl_get_mapped_avframe(in->mix.frames[i]);
+ref_sig = in->mix.signatures[i];
 }
 
 RET(av_frame_copy_props(out, ref));
@@ -851,8 +850,8 @@ static int output_frame_mix(AVFilterContext *ctx,
 goto fail;
 }
 
-update_crops(ctx, mix, &target, ref_sig, out->pts * 
av_q2d(outlink->time_base));
-pl_render_image_mix(s->input.renderer, mix, &target, &s->params);
+update_crops(ctx, &in->mix, &target, ref_sig, out->pts * 
av_q2d(outlink->time_base));
+pl_render_image_mix(in->renderer, &in->mix, &target, &s->params);
 
 if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
 pl_unmap_avframe(s->gpu, &target);
@@ -984,7 +983,7 @@ static int libplacebo_activate(AVFilterContext *ctx)
 case PL_QUEUE_OK:
 if (!s->fps.num)
 av_fifo_drain2(in->out_pts, 1);
-return output_frame_mix(ctx, &in->mix, pts);
+return output_frame(ctx, pts);
 case PL_QUEUE_ERR:
 return AVERROR_EXTERNAL;
 }
-- 
2.41.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 17/22] lavfi/vf_libplacebo: add in_idx variable

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

To allow placing an input dynamically, as a function of the input index.
---
 doc/filters.texi| 2 ++
 libavfilter/vf_libplacebo.c | 9 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index a46357bfd8..2ea4083c3e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -16197,6 +16197,8 @@ the @option{crop_w}, @option{crop_h}, @option{crop_x}, 
@option{crop_y},
 also contain the following constants:
 
 @table @option
+@item in_idx, idx
+The (0-based) numeric index of the currently active input stream.
 @item crop_w, cw
 @item crop_h, ch
 The computed values of @option{crop_w} and @option{crop_h}.
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index f86493f4e2..427a15dc47 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -70,6 +70,7 @@ enum {
 };
 
 static const char *const var_names[] = {
+"in_idx", "idx",///< index of input
 "in_w", "iw",   ///< width  of the input video frame
 "in_h", "ih",   ///< height of the input video frame
 "out_w", "ow",  ///< width  of the output video frame
@@ -92,6 +93,7 @@ static const char *const var_names[] = {
 };
 
 enum var_name {
+VAR_IN_IDX, VAR_IDX,
 VAR_IN_W,   VAR_IW,
 VAR_IN_H,   VAR_IH,
 VAR_OUT_W,  VAR_OW,
@@ -115,6 +117,7 @@ enum var_name {
 
 /* per-input dynamic filter state */
 typedef struct LibplaceboInput {
+int idx;
 pl_renderer renderer;
 pl_queue queue;
 enum pl_queue_status qstatus;
@@ -574,7 +577,7 @@ static void unlock_queue(void *priv, uint32_t qf, uint32_t 
qidx)
 #endif
 
 static int input_init(AVFilterContext *avctx, AVFilterLink *link,
-  LibplaceboInput *input)
+  LibplaceboInput *input, int idx)
 {
 LibplaceboContext *s = avctx->priv;
 
@@ -584,6 +587,7 @@ static int input_init(AVFilterContext *avctx, AVFilterLink 
*link,
 input->queue = pl_queue_create(s->gpu);
 input->renderer = pl_renderer_create(s->log, s->gpu);
 input->link = link;
+input->idx = idx;
 
 return 0;
 }
@@ -668,7 +672,7 @@ static int init_vulkan(AVFilterContext *avctx, const 
AVVulkanDeviceContext *hwct
 if (!s->inputs)
 return AVERROR(ENOMEM);
 for (int i = 0; i < s->nb_inputs; i++)
-RET(input_init(avctx, avctx->inputs[i], &s->inputs[i]));
+RET(input_init(avctx, avctx->inputs[i], &s->inputs[i], i));
 
 /* fall through */
 fail:
@@ -739,6 +743,7 @@ static void update_crops(AVFilterContext *ctx, 
LibplaceboInput *in,
 double image_pts = src->pts * av_q2d(in->link->time_base);
 
 /* Update dynamic variables */
+s->var_values[VAR_IN_IDX] = s->var_values[VAR_IDX] = in->idx;
 s->var_values[VAR_IN_W]   = s->var_values[VAR_IW] = in->link->w;
 s->var_values[VAR_IN_H]   = s->var_values[VAR_IH] = in->link->h;
 s->var_values[VAR_A]  = (double) in->link->w / in->link->h;
-- 
2.41.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 16/22] lavfi/vf_libplacebo: make input-dependent vars dynamic

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Because these can differ based on the input, for multiple inputs.
---
 libavfilter/vf_libplacebo.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 5af8167bb3..f86493f4e2 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -739,6 +739,11 @@ static void update_crops(AVFilterContext *ctx, 
LibplaceboInput *in,
 double image_pts = src->pts * av_q2d(in->link->time_base);
 
 /* Update dynamic variables */
+s->var_values[VAR_IN_W]   = s->var_values[VAR_IW] = in->link->w;
+s->var_values[VAR_IN_H]   = s->var_values[VAR_IH] = in->link->h;
+s->var_values[VAR_A]  = (double) in->link->w / in->link->h;
+s->var_values[VAR_SAR]= in->link->sample_aspect_ratio.num ?
+av_q2d(in->link->sample_aspect_ratio) : 1.0;
 s->var_values[VAR_IN_T]   = s->var_values[VAR_T]  = image_pts;
 s->var_values[VAR_OUT_T]  = s->var_values[VAR_OT] = target_pts;
 s->var_values[VAR_N]  = ctx->outputs[0]->frame_count_out;
@@ -1191,13 +1196,8 @@ static int libplacebo_config_output(AVFilterLink 
*outlink)
 }
 
 /* Static variables */
-s->var_values[VAR_IN_W] = s->var_values[VAR_IW] = inlink->w;
-s->var_values[VAR_IN_H] = s->var_values[VAR_IH] = inlink->h;
 s->var_values[VAR_OUT_W]= s->var_values[VAR_OW] = outlink->w;
 s->var_values[VAR_OUT_H]= s->var_values[VAR_OH] = outlink->h;
-s->var_values[VAR_A]= (double) inlink->w / inlink->h;
-s->var_values[VAR_SAR]  = inlink->sample_aspect_ratio.num ?
-av_q2d(inlink->sample_aspect_ratio) : 1.0;
 s->var_values[VAR_DAR]  = outlink->sample_aspect_ratio.num ?
 av_q2d(outlink->sample_aspect_ratio) : 1.0;
 s->var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
-- 
2.41.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 15/22] lavfi/vf_libplacebo: generalize frame update to multiple inputs

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

In the event that some frame mixes are OK while others are not, the
priority goes:

1. Errors in updating any frame -> return error
2. Any input incomplete -> request frames and return
3. Any inputs OK -> ignore EOF streams and render remaining inputs
4. No inputs OK -> set output to most recent status

This logic ensures that we can continue rendering the remaining streams,
no matter which streams reach their end of life, until we have no
streams left at which point we forward the last EOF.
---
 libavfilter/vf_libplacebo.c | 52 -
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 896bdb4eb8..5af8167bb3 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -978,9 +978,8 @@ static void drain_input_pts(LibplaceboInput *in, int64_t 
until)
 
 static int libplacebo_activate(AVFilterContext *ctx)
 {
-int ret, retry = 0;
+int ret, ok = 0, retry = 0;
 LibplaceboContext *s = ctx->priv;
-LibplaceboInput *in = &s->inputs[0];
 AVFilterLink *outlink = ctx->outputs[0];
 int64_t pts, out_pts;
 
@@ -1012,26 +1011,43 @@ static int libplacebo_activate(AVFilterContext *ctx)
 return 0;
 }
 
-if (s->status && out_pts >= s->status_pts) {
-ff_outlink_set_status(outlink, s->status, s->status_pts);
-return 0;
-}
+/* Update all input queues to the chosen out_pts */
+for (int i = 0; i < s->nb_inputs; i++) {
+LibplaceboInput *in = &s->inputs[i];
+if (in->status && out_pts >= in->status_pts) {
+in->qstatus = PL_QUEUE_EOF;
+continue;
+}
 
-in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params(
-.pts= out_pts * av_q2d(outlink->time_base),
-.radius = pl_frame_mix_radius(&s->params),
-.vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)),
-));
+in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params(
+.pts= out_pts * av_q2d(outlink->time_base),
+.radius = pl_frame_mix_radius(&s->params),
+.vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)),
+));
+
+switch (in->qstatus) {
+case PL_QUEUE_MORE:
+ff_inlink_request_frame(in->link);
+retry = true;
+break;
+case PL_QUEUE_OK:
+ok = true;
+break;
+case PL_QUEUE_ERR:
+return AVERROR_EXTERNAL;
+}
+}
 
-switch (in->qstatus) {
-case PL_QUEUE_MORE:
-ff_inlink_request_frame(in->link);
+if (retry) {
 return 0;
-case PL_QUEUE_OK:
-drain_input_pts(in, out_pts);
+} else if (ok) {
+/* Got any valid frame mixes, drain PTS queue and render output */
+for (int i = 0; i < s->nb_inputs; i++)
+drain_input_pts(&s->inputs[i], out_pts);
 return output_frame(ctx, out_pts);
-case PL_QUEUE_ERR:
-return AVERROR_EXTERNAL;
+} else if (s->status) {
+ff_outlink_set_status(outlink, s->status, s->status_pts);
+return 0;
 }
 
 return AVERROR_BUG;
-- 
2.41.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 14/22] lavfi/vf_libplacebo: only drain actually used PTS

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

When combining multiple inputs, the output PTS may be less than the PTS
of the input. In this case, the current's code assumption of always
draining one value from the FIFO is incorrect. Replace by a smarter
function which drains only those PTS values that were actually consumed.
---
 libavfilter/vf_libplacebo.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 5903bd5a01..896bdb4eb8 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -969,6 +969,13 @@ static int handle_input(AVFilterContext *ctx, 
LibplaceboInput *input)
 return 0;
 }
 
+static void drain_input_pts(LibplaceboInput *in, int64_t until)
+{
+int64_t pts;
+while (av_fifo_peek(in->out_pts, &pts, 1, 0) >= 0 && pts <= until)
+av_fifo_drain2(in->out_pts, 1);
+}
+
 static int libplacebo_activate(AVFilterContext *ctx)
 {
 int ret, retry = 0;
@@ -1021,8 +1028,7 @@ static int libplacebo_activate(AVFilterContext *ctx)
 ff_inlink_request_frame(in->link);
 return 0;
 case PL_QUEUE_OK:
-if (!s->fps.num)
-av_fifo_drain2(in->out_pts, 1);
+drain_input_pts(in, out_pts);
 return output_frame(ctx, out_pts);
 case PL_QUEUE_ERR:
 return AVERROR_EXTERNAL;
-- 
2.41.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 05/22] lavfi/vf_libplacebo: move temporary vars into per-input struct

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Including the queue status, because these will need to be re-queried
inside output_frame_mix when that function is refactored to handle
multiple inputs.
---
 libavfilter/vf_libplacebo.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index beddd2f796..4baa766bac 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -117,6 +117,8 @@ enum var_name {
 typedef struct LibplaceboInput {
 pl_renderer renderer;
 pl_queue queue;
+enum pl_queue_status qstatus;
+struct pl_frame_mix mix; ///< temporary storage
 AVFilterLink *link;
 AVFifo *out_pts; ///< timestamps of wanted output frames
 int64_t status_pts;
@@ -952,9 +954,6 @@ static int libplacebo_activate(AVFilterContext *ctx)
 return ret;
 
 if (ff_outlink_frame_wanted(outlink)) {
-struct pl_frame_mix mix;
-enum pl_queue_status ret;
-
 if (s->fps.num) {
 pts = outlink->frame_count_out;
 } else if (av_fifo_peek(in->out_pts, &pts, 1, 0) < 0) {
@@ -972,20 +971,20 @@ static int libplacebo_activate(AVFilterContext *ctx)
 return 0;
 }
 
-ret = pl_queue_update(in->queue, &mix, pl_queue_params(
+in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params(
 .pts= pts * av_q2d(outlink->time_base),
 .radius = pl_frame_mix_radius(&s->params),
 .vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)),
 ));
 
-switch (ret) {
+switch (in->qstatus) {
 case PL_QUEUE_MORE:
 ff_inlink_request_frame(in->link);
 return 0;
 case PL_QUEUE_OK:
 if (!s->fps.num)
 av_fifo_drain2(in->out_pts, 1);
-return output_frame_mix(ctx, &mix, pts);
+return output_frame_mix(ctx, &in->mix, pts);
 case PL_QUEUE_ERR:
 return AVERROR_EXTERNAL;
 }
-- 
2.41.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 04/22] lavfi/vf_libplacebo: cosmetic

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

Assign local variable 'in' for 's->input' and replace 'inlink' by
'in->link' to avoid hard-coding ID 0 in more than one place.
---
 libavfilter/vf_libplacebo.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 879a3a0508..beddd2f796 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -941,14 +941,14 @@ static int libplacebo_activate(AVFilterContext *ctx)
 {
 int ret;
 LibplaceboContext *s = ctx->priv;
-AVFilterLink *inlink = ctx->inputs[0];
+LibplaceboInput *in = &s->input;
 AVFilterLink *outlink = ctx->outputs[0];
 int64_t pts;
 
-FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+FF_FILTER_FORWARD_STATUS_BACK(outlink, in->link);
 pl_log_level_update(s->log, get_log_level());
 
-if ((ret = handle_input(ctx, &s->input)) < 0)
+if ((ret = handle_input(ctx, in)) < 0)
 return ret;
 
 if (ff_outlink_frame_wanted(outlink)) {
@@ -957,22 +957,22 @@ static int libplacebo_activate(AVFilterContext *ctx)
 
 if (s->fps.num) {
 pts = outlink->frame_count_out;
-} else if (av_fifo_peek(s->input.out_pts, &pts, 1, 0) < 0) {
+} else if (av_fifo_peek(in->out_pts, &pts, 1, 0) < 0) {
 /* No frames queued */
-if (s->input.status) {
-pts = s->input.status_pts;
+if (in->status) {
+pts = in->status_pts;
 } else {
-ff_inlink_request_frame(inlink);
+ff_inlink_request_frame(in->link);
 return 0;
 }
 }
 
-if (s->input.status && pts >= s->input.status_pts) {
-ff_outlink_set_status(outlink, s->input.status, 
s->input.status_pts);
+if (in->status && pts >= in->status_pts) {
+ff_outlink_set_status(outlink, in->status, in->status_pts);
 return 0;
 }
 
-ret = pl_queue_update(s->input.queue, &mix, pl_queue_params(
+ret = pl_queue_update(in->queue, &mix, pl_queue_params(
 .pts= pts * av_q2d(outlink->time_base),
 .radius = pl_frame_mix_radius(&s->params),
 .vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)),
@@ -980,11 +980,11 @@ static int libplacebo_activate(AVFilterContext *ctx)
 
 switch (ret) {
 case PL_QUEUE_MORE:
-ff_inlink_request_frame(inlink);
+ff_inlink_request_frame(in->link);
 return 0;
 case PL_QUEUE_OK:
 if (!s->fps.num)
-av_fifo_drain2(s->input.out_pts, 1);
+av_fifo_drain2(in->out_pts, 1);
 return output_frame_mix(ctx, &mix, pts);
 case PL_QUEUE_ERR:
 return AVERROR_EXTERNAL;
-- 
2.41.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 03/22] lavfi/vf_libplacebo: move input handling to separate function

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

To be re-used once we support more than one input.
---
 libavfilter/vf_libplacebo.c | 45 -
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 10fd432745..879a3a0508 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -896,23 +896,19 @@ static void discard_frame(const struct pl_source_frame 
*src)
 av_frame_free(&avframe);
 }
 
-static int libplacebo_activate(AVFilterContext *ctx)
+static int handle_input(AVFilterContext *ctx, LibplaceboInput *input)
 {
 int ret, status;
 LibplaceboContext *s = ctx->priv;
-AVFilterLink *inlink = ctx->inputs[0];
 AVFilterLink *outlink = ctx->outputs[0];
 AVFrame *in;
 int64_t pts;
 
-FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
-pl_log_level_update(s->log, get_log_level());
-
-while ((ret = ff_inlink_consume_frame(inlink, &in)) > 0) {
+while ((ret = ff_inlink_consume_frame(input->link, &in)) > 0) {
 in->opaque = s;
-pl_queue_push(s->input.queue, &(struct pl_source_frame) {
-.pts = in->pts * av_q2d(inlink->time_base),
-.duration= in->duration * av_q2d(inlink->time_base),
+pl_queue_push(input->queue, &(struct pl_source_frame) {
+.pts = in->pts * av_q2d(input->link->time_base),
+.duration= in->duration * av_q2d(input->link->time_base),
 .first_field = pl_field_from_avframe(in),
 .frame_data  = in,
 .map = map_frame,
@@ -922,22 +918,39 @@ static int libplacebo_activate(AVFilterContext *ctx)
 
 if (!s->fps.num) {
 /* Internally queue an output frame for the same PTS */
-av_assert1(!av_cmp_q(inlink->time_base, outlink->time_base));
-av_fifo_write(s->input.out_pts, &in->pts, 1);
+pts = av_rescale_q(in->pts, input->link->time_base, 
outlink->time_base);
+av_fifo_write(input->out_pts, &pts, 1);
 }
 }
 
 if (ret < 0)
 return ret;
 
-if (!s->input.status && ff_inlink_acknowledge_status(inlink, &status, 
&pts)) {
-pts = av_rescale_q_rnd(pts, inlink->time_base, outlink->time_base,
+if (!input->status && ff_inlink_acknowledge_status(input->link, &status, 
&pts)) {
+pts = av_rescale_q_rnd(pts, input->link->time_base, outlink->time_base,
AV_ROUND_UP);
-pl_queue_push(s->input.queue, NULL); /* Signal EOF to pl_queue */
-s->input.status = status;
-s->input.status_pts = pts;
+pl_queue_push(input->queue, NULL); /* Signal EOF to pl_queue */
+input->status = status;
+input->status_pts = pts;
 }
 
+return 0;
+}
+
+static int libplacebo_activate(AVFilterContext *ctx)
+{
+int ret;
+LibplaceboContext *s = ctx->priv;
+AVFilterLink *inlink = ctx->inputs[0];
+AVFilterLink *outlink = ctx->outputs[0];
+int64_t pts;
+
+FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+pl_log_level_update(s->log, get_log_level());
+
+if ((ret = handle_input(ctx, &s->input)) < 0)
+return ret;
+
 if (ff_outlink_frame_wanted(outlink)) {
 struct pl_frame_mix mix;
 enum pl_queue_status ret;
-- 
2.41.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 02/22] lavfi/vf_libplacebo: move input-specific state to struct

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

In anticipation of a refactor which will enable multiple input support.

Note: the renderer is also input-specific because it maintains a frame
cache, HDR peak detection state and mixing cache, all of which are tied
to a specific input stream.
---
 libavfilter/vf_libplacebo.c | 80 -
 1 file changed, 52 insertions(+), 28 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index a048424cec..10fd432745 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -113,6 +113,16 @@ enum var_name {
 VAR_VARS_NB
 };
 
+/* per-input dynamic filter state */
+typedef struct LibplaceboInput {
+pl_renderer renderer;
+pl_queue queue;
+AVFilterLink *link;
+AVFifo *out_pts; ///< timestamps of wanted output frames
+int64_t status_pts;
+int status;
+} LibplaceboInput;
+
 typedef struct LibplaceboContext {
 /* lavfi vulkan*/
 FFVulkanContext vkctx;
@@ -121,14 +131,10 @@ typedef struct LibplaceboContext {
 pl_log log;
 pl_vulkan vulkan;
 pl_gpu gpu;
-pl_renderer renderer;
-pl_queue queue;
 pl_tex tex[4];
 
-/* filter state */
-AVFifo *out_pts; ///< timestamps of wanted output frames
-int64_t status_pts;
-int status;
+/* input state */
+LibplaceboInput input;
 
 /* settings */
 char *out_format_string;
@@ -536,8 +542,6 @@ static int libplacebo_init(AVFilterContext *avctx)
 RET(av_expr_parse(&s->pos_h_pexpr, s->pos_h_expr, var_names,
   NULL, NULL, NULL, NULL, 0, s));
 
-/* Initialize dynamic filter state */
-s->out_pts = av_fifo_alloc2(1, sizeof(int64_t), AV_FIFO_FLAG_AUTO_GROW);
 if (strcmp(s->fps_string, "none") != 0)
 RET(av_parse_video_rate(&s->fps, s->fps_string));
 
@@ -564,6 +568,28 @@ static void unlock_queue(void *priv, uint32_t qf, uint32_t 
qidx)
 }
 #endif
 
+static int input_init(AVFilterContext *avctx, AVFilterLink *link,
+  LibplaceboInput *input)
+{
+LibplaceboContext *s = avctx->priv;
+
+input->out_pts = av_fifo_alloc2(1, sizeof(int64_t), 
AV_FIFO_FLAG_AUTO_GROW);
+if (!input->out_pts)
+return AVERROR(ENOMEM);
+input->queue = pl_queue_create(s->gpu);
+input->renderer = pl_renderer_create(s->log, s->gpu);
+input->link = link;
+
+return 0;
+}
+
+static void input_uninit(LibplaceboInput *input)
+{
+pl_renderer_destroy(&input->renderer);
+pl_queue_destroy(&input->queue);
+av_fifo_freep2(&input->out_pts);
+}
+
 static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext 
*hwctx)
 {
 int err = 0;
@@ -620,10 +646,7 @@ static int init_vulkan(AVFilterContext *avctx, const 
AVVulkanDeviceContext *hwct
 goto fail;
 }
 
-/* Create the renderer */
 s->gpu = s->vulkan->gpu;
-s->renderer = pl_renderer_create(s->log, s->gpu);
-s->queue = pl_queue_create(s->gpu);
 
 /* Parse the user shaders, if requested */
 if (s->shader_bin_len)
@@ -634,6 +657,9 @@ static int init_vulkan(AVFilterContext *avctx, const 
AVVulkanDeviceContext *hwct
 RET(parse_shader(avctx, buf, buf_len));
 }
 
+/* Initialize inputs */
+RET(input_init(avctx, avctx->inputs[0], &s->input));
+
 /* fall through */
 fail:
 if (buf)
@@ -649,8 +675,7 @@ static void libplacebo_uninit(AVFilterContext *avctx)
 pl_tex_destroy(s->gpu, &s->tex[i]);
 for (int i = 0; i < s->num_hooks; i++)
 pl_mpv_user_shader_destroy(&s->hooks[i]);
-pl_renderer_destroy(&s->renderer);
-pl_queue_destroy(&s->queue);
+input_uninit(&s->input);
 pl_vulkan_destroy(&s->vulkan);
 pl_log_destroy(&s->log);
 ff_vk_uninit(&s->vkctx);
@@ -664,7 +689,6 @@ static void libplacebo_uninit(AVFilterContext *avctx)
 av_expr_free(s->pos_y_pexpr);
 av_expr_free(s->pos_w_pexpr);
 av_expr_free(s->pos_h_pexpr);
-av_fifo_freep2(&s->out_pts);
 }
 
 static int libplacebo_process_command(AVFilterContext *ctx, const char *cmd,
@@ -826,7 +850,7 @@ static int output_frame_mix(AVFilterContext *ctx,
 }
 
 update_crops(ctx, mix, &target, ref_sig, out->pts * 
av_q2d(outlink->time_base));
-pl_render_image_mix(s->renderer, mix, &target, &s->params);
+pl_render_image_mix(s->input.renderer, mix, &target, &s->params);
 
 if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
 pl_unmap_avframe(s->gpu, &target);
@@ -886,7 +910,7 @@ static int libplacebo_activate(AVFilterContext *ctx)
 
 while ((ret = ff_inlink_consume_frame(inlink, &in)) > 0) {
 in->opaque = s;
-pl_queue_push(s->queue, &(struct pl_source_frame) {
+pl_queue_push(s->input.queue, &(struct pl_source_frame) {
 .pts = in->pts * av_q2d(inlink->time_base),
 .duration= in->duration * av_q2d(inlink->time_base),
 .first_field = pl_field_from_avframe(in),
@@ -899,19 +923,19 @@ static int libplacebo_activate(AVFilterContext *ctx)
 if 

[FFmpeg-devel] [PATCH 01/22] lavfi/vf_libplacebo: drop redundant case

2023-06-16 Thread Niklas Haas
From: Niklas Haas 

If the input queue is EOF, then the s->status check should already have
covered it, and prevented the code from getting this far.

If we still hit this case for some reason, it's probably a bug. Better
to hit the AVERROR_BUG branch.
---
 libavfilter/vf_libplacebo.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 242c8a13f5..a048424cec 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -949,9 +949,6 @@ static int libplacebo_activate(AVFilterContext *ctx)
 if (!s->fps.num)
 av_fifo_drain2(s->out_pts, 1);
 return output_frame_mix(ctx, &mix, pts);
-case PL_QUEUE_EOF:
-ff_outlink_set_status(outlink, AVERROR_EOF, pts);
-return 0;
 case PL_QUEUE_ERR:
 return AVERROR_EXTERNAL;
 }
-- 
2.41.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/hls: Forward stream metadata from subdemuxer

2023-06-16 Thread Anton Khirnov
Quoting Armin Hasitzka (2023-06-08 13:37:12)
> Hi all,
> 
> just checking; do you consider this for merge into the upstream? It does
> feel like a lot of upside without any downside.

Looks ok, will push soonish if nobody objects.

-- 
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] avutil/hwcontext_qsv: register free function for device_derive

2023-06-16 Thread Tong Wu
When qsv device is created by device_derive, the ctx->free function is
not registered, causing potential memory leak because of not properly
closing the MFX session.

Signed-off-by: Tong Wu 
Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_qsv.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 4ed4242ddf..713dc90ffd 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -2094,6 +2094,9 @@ static int qsv_device_derive(AVHWDeviceContext *ctx,
  AVDictionary *opts, int flags)
 {
 mfxIMPL impl;
+
+ctx->free = qsv_device_free;
+
 impl = choose_implementation("hw_any", child_device_ctx->type);
 return qsv_device_derive_from_child(ctx, impl,
 child_device_ctx, flags);
-- 
2.41.0.windows.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".