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