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

h264.c

00001 /*****************************************************************************
00002  * h264.c: h264/avc video packetizer
00003  *****************************************************************************
00004  * Copyright (C) 2001, 2002 the VideoLAN team
00005  * $Id: h264.c 13660 2005-12-10 15:36:07Z gbazin $
00006  *
00007  * Authors: Laurent Aimar <[email protected]>
00008  *          Eric Petit <[email protected]>
00009  *          Gildas Bazin <[email protected]>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027  * Preamble
00028  *****************************************************************************/
00029 #include <stdlib.h>                                      /* malloc(), free() */
00030 
00031 #include <vlc/vlc.h>
00032 #include <vlc/decoder.h>
00033 #include <vlc/sout.h>
00034 
00035 #include "vlc_block_helper.h"
00036 #include "vlc_bits.h"
00037 
00038 /*****************************************************************************
00039  * Module descriptor
00040  *****************************************************************************/
00041 static int  Open ( vlc_object_t * );
00042 static void Close( vlc_object_t * );
00043 
00044 vlc_module_begin();
00045     set_category( CAT_SOUT );
00046     set_subcategory( SUBCAT_SOUT_PACKETIZER );
00047     set_description( _("H264 video packetizer") );
00048     set_capability( "packetizer", 50 );
00049     set_callbacks( Open, Close );
00050 vlc_module_end();
00051 
00052 
00053 /****************************************************************************
00054  * Local prototypes
00055  ****************************************************************************/
00056 static block_t *Packetize( decoder_t *, block_t ** );
00057 static block_t *PacketizeAVC1( decoder_t *, block_t ** );
00058 
00059 struct decoder_sys_t
00060 {
00061     block_bytestream_t bytestream;
00062 
00063     int     i_state;
00064     int     i_offset;
00065     uint8_t startcode[4];
00066 
00067     vlc_bool_t b_slice;
00068     block_t    *p_frame;
00069 
00070     vlc_bool_t   b_sps;
00071     vlc_bool_t   b_pps;
00072 
00073     /* avcC data */
00074     int i_avcC_length_size;
00075     block_t *p_sps;
00076     block_t *p_pps;
00077 
00078     /* Useful values of the Sequence Parameter Set */
00079     int i_log2_max_frame_num;
00080     int b_frame_mbs_only;
00081 
00082     /* Useful values of the Slice Header */
00083     int i_nal_type;
00084     int i_nal_ref_idc;
00085     int i_idr_pic_id;
00086     int i_frame_num;
00087 };
00088 
00089 enum
00090 {
00091     STATE_NOSYNC,
00092     STATE_NEXT_SYNC,
00093 };
00094 
00095 enum nal_unit_type_e
00096 {
00097     NAL_UNKNOWN = 0,
00098     NAL_SLICE   = 1,
00099     NAL_SLICE_DPA   = 2,
00100     NAL_SLICE_DPB   = 3,
00101     NAL_SLICE_DPC   = 4,
00102     NAL_SLICE_IDR   = 5,    /* ref_idc != 0 */
00103     NAL_SEI         = 6,    /* ref_idc == 0 */
00104     NAL_SPS         = 7,
00105     NAL_PPS         = 8,
00106     NAL_AU_DELIMITER= 9
00107     /* ref_idc == 0 for 6,9,10,11,12 */
00108 };
00109 
00110 enum nal_priority_e
00111 {
00112     NAL_PRIORITY_DISPOSABLE = 0,
00113     NAL_PRIORITY_LOW        = 1,
00114     NAL_PRIORITY_HIGH       = 2,
00115     NAL_PRIORITY_HIGHEST    = 3,
00116 };
00117 
00118 static block_t *ParseNALBlock( decoder_t *, block_t * );
00119 
00120 static block_t *nal_get_annexeb( decoder_t *, uint8_t *p, int );
00121 
00122 /*****************************************************************************
00123  * Open: probe the packetizer and return score
00124  *****************************************************************************/
00125 static int Open( vlc_object_t *p_this )
00126 {
00127     decoder_t     *p_dec = (decoder_t*)p_this;
00128     decoder_sys_t *p_sys;
00129 
00130     if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'h', '2', '6', '4') &&
00131         p_dec->fmt_in.i_codec != VLC_FOURCC( 'H', '2', '6', '4') &&
00132         p_dec->fmt_in.i_codec != VLC_FOURCC( 'V', 'S', 'S', 'H') &&
00133         p_dec->fmt_in.i_codec != VLC_FOURCC( 'v', 's', 's', 'h') &&
00134         ( p_dec->fmt_in.i_codec != VLC_FOURCC( 'a', 'v', 'c', '1') ||
00135           p_dec->fmt_in.i_extra < 7 ) )
00136     {
00137         return VLC_EGENERIC;
00138     }
00139 
00140     /* Allocate the memory needed to store the decoder's structure */
00141     if( ( p_dec->p_sys = p_sys = malloc( sizeof(decoder_sys_t) ) ) == NULL )
00142     {
00143         msg_Err( p_dec, "out of memory" );
00144         return VLC_EGENERIC;
00145     }
00146     p_sys->i_state = STATE_NOSYNC;
00147     p_sys->i_offset = 0;
00148     p_sys->startcode[0] = 0;
00149     p_sys->startcode[1] = 0;
00150     p_sys->startcode[2] = 0;
00151     p_sys->startcode[3] = 1;
00152     p_sys->bytestream = block_BytestreamInit( p_dec );
00153     p_sys->b_slice = VLC_FALSE;
00154     p_sys->p_frame = NULL;
00155     p_sys->b_sps   = VLC_FALSE;
00156     p_sys->b_pps   = VLC_FALSE;
00157     p_sys->p_sps   = 0;
00158     p_sys->p_pps   = 0;
00159 
00160     p_sys->i_nal_type = -1;
00161     p_sys->i_nal_ref_idc = -1;
00162     p_sys->i_idr_pic_id = -1;
00163     p_sys->i_frame_num = -1;
00164 
00165     /* Setup properties */
00166     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
00167     p_dec->fmt_out.i_codec = VLC_FOURCC( 'h', '2', '6', '4' );
00168     /* FIXME: FFMPEG isn't happy at all if you leave this */
00169     if( p_dec->fmt_out.i_extra ) free( p_dec->fmt_out.p_extra );
00170     p_dec->fmt_out.i_extra = 0; p_dec->fmt_out.p_extra = 0;
00171 
00172     if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'v', 'c', '1' ) )
00173     {
00174         uint8_t *p = &((uint8_t*)p_dec->fmt_in.p_extra)[4];
00175         int i_sps, i_pps;
00176         int i;
00177 
00178         /* Parse avcC */
00179         p_sys->i_avcC_length_size = 1 + ((*p++)&0x03);
00180 
00181         /* Read SPS */
00182         i_sps = (*p++)&0x1f;
00183 
00184         for( i = 0; i < i_sps; i++ )
00185         {
00186             int i_length = GetWBE( p );
00187             block_t *p_sps = nal_get_annexeb( p_dec, p + 2, i_length );
00188 
00189             p_sys->p_sps = block_Duplicate( p_sps );
00190             p_sps->i_pts = p_sps->i_dts = mdate();
00191             ParseNALBlock( p_dec, p_sps );
00192             p += 2 + i_length;
00193         }
00194         /* Read PPS */
00195         i_pps = *p++;
00196         for( i = 0; i < i_pps; i++ )
00197         {
00198             int i_length = GetWBE( p );
00199             block_t *p_pps = nal_get_annexeb( p_dec, p + 2, i_length );
00200 
00201             p_sys->p_pps = block_Duplicate( p_pps );
00202             p_pps->i_pts = p_pps->i_dts = mdate();
00203             ParseNALBlock( p_dec, p_pps );
00204             p += 2 + i_length;
00205         }
00206         msg_Dbg( p_dec, "avcC length size=%d sps=%d pps=%d",
00207                  p_sys->i_avcC_length_size, i_sps, i_pps );
00208 
00209         /* Set callback */
00210         p_dec->pf_packetize = PacketizeAVC1;
00211     }
00212     else
00213     {
00214         /* Set callback */
00215         p_dec->pf_packetize = Packetize;
00216 
00217         /* */
00218         if( p_dec->fmt_in.i_extra > 0 )
00219         {
00220             block_t *p_init = block_New( p_dec, p_dec->fmt_in.i_extra );
00221             block_t *p_pic;
00222 
00223             memcpy( p_init->p_buffer, p_dec->fmt_in.p_extra,
00224                     p_dec->fmt_in.i_extra );
00225 
00226             while( ( p_pic = Packetize( p_dec, &p_init ) ) )
00227             {
00228                 /* Should not occur because we should only receive SPS/PPS */
00229                 block_Release( p_pic );
00230             }
00231         }
00232     }
00233 
00234     return VLC_SUCCESS;
00235 }
00236 
00237 /*****************************************************************************
00238  * Close: clean up the packetizer
00239  *****************************************************************************/
00240 static void Close( vlc_object_t *p_this )
00241 {
00242     decoder_t *p_dec = (decoder_t*)p_this;
00243     decoder_sys_t *p_sys = p_dec->p_sys;
00244 
00245     if( p_sys->p_frame ) block_ChainRelease( p_sys->p_frame );
00246     if( p_sys->p_sps ) block_Release( p_sys->p_sps );
00247     if( p_sys->p_pps ) block_Release( p_sys->p_pps );
00248     block_BytestreamRelease( &p_sys->bytestream );
00249     free( p_sys );
00250 }
00251 
00252 /****************************************************************************
00253  * Packetize: the whole thing
00254  ****************************************************************************/
00255 static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
00256 {
00257     decoder_sys_t *p_sys = p_dec->p_sys;
00258     block_t       *p_pic;
00259 
00260     if( !pp_block || !*pp_block ) return NULL;
00261 
00262     block_BytestreamPush( &p_sys->bytestream, *pp_block );
00263 
00264     for( ;; )
00265     {
00266         switch( p_sys->i_state )
00267         {
00268             case STATE_NOSYNC:
00269                 if( block_FindStartcodeFromOffset( &p_sys->bytestream,
00270                       &p_sys->i_offset, p_sys->startcode+1, 3 ) == VLC_SUCCESS)
00271                 {
00272                     p_sys->i_state = STATE_NEXT_SYNC;
00273                 }
00274 
00275                 if( p_sys->i_offset )
00276                 {
00277                     block_SkipBytes( &p_sys->bytestream, p_sys->i_offset );
00278                     p_sys->i_offset = 0;
00279                     block_BytestreamFlush( &p_sys->bytestream );
00280                 }
00281 
00282                 if( p_sys->i_state != STATE_NEXT_SYNC )
00283                 {
00284                     /* Need more data */
00285                     return NULL;
00286                 }
00287 
00288                 p_sys->i_offset = 1; /* To find next startcode */
00289 
00290             case STATE_NEXT_SYNC:
00291                 /* Find the next startcode */
00292                 if( block_FindStartcodeFromOffset( &p_sys->bytestream,
00293                       &p_sys->i_offset, p_sys->startcode+1, 3 ) != VLC_SUCCESS)
00294                 {
00295                     /* Need more data */
00296                     return NULL;
00297                 }
00298 
00299                 /* Get the new fragment and set the pts/dts */
00300                 p_pic = block_New( p_dec, p_sys->i_offset );
00301                 p_pic->i_pts = p_sys->bytestream.p_block->i_pts;
00302                 p_pic->i_dts = p_sys->bytestream.p_block->i_dts;
00303 
00304                 block_GetBytes( &p_sys->bytestream, p_pic->p_buffer,
00305                                 p_pic->i_buffer );
00306 
00307                 if( !p_pic->p_buffer[p_pic->i_buffer-1] ) p_pic->i_buffer--;
00308                 p_sys->i_offset = 0;
00309 
00310                 /* Parse the NAL */
00311                 if( !( p_pic = ParseNALBlock( p_dec, p_pic ) ) )
00312                 {
00313                     p_sys->i_state = STATE_NOSYNC;
00314                     break;
00315                 }
00316 #if 0
00317                 msg_Dbg( p_dec, "pts="I64Fd" dts="I64Fd,
00318                          p_pic->i_pts, p_pic->i_dts );
00319 #endif
00320 
00321                 /* So p_block doesn't get re-added several times */
00322                 *pp_block = block_BytestreamPop( &p_sys->bytestream );
00323 
00324                 p_sys->i_state = STATE_NOSYNC;
00325 
00326                 return p_pic;
00327         }
00328     }
00329 }
00330 
00331 /****************************************************************************
00332  * PacketizeAVC1: the whole thing
00333  ****************************************************************************/
00334 static block_t *PacketizeAVC1( decoder_t *p_dec, block_t **pp_block )
00335 {
00336     decoder_sys_t *p_sys = p_dec->p_sys;
00337     block_t       *p_block;
00338     block_t       *p_ret = NULL;
00339     uint8_t       *p;
00340 
00341     if( !pp_block || !*pp_block ) return NULL;
00342 
00343     p_block = *pp_block;
00344     *pp_block = NULL;
00345 
00346 #if 0
00347     if( //(p_block->i_flags & BLOCK_FLAG_TYPE_I) &&
00348         p_sys->p_sps && p_sys->p_pps )
00349     {
00350         block_t *p_pic;
00351         block_t *p_sps = block_Duplicate( p_sys->p_sps );
00352         block_t *p_pps = block_Duplicate( p_sys->p_pps );
00353         p_sps->i_dts = p_pps->i_dts = p_block->i_dts;
00354         p_sps->i_pts = p_pps->i_pts = p_block->i_pts;
00355         p_pic = ParseNALBlock( p_dec, p_sps );
00356         if( p_pic ) block_ChainAppend( &p_ret, p_pic );
00357         p_pic = ParseNALBlock( p_dec, p_pps );
00358         if( p_pic ) block_ChainAppend( &p_ret, p_pic );
00359     }
00360 #endif
00361 
00362     for( p = p_block->p_buffer; p < &p_block->p_buffer[p_block->i_buffer]; )
00363     {
00364         block_t *p_pic;
00365         int i_size = 0;
00366         int i;
00367 
00368         for( i = 0; i < p_sys->i_avcC_length_size; i++ )
00369         {
00370             i_size = (i_size << 8) | (*p++);
00371         }
00372 
00373         if( i_size > 0 )
00374         {
00375             block_t *p_part = nal_get_annexeb( p_dec, p, i_size );
00376 
00377             p_part->i_dts = p_block->i_dts;
00378             p_part->i_pts = p_block->i_pts;
00379 
00380             /* Parse the NAL */
00381             if( ( p_pic = ParseNALBlock( p_dec, p_part ) ) )
00382             {
00383                 block_ChainAppend( &p_ret, p_pic );
00384             }
00385         }
00386         p += i_size;
00387     }
00388     block_Release( p_block );
00389 
00390     return p_ret;
00391 }
00392 
00393 static block_t *nal_get_annexeb( decoder_t *p_dec, uint8_t *p, int i_size )
00394 {
00395     block_t *p_nal;
00396 
00397     p_nal = block_New( p_dec, 3 + i_size );
00398 
00399     /* Add start code */
00400     p_nal->p_buffer[0] = 0x00;
00401     p_nal->p_buffer[1] = 0x00;
00402     p_nal->p_buffer[2] = 0x01;
00403 
00404     /* Copy nalu */
00405     memcpy( &p_nal->p_buffer[3], p, i_size );
00406 
00407     return p_nal;
00408 }
00409 
00410 static void nal_get_decoded( uint8_t **pp_ret, int *pi_ret,
00411                              uint8_t *src, int i_src )
00412 {
00413     uint8_t *end = &src[i_src];
00414     uint8_t *dst = malloc( i_src );
00415 
00416     *pp_ret = dst;
00417 
00418     while( src < end )
00419     {
00420         if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 &&
00421             src[2] == 0x03 )
00422         {
00423             *dst++ = 0x00;
00424             *dst++ = 0x00;
00425 
00426             src += 3;
00427             continue;
00428         }
00429         *dst++ = *src++;
00430     }
00431 
00432     *pi_ret = dst - *pp_ret;
00433 }
00434 
00435 static inline int bs_read_ue( bs_t *s )
00436 {
00437     int i = 0;
00438 
00439     while( bs_read1( s ) == 0 && s->p < s->p_end && i < 32 )
00440     {
00441         i++;
00442     }
00443     return( ( 1 << i) - 1 + bs_read( s, i ) );
00444 }
00445 
00446 static inline int bs_read_se( bs_t *s )
00447 {
00448     int val = bs_read_ue( s );
00449 
00450     return val&0x01 ? (val+1)/2 : -(val/2);
00451 }
00452 
00453 
00454 static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
00455 {
00456     decoder_sys_t *p_sys = p_dec->p_sys;
00457     block_t *p_pic = NULL;
00458 
00459     const int i_nal_ref_idc = (p_frag->p_buffer[3] >> 5)&0x03;
00460     const int i_nal_type = p_frag->p_buffer[3]&0x1f;
00461 
00462 #define OUTPUT \
00463     do {                                                \
00464         p_pic = block_ChainGather( p_sys->p_frame );    \
00465         p_pic->i_length = 0;    /* FIXME */             \
00466                                                         \
00467         p_sys->p_frame = NULL;                          \
00468         p_sys->b_slice = VLC_FALSE;                     \
00469     } while(0)
00470 
00471 
00472     if( p_sys->b_slice && !p_sys->b_sps )
00473     {
00474         block_ChainRelease( p_sys->p_frame );
00475         msg_Warn( p_dec, "waiting for SPS" );
00476 
00477         /* Reset context */
00478         p_sys->p_frame = NULL;
00479         p_sys->b_slice = VLC_FALSE;
00480     }
00481 
00482     if( !p_sys->b_sps &&
00483         i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR )
00484     {
00485         p_sys->b_slice = VLC_TRUE;
00486         /* Fragment will be discarded later on */
00487     }
00488     else if( i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR )
00489     {
00490         uint8_t *dec;
00491         int i_dec, i_first_mb, i_slice_type, i_frame_num, i_pic_flags = 0;
00492         vlc_bool_t b_pic = VLC_FALSE;
00493         bs_t s;
00494 
00495         /* do not convert the whole frame */
00496         nal_get_decoded( &dec, &i_dec, &p_frag->p_buffer[4],
00497                          __MIN( p_frag->i_buffer - 4, 60 ) );
00498         bs_init( &s, dec, i_dec );
00499 
00500         /* first_mb_in_slice */
00501         i_first_mb = bs_read_ue( &s );
00502 
00503         /* slice_type */
00504         switch( (i_slice_type = bs_read_ue( &s )) )
00505         {
00506             case 0: case 5:
00507                 i_pic_flags = BLOCK_FLAG_TYPE_P;
00508                 break;
00509             case 1: case 6:
00510                 i_pic_flags = BLOCK_FLAG_TYPE_B;
00511                 break;
00512             case 2: case 7:
00513                 i_pic_flags = BLOCK_FLAG_TYPE_I;
00514                 break;
00515             case 3: case 8: /* SP */
00516                 i_pic_flags = BLOCK_FLAG_TYPE_P;
00517                 break;
00518             case 4: case 9:
00519                 i_pic_flags = BLOCK_FLAG_TYPE_I;
00520                 break;
00521         }
00522 
00523         /* pic_parameter_set_id */
00524         bs_read_ue( &s );
00525         /* frame_num */
00526         i_frame_num = bs_read( &s, p_sys->i_log2_max_frame_num + 4 );
00527 
00528         /* Detection of the first VCL NAL unit of a primary coded picture
00529          * (cf. 7.4.1.2.4) */
00530         if( i_frame_num != p_sys->i_frame_num ||
00531             ( (i_nal_ref_idc != p_sys->i_nal_ref_idc) &&
00532               (!i_nal_ref_idc || !p_sys->i_nal_ref_idc) ) )
00533         {
00534             b_pic = VLC_TRUE;
00535         }
00536         p_sys->i_frame_num = i_frame_num;
00537         p_sys->i_nal_ref_idc = i_nal_ref_idc;
00538 
00539         if( !p_sys->b_frame_mbs_only )
00540         {
00541             /* field_pic_flag */
00542             if( bs_read( &s, 1 ) )
00543             {
00544                 /* bottom_field_flag */
00545                 bs_read( &s, 1 );
00546             }
00547         }
00548 
00549         if( i_nal_type == NAL_SLICE_IDR )
00550         {
00551             /* id_pic_id */
00552             int i_idr_pic_id = bs_read_ue( &s );
00553             if( p_sys->i_nal_type != i_nal_type ) b_pic = VLC_TRUE;
00554             if( p_sys->i_idr_pic_id != i_idr_pic_id ) b_pic = VLC_TRUE;
00555             p_sys->i_idr_pic_id = i_idr_pic_id;
00556         }
00557         p_sys->i_nal_type = i_nal_type;
00558 
00559         if( b_pic && p_sys->b_slice ) OUTPUT;
00560 
00561         p_sys->b_slice = VLC_TRUE;
00562 
00563         free( dec );
00564     }
00565     else if( i_nal_type == NAL_SPS )
00566     {
00567         uint8_t *dec;
00568         int     i_dec;
00569         bs_t s;
00570         int i_tmp;
00571 
00572         if( !p_sys->b_sps ) msg_Dbg( p_dec, "found NAL_SPS" );
00573 
00574         p_sys->b_sps = VLC_TRUE;
00575 
00576         nal_get_decoded( &dec, &i_dec, &p_frag->p_buffer[4],
00577                          p_frag->i_buffer - 4 );
00578 
00579         bs_init( &s, dec, i_dec );
00580         /* Skip profile(8), constraint_set012, reserver(5), level(8) */
00581         bs_skip( &s, 8 + 1+1+1 + 5 + 8 );
00582         /* sps id */
00583         bs_read_ue( &s );
00584         /* Skip i_log2_max_frame_num */
00585         p_sys->i_log2_max_frame_num = bs_read_ue( &s );
00586         /* Read poc_type */
00587         i_tmp = bs_read_ue( &s );
00588         if( i_tmp == 0 )
00589         {
00590             /* skip i_log2_max_poc_lsb */
00591             bs_read_ue( &s );
00592         }
00593         else if( i_tmp == 1 )
00594         {
00595             int i_cycle;
00596             /* skip b_delta_pic_order_always_zero */
00597             bs_skip( &s, 1 );
00598             /* skip i_offset_for_non_ref_pic */
00599             bs_read_se( &s );
00600             /* skip i_offset_for_top_to_bottom_field */
00601             bs_read_se( &s );
00602             /* read i_num_ref_frames_in_poc_cycle */
00603             i_cycle = bs_read_ue( &s );
00604             if( i_cycle > 256 ) i_cycle = 256;
00605             while( i_cycle > 0 )
00606             {
00607                 /* skip i_offset_for_ref_frame */
00608                 bs_read_se(&s );
00609             }
00610         }
00611         /* i_num_ref_frames */
00612         bs_read_ue( &s );
00613         /* b_gaps_in_frame_num_value_allowed */
00614         bs_skip( &s, 1 );
00615 
00616         /* Read size */
00617         p_dec->fmt_out.video.i_width  = 16 * ( bs_read_ue( &s ) + 1 );
00618         p_dec->fmt_out.video.i_height = 16 * ( bs_read_ue( &s ) + 1 );
00619 
00620         /* b_frame_mbs_only */
00621         p_sys->b_frame_mbs_only = bs_read( &s, 1 );
00622         if( p_sys->b_frame_mbs_only == 0 )
00623         {
00624             bs_skip( &s, 1 );
00625         }
00626         /* b_direct8x8_inference */
00627         bs_skip( &s, 1 );
00628 
00629         /* crop */
00630         i_tmp = bs_read( &s, 1 );
00631         if( i_tmp )
00632         {
00633             /* left */
00634             bs_read_ue( &s );
00635             /* right */
00636             bs_read_ue( &s );
00637             /* top */
00638             bs_read_ue( &s );
00639             /* bottom */
00640             bs_read_ue( &s );
00641         }
00642 
00643         /* vui */
00644         i_tmp = bs_read( &s, 1 );
00645         if( i_tmp )
00646         {
00647             /* read the aspect ratio part if any FIXME check it */
00648             i_tmp = bs_read( &s, 1 );
00649             if( i_tmp )
00650             {
00651                 static const struct { int w, h; } sar[14] =
00652                 {
00653                     { 0,   0 }, { 1,   1 }, { 12, 11 }, { 10, 11 },
00654                     { 16, 11 }, { 40, 33 }, { 24, 11 }, { 20, 11 },
00655                     { 32, 11 }, { 80, 33 }, { 18, 11 }, { 15, 11 },
00656                     { 64, 33 }, { 160,99 },
00657                 };
00658                 int i_sar = bs_read( &s, 8 );
00659                 int w, h;
00660 
00661                 if( i_sar < 14 )
00662                 {
00663                     w = sar[i_sar].w;
00664                     h = sar[i_sar].h;
00665                 }
00666                 else
00667                 {
00668                     w = bs_read( &s, 16 );
00669                     h = bs_read( &s, 16 );
00670                 }
00671                 if( h != 0 )
00672                     p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * w /
00673                         h * p_dec->fmt_out.video.i_width /
00674                         p_dec->fmt_out.video.i_height;
00675                 else
00676                     p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR;
00677             }
00678         }
00679 
00680         free( dec );
00681 
00682 
00683         if( p_sys->b_slice ) OUTPUT;
00684     }
00685     else if( i_nal_type == NAL_PPS )
00686     {
00687         bs_t s;
00688         bs_init( &s, &p_frag->p_buffer[4], p_frag->i_buffer - 4 );
00689 
00690         if( !p_sys->b_pps ) msg_Dbg( p_dec, "found NAL_PPS" );
00691         p_sys->b_pps = VLC_TRUE;
00692 
00693         /* TODO */
00694 
00695         if( p_sys->b_slice ) OUTPUT;
00696     }
00697     else if( i_nal_type == NAL_AU_DELIMITER ||
00698              i_nal_type == NAL_SEI ||
00699              ( i_nal_type >= 13 && i_nal_type <= 18 ) )
00700     {
00701         if( p_sys->b_slice ) OUTPUT;
00702     }
00703 
00704 #undef OUTPUT
00705 
00706     /* Append the block */
00707     block_ChainAppend( &p_sys->p_frame, p_frag );
00708 
00709     return p_pic;
00710 }

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