Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
[MV-165] Update set encoding api (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
graszka22 authored Oct 12, 2022
1 parent 827f740 commit 5ea4dad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,10 @@ constructor(
return mapping
}

fun selectTrackEncoding(peerId: String, trackId: String, encoding: TrackEncoding) {
fun setTargetTrackEncoding(trackId: String, encoding: TrackEncoding) {
coroutineScope.launch {
transport.send(
SelectEncoding(
peerId,
trackId,
encoding.rid
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ private constructor(
}

/**
* Selects track encoding that server should send to the client library.
* Sets track encoding that server should send to the client library.
*
* The encoding will be sent whenever it is available.
* If chosen encoding is temporarily unavailable, some other encoding
* will be sent until chosen encoding becomes active again.
*
* @param peerId: an id of a peer that owns the track
* @param trackId: an id of a remote track
* @param encoding: an encoding to receive
*/
public fun selectTrackEncoding(peerId: String, trackId: String, encoding: TrackEncoding) {
client.selectTrackEncoding(peerId, trackId, encoding)
public fun setTargetTrackEncoding(trackId: String, encoding: TrackEncoding) {
client.setTargetTrackEncoding(trackId, encoding)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ data class RenegotiateTracks(val type: String, val data: Payload): SendableEvent
)
}

data class SelectEncoding(val type: String, val data: Data): SendableEvent() {
data class Data(val peerId: String, val trackId: String, val encoding: String)

constructor(peerId: String, trackId: String, encoding: String):
this("selectEncoding", Data(peerId, trackId, encoding))
data class SelectEncoding(val type: String, val data: Payload): SendableEvent() {
constructor(trackId: String, encoding: String):
this("custom", mapOf(
"type" to "setTargetTrackVariant",
"data" to mapOf(
"trackId" to trackId,
"variant" to encoding
)
))
}

data class UpdatePeerMetadata(val type: String, val data: Data): SendableEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ public class RoomViewModel(
val primaryParticipantTrackId = primaryParticipant.value?.videoTrack?.id()
if(localVideoTrack?.id() != primaryParticipantTrackId && localScreencastTrack?.id() != primaryParticipantTrackId) {
val globalId = globalToLocalTrackId.filterValues { it1 -> it1 == primaryParticipantTrackId }.keys.first()
primaryParticipant.value?.id?.let { it1 -> room.value?.selectTrackEncoding(it1, globalId, TrackEncoding.L) }
room.value?.setTargetTrackEncoding(globalId, TrackEncoding.L)
}
primaryParticipant.value = it
val videoTrackId = it.videoTrack?.id()
if(localVideoTrack?.id() != it.videoTrack?.id() && localScreencastTrack?.id() != videoTrackId) {
val globalId = globalToLocalTrackId.filterValues { it1 -> it1 == it.videoTrack?.id() }.keys.first()
room.value?.selectTrackEncoding(participantId, globalId, TrackEncoding.H)
room.value?.setTargetTrackEncoding(globalId, TrackEncoding.H)
}

participants.value = candidates.filter { candidate ->
Expand Down

0 comments on commit 5ea4dad

Please sign in to comment.