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

Karkakol/add active simulcast encodings #56

Merged
merged 24 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import org.membraneframework.rtc.events.OfferData
import org.membraneframework.rtc.events.TracksAdded
import org.membraneframework.rtc.media.*
import org.membraneframework.rtc.models.EncodingReason
import org.membraneframework.rtc.models.Endpoint
Expand Down Expand Up @@ -49,7 +50,7 @@ internal class InternalMembraneRTC
)

private var localEndpoint: Endpoint =
Endpoint(id = "", type = "webrtc", metadata = mapOf(), trackIdToMetadata = mapOf())
Endpoint(id = "", type = "webrtc", metadata = mapOf(), trackIdToMetadata = mapOf(), tracks = mapOf())

// mapping from endpoint's id to the endpoint himself
private val remoteEndpoints = HashMap<String, Endpoint>()
Expand Down Expand Up @@ -249,7 +250,13 @@ internal class InternalMembraneRTC

for ((trackId, metadata) in it.trackIdToMetadata) {
val context =
TrackContext(track = null, endpoint = it, trackId = trackId, metadata = metadata ?: mapOf())
TrackContext(
track = null,
endpoint = it,
trackId = trackId,
metadata = metadata ?: mapOf(),
simulcastConfig = it.tracks[trackId]?.simulcastConfig
)

this.trackContexts[trackId] = context

Expand Down Expand Up @@ -375,7 +382,8 @@ internal class InternalMembraneRTC

override fun onTracksAdded(
endpointId: String,
trackIdToMetadata: Map<String, Metadata?>
trackIdToMetadata: Map<String, Metadata?>,
tracks: Map<String, TracksAdded.Data.TrackData>
) {
if (localEndpoint.id == endpointId) return

Expand All @@ -385,13 +393,19 @@ internal class InternalMembraneRTC
return
}

val updatedEndpoint = endpoint.copy(trackIdToMetadata = trackIdToMetadata)
val updatedEndpoint = endpoint.copy(trackIdToMetadata = trackIdToMetadata, tracks = tracks)

remoteEndpoints[updatedEndpoint.id] = updatedEndpoint

for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) {
val context =
TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata ?: mapOf())
TrackContext(
track = null,
endpoint = endpoint,
trackId = trackId,
metadata = metadata ?: mapOf(),
simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig
)

this.trackContexts[trackId] = context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ internal class RTCEngineCommunication
is EndpointRemoved -> engineListener.onEndpointRemoved(event.data.id)
is EndpointAdded ->
engineListener.onEndpointAdded(
Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf())
Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf(), mapOf())
)
is EndpointUpdated -> engineListener.onEndpointUpdated(event.data.id, event.data.metadata)
is RemoteCandidate ->
Expand All @@ -124,7 +124,12 @@ internal class RTCEngineCommunication
event.data.trackId,
event.data.metadata
)
is TracksAdded -> engineListener.onTracksAdded(event.data.endpointId, event.data.trackIdToMetadata)
is TracksAdded ->
engineListener.onTracksAdded(
event.data.endpointId,
event.data.trackIdToMetadata,
event.data.tracks
)
is TracksRemoved -> engineListener.onTracksRemoved(event.data.endpointId, event.data.trackIds)
is EncodingSwitched ->
engineListener.onTrackEncodingChanged(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.membraneframework.rtc

import org.membraneframework.rtc.events.OfferData
import org.membraneframework.rtc.events.TracksAdded
import org.membraneframework.rtc.models.Endpoint
import org.membraneframework.rtc.utils.Metadata
import org.membraneframework.rtc.utils.SerializedMediaEvent
Expand Down Expand Up @@ -41,7 +42,8 @@ internal interface RTCEngineListener {

fun onTracksAdded(
endpointId: String,
trackIdToMetadata: Map<String, Metadata?>
trackIdToMetadata: Map<String, Metadata?>,
tracks: Map<String, TracksAdded.Data.TrackData>
)

fun onTracksRemoved(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package org.membraneframework.rtc

import com.google.gson.annotations.SerializedName

/**
* Enum describing possible track encodings.
* `"h"` - original encoding
* `"m"` - original encoding scaled down by 2
* `"l"` - original encoding scaled down by 4
*/
enum class TrackEncoding(val rid: String) {
@SerializedName("l")
L("l"),

@SerializedName("m")
M("m"),

@SerializedName("h")
H("h");

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.gson.Gson
import com.google.gson.JsonParseException
import com.google.gson.annotations.SerializedName
import com.google.gson.reflect.TypeToken
import org.membraneframework.rtc.SimulcastConfig
import org.membraneframework.rtc.models.Endpoint
import org.membraneframework.rtc.utils.Metadata
import org.membraneframework.rtc.utils.Payload
Expand Down Expand Up @@ -260,7 +261,13 @@ data class OfferData(val type: ReceivableEventType, val data: Data) : Receivable
}

data class TracksAdded(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class Data(val endpointId: String, val trackIdToMetadata: Map<String, Metadata?>)
data class Data(
val endpointId: String,
val trackIdToMetadata: Map<String, Metadata?>,
val tracks: Map<String, TrackData>
graszka22 marked this conversation as resolved.
Show resolved Hide resolved
) {
data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?)
}
}

data class TracksRemoved(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.membraneframework.rtc.models

import org.membraneframework.rtc.events.TracksAdded
import org.membraneframework.rtc.utils.Metadata

data class Endpoint(
val id: String,
val type: String,
val metadata: Metadata? = mapOf(),
val trackIdToMetadata: Map<String, Metadata?> = mapOf()
val trackIdToMetadata: Map<String, Metadata?> = mapOf(),
val tracks: Map<String, TracksAdded.Data.TrackData>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too we have trackIdToMetadata and tracks, if it's user facing class it would be confusing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also an endpoint might be a local endpoint, do we update it in that case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's user facing it doesn't look nice to me (the TracksAdded.Data.TrackData type is too long and TracksAdded event is not user facing. Consider creating a new type maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary data is removed

) {
fun withTrack(
trackId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.membraneframework.rtc.models

import org.membraneframework.rtc.SimulcastConfig
import org.membraneframework.rtc.TrackEncoding
import org.membraneframework.rtc.media.RemoteTrack
import org.membraneframework.rtc.utils.Metadata
Expand All @@ -19,7 +20,13 @@ fun interface OnVoiceActivityChangedListener {
* @property trackId Track id. It is generated by RTC engine and takes form `endpoint_id:<random_uuidv4>`.
* @property metadata Any info that was passed in MembraneWebRTC.createVideoTrack/MembraneWebRTC.createAudioTrack
*/
class TrackContext(track: RemoteTrack?, val endpoint: Endpoint, val trackId: String, metadata: Metadata = mapOf()) {
class TrackContext(
track: RemoteTrack?,
val endpoint: Endpoint,
val trackId: String,
metadata: Metadata = mapOf(),
simulcastConfig: SimulcastConfig?
) {
private var onTrackEncodingChangeListener: (OnEncodingChangedListener)? = null
private var onVadNotificationListener: (OnVoiceActivityChangedListener)? = null

Expand All @@ -28,6 +35,9 @@ class TrackContext(track: RemoteTrack?, val endpoint: Endpoint, val trackId: Str
var metadata: Metadata = metadata
internal set

var simulcastConfig: SimulcastConfig? = simulcastConfig
graszka22 marked this conversation as resolved.
Show resolved Hide resolved
internal set

var vadStatus: VadStatus = VadStatus.SILENCE
internal set(value) {
field = value
Expand Down