feat: open streaming URLs without changing resolved handoffs
This commit is contained in:
@@ -6,13 +6,13 @@ struct ResolvedPlaybackCheck {
|
||||
static func require(_ condition: @autoclosure () -> Bool, _ message: String) {
|
||||
if !condition() { fatalError("FAIL: " + message) }
|
||||
}
|
||||
static func until(_ message: String, model: PlayerModel, _ predicate: () -> Bool) {
|
||||
static func until(_ message: String, model: PlayerModel, _ predicate: () -> Bool) async throws {
|
||||
let deadline = ContinuousClock.now.advanced(by: .seconds(45))
|
||||
while !predicate(), ContinuousClock.now < deadline {
|
||||
if model.state.status == PLAYER_ERROR || model.commandError != nil {
|
||||
fatalError("FAIL: " + (model.errorText ?? "Playback failed"))
|
||||
}
|
||||
RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.01))
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
require(predicate(), message)
|
||||
}
|
||||
@@ -24,21 +24,31 @@ struct ResolvedPlaybackCheck {
|
||||
static func run() async throws {
|
||||
_ = NSApplication.shared
|
||||
NSApp.setActivationPolicy(.prohibited)
|
||||
let file = URL(fileURLWithPath: CommandLine.arguments[1])
|
||||
let source = try ResolvedSource.load(from: file)
|
||||
let input = CommandLine.arguments[1]
|
||||
let file = URL(fileURLWithPath: input)
|
||||
let source: ResolvedSource
|
||||
if input.hasPrefix("https://") {
|
||||
guard case .miruro(let mediaID, let episode) = try StreamURL.parse(input) else {
|
||||
fatalError("FAIL: URL smoke requires a Miruro episode")
|
||||
}
|
||||
source = try await MiruroResolver.resolve(mediaID: mediaID, episode: episode)
|
||||
} else {
|
||||
source = try ResolvedSource.load(from: file)
|
||||
}
|
||||
let suite = "terebi.resolved-check." + UUID().uuidString
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
defer { defaults.removePersistentDomain(forName: suite) }
|
||||
let model = PlayerModel(defaults: defaults, progressFile: CommandLine.arguments.count > 2 ? CommandLine.arguments[2] : nil)
|
||||
defer { model.shutdown() }
|
||||
model.openResolvedSource(file)
|
||||
until("video/audio decode and advancing playback", model: model) {
|
||||
if input.hasPrefix("https://") { model.openStream(input) }
|
||||
else { model.openResolvedSource(file) }
|
||||
try await until("video/audio decode and advancing playback", model: model) {
|
||||
model.state.status == PLAYER_PLAYING && model.state.has_video && model.state.has_audio && model.state.position > 0.2
|
||||
}
|
||||
print("PASS: resolved HLS decodes video/audio and advances")
|
||||
fflush(stdout)
|
||||
require(model.setPlayback(playing: false), "pause accepted")
|
||||
until("pause acknowledged", model: model) { model.state.status == PLAYER_PAUSED }
|
||||
try await until("pause acknowledged", model: model) { model.state.status == PLAYER_PAUSED }
|
||||
require(model.state.can_seek && model.state.duration > 0, "seekable measured duration")
|
||||
guard let index = source.subtitles.firstIndex(where: \.isDefault) else {
|
||||
fatalError("FAIL: smoke requires a default subtitle")
|
||||
@@ -50,14 +60,14 @@ struct ResolvedPlaybackCheck {
|
||||
let target = playableCues[1].start + min(0.1, (playableCues[1].end - playableCues[1].start) / 2)
|
||||
require(!document.text(at: target).isEmpty, "forward seek targets a visible English cue")
|
||||
require(model.seekRelative(target - model.state.position), "seek accepted")
|
||||
until("seek acknowledged and subtitle synchronized", model: model) {
|
||||
try await until("seek acknowledged and subtitle synchronized", model: model) {
|
||||
!model.state.seek_pending && abs(model.state.position - target) < 0.2 &&
|
||||
model.subtitleText == document.text(at: model.state.position) && model.subtitleError == nil
|
||||
}
|
||||
require(model.selectedSubtitle == index && model.subtitleTracks[index].label == track.label, "default selection and label retained")
|
||||
let backward = playableCues[0].start + min(0.1, (playableCues[0].end - playableCues[0].start) / 2)
|
||||
require(model.seekRelative(backward - model.state.position), "backward seek accepted")
|
||||
until("backward seek subtitle synchronized", model: model) {
|
||||
try await until("backward seek subtitle synchronized", model: model) {
|
||||
!model.state.seek_pending && abs(model.state.position - backward) < 0.2 &&
|
||||
model.subtitleText == document.text(at: model.state.position)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user