Goroutine to fill PCM buffers with decoded data for OpenAL
()
| 310 | |
| 311 | // Goroutine to fill PCM buffers with decoded data for OpenAL |
| 312 | func (p *Player) run() { |
| 313 | |
| 314 | for { |
| 315 | // Get current state of player source |
| 316 | state := al.GetSourcei(p.source, al.SourceState) |
| 317 | processed := al.GetSourcei(p.source, al.BuffersProcessed) |
| 318 | queued := al.GetSourcei(p.source, al.BuffersQueued) |
| 319 | //log.Debug("state:%x processed:%v queued:%v", state, processed, queued) |
| 320 | |
| 321 | // If stopped, unqueues all buffer before exiting |
| 322 | if state == al.Stopped { |
| 323 | if queued == 0 { |
| 324 | break |
| 325 | } |
| 326 | // Unqueue buffers |
| 327 | if processed > 0 { |
| 328 | al.SourceUnqueueBuffers(p.source, uint32(processed), nil) |
| 329 | } |
| 330 | continue |
| 331 | } |
| 332 | |
| 333 | // If no buffers processed, sleeps and try again |
| 334 | if processed == 0 { |
| 335 | time.Sleep(20 * time.Millisecond) |
| 336 | continue |
| 337 | } |
| 338 | |
| 339 | // Remove processed buffers from the queue |
| 340 | al.SourceUnqueueBuffers(p.source, uint32(processed), nil) |
| 341 | // Fill and enqueue buffers with new data |
| 342 | for i := 0; i < int(processed); i++ { |
| 343 | err := p.fillBuffer(p.buffers[p.nextBuf]) |
| 344 | if err != nil { |
| 345 | break |
| 346 | } |
| 347 | p.nextBuf = (p.nextBuf + 1) % playerBufferCount |
| 348 | } |
| 349 | } |
| 350 | // Sends indication of goroutine end |
| 351 | p.gchan <- "end" |
| 352 | } |
| 353 | |
| 354 | // fillBuffer fills the specified OpenAL buffer with next decoded data |
| 355 | // and queues the buffer to this player source |
no test coverage detected