Allow selection of different stream variants in the player (#815)
* WIP video quality selector * The quality selector works even though it is not pretty * Support getting and setting variant name. Closes #743 * Sort video qualities * Fix odd looking selected states of menubutton items * Fix comment
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
package models
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// StreamOutputVariant defines the output specifics of a single HLS stream variant.
|
||||
type StreamOutputVariant struct {
|
||||
// Name is an optional human-readable label for this stream output.
|
||||
Name string `json:"name"`
|
||||
|
||||
// Enable passthrough to copy the video and/or audio directly from the
|
||||
// incoming stream and disable any transcoding. It will ignore any of
|
||||
// the below settings.
|
||||
@@ -76,6 +83,43 @@ func (q *StreamOutputVariant) GetIsAudioPassthrough() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// GetName will return the human readable name for this stream output.
|
||||
func (q *StreamOutputVariant) GetName() string {
|
||||
bitrate := getBitrateString(q.VideoBitrate)
|
||||
|
||||
if q.Name != "" {
|
||||
return q.Name
|
||||
} else if q.IsVideoPassthrough {
|
||||
return "Source"
|
||||
} else if q.ScaledHeight == 720 && q.ScaledWidth == 1080 {
|
||||
return fmt.Sprintf("720p @%s", bitrate)
|
||||
} else if q.ScaledHeight == 1080 && q.ScaledWidth == 1920 {
|
||||
return fmt.Sprintf("1080p @%s", bitrate)
|
||||
} else if q.ScaledHeight != 0 {
|
||||
return fmt.Sprintf("%dh", q.ScaledHeight)
|
||||
} else if q.ScaledWidth != 0 {
|
||||
return fmt.Sprintf("%dw", q.ScaledWidth)
|
||||
} else {
|
||||
return fmt.Sprintf("%s@%dfps", bitrate, q.Framerate)
|
||||
}
|
||||
}
|
||||
|
||||
func getBitrateString(bitrate int) string {
|
||||
if bitrate == 0 {
|
||||
return ""
|
||||
} else if bitrate < 1000 {
|
||||
return fmt.Sprintf("%dKbps", bitrate)
|
||||
} else if bitrate >= 1000 {
|
||||
if math.Mod(float64(bitrate), 1000) == 0 {
|
||||
return fmt.Sprintf("%dMbps", bitrate/1000.0)
|
||||
} else {
|
||||
return fmt.Sprintf("%.1fMbps", float32(bitrate)/1000.0)
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// MarshalJSON is a custom JSON marshal function for video stream qualities.
|
||||
func (q *StreamOutputVariant) MarshalJSON() ([]byte, error) {
|
||||
type Alias StreamOutputVariant
|
||||
|
||||
Reference in New Issue
Block a user