Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Unified Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java

Issue 2488643002: Add screenshare support to AppRTCMobile. (Closed)
Patch Set: Add screenshare support to AppRTCMobile. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
index 48a771632ab7132b6d7c19ba7d154a5ae898bcff..ce4c942505d41324fed687c5ffdaa3d9089df6a4 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
@@ -10,16 +10,15 @@
package org.appspot.apprtc;
-import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters;
-import org.appspot.apprtc.AppRTCClient.SignalingParameters;
-import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.media.projection.MediaProjection;
+import android.media.projection.MediaProjectionManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -28,26 +27,28 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Toast;
-
import java.io.IOException;
import java.lang.RuntimeException;
import java.util.ArrayList;
import java.util.List;
-
+import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters;
+import org.appspot.apprtc.AppRTCClient.SignalingParameters;
+import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters;
import org.webrtc.Camera1Enumerator;
import org.webrtc.Camera2Enumerator;
import org.webrtc.CameraEnumerator;
import org.webrtc.EglBase;
import org.webrtc.FileVideoCapturer;
-import org.webrtc.VideoFileRenderer;
import org.webrtc.IceCandidate;
import org.webrtc.Logging;
import org.webrtc.PeerConnectionFactory;
import org.webrtc.RendererCommon.ScalingType;
+import org.webrtc.ScreenCapturerAndroid;
import org.webrtc.SessionDescription;
import org.webrtc.StatsReport;
import org.webrtc.SurfaceViewRenderer;
import org.webrtc.VideoCapturer;
+import org.webrtc.VideoFileRenderer;
import org.webrtc.VideoRenderer;
/**
@@ -60,6 +61,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
public static final String EXTRA_ROOMID = "org.appspot.apprtc.ROOMID";
public static final String EXTRA_LOOPBACK = "org.appspot.apprtc.LOOPBACK";
public static final String EXTRA_VIDEO_CALL = "org.appspot.apprtc.VIDEO_CALL";
+ public static final String EXTRA_SCREENCAPTURE = "org.appspot.apprtc.SCREENCAPTURE";
public static final String EXTRA_CAMERA2 = "org.appspot.apprtc.CAMERA2";
public static final String EXTRA_VIDEO_WIDTH = "org.appspot.apprtc.VIDEO_WIDTH";
public static final String EXTRA_VIDEO_HEIGHT = "org.appspot.apprtc.VIDEO_HEIGHT";
@@ -94,6 +96,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
public static final String EXTRA_USE_VALUES_FROM_INTENT =
"org.appspot.apprtc.USE_VALUES_FROM_INTENT";
private static final String TAG = "CallRTCClient";
+ private static final int CAPTURE_PERMISSION_REQUEST_CODE = 1;
// List of mandatory application permissions.
private static final String[] MANDATORY_PERMISSIONS = {"android.permission.MODIFY_AUDIO_SETTINGS",
@@ -140,6 +143,9 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
private boolean callControlFragmentVisible = true;
private long callStartedTimeMs = 0;
private boolean micEnabled = true;
+ private boolean screencaptureEnabled = false;
+ private static Intent mediaProjectionPermissionResultData;
+ private static int mediaProjectionPermissionResultCode;
// Controls
private CallFragment callFragment;
@@ -285,7 +291,6 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
ft.add(R.id.call_fragment_container, callFragment);
ft.add(R.id.hud_fragment_container, hudFragment);
ft.commit();
- startCall();
// For command line execution run connection for <runTimeMs> and exit.
if (commandLineRun && runTimeMs > 0) {
@@ -305,6 +310,26 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
}
peerConnectionClient.createPeerConnectionFactory(
CallActivity.this, peerConnectionParameters, CallActivity.this);
+
+ screencaptureEnabled = intent.getBooleanExtra(EXTRA_SCREENCAPTURE, false);
+ if (screencaptureEnabled) {
+ MediaProjectionManager mediaProjectionManager =
+ (MediaProjectionManager) getApplication().getSystemService(
+ Context.MEDIA_PROJECTION_SERVICE);
+ startActivityForResult(
+ mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
+ } else {
+ startCall();
+ }
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode != CAPTURE_PERMISSION_REQUEST_CODE)
+ return;
+ mediaProjectionPermissionResultCode = resultCode;
+ mediaProjectionPermissionResultData = data;
+ startCall();
}
private boolean useCamera2() {
@@ -352,7 +377,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
public void onPause() {
super.onPause();
activityRunning = false;
- if (peerConnectionClient != null) {
+ if (peerConnectionClient != null && !screencaptureEnabled) {
magjed_webrtc 2016/11/09 09:07:53 Comment why we do this, e.g. to allow the user to
sakal 2016/11/09 14:56:00 Done.
peerConnectionClient.stopVideoSource();
}
cpuMonitor.pause();
@@ -362,7 +387,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
public void onResume() {
super.onResume();
activityRunning = true;
- if (peerConnectionClient != null) {
+ if (peerConnectionClient != null && !screencaptureEnabled) {
peerConnectionClient.startVideoSource();
}
cpuMonitor.resume();
@@ -588,6 +613,18 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
reportError("Failed to open video file for emulated camera");
return null;
}
+ } else if (screencaptureEnabled) {
+ if (mediaProjectionPermissionResultCode != Activity.RESULT_OK) {
+ reportError("User didn't give permission to capture the screen.");
+ return null;
+ }
+ return new ScreenCapturerAndroid(
+ mediaProjectionPermissionResultData, new MediaProjection.Callback() {
+ @Override
+ public void onStop() {
+ reportError("User revoked permission to capture the screen.");
+ }
+ });
} else if (useCamera2()) {
if (!captureToTexture()) {
reportError(getString(R.string.camera2_texture_only_error));

Powered by Google App Engine
This is Rietveld 408576698