-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgethdr.c
executable file
·212 lines (191 loc) · 5.29 KB
/
gethdr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// based on tmn codec source file gethdr.c from tmndecode:
/************************************************************************
*
* gethdr.c, header decoding for tmndecode (H.263 decoder)
* Copyright (C) 1995, 1996 Telenor R&D, Norway
* Karl Olav Lillevold <[email protected]>
*
* Contacts:
* Karl Olav Lillevold <[email protected]>, or
* Robert Danielsen <[email protected]>
*
* Telenor Research and Development http://www.nta.no/brukere/DVC/
* P.O.Box 83 tel.: +47 63 84 84 00
* N-2007 Kjeller, Norway fax.: +47 63 81 00 76
*
************************************************************************/
/*
* Disclaimer of Warranty
*
* These software programs are available to the user without any
* license fee or royalty on an "as is" basis. Telenor Research and
* Development disclaims any and all warranties, whether express,
* implied, or statuary, including any implied warranties or
* merchantability or of fitness for a particular purpose. In no
* event shall the copyright-holder be liable for any incidental,
* punitive, or consequential damages of any kind whatsoever arising
* from the use of these programs.
*
* This disclaimer of warranty extends to the user of these programs
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* Telenor Research and Development does not represent or warrant that
* the programs furnished hereunder are free of infringement of any
* third-party patents.
*
* Commercial implementations of H.263, including shareware, are
* subject to royalty fees to patent holders. Many of these patents
* are general enough such that they are unavoidable regardless of
* implementation design.
* */
/*
* based on mpeg2decode, (C) 1994, MPEG Software Simulation Group
* and mpeg2play, (C) 1994 Stefan Eckart
*/
#include <stdio.h>
#include <stdlib.h>
#include "codec.h"
void getpicturehdr(PICTURE *pic, int pictpos);
void startcode();
extern int getbitcnt;
/*
* decode headers from one input stream
* until an End of Sequence or picture start code
* is found
*/
int getheader(PICTURE *pic, int pictpos)
{
unsigned int code, gob;
int hdrsize;
int i;
int bc=getbitcnt;
/* look for startcode */
startcode();
#define PSC_LENGTH 17
code = getbits(PSC_LENGTH);
gob = getbits(5);
// if (gob == SE_CODE)
if (gob !=0){
printf("Error reading gob\n");
return 0;
}
if (gob == 0) {
getpicturehdr(pic, pictpos);
// if (syntax_arith_coding) /* reset decoder after receiving */
// decoder_reset(); /* fixed length PSC string */
}
// return gob + 1;
hdrsize = getbitcnt-bc;
return hdrsize;
}
/* align to start of next startcode */
void startcode()
{
/* search for new picture start code */
// while (showbits(PSC_LENGTH)!=1l)
while (showbits(PSC_LENGTH)!=1)
flushbits(1);
}
/* decode picture header */
void getpicturehdr(PICTURE *pic, int pictpos)
{
int pos, pei, tmp;
int temp_ref;
int prev_temp_ref;
int trd;
int pt;
int pict_type;
int mv_outside_frame;
int long_vectors;
int syntax_arith_coding;
int adv_pred_mode;
pos = pictpos;
temp_ref=0;
prev_temp_ref = temp_ref;
temp_ref = getbits(8);
trd = temp_ref - prev_temp_ref;
if (trd < 0)
trd += 256;
/*
tmp = getbits(1);
if (!tmp)
if (!quiet)
printf("warning: spare in picture header should be \"1\"\n");
tmp = getbits(1);
if (tmp)
if (!quiet)
printf("warning: H.261 distinction bit should be \"0\"\n");
tmp = getbits(1);
if (tmp) {
if (!quiet)
printf("error: split-screen not supported in this version\n");
exit (-1);
}
tmp = getbits(1);
if (tmp)
if (!quiet)
printf("warning: document camera indicator not supported in this version\n");
tmp = getbits(1);
if (tmp)
if (!quiet)
printf("warning: frozen picture not supported in this version\n");
*/
pt = getbits(8);
if (pt!=0x87)
{
printf("Error parsing header\n");
exit(1);
}
getbits(3);
pic->image.src_format = getbits(3);
pict_type = getbits(1);//-
mv_outside_frame = getbits(1);//
long_vectors = (mv_outside_frame ? 1 : 0);//
syntax_arith_coding = getbits(1);//
adv_pred_mode = getbits(1);//
mv_outside_frame = (adv_pred_mode ? 1 : mv_outside_frame);
// int pb_frame = getbits(1);//
getbits(11);
pic->ptype=getbits(3);
getbits(2);
pic->rtype=getbits(1);
getbits(3);
tmp = getbits(1);//
if (tmp) {
printf("error: CPM not supported in this version\n");
exit(-1);
}
pic->pquant = getbits(5);
if (pic->ptype == PCT_PB) {
getbits(3, pic->trb);
getbits(2, pic->dbquant);
}
//npsupp
pei=getbits(1);
if (pei) {
printf("merror: pei not supported\n");
exit(0);
}
/*
if (pb_frame) {
trb = getbits(3);
bquant = getbits(2);
}
else {
trb = 0;
}
#ifdef USE_TIME
if (framerate > 0 && trd > 0)
doframerate(0);
#endif
pei = getbits(1);
pspare:
if (pei) {
getbits(8)
pei = getbits(1);
if (pei) goto pspare;
}
*/
}