From df2d63f6b6ca26deaa27c1139739295cdc48b5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:06:30 +0100 Subject: [PATCH] remove unnecesary track id to metadata property and export TrackData to separate file --- .../rtc/InternalMembraneRTC.kt | 24 +++++++++---------- .../rtc/RTCEngineCommunication.kt | 3 +-- .../rtc/RTCEngineListener.kt | 4 ++-- .../org/membraneframework/rtc/events/Event.kt | 8 +++---- .../membraneframework/rtc/models/Endpoint.kt | 17 +++++++------ .../membraneframework/rtc/models/TrackData.kt | 8 +++++++ 6 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 44a90ef..063e569 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -15,6 +15,7 @@ import org.membraneframework.rtc.models.EncodingReason import org.membraneframework.rtc.models.Endpoint import org.membraneframework.rtc.models.RTCStats import org.membraneframework.rtc.models.TrackContext +import org.membraneframework.rtc.models.TrackData import org.membraneframework.rtc.models.VadStatus import org.membraneframework.rtc.utils.ClosableCoroutineScope import org.membraneframework.rtc.utils.Metadata @@ -50,7 +51,7 @@ internal class InternalMembraneRTC ) private var localEndpoint: Endpoint = - Endpoint(id = "", type = "webrtc", metadata = mapOf(), trackIdToMetadata = mapOf(), tracks = mapOf()) + Endpoint(id = "", type = "webrtc", metadata = mapOf(), tracks = mapOf()) // mapping from endpoint's id to the endpoint himself private val remoteEndpoints = HashMap() @@ -248,14 +249,14 @@ internal class InternalMembraneRTC otherEndpoints.forEach { this.remoteEndpoints[it.id] = it - for ((trackId, metadata) in it.trackIdToMetadata) { + for ((trackId, trackData) in it.tracks) { val context = TrackContext( track = null, endpoint = it, trackId = trackId, - metadata = metadata ?: mapOf(), - simulcastConfig = it.tracks[trackId]?.simulcastConfig + metadata = trackData.metadata ?: mapOf(), + simulcastConfig = trackData.simulcastConfig ) this.trackContexts[trackId] = context @@ -290,7 +291,7 @@ internal class InternalMembraneRTC return } - val trackIds: List = endpoint.trackIdToMetadata.keys.toList() + val trackIds: List = endpoint.tracks.keys.toList() trackIds.forEach { trackContexts.remove(it)?.let { ctx -> @@ -326,7 +327,7 @@ internal class InternalMembraneRTC } rtcEngineCommunication.sdpOffer( offer.description, - localEndpoint.trackIdToMetadata, + localEndpoint.tracks.mapValues { it.value.metadata }, offer.midToTrackIdMapping ) } catch (e: Exception) { @@ -382,8 +383,7 @@ internal class InternalMembraneRTC override fun onTracksAdded( endpointId: String, - trackIdToMetadata: Map, - tracks: Map + tracks: Map ) { if (localEndpoint.id == endpointId) return @@ -393,18 +393,18 @@ internal class InternalMembraneRTC return } - val updatedEndpoint = endpoint.copy(trackIdToMetadata = trackIdToMetadata, tracks = tracks) + val updatedEndpoint = endpoint.copy(tracks = tracks) remoteEndpoints[updatedEndpoint.id] = updatedEndpoint - for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { + for ((trackId, trackData) in updatedEndpoint.tracks) { val context = TrackContext( track = null, endpoint = endpoint, trackId = trackId, - metadata = metadata ?: mapOf(), - simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig + metadata = trackData.metadata ?: mapOf(), + simulcastConfig = trackData.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 c92624f..3ffd7d8 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt @@ -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(), mapOf()) + Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf()) ) is EndpointUpdated -> engineListener.onEndpointUpdated(event.data.id, event.data.metadata) is RemoteCandidate -> @@ -127,7 +127,6 @@ internal class RTCEngineCommunication is TracksAdded -> engineListener.onTracksAdded( event.data.endpointId, - event.data.trackIdToMetadata, event.data.tracks ) is TracksRemoved -> engineListener.onTracksRemoved(event.data.endpointId, event.data.trackIds) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt index e780d7b..f634b61 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt @@ -3,6 +3,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.models.TrackData import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.SerializedMediaEvent @@ -42,8 +43,7 @@ internal interface RTCEngineListener { fun onTracksAdded( endpointId: String, - trackIdToMetadata: Map, - tracks: Map + tracks: Map ) fun onTracksRemoved( 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 3acc145..6137f57 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -6,6 +6,7 @@ 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.models.TrackData import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.Payload import timber.log.Timber @@ -236,7 +237,7 @@ data class EndpointAdded(val type: ReceivableEventType, val data: Data) : Receiv val id: String, val type: String, val metadata: Metadata?, - val trackIdToMetadata: Map + val tracks: Map ) } @@ -263,11 +264,8 @@ 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, 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 432f119..90fd812 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt @@ -1,27 +1,26 @@ 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 tracks: Map + val tracks: Map = mapOf(), ) { fun withTrack( trackId: String, metadata: Metadata? ): Endpoint { - val newTrackIdToMetadata = this.trackIdToMetadata.toMutableMap() - newTrackIdToMetadata[trackId] = metadata ?: mapOf() - return this.copy(trackIdToMetadata = newTrackIdToMetadata) + val tracks = this.tracks.toMutableMap() + val trackData = tracks[trackId] + tracks[trackId] = TrackData(metadata = metadata, simulcastConfig = trackData?.simulcastConfig); + return this.copy(tracks = tracks) } fun withoutTrack(trackId: String): Endpoint { - val newTrackIdToMetadata = this.trackIdToMetadata.toMutableMap() - newTrackIdToMetadata.remove(trackId) - return this.copy(trackIdToMetadata = newTrackIdToMetadata) + val tracks = this.tracks.toMutableMap() + tracks.remove(trackId) + return this.copy(tracks = tracks) } } diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt new file mode 100644 index 0000000..55c283f --- /dev/null +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -0,0 +1,8 @@ +package org.membraneframework.rtc.models + +import org.membraneframework.rtc.SimulcastConfig +import org.membraneframework.rtc.utils.Metadata + +data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?){ + +}