Mercurial > libavcodec.hg
annotate dv.c @ 1537:6df940415116 libavcodec
align
author | michael |
---|---|
date | Wed, 15 Oct 2003 16:20:50 +0000 |
parents | 79dddc5cd990 |
children | a0086452b9d8 |
rev | line source |
---|---|
723 | 1 /* |
2 * DV decoder | |
3 * Copyright (c) 2002 Fabrice Bellard. | |
4 * | |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
5 * DV encoder |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
6 * Copyright (c) 2003 Roman Shaposhnik. |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
7 * |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
8 * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
9 * of DV technical info. |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
10 * |
723 | 11 * This library is free software; you can redistribute it and/or |
12 * modify it under the terms of the GNU Lesser General Public | |
13 * License as published by the Free Software Foundation; either | |
14 * version 2 of the License, or (at your option) any later version. | |
15 * | |
16 * This library is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 * Lesser General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU Lesser General Public | |
22 * License along with this library; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
1106 | 25 |
26 /** | |
27 * @file dv.c | |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
28 * DV codec. |
1106 | 29 */ |
723 | 30 #include "avcodec.h" |
31 #include "dsputil.h" | |
32 #include "mpegvideo.h" | |
33 #include "simple_idct.h" | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
34 #include "dvdata.h" |
723 | 35 |
36 typedef struct DVVideoDecodeContext { | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
37 const DVprofile* sys; |
723 | 38 GetBitContext gb; |
925 | 39 AVFrame picture; |
723 | 40 DCTELEM block[5*6][64] __align8; |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
41 |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
42 /* FIXME: the following is extracted from DSP */ |
1064 | 43 uint8_t dv_zigzag[2][64]; |
44 uint8_t idct_permutation[64]; | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
45 void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size); |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
46 void (*fdct)(DCTELEM *block); |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
47 |
723 | 48 /* XXX: move it to static storage ? */ |
1064 | 49 uint8_t dv_shift[2][22][64]; |
50 void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block); | |
723 | 51 } DVVideoDecodeContext; |
52 | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
53 #define TEX_VLC_BITS 9 |
723 | 54 /* XXX: also include quantization */ |
55 static RL_VLC_ELEM *dv_rl_vlc[1]; | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
56 static VLC_TYPE dv_vlc_codes[15][23]; |
723 | 57 |
58 static void dv_build_unquantize_tables(DVVideoDecodeContext *s) | |
59 { | |
725 | 60 int i, q, j; |
723 | 61 |
62 /* NOTE: max left shift is 6 */ | |
725 | 63 for(q = 0; q < 22; q++) { |
64 /* 88 unquant */ | |
65 for(i = 1; i < 64; i++) { | |
66 /* 88 table */ | |
67 j = s->idct_permutation[i]; | |
68 s->dv_shift[0][q][j] = | |
69 dv_quant_shifts[q][dv_88_areas[i]] + 1; | |
70 } | |
71 | |
72 /* 248 unquant */ | |
73 for(i = 1; i < 64; i++) { | |
74 /* 248 table */ | |
75 s->dv_shift[1][q][i] = | |
76 dv_quant_shifts[q][dv_248_areas[i]] + 1; | |
723 | 77 } |
78 } | |
79 } | |
80 | |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
81 static int dvvideo_init(AVCodecContext *avctx) |
723 | 82 { |
83 DVVideoDecodeContext *s = avctx->priv_data; | |
725 | 84 MpegEncContext s2; |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1064
diff
changeset
|
85 static int done=0; |
723 | 86 |
87 if (!done) { | |
88 int i; | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
89 VLC dv_vlc; |
723 | 90 |
91 done = 1; | |
92 | |
93 /* NOTE: as a trick, we use the fact the no codes are unused | |
94 to accelerate the parsing of partial codes */ | |
95 init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC, | |
96 dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2); | |
97 | |
98 dv_rl_vlc[0] = av_malloc(dv_vlc.table_size * sizeof(RL_VLC_ELEM)); | |
99 for(i = 0; i < dv_vlc.table_size; i++){ | |
100 int code= dv_vlc.table[i][0]; | |
101 int len = dv_vlc.table[i][1]; | |
102 int level, run; | |
103 | |
104 if(len<0){ //more bits needed | |
105 run= 0; | |
106 level= code; | |
107 } else if (code == (NB_DV_VLC - 1)) { | |
108 /* EOB */ | |
109 run = 0; | |
110 level = 256; | |
111 } else { | |
112 run= dv_vlc_run[code] + 1; | |
113 level= dv_vlc_level[code]; | |
114 } | |
115 dv_rl_vlc[0][i].len = len; | |
116 dv_rl_vlc[0][i].level = level; | |
117 dv_rl_vlc[0][i].run = run; | |
118 } | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
119 |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
120 memset(dv_vlc_codes, 0xff, sizeof(dv_vlc_codes)); |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
121 for (i = 0; i < NB_DV_VLC - 1; i++) { |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
122 if (dv_vlc_run[i] < 15 && dv_vlc_level[i] < 23 && dv_vlc_len[i] < 15) |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
123 dv_vlc_codes[dv_vlc_run[i]][dv_vlc_level[i]] = i; |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
124 } |
723 | 125 } |
725 | 126 |
127 /* ugly way to get the idct & scantable */ | |
128 /* XXX: fix it */ | |
129 memset(&s2, 0, sizeof(MpegEncContext)); | |
130 s2.avctx = avctx; | |
1092 | 131 dsputil_init(&s2.dsp, avctx); |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
725
diff
changeset
|
132 if (DCT_common_init(&s2) < 0) |
725 | 133 return -1; |
134 | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
135 s->get_pixels = s2.dsp.get_pixels; |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
136 s->fdct = s2.dsp.fdct; |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
137 |
1092 | 138 s->idct_put[0] = s2.dsp.idct_put; |
139 memcpy(s->idct_permutation, s2.dsp.idct_permutation, 64); | |
725 | 140 memcpy(s->dv_zigzag[0], s2.intra_scantable.permutated, 64); |
141 | |
142 /* XXX: use MMX also for idct248 */ | |
143 s->idct_put[1] = simple_idct248_put; | |
144 memcpy(s->dv_zigzag[1], dv_248_zigzag, 64); | |
145 | |
723 | 146 /* XXX: do it only for constant case */ |
147 dv_build_unquantize_tables(s); | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
148 |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
149 /* FIXME: I really don't think this should be here */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
150 if (dv_codec_profile(avctx)) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
151 avctx->pix_fmt = dv_codec_profile(avctx)->pix_fmt; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
152 |
723 | 153 return 0; |
154 } | |
155 | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
156 // #define VLC_DEBUG |
723 | 157 |
725 | 158 typedef struct BlockInfo { |
1064 | 159 const uint8_t *shift_table; |
160 const uint8_t *scan_table; | |
161 uint8_t pos; /* position in block */ | |
162 uint8_t eob_reached; /* true if EOB has been reached */ | |
163 uint8_t dct_mode; | |
164 uint8_t partial_bit_count; | |
165 uint16_t partial_bit_buffer; | |
725 | 166 int shift_offset; |
167 } BlockInfo; | |
723 | 168 |
169 /* block size in bits */ | |
1064 | 170 static const uint16_t block_sizes[6] = { |
723 | 171 112, 112, 112, 112, 80, 80 |
172 }; | |
173 | |
174 #ifndef ALT_BITSTREAM_READER | |
1256
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
175 #warning only works with ALT_BITSTREAM_READER |
723 | 176 #endif |
177 | |
178 /* decode ac coefs */ | |
179 static void dv_decode_ac(DVVideoDecodeContext *s, | |
1008 | 180 BlockInfo *mb, DCTELEM *block, int last_index) |
723 | 181 { |
182 int last_re_index; | |
725 | 183 int shift_offset = mb->shift_offset; |
1064 | 184 const uint8_t *scan_table = mb->scan_table; |
185 const uint8_t *shift_table = mb->shift_table; | |
725 | 186 int pos = mb->pos; |
723 | 187 int level, pos1, sign, run; |
188 int partial_bit_count; | |
1256
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
189 #ifndef ALT_BITSTREAM_READER //FIXME |
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
190 int re_index=0; |
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
191 int re1_index=0; |
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
192 #endif |
723 | 193 OPEN_READER(re, &s->gb); |
194 | |
195 #ifdef VLC_DEBUG | |
725 | 196 printf("start\n"); |
723 | 197 #endif |
198 | |
199 /* if we must parse a partial vlc, we do it here */ | |
725 | 200 partial_bit_count = mb->partial_bit_count; |
723 | 201 if (partial_bit_count > 0) { |
1064 | 202 uint8_t buf[4]; |
203 uint32_t v; | |
723 | 204 int l, l1; |
205 GetBitContext gb1; | |
206 | |
207 /* build the dummy bit buffer */ | |
208 l = 16 - partial_bit_count; | |
209 UPDATE_CACHE(re, &s->gb); | |
210 #ifdef VLC_DEBUG | |
211 printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16)); | |
212 #endif | |
725 | 213 v = (mb->partial_bit_buffer << l) | SHOW_UBITS(re, &s->gb, l); |
723 | 214 buf[0] = v >> 8; |
215 buf[1] = v; | |
216 #ifdef VLC_DEBUG | |
217 printf("v=%04x cnt=%d %04x\n", | |
725 | 218 v, partial_bit_count, (mb->partial_bit_buffer << l)); |
723 | 219 #endif |
220 /* try to read the codeword */ | |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1008
diff
changeset
|
221 init_get_bits(&gb1, buf, 4*8); |
723 | 222 { |
223 OPEN_READER(re1, &gb1); | |
224 UPDATE_CACHE(re1, &gb1); | |
225 GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0], | |
226 TEX_VLC_BITS, 2); | |
227 l = re1_index; | |
228 CLOSE_READER(re1, &gb1); | |
229 } | |
230 #ifdef VLC_DEBUG | |
231 printf("****run=%d level=%d size=%d\n", run, level, l); | |
232 #endif | |
233 /* compute codeword length */ | |
234 l1 = (level != 256 && level != 0); | |
235 /* if too long, we cannot parse */ | |
236 l -= partial_bit_count; | |
237 if ((re_index + l + l1) > last_index) | |
238 return; | |
239 /* skip read bits */ | |
240 last_re_index = 0; /* avoid warning */ | |
241 re_index += l; | |
725 | 242 /* by definition, if we can read the vlc, all partial bits |
723 | 243 will be read (otherwise we could have read the vlc before) */ |
725 | 244 mb->partial_bit_count = 0; |
723 | 245 UPDATE_CACHE(re, &s->gb); |
246 goto handle_vlc; | |
247 } | |
248 | |
249 /* get the AC coefficients until last_index is reached */ | |
250 for(;;) { | |
251 UPDATE_CACHE(re, &s->gb); | |
252 #ifdef VLC_DEBUG | |
253 printf("%2d: bits=%04x index=%d\n", | |
254 pos, SHOW_UBITS(re, &s->gb, 16), re_index); | |
255 #endif | |
256 last_re_index = re_index; | |
257 GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0], | |
258 TEX_VLC_BITS, 2); | |
259 handle_vlc: | |
260 #ifdef VLC_DEBUG | |
261 printf("run=%d level=%d\n", run, level); | |
262 #endif | |
263 if (level == 256) { | |
264 if (re_index > last_index) { | |
265 cannot_read: | |
266 /* put position before read code */ | |
267 re_index = last_re_index; | |
725 | 268 mb->eob_reached = 0; |
723 | 269 break; |
270 } | |
271 /* EOB */ | |
725 | 272 mb->eob_reached = 1; |
723 | 273 break; |
274 } else if (level != 0) { | |
275 if ((re_index + 1) > last_index) | |
276 goto cannot_read; | |
277 sign = SHOW_SBITS(re, &s->gb, 1); | |
278 level = (level ^ sign) - sign; | |
279 LAST_SKIP_BITS(re, &s->gb, 1); | |
280 pos += run; | |
281 /* error */ | |
282 if (pos >= 64) { | |
283 goto read_error; | |
284 } | |
285 pos1 = scan_table[pos]; | |
725 | 286 level = level << (shift_table[pos1] + shift_offset); |
723 | 287 block[pos1] = level; |
288 // printf("run=%d level=%d shift=%d\n", run, level, shift_table[pos1]); | |
289 } else { | |
290 if (re_index > last_index) | |
291 goto cannot_read; | |
292 /* level is zero: means run without coding. No | |
293 sign is coded */ | |
294 pos += run; | |
295 /* error */ | |
296 if (pos >= 64) { | |
297 read_error: | |
298 #if defined(VLC_DEBUG) || 1 | |
1222
adcc6f345202
making it nicer to the client who doesn't expect errors messages in stdout
romansh
parents:
1221
diff
changeset
|
299 fprintf(stderr, "error pos=%d\n", pos); |
723 | 300 #endif |
301 /* for errors, we consider the eob is reached */ | |
725 | 302 mb->eob_reached = 1; |
723 | 303 break; |
304 } | |
305 } | |
306 } | |
307 CLOSE_READER(re, &s->gb); | |
725 | 308 mb->pos = pos; |
723 | 309 } |
310 | |
311 static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left) | |
312 { | |
313 while (bits_left >= 16) { | |
314 put_bits(pb, 16, get_bits(gb, 16)); | |
315 bits_left -= 16; | |
316 } | |
317 if (bits_left > 0) { | |
318 put_bits(pb, bits_left, get_bits(gb, bits_left)); | |
319 } | |
320 } | |
321 | |
322 /* mb_x and mb_y are in units of 8 pixels */ | |
323 static inline void dv_decode_video_segment(DVVideoDecodeContext *s, | |
1064 | 324 uint8_t *buf_ptr1, |
325 const uint16_t *mb_pos_ptr) | |
723 | 326 { |
327 int quant, dc, dct_mode, class1, j; | |
328 int mb_index, mb_x, mb_y, v, last_index; | |
329 DCTELEM *block, *block1; | |
330 int c_offset, bits_left; | |
1064 | 331 uint8_t *y_ptr; |
725 | 332 BlockInfo mb_data[5 * 6], *mb, *mb1; |
1064 | 333 void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block); |
334 uint8_t *buf_ptr; | |
723 | 335 PutBitContext pb, vs_pb; |
1064 | 336 uint8_t mb_bit_buffer[80 + 4]; /* allow some slack */ |
725 | 337 int mb_bit_count; |
1064 | 338 uint8_t vs_bit_buffer[5 * 80 + 4]; /* allow some slack */ |
723 | 339 int vs_bit_count; |
340 | |
341 memset(s->block, 0, sizeof(s->block)); | |
342 | |
343 /* pass 1 : read DC and AC coefficients in blocks */ | |
344 buf_ptr = buf_ptr1; | |
345 block1 = &s->block[0][0]; | |
725 | 346 mb1 = mb_data; |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1507
diff
changeset
|
347 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80); |
723 | 348 vs_bit_count = 0; |
349 for(mb_index = 0; mb_index < 5; mb_index++) { | |
350 /* skip header */ | |
351 quant = buf_ptr[3] & 0x0f; | |
352 buf_ptr += 4; | |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1507
diff
changeset
|
353 init_put_bits(&pb, mb_bit_buffer, 80); |
725 | 354 mb_bit_count = 0; |
355 mb = mb1; | |
723 | 356 block = block1; |
357 for(j = 0;j < 6; j++) { | |
358 /* NOTE: size is not important here */ | |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1008
diff
changeset
|
359 init_get_bits(&s->gb, buf_ptr, 14*8); |
723 | 360 |
361 /* get the dc */ | |
362 dc = get_bits(&s->gb, 9); | |
363 dc = (dc << (32 - 9)) >> (32 - 9); | |
364 dct_mode = get_bits1(&s->gb); | |
725 | 365 mb->dct_mode = dct_mode; |
366 mb->scan_table = s->dv_zigzag[dct_mode]; | |
723 | 367 class1 = get_bits(&s->gb, 2); |
725 | 368 mb->shift_offset = (class1 == 3); |
369 mb->shift_table = s->dv_shift[dct_mode] | |
723 | 370 [quant + dv_quant_offset[class1]]; |
371 dc = dc << 2; | |
372 /* convert to unsigned because 128 is not added in the | |
373 standard IDCT */ | |
374 dc += 1024; | |
375 block[0] = dc; | |
376 last_index = block_sizes[j]; | |
377 buf_ptr += last_index >> 3; | |
725 | 378 mb->pos = 0; |
379 mb->partial_bit_count = 0; | |
723 | 380 |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
381 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
382 printf("MB block: %d, %d ", mb_index, j); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
383 #endif |
725 | 384 dv_decode_ac(s, mb, block, last_index); |
723 | 385 |
386 /* write the remaining bits in a new buffer only if the | |
387 block is finished */ | |
1256
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
388 bits_left = last_index - get_bits_count(&s->gb); |
725 | 389 if (mb->eob_reached) { |
390 mb->partial_bit_count = 0; | |
391 mb_bit_count += bits_left; | |
723 | 392 bit_copy(&pb, &s->gb, bits_left); |
393 } else { | |
394 /* should be < 16 bits otherwise a codeword could have | |
395 been parsed */ | |
725 | 396 mb->partial_bit_count = bits_left; |
397 mb->partial_bit_buffer = get_bits(&s->gb, bits_left); | |
723 | 398 } |
399 block += 64; | |
725 | 400 mb++; |
723 | 401 } |
402 | |
403 flush_put_bits(&pb); | |
404 | |
405 /* pass 2 : we can do it just after */ | |
406 #ifdef VLC_DEBUG | |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
407 printf("***pass 2 size=%d MB#=%d\n", mb_bit_count, mb_index); |
723 | 408 #endif |
409 block = block1; | |
725 | 410 mb = mb1; |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1008
diff
changeset
|
411 init_get_bits(&s->gb, mb_bit_buffer, 80*8); |
723 | 412 for(j = 0;j < 6; j++) { |
1256
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
413 if (!mb->eob_reached && get_bits_count(&s->gb) < mb_bit_count) { |
725 | 414 dv_decode_ac(s, mb, block, mb_bit_count); |
723 | 415 /* if still not finished, no need to parse other blocks */ |
725 | 416 if (!mb->eob_reached) { |
723 | 417 /* we could not parse the current AC coefficient, |
418 so we add the remaining bytes */ | |
1256
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
419 bits_left = mb_bit_count - get_bits_count(&s->gb); |
723 | 420 if (bits_left > 0) { |
725 | 421 mb->partial_bit_count += bits_left; |
422 mb->partial_bit_buffer = | |
423 (mb->partial_bit_buffer << bits_left) | | |
723 | 424 get_bits(&s->gb, bits_left); |
425 } | |
426 goto next_mb; | |
427 } | |
428 } | |
429 block += 64; | |
725 | 430 mb++; |
723 | 431 } |
432 /* all blocks are finished, so the extra bytes can be used at | |
433 the video segment level */ | |
1256
b8e1c17b8d7d
some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents:
1228
diff
changeset
|
434 bits_left = mb_bit_count - get_bits_count(&s->gb); |
723 | 435 vs_bit_count += bits_left; |
436 bit_copy(&vs_pb, &s->gb, bits_left); | |
437 next_mb: | |
725 | 438 mb1 += 6; |
723 | 439 block1 += 6 * 64; |
440 } | |
441 | |
442 /* we need a pass other the whole video segment */ | |
443 flush_put_bits(&vs_pb); | |
444 | |
445 #ifdef VLC_DEBUG | |
446 printf("***pass 3 size=%d\n", vs_bit_count); | |
447 #endif | |
448 block = &s->block[0][0]; | |
449 mb = mb_data; | |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1008
diff
changeset
|
450 init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8); |
723 | 451 for(mb_index = 0; mb_index < 5; mb_index++) { |
452 for(j = 0;j < 6; j++) { | |
725 | 453 if (!mb->eob_reached) { |
723 | 454 #ifdef VLC_DEBUG |
455 printf("start %d:%d\n", mb_index, j); | |
456 #endif | |
725 | 457 dv_decode_ac(s, mb, block, vs_bit_count); |
723 | 458 } |
459 block += 64; | |
725 | 460 mb++; |
723 | 461 } |
462 } | |
463 | |
464 /* compute idct and place blocks */ | |
465 block = &s->block[0][0]; | |
466 mb = mb_data; | |
467 for(mb_index = 0; mb_index < 5; mb_index++) { | |
468 v = *mb_pos_ptr++; | |
469 mb_x = v & 0xff; | |
470 mb_y = v >> 8; | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
471 y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 8); |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
472 if (s->sys->pix_fmt == PIX_FMT_YUV411P) |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
473 c_offset = (mb_y * s->picture.linesize[1] * 8) + ((mb_x >> 2) * 8); |
723 | 474 else |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
475 c_offset = ((mb_y >> 1) * s->picture.linesize[1] * 8) + ((mb_x >> 1) * 8); |
723 | 476 for(j = 0;j < 6; j++) { |
725 | 477 idct_put = s->idct_put[mb->dct_mode]; |
723 | 478 if (j < 4) { |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
479 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) { |
737 | 480 /* NOTE: at end of line, the macroblock is handled as 420 */ |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
481 idct_put(y_ptr + (j * 8), s->picture.linesize[0], block); |
723 | 482 } else { |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
483 idct_put(y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->picture.linesize[0]), |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
484 s->picture.linesize[0], block); |
723 | 485 } |
486 } else { | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
487 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) { |
1537 | 488 uint64_t aligned_pixels[64/8], *c_ptr, *c_ptr1, *ptr; |
489 uint8_t *pixels= (uint8_t*)aligned_pixels; | |
737 | 490 int y, linesize; |
491 /* NOTE: at end of line, the macroblock is handled as 420 */ | |
492 idct_put(pixels, 8, block); | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
493 linesize = s->picture.linesize[6 - j]; |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
494 c_ptr = s->picture.data[6 - j] + c_offset; |
737 | 495 ptr = pixels; |
496 for(y = 0;y < 8; y++) { | |
497 /* convert to 411P */ | |
1270
f5318caa93f4
seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents:
1256
diff
changeset
|
498 c_ptr1 = c_ptr + 8*linesize; |
f5318caa93f4
seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents:
1256
diff
changeset
|
499 c_ptr[0]= ptr[0]; c_ptr1[0]= ptr[4]; |
f5318caa93f4
seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents:
1256
diff
changeset
|
500 c_ptr[1]= ptr[1]; c_ptr1[1]= ptr[5]; |
f5318caa93f4
seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents:
1256
diff
changeset
|
501 c_ptr[2]= ptr[2]; c_ptr1[2]= ptr[6]; |
f5318caa93f4
seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents:
1256
diff
changeset
|
502 c_ptr[3]= ptr[3]; c_ptr1[3]= ptr[7]; |
f5318caa93f4
seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents:
1256
diff
changeset
|
503 c_ptr += linesize; |
737 | 504 ptr += 8; |
505 } | |
506 } else { | |
507 /* don't ask me why they inverted Cb and Cr ! */ | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
508 idct_put(s->picture.data[6 - j] + c_offset, |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
509 s->picture.linesize[6 - j], block); |
737 | 510 } |
723 | 511 } |
512 block += 64; | |
725 | 513 mb++; |
723 | 514 } |
515 } | |
516 } | |
517 | |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
518 /* Converts run and level (where level != 0) pair into vlc, returning bit size */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
519 static inline int dv_rl2vlc(int run, int l, uint32_t* vlc) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
520 { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
521 int sign = l >> 8; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
522 int level = (l ^ sign) - sign; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
523 int size; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
524 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
525 sign = (sign & 1); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
526 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
527 if (run < 15 && level < 23 && dv_vlc_codes[run][level] != -1) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
528 *vlc = (dv_vlc_bits[dv_vlc_codes[run][level]] << 1) | sign; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
529 size = dv_vlc_len[dv_vlc_codes[run][level]] + 1; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
530 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
531 else { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
532 if (level < 23) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
533 *vlc = (dv_vlc_bits[dv_vlc_codes[0][level]] << 1) | sign; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
534 size = dv_vlc_len[dv_vlc_codes[0][level]] + 1; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
535 } else { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
536 *vlc = 0xfe00 | (level << 1) | sign; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
537 size = 16; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
538 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
539 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
540 switch(run) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
541 case 0: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
542 break; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
543 case 1: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
544 case 2: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
545 *vlc |= ((0x7ce | (run - 1)) << size); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
546 size += 11; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
547 break; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
548 case 3: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
549 case 4: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
550 case 5: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
551 case 6: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
552 *vlc |= ((0xfac | (run - 3)) << size); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
553 size += 12; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
554 break; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
555 default: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
556 *vlc |= ((0x1f80 | (run - 1)) << size); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
557 size += 13; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
558 break; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
559 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
560 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
561 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
562 return size; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
563 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
564 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
565 typedef struct EncBlockInfo { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
566 int qno; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
567 int cno; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
568 int dct_mode; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
569 int block_size; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
570 DCTELEM *mb; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
571 PutBitContext pb; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
572 } EncBlockInfo; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
573 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
574 static inline int dv_bits_left(EncBlockInfo* bi) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
575 { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
576 return (bi->block_size - get_bit_count(&bi->pb)); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
577 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
578 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
579 static inline void dv_encode_ac(EncBlockInfo* bi, PutBitContext* heap) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
580 { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
581 int i, level, size, run = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
582 uint32_t vlc; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
583 PutBitContext* cpb = &bi->pb; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
584 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
585 for (i=1; i<64; i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
586 level = bi->mb[ff_zigzag_direct[i]] / |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
587 (1<<(dv_quant_shifts[bi->qno + dv_quant_offset[bi->cno]] |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
588 [dv_88_areas[ff_zigzag_direct[i]]] + 4 + (bi->cno == 3))); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
589 if (level != 0) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
590 size = dv_rl2vlc(run, level, &vlc); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
591 put_vlc: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
592 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
593 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
594 printf(" %3d:%3d", run, level); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
595 #endif |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
596 if (cpb == &bi->pb && size > dv_bits_left(bi)) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
597 size -= dv_bits_left(bi); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
598 put_bits(cpb, dv_bits_left(bi), vlc >> size); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
599 vlc = vlc & ((1<<size)-1); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
600 cpb = heap; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
601 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
602 put_bits(cpb, size, vlc); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
603 run = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
604 } else |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
605 run++; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
606 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
607 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
608 if (i == 64) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
609 size = 4; vlc = 6; /* End Of Block stamp */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
610 goto put_vlc; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
611 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
612 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
613 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
614 static inline void dv_redistr_bits(EncBlockInfo* bi, int count, uint8_t* extra_data, int extra_bits, PutBitContext* heap) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
615 { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
616 int i; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
617 GetBitContext gb; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
618 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
619 init_get_bits(&gb, extra_data, extra_bits); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
620 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
621 for (i=0; i<count; i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
622 int bits_left = dv_bits_left(bi); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
623 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
624 if (bits_left) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
625 printf("------------> inserting %d bytes in %d:%d\n", bits_left, i/6, i%6); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
626 #endif |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
627 if (bits_left > extra_bits) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
628 bit_copy(&bi->pb, &gb, extra_bits); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
629 extra_bits = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
630 break; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
631 } else |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
632 bit_copy(&bi->pb, &gb, bits_left); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
633 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
634 extra_bits -= bits_left; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
635 bi++; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
636 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
637 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
638 if (extra_bits > 0 && heap) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
639 bit_copy(heap, &gb, extra_bits); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
640 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
641 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
642 static inline void dv_set_class_number(EncBlockInfo* bi, int j) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
643 { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
644 int i, max_ac = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
645 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
646 for (i=1; i<64; i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
647 int ac = abs(bi->mb[ff_zigzag_direct[i]]) / 4; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
648 if (max_ac < ac) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
649 max_ac = ac; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
650 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
651 if (max_ac < 12) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
652 bi->cno = j; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
653 else if (max_ac < 24) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
654 bi->cno = j + 1; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
655 else if (max_ac < 36) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
656 bi->cno = j + 2; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
657 else |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
658 bi->cno = j + 3; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
659 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
660 if (bi->cno > 3) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
661 bi->cno = 3; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
662 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
663 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
664 /* |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
665 * This is a very rough initial implementaion. The performance is |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
666 * horrible and some features are missing, mainly 2-4-8 DCT encoding. |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
667 * The weighting is missing as well, but it's missing from the decoding |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
668 * step also -- so at least we're on the same page with decoder ;-) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
669 */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
670 static inline void dv_encode_video_segment(DVVideoDecodeContext *s, |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
671 uint8_t *dif, |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
672 const uint16_t *mb_pos_ptr) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
673 { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
674 int mb_index, i, j, v; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
675 int mb_x, mb_y, c_offset, linesize; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
676 uint8_t* y_ptr; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
677 uint8_t* data; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
678 int do_edge_wrap; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
679 DCTELEM *block; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
680 EncBlockInfo enc_blks[5*6]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
681 EncBlockInfo* enc_blk; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
682 int free_vs_bits; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
683 int extra_bits; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
684 PutBitContext extra_vs; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
685 uint8_t extra_vs_data[5*6*128]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
686 uint8_t extra_mb_data[6*128]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
687 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
688 int QNO = 15; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
689 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
690 /* Stage 1 -- doing DCT on 5 MBs */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
691 block = &s->block[0][0]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
692 for(mb_index = 0; mb_index < 5; mb_index++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
693 v = *mb_pos_ptr++; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
694 mb_x = v & 0xff; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
695 mb_y = v >> 8; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
696 y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 8); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
697 c_offset = (s->sys->pix_fmt == PIX_FMT_YUV411P) ? |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
698 ((mb_y * s->picture.linesize[1] * 8) + ((mb_x >> 2) * 8)) : |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
699 (((mb_y >> 1) * s->picture.linesize[1] * 8) + ((mb_x >> 1) * 8)); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
700 do_edge_wrap = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
701 for(j = 0;j < 6; j++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
702 if (j < 4) { /* Four Y blocks */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
703 /* NOTE: at end of line, the macroblock is handled as 420 */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
704 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
705 data = y_ptr + (j * 8); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
706 } else { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
707 data = y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->picture.linesize[0]); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
708 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
709 linesize = s->picture.linesize[0]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
710 } else { /* Cr and Cb blocks */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
711 /* don't ask Fabrice why they inverted Cb and Cr ! */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
712 data = s->picture.data[6 - j] + c_offset; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
713 linesize = s->picture.linesize[6 - j]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
714 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
715 do_edge_wrap = 1; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
716 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
717 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
718 /* Everything is set up -- now just copy data -> DCT block */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
719 if (do_edge_wrap) { /* Edge wrap copy: 4x16 -> 8x8 */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
720 uint8_t* d; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
721 DCTELEM *b = block; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
722 for (i=0;i<8;i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
723 d = data + 8 * linesize; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
724 b[0] = data[0]; b[1] = data[1]; b[2] = data[2]; b[3] = data[3]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
725 b[4] = d[0]; b[5] = d[1]; b[6] = d[2]; b[7] = d[3]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
726 data += linesize; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
727 b += 8; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
728 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
729 } else { /* Simple copy: 8x8 -> 8x8 */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
730 s->get_pixels(block, data, linesize); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
731 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
732 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
733 s->fdct(block); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
734 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
735 block += 64; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
736 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
737 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
738 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
739 /* Stage 2 -- setup for encoding phase */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
740 enc_blk = &enc_blks[0]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
741 block = &s->block[0][0]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
742 for (i=0; i<5; i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
743 for (j=0; j<6; j++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
744 enc_blk->mb = block; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
745 enc_blk->dct_mode = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
746 enc_blk->block_size = block_sizes[j]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
747 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
748 dv_set_class_number(enc_blk, j/4*(j%2)); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
749 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
750 block += 64; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
751 enc_blk++; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
752 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
753 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
754 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
755 /* Stage 3 -- encoding by trial-and-error */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
756 encode_vs: |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
757 enc_blk = &enc_blks[0]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
758 for (i=0; i<5; i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
759 uint8_t* p = dif + i*80 + 4; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
760 for (j=0; j<6; j++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
761 enc_blk->qno = QNO; |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1507
diff
changeset
|
762 init_put_bits(&enc_blk->pb, p, block_sizes[j]/8); |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
763 enc_blk++; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
764 p += block_sizes[j]/8; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
765 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
766 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
767 |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1507
diff
changeset
|
768 init_put_bits(&extra_vs, extra_vs_data, sizeof(extra_vs_data)); |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
769 free_vs_bits = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
770 enc_blk = &enc_blks[0]; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
771 for (i=0; i<5; i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
772 PutBitContext extra_mb; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
773 EncBlockInfo* enc_blk2 = enc_blk; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
774 int free_mb_bits = 0; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
775 |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1507
diff
changeset
|
776 init_put_bits(&extra_mb, extra_mb_data, sizeof(extra_mb_data)); |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
777 dif[i*80 + 3] = enc_blk->qno; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
778 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
779 for (j=0; j<6; j++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
780 uint16_t dc = ((enc_blk->mb[0] >> 3) - 1024) >> 2; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
781 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
782 put_bits(&enc_blk->pb, 9, dc); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
783 put_bits(&enc_blk->pb, 1, enc_blk->dct_mode); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
784 put_bits(&enc_blk->pb, 2, enc_blk->cno); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
785 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
786 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
787 printf("[%d, %d]: ", i, j); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
788 #endif |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
789 dv_encode_ac(enc_blk, &extra_mb); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
790 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
791 printf("\n"); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
792 #endif |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
793 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
794 free_mb_bits += dv_bits_left(enc_blk); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
795 enc_blk++; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
796 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
797 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
798 /* We can't flush extra_mb just yet -- since it'll round up bit number */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
799 extra_bits = get_bit_count(&extra_mb); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
800 if (free_mb_bits > extra_bits) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
801 free_vs_bits += free_mb_bits - extra_bits; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
802 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
803 if (extra_bits) { /* FIXME: speed up things when free_mb_bits == 0 */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
804 flush_put_bits(&extra_mb); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
805 dv_redistr_bits(enc_blk2, 6, extra_mb_data, extra_bits, &extra_vs); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
806 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
807 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
808 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
809 /* We can't flush extra_mb just yet -- since it'll round up bit number */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
810 extra_bits = get_bit_count(&extra_vs); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
811 if (extra_bits > free_vs_bits && QNO) { /* FIXME: very crude trial-and-error */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
812 QNO--; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
813 goto encode_vs; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
814 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
815 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
816 if (extra_bits) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
817 flush_put_bits(&extra_vs); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
818 dv_redistr_bits(&enc_blks[0], 5*6, extra_vs_data, extra_bits, NULL); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
819 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
820 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
821 for (i=0; i<6*5; i++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
822 flush_put_bits(&enc_blks[i].pb); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
823 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
824 printf("[%d:%d] qno=%d cno=%d\n", i/6, i%6, enc_blks[i].qno, enc_blks[i].cno); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
825 #endif |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
826 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
827 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
828 |
723 | 829 /* NOTE: exactly one frame must be given (120000 bytes for NTSC, |
830 144000 bytes for PAL) */ | |
831 static int dvvideo_decode_frame(AVCodecContext *avctx, | |
832 void *data, int *data_size, | |
1064 | 833 uint8_t *buf, int buf_size) |
723 | 834 { |
835 DVVideoDecodeContext *s = avctx->priv_data; | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
836 int ds, vs; |
1064 | 837 const uint16_t *mb_pos_ptr; |
723 | 838 |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
839 s->sys = dv_frame_profile(buf); |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
840 if (!s->sys || buf_size < s->sys->frame_size) |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
841 return -1; /* NOTE: we only accept several full frames */ |
723 | 842 |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
843 |
1228 | 844 if(s->picture.data[0]) |
845 avctx->release_buffer(avctx, &s->picture); | |
846 | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
847 s->picture.reference = 0; |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
848 avctx->pix_fmt = s->sys->pix_fmt; |
1507 | 849 avctx->width = s->sys->width; |
850 avctx->height = s->sys->height; | |
903 | 851 if(avctx->get_buffer(avctx, &s->picture) < 0) { |
852 fprintf(stderr, "get_buffer() failed\n"); | |
853 return -1; | |
835 | 854 } |
855 | |
723 | 856 /* for each DIF segment */ |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
857 mb_pos_ptr = s->sys->video_place; |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
858 for (ds = 0; ds < s->sys->difseg_size; ds++) { |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
859 buf += 6 * 80; /* skip DIF segment header */ |
723 | 860 |
861 for(vs = 0; vs < 27; vs++) { | |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
862 if ((vs % 3) == 0) |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
863 buf += 80; /* skip audio block */ |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
864 |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
865 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
866 printf("********************* %d, %d **********************\n", ds, vs); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
867 #endif |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
868 dv_decode_video_segment(s, buf, mb_pos_ptr); |
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
869 buf += 5 * 80; |
723 | 870 mb_pos_ptr += 5; |
871 } | |
872 } | |
873 | |
734
2d6b3e3d6c6f
10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents:
733
diff
changeset
|
874 emms_c(); |
2d6b3e3d6c6f
10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents:
733
diff
changeset
|
875 |
723 | 876 /* return image */ |
925 | 877 *data_size = sizeof(AVFrame); |
878 *(AVFrame*)data= s->picture; | |
903 | 879 |
1489
337d13aee605
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
1416
diff
changeset
|
880 return s->sys->frame_size; |
723 | 881 } |
882 | |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
883 static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size, |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
884 void *data) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
885 { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
886 DVVideoDecodeContext *s = c->priv_data; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
887 const uint16_t *mb_pos_ptr; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
888 int ds, vs; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
889 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
890 s->sys = dv_codec_profile(c); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
891 if (!s->sys) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
892 return -1; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
893 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
894 c->pix_fmt = s->sys->pix_fmt; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
895 s->picture = *((AVFrame *)data); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
896 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
897 /* for each DIF segment */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
898 mb_pos_ptr = s->sys->video_place; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
899 for (ds = 0; ds < s->sys->difseg_size; ds++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
900 buf += 6 * 80; /* skip DIF segment header */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
901 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
902 for(vs = 0; vs < 27; vs++) { |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
903 if ((vs % 3) == 0) |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
904 buf += 80; /* skip audio block */ |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
905 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
906 #ifdef VLC_DEBUG |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
907 printf("********************* %d, %d **********************\n", ds, vs); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
908 #endif |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
909 dv_encode_video_segment(s, buf, mb_pos_ptr); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
910 buf += 5 * 80; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
911 mb_pos_ptr += 5; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
912 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
913 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
914 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
915 emms_c(); |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
916 return s->sys->frame_size; |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
917 } |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
918 |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
919 static int dvvideo_end(AVCodecContext *avctx) |
723 | 920 { |
1214 | 921 avcodec_default_free_buffers(avctx); |
723 | 922 return 0; |
923 } | |
924 | |
925 AVCodec dvvideo_decoder = { | |
926 "dvvideo", | |
927 CODEC_TYPE_VIDEO, | |
928 CODEC_ID_DVVIDEO, | |
929 sizeof(DVVideoDecodeContext), | |
1493
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
930 dvvideo_init, |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
931 dvvideo_encode_frame, |
ad7e62df9962
* preAlpha DV encoding support -- there's still a truckload
romansh
parents:
1489
diff
changeset
|
932 dvvideo_end, |
723 | 933 dvvideo_decode_frame, |
835 | 934 CODEC_CAP_DR1, |
723 | 935 NULL |
936 }; |