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 int vlc_module_set ( module_t
*, enum vlc_module_properties
, void *);
101 void Close( vlc_object_t
* );
102 __attribute__((visibility("default"))) int vlc_entry__0_9_0f ( module_t
*p_module
) {
104 module_t
*p_submodule
= p_module
;
105 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
;
115 int i_bottom_field_flag
;
117 int i_delta_pic_order_cnt0
;
119 struct decoder_sys_t
{
127 int i_pic_order_cnt_type
;
130 enum { NAL_SLICE
= 1, NAL_SLICE_IDR
= 5, NAL_SPS
= 7, NAL_AU_DELIMITER
= 9 };
131 static block_t
*ParseNALBlock( decoder_t
*, block_t
* );
132 int U16_AT ( uint8_t * );
133 int Open( vlc_object_t
*p_this
) {
134 decoder_t
*p_dec
= (decoder_t
*)p_this
;
135 decoder_sys_t
*p_sys
;
136 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 ) ) {
139 if( ( p_dec
->p_sys
= p_sys
= malloc( sizeof(decoder_sys_t
) ) ) == ((void *)0) ) {
140 uint8_t *p
= &((uint8_t*)p_dec
->fmt_in
.p_extra
)[4];
147 int i_length
= U16_AT( p
);
148 block_t
*p_sps
= nal_get_annexeb( p_dec
, p
+ 2, i_length
);
149 ParseNALBlock( p_dec
, p_sps
);
153 static inline int bs_read_ue( bs_t
*s
) {
155 while( bs_read1( s
) == 0 && s
->p
< s
->p_end
&& i
< 32 ) {
158 return( ( 1 << i
) - 1 + bs_read( s
, i
) );
160 static inline int bs_read_se( bs_t
*s
) {
161 int val
= bs_read_ue( s
);
163 block_t
*ParseNALBlock( decoder_t
*p_dec
, block_t
*p_frag
)
165 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
166 block_t
*p_pic
= ((void *)0);
167 const int i_nal_type
= p_frag
->p_buffer
[4]&0x1f;
168 if( ( !p_sys
->b_sps
|| !p_sys
->b_pps
) && i_nal_type
>= NAL_SLICE
&& i_nal_type
<= NAL_SLICE_IDR
) {
170 else if( i_nal_type
>= NAL_SLICE
&& i_nal_type
<= NAL_SLICE_IDR
) {
171 int i_dec
= 0, i_first_mb
, i_slice_type
;
174 i_first_mb
= bs_read_ue( &s
);
175 switch( (i_slice_type
= bs_read_ue( &s
)) ) {
177 if( p_sys
->i_pic_order_cnt_type
== 0 ) {
178 slice
.i_delta_pic_order_cnt0
= bs_read_se( &s
);
180 if( slice
.i_frame_num
!= p_sys
->slice
.i_frame_num
181 || slice
.i_nal_ref_idc
!= p_sys
->slice
.i_nal_ref_idc
)
182 if( (slice
.i_bottom_field_flag
!= -1)
183 && (slice
.i_bottom_field_flag
!= p_sys
->slice
.i_bottom_field_flag
) )
184 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
) )
186 if( !p_sys
->b_header
&& p_sys
->slice
.i_frame_type
!= 0x0002)
188 if( p_sys
->slice
.i_frame_type
== 0x0002 && p_sys
->p_sps
&& p_sys
->p_pps
) {
189 block_t
*p_sps
= block_Duplicate( p_sys
->p_sps
);
190 block_t
*p_pps
= block_Duplicate( p_sys
->p_pps
);
191 p_sps
->i_pts
= p_sys
->p_frame
->i_pts
;
192 block_ChainAppend( &p_sps
, p_pps
);
193 block_ChainAppend( &p_sps
, p_sys
->p_frame
);
195 p_pic
= block_ChainGather( p_sps
);
199 else if( i_nal_type
== NAL_SPS
) {
201 if( p_sys
->i_pic_order_cnt_type
== 0 ) {
203 else if( p_sys
->i_pic_order_cnt_type
== 1 ) {
205 i_cycle
= bs_read_ue( &s
);
206 while( i_cycle
> 0 ) {
213 if( !p_sys
->b_header
&& p_sys
->slice
.i_frame_type
!= 0x0002)
215 if( p_sys
->slice
.i_frame_type
== 0x0002
216 && p_sys
->p_sps
&& p_sys
->p_pps
)
218 block_t
*p_sps
= block_Duplicate( p_sys
->p_sps
);
219 block_t
*p_pps
= block_Duplicate( p_sys
->p_pps
);
220 p_sps
->i_dts
= p_sys
->p_frame
->i_dts
;
221 p_sps
->i_pts
= p_sys
->p_frame
->i_pts
;
222 block_ChainAppend( &p_sps
, p_pps
);
223 block_ChainAppend( &p_sps
, p_sys
->p_frame
);
224 p_pic
= block_ChainGather( p_sps
);
226 p_pic
->i_flags
|= p_sys
->slice
.i_frame_type
;
229 block_ChainAppend( &p_sys
->p_frame
, p_frag
);