2 * Sony OpenMG (OMA) muxer
4 * Copyright (c) 2011 Michael Karcher
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "avio_internal.h"
30 static av_cold int oma_write_header(AVFormatContext *s)
33 AVCodecContext *format;
37 format = s->streams[0]->codec;
38 /* check for support of the format first */
40 for (srate_index = 0; ; srate_index++) {
41 if (ff_oma_srate_tab[srate_index] == 0) {
42 av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n",
44 return AVERROR(EINVAL);
47 if (ff_oma_srate_tab[srate_index] * 100 == format->sample_rate)
51 /* Metadata; OpenMG does not support ID3v2.4 */
52 ff_id3v2_write_simple(s, 3, ID3v2_EA3_MAGIC);
54 ffio_wfourcc(s->pb, "EA3\0");
55 avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
56 avio_w8(s->pb, EA3_HEADER_SIZE & 0x7F);
57 avio_wl16(s->pb, 0xFFFF); /* not encrypted */
58 for (i = 0; i < 6; i++)
59 avio_wl32(s->pb, 0); /* Padding + DRM id */
61 switch(format->codec_tag) {
62 case OMA_CODECID_ATRAC3:
63 if (format->channels != 2) {
64 av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels\n");
65 return AVERROR(EINVAL);
67 if (format->extradata_size == 14) /* WAV format extradata */
68 isjointstereo = format->extradata[6] != 0;
69 else if(format->extradata_size == 10) /* RM format extradata */
70 isjointstereo = format->extradata[8] == 0x12;
72 av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n");
73 return AVERROR(EINVAL);
75 avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) |
76 (isjointstereo << 17) |
78 (format->block_align/8));
80 case OMA_CODECID_ATRAC3P:
81 avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
83 (format->channels << 10) |
84 (format->block_align/8 - 1));
87 av_log(s, AV_LOG_ERROR, "unsupported codec tag %d for write\n",
89 return AVERROR(EINVAL);
91 for (i = 0; i < (EA3_HEADER_SIZE - 36)/4; i++)
92 avio_wl32(s->pb, 0); /* Padding */
97 AVOutputFormat ff_oma_muxer = {
99 .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
100 .mime_type = "audio/x-oma",
102 .audio_codec = AV_CODEC_ID_ATRAC3,
103 .write_header = oma_write_header,
104 .write_packet = ff_raw_write_packet,
105 .codec_tag = (const AVCodecTag* const []){ff_oma_codec_tags, 0},
106 .flags = AVFMT_NOTIMESTAMPS,