diff --git a/cache/transcoding.go b/cache/transcoding.go index 8a664c97a..f1b7d4805 100644 --- a/cache/transcoding.go +++ b/cache/transcoding.go @@ -2,6 +2,8 @@ package cache import ( "sync" + + "github.com/livepeer/catalyst-api/clients" ) type TranscodingCache struct { @@ -25,10 +27,11 @@ type EncodedProfile struct { type SegmentInfo struct { CallbackUrl string - Source string // S3 input we are transcoding - UploadDir string // S3 destination url for multiple renditions - Profiles []EncodedProfile // Requested encoding profiles to produce - Destinations []string // Rendition URLS go here on push start and removed on push end + Source string // S3 input we are transcoding + UploadDir string // S3 destination url for multiple renditions + Profiles []EncodedProfile // Requested encoding profiles to produce + Destinations []string // Rendition URLS go here on push start and removed on push end + Outputs []clients.OutputVideo // Information about the final transcoded outputs we've created } func (si SegmentInfo) ContainsDestination(destination string) bool { diff --git a/handlers/misttriggers/live_tracklist.go b/handlers/misttriggers/live_tracklist.go index 8397e84c7..e76564f92 100644 --- a/handlers/misttriggers/live_tracklist.go +++ b/handlers/misttriggers/live_tracklist.go @@ -1,6 +1,8 @@ package misttriggers import ( + "bytes" + "context" "encoding/json" "fmt" "log" @@ -9,16 +11,13 @@ import ( "sort" "strconv" "strings" - - "bytes" - "context" "time" - "github.com/livepeer/go-tools/drivers" - "github.com/livepeer/catalyst-api/cache" + "github.com/livepeer/catalyst-api/clients" "github.com/livepeer/catalyst-api/config" "github.com/livepeer/catalyst-api/errors" + "github.com/livepeer/go-tools/drivers" ) type MistTrack struct { @@ -60,13 +59,10 @@ func (a ByBitrate) Swap(i, j int) { } func createPlaylist(multivariantPlaylist string, tracks []MistTrack) string { - for _, track := range tracks { multivariantPlaylist += fmt.Sprintf("#EXT-X-STREAM-INF:BANDWIDTH=%d,RESOLUTION=%dx%d\r\n%s\r\n", track.ByteRate*8, track.Width, track.Height, track.manifestDestPath) - } return multivariantPlaylist - } func uploadPlaylist(uploadPath, manifest string) error { @@ -181,9 +177,17 @@ func (d *MistCallbackHandlersCollection) TriggerLiveTrackList(w http.ResponseWri // Generate a sorted list for multivariant playlist (reverse order of bitrate then resolution): sort.Sort(sort.Reverse(ByBitrate(trackList))) manifest := createPlaylist(multivariantPlaylist, trackList) - err = uploadPlaylist(fmt.Sprintf("%s/%s-master.m3u8", rootPathUrl.String(), uniqueName), manifest) + path := fmt.Sprintf("%s/%s-master.m3u8", rootPathUrl.String(), uniqueName) + err = uploadPlaylist(path, manifest) if err != nil { errors.WriteHTTPInternalServerError(w, "Failed to upload multivariant master playlist: "+streamName, err) return } + + // Store the path back into our cached object to allow us to populate the final "Transcode Success" metadata callback + info.Outputs = append(info.Outputs, clients.OutputVideo{ + Type: "google-s3", // TODO: Stop hardcoding this once we support other schemes + Manifest: path, + }) + cache.DefaultStreamCache.Transcoding.Store(streamName, *info) } diff --git a/handlers/misttriggers/triggers.go b/handlers/misttriggers/triggers.go index 87870c18b..a98f44df1 100644 --- a/handlers/misttriggers/triggers.go +++ b/handlers/misttriggers/triggers.go @@ -33,6 +33,11 @@ func (d *MistCallbackHandlersCollection) Trigger() httprouter.Handle { } triggerName := req.Header.Get("X-Trigger") + _ = config.Logger.Log( + "msg", "Received Mist Trigger", + "trigger_name", triggerName, + ) + switch triggerName { case TRIGGER_PUSH_OUT_START: d.TriggerPushOutStart(w, req, payload) diff --git a/handlers/transcode.go b/handlers/transcode.go index 03b18225e..ea78ff48c 100644 --- a/handlers/transcode.go +++ b/handlers/transcode.go @@ -142,6 +142,11 @@ func RunTranscodeProcess(mistClient clients.MistAPIClient, request TranscodeSegm return fmt.Errorf("failed to unmarshal source stream info json: %s", err) } + segmentInfo := cache.DefaultStreamCache.Transcoding.Get(renditionsStream) + if segmentInfo == nil { + return fmt.Errorf("failed to fetch ID %q from stream cache when building SendTranscodeStatusCompleted message", renditionsStream) + } + err = clients.DefaultCallbackClient.SendTranscodeStatusCompleted( request.CallbackUrl, clients.InputVideo{ @@ -172,19 +177,7 @@ func RunTranscodeProcess(mistClient clients.MistAPIClient, request TranscodeSegm }, }, }, - []clients.OutputVideo{ - { - Type: "google-s4", - Manifest: "s4://livepeer-studio-uploads/videos//master.m3u8", - Videos: []clients.OutputVideoFile{ - { - Type: "mp5", - SizeBytes: 12346, - Location: "s4://livepeer-studio-uploads/videos//video-480p.mp4", - }, - }, - }, - }, + segmentInfo.Outputs, ) if err != nil { _ = config.Logger.Log("msg", "Error sending Transcode Completed in stubTranscodingCallbacksForStudio", "err", err)