From 78386c4669ae2c18dc8234a3d867661f7c1430a0 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Mon, 10 Oct 2022 10:38:46 -0700 Subject: [PATCH] Update protocol (#1075) * update protocol * auto egress ensure unique filename * fix tests --- go.mod | 4 ++-- go.sum | 8 ++++---- pkg/rtc/room_egress.go | 16 ++++++++++------ pkg/service/redisstore_test.go | 4 ++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 1d9a7d49..a82960ee 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/livekit/mageutil v0.0.0-20221002073820-d9198083cfdc github.com/livekit/mediatransportutil v0.0.0-20221006082217-6780348e24ae - github.com/livekit/protocol v1.1.3-0.20221003181058-44a5ed6b4d13 + github.com/livekit/protocol v1.1.3-0.20221007212651-d9bc6cd9cb77 github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 github.com/mackerelio/go-osstat v0.2.3 github.com/magefile/mage v1.14.0 @@ -94,7 +94,7 @@ require ( golang.org/x/tools v0.1.10 // indirect golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect - google.golang.org/grpc v1.49.0 // indirect + google.golang.org/grpc v1.50.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 11c9a623..d65b9a6f 100644 --- a/go.sum +++ b/go.sum @@ -244,8 +244,8 @@ github.com/livekit/mageutil v0.0.0-20221002073820-d9198083cfdc h1:e3GIA9AL6h4a38 github.com/livekit/mageutil v0.0.0-20221002073820-d9198083cfdc/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20221006082217-6780348e24ae h1:yty1cLl984C0AEomZZuzqWEvHFXrmIZcLg7pnkAnvFQ= github.com/livekit/mediatransportutil v0.0.0-20221006082217-6780348e24ae/go.mod h1:1Dlx20JPoIKGP45eo+yuj0HjeE25zmyeX/EWHiPCjFw= -github.com/livekit/protocol v1.1.3-0.20221003181058-44a5ed6b4d13 h1:bmJcE0DiwCVESGS5LWMkWb+yIg8uCAtlbf5+o7l6+vM= -github.com/livekit/protocol v1.1.3-0.20221003181058-44a5ed6b4d13/go.mod h1:eburCdz6ZtbgKSKYkAeCdWP1z33DB9clTphz7uNaxp0= +github.com/livekit/protocol v1.1.3-0.20221007212651-d9bc6cd9cb77 h1:vHVvfoKWUT1eZahFn2CVjg9dHatp4XIRLVczy6uVnGI= +github.com/livekit/protocol v1.1.3-0.20221007212651-d9bc6cd9cb77/go.mod h1:jshI3nWbZkF1y1TUr2WIqzhN9HnyMqM9v/e/31L78z0= github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 h1:vOaY2qvfLihDyeZtnGGN1Law9wRrw8BMGCr1TygTvMw= github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995/go.mod h1:116ych8UaEs9vfIE8n6iZCZ30iagUFTls0vRmC+Ix5U= github.com/mackerelio/go-osstat v0.2.3 h1:jAMXD5erlDE39kdX2CU7YwCGRcxIO33u/p8+Fhe5dJw= @@ -765,8 +765,8 @@ google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= -google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= +google.golang.org/grpc v1.50.0 h1:fPVVDxY9w++VjTZsYvXWqEf9Rqar/e+9zYfxKK+W+YU= +google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/pkg/rtc/room_egress.go b/pkg/rtc/room_egress.go index 2fb680e3..9cf181c0 100644 --- a/pkg/rtc/room_egress.go +++ b/pkg/rtc/room_egress.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "strings" - "time" "github.com/livekit/livekit-server/pkg/rtc/types" "github.com/livekit/livekit-server/pkg/telemetry" @@ -53,7 +52,7 @@ func startTrackEgress( ) (*livekit.TrackEgressRequest, error) { output := &livekit.DirectFileOutput{ - Filepath: getFilePath(opts.FilePrefix, string(track.ID())), + Filepath: getFilePath(opts.Filepath), } switch out := opts.Output.(type) { @@ -86,10 +85,15 @@ func startTrackEgress( return req, err } -func getFilePath(prefix, identifier string) string { - if prefix == "" || strings.HasSuffix(prefix, "/") { - return fmt.Sprintf("%s%s_%s", prefix, identifier, time.Now().Format("2006-01-02T150405")) +func getFilePath(filepath string) string { + if filepath == "" || strings.HasSuffix(filepath, "/") || strings.Contains(filepath, "{track_id}") { + return filepath + } + + idx := strings.Index(filepath, ".") + if idx == -1 { + return fmt.Sprintf("%s-{track_id}", filepath) } else { - return fmt.Sprintf("%s_%s_%s", prefix, identifier, time.Now().Format("2006-01-02T150405")) + return fmt.Sprintf("%s-%s%s", filepath[:idx], "{track_id}", filepath[idx:]) } } diff --git a/pkg/service/redisstore_test.go b/pkg/service/redisstore_test.go index 15f60a67..b14cce2e 100644 --- a/pkg/service/redisstore_test.go +++ b/pkg/service/redisstore_test.go @@ -26,14 +26,14 @@ func TestRoomInternal(t *testing.T) { Name: "test_room", } internal := &livekit.RoomInternal{ - TrackEgress: &livekit.AutoTrackEgress{FilePrefix: "egress"}, + TrackEgress: &livekit.AutoTrackEgress{Filepath: "egress"}, } require.NoError(t, rs.StoreRoom(ctx, room, internal)) actualRoom, actualInternal, err := rs.LoadRoom(ctx, livekit.RoomName(room.Name), true) require.NoError(t, err) require.Equal(t, room.Sid, actualRoom.Sid) - require.Equal(t, internal.TrackEgress.FilePrefix, actualInternal.TrackEgress.FilePrefix) + require.Equal(t, internal.TrackEgress.Filepath, actualInternal.TrackEgress.Filepath) // remove internal require.NoError(t, rs.StoreRoom(ctx, room, nil))