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() {
super.onUserLeaveHint()
if (coreContext.core.currentCall?.currentParams?.videoEnabled() == true) {
if (coreContext.isVideoCallOrConferenceActive()) {
Compatibility.enterPipMode(this)
}
}

View file

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

View file

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

View file

@ -181,7 +181,13 @@ class ControlsViewModel : ViewModel() {
val core = coreContext.core
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
if (state == Call.State.End || state == Call.State.Released || state == Call.State.Error)
return
@ -238,7 +244,19 @@ class ControlsViewModel : ViewModel() {
fun startConference() {
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()
}
@ -324,12 +342,12 @@ class ControlsViewModel : ViewModel() {
private fun updateVideoAvailable() {
val core = coreContext.core
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() {
val core = coreContext.core
isVideoEnabled.value = core.currentCall?.currentParams?.videoEnabled()
isVideoEnabled.value = coreContext.isVideoCallOrConferenceActive()
}
private fun updateConferenceState() {

View file

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

View file

@ -353,6 +353,9 @@ class CoreContext(val context: Context, coreConfig: Config) {
}
}
if (core.conference != null && core.isInConference) {
// Nothing to do
} else {
val call = core.currentCall
if (call == null) {
Log.w("[Context] Switching camera while not in call")
@ -360,11 +363,20 @@ class CoreContext(val context: Context, coreConfig: Config) {
}
call.update(null)
}
}
fun showSwitchCameraButton(): Boolean {
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() {
if (!corePreferences.showCallOverlay || callOverlay != null) {
return

View file

@ -116,7 +116,7 @@
<ImageView
android:onClick="@{() -> controlsViewModel.switchCamera()}"
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:layout_width="50dp"
android:layout_height="50dp"

View file

@ -59,6 +59,7 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="?attr/backgroundColor"
android:orientation="vertical">
<RelativeLayout
@ -75,6 +76,19 @@
android:text="@string/call_conference_title" />
<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:contentDescription="@string/content_description_pause_conference"
android:layout_width="wrap_content"
@ -208,7 +222,7 @@
<ImageView
android:onClick="@{() -> controlsViewModel.switchCamera()}"
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:layout_width="50dp"
android:layout_height="50dp"