* [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
@ 2024-04-07 20:39 Andreas Rheinhardt
2024-04-07 20:51 ` James Almer
` (18 more replies)
0 siblings, 19 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 20:39 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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 <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
@ 2024-04-07 20:51 ` James Almer
2024-04-07 21:53 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 02/17] avcodec/ac3enc: Don't overwrite AVCodecContext.ch_layout Andreas Rheinhardt
` (17 subsequent siblings)
18 siblings, 1 reply; 24+ messages in thread
From: James Almer @ 2024-04-07 20:51 UTC (permalink / raw)
To: ffmpeg-devel
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 <andreas.rheinhardt@outlook.com>
> ---
> 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 02/17] avcodec/ac3enc: Don't overwrite AVCodecContext.ch_layout
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
2024-04-07 20:51 ` James Almer
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 03/17] avcodec/ac3enc: Remove redundant channel layout checks Andreas Rheinhardt
` (16 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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 <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 03/17] avcodec/ac3enc: Remove redundant channel layout checks
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
2024-04-07 20:51 ` James Almer
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 02/17] avcodec/ac3enc: Don't overwrite AVCodecContext.ch_layout Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 04/17] avcodec/ac3enc: Use bit-operations for bit-mask Andreas Rheinhardt
` (15 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
These are all checked generically via AVCodec.ch_layouts
in encode_preinit_audio().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 04/17] avcodec/ac3enc: Use bit-operations for bit-mask
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (2 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 03/17] avcodec/ac3enc: Remove redundant channel layout checks Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 05/17] avcodec/ac3enc: Avoid copying strings Andreas Rheinhardt
` (14 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Simply masking the LFE bit is more natural than subtracting
if set.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 05/17] avcodec/ac3enc: Avoid copying strings
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (3 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 04/17] avcodec/ac3enc: Use bit-operations for bit-mask Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 06/17] avcodec/ac3enc: Remove always-false sample rate check Andreas Rheinhardt
` (13 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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;
}
- ff_dlog(avctx, "dmix_mode: %s\n", strbuf);
+ ff_dlog(avctx, "dmix_mode: %s\n", msg);
ff_dlog(avctx, "ltrt_cmixlev: %0.3f (%d)\n",
opt->ltrt_center_mix_level, s->ltrt_center_mix_level);
ff_dlog(avctx, "ltrt_surmixlev: %0.3f (%d)\n",
@@ -1889,26 +1895,32 @@ static void dprint_options(AC3EncodeContext *s)
}
if (opt->extended_bsi_2) {
switch (opt->dolby_surround_ex_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_ex_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_ex_mode);
+ msg = strbuf;
}
- ff_dlog(avctx, "dsurex_mode: %s\n", strbuf);
+ ff_dlog(avctx, "dsurex_mode: %s\n", msg);
switch (opt->dolby_headphone_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_headphone_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_headphone_mode);
+ msg = strbuf;
}
- ff_dlog(avctx, "dheadphone_mode: %s\n", strbuf);
+ ff_dlog(avctx, "dheadphone_mode: %s\n", msg);
switch (opt->ad_converter_type) {
- case AC3ENC_OPT_ADCONV_STANDARD: av_strlcpy(strbuf, "standard", 32); break;
- case AC3ENC_OPT_ADCONV_HDCD: av_strlcpy(strbuf, "hdcd", 32); break;
- default: snprintf(strbuf, 32, "ERROR (%d)", opt->ad_converter_type);
+ case AC3ENC_OPT_ADCONV_STANDARD: msg = "standard"; break;
+ case AC3ENC_OPT_ADCONV_HDCD: msg = "hdcd"; break;
+ default:
+ snprintf(strbuf, sizeof(strbuf), "ERROR (%d)", opt->ad_converter_type);
+ msg = strbuf;
}
- ff_dlog(avctx, "ad_conv_type: %s\n", strbuf);
+ ff_dlog(avctx, "ad_conv_type: %s\n", msg);
} else {
ff_dlog(avctx, "extended bitstream info 2: {not written}\n");
}
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 06/17] avcodec/ac3enc: Remove always-false sample rate check
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (4 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 05/17] avcodec/ac3enc: Avoid copying strings Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 07/17] avcodec/ac3enc: Remove disabled code for RealAudio variant of AC-3 Andreas Rheinhardt
` (12 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
encode_preinit_audio() already checks that the sample rate
is among AVCodec.supported_samplerates.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 07/17] avcodec/ac3enc: Remove disabled code for RealAudio variant of AC-3
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (5 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 06/17] avcodec/ac3enc: Remove always-false sample rate check Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 08/17] avcodec/ac3enc: Use common encode_frame function Andreas Rheinhardt
` (11 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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 <andreas.rheinhardt@outlook.com>
---
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_shift) * 1000;
+ for (int i = 0; i < 19; i++) {
+ int br = ff_ac3_bitrate_tab[i] * 1000;
long long diff = llabs(br - avctx->bit_rate);
if (diff < best_diff) {
best_br = br;
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 1cb1aac4b2..dad53cc4bb 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -256,8 +256,6 @@ 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
- int warned_alternate_bitstream;
-
/* fixed vs. float function pointers */
int (*mdct_init)(struct AC3EncodeContext *s);
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index 527f77e33a..5deda083c3 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -134,13 +134,8 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s)
put_bits(&s->pb, 2, 0); /* stream type = independent */
put_bits(&s->pb, 3, 0); /* substream id = 0 */
put_bits(&s->pb, 11, (s->frame_size / 2) - 1); /* frame size */
- if (s->bit_alloc.sr_shift) {
- put_bits(&s->pb, 2, 0x3); /* fscod2 */
- put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */
- } else {
- put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */
- put_bits(&s->pb, 2, s->num_blks_code); /* number of blocks */
- }
+ put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */
+ put_bits(&s->pb, 2, s->num_blks_code); /* number of blocks */
put_bits(&s->pb, 3, s->channel_mode); /* audio coding mode */
put_bits(&s->pb, 1, s->lfe_on); /* LFE channel indicator */
put_bits(&s->pb, 5, s->bitstream_id); /* bitstream id (EAC3=16) */
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 08/17] avcodec/ac3enc: Use common encode_frame function
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (6 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 07/17] avcodec/ac3enc: Remove disabled code for RealAudio variant of AC-3 Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 09/17] avcodec/ac3enc: Move ff_ac3_validate_metadate() upwards Andreas Rheinhardt
` (10 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is in preparation for sharing even more stuff
common to the fixed and floating-point encoders.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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 = ff_ac3_float_encode_init,
- FF_CODEC_ENCODE_CB(ff_ac3_float_encode_frame),
+ FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
.close = ff_ac3_encode_close,
.p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 45dbc98804..2e0fb9e85a 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -371,10 +371,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
}
-int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt,
- const AVFrame *frame, int *got_packet_ptr)
+static int encode_frame(AC3EncodeContext *s, const AVFrame *frame)
{
- AC3EncodeContext *s = avctx->priv_data;
int ret;
if (s->options.allow_per_frame_metadata) {
@@ -402,5 +400,5 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt,
scale_coefficients(s);
#endif
- return ff_ac3_encode_frame_common_end(avctx, avpkt, frame, got_packet_ptr);
+ return 0;
}
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index 5deda083c3..1ee140f13a 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -252,7 +252,7 @@ const FFCodec ff_eac3_encoder = {
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
.priv_data_size = sizeof(AC3EncodeContext),
.init = ff_ac3_float_encode_init,
- FF_CODEC_ENCODE_CB(ff_ac3_float_encode_frame),
+ FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
.close = ff_ac3_encode_close,
.p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 09/17] avcodec/ac3enc: Move ff_ac3_validate_metadate() upwards
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (7 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 08/17] avcodec/ac3enc: Use common encode_frame function Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 10/17] avcodec/ac3enc: Share more code between fixed/float encoders Andreas Rheinhardt
` (9 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Will avoid a forward declaration in the next commit.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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_stereo_downmix = AC3ENC_OPT_NOT_INDICATED;
+ if (!s->eac3 || s->has_center) {
+ /* validate Lt/Rt center mix level */
+ validate_mix_level(avctx, "ltrt_center_mix_level",
+ &opt->ltrt_center_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 5, 0,
+ &s->ltrt_center_mix_level);
+ /* validate Lo/Ro center mix level */
+ validate_mix_level(avctx, "loro_center_mix_level",
+ &opt->loro_center_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 5, 0,
+ &s->loro_center_mix_level);
+ }
+ if (!s->eac3 || s->has_surround) {
+ /* validate Lt/Rt surround mix level */
+ validate_mix_level(avctx, "ltrt_surround_mix_level",
+ &opt->ltrt_surround_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 6, 3,
+ &s->ltrt_surround_mix_level);
+ /* validate Lo/Ro surround mix level */
+ validate_mix_level(avctx, "loro_surround_mix_level",
+ &opt->loro_surround_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 6, 3,
+ &s->loro_surround_mix_level);
+ }
+ }
+
+ /* validate audio service type / channels combination */
+ if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE &&
+ avctx->ch_layout.nb_channels == 1) ||
+ ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY ||
+ avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY ||
+ avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER)
+ && avctx->ch_layout.nb_channels > 1)) {
+ av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the "
+ "specified number of channels\n");
+ return AVERROR(EINVAL);
+ }
+
+ /* validate extended bsi 2 / info metadata */
+ if (opt->extended_bsi_2 || opt->eac3_info_metadata) {
+ /* default dolby headphone mode */
+ if (opt->dolby_headphone_mode == AC3ENC_OPT_NONE)
+ opt->dolby_headphone_mode = AC3ENC_OPT_NOT_INDICATED;
+ /* default dolby surround ex mode */
+ if (opt->dolby_surround_ex_mode == AC3ENC_OPT_NONE)
+ opt->dolby_surround_ex_mode = AC3ENC_OPT_NOT_INDICATED;
+ /* default A/D converter type */
+ if (opt->ad_converter_type == AC3ENC_OPT_NONE)
+ opt->ad_converter_type = AC3ENC_OPT_ADCONV_STANDARD;
+ }
+
+ /* copyright & original defaults */
+ if (!s->eac3 || opt->eac3_info_metadata) {
+ /* default copyright */
+ if (opt->copyright == AC3ENC_OPT_NONE)
+ opt->copyright = AC3ENC_OPT_OFF;
+ /* default original */
+ if (opt->original == AC3ENC_OPT_NONE)
+ opt->original = AC3ENC_OPT_ON;
+ }
+
+ /* dolby surround mode default */
+ if (!s->eac3 || opt->eac3_info_metadata) {
+ if (opt->dolby_surround_mode == AC3ENC_OPT_NONE)
+ opt->dolby_surround_mode = AC3ENC_OPT_NOT_INDICATED;
+ }
+
+ /* validate audio production info */
+ if (opt->audio_production_info) {
+ if (opt->mixing_level == AC3ENC_OPT_NONE) {
+ av_log(avctx, AV_LOG_ERROR, "mixing_level must be set if "
+ "room_type is set\n");
+ return AVERROR(EINVAL);
+ }
+ if (opt->mixing_level < 80) {
+ av_log(avctx, AV_LOG_ERROR, "invalid mixing level. must be between "
+ "80dB and 111dB\n");
+ return AVERROR(EINVAL);
+ }
+ /* default room type */
+ if (opt->room_type == AC3ENC_OPT_NONE)
+ opt->room_type = AC3ENC_OPT_NOT_INDICATED;
+ }
+
+ /* set bitstream id for alternate bitstream syntax */
+ if (!s->eac3 && (opt->extended_bsi_1 || opt->extended_bsi_2))
+ s->bitstream_id = 6;
+
+ return 0;
+}
+
/**
* Adjust the frame size to make the average bit rate match the target bit rate.
* This is only needed for 11025, 22050, and 44100 sample rates or any E-AC-3.
@@ -1930,217 +2139,6 @@ static void dprint_options(AC3EncodeContext *s)
#endif
}
-
-#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_stereo_downmix = AC3ENC_OPT_NOT_INDICATED;
- if (!s->eac3 || s->has_center) {
- /* validate Lt/Rt center mix level */
- validate_mix_level(avctx, "ltrt_center_mix_level",
- &opt->ltrt_center_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 5, 0,
- &s->ltrt_center_mix_level);
- /* validate Lo/Ro center mix level */
- validate_mix_level(avctx, "loro_center_mix_level",
- &opt->loro_center_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 5, 0,
- &s->loro_center_mix_level);
- }
- if (!s->eac3 || s->has_surround) {
- /* validate Lt/Rt surround mix level */
- validate_mix_level(avctx, "ltrt_surround_mix_level",
- &opt->ltrt_surround_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 6, 3,
- &s->ltrt_surround_mix_level);
- /* validate Lo/Ro surround mix level */
- validate_mix_level(avctx, "loro_surround_mix_level",
- &opt->loro_surround_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 6, 3,
- &s->loro_surround_mix_level);
- }
- }
-
- /* validate audio service type / channels combination */
- if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE &&
- avctx->ch_layout.nb_channels == 1) ||
- ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY ||
- avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY ||
- avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER)
- && avctx->ch_layout.nb_channels > 1)) {
- av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the "
- "specified number of channels\n");
- return AVERROR(EINVAL);
- }
-
- /* validate extended bsi 2 / info metadata */
- if (opt->extended_bsi_2 || opt->eac3_info_metadata) {
- /* default dolby headphone mode */
- if (opt->dolby_headphone_mode == AC3ENC_OPT_NONE)
- opt->dolby_headphone_mode = AC3ENC_OPT_NOT_INDICATED;
- /* default dolby surround ex mode */
- if (opt->dolby_surround_ex_mode == AC3ENC_OPT_NONE)
- opt->dolby_surround_ex_mode = AC3ENC_OPT_NOT_INDICATED;
- /* default A/D converter type */
- if (opt->ad_converter_type == AC3ENC_OPT_NONE)
- opt->ad_converter_type = AC3ENC_OPT_ADCONV_STANDARD;
- }
-
- /* copyright & original defaults */
- if (!s->eac3 || opt->eac3_info_metadata) {
- /* default copyright */
- if (opt->copyright == AC3ENC_OPT_NONE)
- opt->copyright = AC3ENC_OPT_OFF;
- /* default original */
- if (opt->original == AC3ENC_OPT_NONE)
- opt->original = AC3ENC_OPT_ON;
- }
-
- /* dolby surround mode default */
- if (!s->eac3 || opt->eac3_info_metadata) {
- if (opt->dolby_surround_mode == AC3ENC_OPT_NONE)
- opt->dolby_surround_mode = AC3ENC_OPT_NOT_INDICATED;
- }
-
- /* validate audio production info */
- if (opt->audio_production_info) {
- if (opt->mixing_level == AC3ENC_OPT_NONE) {
- av_log(avctx, AV_LOG_ERROR, "mixing_level must be set if "
- "room_type is set\n");
- return AVERROR(EINVAL);
- }
- if (opt->mixing_level < 80) {
- av_log(avctx, AV_LOG_ERROR, "invalid mixing level. must be between "
- "80dB and 111dB\n");
- return AVERROR(EINVAL);
- }
- /* default room type */
- if (opt->room_type == AC3ENC_OPT_NONE)
- opt->room_type = AC3ENC_OPT_NOT_INDICATED;
- }
-
- /* set bitstream id for alternate bitstream syntax */
- if (!s->eac3 && (opt->extended_bsi_1 || opt->extended_bsi_2))
- s->bitstream_id = 6;
-
- return 0;
-}
-
-
/**
* Finalize encoding and free any memory allocated by the encoder.
*
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 10/17] avcodec/ac3enc: Share more code between fixed/float encoders
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (8 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 09/17] avcodec/ac3enc: Move ff_ac3_validate_metadate() upwards Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 11/17] avcodec/ac3enc: Deduplicate allocating buffers Andreas Rheinhardt
` (8 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 11/17] avcodec/ac3enc: Deduplicate allocating buffers
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (9 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 10/17] avcodec/ac3enc: Share more code between fixed/float encoders Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 12/17] avcodec/ac3enc: Deduplicate copying input samples Andreas Rheinhardt
` (7 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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 <andreas.rheinhardt@outlook.com>
---
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 <stdint.h>
#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) *
- sizeof(**s->planar_samples))))
- return AVERROR(ENOMEM);
- }
- return 0;
-}
-
-
/*
* Copy input samples.
* Channels are reordered from FFmpeg's default order to AC-3 order.
@@ -68,13 +49,14 @@ static void copy_input_samples(AC3EncodeContext *s, SampleType **samples)
/* 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], &s->planar_samples[ch][AC3_BLOCK_SIZE * s->num_blocks],
- AC3_BLOCK_SIZE * sizeof(s->planar_samples[0][0]));
+ 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(&s->planar_samples[ch][AC3_BLOCK_SIZE],
+ memcpy((SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE,
samples[s->channel_map[ch]],
- AC3_BLOCK_SIZE * s->num_blocks * sizeof(s->planar_samples[0][0]));
+ AC3_BLOCK_SIZE * s->num_blocks * sizeof(SampleType));
}
}
@@ -91,11 +73,11 @@ static void apply_mdct(AC3EncodeContext *s)
for (ch = 0; ch < s->channels; ch++) {
for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
- const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE];
+ const SampleType *input_samples = (SampleType*)s->planar_samples[ch] + blk * AC3_BLOCK_SIZE;
s->fdsp->vector_fmul(s->windowed_samples, input_samples,
s->mdct_window, AC3_BLOCK_SIZE);
- s->fdsp->vector_fmul_reverse(s->windowed_samples + AC3_BLOCK_SIZE,
+ s->fdsp->vector_fmul_reverse((SampleType*)s->windowed_samples + AC3_BLOCK_SIZE,
&input_samples[AC3_BLOCK_SIZE],
s->mdct_window, AC3_BLOCK_SIZE);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 12/17] avcodec/ac3enc: Deduplicate copying input samples
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (10 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 11/17] avcodec/ac3enc: Deduplicate allocating buffers Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 13/17] avcodec/ac3enc_float: Remove uninformative error message Andreas Rheinhardt
` (6 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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 <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 13/17] avcodec/ac3enc_float: Remove uninformative error message
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (11 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 12/17] avcodec/ac3enc: Deduplicate copying input samples Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 14/17] avcodec/ac3enc: Avoid function pointers to initialize MDCT Andreas Rheinhardt
` (5 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
AVERROR(ENOMEM) is enough.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 14/17] avcodec/ac3enc: Avoid function pointers to initialize MDCT
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (12 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 13/17] avcodec/ac3enc_float: Remove uninformative error message Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 15/17] avcodec/ac3enc: Move EAC-3 specific initialization to eac3enc.c Andreas Rheinhardt
` (4 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 15/17] avcodec/ac3enc: Move EAC-3 specific initialization to eac3enc.c
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (13 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 14/17] avcodec/ac3enc: Avoid function pointers to initialize MDCT Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 16/17] avcodec/flacenc: Avoid shift where possible Andreas Rheinhardt
` (3 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 16/17] avcodec/flacenc: Avoid shift where possible
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (14 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 15/17] avcodec/ac3enc: Move EAC-3 specific initialization to eac3enc.c Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 17/17] avformat/img2: Avoid relocations for ff_img_tags Andreas Rheinhardt
` (2 subsequent siblings)
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 17/17] avformat/img2: Avoid relocations for ff_img_tags
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (15 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 16/17] avcodec/flacenc: Avoid shift where possible Andreas Rheinhardt
@ 2024-04-07 21:09 ` Andreas Rheinhardt
2024-04-08 0:56 ` [FFmpeg-devel] [PATCH 18/18] avcodec/ac3enc: Avoid calculating the CRC multiple times Andreas Rheinhardt
2024-04-10 6:16 ` [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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 <andreas.rheinhardt@outlook.com>
---
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 <assert.h>
+
#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, "tif" },
- { AV_CODEC_ID_TIFF, "dng" },
- { AV_CODEC_ID_SGI, "sgi" },
- { AV_CODEC_ID_PTX, "ptx" },
- { AV_CODEC_ID_PHOTOCD, "pcd" },
- { AV_CODEC_ID_PCX, "pcx" },
- { AV_CODEC_ID_QDRAW, "pic" },
- { AV_CODEC_ID_QDRAW, "pct" },
- { AV_CODEC_ID_QDRAW, "pict" },
- { AV_CODEC_ID_SUNRAST, "sun" },
- { AV_CODEC_ID_SUNRAST, "ras" },
- { AV_CODEC_ID_SUNRAST, "rs" },
- { AV_CODEC_ID_SUNRAST, "im1" },
- { AV_CODEC_ID_SUNRAST, "im8" },
- { AV_CODEC_ID_SUNRAST, "im24" },
- { AV_CODEC_ID_SUNRAST, "im32" },
- { AV_CODEC_ID_SUNRAST, "sunras" },
- { AV_CODEC_ID_SVG, "svg" },
- { AV_CODEC_ID_SVG, "svgz" },
- { AV_CODEC_ID_JPEG2000, "j2c" },
- { AV_CODEC_ID_JPEG2000, "jp2" },
- { AV_CODEC_ID_JPEG2000, "jpc" },
- { AV_CODEC_ID_JPEG2000, "j2k" },
- { AV_CODEC_ID_DPX, "dpx" },
- { AV_CODEC_ID_EXR, "exr" },
- { AV_CODEC_ID_PICTOR, "pic" },
- { AV_CODEC_ID_V210X, "yuv10" },
- { AV_CODEC_ID_WEBP, "webp" },
- { AV_CODEC_ID_XBM, "xbm" },
- { AV_CODEC_ID_XPM, "xpm" },
- { AV_CODEC_ID_XFACE, "xface" },
- { AV_CODEC_ID_XWD, "xwd" },
- { AV_CODEC_ID_GEM, "img" },
- { AV_CODEC_ID_GEM, "ximg" },
- { AV_CODEC_ID_GEM, "timg" },
- { AV_CODEC_ID_VBN, "vbn" },
- { AV_CODEC_ID_JPEGXL, "jxl" },
- { AV_CODEC_ID_QOI, "qoi" },
- { AV_CODEC_ID_RADIANCE_HDR, "hdr" },
- { AV_CODEC_ID_WBMP, "wbmp" },
- { AV_CODEC_ID_NONE, NULL }
+#define TAG(CODECID, STR) { AV_CODEC_ID_ ## CODECID, #STR },
+IMG_TAGS(TAG)
};
static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
diff --git a/libavformat/img2.h b/libavformat/img2.h
index 5fd8ff77fc..e98902c96f 100644
--- a/libavformat/img2.h
+++ b/libavformat/img2.h
@@ -66,7 +66,7 @@ typedef struct VideoDemuxData {
typedef struct IdStrMap {
enum AVCodecID id;
- const char *str;
+ char str[12];
} IdStrMap;
extern const IdStrMap ff_img_tags[];
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
2024-04-07 20:51 ` James Almer
@ 2024-04-07 21:53 ` Andreas Rheinhardt
2024-04-07 22:21 ` James Almer
0 siblings, 1 reply; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 21:53 UTC (permalink / raw)
To: ffmpeg-devel
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 <nb_channels and < 64, then it is equivalent to the
native channel layout with the same nb_channels whose mask is the
bitwise or of all (1ULL << ch_layout.u.map[i].id).
> 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 <andreas.rheinhardt@outlook.com>
>> ---
>> 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
2024-04-07 21:53 ` Andreas Rheinhardt
@ 2024-04-07 22:21 ` James Almer
2024-04-07 22:26 ` Andreas Rheinhardt
0 siblings, 1 reply; 24+ messages in thread
From: James Almer @ 2024-04-07 22:21 UTC (permalink / raw)
To: ffmpeg-devel
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 <nb_channels and < 64, then it is equivalent to the
> 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 <andreas.rheinhardt@outlook.com>
>>> ---
>>> 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-request@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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
2024-04-07 22:21 ` James Almer
@ 2024-04-07 22:26 ` Andreas Rheinhardt
2024-04-07 22:35 ` James Almer
0 siblings, 1 reply; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-07 22:26 UTC (permalink / raw)
To: ffmpeg-devel
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 <nb_channels and < 64, then it is equivalent to the
>> 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 <andreas.rheinhardt@outlook.com>
>>>> ---
>>>> 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
2024-04-07 22:26 ` Andreas Rheinhardt
@ 2024-04-07 22:35 ` James Almer
0 siblings, 0 replies; 24+ messages in thread
From: James Almer @ 2024-04-07 22:35 UTC (permalink / raw)
To: ffmpeg-devel
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 <nb_channels and < 64, then it is equivalent to the
>>> 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 <andreas.rheinhardt@outlook.com>
>>>>> ---
>>>>> 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 18/18] avcodec/ac3enc: Avoid calculating the CRC multiple times
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (16 preceding siblings ...)
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 17/17] avformat/img2: Avoid relocations for ff_img_tags Andreas Rheinhardt
@ 2024-04-08 0:56 ` Andreas Rheinhardt
2024-04-10 6:16 ` [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-08 0:56 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
` (17 preceding siblings ...)
2024-04-08 0:56 ` [FFmpeg-devel] [PATCH 18/18] avcodec/ac3enc: Avoid calculating the CRC multiple times Andreas Rheinhardt
@ 2024-04-10 6:16 ` Andreas Rheinhardt
18 siblings, 0 replies; 24+ messages in thread
From: Andreas Rheinhardt @ 2024-04-10 6:16 UTC (permalink / raw)
To: ffmpeg-devel
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 <andreas.rheinhardt@outlook.com>
> ---
> 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;
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2024-04-10 6:16 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
2024-04-07 20:51 ` James Almer
2024-04-07 21:53 ` Andreas Rheinhardt
2024-04-07 22:21 ` James Almer
2024-04-07 22:26 ` Andreas Rheinhardt
2024-04-07 22:35 ` James Almer
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 02/17] avcodec/ac3enc: Don't overwrite AVCodecContext.ch_layout Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 03/17] avcodec/ac3enc: Remove redundant channel layout checks Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 04/17] avcodec/ac3enc: Use bit-operations for bit-mask Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 05/17] avcodec/ac3enc: Avoid copying strings Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 06/17] avcodec/ac3enc: Remove always-false sample rate check Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 07/17] avcodec/ac3enc: Remove disabled code for RealAudio variant of AC-3 Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 08/17] avcodec/ac3enc: Use common encode_frame function Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 09/17] avcodec/ac3enc: Move ff_ac3_validate_metadate() upwards Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 10/17] avcodec/ac3enc: Share more code between fixed/float encoders Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 11/17] avcodec/ac3enc: Deduplicate allocating buffers Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 12/17] avcodec/ac3enc: Deduplicate copying input samples Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 13/17] avcodec/ac3enc_float: Remove uninformative error message Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 14/17] avcodec/ac3enc: Avoid function pointers to initialize MDCT Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 15/17] avcodec/ac3enc: Move EAC-3 specific initialization to eac3enc.c Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 16/17] avcodec/flacenc: Avoid shift where possible Andreas Rheinhardt
2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 17/17] avformat/img2: Avoid relocations for ff_img_tags Andreas Rheinhardt
2024-04-08 0:56 ` [FFmpeg-devel] [PATCH 18/18] avcodec/ac3enc: Avoid calculating the CRC multiple times Andreas Rheinhardt
2024-04-10 6:16 ` [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git