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.

644 lines
20KB

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