bug 1364341 - part 1: release all resources used by existing codec when re-configure. r=jya
authorJohn Lin <jolin@mozilla.com>
Mon, 15 May 2017 16:43:49 +0800
changeset 360051 1ffcbd8d55f650f7856290eed7ce111a04076a9c
parent 360050 3b05e00b1a14365d9067458d988cc4679c7ba5e0
child 360052 bc722bc488b50ed85df9e013a535687a2bc1efe0
push id43192
push userjolin@mozilla.com
push dateTue, 23 May 2017 02:29:55 +0000
treeherderautoland@bc722bc488b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1364341
milestone55.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 1364341 - part 1: release all resources used by existing codec when re-configure. r=jya MozReview-Commit-ID: JLZ0vSBTg6X
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/Codec.java
--- 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
@@ -355,17 +355,17 @@ import org.mozilla.gecko.gfx.GeckoSurfac
                                           String drmStubId) throws RemoteException {
         if (mCallbacks == null) {
             Log.e(LOGTAG, "FAIL: callbacks must be set before calling configure()");
             return false;
         }
 
         if (mCodec != null) {
             if (DEBUG) { Log.d(LOGTAG, "release existing codec: " + mCodec); }
-            releaseCodec();
+            mCodec.release();
         }
 
         if (DEBUG) { Log.d(LOGTAG, "configure " + this); }
 
         try {
             MediaFormat fmt = format.asFormat();
             AsyncCodec codec = createCodecForFormat(fmt, flags == MediaCodec.CONFIGURE_FLAG_ENCODE ? true : false);
             MediaCrypto crypto = RemoteMediaDrmBridgeStub.getMediaCrypto(drmStubId);
@@ -402,29 +402,16 @@ import org.mozilla.gecko.gfx.GeckoSurfac
         }
     }
 
     @Override
     public synchronized boolean isAdaptivePlaybackSupported() {
         return mIsAdaptivePlaybackSupported;
     }
 
-    private void releaseCodec() {
-        try {
-            // In case Codec.stop() is not called yet.
-            mInputProcessor.stop();
-            mOutputProcessor.stop();
-
-            mCodec.release();
-        } catch (Exception e) {
-            reportError(Error.FATAL, e);
-        }
-        mCodec = null;
-    }
-
     private AsyncCodec createCodecForFormat(MediaFormat format, boolean isEncoder) throws IOException {
         String mime = format.getString(MediaFormat.KEY_MIME);
         if (mime == null || mime.isEmpty()) {
             throw new IllegalArgumentException("invalid MIME type: " + mime);
         }
 
         int numCodecs = MediaCodecList.getCodecCount();
         for (int i = 0; i < numCodecs; i++) {
@@ -538,15 +525,23 @@ import org.mozilla.gecko.gfx.GeckoSurfac
         } catch (Exception e) {
             reportError(Error.FATAL, e);
         }
     }
 
     @Override
     public synchronized void release() throws RemoteException {
         if (DEBUG) { Log.d(LOGTAG, "release " + this); }
-        releaseCodec();
+        try {
+            // In case Codec.stop() is not called yet.
+            mInputProcessor.stop();
+            mOutputProcessor.stop();
+            mCodec.release();
+        } catch (Exception e) {
+            reportError(Error.FATAL, e);
+        }
+        mCodec = null;
         mSamplePool.reset();
         mSamplePool = null;
         mCallbacks.asBinder().unlinkToDeath(this, 0);
         mCallbacks = null;
     }
 }