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

Commit

Permalink
remove unnecesary track id to metadata property and export TrackData …
Browse files Browse the repository at this point in the history
…to separate file
  • Loading branch information
karkakol committed Jan 17, 2024
1 parent 0b93cc1 commit df2d63f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String, Endpoint>()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -290,7 +291,7 @@ internal class InternalMembraneRTC
return
}

val trackIds: List<String> = endpoint.trackIdToMetadata.keys.toList()
val trackIds: List<String> = endpoint.tracks.keys.toList()

trackIds.forEach {
trackContexts.remove(it)?.let { ctx ->
Expand Down Expand Up @@ -326,7 +327,7 @@ internal class InternalMembraneRTC
}
rtcEngineCommunication.sdpOffer(
offer.description,
localEndpoint.trackIdToMetadata,
localEndpoint.tracks.mapValues { it.value.metadata },
offer.midToTrackIdMapping
)
} catch (e: Exception) {
Expand Down Expand Up @@ -382,8 +383,7 @@ internal class InternalMembraneRTC

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

Expand All @@ -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
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(), mapOf())
Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf())
)
is EndpointUpdated -> engineListener.onEndpointUpdated(event.data.id, event.data.metadata)
is RemoteCandidate ->
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -42,8 +43,7 @@ internal interface RTCEngineListener {

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

fun onTracksRemoved(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String, Metadata?>
val tracks: Map<String, TrackData>
)
}

Expand All @@ -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<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,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<String, Metadata?> = mapOf(),
val tracks: Map<String, TracksAdded.Data.TrackData>
val tracks: Map<String, TrackData> = 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)
}
}
Original file line number Diff line number Diff line change
@@ -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?){

}

0 comments on commit df2d63f

Please sign in to comment.