Mercurial > libavcodec.hg
annotate h263.c @ 292:73a9ce3d9715 libavcodec
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
author | michaelni |
---|---|
date | Sun, 24 Mar 2002 23:45:13 +0000 |
parents | ab46ebfd419f |
children | 6eaf5da091fa |
rev | line source |
---|---|
0 | 1 /* |
2 * H263/MPEG4 backend for ffmpeg encoder and decoder | |
3 * Copyright (c) 2000,2001 Gerard Lantau. | |
78 | 4 * H263+ support. |
0 | 5 * Copyright (c) 2001 Juan J. Sierralta P. |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
20 * |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
21 * ac prediction encoding by Michael Niedermayer <michaelni@gmx.at> |
0 | 22 */ |
23 #include "common.h" | |
24 #include "dsputil.h" | |
25 #include "avcodec.h" | |
26 #include "mpegvideo.h" | |
27 #include "h263data.h" | |
28 #include "mpeg4data.h" | |
29 | |
255 | 30 //rounded divison & shift |
31 #define RDIV(a,b) ((a) > 0 ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b)) | |
32 #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
33 #define ABS(a) (((a)>=0)?(a):(-(a))) |
290 | 34 #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
35 #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
255 | 36 |
0 | 37 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, |
38 int n); | |
39 static void h263_encode_motion(MpegEncContext * s, int val); | |
78 | 40 static void h263p_encode_umotion(MpegEncContext * s, int val); |
0 | 41 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
42 int n, int dc, UINT8 *scan_table); |
262 | 43 static int h263_decode_motion(MpegEncContext * s, int pred, int fcode); |
78 | 44 static int h263p_decode_umotion(MpegEncContext * s, int pred); |
0 | 45 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
46 int n, int coded); | |
47 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
48 int n, int coded); | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
49 static inline int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
50 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
51 int dir); |
290 | 52 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s); |
53 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
54 extern UINT32 inverse[256]; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
55 |
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
291
diff
changeset
|
56 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
57 static UINT8 fcode_tab[MAX_MV*2+1]; |
287 | 58 static UINT8 umv_fcode_tab[MAX_MV*2+1]; |
0 | 59 |
60 int h263_get_picture_format(int width, int height) | |
61 { | |
62 int format; | |
63 | |
64 if (width == 128 && height == 96) | |
65 format = 1; | |
66 else if (width == 176 && height == 144) | |
67 format = 2; | |
68 else if (width == 352 && height == 288) | |
69 format = 3; | |
70 else if (width == 704 && height == 576) | |
71 format = 4; | |
72 else if (width == 1408 && height == 1152) | |
73 format = 5; | |
74 else | |
75 format = 7; | |
76 return format; | |
77 } | |
78 | |
79 void h263_encode_picture_header(MpegEncContext * s, int picture_number) | |
80 { | |
78 | 81 int format; |
0 | 82 |
83 align_put_bits(&s->pb); | |
231 | 84 |
85 /* Update the pointer to last GOB */ | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
86 s->ptr_lastgob = pbBufPtr(&s->pb); |
231 | 87 s->gob_number = 0; |
88 | |
89 put_bits(&s->pb, 22, 0x20); /* PSC */ | |
241 | 90 put_bits(&s->pb, 8, (((INT64)s->picture_number * 30 * FRAME_RATE_BASE) / |
0 | 91 s->frame_rate) & 0xff); |
92 | |
93 put_bits(&s->pb, 1, 1); /* marker */ | |
94 put_bits(&s->pb, 1, 0); /* h263 id */ | |
95 put_bits(&s->pb, 1, 0); /* split screen off */ | |
96 put_bits(&s->pb, 1, 0); /* camera off */ | |
97 put_bits(&s->pb, 1, 0); /* freeze picture release off */ | |
78 | 98 |
99 format = h263_get_picture_format(s->width, s->height); | |
0 | 100 if (!s->h263_plus) { |
101 /* H.263v1 */ | |
102 put_bits(&s->pb, 3, format); | |
103 put_bits(&s->pb, 1, (s->pict_type == P_TYPE)); | |
104 /* By now UMV IS DISABLED ON H.263v1, since the restrictions | |
105 of H.263v1 UMV implies to check the predicted MV after | |
106 calculation of the current MB to see if we're on the limits */ | |
107 put_bits(&s->pb, 1, 0); /* unrestricted motion vector: off */ | |
108 put_bits(&s->pb, 1, 0); /* SAC: off */ | |
109 put_bits(&s->pb, 1, 0); /* advanced prediction mode: off */ | |
110 put_bits(&s->pb, 1, 0); /* not PB frame */ | |
111 put_bits(&s->pb, 5, s->qscale); | |
112 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
113 } else { | |
114 /* H.263v2 */ | |
115 /* H.263 Plus PTYPE */ | |
116 put_bits(&s->pb, 3, 7); | |
117 put_bits(&s->pb,3,1); /* Update Full Extended PTYPE */ | |
78 | 118 if (format == 7) |
119 put_bits(&s->pb,3,6); /* Custom Source Format */ | |
120 else | |
121 put_bits(&s->pb, 3, format); | |
122 | |
0 | 123 put_bits(&s->pb,1,0); /* Custom PCF: off */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
124 s->umvplus = (s->pict_type == P_TYPE) && s->unrestricted_mv; |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
125 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ |
0 | 126 put_bits(&s->pb,1,0); /* SAC: off */ |
127 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ | |
128 put_bits(&s->pb,1,0); /* Advanced Intra Coding: off */ | |
129 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ | |
130 put_bits(&s->pb,1,0); /* Slice Structured: off */ | |
131 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ | |
132 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ | |
133 put_bits(&s->pb,1,0); /* Alternative Inter VLC: off */ | |
134 put_bits(&s->pb,1,0); /* Modified Quantization: off */ | |
135 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
136 put_bits(&s->pb,3,0); /* Reserved */ | |
137 | |
138 put_bits(&s->pb, 3, s->pict_type == P_TYPE); | |
139 | |
140 put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ | |
141 put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ | |
142 put_bits(&s->pb,1,0); /* Rounding Type */ | |
143 put_bits(&s->pb,2,0); /* Reserved */ | |
144 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
145 | |
146 /* This should be here if PLUSPTYPE */ | |
147 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
148 | |
78 | 149 if (format == 7) { |
150 /* Custom Picture Format (CPFMT) */ | |
0 | 151 |
78 | 152 put_bits(&s->pb,4,2); /* Aspect ratio: CIF 12:11 (4:3) picture */ |
153 put_bits(&s->pb,9,(s->width >> 2) - 1); | |
154 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
155 put_bits(&s->pb,9,(s->height >> 2)); | |
156 } | |
157 | |
0 | 158 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
159 if (s->umvplus) |
0 | 160 put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
161 put_bits(&s->pb, 5, s->qscale); | |
162 } | |
163 | |
164 put_bits(&s->pb, 1, 0); /* no PEI */ | |
165 } | |
166 | |
162 | 167 int h263_encode_gob_header(MpegEncContext * s, int mb_line) |
168 { | |
169 int pdif=0; | |
170 | |
171 /* Check to see if we need to put a new GBSC */ | |
172 /* for RTP packetization */ | |
173 if (s->rtp_mode) { | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
174 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
162 | 175 if (pdif >= s->rtp_payload_size) { |
176 /* Bad luck, packet must be cut before */ | |
177 align_put_bits(&s->pb); | |
231 | 178 flush_put_bits(&s->pb); |
179 /* Call the RTP callback to send the last GOB */ | |
180 if (s->rtp_callback) { | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
181 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 182 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
183 } | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
184 s->ptr_lastgob = pbBufPtr(&s->pb); |
162 | 185 put_bits(&s->pb, 17, 1); /* GBSC */ |
231 | 186 s->gob_number = mb_line / s->gob_index; |
162 | 187 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
231 | 188 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
162 | 189 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
231 | 190 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
162 | 191 return pdif; |
192 } else if (pdif + s->mb_line_avgsize >= s->rtp_payload_size) { | |
193 /* Cut the packet before we can't */ | |
194 align_put_bits(&s->pb); | |
231 | 195 flush_put_bits(&s->pb); |
196 /* Call the RTP callback to send the last GOB */ | |
197 if (s->rtp_callback) { | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
198 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 199 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
200 } | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
201 s->ptr_lastgob = pbBufPtr(&s->pb); |
162 | 202 put_bits(&s->pb, 17, 1); /* GBSC */ |
231 | 203 s->gob_number = mb_line / s->gob_index; |
162 | 204 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
231 | 205 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
162 | 206 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
231 | 207 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
162 | 208 return pdif; |
209 } | |
210 } | |
211 return 0; | |
212 } | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
213 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
214 static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6]) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
215 { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
216 int score0=0, score1=0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
217 int i, n; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
218 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
219 for(n=0; n<6; n++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
220 INT16 *ac_val, *ac_val1; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
221 |
266 | 222 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
223 ac_val1= ac_val; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
224 if(dir[n]){ |
266 | 225 ac_val-= s->block_wrap[n]*16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
226 for(i=1; i<8; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
227 const int level= block[n][block_permute_op(i )]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
228 score0+= ABS(level); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
229 score1+= ABS(level - ac_val[i+8]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
230 ac_val1[i ]= block[n][block_permute_op(i<<3)]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
231 ac_val1[i+8]= level; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
232 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
233 }else{ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
234 ac_val-= 16; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
235 for(i=1; i<8; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
236 const int level= block[n][block_permute_op(i<<3)]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
237 score0+= ABS(level); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
238 score1+= ABS(level - ac_val[i]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
239 ac_val1[i ]= level; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
240 ac_val1[i+8]= block[n][block_permute_op(i )]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
241 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
242 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
243 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
244 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
245 return score0 > score1 ? 1 : 0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
246 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
247 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
248 void mpeg4_encode_mb(MpegEncContext * s, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
249 DCTELEM block[6][64], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
250 int motion_x, int motion_y) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
251 { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
252 int cbpc, cbpy, i, cbp, pred_x, pred_y; |
286 | 253 int bits; |
162 | 254 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
255 // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
256 if (!s->mb_intra) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
257 /* compute cbp */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
258 cbp = 0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
259 for (i = 0; i < 6; i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
260 if (s->block_last_index[i] >= 0) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
261 cbp |= 1 << (5 - i); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
262 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
263 if ((cbp | motion_x | motion_y) == 0) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
264 /* skip macroblock */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
265 put_bits(&s->pb, 1, 1); |
286 | 266 s->misc_bits++; |
267 s->last_bits++; | |
268 s->skip_count++; | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
269 return; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
270 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
271 put_bits(&s->pb, 1, 0); /* mb coded */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
272 cbpc = cbp & 3; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
273 put_bits(&s->pb, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
274 inter_MCBPC_bits[cbpc], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
275 inter_MCBPC_code[cbpc]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
276 cbpy = cbp >> 2; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
277 cbpy ^= 0xf; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
278 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
286 | 279 |
280 bits= get_bit_count(&s->pb); | |
281 s->misc_bits+= bits - s->last_bits; | |
282 s->last_bits=bits; | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
283 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
284 /* motion vectors: 16x16 mode only now */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
285 h263_pred_motion(s, 0, &pred_x, &pred_y); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
286 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
287 h263_encode_motion(s, motion_x - pred_x); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
288 h263_encode_motion(s, motion_y - pred_y); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
289 |
286 | 290 bits= get_bit_count(&s->pb); |
291 s->mv_bits+= bits - s->last_bits; | |
292 s->last_bits=bits; | |
293 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
294 /* encode each block */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
295 for (i = 0; i < 6; i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
296 mpeg4_encode_block(s, block[i], i, 0, zigzag_direct); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
297 } |
286 | 298 bits= get_bit_count(&s->pb); |
299 s->p_tex_bits+= bits - s->last_bits; | |
300 s->last_bits=bits; | |
301 s->p_count++; | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
302 } else { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
303 int dc_diff[6]; //dc values with the dc prediction subtracted |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
304 int dir[6]; //prediction direction |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
305 int zigzag_last_index[6]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
306 UINT8 *scan_table[6]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
307 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
308 for(i=0; i<6; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
309 const int level= block[i][0]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
310 UINT16 *dc_ptr; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
311 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
312 dc_diff[i]= level - mpeg4_pred_dc(s, i, &dc_ptr, &dir[i]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
313 if (i < 4) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
314 *dc_ptr = level * s->y_dc_scale; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
315 } else { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
316 *dc_ptr = level * s->c_dc_scale; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
317 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
318 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
319 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
320 s->ac_pred= decide_ac_pred(s, block, dir); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
321 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
322 if(s->ac_pred){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
323 for(i=0; i<6; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
324 UINT8 *st; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
325 int last_index; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
326 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
327 mpeg4_inv_pred_ac(s, block[i], i, dir[i]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
328 if (dir[i]==0) st = ff_alternate_vertical_scan; /* left */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
329 else st = ff_alternate_horizontal_scan; /* top */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
330 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
331 for(last_index=63; last_index>=0; last_index--) //FIXME optimize |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
332 if(block[i][st[last_index]]) break; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
333 zigzag_last_index[i]= s->block_last_index[i]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
334 s->block_last_index[i]= last_index; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
335 scan_table[i]= st; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
336 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
337 }else{ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
338 for(i=0; i<6; i++) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
339 scan_table[i]= zigzag_direct; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
340 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
341 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
342 /* compute cbp */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
343 cbp = 0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
344 for (i = 0; i < 6; i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
345 if (s->block_last_index[i] >= 1) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
346 cbp |= 1 << (5 - i); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
347 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
348 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
349 cbpc = cbp & 3; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
350 if (s->pict_type == I_TYPE) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
351 put_bits(&s->pb, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
352 intra_MCBPC_bits[cbpc], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
353 intra_MCBPC_code[cbpc]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
354 } else { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
355 put_bits(&s->pb, 1, 0); /* mb coded */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
356 put_bits(&s->pb, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
357 inter_MCBPC_bits[cbpc + 4], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
358 inter_MCBPC_code[cbpc + 4]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
359 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
360 put_bits(&s->pb, 1, s->ac_pred); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
361 cbpy = cbp >> 2; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
362 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
363 |
286 | 364 bits= get_bit_count(&s->pb); |
365 s->misc_bits+= bits - s->last_bits; | |
366 s->last_bits=bits; | |
367 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
368 /* encode each block */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
369 for (i = 0; i < 6; i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
370 mpeg4_encode_block(s, block[i], i, dc_diff[i], scan_table[i]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
371 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
372 |
286 | 373 bits= get_bit_count(&s->pb); |
374 s->i_tex_bits+= bits - s->last_bits; | |
375 s->last_bits=bits; | |
376 s->i_count++; | |
377 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
378 /* restore ac coeffs & last_index stuff if we messed them up with the prediction */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
379 if(s->ac_pred){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
380 for(i=0; i<6; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
381 int j; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
382 INT16 *ac_val; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
383 |
266 | 384 ac_val = s->ac_val[0][0] + s->block_index[i] * 16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
385 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
386 if(dir[i]){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
387 for(j=1; j<8; j++) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
388 block[i][block_permute_op(j )]= ac_val[j+8]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
389 }else{ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
390 for(j=1; j<8; j++) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
391 block[i][block_permute_op(j<<3)]= ac_val[j ]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
392 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
393 s->block_last_index[i]= zigzag_last_index[i]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
394 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
395 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
396 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
397 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
398 |
0 | 399 void h263_encode_mb(MpegEncContext * s, |
400 DCTELEM block[6][64], | |
401 int motion_x, int motion_y) | |
402 { | |
403 int cbpc, cbpy, i, cbp, pred_x, pred_y; | |
162 | 404 |
0 | 405 // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
78 | 406 if (!s->mb_intra) { |
407 /* compute cbp */ | |
408 cbp = 0; | |
409 for (i = 0; i < 6; i++) { | |
410 if (s->block_last_index[i] >= 0) | |
411 cbp |= 1 << (5 - i); | |
412 } | |
413 if ((cbp | motion_x | motion_y) == 0) { | |
414 /* skip macroblock */ | |
415 put_bits(&s->pb, 1, 1); | |
416 return; | |
417 } | |
418 put_bits(&s->pb, 1, 0); /* mb coded */ | |
419 cbpc = cbp & 3; | |
420 put_bits(&s->pb, | |
421 inter_MCBPC_bits[cbpc], | |
422 inter_MCBPC_code[cbpc]); | |
423 cbpy = cbp >> 2; | |
424 cbpy ^= 0xf; | |
425 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
0 | 426 |
78 | 427 /* motion vectors: 16x16 mode only now */ |
428 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
429 | |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
430 if (!s->umvplus) { |
78 | 431 h263_encode_motion(s, motion_x - pred_x); |
432 h263_encode_motion(s, motion_y - pred_y); | |
433 } | |
434 else { | |
435 h263p_encode_umotion(s, motion_x - pred_x); | |
436 h263p_encode_umotion(s, motion_y - pred_y); | |
437 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
438 /* To prevent Start Code emulation */ | |
439 put_bits(&s->pb,1,1); | |
440 } | |
441 } else { | |
0 | 442 /* compute cbp */ |
443 cbp = 0; | |
444 for (i = 0; i < 6; i++) { | |
445 if (s->block_last_index[i] >= 1) | |
446 cbp |= 1 << (5 - i); | |
447 } | |
448 | |
449 cbpc = cbp & 3; | |
450 if (s->pict_type == I_TYPE) { | |
451 put_bits(&s->pb, | |
452 intra_MCBPC_bits[cbpc], | |
453 intra_MCBPC_code[cbpc]); | |
454 } else { | |
455 put_bits(&s->pb, 1, 0); /* mb coded */ | |
456 put_bits(&s->pb, | |
457 inter_MCBPC_bits[cbpc + 4], | |
458 inter_MCBPC_code[cbpc + 4]); | |
459 } | |
460 if (s->h263_pred) { | |
461 /* XXX: currently, we do not try to use ac prediction */ | |
462 put_bits(&s->pb, 1, 0); /* no ac prediction */ | |
463 } | |
464 cbpy = cbp >> 2; | |
465 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
466 } | |
467 | |
468 /* encode each block */ | |
469 if (s->h263_pred) { | |
470 for (i = 0; i < 6; i++) { | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
471 // mpeg4_encode_block(s, block[i], i); |
0 | 472 } |
473 } else { | |
474 for (i = 0; i < 6; i++) { | |
475 h263_encode_block(s, block[i], i); | |
476 } | |
477 } | |
478 } | |
479 | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
480 void h263_pred_acdc(MpegEncContext * s, INT16 *block, int n) |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
481 { |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
482 int x, y, wrap, a, c, pred_dc, scale, i; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
483 INT16 *dc_val, *ac_val, *ac_val1; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
484 |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
485 /* find prediction */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
486 if (n < 4) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
487 x = 2 * s->mb_x + 1 + (n & 1); |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
488 y = 2 * s->mb_y + 1 + ((n & 2) >> 1); |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
489 wrap = s->mb_width * 2 + 2; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
490 dc_val = s->dc_val[0]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
491 ac_val = s->ac_val[0][0]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
492 scale = s->y_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
493 } else { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
494 x = s->mb_x + 1; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
495 y = s->mb_y + 1; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
496 wrap = s->mb_width + 2; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
497 dc_val = s->dc_val[n - 4 + 1]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
498 ac_val = s->ac_val[n - 4 + 1][0]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
499 scale = s->c_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
500 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
501 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
502 ac_val += ((y) * wrap + (x)) * 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
503 ac_val1 = ac_val; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
504 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
505 /* B C |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
506 * A X |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
507 */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
508 a = dc_val[(x - 1) + (y) * wrap]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
509 c = dc_val[(x) + (y - 1) * wrap]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
510 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
511 pred_dc = 1024; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
512 if (s->ac_pred) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
513 if (s->h263_aic_dir) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
514 /* left prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
515 if (a != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
516 ac_val -= 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
517 for(i=1;i<8;i++) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
518 block[block_permute_op(i*8)] += ac_val[i]; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
519 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
520 pred_dc = a; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
521 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
522 } else { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
523 /* top prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
524 if (c != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
525 ac_val -= 16 * wrap; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
526 for(i=1;i<8;i++) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
527 block[block_permute_op(i)] += ac_val[i + 8]; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
528 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
529 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
530 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
531 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
532 } else { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
533 /* just DC prediction */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
534 if (a != 1024 && c != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
535 pred_dc = (a + c) >> 1; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
536 else if (a != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
537 pred_dc = a; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
538 else |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
539 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
540 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
541 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
542 /* we assume pred is positive */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
543 block[0]=block[0]*scale + pred_dc; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
544 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
545 if (block[0] < 0) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
546 block[0] = 0; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
547 else if (!(block[0] & 1)) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
548 block[0]++; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
549 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
550 /* Update AC/DC tables */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
551 dc_val[(x) + (y) * wrap] = block[0]; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
552 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
553 /* left copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
554 for(i=1;i<8;i++) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
555 ac_val1[i] = block[block_permute_op(i * 8)]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
556 /* top copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
557 for(i=1;i<8;i++) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
558 ac_val1[8 + i] = block[block_permute_op(i)]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
559 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
560 |
0 | 561 INT16 *h263_pred_motion(MpegEncContext * s, int block, |
562 int *px, int *py) | |
563 { | |
266 | 564 int xy, wrap; |
0 | 565 INT16 *A, *B, *C, *mot_val; |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
566 static const int off[4]= {2, 1, 1, -1}; |
0 | 567 |
266 | 568 wrap = s->block_wrap[0]; |
569 xy = s->block_index[block]; | |
0 | 570 |
245 | 571 mot_val = s->motion_val[xy]; |
0 | 572 |
573 /* special case for first line */ | |
272 | 574 if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line) && block<2) { |
245 | 575 A = s->motion_val[xy - 1]; |
0 | 576 *px = A[0]; |
577 *py = A[1]; | |
578 } else { | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
579 A = s->motion_val[xy - 1]; |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
580 B = s->motion_val[xy - wrap]; |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
581 C = s->motion_val[xy + off[block] - wrap]; |
0 | 582 *px = mid_pred(A[0], B[0], C[0]); |
583 *py = mid_pred(A[1], B[1], C[1]); | |
584 } | |
585 return mot_val; | |
586 } | |
587 | |
588 static void h263_encode_motion(MpegEncContext * s, int val) | |
589 { | |
590 int range, l, m, bit_size, sign, code, bits; | |
591 | |
592 if (val == 0) { | |
593 /* zero vector */ | |
594 code = 0; | |
595 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); | |
596 } else { | |
597 bit_size = s->f_code - 1; | |
598 range = 1 << bit_size; | |
599 /* modulo encoding */ | |
600 l = range * 32; | |
601 m = 2 * l; | |
602 if (val < -l) { | |
603 val += m; | |
604 } else if (val >= l) { | |
605 val -= m; | |
606 } | |
607 | |
608 if (val >= 0) { | |
609 val--; | |
610 code = (val >> bit_size) + 1; | |
611 bits = val & (range - 1); | |
612 sign = 0; | |
613 } else { | |
614 val = -val; | |
615 val--; | |
616 code = (val >> bit_size) + 1; | |
617 bits = val & (range - 1); | |
618 sign = 1; | |
619 } | |
620 | |
621 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); | |
622 if (bit_size > 0) { | |
623 put_bits(&s->pb, bit_size, bits); | |
624 } | |
625 } | |
626 } | |
627 | |
78 | 628 /* Encode MV differences on H.263+ with Unrestricted MV mode */ |
629 static void h263p_encode_umotion(MpegEncContext * s, int val) | |
630 { | |
631 short sval = 0; | |
632 short i = 0; | |
633 short n_bits = 0; | |
634 short temp_val; | |
635 int code = 0; | |
636 int tcode; | |
637 | |
638 if ( val == 0) | |
639 put_bits(&s->pb, 1, 1); | |
640 else if (val == 1) | |
641 put_bits(&s->pb, 3, 0); | |
642 else if (val == -1) | |
643 put_bits(&s->pb, 3, 2); | |
644 else { | |
645 | |
646 sval = ((val < 0) ? (short)(-val):(short)val); | |
647 temp_val = sval; | |
648 | |
649 while (temp_val != 0) { | |
650 temp_val = temp_val >> 1; | |
651 n_bits++; | |
652 } | |
653 | |
654 i = n_bits - 1; | |
655 while (i > 0) { | |
656 tcode = (sval & (1 << (i-1))) >> (i-1); | |
657 tcode = (tcode << 1) | 1; | |
658 code = (code << 2) | tcode; | |
659 i--; | |
660 } | |
661 code = ((code << 1) | (val < 0)) << 1; | |
662 put_bits(&s->pb, (2*n_bits)+1, code); | |
663 //printf("\nVal = %d\tCode = %d", sval, code); | |
664 } | |
665 } | |
666 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
667 static void init_mv_penalty_and_fcode(MpegEncContext *s) |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
668 { |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
669 int f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
670 int mv; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
671 for(f_code=1; f_code<=MAX_FCODE; f_code++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
672 for(mv=-MAX_MV; mv<=MAX_MV; mv++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
673 int len; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
674 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
675 if(mv==0) len= mvtab[0][1]; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
676 else{ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
677 int val, bit_size, range, code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
678 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
679 bit_size = s->f_code - 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
680 range = 1 << bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
681 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
682 val=mv; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
683 if (val < 0) |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
684 val = -val; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
685 val--; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
686 code = (val >> bit_size) + 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
687 if(code<33){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
688 len= mvtab[code][1] + 1 + bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
689 }else{ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
690 len= mvtab[32][1] + 2 + bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
691 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
692 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
693 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
694 mv_penalty[f_code][mv+MAX_MV]= len; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
695 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
696 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
697 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
698 for(f_code=MAX_FCODE; f_code>0; f_code--){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
699 for(mv=-(16<<f_code); mv<(16<<f_code); mv++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
700 fcode_tab[mv+MAX_MV]= f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
701 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
702 } |
287 | 703 |
704 for(mv=0; mv<MAX_MV*2+1; mv++){ | |
705 umv_fcode_tab[mv]= 1; | |
706 } | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
707 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
708 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
709 void h263_encode_init(MpegEncContext *s) |
0 | 710 { |
711 static int done = 0; | |
712 | |
713 if (!done) { | |
714 done = 1; | |
715 init_rl(&rl_inter); | |
716 init_rl(&rl_intra); | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
717 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
718 init_mv_penalty_and_fcode(s); |
0 | 719 } |
287 | 720 s->mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
721 |
287 | 722 // use fcodes >1 only for mpeg4 & h263 & h263p FIXME |
723 if(s->h263_plus) s->fcode_tab= umv_fcode_tab; | |
724 else if(s->h263_pred) s->fcode_tab= fcode_tab; | |
0 | 725 } |
726 | |
727 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) | |
728 { | |
729 int level, run, last, i, j, last_index, last_non_zero, sign, slevel; | |
730 int code; | |
731 RLTable *rl = &rl_inter; | |
732 | |
733 if (s->mb_intra) { | |
231 | 734 /* DC coef */ |
735 level = block[0]; | |
0 | 736 /* 255 cannot be represented, so we clamp */ |
737 if (level > 254) { | |
738 level = 254; | |
739 block[0] = 254; | |
740 } | |
231 | 741 /* 0 cannot be represented also */ |
742 else if (!level) { | |
743 level = 1; | |
744 block[0] = 1; | |
745 } | |
746 if (level == 128) | |
747 put_bits(&s->pb, 8, 0xff); | |
748 else | |
749 put_bits(&s->pb, 8, level & 0xff); | |
750 i = 1; | |
0 | 751 } else { |
231 | 752 i = 0; |
0 | 753 } |
754 | |
755 /* AC coefs */ | |
756 last_index = s->block_last_index[n]; | |
757 last_non_zero = i - 1; | |
758 for (; i <= last_index; i++) { | |
759 j = zigzag_direct[i]; | |
760 level = block[j]; | |
761 if (level) { | |
762 run = i - last_non_zero - 1; | |
763 last = (i == last_index); | |
764 sign = 0; | |
765 slevel = level; | |
766 if (level < 0) { | |
767 sign = 1; | |
768 level = -level; | |
769 } | |
770 code = get_rl_index(rl, last, run, level); | |
771 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
772 if (code == rl->n) { | |
773 put_bits(&s->pb, 1, last); | |
774 put_bits(&s->pb, 6, run); | |
775 put_bits(&s->pb, 8, slevel & 0xff); | |
776 } else { | |
777 put_bits(&s->pb, 1, sign); | |
778 } | |
779 last_non_zero = i; | |
780 } | |
781 } | |
782 } | |
783 | |
784 /***************************************************/ | |
785 | |
262 | 786 static void mpeg4_stuffing(PutBitContext * pbc) |
787 { | |
788 int length; | |
789 put_bits(pbc, 1, 0); | |
790 length= (-get_bit_count(pbc))&7; | |
791 put_bits(pbc, length, (1<<length)-1); | |
792 } | |
793 | |
794 static void put_string(PutBitContext * pbc, char *s) | |
795 { | |
796 while(*s){ | |
797 put_bits(pbc, 8, *s); | |
798 s++; | |
799 } | |
800 put_bits(pbc, 8, 0); | |
801 } | |
802 | |
263 | 803 static void mpeg4_encode_vol_header(MpegEncContext * s) |
0 | 804 { |
263 | 805 int vo_ver_id=1; //must be 2 if we want GMC or q-pel |
806 | |
807 if(get_bit_count(&s->pb)!=0) mpeg4_stuffing(&s->pb); | |
808 put_bits(&s->pb, 16, 0); | |
809 put_bits(&s->pb, 16, 0x100); /* video obj */ | |
810 put_bits(&s->pb, 16, 0); | |
811 put_bits(&s->pb, 16, 0x120); /* video obj layer */ | |
812 | |
813 put_bits(&s->pb, 1, 0); /* random access vol */ | |
814 put_bits(&s->pb, 8, 1); /* video obj type indication= simple obj */ | |
815 put_bits(&s->pb, 1, 1); /* is obj layer id= yes */ | |
816 put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */ | |
817 put_bits(&s->pb, 3, 1); /* is obj layer priority */ | |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
818 if(s->aspect_ratio_info) |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
819 put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
820 else |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
821 put_bits(&s->pb, 4, 1); /* aspect ratio info= sqare pixel */ |
263 | 822 put_bits(&s->pb, 1, 0); /* vol control parameters= no */ |
823 put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */ | |
824 put_bits(&s->pb, 1, 1); /* marker bit */ | |
825 put_bits(&s->pb, 16, s->time_increment_resolution=30000); | |
826 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
827 if (s->time_increment_bits < 1) | |
828 s->time_increment_bits = 1; | |
829 put_bits(&s->pb, 1, 1); /* marker bit */ | |
830 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ | |
831 put_bits(&s->pb, 1, 1); /* marker bit */ | |
832 put_bits(&s->pb, 13, s->width); /* vol width */ | |
833 put_bits(&s->pb, 1, 1); /* marker bit */ | |
834 put_bits(&s->pb, 13, s->height); /* vol height */ | |
835 put_bits(&s->pb, 1, 1); /* marker bit */ | |
836 put_bits(&s->pb, 1, 0); /* interlace */ | |
837 put_bits(&s->pb, 1, 1); /* obmc disable */ | |
838 if (vo_ver_id == 1) { | |
839 put_bits(&s->pb, 1, s->vol_sprite_usage=0); /* sprite enable */ | |
840 }else{ /* vo_ver_id == 2 */ | |
841 put_bits(&s->pb, 2, s->vol_sprite_usage=0); /* sprite enable */ | |
842 } | |
843 put_bits(&s->pb, 1, 0); /* not 8 bit */ | |
844 put_bits(&s->pb, 1, 0); /* quant type= h263 style*/ | |
845 if (vo_ver_id != 1) | |
846 put_bits(&s->pb, 1, s->quarter_sample=0); | |
847 put_bits(&s->pb, 1, 1); /* complexity estimation disable */ | |
848 put_bits(&s->pb, 1, 1); /* resync marker disable */ | |
849 put_bits(&s->pb, 1, 0); /* data partitioned */ | |
850 if (vo_ver_id != 1){ | |
851 put_bits(&s->pb, 1, 0); /* newpred */ | |
852 put_bits(&s->pb, 1, 0); /* reduced res vop */ | |
853 } | |
854 put_bits(&s->pb, 1, 0); /* scalability */ | |
855 | |
262 | 856 mpeg4_stuffing(&s->pb); |
857 put_bits(&s->pb, 16, 0); | |
858 put_bits(&s->pb, 16, 0x1B2); /* user_data */ | |
859 put_string(&s->pb, "ffmpeg"); //FIXME append some version ... | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
860 |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
861 s->no_rounding = 0; |
263 | 862 } |
863 | |
864 /* write mpeg4 VOP header */ | |
865 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) | |
866 { | |
867 if(s->pict_type==I_TYPE) mpeg4_encode_vol_header(s); | |
868 | |
869 if(get_bit_count(&s->pb)!=0) mpeg4_stuffing(&s->pb); | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
870 put_bits(&s->pb, 16, 0); /* vop header */ |
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
871 put_bits(&s->pb, 16, 0x1B6); /* vop header */ |
0 | 872 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ |
873 /* XXX: time base + 1 not always correct */ | |
874 put_bits(&s->pb, 1, 1); | |
875 put_bits(&s->pb, 1, 0); | |
876 | |
877 put_bits(&s->pb, 1, 1); /* marker */ | |
263 | 878 put_bits(&s->pb, s->time_increment_bits, 1); /* XXX: correct time increment */ |
0 | 879 put_bits(&s->pb, 1, 1); /* marker */ |
880 put_bits(&s->pb, 1, 1); /* vop coded */ | |
263 | 881 if ( s->pict_type == P_TYPE |
882 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { | |
883 s->no_rounding ^= 1; | |
0 | 884 put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ |
885 } | |
886 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ | |
263 | 887 //FIXME sprite stuff |
0 | 888 |
889 put_bits(&s->pb, 5, s->qscale); | |
890 | |
891 if (s->pict_type != I_TYPE) | |
892 put_bits(&s->pb, 3, s->f_code); /* fcode_for */ | |
263 | 893 if (s->pict_type == B_TYPE) |
894 put_bits(&s->pb, 3, s->b_code); /* fcode_back */ | |
0 | 895 // printf("****frame %d\n", picture_number); |
896 } | |
897 | |
898 void h263_dc_scale(MpegEncContext * s) | |
899 { | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
900 #if 1 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
901 const static UINT8 y_tab[32]={ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
902 // 0 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 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
903 0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,36,38,40,42,44,46 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
904 }; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
905 const static UINT8 c_tab[32]={ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
906 // 0 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 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
907 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,20,21,22,23,24,25 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
908 }; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
909 s->y_dc_scale = y_tab[s->qscale]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
910 s->c_dc_scale = c_tab[s->qscale]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
911 #else |
0 | 912 int quant; |
913 quant = s->qscale; | |
914 /* luminance */ | |
915 if (quant < 5) | |
916 s->y_dc_scale = 8; | |
917 else if (quant > 4 && quant < 9) | |
918 s->y_dc_scale = (2 * quant); | |
919 else if (quant > 8 && quant < 25) | |
920 s->y_dc_scale = (quant + 8); | |
921 else | |
922 s->y_dc_scale = (2 * quant - 16); | |
923 /* chrominance */ | |
924 if (quant < 5) | |
925 s->c_dc_scale = 8; | |
926 else if (quant > 4 && quant < 25) | |
927 s->c_dc_scale = ((quant + 13) / 2); | |
928 else | |
929 s->c_dc_scale = (quant - 6); | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
930 #endif |
0 | 931 } |
932 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
933 static inline int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr) |
0 | 934 { |
266 | 935 int a, b, c, wrap, pred, scale; |
0 | 936 UINT16 *dc_val; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
937 int dummy; |
0 | 938 |
939 /* find prediction */ | |
940 if (n < 4) { | |
941 scale = s->y_dc_scale; | |
942 } else { | |
943 scale = s->c_dc_scale; | |
944 } | |
266 | 945 wrap= s->block_wrap[n]; |
946 dc_val = s->dc_val[0] + s->block_index[n]; | |
0 | 947 |
948 /* B C | |
949 * A X | |
950 */ | |
266 | 951 a = dc_val[ - 1]; |
952 b = dc_val[ - 1 - wrap]; | |
953 c = dc_val[ - wrap]; | |
0 | 954 |
955 if (abs(a - b) < abs(b - c)) { | |
956 pred = c; | |
957 *dir_ptr = 1; /* top */ | |
958 } else { | |
959 pred = a; | |
960 *dir_ptr = 0; /* left */ | |
961 } | |
962 /* we assume pred is positive */ | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
963 #ifdef ARCH_X86 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
964 asm volatile ( |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
965 "xorl %%edx, %%edx \n\t" |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
966 "mul %%ecx \n\t" |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
967 : "=d" (pred), "=a"(dummy) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
968 : "a" (pred + (scale >> 1)), "c" (inverse[scale]) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
969 ); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
970 #else |
0 | 971 pred = (pred + (scale >> 1)) / scale; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
972 #endif |
0 | 973 |
974 /* prepare address for prediction update */ | |
266 | 975 *dc_val_ptr = &dc_val[0]; |
0 | 976 |
977 return pred; | |
978 } | |
979 | |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
980 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, |
0 | 981 int dir) |
982 { | |
266 | 983 int i; |
0 | 984 INT16 *ac_val, *ac_val1; |
985 | |
986 /* find prediction */ | |
266 | 987 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
0 | 988 ac_val1 = ac_val; |
989 if (s->ac_pred) { | |
990 if (dir == 0) { | |
991 /* left prediction */ | |
992 ac_val -= 16; | |
993 for(i=1;i<8;i++) { | |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
994 block[block_permute_op(i*8)] += ac_val[i]; |
0 | 995 } |
996 } else { | |
997 /* top prediction */ | |
266 | 998 ac_val -= 16 * s->block_wrap[n]; |
0 | 999 for(i=1;i<8;i++) { |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
1000 block[block_permute_op(i)] += ac_val[i + 8]; |
0 | 1001 } |
1002 } | |
1003 } | |
1004 /* left copy */ | |
1005 for(i=1;i<8;i++) | |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
1006 ac_val1[i] = block[block_permute_op(i * 8)]; |
0 | 1007 /* top copy */ |
1008 for(i=1;i<8;i++) | |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
1009 ac_val1[8 + i] = block[block_permute_op(i)]; |
0 | 1010 } |
1011 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1012 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1013 int dir) |
0 | 1014 { |
266 | 1015 int i; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1016 INT16 *ac_val; |
0 | 1017 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1018 /* find prediction */ |
266 | 1019 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1020 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1021 if (dir == 0) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1022 /* left prediction */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1023 ac_val -= 16; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1024 for(i=1;i<8;i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1025 block[block_permute_op(i*8)] -= ac_val[i]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1026 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1027 } else { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1028 /* top prediction */ |
266 | 1029 ac_val -= 16 * s->block_wrap[n]; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1030 for(i=1;i<8;i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1031 block[block_permute_op(i)] -= ac_val[i + 8]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1032 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1033 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1034 } |
0 | 1035 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1036 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1037 static inline void mpeg4_encode_dc(MpegEncContext * s, int level, int n) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1038 { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1039 int size, v; |
0 | 1040 /* find number of bits */ |
1041 size = 0; | |
1042 v = abs(level); | |
1043 while (v) { | |
1044 v >>= 1; | |
1045 size++; | |
1046 } | |
1047 | |
1048 if (n < 4) { | |
1049 /* luminance */ | |
1050 put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]); | |
1051 } else { | |
1052 /* chrominance */ | |
1053 put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]); | |
1054 } | |
1055 | |
1056 /* encode remaining bits */ | |
1057 if (size > 0) { | |
1058 if (level < 0) | |
1059 level = (-level) ^ ((1 << size) - 1); | |
1060 put_bits(&s->pb, size, level); | |
1061 if (size > 8) | |
1062 put_bits(&s->pb, 1, 1); | |
1063 } | |
1064 } | |
1065 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1066 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, UINT8 *scan_table) |
0 | 1067 { |
1068 int level, run, last, i, j, last_index, last_non_zero, sign, slevel; | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1069 int code; |
0 | 1070 const RLTable *rl; |
1071 | |
1072 if (s->mb_intra) { | |
1073 /* mpeg4 based DC predictor */ | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1074 mpeg4_encode_dc(s, intra_dc, n); |
0 | 1075 i = 1; |
1076 rl = &rl_intra; | |
1077 } else { | |
1078 i = 0; | |
1079 rl = &rl_inter; | |
1080 } | |
1081 | |
1082 /* AC coefs */ | |
1083 last_index = s->block_last_index[n]; | |
1084 last_non_zero = i - 1; | |
1085 for (; i <= last_index; i++) { | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1086 j = scan_table[i]; |
0 | 1087 level = block[j]; |
1088 if (level) { | |
1089 run = i - last_non_zero - 1; | |
1090 last = (i == last_index); | |
1091 sign = 0; | |
1092 slevel = level; | |
1093 if (level < 0) { | |
1094 sign = 1; | |
1095 level = -level; | |
1096 } | |
1097 code = get_rl_index(rl, last, run, level); | |
1098 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1099 if (code == rl->n) { | |
1100 int level1, run1; | |
1101 level1 = level - rl->max_level[last][run]; | |
1102 if (level1 < 1) | |
1103 goto esc2; | |
1104 code = get_rl_index(rl, last, run, level1); | |
1105 if (code == rl->n) { | |
1106 esc2: | |
1107 put_bits(&s->pb, 1, 1); | |
1108 if (level > MAX_LEVEL) | |
1109 goto esc3; | |
1110 run1 = run - rl->max_run[last][level] - 1; | |
1111 if (run1 < 0) | |
1112 goto esc3; | |
1113 code = get_rl_index(rl, last, run1, level); | |
1114 if (code == rl->n) { | |
1115 esc3: | |
1116 /* third escape */ | |
1117 put_bits(&s->pb, 1, 1); | |
1118 put_bits(&s->pb, 1, last); | |
1119 put_bits(&s->pb, 6, run); | |
1120 put_bits(&s->pb, 1, 1); | |
1121 put_bits(&s->pb, 12, slevel & 0xfff); | |
1122 put_bits(&s->pb, 1, 1); | |
1123 } else { | |
1124 /* second escape */ | |
1125 put_bits(&s->pb, 1, 0); | |
1126 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1127 put_bits(&s->pb, 1, sign); | |
1128 } | |
1129 } else { | |
1130 /* first escape */ | |
1131 put_bits(&s->pb, 1, 0); | |
1132 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1133 put_bits(&s->pb, 1, sign); | |
1134 } | |
1135 } else { | |
1136 put_bits(&s->pb, 1, sign); | |
1137 } | |
1138 last_non_zero = i; | |
1139 } | |
1140 } | |
1141 } | |
1142 | |
1143 | |
1144 | |
1145 /***********************************************/ | |
1146 /* decoding */ | |
1147 | |
1148 static VLC intra_MCBPC_vlc; | |
1149 static VLC inter_MCBPC_vlc; | |
1150 static VLC cbpy_vlc; | |
1151 static VLC mv_vlc; | |
1152 static VLC dc_lum, dc_chrom; | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1153 static VLC sprite_trajectory; |
262 | 1154 static VLC mb_type_b_vlc; |
0 | 1155 |
1156 void init_rl(RLTable *rl) | |
1157 { | |
1158 INT8 max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; | |
1159 UINT8 index_run[MAX_RUN+1]; | |
1160 int last, run, level, start, end, i; | |
1161 | |
1162 /* compute max_level[], max_run[] and index_run[] */ | |
1163 for(last=0;last<2;last++) { | |
1164 if (last == 0) { | |
1165 start = 0; | |
1166 end = rl->last; | |
1167 } else { | |
1168 start = rl->last; | |
1169 end = rl->n; | |
1170 } | |
1171 | |
1172 memset(max_level, 0, MAX_RUN + 1); | |
1173 memset(max_run, 0, MAX_LEVEL + 1); | |
1174 memset(index_run, rl->n, MAX_RUN + 1); | |
1175 for(i=start;i<end;i++) { | |
1176 run = rl->table_run[i]; | |
1177 level = rl->table_level[i]; | |
1178 if (index_run[run] == rl->n) | |
1179 index_run[run] = i; | |
1180 if (level > max_level[run]) | |
1181 max_level[run] = level; | |
1182 if (run > max_run[level]) | |
1183 max_run[level] = run; | |
1184 } | |
1185 rl->max_level[last] = malloc(MAX_RUN + 1); | |
1186 memcpy(rl->max_level[last], max_level, MAX_RUN + 1); | |
1187 rl->max_run[last] = malloc(MAX_LEVEL + 1); | |
1188 memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); | |
1189 rl->index_run[last] = malloc(MAX_RUN + 1); | |
1190 memcpy(rl->index_run[last], index_run, MAX_RUN + 1); | |
1191 } | |
1192 } | |
1193 | |
1194 void init_vlc_rl(RLTable *rl) | |
1195 { | |
1196 init_vlc(&rl->vlc, 9, rl->n + 1, | |
1197 &rl->table_vlc[0][1], 4, 2, | |
1198 &rl->table_vlc[0][0], 4, 2); | |
1199 } | |
1200 | |
1201 /* init vlcs */ | |
1202 | |
1203 /* XXX: find a better solution to handle static init */ | |
1204 void h263_decode_init_vlc(MpegEncContext *s) | |
1205 { | |
1206 static int done = 0; | |
1207 | |
1208 if (!done) { | |
1209 done = 1; | |
1210 | |
1211 init_vlc(&intra_MCBPC_vlc, 6, 8, | |
1212 intra_MCBPC_bits, 1, 1, | |
1213 intra_MCBPC_code, 1, 1); | |
161 | 1214 init_vlc(&inter_MCBPC_vlc, 9, 25, |
0 | 1215 inter_MCBPC_bits, 1, 1, |
1216 inter_MCBPC_code, 1, 1); | |
1217 init_vlc(&cbpy_vlc, 6, 16, | |
1218 &cbpy_tab[0][1], 2, 1, | |
1219 &cbpy_tab[0][0], 2, 1); | |
1220 init_vlc(&mv_vlc, 9, 33, | |
1221 &mvtab[0][1], 2, 1, | |
1222 &mvtab[0][0], 2, 1); | |
1223 init_rl(&rl_inter); | |
1224 init_rl(&rl_intra); | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1225 init_rl(&rl_intra_aic); |
0 | 1226 init_vlc_rl(&rl_inter); |
1227 init_vlc_rl(&rl_intra); | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1228 init_vlc_rl(&rl_intra_aic); |
0 | 1229 init_vlc(&dc_lum, 9, 13, |
1230 &DCtab_lum[0][1], 2, 1, | |
1231 &DCtab_lum[0][0], 2, 1); | |
1232 init_vlc(&dc_chrom, 9, 13, | |
1233 &DCtab_chrom[0][1], 2, 1, | |
1234 &DCtab_chrom[0][0], 2, 1); | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1235 init_vlc(&sprite_trajectory, 9, 15, |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1236 &sprite_trajectory_tab[0][1], 4, 2, |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1237 &sprite_trajectory_tab[0][0], 4, 2); |
262 | 1238 init_vlc(&mb_type_b_vlc, 4, 4, |
1239 &mb_type_b_tab[0][1], 2, 1, | |
1240 &mb_type_b_tab[0][0], 2, 1); | |
0 | 1241 } |
1242 } | |
1243 | |
162 | 1244 int h263_decode_gob_header(MpegEncContext *s) |
1245 { | |
1246 unsigned int val, gfid; | |
1247 | |
1248 /* Check for GOB Start Code */ | |
1249 val = show_bits(&s->gb, 16); | |
1250 if (val == 0) { | |
1251 /* We have a GBSC probably with GSTUFF */ | |
1252 skip_bits(&s->gb, 16); /* Drop the zeros */ | |
1253 while (get_bits1(&s->gb) == 0); /* Seek the '1' bit */ | |
1254 #ifdef DEBUG | |
1255 fprintf(stderr,"\nGOB Start Code at MB %d\n", (s->mb_y * s->mb_width) + s->mb_x); | |
1256 #endif | |
1257 s->gob_number = get_bits(&s->gb, 5); /* GN */ | |
1258 gfid = get_bits(&s->gb, 2); /* GFID */ | |
1259 s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | |
1260 #ifdef DEBUG | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
1261 fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", s->gob_number, gfid, s->qscale); |
162 | 1262 #endif |
1263 return 1; | |
1264 } | |
1265 return 0; | |
1266 | |
1267 } | |
1268 | |
290 | 1269 static inline void memsetw(short *tab, int val, int n) |
1270 { | |
1271 int i; | |
1272 for(i=0;i<n;i++) | |
1273 tab[i] = val; | |
1274 } | |
1275 | |
1276 static int mpeg4_resync(MpegEncContext *s) | |
1277 { | |
1278 int state, v, bits; | |
1279 int mb_num_bits= av_log2(s->mb_num - 1) + 1; | |
1280 int header_extension=0, mb_num; | |
1281 int c_wrap, c_xy, l_wrap, l_xy; | |
1282 //printf("resync at %d %d\n", s->mb_x, s->mb_y); | |
1283 //printf("%X\n", show_bits(&s->gb, 24)); | |
1284 | |
1285 if( get_bits_count(&s->gb) > s->gb.size*8-32) | |
1286 return 0; | |
1287 | |
1288 align_get_bits(&s->gb); | |
1289 state = 0xff; | |
1290 for(;;) { | |
1291 v = get_bits(&s->gb, 8); | |
1292 //printf("%X ", v); | |
1293 state = ((state << 8) | v) & 0xffff; | |
1294 if (state == 0) break; | |
1295 if( get_bits_count(&s->gb) > s->gb.size*8-32){ | |
1296 printf("resync failed\n"); | |
1297 return -1; | |
1298 } | |
1299 } | |
1300 //printf("%X\n", show_bits(&s->gb, 24)); | |
1301 bits=0; | |
1302 while(!get_bits1(&s->gb) && bits<30) bits++; | |
1303 if(s->pict_type == P_TYPE && bits != s->f_code-1) | |
1304 printf("marker does not match f_code\n"); | |
1305 //FIXME check bits for B-framess | |
1306 //printf("%X\n", show_bits(&s->gb, 24)); | |
1307 | |
1308 if(s->shape != RECT_SHAPE){ | |
1309 header_extension= get_bits1(&s->gb); | |
1310 //FIXME more stuff here | |
1311 } | |
1312 | |
1313 mb_num= get_bits(&s->gb, mb_num_bits); | |
1314 if(mb_num != s->mb_x + s->mb_y*s->mb_width){ | |
1315 printf("MB-num change not supported %d %d\n", mb_num, s->mb_x + s->mb_y*s->mb_width); | |
1316 // s->mb_x= mb_num % s->mb_width; | |
1317 // s->mb_y= mb_num / s->mb_width; | |
1318 //FIXME many vars are wrong now | |
1319 } | |
1320 | |
1321 if(s->shape != BIN_ONLY_SHAPE){ | |
1322 s->qscale= get_bits(&s->gb, 5); | |
1323 h263_dc_scale(s); | |
1324 } | |
1325 | |
1326 if(s->shape == RECT_SHAPE){ | |
1327 header_extension= get_bits1(&s->gb); | |
1328 } | |
1329 if(header_extension){ | |
1330 int time_incr=0; | |
1331 printf("header extension not really supported\n"); | |
1332 while (get_bits1(&s->gb) != 0) | |
1333 time_incr++; | |
1334 | |
1335 check_marker(&s->gb, "before time_increment in video packed header"); | |
1336 s->time_increment= get_bits(&s->gb, s->time_increment_bits); | |
1337 if(s->pict_type!=B_TYPE){ | |
1338 s->time_base+= time_incr; | |
1339 s->last_non_b_time[1]= s->last_non_b_time[0]; | |
1340 s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment; | |
1341 }else{ | |
1342 s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution; | |
1343 s->time+= s->time_increment; | |
1344 } | |
1345 check_marker(&s->gb, "before vop_coding_type in video packed header"); | |
1346 | |
1347 skip_bits(&s->gb, 2); /* vop coding type */ | |
1348 //FIXME not rect stuff here | |
1349 | |
1350 if(s->shape != BIN_ONLY_SHAPE){ | |
1351 skip_bits(&s->gb, 3); /* intra dc vlc threshold */ | |
1352 | |
1353 if(s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE && s->num_sprite_warping_points){ | |
1354 mpeg4_decode_sprite_trajectory(s); | |
1355 } | |
1356 | |
1357 //FIXME reduced res stuff here | |
1358 | |
1359 if (s->pict_type != I_TYPE) { | |
1360 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ | |
1361 if(s->f_code==0){ | |
1362 printf("Error, video packet header damaged or not MPEG4 header (f_code=0)\n"); | |
1363 return -1; // makes no sense to continue, as the MV decoding will break very quickly | |
1364 } | |
1365 } | |
1366 if (s->pict_type == B_TYPE) { | |
1367 s->b_code = get_bits(&s->gb, 3); | |
1368 } | |
1369 } | |
1370 | |
1371 } | |
1372 //FIXME new-pred stuff | |
1373 | |
1374 l_wrap= s->block_wrap[0]; | |
1375 l_xy= s->mb_y*l_wrap*2; | |
1376 c_wrap= s->block_wrap[4]; | |
1377 c_xy= s->mb_y*c_wrap; | |
1378 | |
1379 /* clean DC */ | |
1380 memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*3); | |
1381 memsetw(s->dc_val[1] + c_xy, 1024, c_wrap*2); | |
1382 memsetw(s->dc_val[2] + c_xy, 1024, c_wrap*2); | |
1383 | |
1384 /* clean AC */ | |
1385 memset(s->ac_val[0] + l_xy, 0, l_wrap*3*16*sizeof(INT16)); | |
1386 memset(s->ac_val[1] + c_xy, 0, c_wrap*2*16*sizeof(INT16)); | |
1387 memset(s->ac_val[2] + c_xy, 0, c_wrap*2*16*sizeof(INT16)); | |
1388 | |
1389 /* clean MV */ | |
1390 memset(s->motion_val + l_xy, 0, l_wrap*3*2*sizeof(INT16)); | |
1391 // memset(s->motion_val, 0, 2*sizeof(INT16)*(2 + s->mb_width*2)*(2 + s->mb_height*2)); | |
1392 s->resync_x_pos= s->mb_x; | |
1393 s->first_slice_line=1; | |
1394 | |
1395 return 0; | |
1396 } | |
1397 | |
0 | 1398 int h263_decode_mb(MpegEncContext *s, |
1399 DCTELEM block[6][64]) | |
1400 { | |
1401 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | |
1402 INT16 *mot_val; | |
110 | 1403 static INT8 quant_tab[4] = { -1, -2, 1, 2 }; |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
1404 |
290 | 1405 if(s->resync_marker){ |
1406 if( s->resync_x_pos == s->mb_x+1 | |
1407 || s->resync_x_pos == s->mb_x){ | |
1408 /* f*ck mpeg4 | |
1409 this is here so we dont need to slowdown h263_pred_motion with it */ | |
1410 if(s->resync_x_pos == s->mb_x+1 && s->mb_x==0){ | |
1411 int xy= s->block_index[0] - s->block_wrap[0]; | |
1412 s->motion_val[xy][0]= s->motion_val[xy+2][0]; | |
1413 s->motion_val[xy][1]= s->motion_val[xy+2][1]; | |
1414 } | |
1415 | |
1416 s->first_slice_line=0; | |
1417 s->resync_x_pos=0; // isnt needed but for cleanness sake ;) | |
1418 } | |
1419 | |
1420 if(show_aligned_bits(&s->gb, 1, 16) == 0){ | |
1421 if( mpeg4_resync(s) < 0 ) return -1; | |
1422 | |
1423 } | |
1424 } | |
1425 | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1426 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { |
21 | 1427 if (get_bits1(&s->gb)) { |
0 | 1428 /* skip mb */ |
1429 s->mb_intra = 0; | |
1430 for(i=0;i<6;i++) | |
1431 s->block_last_index[i] = -1; | |
1432 s->mv_dir = MV_DIR_FORWARD; | |
1433 s->mv_type = MV_TYPE_16X16; | |
255 | 1434 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
1435 const int a= s->sprite_warping_accuracy; | |
1436 // int l = (1 << (s->f_code - 1)) * 32; | |
1437 | |
1438 s->mcsel=1; | |
1439 s->mv[0][0][0] = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
1440 s->mv[0][0][1] = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
1441 /* if (s->mv[0][0][0] < -l) s->mv[0][0][0]= -l; | |
1442 else if (s->mv[0][0][0] >= l) s->mv[0][0][0]= l-1; | |
1443 if (s->mv[0][0][1] < -l) s->mv[0][0][1]= -l; | |
1444 else if (s->mv[0][0][1] >= l) s->mv[0][0][1]= l-1;*/ | |
1445 | |
1446 s->mb_skiped = 0; | |
1447 }else{ | |
1448 s->mcsel=0; | |
1449 s->mv[0][0][0] = 0; | |
1450 s->mv[0][0][1] = 0; | |
1451 s->mb_skiped = 1; | |
1452 } | |
0 | 1453 return 0; |
1454 } | |
1455 cbpc = get_vlc(&s->gb, &inter_MCBPC_vlc); | |
144 | 1456 //fprintf(stderr, "\tCBPC: %d", cbpc); |
0 | 1457 if (cbpc < 0) |
1458 return -1; | |
161 | 1459 if (cbpc > 20) |
1460 cbpc+=3; | |
1461 else if (cbpc == 20) | |
1462 fprintf(stderr, "Stuffing !"); | |
144 | 1463 |
0 | 1464 dquant = cbpc & 8; |
1465 s->mb_intra = ((cbpc & 4) != 0); | |
262 | 1466 if (s->mb_intra) goto intra; |
1467 | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1468 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1469 s->mcsel= get_bits1(&s->gb); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1470 else s->mcsel= 0; |
0 | 1471 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
1472 cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); | |
1473 if (dquant) { | |
1474 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
1475 if (s->qscale < 1) | |
1476 s->qscale = 1; | |
1477 else if (s->qscale > 31) | |
1478 s->qscale = 31; | |
290 | 1479 h263_dc_scale(s); |
0 | 1480 } |
1481 s->mv_dir = MV_DIR_FORWARD; | |
1482 if ((cbpc & 16) == 0) { | |
1483 /* 16x16 motion prediction */ | |
1484 s->mv_type = MV_TYPE_16X16; | |
1485 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1486 if (s->umvplus_dec) |
78 | 1487 mx = h263p_decode_umotion(s, pred_x); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1488 else if(!s->mcsel) |
262 | 1489 mx = h263_decode_motion(s, pred_x, s->f_code); |
255 | 1490 else { |
1491 const int a= s->sprite_warping_accuracy; | |
1492 // int l = (1 << (s->f_code - 1)) * 32; | |
1493 mx= RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
1494 // if (mx < -l) mx= -l; | |
1495 // else if (mx >= l) mx= l-1; | |
1496 } | |
0 | 1497 if (mx >= 0xffff) |
1498 return -1; | |
78 | 1499 |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1500 if (s->umvplus_dec) |
78 | 1501 my = h263p_decode_umotion(s, pred_y); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1502 else if(!s->mcsel) |
262 | 1503 my = h263_decode_motion(s, pred_y, s->f_code); |
255 | 1504 else{ |
1505 const int a= s->sprite_warping_accuracy; | |
1506 // int l = (1 << (s->f_code - 1)) * 32; | |
1507 my= RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
1508 // if (my < -l) my= -l; | |
1509 // else if (my >= l) my= l-1; | |
1510 } | |
0 | 1511 if (my >= 0xffff) |
1512 return -1; | |
1513 s->mv[0][0][0] = mx; | |
1514 s->mv[0][0][1] = my; | |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1515 /*fprintf(stderr, "\n MB %d", (s->mb_y * s->mb_width) + s->mb_x); |
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1516 fprintf(stderr, "\n\tmvx: %d\t\tpredx: %d", mx, pred_x); |
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1517 fprintf(stderr, "\n\tmvy: %d\t\tpredy: %d", my, pred_y);*/ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1518 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
78 | 1519 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
1520 | |
0 | 1521 } else { |
1522 s->mv_type = MV_TYPE_8X8; | |
1523 for(i=0;i<4;i++) { | |
1524 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); | |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1525 if (s->umvplus_dec) |
78 | 1526 mx = h263p_decode_umotion(s, pred_x); |
1527 else | |
262 | 1528 mx = h263_decode_motion(s, pred_x, s->f_code); |
0 | 1529 if (mx >= 0xffff) |
1530 return -1; | |
78 | 1531 |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1532 if (s->umvplus_dec) |
78 | 1533 my = h263p_decode_umotion(s, pred_y); |
1534 else | |
262 | 1535 my = h263_decode_motion(s, pred_y, s->f_code); |
0 | 1536 if (my >= 0xffff) |
1537 return -1; | |
1538 s->mv[0][i][0] = mx; | |
1539 s->mv[0][i][1] = my; | |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1540 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
78 | 1541 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
0 | 1542 mot_val[0] = mx; |
1543 mot_val[1] = my; | |
1544 } | |
1545 } | |
262 | 1546 } else if(s->pict_type==B_TYPE) { |
1547 int modb1; // first bit of modb | |
1548 int modb2; // second bit of modb | |
1549 int mb_type; | |
1550 int time_pp; | |
1551 int time_pb; | |
1552 int xy; | |
1553 | |
1554 s->mb_intra = 0; //B-frames never contain intra blocks | |
1555 s->mcsel=0; // ... true gmc blocks | |
1556 | |
1557 if(s->mb_x==0){ | |
1558 s->last_mv[0][0][0]= | |
1559 s->last_mv[0][0][1]= | |
1560 s->last_mv[1][0][0]= | |
1561 s->last_mv[1][0][1]= 0; | |
1562 } | |
1563 | |
1564 /* if we skipped it in the future P Frame than skip it now too */ | |
1565 s->mb_skiped= s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC | |
1566 | |
1567 if(s->mb_skiped){ | |
1568 /* skip mb */ | |
1569 for(i=0;i<6;i++) | |
1570 s->block_last_index[i] = -1; | |
1571 | |
1572 s->mv_dir = MV_DIR_FORWARD; | |
1573 s->mv_type = MV_TYPE_16X16; | |
1574 s->mv[0][0][0] = 0; | |
1575 s->mv[0][0][1] = 0; | |
1576 s->mv[1][0][0] = 0; | |
1577 s->mv[1][0][1] = 0; | |
291 | 1578 //FIXME is this correct? |
1579 /* s->last_mv[0][0][0]= | |
1580 s->last_mv[0][0][1]=0;*/ | |
262 | 1581 s->mb_skiped = 1; |
1582 return 0; | |
1583 } | |
1584 | |
1585 modb1= get_bits1(&s->gb); | |
1586 if(modb1==0){ | |
1587 modb2= get_bits1(&s->gb); | |
1588 mb_type= get_vlc(&s->gb, &mb_type_b_vlc); | |
1589 if(modb2==0) cbp= get_bits(&s->gb, 6); | |
1590 else cbp=0; | |
1591 if (mb_type && cbp) { | |
1592 if(get_bits1(&s->gb)){ | |
1593 s->qscale +=get_bits1(&s->gb)*4 - 2; | |
1594 if (s->qscale < 1) | |
1595 s->qscale = 1; | |
1596 else if (s->qscale > 31) | |
1597 s->qscale = 31; | |
290 | 1598 h263_dc_scale(s); |
262 | 1599 } |
1600 } | |
1601 }else{ | |
1602 mb_type=4; //like 0 but no vectors coded | |
1603 cbp=0; | |
1604 } | |
1605 s->mv_type = MV_TYPE_16X16; // we'll switch to 8x8 only if the last P frame had 8x8 for this MB and mb_type=0 here | |
1606 mx=my=0; //for case 4, we could put this to the mb_type=4 but than gcc compains about uninitalized mx/my | |
1607 switch(mb_type) | |
1608 { | |
1609 case 0: | |
1610 mx = h263_decode_motion(s, 0, 1); | |
1611 my = h263_decode_motion(s, 0, 1); | |
1612 case 4: | |
1613 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
266 | 1614 xy= s->block_index[0]; |
262 | 1615 time_pp= s->last_non_b_time[0] - s->last_non_b_time[1]; |
1616 time_pb= s->time - s->last_non_b_time[1]; | |
1617 //if(time_pp>3000 )printf("%d %d ", time_pp, time_pb); | |
1618 //FIXME 4MV | |
1619 //FIXME avoid divides | |
1620 s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; | |
1621 s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp + my; | |
1622 s->mv[1][0][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] | |
1623 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx; | |
1624 s->mv[1][0][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] | |
1625 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my; | |
1626 /* s->mv[0][0][0] = | |
1627 s->mv[0][0][1] = | |
1628 s->mv[1][0][0] = | |
1629 s->mv[1][0][1] = 1000;*/ | |
1630 break; | |
1631 case 1: | |
1632 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
1633 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
1634 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
1635 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
1636 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
1637 | |
1638 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
1639 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
1640 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
1641 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
1642 break; | |
1643 case 2: | |
1644 s->mv_dir = MV_DIR_BACKWARD; | |
1645 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
1646 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
1647 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
1648 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
1649 break; | |
1650 case 3: | |
1651 s->mv_dir = MV_DIR_FORWARD; | |
1652 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
1653 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
1654 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
1655 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
1656 break; | |
1657 default: return -1; | |
1658 } | |
1659 } else { /* I-Frame */ | |
1660 cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); | |
1661 if (cbpc < 0) | |
1662 return -1; | |
1663 dquant = cbpc & 4; | |
1664 s->mb_intra = 1; | |
1665 intra: | |
0 | 1666 s->ac_pred = 0; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1667 if (s->h263_pred || s->h263_aic) { |
21 | 1668 s->ac_pred = get_bits1(&s->gb); |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1669 if (s->ac_pred && s->h263_aic) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1670 s->h263_aic_dir = get_bits1(&s->gb); |
0 | 1671 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1672 if (s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1673 s->y_dc_scale = 2 * s->qscale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1674 s->c_dc_scale = 2 * s->qscale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1675 } |
0 | 1676 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
1677 cbp = (cbpc & 3) | (cbpy << 2); | |
1678 if (dquant) { | |
1679 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
1680 if (s->qscale < 1) | |
1681 s->qscale = 1; | |
1682 else if (s->qscale > 31) | |
1683 s->qscale = 31; | |
290 | 1684 h263_dc_scale(s); |
0 | 1685 } |
1686 } | |
1687 | |
1688 /* decode each block */ | |
1689 if (s->h263_pred) { | |
1690 for (i = 0; i < 6; i++) { | |
1691 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
1692 return -1; | |
1693 } | |
1694 } else { | |
1695 for (i = 0; i < 6; i++) { | |
1696 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
1697 return -1; | |
1698 } | |
1699 } | |
1700 return 0; | |
1701 } | |
1702 | |
262 | 1703 static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) |
0 | 1704 { |
1705 int code, val, sign, shift, l, m; | |
1706 | |
1707 code = get_vlc(&s->gb, &mv_vlc); | |
1708 if (code < 0) | |
1709 return 0xffff; | |
1710 | |
1711 if (code == 0) | |
1712 return pred; | |
21 | 1713 sign = get_bits1(&s->gb); |
262 | 1714 shift = f_code - 1; |
0 | 1715 val = (code - 1) << shift; |
1716 if (shift > 0) | |
1717 val |= get_bits(&s->gb, shift); | |
1718 val++; | |
1719 if (sign) | |
1720 val = -val; | |
1721 val += pred; | |
1722 | |
1723 /* modulo decoding */ | |
1724 if (!s->h263_long_vectors) { | |
262 | 1725 l = (1 << (f_code - 1)) * 32; |
0 | 1726 m = 2 * l; |
1727 if (val < -l) { | |
1728 val += m; | |
1729 } else if (val >= l) { | |
1730 val -= m; | |
1731 } | |
1732 } else { | |
1733 /* horrible h263 long vector mode */ | |
1734 if (pred < -31 && val < -63) | |
1735 val += 64; | |
1736 if (pred > 32 && val > 63) | |
1737 val -= 64; | |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1738 |
0 | 1739 } |
1740 return val; | |
1741 } | |
1742 | |
78 | 1743 /* Decodes RVLC of H.263+ UMV */ |
1744 static int h263p_decode_umotion(MpegEncContext * s, int pred) | |
1745 { | |
1746 int code = 0, sign; | |
1747 | |
1748 if (get_bits1(&s->gb)) /* Motion difference = 0 */ | |
1749 return pred; | |
1750 | |
1751 code = 2 + get_bits1(&s->gb); | |
1752 | |
1753 while (get_bits1(&s->gb)) | |
1754 { | |
1755 code <<= 1; | |
1756 code += get_bits1(&s->gb); | |
1757 } | |
1758 sign = code & 1; | |
1759 code >>= 1; | |
1760 | |
1761 code = (sign) ? (pred - code) : (pred + code); | |
1762 #ifdef DEBUG | |
1763 fprintf(stderr,"H.263+ UMV Motion = %d\n", code); | |
1764 #endif | |
1765 return code; | |
1766 | |
1767 } | |
1768 | |
0 | 1769 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
1770 int n, int coded) | |
1771 { | |
1772 int code, level, i, j, last, run; | |
1773 RLTable *rl = &rl_inter; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1774 const UINT8 *scan_table; |
0 | 1775 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1776 scan_table = zigzag_direct; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1777 if (s->h263_aic && s->mb_intra) { |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1778 rl = &rl_intra_aic; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1779 i = 0; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1780 if (s->ac_pred) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1781 if (s->h263_aic_dir) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1782 scan_table = ff_alternate_vertical_scan; /* left */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1783 else |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1784 scan_table = ff_alternate_horizontal_scan; /* top */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1785 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1786 } else if (s->mb_intra) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1787 /* DC coef */ |
0 | 1788 if (s->h263_rv10 && s->rv10_version == 3 && s->pict_type == I_TYPE) { |
1789 int component, diff; | |
1790 component = (n <= 3 ? 0 : n - 4 + 1); | |
1791 level = s->last_dc[component]; | |
1792 if (s->rv10_first_dc_coded[component]) { | |
1793 diff = rv_decode_dc(s, n); | |
1794 if (diff == 0xffff) | |
1795 return -1; | |
1796 level += diff; | |
1797 level = level & 0xff; /* handle wrap round */ | |
1798 s->last_dc[component] = level; | |
1799 } else { | |
1800 s->rv10_first_dc_coded[component] = 1; | |
1801 } | |
1802 } else { | |
1803 level = get_bits(&s->gb, 8); | |
1804 if (level == 255) | |
1805 level = 128; | |
1806 } | |
1807 block[0] = level; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1808 i = 1; |
0 | 1809 } else { |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1810 i = 0; |
0 | 1811 } |
1812 if (!coded) { | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1813 if (s->mb_intra && s->h263_aic) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1814 goto not_coded; |
0 | 1815 s->block_last_index[n] = i - 1; |
1816 return 0; | |
1817 } | |
1818 | |
1819 for(;;) { | |
1820 code = get_vlc(&s->gb, &rl->vlc); | |
1821 if (code < 0) | |
1822 return -1; | |
1823 if (code == rl->n) { | |
1824 /* escape */ | |
21 | 1825 last = get_bits1(&s->gb); |
0 | 1826 run = get_bits(&s->gb, 6); |
1827 level = (INT8)get_bits(&s->gb, 8); | |
1828 if (s->h263_rv10 && level == -128) { | |
1829 /* XXX: should patch encoder too */ | |
1830 level = get_bits(&s->gb, 12); | |
1831 level = (level << 20) >> 20; | |
1832 } | |
1833 } else { | |
1834 run = rl->table_run[code]; | |
1835 level = rl->table_level[code]; | |
1836 last = code >= rl->last; | |
21 | 1837 if (get_bits1(&s->gb)) |
0 | 1838 level = -level; |
1839 } | |
1840 i += run; | |
1841 if (i >= 64) | |
1842 return -1; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1843 j = scan_table[i]; |
0 | 1844 block[j] = level; |
1845 if (last) | |
1846 break; | |
1847 i++; | |
1848 } | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1849 not_coded: |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1850 if (s->mb_intra && s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1851 h263_pred_acdc(s, block, n); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1852 i = 63; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1853 } |
0 | 1854 s->block_last_index[n] = i; |
1855 return 0; | |
1856 } | |
1857 | |
1858 static int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) | |
1859 { | |
1860 int level, pred, code; | |
1861 UINT16 *dc_val; | |
1862 | |
1863 if (n < 4) | |
1864 code = get_vlc(&s->gb, &dc_lum); | |
1865 else | |
1866 code = get_vlc(&s->gb, &dc_chrom); | |
1867 if (code < 0) | |
1868 return -1; | |
1869 if (code == 0) { | |
1870 level = 0; | |
1871 } else { | |
1872 level = get_bits(&s->gb, code); | |
1873 if ((level >> (code - 1)) == 0) /* if MSB not set it is negative*/ | |
1874 level = - (level ^ ((1 << code) - 1)); | |
1875 if (code > 8) | |
21 | 1876 skip_bits1(&s->gb); /* marker */ |
0 | 1877 } |
1878 | |
1879 pred = mpeg4_pred_dc(s, n, &dc_val, dir_ptr); | |
1880 level += pred; | |
1881 if (level < 0) | |
1882 level = 0; | |
1883 if (n < 4) { | |
1884 *dc_val = level * s->y_dc_scale; | |
1885 } else { | |
1886 *dc_val = level * s->c_dc_scale; | |
1887 } | |
1888 return level; | |
1889 } | |
1890 | |
1891 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
1892 int n, int coded) | |
1893 { | |
1894 int code, level, i, j, last, run; | |
1895 int dc_pred_dir; | |
1896 RLTable *rl; | |
1897 const UINT8 *scan_table; | |
1898 | |
1899 if (s->mb_intra) { | |
1900 /* DC coef */ | |
1901 level = mpeg4_decode_dc(s, n, &dc_pred_dir); | |
1902 if (level < 0) | |
1903 return -1; | |
1904 block[0] = level; | |
1905 i = 1; | |
1906 if (!coded) | |
1907 goto not_coded; | |
1908 rl = &rl_intra; | |
1909 if (s->ac_pred) { | |
1910 if (dc_pred_dir == 0) | |
1911 scan_table = ff_alternate_vertical_scan; /* left */ | |
1912 else | |
1913 scan_table = ff_alternate_horizontal_scan; /* top */ | |
1914 } else { | |
1915 scan_table = zigzag_direct; | |
1916 } | |
1917 } else { | |
1918 i = 0; | |
1919 if (!coded) { | |
1920 s->block_last_index[n] = i - 1; | |
1921 return 0; | |
1922 } | |
1923 rl = &rl_inter; | |
1924 scan_table = zigzag_direct; | |
1925 } | |
1926 | |
1927 for(;;) { | |
1928 code = get_vlc(&s->gb, &rl->vlc); | |
1929 if (code < 0) | |
1930 return -1; | |
1931 if (code == rl->n) { | |
1932 /* escape */ | |
21 | 1933 if (get_bits1(&s->gb) != 0) { |
1934 if (get_bits1(&s->gb) != 0) { | |
0 | 1935 /* third escape */ |
21 | 1936 last = get_bits1(&s->gb); |
0 | 1937 run = get_bits(&s->gb, 6); |
21 | 1938 get_bits1(&s->gb); /* marker */ |
0 | 1939 level = get_bits(&s->gb, 12); |
1940 level = (level << 20) >> 20; /* sign extend */ | |
21 | 1941 skip_bits1(&s->gb); /* marker */ |
0 | 1942 } else { |
1943 /* second escape */ | |
1944 code = get_vlc(&s->gb, &rl->vlc); | |
1945 if (code < 0 || code >= rl->n) | |
1946 return -1; | |
1947 run = rl->table_run[code]; | |
1948 level = rl->table_level[code]; | |
1949 last = code >= rl->last; | |
1950 run += rl->max_run[last][level] + 1; | |
21 | 1951 if (get_bits1(&s->gb)) |
0 | 1952 level = -level; |
1953 } | |
1954 } else { | |
1955 /* first escape */ | |
1956 code = get_vlc(&s->gb, &rl->vlc); | |
1957 if (code < 0 || code >= rl->n) | |
1958 return -1; | |
1959 run = rl->table_run[code]; | |
1960 level = rl->table_level[code]; | |
1961 last = code >= rl->last; | |
1962 level += rl->max_level[last][run]; | |
21 | 1963 if (get_bits1(&s->gb)) |
0 | 1964 level = -level; |
1965 } | |
1966 } else { | |
1967 run = rl->table_run[code]; | |
1968 level = rl->table_level[code]; | |
1969 last = code >= rl->last; | |
21 | 1970 if (get_bits1(&s->gb)) |
0 | 1971 level = -level; |
1972 } | |
1973 i += run; | |
1974 if (i >= 64) | |
1975 return -1; | |
1976 j = scan_table[i]; | |
1977 block[j] = level; | |
1978 i++; | |
1979 if (last) | |
1980 break; | |
1981 } | |
1982 not_coded: | |
1983 if (s->mb_intra) { | |
1984 mpeg4_pred_ac(s, block, n, dc_pred_dir); | |
1985 if (s->ac_pred) { | |
1986 i = 64; /* XXX: not optimal */ | |
1987 } | |
1988 } | |
1989 s->block_last_index[n] = i - 1; | |
1990 return 0; | |
1991 } | |
1992 | |
1993 /* most is hardcoded. should extend to handle all h263 streams */ | |
1994 int h263_decode_picture_header(MpegEncContext *s) | |
1995 { | |
1996 int format, width, height; | |
1997 | |
1998 /* picture header */ | |
1999 if (get_bits(&s->gb, 22) != 0x20) | |
2000 return -1; | |
231 | 2001 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ |
2002 | |
21 | 2003 if (get_bits1(&s->gb) != 1) |
0 | 2004 return -1; /* marker */ |
21 | 2005 if (get_bits1(&s->gb) != 0) |
0 | 2006 return -1; /* h263 id */ |
21 | 2007 skip_bits1(&s->gb); /* split screen off */ |
2008 skip_bits1(&s->gb); /* camera off */ | |
2009 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 2010 |
155
3c3449bce692
- Bug fix on MV prediction for MPEG4 caused by new H.263 GOB code.
pulento
parents:
154
diff
changeset
|
2011 /* Reset GOB number */ |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
2012 s->gob_number = 0; |
155
3c3449bce692
- Bug fix on MV prediction for MPEG4 caused by new H.263 GOB code.
pulento
parents:
154
diff
changeset
|
2013 |
0 | 2014 format = get_bits(&s->gb, 3); |
2015 | |
161 | 2016 if (format != 7 && format != 6) { |
0 | 2017 s->h263_plus = 0; |
2018 /* H.263v1 */ | |
2019 width = h263_format[format][0]; | |
2020 height = h263_format[format][1]; | |
2021 if (!width) | |
2022 return -1; | |
161 | 2023 |
2024 s->width = width; | |
2025 s->height = height; | |
21 | 2026 s->pict_type = I_TYPE + get_bits1(&s->gb); |
0 | 2027 |
21 | 2028 s->unrestricted_mv = get_bits1(&s->gb); |
0 | 2029 s->h263_long_vectors = s->unrestricted_mv; |
2030 | |
21 | 2031 if (get_bits1(&s->gb) != 0) |
0 | 2032 return -1; /* SAC: off */ |
161 | 2033 if (get_bits1(&s->gb) != 0) { |
2034 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
2035 } | |
2036 | |
21 | 2037 if (get_bits1(&s->gb) != 0) |
0 | 2038 return -1; /* not PB frame */ |
2039 | |
2040 s->qscale = get_bits(&s->gb, 5); | |
21 | 2041 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
0 | 2042 } else { |
161 | 2043 int ufep; |
2044 | |
0 | 2045 /* H.263v2 */ |
161 | 2046 s->h263_plus = 1; |
2047 ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | |
2048 | |
2049 if (ufep == 1) { | |
2050 /* OPPTYPE */ | |
2051 format = get_bits(&s->gb, 3); | |
2052 skip_bits(&s->gb,1); /* Custom PCF */ | |
2053 s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ | |
2054 skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */ | |
2055 if (get_bits1(&s->gb) != 0) { | |
2056 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
2057 } | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2058 if (get_bits1(&s->gb) != 0) { /* Advanced Intra Coding (AIC) */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2059 s->h263_aic = 1; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2060 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2061 skip_bits(&s->gb, 7); |
161 | 2062 skip_bits(&s->gb, 3); /* Reserved */ |
2063 } else if (ufep != 0) | |
0 | 2064 return -1; |
161 | 2065 |
78 | 2066 /* MPPTYPE */ |
0 | 2067 s->pict_type = get_bits(&s->gb, 3) + 1; |
2068 if (s->pict_type != I_TYPE && | |
2069 s->pict_type != P_TYPE) | |
2070 return -1; | |
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2071 skip_bits(&s->gb, 2); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2072 s->no_rounding = get_bits1(&s->gb); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2073 //fprintf(stderr, "\nRTYPE: %d", s->no_rounding); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2074 skip_bits(&s->gb, 4); |
78 | 2075 |
2076 /* Get the picture dimensions */ | |
161 | 2077 if (ufep) { |
2078 if (format == 6) { | |
2079 /* Custom Picture Format (CPFMT) */ | |
2080 skip_bits(&s->gb, 4); /* aspect ratio */ | |
2081 width = (get_bits(&s->gb, 9) + 1) * 4; | |
2082 skip_bits1(&s->gb); | |
2083 height = get_bits(&s->gb, 9) * 4; | |
78 | 2084 #ifdef DEBUG |
161 | 2085 fprintf(stderr,"\nH.263+ Custom picture: %dx%d\n",width,height); |
78 | 2086 #endif |
161 | 2087 } |
2088 else { | |
2089 width = h263_format[format][0]; | |
2090 height = h263_format[format][1]; | |
2091 } | |
2092 if ((width == 0) || (height == 0)) | |
2093 return -1; | |
2094 s->width = width; | |
2095 s->height = height; | |
2096 if (s->umvplus_dec) { | |
2097 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
2098 } | |
78 | 2099 } |
2100 | |
0 | 2101 s->qscale = get_bits(&s->gb, 5); |
2102 } | |
2103 /* PEI */ | |
21 | 2104 while (get_bits1(&s->gb) != 0) { |
2105 skip_bits(&s->gb, 8); | |
0 | 2106 } |
2107 s->f_code = 1; | |
2108 return 0; | |
2109 } | |
2110 | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2111 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2112 { |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2113 int i; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2114 int a= 2<<s->sprite_warping_accuracy; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2115 int rho= 3-s->sprite_warping_accuracy; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2116 int r=16/a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2117 const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2118 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}}; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2119 int sprite_ref[4][2]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2120 int virtual_ref[2][2]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2121 int w2, h2; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2122 int alpha=0, beta=0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2123 int w= s->width; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2124 int h= s->height; |
255 | 2125 //printf("SP %d\n", s->sprite_warping_accuracy); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2126 for(i=0; i<s->num_sprite_warping_points; i++){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2127 int length; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2128 int x=0, y=0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2129 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2130 length= get_vlc(&s->gb, &sprite_trajectory); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2131 if(length){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2132 x= get_bits(&s->gb, length); |
255 | 2133 //printf("lx %d %d\n", length, x); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2134 if ((x >> (length - 1)) == 0) /* if MSB not set it is negative*/ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2135 x = - (x ^ ((1 << length) - 1)); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2136 } |
255 | 2137 if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(&s->gb); /* marker bit */ |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2138 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2139 length= get_vlc(&s->gb, &sprite_trajectory); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2140 if(length){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2141 y=get_bits(&s->gb, length); |
255 | 2142 //printf("ly %d %d\n", length, y); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2143 if ((y >> (length - 1)) == 0) /* if MSB not set it is negative*/ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2144 y = - (y ^ ((1 << length) - 1)); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2145 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2146 skip_bits1(&s->gb); /* marker bit */ |
255 | 2147 //printf("%d %d %d %d\n", x, y, i, s->sprite_warping_accuracy); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2148 //if(i>0 && (x!=0 || y!=0)) printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); |
255 | 2149 //x=y=0; |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2150 d[i][0]= x; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2151 d[i][1]= y; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2152 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2153 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2154 while((1<<alpha)<w) alpha++; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2155 while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h' |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2156 w2= 1<<alpha; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2157 h2= 1<<beta; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2158 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2159 // Note, the 4th point isnt used for GMC |
262 | 2160 if(s->divx_version==500 && s->divx_build==413){ |
2161 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; | |
2162 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; | |
2163 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; | |
2164 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; | |
2165 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; | |
2166 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; | |
2167 } else { | |
2168 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); | |
2169 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); | |
2170 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); | |
2171 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); | |
2172 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); | |
2173 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); | |
2174 } | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2175 /* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2176 sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2177 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2178 // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2179 // perhaps it should be reordered to be more readable ... |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2180 // the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2181 // so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2182 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) |
255 | 2183 + RDIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2184 virtual_ref[0][1]= 16*vop_ref[0][1] |
255 | 2185 + RDIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2186 virtual_ref[1][0]= 16*vop_ref[0][0] |
255 | 2187 + RDIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2188 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) |
255 | 2189 + RDIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2190 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2191 switch(s->num_sprite_warping_points) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2192 { |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2193 case 0: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2194 s->sprite_offset[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2195 s->sprite_offset[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2196 s->sprite_offset[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2197 s->sprite_offset[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2198 s->sprite_delta[0][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2199 s->sprite_delta[0][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2200 s->sprite_delta[0][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2201 s->sprite_delta[0][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2202 s->sprite_delta[1][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2203 s->sprite_delta[1][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2204 s->sprite_delta[1][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2205 s->sprite_delta[1][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2206 s->sprite_shift[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2207 s->sprite_shift[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2208 s->sprite_shift[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2209 s->sprite_shift[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2210 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2211 case 1: //GMC only |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2212 s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2213 s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2214 s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2215 s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2216 s->sprite_delta[0][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2217 s->sprite_delta[0][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2218 s->sprite_delta[0][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2219 s->sprite_delta[0][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2220 s->sprite_delta[1][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2221 s->sprite_delta[1][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2222 s->sprite_delta[1][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2223 s->sprite_delta[1][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2224 s->sprite_shift[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2225 s->sprite_shift[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2226 s->sprite_shift[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2227 s->sprite_shift[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2228 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2229 case 2: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2230 case 3: //FIXME |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2231 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho)) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2232 + ((-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0]) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2233 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2234 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho)) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2235 + ((-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0]) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2236 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2237 s->sprite_offset[1][0]= ((-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2238 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2239 +2*w2*r*sprite_ref[0][0] - 16*w2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2240 s->sprite_offset[1][1]= ((-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2241 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2242 +2*w2*r*sprite_ref[0][1] - 16*w2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2243 s->sprite_delta[0][0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2244 s->sprite_delta[0][0][1]= ( r*sprite_ref[0][1] - virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2245 s->sprite_delta[0][1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2246 s->sprite_delta[0][1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2247 s->sprite_delta[1][0][0]= 4*(-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2248 s->sprite_delta[1][0][1]= 4*( r*sprite_ref[0][1] - virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2249 s->sprite_delta[1][1][0]= 4*(-r*sprite_ref[0][1] + virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2250 s->sprite_delta[1][1][1]= 4*(-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2251 s->sprite_shift[0][0]= alpha+rho; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2252 s->sprite_shift[0][1]= alpha+rho; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2253 s->sprite_shift[1][0]= alpha+rho+2; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2254 s->sprite_shift[1][1]= alpha+rho+2; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2255 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2256 // case 3: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2257 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2258 } |
255 | 2259 /*printf("%d %d\n", s->sprite_delta[0][0][0], a<<s->sprite_shift[0][0]); |
2260 printf("%d %d\n", s->sprite_delta[0][0][1], 0); | |
2261 printf("%d %d\n", s->sprite_delta[0][1][0], 0); | |
2262 printf("%d %d\n", s->sprite_delta[0][1][1], a<<s->sprite_shift[0][1]); | |
2263 printf("%d %d\n", s->sprite_delta[1][0][0], a<<s->sprite_shift[1][0]); | |
2264 printf("%d %d\n", s->sprite_delta[1][0][1], 0); | |
2265 printf("%d %d\n", s->sprite_delta[1][1][0], 0); | |
2266 printf("%d %d\n", s->sprite_delta[1][1][1], a<<s->sprite_shift[1][1]);*/ | |
2267 /* try to simplify the situation */ | |
2268 if( s->sprite_delta[0][0][0] == a<<s->sprite_shift[0][0] | |
2269 && s->sprite_delta[0][0][1] == 0 | |
2270 && s->sprite_delta[0][1][0] == 0 | |
2271 && s->sprite_delta[0][1][1] == a<<s->sprite_shift[0][1] | |
2272 && s->sprite_delta[1][0][0] == a<<s->sprite_shift[1][0] | |
2273 && s->sprite_delta[1][0][1] == 0 | |
2274 && s->sprite_delta[1][1][0] == 0 | |
2275 && s->sprite_delta[1][1][1] == a<<s->sprite_shift[1][1]) | |
2276 { | |
2277 s->sprite_offset[0][0]>>=s->sprite_shift[0][0]; | |
2278 s->sprite_offset[0][1]>>=s->sprite_shift[0][1]; | |
2279 s->sprite_offset[1][0]>>=s->sprite_shift[1][0]; | |
2280 s->sprite_offset[1][1]>>=s->sprite_shift[1][1]; | |
2281 s->sprite_delta[0][0][0]= a; | |
2282 s->sprite_delta[0][0][1]= 0; | |
2283 s->sprite_delta[0][1][0]= 0; | |
2284 s->sprite_delta[0][1][1]= a; | |
2285 s->sprite_delta[1][0][0]= a; | |
2286 s->sprite_delta[1][0][1]= 0; | |
2287 s->sprite_delta[1][1][0]= 0; | |
2288 s->sprite_delta[1][1][1]= a; | |
2289 s->sprite_shift[0][0]= 0; | |
2290 s->sprite_shift[0][1]= 0; | |
2291 s->sprite_shift[1][0]= 0; | |
2292 s->sprite_shift[1][1]= 0; | |
2293 s->real_sprite_warping_points=1; | |
2294 } | |
2295 else | |
2296 s->real_sprite_warping_points= s->num_sprite_warping_points; | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2297 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2298 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2299 |
0 | 2300 /* decode mpeg4 VOP header */ |
2301 int mpeg4_decode_picture_header(MpegEncContext * s) | |
2302 { | |
2303 int time_incr, startcode, state, v; | |
2304 | |
2305 redo: | |
2306 /* search next start code */ | |
2307 align_get_bits(&s->gb); | |
2308 state = 0xff; | |
2309 for(;;) { | |
2310 v = get_bits(&s->gb, 8); | |
2311 if (state == 0x000001) { | |
2312 state = ((state << 8) | v) & 0xffffff; | |
2313 startcode = state; | |
2314 break; | |
2315 } | |
2316 state = ((state << 8) | v) & 0xffffff; | |
278 | 2317 if( get_bits_count(&s->gb) > s->gb.size*8-32){ |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2318 printf("no VOP startcode found\n"); |
0 | 2319 return -1; |
263 | 2320 } |
0 | 2321 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2322 //printf("startcode %X %d\n", startcode, get_bits_count(&s->gb)); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2323 if (startcode == 0x120) { // Video Object Layer |
262 | 2324 int width, height, vo_ver_id; |
0 | 2325 |
2326 /* vol header */ | |
21 | 2327 skip_bits(&s->gb, 1); /* random access */ |
2328 skip_bits(&s->gb, 8); /* vo_type */ | |
63 | 2329 if (get_bits1(&s->gb) != 0) { /* is_ol_id */ |
2330 vo_ver_id = get_bits(&s->gb, 4); /* vo_ver_id */ | |
2331 skip_bits(&s->gb, 3); /* vo_priority */ | |
2332 } else { | |
2333 vo_ver_id = 1; | |
2334 } | |
0 | 2335 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2336 s->aspect_ratio_info= get_bits(&s->gb, 4); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2337 if(s->aspect_ratio_info == EXTENDET_PAR){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2338 skip_bits(&s->gb, 8); //par_width |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2339 skip_bits(&s->gb, 8); // par_height |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2340 } |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
2341 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2342 if(get_bits1(&s->gb)){ /* vol control parameter */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2343 printf("vol control parameter not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2344 return -1; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2345 } |
63 | 2346 s->shape = get_bits(&s->gb, 2); /* vol shape */ |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2347 if(s->shape != RECT_SHAPE) printf("only rectangular vol supported\n"); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2348 if(s->shape == GRAY_SHAPE && vo_ver_id != 1){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2349 printf("Gray shape not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2350 skip_bits(&s->gb, 4); //video_object_layer_shape_extension |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2351 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2352 |
21 | 2353 skip_bits1(&s->gb); /* marker */ |
0 | 2354 |
262 | 2355 s->time_increment_resolution = get_bits(&s->gb, 16); |
2356 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
63 | 2357 if (s->time_increment_bits < 1) |
2358 s->time_increment_bits = 1; | |
21 | 2359 skip_bits1(&s->gb); /* marker */ |
0 | 2360 |
63 | 2361 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */ |
2362 skip_bits(&s->gb, s->time_increment_bits); | |
2363 } | |
0 | 2364 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2365 if (s->shape != BIN_ONLY_SHAPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2366 if (s->shape == RECT_SHAPE) { |
63 | 2367 skip_bits1(&s->gb); /* marker */ |
2368 width = get_bits(&s->gb, 13); | |
2369 skip_bits1(&s->gb); /* marker */ | |
2370 height = get_bits(&s->gb, 13); | |
2371 skip_bits1(&s->gb); /* marker */ | |
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2372 if(width && height){ /* they should be non zero but who knows ... */ |
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2373 s->width = width; |
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2374 s->height = height; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2375 // printf("%d %d\n", width, height); |
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2376 } |
63 | 2377 } |
2378 | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2379 if(get_bits1(&s->gb)) printf("interlaced not supported\n"); /* interlaced */ |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2380 if(!get_bits1(&s->gb)) printf("OBMC not supported\n"); /* OBMC Disable */ |
63 | 2381 if (vo_ver_id == 1) { |
2382 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */ | |
2383 } else { | |
2384 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */ | |
2385 } | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2386 if(s->vol_sprite_usage==STATIC_SPRITE) printf("Static Sprites not supported\n"); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2387 if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2388 if(s->vol_sprite_usage==STATIC_SPRITE){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2389 s->sprite_width = get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2390 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2391 s->sprite_height= get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2392 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2393 s->sprite_left = get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2394 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2395 s->sprite_top = get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2396 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2397 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2398 s->num_sprite_warping_points= get_bits(&s->gb, 6); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2399 s->sprite_warping_accuracy = get_bits(&s->gb, 2); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2400 s->sprite_brightness_change= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2401 if(s->vol_sprite_usage==STATIC_SPRITE) |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2402 s->low_latency_sprite= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2403 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2404 // FIXME sadct disable bit if verid!=1 && shape not rect |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2405 |
63 | 2406 if (get_bits1(&s->gb) == 1) { /* not_8_bit */ |
2407 s->quant_precision = get_bits(&s->gb, 4); /* quant_precision */ | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2408 if(get_bits(&s->gb, 4)!=8) printf("N-bit not supported\n"); /* bits_per_pixel */ |
290 | 2409 if(s->quant_precision!=5) printf("quant precission %d\n", s->quant_precision); |
63 | 2410 } else { |
2411 s->quant_precision = 5; | |
2412 } | |
2413 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2414 // FIXME a bunch of grayscale shape things |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2415 if(get_bits1(&s->gb)) printf("Quant-Type not supported\n"); /* vol_quant_type */ //FIXME |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2416 if(vo_ver_id != 1) |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2417 s->quarter_sample= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2418 else s->quarter_sample=0; |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2419 |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2420 if(!get_bits1(&s->gb)) printf("Complexity estimation not supported\n"); |
290 | 2421 |
2422 s->resync_marker= !get_bits1(&s->gb); /* resync_marker_disabled */ | |
2423 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2424 s->data_partioning= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2425 if(s->data_partioning){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2426 printf("data partitioning not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2427 skip_bits1(&s->gb); // reversible vlc |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2428 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2429 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2430 if(vo_ver_id != 1) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2431 s->new_pred= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2432 if(s->new_pred){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2433 printf("new pred not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2434 skip_bits(&s->gb, 2); /* requested upstream message type */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2435 skip_bits1(&s->gb); /* newpred segment type */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2436 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2437 s->reduced_res_vop= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2438 if(s->reduced_res_vop) printf("reduced resolution VOP not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2439 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2440 else{ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2441 s->new_pred=0; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2442 s->reduced_res_vop= 0; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2443 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2444 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2445 s->scalability= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2446 if (s->scalability) { |
285 | 2447 printf("scalability not supported\n"); |
63 | 2448 } |
2449 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2450 //printf("end Data %X %d\n", show_bits(&s->gb, 32), get_bits_count(&s->gb)&0x7); |
0 | 2451 goto redo; |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2452 } else if (startcode == 0x1b2) { //userdata |
255 | 2453 char buf[256]; |
2454 int i; | |
2455 int e; | |
2456 int ver, build; | |
2457 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2458 //printf("user Data %X\n", show_bits(&s->gb, 32)); |
255 | 2459 buf[0]= show_bits(&s->gb, 8); |
2460 for(i=1; i<256; i++){ | |
2461 buf[i]= show_bits(&s->gb, 16)&0xFF; | |
2462 if(buf[i]==0) break; | |
2463 skip_bits(&s->gb, 8); | |
2464 } | |
2465 buf[255]=0; | |
2466 e=sscanf(buf, "DivX%dBuild%d", &ver, &build); | |
2467 if(e==2){ | |
2468 s->divx_version= ver; | |
2469 s->divx_build= build; | |
2470 if(s->picture_number==0){ | |
2471 printf("This file was encoded with DivX%d Build%d\n", ver, build); | |
2472 if(ver==500 && build==413){ //most likely all version are indeed totally buggy but i dunno for sure ... | |
2473 printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n"); | |
2474 }else{ | |
2475 printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n" | |
2476 "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n"); | |
2477 } | |
2478 } | |
2479 } | |
2480 //printf("User Data: %s\n", buf); | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2481 goto redo; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2482 } else if (startcode != 0x1b6) { //VOP |
0 | 2483 goto redo; |
2484 } | |
2485 | |
2486 s->pict_type = get_bits(&s->gb, 2) + 1; /* pict type: I = 0 , P = 1 */ | |
291 | 2487 //printf("pic: %d, qpel:%d\n", s->pict_type, s->quarter_sample); |
262 | 2488 time_incr=0; |
21 | 2489 while (get_bits1(&s->gb) != 0) |
0 | 2490 time_incr++; |
2491 | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2492 check_marker(&s->gb, "before time_increment"); |
262 | 2493 s->time_increment= get_bits(&s->gb, s->time_increment_bits); |
2494 if(s->pict_type!=B_TYPE){ | |
2495 s->time_base+= time_incr; | |
2496 s->last_non_b_time[1]= s->last_non_b_time[0]; | |
2497 s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment; | |
2498 }else{ | |
2499 s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution; | |
2500 s->time+= s->time_increment; | |
2501 } | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2502 |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2503 if(check_marker(&s->gb, "before vop_coded")==0 && s->picture_number==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2504 printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n"); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2505 for(s->time_increment_bits++ ;s->time_increment_bits<16; s->time_increment_bits++){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2506 if(get_bits1(&s->gb)) break; |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2507 } |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2508 printf("my guess is %d bits ;)\n",s->time_increment_bits); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2509 } |
0 | 2510 /* vop coded */ |
21 | 2511 if (get_bits1(&s->gb) != 1) |
63 | 2512 goto redo; |
262 | 2513 //printf("time %d %d %d || %d %d %d\n", s->time_increment_bits, s->time_increment, s->time_base, |
2514 //s->time, s->last_non_b_time[0], s->last_non_b_time[1]); | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2515 if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2516 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { |
0 | 2517 /* rounding type for motion estimation */ |
21 | 2518 s->no_rounding = get_bits1(&s->gb); |
63 | 2519 } else { |
2520 s->no_rounding = 0; | |
0 | 2521 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2522 //FIXME reduced res stuff |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2523 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2524 if (s->shape != RECT_SHAPE) { |
63 | 2525 if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) { |
2526 int width, height, hor_spat_ref, ver_spat_ref; | |
2527 | |
2528 width = get_bits(&s->gb, 13); | |
2529 skip_bits1(&s->gb); /* marker */ | |
2530 height = get_bits(&s->gb, 13); | |
2531 skip_bits1(&s->gb); /* marker */ | |
2532 hor_spat_ref = get_bits(&s->gb, 13); /* hor_spat_ref */ | |
2533 skip_bits1(&s->gb); /* marker */ | |
2534 ver_spat_ref = get_bits(&s->gb, 13); /* ver_spat_ref */ | |
2535 } | |
2536 skip_bits1(&s->gb); /* change_CR_disable */ | |
2537 | |
2538 if (get_bits1(&s->gb) != 0) { | |
2539 skip_bits(&s->gb, 8); /* constant_alpha_value */ | |
2540 } | |
2541 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2542 //FIXME complexity estimation stuff |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2543 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2544 if (s->shape != BIN_ONLY_SHAPE) { |
290 | 2545 int t; |
2546 t=get_bits(&s->gb, 3); /* intra dc VLC threshold */ | |
2547 //printf("threshold %d\n", t); | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2548 //FIXME interlaced specific bits |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2549 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2550 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2551 if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2552 if(s->num_sprite_warping_points){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2553 mpeg4_decode_sprite_trajectory(s); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2554 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2555 if(s->sprite_brightness_change) printf("sprite_brightness_change not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2556 if(s->vol_sprite_usage==STATIC_SPRITE) printf("static sprite not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2557 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2558 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2559 if (s->shape != BIN_ONLY_SHAPE) { |
63 | 2560 /* note: we do not use quant_precision to avoid problem if no |
2561 MPEG4 vol header as it is found on some old opendivx | |
2562 movies */ | |
2563 s->qscale = get_bits(&s->gb, 5); | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2564 if(s->qscale==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2565 printf("Error, header damaged or not MPEG4 header (qscale=0)\n"); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2566 return -1; // makes no sense to continue, as there is nothing left from the image then |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2567 } |
63 | 2568 |
2569 if (s->pict_type != I_TYPE) { | |
2570 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2571 if(s->f_code==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2572 printf("Error, header damaged or not MPEG4 header (f_code=0)\n"); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2573 return -1; // makes no sense to continue, as the MV decoding will break very quickly |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2574 } |
63 | 2575 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2576 if (s->pict_type == B_TYPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2577 s->b_code = get_bits(&s->gb, 3); |
262 | 2578 //printf("b-code %d\n", s->b_code); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2579 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2580 //printf("quant:%d fcode:%d\n", s->qscale, s->f_code); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2581 if(!s->scalability){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2582 if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2583 skip_bits1(&s->gb); // vop shape coding type |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2584 } |
63 | 2585 } |
2586 } | |
255 | 2587 s->picture_number++; // better than pic number==0 allways ;) |
63 | 2588 return 0; |
0 | 2589 } |
2590 | |
2591 /* don't understand why they choose a different header ! */ | |
2592 int intel_h263_decode_picture_header(MpegEncContext *s) | |
2593 { | |
2594 int format; | |
2595 | |
2596 /* picture header */ | |
2597 if (get_bits(&s->gb, 22) != 0x20) | |
2598 return -1; | |
21 | 2599 skip_bits(&s->gb, 8); /* picture timestamp */ |
0 | 2600 |
21 | 2601 if (get_bits1(&s->gb) != 1) |
0 | 2602 return -1; /* marker */ |
21 | 2603 if (get_bits1(&s->gb) != 0) |
0 | 2604 return -1; /* h263 id */ |
21 | 2605 skip_bits1(&s->gb); /* split screen off */ |
2606 skip_bits1(&s->gb); /* camera off */ | |
2607 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 2608 |
2609 format = get_bits(&s->gb, 3); | |
2610 if (format != 7) | |
2611 return -1; | |
2612 | |
2613 s->h263_plus = 0; | |
2614 | |
21 | 2615 s->pict_type = I_TYPE + get_bits1(&s->gb); |
0 | 2616 |
21 | 2617 s->unrestricted_mv = get_bits1(&s->gb); |
0 | 2618 s->h263_long_vectors = s->unrestricted_mv; |
2619 | |
21 | 2620 if (get_bits1(&s->gb) != 0) |
0 | 2621 return -1; /* SAC: off */ |
21 | 2622 if (get_bits1(&s->gb) != 0) |
0 | 2623 return -1; /* advanced prediction mode: off */ |
21 | 2624 if (get_bits1(&s->gb) != 0) |
0 | 2625 return -1; /* not PB frame */ |
2626 | |
2627 /* skip unknown header garbage */ | |
21 | 2628 skip_bits(&s->gb, 41); |
0 | 2629 |
2630 s->qscale = get_bits(&s->gb, 5); | |
21 | 2631 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
0 | 2632 |
2633 /* PEI */ | |
21 | 2634 while (get_bits1(&s->gb) != 0) { |
2635 skip_bits(&s->gb, 8); | |
0 | 2636 } |
2637 s->f_code = 1; | |
2638 return 0; | |
2639 } | |
144 | 2640 |