[FFmpeg-cvslog] r12593 - trunk/libavcodec/ac3dec.c

Justin Ruggles justinruggles
Wed Mar 26 04:33:37 CET 2008


Michael Niedermayer wrote:
> On Tue, Mar 25, 2008 at 08:49:41PM -0400, Justin Ruggles wrote:
>> M?ns Rullg?rd wrote:
>>> Justin Ruggles <justinruggles at bellsouth.net> writes:
>>>
>>>> Uoti Urpala wrote:
>>>>> On Tue, 2008-03-25 at 19:38 -0400, Justin Ruggles wrote:
>>>>>> jbr wrote:
>>>>>>> @@ -191,6 +194,7 @@ typedef struct {
>>>>>>>      GetBitContext gbc;                      ///< bitstream reader
>>>>>>>      AVRandomState dith_state;               ///< for dither generation
>>>>>>>      AVCodecContext *avctx;                  ///< parent context
>>>>>>> +    uint8_t input_buffer[AC3_MAX_FRAME_SIZE];   ///< temp buffer to prevent overread
>>>>>>>  } AC3DecodeContext;
>>>>>> Right after I applied this, it occurred to me that it might be better to
>>>>>> allocate this with av_malloc() at decoder init depending on
>>>>>> error_resiliance.  Does that sound like a good idea?
>>>>> I haven't looked at the specific code in this case, but generally moving
>>>>> a commonly used buffer out of a context struct could hurt performance.
>>>>> The compiler must either generate extra indirection through the struct
>>>>> or reserve another register to keep the location of the buffer. OTOH if
>>>>> time is mostly spent elsewhere, or if accesses to be buffer are not
>>>>> interleaved with code which would also need to access the struct, then
>>>>> it might not matter.
>>>> Thanks Uoti. This is definitely a commonly used buffer, so maybe it is
>>>> not a big enough trade-off just to reduce memory footprint when running
>>>> with zero error_resilience.  I will test the speed, but if what you say
>>>> is true, it will probably be slower.
>>> On most systems, the extra allocation won't matter (much), since
>>> physical pages are allocated only when written to.
>> Indeed, this change had pretty much zero affect on performance on my system.
>>
>> So does the attached look ok?
>>
>> -Justin
>>
> 
>> Index: libavcodec/ac3dec.c
>> ===================================================================
>> --- libavcodec/ac3dec.c	(revision 12594)
>> +++ libavcodec/ac3dec.c	(working copy)
>> @@ -194,7 +194,7 @@
>>      GetBitContext gbc;                      ///< bitstream reader
>>      AVRandomState dith_state;               ///< for dither generation
>>      AVCodecContext *avctx;                  ///< parent context
>> -    uint8_t input_buffer[AC3_MAX_FRAME_SIZE];   ///< temp buffer to prevent overread
>> +    uint8_t *input_buffer;                  ///< temp buffer to prevent overread
>>  } AC3DecodeContext;
>>  
>>  /**
>> @@ -294,6 +294,13 @@
>>      }
>>      s->downmixed = 1;
>>  
>> +    /* allocate context input buffer */
>> +    if (avctx->error_resilience >= FF_ER_CAREFUL) {
>> +        s->input_buffer = av_mallocz(AC3_MAX_FRAME_SIZE);
>> +        if (!s->input_buffer)
>> +            return AVERROR_NOMEM;
>> +    }
> 
> You dont need the if() as you check it later anyway, also you do need a
> av_free() somewhere.
> and then a + FF_INPUT_BUFFER_PADDING_SIZE might be needed as well

ah, yes. I did forget the av_free() and about the padding.

>> +
>>      return 0;
>>  }
>>  
>> @@ -1137,7 +1144,7 @@
>>      int i, blk, ch, err;
>>  
>>      /* initialize the GetBitContext with the start of valid AC-3 Frame */
>> -    if(avctx->error_resilience >= FF_ER_CAREFUL) {
>> +    if(avctx->error_resilience >= FF_ER_CAREFUL && s->input_buffer) {
> 
> I do not think the error_resilience check here is needed anymore.

good point.

-Justin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ac3_malloc_buffer.diff
Type: text/x-diff
Size: 1509 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-cvslog/attachments/20080325/33a36a69/attachment.diff>



More information about the ffmpeg-cvslog mailing list