replace proto.Clone calls (#3024)
* replace proto.Clone calls * deps * tests
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
@@ -116,7 +117,7 @@ func NewMediaTrackReceiver(params MediaTrackReceiverParams, ti *livekit.TrackInf
|
||||
params: params,
|
||||
state: mediaTrackReceiverStateOpen,
|
||||
}
|
||||
t.trackInfo.Store(proto.Clone(ti).(*livekit.TrackInfo))
|
||||
t.trackInfo.Store(utils.CloneProto(ti))
|
||||
|
||||
t.MediaTrackSubscriptions = NewMediaTrackSubscriptions(MediaTrackSubscriptionsParams{
|
||||
MediaTrack: params.MediaTrack,
|
||||
@@ -185,7 +186,7 @@ func (t *MediaTrackReceiver) SetupReceiver(receiver sfu.TrackReceiver, priority
|
||||
trackInfo := t.TrackInfo()
|
||||
|
||||
if priority == 0 {
|
||||
trackInfo = proto.Clone(trackInfo).(*livekit.TrackInfo)
|
||||
trackInfo = utils.CloneProto(trackInfo)
|
||||
trackInfo.MimeType = receiver.Codec().MimeType
|
||||
trackInfo.Mid = mid
|
||||
t.trackInfo.Store(trackInfo)
|
||||
@@ -605,7 +606,7 @@ func (t *MediaTrackReceiver) UpdateCodecCid(codecs []*livekit.SimulcastCodec) {
|
||||
|
||||
func (t *MediaTrackReceiver) UpdateTrackInfo(ti *livekit.TrackInfo) {
|
||||
updateMute := false
|
||||
clonedInfo := proto.Clone(ti).(*livekit.TrackInfo)
|
||||
clonedInfo := utils.CloneProto(ti)
|
||||
|
||||
t.lock.Lock()
|
||||
trackInfo := t.TrackInfo()
|
||||
@@ -658,7 +659,7 @@ func (t *MediaTrackReceiver) UpdateAudioTrack(update *livekit.UpdateLocalAudioTr
|
||||
|
||||
t.lock.Lock()
|
||||
trackInfo := t.TrackInfo()
|
||||
clonedInfo := proto.Clone(trackInfo).(*livekit.TrackInfo)
|
||||
clonedInfo := utils.CloneProto(trackInfo)
|
||||
clonedInfo.AudioFeatures = update.Features
|
||||
clonedInfo.Stereo = false
|
||||
clonedInfo.DisableDtx = false
|
||||
@@ -690,7 +691,7 @@ func (t *MediaTrackReceiver) UpdateVideoTrack(update *livekit.UpdateLocalVideoTr
|
||||
|
||||
t.lock.Lock()
|
||||
trackInfo := t.TrackInfo()
|
||||
clonedInfo := proto.Clone(trackInfo).(*livekit.TrackInfo)
|
||||
clonedInfo := utils.CloneProto(trackInfo)
|
||||
clonedInfo.Width = update.Width
|
||||
clonedInfo.Height = update.Height
|
||||
if proto.Equal(trackInfo, clonedInfo) {
|
||||
|
||||
@@ -1949,7 +1949,7 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
||||
|
||||
clonedLayers := make([]*livekit.VideoLayer, 0, len(req.Layers))
|
||||
for _, l := range req.Layers {
|
||||
clonedLayers = append(clonedLayers, proto.Clone(l).(*livekit.VideoLayer))
|
||||
clonedLayers = append(clonedLayers, utils.CloneProto(l))
|
||||
}
|
||||
ti.Codecs = append(ti.Codecs, &livekit.SimulcastCodecInfo{
|
||||
MimeType: mime,
|
||||
|
||||
+4
-4
@@ -246,7 +246,7 @@ func NewRoom(
|
||||
egressLauncher EgressLauncher,
|
||||
) *Room {
|
||||
r := &Room{
|
||||
protoRoom: proto.Clone(room).(*livekit.Room),
|
||||
protoRoom: utils.CloneProto(room),
|
||||
internal: internal,
|
||||
Logger: LoggerWithRoom(
|
||||
logger.GetLogger().WithComponent(sutils.ComponentRoom),
|
||||
@@ -964,7 +964,7 @@ func (r *Room) GetAgentDispatches(dispatchID string) ([]*livekit.AgentDispatch,
|
||||
|
||||
for _, ad := range r.agentDispatches {
|
||||
if dispatchID == "" || ad.Id == dispatchID {
|
||||
ret = append(ret, proto.Clone(ad.AgentDispatch).(*livekit.AgentDispatch))
|
||||
ret = append(ret, utils.CloneProto(ad.AgentDispatch))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1427,7 +1427,7 @@ func (r *Room) pushAndDequeueUpdates(
|
||||
|
||||
func (r *Room) updateProto() *livekit.Room {
|
||||
r.lock.RLock()
|
||||
room := proto.Clone(r.protoRoom).(*livekit.Room)
|
||||
room := utils.CloneProto(r.protoRoom)
|
||||
r.lock.RUnlock()
|
||||
|
||||
room.NumPublishers = 0
|
||||
@@ -1493,7 +1493,7 @@ func (r *Room) audioUpdateWorker() {
|
||||
// changedSpeakers need to include previous speakers that are no longer speaking
|
||||
for sid, speaker := range lastActiveMap {
|
||||
if nextActiveMap[sid] == nil {
|
||||
inactiveSpeaker := proto.Clone(speaker).(*livekit.SpeakerInfo)
|
||||
inactiveSpeaker := utils.CloneProto(speaker)
|
||||
inactiveSpeaker.Level = 0
|
||||
inactiveSpeaker.Active = false
|
||||
changedSpeakers = append(changedSpeakers, inactiveSpeaker)
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
|
||||
"github.com/livekit/livekit-server/version"
|
||||
@@ -284,7 +285,7 @@ func TestPushAndDequeueUpdates(t *testing.T) {
|
||||
{
|
||||
name: "last version is enqueued",
|
||||
pi: subscriber1v2,
|
||||
existing: &participantUpdate{pi: proto.Clone(subscriber1v1).(*livekit.ParticipantInfo)}, // clone the existing value since it can be modified when setting to disconnected
|
||||
existing: &participantUpdate{pi: utils.CloneProto(subscriber1v1)}, // clone the existing value since it can be modified when setting to disconnected
|
||||
validate: func(t *testing.T, rm *Room, _ []*participantUpdate) {
|
||||
queued := rm.batchedUpdates[livekit.ParticipantIdentity(identity)]
|
||||
require.NotNil(t, queued)
|
||||
@@ -294,7 +295,7 @@ func TestPushAndDequeueUpdates(t *testing.T) {
|
||||
{
|
||||
name: "latest version when immediate",
|
||||
pi: subscriber1v2,
|
||||
existing: &participantUpdate{pi: proto.Clone(subscriber1v1).(*livekit.ParticipantInfo)},
|
||||
existing: &participantUpdate{pi: utils.CloneProto(subscriber1v1)},
|
||||
immediate: true,
|
||||
expected: []*participantUpdate{{pi: subscriber1v2}},
|
||||
validate: func(t *testing.T, rm *Room, _ []*participantUpdate) {
|
||||
@@ -305,7 +306,7 @@ func TestPushAndDequeueUpdates(t *testing.T) {
|
||||
{
|
||||
name: "out of order updates are rejected",
|
||||
pi: subscriber1v1,
|
||||
existing: &participantUpdate{pi: proto.Clone(subscriber1v2).(*livekit.ParticipantInfo)},
|
||||
existing: &participantUpdate{pi: utils.CloneProto(subscriber1v2)},
|
||||
validate: func(t *testing.T, rm *Room, updates []*participantUpdate) {
|
||||
queued := rm.batchedUpdates[livekit.ParticipantIdentity(identity)]
|
||||
requirePIEquals(t, subscriber1v2, queued.pi)
|
||||
@@ -315,7 +316,7 @@ func TestPushAndDequeueUpdates(t *testing.T) {
|
||||
name: "sid change is broadcasted immediately with synthsized disconnect",
|
||||
pi: publisher2,
|
||||
closeReason: types.ParticipantCloseReasonServiceRequestRemoveParticipant, // just to test if update contain the close reason
|
||||
existing: &participantUpdate{pi: proto.Clone(subscriber1v2).(*livekit.ParticipantInfo), closeReason: types.ParticipantCloseReasonStale},
|
||||
existing: &participantUpdate{pi: utils.CloneProto(subscriber1v2), closeReason: types.ParticipantCloseReasonStale},
|
||||
expected: []*participantUpdate{
|
||||
{
|
||||
pi: &livekit.ParticipantInfo{
|
||||
@@ -333,7 +334,7 @@ func TestPushAndDequeueUpdates(t *testing.T) {
|
||||
{
|
||||
name: "when switching to publisher, queue is cleared",
|
||||
pi: publisher1v2,
|
||||
existing: &participantUpdate{pi: proto.Clone(subscriber1v1).(*livekit.ParticipantInfo)},
|
||||
existing: &participantUpdate{pi: utils.CloneProto(subscriber1v1)},
|
||||
expected: []*participantUpdate{{pi: publisher1v2}},
|
||||
validate: func(t *testing.T, rm *Room, updates []*participantUpdate) {
|
||||
require.Empty(t, rm.batchedUpdates)
|
||||
@@ -622,7 +623,7 @@ func TestDataChannel(t *testing.T) {
|
||||
}
|
||||
setSource(mode, packet, p)
|
||||
|
||||
packetExp := proto.Clone(packet).(*livekit.DataPacket)
|
||||
packetExp := utils.CloneProto(packet)
|
||||
if mode != legacySID {
|
||||
packetExp.ParticipantIdentity = string(p.Identity())
|
||||
packetExp.GetUser().ParticipantIdentity = string(p.Identity())
|
||||
@@ -667,7 +668,7 @@ func TestDataChannel(t *testing.T) {
|
||||
setSource(mode, packet, p)
|
||||
setDest(mode, packet, p1)
|
||||
|
||||
packetExp := proto.Clone(packet).(*livekit.DataPacket)
|
||||
packetExp := utils.CloneProto(packet)
|
||||
if mode != legacySID {
|
||||
packetExp.ParticipantIdentity = string(p.Identity())
|
||||
packetExp.GetUser().ParticipantIdentity = string(p.Identity())
|
||||
|
||||
@@ -220,7 +220,7 @@ func (t *SubscribedTrack) UpdateSubscriberSettings(settings *livekit.UpdateTrack
|
||||
}
|
||||
|
||||
isImmediate = isImmediate || (!settings.Disabled && settings.Disabled != t.isMutedLocked())
|
||||
t.settings = proto.Clone(settings).(*livekit.UpdateTrackSettings)
|
||||
t.settings = utils.CloneProto(settings)
|
||||
t.settingsLock.Unlock()
|
||||
|
||||
if isImmediate {
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/livekit/mediatransportutil/pkg/twcc"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/transport"
|
||||
@@ -439,7 +440,7 @@ func (t *TransportManager) GetICEConfig() *livekit.ICEConfig {
|
||||
if t.iceConfig == nil {
|
||||
return nil
|
||||
}
|
||||
return proto.Clone(t.iceConfig).(*livekit.ICEConfig)
|
||||
return utils.CloneProto(t.iceConfig)
|
||||
}
|
||||
|
||||
func (t *TransportManager) resetTransportConfigureLocked(reconfigured bool) {
|
||||
|
||||
Reference in New Issue
Block a user