Skip to content

Commit

Permalink
fix(core): endpoint info union should be name intersect instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Jan 14, 2025
1 parent 675b481 commit 4039924
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import io.github.thibaultbee.streampack.core.configuration.mediadescriptor.Media
import io.github.thibaultbee.streampack.core.elements.data.Frame
import io.github.thibaultbee.streampack.core.elements.encoders.CodecConfig
import io.github.thibaultbee.streampack.core.elements.utils.combineStates
import io.github.thibaultbee.streampack.core.elements.utils.extensions.union
import io.github.thibaultbee.streampack.core.elements.utils.extensions.intersect
import io.github.thibaultbee.streampack.core.logger.Logger
import kotlinx.coroutines.flow.StateFlow

Expand Down Expand Up @@ -70,14 +70,14 @@ open class CombineEndpoint(protected val endpointInternals: List<IEndpointIntern
*/
override val info: IEndpoint.IEndpointInfo
get() = endpointInternals.map { it.info }
.reduce { acc, iEndpointInfo -> acc union iEndpointInfo }
.reduce { acc, iEndpointInfo -> acc intersect iEndpointInfo }

/**
* The union of all endpoints' [IEndpoint.IEndpointInfo].
*/
override fun getInfo(type: MediaDescriptor.Type): IEndpoint.IEndpointInfo {
return endpointInternals.map { it.getInfo(type) }
.reduce { acc, iEndpointInfo -> acc union iEndpointInfo }
.reduce { acc, iEndpointInfo -> acc intersect iEndpointInfo }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,42 @@ import io.github.thibaultbee.streampack.core.elements.endpoints.IEndpoint
/**
* Returns the union of two [IEndpoint.IEndpointInfo]
*/
internal infix fun IEndpoint.IEndpointInfo.union(other: IEndpoint.IEndpointInfo): IEndpoint.IEndpointInfo {
internal infix fun IEndpoint.IEndpointInfo.intersect(other: IEndpoint.IEndpointInfo): IEndpoint.IEndpointInfo {
return object : IEndpoint.IEndpointInfo {
override val audio = object : IEndpoint.IEndpointInfo.IAudioEndpointInfo {
override val supportedEncoders: List<String>
get() = this@union.audio.supportedEncoders.union(other.audio.supportedEncoders)
get() = this@intersect.audio.supportedEncoders.intersect(other.audio.supportedEncoders.toSet())
.toList()

override val supportedSampleRates: List<Int>?
get() {
val supportedSampleRates = this@union.audio.supportedSampleRates
val supportedSampleRates = this@intersect.audio.supportedSampleRates
val otherSupportedSampleRates = other.audio.supportedSampleRates
return if (supportedSampleRates == null) {
otherSupportedSampleRates
} else if (otherSupportedSampleRates == null) {
supportedSampleRates
} else {
supportedSampleRates.union(otherSupportedSampleRates).toList()
supportedSampleRates.intersect(otherSupportedSampleRates).toList()
}
}

override val supportedByteFormats: List<Int>?
get() {
val supportedByteFormats = this@union.audio.supportedByteFormats
val supportedByteFormats = this@intersect.audio.supportedByteFormats
val otherSupportedByteFormats = other.audio.supportedByteFormats
return if (supportedByteFormats == null) {
otherSupportedByteFormats
} else if (otherSupportedByteFormats == null) {
supportedByteFormats
} else {
supportedByteFormats.union(otherSupportedByteFormats).toList()
supportedByteFormats.intersect(otherSupportedByteFormats).toList()
}
}
}
override val video = object : IEndpoint.IEndpointInfo.IVideoEndpointInfo {
override val supportedEncoders: List<String> =
this@union.video.supportedEncoders.union(other.video.supportedEncoders)
this@intersect.video.supportedEncoders.intersect(other.video.supportedEncoders.toSet())
.toList()
}
}
Expand Down

0 comments on commit 4039924

Please sign in to comment.