Mercurial > mplayer.hg
annotate libmpdemux/mpeg_hdr.c @ 22188:b9fa8b0ddab9
strncat() misuses, may have been exploitable.
Reported by Sascha Sommer.
author | rtogni |
---|---|
date | Sun, 11 Feb 2007 18:00:06 +0000 |
parents | 62bf4204eed4 |
children | 328d1b36952a |
rev | line source |
---|---|
2565 | 1 |
2 // based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
3 | |
15225 | 4 #include <inttypes.h> |
2565 | 5 #include <stdio.h> |
14886 | 6 #include <stdlib.h> |
21947 | 7 #include <string.h> |
2565 | 8 |
9 #include "config.h" | |
10 #include "mpeg_hdr.h" | |
11 | |
18398
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
12 #include "mp_msg.h" |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
13 |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
14 static float frameratecode2framerate[16] = { |
2565 | 15 0, |
5441 | 16 // Official mpeg1/2 framerates: (1-8) |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
17 24000.0/1001, 24,25, |
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
18 30000.0/1001, 30,50, |
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
19 60000.0/1001, 60, |
5441 | 20 // Xing's 15fps: (9) |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
21 15, |
5441 | 22 // libmpeg3's "Unofficial economy rates": (10-13) |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
23 5,10,12,15, |
5441 | 24 // some invalid ones: (14-15) |
25 0,0 | |
2565 | 26 }; |
27 | |
28 | |
29 int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer) | |
30 { | |
31 int width, height; | |
32 | |
33 if ((buffer[6] & 0x20) != 0x20){ | |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
34 fprintf(stderr, "missing marker bit!\n"); |
2565 | 35 return 1; /* missing marker_bit */ |
36 } | |
37 | |
38 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; | |
39 | |
40 picture->display_picture_width = (height >> 12); | |
41 picture->display_picture_height = (height & 0xfff); | |
42 | |
43 width = ((height >> 12) + 15) & ~15; | |
44 height = ((height & 0xfff) + 15) & ~15; | |
45 | |
46 picture->aspect_ratio_information = buffer[3] >> 4; | |
47 picture->frame_rate_code = buffer[3] & 15; | |
48 picture->fps=frameratecode2framerate[picture->frame_rate_code]; | |
49 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6); | |
50 picture->mpeg1 = 1; | |
51 picture->picture_structure = 3; //FRAME_PICTURE; | |
52 picture->display_time=100; | |
53 return 0; | |
54 } | |
55 | |
56 static int header_process_sequence_extension (mp_mpeg_header_t * picture, | |
57 unsigned char * buffer) | |
58 { | |
59 /* check chroma format, size extensions, marker bit */ | |
12562 | 60 |
61 if ( ((buffer[1] & 0x06) == 0x00) || | |
62 ((buffer[1] & 0x01) != 0x00) || (buffer[2] & 0xe0) || | |
63 ((buffer[3] & 0x01) != 0x01) ) | |
2565 | 64 return 1; |
65 | |
66 picture->progressive_sequence = (buffer[1] >> 3) & 1; | |
67 picture->mpeg1 = 0; | |
68 return 0; | |
69 } | |
70 | |
71 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer) | |
72 { | |
73 picture->picture_structure = buffer[2] & 3; | |
74 picture->top_field_first = buffer[3] >> 7; | |
75 picture->repeat_first_field = (buffer[3] >> 1) & 1; | |
76 picture->progressive_frame = buffer[4] >> 7; | |
77 | |
78 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3: | |
79 picture->display_time=100; | |
80 if(picture->repeat_first_field){ | |
81 if(picture->progressive_sequence){ | |
82 if(picture->top_field_first) | |
83 picture->display_time+=200; | |
84 else | |
85 picture->display_time+=100; | |
86 } else | |
87 if(picture->progressive_frame){ | |
88 picture->display_time+=50; | |
89 } | |
90 } | |
91 //temopral hack. We calc time on every field, so if we have 2 fields | |
92 // interlaced we'll end with double time for 1 frame | |
93 if( picture->picture_structure!=3 ) picture->display_time/=2; | |
94 return 0; | |
95 } | |
96 | |
97 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer) | |
98 { | |
99 switch (buffer[0] & 0xf0) { | |
100 case 0x10: /* sequence extension */ | |
101 return header_process_sequence_extension (picture, buffer); | |
102 case 0x80: /* picture coding extension */ | |
103 return header_process_picture_coding_extension (picture, buffer); | |
104 } | |
105 return 0; | |
106 } | |
107 | |
18398
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
108 float mpeg12_aspect_info(mp_mpeg_header_t *picture) |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
109 { |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
110 float aspect = 0.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
111 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
112 switch(picture->aspect_ratio_information) { |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
113 case 2: // PAL/NTSC SVCD/DVD 4:3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
114 case 8: // PAL VCD 4:3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
115 case 12: // NTSC VCD 4:3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
116 aspect=4.0/3.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
117 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
118 case 3: // PAL/NTSC Widescreen SVCD/DVD 16:9 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
119 case 6: // (PAL?)/NTSC Widescreen SVCD 16:9 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
120 aspect=16.0/9.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
121 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
122 case 4: // according to ISO-138182-2 Table 6.3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
123 aspect=2.21; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
124 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
125 case 1: // VGA 1:1 - do not prescale |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
126 case 9: // Movie Type ??? / 640x480 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
127 aspect=0.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
128 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
129 default: |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
130 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Detected unknown aspect_ratio_information in mpeg sequence header.\n" |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
131 "Please report the aspect value (%i) along with the movie type (VGA,PAL,NTSC," |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
132 "SECAM) and the movie resolution (720x576,352x240,480x480,...) to the MPlayer" |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
133 " developers, so that we can add support for it!\nAssuming 1:1 aspect for now.\n", |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
134 picture->aspect_ratio_information); |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
135 } |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
136 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
137 return aspect; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
138 } |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
139 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
140 //MPEG4 HEADERS |
14967 | 141 unsigned char mp_getbits(unsigned char *buffer, unsigned int from, unsigned char len) |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
142 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
143 unsigned int n; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
144 unsigned char m, u, l, y; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
145 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
146 n = from / 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
147 m = from % 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
148 u = 8 - m; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
149 l = (len > u ? len - u : 0); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
150 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
151 y = (buffer[n] << m); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
152 if(8 > len) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
153 y >>= (8-len); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
154 if(l) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
155 y |= (buffer[n+1] >> (8-l)); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
156 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
157 //fprintf(stderr, "GETBITS(%d -> %d): bytes=0x%x 0x%x, n=%d, m=%d, l=%d, u=%d, Y=%d\n", |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
158 // from, (int) len, (int) buffer[n],(int) buffer[n+1], n, (int) m, (int) l, (int) u, (int) y); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
159 return y; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
160 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
161 |
21947 | 162 static inline unsigned int mp_getbits16(unsigned char *buffer, unsigned int from, unsigned char len) |
163 { | |
164 if(len > 8) | |
165 return (mp_getbits(buffer, from, len - 8) << 8) | mp_getbits(buffer, from + len - 8, 8); | |
166 else | |
167 return mp_getbits(buffer, from, len); | |
168 } | |
169 | |
14967 | 170 #define getbits mp_getbits |
21947 | 171 #define getbits16 mp_getbits16 |
14967 | 172 |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
173 static int read_timeinc(mp_mpeg_header_t * picture, unsigned char * buffer, int n) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
174 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
175 if(picture->timeinc_bits > 8) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
176 picture->timeinc_unit = getbits(buffer, n, picture->timeinc_bits - 8) << 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
177 n += picture->timeinc_bits - 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
178 picture->timeinc_unit |= getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
179 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
180 } else { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
181 picture->timeinc_unit = getbits(buffer, n, picture->timeinc_bits); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
182 n += picture->timeinc_bits; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
183 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
184 //fprintf(stderr, "TIMEINC2: %d, bits: %d\n", picture->timeinc_unit, picture->timeinc_bits); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
185 return n; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
186 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
187 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
188 int mp4_header_process_vol(mp_mpeg_header_t * picture, unsigned char * buffer) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
189 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
190 unsigned int n, aspect=0, aspectw=0, aspecth=0, x=1, v; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
191 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
192 //begins with 0x0000012x |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
193 picture->fps = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
194 picture->timeinc_bits = picture->timeinc_resolution = picture->timeinc_unit = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
195 n = 9; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
196 if(getbits(buffer, n, 1)) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
197 n += 7; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
198 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
199 aspect=getbits(buffer, n, 4); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
200 n += 4; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
201 if(aspect == 0x0f) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
202 aspectw = getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
203 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
204 aspecth = getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
205 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
206 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
207 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
208 if(getbits(buffer, n, 1)) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
209 n += 4; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
210 if(getbits(buffer, n, 1)) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
211 n += 79; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
212 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
213 } else n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
214 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
215 n+=3; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
216 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
217 picture->timeinc_resolution = getbits(buffer, n, 8) << 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
218 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
219 picture->timeinc_resolution |= getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
220 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
221 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
222 picture->timeinc_bits = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
223 v = picture->timeinc_resolution - 1; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
224 while(v && (x<16)) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
225 v>>=1; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
226 picture->timeinc_bits++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
227 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
228 picture->timeinc_bits = (picture->timeinc_bits > 1 ? picture->timeinc_bits : 1); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
229 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
230 n++; //marker bit |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
231 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
232 if(getbits(buffer, n, 1)) { //fixed_vop_timeinc |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
233 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
234 n = read_timeinc(picture, buffer, n); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
235 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
236 if(picture->timeinc_unit) |
16319
798d9be2337f
multiplying fps by 10000 is no more necessary (when determining mp4v and h264 framerate)
nicodvb
parents:
16184
diff
changeset
|
237 picture->fps = (float) picture->timeinc_resolution / (float) picture->timeinc_unit; |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
238 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
239 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
240 //fprintf(stderr, "ASPECT: %d, PARW=%d, PARH=%d, TIMEINCRESOLUTION: %d, FIXED_TIMEINC: %d (number of bits: %d), FPS: %u\n", |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
241 // aspect, aspectw, aspecth, picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_bits, picture->fps); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
242 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
243 return 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
244 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
245 |
14887 | 246 void mp4_header_process_vop(mp_mpeg_header_t * picture, unsigned char * buffer) |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
247 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
248 int n; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
249 n = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
250 picture->picture_type = getbits(buffer, n, 2); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
251 n += 2; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
252 while(getbits(buffer, n, 1)) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
253 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
254 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
255 getbits(buffer, n, 1); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
256 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
257 n = read_timeinc(picture, buffer, n); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
258 } |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
259 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
260 #define min(a, b) ((a) <= (b) ? (a) : (b)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
261 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
262 static unsigned int read_golomb(unsigned char *buffer, unsigned int *init) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
263 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
264 unsigned int x, v = 0, v2 = 0, m, len = 0, n = *init; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
265 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
266 while(getbits(buffer, n++, 1) == 0) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
267 len++; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
268 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
269 x = len + n; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
270 while(n < x) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
271 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
272 m = min(x - n, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
273 v |= getbits(buffer, n, m); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
274 n += m; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
275 if(x - n > 8) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
276 v <<= 8; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
277 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
278 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
279 v2 = 1; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
280 for(n = 0; n < len; n++) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
281 v2 <<= 1; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
282 v2 = (v2 - 1) + v; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
283 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
284 //fprintf(stderr, "READ_GOLOMB(%u), V=2^%u + %u-1 = %u\n", *init, len, v, v2); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
285 *init = x; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
286 return v2; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
287 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
288 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
289 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
290 static int h264_parse_vui(mp_mpeg_header_t * picture, unsigned char * buf, unsigned int n) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
291 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
292 unsigned int overscan, vsp_color, chroma, timing, fixed_fps; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
293 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
294 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
295 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
296 picture->aspect_ratio_information = getbits(buf, n, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
297 n += 8; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
298 if(picture->aspect_ratio_information == 255) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
299 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
300 picture->display_picture_width = (getbits(buf, n, 8) << 8) | getbits(buf, n + 8, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
301 n += 16; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
302 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
303 picture->display_picture_height = (getbits(buf, n, 8) << 8) | getbits(buf, n + 8, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
304 n += 16; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
305 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
306 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
307 |
14887 | 308 if((overscan=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
309 n++; |
14887 | 310 if((vsp_color=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
311 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
312 n += 4; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
313 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
314 n += 24; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
315 } |
14887 | 316 if((chroma=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
317 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
318 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
319 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
320 } |
14887 | 321 if((timing=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
322 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
323 picture->timeinc_unit = (getbits(buf, n, 8) << 24) | (getbits(buf, n+8, 8) << 16) | (getbits(buf, n+16, 8) << 8) | getbits(buf, n+24, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
324 n += 32; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
325 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
326 picture->timeinc_resolution = (getbits(buf, n, 8) << 24) | (getbits(buf, n+8, 8) << 16) | (getbits(buf, n+16, 8) << 8) | getbits(buf, n+24, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
327 n += 32; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
328 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
329 fixed_fps = getbits(buf, n, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
330 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
331 if(picture->timeinc_unit > 0 && picture->timeinc_resolution > 0) |
16319
798d9be2337f
multiplying fps by 10000 is no more necessary (when determining mp4v and h264 framerate)
nicodvb
parents:
16184
diff
changeset
|
332 picture->fps = (float) picture->timeinc_resolution / (float) picture->timeinc_unit; |
17952
7ad7d20cfadc
H264: when fixed_fps is set the framerate is expressed in fields per second, so it must be halved
nicodvb
parents:
16319
diff
changeset
|
333 if(fixed_fps) |
7ad7d20cfadc
H264: when fixed_fps is set the framerate is expressed in fields per second, so it must be halved
nicodvb
parents:
16319
diff
changeset
|
334 picture->fps /= 2; |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
335 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
336 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
337 //fprintf(stderr, "H264_PARSE_VUI, OVESCAN=%u, VSP_COLOR=%u, CHROMA=%u, TIMING=%u, DISPW=%u, DISPH=%u, TIMERES=%u, TIMEINC=%u, FIXED_FPS=%u\n", overscan, vsp_color, chroma, timing, picture->display_picture_width, picture->display_picture_height, |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
338 // picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_unit, fixed_fps); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
339 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
340 return n; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
341 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
342 |
21953 | 343 static int mp_unescape03(unsigned char *buf, int len); |
344 | |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
345 int h264_parse_sps(mp_mpeg_header_t * picture, unsigned char * buf, int len) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
346 { |
21953 | 347 unsigned int n = 0, v, i, mbh; |
15073 | 348 int frame_mbs_only; |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
349 |
21953 | 350 len = mp_unescape03(buf, len); |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
351 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
352 picture->fps = picture->timeinc_unit = picture->timeinc_resolution = 0; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
353 n = 24; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
354 read_golomb(buf, &n); |
15618 | 355 if(buf[0] >= 100){ |
356 if(read_golomb(buf, &n) == 3) | |
357 n++; | |
358 read_golomb(buf, &n); | |
359 read_golomb(buf, &n); | |
360 n++; | |
361 if(getbits(buf, n++, 1)){ | |
362 //FIXME scaling matrix | |
363 } | |
364 } | |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
365 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
366 v = read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
367 if(v == 0) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
368 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
369 else if(v == 1) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
370 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
371 getbits(buf, n++, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
372 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
373 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
374 v = read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
375 for(i = 0; i < v; i++) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
376 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
377 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
378 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
379 getbits(buf, n++, 1); |
15073 | 380 picture->display_picture_width = 16 *(read_golomb(buf, &n)+1); |
381 mbh = read_golomb(buf, &n)+1; | |
382 frame_mbs_only = getbits(buf, n++, 1); | |
383 picture->display_picture_height = 16 * (2 - frame_mbs_only) * mbh; | |
384 if(!frame_mbs_only) | |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
385 getbits(buf, n++, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
386 getbits(buf, n++, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
387 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
388 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
389 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
390 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
391 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
392 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
393 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
394 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
395 n = h264_parse_vui(picture, buf, n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
396 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
397 return n; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
398 } |
21947 | 399 |
400 static int mp_unescape03(unsigned char *buf, int len) | |
401 { | |
402 unsigned char *dest; | |
403 int i, j, skip; | |
404 | |
405 dest = malloc(len); | |
406 if(! dest) | |
407 return 0; | |
408 | |
409 j = i = skip = 0; | |
410 while(i <= len-3) | |
411 { | |
412 if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 3) | |
413 { | |
414 dest[j] = dest[j+1] = 0; | |
415 j += 2; | |
416 i += 3; | |
417 skip++; | |
418 } | |
419 else | |
420 { | |
421 dest[j] = buf[i]; | |
422 j++; | |
423 i++; | |
424 } | |
425 } | |
426 dest[j] = buf[len-2]; | |
427 dest[j+1] = buf[len-1]; | |
428 len -= skip; | |
429 memcpy(buf, dest, len); | |
430 free(dest); | |
431 | |
432 return len; | |
433 } | |
434 | |
435 int mp_vc1_decode_sequence_header(mp_mpeg_header_t * picture, unsigned char * buf, int len) | |
436 { | |
437 int n, x; | |
438 | |
439 len = mp_unescape03(buf, len); | |
440 | |
441 picture->display_picture_width = picture->display_picture_height = 0; | |
442 picture->fps = 0; | |
443 n = 0; | |
444 x = getbits(buf, n, 2); | |
445 n += 2; | |
446 if(x != 3) //not advanced profile | |
447 return 0; | |
448 | |
449 getbits16(buf, n, 14); | |
450 n += 14; | |
451 picture->display_picture_width = getbits16(buf, n, 12) * 2 + 2; | |
452 n += 12; | |
453 picture->display_picture_height = getbits16(buf, n, 12) * 2 + 2; | |
454 n += 12; | |
455 getbits(buf, n, 6); | |
456 n += 6; | |
457 x = getbits(buf, n, 1); | |
458 n += 1; | |
459 if(x) //display info | |
460 { | |
461 getbits16(buf, n, 14); | |
462 n += 14; | |
463 getbits16(buf, n, 14); | |
464 n += 14; | |
465 if(getbits(buf, n++, 1)) //aspect ratio | |
466 { | |
467 x = getbits(buf, n, 4); | |
468 n += 4; | |
469 if(x == 15) | |
470 { | |
471 getbits16(buf, n, 16); | |
472 n += 16; | |
473 } | |
474 } | |
475 | |
476 if(getbits(buf, n++, 1)) //framerates | |
477 { | |
478 int frexp=0, frnum=0, frden=0; | |
479 | |
480 if(getbits(buf, n++, 1)) | |
481 { | |
482 frexp = getbits16(buf, n, 16); | |
483 n += 16; | |
484 picture->fps = (double) (frexp+1) / 32.0; | |
485 } | |
486 else | |
487 { | |
488 float frates[] = {0, 24000, 25000, 30000, 50000, 60000, 48000, 72000, 0}; | |
489 float frdivs[] = {0, 1000, 1001, 0}; | |
490 | |
491 frnum = getbits(buf, n, 8); | |
492 n += 8; | |
493 frden = getbits(buf, n, 4); | |
494 n += 4; | |
495 if((frden == 1 || frden == 2) && (frnum < 8)) | |
496 picture->fps = frates[frnum] / frdivs[frden]; | |
497 } | |
498 } | |
499 } | |
500 | |
501 //free(dest); | |
502 return 1; | |
503 } |