Add exception handling when configuring MediaCodc in order to prevent break in the new sdk release.

BUG=2603
R=fischman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/3909004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5158 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
dwkang@webrtc.org 2013-11-22 02:49:17 +00:00
parent 9fe3603dc1
commit 9e85c01ec8
2 changed files with 30 additions and 13 deletions

View File

@ -58,7 +58,7 @@ int32_t AndroidMediaCodecDecoder::InitDecode(
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG,
"Could not attach thread to JVM (%d, %p)", ret,
env_);
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
return WEBRTC_VIDEO_CODEC_ERROR;
} else {
vm_attached_ = true;
}
@ -68,9 +68,13 @@ int32_t AndroidMediaCodecDecoder::InitDecode(
mediaCodecDecoder_ = env_->NewGlobalRef(env_->NewObject(decoderClass_, mid));
mid = env_->GetMethodID(
decoderClass_, "configure", "(Landroid/view/SurfaceView;II)V");
env_->CallVoidMethod(mediaCodecDecoder_, mid, surface_,
codecSettings->width, codecSettings->height);
decoderClass_, "configure", "(Landroid/view/SurfaceView;II)Z");
bool success = env_->CallBooleanMethod(
mediaCodecDecoder_, mid, surface_, codecSettings->width,
codecSettings->height);
if (!success) {
return WEBRTC_VIDEO_CODEC_ERROR;
}
setEncodedImageID_ = env_->GetMethodID(
decoderClass_, "setEncodedImage", "(Ljava/nio/ByteBuffer;J)V");

View File

@ -20,6 +20,7 @@ import android.util.Log;
import android.view.Surface;
import android.view.SurfaceView;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.LinkedList;
@ -245,7 +246,7 @@ class ViEMediaCodecDecoder {
private Thread mLooperThread;
public void configure(SurfaceView surfaceView, int width, int height) {
public boolean configure(SurfaceView surfaceView, int width, int height) {
mSurfaceView = surfaceView;
Log.d(TAG, "configure " + "width" + width + "height" + height + mSurfaceView.toString());
@ -253,18 +254,30 @@ class ViEMediaCodecDecoder {
format.setString(MediaFormat.KEY_MIME, "video/x-vnd.on2.vp8");
format.setInteger(MediaFormat.KEY_WIDTH, width);
format.setInteger(MediaFormat.KEY_HEIGHT, height);
MediaCodec codec = MediaCodec.createDecoderByType("video/x-vnd.on2.vp8");
// SW VP8 decoder
// MediaCodec codec = MediaCodec.createByCodecName("OMX.google.vpx.decoder");
// Nexus10 HW VP8 decoder
// MediaCodec codec = MediaCodec.createByCodecName("OMX.Exynos.VP8.Decoder");
Surface surface = mSurfaceView.getHolder().getSurface();
Log.d(TAG, "Surface " + surface.isValid());
codec.configure(
format, surface, null, 0);
mCodecState = new CodecState(this, format, codec);
MediaCodec codec;
try {
codec = MediaCodec.createDecoderByType("video/x-vnd.on2.vp8");
// SW VP8 decoder
// codec = MediaCodec.createByCodecName("OMX.google.vpx.decoder");
// Nexus10 HW VP8 decoder
// codec = MediaCodec.createByCodecName("OMX.Exynos.VP8.Decoder");
} catch (Exception e) {
// TODO(dwkang): replace this instanceof/throw with a narrower catch clause
// once the SDK advances.
if (e instanceof IOException) {
Log.e(TAG, "Failed to create MediaCodec for VP8.", e);
return false;
}
throw new RuntimeException(e);
}
codec.configure(format, surface, null, 0);
mCodecState = new CodecState(this, format, codec);
initMediaCodecView();
return true;
}
public void setEncodedImage(ByteBuffer buffer, long renderTimeMs) {