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