annotate libmpdemux/mpeg_hdr.c @ 14938:25df9508f9a8

Mark modified files as such to comply more closely with GPL ¡ø2a.
author diego
date Fri, 11 Mar 2005 02:40:28 +0000
parents e9c9fbc78092
children d901658f487d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
1
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
2 // based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
3
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
4 // #include <inttypes.h>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
5 #include <stdio.h>
14886
a109ae86ba63 missing #include (for malloc and free)
rathann
parents: 14798
diff changeset
6 #include <stdlib.h>
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
7
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
8 #include "config.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
9 #include "mpeg_hdr.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
10
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
11 static int frameratecode2framerate[16] = {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
12 0,
5441
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
13 // Official mpeg1/2 framerates: (1-8)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
14 24000*10000/1001, 24*10000,25*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
15 30000*10000/1001, 30*10000,50*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
16 60000*10000/1001, 60*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
17 // Xing's 15fps: (9)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
18 15*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
19 // libmpeg3's "Unofficial economy rates": (10-13)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
20 5*10000,10*10000,12*10000,15*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
21 // some invalid ones: (14-15)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
22 0,0
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
23 };
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
24
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
25
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
26 int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
27 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
28 int width, height;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
29
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
30 if ((buffer[6] & 0x20) != 0x20){
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
31 fprintf(stderr, "missing marker bit!\n");
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
32 return 1; /* missing marker_bit */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
33 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
34
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
35 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
36
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
37 picture->display_picture_width = (height >> 12);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
38 picture->display_picture_height = (height & 0xfff);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
39
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
40 width = ((height >> 12) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
41 height = ((height & 0xfff) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
42
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
43 picture->aspect_ratio_information = buffer[3] >> 4;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
44 picture->frame_rate_code = buffer[3] & 15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
45 picture->fps=frameratecode2framerate[picture->frame_rate_code];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
46 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
47 picture->mpeg1 = 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
48 picture->picture_structure = 3; //FRAME_PICTURE;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
49 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
50 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
51 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
52
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
53 static int header_process_sequence_extension (mp_mpeg_header_t * picture,
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
54 unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
55 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
56 /* check chroma format, size extensions, marker bit */
12562
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
57
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
58 if ( ((buffer[1] & 0x06) == 0x00) ||
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
59 ((buffer[1] & 0x01) != 0x00) || (buffer[2] & 0xe0) ||
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
60 ((buffer[3] & 0x01) != 0x01) )
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
61 return 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
62
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
63 picture->progressive_sequence = (buffer[1] >> 3) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
64 picture->mpeg1 = 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
65 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
66 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
67
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
68 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
69 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
70 picture->picture_structure = buffer[2] & 3;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
71 picture->top_field_first = buffer[3] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
72 picture->repeat_first_field = (buffer[3] >> 1) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
73 picture->progressive_frame = buffer[4] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
74
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
75 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
76 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
77 if(picture->repeat_first_field){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
78 if(picture->progressive_sequence){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
79 if(picture->top_field_first)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
80 picture->display_time+=200;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
81 else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
82 picture->display_time+=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
83 } else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
84 if(picture->progressive_frame){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
85 picture->display_time+=50;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
86 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
87 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
88 //temopral hack. We calc time on every field, so if we have 2 fields
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
89 // interlaced we'll end with double time for 1 frame
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
90 if( picture->picture_structure!=3 ) picture->display_time/=2;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
91 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
92 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
93
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
94 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
95 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
96 switch (buffer[0] & 0xf0) {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
97 case 0x10: /* sequence extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
98 return header_process_sequence_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
99 case 0x80: /* picture coding extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
100 return header_process_picture_coding_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
101 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
102 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
103 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
104
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
105
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
106 //MPEG4 HEADERS
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
107 static unsigned char getbits(unsigned char *buffer, unsigned int from, unsigned char len)
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
108 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
109 unsigned int n;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
110 unsigned char m, u, l, y;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
111
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
112 n = from / 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
113 m = from % 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
114 u = 8 - m;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
115 l = (len > u ? len - u : 0);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
116
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
117 y = (buffer[n] << m);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
118 if(8 > len)
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
119 y >>= (8-len);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
120 if(l)
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
121 y |= (buffer[n+1] >> (8-l));
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
122
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
123 //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
124 // 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
125 return y;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
126 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
127
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
128 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
129 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
130 if(picture->timeinc_bits > 8) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
131 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
132 n += picture->timeinc_bits - 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
133 picture->timeinc_unit |= getbits(buffer, n, 8);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
134 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
135 } else {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
136 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
137 n += picture->timeinc_bits;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
138 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
139 //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
140 return n;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
141 }
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 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
144 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
145 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
146
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
147 //begins with 0x0000012x
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
148 picture->fps = 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
149 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
150 n = 9;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
151 if(getbits(buffer, n, 1))
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
152 n += 7;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
153 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
154 aspect=getbits(buffer, n, 4);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
155 n += 4;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
156 if(aspect == 0x0f) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
157 aspectw = getbits(buffer, n, 8);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
158 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
159 aspecth = getbits(buffer, n, 8);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
160 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
161 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
162
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
163 if(getbits(buffer, n, 1)) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
164 n += 4;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
165 if(getbits(buffer, n, 1))
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
166 n += 79;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
167 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
168 } else n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
169
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
170 n+=3;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
171
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
172 picture->timeinc_resolution = getbits(buffer, n, 8) << 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
173 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
174 picture->timeinc_resolution |= getbits(buffer, n, 8);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
175 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
176
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
177 picture->timeinc_bits = 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
178 v = picture->timeinc_resolution - 1;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
179 while(v && (x<16)) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
180 v>>=1;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
181 picture->timeinc_bits++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
182 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
183 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
184
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
185 n++; //marker bit
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 if(getbits(buffer, n, 1)) { //fixed_vop_timeinc
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
188 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
189 n = read_timeinc(picture, buffer, n);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
190
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
191 if(picture->timeinc_unit)
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
192 picture->fps = (picture->timeinc_resolution * 10000) / picture->timeinc_unit;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
193 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
194
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
195 //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
196 // 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
197
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
198 return 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
199 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
200
14887
rathann
parents: 14886
diff changeset
201 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
202 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
203 int n;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
204 n = 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
205 picture->picture_type = getbits(buffer, n, 2);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
206 n += 2;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
207 while(getbits(buffer, n, 1))
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
208 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
209 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
210 getbits(buffer, n, 1);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
211 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
212 n = read_timeinc(picture, buffer, n);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
213 }
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
214
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
215 #define min(a, b) ((a) <= (b) ? (a) : (b))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
216
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
217 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
218 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
219 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
220
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
221 while(getbits(buffer, n++, 1) == 0)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
222 len++;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
223
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
224 x = len + n;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
225 while(n < x)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
226 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
227 m = min(x - n, 8);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
228 v |= getbits(buffer, n, m);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
229 n += m;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
230 if(x - n > 8)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
231 v <<= 8;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
232 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
233
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
234 v2 = 1;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
235 for(n = 0; n < len; n++)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
236 v2 <<= 1;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
237 v2 = (v2 - 1) + v;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
238
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
239 //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
240 *init = x;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
241 return v2;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
242 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
243
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
244
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
245 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
246 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
247 unsigned int overscan, vsp_color, chroma, timing, fixed_fps;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
248
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
249 if(getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
250 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
251 picture->aspect_ratio_information = getbits(buf, n, 8);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
252 n += 8;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
253 if(picture->aspect_ratio_information == 255)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
254 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
255 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
256 n += 16;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
257
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
258 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
259 n += 16;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
260 }
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
14887
rathann
parents: 14886
diff changeset
263 if((overscan=getbits(buf, n++, 1)))
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
264 n++;
14887
rathann
parents: 14886
diff changeset
265 if((vsp_color=getbits(buf, n++, 1)))
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
266 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
267 n += 4;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
268 if(getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
269 n += 24;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
270 }
14887
rathann
parents: 14886
diff changeset
271 if((chroma=getbits(buf, n++, 1)))
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
272 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
273 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
274 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
275 }
14887
rathann
parents: 14886
diff changeset
276 if((timing=getbits(buf, n++, 1)))
14798
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 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
279 n += 32;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
280
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
281 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
282 n += 32;
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 fixed_fps = getbits(buf, n, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
285
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
286 if(picture->timeinc_unit > 0 && picture->timeinc_resolution > 0)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
287 picture->fps = (picture->timeinc_resolution * 10000) / picture->timeinc_unit;
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 //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
291 // 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
292
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
293 return n;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
294 }
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 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
297 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
298 unsigned int n = 0, m = 0, v, i, j;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
299 unsigned char *dest;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
300
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
301 dest = (unsigned char*) malloc(len);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
302 if(! dest)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
303 return 0;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
304 j = i = 0;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
305 while(i <= len-3)
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 if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 3)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
308 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
309 dest[j] = dest[j+1] = 0;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
310 j += 2;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
311 i += 3;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
312 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
313 else
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
314 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
315 dest[j] = buf[i];
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
316 j++;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
317 i++;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
318 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
319 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
320 dest[j] = buf[len-2];
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
321 dest[j+1] = buf[len-1];
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
322 j += 2;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
323 len = j+1;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
324 buf = dest;
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->fps = picture->timeinc_unit = picture->timeinc_resolution = 0;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
327 n = 24;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
328 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
329 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
330 v = read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
331 if(v == 0)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
332 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
333 else if(v == 1)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
334 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
335 getbits(buf, n++, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
336 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
337 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
338 v = read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
339 for(i = 0; i < v; i++)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
340 read_golomb(buf, &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 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
343 getbits(buf, n++, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
344 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
345 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
346 if(!getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
347 getbits(buf, n++, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
348 getbits(buf, n++, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
349 if(getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
350 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
351 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
352 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
353 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
354 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
355 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
356 if(getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
357 n = h264_parse_vui(picture, buf, n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
358
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
359 free(dest);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
360 return n;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
361 }