Switch HW video decoder to output byte buffers if video
renderer EGL context is not provided by app.

R=tkchin@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7281 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc
index 38f1e90..27f69e4 100644
--- a/talk/app/webrtc/java/jni/peerconnection_jni.cc
+++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc
@@ -1210,9 +1210,6 @@
 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
 
-// Set to false to switch HW video decoder back to byte buffer output.
-#define HW_DECODER_USE_SURFACE true
-
 // Color formats supported by encoder - should mirror supportedColorList
 // from MediaCodecVideoEncoder.java
 enum COLOR_FORMATTYPE {
@@ -2054,15 +2051,18 @@
   if (render_egl_context_) {
     jni->DeleteGlobalRef(render_egl_context_);
   }
-  render_egl_context_ = jni->NewGlobalRef(render_egl_context);
-  ALOGD("VideoDecoder EGL context set");
+  if (IsNull(jni, render_egl_context)) {
+    render_egl_context_ = NULL;
+  } else {
+    render_egl_context_ = jni->NewGlobalRef(render_egl_context);
+  }
+  ALOGD("VideoDecoder EGL context set.");
   return 0;
 }
 
 MediaCodecVideoDecoder::MediaCodecVideoDecoder(JNIEnv* jni)
   : key_frame_required_(true),
     inited_(false),
-    use_surface_(HW_DECODER_USE_SURFACE),
     codec_thread_(new Thread()),
     j_media_codec_video_decoder_class_(
         jni,
@@ -2127,6 +2127,9 @@
       jni, j_decoder_output_buffer_info_class, "presentationTimestampUs", "J");
 
   CHECK_EXCEPTION(jni) << "MediaCodecVideoDecoder ctor failed";
+  use_surface_ = true;
+  if (render_egl_context_ == NULL)
+    use_surface_ = false;
   memset(&codec_, 0, sizeof(codec_));
 }