public void run ( ) { //wait for finished item //send finished item to encoder //loop to top boolean loop = true ; boolean interrupted = false ; try { while ( loop ) { try { if ( nextTarget == null ) nextTarget = orderedEncodeRequests . poll ( 500 , TimeUnit . MILLISECONDS ) ; if ( nextTarget == null ) { loop = false ; } else if ( nextTarget . frameNumber < 0 ) { loop = false ; nextTarget = null ; orderedEncodeRequests . clear ( ) ; } else if ( finishedRequestStore . remove ( nextTarget ) ) { encoder . blockFinished ( nextTarget ) ; nextTarget = null ; synchronized ( outstandingCountLock ) { outstandingCount -- ; outstandingCountLock . notifyAll ( ) ; } } else { BlockEncodeRequest ber = finishedEncodeRequests . poll ( 500 , TimeUnit . MILLISECONDS ) ; if ( ber == null ) { //nothing to process yet, let this thread end. loop = false ; } else if ( nextTarget == ber ) { encoder . blockFinished ( ber ) ; nextTarget = null ; synchronized ( outstandingCountLock ) { outstandingCount -- ; outstandingCountLock . notifyAll ( ) ; } } else { finishedRequestStore . add ( ber ) ; } } } catch ( InterruptedException e ) { interrupted = true ; } } } finally { if ( interrupted ) Thread . currentThread ( ) . interrupt ( ) ; } synchronized ( this ) { managerThread = null ; restartManager ( ) ; } }
Waits for the next BlockEncodeRequest that needs to be sent back to the FLACEncoder for finalizing . If no request is finished or currently assigned to an encoding thread will timeout after 0 . 5 seconds and end .