2003-09-02 04:32:02 +00:00
|
|
|
/*
|
|
|
|
* Interplay MVE File Demuxer
|
2014-08-23 19:39:22 +00:00
|
|
|
* Copyright (c) 2003 The FFmpeg Project
|
2003-09-02 04:32:02 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2003-09-02 04:32:02 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-09-02 04:32:02 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2003-09-02 04:32:02 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-09-02 04:32:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2003-09-02 04:32:02 +00:00
|
|
|
* Interplay MVE file demuxer
|
|
|
|
* by Mike Melanson (melanson@pcisys.net)
|
|
|
|
* For more information regarding the Interplay MVE file format, visit:
|
|
|
|
* http://www.pcisys.net/~melanson/codecs/
|
|
|
|
* The aforementioned site also contains a command line utility for parsing
|
|
|
|
* IP MVE files so that you can get a good idea of the typical structure of
|
|
|
|
* such files. This demuxer is not the best example to use if you are trying
|
|
|
|
* to write your own as it uses a rather roundabout approach for splitting
|
|
|
|
* up and sending out the chunks.
|
|
|
|
*/
|
|
|
|
|
2012-04-07 20:44:46 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2009-01-11 22:19:48 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2003-09-02 04:32:02 +00:00
|
|
|
#include "avformat.h"
|
2011-11-29 18:28:15 +00:00
|
|
|
#include "internal.h"
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
#define CHUNK_PREAMBLE_SIZE 4
|
|
|
|
#define OPCODE_PREAMBLE_SIZE 4
|
|
|
|
|
|
|
|
#define CHUNK_INIT_AUDIO 0x0000
|
|
|
|
#define CHUNK_AUDIO_ONLY 0x0001
|
|
|
|
#define CHUNK_INIT_VIDEO 0x0002
|
|
|
|
#define CHUNK_VIDEO 0x0003
|
|
|
|
#define CHUNK_SHUTDOWN 0x0004
|
|
|
|
#define CHUNK_END 0x0005
|
|
|
|
/* these last types are used internally */
|
|
|
|
#define CHUNK_DONE 0xFFFC
|
|
|
|
#define CHUNK_NOMEM 0xFFFD
|
|
|
|
#define CHUNK_EOF 0xFFFE
|
|
|
|
#define CHUNK_BAD 0xFFFF
|
|
|
|
|
|
|
|
#define OPCODE_END_OF_STREAM 0x00
|
|
|
|
#define OPCODE_END_OF_CHUNK 0x01
|
|
|
|
#define OPCODE_CREATE_TIMER 0x02
|
|
|
|
#define OPCODE_INIT_AUDIO_BUFFERS 0x03
|
|
|
|
#define OPCODE_START_STOP_AUDIO 0x04
|
|
|
|
#define OPCODE_INIT_VIDEO_BUFFERS 0x05
|
|
|
|
#define OPCODE_UNKNOWN_06 0x06
|
|
|
|
#define OPCODE_SEND_BUFFER 0x07
|
|
|
|
#define OPCODE_AUDIO_FRAME 0x08
|
|
|
|
#define OPCODE_SILENCE_FRAME 0x09
|
|
|
|
#define OPCODE_INIT_VIDEO_MODE 0x0A
|
|
|
|
#define OPCODE_CREATE_GRADIENT 0x0B
|
|
|
|
#define OPCODE_SET_PALETTE 0x0C
|
|
|
|
#define OPCODE_SET_PALETTE_COMPRESSED 0x0D
|
|
|
|
#define OPCODE_UNKNOWN_0E 0x0E
|
|
|
|
#define OPCODE_SET_DECODING_MAP 0x0F
|
|
|
|
#define OPCODE_UNKNOWN_10 0x10
|
|
|
|
#define OPCODE_VIDEO_DATA 0x11
|
|
|
|
#define OPCODE_UNKNOWN_12 0x12
|
|
|
|
#define OPCODE_UNKNOWN_13 0x13
|
|
|
|
#define OPCODE_UNKNOWN_14 0x14
|
|
|
|
#define OPCODE_UNKNOWN_15 0x15
|
|
|
|
|
|
|
|
#define PALETTE_COUNT 256
|
|
|
|
|
|
|
|
typedef struct IPMVEContext {
|
2015-07-26 01:41:57 +00:00
|
|
|
AVFormatContext *avf;
|
2003-09-02 04:32:02 +00:00
|
|
|
unsigned char *buf;
|
|
|
|
int buf_size;
|
|
|
|
|
2009-02-27 10:07:12 +00:00
|
|
|
uint64_t frame_pts_inc;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2009-12-27 08:21:40 +00:00
|
|
|
unsigned int video_bpp;
|
2003-09-02 04:32:02 +00:00
|
|
|
unsigned int video_width;
|
|
|
|
unsigned int video_height;
|
|
|
|
int64_t video_pts;
|
2011-04-09 13:49:51 +00:00
|
|
|
uint32_t palette[256];
|
|
|
|
int has_palette;
|
2012-01-06 01:09:06 +00:00
|
|
|
int changed;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
unsigned int audio_bits;
|
|
|
|
unsigned int audio_channels;
|
|
|
|
unsigned int audio_sample_rate;
|
2012-08-05 09:11:04 +00:00
|
|
|
enum AVCodecID audio_type;
|
2003-09-02 04:32:02 +00:00
|
|
|
unsigned int audio_frame_count;
|
|
|
|
|
|
|
|
int video_stream_index;
|
|
|
|
int audio_stream_index;
|
|
|
|
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t audio_chunk_offset;
|
2003-09-02 04:32:02 +00:00
|
|
|
int audio_chunk_size;
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t video_chunk_offset;
|
2003-09-02 04:32:02 +00:00
|
|
|
int video_chunk_size;
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t decode_map_chunk_offset;
|
2003-09-02 04:32:02 +00:00
|
|
|
int decode_map_chunk_size;
|
|
|
|
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t next_chunk_offset;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
} IPMVEContext;
|
|
|
|
|
2011-02-20 10:04:12 +00:00
|
|
|
static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb,
|
2003-09-02 04:32:02 +00:00
|
|
|
AVPacket *pkt) {
|
|
|
|
|
|
|
|
int chunk_type;
|
|
|
|
|
2011-12-21 21:02:01 +00:00
|
|
|
if (s->audio_chunk_offset && s->audio_channels && s->audio_bits) {
|
2012-08-05 09:11:04 +00:00
|
|
|
if (s->audio_type == AV_CODEC_ID_NONE) {
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_ERROR, "Can not read audio packet before"
|
2012-01-05 20:57:22 +00:00
|
|
|
"audio codec is known\n");
|
|
|
|
return CHUNK_BAD;
|
|
|
|
}
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2003-09-18 04:25:41 +00:00
|
|
|
/* adjust for PCM audio by skipping chunk header */
|
2012-08-05 09:11:04 +00:00
|
|
|
if (s->audio_type != AV_CODEC_ID_INTERPLAY_DPCM) {
|
2003-09-18 04:25:41 +00:00
|
|
|
s->audio_chunk_offset += 6;
|
|
|
|
s->audio_chunk_size -= 6;
|
|
|
|
}
|
|
|
|
|
2011-02-28 13:57:54 +00:00
|
|
|
avio_seek(pb, s->audio_chunk_offset, SEEK_SET);
|
2003-09-02 04:32:02 +00:00
|
|
|
s->audio_chunk_offset = 0;
|
|
|
|
|
2005-05-26 20:17:12 +00:00
|
|
|
if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size))
|
|
|
|
return CHUNK_EOF;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
pkt->stream_index = s->audio_stream_index;
|
2009-02-27 10:07:12 +00:00
|
|
|
pkt->pts = s->audio_frame_count;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
/* audio frame maintenance */
|
2012-08-05 09:11:04 +00:00
|
|
|
if (s->audio_type != AV_CODEC_ID_INTERPLAY_DPCM)
|
2003-09-02 04:32:02 +00:00
|
|
|
s->audio_frame_count +=
|
|
|
|
(s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8));
|
|
|
|
else
|
|
|
|
s->audio_frame_count +=
|
2012-01-10 13:48:23 +00:00
|
|
|
(s->audio_chunk_size - 6 - s->audio_channels) / s->audio_channels;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "sending audio frame with pts %"PRId64" (%d audio frames)\n",
|
2011-06-02 20:49:53 +00:00
|
|
|
pkt->pts, s->audio_frame_count);
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
chunk_type = CHUNK_VIDEO;
|
|
|
|
|
|
|
|
} else if (s->decode_map_chunk_offset) {
|
|
|
|
|
2003-09-14 18:56:45 +00:00
|
|
|
/* send both the decode map and the video data together */
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2015-11-01 16:02:26 +00:00
|
|
|
if (av_new_packet(pkt, 2 + s->decode_map_chunk_size + s->video_chunk_size))
|
2003-09-02 04:32:02 +00:00
|
|
|
return CHUNK_NOMEM;
|
|
|
|
|
2011-04-09 13:49:51 +00:00
|
|
|
if (s->has_palette) {
|
|
|
|
uint8_t *pal;
|
|
|
|
|
|
|
|
pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
|
|
|
|
AVPALETTE_SIZE);
|
|
|
|
if (pal) {
|
|
|
|
memcpy(pal, s->palette, AVPALETTE_SIZE);
|
|
|
|
s->has_palette = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-06 01:09:06 +00:00
|
|
|
if (s->changed) {
|
|
|
|
ff_add_param_change(pkt, 0, 0, 0, s->video_width, s->video_height);
|
|
|
|
s->changed = 0;
|
|
|
|
}
|
2005-05-26 20:17:12 +00:00
|
|
|
pkt->pos= s->decode_map_chunk_offset;
|
2011-02-28 13:57:54 +00:00
|
|
|
avio_seek(pb, s->decode_map_chunk_offset, SEEK_SET);
|
2003-09-14 18:56:45 +00:00
|
|
|
s->decode_map_chunk_offset = 0;
|
|
|
|
|
2015-11-01 16:02:26 +00:00
|
|
|
AV_WL16(pkt->data, s->decode_map_chunk_size);
|
|
|
|
if (avio_read(pb, pkt->data + 2, s->decode_map_chunk_size) !=
|
2003-09-02 04:32:02 +00:00
|
|
|
s->decode_map_chunk_size) {
|
2015-10-23 09:11:31 +00:00
|
|
|
av_packet_unref(pkt);
|
2003-09-02 04:32:02 +00:00
|
|
|
return CHUNK_EOF;
|
|
|
|
}
|
|
|
|
|
2011-02-28 13:57:54 +00:00
|
|
|
avio_seek(pb, s->video_chunk_offset, SEEK_SET);
|
2003-09-02 04:32:02 +00:00
|
|
|
s->video_chunk_offset = 0;
|
|
|
|
|
2015-11-01 16:02:26 +00:00
|
|
|
if (avio_read(pb, pkt->data + 2 + s->decode_map_chunk_size,
|
2003-09-14 18:56:45 +00:00
|
|
|
s->video_chunk_size) != s->video_chunk_size) {
|
2015-10-23 09:11:31 +00:00
|
|
|
av_packet_unref(pkt);
|
2003-09-02 04:32:02 +00:00
|
|
|
return CHUNK_EOF;
|
|
|
|
}
|
|
|
|
|
2003-09-14 18:56:45 +00:00
|
|
|
pkt->stream_index = s->video_stream_index;
|
|
|
|
pkt->pts = s->video_pts;
|
|
|
|
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "sending video frame with pts %"PRId64"\n", pkt->pts);
|
2003-10-02 04:16:59 +00:00
|
|
|
|
2003-09-02 04:32:02 +00:00
|
|
|
s->video_pts += s->frame_pts_inc;
|
|
|
|
|
|
|
|
chunk_type = CHUNK_VIDEO;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2011-02-28 13:57:54 +00:00
|
|
|
avio_seek(pb, s->next_chunk_offset, SEEK_SET);
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_DONE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return chunk_type;
|
|
|
|
}
|
|
|
|
|
2015-07-26 01:39:55 +00:00
|
|
|
static int init_audio(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
IPMVEContext *ipmovie = s->priv_data;
|
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
avpriv_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate);
|
|
|
|
ipmovie->audio_stream_index = st->index;
|
2016-04-10 19:58:15 +00:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
st->codecpar->codec_id = ipmovie->audio_type;
|
|
|
|
st->codecpar->codec_tag = 0; /* no tag */
|
|
|
|
st->codecpar->channels = ipmovie->audio_channels;
|
|
|
|
st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :
|
2015-07-26 01:39:55 +00:00
|
|
|
AV_CH_LAYOUT_STEREO;
|
2016-04-10 19:58:15 +00:00
|
|
|
st->codecpar->sample_rate = ipmovie->audio_sample_rate;
|
|
|
|
st->codecpar->bits_per_coded_sample = ipmovie->audio_bits;
|
|
|
|
st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate *
|
|
|
|
st->codecpar->bits_per_coded_sample;
|
|
|
|
if (st->codecpar->codec_id == AV_CODEC_ID_INTERPLAY_DPCM)
|
|
|
|
st->codecpar->bit_rate /= 2;
|
|
|
|
st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample;
|
2015-07-26 01:39:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-02 04:32:02 +00:00
|
|
|
/* This function loads and processes a single chunk in an IP movie file.
|
|
|
|
* It returns the type of chunk that was processed. */
|
2011-02-20 10:04:12 +00:00
|
|
|
static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb,
|
2003-09-02 04:32:02 +00:00
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
|
|
|
unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
|
|
|
|
int chunk_type;
|
|
|
|
int chunk_size;
|
|
|
|
unsigned char opcode_preamble[OPCODE_PREAMBLE_SIZE];
|
|
|
|
unsigned char opcode_type;
|
|
|
|
unsigned char opcode_version;
|
|
|
|
int opcode_size;
|
|
|
|
unsigned char scratch[1024];
|
2003-09-14 18:56:45 +00:00
|
|
|
int i, j;
|
2003-09-02 04:32:02 +00:00
|
|
|
int first_color, last_color;
|
|
|
|
int audio_flags;
|
2003-10-30 05:40:58 +00:00
|
|
|
unsigned char r, g, b;
|
2012-01-06 01:09:06 +00:00
|
|
|
unsigned int width, height;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
/* see if there are any pending packets */
|
|
|
|
chunk_type = load_ipmovie_packet(s, pb, pkt);
|
2007-02-17 02:46:47 +00:00
|
|
|
if (chunk_type != CHUNK_DONE)
|
2003-09-02 04:32:02 +00:00
|
|
|
return chunk_type;
|
|
|
|
|
|
|
|
/* read the next chunk, wherever the file happens to be pointing */
|
2014-08-07 20:12:41 +00:00
|
|
|
if (avio_feof(pb))
|
2003-09-02 04:32:02 +00:00
|
|
|
return CHUNK_EOF;
|
2011-02-21 15:43:01 +00:00
|
|
|
if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
|
2003-09-02 04:32:02 +00:00
|
|
|
CHUNK_PREAMBLE_SIZE)
|
|
|
|
return CHUNK_BAD;
|
2007-01-19 22:12:59 +00:00
|
|
|
chunk_size = AV_RL16(&chunk_preamble[0]);
|
|
|
|
chunk_type = AV_RL16(&chunk_preamble[2]);
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
switch (chunk_type) {
|
|
|
|
|
|
|
|
case CHUNK_INIT_AUDIO:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "initialize audio\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHUNK_AUDIO_ONLY:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "audio only\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHUNK_INIT_VIDEO:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "initialize video\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHUNK_VIDEO:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "video (and audio)\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHUNK_SHUTDOWN:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "shutdown\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHUNK_END:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "end\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "invalid chunk\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((chunk_size > 0) && (chunk_type != CHUNK_BAD)) {
|
|
|
|
|
|
|
|
/* read the next chunk, wherever the file happens to be pointing */
|
2014-08-07 20:12:41 +00:00
|
|
|
if (avio_feof(pb)) {
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_EOF;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-21 15:43:01 +00:00
|
|
|
if (avio_read(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) !=
|
2003-09-02 04:32:02 +00:00
|
|
|
CHUNK_PREAMBLE_SIZE) {
|
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-19 22:12:59 +00:00
|
|
|
opcode_size = AV_RL16(&opcode_preamble[0]);
|
2003-09-02 04:32:02 +00:00
|
|
|
opcode_type = opcode_preamble[2];
|
|
|
|
opcode_version = opcode_preamble[3];
|
|
|
|
|
|
|
|
chunk_size -= OPCODE_PREAMBLE_SIZE;
|
|
|
|
chunk_size -= opcode_size;
|
|
|
|
if (chunk_size < 0) {
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "chunk_size countdown just went negative\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, " opcode type %02X, version %d, 0x%04X bytes: ",
|
2011-06-02 20:49:53 +00:00
|
|
|
opcode_type, opcode_version, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
switch (opcode_type) {
|
|
|
|
|
|
|
|
case OPCODE_END_OF_STREAM:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "end of stream\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_END_OF_CHUNK:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "end of chunk\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_CREATE_TIMER:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "create timer\n");
|
2013-12-14 20:22:14 +00:00
|
|
|
if ((opcode_version > 0) || (opcode_size != 6)) {
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "bad create_timer opcode\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-21 15:43:01 +00:00
|
|
|
if (avio_read(pb, scratch, opcode_size) !=
|
2003-09-02 04:32:02 +00:00
|
|
|
opcode_size) {
|
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-27 10:07:12 +00:00
|
|
|
s->frame_pts_inc = ((uint64_t)AV_RL32(&scratch[0])) * AV_RL16(&scratch[4]);
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, " %.2f frames/second (timer div = %d, subdiv = %d)\n",
|
2011-06-02 20:49:53 +00:00
|
|
|
1000000.0 / s->frame_pts_inc, AV_RL32(&scratch[0]),
|
|
|
|
AV_RL16(&scratch[4]));
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_INIT_AUDIO_BUFFERS:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "initialize audio buffers\n");
|
2013-12-18 22:15:52 +00:00
|
|
|
if (opcode_version > 1 || opcode_size > 10 || opcode_size < 6) {
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "bad init_audio_buffers opcode\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-21 15:43:01 +00:00
|
|
|
if (avio_read(pb, scratch, opcode_size) !=
|
2003-09-02 04:32:02 +00:00
|
|
|
opcode_size) {
|
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-19 22:12:59 +00:00
|
|
|
s->audio_sample_rate = AV_RL16(&scratch[4]);
|
|
|
|
audio_flags = AV_RL16(&scratch[2]);
|
2003-09-02 04:32:02 +00:00
|
|
|
/* bit 0 of the flags: 0 = mono, 1 = stereo */
|
|
|
|
s->audio_channels = (audio_flags & 1) + 1;
|
|
|
|
/* bit 1 of the flags: 0 = 8 bit, 1 = 16 bit */
|
|
|
|
s->audio_bits = (((audio_flags >> 1) & 1) + 1) * 8;
|
|
|
|
/* bit 2 indicates compressed audio in version 1 opcode */
|
|
|
|
if ((opcode_version == 1) && (audio_flags & 0x4))
|
2012-08-05 09:11:04 +00:00
|
|
|
s->audio_type = AV_CODEC_ID_INTERPLAY_DPCM;
|
2003-09-02 04:32:02 +00:00
|
|
|
else if (s->audio_bits == 16)
|
2012-08-05 09:11:04 +00:00
|
|
|
s->audio_type = AV_CODEC_ID_PCM_S16LE;
|
2003-09-02 04:32:02 +00:00
|
|
|
else
|
2012-08-05 09:11:04 +00:00
|
|
|
s->audio_type = AV_CODEC_ID_PCM_U8;
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "audio: %d bits, %d Hz, %s, %s format\n",
|
2011-06-02 20:49:53 +00:00
|
|
|
s->audio_bits, s->audio_sample_rate,
|
|
|
|
(s->audio_channels == 2) ? "stereo" : "mono",
|
2012-08-05 09:11:04 +00:00
|
|
|
(s->audio_type == AV_CODEC_ID_INTERPLAY_DPCM) ?
|
2011-06-02 20:49:53 +00:00
|
|
|
"Interplay audio" : "PCM");
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_START_STOP_AUDIO:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "start/stop audio\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_INIT_VIDEO_BUFFERS:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "initialize video buffers\n");
|
2013-12-13 18:50:34 +00:00
|
|
|
if ((opcode_version > 2) || (opcode_size > 8) || opcode_size < 4
|
|
|
|
|| opcode_version == 2 && opcode_size < 8
|
|
|
|
) {
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "bad init_video_buffers opcode\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-21 15:43:01 +00:00
|
|
|
if (avio_read(pb, scratch, opcode_size) !=
|
2003-09-02 04:32:02 +00:00
|
|
|
opcode_size) {
|
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-06 01:09:06 +00:00
|
|
|
width = AV_RL16(&scratch[0]) * 8;
|
|
|
|
height = AV_RL16(&scratch[2]) * 8;
|
|
|
|
if (width != s->video_width) {
|
|
|
|
s->video_width = width;
|
|
|
|
s->changed++;
|
|
|
|
}
|
|
|
|
if (height != s->video_height) {
|
|
|
|
s->video_height = height;
|
|
|
|
s->changed++;
|
|
|
|
}
|
2009-12-27 08:21:40 +00:00
|
|
|
if (opcode_version < 2 || !AV_RL16(&scratch[6])) {
|
|
|
|
s->video_bpp = 8;
|
|
|
|
} else {
|
|
|
|
s->video_bpp = 16;
|
|
|
|
}
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "video resolution: %d x %d\n",
|
2011-06-02 20:49:53 +00:00
|
|
|
s->video_width, s->video_height);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_UNKNOWN_06:
|
|
|
|
case OPCODE_UNKNOWN_0E:
|
|
|
|
case OPCODE_UNKNOWN_10:
|
|
|
|
case OPCODE_UNKNOWN_12:
|
|
|
|
case OPCODE_UNKNOWN_13:
|
|
|
|
case OPCODE_UNKNOWN_14:
|
|
|
|
case OPCODE_UNKNOWN_15:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "unknown (but documented) opcode %02X\n", opcode_type);
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_SEND_BUFFER:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "send buffer\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_AUDIO_FRAME:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "audio frame\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
/* log position and move on for now */
|
2011-03-03 19:11:45 +00:00
|
|
|
s->audio_chunk_offset = avio_tell(pb);
|
2003-09-02 04:32:02 +00:00
|
|
|
s->audio_chunk_size = opcode_size;
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_SILENCE_FRAME:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "silence frame\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_INIT_VIDEO_MODE:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "initialize video mode\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_CREATE_GRADIENT:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "create gradient\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_SET_PALETTE:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "set palette\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
/* check for the logical maximum palette size
|
|
|
|
* (3 * 256 + 4 bytes) */
|
2013-12-18 22:43:20 +00:00
|
|
|
if (opcode_size > 0x304 || opcode_size < 4) {
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "demux_ipmovie: set_palette opcode with invalid size\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-21 15:43:01 +00:00
|
|
|
if (avio_read(pb, scratch, opcode_size) != opcode_size) {
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load the palette into internal data structure */
|
2007-01-19 22:12:59 +00:00
|
|
|
first_color = AV_RL16(&scratch[0]);
|
|
|
|
last_color = first_color + AV_RL16(&scratch[2]) - 1;
|
2003-09-02 04:32:02 +00:00
|
|
|
/* sanity check (since they are 16 bit values) */
|
2013-12-18 22:46:37 +00:00
|
|
|
if ( (first_color > 0xFF) || (last_color > 0xFF)
|
|
|
|
|| (last_color - first_color + 1)*3 + 4 > opcode_size) {
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "demux_ipmovie: set_palette indexes out of range (%d -> %d)\n",
|
2003-09-02 04:32:02 +00:00
|
|
|
first_color, last_color);
|
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
j = 4; /* offset of first palette data */
|
|
|
|
for (i = first_color; i <= last_color; i++) {
|
2003-09-14 18:56:45 +00:00
|
|
|
/* the palette is stored as a 6-bit VGA palette, thus each
|
|
|
|
* component is shifted up to a 8-bit range */
|
2003-10-30 05:40:58 +00:00
|
|
|
r = scratch[j++] * 4;
|
|
|
|
g = scratch[j++] * 4;
|
|
|
|
b = scratch[j++] * 4;
|
2011-12-27 17:26:31 +00:00
|
|
|
s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | (b);
|
|
|
|
s->palette[i] |= s->palette[i] >> 6 & 0x30303;
|
2003-09-02 04:32:02 +00:00
|
|
|
}
|
2011-04-09 13:49:51 +00:00
|
|
|
s->has_palette = 1;
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_SET_PALETTE_COMPRESSED:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "set palette compressed\n");
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_SET_DECODING_MAP:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "set decoding map\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
/* log position and move on for now */
|
2011-03-03 19:11:45 +00:00
|
|
|
s->decode_map_chunk_offset = avio_tell(pb);
|
2003-09-02 04:32:02 +00:00
|
|
|
s->decode_map_chunk_size = opcode_size;
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPCODE_VIDEO_DATA:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "set video data\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
/* log position and move on for now */
|
2011-03-03 19:11:45 +00:00
|
|
|
s->video_chunk_offset = avio_tell(pb);
|
2003-09-02 04:32:02 +00:00
|
|
|
s->video_chunk_size = opcode_size;
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, opcode_size);
|
2003-09-02 04:32:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-11-02 08:00:53 +00:00
|
|
|
av_log(s->avf, AV_LOG_TRACE, "*** unknown opcode type\n");
|
2003-09-02 04:32:02 +00:00
|
|
|
chunk_type = CHUNK_BAD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-26 01:41:57 +00:00
|
|
|
if (s->avf->nb_streams == 1 && s->audio_type)
|
|
|
|
init_audio(s->avf);
|
|
|
|
|
2003-09-02 04:32:02 +00:00
|
|
|
/* make a note of where the stream is sitting */
|
2011-03-03 19:11:45 +00:00
|
|
|
s->next_chunk_offset = avio_tell(pb);
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
/* dispatch the first of any pending packets */
|
|
|
|
if ((chunk_type == CHUNK_VIDEO) || (chunk_type == CHUNK_AUDIO_ONLY))
|
|
|
|
chunk_type = load_ipmovie_packet(s, pb, pkt);
|
|
|
|
|
|
|
|
return chunk_type;
|
|
|
|
}
|
|
|
|
|
2009-09-05 11:30:55 +00:00
|
|
|
static const char signature[] = "Interplay MVE File\x1A\0\x1A";
|
|
|
|
|
2003-09-02 04:32:02 +00:00
|
|
|
static int ipmovie_probe(AVProbeData *p)
|
|
|
|
{
|
2012-12-25 00:44:59 +00:00
|
|
|
const uint8_t *b = p->buf;
|
|
|
|
const uint8_t *b_end = p->buf + p->buf_size - sizeof(signature);
|
2009-09-05 15:41:32 +00:00
|
|
|
do {
|
2012-05-31 14:19:26 +00:00
|
|
|
if (b[0] == signature[0] && memcmp(b, signature, sizeof(signature)) == 0)
|
2009-09-05 15:41:32 +00:00
|
|
|
return AVPROBE_SCORE_MAX;
|
2012-05-31 14:19:26 +00:00
|
|
|
b++;
|
2009-09-05 15:41:32 +00:00
|
|
|
} while (b < b_end);
|
|
|
|
|
|
|
|
return 0;
|
2003-09-02 04:32:02 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 12:20:36 +00:00
|
|
|
static int ipmovie_read_header(AVFormatContext *s)
|
2003-09-02 04:32:02 +00:00
|
|
|
{
|
2007-04-08 20:24:16 +00:00
|
|
|
IPMVEContext *ipmovie = s->priv_data;
|
2011-02-20 10:04:12 +00:00
|
|
|
AVIOContext *pb = s->pb;
|
2003-09-02 04:32:02 +00:00
|
|
|
AVPacket pkt;
|
|
|
|
AVStream *st;
|
2003-10-02 04:16:59 +00:00
|
|
|
unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
|
2011-12-27 17:26:31 +00:00
|
|
|
int chunk_type, i;
|
2009-09-05 15:41:32 +00:00
|
|
|
uint8_t signature_buffer[sizeof(signature)];
|
|
|
|
|
2015-07-26 01:41:57 +00:00
|
|
|
ipmovie->avf = s;
|
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
avio_read(pb, signature_buffer, sizeof(signature_buffer));
|
2009-09-05 15:41:32 +00:00
|
|
|
while (memcmp(signature_buffer, signature, sizeof(signature))) {
|
|
|
|
memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1);
|
2011-02-21 15:43:01 +00:00
|
|
|
signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb);
|
2014-08-07 20:12:41 +00:00
|
|
|
if (avio_feof(pb))
|
2009-09-05 15:41:32 +00:00
|
|
|
return AVERROR_EOF;
|
|
|
|
}
|
2003-09-02 04:32:02 +00:00
|
|
|
/* initialize private context members */
|
|
|
|
ipmovie->video_pts = ipmovie->audio_frame_count = 0;
|
|
|
|
ipmovie->audio_chunk_offset = ipmovie->video_chunk_offset =
|
|
|
|
ipmovie->decode_map_chunk_offset = 0;
|
|
|
|
|
|
|
|
/* on the first read, this will position the stream at the first chunk */
|
2011-03-03 19:11:45 +00:00
|
|
|
ipmovie->next_chunk_offset = avio_tell(pb) + 4;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2011-12-27 17:26:31 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
ipmovie->palette[i] = 0xFFU << 24;
|
|
|
|
|
2003-09-02 04:32:02 +00:00
|
|
|
/* process the first chunk which should be CHUNK_INIT_VIDEO */
|
|
|
|
if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2003-10-02 04:16:59 +00:00
|
|
|
/* 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 */
|
2011-02-21 15:43:01 +00:00
|
|
|
if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
|
2003-10-02 04:16:59 +00:00
|
|
|
CHUNK_PREAMBLE_SIZE)
|
2007-07-19 15:23:32 +00:00
|
|
|
return AVERROR(EIO);
|
2007-01-19 22:12:59 +00:00
|
|
|
chunk_type = AV_RL16(&chunk_preamble[2]);
|
2011-02-28 13:57:54 +00:00
|
|
|
avio_seek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
|
2003-10-02 04:16:59 +00:00
|
|
|
|
|
|
|
if (chunk_type == CHUNK_VIDEO)
|
2012-08-05 09:11:04 +00:00
|
|
|
ipmovie->audio_type = AV_CODEC_ID_NONE; /* no audio */
|
2003-10-02 04:16:59 +00:00
|
|
|
else if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
|
2003-09-02 04:32:02 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
/* initialize the stream decoders */
|
2011-06-18 09:43:24 +00:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2003-09-02 04:32:02 +00:00
|
|
|
if (!st)
|
2007-07-19 15:21:30 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2011-11-29 18:28:15 +00:00
|
|
|
avpriv_set_pts_info(st, 63, 1, 1000000);
|
2003-09-02 04:32:02 +00:00
|
|
|
ipmovie->video_stream_index = st->index;
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_INTERPLAY_VIDEO;
|
|
|
|
st->codecpar->codec_tag = 0; /* no fourcc */
|
|
|
|
st->codecpar->width = ipmovie->video_width;
|
|
|
|
st->codecpar->height = ipmovie->video_height;
|
|
|
|
st->codecpar->bits_per_coded_sample = ipmovie->video_bpp;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2003-10-02 04:16:59 +00:00
|
|
|
if (ipmovie->audio_type) {
|
2015-07-26 01:39:55 +00:00
|
|
|
return init_audio(s);
|
2015-07-26 02:00:02 +00:00
|
|
|
} else
|
|
|
|
s->ctx_flags |= AVFMTCTX_NOHEADER;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipmovie_read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
2007-04-08 20:24:16 +00:00
|
|
|
IPMVEContext *ipmovie = s->priv_data;
|
2011-02-20 10:04:12 +00:00
|
|
|
AVIOContext *pb = s->pb;
|
2003-09-02 04:32:02 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-01-08 17:37:19 +00:00
|
|
|
for (;;) {
|
2003-09-02 04:32:02 +00:00
|
|
|
ret = process_ipmovie_chunk(ipmovie, pb, pkt);
|
|
|
|
if (ret == CHUNK_BAD)
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
else if (ret == CHUNK_EOF)
|
2007-07-19 15:23:32 +00:00
|
|
|
ret = AVERROR(EIO);
|
2003-09-02 04:32:02 +00:00
|
|
|
else if (ret == CHUNK_NOMEM)
|
2007-07-19 15:21:30 +00:00
|
|
|
ret = AVERROR(ENOMEM);
|
2007-02-17 02:46:47 +00:00
|
|
|
else if (ret == CHUNK_VIDEO)
|
2003-09-02 04:32:02 +00:00
|
|
|
ret = 0;
|
2012-01-08 17:37:19 +00:00
|
|
|
else if (ret == CHUNK_INIT_VIDEO || ret == CHUNK_INIT_AUDIO)
|
|
|
|
continue;
|
2007-02-17 02:46:47 +00:00
|
|
|
else
|
2015-07-26 02:00:02 +00:00
|
|
|
continue;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
|
|
|
return ret;
|
2012-01-08 17:37:19 +00:00
|
|
|
}
|
2003-09-02 04:32:02 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 22:03:28 +00:00
|
|
|
AVInputFormat ff_ipmovie_demuxer = {
|
2011-07-16 20:18:12 +00:00
|
|
|
.name = "ipmovie",
|
2012-07-24 21:51:41 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Interplay MVE"),
|
2011-07-16 20:18:12 +00:00
|
|
|
.priv_data_size = sizeof(IPMVEContext),
|
|
|
|
.read_probe = ipmovie_probe,
|
|
|
|
.read_header = ipmovie_read_header,
|
|
|
|
.read_packet = ipmovie_read_packet,
|
2003-09-02 04:32:02 +00:00
|
|
|
};
|