annotate libmpdemux/mpeg_hdr.c @ 29876:c60ed2ae1d0d

synced with r29912
author Gabrov
date Mon, 16 Nov 2009 15:20:57 +0000
parents e8d71beb79b9
children 102ae81b5dc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
1 /*
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
2 * based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
3 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
4 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
5 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
7 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
9 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
10 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
14 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
15 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
16 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 24784
diff changeset
19 */
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
20
15225
a8c02eef4972 proper fix
rfelker
parents: 15224
diff changeset
21 #include <inttypes.h>
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
22 #include <stdio.h>
14886
a109ae86ba63 missing #include (for malloc and free)
rathann
parents: 14798
diff changeset
23 #include <stdlib.h>
21947
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
24 #include <string.h>
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
25
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
26 #include "config.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
27 #include "mpeg_hdr.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
28
18398
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
29 #include "mp_msg.h"
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
30
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
31 static float frameratecode2framerate[16] = {
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
32 0,
5441
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
33 // 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
34 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
35 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
36 60000.0/1001, 60,
5441
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
37 // 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
38 15,
5441
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
39 // 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
40 5,10,12,15,
5441
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
41 // some invalid ones: (14-15)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
42 0,0
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
43 };
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
44
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
45
24784
328d1b36952a Mark constant argument of mp_header_process_sequence_header as such.
diego
parents: 21953
diff changeset
46 int mp_header_process_sequence_header (mp_mpeg_header_t * picture, const unsigned char * buffer)
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
47 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
48 int width, height;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
49
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
50 if ((buffer[6] & 0x20) != 0x20){
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
51 fprintf(stderr, "missing marker bit!\n");
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
52 return 1; /* missing marker_bit */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
53 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
54
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
55 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
56
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
57 picture->display_picture_width = (height >> 12);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
58 picture->display_picture_height = (height & 0xfff);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
59
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
60 width = ((height >> 12) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
61 height = ((height & 0xfff) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
62
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
63 picture->aspect_ratio_information = buffer[3] >> 4;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
64 picture->frame_rate_code = buffer[3] & 15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
65 picture->fps=frameratecode2framerate[picture->frame_rate_code];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
66 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
67 picture->mpeg1 = 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
68 picture->picture_structure = 3; //FRAME_PICTURE;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
69 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
70 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
71 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
72
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
73 static int header_process_sequence_extension (mp_mpeg_header_t * picture,
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
74 unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
75 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
76 /* check chroma format, size extensions, marker bit */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
77
12562
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
78 if ( ((buffer[1] & 0x06) == 0x00) ||
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
79 ((buffer[1] & 0x01) != 0x00) || (buffer[2] & 0xe0) ||
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
80 ((buffer[3] & 0x01) != 0x01) )
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
81 return 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
82
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
83 picture->progressive_sequence = (buffer[1] >> 3) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
84 picture->mpeg1 = 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
85 return 0;
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 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
89 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
90 picture->picture_structure = buffer[2] & 3;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
91 picture->top_field_first = buffer[3] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
92 picture->repeat_first_field = (buffer[3] >> 1) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
93 picture->progressive_frame = buffer[4] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
94
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
95 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
96 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
97 if(picture->repeat_first_field){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
98 if(picture->progressive_sequence){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
99 if(picture->top_field_first)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
100 picture->display_time+=200;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
101 else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
102 picture->display_time+=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
103 } else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
104 if(picture->progressive_frame){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
105 picture->display_time+=50;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
106 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
107 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
108 //temopral hack. We calc time on every field, so if we have 2 fields
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
109 // interlaced we'll end with double time for 1 frame
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
110 if( picture->picture_structure!=3 ) picture->display_time/=2;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
111 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
112 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
113
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
114 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
115 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
116 switch (buffer[0] & 0xf0) {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
117 case 0x10: /* sequence extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
118 return header_process_sequence_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
119 case 0x80: /* picture coding extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
120 return header_process_picture_coding_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
121 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
122 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
123 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
124
18398
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
125 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
126 {
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
127 float aspect = 0.0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
128
18398
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
129 switch(picture->aspect_ratio_information) {
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
130 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
131 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
132 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
133 aspect=4.0/3.0;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
134 break;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
135 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
136 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
137 aspect=16.0/9.0;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
138 break;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
139 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
140 aspect=2.21;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
141 break;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
142 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
143 case 9: // Movie Type ??? / 640x480
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
144 aspect=0.0;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
145 break;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
146 default:
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
147 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
148 "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
149 "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
150 " 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
151 picture->aspect_ratio_information);
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
152 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
153
18398
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
154 return aspect;
a1375e440e92 COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents: 17952
diff changeset
155 }
14477
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 //MPEG4 HEADERS
14967
d901658f487d export getbits() as mp_getbits()
nicodvb
parents: 14887
diff changeset
158 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
159 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
160 unsigned int n;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
161 unsigned char m, u, l, y;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
162
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
163 n = from / 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
164 m = from % 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
165 u = 8 - m;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
166 l = (len > u ? len - u : 0);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
167
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
168 y = (buffer[n] << m);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
169 if(8 > len)
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
170 y >>= (8-len);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
171 if(l)
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
172 y |= (buffer[n+1] >> (8-l));
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
173
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
174 //fprintf(stderr, "GETBITS(%d -> %d): bytes=0x%x 0x%x, n=%d, m=%d, l=%d, u=%d, Y=%d\n",
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
175 // 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
176 return y;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
177 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
178
21947
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
179 static inline unsigned int mp_getbits16(unsigned char *buffer, unsigned int from, unsigned char len)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
180 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
181 if(len > 8)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
182 return (mp_getbits(buffer, from, len - 8) << 8) | mp_getbits(buffer, from + len - 8, 8);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
183 else
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
184 return mp_getbits(buffer, from, len);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
185 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
186
14967
d901658f487d export getbits() as mp_getbits()
nicodvb
parents: 14887
diff changeset
187 #define getbits mp_getbits
21947
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
188 #define getbits16 mp_getbits16
14967
d901658f487d export getbits() as mp_getbits()
nicodvb
parents: 14887
diff changeset
189
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
190 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
191 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
192 if(picture->timeinc_bits > 8) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
193 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
194 n += picture->timeinc_bits - 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
195 picture->timeinc_unit |= getbits(buffer, n, 8);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
196 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
197 } else {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
198 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
199 n += picture->timeinc_bits;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
200 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
201 //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
202 return n;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
203 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
204
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
205 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
206 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
207 unsigned int n, aspect=0, aspectw=0, aspecth=0, x=1, v;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
208
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
209 //begins with 0x0000012x
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
210 picture->fps = 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
211 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
212 n = 9;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
213 if(getbits(buffer, n, 1))
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
214 n += 7;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
215 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
216 aspect=getbits(buffer, n, 4);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
217 n += 4;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
218 if(aspect == 0x0f) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
219 aspectw = 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 aspecth = getbits(buffer, n, 8);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
222 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
223 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
224
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
225 if(getbits(buffer, n, 1)) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
226 n += 4;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
227 if(getbits(buffer, n, 1))
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
228 n += 79;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
229 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
230 } else n++;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
231
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
232 n+=3;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
233
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
234 picture->timeinc_resolution = getbits(buffer, n, 8) << 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
235 n += 8;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
236 picture->timeinc_resolution |= getbits(buffer, n, 8);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
237 n += 8;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
238
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
239 picture->timeinc_bits = 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
240 v = picture->timeinc_resolution - 1;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
241 while(v && (x<16)) {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
242 v>>=1;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
243 picture->timeinc_bits++;
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 picture->timeinc_bits = (picture->timeinc_bits > 1 ? picture->timeinc_bits : 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
246
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
247 n++; //marker bit
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
248
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
249 if(getbits(buffer, n, 1)) { //fixed_vop_timeinc
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
250 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
251 n = read_timeinc(picture, buffer, n);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
252
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
253 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
254 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
255 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
256
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
257 //fprintf(stderr, "ASPECT: %d, PARW=%d, PARH=%d, TIMEINCRESOLUTION: %d, FIXED_TIMEINC: %d (number of bits: %d), FPS: %u\n",
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
258 // aspect, aspectw, aspecth, picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_bits, picture->fps);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
259
14477
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
260 return 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
261 }
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
262
14887
rathann
parents: 14886
diff changeset
263 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
264 {
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
265 int n;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
266 n = 0;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
267 picture->picture_type = getbits(buffer, n, 2);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
268 n += 2;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
269 while(getbits(buffer, n, 1))
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
270 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
271 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
272 getbits(buffer, n, 1);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
273 n++;
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
274 n = read_timeinc(picture, buffer, n);
92553e3c8f01 automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents: 12755
diff changeset
275 }
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
276
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
277 #define min(a, b) ((a) <= (b) ? (a) : (b))
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 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
280 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
281 unsigned int x, v = 0, v2 = 0, m, len = 0, n = *init;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
282
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
283 while(getbits(buffer, n++, 1) == 0)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
284 len++;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
285
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
286 x = len + n;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
287 while(n < x)
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 m = min(x - n, 8);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
290 v |= getbits(buffer, n, m);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
291 n += m;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
292 if(x - n > 8)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
293 v <<= 8;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
294 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
295
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
296 v2 = 1;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
297 for(n = 0; n < len; n++)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
298 v2 <<= 1;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
299 v2 = (v2 - 1) + v;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
300
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
301 //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
302 *init = x;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
303 return v2;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
304 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
305
29452
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
306 inline static int read_golomb_s(unsigned char *buffer, unsigned int *init)
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
307 {
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
308 unsigned int v = read_golomb(buffer, init);
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
309 return (v & 1) ? ((v + 1) >> 1) : -(v >> 1);
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
310 }
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 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
313 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
314 unsigned int overscan, vsp_color, chroma, timing, fixed_fps;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
315
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
316 if(getbits(buf, n++, 1))
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 picture->aspect_ratio_information = getbits(buf, n, 8);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
319 n += 8;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
320 if(picture->aspect_ratio_information == 255)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
321 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
322 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
323 n += 16;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
324
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
325 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
326 n += 16;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
327 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
328 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
329
14887
rathann
parents: 14886
diff changeset
330 if((overscan=getbits(buf, n++, 1)))
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
331 n++;
14887
rathann
parents: 14886
diff changeset
332 if((vsp_color=getbits(buf, n++, 1)))
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
333 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
334 n += 4;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
335 if(getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
336 n += 24;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
337 }
14887
rathann
parents: 14886
diff changeset
338 if((chroma=getbits(buf, n++, 1)))
14798
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 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
341 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
342 }
14887
rathann
parents: 14886
diff changeset
343 if((timing=getbits(buf, n++, 1)))
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
344 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
345 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
346 n += 32;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
347
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
348 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
349 n += 32;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
350
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
351 fixed_fps = getbits(buf, n, 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
352
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
353 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
354 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
355 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
356 picture->fps /= 2;
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
357 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
358
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
359 //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
360 // picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_unit, fixed_fps);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
361
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
362 return n;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
363 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
364
21953
62bf4204eed4 in h264_parse_sps() reuse mp_unescape03()
nicodvb
parents: 21947
diff changeset
365 static int mp_unescape03(unsigned char *buf, int len);
62bf4204eed4 in h264_parse_sps() reuse mp_unescape03()
nicodvb
parents: 21947
diff changeset
366
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
367 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
368 {
29452
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
369 unsigned int n = 0, v, i, k, mbh;
15073
28ba6bfcf2dc assign picture->(width,height) when parsing h264
nicodvb
parents: 14967
diff changeset
370 int frame_mbs_only;
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
371
21953
62bf4204eed4 in h264_parse_sps() reuse mp_unescape03()
nicodvb
parents: 21947
diff changeset
372 len = mp_unescape03(buf, len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
373
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
374 picture->fps = picture->timeinc_unit = picture->timeinc_resolution = 0;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
375 n = 24;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
376 read_golomb(buf, &n);
15618
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
377 if(buf[0] >= 100){
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
378 if(read_golomb(buf, &n) == 3)
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
379 n++;
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
380 read_golomb(buf, &n);
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
381 read_golomb(buf, &n);
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
382 n++;
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
383 if(getbits(buf, n++, 1)){
29452
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
384 for(i = 0; i < 8; i++)
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
385 { // scaling list is skipped for now
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
386 if(getbits(buf, n++, 1))
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
387 {
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
388 v = 8;
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
389 for(k = (i < 6 ? 16 : 64); k && v; k--)
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
390 v = (v + read_golomb_s(buf, &n)) & 255;
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
391 }
e8d71beb79b9 Fix H.264 SPS parsing in case of scaling list present.
cehoyos
parents: 29263
diff changeset
392 }
15618
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
393 }
1965072518be demux high profile H.264 ES
lorenm
parents: 15225
diff changeset
394 }
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
395 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
396 v = read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
397 if(v == 0)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
398 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
399 else if(v == 1)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
400 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
401 getbits(buf, n++, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
402 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
403 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
404 v = read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
405 for(i = 0; i < v; i++)
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
406 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
407 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
408 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
409 getbits(buf, n++, 1);
15073
28ba6bfcf2dc assign picture->(width,height) when parsing h264
nicodvb
parents: 14967
diff changeset
410 picture->display_picture_width = 16 *(read_golomb(buf, &n)+1);
28ba6bfcf2dc assign picture->(width,height) when parsing h264
nicodvb
parents: 14967
diff changeset
411 mbh = read_golomb(buf, &n)+1;
28ba6bfcf2dc assign picture->(width,height) when parsing h264
nicodvb
parents: 14967
diff changeset
412 frame_mbs_only = getbits(buf, n++, 1);
28ba6bfcf2dc assign picture->(width,height) when parsing h264
nicodvb
parents: 14967
diff changeset
413 picture->display_picture_height = 16 * (2 - frame_mbs_only) * mbh;
28ba6bfcf2dc assign picture->(width,height) when parsing h264
nicodvb
parents: 14967
diff changeset
414 if(!frame_mbs_only)
14798
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
415 getbits(buf, n++, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
416 getbits(buf, n++, 1);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
417 if(getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
418 {
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
419 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
420 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
421 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
422 read_golomb(buf, &n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
423 }
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
424 if(getbits(buf, n++, 1))
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
425 n = h264_parse_vui(picture, buf, n);
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
426
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
427 return n;
0bd50330e688 framerate autodetection for H264 in raw/ts streams
nicodvb
parents: 14477
diff changeset
428 }
21947
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
429
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
430 static int mp_unescape03(unsigned char *buf, int len)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
431 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
432 unsigned char *dest;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
433 int i, j, skip;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
434
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
435 dest = malloc(len);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
436 if(! dest)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
437 return 0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
438
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
439 j = i = skip = 0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
440 while(i <= len-3)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
441 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
442 if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 3)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
443 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
444 dest[j] = dest[j+1] = 0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
445 j += 2;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
446 i += 3;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
447 skip++;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
448 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
449 else
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
450 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
451 dest[j] = buf[i];
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
452 j++;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
453 i++;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
454 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
455 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
456 dest[j] = buf[len-2];
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
457 dest[j+1] = buf[len-1];
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
458 len -= skip;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
459 memcpy(buf, dest, len);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
460 free(dest);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
461
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
462 return len;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
463 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
464
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
465 int mp_vc1_decode_sequence_header(mp_mpeg_header_t * picture, unsigned char * buf, int len)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
466 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
467 int n, x;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
468
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
469 len = mp_unescape03(buf, len);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
470
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
471 picture->display_picture_width = picture->display_picture_height = 0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
472 picture->fps = 0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
473 n = 0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
474 x = getbits(buf, n, 2);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
475 n += 2;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
476 if(x != 3) //not advanced profile
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
477 return 0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
478
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
479 getbits16(buf, n, 14);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
480 n += 14;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
481 picture->display_picture_width = getbits16(buf, n, 12) * 2 + 2;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
482 n += 12;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
483 picture->display_picture_height = getbits16(buf, n, 12) * 2 + 2;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
484 n += 12;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
485 getbits(buf, n, 6);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
486 n += 6;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
487 x = getbits(buf, n, 1);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
488 n += 1;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
489 if(x) //display info
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
490 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
491 getbits16(buf, n, 14);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
492 n += 14;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
493 getbits16(buf, n, 14);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
494 n += 14;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
495 if(getbits(buf, n++, 1)) //aspect ratio
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
496 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
497 x = getbits(buf, n, 4);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
498 n += 4;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
499 if(x == 15)
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
500 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
501 getbits16(buf, n, 16);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
502 n += 16;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
503 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
504 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
505
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
506 if(getbits(buf, n++, 1)) //framerates
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
507 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
508 int frexp=0, frnum=0, frden=0;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
509
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
510 if(getbits(buf, n++, 1))
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
511 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
512 frexp = getbits16(buf, n, 16);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
513 n += 16;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
514 picture->fps = (double) (frexp+1) / 32.0;
21947
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
515 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
516 else
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
517 {
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
518 float frates[] = {0, 24000, 25000, 30000, 50000, 60000, 48000, 72000, 0};
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
519 float frdivs[] = {0, 1000, 1001, 0};
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
520
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
521 frnum = getbits(buf, n, 8);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
522 n += 8;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
523 frden = getbits(buf, n, 4);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
524 n += 4;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
525 if((frden == 1 || frden == 2) && (frnum < 8))
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
526 picture->fps = frates[frnum] / frdivs[frden];
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
527 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
528 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
529 }
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
530
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
531 //free(dest);
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
532 return 1;
df1d03939216 added function to parse vc1 sequence header
nicodvb
parents: 18398
diff changeset
533 }