]> git.sesse.net Git - vlc/blob - modules/codec/libmpeg2.c
* modules/codec/libmpeg2.c, ffmpeg/video.c, theora.c: decoder sets fmt_out.video...
[vlc] / modules / codec / libmpeg2.c
1 /*****************************************************************************
2  * libmpeg2.c: mpeg2 video decoder module making use of libmpeg2.
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc/vout.h>
30 #include <vlc/decoder.h>
31
32 #include <mpeg2dec/mpeg2.h>
33
34 #include "vout_synchro.h"
35
36 /* Aspect ratio (ISO/IEC 13818-2 section 6.3.3, table 6-3) */
37 #define AR_SQUARE_PICTURE       1                           /* square pixels */
38 #define AR_3_4_PICTURE          2                        /* 3:4 picture (TV) */
39 #define AR_16_9_PICTURE         3              /* 16:9 picture (wide screen) */
40 #define AR_221_1_PICTURE        4                  /* 2.21:1 picture (movie) */
41
42 /*****************************************************************************
43  * decoder_sys_t : libmpeg2 decoder descriptor
44  *****************************************************************************/
45 struct decoder_sys_t
46 {
47     /*
48      * libmpeg2 properties
49      */
50     mpeg2dec_t          *p_mpeg2dec;
51     const mpeg2_info_t  *p_info;
52     vlc_bool_t          b_skip;
53
54     /*
55      * Input properties
56      */
57     mtime_t          i_previous_pts;
58     mtime_t          i_current_pts;
59     mtime_t          i_previous_dts;
60     mtime_t          i_current_dts;
61     int              i_current_rate;
62     picture_t *      p_picture_to_destroy;
63     vlc_bool_t       b_garbage_pic;
64     vlc_bool_t       b_after_sequence_header; /* is it the next frame after
65                                                * the sequence header ?    */
66     vlc_bool_t       b_slice_i;             /* intra-slice refresh stream */
67
68     /*
69      * Output properties
70      */
71     vout_synchro_t *p_synchro;
72     int            i_aspect;
73     mtime_t        i_last_frame_pts;
74
75 };
76
77 /*****************************************************************************
78  * Local prototypes
79  *****************************************************************************/
80 static int  OpenDecoder( vlc_object_t * );
81 static void CloseDecoder( vlc_object_t * );
82
83 static picture_t *DecodeBlock( decoder_t *, block_t ** );
84
85 static picture_t *GetNewPicture( decoder_t *, uint8_t ** );
86
87 /*****************************************************************************
88  * Module descriptor
89  *****************************************************************************/
90 vlc_module_begin();
91     set_description( _("MPEG I/II video decoder (using libmpeg2)") );
92     set_capability( "decoder", 150 );
93     set_callbacks( OpenDecoder, CloseDecoder );
94     add_shortcut( "libmpeg2" );
95 vlc_module_end();
96
97 /*****************************************************************************
98  * OpenDecoder: probe the decoder and return score
99  *****************************************************************************/
100 static int OpenDecoder( vlc_object_t *p_this )
101 {
102     decoder_t *p_dec = (decoder_t*)p_this;
103     decoder_sys_t *p_sys;
104     uint32_t i_accel = 0;
105
106     if( p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','v') &&
107         p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','1') &&
108         /* Pinnacle hardware-mpeg1 */
109         p_dec->fmt_in.i_codec != VLC_FOURCC('P','I','M','1') &&
110         /* ATI Video */
111         p_dec->fmt_in.i_codec != VLC_FOURCC('V','C','R','2') &&
112         p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','2') )
113     {
114         return VLC_EGENERIC;
115     }
116
117     /* Allocate the memory needed to store the decoder's structure */
118     if( ( p_dec->p_sys = p_sys =
119           (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
120     {
121         msg_Err( p_dec, "out of memory" );
122         return VLC_EGENERIC;
123     }
124
125     /* Initialize the thread properties */
126     memset( p_sys, 0, sizeof(decoder_sys_t) );
127     p_sys->p_mpeg2dec = NULL;
128     p_sys->p_synchro  = NULL;
129     p_sys->p_info     = NULL;
130     p_sys->i_current_pts  = 0;
131     p_sys->i_previous_pts = 0;
132     p_sys->i_current_dts  = 0;
133     p_sys->i_previous_dts = 0;
134     p_sys->p_picture_to_destroy = NULL;
135     p_sys->b_garbage_pic = 0;
136     p_sys->b_slice_i  = 0;
137     p_sys->b_skip     = 0;
138
139 #if defined( __i386__ )
140     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMX )
141     {
142         i_accel |= MPEG2_ACCEL_X86_MMX;
143     }
144
145     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_3DNOW )
146     {
147         i_accel |= MPEG2_ACCEL_X86_3DNOW;
148     }
149
150     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMXEXT )
151     {
152         i_accel |= MPEG2_ACCEL_X86_MMXEXT;
153     }
154
155 #elif defined( __powerpc__ ) || defined( SYS_DARWIN )
156     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC )
157     {
158         i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
159     }
160
161 #else
162     /* If we do not know this CPU, trust libmpeg2's feature detection */
163     i_accel = MPEG2_ACCEL_DETECT;
164
165 #endif
166
167     /* Set CPU acceleration features */
168     mpeg2_accel( i_accel );
169
170     /* Initialize decoder */
171     p_sys->p_mpeg2dec = mpeg2_init();
172     if( p_sys->p_mpeg2dec == NULL)
173     {
174         msg_Err( p_dec, "mpeg2_init() failed" );
175         free( p_sys );
176         return VLC_EGENERIC;
177     }
178
179     p_sys->p_info = mpeg2_info( p_sys->p_mpeg2dec );
180
181     p_dec->pf_decode_video = DecodeBlock;
182
183     return VLC_SUCCESS;
184 }
185
186 /*****************************************************************************
187  * RunDecoder: the libmpeg2 decoder
188  *****************************************************************************/
189 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
190 {
191     decoder_sys_t   *p_sys = p_dec->p_sys;
192     mpeg2_state_t   state;
193     picture_t       *p_pic;
194
195     block_t *p_block;
196
197     if( !pp_block || !*pp_block ) return NULL;
198
199     p_block = *pp_block;
200
201     while( 1 )
202     {
203         state = mpeg2_parse( p_sys->p_mpeg2dec );
204
205         switch( state )
206         {
207         case STATE_BUFFER:
208             if( !p_block->i_buffer )
209             {
210                 block_Release( p_block );
211                 return NULL;
212             }
213
214             if( (p_block->i_flags&BLOCK_FLAG_DISCONTINUITY) &&
215                 p_sys->p_synchro &&
216                 p_sys->p_info->sequence &&
217                 p_sys->p_info->sequence->width != (unsigned)-1 )
218             {
219                 vout_SynchroReset( p_sys->p_synchro );
220                 if( p_sys->p_info->current_fbuf != NULL
221                     && p_sys->p_info->current_fbuf->id != NULL )
222                 {
223                     p_sys->b_garbage_pic = 1;
224                     p_pic = p_sys->p_info->current_fbuf->id;
225                 }
226                 else
227                 {
228                     uint8_t *buf[3];
229                     buf[0] = buf[1] = buf[2] = NULL;
230                     if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
231                         break;
232                     mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
233                 }
234                 p_sys->p_picture_to_destroy = p_pic;
235
236                 if ( p_sys->b_slice_i )
237                 {
238                     vout_SynchroNewPicture( p_sys->p_synchro,
239                         I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
240                     vout_SynchroDecode( p_sys->p_synchro );
241                     vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
242                 }
243             }
244
245 #ifdef PIC_FLAG_PTS
246             if( p_block->i_pts )
247             {
248                 mpeg2_pts( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts );
249
250 #else /* New interface */
251             if( p_block->i_pts || p_block->i_dts )
252             {
253                 mpeg2_tag_picture( p_sys->p_mpeg2dec,
254                                    (uint32_t)p_block->i_pts,
255                                    (uint32_t)p_block->i_dts );
256 #endif
257                 p_sys->i_previous_pts = p_sys->i_current_pts;
258                 p_sys->i_current_pts = p_block->i_pts;
259                 p_sys->i_previous_dts = p_sys->i_current_dts;
260                 p_sys->i_current_dts = p_block->i_dts;
261             }
262
263             p_sys->i_current_rate = p_block->i_rate;
264
265             mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
266                           p_block->p_buffer + p_block->i_buffer );
267
268             p_block->i_buffer = 0;
269             break;
270
271         case STATE_SEQUENCE:
272         {
273             /* Initialize video output */
274             uint8_t *buf[3];
275             buf[0] = buf[1] = buf[2] = NULL;
276
277             /* Check whether the input gave a particular aspect ratio */
278             if( p_dec->fmt_in.video.i_aspect )
279             {
280                 p_sys->i_aspect = p_dec->fmt_in.video.i_aspect;
281                 if( p_sys->i_aspect <= AR_221_1_PICTURE )
282                 switch( p_sys->i_aspect )
283                 {
284                 case AR_3_4_PICTURE:
285                     p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
286                     break;
287                 case AR_16_9_PICTURE:
288                     p_sys->i_aspect = VOUT_ASPECT_FACTOR * 16 / 9;
289                     break;
290                 case AR_221_1_PICTURE:
291                     p_sys->i_aspect = VOUT_ASPECT_FACTOR * 221 / 100;
292                     break;
293                 case AR_SQUARE_PICTURE:
294                     p_sys->i_aspect = VOUT_ASPECT_FACTOR *
295                                    p_sys->p_info->sequence->width /
296                                    p_sys->p_info->sequence->height;
297                     break;
298                 }
299             }
300             else
301             {
302                 /* Use the value provided in the MPEG sequence header */
303                 if( p_sys->p_info->sequence->pixel_height > 0 )
304                 {
305                     p_sys->i_aspect =
306                         ((uint64_t)p_sys->p_info->sequence->display_width) *
307                         p_sys->p_info->sequence->pixel_width *
308                         VOUT_ASPECT_FACTOR /
309                         p_sys->p_info->sequence->display_height /
310                         p_sys->p_info->sequence->pixel_height;
311                 }
312                 else
313                 {
314                     /* Invalid aspect, assume 4:3.
315                      * This shouldn't happen and if it does it is a bug
316                      * in libmpeg2 (likely triggered by an invalid stream) */
317                     p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
318                 }
319             }
320
321             msg_Dbg( p_dec, "%dx%d, aspect %d, %u.%03u fps",
322                      p_sys->p_info->sequence->width,
323                      p_sys->p_info->sequence->height, p_sys->i_aspect,
324                      (uint32_t)((uint64_t)1001000000 * 27 /
325                          p_sys->p_info->sequence->frame_period / 1001),
326                      (uint32_t)((uint64_t)1001000000 * 27 /
327                          p_sys->p_info->sequence->frame_period % 1001) );
328
329             mpeg2_custom_fbuf( p_sys->p_mpeg2dec, 1 );
330
331             /* Set the first 2 reference frames */
332             mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
333
334             if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
335             {
336                 block_Release( p_block );
337                 return NULL;
338             }
339
340             mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
341
342             /* This picture will never go through display_picture. */
343             p_pic->date = 0;
344
345             /* For some reason, libmpeg2 will put this pic twice in
346              * discard_picture. This can be considered a bug in libmpeg2. */
347             p_dec->pf_picture_link( p_dec, p_pic );
348
349             if( p_sys->p_synchro )
350             {
351                 vout_SynchroRelease( p_sys->p_synchro );
352             }
353             p_sys->p_synchro = vout_SynchroInit( p_dec,
354                 (uint32_t)((uint64_t)1001000000 * 27 /
355                 p_sys->p_info->sequence->frame_period) );
356             p_sys->b_after_sequence_header = 1;
357         }
358         break;
359
360         case STATE_PICTURE_2ND:
361             vout_SynchroNewPicture( p_sys->p_synchro,
362                 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
363                 p_sys->p_info->current_picture->nb_fields,
364                 0, 0, p_sys->i_current_rate );
365
366             if( p_sys->b_skip )
367             {
368                 vout_SynchroTrash( p_sys->p_synchro );
369             }
370             else
371             {
372                 vout_SynchroDecode( p_sys->p_synchro );
373             }
374             break;
375
376         case STATE_PICTURE:
377         {
378             uint8_t *buf[3];
379             mtime_t i_pts, i_dts;
380             buf[0] = buf[1] = buf[2] = NULL;
381
382             if ( p_sys->b_after_sequence_header &&
383                  ((p_sys->p_info->current_picture->flags &
384                        PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P) )
385             {
386                 /* Intra-slice refresh. Simulate a blank I picture. */
387                 msg_Dbg( p_dec, "intra-slice refresh stream" );
388                 vout_SynchroNewPicture( p_sys->p_synchro,
389                     I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
390                 vout_SynchroDecode( p_sys->p_synchro );
391                 vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
392                 p_sys->b_slice_i = 1;
393             }
394             p_sys->b_after_sequence_header = 0;
395
396 #ifdef PIC_FLAG_PTS
397             i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_PTS ?
398                 ( ( p_sys->p_info->current_picture->pts ==
399                     (uint32_t)p_sys->i_current_pts ) ?
400                   p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
401             i_dts = 0;
402
403             /* Hack to handle demuxers which only have DTS timestamps */
404             if( !i_pts && !p_block->i_pts && p_block->i_dts > 0 )
405             {
406                 if( p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ||
407                     (p_sys->p_info->current_picture->flags &
408                       PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
409                 {
410                     i_pts = p_block->i_dts;
411                 }
412             }
413             p_block->i_pts = p_block->i_dts = 0;
414             /* End hack */
415
416 #else /* New interface */
417
418             i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
419                 ( ( p_sys->p_info->current_picture->tag ==
420                     (uint32_t)p_sys->i_current_pts ) ?
421                   p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
422             i_dts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
423                 ( ( p_sys->p_info->current_picture->tag2 ==
424                     (uint32_t)p_sys->i_current_dts ) ?
425                   p_sys->i_current_dts : p_sys->i_previous_dts ) : 0;
426 #endif
427
428             vout_SynchroNewPicture( p_sys->p_synchro,
429                 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
430                 p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
431                 p_sys->i_current_rate );
432
433             if( !p_dec->b_pace_control &&
434                 !(p_sys->b_slice_i
435                    && ((p_sys->p_info->current_picture->flags
436                          & PIC_MASK_CODING_TYPE) == P_CODING_TYPE))
437                    && !vout_SynchroChoose( p_sys->p_synchro,
438                               p_sys->p_info->current_picture->flags
439                                 & PIC_MASK_CODING_TYPE,
440                               /*p_sys->p_vout->render_time*/ 0 /*FIXME*/ ) )
441             {
442                 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
443                 p_sys->b_skip = 1;
444                 vout_SynchroTrash( p_sys->p_synchro );
445                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
446             }
447             else
448             {
449                 mpeg2_skip( p_sys->p_mpeg2dec, 0 );
450                 p_sys->b_skip = 0;
451                 vout_SynchroDecode( p_sys->p_synchro );
452
453                 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
454                 {
455                     block_Release( p_block );
456                     return NULL;
457                 }
458
459                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
460             }
461         }
462         break;
463
464         case STATE_END:
465         case STATE_SLICE:
466             p_pic = NULL;
467             if( p_sys->p_info->display_fbuf
468                 && p_sys->p_info->display_fbuf->id )
469             {
470                 p_pic = (picture_t *)p_sys->p_info->display_fbuf->id;
471
472                 vout_SynchroEnd( p_sys->p_synchro,
473                             p_sys->p_info->display_picture->flags
474                              & PIC_MASK_CODING_TYPE,
475                             p_sys->b_garbage_pic );
476                 p_sys->b_garbage_pic = 0;
477
478                 if ( p_sys->p_picture_to_destroy != p_pic )
479                 {
480                     p_pic->date = vout_SynchroDate( p_sys->p_synchro );
481                 }
482                 else
483                 {
484                     p_sys->p_picture_to_destroy = NULL;
485                     p_pic->date = 0;
486                 }
487             }
488
489             if( p_sys->p_info->discard_fbuf &&
490                 p_sys->p_info->discard_fbuf->id )
491             {
492                 p_dec->pf_picture_unlink( p_dec,
493                                           p_sys->p_info->discard_fbuf->id );
494             }
495
496             /* For still frames */
497             if( state == STATE_END && p_pic ) p_pic->b_force = VLC_TRUE;
498
499             if( p_pic )
500             {
501                 /* Avoid frames with identical timestamps.
502                  * Especially needed for still frames in DVD menus. */
503                 if( p_sys->i_last_frame_pts == p_pic->date ) p_pic->date++;
504                 p_sys->i_last_frame_pts = p_pic->date;
505
506                 return p_pic;
507             }
508
509             break;
510
511         case STATE_INVALID:
512         {
513             uint8_t *buf[3];
514             buf[0] = buf[1] = buf[2] = NULL;
515
516             msg_Warn( p_dec, "invalid picture encountered" );
517             if ( ( p_sys->p_info->current_picture == NULL ) ||
518                ( ( p_sys->p_info->current_picture->flags &
519                    PIC_MASK_CODING_TYPE) != B_CODING_TYPE ) )
520             {
521                 if( p_sys->p_synchro ) vout_SynchroReset( p_sys->p_synchro );
522             }
523             mpeg2_skip( p_sys->p_mpeg2dec, 1 );
524             p_sys->b_skip = 1;
525
526             if( p_sys->p_info->current_fbuf &&
527                 p_sys->p_info->current_fbuf->id )
528             {
529                 p_sys->b_garbage_pic = 1;
530                 p_pic = p_sys->p_info->current_fbuf->id;
531             }
532             else if( !p_sys->p_info->sequence )
533             {
534                 break;
535             }
536             else
537             {
538                 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
539                     break;
540                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
541             }
542             p_sys->p_picture_to_destroy = p_pic;
543
544             memset( p_pic->p[0].p_pixels, 0,
545                     p_sys->p_info->sequence->width
546                      * p_sys->p_info->sequence->height );
547             memset( p_pic->p[1].p_pixels, 0x80,
548                     p_sys->p_info->sequence->width
549                      * p_sys->p_info->sequence->height / 4 );
550             memset( p_pic->p[2].p_pixels, 0x80,
551                     p_sys->p_info->sequence->width
552                      * p_sys->p_info->sequence->height / 4 );
553
554             if( p_sys->b_slice_i )
555             {
556                 vout_SynchroNewPicture( p_sys->p_synchro,
557                             I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
558                 vout_SynchroDecode( p_sys->p_synchro );
559                 vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
560             }
561             break;
562         }
563
564         default:
565             break;
566         }
567     }
568
569     /* Never reached */
570     return NULL;
571 }
572
573 /*****************************************************************************
574  * CloseDecoder: libmpeg2 decoder destruction
575  *****************************************************************************/
576 static void CloseDecoder( vlc_object_t *p_this )
577 {
578     decoder_t *p_dec = (decoder_t *)p_this;
579     decoder_sys_t *p_sys = p_dec->p_sys;
580
581     if( p_sys->p_synchro ) vout_SynchroRelease( p_sys->p_synchro );
582
583     if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
584
585     free( p_sys );
586 }
587
588 /*****************************************************************************
589  * GetNewPicture: Get a new picture from the vout and set the buf struct
590  *****************************************************************************/
591 static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
592 {
593     decoder_sys_t *p_sys = p_dec->p_sys;
594     picture_t *p_pic;
595
596     p_dec->fmt_out.video.i_width = p_sys->p_info->sequence->width;
597     p_dec->fmt_out.video.i_visible_width =
598         p_sys->p_info->sequence->picture_width;
599     p_dec->fmt_out.video.i_height = p_sys->p_info->sequence->height;
600     p_dec->fmt_out.video.i_visible_height =
601         p_sys->p_info->sequence->picture_height;
602     p_dec->fmt_out.video.i_aspect = p_sys->i_aspect;
603
604     if( p_sys->p_info->sequence->frame_period > 0 )
605     {
606         p_dec->fmt_out.video.i_frame_rate =
607             (uint32_t)( (uint64_t)1001000000 * 27 /
608                         p_sys->p_info->sequence->frame_period );
609         p_dec->fmt_out.video.i_frame_rate_base = 1001;
610     }
611
612     p_dec->fmt_out.i_codec =
613         ( p_sys->p_info->sequence->chroma_height <
614           p_sys->p_info->sequence->height ) ?
615         VLC_FOURCC('I','4','2','0') : VLC_FOURCC('I','4','2','2');
616
617     /* Get a new picture */
618     p_pic = p_dec->pf_vout_buffer_new( p_dec );
619
620     if( p_pic == NULL ) return NULL;
621
622     p_pic->b_progressive = p_sys->p_info->current_picture != NULL ?
623         p_sys->p_info->current_picture->flags & PIC_FLAG_PROGRESSIVE_FRAME : 1;
624     p_pic->b_top_field_first = p_sys->p_info->current_picture != NULL ?
625         p_sys->p_info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST : 1;
626     p_pic->i_nb_fields = p_sys->p_info->current_picture != NULL ?
627         p_sys->p_info->current_picture->nb_fields : 2;
628
629     p_dec->pf_picture_link( p_dec, p_pic );
630
631     pp_buf[0] = p_pic->p[0].p_pixels;
632     pp_buf[1] = p_pic->p[1].p_pixels;
633     pp_buf[2] = p_pic->p[2].p_pixels;
634
635     return p_pic;
636 }