2 /* { dg-do compile } */
3 /* { dg-options "-O2 -g -funroll-loops" } */
4 typedef int vlc_bool_t;
5 typedef __SIZE_TYPE__ size_t;
6 typedef struct vlc_object_t vlc_object_t;
7 typedef long long int64_t;
8 #if(__SIZEOF_INT__ >= 4)
9 typedef unsigned int uint32_t;
11 typedef unsigned long uint32_t;
13 typedef unsigned char uint8_t;
14 typedef int64_t mtime_t;
15 typedef uint32_t vlc_fourcc_t;
16 typedef struct module_t module_t;
17 typedef struct es_format_t es_format_t;
18 typedef struct decoder_t decoder_t;
19 typedef struct decoder_sys_t decoder_sys_t;
20 typedef struct block_t block_t;
21 extern void* malloc (size_t);
22 enum vlc_module_properties {
23 VLC_MODULE_CB_OPEN, VLC_MODULE_CB_CLOSE, VLC_MODULE_NAME, };
37 block_t* block_New(void*, size_t);
38 block_t *nal_get_annexeb(decoder_t *, uint8_t *, int);
39 block_t *block_ChainGather (block_t *);
40 static inline block_t *block_Duplicate( block_t *p_block ) {
41 block_t *p_dup = block_New( ((void *)0), p_block->i_buffer );
42 p_dup->i_dts = p_block->i_dts;
43 p_dup->i_pts = p_block->i_pts;
45 static inline void block_ChainAppend( block_t **pp_list, block_t *p_block ) {
46 if( *pp_list == ((void *)0) ) {
49 block_t *p = *pp_list;
50 while( p->p_next ) p = p->p_next;
55 decoder_sys_t * p_sys;
63 static inline uint32_t bs_read( bs_t *s, int i_count ) {
64 static uint32_t i_mask[33] = {
65 0x00, 0x1fffffff,0x3fffffff,0x7fffffff,0xffffffff};
67 uint32_t i_result = 0;
68 while( i_count > 0 ) {
69 if( s->p >= s->p_end ) {
72 if( ( i_shr = s->i_left - i_count ) >= 0 ) {
73 i_result |= ( *s->p >> i_shr )&i_mask[i_count];
81 i_result |= (*s->p&i_mask[s->i_left]) << -i_shr;
87 static inline uint32_t bs_read1( bs_t *s ) {
88 if( s->p < s->p_end ) {
89 unsigned int i_result;
91 i_result = ( *s->p >> s->i_left )&0x01;
92 if( s->i_left == 0 ) {
99 int Open ( vlc_object_t * );
100 void Close( vlc_object_t * );
101 __attribute__((visibility("default"))) int vlc_entry__0_9_0f ( module_t *p_module ) {
103 module_t *p_submodule = p_module;
104 if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, (void *)(Open)) || vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, (void *)(Close))) goto error;
114 int i_bottom_field_flag;
116 int i_delta_pic_order_cnt0;
118 struct decoder_sys_t {
126 int i_pic_order_cnt_type;
129 enum { NAL_SLICE = 1, NAL_SLICE_IDR = 5, NAL_SPS = 7, NAL_AU_DELIMITER= 9 };
130 static block_t *ParseNALBlock( decoder_t *, block_t * );
131 int Open( vlc_object_t *p_this ) {
132 decoder_t *p_dec = (decoder_t*)p_this;
133 decoder_sys_t *p_sys;
134 if( p_dec->fmt_in.i_codec != ( ((uint32_t)'h') | ( ((uint32_t)'2') << 8 ) | ( ((uint32_t)'6') << 16 ) | ( ((uint32_t)'4') << 24 ) ) && ( p_dec->fmt_in.i_codec != ( ((uint32_t)'a') | ( ((uint32_t)'v') << 8 ) | ( ((uint32_t)'c') << 16 ) | ( ((uint32_t)'1') << 24 ) ) || p_dec->fmt_in.i_extra < 7 ) ) {
137 if( ( p_dec->p_sys = p_sys = malloc( sizeof(decoder_sys_t) ) ) == ((void *)0) ) {
138 uint8_t *p = &((uint8_t*)p_dec->fmt_in.p_extra)[4];
145 int i_length = U16_AT( p );
146 block_t *p_sps = nal_get_annexeb( p_dec, p + 2, i_length );
147 ParseNALBlock( p_dec, p_sps );
151 static inline int bs_read_ue( bs_t *s ) {
153 while( bs_read1( s ) == 0 && s->p < s->p_end && i < 32 ) {
156 return( ( 1 << i) - 1 + bs_read( s, i ) );
158 static inline int bs_read_se( bs_t *s ) {
159 int val = bs_read_ue( s );
161 block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
163 decoder_sys_t *p_sys = p_dec->p_sys;
164 block_t *p_pic = ((void *)0);
165 const int i_nal_type = p_frag->p_buffer[4]&0x1f;
166 if( ( !p_sys->b_sps || !p_sys->b_pps ) && i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR ) {
168 else if( i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR ) {
169 int i_dec = 0, i_first_mb, i_slice_type;
172 i_first_mb = bs_read_ue( &s );
173 switch( (i_slice_type = bs_read_ue( &s )) ) {
175 if( p_sys->i_pic_order_cnt_type == 0 ) {
176 slice.i_delta_pic_order_cnt0 = bs_read_se( &s );
178 if( slice.i_frame_num != p_sys->slice.i_frame_num
179 || slice.i_nal_ref_idc != p_sys->slice.i_nal_ref_idc )
180 if( (slice.i_bottom_field_flag != -1)
181 && (slice.i_bottom_field_flag != p_sys->slice.i_bottom_field_flag) )
182 if( p_sys->i_pic_order_cnt_type == 0 && ( slice.i_nal_type != p_sys->slice.i_nal_type || slice.i_idr_pic_id != p_sys->slice.i_idr_pic_id ) )
184 if( !p_sys->b_header && p_sys->slice.i_frame_type != 0x0002)
186 if( p_sys->slice.i_frame_type == 0x0002 && p_sys->p_sps && p_sys->p_pps ) {
187 block_t *p_sps = block_Duplicate( p_sys->p_sps );
188 block_t *p_pps = block_Duplicate( p_sys->p_pps );
189 p_sps->i_pts = p_sys->p_frame->i_pts;
190 block_ChainAppend( &p_sps, p_pps );
191 block_ChainAppend( &p_sps, p_sys->p_frame );
193 p_pic = block_ChainGather( p_sps );
197 else if( i_nal_type == NAL_SPS ) {
199 if( p_sys->i_pic_order_cnt_type == 0 ) {
201 else if( p_sys->i_pic_order_cnt_type == 1 ) {
203 i_cycle = bs_read_ue( &s );
204 while( i_cycle > 0 ) {
211 if( !p_sys->b_header && p_sys->slice.i_frame_type != 0x0002)
213 if( p_sys->slice.i_frame_type == 0x0002
214 && p_sys->p_sps && p_sys->p_pps )
216 block_t *p_sps = block_Duplicate( p_sys->p_sps );
217 block_t *p_pps = block_Duplicate( p_sys->p_pps );
218 p_sps->i_dts = p_sys->p_frame->i_dts;
219 p_sps->i_pts = p_sys->p_frame->i_pts;
220 block_ChainAppend( &p_sps, p_pps );
221 block_ChainAppend( &p_sps, p_sys->p_frame );
222 p_pic = block_ChainGather( p_sps );
224 p_pic->i_flags |= p_sys->slice.i_frame_type;
227 block_ChainAppend( &p_sys->p_frame, p_frag );