2008-03-31 13:44:33 +03:00
|
|
|
/*
|
|
|
|
* ARMovie/RPL demuxer
|
|
|
|
* Copyright (c) 2007 Christian Ohm, 2008 Eli Friedman
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2014-03-10 17:35:59 +03:00
|
|
|
#include <inttypes.h>
|
2013-11-23 23:32:55 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavutil/avstring.h"
|
2011-05-22 13:46:29 +03:00
|
|
|
#include "libavutil/dict.h"
|
2008-03-31 13:44:33 +03:00
|
|
|
#include "avformat.h"
|
2011-11-29 21:28:15 +03:00
|
|
|
#include "internal.h"
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
#define RPL_SIGNATURE "ARMovie\x0A"
|
|
|
|
#define RPL_SIGNATURE_SIZE 8
|
|
|
|
|
|
|
|
/** 256 is arbitrary, but should be big enough for any reasonable file. */
|
|
|
|
#define RPL_LINE_LENGTH 256
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int rpl_probe(const AVProbeData *p)
|
2008-03-31 13:44:33 +03:00
|
|
|
{
|
|
|
|
if (memcmp(p->buf, RPL_SIGNATURE, RPL_SIGNATURE_SIZE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct RPLContext {
|
|
|
|
// RPL header data
|
|
|
|
int32_t frames_per_chunk;
|
|
|
|
|
|
|
|
// Stream position data
|
|
|
|
uint32_t chunk_number;
|
|
|
|
uint32_t chunk_part;
|
|
|
|
uint32_t frame_in_part;
|
|
|
|
} RPLContext;
|
|
|
|
|
2011-02-20 12:04:12 +02:00
|
|
|
static int read_line(AVIOContext * pb, char* line, int bufsize)
|
2008-03-31 13:44:33 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < bufsize - 1; i++) {
|
2011-02-21 17:43:01 +02:00
|
|
|
int b = avio_r8(pb);
|
2008-03-31 13:44:33 +03:00
|
|
|
if (b == 0)
|
|
|
|
break;
|
|
|
|
if (b == '\n') {
|
|
|
|
line[i] = '\0';
|
2014-08-07 23:12:41 +03:00
|
|
|
return avio_feof(pb) ? -1 : 0;
|
2008-03-31 13:44:33 +03:00
|
|
|
}
|
|
|
|
line[i] = b;
|
|
|
|
}
|
|
|
|
line[i] = '\0';
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t read_int(const char* line, const char** endptr, int* error)
|
|
|
|
{
|
|
|
|
unsigned long result = 0;
|
|
|
|
for (; *line>='0' && *line<='9'; line++) {
|
|
|
|
if (result > (0x7FFFFFFF - 9) / 10)
|
|
|
|
*error = -1;
|
|
|
|
result = 10 * result + *line - '0';
|
|
|
|
}
|
|
|
|
*endptr = line;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-02-20 12:04:12 +02:00
|
|
|
static int32_t read_line_and_int(AVIOContext * pb, int* error)
|
2008-03-31 13:44:33 +03:00
|
|
|
{
|
|
|
|
char line[RPL_LINE_LENGTH];
|
|
|
|
const char *endptr;
|
|
|
|
*error |= read_line(pb, line, sizeof(line));
|
|
|
|
return read_int(line, &endptr, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Parsing for fps, which can be a fraction. Unfortunately,
|
|
|
|
* the spec for the header leaves out a lot of details,
|
|
|
|
* so this is mostly guessing.
|
|
|
|
*/
|
|
|
|
static AVRational read_fps(const char* line, int* error)
|
|
|
|
{
|
|
|
|
int64_t num, den = 1;
|
|
|
|
AVRational result;
|
|
|
|
num = read_int(line, &line, error);
|
|
|
|
if (*line == '.')
|
|
|
|
line++;
|
|
|
|
for (; *line>='0' && *line<='9'; line++) {
|
|
|
|
// Truncate any numerator too large to fit into an int64_t
|
|
|
|
if (num > (INT64_MAX - 9) / 10 || den > INT64_MAX / 10)
|
|
|
|
break;
|
|
|
|
num = 10 * num + *line - '0';
|
|
|
|
den *= 10;
|
|
|
|
}
|
|
|
|
if (!num)
|
|
|
|
*error = -1;
|
|
|
|
av_reduce(&result.num, &result.den, num, den, 0x7FFFFFFF);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-01-12 15:20:36 +03:00
|
|
|
static int rpl_read_header(AVFormatContext *s)
|
2008-03-31 13:44:33 +03:00
|
|
|
{
|
2011-02-20 12:04:12 +02:00
|
|
|
AVIOContext *pb = s->pb;
|
2008-03-31 13:44:33 +03:00
|
|
|
RPLContext *rpl = s->priv_data;
|
|
|
|
AVStream *vst = NULL, *ast = NULL;
|
|
|
|
int total_audio_size;
|
|
|
|
int error = 0;
|
2018-10-13 01:06:40 +02:00
|
|
|
const char *endptr;
|
|
|
|
char audio_type[RPL_LINE_LENGTH];
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
uint32_t i;
|
|
|
|
|
2019-06-14 21:51:34 +02:00
|
|
|
int32_t video_format, audio_format, chunk_catalog_offset, number_of_chunks;
|
2008-03-31 13:44:33 +03:00
|
|
|
AVRational fps;
|
|
|
|
|
|
|
|
char line[RPL_LINE_LENGTH];
|
|
|
|
|
|
|
|
// The header for RPL/ARMovie files is 21 lines of text
|
|
|
|
// containing the various header fields. The fields are always
|
|
|
|
// in the same order, and other text besides the first
|
|
|
|
// number usually isn't important.
|
|
|
|
// (The spec says that there exists some significance
|
|
|
|
// for the text in a few cases; samples needed.)
|
2009-02-27 00:39:53 +02:00
|
|
|
error |= read_line(pb, line, sizeof(line)); // ARMovie
|
2009-02-27 00:38:46 +02:00
|
|
|
error |= read_line(pb, line, sizeof(line)); // movie name
|
2011-05-22 13:46:29 +03:00
|
|
|
av_dict_set(&s->metadata, "title" , line, 0);
|
2009-02-27 00:38:46 +02:00
|
|
|
error |= read_line(pb, line, sizeof(line)); // date/copyright
|
2011-05-22 13:46:29 +03:00
|
|
|
av_dict_set(&s->metadata, "copyright", line, 0);
|
2009-02-27 00:38:46 +02:00
|
|
|
error |= read_line(pb, line, sizeof(line)); // author and other
|
2011-05-22 13:46:29 +03:00
|
|
|
av_dict_set(&s->metadata, "author" , line, 0);
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
// video headers
|
2019-06-14 21:51:34 +02:00
|
|
|
video_format = read_line_and_int(pb, &error);
|
|
|
|
if (video_format) {
|
|
|
|
vst = avformat_new_stream(s, NULL);
|
|
|
|
if (!vst)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
|
vst->codecpar->codec_tag = video_format;
|
|
|
|
vst->codecpar->width = read_line_and_int(pb, &error); // video width
|
|
|
|
vst->codecpar->height = read_line_and_int(pb, &error); // video height
|
|
|
|
vst->codecpar->bits_per_coded_sample = read_line_and_int(pb, &error); // video bits per sample
|
2008-03-31 13:44:33 +03:00
|
|
|
|
2019-06-14 21:51:34 +02:00
|
|
|
// Figure out the video codec
|
|
|
|
switch (vst->codecpar->codec_tag) {
|
2008-03-31 13:44:33 +03:00
|
|
|
#if 0
|
2019-06-14 21:51:34 +02:00
|
|
|
case 122:
|
|
|
|
vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE122;
|
|
|
|
break;
|
2008-03-31 13:44:33 +03:00
|
|
|
#endif
|
2019-06-14 21:51:34 +02:00
|
|
|
case 124:
|
|
|
|
vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE124;
|
|
|
|
// The header is wrong here, at least sometimes
|
|
|
|
vst->codecpar->bits_per_coded_sample = 16;
|
|
|
|
break;
|
|
|
|
case 130:
|
|
|
|
vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE130;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
avpriv_report_missing_feature(s, "Video format %s",
|
|
|
|
av_fourcc2str(vst->codecpar->codec_tag));
|
|
|
|
vst->codecpar->codec_id = AV_CODEC_ID_NONE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
error |= read_line(pb, line, sizeof(line));
|
2008-03-31 13:44:33 +03:00
|
|
|
}
|
|
|
|
|
2019-06-14 21:51:34 +02:00
|
|
|
error |= read_line(pb, line, sizeof(line)); // video frames per second
|
|
|
|
fps = read_fps(line, &error);
|
|
|
|
if (vst)
|
|
|
|
avpriv_set_pts_info(vst, 32, fps.den, fps.num);
|
|
|
|
|
2008-03-31 13:44:33 +03:00
|
|
|
// Audio headers
|
|
|
|
|
|
|
|
// ARMovie supports multiple audio tracks; I don't have any
|
|
|
|
// samples, though. This code will ignore additional tracks.
|
|
|
|
audio_format = read_line_and_int(pb, &error); // audio format ID
|
|
|
|
if (audio_format) {
|
2011-06-18 12:43:24 +03:00
|
|
|
ast = avformat_new_stream(s, NULL);
|
2008-03-31 13:44:33 +03:00
|
|
|
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;
|
|
|
|
ast->codecpar->codec_tag = audio_format;
|
|
|
|
ast->codecpar->sample_rate = read_line_and_int(pb, &error); // audio bitrate
|
|
|
|
ast->codecpar->channels = read_line_and_int(pb, &error); // number of audio channels
|
2018-10-13 01:06:40 +02:00
|
|
|
error |= read_line(pb, line, sizeof(line));
|
|
|
|
ast->codecpar->bits_per_coded_sample = read_int(line, &endptr, &error); // audio bits per sample
|
2019-07-10 10:27:02 +02:00
|
|
|
av_strlcpy(audio_type, endptr, RPL_LINE_LENGTH);
|
2008-03-31 13:44:33 +03:00
|
|
|
// At least one sample uses 0 for ADPCM, which is really 4 bits
|
|
|
|
// per sample.
|
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->bits_per_coded_sample == 0)
|
|
|
|
ast->codecpar->bits_per_coded_sample = 4;
|
2008-03-31 13:44:33 +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
|
|
|
ast->codecpar->bit_rate = ast->codecpar->sample_rate *
|
|
|
|
ast->codecpar->bits_per_coded_sample *
|
|
|
|
ast->codecpar->channels;
|
2008-03-31 13:44:33 +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
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_NONE;
|
2008-03-31 13:44:33 +03:00
|
|
|
switch (audio_format) {
|
|
|
|
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
|
|
|
if (ast->codecpar->bits_per_coded_sample == 16) {
|
2008-03-31 13:44:33 +03:00
|
|
|
// 16-bit audio is always 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_S16LE;
|
2008-03-31 13:44:33 +03:00
|
|
|
break;
|
2018-10-13 01:06:40 +02:00
|
|
|
} else if (ast->codecpar->bits_per_coded_sample == 8) {
|
2019-06-14 21:51:33 +02:00
|
|
|
if(av_stristr(audio_type, "unsigned") != NULL) {
|
2018-10-13 01:06:40 +02:00
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
|
|
|
|
break;
|
2019-06-14 21:51:33 +02:00
|
|
|
} else if(av_stristr(audio_type, "linear") != NULL) {
|
2018-10-13 01:06:40 +02:00
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_PCM_S8;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_PCM_VIDC;
|
|
|
|
break;
|
|
|
|
}
|
2008-03-31 13:44:33 +03:00
|
|
|
}
|
|
|
|
// There are some other formats listed as legal per the spec;
|
|
|
|
// samples needed.
|
|
|
|
break;
|
|
|
|
case 101:
|
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->bits_per_coded_sample == 8) {
|
2008-03-31 13:44:33 +03:00
|
|
|
// The samples with this kind of audio that I have
|
|
|
|
// are all unsigned.
|
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_U8;
|
2008-03-31 13:44:33 +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
|
|
|
} else if (ast->codecpar->bits_per_coded_sample == 4) {
|
|
|
|
ast->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_EA_SEAD;
|
2008-03-31 13:44:33 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-04-10 21:58:15 +02:00
|
|
|
if (ast->codecpar->codec_id == AV_CODEC_ID_NONE)
|
2014-03-11 23:05:34 +03:00
|
|
|
avpriv_request_sample(s, "Audio format %"PRId32,
|
|
|
|
audio_format);
|
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, 32, 1, ast->codecpar->bit_rate);
|
2008-03-31 13:44:33 +03:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
error |= read_line(pb, line, sizeof(line));
|
|
|
|
}
|
|
|
|
|
2020-12-09 01:49:29 +02:00
|
|
|
if (s->nb_streams == 0)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2008-03-31 13:44:33 +03:00
|
|
|
rpl->frames_per_chunk = read_line_and_int(pb, &error); // video frames per chunk
|
2019-06-14 21:51:34 +02:00
|
|
|
if (vst && rpl->frames_per_chunk > 1 && vst->codecpar->codec_tag != 124)
|
2008-03-31 13:44:33 +03:00
|
|
|
av_log(s, AV_LOG_WARNING,
|
2017-03-27 21:31:46 +02:00
|
|
|
"Don't know how to split frames for video format %s. "
|
|
|
|
"Video stream will be broken!\n", av_fourcc2str(vst->codecpar->codec_tag));
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
number_of_chunks = read_line_and_int(pb, &error); // number of chunks in the file
|
|
|
|
// The number in the header is actually the index of the last chunk.
|
|
|
|
number_of_chunks++;
|
|
|
|
|
|
|
|
error |= read_line(pb, line, sizeof(line)); // "even" chunk size in bytes
|
|
|
|
error |= read_line(pb, line, sizeof(line)); // "odd" chunk size in bytes
|
|
|
|
chunk_catalog_offset = // offset of the "chunk catalog"
|
|
|
|
read_line_and_int(pb, &error); // (file index)
|
|
|
|
error |= read_line(pb, line, sizeof(line)); // offset to "helpful" sprite
|
|
|
|
error |= read_line(pb, line, sizeof(line)); // size of "helpful" sprite
|
2019-06-30 01:00:44 +02:00
|
|
|
if (vst) {
|
2019-06-14 21:51:34 +02:00
|
|
|
error |= read_line(pb, line, sizeof(line)); // offset to key frame list
|
2019-06-30 01:00:44 +02:00
|
|
|
vst->duration = number_of_chunks * rpl->frames_per_chunk;
|
|
|
|
}
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
// Read the index
|
2011-02-28 15:57:54 +02:00
|
|
|
avio_seek(pb, chunk_catalog_offset, SEEK_SET);
|
2008-03-31 13:44:33 +03:00
|
|
|
total_audio_size = 0;
|
2011-12-24 21:57:18 +03:00
|
|
|
for (i = 0; !error && i < number_of_chunks; i++) {
|
2008-03-31 13:44:33 +03:00
|
|
|
int64_t offset, video_size, audio_size;
|
|
|
|
error |= read_line(pb, line, sizeof(line));
|
2013-04-10 10:52:08 +03:00
|
|
|
if (3 != sscanf(line, "%"SCNd64" , %"SCNd64" ; %"SCNd64,
|
2013-12-19 21:22:38 +03:00
|
|
|
&offset, &video_size, &audio_size)) {
|
2008-03-31 13:44:33 +03:00
|
|
|
error = -1;
|
2013-12-19 21:22:38 +03:00
|
|
|
continue;
|
|
|
|
}
|
2019-06-14 21:51:34 +02:00
|
|
|
if (vst)
|
|
|
|
av_add_index_entry(vst, offset, i * rpl->frames_per_chunk,
|
|
|
|
video_size, rpl->frames_per_chunk, 0);
|
2008-03-31 13:44:33 +03:00
|
|
|
if (ast)
|
|
|
|
av_add_index_entry(ast, offset + video_size, total_audio_size,
|
|
|
|
audio_size, audio_size * 8, 0);
|
|
|
|
total_audio_size += audio_size * 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) return AVERROR(EIO);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
RPLContext *rpl = s->priv_data;
|
2011-02-20 12:04:12 +02:00
|
|
|
AVIOContext *pb = s->pb;
|
2008-03-31 13:44:33 +03:00
|
|
|
AVStream* stream;
|
|
|
|
AVIndexEntry* index_entry;
|
2015-02-05 16:44:43 +02:00
|
|
|
int ret;
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
if (rpl->chunk_part == s->nb_streams) {
|
|
|
|
rpl->chunk_number++;
|
|
|
|
rpl->chunk_part = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = s->streams[rpl->chunk_part];
|
|
|
|
|
2020-10-09 09:22:36 +02:00
|
|
|
if (rpl->chunk_number >= stream->internal->nb_index_entries)
|
2012-11-21 12:48:46 +03:00
|
|
|
return AVERROR_EOF;
|
2008-03-31 13:44:33 +03:00
|
|
|
|
2020-10-09 09:22:36 +02:00
|
|
|
index_entry = &stream->internal->index_entries[rpl->chunk_number];
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
if (rpl->frame_in_part == 0)
|
2011-02-28 15:57:54 +02:00
|
|
|
if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0)
|
2008-03-31 13:44:33 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
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 (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
|
|
|
|
stream->codecpar->codec_tag == 124) {
|
2008-03-31 13:44:33 +03:00
|
|
|
// We have to split Escape 124 frames because there are
|
|
|
|
// multiple frames per chunk in Escape 124 samples.
|
2011-06-01 19:26:27 +03:00
|
|
|
uint32_t frame_size;
|
2008-03-31 13:44:33 +03:00
|
|
|
|
2011-06-01 19:26:27 +03:00
|
|
|
avio_skip(pb, 4); /* flags */
|
2011-02-21 17:43:01 +02:00
|
|
|
frame_size = avio_rl32(pb);
|
2011-02-28 15:57:54 +02:00
|
|
|
if (avio_seek(pb, -8, SEEK_CUR) < 0)
|
2008-03-31 13:44:33 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
|
|
|
ret = av_get_packet(pb, pkt, frame_size);
|
2015-02-05 16:44:43 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-03-31 13:44:33 +03:00
|
|
|
if (ret != frame_size) {
|
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
pkt->duration = 1;
|
|
|
|
pkt->pts = index_entry->timestamp + rpl->frame_in_part;
|
|
|
|
pkt->stream_index = rpl->chunk_part;
|
|
|
|
|
|
|
|
rpl->frame_in_part++;
|
|
|
|
if (rpl->frame_in_part == rpl->frames_per_chunk) {
|
|
|
|
rpl->frame_in_part = 0;
|
|
|
|
rpl->chunk_part++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = av_get_packet(pb, pkt, index_entry->size);
|
2015-02-05 16:44:43 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-03-31 13:44:33 +03:00
|
|
|
if (ret != index_entry->size) {
|
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
|
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 (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
2008-03-31 13:44:33 +03:00
|
|
|
// frames_per_chunk should always be one here; the header
|
|
|
|
// parsing will warn if it isn't.
|
|
|
|
pkt->duration = rpl->frames_per_chunk;
|
|
|
|
} else {
|
|
|
|
// All the audio codecs supported in this container
|
|
|
|
// (at least so far) are constant-bitrate.
|
|
|
|
pkt->duration = ret * 8;
|
|
|
|
}
|
|
|
|
pkt->pts = index_entry->timestamp;
|
|
|
|
pkt->stream_index = rpl->chunk_part;
|
|
|
|
rpl->chunk_part++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// None of the Escape formats have keyframes, and the ADPCM
|
|
|
|
// format used doesn't have keyframes.
|
|
|
|
if (rpl->chunk_number == 0 && rpl->frame_in_part == 0)
|
2010-03-31 15:29:58 +03:00
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
2008-03-31 13:44:33 +03:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-26 00:03:28 +02:00
|
|
|
AVInputFormat ff_rpl_demuxer = {
|
2011-07-16 23:18:12 +03:00
|
|
|
.name = "rpl",
|
2012-07-25 00:51:41 +03:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("RPL / ARMovie"),
|
2011-07-16 23:18:12 +03:00
|
|
|
.priv_data_size = sizeof(RPLContext),
|
|
|
|
.read_probe = rpl_probe,
|
|
|
|
.read_header = rpl_read_header,
|
|
|
|
.read_packet = rpl_read_packet,
|
2008-03-31 13:44:33 +03:00
|
|
|
};
|