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.

638 lines
21KB

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