Loading core/java/android/speech/tts/AudioPlaybackHandler.java +22 −14 Original line number Diff line number Diff line Loading @@ -418,23 +418,31 @@ class AudioPlaybackHandler { if (DBG) Log.d(TAG, "handleSynthesisDone()"); final AudioTrack audioTrack = params.getAudioTrack(); try { if (audioTrack != null) { if (audioTrack == null) { return; } if (DBG) Log.d(TAG, "Waiting for audio track to complete : " + audioTrack.hashCode()); blockUntilDone(params); if (DBG) Log.d(TAG, "Releasing audio track [" + audioTrack.hashCode() + "]"); // The last call to AudioTrack.write( ) will return only after // all data from the audioTrack has been sent to the mixer, so // it's safe to release at this point. // it's safe to release at this point. Make sure release() and the call // that set the audio track to null are performed atomically. synchronized (this) { // Never allow the audioTrack to be observed in a state where // it is released but non null. The only case this might happen // is in the various stopFoo methods that call AudioTrack#stop from // different threads, but they are synchronized on AudioPlayBackHandler#this // too. audioTrack.release(); } } finally { params.setAudioTrack(null); } params.getDispatcher().dispatchUtteranceCompleted(); mLastSynthesisRequest = null; } } private static void blockUntilDone(SynthesisMessageParams params) { if (params.mAudioTrack == null || params.mBytesWritten <= 0) { Loading Loading
core/java/android/speech/tts/AudioPlaybackHandler.java +22 −14 Original line number Diff line number Diff line Loading @@ -418,23 +418,31 @@ class AudioPlaybackHandler { if (DBG) Log.d(TAG, "handleSynthesisDone()"); final AudioTrack audioTrack = params.getAudioTrack(); try { if (audioTrack != null) { if (audioTrack == null) { return; } if (DBG) Log.d(TAG, "Waiting for audio track to complete : " + audioTrack.hashCode()); blockUntilDone(params); if (DBG) Log.d(TAG, "Releasing audio track [" + audioTrack.hashCode() + "]"); // The last call to AudioTrack.write( ) will return only after // all data from the audioTrack has been sent to the mixer, so // it's safe to release at this point. // it's safe to release at this point. Make sure release() and the call // that set the audio track to null are performed atomically. synchronized (this) { // Never allow the audioTrack to be observed in a state where // it is released but non null. The only case this might happen // is in the various stopFoo methods that call AudioTrack#stop from // different threads, but they are synchronized on AudioPlayBackHandler#this // too. audioTrack.release(); } } finally { params.setAudioTrack(null); } params.getDispatcher().dispatchUtteranceCompleted(); mLastSynthesisRequest = null; } } private static void blockUntilDone(SynthesisMessageParams params) { if (params.mAudioTrack == null || params.mBytesWritten <= 0) { Loading