2009-03-07 22:42:09 +00:00
|
|
|
/*
|
|
|
|
* VQF demuxer
|
|
|
|
* Copyright (c) 2009 Vitor Sessak
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
2011-11-29 18:28:15 +00:00
|
|
|
#include "internal.h"
|
2009-03-07 22:42:09 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2011-05-22 10:46:29 +00:00
|
|
|
#include "libavutil/dict.h"
|
2011-06-04 11:58:23 +00:00
|
|
|
#include "libavutil/mathematics.h"
|
2012-01-07 17:31:31 +00:00
|
|
|
#include "riff.h"
|
2009-03-07 22:42:09 +00:00
|
|
|
|
|
|
|
typedef struct VqfContext {
|
|
|
|
int frame_bit_len;
|
|
|
|
uint8_t last_frame_bits;
|
|
|
|
int remaining_bits;
|
|
|
|
} VqfContext;
|
|
|
|
|
2019-03-21 00:18:37 +00:00
|
|
|
static int vqf_probe(const AVProbeData *probe_packet)
|
2009-03-07 22:42:09 +00:00
|
|
|
{
|
|
|
|
if (AV_RL32(probe_packet->buf) != MKTAG('T','W','I','N'))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!memcmp(probe_packet->buf + 4, "97012000", 8))
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
|
|
|
|
if (!memcmp(probe_packet->buf + 4, "00052200", 8))
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
|
2013-11-12 21:26:34 +00:00
|
|
|
if (AV_RL32(probe_packet->buf + 12) > (1<<27))
|
|
|
|
return AVPROBE_SCORE_EXTENSION/2;
|
|
|
|
|
2013-03-25 15:12:51 +00:00
|
|
|
return AVPROBE_SCORE_EXTENSION;
|
2009-03-07 22:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-07 17:31:31 +00:00
|
|
|
static void add_metadata(AVFormatContext *s, uint32_t tag,
|
2009-03-07 22:42:09 +00:00
|
|
|
unsigned int tag_len, unsigned int remaining)
|
|
|
|
{
|
2009-12-13 20:27:29 +00:00
|
|
|
int len = FFMIN(tag_len, remaining);
|
2012-01-07 17:31:31 +00:00
|
|
|
char *buf, key[5] = {0};
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2009-12-13 20:27:29 +00:00
|
|
|
if (len == UINT_MAX)
|
|
|
|
return;
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2009-12-13 20:27:29 +00:00
|
|
|
buf = av_malloc(len+1);
|
|
|
|
if (!buf)
|
|
|
|
return;
|
2011-02-21 15:43:01 +00:00
|
|
|
avio_read(s->pb, buf, len);
|
2009-03-07 22:42:09 +00:00
|
|
|
buf[len] = 0;
|
2012-01-07 17:31:31 +00:00
|
|
|
AV_WL32(key, tag);
|
|
|
|
av_dict_set(&s->metadata, key, buf, AV_DICT_DONT_STRDUP_VAL);
|
2009-03-07 22:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-07 17:31:31 +00:00
|
|
|
static const AVMetadataConv vqf_metadata_conv[] = {
|
|
|
|
{ "(c) ", "copyright" },
|
|
|
|
{ "ARNG", "arranger" },
|
|
|
|
{ "AUTH", "author" },
|
|
|
|
{ "BAND", "band" },
|
|
|
|
{ "CDCT", "conductor" },
|
|
|
|
{ "COMT", "comment" },
|
|
|
|
{ "FILE", "filename" },
|
|
|
|
{ "GENR", "genre" },
|
|
|
|
{ "LABL", "publisher" },
|
|
|
|
{ "MUSC", "composer" },
|
|
|
|
{ "NAME", "title" },
|
|
|
|
{ "NOTE", "note" },
|
|
|
|
{ "PROD", "producer" },
|
|
|
|
{ "PRSN", "personnel" },
|
|
|
|
{ "REMX", "remixer" },
|
|
|
|
{ "SING", "singer" },
|
|
|
|
{ "TRCK", "track" },
|
|
|
|
{ "WORD", "words" },
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
2012-01-12 12:20:36 +00:00
|
|
|
static int vqf_read_header(AVFormatContext *s)
|
2009-03-07 22:42:09 +00:00
|
|
|
{
|
|
|
|
VqfContext *c = s->priv_data;
|
2011-06-18 09:43:24 +00:00
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
2009-03-07 22:42:09 +00:00
|
|
|
int chunk_tag;
|
|
|
|
int rate_flag = -1;
|
|
|
|
int header_size;
|
|
|
|
int read_bitrate = 0;
|
2019-12-10 21:59:53 +00:00
|
|
|
int size, ret;
|
2011-10-30 04:46:16 +00:00
|
|
|
uint8_t comm_chunk[12];
|
2009-03-07 22:42:09 +00:00
|
|
|
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(s->pb, 12);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
header_size = avio_rb32(s->pb);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2019-06-18 21:17:23 +00:00
|
|
|
if (header_size < 0)
|
|
|
|
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 18:42:52 +00:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_TWINVQ;
|
2009-03-07 22:42:09 +00:00
|
|
|
st->start_time = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
int len;
|
2011-02-21 15:43:01 +00:00
|
|
|
chunk_tag = avio_rl32(s->pb);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
|
|
|
if (chunk_tag == MKTAG('D','A','T','A'))
|
|
|
|
break;
|
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
len = avio_rb32(s->pb);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2019-06-18 21:17:23 +00:00
|
|
|
if ((unsigned) len > INT_MAX/2 || header_size < 8) {
|
2009-03-07 22:42:09 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "Malformed header\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
header_size -= 8;
|
|
|
|
|
|
|
|
switch(chunk_tag){
|
|
|
|
case MKTAG('C','O','M','M'):
|
2020-11-01 19:20:02 +00:00
|
|
|
if (len < 12)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2011-10-30 04:46:16 +00:00
|
|
|
avio_read(s->pb, comm_chunk, 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 18:42:52 +00:00
|
|
|
st->codecpar->channels = AV_RB32(comm_chunk ) + 1;
|
2011-10-30 04:46:16 +00:00
|
|
|
read_bitrate = AV_RB32(comm_chunk + 4);
|
|
|
|
rate_flag = AV_RB32(comm_chunk + 8);
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(s->pb, len-12);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2016-04-10 19:58:15 +00:00
|
|
|
if (st->codecpar->channels <= 0) {
|
2013-05-07 20:26:22 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid number of channels\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2016-12-12 23:38:25 +00:00
|
|
|
st->codecpar->bit_rate = (int64_t)read_bitrate * 1000;
|
2009-03-07 22:42:09 +00:00
|
|
|
break;
|
2012-01-07 17:31:31 +00:00
|
|
|
case MKTAG('D','S','I','Z'): // size of compressed data
|
|
|
|
{
|
2014-07-29 19:10:39 +00:00
|
|
|
av_dict_set_int(&s->metadata, "size", avio_rb32(s->pb), 0);
|
2012-01-07 17:31:31 +00:00
|
|
|
}
|
2009-03-07 22:42:09 +00:00
|
|
|
break;
|
2012-01-07 17:31:31 +00:00
|
|
|
case MKTAG('Y','E','A','R'): // recording date
|
|
|
|
case MKTAG('E','N','C','D'): // compression date
|
|
|
|
case MKTAG('E','X','T','R'): // reserved
|
|
|
|
case MKTAG('_','Y','M','H'): // reserved
|
|
|
|
case MKTAG('_','N','T','T'): // reserved
|
|
|
|
case MKTAG('_','I','D','3'): // reserved for ID3 tags
|
|
|
|
avio_skip(s->pb, FFMIN(len, header_size));
|
2009-03-07 22:42:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-01-07 17:31:31 +00:00
|
|
|
add_metadata(s, chunk_tag, len, header_size);
|
2009-03-07 22:42:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
header_size -= len;
|
|
|
|
|
2014-08-07 20:12:41 +00:00
|
|
|
} while (header_size >= 0 && !avio_feof(s->pb));
|
2009-03-07 22:42:09 +00:00
|
|
|
|
|
|
|
switch (rate_flag) {
|
|
|
|
case -1:
|
|
|
|
av_log(s, AV_LOG_ERROR, "COMM tag not found!\n");
|
|
|
|
return -1;
|
|
|
|
case 44:
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
st->codecpar->sample_rate = 44100;
|
2009-03-07 22:42:09 +00:00
|
|
|
break;
|
|
|
|
case 22:
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
st->codecpar->sample_rate = 22050;
|
2009-03-07 22:42:09 +00:00
|
|
|
break;
|
|
|
|
case 11:
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
st->codecpar->sample_rate = 11025;
|
2009-03-07 22:42:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-27 21:34:35 +00:00
|
|
|
if (rate_flag < 8 || rate_flag > 44) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid rate flag %d\n", rate_flag);
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-11-09 17:04:54 +00: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 18:42:52 +00:00
|
|
|
st->codecpar->sample_rate = rate_flag*1000;
|
2009-03-07 22:42:09 +00: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 18:42:52 +00:00
|
|
|
if (read_bitrate / st->codecpar->channels < 8 ||
|
|
|
|
read_bitrate / st->codecpar->channels > 48) {
|
2013-09-28 20:19:10 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid bitrate per channel %d\n",
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
read_bitrate / st->codecpar->channels);
|
2013-09-28 20:19:10 +00: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 18:42:52 +00:00
|
|
|
switch (((st->codecpar->sample_rate/1000) << 8) +
|
|
|
|
read_bitrate/st->codecpar->channels) {
|
2009-03-07 22:42:09 +00:00
|
|
|
case (11<<8) + 8 :
|
|
|
|
case (8 <<8) + 8 :
|
|
|
|
case (11<<8) + 10:
|
|
|
|
case (22<<8) + 32:
|
|
|
|
size = 512;
|
|
|
|
break;
|
|
|
|
case (16<<8) + 16:
|
|
|
|
case (22<<8) + 20:
|
|
|
|
case (22<<8) + 24:
|
|
|
|
size = 1024;
|
|
|
|
break;
|
|
|
|
case (44<<8) + 40:
|
|
|
|
case (44<<8) + 48:
|
|
|
|
size = 2048;
|
|
|
|
break;
|
|
|
|
default:
|
2016-01-30 12:08:37 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "Mode not supported: %d Hz, %"PRId64" kb/s.\n",
|
2017-09-21 23:33:22 +00:00
|
|
|
st->codecpar->sample_rate, st->codecpar->bit_rate);
|
2009-03-07 22:42:09 +00:00
|
|
|
return -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 18:42:52 +00:00
|
|
|
c->frame_bit_len = st->codecpar->bit_rate*size/st->codecpar->sample_rate;
|
|
|
|
avpriv_set_pts_info(st, 64, size, st->codecpar->sample_rate);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2011-10-30 04:46:16 +00:00
|
|
|
/* put first 12 bytes of COMM chunk in extradata */
|
2019-12-10 21:59:53 +00:00
|
|
|
if ((ret = ff_alloc_extradata(st->codecpar, 12)) < 0)
|
|
|
|
return ret;
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
memcpy(st->codecpar->extradata, comm_chunk, 12);
|
2011-10-30 04:46:16 +00:00
|
|
|
|
2012-01-07 17:31:31 +00:00
|
|
|
ff_metadata_conv_ctx(s, NULL, vqf_metadata_conv);
|
|
|
|
|
2009-03-07 22:42:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
VqfContext *c = s->priv_data;
|
|
|
|
int ret;
|
|
|
|
int size = (c->frame_bit_len - c->remaining_bits + 7)>>3;
|
|
|
|
|
2020-01-07 13:55:44 +00:00
|
|
|
if ((ret = av_new_packet(pkt, size + 2)) < 0)
|
|
|
|
return ret;
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2012-01-19 20:48:11 +00:00
|
|
|
pkt->pos = avio_tell(s->pb);
|
|
|
|
pkt->stream_index = 0;
|
2012-01-13 19:04:11 +00:00
|
|
|
pkt->duration = 1;
|
2012-01-19 20:48:11 +00:00
|
|
|
|
2009-03-07 22:42:09 +00:00
|
|
|
pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
|
|
|
|
pkt->data[1] = c->last_frame_bits;
|
2011-02-21 15:43:01 +00:00
|
|
|
ret = avio_read(s->pb, pkt->data+2, size);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2014-01-01 14:29:20 +00:00
|
|
|
if (ret != size) {
|
2009-03-07 22:42:09 +00:00
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
c->last_frame_bits = pkt->data[size+1];
|
|
|
|
c->remaining_bits = (size << 3) - c->frame_bit_len + c->remaining_bits;
|
|
|
|
|
|
|
|
return size+2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vqf_read_seek(AVFormatContext *s,
|
|
|
|
int stream_index, int64_t timestamp, int flags)
|
|
|
|
{
|
|
|
|
VqfContext *c = s->priv_data;
|
|
|
|
AVStream *st;
|
2015-02-20 20:00:57 +00:00
|
|
|
int64_t ret;
|
2009-03-07 22:42:09 +00:00
|
|
|
int64_t pos;
|
|
|
|
|
|
|
|
st = s->streams[stream_index];
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
pos = av_rescale_rnd(timestamp * st->codecpar->bit_rate,
|
2009-03-07 22:42:09 +00:00
|
|
|
st->time_base.num,
|
|
|
|
st->time_base.den * (int64_t)c->frame_bit_len,
|
|
|
|
(flags & AVSEEK_FLAG_BACKWARD) ?
|
|
|
|
AV_ROUND_DOWN : AV_ROUND_UP);
|
|
|
|
pos *= c->frame_bit_len;
|
|
|
|
|
|
|
|
st->cur_dts = av_rescale(pos, st->time_base.den,
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
st->codecpar->bit_rate * (int64_t)st->time_base.num);
|
2009-03-07 22:42:09 +00:00
|
|
|
|
2015-02-06 13:53:40 +00:00
|
|
|
if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + s->internal->data_offset, SEEK_SET)) < 0)
|
2009-03-07 22:42:09 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
c->remaining_bits = -7 - ((pos-7)&7);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:03:28 +00:00
|
|
|
AVInputFormat ff_vqf_demuxer = {
|
2011-07-16 20:18:12 +00:00
|
|
|
.name = "vqf",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"),
|
|
|
|
.priv_data_size = sizeof(VqfContext),
|
|
|
|
.read_probe = vqf_probe,
|
|
|
|
.read_header = vqf_read_header,
|
|
|
|
.read_packet = vqf_read_packet,
|
|
|
|
.read_seek = vqf_read_seek,
|
2012-01-06 17:18:07 +00:00
|
|
|
.extensions = "vqf,vql,vqe",
|
2009-03-07 22:42:09 +00:00
|
|
|
};
|