2012-12-17 12:37:54 +03:00
|
|
|
/*
|
|
|
|
* Silicon Graphics Movie demuxer
|
|
|
|
* Copyright (c) 2012 Peter Ross
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Silicon Graphics Movie demuxer
|
|
|
|
*/
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-12-17 12:37:54 +03:00
|
|
|
#include "libavutil/eval.h"
|
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
#include "libavutil/rational.h"
|
2012-12-17 12:37:54 +03:00
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
#include "avformat.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
typedef struct MvContext {
|
2012-12-17 12:37:54 +03:00
|
|
|
int nb_video_tracks;
|
|
|
|
int nb_audio_tracks;
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
int eof_count; ///< number of streams that have finished
|
|
|
|
int stream_index; ///< current stream index
|
|
|
|
int frame[2]; ///< frame nb for current stream
|
|
|
|
|
|
|
|
int acompression; ///< compression level for audio stream
|
|
|
|
int aformat; ///< audio format
|
2012-12-17 12:37:54 +03:00
|
|
|
} MvContext;
|
|
|
|
|
|
|
|
#define AUDIO_FORMAT_SIGNED 401
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int mv_probe(const AVProbeData *p)
|
2012-12-17 12:37:54 +03:00
|
|
|
{
|
2012-12-17 12:37:54 +03:00
|
|
|
if (AV_RB32(p->buf) == MKBETAG('M', 'O', 'V', 'I') &&
|
|
|
|
AV_RB16(p->buf + 4) < 3)
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
static char *var_read_string(AVIOContext *pb, int size)
|
2012-12-17 12:37:54 +03:00
|
|
|
{
|
|
|
|
int n;
|
2014-10-28 17:42:05 +02:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (size < 0 || size == INT_MAX)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
str = av_malloc(size + 1);
|
2012-12-17 12:37:54 +03:00
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
n = avio_get_str(pb, size, str, size + 1);
|
|
|
|
if (n < size)
|
2012-12-17 12:37:54 +03:00
|
|
|
avio_skip(pb, size - n);
|
2012-12-17 12:37:54 +03:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int var_read_int(AVIOContext *pb, int size)
|
|
|
|
{
|
|
|
|
int v;
|
2012-12-17 12:37:54 +03:00
|
|
|
char *s = var_read_string(pb, size);
|
|
|
|
if (!s)
|
|
|
|
return 0;
|
|
|
|
v = strtol(s, NULL, 10);
|
2012-12-17 12:37:54 +03:00
|
|
|
av_free(s);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AVRational var_read_float(AVIOContext *pb, int size)
|
|
|
|
{
|
|
|
|
AVRational v;
|
2012-12-17 12:37:54 +03:00
|
|
|
char *s = var_read_string(pb, size);
|
2012-12-17 12:37:54 +03:00
|
|
|
if (!s)
|
2012-12-17 12:37:54 +03:00
|
|
|
return (AVRational) { 0, 0 };
|
2012-12-17 12:37:54 +03:00
|
|
|
v = av_d2q(av_strtod(s, NULL), INT_MAX);
|
|
|
|
av_free(s);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void var_read_metadata(AVFormatContext *avctx, const char *tag, int size)
|
|
|
|
{
|
|
|
|
char *value = var_read_string(avctx->pb, size);
|
|
|
|
if (value)
|
|
|
|
av_dict_set(&avctx->metadata, tag, value, AV_DICT_DONT_STRDUP_VAL);
|
|
|
|
}
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
static int set_channels(AVFormatContext *avctx, AVStream *st, int channels)
|
|
|
|
{
|
2013-01-23 01:05:53 +03:00
|
|
|
if (channels <= 0) {
|
2012-12-17 12:37:54 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid.\n", channels);
|
2013-01-23 01:05:53 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
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->channels = channels;
|
|
|
|
st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO
|
|
|
|
: AV_CH_LAYOUT_STEREO;
|
2013-01-23 01:05:53 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
/**
|
|
|
|
* Parse global variable
|
|
|
|
* @return < 0 if unknown
|
|
|
|
*/
|
2012-12-17 12:37:54 +03:00
|
|
|
static int parse_global_var(AVFormatContext *avctx, AVStream *st,
|
|
|
|
const char *name, int size)
|
2012-12-17 12:37:54 +03:00
|
|
|
{
|
|
|
|
MvContext *mv = avctx->priv_data;
|
|
|
|
AVIOContext *pb = avctx->pb;
|
|
|
|
if (!strcmp(name, "__NUM_I_TRACKS")) {
|
|
|
|
mv->nb_video_tracks = var_read_int(pb, size);
|
|
|
|
} else if (!strcmp(name, "__NUM_A_TRACKS")) {
|
|
|
|
mv->nb_audio_tracks = var_read_int(pb, size);
|
|
|
|
} else if (!strcmp(name, "COMMENT") || !strcmp(name, "TITLE")) {
|
|
|
|
var_read_metadata(avctx, name, size);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "LOOP_MODE") || !strcmp(name, "NUM_LOOPS") ||
|
|
|
|
!strcmp(name, "OPTIMIZED")) {
|
2012-12-17 12:37:54 +03:00
|
|
|
avio_skip(pb, size); // ignore
|
|
|
|
} else
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2012-12-17 12:37:54 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse audio variable
|
|
|
|
* @return < 0 if unknown
|
|
|
|
*/
|
2012-12-17 12:37:54 +03:00
|
|
|
static int parse_audio_var(AVFormatContext *avctx, AVStream *st,
|
|
|
|
const char *name, int size)
|
2012-12-17 12:37:54 +03:00
|
|
|
{
|
2012-12-17 12:37:54 +03:00
|
|
|
MvContext *mv = avctx->priv_data;
|
2012-12-17 12:37:54 +03:00
|
|
|
AVIOContext *pb = avctx->pb;
|
|
|
|
if (!strcmp(name, "__DIR_COUNT")) {
|
|
|
|
st->nb_frames = var_read_int(pb, size);
|
|
|
|
} else if (!strcmp(name, "AUDIO_FORMAT")) {
|
2012-12-17 12:37:54 +03:00
|
|
|
mv->aformat = var_read_int(pb, size);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "COMPRESSION")) {
|
2012-12-17 12:37:54 +03:00
|
|
|
mv->acompression = var_read_int(pb, size);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "DEFAULT_VOL")) {
|
|
|
|
var_read_metadata(avctx, name, size);
|
|
|
|
} else if (!strcmp(name, "NUM_CHANNELS")) {
|
2013-01-23 01:05:53 +03:00
|
|
|
return set_channels(avctx, st, var_read_int(pb, size));
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "SAMPLE_RATE")) {
|
2021-09-15 22:00:46 +02:00
|
|
|
int sample_rate = var_read_int(pb, size);
|
|
|
|
if (sample_rate <= 0)
|
2021-04-28 16:44:13 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2021-09-15 22:00:46 +02:00
|
|
|
st->codecpar->sample_rate = sample_rate;
|
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
|
|
|
avpriv_set_pts_info(st, 33, 1, st->codecpar->sample_rate);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "SAMPLE_WIDTH")) {
|
2021-02-02 21:47:10 +02:00
|
|
|
uint64_t bpc = var_read_int(pb, size) * (uint64_t)8;
|
|
|
|
if (bpc > 16)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
st->codecpar->bits_per_coded_sample = bpc;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse video variable
|
|
|
|
* @return < 0 if unknown
|
|
|
|
*/
|
2012-12-17 12:37:54 +03:00
|
|
|
static int parse_video_var(AVFormatContext *avctx, AVStream *st,
|
|
|
|
const char *name, int size)
|
2012-12-17 12:37:54 +03:00
|
|
|
{
|
|
|
|
AVIOContext *pb = avctx->pb;
|
|
|
|
if (!strcmp(name, "__DIR_COUNT")) {
|
|
|
|
st->nb_frames = st->duration = var_read_int(pb, size);
|
|
|
|
} else if (!strcmp(name, "COMPRESSION")) {
|
2012-12-17 12:37:54 +03:00
|
|
|
char *str = var_read_string(pb, size);
|
2013-01-27 04:14:38 +03:00
|
|
|
if (!str)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-12-17 12:37:54 +03:00
|
|
|
if (!strcmp(str, "1")) {
|
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_id = AV_CODEC_ID_MVC1;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(str, "2")) {
|
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->format = AV_PIX_FMT_ABGR;
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(str, "3")) {
|
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_id = AV_CODEC_ID_SGIRLE;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(str, "10")) {
|
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_id = AV_CODEC_ID_MJPEG;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(str, "MVC2")) {
|
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_id = AV_CODEC_ID_MVC2;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else {
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx, "Video compression %s", str);
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
av_free(str);
|
|
|
|
} else if (!strcmp(name, "FPS")) {
|
2013-01-23 00:52:23 +03:00
|
|
|
AVRational fps = var_read_float(pb, size);
|
|
|
|
avpriv_set_pts_info(st, 64, fps.den, fps.num);
|
2012-12-17 12:37:54 +03:00
|
|
|
st->avg_frame_rate = fps;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "HEIGHT")) {
|
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->height = var_read_int(pb, size);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "PIXEL_ASPECT")) {
|
|
|
|
st->sample_aspect_ratio = var_read_float(pb, size);
|
|
|
|
av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den,
|
2012-12-17 12:37:54 +03:00
|
|
|
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
|
|
|
|
INT_MAX);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "WIDTH")) {
|
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->width = var_read_int(pb, size);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else if (!strcmp(name, "ORIENTATION")) {
|
|
|
|
if (var_read_int(pb, size) == 1101) {
|
2021-01-02 01:36:39 +02:00
|
|
|
if (!st->codecpar->extradata) {
|
|
|
|
st->codecpar->extradata = av_strdup("BottomUp");
|
|
|
|
if (!st->codecpar->extradata)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
st->codecpar->extradata_size = 9;
|
|
|
|
}
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
} else if (!strcmp(name, "Q_SPATIAL") || !strcmp(name, "Q_TEMPORAL")) {
|
|
|
|
var_read_metadata(avctx, name, size);
|
|
|
|
} else if (!strcmp(name, "INTERLACING") || !strcmp(name, "PACKING")) {
|
|
|
|
avio_skip(pb, size); // ignore
|
|
|
|
} else
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:59:50 +02:00
|
|
|
static int read_table(AVFormatContext *avctx, AVStream *st,
|
2012-12-17 12:37:54 +03:00
|
|
|
int (*parse)(AVFormatContext *avctx, AVStream *st,
|
|
|
|
const char *name, int size))
|
2012-12-17 12:37:54 +03:00
|
|
|
{
|
2017-11-05 11:39:23 +02:00
|
|
|
unsigned count;
|
|
|
|
int i;
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
AVIOContext *pb = avctx->pb;
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
count = avio_rb32(pb);
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
char name[17];
|
|
|
|
int size;
|
2017-11-05 11:39:23 +02:00
|
|
|
|
|
|
|
if (avio_feof(pb))
|
|
|
|
return AVERROR_EOF;
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
avio_read(pb, name, 16);
|
|
|
|
name[sizeof(name) - 1] = 0;
|
|
|
|
size = avio_rb32(pb);
|
2014-10-28 17:59:50 +02:00
|
|
|
if (size < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "entry size %d is invalid\n", size);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2012-12-17 12:37:54 +03:00
|
|
|
if (parse(avctx, st, name, size) < 0) {
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx, "Variable %s", name);
|
2012-12-17 12:37:54 +03:00
|
|
|
avio_skip(pb, size);
|
|
|
|
}
|
|
|
|
}
|
2014-10-28 17:59:50 +02:00
|
|
|
return 0;
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void read_index(AVIOContext *pb, AVStream *st)
|
|
|
|
{
|
|
|
|
uint64_t timestamp = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < st->nb_frames; i++) {
|
|
|
|
uint32_t pos = avio_rb32(pb);
|
|
|
|
uint32_t size = avio_rb32(pb);
|
|
|
|
avio_skip(pb, 8);
|
2021-01-31 17:19:42 +02:00
|
|
|
if (avio_feof(pb))
|
|
|
|
return ;
|
2012-12-17 12:37:54 +03:00
|
|
|
av_add_index_entry(st, pos, timestamp, size, 0, AVINDEX_KEYFRAME);
|
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
|
|
|
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
|
2020-06-23 01:01:53 +02:00
|
|
|
timestamp += size / (st->codecpar->channels * 2LL);
|
2012-12-17 12:37:54 +03:00
|
|
|
} else {
|
|
|
|
timestamp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mv_read_header(AVFormatContext *avctx)
|
|
|
|
{
|
|
|
|
MvContext *mv = avctx->priv_data;
|
|
|
|
AVIOContext *pb = avctx->pb;
|
2012-12-24 20:21:46 +03:00
|
|
|
AVStream *ast = NULL, *vst = NULL; //initialization to suppress warning
|
2012-12-17 12:37:54 +03:00
|
|
|
int version, i;
|
2014-10-28 17:59:50 +02:00
|
|
|
int ret;
|
2012-12-17 12:37:54 +03:00
|
|
|
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
|
|
|
|
version = avio_rb16(pb);
|
|
|
|
if (version == 2) {
|
|
|
|
uint64_t timestamp;
|
|
|
|
int v;
|
|
|
|
avio_skip(pb, 22);
|
|
|
|
|
|
|
|
/* allocate audio track first to prevent unnecessary seeking
|
2012-12-17 12:37:54 +03:00
|
|
|
* (audio packet always precede video packet for a given frame) */
|
2012-12-17 12:37:54 +03:00
|
|
|
ast = avformat_new_stream(avctx, NULL);
|
|
|
|
if (!ast)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
vst = avformat_new_stream(avctx, NULL);
|
|
|
|
if (!vst)
|
|
|
|
return AVERROR(ENOMEM);
|
2013-01-23 00:40:38 +03:00
|
|
|
avpriv_set_pts_info(vst, 64, 1, 15);
|
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
|
|
|
vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
2012-12-17 12:37:54 +03:00
|
|
|
vst->avg_frame_rate = av_inv_q(vst->time_base);
|
|
|
|
vst->nb_frames = avio_rb32(pb);
|
2012-12-17 12:37:54 +03:00
|
|
|
v = avio_rb32(pb);
|
|
|
|
switch (v) {
|
|
|
|
case 1:
|
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
|
|
|
vst->codecpar->codec_id = AV_CODEC_ID_MVC1;
|
2012-12-17 12:37:54 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
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
|
|
|
vst->codecpar->format = AV_PIX_FMT_ARGB;
|
|
|
|
vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
|
2012-12-17 12:37:54 +03:00
|
|
|
break;
|
|
|
|
default:
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx, "Video compression %i", v);
|
2012-12-17 12:37:54 +03:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
vst->codecpar->codec_tag = 0;
|
|
|
|
vst->codecpar->width = avio_rb32(pb);
|
|
|
|
vst->codecpar->height = avio_rb32(pb);
|
2012-12-17 12:37:54 +03:00
|
|
|
avio_skip(pb, 12);
|
|
|
|
|
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
|
|
|
ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
2012-12-17 12:37:54 +03:00
|
|
|
ast->nb_frames = vst->nb_frames;
|
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
|
|
|
ast->codecpar->sample_rate = avio_rb32(pb);
|
2016-10-23 17:06:45 +02:00
|
|
|
if (ast->codecpar->sample_rate <= 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid sample rate %d\n", ast->codecpar->sample_rate);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
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
|
|
|
avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate);
|
2013-01-23 01:05:53 +03:00
|
|
|
if (set_channels(avctx, ast, avio_rb32(pb)) < 0)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
v = avio_rb32(pb);
|
|
|
|
if (v == AUDIO_FORMAT_SIGNED) {
|
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
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else {
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx, "Audio compression (format %i)", v);
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
avio_skip(pb, 12);
|
|
|
|
var_read_metadata(avctx, "title", 0x80);
|
|
|
|
var_read_metadata(avctx, "comment", 0x100);
|
|
|
|
avio_skip(pb, 0x80);
|
|
|
|
|
|
|
|
timestamp = 0;
|
|
|
|
for (i = 0; i < vst->nb_frames; i++) {
|
|
|
|
uint32_t pos = avio_rb32(pb);
|
|
|
|
uint32_t asize = avio_rb32(pb);
|
|
|
|
uint32_t vsize = avio_rb32(pb);
|
2017-08-25 01:15:30 +02:00
|
|
|
if (avio_feof(pb))
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-12-17 12:37:54 +03:00
|
|
|
avio_skip(pb, 8);
|
2012-12-17 12:37:54 +03:00
|
|
|
av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME);
|
|
|
|
av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME);
|
2020-06-23 01:01:53 +02:00
|
|
|
timestamp += asize / (ast->codecpar->channels * 2LL);
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
} else if (!version && avio_rb16(pb) == 3) {
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
|
2014-10-28 17:59:50 +02:00
|
|
|
if ((ret = read_table(avctx, NULL, parse_global_var)) < 0)
|
|
|
|
return ret;
|
2012-12-17 12:37:54 +03:00
|
|
|
|
2020-02-23 10:27:27 +02:00
|
|
|
if (mv->nb_audio_tracks < 0 || mv->nb_video_tracks < 0 ||
|
|
|
|
(mv->nb_audio_tracks == 0 && mv->nb_video_tracks == 0)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Stream count is invalid.\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
if (mv->nb_audio_tracks > 1) {
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx, "Multiple audio streams support");
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
} else if (mv->nb_audio_tracks) {
|
|
|
|
ast = avformat_new_stream(avctx, NULL);
|
|
|
|
if (!ast)
|
|
|
|
return AVERROR(ENOMEM);
|
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
|
|
|
ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
2021-09-16 21:34:03 +02:00
|
|
|
if ((ret = read_table(avctx, ast, parse_audio_var)) < 0)
|
2014-10-28 17:59:50 +02:00
|
|
|
return ret;
|
2012-12-17 12:37:54 +03:00
|
|
|
if (mv->acompression == 100 &&
|
|
|
|
mv->aformat == AUDIO_FORMAT_SIGNED &&
|
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
|
|
|
ast->codecpar->bits_per_coded_sample == 16) {
|
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
|
2012-12-17 12:37:54 +03:00
|
|
|
} else {
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx,
|
|
|
|
"Audio compression %i (format %i, sr %i)",
|
|
|
|
mv->acompression, mv->aformat,
|
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
|
|
|
ast->codecpar->bits_per_coded_sample);
|
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_NONE;
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
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
|
|
|
if (ast->codecpar->channels <= 0) {
|
2012-12-17 12:37:54 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "No valid channel count found.\n");
|
2013-01-23 01:05:53 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mv->nb_video_tracks > 1) {
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx, "Multiple video streams support");
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
} else if (mv->nb_video_tracks) {
|
|
|
|
vst = avformat_new_stream(avctx, NULL);
|
|
|
|
if (!vst)
|
|
|
|
return AVERROR(ENOMEM);
|
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
|
|
|
vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
2014-10-28 17:59:50 +02:00
|
|
|
if ((ret = read_table(avctx, vst, parse_video_var))<0)
|
|
|
|
return ret;
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mv->nb_audio_tracks)
|
|
|
|
read_index(pb, ast);
|
|
|
|
|
|
|
|
if (mv->nb_video_tracks)
|
|
|
|
read_index(pb, vst);
|
|
|
|
} else {
|
2012-12-17 12:37:54 +03:00
|
|
|
avpriv_request_sample(avctx, "Version %i", version);
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
MvContext *mv = avctx->priv_data;
|
|
|
|
AVIOContext *pb = avctx->pb;
|
|
|
|
AVStream *st = avctx->streams[mv->stream_index];
|
2021-08-24 19:41:16 +02:00
|
|
|
FFStream *const sti = ffstream(st);
|
2012-12-17 12:37:54 +03:00
|
|
|
const AVIndexEntry *index;
|
|
|
|
int frame = mv->frame[mv->stream_index];
|
2015-02-20 21:41:35 +02:00
|
|
|
int64_t ret;
|
2012-12-17 12:37:54 +03:00
|
|
|
uint64_t pos;
|
|
|
|
|
2021-08-24 19:41:16 +02:00
|
|
|
if (frame < sti->nb_index_entries) {
|
|
|
|
index = &sti->index_entries[frame];
|
2012-12-17 12:37:54 +03:00
|
|
|
pos = avio_tell(pb);
|
2012-12-17 12:37:54 +03:00
|
|
|
if (index->pos > pos)
|
|
|
|
avio_skip(pb, index->pos - pos);
|
|
|
|
else if (index->pos < pos) {
|
2016-09-27 16:26:37 +02:00
|
|
|
if (!(pb->seekable & AVIO_SEEKABLE_NORMAL))
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
ret = avio_seek(pb, index->pos, SEEK_SET);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = av_get_packet(pb, pkt, index->size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pkt->stream_index = mv->stream_index;
|
2012-12-17 12:37:54 +03:00
|
|
|
pkt->pts = index->timestamp;
|
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
2012-12-17 12:37:54 +03:00
|
|
|
|
|
|
|
mv->frame[mv->stream_index]++;
|
|
|
|
mv->eof_count = 0;
|
|
|
|
} else {
|
|
|
|
mv->eof_count++;
|
|
|
|
if (mv->eof_count >= avctx->nb_streams)
|
|
|
|
return AVERROR_EOF;
|
2012-12-17 12:37:54 +03:00
|
|
|
|
|
|
|
// avoid returning 0 without a packet
|
|
|
|
return AVERROR(EAGAIN);
|
2012-12-17 12:37:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mv->stream_index++;
|
|
|
|
if (mv->stream_index >= avctx->nb_streams)
|
|
|
|
mv->stream_index = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 12:37:54 +03:00
|
|
|
static int mv_read_seek(AVFormatContext *avctx, int stream_index,
|
|
|
|
int64_t timestamp, int flags)
|
2012-12-17 12:37:54 +03:00
|
|
|
{
|
|
|
|
MvContext *mv = avctx->priv_data;
|
|
|
|
AVStream *st = avctx->streams[stream_index];
|
|
|
|
int frame, i;
|
|
|
|
|
|
|
|
if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE))
|
|
|
|
return AVERROR(ENOSYS);
|
|
|
|
|
2016-09-27 16:26:37 +02:00
|
|
|
if (!(avctx->pb->seekable & AVIO_SEEKABLE_NORMAL))
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
|
|
|
frame = av_index_search_timestamp(st, timestamp, flags);
|
|
|
|
if (frame < 0)
|
2012-12-17 12:37:54 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2012-12-17 12:37:54 +03:00
|
|
|
|
|
|
|
for (i = 0; i < avctx->nb_streams; i++)
|
|
|
|
mv->frame[i] = frame;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:45:24 +02:00
|
|
|
const AVInputFormat ff_mv_demuxer = {
|
2012-12-17 12:37:54 +03:00
|
|
|
.name = "mv",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Silicon Graphics Movie"),
|
|
|
|
.priv_data_size = sizeof(MvContext),
|
|
|
|
.read_probe = mv_probe,
|
|
|
|
.read_header = mv_read_header,
|
|
|
|
.read_packet = mv_read_packet,
|
|
|
|
.read_seek = mv_read_seek,
|
|
|
|
};
|