Index: trunk/extensions/OggHandler/cortado/src/com/fluendo/plugin/AudioSink.java |
— | — | @@ -200,6 +200,9 @@ |
201 | 201 | |
202 | 202 | return res; |
203 | 203 | } |
| 204 | + public synchronized boolean isAcquired() { |
| 205 | + return opened; |
| 206 | + } |
204 | 207 | public boolean release() { |
205 | 208 | stop(); |
206 | 209 | |
— | — | @@ -430,6 +433,8 @@ |
431 | 434 | case Event.NEWSEGMENT: |
432 | 435 | break; |
433 | 436 | case Event.EOS: |
| 437 | + // wait for completion, perform blocking drain of buffers |
| 438 | + drain(); |
434 | 439 | break; |
435 | 440 | } |
436 | 441 | return true; |
— | — | @@ -498,6 +503,32 @@ |
499 | 504 | return result; |
500 | 505 | } |
501 | 506 | |
| 507 | + /* |
| 508 | + * Block until audio playback is finished |
| 509 | + */ |
| 510 | + protected void drain() { |
| 511 | + if (ringBuffer.rate <= 0) { |
| 512 | + return; |
| 513 | + } |
| 514 | + |
| 515 | + /* need to start playback before we can drain, but only when |
| 516 | + * we have successfully negotiated a format and thus acquired the |
| 517 | + * ringbuffer. */ |
| 518 | + if (!ringBuffer.isAcquired()) { |
| 519 | + // FIXME make it work like it does in GstBaseAudioSink |
| 520 | + // ringBuffer.acquire(...); |
| 521 | + return; |
| 522 | + } |
| 523 | + |
| 524 | + if (ringBuffer.nextSample != -1) { |
| 525 | + long time = ringBuffer.nextSample * Clock.SECOND / ringBuffer.rate; |
| 526 | + Clock.ClockID id = audioClock.newSingleShotID(time); |
| 527 | + Debug.log(Debug.DEBUG, this+" waiting until t=" + ((double)time / Clock.SECOND) + "s for playback to finish"); |
| 528 | + id.waitID(); |
| 529 | + ringBuffer.nextSample = -1; |
| 530 | + } |
| 531 | + } |
| 532 | + |
502 | 533 | protected abstract RingBuffer createRingBuffer(); |
503 | 534 | protected abstract boolean open (RingBuffer ring); |
504 | 535 | protected abstract boolean close (RingBuffer ring); |