From 824b6a4a67166c3937400702944f659bd0d5d386 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 24 Sep 2009 07:03:14 -0700 Subject: Fix issue 2142613: ToneGenerator: short tones sometimes don't play on sholes or over A2DP. When the AudioTrack callback notification size is relatively high (Which is the case on Sholes and over A2DP), it is likely that the end of tone is reached during the first callback. In this case, the AudioTrack is stopped before exiting the callback which causes 2 problems: - 1: If the AudioFlinger thread is scheduled before we exit the ToneGenerator callback, the track can be stopped and reset before the data is actually marked as present in the buffer by the AudioTrack callback => no audio will be processed by AudioFlinger. - 2: In this case, the data write index in the AudioTrack buffer is incremented after the track was reset by the AudioFlinger which leaves unplayed data in the buffer. This data will be played the next time the AudioTrack is started if not flushed in between. The fix consists in adding an intermediate state to ToneGenerator state machine so that we exit the callback function when the stop condition is reached and stop the AudioTrack the next time we execute the callback. --- include/media/ToneGenerator.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/media/ToneGenerator.h') diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h index ea6bf5d..e8df08e 100644 --- a/include/media/ToneGenerator.h +++ b/include/media/ToneGenerator.h @@ -167,7 +167,8 @@ private: TONE_STARTING, // ToneGenerator is starting playing TONE_PLAYING, // ToneGenerator is playing TONE_STOPPING, // ToneGenerator is stoping - TONE_RESTARTING // + TONE_STOPPED, // ToneGenerator is stopped: the AudioTrack will be stopped + TONE_RESTARTING // A start request was received in active state (playing or stopping) }; -- cgit v1.1