Skip to content

Commit

Permalink
DIOS-4818 Integrate Millicast v1.9.0 + fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaa92 committed May 22, 2024
1 parent 4a8d7e5 commit 87ff9b2
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ fun StreamingScreen(viewModel: StreamingViewModel = hiltViewModel(), onBack: ()
isMain = true,
view = view
)
},
onRelease = { view ->
uiState.videoTrack?.disableSync(videoSink = view)
view.release()
}
)
SetupVolumeControlAudioStream()
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
appcompat = "1.6.1"
material = "1.8.0"
millicast-sdk = "1.9.0-SNAPSHOT-2684-63f6cfd2"
millicast-sdk = "1.9.0"

[libraries]
androidx-appcompat = "androidx.appcompat:appcompat:1.6.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.millicast.Media
import com.millicast.subscribers.remote.RemoteVideoTrack
import com.millicast.video.TextureViewRenderer
Expand All @@ -44,7 +43,7 @@ fun GridViewScreen(
onMainClick: (String?) -> Unit,
onSettingsClick: () -> Unit
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val uiState by viewModel.uiState.collectAsState()

val screenContentDescription = stringResource(id = R.string.streaming_screen_contentDescription)

Expand All @@ -57,8 +56,8 @@ fun GridViewScreen(
TopAppBar(
title = uiState.streamName ?: screenContentDescription,
onBack = {
onBack()
viewModel.disconnect()
onBack()
},
onAction = onSettingsClick
)
Expand Down Expand Up @@ -170,9 +169,9 @@ private fun VideoView(
// video.play(view, viewModel, videoQuality)
},
onRelease = {
video.disableSync(it)
video.disableAsync()
// viewModel.stopVideo(video)
it.release()
// it.release()
}
)
if (displayLabel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.dolby.interactiveplayer.streaming.multiview

import android.content.res.Configuration
import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -24,10 +25,12 @@ import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
Expand Down Expand Up @@ -55,8 +58,7 @@ fun ListViewScreen(
onMainClick: (String?) -> Unit,
onSettingsClick: () -> Unit
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

val uiState by viewModel.uiState.collectAsState()
val screenContentDescription = stringResource(id = R.string.streaming_screen_contentDescription)

val focusManager = LocalFocusManager.current
Expand All @@ -69,8 +71,8 @@ fun ListViewScreen(
TopAppBar(
title = uiState.streamName ?: screenContentDescription,
onBack = {
onBack()
viewModel.disconnect()
onBack()
},
onAction = onSettingsClick
)
Expand Down Expand Up @@ -152,22 +154,14 @@ fun HorizontalEndListView(
factory = { context ->
val view = TextureViewRenderer(context)
view.init(Media.eglBaseContext, null)
// view.setZOrderOnTop(true)
// view.setZOrderMediaOverlay(true)
view
},
update = { view ->
view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
mainVideo?.enableAsync(videoSink = view)
// mainVideo?.play(
// view = view,
// viewModel = viewModel,
// videoQuality = uiState.connectOptions?.primaryVideoQuality
// ?: VideoQuality.AUTO
// )
},
onRelease = { view ->
mainVideo?.disableSync(videoSink = view)
mainVideo?.disableAsync()
view.release()
}
)
Expand All @@ -187,6 +181,7 @@ fun HorizontalEndListView(
}
val otherTracks =
uiState.videoTracks.filter { it.sourceId != mainVideo?.sourceId }

LazyColumn(
modifier = Modifier
.fillMaxHeight()
Expand Down Expand Up @@ -241,23 +236,15 @@ fun VerticalTopListView(
factory = { context ->
val view = TextureViewRenderer(context)
view.init(Media.eglBaseContext, null)
// view.setZOrderOnTop(true)
// view.setZOrderMediaOverlay(true)
view
},
update = { view ->
view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
mainVideo?.enableAsync(videoSink = view)
// mainVideo?.play(
// view = view,
// viewModel = viewModel,
// videoQuality = uiState.connectOptions?.primaryVideoQuality
// ?: VideoQuality.AUTO
// )
},
onRelease = { view ->
mainVideo?.disableSync(view)
view.release()
mainVideo?.disableAsync()
// view.release()
}
)
if (displayLabel) {
Expand All @@ -274,7 +261,9 @@ fun VerticalTopListView(
}
val otherTracks =
uiState.videoTracks.filter { it.sourceId != mainVideo?.sourceId }

val lazyVerticalGridState = rememberLazyGridState()

LazyVerticalGrid(
state = lazyVerticalGridState,
columns = GridCells.Fixed(count = 2),
Expand Down Expand Up @@ -318,22 +307,23 @@ fun VideoView(
val updatedModifier = onClick?.let {
modifier.clickable { onClick(video) }
} ?: modifier
val context = LocalContext.current
val videoRenderer = remember(context) {
TextureViewRenderer(context).apply {
init(Media.eglBaseContext, null)
}
}
Box {
AndroidView(
modifier = updatedModifier,
factory = { context ->
val view = TextureViewRenderer(context)
view.init(Media.eglBaseContext, null)
view
},
factory = { videoRenderer },
update = { view ->
view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
video.enableAsync(videoSink = view)
// video.play(view, viewModel, videoQuality)
},
onRelease = {
video.disableSync(it)
// viewModel.stopVideo(video)
Log.d("VideoView", "disable sync for video id ${video.currentMid}")
video.disableAsync()
it.release()
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class MultiStreamingViewModel @Inject constructor(
} else {
Error.NO_INTERNET_CONNECTION
}
it.copy(error = error)
it.copy(error = error, videoTracks = emptyList())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun SingleStreamingScreen(
onBack: () -> Unit,
onSettingsClick: (StreamingData?) -> Unit
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val uiState by viewModel.uiState.collectAsState()

val screenContentDescription = stringResource(id = R.string.streaming_screen_contentDescription)
val selectedItem =
Expand Down Expand Up @@ -190,7 +190,7 @@ private fun VideoView(
},
update = { view ->
view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
uiState.videoTracks[page].disableSync()
uiState.videoTracks[page].disableAsync()
val isSelected =
uiState.selectedVideoTrackId == uiState.videoTracks[page].sourceId

Expand All @@ -201,7 +201,7 @@ private fun VideoView(
)
},
onRelease = { view ->
uiState.videoTracks[page].disableSync(videoSink = view)
uiState.videoTracks[page].disableAsync()
view.release()
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.dolby.interactiveplayer.utils

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,20 @@ class MultiStreamListener(
fun connected(): Boolean = subscriber.isSubscribed

fun disconnect() {
Log.d(TAG, "Cancelling coroutines...")
subscriber.disconnect()
coroutineScope.coroutineContext.cancelChildren()
coroutineScope.coroutineContext.cancel()
Log.d(TAG, "Disconnecting subscriber...")
subscriber.release()
}

private fun onConnected() {
Log.d(
TAG,
"onConnected, this: $this, thread: ${Thread.currentThread().id}"
)
data.update {
it.copy(isConnected = true, isSubscribed = false)
}
}

private fun onDisconnected() {
Expand Down Expand Up @@ -165,7 +167,7 @@ class MultiStreamListener(

private fun onSubscribed() {
Log.d(TAG, "onSubscribed")
data.update { data -> data.copy(isSubscribed = true, error = null) }
data.update { data -> data.copy(isSubscribed = true, isSubscribing = false, error = null) }
}

private fun onSubscribedError(p0: String?) {
Expand All @@ -180,7 +182,7 @@ class MultiStreamListener(
data.update { data ->
data.copy(
videoTracks = subscriber.currentState.tracks
.filter { it is RemoteVideoTrack && it.isActive }
.filter { it is RemoteVideoTrack }
.map { it as RemoteVideoTrack }
)
}
Expand All @@ -191,7 +193,7 @@ class MultiStreamListener(
data.update { data ->
data.copy(
audioTracks = subscriber.currentState.tracks
.filter { it is RemoteAudioTrack && it.isActive }
.filter { it is RemoteAudioTrack }
.map { it as RemoteAudioTrack }
)
}
Expand Down
Loading

0 comments on commit 87ff9b2

Please sign in to comment.