Bug 1229361 - Support AMR audio in OpenMAX PDM. r=alfredo
authorJohn Lin <jolin@mozilla.com>
Fri, 19 Feb 2016 15:58:12 +0800
changeset 321867 12e56cb35dc57123fb43bc38a44e09207cd68414
parent 321866 e6b2fb0874ab18c7df9c29cc27298ec5503d2d47
child 321868 06f762ea5c7ffaf01ea1299ffc148f87a26b0264
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalfredo
bugs1229361
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1229361 - Support AMR audio in OpenMAX PDM. r=alfredo MozReview-Commit-ID: 4csBcHMxJem
dom/media/platforms/omx/OmxPlatformLayer.cpp
--- a/dom/media/platforms/omx/OmxPlatformLayer.cpp
+++ b/dom/media/platforms/omx/OmxPlatformLayer.cpp
@@ -127,28 +127,62 @@ public:
 
     LOG("Config OMX_IndexParamAudioMp3, channel %d, sample rate %d",
         mp3Param.nChannels, mp3Param.nSampleRate);
 
     return ConfigAudioOutputPort(aOmx, aInfo);
   }
 };
 
+enum OmxAmrSampleRate {
+  kNarrowBand = 8000,
+  kWideBand = 16000,
+};
+
+template <OmxAmrSampleRate R>
+class OmxAmrConfig : public OmxAudioConfig
+{
+public:
+  OMX_ERRORTYPE Apply(OmxPlatformLayer& aOmx, const AudioInfo& aInfo) override
+  {
+    OMX_ERRORTYPE err;
+
+    OMX_AUDIO_PARAM_AMRTYPE def;
+    InitOmxParameter(&def);
+    def.nPortIndex = aOmx.InputPortIndex();
+    err = aOmx.GetParameter(OMX_IndexParamAudioAmr, &def, sizeof(def));
+    RETURN_IF_ERR(err);
+
+    def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
+    err = aOmx.SetParameter(OMX_IndexParamAudioAmr, &def, sizeof(def));
+    RETURN_IF_ERR(err);
+
+    MOZ_ASSERT(aInfo.mChannels == 1);
+    MOZ_ASSERT(aInfo.mRate == R);
+
+    return ConfigAudioOutputPort(aOmx, aInfo);
+  }
+};
+
 template<>
 UniquePtr<OmxAudioConfig>
 ConfigForMime(const nsACString& aMimeType)
 {
   UniquePtr<OmxAudioConfig> conf;
 
   if (OmxPlatformLayer::SupportsMimeType(aMimeType)) {
     if (aMimeType.EqualsLiteral("audio/mp4a-latm")) {
       conf.reset(new OmxAacConfig());
     } else if (aMimeType.EqualsLiteral("audio/mp3") ||
                 aMimeType.EqualsLiteral("audio/mpeg")) {
       conf.reset(new OmxMp3Config());
+    } else if (aMimeType.EqualsLiteral("audio/3gpp")) {
+      conf.reset(new OmxAmrConfig<OmxAmrSampleRate::kNarrowBand>());
+    } else if (aMimeType.EqualsLiteral("audio/amr-wb")) {
+      conf.reset(new OmxAmrConfig<OmxAmrSampleRate::kWideBand>());
     }
   }
   return Move(conf);
 }
 
 // There should be a better way to calculate it.
 #define MIN_VIDEO_INPUT_BUFFER_SIZE 64 * 1024