video.c 28.2 KB
Newer Older
1
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
2
 * video.c: video decoder using the ffmpeg library
3 4
 *****************************************************************************
 * Copyright (C) 1999-2001 VideoLAN
5
 * $Id$
6 7
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8
 *          Gildas Bazin <gbazin@videolan.org>
9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
14
 *
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <vlc/vlc.h>
#include <vlc/decoder.h>

Gildas Bazin's avatar
 
Gildas Bazin committed
31 32 33 34 35 36 37
/* ffmpeg header */
#ifdef HAVE_FFMPEG_AVCODEC_H
#   include <ffmpeg/avcodec.h>
#else
#   include <avcodec.h>
#endif

38
#include "ffmpeg.h"
39

Gildas Bazin's avatar
 
Gildas Bazin committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/*****************************************************************************
 * decoder_sys_t : decoder descriptor
 *****************************************************************************/
struct decoder_sys_t
{
    /* Common part between video and audio decoder */
    int i_cat;
    int i_codec_id;
    char *psz_namecodec;

    AVCodecContext      *p_context;
    AVCodec             *p_codec;

    /* Video decoder specific part */
    mtime_t input_pts;
Gildas Bazin's avatar
 
Gildas Bazin committed
55
    mtime_t input_dts;
Gildas Bazin's avatar
 
Gildas Bazin committed
56 57 58 59
    mtime_t i_pts;

    AVFrame          *p_ff_pic;
    BITMAPINFOHEADER *p_format;
60

Gildas Bazin's avatar
 
Gildas Bazin committed
61 62 63 64 65 66 67 68 69 70 71 72 73
    /* for frame skipping algo */
    int b_hurry_up;
    int i_frame_skip;

    /* how many decoded frames are late */
    int     i_late_frames;
    mtime_t i_late_frames_start;

    /* for direct rendering */
    int b_direct_rendering;

    vlc_bool_t b_has_b_frames;

74 75 76
    /* Hack to force display of still pictures */
    vlc_bool_t b_first_frame;

Gildas Bazin's avatar
 
Gildas Bazin committed
77 78
    int i_buffer_orig, i_buffer;
    char *p_buffer_orig, *p_buffer;
Gildas Bazin's avatar
 
Gildas Bazin committed
79 80 81

    /* Postprocessing handle */
    void *p_pp;
Gildas Bazin's avatar
 
Gildas Bazin committed
82 83
    vlc_bool_t b_pp;
    vlc_bool_t b_pp_async;
Gildas Bazin's avatar
 
Gildas Bazin committed
84
    vlc_bool_t b_pp_init;
Gildas Bazin's avatar
 
Gildas Bazin committed
85
};
86

Gildas Bazin's avatar
 
Gildas Bazin committed
87 88 89
/* FIXME (dummy palette for now) */
static AVPaletteControl palette_control;

Gildas Bazin's avatar
 
Gildas Bazin committed
90
/*****************************************************************************
91
 * Local prototypes
Gildas Bazin's avatar
 
Gildas Bazin committed
92
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
93 94 95
static void ffmpeg_CopyPicture    ( decoder_t *, picture_t *, AVFrame * );
static int  ffmpeg_GetFrameBuf    ( struct AVCodecContext *, AVFrame * );
static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *, AVFrame * );
96

97 98 99 100 101 102
static uint32_t ffmpeg_CodecTag( vlc_fourcc_t fcc )
{
    uint8_t *p = (uint8_t*)&fcc;
    return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}

Gildas Bazin's avatar
 
Gildas Bazin committed
103 104 105
/*****************************************************************************
 * Local Functions
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
106
static uint32_t ffmpeg_PixFmtToChroma( int i_ff_chroma )
107
{
108 109
    switch( i_ff_chroma )
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
110
    case PIX_FMT_YUV420P:
Gildas Bazin's avatar
 
Gildas Bazin committed
111
        return VLC_FOURCC('I','4','2','0');
Gildas Bazin's avatar
 
Gildas Bazin committed
112
    case PIX_FMT_YUV422P:
Gildas Bazin's avatar
 
Gildas Bazin committed
113
        return VLC_FOURCC('I','4','2','2');
Gildas Bazin's avatar
 
Gildas Bazin committed
114
    case PIX_FMT_YUV444P:
Gildas Bazin's avatar
 
Gildas Bazin committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
        return VLC_FOURCC('I','4','4','4');

    case PIX_FMT_YUV422:
        return VLC_FOURCC('Y','U','Y','2');

    case PIX_FMT_RGB555:
        return VLC_FOURCC('R','V','1','5');
    case PIX_FMT_RGB565:
        return VLC_FOURCC('R','V','1','6');
    case PIX_FMT_RGB24:
        return VLC_FOURCC('R','V','2','4');
    case PIX_FMT_RGBA32:
        return VLC_FOURCC('R','V','3','2');
    case PIX_FMT_GRAY8:
        return VLC_FOURCC('G','R','E','Y');

Gildas Bazin's avatar
 
Gildas Bazin committed
131 132 133 134 135
    case PIX_FMT_YUV410P:
    case PIX_FMT_YUV411P:
    case PIX_FMT_BGR24:
    default:
        return 0;
136 137 138
    }
}

Gildas Bazin's avatar
 
Gildas Bazin committed
139 140 141
/* Returns a new picture buffer */
static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
                                            AVCodecContext *p_context )
142
{
Gildas Bazin's avatar
 
Gildas Bazin committed
143 144
    decoder_sys_t *p_sys = p_dec->p_sys;
    picture_t *p_pic;
145

Gildas Bazin's avatar
 
Gildas Bazin committed
146 147 148 149 150
    p_dec->fmt_out.video.i_width = p_context->width;
    p_dec->fmt_out.video.i_height = p_context->height;
    p_dec->fmt_out.i_codec = ffmpeg_PixFmtToChroma( p_context->pix_fmt );

    if( !p_context->width || !p_context->height )
151
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
152
        return NULL; /* invalid display size */
153 154
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
155
    if( !p_dec->fmt_out.i_codec )
156 157
    {
        /* we make conversion if possible*/
Gildas Bazin's avatar
 
Gildas Bazin committed
158
        p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
159
    }
160

161 162 163 164 165 166 167
    /* If an aspect-ratio was specified in the input format then force it */
    if( p_dec->fmt_in.video.i_aspect )
    {
        p_dec->fmt_out.video.i_aspect = p_dec->fmt_in.video.i_aspect;
    }
    else
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
168
#if LIBAVCODEC_BUILD >= 4687
169 170 171
        p_dec->fmt_out.video.i_aspect =
            VOUT_ASPECT_FACTOR * ( av_q2d(p_context->sample_aspect_ratio) *
                p_context->width / p_context->height );
Gildas Bazin's avatar
 
Gildas Bazin committed
172
#else
Gildas Bazin's avatar
 
Gildas Bazin committed
173
        p_dec->fmt_out.video.i_aspect =
174 175 176 177 178 179 180
            VOUT_ASPECT_FACTOR * p_context->aspect_ratio;
#endif
        if( p_dec->fmt_out.video.i_aspect == 0 )
        {
            p_dec->fmt_out.video.i_aspect =
                VOUT_ASPECT_FACTOR * p_context->width / p_context->height;
        }
181
    }
182

183 184 185 186 187 188
    if( p_context->frame_rate > 0 && p_context->frame_rate_base > 0 )
    {
        p_dec->fmt_out.video.i_frame_rate = p_context->frame_rate;
        p_dec->fmt_out.video.i_frame_rate_base = p_context->frame_rate_base;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
189
    p_pic = p_dec->pf_vout_buffer_new( p_dec );
190

Gildas Bazin's avatar
 
Gildas Bazin committed
191
#ifdef LIBAVCODEC_PP
Gildas Bazin's avatar
 
Gildas Bazin committed
192
    if( p_sys->p_pp && p_sys->b_pp && !p_sys->b_pp_init )
Gildas Bazin's avatar
 
Gildas Bazin committed
193 194 195 196 197
    {
        E_(InitPostproc)( p_dec, p_sys->p_pp, p_context->width,
                          p_context->height, p_context->pix_fmt );
        p_sys->b_pp_init = VLC_TRUE;
    }
198
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
199

Gildas Bazin's avatar
 
Gildas Bazin committed
200
    return p_pic;
201 202 203
}

/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
204
 * InitVideo: initialize the video decoder
205
 *****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
206 207
 * the ffmpeg codec will be opened, some memory allocated. The vout is not yet
 * opened (done after the first decoded frame).
208
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
209 210
int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
                      AVCodec *p_codec, int i_codec_id, char *psz_namecodec )
211
{
Gildas Bazin's avatar
 
Gildas Bazin committed
212
    decoder_sys_t *p_sys;
213
    vlc_value_t lockval;
Gildas Bazin's avatar
 
Gildas Bazin committed
214
    vlc_value_t val;
215 216 217

    var_Get( p_dec->p_libvlc, "avcodec", &lockval );

Gildas Bazin's avatar
 
Gildas Bazin committed
218 219 220 221 222 223 224 225 226 227 228 229 230
    /* Allocate the memory needed to store the decoder's structure */
    if( ( p_dec->p_sys = p_sys =
          (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
    {
        msg_Err( p_dec, "out of memory" );
        return VLC_EGENERIC;
    }

    p_dec->p_sys->p_context = p_context;
    p_dec->p_sys->p_codec = p_codec;
    p_dec->p_sys->i_codec_id = i_codec_id;
    p_dec->p_sys->psz_namecodec = psz_namecodec;
    p_sys->p_ff_pic = avcodec_alloc_frame();
Gildas Bazin's avatar
 
Gildas Bazin committed
231

Gildas Bazin's avatar
 
Gildas Bazin committed
232
    /* ***** Fill p_context with init values ***** */
233 234 235
    /* FIXME: remove when ffmpeg deals properly with avc1 */
    if( p_dec->fmt_in.i_codec != VLC_FOURCC('a','v','c','1') )
    /* End FIXME */
236
    p_sys->p_context->codec_tag = ffmpeg_CodecTag( p_dec->fmt_in.i_codec );
Gildas Bazin's avatar
 
Gildas Bazin committed
237 238
    p_sys->p_context->width  = p_dec->fmt_in.video.i_width;
    p_sys->p_context->height = p_dec->fmt_in.video.i_height;
239
    p_sys->p_context->bits_per_sample = p_dec->fmt_in.video.i_bits_per_pixel;
240 241

    /*  ***** Get configuration of ffmpeg plugin ***** */
Gildas Bazin's avatar
Gildas Bazin committed
242 243 244 245
    p_sys->p_context->workaround_bugs =
        config_GetInt( p_dec, "ffmpeg-workaround-bugs" );
    p_sys->p_context->error_resilience =
        config_GetInt( p_dec, "ffmpeg-error-resilience" );
246

Gildas Bazin's avatar
 
Gildas Bazin committed
247 248 249
    var_Create( p_dec, "grayscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Get( p_dec, "grayscale", &val );
    if( val.b_bool ) p_sys->p_context->flags |= CODEC_FLAG_GRAY;
250

Gildas Bazin's avatar
Gildas Bazin committed
251 252
    var_Create( p_dec, "ffmpeg-vismv", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
    var_Get( p_dec, "ffmpeg-vismv", &val );
253
#if LIBAVCODEC_BUILD >= 4698
Gildas Bazin's avatar
Gildas Bazin committed
254
    if( val.i_int ) p_sys->p_context->debug_mv = val.i_int;
255
#endif
Gildas Bazin's avatar
Gildas Bazin committed
256

257 258 259 260 261 262
    var_Create( p_dec, "ffmpeg-lowres", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
    var_Get( p_dec, "ffmpeg-lowres", &val );
#if LIBAVCODEC_BUILD >= 4723
    if( val.i_int > 0 && val.i_int <= 2 ) p_sys->p_context->lowres = val.i_int;
#endif

Gildas Bazin's avatar
 
Gildas Bazin committed
263 264 265 266 267 268 269 270 271 272 273
    /* ***** ffmpeg frame skipping ***** */
    var_Create( p_dec, "ffmpeg-hurry-up", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Get( p_dec, "ffmpeg-hurry-up", &val );
    p_sys->b_hurry_up = val.b_bool;

    /* ***** ffmpeg direct rendering ***** */
    p_sys->b_direct_rendering = 0;
    var_Create( p_dec, "ffmpeg-dr", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Get( p_dec, "ffmpeg-dr", &val );
    if( val.b_bool && (p_sys->p_codec->capabilities & CODEC_CAP_DR1) &&
        ffmpeg_PixFmtToChroma( p_sys->p_context->pix_fmt ) &&
Gildas Bazin's avatar
 
Gildas Bazin committed
274
        /* Apparently direct rendering doesn't work with YUV422P */
Gildas Bazin's avatar
 
Gildas Bazin committed
275
        p_sys->p_context->pix_fmt != PIX_FMT_YUV422P &&
Gildas Bazin's avatar
Gildas Bazin committed
276 277
        /* H264 uses too many reference frames */
        p_sys->i_codec_id != CODEC_ID_H264 &&
278
        !(p_sys->p_context->width % 16) && !(p_sys->p_context->height % 16) &&
279
#if LIBAVCODEC_BUILD >= 4698
280
        !p_sys->p_context->debug_mv )
281 282 283
#else
        1 )
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
284
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
285 286
        /* Some codecs set pix_fmt only after the 1st frame has been decoded,
         * so we need to do another check in ffmpeg_GetFrameBuf() */
Gildas Bazin's avatar
 
Gildas Bazin committed
287
        p_sys->b_direct_rendering = 1;
Gildas Bazin's avatar
 
Gildas Bazin committed
288 289 290
    }

#ifdef LIBAVCODEC_PP
291
    p_sys->p_pp = NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
292 293
    p_sys->b_pp = p_sys->b_pp_async = p_sys->b_pp_init = VLC_FALSE;
    p_sys->p_pp = E_(OpenPostproc)( p_dec, &p_sys->b_pp_async );
Gildas Bazin's avatar
 
Gildas Bazin committed
294 295
#endif

Gildas Bazin's avatar
 
Gildas Bazin committed
296
    /* ffmpeg doesn't properly release old pictures when frames are skipped */
Gildas Bazin's avatar
 
Gildas Bazin committed
297
    //if( p_sys->b_hurry_up ) p_sys->b_direct_rendering = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
298 299 300 301 302
    if( p_sys->b_direct_rendering )
    {
        msg_Dbg( p_dec, "using direct rendering" );
        p_sys->p_context->flags |= CODEC_FLAG_EMU_EDGE;
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
303

Gildas Bazin's avatar
 
Gildas Bazin committed
304 305
    /* Always use our get_buffer wrapper so we can calculate the
     * PTS correctly */
Gildas Bazin's avatar
 
Gildas Bazin committed
306 307 308
    p_sys->p_context->get_buffer = ffmpeg_GetFrameBuf;
    p_sys->p_context->release_buffer = ffmpeg_ReleaseFrameBuf;
    p_sys->p_context->opaque = p_dec;
Gildas Bazin's avatar
 
Gildas Bazin committed
309

310
    /* ***** init this codec with special data ***** */
Gildas Bazin's avatar
 
Gildas Bazin committed
311
    if( p_dec->fmt_in.i_extra )
312
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
313
        int i_size = p_dec->fmt_in.i_extra;
314

315
        if( p_sys->i_codec_id == CODEC_ID_SVQ3 )
316
        {
Laurent Aimar's avatar
Laurent Aimar committed
317 318
            uint8_t *p;

Gildas Bazin's avatar
 
Gildas Bazin committed
319 320 321
            p_sys->p_context->extradata_size = i_size + 12;
            p = p_sys->p_context->extradata  =
                malloc( p_sys->p_context->extradata_size );
Laurent Aimar's avatar
Laurent Aimar committed
322 323 324

            memcpy( &p[0],  "SVQ3", 4 );
            memset( &p[4], 0, 8 );
Gildas Bazin's avatar
 
Gildas Bazin committed
325
            memcpy( &p[12], p_dec->fmt_in.p_extra, i_size );
326 327

            /* Now remove all atoms before the SMI one */
328 329
            if( p_sys->p_context->extradata_size > 0x5a &&
                strncmp( &p[0x56], "SMI ", 4 ) )
330 331 332 333 334 335 336 337 338 339 340 341 342
            {
                uint8_t *psz = &p[0x52];

                while( psz < &p[p_sys->p_context->extradata_size - 8] )
                {
                    int i_size = GetDWBE( psz );
                    if( i_size <= 1 )
                    {
                        /* FIXME handle 1 as long size */
                        break;
                    }
                    if( !strncmp( &psz[4], "SMI ", 4 ) )
                    {
343 344
                        memmove( &p[0x52], psz,
                                 &p[p_sys->p_context->extradata_size] - psz );
345 346 347 348 349 350
                        break;
                    }

                    psz += i_size;
                }
            }
351
        }
352 353 354 355 356 357 358 359 360 361 362 363 364 365
        else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'R', 'V', '1', '0' ) ||
                 p_dec->fmt_in.i_codec == VLC_FOURCC( 'R', 'V', '1', '3' ) ||
                 p_dec->fmt_in.i_codec == VLC_FOURCC( 'R', 'V', '2', '0' ) )
        {
            if( p_dec->fmt_in.i_extra == 8 )
            {
                p_sys->p_context->extradata_size = 8;
                p_sys->p_context->extradata = malloc( 8 );

                memcpy( p_sys->p_context->extradata,
                        p_dec->fmt_in.p_extra,
                        p_dec->fmt_in.i_extra );
                p_sys->p_context->sub_id= ((uint32_t*)p_dec->fmt_in.p_extra)[1];

366 367
                msg_Warn( p_dec, "using extra data for RV codec sub_id=%08x",
                          p_sys->p_context->sub_id );
368 369
            }
        }
370 371 372 373 374 375
        /* FIXME: remove when ffmpeg deals properly with avc1 */
        else if( p_dec->fmt_in.i_codec == VLC_FOURCC('a','v','c','1') )
        {
            ;
        }
        /* End FIXME */
376
        else
377
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
378 379
            p_sys->p_context->extradata_size = i_size;
            p_sys->p_context->extradata =
Gildas Bazin's avatar
 
Gildas Bazin committed
380
                malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE );
Gildas Bazin's avatar
 
Gildas Bazin committed
381
            memcpy( p_sys->p_context->extradata,
Gildas Bazin's avatar
 
Gildas Bazin committed
382
                    p_dec->fmt_in.p_extra, i_size );
Gildas Bazin's avatar
 
Gildas Bazin committed
383
            memset( &((uint8_t*)p_sys->p_context->extradata)[i_size],
Gildas Bazin's avatar
 
Gildas Bazin committed
384
                    0, FF_INPUT_BUFFER_PADDING_SIZE );
385 386
        }
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
387

Gildas Bazin's avatar
 
Gildas Bazin committed
388
    /* ***** misc init ***** */
Gildas Bazin's avatar
 
Gildas Bazin committed
389
    p_sys->input_pts = p_sys->input_dts = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
390 391
    p_sys->i_pts = 0;
    p_sys->b_has_b_frames = VLC_FALSE;
392
    p_sys->b_first_frame = VLC_TRUE;
Gildas Bazin's avatar
 
Gildas Bazin committed
393
    p_sys->i_late_frames = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
394 395
    p_sys->i_buffer = 0;
    p_sys->i_buffer_orig = 1;
396
    p_sys->p_buffer_orig = p_sys->p_buffer = malloc( p_sys->i_buffer_orig );
Gildas Bazin's avatar
 
Gildas Bazin committed
397 398 399 400

    /* Set output properties */
    p_dec->fmt_out.i_cat = VIDEO_ES;
    p_dec->fmt_out.i_codec = ffmpeg_PixFmtToChroma( p_context->pix_fmt );
Gildas Bazin's avatar
 
Gildas Bazin committed
401

Gildas Bazin's avatar
 
Gildas Bazin committed
402
    /* Setup palette */
403
#if LIBAVCODEC_BUILD >= 4688
Gildas Bazin's avatar
 
Gildas Bazin committed
404 405 406 407 408
    if( p_dec->fmt_in.video.p_palette )
        p_sys->p_context->palctrl =
            (AVPaletteControl *)p_dec->fmt_in.video.p_palette;
    else
        p_sys->p_context->palctrl = &palette_control;
409
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
410

411 412 413 414 415 416
    /* ***** Open the codec ***** */
    vlc_mutex_lock( lockval.p_address );
    if( avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0 )
    {
        vlc_mutex_unlock( lockval.p_address );
        msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
417
        free( p_sys );
418 419 420 421 422 423
        return VLC_EGENERIC;
    }
    vlc_mutex_unlock( lockval.p_address );
    msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );


Gildas Bazin's avatar
 
Gildas Bazin committed
424
    return VLC_SUCCESS;
425 426 427
}

/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
428
 * DecodeVideo: Called to decode one or more frames
429
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
430
picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
431
{
Gildas Bazin's avatar
 
Gildas Bazin committed
432
    decoder_sys_t *p_sys = p_dec->p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
433
    int b_drawpicture;
434
    int b_null_size = VLC_FALSE;
Gildas Bazin's avatar
 
Gildas Bazin committed
435 436 437 438 439
    block_t *p_block;

    if( !pp_block || !*pp_block ) return NULL;

    p_block = *pp_block;
Gildas Bazin's avatar
 
Gildas Bazin committed
440

Laurent Aimar's avatar
Laurent Aimar committed
441
    if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
442 443 444 445
    {
        p_sys->i_buffer = 0;
        p_sys->i_pts = 0; /* To make sure we recover properly */

446 447 448
        p_sys->input_pts = p_sys->input_dts = 0;
        p_sys->i_late_frames = 0;

449 450 451 452
        block_Release( p_block );
        return NULL;
    }

Laurent Aimar's avatar
Laurent Aimar committed
453 454 455 456 457 458 459 460
    if( p_block->i_flags & BLOCK_FLAG_PREROLL )
    {
        /* Do not care about late frames when prerolling
         * TODO avoid decoding of non reference frame
         * (ie all B except for H264 where it depends only on nal_ref_idc) */
        p_sys->i_late_frames = 0;
    }

461
    if( !p_dec->b_pace_control && p_sys->i_late_frames > 0 &&
462 463 464 465 466 467 468 469 470 471 472 473 474
        mdate() - p_sys->i_late_frames_start > I64C(5000000) )
    {
        if( p_sys->i_pts )
        {
            msg_Err( p_dec, "more than 5 seconds of late video -> "
                     "dropping frame (computer too slow ?)" );
            p_sys->i_pts = 0; /* To make sure we recover properly */
        }
        block_Release( p_block );
        p_sys->i_late_frames--;
        return NULL;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
475
    if( p_block->i_pts > 0 || p_block->i_dts > 0 )
Gildas Bazin's avatar
 
Gildas Bazin committed
476 477
    {
        p_sys->input_pts = p_block->i_pts;
Gildas Bazin's avatar
 
Gildas Bazin committed
478 479 480 481
        p_sys->input_dts = p_block->i_dts;

        /* Make sure we don't reuse the same timestamps twice */
        p_block->i_pts = p_block->i_dts = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
482
    }
483

484 485
    /* TODO implement it in a better way */
    /* A good idea could be to decode all I pictures and see for the other */
486 487
    if( !p_dec->b_pace_control &&
        p_sys->b_hurry_up && p_sys->i_late_frames > 4 )
488 489
    {
        b_drawpicture = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
490
        if( p_sys->i_late_frames < 8 )
491
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
492
            p_sys->p_context->hurry_up = 2;
493 494 495
        }
        else
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
496 497 498 499 500
            /* picture too late, won't decode
             * but break picture until a new I, and for mpeg4 ...*/

            p_sys->i_late_frames--; /* needed else it will never be decrease */
            block_Release( p_block );
Gildas Bazin's avatar
 
Gildas Bazin committed
501 502
            p_sys->i_buffer = 0;
            return NULL;
503 504 505 506 507
        }
    }
    else
    {
        b_drawpicture = 1;
Gildas Bazin's avatar
 
Gildas Bazin committed
508
        p_sys->p_context->hurry_up = 0;
509 510
    }

511

512
    if( p_sys->p_context->width <= 0 || p_sys->p_context->height <= 0 )
Gildas Bazin's avatar
 
Gildas Bazin committed
513 514
    {
        p_sys->p_context->hurry_up = 5;
515
        b_null_size = VLC_TRUE;
516 517
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
518 519 520 521
    /*
     * Do the actual decoding now
     */

Gildas Bazin's avatar
 
Gildas Bazin committed
522 523 524
    /* Check if post-processing was enabled */
    p_sys->b_pp = p_sys->b_pp_async;

Gildas Bazin's avatar
 
Gildas Bazin committed
525 526
    /* Don't forget that ffmpeg requires a little more bytes
     * that the real frame size */
527
    if( p_block->i_buffer > 0 )
528
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
        p_sys->i_buffer = p_block->i_buffer;
        if( p_sys->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE >
            p_sys->i_buffer_orig )
        {
            free( p_sys->p_buffer_orig );
            p_sys->i_buffer_orig =
                p_block->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE;
            p_sys->p_buffer_orig = malloc( p_sys->i_buffer_orig );
        }
        p_sys->p_buffer = p_sys->p_buffer_orig;
        p_sys->i_buffer = p_block->i_buffer;
        p_dec->p_vlc->pf_memcpy( p_sys->p_buffer, p_block->p_buffer,
                                 p_block->i_buffer );
        memset( p_sys->p_buffer + p_block->i_buffer, 0,
                FF_INPUT_BUFFER_PADDING_SIZE );

        p_block->i_buffer = 0;
546 547
    }

548
    while( p_sys->i_buffer > 0 )
549
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
550 551 552 553 554
        int i_used, b_gotpicture;
        picture_t *p_pic;

        i_used = avcodec_decode_video( p_sys->p_context, p_sys->p_ff_pic,
                                       &b_gotpicture,
Gildas Bazin's avatar
 
Gildas Bazin committed
555
                                       p_sys->p_buffer, p_sys->i_buffer );
556 557
        if( b_null_size && p_sys->p_context->width > 0 &&
            p_sys->p_context->height > 0 )
558 559 560 561 562 563 564 565 566
        {
            /* Reparse it to not drop the I frame */
            b_null_size = VLC_FALSE;
            p_sys->p_context->hurry_up = 0;
            i_used = avcodec_decode_video( p_sys->p_context, p_sys->p_ff_pic,
                                           &b_gotpicture,
                                           p_sys->p_buffer, p_sys->i_buffer );
        }

Gildas Bazin's avatar
 
Gildas Bazin committed
567
        if( i_used < 0 )
568
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
569 570
            msg_Warn( p_dec, "cannot decode one frame (%d bytes)",
                      p_sys->i_buffer );
Gildas Bazin's avatar
 
Gildas Bazin committed
571
            block_Release( p_block );
Gildas Bazin's avatar
 
Gildas Bazin committed
572
            return NULL;
573
        }
574 575 576 577
        else if( i_used > p_sys->i_buffer )
        {
            i_used = p_sys->i_buffer;
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
578

Gildas Bazin's avatar
 
Gildas Bazin committed
579
        /* Consumed bytes */
Gildas Bazin's avatar
 
Gildas Bazin committed
580 581
        p_sys->i_buffer -= i_used;
        p_sys->p_buffer += i_used;
Gildas Bazin's avatar
 
Gildas Bazin committed
582 583

        /* Nothing to display */
584 585
        if( !b_gotpicture )
        {
Gildas Bazin's avatar
Gildas Bazin committed
586
            if( i_used == 0 ) break;
587 588
            continue;
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
589

Laurent Aimar's avatar
Laurent Aimar committed
590 591 592
        /* Update frame late count (except when doing preroll) */
        if( p_sys->i_pts && p_sys->i_pts <= mdate() &&
            !(p_block->i_flags & BLOCK_FLAG_PREROLL) )
Gildas Bazin's avatar
 
Gildas Bazin committed
593 594 595 596 597 598
        {
            p_sys->i_late_frames++;
            if( p_sys->i_late_frames == 1 )
                p_sys->i_late_frames_start = mdate();
        }
        else
599
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
600
            p_sys->i_late_frames = 0;
601 602
        }

Gildas Bazin's avatar
Gildas Bazin committed
603
        if( !b_drawpicture || !p_sys->p_ff_pic->linesize[0] )
Gildas Bazin's avatar
 
Gildas Bazin committed
604 605 606 607
        {
            /* Do not display the picture */
            continue;
        }
608

Gildas Bazin's avatar
 
Gildas Bazin committed
609
        if( !p_sys->p_ff_pic->opaque )
610
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
611
            /* Get a new picture */
Gildas Bazin's avatar
 
Gildas Bazin committed
612 613
            p_pic = ffmpeg_NewPictBuf( p_dec, p_sys->p_context );
            if( !p_pic )
614
            {
Gildas Bazin's avatar
 
Gildas Bazin committed
615 616
                block_Release( p_block );
                return NULL;
617
            }
618

Gildas Bazin's avatar
 
Gildas Bazin committed
619 620 621 622 623
            /* Fill p_picture_t from AVVideoFrame and do chroma conversion
             * if needed */
            ffmpeg_CopyPicture( p_dec, p_pic, p_sys->p_ff_pic );
        }
        else
624
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
625
            p_pic = (picture_t *)p_sys->p_ff_pic->opaque;
626
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
627

Gildas Bazin's avatar
 
Gildas Bazin committed
628 629 630 631
        /* Set the PTS */
        if( p_sys->p_ff_pic->pts ) p_sys->i_pts = p_sys->p_ff_pic->pts;

        /* Sanity check (seems to be needed for some streams ) */
Gildas Bazin's avatar
 
Gildas Bazin committed
632
        if( p_sys->p_ff_pic->pict_type == FF_B_TYPE )
633
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
634
            p_sys->b_has_b_frames = VLC_TRUE;
635 636
        }

Gildas Bazin's avatar
 
Gildas Bazin committed
637 638
        /* Send decoded frame to vout */
        if( p_sys->i_pts )
639
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
640
            p_pic->date = p_sys->i_pts;
Gildas Bazin's avatar
 
Gildas Bazin committed
641

Laurent Aimar's avatar
Laurent Aimar committed
642 643 644 645
            static int64_t i_old = 0;
            msg_Dbg( p_dec, "pts=%lld diff=%lld", p_pic->date, p_pic->date - i_old );
            i_old = p_pic->date;

Gildas Bazin's avatar
 
Gildas Bazin committed
646 647
            /* interpolate the next PTS */
            if( p_sys->p_context->frame_rate > 0 )
Gildas Bazin's avatar
 
Gildas Bazin committed
648
            {
Gildas Bazin's avatar
 
Gildas Bazin committed
649 650 651 652
                p_sys->i_pts += I64C(1000000) *
                    (2 + p_sys->p_ff_pic->repeat_pict) *
                    p_sys->p_context->frame_rate_base /
                    (2 * p_sys->p_context->frame_rate);
Gildas Bazin's avatar
 
Gildas Bazin committed
653
            }
654 655 656 657 658 659 660

            if( p_sys->b_first_frame )
            {
                /* Hack to force display of still pictures */
                p_sys->b_first_frame = VLC_FALSE;
                p_pic->b_force = VLC_TRUE;
            }
661

662
            p_pic->i_nb_fields = 2 + p_sys->p_ff_pic->repeat_pict;
663 664 665 666 667
#if LIBAVCODEC_BUILD >= 4685
            p_pic->b_progressive = !p_sys->p_ff_pic->interlaced_frame;
            p_pic->b_top_field_first = p_sys->p_ff_pic->top_field_first;
#endif

Gildas Bazin's avatar
 
Gildas Bazin committed
668 669 670 671 672
            return p_pic;
        }
        else
        {
            p_dec->pf_vout_buffer_del( p_dec, p_pic );
Laurent Aimar's avatar
Laurent Aimar committed
673
            msg_Dbg( p_dec, "pts=0" );
674
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
675 676
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
677
    block_Release( p_block );
Gildas Bazin's avatar
 
Gildas Bazin committed
678
    return NULL;
679 680 681
}

/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
682
 * EndVideo: decoder destruction
683 684 685 686
 *****************************************************************************
 * This function is called when the thread ends after a sucessful
 * initialization.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
687
void E_(EndVideoDec)( decoder_t *p_dec )
688
{
Gildas Bazin's avatar
 
Gildas Bazin committed
689 690
    decoder_sys_t *p_sys = p_dec->p_sys;

691
    if( p_sys->p_ff_pic ) av_free( p_sys->p_ff_pic );
Gildas Bazin's avatar
 
Gildas Bazin committed
692

693
#ifdef LIBAVCODEC_PP
Gildas Bazin's avatar
 
Gildas Bazin committed
694
    E_(ClosePostproc)( p_dec, p_sys->p_pp );
695
#endif
696

Gildas Bazin's avatar
 
Gildas Bazin committed
697
    free( p_sys->p_buffer_orig );
Gildas Bazin's avatar
 
Gildas Bazin committed
698 699 700 701 702 703
}

/*****************************************************************************
 * ffmpeg_CopyPicture: copy a picture from ffmpeg internal buffers to a
 *                     picture_t structure (when not in direct rendering mode).
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
704 705
static void ffmpeg_CopyPicture( decoder_t *p_dec,
                                picture_t *p_pic, AVFrame *p_ff_pic )
Gildas Bazin's avatar
 
Gildas Bazin committed
706
{
Gildas Bazin's avatar
 
Gildas Bazin committed
707
    decoder_sys_t *p_sys = p_dec->p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
708

Gildas Bazin's avatar
 
Gildas Bazin committed
709
    if( ffmpeg_PixFmtToChroma( p_sys->p_context->pix_fmt ) )
Gildas Bazin's avatar
 
Gildas Bazin committed
710
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
711 712 713
        int i_plane, i_size, i_line;
        uint8_t *p_dst, *p_src;
        int i_src_stride, i_dst_stride;
714

715
#ifdef LIBAVCODEC_PP
Gildas Bazin's avatar
 
Gildas Bazin committed
716
        if( p_sys->p_pp && p_sys->b_pp )
717 718 719
            E_(PostprocPict)( p_dec, p_sys->p_pp, p_pic, p_ff_pic );
        else
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
720
        for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
721
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
722 723 724 725
            p_src  = p_ff_pic->data[i_plane];
            p_dst = p_pic->p[i_plane].p_pixels;
            i_src_stride = p_ff_pic->linesize[i_plane];
            i_dst_stride = p_pic->p[i_plane].i_pitch;
726

Gildas Bazin's avatar
 
Gildas Bazin committed
727
            i_size = __MIN( i_src_stride, i_dst_stride );
728 729
            for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines;
                 i_line++ )
Gildas Bazin's avatar
 
Gildas Bazin committed
730 731 732 733
            {
                p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_size );
                p_src += i_src_stride;
                p_dst += i_dst_stride;
734 735
            }
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
736 737 738
    }
    else
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
739 740 741
        AVPicture dest_pic;
        int i;

Gildas Bazin's avatar
 
Gildas Bazin committed
742
        /* we need to convert to I420 */
Gildas Bazin's avatar
 
Gildas Bazin committed
743
        switch( p_sys->p_context->pix_fmt )
Gildas Bazin's avatar
 
Gildas Bazin committed
744
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
745 746 747
        case PIX_FMT_YUV410P:
        case PIX_FMT_YUV411P:
        case PIX_FMT_PAL8:
Gildas Bazin's avatar
 
Gildas Bazin committed
748 749 750 751 752 753 754 755 756 757 758 759 760 761
            for( i = 0; i < p_pic->i_planes; i++ )
            {
                dest_pic.data[i] = p_pic->p[i].p_pixels;
                dest_pic.linesize[i] = p_pic->p[i].i_pitch;
            }
            img_convert( &dest_pic, PIX_FMT_YUV420P,
                         (AVPicture *)p_ff_pic,
                         p_sys->p_context->pix_fmt,
                         p_sys->p_context->width,
                         p_sys->p_context->height );
            break;
        default:
            msg_Err( p_dec, "don't know how to convert chroma %i",
                     p_sys->p_context->pix_fmt );
Laurent Aimar's avatar
Laurent Aimar committed
762
            p_dec->b_error = 1;
Gildas Bazin's avatar
 
Gildas Bazin committed
763
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
764 765 766
        }
    }
}
767

Gildas Bazin's avatar
 
Gildas Bazin committed
768 769
/*****************************************************************************
 * ffmpeg_GetFrameBuf: callback used by ffmpeg to get a frame buffer.
Gildas Bazin's avatar
 
Gildas Bazin committed
770 771 772
 *****************************************************************************
 * It is used for direct rendering as well as to get the right PTS for each
 * decoded picture (even in indirect rendering mode).
Gildas Bazin's avatar
 
Gildas Bazin committed
773
 *****************************************************************************/
774
static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
775
                               AVFrame *p_ff_pic )
Gildas Bazin's avatar
 
Gildas Bazin committed
776
{
Gildas Bazin's avatar
 
Gildas Bazin committed
777 778
    decoder_t *p_dec = (decoder_t *)p_context->opaque;
    decoder_sys_t *p_sys = p_dec->p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
779 780
    picture_t *p_pic;

Gildas Bazin's avatar
 
Gildas Bazin committed
781
    /* Set picture PTS */
Gildas Bazin's avatar
 
Gildas Bazin committed
782 783 784 785 786 787 788 789 790
    if( p_sys->input_pts )
    {
        p_ff_pic->pts = p_sys->input_pts;
    }
    else if( p_sys->input_dts )
    {
        /* Some demuxers only set the dts so let's try to find a useful
         * timestamp from this */
        if( !p_context->has_b_frames || !p_sys->b_has_b_frames ||
791
            !p_ff_pic->reference || !p_sys->i_pts )
Gildas Bazin's avatar
 
Gildas Bazin committed
792 793 794 795 796 797 798
        {
            p_ff_pic->pts = p_sys->input_dts;
        }
        else p_ff_pic->pts = 0;
    }
    else p_ff_pic->pts = 0;

799 800 801 802 803
    if( p_sys->i_pts ) /* make sure 1st frame has a pts > 0 */
    {
        p_sys->input_pts = p_sys->input_dts = 0;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
804
    p_ff_pic->opaque = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
805 806

    /* Not much to do in indirect rendering mode */
Gildas Bazin's avatar
 
Gildas Bazin committed
807
    if( !p_sys->b_direct_rendering || p_sys->b_pp )
Gildas Bazin's avatar
 
Gildas Bazin committed
808 809 810 811
    {
        return avcodec_default_get_buffer( p_context, p_ff_pic );
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
812 813
    /* Some codecs set pix_fmt only after the 1st frame has been decoded,
     * so this check is necessary. */
814
    if( !ffmpeg_PixFmtToChroma( p_context->pix_fmt ) ||
Gildas Bazin's avatar
 
Gildas Bazin committed
815
        p_sys->p_context->width % 16 || p_sys->p_context->height % 16 )
Gildas Bazin's avatar
 
Gildas Bazin committed
816
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
817 818
        msg_Dbg( p_dec, "disabling direct rendering" );
        p_sys->b_direct_rendering = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
819
        return avcodec_default_get_buffer( p_context, p_ff_pic );
Gildas Bazin's avatar
 
Gildas Bazin committed
820 821
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
822 823 824 825
    /* Get a new picture */
    //p_sys->p_vout->render.b_allow_modify_pics = 0;
    p_pic = ffmpeg_NewPictBuf( p_dec, p_sys->p_context );
    if( !p_pic )
Gildas Bazin's avatar
 
Gildas Bazin committed
826
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
827
        p_sys->b_direct_rendering = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
828
        return avcodec_default_get_buffer( p_context, p_ff_pic );
Gildas Bazin's avatar
 
Gildas Bazin committed
829
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
830
    p_sys->p_context->draw_horiz_band = NULL;
831 832

    p_ff_pic->opaque = (void*)p_pic;
833
    p_ff_pic->type = FF_BUFFER_TYPE_USER;
834 835 836 837
    p_ff_pic->data[0] = p_pic->p[0].p_pixels;
    p_ff_pic->data[1] = p_pic->p[1].p_pixels;
    p_ff_pic->data[2] = p_pic->p[2].p_pixels;
    p_ff_pic->data[3] = NULL; /* alpha channel but I'm not sure */
838

839 840 841 842 843 844 845
    p_ff_pic->linesize[0] = p_pic->p[0].i_pitch;
    p_ff_pic->linesize[1] = p_pic->p[1].i_pitch;
    p_ff_pic->linesize[2] = p_pic->p[2].i_pitch;
    p_ff_pic->linesize[3] = 0;

    if( p_ff_pic->reference != 0 )
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
846
        p_dec->pf_picture_link( p_dec, p_pic );
847
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
848

849 850
    /* FIXME what is that, should give good value */
    p_ff_pic->age = 256*256*256*64; // FIXME FIXME from ffmpeg
Gildas Bazin's avatar
 
Gildas Bazin committed
851

Gildas Bazin's avatar
 
Gildas Bazin committed
852
    return 0;
853 854
}

Gildas Bazin's avatar
 
Gildas Bazin committed
855 856
static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
                                    AVFrame *p_ff_pic )
857
{
Gildas Bazin's avatar
 
Gildas Bazin committed
858
    decoder_t *p_dec = (decoder_t *)p_context->opaque;
859
    picture_t *p_pic;
Gildas Bazin's avatar
 
Gildas Bazin committed
860

Gildas Bazin's avatar
 
Gildas Bazin committed
861
    if( !p_ff_pic->opaque )
Gildas Bazin's avatar
 
Gildas Bazin committed
862 863 864 865 866
    {
        avcodec_default_release_buffer( p_context, p_ff_pic );
        return;
    }

867
    p_pic = (picture_t*)p_ff_pic->opaque;
Gildas Bazin's avatar
 
Gildas Bazin committed
868

869 870 871 872
    p_ff_pic->data[0] = NULL;
    p_ff_pic->data[1] = NULL;
    p_ff_pic->data[2] = NULL;
    p_ff_pic->data[3] = NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
873

Gildas Bazin's avatar
 
Gildas Bazin committed
874 875
    if( p_ff_pic->reference != 0 )
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
876
        p_dec->pf_picture_unlink( p_dec, p_pic );
Gildas Bazin's avatar
 
Gildas Bazin committed
877
    }
878
}