Commit Graph

84 Commits

Author SHA1 Message Date
Eric Laurent
775fa3cd32 Additional fix for isssue 2548710: Native AudioTrack resources never freed.
This changes fixes the issue for the direct output thread that was not
addressed by commit 71f37cd8a175ee00635cb91506d6810fd02b5b51.

Change-Id: I1bbe26be5f444415dd97270e49257650f5d2858f
2010-04-09 06:11:48 -07:00
Eric Laurent
deea502a92 Fix isssue 2548710: Native AudioTrack resources never freed.
The problem is a bug in AudioFlinger::MixerThread::prepareTracks_l() that makes that even if the TrackHandle
is destroyed, the corresponding Track will remain active as long as frames are ready for mixing.
If the track uses shared memory (static mode) and the sound is looped, this track will play for ever.

The fix consists in removing the track from active list immediately if the track is terminated.

Change-Id: I4582aa1d981079ab79be442fb6185f5afaed5cf3
2010-03-31 12:36:34 -07:00
Eric Laurent
101e77a31b Fix issue 2416481: Support Voice Dialer over BT SCO.
- AudioPolicyManager: allow platform specific choice for opening a direct output.
 Also fixed problems in direct output management.
- AudioFliinger: use shorter standby delay and track inactivity grace period for direct output
thread to free hardware resources as soon as possible.
- AudioSystem: do not use cached output selection in getOutput() when a direct output
can be selected.

Change-Id: If44b50d29237b8402ffd7a5ba1dc43c56f903e9b
2010-03-16 17:32:18 -07:00
Glenn Kasten
d5ea969b41 Initial version of LifeVibes integration.
Also changed tabs to spaces in other audioflinger files.
2010-03-09 14:16:01 -08:00
Eric Laurent
4f1fcc2890 Fix issue 2428563: Camera rendered inoperable by voice call interruption.
The problem is that AudioRecord never exits read() when a timeout occurs while trying
to get new PCM data from audio hardware input buffer: it just keeps waiting and retrying until stop() is called.
In the same time, opencore AndroidAudioInput::audin_thread_func() loop cannot be exited when stuck
in AudioRecord::read() because the iExitAudioThread flag can only be sampled when AudioRecord::read()
returns. We remain stuck with the audio input thread running.

The fix consists in modifying AudioRecord behavior in case of timeout when getting new PCM samples.
We now wait only one timeout period and try to restart audio record, in case the problem is due to a media_server
process crash. If this fails, we exit read() with a number of bytes read equals to 0 so that
AndroidAudioInput::audin_thread_func() loop can exit.

Also modified Audioflinger::RecordThread() loop so that we attempt to recover from HAL read errors.
In case of read error, the input stream is forced to standby so that next read attempt does a
reconfiguration and restart of the audio input device.
2010-03-05 11:54:23 -08:00
Eric Laurent
134ccbd131 Issue 2071329: audio track is shorter than video track for video capture on sholes
Add API to retrieve number of frames dropped by audio input kernel driver.

Submitted on behalf of Masaki Sato <masaki.sato@motorola.com>
2010-03-02 08:20:13 -08:00
Mathias Agopian
0dd0d2944a Simplify the MemoryDealer implementation
At some point the implementation became complicated because of
SurfaceFlinger's special needs, since we are now relying on gralloc
we can go back to much simpler MemoryDealer.

Removed HeapInterface and AllocatorInterface, since those don't need
to be paramterized anymore. Merged SimpleMemory and Allocation.
Made SimplisticAllocator non virtual.

Removed MemoryDealer flags (READ_ONLY, PAGE_ALIGNED)

Removed a lot of unneeded code.
2010-01-29 14:51:06 -08:00
Eric Laurent
e9ed2721f4 Fix issue 2285561: New AudioFlinger and audio driver API needed for A/V sync
Added getRenderPosition() API to IAudioFlinger to retreive number of audio frames
written by AudioFlinger to audio HAL and by DSP to DAC.

Added getRenderPosition() API to AudioHardwareInterface to retreive number of audio frames
written by DSP to DAC.

Exposed AudioTrack::getPosition() to AudioSink() to make it available to media player.

Removed excessive log in AudioHardwareGeneric.
2010-01-26 18:40:39 -08:00
Eric Laurent
43c0b0a1f6 Fix issue 2378022: AudioService should direct volume control to STREAM_VOICE_CALL stream when STREAM_VOICE_CALL stream is active.
Modified AudioService.getActiveStreamType() so that STREAM_VOICE_CALL is selected when a track using this stream
type is playing.

Chanded isMusicActive() for a more generic isStreamActive(stream) method in AudioSystem, IAudioFlinger and AudioFlinger.
2010-01-25 14:00:10 -08:00
Eric Laurent
7e2aad1e27 Fix issue 2323920: Notification & A2DP audio stutter.
Modified AudioFlinger duplicating output thread so that audio tracks are not mixed until both outputs (A2DP and hardware) have exited standby mode. This avoids to have one output far ahead of the other and audio frames dropped because the compensation mechanism cannot keep up.
Also calculate the maximum wait time in OutputTrack::write() based the on smallest frame count of all output threads instead of the frame count of the thread the OutputTrack is connected to. This avoids starving the thread with the smallest frame count by waiting too long on the other thread.
Since the frame count was reduced on hardware output to reduce latency the difference between A2DP and hardware outputs frame counts had become problematic.
Also increased the number of overflow buffers to cope with bigger timing differences among outputs.
2009-12-22 09:06:46 -08:00
Eric Laurent
fed9382a6a Fix issue 2306779: Runtime restart - Init failed at android.media.ToneGenerator.
The ToneGenerator failed to initialize because no more tracks were available in AudioFlinger mixer.

All tracks were used because the duplicating output was failing to free the tracks on audio hardware output mixer when exiting due to a misplaced test on output activity: output tracks where only freed if the duplicating output was active when exiting.

The fix consists in freeing the output tracks when the duplicating thread is destroyed without condition.
2009-12-07 12:30:22 -08:00
Eric Laurent
5291095089 Fix issue 2304669: VoiceIME: starting and canceling voice IME yields persistent "error 8" state on future attempts and breaks voice search.
Fixed AudioFlinger::openInput() broken in change ddb78e7753be03937ad57ce7c3c842c52bdad65e
so that an invalid IO handle (0) is returned in case of failure.
Applied the same correction to openOutput().
Modified RecordThread start procedure so that a failure occuring during the first read from audio input stream is detected and causes
the record start to fail.
Modified RecordThread stop procedure to make sure that audio input stream fd is closed before we exit the stop function.

Fixed AudioRecord JAVA and JNI implementation to take status of native AudioRecord::start() into account
and not change mRecordingState to RECORDSTATE_RECORDING if start fails.
2009-12-07 05:37:47 -08:00
Eric Laurent
d3fc8ac6c5 Fix issue 2292062: Audio freezes for three seconds when choosing ringtones with a headset connected and music playing.
The problem comes from a deadlock with AudioPolicyService mutex: When the second ringtone starts,
this mutex is locked by AudioPolicyService::startOutput() which in turn calls setParameters() to change the output device.
Audioflinger::ThreadBase::setParameters() signals the parameter change to the AudioFlinger mixer thread and waits for a condition
indicating that the parameter change has been processed.
At the same time, the mixer thread detects that the audio track corresponding to the first ring tone has been killed and calls its destructor.
This calls AudioPolicyService::releaseOutput() which tries to lock the AudioPolicyService mutex.
If this happens before the mixer thread can process the setParameters() command we are deadlocked.
The deadlock ends because setParameters() uses a timeout when waiting for the condition.

This regression was introduced by change 33736 fixing issue 2265163.

The fix consists in calling AudioPolicyService::releaseOutput() from Track::destroy() instead of from Track destructor: as detroy() is never called from the mixer thread loop (as opposed to the destructor) the deadlock described above cannot occur.
2009-12-01 02:17:41 -08:00
Eric Laurent
09b4ba82d7 Issue 2265163: Audio still reported routed through earpiece on sholes
This is a second attempt to fix the audio routed to earpiece syndrom.
The root cause identified this time is the crash of an application having an active AudioTrack playing on the VOICE_CALL stream type.
When this happens, the AudioTrack destructor is not called and the audio policy manager is not notified of the track stop.
Results a situation where the VOICE_CALL stream is considered as always in use by audio policy manager which makes that audio is routed to earpiece.

The fix consists in moving the track start/stop/close notification to audio policiy manager from AudioTrack to AudioFlinger Track objet.
The net result is that in the case of a client application crash, the AudioFlinger TrackHandle object (which implements the remote side of the IAudioTrack binder interface) destructor is called which in turn destroys the Track object and we can notify the audio policy manager of the track stop and removal.

The same modification is made for AudioRecord although no bug related to record has been reported yet.
Also fixed a potential problem if record stop is called while the record thread is exiting.
2009-11-19 23:57:45 -08:00
Eric Laurent
0e49d35fa4 Improvements for issue 2197683: English IME key-press latency is noticeably higher on passion than sholes
This change goes with a kernel driver change that reduces the audio buffer size from 4800 bytes (~27ms) to 3072 bytes (~17ms).
- The AudioFlinger modifcations in change 0bca68cfff161abbc992fec82dc7c88079dd1a36 have been removed: the short sleep period was counter productive when the AudioTrack is using the call back thread as it causes to many preemptions.
- AudioFlinger mixer thread now detects long standby exit time and in this case anticipates start by writing 0s as soon as a track is enabled even if not ready for mixing.
- AudioTrack::start() is modified to start call back thread before starting the IAudioTrack so that thread startup time is masked by IAudioTrack start and mixer thread wakeup time.
2009-11-11 12:13:27 -08:00
Eric Laurent
7b57085a73 AudioFlinger: delete Track object when createTrack() fails due to lack of tracks in AudioMixer.
This problem was encountered as a side effect of issue 2245298.
2009-11-09 04:45:39 -08:00
Eric Laurent
ee47d43ed3 More log for issue 2242381.
Added more log in system dump for AudioFlinger and AudioPolicyService to help debug issue 2242381 and other issues where the audio driver hangs.
2009-11-07 01:18:20 -08:00
Eric Laurent
134aa9c942 Fix issue 197683: English IME key-press latency is noticeably higher on passion than sholes. Part 2.
Reduce sleep time in AudioFlinger mixer thread when no data has been written to output to speed up startup time when  exiting standby.

The rest of the modifications for this issues is in kernel driver:
 commit 0dbb0ee136ed8de757df1ae26d84556c1751deae for buffer size modification from 8192 to 4800 bytes.
Another kernel improvement that is not submitted yes will reduce delay when audio output is exiting standby.
2009-11-02 00:13:56 -08:00
Eric Laurent
63da2b65f9 Fix issue 2192181: AudioFlinger must provide separated methods to set VOICE_CALL stream volume and down link audio volume.
Added setVoiceVolume() method to AudioSystem, AudioFlinger, IAudioFlinger, AudioPolicyService.
Removed call to AudioHardwareInterface::setVoiceVolume() from AudioFlinger::setStreamVolume().
2009-10-21 12:29:37 -07:00
Eric Laurent
f5e868baf9 Fix issue 2139634: DTMF tones on Sholes popping, hissing (audio latency too high).
This change is a complement to the main fix in kernel driver for the same issue (partner change #1250).
It removes clicks sometimes heard after the end of the tones while audio flinger is sending 0s to the audio output stream.
The problem was that the sleep time between two writes was more than the duration of one audio output stream buffer which could cause some underrun.

Also fixed a recent regression in ToneGenerator that made that the end of previous tone was repeated at the beginning of current one under certain timing circumstances when the maximum tone duration was specified.
2009-10-06 18:59:35 -07:00
Eric Laurent
2d70c80a7f Fix issue 2153835: AudioFlinger: setParameters() can remain stuck if output thread is terminated.
Wait for the parameter set completed condition with a time out in ThreadBase::setParameters().
Also lock AudioFlinger mutex before accessing thread list in AudioFlinger::setParameters() and keep a strong reference
on the thread being used in case it is exited while processing the request.
2009-09-30 14:48:20 -07:00
Dave Sparks
8a95a45fd9 Reduce the log spew from AudioFlinger due to a certain device that can't meet latency timing. Bug 2142215. 2009-09-30 03:09:03 -07:00
Eric Laurent
aef692f50f Fix issue 2116700: Ringer screwy while connected over Bluetooth.
There was a regression introduced in AudioFlinger by change 24114 for suspended output:
The suspended output was not reading and mixing audio tracks.
When the phone is ringing, the A2DP output is suspended if the SCO headset and A2DP headset are the same. As the ringtone is played over the duplicated output, the fact that the A2DP output was not reading data was causing the hardware output to be stalled from time to time.
2009-09-22 00:35:48 -07:00
Eric Laurent
0f8ab670c0 Fix issue 2127371: Possible race condition in AudioFlinger::openRecord() when a Track is being destroyed.
The fix consists in locking AudioFlinger::mLock mutex in the TrackBase destructor before clearing the strong pointer to the shared memory client. The mutex is not locked in removeclient() any more which implies that we must make sure that the Client destructor is always called from the TrackBase destructor or that we hold the mLock mutex before calling deleting the Client.
2009-09-17 09:26:04 -07:00
Eric Laurent
bdc0f84793 Fix issue 2123668: Class scope typo in AudioFlinger.cpp. 2009-09-16 06:02:45 -07:00
Eric Laurent
b3687ae925 Fix issue 2118464: cannot play ring tones and notifications after disconnecting BT headset while in call.
The problem comes from the fact that when the duplicated output is closed after BT headset disconnection, the OUTPUT_CLOSED notification is not sent to AudioSystem. Then the mapping between notification stream and duplicated output cached in AudioSystem is not cleared and next time a notification is played, the duplicated output is selected and the createTrack() request is refused by AudioFlinger as the selected output doesn't exist.
The notification is ignored by AudioFlinger because when it is sent by the terminating playback thread, the thread has already been removed from the playback thread list.

The fix consists in sending the notification in closeOutput() and not when exiting the playback thread.
The same fix is applied to record threads.
2009-09-15 07:10:12 -07:00
Eric Laurent
a6e58fe316 Fix issue 2115450: a2dp thread is started, even though we are only connected to headset and not playing music.
This is due to a regression introduced by change 24114: when no audio tracks are ready for mixing, 0s are written to audio hardware. However this should only happen if tracks have already been mixed since the audio flinger thread woke up.
Also do not write 0s to audio hardware in direct output threads when audio format is not linear PCM.
2009-09-14 02:37:15 -07:00
Eric Laurent
6ad8c64ce9 Fix issue 2107584: media server crash when AudioFlinger fails to allocate memory for track control block.
AudioFlinger: verify that mCblk is not null before using it in Track and RecordTrack contructors.
IAudioFlinger: check result of remote transaction before reading IAudioTrack and IAudioRecord.
IAudioTrack and IAudioRecord: check result of remote transaction before reading IMemory.
2009-09-09 05:16:08 -07:00
Eric Laurent
3522c80819 Fix issue 1992233: DTMF tones on Sholes is really long.
Add a parameter to ToneGenerator.startTone() allowing the caller to specify the tone duration. This is used by the phone application to have a precise control on the DTMF tone duration which was not possible with the use of delayed messaged.
Also modified AudioFlinger output threads so that 0s are written to the audio output stream when no more tracks are ready to mix instead of just sleeping. This avoids an issue where the end of a previous DTMF tone could stay in audio hardware buffers and be played just before the beginning of the next DTMF tone.
2009-09-08 22:56:07 -07:00
Eric Laurent
08d3d1d001 fix issue 2096657: Sholes: residue shutter sound heard ONCE while taking a picture AFTER the volume is turned off.
Do not ramp volume if the first frame of a track is processed after the track was stopped.
In the case of very short sounds, the track stop request can be received by AudioFlinger just after the start request before the first frame is mixed by AudioMixer. In this case, the track is already in stopped state and initial volume is applied with a ramp for the first frame processed which should not be the case: initial volume change is always applied immediatelly.
2009-09-03 04:11:18 -07:00
Eric Laurent
0643771ad0 Fix issue 2091594: music chirp after disconnecting A2DP.
In AudioFlinger::MixerThread::putTracks(), change the mFillingUpStatus flag to FS_FILLING for active tracks so that mute request is executed without ramping volume down when the track is moved from A2DP to hardware output.
Also modified AudioFlinger::setStreamOutput() so that the notification of the change is sent only once to AudioSystem.
2009-09-01 05:56:26 -07:00
Eric Laurent
c80b1a0034 Fix issue 2085690: AudioFlinger must properly terminate the input and output threads when destroyed.
Call closeInput() for all inputs and closeOutput() for all outputs before deleting audio hardware in AudioFlinger destructor.
2009-08-31 02:10:20 -07:00
Eric Laurent
f5aba82cb7 Fix issue 2046140: master: media_server crash when powering down A2DP headset while a ringtone is playing.
This is because the AudioFlinger duplicating thread is closed while the output tracks are still active. This cause the output tracks objects to be destroyed at a time where they can be in use by the destination output mixer.

The fix consists in adding the OutputTrack to the track list (mTracks) of its destination thread so that a strong reference is help during the mixer processed and the track is detroyed only when safe by destination thread.

Also added detection of problems when creating the output track (e.g. no more tracks in mixer). In this case the output track is not added to output track list of duplicating thread.
2009-08-11 09:43:09 -07:00
Eric Laurent
9e7b81943b Fix issue 2043314: Recorded audio is choppy.
Fixed cut/paste error causing constant reset of current frame index in input buffer.
2009-08-11 09:07:44 -07:00
Eric Laurent
878c0e1d68 Limit AudioFlinger mixer track sampling rate.
When changing the audio output stream sampling rate with setParameters() make sure that all tracks have a sampling rate less or equal to 2 times the new output sampling rate.
2009-08-10 08:15:12 -07:00
Eric Laurent
f9df24932f AudioService now differentiates BT headsets and car kits.
The BT headset detection now makes the difference between car kits and headsets, which can be used by audio policy manager.
The headset connection is also detected earlier, that is when the headset is connected and not when the SCO socket is connected as it was the case before. This allows the audio policy manager to suspend A2DP output while ringing if a SCO headset is connected.
2009-08-07 10:31:53 -07:00
Eric Laurent
dae20d9b7f Fix problem in AudioFlinger closeOutput and closeInput.
There was no garanty that the corresponding thread destructor had been already called when exiting the closeOutput() or closeInput() functions.
This contructor could be called by the thread after the exit condition is signalled. By way of consequence, closeOutputStream() could be called after
we exited closeOutput() function.

To solve the problem, the call to closeOutputStream() or closeInputStream() is moved to closeOutput() or closeInput().
2009-08-07 10:19:09 -07:00
Eric Laurent
3464c015ad Fix lockup in audio flinger threadbase setParameters.
The function checkForNewParameters_l() is called with the ThreadBase mutex mLock locked. In the case where the parameter change implies
an audio parameter modification (e.g. sampling rate) the function sendConfigEvent() is called which tries to lock mLock creating a deadlock.

The fix consists in creating a function equivalent to sendConfigEvent() that must be called with mLock locked and does not lock mLock.

Also added the possibility to have more than one set parameter request pending.
2009-08-07 09:28:40 -07:00
Eric Laurent
e0e9ecc0ce Fix issue 2001214: AudioFlinger and AudioPolicyService interfaces should not use pointers as handles to inputs and outputs.
Use integers instead of void* as input/output handles at IAudioFlinger and IAudioPolicyService interfaces.
AudioFlinger maintains an always increasing count of opened inputs or outputs as unique ID.
2009-08-07 00:27:19 -07:00
Eric Laurent
d55d179e95 Fix issue 2004229: DTMF tones play through earpiece (G1). 2009-07-28 06:11:55 -07:00
Eric Laurent
fd558a97ed Fix issue 1999585: audioflinger crash.
We were looping on the number of playback threads when dumping record threads.
2009-07-23 13:53:19 -07:00
Eric Laurent
9395d9be9c Fix the sim build. 2009-07-23 13:17:39 -07:00
Eric Laurent
9d91ad5d99 Fix issue 1795088 Improve audio routing code
Initial commit for review.
Integrated comments after patch set 1 review.
Fixed lockup in AudioFlinger::ThreadBase::exit()
Fixed lockup when playing tone with AudioPlocyService startTone()
2009-07-23 06:03:39 -07:00
Nick Pelly
07c8a20f39 Standby A2DP audio hardware interface when disabling A2DP.
Patch supplied on advice of partner. This causes us to send suspend_sink to
Bluez via socket interface, so we enter suspend on the A2DP link faster.
This is especially important when switching to SCO so that we come closer to
whitepaper recommendations to suspend A2DP before setting up SCO.

We have another patch set to add DBUS A2DP suspend and resume calls to Bluez
that will do a better job of following whitepaper recommendations for
A2DP -> SCO -> A2DP, but this small patch is still an improvement.
2009-07-15 12:22:55 -07:00
Android (Google) Code Review
17500c2031 am 3893da46: Merge change 6614 into donut
Merge commit '3893da46f0a97d59a7687ae2bd71ba855eb5ffe3'

* commit '3893da46f0a97d59a7687ae2bd71ba855eb5ffe3':
  Fix issue 1970108: crash in AudioFlinger::isMusicActive()
2009-07-09 12:49:43 -07:00
Eric Laurent
b025ca0c83 Fix issue 1970108: crash in AudioFlinger::isMusicActive()
Protected calls to MixerThread::isMusicActive() by AudioFlinger::mLock
2009-07-09 03:20:57 -07:00
Eric Laurent
8434c78862 am 88e209dc: Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR
Merge commit '88e209dcf8c2ebddda5c272f46d1bd5478bc639c'

* commit '88e209dcf8c2ebddda5c272f46d1bd5478bc639c':
  Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR
2009-07-07 09:36:14 -07:00
Eric Laurent
0bac53801b Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR
Store sample rate on 32 bits instead of 16 bits in audio_track_cblk_t.
Removed sampleRate() methods from AudioTrack and AudioRecord: replaced by getSampleRate().
AudioTrack::setSampleRate() no returns a status.
2009-07-07 07:10:45 -07:00
Android (Google) Code Review
7887aa766e am 2bbb80e1: Merge change 5994 into donut
Merge commit '2bbb80e183c6492689f8b10b2d0f5dfe9872a6ac'

* commit '2bbb80e183c6492689f8b10b2d0f5dfe9872a6ac':
  Less logging in some places.  More in others.
2009-07-03 08:18:22 -07:00
Joe Onorato
00dae0a084 Less logging in some places. More in others. 2009-07-01 21:04:03 -04:00