2011-10-22 00:32:33 +03:00
|
|
|
/*
|
|
|
|
* Sony OpenMG (OMA) muxer
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 Michael Karcher
|
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* This file is part of FFmpeg.
|
2011-10-22 00:32:33 +03:00
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2011-10-22 00:32:33 +03: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.
|
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2011-10-22 00:32:33 +03: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
|
2013-08-16 00:12:51 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2011-10-22 00:32:33 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
|
|
|
#include "avio_internal.h"
|
|
|
|
#include "id3v2.h"
|
|
|
|
#include "internal.h"
|
2023-01-27 16:06:00 +02:00
|
|
|
#include "mux.h"
|
2011-10-22 00:32:33 +03:00
|
|
|
#include "oma.h"
|
|
|
|
#include "rawenc.h"
|
|
|
|
|
|
|
|
static av_cold int oma_write_header(AVFormatContext *s)
|
|
|
|
{
|
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
|
|
|
AVCodecParameters *par;
|
2011-10-22 00:32:33 +03:00
|
|
|
int srate_index;
|
|
|
|
int isjointstereo;
|
|
|
|
|
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
|
|
|
par = s->streams[0]->codecpar;
|
2011-10-22 00:32:33 +03:00
|
|
|
/* check for support of the format first */
|
|
|
|
|
|
|
|
for (srate_index = 0; ; srate_index++) {
|
|
|
|
if (ff_oma_srate_tab[srate_index] == 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\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 21:42:52 +03:00
|
|
|
par->sample_rate);
|
2011-10-22 00:32:33 +03:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
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 (ff_oma_srate_tab[srate_index] * 100 == par->sample_rate)
|
2011-10-22 00:32:33 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Metadata; OpenMG does not support ID3v2.4 */
|
2012-02-28 00:08:50 +03:00
|
|
|
ff_id3v2_write_simple(s, 3, ID3v2_EA3_MAGIC);
|
2011-10-22 00:32:33 +03:00
|
|
|
|
|
|
|
ffio_wfourcc(s->pb, "EA3\0");
|
|
|
|
avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
|
|
|
|
avio_w8(s->pb, EA3_HEADER_SIZE & 0x7F);
|
|
|
|
avio_wl16(s->pb, 0xFFFF); /* not encrypted */
|
2021-09-22 23:47:58 +02:00
|
|
|
ffio_fill(s->pb, 0, 6 * 4); /* Padding + DRM id */
|
2011-10-22 00:32: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
|
|
|
switch (par->codec_tag) {
|
2011-10-22 00:32:33 +03:00
|
|
|
case OMA_CODECID_ATRAC3:
|
2017-03-31 18:04:05 +02:00
|
|
|
if (par->ch_layout.nb_channels != 2) {
|
2012-09-01 13:35:14 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels\n");
|
2011-10-22 00:32:33 +03:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
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 (par->extradata_size == 14) /* WAV format extradata */
|
|
|
|
isjointstereo = par->extradata[6] != 0;
|
|
|
|
else if(par->extradata_size == 10) /* RM format extradata */
|
|
|
|
isjointstereo = par->extradata[8] == 0x12;
|
2011-10-22 00:32:33 +03:00
|
|
|
else {
|
|
|
|
av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) |
|
|
|
|
(isjointstereo << 17) |
|
|
|
|
(srate_index << 13) |
|
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
|
|
|
(par->block_align/8));
|
2011-10-22 00:32:33 +03:00
|
|
|
break;
|
|
|
|
case OMA_CODECID_ATRAC3P:
|
|
|
|
avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
|
|
|
|
(srate_index << 13) |
|
2017-03-31 18:04:05 +02:00
|
|
|
(par->ch_layout.nb_channels << 10) |
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
(par->block_align/8 - 1));
|
2011-10-22 00:32:33 +03:00
|
|
|
break;
|
|
|
|
default:
|
2017-03-27 21:31:46 +02:00
|
|
|
av_log(s, AV_LOG_ERROR, "unsupported codec tag %s for write\n",
|
|
|
|
av_fourcc2str(par->codec_tag));
|
2012-11-24 12:51:47 +03:00
|
|
|
return AVERROR(EINVAL);
|
2011-10-22 00:32:33 +03:00
|
|
|
}
|
2021-09-22 23:47:58 +02:00
|
|
|
ffio_fill(s->pb, 0, EA3_HEADER_SIZE - 36); /* Padding */
|
2011-10-22 00:32:33 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-27 16:06:00 +02:00
|
|
|
const FFOutputFormat ff_oma_muxer = {
|
|
|
|
.p.name = "oma",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
|
|
|
|
.p.mime_type = "audio/x-oma",
|
|
|
|
.p.extensions = "oma",
|
|
|
|
.p.audio_codec = AV_CODEC_ID_ATRAC3,
|
2011-10-22 00:32:33 +03:00
|
|
|
.write_header = oma_write_header,
|
|
|
|
.write_packet = ff_raw_write_packet,
|
2023-01-27 16:06:00 +02:00
|
|
|
.p.codec_tag = ff_oma_codec_tags_list,
|
|
|
|
.p.flags = AVFMT_NOTIMESTAMPS,
|
2011-10-22 00:32:33 +03:00
|
|
|
};
|