Re: [FFmpeg-devel] [PATCH v1] libavfilter/af_channelsplit.c:fix memory leak

2024-04-14 Thread Zhao Zhili



> On Apr 12, 2024, at 17:49, Zhao Zhili  wrote:
> 
> 
>> On Apr 12, 2024, at 17:19, LuMingYin  wrote:
>> 
>> Signed-off-by: LuMingYin 
>> ---
>> libavfilter/af_channelsplit.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c
>> index d18d91dcb6..2cfac19cd3 100644
>> --- a/libavfilter/af_channelsplit.c
>> +++ b/libavfilter/af_channelsplit.c
>> @@ -163,8 +163,10 @@ static int filter_frame(AVFilterLink *outlink, AVFrame 
>> *buf)
>> 
>>buf_out->data[0] = buf_out->extended_data[0] = 
>> buf_out->extended_data[s->map[i]];
>>ret = av_channel_layout_from_mask(_out->ch_layout, 1ULL << channel);
>> -if (ret < 0)
>> +if (ret < 0){
>> +av_frame_free(_out);
>>return ret;
>> +}
> 
> LGTM. Please pay attention to the coding style. I can fix it manually this 
> time.

Applied as 5e380bcdb13dd47ce9c358a4edb281f05fde3f24.

> 
>> 
>>return ff_filter_frame(ctx->outputs[i], buf_out);
>> }
>> -- 
>> 2.25.1
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@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 both RFC 2617 and RFC 7617]

2024-04-14 Thread 정지우 | Eugene
Hello, thank you for taking the time to review my code.

I've made a new commit incorporating the code style improvements you suggested.
This includes adding spaces before pointers, removing unnecessary comments,
performing case-insensitive comparisons, applying consistent brace styles,
and adding spaces when concatenating strings.

Regarding the use of strcmp, I gave it some thought,
but decided to stick with av_stristr for now to avoid the complexity
of handling all four cases: md5, md5-sess, MD5, and MD5-sess.
However, I acknowledge the benefits of strict string comparison with strcmp
and will keep exploring this approach for future enhancements.

Thank you very much for your thorough review and valuable feedback.

-Original Message-
From: ffmpeg-devel  On Behalf Of Stefano 
Sabatini
Sent: Saturday, April 13, 2024 6:38 PM
To: FFmpeg development discussions and patches 
Subject: Re: [FFmpeg-devel] [PATCH] avformat/httpauth.c [support both RFC 2617 
and RFC 7617]

On date Thursday 2024-04-11 07:48:14 +,| Eugene wrote:
> - Updated the make_digest_auth() function to support both RFC 2617 and RFC 
> 7617 digest authentication.
> - Supports sha256 , sha512-256 along with the existing md5. MD5 and sha256 
> were tested, but sha512-256 was not tested due to lack of testable server.
> - AVHashContext instead of AVMD5 structure.
> - update_md5_strings() -> update_hash_strings().
> - There are some lynt issues in the old code of make_digest_auth, but this is 
> a feature update patch, so I didn't fix it.
> - modified the implementation of RFC7616 based on community feedback.
> 
> Signed-off-by: Eugene-bitsensing 
> ---
>  libavformat/httpauth.c | 105 
> ++---
>  1 file changed, 57 insertions(+), 48 deletions(-)
> 
> diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c index 
> 9780928357..ba2ebea3a4 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*);
>  if (!str)
>  break;
> -av_md5_update(md5ctx, str, strlen(str));

> +av_hash_update(hash_ctx, (const uint8_t*)str, strlen(str));

nit++: (const uint8_t *)str

note the space before the "*"

>  }
>  va_end(vl);
>  }
>  
> -/* Generate a digest reply, according to RFC 2617. */

> +/* Generate a digest reply, according to RFC 2617. Update to support 
> +RFC 7617*/

nit: according to RFC 2617/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;// change int -> size_t

drop this comment

>  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]; // increase hash 
> + size for SHA-2

same here, drop the comment or this will be confusing without reference to the 
diff

> +struct AVHashContext* hash_ctx = NULL; // use AVHashContext for 
> + other algorithm support

nit: here and below, use:
TYPE *VAR

rather than:
TYPE* VAR

style for consistency

> +size_t len_hash = 33; // Modifiable hash length, MD5:32, SHA-2:64
>  char *authstr;
>  
>  digest->nc++;
> @@ -156,52 +156,61 @@ 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);
> -

[FFmpeg-devel] [PATCH] avformat/httpauth.c Support RFC7616 [Style fixed]

2024-04-14 Thread 정지우 | Eugene
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(-)

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;
+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 ret = av_hash_alloc(_ctx, hashing_algorithm);
+if (ret < 0)
+return NULL;
 
-av_md5_init(md5ctx);
-update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL);
-if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) {
-update_md5_strings(md5ctx, ":", nc, ":", cnonce, ":", digest->qop, 
NULL);
+/* a1 hash calculation */
+av_hash_init(hash_ctx);
+update_hash_strings(hash_ctx, 

[FFmpeg-devel] [PATCH 3/3] lavc/vaapi_encode_av1: insert HDR_CLL metadata if have

2024-04-14 Thread Xiang, Haihao
From: Haihao Xiang 

Only look for HDR_CLL on key frame on the output.

Signed-off-by: Haihao Xiang 
---
 libavcodec/vaapi_encode_av1.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index 4077d21202..b868f5b66a 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -707,6 +707,21 @@ static int 
vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
mdm->min_luminance.den);
 }
 }
+
+sd = av_frame_get_side_data(pic->input_image,
+AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+if (sd) {
+AVContentLightMetadata *cllm = (AVContentLightMetadata *)sd->data;
+AV1RawOBU   *obu = >mh[priv->nb_mh++];
+AV1RawMetadata   *md = >obu.metadata;
+AV1RawMetadataHDRCLL*cll = >metadata.hdr_cll;
+
+memset(obu, 0, sizeof(*obu));
+obu->header.obu_type = AV1_OBU_METADATA;
+md->metadata_type= AV1_METADATA_TYPE_HDR_CLL;
+cll->max_cll = cllm->MaxCLL;
+cll->max_fall= cllm->MaxFALL;
+}
 }
 
 end:
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/3] lavc/vaapi_encode_av1: Insert HDR_MDCV metadata if have

2024-04-14 Thread Xiang, Haihao
From: Haihao Xiang 

Only look for HDR_MDVC on key frame on the output.

Signed-off-by: Haihao Xiang 
---
 libavcodec/vaapi_encode_av1.c | 46 +++
 1 file changed, 46 insertions(+)

diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index 4b417b05e7..4077d21202 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
+#include "libavutil/mastering_display_metadata.h"
 
 #include "cbs_av1.h"
 #include "put_bits.h"
@@ -663,6 +664,51 @@ static int 
vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
 
 priv->nb_mh = 0;
 
+if (pic->type == PICTURE_TYPE_IDR) {
+AVFrameSideData *sd =
+av_frame_get_side_data(pic->input_image,
+   AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd) {
+AVMasteringDisplayMetadata *mdm =
+(AVMasteringDisplayMetadata *)sd->data;
+if (mdm->has_primaries && mdm->has_luminance) {
+AV1RawOBU  *obu = >mh[priv->nb_mh++];
+AV1RawMetadata  *md = >obu.metadata;
+AV1RawMetadataHDRMDCV *mdcv = >metadata.hdr_mdcv;
+const intchroma_den = 1 << 16;
+const int  max_luma_den = 1 << 8;
+const int  min_luma_den = 1 << 14;
+
+memset(obu, 0, sizeof(*obu));
+obu->header.obu_type = AV1_OBU_METADATA;
+md->metadata_type = AV1_METADATA_TYPE_HDR_MDCV;
+
+for (i = 0; i < 3; i++) {
+mdcv->primary_chromaticity_x[i] =
+av_rescale(mdm->display_primaries[i][0].num, 
chroma_den,
+   mdm->display_primaries[i][0].den);
+mdcv->primary_chromaticity_y[i] =
+av_rescale(mdm->display_primaries[i][1].num, 
chroma_den,
+   mdm->display_primaries[i][1].den);
+}
+
+mdcv->white_point_chromaticity_x =
+av_rescale(mdm->white_point[0].num, chroma_den,
+   mdm->white_point[0].den);
+mdcv->white_point_chromaticity_y =
+av_rescale(mdm->white_point[1].num, chroma_den,
+   mdm->white_point[1].den);
+
+mdcv->luminance_max =
+av_rescale(mdm->max_luminance.num, max_luma_den,
+   mdm->max_luminance.den);
+mdcv->luminance_min =
+av_rescale(mdm->min_luminance.num, min_luma_den,
+   mdm->min_luminance.den);
+}
+}
+}
+
 end:
 ff_cbs_fragment_reset(obu);
 return ret;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/3] lavc/vaapi_encode_av1: implement write_extra_header callback

2024-04-14 Thread Xiang, Haihao
From: Haihao Xiang 

This can be used to insert a metadata OBU to the stream later.

Signed-off-by: Haihao Xiang 
---
 libavcodec/vaapi_encode_av1.c | 42 ++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index 02a31b894d..4b417b05e7 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -41,6 +41,8 @@ typedef struct VAAPIEncodeAV1Context {
 VAAPIEncodeContext common;
 AV1RawOBU sh; /**< sequence header.*/
 AV1RawOBU fh; /**< frame header.*/
+AV1RawOBU mh[4]; /**< metadata header.*/
+int nb_mh;
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_obu;
 VAConfigAttribValEncAV1 attr;
@@ -659,6 +661,8 @@ static int 
vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
2 : 1));
 }
 
+priv->nb_mh = 0;
+
 end:
 ff_cbs_fragment_reset(obu);
 return ret;
@@ -735,6 +739,39 @@ end:
 return ret;
 }
 
+static int vaapi_encode_av1_write_extra_header(AVCodecContext *avctx,
+   VAAPIEncodePicture *pic,
+   int index, int *type,
+   char *data, size_t *data_len)
+{
+VAAPIEncodeAV1Context  *priv = avctx->priv_data;
+CodedBitstreamFragment *obu  = >current_obu;
+AV1RawOBU *mh_obu;
+char mh_data[MAX_PARAM_BUFFER_SIZE];
+size_t mh_data_len;
+int ret = 0;
+
+if (index >= priv->nb_mh)
+return AVERROR_EOF;
+
+mh_obu = >mh[index];
+ret = vaapi_encode_av1_add_obu(avctx, obu, AV1_OBU_METADATA, mh_obu);
+if (ret < 0)
+goto end;
+
+ret = vaapi_encode_av1_write_obu(avctx, mh_data, _data_len, obu);
+if (ret < 0)
+goto end;
+
+memcpy(data, mh_data, MAX_PARAM_BUFFER_SIZE * sizeof(char));
+*data_len = mh_data_len;
+*type = VAEncPackedHeaderRawData;
+
+end:
+ff_cbs_fragment_reset(obu);
+return ret;
+}
+
 static const VAAPIEncodeProfile vaapi_encode_av1_profiles[] = {
 { AV_PROFILE_AV1_MAIN,  8, 3, 1, 1, VAProfileAV1Profile0 },
 { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, VAProfileAV1Profile0 },
@@ -762,6 +799,8 @@ static const VAAPIEncodeType vaapi_encode_type_av1 = {
 
 .slice_params_size = sizeof(VAEncTileGroupBufferAV1),
 .init_slice_params = _encode_av1_init_slice_params,
+
+.write_extra_header = _encode_av1_write_extra_header,
 };
 
 static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx)
@@ -776,7 +815,8 @@ static av_cold int vaapi_encode_av1_init(AVCodecContext 
*avctx)
 
 ctx->desired_packed_headers =
 VA_ENC_PACKED_HEADER_SEQUENCE |
-VA_ENC_PACKED_HEADER_PICTURE;
+VA_ENC_PACKED_HEADER_PICTURE |
+VA_ENC_PACKED_HEADER_MISC;  // Metadata
 
 if (avctx->profile == AV_PROFILE_UNKNOWN)
 avctx->profile = priv->profile;
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavfi/tonemap_vaapi: By default use bt709 for output frame

2024-04-14 Thread Xiang, Haihao
On Ma, 2024-03-18 at 16:12 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> By default don't use the color properties from input frame as output
> frame properties when performing HDR to SDR conversion
> 
> Signed-off-by: Haihao Xiang 
> ---
>  doc/filters.texi   | 4 ++--
>  libavfilter/vf_tonemap_vaapi.c | 7 +--
>  2 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 913365671d..2cb84c1476 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -27839,7 +27839,7 @@ Default is nv12.
>  @item primaries, p
>  Set the output color primaries.
>  
> -Default is same as input.
> +Default is bt709.
>  
>  @item transfer, t
>  Set the output transfer characteristics.
> @@ -27849,7 +27849,7 @@ Default is bt709.
>  @item matrix, m
>  Set the output colorspace matrix.
>  
> -Default is same as input.
> +Default is bt709.
>  
>  @end table
>  
> diff --git a/libavfilter/vf_tonemap_vaapi.c b/libavfilter/vf_tonemap_vaapi.c
> index 0b767202d2..a21f565e3a 100644
> --- a/libavfilter/vf_tonemap_vaapi.c
> +++ b/libavfilter/vf_tonemap_vaapi.c
> @@ -278,13 +278,16 @@ static int tonemap_vaapi_filter_frame(AVFilterLink
> *inlink, AVFrame *input_frame
>  if (err < 0)
>  goto fail;
>  
> +    /* Use BT709 by default for HDR to SDR output frame */
> +    output_frame->color_primaries = AVCOL_PRI_BT709;
> +    output_frame->color_trc = AVCOL_TRC_BT709;
> +    output_frame->colorspace = AVCOL_SPC_BT709;
> +
>  if (ctx->color_primaries != AVCOL_PRI_UNSPECIFIED)
>  output_frame->color_primaries = ctx->color_primaries;
>  
>  if (ctx->color_transfer != AVCOL_TRC_UNSPECIFIED)
>  output_frame->color_trc = ctx->color_transfer;
> -    else
> -    output_frame->color_trc = AVCOL_TRC_BT709;
>  
>  if (ctx->color_matrix != AVCOL_SPC_UNSPECIFIED)
>  output_frame->colorspace = ctx->color_matrix;

Will apply, 

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavfi: Add pad_vaapi filter

2024-04-14 Thread Xiang, Haihao
On Ma, 2024-03-18 at 14:06 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Signed-off-by: Haihao Xiang 
> ---
>  configure  |   1 +
>  doc/filters.texi   |  77 ++
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vf_pad_vaapi.c | 283 +
>  5 files changed, 363 insertions(+)
>  create mode 100644 libavfilter/vf_pad_vaapi.c
> 
> diff --git a/configure b/configure
> index 2b4c4ec9a2..4f64f48b38 100755
> --- a/configure
> +++ b/configure
> @@ -3890,6 +3890,7 @@ vstack_qsv_filter_deps="libmfx"
>  vstack_qsv_filter_select="qsvvpp"
>  xstack_qsv_filter_deps="libmfx"
>  xstack_qsv_filter_select="qsvvpp"
> +pad_vaapi_filter_deps="vaapi_1"
>  
>  # examples
>  avio_http_serve_files_deps="avformat avutil fork"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 913365671d..2bd1a5b9e7 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -27941,6 +27941,83 @@ first input stream. For the syntax of this option,
> check the
>  See @ref{xstack}.
>  @end table
>  
> +@section pad_vaapi
> +
> +Add paddings to the input image, and place the original input at the
> +provided @var{x}, @var{y} coordinates.
> +
> +It accepts the following options:
> +
> +@table @option
> +@item width, w
> +@item height, h
> +Specify an expression for the size of the output image with the
> +paddings added. If the value for @var{width} or @var{height} is 0, the
> +corresponding input size is used for the output.
> +
> +The @var{width} expression can reference the value set by the
> +@var{height} expression, and vice versa.
> +
> +The default value of @var{width} and @var{height} is 0.
> +
> +@item x
> +@item y
> +Specify the offsets to place the input image at within the padded area,
> +with respect to the top/left border of the output image.
> +
> +The @var{x} expression can reference the value set by the @var{y}
> +expression, and vice versa.
> +
> +The default value of @var{x} and @var{y} is 0.
> +
> +If @var{x} or @var{y} evaluate to a negative number, they'll be changed
> +so the input image is centered on the padded area.
> +
> +@item color
> +Specify the color of the padded area. For the syntax of this option,
> +check the @ref{color syntax,,"Color" section in the ffmpeg-utils
> +manual,ffmpeg-utils}.
> +
> +@item aspect
> +Pad to an aspect instead to a resolution.
> +@end table
> +
> +The value for the @var{width}, @var{height}, @var{x}, and @var{y}
> +options are expressions containing the following constants:
> +
> +@table @option
> +@item in_w
> +@item in_h
> +The input video width and height.
> +
> +@item iw
> +@item ih
> +These are the same as @var{in_w} and @var{in_h}.
> +
> +@item out_w
> +@item out_h
> +The output width and height (the size of the padded area), as
> +specified by the @var{width} and @var{height} expressions.
> +
> +@item ow
> +@item oh
> +These are the same as @var{out_w} and @var{out_h}.
> +
> +@item x
> +@item y
> +The x and y offsets as specified by the @var{x} and @var{y}
> +expressions, or NAN if not yet specified.
> +
> +@item a
> +same as @var{iw} / @var{ih}
> +
> +@item sar
> +input sample aspect ratio
> +
> +@item dar
> +input display aspect ratio, it is the same as (@var{iw} / @var{ih}) *
> @var{sar}
> +@end table
> +
>  @c man end VAAPI VIDEO FILTERS
>  
>  @chapter Vulkan Video Filters
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 994d9773ba..babcc7b676 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -581,6 +581,7 @@ OBJS-$(CONFIG_XSTACK_VAAPI_FILTER)   +=
> vf_stack_vaapi.o framesync.o vaa
>  OBJS-$(CONFIG_HSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o
>  OBJS-$(CONFIG_VSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o
>  OBJS-$(CONFIG_XSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o
> +OBJS-$(CONFIG_PAD_VAAPI_FILTER)  += vf_pad_vaapi.o vaapi_vpp.o
>  
>  OBJS-$(CONFIG_ALLRGB_FILTER) += vsrc_testsrc.o
>  OBJS-$(CONFIG_ALLYUV_FILTER) += vsrc_testsrc.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 149bf50997..1e024b3376 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -546,6 +546,7 @@ extern const AVFilter ff_vf_xstack_vaapi;
>  extern const AVFilter ff_vf_hstack_qsv;
>  extern const AVFilter ff_vf_vstack_qsv;
>  extern const AVFilter ff_vf_xstack_qsv;
> +extern const AVFilter ff_vf_pad_vaapi;
>  
>  extern const AVFilter ff_vsrc_allrgb;
>  extern const AVFilter ff_vsrc_allyuv;
> diff --git a/libavfilter/vf_pad_vaapi.c b/libavfilter/vf_pad_vaapi.c
> new file mode 100644
> index 00..98f6285222
> --- /dev/null
> +++ b/libavfilter/vf_pad_vaapi.c
> @@ -0,0 +1,283 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software 

Re: [FFmpeg-devel] [PATCH v2 1/2] lavc/vaapi_decode: Use dynamic frame pool if possible

2024-04-14 Thread Xiang, Haihao
On Wo, 2024-04-10 at 11:01 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> libva2 doesn't require a fixed surface-array any more, so we may use
> dynamic frame pool for decoding when libva2 is available, which allows a
> downstream element stores more frames from VAAPI decoders and fixes the
> error below:
> 
> $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi \
> -i input.mp4 -c:v hevc_vaapi -f null -
> ...
> [h264 @ 0x557a075a1400] get_buffer() failed
> [h264 @ 0x557a075a1400] thread_get_buffer() failed
> [h264 @ 0x557a075a1400] decode_slice_header error
> [h264 @ 0x557a075a1400] no frame!
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/vaapi_decode.c | 36 
>  1 file changed, 20 insertions(+), 16 deletions(-)
> 
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 5665639dd7..21b273cd0f 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -599,22 +599,26 @@ static int vaapi_decode_make_config(AVCodecContext
> *avctx,
>  if (err < 0)
>  goto fail;
>  
> -    frames->initial_pool_size = 1;
> -    // Add per-codec number of surfaces used for storing reference
> frames.
> -    switch (avctx->codec_id) {
> -    case AV_CODEC_ID_H264:
> -    case AV_CODEC_ID_HEVC:
> -    case AV_CODEC_ID_AV1:
> -    frames->initial_pool_size += 16;
> -    break;
> -    case AV_CODEC_ID_VP9:
> -    frames->initial_pool_size += 8;
> -    break;
> -    case AV_CODEC_ID_VP8:
> -    frames->initial_pool_size += 3;
> -    break;
> -    default:
> -    frames->initial_pool_size += 2;
> +    if (CONFIG_VAAPI_1)
> +    frames->initial_pool_size = 0;
> +    else {
> +    frames->initial_pool_size = 1;
> +    // Add per-codec number of surfaces used for storing reference
> frames.
> +    switch (avctx->codec_id) {
> +    case AV_CODEC_ID_H264:
> +    case AV_CODEC_ID_HEVC:
> +    case AV_CODEC_ID_AV1:
> +    frames->initial_pool_size += 16;
> +    break;
> +    case AV_CODEC_ID_VP9:
> +    frames->initial_pool_size += 8;
> +    break;
> +    case AV_CODEC_ID_VP8:
> +    frames->initial_pool_size += 3;
> +    break;
> +    default:
> +    frames->initial_pool_size += 2;
> +    }
>  }
>  }
> 
> 

Hi,

I'll merge this patchset if there are no objections.

Thanks
Haihao

>  

___
ffmpeg-devel mailing list
ffmpeg-devel@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] avcodec/vaapi_encode_h264: use is_reference to fill reference_pic_flag

2024-04-14 Thread Xiang, Haihao
On Di, 2024-03-05 at 16:02 +0800, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> This codec supports FLAG_B_PICTURE_REFERENCES. We need to correctly fill
> the reference_pic_flag with is_reference variable instead of 0 for B
> frames.
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/vaapi_encode_h264.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
> index 37df9103ae..4a738215c1 100644
> --- a/libavcodec/vaapi_encode_h264.c
> +++ b/libavcodec/vaapi_encode_h264.c
> @@ -759,7 +759,7 @@ static int
> vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
>  vpic->frame_num = hpic->frame_num;
>  
>  vpic->pic_fields.bits.idr_pic_flag   = (pic->type ==
> PICTURE_TYPE_IDR);
> -    vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B);
> +    vpic->pic_fields.bits.reference_pic_flag = pic->is_reference;
>  
>  return 0;
>  }

Patchset LGTM, will apply, 

Thanks
Haihao

___
ffmpeg-devel mailing list
ffmpeg-devel@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-14 Thread Xiang, Haihao
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.

Thanks
Haihao


___
ffmpeg-devel mailing list
ffmpeg-devel@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] vulkan_av1: add workaround for NVIDIA drivers tested on broken CTS

2024-04-14 Thread Lynne
Apr 14, 2024, 14:49 by d...@lynne.ee:

> The first release of the CTS for AV1 decoding had incorrect
> offsets for the OrderHints values.
> The CTS will be fixed, and eventually, the drivers will be
> updated to the proper spec-conforming behaviour, but we still
> need to add a workaround as this will take months.
> Only NVIDIA use these values at all, so limit the workaround
> to only NVIDIA.
>
> Meant to be applied on top of jkqxz's previous 2 patches.
>
> Patch attached.
>

Pushed after an approval from jkqxz.
___
ffmpeg-devel mailing list
ffmpeg-devel@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-14 Thread James Almer

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.




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

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

thx


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

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

___
ffmpeg-devel mailing list
ffmpeg-devel@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] [RFC] Anyone using 6.0, 4.1, 3.4 ?

2024-04-14 Thread Michael Niedermayer
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

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

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

thx

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.


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] avcodec/vvc/ps: reset sps_id_used on PS uninit

2024-04-14 Thread James Almer

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


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

2024-04-14 Thread 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.


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.


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.




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.




In short, IndexEditRate MUST be set and it MUST equal the EditRate of
the associated Essence Track (confusingly called source_track in the
code). Section 11 is even more explicit:


An Index Table shall be used to index a single Essence Container.
Each Index Table shall index Edit Units
stored Essence of the Essence Container. The Edit Unit rate of an
Index Table is defined by the Edit Rate of the
Essence Tracks of the Package that describes the Essence Container
that the Index Table indexes.


EditRate MAY be different between MaterialPackage and FilePackage
however. This is a consequence of MXF's AAF heritage. MXF is really an
NLE format.

Section 11.6.2 "Look-up Algorithm for Conversion of Index Position to
Stream Offset" is also of relevance. It doesn't make use of
IndexEditRate at all.


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


Re: [FFmpeg-devel] [PATCH] avutil/opt: add AV_OPT_FLAG_FORCE_CONST

2024-04-14 Thread Timo Rothenpieler

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.


Due to it technically being an API break, just turning it on for old 
options is not that easy, but it's something for a future major update.




diff --git a/doc/APIchanges b/doc/APIchanges
index 63e7a47126..da2c87909b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 
2024-03-07


API changes, most recent first:

+2024-04-xx - xx - lavu 59.15.101 - opt.h
+  Add AV_OPT_FLAG_FORCE_CONST.
+
2024-04-11 - xx - lavc 61.5.102 - avcodec.h
  AVCodecContext.decoded_side_data may now be set by libavcodec after
  calling avcodec_open2().
diff --git a/libavutil/opt.c b/libavutil/opt.c
index d11e9d2ac5..9e51fa47f9 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -365,6 +365,20 @@ static int set_string_number(void *obj, void 
*target_obj, const AVOption *o, con

    if (o_named->flags & AV_OPT_FLAG_DEPRECATED)
    av_log(obj, AV_LOG_WARNING, "The \"%s\" option is 
deprecated: %s\n",

   o_named->name, o_named->help);
+    } else if (o->flags & AV_OPT_FLAG_FORCE_CONST) {
+    av_log(obj, AV_LOG_ERROR, "The \"%s\" option only 
accepts one of its pre-defined constant values",

+   o->name);
+    buf[0] = ':'; buf[1] = ' '; buf[2] = 0;
+    for (o_named = NULL; o_named = 
av_opt_next(target_obj, o_named); ) {

+    if (o_named->type == AV_OPT_TYPE_CONST &&
+    o_named->unit && o->unit &&
+    !strcmp(o_named->unit, o->unit)) {
+    av_log(obj, AV_LOG_ERROR, "%s%s", buf, 
o_named->name);

+    buf[0] = ',';
+    }
+    }
+    av_log(obj, AV_LOG_ERROR, "\n");
+    return AVERROR(EINVAL);
    } else {
    if (o->unit) {
    for (o_named = NULL; o_named = 
av_opt_next(target_obj, o_named); ) {

diff --git a/libavutil/opt.h b/libavutil/opt.h
index e6013662f6..67e2b687b2 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -305,6 +305,11 @@ enum AVOptionType{
 * Set if option constants can also reside in child objects.
 */
#define AV_OPT_FLAG_CHILD_CONSTS    (1 << 18)
+/**
+ * The option will only accept AV_OPT_TYPE_CONST values.
+ * Any other user supplied values will be rejected.
+ */


What about built-in named constants, such as min/max/default?


+#define AV_OPT_FLAG_FORCE_CONST (1 << 19)

/**
 * May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
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.34.1


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 mailing list
ffmpeg-devel@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-14 Thread Marton Balint




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.




diff --git a/doc/APIchanges b/doc/APIchanges
index 63e7a47126..da2c87909b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07

API changes, most recent first:

+2024-04-xx - xx - lavu 59.15.101 - opt.h
+  Add AV_OPT_FLAG_FORCE_CONST.
+
2024-04-11 - xx - lavc 61.5.102 - avcodec.h
  AVCodecContext.decoded_side_data may now be set by libavcodec after
  calling avcodec_open2().
diff --git a/libavutil/opt.c b/libavutil/opt.c
index d11e9d2ac5..9e51fa47f9 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -365,6 +365,20 @@ static int set_string_number(void *obj, void *target_obj, 
const AVOption *o, con
if (o_named->flags & AV_OPT_FLAG_DEPRECATED)
av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: 
%s\n",
   o_named->name, o_named->help);
+} else if (o->flags & AV_OPT_FLAG_FORCE_CONST) {
+av_log(obj, AV_LOG_ERROR, "The \"%s\" option only accepts one of 
its pre-defined constant values",
+   o->name);
+buf[0] = ':'; buf[1] = ' '; buf[2] = 0;
+for (o_named = NULL; o_named = av_opt_next(target_obj, 
o_named); ) {
+if (o_named->type == AV_OPT_TYPE_CONST &&
+o_named->unit && o->unit &&
+!strcmp(o_named->unit, o->unit)) {
+av_log(obj, AV_LOG_ERROR, "%s%s", buf, o_named->name);
+buf[0] = ',';
+}
+}
+av_log(obj, AV_LOG_ERROR, "\n");
+return AVERROR(EINVAL);
} else {
if (o->unit) {
for (o_named = NULL; o_named = av_opt_next(target_obj, 
o_named); ) {
diff --git a/libavutil/opt.h b/libavutil/opt.h
index e6013662f6..67e2b687b2 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -305,6 +305,11 @@ enum AVOptionType{
 * Set if option constants can also reside in child objects.
 */
#define AV_OPT_FLAG_CHILD_CONSTS(1 << 18)
+/**
+ * The option will only accept AV_OPT_TYPE_CONST values.
+ * Any other user supplied values will be rejected.
+ */


What about built-in named constants, such as min/max/default?


+#define AV_OPT_FLAG_FORCE_CONST (1 << 19)

/**
 * May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
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.34.1


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


Re: [FFmpeg-devel] [PATCH v2 1/2] lavc/av1: Record reference ordering information for each frame

2024-04-14 Thread Mark Thompson
On 13/04/2024 20:05, Mark Thompson wrote:
> This is needed by Vulkan.  Constructing this can't be delegated to CBS
> because packets might contain multiple frames (when non-shown frames are
> present) but we need separate snapshots immediately before each frame
> for the decoder.
> ---
> Changes over v1: rename the order hint field and document exactly what the 
> new fields contain.
> 
>  libavcodec/av1dec.c | 26 ++
>  libavcodec/av1dec.h |  8 
>  2 files changed, 34 insertions(+)
> > ---
> Changes over v1: fix the OrderHints field as well; move things into the loop 
> over reference names rather than the loop over reference slots.
>
>  libavcodec/vulkan_av1.c | 23 ++-
>  1 file changed, 10 insertions(+), 13 deletions(-)
>

Both pushed with approval from Lynne.

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

2024-04-14 Thread Timo Rothenpieler
---
 doc/APIchanges  |  3 +++
 libavutil/opt.c | 14 ++
 libavutil/opt.h |  5 +
 libavutil/version.h |  2 +-
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 63e7a47126..da2c87909b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-04-xx - xx - lavu 59.15.101 - opt.h
+  Add AV_OPT_FLAG_FORCE_CONST.
+
 2024-04-11 - xx - lavc 61.5.102 - avcodec.h
   AVCodecContext.decoded_side_data may now be set by libavcodec after
   calling avcodec_open2().
diff --git a/libavutil/opt.c b/libavutil/opt.c
index d11e9d2ac5..9e51fa47f9 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -365,6 +365,20 @@ static int set_string_number(void *obj, void *target_obj, 
const AVOption *o, con
 if (o_named->flags & AV_OPT_FLAG_DEPRECATED)
 av_log(obj, AV_LOG_WARNING, "The \"%s\" option is 
deprecated: %s\n",
o_named->name, o_named->help);
+} else if (o->flags & AV_OPT_FLAG_FORCE_CONST) {
+av_log(obj, AV_LOG_ERROR, "The \"%s\" option only accepts one 
of its pre-defined constant values",
+   o->name);
+buf[0] = ':'; buf[1] = ' '; buf[2] = 0;
+for (o_named = NULL; o_named = av_opt_next(target_obj, 
o_named); ) {
+if (o_named->type == AV_OPT_TYPE_CONST &&
+o_named->unit && o->unit &&
+!strcmp(o_named->unit, o->unit)) {
+av_log(obj, AV_LOG_ERROR, "%s%s", buf, o_named->name);
+buf[0] = ',';
+}
+}
+av_log(obj, AV_LOG_ERROR, "\n");
+return AVERROR(EINVAL);
 } else {
 if (o->unit) {
 for (o_named = NULL; o_named = av_opt_next(target_obj, 
o_named); ) {
diff --git a/libavutil/opt.h b/libavutil/opt.h
index e6013662f6..67e2b687b2 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -305,6 +305,11 @@ enum AVOptionType{
  * Set if option constants can also reside in child objects.
  */
 #define AV_OPT_FLAG_CHILD_CONSTS(1 << 18)
+/**
+ * The option will only accept AV_OPT_TYPE_CONST values.
+ * Any other user supplied values will be rejected.
+ */
+#define AV_OPT_FLAG_FORCE_CONST (1 << 19)
 
 /**
  * May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
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.34.1

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

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


Re: [FFmpeg-devel] [PATCH] libavdevice: Improve example in deprecation message for opengl and sdl

2024-04-14 Thread Nicolas George
Nicolas George (12024-04-14):
> Either we find options to make ffplay display frames as fast as
> possible, or we must document to the user that no adequate replacement
> exists.

Please add “-vf setpts=0”. It still has a little more latency than a
built-in device, but at least the feature is not *completely* broken.

> Or we make a point of fixing the devices that were broken.

We still should.

Regards,

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

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


Re: [FFmpeg-devel] [PATCH] libavdevice: Improve example in deprecation message for opengl and sdl

2024-04-14 Thread Nicolas George
Alexander Strasser via ffmpeg-devel (12024-04-14):
> When piping ffmpeg into ffplay both programs write a status line in
> the terminal. That causes flickering and invisibility of one or the
> other status line.

The suggestion of piping to ffplay to replace opengl is inadequate: the
muxing, pipe, demuxing steps introduce a significant latency, and ffplay
tries to maintain the timing, so the latency is never reduced.

Compare:

ffplay -f x11grab -framerate 5 -video_size 284x92 -i :0+1138+0
ffmpeg -f x11grab -framerate 5 -video_size 284x92 -i :0+1138+0 \
  -f nut -c:v rawvideo - | ffplay -loglevel warning -
ffmpeg -f x11grab -framerate 5 -video_size 284x92 -i :0+1138+0 \
  -pix_fmt yuv420p -f xv :0

(since at least xv was not broken)
(replace 284x92 and +1138+0 with an area of your screen where something
is happening)

The first two ones will have a delay of about five seconds, the last one
is almost instantaneous.

Either we find options to make ffplay display frames as fast as
possible, or we must document to the user that no adequate replacement
exists.

Or we make a point of fixing the devices that were broken.

Regards,

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

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


[FFmpeg-devel] [PATCH] libavdevice: Improve example in deprecation message for opengl and sdl

2024-04-14 Thread Alexander Strasser via ffmpeg-devel
When piping ffmpeg into ffplay both programs write a status line in
the terminal. That causes flickering and invisibility of one or the
other status line.

As compromise set ffplay log level to warning, so it doesn't show
the status line.

The user is usually testing ffmpeg command lines and want's a
preview of the result. This way the user can see the ffmpeg output
and still see errors and warnings from ffplay, should they occur.
---
 libavdevice/opengl_enc.c | 2 +-
 libavdevice/sdl2.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index 6f7a30ff9e..c50d02870a 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -1067,7 +1067,7 @@ static av_cold int opengl_write_header(AVFormatContext *h)
 av_log(opengl, AV_LOG_WARNING,
 "The opengl output device is deprecated due to being fundamentally 
incompatible with libavformat API. "
 "For monitoring purposes in ffmpeg you can output to a file or use 
pipes and a video player.\n"
-"Example: ffmpeg -i INPUT -f nut -c:v rawvideo - | ffplay -\n"
+"Example: ffmpeg -i INPUT -f nut -c:v rawvideo - | ffplay 
-loglevel warning -\n"
 );
 opengl->warned = 1;
 }
diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c
index 779c8e08b0..59e3182df8 100644
--- a/libavdevice/sdl2.c
+++ b/libavdevice/sdl2.c
@@ -167,7 +167,7 @@ static int sdl2_write_header(AVFormatContext *s)
 av_log(sdl, AV_LOG_WARNING,
 "The sdl output device is deprecated due to being fundamentally 
incompatible with libavformat API. "
 "For monitoring purposes in ffmpeg you can output to a file or use 
pipes and a video player.\n"
-"Example: ffmpeg -i INPUT -f nut -c:v rawvideo - | ffplay -\n"
+"Example: ffmpeg -i INPUT -f nut -c:v rawvideo - | ffplay 
-loglevel warning -\n"
 );
 sdl->warned = 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 6/6] avcodec/ac3enc: Avoid copying samples

2024-04-14 Thread Andreas Rheinhardt
Only the last 256 samples of each frame are used;
the encoder currently uses a buffer for 1536 + 256 samples
whose first 256 samples contain are the last 256 samples
from the last frame and the next 1536 are the samples
of the current frame.
Yet since 238b2d4155d9779d770fccb3594076bb32742c82 all the
DSP functions only need 256 contiguous samples and this can
be achieved by only retaining the last 256 samples of each
frame. Doing so saves 6KiB per channel.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  | 29 ++---
 libavcodec/ac3enc.h  |  2 +-
 libavcodec/ac3enc_template.c | 20 ++--
 3 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 71d3026d40..1a869ab865 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -503,28 +503,6 @@ static void ac3_adjust_frame_size(AC3EncodeContext *s)
 s->samples_written += AC3_BLOCK_SIZE * s->num_blocks;
 }
 
-/*
- * Copy input samples.
- * Channels are reordered from FFmpeg's default order to AC-3 order.
- */
-static void copy_input_samples(AC3EncodeContext *s, uint8_t * const *samples)
-{
-const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
-
-/* copy and remap input samples */
-for (int ch = 0; ch < s->channels; ch++) {
-/* copy last 256 samples of previous frame to the start of the current 
frame */
-memcpy(>planar_samples[ch][0],
-   s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size * 
s->num_blocks,
-   AC3_BLOCK_SIZE * sampletype_size);
-
-/* copy new samples for current frame */
-memcpy(s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size,
-   samples[s->channel_map[ch]],
-   sampletype_size * AC3_BLOCK_SIZE * s->num_blocks);
-}
-}
-
 /**
  * Set the initial coupling strategy parameters prior to coupling analysis.
  *
@@ -2018,9 +1996,7 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 if (s->bit_alloc.sr_code == 1 || s->eac3)
 ac3_adjust_frame_size(s);
 
-copy_input_samples(s, frame->extended_data);
-
-s->encode_frame(s);
+s->encode_frame(s, frame->extended_data);
 
 ac3_apply_rematrixing(s);
 
@@ -2442,8 +2418,7 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
 
 for (int ch = 0; ch < s->channels; ch++) {
-s->planar_samples[ch] = av_mallocz((AC3_FRAME_SIZE + AC3_BLOCK_SIZE) *
-  sampletype_size);
+s->planar_samples[ch] = av_mallocz(AC3_BLOCK_SIZE * sampletype_size);
 if (!s->planar_samples[ch])
 return AVERROR(ENOMEM);
 }
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 4241a908a1..30812617cc 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -253,7 +253,7 @@ typedef struct AC3EncodeContext {
 int ref_bap_set; ///< indicates if 
ref_bap pointers have been set
 
 /** fixed vs. float function pointers */
-void (*encode_frame)(struct AC3EncodeContext *s);
+void (*encode_frame)(struct AC3EncodeContext *s, uint8_t * const *samples);
 
 /* AC-3 vs. E-AC-3 function pointers */
 void (*output_frame_header)(struct AC3EncodeContext *s);
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 698042ae5c..49fc6d7f37 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -48,25 +48,33 @@
  * This applies the KBD window and normalizes the input to reduce precision
  * loss due to fixed-point calculations.
  */
-static void apply_mdct(AC3EncodeContext *s)
+static void apply_mdct(AC3EncodeContext *s, uint8_t * const *samples)
 {
 int blk, ch;
 
 for (ch = 0; ch < s->channels; ch++) {
+const SampleType *input_samples0 = (const 
SampleType*)s->planar_samples[ch];
+/* Reorder channels from native order to AC-3 order. */
+const SampleType *input_samples1 = (const 
SampleType*)samples[s->channel_map[ch]];
+
 for (blk = 0; blk < s->num_blocks; blk++) {
 AC3Block *block = >blocks[blk];
-const SampleType *input_samples = 
(SampleType*)s->planar_samples[ch] + blk * AC3_BLOCK_SIZE;
 SampleType *windowed_samples = s->RENAME(windowed_samples);
 
-s->fdsp->vector_fmul(windowed_samples, input_samples,
+s->fdsp->vector_fmul(windowed_samples, input_samples0,
  s->RENAME(mdct_window), AC3_BLOCK_SIZE);
 s->fdsp->vector_fmul_reverse(windowed_samples + AC3_BLOCK_SIZE,
- _samples[AC3_BLOCK_SIZE],
+ input_samples1,
  s->RENAME(mdct_window), 
AC3_BLOCK_SIZE);
 
 s->tx_fn(s->tx, block->mdct_coef[ch+1],
  windowed_samples, 

[FFmpeg-devel] [PATCH 5/6] avcodec/ac3enc: Combine cpl_coord buffers

2024-04-14 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 12 ++--
 libavcodec/ac3enc.h |  3 +--
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index eb878afc7b..71d3026d40 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2194,8 +2194,7 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 av_freep(>band_psd_buffer);
 av_freep(>mask_buffer);
 av_freep(>qmant_buffer);
-av_freep(>cpl_coord_exp_buffer);
-av_freep(>cpl_coord_mant_buffer);
+av_freep(>cpl_coord_buffer);
 av_freep(>fdsp);
 
 av_tx_uninit(>tx);
@@ -2439,6 +2438,7 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 int channels = s->channels + 1; /* includes coupling channel */
 int channel_blocks = channels * s->num_blocks;
 int total_coefs= AC3_MAX_COEFS * channel_blocks;
+uint8_t *cpl_coord_mant_buffer;
 const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
 
 for (int ch = 0; ch < s->channels; ch++) {
@@ -2464,9 +2464,9 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 return AVERROR(ENOMEM);
 }
 if (s->cpl_enabled) {
-if (!FF_ALLOC_TYPED_ARRAY(s->cpl_coord_exp_buffer,  channel_blocks * 
16) ||
-!FF_ALLOC_TYPED_ARRAY(s->cpl_coord_mant_buffer, channel_blocks * 
16))
+if (!FF_ALLOC_TYPED_ARRAY(s->cpl_coord_buffer, channel_blocks * 32))
 return AVERROR(ENOMEM);
+cpl_coord_mant_buffer = s->cpl_coord_buffer + 16 * channel_blocks;
 }
 for (blk = 0; blk < s->num_blocks; blk++) {
 AC3Block *block = >blocks[blk];
@@ -2479,8 +2479,8 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 block->mask[ch]= >mask_buffer   [64* 
(blk * channels + ch)];
 block->qmant[ch]   = >qmant_buffer  [AC3_MAX_COEFS * 
(blk * channels + ch)];
 if (s->cpl_enabled) {
-block->cpl_coord_exp[ch]  = >cpl_coord_exp_buffer [16  * 
(blk * channels + ch)];
-block->cpl_coord_mant[ch] = >cpl_coord_mant_buffer[16  * 
(blk * channels + ch)];
+block->cpl_coord_exp[ch]  = >cpl_coord_buffer [16  * (blk * 
channels + ch)];
+block->cpl_coord_mant[ch] = _coord_mant_buffer[16  * (blk 
* channels + ch)];
 }
 
 /* arrangement: channel, block, coeff */
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 54e14d43d9..4241a908a1 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -243,8 +243,7 @@ typedef struct AC3EncodeContext {
 int16_t *band_psd_buffer;
 int16_t *mask_buffer;
 int16_t *qmant_buffer;
-uint8_t *cpl_coord_exp_buffer;
-uint8_t *cpl_coord_mant_buffer;
+uint8_t *cpl_coord_buffer;
 
 uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent 
strategies
 uint8_t frame_exp_strategy[AC3_MAX_CHANNELS];   ///< frame exp 
strategy index
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 4/6] avcodec/ac3enc: Combine loops

2024-04-14 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 24 +++-
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1ef670622a..eb878afc7b 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2459,6 +2459,10 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 !FF_ALLOC_TYPED_ARRAY(s->qmant_buffer,   total_coefs))
 return AVERROR(ENOMEM);
 
+if (!s->fixed_point) {
+if (!FF_ALLOCZ_TYPED_ARRAY(s->fixed_coef_buffer, total_coefs))
+return AVERROR(ENOMEM);
+}
 if (s->cpl_enabled) {
 if (!FF_ALLOC_TYPED_ARRAY(s->cpl_coord_exp_buffer,  channel_blocks * 
16) ||
 !FF_ALLOC_TYPED_ARRAY(s->cpl_coord_mant_buffer, channel_blocks * 
16))
@@ -2482,24 +2486,10 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 /* arrangement: channel, block, coeff */
 block->exp[ch] = >exp_buffer[AC3_MAX_COEFS * 
(s->num_blocks * ch + blk)];
 block->mdct_coef[ch]   = >mdct_coef_buffer  [AC3_MAX_COEFS * 
(s->num_blocks * ch + blk)];
-}
-}
-
-if (!s->fixed_point) {
-if (!FF_ALLOCZ_TYPED_ARRAY(s->fixed_coef_buffer, total_coefs))
-return AVERROR(ENOMEM);
-for (blk = 0; blk < s->num_blocks; blk++) {
-AC3Block *block = >blocks[blk];
-
-for (ch = 0; ch < channels; ch++)
-block->fixed_coef[ch] = >fixed_coef_buffer[AC3_MAX_COEFS * 
(s->num_blocks * ch + blk)];
-}
-} else {
-for (blk = 0; blk < s->num_blocks; blk++) {
-AC3Block *block = >blocks[blk];
-
-for (ch = 0; ch < channels; ch++)
+if (s->fixed_point)
 block->fixed_coef[ch] = (int32_t *)block->mdct_coef[ch];
+else
+block->fixed_coef[ch] = >fixed_coef_buffer[AC3_MAX_COEFS * 
(s->num_blocks * ch + blk)];
 }
 }
 
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 3/6] avcodec/ac3enc: Avoid indirections, allocations of small arrays

2024-04-14 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 44 
 libavcodec/ac3enc.h | 22 +++---
 2 files changed, 15 insertions(+), 51 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index a3a05b3ac8..1ef670622a 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2180,13 +2180,10 @@ static void dprint_options(AC3EncodeContext *s)
  */
 av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 {
-int blk, ch;
 AC3EncodeContext *s = avctx->priv_data;
 
-if (s->planar_samples)
-for (ch = 0; ch < s->channels; ch++)
-av_freep(>planar_samples[ch]);
-av_freep(>planar_samples);
+for (int ch = 0; ch < s->channels; ch++)
+av_freep(>planar_samples[ch]);
 av_freep(>bap_buffer);
 av_freep(>bap1_buffer);
 av_freep(>mdct_coef_buffer);
@@ -2200,19 +2197,6 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 av_freep(>cpl_coord_exp_buffer);
 av_freep(>cpl_coord_mant_buffer);
 av_freep(>fdsp);
-for (blk = 0; blk < s->num_blocks; blk++) {
-AC3Block *block = >blocks[blk];
-av_freep(>mdct_coef);
-av_freep(>fixed_coef);
-av_freep(>exp);
-av_freep(>grouped_exp);
-av_freep(>psd);
-av_freep(>band_psd);
-av_freep(>mask);
-av_freep(>qmant);
-av_freep(>cpl_coord_exp);
-av_freep(>cpl_coord_mant);
-}
 
 av_tx_uninit(>tx);
 
@@ -2457,9 +2441,6 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 int total_coefs= AC3_MAX_COEFS * channel_blocks;
 const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
 
-if (!FF_ALLOCZ_TYPED_ARRAY(s->planar_samples,  s->channels))
-return AVERROR(ENOMEM);
-
 for (int ch = 0; ch < s->channels; ch++) {
 s->planar_samples[ch] = av_mallocz((AC3_FRAME_SIZE + AC3_BLOCK_SIZE) *
   sampletype_size);
@@ -2486,21 +2467,6 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 for (blk = 0; blk < s->num_blocks; blk++) {
 AC3Block *block = >blocks[blk];
 
-if (!FF_ALLOCZ_TYPED_ARRAY(block->mdct_coef,   channels) ||
-!FF_ALLOCZ_TYPED_ARRAY(block->exp, channels) ||
-!FF_ALLOCZ_TYPED_ARRAY(block->grouped_exp, channels) ||
-!FF_ALLOCZ_TYPED_ARRAY(block->psd, channels) ||
-!FF_ALLOCZ_TYPED_ARRAY(block->band_psd,channels) ||
-!FF_ALLOCZ_TYPED_ARRAY(block->mask,channels) ||
-!FF_ALLOCZ_TYPED_ARRAY(block->qmant,   channels))
-return AVERROR(ENOMEM);
-
-if (s->cpl_enabled) {
-if (!FF_ALLOCZ_TYPED_ARRAY(block->cpl_coord_exp,  channels) ||
-!FF_ALLOCZ_TYPED_ARRAY(block->cpl_coord_mant, channels))
-return AVERROR(ENOMEM);
-}
-
 for (ch = 0; ch < channels; ch++) {
 /* arrangement: block, channel, coeff */
 block->grouped_exp[ch] = >grouped_exp_buffer[128   * 
(blk * channels + ch)];
@@ -2524,16 +2490,14 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 return AVERROR(ENOMEM);
 for (blk = 0; blk < s->num_blocks; blk++) {
 AC3Block *block = >blocks[blk];
-if (!FF_ALLOCZ_TYPED_ARRAY(block->fixed_coef, channels))
-return AVERROR(ENOMEM);
+
 for (ch = 0; ch < channels; ch++)
 block->fixed_coef[ch] = >fixed_coef_buffer[AC3_MAX_COEFS * 
(s->num_blocks * ch + blk)];
 }
 } else {
 for (blk = 0; blk < s->num_blocks; blk++) {
 AC3Block *block = >blocks[blk];
-if (!FF_ALLOCZ_TYPED_ARRAY(block->fixed_coef, channels))
-return AVERROR(ENOMEM);
+
 for (ch = 0; ch < channels; ch++)
 block->fixed_coef[ch] = (int32_t *)block->mdct_coef[ch];
 }
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 41b9a3a20b..54e14d43d9 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -127,16 +127,16 @@ typedef struct AC3EncOptions {
  * Data for a single audio block.
  */
 typedef struct AC3Block {
-CoefType **mdct_coef;   ///< MDCT coefficients
-int32_t  **fixed_coef;  ///< fixed-point MDCT 
coefficients
-uint8_t  **exp; ///< original exponents
-uint8_t  **grouped_exp; ///< grouped exponents
-int16_t  **psd; ///< psd per frequency bin
-int16_t  **band_psd;///< psd per critical band
-int16_t  **mask;///< masking curve
-uint16_t **qmant;   ///< quantized mantissas
-uint8_t  **cpl_coord_exp;   ///< coupling coord exponents  
 (cplcoexp)
-uint8_t  **cpl_coord_mant;  ///< coupling coord mantissas  
   

[FFmpeg-devel] [PATCH 2/6] avcodec/ac3enc: Avoid allocation for mdct_window

2024-04-14 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  | 1 -
 libavcodec/ac3enc.h  | 5 -
 libavcodec/ac3enc_fixed.c| 7 +--
 libavcodec/ac3enc_float.c| 7 +--
 libavcodec/ac3enc_template.c | 4 ++--
 5 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index a31b528597..a3a05b3ac8 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2183,7 +2183,6 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 int blk, ch;
 AC3EncodeContext *s = avctx->priv_data;
 
-av_freep(>mdct_window);
 if (s->planar_samples)
 for (ch = 0; ch < s->channels; ch++)
 av_freep(>planar_samples[ch]);
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 618c952a18..41b9a3a20b 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -169,7 +169,6 @@ typedef struct AC3EncodeContext {
 AC3DSPContext ac3dsp;   ///< AC-3 optimized functions
 AVTXContext *tx;///< FFT context for MDCT 
calculation
 av_tx_fn tx_fn;
-const SampleType *mdct_window;  ///< MDCT window function array
 
 AC3Block blocks[AC3_MAX_BLOCKS];///< per-block info
 
@@ -260,6 +259,10 @@ typedef struct AC3EncodeContext {
 /* AC-3 vs. E-AC-3 function pointers */
 void (*output_frame_header)(struct AC3EncodeContext *s);
 
+union {
+DECLARE_ALIGNED(32, float,   mdct_window_float)[AC3_BLOCK_SIZE];
+DECLARE_ALIGNED(32, int32_t, mdct_window_fixed)[AC3_BLOCK_SIZE];
+};
 union {
 DECLARE_ALIGNED(32, float,   windowed_samples_float)[AC3_WINDOW_SIZE];
 DECLARE_ALIGNED(32, int32_t, windowed_samples_fixed)[AC3_WINDOW_SIZE];
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index d2f4cecd72..869e1f27a2 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -27,7 +27,6 @@
  */
 
 #define AC3ENC_FLOAT 0
-#include "libavutil/mem.h"
 #include "audiodsp.h"
 #include "ac3enc.h"
 #include "codec_internal.h"
@@ -79,16 +78,12 @@ static av_cold int ac3_fixed_mdct_init(AVCodecContext 
*avctx, AC3EncodeContext *
 float fwin[AC3_BLOCK_SIZE];
 const float scale = -1.0f;
 
-int32_t *iwin = av_malloc_array(AC3_BLOCK_SIZE, sizeof(*iwin));
-if (!iwin)
-return AVERROR(ENOMEM);
+int32_t *iwin = s->mdct_window_fixed;
 
 ff_kbd_window_init(fwin, 5.0, AC3_BLOCK_SIZE);
 for (int i = 0; i < AC3_BLOCK_SIZE; i++)
 iwin[i] = lrintf(fwin[i] * (1 << 22));
 
-s->mdct_window = iwin;
-
 s->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT);
 if (!s->fdsp)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index cfd233da09..94e8ebc42d 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -27,7 +27,6 @@
  */
 
 #define AC3ENC_FLOAT 1
-#include "libavutil/mem.h"
 #include "audiodsp.h"
 #include "ac3enc.h"
 #include "codec_internal.h"
@@ -87,12 +86,8 @@ static void sum_square_butterfly(AC3EncodeContext *s, float 
sum[4],
 static av_cold int ac3_float_mdct_init(AC3EncodeContext *s)
 {
 const float scale = -2.0 / AC3_WINDOW_SIZE;
-float *window = av_malloc_array(AC3_BLOCK_SIZE, sizeof(*window));
-if (!window)
-return AVERROR(ENOMEM);
 
-ff_kbd_window_init(window, 5.0, AC3_BLOCK_SIZE);
-s->mdct_window = window;
+ff_kbd_window_init(s->mdct_window_float, 5.0, AC3_BLOCK_SIZE);
 
 return av_tx_init(>tx, >tx_fn, AV_TX_FLOAT_MDCT, 0,
   AC3_BLOCK_SIZE, , 0);
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 6070e14961..698042ae5c 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -59,10 +59,10 @@ static void apply_mdct(AC3EncodeContext *s)
 SampleType *windowed_samples = s->RENAME(windowed_samples);
 
 s->fdsp->vector_fmul(windowed_samples, input_samples,
- s->mdct_window, AC3_BLOCK_SIZE);
+ s->RENAME(mdct_window), AC3_BLOCK_SIZE);
 s->fdsp->vector_fmul_reverse(windowed_samples + AC3_BLOCK_SIZE,
  _samples[AC3_BLOCK_SIZE],
- s->mdct_window, AC3_BLOCK_SIZE);
+ s->RENAME(mdct_window), 
AC3_BLOCK_SIZE);
 
 s->tx_fn(s->tx, block->mdct_coef[ch+1],
  windowed_samples, sizeof(*windowed_samples));
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 1/6] avcodec/ac3enc: Avoid allocation for windowed_samples

2024-04-14 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  |  4 
 libavcodec/ac3enc.h  |  7 ++-
 libavcodec/ac3enc_template.c | 12 +---
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1ba4ba549e..a31b528597 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2184,7 +2184,6 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 AC3EncodeContext *s = avctx->priv_data;
 
 av_freep(>mdct_window);
-av_freep(>windowed_samples);
 if (s->planar_samples)
 for (ch = 0; ch < s->channels; ch++)
 av_freep(>planar_samples[ch]);
@@ -2459,9 +2458,6 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
 int total_coefs= AC3_MAX_COEFS * channel_blocks;
 const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
 
-if (!(s->windowed_samples = av_malloc(sampletype_size * AC3_WINDOW_SIZE)))
-return AVERROR(ENOMEM);
-
 if (!FF_ALLOCZ_TYPED_ARRAY(s->planar_samples,  s->channels))
 return AVERROR(ENOMEM);
 
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 227744d27f..618c952a18 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -30,6 +30,7 @@
 
 #include 
 
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 #include "libavutil/tx.h"
 
@@ -232,7 +233,6 @@ typedef struct AC3EncodeContext {
 int frame_bits; ///< all frame bits except 
exponents and mantissas
 int exponent_bits;  ///< number of bits used for 
exponents
 
-void *windowed_samples;
 uint8_t **planar_samples;
 uint8_t *bap_buffer;
 uint8_t *bap1_buffer;
@@ -259,6 +259,11 @@ typedef struct AC3EncodeContext {
 
 /* AC-3 vs. E-AC-3 function pointers */
 void (*output_frame_header)(struct AC3EncodeContext *s);
+
+union {
+DECLARE_ALIGNED(32, float,   windowed_samples_float)[AC3_WINDOW_SIZE];
+DECLARE_ALIGNED(32, int32_t, windowed_samples_fixed)[AC3_WINDOW_SIZE];
+};
 } AC3EncodeContext;
 
 extern const AVChannelLayout ff_ac3_ch_layouts[19];
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index b0f9e69ee8..6070e14961 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -37,6 +37,11 @@
 #include "ac3enc.h"
 #include "eac3enc.h"
 
+#if AC3ENC_FLOAT
+#define RENAME(element) element ## _float
+#else
+#define RENAME(element) element ## _fixed
+#endif
 
 /*
  * Apply the MDCT to input samples to generate frequency coefficients.
@@ -51,15 +56,16 @@ static void apply_mdct(AC3EncodeContext *s)
 for (blk = 0; blk < s->num_blocks; blk++) {
 AC3Block *block = >blocks[blk];
 const SampleType *input_samples = 
(SampleType*)s->planar_samples[ch] + blk * AC3_BLOCK_SIZE;
+SampleType *windowed_samples = s->RENAME(windowed_samples);
 
-s->fdsp->vector_fmul(s->windowed_samples, input_samples,
+s->fdsp->vector_fmul(windowed_samples, input_samples,
  s->mdct_window, AC3_BLOCK_SIZE);
-s->fdsp->vector_fmul_reverse((SampleType*)s->windowed_samples + 
AC3_BLOCK_SIZE,
+s->fdsp->vector_fmul_reverse(windowed_samples + AC3_BLOCK_SIZE,
  _samples[AC3_BLOCK_SIZE],
  s->mdct_window, AC3_BLOCK_SIZE);
 
 s->tx_fn(s->tx, block->mdct_coef[ch+1],
- s->windowed_samples, sizeof(float));
+ windowed_samples, sizeof(*windowed_samples));
 }
 }
 }
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH] vulkan_av1: add workaround for NVIDIA drivers tested on broken CTS

2024-04-14 Thread Lynne
The first release of the CTS for AV1 decoding had incorrect
offsets for the OrderHints values.
The CTS will be fixed, and eventually, the drivers will be
updated to the proper spec-conforming behaviour, but we still
need to add a workaround as this will take months.
Only NVIDIA use these values at all, so limit the workaround
to only NVIDIA.

Meant to be applied on top of jkqxz's previous 2 patches.

Patch attached.

>From bbd2cc90206e59098accced3ff3a8896e0bfa269 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Sun, 14 Apr 2024 14:41:26 +0200
Subject: [PATCH] vulkan_av1: add workaround for NVIDIA drivers tested on
 broken CTS

The first release of the CTS for AV1 decoding had incorrect
offsets for the OrderHints values.
The CTS will be fixed, and eventually, the drivers will be
updated to the proper spec-conforming behaviour, but we still
need to add a workaround as this will take months.
Only NVIDIA use these values at all, so limit the workaround
to only NVIDIA.
---
 libavcodec/vulkan_av1.c| 20 +++-
 libavcodec/vulkan_decode.c |  8 
 libavcodec/vulkan_decode.h |  4 
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index 8d532445a1..ff663c8cec 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -97,9 +97,15 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src,
 .RefFrameSignBias = hp->ref_frame_sign_bias_mask,
 };
 
-if (saved_order_hints)
-for (int i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++)
-vkav1_std_ref->SavedOrderHints[i] = saved_order_hints[i];
+if (saved_order_hints) {
+if (dec->quirk_av1_offset) {
+for (int i = 1; i < AV1_TOTAL_REFS_PER_FRAME; i++)
+vkav1_std_ref->SavedOrderHints[i - 1] = saved_order_hints[i];
+} else {
+for (int i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++)
+vkav1_std_ref->SavedOrderHints[i] = saved_order_hints[i];
+}
+}
 
 *vkav1_ref = (VkVideoDecodeAV1DpbSlotInfoKHR) {
 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_DPB_SLOT_INFO_KHR,
@@ -490,8 +496,12 @@ static int vk_av1_start_frame(AVCodecContext  *avctx,
 }
 }
 
-for (int i = 0; i < STD_VIDEO_AV1_NUM_REF_FRAMES; i++) {
-ap->std_pic_info.OrderHints[i] = pic->order_hints[i];
+if (dec->quirk_av1_offset) {
+for (int i = 1; i < STD_VIDEO_AV1_NUM_REF_FRAMES; i++)
+ap->std_pic_info.OrderHints[i - 1] = pic->order_hints[i];
+} else {
+for (int i = 0; i < STD_VIDEO_AV1_NUM_REF_FRAMES; i++)
+ap->std_pic_info.OrderHints[i] = pic->order_hints[i];
 }
 
 for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++)
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 9c6c2d4efb..5cb328d8ca 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -1115,6 +1115,7 @@ int ff_vk_decode_init(AVCodecContext *avctx)
 FFVulkanFunctions *vk;
 const VkVideoProfileInfoKHR *profile;
 const FFVulkanDecodeDescriptor *vk_desc;
+const VkPhysicalDeviceDriverProperties *driver_props;
 
 VkVideoDecodeH264SessionParametersCreateInfoKHR h264_params = {
 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR,
@@ -1276,6 +1277,13 @@ int ff_vk_decode_init(AVCodecContext *avctx)
 return AVERROR_EXTERNAL;
 }
 
+driver_props = >shared_ctx->s.driver_props;
+if (driver_props->driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY &&
+driver_props->conformanceVersion.major == 1 &&
+driver_props->conformanceVersion.minor == 3 &&
+driver_props->conformanceVersion.subminor == 8)
+dec->quirk_av1_offset = 1;
+
 ff_vk_decode_flush(avctx);
 
 av_log(avctx, AV_LOG_VERBOSE, "Vulkan decoder initialization sucessful\n");
diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h
index 7ba8b239cb..076af93499 100644
--- a/libavcodec/vulkan_decode.h
+++ b/libavcodec/vulkan_decode.h
@@ -72,6 +72,10 @@ typedef struct FFVulkanDecodeContext {
 int external_fg;   /* Oddity  #2 - hardware can't apply film grain */
 uint32_t frame_id_alloc_mask; /* For AV1 only */
 
+/* Workaround for NVIDIA drivers tested with CTS version 1.3.8 for AV1.
+ * The tests were incorrect as the OrderHints were offset by 1. */
+int quirk_av1_offset;
+
 /* Thread-local state below */
 struct HEVCHeaderSet *hevc_headers;
 size_t hevc_headers_size;
-- 
2.43.0.381.gb435a96ce8

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

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