From 9dbd5760ce894714d3de7c7b701bf8bd1230d46b Mon Sep 17 00:00:00 2001 From: Nonoo Date: Wed, 21 Oct 2020 16:09:10 +0200 Subject: [PATCH] Use radio name for pulse dev description --- audio-linux.go | 6 +++--- audiostream.go | 4 +++- controlstream.go | 14 ++++++++++++-- main.go | 1 - 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/audio-linux.go b/audio-linux.go index c159926..5af7d3a 100644 --- a/audio-linux.go +++ b/audio-linux.go @@ -112,14 +112,14 @@ func (a *audioStruct) loop() { } } -func (a *audioStruct) init() { +func (a *audioStruct) init(devName string) { a.source.Name = "kappanhang" a.source.Filename = "/tmp/kappanhang.source" a.source.Rate = 48000 a.source.Format = "s16le" a.source.Channels = 1 a.source.SetProperty("device.buffering.buffer_size", (48000*16)/10) // 100 ms - a.source.SetProperty("device.description", "kappanhang input") + a.source.SetProperty("device.description", "kappanhang: "+devName) a.sink.Name = "kappanhang" a.sink.Filename = "/tmp/kappanhang.sink" @@ -127,7 +127,7 @@ func (a *audioStruct) init() { a.sink.Format = "s16le" a.sink.Channels = 1 a.sink.SetProperty("device.buffering.buffer_size", (48000*16)/10) - a.sink.SetProperty("device.description", "kappanhang output") + a.sink.SetProperty("device.description", "kappanhang: "+devName) if err := a.source.Open(); err != nil { exit(err) diff --git a/audiostream.go b/audiostream.go index da32e62..54631d9 100644 --- a/audiostream.go +++ b/audiostream.go @@ -119,12 +119,14 @@ func (s *audioStream) init() { s.rxSeqBuf.init(rxSeqBufLength, 0xffff, 0, s.rxSeqBufEntryChan) } -func (s *audioStream) start() { +func (s *audioStream) start(devName string) { s.common.sendPkt3() s.common.waitForPkt4Answer() s.common.sendPkt6() s.common.waitForPkt6Answer() + audio.init(devName) + log.Print("stream started") s.timeoutTimer = time.NewTimer(audioTimeoutDuration) diff --git a/controlstream.go b/controlstream.go index a8ca9f6..1d6cd6a 100644 --- a/controlstream.go +++ b/controlstream.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "encoding/binary" "errors" + "strings" "time" "github.com/nonoo/kappanhang/log" @@ -150,6 +151,14 @@ func (s *controlStream) sendRequestSerialAndAudio() { }) } +func (s *controlStream) parseNullTerminatedString(d []byte) (res string) { + nullIndex := strings.Index(string(d), "\x00") + if nullIndex > 0 { + res = string(d[:nullIndex]) + } + return +} + func (s *controlStream) handleRead(r []byte) { switch len(r) { case 16: @@ -200,13 +209,14 @@ func (s *controlStream) handleRead(r []byte) { // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x03, 0x03, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - log.Print("serial and audio request success") + devName := s.parseNullTerminatedString(r[64:]) + log.Print("serial and audio request success, device name: ", devName) if s.requestSerialAndAudioTimeout != nil { s.requestSerialAndAudioTimeout.Stop() s.requestSerialAndAudioTimeout = nil } go streams.serial.start() - go streams.audio.start() + go streams.audio.start(devName) s.serialAndAudioStreamOpened = true } } diff --git a/main.go b/main.go index 323064f..06e9f12 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,6 @@ func main() { parseArgs() serialPort.init() - audio.init() streams.audio.init() streams.serial.init() streams.control.init()