Skip to content

Commit

Permalink
Remove vanished tracking sources
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Apr 25, 2021
1 parent c92f556 commit 3556210
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/tracked/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (r *Receiver) TrackedFrames() map[string]*TrackerWrapperPacket {
r.mutex.Lock()
defer r.mutex.Unlock()

r.cleanupOldSources()
frames := map[string]*TrackerWrapperPacket{}
for k, v := range r.frames {
frames[k] = v
Expand Down Expand Up @@ -61,11 +62,11 @@ func parseVisionWrapperPacket(data []byte) (message *TrackerWrapperPacket, err e
return
}

func (r *Receiver) cleanupDetections() {
for camId, t := range r.receivedTimes {
func (r *Receiver) cleanupOldSources() {
for uuid, t := range r.receivedTimes {
if time.Now().Sub(t) > time.Second {
delete(r.receivedTimes, camId)
delete(r.frames, camId)
delete(r.receivedTimes, uuid)
delete(r.frames, uuid)
}
}
}

0 comments on commit 3556210

Please sign in to comment.