Bug 864180 - Move audio software decoder to app's process. r=doublec, a=leo+
authorSotaro Ikeda <sikeda@mozilla.com>
Mon, 06 May 2013 08:43:18 -0400
changeset 119282 b12f63fa6dc7836ea2996a1b5d9c82239e382923
parent 119281 de3c1a9e486e1bad62af99306af000123dd26e0c
child 119283 65049cb236f40eb9c00084c01ce4106ecda77687
push id763
push userryanvm@gmail.com
push dateTue, 07 May 2013 13:54:44 +0000
reviewersdoublec, leo
bugs864180
milestone18.0
Bug 864180 - Move audio software decoder to app's process. r=doublec, a=leo+
content/media/omx/OmxDecoder.cpp
--- a/content/media/omx/OmxDecoder.cpp
+++ b/content/media/omx/OmxDecoder.cpp
@@ -7,16 +7,17 @@
 #include <fcntl.h>
 
 #include "base/basictypes.h"
 #include <cutils/properties.h>
 #include <stagefright/MediaExtractor.h>
 #include <stagefright/MetaData.h>
 #include <stagefright/OMXClient.h>
 #include <stagefright/OMXCodec.h>
+#include <OMX.h>
 
 #include "mozilla/Preferences.h"
 #include "mozilla/Types.h"
 #include "MPAPI.h"
 #include "prlog.h"
 
 #include "GonkNativeWindow.h"
 #include "GonkNativeWindowClient.h"
@@ -165,16 +166,24 @@ public:
   AutoStopMediaSource(const sp<MediaSource>& aMediaSource) : mMediaSource(aMediaSource) {
   }
 
   ~AutoStopMediaSource() {
     mMediaSource->stop();
   }
 };
 
+static sp<IOMX> sOMX = nullptr;
+static sp<IOMX> GetOMX() {
+  if(sOMX.get() == nullptr) {
+    sOMX = new OMX;
+    }
+  return sOMX;
+}
+
 bool OmxDecoder::Init() {
 #ifdef PR_LOGGING
   if (!gOmxDecoderLog) {
     gOmxDecoderLog = PR_NewLogModule("OmxDecoder");
   }
 #endif
 
   //register sniffers, if they are not registered in this process.
@@ -291,24 +300,38 @@ bool OmxDecoder::Init() {
 
   sp<MediaSource> audioTrack;
   sp<MediaSource> audioSource;
   if (audioTrackIndex != -1 && (audioTrack = extractor->getTrack(audioTrackIndex)) != nullptr)
   {
     if (!strcasecmp(audioMime, "audio/raw")) {
       audioSource = audioTrack;
     } else {
+      // try to load hardware codec in mediaserver process.
+      int flags = kHardwareCodecsOnly;
       audioSource = OMXCodec::Create(omx,
                                      audioTrack->getFormat(),
                                      false, // decoder
-                                     audioTrack);
+                                     audioTrack,
+                                     nullptr,
+                                     flags);
     }
     if (audioSource == nullptr) {
-      NS_WARNING("Couldn't create OMX audio source");
-      return false;
+      // try to load software codec in this process.
+      int flags = kSoftwareCodecsOnly;
+      audioSource = OMXCodec::Create(GetOMX(),
+                                     audioTrack->getFormat(),
+                                     false, // decoder
+                                     audioTrack,
+                                     nullptr,
+                                     flags);
+      if (audioSource == nullptr) {
+        NS_WARNING("Couldn't create OMX audio source");
+        return false;
+      }
     }
     if (audioSource->start() != OK) {
       NS_WARNING("Couldn't start OMX audio source");
       return false;
     }
 
     int64_t durationUs;
     if (audioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {