From 59ad94ff59c874a6f3792216aa95185064317219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Mon, 8 Jan 2024 17:57:55 +0100 Subject: [PATCH] add simulcast confit to added track event --- .idea/gradle.xml | 5 ++--- .idea/inspectionProfiles/Project_Default.xml | 4 ++++ .../org/membraneframework/rtc/InternalMembraneRTC.kt | 11 ++++++----- .../membraneframework/rtc/RTCEngineCommunication.kt | 4 ++-- .../org/membraneframework/rtc/RTCEngineListener.kt | 3 ++- .../java/org/membraneframework/rtc/events/Event.kt | 5 ++++- .../java/org/membraneframework/rtc/models/Endpoint.kt | 4 +++- .../org/membraneframework/rtc/models/TrackContext.kt | 6 +++++- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 0b1f53f..c6e9676 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,10 +4,8 @@ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 7f41d7c..44ca2d9 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -7,6 +7,7 @@ \ No newline at end of file diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 7c2f8e5..b6ee372 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -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 @@ -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() @@ -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 @@ -337,7 +338,7 @@ constructor( } } - override fun onTracksAdded(endpointId: String, trackIdToMetadata: Map) { + override fun onTracksAdded(endpointId: String, trackIdToMetadata: Map, tracks: Map) { if (localEndpoint.id == endpointId) return val endpoint = remoteEndpoints.remove(endpointId) ?: run { @@ -345,12 +346,12 @@ constructor( 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 diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt index 10f18d7..0a179ca 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt @@ -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( @@ -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, diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt index b51f9ab..6af47c2 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt @@ -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 @@ -14,7 +15,7 @@ internal interface RTCEngineListener { fun onOfferData(integratedTurnServers: List, tracksTypes: Map) fun onSdpAnswer(type: String, sdp: String, midToTrackId: Map) fun onRemoteCandidate(candidate: String, sdpMLineIndex: Int, sdpMid: String?) - fun onTracksAdded(endpointId: String, trackIdToMetadata: Map) + fun onTracksAdded(endpointId: String, trackIdToMetadata: Map, tracks: Map) fun onTracksRemoved(endpointId: String, trackIds: List) fun onTrackUpdated(endpointId: String, trackId: String, metadata: Metadata) fun onTrackEncodingChanged(endpointId: String, trackId: String, encoding: String, encodingReason: String) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt index 7d1baa3..887c7f6 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -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 @@ -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) + data class Data(val endpointId: String, val trackIdToMetadata: Map, val tracks: Map){ + data class TrackData(val metadata: Metadata, val simulcastConfig: SimulcastConfig) + } } data class TracksRemoved(val type: ReceivableEventType, val data: Data) : ReceivableEvent() { diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt index 7b9702f..bbc31b2 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt @@ -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 = mapOf() + val trackIdToMetadata: Map = mapOf(), + val tracks: Map, ) { fun withTrack(trackId: String, metadata: Metadata?): Endpoint { val newTrackIdToMetadata = this.trackIdToMetadata.toMutableMap() diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt index 0cad3bb..6171bfa 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt @@ -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 @@ -19,7 +20,7 @@ fun interface OnVoiceActivityChangedListener { * @property trackId Track id. It is generated by RTC engine and takes form `endpoint_id:`. * @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 @@ -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