From 0c387fc19a3f04ee4a4c6e5e942aaeb40294d39c Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 1 Apr 2024 17:25:47 +0200 Subject: [PATCH 1/4] Fix segments list having a greater length than capacity --- transcoder/src/info.go | 3 ++- transcoder/src/stream.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/transcoder/src/info.go b/transcoder/src/info.go index 06643e02..00a969dc 100644 --- a/transcoder/src/info.go +++ b/transcoder/src/info.go @@ -1,6 +1,7 @@ package src import ( + "cmp" "encoding/json" "fmt" "io" @@ -167,7 +168,7 @@ func OrNull(str string) *string { return &str } -func Max(x, y uint32) uint32 { +func Max[T cmp.Ordered](x, y T) T { if x < y { return y } diff --git a/transcoder/src/stream.go b/transcoder/src/stream.go index 10a88ea9..abb8a2cc 100644 --- a/transcoder/src/stream.go +++ b/transcoder/src/stream.go @@ -68,7 +68,7 @@ func NewStream(file *FileStream, handle StreamHandle, ret *Stream) { ret.heads = make([]Head, 0) length, is_done := file.Keyframes.Length() - ret.segments = make([]Segment, length, 2000) + ret.segments = make([]Segment, length, Max(length, 2000)) for seg := range ret.segments { ret.segments[seg].channel = make(chan struct{}) } From 1f16271354ae2be3d9784d40208c0a9d830288f4 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 1 Apr 2024 20:53:53 +0200 Subject: [PATCH 2/4] Use duration from /info endpoint instead of player's duration --- front/packages/ui/src/player/index.tsx | 7 ++++++- front/packages/ui/src/player/state.tsx | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/front/packages/ui/src/player/index.tsx b/front/packages/ui/src/player/index.tsx index 506cdb09..e42f00bc 100644 --- a/front/packages/ui/src/player/index.tsx +++ b/front/packages/ui/src/player/index.tsx @@ -36,7 +36,7 @@ import { useRouter } from "solito/router"; import { useSetAtom } from "jotai"; import { useYoshiki } from "yoshiki/native"; import { Back, Hover, LoadingIndicator } from "./components/hover"; -import { fullscreenAtom, Video } from "./state"; +import { durationAtom, fullscreenAtom, Video } from "./state"; import { episodeDisplayNumber } from "../details/episode"; import { useVideoKeyboard } from "./keyboard"; import { MediaSessionManager } from "./media-session"; @@ -104,6 +104,11 @@ export const Player = ({ }; }, [setFullscreen]); + const setDuration = useSetAtom(durationAtom); + useEffect(() => { + setDuration(info?.durationSeconds); + }, [info, setDuration]); + if (error || infoError || playbackError) return ( <> diff --git a/front/packages/ui/src/player/state.tsx b/front/packages/ui/src/player/state.tsx index ea9781e5..ee1aa337 100644 --- a/front/packages/ui/src/player/state.tsx +++ b/front/packages/ui/src/player/state.tsx @@ -119,7 +119,6 @@ export const Video = memo(function Video({ const setPrivateProgress = useSetAtom(privateProgressAtom); const setPublicProgress = useSetAtom(publicProgressAtom); const setBuffered = useSetAtom(bufferedAtom); - const setDuration = useSetAtom(durationAtom); useEffect(() => { ref.current?.seek(publicProgress); }, [publicProgress]); @@ -217,9 +216,6 @@ export const Video = memo(function Video({ setPrivateProgress(progress.currentTime); setBuffered(progress.playableDuration); }} - onLoad={(info) => { - setDuration(info.duration); - }} onPlaybackStateChanged={(state) => setPlay(state.isPlaying)} fonts={fonts} subtitles={subtitles} From 83110374f833f1ac3b029e4eee5d04c147450818 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 1 Apr 2024 21:39:27 +0200 Subject: [PATCH 3/4] Fix login page unscrollable on web --- front/packages/ui/src/login/form.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/front/packages/ui/src/login/form.tsx b/front/packages/ui/src/login/form.tsx index b5e4f216..45267eec 100644 --- a/front/packages/ui/src/login/form.tsx +++ b/front/packages/ui/src/login/form.tsx @@ -62,6 +62,7 @@ export const FormPage = ({ {...css({ flexDirection: "row", flexGrow: 1, + flexShrink: 1, backgroundColor: (theme) => theme.dark.background, })} > From ea98598399ecf89b3cfec007f14cdcb4e5625d83 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 1 Apr 2024 22:18:44 +0200 Subject: [PATCH 4/4] Use builtin max instead of custom one --- transcoder/src/info.go | 10 +--------- transcoder/src/stream.go | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/transcoder/src/info.go b/transcoder/src/info.go index 00a969dc..75f4a80f 100644 --- a/transcoder/src/info.go +++ b/transcoder/src/info.go @@ -1,7 +1,6 @@ package src import ( - "cmp" "encoding/json" "fmt" "io" @@ -168,13 +167,6 @@ func OrNull(str string) *string { return &str } -func Max[T cmp.Ordered](x, y T) T { - if x < y { - return y - } - return x -} - var SubtitleExtensions = map[string]string{ "subrip": "srt", "ass": "ass", @@ -316,7 +308,7 @@ func getInfo(path string, route string) (*MediaInfo, error) { Link: link, } }), - Chapters: Map(make([]Chapter, Max(chapters_end-chapters_begin, 1)-1), func(_ Chapter, i int) Chapter { + Chapters: Map(make([]Chapter, max(chapters_end-chapters_begin, 1)-1), func(_ Chapter, i int) Chapter { return Chapter{ StartTime: ParseTime(mi.GetI(mediainfo.StreamMenu, 0, int(chapters_begin)+i, mediainfo.InfoName)), // +1 is safe, the value at chapters_end contains the right duration diff --git a/transcoder/src/stream.go b/transcoder/src/stream.go index abb8a2cc..c1d8f0dd 100644 --- a/transcoder/src/stream.go +++ b/transcoder/src/stream.go @@ -68,7 +68,7 @@ func NewStream(file *FileStream, handle StreamHandle, ret *Stream) { ret.heads = make([]Head, 0) length, is_done := file.Keyframes.Length() - ret.segments = make([]Segment, length, Max(length, 2000)) + ret.segments = make([]Segment, length, max(length, 2000)) for seg := range ret.segments { ret.segments[seg].channel = make(chan struct{}) }