Browse code

lavf: add OpenMG audio muxer.

Signed-off-by: Anton Khirnov <anton@khirnov.net>

Michael Karcher authored on 2011/10/22 06:32:33
Showing 6 changed files
... ...
@@ -108,6 +108,7 @@ easier to use. The changes are:
108 108
 - CLJR encoder
109 109
 - Dxtory capture format decoder
110 110
 - v410 QuickTime uncompressed 4:4:4 10-bit encoder and decoder
111
+- OpenMG Audio muxer
111 112
 
112 113
 
113 114
 version 0.7:
... ...
@@ -296,7 +296,7 @@ library:
296 296
     @tab Used in Sierra CD-ROM games.
297 297
 @item Smacker                   @tab   @tab X
298 298
     @tab Multimedia format used by many games.
299
-@item Sony OpenMG (OMA)         @tab   @tab X
299
+@item Sony OpenMG (OMA)         @tab X @tab X
300 300
     @tab Audio format used in Sony Sonic Stage and Sony Vegas.
301 301
 @item Sony PlayStation STR      @tab   @tab X
302 302
 @item Sony Wave64 (W64)         @tab   @tab X
... ...
@@ -179,6 +179,7 @@ OBJS-$(CONFIG_OGG_DEMUXER)               += oggdec.o         \
179 179
 OBJS-$(CONFIG_OGG_MUXER)                 += oggenc.o \
180 180
                                             vorbiscomment.o
181 181
 OBJS-$(CONFIG_OMA_DEMUXER)               += omadec.o pcm.o oma.o
182
+OBJS-$(CONFIG_OMA_MUXER)                 += omaenc.o rawenc.o oma.o
182 183
 OBJS-$(CONFIG_PCM_ALAW_DEMUXER)          += pcmdec.o pcm.o rawdec.o
183 184
 OBJS-$(CONFIG_PCM_ALAW_MUXER)            += pcmenc.o rawenc.o
184 185
 OBJS-$(CONFIG_PCM_F32BE_DEMUXER)         += pcmdec.o pcm.o rawdec.o
... ...
@@ -156,7 +156,7 @@ void av_register_all(void)
156 156
     REGISTER_MUXDEMUX (NUT, nut);
157 157
     REGISTER_DEMUXER  (NUV, nuv);
158 158
     REGISTER_MUXDEMUX (OGG, ogg);
159
-    REGISTER_DEMUXER  (OMA, oma);
159
+    REGISTER_MUXDEMUX (OMA, oma);
160 160
     REGISTER_MUXDEMUX (PCM_ALAW,  pcm_alaw);
161 161
     REGISTER_MUXDEMUX (PCM_MULAW, pcm_mulaw);
162 162
     REGISTER_MUXDEMUX (PCM_F64BE, pcm_f64be);
163 163
new file mode 100644
... ...
@@ -0,0 +1,105 @@
0
+/*
1
+ * Sony OpenMG (OMA) muxer
2
+ *
3
+ * Copyright (c) 2011 Michael Karcher
4
+ *
5
+ * This file is part of Libav.
6
+ *
7
+ * Libav is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * Libav is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with Libav; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+#include "avformat.h"
23
+#include "avio_internal.h"
24
+#include "id3v2.h"
25
+#include "internal.h"
26
+#include "oma.h"
27
+#include "rawenc.h"
28
+
29
+static av_cold int oma_write_header(AVFormatContext *s)
30
+{
31
+    int i;
32
+    AVCodecContext *format;
33
+    int srate_index;
34
+    int isjointstereo;
35
+
36
+    format = s->streams[0]->codec;
37
+    /* check for support of the format first */
38
+
39
+    for (srate_index = 0; ; srate_index++) {
40
+        if (ff_oma_srate_tab[srate_index] == 0) {
41
+            av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n",
42
+                   format->sample_rate);
43
+            return AVERROR(EINVAL);
44
+        }
45
+
46
+        if (ff_oma_srate_tab[srate_index] * 100 == format->sample_rate)
47
+            break;
48
+    }
49
+
50
+    /* Metadata; OpenMG does not support ID3v2.4 */
51
+    ff_id3v2_write(s, 3, ID3v2_EA3_MAGIC);
52
+
53
+    ffio_wfourcc(s->pb, "EA3\0");
54
+    avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
55
+    avio_w8(s->pb, EA3_HEADER_SIZE & 0x7F);
56
+    avio_wl16(s->pb, 0xFFFF);       /* not encrypted */
57
+    for (i = 0; i < 6; i++)
58
+        avio_wl32(s->pb, 0);        /* Padding + DRM id */
59
+
60
+    switch(format->codec_tag) {
61
+    case OMA_CODECID_ATRAC3:
62
+        if (format->channels != 2) {
63
+            av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels");
64
+            return AVERROR(EINVAL);
65
+        }
66
+        if (format->extradata_size == 14) /* WAV format extradata */
67
+            isjointstereo = format->extradata[6] != 0;
68
+        else if(format->extradata_size == 10) /* RM format extradata */
69
+            isjointstereo = format->extradata[8] == 0x12;
70
+        else {
71
+            av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n");
72
+            return AVERROR(EINVAL);
73
+        }
74
+        avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) |
75
+                         (isjointstereo << 17) |
76
+                         (srate_index << 13) |
77
+                         (format->block_align/8));
78
+        break;
79
+    case OMA_CODECID_ATRAC3P:
80
+        avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
81
+                         (srate_index << 13) |
82
+                         (format->channels << 10) |
83
+                         (format->block_align/8 - 1));
84
+        break;
85
+    default:
86
+        av_log(s, AV_LOG_ERROR, "OMA: unsupported codec tag %d for write\n",
87
+               format->codec_tag);
88
+    }
89
+    for (i = 0; i < (EA3_HEADER_SIZE - 36)/4; i++)
90
+        avio_wl32(s->pb, 0);        /* Padding */
91
+
92
+    return 0;
93
+}
94
+
95
+AVOutputFormat ff_oma_muxer = {
96
+    .name              = "oma",
97
+    .long_name         = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
98
+    .mime_type         = "audio/x-oma",
99
+    .extensions        = "oma",
100
+    .audio_codec       = CODEC_ID_ATRAC3,
101
+    .write_header      = oma_write_header,
102
+    .write_packet      = ff_raw_write_packet,
103
+    .codec_tag         = (const AVCodecTag* const []){ff_oma_codec_tags, 0},
104
+};
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 53
33
-#define LIBAVFORMAT_VERSION_MINOR 17
33
+#define LIBAVFORMAT_VERSION_MINOR 18
34 34
 #define LIBAVFORMAT_VERSION_MICRO  0
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \