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.

624 lines
20KB

  1. /*
  2. * Interplay MVE File Demuxer
  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 libavformat/ipmovie.c
  23. * Interplay MVE file demuxer
  24. * by Mike Melanson (melanson@pcisys.net)
  25. * For more information regarding the Interplay MVE file format, visit:
  26. * http://www.pcisys.net/~melanson/codecs/
  27. * The aforementioned site also contains a command line utility for parsing
  28. * IP MVE files so that you can get a good idea of the typical structure of
  29. * such files. This demuxer is not the best example to use if you are trying
  30. * to write your own as it uses a rather roundabout approach for splitting
  31. * up and sending out the chunks.
  32. */
  33. #include "libavutil/intreadwrite.h"
  34. #include "avformat.h"
  35. /* debugging support: #define DEBUG_IPMOVIE as non-zero to see extremely
  36. * verbose information about the demux process */
  37. #define DEBUG_IPMOVIE 0
  38. #if DEBUG_IPMOVIE
  39. #undef printf
  40. #define debug_ipmovie printf
  41. #else
  42. static inline void debug_ipmovie(const char *format, ...) { }
  43. #endif
  44. #define CHUNK_PREAMBLE_SIZE 4
  45. #define OPCODE_PREAMBLE_SIZE 4
  46. #define CHUNK_INIT_AUDIO 0x0000
  47. #define CHUNK_AUDIO_ONLY 0x0001
  48. #define CHUNK_INIT_VIDEO 0x0002
  49. #define CHUNK_VIDEO 0x0003
  50. #define CHUNK_SHUTDOWN 0x0004
  51. #define CHUNK_END 0x0005
  52. /* these last types are used internally */
  53. #define CHUNK_DONE 0xFFFC
  54. #define CHUNK_NOMEM 0xFFFD
  55. #define CHUNK_EOF 0xFFFE
  56. #define CHUNK_BAD 0xFFFF
  57. #define OPCODE_END_OF_STREAM 0x00
  58. #define OPCODE_END_OF_CHUNK 0x01
  59. #define OPCODE_CREATE_TIMER 0x02
  60. #define OPCODE_INIT_AUDIO_BUFFERS 0x03
  61. #define OPCODE_START_STOP_AUDIO 0x04
  62. #define OPCODE_INIT_VIDEO_BUFFERS 0x05
  63. #define OPCODE_UNKNOWN_06 0x06
  64. #define OPCODE_SEND_BUFFER 0x07
  65. #define OPCODE_AUDIO_FRAME 0x08
  66. #define OPCODE_SILENCE_FRAME 0x09
  67. #define OPCODE_INIT_VIDEO_MODE 0x0A
  68. #define OPCODE_CREATE_GRADIENT 0x0B
  69. #define OPCODE_SET_PALETTE 0x0C
  70. #define OPCODE_SET_PALETTE_COMPRESSED 0x0D
  71. #define OPCODE_UNKNOWN_0E 0x0E
  72. #define OPCODE_SET_DECODING_MAP 0x0F
  73. #define OPCODE_UNKNOWN_10 0x10
  74. #define OPCODE_VIDEO_DATA 0x11
  75. #define OPCODE_UNKNOWN_12 0x12
  76. #define OPCODE_UNKNOWN_13 0x13
  77. #define OPCODE_UNKNOWN_14 0x14
  78. #define OPCODE_UNKNOWN_15 0x15
  79. #define PALETTE_COUNT 256
  80. typedef struct IPMVEContext {
  81. unsigned char *buf;
  82. int buf_size;
  83. uint64_t frame_pts_inc;
  84. unsigned int video_width;
  85. unsigned int video_height;
  86. int64_t video_pts;
  87. unsigned int audio_bits;
  88. unsigned int audio_channels;
  89. unsigned int audio_sample_rate;
  90. enum CodecID audio_type;
  91. unsigned int audio_frame_count;
  92. int video_stream_index;
  93. int audio_stream_index;
  94. int64_t audio_chunk_offset;
  95. int audio_chunk_size;
  96. int64_t video_chunk_offset;
  97. int video_chunk_size;
  98. int64_t decode_map_chunk_offset;
  99. int decode_map_chunk_size;
  100. int64_t next_chunk_offset;
  101. AVPaletteControl palette_control;
  102. } IPMVEContext;
  103. static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
  104. AVPacket *pkt) {
  105. int chunk_type;
  106. if (s->audio_chunk_offset) {
  107. /* adjust for PCM audio by skipping chunk header */
  108. if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) {
  109. s->audio_chunk_offset += 6;
  110. s->audio_chunk_size -= 6;
  111. }
  112. url_fseek(pb, s->audio_chunk_offset, SEEK_SET);
  113. s->audio_chunk_offset = 0;
  114. if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size))
  115. return CHUNK_EOF;
  116. pkt->stream_index = s->audio_stream_index;
  117. pkt->pts = s->audio_frame_count;
  118. /* audio frame maintenance */
  119. if (s->audio_type != CODEC_ID_INTERPLAY_DPCM)
  120. s->audio_frame_count +=
  121. (s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8));
  122. else
  123. s->audio_frame_count +=
  124. (s->audio_chunk_size - 6) / s->audio_channels;
  125. debug_ipmovie("sending audio frame with pts %"PRId64" (%d audio frames)\n",
  126. pkt->pts, s->audio_frame_count);
  127. chunk_type = CHUNK_VIDEO;
  128. } else if (s->decode_map_chunk_offset) {
  129. /* send both the decode map and the video data together */
  130. if (av_new_packet(pkt, s->decode_map_chunk_size + s->video_chunk_size))
  131. return CHUNK_NOMEM;
  132. pkt->pos= s->decode_map_chunk_offset;
  133. url_fseek(pb, s->decode_map_chunk_offset, SEEK_SET);
  134. s->decode_map_chunk_offset = 0;
  135. if (get_buffer(pb, pkt->data, s->decode_map_chunk_size) !=
  136. s->decode_map_chunk_size) {
  137. av_free_packet(pkt);
  138. return CHUNK_EOF;
  139. }
  140. url_fseek(pb, s->video_chunk_offset, SEEK_SET);
  141. s->video_chunk_offset = 0;
  142. if (get_buffer(pb, pkt->data + s->decode_map_chunk_size,
  143. s->video_chunk_size) != s->video_chunk_size) {
  144. av_free_packet(pkt);
  145. return CHUNK_EOF;
  146. }
  147. pkt->stream_index = s->video_stream_index;
  148. pkt->pts = s->video_pts;
  149. debug_ipmovie("sending video frame with pts %"PRId64"\n",
  150. pkt->pts);
  151. s->video_pts += s->frame_pts_inc;
  152. chunk_type = CHUNK_VIDEO;
  153. } else {
  154. url_fseek(pb, s->next_chunk_offset, SEEK_SET);
  155. chunk_type = CHUNK_DONE;
  156. }
  157. return chunk_type;
  158. }
  159. /* This function loads and processes a single chunk in an IP movie file.
  160. * It returns the type of chunk that was processed. */
  161. static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
  162. AVPacket *pkt)
  163. {
  164. unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
  165. int chunk_type;
  166. int chunk_size;
  167. unsigned char opcode_preamble[OPCODE_PREAMBLE_SIZE];
  168. unsigned char opcode_type;
  169. unsigned char opcode_version;
  170. int opcode_size;
  171. unsigned char scratch[1024];
  172. int i, j;
  173. int first_color, last_color;
  174. int audio_flags;
  175. unsigned char r, g, b;
  176. /* see if there are any pending packets */
  177. chunk_type = load_ipmovie_packet(s, pb, pkt);
  178. if (chunk_type != CHUNK_DONE)
  179. return chunk_type;
  180. /* read the next chunk, wherever the file happens to be pointing */
  181. if (url_feof(pb))
  182. return CHUNK_EOF;
  183. if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
  184. CHUNK_PREAMBLE_SIZE)
  185. return CHUNK_BAD;
  186. chunk_size = AV_RL16(&chunk_preamble[0]);
  187. chunk_type = AV_RL16(&chunk_preamble[2]);
  188. debug_ipmovie("chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size);
  189. switch (chunk_type) {
  190. case CHUNK_INIT_AUDIO:
  191. debug_ipmovie("initialize audio\n");
  192. break;
  193. case CHUNK_AUDIO_ONLY:
  194. debug_ipmovie("audio only\n");
  195. break;
  196. case CHUNK_INIT_VIDEO:
  197. debug_ipmovie("initialize video\n");
  198. break;
  199. case CHUNK_VIDEO:
  200. debug_ipmovie("video (and audio)\n");
  201. break;
  202. case CHUNK_SHUTDOWN:
  203. debug_ipmovie("shutdown\n");
  204. break;
  205. case CHUNK_END:
  206. debug_ipmovie("end\n");
  207. break;
  208. default:
  209. debug_ipmovie("invalid chunk\n");
  210. chunk_type = CHUNK_BAD;
  211. break;
  212. }
  213. while ((chunk_size > 0) && (chunk_type != CHUNK_BAD)) {
  214. /* read the next chunk, wherever the file happens to be pointing */
  215. if (url_feof(pb)) {
  216. chunk_type = CHUNK_EOF;
  217. break;
  218. }
  219. if (get_buffer(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) !=
  220. CHUNK_PREAMBLE_SIZE) {
  221. chunk_type = CHUNK_BAD;
  222. break;
  223. }
  224. opcode_size = AV_RL16(&opcode_preamble[0]);
  225. opcode_type = opcode_preamble[2];
  226. opcode_version = opcode_preamble[3];
  227. chunk_size -= OPCODE_PREAMBLE_SIZE;
  228. chunk_size -= opcode_size;
  229. if (chunk_size < 0) {
  230. debug_ipmovie("chunk_size countdown just went negative\n");
  231. chunk_type = CHUNK_BAD;
  232. break;
  233. }
  234. debug_ipmovie(" opcode type %02X, version %d, 0x%04X bytes: ",
  235. opcode_type, opcode_version, opcode_size);
  236. switch (opcode_type) {
  237. case OPCODE_END_OF_STREAM:
  238. debug_ipmovie("end of stream\n");
  239. url_fseek(pb, opcode_size, SEEK_CUR);
  240. break;
  241. case OPCODE_END_OF_CHUNK:
  242. debug_ipmovie("end of chunk\n");
  243. url_fseek(pb, opcode_size, SEEK_CUR);
  244. break;
  245. case OPCODE_CREATE_TIMER:
  246. debug_ipmovie("create timer\n");
  247. if ((opcode_version > 0) || (opcode_size > 6)) {
  248. debug_ipmovie("bad create_timer opcode\n");
  249. chunk_type = CHUNK_BAD;
  250. break;
  251. }
  252. if (get_buffer(pb, scratch, opcode_size) !=
  253. opcode_size) {
  254. chunk_type = CHUNK_BAD;
  255. break;
  256. }
  257. s->frame_pts_inc = ((uint64_t)AV_RL32(&scratch[0])) * AV_RL16(&scratch[4]);
  258. debug_ipmovie(" %.2f frames/second (timer div = %d, subdiv = %d)\n",
  259. 1000000.0/s->frame_pts_inc, AV_RL32(&scratch[0]), AV_RL16(&scratch[4]));
  260. break;
  261. case OPCODE_INIT_AUDIO_BUFFERS:
  262. debug_ipmovie("initialize audio buffers\n");
  263. if ((opcode_version > 1) || (opcode_size > 10)) {
  264. debug_ipmovie("bad init_audio_buffers opcode\n");
  265. chunk_type = CHUNK_BAD;
  266. break;
  267. }
  268. if (get_buffer(pb, scratch, opcode_size) !=
  269. opcode_size) {
  270. chunk_type = CHUNK_BAD;
  271. break;
  272. }
  273. s->audio_sample_rate = AV_RL16(&scratch[4]);
  274. audio_flags = AV_RL16(&scratch[2]);
  275. /* bit 0 of the flags: 0 = mono, 1 = stereo */
  276. s->audio_channels = (audio_flags & 1) + 1;
  277. /* bit 1 of the flags: 0 = 8 bit, 1 = 16 bit */
  278. s->audio_bits = (((audio_flags >> 1) & 1) + 1) * 8;
  279. /* bit 2 indicates compressed audio in version 1 opcode */
  280. if ((opcode_version == 1) && (audio_flags & 0x4))
  281. s->audio_type = CODEC_ID_INTERPLAY_DPCM;
  282. else if (s->audio_bits == 16)
  283. s->audio_type = CODEC_ID_PCM_S16LE;
  284. else
  285. s->audio_type = CODEC_ID_PCM_U8;
  286. debug_ipmovie("audio: %d bits, %d Hz, %s, %s format\n",
  287. s->audio_bits,
  288. s->audio_sample_rate,
  289. (s->audio_channels == 2) ? "stereo" : "mono",
  290. (s->audio_type == CODEC_ID_INTERPLAY_DPCM) ?
  291. "Interplay audio" : "PCM");
  292. break;
  293. case OPCODE_START_STOP_AUDIO:
  294. debug_ipmovie("start/stop audio\n");
  295. url_fseek(pb, opcode_size, SEEK_CUR);
  296. break;
  297. case OPCODE_INIT_VIDEO_BUFFERS:
  298. debug_ipmovie("initialize video buffers\n");
  299. if ((opcode_version > 2) || (opcode_size > 8)) {
  300. debug_ipmovie("bad init_video_buffers opcode\n");
  301. chunk_type = CHUNK_BAD;
  302. break;
  303. }
  304. if (get_buffer(pb, scratch, opcode_size) !=
  305. opcode_size) {
  306. chunk_type = CHUNK_BAD;
  307. break;
  308. }
  309. s->video_width = AV_RL16(&scratch[0]) * 8;
  310. s->video_height = AV_RL16(&scratch[2]) * 8;
  311. debug_ipmovie("video resolution: %d x %d\n",
  312. s->video_width, s->video_height);
  313. break;
  314. case OPCODE_UNKNOWN_06:
  315. case OPCODE_UNKNOWN_0E:
  316. case OPCODE_UNKNOWN_10:
  317. case OPCODE_UNKNOWN_12:
  318. case OPCODE_UNKNOWN_13:
  319. case OPCODE_UNKNOWN_14:
  320. case OPCODE_UNKNOWN_15:
  321. debug_ipmovie("unknown (but documented) opcode %02X\n", opcode_type);
  322. url_fseek(pb, opcode_size, SEEK_CUR);
  323. break;
  324. case OPCODE_SEND_BUFFER:
  325. debug_ipmovie("send buffer\n");
  326. url_fseek(pb, opcode_size, SEEK_CUR);
  327. break;
  328. case OPCODE_AUDIO_FRAME:
  329. debug_ipmovie("audio frame\n");
  330. /* log position and move on for now */
  331. s->audio_chunk_offset = url_ftell(pb);
  332. s->audio_chunk_size = opcode_size;
  333. url_fseek(pb, opcode_size, SEEK_CUR);
  334. break;
  335. case OPCODE_SILENCE_FRAME:
  336. debug_ipmovie("silence frame\n");
  337. url_fseek(pb, opcode_size, SEEK_CUR);
  338. break;
  339. case OPCODE_INIT_VIDEO_MODE:
  340. debug_ipmovie("initialize video mode\n");
  341. url_fseek(pb, opcode_size, SEEK_CUR);
  342. break;
  343. case OPCODE_CREATE_GRADIENT:
  344. debug_ipmovie("create gradient\n");
  345. url_fseek(pb, opcode_size, SEEK_CUR);
  346. break;
  347. case OPCODE_SET_PALETTE:
  348. debug_ipmovie("set palette\n");
  349. /* check for the logical maximum palette size
  350. * (3 * 256 + 4 bytes) */
  351. if (opcode_size > 0x304) {
  352. debug_ipmovie("demux_ipmovie: set_palette opcode too large\n");
  353. chunk_type = CHUNK_BAD;
  354. break;
  355. }
  356. if (get_buffer(pb, scratch, opcode_size) != opcode_size) {
  357. chunk_type = CHUNK_BAD;
  358. break;
  359. }
  360. /* load the palette into internal data structure */
  361. first_color = AV_RL16(&scratch[0]);
  362. last_color = first_color + AV_RL16(&scratch[2]) - 1;
  363. /* sanity check (since they are 16 bit values) */
  364. if ((first_color > 0xFF) || (last_color > 0xFF)) {
  365. debug_ipmovie("demux_ipmovie: set_palette indexes out of range (%d -> %d)\n",
  366. first_color, last_color);
  367. chunk_type = CHUNK_BAD;
  368. break;
  369. }
  370. j = 4; /* offset of first palette data */
  371. for (i = first_color; i <= last_color; i++) {
  372. /* the palette is stored as a 6-bit VGA palette, thus each
  373. * component is shifted up to a 8-bit range */
  374. r = scratch[j++] * 4;
  375. g = scratch[j++] * 4;
  376. b = scratch[j++] * 4;
  377. s->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
  378. }
  379. /* indicate a palette change */
  380. s->palette_control.palette_changed = 1;
  381. break;
  382. case OPCODE_SET_PALETTE_COMPRESSED:
  383. debug_ipmovie("set palette compressed\n");
  384. url_fseek(pb, opcode_size, SEEK_CUR);
  385. break;
  386. case OPCODE_SET_DECODING_MAP:
  387. debug_ipmovie("set decoding map\n");
  388. /* log position and move on for now */
  389. s->decode_map_chunk_offset = url_ftell(pb);
  390. s->decode_map_chunk_size = opcode_size;
  391. url_fseek(pb, opcode_size, SEEK_CUR);
  392. break;
  393. case OPCODE_VIDEO_DATA:
  394. debug_ipmovie("set video data\n");
  395. /* log position and move on for now */
  396. s->video_chunk_offset = url_ftell(pb);
  397. s->video_chunk_size = opcode_size;
  398. url_fseek(pb, opcode_size, SEEK_CUR);
  399. break;
  400. default:
  401. debug_ipmovie("*** unknown opcode type\n");
  402. chunk_type = CHUNK_BAD;
  403. break;
  404. }
  405. }
  406. /* make a note of where the stream is sitting */
  407. s->next_chunk_offset = url_ftell(pb);
  408. /* dispatch the first of any pending packets */
  409. if ((chunk_type == CHUNK_VIDEO) || (chunk_type == CHUNK_AUDIO_ONLY))
  410. chunk_type = load_ipmovie_packet(s, pb, pkt);
  411. return chunk_type;
  412. }
  413. static const char signature[] = "Interplay MVE File\x1A\0\x1A";
  414. static int ipmovie_probe(AVProbeData *p)
  415. {
  416. uint8_t *b = p->buf;
  417. uint8_t *b_end = p->buf + p->buf_size - sizeof(signature);
  418. do {
  419. if (memcmp(b++, signature, sizeof(signature)) == 0)
  420. return AVPROBE_SCORE_MAX;
  421. } while (b < b_end);
  422. return 0;
  423. }
  424. static int ipmovie_read_header(AVFormatContext *s,
  425. AVFormatParameters *ap)
  426. {
  427. IPMVEContext *ipmovie = s->priv_data;
  428. ByteIOContext *pb = s->pb;
  429. AVPacket pkt;
  430. AVStream *st;
  431. unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
  432. int chunk_type;
  433. uint8_t signature_buffer[sizeof(signature)];
  434. get_buffer(pb, signature_buffer, sizeof(signature_buffer));
  435. while (memcmp(signature_buffer, signature, sizeof(signature))) {
  436. memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1);
  437. signature_buffer[sizeof(signature_buffer) - 1] = get_byte(pb);
  438. if (url_feof(pb))
  439. return AVERROR_EOF;
  440. }
  441. /* initialize private context members */
  442. ipmovie->video_pts = ipmovie->audio_frame_count = 0;
  443. ipmovie->audio_chunk_offset = ipmovie->video_chunk_offset =
  444. ipmovie->decode_map_chunk_offset = 0;
  445. /* on the first read, this will position the stream at the first chunk */
  446. ipmovie->next_chunk_offset = url_ftell(pb) + 4;
  447. /* process the first chunk which should be CHUNK_INIT_VIDEO */
  448. if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
  449. return AVERROR_INVALIDDATA;
  450. /* peek ahead to the next chunk-- if it is an init audio chunk, process
  451. * it; if it is the first video chunk, this is a silent file */
  452. if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
  453. CHUNK_PREAMBLE_SIZE)
  454. return AVERROR(EIO);
  455. chunk_type = AV_RL16(&chunk_preamble[2]);
  456. url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
  457. if (chunk_type == CHUNK_VIDEO)
  458. ipmovie->audio_type = CODEC_ID_NONE; /* no audio */
  459. else if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
  460. return AVERROR_INVALIDDATA;
  461. /* initialize the stream decoders */
  462. st = av_new_stream(s, 0);
  463. if (!st)
  464. return AVERROR(ENOMEM);
  465. av_set_pts_info(st, 63, 1, 1000000);
  466. ipmovie->video_stream_index = st->index;
  467. st->codec->codec_type = CODEC_TYPE_VIDEO;
  468. st->codec->codec_id = CODEC_ID_INTERPLAY_VIDEO;
  469. st->codec->codec_tag = 0; /* no fourcc */
  470. st->codec->width = ipmovie->video_width;
  471. st->codec->height = ipmovie->video_height;
  472. /* palette considerations */
  473. st->codec->palctrl = &ipmovie->palette_control;
  474. if (ipmovie->audio_type) {
  475. st = av_new_stream(s, 0);
  476. if (!st)
  477. return AVERROR(ENOMEM);
  478. av_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate);
  479. ipmovie->audio_stream_index = st->index;
  480. st->codec->codec_type = CODEC_TYPE_AUDIO;
  481. st->codec->codec_id = ipmovie->audio_type;
  482. st->codec->codec_tag = 0; /* no tag */
  483. st->codec->channels = ipmovie->audio_channels;
  484. st->codec->sample_rate = ipmovie->audio_sample_rate;
  485. st->codec->bits_per_coded_sample = ipmovie->audio_bits;
  486. st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
  487. st->codec->bits_per_coded_sample;
  488. if (st->codec->codec_id == CODEC_ID_INTERPLAY_DPCM)
  489. st->codec->bit_rate /= 2;
  490. st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
  491. }
  492. return 0;
  493. }
  494. static int ipmovie_read_packet(AVFormatContext *s,
  495. AVPacket *pkt)
  496. {
  497. IPMVEContext *ipmovie = s->priv_data;
  498. ByteIOContext *pb = s->pb;
  499. int ret;
  500. ret = process_ipmovie_chunk(ipmovie, pb, pkt);
  501. if (ret == CHUNK_BAD)
  502. ret = AVERROR_INVALIDDATA;
  503. else if (ret == CHUNK_EOF)
  504. ret = AVERROR(EIO);
  505. else if (ret == CHUNK_NOMEM)
  506. ret = AVERROR(ENOMEM);
  507. else if (ret == CHUNK_VIDEO)
  508. ret = 0;
  509. else
  510. ret = -1;
  511. return ret;
  512. }
  513. AVInputFormat ipmovie_demuxer = {
  514. "ipmovie",
  515. NULL_IF_CONFIG_SMALL("Interplay MVE format"),
  516. sizeof(IPMVEContext),
  517. ipmovie_probe,
  518. ipmovie_read_header,
  519. ipmovie_read_packet,
  520. };