bug 1364341 - part 1: release all resources used by existing codec when re-configure. r?jya
MozReview-Commit-ID: JLZ0vSBTg6X
--- 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;
}
}