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.

754 lines
21KB

  1. /*
  2. * Interplay MVE Video Decoder
  3. * Copyright (C) 2003 the ffmpeg project
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavcodec/interplayvideo.c
  23. * Interplay MVE Video Decoder by Mike Melanson (melanson@pcisys.net)
  24. * For more information about the Interplay MVE format, visit:
  25. * http://www.pcisys.net/~melanson/codecs/interplay-mve.txt
  26. * This code is written in such a way that the identifiers match up
  27. * with the encoding descriptions in the document.
  28. *
  29. * This decoder presently only supports a PAL8 output colorspace.
  30. *
  31. * An Interplay video frame consists of 2 parts: The decoding map and
  32. * the video data. A demuxer must load these 2 parts together in a single
  33. * buffer before sending it through the stream to this decoder.
  34. */
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <unistd.h>
  39. #include "avcodec.h"
  40. #include "bytestream.h"
  41. #include "dsputil.h"
  42. #define PALETTE_COUNT 256
  43. /* debugging support */
  44. #define DEBUG_INTERPLAY 0
  45. #if DEBUG_INTERPLAY
  46. #define debug_interplay(x,...) av_log(NULL, AV_LOG_DEBUG, x, __VA_ARGS__)
  47. #else
  48. static inline void debug_interplay(const char *format, ...) { }
  49. #endif
  50. typedef struct IpvideoContext {
  51. AVCodecContext *avctx;
  52. DSPContext dsp;
  53. AVFrame second_last_frame;
  54. AVFrame last_frame;
  55. AVFrame current_frame;
  56. const unsigned char *decoding_map;
  57. int decoding_map_size;
  58. const unsigned char *buf;
  59. int size;
  60. const unsigned char *stream_ptr;
  61. const unsigned char *stream_end;
  62. unsigned char *pixel_ptr;
  63. int line_inc;
  64. int stride;
  65. int upper_motion_limit_offset;
  66. } IpvideoContext;
  67. #define CHECK_STREAM_PTR(n) \
  68. if (s->stream_end - s->stream_ptr < n) { \
  69. av_log(s->avctx, AV_LOG_ERROR, "Interplay video warning: stream_ptr out of bounds (%p >= %p)\n", \
  70. s->stream_ptr + n, s->stream_end); \
  71. return -1; \
  72. }
  73. static int copy_from(IpvideoContext *s, AVFrame *src, int delta_x, int delta_y)
  74. {
  75. int current_offset = s->pixel_ptr - s->current_frame.data[0];
  76. int motion_offset = current_offset + delta_y * s->stride + delta_x;
  77. if (motion_offset < 0) {
  78. av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset < 0 (%d)\n", motion_offset);
  79. return -1;
  80. } else if (motion_offset > s->upper_motion_limit_offset) {
  81. av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset above limit (%d >= %d)\n",
  82. motion_offset, s->upper_motion_limit_offset);
  83. return -1;
  84. }
  85. s->dsp.put_pixels_tab[1][0](s->pixel_ptr, src->data[0] + motion_offset, s->stride, 8);
  86. return 0;
  87. }
  88. static int ipvideo_decode_block_opcode_0x0(IpvideoContext *s)
  89. {
  90. return copy_from(s, &s->last_frame, 0, 0);
  91. }
  92. static int ipvideo_decode_block_opcode_0x1(IpvideoContext *s)
  93. {
  94. return copy_from(s, &s->second_last_frame, 0, 0);
  95. }
  96. static int ipvideo_decode_block_opcode_0x2(IpvideoContext *s)
  97. {
  98. unsigned char B;
  99. int x, y;
  100. /* copy block from 2 frames ago using a motion vector; need 1 more byte */
  101. CHECK_STREAM_PTR(1);
  102. B = *s->stream_ptr++;
  103. if (B < 56) {
  104. x = 8 + (B % 7);
  105. y = B / 7;
  106. } else {
  107. x = -14 + ((B - 56) % 29);
  108. y = 8 + ((B - 56) / 29);
  109. }
  110. debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
  111. return copy_from(s, &s->second_last_frame, x, y);
  112. }
  113. static int ipvideo_decode_block_opcode_0x3(IpvideoContext *s)
  114. {
  115. unsigned char B;
  116. int x, y;
  117. /* copy 8x8 block from current frame from an up/left block */
  118. /* need 1 more byte for motion */
  119. CHECK_STREAM_PTR(1);
  120. B = *s->stream_ptr++;
  121. if (B < 56) {
  122. x = -(8 + (B % 7));
  123. y = -(B / 7);
  124. } else {
  125. x = -(-14 + ((B - 56) % 29));
  126. y = -( 8 + ((B - 56) / 29));
  127. }
  128. debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
  129. return copy_from(s, &s->current_frame, x, y);
  130. }
  131. static int ipvideo_decode_block_opcode_0x4(IpvideoContext *s)
  132. {
  133. int x, y;
  134. unsigned char B, BL, BH;
  135. /* copy a block from the previous frame; need 1 more byte */
  136. CHECK_STREAM_PTR(1);
  137. B = *s->stream_ptr++;
  138. BL = B & 0x0F;
  139. BH = (B >> 4) & 0x0F;
  140. x = -8 + BL;
  141. y = -8 + BH;
  142. debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
  143. return copy_from(s, &s->last_frame, x, y);
  144. }
  145. static int ipvideo_decode_block_opcode_0x5(IpvideoContext *s)
  146. {
  147. signed char x, y;
  148. /* copy a block from the previous frame using an expanded range;
  149. * need 2 more bytes */
  150. CHECK_STREAM_PTR(2);
  151. x = *s->stream_ptr++;
  152. y = *s->stream_ptr++;
  153. debug_interplay (" motion bytes = %d, %d\n", x, y);
  154. return copy_from(s, &s->last_frame, x, y);
  155. }
  156. static int ipvideo_decode_block_opcode_0x6(IpvideoContext *s)
  157. {
  158. /* mystery opcode? skip multiple blocks? */
  159. av_log(s->avctx, AV_LOG_ERROR, " Interplay video: Help! Mystery opcode 0x6 seen\n");
  160. /* report success */
  161. return 0;
  162. }
  163. static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s)
  164. {
  165. int x, y;
  166. unsigned char P[2];
  167. unsigned int flags;
  168. /* 2-color encoding */
  169. CHECK_STREAM_PTR(2);
  170. P[0] = *s->stream_ptr++;
  171. P[1] = *s->stream_ptr++;
  172. if (P[0] <= P[1]) {
  173. /* need 8 more bytes from the stream */
  174. CHECK_STREAM_PTR(8);
  175. for (y = 0; y < 8; y++) {
  176. flags = *s->stream_ptr++ | 0x100;
  177. for (; flags != 1; flags >>= 1) {
  178. *s->pixel_ptr++ = P[flags & 1];
  179. }
  180. s->pixel_ptr += s->line_inc;
  181. }
  182. } else {
  183. /* need 2 more bytes from the stream */
  184. CHECK_STREAM_PTR(2);
  185. flags = bytestream_get_le16(&s->stream_ptr);
  186. for (y = 0; y < 8; y += 2) {
  187. for (x = 0; x < 8; x += 2, flags >>= 1) {
  188. s->pixel_ptr[x ] =
  189. s->pixel_ptr[x + 1 ] =
  190. s->pixel_ptr[x + s->stride] =
  191. s->pixel_ptr[x + 1 + s->stride] = P[flags & 1];
  192. }
  193. s->pixel_ptr += s->stride * 2;
  194. }
  195. }
  196. /* report success */
  197. return 0;
  198. }
  199. static int ipvideo_decode_block_opcode_0x8(IpvideoContext *s)
  200. {
  201. int x, y;
  202. unsigned char P[2];
  203. unsigned int flags = 0;
  204. /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on
  205. * either top and bottom or left and right halves */
  206. CHECK_STREAM_PTR(2);
  207. P[0] = *s->stream_ptr++;
  208. P[1] = *s->stream_ptr++;
  209. if (P[0] <= P[1]) {
  210. CHECK_STREAM_PTR(14);
  211. s->stream_ptr -= 2;
  212. for (y = 0; y < 16; y++) {
  213. // new values for each 4x4 block
  214. if (!(y & 3)) {
  215. P[0] = *s->stream_ptr++; P[1] = *s->stream_ptr++;
  216. flags = bytestream_get_le16(&s->stream_ptr);
  217. }
  218. for (x = 0; x < 4; x++, flags >>= 1) {
  219. *s->pixel_ptr++ = P[flags & 1];
  220. }
  221. s->pixel_ptr += s->stride - 4;
  222. // switch to right half
  223. if (y == 7) s->pixel_ptr -= 8 * s->stride - 4;
  224. }
  225. } else {
  226. /* need 10 more bytes */
  227. CHECK_STREAM_PTR(10);
  228. if (s->stream_ptr[4] <= s->stream_ptr[5]) {
  229. flags = bytestream_get_le32(&s->stream_ptr);
  230. /* vertical split; left & right halves are 2-color encoded */
  231. for (y = 0; y < 16; y++) {
  232. for (x = 0; x < 4; x++, flags >>= 1) {
  233. *s->pixel_ptr++ = P[flags & 1];
  234. }
  235. s->pixel_ptr += s->stride - 4;
  236. // switch to right half
  237. if (y == 7) {
  238. s->pixel_ptr -= 8 * s->stride - 4;
  239. P[0] = *s->stream_ptr++; P[1] = *s->stream_ptr++;
  240. flags = bytestream_get_le32(&s->stream_ptr);
  241. }
  242. }
  243. } else {
  244. /* horizontal split; top & bottom halves are 2-color encoded */
  245. for (y = 0; y < 8; y++) {
  246. if (y == 4) {
  247. P[0] = *s->stream_ptr++;
  248. P[1] = *s->stream_ptr++;
  249. }
  250. flags = *s->stream_ptr++ | 0x100;
  251. for (; flags != 1; flags >>= 1) {
  252. *s->pixel_ptr++ = P[flags & 1];
  253. }
  254. s->pixel_ptr += s->line_inc;
  255. }
  256. }
  257. }
  258. /* report success */
  259. return 0;
  260. }
  261. static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s)
  262. {
  263. int x, y;
  264. unsigned char P[4];
  265. /* 4-color encoding */
  266. CHECK_STREAM_PTR(4);
  267. memcpy(P, s->stream_ptr, 4);
  268. s->stream_ptr += 4;
  269. if (P[0] <= P[1]) {
  270. if (P[2] <= P[3]) {
  271. /* 1 of 4 colors for each pixel, need 16 more bytes */
  272. CHECK_STREAM_PTR(16);
  273. for (y = 0; y < 8; y++) {
  274. /* get the next set of 8 2-bit flags */
  275. int flags = bytestream_get_le16(&s->stream_ptr);
  276. for (x = 0; x < 8; x++, flags >>= 2) {
  277. *s->pixel_ptr++ = P[flags & 0x03];
  278. }
  279. s->pixel_ptr += s->line_inc;
  280. }
  281. } else {
  282. uint32_t flags;
  283. /* 1 of 4 colors for each 2x2 block, need 4 more bytes */
  284. CHECK_STREAM_PTR(4);
  285. flags = bytestream_get_le32(&s->stream_ptr);
  286. for (y = 0; y < 8; y += 2) {
  287. for (x = 0; x < 8; x += 2, flags >>= 2) {
  288. s->pixel_ptr[x ] =
  289. s->pixel_ptr[x + 1 ] =
  290. s->pixel_ptr[x + s->stride] =
  291. s->pixel_ptr[x + 1 + s->stride] = P[flags & 0x03];
  292. }
  293. s->pixel_ptr += s->stride * 2;
  294. }
  295. }
  296. } else {
  297. uint64_t flags;
  298. /* 1 of 4 colors for each 2x1 or 1x2 block, need 8 more bytes */
  299. CHECK_STREAM_PTR(8);
  300. flags = bytestream_get_le64(&s->stream_ptr);
  301. if (P[2] <= P[3]) {
  302. for (y = 0; y < 8; y++) {
  303. for (x = 0; x < 8; x += 2, flags >>= 2) {
  304. s->pixel_ptr[x ] =
  305. s->pixel_ptr[x + 1] = P[flags & 0x03];
  306. }
  307. s->pixel_ptr += s->stride;
  308. }
  309. } else {
  310. for (y = 0; y < 8; y += 2) {
  311. for (x = 0; x < 8; x++, flags >>= 2) {
  312. s->pixel_ptr[x ] =
  313. s->pixel_ptr[x + s->stride] = P[flags & 0x03];
  314. }
  315. s->pixel_ptr += s->stride * 2;
  316. }
  317. }
  318. }
  319. /* report success */
  320. return 0;
  321. }
  322. static int ipvideo_decode_block_opcode_0xA(IpvideoContext *s)
  323. {
  324. int x, y;
  325. unsigned char P[16];
  326. unsigned char B[16];
  327. int flags = 0;
  328. int index;
  329. int split;
  330. int lower_half;
  331. /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on
  332. * either top and bottom or left and right halves */
  333. CHECK_STREAM_PTR(4);
  334. memcpy(P, s->stream_ptr, 4);
  335. s->stream_ptr += 4;
  336. if (P[0] <= P[1]) {
  337. /* 4-color encoding for each quadrant; need 28 more bytes */
  338. CHECK_STREAM_PTR(28);
  339. memcpy(B, s->stream_ptr, 4);
  340. s->stream_ptr += 4;
  341. for (y = 4; y < 16; y += 4) {
  342. memcpy(P + y, s->stream_ptr, 4);
  343. s->stream_ptr += 4;
  344. memcpy(B + y, s->stream_ptr, 4);
  345. s->stream_ptr += 4;
  346. }
  347. for (y = 0; y < 8; y++) {
  348. lower_half = (y >= 4) ? 4 : 0;
  349. flags = (B[y + 8] << 8) | B[y];
  350. for (x = 0; x < 8; x++, flags >>= 2) {
  351. split = (x >= 4) ? 8 : 0;
  352. index = split + lower_half + (flags & 0x03);
  353. *s->pixel_ptr++ = P[index];
  354. }
  355. s->pixel_ptr += s->line_inc;
  356. }
  357. } else {
  358. /* 4-color encoding for either left and right or top and bottom
  359. * halves; need 20 more bytes */
  360. CHECK_STREAM_PTR(20);
  361. memcpy(B, s->stream_ptr, 8);
  362. s->stream_ptr += 8;
  363. memcpy(P + 4, s->stream_ptr, 4);
  364. s->stream_ptr += 4;
  365. memcpy(B + 8, s->stream_ptr, 8);
  366. s->stream_ptr += 8;
  367. if (P[4] <= P[5]) {
  368. /* block is divided into left and right halves */
  369. for (y = 0; y < 8; y++) {
  370. flags = (B[y + 8] << 8) | B[y];
  371. split = 0;
  372. for (x = 0; x < 8; x++, flags >>= 2) {
  373. if (x == 4)
  374. split = 4;
  375. *s->pixel_ptr++ = P[split + (flags & 0x03)];
  376. }
  377. s->pixel_ptr += s->line_inc;
  378. }
  379. } else {
  380. /* block is divided into top and bottom halves */
  381. split = 0;
  382. for (y = 0; y < 8; y++) {
  383. flags = (B[y * 2 + 1] << 8) | B[y * 2];
  384. if (y == 4)
  385. split = 4;
  386. for (x = 0; x < 8; x++, flags >>= 2)
  387. *s->pixel_ptr++ = P[split + (flags & 0x03)];
  388. s->pixel_ptr += s->line_inc;
  389. }
  390. }
  391. }
  392. /* report success */
  393. return 0;
  394. }
  395. static int ipvideo_decode_block_opcode_0xB(IpvideoContext *s)
  396. {
  397. int y;
  398. /* 64-color encoding (each pixel in block is a different color) */
  399. CHECK_STREAM_PTR(64);
  400. for (y = 0; y < 8; y++) {
  401. memcpy(s->pixel_ptr, s->stream_ptr, 8);
  402. s->stream_ptr += 8;
  403. s->pixel_ptr += s->stride;
  404. }
  405. /* report success */
  406. return 0;
  407. }
  408. static int ipvideo_decode_block_opcode_0xC(IpvideoContext *s)
  409. {
  410. int x, y;
  411. /* 16-color block encoding: each 2x2 block is a different color */
  412. CHECK_STREAM_PTR(16);
  413. for (y = 0; y < 8; y += 2) {
  414. for (x = 0; x < 8; x += 2) {
  415. s->pixel_ptr[x ] =
  416. s->pixel_ptr[x + 1 ] =
  417. s->pixel_ptr[x + s->stride] =
  418. s->pixel_ptr[x + 1 + s->stride] = *s->stream_ptr++;
  419. }
  420. s->pixel_ptr += s->stride * 2;
  421. }
  422. /* report success */
  423. return 0;
  424. }
  425. static int ipvideo_decode_block_opcode_0xD(IpvideoContext *s)
  426. {
  427. int y;
  428. unsigned char P[4];
  429. unsigned char index = 0;
  430. /* 4-color block encoding: each 4x4 block is a different color */
  431. CHECK_STREAM_PTR(4);
  432. memcpy(P, s->stream_ptr, 4);
  433. s->stream_ptr += 4;
  434. for (y = 0; y < 8; y++) {
  435. if (y < 4)
  436. index = 0;
  437. else
  438. index = 2;
  439. memset(s->pixel_ptr , P[index ], 4);
  440. memset(s->pixel_ptr + 4, P[index + 1], 4);
  441. s->pixel_ptr += s->stride;
  442. }
  443. /* report success */
  444. return 0;
  445. }
  446. static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s)
  447. {
  448. int y;
  449. unsigned char pix;
  450. /* 1-color encoding: the whole block is 1 solid color */
  451. CHECK_STREAM_PTR(1);
  452. pix = *s->stream_ptr++;
  453. for (y = 0; y < 8; y++) {
  454. memset(s->pixel_ptr, pix, 8);
  455. s->pixel_ptr += s->stride;
  456. }
  457. /* report success */
  458. return 0;
  459. }
  460. static int ipvideo_decode_block_opcode_0xF(IpvideoContext *s)
  461. {
  462. int x, y;
  463. unsigned char sample[2];
  464. /* dithered encoding */
  465. CHECK_STREAM_PTR(2);
  466. sample[0] = *s->stream_ptr++;
  467. sample[1] = *s->stream_ptr++;
  468. for (y = 0; y < 8; y++) {
  469. for (x = 0; x < 8; x += 2) {
  470. *s->pixel_ptr++ = sample[ y & 1 ];
  471. *s->pixel_ptr++ = sample[!(y & 1)];
  472. }
  473. s->pixel_ptr += s->line_inc;
  474. }
  475. /* report success */
  476. return 0;
  477. }
  478. static int (* const ipvideo_decode_block[])(IpvideoContext *s) = {
  479. ipvideo_decode_block_opcode_0x0, ipvideo_decode_block_opcode_0x1,
  480. ipvideo_decode_block_opcode_0x2, ipvideo_decode_block_opcode_0x3,
  481. ipvideo_decode_block_opcode_0x4, ipvideo_decode_block_opcode_0x5,
  482. ipvideo_decode_block_opcode_0x6, ipvideo_decode_block_opcode_0x7,
  483. ipvideo_decode_block_opcode_0x8, ipvideo_decode_block_opcode_0x9,
  484. ipvideo_decode_block_opcode_0xA, ipvideo_decode_block_opcode_0xB,
  485. ipvideo_decode_block_opcode_0xC, ipvideo_decode_block_opcode_0xD,
  486. ipvideo_decode_block_opcode_0xE, ipvideo_decode_block_opcode_0xF,
  487. };
  488. static void ipvideo_decode_opcodes(IpvideoContext *s)
  489. {
  490. int x, y;
  491. int index = 0;
  492. unsigned char opcode;
  493. int ret;
  494. int code_counts[16] = {0};
  495. static int frame = 0;
  496. debug_interplay("------------------ frame %d\n", frame);
  497. frame++;
  498. /* this is PAL8, so make the palette available */
  499. memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4);
  500. s->stride = s->current_frame.linesize[0];
  501. s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */
  502. s->stream_end = s->buf + s->size;
  503. s->line_inc = s->stride - 8;
  504. s->upper_motion_limit_offset = (s->avctx->height - 8) * s->stride
  505. + s->avctx->width - 8;
  506. for (y = 0; y < (s->stride * s->avctx->height); y += s->stride * 8) {
  507. for (x = y; x < y + s->avctx->width; x += 8) {
  508. /* bottom nibble first, then top nibble (which makes it
  509. * hard to use a GetBitcontext) */
  510. if (index & 1)
  511. opcode = s->decoding_map[index >> 1] >> 4;
  512. else
  513. opcode = s->decoding_map[index >> 1] & 0xF;
  514. index++;
  515. debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n",
  516. x - y, y / s->stride, opcode, s->stream_ptr);
  517. code_counts[opcode]++;
  518. s->pixel_ptr = s->current_frame.data[0] + x;
  519. ret = ipvideo_decode_block[opcode](s);
  520. if (ret != 0) {
  521. av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode problem on frame %d, @ block (%d, %d)\n",
  522. frame, x - y, y / s->stride);
  523. return;
  524. }
  525. }
  526. }
  527. if (s->stream_end - s->stream_ptr > 1) {
  528. av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode finished with %td bytes left over\n",
  529. s->stream_end - s->stream_ptr);
  530. }
  531. }
  532. static av_cold int ipvideo_decode_init(AVCodecContext *avctx)
  533. {
  534. IpvideoContext *s = avctx->priv_data;
  535. s->avctx = avctx;
  536. if (s->avctx->palctrl == NULL) {
  537. av_log(avctx, AV_LOG_ERROR, " Interplay video: palette expected.\n");
  538. return -1;
  539. }
  540. avctx->pix_fmt = PIX_FMT_PAL8;
  541. dsputil_init(&s->dsp, avctx);
  542. /* decoding map contains 4 bits of information per 8x8 block */
  543. s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
  544. s->current_frame.data[0] = s->last_frame.data[0] =
  545. s->second_last_frame.data[0] = NULL;
  546. return 0;
  547. }
  548. static int ipvideo_decode_frame(AVCodecContext *avctx,
  549. void *data, int *data_size,
  550. const uint8_t *buf, int buf_size)
  551. {
  552. IpvideoContext *s = avctx->priv_data;
  553. AVPaletteControl *palette_control = avctx->palctrl;
  554. /* compressed buffer needs to be large enough to at least hold an entire
  555. * decoding map */
  556. if (buf_size < s->decoding_map_size)
  557. return buf_size;
  558. s->decoding_map = buf;
  559. s->buf = buf + s->decoding_map_size;
  560. s->size = buf_size - s->decoding_map_size;
  561. s->current_frame.reference = 3;
  562. if (avctx->get_buffer(avctx, &s->current_frame)) {
  563. av_log(avctx, AV_LOG_ERROR, " Interplay Video: get_buffer() failed\n");
  564. return -1;
  565. }
  566. ipvideo_decode_opcodes(s);
  567. if (palette_control->palette_changed) {
  568. palette_control->palette_changed = 0;
  569. s->current_frame.palette_has_changed = 1;
  570. }
  571. *data_size = sizeof(AVFrame);
  572. *(AVFrame*)data = s->current_frame;
  573. /* shuffle frames */
  574. if (s->second_last_frame.data[0])
  575. avctx->release_buffer(avctx, &s->second_last_frame);
  576. s->second_last_frame = s->last_frame;
  577. s->last_frame = s->current_frame;
  578. s->current_frame.data[0] = NULL; /* catch any access attempts */
  579. /* report that the buffer was completely consumed */
  580. return buf_size;
  581. }
  582. static av_cold int ipvideo_decode_end(AVCodecContext *avctx)
  583. {
  584. IpvideoContext *s = avctx->priv_data;
  585. /* release the last frame */
  586. if (s->last_frame.data[0])
  587. avctx->release_buffer(avctx, &s->last_frame);
  588. if (s->second_last_frame.data[0])
  589. avctx->release_buffer(avctx, &s->second_last_frame);
  590. return 0;
  591. }
  592. AVCodec interplay_video_decoder = {
  593. "interplayvideo",
  594. CODEC_TYPE_VIDEO,
  595. CODEC_ID_INTERPLAY_VIDEO,
  596. sizeof(IpvideoContext),
  597. ipvideo_decode_init,
  598. NULL,
  599. ipvideo_decode_end,
  600. ipvideo_decode_frame,
  601. CODEC_CAP_DR1,
  602. .long_name = NULL_IF_CONFIG_SMALL("Interplay MVE video"),
  603. };