2015-02-13 07:36:17 +00:00
|
|
|
/*
|
|
|
|
* Digital Speech Standard (DSS) demuxer
|
|
|
|
* Copyright (c) 2014 Oleksij Rempel <linux@rempel-privat.de>
|
|
|
|
*
|
2015-02-19 20:44:58 +00:00
|
|
|
* This file is part of FFmpeg.
|
2015-02-13 07:36:17 +00:00
|
|
|
*
|
2015-02-19 20:44:58 +00:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2015-02-13 07:36:17 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2015-02-19 20:44:58 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2015-02-13 07:36:17 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2015-02-19 20:44:58 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2015-02-13 07:36:17 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/channel_layout.h"
|
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
|
|
|
|
#include "avformat.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
#define DSS_HEAD_OFFSET_AUTHOR 0xc
|
|
|
|
#define DSS_AUTHOR_SIZE 16
|
|
|
|
|
|
|
|
#define DSS_HEAD_OFFSET_START_TIME 0x26
|
|
|
|
#define DSS_HEAD_OFFSET_END_TIME 0x32
|
|
|
|
#define DSS_TIME_SIZE 12
|
|
|
|
|
|
|
|
#define DSS_HEAD_OFFSET_ACODEC 0x2a4
|
|
|
|
#define DSS_ACODEC_DSS_SP 0x0 /* SP mode */
|
|
|
|
#define DSS_ACODEC_G723_1 0x2 /* LP mode */
|
|
|
|
|
|
|
|
#define DSS_HEAD_OFFSET_COMMENT 0x31e
|
|
|
|
#define DSS_COMMENT_SIZE 64
|
|
|
|
|
|
|
|
#define DSS_BLOCK_SIZE 512
|
|
|
|
#define DSS_AUDIO_BLOCK_HEADER_SIZE 6
|
|
|
|
#define DSS_FRAME_SIZE 42
|
|
|
|
|
|
|
|
static const uint8_t frame_size[4] = { 24, 20, 4, 1 };
|
|
|
|
|
|
|
|
typedef struct DSSDemuxContext {
|
|
|
|
unsigned int audio_codec;
|
|
|
|
int counter;
|
|
|
|
int swap;
|
|
|
|
int dss_sp_swap_byte;
|
2015-02-24 13:57:39 +00:00
|
|
|
|
|
|
|
int packet_size;
|
2017-01-11 12:23:13 +00:00
|
|
|
int dss_header_size;
|
2015-02-13 07:36:17 +00:00
|
|
|
} DSSDemuxContext;
|
|
|
|
|
2019-03-21 00:18:37 +00:00
|
|
|
static int dss_probe(const AVProbeData *p)
|
2015-02-13 07:36:17 +00:00
|
|
|
{
|
2017-01-11 12:23:13 +00:00
|
|
|
if ( AV_RL32(p->buf) != MKTAG(0x2, 'd', 's', 's')
|
|
|
|
&& AV_RL32(p->buf) != MKTAG(0x3, 'd', 's', 's'))
|
2015-02-13 07:36:17 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dss_read_metadata_date(AVFormatContext *s, unsigned int offset,
|
|
|
|
const char *key)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
char datetime[64], string[DSS_TIME_SIZE + 1] = { 0 };
|
|
|
|
int y, month, d, h, minute, sec;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
avio_seek(pb, offset, SEEK_SET);
|
|
|
|
|
|
|
|
ret = avio_read(s->pb, string, DSS_TIME_SIZE);
|
|
|
|
if (ret < DSS_TIME_SIZE)
|
|
|
|
return ret < 0 ? ret : AVERROR_EOF;
|
|
|
|
|
2015-02-19 21:10:47 +00:00
|
|
|
if (sscanf(string, "%2d%2d%2d%2d%2d%2d", &y, &month, &d, &h, &minute, &sec) != 6)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2015-02-13 07:36:17 +00:00
|
|
|
/* We deal with a two-digit year here, so set the default date to 2000
|
|
|
|
* and hope it will never be used in the next century. */
|
|
|
|
snprintf(datetime, sizeof(datetime), "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
|
|
|
|
y + 2000, month, d, h, minute, sec);
|
|
|
|
return av_dict_set(&s->metadata, key, datetime, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dss_read_metadata_string(AVFormatContext *s, unsigned int offset,
|
|
|
|
unsigned int size, const char *key)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
char *value;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
avio_seek(pb, offset, SEEK_SET);
|
|
|
|
|
|
|
|
value = av_mallocz(size + 1);
|
|
|
|
if (!value)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
ret = avio_read(s->pb, value, size);
|
|
|
|
if (ret < size) {
|
2019-11-10 01:48:21 +00:00
|
|
|
av_free(value);
|
|
|
|
return ret < 0 ? ret : AVERROR_EOF;
|
2015-02-13 07:36:17 +00:00
|
|
|
}
|
|
|
|
|
2019-11-10 01:48:21 +00:00
|
|
|
return av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
|
2015-02-13 07:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dss_read_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
DSSDemuxContext *ctx = s->priv_data;
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
AVStream *st;
|
2017-01-11 12:23:13 +00:00
|
|
|
int ret, version;
|
2015-02-13 07:36:17 +00:00
|
|
|
|
|
|
|
st = avformat_new_stream(s, NULL);
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2017-01-11 12:23:13 +00:00
|
|
|
version = avio_r8(pb);
|
|
|
|
ctx->dss_header_size = version * DSS_BLOCK_SIZE;
|
|
|
|
|
2015-02-13 07:36:17 +00:00
|
|
|
ret = dss_read_metadata_string(s, DSS_HEAD_OFFSET_AUTHOR,
|
|
|
|
DSS_AUTHOR_SIZE, "author");
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = dss_read_metadata_date(s, DSS_HEAD_OFFSET_END_TIME, "date");
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = dss_read_metadata_string(s, DSS_HEAD_OFFSET_COMMENT,
|
|
|
|
DSS_COMMENT_SIZE, "comment");
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
avio_seek(pb, DSS_HEAD_OFFSET_ACODEC, SEEK_SET);
|
|
|
|
ctx->audio_codec = avio_r8(pb);
|
|
|
|
|
|
|
|
if (ctx->audio_codec == DSS_ACODEC_DSS_SP) {
|
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_id = AV_CODEC_ID_DSS_SP;
|
2016-04-10 19:58:15 +00:00
|
|
|
st->codecpar->sample_rate = 11025;
|
2021-04-01 20:31:13 +00:00
|
|
|
s->bit_rate = 8 * (DSS_FRAME_SIZE - 1) * st->codecpar->sample_rate
|
|
|
|
* 512 / (506 * 264);
|
2015-02-13 07:36:17 +00:00
|
|
|
} else if (ctx->audio_codec == DSS_ACODEC_G723_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
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_G723_1;
|
|
|
|
st->codecpar->sample_rate = 8000;
|
2015-02-13 07:36:17 +00:00
|
|
|
} else {
|
|
|
|
avpriv_request_sample(s, "Support for codec %x in DSS",
|
|
|
|
ctx->audio_codec);
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
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;
|
2017-03-31 11:46:26 +00:00
|
|
|
st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
|
2015-02-13 07:36:17 +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
|
|
|
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
|
2015-02-13 07:36:17 +00:00
|
|
|
st->start_time = 0;
|
|
|
|
|
|
|
|
/* Jump over header */
|
|
|
|
|
2017-01-11 12:23:13 +00:00
|
|
|
if (avio_seek(pb, ctx->dss_header_size, SEEK_SET) != ctx->dss_header_size)
|
2015-02-13 07:36:17 +00:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
|
|
|
ctx->counter = 0;
|
|
|
|
ctx->swap = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dss_skip_audio_header(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
DSSDemuxContext *ctx = s->priv_data;
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
|
|
|
|
avio_skip(pb, DSS_AUDIO_BLOCK_HEADER_SIZE);
|
|
|
|
ctx->counter += DSS_BLOCK_SIZE - DSS_AUDIO_BLOCK_HEADER_SIZE;
|
|
|
|
}
|
|
|
|
|
2021-04-01 20:55:31 +00:00
|
|
|
static void dss_sp_byte_swap(DSSDemuxContext *ctx, uint8_t *data)
|
2015-02-13 07:36:17 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ctx->swap) {
|
|
|
|
for (i = 0; i < DSS_FRAME_SIZE - 2; i += 2)
|
2021-04-01 20:55:31 +00:00
|
|
|
data[i] = data[i + 4];
|
2015-02-13 07:36:17 +00:00
|
|
|
|
2021-04-01 20:55:31 +00:00
|
|
|
/* Zero the padding. */
|
|
|
|
data[DSS_FRAME_SIZE] = 0;
|
|
|
|
data[1] = ctx->dss_sp_swap_byte;
|
2015-02-13 07:36:17 +00:00
|
|
|
} else {
|
2021-04-01 20:55:31 +00:00
|
|
|
ctx->dss_sp_swap_byte = data[DSS_FRAME_SIZE - 2];
|
2015-02-13 07:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure byte 40 is always 0 */
|
2021-04-01 20:55:31 +00:00
|
|
|
data[DSS_FRAME_SIZE - 2] = 0;
|
2015-02-13 07:36:17 +00:00
|
|
|
ctx->swap ^= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
DSSDemuxContext *ctx = s->priv_data;
|
|
|
|
int read_size, ret, offset = 0, buff_offset = 0;
|
2015-02-24 13:54:20 +00:00
|
|
|
int64_t pos = avio_tell(s->pb);
|
2015-02-13 07:36:17 +00:00
|
|
|
|
|
|
|
if (ctx->counter == 0)
|
|
|
|
dss_skip_audio_header(s, pkt);
|
|
|
|
|
|
|
|
if (ctx->swap) {
|
|
|
|
read_size = DSS_FRAME_SIZE - 2;
|
|
|
|
buff_offset = 3;
|
|
|
|
} else
|
|
|
|
read_size = DSS_FRAME_SIZE;
|
|
|
|
|
|
|
|
ret = av_new_packet(pkt, DSS_FRAME_SIZE);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2015-02-24 13:51:16 +00:00
|
|
|
pkt->duration = 264;
|
2015-02-24 13:54:20 +00:00
|
|
|
pkt->pos = pos;
|
2015-02-13 07:36:17 +00:00
|
|
|
pkt->stream_index = 0;
|
|
|
|
|
2021-04-01 20:07:40 +00:00
|
|
|
if (ctx->counter < read_size) {
|
2021-04-01 20:55:31 +00:00
|
|
|
ret = avio_read(s->pb, pkt->data + buff_offset,
|
2021-04-01 20:07:40 +00:00
|
|
|
ctx->counter);
|
|
|
|
if (ret < ctx->counter)
|
2015-02-13 07:36:17 +00:00
|
|
|
goto error_eof;
|
|
|
|
|
2021-04-01 20:07:40 +00:00
|
|
|
offset = ctx->counter;
|
2015-02-13 07:36:17 +00:00
|
|
|
dss_skip_audio_header(s, pkt);
|
|
|
|
}
|
2021-04-01 20:07:40 +00:00
|
|
|
ctx->counter -= read_size;
|
2015-02-13 07:36:17 +00:00
|
|
|
|
2021-04-01 20:55:31 +00:00
|
|
|
/* This will write one byte into pkt's padding if buff_offset == 3 */
|
|
|
|
ret = avio_read(s->pb, pkt->data + offset + buff_offset,
|
2015-02-13 07:36:17 +00:00
|
|
|
read_size - offset);
|
|
|
|
if (ret < read_size - offset)
|
|
|
|
goto error_eof;
|
|
|
|
|
2021-04-01 20:55:31 +00:00
|
|
|
dss_sp_byte_swap(ctx, pkt->data);
|
2015-02-13 07:36:17 +00:00
|
|
|
|
2015-02-24 13:58:17 +00:00
|
|
|
if (ctx->dss_sp_swap_byte < 0) {
|
2020-01-07 13:55:40 +00:00
|
|
|
return AVERROR(EAGAIN);
|
2015-02-24 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 21:02:18 +00:00
|
|
|
return 0;
|
2015-02-13 07:36:17 +00:00
|
|
|
|
|
|
|
error_eof:
|
|
|
|
return ret < 0 ? ret : AVERROR_EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
DSSDemuxContext *ctx = s->priv_data;
|
2015-02-24 13:57:39 +00:00
|
|
|
AVStream *st = s->streams[0];
|
2015-02-13 07:36:17 +00:00
|
|
|
int size, byte, ret, offset;
|
2015-02-24 13:54:20 +00:00
|
|
|
int64_t pos = avio_tell(s->pb);
|
2015-02-13 07:36:17 +00:00
|
|
|
|
|
|
|
if (ctx->counter == 0)
|
|
|
|
dss_skip_audio_header(s, pkt);
|
|
|
|
|
|
|
|
/* We make one byte-step here. Don't forget to add offset. */
|
|
|
|
byte = avio_r8(s->pb);
|
|
|
|
if (byte == 0xff)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
size = frame_size[byte & 3];
|
|
|
|
|
2015-02-24 13:57:39 +00:00
|
|
|
ctx->packet_size = size;
|
2021-04-01 20:07:40 +00:00
|
|
|
ctx->counter--;
|
2015-02-13 07:36:17 +00:00
|
|
|
|
|
|
|
ret = av_new_packet(pkt, size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-02-24 13:54:20 +00:00
|
|
|
pkt->pos = pos;
|
2015-02-13 07:36:17 +00:00
|
|
|
|
|
|
|
pkt->data[0] = byte;
|
|
|
|
offset = 1;
|
|
|
|
pkt->duration = 240;
|
2021-04-01 20:07:40 +00:00
|
|
|
s->bit_rate = 8LL * size-- * st->codecpar->sample_rate * 512 / (506 * pkt->duration);
|
2015-02-13 07:36:17 +00:00
|
|
|
|
|
|
|
pkt->stream_index = 0;
|
|
|
|
|
2021-04-01 20:07:40 +00:00
|
|
|
if (ctx->counter < size) {
|
2015-02-13 07:36:17 +00:00
|
|
|
ret = avio_read(s->pb, pkt->data + offset,
|
2021-04-01 20:07:40 +00:00
|
|
|
ctx->counter);
|
|
|
|
if (ret < ctx->counter)
|
2015-02-13 07:36:17 +00:00
|
|
|
return ret < 0 ? ret : AVERROR_EOF;
|
|
|
|
|
2021-04-01 20:07:40 +00:00
|
|
|
offset += ctx->counter;
|
|
|
|
size -= ctx->counter;
|
|
|
|
ctx->counter = 0;
|
2015-02-13 07:36:17 +00:00
|
|
|
dss_skip_audio_header(s, pkt);
|
|
|
|
}
|
2021-04-01 20:07:40 +00:00
|
|
|
ctx->counter -= size;
|
2015-02-13 07:36:17 +00:00
|
|
|
|
2021-04-01 20:07:40 +00:00
|
|
|
ret = avio_read(s->pb, pkt->data + offset, size);
|
|
|
|
if (ret < size)
|
2015-02-13 07:36:17 +00:00
|
|
|
return ret < 0 ? ret : AVERROR_EOF;
|
|
|
|
|
2021-04-01 21:02:18 +00:00
|
|
|
return 0;
|
2015-02-13 07:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dss_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
DSSDemuxContext *ctx = s->priv_data;
|
|
|
|
|
|
|
|
if (ctx->audio_codec == DSS_ACODEC_DSS_SP)
|
|
|
|
return dss_sp_read_packet(s, pkt);
|
|
|
|
else
|
|
|
|
return dss_723_1_read_packet(s, pkt);
|
|
|
|
}
|
|
|
|
|
2015-02-24 13:58:17 +00:00
|
|
|
static int dss_read_seek(AVFormatContext *s, int stream_index,
|
|
|
|
int64_t timestamp, int flags)
|
|
|
|
{
|
|
|
|
DSSDemuxContext *ctx = s->priv_data;
|
|
|
|
int64_t ret, seekto;
|
|
|
|
uint8_t header[DSS_AUDIO_BLOCK_HEADER_SIZE];
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
if (ctx->audio_codec == DSS_ACODEC_DSS_SP)
|
|
|
|
seekto = timestamp / 264 * 41 / 506 * 512;
|
|
|
|
else
|
|
|
|
seekto = timestamp / 240 * ctx->packet_size / 506 * 512;
|
|
|
|
|
|
|
|
if (seekto < 0)
|
|
|
|
seekto = 0;
|
|
|
|
|
2017-01-11 12:23:13 +00:00
|
|
|
seekto += ctx->dss_header_size;
|
2015-02-24 13:58:17 +00:00
|
|
|
|
|
|
|
ret = avio_seek(s->pb, seekto, SEEK_SET);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
avio_read(s->pb, header, DSS_AUDIO_BLOCK_HEADER_SIZE);
|
|
|
|
ctx->swap = !!(header[0] & 0x80);
|
|
|
|
offset = 2*header[1] + 2*ctx->swap;
|
|
|
|
if (offset < DSS_AUDIO_BLOCK_HEADER_SIZE)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
if (offset == DSS_AUDIO_BLOCK_HEADER_SIZE) {
|
|
|
|
ctx->counter = 0;
|
|
|
|
offset = avio_skip(s->pb, -DSS_AUDIO_BLOCK_HEADER_SIZE);
|
|
|
|
} else {
|
|
|
|
ctx->counter = DSS_BLOCK_SIZE - offset;
|
|
|
|
offset = avio_skip(s->pb, offset - DSS_AUDIO_BLOCK_HEADER_SIZE);
|
|
|
|
}
|
|
|
|
ctx->dss_sp_swap_byte = -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-19 17:45:24 +00:00
|
|
|
const AVInputFormat ff_dss_demuxer = {
|
2015-02-13 07:36:17 +00:00
|
|
|
.name = "dss",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Digital Speech Standard (DSS)"),
|
|
|
|
.priv_data_size = sizeof(DSSDemuxContext),
|
|
|
|
.read_probe = dss_probe,
|
|
|
|
.read_header = dss_read_header,
|
|
|
|
.read_packet = dss_read_packet,
|
2015-02-24 13:58:17 +00:00
|
|
|
.read_seek = dss_read_seek,
|
2015-02-13 07:36:17 +00:00
|
|
|
.extensions = "dss"
|
|
|
|
};
|