Add option to capture to texture in AppRTCDemo for Android.

The purpose is to be able to easier test and find differences between the path when capturing to textures or byte buffers.

This require https://codereview.webrtc.org/1403713002/ to work.

BUG=webrtc:4993
R=magjed@webrtc.org
TBR=glaznew@webrtc.org

Review URL: https://codereview.webrtc.org/1452423003 .

Cr-Commit-Position: refs/heads/master@{#10766}
diff --git a/webrtc/examples/androidapp/res/values/strings.xml b/webrtc/examples/androidapp/res/values/strings.xml
index 951f65a..573ff80 100644
--- a/webrtc/examples/androidapp/res/values/strings.xml
+++ b/webrtc/examples/androidapp/res/values/strings.xml
@@ -71,6 +71,11 @@
     <string name="pref_hwcodec_dlg">Use hardware accelerated video codec (if available).</string>
     <string name="pref_hwcodec_default">true</string>
 
+    <string name="pref_capturetotexture_key">capturetotexture_preference</string>
+    <string name="pref_capturetotexture_title">Video capture to surface texture.</string>
+    <string name="pref_capturetotexture_dlg">Capture video to textures (if available).</string>
+    <string name="pref_capturetotexture_default">false</string>
+
     <string name="pref_value_enabled">Enabled</string>
     <string name="pref_value_disabled">Disabled</string>
 
diff --git a/webrtc/examples/androidapp/res/xml/preferences.xml b/webrtc/examples/androidapp/res/xml/preferences.xml
index 8c111e0..b54f244 100644
--- a/webrtc/examples/androidapp/res/xml/preferences.xml
+++ b/webrtc/examples/androidapp/res/xml/preferences.xml
@@ -60,6 +60,12 @@
             android:title="@string/pref_hwcodec_title"
             android:dialogTitle="@string/pref_hwcodec_dlg"
             android:defaultValue="@string/pref_hwcodec_default" />
+
+        <CheckBoxPreference
+            android:key="@string/pref_capturetotexture_key"
+            android:title="@string/pref_capturetotexture_title"
+            android:dialogTitle="@string/pref_capturetotexture_dlg"
+            android:defaultValue="@string/pref_capturetotexture_default" />
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
index 06c491a..7a4d09e 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
@@ -66,6 +66,8 @@
       "org.appspot.apprtc.VIDEOCODEC";
   public static final String EXTRA_HWCODEC_ENABLED =
       "org.appspot.apprtc.HWCODEC";
+  public static final String EXTRA_CAPTURETOTEXTURE_ENABLED =
+      "org.appspot.apprtc.CAPTURETOTEXTURE";
   public static final String EXTRA_AUDIO_BITRATE =
       "org.appspot.apprtc.AUDIO_BITRATE";
   public static final String EXTRA_AUDIOCODEC =
@@ -220,6 +222,7 @@
         intent.getIntExtra(EXTRA_VIDEO_BITRATE, 0),
         intent.getStringExtra(EXTRA_VIDEOCODEC),
         intent.getBooleanExtra(EXTRA_HWCODEC_ENABLED, true),
+        intent.getBooleanExtra(EXTRA_CAPTURETOTEXTURE_ENABLED, false),
         intent.getIntExtra(EXTRA_AUDIO_BITRATE, 0),
         intent.getStringExtra(EXTRA_AUDIOCODEC),
         intent.getBooleanExtra(EXTRA_NOAUDIOPROCESSING_ENABLED, false),
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java
index 9bc0b45..2d1d5aa 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java
@@ -65,6 +65,7 @@
   private String keyprefAudioBitrateValue;
   private String keyprefAudioCodec;
   private String keyprefHwCodecAcceleration;
+  private String keyprefCaptureToTexture;
   private String keyprefNoAudioProcessingPipeline;
   private String keyprefOpenSLES;
   private String keyprefDisplayHud;
@@ -89,6 +90,7 @@
     keyprefVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key);
     keyprefVideoCodec = getString(R.string.pref_videocodec_key);
     keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
+    keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key);
     keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
     keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
     keyprefAudioCodec = getString(R.string.pref_audiocodec_key);
@@ -253,6 +255,10 @@
     boolean hwCodec = sharedPref.getBoolean(keyprefHwCodecAcceleration,
         Boolean.valueOf(getString(R.string.pref_hwcodec_default)));
 
+    // Check Capture to texture.
+    boolean captureToTexture = sharedPref.getBoolean(keyprefCaptureToTexture,
+        Boolean.valueOf(getString(R.string.pref_capturetotexture_default)));
+
     // Check Disable Audio Processing flag.
     boolean noAudioProcessing = sharedPref.getBoolean(
         keyprefNoAudioProcessingPipeline,
@@ -339,6 +345,7 @@
       intent.putExtra(CallActivity.EXTRA_VIDEO_BITRATE, videoStartBitrate);
       intent.putExtra(CallActivity.EXTRA_VIDEOCODEC, videoCodec);
       intent.putExtra(CallActivity.EXTRA_HWCODEC_ENABLED, hwCodec);
+      intent.putExtra(CallActivity.EXTRA_CAPTURETOTEXTURE_ENABLED, captureToTexture);
       intent.putExtra(CallActivity.EXTRA_NOAUDIOPROCESSING_ENABLED,
           noAudioProcessing);
       intent.putExtra(CallActivity.EXTRA_OPENSLES_ENABLED, useOpenSLES);
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
index 7c292ae..77e78c4 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
@@ -133,6 +133,7 @@
     public final int videoStartBitrate;
     public final String videoCodec;
     public final boolean videoCodecHwAcceleration;
+    public final boolean captureToTexture;
     public final int audioStartBitrate;
     public final String audioCodec;
     public final boolean noAudioProcessing;
@@ -141,7 +142,7 @@
     public PeerConnectionParameters(
         boolean videoCallEnabled, boolean loopback,
         int videoWidth, int videoHeight, int videoFps, int videoStartBitrate,
-        String videoCodec, boolean videoCodecHwAcceleration,
+        String videoCodec, boolean videoCodecHwAcceleration, boolean captureToTexture,
         int audioStartBitrate, String audioCodec,
         boolean noAudioProcessing, boolean useOpenSLES) {
       this.videoCallEnabled = videoCallEnabled;
@@ -152,6 +153,7 @@
       this.videoStartBitrate = videoStartBitrate;
       this.videoCodec = videoCodec;
       this.videoCodecHwAcceleration = videoCodecHwAcceleration;
+      this.captureToTexture = captureToTexture;
       this.audioStartBitrate = audioStartBitrate;
       this.audioCodec = audioCodec;
       this.noAudioProcessing = noAudioProcessing;
@@ -429,7 +431,7 @@
 
     if (videoCallEnabled) {
       Log.d(TAG, "EGLContext: " + renderEGLContext);
-      factory.setVideoHwAccelerationOptions(renderEGLContext);
+      factory.setVideoHwAccelerationOptions(renderEGLContext, renderEGLContext);
     }
 
     PeerConnection.RTCConfiguration rtcConfig =
@@ -462,7 +464,8 @@
         cameraDeviceName = frontCameraDeviceName;
       }
       Log.d(TAG, "Opening camera: " + cameraDeviceName);
-      videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null);
+      videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null,
+            peerConnectionParameters.captureToTexture ?  renderEGLContext : null);
       if (videoCapturer == null) {
         reportError("Failed to open camera");
         return;
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/SettingsActivity.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/SettingsActivity.java
index f3cc770..1a636ca 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/SettingsActivity.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/SettingsActivity.java
@@ -30,6 +30,7 @@
   private String keyprefStartVideoBitrateValue;
   private String keyPrefVideoCodec;
   private String keyprefHwCodec;
+  private String keyprefCaptureToTexture;
 
   private String keyprefStartAudioBitrateType;
   private String keyprefStartAudioBitrateValue;
@@ -51,6 +52,7 @@
     keyprefStartVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key);
     keyPrefVideoCodec = getString(R.string.pref_videocodec_key);
     keyprefHwCodec = getString(R.string.pref_hwcodec_key);
+    keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key);
 
     keyprefStartAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
     keyprefStartAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
@@ -84,6 +86,7 @@
     setVideoBitrateEnable(sharedPreferences);
     updateSummary(sharedPreferences, keyPrefVideoCodec);
     updateSummaryB(sharedPreferences, keyprefHwCodec);
+    updateSummaryB(sharedPreferences, keyprefCaptureToTexture);
 
     updateSummary(sharedPreferences, keyprefStartAudioBitrateType);
     updateSummaryBitrate(sharedPreferences, keyprefStartAudioBitrateValue);
@@ -121,6 +124,7 @@
     } else if (key.equals(keyprefVideoCall)
         || key.equals(keyprefCaptureQualitySlider)
         || key.equals(keyprefHwCodec)
+        || key.equals(keyprefCaptureToTexture)
         || key.equals(keyprefNoAudioProcessing)
         || key.equals(keyprefOpenSLES)
         || key.equals(keyPrefDisplayHud)) {
diff --git a/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java
index 58ed28a..afcab3c 100644
--- a/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java
+++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java
@@ -250,7 +250,7 @@
     PeerConnectionParameters peerConnectionParameters =
         new PeerConnectionParameters(
             enableVideo, true, // videoCallEnabled, loopback.
-            0, 0, 0, 0, videoCodec, true, // video codec parameters.
+            0, 0, 0, 0, videoCodec, true, false, // video codec parameters.
             0, "OPUS", false, false); // audio codec parameters.
     return peerConnectionParameters;
   }