Skip to content

Commit

Permalink
fixed random WdmSyncloctl error in nats server (windows)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dh1tw committed Dec 12, 2021
1 parent 8d3642c commit 450313e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
4 changes: 0 additions & 4 deletions audio/sinks/scWriter/scWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions audio/sources/scReader/scReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions cmd/client_nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion cmd/enumerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 13 additions & 11 deletions cmd/server_nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 450313e

Please sign in to comment.