Skip to content

Commit

Permalink
Merge branch 'main' into end-transcoding-dtsh-percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
thomshutt committed Nov 9, 2022
2 parents 6cfba7d + 7fc95eb commit 4fe313e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
17 changes: 9 additions & 8 deletions handlers/misttriggers/recording_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ func (d *MistCallbackHandlersCollection) triggerRecordingEndSegmenting(w http.Re
return
}

// When createDtsh() completes issue another callback signaling to studio playback is ready
defer func() {
// Send the success callback
err = clients.DefaultCallbackClient.SendTranscodeStatusCompleted(transcodeRequest.CallbackURL, inputInfo, outputs)
if err != nil {
log.LogError(transcodeRequest.RequestID, "Failed to send TranscodeStatusCompleted callback", err, "url", transcodeRequest.CallbackURL)
}
}()

// prepare .dtsh headers for all rendition playlists
for _, output := range outputs {
// output is multivariant playlist
Expand All @@ -152,14 +161,6 @@ func (d *MistCallbackHandlersCollection) triggerRecordingEndSegmenting(w http.Re
// should not block the ingestion flow or make it fail on error.
log.LogError(requestID, "master createDtsh() failed", err, "destination", output.Manifest)
}
for _, rendition := range output.Videos {
// we create dtsh for all rendition playlists
err := createDtsh(requestID, rendition.Location)
if err != nil {
// should not block the ingestion flow or make it fail on error.
log.LogError(requestID, "createDtsh() failed", err, "destination", rendition.Location)
}
}
}

}()
Expand Down
2 changes: 1 addition & 1 deletion transcode/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GetSourceSegmentURLs(sourceManifestURL string, manifest m3u8.MediaPlaylist)

// Generate a Master manifest, plus one Rendition manifest for each Profile we're transcoding, then write them to storage
// Returns the master manifest URL on success
func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL string, transcodedStats []RenditionStats) (string, error) {
func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL string, transcodedStats []*RenditionStats) (string, error) {
// Generate the master + rendition output manifests
masterPlaylist := m3u8.NewMasterPlaylist()

Expand Down
4 changes: 2 additions & 2 deletions transcode/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestItCanGenerateAndWriteManifests(t *testing.T) {
masterManifestURL, err := GenerateAndUploadManifests(
*sourceMediaPlaylist,
outputDir,
[]RenditionStats{
[]*RenditionStats{
{
Name: "lowlowlow",
FPS: 60,
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestCompliantMasterManifestOrdering(t *testing.T) {
_, err = GenerateAndUploadManifests(
*sourceMediaPlaylist,
outputDir,
[]RenditionStats{
[]*RenditionStats{
{
Name: "lowlowlow",
FPS: 60,
Expand Down
13 changes: 4 additions & 9 deletions transcode/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,11 @@ func RunTranscodeProcess(transcodeRequest TranscodeSegmentRequest, streamName st
output.Videos = append(output.Videos, clients.OutputVideoFile{Location: rendition.ManifestLocation})
}
outputs = []clients.OutputVideo{output}
// Send the success callback
err = clients.DefaultCallbackClient.SendTranscodeStatusCompleted(transcodeRequest.CallbackURL, inputInfo, outputs)
if err != nil {
log.LogError(transcodeRequest.RequestID, "Failed to send TranscodeStatusCompleted callback", err, "url", transcodeRequest.CallbackURL)
}
// Return outputs for .dtsh file creation
return outputs, nil
}

func transcodeSegment(segment segmentInfo, streamName, manifestID string, transcodeRequest TranscodeSegmentRequest, transcodeProfiles []clients.EncodedProfile, targetOSURL *url.URL, transcodedStats []RenditionStats) error {
func transcodeSegment(segment segmentInfo, streamName, manifestID string, transcodeRequest TranscodeSegmentRequest, transcodeProfiles []clients.EncodedProfile, targetOSURL *url.URL, transcodedStats []*RenditionStats) error {
rc, err := clients.DownloadOSURL(segment.Input.URL)
if err != nil {
return fmt.Errorf("failed to download source segment %q: %s", segment.Input, err)
Expand Down Expand Up @@ -312,10 +307,10 @@ type segmentInfo struct {
Index int
}

func statsFromProfiles(profiles []clients.EncodedProfile) []RenditionStats {
stats := []RenditionStats{}
func statsFromProfiles(profiles []clients.EncodedProfile) []*RenditionStats {
stats := []*RenditionStats{}
for _, profile := range profiles {
stats = append(stats, RenditionStats{
stats = append(stats, &RenditionStats{
Name: profile.Name,
Width: profile.Width, // TODO: extract this from actual media retrieved from B
Height: profile.Height, // TODO: extract this from actual media retrieved from B
Expand Down
26 changes: 16 additions & 10 deletions transcode/transcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"path"
"path/filepath"
"strconv"
"testing"
Expand Down Expand Up @@ -103,7 +104,7 @@ func TestItCanTranscode(t *testing.T) {
}

// Check we don't get an error downloading or parsing it
_, err = RunTranscodeProcess(
outputs, err := RunTranscodeProcess(
TranscodeSegmentRequest{
CallbackURL: callbackServer.URL,
UploadURL: manifestFile.Name(),
Expand All @@ -124,24 +125,29 @@ func TestItCanTranscode(t *testing.T) {
require.NoError(t, err)

// Confirm the master manifest was created and that it looks like a manifest
var expectedMasterManifest = `#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=28800,RESOLUTION=2020x2020,NAME="0-2020p0"
2020p0/index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=19200,RESOLUTION=2020x2020,NAME="1-low-bitrate"
low-bitrate/index.m3u8
`

masterManifestBytes, err := os.ReadFile(filepath.Join(topLevelDir, "index.m3u8"))

require.NoError(t, err)
require.Greater(t, len(masterManifestBytes), 0)
require.Contains(t, string(masterManifestBytes), "#EXTM3U")
require.Contains(t, string(masterManifestBytes), "#EXT-X-STREAM-INF")

// Confirm that the master manifest contains links to 2 renditions
require.Contains(t, string(masterManifestBytes), "low-bitrate/index.m3u8")
require.Contains(t, string(masterManifestBytes), "2020p0/index.m3u8")
require.Equal(t, expectedMasterManifest, string(masterManifestBytes))

// Check we received a progress callback for each segment
require.Equal(t, 3, len(callbacks))
require.Equal(t, 2, len(callbacks))
require.Equal(t, 0.65, callbacks[0]["completion_ratio"])
require.Equal(t, 0.9, callbacks[1]["completion_ratio"])

// Check we received a final Transcode Completed callback
require.Equal(t, 1.0, callbacks[2]["completion_ratio"])
require.Equal(t, "success", callbacks[2]["status"])
require.Equal(t, 1, len(outputs))
require.Equal(t, path.Join(topLevelDir, "index.m3u8"), outputs[0].Manifest)
require.Equal(t, 2, len(outputs[0].Videos))
}

func TestItCalculatesTheTranscodeCompletionPercentageCorrectly(t *testing.T) {
Expand Down

0 comments on commit 4fe313e

Please sign in to comment.