Mercurial > libavcodec.hg
annotate h263.c @ 290:2899263586cd libavcodec
resync marker support, needed for some mp4 files
author | michaelni |
---|---|
date | Sun, 24 Mar 2002 21:25:04 +0000 |
parents | 32a3dcce2e9b |
children | ab46ebfd419f |
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 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
56 static UINT16 mv_penalty[MAX_FCODE][MAX_MV*2+1]; |
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; | |
1578 s->last_mv[0][0][0]= | |
1579 s->last_mv[0][0][1]= | |
1580 s->last_mv[1][0][0]= | |
1581 s->last_mv[1][0][1]= 0; | |
1582 s->mb_skiped = 1; | |
1583 return 0; | |
1584 } | |
1585 | |
1586 modb1= get_bits1(&s->gb); | |
1587 if(modb1==0){ | |
1588 modb2= get_bits1(&s->gb); | |
1589 mb_type= get_vlc(&s->gb, &mb_type_b_vlc); | |
1590 if(modb2==0) cbp= get_bits(&s->gb, 6); | |
1591 else cbp=0; | |
1592 if (mb_type && cbp) { | |
1593 if(get_bits1(&s->gb)){ | |
1594 s->qscale +=get_bits1(&s->gb)*4 - 2; | |
1595 if (s->qscale < 1) | |
1596 s->qscale = 1; | |
1597 else if (s->qscale > 31) | |
1598 s->qscale = 31; | |
290 | 1599 h263_dc_scale(s); |
262 | 1600 } |
1601 } | |
1602 }else{ | |
1603 mb_type=4; //like 0 but no vectors coded | |
1604 cbp=0; | |
1605 } | |
1606 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 | |
1607 mx=my=0; //for case 4, we could put this to the mb_type=4 but than gcc compains about uninitalized mx/my | |
1608 switch(mb_type) | |
1609 { | |
1610 case 0: | |
1611 mx = h263_decode_motion(s, 0, 1); | |
1612 my = h263_decode_motion(s, 0, 1); | |
1613 case 4: | |
1614 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
266 | 1615 xy= s->block_index[0]; |
262 | 1616 time_pp= s->last_non_b_time[0] - s->last_non_b_time[1]; |
1617 time_pb= s->time - s->last_non_b_time[1]; | |
1618 //if(time_pp>3000 )printf("%d %d ", time_pp, time_pb); | |
1619 //FIXME 4MV | |
1620 //FIXME avoid divides | |
1621 s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; | |
1622 s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp + my; | |
1623 s->mv[1][0][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] | |
1624 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx; | |
1625 s->mv[1][0][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] | |
1626 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my; | |
1627 /* s->mv[0][0][0] = | |
1628 s->mv[0][0][1] = | |
1629 s->mv[1][0][0] = | |
1630 s->mv[1][0][1] = 1000;*/ | |
1631 break; | |
1632 case 1: | |
1633 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
1634 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
1635 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
1636 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
1637 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
1638 | |
1639 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
1640 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
1641 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
1642 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
1643 break; | |
1644 case 2: | |
1645 s->mv_dir = MV_DIR_BACKWARD; | |
1646 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
1647 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
1648 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
1649 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
1650 break; | |
1651 case 3: | |
1652 s->mv_dir = MV_DIR_FORWARD; | |
1653 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
1654 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
1655 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
1656 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
1657 break; | |
1658 default: return -1; | |
1659 } | |
1660 } else { /* I-Frame */ | |
1661 cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); | |
1662 if (cbpc < 0) | |
1663 return -1; | |
1664 dquant = cbpc & 4; | |
1665 s->mb_intra = 1; | |
1666 intra: | |
0 | 1667 s->ac_pred = 0; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1668 if (s->h263_pred || s->h263_aic) { |
21 | 1669 s->ac_pred = get_bits1(&s->gb); |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1670 if (s->ac_pred && s->h263_aic) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1671 s->h263_aic_dir = get_bits1(&s->gb); |
0 | 1672 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1673 if (s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1674 s->y_dc_scale = 2 * s->qscale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1675 s->c_dc_scale = 2 * s->qscale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1676 } |
0 | 1677 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
1678 cbp = (cbpc & 3) | (cbpy << 2); | |
1679 if (dquant) { | |
1680 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
1681 if (s->qscale < 1) | |
1682 s->qscale = 1; | |
1683 else if (s->qscale > 31) | |
1684 s->qscale = 31; | |
290 | 1685 h263_dc_scale(s); |
0 | 1686 } |
1687 } | |
1688 | |
1689 /* decode each block */ | |
1690 if (s->h263_pred) { | |
1691 for (i = 0; i < 6; i++) { | |
1692 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
1693 return -1; | |
1694 } | |
1695 } else { | |
1696 for (i = 0; i < 6; i++) { | |
1697 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
1698 return -1; | |
1699 } | |
1700 } | |
1701 return 0; | |
1702 } | |
1703 | |
262 | 1704 static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) |
0 | 1705 { |
1706 int code, val, sign, shift, l, m; | |
1707 | |
1708 code = get_vlc(&s->gb, &mv_vlc); | |
1709 if (code < 0) | |
1710 return 0xffff; | |
1711 | |
1712 if (code == 0) | |
1713 return pred; | |
21 | 1714 sign = get_bits1(&s->gb); |
262 | 1715 shift = f_code - 1; |
0 | 1716 val = (code - 1) << shift; |
1717 if (shift > 0) | |
1718 val |= get_bits(&s->gb, shift); | |
1719 val++; | |
1720 if (sign) | |
1721 val = -val; | |
1722 val += pred; | |
1723 | |
1724 /* modulo decoding */ | |
1725 if (!s->h263_long_vectors) { | |
262 | 1726 l = (1 << (f_code - 1)) * 32; |
0 | 1727 m = 2 * l; |
1728 if (val < -l) { | |
1729 val += m; | |
1730 } else if (val >= l) { | |
1731 val -= m; | |
1732 } | |
1733 } else { | |
1734 /* horrible h263 long vector mode */ | |
1735 if (pred < -31 && val < -63) | |
1736 val += 64; | |
1737 if (pred > 32 && val > 63) | |
1738 val -= 64; | |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1739 |
0 | 1740 } |
1741 return val; | |
1742 } | |
1743 | |
78 | 1744 /* Decodes RVLC of H.263+ UMV */ |
1745 static int h263p_decode_umotion(MpegEncContext * s, int pred) | |
1746 { | |
1747 int code = 0, sign; | |
1748 | |
1749 if (get_bits1(&s->gb)) /* Motion difference = 0 */ | |
1750 return pred; | |
1751 | |
1752 code = 2 + get_bits1(&s->gb); | |
1753 | |
1754 while (get_bits1(&s->gb)) | |
1755 { | |
1756 code <<= 1; | |
1757 code += get_bits1(&s->gb); | |
1758 } | |
1759 sign = code & 1; | |
1760 code >>= 1; | |
1761 | |
1762 code = (sign) ? (pred - code) : (pred + code); | |
1763 #ifdef DEBUG | |
1764 fprintf(stderr,"H.263+ UMV Motion = %d\n", code); | |
1765 #endif | |
1766 return code; | |
1767 | |
1768 } | |
1769 | |
0 | 1770 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
1771 int n, int coded) | |
1772 { | |
1773 int code, level, i, j, last, run; | |
1774 RLTable *rl = &rl_inter; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1775 const UINT8 *scan_table; |
0 | 1776 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1777 scan_table = zigzag_direct; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1778 if (s->h263_aic && s->mb_intra) { |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1779 rl = &rl_intra_aic; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1780 i = 0; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1781 if (s->ac_pred) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1782 if (s->h263_aic_dir) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1783 scan_table = ff_alternate_vertical_scan; /* left */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1784 else |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1785 scan_table = ff_alternate_horizontal_scan; /* top */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1786 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1787 } else if (s->mb_intra) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1788 /* DC coef */ |
0 | 1789 if (s->h263_rv10 && s->rv10_version == 3 && s->pict_type == I_TYPE) { |
1790 int component, diff; | |
1791 component = (n <= 3 ? 0 : n - 4 + 1); | |
1792 level = s->last_dc[component]; | |
1793 if (s->rv10_first_dc_coded[component]) { | |
1794 diff = rv_decode_dc(s, n); | |
1795 if (diff == 0xffff) | |
1796 return -1; | |
1797 level += diff; | |
1798 level = level & 0xff; /* handle wrap round */ | |
1799 s->last_dc[component] = level; | |
1800 } else { | |
1801 s->rv10_first_dc_coded[component] = 1; | |
1802 } | |
1803 } else { | |
1804 level = get_bits(&s->gb, 8); | |
1805 if (level == 255) | |
1806 level = 128; | |
1807 } | |
1808 block[0] = level; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1809 i = 1; |
0 | 1810 } else { |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1811 i = 0; |
0 | 1812 } |
1813 if (!coded) { | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1814 if (s->mb_intra && s->h263_aic) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1815 goto not_coded; |
0 | 1816 s->block_last_index[n] = i - 1; |
1817 return 0; | |
1818 } | |
1819 | |
1820 for(;;) { | |
1821 code = get_vlc(&s->gb, &rl->vlc); | |
1822 if (code < 0) | |
1823 return -1; | |
1824 if (code == rl->n) { | |
1825 /* escape */ | |
21 | 1826 last = get_bits1(&s->gb); |
0 | 1827 run = get_bits(&s->gb, 6); |
1828 level = (INT8)get_bits(&s->gb, 8); | |
1829 if (s->h263_rv10 && level == -128) { | |
1830 /* XXX: should patch encoder too */ | |
1831 level = get_bits(&s->gb, 12); | |
1832 level = (level << 20) >> 20; | |
1833 } | |
1834 } else { | |
1835 run = rl->table_run[code]; | |
1836 level = rl->table_level[code]; | |
1837 last = code >= rl->last; | |
21 | 1838 if (get_bits1(&s->gb)) |
0 | 1839 level = -level; |
1840 } | |
1841 i += run; | |
1842 if (i >= 64) | |
1843 return -1; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1844 j = scan_table[i]; |
0 | 1845 block[j] = level; |
1846 if (last) | |
1847 break; | |
1848 i++; | |
1849 } | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1850 not_coded: |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1851 if (s->mb_intra && s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1852 h263_pred_acdc(s, block, n); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1853 i = 63; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1854 } |
0 | 1855 s->block_last_index[n] = i; |
1856 return 0; | |
1857 } | |
1858 | |
1859 static int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) | |
1860 { | |
1861 int level, pred, code; | |
1862 UINT16 *dc_val; | |
1863 | |
1864 if (n < 4) | |
1865 code = get_vlc(&s->gb, &dc_lum); | |
1866 else | |
1867 code = get_vlc(&s->gb, &dc_chrom); | |
1868 if (code < 0) | |
1869 return -1; | |
1870 if (code == 0) { | |
1871 level = 0; | |
1872 } else { | |
1873 level = get_bits(&s->gb, code); | |
1874 if ((level >> (code - 1)) == 0) /* if MSB not set it is negative*/ | |
1875 level = - (level ^ ((1 << code) - 1)); | |
1876 if (code > 8) | |
21 | 1877 skip_bits1(&s->gb); /* marker */ |
0 | 1878 } |
1879 | |
1880 pred = mpeg4_pred_dc(s, n, &dc_val, dir_ptr); | |
1881 level += pred; | |
1882 if (level < 0) | |
1883 level = 0; | |
1884 if (n < 4) { | |
1885 *dc_val = level * s->y_dc_scale; | |
1886 } else { | |
1887 *dc_val = level * s->c_dc_scale; | |
1888 } | |
1889 return level; | |
1890 } | |
1891 | |
1892 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
1893 int n, int coded) | |
1894 { | |
1895 int code, level, i, j, last, run; | |
1896 int dc_pred_dir; | |
1897 RLTable *rl; | |
1898 const UINT8 *scan_table; | |
1899 | |
1900 if (s->mb_intra) { | |
1901 /* DC coef */ | |
1902 level = mpeg4_decode_dc(s, n, &dc_pred_dir); | |
1903 if (level < 0) | |
1904 return -1; | |
1905 block[0] = level; | |
1906 i = 1; | |
1907 if (!coded) | |
1908 goto not_coded; | |
1909 rl = &rl_intra; | |
1910 if (s->ac_pred) { | |
1911 if (dc_pred_dir == 0) | |
1912 scan_table = ff_alternate_vertical_scan; /* left */ | |
1913 else | |
1914 scan_table = ff_alternate_horizontal_scan; /* top */ | |
1915 } else { | |
1916 scan_table = zigzag_direct; | |
1917 } | |
1918 } else { | |
1919 i = 0; | |
1920 if (!coded) { | |
1921 s->block_last_index[n] = i - 1; | |
1922 return 0; | |
1923 } | |
1924 rl = &rl_inter; | |
1925 scan_table = zigzag_direct; | |
1926 } | |
1927 | |
1928 for(;;) { | |
1929 code = get_vlc(&s->gb, &rl->vlc); | |
1930 if (code < 0) | |
1931 return -1; | |
1932 if (code == rl->n) { | |
1933 /* escape */ | |
21 | 1934 if (get_bits1(&s->gb) != 0) { |
1935 if (get_bits1(&s->gb) != 0) { | |
0 | 1936 /* third escape */ |
21 | 1937 last = get_bits1(&s->gb); |
0 | 1938 run = get_bits(&s->gb, 6); |
21 | 1939 get_bits1(&s->gb); /* marker */ |
0 | 1940 level = get_bits(&s->gb, 12); |
1941 level = (level << 20) >> 20; /* sign extend */ | |
21 | 1942 skip_bits1(&s->gb); /* marker */ |
0 | 1943 } else { |
1944 /* second escape */ | |
1945 code = get_vlc(&s->gb, &rl->vlc); | |
1946 if (code < 0 || code >= rl->n) | |
1947 return -1; | |
1948 run = rl->table_run[code]; | |
1949 level = rl->table_level[code]; | |
1950 last = code >= rl->last; | |
1951 run += rl->max_run[last][level] + 1; | |
21 | 1952 if (get_bits1(&s->gb)) |
0 | 1953 level = -level; |
1954 } | |
1955 } else { | |
1956 /* first escape */ | |
1957 code = get_vlc(&s->gb, &rl->vlc); | |
1958 if (code < 0 || code >= rl->n) | |
1959 return -1; | |
1960 run = rl->table_run[code]; | |
1961 level = rl->table_level[code]; | |
1962 last = code >= rl->last; | |
1963 level += rl->max_level[last][run]; | |
21 | 1964 if (get_bits1(&s->gb)) |
0 | 1965 level = -level; |
1966 } | |
1967 } else { | |
1968 run = rl->table_run[code]; | |
1969 level = rl->table_level[code]; | |
1970 last = code >= rl->last; | |
21 | 1971 if (get_bits1(&s->gb)) |
0 | 1972 level = -level; |
1973 } | |
1974 i += run; | |
1975 if (i >= 64) | |
1976 return -1; | |
1977 j = scan_table[i]; | |
1978 block[j] = level; | |
1979 i++; | |
1980 if (last) | |
1981 break; | |
1982 } | |
1983 not_coded: | |
1984 if (s->mb_intra) { | |
1985 mpeg4_pred_ac(s, block, n, dc_pred_dir); | |
1986 if (s->ac_pred) { | |
1987 i = 64; /* XXX: not optimal */ | |
1988 } | |
1989 } | |
1990 s->block_last_index[n] = i - 1; | |
1991 return 0; | |
1992 } | |
1993 | |
1994 /* most is hardcoded. should extend to handle all h263 streams */ | |
1995 int h263_decode_picture_header(MpegEncContext *s) | |
1996 { | |
1997 int format, width, height; | |
1998 | |
1999 /* picture header */ | |
2000 if (get_bits(&s->gb, 22) != 0x20) | |
2001 return -1; | |
231 | 2002 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ |
2003 | |
21 | 2004 if (get_bits1(&s->gb) != 1) |
0 | 2005 return -1; /* marker */ |
21 | 2006 if (get_bits1(&s->gb) != 0) |
0 | 2007 return -1; /* h263 id */ |
21 | 2008 skip_bits1(&s->gb); /* split screen off */ |
2009 skip_bits1(&s->gb); /* camera off */ | |
2010 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 2011 |
155
3c3449bce692
- Bug fix on MV prediction for MPEG4 caused by new H.263 GOB code.
pulento
parents:
154
diff
changeset
|
2012 /* Reset GOB number */ |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
2013 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
|
2014 |
0 | 2015 format = get_bits(&s->gb, 3); |
2016 | |
161 | 2017 if (format != 7 && format != 6) { |
0 | 2018 s->h263_plus = 0; |
2019 /* H.263v1 */ | |
2020 width = h263_format[format][0]; | |
2021 height = h263_format[format][1]; | |
2022 if (!width) | |
2023 return -1; | |
161 | 2024 |
2025 s->width = width; | |
2026 s->height = height; | |
21 | 2027 s->pict_type = I_TYPE + get_bits1(&s->gb); |
0 | 2028 |
21 | 2029 s->unrestricted_mv = get_bits1(&s->gb); |
0 | 2030 s->h263_long_vectors = s->unrestricted_mv; |
2031 | |
21 | 2032 if (get_bits1(&s->gb) != 0) |
0 | 2033 return -1; /* SAC: off */ |
161 | 2034 if (get_bits1(&s->gb) != 0) { |
2035 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
2036 } | |
2037 | |
21 | 2038 if (get_bits1(&s->gb) != 0) |
0 | 2039 return -1; /* not PB frame */ |
2040 | |
2041 s->qscale = get_bits(&s->gb, 5); | |
21 | 2042 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
0 | 2043 } else { |
161 | 2044 int ufep; |
2045 | |
0 | 2046 /* H.263v2 */ |
161 | 2047 s->h263_plus = 1; |
2048 ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | |
2049 | |
2050 if (ufep == 1) { | |
2051 /* OPPTYPE */ | |
2052 format = get_bits(&s->gb, 3); | |
2053 skip_bits(&s->gb,1); /* Custom PCF */ | |
2054 s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ | |
2055 skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */ | |
2056 if (get_bits1(&s->gb) != 0) { | |
2057 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
2058 } | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2059 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
|
2060 s->h263_aic = 1; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2061 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2062 skip_bits(&s->gb, 7); |
161 | 2063 skip_bits(&s->gb, 3); /* Reserved */ |
2064 } else if (ufep != 0) | |
0 | 2065 return -1; |
161 | 2066 |
78 | 2067 /* MPPTYPE */ |
0 | 2068 s->pict_type = get_bits(&s->gb, 3) + 1; |
2069 if (s->pict_type != I_TYPE && | |
2070 s->pict_type != P_TYPE) | |
2071 return -1; | |
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2072 skip_bits(&s->gb, 2); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2073 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
|
2074 //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
|
2075 skip_bits(&s->gb, 4); |
78 | 2076 |
2077 /* Get the picture dimensions */ | |
161 | 2078 if (ufep) { |
2079 if (format == 6) { | |
2080 /* Custom Picture Format (CPFMT) */ | |
2081 skip_bits(&s->gb, 4); /* aspect ratio */ | |
2082 width = (get_bits(&s->gb, 9) + 1) * 4; | |
2083 skip_bits1(&s->gb); | |
2084 height = get_bits(&s->gb, 9) * 4; | |
78 | 2085 #ifdef DEBUG |
161 | 2086 fprintf(stderr,"\nH.263+ Custom picture: %dx%d\n",width,height); |
78 | 2087 #endif |
161 | 2088 } |
2089 else { | |
2090 width = h263_format[format][0]; | |
2091 height = h263_format[format][1]; | |
2092 } | |
2093 if ((width == 0) || (height == 0)) | |
2094 return -1; | |
2095 s->width = width; | |
2096 s->height = height; | |
2097 if (s->umvplus_dec) { | |
2098 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
2099 } | |
78 | 2100 } |
2101 | |
0 | 2102 s->qscale = get_bits(&s->gb, 5); |
2103 } | |
2104 /* PEI */ | |
21 | 2105 while (get_bits1(&s->gb) != 0) { |
2106 skip_bits(&s->gb, 8); | |
0 | 2107 } |
2108 s->f_code = 1; | |
2109 return 0; | |
2110 } | |
2111 | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2112 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
|
2113 { |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2114 int i; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2115 int a= 2<<s->sprite_warping_accuracy; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2116 int rho= 3-s->sprite_warping_accuracy; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2117 int r=16/a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2118 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
|
2119 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
|
2120 int sprite_ref[4][2]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2121 int virtual_ref[2][2]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2122 int w2, h2; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2123 int alpha=0, beta=0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2124 int w= s->width; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2125 int h= s->height; |
255 | 2126 //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
|
2127 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
|
2128 int length; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2129 int x=0, y=0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2130 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2131 length= get_vlc(&s->gb, &sprite_trajectory); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2132 if(length){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2133 x= get_bits(&s->gb, length); |
255 | 2134 //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
|
2135 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
|
2136 x = - (x ^ ((1 << length) - 1)); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2137 } |
255 | 2138 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
|
2139 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2140 length= get_vlc(&s->gb, &sprite_trajectory); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2141 if(length){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2142 y=get_bits(&s->gb, length); |
255 | 2143 //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
|
2144 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
|
2145 y = - (y ^ ((1 << length) - 1)); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2146 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2147 skip_bits1(&s->gb); /* marker bit */ |
255 | 2148 //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
|
2149 //if(i>0 && (x!=0 || y!=0)) printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); |
255 | 2150 //x=y=0; |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2151 d[i][0]= x; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2152 d[i][1]= y; |
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 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2155 while((1<<alpha)<w) alpha++; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2156 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
|
2157 w2= 1<<alpha; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2158 h2= 1<<beta; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2159 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2160 // Note, the 4th point isnt used for GMC |
262 | 2161 if(s->divx_version==500 && s->divx_build==413){ |
2162 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; | |
2163 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; | |
2164 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; | |
2165 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; | |
2166 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; | |
2167 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; | |
2168 } else { | |
2169 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); | |
2170 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); | |
2171 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); | |
2172 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); | |
2173 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); | |
2174 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); | |
2175 } | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2176 /* 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
|
2177 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
|
2178 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2179 // 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
|
2180 // 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
|
2181 // 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
|
2182 // 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
|
2183 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) |
255 | 2184 + 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
|
2185 virtual_ref[0][1]= 16*vop_ref[0][1] |
255 | 2186 + 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
|
2187 virtual_ref[1][0]= 16*vop_ref[0][0] |
255 | 2188 + 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
|
2189 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) |
255 | 2190 + 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
|
2191 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2192 switch(s->num_sprite_warping_points) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2193 { |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2194 case 0: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2195 s->sprite_offset[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2196 s->sprite_offset[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2197 s->sprite_offset[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2198 s->sprite_offset[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2199 s->sprite_delta[0][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2200 s->sprite_delta[0][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2201 s->sprite_delta[0][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2202 s->sprite_delta[0][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2203 s->sprite_delta[1][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2204 s->sprite_delta[1][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2205 s->sprite_delta[1][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2206 s->sprite_delta[1][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2207 s->sprite_shift[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2208 s->sprite_shift[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2209 s->sprite_shift[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2210 s->sprite_shift[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2211 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2212 case 1: //GMC only |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2213 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
|
2214 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
|
2215 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
|
2216 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
|
2217 s->sprite_delta[0][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2218 s->sprite_delta[0][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2219 s->sprite_delta[0][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2220 s->sprite_delta[0][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2221 s->sprite_delta[1][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2222 s->sprite_delta[1][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2223 s->sprite_delta[1][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2224 s->sprite_delta[1][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2225 s->sprite_shift[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2226 s->sprite_shift[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2227 s->sprite_shift[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2228 s->sprite_shift[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2229 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2230 case 2: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2231 case 3: //FIXME |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2232 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
|
2233 + ((-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
|
2234 +( 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
|
2235 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
|
2236 + ((-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
|
2237 +(-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
|
2238 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
|
2239 +( 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
|
2240 +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
|
2241 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
|
2242 +(-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
|
2243 +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
|
2244 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
|
2245 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
|
2246 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
|
2247 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
|
2248 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
|
2249 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
|
2250 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
|
2251 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
|
2252 s->sprite_shift[0][0]= alpha+rho; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2253 s->sprite_shift[0][1]= alpha+rho; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2254 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
|
2255 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
|
2256 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2257 // case 3: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2258 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2259 } |
255 | 2260 /*printf("%d %d\n", s->sprite_delta[0][0][0], a<<s->sprite_shift[0][0]); |
2261 printf("%d %d\n", s->sprite_delta[0][0][1], 0); | |
2262 printf("%d %d\n", s->sprite_delta[0][1][0], 0); | |
2263 printf("%d %d\n", s->sprite_delta[0][1][1], a<<s->sprite_shift[0][1]); | |
2264 printf("%d %d\n", s->sprite_delta[1][0][0], a<<s->sprite_shift[1][0]); | |
2265 printf("%d %d\n", s->sprite_delta[1][0][1], 0); | |
2266 printf("%d %d\n", s->sprite_delta[1][1][0], 0); | |
2267 printf("%d %d\n", s->sprite_delta[1][1][1], a<<s->sprite_shift[1][1]);*/ | |
2268 /* try to simplify the situation */ | |
2269 if( s->sprite_delta[0][0][0] == a<<s->sprite_shift[0][0] | |
2270 && s->sprite_delta[0][0][1] == 0 | |
2271 && s->sprite_delta[0][1][0] == 0 | |
2272 && s->sprite_delta[0][1][1] == a<<s->sprite_shift[0][1] | |
2273 && s->sprite_delta[1][0][0] == a<<s->sprite_shift[1][0] | |
2274 && s->sprite_delta[1][0][1] == 0 | |
2275 && s->sprite_delta[1][1][0] == 0 | |
2276 && s->sprite_delta[1][1][1] == a<<s->sprite_shift[1][1]) | |
2277 { | |
2278 s->sprite_offset[0][0]>>=s->sprite_shift[0][0]; | |
2279 s->sprite_offset[0][1]>>=s->sprite_shift[0][1]; | |
2280 s->sprite_offset[1][0]>>=s->sprite_shift[1][0]; | |
2281 s->sprite_offset[1][1]>>=s->sprite_shift[1][1]; | |
2282 s->sprite_delta[0][0][0]= a; | |
2283 s->sprite_delta[0][0][1]= 0; | |
2284 s->sprite_delta[0][1][0]= 0; | |
2285 s->sprite_delta[0][1][1]= a; | |
2286 s->sprite_delta[1][0][0]= a; | |
2287 s->sprite_delta[1][0][1]= 0; | |
2288 s->sprite_delta[1][1][0]= 0; | |
2289 s->sprite_delta[1][1][1]= a; | |
2290 s->sprite_shift[0][0]= 0; | |
2291 s->sprite_shift[0][1]= 0; | |
2292 s->sprite_shift[1][0]= 0; | |
2293 s->sprite_shift[1][1]= 0; | |
2294 s->real_sprite_warping_points=1; | |
2295 } | |
2296 else | |
2297 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
|
2298 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2299 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2300 |
0 | 2301 /* decode mpeg4 VOP header */ |
2302 int mpeg4_decode_picture_header(MpegEncContext * s) | |
2303 { | |
2304 int time_incr, startcode, state, v; | |
2305 | |
2306 redo: | |
2307 /* search next start code */ | |
2308 align_get_bits(&s->gb); | |
2309 state = 0xff; | |
2310 for(;;) { | |
2311 v = get_bits(&s->gb, 8); | |
2312 if (state == 0x000001) { | |
2313 state = ((state << 8) | v) & 0xffffff; | |
2314 startcode = state; | |
2315 break; | |
2316 } | |
2317 state = ((state << 8) | v) & 0xffffff; | |
278 | 2318 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
|
2319 printf("no VOP startcode found\n"); |
0 | 2320 return -1; |
263 | 2321 } |
0 | 2322 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2323 //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
|
2324 if (startcode == 0x120) { // Video Object Layer |
262 | 2325 int width, height, vo_ver_id; |
0 | 2326 |
2327 /* vol header */ | |
21 | 2328 skip_bits(&s->gb, 1); /* random access */ |
2329 skip_bits(&s->gb, 8); /* vo_type */ | |
63 | 2330 if (get_bits1(&s->gb) != 0) { /* is_ol_id */ |
2331 vo_ver_id = get_bits(&s->gb, 4); /* vo_ver_id */ | |
2332 skip_bits(&s->gb, 3); /* vo_priority */ | |
2333 } else { | |
2334 vo_ver_id = 1; | |
2335 } | |
0 | 2336 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2337 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
|
2338 if(s->aspect_ratio_info == EXTENDET_PAR){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2339 skip_bits(&s->gb, 8); //par_width |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2340 skip_bits(&s->gb, 8); // par_height |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2341 } |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
2342 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2343 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
|
2344 printf("vol control parameter not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2345 return -1; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2346 } |
63 | 2347 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
|
2348 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
|
2349 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
|
2350 printf("Gray shape not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2351 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
|
2352 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2353 |
21 | 2354 skip_bits1(&s->gb); /* marker */ |
0 | 2355 |
262 | 2356 s->time_increment_resolution = get_bits(&s->gb, 16); |
2357 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
63 | 2358 if (s->time_increment_bits < 1) |
2359 s->time_increment_bits = 1; | |
21 | 2360 skip_bits1(&s->gb); /* marker */ |
0 | 2361 |
63 | 2362 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */ |
2363 skip_bits(&s->gb, s->time_increment_bits); | |
2364 } | |
0 | 2365 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2366 if (s->shape != BIN_ONLY_SHAPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2367 if (s->shape == RECT_SHAPE) { |
63 | 2368 skip_bits1(&s->gb); /* marker */ |
2369 width = get_bits(&s->gb, 13); | |
2370 skip_bits1(&s->gb); /* marker */ | |
2371 height = get_bits(&s->gb, 13); | |
2372 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
|
2373 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
|
2374 s->width = width; |
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2375 s->height = height; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2376 // 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
|
2377 } |
63 | 2378 } |
2379 | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2380 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
|
2381 if(!get_bits1(&s->gb)) printf("OBMC not supported\n"); /* OBMC Disable */ |
63 | 2382 if (vo_ver_id == 1) { |
2383 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */ | |
2384 } else { | |
2385 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */ | |
2386 } | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2387 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
|
2388 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
|
2389 if(s->vol_sprite_usage==STATIC_SPRITE){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2390 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
|
2391 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2392 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
|
2393 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2394 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
|
2395 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2396 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
|
2397 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2398 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2399 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
|
2400 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
|
2401 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
|
2402 if(s->vol_sprite_usage==STATIC_SPRITE) |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2403 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
|
2404 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2405 // 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
|
2406 |
63 | 2407 if (get_bits1(&s->gb) == 1) { /* not_8_bit */ |
2408 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
|
2409 if(get_bits(&s->gb, 4)!=8) printf("N-bit not supported\n"); /* bits_per_pixel */ |
290 | 2410 if(s->quant_precision!=5) printf("quant precission %d\n", s->quant_precision); |
63 | 2411 } else { |
2412 s->quant_precision = 5; | |
2413 } | |
2414 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2415 // FIXME a bunch of grayscale shape things |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2416 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
|
2417 if(vo_ver_id != 1) |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2418 s->quarter_sample= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2419 else s->quarter_sample=0; |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2420 |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2421 if(!get_bits1(&s->gb)) printf("Complexity estimation not supported\n"); |
290 | 2422 |
2423 s->resync_marker= !get_bits1(&s->gb); /* resync_marker_disabled */ | |
2424 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2425 s->data_partioning= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2426 if(s->data_partioning){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2427 printf("data partitioning not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2428 skip_bits1(&s->gb); // reversible vlc |
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 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2431 if(vo_ver_id != 1) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2432 s->new_pred= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2433 if(s->new_pred){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2434 printf("new pred not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2435 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
|
2436 skip_bits1(&s->gb); /* newpred segment type */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2437 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2438 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
|
2439 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
|
2440 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2441 else{ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2442 s->new_pred=0; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2443 s->reduced_res_vop= 0; |
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 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2446 s->scalability= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2447 if (s->scalability) { |
285 | 2448 printf("scalability not supported\n"); |
63 | 2449 } |
2450 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2451 //printf("end Data %X %d\n", show_bits(&s->gb, 32), get_bits_count(&s->gb)&0x7); |
0 | 2452 goto redo; |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2453 } else if (startcode == 0x1b2) { //userdata |
255 | 2454 char buf[256]; |
2455 int i; | |
2456 int e; | |
2457 int ver, build; | |
2458 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2459 //printf("user Data %X\n", show_bits(&s->gb, 32)); |
255 | 2460 buf[0]= show_bits(&s->gb, 8); |
2461 for(i=1; i<256; i++){ | |
2462 buf[i]= show_bits(&s->gb, 16)&0xFF; | |
2463 if(buf[i]==0) break; | |
2464 skip_bits(&s->gb, 8); | |
2465 } | |
2466 buf[255]=0; | |
2467 e=sscanf(buf, "DivX%dBuild%d", &ver, &build); | |
2468 if(e==2){ | |
2469 s->divx_version= ver; | |
2470 s->divx_build= build; | |
2471 if(s->picture_number==0){ | |
2472 printf("This file was encoded with DivX%d Build%d\n", ver, build); | |
2473 if(ver==500 && build==413){ //most likely all version are indeed totally buggy but i dunno for sure ... | |
2474 printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n"); | |
2475 }else{ | |
2476 printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n" | |
2477 "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n"); | |
2478 } | |
2479 } | |
2480 } | |
2481 //printf("User Data: %s\n", buf); | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2482 goto redo; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2483 } else if (startcode != 0x1b6) { //VOP |
0 | 2484 goto redo; |
2485 } | |
2486 | |
2487 s->pict_type = get_bits(&s->gb, 2) + 1; /* pict type: I = 0 , P = 1 */ | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2488 //printf("pic: %d\n", s->pict_type); |
262 | 2489 time_incr=0; |
21 | 2490 while (get_bits1(&s->gb) != 0) |
0 | 2491 time_incr++; |
2492 | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2493 check_marker(&s->gb, "before time_increment"); |
262 | 2494 s->time_increment= get_bits(&s->gb, s->time_increment_bits); |
2495 if(s->pict_type!=B_TYPE){ | |
2496 s->time_base+= time_incr; | |
2497 s->last_non_b_time[1]= s->last_non_b_time[0]; | |
2498 s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment; | |
2499 }else{ | |
2500 s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution; | |
2501 s->time+= s->time_increment; | |
2502 } | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2503 |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2504 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
|
2505 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
|
2506 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
|
2507 if(get_bits1(&s->gb)) break; |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2508 } |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2509 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
|
2510 } |
0 | 2511 /* vop coded */ |
21 | 2512 if (get_bits1(&s->gb) != 1) |
63 | 2513 goto redo; |
262 | 2514 //printf("time %d %d %d || %d %d %d\n", s->time_increment_bits, s->time_increment, s->time_base, |
2515 //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
|
2516 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
|
2517 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { |
0 | 2518 /* rounding type for motion estimation */ |
21 | 2519 s->no_rounding = get_bits1(&s->gb); |
63 | 2520 } else { |
2521 s->no_rounding = 0; | |
0 | 2522 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2523 //FIXME reduced res stuff |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2524 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2525 if (s->shape != RECT_SHAPE) { |
63 | 2526 if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) { |
2527 int width, height, hor_spat_ref, ver_spat_ref; | |
2528 | |
2529 width = get_bits(&s->gb, 13); | |
2530 skip_bits1(&s->gb); /* marker */ | |
2531 height = get_bits(&s->gb, 13); | |
2532 skip_bits1(&s->gb); /* marker */ | |
2533 hor_spat_ref = get_bits(&s->gb, 13); /* hor_spat_ref */ | |
2534 skip_bits1(&s->gb); /* marker */ | |
2535 ver_spat_ref = get_bits(&s->gb, 13); /* ver_spat_ref */ | |
2536 } | |
2537 skip_bits1(&s->gb); /* change_CR_disable */ | |
2538 | |
2539 if (get_bits1(&s->gb) != 0) { | |
2540 skip_bits(&s->gb, 8); /* constant_alpha_value */ | |
2541 } | |
2542 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2543 //FIXME complexity estimation stuff |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2544 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2545 if (s->shape != BIN_ONLY_SHAPE) { |
290 | 2546 int t; |
2547 t=get_bits(&s->gb, 3); /* intra dc VLC threshold */ | |
2548 //printf("threshold %d\n", t); | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2549 //FIXME interlaced specific bits |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2550 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2551 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2552 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
|
2553 if(s->num_sprite_warping_points){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2554 mpeg4_decode_sprite_trajectory(s); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2555 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2556 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
|
2557 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
|
2558 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2559 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2560 if (s->shape != BIN_ONLY_SHAPE) { |
63 | 2561 /* note: we do not use quant_precision to avoid problem if no |
2562 MPEG4 vol header as it is found on some old opendivx | |
2563 movies */ | |
2564 s->qscale = get_bits(&s->gb, 5); | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2565 if(s->qscale==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2566 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
|
2567 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
|
2568 } |
63 | 2569 |
2570 if (s->pict_type != I_TYPE) { | |
2571 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
|
2572 if(s->f_code==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2573 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
|
2574 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
|
2575 } |
63 | 2576 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2577 if (s->pict_type == B_TYPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2578 s->b_code = get_bits(&s->gb, 3); |
262 | 2579 //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
|
2580 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2581 //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
|
2582 if(!s->scalability){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2583 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
|
2584 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
|
2585 } |
63 | 2586 } |
2587 } | |
255 | 2588 s->picture_number++; // better than pic number==0 allways ;) |
63 | 2589 return 0; |
0 | 2590 } |
2591 | |
2592 /* don't understand why they choose a different header ! */ | |
2593 int intel_h263_decode_picture_header(MpegEncContext *s) | |
2594 { | |
2595 int format; | |
2596 | |
2597 /* picture header */ | |
2598 if (get_bits(&s->gb, 22) != 0x20) | |
2599 return -1; | |
21 | 2600 skip_bits(&s->gb, 8); /* picture timestamp */ |
0 | 2601 |
21 | 2602 if (get_bits1(&s->gb) != 1) |
0 | 2603 return -1; /* marker */ |
21 | 2604 if (get_bits1(&s->gb) != 0) |
0 | 2605 return -1; /* h263 id */ |
21 | 2606 skip_bits1(&s->gb); /* split screen off */ |
2607 skip_bits1(&s->gb); /* camera off */ | |
2608 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 2609 |
2610 format = get_bits(&s->gb, 3); | |
2611 if (format != 7) | |
2612 return -1; | |
2613 | |
2614 s->h263_plus = 0; | |
2615 | |
21 | 2616 s->pict_type = I_TYPE + get_bits1(&s->gb); |
0 | 2617 |
21 | 2618 s->unrestricted_mv = get_bits1(&s->gb); |
0 | 2619 s->h263_long_vectors = s->unrestricted_mv; |
2620 | |
21 | 2621 if (get_bits1(&s->gb) != 0) |
0 | 2622 return -1; /* SAC: off */ |
21 | 2623 if (get_bits1(&s->gb) != 0) |
0 | 2624 return -1; /* advanced prediction mode: off */ |
21 | 2625 if (get_bits1(&s->gb) != 0) |
0 | 2626 return -1; /* not PB frame */ |
2627 | |
2628 /* skip unknown header garbage */ | |
21 | 2629 skip_bits(&s->gb, 41); |
0 | 2630 |
2631 s->qscale = get_bits(&s->gb, 5); | |
21 | 2632 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
0 | 2633 |
2634 /* PEI */ | |
21 | 2635 while (get_bits1(&s->gb) != 0) { |
2636 skip_bits(&s->gb, 8); | |
0 | 2637 } |
2638 s->f_code = 1; | |
2639 return 0; | |
2640 } | |
144 | 2641 |