From 450313eabedfb741dbf7afda5917a1bd4103695c Mon Sep 17 00:00:00 2001 From: "Tobias Wellnitz, DH1TW" Date: Sun, 12 Dec 2021 14:15:52 +0100 Subject: [PATCH] fixed random WdmSyncloctl error in nats server (windows) When starting a Nats Server on Windows, enabling the ScWriter during startup caused the following portaudio error: 'WdmSyncIoctl: DeviceIoControl GLE = 0x00000490 (prop_set = {8C134960-51AD-11CF-878A-94F801C10000}, prop_id = 10)' For unknown reasons, this error is thrown if the stream is started immediately. --- audio/sinks/scWriter/scWriter.go | 4 ---- audio/sources/scReader/scReader.go | 4 ---- cmd/client_nats.go | 6 ++++-- cmd/enumerate.go | 5 ++++- cmd/server_nats.go | 24 +++++++++++++----------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/audio/sinks/scWriter/scWriter.go b/audio/sinks/scWriter/scWriter.go index 327a293..8642931 100644 --- a/audio/sinks/scWriter/scWriter.go +++ b/audio/sinks/scWriter/scWriter.go @@ -39,10 +39,6 @@ type src struct { // device. This is typically a speaker or a pair of headphones. func NewScWriter(opts ...Option) (*ScWriter, error) { - if err := pa.Initialize(); err != nil { - return nil, err - } - w := &ScWriter{ options: Options{ DeviceName: "default", diff --git a/audio/sources/scReader/scReader.go b/audio/sources/scReader/scReader.go index 500076b..e44dc32 100644 --- a/audio/sources/scReader/scReader.go +++ b/audio/sources/scReader/scReader.go @@ -26,10 +26,6 @@ type ScReader struct { // asynchronously from an a local audio device (e.g. a microphone). func NewScReader(opts ...Option) (*ScReader, error) { - if err := pa.Initialize(); err != nil { - return nil, err - } - r := &ScReader{ options: Options{ HostAPI: "default", diff --git a/cmd/client_nats.go b/cmd/client_nats.go index afd597f..a15aab0 100644 --- a/cmd/client_nats.go +++ b/cmd/client_nats.go @@ -158,7 +158,9 @@ func natsAudioClient(cmd *cobra.Command, args []string) { natsBrokerPort := viper.GetInt("nats.broker-port") serverName := viper.GetString("server.name") - portaudio.Initialize() + if err := portaudio.Initialize(); err != nil { + exit(err) + } defer portaudio.Terminate() if len(serverName) > 0 && strings.ContainsAny(serverName, " _\n\r") { @@ -323,7 +325,7 @@ func natsAudioClient(cmd *cobra.Command, args []string) { rx.Sources.AddSource("fromNetwork", fromNetwork) // set and enable speaker as default sink rx.Sinks.AddSink("speaker", speaker, true) - // start streaming to the network immediately + // start streaming from the network immediately rx.Sources.SetSource("fromNetwork") tx.Sources.AddSource("mic", mic) diff --git a/cmd/enumerate.go b/cmd/enumerate.go index a1143aa..b51d000 100644 --- a/cmd/enumerate.go +++ b/cmd/enumerate.go @@ -47,7 +47,10 @@ Available audio devices and supported Host APIs: // enumerate lists all available Audio devices on the system func enumerate() { - portaudio.Initialize() + if err := portaudio.Initialize(); err != nil { + exit(err) + } + defer portaudio.Terminate() hs, err := portaudio.HostApis() diff --git a/cmd/server_nats.go b/cmd/server_nats.go index 6bf13fc..1b1ba60 100644 --- a/cmd/server_nats.go +++ b/cmd/server_nats.go @@ -130,7 +130,10 @@ func natsAudioServer(cmd *cobra.Command, args []string) { natsBrokerPort := viper.GetInt("nats.broker-port") natsAddr := fmt.Sprintf("nats://%s:%v", natsBrokerURL, natsBrokerPort) - portaudio.Initialize() + if err := portaudio.Initialize(); err != nil { + exit(err) + } + defer portaudio.Terminate() // start from default nats config and add the common options @@ -301,10 +304,17 @@ func natsAudioServer(cmd *cobra.Command, args []string) { // add audio sinks & sources to the tx audio chain tx.Sources.AddSource("fromNetwork", fromNetwork) - tx.Sinks.AddSink("mic", mic, false) + // stream immediately audio from the network to the radio + if err := tx.Sources.SetSource("fromNetwork"); err != nil { + exit(err) + } + tx.Sinks.AddSink("mic", mic, true) // add audio sinks & sources to the rx audio chain rx.Sources.AddSource("radioAudio", radioAudio) + if err := rx.Sources.SetSource("radioAudio"); err != nil { + exit(err) + } rx.Sinks.AddSink("toNetwork", toNetwork, false) // assign the rx and tx audio chain to our natsServer @@ -342,17 +352,9 @@ func natsAudioServer(cmd *cobra.Command, args []string) { } ns.txAudioSub = sub - // register our Rotator RPC handler + // register our RPC handler sbAudio.RegisterServerHandler(rs.Server(), ns) - rx.Sources.SetSource("radioAudio") - - // stream immediately audio from the network to the radio - tx.Sources.SetSource("fromNetwork") - if err := tx.Enable(true); err != nil { - exit(err) - } - // when no ping is received, turn of the audio stream go ns.checkTimeout()