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

Commit

Permalink
add simulcast confit to added track event
Browse files Browse the repository at this point in the history
  • Loading branch information
karkakol committed Jan 8, 2024
1 parent 1320b41 commit 59ad94f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
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 @@ -48,7 +49,7 @@ constructor(
)

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 @@ -230,7 +231,7 @@ constructor(
this.remoteEndpoints[it.id] = it

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

this.trackContexts[trackId] = context

Expand Down Expand Up @@ -337,20 +338,20 @@ constructor(
}
}

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

val endpoint = remoteEndpoints.remove(endpointId) ?: run {
Timber.e("Failed to process TracksAdded event: Endpoint not found: $endpointId")
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)
val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata, simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig)

this.trackContexts[trackId] = context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ constructor(
is OfferData -> engineListener.onOfferData(event.data.integratedTurnServers, event.data.tracksTypes)
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 -> engineListener.onRemoteCandidate(
Expand All @@ -114,7 +114,7 @@ constructor(
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(
event.data.endpointId,
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 All @@ -14,7 +15,7 @@ internal interface RTCEngineListener {
fun onOfferData(integratedTurnServers: List<OfferData.TurnServer>, tracksTypes: Map<String, Int>)
fun onSdpAnswer(type: String, sdp: String, midToTrackId: Map<String, String>)
fun onRemoteCandidate(candidate: String, sdpMLineIndex: Int, sdpMid: String?)
fun onTracksAdded(endpointId: String, trackIdToMetadata: Map<String, Metadata>)
fun onTracksAdded(endpointId: String, trackIdToMetadata: Map<String, Metadata>, tracks: Map<String, TracksAdded.Data.TrackData>)
fun onTracksRemoved(endpointId: String, trackIds: List<String>)
fun onTrackUpdated(endpointId: String, trackId: String, metadata: Metadata)
fun onTrackEncodingChanged(endpointId: String, trackId: String, encoding: String, encodingReason: String)
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 @@ -255,7 +256,9 @@ 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>){
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>,
) {
fun withTrack(trackId: String, metadata: Metadata?): Endpoint {
val newTrackIdToMetadata = this.trackIdToMetadata.toMutableMap()
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,7 @@ 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) {
class TrackContext(track: RemoteTrack?, val endpoint: Endpoint, val trackId: String, metadata: Metadata, simulcastConfig: SimulcastConfig?) {
private var onTrackEncodingChangeListener: (OnEncodingChangedListener)? = null
private var onVadNotificationListener: (OnVoiceActivityChangedListener)? = null

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

var simulcastConfig: SimulcastConfig? = simulcastConfig
internal set

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

0 comments on commit 59ad94f

Please sign in to comment.