Bug 803471 - Part 2 - Use OmxClient in OmxDecoder. r=cdouble
authorSotaro Ikeda <sikeda@mozilla.com>
Fri, 08 Mar 2013 14:43:32 -0500
changeset 124261 8a29e43d47af22637e254c45633e6c53c4367dfc
parent 124260 2422115b7400378bf635f41c94638a7150dba5c8
child 124262 bc9d903311b72989395e7e8fef44c6d68de880d2
push id24412
push userryanvm@gmail.com
push dateSun, 10 Mar 2013 00:01:53 +0000
treeherdermozilla-central@9e6232e86000 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscdouble
bugs803471
milestone22.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 803471 - Part 2 - Use OmxClient in OmxDecoder. r=cdouble
content/media/omx/OmxDecoder.cpp
content/media/omx/OmxDecoder.h
--- a/content/media/omx/OmxDecoder.cpp
+++ b/content/media/omx/OmxDecoder.cpp
@@ -3,21 +3,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include <unistd.h>
 #include <fcntl.h>
 
 #include "base/basictypes.h"
 #include <cutils/properties.h>
-#include <stagefright/DataSource.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 "OmxDecoder.h"
@@ -165,24 +164,16 @@ 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.
@@ -232,26 +223,33 @@ bool OmxDecoder::Init() {
   }
 
   mResource->SetReadMode(MediaCacheStream::MODE_PLAYBACK);
 
   int64_t totalDurationUs = 0;
 
   mNativeWindow = new GonkNativeWindow();
 
+  // OMXClient::connect() always returns OK and abort's fatally if
+  // it can't connect.
+  OMXClient client;
+  status_t err = client.connect();
+  NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
+  sp<IOMX> omx = client.interface();
+
   sp<MediaSource> videoTrack;
   sp<MediaSource> videoSource;
   if (videoTrackIndex != -1 && (videoTrack = extractor->getTrack(videoTrackIndex)) != nullptr) {
     // Experience with OMX codecs is that only the HW decoders are
     // worth bothering with, at least on the platforms where this code
     // is currently used, and for formats this code is currently used
     // for (h.264).  So if we don't get a hardware decoder, just give
     // up.
     int flags = kHardwareCodecsOnly;
-    videoSource = OMXCodec::Create(GetOMX(),
+    videoSource = OMXCodec::Create(omx,
                                    videoTrack->getFormat(),
                                    false, // decoder
                                    videoTrack,
                                    nullptr,
                                    flags,
                                    mNativeWindow);
     if (videoSource == nullptr) {
       NS_WARNING("Couldn't create OMX video source");
@@ -291,17 +289,17 @@ 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 {
-      audioSource = OMXCodec::Create(GetOMX(),
+      audioSource = OMXCodec::Create(omx,
                                      audioTrack->getFormat(),
                                      false, // decoder
                                      audioTrack);
     }
     if (audioSource == nullptr) {
       NS_WARNING("Couldn't create OMX audio source");
       return false;
     }
--- a/content/media/omx/OmxDecoder.h
+++ b/content/media/omx/OmxDecoder.h
@@ -1,12 +1,10 @@
-#include <OMX.h>
+#include <stagefright/DataSource.h>
 #include <stagefright/MediaSource.h>
-#include <stagefright/DataSource.h>
-
 #include <utils/RefBase.h>
 
 #include "GonkNativeWindow.h"
 #include "GonkIOSurfaceImage.h"
 #include "MPAPI.h"
 #include "MediaResource.h"
 #include "AbstractMediaDecoder.h"