~ubuntu-branches/ubuntu/saucy/x264/saucy-updates

« back to all changes in this revision

Viewing changes to decoder/set.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-01-17 22:00:05 UTC
  • mto: (12.1.1 sid) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20070117220005-4cesfv31lq3inbdp
Tags: upstream-0.cvs20070117
ImportĀ upstreamĀ versionĀ 0.cvs20070117

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 * x264: h264 decoder
3
 
 *****************************************************************************
4
 
 * Copyright (C) 2003 Laurent Aimar
5
 
 * $Id: set.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $
6
 
 *
7
 
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8
 
 *
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.
13
 
 *
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.
18
 
 *
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
 
 *****************************************************************************/
23
 
 
24
 
#include <stdlib.h>
25
 
#include <stdio.h>
26
 
#include <string.h>
27
 
#include <stdint.h>
28
 
 
29
 
#include "common/common.h"
30
 
#include "set.h"
31
 
 
32
 
/* return -1 if invalid, else the id */
33
 
int x264_sps_read( bs_t *s, x264_sps_t sps_array[32] )
34
 
{
35
 
    x264_sps_t *sps;
36
 
 
37
 
    int i_profile_idc;
38
 
    int i_level_idc;
39
 
 
40
 
    int b_constraint_set0;
41
 
    int b_constraint_set1;
42
 
    int b_constraint_set2;
43
 
 
44
 
    int id;
45
 
 
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 );
50
 
 
51
 
    bs_skip( s, 5 );    /* reserved */
52
 
    i_level_idc       = bs_read( s, 8 );
53
 
 
54
 
 
55
 
    id = bs_read_ue( s );
56
 
    if( bs_eof( s ) || id >= 32 )
57
 
    {
58
 
        /* the sps is invalid, no need to corrupt sps_array[0] */
59
 
        return -1;
60
 
    }
61
 
 
62
 
    sps = &sps_array[id];
63
 
    sps->i_id = id;
64
 
 
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;
71
 
 
72
 
    sps->i_log2_max_frame_num = bs_read_ue( s ) + 4;
73
 
 
74
 
    sps->i_poc_type = bs_read_ue( s );
75
 
    if( sps->i_poc_type == 0 )
76
 
    {
77
 
        sps->i_log2_max_poc_lsb = bs_read_ue( s ) + 4;
78
 
    }
79
 
    else if( sps->i_poc_type == 1 )
80
 
    {
81
 
        int i;
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 )
87
 
        {
88
 
            /* FIXME what to do */
89
 
            sps->i_num_ref_frames_in_poc_cycle = 256;
90
 
        }
91
 
        for( i = 0; i < sps->i_num_ref_frames_in_poc_cycle; i++ )
92
 
        {
93
 
            sps->i_offset_for_ref_frame[i] = bs_read_se( s );
94
 
        }
95
 
    }
96
 
    else if( sps->i_poc_type > 2 )
97
 
    {
98
 
        goto error;
99
 
    }
100
 
 
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 )
107
 
    {
108
 
        sps->b_mb_adaptive_frame_field = bs_read( s, 1 );
109
 
    }
110
 
    else
111
 
    {
112
 
        sps->b_mb_adaptive_frame_field = 0;
113
 
    }
114
 
    sps->b_direct8x8_inference = bs_read( s, 1 );
115
 
 
116
 
    sps->b_crop = bs_read( s, 1 );
117
 
    if( sps->b_crop )
118
 
    {
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 );
123
 
    }
124
 
    else
125
 
    {
126
 
        sps->crop.i_left  = 0;
127
 
        sps->crop.i_right = 0;
128
 
        sps->crop.i_top   = 0;
129
 
        sps->crop.i_bottom= 0;
130
 
    }
131
 
 
132
 
    sps->b_vui = bs_read( s, 1 );
133
 
    if( sps->b_vui )
134
 
    {
135
 
        /* FIXME */
136
 
    }
137
 
    else
138
 
    {
139
 
 
140
 
    }
141
 
 
142
 
    if( bs_eof( s ) )
143
 
    {
144
 
        /* no rbsp trailing */
145
 
        fprintf( stderr, "incomplete SPS\n" );
146
 
        goto error;
147
 
    }
148
 
 
149
 
    fprintf( stderr, "x264_sps_read: sps:0x%x profile:%d/%d poc:%d ref:%d %xx%d crop:%d-%d-%d-%d\n",
150
 
             sps->i_id,
151
 
             sps->i_profile_idc, sps->i_level_idc,
152
 
             sps->i_poc_type,
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 );
157
 
 
158
 
    return id;
159
 
 
160
 
error:
161
 
    /* invalidate this sps */
162
 
    sps->i_id = -1;
163
 
    return -1;
164
 
}
165
 
 
166
 
/* return -1 if invalid, else the id */
167
 
int x264_pps_read( bs_t *s, x264_pps_t pps_array[256] )
168
 
{
169
 
    x264_pps_t *pps;
170
 
    int id;
171
 
    int i;
172
 
 
173
 
    id = bs_read_ue( s );
174
 
    if( bs_eof( s ) || id >= 256 )
175
 
    {
176
 
        fprintf( stderr, "id invalid\n" );
177
 
        return -1;
178
 
    }
179
 
    pps = &pps_array[id];
180
 
    pps->i_id = id;
181
 
    pps->i_sps_id = bs_read_ue( s );
182
 
    if( pps->i_sps_id >= 32 )
183
 
    {
184
 
        goto error;
185
 
    }
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 )
190
 
    {
191
 
        fprintf( stderr, "FMO unsupported\n " );
192
 
 
193
 
        pps->i_slice_group_map_type  =bs_read_ue( s );
194
 
        if( pps->i_slice_group_map_type == 0 )
195
 
        {
196
 
            for( i = 0; i < pps->i_num_slice_groups; i++ )
197
 
            {
198
 
                pps->i_run_length[i] = bs_read_ue( s );
199
 
            }
200
 
        }
201
 
        else if( pps->i_slice_group_map_type == 2 )
202
 
        {
203
 
            for( i = 0; i < pps->i_num_slice_groups; i++ )
204
 
            {
205
 
                pps->i_top_left[i] = bs_read_ue( s );
206
 
                pps->i_bottom_right[i] = bs_read_ue( s );
207
 
            }
208
 
        }
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 )
212
 
        {
213
 
            pps->b_slice_group_change_direction = bs_read( s, 1 );
214
 
            pps->i_slice_group_change_rate = bs_read_ue( s ) + 1;
215
 
        }
216
 
        else if( pps->i_slice_group_map_type == 6 )
217
 
        {
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++ )
220
 
            {
221
 
               /*  FIXME */
222
 
                /* pps->i_slice_group_id = bs_read( s, ceil( log2( pps->i_pic_size_in_map_units +1 ) ) ); */
223
 
            }
224
 
        }
225
 
    }
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 );
230
 
 
231
 
    pps->i_pic_init_qp = bs_read_se( s ) + 26;
232
 
    pps->i_pic_init_qs = bs_read_se( s ) + 26;
233
 
 
234
 
    pps->i_chroma_qp_index_offset = bs_read_se( s );
235
 
 
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 );
239
 
 
240
 
    if( bs_eof( s ) )
241
 
    {
242
 
        /* no rbsp trailing */
243
 
        fprintf( stderr, "incomplete PPS\n" );
244
 
        goto error;
245
 
    }
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 );
256
 
 
257
 
    return id;
258
 
error:
259
 
    pps->i_id = -1;
260
 
    return -1;
261
 
}
262