[FFmpeg-devel] [PATCH 18/18] avcodec/ac3enc: Avoid calculating the CRC multiple times

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

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index f520e72fc0..49b0d4b956 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1942,7 +1942,7 @@ static unsigned int pow_poly(unsigned int a, unsigned int 
n, unsigned int poly)
 static void output_frame_end(AC3EncodeContext *s)
 {
 const AVCRC *crc_ctx = av_crc_get_table(AV_CRC_16_ANSI);
-int frame_size_58, pad_bytes, crc1, crc2_partial, crc2, crc_inv;
+int frame_size_58, pad_bytes, crc1, crc2, crc_inv;
 uint8_t *frame;
 
 frame_size_58 = ((s->frame_size >> 2) + (s->frame_size >> 4)) << 1;
@@ -1958,7 +1958,7 @@ static void output_frame_end(AC3EncodeContext *s)
 
 if (s->eac3) {
 /* compute crc2 */
-crc2_partial = av_crc(crc_ctx, 0, frame + 2, s->frame_size - 5);
+crc2 = av_crc(crc_ctx, 0, frame + 2, s->frame_size - 4);
 } else {
 /* compute crc1 */
 /* this is not so easy because it is at the beginning of the data... */
@@ -1968,16 +1968,17 @@ static void output_frame_end(AC3EncodeContext *s)
 AV_WB16(frame + 2, crc1);
 
 /* compute crc2 */
-crc2_partial = av_crc(crc_ctx, 0, frame + frame_size_58,
-  s->frame_size - frame_size_58 - 3);
+crc2 = av_crc(crc_ctx, 0, frame + frame_size_58,
+  s->frame_size - frame_size_58 - 2);
 }
-crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1);
+crc2 = av_bswap16(crc2);
 /* ensure crc2 does not match sync word by flipping crcrsv bit if needed */
-if (crc2 == 0x770B) {
+if (crc2 == 0x0B77) {
+/* The CRC generator polynomial is x^16 + x^15 + x^2 + 1,
+ * so xor'ing with 0x18005 does not affect the CRC. */
 frame[s->frame_size - 3] ^= 0x1;
-crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1);
+crc2 ^= 0x8005;
 }
-crc2 = av_bswap16(crc2);
 AV_WB16(frame + s->frame_size - 2, crc2);
 }
 
-- 
2.40.1

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/h264dec: Remove unused coded_picture_number

2024-04-07 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/h264_slice.c | 1 -
>  libavcodec/h264dec.h| 1 -
>  2 files changed, 2 deletions(-)
> 
> diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
> index 4b01c54147..f61af0d6d7 100644
> --- a/libavcodec/h264_slice.c
> +++ b/libavcodec/h264_slice.c
> @@ -388,7 +388,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
>  
>  h->width_from_caller= h1->width_from_caller;
>  h->height_from_caller   = h1->height_from_caller;
> -h->coded_picture_number = h1->coded_picture_number;
>  h->first_field  = h1->first_field;
>  h->picture_structure= h1->picture_structure;
>  h->mb_aff_frame = h1->mb_aff_frame;
> diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
> index 447c2499d9..fc50df90f2 100644
> --- a/libavcodec/h264dec.h
> +++ b/libavcodec/h264dec.h
> @@ -356,7 +356,6 @@ typedef struct H264Context {
>  int chroma_x_shift, chroma_y_shift;
>  
>  int droppable;
> -int coded_picture_number;
>  
>  int context_initialized;
>  int flags;

Will apply this patch tomorrow unless there are objections.

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/mpegvideo_enc: Reject input incompatible with chroma subsampling

2024-04-07 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Fixes ticket #10952.
> 
> Discovered by: Zeng Yunxiang
> Signed-off-by: Andreas Rheinhardt 
> ---
> I am pretty sure that a lot of other encoders don't handle this well
> either. Maybe we should handle this more generically in
> ff_encode_preinit?
> 
>  libavcodec/mpegvideo_enc.c | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
> index d1b1917824..a65ecc6839 100644
> --- a/libavcodec/mpegvideo_enc.c
> +++ b/libavcodec/mpegvideo_enc.c
> @@ -314,6 +314,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
>  AVCPBProperties *cpb_props;
>  int i, ret;
>  int mb_array_size, mv_table_size;
> +int chroma_h_subsampling = 1, chroma_v_subsampling = 1;
>  
>  mpv_encode_defaults(s);
>  
> @@ -325,14 +326,25 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
>  case AV_PIX_FMT_YUVJ422P:
>  case AV_PIX_FMT_YUV422P:
>  s->chroma_format = CHROMA_422;
> +chroma_h_subsampling = 2;
>  break;
>  case AV_PIX_FMT_YUVJ420P:
>  case AV_PIX_FMT_YUV420P:
>  default:
>  s->chroma_format = CHROMA_420;
> +chroma_h_subsampling = 2;
> +chroma_v_subsampling = 2;
>  break;
>  }
>  
> +if (avctx->width &  (chroma_h_subsampling - 1) ||
> +avctx->height & (chroma_v_subsampling - 1)) {
> +av_log(avctx, AV_LOG_ERROR,
> +   "Dimensions %dx%d incompatible with chroma subsampling.\n",
> +   avctx->width, avctx->height);
> +return AVERROR(EINVAL);
> +}
> +
>  avctx->bits_per_raw_sample = av_clip(avctx->bits_per_raw_sample, 0, 8);
>  
>  s->bit_rate = avctx->bit_rate;

Will apply this patchset tomorrow unless there are objections.

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE

2024-04-07 Thread James Almer

On 4/7/2024 7:26 PM, Andreas Rheinhardt wrote:

James Almer:

On 4/7/2024 6:53 PM, Andreas Rheinhardt wrote:

James Almer:

On 4/7/2024 5:39 PM, Andreas Rheinhardt wrote:

It is perfectly legal for users to use a custom layout
that is equivalent to a supported native one.


Is that really the case? FFCodec.p.ch_layouts[] has a list of native
ones, and the generic encode.c code will reject anything not in it.



This is not true. It allows everything that is equivalent (in the
av_channel_layout_compare() sense) to one of the channel layouts in
AVCodec.ch_layouts. This means that if ch_layout.u.map[i].id is strictly
ascending for 0 <= i 

Right, misread av_channel_layout_compare() as rejecting layouts that
were not the same order.




I guess the encode.c check could be improved with
av_channel_layout_retype().



ch_layout is not supposed to be set by lavc for encoders.


I didn't mean to set the layout for encoders, i meant it as a way for
encode.c to compare input layouts with encoder-supported native layouts,
because of my misunderstanding of how av_channel_layout_compare() behaved.




In this case the union in AVChannelLayout is not an uint64_t mask,
but a pointer to a custom map.

Signed-off-by: Andreas Rheinhardt 
---
    libavcodec/ac3enc.c | 6 +-
    1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 7a6bcf7900..dc197c1517 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2192,18 +2192,14 @@ av_cold int ff_ac3_encode_close(AVCodecContext
*avctx)
    static av_cold int set_channel_info(AVCodecContext *avctx)
    {
    AC3EncodeContext *s = avctx->priv_data;
+    uint64_t mask = av_channel_layout_subset(&avctx->ch_layout,
~(uint64_t)0);


Might as well use UINT64_MAX.



This is a bitfield, so I intentionally used a bit-operation.


Then ~UINT64_C(0).



And the advantage of this is?


It's the proper way to expand a literal to ensure it's 64bits, and we 
use it everywhere for that purpose. But it's a nit in any case.

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

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


Re: [FFmpeg-devel] [PATCH 01/15] avcodec/mpegvideo_enc: Don't update current_picture unnecessarily

2024-04-07 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> current_picture is not changed after frame_start() at all
> and it therefore does not need to be updated (i.e. copied to the
> slice thread contexts) a second time.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/mpegvideo_enc.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
> index d1b1917824..0e3255c0fb 100644
> --- a/libavcodec/mpegvideo_enc.c
> +++ b/libavcodec/mpegvideo_enc.c
> @@ -251,7 +251,6 @@ static void 
> update_duplicate_context_after_me(MpegEncContext *dst,
>  {
>  #define COPY(a) dst->a= src->a
>  COPY(pict_type);
> -COPY(current_picture);
>  COPY(f_code);
>  COPY(b_code);
>  COPY(qscale);

Will apply this patchset tonight unless there are objections.

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE

2024-04-07 Thread Andreas Rheinhardt
James Almer:
> On 4/7/2024 6:53 PM, Andreas Rheinhardt wrote:
>> James Almer:
>>> On 4/7/2024 5:39 PM, Andreas Rheinhardt wrote:
 It is perfectly legal for users to use a custom layout
 that is equivalent to a supported native one.
>>>
>>> Is that really the case? FFCodec.p.ch_layouts[] has a list of native
>>> ones, and the generic encode.c code will reject anything not in it.
>>>
>>
>> This is not true. It allows everything that is equivalent (in the
>> av_channel_layout_compare() sense) to one of the channel layouts in
>> AVCodec.ch_layouts. This means that if ch_layout.u.map[i].id is strictly
>> ascending for 0 <= i > native channel layout with the same nb_channels whose mask is the
>> bitwise or of all (1ULL << ch_layout.u.map[i].id).
> 
> Right, misread av_channel_layout_compare() as rejecting layouts that
> were not the same order.
> 
>>
>>> I guess the encode.c check could be improved with
>>> av_channel_layout_retype().
>>>
>>
>> ch_layout is not supposed to be set by lavc for encoders.
> 
> I didn't mean to set the layout for encoders, i meant it as a way for
> encode.c to compare input layouts with encoder-supported native layouts,
> because of my misunderstanding of how av_channel_layout_compare() behaved.
> 
>>
 In this case the union in AVChannelLayout is not an uint64_t mask,
 but a pointer to a custom map.

 Signed-off-by: Andreas Rheinhardt 
 ---
    libavcodec/ac3enc.c | 6 +-
    1 file changed, 1 insertion(+), 5 deletions(-)

 diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
 index 7a6bcf7900..dc197c1517 100644
 --- a/libavcodec/ac3enc.c
 +++ b/libavcodec/ac3enc.c
 @@ -2192,18 +2192,14 @@ av_cold int ff_ac3_encode_close(AVCodecContext
 *avctx)
    static av_cold int set_channel_info(AVCodecContext *avctx)
    {
    AC3EncodeContext *s = avctx->priv_data;
 +    uint64_t mask = av_channel_layout_subset(&avctx->ch_layout,
 ~(uint64_t)0);
>>>
>>> Might as well use UINT64_MAX.
>>>
>>
>> This is a bitfield, so I intentionally used a bit-operation.
> 
> Then ~UINT64_C(0).
> 

And the advantage of this is?

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE

2024-04-07 Thread James Almer

On 4/7/2024 6:53 PM, Andreas Rheinhardt wrote:

James Almer:

On 4/7/2024 5:39 PM, Andreas Rheinhardt wrote:

It is perfectly legal for users to use a custom layout
that is equivalent to a supported native one.


Is that really the case? FFCodec.p.ch_layouts[] has a list of native
ones, and the generic encode.c code will reject anything not in it.



This is not true. It allows everything that is equivalent (in the
av_channel_layout_compare() sense) to one of the channel layouts in
AVCodec.ch_layouts. This means that if ch_layout.u.map[i].id is strictly
ascending for 0 <= i 

Right, misread av_channel_layout_compare() as rejecting layouts that 
were not the same order.





I guess the encode.c check could be improved with
av_channel_layout_retype().



ch_layout is not supposed to be set by lavc for encoders.


I didn't mean to set the layout for encoders, i meant it as a way for 
encode.c to compare input layouts with encoder-supported native layouts, 
because of my misunderstanding of how av_channel_layout_compare() behaved.





In this case the union in AVChannelLayout is not an uint64_t mask,
but a pointer to a custom map.

Signed-off-by: Andreas Rheinhardt 
---
   libavcodec/ac3enc.c | 6 +-
   1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 7a6bcf7900..dc197c1517 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2192,18 +2192,14 @@ av_cold int ff_ac3_encode_close(AVCodecContext
*avctx)
   static av_cold int set_channel_info(AVCodecContext *avctx)
   {
   AC3EncodeContext *s = avctx->priv_data;
+    uint64_t mask = av_channel_layout_subset(&avctx->ch_layout,
~(uint64_t)0);


Might as well use UINT64_MAX.



This is a bitfield, so I intentionally used a bit-operation.


Then ~UINT64_C(0).




   int channels = avctx->ch_layout.nb_channels;
-    uint64_t mask = avctx->ch_layout.u.mask;
     if (channels < 1 || channels > AC3_MAX_CHANNELS)
   return AVERROR(EINVAL);
   if (mask > 0x7FF)
   return AVERROR(EINVAL);
   -    if (!mask)
-    av_channel_layout_default(&avctx->ch_layout, channels);
-    mask = avctx->ch_layout.u.mask;
-
   s->lfe_on   = !!(mask & AV_CH_LOW_FREQUENCY);
   s->channels = channels;
   s->fbw_channels = channels - s->lfe_on;


___
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 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE

2024-04-07 Thread Andreas Rheinhardt
James Almer:
> On 4/7/2024 5:39 PM, Andreas Rheinhardt wrote:
>> It is perfectly legal for users to use a custom layout
>> that is equivalent to a supported native one.
> 
> Is that really the case? FFCodec.p.ch_layouts[] has a list of native
> ones, and the generic encode.c code will reject anything not in it.
> 

This is not true. It allows everything that is equivalent (in the
av_channel_layout_compare() sense) to one of the channel layouts in
AVCodec.ch_layouts. This means that if ch_layout.u.map[i].id is strictly
ascending for 0 <= i  I guess the encode.c check could be improved with
> av_channel_layout_retype().
> 

ch_layout is not supposed to be set by lavc for encoders.

>> In this case the union in AVChannelLayout is not an uint64_t mask,
>> but a pointer to a custom map.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>   libavcodec/ac3enc.c | 6 +-
>>   1 file changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
>> index 7a6bcf7900..dc197c1517 100644
>> --- a/libavcodec/ac3enc.c
>> +++ b/libavcodec/ac3enc.c
>> @@ -2192,18 +2192,14 @@ av_cold int ff_ac3_encode_close(AVCodecContext
>> *avctx)
>>   static av_cold int set_channel_info(AVCodecContext *avctx)
>>   {
>>   AC3EncodeContext *s = avctx->priv_data;
>> +    uint64_t mask = av_channel_layout_subset(&avctx->ch_layout,
>> ~(uint64_t)0);
> 
> Might as well use UINT64_MAX.
> 

This is a bitfield, so I intentionally used a bit-operation.

>>   int channels = avctx->ch_layout.nb_channels;
>> -    uint64_t mask = avctx->ch_layout.u.mask;
>>     if (channels < 1 || channels > AC3_MAX_CHANNELS)
>>   return AVERROR(EINVAL);
>>   if (mask > 0x7FF)
>>   return AVERROR(EINVAL);
>>   -    if (!mask)
>> -    av_channel_layout_default(&avctx->ch_layout, channels);
>> -    mask = avctx->ch_layout.u.mask;
>> -
>>   s->lfe_on   = !!(mask & AV_CH_LOW_FREQUENCY);
>>   s->channels = channels;
>>   s->fbw_channels = channels - s->lfe_on;

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

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


[FFmpeg-devel] [PATCH 07/17] avcodec/ac3enc: Remove disabled code for RealAudio variant of AC-3

2024-04-07 Thread Andreas Rheinhardt
Implicitly disabled by 4679a474f06c229b10976d7f0b4eee0613c2715a.
Given that no one has ever complained about this, this commit
removes the now dead code.

Signed-off-by: Andreas Rheinhardt 
---
 doc/encoders.texi|  3 +--
 libavcodec/ac3enc.c  | 43 +--
 libavcodec/ac3enc.h  |  2 --
 libavcodec/eac3enc.c |  9 ++---
 4 files changed, 16 insertions(+), 41 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 8dd709186e..c08e40ee45 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -144,8 +144,7 @@ If this option is unspecified it is set to @samp{aac_low}.
 
 AC-3 audio encoders.
 
-These encoders implement part of ATSC A/52:2010 and ETSI TS 102 366, as well as
-the undocumented RealAudio 3 (a.k.a. dnet).
+These encoders implement part of ATSC A/52:2010 and ETSI TS 102 366.
 
 The @var{ac3} encoder uses floating-point math, while the @var{ac3_fixed}
 encoder only uses fixed-point integer math. This does not mean that one is
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 32aaf89ec1..12bd3b25f3 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -874,8 +874,8 @@ static av_cold void bit_alloc_init(AC3EncodeContext *s)
 /* compute real values */
 /* currently none of these values change during encoding, so we can just
set them once at initialization */
-s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> 
s->bit_alloc.sr_shift;
-s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> 
s->bit_alloc.sr_shift;
+s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code];
+s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code];
 s->bit_alloc.slow_gain  = ff_ac3_slow_gain_tab[s->slow_gain_code];
 s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
 s->bit_alloc.floor  = ff_ac3_floor_tab[s->floor_code];
@@ -1812,8 +1812,6 @@ static void dprint_options(AC3EncodeContext *s)
 switch (s->bitstream_id) {
 case  6: msg = "AC-3 (alt syntax)";   break;
 case  8: msg = "AC-3 (standard)"; break;
-case  9: msg = "AC-3 (dnet half-rate)";   break;
-case 10: msg = "AC-3 (dnet quater-rate)"; break;
 case 16: msg = "E-AC-3 (enhanced)";   break;
 default: msg = "ERROR";
 }
@@ -2132,18 +2130,8 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s)
 }
 
 /* set bitstream id for alternate bitstream syntax */
-if (!s->eac3 && (opt->extended_bsi_1 || opt->extended_bsi_2)) {
-if (s->bitstream_id > 8 && s->bitstream_id < 11) {
-if (!s->warned_alternate_bitstream) {
-av_log(avctx, AV_LOG_WARNING, "alternate bitstream syntax is "
-   "not compatible with reduced samplerates. writing of "
-   "extended bitstream information will be disabled.\n");
-s->warned_alternate_bitstream = 1;
-}
-} else {
-s->bitstream_id = 6;
-}
-}
+if (!s->eac3 && (opt->extended_bsi_1 || opt->extended_bsi_2))
+s->bitstream_id = 6;
 
 return 0;
 }
@@ -2233,23 +2221,18 @@ static av_cold void set_channel_info(AVCodecContext 
*avctx)
 static av_cold int validate_options(AC3EncodeContext *s)
 {
 AVCodecContext *avctx = s->avctx;
-int i, ret, max_sr;
+int ret;
 
 set_channel_info(avctx);
 
-/* validate sample rate */
-/* note: max_sr could be changed from 2 to 5 for E-AC-3 once we find a
- decoder that supports half sample rate so we can validate that
- the generated files are correct. */
-max_sr = s->eac3 ? 2 : 8;
-for (i = 0; i <= max_sr; i++) {
-if ((ff_ac3_sample_rate_tab[i % 3] >> (i / 3)) == avctx->sample_rate)
+for (int i = 0;; i++) {
+if (ff_ac3_sample_rate_tab[i] == avctx->sample_rate) {
+s->bit_alloc.sr_code = i;
 break;
+}
 }
 s->sample_rate= avctx->sample_rate;
-s->bit_alloc.sr_shift = i / 3;
-s->bit_alloc.sr_code  = i % 3;
-s->bitstream_id   = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;
+s->bitstream_id   = s->eac3 ? 16 : 8;
 
 /* select a default bit rate if not set by the user */
 if (!avctx->bit_rate) {
@@ -2297,7 +2280,7 @@ static av_cold int validate_options(AC3EncodeContext *s)
parameter selection */
 min_br_code = -1;
 min_br_dist = INT64_MAX;
-for (i = 0; i < 19; i++) {
+for (int i = 0; i < 19; i++) {
 long long br_dist = llabs(ff_ac3_bitrate_tab[i] * 1000 - 
avctx->bit_rate);
 if (br_dist < min_br_dist) {
 min_br_dist = br_dist;
@@ -2313,8 +2296,8 @@ static av_cold int validate_options(AC3EncodeContext *s)
 } else {
 int best_br = 0, best_code = 0;
 long long best_diff = INT64_MAX;
-for (i = 0; i < 19; i++) {
-int br   = (ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shif

[FFmpeg-devel] [PATCH 17/17] avformat/img2: Avoid relocations for ff_img_tags

2024-04-07 Thread Andreas Rheinhardt
The strings here are so short that using a pointer is wasteful
(the longest string takes nine bytes; on 64 bit systems,
the pointer+padding already take 12 bytes). So avoid them
and add asserts to ensure that no one ever tries to use a too
long tag.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/img2.c | 148 -
 libavformat/img2.h |   2 +-
 2 files changed, 80 insertions(+), 70 deletions(-)

diff --git a/libavformat/img2.c b/libavformat/img2.c
index 06e48549ac..9981867f82 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -20,80 +20,90 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "libavutil/avstring.h"
 #include "internal.h"
 #include "img2.h"
 
+#define IMG_TAGS(TAG)   \
+TAG(MJPEG,   jpeg ) \
+TAG(MJPEG,   jpg  ) \
+TAG(MJPEG,   jps  ) \
+TAG(MJPEG,   mpo  ) \
+TAG(LJPEG,   ljpg ) \
+TAG(JPEGLS,  jls  ) \
+TAG(PNG, png  ) \
+TAG(PNG, pns  ) \
+TAG(PNG, mng  ) \
+TAG(PPM, ppm  ) \
+TAG(PPM, pnm  ) \
+TAG(PGM, pgm  ) \
+TAG(PGMYUV,  pgmyuv   ) \
+TAG(PBM, pbm  ) \
+TAG(PAM, pam  ) \
+TAG(PFM, pfm  ) \
+TAG(PHM, phm  ) \
+TAG(CRI, cri  ) \
+TAG(ALIAS_PIX,   pix  ) \
+TAG(DDS, dds  ) \
+TAG(MPEG1VIDEO,  mpg1-img ) \
+TAG(MPEG2VIDEO,  mpg2-img ) \
+TAG(MPEG4,   mpg4-img ) \
+TAG(RAWVIDEO,y) \
+TAG(RAWVIDEO,raw  ) \
+TAG(BMP, bmp  ) \
+TAG(TARGA,   tga  ) \
+TAG(TIFF,tiff ) \
+TAG(TIFF,tif  ) \
+TAG(TIFF,dng  ) \
+TAG(SGI, sgi  ) \
+TAG(PTX, ptx  ) \
+TAG(PHOTOCD, pcd  ) \
+TAG(PCX, pcx  ) \
+TAG(QDRAW,   pic  ) \
+TAG(QDRAW,   pct  ) \
+TAG(QDRAW,   pict ) \
+TAG(SUNRAST, sun  ) \
+TAG(SUNRAST, ras  ) \
+TAG(SUNRAST, rs   ) \
+TAG(SUNRAST, im1  ) \
+TAG(SUNRAST, im8  ) \
+TAG(SUNRAST, im24 ) \
+TAG(SUNRAST, im32 ) \
+TAG(SUNRAST, sunras   ) \
+TAG(SVG, svg  ) \
+TAG(SVG, svgz ) \
+TAG(JPEG2000,j2c  ) \
+TAG(JPEG2000,jp2  ) \
+TAG(JPEG2000,jpc  ) \
+TAG(JPEG2000,j2k  ) \
+TAG(DPX, dpx  ) \
+TAG(EXR, exr  ) \
+TAG(PICTOR,  pic  ) \
+TAG(V210X,   yuv10) \
+TAG(WEBP,webp ) \
+TAG(XBM, xbm  ) \
+TAG(XPM, xpm  ) \
+TAG(XFACE,   xface) \
+TAG(XWD, xwd  ) \
+TAG(GEM, img  ) \
+TAG(GEM, ximg ) \
+TAG(GEM, timg ) \
+TAG(VBN, vbn  ) \
+TAG(JPEGXL,  jxl  ) \
+TAG(QOI, qoi  ) \
+TAG(RADIANCE_HDR,hdr  ) \
+TAG(WBMP,wbmp ) \
+TAG(NONE, )
+
+#define LENGTH_CHECK(CODECID, STR) \
+static_assert(sizeof(#STR) <= sizeof(ff_img_tags->str), #STR " does not 
fit into IdStrMap.str\n");
+IMG_TAGS(LENGTH_CHECK)
+
 const IdStrMap ff_img_tags[] = {
-{ AV_CODEC_ID_MJPEG,  "jpeg" },
-{ AV_CODEC_ID_MJPEG,  "jpg"  },
-{ AV_CODEC_ID_MJPEG,  "jps"  },
-{ AV_CODEC_ID_MJPEG,  "mpo"  },
-{ AV_CODEC_ID_LJPEG,  "ljpg" },
-{ AV_CODEC_ID_JPEGLS, "jls"  },
-{ AV_CODEC_ID_PNG,"png"  },
-{ AV_CODEC_ID_PNG,"pns"  },
-{ AV_CODEC_ID_PNG,"mng"  },
-{ AV_CODEC_ID_PPM,"ppm"  },
-{ AV_CODEC_ID_PPM,"pnm"  },
-{ AV_CODEC_ID_PGM,"pgm"  },
-{ AV_CODEC_ID_PGMYUV, "pgmyuv"   },
-{ AV_CODEC_ID_PBM,"pbm"  },
-{ AV_CODEC_ID_PAM,"pam"  },
-{ AV_CODEC_ID_PFM,"pfm"  },
-{ AV_CODEC_ID_PHM,"phm"  },
-{ AV_CODEC_ID_CRI,"cri"  },
-{ AV_CODEC_ID_ALIAS_PIX,  "pix"  },
-{ AV_CODEC_ID_DDS,"dds"  },
-{ AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },
-{ AV_CODEC_ID_MPEG2VIDEO, "mpg2-img" },
-{ AV_CODEC_ID_MPEG4,  "mpg4-img" },
-{ AV_CODEC_ID_RAWVIDEO,   "y"},
-{ AV_CODEC_ID_RAWVIDEO,   "raw"  },
-{ AV_CODEC_ID_BMP,"bmp"  },
-{ AV_CODEC_ID_TARGA,  "tga"  },
-{ AV_CODEC_ID_TIFF,   "tiff" },
-{ AV_CODEC_ID_TIFF, 

[FFmpeg-devel] [PATCH 16/17] avcodec/flacenc: Avoid shift where possible

2024-04-07 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/flacenc.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index e29be5822b..3a9578f5cd 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -525,11 +525,10 @@ static void copy_samples(FlacEncodeContext *s, const void 
*samples)
 {
 int i, j, ch;
 FlacFrame *frame;
-int shift = av_get_bytes_per_sample(s->avctx->sample_fmt) * 8 -
-s->avctx->bits_per_raw_sample;
 
-#define COPY_SAMPLES(bits) do { \
+#define COPY_SAMPLES(bits, shift0) do { \
 const int ## bits ## _t *samples0 = samples;\
+const int shift = shift0;   \
 frame = &s->frame;  \
 for (i = 0, j = 0; i < frame->blocksize; i++)   \
 for (ch = 0; ch < s->channels; ch++, j++)   \
@@ -537,9 +536,9 @@ static void copy_samples(FlacEncodeContext *s, const void 
*samples)
 } while (0)
 
 if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S16)
-COPY_SAMPLES(16);
+COPY_SAMPLES(16, 0);
 else
-COPY_SAMPLES(32);
+COPY_SAMPLES(32, 32 - s->avctx->bits_per_raw_sample);
 }
 
 
-- 
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 15/17] avcodec/ac3enc: Move EAC-3 specific initialization to eac3enc.c

2024-04-07 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  |  8 +---
 libavcodec/eac3enc.c | 26 ++
 libavcodec/eac3enc.h | 10 --
 3 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 8ad89b6a84..f520e72fc0 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2554,8 +2554,6 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
 
 s->avctx = avctx;
 
-s->eac3 = avctx->codec_id == AV_CODEC_ID_EAC3;
-
 ret = validate_options(s);
 if (ret)
 return ret;
@@ -2578,11 +2576,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
 s->crc_inv[1] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, 
CRC16_POLY);
 }
 
-if (CONFIG_EAC3_ENCODER && s->eac3) {
-static AVOnce init_static_once_eac3 = AV_ONCE_INIT;
-ff_thread_once(&init_static_once_eac3, ff_eac3_exponent_init);
-s->output_frame_header = ff_eac3_output_frame_header;
-} else
+if (!s->output_frame_header)
 s->output_frame_header = ac3_output_frame_header;
 
 set_bandwidth(s);
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index 1ee140f13a..c957174a70 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -27,6 +27,7 @@
 #define AC3ENC_FLOAT 1
 
 #include "libavutil/attributes.h"
+#include "libavutil/thread.h"
 #include "ac3enc.h"
 #include "codec_internal.h"
 #include "eac3enc.h"
@@ -47,7 +48,10 @@ static const AVClass eac3enc_class = {
 static int8_t eac3_frame_expstr_index_tab[3][4][4][4][4][4];
 
 
-av_cold void ff_eac3_exponent_init(void)
+/**
+ * Initialize E-AC-3 exponent tables.
+ */
+static av_cold void eac3_exponent_init(void)
 {
 int i;
 
@@ -122,8 +126,10 @@ void ff_eac3_set_cpl_states(AC3EncodeContext *s)
 }
 }
 
-
-void ff_eac3_output_frame_header(AC3EncodeContext *s)
+/**
+ * Write the E-AC-3 frame header to the output bitstream.
+ */
+static void eac3_output_frame_header(AC3EncodeContext *s)
 {
 int blk, ch;
 AC3EncOptions *opt = &s->options;
@@ -243,6 +249,18 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s)
 put_bits(&s->pb, 1, 0);
 }
 
+static av_cold int eac3_encode_init(AVCodecContext *avctx)
+{
+static AVOnce init_static_once = AV_ONCE_INIT;
+AC3EncodeContext *s = avctx->priv_data;
+
+s->eac3 = 1;
+s->output_frame_header = eac3_output_frame_header;
+
+ff_thread_once(&init_static_once, eac3_exponent_init);
+
+return ff_ac3_float_encode_init(avctx);
+}
 
 const FFCodec ff_eac3_encoder = {
 .p.name  = "eac3",
@@ -251,7 +269,7 @@ const FFCodec ff_eac3_encoder = {
 .p.id= AV_CODEC_ID_EAC3,
 .p.capabilities  = AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
 .priv_data_size  = sizeof(AC3EncodeContext),
-.init= ff_ac3_float_encode_init,
+.init= eac3_encode_init,
 FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
 .close   = ff_ac3_encode_close,
 .p.sample_fmts   = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
diff --git a/libavcodec/eac3enc.h b/libavcodec/eac3enc.h
index 7d6155975d..0523de411b 100644
--- a/libavcodec/eac3enc.h
+++ b/libavcodec/eac3enc.h
@@ -29,11 +29,6 @@
 
 #include "ac3enc.h"
 
-/**
- * Initialize E-AC-3 exponent tables.
- */
-void ff_eac3_exponent_init(void);
-
 /**
  * Determine frame exponent strategy use and indices.
  */
@@ -46,9 +41,4 @@ void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s);
  */
 void ff_eac3_set_cpl_states(AC3EncodeContext *s);
 
-/**
- * Write the E-AC-3 frame header to the output bitstream.
- */
-void ff_eac3_output_frame_header(AC3EncodeContext *s);
-
 #endif /* AVCODEC_EAC3ENC_H */
-- 
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 13/17] avcodec/ac3enc_float: Remove uninformative error message

2024-04-07 Thread Andreas Rheinhardt
AVERROR(ENOMEM) is enough.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc_float.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index 77a7725f31..cbe87dc5fe 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -88,10 +88,8 @@ 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) {
-av_log(s->avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
+if (!window)
 return AVERROR(ENOMEM);
-}
 
 ff_kbd_window_init(window, 5.0, AC3_BLOCK_SIZE);
 s->mdct_window = window;
-- 
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 14/17] avcodec/ac3enc: Avoid function pointers to initialize MDCT

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

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 7adb1c444a..8ad89b6a84 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2589,10 +2589,6 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
 
 bit_alloc_init(s);
 
-ret = s->mdct_init(s);
-if (ret)
-return ret;
-
 ret = allocate_buffers(s);
 if (ret)
 return ret;
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 271f0eb8eb..227744d27f 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -257,9 +257,6 @@ typedef struct AC3EncodeContext {
 /** fixed vs. float function pointers */
 void (*encode_frame)(struct AC3EncodeContext *s);
 
-/* fixed vs. float function pointers */
-int  (*mdct_init)(struct AC3EncodeContext *s);
-
 /* AC-3 vs. E-AC-3 function pointers */
 void (*output_frame_header)(struct AC3EncodeContext *s);
 } AC3EncodeContext;
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index b8a4d88a42..d2f4cecd72 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -74,7 +74,7 @@ static CoefType calc_cpl_coord(CoefSumType energy_ch, 
CoefSumType energy_cpl)
  * @param s  AC-3 encoder private context
  * @return   0 on success, negative error code on failure
  */
-static av_cold int ac3_fixed_mdct_init(AC3EncodeContext *s)
+static av_cold int ac3_fixed_mdct_init(AVCodecContext *avctx, AC3EncodeContext 
*s)
 {
 float fwin[AC3_BLOCK_SIZE];
 const float scale = -1.0f;
@@ -89,7 +89,7 @@ static av_cold int ac3_fixed_mdct_init(AC3EncodeContext *s)
 
 s->mdct_window = iwin;
 
-s->fdsp = avpriv_alloc_fixed_dsp(s->avctx->flags & AV_CODEC_FLAG_BITEXACT);
+s->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT);
 if (!s->fdsp)
 return AVERROR(ENOMEM);
 
@@ -101,9 +101,15 @@ static av_cold int ac3_fixed_mdct_init(AC3EncodeContext *s)
 static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
 {
 AC3EncodeContext *s = avctx->priv_data;
+int ret;
+
 s->fixed_point = 1;
 s->encode_frame= encode_frame;
-s->mdct_init   = ac3_fixed_mdct_init;
+
+ret = ac3_fixed_mdct_init(avctx, s);
+if (ret < 0)
+return ret;
+
 return ff_ac3_encode_init(avctx);
 }
 
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index cbe87dc5fe..cfd233da09 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -102,12 +102,17 @@ static av_cold int ac3_float_mdct_init(AC3EncodeContext 
*s)
 av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx)
 {
 AC3EncodeContext *s = avctx->priv_data;
+int ret;
 
 s->encode_frame= encode_frame;
-s->mdct_init   = ac3_float_mdct_init;
 s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
 if (!s->fdsp)
 return AVERROR(ENOMEM);
+
+ret = ac3_float_mdct_init(s);
+if (ret < 0)
+return ret;
+
 return ff_ac3_encode_init(avctx);
 }
 
-- 
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 12/17] avcodec/ac3enc: Deduplicate copying input samples

2024-04-07 Thread Andreas Rheinhardt
These memcpy operands only depend upon sizeof(SampleType)
(and this size is actually the same for both the fixed-point
and the floating-point encoders for most (all supported?)
systems).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  | 25 -
 libavcodec/ac3enc.h  |  2 +-
 libavcodec/ac3enc_template.c | 27 +--
 3 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 681b227d3d..7adb1c444a 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -503,6 +503,27 @@ 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(&s->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.
@@ -1996,7 +2017,9 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 if (s->bit_alloc.sr_code == 1 || s->eac3)
 ac3_adjust_frame_size(s);
 
-s->encode_frame(s, frame);
+copy_input_samples(s, frame->extended_data);
+
+s->encode_frame(s);
 
 ac3_apply_rematrixing(s);
 
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 8d6cb3b3de..271f0eb8eb 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -255,7 +255,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, const AVFrame *frame);
+void (*encode_frame)(struct AC3EncodeContext *s);
 
 /* fixed vs. float function pointers */
 int  (*mdct_init)(struct AC3EncodeContext *s);
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 3646e1dcaa..b0f9e69ee8 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -38,29 +38,6 @@
 #include "eac3enc.h"
 
 
-/*
- * Copy input samples.
- * Channels are reordered from FFmpeg's default order to AC-3 order.
- */
-static void copy_input_samples(AC3EncodeContext *s, SampleType **samples)
-{
-int ch;
-
-/* copy and remap input samples */
-for (ch = 0; ch < s->channels; ch++) {
-/* copy last 256 samples of previous frame to the start of the current 
frame */
-memcpy(&s->planar_samples[ch][0],
-   (SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE * 
s->num_blocks,
-   AC3_BLOCK_SIZE * sizeof(SampleType));
-
-/* copy new samples for current frame */
-memcpy((SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE,
-   samples[s->channel_map[ch]],
-   AC3_BLOCK_SIZE * s->num_blocks * sizeof(SampleType));
-}
-}
-
-
 /*
  * Apply the MDCT to input samples to generate frequency coefficients.
  * This applies the KBD window and normalizes the input to reduce precision
@@ -353,10 +330,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext 
*s)
 }
 
 
-static void encode_frame(AC3EncodeContext *s, const AVFrame *frame)
+static void encode_frame(AC3EncodeContext *s)
 {
-copy_input_samples(s, (SampleType **)frame->extended_data);
-
 apply_mdct(s);
 
 s->cpl_on = s->cpl_enabled;
-- 
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 06/17] avcodec/ac3enc: Remove always-false sample rate check

2024-04-07 Thread Andreas Rheinhardt
encode_preinit_audio() already checks that the sample rate
is among AVCodec.supported_samplerates.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 272d2481d9..32aaf89ec1 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2246,10 +2246,6 @@ static av_cold int validate_options(AC3EncodeContext *s)
 if ((ff_ac3_sample_rate_tab[i % 3] >> (i / 3)) == avctx->sample_rate)
 break;
 }
-if (i > max_sr) {
-av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
-return AVERROR(EINVAL);
-}
 s->sample_rate= avctx->sample_rate;
 s->bit_alloc.sr_shift = i / 3;
 s->bit_alloc.sr_code  = i % 3;
-- 
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 11/17] avcodec/ac3enc: Deduplicate allocating buffers

2024-04-07 Thread Andreas Rheinhardt
These allocations only depend upon sizeof(SampleType)
(and this size is actually the same for both the fixed-point
and the floating-point encoders for most (all supported?)
systems).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  | 16 +++-
 libavcodec/ac3enc.h  |  7 ++-
 libavcodec/ac3enc_fixed.c|  1 -
 libavcodec/ac3enc_float.c|  1 -
 libavcodec/ac3enc_template.c | 32 +++-
 5 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index ef1ac381c1..681b227d3d 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -52,6 +52,9 @@
 #include "ac3enc.h"
 #include "eac3enc.h"
 
+#define SAMPLETYPE_SIZE(ctx) (sizeof(float) == sizeof(int32_t) ? sizeof(float) 
: \
+  (ctx)->fixed_point ? sizeof(int32_t) : 
sizeof(float))
+
 typedef struct AC3Mant {
 int16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for 
bap=1,2,4
 int mant1_cnt, mant2_cnt, mant4_cnt;///< mantissa counts for bap=1,2,4
@@ -2429,10 +2432,21 @@ 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;
+const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
+
+if (!(s->windowed_samples = av_malloc(sampletype_size * AC3_WINDOW_SIZE)))
+return AVERROR(ENOMEM);
 
-if (s->allocate_sample_buffers(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);
+if (!s->planar_samples[ch])
+return AVERROR(ENOMEM);
+}
+
 if (!FF_ALLOC_TYPED_ARRAY(s->bap_buffer, total_coefs)  ||
 !FF_ALLOC_TYPED_ARRAY(s->bap1_buffer,total_coefs)  ||
 !FF_ALLOCZ_TYPED_ARRAY(s->mdct_coef_buffer,  total_coefs)  ||
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 3dc8acfd91..8d6cb3b3de 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -232,8 +232,8 @@ typedef struct AC3EncodeContext {
 int frame_bits; ///< all frame bits except 
exponents and mantissas
 int exponent_bits;  ///< number of bits used for 
exponents
 
-SampleType *windowed_samples;
-SampleType **planar_samples;
+void *windowed_samples;
+uint8_t **planar_samples;
 uint8_t *bap_buffer;
 uint8_t *bap1_buffer;
 CoefType *mdct_coef_buffer;
@@ -260,9 +260,6 @@ typedef struct AC3EncodeContext {
 /* fixed vs. float function pointers */
 int  (*mdct_init)(struct AC3EncodeContext *s);
 
-/* fixed vs. float templated function pointers */
-int  (*allocate_sample_buffers)(struct AC3EncodeContext *s);
-
 /* AC-3 vs. E-AC-3 function pointers */
 void (*output_frame_header)(struct AC3EncodeContext *s);
 } AC3EncodeContext;
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 4a24cce833..b8a4d88a42 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -104,7 +104,6 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext 
*avctx)
 s->fixed_point = 1;
 s->encode_frame= encode_frame;
 s->mdct_init   = ac3_fixed_mdct_init;
-s->allocate_sample_buffers = allocate_sample_buffers;
 return ff_ac3_encode_init(avctx);
 }
 
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index e0907fed05..77a7725f31 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -107,7 +107,6 @@ av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx)
 
 s->encode_frame= encode_frame;
 s->mdct_init   = ac3_float_mdct_init;
-s->allocate_sample_buffers = allocate_sample_buffers;
 s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
 if (!s->fdsp)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 56ce36c012..3646e1dcaa 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -31,8 +31,6 @@
 #include 
 
 #include "libavutil/attributes.h"
-#include "libavutil/internal.h"
-#include "libavutil/mem.h"
 #include "libavutil/mem_internal.h"
 
 #include "audiodsp.h"
@@ -40,23 +38,6 @@
 #include "eac3enc.h"
 
 
-static int allocate_sample_buffers(AC3EncodeContext *s)
-{
-int ch;
-
-if (!FF_ALLOC_TYPED_ARRAY(s->windowed_samples, AC3_WINDOW_SIZE) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->planar_samples,  s->channels))
-return AVERROR(ENOMEM);
-
-for (ch = 0; ch < s->channels; ch++) {
-if (!(s->planar_samples[ch] = av_mallocz((AC3_FRAME_SIZE + 
AC3_BLOCK_SIZE) 

[FFmpeg-devel] [PATCH 10/17] avcodec/ac3enc: Share more code between fixed/float encoders

2024-04-07 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  | 19 +--
 libavcodec/ac3enc.h  |  5 +
 libavcodec/ac3enc_template.c | 15 +--
 3 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1f05436720..ef1ac381c1 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -315,7 +315,7 @@ static void validate_mix_level(void *log_ctx, const char 
*opt_name,
  *
  * @param s  AC-3 encoder private context
  */
-int ff_ac3_validate_metadata(AC3EncodeContext *s)
+static int ac3_validate_metadata(AC3EncodeContext *s)
 {
 AVCodecContext *avctx = s->avctx;
 AC3EncOptions *opt = &s->options;
@@ -488,7 +488,7 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s)
  *
  * @param s  AC-3 encoder private context
  */
-void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
+static void ac3_adjust_frame_size(AC3EncodeContext *s)
 {
 while (s->bits_written >= s->bit_rate && s->samples_written >= 
s->sample_rate) {
 s->bits_written-= s->bit_rate;
@@ -1984,9 +1984,16 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 AC3EncodeContext *const s = avctx->priv_data;
 int ret;
 
-ret = s->encode_frame(s, frame);
-if (ret < 0)
-return ret;
+if (s->options.allow_per_frame_metadata) {
+ret = ac3_validate_metadata(s);
+if (ret)
+return ret;
+}
+
+if (s->bit_alloc.sr_code == 1 || s->eac3)
+ac3_adjust_frame_size(s);
+
+s->encode_frame(s, frame);
 
 ac3_apply_rematrixing(s);
 
@@ -2327,7 +2334,7 @@ static av_cold int validate_options(AC3EncodeContext *s)
 if (s->cutoff > (s->sample_rate >> 1))
 s->cutoff = s->sample_rate >> 1;
 
-ret = ff_ac3_validate_metadata(s);
+ret = ac3_validate_metadata(s);
 if (ret)
 return ret;
 
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 1a51423ac1..3dc8acfd91 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -255,7 +255,7 @@ typedef struct AC3EncodeContext {
 int ref_bap_set; ///< indicates if 
ref_bap pointers have been set
 
 /** fixed vs. float function pointers */
-int (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame);
+void (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame);
 
 /* fixed vs. float function pointers */
 int  (*mdct_init)(struct AC3EncodeContext *s);
@@ -277,9 +277,6 @@ int ff_ac3_float_encode_init(AVCodecContext *avctx);
 
 int ff_ac3_encode_close(AVCodecContext *avctx);
 
-int ff_ac3_validate_metadata(AC3EncodeContext *s);
-
-void ff_ac3_adjust_frame_size(AC3EncodeContext *s);
 
 void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s);
 
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 2e0fb9e85a..56ce36c012 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -371,19 +371,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext 
*s)
 }
 
 
-static int encode_frame(AC3EncodeContext *s, const AVFrame *frame)
+static void encode_frame(AC3EncodeContext *s, const AVFrame *frame)
 {
-int ret;
-
-if (s->options.allow_per_frame_metadata) {
-ret = ff_ac3_validate_metadata(s);
-if (ret)
-return ret;
-}
-
-if (s->bit_alloc.sr_code == 1 || (AC3ENC_FLOAT && s->eac3))
-ff_ac3_adjust_frame_size(s);
-
 copy_input_samples(s, (SampleType **)frame->extended_data);
 
 apply_mdct(s);
@@ -399,6 +388,4 @@ static int encode_frame(AC3EncodeContext *s, const AVFrame 
*frame)
 #if AC3ENC_FLOAT
 scale_coefficients(s);
 #endif
-
-return 0;
 }
-- 
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 09/17] avcodec/ac3enc: Move ff_ac3_validate_metadate() upwards

2024-04-07 Thread Andreas Rheinhardt
Will avoid a forward declaration in the next commit.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 420 ++--
 1 file changed, 209 insertions(+), 211 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index c19837e88f..1f05436720 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -273,6 +273,215 @@ static const int8_t ac3_coupling_start_tab[6][3][19] = {
 };
 
 
+#define FLT_OPTION_THRESHOLD 0.01
+
+static int validate_float_option(float v, const float *v_list, int v_list_size)
+{
+int i;
+
+for (i = 0; i < v_list_size; i++) {
+if (v < (v_list[i] + FLT_OPTION_THRESHOLD) &&
+v > (v_list[i] - FLT_OPTION_THRESHOLD))
+break;
+}
+if (i == v_list_size)
+return AVERROR(EINVAL);
+
+return i;
+}
+
+
+static void validate_mix_level(void *log_ctx, const char *opt_name,
+   float *opt_param, const float *list,
+   int list_size, int default_value, int min_value,
+   int *ctx_param)
+{
+int mixlev = validate_float_option(*opt_param, list, list_size);
+if (mixlev < min_value) {
+mixlev = default_value;
+if (*opt_param >= 0.0) {
+av_log(log_ctx, AV_LOG_WARNING, "requested %s is not valid. using "
+   "default value: %0.3f\n", opt_name, list[mixlev]);
+}
+}
+*opt_param = list[mixlev];
+*ctx_param = mixlev;
+}
+
+
+/**
+ * Validate metadata options as set by AVOption system.
+ * These values can optionally be changed per-frame.
+ *
+ * @param s  AC-3 encoder private context
+ */
+int ff_ac3_validate_metadata(AC3EncodeContext *s)
+{
+AVCodecContext *avctx = s->avctx;
+AC3EncOptions *opt = &s->options;
+
+opt->audio_production_info = 0;
+opt->extended_bsi_1= 0;
+opt->extended_bsi_2= 0;
+opt->eac3_mixing_metadata  = 0;
+opt->eac3_info_metadata= 0;
+
+/* determine mixing metadata / xbsi1 use */
+if (s->channel_mode > AC3_CHMODE_STEREO && opt->preferred_stereo_downmix 
!= AC3ENC_OPT_NONE) {
+opt->extended_bsi_1   = 1;
+opt->eac3_mixing_metadata = 1;
+}
+if (s->has_center &&
+(opt->ltrt_center_mix_level >= 0 || opt->loro_center_mix_level >= 0)) {
+opt->extended_bsi_1   = 1;
+opt->eac3_mixing_metadata = 1;
+}
+if (s->has_surround &&
+(opt->ltrt_surround_mix_level >= 0 || opt->loro_surround_mix_level >= 
0)) {
+opt->extended_bsi_1   = 1;
+opt->eac3_mixing_metadata = 1;
+}
+
+if (s->eac3) {
+/* determine info metadata use */
+if (avctx->audio_service_type != AV_AUDIO_SERVICE_TYPE_MAIN)
+opt->eac3_info_metadata = 1;
+if (opt->copyright != AC3ENC_OPT_NONE || opt->original != 
AC3ENC_OPT_NONE)
+opt->eac3_info_metadata = 1;
+if (s->channel_mode == AC3_CHMODE_STEREO &&
+(opt->dolby_headphone_mode != AC3ENC_OPT_NONE || 
opt->dolby_surround_mode != AC3ENC_OPT_NONE))
+opt->eac3_info_metadata = 1;
+if (s->channel_mode >= AC3_CHMODE_2F2R && opt->dolby_surround_ex_mode 
!= AC3ENC_OPT_NONE)
+opt->eac3_info_metadata = 1;
+if (opt->mixing_level != AC3ENC_OPT_NONE || opt->room_type != 
AC3ENC_OPT_NONE ||
+opt->ad_converter_type != AC3ENC_OPT_NONE) {
+opt->audio_production_info = 1;
+opt->eac3_info_metadata= 1;
+}
+} else {
+/* determine audio production info use */
+if (opt->mixing_level != AC3ENC_OPT_NONE || opt->room_type != 
AC3ENC_OPT_NONE)
+opt->audio_production_info = 1;
+
+/* determine xbsi2 use */
+if (s->channel_mode >= AC3_CHMODE_2F2R && opt->dolby_surround_ex_mode 
!= AC3ENC_OPT_NONE)
+opt->extended_bsi_2 = 1;
+if (s->channel_mode == AC3_CHMODE_STEREO && opt->dolby_headphone_mode 
!= AC3ENC_OPT_NONE)
+opt->extended_bsi_2 = 1;
+if (opt->ad_converter_type != AC3ENC_OPT_NONE)
+opt->extended_bsi_2 = 1;
+}
+
+/* validate AC-3 mixing levels */
+if (!s->eac3) {
+if (s->has_center) {
+validate_mix_level(avctx, "center_mix_level", 
&opt->center_mix_level,
+   cmixlev_options, CMIXLEV_NUM_OPTIONS, 1, 0,
+   &s->center_mix_level);
+}
+if (s->has_surround) {
+validate_mix_level(avctx, "surround_mix_level", 
&opt->surround_mix_level,
+   surmixlev_options, SURMIXLEV_NUM_OPTIONS, 1, 0,
+   &s->surround_mix_level);
+}
+}
+
+/* validate extended bsi 1 / mixing metadata */
+if (opt->extended_bsi_1 || opt->eac3_mixing_metadata) {
+/* default preferred stereo downmix */
+if (opt->preferred_stereo_downmix == AC3ENC_OPT_NONE)
+opt->preferred_

[FFmpeg-devel] [PATCH 08/17] avcodec/ac3enc: Use common encode_frame function

2024-04-07 Thread Andreas Rheinhardt
This is in preparation for sharing even more stuff
common to the fixed and floating-point encoders.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c  |  8 ++--
 libavcodec/ac3enc.h  | 16 +---
 libavcodec/ac3enc_fixed.c|  3 ++-
 libavcodec/ac3enc_float.c|  4 +++-
 libavcodec/ac3enc_template.c |  6 ++
 libavcodec/eac3enc.c |  2 +-
 6 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 12bd3b25f3..c19837e88f 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1769,12 +1769,16 @@ static void ac3_output_frame(AC3EncodeContext *s, 
unsigned char *frame)
 output_frame_end(s);
 }
 
-int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
-   const AVFrame *frame, int *got_packet_ptr)
+int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+const AVFrame *frame, int *got_packet_ptr)
 {
 AC3EncodeContext *const s = avctx->priv_data;
 int ret;
 
+ret = s->encode_frame(s, frame);
+if (ret < 0)
+return ret;
+
 ac3_apply_rematrixing(s);
 
 ac3_process_exponents(s);
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index dad53cc4bb..1a51423ac1 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -49,7 +49,6 @@
 
 #if AC3ENC_FLOAT
 #include "libavutil/float_dsp.h"
-#define AC3_NAME(x) ff_ac3_float_ ## x
 #define MAC_COEF(d,a,b) ((d)+=(a)*(b))
 #define COEF_MIN (-16777215.0/16777216.0)
 #define COEF_MAX ( 16777215.0/16777216.0)
@@ -59,7 +58,6 @@ typedef float CoefType;
 typedef float CoefSumType;
 #else
 #include "libavutil/fixed_dsp.h"
-#define AC3_NAME(x) ff_ac3_fixed_ ## x
 #define MAC_COEF(d,a,b) MAC64(d,a,b)
 #define COEF_MIN -16777215
 #define COEF_MAX  16777215
@@ -256,6 +254,9 @@ typedef struct AC3EncodeContext {
 uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit 
allocation pointers (bap)
 int ref_bap_set; ///< indicates if 
ref_bap pointers have been set
 
+/** fixed vs. float function pointers */
+int (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame);
+
 /* fixed vs. float function pointers */
 int  (*mdct_init)(struct AC3EncodeContext *s);
 
@@ -282,14 +283,7 @@ void ff_ac3_adjust_frame_size(AC3EncodeContext *s);
 
 void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s);
 
-int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
-   const AVFrame *frame, int *got_packet_ptr);
-
-/* prototypes for functions in ac3enc_template.c */
-
-int ff_ac3_fixed_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
-  const AVFrame *frame, int *got_packet_ptr);
-int ff_ac3_float_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
-  const AVFrame *frame, int *got_packet_ptr);
+int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+const AVFrame *frame, int *got_packet_ptr);
 
 #endif /* AVCODEC_AC3ENC_H */
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index c399d6cd09..4a24cce833 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -102,6 +102,7 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext 
*avctx)
 {
 AC3EncodeContext *s = avctx->priv_data;
 s->fixed_point = 1;
+s->encode_frame= encode_frame;
 s->mdct_init   = ac3_fixed_mdct_init;
 s->allocate_sample_buffers = allocate_sample_buffers;
 return ff_ac3_encode_init(avctx);
@@ -116,7 +117,7 @@ const FFCodec ff_ac3_fixed_encoder = {
 .p.capabilities  = AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
 .priv_data_size  = sizeof(AC3EncodeContext),
 .init= ac3_fixed_encode_init,
-FF_CODEC_ENCODE_CB(ff_ac3_fixed_encode_frame),
+FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
 .close   = ff_ac3_encode_close,
 .p.sample_fmts   = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
   AV_SAMPLE_FMT_NONE },
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index 24960f318b..e0907fed05 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -104,6 +104,8 @@ static av_cold int ac3_float_mdct_init(AC3EncodeContext *s)
 av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx)
 {
 AC3EncodeContext *s = avctx->priv_data;
+
+s->encode_frame= encode_frame;
 s->mdct_init   = ac3_float_mdct_init;
 s->allocate_sample_buffers = allocate_sample_buffers;
 s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
@@ -120,7 +122,7 @@ const FFCodec ff_ac3_encoder = {
 .p.capabilities  = AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
 .priv_data_size  = sizeof(AC3EncodeContext),
 .init

[FFmpeg-devel] [PATCH 05/17] avcodec/ac3enc: Avoid copying strings

2024-04-07 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 88 +
 1 file changed, 50 insertions(+), 38 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 31b9474822..272d2481d9 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -30,7 +30,6 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
-#include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/crc.h"
 #include "libavutil/emms.h"
@@ -1807,17 +1806,18 @@ static void dprint_options(AC3EncodeContext *s)
 #ifdef DEBUG
 AVCodecContext *avctx = s->avctx;
 AC3EncOptions *opt = &s->options;
+const char *msg;
 char strbuf[32];
 
 switch (s->bitstream_id) {
-case  6:  av_strlcpy(strbuf, "AC-3 (alt syntax)",   32); break;
-case  8:  av_strlcpy(strbuf, "AC-3 (standard)", 32); break;
-case  9:  av_strlcpy(strbuf, "AC-3 (dnet half-rate)",   32); break;
-case 10:  av_strlcpy(strbuf, "AC-3 (dnet quater-rate)", 32); break;
-case 16:  av_strlcpy(strbuf, "E-AC-3 (enhanced)",   32); break;
-default: snprintf(strbuf, 32, "ERROR");
-}
-ff_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id);
+case  6: msg = "AC-3 (alt syntax)";   break;
+case  8: msg = "AC-3 (standard)"; break;
+case  9: msg = "AC-3 (dnet half-rate)";   break;
+case 10: msg = "AC-3 (dnet quater-rate)"; break;
+case 16: msg = "E-AC-3 (enhanced)";   break;
+default: msg = "ERROR";
+}
+ff_dlog(avctx, "bitstream_id: %s (%d)\n", msg, s->bitstream_id);
 ff_dlog(avctx, "sample_fmt: %s\n", 
av_get_sample_fmt_name(avctx->sample_fmt));
 av_channel_layout_describe(&avctx->ch_layout, strbuf, sizeof(strbuf));
 ff_dlog(avctx, "channel_layout: %s\n", strbuf);
@@ -1842,12 +1842,14 @@ static void dprint_options(AC3EncodeContext *s)
 if (opt->audio_production_info) {
 ff_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level);
 switch (opt->room_type) {
-case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); 
break;
-case AC3ENC_OPT_LARGE_ROOM:av_strlcpy(strbuf, "large", 32);
break;
-case AC3ENC_OPT_SMALL_ROOM:av_strlcpy(strbuf, "small", 32);
break;
-default: snprintf(strbuf, 32, "ERROR (%d)", opt->room_type);
+case AC3ENC_OPT_NOT_INDICATED: msg = "notindicated"; break;
+case AC3ENC_OPT_LARGE_ROOM:msg = "large";break;
+case AC3ENC_OPT_SMALL_ROOM:msg = "small";break;
+default:
+snprintf(strbuf, sizeof(strbuf), "ERROR (%d)", opt->room_type);
+msg = strbuf;
 }
-ff_dlog(avctx, "room_type: %s\n", strbuf);
+ff_dlog(avctx, "room_type: %s\n", msg);
 } else {
 ff_dlog(avctx, "mixing_level: {not written}\n");
 ff_dlog(avctx, "room_type: {not written}\n");
@@ -1856,12 +1858,14 @@ static void dprint_options(AC3EncodeContext *s)
 ff_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level);
 if (s->channel_mode == AC3_CHMODE_STEREO) {
 switch (opt->dolby_surround_mode) {
-case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); 
break;
-case AC3ENC_OPT_MODE_ON:   av_strlcpy(strbuf, "on", 32);   
break;
-case AC3ENC_OPT_MODE_OFF:  av_strlcpy(strbuf, "off", 32);  
break;
-default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_mode);
+case AC3ENC_OPT_NOT_INDICATED: msg = "notindicated"; break;
+case AC3ENC_OPT_MODE_ON:   msg = "on";   break;
+case AC3ENC_OPT_MODE_OFF:  msg = "off";  break;
+default:
+snprintf(strbuf, sizeof(strbuf), "ERROR (%d)", 
opt->dolby_surround_mode);
+msg = strbuf;
 }
-ff_dlog(avctx, "dsur_mode: %s\n", strbuf);
+ff_dlog(avctx, "dsur_mode: %s\n", msg);
 } else {
 ff_dlog(avctx, "dsur_mode: {not written}\n");
 }
@@ -1870,12 +1874,14 @@ static void dprint_options(AC3EncodeContext *s)
 if (s->bitstream_id == 6) {
 if (opt->extended_bsi_1) {
 switch (opt->preferred_stereo_downmix) {
-case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 
32); break;
-case AC3ENC_OPT_DOWNMIX_LTRT:  av_strlcpy(strbuf, "ltrt", 32); 
break;
-case AC3ENC_OPT_DOWNMIX_LORO:  av_strlcpy(strbuf, "loro", 32); 
break;
-default: snprintf(strbuf, 32, "ERROR (%d)", 
opt->preferred_stereo_downmix);
+case AC3ENC_OPT_NOT_INDICATED: msg = "notindicated"; break;
+case AC3ENC_OPT_DOWNMIX_LTRT:  msg = "ltrt"; break;
+case AC3ENC_OPT_DOWNMIX_LORO:  msg = "loro"; break;
+default:
+snprintf(strbuf, sizeof(strbuf), "ERROR (%d)", 
opt->preferred_stereo_downmix);
+msg = strbuf;

[FFmpeg-devel] [PATCH 04/17] avcodec/ac3enc: Use bit-operations for bit-mask

2024-04-07 Thread Andreas Rheinhardt
Simply masking the LFE bit is more natural than subtracting
if set.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1a65e35161..31b9474822 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2199,10 +2199,8 @@ static av_cold void set_channel_info(AVCodecContext 
*avctx)
 s->channels = channels;
 s->fbw_channels = channels - s->lfe_on;
 s->lfe_channel  = s->lfe_on ? s->fbw_channels + 1 : -1;
-if (s->lfe_on)
-mask -= AV_CH_LOW_FREQUENCY;
 
-switch (mask) {
+switch (mask & ~AV_CH_LOW_FREQUENCY) {
 case AV_CH_LAYOUT_MONO:   s->channel_mode = AC3_CHMODE_MONO;   
break;
 case AV_CH_LAYOUT_STEREO: s->channel_mode = AC3_CHMODE_STEREO; 
break;
 case AV_CH_LAYOUT_SURROUND:   s->channel_mode = AC3_CHMODE_3F; 
break;
-- 
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 03/17] avcodec/ac3enc: Remove redundant channel layout checks

2024-04-07 Thread Andreas Rheinhardt
These are all checked generically via AVCodec.ch_layouts
in encode_preinit_audio().

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

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index f6456b2a22..1a65e35161 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2189,17 +2189,12 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 /*
  * Set channel information during initialization.
  */
-static av_cold int set_channel_info(AVCodecContext *avctx)
+static av_cold void set_channel_info(AVCodecContext *avctx)
 {
 AC3EncodeContext *s = avctx->priv_data;
 uint64_t mask = av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0);
 int channels = avctx->ch_layout.nb_channels;
 
-if (channels < 1 || channels > AC3_MAX_CHANNELS)
-return AVERROR(EINVAL);
-if (mask > 0x7FF)
-return AVERROR(EINVAL);
-
 s->lfe_on   = !!(mask & AV_CH_LOW_FREQUENCY);
 s->channels = channels;
 s->fbw_channels = channels - s->lfe_on;
@@ -2217,15 +2212,11 @@ static av_cold int set_channel_info(AVCodecContext 
*avctx)
 case AV_CH_LAYOUT_2_2:s->channel_mode = AC3_CHMODE_2F2R;   
break;
 case AV_CH_LAYOUT_5POINT0:
 case AV_CH_LAYOUT_5POINT0_BACK:   s->channel_mode = AC3_CHMODE_3F2R;   
break;
-default:
-return AVERROR(EINVAL);
 }
 s->has_center   = (s->channel_mode & 0x01) && s->channel_mode != 
AC3_CHMODE_MONO;
 s->has_surround =  s->channel_mode & 0x04;
 
 s->channel_map  = ac3_enc_channel_map[s->channel_mode][s->lfe_on];
-
-return 0;
 }
 
 
@@ -2234,17 +2225,7 @@ static av_cold int validate_options(AC3EncodeContext *s)
 AVCodecContext *avctx = s->avctx;
 int i, ret, max_sr;
 
-/* validate channel layout */
-if (!avctx->ch_layout.nb_channels) {
-av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
-  "encoder will guess the layout, but it "
-  "might be incorrect.\n");
-}
-ret = set_channel_info(avctx);
-if (ret) {
-av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");
-return ret;
-}
+set_channel_info(avctx);
 
 /* validate sample rate */
 /* note: max_sr could be changed from 2 to 5 for E-AC-3 once we find a
-- 
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 02/17] avcodec/ac3enc: Don't overwrite AVCodecContext.ch_layout

2024-04-07 Thread Andreas Rheinhardt
This is unnecessary (the channel layout guessing code became
moot when the channel layouts were enforced generically)
and also dangerous, as a custom channel layout mapping
would leak in case one was used.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index dc197c1517..f6456b2a22 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2224,9 +2224,6 @@ static av_cold int set_channel_info(AVCodecContext *avctx)
 s->has_surround =  s->channel_mode & 0x04;
 
 s->channel_map  = ac3_enc_channel_map[s->channel_mode][s->lfe_on];
-if (s->lfe_on)
-mask |= AV_CH_LOW_FREQUENCY;
-av_channel_layout_from_mask(&avctx->ch_layout, mask);
 
 return 0;
 }
-- 
2.40.1

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

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


Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE

2024-04-07 Thread James Almer

On 4/7/2024 5:39 PM, Andreas Rheinhardt wrote:

It is perfectly legal for users to use a custom layout
that is equivalent to a supported native one.


Is that really the case? FFCodec.p.ch_layouts[] has a list of native 
ones, and the generic encode.c code will reject anything not in it.


I guess the encode.c check could be improved with 
av_channel_layout_retype().



In this case the union in AVChannelLayout is not an uint64_t mask,
but a pointer to a custom map.

Signed-off-by: Andreas Rheinhardt 
---
  libavcodec/ac3enc.c | 6 +-
  1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 7a6bcf7900..dc197c1517 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2192,18 +2192,14 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
  static av_cold int set_channel_info(AVCodecContext *avctx)
  {
  AC3EncodeContext *s = avctx->priv_data;
+uint64_t mask = av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0);


Might as well use UINT64_MAX.


  int channels = avctx->ch_layout.nb_channels;
-uint64_t mask = avctx->ch_layout.u.mask;
  
  if (channels < 1 || channels > AC3_MAX_CHANNELS)

  return AVERROR(EINVAL);
  if (mask > 0x7FF)
  return AVERROR(EINVAL);
  
-if (!mask)

-av_channel_layout_default(&avctx->ch_layout, channels);
-mask = avctx->ch_layout.u.mask;
-
  s->lfe_on   = !!(mask & AV_CH_LOW_FREQUENCY);
  s->channels = channels;
  s->fbw_channels = channels - s->lfe_on;

___
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 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE

2024-04-07 Thread Andreas Rheinhardt
It is perfectly legal for users to use a custom layout
that is equivalent to a supported native one.
In this case the union in AVChannelLayout is not an uint64_t mask,
but a pointer to a custom map.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ac3enc.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 7a6bcf7900..dc197c1517 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2192,18 +2192,14 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 static av_cold int set_channel_info(AVCodecContext *avctx)
 {
 AC3EncodeContext *s = avctx->priv_data;
+uint64_t mask = av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0);
 int channels = avctx->ch_layout.nb_channels;
-uint64_t mask = avctx->ch_layout.u.mask;
 
 if (channels < 1 || channels > AC3_MAX_CHANNELS)
 return AVERROR(EINVAL);
 if (mask > 0x7FF)
 return AVERROR(EINVAL);
 
-if (!mask)
-av_channel_layout_default(&avctx->ch_layout, channels);
-mask = avctx->ch_layout.u.mask;
-
 s->lfe_on   = !!(mask & AV_CH_LOW_FREQUENCY);
 s->channels = channels;
 s->fbw_channels = channels - s->lfe_on;
-- 
2.40.1

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/vvc/ps: reset sps_id_used on PS uninit

2024-04-07 Thread James Almer

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(&ps->sps_list[i]);
  for (int i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
  ff_refstruct_unref(&ps->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?

___
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] libavformat/hls.c: support in-stream ID3 metadata update.

2024-04-07 Thread Romain Beauxis
Le dim. 7 avr. 2024 à 05:44, Steven Liu  a écrit :

> Romain Beauxis  于2024年3月26日周二 08:58写道:
> >
> > This patch adds support for updating HLS metadata passed as ID3 frames.
> >
> > This seems like a pretty straight-forward improvement. Updating the
> > metadaata of the first stream seems to be the mechanism is other places
> > in the code and works as expected.
> >
> > ---
> >  libavformat/hls.c | 54 ---
> >  1 file changed, 32 insertions(+), 22 deletions(-)
> >
> > diff --git a/libavformat/hls.c b/libavformat/hls.c
> > index f6b44c2e35..ba6634d57a 100644
> > --- a/libavformat/hls.c
> > +++ b/libavformat/hls.c
> > @@ -93,6 +93,12 @@ enum PlaylistType {
> >  PLS_TYPE_VOD
> >  };
> >
> > +#define ID3_PRIV_OWNER_TS "com.apple.streaming.transportStreamTimestamp"
> > +#define ID3_PRIV_OWNER_AUDIO_SETUP
> "com.apple.streaming.audioDescription"
> > +
> > +#define ID3v2_PRIV_OWNER_TS ID3v2_PRIV_METADATA_PREFIX ID3_PRIV_OWNER_TS
> > +#define ID3v2_PRIV_OWNER_AUDIO_SETUP ID3v2_PRIV_METADATA_PREFIX
> ID3_PRIV_OWNER_AUDIO_SETUP
> > +
> >  /*
> >   * Each playlist has its own demuxer. If it currently is active,
> >   * it has an open AVIOContext too, and potentially an AVPacket
> > @@ -150,9 +156,7 @@ struct playlist {
> >  int64_t id3_offset; /* in stream original tb */
> >  uint8_t* id3_buf; /* temp buffer for id3 parsing */
> >  unsigned int id3_buf_size;
> > -AVDictionary *id3_initial; /* data from first id3 tag */
> > -int id3_found; /* ID3 tag found at some point */
> > -int id3_changed; /* ID3 tag data has changed at some point */
> > +AVDictionary *last_id3; /* data from the last id3 tag */
> >  ID3v2ExtraMeta *id3_deferred_extra; /* stored here until subdemuxer
> is opened */
> >
> >  HLSAudioSetupInfo audio_setup_info;
> > @@ -270,7 +274,7 @@ static void free_playlist_list(HLSContext *c)
> >  av_freep(&pls->main_streams);
> >  av_freep(&pls->renditions);
> >  av_freep(&pls->id3_buf);
> > -av_dict_free(&pls->id3_initial);
> > +av_dict_free(&pls->last_id3);
> >  ff_id3v2_free_extra_meta(&pls->id3_deferred_extra);
> >  av_freep(&pls->init_sec_buf);
> >  av_packet_free(&pls->pkt);
> > @@ -1083,15 +1087,13 @@ static void parse_id3(AVFormatContext *s,
> AVIOContext *pb,
> >AVDictionary **metadata, int64_t *dts,
> HLSAudioSetupInfo *audio_setup_info,
> >ID3v2ExtraMetaAPIC **apic, ID3v2ExtraMeta
> **extra_meta)
> >  {
> > -static const char id3_priv_owner_ts[] =
> "com.apple.streaming.transportStreamTimestamp";
> > -static const char id3_priv_owner_audio_setup[] =
> "com.apple.streaming.audioDescription";
> >  ID3v2ExtraMeta *meta;
> >
> >  ff_id3v2_read_dict(pb, metadata, ID3v2_DEFAULT_MAGIC, extra_meta);
> >  for (meta = *extra_meta; meta; meta = meta->next) {
> >  if (!strcmp(meta->tag, "PRIV")) {
> >  ID3v2ExtraMetaPRIV *priv = &meta->data.priv;
> > -if (priv->datasize == 8 && !av_strncasecmp(priv->owner,
> id3_priv_owner_ts, 44)) {
> > +if (priv->datasize == 8 && !av_strncasecmp(priv->owner,
> ID3_PRIV_OWNER_TS, strlen(ID3_PRIV_OWNER_TS))) {
> >  /* 33-bit MPEG timestamp */
> >  int64_t ts = AV_RB64(priv->data);
> >  av_log(s, AV_LOG_DEBUG, "HLS ID3 audio timestamp
> %"PRId64"\n", ts);
> > @@ -1099,7 +1101,9 @@ static void parse_id3(AVFormatContext *s,
> AVIOContext *pb,
> >  *dts = ts;
> >  else
> >  av_log(s, AV_LOG_ERROR, "Invalid HLS ID3 audio
> timestamp %"PRId64"\n", ts);
> > -} else if (priv->datasize >= 8 &&
> !av_strncasecmp(priv->owner, id3_priv_owner_audio_setup, 36)) {
> > +} else if (priv->datasize >= 8 &&
> > +   !av_strncasecmp(priv->owner,
> ID3_PRIV_OWNER_AUDIO_SETUP, 36) &&
> > +   audio_setup_info) {
> >  ff_hls_senc_read_audio_setup_info(audio_setup_info,
> priv->data, priv->datasize);
> >  }
> >  } else if (!strcmp(meta->tag, "APIC") && apic)
> > @@ -1113,9 +1117,10 @@ static int id3_has_changed_values(struct playlist
> *pls, AVDictionary *metadata,
> >  {
> >  const AVDictionaryEntry *entry = NULL;
> >  const AVDictionaryEntry *oldentry;
> > +
> >  /* check that no keys have changed values */
> >  while ((entry = av_dict_iterate(metadata, entry))) {
> > -oldentry = av_dict_get(pls->id3_initial, entry->key, NULL,
> AV_DICT_MATCH_CASE);
> > +oldentry = av_dict_get(pls->last_id3, entry->key, NULL,
> AV_DICT_MATCH_CASE);
> >  if (!oldentry || strcmp(oldentry->value, entry->value) != 0)
> >  return 1;
> >  }
> > @@ -1143,35 +1148,40 @@ static void handle_id3(AVIOContext *pb, struct
> playlist *pls)
> >  ID3v2ExtraMetaAPIC *apic = NULL;
> >  ID3v2ExtraMeta *extra_meta = NULL;
> 

[FFmpeg-devel] [PATCH 2/2] lavc/vulkan_av1: Use av1dec reference order hint information

2024-04-07 Thread Mark Thompson

---
 libavcodec/vulkan_av1.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index c9e398eaec..8cca97c005 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -242,7 +242,6 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 const AV1RawFrameHeader *frame_header = s->raw_frame_header;
 const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
-CodedBitstreamAV1Context *cbs_ctx = (CodedBitstreamAV1Context 
*)(s->cbc->priv_data);

 const int apply_grain = !(avctx->export_side_data & 
AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
 film_grain->apply_grain;
@@ -272,7 +271,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 ap->ref_frame_sign_bias_mask = 0x0;
 for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++)
-ap->ref_frame_sign_bias_mask |= cbs_ctx->ref_frame_sign_bias[i] << i;
+ap->ref_frame_sign_bias_mask |= pic->ref_frame_sign_bias[i] << i;

 for (int i = 0; i < STD_VIDEO_AV1_REFS_PER_FRAME; i++) {
 const int idx = pic->raw_frame_header->ref_frame_idx[i];
@@ -294,7 +293,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 err = vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], 
&vp->ref_slots[ref_count],
&vp->refs[ref_count], &ap->std_refs[ref_count], 
&ap->vkav1_refs[ref_count],
-   ref_frame, 0, 0, 
cbs_ctx->ref[idx].saved_order_hints);
+   ref_frame, 0, 0, ref_frame->saved_order_hints);
 if (err < 0)
 return err;

--
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/2] lavc/av1: Record reference ordering information for each frame

2024-04-07 Thread Mark Thompson

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.
---
 libavcodec/av1dec.c | 26 ++
 libavcodec/av1dec.h |  4 
 2 files changed, 30 insertions(+)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 824725c031..439f17825b 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -359,6 +359,25 @@ static void coded_lossless_param(AV1DecContext *s)
 }
 }

+static void order_hint_info(AV1DecContext *s)
+{
+const AV1RawFrameHeader *header = s->raw_frame_header;
+const AV1RawSequenceHeader *seq = s->raw_seq;
+AV1Frame *frame = &s->cur_frame;
+
+frame->order_hint = header->order_hint;
+
+for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
+int ref_name = i + AV1_REF_FRAME_LAST;
+int ref_slot = header->ref_frame_idx[i];
+int ref_order_hint = s->ref[ref_slot].order_hint;
+
+frame->saved_order_hints[ref_name] = ref_order_hint;
+frame->ref_frame_sign_bias[ref_name] =
+get_relative_dist(seq, ref_order_hint, frame->order_hint);
+}
+}
+
 static void load_grain_params(AV1DecContext *s)
 {
 const AV1RawFrameHeader *header = s->raw_frame_header;
@@ -701,6 +720,12 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame 
*dst, const AV1Frame *s
sizeof(dst->film_grain));
 dst->coded_lossless = src->coded_lossless;

+dst->order_hint = src->order_hint;
+memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias,
+   sizeof(dst->ref_frame_sign_bias));
+memcpy(dst->saved_order_hints, src->saved_order_hints,
+   sizeof(dst->saved_order_hints));
+
 return 0;

 fail:
@@ -1257,6 +1282,7 @@ static int get_current_frame(AVCodecContext *avctx)
 global_motion_params(s);
 skip_mode_params(s);
 coded_lossless_param(s);
+order_hint_info(s);
 load_grain_params(s);

 return ret;
diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h
index 336eb61359..0a7073ddce 100644
--- a/libavcodec/av1dec.h
+++ b/libavcodec/av1dec.h
@@ -53,6 +53,10 @@ typedef struct AV1Frame {
 AV1RawFilmGrainParams film_grain;

 uint8_t coded_lossless;
+
+uint8_t order_hint;
+uint8_t ref_frame_sign_bias[AV1_NUM_REF_FRAMES];
+uint8_t saved_order_hints[AV1_NUM_REF_FRAMES];
 } AV1Frame;

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

2024-04-07 Thread Nuo Mi
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(&ps->sps_list[i]);
>  for (int i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
>  ff_refstruct_unref(&ps->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.

 }
>
>  static void alf_coeff(int16_t *coeff,
> --
> 2.44.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] lavf/vsrc_ddagrab: WinAPI functions must be called as stdcall in x86_32

2024-04-07 Thread Vadim Guchenko
Henrik Gramner via ffmpeg-devel wrote on 07.04.2024 at 17:32:

> I believe most existing code uses WINAPI instead of __stdcall.

Thanks for correction. Here is a new patch:

diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
--- a/libavfilter/vsrc_ddagrab.c
+++ b/libavfilter/vsrc_ddagrab.c
@@ -178,7 +178,7 @@ static av_cold int init_dxgi_dda(AVFilterContext *avctx)
 #if HAVE_IDXGIOUTPUT5 && HAVE_DPI_AWARENESS_CONTEXT
 IDXGIOutput5 *dxgi_output5 = NULL;
 
-typedef DPI_AWARENESS_CONTEXT (*set_thread_dpi_t)(DPI_AWARENESS_CONTEXT);
+typedef DPI_AWARENESS_CONTEXT (WINAPI 
*set_thread_dpi_t)(DPI_AWARENESS_CONTEXT);
 set_thread_dpi_t set_thread_dpi;
 HMODULE user32_module;
 #endif

___
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] lavc/vvc: Error if SPS ID is duplicated within CVS

2024-04-07 Thread Nuo Mi
On Sun, Apr 7, 2024 at 8:16 PM Anton Khirnov  wrote:

> Quoting Nuo Mi (2024-04-07 14:13:58)
> > On Sun, Apr 7, 2024 at 2:15 PM Anton Khirnov  wrote:
> >
> > > Quoting Frank Plowman (2024-04-06 15:46:09)
> > > > Key line from the spec is:
> > > >
> > > > "All SPS NAL units with a particular value of
> sps_seq_parameter_set_id
> > > > in a CVS shall have the same content."
> > > >
> > > > Prior to this patch, the VVC decoder's behaviour on encountering a
> > > > duplicated SPS ID (within the entire bitstream, not restricted to
> > > > a CVS) was simply to replace the entry in the SPS lookup table with
> the
> > > > new data.  Illegal bitstreams with multiple SPSs in the same CVS
> sharing
> > > > an ID but differing elsewhere could cause all manner of issues.
> > > >
> > > > The patch tracks which SPS IDs have been used in the given CVS using
> the
> > > > new sps_id_used field of VVCParamSets.  If it encounters an SPS with
> an
> > > > ID already in use and whose content differs from the previous SPS, it
> > > > throws an AVERROR_INVALIDDATA.
> > >
> > > I wonder if it wouldn't be better to do what H264/HEVC do, which is
> > > replace the SPS, invalidate the PPSes that depend on the old one, and
> > > start a new CVS.
> > >
> > Consider two scenarios:
> > If the first SPS is incorrect, the entire CVS is undecodable because the
> > key frame is wrong, no matter what we do.
> > If the second SPS is incorrect, H.264/HEVC can't recover until the next
> CVS
> > because it replaces the correct SPS with the wrong one. However, the
> > current VVC logic allows for recovery in such cases.
> > Therefore, in the second case, the current logic may have benefits.
>
> Could the new SPS not signal the start of a new CVS?
>
Yes.
Take AUD_A_Broadcom_3.bit as an example, the nal order is

SPS
PPS
IDR_N_LP
TRAIL
MORE TRAILS...
SPS
PPS
CRA
TRAIL
MORE TRAILS...
SPS
PPS
IDR_N_LP

The SPS before CRA will not start a new CVS, unless you seek to the CRA.

>
> --
> Anton Khirnov
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel 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] lavc/vvc: Error if SPS ID is duplicated within CVS

2024-04-07 Thread Anton Khirnov
Quoting Nuo Mi (2024-04-07 14:13:58)
> On Sun, Apr 7, 2024 at 2:15 PM Anton Khirnov  wrote:
> 
> > Quoting Frank Plowman (2024-04-06 15:46:09)
> > > Key line from the spec is:
> > >
> > > "All SPS NAL units with a particular value of sps_seq_parameter_set_id
> > > in a CVS shall have the same content."
> > >
> > > Prior to this patch, the VVC decoder's behaviour on encountering a
> > > duplicated SPS ID (within the entire bitstream, not restricted to
> > > a CVS) was simply to replace the entry in the SPS lookup table with the
> > > new data.  Illegal bitstreams with multiple SPSs in the same CVS sharing
> > > an ID but differing elsewhere could cause all manner of issues.
> > >
> > > The patch tracks which SPS IDs have been used in the given CVS using the
> > > new sps_id_used field of VVCParamSets.  If it encounters an SPS with an
> > > ID already in use and whose content differs from the previous SPS, it
> > > throws an AVERROR_INVALIDDATA.
> >
> > I wonder if it wouldn't be better to do what H264/HEVC do, which is
> > replace the SPS, invalidate the PPSes that depend on the old one, and
> > start a new CVS.
> >
> Consider two scenarios:
> If the first SPS is incorrect, the entire CVS is undecodable because the
> key frame is wrong, no matter what we do.
> If the second SPS is incorrect, H.264/HEVC can't recover until the next CVS
> because it replaces the correct SPS with the wrong one. However, the
> current VVC logic allows for recovery in such cases.
> Therefore, in the second case, the current logic may have benefits.

Could the new SPS not signal the start of a new CVS?

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

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


Re: [FFmpeg-devel] [PATCH v2] lavc/vvc: Error if SPS ID is duplicated within CVS

2024-04-07 Thread Nuo Mi
On Sun, Apr 7, 2024 at 2:15 PM Anton Khirnov  wrote:

> Quoting Frank Plowman (2024-04-06 15:46:09)
> > Key line from the spec is:
> >
> > "All SPS NAL units with a particular value of sps_seq_parameter_set_id
> > in a CVS shall have the same content."
> >
> > Prior to this patch, the VVC decoder's behaviour on encountering a
> > duplicated SPS ID (within the entire bitstream, not restricted to
> > a CVS) was simply to replace the entry in the SPS lookup table with the
> > new data.  Illegal bitstreams with multiple SPSs in the same CVS sharing
> > an ID but differing elsewhere could cause all manner of issues.
> >
> > The patch tracks which SPS IDs have been used in the given CVS using the
> > new sps_id_used field of VVCParamSets.  If it encounters an SPS with an
> > ID already in use and whose content differs from the previous SPS, it
> > throws an AVERROR_INVALIDDATA.
>
> I wonder if it wouldn't be better to do what H264/HEVC do, which is
> replace the SPS, invalidate the PPSes that depend on the old one, and
> start a new CVS.
>
Consider two scenarios:
If the first SPS is incorrect, the entire CVS is undecodable because the
key frame is wrong, no matter what we do.
If the second SPS is incorrect, H.264/HEVC can't recover until the next CVS
because it replaces the correct SPS with the wrong one. However, the
current VVC logic allows for recovery in such cases.
Therefore, in the second case, the current logic may have benefits.

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

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


Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()

2024-04-07 Thread Anton Khirnov
Quoting Michael Niedermayer (2024-04-07 01:16:39)
> On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> > From: Niklas Haas 
> > 
> > This replaces the myriad of existing lists in AVCodec by a unified API
> > call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> > substantially, while also making this more trivially extensible.
> > 
> > In addition to the already covered lists, add two new entries for color
> > space and color range, mirroring the newly added negotiable fields in
> > libavfilter.
> > 
> > I decided to drop the explicit length field from the API proposed by
> > Andreas Rheinhardt, because having it in place ended up complicating
> > both the codec side and the client side implementations, while also
> > being strictly less flexible (it's trivial to recover a length given
> > a terminator, but requires allocation to add a terminator given
> > a length). Using a terminator also presents less of a porting challenge
> > for existing users of the current API.
> > 
> > Once the deprecation period passes for the existing public fields, the
> > rough plan is to move the commonly used fields (such as
> > pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> > configuration types, and then implement the rarely used fields with
> > custom callbacks.
> > ---
> >  doc/APIchanges  |  5 
> >  libavcodec/avcodec.c| 51 +
> >  libavcodec/avcodec.h| 27 
> >  libavcodec/codec.h  | 19 +++---
> >  libavcodec/codec_internal.h | 21 +++
> >  libavcodec/version.h|  4 +--
> >  6 files changed, 121 insertions(+), 6 deletions(-)
> 
> If the API is changed, it should be to an API that allows externally
> maintained codecs.
> (it would result in more developers working on codecs)


This seems like a complete non sequitur in relation to this patch.

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

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


Re: [FFmpeg-devel] [PATCH 1/2] libavformat/hls.c: support in-stream ID3 metadata update.

2024-04-07 Thread Steven Liu
Romain Beauxis  于2024年3月26日周二 08:58写道:
>
> This patch adds support for updating HLS metadata passed as ID3 frames.
>
> This seems like a pretty straight-forward improvement. Updating the
> metadaata of the first stream seems to be the mechanism is other places
> in the code and works as expected.
>
> ---
>  libavformat/hls.c | 54 ---
>  1 file changed, 32 insertions(+), 22 deletions(-)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index f6b44c2e35..ba6634d57a 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -93,6 +93,12 @@ enum PlaylistType {
>  PLS_TYPE_VOD
>  };
>
> +#define ID3_PRIV_OWNER_TS "com.apple.streaming.transportStreamTimestamp"
> +#define ID3_PRIV_OWNER_AUDIO_SETUP "com.apple.streaming.audioDescription"
> +
> +#define ID3v2_PRIV_OWNER_TS ID3v2_PRIV_METADATA_PREFIX ID3_PRIV_OWNER_TS
> +#define ID3v2_PRIV_OWNER_AUDIO_SETUP ID3v2_PRIV_METADATA_PREFIX 
> ID3_PRIV_OWNER_AUDIO_SETUP
> +
>  /*
>   * Each playlist has its own demuxer. If it currently is active,
>   * it has an open AVIOContext too, and potentially an AVPacket
> @@ -150,9 +156,7 @@ struct playlist {
>  int64_t id3_offset; /* in stream original tb */
>  uint8_t* id3_buf; /* temp buffer for id3 parsing */
>  unsigned int id3_buf_size;
> -AVDictionary *id3_initial; /* data from first id3 tag */
> -int id3_found; /* ID3 tag found at some point */
> -int id3_changed; /* ID3 tag data has changed at some point */
> +AVDictionary *last_id3; /* data from the last id3 tag */
>  ID3v2ExtraMeta *id3_deferred_extra; /* stored here until subdemuxer is 
> opened */
>
>  HLSAudioSetupInfo audio_setup_info;
> @@ -270,7 +274,7 @@ static void free_playlist_list(HLSContext *c)
>  av_freep(&pls->main_streams);
>  av_freep(&pls->renditions);
>  av_freep(&pls->id3_buf);
> -av_dict_free(&pls->id3_initial);
> +av_dict_free(&pls->last_id3);
>  ff_id3v2_free_extra_meta(&pls->id3_deferred_extra);
>  av_freep(&pls->init_sec_buf);
>  av_packet_free(&pls->pkt);
> @@ -1083,15 +1087,13 @@ static void parse_id3(AVFormatContext *s, AVIOContext 
> *pb,
>AVDictionary **metadata, int64_t *dts, 
> HLSAudioSetupInfo *audio_setup_info,
>ID3v2ExtraMetaAPIC **apic, ID3v2ExtraMeta **extra_meta)
>  {
> -static const char id3_priv_owner_ts[] = 
> "com.apple.streaming.transportStreamTimestamp";
> -static const char id3_priv_owner_audio_setup[] = 
> "com.apple.streaming.audioDescription";
>  ID3v2ExtraMeta *meta;
>
>  ff_id3v2_read_dict(pb, metadata, ID3v2_DEFAULT_MAGIC, extra_meta);
>  for (meta = *extra_meta; meta; meta = meta->next) {
>  if (!strcmp(meta->tag, "PRIV")) {
>  ID3v2ExtraMetaPRIV *priv = &meta->data.priv;
> -if (priv->datasize == 8 && !av_strncasecmp(priv->owner, 
> id3_priv_owner_ts, 44)) {
> +if (priv->datasize == 8 && !av_strncasecmp(priv->owner, 
> ID3_PRIV_OWNER_TS, strlen(ID3_PRIV_OWNER_TS))) {
>  /* 33-bit MPEG timestamp */
>  int64_t ts = AV_RB64(priv->data);
>  av_log(s, AV_LOG_DEBUG, "HLS ID3 audio timestamp 
> %"PRId64"\n", ts);
> @@ -1099,7 +1101,9 @@ static void parse_id3(AVFormatContext *s, AVIOContext 
> *pb,
>  *dts = ts;
>  else
>  av_log(s, AV_LOG_ERROR, "Invalid HLS ID3 audio timestamp 
> %"PRId64"\n", ts);
> -} else if (priv->datasize >= 8 && !av_strncasecmp(priv->owner, 
> id3_priv_owner_audio_setup, 36)) {
> +} else if (priv->datasize >= 8 &&
> +   !av_strncasecmp(priv->owner, 
> ID3_PRIV_OWNER_AUDIO_SETUP, 36) &&
> +   audio_setup_info) {
>  ff_hls_senc_read_audio_setup_info(audio_setup_info, 
> priv->data, priv->datasize);
>  }
>  } else if (!strcmp(meta->tag, "APIC") && apic)
> @@ -1113,9 +1117,10 @@ static int id3_has_changed_values(struct playlist 
> *pls, AVDictionary *metadata,
>  {
>  const AVDictionaryEntry *entry = NULL;
>  const AVDictionaryEntry *oldentry;
> +
>  /* check that no keys have changed values */
>  while ((entry = av_dict_iterate(metadata, entry))) {
> -oldentry = av_dict_get(pls->id3_initial, entry->key, NULL, 
> AV_DICT_MATCH_CASE);
> +oldentry = av_dict_get(pls->last_id3, entry->key, NULL, 
> AV_DICT_MATCH_CASE);
>  if (!oldentry || strcmp(oldentry->value, entry->value) != 0)
>  return 1;
>  }
> @@ -1143,35 +1148,40 @@ static void handle_id3(AVIOContext *pb, struct 
> playlist *pls)
>  ID3v2ExtraMetaAPIC *apic = NULL;
>  ID3v2ExtraMeta *extra_meta = NULL;
>  int64_t timestamp = AV_NOPTS_VALUE;
> +// Only set audio_setup_info on first id3 chunk.
> +HLSAudioSetupInfo *audio_setup_info = pls->last_id3 ? NULL : 
> &pls->audio_setup_info;
>
> -parse_id3(pls->ctx, p

Re: [FFmpeg-devel] [PATCH] lavf/vsrc_ddagrab: WinAPI functions must be called as stdcall in x86_32

2024-04-07 Thread Henrik Gramner via ffmpeg-devel
On Sun, Apr 7, 2024 at 2:59 AM Vadim Guchenko  wrote:
> +typedef DPI_AWARENESS_CONTEXT (__stdcall 
> *set_thread_dpi_t)(DPI_AWARENESS_CONTEXT);

I believe most existing code uses WINAPI instead of __stdcall.
___
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] lavf/matroskaenc: sort options by name

2024-04-07 Thread Zhao Zhili


> On Apr 7, 2024, at 14:16, Anton Khirnov  wrote:
> 
> Quoting Andreas Rheinhardt (2024-04-06 13:25:49)
>> See https://ffmpeg.org/pipermail/ffmpeg-devel/2024-February/320849.html
>> Additionally I do not agree that sorting options by name is the best
>> way; it should be sorted by what are (believed to be) the most commonly
>> used options.
> 
> +1

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240106165246.274472-1-stefa...@gmail.com/

I have the same consideration in another patch. Maybe group related options 
together than sort whole
options.

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

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