This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
a9f7ddc
commit 81f5353
Showing
13 changed files
with
219 additions
and
95 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
35 changes: 35 additions & 0 deletions
35
src/commonMain/kotlin/cinterop/mpv/LibMpvClient.kt.disabled
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,35 @@ | ||
package cinterop.mpv | ||
|
||
import spms.player.Player | ||
import kotlinx.cinterop.CPrimitiveVar | ||
import kotlinx.cinterop.MemScope | ||
import kotlin.reflect.KClass | ||
|
||
typealias MpvFormat = Unit | ||
|
||
class mpv_event { | ||
val event_id: Int get() = throw NotImplementedError() | ||
} | ||
|
||
abstract class LibMpvClient(val headless: Boolean = true): Player { | ||
companion object { | ||
fun isAvailable(): Boolean = false | ||
} | ||
|
||
init { | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun release() { throw NotImplementedError() } | ||
|
||
protected fun runCommand(name: String, vararg args: Any?, check_result: Boolean = true): Int = throw NotImplementedError() | ||
protected inline fun <reified V> getProperty(name: String): V = throw NotImplementedError() | ||
protected inline fun <reified T: Any> setProperty(name: String, value: T) { throw NotImplementedError() } | ||
protected fun observeProperty(name: String, cls: KClass<*>) { throw NotImplementedError() } | ||
protected inline fun <reified T> MemScope.getPointerOf(v: T? = null): CPrimitiveVar = throw NotImplementedError() | ||
protected fun getFormatOf(cls: KClass<*>): MpvFormat = throw NotImplementedError() | ||
protected fun waitForEvent(): mpv_event? = throw NotImplementedError() | ||
protected fun requestLogMessages() { throw NotImplementedError() } | ||
protected fun addHook(name: String, priority: Int = 0) { throw NotImplementedError() } | ||
protected fun continueHook(id: ULong) { throw NotImplementedError() } | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/commonMain/kotlin/cinterop/mpv/MpvClientEventLoop.kt.disabled
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,5 @@ | ||
package cinterop.mpv | ||
|
||
internal suspend fun MpvClientImpl.eventLoop() { | ||
throw NotImplementedError() | ||
} |
70 changes: 70 additions & 0 deletions
70
src/commonMain/kotlin/cinterop/mpv/MpvClientEventLoop.kt.enabled
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,70 @@ | ||
package cinterop.mpv | ||
|
||
import libmpv.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.serialization.json.JsonPrimitive | ||
import spms.server.SpMs | ||
import spms.socketapi.shared.SpMsPlayerEvent | ||
import cinterop.utils.safeToKString | ||
import kotlinx.cinterop.* | ||
|
||
internal suspend fun MpvClientImpl.eventLoop() = withContext(Dispatchers.IO) { | ||
while (true) { | ||
val event: mpv_event? = waitForEvent() | ||
|
||
when (event?.event_id) { | ||
MPV_EVENT_START_FILE -> { | ||
val data: mpv_event_start_file = event.data.pointedAs() | ||
if (data.playlist_entry_id.toInt() != current_item_playlist_id) { | ||
continue | ||
} | ||
|
||
onEvent(SpMsPlayerEvent.ItemTransition(current_item_index), clientless = true) | ||
} | ||
MPV_EVENT_PLAYBACK_RESTART -> { | ||
onEvent(SpMsPlayerEvent.PropertyChanged("state", JsonPrimitive(state.ordinal)), clientless = true) | ||
onEvent(SpMsPlayerEvent.PropertyChanged("duration_ms", JsonPrimitive(duration_ms)), clientless = true) | ||
onEvent(SpMsPlayerEvent.SeekedToTime(current_position_ms), clientless = true) | ||
} | ||
MPV_EVENT_END_FILE -> { | ||
onEvent(SpMsPlayerEvent.PropertyChanged("state", JsonPrimitive(state.ordinal)), clientless = true) | ||
} | ||
MPV_EVENT_FILE_LOADED -> { | ||
onEvent(SpMsPlayerEvent.ReadyToPlay(), clientless = true) | ||
|
||
song_initial_seek_position_ms?.also { position_ms -> | ||
seekToTime(position_ms) | ||
song_initial_seek_position_ms = null | ||
} | ||
} | ||
MPV_EVENT_SHUTDOWN -> { | ||
onShutdown() | ||
} | ||
MPV_EVENT_PROPERTY_CHANGE -> { | ||
val data: mpv_event_property = event.data.pointedAs() | ||
|
||
when (data.name?.safeToKString()) { | ||
"core-idle" -> { | ||
val playing: Boolean = !data.data.pointedAs<BooleanVar>().value | ||
onEvent(SpMsPlayerEvent.PropertyChanged("is_playing", JsonPrimitive(playing)), clientless = true) | ||
} | ||
} | ||
} | ||
|
||
MPV_EVENT_HOOK -> { | ||
val data: mpv_event_hook = event.data.pointedAs() | ||
launch { | ||
onMpvHook(data.name?.safeToKString(), data.id) | ||
} | ||
} | ||
|
||
MPV_EVENT_LOG_MESSAGE -> { | ||
if (SpMs.logging_enabled) { | ||
val message: mpv_event_log_message = event.data.pointedAs() | ||
SpMs.log("From mpv (${message.prefix?.safeToKString()}): ${message.text?.safeToKString()}") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.