00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00052 ff_id3v2_write_simple(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);
00058 for (i = 0; i < 6; i++)
00059 avio_wl32(s->pb, 0);
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)
00068 isjointstereo = format->extradata[6] != 0;
00069 else if(format->extradata_size == 10)
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);
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 };