MediaCodec: change onError cb to send CodecException

Bug: 11990118
Change-Id: I8b6112f126c2f473f64e2aad6ffcfbc3f1d6e64a
This commit is contained in:
Chong Zhang
2014-07-11 15:53:58 -07:00
parent d336042f7a
commit 94686d13ca
3 changed files with 18 additions and 13 deletions

View File

@@ -14336,7 +14336,7 @@ package android.media {
public static abstract class MediaCodec.Callback {
ctor public MediaCodec.Callback();
method public abstract void onError(android.media.MediaCodec, int, int);
method public abstract void onError(android.media.MediaCodec, android.media.MediaCodec.CodecException);
method public abstract void onInputBufferAvailable(android.media.MediaCodec, int);
method public abstract void onOutputBufferAvailable(android.media.MediaCodec, int, android.media.MediaCodec.BufferInfo);
method public abstract void onOutputFormatChanged(android.media.MediaCodec, android.media.MediaFormat);

View File

@@ -332,8 +332,7 @@ final public class MediaCodec {
case CB_ERROR:
{
mCallback.onError(mCodec,
msg.arg2 /* error */, (Integer) msg.obj /* actionCode */);
mCallback.onError(mCodec, (MediaCodec.CodecException) msg.obj);
break;
}
@@ -1454,10 +1453,9 @@ final public class MediaCodec {
* Called when the MediaCodec encountered an error
*
* @param codec The MediaCodec object.
* @param error a device specific error code.
* @param actionCode a value for use in {@link MediaCodec.CodecException}.
* @param e The {@link MediaCodec.CodecException} object describing the error.
*/
public abstract void onError(MediaCodec codec, int error, int actionCode);
public abstract void onError(MediaCodec codec, CodecException e);
/**
* Called when the output format has changed

View File

@@ -566,20 +566,27 @@ void JMediaCodec::handleCallback(const sp<AMessage> &msg) {
case MediaCodec::CB_ERROR:
{
CHECK(msg->findInt32("err", &arg2));
int32_t actionCode;
int32_t err, actionCode;
CHECK(msg->findInt32("err", &err));
CHECK(msg->findInt32("actionCode", &actionCode));
// use Integer object to pass the action code
ScopedLocalRef<jclass> clazz(
env, env->FindClass("java/lang/Integer"));
jmethodID ctor = env->GetMethodID(clazz.get(), "<init>", "(I)V");
obj = env->NewObject(clazz.get(), ctor, actionCode);
env, env->FindClass("android/media/MediaCodec$CodecException"));
jmethodID ctor = env->GetMethodID(clazz.get(), "<init>", "(IILjava/lang/String;)V");
AString str;
const char *detail = "Unknown error";
if (msg->findString("detail", &str)) {
detail = str.c_str();
}
jstring msgObj = env->NewStringUTF(detail);
obj = env->NewObject(clazz.get(), ctor, err, actionCode, msgObj);
if (obj == NULL) {
if (env->ExceptionCheck()) {
ALOGE("Could not create Integer object for actionCode.");
ALOGE("Could not create CodecException object.");
env->ExceptionClear();
}
jniThrowException(env, "java/lang/IllegalStateException", NULL);