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.

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