1
/*****************************************************************************
3
*****************************************************************************
4
* Copyright (C) 2003 Laurent Aimar
5
* $Id: set.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $
7
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22
*****************************************************************************/
29
#include "common/common.h"
32
/* return -1 if invalid, else the id */
33
int x264_sps_read( bs_t *s, x264_sps_t sps_array[32] )
40
int b_constraint_set0;
41
int b_constraint_set1;
42
int b_constraint_set2;
46
i_profile_idc = bs_read( s, 8 );
47
b_constraint_set0 = bs_read( s, 1 );
48
b_constraint_set1 = bs_read( s, 1 );
49
b_constraint_set2 = bs_read( s, 1 );
51
bs_skip( s, 5 ); /* reserved */
52
i_level_idc = bs_read( s, 8 );
56
if( bs_eof( s ) || id >= 32 )
58
/* the sps is invalid, no need to corrupt sps_array[0] */
65
/* put pack parsed value */
66
sps->i_profile_idc = i_profile_idc;
67
sps->i_level_idc = i_level_idc;
68
sps->b_constraint_set0 = b_constraint_set0;
69
sps->b_constraint_set1 = b_constraint_set1;
70
sps->b_constraint_set2 = b_constraint_set2;
72
sps->i_log2_max_frame_num = bs_read_ue( s ) + 4;
74
sps->i_poc_type = bs_read_ue( s );
75
if( sps->i_poc_type == 0 )
77
sps->i_log2_max_poc_lsb = bs_read_ue( s ) + 4;
79
else if( sps->i_poc_type == 1 )
82
sps->b_delta_pic_order_always_zero = bs_read( s, 1 );
83
sps->i_offset_for_non_ref_pic = bs_read_se( s );
84
sps->i_offset_for_top_to_bottom_field = bs_read_se( s );
85
sps->i_num_ref_frames_in_poc_cycle = bs_read_ue( s );
86
if( sps->i_num_ref_frames_in_poc_cycle > 256 )
88
/* FIXME what to do */
89
sps->i_num_ref_frames_in_poc_cycle = 256;
91
for( i = 0; i < sps->i_num_ref_frames_in_poc_cycle; i++ )
93
sps->i_offset_for_ref_frame[i] = bs_read_se( s );
96
else if( sps->i_poc_type > 2 )
101
sps->i_num_ref_frames = bs_read_ue( s );
102
sps->b_gaps_in_frame_num_value_allowed = bs_read( s, 1 );
103
sps->i_mb_width = bs_read_ue( s ) + 1;
104
sps->i_mb_height= bs_read_ue( s ) + 1;
105
sps->b_frame_mbs_only = bs_read( s, 1 );
106
if( !sps->b_frame_mbs_only )
108
sps->b_mb_adaptive_frame_field = bs_read( s, 1 );
112
sps->b_mb_adaptive_frame_field = 0;
114
sps->b_direct8x8_inference = bs_read( s, 1 );
116
sps->b_crop = bs_read( s, 1 );
119
sps->crop.i_left = bs_read_ue( s );
120
sps->crop.i_right = bs_read_ue( s );
121
sps->crop.i_top = bs_read_ue( s );
122
sps->crop.i_bottom= bs_read_ue( s );
126
sps->crop.i_left = 0;
127
sps->crop.i_right = 0;
129
sps->crop.i_bottom= 0;
132
sps->b_vui = bs_read( s, 1 );
144
/* no rbsp trailing */
145
fprintf( stderr, "incomplete SPS\n" );
149
fprintf( stderr, "x264_sps_read: sps:0x%x profile:%d/%d poc:%d ref:%d %xx%d crop:%d-%d-%d-%d\n",
151
sps->i_profile_idc, sps->i_level_idc,
153
sps->i_num_ref_frames,
154
sps->i_mb_width, sps->i_mb_height,
155
sps->crop.i_left, sps->crop.i_right,
156
sps->crop.i_top, sps->crop.i_bottom );
161
/* invalidate this sps */
166
/* return -1 if invalid, else the id */
167
int x264_pps_read( bs_t *s, x264_pps_t pps_array[256] )
173
id = bs_read_ue( s );
174
if( bs_eof( s ) || id >= 256 )
176
fprintf( stderr, "id invalid\n" );
179
pps = &pps_array[id];
181
pps->i_sps_id = bs_read_ue( s );
182
if( pps->i_sps_id >= 32 )
186
pps->b_cabac = bs_read( s, 1 );
187
pps->b_pic_order = bs_read( s, 1 );
188
pps->i_num_slice_groups = bs_read_ue( s ) + 1;
189
if( pps->i_num_slice_groups > 1 )
191
fprintf( stderr, "FMO unsupported\n " );
193
pps->i_slice_group_map_type =bs_read_ue( s );
194
if( pps->i_slice_group_map_type == 0 )
196
for( i = 0; i < pps->i_num_slice_groups; i++ )
198
pps->i_run_length[i] = bs_read_ue( s );
201
else if( pps->i_slice_group_map_type == 2 )
203
for( i = 0; i < pps->i_num_slice_groups; i++ )
205
pps->i_top_left[i] = bs_read_ue( s );
206
pps->i_bottom_right[i] = bs_read_ue( s );
209
else if( pps->i_slice_group_map_type == 3 ||
210
pps->i_slice_group_map_type == 4 ||
211
pps->i_slice_group_map_type == 5 )
213
pps->b_slice_group_change_direction = bs_read( s, 1 );
214
pps->i_slice_group_change_rate = bs_read_ue( s ) + 1;
216
else if( pps->i_slice_group_map_type == 6 )
218
pps->i_pic_size_in_map_units = bs_read_ue( s ) + 1;
219
for( i = 0; i < pps->i_pic_size_in_map_units; i++ )
222
/* pps->i_slice_group_id = bs_read( s, ceil( log2( pps->i_pic_size_in_map_units +1 ) ) ); */
226
pps->i_num_ref_idx_l0_active = bs_read_ue( s ) + 1;
227
pps->i_num_ref_idx_l1_active = bs_read_ue( s ) + 1;
228
pps->b_weighted_pred = bs_read( s, 1 );
229
pps->b_weighted_bipred = bs_read( s, 2 );
231
pps->i_pic_init_qp = bs_read_se( s ) + 26;
232
pps->i_pic_init_qs = bs_read_se( s ) + 26;
234
pps->i_chroma_qp_index_offset = bs_read_se( s );
236
pps->b_deblocking_filter_control = bs_read( s, 1 );
237
pps->b_constrained_intra_pred = bs_read( s, 1 );
238
pps->b_redundant_pic_cnt = bs_read( s, 1 );
242
/* no rbsp trailing */
243
fprintf( stderr, "incomplete PPS\n" );
246
fprintf( stderr, "x264_sps_read: pps:0x%x sps:0x%x %s slice_groups=%d ref0:%d ref1:%d QP:%d QS:%d QC=%d DFC:%d CIP:%d RPC:%d\n",
247
pps->i_id, pps->i_sps_id,
248
pps->b_cabac ? "CABAC" : "CAVLC",
249
pps->i_num_slice_groups,
250
pps->i_num_ref_idx_l0_active,
251
pps->i_num_ref_idx_l1_active,
252
pps->i_pic_init_qp, pps->i_pic_init_qs, pps->i_chroma_qp_index_offset,
253
pps->b_deblocking_filter_control,
254
pps->b_constrained_intra_pred,
255
pps->b_redundant_pic_cnt );