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.

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