diff options
-rw-r--r-- | base/src/assetfed.rs | 10 | ||||
-rw-r--r-- | common/src/lib.rs | 2 | ||||
-rw-r--r-- | import/src/lib.rs | 13 | ||||
-rw-r--r-- | server/src/routes/ui/assets.rs | 9 | ||||
-rw-r--r-- | stream/src/lib.rs | 5 | ||||
-rw-r--r-- | web/script/player/mediacaps.ts | 6 | ||||
-rw-r--r-- | web/script/player/profiles.ts | 5 | ||||
-rw-r--r-- | web/script/player/track/mse.ts | 3 |
8 files changed, 37 insertions, 16 deletions
diff --git a/base/src/assetfed.rs b/base/src/assetfed.rs index d20446b..575188d 100644 --- a/base/src/assetfed.rs +++ b/base/src/assetfed.rs @@ -6,7 +6,7 @@ use aes_gcm_siv::{ use anyhow::{anyhow, bail, Context}; use base64::Engine; use bincode::{Decode, Encode}; -use jellycommon::Asset; +use jellycommon::{Asset, LocalTrack}; use log::warn; use serde::Serialize; use std::{path::PathBuf, sync::LazyLock}; @@ -32,6 +32,7 @@ pub enum AssetInner { Cache(CachePath), Assets(PathBuf), Media(PathBuf), + LocalTrack(LocalTrack), } impl AssetInner { @@ -77,4 +78,11 @@ impl AssetInner { pub fn is_federated(&self) -> bool { matches!(self, Self::Federated { .. }) } + + pub fn as_local_track(self) -> Option<LocalTrack> { + match self { + AssetInner::LocalTrack(x) => Some(x), + _ => None, + } + } } diff --git a/common/src/lib.rs b/common/src/lib.rs index c496cf2..d8e5d7e 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -161,7 +161,7 @@ pub enum NodeKind { #[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)] #[serde(rename_all = "snake_case")] pub enum TrackSource { - Local(LocalTrack), + Local(Asset), Remote(usize), } diff --git a/import/src/lib.rs b/import/src/lib.rs index 7d1b635..3e90e7e 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -386,11 +386,14 @@ fn import_media_file( } else { SourceTrackKind::Subtitles }, - source: TrackSource::Local(LocalTrack { - codec_private: track.codec_private, - path: path.to_owned(), - track: track.track_number as usize, - }), + source: TrackSource::Local( + AssetInner::LocalTrack(LocalTrack { + codec_private: track.codec_private, + path: path.to_owned(), + track: track.track_number as usize, + }) + .ser(), + ), }) .collect::<Vec<_>>(); diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index a925e31..cfaa68e 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -4,7 +4,7 @@ Copyright (C) 2025 metamuffin <metamuffin.org> */ use crate::routes::ui::{account::session::Session, error::MyResult, CacheControlFile}; -use anyhow::{anyhow, Context}; +use anyhow::{anyhow, bail, Context}; use base64::Engine; use jellybase::{ assetfed::AssetInner, cache::async_cache_file, database::Database, federation::Federation, CONF, @@ -56,7 +56,7 @@ pub async fn resolve_asset(asset: AssetInner) -> anyhow::Result<PathBuf> { AssetInner::Cache(c) => Ok(c.abs()), AssetInner::Assets(c) => Ok(CONF.asset_path.join(c)), AssetInner::Media(c) => Ok(CONF.media_path.join(c)), - _ => unreachable!(), + _ => bail!("wrong asset type"), } } @@ -168,7 +168,10 @@ pub async fn r_node_thumbnail( let t = (t / step).floor() * step; let asset = match thumb_track_source { - TrackSource::Local(LocalTrack { path, .. }) => { + TrackSource::Local(a) => { + let AssetInner::LocalTrack(LocalTrack { path, .. }) = AssetInner::deser(&a.0)? else { + return Err(anyhow!("track set to wrong asset type").into()); + }; // the track selected might be different from thumb_track jellytranscoder::thumbnail::create_thumbnail(&CONF.media_path.join(path), t).await? } diff --git a/stream/src/lib.rs b/stream/src/lib.rs index ca7578d..00338c1 100644 --- a/stream/src/lib.rs +++ b/stream/src/lib.rs @@ -13,6 +13,7 @@ use anyhow::{anyhow, bail, Context, Result}; use fragment::fragment_stream; use hls::{hls_master_stream, hls_variant_stream}; use jellybase::{ + assetfed::AssetInner, common::{ stream::{StreamFormat, StreamSpec}, user::{PermissionSet, UserPermission}, @@ -73,7 +74,9 @@ pub async fn stream( .ok_or(anyhow!("track does not exist"))? .source { - TrackSource::Local(t) => t.to_owned(), + TrackSource::Local(t) => AssetInner::deser(&t.0)? + .as_local_track() + .ok_or(anyhow!("asset not a track"))?, TrackSource::Remote(_) => bail!("track is not local"), }, ) diff --git a/web/script/player/mediacaps.ts b/web/script/player/mediacaps.ts index 61ad398..e44b92b 100644 --- a/web/script/player/mediacaps.ts +++ b/web/script/player/mediacaps.ts @@ -107,9 +107,9 @@ const FFMPEG_ENCODER_CODEC_MAP: { [key: string]: string } = { export type TrackKind = "audio" | "video" | "subtitles" export function get_track_kind(track: SourceTrackKind): TrackKind { - //@ts-ignore // TODO clean this mess up please - // TODO why is the subtitle encoded diffenrently sometimes?! - if (track == "subtitles" || track["subtitles"]) return "subtitles" + // TODO why different encodings for "subtitles"? + if (track == "subtitles") return "subtitles" + if ("subtitles" in track) return "subtitles" if ("audio" in track) return "audio" if ("video" in track) return "video" throw new Error("invalid track"); diff --git a/web/script/player/profiles.ts b/web/script/player/profiles.ts index 3344ef6..5ebdeb4 100644 --- a/web/script/player/profiles.ts +++ b/web/script/player/profiles.ts @@ -5,7 +5,8 @@ */ /// <reference lib="dom" /> import { OVar } from "../jshelper/mod.ts"; -import { EncodingProfile } from "./jhls.d.ts"; +import { EncodingProfile, SourceTrackKind } from "./jhls.d.ts"; +import { get_track_kind } from "./mediacaps.ts"; import { profile_to_partial_track, test_media_capability } from "./mediacaps.ts"; import { Player } from "./player.ts"; import { MSEPlayerTrack } from "./track/mse.ts"; @@ -27,6 +28,8 @@ export class ProfileSelector { async init() { for (let id = 0; id < this.track.index!.extra_profiles.length; id++) { const p = this.track.index!.extra_profiles[id]; + // TODO hacky type casting solution + if (get_track_kind(this.track.metadata.kind) != get_track_kind(p as unknown as SourceTrackKind)) continue if (!await test_media_capability(profile_to_partial_track(p))) continue this.profiles.push({ id, order: 0, ...p }) } diff --git a/web/script/player/track/mse.ts b/web/script/player/track/mse.ts index 5d1842f..ec036b4 100644 --- a/web/script/player/track/mse.ts +++ b/web/script/player/track/mse.ts @@ -25,7 +25,7 @@ export class MSEPlayerTrack extends PlayerTrack { private player: Player, private node_id: string, track_index: number, - private metadata: SourceTrack, + public metadata: SourceTrack, ) { super(track_index); this.profile_selector = new ProfileSelector(player, this, player.downloader.bandwidth_avail); @@ -147,6 +147,7 @@ export class MSEPlayerTrack extends PlayerTrack { this.current_load = frag; // TODO why is appending so unreliable?! sometimes it does not add it this.source_buffer.changeType(track_to_content_type(this.track_from_profile())!); + this.source_buffer.timestampOffset = this.profile ? frag.start : 0 console.log(`append track ${this.track_index}`); this.source_buffer.appendBuffer(frag.buf); } |