40 #define CHUNK_PREAMBLE_SIZE 4
41 #define OPCODE_PREAMBLE_SIZE 4
43 #define CHUNK_INIT_AUDIO 0x0000
44 #define CHUNK_AUDIO_ONLY 0x0001
45 #define CHUNK_INIT_VIDEO 0x0002
46 #define CHUNK_VIDEO 0x0003
47 #define CHUNK_SHUTDOWN 0x0004
48 #define CHUNK_END 0x0005
50 #define CHUNK_HAVE_PACKET 0xFFFB
51 #define CHUNK_DONE 0xFFFC
52 #define CHUNK_NOMEM 0xFFFD
53 #define CHUNK_EOF 0xFFFE
54 #define CHUNK_BAD 0xFFFF
56 #define OPCODE_END_OF_STREAM 0x00
57 #define OPCODE_END_OF_CHUNK 0x01
58 #define OPCODE_CREATE_TIMER 0x02
59 #define OPCODE_INIT_AUDIO_BUFFERS 0x03
60 #define OPCODE_START_STOP_AUDIO 0x04
61 #define OPCODE_INIT_VIDEO_BUFFERS 0x05
62 #define OPCODE_VIDEO_DATA_06 0x06
63 #define OPCODE_SEND_BUFFER 0x07
64 #define OPCODE_AUDIO_FRAME 0x08
65 #define OPCODE_SILENCE_FRAME 0x09
66 #define OPCODE_INIT_VIDEO_MODE 0x0A
67 #define OPCODE_CREATE_GRADIENT 0x0B
68 #define OPCODE_SET_PALETTE 0x0C
69 #define OPCODE_SET_PALETTE_COMPRESSED 0x0D
70 #define OPCODE_SET_SKIP_MAP 0x0E
71 #define OPCODE_SET_DECODING_MAP 0x0F
72 #define OPCODE_VIDEO_DATA_10 0x10
73 #define OPCODE_VIDEO_DATA_11 0x11
74 #define OPCODE_UNKNOWN_12 0x12
75 #define OPCODE_UNKNOWN_13 0x13
76 #define OPCODE_UNKNOWN_14 0x14
77 #define OPCODE_UNKNOWN_15 0x15
79 #define PALETTE_COUNT 256
125 if (
s->audio_chunk_offset &&
s->audio_channels &&
s->audio_bits) {
128 "audio codec is known\n");
134 s->audio_chunk_offset += 6;
135 s->audio_chunk_size -= 6;
138 avio_seek(pb,
s->audio_chunk_offset, SEEK_SET);
139 s->audio_chunk_offset = 0;
145 pkt->
pts =
s->audio_frame_count;
149 s->audio_frame_count +=
150 (
s->audio_chunk_size /
s->audio_channels / (
s->audio_bits / 8));
152 s->audio_frame_count +=
153 (
s->audio_chunk_size - 6 -
s->audio_channels) /
s->audio_channels;
156 pkt->
pts,
s->audio_frame_count);
160 }
else if (
s->frame_format) {
164 if (
av_new_packet(
pkt, 8 +
s->decode_map_chunk_size +
s->video_chunk_size +
s->skip_map_chunk_size))
167 if (
s->has_palette) {
192 pkt->
pos =
s->video_chunk_offset;
193 avio_seek(pb,
s->video_chunk_offset, SEEK_SET);
194 s->video_chunk_offset = 0;
197 s->video_chunk_size) {
202 if (
s->decode_map_chunk_size) {
203 pkt->
pos =
s->decode_map_chunk_offset;
204 avio_seek(pb,
s->decode_map_chunk_offset, SEEK_SET);
205 s->decode_map_chunk_offset = 0;
208 s->decode_map_chunk_size) !=
s->decode_map_chunk_size) {
214 if (
s->skip_map_chunk_size) {
215 pkt->
pos =
s->skip_map_chunk_offset;
216 avio_seek(pb,
s->skip_map_chunk_offset, SEEK_SET);
217 s->skip_map_chunk_offset = 0;
220 s->skip_map_chunk_size) !=
s->skip_map_chunk_size) {
226 s->video_chunk_size = 0;
227 s->decode_map_chunk_size = 0;
228 s->skip_map_chunk_size = 0;
235 s->video_pts +=
s->frame_pts_inc;
241 avio_seek(pb,
s->next_chunk_offset, SEEK_SET);
283 unsigned char opcode_type;
284 unsigned char opcode_version;
286 unsigned char scratch[1024];
288 int first_color, last_color;
290 unsigned char r,
g,
b;
304 chunk_size =
AV_RL16(&chunk_preamble[0]);
305 chunk_type =
AV_RL16(&chunk_preamble[2]);
309 switch (chunk_type) {
342 while ((chunk_size > 0) && (chunk_type !=
CHUNK_BAD)) {
355 opcode_size =
AV_RL16(&opcode_preamble[0]);
356 opcode_type = opcode_preamble[2];
357 opcode_version = opcode_preamble[3];
360 chunk_size -= opcode_size;
361 if (chunk_size < 0) {
368 opcode_type, opcode_version, opcode_size);
369 switch (opcode_type) {
383 if ((opcode_version > 0) || (opcode_size != 6)) {
388 if (
avio_read(pb, scratch, opcode_size) !=
393 s->frame_pts_inc = ((uint64_t)
AV_RL32(&scratch[0])) *
AV_RL16(&scratch[4]);
398 if (opcode_version > 1 || opcode_size > 10 || opcode_size < 6) {
403 if (
avio_read(pb, scratch, opcode_size) !=
408 s->audio_sample_rate =
AV_RL16(&scratch[4]);
409 audio_flags =
AV_RL16(&scratch[2]);
411 s->audio_channels = (audio_flags & 1) + 1;
413 s->audio_bits = (((audio_flags >> 1) & 1) + 1) * 8;
415 if ((opcode_version == 1) && (audio_flags & 0x4))
417 else if (
s->audio_bits == 16)
422 s->audio_bits,
s->audio_sample_rate,
423 (
s->audio_channels == 2) ?
"stereo" :
"mono",
425 "Interplay audio" :
"PCM");
435 if ((opcode_version > 2) || (opcode_size > 8) || opcode_size < 4
436 || opcode_version == 2 && opcode_size < 8
442 if (
avio_read(pb, scratch, opcode_size) !=
449 if (
width !=
s->video_width) {
453 if (
height !=
s->video_height) {
457 if (opcode_version < 2 || !
AV_RL16(&scratch[6])) {
463 s->video_width,
s->video_height);
485 s->audio_chunk_size = opcode_size;
508 if (opcode_size > 0x304 || opcode_size < 4) {
513 if (
avio_read(pb, scratch, opcode_size) != opcode_size) {
519 first_color =
AV_RL16(&scratch[0]);
520 last_color = first_color +
AV_RL16(&scratch[2]) - 1;
522 if ( (first_color > 0xFF) || (last_color > 0xFF)
523 || (last_color - first_color + 1)*3 + 4 > opcode_size) {
524 av_log(
s->avf,
AV_LOG_TRACE,
"demux_ipmovie: set_palette indexes out of range (%d -> %d)\n",
525 first_color, last_color);
530 for (
i = first_color;
i <= last_color;
i++) {
533 r = scratch[j++] * 4;
534 g = scratch[j++] * 4;
535 b = scratch[j++] * 4;
536 s->palette[
i] = (0xFFU << 24) | (
r << 16) | (
g << 8) | (
b);
537 s->palette[
i] |=
s->palette[
i] >> 6 & 0x30303;
552 s->skip_map_chunk_size = opcode_size;
561 s->decode_map_chunk_size = opcode_size;
567 s->frame_format = 0x06;
571 s->video_chunk_size = opcode_size;
577 s->frame_format = 0x10;
581 s->video_chunk_size = opcode_size;
587 s->frame_format = 0x11;
591 s->video_chunk_size = opcode_size;
603 if (
s->avf->nb_streams == 1 &&
s->audio_type)
612 static const char signature[] =
"Interplay MVE File\x1A\0\x1A";
638 if (
avio_read(pb, signature_buffer,
sizeof(signature_buffer)) !=
sizeof(signature_buffer))
641 memmove(signature_buffer, signature_buffer + 1,
sizeof(signature_buffer) - 1);
642 signature_buffer[
sizeof(signature_buffer) - 1] =
avio_r8(pb);
657 for (
i = 0;
i < 256;
i++)
670 chunk_type =
AV_RL16(&chunk_preamble[2]);
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int avio_r8(AVIOContext *s)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
audio channel layout utility functions
static int read_header(FFV1Context *f)
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_INTERPLAY_DPCM
@ AV_CODEC_ID_INTERPLAY_VIDEO
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVInputFormat ff_ipmovie_demuxer
#define OPCODE_INIT_VIDEO_BUFFERS
#define OPCODE_UNKNOWN_12
#define OPCODE_SILENCE_FRAME
#define OPCODE_SET_SKIP_MAP
#define OPCODE_INIT_VIDEO_MODE
#define OPCODE_INIT_AUDIO_BUFFERS
#define OPCODE_VIDEO_DATA_11
#define OPCODE_VIDEO_DATA_06
#define OPCODE_SEND_BUFFER
#define OPCODE_SET_PALETTE
static int init_audio(AVFormatContext *s)
#define OPCODE_PREAMBLE_SIZE
static const char signature[]
#define OPCODE_CREATE_GRADIENT
#define OPCODE_END_OF_STREAM
#define OPCODE_SET_DECODING_MAP
#define OPCODE_SET_PALETTE_COMPRESSED
#define CHUNK_PREAMBLE_SIZE
#define OPCODE_START_STOP_AUDIO
#define OPCODE_UNKNOWN_14
#define OPCODE_AUDIO_FRAME
static int ipmovie_read_header(AVFormatContext *s)
#define OPCODE_UNKNOWN_15
static int ipmovie_probe(const AVProbeData *p)
#define OPCODE_UNKNOWN_13
#define CHUNK_HAVE_PACKET
#define OPCODE_END_OF_CHUNK
static int ipmovie_read_packet(AVFormatContext *s, AVPacket *pkt)
#define OPCODE_CREATE_TIMER
static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb, AVPacket *pkt)
#define OPCODE_VIDEO_DATA_10
static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb, AVPacket *pkt)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint64_t channel_layout
Audio only.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
int block_align
Audio only.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
Audio only.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t pos
byte position in stream, -1 if unknown
This structure contains the data a format has to probe a file.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int index
stream index in AVFormatContext
int64_t audio_chunk_offset
unsigned int audio_sample_rate
unsigned int audio_channels
int64_t video_chunk_offset
unsigned int video_height
int decode_map_chunk_size
int64_t decode_map_chunk_offset
int64_t skip_map_chunk_offset
int64_t next_chunk_offset
enum AVCodecID audio_type
unsigned int audio_frame_count