1 /*****************************************************************************
2 * h264.c: h264/avc video packetizer
3 *****************************************************************************
4 * Copyright (C) 2001, 2002, 2006 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Eric Petit <titer@videolan.org>
9 * Gildas Bazin <gbazin@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
33 #include <vlc_codec.h>
34 #include <vlc_block.h>
36 #include "vlc_block_helper.h"
39 /*****************************************************************************
41 *****************************************************************************/
42 static int Open ( vlc_object_t * );
43 static void Close( vlc_object_t * );
46 set_category( CAT_SOUT );
47 set_subcategory( SUBCAT_SOUT_PACKETIZER );
48 set_description( _("H.264 video packetizer") );
49 set_capability( "packetizer", 50 );
50 set_callbacks( Open, Close );
54 /****************************************************************************
56 ****************************************************************************/
57 static block_t *Packetize( decoder_t *, block_t ** );
58 static block_t *PacketizeAVC1( decoder_t *, block_t ** );
66 int i_pic_parameter_set_id;
70 int i_bottom_field_flag;
74 int i_pic_order_cnt_lsb;
75 int i_delta_pic_order_cnt_bottom;
77 int i_delta_pic_order_cnt0;
78 int i_delta_pic_order_cnt1;
83 block_bytestream_t bytestream;
96 int i_avcC_length_size;
100 /* Useful values of the Sequence Parameter Set */
101 int i_log2_max_frame_num;
102 int b_frame_mbs_only;
103 int i_pic_order_cnt_type;
104 int i_delta_pic_order_always_zero_flag;
105 int i_log2_max_pic_order_cnt_lsb;
107 /* Value from Picture Parameter Set */
108 int i_pic_order_present_flag;
110 /* Useful values of the Slice Header */
127 NAL_SLICE_IDR = 5, /* ref_idc != 0 */
128 NAL_SEI = 6, /* ref_idc == 0 */
132 /* ref_idc == 0 for 6,9,10,11,12 */
137 NAL_PRIORITY_DISPOSABLE = 0,
138 NAL_PRIORITY_LOW = 1,
139 NAL_PRIORITY_HIGH = 2,
140 NAL_PRIORITY_HIGHEST = 3,
143 static block_t *ParseNALBlock( decoder_t *, block_t * );
145 static block_t *nal_get_annexeb( decoder_t *, uint8_t *p, int );
147 /*****************************************************************************
148 * Open: probe the packetizer and return score
149 * When opening after demux, the packetizer is only loaded AFTER the decoder
150 * That means that what you set in fmt_out is ignored by the decoder in this special case
151 *****************************************************************************/
152 static int Open( vlc_object_t *p_this )
154 decoder_t *p_dec = (decoder_t*)p_this;
155 decoder_sys_t *p_sys;
157 if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'h', '2', '6', '4') &&
158 p_dec->fmt_in.i_codec != VLC_FOURCC( 'H', '2', '6', '4') &&
159 p_dec->fmt_in.i_codec != VLC_FOURCC( 'V', 'S', 'S', 'H') &&
160 p_dec->fmt_in.i_codec != VLC_FOURCC( 'v', 's', 's', 'h') &&
161 p_dec->fmt_in.i_codec != VLC_FOURCC( 'D', 'A', 'V', 'C') &&
162 ( p_dec->fmt_in.i_codec != VLC_FOURCC( 'a', 'v', 'c', '1') ||
163 p_dec->fmt_in.i_extra < 7 ) )
168 /* Allocate the memory needed to store the decoder's structure */
169 if( ( p_dec->p_sys = p_sys = malloc( sizeof(decoder_sys_t) ) ) == NULL )
171 msg_Err( p_dec, "out of memory" );
174 p_sys->i_state = STATE_NOSYNC;
176 p_sys->startcode[0] = 0;
177 p_sys->startcode[1] = 0;
178 p_sys->startcode[2] = 0;
179 p_sys->startcode[3] = 1;
180 p_sys->bytestream = block_BytestreamInit( p_dec );
181 p_sys->b_slice = VLC_FALSE;
182 p_sys->p_frame = NULL;
183 p_sys->b_sps = VLC_FALSE;
184 p_sys->b_pps = VLC_FALSE;
188 p_sys->slice.i_nal_type = -1;
189 p_sys->slice.i_nal_ref_idc = -1;
190 p_sys->slice.i_idr_pic_id = -1;
191 p_sys->slice.i_frame_num = -1;
192 p_sys->slice.i_frame_type = 0;
193 p_sys->slice.i_pic_parameter_set_id = -1;
194 p_sys->slice.i_field_pic_flag = 0;
195 p_sys->slice.i_bottom_field_flag = -1;
196 p_sys->slice.i_pic_order_cnt_lsb = -1;
197 p_sys->slice.i_delta_pic_order_cnt_bottom = -1;
199 /* Setup properties */
200 es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
201 p_dec->fmt_out.i_codec = VLC_FOURCC( 'h', '2', '6', '4' );
203 if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'v', 'c', '1' ) )
205 /* This type of stream is produced by mp4 and matroska
206 * when we want to store it in another streamformat, you need to convert
207 * The fmt_in.p_extra should ALWAYS contain the avcC
208 * The fmt_out.p_extra should contain all the SPS and PPS with 4 byte startcodes */
209 uint8_t *p = &((uint8_t*)p_dec->fmt_in.p_extra)[4];
214 p_sys->i_avcC_length_size = 1 + ((*p++)&0x03);
218 for( i = 0; i < i_sps; i++ )
220 int i_length = GetWBE( p );
221 block_t *p_sps = nal_get_annexeb( p_dec, p + 2, i_length );
223 p_sys->p_sps = block_Duplicate( p_sps );
224 p_sps->i_pts = p_sps->i_dts = mdate();
225 ParseNALBlock( p_dec, p_sps );
230 for( i = 0; i < i_pps; i++ )
232 int i_length = GetWBE( p );
233 block_t *p_pps = nal_get_annexeb( p_dec, p + 2, i_length );
235 p_sys->p_pps = block_Duplicate( p_pps );
236 p_pps->i_pts = p_pps->i_dts = mdate();
237 ParseNALBlock( p_dec, p_pps );
240 msg_Dbg( p_dec, "avcC length size=%d, sps=%d, pps=%d",
241 p_sys->i_avcC_length_size, i_sps, i_pps );
243 /* FIXME: FFMPEG isn't happy at all if you leave this */
244 if( p_dec->fmt_out.i_extra ) free( p_dec->fmt_out.p_extra );
245 p_dec->fmt_out.i_extra = 0; p_dec->fmt_out.p_extra = NULL;
247 /* Set the new extradata */
248 p_dec->fmt_out.i_extra = p_sys->p_pps->i_buffer + p_sys->p_sps->i_buffer;
249 p_dec->fmt_out.p_extra = (uint8_t*)malloc( p_dec->fmt_out.i_extra );
250 memcpy( (uint8_t*)p_dec->fmt_out.p_extra, p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer);
251 memcpy( (uint8_t*)p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer, p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer);
254 p_dec->pf_packetize = PacketizeAVC1;
258 /* This type of stream contains data with 3 of 4 byte startcodes
259 * The fmt_in.p_extra MAY contain SPS/PPS with 4 byte startcodes
260 * The fmt_out.p_extra should be the same */
263 p_dec->pf_packetize = Packetize;
266 if( p_dec->fmt_in.i_extra > 0 )
268 block_t *p_init = block_New( p_dec, p_dec->fmt_in.i_extra );
271 memcpy( p_init->p_buffer, p_dec->fmt_in.p_extra,
272 p_dec->fmt_in.i_extra );
274 while( ( p_pic = Packetize( p_dec, &p_init ) ) )
276 /* Should not occur because we should only receive SPS/PPS */
277 block_Release( p_pic );
285 /*****************************************************************************
286 * Close: clean up the packetizer
287 *****************************************************************************/
288 static void Close( vlc_object_t *p_this )
290 decoder_t *p_dec = (decoder_t*)p_this;
291 decoder_sys_t *p_sys = p_dec->p_sys;
293 if( p_sys->p_frame ) block_ChainRelease( p_sys->p_frame );
294 if( p_sys->p_sps ) block_Release( p_sys->p_sps );
295 if( p_sys->p_pps ) block_Release( p_sys->p_pps );
296 block_BytestreamRelease( &p_sys->bytestream );
300 /****************************************************************************
301 * Packetize: the whole thing
302 * Search for the startcodes 3 or more bytes
303 * Feed ParseNALBlock ALWAYS with 4 byte startcode prepended NALs
304 ****************************************************************************/
305 static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
307 decoder_sys_t *p_sys = p_dec->p_sys;
310 if( !pp_block || !*pp_block )
313 if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
315 if( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED )
317 p_sys->i_state = STATE_NOSYNC;
318 block_BytestreamFlush( &p_sys->bytestream );
321 block_ChainRelease( p_sys->p_frame );
322 p_sys->p_frame = NULL;
323 p_sys->slice.i_frame_type = 0;
324 p_sys->b_slice = VLC_FALSE;
326 block_Release( *pp_block );
330 block_BytestreamPush( &p_sys->bytestream, *pp_block );
334 switch( p_sys->i_state )
337 /* Skip until 3 byte startcode 0 0 1 */
338 if( block_FindStartcodeFromOffset( &p_sys->bytestream,
339 &p_sys->i_offset, p_sys->startcode+1, 3 ) == VLC_SUCCESS)
341 p_sys->i_state = STATE_NEXT_SYNC;
344 if( p_sys->i_offset )
347 block_SkipBytes( &p_sys->bytestream, p_sys->i_offset );
349 block_BytestreamFlush( &p_sys->bytestream );
352 if( p_sys->i_state != STATE_NEXT_SYNC )
358 p_sys->i_offset = 1; /* To find next startcode */
360 case STATE_NEXT_SYNC:
361 /* Find the next 3 byte startcode 0 0 1*/
362 if( block_FindStartcodeFromOffset( &p_sys->bytestream,
363 &p_sys->i_offset, p_sys->startcode+1, 3 ) != VLC_SUCCESS)
369 /* Get the new fragment and set the pts/dts */
370 p_pic = block_New( p_dec, p_sys->i_offset +1 );
371 p_pic->i_pts = p_sys->bytestream.p_block->i_pts;
372 p_pic->i_dts = p_sys->bytestream.p_block->i_dts;
373 /* Force 4 byte startcode 0 0 0 1 */
374 p_pic->p_buffer[0] = 0;
376 block_GetBytes( &p_sys->bytestream, &p_pic->p_buffer[1],
379 /* Remove trailing 0 bytes */
380 while( p_pic->i_buffer && (!p_pic->p_buffer[p_pic->i_buffer-1] ) )
385 if( !( p_pic = ParseNALBlock( p_dec, p_pic ) ) )
387 p_sys->i_state = STATE_NOSYNC;
391 msg_Dbg( p_dec, "pts="I64Fd" dts="I64Fd,
392 p_pic->i_pts, p_pic->i_dts );
395 /* So p_block doesn't get re-added several times */
396 *pp_block = block_BytestreamPop( &p_sys->bytestream );
398 p_sys->i_state = STATE_NOSYNC;
405 /****************************************************************************
406 * PacketizeAVC1: Takes VCL blocks of data and creates annexe B type NAL stream
407 * Will always use 4 byte 0 0 0 1 startcodes
408 * Will prepend a SPS and PPS before each keyframe
409 ****************************************************************************/
410 static block_t *PacketizeAVC1( decoder_t *p_dec, block_t **pp_block )
412 decoder_sys_t *p_sys = p_dec->p_sys;
414 block_t *p_ret = NULL;
417 if( !pp_block || !*pp_block )
419 if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
421 block_Release( *pp_block );
428 for( p = p_block->p_buffer; p < &p_block->p_buffer[p_block->i_buffer]; )
434 for( i = 0; i < p_sys->i_avcC_length_size; i++ )
436 i_size = (i_size << 8) | (*p++);
441 block_t *p_part = nal_get_annexeb( p_dec, p, i_size );
443 p_part->i_dts = p_block->i_dts;
444 p_part->i_pts = p_block->i_pts;
447 if( ( p_pic = ParseNALBlock( p_dec, p_part ) ) )
449 block_ChainAppend( &p_ret, p_pic );
454 block_Release( p_block );
459 static block_t *nal_get_annexeb( decoder_t *p_dec, uint8_t *p, int i_size )
463 p_nal = block_New( p_dec, 4 + i_size );
466 p_nal->p_buffer[0] = 0x00;
467 p_nal->p_buffer[1] = 0x00;
468 p_nal->p_buffer[2] = 0x00;
469 p_nal->p_buffer[3] = 0x01;
472 memcpy( &p_nal->p_buffer[4], p, i_size );
477 static void nal_get_decoded( uint8_t **pp_ret, int *pi_ret,
478 uint8_t *src, int i_src )
480 uint8_t *end = &src[i_src];
481 uint8_t *dst = malloc( i_src );
487 if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 &&
499 *pi_ret = dst - *pp_ret;
502 static inline int bs_read_ue( bs_t *s )
506 while( bs_read1( s ) == 0 && s->p < s->p_end && i < 32 )
510 return( ( 1 << i) - 1 + bs_read( s, i ) );
513 static inline int bs_read_se( bs_t *s )
515 int val = bs_read_ue( s );
517 return val&0x01 ? (val+1)/2 : -(val/2);
521 /*****************************************************************************
522 * ParseNALBlock: parses annexB type NALs
523 * All p_frag blocks are required to start with 0 0 0 1 4-byte startcode
524 *****************************************************************************/
525 static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
527 decoder_sys_t *p_sys = p_dec->p_sys;
528 block_t *p_pic = NULL;
530 const int i_nal_ref_idc = (p_frag->p_buffer[4] >> 5)&0x03;
531 const int i_nal_type = p_frag->p_buffer[4]&0x1f;
535 if( !p_sys->b_header && p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I) \
538 if( p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I && p_sys->p_sps && p_sys->p_pps ) \
540 block_t *p_sps = block_Duplicate( p_sys->p_sps ); \
541 block_t *p_pps = block_Duplicate( p_sys->p_pps ); \
542 p_sps->i_dts = p_sys->p_frame->i_dts; \
543 p_sps->i_pts = p_sys->p_frame->i_pts; \
544 block_ChainAppend( &p_sps, p_pps ); \
545 block_ChainAppend( &p_sps, p_sys->p_frame ); \
546 p_pic = block_ChainGather( p_sps ); \
548 p_pic = block_ChainGather( p_sys->p_frame ); \
550 p_pic->i_length = 0; /* FIXME */ \
551 p_pic->i_flags |= p_sys->slice.i_frame_type; \
553 p_sys->slice.i_frame_type = 0; \
554 p_sys->p_frame = NULL; \
555 p_sys->b_slice = VLC_FALSE; \
558 if( p_sys->b_slice && ( !p_sys->b_sps || !p_sys->b_pps ) )
560 block_ChainRelease( p_sys->p_frame );
561 msg_Warn( p_dec, "waiting for SPS/PPS" );
564 p_sys->slice.i_frame_type = 0;
565 p_sys->p_frame = NULL;
566 p_sys->b_slice = VLC_FALSE;
569 if( ( !p_sys->b_sps || !p_sys->b_pps ) &&
570 i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR )
572 p_sys->b_slice = VLC_TRUE;
573 /* Fragment will be discarded later on */
575 else if( i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR )
578 int i_dec, i_first_mb, i_slice_type;
583 /* do not convert the whole frame */
584 nal_get_decoded( &dec, &i_dec, &p_frag->p_buffer[5],
585 __MIN( p_frag->i_buffer - 5, 60 ) );
586 bs_init( &s, dec, i_dec );
588 /* first_mb_in_slice */
589 i_first_mb = bs_read_ue( &s );
592 switch( (i_slice_type = bs_read_ue( &s )) )
595 slice.i_frame_type = BLOCK_FLAG_TYPE_P;
598 slice.i_frame_type = BLOCK_FLAG_TYPE_B;
601 slice.i_frame_type = BLOCK_FLAG_TYPE_I;
603 case 3: case 8: /* SP */
604 slice.i_frame_type = BLOCK_FLAG_TYPE_P;
607 slice.i_frame_type = BLOCK_FLAG_TYPE_I;
610 slice.i_frame_type = 0;
615 slice.i_nal_type = i_nal_type;
616 slice.i_nal_ref_idc = i_nal_ref_idc;
618 slice.i_pic_parameter_set_id = bs_read_ue( &s );
619 slice.i_frame_num = bs_read( &s, p_sys->i_log2_max_frame_num + 4 );
621 slice.i_field_pic_flag = 0;
622 slice.i_bottom_field_flag = -1;
623 if( !p_sys->b_frame_mbs_only )
626 slice.i_field_pic_flag = bs_read( &s, 1 );
627 if( slice.i_field_pic_flag )
628 slice.i_bottom_field_flag = bs_read( &s, 1 );
631 slice.i_idr_pic_id = p_sys->slice.i_idr_pic_id;
632 if( slice.i_nal_type == NAL_SLICE_IDR )
633 slice.i_idr_pic_id = bs_read_ue( &s );
635 slice.i_pic_order_cnt_lsb = -1;
636 slice.i_delta_pic_order_cnt_bottom = -1;
637 slice.i_delta_pic_order_cnt0 = 0;
638 slice.i_delta_pic_order_cnt1 = 0;
639 if( p_sys->i_pic_order_cnt_type == 0 )
641 slice.i_pic_order_cnt_lsb = bs_read( &s, p_sys->i_log2_max_pic_order_cnt_lsb + 4 );
642 if( p_sys->i_pic_order_present_flag && !slice.i_field_pic_flag )
643 slice.i_delta_pic_order_cnt_bottom = bs_read_se( &s );
645 else if( p_sys->i_pic_order_cnt_type == 1 && !p_sys->i_delta_pic_order_always_zero_flag )
647 slice.i_delta_pic_order_cnt0 = bs_read_se( &s );
648 if( p_sys->i_pic_order_present_flag && !slice.i_field_pic_flag )
649 slice.i_delta_pic_order_cnt1 = bs_read_se( &s );
652 /* Detection of the first VCL NAL unit of a primary coded picture
655 if( slice.i_frame_num != p_sys->slice.i_frame_num ||
656 slice.i_pic_parameter_set_id != p_sys->slice.i_pic_parameter_set_id ||
657 slice.i_field_pic_flag != p_sys->slice.i_field_pic_flag ||
658 slice.i_nal_ref_idc != p_sys->slice.i_nal_ref_idc )
660 if( slice.i_bottom_field_flag != -1 && p_sys->slice.i_bottom_field_flag != -1 && slice.i_bottom_field_flag != p_sys->slice.i_bottom_field_flag )
662 if( p_sys->i_pic_order_cnt_type == 0 &&
663 ( slice.i_pic_order_cnt_lsb != p_sys->slice.i_pic_order_cnt_lsb ||
664 slice.i_delta_pic_order_cnt_bottom != p_sys->slice.i_delta_pic_order_cnt_bottom ) )
666 else if( p_sys->i_pic_order_cnt_type == 1 &&
667 ( slice.i_delta_pic_order_cnt0 != p_sys->slice.i_delta_pic_order_cnt0 ||
668 slice.i_delta_pic_order_cnt1 != p_sys->slice.i_delta_pic_order_cnt1 ) )
670 if( ( slice.i_nal_type == NAL_SLICE_IDR || p_sys->slice.i_nal_type == NAL_SLICE_IDR ) &&
671 ( slice.i_nal_type != p_sys->slice.i_nal_type || slice.i_idr_pic_id != p_sys->slice.i_idr_pic_id ) )
675 p_sys->slice = slice;
677 if( b_pic && p_sys->b_slice )
680 p_sys->b_slice = VLC_TRUE;
684 else if( i_nal_type == NAL_SPS )
691 if( !p_sys->b_sps ) msg_Dbg( p_dec, "found NAL_SPS" );
693 p_sys->b_sps = VLC_TRUE;
695 nal_get_decoded( &dec, &i_dec, &p_frag->p_buffer[5],
696 p_frag->i_buffer - 5 );
698 bs_init( &s, dec, i_dec );
699 /* Skip profile(8), constraint_set012, reserver(5), level(8) */
700 bs_skip( &s, 8 + 1+1+1 + 5 + 8 );
703 /* Skip i_log2_max_frame_num */
704 p_sys->i_log2_max_frame_num = bs_read_ue( &s );
705 if( p_sys->i_log2_max_frame_num > 12)
706 p_sys->i_log2_max_frame_num = 12;
708 p_sys->i_pic_order_cnt_type = bs_read_ue( &s );
709 if( p_sys->i_pic_order_cnt_type == 0 )
711 /* skip i_log2_max_poc_lsb */
712 p_sys->i_log2_max_pic_order_cnt_lsb = bs_read_ue( &s );
713 if( p_sys->i_log2_max_pic_order_cnt_lsb > 12 )
714 p_sys->i_log2_max_pic_order_cnt_lsb = 12;
716 else if( p_sys->i_pic_order_cnt_type == 1 )
719 /* skip b_delta_pic_order_always_zero */
720 p_sys->i_delta_pic_order_always_zero_flag = bs_read( &s, 1 );
721 /* skip i_offset_for_non_ref_pic */
723 /* skip i_offset_for_top_to_bottom_field */
725 /* read i_num_ref_frames_in_poc_cycle */
726 i_cycle = bs_read_ue( &s );
727 if( i_cycle > 256 ) i_cycle = 256;
730 /* skip i_offset_for_ref_frame */
734 /* i_num_ref_frames */
736 /* b_gaps_in_frame_num_value_allowed */
740 p_dec->fmt_out.video.i_width = 16 * ( bs_read_ue( &s ) + 1 );
741 p_dec->fmt_out.video.i_height = 16 * ( bs_read_ue( &s ) + 1 );
743 /* b_frame_mbs_only */
744 p_sys->b_frame_mbs_only = bs_read( &s, 1 );
745 if( p_sys->b_frame_mbs_only == 0 )
749 /* b_direct8x8_inference */
753 i_tmp = bs_read( &s, 1 );
767 i_tmp = bs_read( &s, 1 );
770 /* read the aspect ratio part if any FIXME check it */
771 i_tmp = bs_read( &s, 1 );
774 static const struct { int w, h; } sar[14] =
776 { 0, 0 }, { 1, 1 }, { 12, 11 }, { 10, 11 },
777 { 16, 11 }, { 40, 33 }, { 24, 11 }, { 20, 11 },
778 { 32, 11 }, { 80, 33 }, { 18, 11 }, { 15, 11 },
779 { 64, 33 }, { 160,99 },
781 int i_sar = bs_read( &s, 8 );
791 w = bs_read( &s, 16 );
792 h = bs_read( &s, 16 );
795 p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * w /
796 h * p_dec->fmt_out.video.i_width /
797 p_dec->fmt_out.video.i_height;
799 p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR;
805 if( p_sys->b_slice ) OUTPUT;
807 /* We have a new SPS */
808 if( p_sys->p_sps ) block_Release( p_sys->p_sps );
809 p_sys->p_sps = p_frag;
811 /* Do not append the SPS because we will insert it on keyframes */
814 else if( i_nal_type == NAL_PPS )
818 bs_init( &s, &p_frag->p_buffer[5], p_frag->i_buffer - 5 );
819 bs_read_ue( &s ); // pps id
820 bs_read_ue( &s ); // sps id
821 bs_skip( &s, 1 ); // entropy coding mode flag
822 p_sys->i_pic_order_present_flag = bs_read( &s, 1 );
824 if( !p_sys->b_pps ) msg_Dbg( p_dec, "found NAL_PPS" );
825 p_sys->b_pps = VLC_TRUE;
829 if( p_sys->b_slice ) OUTPUT;
831 /* We have a new PPS */
832 if( p_sys->p_pps ) block_Release( p_sys->p_pps );
833 p_sys->p_pps = p_frag;
835 /* Do not append the PPS because we will insert it on keyframes */
838 else if( i_nal_type == NAL_AU_DELIMITER ||
839 i_nal_type == NAL_SEI ||
840 ( i_nal_type >= 13 && i_nal_type <= 18 ) )
842 if( p_sys->b_slice ) OUTPUT;
847 /* Append the block */
848 block_ChainAppend( &p_sys->p_frame, p_frag );