From 758812c69958d524dcadab8f5e89547c4edc267e Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 1 Dec 2022 13:05:19 -0800 Subject: [PATCH] Make sure max is at end --- manager.go | 11 +++++++++-- stream.go | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/manager.go b/manager.go index 390158ec..2259eb62 100644 --- a/manager.go +++ b/manager.go @@ -76,6 +76,8 @@ func NewManager(c *Config, path string, id string, close chan string) (*Manager, // Only keep streams that are smaller than the video for k, stream := range m.streams { + stream.order = 0 + // scale bitrate by frame rate with reference 30 stream.bitrate = int(float64(stream.bitrate) * float64(m.probe.FrameRate) / 30.0) @@ -94,8 +96,12 @@ func NewManager(c *Config, path string, id string, close chan string) (*Manager, // Original stream m.streams["max"] = &Stream{ - c: c, m: m, quality: "max", height: m.probe.Height, width: m.probe.Width, + c: c, m: m, + quality: "max", + height: m.probe.Height, + width: m.probe.Width, bitrate: m.probe.BitRate, + order: 1, } // Start all streams @@ -213,7 +219,8 @@ func (m *Manager) ServeIndex(w http.ResponseWriter) error { streams = append(streams, stream) } sort.Slice(streams, func(i, j int) bool { - return streams[i].bitrate < streams[j].bitrate + return streams[i].order < streams[j].order || + (streams[i].order == streams[j].order && streams[i].bitrate < streams[j].bitrate) }) // Write all streams diff --git a/stream.go b/stream.go index 6540fd5c..179be5f3 100644 --- a/stream.go +++ b/stream.go @@ -33,6 +33,7 @@ type Stream struct { c *Config m *Manager quality string + order int height int width int bitrate int