1 /*****************************************************************************
2 * video.c: video decoder using the ffmpeg library
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Gildas Bazin <gbazin@netcourrier.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #include <vlc/decoder.h>
32 #ifdef HAVE_FFMPEG_AVCODEC_H
33 # include <ffmpeg/avcodec.h>
40 /*****************************************************************************
41 * decoder_sys_t : decoder descriptor
42 *****************************************************************************/
45 /* Common part between video and audio decoder */
50 AVCodecContext *p_context;
53 /* Video decoder specific part */
59 BITMAPINFOHEADER *p_format;
61 /* for frame skipping algo */
65 /* how many decoded frames are late */
67 mtime_t i_late_frames_start;
69 /* for direct rendering */
70 int b_direct_rendering;
72 vlc_bool_t b_has_b_frames;
74 int i_buffer_orig, i_buffer;
75 char *p_buffer_orig, *p_buffer;
77 /* Postprocessing handle */
80 vlc_bool_t b_pp_async;
84 /* FIXME (dummy palette for now) */
85 static AVPaletteControl palette_control;
87 /*****************************************************************************
89 *****************************************************************************/
90 static void ffmpeg_CopyPicture ( decoder_t *, picture_t *, AVFrame * );
91 static int ffmpeg_GetFrameBuf ( struct AVCodecContext *, AVFrame * );
92 static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *, AVFrame * );
94 /*****************************************************************************
96 *****************************************************************************/
97 static uint32_t ffmpeg_PixFmtToChroma( int i_ff_chroma )
101 case PIX_FMT_YUV420P:
102 return VLC_FOURCC('I','4','2','0');
103 case PIX_FMT_YUV422P:
104 return VLC_FOURCC('I','4','2','2');
105 case PIX_FMT_YUV444P:
106 return VLC_FOURCC('I','4','4','4');
109 return VLC_FOURCC('Y','U','Y','2');
112 return VLC_FOURCC('R','V','1','5');
114 return VLC_FOURCC('R','V','1','6');
116 return VLC_FOURCC('R','V','2','4');
118 return VLC_FOURCC('R','V','3','2');
120 return VLC_FOURCC('G','R','E','Y');
122 case PIX_FMT_YUV410P:
123 case PIX_FMT_YUV411P:
130 /* Returns a new picture buffer */
131 static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
132 AVCodecContext *p_context )
134 decoder_sys_t *p_sys = p_dec->p_sys;
137 p_dec->fmt_out.video.i_width = p_context->width;
138 p_dec->fmt_out.video.i_height = p_context->height;
139 p_dec->fmt_out.i_codec = ffmpeg_PixFmtToChroma( p_context->pix_fmt );
141 if( !p_context->width || !p_context->height )
143 return NULL; /* invalid display size */
146 if( !p_dec->fmt_out.i_codec )
148 /* we make conversion if possible*/
149 p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
152 /* If an aspect-ratio was specified in the input format then force it */
153 if( p_dec->fmt_in.video.i_aspect )
155 p_dec->fmt_out.video.i_aspect = p_dec->fmt_in.video.i_aspect;
159 #if LIBAVCODEC_BUILD >= 4687
160 p_dec->fmt_out.video.i_aspect =
161 VOUT_ASPECT_FACTOR * ( av_q2d(p_context->sample_aspect_ratio) *
162 p_context->width / p_context->height );
164 p_dec->fmt_out.video.i_aspect =
165 VOUT_ASPECT_FACTOR * p_context->aspect_ratio;
167 if( p_dec->fmt_out.video.i_aspect == 0 )
169 p_dec->fmt_out.video.i_aspect =
170 VOUT_ASPECT_FACTOR * p_context->width / p_context->height;
174 p_pic = p_dec->pf_vout_buffer_new( p_dec );
177 if( p_sys->p_pp && p_sys->b_pp && !p_sys->b_pp_init )
179 E_(InitPostproc)( p_dec, p_sys->p_pp, p_context->width,
180 p_context->height, p_context->pix_fmt );
181 p_sys->b_pp_init = VLC_TRUE;
188 /*****************************************************************************
189 * InitVideo: initialize the video decoder
190 *****************************************************************************
191 * the ffmpeg codec will be opened, some memory allocated. The vout is not yet
192 * opened (done after the first decoded frame).
193 *****************************************************************************/
194 int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
195 AVCodec *p_codec, int i_codec_id, char *psz_namecodec )
197 decoder_sys_t *p_sys;
203 var_Get( p_dec->p_libvlc, "avcodec", &lockval );
205 /* Allocate the memory needed to store the decoder's structure */
206 if( ( p_dec->p_sys = p_sys =
207 (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
209 msg_Err( p_dec, "out of memory" );
213 p_dec->p_sys->p_context = p_context;
214 p_dec->p_sys->p_codec = p_codec;
215 p_dec->p_sys->i_codec_id = i_codec_id;
216 p_dec->p_sys->psz_namecodec = psz_namecodec;
217 p_sys->p_ff_pic = avcodec_alloc_frame();
219 /* ***** Fill p_context with init values ***** */
220 p_sys->p_context->width = p_dec->fmt_in.video.i_width;
221 p_sys->p_context->height = p_dec->fmt_in.video.i_height;
222 p_sys->p_context->bits_per_sample = p_dec->fmt_in.video.i_bits_per_pixel;
224 /* ***** Get configuration of ffmpeg plugin ***** */
225 i_tmp = config_GetInt( p_dec, "ffmpeg-workaround-bugs" );
226 p_sys->p_context->workaround_bugs = __MAX( __MIN( i_tmp, 99 ), 0 );
228 i_tmp = config_GetInt( p_dec, "ffmpeg-error-resilience" );
229 p_sys->p_context->error_resilience = __MAX( __MIN( i_tmp, 99 ), -1 );
231 var_Create( p_dec, "grayscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
232 var_Get( p_dec, "grayscale", &val );
233 if( val.b_bool ) p_sys->p_context->flags |= CODEC_FLAG_GRAY;
235 /* ***** ffmpeg frame skipping ***** */
236 var_Create( p_dec, "ffmpeg-hurry-up", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
237 var_Get( p_dec, "ffmpeg-hurry-up", &val );
238 p_sys->b_hurry_up = val.b_bool;
240 /* ***** ffmpeg direct rendering ***** */
241 p_sys->b_direct_rendering = 0;
242 var_Create( p_dec, "ffmpeg-dr", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
243 var_Get( p_dec, "ffmpeg-dr", &val );
244 if( val.b_bool && (p_sys->p_codec->capabilities & CODEC_CAP_DR1) &&
245 ffmpeg_PixFmtToChroma( p_sys->p_context->pix_fmt ) &&
246 /* Apparently direct rendering doesn't work with YUV422P */
247 p_sys->p_context->pix_fmt != PIX_FMT_YUV422P &&
248 p_sys->i_codec_id != CODEC_ID_H264 && /* H264 use too many reference frames */
249 !(p_sys->p_context->width % 16) && !(p_sys->p_context->height % 16) )
251 /* Some codecs set pix_fmt only after the 1st frame has been decoded,
252 * so we need to do another check in ffmpeg_GetFrameBuf() */
253 p_sys->b_direct_rendering = 1;
258 p_sys->b_pp = p_sys->b_pp_async = p_sys->b_pp_init = VLC_FALSE;
259 p_sys->p_pp = E_(OpenPostproc)( p_dec, &p_sys->b_pp_async );
262 /* ffmpeg doesn't properly release old pictures when frames are skipped */
263 //if( p_sys->b_hurry_up ) p_sys->b_direct_rendering = 0;
264 if( p_sys->b_direct_rendering )
266 msg_Dbg( p_dec, "using direct rendering" );
267 p_sys->p_context->flags |= CODEC_FLAG_EMU_EDGE;
270 /* Always use our get_buffer wrapper so we can calculate the
272 p_sys->p_context->get_buffer = ffmpeg_GetFrameBuf;
273 p_sys->p_context->release_buffer = ffmpeg_ReleaseFrameBuf;
274 p_sys->p_context->opaque = p_dec;
276 /* ***** init this codec with special data ***** */
277 if( p_dec->fmt_in.i_extra )
279 int i_size = p_dec->fmt_in.i_extra;
281 if( p_sys->i_codec_id == CODEC_ID_SVQ3 )
285 p_sys->p_context->extradata_size = i_size + 12;
286 p = p_sys->p_context->extradata =
287 malloc( p_sys->p_context->extradata_size );
289 memcpy( &p[0], "SVQ3", 4 );
290 memset( &p[4], 0, 8 );
291 memcpy( &p[12], p_dec->fmt_in.p_extra, i_size );
293 /* Now remove all atoms before the SMI one */
294 if( p_sys->p_context->extradata_size > 0x5a &&
295 strncmp( &p[0x56], "SMI ", 4 ) )
297 uint8_t *psz = &p[0x52];
299 while( psz < &p[p_sys->p_context->extradata_size - 8] )
301 int i_size = GetDWBE( psz );
304 /* FIXME handle 1 as long size */
307 if( !strncmp( &psz[4], "SMI ", 4 ) )
309 memmove( &p[0x52], psz,
310 &p[p_sys->p_context->extradata_size] - psz );
318 else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'R', 'V', '1', '0' ) ||
319 p_dec->fmt_in.i_codec == VLC_FOURCC( 'R', 'V', '1', '3' ) ||
320 p_dec->fmt_in.i_codec == VLC_FOURCC( 'R', 'V', '2', '0' ) )
322 if( p_dec->fmt_in.i_extra == 8 )
324 p_sys->p_context->extradata_size = 8;
325 p_sys->p_context->extradata = malloc( 8 );
327 memcpy( p_sys->p_context->extradata,
328 p_dec->fmt_in.p_extra,
329 p_dec->fmt_in.i_extra );
330 p_sys->p_context->sub_id= ((uint32_t*)p_dec->fmt_in.p_extra)[1];
332 msg_Warn( p_dec, "using extra data for RV codec sub_id=%08x",
333 p_sys->p_context->sub_id );
338 p_sys->p_context->extradata_size = i_size;
339 p_sys->p_context->extradata =
340 malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE );
341 memcpy( p_sys->p_context->extradata,
342 p_dec->fmt_in.p_extra, i_size );
343 memset( &((uint8_t*)p_sys->p_context->extradata)[i_size],
344 0, FF_INPUT_BUFFER_PADDING_SIZE );
348 /* ***** misc init ***** */
349 p_sys->input_pts = p_sys->input_dts = 0;
351 p_sys->b_has_b_frames = VLC_FALSE;
352 p_sys->i_late_frames = 0;
354 p_sys->i_buffer_orig = 1;
355 p_sys->p_buffer_orig = p_sys->p_buffer = malloc( p_sys->i_buffer );
357 /* Set output properties */
358 p_dec->fmt_out.i_cat = VIDEO_ES;
359 p_dec->fmt_out.i_codec = ffmpeg_PixFmtToChroma( p_context->pix_fmt );
362 #if LIBAVCODEC_BUILD >= 4688
363 if( p_dec->fmt_in.video.p_palette )
364 p_sys->p_context->palctrl =
365 (AVPaletteControl *)p_dec->fmt_in.video.p_palette;
367 p_sys->p_context->palctrl = &palette_control;
370 /* ***** Open the codec ***** */
371 vlc_mutex_lock( lockval.p_address );
372 if( avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0 )
374 vlc_mutex_unlock( lockval.p_address );
375 msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
378 vlc_mutex_unlock( lockval.p_address );
379 msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
385 /*****************************************************************************
386 * DecodeVideo: Called to decode one or more frames
387 *****************************************************************************/
388 picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
390 decoder_sys_t *p_sys = p_dec->p_sys;
394 if( !pp_block || !*pp_block ) return NULL;
398 if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
401 p_sys->i_pts = 0; /* To make sure we recover properly */
403 p_sys->input_pts = p_sys->input_dts = 0;
404 p_sys->i_late_frames = 0;
406 block_Release( p_block );
410 if( p_sys->i_late_frames > 0 &&
411 mdate() - p_sys->i_late_frames_start > I64C(5000000) )
415 msg_Err( p_dec, "more than 5 seconds of late video -> "
416 "dropping frame (computer too slow ?)" );
417 p_sys->i_pts = 0; /* To make sure we recover properly */
419 block_Release( p_block );
420 p_sys->i_late_frames--;
424 if( p_block->i_pts > 0 || p_block->i_dts > 0 )
426 p_sys->input_pts = p_block->i_pts;
427 p_sys->input_dts = p_block->i_dts;
429 /* Make sure we don't reuse the same timestamps twice */
430 p_block->i_pts = p_block->i_dts = 0;
433 /* TODO implement it in a better way */
434 /* A good idea could be to decode all I pictures and see for the other */
435 if( p_sys->b_hurry_up && p_sys->i_late_frames > 4 )
438 if( p_sys->i_late_frames < 8 )
440 p_sys->p_context->hurry_up = 2;
444 /* picture too late, won't decode
445 * but break picture until a new I, and for mpeg4 ...*/
447 p_sys->i_late_frames--; /* needed else it will never be decrease */
448 block_Release( p_block );
456 p_sys->p_context->hurry_up = 0;
460 if( p_sys->p_context->width <= 0 || p_sys->p_context->height <= 0 )
462 p_sys->p_context->hurry_up = 5;
466 * Do the actual decoding now
469 /* Check if post-processing was enabled */
470 p_sys->b_pp = p_sys->b_pp_async;
472 /* Don't forget that ffmpeg requires a little more bytes
473 * that the real frame size */
474 if( p_block->i_buffer > 0 )
476 p_sys->i_buffer = p_block->i_buffer;
477 if( p_sys->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE >
478 p_sys->i_buffer_orig )
480 free( p_sys->p_buffer_orig );
481 p_sys->i_buffer_orig =
482 p_block->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE;
483 p_sys->p_buffer_orig = malloc( p_sys->i_buffer_orig );
485 p_sys->p_buffer = p_sys->p_buffer_orig;
486 p_sys->i_buffer = p_block->i_buffer;
487 p_dec->p_vlc->pf_memcpy( p_sys->p_buffer, p_block->p_buffer,
489 memset( p_sys->p_buffer + p_block->i_buffer, 0,
490 FF_INPUT_BUFFER_PADDING_SIZE );
492 p_block->i_buffer = 0;
495 while( p_sys->i_buffer > 0 )
497 int i_used, b_gotpicture;
500 i_used = avcodec_decode_video( p_sys->p_context, p_sys->p_ff_pic,
502 p_sys->p_buffer, p_sys->i_buffer );
505 msg_Warn( p_dec, "cannot decode one frame (%d bytes)",
507 block_Release( p_block );
510 else if( i_used > p_sys->i_buffer )
512 i_used = p_sys->i_buffer;
516 p_sys->i_buffer -= i_used;
517 p_sys->p_buffer += i_used;
519 /* Nothing to display */
529 /* Update frame late count*/
530 if( p_sys->i_pts && p_sys->i_pts <= mdate() )
532 p_sys->i_late_frames++;
533 if( p_sys->i_late_frames == 1 )
534 p_sys->i_late_frames_start = mdate();
538 p_sys->i_late_frames = 0;
541 if( !b_drawpicture || p_sys->p_ff_pic->linesize[0] == 0 )
543 /* Do not display the picture */
547 if( !p_sys->p_ff_pic->opaque )
549 /* Get a new picture */
550 p_pic = ffmpeg_NewPictBuf( p_dec, p_sys->p_context );
553 block_Release( p_block );
557 /* Fill p_picture_t from AVVideoFrame and do chroma conversion
559 ffmpeg_CopyPicture( p_dec, p_pic, p_sys->p_ff_pic );
563 p_pic = (picture_t *)p_sys->p_ff_pic->opaque;
567 if( p_sys->p_ff_pic->pts ) p_sys->i_pts = p_sys->p_ff_pic->pts;
569 /* Sanity check (seems to be needed for some streams ) */
570 if( p_sys->p_ff_pic->pict_type == FF_B_TYPE )
572 p_sys->b_has_b_frames = VLC_TRUE;
575 /* Send decoded frame to vout */
578 p_pic->date = p_sys->i_pts;
580 /* interpolate the next PTS */
581 if( p_sys->p_context->frame_rate > 0 )
583 p_sys->i_pts += I64C(1000000) *
584 (2 + p_sys->p_ff_pic->repeat_pict) *
585 p_sys->p_context->frame_rate_base /
586 (2 * p_sys->p_context->frame_rate);
592 p_dec->pf_vout_buffer_del( p_dec, p_pic );
596 block_Release( p_block );
600 /*****************************************************************************
601 * EndVideo: decoder destruction
602 *****************************************************************************
603 * This function is called when the thread ends after a sucessful
605 *****************************************************************************/
606 void E_(EndVideoDec)( decoder_t *p_dec )
608 decoder_sys_t *p_sys = p_dec->p_sys;
610 if( p_sys->p_ff_pic ) free( p_sys->p_ff_pic );
613 E_(ClosePostproc)( p_dec, p_sys->p_pp );
616 free( p_sys->p_buffer_orig );
619 /*****************************************************************************
620 * ffmpeg_CopyPicture: copy a picture from ffmpeg internal buffers to a
621 * picture_t structure (when not in direct rendering mode).
622 *****************************************************************************/
623 static void ffmpeg_CopyPicture( decoder_t *p_dec,
624 picture_t *p_pic, AVFrame *p_ff_pic )
626 decoder_sys_t *p_sys = p_dec->p_sys;
628 if( ffmpeg_PixFmtToChroma( p_sys->p_context->pix_fmt ) )
630 int i_plane, i_size, i_line;
631 uint8_t *p_dst, *p_src;
632 int i_src_stride, i_dst_stride;
635 if( p_sys->p_pp && p_sys->b_pp )
636 E_(PostprocPict)( p_dec, p_sys->p_pp, p_pic, p_ff_pic );
639 for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
641 p_src = p_ff_pic->data[i_plane];
642 p_dst = p_pic->p[i_plane].p_pixels;
643 i_src_stride = p_ff_pic->linesize[i_plane];
644 i_dst_stride = p_pic->p[i_plane].i_pitch;
646 i_size = __MIN( i_src_stride, i_dst_stride );
647 for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
649 p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_size );
650 p_src += i_src_stride;
651 p_dst += i_dst_stride;
660 /* we need to convert to I420 */
661 switch( p_sys->p_context->pix_fmt )
663 case PIX_FMT_YUV410P:
664 case PIX_FMT_YUV411P:
666 for( i = 0; i < p_pic->i_planes; i++ )
668 dest_pic.data[i] = p_pic->p[i].p_pixels;
669 dest_pic.linesize[i] = p_pic->p[i].i_pitch;
671 img_convert( &dest_pic, PIX_FMT_YUV420P,
672 (AVPicture *)p_ff_pic,
673 p_sys->p_context->pix_fmt,
674 p_sys->p_context->width,
675 p_sys->p_context->height );
678 msg_Err( p_dec, "don't know how to convert chroma %i",
679 p_sys->p_context->pix_fmt );
686 /*****************************************************************************
687 * ffmpeg_GetFrameBuf: callback used by ffmpeg to get a frame buffer.
688 *****************************************************************************
689 * It is used for direct rendering as well as to get the right PTS for each
690 * decoded picture (even in indirect rendering mode).
691 *****************************************************************************/
692 static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
695 decoder_t *p_dec = (decoder_t *)p_context->opaque;
696 decoder_sys_t *p_sys = p_dec->p_sys;
699 /* Set picture PTS */
700 if( p_sys->input_pts )
702 p_ff_pic->pts = p_sys->input_pts;
704 else if( p_sys->input_dts )
706 /* Some demuxers only set the dts so let's try to find a useful
707 * timestamp from this */
708 if( !p_context->has_b_frames || !p_sys->b_has_b_frames ||
709 !p_ff_pic->reference || !p_sys->i_pts )
711 p_ff_pic->pts = p_sys->input_dts;
713 else p_ff_pic->pts = 0;
715 else p_ff_pic->pts = 0;
717 if( p_sys->i_pts ) /* make sure 1st frame has a pts > 0 */
719 p_sys->input_pts = p_sys->input_dts = 0;
722 p_ff_pic->opaque = 0;
724 /* Not much to do in indirect rendering mode */
725 if( !p_sys->b_direct_rendering || p_sys->b_pp )
727 return avcodec_default_get_buffer( p_context, p_ff_pic );
730 /* Some codecs set pix_fmt only after the 1st frame has been decoded,
731 * so this check is necessary. */
732 if( !ffmpeg_PixFmtToChroma( p_context->pix_fmt ) ||
733 p_sys->p_context->width % 16 || p_sys->p_context->height % 16 )
735 msg_Dbg( p_dec, "disabling direct rendering" );
736 p_sys->b_direct_rendering = 0;
737 return avcodec_default_get_buffer( p_context, p_ff_pic );
740 /* Get a new picture */
741 //p_sys->p_vout->render.b_allow_modify_pics = 0;
742 p_pic = ffmpeg_NewPictBuf( p_dec, p_sys->p_context );
745 p_sys->b_direct_rendering = 0;
746 return avcodec_default_get_buffer( p_context, p_ff_pic );
748 p_sys->p_context->draw_horiz_band = NULL;
750 p_ff_pic->opaque = (void*)p_pic;
751 p_ff_pic->type = FF_BUFFER_TYPE_USER;
752 p_ff_pic->data[0] = p_pic->p[0].p_pixels;
753 p_ff_pic->data[1] = p_pic->p[1].p_pixels;
754 p_ff_pic->data[2] = p_pic->p[2].p_pixels;
755 p_ff_pic->data[3] = NULL; /* alpha channel but I'm not sure */
757 p_ff_pic->linesize[0] = p_pic->p[0].i_pitch;
758 p_ff_pic->linesize[1] = p_pic->p[1].i_pitch;
759 p_ff_pic->linesize[2] = p_pic->p[2].i_pitch;
760 p_ff_pic->linesize[3] = 0;
762 if( p_ff_pic->reference != 0 )
764 p_dec->pf_picture_link( p_dec, p_pic );
767 /* FIXME what is that, should give good value */
768 p_ff_pic->age = 256*256*256*64; // FIXME FIXME from ffmpeg
773 static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
776 decoder_t *p_dec = (decoder_t *)p_context->opaque;
779 if( !p_ff_pic->opaque )
781 avcodec_default_release_buffer( p_context, p_ff_pic );
785 p_pic = (picture_t*)p_ff_pic->opaque;
787 p_ff_pic->data[0] = NULL;
788 p_ff_pic->data[1] = NULL;
789 p_ff_pic->data[2] = NULL;
790 p_ff_pic->data[3] = NULL;
792 if( p_ff_pic->reference != 0 )
794 p_dec->pf_picture_unlink( p_dec, p_pic );