Skip to content

Commit

Permalink
Suppress PICTURE broadcast when nobody is listening
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmab committed Aug 29, 2024
1 parent 95f92c6 commit 8ca9540
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func (c *controller) HandlePicture(request *brevity.PictureRequest) {
}

func (c *controller) broadcastPicture(logger *zerolog.Logger, forceBroadcast bool) {
if c.srsClient.ClientsOnFrequency() == 0 && !forceBroadcast {
logger.Debug().Msg("skipping PICTURE broadcast because no clients are on frequency")
return
}
count, groups := c.scope.GetPicture(conf.DefaultPictureRadius, c.coalition.Opposite(), brevity.FixedWing)
isPictureClean := count == 0
for _, group := range groups {
Expand Down
7 changes: 7 additions & 0 deletions pkg/simpleradio/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Client interface {
Transmit(audio.Audio)
// IsOnFrequency checks if the named unit is on the client's frequency.
IsOnFrequency(string) bool
// ClientsOnFrequency returns the number of peers on this client's frequency.
ClientsOnFrequency() int
}

// client implements the SRS Client.
Expand Down Expand Up @@ -132,3 +134,8 @@ func (c *client) Transmit(sample audio.Audio) {
func (c *client) IsOnFrequency(name string) bool {
return c.dataClient.IsOnFrequency(name)
}

// ClientsOnFrequency implements [Client.ClientsOnFrequency].
func (c *client) ClientsOnFrequency() int {
return c.dataClient.ClientsOnFrequency()
}
14 changes: 14 additions & 0 deletions pkg/simpleradio/data/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type DataClient interface {
Send(types.Message) error
// IsOnFrequency checks if the named unit is on the client's frequency.
IsOnFrequency(string) bool
// ClientsOnFrequency returns the number of peers on this client's frequency.
ClientsOnFrequency() int
}

type dataClient struct {
Expand Down Expand Up @@ -322,3 +324,15 @@ func (c *dataClient) IsOnFrequency(name string) bool {
}
return false
}

func (c *dataClient) ClientsOnFrequency() int {
c.clientsLock.RLock()
defer c.clientsLock.RUnlock()
count := 0
for _, client := range c.clients {
if ok := c.clientInfo.RadioInfo.IsOnFrequency(client.RadioInfo); ok {
count++
}
}
return count
}

0 comments on commit 8ca9540

Please sign in to comment.