()
| 335 | } |
| 336 | |
| 337 | func (c *wasapiContext) loopOnRenderThread() error { |
| 338 | last := time.Now() |
| 339 | for { |
| 340 | c.suspendedCond.L.Lock() |
| 341 | for c.suspended { |
| 342 | c.suspendedCond.Wait() |
| 343 | } |
| 344 | c.suspendedCond.L.Unlock() |
| 345 | |
| 346 | evt, err := windows.WaitForSingleObject(c.sampleReadyEvent, windows.INFINITE) |
| 347 | if err != nil { |
| 348 | return err |
| 349 | } |
| 350 | if evt != windows.WAIT_OBJECT_0 { |
| 351 | return fmt.Errorf("oto: WaitForSingleObject failed: returned value: %d", evt) |
| 352 | } |
| 353 | |
| 354 | if err := c.writeOnRenderThread(); err != nil { |
| 355 | return err |
| 356 | } |
| 357 | |
| 358 | // Checking the current default audio device might be an expensive operation. |
| 359 | // Check this repeatedly but with some time interval. |
| 360 | if now := time.Now(); now.Sub(last) >= 500*time.Millisecond { |
| 361 | switched, err := c.isDeviceSwitched() |
| 362 | if err != nil { |
| 363 | return err |
| 364 | } |
| 365 | if switched { |
| 366 | return errDeviceSwitched |
| 367 | } |
| 368 | last = now |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | func (c *wasapiContext) writeOnRenderThread() error { |
| 374 | c.m.Lock() |
no test coverage detected