Bug 1484648 - Implement CodecProxy::IsHardwareAccelerated. r=jolin
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 20 Aug 2018 15:42:33 +0000
changeset 487459 54da55f0f79661cca9cf51278b0ab520c0772796
parent 487458 89117b6b5799666c38926cd566f230e19b050528
child 487460 5a6ea725be3fd22b2036380d801f076efbbc2e8f
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjolin
bugs1484648
milestone63.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 1484648 - Implement CodecProxy::IsHardwareAccelerated. r=jolin Differential Revision: https://phabricator.services.mozilla.com/D3789
dom/media/platforms/android/RemoteDataDecoder.cpp
mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/Codec.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/CodecProxy.java
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -203,16 +203,18 @@ public:
                                       mJavaCallbacks,
                                       mDrmStubId);
     if (mJavaDecoder == nullptr) {
       return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                                           __func__);
     }
     mIsCodecSupportAdaptivePlayback =
       mJavaDecoder->IsAdaptivePlaybackSupported();
+    mIsHardwareAccelerated =
+      mJavaDecoder->IsHardwareAccelerated();
     return InitPromise::CreateAndResolve(TrackInfo::kVideoTrack, __func__);
   }
 
   RefPtr<MediaDataDecoder::FlushPromise> Flush() override
   {
     RefPtr<RemoteVideoDecoder> self = this;
     return RemoteDataDecoder::Flush()->Then(
       mTaskQueue,
@@ -267,22 +269,29 @@ public:
       return false;
     }
 
     mSeekTarget.reset();
     mLatestOutputTime = Some(endTime);
     return true;
   }
 
+  bool IsHardwareAccelerated(nsACString& aFailureReason) const override
+  {
+    return mIsHardwareAccelerated;
+  }
+
 private:
   const VideoInfo mConfig;
   GeckoSurface::GlobalRef mSurface;
   AndroidSurfaceTextureHandle mSurfaceHandle;
   // Only accessed on reader's task queue.
   bool mIsCodecSupportAdaptivePlayback = false;
+  // Can be accessed on any thread, but only written on during init.
+  bool mIsHardwareAccelerated = false;
   // Accessed on mTaskQueue, reader's TaskQueue and Java callback tread.
   // SimpleMap however is thread-safe, so it's okay to do so.
   SimpleMap<InputInfo> mInputInfos;
   // Only accessed on the TaskQueue.
   Maybe<TimeUnit> mSeekTarget;
   Maybe<TimeUnit> mLatestOutputTime;
 };
 
--- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl
+++ b/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl
@@ -10,16 +10,17 @@ import org.mozilla.gecko.gfx.GeckoSurfac
 import org.mozilla.gecko.media.FormatParam;
 import org.mozilla.gecko.media.ICodecCallbacks;
 import org.mozilla.gecko.media.Sample;
 
 interface ICodec {
     void setCallbacks(in ICodecCallbacks callbacks);
     boolean configure(in FormatParam format, in GeckoSurface surface, in int flags, in String drmStubId);
     boolean isAdaptivePlaybackSupported();
+    boolean isHardwareAccelerated();
     boolean isTunneledPlaybackSupported();
     void start();
     void stop();
     void flush();
     void release();
 
     Sample dequeueInput(int size);
     oneway void queueInput(in Sample sample);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/Codec.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/Codec.java
@@ -345,16 +345,17 @@ import org.mozilla.gecko.gfx.GeckoSurfac
 
     private volatile ICodecCallbacks mCallbacks;
     private AsyncCodec mCodec;
     private InputProcessor mInputProcessor;
     private OutputProcessor mOutputProcessor;
     private SamplePool mSamplePool;
     // Values will be updated after configure called.
     private volatile boolean mIsAdaptivePlaybackSupported = false;
+    private volatile boolean mIsHardwareAccelerated = false;
     private boolean mIsTunneledPlaybackSupported = false;
 
     public synchronized void setCallbacks(ICodecCallbacks callbacks) throws RemoteException {
         mCallbacks = callbacks;
         callbacks.asBinder().linkToDeath(this, 0);
     }
 
     // IBinder.DeathRecipient
@@ -394,16 +395,17 @@ import org.mozilla.gecko.gfx.GeckoSurfac
 
         final List<String> found = findMatchingCodecNames(mime, flags == MediaCodec.CONFIGURE_FLAG_ENCODE);
         for (final String name : found) {
             final AsyncCodec codec = configureCodec(name, fmt, surface, flags, drmStubId);
             if (codec == null) {
                 Log.w(LOGTAG, "unable to configure " + name + ". Try next.");
                 continue;
             }
+            mIsHardwareAccelerated = !name.startsWith("OMX.google.");
             mCodec = codec;
             mInputProcessor = new InputProcessor();
             final boolean renderToSurface = surface != null;
             mOutputProcessor = new OutputProcessor(renderToSurface);
             mSamplePool = new SamplePool(name, renderToSurface);
             if (renderToSurface) {
                 mIsTunneledPlaybackSupported = mCodec.isTunneledPlaybackSupported(mime);
             }
@@ -473,16 +475,21 @@ import org.mozilla.gecko.gfx.GeckoSurfac
     }
 
     @Override
     public synchronized boolean isAdaptivePlaybackSupported() {
         return mIsAdaptivePlaybackSupported;
     }
 
     @Override
+    public synchronized boolean isHardwareAccelerated() {
+        return mIsHardwareAccelerated;
+    }
+
+    @Override
     public synchronized boolean isTunneledPlaybackSupported() {
         return mIsTunneledPlaybackSupported;
     }
 
     @Override
     public synchronized void start() throws RemoteException {
         if (DEBUG) { Log.d(LOGTAG, "start " + this); }
         mInputProcessor.start();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/CodecProxy.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/CodecProxy.java
@@ -187,16 +187,31 @@ public final class CodecProxy {
             return mRemote.isAdaptivePlaybackSupported();
         } catch (RemoteException e) {
             e.printStackTrace();
             return false;
         }
     }
 
     @WrapForJNI
+    public synchronized boolean isHardwareAccelerated()
+    {
+      if (mRemote == null) {
+          Log.e(LOGTAG, "cannot check isHardwareAccelerated with an ended codec");
+          return false;
+      }
+      try {
+            return mRemote.isHardwareAccelerated();
+        } catch (RemoteException e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    @WrapForJNI
     public synchronized boolean isTunneledPlaybackSupported()
     {
       if (mRemote == null) {
           Log.e(LOGTAG, "cannot check isTunneledPlaybackSupported with an ended codec");
           return false;
       }
       try {
             return mRemote.isTunneledPlaybackSupported();