Skip to content

Commit 2649e1f

Browse files
SimonBrandnerdaniel-abramov
authored andcommitted
Use time.Time as type
Signed-off-by: Šimon Brandner <[email protected]>
1 parent fd545d0 commit 2649e1f

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

pkg/conference/participant.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package conference
22

33
import (
44
"encoding/json"
5-
"sync/atomic"
5+
"time"
66

77
"github.com/matrix-org/waterfall/pkg/peer"
88
"github.com/matrix-org/waterfall/pkg/signaling"
@@ -24,7 +24,7 @@ type PublishedTrack struct {
2424
track *webrtc.TrackLocalStaticRTP
2525
// The time when we sent the last PLI to the sender. We store this to avoid
2626
// spamming the sender.
27-
lastPLITimestamp atomic.Int64
27+
lastPLITimestamp time.Time
2828
}
2929

3030
// Participant represents a participant in the conference.

pkg/conference/peer_message_processor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (c *Conference) processForwardRTCPMessage(msg peer.RTCPReceived) {
117117
for _, participant := range c.participants {
118118
for _, publishedTrack := range participant.publishedTracks {
119119
if publishedTrack.track.StreamID() == msg.StreamID && publishedTrack.track.ID() == msg.TrackID {
120-
participant.peer.WriteRTCP(msg.Packets, msg.StreamID, msg.TrackID, publishedTrack.lastPLITimestamp.Load())
120+
participant.peer.WriteRTCP(msg.Packets, msg.StreamID, msg.TrackID, publishedTrack.lastPLITimestamp)
121121
}
122122
}
123123
}
@@ -127,7 +127,7 @@ func (c *Conference) processPLISentMessage(msg peer.PLISent) {
127127
for _, participant := range c.participants {
128128
for _, publishedTrack := range participant.publishedTracks {
129129
if publishedTrack.track.StreamID() == msg.StreamID && publishedTrack.track.ID() == msg.TrackID {
130-
publishedTrack.lastPLITimestamp.Store(msg.Timestamp)
130+
publishedTrack.lastPLITimestamp = msg.Timestamp
131131
}
132132
}
133133
}

pkg/peer/messages.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package peer
22

33
import (
4+
"time"
5+
46
"github.com/pion/rtcp"
57
"github.com/pion/webrtc/v3"
68
"maunium.net/go/mautrix/event"
@@ -47,7 +49,7 @@ type RTCPReceived struct {
4749
}
4850

4951
type PLISent struct {
50-
Timestamp int64
52+
Timestamp time.Time
5153
StreamID string
5254
TrackID string
5355
}

pkg/peer/peer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (p *Peer[ID]) SubscribeTo(track *webrtc.TrackLocalStaticRTP) error {
119119
return nil
120120
}
121121

122-
func (p *Peer[ID]) WriteRTCP(packets []rtcp.Packet, streamID string, trackID string, lastPLITimestamp int64) error {
122+
func (p *Peer[ID]) WriteRTCP(packets []rtcp.Packet, streamID string, trackID string, lastPLITimestamp time.Time) error {
123123
const minimalPLIInterval = time.Millisecond * 500
124124

125125
packetsToSend := []rtcp.Packet{}
@@ -147,11 +147,11 @@ func (p *Peer[ID]) WriteRTCP(packets []rtcp.Packet, streamID string, trackID str
147147
case *rtcp.PictureLossIndication:
148148
// Since we sometimes spam the sender with PLIs, make sure we don't send
149149
// them way too often
150-
if time.Now().UnixNano()-lastPLITimestamp < minimalPLIInterval.Nanoseconds() {
150+
if time.Now().UnixNano()-lastPLITimestamp.UnixNano() < minimalPLIInterval.Nanoseconds() {
151151
continue
152152
}
153153

154-
p.sink.Send(PLISent{Timestamp: time.Now().UnixNano(), StreamID: streamID, TrackID: trackID})
154+
p.sink.Send(PLISent{Timestamp: time.Now(), StreamID: streamID, TrackID: trackID})
155155

156156
typedPacket.MediaSSRC = mediaSSRC
157157
packetsToSend = append(packetsToSend, typedPacket)

0 commit comments

Comments
 (0)