Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

libmpeg2.c

00001 /*****************************************************************************
00002  * libmpeg2.c: mpeg2 video decoder module making use of libmpeg2.
00003  *****************************************************************************
00004  * Copyright (C) 1999-2001 the VideoLAN team
00005  * $Id: libmpeg2.c 13118 2005-11-02 23:32:56Z gbazin $
00006  *
00007  * Authors: Gildas Bazin <[email protected]>
00008  *          Christophe Massiot <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <vlc/vlc.h>
00029 #include <vlc/vout.h>
00030 #include <vlc/decoder.h>
00031 
00032 #include <mpeg2dec/mpeg2.h>
00033 
00034 #include "vout_synchro.h"
00035 
00036 /* Aspect ratio (ISO/IEC 13818-2 section 6.3.3, table 6-3) */
00037 #define AR_SQUARE_PICTURE       1                           /* square pixels */
00038 #define AR_4_3_PICTURE          2                        /* 4:3 picture (TV) */
00039 #define AR_16_9_PICTURE         3              /* 16:9 picture (wide screen) */
00040 #define AR_221_1_PICTURE        4                  /* 2.21:1 picture (movie) */
00041 
00042 /*****************************************************************************
00043  * decoder_sys_t : libmpeg2 decoder descriptor
00044  *****************************************************************************/
00045 struct decoder_sys_t
00046 {
00047     /*
00048      * libmpeg2 properties
00049      */
00050     mpeg2dec_t          *p_mpeg2dec;
00051     const mpeg2_info_t  *p_info;
00052     vlc_bool_t          b_skip;
00053 
00054     /*
00055      * Input properties
00056      */
00057     mtime_t          i_previous_pts;
00058     mtime_t          i_current_pts;
00059     mtime_t          i_previous_dts;
00060     mtime_t          i_current_dts;
00061     int              i_current_rate;
00062     picture_t *      p_picture_to_destroy;
00063     vlc_bool_t       b_garbage_pic;
00064     vlc_bool_t       b_after_sequence_header; /* is it the next frame after
00065                                                * the sequence header ?    */
00066     vlc_bool_t       b_slice_i;             /* intra-slice refresh stream */
00067 
00068     vlc_bool_t      b_preroll;
00069 
00070     /*
00071      * Output properties
00072      */
00073     vout_synchro_t *p_synchro;
00074     int            i_aspect;
00075     int            i_sar_num;
00076     int            i_sar_den;
00077     mtime_t        i_last_frame_pts;
00078 
00079 };
00080 
00081 /*****************************************************************************
00082  * Local prototypes
00083  *****************************************************************************/
00084 static int  OpenDecoder( vlc_object_t * );
00085 static void CloseDecoder( vlc_object_t * );
00086 
00087 static picture_t *DecodeBlock( decoder_t *, block_t ** );
00088 
00089 static picture_t *GetNewPicture( decoder_t *, uint8_t ** );
00090 static void GetAR( decoder_t *p_dec );
00091 
00092 /*****************************************************************************
00093  * Module descriptor
00094  *****************************************************************************/
00095 vlc_module_begin();
00096     set_description( _("MPEG I/II video decoder (using libmpeg2)") );
00097     set_capability( "decoder", 150 );
00098     set_category( CAT_INPUT );
00099     set_subcategory( SUBCAT_INPUT_VCODEC );
00100     set_callbacks( OpenDecoder, CloseDecoder );
00101     add_shortcut( "libmpeg2" );
00102 vlc_module_end();
00103 
00104 /*****************************************************************************
00105  * OpenDecoder: probe the decoder and return score
00106  *****************************************************************************/
00107 static int OpenDecoder( vlc_object_t *p_this )
00108 {
00109     decoder_t *p_dec = (decoder_t*)p_this;
00110     decoder_sys_t *p_sys;
00111     uint32_t i_accel = 0;
00112 
00113     if( p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','v') &&
00114         p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','1') &&
00115         /* Pinnacle hardware-mpeg1 */
00116         p_dec->fmt_in.i_codec != VLC_FOURCC('P','I','M','1') &&
00117         /* ATI Video */
00118         p_dec->fmt_in.i_codec != VLC_FOURCC('V','C','R','2') &&
00119         p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','2') &&
00120         p_dec->fmt_in.i_codec != VLC_FOURCC('h','d','v','2') )
00121     {
00122         return VLC_EGENERIC;
00123     }
00124 
00125     /* Allocate the memory needed to store the decoder's structure */
00126     if( ( p_dec->p_sys = p_sys =
00127           (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
00128     {
00129         msg_Err( p_dec, "out of memory" );
00130         return VLC_EGENERIC;
00131     }
00132 
00133     /* Initialize the thread properties */
00134     memset( p_sys, 0, sizeof(decoder_sys_t) );
00135     p_sys->p_mpeg2dec = NULL;
00136     p_sys->p_synchro  = NULL;
00137     p_sys->p_info     = NULL;
00138     p_sys->i_current_pts  = 0;
00139     p_sys->i_previous_pts = 0;
00140     p_sys->i_current_dts  = 0;
00141     p_sys->i_previous_dts = 0;
00142     p_sys->p_picture_to_destroy = NULL;
00143     p_sys->b_garbage_pic = 0;
00144     p_sys->b_slice_i  = 0;
00145     p_sys->b_skip     = 0;
00146     p_sys->b_preroll = VLC_FALSE;
00147 
00148 #if defined( __i386__ ) || defined( __x86_64__ )
00149     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMX )
00150     {
00151         i_accel |= MPEG2_ACCEL_X86_MMX;
00152     }
00153 
00154     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_3DNOW )
00155     {
00156         i_accel |= MPEG2_ACCEL_X86_3DNOW;
00157     }
00158 
00159     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMXEXT )
00160     {
00161         i_accel |= MPEG2_ACCEL_X86_MMXEXT;
00162     }
00163 
00164 #elif defined( __powerpc__ ) || defined( SYS_DARWIN )
00165     if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC )
00166     {
00167         i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
00168     }
00169 
00170 #else
00171     /* If we do not know this CPU, trust libmpeg2's feature detection */
00172     i_accel = MPEG2_ACCEL_DETECT;
00173 
00174 #endif
00175 
00176     /* Set CPU acceleration features */
00177     mpeg2_accel( i_accel );
00178 
00179     /* Initialize decoder */
00180     p_sys->p_mpeg2dec = mpeg2_init();
00181     if( p_sys->p_mpeg2dec == NULL)
00182     {
00183         msg_Err( p_dec, "mpeg2_init() failed" );
00184         free( p_sys );
00185         return VLC_EGENERIC;
00186     }
00187 
00188     p_sys->p_info = mpeg2_info( p_sys->p_mpeg2dec );
00189 
00190     p_dec->pf_decode_video = DecodeBlock;
00191 
00192     return VLC_SUCCESS;
00193 }
00194 
00195 /*****************************************************************************
00196  * RunDecoder: the libmpeg2 decoder
00197  *****************************************************************************/
00198 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
00199 {
00200     decoder_sys_t   *p_sys = p_dec->p_sys;
00201     mpeg2_state_t   state;
00202     picture_t       *p_pic;
00203 
00204     block_t *p_block;
00205 
00206     if( !pp_block || !*pp_block ) return NULL;
00207 
00208     p_block = *pp_block;
00209 
00210     while( 1 )
00211     {
00212         state = mpeg2_parse( p_sys->p_mpeg2dec );
00213 
00214         switch( state )
00215         {
00216         case STATE_BUFFER:
00217             if( !p_block->i_buffer )
00218             {
00219                 block_Release( p_block );
00220                 return NULL;
00221             }
00222 
00223             if( (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
00224                                       | BLOCK_FLAG_CORRUPTED)) &&
00225                 p_sys->p_synchro &&
00226                 p_sys->p_info->sequence &&
00227                 p_sys->p_info->sequence->width != (unsigned)-1 )
00228             {
00229                 vout_SynchroReset( p_sys->p_synchro );
00230                 if( p_sys->p_info->current_fbuf != NULL
00231                     && p_sys->p_info->current_fbuf->id != NULL )
00232                 {
00233                     p_sys->b_garbage_pic = 1;
00234                     p_pic = p_sys->p_info->current_fbuf->id;
00235                 }
00236                 else
00237                 {
00238                     uint8_t *buf[3];
00239                     buf[0] = buf[1] = buf[2] = NULL;
00240                     if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
00241                         break;
00242                     mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
00243                 }
00244                 p_sys->p_picture_to_destroy = p_pic;
00245 
00246                 if ( p_sys->b_slice_i )
00247                 {
00248                     vout_SynchroNewPicture( p_sys->p_synchro,
00249                         I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
00250                         p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
00251                     vout_SynchroDecode( p_sys->p_synchro );
00252                     vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
00253                 }
00254             }
00255 
00256             if( p_block->i_flags & BLOCK_FLAG_PREROLL )
00257             {
00258                 p_sys->b_preroll = VLC_TRUE;
00259             }
00260             else if( p_sys->b_preroll )
00261             {
00262                 p_sys->b_preroll = VLC_FALSE;
00263                 /* Reset synchro */
00264                 vout_SynchroReset( p_sys->p_synchro );
00265             }
00266 
00267 #ifdef PIC_FLAG_PTS
00268             if( p_block->i_pts )
00269             {
00270                 mpeg2_pts( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts );
00271 
00272 #else /* New interface */
00273             if( p_block->i_pts || p_block->i_dts )
00274             {
00275                 mpeg2_tag_picture( p_sys->p_mpeg2dec,
00276                                    (uint32_t)p_block->i_pts,
00277                                    (uint32_t)p_block->i_dts );
00278 #endif
00279                 p_sys->i_previous_pts = p_sys->i_current_pts;
00280                 p_sys->i_current_pts = p_block->i_pts;
00281                 p_sys->i_previous_dts = p_sys->i_current_dts;
00282                 p_sys->i_current_dts = p_block->i_dts;
00283             }
00284 
00285             p_sys->i_current_rate = p_block->i_rate;
00286 
00287             mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
00288                           p_block->p_buffer + p_block->i_buffer );
00289 
00290             p_block->i_buffer = 0;
00291             break;
00292 
00293 #ifdef STATE_SEQUENCE_MODIFIED
00294         case STATE_SEQUENCE_MODIFIED:
00295             GetAR( p_dec );
00296             break;
00297 #endif
00298 
00299         case STATE_SEQUENCE:
00300         {
00301             /* Initialize video output */
00302             uint8_t *buf[3];
00303             buf[0] = buf[1] = buf[2] = NULL;
00304 
00305             GetAR( p_dec );
00306 
00307             mpeg2_custom_fbuf( p_sys->p_mpeg2dec, 1 );
00308 
00309             /* Set the first 2 reference frames */
00310             mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
00311 
00312             if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
00313             {
00314                 block_Release( p_block );
00315                 return NULL;
00316             }
00317 
00318             mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
00319 
00320             /* This picture will never go through display_picture. */
00321             p_pic->date = 0;
00322 
00323             /* For some reason, libmpeg2 will put this pic twice in
00324              * discard_picture. This can be considered a bug in libmpeg2. */
00325             p_dec->pf_picture_link( p_dec, p_pic );
00326 
00327             if( p_sys->p_synchro )
00328             {
00329                 vout_SynchroRelease( p_sys->p_synchro );
00330             }
00331             p_sys->p_synchro = vout_SynchroInit( p_dec,
00332                 (uint32_t)((uint64_t)1001000000 * 27 /
00333                 p_sys->p_info->sequence->frame_period) );
00334             p_sys->b_after_sequence_header = 1;
00335         }
00336         break;
00337 
00338         case STATE_PICTURE_2ND:
00339             vout_SynchroNewPicture( p_sys->p_synchro,
00340                 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
00341                 p_sys->p_info->current_picture->nb_fields,
00342                 0, 0, p_sys->i_current_rate,
00343                 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
00344 
00345             if( p_sys->b_skip )
00346             {
00347                 vout_SynchroTrash( p_sys->p_synchro );
00348             }
00349             else
00350             {
00351                 vout_SynchroDecode( p_sys->p_synchro );
00352             }
00353             break;
00354 
00355         case STATE_PICTURE:
00356         {
00357             uint8_t *buf[3];
00358             mtime_t i_pts, i_dts;
00359             buf[0] = buf[1] = buf[2] = NULL;
00360 
00361             if ( p_sys->b_after_sequence_header &&
00362                  ((p_sys->p_info->current_picture->flags &
00363                        PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P) )
00364             {
00365                 /* Intra-slice refresh. Simulate a blank I picture. */
00366                 msg_Dbg( p_dec, "intra-slice refresh stream" );
00367                 vout_SynchroNewPicture( p_sys->p_synchro,
00368                     I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
00369                     p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
00370                 vout_SynchroDecode( p_sys->p_synchro );
00371                 vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
00372                 p_sys->b_slice_i = 1;
00373             }
00374             p_sys->b_after_sequence_header = 0;
00375 
00376 #ifdef PIC_FLAG_PTS
00377             i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_PTS ?
00378                 ( ( p_sys->p_info->current_picture->pts ==
00379                     (uint32_t)p_sys->i_current_pts ) ?
00380                   p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
00381             i_dts = 0;
00382 
00383             /* Hack to handle demuxers which only have DTS timestamps */
00384             if( !i_pts && !p_block->i_pts && p_block->i_dts > 0 )
00385             {
00386                 if( p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ||
00387                     (p_sys->p_info->current_picture->flags &
00388                       PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
00389                 {
00390                     i_pts = p_block->i_dts;
00391                 }
00392             }
00393             p_block->i_pts = p_block->i_dts = 0;
00394             /* End hack */
00395 
00396 #else /* New interface */
00397 
00398             i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
00399                 ( ( p_sys->p_info->current_picture->tag ==
00400                     (uint32_t)p_sys->i_current_pts ) ?
00401                   p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
00402             i_dts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
00403                 ( ( p_sys->p_info->current_picture->tag2 ==
00404                     (uint32_t)p_sys->i_current_dts ) ?
00405                   p_sys->i_current_dts : p_sys->i_previous_dts ) : 0;
00406 #endif
00407 
00408             vout_SynchroNewPicture( p_sys->p_synchro,
00409                 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
00410                 p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
00411                 p_sys->i_current_rate,
00412                 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
00413 
00414             if( !p_dec->b_pace_control && !p_sys->b_preroll &&
00415                 !(p_sys->b_slice_i
00416                    && ((p_sys->p_info->current_picture->flags
00417                          & PIC_MASK_CODING_TYPE) == P_CODING_TYPE))
00418                    && !vout_SynchroChoose( p_sys->p_synchro,
00419                               p_sys->p_info->current_picture->flags
00420                                 & PIC_MASK_CODING_TYPE,
00421                               /*p_sys->p_vout->render_time*/ 0 /*FIXME*/,
00422                               p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ) )
00423             {
00424                 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
00425                 p_sys->b_skip = 1;
00426                 vout_SynchroTrash( p_sys->p_synchro );
00427                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
00428             }
00429             else
00430             {
00431                 mpeg2_skip( p_sys->p_mpeg2dec, 0 );
00432                 p_sys->b_skip = 0;
00433                 vout_SynchroDecode( p_sys->p_synchro );
00434 
00435                 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
00436                 {
00437                     block_Release( p_block );
00438                     return NULL;
00439                 }
00440 
00441                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
00442             }
00443         }
00444         break;
00445 
00446         case STATE_END:
00447         case STATE_SLICE:
00448             p_pic = NULL;
00449             if( p_sys->p_info->display_fbuf
00450                 && p_sys->p_info->display_fbuf->id )
00451             {
00452                 p_pic = (picture_t *)p_sys->p_info->display_fbuf->id;
00453 
00454                 vout_SynchroEnd( p_sys->p_synchro,
00455                             p_sys->p_info->display_picture->flags
00456                              & PIC_MASK_CODING_TYPE,
00457                             p_sys->b_garbage_pic );
00458                 p_sys->b_garbage_pic = 0;
00459 
00460                 if ( p_sys->p_picture_to_destroy != p_pic )
00461                 {
00462                     p_pic->date = vout_SynchroDate( p_sys->p_synchro );
00463                 }
00464                 else
00465                 {
00466                     p_sys->p_picture_to_destroy = NULL;
00467                     p_pic->date = 0;
00468                 }
00469             }
00470 
00471             if( p_sys->p_info->discard_fbuf &&
00472                 p_sys->p_info->discard_fbuf->id )
00473             {
00474                 p_dec->pf_picture_unlink( p_dec,
00475                                           p_sys->p_info->discard_fbuf->id );
00476             }
00477 
00478             /* For still frames */
00479             if( state == STATE_END && p_pic ) p_pic->b_force = VLC_TRUE;
00480 
00481             if( p_pic )
00482             {
00483                 /* Avoid frames with identical timestamps.
00484                  * Especially needed for still frames in DVD menus. */
00485                 if( p_sys->i_last_frame_pts == p_pic->date ) p_pic->date++;
00486                 p_sys->i_last_frame_pts = p_pic->date;
00487 
00488                 return p_pic;
00489             }
00490 
00491             break;
00492 
00493         case STATE_INVALID:
00494         {
00495             uint8_t *buf[3];
00496             buf[0] = buf[1] = buf[2] = NULL;
00497 
00498             msg_Warn( p_dec, "invalid picture encountered" );
00499             if ( ( p_sys->p_info->current_picture == NULL ) ||
00500                ( ( p_sys->p_info->current_picture->flags &
00501                    PIC_MASK_CODING_TYPE) != B_CODING_TYPE ) )
00502             {
00503                 if( p_sys->p_synchro ) vout_SynchroReset( p_sys->p_synchro );
00504             }
00505             mpeg2_skip( p_sys->p_mpeg2dec, 1 );
00506             p_sys->b_skip = 1;
00507 
00508             if( p_sys->p_info->current_fbuf &&
00509                 p_sys->p_info->current_fbuf->id )
00510             {
00511                 p_sys->b_garbage_pic = 1;
00512                 p_pic = p_sys->p_info->current_fbuf->id;
00513             }
00514             else if( !p_sys->p_info->sequence )
00515             {
00516                 break;
00517             }
00518             else
00519             {
00520                 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
00521                     break;
00522                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
00523             }
00524             p_sys->p_picture_to_destroy = p_pic;
00525 
00526             memset( p_pic->p[0].p_pixels, 0,
00527                     p_sys->p_info->sequence->width
00528                      * p_sys->p_info->sequence->height );
00529             memset( p_pic->p[1].p_pixels, 0x80,
00530                     p_sys->p_info->sequence->width
00531                      * p_sys->p_info->sequence->height / 4 );
00532             memset( p_pic->p[2].p_pixels, 0x80,
00533                     p_sys->p_info->sequence->width
00534                      * p_sys->p_info->sequence->height / 4 );
00535 
00536             if( p_sys->b_slice_i )
00537             {
00538                 vout_SynchroNewPicture( p_sys->p_synchro,
00539                         I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
00540                         p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
00541                 vout_SynchroDecode( p_sys->p_synchro );
00542                 vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
00543             }
00544             break;
00545         }
00546 
00547         default:
00548             break;
00549         }
00550     }
00551 
00552     /* Never reached */
00553     return NULL;
00554 }
00555 
00556 /*****************************************************************************
00557  * CloseDecoder: libmpeg2 decoder destruction
00558  *****************************************************************************/
00559 static void CloseDecoder( vlc_object_t *p_this )
00560 {
00561     decoder_t *p_dec = (decoder_t *)p_this;
00562     decoder_sys_t *p_sys = p_dec->p_sys;
00563 
00564     if( p_sys->p_synchro ) vout_SynchroRelease( p_sys->p_synchro );
00565 
00566     if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
00567 
00568     free( p_sys );
00569 }
00570 
00571 /*****************************************************************************
00572  * GetNewPicture: Get a new picture from the vout and set the buf struct
00573  *****************************************************************************/
00574 static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
00575 {
00576     decoder_sys_t *p_sys = p_dec->p_sys;
00577     picture_t *p_pic;
00578 
00579     p_dec->fmt_out.video.i_width = p_sys->p_info->sequence->width;
00580     p_dec->fmt_out.video.i_visible_width =
00581         p_sys->p_info->sequence->picture_width;
00582     p_dec->fmt_out.video.i_height = p_sys->p_info->sequence->height;
00583     p_dec->fmt_out.video.i_visible_height =
00584         p_sys->p_info->sequence->picture_height;
00585     p_dec->fmt_out.video.i_aspect = p_sys->i_aspect;
00586     p_dec->fmt_out.video.i_sar_num = p_sys->i_sar_num;
00587     p_dec->fmt_out.video.i_sar_den = p_sys->i_sar_den;
00588 
00589     if( p_sys->p_info->sequence->frame_period > 0 )
00590     {
00591         p_dec->fmt_out.video.i_frame_rate =
00592             (uint32_t)( (uint64_t)1001000000 * 27 /
00593                         p_sys->p_info->sequence->frame_period );
00594         p_dec->fmt_out.video.i_frame_rate_base = 1001;
00595     }
00596 
00597     p_dec->fmt_out.i_codec =
00598         ( p_sys->p_info->sequence->chroma_height <
00599           p_sys->p_info->sequence->height ) ?
00600         VLC_FOURCC('I','4','2','0') : VLC_FOURCC('I','4','2','2');
00601 
00602     /* Get a new picture */
00603     p_pic = p_dec->pf_vout_buffer_new( p_dec );
00604 
00605     if( p_pic == NULL ) return NULL;
00606 
00607     p_pic->b_progressive = p_sys->p_info->current_picture != NULL ?
00608         p_sys->p_info->current_picture->flags & PIC_FLAG_PROGRESSIVE_FRAME : 1;
00609     p_pic->b_top_field_first = p_sys->p_info->current_picture != NULL ?
00610         p_sys->p_info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST : 1;
00611     p_pic->i_nb_fields = p_sys->p_info->current_picture != NULL ?
00612         p_sys->p_info->current_picture->nb_fields : 2;
00613 
00614     p_dec->pf_picture_link( p_dec, p_pic );
00615 
00616     pp_buf[0] = p_pic->p[0].p_pixels;
00617     pp_buf[1] = p_pic->p[1].p_pixels;
00618     pp_buf[2] = p_pic->p[2].p_pixels;
00619 
00620     return p_pic;
00621 }
00622 
00623 /*****************************************************************************
00624  * GetAR: Get aspect ratio
00625  *****************************************************************************/
00626 static void GetAR( decoder_t *p_dec )
00627 {
00628     decoder_sys_t *p_sys = p_dec->p_sys;
00629 
00630     /* Check whether the input gave a particular aspect ratio */
00631     if( p_dec->fmt_in.video.i_aspect )
00632     {
00633         p_sys->i_aspect = p_dec->fmt_in.video.i_aspect;
00634         if( p_sys->i_aspect <= AR_221_1_PICTURE )
00635         switch( p_sys->i_aspect )
00636         {
00637         case AR_4_3_PICTURE:
00638             p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
00639             p_sys->i_sar_num = p_sys->p_info->sequence->picture_height * 4;
00640             p_sys->i_sar_den = p_sys->p_info->sequence->picture_width * 3;
00641             break;
00642         case AR_16_9_PICTURE:
00643             p_sys->i_aspect = VOUT_ASPECT_FACTOR * 16 / 9;
00644             p_sys->i_sar_num = p_sys->p_info->sequence->picture_height * 16;
00645             p_sys->i_sar_den = p_sys->p_info->sequence->picture_width * 9;
00646             break;
00647         case AR_221_1_PICTURE:
00648             p_sys->i_aspect = VOUT_ASPECT_FACTOR * 221 / 100;
00649             p_sys->i_sar_num = p_sys->p_info->sequence->picture_height * 221;
00650             p_sys->i_sar_den = p_sys->p_info->sequence->picture_width * 100;
00651             break;
00652         case AR_SQUARE_PICTURE:
00653             p_sys->i_aspect = VOUT_ASPECT_FACTOR *
00654                            p_sys->p_info->sequence->picture_width /
00655                            p_sys->p_info->sequence->picture_height;
00656             p_sys->i_sar_num = p_sys->i_sar_den = 1;
00657             break;
00658         }
00659     }
00660     else
00661     {
00662         /* Use the value provided in the MPEG sequence header */
00663         if( p_sys->p_info->sequence->pixel_height > 0 )
00664         {
00665             p_sys->i_aspect =
00666                 ((uint64_t)p_sys->p_info->sequence->picture_width) *
00667                 p_sys->p_info->sequence->pixel_width *
00668                 VOUT_ASPECT_FACTOR /
00669                 p_sys->p_info->sequence->picture_height /
00670                 p_sys->p_info->sequence->pixel_height;
00671             p_sys->i_sar_num = p_sys->p_info->sequence->pixel_width;
00672             p_sys->i_sar_den = p_sys->p_info->sequence->pixel_height;
00673         }
00674         else
00675         {
00676             /* Invalid aspect, assume 4:3.
00677              * This shouldn't happen and if it does it is a bug
00678              * in libmpeg2 (likely triggered by an invalid stream) */
00679             p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
00680             p_sys->i_sar_num = p_sys->p_info->sequence->picture_height * 4;
00681             p_sys->i_sar_den = p_sys->p_info->sequence->picture_width * 3;
00682         }
00683     }
00684 
00685     msg_Dbg( p_dec, "%dx%d (display %d,%d), aspect %d, sar %i:%i, %u.%03u fps",
00686              p_sys->p_info->sequence->picture_width,
00687              p_sys->p_info->sequence->picture_height,
00688              p_sys->p_info->sequence->display_width,
00689              p_sys->p_info->sequence->display_height,
00690              p_sys->i_aspect, p_sys->i_sar_num, p_sys->i_sar_den,
00691              (uint32_t)((uint64_t)1001000000 * 27 /
00692                  p_sys->p_info->sequence->frame_period / 1001),
00693              (uint32_t)((uint64_t)1001000000 * 27 /
00694                  p_sys->p_info->sequence->frame_period % 1001) );
00695 }

Generated on Tue Dec 20 10:14:29 2005 for vlc-0.8.4a by  doxygen 1.4.2