Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1530/share android screen #1562

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.nextcloud.talk.activities

import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import android.view.View
Expand Down Expand Up @@ -82,6 +83,7 @@ class MagicCallActivity : BaseActivity() {
RouterTransaction.with(CallController(intent.extras))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
.tag("callController")
)
}
}
Expand Down Expand Up @@ -116,6 +118,13 @@ class MagicCallActivity : BaseActivity() {
eventBus.post(ConfigurationChangeEvent())
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode != CallController.CAPTURE_PERMISSION_REQUEST_CODE) return
val callController : CallController = router!!.getControllerWithTag("callController") as CallController
callController.initScreenShare(resultCode, data);
}

companion object {
private val TAG = "MagicCallActivity"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.media.projection.MediaProjection;
import android.media.projection.MediaProjectionManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -48,6 +53,7 @@
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bluelinelabs.logansquare.LoganSquare;
import com.facebook.drawee.view.SimpleDraweeView;
Expand Down Expand Up @@ -120,6 +126,7 @@
import org.webrtc.PeerConnection;
import org.webrtc.PeerConnectionFactory;
import org.webrtc.RendererCommon;
import org.webrtc.ScreenCapturerAndroid;
import org.webrtc.SessionDescription;
import org.webrtc.SurfaceTextureHelper;
import org.webrtc.SurfaceViewRenderer;
Expand Down Expand Up @@ -175,6 +182,7 @@ public class CallController extends BaseController {
private static final String[] PERMISSIONS_MICROPHONE = {
Manifest.permission.RECORD_AUDIO
};
public static final int CAPTURE_PERMISSION_REQUEST_CODE = 1;

@BindView(R.id.callControlEnableSpeaker)
SimpleDraweeView callControlEnableSpeaker;
Expand All @@ -194,6 +202,8 @@ public class CallController extends BaseController {
SimpleDraweeView cameraControlButton;
@BindView(R.id.call_control_switch_camera)
SimpleDraweeView cameraSwitchButton;
@BindView(R.id.callControlShareScreen)
SimpleDraweeView callControlShareScreen;
@BindView(R.id.callStateTextView)
TextView callStateTextView;

Expand Down Expand Up @@ -429,7 +439,9 @@ private void basicInitialization() {
sdpConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));

if (!isVoiceOnlyCall) {
cameraInitialization();
checkPermissions();
// TODO change back to cameraInitialization (just changed this for androidScreensharing Proof of concept)
// cameraInitialization();
}

microphoneInitialization();
Expand Down Expand Up @@ -472,7 +484,6 @@ public void onComplete() {
});
}


@SuppressLint("ClickableViewAccessibility")
private void initViews() {
participantDisplayItems = new HashMap<>();
Expand Down Expand Up @@ -573,16 +584,22 @@ public void onGlobalLayout() {


private void checkPermissions() {
if (isVoiceOnlyCall) {
onMicrophoneClick();
} else if (getActivity() != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(PERMISSIONS_CALL, 100);
} else {
onRequestPermissionsResult(100, PERMISSIONS_CALL, new int[]{1, 1});
}
}

// TODO revert (just changed this for androidScreensharing Proof of concept)
// if (isVoiceOnlyCall) {
// onMicrophoneClick();
// } else if (getActivity() != null) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// requestPermissions(PERMISSIONS_CALL, 100);
// } else {
// onRequestPermissionsResult(100, PERMISSIONS_CALL, new int[]{1, 1});
// }
// }

MediaProjectionManager mediaProjectionManager =
(MediaProjectionManager) getApplicationContext().getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
getActivity().startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
}

private boolean isConnectionEstablished() {
Expand Down Expand Up @@ -704,6 +721,27 @@ private void cameraInitialization() {
localVideoTrack.addSink(pipVideoView);
}

public void initScreenShare(int resultCode, Intent intent){
videoCapturer = createScreenCapturer(resultCode, intent);

if (videoCapturer != null) {
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
videoSource = peerConnectionFactory.createVideoSource(true);
videoCapturer.initialize(surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver());
}

localVideoTrack = peerConnectionFactory.createVideoTrack("ARDAMSv0", videoSource);
localMediaStream.addTrack(localVideoTrack);
localVideoTrack.setEnabled(true);
localVideoTrack.addSink(pipVideoView);

videoCapturer.startCapture(1000, 1000, 10);

if (!isConnectionEstablished()) {
fetchSignalingSettings();
}
}

private void microphoneInitialization() {
//create an AudioSource instance
audioSource = peerConnectionFactory.createAudioSource(audioConstraints);
Expand Down Expand Up @@ -746,6 +784,20 @@ private VideoCapturer createCameraCapturer(CameraEnumerator enumerator) {
return null;
}

private VideoCapturer createScreenCapturer(int resultCode, Intent intent) {
if (resultCode != Activity.RESULT_OK) {
Log.d("","User didn't give permission to capture the screen.");
return null;
}
return new ScreenCapturerAndroid(intent, new MediaProjection.Callback() {
@Override
public void onStop() {
Log.d("","User revoked permission to capture the screen.");
}
});
}


@OnLongClick(R.id.call_control_microphone)
boolean onMicrophoneLongClick() {
if (!audioOn) {
Expand Down Expand Up @@ -883,6 +935,11 @@ public void onCameraClick() {

}

@OnClick(R.id.callControlShareScreen)
public void onCallControlShareScreenClick() {
Toast.makeText(getApplicationContext(), "not yet implemented", Toast.LENGTH_LONG).show();
}

@OnClick({R.id.call_control_switch_camera})
public void switchCamera() {
CameraVideoCapturer cameraVideoCapturer = (CameraVideoCapturer) videoCapturer;
Expand Down Expand Up @@ -1380,7 +1437,8 @@ private void setupAndInitiateWebSocketsConnection() {

private void initiateCall() {
if (!TextUtils.isEmpty(roomToken)) {
checkPermissions();
// TODO revert (just changed this for androidScreensharing Proof of concept)
// checkPermissions();
} else {
handleFromNotification();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M21.22,18.02l2,2L24,20.02v-2h-2.78zM21.99,16.02l0.01,-10c0,-1.11 -0.9,-2 -2,-2L7.22,4.02l5.23,5.23c0.18,-0.04 0.36,-0.07 0.55,-0.1L13,7.02l4,3.73 -1.58,1.47 5.54,5.54c0.61,-0.33 1.03,-0.99 1.03,-1.74zM2.39,1.73L1.11,3l1.54,1.54c-0.4,0.36 -0.65,0.89 -0.65,1.48v10c0,1.1 0.89,2 2,2L0,18.02v2h18.13l2.71,2.71 1.27,-1.27L2.39,1.73zM7,15.02c0.31,-1.48 0.92,-2.95 2.07,-4.06l1.59,1.59c-1.54,0.38 -2.7,1.18 -3.66,2.47z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/layout/controller_call.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@
app:placeholderImage="@drawable/ic_comment_white"
app:roundAsCircle="true" />

<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/callControlShareScreen"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:backgroundImage="@color/call_buttons_background"
app:placeholderImage="@drawable/ic_baseline_stop_screen_share_24"
app:roundAsCircle="true" />

<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/callControlEnableSpeaker"
android:layout_width="60dp"
Expand Down