• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/omaenc.c

Go to the documentation of this file.
00001 /*
00002  * Sony OpenMG (OMA) muxer
00003  *
00004  * Copyright (c) 2011 Michael Karcher
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "avformat.h"
00024 #include "avio_internal.h"
00025 #include "id3v2.h"
00026 #include "internal.h"
00027 #include "oma.h"
00028 #include "rawenc.h"
00029 
00030 static av_cold int oma_write_header(AVFormatContext *s)
00031 {
00032     int i;
00033     AVCodecContext *format;
00034     int srate_index;
00035     int isjointstereo;
00036 
00037     format = s->streams[0]->codec;
00038     /* check for support of the format first */
00039 
00040     for (srate_index = 0; ; srate_index++) {
00041         if (ff_oma_srate_tab[srate_index] == 0) {
00042             av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n",
00043                    format->sample_rate);
00044             return AVERROR(EINVAL);
00045         }
00046 
00047         if (ff_oma_srate_tab[srate_index] * 100 == format->sample_rate)
00048             break;
00049     }
00050 
00051     /* Metadata; OpenMG does not support ID3v2.4 */
00052     ff_id3v2_write(s, 3, ID3v2_EA3_MAGIC);
00053 
00054     ffio_wfourcc(s->pb, "EA3\0");
00055     avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
00056     avio_w8(s->pb, EA3_HEADER_SIZE & 0x7F);
00057     avio_wl16(s->pb, 0xFFFF);       /* not encrypted */
00058     for (i = 0; i < 6; i++)
00059         avio_wl32(s->pb, 0);        /* Padding + DRM id */
00060 
00061     switch(format->codec_tag) {
00062     case OMA_CODECID_ATRAC3:
00063         if (format->channels != 2) {
00064             av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels");
00065             return AVERROR(EINVAL);
00066         }
00067         if (format->extradata_size == 14) /* WAV format extradata */
00068             isjointstereo = format->extradata[6] != 0;
00069         else if(format->extradata_size == 10) /* RM format extradata */
00070             isjointstereo = format->extradata[8] == 0x12;
00071         else {
00072             av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n");
00073             return AVERROR(EINVAL);
00074         }
00075         avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) |
00076                          (isjointstereo << 17) |
00077                          (srate_index << 13) |
00078                          (format->block_align/8));
00079         break;
00080     case OMA_CODECID_ATRAC3P:
00081         avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
00082                          (srate_index << 13) |
00083                          (format->channels << 10) |
00084                          (format->block_align/8 - 1));
00085         break;
00086     default:
00087         av_log(s, AV_LOG_ERROR, "OMA: unsupported codec tag %d for write\n",
00088                format->codec_tag);
00089     }
00090     for (i = 0; i < (EA3_HEADER_SIZE - 36)/4; i++)
00091         avio_wl32(s->pb, 0);        /* Padding */
00092 
00093     return 0;
00094 }
00095 
00096 AVOutputFormat ff_oma_muxer = {
00097     .name              = "oma",
00098     .long_name         = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
00099     .mime_type         = "audio/x-oma",
00100     .extensions        = "oma",
00101     .audio_codec       = CODEC_ID_ATRAC3,
00102     .write_header      = oma_write_header,
00103     .write_packet      = ff_raw_write_packet,
00104     .codec_tag         = (const AVCodecTag* const []){ff_oma_codec_tags, 0},
00105 };
Generated on Sun Apr 22 2012 21:54:08 for Libav by doxygen 1.7.1