[FFmpeg-devel] [PATCH] AAC Decoder round 4
Michael Niedermayer
michaelni
Tue Aug 5 23:17:01 CEST 2008
On Tue, Aug 05, 2008 at 04:32:23PM +0100, Robert Swain wrote:
> 2008/7/27 Michael Niedermayer <michaelni at gmx.at>:
> > On Fri, Jul 18, 2008 at 03:13:38PM +0100, Robert Swain wrote:
> >> + * @param sf array of scalefactors or intensity stereo positions used for a window group's scalefactor band
> >> + * @return Returns error status. 0 - OK, !0 - error
> >> + */
> >> +static int decode_scalefactors(AACContext * ac, GetBitContext * gb, float mix_gain, unsigned int global_gain,
> >> + IndividualChannelStream * ics, const enum BandType band_type[][64], const int band_type_run_end[][64], float sf[][64]) {
> >> + const int sf_offset = ac->sf_offset + (ics->window_sequence == EIGHT_SHORT_SEQUENCE ? 12 : 0);
> >> + int g, i;
> >> + int offset[3] = { global_gain, global_gain - 90, 100 };
> >> + int noise_flag = 1;
> >> + static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" };
> >> + ics->intensity_present = 0;
> >> + for (g = 0; g < ics->num_window_groups; g++) {
> >> + for (i = 0; i < ics->max_sfb;) {
> >> + int run_end = band_type_run_end[g][i];
> >> + if (band_type[g][i] == ZERO_BT) {
> >> + for(; i < run_end; i++)
> >> + sf[g][i] = 0.;
> >> + }else if((band_type[g][i] == INTENSITY_BT) || (band_type[g][i] == INTENSITY_BT2)) {
> >> + ics->intensity_present = 1;
> >
> >> + for(; i < run_end; i++) {
> >> + offset[2] += get_vlc2(gb, mainvlc.table, 7, 3) - 60;
> >> + if(offset[2] > 255) {
> >> + av_log(ac->avccontext, AV_LOG_ERROR,
> >> + "%s (%d) out of range.\n", sf_str[2], offset[2]);
> >> + return -1;
> >> + }
> >> + sf[g][i] = pow2sf_tab[-offset[2] + 300];
> >> + sf[g][i] *= mix_gain;
> >> + }
> >
> > you are checking for a max of 255 here, cant this also overflow on the
> > negative side? offset is not unsigned so <0 is not naturally caught
>
> I found text in the spec that states the scalefactors (at least in the
> normal scalefactor and noise cases) should be [0, 255]. global_gain is
> 8 bits unsigned read from the bitstream so the initial values of
> offset[] could be < 0.
>
> As it is, declaring offset[] as unsigned won't work. However, I think
> I could make offset[] int16_t and do if(offset[] & 0xFF00) unless you
> have a better suggestion. I thought that would be a fast check. I
> could just do if(offset[] < 0 || offset[] > 255) if you would prefer.
if(offset[] > 255U)
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080805/abd573e6/attachment.pgp>
More information about the ffmpeg-devel
mailing list