2004-01-02 06:47:02 +02:00
|
|
|
/*
|
|
|
|
* Sierra VMD Format Demuxer
|
2016-04-27 19:45:23 +02:00
|
|
|
* Copyright (c) 2004 The FFmpeg project
|
2004-01-02 06:47:02 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2004-01-02 06:47:02 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-01-02 06:47:02 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2004-01-02 06:47:02 +02: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 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-01-02 06:47:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2004-01-02 06:47:02 +02:00
|
|
|
* Sierra VMD file demuxer
|
|
|
|
* by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
|
2004-03-14 06:08:11 +02:00
|
|
|
* for more information on the Sierra VMD file format, visit:
|
|
|
|
* http://www.pcisys.net/~melanson/codecs/
|
2004-01-02 06:47:02 +02:00
|
|
|
*/
|
|
|
|
|
2012-04-08 01:32:13 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2009-01-12 00:19:48 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2004-01-02 06:47:02 +02:00
|
|
|
#include "avformat.h"
|
2011-11-29 21:28:15 +03:00
|
|
|
#include "internal.h"
|
2011-12-25 00:06:25 +03:00
|
|
|
#include "avio_internal.h"
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
#define VMD_HEADER_SIZE 0x0330
|
|
|
|
#define BYTES_PER_FRAME_RECORD 16
|
|
|
|
|
2014-09-22 10:19:33 +03:00
|
|
|
typedef struct vmd_frame {
|
2004-01-02 06:47:02 +02:00
|
|
|
int stream_index;
|
2008-10-03 13:16:29 +03:00
|
|
|
int64_t frame_offset;
|
2004-01-02 06:47:02 +02:00
|
|
|
unsigned int frame_size;
|
|
|
|
int64_t pts;
|
|
|
|
int keyframe;
|
|
|
|
unsigned char frame_record[BYTES_PER_FRAME_RECORD];
|
2008-12-14 05:29:33 +02:00
|
|
|
} vmd_frame;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
typedef struct VmdDemuxContext {
|
|
|
|
int video_stream_index;
|
|
|
|
int audio_stream_index;
|
|
|
|
|
|
|
|
unsigned int frame_count;
|
2006-03-11 06:27:58 +02:00
|
|
|
unsigned int frames_per_block;
|
2008-12-14 05:29:33 +02:00
|
|
|
vmd_frame *frame_table;
|
2004-01-02 06:47:02 +02:00
|
|
|
unsigned int current_frame;
|
2008-12-27 19:34:00 +02:00
|
|
|
int is_indeo3;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
2004-03-14 06:08:11 +02:00
|
|
|
int sample_rate;
|
|
|
|
int64_t audio_sample_counter;
|
2006-03-11 06:27:58 +02:00
|
|
|
int skiphdr;
|
2004-03-14 06:08:11 +02:00
|
|
|
|
2004-01-02 06:47:02 +02:00
|
|
|
unsigned char vmd_header[VMD_HEADER_SIZE];
|
|
|
|
} VmdDemuxContext;
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int vmd_probe(const AVProbeData *p)
|
2004-01-02 06:47:02 +02:00
|
|
|
{
|
2013-05-05 20:52:30 +03:00
|
|
|
int w, h, sample_rate;
|
|
|
|
if (p->buf_size < 806)
|
2009-09-15 12:16:29 +03:00
|
|
|
return 0;
|
2004-01-02 06:47:02 +02:00
|
|
|
/* check if the first 2 bytes of the file contain the appropriate size
|
|
|
|
* of a VMD header chunk */
|
2007-01-20 00:12:59 +02:00
|
|
|
if (AV_RL16(&p->buf[0]) != VMD_HEADER_SIZE - 2)
|
2004-01-02 06:47:02 +02:00
|
|
|
return 0;
|
2009-09-15 12:16:29 +03:00
|
|
|
w = AV_RL16(&p->buf[12]);
|
|
|
|
h = AV_RL16(&p->buf[14]);
|
2013-05-05 20:52:30 +03:00
|
|
|
sample_rate = AV_RL16(&p->buf[804]);
|
|
|
|
if ((!w || w > 2048 || !h || h > 2048) &&
|
|
|
|
sample_rate != 22050)
|
2009-09-15 12:16:29 +03:00
|
|
|
return 0;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
/* only return half certainty since this check is a bit sketchy */
|
2013-03-25 18:12:51 +03:00
|
|
|
return AVPROBE_SCORE_EXTENSION;
|
2004-01-02 06:47:02 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 15:20:36 +03:00
|
|
|
static int vmd_read_header(AVFormatContext *s)
|
2004-01-02 06:47:02 +02:00
|
|
|
{
|
2007-04-08 23:24:16 +03:00
|
|
|
VmdDemuxContext *vmd = s->priv_data;
|
2011-02-20 12:04:12 +02:00
|
|
|
AVIOContext *pb = s->pb;
|
2013-05-05 20:52:30 +03:00
|
|
|
AVStream *st = NULL, *vst = NULL;
|
2004-01-02 06:47:02 +02:00
|
|
|
unsigned int toc_offset;
|
|
|
|
unsigned char *raw_frame_table;
|
|
|
|
int raw_frame_table_size;
|
2008-10-03 13:16:29 +03:00
|
|
|
int64_t current_offset;
|
2013-09-11 22:56:55 +03:00
|
|
|
int i, j, ret;
|
2013-09-16 13:32:24 +03:00
|
|
|
int width, height;
|
2004-01-02 06:47:02 +02:00
|
|
|
unsigned int total_frames;
|
2009-01-21 15:27:39 +02:00
|
|
|
int64_t current_audio_pts = 0;
|
2006-03-11 06:27:58 +02:00
|
|
|
unsigned char chunk[BYTES_PER_FRAME_RECORD];
|
2006-11-13 07:18:19 +02:00
|
|
|
int num, den;
|
2006-11-19 07:30:43 +02:00
|
|
|
int sound_buffers;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
/* fetch the main header, including the 2 header length bytes */
|
2011-02-28 15:57:54 +02:00
|
|
|
avio_seek(pb, 0, SEEK_SET);
|
2011-02-21 17:43:01 +02:00
|
|
|
if (avio_read(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
|
2007-07-19 18:23:32 +03:00
|
|
|
return AVERROR(EIO);
|
2004-01-02 06:47:02 +02:00
|
|
|
|
2013-05-05 20:52:30 +03:00
|
|
|
width = AV_RL16(&vmd->vmd_header[12]);
|
|
|
|
height = AV_RL16(&vmd->vmd_header[14]);
|
|
|
|
if (width && height) {
|
2013-05-05 20:56:46 +03:00
|
|
|
if(vmd->vmd_header[24] == 'i' && vmd->vmd_header[25] == 'v' && vmd->vmd_header[26] == '3') {
|
|
|
|
vmd->is_indeo3 = 1;
|
|
|
|
} else {
|
|
|
|
vmd->is_indeo3 = 0;
|
|
|
|
}
|
|
|
|
/* start up the decoders */
|
|
|
|
vst = avformat_new_stream(s, NULL);
|
|
|
|
if (!vst)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
avpriv_set_pts_info(vst, 33, 1, 10);
|
|
|
|
vmd->video_stream_index = vst->index;
|
2016-04-10 21:58:15 +02:00
|
|
|
vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
|
vst->codecpar->codec_id = vmd->is_indeo3 ? AV_CODEC_ID_INDEO3 : AV_CODEC_ID_VMDVIDEO;
|
|
|
|
vst->codecpar->codec_tag = 0; /* no fourcc */
|
|
|
|
vst->codecpar->width = width;
|
|
|
|
vst->codecpar->height = height;
|
|
|
|
if(vmd->is_indeo3 && vst->codecpar->width > 320){
|
|
|
|
vst->codecpar->width >>= 1;
|
|
|
|
vst->codecpar->height >>= 1;
|
2013-05-05 20:56:46 +03:00
|
|
|
}
|
2019-12-10 23:59:53 +02:00
|
|
|
if ((ret = ff_alloc_extradata(vst->codecpar, VMD_HEADER_SIZE)) < 0)
|
|
|
|
return ret;
|
2016-04-10 21:58:15 +02:00
|
|
|
memcpy(vst->codecpar->extradata, vmd->vmd_header, VMD_HEADER_SIZE);
|
2013-05-05 20:52:30 +03:00
|
|
|
}
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
/* if sample rate is 0, assume no audio */
|
2007-01-20 00:12:59 +02:00
|
|
|
vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
|
2004-03-14 06:08:11 +02:00
|
|
|
if (vmd->sample_rate) {
|
2011-06-18 12:43:24 +03:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2004-01-02 06:47:02 +02:00
|
|
|
if (!st)
|
2007-07-19 18:21:30 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2004-01-02 06:47:02 +02:00
|
|
|
vmd->audio_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 21:42:52 +03:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_VMDAUDIO;
|
|
|
|
st->codecpar->codec_tag = 0; /* no fourcc */
|
|
|
|
st->codecpar->sample_rate = vmd->sample_rate;
|
|
|
|
st->codecpar->block_align = AV_RL16(&vmd->vmd_header[806]);
|
|
|
|
if (st->codecpar->block_align & 0x8000) {
|
|
|
|
st->codecpar->bits_per_coded_sample = 16;
|
|
|
|
st->codecpar->block_align = -(st->codecpar->block_align - 0x10000);
|
2006-03-11 06:27:58 +02:00
|
|
|
} else {
|
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 21:42:52 +03:00
|
|
|
st->codecpar->bits_per_coded_sample = 8;
|
2006-03-11 06:27:58 +02:00
|
|
|
}
|
2017-02-18 05:50:11 +02:00
|
|
|
if (vmd->vmd_header[811] & 0x80) {
|
|
|
|
st->codecpar->channels = 2;
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
|
|
|
|
} else if (vmd->vmd_header[811] & 0x2) {
|
|
|
|
/* Shivers 2 stereo audio */
|
|
|
|
/* Frame length is for 1 channel */
|
|
|
|
st->codecpar->channels = 2;
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
|
|
|
|
st->codecpar->block_align = st->codecpar->block_align << 1;
|
|
|
|
} else {
|
|
|
|
st->codecpar->channels = 1;
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
|
|
|
|
}
|
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 21:42:52 +03:00
|
|
|
st->codecpar->bit_rate = st->codecpar->sample_rate *
|
|
|
|
st->codecpar->bits_per_coded_sample * st->codecpar->channels;
|
2004-03-14 06:08:11 +02:00
|
|
|
|
2006-11-13 07:18:19 +02:00
|
|
|
/* calculate pts */
|
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 21:42:52 +03:00
|
|
|
num = st->codecpar->block_align;
|
|
|
|
den = st->codecpar->sample_rate * st->codecpar->channels;
|
2012-10-16 21:03:37 +03:00
|
|
|
av_reduce(&num, &den, num, den, (1UL<<31)-1);
|
2013-05-05 20:52:30 +03:00
|
|
|
if (vst)
|
2013-05-05 20:56:46 +03:00
|
|
|
avpriv_set_pts_info(vst, 33, num, den);
|
2011-11-29 21:28:15 +03:00
|
|
|
avpriv_set_pts_info(st, 33, num, den);
|
2004-01-02 06:47:02 +02:00
|
|
|
}
|
|
|
|
|
2007-01-20 00:12:59 +02:00
|
|
|
toc_offset = AV_RL32(&vmd->vmd_header[812]);
|
|
|
|
vmd->frame_count = AV_RL16(&vmd->vmd_header[6]);
|
|
|
|
vmd->frames_per_block = AV_RL16(&vmd->vmd_header[18]);
|
2011-02-28 15:57:54 +02:00
|
|
|
avio_seek(pb, toc_offset, SEEK_SET);
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
raw_frame_table = NULL;
|
|
|
|
vmd->frame_table = NULL;
|
2007-01-20 00:12:59 +02:00
|
|
|
sound_buffers = AV_RL16(&vmd->vmd_header[808]);
|
2006-03-11 06:27:58 +02:00
|
|
|
raw_frame_table_size = vmd->frame_count * 6;
|
2009-09-16 18:12:23 +03:00
|
|
|
if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame) - sound_buffers){
|
2006-05-13 14:37:56 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "vmd->frame_count * vmd->frames_per_block too large\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-05-29 01:26:35 +03:00
|
|
|
raw_frame_table = av_malloc(raw_frame_table_size);
|
2015-04-12 16:50:19 +02:00
|
|
|
vmd->frame_table = av_malloc_array(vmd->frame_count * vmd->frames_per_block + sound_buffers, sizeof(vmd_frame));
|
2004-01-02 06:47:02 +02:00
|
|
|
if (!raw_frame_table || !vmd->frame_table) {
|
2013-09-11 22:56:55 +03:00
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto error;
|
2004-01-02 06:47:02 +02:00
|
|
|
}
|
2011-02-21 17:43:01 +02:00
|
|
|
if (avio_read(pb, raw_frame_table, raw_frame_table_size) !=
|
2004-01-02 06:47:02 +02:00
|
|
|
raw_frame_table_size) {
|
2013-09-11 22:56:55 +03:00
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto error;
|
2004-01-02 06:47:02 +02:00
|
|
|
}
|
|
|
|
|
2006-03-11 06:27:58 +02:00
|
|
|
total_frames = 0;
|
|
|
|
for (i = 0; i < vmd->frame_count; i++) {
|
|
|
|
|
2007-01-20 00:12:59 +02:00
|
|
|
current_offset = AV_RL32(&raw_frame_table[6 * i + 2]);
|
2006-03-11 06:27:58 +02:00
|
|
|
|
|
|
|
/* handle each entry in index block */
|
|
|
|
for (j = 0; j < vmd->frames_per_block; j++) {
|
|
|
|
int type;
|
|
|
|
uint32_t size;
|
|
|
|
|
2013-12-19 22:48:51 +03:00
|
|
|
if ((ret = avio_read(pb, chunk, BYTES_PER_FRAME_RECORD)) != BYTES_PER_FRAME_RECORD) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Failed to read frame record\n");
|
|
|
|
if (ret >= 0)
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto error;
|
|
|
|
}
|
2006-03-11 06:27:58 +02:00
|
|
|
type = chunk[0];
|
2007-01-20 00:12:59 +02:00
|
|
|
size = AV_RL32(&chunk[2]);
|
2013-09-11 22:56:55 +03:00
|
|
|
if (size > INT_MAX / 2) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid frame size\n");
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto error;
|
|
|
|
}
|
2009-01-21 15:26:01 +02:00
|
|
|
if(!size && type != 1)
|
2006-03-11 06:27:58 +02:00
|
|
|
continue;
|
|
|
|
switch(type) {
|
|
|
|
case 1: /* Audio Chunk */
|
2008-02-04 14:13:09 +02:00
|
|
|
if (!st) break;
|
2006-11-19 07:30:43 +02:00
|
|
|
/* first audio chunk contains several audio buffers */
|
2009-01-21 15:25:14 +02:00
|
|
|
vmd->frame_table[total_frames].frame_offset = current_offset;
|
|
|
|
vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index;
|
|
|
|
vmd->frame_table[total_frames].frame_size = size;
|
|
|
|
memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
|
|
|
|
vmd->frame_table[total_frames].pts = current_audio_pts;
|
|
|
|
total_frames++;
|
2009-01-21 15:27:39 +02:00
|
|
|
if(!current_audio_pts)
|
2012-01-10 17:24:21 +03:00
|
|
|
current_audio_pts += sound_buffers - 1;
|
2009-01-21 15:27:39 +02:00
|
|
|
else
|
|
|
|
current_audio_pts++;
|
2006-03-11 06:27:58 +02:00
|
|
|
break;
|
|
|
|
case 2: /* Video Chunk */
|
|
|
|
vmd->frame_table[total_frames].frame_offset = current_offset;
|
|
|
|
vmd->frame_table[total_frames].stream_index = vmd->video_stream_index;
|
2006-11-13 07:18:19 +02:00
|
|
|
vmd->frame_table[total_frames].frame_size = size;
|
2006-03-11 06:27:58 +02:00
|
|
|
memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
|
2009-01-21 15:27:39 +02:00
|
|
|
vmd->frame_table[total_frames].pts = i;
|
2006-03-11 06:27:58 +02:00
|
|
|
total_frames++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
current_offset += size;
|
2004-01-02 06:47:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
av_free(raw_frame_table);
|
|
|
|
|
|
|
|
vmd->current_frame = 0;
|
2006-03-11 06:27:58 +02:00
|
|
|
vmd->frame_count = total_frames;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
return 0;
|
2013-09-11 22:56:55 +03:00
|
|
|
|
|
|
|
error:
|
2013-09-16 15:39:45 +03:00
|
|
|
av_freep(&raw_frame_table);
|
|
|
|
av_freep(&vmd->frame_table);
|
2013-09-11 22:56:55 +03:00
|
|
|
return ret;
|
2004-01-02 06:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vmd_read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
2007-04-08 23:24:16 +03:00
|
|
|
VmdDemuxContext *vmd = s->priv_data;
|
2011-02-20 12:04:12 +02:00
|
|
|
AVIOContext *pb = s->pb;
|
2004-01-02 06:47:02 +02:00
|
|
|
int ret = 0;
|
2008-12-14 05:29:33 +02:00
|
|
|
vmd_frame *frame;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
if (vmd->current_frame >= vmd->frame_count)
|
2012-11-21 13:38:52 +03:00
|
|
|
return AVERROR_EOF;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
frame = &vmd->frame_table[vmd->current_frame];
|
|
|
|
/* position the stream (will probably be there already) */
|
2011-02-28 15:57:54 +02:00
|
|
|
avio_seek(pb, frame->frame_offset, SEEK_SET);
|
2004-01-02 06:47:02 +02:00
|
|
|
|
2011-12-25 00:06:25 +03:00
|
|
|
if(ffio_limit(pb, frame->frame_size) != frame->frame_size)
|
|
|
|
return AVERROR(EIO);
|
2019-12-10 23:59:53 +02:00
|
|
|
ret = av_new_packet(pkt, frame->frame_size + BYTES_PER_FRAME_RECORD);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-03-03 21:11:45 +02:00
|
|
|
pkt->pos= avio_tell(pb);
|
2004-01-02 06:47:02 +02:00
|
|
|
memcpy(pkt->data, frame->frame_record, BYTES_PER_FRAME_RECORD);
|
2011-03-31 17:42:22 +03:00
|
|
|
if(vmd->is_indeo3 && frame->frame_record[0] == 0x02)
|
2011-02-21 17:43:01 +02:00
|
|
|
ret = avio_read(pb, pkt->data, frame->frame_size);
|
2008-12-27 19:34:00 +02:00
|
|
|
else
|
2011-02-21 17:43:01 +02:00
|
|
|
ret = avio_read(pb, pkt->data + BYTES_PER_FRAME_RECORD,
|
2008-12-27 19:34:00 +02:00
|
|
|
frame->frame_size);
|
2004-01-02 06:47:02 +02:00
|
|
|
|
2004-03-14 06:08:11 +02:00
|
|
|
if (ret != frame->frame_size) {
|
2007-07-19 18:23:32 +03:00
|
|
|
ret = AVERROR(EIO);
|
2004-03-14 06:08:11 +02:00
|
|
|
}
|
2004-01-02 06:47:02 +02:00
|
|
|
pkt->stream_index = frame->stream_index;
|
2006-11-13 07:18:19 +02:00
|
|
|
pkt->pts = frame->pts;
|
2009-02-16 16:45:05 +02:00
|
|
|
av_log(s, AV_LOG_DEBUG, " dispatching %s frame with %d bytes and pts %"PRId64"\n",
|
2006-11-01 23:09:14 +02:00
|
|
|
(frame->frame_record[0] == 0x02) ? "video" : "audio",
|
|
|
|
frame->frame_size + BYTES_PER_FRAME_RECORD,
|
2006-11-13 07:18:19 +02:00
|
|
|
pkt->pts);
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
vmd->current_frame++;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vmd_read_close(AVFormatContext *s)
|
|
|
|
{
|
2007-04-08 23:24:16 +03:00
|
|
|
VmdDemuxContext *vmd = s->priv_data;
|
2004-01-02 06:47:02 +02:00
|
|
|
|
2013-09-16 15:39:45 +03:00
|
|
|
av_freep(&vmd->frame_table);
|
2004-01-02 06:47:02 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-26 00:03:28 +02:00
|
|
|
AVInputFormat ff_vmd_demuxer = {
|
2011-07-16 23:18:12 +03:00
|
|
|
.name = "vmd",
|
2012-07-25 00:51:41 +03:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Sierra VMD"),
|
2011-07-16 23:18:12 +03:00
|
|
|
.priv_data_size = sizeof(VmdDemuxContext),
|
|
|
|
.read_probe = vmd_probe,
|
|
|
|
.read_header = vmd_read_header,
|
|
|
|
.read_packet = vmd_read_packet,
|
|
|
|
.read_close = vmd_read_close,
|
2004-01-02 06:47:02 +02:00
|
|
|
};
|