* [FFmpeg-devel] [PATCH 1/4] aacdec_usac: respect tns_on_lr flag
@ 2024-06-06 5:12 Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 2/4] aacdec_usac: do not continue parsing bitstream on core_mode == 1 Lynne via ffmpeg-devel
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-06-06 5:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
This was left out, and due to av_unused, forgotten about.
---
libavcodec/aac/aacdec.h | 1 +
libavcodec/aac/aacdec_usac.c | 16 ++++++++++++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h
index ee21a94007..f0a33e7ac3 100644
--- a/libavcodec/aac/aacdec.h
+++ b/libavcodec/aac/aacdec.h
@@ -230,6 +230,7 @@ typedef struct SingleChannelElement {
typedef struct AACUsacStereo {
uint8_t common_window;
uint8_t common_tw;
+ uint8_t tns_on_lr; ///< Apply TNS before M/S and stereo prediction
uint8_t ms_mask_mode;
uint8_t config_idx;
diff --git a/libavcodec/aac/aacdec_usac.c b/libavcodec/aac/aacdec_usac.c
index 561734f930..3b4e980df4 100644
--- a/libavcodec/aac/aacdec_usac.c
+++ b/libavcodec/aac/aacdec_usac.c
@@ -876,14 +876,14 @@ static int decode_usac_stereo_info(AACDecContext *ac, AACUSACConfig *usac,
return AVERROR_PATCHWELCOME;
}
+ us->tns_on_lr = 0;
sce1->tns.present = sce2->tns.present = 0;
if (tns_active) {
- av_unused int tns_on_lr;
int common_tns = 0;
if (us->common_window)
common_tns = get_bits1(gb);
- tns_on_lr = get_bits1(gb);
+ us->tns_on_lr = get_bits1(gb);
if (common_tns) {
ret = ff_aac_decode_tns(ac, &sce1->tns, gb, ics1);
if (ret < 0)
@@ -1214,6 +1214,14 @@ static void spectrum_decode(AACDecContext *ac, AACUSACConfig *usac,
}
if (nb_channels > 1 && us->common_window) {
+ for (int ch = 0; ch < nb_channels; ch++) {
+ SingleChannelElement *sce = &cpe->ch[ch];
+
+ /* Apply TNS, if the tns_on_lr bit is not set. */
+ if (sce->tns.present && !us->tns_on_lr)
+ ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1);
+ }
+
if (us->ms_mask_mode == 3) {
const float *filt;
complex_stereo_downmix_cur(ac, cpe, us->dmix_re);
@@ -1248,8 +1256,8 @@ static void spectrum_decode(AACDecContext *ac, AACUSACConfig *usac,
for (int ch = 0; ch < nb_channels; ch++) {
SingleChannelElement *sce = &cpe->ch[ch];
- /* Apply TNS */
- if (sce->tns.present)
+ /* Apply TNS, if it hasn't been applied yet. */
+ if (sce->tns.present && ((nb_channels == 1) || (us->tns_on_lr)))
ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1);
ac->oc[1].m4ac.frame_length_short ? ac->dsp.imdct_and_windowing_768(ac, sce) :
--
2.43.0.381.gb435a96ce8
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 2/4] aacdec_usac: do not continue parsing bitstream on core_mode == 1
2024-06-06 5:12 [FFmpeg-devel] [PATCH 1/4] aacdec_usac: respect tns_on_lr flag Lynne via ffmpeg-devel
@ 2024-06-06 5:12 ` Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 3/4] aacdec_usac: decouple TNS active from TNS data present flag Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 4/4] aacdec_usac: skip coeff decoding if the number to be decoded is 0 Lynne via ffmpeg-devel
2 siblings, 0 replies; 4+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-06-06 5:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
Although LPD is not functional yet, the bitstream ends at that point.
---
libavcodec/aac/aacdec_usac.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libavcodec/aac/aacdec_usac.c b/libavcodec/aac/aacdec_usac.c
index 3b4e980df4..9b28a9e90b 100644
--- a/libavcodec/aac/aacdec_usac.c
+++ b/libavcodec/aac/aacdec_usac.c
@@ -1301,6 +1301,7 @@ static int decode_usac_core_coder(AACDecContext *ac, AACUSACConfig *usac,
ret = ff_aac_ldp_parse_channel_stream(ac, usac, ue, gb);
if (ret < 0)
return ret;
+ continue;
}
if ((nb_channels == 1) ||
--
2.43.0.381.gb435a96ce8
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 3/4] aacdec_usac: decouple TNS active from TNS data present flag
2024-06-06 5:12 [FFmpeg-devel] [PATCH 1/4] aacdec_usac: respect tns_on_lr flag Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 2/4] aacdec_usac: do not continue parsing bitstream on core_mode == 1 Lynne via ffmpeg-devel
@ 2024-06-06 5:12 ` Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 4/4] aacdec_usac: skip coeff decoding if the number to be decoded is 0 Lynne via ffmpeg-devel
2 siblings, 0 replies; 4+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-06-06 5:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
The issue was that in case of common TNS parameters, TNS was
entirely skipped, as tns.present was set to 0.
---
libavcodec/aac/aacdec.h | 1 +
libavcodec/aac/aacdec_usac.c | 25 +++++++++++++++----------
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h
index f0a33e7ac3..a2ef4a82e8 100644
--- a/libavcodec/aac/aacdec.h
+++ b/libavcodec/aac/aacdec.h
@@ -125,6 +125,7 @@ typedef struct LongTermPrediction {
typedef struct AACUsacElemData {
uint8_t core_mode;
uint8_t scale_factor_grouping;
+ uint8_t tns_data_present;
/* Timewarping ratio */
#define NUM_TW_NODES 16
diff --git a/libavcodec/aac/aacdec_usac.c b/libavcodec/aac/aacdec_usac.c
index 9b28a9e90b..97655787ee 100644
--- a/libavcodec/aac/aacdec_usac.c
+++ b/libavcodec/aac/aacdec_usac.c
@@ -877,7 +877,7 @@ static int decode_usac_stereo_info(AACDecContext *ac, AACUSACConfig *usac,
}
us->tns_on_lr = 0;
- sce1->tns.present = sce2->tns.present = 0;
+ ue1->tns_data_present = ue2->tns_data_present = 0;
if (tns_active) {
int common_tns = 0;
if (us->common_window)
@@ -889,15 +889,17 @@ static int decode_usac_stereo_info(AACDecContext *ac, AACUSACConfig *usac,
if (ret < 0)
return ret;
memcpy(&sce2->tns, &sce1->tns, sizeof(sce1->tns));
- sce2->tns.present = 0;
- sce1->tns.present = 0;
+ sce2->tns.present = 1;
+ sce1->tns.present = 1;
+ ue1->tns_data_present = 0;
+ ue2->tns_data_present = 0;
} else {
if (get_bits1(gb)) {
- sce2->tns.present = 1;
- sce1->tns.present = 1;
+ ue1->tns_data_present = 1;
+ ue2->tns_data_present = 1;
} else {
- sce2->tns.present = get_bits1(gb);
- sce1->tns.present = !sce2->tns.present;
+ ue2->tns_data_present = get_bits1(gb);
+ ue1->tns_data_present = !ue2->tns_data_present;
}
}
}
@@ -1277,12 +1279,14 @@ static int decode_usac_core_coder(AACDecContext *ac, AACUSACConfig *usac,
uint8_t global_gain;
us->common_window = 0;
- che->ch[0].tns.present = che->ch[1].tns.present = 0;
for (int ch = 0; ch < nb_channels; ch++) {
SingleChannelElement *sce = &che->ch[ch];
AACUsacElemData *ue = &sce->ue;
+ sce->tns.present = 0;
+ ue->tns_data_present = 0;
+
ue->core_mode = get_bits1(gb);
}
@@ -1306,7 +1310,7 @@ static int decode_usac_core_coder(AACDecContext *ac, AACUSACConfig *usac,
if ((nb_channels == 1) ||
(che->ch[0].ue.core_mode != che->ch[1].ue.core_mode))
- sce->tns.present = get_bits1(gb);
+ ue->tns_data_present = get_bits1(gb);
/* fd_channel_stream */
global_gain = get_bits(gb, 8);
@@ -1351,7 +1355,8 @@ static int decode_usac_core_coder(AACDecContext *ac, AACUSACConfig *usac,
ac->dsp.dequant_scalefactors(sce);
- if (sce->tns.present) {
+ if (ue->tns_data_present) {
+ sce->tns.present = 1;
ret = ff_aac_decode_tns(ac, &sce->tns, gb, ics);
if (ret < 0)
return ret;
--
2.43.0.381.gb435a96ce8
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 4/4] aacdec_usac: skip coeff decoding if the number to be decoded is 0
2024-06-06 5:12 [FFmpeg-devel] [PATCH 1/4] aacdec_usac: respect tns_on_lr flag Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 2/4] aacdec_usac: do not continue parsing bitstream on core_mode == 1 Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 3/4] aacdec_usac: decouple TNS active from TNS data present flag Lynne via ffmpeg-devel
@ 2024-06-06 5:12 ` Lynne via ffmpeg-devel
2 siblings, 0 replies; 4+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-06-06 5:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
Yet another thing not mentioned in the spec.
---
libavcodec/aac/aacdec_usac.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/libavcodec/aac/aacdec_usac.c b/libavcodec/aac/aacdec_usac.c
index 97655787ee..5dd489a43b 100644
--- a/libavcodec/aac/aacdec_usac.c
+++ b/libavcodec/aac/aacdec_usac.c
@@ -572,9 +572,15 @@ static int decode_spectrum_and_dequant_ac(AACDecContext *s, float coef[1024],
int gb_count;
GetBitContext gb2;
- ff_aac_ac_init(&ac, gb);
c = ff_aac_ac_map_process(state, reset, N);
+ if (!len) {
+ ff_aac_ac_finish(state, 0, N);
+ return 0;
+ }
+
+ ff_aac_ac_init(&ac, gb);
+
/* Backup reader for rolling back by 14 bits at the end */
gb2 = *gb;
gb_count = get_bits_count(&gb2);
--
2.43.0.381.gb435a96ce8
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-06 5:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-06 5:12 [FFmpeg-devel] [PATCH 1/4] aacdec_usac: respect tns_on_lr flag Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 2/4] aacdec_usac: do not continue parsing bitstream on core_mode == 1 Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 3/4] aacdec_usac: decouple TNS active from TNS data present flag Lynne via ffmpeg-devel
2024-06-06 5:12 ` [FFmpeg-devel] [PATCH 4/4] aacdec_usac: skip coeff decoding if the number to be decoded is 0 Lynne via ffmpeg-devel
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