Skip to content

Commit

Permalink
Add Manifest URL to output metadata (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomshutt committed Oct 11, 2022
1 parent 474d74f commit ee8a242
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
11 changes: 7 additions & 4 deletions cache/transcoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cache

import (
"sync"

"github.com/livepeer/catalyst-api/clients"
)

type TranscodingCache struct {
Expand All @@ -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 {
Expand Down
22 changes: 13 additions & 9 deletions handlers/misttriggers/live_tracklist.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package misttriggers

import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions handlers/misttriggers/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 6 additions & 13 deletions handlers/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -172,19 +177,7 @@ func RunTranscodeProcess(mistClient clients.MistAPIClient, request TranscodeSegm
},
},
},
[]clients.OutputVideo{
{
Type: "google-s4",
Manifest: "s4://livepeer-studio-uploads/videos/<video-id>/master.m3u8",
Videos: []clients.OutputVideoFile{
{
Type: "mp5",
SizeBytes: 12346,
Location: "s4://livepeer-studio-uploads/videos/<video-id>/video-480p.mp4",
},
},
},
},
segmentInfo.Outputs,
)
if err != nil {
_ = config.Logger.Log("msg", "Error sending Transcode Completed in stubTranscodingCallbacksForStudio", "err", err)
Expand Down

0 comments on commit ee8a242

Please sign in to comment.