Mercurial > libavcodec.hg
annotate dv.c @ 743:4cf7173a004e libavcodec
removed unused variables
author | bellard |
---|---|
date | Fri, 11 Oct 2002 13:49:16 +0000 |
parents | 044307862b4b |
children | 9cec9eab681f |
rev | line source |
---|---|
723 | 1 /* |
2 * DV decoder | |
3 * Copyright (c) 2002 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avcodec.h" | |
20 #include "dsputil.h" | |
21 #include "mpegvideo.h" | |
22 #include "simple_idct.h" | |
23 | |
24 #define NTSC_FRAME_SIZE 120000 | |
25 #define PAL_FRAME_SIZE 144000 | |
26 | |
27 #define TEX_VLC_BITS 9 | |
28 | |
29 typedef struct DVVideoDecodeContext { | |
30 AVCodecContext *avctx; | |
31 GetBitContext gb; | |
32 VLC *vlc; | |
33 int sampling_411; /* 0 = 420, 1 = 411 */ | |
34 int width, height; | |
35 UINT8 *current_picture[3]; /* picture structure */ | |
36 int linesize[3]; | |
37 DCTELEM block[5*6][64] __align8; | |
38 UINT8 dv_zigzag[2][64]; | |
725 | 39 UINT8 idct_permutation[64]; |
723 | 40 /* XXX: move it to static storage ? */ |
725 | 41 UINT8 dv_shift[2][22][64]; |
723 | 42 void (*idct_put[2])(UINT8 *dest, int line_size, DCTELEM *block); |
43 } DVVideoDecodeContext; | |
44 | |
45 #include "dvdata.h" | |
46 | |
47 static VLC dv_vlc; | |
48 /* XXX: also include quantization */ | |
49 static RL_VLC_ELEM *dv_rl_vlc[1]; | |
50 | |
51 static void dv_build_unquantize_tables(DVVideoDecodeContext *s) | |
52 { | |
725 | 53 int i, q, j; |
723 | 54 |
55 /* NOTE: max left shift is 6 */ | |
725 | 56 for(q = 0; q < 22; q++) { |
57 /* 88 unquant */ | |
58 for(i = 1; i < 64; i++) { | |
59 /* 88 table */ | |
60 j = s->idct_permutation[i]; | |
61 s->dv_shift[0][q][j] = | |
62 dv_quant_shifts[q][dv_88_areas[i]] + 1; | |
63 } | |
64 | |
65 /* 248 unquant */ | |
66 for(i = 1; i < 64; i++) { | |
67 /* 248 table */ | |
68 s->dv_shift[1][q][i] = | |
69 dv_quant_shifts[q][dv_248_areas[i]] + 1; | |
723 | 70 } |
71 } | |
72 } | |
73 | |
74 static int dvvideo_decode_init(AVCodecContext *avctx) | |
75 { | |
76 DVVideoDecodeContext *s = avctx->priv_data; | |
725 | 77 MpegEncContext s2; |
723 | 78 static int done; |
79 | |
80 if (!done) { | |
81 int i; | |
82 | |
83 done = 1; | |
84 | |
85 /* NOTE: as a trick, we use the fact the no codes are unused | |
86 to accelerate the parsing of partial codes */ | |
87 init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC, | |
88 dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2); | |
89 | |
90 dv_rl_vlc[0] = av_malloc(dv_vlc.table_size * sizeof(RL_VLC_ELEM)); | |
91 for(i = 0; i < dv_vlc.table_size; i++){ | |
92 int code= dv_vlc.table[i][0]; | |
93 int len = dv_vlc.table[i][1]; | |
94 int level, run; | |
95 | |
96 if(len<0){ //more bits needed | |
97 run= 0; | |
98 level= code; | |
99 } else if (code == (NB_DV_VLC - 1)) { | |
100 /* EOB */ | |
101 run = 0; | |
102 level = 256; | |
103 } else { | |
104 run= dv_vlc_run[code] + 1; | |
105 level= dv_vlc_level[code]; | |
106 } | |
107 dv_rl_vlc[0][i].len = len; | |
108 dv_rl_vlc[0][i].level = level; | |
109 dv_rl_vlc[0][i].run = run; | |
110 } | |
111 } | |
725 | 112 |
113 /* ugly way to get the idct & scantable */ | |
114 /* XXX: fix it */ | |
115 memset(&s2, 0, sizeof(MpegEncContext)); | |
116 s2.avctx = 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
|
117 if (DCT_common_init(&s2) < 0) |
725 | 118 return -1; |
119 | |
120 s->idct_put[0] = s2.idct_put; | |
121 memcpy(s->idct_permutation, s2.idct_permutation, 64); | |
122 memcpy(s->dv_zigzag[0], s2.intra_scantable.permutated, 64); | |
123 | |
124 /* XXX: use MMX also for idct248 */ | |
125 s->idct_put[1] = simple_idct248_put; | |
126 memcpy(s->dv_zigzag[1], dv_248_zigzag, 64); | |
127 | |
723 | 128 /* XXX: do it only for constant case */ |
129 dv_build_unquantize_tables(s); | |
130 | |
131 return 0; | |
132 } | |
133 | |
134 //#define VLC_DEBUG | |
135 | |
725 | 136 typedef struct BlockInfo { |
137 const UINT8 *shift_table; | |
138 const UINT8 *scan_table; | |
139 UINT8 pos; /* position in block */ | |
140 UINT8 eob_reached; /* true if EOB has been reached */ | |
141 UINT8 dct_mode; | |
142 UINT8 partial_bit_count; | |
143 UINT16 partial_bit_buffer; | |
144 int shift_offset; | |
145 } BlockInfo; | |
723 | 146 |
147 /* block size in bits */ | |
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
|
148 static const UINT16 block_sizes[6] = { |
723 | 149 112, 112, 112, 112, 80, 80 |
150 }; | |
151 | |
152 #ifndef ALT_BITSTREAM_READER | |
153 #error only works with ALT_BITSTREAM_READER | |
154 #endif | |
155 | |
156 /* decode ac coefs */ | |
157 static void dv_decode_ac(DVVideoDecodeContext *s, | |
725 | 158 BlockInfo *mb, INT16 *block, int last_index) |
723 | 159 { |
160 int last_re_index; | |
725 | 161 int shift_offset = mb->shift_offset; |
162 const UINT8 *scan_table = mb->scan_table; | |
163 const UINT8 *shift_table = mb->shift_table; | |
164 int pos = mb->pos; | |
723 | 165 int level, pos1, sign, run; |
166 int partial_bit_count; | |
167 | |
168 OPEN_READER(re, &s->gb); | |
169 | |
170 #ifdef VLC_DEBUG | |
725 | 171 printf("start\n"); |
723 | 172 #endif |
173 | |
174 /* if we must parse a partial vlc, we do it here */ | |
725 | 175 partial_bit_count = mb->partial_bit_count; |
723 | 176 if (partial_bit_count > 0) { |
177 UINT8 buf[4]; | |
178 UINT32 v; | |
179 int l, l1; | |
180 GetBitContext gb1; | |
181 | |
182 /* build the dummy bit buffer */ | |
183 l = 16 - partial_bit_count; | |
184 UPDATE_CACHE(re, &s->gb); | |
185 #ifdef VLC_DEBUG | |
186 printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16)); | |
187 #endif | |
725 | 188 v = (mb->partial_bit_buffer << l) | SHOW_UBITS(re, &s->gb, l); |
723 | 189 buf[0] = v >> 8; |
190 buf[1] = v; | |
191 #ifdef VLC_DEBUG | |
192 printf("v=%04x cnt=%d %04x\n", | |
725 | 193 v, partial_bit_count, (mb->partial_bit_buffer << l)); |
723 | 194 #endif |
195 /* try to read the codeword */ | |
196 init_get_bits(&gb1, buf, 4); | |
197 { | |
198 OPEN_READER(re1, &gb1); | |
199 UPDATE_CACHE(re1, &gb1); | |
200 GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0], | |
201 TEX_VLC_BITS, 2); | |
202 l = re1_index; | |
203 CLOSE_READER(re1, &gb1); | |
204 } | |
205 #ifdef VLC_DEBUG | |
206 printf("****run=%d level=%d size=%d\n", run, level, l); | |
207 #endif | |
208 /* compute codeword length */ | |
209 l1 = (level != 256 && level != 0); | |
210 /* if too long, we cannot parse */ | |
211 l -= partial_bit_count; | |
212 if ((re_index + l + l1) > last_index) | |
213 return; | |
214 /* skip read bits */ | |
215 last_re_index = 0; /* avoid warning */ | |
216 re_index += l; | |
725 | 217 /* by definition, if we can read the vlc, all partial bits |
723 | 218 will be read (otherwise we could have read the vlc before) */ |
725 | 219 mb->partial_bit_count = 0; |
723 | 220 UPDATE_CACHE(re, &s->gb); |
221 goto handle_vlc; | |
222 } | |
223 | |
224 /* get the AC coefficients until last_index is reached */ | |
225 for(;;) { | |
226 UPDATE_CACHE(re, &s->gb); | |
227 #ifdef VLC_DEBUG | |
228 printf("%2d: bits=%04x index=%d\n", | |
229 pos, SHOW_UBITS(re, &s->gb, 16), re_index); | |
230 #endif | |
231 last_re_index = re_index; | |
232 GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0], | |
233 TEX_VLC_BITS, 2); | |
234 handle_vlc: | |
235 #ifdef VLC_DEBUG | |
236 printf("run=%d level=%d\n", run, level); | |
237 #endif | |
238 if (level == 256) { | |
239 if (re_index > last_index) { | |
240 cannot_read: | |
241 /* put position before read code */ | |
242 re_index = last_re_index; | |
725 | 243 mb->eob_reached = 0; |
723 | 244 break; |
245 } | |
246 /* EOB */ | |
725 | 247 mb->eob_reached = 1; |
723 | 248 break; |
249 } else if (level != 0) { | |
250 if ((re_index + 1) > last_index) | |
251 goto cannot_read; | |
252 sign = SHOW_SBITS(re, &s->gb, 1); | |
253 level = (level ^ sign) - sign; | |
254 LAST_SKIP_BITS(re, &s->gb, 1); | |
255 pos += run; | |
256 /* error */ | |
257 if (pos >= 64) { | |
258 goto read_error; | |
259 } | |
260 pos1 = scan_table[pos]; | |
725 | 261 level = level << (shift_table[pos1] + shift_offset); |
723 | 262 block[pos1] = level; |
263 // printf("run=%d level=%d shift=%d\n", run, level, shift_table[pos1]); | |
264 } else { | |
265 if (re_index > last_index) | |
266 goto cannot_read; | |
267 /* level is zero: means run without coding. No | |
268 sign is coded */ | |
269 pos += run; | |
270 /* error */ | |
271 if (pos >= 64) { | |
272 read_error: | |
273 #if defined(VLC_DEBUG) || 1 | |
274 printf("error pos=%d\n", pos); | |
275 #endif | |
276 /* for errors, we consider the eob is reached */ | |
725 | 277 mb->eob_reached = 1; |
723 | 278 break; |
279 } | |
280 } | |
281 } | |
282 CLOSE_READER(re, &s->gb); | |
725 | 283 mb->pos = pos; |
723 | 284 } |
285 | |
286 static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left) | |
287 { | |
288 while (bits_left >= 16) { | |
289 put_bits(pb, 16, get_bits(gb, 16)); | |
290 bits_left -= 16; | |
291 } | |
292 if (bits_left > 0) { | |
293 put_bits(pb, bits_left, get_bits(gb, bits_left)); | |
294 } | |
295 } | |
296 | |
297 /* mb_x and mb_y are in units of 8 pixels */ | |
298 static inline void dv_decode_video_segment(DVVideoDecodeContext *s, | |
299 UINT8 *buf_ptr1, | |
300 const UINT16 *mb_pos_ptr) | |
301 { | |
302 int quant, dc, dct_mode, class1, j; | |
303 int mb_index, mb_x, mb_y, v, last_index; | |
304 DCTELEM *block, *block1; | |
305 int c_offset, bits_left; | |
306 UINT8 *y_ptr; | |
725 | 307 BlockInfo mb_data[5 * 6], *mb, *mb1; |
723 | 308 void (*idct_put)(UINT8 *dest, int line_size, DCTELEM *block); |
309 UINT8 *buf_ptr; | |
310 PutBitContext pb, vs_pb; | |
725 | 311 UINT8 mb_bit_buffer[80 + 4]; /* allow some slack */ |
312 int mb_bit_count; | |
313 UINT8 vs_bit_buffer[5 * 80 + 4]; /* allow some slack */ | |
723 | 314 int vs_bit_count; |
315 | |
316 memset(s->block, 0, sizeof(s->block)); | |
317 | |
318 /* pass 1 : read DC and AC coefficients in blocks */ | |
319 buf_ptr = buf_ptr1; | |
320 block1 = &s->block[0][0]; | |
725 | 321 mb1 = mb_data; |
723 | 322 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80, NULL, NULL); |
323 vs_bit_count = 0; | |
324 for(mb_index = 0; mb_index < 5; mb_index++) { | |
325 /* skip header */ | |
326 quant = buf_ptr[3] & 0x0f; | |
327 buf_ptr += 4; | |
725 | 328 init_put_bits(&pb, mb_bit_buffer, 80, NULL, NULL); |
329 mb_bit_count = 0; | |
330 mb = mb1; | |
723 | 331 block = block1; |
332 for(j = 0;j < 6; j++) { | |
333 /* NOTE: size is not important here */ | |
334 init_get_bits(&s->gb, buf_ptr, 14); | |
335 | |
336 /* get the dc */ | |
337 dc = get_bits(&s->gb, 9); | |
338 dc = (dc << (32 - 9)) >> (32 - 9); | |
339 dct_mode = get_bits1(&s->gb); | |
725 | 340 mb->dct_mode = dct_mode; |
341 mb->scan_table = s->dv_zigzag[dct_mode]; | |
723 | 342 class1 = get_bits(&s->gb, 2); |
725 | 343 mb->shift_offset = (class1 == 3); |
344 mb->shift_table = s->dv_shift[dct_mode] | |
723 | 345 [quant + dv_quant_offset[class1]]; |
346 dc = dc << 2; | |
347 /* convert to unsigned because 128 is not added in the | |
348 standard IDCT */ | |
349 dc += 1024; | |
350 block[0] = dc; | |
351 last_index = block_sizes[j]; | |
352 buf_ptr += last_index >> 3; | |
725 | 353 mb->pos = 0; |
354 mb->partial_bit_count = 0; | |
723 | 355 |
725 | 356 dv_decode_ac(s, mb, block, last_index); |
723 | 357 |
358 /* write the remaining bits in a new buffer only if the | |
359 block is finished */ | |
360 bits_left = last_index - s->gb.index; | |
725 | 361 if (mb->eob_reached) { |
362 mb->partial_bit_count = 0; | |
363 mb_bit_count += bits_left; | |
723 | 364 bit_copy(&pb, &s->gb, bits_left); |
365 } else { | |
366 /* should be < 16 bits otherwise a codeword could have | |
367 been parsed */ | |
725 | 368 mb->partial_bit_count = bits_left; |
369 mb->partial_bit_buffer = get_bits(&s->gb, bits_left); | |
723 | 370 } |
371 block += 64; | |
725 | 372 mb++; |
723 | 373 } |
374 | |
375 flush_put_bits(&pb); | |
376 | |
377 /* pass 2 : we can do it just after */ | |
378 #ifdef VLC_DEBUG | |
725 | 379 printf("***pass 2 size=%d\n", mb_bit_count); |
723 | 380 #endif |
381 block = block1; | |
725 | 382 mb = mb1; |
383 init_get_bits(&s->gb, mb_bit_buffer, 80); | |
723 | 384 for(j = 0;j < 6; j++) { |
725 | 385 if (!mb->eob_reached && s->gb.index < mb_bit_count) { |
386 dv_decode_ac(s, mb, block, mb_bit_count); | |
723 | 387 /* if still not finished, no need to parse other blocks */ |
725 | 388 if (!mb->eob_reached) { |
723 | 389 /* we could not parse the current AC coefficient, |
390 so we add the remaining bytes */ | |
725 | 391 bits_left = mb_bit_count - s->gb.index; |
723 | 392 if (bits_left > 0) { |
725 | 393 mb->partial_bit_count += bits_left; |
394 mb->partial_bit_buffer = | |
395 (mb->partial_bit_buffer << bits_left) | | |
723 | 396 get_bits(&s->gb, bits_left); |
397 } | |
398 goto next_mb; | |
399 } | |
400 } | |
401 block += 64; | |
725 | 402 mb++; |
723 | 403 } |
404 /* all blocks are finished, so the extra bytes can be used at | |
405 the video segment level */ | |
725 | 406 bits_left = mb_bit_count - s->gb.index; |
723 | 407 vs_bit_count += bits_left; |
408 bit_copy(&vs_pb, &s->gb, bits_left); | |
409 next_mb: | |
725 | 410 mb1 += 6; |
723 | 411 block1 += 6 * 64; |
412 } | |
413 | |
414 /* we need a pass other the whole video segment */ | |
415 flush_put_bits(&vs_pb); | |
416 | |
417 #ifdef VLC_DEBUG | |
418 printf("***pass 3 size=%d\n", vs_bit_count); | |
419 #endif | |
420 block = &s->block[0][0]; | |
421 mb = mb_data; | |
422 init_get_bits(&s->gb, vs_bit_buffer, 5 * 80); | |
423 for(mb_index = 0; mb_index < 5; mb_index++) { | |
424 for(j = 0;j < 6; j++) { | |
725 | 425 if (!mb->eob_reached) { |
723 | 426 #ifdef VLC_DEBUG |
427 printf("start %d:%d\n", mb_index, j); | |
428 #endif | |
725 | 429 dv_decode_ac(s, mb, block, vs_bit_count); |
723 | 430 } |
431 block += 64; | |
725 | 432 mb++; |
723 | 433 } |
434 } | |
435 | |
436 /* compute idct and place blocks */ | |
437 block = &s->block[0][0]; | |
438 mb = mb_data; | |
439 for(mb_index = 0; mb_index < 5; mb_index++) { | |
440 v = *mb_pos_ptr++; | |
441 mb_x = v & 0xff; | |
442 mb_y = v >> 8; | |
443 y_ptr = s->current_picture[0] + (mb_y * s->linesize[0] * 8) + (mb_x * 8); | |
444 if (s->sampling_411) | |
445 c_offset = (mb_y * s->linesize[1] * 8) + ((mb_x >> 2) * 8); | |
446 else | |
447 c_offset = ((mb_y >> 1) * s->linesize[1] * 8) + ((mb_x >> 1) * 8); | |
448 for(j = 0;j < 6; j++) { | |
725 | 449 idct_put = s->idct_put[mb->dct_mode]; |
723 | 450 if (j < 4) { |
737 | 451 if (s->sampling_411 && mb_x < (704 / 8)) { |
452 /* NOTE: at end of line, the macroblock is handled as 420 */ | |
723 | 453 idct_put(y_ptr + (j * 8), s->linesize[0], block); |
454 } else { | |
455 idct_put(y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->linesize[0]), | |
456 s->linesize[0], block); | |
457 } | |
458 } else { | |
737 | 459 if (s->sampling_411 && mb_x >= (704 / 8)) { |
460 uint8_t pixels[64], *c_ptr, *c_ptr1, *ptr; | |
461 int y, linesize; | |
462 /* NOTE: at end of line, the macroblock is handled as 420 */ | |
463 idct_put(pixels, 8, block); | |
464 linesize = s->linesize[6 - j]; | |
465 c_ptr = s->current_picture[6 - j] + c_offset; | |
466 ptr = pixels; | |
467 for(y = 0;y < 8; y++) { | |
468 /* convert to 411P */ | |
469 c_ptr1 = c_ptr + linesize; | |
470 c_ptr1[0] = c_ptr[0] = (ptr[0] + ptr[1]) >> 1; | |
471 c_ptr1[1] = c_ptr[1] = (ptr[2] + ptr[3]) >> 1; | |
472 c_ptr1[2] = c_ptr[2] = (ptr[4] + ptr[5]) >> 1; | |
473 c_ptr1[3] = c_ptr[3] = (ptr[6] + ptr[7]) >> 1; | |
474 c_ptr += linesize * 2; | |
475 ptr += 8; | |
476 } | |
477 } else { | |
478 /* don't ask me why they inverted Cb and Cr ! */ | |
479 idct_put(s->current_picture[6 - j] + c_offset, | |
480 s->linesize[6 - j], block); | |
481 } | |
723 | 482 } |
483 block += 64; | |
725 | 484 mb++; |
723 | 485 } |
486 } | |
487 } | |
488 | |
489 | |
490 /* NOTE: exactly one frame must be given (120000 bytes for NTSC, | |
491 144000 bytes for PAL) */ | |
492 static int dvvideo_decode_frame(AVCodecContext *avctx, | |
493 void *data, int *data_size, | |
494 UINT8 *buf, int buf_size) | |
495 { | |
496 DVVideoDecodeContext *s = avctx->priv_data; | |
738 | 497 int sct, dsf, apt, ds, nb_dif_segs, vs, size, width, height, i, packet_size; |
723 | 498 UINT8 *buf_ptr; |
499 const UINT16 *mb_pos_ptr; | |
500 AVPicture *picture; | |
501 | |
502 /* parse id */ | |
503 init_get_bits(&s->gb, buf, buf_size); | |
504 sct = get_bits(&s->gb, 3); | |
505 if (sct != 0) | |
506 return -1; | |
507 skip_bits(&s->gb, 5); | |
508 get_bits(&s->gb, 4); /* dsn (sequence number */ | |
509 get_bits(&s->gb, 1); /* fsc (channel number) */ | |
510 skip_bits(&s->gb, 3); | |
511 get_bits(&s->gb, 8); /* dbn (diff block number 0-134) */ | |
512 | |
513 dsf = get_bits(&s->gb, 1); /* 0 = NTSC 1 = PAL */ | |
514 if (get_bits(&s->gb, 1) != 0) | |
515 return -1; | |
516 skip_bits(&s->gb, 11); | |
517 apt = get_bits(&s->gb, 3); /* apt */ | |
518 | |
519 get_bits(&s->gb, 1); /* tf1 */ | |
520 skip_bits(&s->gb, 4); | |
521 get_bits(&s->gb, 3); /* ap1 */ | |
522 | |
523 get_bits(&s->gb, 1); /* tf2 */ | |
524 skip_bits(&s->gb, 4); | |
525 get_bits(&s->gb, 3); /* ap2 */ | |
526 | |
527 get_bits(&s->gb, 1); /* tf3 */ | |
528 skip_bits(&s->gb, 4); | |
529 get_bits(&s->gb, 3); /* ap3 */ | |
530 | |
531 /* init size */ | |
532 width = 720; | |
533 if (dsf) { | |
738 | 534 packet_size = PAL_FRAME_SIZE; |
723 | 535 height = 576; |
536 nb_dif_segs = 12; | |
537 } else { | |
738 | 538 packet_size = NTSC_FRAME_SIZE; |
723 | 539 height = 480; |
540 nb_dif_segs = 10; | |
541 } | |
738 | 542 /* NOTE: we only accept several full frames */ |
543 if (buf_size < packet_size) | |
544 return -1; | |
545 | |
733 | 546 /* XXX: is it correct to assume that 420 is always used in PAL |
547 mode ? */ | |
548 s->sampling_411 = !dsf; | |
549 if (s->sampling_411) | |
550 mb_pos_ptr = dv_place_411; | |
551 else | |
552 mb_pos_ptr = dv_place_420; | |
553 | |
723 | 554 /* (re)alloc picture if needed */ |
555 if (s->width != width || s->height != height) { | |
556 for(i=0;i<3;i++) | |
557 av_freep(&s->current_picture[i]); | |
558 for(i=0;i<3;i++) { | |
559 size = width * height; | |
560 s->linesize[i] = width; | |
561 if (i >= 1) { | |
562 size >>= 2; | |
733 | 563 s->linesize[i] >>= s->sampling_411 ? 2 : 1; |
723 | 564 } |
565 s->current_picture[i] = av_malloc(size); | |
566 if (!s->current_picture[i]) | |
567 return -1; | |
568 } | |
569 s->width = width; | |
570 s->height = height; | |
571 } | |
572 | |
573 /* for each DIF segment */ | |
574 buf_ptr = buf; | |
575 for (ds = 0; ds < nb_dif_segs; ds++) { | |
576 buf_ptr += 6 * 80; /* skip DIF segment header */ | |
577 | |
578 for(vs = 0; vs < 27; vs++) { | |
579 if ((vs % 3) == 0) { | |
580 /* skip audio block */ | |
581 buf_ptr += 80; | |
582 } | |
583 dv_decode_video_segment(s, buf_ptr, mb_pos_ptr); | |
584 buf_ptr += 5 * 80; | |
585 mb_pos_ptr += 5; | |
586 } | |
587 } | |
588 | |
734
2d6b3e3d6c6f
10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents:
733
diff
changeset
|
589 emms_c(); |
2d6b3e3d6c6f
10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents:
733
diff
changeset
|
590 |
723 | 591 /* return image */ |
592 avctx->width = width; | |
593 avctx->height = height; | |
594 if (s->sampling_411) | |
733 | 595 avctx->pix_fmt = PIX_FMT_YUV411P; |
723 | 596 else |
597 avctx->pix_fmt = PIX_FMT_YUV420P; | |
598 if (dsf) | |
599 avctx->frame_rate = 25 * FRAME_RATE_BASE; | |
600 else | |
601 avctx->frame_rate = 30 * FRAME_RATE_BASE; | |
602 *data_size = sizeof(AVPicture); | |
603 picture = data; | |
604 for(i=0;i<3;i++) { | |
605 picture->data[i] = s->current_picture[i]; | |
606 picture->linesize[i] = s->linesize[i]; | |
607 } | |
738 | 608 return packet_size; |
723 | 609 } |
610 | |
611 static int dvvideo_decode_end(AVCodecContext *avctx) | |
612 { | |
613 DVVideoDecodeContext *s = avctx->priv_data; | |
614 int i; | |
615 | |
616 for(i=0;i<3;i++) | |
617 av_freep(&s->current_picture[i]); | |
618 return 0; | |
619 } | |
620 | |
621 AVCodec dvvideo_decoder = { | |
622 "dvvideo", | |
623 CODEC_TYPE_VIDEO, | |
624 CODEC_ID_DVVIDEO, | |
625 sizeof(DVVideoDecodeContext), | |
626 dvvideo_decode_init, | |
627 NULL, | |
628 dvvideo_decode_end, | |
629 dvvideo_decode_frame, | |
630 0, | |
631 NULL | |
632 }; | |
633 | |
634 typedef struct DVAudioDecodeContext { | |
635 AVCodecContext *avctx; | |
636 GetBitContext gb; | |
637 | |
638 } DVAudioDecodeContext; | |
639 | |
640 static int dvaudio_decode_init(AVCodecContext *avctx) | |
641 { | |
642 // DVAudioDecodeContext *s = avctx->priv_data; | |
643 return 0; | |
644 } | |
645 | |
646 /* NOTE: exactly one frame must be given (120000 bytes for NTSC, | |
647 144000 bytes for PAL) */ | |
648 static int dvaudio_decode_frame(AVCodecContext *avctx, | |
649 void *data, int *data_size, | |
650 UINT8 *buf, int buf_size) | |
651 { | |
652 // DVAudioDecodeContext *s = avctx->priv_data; | |
653 return buf_size; | |
654 } | |
655 | |
656 static int dvaudio_decode_end(AVCodecContext *avctx) | |
657 { | |
658 // DVAudioDecodeContext *s = avctx->priv_data; | |
659 return 0; | |
660 } | |
661 | |
662 AVCodec dvaudio_decoder = { | |
663 "dvaudio", | |
664 CODEC_TYPE_AUDIO, | |
665 CODEC_ID_DVAUDIO, | |
666 sizeof(DVAudioDecodeContext), | |
667 dvaudio_decode_init, | |
668 NULL, | |
669 dvaudio_decode_end, | |
670 dvaudio_decode_frame, | |
671 0, | |
672 NULL | |
673 }; |