[FFmpeg-devel] [PATCH 1/3] omadec: fix overflows during bit rate calculation

Andreas Cadhalpun andreas.cadhalpun at googlemail.com
Thu Dec 15 02:53:22 EET 2016


On 14.12.2016 11:16, Moritz Barsnick wrote:
> On Wed, Dec 14, 2016 at 01:02:41 +0100, Andreas Cadhalpun wrote:
>> On 13.12.2016 08:11, Paul B Mahol wrote:
>>>> -        st->codecpar->bit_rate    = samplerate * framesize * 8 / 2048;
>>>> +        st->codecpar->bit_rate    = samplerate * framesize / 256;
>>
>> Why multiply with 8 when dividing by a multiple of 8 directly afterwards?
>> That's just a waste of computational resources.
> 
> I can only explain the term with "readability" (e.g. "number of bytes
> times 8 is number of bits, divided by 2048 is the rate"). If you
> bracket the (8 / 2048), it would avoid the overflow, and the compiler
> should evaluate the term to that constant 256 anyway, right? (Just if
> anyone cares about the presumed readability.)

Well, (8 / 2048) = 0, but one can do "/ (2048 / 8)".
Attached is a version doing it that way. Do you think that's better?

Best regards,
Andreas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-omadec-fix-overflows-during-bit-rate-calculation.patch
Type: text/x-diff
Size: 1445 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161215/3da0f663/attachment.patch>


More information about the ffmpeg-devel mailing list