History log of /frameworks/base/services/audioflinger/AudioFlinger.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
0609231f4fa415cc8198d706ee1c6b5f5e911023 24-Jan-2012 Eric Laurent <elaurent@google.com> AudioFlinger: refine mixer sleep time logic

When an AudioTrack is in underrun state, the AudioFlinger mixer will
sleep for a short period of time to give the app a chance to fill the
AudioTrack buffer. If the AudioTrack is still not ready during next mixing round,
the mixer will proceed with other tracks.

If an application keeps a steady underrun condition, the AudioFlinger mixer will
alternate between ready and not ready states. In the longer term this will cause the
audio HAL to underrun.
There is a mechanism to reduce the sleep period if the mixer is not ready several times in a
row but this mechanism is defeated by the alternating ready/not ready conditions.

The fix consists in only increasing sleep time if the mixer is ready for at least two
consecutive times.

Issue 5904527.

Change-Id: Id0139bca9be8c4e425ec6d428515c4d8f718e8c9
/frameworks/base/services/audioflinger/AudioFlinger.cpp
0b0896555827d2a5a9c8240f27dd94e8933dd778 24-Jan-2012 Eric Laurent <elaurent@google.com> DO NOT MERGE Revert "Revert "AudioFlinger: mix track only when really ready (2)""

This reverts commit b918035d34422a2041b6ec8c09c566bb93345b40.

Change-Id: I093bcfa56ad54a080b930208b6b79169d33581fb
/frameworks/base/services/audioflinger/AudioFlinger.cpp
b918035d34422a2041b6ec8c09c566bb93345b40 23-Jan-2012 Justin Ho <justinho@google.com> DO NOT MERGE Revert "AudioFlinger: mix track only when really ready (2)"

This reverts commit 71c4496a9757438afd30b4404824f296f6158a49.

Change-Id: Iff10c49ea728bb10023ddeb50a3b708db770fff2
/frameworks/base/services/audioflinger/AudioFlinger.cpp
71c4496a9757438afd30b4404824f296f6158a49 18-Jan-2012 Eric Laurent <elaurent@google.com> AudioFlinger: mix track only when really ready (2)

This problem due to the way audio buffers are mixed when
low power mode is active was addressed by commits 19ddf0eb
and 8a04fe03 but only partially. As a matter of fact, when more
than one audio track is playing, the problem is still present.
This is most noticeable when playing music with screen off
and a notification or navigation instruction is played: in this case,
the music or notification is likely to skip.

The fix consists in declaring the mixer ready if all active tracks
are ready. Previous behavior was to declare ready if at least one track was
ready. To avoid that one application failing to fill the track buffer blocks other
tracks indefinitely, this condition is respected only if the mixer was ready
in the previous round.

Issue 5799167.

Change-Id: Iabd4ca08d3d45f563d9824c8a03c2c68a43ae179
/frameworks/base/services/audioflinger/AudioFlinger.cpp
72dafb20e036b8844775e3456e5d06a8a8a2cd50 23-Dec-2011 Eric Laurent <elaurent@google.com> audioflinger: fix clicks on 48kHz audio.

The calculation done in prepareTracks_l() for the minimum amount
off frames needed to mix one output buffer had 2 issues:
- the additional sample needed for interpolation was not included
- the fact that the resampler does not acknowledge the frames consumed
immediately after each mixing round but only once all frames requested have been used
was not taken into account.
Thus the number of frames available in track buffer could be considered sufficient although
it was not and the resampler would abort producing a short silence perceived as a click.

Issue 5727099.

Change-Id: I7419847a7474c7d9f9170bedd0a636132262142c
/frameworks/base/services/audioflinger/AudioFlinger.cpp
4433169a64eddb8598735bd950491ed35ad9c5f8 05-Dec-2011 Eric Laurent <elaurent@google.com> audioflinger: fix audio skipping over A2DP

The maximum sleep time allowed in the mixer thread when audio tracks
are enabled but not ready for mixing is derived from the latency
reported by the output stream.
This does not work for A2DP where the latency also reflects encoding, decoding
and transfer time.

Modified activeSleepTimeUs() to take A2DP case into account.

Issue 5682206.

Change-Id: I3784ac01fb6f836b5a6ce6f764fb15347586de35
/frameworks/base/services/audioflinger/AudioFlinger.cpp
f1f5fc85b07fe74cfa12789fefa126cac7a499a9 23-Nov-2011 Eric Laurent <elaurent@google.com> audioflinger: reduce sleep time to avoid underrun

Progressively reduce the sleep time applied in MixerThread::threadLoop()
in case of consecutive application underruns to avoid starving the audio HAL.
As the default sleep time is longer than the duration of an audio buffer
we ended up writing less data than needed by the audio HAL if
the condition persisted.

Issue 5553055.

Change-Id: I2b23ee79c032efa945025db228beaecd1e07a2e5
/frameworks/base/services/audioflinger/AudioFlinger.cpp
f9c361dec4b9380db2b7eeaed68c828e154681ed 12-Nov-2011 Eric Laurent <elaurent@google.com> audioflinger: fix noise when skipping to next song

When audio effects are enabled, a noise can be heard at the
beginning of the new song when skipping to next song in music app.

This is because some effects (especially virtualizer) have a tail.
This tail was not played when previous song was stopped because effects were
not processed when no tracks were present on a given session. This is to
reduce CPU load when effects are enabled but no audio is playing.
The tail was then rendered when the new song was started.

Added a delay before stopping effect process after all tracks have been removed from a session.

Issue 5584880.

Change-Id: I815e0f7441f9302e8dfe413dc269a94e4cc6fd95
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8a04fe032b2a9ab0f2905571c59b5ce6bd0e9d71 09-Nov-2011 Eric Laurent <elaurent@google.com> Fix regression for SoundPool playback

Commit 19ddf0eb introduced a problem with applications (like SoundPool)
relying on an underrun condition to detect end of playback instead of
stopping the track when all data is written.
AudioFlinger would keep waiting for new data in case of partial buffer
filling and never reach the underrun condition.

Added a mechanism to wait no more than once if not enough frames are present
in the track buffer.

Issue 5585490.

Change-Id: I131e605ff6070831a01ddf734e68459e3bf2354b
/frameworks/base/services/audioflinger/AudioFlinger.cpp
19ddf0ebb013c0ad1d6c04f0c9d6ce177a0fafae 03-Nov-2011 Eric Laurent <elaurent@google.com> AudioFlinger: mix track only when really ready

The addition of low power audio playback mode made that audio buffer consumption
by audio HAL can now happen in bursts. This makes that requesting audio data
from an AudioTrack for mixing can happen at much shorter intervals than before.
This revealed an existing problem where AudioFlinger would consider a track ready
for mixing although not enough frames were ready to completely fill one output buffer,
thus creating short periods of silence.

The fix consists in waiting for enough frames to be ready in AudioTrack buffer before
declaring a track ready for mixing. This minimum is not applied when the track is stopped
to allow the buffer to be emptied completely.

Change-Id: I6d04f9b65db5af85b0b53f0a5674be7ec02f9e9f
/frameworks/base/services/audioflinger/AudioFlinger.cpp
7fa1cee12c12231b5d72c95dc72512867713ff1b 19-Oct-2011 Eric Laurent <elaurent@google.com> Fix issue 381905: BassBoostTest CTS tests fail...

When AudioEffectTest is executed, an Equalizer is created
and enabled on a MediaPlayer session. Effects on the output
mix are therefore suspended.
Then the MediaPlayer is released with the effect still enabled.
In this case, Audioflinger::purgeStaleEffects_l() fails to restore
the suspended effects when the effect attached to the released audio session
is removed.
When subsequent tests are executed on output mix effects, these effects cannot be
enabled as they are still suspended.

Fixed purgeStaleEffects_l() to restore suspended effects if the effect removed is enabled.

Also fixed EffectHandle::disconnect() to only restore suspended effects if the disconnected
handle actually has control over the effect.

Change-Id: I67232e7c34680b0cc01abfd57d5d510a524e5d4f
/frameworks/base/services/audioflinger/AudioFlinger.cpp
276fa43b98920f4da60b64fe23da4debb72667c0 19-Oct-2011 Eric Laurent <elaurent@google.com> Limit AudioFlinger log.

AudioFlinger logs a warning when a write to the audio HAL
takes too long to return. The threshold for this warning is
a rule of thumb based on the assumption that the audio HAL will consume
buffers at a regular pace.
The introduction of low power audio mode with larger buffers and writes
occuring in bursts makes that this threshold is often exceeded resulting
in excessive and misleading warnings.

The threshold is raised to remove unwanted warnings but we should reconsider
the usefulness of this warning altogether.

Change-Id: I5ef6898ea28d879cede3e47da542a64092a3cca4
/frameworks/base/services/audioflinger/AudioFlinger.cpp
6fccbd04fc7e64dfc05096281cd64d76dfcb299d 06-Oct-2011 Eric Laurent <elaurent@google.com> Fix issue 5381089: problem with A2DP music volume

This problem only occurs when audio effects are present and
the music volume is applied by one effect engine.
When connecting or disconnecting A2DP, audio effects are moved from
one mixer thread to another. When removed from the source thread,
the effect is stopped but it is not restarted when added to the
destination thread.
This regression was introduced by commit 21b5c47e.

Change-Id: I4cc578d8d760ec65b185032b6fda98c739d331bc
/frameworks/base/services/audioflinger/AudioFlinger.cpp
4a64a6e32c40c2708208864961844b242568ea17 27-Sep-2011 Eric Laurent <elaurent@google.com> Fix issue 5373658: memory leak in AudioFlinger.

Unlink PowerManagerService binder interface death recipient
in ThreadBase destructor.

Change-Id: Iab06ae9a8a6737bb002b6416a157b0fb50c11ad5
/frameworks/base/services/audioflinger/AudioFlinger.cpp
5e7acae2c3e4cf345e3fa7bf10e3c62f9e69e6be 23-Sep-2011 Eric Laurent <elaurent@google.com> Fix issue 5355047: Automated effect tests fail.

Fixed several regressions in automated audio effect tests due
to changes in effect framework and visualizer FFT output range.

- Do not suspend Volume effect on session 0 when effects are
enabled on specific sessions.
- Adapt energy detection thresholds to new visualizer FFT range.
- Leave more time for BassBoost and Virtualizer effects to ramp up
before measuring the effect.
- Removed second insert reverb left by mistake on the player session
in preset reverb test.

Change-Id: I7a1ad1372d783fa7900eb9dd1d3b47f54d8d766f
/frameworks/base/services/audioflinger/AudioFlinger.cpp
5f37be324f93b5a4bc0d424845bab59c914cbacf 13-Sep-2011 Eric Laurent <elaurent@google.com> Issue 4345021: Audio routed to multiple devices...

There is a possiblility that the condition on which RecordThread::checkForNewParameters_l()
waits after updating the command completion status is never signalled.
This happens if the thread executing ThreadBase::setParameters() has timed out waiting
for the status (for instance if the audio HAL takes too long to execute the setParameters()
command. Then the RecordThread is stuck forever.

The fix consists in waiting for the condition with a timeout in RecordThread::checkForNewParameters_l().

Change-Id: I7fc671bc2fc43ba4acb65a2beb33ee05742f091e
/frameworks/base/services/audioflinger/AudioFlinger.cpp
0e35c78d25a8df8b3bde566ad6c474f9df242ea4 30-Aug-2011 Eric Laurent <elaurent@google.com> Merge "226483: A2DP connected, but music out to speaker"
05ce0941649c3cdd7f8034496719e607977fc005 30-Aug-2011 Eric Laurent <elaurent@google.com> 226483: A2DP connected, but music out to speaker

When the A2DP headset is connected, there is a possible
race condition when the audio tracks are moved from
the mixer thread attached to the speaker output to the thread
attached to A2DP output.
As the request to clear the stream type to output mapping cache in
the client process is asynchronous, it is possible that the flag
indicating to the client audio track to re-create the IAudioTrack
on the new thread is processed before the cache is invalidated.
In this case, the track will be attached to the old thread and
music will continue playing over the device speaker instead of being
redirected to A2DP headset.

Change-Id: Ib2ce1eb5320eaff83287b93779061bf4e7a330df
/frameworks/base/services/audioflinger/AudioFlinger.cpp
2d95dfbf4d284780035ac868651402bc39caac32 29-Aug-2011 Eric Laurent <elaurent@google.com> Audioflinger: reverse logic of BT NREC indication

The interpretation of BT NREC by AudioFlinger to enable
or disable AEC and NS was wrong: NREC to ON (default) means
the phone (Audio Gateway) must enable local AEC and NS.

Change-Id: I88a264e7fc9831c43bbace4f6b585baec73f2006
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8b4dbf7ff5589a79b56d6fe420527dbc6fd83982 23-Aug-2011 Eric Laurent <elaurent@google.com> AudioFlinger: add check for audio HAL init failure

Do not call audio HAL functions on the primary HW interface
if it could not be initialized properly.

Change-Id: If54059c8fd188d6c1686f9e0439994fe9411478a
/frameworks/base/services/audioflinger/AudioFlinger.cpp
2255a1e64f842997273071b359eab6a88a3fe113 12-Aug-2011 Marco Nelissen <marcone@google.com> Don't remove effects on session 0

b/5159902
Change-Id: Id6f29fb1c687069f7480dd81d4745a558f202226
/frameworks/base/services/audioflinger/AudioFlinger.cpp
6752ec80b25cb1f39507d18745c7e62323772cda 10-Aug-2011 Eric Laurent <elaurent@google.com> Audio effects: track CPU and memory use separately

Before this change, CPU and memory usage for an audio effect were
registered and checked against the limit by audio policy manager
upon effect instantiation. Even if an effect was not enabled
it would prevent another effect to be created if the CPU load budget
was exceeded, which was too restrictive.

This change adds a method to register/unregister CPU load only when
an effect is enabled or disabled.
It also adds a mechanism to place all effects on the global output mix
in suspend state (disabled) when an effect is enabled on a specific session.
This will allow applications using session effects to have the priority
over others using global effects.

Also fixes some issues with suspend/restore mechanism:
- avoid taking actions when an effect is disconnected and was not enabled.
- do not remove a session from the suspended sessions list when corresponding
effect chain is destroyed.

Change-Id: I5225278aba1ae13d0d0997bfe26a0c9fb46b17d3
/frameworks/base/services/audioflinger/AudioFlinger.cpp
c74b93fdf3ddb6fdab7878edab4d304fb14917f9 02-Aug-2011 Marco Nelissen <marcone@google.com> Keep effects sessions active when the caller dies.

Don't remove effects until the session they are in goes away or all
AudioEffects have been explicitly released. This allows the control
panel process to die without stopping the effects.

Change-Id: I4496e5df080230ca1af149dec95c1309ab8ea888
/frameworks/base/services/audioflinger/AudioFlinger.cpp
c993acbce63b60385b01cf1b95a4799ec308339b 08-Aug-2011 Eric Laurent <elaurent@google.com> Merge "AudioFlinger: protect input/output stream access"
828b9773cc765f45b4f61af70f2184ca85fa82f9 08-Aug-2011 Eric Laurent <elaurent@google.com> AudioFlinger: protect input/output stream access

Some methods would not check that the output orinput stream of a thread
was still valid before calling functions on its interface.
This could cause a crash if those methods where called while the output or
input was being closed by another thread.

Make sure that the output or input stream pointer is cleared before closing the
stream.
Always check that the output or input pointer is not null before calling
functions at the stream interface.
Generalize the use of initCheck() method to verify that the output or input
stream is not null.

Change-Id: I9d9ca6b744d011bcf3a7bbacb4a581ac1477bfa5
/frameworks/base/services/audioflinger/AudioFlinger.cpp
6639b559bb0147dd82cda43e794678742f712eb8 01-Aug-2011 Eric Laurent <elaurent@google.com> AudioFlinger: disable AEC and NS with BT headsets

Disable AEC and NS when the Bluetooth SCO headset in use indicates it
implements those pre processings.

Change-Id: I93f3d10b0a27243d5dbff7182639576fc0c6d862
/frameworks/base/services/audioflinger/AudioFlinger.cpp
f82fccd8ae6cd36e5934d6c05eccc8008d9e23ea 28-Jul-2011 Eric Laurent <elaurent@google.com> Audio Effect Framework: add effect suspend/restore

Add the possibility for the effect framework to suspend
(temporarily disable process) and restore audio effects.
This feature will be usefull to disable pre processing under certain
conditions and better control coexistence of audio effects
on output mix and specific sources.

Change-Id: I79b195982cc48748d5708308fb1647b9c3c34cc6
/frameworks/base/services/audioflinger/AudioFlinger.cpp
d49ead677f734fc551c0677d6d8511a18238feb3 28-Jul-2011 Eric Laurent <elaurent@google.com> Fix issue 5090721: audio record broken

Commit 6dbdc40 introduced a deadlock when exiting the
AudioFlinger RecordThread.

Change-Id: I1f63e54c5aeff05da4e4d028b53f734c62c78677
/frameworks/base/services/audioflinger/AudioFlinger.cpp
525efbb29d1198d8562a6d070e1cdf88ce721e01 27-Jul-2011 Eric Laurent <elaurent@google.com> Merge "AudioFlinger: fix crash when deleting pre process."
21b5c47ed82ab111828db6145af36f220465571c 27-Jul-2011 Eric Laurent <elaurent@google.com> AudioFlinger: fix crash when deleting pre process.

If a pre processing effect is detroyed while enabled and capture is active,
there was a possibility that the effect engine is released by the framework
while still processed by the audio HAL.

The fix consists in not releasing the engine in EffectModule::removeHandle()
but just flag the effect as being detroyed to avoid further calls to functions
on the engine effect interface.
The effect interface is then removed from the audio HAL safely in
EffectChain::removeEffect_l() while holding the EffectChain mutex.

Change-Id: I71fab30d9145062af8644f545a1f1d4d3e7e7f02
/frameworks/base/services/audioflinger/AudioFlinger.cpp
6dbdc40e9a317488fc5f6e14cf9e699bce9a9387 22-Jul-2011 Eric Laurent <elaurent@google.com> Fix issue 4604090: notification sound interrupted.

The problem is that the audio HAL fails to acquire the wake lock when playing the notification.
This is because of a change that removed the mediaserver process form the system group for honeycomb.

The fix consists in requesting the wake lock from PowerManagerService when AudioFlinger mixer
wakes up.

A consequence of this change is that audio HALs or pcm drivers do not have to hold wake locks
anymore as in the past.

Change-Id: I4fb3cc84816c9c408ab7fec75886baf801e1ecb5
/frameworks/base/services/audioflinger/AudioFlinger.cpp
1345d3307692b195be7a5a407e8fc61c4753c1d7 25-Jul-2011 Eric Laurent <elaurent@google.com> AudioFlinger: add dump of audio pre processing.

Dump of media.audio_flinger service was only listing effects on output threads.
Moved the dump of effect chains from PlaybackThread to ThreadBase class so that
pre processings on RecordThread are also listed.

Change-Id: If8bc74023c12b9c2371f1b300743b156ceca7b87
/frameworks/base/services/audioflinger/AudioFlinger.cpp
095086111f70ad538a97c7ef69f633cc74f2dbe6 22-Jul-2011 Eric Laurent <elaurent@google.com> Fix issue 4988574: 8 bit PCM audio playback broken.

Fixed regression in audio track control block frame size
calculation introduced by commit c310dcb.

Change-Id: Ia731b946ae4e43316b98d80229e3b08a696e47d6
/frameworks/base/services/audioflinger/AudioFlinger.cpp
464d5b3da21c84ba13dc69c611d40f6bed49badb 18-Jun-2011 Eric Laurent <elaurent@google.com> Audio framework: support for audio pre processing

Audio effect framework is extended to suport effects on
output and input audio path.

AudioFlinger: Support for audio effects and effect chains is
moved from PlaybackThread class to ThreadBase class so that
RecordThread can manage effects.
Effects of type pre processing are allowed on record thread
only. When a pre processing is enabled, the effect interface handle is
passed down to the input stream so that the audio HAL can call the
process function. The record thread loop calls the effect chain process
function that will only manage the effect state and commands and skip the
process function.

AudioRecord: The audio session is allocated before calling getInput() into
audio policy serice so that the session is known before the input theead is
created and pre processings can be created on the correct session.

AudioPolicyService: default pre processing for a given input source are
loaded from audio_effects.conf file.
When an input is created, corresponding effects are created and enabled.

Change-Id: Id17119e0979b4dcf189b5c7957fec30dc3478790
/frameworks/base/services/audioflinger/AudioFlinger.cpp
0bd30801c9e0abf6a8a29aab4686de7bce5a5a84 16-Jul-2011 Glenn Kasten <gkasten@google.com> Merge "Log CPU usage"
da494f962592960f2eb5111ad3f7abe1ff8732d5 09-Jul-2011 Glenn Kasten <gkasten@google.com> Log CPU usage

Change-Id: Ie447e59be139153e526b7ad467c46c659d26816f
/frameworks/base/services/audioflinger/AudioFlinger.cpp
5cc05263399fea948c3b80f83f07ff7476ef0505 24-Jun-2011 Eric Laurent <elaurent@google.com> Moved and renamed effect API header files

Moved specific effect header files to
system/media/audio_effects/include/audio_effects
and renamed to lower case (effect_xxx.h).

Change-Id: Icfc2264bfd013cab0395d7e310ada636b9fe3621
/frameworks/base/services/audioflinger/AudioFlinger.cpp
c310dcbed66026fa548f9ec0821ec15f8c6a080d 17-Jun-2011 Eric Laurent <elaurent@google.com> Added audio_bytes_per_sample() helper function

Change-Id: Ibfcd75c4c241a53d5f052c25ada091904991048a
/frameworks/base/services/audioflinger/AudioFlinger.cpp
290029d19a9d314e925b73e19453ab0497602f80 14-Jun-2011 Dima Zavin <dima@android.com> audio: update for audio/audio_policy header names/locations

Change-Id: I36c49352eee57559403cd1597f56a8485a360289
Signed-off-by: Dima Zavin <dima@android.com>
/frameworks/base/services/audioflinger/AudioFlinger.cpp
6af763bec7c3f4d50fee8dd0046409bb8a7fe8f6 05-May-2011 Glenn Kasten <gkasten@google.com> Remove dead code related to gettid

The gettid system call is always available now.

Change-Id: Ib78b41781eda182dc8605daf456bbea7ff7c2dc0
/frameworks/base/services/audioflinger/AudioFlinger.cpp
5439223b5633679edcc255651e7062046004d75d 25-May-2011 Jean-Michel Trivi <jmtrivi@google.com> Use channel mask instead of channel count for track creation

Record and playback objects (resp AudioRecord and AudioTrack)
are created using a channel mask, but this information is lost
in the mixer because only the channel count is known to
AudioFlinger. A channel count can always be derived from a
channel mask.

The change consists in:
- disambiguiting variable names for channel masks and counts
- passing the mask information from the client to AudioFlinger
and the mixer.
- when using the DIRECT ouput, only verifying the format of
the track is compatible with the output's for PCM.

Change-Id: I50d87bfb7d7afcabdf5f12d4ab75ef3a54132c0e
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8f18cf55747b8ab138661a841cbb1b2bd19f3d97 28-May-2011 Eric Laurent <elaurent@google.com> Removed interface to load audio effects libraries

Removed unused functions allowing dynamic loading of audio effects libraries
from effects factory API.

Change-Id: I06cc5a51dc10aca87c7a8687bbb874babd711eca
/frameworks/base/services/audioflinger/AudioFlinger.cpp
0fb66c2b83084a16989afaf949d0101cb6505398 18-May-2011 Eric Laurent <elaurent@google.com> New effect library API

Moved and renamed media/EffectApi.h to hardware/audio_effect.h
Modified the effect library API to expose a library info structure
containing an interface functions table.
Also removed enums for audio channels, audio format and devices
from effect API and use values from system/audio.h instead.

Modified effects factory to support new library interface format and
load libraries and efffects listed in audio_effects.conf file.
The file audio_effects.conf is first loaded from /vendor/etc and
then from /system/etc/audio_effects.conf if not found.

Modified existing effect libraries to implement the new library interface.

Change-Id: Ie52351e071b6d352fa2fbc06c3846686f8c45df9
/frameworks/base/services/audioflinger/AudioFlinger.cpp
bdd8a16282cf85bfdbe4c15adcd5c37db772de11 23-May-2011 Glenn Kasten <gkasten@google.com> Merge "HAVE_ANDROID_OS AUDIOFLINGER_SECURITY_ENABLED dead"
6ebbc077404a2ae1c82c746faa7b941901340569 13-May-2011 Eric Laurent <elaurent@google.com> Merge "Fix audio effect framework issues"
90681d6ad203119a2a6a761740dddc6c6662c542 09-May-2011 Eric Laurent <elaurent@google.com> Fix audio effect framework issues

Fix two issues in audio effect framework reported by partners.

1 - Fixed duplicated audio buffer sent to effect process function when
pausing a track.
Modified Effectchain::process_l() function to clear the effect chain
input buffer before calling the effect process functions when no track
is active on the session. Previous code was clearing the buffer after
calling the process functions and when transitioning from active
to inactive, the last processed buffer was passed again once to effect
process function before being cleared.

2 - Fixed potential mutex cross deadlock when disconnecting an effect
while playback is active. This is because EffectChain::process_l()
was calling PlaybackThread::hasAudioSession() thus creating an inversion
in the mutex lock order (EffectChain mutex locked before ThreadBase mutex).
The fix consists in removing the call to hasAudioSession() from process_l()
and requires each effect chain to keep count of the number of audio tracks
attached to it (previously only the active tracks were accounted for).

Change-Id: Iee4246694ea8c7a66c012120c629d72dd38f9c35
/frameworks/base/services/audioflinger/AudioFlinger.cpp
34bb419e5946ab28112e9e27a4d1b3928d31e0e2 11-May-2011 Dima Zavin <dima@android.com> update for new audio.h header location

Change-Id: Ic4c62c4037800802427eb7d3c7f5eb8b25d18876
Signed-off-by: Dima Zavin <dima@android.com>
/frameworks/base/services/audioflinger/AudioFlinger.cpp
f0e95696c03d9b2dca6a301a767071cf599a2845 05-May-2011 Glenn Kasten <gkasten@google.com> HAVE_ANDROID_OS AUDIOFLINGER_SECURITY_ENABLED dead

Remove dead code from the days when Android ran in emulator.

Change-Id: Ibadbbde0538239ad9b2811a3a2e8f8a6d3b6389c
/frameworks/base/services/audioflinger/AudioFlinger.cpp
2986f5bed370709c10d24c058591d775e6092d89 20-Apr-2011 Dima Zavin <dima@android.com> audioflinger: don't do work in constructor, instead do it in onFirstRef

Change-Id: I22d9e01821816c3beb52b014330386c7fd2f0411
Signed-off-by: Dima Zavin <dima@android.com>
/frameworks/base/services/audioflinger/AudioFlinger.cpp
31f18889a2c3cd5580db8d2a497a96b7b8a6fd95 19-Apr-2011 Dima Zavin <dima@android.com> audioflinger: enumerate all the possible audio interfaces

Keep track of the primary interface that handles the master volume,
etc.

Change-Id: Ib0701fccff8d8783a99035a241ab7c8ec75c00ac
Signed-off-by: Dima Zavin <dima@android.com>
/frameworks/base/services/audioflinger/AudioFlinger.cpp
24fc2fb1c541e954b83fd31ea9f786a5e9b45501 20-Apr-2011 Dima Zavin <dima@android.com> audio/media: convert to using the audio HAL and new audio defs

Change-Id: Ibc637918637329e4f2b62f4ac7781102fbc269f5
Signed-off-by: Dima Zavin <dima@android.com>
/frameworks/base/services/audioflinger/AudioFlinger.cpp
85b65f2008e7eb8ef492a63cba80555f58915769 06-Apr-2011 Glenn Kasten <gkasten@google.com> Merge "Miscellaneous code cleanup in audio framework"
ed0079ddddd4070f3369b13b274222da2e69f4b9 04-Apr-2011 Glenn Kasten <gkasten@google.com> Miscellaneous code cleanup in audio framework

Changes:
- Move declaration of kClassPathName to top of file so it can be used
in more than one place, instead of "android/media/AudioSystem".
- Make private methods static.
- Add comment to stream_type, audio_mode, force_use types that they must match
values in AudioSystem.java.
- Add comment about unused types mp3_sub_format and vorbis_sub_format.
- Fix typos.
- Use @ in javadoc comments.
- Delete dead APIs setMode, getMode, setRouting, getRouting in AudioSystem.java
(they are all hidden, deprecated, and unused by rest of framework)
- Delete unused private log method.
- Fix pathname for android_media_AudioSystem.cpp.
- Improve code formatting for space after == and !=.
- Add logging of delta for changing audio policy manager ref count.

Change-Id: I18037c7beb8ab76d1fda08c11e589f6e591d36e1
/frameworks/base/services/audioflinger/AudioFlinger.cpp
ae29b7632ecf2068698c0d121cff284dcc82f4ec 29-Mar-2011 Eric Laurent <elaurent@google.com> New fix for issue 4111672: control block flags

The first fix (commit 913af0b4) is problematic because it makes threads
in mediaserver process block on the cblk mutex. This is not permitted
as it can cause audio to skip or worse have a malicious application
prevent all audio playback by keeping the mutex locked.

The fix consists in using atomic operations when modifying the control
block flags.

Also fixed audio_track_cblk_t::framesReady() so that it doesn't block
when called from AudioFlinger (only applies when a loop is active).

Change-Id: Ibf0abb562ced3e9f64118afdd5036854bb959428
/frameworks/base/services/audioflinger/AudioFlinger.cpp
913af0b48fbc9a1e4db8411c763b339f2b09c954 17-Mar-2011 Eric Laurent <elaurent@google.com> Fix issue 4111672: AudioTrack control block flags

Make sure that all read/modify/write operations on the AudioTrack
and AudioRecord control block flags field are protected by the
control block's mutex.

Also fix potential infinite loop in AudioTrack::write() if the
written size is not a multiple of frame size.

Change-Id: Ib3d557eb45dcc3abeb32c9aa56058e2873afee27
/frameworks/base/services/audioflinger/AudioFlinger.cpp
9b3f1521b521fd7248632fed71a81423e479a523 24-Feb-2011 Gloria Wang <gwang@google.com> - To track the usage of all audio output devices
- To track the currently used audio device
- The devices are separated as speaker and other audio devices
- Provide the collected data to battery application through pullBatteryData()

Change-Id: I374c755266b5ac6b1c6c630400f4daf901ea8acc
/frameworks/base/services/audioflinger/AudioFlinger.cpp
4bb21c496b2c9427c18b8370dd631339e4e11094 01-Mar-2011 Eric Laurent <elaurent@google.com> Fix issue 3479042.

The problem is that when an AudioRecord using the resampler is restarted,
the resampler state is not reset (as there is no reset function in the resampler).
The consequence is that the first time the record thread loop runs, it calls the resampler
which consumes the remaining data in the input buffer and when this buffer is released
the input index is incremented over the limit.

The fix consists in implementing a reset function in the resampler.

A similar problem was also present for playback but unoticed because the track buffer is always
drained by the mixer when a track stops. The only problem for playback was that the initial
phase fraction was wrong when restarting a track after stop (it was correct after a pause).

Change-Id: Ifc2585d685f4402d29f4afc63f6efd1d69265de3
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8adacd8e22e2a44c941e2b930cc53b7b843f4063 04-Feb-2011 Glenn Kasten <gkasten@google.com> Merge "Bug 3366885 Remove LVMX switch"
1570aff60f8de004f0790f93bd0dfb73ee4d0ab2 04-Feb-2011 Glenn Kasten <gkasten@google.com> Bug 3366885 Remove LVMX switch

Change-Id: I0bf98c6f85f00b3296874571e1c049dcc4e2fcca
/frameworks/base/services/audioflinger/AudioFlinger.cpp
25101b0b9a84571ead15b26e9f4cd9c4298d7823 02-Feb-2011 Eric Laurent <elaurent@google.com> Fix issue 3371080

Modified default volume control logic in AudioService:
1 IN_CALL volume if in video/audio chat
2 NOTIFICATION if notification is playing or was playing less than 5s ago.
3 MUSIC

Modified silent mode:
- now also affect MUSIC stream type
- entering silent mode when VOL- hard key is pressed once while selected
stream volume is already at 0 (except for VOICE_CALL stream).
- exiting silent mode when pressing VOL+ hard key while in silent mode

Play sound FX (audible selections, keyboard clicks) at a fixed volume.

Modified audio framework:
- isStreamActive() method now implemented in AudioPolicyManagerBase (previously AudioFlinger)
- iStreamActive() now specifies a time window during which the stream is considered
active after it actually stopped.

Change-Id: I7e5a0724099450b9fc90825224180ac97322785f
/frameworks/base/services/audioflinger/AudioFlinger.cpp
67b5ed31ed1b2ab894a517e0f3d3ee8fbbfdaf16 20-Jan-2011 Eric Laurent <elaurent@google.com> Fix issue 3371096.

EffectModule::process() was copying effect chain input buffer to
output buffer if no effect was active instead of accumulating it.

Change-Id: I2838af2e7b6654d0a76547625929a5453da68d02
/frameworks/base/services/audioflinger/AudioFlinger.cpp
01635943012f82ed714f00ee357003519f3de45d 19-Jan-2011 Eric Laurent <elaurent@google.com> Tentative fix for issue 3362362.

The problem is likely that one method is called on the AudioPolicyManagerBase
instance while it is still being constructed by AudioPolicyService.

To avoid this, the AudioPolicyService mutex is held by the constructor until the
platform specific AudioPolicyManager is constructed and the member
mpPolicyManager initialized.

Also added an initCheck() method to AudioPolicyInterface to verify successful
initialization of AudioPolicyManager.

A similar change is done in AudioFlinger constructor.
Also added some missing protections in AudioFlinger methods where the
playback thread list is parsed.

Change-Id: I006b244ec057e1bb0aa5ebe426ef006e3b171056
/frameworks/base/services/audioflinger/AudioFlinger.cpp
f3d6dd0782e3135885efdc26cb86cf0bf811749f 18-Nov-2010 Eric Laurent <elaurent@google.com> Fix issue 3157123.

Use a Mutex wherever atomic operations were used in AudioTrack,
AudioRecord, AudioFlinger and AudioEffect classes.

Change-Id: I6f55b2cabdcd93d64ef19446735b8f33720f8dbc
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8f677d66d9c3ba34c97e69b2bb9e161f129af0ee 15-Nov-2010 Jean-Michel Trivi <jmtrivi@google.com> Add new audio mode for audio communications other than telelphony.

The audio mode MODE_IN_CALL signals the system the device a phone
call is currently underway. There was no way for audio video
chat or VoIP applications to signal a call is underway, but not
using the telephony resources. This change introduces a new mode
to address this. Changes in other parts of the system (java
and native) are required to take this new mode into account.
The generic AudioPolicyManager is updated to not use its phone
state variable directly, but to use two new convenience methods,
isInCall() and isStateInCall(int) instead.

Change-Id: Id744cd26520ea1d1a4795eabe6a1f0c58789af76
/frameworks/base/services/audioflinger/AudioFlinger.cpp
9a30fc13f55ca55bc0409f8a9d2e77d5a803bb7c 05-Oct-2010 Eric Laurent <elaurent@google.com> Fixed AudioFlinger not always pausing tracks

If the pause request is received before the AudioTrack buffer was
completelly filled and the track ready for mixing, the pause is
not executed: the track just underruns and stays in pausing state.

The fix consists in considering the track ready for mixing immediately
if pausing.

Change-Id: Ia6cb4703fee2126e41011a6400ea8eeb3a3e5456
/frameworks/base/services/audioflinger/AudioFlinger.cpp
4712baab81d0b683bc22668d2278c9daff92797e 01-Oct-2010 Eric Laurent <elaurent@google.com> Issue 3032913: improve AudioTrack recovery time

This issue showed that when an AudioTrack underruns during a too long period
of time and is therefore disabled by audioflinger mixer, it takes an additional
delay of up to 3 seconds to recover.
This fix adds a simple mechanism to recover immediately when the client application
is ready to write data again in the AudioTrack buffer

Also throttle warnings on record overflows

Change-Id: I8b2c71578dd134b9e60a15ee4d91b70f3799cb3d
/frameworks/base/services/audioflinger/AudioFlinger.cpp
4fd3ecc1f0b8d95f52b516cd81fe4f06607d5cb0 28-Sep-2010 Eric Laurent <elaurent@google.com> Fix several audio effects problems.

Fixed the following issues in LVM effect bundle wrapper:
- memory leaks in EffectCreate() in case effect creation fails at various stages
- Added saturation when accumulating to output buffer
- Fixed problems with enabled effects count when an effect is released while enabled
- Do not allocate temporary buffer for accumulation each time process() is called

Fixed the following issues in effects framework (AudioFlinger)
- Release effect synchronously in the library when deleted from effect chain
- Do not call the effect process function if no tracks are present in the same
audio session

Change-Id: Ifbd80a163415cfb3c0a337c12082853ea45d9c91
/frameworks/base/services/audioflinger/AudioFlinger.cpp
98c92599acebb8ca893d54d3dc4c96a0c037f0a8 24-Sep-2010 Eric Laurent <elaurent@google.com> Fix issue 3007862

Removed a cross deadlock condition between audioflinger and audio policy
service mutexes.
Audioflinger::createEffect() locks audioflinger mutex and then calls
AudioSystem::getOutputForEffect() which ends up in
AudioPolicyService::getOutputForEffect() which locks audio policy service
mutex. If at the same time, the command thread in audio policy service is
processing a command(set volume, set route...), the mutex is locked and the
command will call one audioflinger method which in turn will attempt to
lock audioflinger mutex.
The fix consists in releasing audioflinger mutex before calling
getOutputForEffect().

Change-Id: Id44e7feb36e0a295731f6aa97cf32d022edd34d0
/frameworks/base/services/audioflinger/AudioFlinger.cpp
14beea487c065ca902bfd7089399eb71a805e302 22-Sep-2010 Eric Laurent <elaurent@google.com> Request permission for global audio effects.

Applications creating an audio effect on the output mix must
have the MODIFY_AUDIO_SETTINGS permission.

Change-Id: I57d88533f91ad0d33680107d79abcec28f7263b5
/frameworks/base/services/audioflinger/AudioFlinger.cpp
27a2fdfb8ad1606bdb686c35e30ae894dd037588 11-Sep-2010 Eric Laurent <elaurent@google.com> Fix volume problems with insert revert

- Use a constant input level to the reverb engine and implement volume control in the
insert reverb. This avoids the volume spikes when an effect that was inserted after
the reverb is disabled or removed.
- Fix clicks (one silent buffer) at the end of the reverb disable period.
- Modified volume management in audioflinger so that the volume ramp is also done by
the insert effect if present when the track is paused (avoids clicks).
- Increased room level for all presets.

Also fixed problems with output stage session (-1):
- effect bundle wrapper was not designed to support session -1
- the permission check in audioflinger for using session -1 failed due to a wrong usage of
getCallingPid()

Change-Id: Id1ff51327263364bf71d3f2668fa5cde4311d84f
/frameworks/base/services/audioflinger/AudioFlinger.cpp
e65280c5528d38a88fee6366328cf57dbe5a047f 02-Sep-2010 Eric Laurent <elaurent@google.com> Fix problem in AudioEffect::command() status.

The *pReplyData argument of the command() function was left unitialized by EffectHandle::command()
when command was EFFECT_CMD_ENABLE, EFFECT_CMD_DISABLE and EFFECT_CMD_SET_PARAM_COMMIT.

Change-Id: I91a19817ead2a8cfbdd8e2d77ca270c7ce9d5bd4
/frameworks/base/services/audioflinger/AudioFlinger.cpp
a92ebfa1cd96dc91174f68baab820dbed8239e4b 31-Aug-2010 Eric Laurent <elaurent@google.com> Audio Effects: fix problems in volume control.

- Fixed click when re-enabling effect during the turn off phase:
make sure the effect states where effect is processed are the same
where volume control is delegated to effect.
- Fixed click when effect is deleted while still active: do not apply
volume ramp if an effect having volume control was just removed from the
effect chain.

Also fixed a crash when PCM dump is enabled in effect bundle wrapper.

Change-Id: Ib562f5cf75c69af75df0e862536262e2514493e4
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8448a79767b7dfc53a12502661cba89774733c10 19-Aug-2010 Eric Laurent <elaurent@google.com> Fix issue 2929440

Fixed regression introduced by change a54d7d3d7dd691334189aab20d23c65710092869 in audioflinger mixer thread:
When the output stream is suspended, the sleep time between two writes must match the actual duration
of one output stream buffer otherwise the playback rate is not respected.

Change-Id: Ic5bebe890290d1f44aeff9dd3c142d18e26fff2a
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8cc93b9b21310bd49d293152e4d68cedce8a72ef 11-Aug-2010 Eric Laurent <elaurent@google.com> Fix issue 2909189: System property ro.audio.silent no longer mutes system.

Fixed regression introduced by commit 2a6b80bc65c4782b5a7168b300e1dc5ec9f617ee:
master mute was not working if no effect chains were present on session 0.

Change-Id: I66d107e045d159cb94d29c7476fa1e12d92f2ae7
/frameworks/base/services/audioflinger/AudioFlinger.cpp
2a6b80bc65c4782b5a7168b300e1dc5ec9f617ee 30-Jul-2010 Eric Laurent <elaurent@google.com> Fixed several audio effects problems.

- Fixed constant inversions in AudioEffect.java
- Do not return error when enabling an already enabled effect
- Update cached effect state in native AudioEffect class when effect is enabled/disabled by command() method
- Remove click when restarting effect during disable sequence
- Fixed problem in master mute management when volume control is delegated to effect.

Change-Id: I6df4ce9fcc54fdc7345df858f639d20d802d6712
/frameworks/base/services/audioflinger/AudioFlinger.cpp
a54d7d3d7dd691334189aab20d23c65710092869 29-Jul-2010 Eric Laurent <elaurent@google.com> Fixed underrun in audioflinger mixer.

When all audio tracks have been disabled and the mixer is running idle before the output stream is placed in standby,
the mixer sometimes fails to write to the output stream on time to avoid underrun.

This is because the sleep period used to wait before the next write to output stream is too close to the actual buffer duration.
In fact this sleep time is not critical as if we write too early to the output stream, the kernel driver will wait for free buffers
from the audio DSP DMA and we will sleep anyways.

The fix consists in dividing the calculated wait period by 2 to increase the margin.

Change-Id: I5730887dc2ccce2a511bc858494a6f7da6b392a0
/frameworks/base/services/audioflinger/AudioFlinger.cpp
493941b8d8a12ee843d9823c0177f8005a7be54f 28-Jul-2010 Eric Laurent <elaurent@google.com> Allow creation of an audio effect on a session with no audio tracks.

This is necessary to allow creating and enabling an effect attached to a particular player
session before the playback is started. As a matter of fact, the implementation of the mediaplayer
does not create the AudioTrack before playback starts.

Change-Id: I1266e8885f9d756acc949303321aaac0fbf83e34
/frameworks/base/services/audioflinger/AudioFlinger.cpp
a4c72acfbc6c06588dd26cf41e67a834fc0a54f9 28-Jul-2010 Eric Laurent <elaurent@google.com> Audio effects: modified command() parameter types.

The type of the cmd, cmdSize and *pReplySize parameters of the effect control interface command()
function have been modified from int to uint32_t. This is more consistent with their role.

Change-Id: I84d289fc262d6753747910f06f485597dfee6591
/frameworks/base/services/audioflinger/AudioFlinger.cpp
8ed6ed0b6216a9dfcbcd6a5ba6a62d28a901baec 13-Jul-2010 Eric Laurent <elaurent@google.com> Audio policy manager changes for audio effects

Added methods for audio effects management by audio policy manager.
- control of total CPU load and memory used by effect engines
- selection of output stream for global effects
- added audio session id in parameter list for startOutput() and stopOutput().
this is not used in default audio policy manager implementation.

Modifications of audio effect framework in AudioFlinger to allow moving and reconfiguring
effect engines from one output mixer thread to another when audio tracks in the same session
are moved or when requested by audio policy manager.
Also fixed mutex deadlock problem with effect chains locks.

Change-Id: Ida43484b06e9b890d6b9e53c13958d042720ebdb
/frameworks/base/services/audioflinger/AudioFlinger.cpp
0d7e048cf2e38d32568261760aef82d1ee145126 19-Jul-2010 Eric Laurent <elaurent@google.com> Fixed problems in audio effect volume control.

Fixed the following problems in audio effect volume control in AudioFlinger:
- Make sure that the volumes returned by EffectChain::setVolume_l() are correct even is
no change is detected since last call
- Do not use isEnabled() to validate volume control but mState >= ACTIVE instead as the volume control
must be also active in STOPPING and STOPPED states.

Change-Id: Id62da3164fad500ee8a5efd6cd78c77e8fdcb541
/frameworks/base/services/audioflinger/AudioFlinger.cpp
76c40f74ced0b034a534ebc31ab9616425d3e711 15-Jul-2010 Eric Laurent <elaurent@google.com> Several improvements in audio effects volume control.

- Fixed crash when deleting an effect chained before an effect having volume control
- Changed EFFECT_FLAG_VOLUME_CTRL to implicitely include EFFECT_FLAG_VOLUME_IND
(not need to set both in effect descriptor).
- Volume control changes from one effect to another if needed according to effect enable state
- EFFECT_CMD_SET_VOLUME is only sent when their is an actual change in volume

Change-Id: Ieebaf09157e2627366023569d95516646e03e26c
/frameworks/base/services/audioflinger/AudioFlinger.cpp
24651682edaf71e8a826f23a7ea09bc97c8072c4 15-Jul-2010 Mathias Agopian <mathias@google.com> added BinderService<> template to help creating native binder services

Change-Id: Id980899d2647b56479f8a27c89eaa949f9209dfe
/frameworks/base/services/audioflinger/AudioFlinger.cpp
08e83bb3b7cc41f603867acbeb1168019cf535fe 15-Jul-2010 Mathias Agopian <mathias@google.com> move native services under services/

moved surfaceflinger, audioflinger, cameraservice

all native services should now reside in this location.

Change-Id: Iee42b83dd2a94c3bf5107ab0895fe2dfcd5337a8
/frameworks/base/services/audioflinger/AudioFlinger.cpp