+static void PutSPS( decoder_t *p_dec, block_t *p_frag )
+{
+ decoder_sys_t *p_sys = p_dec->p_sys;
+
+ uint8_t *pb_dec = NULL;
+ int i_dec = 0;
+ bs_t s;
+ int i_tmp;
+ int i_sps_id;
+
+ CreateDecodedNAL( &pb_dec, &i_dec, &p_frag->p_buffer[5],
+ p_frag->i_buffer - 5 );
+
+ bs_init( &s, pb_dec, i_dec );
+ /* Skip profile(8), constraint_set012, reserver(5), level(8) */
+ bs_skip( &s, 8 + 1+1+1 + 5 + 8 );
+ /* sps id */
+ i_sps_id = bs_read_ue( &s );
+ if( i_sps_id >= SPS_MAX )
+ {
+ msg_Warn( p_dec, "invalid SPS (sps_id=%d)", i_sps_id );
+ free( pb_dec );
+ block_Release( p_frag );
+ return;
+ }
+
+ /* Skip i_log2_max_frame_num */
+ p_sys->i_log2_max_frame_num = bs_read_ue( &s );
+ if( p_sys->i_log2_max_frame_num > 12)
+ p_sys->i_log2_max_frame_num = 12;
+ /* Read poc_type */
+ p_sys->i_pic_order_cnt_type = bs_read_ue( &s );
+ if( p_sys->i_pic_order_cnt_type == 0 )
+ {
+ /* skip i_log2_max_poc_lsb */
+ p_sys->i_log2_max_pic_order_cnt_lsb = bs_read_ue( &s );
+ if( p_sys->i_log2_max_pic_order_cnt_lsb > 12 )
+ p_sys->i_log2_max_pic_order_cnt_lsb = 12;
+ }
+ else if( p_sys->i_pic_order_cnt_type == 1 )
+ {
+ int i_cycle;
+ /* skip b_delta_pic_order_always_zero */
+ p_sys->i_delta_pic_order_always_zero_flag = bs_read( &s, 1 );
+ /* skip i_offset_for_non_ref_pic */
+ bs_read_se( &s );
+ /* skip i_offset_for_top_to_bottom_field */
+ bs_read_se( &s );
+ /* read i_num_ref_frames_in_poc_cycle */
+ i_cycle = bs_read_ue( &s );
+ if( i_cycle > 256 ) i_cycle = 256;
+ while( i_cycle > 0 )