unsigned char *buf;
int buf_size;
- int fps;
+ float fps;
int frame_pts_inc;
unsigned int video_width;
offset_t next_chunk_offset;
+ AVPaletteControl palette_control;
+
} IPMVEContext;
static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
if (s->audio_chunk_offset) {
+ /* adjust for PCM audio by skipping chunk header */
+ if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) {
+ s->audio_chunk_offset += 6;
+ s->audio_chunk_size -= 6;
+ }
+
url_fseek(pb, s->audio_chunk_offset, SEEK_SET);
s->audio_chunk_offset = 0;
} else if (s->decode_map_chunk_offset) {
- url_fseek(pb, s->decode_map_chunk_offset, SEEK_SET);
- s->decode_map_chunk_offset = 0;
+ /* send both the decode map and the video data together */
- if (av_new_packet(pkt, s->decode_map_chunk_size))
+ if (av_new_packet(pkt, s->decode_map_chunk_size + s->video_chunk_size))
return CHUNK_NOMEM;
- pkt->stream_index = s->video_stream_index;
- pkt->pts = s->video_pts;
+ url_fseek(pb, s->decode_map_chunk_offset, SEEK_SET);
+ s->decode_map_chunk_offset = 0;
+
if (get_buffer(pb, pkt->data, s->decode_map_chunk_size) !=
s->decode_map_chunk_size) {
av_free_packet(pkt);
return CHUNK_EOF;
}
- chunk_type = CHUNK_VIDEO;
-
- } else if (s->video_chunk_offset) {
-
url_fseek(pb, s->video_chunk_offset, SEEK_SET);
s->video_chunk_offset = 0;
- if (av_new_packet(pkt, s->video_chunk_size))
- return CHUNK_NOMEM;
-
- pkt->stream_index = s->video_stream_index;
- pkt->pts = s->video_pts;
- if (get_buffer(pb, pkt->data, s->video_chunk_size) !=
- s->video_chunk_size) {
+ if (get_buffer(pb, pkt->data + s->decode_map_chunk_size,
+ s->video_chunk_size) != s->video_chunk_size) {
av_free_packet(pkt);
return CHUNK_EOF;
}
+ pkt->stream_index = s->video_stream_index;
+ pkt->pts = s->video_pts;
+
+ debug_ipmovie("sending video frame with pts %lld\n",
+ pkt->pts);
+
s->video_pts += s->frame_pts_inc;
chunk_type = CHUNK_VIDEO;
unsigned char opcode_version;
int opcode_size;
unsigned char scratch[1024];
- int j;
+ int i, j;
int first_color, last_color;
int audio_flags;
+ unsigned char r, g, b;
/* see if there are any pending packets */
chunk_type = load_ipmovie_packet(s, pb, pkt);
chunk_type = CHUNK_BAD;
break;
}
- s->fps = 1000000 / (LE_32(&scratch[0]) * LE_16(&scratch[4]));
- s->fps++; /* above calculation usually yields 14.9; we need 15 */
+ s->fps = 1000000.0 / (LE_32(&scratch[0]) * LE_16(&scratch[4]));
s->frame_pts_inc = 90000 / s->fps;
- debug_ipmovie("%d frames/second (timer div = %d, subdiv = %d)\n",
+ debug_ipmovie(" %.2f frames/second (timer div = %d, subdiv = %d)\n",
s->fps, LE_32(&scratch[0]), LE_16(&scratch[4]));
break;
/* load the palette into internal data structure */
first_color = LE_16(&scratch[0]);
- last_color = LE_16(&scratch[2]);
+ last_color = first_color + LE_16(&scratch[2]);
/* sanity check (since they are 16 bit values) */
if ((first_color > 0xFF) || (last_color > 0xFF)) {
debug_ipmovie("demux_ipmovie: set_palette indices out of range (%d -> %d)\n",
break;
}
j = 4; /* offset of first palette data */
-#if 0
for (i = first_color; i <= last_color; i++) {
- s->palette[i].r = scratch[j++] * 4;
- s->palette[i].g = scratch[j++] * 4;
- s->palette[i].b = scratch[j++] * 4;
+ /* the palette is stored as a 6-bit VGA palette, thus each
+ * component is shifted up to a 8-bit range */
+ r = scratch[j++] * 4;
+ g = scratch[j++] * 4;
+ b = scratch[j++] * 4;
+ s->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
}
-#endif
+ /* indicate a palette change */
+ s->palette_control.palette_changed = 1;
break;
case OPCODE_SET_PALETTE_COMPRESSED:
ByteIOContext *pb = &s->pb;
AVPacket pkt;
AVStream *st;
+ unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
+ int chunk_type;
/* initialize private context members */
ipmovie->video_pts = ipmovie->audio_frame_count = 0;
if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
return AVERROR_INVALIDDATA;
- /* process the next chunk which should be CHUNK_INIT_AUDIO */
- if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
+ /* peek ahead to the next chunk-- if it is an init audio chunk, process
+ * it; if it is the first video chunk, this is a silent file */
+ if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
+ CHUNK_PREAMBLE_SIZE)
+ return -EIO;
+ chunk_type = LE_16(&chunk_preamble[2]);
+ url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
+
+ if (chunk_type == CHUNK_VIDEO)
+ ipmovie->audio_type = 0; /* no audio */
+ else if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
return AVERROR_INVALIDDATA;
/* set the pts reference (1 pts = 1/90000) */
st->codec.width = ipmovie->video_width;
st->codec.height = ipmovie->video_height;
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- ipmovie->audio_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = ipmovie->audio_type;
- st->codec.codec_tag = 0; /* no tag */
- st->codec.channels = ipmovie->audio_channels;
- st->codec.sample_rate = ipmovie->audio_sample_rate;
- st->codec.bits_per_sample = ipmovie->audio_bits;
- st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
- st->codec.bits_per_sample /
- (st->codec.codec_id == CODEC_ID_INTERPLAY_DPCM) ? 2 : 1;
- st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
+ /* palette considerations */
+ st->codec.palctrl = &ipmovie->palette_control;
+
+ if (ipmovie->audio_type) {
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ ipmovie->audio_stream_index = st->index;
+ st->codec.codec_type = CODEC_TYPE_AUDIO;
+ st->codec.codec_id = ipmovie->audio_type;
+ st->codec.codec_tag = 0; /* no tag */
+ st->codec.channels = ipmovie->audio_channels;
+ st->codec.sample_rate = ipmovie->audio_sample_rate;
+ st->codec.bits_per_sample = ipmovie->audio_bits;
+ st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
+ st->codec.bits_per_sample;
+ if (st->codec.codec_id == CODEC_ID_INTERPLAY_DPCM)
+ st->codec.bit_rate /= 2;
+ st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
+ }
return 0;
}