2012-06-17 12:54:31 +00:00
|
|
|
/*
|
|
|
|
* iLBC storage file format
|
|
|
|
* Copyright (c) 2012 Martin Storsjo
|
|
|
|
*
|
2012-06-19 18:52:00 +00:00
|
|
|
* This file is part of FFmpeg.
|
2012-06-17 12:54:31 +00:00
|
|
|
*
|
2012-06-19 18:52:00 +00:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2012-06-17 12:54:31 +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.
|
|
|
|
*
|
2012-06-19 18:52:00 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2012-06-17 12:54:31 +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
|
2012-06-19 18:52:00 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2012-06-17 12:54:31 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2022-02-23 12:56:49 +00:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2012-06-17 12:54:31 +00:00
|
|
|
#include "avformat.h"
|
2024-02-10 14:50:43 +00:00
|
|
|
#include "demux.h"
|
2012-06-17 12:54:31 +00:00
|
|
|
#include "internal.h"
|
2023-01-27 14:06:00 +00:00
|
|
|
#include "mux.h"
|
2020-04-02 16:05:15 +00:00
|
|
|
#include "rawenc.h"
|
2012-06-17 12:54:31 +00:00
|
|
|
|
|
|
|
static const char mode20_header[] = "#!iLBC20\n";
|
|
|
|
static const char mode30_header[] = "#!iLBC30\n";
|
|
|
|
|
|
|
|
static int ilbc_write_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
2024-03-19 20:40:54 +00:00
|
|
|
AVCodecParameters *par = s->streams[0]->codecpar;
|
2012-06-17 12:54:31 +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
|
|
|
if (par->block_align == 50) {
|
2012-06-17 12:54:31 +00:00
|
|
|
avio_write(pb, mode30_header, sizeof(mode30_header) - 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
|
|
|
} else if (par->block_align == 38) {
|
2012-06-17 12:54:31 +00:00
|
|
|
avio_write(pb, mode20_header, sizeof(mode20_header) - 1);
|
|
|
|
} else {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Unsupported mode\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-21 00:18:37 +00:00
|
|
|
static int ilbc_probe(const AVProbeData *p)
|
2012-06-17 12:54:31 +00:00
|
|
|
{
|
|
|
|
// Only check for "#!iLBC" which matches both formats
|
|
|
|
if (!memcmp(p->buf, mode20_header, 6))
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ilbc_read_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
AVStream *st;
|
|
|
|
uint8_t header[9];
|
|
|
|
|
|
|
|
avio_read(pb, header, 9);
|
|
|
|
|
|
|
|
st = avformat_new_stream(s, NULL);
|
|
|
|
if (!st)
|
|
|
|
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 18:42:52 +00:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_ILBC;
|
|
|
|
st->codecpar->sample_rate = 8000;
|
2017-03-31 12:20:59 +00:00
|
|
|
st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
|
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;
|
2012-06-17 12:54:31 +00:00
|
|
|
st->start_time = 0;
|
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);
|
2012-06-17 12:54:31 +00:00
|
|
|
if (!memcmp(header, mode20_header, sizeof(mode20_header) - 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->block_align = 38;
|
|
|
|
st->codecpar->bit_rate = 15200;
|
2012-06-17 12:54:31 +00:00
|
|
|
} else if (!memcmp(header, mode30_header, sizeof(mode30_header) - 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->block_align = 50;
|
|
|
|
st->codecpar->bit_rate = 13333;
|
2012-06-17 12:54:31 +00:00
|
|
|
} else {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Unrecognized iLBC file header\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ilbc_read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
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
|
|
|
AVCodecParameters *par = s->streams[0]->codecpar;
|
2012-06-17 12:54:31 +00:00
|
|
|
int ret;
|
|
|
|
|
2021-02-03 07:19:39 +00:00
|
|
|
if ((ret = av_get_packet(s->pb, pkt, par->block_align)) != par->block_align)
|
|
|
|
return ret < 0 ? ret : AVERROR_INVALIDDATA;
|
2012-06-17 12:54:31 +00:00
|
|
|
|
|
|
|
pkt->stream_index = 0;
|
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
|
|
|
pkt->duration = par->block_align == 38 ? 160 : 240;
|
2012-06-17 12:54:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-10 14:50:43 +00:00
|
|
|
const FFInputFormat ff_ilbc_demuxer = {
|
|
|
|
.p.name = "ilbc",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("iLBC storage"),
|
|
|
|
.p.flags = AVFMT_GENERIC_INDEX,
|
2012-06-17 12:54:31 +00:00
|
|
|
.read_probe = ilbc_probe,
|
|
|
|
.read_header = ilbc_read_header,
|
|
|
|
.read_packet = ilbc_read_packet,
|
|
|
|
};
|
|
|
|
|
2020-04-07 14:55:41 +00:00
|
|
|
#if CONFIG_ILBC_MUXER
|
2023-01-27 14:06:00 +00:00
|
|
|
const FFOutputFormat ff_ilbc_muxer = {
|
|
|
|
.p.name = "ilbc",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("iLBC storage"),
|
|
|
|
.p.mime_type = "audio/iLBC",
|
|
|
|
.p.extensions = "lbc",
|
2024-03-19 20:40:54 +00:00
|
|
|
.p.video_codec = AV_CODEC_ID_NONE,
|
2023-01-27 14:06:00 +00:00
|
|
|
.p.audio_codec = AV_CODEC_ID_ILBC,
|
2024-03-19 20:40:54 +00:00
|
|
|
.p.subtitle_codec = AV_CODEC_ID_NONE,
|
2023-01-27 14:06:00 +00:00
|
|
|
.p.flags = AVFMT_NOTIMESTAMPS,
|
2024-03-19 22:28:36 +00:00
|
|
|
.flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH |
|
|
|
|
FF_OFMT_FLAG_ONLY_DEFAULT_CODECS,
|
2012-06-17 12:54:31 +00:00
|
|
|
.write_header = ilbc_write_header,
|
2020-04-02 16:05:15 +00:00
|
|
|
.write_packet = ff_raw_write_packet,
|
2012-06-17 12:54:31 +00:00
|
|
|
};
|
2020-04-07 14:55:41 +00:00
|
|
|
#endif
|