Skip to content

Commit

Permalink
Fix segments list having a greater length than capacity (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya committed Apr 1, 2024
2 parents 7d423bb + ea98598 commit 266caa3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions front/packages/ui/src/login/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const FormPage = ({
{...css({
flexDirection: "row",
flexGrow: 1,
flexShrink: 1,
backgroundColor: (theme) => theme.dark.background,
})}
>
Expand Down
7 changes: 6 additions & 1 deletion front/packages/ui/src/player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -104,6 +104,11 @@ export const Player = ({
};
}, [setFullscreen]);

const setDuration = useSetAtom(durationAtom);
useEffect(() => {
setDuration(info?.durationSeconds);
}, [info, setDuration]);

if (error || infoError || playbackError)
return (
<>
Expand Down
4 changes: 0 additions & 4 deletions front/packages/ui/src/player/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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}
Expand Down
9 changes: 1 addition & 8 deletions transcoder/src/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ func OrNull(str string) *string {
return &str
}

func Max(x, y uint32) uint32 {
if x < y {
return y
}
return x
}

var SubtitleExtensions = map[string]string{
"subrip": "srt",
"ass": "ass",
Expand Down Expand Up @@ -315,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
Expand Down
2 changes: 1 addition & 1 deletion transcoder/src/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
Expand Down

0 comments on commit 266caa3

Please sign in to comment.