1 /*****************************************************************************
2 * video.c: video decoder using ffmpeg library
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: video.c,v 1.29 2003/06/14 15:43:39 gbazin Exp $
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 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
33 #include <vlc/decoder.h>
34 #include <vlc/input.h>
38 #ifdef HAVE_SYS_TIMES_H
39 # include <sys/times.h>
43 #ifdef HAVE_FFMPEG_AVCODEC_H
44 # include <ffmpeg/avcodec.h>
52 # ifdef HAVE_POSTPROC_POSTPROCESS_H
53 # include <postproc/postprocess.h>
55 # include <libpostproc/postprocess.h>
58 # include "postprocessing/postprocessing.h"
64 /*****************************************************************************
66 *****************************************************************************/
67 static void ffmpeg_CopyPicture( picture_t *, AVFrame *, vdec_thread_t * );
70 static void ffmpeg_PostProcPicture( vdec_thread_t *, picture_t * );
73 /* direct rendering */
74 static int ffmpeg_GetFrameBuf ( struct AVCodecContext *, AVFrame *);
75 static void ffmpeg_ReleaseFrameBuf ( struct AVCodecContext *, AVFrame *);
77 /*****************************************************************************
79 *****************************************************************************/
81 static inline uint32_t ffmpeg_PixFmtToChroma( int i_ff_chroma )
83 /* FIXME FIXME some of them are wrong */
88 return( VLC_FOURCC('I','4','2','0') );
90 return( VLC_FOURCC('R','V','2','4') );
93 return( VLC_FOURCC('I','4','2','2') );
95 return( VLC_FOURCC('I','4','4','4') );
105 static vout_thread_t *ffmpeg_CreateVout( vdec_thread_t *p_vdec,
106 AVCodecContext *p_context )
108 vout_thread_t *p_vout;
109 unsigned int i_width = p_context->width;
110 unsigned int i_height = p_context->height;
111 uint32_t i_chroma = ffmpeg_PixFmtToChroma( p_context->pix_fmt );
112 unsigned int i_aspect;
114 if( !i_width || !i_height )
116 return( NULL ); /* Can't create a new vout without display size */
121 /* we make conversion if possible*/
122 i_chroma = VLC_FOURCC('I','4','2','0');
125 i_aspect = VOUT_ASPECT_FACTOR * p_context->aspect_ratio;
128 i_aspect = VOUT_ASPECT_FACTOR * i_width / i_height;
131 /* Spawn a video output if there is none. First we look for our children,
132 * then we look for any other vout that might be available. */
133 p_vout = vout_Request( p_vdec->p_fifo, NULL,
134 i_width, i_height, i_chroma, i_aspect );
136 if( p_vdec->pp_mode && !p_vdec->pp_context )
138 int32_t i_cpu = p_vdec->p_fifo->p_libvlc->i_cpu;
141 if( i_cpu & CPU_CAPABILITY_MMX )
143 i_flags |= PP_CPU_CAPS_MMX;
145 if( i_cpu & CPU_CAPABILITY_MMXEXT )
147 i_flags |= PP_CPU_CAPS_MMX2;
149 if( i_cpu & CPU_CAPABILITY_3DNOW )
151 i_flags |= PP_CPU_CAPS_3DNOW;
154 switch( p_context->pix_fmt )
156 case PIX_FMT_YUV444P:
157 i_flags |= PP_FORMAT_444;
159 case PIX_FMT_YUV422P:
160 i_flags |= PP_FORMAT_422;
162 case PIX_FMT_YUV411P:
163 i_flags |= PP_FORMAT_411;
166 i_flags |= PP_FORMAT_420;
170 p_vdec->pp_context = pp_get_context( i_width, i_height, i_flags );
177 /*****************************************************************************
179 * Functions that initialize, decode and end the decoding process
181 * Functions exported for ffmpeg.c
182 * * E_( InitThread_Video )
183 * * E_( DecodeThread )
184 * * E_( EndThread_Video )
185 *****************************************************************************/
187 /*****************************************************************************
188 * InitThread: initialize vdec output thread
189 *****************************************************************************
190 * This function is called from decoder_Run and performs the second step
191 * of the initialization. It returns 0 on success. Note that the thread's
192 * flag are not modified inside this function.
194 * ffmpeg codec will be open, some memory allocated. But Vout is not yet
195 * open (done after the first decoded frame)
196 *****************************************************************************/
197 static inline void SetDWBE( void *data, uint32_t dw )
201 p[0] = (dw >> 24 )&0xff;
202 p[1] = (dw >> 16 )&0xff;
203 p[2] = (dw >> 8 )&0xff;
207 int E_( InitThread_Video )( vdec_thread_t *p_vdec )
212 p_vdec->p_ff_pic = avcodec_alloc_frame();
214 if( ( p_vdec->p_format = (BITMAPINFOHEADER *)p_vdec->p_fifo->p_bitmapinfoheader) != NULL )
216 /* ***** Fill p_context with init values ***** */
217 p_vdec->p_context->width = p_vdec->p_format->biWidth;
218 p_vdec->p_context->height = p_vdec->p_format->biHeight;
222 msg_Warn( p_vdec->p_fifo, "display informations missing" );
223 p_vdec->p_format = NULL;
227 /* ***** Get configuration of ffmpeg plugin ***** */
228 i_tmp = config_GetInt( p_vdec->p_fifo, "ffmpeg-workaround-bugs" );
229 p_vdec->p_context->workaround_bugs = __MAX( __MIN( i_tmp, 99 ), 0 );
231 i_tmp = config_GetInt( p_vdec->p_fifo, "ffmpeg-error-resilience" );
232 p_vdec->p_context->error_resilience = __MAX( __MIN( i_tmp, 99 ), -1 );
234 if( config_GetInt( p_vdec->p_fifo, "grayscale" ) )
236 p_vdec->p_context->flags|= CODEC_FLAG_GRAY;
239 p_vdec->b_hurry_up = config_GetInt(p_vdec->p_fifo, "ffmpeg-hurry-up");
241 p_vdec->b_direct_rendering = 0;
243 /* CODEC_FLAG_TRUNCATED */
245 /* FIXME search real LIBAVCODEC_BUILD */
246 #if LIBAVCODEC_BUILD >= 4662
247 i_truncated = config_GetInt( p_vdec->p_fifo, "ffmpeg-truncated" );
248 if( i_truncated == 1 ||
249 ( i_truncated == -1 && ( p_vdec->p_context->width == 0 || p_vdec->p_context->height == 0 ) ) )
251 p_vdec->p_context->flags |= CODEC_FLAG_TRUNCATED;
254 /* ***** Open the codec ***** */
255 if( avcodec_open(p_vdec->p_context, p_vdec->p_codec) < 0 )
257 msg_Err( p_vdec->p_fifo, "cannot open codec (%s)",
258 p_vdec->psz_namecodec );
259 return( VLC_EGENERIC );
263 msg_Dbg( p_vdec->p_fifo, "ffmpeg codec (%s) started",
264 p_vdec->psz_namecodec );
267 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-dr" ) &&
268 p_vdec->p_codec->capabilities & CODEC_CAP_DR1 &&
269 ffmpeg_PixFmtToChroma( p_vdec->p_context->pix_fmt ) &&
270 !(p_vdec->p_context->width % 16) && !(p_vdec->p_context->height % 16) )
272 /* FIXME: some codecs set pix_fmt only after a frame
273 * has been decoded. */
275 msg_Dbg( p_vdec->p_fifo, "using direct rendering" );
276 p_vdec->b_direct_rendering = 1;
277 p_vdec->p_context->flags|= CODEC_FLAG_EMU_EDGE;
278 p_vdec->p_context->get_buffer = ffmpeg_GetFrameBuf;
279 p_vdec->p_context->release_buffer = ffmpeg_ReleaseFrameBuf;
280 p_vdec->p_context->opaque = p_vdec;
284 /* ***** init this codec with special data ***** */
285 if( p_vdec->p_format &&
286 p_vdec->p_format->biSize > sizeof(BITMAPINFOHEADER) )
289 int i_size = p_vdec->p_format->biSize - sizeof(BITMAPINFOHEADER);
291 if( p_vdec->i_codec_id == CODEC_ID_MPEG4 )
293 avcodec_decode_video( p_vdec->p_context, p_vdec->p_ff_pic,
295 (void *)&p_vdec->p_format[1],
298 #if LIBAVCODEC_BUILD >= 4666
299 else if( p_vdec->i_codec_id == CODEC_ID_SVQ3 )
303 p_vdec->p_context->extradata_size = i_size + 12;
304 p = p_vdec->p_context->extradata = malloc( p_vdec->p_context->extradata_size );
306 memcpy( &p[0], "SVQ3", 4 );
307 memset( &p[4], 0, 8 );
308 memcpy( &p[12], &p_vdec->p_format[1], i_size );
313 p_vdec->p_context->extradata_size = i_size;
314 p_vdec->p_context->extradata = malloc( i_size );
315 memcpy( p_vdec->p_context->extradata,
316 &p_vdec->p_format[1],
321 /* ***** Load post processing ***** */
323 p_vdec->pp_context = NULL;
324 p_vdec->pp_mode = NULL;
326 /* for now we cannot do postproc and dr */
327 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" ) > 0 && !p_vdec->b_direct_rendering )
329 int i_quality = config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" );
330 char *psz_name = config_GetPsz( p_vdec->p_fifo, "ffmpeg-pp-name" );
335 psz_name = strdup( "default" );
337 else if( *psz_name == '\0' )
340 psz_name = strdup( "default" );
344 p_vdec->pp_mode = pp_get_mode_by_name_and_quality( psz_name, i_quality );
346 if( !p_vdec->pp_mode )
348 msg_Err( p_vdec->p_fifo, "failed geting mode for postproc" );
352 msg_Info( p_vdec->p_fifo, "postproc activated" );
358 msg_Dbg( p_vdec->p_fifo, "no postproc" );
362 /* get overridding settings */
363 p_vdec->i_pp_mode = 0;
364 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-yv" ) )
365 p_vdec->i_pp_mode |= PP_DEBLOCK_Y_V;
366 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-yh" ) )
367 p_vdec->i_pp_mode |= PP_DEBLOCK_Y_H;
368 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-cv" ) )
369 p_vdec->i_pp_mode |= PP_DEBLOCK_C_V;
370 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-ch" ) )
371 p_vdec->i_pp_mode |= PP_DEBLOCK_C_H;
372 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-dr-y" ) )
373 p_vdec->i_pp_mode |= PP_DERING_Y;
374 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-dr-c" ) )
375 p_vdec->i_pp_mode |= PP_DERING_C;
377 if( ( config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" ) > 0 )||
378 ( config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-auto" ) )||
379 ( p_vdec->i_pp_mode != 0 ) )
381 /* check if the codec support postproc. */
382 switch( p_vdec->i_codec_id )
384 case( CODEC_ID_MSMPEG4V1 ):
385 case( CODEC_ID_MSMPEG4V2 ):
386 case( CODEC_ID_MSMPEG4V3 ):
387 case( CODEC_ID_MPEG4 ):
388 case( CODEC_ID_H263 ):
389 // case( CODEC_ID_H263P ): I don't use it up to now
390 case( CODEC_ID_H263I ):
391 /* Ok we can make postprocessing :)) */
392 /* first try to get a postprocess module */
393 p_vdec->p_pp = vlc_object_create( p_vdec->p_fifo,
394 sizeof( postprocessing_t ) );
395 p_vdec->p_pp->psz_object_name = "postprocessing";
396 p_vdec->p_pp->p_module =
397 module_Need( p_vdec->p_pp, "postprocessing", "$ffmpeg-pp" );
399 if( !p_vdec->p_pp->p_module )
401 msg_Warn( p_vdec->p_fifo,
402 "no suitable postprocessing module" );
403 vlc_object_destroy( p_vdec->p_pp );
405 p_vdec->i_pp_mode = 0;
409 /* get mode upon quality */
411 p_vdec->p_pp->pf_getmode(
412 config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" ),
413 config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-auto" )
418 p_vdec->i_pp_mode = 0;
419 msg_Warn( p_vdec->p_fifo,
420 "Post processing unsupported for this codec" );
426 return( VLC_SUCCESS );
429 /*****************************************************************************
430 * DecodeThread: Called to decode one frame
431 *****************************************************************************
432 * We have to get a frame stored in a pes, give it to ffmpeg decoder and send
433 * the image to the output.
434 *****************************************************************************/
435 void E_( DecodeThread_Video )( vdec_thread_t *p_vdec )
442 picture_t *p_pic; /* videolan picture */
446 /* TODO implement it in a better way */
447 /* A good idea could be to decode all I pictures and see for the other */
448 if( ( p_vdec->b_hurry_up )&& ( p_vdec->i_frame_late > 4 ) )
451 if( p_vdec->i_frame_late < 8 )
453 p_vdec->p_context->hurry_up = 2;
457 /* too much late picture, won't decode
458 but break picture until a new I, and for mpeg4 ...*/
459 p_vdec->i_frame_late--; /* needed else it will never be decrease */
460 input_ExtractPES( p_vdec->p_fifo, NULL );
467 p_vdec->p_context->hurry_up = 0;
470 if( p_vdec->i_frame_late > 0 && mdate() - p_vdec->i_frame_late_start > (mtime_t)5000000 )
472 msg_Err( p_vdec->p_fifo, "more than 5 seconds of late video -> dropping (to slow computer ?)" );
475 input_ExtractPES( p_vdec->p_fifo, &p_pes );
478 p_vdec->p_fifo->b_error = 1;
481 i_pts = p_pes->i_pts;
482 input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes );
484 } while( i_pts <= 0 || i_pts < mdate() );
487 if( !p_vdec->p_context->width || !p_vdec->p_context->height )
489 p_vdec->p_context->hurry_up = 5;
494 input_ExtractPES( p_vdec->p_fifo, &p_pes );
497 p_vdec->p_fifo->b_error = 1;
501 if( p_vdec->i_codec_id == CODEC_ID_MPEG1VIDEO )
505 p_vdec->pts = p_pes->i_dts;
506 p_vdec->i_frame_count = 0;
513 p_vdec->pts = p_pes->i_pts;
514 p_vdec->i_frame_count = 0;
520 p_vdec->pts = p_pes->i_pts;
521 p_vdec->i_frame_count = 0;
524 i_frame_size = p_pes->i_pes_size;
526 if( i_frame_size > 0 )
530 /* XXX Don't forget that ffmpeg required a little more bytes
531 * that the real frame size */
532 i_need = i_frame_size + 16 + p_vdec->i_buffer;
533 if( p_vdec->i_buffer_size < i_need)
535 p_last = p_vdec->p_buffer;
536 p_vdec->p_buffer = malloc( i_need );
537 p_vdec->i_buffer_size = i_need;
538 if( p_vdec->i_buffer > 0 )
540 memcpy( p_vdec->p_buffer, p_last, p_vdec->i_buffer );
545 E_( GetPESData )( p_vdec->p_buffer + p_vdec->i_buffer,
548 memset( p_vdec->p_buffer + p_vdec->i_buffer + i_frame_size,
552 input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes );
553 } while( i_frame_size <= 0 );
555 i_frame_size += p_vdec->i_buffer;
558 i_used = avcodec_decode_video( p_vdec->p_context,
565 msg_Dbg( p_vdec->p_fifo,
566 "used:%d framesize:%d (%s picture)",
567 i_used, i_frame_size, b_gotpicture ? "got":"no got" );
571 msg_Warn( p_vdec->p_fifo, "cannot decode one frame (%d bytes)",
573 p_vdec->i_frame_error++;
574 p_vdec->i_buffer = 0;
577 else if( i_used < i_frame_size )
579 memmove( p_vdec->p_buffer,
580 p_vdec->p_buffer + i_used,
581 p_vdec->i_buffer_size - i_used );
583 p_vdec->i_buffer = i_frame_size - i_used;
587 p_vdec->i_buffer = 0;
592 p_vdec->i_frame_count++;
596 i_frame_size -= i_used;
598 /* Update frame late count*/
599 if( p_vdec->pts <= mdate() )
601 p_vdec->i_frame_late++;
602 if( p_vdec->i_frame_late == 1 )
604 p_vdec->i_frame_late_start = mdate();
609 p_vdec->i_frame_late = 0;
612 if( !b_gotpicture || p_vdec->p_ff_pic->linesize[0] == 0 || !b_drawpicture )
617 if( !p_vdec->b_direct_rendering )
619 p_vdec->p_vout = ffmpeg_CreateVout( p_vdec, p_vdec->p_context );
620 if( !p_vdec->p_vout )
622 msg_Err( p_vdec->p_fifo, "cannot create vout" );
623 p_vdec->p_fifo->b_error = 1; /* abort */
627 /* Get a new picture */
628 while( !(p_pic = vout_CreatePicture( p_vdec->p_vout, 0, 0, 0 ) ) )
630 if( p_vdec->p_fifo->b_die || p_vdec->p_fifo->b_error )
634 msleep( VOUT_OUTMEM_SLEEP );
637 /* fill p_picture_t from AVVideoFrame and do chroma conversion
639 ffmpeg_CopyPicture( p_pic, p_vdec->p_ff_pic, p_vdec );
641 #ifndef LIBAVCODEC_PP
642 /* Do post-processing if requested (with old code)*/
644 if( ( p_vdec->i_pp_mode )&&
645 ( ( p_vdec->p_vout->render.i_chroma ==
646 VLC_FOURCC( 'I','4','2','0' ) )||
647 ( p_vdec->p_vout->render.i_chroma ==
648 VLC_FOURCC( 'Y','V','1','2' ) ) ) )
650 p_vdec->p_pp->pf_postprocess( p_pic,
651 p_vdec->p_ff_pic->qscale_table,
652 p_vdec->p_ff_pic->qstride,
660 p_pic = (picture_t *)p_vdec->p_ff_pic->opaque;
663 /* fix date calculation */
664 if( p_vdec->pts > 0 )
668 if( p_vdec->p_context->frame_rate > 0 )
670 #if LIBAVCODEC_BUILD >= 4662
671 i_pts += (uint64_t)1000000 *
672 ( p_vdec->i_frame_count - 1) /
673 DEFAULT_FRAME_RATE_BASE /
674 p_vdec->p_context->frame_rate;
676 i_pts += (uint64_t)1000000 *
677 ( p_vdec->i_frame_count - 1) /
679 p_vdec->p_context->frame_rate;
685 i_pts = mdate() + DEFAULT_PTS_DELAY; // FIXME
688 vout_DatePicture( p_vdec->p_vout,
692 /* Send decoded frame to vout */
693 vout_DisplayPicture( p_vdec->p_vout, p_pic );
695 if( i_frame_size > 0 )
697 goto usenextdata; /* try to use all data */
701 /*****************************************************************************
702 * EndThread: thread destruction
703 *****************************************************************************
704 * This function is called when the thread ends after a sucessful
706 *****************************************************************************/
707 void E_( EndThread_Video )( vdec_thread_t *p_vdec )
711 if( p_vdec->pp_mode )
713 pp_free_mode( p_vdec->pp_mode );
714 if( p_vdec->pp_context )
716 pp_free_context( p_vdec->pp_context );
722 /* release postprocessing module */
723 module_Unneed( p_vdec->p_pp, p_vdec->p_pp->p_module );
724 vlc_object_destroy( p_vdec->p_pp );
729 if( p_vdec->p_ff_pic )
731 free( p_vdec->p_ff_pic );
734 /* We are about to die. Reattach video output to p_vlc. */
735 vout_Request( p_vdec->p_fifo, p_vdec->p_vout, 0, 0, 0, 0 );
738 /*****************************************************************************
739 * ffmpeg_CopyPicture: copy a picture from ffmpeg internal buffers to a
740 * picture_t structure (when not in direct rendering mode).
741 *****************************************************************************/
742 static void ffmpeg_CopyPicture( picture_t *p_pic,
744 vdec_thread_t *p_vdec )
755 if( ffmpeg_PixFmtToChroma( p_vdec->p_context->pix_fmt ) )
758 if( p_vdec->pp_mode && p_vdec->pp_context )
760 uint8_t *src[3], *dst[3];
761 int i_src_stride[3], i_dst_stride[3];
763 for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
765 src[i_plane] = p_ff_pic->data[i_plane];
766 dst[i_plane] = p_pic->p[i_plane].p_pixels;
768 i_src_stride[i_plane] = p_ff_pic->linesize[i_plane];
769 i_dst_stride[i_plane] = p_pic->p[i_plane].i_pitch;
771 pp_postprocess( src, i_src_stride,
773 p_vdec->p_context->width, p_vdec->p_context->height,
774 p_ff_pic->qscale_table, p_ff_pic->qstride,
775 p_vdec->pp_mode, p_vdec->pp_context,
776 p_ff_pic->pict_type );
781 for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
783 p_src = p_ff_pic->data[i_plane];
784 p_dst = p_pic->p[i_plane].p_pixels;
785 i_src_stride = p_ff_pic->linesize[i_plane];
786 i_dst_stride = p_pic->p[i_plane].i_pitch;
788 i_size = __MIN( i_src_stride, i_dst_stride );
789 for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
791 p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_size );
792 p_src += i_src_stride;
793 p_dst += i_dst_stride;
802 /* we need to convert to I420 */
803 switch( p_vdec->p_context->pix_fmt )
808 case( PIX_FMT_YUV410P ):
809 case( PIX_FMT_YUV411P ):
810 for( i = 0; i < p_pic->i_planes; i++ )
812 dest_pic.data[i] = p_pic->p[i].p_pixels;
813 dest_pic.linesize[i] = p_pic->p[i].i_pitch;
815 img_convert( &dest_pic, PIX_FMT_YUV420P,
816 (AVPicture *)p_ff_pic,
817 p_vdec->p_context->pix_fmt,
818 p_vdec->p_context->width,
819 p_vdec->p_context->height );
822 msg_Err( p_vdec->p_fifo, "don't know how to convert chroma %i",
823 p_vdec->p_context->pix_fmt );
824 p_vdec->p_fifo->b_error = 1;
830 /*****************************************************************************
831 * ffmpeg_GetFrameBuf: callback used by ffmpeg to get a frame buffer.
832 * (used for direct rendering)
833 *****************************************************************************/
834 static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
837 vdec_thread_t *p_vdec = (vdec_thread_t *)p_context->opaque;
840 /* Check and (re)create if needed our vout */
841 p_vdec->p_vout = ffmpeg_CreateVout( p_vdec, p_vdec->p_context );
842 if( !p_vdec->p_vout )
844 msg_Err( p_vdec->p_fifo, "cannot create vout" );
845 p_vdec->p_fifo->b_error = 1; /* abort */
848 p_vdec->p_vout->render.b_allow_modify_pics = 0;
850 /* Get a new picture */
851 while( !(p_pic = vout_CreatePicture( p_vdec->p_vout, 0, 0, 0 ) ) )
853 if( p_vdec->p_fifo->b_die || p_vdec->p_fifo->b_error )
857 msleep( VOUT_OUTMEM_SLEEP );
859 p_vdec->p_context->draw_horiz_band= NULL;
861 p_ff_pic->opaque = (void*)p_pic;
862 p_ff_pic->type = FF_BUFFER_TYPE_USER;
863 p_ff_pic->data[0] = p_pic->p[0].p_pixels;
864 p_ff_pic->data[1] = p_pic->p[1].p_pixels;
865 p_ff_pic->data[2] = p_pic->p[2].p_pixels;
866 p_ff_pic->data[3] = NULL; /* alpha channel but I'm not sure */
868 p_ff_pic->linesize[0] = p_pic->p[0].i_pitch;
869 p_ff_pic->linesize[1] = p_pic->p[1].i_pitch;
870 p_ff_pic->linesize[2] = p_pic->p[2].i_pitch;
871 p_ff_pic->linesize[3] = 0;
873 if( p_ff_pic->reference != 0 )
875 vout_LinkPicture( p_vdec->p_vout, p_pic );
877 /* FIXME what is that, should give good value */
878 p_ff_pic->age = 256*256*256*64; // FIXME FIXME from ffmpeg
883 static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
886 vdec_thread_t *p_vdec = (vdec_thread_t *)p_context->opaque;
889 //msg_Dbg( p_vdec->p_fifo, "ffmpeg_ReleaseFrameBuf" );
890 p_pic = (picture_t*)p_ff_pic->opaque;
892 p_ff_pic->data[0] = NULL;
893 p_ff_pic->data[1] = NULL;
894 p_ff_pic->data[2] = NULL;
895 p_ff_pic->data[3] = NULL;
897 vout_UnlinkPicture( p_vdec->p_vout, p_pic );