Avoid using EGLContext class for Android 4.1 and below.

Support for this class was added in Android 4.2, so
disable surface decoding for lower Android versions.

BUG=3901
R=tkchin@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7478 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java
index e0542ed..a393774 100644
--- a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java
+++ b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java
@@ -80,6 +80,11 @@
   //    aspect ratio is changed if necessary.
   public static enum ScalingType
       { SCALE_ASPECT_FIT, SCALE_ASPECT_FILL, SCALE_FILL };
+  private static final int EGL14_SDK_VERSION =
+      android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
+  // Current SDK version.
+  private static final int CURRENT_SDK_VERSION =
+      android.os.Build.VERSION.SDK_INT;
 
   private final String VERTEX_SHADER_STRING =
       "varying vec2 interp_tc;\n" +
@@ -666,8 +671,10 @@
   public void onSurfaceCreated(GL10 unused, EGLConfig config) {
     Log.d(TAG, "VideoRendererGui.onSurfaceCreated");
     // Store render EGL context
-    eglContext = EGL14.eglGetCurrentContext();
-    Log.d(TAG, "VideoRendererGui EGL Context: " + eglContext);
+    if (CURRENT_SDK_VERSION >= EGL14_SDK_VERSION) {
+      eglContext = EGL14.eglGetCurrentContext();
+      Log.d(TAG, "VideoRendererGui EGL Context: " + eglContext);
+    }
 
     // Create YUV and OES programs.
     yuvProgram = createProgram(VERTEX_SHADER_STRING,
diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc
index d2b1639..d82a54f 100644
--- a/talk/app/webrtc/java/jni/peerconnection_jni.cc
+++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc
@@ -273,11 +273,19 @@
     LoadClass(jni, "org/webrtc/IceCandidate");
 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
     LoadClass(jni, "android/graphics/SurfaceTexture");
-    LoadClass(jni, "android/opengl/EGLContext");
     LoadClass(jni, "org/webrtc/MediaCodecVideoEncoder");
     LoadClass(jni, "org/webrtc/MediaCodecVideoEncoder$OutputBufferInfo");
     LoadClass(jni, "org/webrtc/MediaCodecVideoDecoder");
     LoadClass(jni, "org/webrtc/MediaCodecVideoDecoder$DecoderOutputBufferInfo");
+    jclass j_decoder_class = GetClass("org/webrtc/MediaCodecVideoDecoder");
+    jmethodID j_is_egl14_supported_method = jni->GetStaticMethodID(
+        j_decoder_class, "isEGL14Supported", "()Z");
+    bool is_egl14_supported = jni->CallStaticBooleanMethod(
+        j_decoder_class, j_is_egl14_supported_method);
+    CHECK_EXCEPTION(jni);
+    if (is_egl14_supported) {
+      LoadClass(jni, "android/opengl/EGLContext");
+    }
 #endif
     LoadClass(jni, "org/webrtc/MediaSource$State");
     LoadClass(jni, "org/webrtc/MediaStream");
diff --git a/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoDecoder.java b/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoDecoder.java
index 96d8b1b..f93f02a 100644
--- a/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoDecoder.java
+++ b/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoDecoder.java
@@ -95,6 +95,10 @@
   private EGLDisplay eglDisplay = EGL14.EGL_NO_DISPLAY;
   private EGLContext eglContext = EGL14.EGL_NO_CONTEXT;
   private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
+  private static final int EGL14_SDK_VERSION =
+      android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
+  private static final int CURRENT_SDK_VERSION =
+      android.os.Build.VERSION.SDK_INT;
 
 
   private MediaCodecVideoDecoder() { }
@@ -166,6 +170,11 @@
     return null;  // No HW VP8 decoder.
   }
 
+  private static boolean isEGL14Supported() {
+    Log.d(TAG, "SDK version: " + CURRENT_SDK_VERSION);
+    return (CURRENT_SDK_VERSION >= EGL14_SDK_VERSION);
+  }
+
   private static boolean isPlatformSupported() {
     return findVp8Decoder(false) != null;
   }