Skip to content

Commit

Permalink
Add ImageOutput to egress EncodedOutput utils (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben authored Feb 26, 2024
1 parent 3339e80 commit 6e689b5
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 12 deletions.
32 changes: 20 additions & 12 deletions egress/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
OutputTypeFile = "file"
OutputTypeStream = "stream"
OutputTypeSegments = "segments"
OutputTypeImages = "images"
OutputTypeMultiple = "multiple"

Unknown = "unknown"
Expand All @@ -35,6 +36,7 @@ type EncodedOutput interface {
GetFileOutputs() []*livekit.EncodedFileOutput
GetStreamOutputs() []*livekit.StreamOutput
GetSegmentOutputs() []*livekit.SegmentedFileOutput
GetImageOutputs() []*livekit.ImageOutput
}

type EncodedOutputDeprecated interface {
Expand Down Expand Up @@ -70,20 +72,26 @@ func GetTypes(request interface{}) (string, string) {
}

func GetOutputType(req EncodedOutput) string {
hasFile := len(req.GetFileOutputs()) > 0
hasStream := len(req.GetStreamOutputs()) > 0
hasSegments := len(req.GetSegmentOutputs()) > 0
outputs := make([]string, 0)
if len(req.GetFileOutputs()) > 0 {
outputs = append(outputs, OutputTypeFile)
}
if len(req.GetStreamOutputs()) > 0 {
outputs = append(outputs, OutputTypeStream)
}
if len(req.GetSegmentOutputs()) > 0 {
outputs = append(outputs, OutputTypeSegments)
}
if len(req.GetImageOutputs()) > 0 {
outputs = append(outputs, OutputTypeImages)
}

switch {
case (hasFile && (hasStream || hasSegments)) || (hasStream && hasSegments):
return OutputTypeMultiple
case hasFile:
return OutputTypeFile
case hasStream:
return OutputTypeStream
case hasSegments:
return OutputTypeSegments
switch len(outputs) {
default:
return OutputTypeMultiple
case 1:
return outputs[0]
case 0:
if r, ok := req.(EncodedOutputDeprecated); ok {
if r.GetFile() != nil {
return OutputTypeFile
Expand Down
81 changes: 81 additions & 0 deletions egress/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package egress

import (
"testing"

"github.com/livekit/protocol/livekit"
"github.com/stretchr/testify/require"
)

func TestGetOutputType(t *testing.T) {
roomReq := &livekit.RoomCompositeEgressRequest{
FileOutputs: []*livekit.EncodedFileOutput{
&livekit.EncodedFileOutput{},
},
}

ot := GetOutputType(roomReq)
require.Equal(t, OutputTypeFile, ot)

roomReq = &livekit.RoomCompositeEgressRequest{
Output: &livekit.RoomCompositeEgressRequest_File{
File: &livekit.EncodedFileOutput{},
},
}

ot = GetOutputType(roomReq)
require.Equal(t, OutputTypeFile, ot)

trackReq := &livekit.TrackCompositeEgressRequest{
SegmentOutputs: []*livekit.SegmentedFileOutput{
&livekit.SegmentedFileOutput{},
},
}

ot = GetOutputType(trackReq)
require.Equal(t, OutputTypeSegments, ot)

trackReq = &livekit.TrackCompositeEgressRequest{
Output: &livekit.TrackCompositeEgressRequest_Segments{
Segments: &livekit.SegmentedFileOutput{},
},
}

ot = GetOutputType(trackReq)
require.Equal(t, OutputTypeSegments, ot)

webReq := &livekit.WebEgressRequest{
StreamOutputs: []*livekit.StreamOutput{
&livekit.StreamOutput{},
},
}

ot = GetOutputType(webReq)
require.Equal(t, OutputTypeStream, ot)

webReq = &livekit.WebEgressRequest{
Output: &livekit.WebEgressRequest_Stream{
Stream: &livekit.StreamOutput{},
},
}

ot = GetOutputType(webReq)
require.Equal(t, OutputTypeStream, ot)

participantReq := &livekit.ParticipantEgressRequest{
ImageOutputs: []*livekit.ImageOutput{
&livekit.ImageOutput{},
},
}

ot = GetOutputType(participantReq)
require.Equal(t, OutputTypeImages, ot)

participantReq.SegmentOutputs = []*livekit.SegmentedFileOutput{
&livekit.SegmentedFileOutput{},
}

ot = GetOutputType(participantReq)
require.Equal(t, OutputTypeMultiple, ot)

}

0 comments on commit 6e689b5

Please sign in to comment.