diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcTestsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcTestsActivity.kt index 7d7fb40957..924615bb3d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcTestsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcTestsActivity.kt @@ -36,6 +36,8 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection private val eglBase by lazy { EglBase.create() } private val surfaceHelper by lazy { SurfaceTextureHelper.create(Thread.currentThread().name, eglBase.eglBaseContext) } + private val audioSource by lazy { connectionFactory.createAudioSource(MediaConstraints()) } + private val videoCapturer by lazy { createCameraCapturer(Camera2Enumerator(this)) } private val connectionFactory by lazy { @@ -74,18 +76,32 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection setEnableHardwareScaler(true) init(eglBase.eglBaseContext, null) } + remote_renderer.run { setMirror(true) setEnableHardwareScaler(true) init(eglBase.eglBaseContext, null) } - val audioSource = connectionFactory.createAudioSource(MediaConstraints()) + end_call_button.setOnClickListener { + endCall() + } + + switch_camera_button.setOnClickListener { + videoCapturer?.switchCamera(null) + } + + switch_audio_button.setOnClickListener { + + } + val videoSource = connectionFactory.createVideoSource(false) - val videoCapturer = createCameraCapturer(Camera2Enumerator(this)) ?: kotlin.run { finish(); return } - videoCapturer.initialize(surfaceHelper, local_renderer.context, videoSource.capturerObserver) - videoCapturer.startCapture(HD_VIDEO_WIDTH, HD_VIDEO_HEIGHT, 10) + videoCapturer?.initialize(surfaceHelper, local_renderer.context, videoSource.capturerObserver) ?: run { + finish() + return + } + videoCapturer?.startCapture(HD_VIDEO_WIDTH, HD_VIDEO_HEIGHT, 10) val audioTrack = connectionFactory.createAudioTrack(LOCAL_TRACK_ID + "_audio", audioSource) val videoTrack = connectionFactory.createVideoTrack(LOCAL_TRACK_ID, videoSource) @@ -109,6 +125,19 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection } } + private fun endCall() { + peerConnection.close() + MessageSender.sendNonDurably( + CallMessage(SignalServiceProtos.CallMessage.Type.END_CALL,emptyList(),emptyList(), emptyList()), + callAddress + ) + } + + override fun onDestroy() { + super.onDestroy() + endCall() + } + override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) if (intent == null) return @@ -132,7 +161,7 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection } } - private fun createCameraCapturer(enumerator: CameraEnumerator): VideoCapturer? { + private fun createCameraCapturer(enumerator: CameraEnumerator): CameraVideoCapturer? { val deviceNames = enumerator.deviceNames // First, try to find front facing camera @@ -140,7 +169,7 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection for (deviceName in deviceNames) { if (enumerator.isFrontFacing(deviceName)) { Log.d("Loki-RTC-vid", "Creating front facing camera capturer.") - val videoCapturer: VideoCapturer? = enumerator.createCapturer(deviceName, null) + val videoCapturer = enumerator.createCapturer(deviceName, null) if (videoCapturer != null) { return videoCapturer } @@ -152,7 +181,7 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection for (deviceName in deviceNames) { if (!enumerator.isFrontFacing(deviceName)) { Log.d("Loki-RTC-vid", "Creating other camera capturer.") - val videoCapturer: VideoCapturer? = enumerator.createCapturer(deviceName, null) + val videoCapturer = enumerator.createCapturer(deviceName, null) if (videoCapturer != null) { return videoCapturer } diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/AudioManager.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/AudioManager.kt new file mode 100644 index 0000000000..d59adb9113 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/AudioManager.kt @@ -0,0 +1,14 @@ +package org.thoughtcrime.securesms.webrtc + +import android.content.Context +import android.media.AudioManager + +class RTCAudioManager(context: Context, deviceChangeListener: (currentDevice: AudioDevice?, availableDevices: Collection)->Unit) { + + enum class AudioDevice { + SPEAKER_PHONE, WIRED_HEADSET, EARPIECE, NONE + } + + val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_call_end_24.xml b/app/src/main/res/drawable/ic_baseline_call_end_24.xml new file mode 100644 index 0000000000..dd6ff40926 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_call_end_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_flip_camera_android_24.xml b/app/src/main/res/drawable/ic_baseline_flip_camera_android_24.xml new file mode 100644 index 0000000000..951aa1f621 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_flip_camera_android_24.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/layout/activity_webrtc_tests.xml b/app/src/main/res/layout/activity_webrtc_tests.xml index 930cb746eb..4694b29d98 100644 --- a/app/src/main/res/layout/activity_webrtc_tests.xml +++ b/app/src/main/res/layout/activity_webrtc_tests.xml @@ -1,19 +1,76 @@ - + + app:layout_constraintBottom_toTopOf="@+id/halfway_guideline" + app:layout_constraintTop_toTopOf="parent"/> + + + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@+id/halfway_guideline" /> - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 5e5661c5e2..6eee7a13ea 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -12,6 +12,7 @@ 34dp 38dp + 54dp 22dp 4dp 26dp