feat: adding UI and flipping cameras

This commit is contained in:
Harris 2021-09-02 17:39:02 +10:00
parent b648a3cf65
commit 3dd2a83dd0
6 changed files with 139 additions and 12 deletions

View File

@ -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
}

View File

@ -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<AudioDevice>)->Unit) {
enum class AudioDevice {
SPEAKER_PHONE, WIRED_HEADSET, EARPIECE, NONE
}
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,9c-1.6,0 -3.15,0.25 -4.6,0.72v3.1c0,0.39 -0.23,0.74 -0.56,0.9 -0.98,0.49 -1.87,1.12 -2.66,1.85 -0.18,0.18 -0.43,0.28 -0.7,0.28 -0.28,0 -0.53,-0.11 -0.71,-0.29L0.29,13.08c-0.18,-0.17 -0.29,-0.42 -0.29,-0.7 0,-0.28 0.11,-0.53 0.29,-0.71C3.34,8.78 7.46,7 12,7s8.66,1.78 11.71,4.67c0.18,0.18 0.29,0.43 0.29,0.71 0,0.28 -0.11,0.53 -0.29,0.71l-2.48,2.48c-0.18,0.18 -0.43,0.29 -0.71,0.29 -0.27,0 -0.52,-0.11 -0.7,-0.28 -0.79,-0.74 -1.69,-1.36 -2.67,-1.85 -0.33,-0.16 -0.56,-0.5 -0.56,-0.9v-3.1C15.15,9.25 13.6,9 12,9z"/>
</vector>

View File

@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M9,12c0,1.66 1.34,3 3,3s3,-1.34 3,-3s-1.34,-3 -3,-3S9,10.34 9,12z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M8,10V8H5.09C6.47,5.61 9.05,4 12,4c3.72,0 6.85,2.56 7.74,6h2.06c-0.93,-4.56 -4.96,-8 -9.8,-8C8.73,2 5.82,3.58 4,6.01V4H2v6H8z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M16,14v2h2.91c-1.38,2.39 -3.96,4 -6.91,4c-3.72,0 -6.85,-2.56 -7.74,-6H2.2c0.93,4.56 4.96,8 9.8,8c3.27,0 6.18,-1.58 8,-4.01V20h2v-6H16z"/>
</vector>

View File

@ -1,19 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.webrtc.SurfaceViewRenderer
android:id="@+id/remote_renderer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
app:layout_constraintBottom_toTopOf="@+id/halfway_guideline"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/halfway_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<org.webrtc.SurfaceViewRenderer
android:id="@+id/local_renderer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/halfway_guideline" />
</LinearLayout>
<ImageView
android:id="@+id/end_call_button"
android:background="@drawable/circle_tintable"
android:src="@drawable/ic_baseline_call_end_24"
android:padding="@dimen/small_spacing"
app:tint="@color/core_white"
android:backgroundTint="@color/destructive"
android:layout_width="@dimen/large_button_height"
android:layout_height="@dimen/large_button_height"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="@dimen/large_spacing"
/>
<ImageView
android:id="@+id/switch_camera_button"
android:background="@drawable/circle_tintable"
android:src="@drawable/ic_baseline_flip_camera_android_24"
android:padding="@dimen/small_spacing"
app:tint="@color/unimportant"
android:backgroundTint="@color/unimportant_button_background"
android:layout_width="@dimen/large_button_height"
android:layout_height="@dimen/large_button_height"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="@dimen/large_spacing"
app:layout_constraintHorizontal_bias="0.2"
/>
<ImageView
android:id="@+id/switch_audio_button"
android:background="@drawable/circle_tintable"
android:src="@drawable/ic_audio_light"
android:padding="@dimen/small_spacing"
app:tint="@color/unimportant"
android:backgroundTint="@color/unimportant_button_background"
android:layout_width="@dimen/large_button_height"
android:layout_height="@dimen/large_button_height"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="@dimen/large_spacing"
app:layout_constraintHorizontal_bias="0.8"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -12,6 +12,7 @@
<!-- Element Sizes -->
<dimen name="small_button_height">34dp</dimen>
<dimen name="medium_button_height">38dp</dimen>
<dimen name="large_button_height">54dp</dimen>
<dimen name="medium_button_corner_radius">22dp</dimen>
<dimen name="accent_line_thickness">4dp</dimen>
<dimen name="very_small_profile_picture_size">26dp</dimen>