1 /*****************************************************************************
2 * video.c: video decoder using ffmpeg library
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: video.c,v 1.2 2002/11/05 10:07:56 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>
42 #include "avcodec.h" /* ffmpeg */
44 #include "postprocessing/postprocessing.h"
49 /*****************************************************************************
51 *****************************************************************************/
52 static void ffmpeg_CopyPicture( picture_t *, AVPicture *, vdec_thread_t * );
53 static void ffmpeg_PostProcPicture( vdec_thread_t *, picture_t * );
54 static int ffmpeg_GetFrameBuf( struct AVCodecContext *, int, int, int );
56 /* FIXME FIXME some of them are wrong */
57 static int i_ffmpeg_PixFmtToChroma[] =
59 /* PIX_FMT_ANY = -1, PIX_FMT_YUV420P,
60 PIX_FMT_YUV422, PIX_FMT_RGB24,
61 PIX_FMT_BGR24, PIX_FMT_YUV422P,
62 PIX_FMT_YUV444P, PIX_FMT_YUV410P
64 0, VLC_FOURCC('I','4','2','0'),
65 VLC_FOURCC('I','4','2','0'), VLC_FOURCC('R','V','2','4'),
66 0, VLC_FOURCC('Y','4','2','2'),
67 VLC_FOURCC('I','4','4','4'), 0
70 /*****************************************************************************
72 *****************************************************************************/
74 static inline u32 ffmpeg_PixFmtToChroma( int i_ffmpegchroma )
76 if( ++i_ffmpegchroma > 7 )
82 return( i_ffmpeg_PixFmtToChroma[i_ffmpegchroma] );
86 static inline int ffmpeg_FfAspect( int i_width, int i_height, int i_ffaspect )
90 case( FF_ASPECT_4_3_625 ):
91 case( FF_ASPECT_4_3_525 ):
92 return( VOUT_ASPECT_FACTOR * 4 / 3);
93 case( FF_ASPECT_16_9_625 ):
94 case( FF_ASPECT_16_9_525 ):
95 return( VOUT_ASPECT_FACTOR * 16 / 9 );
96 case( FF_ASPECT_SQUARE ):
98 return( VOUT_ASPECT_FACTOR * i_width / i_height );
102 /* Check if we have a Vout with good parameters */
103 static int ffmpeg_CheckVout( vout_thread_t *p_vout,
115 /* we will try to make conversion */
116 i_chroma = VLC_FOURCC('I','4','2','0');
119 if( ( p_vout->render.i_width != i_width )||
120 ( p_vout->render.i_height != i_height )||
121 ( p_vout->render.i_chroma != i_chroma )||
122 ( p_vout->render.i_aspect !=
123 ffmpeg_FfAspect( i_width, i_height, i_aspect ) ) )
134 static vout_thread_t *ffmpeg_CreateVout( vdec_thread_t *p_vdec,
140 vout_thread_t *p_vout;
142 if( (!i_width)||(!i_height) )
144 return( NULL ); /* Can't create a new vout without display size */
149 /* we make conversion if possible*/
150 i_chroma = VLC_FOURCC('I','4','2','0');
151 msg_Warn( p_vdec->p_fifo, "Internal chroma conversion (FIXME)");
152 /* It's mainly for I410 -> I420 conversion that I've made,
153 it's buggy and very slow */
156 i_aspect = ffmpeg_FfAspect( i_width, i_height, i_aspect );
158 /* Spawn a video output if there is none. First we look for our children,
159 * then we look for any other vout that might be available. */
160 p_vout = vlc_object_find( p_vdec->p_fifo, VLC_OBJECT_VOUT,
164 p_vout = vlc_object_find( p_vdec->p_fifo, VLC_OBJECT_VOUT,
170 if( !ffmpeg_CheckVout( p_vout,
171 i_width, i_height, i_aspect,i_chroma ) )
173 /* We are not interested in this format, close this vout */
174 vlc_object_detach( p_vout );
175 vlc_object_release( p_vout );
176 vout_DestroyThread( p_vout );
181 /* This video output is cool! Hijack it. */
182 vlc_object_detach( p_vout );
183 vlc_object_attach( p_vout, p_vdec->p_fifo );
184 vlc_object_release( p_vout );
190 msg_Dbg( p_vdec->p_fifo, "no vout present, spawning one" );
192 p_vout = vout_CreateThread( p_vdec->p_fifo,
194 i_chroma, i_aspect );
200 /* FIXME FIXME FIXME this is a big shit
201 does someone want to rewrite this function ?
202 or said to me how write a better thing
205 static void ffmpeg_ConvertPictureI410toI420( picture_t *p_pic,
206 AVPicture *p_avpicture,
207 vdec_thread_t *p_vdec )
213 int i_stride, i_lines;
214 int i_height, i_width;
217 i_height = p_vdec->p_context->height;
218 i_width = p_vdec->p_context->width;
220 p_dst = p_pic->p[0].p_pixels;
221 p_src = p_avpicture->data[0];
223 /* copy first plane */
224 for( i_y = 0; i_y < i_height; i_y++ )
226 p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_width);
227 p_dst += p_pic->p[0].i_pitch;
228 p_src += p_avpicture->linesize[0];
231 /* process each plane in a temporary buffer */
232 for( i_plane = 1; i_plane < 3; i_plane++ )
234 i_stride = p_avpicture->linesize[i_plane];
235 i_lines = i_height / 4;
237 p_dst = p_plane[i_plane] = malloc( i_lines * i_stride * 2 * 2 );
238 p_src = p_avpicture->data[i_plane];
240 /* for each source line */
241 for( i_y = 0; i_y < i_lines; i_y++ )
243 for( i_x = 0; i_x < i_stride - 1; i_x++ )
245 p_dst[2 * i_x ] = p_src[i_x];
246 p_dst[2 * i_x + 1] = ( p_src[i_x] + p_src[i_x + 1]) / 2;
249 p_dst[2 * i_stride - 2] = p_src[i_x];
250 p_dst[2 * i_stride - 1] = p_src[i_x];
252 p_dst += 4 * i_stride; /* process the next even lines */
257 for( i_plane = 1; i_plane < 3; i_plane++ )
259 i_stride = p_avpicture->linesize[i_plane];
260 i_lines = i_height / 4;
262 p_dst = p_plane[i_plane] + 2*i_stride;
263 p_src = p_plane[i_plane];
265 for( i_y = 0; i_y < i_lines - 1; i_y++ )
267 for( i_x = 0; i_x < 2 * i_stride ; i_x++ )
269 p_dst[i_x] = ( p_src[i_x] + p_src[i_x + 4*i_stride])/2;
272 p_dst += 4 * i_stride; /* process the next odd lines */
273 p_src += 4 * i_stride;
276 p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, 2*i_stride );
278 /* copy to p_pic, by block
279 if I do pixel per pixel it segfault. It's why I use
280 temporaries buffers */
281 for( i_plane = 1; i_plane < 3; i_plane++ )
284 p_src = p_plane[i_plane];
285 p_dst = p_pic->p[i_plane].p_pixels;
287 i_size = __MIN( 2*i_stride, p_pic->p[i_plane].i_pitch);
288 for( i_y = 0; i_y < __MIN(p_pic->p[i_plane].i_lines, 2 * i_lines); i_y++ )
290 p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_size );
291 p_src += 2 * i_stride;
292 p_dst += p_pic->p[i_plane].i_pitch;
294 free( p_plane[i_plane] );
298 /*****************************************************************************
300 * Functions that initialize, decode and end the decoding process
302 * Functions exported for ffmpeg.c
303 * * E_( InitThread_Video )
304 * * E_( DecodeThread )
305 * * E_( EndThread_Video )
306 *****************************************************************************/
308 /*****************************************************************************
309 * InitThread: initialize vdec output thread
310 *****************************************************************************
311 * This function is called from decoder_Run and performs the second step
312 * of the initialization. It returns 0 on success. Note that the thread's
313 * flag are not modified inside this function.
315 * ffmpeg codec will be open, some memory allocated. But Vout is not yet
316 * open (done after the first decoded frame)
317 *****************************************************************************/
318 int E_( InitThread_Video )( vdec_thread_t *p_vdec )
322 if( p_vdec->p_fifo->p_demux_data )
324 p_vdec->p_format = (BITMAPINFOHEADER *)p_vdec->p_fifo->p_demux_data;
328 msg_Warn( p_vdec->p_fifo, "display informations missing" );
331 /* ***** Fill p_context with init values ***** */
332 p_vdec->p_context->width = p_vdec->p_format->biWidth;
333 p_vdec->p_context->height = p_vdec->p_format->biHeight;
335 /* ***** Get configuration of ffmpeg plugin ***** */
336 #if LIBAVCODEC_BUILD >= 4611
337 i_tmp = config_GetInt( p_vdec->p_fifo, "ffmpeg-workaround-bugs" );
338 p_vdec->p_context->workaround_bugs = __MAX( __MIN( i_tmp, 99 ), 0 );
340 i_tmp = config_GetInt( p_vdec->p_fifo, "ffmpeg-error-resilience" );
341 p_vdec->p_context->error_resilience = __MAX( __MIN( i_tmp, 99 ), -1 );
343 #if LIBAVCODEC_BUILD >= 4614
344 if( config_GetInt( p_vdec->p_fifo, "grayscale" ) )
346 p_vdec->p_context->flags|= CODEC_FLAG_GRAY;
350 p_vdec->b_hurry_up = config_GetInt(p_vdec->p_fifo, "ffmpeg-hurry-up");
352 p_vdec->b_direct_rendering = 0;
353 #if LIBAVCODEC_BUILD > 4615
354 if( (p_vdec->p_codec->capabilities & CODEC_CAP_DR1)
355 && (p_vdec->p_context->pix_fmt != PIX_FMT_YUV410P) )
357 msg_Dbg( p_vdec->p_fifo, "using direct rendering" );
358 p_vdec->b_direct_rendering = 1;
359 p_vdec->p_context->flags|= CODEC_FLAG_EMU_EDGE | CODEC_FLAG_DR1;
360 p_vdec->p_context->get_buffer_callback = ffmpeg_GetFrameBuf;
361 p_vdec->p_context->opaque = p_vdec;
365 /* ***** Open the codec ***** */
366 if( avcodec_open(p_vdec->p_context, p_vdec->p_codec) < 0 )
368 msg_Err( p_vdec->p_fifo, "cannot open codec (%s)",
369 p_vdec->psz_namecodec );
374 msg_Dbg( p_vdec->p_fifo, "ffmpeg codec (%s) started",
375 p_vdec->psz_namecodec );
378 /* ***** init this codec with special data ***** */
379 if( p_vdec->p_format->biSize > sizeof(BITMAPINFOHEADER) )
384 switch( p_vdec->i_codec_id )
386 case( CODEC_ID_MPEG4 ):
387 avcodec_decode_video( p_vdec->p_context, &avpicture,
389 (void *)&p_vdec->p_format[1],
390 p_vdec->p_format->biSize
391 - sizeof(BITMAPINFOHEADER) );
394 if( p_vdec->p_fifo->i_fourcc == FOURCC_MP4S ||
395 p_vdec->p_fifo->i_fourcc == FOURCC_mp4s ||
396 p_vdec->p_fifo->i_fourcc == FOURCC_M4S2 ||
397 p_vdec->p_fifo->i_fourcc == FOURCC_m4s2 )
399 p_vdec->p_context->extradata_size =
400 p_vdec->p_format->biSize - sizeof(BITMAPINFOHEADER);
401 p_vdec->p_context->extradata =
402 malloc( p_vdec->p_context->extradata_size );
403 memcpy( p_vdec->p_context->extradata,
404 &p_vdec->p_format[1],
405 p_vdec->p_context->extradata_size );
412 /* ***** Load post processing ***** */
414 /* get overridding settings */
415 p_vdec->i_pp_mode = 0;
416 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-yv" ) )
417 p_vdec->i_pp_mode |= PP_DEBLOCK_Y_V;
418 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-yh" ) )
419 p_vdec->i_pp_mode |= PP_DEBLOCK_Y_H;
420 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-cv" ) )
421 p_vdec->i_pp_mode |= PP_DEBLOCK_C_V;
422 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-ch" ) )
423 p_vdec->i_pp_mode |= PP_DEBLOCK_C_H;
424 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-dr-y" ) )
425 p_vdec->i_pp_mode |= PP_DERING_Y;
426 if( config_GetInt( p_vdec->p_fifo, "ffmpeg-dr-c" ) )
427 p_vdec->i_pp_mode |= PP_DERING_C;
429 if( ( config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" ) > 0 )||
430 ( config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-auto" ) )||
431 ( p_vdec->i_pp_mode != 0 ) )
433 /* check if the codec support postproc. */
434 switch( p_vdec->i_codec_id )
436 #if LIBAVCODEC_BUILD > 4608
437 case( CODEC_ID_MSMPEG4V1 ):
438 case( CODEC_ID_MSMPEG4V2 ):
439 case( CODEC_ID_MSMPEG4V3 ):
441 case( CODEC_ID_MSMPEG4 ):
443 case( CODEC_ID_MPEG4 ):
444 case( CODEC_ID_H263 ):
445 // case( CODEC_ID_H263P ): I don't use it up to now
446 case( CODEC_ID_H263I ):
447 /* Ok we can make postprocessing :)) */
448 /* first try to get a postprocess module */
449 #if LIBAVCODEC_BUILD > 4613
450 p_vdec->p_pp = vlc_object_create( p_vdec->p_fifo,
451 sizeof( postprocessing_t ) );
452 p_vdec->p_pp->psz_object_name = "postprocessing";
453 p_vdec->p_pp->p_module =
454 module_Need( p_vdec->p_pp, "postprocessing", "$ffmpeg-pp" );
456 if( !p_vdec->p_pp->p_module )
458 msg_Warn( p_vdec->p_fifo,
459 "no suitable postprocessing module" );
460 vlc_object_destroy( p_vdec->p_pp );
462 p_vdec->i_pp_mode = 0;
466 /* get mode upon quality */
468 p_vdec->p_pp->pf_getmode(
469 config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" ),
470 config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-auto" )
473 /* allocate table for postprocess */
474 p_vdec->p_context->quant_store =
475 malloc( sizeof( int ) * ( MBR + 1 ) * ( MBC + 1 ) );
476 p_vdec->p_context->qstride = MBC + 1;
479 p_vdec->i_pp_mode = 0;
480 msg_Warn( p_vdec->p_fifo,
481 "post-processing not supported, upgrade ffmpeg" );
485 p_vdec->i_pp_mode = 0;
486 msg_Warn( p_vdec->p_fifo,
487 "Post processing unsupported for this codec" );
492 // memset( &p_vdec->statistic, 0, sizeof( statistic_t ) );
497 /*****************************************************************************
498 * DecodeThread: Called for decode one frame
499 *****************************************************************************
500 * We have to get a frame stored in a pes, give it to ffmpeg decoder and send
501 * the image to the output.
502 *****************************************************************************/
503 void E_( DecodeThread_Video )( vdec_thread_t *p_vdec )
510 AVPicture avpicture; /* ffmpeg picture */
511 picture_t *p_pic; /* videolan picture */
513 /* TODO implement it in a better way */
514 /* A good idea could be to decode all I pictures and see for the other */
515 if( ( p_vdec->b_hurry_up )&& ( p_vdec->i_frame_late > 4 ) )
517 #if LIBAVCODEC_BUILD > 4603
519 if( p_vdec->i_frame_late < 8 )
521 p_vdec->p_context->hurry_up = 2;
525 /* too much late picture, won't decode
526 but break picture until a new I, and for mpeg4 ...*/
527 p_vdec->i_frame_late--; /* needed else it will never be decrease */
528 input_ExtractPES( p_vdec->p_fifo, NULL );
532 if( p_vdec->i_frame_late < 8 )
534 b_drawpicture = 0; /* not really good but .. UPGRADE FFMPEG !! */
538 /* too much late picture, won't decode
539 but break picture until a new I, and for mpeg4 ...*/
540 p_vdec->i_frame_late--; /* needed else it will never be decrease */
541 input_ExtractPES( p_vdec->p_fifo, NULL );
549 #if LIBAVCODEC_BUILD > 4603
550 p_vdec->p_context->hurry_up = 0;
556 input_ExtractPES( p_vdec->p_fifo, &p_pes );
559 p_vdec->p_fifo->b_error = 1;
562 p_vdec->pts = p_pes->i_pts;
563 i_frame_size = p_pes->i_pes_size;
565 if( i_frame_size > 0 )
567 if( p_vdec->i_buffer < i_frame_size + 16 )
569 FREE( p_vdec->p_buffer );
570 p_vdec->p_buffer = malloc( i_frame_size + 16 );
571 p_vdec->i_buffer = i_frame_size + 16;
574 E_( GetPESData )( p_vdec->p_buffer, p_vdec->i_buffer, p_pes );
576 input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes );
577 } while( i_frame_size <= 0 );
580 i_status = avcodec_decode_video( p_vdec->p_context,
588 msg_Warn( p_vdec->p_fifo, "cannot decode one frame (%d bytes)",
590 p_vdec->i_frame_error++;
593 /* Update frame late count*/
594 /* I don't make statistic on decoding time */
595 if( p_vdec->pts <= mdate())
597 p_vdec->i_frame_late++;
601 p_vdec->i_frame_late = 0;
604 if( !b_gotpicture || avpicture.linesize[0] == 0 || !b_drawpicture )
609 if( !p_vdec->b_direct_rendering )
612 if( !ffmpeg_CheckVout( p_vdec->p_vout,
613 p_vdec->p_context->width,
614 p_vdec->p_context->height,
615 p_vdec->p_context->aspect_ratio_info,
616 ffmpeg_PixFmtToChroma(p_vdec->p_context->pix_fmt)) )
618 p_vdec->p_vout = ffmpeg_CreateVout( p_vdec,
619 p_vdec->p_context->width,
620 p_vdec->p_context->height,
621 p_vdec->p_context->aspect_ratio_info,
622 ffmpeg_PixFmtToChroma(p_vdec->p_context->pix_fmt) );
623 if( !p_vdec->p_vout )
625 msg_Err( p_vdec->p_fifo, "cannot create vout" );
626 p_vdec->p_fifo->b_error = 1; /* abort */
631 /* Get a new picture */
632 while( !(p_pic = vout_CreatePicture( p_vdec->p_vout, 0, 0, 0 ) ) )
634 if( p_vdec->p_fifo->b_die || p_vdec->p_fifo->b_error )
638 msleep( VOUT_OUTMEM_SLEEP );
641 /* fill p_picture_t from avpicture, do I410->I420 if needed */
642 ffmpeg_CopyPicture( p_pic, &avpicture, p_vdec );
646 #if LIBAVCODEC_BUILD > 4615
647 p_pic = (picture_t *)p_vdec->p_context->dr_opaque_frame;
651 /* Do post-processing if requested */
652 ffmpeg_PostProcPicture( p_vdec, p_pic );
654 /* FIXME correct avi and use i_dts */
656 /* Send decoded frame to vout */
657 vout_DatePicture( p_vdec->p_vout, p_pic, p_vdec->pts);
658 vout_DisplayPicture( p_vdec->p_vout, p_pic );
663 /*****************************************************************************
664 * EndThread: thread destruction
665 *****************************************************************************
666 * This function is called when the thread ends after a sucessful
668 *****************************************************************************/
669 void E_( EndThread_Video )( vdec_thread_t *p_vdec )
673 /* release postprocessing module */
674 module_Unneed( p_vdec->p_pp, p_vdec->p_pp->p_module );
675 vlc_object_destroy( p_vdec->p_pp );
679 if( p_vdec->p_vout != NULL )
681 /* We are about to die. Reattach video output to p_vlc. */
682 vlc_object_detach( p_vdec->p_vout );
683 vlc_object_attach( p_vdec->p_vout, p_vdec->p_fifo->p_vlc );
687 /*****************************************************************************
688 * ffmpeg_CopyPicture: copy a picture from ffmpeg internal buffers to a
689 * picture_t structure (when not in direct rendering mode).
690 *****************************************************************************/
691 static void ffmpeg_CopyPicture( picture_t *p_pic, AVPicture *p_avpicture,
692 vdec_thread_t *p_vdec )
703 if( ffmpeg_PixFmtToChroma( p_vdec->p_context->pix_fmt ) )
705 for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
707 p_src = p_avpicture->data[i_plane];
708 p_dst = p_pic->p[i_plane].p_pixels;
709 i_src_stride = p_avpicture->linesize[i_plane];
710 i_dst_stride = p_pic->p[i_plane].i_pitch;
712 i_size = __MIN( i_src_stride, i_dst_stride );
713 for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
715 p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_size );
716 p_src += i_src_stride;
717 p_dst += i_dst_stride;
723 /* we need to convert to I420 */
724 switch( p_vdec->p_context->pix_fmt )
726 #if LIBAVCODEC_BUILD >= 4615
727 case( PIX_FMT_YUV410P ):
728 ffmpeg_ConvertPictureI410toI420( p_pic, p_avpicture, p_vdec );
732 p_vdec->p_fifo->b_error = 1;
738 /*****************************************************************************
739 * ffmpeg_PostProcPicture: Postprocessing is done here.
740 *****************************************************************************/
741 static void ffmpeg_PostProcPicture( vdec_thread_t *p_vdec, picture_t *p_pic )
743 #if LIBAVCODEC_BUILD > 4313
744 if( ( p_vdec->i_pp_mode )&&
745 ( ( p_vdec->p_vout->render.i_chroma ==
746 VLC_FOURCC( 'I','4','2','0' ) )||
747 ( p_vdec->p_vout->render.i_chroma ==
748 VLC_FOURCC( 'Y','V','1','2' ) ) ) )
751 p_vdec->p_pp->pf_postprocess( p_pic,
752 p_vdec->p_context->quant_store,
753 p_vdec->p_context->qstride,
759 /*****************************************************************************
760 * ffmpeg_GetFrameBuf: callback used by ffmpeg to get a frame buffer.
761 * (used for direct rendering)
762 *****************************************************************************/
763 static int ffmpeg_GetFrameBuf( struct AVCodecContext *avctx, int width,
764 int height, int pict_type )
766 #if LIBAVCODEC_BUILD > 4615
767 vdec_thread_t *p_vdec = (vdec_thread_t *)avctx->opaque;
771 if( !ffmpeg_CheckVout( p_vdec->p_vout,
772 p_vdec->p_context->width,
773 p_vdec->p_context->height,
774 p_vdec->p_context->aspect_ratio_info,
775 ffmpeg_PixFmtToChroma(p_vdec->p_context->pix_fmt)) )
777 p_vdec->p_vout = ffmpeg_CreateVout( p_vdec,
778 p_vdec->p_context->width,
779 p_vdec->p_context->height,
780 p_vdec->p_context->aspect_ratio_info,
781 ffmpeg_PixFmtToChroma(p_vdec->p_context->pix_fmt) );
782 if( !p_vdec->p_vout )
784 msg_Err( p_vdec->p_fifo, "cannot create vout" );
785 p_vdec->p_fifo->b_error = 1; /* abort */
790 /* Get a new picture */
791 while( !(p_pic = vout_CreatePicture( p_vdec->p_vout, 0, 0, 0 ) ) )
793 if( p_vdec->p_fifo->b_die || p_vdec->p_fifo->b_error )
797 msleep( VOUT_OUTMEM_SLEEP );
800 /* FIXME: we may have to use link/unlinkPicture to fully support streams
803 avctx->draw_horiz_band= NULL;
804 avctx->dr_buffer[0]= p_pic->p[0].p_pixels;
805 avctx->dr_buffer[1]= p_pic->p[1].p_pixels;
806 avctx->dr_buffer[2]= p_pic->p[2].p_pixels;
808 avctx->dr_stride = p_pic->p[0].i_pitch;
809 avctx->dr_uvstride = p_pic->p[1].i_pitch;
811 avctx->dr_opaque_frame = p_pic;
813 /* FIXME: this variable is used to determine if a macro-block to be written
814 * can be skipped. The idea behind this is that if a macro-block hasn't
815 * changed and all the frame-buffers already have the value of this
816 * macro-block, then we can skip the writting.
817 * But currently we cannot ensure this is the case, so we decide to write
819 avctx->dr_ip_buffer_count = 999;