From 8a4e92709e80d2a65a0f7552f56bebc9f42eb319 Mon Sep 17 00:00:00 2001 From: Benjamin Pracht Date: Wed, 22 Mar 2023 16:43:11 -0700 Subject: [PATCH] Implement all presets defined in protocol (#85) --- go.mod | 4 ++-- go.sum | 8 +++---- pkg/media/presets.go | 50 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index e45cdbf..d971462 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/frostbyte73/core v0.0.5 github.com/livekit/go-rtmp v0.0.0-20230317185657-6e9cfa387c7e github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 - github.com/livekit/protocol v1.5.1-0.20230316165531-6b747fe252cf + github.com/livekit/protocol v1.5.1-0.20230322011329-e78c5b18c0f3 github.com/livekit/psrpc v0.2.10-0.20230303054701-5853a56b4643 github.com/livekit/server-sdk-go v1.0.9-0.20230314192457-52c28d42b5d4 github.com/pion/rtcp v1.2.10 @@ -19,7 +19,7 @@ require ( github.com/urfave/cli/v2 v2.24.4 github.com/yutopp/go-flv v0.2.0 go.uber.org/atomic v1.10.0 - google.golang.org/protobuf v1.29.1 + google.golang.org/protobuf v1.30.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 2638f34..c344e13 100644 --- a/go.sum +++ b/go.sum @@ -79,8 +79,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a h1:5UkGQpskXp7HcBmyrCwWtO7ygDWbqtjN09Yva4l/nyE= github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a/go.mod h1:1Dlx20JPoIKGP45eo+yuj0HjeE25zmyeX/EWHiPCjFw= -github.com/livekit/protocol v1.5.1-0.20230316165531-6b747fe252cf h1:V8jSXH/6x4hXfN08+a2jgCwT2zMzcs75J1zEzxSLpII= -github.com/livekit/protocol v1.5.1-0.20230316165531-6b747fe252cf/go.mod h1:1aepmVXRS/Uh3QpenQ7Fzxejt1GjhTzyWh0Y6EPDzmE= +github.com/livekit/protocol v1.5.1-0.20230322011329-e78c5b18c0f3 h1:4MG8Wmnjohhjl6EWaxv6DfYQ47yY197TbSTQ8Eq1fcA= +github.com/livekit/protocol v1.5.1-0.20230322011329-e78c5b18c0f3/go.mod h1:m5PkhcDT0EWdhatB0MpjmMaxyySjfE5NyZQC/LJWfEM= github.com/livekit/psrpc v0.2.10-0.20230303054701-5853a56b4643 h1:ftDwqesgXMu0hUXFxf4KWAqqDIXz8BBdNnit3xc6RQA= github.com/livekit/psrpc v0.2.10-0.20230303054701-5853a56b4643/go.mod h1:K0j8f1PgLShR7Lx80KbmwFkDH2BvOnycXGV0OSRURKc= github.com/livekit/server-sdk-go v1.0.9-0.20230314192457-52c28d42b5d4 h1:fSm7wr75fh6NcTtLKa6nsyFKb7z+kRt6YzgxpyFrym4= @@ -301,8 +301,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.29.1 h1:7QBf+IK2gx70Ap/hDsOmam3GE0v9HicjfEdAxE62UoM= -google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/media/presets.go b/pkg/media/presets.go index c34e793..17ea193 100644 --- a/pkg/media/presets.go +++ b/pkg/media/presets.go @@ -18,6 +18,50 @@ func getOptionsForVideoPreset(preset livekit.IngressVideoEncodingPreset) (*livek Bitrate: 1700000, }, 3), }, nil + case livekit.IngressVideoEncodingPreset_H264_1080P_30FPS_3_LAYERS: + return &livekit.IngressVideoEncodingOptions{ + VideoCodec: livekit.VideoCodec_H264_BASELINE, + FrameRate: 30, + Layers: computeVideoLayers(&livekit.VideoLayer{ + Quality: livekit.VideoQuality_HIGH, + Width: 1920, + Height: 1080, + Bitrate: 3000000, + }, 3), + }, nil + case livekit.IngressVideoEncodingPreset_H264_540P_25FPS_2_LAYERS: + return &livekit.IngressVideoEncodingOptions{ + VideoCodec: livekit.VideoCodec_H264_BASELINE, + FrameRate: 25, + Layers: computeVideoLayers(&livekit.VideoLayer{ + Quality: livekit.VideoQuality_HIGH, + Width: 960, + Height: 540, + Bitrate: 600000, + }, 2), + }, nil + case livekit.IngressVideoEncodingPreset_H264_720P_30FPS_1_LAYER: + return &livekit.IngressVideoEncodingOptions{ + VideoCodec: livekit.VideoCodec_H264_BASELINE, + FrameRate: 25, + Layers: computeVideoLayers(&livekit.VideoLayer{ + Quality: livekit.VideoQuality_HIGH, + Width: 1280, + Height: 720, + Bitrate: 1700000, + }, 1), + }, nil + case livekit.IngressVideoEncodingPreset_H264_1080P_30FPS_1_LAYER: + return &livekit.IngressVideoEncodingOptions{ + VideoCodec: livekit.VideoCodec_H264_BASELINE, + FrameRate: 25, + Layers: computeVideoLayers(&livekit.VideoLayer{ + Quality: livekit.VideoQuality_HIGH, + Width: 1920, + Height: 1080, + Bitrate: 3000000, + }, 1), + }, nil default: return nil, errors.ErrInvalidVideoPreset } @@ -53,6 +97,12 @@ func getOptionsForAudioPreset(preset livekit.IngressAudioEncodingPreset) (*livek Channels: 2, Bitrate: 96000, }, nil + case livekit.IngressAudioEncodingPreset_OPUS_MONO_64KBS: + return &livekit.IngressAudioEncodingOptions{ + AudioCodec: livekit.AudioCodec_OPUS, + Channels: 1, + Bitrate: 64000, + }, nil default: return nil, errors.ErrInvalidAudioPreset }