Revamp the transcoding decision tree
This commit is contained in:
@@ -168,6 +168,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
|
|||||||
}
|
}
|
||||||
encodeOptions := encode.Options{
|
encodeOptions := encode.Options{
|
||||||
TrackPath: trackPath,
|
TrackPath: trackPath,
|
||||||
|
TrackBitrate: track.Bitrate,
|
||||||
CachePath: c.CachePath,
|
CachePath: c.CachePath,
|
||||||
ProfileName: pref.Profile,
|
ProfileName: pref.Profile,
|
||||||
PreferredBitrate: params.GetOrInt("maxBitRate", 0),
|
PreferredBitrate: params.GetOrInt("maxBitRate", 0),
|
||||||
|
|||||||
@@ -146,14 +146,6 @@ func cacheKey(sourcePath string, profileName string, profile Profile) string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBitrate checks if the client forces bitrate lower than set in profile
|
|
||||||
func getBitrate(preferred, defined int) int {
|
|
||||||
if preferred != 0 && preferred < defined {
|
|
||||||
return preferred
|
|
||||||
}
|
|
||||||
return defined
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
OnInvalidProfileFunc func() error
|
OnInvalidProfileFunc func() error
|
||||||
OnCacheHitFunc func(Profile, string) error
|
OnCacheHitFunc func(Profile, string) error
|
||||||
@@ -162,6 +154,7 @@ type (
|
|||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
TrackPath string
|
TrackPath string
|
||||||
|
TrackBitrate int
|
||||||
CachePath string
|
CachePath string
|
||||||
ProfileName string
|
ProfileName string
|
||||||
PreferredBitrate int
|
PreferredBitrate int
|
||||||
@@ -175,7 +168,20 @@ func Encode(opts Options) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return opts.OnInvalidProfile()
|
return opts.OnInvalidProfile()
|
||||||
}
|
}
|
||||||
profile.Bitrate = getBitrate(opts.PreferredBitrate, profile.Bitrate)
|
log.Printf("client requests %dk, transcoding profile %dk, track bitrate %dk \n", opts.PreferredBitrate, profile.Bitrate, opts.TrackBitrate)
|
||||||
|
if opts.PreferredBitrate != 0 && opts.PreferredBitrate >= opts.TrackBitrate {
|
||||||
|
log.Printf("Not transcoding, requested bitrate larger or equal to track bitrate \n")
|
||||||
|
return opts.OnInvalidProfile()
|
||||||
|
} else if opts.PreferredBitrate != 0 && opts.PreferredBitrate < opts.TrackBitrate {
|
||||||
|
profile.Bitrate = opts.PreferredBitrate
|
||||||
|
log.Printf("Transcoding according to client request of %dk \n", profile.Bitrate)
|
||||||
|
} else if opts.PreferredBitrate == 0 && profile.Bitrate >= opts.TrackBitrate {
|
||||||
|
log.Printf("Not transcoding, transcoding profile bitrate larger or equal to track bitrate \n")
|
||||||
|
return opts.OnInvalidProfile()
|
||||||
|
} else {
|
||||||
|
log.Printf("Transcoding according to transcoding profile of %dk \n", profile.Bitrate)
|
||||||
|
}
|
||||||
|
|
||||||
cacheKey := cacheKey(opts.TrackPath, opts.ProfileName, profile)
|
cacheKey := cacheKey(opts.TrackPath, opts.ProfileName, profile)
|
||||||
cachePath := path.Join(opts.CachePath, cacheKey)
|
cachePath := path.Join(opts.CachePath, cacheKey)
|
||||||
if fileExists(cachePath) {
|
if fileExists(cachePath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user