---
 Changelog                |    1 +
 doc/general.texi         |    2 +-
 libavformat/Makefile     |    1 +
 libavformat/allformats.c |    2 +-
 libavformat/oma.c        |   97 ++++++++++++++++++++++++++++++++++++++++++++-
 libavformat/version.h    |    2 +-
 6 files changed, 99 insertions(+), 6 deletions(-)

diff --git a/Changelog b/Changelog
index 491f93b..6e03c0e 100644
--- a/Changelog
+++ b/Changelog
@@ -55,6 +55,7 @@ easier to use. The changes are:
 - Ut Video decoder
 - Speex encoding via libspeex
 - 4:2:2 H.264 decoding support
+- OpenMG Audio muxer
 
 
 version 0.7:
diff --git a/doc/general.texi b/doc/general.texi
index b1c2534..4da87b9 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -237,7 +237,7 @@ library:
     @tab Used in Sierra CD-ROM games.
 @item Smacker                   @tab   @tab X
     @tab Multimedia format used by many games.
-@item Sony OpenMG (OMA)         @tab   @tab X
+@item Sony OpenMG (OMA)         @tab X @tab X
     @tab Audio format used in Sony Sonic Stage and Sony Vegas.
 @item Sony PlayStation STR      @tab   @tab X
 @item Sony Wave64 (W64)         @tab   @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6973b15..8c545bc 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -174,6 +174,7 @@ OBJS-$(CONFIG_OGG_DEMUXER)               += oggdec.o        
 \
 OBJS-$(CONFIG_OGG_MUXER)                 += oggenc.o \
                                             vorbiscomment.o
 OBJS-$(CONFIG_OMA_DEMUXER)               += oma.o pcm.o
+OBJS-$(CONFIG_OMA_MUXER)                 += oma.o rawenc.o
 OBJS-$(CONFIG_PCM_ALAW_DEMUXER)          += pcmdec.o pcm.o rawdec.o
 OBJS-$(CONFIG_PCM_ALAW_MUXER)            += pcmenc.o rawenc.o
 OBJS-$(CONFIG_PCM_F32BE_DEMUXER)         += pcmdec.o pcm.o rawdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 8e89b2f..797f388 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -154,7 +154,7 @@ void av_register_all(void)
     REGISTER_MUXDEMUX (NUT, nut);
     REGISTER_DEMUXER  (NUV, nuv);
     REGISTER_MUXDEMUX (OGG, ogg);
-    REGISTER_DEMUXER  (OMA, oma);
+    REGISTER_MUXDEMUX (OMA, oma);
     REGISTER_MUXDEMUX (PCM_ALAW,  pcm_alaw);
     REGISTER_MUXDEMUX (PCM_MULAW, pcm_mulaw);
     REGISTER_MUXDEMUX (PCM_F64BE, pcm_f64be);
diff --git a/libavformat/oma.c b/libavformat/oma.c
index da01468..faac587 100644
--- a/libavformat/oma.c
+++ b/libavformat/oma.c
@@ -1,9 +1,10 @@
 /*
- * Sony OpenMG (OMA) demuxer
+ * Sony OpenMG (OMA) muxer and demuxer
  *
  * Copyright (c) 2008 Maxim Poliakovski
  *               2008 Benjamin Larsson
  *               2011 David Goldwich
+ *               2011 Michael Karcher
  *
  * This file is part of Libav.
  *
@@ -24,7 +25,7 @@
 
 /**
  * @file
- * This is a demuxer for Sony OpenMG Music files
+ * This is a muxer and demuxer for Sony OpenMG Music files
  *
  * Known file extensions: ".oma", "aa3"
  * The format of such files consists of three parts:
@@ -41,6 +42,8 @@
  */
 
 #include "avformat.h"
+#include "rawenc.h"
+#include "avio_internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/des.h"
 #include "pcm.h"
@@ -65,6 +68,10 @@ static const AVCodecTag codec_oma_tags[] = {
     { CODEC_ID_MP3,     OMA_CODECID_MP3 },
 };
 
+static const uint16_t srate_tab[6] = {320,441,480,882,960,0};
+
+#if CONFIG_OMA_DEMUXER
+
 static const uint64_t leaf_table[] = {
     0xd79e8283acea4620, 0x7a9762f445afd0d8,
     0x354d60a60b8c79f1, 0x584e1cde00b07aee,
@@ -274,7 +281,6 @@ static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta 
*em, uint8_t *header)
 static int oma_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
 {
-    static const uint16_t srate_tab[6] = {320,441,480,882,960,0};
     int     ret, framesize, jsflag, samplerate;
     uint32_t codec_params;
     int16_t eid;
@@ -444,3 +450,88 @@ AVInputFormat ff_oma_demuxer = {
     .codec_tag      = (const AVCodecTag* const []){codec_oma_tags, 0},
 };
 
+#endif
+
+#if CONFIG_OMA_MUXER
+
+static av_cold int oma_write_header(AVFormatContext *s)
+{
+    int i;
+    AVCodecContext *format;
+    int srate_index;
+    int isjointstereo;
+
+    format = s->streams[0]->codec;
+    /* check for support of the format first */
+
+    for (srate_index = 0; ; srate_index++)
+    {
+        if(srate_tab[srate_index] == 0)
+        {
+            av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG 
audio\n",
+                                    format->sample_rate);
+            return -1;
+        }
+
+        if(srate_tab[srate_index] * 100 == format->sample_rate)
+            break;
+    }
+
+    /* Metadata; OpenMG does not support ID3v2.4 */
+    ff_id3v2_write(s, 3, ID3v2_EA3_MAGIC);
+
+    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 */
+    for (i = 0;i < 6;i++)
+        avio_wl32(s->pb, 0);           /* Padding + DRM id */
+
+    switch(format->codec_tag)
+    {
+        case OMA_CODECID_ATRAC3:
+            if (format->channels != 2) {
+                av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 
2 channels");
+                return -1;
+            }
+            if (format->extradata_size == 14) /* WAV format extradata */
+                isjointstereo = format->extradata[6] != 0;
+            else if(format->extradata_size == 10) /* RM format extradata */
+                isjointstereo = format->extradata[8] == 0x12;
+            else {
+                av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata 
size\n");
+                return -1;
+            }
+            avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) |
+                             (isjointstereo << 17) |
+                             (srate_index << 13) |
+                             (format->block_align/8));
+            break;
+        case OMA_CODECID_ATRAC3P:
+            avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
+                             (srate_index << 13) |
+                             (format->channels << 10) |
+                             (format->block_align/8 - 1));
+            break;
+        default:
+            av_log(s, AV_LOG_ERROR, "OMA: unsupported codec tag %d for 
write\n",
+                    format->codec_tag);
+    }
+    for (i = 0;i < (EA3_HEADER_SIZE - 36)/4;i++)
+        avio_wl32(s->pb, 0);           /* Padding */
+
+    return 0;
+}
+
+AVOutputFormat ff_oma_muxer = {
+    .name              = "oma",
+    .long_name         = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
+    .mime_type         = "audio/x-oma",
+    .extensions        = "oma",
+    .audio_codec       = CODEC_ID_ATRAC3,
+    .video_codec       = CODEC_ID_NONE,
+    .write_header      = oma_write_header,
+    .write_packet      = ff_raw_write_packet,
+    .codec_tag         = (const AVCodecTag* const []){codec_oma_tags, 0},
+};
+#endif
diff --git a/libavformat/version.h b/libavformat/version.h
index 9de30ea..df60cc4 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -24,7 +24,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 10
+#define LIBAVFORMAT_VERSION_MINOR 11
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
1.7.6.3

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to