Chromium Code Reviews| Index: media/base/android/java/src/org/chromium/media/MediaServerCrashListener.java |
| diff --git a/media/base/android/java/src/org/chromium/media/MediaServerCrashListener.java b/media/base/android/java/src/org/chromium/media/MediaServerCrashListener.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3537ea12a619f12b8839d349e32bb79070519885 |
| --- /dev/null |
| +++ b/media/base/android/java/src/org/chromium/media/MediaServerCrashListener.java |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.media; |
| + |
| +import android.content.Context; |
| +import android.media.MediaPlayer; |
| + |
| +import org.chromium.base.Log; |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.content.R; |
| + |
| +/** |
| + * Class for listening to Android MediaServer Crashes to throttle media decoding |
| + * when needed. |
| + */ |
| +@JNINamespace("media") |
|
DaleCurtis
2016/11/08 22:35:41
Need any @MainDex tagging?
tguilbert
2016/11/11 03:50:28
Probably, since it might be used in the GPU proces
|
| +public class MediaServerCrashListener implements MediaPlayer.OnErrorListener { |
| + private static final String TAG = "cr_MediaCrashListen"; |
|
DaleCurtis
2016/11/08 22:35:40
Listener?
tguilbert
2016/11/11 03:50:29
Oops, fixed. Had to drop the '_' to have it fit in
|
| + |
| + // Watch dog player. Used to listen to all media server crashes. |
| + private MediaPlayer mPlayer; |
| + // Application context. |
| + private final Context mContext; |
| + |
| + private long mNativeMediaServerCrashListener; |
| + |
| + @CalledByNative |
| + private static MediaServerCrashListener create( |
| + Context context, long nativeMediaServerCrashListener) { |
| + return new MediaServerCrashListener(context, nativeMediaServerCrashListener); |
| + } |
| + |
| + private MediaServerCrashListener(Context context, long nativeMediaServerCrashListener) { |
| + mContext = context; |
| + mNativeMediaServerCrashListener = nativeMediaServerCrashListener; |
| + } |
| + |
| + @CalledByNative |
| + public boolean startListening() { |
| + if (mPlayer != null) return true; |
|
DaleCurtis
2016/11/08 22:35:40
Does if (mPlayer) work?
tguilbert
2016/11/11 03:50:29
No : error message is "MediaPlayer cannot be conve
|
| + |
| + try { |
| + mPlayer = MediaPlayer.create(mContext, R.raw.empty); |
| + } catch (IllegalStateException e) { |
|
DaleCurtis
2016/11/08 22:35:40
(IllegalStateException | RuntimeException e)
tguilbert
2016/11/11 03:50:29
I get this error message:
error: Alternatives in a
|
| + Log.e(TAG, "Exception happens while creating the watch dog player.", e); |
| + } catch (RuntimeException e) { |
| + Log.e(TAG, "Exception happens while creating the watch dog player.", e); |
| + } |
| + |
| + if (mPlayer == null) { |
|
DaleCurtis
2016/11/08 22:35:40
If (!mPlayer) or flip so if (mPlayer) ? Also don't
tguilbert
2016/11/11 03:50:29
Done.
|
| + Log.e(TAG, "Unable to create watch dog player, treat it as server crash."); |
| + nativeOnMediaServerCrashDetected(mNativeMediaServerCrashListener); |
| + return false; |
| + } else { |
| + mPlayer.setOnErrorListener(MediaServerCrashListener.this); |
| + return true; |
| + } |
| + } |
| + |
| + @Override |
| + public boolean onError(MediaPlayer mp, int what, int extra) { |
| + if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) { |
| + nativeOnMediaServerCrashDetected(mNativeMediaServerCrashListener); |
| + } |
| + return true; |
| + } |
| + |
| + private native void nativeOnMediaServerCrashDetected(long nativeMediaServerCrashListener); |
| +} |