Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/vaapi_encode_h265: Map HEVC AV REXT profile to VA REXT profile

2024-04-15 Thread Wang, Fei W
On Mon, 2024-04-15 at 23:07 +0100, Mark Thompson wrote:
> On 15/04/2024 02:21, Xiang, Haihao wrote:
> > On Ma, 2024-03-18 at 12:21 +0800, 
> > fei.w.wang-at-intel@ffmpeg.org wrote:
> > > From: Fei Wang 
> > > 
> > > There is no Main8/10 profile defined in HEVC REXT profiles. Use
> > > Main12
> > > which is compatible with 8/10bit.
> > > 
> > > Signed-off-by: Fei Wang 
> > > ---
> > >  libavcodec/vaapi_encode_h265.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/libavcodec/vaapi_encode_h265.c
> > > b/libavcodec/vaapi_encode_h265.c
> > > index c4aabbf5ed..43755e2188 100644
> > > --- a/libavcodec/vaapi_encode_h265.c
> > > +++ b/libavcodec/vaapi_encode_h265.c
> > > @@ -1305,12 +1305,12 @@ static av_cold int
> > > vaapi_encode_h265_configure(AVCodecContext *avctx)
> > >  
> > >  static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = {
> > >  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1,
> > > VAProfileHEVCMain   },
> > > -{ AV_PROFILE_HEVC_REXT, 8, 3, 1, 1,
> > > VAProfileHEVCMain   },
> > >  #if VA_CHECK_VERSION(0, 37, 0)
> > >  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1,
> > > VAProfileHEVCMain10 },
> > > -{ AV_PROFILE_HEVC_REXT,10, 3, 1, 1,
> > > VAProfileHEVCMain10 },
> > >  #endif
> > >  #if VA_CHECK_VERSION(1, 2, 0)
> > > +{ AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain12
> > > },
> > > +{ AV_PROFILE_HEVC_REXT,10, 3, 1, 1, VAProfileHEVCMain12
> > > },
> > >  { AV_PROFILE_HEVC_REXT,12, 3, 1, 1, VAProfileHEVCMain12
> > > },
> > >  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0,
> > > VAProfileHEVCMain422_10 },
> > >  { AV_PROFILE_HEVC_REXT,10, 3, 1, 0,
> > > VAProfileHEVCMain422_10 },
> > 
> > Patchset LGTM, I'll push it if there are no comments.
> 
> Why is this change helpful?

Together with 2/2 fix on the hw support VAAPI main12 decode and encode:

$ ffmpeg -hwaccel vaapi -f lavfi -i testsrc -vf 'format=nv12,hwupload'
-c:v hevc_vaapi -profile:v rext -vframes 30 -y out.mp4

$ ffmpeg -hwaccel vaapi -i out.mp4 -f null -
...
[hevc @ 0x55b4fda0a780] HEVC profile is not found.
[hevc @ 0x55b4fda0a780] No support for codec hevc profile 4.
[hevc @ 0x55b4fda0a780] Failed setup for format vaapi: hwaccel
initialisation returned error.

Same for p010le as input of encoder.

Thanks
Fei
> 
> We don't use the rext features allowed in these cases (unlike in the
> decoder where we have to support them), so Main / Main 10 encoders
> will be able to produce a compatible stream without pointlessly
> requiring Main 12 support which many devices do not have.
> 
> Thanks,
> 
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] ffmpeg: Carry streamid as metadata key 'id'

2024-04-15 Thread James Almer

On 4/15/2024 9:30 PM, Michael Niedermayer wrote:

On Mon, Apr 15, 2024 at 10:35:44AM +0200, Tomas Härdin wrote:

lör 2024-04-13 klockan 01:25 +0200 skrev Michael Niedermayer:

On Fri, Apr 12, 2024 at 11:40:47AM +0200, Tomas Härdin wrote:

This idea could be extended to other fields not presently
considered to
be metadata, that would be handy to treat as such.

I use the key "id" because ffprobe outputs id= for streamid.
Another
option could be to collect these types of metadata that go into
AVStream fields under a namespace like FFMPEG: or AVSTREAM: or
something, then delete all of them using AV_DICT_IGNORE_SUFFIX near
the
end of of_open() since they're for internal ffmpeg use.

The FATE change is just because av_dict() changes the order of
things
when elements are deleted.

/Tomas



  fftools/ffmpeg_demux.c  |    5 +++
  fftools/ffmpeg_mux_init.c   |   56
++--
  tests/ref/fate/matroska-stereo_mode |    6 +--
  3 files changed, 49 insertions(+), 18 deletions(-)
cd526b2292b6d7e3fb5739a04cf17fbe5f207f16  0001-ffmpeg-Carry-
streamid-as-metadata-key-id.patch
 From 7799f1b2eb8ab02e58118565f3e889fbe0d568a7 Mon Sep 17 00:00:00
2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Fri, 12 Apr 2024 10:34:12 +0200
Subject: [PATCH] ffmpeg: Carry streamid as metadata key 'id'

This allows using -map_metadata and -metadata to copy/set streamids
(PIDs).
---
  fftools/ffmpeg_demux.c  |  5 +++
  fftools/ffmpeg_mux_init.c   | 56 +

  tests/ref/fate/matroska-stereo_mode |  6 ++--
  3 files changed, 49 insertions(+), 18 deletions(-)


breaks:

./ffmpeg -i ~/videos/mm-short.mpg -vstats_file /tmp/vstats -bitexact
-map 0:1 -map 0:1 -map 0:2 -threads 6 -vcodec libx264 -vcodec libx264
-pass 1 -b:v:0 300k -b:v:1 900k -passlogfile:v:1 /tmp/video2 -
passlogfile:v:0 /tmp/video1 -t 1 -y -ab 128k  /tmp/x.ts

[mpegts @ 0x558d5e3b2140] Duplicate stream id 480


It's hardly strange if you map the same stream to the output twice that
you get duplicate streamids


ok but asking for a stream to be mapped twice is a valid case.
Ideally FFmpeg should not fail, it should resolve all parameters
within what is valid.
It could fail if the user explcicitly asks for invalid parameters ...


mpegts muxer could change the duplicate id for a free one. Afaik the 
field is documented as being modifiable by muxers. It could also do it 
internally.

___
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] ffmpeg: Carry streamid as metadata key 'id'

2024-04-15 Thread Michael Niedermayer
On Mon, Apr 15, 2024 at 10:35:44AM +0200, Tomas Härdin wrote:
> lör 2024-04-13 klockan 01:25 +0200 skrev Michael Niedermayer:
> > On Fri, Apr 12, 2024 at 11:40:47AM +0200, Tomas Härdin wrote:
> > > This idea could be extended to other fields not presently
> > > considered to
> > > be metadata, that would be handy to treat as such.
> > > 
> > > I use the key "id" because ffprobe outputs id= for streamid.
> > > Another
> > > option could be to collect these types of metadata that go into
> > > AVStream fields under a namespace like FFMPEG: or AVSTREAM: or
> > > something, then delete all of them using AV_DICT_IGNORE_SUFFIX near
> > > the
> > > end of of_open() since they're for internal ffmpeg use.
> > > 
> > > The FATE change is just because av_dict() changes the order of
> > > things
> > > when elements are deleted.
> > > 
> > > /Tomas
> > 
> > >  fftools/ffmpeg_demux.c  |    5 +++
> > >  fftools/ffmpeg_mux_init.c   |   56
> > > ++--
> > >  tests/ref/fate/matroska-stereo_mode |    6 +--
> > >  3 files changed, 49 insertions(+), 18 deletions(-)
> > > cd526b2292b6d7e3fb5739a04cf17fbe5f207f16  0001-ffmpeg-Carry-
> > > streamid-as-metadata-key-id.patch
> > > From 7799f1b2eb8ab02e58118565f3e889fbe0d568a7 Mon Sep 17 00:00:00
> > > 2001
> > > From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
> > > Date: Fri, 12 Apr 2024 10:34:12 +0200
> > > Subject: [PATCH] ffmpeg: Carry streamid as metadata key 'id'
> > > 
> > > This allows using -map_metadata and -metadata to copy/set streamids
> > > (PIDs).
> > > ---
> > >  fftools/ffmpeg_demux.c  |  5 +++
> > >  fftools/ffmpeg_mux_init.c   | 56 +
> > > 
> > >  tests/ref/fate/matroska-stereo_mode |  6 ++--
> > >  3 files changed, 49 insertions(+), 18 deletions(-)
> > 
> > breaks:
> > 
> > ./ffmpeg -i ~/videos/mm-short.mpg -vstats_file /tmp/vstats -bitexact
> > -map 0:1 -map 0:1 -map 0:2 -threads 6 -vcodec libx264 -vcodec libx264
> > -pass 1 -b:v:0 300k -b:v:1 900k -passlogfile:v:1 /tmp/video2 -
> > passlogfile:v:0 /tmp/video1 -t 1 -y -ab 128k  /tmp/x.ts
> > 
> > [mpegts @ 0x558d5e3b2140] Duplicate stream id 480
> 
> It's hardly strange if you map the same stream to the output twice that
> you get duplicate streamids

ok but asking for a stream to be mapped twice is a valid case.
Ideally FFmpeg should not fail, it should resolve all parameters
within what is valid.
It could fail if the user explcicitly asks for invalid parameters ...

thx

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

Does the universe only have a finite lifespan? No, its going to go on
forever, its just that you wont like living in it. -- Hiranya Peiri


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] avutil/opt: add AV_OPT_FLAG_FORCE_CONST

2024-04-15 Thread Michael Niedermayer
On Sun, Apr 14, 2024 at 10:35:57PM +0200, Timo Rothenpieler wrote:
> On 14.04.2024 22:30, Marton Balint wrote:
> > 
> > 
> > On Sun, 14 Apr 2024, Timo Rothenpieler wrote:
> > 
> > > ---
> > > doc/APIchanges  |  3 +++
> > > libavutil/opt.c | 14 ++
> > > libavutil/opt.h |  5 +
> > > libavutil/version.h |  2 +-
> > > 4 files changed, 23 insertions(+), 1 deletion(-)
> > 
> > Where do you intend to use this flag? So some justification or
> > description of your plans is missing from the commit message.
> 
> Some options in nvenc could be greatly simplified with it, where right now
> there's multiple if/switch-trees in the code, just to weed out invalid
> values.

This doesnt feel right.

The code would need to validate the actual value the same way it
checks min/max at least

avoptions allows the user to obtain a parameters address and set
it directly as well as set it without any AVOption

iam still not sure thats a good idea.
Why are the values not in a continous sequence of integers that can
be checked with min/max ?

thx

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

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin


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

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


Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/vaapi_encode_h265: Map HEVC AV REXT profile to VA REXT profile

2024-04-15 Thread Mark Thompson
On 15/04/2024 02:21, Xiang, Haihao wrote:
> On Ma, 2024-03-18 at 12:21 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
>> From: Fei Wang 
>>
>> There is no Main8/10 profile defined in HEVC REXT profiles. Use Main12
>> which is compatible with 8/10bit.
>>
>> Signed-off-by: Fei Wang 
>> ---
>>  libavcodec/vaapi_encode_h265.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
>> index c4aabbf5ed..43755e2188 100644
>> --- a/libavcodec/vaapi_encode_h265.c
>> +++ b/libavcodec/vaapi_encode_h265.c
>> @@ -1305,12 +1305,12 @@ static av_cold int
>> vaapi_encode_h265_configure(AVCodecContext *avctx)
>>  
>>  static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = {
>>  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain   },
>> -    { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain   },
>>  #if VA_CHECK_VERSION(0, 37, 0)
>>  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
>> -    { AV_PROFILE_HEVC_REXT,    10, 3, 1, 1, VAProfileHEVCMain10 },
>>  #endif
>>  #if VA_CHECK_VERSION(1, 2, 0)
>> +    { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain12 },
>> +    { AV_PROFILE_HEVC_REXT,    10, 3, 1, 1, VAProfileHEVCMain12 },
>>  { AV_PROFILE_HEVC_REXT,    12, 3, 1, 1, VAProfileHEVCMain12 },
>>  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 },
>>  { AV_PROFILE_HEVC_REXT,    10, 3, 1, 0, VAProfileHEVCMain422_10 },
> 
> Patchset LGTM, I'll push it if there are no comments.

Why is this change helpful?

We don't use the rext features allowed in these cases (unlike in the decoder 
where we have to support them), so Main / Main 10 encoders will be able to 
produce a compatible stream without pointlessly requiring Main 12 support which 
many devices do not have.

Thanks,

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

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


[FFmpeg-devel] [PATCH] avformat/mxfdec: only check index_edit_rate when calculating the index tables

2024-04-15 Thread Marton Balint
Commit ed49391961999f028e0bc55767d0eef6eeb15e49 started rejecting negative
index segment edit rates to avoid negative av_rescale parameters. There are two
problems with this:

1) there is already a validation for zero (uninitialized) rates later on
2) it rejects files with 0/0 index edit rates which do exist and we should
continue to support those

Let's solve these problems by removing the new check and extending the old
check for negative index edit rates. This should fix the original issue and
also restore support for 0/0 index edit rates.

Signed-off-by: Marton Balint 
---
 libavformat/mxfdec.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 233d614f78..71692c36bd 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1264,9 +1264,6 @@ static int mxf_read_index_table_segment(void *arg, 
AVIOContext *pb, int tag, int
 case 0x3F0B:
 segment->index_edit_rate.num = avio_rb32(pb);
 segment->index_edit_rate.den = avio_rb32(pb);
-if (segment->index_edit_rate.num <= 0 ||
-segment->index_edit_rate.den <= 0)
-return AVERROR_INVALIDDATA;
 av_log(NULL, AV_LOG_TRACE, "IndexEditRate %d/%d\n", 
segment->index_edit_rate.num,
 segment->index_edit_rate.den);
 break;
@@ -2135,7 +2132,7 @@ static int mxf_compute_index_tables(MXFContext *mxf)
 
 /* fix zero IndexDurations */
 for (k = 0; k < t->nb_segments; k++) {
-if (!t->segments[k]->index_edit_rate.num || 
!t->segments[k]->index_edit_rate.den) {
+if (t->segments[k]->index_edit_rate.num <= 0 || 
t->segments[k]->index_edit_rate.den <= 0) {
 av_log(mxf->fc, AV_LOG_WARNING, "IndexSID %i segment %i has 
invalid IndexEditRate\n",
t->index_sid, k);
 if (mxf_track)
-- 
2.35.3

___
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 0/3] avcodec/h264dec: Fix dropped frames when draining

2024-04-15 Thread Derek Buitenhuis
On 4/9/2024 4:15 PM, Derek Buitenhuis wrote:
> To me, it LGTM, but I would like someone more experience in H.264 internals
> to OK it, too - possibly Michael?

If there are no objections raised, I will merge this tomorrow.

- Derek
___
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/httpauth.c Support RFC7616 [Style fixed]

2024-04-15 Thread Stefano Sabatini
On date Monday 2024-04-15 02:32:14 +, �� | Eugene wrote:
> Update digest authentication in httpauth.c
> 
> - Refactor make_digest_auth() to support RFC 2617 and RFC 7617
> - Add support for SHA-256 and SHA-512/256 algorithms along with MD5
> - MD5 and SHA-256 tested, but SHA-512/256 untested due to lack of server
> - Replace AVMD5 structure with AVHashContext for hash algorithm flexibility
> - Rename update_md5_strings() to update_hash_strings() for consistency
> - Address coding style feedback from reviewer:
> 
> This is a feature update focused on digest authentication enhancements.
> Some lint issues in the existing code remain unaddressed in this patch.
> 
> Signed-off-by: Eugene-bitsensing 
> ---

>  libavformat/httpauth.c | 102 +
>  1 file changed, 53 insertions(+), 49 deletions(-)

add entry to Changelog?

> 
> diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c
> index 9780928357..2592140526 100644
> --- a/libavformat/httpauth.c
> +++ b/libavformat/httpauth.c
> @@ -24,7 +24,7 @@
>  #include "libavutil/avstring.h"
>  #include "internal.h"
>  #include "libavutil/random_seed.h"
> -#include "libavutil/md5.h"
> +#include "libavutil/hash.h"
>  #include "urldecode.h"
>  
>  static void handle_basic_params(HTTPAuthState *state, const char *key,
> @@ -117,35 +117,35 @@ void ff_http_auth_handle_header(HTTPAuthState *state, 
> const char *key,
>  }
>  }
>  
> -
> -static void update_md5_strings(struct AVMD5 *md5ctx, ...)
> +/* Generate hash string, updated to use AVHashContext to support other 
> algorithms */
> +static void update_hash_strings(struct AVHashContext *hash_ctx, ...)
>  {
>  va_list vl;
>  
> -va_start(vl, md5ctx);
> +va_start(vl, hash_ctx);
>  while (1) {
> -const char* str = va_arg(vl, const char*);
> +const char *str = va_arg(vl, const char*);
>  if (!str)
>  break;
> -av_md5_update(md5ctx, str, strlen(str));
> +av_hash_update(hash_ctx, (const uint8_t *)str, strlen(str));
>  }
>  va_end(vl);
>  }
>  
> -/* Generate a digest reply, according to RFC 2617. */
> +/* Generate a digest reply, according to RFC 2617. Update to support RFC 
> 7617*/
>  static char *make_digest_auth(HTTPAuthState *state, const char *username,
>const char *password, const char *uri,
>const char *method)
>  {
>  DigestParams *digest = >digest_params;
> -int len;
> +size_t len;
>  uint32_t cnonce_buf[2];
>  char cnonce[17];
>  char nc[9];
>  int i;
> -char A1hash[33], A2hash[33], response[33];
> -struct AVMD5 *md5ctx;
> -uint8_t hash[16];
> +char a1_hash[65], a2_hash[65], response[65];
> +struct AVHashContext *hash_ctx = NULL; // use AVHashContext for other 
> algorithm support
> +size_t len_hash = 33; // Modifiable hash length, MD5:32, SHA-2:64
>  char *authstr;
>  
>  digest->nc++;
> @@ -156,52 +156,56 @@ static char *make_digest_auth(HTTPAuthState *state, 
> const char *username,
>  cnonce_buf[i] = av_get_random_seed();
>  ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 
> 1);
>  
> -md5ctx = av_md5_alloc();
> -if (!md5ctx)
> -return NULL;
> -
> -av_md5_init(md5ctx);
> -update_md5_strings(md5ctx, username, ":", state->realm, ":", password, 
> NULL);
> -av_md5_final(md5ctx, hash);
> -ff_data_to_hex(A1hash, hash, 16, 1);
> -
> -if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) 
> {
> -} else if (!strcmp(digest->algorithm, "MD5-sess")) {
> -av_md5_init(md5ctx);
> -update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, 
> NULL);
> -av_md5_final(md5ctx, hash);
> -ff_data_to_hex(A1hash, hash, 16, 1);
> -} else {
> -/* Unsupported algorithm */
> -av_free(md5ctx);
> +/* Generate hash context by algorithm. */
> +const char *algorithm = digest->algorithm;

> +const char *hashing_algorithm;

nit++: to avoid semantic overlap I'd rather name this
selected_algorithm

> +if (!*algorithm) {
> +algorithm = "MD5";  // if empty, use MD5 as Default 
> +hashing_algorithm = "MD5";
> +} else if (av_stristr(algorithm, "MD5")) {
> +hashing_algorithm = "MD5";
> +} else if (av_stristr(algorithm, "sha256") || av_stristr(algorithm, 
> "sha-256")) {
> +hashing_algorithm = "SHA256";
> +len_hash = 65; // SHA-2: 64 characters.
> +} else if (av_stristr(algorithm, "sha512-256") || av_stristr(algorithm, 
> "sha-512-256")) {
> +hashing_algorithm = "SHA512_256";
> +len_hash = 65; // SHA-2: 64 characters.
> +} else { // Unsupported algorithm
>  return NULL;
>  }
>  
> -av_md5_init(md5ctx);
> -update_md5_strings(md5ctx, method, ":", uri, NULL);
> -av_md5_final(md5ctx, hash);
> -ff_data_to_hex(A2hash, hash, 16, 1);
> +int 

Re: [FFmpeg-devel] [PATCH 4/5] avformat/mxfdec: Check index_edit_rate

2024-04-15 Thread Marton Balint



On Mon, 15 Apr 2024, Tomas Härdin wrote:


sön 2024-04-14 klockan 22:55 +0200 skrev Marton Balint:



On Wed, 10 Apr 2024, Tomas Härdin wrote:

> tis 2024-04-09 klockan 22:58 +0200 skrev Marton Balint:
> > 
> > 
> > On Tue, 9 Apr 2024, Tomas Härdin wrote:
> > 
> > > mån 2024-04-08 klockan 21:46 +0200 skrev Marton Balint:
> > > > 
> > > > 
> > > > On Mon, 8 Apr 2024, Tomas Härdin wrote:
> > > > 
> > > > > tor 2024-04-04 klockan 00:51 +0200 skrev Michael

> > > > > Niedermayer:
> > > > > > Fixes: Assertion b >=0 failed at
> > > > > > libavutil/mathematics.c:62
> > > > > > Fixes: 67811/clusterfuzz-testcase-minimized-
> > > > > > ffmpeg_dem_MXF_fuzzer-
> > > > > > 5108429687422976
> > > > > > 
> > > > > > Found-by: continuous fuzzing process

> > > > > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > > > > Signed-off-by: Michael Niedermayer
> > > > > > 
> > > > > > ---
> > > > > >  libavformat/mxfdec.c | 3 +++
> > > > > >  1 file changed, 3 insertions(+)
> > > > > > 
> > > > > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c

> > > > > > index 04de4c1d5e3..233d614f783 100644
> > > > > > --- a/libavformat/mxfdec.c
> > > > > > +++ b/libavformat/mxfdec.c
> > > > > > @@ -1264,6 +1264,9 @@ static int
> > > > > > mxf_read_index_table_segment(void
> > > > > > *arg, AVIOContext *pb, int tag, int
> > > > > >  case 0x3F0B:
> > > > > >  segment->index_edit_rate.num = avio_rb32(pb);
> > > > > >  segment->index_edit_rate.den = avio_rb32(pb);
> > > > > > +    if (segment->index_edit_rate.num <= 0 ||
> > > > > > +    segment->index_edit_rate.den <= 0)
> > > > > > +    return AVERROR_INVALIDDATA;
> > > > > 
> > > > > mxf_compute_index_tables() has a check for index_edit_rate

> > > > > that
> > > > > you
> > > > > probably want to remove as well. It was introduced in
> > > > > c6fff3d,
> > > > > but
> > > > > the
> > > > > files it supposedly fixes aren't in FATE. We shouldn't
> > > > > encourage
> > > > > broken
> > > > > muxers.
> > > > 
> > > > I don't quite get what FATE has to do with it. And the

> > > > samples
> > > > mentioned 
> > > > in the patch has valid index segment edit rates, only they

> > > > are
> > > > different 
> > > > from the track edit rate, and the patch was intended to fix

> > > > that
> > > > case.
> > > 
> > > Then why does it check against 0/0?
> > 
> > Probably to avoid divison by zero.
> 
> I think it's safe to say that EditRates with zero in the numerator

> or
> denominator are not allowed. We currently default to 25/1 in this
> case
> for Tracks, but I am skeptical of this since it encourages broken
> muxers.

In general, I don't like the idea of rejecting everything which is
not 
following the standard to the letter. Decoding and demuxing should be

based on the "Robustness principle", as in being liberal in what we
accept 
and strict in what we generate.


No. We should not encourage proliferation of broken muxers. This leads
to compounding headaches down the line.


I am also not sure about your reasoning that rejecting files will
force 
vendors to fix their muxers, because the users will have to pay the
price 
for this approach. Users may well already have their archives full of
non-compliant files, their camera, phone, whatever is likely out of 
warranty/support, so they might not even be in a position to request 
anything from vendors.


These users can sign an SLA if they want support for these cameras.


You only want to support non-compliant files if the users pay for it?

Regards,
Marton
___
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] avcodec/x86/vvc/vvcdsp_init: fix linking error when configuring with --disable-ssse3 --disable-optimizations options

2024-04-15 Thread Wu Jianhua
> 发件人: Nuo Mi 
> 发送时间: 2024年3月3日 6:49
> 收件人: FFmpeg development discussions and patches
> 抄送: Wu Jianhua
> 主题: Re: [FFmpeg-devel] [PATCH] avcodec/x86/vvc/vvcdsp_init: fix linking error 
> when configuring with --disable-> > ssse3 --disable-optimizations options
> 
> Thank you, Jianhua.
> This patch mixes many things.
> Could you help split it into smaller, more atomic patches?
> For example, one for moving code blocks and another for fixing 
> --disable-ssse3.
> 

Sure. I sent the v2.

>  #define AVG_INIT(bd, opt) do {  \
> -c->inter.avg= bf(avg, bd, opt); \
> -c->inter.w_avg  = bf(w_avg, bd, opt);   \
> +c->inter.avg= bf(ff_vvc_avg, bd, opt);  \
> +c->inter.w_avg  = bf(ff_vvc_w_avg, bd, opt);\
> Why change the function scope to fix a compilation issue?

I use the same way that adds prototypes for the functions as HEVC DSP. Hence, 
the functions
cannot be declared with static and need the prefix to avoid naming conflict.



___
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 3/3] avcodec/x86/vvc/vvcdsp_init: fix linking error when configuring with --disable-ssse3 --disable-optimizations options

2024-04-15 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/x86/vvc/vvcdsp_init.c | 46 +---
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
index aef6699c35..985d750472 100644
--- a/libavcodec/x86/vvc/vvcdsp_init.c
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -88,6 +88,7 @@ AVG_PROTOTYPES(10, avx2)
 AVG_PROTOTYPES(12, avx2)
 
 #if ARCH_X86_64
+#if HAVE_SSE4_EXTERNAL
 #define FW_PUT(name, depth, opt) \
 void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const uint8_t 
*src, ptrdiff_t srcstride,\
  int height, const int8_t *hf, 
const int8_t *vf, int width)\
@@ -125,7 +126,9 @@ void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t 
*dst, const uint8_t *sr
 FW_PUT_SSE4( 8)
 FW_PUT_SSE4(10)
 FW_PUT_SSE4(12)
+#endif
 
+#if HAVE_AVX2_EXTERNAL
 #define FW_PUT_TAP_AVX2(n, bitd)\
 FW_PUT(n ## tap_h32,   bitd, avx2)  \
 FW_PUT(n ## tap_h64,   bitd, avx2)  \
@@ -161,6 +164,25 @@ FW_PUT_AVX2(12)
 FW_PUT_16BPC_AVX2(10)
 FW_PUT_16BPC_AVX2(12)
 
+#define AVG_FUNCS(bpc, bd, opt)
 \
+void bf(ff_vvc_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride,   
 \
+const int16_t *src0, const int16_t *src1, int width, int height)   
 \
+{  
 \
+BF(ff_vvc_avg, bpc, opt)(dst, dst_stride, src0, src1, width, height, (1 << 
bd)  - 1);   \
+}  
 \
+void bf(ff_vvc_w_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, 
 \
+const int16_t *src0, const int16_t *src1, int width, int height,   
 \
+int denom, int w0, int w1, int o0, int o1) 
 \
+{  
 \
+BF(ff_vvc_w_avg, bpc, opt)(dst, dst_stride, src0, src1, width, height, 
 \
+denom, w0, w1, o0, o1, (1 << bd)  - 1);
 \
+}
+
+AVG_FUNCS(8,  8,  avx2)
+AVG_FUNCS(16, 10, avx2)
+AVG_FUNCS(16, 12, avx2)
+#endif
+
 #define PEL_LINK(dst, C, W, idx1, idx2, name, D, opt)  
\
 dst[C][W][idx1][idx2] = ff_vvc_put_## name ## _ ## D ## _##opt;
\
 dst ## _uni[C][W][idx1][idx2] = ff_h2656_put_uni_ ## name ## _ ## D ## 
_##opt; \
@@ -226,27 +248,9 @@ FW_PUT_16BPC_AVX2(12)
 MC_TAP_LINKS_16BPC_AVX2(LUMA,   8, bd);  \
 MC_TAP_LINKS_16BPC_AVX2(CHROMA, 4, bd);
 
-#define AVG_FUNCS(bpc, bd, opt)
 \
-void bf(ff_vvc_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride,   
 \
-const int16_t *src0, const int16_t *src1, int width, int height)   
 \
-{  
 \
-BF(ff_vvc_avg, bpc, opt)(dst, dst_stride, src0, src1, width, height, (1 << 
bd)  - 1);   \
-}  
 \
-void bf(ff_vvc_w_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, 
 \
-const int16_t *src0, const int16_t *src1, int width, int height,   
 \
-int denom, int w0, int w1, int o0, int o1) 
 \
-{  
 \
-BF(ff_vvc_w_avg, bpc, opt)(dst, dst_stride, src0, src1, width, height, 
 \
-denom, w0, w1, o0, o1, (1 << bd)  - 1);
 \
-}
-
-AVG_FUNCS(8,  8,  avx2)
-AVG_FUNCS(16, 10, avx2)
-AVG_FUNCS(16, 12, avx2)
-
-#define AVG_INIT(bd, opt) do {  \
-c->inter.avg= bf(ff_vvc_avg, bd, opt);  \
-c->inter.w_avg  = bf(ff_vvc_w_avg, bd, opt);\
+#define AVG_INIT(bd, opt) do {   \
+c->inter.avg= bf(ff_vvc_avg, bd, opt);   \
+c->inter.w_avg  = bf(ff_vvc_w_avg, bd, opt); \
 } while (0)
 #endif
 
-- 
2.44.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 v2 2/3] avcodec/x86/vvc/vvcdsp_init: add avg prototypes

2024-04-15 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/x86/vvc/vvcdsp_init.c | 45 
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
index d9203f4d5f..aef6699c35 100644
--- a/libavcodec/x86/vvc/vvcdsp_init.c
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -63,6 +63,30 @@ PUT_TAP_PROTOTYPES(8, sse4)
 PUT_TAP_PROTOTYPES(4, avx2)
 PUT_TAP_PROTOTYPES(8, avx2)
 
+#define bf(fn, bd,  opt) fn##_##bd##_##opt
+#define BF(fn, bpc, opt) fn##_##bpc##bpc_##opt
+
+#define AVG_BPC_PROTOTYPES(bpc, opt)   
  \
+void BF(ff_vvc_avg, bpc, opt)(uint8_t *dst, ptrdiff_t dst_stride,  
  \
+const int16_t *src0, const int16_t *src1, intptr_t width, intptr_t height, 
intptr_t pixel_max);  \
+void BF(ff_vvc_w_avg, bpc, opt)(uint8_t *dst, ptrdiff_t dst_stride,
  \
+const int16_t *src0, const int16_t *src1, intptr_t width, intptr_t height, 
  \
+intptr_t denom, intptr_t w0, intptr_t w1,  intptr_t o0, intptr_t o1, 
intptr_t pixel_max);
+
+#define AVG_PROTOTYPES(bd, opt)
  \
+void bf(ff_vvc_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride,   
  \
+const int16_t *src0, const int16_t *src1, int width, int height);  
  \
+void bf(ff_vvc_w_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, 
  \
+const int16_t *src0, const int16_t *src1, int width, int height,   
  \
+int denom, int w0, int w1, int o0, int o1);
+
+AVG_BPC_PROTOTYPES( 8, avx2)
+AVG_BPC_PROTOTYPES(16, avx2)
+
+AVG_PROTOTYPES( 8, avx2)
+AVG_PROTOTYPES(10, avx2)
+AVG_PROTOTYPES(12, avx2)
+
 #if ARCH_X86_64
 #define FW_PUT(name, depth, opt) \
 void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const uint8_t 
*src, ptrdiff_t srcstride,\
@@ -202,23 +226,13 @@ FW_PUT_16BPC_AVX2(12)
 MC_TAP_LINKS_16BPC_AVX2(LUMA,   8, bd);  \
 MC_TAP_LINKS_16BPC_AVX2(CHROMA, 4, bd);
 
-#define bf(fn, bd,  opt) fn##_##bd##_##opt
-#define BF(fn, bpc, opt) fn##_##bpc##bpc_##opt
-
-#define AVG_BPC_FUNC(bpc, opt) 
 \
-void BF(ff_vvc_avg, bpc, opt)(uint8_t *dst, ptrdiff_t dst_stride,  
 \
-const int16_t *src0, const int16_t *src1, intptr_t width, intptr_t height, 
intptr_t pixel_max); \
-void BF(ff_vvc_w_avg, bpc, opt)(uint8_t *dst, ptrdiff_t dst_stride,
 \
-const int16_t *src0, const int16_t *src1, intptr_t width, intptr_t height, 
 \
-intptr_t denom, intptr_t w0, intptr_t w1,  intptr_t o0, intptr_t o1, 
intptr_t pixel_max);
-
 #define AVG_FUNCS(bpc, bd, opt)
 \
-static void bf(avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride,   
 \
+void bf(ff_vvc_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride,   
 \
 const int16_t *src0, const int16_t *src1, int width, int height)   
 \
 {  
 \
 BF(ff_vvc_avg, bpc, opt)(dst, dst_stride, src0, src1, width, height, (1 << 
bd)  - 1);   \
 }  
 \
-static void bf(w_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, 
 \
+void bf(ff_vvc_w_avg, bd, opt)(uint8_t *dst, ptrdiff_t dst_stride, 
 \
 const int16_t *src0, const int16_t *src1, int width, int height,   
 \
 int denom, int w0, int w1, int o0, int o1) 
 \
 {  
 \
@@ -226,16 +240,13 @@ static void bf(w_avg, bd, opt)(uint8_t *dst, ptrdiff_t 
dst_stride,
 denom, w0, w1, o0, o1, (1 << bd)  - 1);
 \
 }
 
-AVG_BPC_FUNC(8,   avx2)
-AVG_BPC_FUNC(16,  avx2)
-
 AVG_FUNCS(8,  8,  avx2)
 AVG_FUNCS(16, 10, avx2)
 AVG_FUNCS(16, 12, avx2)
 
 #define AVG_INIT(bd, opt) do {  \
-c->inter.avg= bf(avg, bd, opt); \
-c->inter.w_avg  = bf(w_avg, bd, opt);   \
+c->inter.avg= bf(ff_vvc_avg, bd, opt);  \
+c->inter.w_avg  = bf(ff_vvc_w_avg, bd, opt);\
 } while (0)
 #endif
 
-- 
2.44.0.windows.1

___

[FFmpeg-devel] [PATCH v2 1/3] avcodec/x86/vvc/vvcdsp_init: add put prototypes

2024-04-15 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/x86/vvc/vvcdsp_init.c | 35 +++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
index 23a3172c45..d9203f4d5f 100644
--- a/libavcodec/x86/vvc/vvcdsp_init.c
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -30,9 +30,42 @@
 #include "libavcodec/vvc/dsp.h"
 #include "libavcodec/x86/h26x/h2656dsp.h"
 
+#define PUT_PROTOTYPE(name, depth, opt) \
+void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const uint8_t 
*src, ptrdiff_t srcstride, int height, const int8_t *hf, const int8_t *vf, int 
width);
+
+#define PUT_PROTOTYPES(name, bitd, opt) \
+PUT_PROTOTYPE(name##2,   bitd, opt) \
+PUT_PROTOTYPE(name##4,   bitd, opt) \
+PUT_PROTOTYPE(name##8,   bitd, opt) \
+PUT_PROTOTYPE(name##12,  bitd, opt) \
+PUT_PROTOTYPE(name##16,  bitd, opt) \
+PUT_PROTOTYPE(name##24,  bitd, opt) \
+PUT_PROTOTYPE(name##32,  bitd, opt) \
+PUT_PROTOTYPE(name##48,  bitd, opt) \
+PUT_PROTOTYPE(name##64,  bitd, opt) \
+PUT_PROTOTYPE(name##128, bitd, opt)
+
+#define PUT_BPC_PROTOTYPES(name, opt) \
+PUT_PROTOTYPES(name,  8, opt) \
+PUT_PROTOTYPES(name, 10, opt) \
+PUT_PROTOTYPES(name, 12, opt)
+
+#define PUT_TAP_PROTOTYPES(n, opt) \
+PUT_BPC_PROTOTYPES(n##tap_h,  opt) \
+PUT_BPC_PROTOTYPES(n##tap_v,  opt) \
+PUT_BPC_PROTOTYPES(n##tap_hv, opt)
+
+PUT_BPC_PROTOTYPES(pixels, sse4)
+PUT_BPC_PROTOTYPES(pixels, avx2)
+
+PUT_TAP_PROTOTYPES(4, sse4)
+PUT_TAP_PROTOTYPES(8, sse4)
+PUT_TAP_PROTOTYPES(4, avx2)
+PUT_TAP_PROTOTYPES(8, avx2)
+
 #if ARCH_X86_64
 #define FW_PUT(name, depth, opt) \
-static void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const 
uint8_t *src, ptrdiff_t srcstride, \
+void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const uint8_t 
*src, ptrdiff_t srcstride,\
  int height, const int8_t *hf, 
const int8_t *vf, int width)\
 {  
\
 ff_h2656_put_## name ## _ ## depth ## _##opt(dst, 2 * MAX_PB_SIZE, src, 
srcstride, height, hf, vf, width); \
-- 
2.44.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] [PATCH 4/6 v2] avformat/http: Add support for Retry-After header

2024-04-15 Thread Stefano Sabatini
On date Monday 2024-04-15 17:49:33 +0100, Derek Buitenhuis wrote:
> 429 and 503 codes can, and often do (e.g. all Google Cloud
> Storage URLs can), return a Retry-After header with the error,
> indicating how long to wait, in seconds, before retrying again.
> If it is not respected by, for example, using our default backoff
> stratetgy instead, chances of success are very unlikely.
> 
> This adds an AVOption to respect that header.
> 
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavformat/http.c| 12 
>  libavformat/version.h |  2 +-
>  2 files changed, 13 insertions(+), 1 deletion(-)

missing doc/protocols.texi update
___
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/jni: fix mixed declaration and code

2024-04-15 Thread Matthieu Bouron
On Thu, Apr 04, 2024 at 10:07:25PM +0200, Matthieu Bouron wrote:
> ---
>  libavcodec/jni.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/jni.c b/libavcodec/jni.c
> index 1193c608c3..fcb4837413 100644
> --- a/libavcodec/jni.c
> +++ b/libavcodec/jni.c
> @@ -84,11 +84,13 @@ void *av_jni_get_java_vm(void *log_ctx)
>  int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx)
>  {
>  #if CONFIG_JNI
> +jobjectRefType type;
> +
>  JNIEnv *env = ff_jni_get_env(log_ctx);
>  if (!env)
>  return AVERROR(EINVAL);
>  
> -jobjectRefType type = (*env)->GetObjectRefType(env, app_ctx);
> +type = (*env)->GetObjectRefType(env, app_ctx);
>  if (type != JNIGlobalRefType) {
>  av_log(log_ctx, AV_LOG_ERROR, "Application context must be passed as 
> a global reference");
>  return AVERROR(EINVAL);
> -- 
> 2.44.0
> 

I will apply the patch in a few days if there is no objection.


-- 
Matthieu B.
___
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/6] avformat/http: Add support for Retry-After header

2024-04-15 Thread Derek Buitenhuis
On 4/15/2024 5:35 PM, James Almer wrote:
> Why strtoull for an int? If the value can't be negative, then make it 
> unsigned and use strtoul instead.
Done, v2 sent.

- Derek
___
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/6 v2] avformat/http: Add support for Retry-After header

2024-04-15 Thread Derek Buitenhuis
429 and 503 codes can, and often do (e.g. all Google Cloud
Storage URLs can), return a Retry-After header with the error,
indicating how long to wait, in seconds, before retrying again.
If it is not respected by, for example, using our default backoff
stratetgy instead, chances of success are very unlikely.

This adds an AVOption to respect that header.

Signed-off-by: Derek Buitenhuis 
---
 libavformat/http.c| 12 
 libavformat/version.h |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index e7603037f4..5ed481b63a 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -138,6 +138,8 @@ typedef struct HTTPContext {
 char *new_location;
 AVDictionary *redirect_cache;
 uint64_t filesize_from_content_range;
+int respect_retry_after;
+unsigned int retry_after;
 } HTTPContext;
 
 #define OFFSET(x) offsetof(HTTPContext, x)
@@ -176,6 +178,7 @@ static const AVOption options[] = {
 { "reconnect_on_http_error", "list of http status codes to reconnect on", 
OFFSET(reconnect_on_http_error), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
 { "reconnect_streamed", "auto reconnect streamed / non seekable streams", 
OFFSET(reconnect_streamed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
 { "reconnect_delay_max", "max reconnect delay in seconds after which to 
give up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, 
UINT_MAX/1000/1000, D },
+{ "respect_retry_after", "respect the Retry-After header when retrying 
connections", OFFSET(respect_retry_after), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 
1, D },
 { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 
}, 0, 2, D | E },
 { "resource", "The resource requested by a client", OFFSET(resource), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
 { "reply_code", "The http status code to return to a client", 
OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E},
@@ -386,6 +389,13 @@ redo:
 reconnect_delay > s->reconnect_delay_max)
 goto fail;
 
+if (s->respect_retry_after && s->retry_after > 0) {
+reconnect_delay = s->retry_after;
+if (reconnect_delay > s->reconnect_delay_max)
+goto fail;
+s->retry_after = 0;
+}
+
 av_log(h, AV_LOG_WARNING, "Will reconnect at %"PRIu64" in %d 
second(s).\n", off, reconnect_delay);
 ret = ff_network_sleep_interruptible(1000U * 1000 * reconnect_delay, 
>interrupt_callback);
 if (ret != AVERROR(ETIMEDOUT))
@@ -1231,6 +1241,8 @@ static int process_line(URLContext *h, char *line, int 
line_count, int *parsed_h
 parse_expires(s, p);
 } else if (!av_strcasecmp(tag, "Cache-Control")) {
 parse_cache_control(s, p);
+} else if (!av_strcasecmp(tag, "Retry-After")) {
+s->retry_after = strtoul(p, NULL, 10);
 }
 }
 return 1;
diff --git a/libavformat/version.h b/libavformat/version.h
index 7ff1483912..ee91990360 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFORMAT_VERSION_MINOR   3
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH 1/6] avutil/error: Add HTTP 429 Too Many Requests AVERROR code

2024-04-15 Thread Derek Buitenhuis
On 4/15/2024 5:43 PM, Derek Buitenhuis wrote:
> ---
>  libavutil/error.c   | 1 +
>  libavutil/error.h   | 1 +
>  libavutil/version.h | 2 +-
>  3 files changed, 3 insertions(+), 1 deletion(-)

This is a v2 I forgot to tag as v2. Woops.

- Derek
___
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/6] avutil/error: Add HTTP 429 Too Many Requests AVERROR code

2024-04-15 Thread Derek Buitenhuis
On 4/15/2024 5:31 PM, Andreas Rheinhardt wrote:
> Wouldn't you need to add a new entry to error_entries in error.c for this?

You are right, I missed that since grep failed me, as error.c uses macros, and
thus does not contain any AVERROR_HTTP_* directly.

I have sent a v2 for this patch.

- Derek
___
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/6] avutil/error: Add HTTP 429 Too Many Requests AVERROR code

2024-04-15 Thread Derek Buitenhuis
This is a common error code from e.g. CDNs or cloud storage, and
it is useful to be able to handle it differently to a generic
4XX code.

Its source is RFC6585.

Signed-off-by: Derek Buitenhuis 
---
 libavutil/error.c   | 1 +
 libavutil/error.h   | 1 +
 libavutil/version.h | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavutil/error.c b/libavutil/error.c
index 938a8bc000..7a9d760e76 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -61,6 +61,7 @@ static const struct error_entry error_entries[] = {
 { ERROR_TAG(HTTP_UNAUTHORIZED),  "Server returned 401 Unauthorized 
(authorization failed)" },
 { ERROR_TAG(HTTP_FORBIDDEN), "Server returned 403 Forbidden (access 
denied)" },
 { ERROR_TAG(HTTP_NOT_FOUND), "Server returned 404 Not Found"   
},
+{ ERROR_TAG(HTTP_TOO_MANY_REQUESTS), "Server returned 404 Too Many 
Requests"  },
 { ERROR_TAG(HTTP_OTHER_4XX), "Server returned 4XX Client Error, but 
not one of 40{0,1,3,4}" },
 { ERROR_TAG(HTTP_SERVER_ERROR),  "Server returned 5XX Server Error reply" 
},
 #if !HAVE_STRERROR_R
diff --git a/libavutil/error.h b/libavutil/error.h
index 0d3269aa6d..1efa86c4c1 100644
--- a/libavutil/error.h
+++ b/libavutil/error.h
@@ -79,6 +79,7 @@
 #define AVERROR_HTTP_UNAUTHORIZED  FFERRTAG(0xF8,'4','0','1')
 #define AVERROR_HTTP_FORBIDDEN FFERRTAG(0xF8,'4','0','3')
 #define AVERROR_HTTP_NOT_FOUND FFERRTAG(0xF8,'4','0','4')
+#define AVERROR_HTTP_TOO_MANY_REQUESTS FFERRTAG(0xF8,'4','2','9')
 #define AVERROR_HTTP_OTHER_4XX FFERRTAG(0xF8,'4','X','X')
 #define AVERROR_HTTP_SERVER_ERROR  FFERRTAG(0xF8,'5','X','X')
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 1f2bddc022..5de2d92146 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR  59
 #define LIBAVUTIL_VERSION_MINOR  15
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH 1/2] doc/utils/eval: clarify meaning of random* seed value

2024-04-15 Thread Stefano Sabatini
On date Thursday 2024-04-11 03:50:46 +0200, Michael Niedermayer wrote:
> On Wed, Apr 10, 2024 at 03:47:42PM +0200, Stefano Sabatini wrote:
> > Possible address trac issue:
> 
> > http://trac.ffmpeg.org/ticket/10763
> 
> Some of the things in this ticket are specific to the buggy LCG
> we no longer use
> 
> 
> > ---
> >  doc/utils.texi | 12 
> >  1 file changed, 12 insertions(+)
> 
> sounds ok
> 
> thx

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


Re: [FFmpeg-devel] [PATCH] avformat/lc3: Add file format for LC3/LC3plus transport

2024-04-15 Thread Stefano Sabatini
On date Saturday 2024-04-13 10:54:38 +0200, Stefano Sabatini wrote:
> On date Friday 2024-04-12 16:46:29 -0700, ffmpeg-devel Mailing List wrote:
> > Thanks.
> > 
> > On Fri, Apr 12, 2024 at 6:05 AM Stefano Sabatini  wrote:
> [...]
> > From 93c5628502a1f242043b39a18e83895d9067541e Mon Sep 17 00:00:00 2001
> > From: Antoine SOULIER 
> > Date: Thu, 4 Apr 2024 22:38:03 +
> > Subject: [PATCH] avformat/lc3: Add file format for LC3/LC3plus transport
> > 
> > A file format is described in Bluetooth SIG LC3 and ETSI TS 103 634, for
> > test purpose. This is the format implemented here.
> > ---
> >  Changelog|   1 +
> >  doc/muxers.texi  |   6 +
> >  libavformat/Makefile |   2 +
> >  libavformat/allformats.c |   2 +
> >  libavformat/lc3.c| 252 +++
> >  5 files changed, 263 insertions(+)
> >  create mode 100644 libavformat/lc3.c
> 
> Looks good to me.
> 
> Andreas, Paul, please comment. If I see no comments I'll push this in
> two/three days.

Finally applied, 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".


Re: [FFmpeg-devel] [PATCH 4/6] avformat/http: Add support for Retry-After header

2024-04-15 Thread James Almer

On 4/15/2024 1:27 PM, Derek Buitenhuis wrote:

429 and 503 codes can, and often do (e.g. all Google Cloud
Storage URLs can), return a Retry-After header with the error,
indicating how long to wait, in seconds, before retrying again.
If it is not respected by, for example, using our default backoff
stratetgy instead, chances of success are very unlikely.

This adds an AVOption to respect that header.

Signed-off-by: Derek Buitenhuis 
---
  libavformat/http.c| 12 
  libavformat/version.h |  2 +-
  2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index e7603037f4..8f092f108d 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -138,6 +138,8 @@ typedef struct HTTPContext {
  char *new_location;
  AVDictionary *redirect_cache;
  uint64_t filesize_from_content_range;
+int respect_retry_after;
+int retry_after;
  } HTTPContext;
  
  #define OFFSET(x) offsetof(HTTPContext, x)

@@ -176,6 +178,7 @@ static const AVOption options[] = {
  { "reconnect_on_http_error", "list of http status codes to reconnect on", 
OFFSET(reconnect_on_http_error), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
  { "reconnect_streamed", "auto reconnect streamed / non seekable streams", 
OFFSET(reconnect_streamed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
  { "reconnect_delay_max", "max reconnect delay in seconds after which to give 
up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, UINT_MAX/1000/1000, D },
+{ "respect_retry_after", "respect the Retry-After header when retrying 
connections", OFFSET(respect_retry_after), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, D },
  { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 
}, 0, 2, D | E },
  { "resource", "The resource requested by a client", OFFSET(resource), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
  { "reply_code", "The http status code to return to a client", 
OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E},
@@ -386,6 +389,13 @@ redo:
  reconnect_delay > s->reconnect_delay_max)
  goto fail;
  
+if (s->respect_retry_after && s->retry_after > 0) {

+reconnect_delay = s->retry_after;
+if (reconnect_delay > s->reconnect_delay_max)
+goto fail;
+s->retry_after = 0;
+}
+
  av_log(h, AV_LOG_WARNING, "Will reconnect at %"PRIu64" in %d 
second(s).\n", off, reconnect_delay);
  ret = ff_network_sleep_interruptible(1000U * 1000 * reconnect_delay, 
>interrupt_callback);
  if (ret != AVERROR(ETIMEDOUT))
@@ -1231,6 +1241,8 @@ static int process_line(URLContext *h, char *line, int 
line_count, int *parsed_h
  parse_expires(s, p);
  } else if (!av_strcasecmp(tag, "Cache-Control")) {
  parse_cache_control(s, p);
+} else if (!av_strcasecmp(tag, "Retry-After")) {
+s->retry_after = strtoull(p, NULL, 10);


Why strtoull for an int? If the value can't be negative, then make it 
unsigned and use strtoul instead.



  }
  }
  return 1;
diff --git a/libavformat/version.h b/libavformat/version.h
index 7ff1483912..ee91990360 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
  #include "version_major.h"
  
  #define LIBAVFORMAT_VERSION_MINOR   3

-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
  
  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

 LIBAVFORMAT_VERSION_MINOR, \

___
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/6] avutil/error: Add HTTP 429 Too Many Requests AVERROR code

2024-04-15 Thread Andreas Rheinhardt
Derek Buitenhuis:
> This is a common error code from e.g. CDNs or cloud storage, and
> it is useful to be able to handle it differently to a generic
> 4XX code.
> 
> Its source is RFC6585.
> 
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavutil/error.h   | 1 +
>  libavutil/version.h | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/error.h b/libavutil/error.h
> index 0d3269aa6d..1efa86c4c1 100644
> --- a/libavutil/error.h
> +++ b/libavutil/error.h
> @@ -79,6 +79,7 @@
>  #define AVERROR_HTTP_UNAUTHORIZED  FFERRTAG(0xF8,'4','0','1')
>  #define AVERROR_HTTP_FORBIDDEN FFERRTAG(0xF8,'4','0','3')
>  #define AVERROR_HTTP_NOT_FOUND FFERRTAG(0xF8,'4','0','4')
> +#define AVERROR_HTTP_TOO_MANY_REQUESTS FFERRTAG(0xF8,'4','2','9')
>  #define AVERROR_HTTP_OTHER_4XX FFERRTAG(0xF8,'4','X','X')
>  #define AVERROR_HTTP_SERVER_ERROR  FFERRTAG(0xF8,'5','X','X')
>  
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 1f2bddc022..5de2d92146 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -80,7 +80,7 @@
>  
>  #define LIBAVUTIL_VERSION_MAJOR  59
>  #define LIBAVUTIL_VERSION_MINOR  15
> -#define LIBAVUTIL_VERSION_MICRO 100
> +#define LIBAVUTIL_VERSION_MICRO 101
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> LIBAVUTIL_VERSION_MINOR, \

Wouldn't you need to add a new entry to error_entries in error.c for this?

- Andreas

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

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


[FFmpeg-devel] [PATCH 6/6] avformat/http: Add options to set the max number of connection retries

2024-04-15 Thread Derek Buitenhuis
Not every use case benefits from setting retries in terms of the backoff.

Signed-off-by: Derek Buitenhuis 
---
 libavformat/http.c| 12 +---
 libavformat/version.h |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index ce1af5f976..009536901a 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -140,6 +140,7 @@ typedef struct HTTPContext {
 uint64_t filesize_from_content_range;
 int respect_retry_after;
 int retry_after;
+int reconnect_max_retries;
 } HTTPContext;
 
 #define OFFSET(x) offsetof(HTTPContext, x)
@@ -178,6 +179,7 @@ static const AVOption options[] = {
 { "reconnect_on_http_error", "list of http status codes to reconnect on", 
OFFSET(reconnect_on_http_error), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
 { "reconnect_streamed", "auto reconnect streamed / non seekable streams", 
OFFSET(reconnect_streamed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
 { "reconnect_delay_max", "max reconnect delay in seconds after which to 
give up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, 
UINT_MAX/1000/1000, D },
+{ "reconnect_max_retries", "the max number of times to retry a 
connection", OFFSET(reconnect_max_retries), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 
INT_MAX, D },
 { "respect_retry_after", "respect the Retry-After header when retrying 
connections", OFFSET(respect_retry_after), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 
1, D },
 { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 
}, 0, 2, D | E },
 { "resource", "The resource requested by a client", OFFSET(resource), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
@@ -359,7 +361,7 @@ static int http_open_cnx(URLContext *h, AVDictionary 
**options)
 {
 HTTPAuthType cur_auth_type, cur_proxy_auth_type;
 HTTPContext *s = h->priv_data;
-int ret, auth_attempts = 0, redirects = 0;
+int ret, conn_attempts = 1, auth_attempts = 0, redirects = 0;
 int reconnect_delay = 0;
 uint64_t off;
 char *cached;
@@ -386,7 +388,8 @@ redo:
 ret = http_open_cnx_internal(h, options);
 if (ret < 0) {
 if (!http_should_reconnect(s, ret) ||
-reconnect_delay > s->reconnect_delay_max)
+reconnect_delay > s->reconnect_delay_max ||
+(s->reconnect_max_retries >= 0 && conn_attempts > 
s->reconnect_max_retries))
 goto fail;
 
 if (s->respect_retry_after && s->retry_after > 0) {
@@ -401,6 +404,7 @@ redo:
 if (ret != AVERROR(ETIMEDOUT))
 goto fail;
 reconnect_delay = 1 + 2 * reconnect_delay;
+conn_attempts++;
 
 /* restore the offset (http_connect resets it) */
 s->off = off;
@@ -1706,6 +1710,7 @@ static int http_read_stream(URLContext *h, uint8_t *buf, 
int size)
 int err, read_ret;
 int64_t seek_ret;
 int reconnect_delay = 0;
+int conn_attempt = 1;
 
 if (!s->hd)
 return AVERROR_EOF;
@@ -1734,7 +1739,7 @@ static int http_read_stream(URLContext *h, uint8_t *buf, 
int size)
 !(s->reconnect_at_eof && read_ret == AVERROR_EOF))
 break;
 
-if (reconnect_delay > s->reconnect_delay_max)
+if (reconnect_delay > s->reconnect_delay_max || 
(s->reconnect_max_retries >= 0 && conn_attempt > s->reconnect_max_retries))
 return AVERROR(EIO);
 
 av_log(h, AV_LOG_WARNING, "Will reconnect at %"PRIu64" in %d 
second(s), error=%s.\n", s->off, reconnect_delay, av_err2str(read_ret));
@@ -1742,6 +1747,7 @@ static int http_read_stream(URLContext *h, uint8_t *buf, 
int size)
 if (err != AVERROR(ETIMEDOUT))
 return err;
 reconnect_delay = 1 + 2*reconnect_delay;
+conn_attempt++;
 seek_ret = http_seek_internal(h, target, SEEK_SET, 1);
 if (seek_ret >= 0 && seek_ret != target) {
 av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRIu64".\n", 
target);
diff --git a/libavformat/version.h b/libavformat/version.h
index ee91990360..41dbd4ad01 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFORMAT_VERSION_MINOR   3
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MICRO 102
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.43.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/6] avformat/http: Rename attempts to auth_attempts

2024-04-15 Thread Derek Buitenhuis
This accurately reflects what it does, as per
e75bbcf493aeb549d04c56f49406aeee3950d93b.

Signed-off-by: Derek Buitenhuis 
---
 libavformat/http.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 8f092f108d..ce1af5f976 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -359,7 +359,7 @@ static int http_open_cnx(URLContext *h, AVDictionary 
**options)
 {
 HTTPAuthType cur_auth_type, cur_proxy_auth_type;
 HTTPContext *s = h->priv_data;
-int ret, attempts = 0, redirects = 0;
+int ret, auth_attempts = 0, redirects = 0;
 int reconnect_delay = 0;
 uint64_t off;
 char *cached;
@@ -409,10 +409,10 @@ redo:
 goto redo;
 }
 
-attempts++;
+auth_attempts++;
 if (s->http_code == 401) {
 if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) &&
-s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
+s->auth_state.auth_type != HTTP_AUTH_NONE && auth_attempts < 4) {
 ffurl_closep(>hd);
 goto redo;
 } else
@@ -420,7 +420,7 @@ redo:
 }
 if (s->http_code == 407) {
 if ((cur_proxy_auth_type == HTTP_AUTH_NONE || 
s->proxy_auth_state.stale) &&
-s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
+s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && auth_attempts < 
4) {
 ffurl_closep(>hd);
 goto redo;
 } else
@@ -449,7 +449,7 @@ redo:
 /* Restart the authentication process with the new target, which
  * might use a different auth mechanism. */
 memset(>auth_state, 0, sizeof(s->auth_state));
-attempts = 0;
+auth_attempts = 0;
 goto redo;
 }
 return 0;
@@ -2082,7 +2082,7 @@ static int http_proxy_open(URLContext *h, const char 
*uri, int flags)
 char hostname[1024], hoststr[1024];
 char auth[1024], pathbuf[1024], *path;
 char lower_url[100];
-int port, ret = 0, attempts = 0;
+int port, ret = 0, auth_attempts = 0;
 HTTPAuthType cur_auth_type;
 char *authstr;
 
@@ -2142,10 +2142,10 @@ redo:
 if (ret < 0)
 goto fail;
 
-attempts++;
+auth_attempts++;
 if (s->http_code == 407 &&
 (cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
-s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 2) {
+s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && auth_attempts < 2) {
 ffurl_closep(>hd);
 goto redo;
 }
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 4/6] avformat/http: Add support for Retry-After header

2024-04-15 Thread Derek Buitenhuis
429 and 503 codes can, and often do (e.g. all Google Cloud
Storage URLs can), return a Retry-After header with the error,
indicating how long to wait, in seconds, before retrying again.
If it is not respected by, for example, using our default backoff
stratetgy instead, chances of success are very unlikely.

This adds an AVOption to respect that header.

Signed-off-by: Derek Buitenhuis 
---
 libavformat/http.c| 12 
 libavformat/version.h |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index e7603037f4..8f092f108d 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -138,6 +138,8 @@ typedef struct HTTPContext {
 char *new_location;
 AVDictionary *redirect_cache;
 uint64_t filesize_from_content_range;
+int respect_retry_after;
+int retry_after;
 } HTTPContext;
 
 #define OFFSET(x) offsetof(HTTPContext, x)
@@ -176,6 +178,7 @@ static const AVOption options[] = {
 { "reconnect_on_http_error", "list of http status codes to reconnect on", 
OFFSET(reconnect_on_http_error), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
 { "reconnect_streamed", "auto reconnect streamed / non seekable streams", 
OFFSET(reconnect_streamed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
 { "reconnect_delay_max", "max reconnect delay in seconds after which to 
give up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, 
UINT_MAX/1000/1000, D },
+{ "respect_retry_after", "respect the Retry-After header when retrying 
connections", OFFSET(respect_retry_after), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 
1, D },
 { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 
}, 0, 2, D | E },
 { "resource", "The resource requested by a client", OFFSET(resource), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
 { "reply_code", "The http status code to return to a client", 
OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E},
@@ -386,6 +389,13 @@ redo:
 reconnect_delay > s->reconnect_delay_max)
 goto fail;
 
+if (s->respect_retry_after && s->retry_after > 0) {
+reconnect_delay = s->retry_after;
+if (reconnect_delay > s->reconnect_delay_max)
+goto fail;
+s->retry_after = 0;
+}
+
 av_log(h, AV_LOG_WARNING, "Will reconnect at %"PRIu64" in %d 
second(s).\n", off, reconnect_delay);
 ret = ff_network_sleep_interruptible(1000U * 1000 * reconnect_delay, 
>interrupt_callback);
 if (ret != AVERROR(ETIMEDOUT))
@@ -1231,6 +1241,8 @@ static int process_line(URLContext *h, char *line, int 
line_count, int *parsed_h
 parse_expires(s, p);
 } else if (!av_strcasecmp(tag, "Cache-Control")) {
 parse_cache_control(s, p);
+} else if (!av_strcasecmp(tag, "Retry-After")) {
+s->retry_after = strtoull(p, NULL, 10);
 }
 }
 return 1;
diff --git a/libavformat/version.h b/libavformat/version.h
index 7ff1483912..ee91990360 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFORMAT_VERSION_MINOR   3
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.43.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 3/6] avformat/http: Don't bail on parsing headers on "bad" HTTP codes

2024-04-15 Thread Derek Buitenhuis
Many "bad" HTTP codes like 429 and 503 may include important info in
their headers.

Also, in general, there is no purpose in bailing here.

Signed-off-by: Derek Buitenhuis 
---
 libavformat/http.c | 25 -
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index bbace2694f..e7603037f4 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1086,7 +1086,7 @@ static void parse_cache_control(HTTPContext *s, const 
char *p)
 }
 }
 
-static int process_line(URLContext *h, char *line, int line_count)
+static int process_line(URLContext *h, char *line, int line_count, int 
*parsed_http_code)
 {
 HTTPContext *s = h->priv_data;
 const char *auto_method =  h->flags & AVIO_FLAG_READ ? "POST" : "GET";
@@ -1166,6 +1166,8 @@ static int process_line(URLContext *h, char *line, int 
line_count)
 
 av_log(h, AV_LOG_TRACE, "http_code=%d\n", s->http_code);
 
+*parsed_http_code = 1;
+
 if ((ret = check_http_code(h, s->http_code, end)) < 0)
 return ret;
 }
@@ -1338,7 +1340,7 @@ static int http_read_header(URLContext *h)
 {
 HTTPContext *s = h->priv_data;
 char line[MAX_URL_SIZE];
-int err = 0;
+int err = 0, http_err = 0;
 
 av_freep(>new_location);
 s->expires = 0;
@@ -1346,18 +1348,31 @@ static int http_read_header(URLContext *h)
 s->filesize_from_content_range = UINT64_MAX;
 
 for (;;) {
+int parsed_http_code = 0;
+
 if ((err = http_get_line(s, line, sizeof(line))) < 0)
 return err;
 
 av_log(h, AV_LOG_TRACE, "header='%s'\n", line);
 
-err = process_line(h, line, s->line_count);
-if (err < 0)
-return err;
+err = process_line(h, line, s->line_count, _http_code);
+if (err < 0) {
+if (parsed_http_code) {
+http_err = err;
+} else {
+/* Prefer to return HTTP code error if we've already seen one. 
*/
+if (http_err)
+return http_err;
+else
+return err;
+}
+}
 if (err == 0)
 break;
 s->line_count++;
 }
+if (http_err)
+return http_err;
 
 // filesize from Content-Range can always be used, even if using chunked 
Transfer-Encoding
 if (s->filesize_from_content_range != UINT64_MAX)
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 2/6] avformat/http: Use AVERROR_HTTP_TOO_MANY_REQUESTS

2024-04-15 Thread Derek Buitenhuis
Added in thep previous commit.

Signed-off-by: Derek Buitenhuis 
---
 libavformat/http.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/http.c b/libavformat/http.c
index ed20359552..bbace2694f 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -286,6 +286,7 @@ static int http_should_reconnect(HTTPContext *s, int err)
 case AVERROR_HTTP_UNAUTHORIZED:
 case AVERROR_HTTP_FORBIDDEN:
 case AVERROR_HTTP_NOT_FOUND:
+case AVERROR_HTTP_TOO_MANY_REQUESTS:
 case AVERROR_HTTP_OTHER_4XX:
 status_group = "4xx";
 break;
@@ -522,6 +523,7 @@ int ff_http_averror(int status_code, int default_averror)
 case 401: return AVERROR_HTTP_UNAUTHORIZED;
 case 403: return AVERROR_HTTP_FORBIDDEN;
 case 404: return AVERROR_HTTP_NOT_FOUND;
+case 429: return AVERROR_HTTP_TOO_MANY_REQUESTS;
 default: break;
 }
 if (status_code >= 400 && status_code <= 499)
@@ -558,6 +560,10 @@ static int http_write_reply(URLContext* h, int status_code)
 reply_code = 404;
 reply_text = "Not Found";
 break;
+case 429:
+reply_code = 429;
+reply_text = "Too Many Requests";
+break;
 case 200:
 reply_code = 200;
 reply_text = "OK";
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 1/6] avutil/error: Add HTTP 429 Too Many Requests AVERROR code

2024-04-15 Thread Derek Buitenhuis
This is a common error code from e.g. CDNs or cloud storage, and
it is useful to be able to handle it differently to a generic
4XX code.

Its source is RFC6585.

Signed-off-by: Derek Buitenhuis 
---
 libavutil/error.h   | 1 +
 libavutil/version.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/error.h b/libavutil/error.h
index 0d3269aa6d..1efa86c4c1 100644
--- a/libavutil/error.h
+++ b/libavutil/error.h
@@ -79,6 +79,7 @@
 #define AVERROR_HTTP_UNAUTHORIZED  FFERRTAG(0xF8,'4','0','1')
 #define AVERROR_HTTP_FORBIDDEN FFERRTAG(0xF8,'4','0','3')
 #define AVERROR_HTTP_NOT_FOUND FFERRTAG(0xF8,'4','0','4')
+#define AVERROR_HTTP_TOO_MANY_REQUESTS FFERRTAG(0xF8,'4','2','9')
 #define AVERROR_HTTP_OTHER_4XX FFERRTAG(0xF8,'4','X','X')
 #define AVERROR_HTTP_SERVER_ERROR  FFERRTAG(0xF8,'5','X','X')
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 1f2bddc022..5de2d92146 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR  59
 #define LIBAVUTIL_VERSION_MINOR  15
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
-- 
2.43.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 0/6] HTTP rate limiting and retry improvements

2024-04-15 Thread Derek Buitenhuis
This patch set adds support for properly handling HTTP 429 codes,
and their rate limiting, which is widely used and is standardized.

Derek Buitenhuis (6):
  avutil/error: Add HTTP 429 Too Many Requests AVERROR code
  avformat/http: Use AVERROR_HTTP_TOO_MANY_REQUESTS
  avformat/http: Don't bail on parsing headers on "bad" HTTP codes
  avformat/http: Add support for Retry-After header
  avformat/http: Rename attempts to auth_attempts
  avformat/http: Add options to set the max number of connection retries

 libavformat/http.c| 69 +--
 libavformat/version.h |  2 +-
 libavutil/error.h |  1 +
 libavutil/version.h   |  2 +-
 4 files changed, 57 insertions(+), 17 deletions(-)

-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg_mux_init: allow mapping a stream group from one of the inputs

2024-04-15 Thread James Almer
Do this by extending the -stream_group option to accept a map key where the
value selects the input file and stream group.
The can and should set the streams in the output that the copied group will
reference, same as they'd do if they created a group from scratch.

Example command line:
ffmpeg -i input.iamf -map 0 -c:a copy -f null -stream_group \
map=0=0:st=0:st=1:st=2:st=3 -stream_group map=0=1:st=0:st=1:st=2:st=3

Signed-off-by: James Almer 
---
 fftools/ffmpeg_mux_init.c | 154 +-
 1 file changed, 152 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6d8bd5bcdf..a46b0628d8 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2232,11 +2232,137 @@ fail:
 return ret;
 }
 
+static int of_serialize_options(Muxer *mux, void *obj, AVBPrint *bp)
+{
+char *ptr;
+int ret;
+
+ret = av_opt_serialize(obj, 0, AV_OPT_SERIALIZE_SKIP_DEFAULTS | 
AV_OPT_SERIALIZE_SEARCH_CHILDREN,
+   , '=', ':');
+if (ret < 0) {
+av_log(mux, AV_LOG_ERROR, "Failed to serialize group\n");
+return ret;
+}
+
+av_bprintf(bp, "%s", ptr);
+ret = strlen(ptr);
+av_free(ptr);
+
+return ret;
+}
+
+#define SERIALIZE(parent, child) do {   \
+ret = of_serialize_options(mux, parent->child, bp); \
+if (ret < 0)\
+return ret; \
+} while (0)
+
+#define SERIALIZE_LOOP(parent, child, suffix, separator) do {\
+for (int j = 0; j < parent->nb_## child ## suffix; j++) {\
+av_bprintf(bp, separator#child "="); \
+SERIALIZE(parent, child ## suffix[j]);   \
+}\
+} while (0)
+
+static int64_t get_stream_group_index_from_id(Muxer *mux, int64_t id)
+{
+AVFormatContext *oc = mux->fc;
+
+for (unsigned i = 0; i < oc->nb_stream_groups; i++)
+if (oc->stream_groups[i]->id == id)
+return oc->stream_groups[i]->index;
+
+return AVERROR(EINVAL);
+}
+
+static int of_map_group(Muxer *mux, AVDictionary **dict, AVBPrint *bp, const 
char *map)
+{
+AVStreamGroup *stg;
+int ret, file_idx, stream_idx;
+char *ptr;
+
+file_idx = strtol(map, , 0);
+if (file_idx >= nb_input_files || file_idx < 0 || map == ptr) {
+av_log(mux, AV_LOG_ERROR, "Invalid input file index: %d.\n", file_idx);
+return AVERROR(EINVAL);
+}
+
+stream_idx = strtol(*ptr == '=' ? ptr + 1 : ptr, , 0);
+if (*ptr || stream_idx >= input_files[file_idx]->ctx->nb_stream_groups || 
stream_idx < 0) {
+av_log(mux, AV_LOG_ERROR, "Invalid input stream group index: %d.\n", 
stream_idx);
+return AVERROR(EINVAL);
+}
+
+stg = input_files[file_idx]->ctx->stream_groups[stream_idx];
+ret = of_serialize_options(mux, stg, bp);
+if (ret < 0)
+   return ret;
+
+ret = av_dict_parse_string(dict, bp->str, "=", ":", 0);
+if (ret < 0)
+av_log(mux, AV_LOG_ERROR, "Error parsing mapped group specification 
%s\n", ptr);
+av_dict_set_int(dict, "type", stg->type, 0);
+
+av_log(mux, AV_LOG_VERBOSE, "stg %s\n", bp->str);
+av_bprint_clear(bp);
+switch(stg->type) {
+case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: {
+AVIAMFAudioElement *audio_element = stg->params.iamf_audio_element;
+
+if (audio_element->demixing_info) {
+av_bprintf(bp, ",demixing=");
+SERIALIZE(audio_element, demixing_info);
+}
+if (audio_element->recon_gain_info) {
+av_bprintf(bp, ",recon_gain=");
+SERIALIZE(audio_element, recon_gain_info);
+}
+SERIALIZE_LOOP(audio_element, layer, s, ",");
+break;
+}
+case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: {
+AVIAMFMixPresentation *mix = stg->params.iamf_mix_presentation;
+
+for (int i = 0; i < mix->nb_submixes; i++) {
+AVIAMFSubmix *submix = mix->submixes[i];
+
+av_bprintf(bp, ",submix=");
+SERIALIZE(mix, submixes[i]);
+for (int j = 0; j < submix->nb_elements; j++) {
+AVIAMFSubmixElement *element = submix->elements[j];
+int64_t id = get_stream_group_index_from_id(mux, 
element->audio_element_id);
+
+if (id < 0) {
+av_log(mux, AV_LOG_ERROR, "Invalid or missing stream group 
index in"
+  "submix element");
+return id;
+}
+
+av_bprintf(bp, "|element=");
+SERIALIZE(submix, elements[j]);
+if (ret)
+av_bprintf(bp, ":");
+av_bprintf(bp, "stg=%"PRId64, id);
+}
+SERIALIZE_LOOP(submix, layout, s, "|");
+}
+  

[FFmpeg-devel] [PATCH] avcodec/nvenc: High bit depth encoding for HEVC

2024-04-15 Thread Diego Felix de Souza via ffmpeg-devel
From: Diego Felix de Souza 

Adding 10-bit encoding support for HEVC if the input is 8-bit. In
case of 8-bit input content, NVENC performs an internal CUDA 8 to
10-bit conversion of the input prior to encoding. Currently, only
AV1 supports encoding 8-bit content as 10-bit.

Signed-off-by: Diego Felix de Souza 
---
 libavcodec/nvenc.c  | 8 
 libavcodec/nvenc_hevc.c | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 794174a53f..c302cc7dc4 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -514,7 +514,7 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
 }

 ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_10BIT_ENCODE);
-if (IS_10BIT(ctx->data_pix_fmt) && ret <= 0) {
+if ((IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) && ret <= 0) {
 av_log(avctx, AV_LOG_WARNING, "10 bit encode not supported\n");
 return AVERROR(ENOSYS);
 }
@@ -1421,7 +1421,7 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext 
*avctx)
 }

 // force setting profile as main10 if input is 10 bit
-if (IS_10BIT(ctx->data_pix_fmt)) {
+if (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) {
 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN10_GUID;
 avctx->profile = AV_PROFILE_HEVC_MAIN_10;
 }
@@ -1435,8 +1435,8 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext 
*avctx)
 hevc->chromaFormatIDC = IS_YUV444(ctx->data_pix_fmt) ? 3 : 1;

 #ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
-hevc->inputBitDepth = hevc->outputBitDepth =
-IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
+hevc->inputBitDepth = IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : 
NV_ENC_BIT_DEPTH_8;
+hevc->outputBitDepth = (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) 
? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
 #else
 hevc->pixelBitDepthMinus8 = IS_10BIT(ctx->data_pix_fmt) ? 2 : 0;
 #endif
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index b949cb1bd7..02e9c9c8eb 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -183,6 +183,7 @@ static const AVOption options[] = {
 { "fullres",  "Two Pass encoding is enabled where first Pass is full 
resolution",
 0, 
   AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TWO_PASS_FULL_RESOLUTION },0, 
 0,   VE, .unit = "multipass" },
 #endif
+{ "highbitdepth", "Enable 10 bit encode for 8 bit 
input",OFFSET(highbitdepth),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
 #ifdef NVENC_HAVE_LDKFS
 { "ldkfs","Low delay key frame scale; Specifies the Scene Change 
frame size increase allowed in case of single frame VBV and CBR",
 OFFSET(ldkfs), 
   AV_OPT_TYPE_INT,   { .i64 = 0 }, 0, UCHAR_MAX, VE },
--
2.34.1

---
NVIDIA GmbH
Wuerselen
Amtsgericht Aachen
HRB 8361
Managing Directors: Rebecca Peters, Donald Robertson, Janet Hall, Ludwig von 
Reiche

---
This email message is for the sole use of the intended recipient(s) and may 
contain
confidential information.  Any unauthorized review, use, disclosure or 
distribution
is prohibited.  If you are not the intended recipient, please contact the 
sender by
reply email and destroy all copies of the original message.
---
___
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/vvc: Increase size of ctb_size_y

2024-04-15 Thread Nuo Mi
On Sat, Apr 13, 2024 at 9:55 PM James Almer  wrote:

> On 4/13/2024 7:55 AM, Frank Plowman wrote:
> > sps_log2_ctu_size_minus5 is between 0 and 2, with 3 reserved for future
> > use.  The VVC decoder allows sps_log2_ctu_size_minus5 to be 3, and so
> > ctb_size_y should be at least 16 bits to prevent overflows.  An
> > alternative patch would leave sps_log2_ctu_size_minus5 as 8 bits and
> > disallow sps_log2_ctu_size_minus5 = 3.
>
> The spec says a value of 3 should be ignored, which i assume means
> decoding is not meant to stop. So this patch is probably better than
> outright rejecting the value in CBS.

Applied.
Thank you, Frank and James.

>
> >
> > Signed-off-by: Frank Plowman 
> > ---
> >   libavcodec/vvc/ps.h | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/vvc/ps.h b/libavcodec/vvc/ps.h
> > index 78f1687fef..6656a06320 100644
> > --- a/libavcodec/vvc/ps.h
> > +++ b/libavcodec/vvc/ps.h
> > @@ -69,7 +69,7 @@ typedef struct VVCSPS {
> >   uint8_t bit_depth;
> ///< BitDepth
> >   uint8_t qp_bd_offset;
>  ///< QpBdOffset
> >   uint8_t ctb_log2_size_y;
> ///< CtbLog2SizeY
> > -uint8_t ctb_size_y;
>  ///< CtbSizeY
> > +uint16_tctb_size_y;
>  ///< CtbSizeY
> >   uint8_t min_cb_log2_size_y;
>  ///< MinCbLog2SizeY
> >   uint8_t min_cb_size_y;
> ///< MinCbSizeY
> >   uint8_t max_tb_size_y;
> ///< MaxTbSizeY
> ___
> 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/vvc/ps: reset sps_id_used on PS uninit

2024-04-15 Thread Nuo Mi
Mostly Harmless :)

On Mon, Apr 15, 2024 at 6:24 AM James Almer  wrote:

> On 4/13/2024 7:18 AM, Frank Plowman wrote:
> >
> >
> > On 09/04/2024 14:36, Nuo Mi wrote:
> >> On Mon, Apr 8, 2024 at 11:15 PM Frank Plowman 
> wrote:
> >>
> >>> On 08/04/2024 15:12, Nuo Mi wrote:
>  On Mon, Apr 8, 2024 at 4:37 PM Frank Plowman 
> >>> wrote:
> 
> > On 07/04/2024 15:48, James Almer wrote:
> >> On 4/7/2024 10:38 AM, Nuo Mi wrote:
> >>> On Sun, Apr 7, 2024 at 11:05 AM James Almer 
> >>> wrote:
> >>>
>  Signed-off-by: James Almer 
>  ---
> libavcodec/vvc/ps.c | 1 +
> 1 file changed, 1 insertion(+)
> 
>  diff --git a/libavcodec/vvc/ps.c b/libavcodec/vvc/ps.c
>  index 3c71c34bae..83ee75fb62 100644
>  --- a/libavcodec/vvc/ps.c
>  +++ b/libavcodec/vvc/ps.c
>  @@ -912,6 +912,7 @@ void ff_vvc_ps_uninit(VVCParamSets *ps)
> ff_refstruct_unref(>sps_list[i]);
> for (int i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
> ff_refstruct_unref(>pps_list[i]);
>  +ps->sps_id_used = 0;
> 
> >>> Hi James,
> >>> thank you for the patch.
> >>>
> >>> Is this really necessary?
> >>> vvc_ps_uninit will be called by vvc_decode_free,
> >>> We are not supposed to use any member of VVCParamSets after
> >>> vvc_decode_free.
> >>
> >> My bad, i thought it was also called on every flush() call.
> >>
> >> Something like the following:
> >>
> >>> diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
> >>> index eb447604fe..463536512e 100644
> >>> --- a/libavcodec/vvc/dec.c
> >>> +++ b/libavcodec/vvc/dec.c
> >>> @@ -963,6 +963,8 @@ static av_cold void
> >>> vvc_decode_flush(AVCodecContext *avctx)
> >>>   ff_vvc_flush_dpb(last);
> >>>   }
> >>>
> >>> +s->ps->sps_id_used = 0;
> >>> +
> >>>   s->eos = 1;
> >>>   }
> >>
> >> Should be done on FFCodec.flush() (like when seeking) as the
> previous
> >> state is no longer valid, right?
> >
> > Yes I agree, I think this is needed.  Cases where the random access
> > point has no leading pictures should be covered by the existing
> logic as
> > these always fall at the start of a CVS, but I think this is needed
> to
> > cover the case in which there are leading pictures.
> >
>  This patch isn't necessary.
>  Leading pictures won't carry SPS.
>  IDR, CRA, and GDR will carry SPS, but they will also start a new CVS,
> >>> which
>  will covered by the current logic.
> 
> >>>
> >>> I may be misunderstanding the spec, NoOutputBeforeRecoveryFlag is set
> >>> for pictures which have no leading pictures, no?  In any case take, for
> >>> instance, a CRA picture.  In most cases, CRA pictures have
> >>> NoOutputBeforeRecoveryFlag=0, therefore are not CLVSS pictures and
> >>> sps_id_used is not reset by the existing logic.  Do we not need to
> reset
> >>> sps_id_used when seeking to a CRA then?
> >>>
> >> After seeking, we'll set s->last_eos to 1.
> >> For a CRA, decode_recovery_flag will set
> s->no_output_before_recovery_flag
> >> to s->last_eos.
> >> So no_output_before_recovery_flag will be 1, not 0.
> >
> > I see, my mistake.  Yes in this case I do not think sps_id_used must be
> > explicitly reset.
>
> Should i revert the commit then, or is it harmless?
> This you discussed above could also be documented somewhere in the code.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 2/2] avutil/opt: add support for children objects in av_opt_serialize

2024-04-15 Thread James Almer

On 4/12/2024 8:16 PM, James Almer wrote:

Signed-off-by: James Almer 
---
  libavutil/opt.c   | 65 +--
  libavutil/opt.h   |  1 +
  libavutil/tests/opt.c | 47 +--
  tests/ref/fate/opt|  2 +-
  4 files changed, 90 insertions(+), 25 deletions(-)


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] libavformat/hlsenc: fix a memory leak in libavformat/hlsenc.c

2024-04-15 Thread Steven Liu
LuMingYin  于2024年4月13日周六 14:35写道:
>
> In the function 'hls_write_trailer' in the file 
> '/FFmpeg/libavformat/hlsenc.c', the variable named 'options' allocates a 
> block of dynamic memory in the 'av_dict_set' function, which is not freed on 
> error paths.
>
> Signed-off-by: LuMingYin 
> ---
>  libavformat/hlsenc.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index bde7230036..0e2843c6bc 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2757,6 +2757,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
>  filename = av_asprintf("%s", oc->url);
>  }
>  if (!filename) {
> +av_dict_free();
>  av_freep(_filename);
>  return AVERROR(ENOMEM);
>  }
> --
> 2.25.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

LGTM



Thanks
Steven
___
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] avcodec/libx264: bump minimum required version to 155

2024-04-15 Thread Niklas Haas
On Fri, 12 Apr 2024 12:45:44 +0200 Niklas Haas  wrote:
> On Tue, 09 Apr 2024 15:12:05 +0200 Niklas Haas  wrote:
> > From: Niklas Haas 
> > 
> > This version is seven years old, and present in Debian oldoldstable,
> > Ubuntu 20.04 and Leap 15.0.
> > 
> > Allows cleaning up the file substantially. In particular, this is
> > motivated by the desire to stop relying on init_static_data.
> > ---
> >  configure|  2 +-
> >  libavcodec/libx264.c | 52 ++--
> >  2 files changed, 8 insertions(+), 46 deletions(-)
> > 
> > diff --git a/configure b/configure
> > index f511fbae492..248ce2040d6 100755
> > --- a/configure
> > +++ b/configure
> > @@ -7007,7 +7007,7 @@ enabled libwebp   && {
> >  enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
> > 0.2.0" webp/encode.h WebPGetEncoderVersion
> >  enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder 
> > "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
> >  enabled libx264   && require_pkg_config libx264 x264 "stdint.h 
> > x264.h" x264_encoder_encode &&
> > - require_cpp_condition libx264 x264.h 
> > "X264_BUILD >= 122" && {
> > + require_cpp_condition libx264 x264.h 
> > "X264_BUILD >= 155" && {
> >   [ "$toolchain" != "msvc" ] ||
> >   require_cpp_condition libx264 x264.h 
> > "X264_BUILD >= 158"; } &&
> >   check_cpp_condition libx264_hdr10 x264.h 
> > "X264_BUILD >= 163" &&
> > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > index eadb20d2b39..2715f277f1f 100644
> > --- a/libavcodec/libx264.c
> > +++ b/libavcodec/libx264.c
> > @@ -270,11 +270,9 @@ static void reconfig_encoder(AVCodecContext *ctx, 
> > const AVFrame *frame)
> >  case AV_STEREO3D_FRAMESEQUENCE:
> >  fpa_type = 5;
> >  break;
> > -#if X264_BUILD >= 145
> >  case AV_STEREO3D_2D:
> >  fpa_type = 6;
> >  break;
> > -#endif
> >  default:
> >  fpa_type = -1;
> >  break;
> > @@ -394,14 +392,14 @@ static int setup_mb_info(AVCodecContext *ctx, 
> > x264_picture_t *pic,
> >  return 0;
> >  }
> >  
> > -static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic, int 
> > bit_depth,
> > +static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic,
> >   const AVFrame *frame, const uint8_t *data, size_t 
> > size)
> >  {
> >  X264Context *x4 = ctx->priv_data;
> >  
> >  int mbx = (frame->width + MB_SIZE - 1) / MB_SIZE;
> >  int mby = (frame->height + MB_SIZE - 1) / MB_SIZE;
> > -int qp_range = 51 + 6 * (bit_depth - 8);
> > +int qp_range = 51 + 6 * (x4->params.i_bitdepth - 8);
> >  int nb_rois;
> >  const AVRegionOfInterest *roi;
> >  uint32_t roi_size;
> > @@ -476,7 +474,7 @@ static int setup_frame(AVCodecContext *ctx, const 
> > AVFrame *frame,
> >  x264_sei_t *sei = >extra_sei;
> >  unsigned int sei_data_size = 0;
> >  int64_t wallclock = 0;
> > -int bit_depth, ret;
> > +int ret;
> >  AVFrameSideData *sd;
> >  AVFrameSideData *mbinfo_sd;
> >  
> > @@ -486,12 +484,7 @@ static int setup_frame(AVCodecContext *ctx, const 
> > AVFrame *frame,
> >  
> >  x264_picture_init(pic);
> >  pic->img.i_csp   = x4->params.i_csp;
> > -#if X264_BUILD >= 153
> > -bit_depth = x4->params.i_bitdepth;
> > -#else
> > -bit_depth = x264_bit_depth;
> > -#endif
> > -if (bit_depth > 8)
> > +if (x4->params.i_bitdepth > 8)
> >  pic->img.i_csp |= X264_CSP_HIGH_DEPTH;
> >  pic->img.i_plane = av_pix_fmt_count_planes(ctx->pix_fmt);
> >  
> > @@ -564,7 +557,7 @@ static int setup_frame(AVCodecContext *ctx, const 
> > AVFrame *frame,
> >  
> >  sd = av_frame_get_side_data(frame, AV_FRAME_DATA_REGIONS_OF_INTEREST);
> >  if (sd) {
> > -ret = setup_roi(ctx, pic, bit_depth, frame, sd->data, sd->size);
> > +ret = setup_roi(ctx, pic, frame, sd->data, sd->size);
> >  if (ret < 0)
> >  goto fail;
> >  }
> > @@ -1109,9 +1102,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
> >  x4->params.p_log_private= avctx;
> >  x4->params.i_log_level  = X264_LOG_DEBUG;
> >  x4->params.i_csp= convert_pix_fmt(avctx->pix_fmt);
> > -#if X264_BUILD >= 153
> >  x4->params.i_bitdepth   = 
> > av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
> > -#endif
> >  
> >  PARSE_X264_OPT("weightp", wpredp);
> >  
> > @@ -1180,11 +1171,10 @@ static av_cold int X264_init(AVCodecContext *avctx)
> >  else if (x4->params.i_level_idc > 0) {
> >  int i;
> >  int mbn = AV_CEIL_RSHIFT(avctx->width, 4) * 
> > AV_CEIL_RSHIFT(avctx->height, 4);
> > -int scale = X264_BUILD < 129 ? 384 : 1;
> >  
> >  for (i = 0; i >  if 

[FFmpeg-devel] ffmpeg can't get video rotate info

2024-04-15 Thread new...@163.com
ffmpeg can't get video rotate info, 5.0 - 6.1.1 version all can't get video 
rotate info 
tag = av_dict_get(m_pVideoSt->metadata, "rotate", tag, 0);
if (tag)
{
m_Rotate = atoi(tag->value);
}

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

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


[FFmpeg-devel] [PATCH 4/4] avcodec/amfenc: GPU driver version check

2024-04-15 Thread Araz Iusubov
Implemented gpu driver check.
10-bit patch works incorrectly on driver version lower than 23.30.

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

diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 634eeea48f..7463251529 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -215,6 +215,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 : avctx->pix_fmt;
 color_depth = AMF_COLOR_BIT_DEPTH_8;
 if (pix_fmt == AV_PIX_FMT_P010) {
+AMF_RETURN_IF_FALSE(ctx, ctx->version >= AMF_MAKE_FULL_VERSION(1, 4, 
32, 0), AVERROR_UNKNOWN, "HEVC 10-bit encoder is not supported by AMD GPU 
drivers versions lower than 23.30.\n");
 color_depth = AMF_COLOR_BIT_DEPTH_10;
 }
 
-- 
2.43.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 3/4] avcodec/amfenc: add 10 bit encoding in av1_amf

2024-04-15 Thread Araz Iusubov
From: Evgeny Pavlov 

v2: refactored after review

Signed-off-by: Evgeny Pavlov 
Co-authored-by: Dmitrii Ovchinnikov 
---
 libavcodec/amfenc.c |  2 ++
 libavcodec/amfenc_av1.c | 22 ++
 2 files changed, 24 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 068bb53002..f1b76bd6aa 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -826,6 +826,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
 case AV_CODEC_ID_HEVC:
 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+case AV_CODEC_ID_AV1:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_INPUT_HDR_METADATA, hdrmeta_buffer); break;
 }
 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
 }
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 8f13aea29e..634eeea48f 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -165,6 +165,9 @@ static av_cold int amf_encode_init_av1(AVCodecContext* 
avctx)
 AMFGuid guid;
 AMFRate framerate;
 AMFSize framesize = AMFConstructSize(avctx->width, 
avctx->height);
+amf_int64   color_depth;
+amf_int64   color_profile;
+enumAVPixelFormat pix_fmt;
 
 
 
@@ -203,6 +206,25 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_PROFILE, profile);
 
+/// Color profile
+color_profile = ff_amf_get_color_profile(avctx);
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
+
+/// Color Depth
+pix_fmt = avctx->hw_frames_ctx ? 
((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format
+: avctx->pix_fmt;
+color_depth = AMF_COLOR_BIT_DEPTH_8;
+if (pix_fmt == AV_PIX_FMT_P010) {
+color_depth = AMF_COLOR_BIT_DEPTH_10;
+}
+
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_COLOR_BIT_DEPTH, color_depth);
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
+/// Color Transfer Characteristics (AMF matches ISO/IEC)
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_TRANSFER_CHARACTERISTIC, 
(amf_int64)avctx->color_trc);
+/// Color Primaries (AMF matches ISO/IEC)
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PRIMARIES, 
(amf_int64)avctx->color_primaries);
+
 profile_level = avctx->level;
 if (profile_level == AV_LEVEL_UNKNOWN) {
 profile_level = ctx->level;
-- 
2.43.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 2/4] avcodec/amfenc: HDR metadata.

2024-04-15 Thread Araz Iusubov
From: nyanmisaka 

v2: fixes for indentation
---
 libavcodec/amfenc.c | 83 +
 1 file changed, 83 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 0bd15dd812..068bb53002 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -36,6 +36,57 @@
 #include "amfenc.h"
 #include "encode.h"
 #include "internal.h"
+#include "libavutil/mastering_display_metadata.h"
+
+static int amf_save_hdr_metadata(AVCodecContext *avctx, const AVFrame *frame, 
AMFHDRMetadata *hdrmeta)
+{
+AVFrameSideData*sd_display;
+AVFrameSideData*sd_light;
+AVMasteringDisplayMetadata *display_meta;
+AVContentLightMetadata *light_meta;
+
+sd_display = av_frame_get_side_data(frame, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd_display) {
+display_meta = (AVMasteringDisplayMetadata *)sd_display->data;
+if (display_meta->has_luminance) {
+const unsigned int luma_den = 1;
+hdrmeta->maxMasteringLuminance =
+(amf_uint32)(luma_den * av_q2d(display_meta->max_luminance));
+hdrmeta->minMasteringLuminance =
+FFMIN((amf_uint32)(luma_den * 
av_q2d(display_meta->min_luminance)), hdrmeta->maxMasteringLuminance);
+}
+if (display_meta->has_primaries) {
+const unsigned int chroma_den = 5;
+hdrmeta->redPrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[0][0])), chroma_den);
+hdrmeta->redPrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[0][1])), chroma_den);
+hdrmeta->greenPrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[1][0])), chroma_den);
+hdrmeta->greenPrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[1][1])), chroma_den);
+hdrmeta->bluePrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[2][0])), chroma_den);
+hdrmeta->bluePrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[2][1])), chroma_den);
+hdrmeta->whitePoint[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->white_point[0])), chroma_den);
+hdrmeta->whitePoint[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->white_point[1])), chroma_den);
+}
+
+sd_light = av_frame_get_side_data(frame, 
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+if (sd_light) {
+light_meta = (AVContentLightMetadata *)sd_light->data;
+if (light_meta) {
+hdrmeta->maxContentLightLevel = (amf_uint16)light_meta->MaxCLL;
+hdrmeta->maxFrameAverageLightLevel = 
(amf_uint16)light_meta->MaxFALL;
+}
+}
+return 0;
+}
+return 1;
+}
 
 #if CONFIG_D3D11VA
 #include 
@@ -683,6 +734,26 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
 }
 
+// HDR10 metadata
+if (frame->color_trc == AVCOL_TRC_SMPTE2084) {
+AMFBuffer * hdrmeta_buffer = NULL;
+res = ctx->context->pVtbl->AllocBuffer(ctx->context, 
AMF_MEMORY_HOST, sizeof(AMFHDRMetadata), _buffer);
+if (res == AMF_OK) {
+AMFHDRMetadata * hdrmeta = 
(AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
+if (amf_save_hdr_metadata(avctx, frame, hdrmeta) == 0) {
+switch (avctx->codec->id) {
+case AV_CODEC_ID_H264:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+case AV_CODEC_ID_HEVC:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+}
+res = amf_set_property_buffer(surface, 
L"av_frame_hdrmeta", hdrmeta_buffer);
+AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, 
"SetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res);
+}
+hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
+}
+}
+
 surface->pVtbl->SetPts(surface, frame->pts);
 AMF_ASSIGN_PROPERTY_INT64(res, surface, PTS_PROP, frame->pts);
 
@@ -746,6 +817,18 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 }
 res_resubmit = AMF_OK;
 if (ctx->delayed_surface != NULL) { // try to resubmit frame
+if (ctx->delayed_surface->pVtbl->HasProperty(ctx->delayed_surface, 
L"av_frame_hdrmeta")) {
+AMFBuffer * 

[FFmpeg-devel] [PATCH 1/4] avcodec/amfenc: Fixes the color information in the output.

2024-04-15 Thread Araz Iusubov
From: Michael Fabian 'Xaymar' Dirks 

added 10 bit support for amf hevc.

before:

command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file.mkv -an -c:v h264_amf res.dx11_hw_h264.mkv
output -  Format of input frames context (p010le) is not supported by AMF.
command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv
output -  Format of input frames context (p010le) is not supported by AMF.

after:

command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v h264_amf res.dx11_hw_h264.mkv
output -  10-bit input video is not supported by AMF H264 encoder
command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv
output -  10bit file

v2 - lost line returned in ff_amf_pix_fmts
v3 - fixes after review
v4 - extract duplicated code, fix incorrect processing of 10-bit input for h264
v5 - non-functional changes after review

Co-authored-by: Evgeny Pavlov 
---
 libavcodec/amfenc.c  | 37 +
 libavcodec/amfenc.h  |  3 +++
 libavcodec/amfenc_h264.c | 24 
 libavcodec/amfenc_hevc.c | 26 +-
 4 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 061859f85c..0bd15dd812 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -60,6 +60,7 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 #if CONFIG_DXVA2
 AV_PIX_FMT_DXVA2_VLD,
 #endif
+AV_PIX_FMT_P010,
 AV_PIX_FMT_NONE
 };
 
@@ -72,6 +73,7 @@ static const FormatMap format_map[] =
 {
 { AV_PIX_FMT_NONE,   AMF_SURFACE_UNKNOWN },
 { AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_P010,   AMF_SURFACE_P010 },
 { AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
 { AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
 { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
@@ -785,6 +787,41 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 return ret;
 }
 
+int ff_amf_get_color_profile(AVCodecContext *avctx)
+{
+amf_int64 color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
+if (avctx->color_range == AVCOL_RANGE_JPEG) {
+/// Color Space for Full (JPEG) Range
+switch (avctx->colorspace) {
+case AVCOL_SPC_SMPTE170M:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601;
+break;
+case AVCOL_SPC_BT709:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709;
+break;
+case AVCOL_SPC_BT2020_NCL:
+case AVCOL_SPC_BT2020_CL:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020;
+break;
+}
+} else {
+/// Color Space for Limited (MPEG) range
+switch (avctx->colorspace) {
+case AVCOL_SPC_SMPTE170M:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_601;
+break;
+case AVCOL_SPC_BT709:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709;
+break;
+case AVCOL_SPC_BT2020_NCL:
+case AVCOL_SPC_BT2020_CL:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020;
+break;
+}
+}
+return color_profile;
+}
+
 const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[] = {
 #if CONFIG_D3D11VA
 HW_CONFIG_ENCODER_FRAMES(D3D11, D3D11VA),
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..62736ef579 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -21,6 +21,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -170,6 +171,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt);
 */
 extern const enum AVPixelFormat ff_amf_pix_fmts[];
 
+int ff_amf_get_color_profile(AVCodecContext *avctx);
+
 /**
 * Error handling helper
 */
diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c
index bd544d12df..f785e091c9 100644
--- a/libavcodec/amfenc_h264.c
+++ b/libavcodec/amfenc_h264.c
@@ -199,6 +199,8 @@ static av_cold int amf_encode_init_h264(AVCodecContext 
*avctx)
 AMFRate  framerate;
 AMFSize  framesize = 
AMFConstructSize(avctx->width, avctx->height);
 int  deblocking_filter = (avctx->flags & 
AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
+amf_int64color_profile;
+enum AVPixelFormat pix_fmt;
 
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
 framerate = AMFConstructRate(avctx->framerate.num, 
avctx->framerate.den);
@@ -262,10 +264,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
 AMF_ASSIGN_PROPERTY_RATIO(res, ctx->encoder, 
AMF_VIDEO_ENCODER_ASPECT_RATIO, ratio);
 }
 
-/// Color Range (Partial/TV/MPEG or Full/PC/JPEG)
- 

Re: [FFmpeg-devel] [PATCH 4/5] avformat/mxfdec: Check index_edit_rate

2024-04-15 Thread Tomas Härdin
sön 2024-04-14 klockan 22:55 +0200 skrev Marton Balint:
> 
> 
> On Wed, 10 Apr 2024, Tomas Härdin wrote:
> 
> > tis 2024-04-09 klockan 22:58 +0200 skrev Marton Balint:
> > > 
> > > 
> > > On Tue, 9 Apr 2024, Tomas Härdin wrote:
> > > 
> > > > mån 2024-04-08 klockan 21:46 +0200 skrev Marton Balint:
> > > > > 
> > > > > 
> > > > > On Mon, 8 Apr 2024, Tomas Härdin wrote:
> > > > > 
> > > > > > tor 2024-04-04 klockan 00:51 +0200 skrev Michael
> > > > > > Niedermayer:
> > > > > > > Fixes: Assertion b >=0 failed at
> > > > > > > libavutil/mathematics.c:62
> > > > > > > Fixes: 67811/clusterfuzz-testcase-minimized-
> > > > > > > ffmpeg_dem_MXF_fuzzer-
> > > > > > > 5108429687422976
> > > > > > > 
> > > > > > > Found-by: continuous fuzzing process
> > > > > > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > > > > > Signed-off-by: Michael Niedermayer
> > > > > > > 
> > > > > > > ---
> > > > > > >  libavformat/mxfdec.c | 3 +++
> > > > > > >  1 file changed, 3 insertions(+)
> > > > > > > 
> > > > > > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> > > > > > > index 04de4c1d5e3..233d614f783 100644
> > > > > > > --- a/libavformat/mxfdec.c
> > > > > > > +++ b/libavformat/mxfdec.c
> > > > > > > @@ -1264,6 +1264,9 @@ static int
> > > > > > > mxf_read_index_table_segment(void
> > > > > > > *arg, AVIOContext *pb, int tag, int
> > > > > > >  case 0x3F0B:
> > > > > > >  segment->index_edit_rate.num = avio_rb32(pb);
> > > > > > >  segment->index_edit_rate.den = avio_rb32(pb);
> > > > > > > +    if (segment->index_edit_rate.num <= 0 ||
> > > > > > > +    segment->index_edit_rate.den <= 0)
> > > > > > > +    return AVERROR_INVALIDDATA;
> > > > > > 
> > > > > > mxf_compute_index_tables() has a check for index_edit_rate
> > > > > > that
> > > > > > you
> > > > > > probably want to remove as well. It was introduced in
> > > > > > c6fff3d,
> > > > > > but
> > > > > > the
> > > > > > files it supposedly fixes aren't in FATE. We shouldn't
> > > > > > encourage
> > > > > > broken
> > > > > > muxers.
> > > > > 
> > > > > I don't quite get what FATE has to do with it. And the
> > > > > samples
> > > > > mentioned 
> > > > > in the patch has valid index segment edit rates, only they
> > > > > are
> > > > > different 
> > > > > from the track edit rate, and the patch was intended to fix
> > > > > that
> > > > > case.
> > > > 
> > > > Then why does it check against 0/0?
> > > 
> > > Probably to avoid divison by zero.
> > 
> > I think it's safe to say that EditRates with zero in the numerator
> > or
> > denominator are not allowed. We currently default to 25/1 in this
> > case
> > for Tracks, but I am skeptical of this since it encourages broken
> > muxers.
> 
> In general, I don't like the idea of rejecting everything which is
> not 
> following the standard to the letter. Decoding and demuxing should be
> based on the "Robustness principle", as in being liberal in what we
> accept 
> and strict in what we generate.

No. We should not encourage proliferation of broken muxers. This leads
to compounding headaches down the line.

> I am also not sure about your reasoning that rejecting files will
> force 
> vendors to fix their muxers, because the users will have to pay the
> price 
> for this approach. Users may well already have their archives full of
> non-compliant files, their camera, phone, whatever is likely out of 
> warranty/support, so they might not even be in a position to request 
> anything from vendors.

These users can sign an SLA if they want support for these cameras.

> Sure, I get it, some issues cannot be worked around easily, and I am
> not 
> saying that everything must be supported with huge hacks if needed.
> But an 
> effort should be made to not break existing real files, and support
> what 
> we reasonably can.

I mean, at the very least we need such samples in FATE or we can't
refactor mxfdec with any level of confidence. Restricting hacks to
specific vendors as identified by the Identification set would help
bring some order to them.

> > As for IndexEditRate, here's what ST 377-1:2019 has to say:
> > 
> > 
> > > Edit Rate copied from the Essence Tracks of the
> > > Essence Container
> > > [Note: SMPTE RP 210 definition Specifies the
> > > indexing rate in hertz]
> > 
> > It's possible to encode a file that does not specify IndexEditRate,
> > but
> > this is not allowed since the field is marked Required in Table 26.
> > mxfdec.c will default to 0/0 since the segment is calloc'd.
> > Michael's
> > fix won't work if one changes the IndexEditRate local tag in the
> > file
> > to something else, say  instead of 3F0B.
> 
> Yes, you are right about this. To be honest, I'd rather fix the
> invalid 
> index edit rate issue by dropping the invalid segments when sorting
> them. 
> That should work for both the explicitly and implicitly invalid index
> edit 
> rates.

This is in contradiction with your desire to support broken muxers (:

If 

Re: [FFmpeg-devel] [PATCH] ffmpeg: Carry streamid as metadata key 'id'

2024-04-15 Thread Tomas Härdin
lör 2024-04-13 klockan 01:25 +0200 skrev Michael Niedermayer:
> On Fri, Apr 12, 2024 at 11:40:47AM +0200, Tomas Härdin wrote:
> > This idea could be extended to other fields not presently
> > considered to
> > be metadata, that would be handy to treat as such.
> > 
> > I use the key "id" because ffprobe outputs id= for streamid.
> > Another
> > option could be to collect these types of metadata that go into
> > AVStream fields under a namespace like FFMPEG: or AVSTREAM: or
> > something, then delete all of them using AV_DICT_IGNORE_SUFFIX near
> > the
> > end of of_open() since they're for internal ffmpeg use.
> > 
> > The FATE change is just because av_dict() changes the order of
> > things
> > when elements are deleted.
> > 
> > /Tomas
> 
> >  fftools/ffmpeg_demux.c  |    5 +++
> >  fftools/ffmpeg_mux_init.c   |   56
> > ++--
> >  tests/ref/fate/matroska-stereo_mode |    6 +--
> >  3 files changed, 49 insertions(+), 18 deletions(-)
> > cd526b2292b6d7e3fb5739a04cf17fbe5f207f16  0001-ffmpeg-Carry-
> > streamid-as-metadata-key-id.patch
> > From 7799f1b2eb8ab02e58118565f3e889fbe0d568a7 Mon Sep 17 00:00:00
> > 2001
> > From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
> > Date: Fri, 12 Apr 2024 10:34:12 +0200
> > Subject: [PATCH] ffmpeg: Carry streamid as metadata key 'id'
> > 
> > This allows using -map_metadata and -metadata to copy/set streamids
> > (PIDs).
> > ---
> >  fftools/ffmpeg_demux.c  |  5 +++
> >  fftools/ffmpeg_mux_init.c   | 56 +
> > 
> >  tests/ref/fate/matroska-stereo_mode |  6 ++--
> >  3 files changed, 49 insertions(+), 18 deletions(-)
> 
> breaks:
> 
> ./ffmpeg -i ~/videos/mm-short.mpg -vstats_file /tmp/vstats -bitexact
> -map 0:1 -map 0:1 -map 0:2 -threads 6 -vcodec libx264 -vcodec libx264
> -pass 1 -b:v:0 300k -b:v:1 900k -passlogfile:v:1 /tmp/video2 -
> passlogfile:v:0 /tmp/video1 -t 1 -y -ab 128k  /tmp/x.ts
> 
> [mpegts @ 0x558d5e3b2140] Duplicate stream id 480

It's hardly strange if you map the same stream to the output twice that
you get duplicate streamids

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

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


Re: [FFmpeg-devel] [RFC] Anyone using 6.0, 4.1, 3.4 ?

2024-04-15 Thread Michael Niedermayer
On Sun, Apr 14, 2024 at 09:15:07PM -0300, James Almer wrote:
> On 4/14/2024 8:55 PM, Michael Niedermayer wrote:
> > Hi
> > 
> > I see nothing using 6.0 and 4.1 on our downstreams page, so i suggest to
> > move 6.0 to the archieve page after 6.0.2 and 4.1 probably without
> > new releases
> 
> 4.1 is used by debian old-old-stable, so one last point release would not be
> unwelcome.

debian old stable lists 4.3 on our https://trac.ffmpeg.org/wiki/Downstreams

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is what and why we do it that matters, not just one of them.


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] [RFC] Anyone using 6.0, 4.1, 3.4 ?

2024-04-15 Thread Jean-Baptiste Kempf
Hi,

On Mon, 15 Apr 2024, at 01:55, Michael Niedermayer wrote:
> I see nothing using 6.0 and 4.1 on our downstreams page, so i suggest to
> move 6.0 to the archieve page after 6.0.2 and 4.1 probably without
> new releases

Good idea.

> About 3.4
> ubuntu 18.04 last updated its FFmpeg 3.4 package 15 November 2023
> sadly "apt changelog" doesnt seem to work with that package so iam not
> sure that includes our fixes or only other things
> our last 3.4 release was 2023-06-12

Just make one point release of 3.4 and drop that branch.

> but i intend to make new 3.4 and 2.8 releases too

> The branches can be droped afterwards if noone is left using these.

Even if those have people using them, you should drop them now.
They are old, and we're not sure they are complete in terms of backports and 
fixes.

If you maintain them, people expect completion, while they are not complete, 
and it does not incentize people to upgrade.

> But as shown above ubuntu is still actively doing things with these
> packages so if someone confirms that ubuntu still has interrest in
> these (or another distro) then ill try to continue to update these

In summary, IMHO:
I think you should support less versions.

Drop 2.8 and 3.4 (after a point release, if you want).
Maintain 4.2, 4.4, 5.1, 6.1 and drop all the rest (4.0, 4.1, 4,.3, 5.0).

Almost no other project in the world support that many branches.
It's better to have a few very well maintained, than all those.

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
https://jbkempf.com/
___
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] opusdsp: add ability to modify deemphasis constant

2024-04-15 Thread Lynne
xHE-AAC relies on the same postfilter mechanism
that Opus uses to improve clarity (albeit with a steeper
deemphasis filter, using a z=0.64).

The code to apply it is identical, it's still just a
simple IIR low-pass filter. This commit makes it possible
to use alternative constants.

Patch attached.

>From c4ad107076970a555ed838a75c0343dffe0cad36 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Mon, 29 Jan 2024 04:31:43 +0100
Subject: [PATCH] opusdsp: add ability to modify deemphasis constant

xHE-AAC relies on the same postfilter mechanism
that Opus uses to improve clarity (albeit with a steeper
deemphasis filter).

The code to apply it is identical, it's still just a
simple IIR low-pass filter. This commit makes it possible
to use alternative constants.
---
 libavcodec/aarch64/opusdsp_init.c |  2 +-
 libavcodec/aarch64/opusdsp_neon.S | 28 +---
 libavcodec/opusdec_celt.c |  4 +++-
 libavcodec/opusdsp.c  | 28 ++--
 libavcodec/opusdsp.h  |  2 +-
 libavcodec/x86/opusdsp.asm|  9 +++--
 libavcodec/x86/opusdsp_init.c |  2 +-
 7 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/libavcodec/aarch64/opusdsp_init.c b/libavcodec/aarch64/opusdsp_init.c
index bb6d71b66b..449d95e8d3 100644
--- a/libavcodec/aarch64/opusdsp_init.c
+++ b/libavcodec/aarch64/opusdsp_init.c
@@ -23,7 +23,7 @@
 #include "libavcodec/opusdsp.h"
 
 void ff_opus_postfilter_neon(float *data, int period, float *gains, int len);
-float ff_opus_deemphasis_neon(float *out, float *in, float coeff, int len);
+float ff_opus_deemphasis_neon(float *out, float *in, float coeff, float *weights, int len);
 
 av_cold void ff_opus_dsp_init_aarch64(OpusDSP *ctx)
 {
diff --git a/libavcodec/aarch64/opusdsp_neon.S b/libavcodec/aarch64/opusdsp_neon.S
index e933151ab4..253825aa61 100644
--- a/libavcodec/aarch64/opusdsp_neon.S
+++ b/libavcodec/aarch64/opusdsp_neon.S
@@ -18,29 +18,11 @@
 
 #include "libavutil/aarch64/asm.S"
 
-   // 0.85..^10.85..^20.85..^30.85..^4
-const tab_st, align=4
-.word 0x3f599a00, 0x3f38f671, 0x3f1d382a, 0x3f05a32f
-endconst
-const tab_x0, align=4
-.word 0x0,0x3f599a00, 0x3f38f671, 0x3f1d382a
-endconst
-const tab_x1, align=4
-.word 0x0,0x0,0x3f599a00, 0x3f38f671
-endconst
-const tab_x2, align=4
-.word 0x0,0x0,0x0,0x3f599a00
-endconst
-
 function ff_opus_deemphasis_neon, export=1
-movrel  x4, tab_st
-ld1 {v4.4s}, [x4]
-movrel  x4, tab_x0
-ld1 {v5.4s}, [x4]
-movrel  x4, tab_x1
-ld1 {v6.4s}, [x4]
-movrel  x4, tab_x2
-ld1 {v7.4s}, [x4]
+ld1 {v4.4s}, [x2], #16
+ld1 {v5.4s}, [x2], #16
+ld1 {v6.4s}, [x2], #16
+ld1 {v7.4s}, [x2]
 
 fmulv0.4s, v4.4s, v0.s[0]
 
@@ -63,7 +45,7 @@ function ff_opus_deemphasis_neon, export=1
 st1 {v1.4s, v2.4s}, [x0], #32
 fmulv0.4s, v4.4s, v2.s[3]
 
-subsw2, w2, #8
+subsw3, w3, #8
 b.gt1b
 
 mov s0, v2.s[3]
diff --git a/libavcodec/opusdec_celt.c b/libavcodec/opusdec_celt.c
index fd8e9929e9..2dd3e12c48 100644
--- a/libavcodec/opusdec_celt.c
+++ b/libavcodec/opusdec_celt.c
@@ -460,7 +460,9 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc,
 /* deemphasis */
 block->emph_coeff = f->opusdsp.deemphasis(output[i],
   >buf[1024 - frame_size],
-  block->emph_coeff, frame_size);
+  block->emph_coeff,
+  ff_deemph_opus_weights,
+  frame_size);
 }
 
 if (channels == 1)
diff --git a/libavcodec/opusdsp.c b/libavcodec/opusdsp.c
index 0764d712e4..e46079c271 100644
--- a/libavcodec/opusdsp.c
+++ b/libavcodec/opusdsp.c
@@ -18,8 +18,31 @@
 
 #include "config.h"
 #include "libavutil/attributes.h"
+#include "libavutil/mem_internal.h"
 #include "opusdsp.h"
 
+static const DECLARE_ALIGNED(16, float, ff_deemph_opus_weights)[] = {
+CELT_EMPH_COEFF,
+CELT_EMPH_COEFF*CELT_EMPH_COEFF,
+CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF,
+CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF,
+
+0,
+CELT_EMPH_COEFF,
+CELT_EMPH_COEFF*CELT_EMPH_COEFF,
+CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF,
+
+0,
+0,
+CELT_EMPH_COEFF,
+CELT_EMPH_COEFF*CELT_EMPH_COEFF,
+
+0,
+0,
+0,
+CELT_EMPH_COEFF,
+};
+
 static void postfilter_c(float *data, int period, float *gains, int len)
 {
 const float g0 = gains[0];
@@ -43,10 +66,11 @@ static void postfilter_c(float