You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

696 lines
21KB

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