Pause playback while transmitting and declare microphone use.

macOS refuses capture without a usage string, and queued remote audio was still handed to the speaker after push-to-talk began.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Konrad Neitzel
2026-10-03 16:32:01 +02:00
co-authored by Cursor
parent 9c4f6621fc
commit 6233292931
9 changed files with 44 additions and 15 deletions
+26
View File
@@ -360,6 +360,32 @@ func TestRemoteAudioAndTalker(t *testing.T) {
}
}
func TestPlaybackPausesWhenTransmitting(t *testing.T) {
in := login(t, "DL1ABC", "key", 20, 7, []string{"OPUS"})
enc, err := opus.NewEncoder()
if err != nil {
t.Fatal(err)
}
defer enc.Close()
pkt, err := enc.Encode(make([]int16, opus.FrameSamples))
if err != nil {
t.Fatal(err)
}
in.refl.writeUDP(t, 101, 7, 1, appendBytes(nil, pkt))
in.refl.writeUDP(t, 101, 7, 2, appendBytes(nil, pkt))
if _, err := in.st.WaitPlayback(t.Context(), 2*opus.FrameSamples-1); err != nil {
t.Fatal(err)
}
in.st.HoldButton()
in.refl.writeFrame(t, 105, appendStr(appendU32(nil, 20), "DB0XYZ"))
if _, err := in.st.Wait(t.Context(), func(s station.State) bool { return s.Transmitting }); err != nil {
t.Fatal(err)
}
if pcm := in.st.TakePlayback(); len(pcm) != 0 {
t.Fatalf("playback %d samples, want none while transmitting", len(pcm))
}
}
func TestMicrophoneIsNotPlayed(t *testing.T) {
in := login(t, "DL1ABC", "key", 20, 7, []string{"OPUS"})
in.st.HoldButton()
+7 -4
View File
@@ -163,12 +163,12 @@ func (s *Station) session(ctx context.Context, conn net.Conn) error {
case <-ctx.Done():
timer.Stop()
return ctx.Err()
case <-tcpErr:
case err := <-tcpErr:
timer.Stop()
return errors.New("tcp closed")
case <-udpFail:
return err
case err := <-udpFail:
timer.Stop()
return errors.New("udp closed")
return err
case tcpf = <-tcpCh:
timer.Stop()
reason = "tcp"
@@ -465,12 +465,14 @@ func (s *Station) endTransmit() {
copy(frame, s.mic)
s.mic = nil
if pkt, err := s.enc.Encode(frame); err == nil {
// A lost datagram ends the session when the receive timer expires.
_ = s.sendUDP(udpAudio, appendBlob(nil, pkt))
}
} else {
s.mic = nil
}
if s.udp != nil {
// A lost datagram ends the session when the receive timer expires.
_ = s.sendUDP(udpFlush, nil)
}
}
@@ -511,6 +513,7 @@ func (s *Station) publish() {
s.state.Transmitting = tx
if tx {
s.state.Talker = s.cfg.callsign
s.play = nil
} else {
s.state.Talker = s.remoteTalker
}
+5
View File
@@ -151,6 +151,7 @@ func (s *Station) WriteMicrophone(pcm []int16) {
if err != nil {
continue
}
// A lost datagram ends the session when the receive timer expires.
_ = s.sendUDP(udpAudio, appendBlob(nil, pkt))
}
}
@@ -159,6 +160,10 @@ func (s *Station) WriteMicrophone(pcm []int16) {
func (s *Station) TakePlayback() []int16 {
s.mu.Lock()
defer s.mu.Unlock()
if s.transmitting() {
s.play = nil
return nil
}
out := s.play
s.play = nil
return out