[FFmpeg-devel] [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture

Anatoly Nenashev anatoly.nenashev
Mon Feb 28 15:13:27 CET 2011


On 26.02.2011 22:05, Ronald S. Bultje wrote:
> Hi,
>
> On Wed, Feb 16, 2011 at 5:02 PM, Anatoly Nenashev
> <anatoly.nenashev at ovsoft.ru>  wrote:
>    
>> On 17.02.2011 00:38, M?ns Rullg?rd wrote:
>>      
>>> Anatoly Nenashev<anatoly.nenashev at ovsoft.ru>    writes:
>>>
>>>
>>>        
>>>>   From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001
>>>> From: anatoly<anatoly.nenashev at ovsoft.ru>
>>>> Date: Tue, 15 Feb 2011 11:33:56 +0300
>>>> Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's
>>>> picture
>>>>
>>>> ---
>>>>   libavcodec/jpeglsdec.c |   18 +++++++++---------
>>>>   libavcodec/mjpegbdec.c |    2 +-
>>>>   libavcodec/mjpegdec.c  |   44
>>>> +++++++++++++++++++++++++++-----------------
>>>>   libavcodec/mjpegdec.h  |    2 +-
>>>>   4 files changed, 38 insertions(+), 28 deletions(-)
>>>>
>>>>          
>>> [...]
>>>
>>>
>>>        
>>>> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
>>>> index 9792616..2db6760 100644
>>>> --- a/libavcodec/mjpegdec.c
>>>> +++ b/libavcodec/mjpegdec.c
>>>> @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext
>>>> *avctx)
>>>>   {
>>>>       MJpegDecodeContext *s = avctx->priv_data;
>>>>
>>>> +    if (!s->picture_ptr) {
>>>> +        s->picture_ptr = av_mallocz(sizeof(AVFrame));
>>>> +        if (!s->picture_ptr)
>>>> +              return AVERROR(ENOMEM);
>>>> +        s->picture_ptr->reference = 0;
>>>> +    }
>>>> +
>>>>       s->avctx = avctx;
>>>>       dsputil_init(&s->dsp, avctx);
>>>>       ff_init_scantable(s->dsp.idct_permutation,&s->scantable,
>>>> ff_zigzag_direct);
>>>>
>>>>          
>>> [...]
>>>
>>>
>>>        
>>>> diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h
>>>> index 9c78ab2..a1dee59 100644
>>>> --- a/libavcodec/mjpegdec.h
>>>> +++ b/libavcodec/mjpegdec.h
>>>> @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext {
>>>>       int h_max, v_max; /* maximum h and v counts */
>>>>       int quant_index[4];   /* quant table index for each component */
>>>>       int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right
>>>> to do that ?) */
>>>> -    AVFrame picture; /* picture structure */
>>>> +    AVFrame *picture_ptr; /* pointer to picture structure */
>>>>       int got_picture;                                ///<    we found a SOF
>>>> and picture is valid, too.
>>>>       int linesize[MAX_COMPONENTS];                   ///<    linesize<<
>>>>   interlaced
>>>>       int8_t *qscale_table;
>>>> --
>>>>
>>>>          
>>> Why don't you simply make an array: AVFrame picture[2]?
>>>        
>> Because in this case this isn't enough. I should also add "picture_index"
>> field and implement switching between pictures. I don't think this must be
>> done in this file.
>>      
> For mxpeg, and that's why that's in another patch (4/4) and file.
>
> But this is mjpeg.c. You remove picture and replace it with
> picture_ptr, and then allocate picture_ptr. Why not leave picture, add
> picture_ptr so no extra allocation is needed?
>
> Ronald
>
>    

Ok. Dynamic memory allocation removed.





More information about the ffmpeg-devel mailing list