Changes for local video conferencing

This commit is contained in:
Sylvain Berfini 2020-04-21 18:52:20 +02:00
parent e73e844070
commit f6df9711b7
8 changed files with 72 additions and 27 deletions

View file

@ -123,7 +123,7 @@ class CallActivity : ProximitySensorActivity() {
override fun onUserLeaveHint() { override fun onUserLeaveHint() {
super.onUserLeaveHint() super.onUserLeaveHint()
if (coreContext.core.currentCall?.currentParams?.videoEnabled() == true) { if (coreContext.isVideoCallOrConferenceActive()) {
Compatibility.enterPipMode(this) Compatibility.enterPipMode(this)
} }
} }

View file

@ -26,7 +26,7 @@ import android.hardware.SensorEventListener
import android.hardware.SensorManager import android.hardware.SensorManager
import android.os.Bundle import android.os.Bundle
import android.os.PowerManager import android.os.PowerManager
import org.linphone.LinphoneApplication import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.activities.GenericActivity import org.linphone.activities.GenericActivity
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
@ -75,12 +75,9 @@ abstract class ProximitySensorActivity : GenericActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (LinphoneApplication.coreContext.core.callsNb > 0) { if (coreContext.core.callsNb > 0) {
val currentCall = LinphoneApplication.coreContext.core.currentCall ?: LinphoneApplication.coreContext.core.calls[0] val videoEnabled = coreContext.isVideoCallOrConferenceActive()
if (currentCall != null) { enableProximitySensor(!videoEnabled)
val videoEnabled = currentCall.currentParams.videoEnabled()
enableProximitySensor(!videoEnabled)
}
} }
} }

View file

@ -46,8 +46,9 @@ class ControlsFadingViewModel : ViewModel() {
message: String? message: String?
) { ) {
if (state == Call.State.StreamsRunning || state == Call.State.Updating || state == Call.State.UpdatedByRemote) { if (state == Call.State.StreamsRunning || state == Call.State.Updating || state == Call.State.UpdatedByRemote) {
Log.i("[Controls Fading] Call is in state $state, video is enabled? ${call.currentParams.videoEnabled()}") val videoEnabled = coreContext.isVideoCallOrConferenceActive()
if (call.currentParams.videoEnabled()) { Log.i("[Controls Fading] Call is in state $state, video is enabled? $videoEnabled")
if (videoEnabled) {
videoEnabledEvent.value = Event(true) videoEnabledEvent.value = Event(true)
startTimer() startTimer()
} else { } else {
@ -64,8 +65,8 @@ class ControlsFadingViewModel : ViewModel() {
areControlsHidden.value = false areControlsHidden.value = false
isVideoPreviewHidden.value = false isVideoPreviewHidden.value = false
val currentCall = coreContext.core.currentCall val videoEnabled = coreContext.isVideoCallOrConferenceActive()
if (currentCall != null && currentCall.currentParams.videoEnabled()) { if (videoEnabled) {
videoEnabledEvent.value = Event(true) videoEnabledEvent.value = Event(true)
startTimer() startTimer()
} }
@ -95,7 +96,8 @@ class ControlsFadingViewModel : ViewModel() {
timer = Timer("Hide UI controls scheduler") timer = Timer("Hide UI controls scheduler")
timer?.schedule(object : TimerTask() { timer?.schedule(object : TimerTask() {
override fun run() { override fun run() {
areControlsHidden.postValue(coreContext.core.currentCall?.currentParams?.videoEnabled() ?: false) val videoEnabled = coreContext.isVideoCallOrConferenceActive()
areControlsHidden.postValue(videoEnabled)
} }
}, 3000) }, 3000)
} }

View file

@ -181,7 +181,13 @@ class ControlsViewModel : ViewModel() {
val core = coreContext.core val core = coreContext.core
val currentCall = core.currentCall val currentCall = core.currentCall
if (currentCall != null) { if (core.conference != null && core.isInConference) {
val params = core.createConferenceParams()
val videoEnabled = core.conference.currentParams.videoEnabled()
params.enableVideo(!videoEnabled)
Log.i("[Controls VM] Conference current param for video is $videoEnabled")
core.conference.updateParams(params)
} else if (currentCall != null) {
val state = currentCall.state val state = currentCall.state
if (state == Call.State.End || state == Call.State.Released || state == Call.State.Error) if (state == Call.State.End || state == Call.State.Released || state == Call.State.Error)
return return
@ -238,7 +244,19 @@ class ControlsViewModel : ViewModel() {
fun startConference() { fun startConference() {
somethingClickedEvent.value = Event(true) somethingClickedEvent.value = Event(true)
coreContext.core.addAllToConference()
val core = coreContext.core
val currentCallVideoEnabled = core.currentCall?.currentParams?.videoEnabled() ?: false
val params = core.createConferenceParams()
params.enableVideo(currentCallVideoEnabled)
Log.i("[Call] Setting videoEnabled to [$currentCallVideoEnabled] in conference params")
val conference = core.createConferenceWithParams(params)
for (call in core.calls) {
conference.addParticipant(call)
}
toggleOptionsMenu() toggleOptionsMenu()
} }
@ -324,12 +342,12 @@ class ControlsViewModel : ViewModel() {
private fun updateVideoAvailable() { private fun updateVideoAvailable() {
val core = coreContext.core val core = coreContext.core
isVideoAvailable.value = (core.videoCaptureEnabled() || core.videoPreviewEnabled()) && isVideoAvailable.value = (core.videoCaptureEnabled() || core.videoPreviewEnabled()) &&
core.currentCall != null && !core.currentCall.mediaInProgress() ((core.currentCall != null && !core.currentCall.mediaInProgress()) ||
(core.conference != null && core.isInConference))
} }
private fun updateVideoEnabled() { private fun updateVideoEnabled() {
val core = coreContext.core isVideoEnabled.value = coreContext.isVideoCallOrConferenceActive()
isVideoEnabled.value = core.currentCall?.currentParams?.videoEnabled()
} }
private fun updateConferenceState() { private fun updateConferenceState() {

View file

@ -37,11 +37,13 @@ class StatisticsListViewModel : ViewModel() {
message: String? message: String?
) { ) {
if (state == Call.State.End || state == Call.State.Error) { if (state == Call.State.End || state == Call.State.Error) {
val newList = arrayListOf<CallStatisticsViewModel>()
for (stat in callStatsList.value.orEmpty()) { for (stat in callStatsList.value.orEmpty()) {
if (stat.call == call) { if (stat.call != call) {
callStatsList.value?.remove(stat) newList.add(stat)
} }
} }
callStatsList.value = newList
} }
} }
} }

View file

@ -353,18 +353,30 @@ class CoreContext(val context: Context, coreConfig: Config) {
} }
} }
val call = core.currentCall if (core.conference != null && core.isInConference) {
if (call == null) { // Nothing to do
Log.w("[Context] Switching camera while not in call") } else {
return val call = core.currentCall
if (call == null) {
Log.w("[Context] Switching camera while not in call")
return
}
call.update(null)
} }
call.update(null)
} }
fun showSwitchCameraButton(): Boolean { fun showSwitchCameraButton(): Boolean {
return core.videoDevicesList.orEmpty().size > 2 // Count StaticImage camera return core.videoDevicesList.orEmpty().size > 2 // Count StaticImage camera
} }
fun isVideoCallOrConferenceActive(): Boolean {
return if (core.conference != null && core.isInConference) {
core.conference.currentParams.videoEnabled()
} else {
core.currentCall?.currentParams?.videoEnabled() ?: false
}
}
fun createCallOverlay() { fun createCallOverlay() {
if (!corePreferences.showCallOverlay || callOverlay != null) { if (!corePreferences.showCallOverlay || callOverlay != null) {
return return

View file

@ -116,7 +116,7 @@
<ImageView <ImageView
android:onClick="@{() -> controlsViewModel.switchCamera()}" android:onClick="@{() -> controlsViewModel.switchCamera()}"
android:enabled="@{!viewModel.callPausedByRemote}" android:enabled="@{!viewModel.callPausedByRemote}"
android:visibility="@{controlsViewModel.isVideoEnabled &amp;&amp; controlsViewModel.showSwitchCamera ? View.VISIBLE : View.GONE, default=gone}" android:visibility="@{controlsViewModel.isVideoEnabled &amp;&amp; controlsViewModel.showSwitchCamera &amp;&amp; (viewModel.conferenceCalls.size() == 0 || viewModel.isConferencePaused) ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_switch_camera" android:contentDescription="@string/content_description_switch_camera"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"

View file

@ -59,6 +59,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:background="?attr/backgroundColor"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout <RelativeLayout
@ -75,6 +76,19 @@
android:text="@string/call_conference_title" /> android:text="@string/call_conference_title" />
<ImageView <ImageView
android:onClick="@{() -> controlsViewModel.switchCamera()}"
android:visibility="@{controlsViewModel.isVideoEnabled ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_switch_camera"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/pause_conference"
android:adjustViewBounds="true"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@drawable/switch_camera" />
<ImageView
android:id="@+id/pause_conference"
android:onClick="@{() -> viewModel.pauseConference()}" android:onClick="@{() -> viewModel.pauseConference()}"
android:contentDescription="@string/content_description_pause_conference" android:contentDescription="@string/content_description_pause_conference"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -208,7 +222,7 @@
<ImageView <ImageView
android:onClick="@{() -> controlsViewModel.switchCamera()}" android:onClick="@{() -> controlsViewModel.switchCamera()}"
android:enabled="@{!viewModel.callPausedByRemote}" android:enabled="@{!viewModel.callPausedByRemote}"
android:visibility="@{controlsViewModel.isVideoEnabled &amp;&amp; controlsViewModel.showSwitchCamera ? View.VISIBLE : View.GONE, default=gone}" android:visibility="@{controlsViewModel.isVideoEnabled &amp;&amp; controlsViewModel.showSwitchCamera &amp;&amp; (viewModel.conferenceCalls.size() == 0 || viewModel.isConferencePaused) ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_switch_camera" android:contentDescription="@string/content_description_switch_camera"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"