On 20.11.2015 10:51, Michael Niedermayer wrote:
> On Fri, Nov 20, 2015 at 12:16:09AM +0100, Andreas Cadhalpun wrote:
>>  aacsbr_template.c |    8 ++++++++
>>  1 file changed, 8 insertions(+)
>> 43ace0364265ef16eecd6ca2d9564cc9585847f7  
>> 0001-aacsbr-don-t-call-sbr_dequant-twice-without-intermed.patch
>> From 0237ebfca9571d2d3e51f5c5dc15f8f5a516510a Mon Sep 17 00:00:00 2001
>> From: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
>> Date: Fri, 20 Nov 2015 00:04:50 +0100
>> Subject: [PATCH] aacsbr: don't call sbr_dequant twice without intermediate
>>  read_sbr_data
>>
>> Doing that doesn't make sense, because the only purpose of sbr_dequant
>> is to process the data from read_sbr_data.
>>
>> Signed-off-by: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
>> ---
>>  libavcodec/aacsbr_template.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
>> index cf18862..564930a 100644
>> --- a/libavcodec/aacsbr_template.c
>> +++ b/libavcodec/aacsbr_template.c
>> @@ -1041,6 +1041,7 @@ static unsigned int read_sbr_data(AACContext *ac, 
>> SpectralBandReplication *sbr,
>>      unsigned int cnt = get_bits_count(gb);
>>  
>>      sbr->id_aac = id_aac;
>> +    sbr->start = 2;
> 
> the new value should be documented
> or maybe it would be possible to use a new field with self explanatory
> name

I think using a new field is a good idea for code readability.
Updated patch attached.

Best regards,
Andreas

>From 10acbb3939e576594b43965847ea7b2231722ee4 Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
Date: Fri, 20 Nov 2015 20:15:21 +0100
Subject: [PATCH] aacsbr: don't call sbr_dequant twice without intermediate
 read_sbr_data

Doing that doesn't make sense, because the only purpose of sbr_dequant
is to process the data from read_sbr_data.

Signed-off-by: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
---
 libavcodec/aacsbr_template.c | 10 ++++++++++
 libavcodec/sbr.h             |  1 +
 2 files changed, 11 insertions(+)

diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index cf18862..1d7a7be 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -72,6 +72,7 @@ av_cold void AAC_RENAME(ff_aac_sbr_init)(void)
 /** Places SBR in pure upsampling mode. */
 static void sbr_turnoff(SpectralBandReplication *sbr) {
     sbr->start = 0;
+    sbr->ready_for_dequant = 0;
     // Init defults used in pure upsampling mode
     sbr->kx[1] = 32; //Typo in spec, kx' inits to 32
     sbr->m[1] = 0;
@@ -179,6 +180,7 @@ static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext
     SpectrumParameters old_spectrum_params;
 
     sbr->start = 1;
+    sbr->ready_for_dequant = 0;
 
     // Save last spectrum parameters variables to compare to new ones
     memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters));
@@ -1041,6 +1043,7 @@ static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr,
     unsigned int cnt = get_bits_count(gb);
 
     sbr->id_aac = id_aac;
+    sbr->ready_for_dequant = 1;
 
     if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) {
         if (read_sbr_single_channel_element(ac, sbr, gb)) {
@@ -1476,6 +1479,12 @@ void AAC_RENAME(ff_sbr_apply)(AACContext *ac, SpectralBandReplication *sbr, int
         sbr_turnoff(sbr);
     }
 
+    if (sbr->start && !sbr->ready_for_dequant) {
+        av_log(ac->avctx, AV_LOG_ERROR,
+               "No quantized data read for sbr_dequant.\n");
+        sbr_turnoff(sbr);
+    }
+
     if (!sbr->kx_and_m_pushed) {
         sbr->kx[0] = sbr->kx[1];
         sbr->m[0] = sbr->m[1];
@@ -1485,6 +1494,7 @@ void AAC_RENAME(ff_sbr_apply)(AACContext *ac, SpectralBandReplication *sbr, int
 
     if (sbr->start) {
         sbr_dequant(sbr, id_aac);
+        sbr->ready_for_dequant = 0;
     }
     for (ch = 0; ch < nch; ch++) {
         /* decode channel */
diff --git a/libavcodec/sbr.h b/libavcodec/sbr.h
index 4a94c4a..eb7d1ae 100644
--- a/libavcodec/sbr.h
+++ b/libavcodec/sbr.h
@@ -139,6 +139,7 @@ typedef struct AACSBRContext {
 struct SpectralBandReplication {
     int                sample_rate;
     int                start;
+    int                ready_for_dequant;
     int                id_aac;
     int                reset;
     SpectrumParameters spectrum_params;
-- 
2.6.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to