diff --git a/egress/types.go b/egress/types.go index 60de07e7..a86cff67 100644 --- a/egress/types.go +++ b/egress/types.go @@ -26,6 +26,7 @@ const ( OutputTypeFile = "file" OutputTypeStream = "stream" OutputTypeSegments = "segments" + OutputTypeImages = "images" OutputTypeMultiple = "multiple" Unknown = "unknown" @@ -35,6 +36,7 @@ type EncodedOutput interface { GetFileOutputs() []*livekit.EncodedFileOutput GetStreamOutputs() []*livekit.StreamOutput GetSegmentOutputs() []*livekit.SegmentedFileOutput + GetImageOutputs() []*livekit.ImageOutput } type EncodedOutputDeprecated interface { @@ -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 diff --git a/egress/types_test.go b/egress/types_test.go new file mode 100644 index 00000000..36b96e4f --- /dev/null +++ b/egress/types_test.go @@ -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) + +}