-
-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73626e1
commit 280db35
Showing
27 changed files
with
204 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.jellyfin.playback.core.element | ||
|
||
/** | ||
* A key to identify the type of an element. | ||
*/ | ||
class ElementKey<T : Any>(val name: String) { | ||
override fun toString(): String = "ElementKey $name" | ||
} |
26 changes: 26 additions & 0 deletions
26
playback/core/src/main/kotlin/element/ElementsContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.jellyfin.playback.core.element | ||
|
||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
/** | ||
* Container to hold elements identified with an [ElementKey]. | ||
*/ | ||
open class ElementsContainer { | ||
private val elements = ConcurrentHashMap<ElementKey<*>, Any?>() | ||
|
||
fun <T : Any> get(key: ElementKey<T>): T = getOrNull(key) | ||
?: error("No element found for key $key.") | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T : Any> getOrNull(key: ElementKey<T>): T? = elements[key] as T? | ||
|
||
operator fun <T : Any> contains(key: ElementKey<T>): Boolean = elements.containsKey(key) | ||
|
||
fun <T : Any> put(key: ElementKey<T>, value: T) { | ||
elements[key] = value | ||
} | ||
|
||
fun <T : Any> remove(key: ElementKey<T>) { | ||
elements.remove(key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jellyfin.playback.core.element | ||
|
||
import kotlin.properties.ReadWriteProperty | ||
import kotlin.reflect.KProperty | ||
|
||
/** | ||
* Delegate for an optional element. | ||
*/ | ||
fun <T : Any> element( | ||
key: ElementKey<T> | ||
) = object : ReadWriteProperty<ElementsContainer, T?> { | ||
override fun getValue(thisRef: ElementsContainer, property: KProperty<*>): T? = | ||
thisRef.getOrNull(key) | ||
|
||
override fun setValue(thisRef: ElementsContainer, property: KProperty<*>, value: T?) { | ||
if (value == null) thisRef.remove(key) | ||
else thisRef.put(key, value) | ||
} | ||
} | ||
|
||
/** | ||
* Delegate for an required element. | ||
*/ | ||
fun <T : Any> requiredElement( | ||
key: ElementKey<T>, | ||
computeDefault: () -> T, | ||
) = object : ReadWriteProperty<ElementsContainer, T> { | ||
override fun getValue(thisRef: ElementsContainer, property: KProperty<*>): T { | ||
val value = thisRef.getOrNull(key) | ||
if (value != null) return value | ||
|
||
val default = computeDefault() | ||
thisRef.put(key, default) | ||
return default | ||
} | ||
|
||
override fun setValue(thisRef: ElementsContainer, property: KProperty<*>, value: T) { | ||
thisRef.put(key, value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
playback/core/src/main/kotlin/mediastream/MediaStreamResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.jellyfin.playback.core.queue | ||
|
||
import org.jellyfin.playback.core.element.ElementsContainer | ||
|
||
/** | ||
* The QueueEntry is a single item in a queue and can represent any supported media type. | ||
* All related data is stored in elements via the [ElementsContainer]. | ||
*/ | ||
class QueueEntry : ElementsContainer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.