• Home
  • History
  • Annotate
  • only in /frameworks/av/services/audioflinger/
History log of /frameworks/av/services/audioflinger/
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
c4640c9eef850bb1c754bd6b477f1cc8350c6081 23-Oct-2012 Glenn Kasten <gkasten@google.com> Increase allowed number of VHQ resamplers to 3

Bug: 7378660
Change-Id: I69e33ca2eb4bb9bd38e2c63df62cd1130d68baf6
udioResampler.cpp
61ea117b03b53382b5ecbc33004c7d37ea70ea8b 21-Oct-2012 Mathias Agopian <mathias@google.com> Fix a typo that caused the high quality resampler to produce garbage

the problem is that if libaudio_resampler is present, it is those
coefficients that will always be selected, but the correct
meta-data.

Bug: 7385994
Change-Id: Ieebeb37b4dfb62a1a051bc29fae2ce056dbc6621
udioResamplerSinc.cpp
291f824e02ff517a34cfe50220b4e2b402ee998d 19-Oct-2012 Glenn Kasten <gkasten@google.com> Remove active track when thread goes to standby

Bug: 7369232
Change-Id: I7ff9f525dad4be0aef562a53015b06ee7d3d50f1
udioFlinger.cpp
a045dcafd2b77036210f5b72e79d745ad4c1b848 16-Oct-2012 Jean-Michel Trivi <jmtrivi@google.com> Fix track estimation for presentation complete

Audio tracks were not using the right latency estimation for
signalling the completion of their presetation. This caused
the synchronization mechanism between playback and record to be
off, and a synchronized recording would contain some of the audio
that was meant to be over once recording would start.
Use the playback thread's latency reporting which takes the audio
pipe into account.

Bug 7237669

Change-Id: I23a907a53ad0b0d68d246789ec595a77a79fced5
udioFlinger.cpp
d7086030fcf731e4bcef6c033cc6418cd04e6b91 10-Oct-2012 Jean-Michel Trivi <jmtrivi@google.com> Support querying active record sources

Add support for querying whether there is currently a recording
underway from the specified audio source.

Bug 7314859

Change-Id: I986b231a10ffd368b08ec2f9c7f348d28eaeb892
udioPolicyService.cpp
udioPolicyService.h
bac4a4a9073a440bc6df7ca2306604819aa1c342 09-Oct-2012 Eric Laurent <elaurent@google.com> audio policy: deprecate ro.camera.sound.forced

The volume and routing policy of AUDIO_STREAM_ENFORCED_AUDIBLE is
now controlled by AudioService.

Do not read ro.camera.sound.forced is not needed anymore.

Bug 7032634.

Change-Id: Ic0a6396fc4b6efb91cdb4dffe0c8eb035d0440bd
udioPolicyService.cpp
c8823995d16b909fae30ff4f94217e875d3e8c8a 01-Oct-2012 ty.lee <ty.lee@lge.com> audioflinger/resampler: add build source for libaudio-resampler

Bug: 7229644
Change-Id: I93bde36be1c3ec84174a4c98423e28f8b3d8782f
Signed-off-by: ty.lee <ty.lee@lge.com>
Signed-off-by: Iliyan Malchev <malchev@google.com>
ndroid.mk
ac6020508acedd316391dee42329040bf45f8d90 01-Oct-2012 Glenn Kasten <gkasten@google.com> Integrate improved coefficient sinc resampler: VHQ

Summary:
Very high quality is enabled only for 44.1 -> 48 or 48 -> 44.1,
and uses low quality for all other use cases.
Track estimated CPU load and throttles the quality based on load;
as currently configured it should allow up to 2 instances of very high quality.
Medium quality and high quality are currently disabled unless explicitly requested.

Details:
Only load .so the first time it is needed.
Cleanup code style: formatting, indentation, whitespace.
Restore medium quality resampler, but it is not used (see next line).
Fix memory leak for sinc resampler.
Check sample rate in resampler constructor.
Add logs for debugging.
Rename DEFAULT to DEFAULT_QUALITY for consistency with other quality levels.
Renumber VERY_HIGH_QUALITY from 255 to 4.
Use enum src_quality consistently.
Improve parsing of property af.resampler.quality.
Fix reentrancy bug - allow an instance of high quality and an instance
of very high quality to both be active concurrently.

Bug: 7229644
Change-Id: I0ce6b913b05038889f50462a38830b61a602a9f7
ndroid.mk
udioMixer.cpp
udioResampler.cpp
udioResampler.h
udioResamplerCubic.h
udioResamplerSinc.cpp
udioResamplerSinc.h
087dd8e7232e4c009e9121ab7e8c37985522c9ad 27-Sep-2012 Glenn Kasten <gkasten@google.com> Disable audio watchdog

It's not critical, and is wasting power

Bug: 7241714
Change-Id: I6ad4375f0000c92529688723dbe0ff0caa809c5d
ndroid.mk
udioFlinger.cpp
2bfc6b42b3733c12485dd51ed95191956abc3e4e 28-Sep-2012 Jean-Michel Trivi <jmtrivi@google.com> bug 7253033 clean up before closing an output

An output can only be closed if there is no lock contention that
prevents ThreadBase::exit() from being blocked. If an output
device is waiting for an operation to complete (here a write
in the remote_submix module, because the pipe is full), signal
the module that it's entering the "exiting" state.

Change-Id: I8248add60da543e90c25a4c809866cdb26255651
udioFlinger.cpp
udioFlinger.h
76b111685010e1fea7c0a865c038aee35507fde4 17-Jan-2012 SathishKumar Mani <smani@codeaurora.org> audioflinger: use resample coefficients from audio-resampler library.

-Add a separate quality VERY_HIGH_QUALITY in resampler
-Use resample coefficients audio-resampler library for
quality VERY_HIGH_QUALITY.
-This improves the quality of resampled output.

Bug: 7024293
Change-Id: Ia44142413bed5f5963d7eab7846eec877a2415e4
Signed-off-by: Iliyan Malchev <malchev@google.com>
ndroid.mk
udioResampler.cpp
udioResampler.h
udioResamplerSinc.cpp
udioResamplerSinc.h
12bff5dd87e6b863482e6bfd9f4561078ebcf3f0 24-Sep-2012 SathishKumar Mani <smani@codeaurora.org> audioflinger/resampler: Add VERY_HIGH_QUALITY audio-resampler

Change-Id: I34f5d36ae60010ec64222d6660d10a84da3bf566
Bug: 7024293
Signed-off-by: Iliyan Malchev <malchev@google.com>
udio-resampler/Android.mk
udio-resampler/AudioResamplerCoefficients.cpp
udio-resampler/dnsampler_filter_coefficients_x128_10112011.h
udio-resampler/resampler_filter_coefficients_10042011.h
842c5d9553f3f8e97d04ed1bd0d37e4851240654 26-Sep-2012 Glenn Kasten <gkasten@google.com> Revert "Don't wait for presentation complete if terminated"

This reverts commit 44cda3a4e7ca3de0db9cb49145def3803b03ebb4

Change-Id: I7fd29b77690dab057ac966a42fb198b2772f092c
udioFlinger.cpp
cc0f1cfb69ce8b8985fc2c0984847a06a13ad22d 24-Sep-2012 Glenn Kasten <gkasten@google.com> Implement android.media.AudioManager.getProperty()

Bug: 6635041
Change-Id: I3386a4a6c226bc4eceaf65556119e4fb15f73224
udioFlinger.cpp
udioFlinger.h
b6ba2fd0d61a4844c153e17843fbe2c841c4bf57 25-Sep-2012 Eric Laurent <elaurent@google.com> audioflinger: improve record start and thread exit

Use broadcast() instead of signal() on the
thread wake up condition when starting record or requesting thread
exit to make sure that if another thread is waiting for the same
condition (e.g binder thread calling setParameters()) the mixer
thread will be woken up.

Bug 7184317.

Change-Id: I3154a4509ca7af6ffae5236e522b0fab8e75ed06
udioFlinger.cpp
8d452f1c61aa70c4a86c4114532f2c0983120ef8 24-Sep-2012 Glenn Kasten <gkasten@google.com> Merge "Check clock_gettime(CLOCK_MONOTONIC) for failure" into jb-mr1-dev
80b3273cea8660fe8a5868d024d2788a1e083ffc 24-Sep-2012 Glenn Kasten <gkasten@google.com> Check clock_gettime(CLOCK_MONOTONIC) for failure

Bug: 7100774
Change-Id: I15a84a19bb6d6ef1d9dac4beaa03587638196404
astMixer.cpp
1afc26db11b71c43f63a0f72a45a803f1a7910dd 24-Sep-2012 Eric Laurent <elaurent@google.com> fix end of track presentation on suspended output

The code detecting the end of an audio track presentation before
removing it from the active track list is based on the
count of audio frames sent to audio HAL. When an output stream
is suspended (e.g. A2DP when SCO is active), this count does not
change and a track in stopped state will never be removed from
active track list causing the mixer thread to never release
the wake lock.

The fix consists in incrementing the audio HAL frame count even
if the output is suspended.

Also fix a problem in getRenderPosition() when the output is suspended.

Bug 7167534.

Change-Id: I3be836cbbea29b65dc087199cac6a1cd84c0a41d
udioFlinger.cpp
896adcd3ae6a1c7010e526327eff54e16179987b 13-Sep-2012 Eric Laurent <elaurent@google.com> audioflinger: send priority request from a thread

When creating a fast AudioTrack, a request is sent to SchedulingPolicyService
to elevate the requesting thread priority. This generates a binder
call into system_server process and to a JAVA service via JNI.
If the thread from which the track was created is in the system_server
process and does not have the "can call java" attribute, a crash occurs because
the binder optimization reuses the same thread to process the returning binder
call and no JNI env is present.

The fix consists in sending the priority change request from the AudioFlinger
mixer thread, not from the binder thread.

This also reverts the workaround in commit 73431968

Bug 7126707.

Change-Id: I3347adf71ffbb56ed8436506d4357eab693078a3
udioFlinger.cpp
udioFlinger.h
4362f5300162ed55f56cf167eccf7f2e5b89d435 13-Sep-2012 Jean-Michel Trivi <jmtrivi@google.com> Handle audio HAL returning 0 bytes in record thread

Enter standby when HAL returns an error, but also consider 0 bytes
returned as NOT_ENOUGH_DATA.

Change-Id: Ica83142310e9c176f936e0440571a6034cbc575f
udioFlinger.cpp
52762410dbc9189cd92a4094a1dbd4cfe8e71cb6 13-Sep-2012 Jean-Michel Trivi <jmtrivi@google.com> Don't deadlock on AudioRecord start when reads return 0

When calling start() on an AudioRecord with a HAL that
returns 0 on a read() operation, the start blocking
condition was never unblocked.
Add a boolean to track the first read operation so the returned
number of bytes (mBytesRead) is only evaluated after that
first read.

Change-Id: I8c735a00d48cd6a0da467ccdf75d3616b38f6afa
udioFlinger.cpp
fe3156ec6fd9fa57dde913fd8567530d095a6550 11-Sep-2012 Jean-Michel Trivi <jmtrivi@google.com> Communicate audio session ID to downmixer

The audio downmixer effect might need the audio session Id, pass it
from the track creation in AudioFlinger to the downmix effect
creation in AudioMixer.

Change-Id: I5e29540542ae89cf4a0cdb537b3e67f04442a20a
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
astMixer.cpp
6ce3d19cd35a49add6893298f70b87917fc60d52 09-Sep-2012 Glenn Kasten <gkasten@google.com> Merge "Add outlier statistics for fast mixer cycle times" into jb-mr1-dev
1ab212cf5cfa5b88c801840e11e3191cd10f48e4 07-Sep-2012 Glenn Kasten <gkasten@google.com> Add outlier statistics for fast mixer cycle times

Change-Id: I31c964caeb8b5d9ae0a426224f030cdcb01114a0
astMixer.cpp
f1c04f952916cf70407051c9f824ab84fb2b6e09 28-Aug-2012 Eric Laurent <elaurent@google.com> audioflinger: changes for new audio devices enums

The ThreadBase class now has a separate member for input
and output devices (mInDevice, mOutDevice).

Only query get_supported_devices() from audio HAL if the function
is exposed and if the audio policy manager did not specify the
audio module to open.

Also fixed bug in AEC preprocessing that would reset
to default output device when an input device was given.

Change-Id: I19d4d06aeb920b068e3ef31e6e6be6345ce5d67a
udioFlinger.cpp
udioFlinger.h
57b2dd1e78af53115985f18d31ec5421c9da947e 01-Sep-2012 Eric Laurent <elaurent@google.com> AudioFlinger: send audio source to audio effects

Added support for EFFECT_CMD_SET_AUDIO_SOURCE audio effect
command to inform preprocessings of current audio source
selection for capture.

Change-Id: Ib2418a9aa8114e8457fe828ecd43b230ed86cdd6
udioFlinger.cpp
udioFlinger.h
c3ae93f21280859086ae371428ffd32f39e76d50 30-Jul-2012 Glenn Kasten <gkasten@google.com> Update audio comments

Change-Id: Ie7504d0ddb252f7e4d4f99ed0b44cfc7b1049816
udioFlinger.cpp
udioFlinger.h
7aa25591769685ae0e8349b3ca3534c724484375 03-Aug-2012 Glenn Kasten <gkasten@google.com> Remove dead code

RecordThread::isValidSyncEvent() returns false, so most of
RecordThread::setSyncEvent() is never executed.

Change-Id: I0cf848beb46a367a45126d2df3073c5afa2ca59c
udioFlinger.cpp
2dd4bdd715f586d4d30cf90cc6fc2bbfbce60fe0 29-Aug-2012 Glenn Kasten <gkasten@google.com> Move libnbaio out of AudioFlinger

libnbaio is now a separate shared library from AudioFlinger, rather
than a static library used only by AudioFlinger.

AudioBufferProvider interface is now also independent of AudioFlinger,
moved to include/media/

Change-Id: I9bb62ffbc38d42a38b0af76e66da5e9ab1e0e21b
ndroid.mk
udioBufferProvider.h
udioBufferProviderSource.cpp
udioBufferProviderSource.h
udioFlinger.cpp
udioFlinger.h
udioMixer.h
udioResampler.h
udioStreamInSource.cpp
udioStreamInSource.h
udioStreamOutSink.cpp
udioStreamOutSink.h
xtendedAudioBufferProvider.h
astMixerState.h
ibsndfileSink.cpp
ibsndfileSink.h
ibsndfileSource.cpp
ibsndfileSource.h
onoPipe.cpp
onoPipe.h
onoPipeReader.cpp
onoPipeReader.h
BAIO.cpp
BAIO.h
ipe.cpp
ipe.h
ipeReader.cpp
ipeReader.h
ourceAudioBufferProvider.cpp
ourceAudioBufferProvider.h
oundup.c
oundup.h
0c676cd04ff15cc7eacf6144b4aead6deaccf60c 22-Aug-2012 Glenn Kasten <gkasten@google.com> Make tee sink compile OK again

Change-Id: Ie865ceeabaeb698a62c11eac9f96e303c44c28ae
ipeReader.cpp
ipeReader.h
106e8a42038f9e90d5ff97f8ab6f1a42258bde9e 02-Aug-2012 Glenn Kasten <gkasten@google.com> const methods

Change-Id: I92e32ee16274c032c9d0ce910676be2a7fa52471
udioFlinger.cpp
udioFlinger.h
0dbb356050d0db9e0043dd43045c1864a933332b 03-Aug-2012 Glenn Kasten <gkasten@google.com> Simplify AudioFlinger::PlaybackThread::isValidSyncEvent()

Change-Id: I3e4af69b929d4ca04afaac26c7e41c89fce25b9c
udioFlinger.cpp
d23eedca9b5a1812891c05d89850ab7ee707040d 02-Aug-2012 Glenn Kasten <gkasten@google.com> Discard setSyncEvent() return value

setSyncEvent() returns a status_t which is sometimes ignored.
Emphasize this is intentional by casting to void.

Change-Id: Ic614988347cba36bd2504d7ad321594a355b0d9d
udioFlinger.cpp
a959904968f1d300fe86334bf5099ae2dc39ee28 13-Aug-2012 Glenn Kasten <gkasten@google.com> Merge "Replace hard-coded "2" by a constant and comment" into jb-mr1-dev
fcfc61da927e98d18cdcb53da8fa0a8a32ee1422 10-Aug-2012 Jean-Baptiste Queru <jbq@google.com> am ff4c64d6: am c64a1787: Merge "Fix initialization of audio mixer track resources for MIPS."

* commit 'ff4c64d6b1b58494a1b15f1a664e5c421d095d15':
Fix initialization of audio mixer track resources for MIPS.
3ed292031dc50c56110cdadb1e3778117e3be76a 08-Aug-2012 Glenn Kasten <gkasten@google.com> Replace hard-coded "2" by a constant and comment

Bug: 6679403
Change-Id: I6c2701f9afedc26540dfad0b4e23348bbc4cb01a
udioFlinger.cpp
0d27c65ddb5c968baa6db0c26e80f5c451bc52bc 07-Aug-2012 Glenn Kasten <gkasten@google.com> Tune the overrun correction

The new overrun correction is: if the previous write() cycle time is <
50% of expected, then sleep enough extra to make the total cycle time =
95% of expected. This should help compensate for HAL implementations
that have uneven cycle times due to sample rate conversion.

Bug: 6881638
Change-Id: I5ab58afdfceee7ac523177f021fbf62d743d571a
astMixer.cpp
2c3b2da3049627264b7c6b449a1622f002210f03 03-Aug-2012 John Grossman <johngro@google.com> AudioFlinger: fix timed audio

(cherry picked from commit e20ac92c564a2f4e8123885807abdf0a78de0dd7)

> AudioFlinger: fix timed audio
>
> Addresses Bug 6900517.
>
> Finish up support for timed audio in the new FastMixer world. Pay special
> attention to remaining lock-less and voluntary yield free on the FastMixer
> thread. This fixes audio playback for Q on JB.
>
> Change-Id: Iaf815e58a1b1d0a0190051794bec8dc5c9231785
> Signed-off-by: John Grossman <johngro@google.com>

Change-Id: I9bd687acc345a05867af48e71116690fdb0ce1b5
Signed-off-by: John Grossman <johngro@google.com>
udioBufferProviderSource.cpp
udioBufferProviderSource.h
udioFlinger.cpp
udioStreamOutSink.cpp
udioStreamOutSink.h
astMixer.cpp
onoPipe.cpp
onoPipe.h
onoPipeReader.cpp
onoPipeReader.h
BAIO.cpp
BAIO.h
ourceAudioBufferProvider.cpp
ee578c0330319f04a48bccbdb26b53fea0388d04 24-Jul-2012 John Grossman <johngro@google.com> AudioFlinger: Better handling for master volume/mute

(cherry picked from commit 93d906837e0e89aa1d9c913ab2b531b809f9bb9e)

> AudioFlinger: Better handling for master volume/mute
>
> Changes to address bug 6842827.
>
> When a HAL is loaded, cache whether or not the HAL supports
> set_master_volume/mute in the AudioHwDevice structure. Store an
> AudioHwDevice in AudioStream(In|Out) structures instead of just an
> audio_he_device_t. This give threads (PlaybackThreads in
> particular) access to the cached capabilities.
>
> When setting master volume/mute, change the system to always set the
> setting on all HAL which support it and also to set the setting on all
> PlaybackThreads. Change PlaybackThreads to apply the setting at the
> in SW mix stage of the pipeline if its assigned HAL does not support
> the setting, or to ignore the setting of the assigned HAL does support
> it.
>
> Change-Id: Ia14137a30b4c3ee6f2d7ddcc8cba87bf5eec87f4
> Signed-off-by: John Grossman <johngro@google.com>

Change-Id: Icb6bc13764e100a2003eb1dee2231132ab287d98
Signed-off-by: John Grossman <johngro@google.com>
udioFlinger.cpp
udioFlinger.h
d8f178d613821c3f61a5c5e391eb275339e526a9 20-Jul-2012 John Grossman <johngro@google.com> Change audio flinger to user HAL master mute if available

(cherry picked from commit 91de9b56282d126ffb36344266af5fee3cefcfdd)

> Change audio flinger to user HAL master mute if available
>
> Hand merge from ics-aah
>
> > Change audio flinger to user HAL master mute if available: DO NOT MERGE
> >
> > Replicate the pattern used for HAL master volume support to make use
> > of master mute support if the HAL supports it. This is part of the
> > change needed to address bug 6828363. Because of the divergences
> > between ICS and master, this change will need to be merged by hand.
> >
> > Signed-off-by: John Grossman <johngro@google.com>
> > Change-Id: I6d83be524021d273d093bcb117b8f2fe57c23685
>
> Change-Id: I32280582905c969aaec2bb166ec5c61df82d737a
> Signed-off-by: John Grossman <johngro@google.com>

Change-Id: I5cd709187221d307fe25c5117ccaadca5f6b197b
Signed-off-by: John Grossman <johngro@google.com>
udioFlinger.cpp
udioFlinger.h
3c0a0e8541846427db0587c2fffb90f60ee680b0 02-Aug-2012 Paul Lind <plind@mips.com> Fix initialization of audio mixer track resources for MIPS.

The value 1 << 32 (maxNumTracks defaults to 32) is surprisingly not defined
in C, and differs on MIPS than the other arch.

Therefore the track resources were not initialized properly, resulting
in failure to play any audio.

The fix allows the mConfiguredNames bitmask to be correctly set to all
1's in the 32-track case, for all arch.

Change-Id: Ied3e1305952e9567602e2cd76c5ef3acb0809ee0
Signed-off-by: Paul Lind <plind@mips.com>
udioMixer.cpp
44cda3a4e7ca3de0db9cb49145def3803b03ebb4 01-Aug-2012 Glenn Kasten <gkasten@google.com> Don't wait for presentation complete if terminated

Change-Id: Ia04cf6c620693457dca87b4ffea5dd0fe71efdce
udioFlinger.cpp
510a3d6b8018a77683dac466127ffd0af34bef6e 16-Jul-2012 Glenn Kasten <gkasten@google.com> Start adding support for multiple record tracks

Replace single mTrack by vector mTracks.
Destroy record tracks similarly to playback tracks.
Dump all record tracks, in addition to the active record track.

Change-Id: I503f10b51928b6b92698fe1c51a9ddd3215df1f4
udioFlinger.cpp
udioFlinger.h
0ec23ce0d1ff79566c402bc30df3074f6e25a22b 10-Jul-2012 Glenn Kasten <gkasten@google.com> Clean up start() parameters

Document where int is used instead of AudioSystem::sync_event_t
(probably because of a header file dependency).
TrackBase::start() and RecordTrack::start() don't need default parameters.

Change-Id: I82f4a4d078be900f3aa4bd926697e32f5ed68ec8
udioFlinger.cpp
udioFlinger.h
e4e2a37dbe2a4d923232305549101f779a2e3638 23-Jul-2012 Glenn Kasten <gkasten@google.com> Extract methods to enter standby and standby mode

Also move initial standby from to threadLoop to avoid a race condition.

Change-Id: I65afca83c36fb41b983b3b1d3dab35d4029560e3
udioFlinger.cpp
udioFlinger.h
0a7af18d0308295405491f86603e3d119450aba0 10-Jul-2012 Glenn Kasten <gkasten@google.com> Use valueAt instead of editValueAt when possible

Change-Id: I885b169f4b176a6b5c2ca9a534214b4ffff1700e
udioFlinger.cpp
udioFlinger.h
58e5aa34f01d663654d8bafad65db1dda42161ff 20-Jun-2012 Glenn Kasten <gkasten@google.com> effect_descriptor_t const correctness

Change-Id: Iad008f20d35a18acf500f773900164552fd0c19e
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
1d491ff06f4b9c90ff24fe953b90d0843eaf1c04 16-Jul-2012 Glenn Kasten <gkasten@google.com> Fix races in AudioRecord stop()

Change-Id: Id0ac1915f57fef4a938c7f90989c1162a8b6c51c
udioFlinger.cpp
udioFlinger.h
69d799679c8c0308e42057e7b5ad63a7ae806480 19-Jul-2012 Glenn Kasten <gkasten@google.com> Use upmix/downmix utility routines

Change-Id: I9ae2ec938fb695ec576ea008a42205325af7bbf1
udioFlinger.cpp
e65c89113232d070dd9153c54ca19301bca7a162 21-Jul-2012 Eric Laurent <elaurent@google.com> fix audio effect not destroyed when needed.

commit a5f44eba contained an error which made that audio effect
modules where not destroyed but left in the destroyed state
rendering them unuseable after being released.

Bug 6805168.

Change-Id: Ia4e683b3c970ffd01846c482fde73d799ff219de
udioFlinger.cpp
33e6e35b03a726e35203e97550f32154c91d5f13 17-Jul-2012 Glenn Kasten <gkasten@google.com> Miscellaneous audio record fixes

Call AudioSystem::stopInput() if exitPending() after wait() returns.

Acquire lock before clearing mActiveThread.

Change-Id: Ia55e4c4b3accc65ad5479cbdc094fd919152af9f
udioFlinger.cpp
cd2d61016527bf48bd2e9a920bb3fdbb875eb3e4 19-Jul-2012 Glenn Kasten <gkasten@google.com> Use constructor to initialize instead of memcpy

Also don't check for thread parameter as it's always non-NULL

Change-Id: Id23ded1370556ef3f76f81f5f0c6fa644bcba681
udioFlinger.cpp
be5f05e0fdfc4e3799653702187861a2afa072ee 19-Jul-2012 Glenn Kasten <gkasten@google.com> Internal dump methods return void not status_t

Only the IAudioFlinger::dump() needs to return a status_t.

Change-Id: Iffeb2a7db4846df850b6b2ed960276f1fd75dba0
udioFlinger.cpp
udioFlinger.h
5ad92f620fbbb6a8281f10169a23d38e3601e07a 19-Jul-2012 Glenn Kasten <gkasten@google.com> Revert 94479fd5405642c67efd14cebe722feb9cbe6e77

Change-Id: I5ca78d5462badf541868785b2ba2e3f6d0cf492a
udioFlinger.cpp
bb4350d3b9e9485ae59e084de270f86aecef8066 04-Jul-2012 Glenn Kasten <gkasten@google.com> Use audio_devices_t more places

Change-Id: Id0ace02ca6f480a6c46e11880acf6cdc66d83184
udioFlinger.cpp
udioFlinger.h
a189a6883ee55cf62da1d7bf5bf5a8ab501938a4 20-Feb-2012 Glenn Kasten <gkasten@google.com> Use struct assignment instead of explicit memcpy

for POD structs effect_descriptor_t and effect_config_t

Change-Id: Ib2fc47f85fb65ed91b0abb1f87217c49b5eb571d
udioFlinger.cpp
udioPolicyService.cpp
fd4e20c226eca185fc789de761beae64855bfbbb 04-Jun-2012 Glenn Kasten <gkasten@google.com> Run audio at priorities 2 and 3 above kernel 1

Also run the watchdog at same priority as the fast mixer.
requestPriority() originally used only the caller's pid to decide which
cgroup to assign, but in the future it might look at the priority also.
So it's safer to use same priority as the fast mixer to be sure we
run in the same cgroup.

Bug: 6461925
Change-Id: Ia59c93e4b22dacbb6746bfa6ad491be7b72f2b8d
udioFlinger.cpp
d96c5724818fb47917bb5e7abe37799735e1ec0e 25-Apr-2012 Glenn Kasten <gkasten@google.com> Don't call virtual methods in destructor

The result of calling virtual methods from a destructor is undefined.

Change-Id: I0fd4a19626e5ae564a60b753315b5f6c4b8d1f2c
udioFlinger.cpp
udioFlinger.h
1ea6d23396118a9cfe912b7b8a4e6f231e318ea2 09-Jul-2012 Glenn Kasten <gkasten@google.com> Use atomic ops for thread suspend count

There was a theoretical but unlikely race if two binder threads
executed suspend() or restore() concurrently. Also added comments.

Change-Id: I0908acc810b83bdd66455b27ca3429de1662a2cd
udioFlinger.cpp
udioFlinger.h
1879fff068422852c1483dcf8365c2ff0e2fadfc 12-Jul-2012 Glenn Kasten <gkasten@google.com> Add tid parameter to IAudioFlinger::openRecord

Not yet implemented

Change-Id: I35523fb15ad71727ecc9f4bb870f07e4b7397dc4
udioFlinger.cpp
udioFlinger.h
bf04a5d7f287fc712e0ed91849dc85c90c1e182d 12-Jul-2012 Glenn Kasten <gkasten@google.com> Simplify AudioRecord::getInputFramesLost()

This also fixes a benign race in reading mActive without a lock.

Change-Id: I19e953d4f275e5c266ca1ca3fece7b6c02ad1707
udioFlinger.cpp
39c54f68804c1ce5c85ec588f3c2c63447a807b4 09-Mar-2012 Glenn Kasten <gkasten@google.com> Remove dead code

Change-Id: If22a6c4e572b0734eba0c5a7ce29a2c61c581e5d
udioFlinger.cpp
udioFlinger.h
4fe1ec4f40b58abff6cec147aa786cb65698161a 28-Feb-2012 Glenn Kasten <gkasten@google.com> Fix check for invalid channel count

Change-Id: Id9e3dce0e3d5971786212d3f70e17a17e32ce92b
udioFlinger.cpp
04270daf50f0c602d7c57a257a693e68246cbeb7 10-Jul-2012 Glenn Kasten <gkasten@google.com> Record overflow cleanup

Add comments and rename one method for clarity

Change-Id: I04a9147e46e88a072256c0211b112d52202419e2
udioFlinger.cpp
udioFlinger.h
254af180475346b6186b49c297f340c9c4817511 03-Jul-2012 Glenn Kasten <gkasten@google.com> Use audio_channel_mask_t more places

Use it in AudioSystem::getOutput(), AudioSystem::getInput(),
IAudioPolicyService::getOutput(), IAudioPolicyService::getInput(),
and various other places in AudioFlinger.

Not done: AudioTrack and OutputDescriptor.

Change-Id: I70e83455820bd8f05dafd30c63d636c6a47cd172
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioPolicyService.cpp
udioPolicyService.h
4d2132c866228eaef563e8141ebf06aa25ee9ff7 10-Jul-2012 Eric Laurent <elaurent@google.com> Merge "audio policy: fix delayed command insertion"
2df8f55055fe431a508148cf525df1ba40f03113 10-Jul-2012 Glenn Kasten <gkasten@google.com> Add comments on use of volatile for track count

and add acquire load at the read

Change-Id: Ib41a58f5b1f6af87a8bd63d3f77d2ec0e48cb479
udioFlinger.h
a34f8ec169986c5a28600c0decaa4e2db70df8e4 21-Jun-2012 Glenn Kasten <gkasten@google.com> Remove 'volatile' from mMute and add comments

Change-Id: I386ba27b2305a397aba70331c6bf0d35ea727cf6
udioFlinger.h
9f34a36d9cdb9595c288e50ffe00da038bc8abb9 21-Mar-2012 Glenn Kasten <gkasten@google.com> Whitespace and indentation

Change-Id: I424052b4ff9218147a5cfc8e6dcd67fe8105d229
udioFlinger.cpp
udioFlinger.h
7d6c35bf132a46c0a8a9826491882495fc98bd8c 02-Jul-2012 Glenn Kasten <gkasten@google.com> Move constant initializations from onFirstRef() to constructor

Change-Id: I57f55b0bd1edee105c58c3a055f95f1e4a2c9646
udioFlinger.cpp
6648821933dc06c0b09ab2c8b32135edddcd4291 21-Jun-2012 Glenn Kasten <gkasten@google.com> AudioFlinger::getBuffer() always returns non-NULL

Change-Id: I543d3db507597cacbfdad5d9ea71732137fe54fb
udioFlinger.cpp
udioFlinger.h
94479fd5405642c67efd14cebe722feb9cbe6e77 10-Jul-2012 Glenn Kasten <gkasten@google.com> Fix build

Revert after system/core audio_devices_t is submitted

Change-Id: I5a8ee1a7b711e834501e927f41c62efa6a6600b6
udioFlinger.cpp
cec4abb2a39eafa75cf6894170a200322aa7226e 03-Jul-2012 Eric Laurent <elaurent@google.com> audio policy: fix delayed command insertion

When inserting a delayed command in the audio policy service
command thread queue, later similar commands are filtered out.
In case of volume commands and delayed unmuting, this can cause
a problem where a new volume command can cause the timing of a
delayed unmuting command to not be honored.

This change makes that a volume command gets the time stamp of
any delayed command it replaces.

Bug 6720482.

Change-Id: I216f85ac0ea46e4a046d3483e9e9b7ffe6c34a08
udioPolicyService.cpp
01542f2704f39956da09ae2840e192dab760091f 02-Jul-2012 Glenn Kasten <gkasten@google.com> Only write to mDevice once

This fixes a bug where readers might see intermediate values.
Also add comments about how mStandby and mDevice are used.

Change-Id: Idc84e56c21381a45137a2ca5ff9c57d437201869
udioFlinger.cpp
udioFlinger.h
c1dae24a08b67b98e18e4239d4f3a74d600d353c 03-Jul-2012 Glenn Kasten <gkasten@google.com> Remove debug code HAVE_REQUEST_PRIORITY and SOAKER

Change-Id: I73a2afe72d8acb53e57e6b4e6fb5133e22b7875a
ndroid.mk
udioFlinger.cpp
udioFlinger.h
oaker.h
a5f44ebaf58911805b4fb7fb479b19fd89d2e39b 25-Jun-2012 Eric Laurent <elaurent@google.com> audioflinger: fix effect disconnect deadlock

Fix possible deadlock when several EffectHandles on the same
EffectModule are destroyed simultaneously:
A wp on an EffectHandle should not be promoted to a local sp
with ThreadBase mutex held as the EffectHandle destructor can be
called when the sp gets out of scope which will call
ThreadBase::disconnectEffect() and try to acquire the mutex.

Use raw pointers instead of weak pointers for the list of handles
on an EffectModule.

Bug 6679606.

Change-Id: Ice8b602fb03a7d363c44ce3dced8a53540d96270
udioFlinger.cpp
udioFlinger.h
dd8104cc5367262f0e5f13df4e79f131e8d560bb 02-Jul-2012 Glenn Kasten <gkasten@google.com> Use audio_channel_mask_t more consistently

In IAudioFlinger::createTrack() and IAudioFlinger::openRecord(),
declare input parameter to use correct type audio_channel_mask_t.

In IAudioFlinger::getInputBufferSize(), input parameter is now channel mask
instead of channel count.

Remove unused IAudioFlinger::channelCount(audio_io_handle_t).

In AudioRecord::getMinFrameCount() and AudioSystem::getInputBufferSize(),
input parameter is channel mask instead of channel count.

Change-Id: Ib2f1c29bea70f016b3cfce83942ba292190ac965
udioFlinger.cpp
udioFlinger.h
f1da96d8cf60842538e00a9c950cc451f7da2c10 03-Jul-2012 Glenn Kasten <gkasten@google.com> Remove longStandbyExit

It was never set (the assignment was within an "if" that was never true).

Change-Id: I01cc68e9df6b190eece621b2aa9858b4361880ce
udioFlinger.cpp
udioFlinger.h
415fa7599f48494f99206b8d6e1974abb52c5923 03-Jul-2012 Glenn Kasten <gkasten@google.com> Fix uninitialized field EffectModule::mPinned

Also mark EffectModule::mId and EffectModule::mSessionId const, and
document the initialization of other fields in EffectModule.

Change-Id: Ic1ca008e75e9b5924743ffc35bef80057f3a0669
udioFlinger.cpp
udioFlinger.h
d5903ec1332630f2992a6f0d5ca69d13a185c665 18-Mar-2012 Glenn Kasten <gkasten@google.com> Compare sp<> to 0 and raw pointers to NULL

Change-Id: I50ff8a010d349d1d7e3dffa04a6331814c2128b0
udioFlinger.cpp
a01992a0675a06df7d0bbe7b977207dd0c33fdc7 02-Jul-2012 Eric Laurent <elaurent@google.com> am dbbd5b86: am 109347d4: audioflinger: fix regression in attachAuxEffect().

* commit 'dbbd5b860a3a26bea3376410f75f27530d9cd10b':
audioflinger: fix regression in attachAuxEffect().
109347d421413303eb1678dd9e2aa9d40acf89d2 02-Jul-2012 Eric Laurent <elaurent@google.com> audioflinger: fix regression in attachAuxEffect().

Commit 717e1286 introduced a regression in PlaybackThread::Track::attachAuxEffect()
when called with an effect ID of 0 to detach the auxiliary effect.

It is normal in this case that AudioFlinger::getEffectThread_l() returns 0.

Bug 6768757.

Change-Id: I7430bd1aad2f68da38f7c3e4794e7ad657bfc6be
udioFlinger.cpp
dbabf8a7dfe3aa8bf0ed169220d2009d5891fef2 01-Jul-2012 Eric Laurent <elaurent@google.com> am 651f9e7c: am 717e1286: audioflinger: fix auxiliary effect attachment

* commit '651f9e7c972b58a49066081187161268bcf9237a':
audioflinger: fix auxiliary effect attachment
717e128691f083a9469a1d0e363ac6ecd5c65d58 30-Jun-2012 Eric Laurent <elaurent@google.com> audioflinger: fix auxiliary effect attachment

Auxiliary effects (Reverb) are global effects and as such follow
the default rule which is to attach them to the output thread that
handles music streams by default. This causes a problem when several
threads are eligible to handle music streams as tracks can be attached
to either thread based on criteria unknown when teh effect is created.

The fix consists in moving the auxiliary effect if necessary when an
AudioTrack is attached to it and this track is not on the same
output thread.

Bug 6608561.

Change-Id: Ib32c3cabc731b2046aba728be1771982999c6069
udioFlinger.cpp
udioFlinger.h
9ee836fc8cf54d26e1e0819d1467d4d39bb9295c 25-Jun-2012 Glenn Kasten <gkasten@google.com> Merge "Remove acoustics from AudioSystem::getInput()"
20010053daabfa43fcfe781bbf004473b4c08538 22-Jun-2012 Glenn Kasten <gkasten@google.com> Remove acoustics from AudioSystem::getInput()

Change-Id: I29fb3ee5664c1f0ee0409c1bb2be087ecca637db
udioPolicyService.cpp
udioPolicyService.h
22167855ff9af7b13fda669ca27c67a037a7d585 20-Jun-2012 Eric Laurent <elaurent@google.com> audioflinger: fix setStreamOutput()

AudioFlinger::setStreamOutput() should also work for direct outputs.
Also ignore the destination output specified to match the expected
behavior which is to invalidate all tracks using the specified stream
type so that they can be re created on the correct ouput thread.

Do not send STREAM_CONFIG_CHANGED event wich is ignored by AudioSystem
anyway since the stream to output cache has been removed.

Change-Id: I13d9d47922923b630dd755717875424c16be4637
udioFlinger.cpp
udioFlinger.h
5f12136299918ea30555f3481668ec0dbb775e5f 15-Jun-2012 Eric Laurent <elaurent@google.com> audio policy: acquire lock for volume functions

Acquire the AudioPolicyService mutex when executing
setStreamVolumeIndex() and getStreamVolumeIndex().

These functions have become more complex and iterate on the
list of opened outputs and it is safer to acquire the
AudioPolicyService mutex to avoid concurrency with other
functions.

Bug 6626532.

Change-Id: Ifdcbbbf13338fd9a59f694d43faa7ade143f94bf
udioPolicyService.cpp
eb15716b59020f342df62bce5b293f0603b94861 13-Jun-2012 Glenn Kasten <gkasten@google.com> Change definition of warmup period

Previously, warmup was considered done as soon as any write() took
more than 0.5 nominal cycle time. In practice, this was always the
first write() that turned on power to the output path, and it didn't
accurately account for filling the full kernel buffer queue, or for
buffering in the HAL sample rate conversion.

Now warmup is considered done when a write() _after_ the first write
takes more than 0.5 nominal cycle time.

This will throttle the initial pull rate after coming out of standby.
When combined with another change to throttle the pull rate for
devices with HAL sample rate conversion, it may help reduce some of the
notification glitches. The only downside is that it will increase the
warmup time a bit.

Bug: 6508317, 6650846, 6607056
Change-Id: I39f324c5195578170a55308e9601d3a1b41db3e0
astMixer.cpp
972af221ae7253e406e0e1ea853e56a3010ed6b1 14-Jun-2012 Glenn Kasten <gkasten@google.com> FastMixer compensates for SRC jitter in audio HAL

Force a sleep if audio HAL write() returns too quickly.

Bug: 6661275
Change-Id: Ie810f5a087b89fb24dab229a0e500af1dee53571
astMixer.cpp
0a14c4ce1a41bc09eb7855fa531a3af629a69139 13-Jun-2012 Glenn Kasten <gkasten@google.com> Make CPU frequency statistics optional

Certain CPUs with dynamic cluster swapping and hotplug
don't report CPU frequency accurately. The file descriptors
used to read the frequency become stale and report bogus data.
So make this feature a build time option for debugging only.
This will also improve performance of the fast mixer loop.

Change-Id: I602f81ec3281a37992769208be08084ed1469e8c
ndroid.mk
astMixer.cpp
astMixer.h
362ebcbf100f7fccd37551c77e67c4faa7241b63 24-May-2012 Glenn Kasten <gkasten@google.com> DO NOT MERGE Remove log spam for fast track denied

Bug: 6531054
Change-Id: Iedf58e810a157aae88b5900da27c81054c437058
udioFlinger.cpp
e6adde403480333b613452ae0df442df9da4a5b2 14-Jun-2012 Glenn Kasten <gkasten@google.com> Merge "Shorten dumpsys media.audio_flinger output" into jb-dev
49dd5cf3469cd755321f8ec10013ad4fcfaf723d 14-Jun-2012 Glenn Kasten <gkasten@google.com> Merge "Log track name on obtain/releaseBuffer warnings" into jb-dev
3d51d5cb53cc630709a0ba78d0e60501a675f2d5 13-Jun-2012 James Dong <jdong@google.com> Add NOTICE and MODULE_LICENSE_APACH2 to libs build under /frameworks/av/

Change-Id: I0a3af3e2abdedebd5934f3d941d01c32cfc75e26
related-to-bug: 6647465
ODULE_LICENSE_APACHE2
OTICE
868c0abe9f26852c217bc201b337e72c68f829b8 13-Jun-2012 Glenn Kasten <gkasten@google.com> Shorten dumpsys media.audio_flinger output

Don't include in FastMixer if it's not present.
This removes confusing clutter especially for devices
with a separate deep buffer output thread, or for the
duplicating thread and A2DP output thread.

Change-Id: I84933f5555593256f11ba0895ec915c09cf16963
astMixer.cpp
0c9d26d187017f7fb028ab52a0fbc6395142faa4 31-May-2012 Glenn Kasten <gkasten@google.com> Log track name on obtain/releaseBuffer warnings

This should help diagnose problems by allowing us to correlate
the logs with the dumpsys media.audio_flinger output.

Change-Id: I8c7c592b4f87d13b0f29c66ce7a2f301a0f063c9
udioFlinger.cpp
c15d6657a17d7cef91f800f40d11760e2e7340af 30-May-2012 Glenn Kasten <gkasten@google.com> Add audio watchdog thread

Change-Id: I4ed62087bd6554179abb8258d2da606050e762c0
ndroid.mk
udioFlinger.cpp
udioFlinger.h
udioWatchdog.cpp
udioWatchdog.h
28ed2f93324988767b5658eba7c1fa781a275183 07-Jun-2012 Glenn Kasten <gkasten@google.com> Reduce underruns in screen off, esp. with EQ

Add MonoPipe APIs to specify setpoint.
Use screen state to configure pipe setpoint.
Fix a long-standing bug where pipe sleep time was excessive,
which interacted poorly with governor and low clock frequencies.
Now it deducts the elapsed time since last write(),
which was significant when there was EQ and low clock frequency.

Bug: 6618373
Change-Id: I6f3b0072c2244aeb033ef0795ad164491a164ff5
ndroid.mk
udioFlinger.cpp
udioFlinger.h
onoPipe.cpp
onoPipe.h
a4f7e0e9a0e92a063f1b3a08988cf46e2cf1fa94 08-Jun-2012 Eric Laurent <elaurent@google.com> audioflinger: fix duplicating thread standby

The code that waits for a track presentation to be complete
before disabling it caused a regression for duplicating threads.
Because of the way output tracks activity is managed, the number
of frames output by the duplicating thread would never
reach the target set for a track to be considered presented.
The track would not be removed from active list and the thread would
not go to standby and keep its wakelock held.

Bug 6606922.

Change-Id: I4b46b420ac4cbf79a86b6791ae6589d407b01c92
udioFlinger.cpp
e35a55fbdff5a695ee35ff43f1466a62fb75662b 07-Jun-2012 Marco Nelissen <marcone@google.com> Merge "Take latency and current time into account for visualization" into jb-dev
f06c2ed50e1db871ae9eb2bd15a196064f8c278c 06-Jun-2012 Marco Nelissen <marcone@google.com> Take latency and current time into account for visualization

Buffer more data, and return the data that is currently being
output from the audio output, to ensure that visualizations are
smooth and responsive even when the audio output has a large
latency and/or large buffers.
b/6522728

Change-Id: I401637f01be7600b3c594a55c869036c13b206c0
udioFlinger.cpp
udioFlinger.h
9a0d82df8fd681257bc5b29fb5e6c65fcc7cef5a 06-Jun-2012 Eric Laurent <elaurent@google.com> audioflinger: modify fast mixer overrun management

Do not force sleep when an overrun occurs. This was for non
blocking audio HAL and is unused.
Keep statistics on overruns.

Bug 6605215.

Change-Id: I295455d4562201aa3814c88bdd6e52c9226712af
astMixer.cpp
67c0a58e05f4c19d4a6f01fe6f06267d57b49305 02-May-2012 Eric Laurent <elaurent@google.com> audioflinger: various fixes on direct output

Various fixes in direct output playback thread implementation:
- threadLoop_write() was broken for playback threads that do not
use a pipe sink.
- output buffer size calculation was hard coded for stereo.
- removed software volume that was implemented for PCM stereo
format only: the audio HAL has to implement volume if needed
for direct outputs.

Change-Id: If211b4489be9af395435707b8cf0388cce1347b2
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
ab9071b8d1b375418eb797c9a790da71de644344 04-Jun-2012 Eric Laurent <elaurent@google.com> audioflinger: fix active sleep time calculation.

When an audioTrack underruns, the audioflinger mixer thread
sleeps for a certain time to give the app a chance to recover.
This time is based on the reported audio HAL latency.
Some audio HALs implementing deep buffering have a variable
latency and this creates a problem if the sleep time is cached
when the output stream is opened and not updated afterwards.

This change derives the active sleep time from the mix buffer
framecount instead of the latency. This is more conservative
but works for variable latency.

Bug 6588525.

Change-Id: Ia892fc290fe06f836565c3ae15f7a2ce026c88c6
udioFlinger.cpp
399930859a75d806ce0ef124ac22025ae4ef0549 31-May-2012 Glenn Kasten <gkasten@google.com> State queue dump

Bug: 6591648
Change-Id: Iac75e5ea64e86640b3d890c46a636641b9733c6d
ndroid.mk
udioFlinger.cpp
udioFlinger.h
tateQueue.cpp
tateQueue.h
1295bb4dcff7b29c75cd23746816df12a871d72c 31-May-2012 Glenn Kasten <gkasten@google.com> Fast track dumpsys

Bug: 6591648
Change-Id: I696f51c682e7233ba690d97da26012084989b412
udioFlinger.cpp
astMixer.cpp
astMixer.h
bf0d21fb1310e8677caa53b90e8c3aecebc7fc13 31-May-2012 Glenn Kasten <gkasten@google.com> Count underruns for normal tracks also

Bug: 6591648
Change-Id: Iff9cabe392bb2ce97062603adb9c9dc7aa4170d5
udioFlinger.cpp
81787e56f8f21407eade5accc50c6da39b8af9b2 03-Jun-2012 Glenn Kasten <gkasten@google.com> Merge "Was calculating measured warmup time wrong" into jb-dev
7dc5b165d4f98a2059eaf1c7fec20b3b5773cd4c 01-Jun-2012 Glenn Kasten <gkasten@google.com> Merge "Fix fast track leak if out of normal track names" into jb-dev
0c22272f1c97fd4b7e106030a1fd5e6b50680b61 01-Jun-2012 Glenn Kasten <gkasten@google.com> Merge "Pipe throttle based on requested frame count" into jb-dev
04a4ca4217e9b30342d5865024c340013d7184e8 01-Jun-2012 Glenn Kasten <gkasten@google.com> Was calculating measured warmup time wrong

Bug: 6592923
Change-Id: I980c6fc69d78c569147ea44ce33a7f8a41739c91
astMixer.cpp
893a05479c96f911d02beb0443da3ed6508143a7 30-May-2012 Glenn Kasten <gkasten@google.com> Fix fast track leak if out of normal track names

Bug: 6580402
Change-Id: I3ac7f012062c35833147f47ba822eb4bf532a824
udioFlinger.cpp
udioFlinger.h
820ba70df8ba595ae9055dfd34fdbfa32f70f14d 31-May-2012 Glenn Kasten <gkasten@google.com> Pipe throttle based on requested frame count

Now does throttling based on the requested frame count, but
still permits overfilling pipe up to the rounded-up frame count.
Also still uses the larger frame count for non-blocking arithmetic.

Bug: 6585323
Change-Id: Ic2420a071419905524a14c22ebe1ce0e32d70a9d
onoPipe.cpp
onoPipe.h
91b14c4c144d0cc957a427cffc02ba10d0615677 30-May-2012 Eric Laurent <elaurent@google.com> audioflinger: fix effect problem during underrun

When an audio track underruns, the input buffer of the
corresponding effect chain (if any) must be cleared, otherwise
audio from previous mixer run will be fed again to the effect process
function.

Bug 6551652.

Change-Id: I5cd02196745f756c85af82d6937e9dc54369b37f
udioFlinger.cpp
udioFlinger.h
f436fdcf93bd417fd3c9d2a8b19fd221d894b5e3 24-May-2012 Eric Laurent <elaurent@google.com> audioflinger: change session check in createTrack.

Do not refuse to create a track on an output thread if the same session
is present on another thread. It is now possible that two tracks
with the same session ID are on different threads if one can use deep
buffering and the other can't.

In this case, move effects attached to this session to the output
thread ion which the new track is created.

Bug 6530324.

Change-Id: I9019b3ee382e374c89d2319033afcfa7f886e4c4
udioFlinger.cpp
e737cda649acbfa43fc1b74612a83f2fac9aa449 23-May-2012 Eric Laurent <elaurent@google.com> audioflinger: refine latency latency calculation.

There is an audio pipe between the normal mixer output and the fast
mixer to cope for scheduling delays and buffer size difference.
This pipe depth was not taken into account in latency calculation.

Adding the pipe contribution to the latency significantly improves A/V sync.

Bug 6520569.

Change-Id: I5584908e8aa8a02170eb38b22b4370eea800a235
udioFlinger.cpp
udioFlinger.h
onoPipe.h
fbae5dae5187aca9d974cbe15ec818e9c6f56705 21-May-2012 Glenn Kasten <gkasten@google.com> Keep a copy of most recent audio played

Change-Id: I6b2f97881c39998a2fae9ab79d669af6c0a37e94
ndroid.mk
udioFlinger.cpp
udioFlinger.h
astMixer.cpp
astMixerState.cpp
astMixerState.h
ipeReader.cpp
6d8aabe8a3be1ac0789d00b82c3ca8b81381f5ab 18-May-2012 Glenn Kasten <gkasten@google.com> Add throttle to have pipe fill at more stable rate

Change-Id: Ibff9ab62764e2acd04518a4a00e25f19e28aff4a
onoPipe.cpp
onoPipe.h
99c99d00beb43b939dedc9ffb07adb89f6a85ba5 15-May-2012 Glenn Kasten <gkasten@google.com> systrace for audio

Trace fast track buffer fill status for underruns etc.

Move the definition of macro to Android.mk.

No overhead if disabled.

Change-Id: If0e83e21b61b059ca38f543f8a6ffb58e08c79ee
ndroid.mk
udioFlinger.cpp
astMixer.cpp
552477608b137fb66af126655c6865207a82d888 18-May-2012 Glenn Kasten <gkasten@google.com> Merge "Display pipe underrun counters in dumpsys" into jb-dev
88cbea8a918bbaf5e06e48aadd5af5e81d58d232 15-May-2012 Glenn Kasten <gkasten@google.com> Display pipe underrun counters in dumpsys

The normal mixer writes it's submix to a pipe, which is read by the fast
mixer. Now dumpsys media.audio_flinger display the raw underrun counters
when fast mixer tries to pull from the pipe but doesn't get enough frames.

Change-Id: I72505f149f9e12802784da654a651d43734e1c79
udioFlinger.cpp
udioFlinger.h
c059bd4246c1b3944965be921e5b334d51cd236c 15-May-2012 Glenn Kasten <gkasten@google.com> Skip bad kHz values, and display them accurately

One device reports zero CPU kHz occasionally, so skip those values.

Preserve accuracy of the low-order 4 bits of the the CPU frequency.

Change-Id: I7d934f697412277462464fca82d112d0306a214e
astMixer.cpp
9017e5e0ebad9664bb7b6f2057e5bb29c852c64f 15-May-2012 Glenn Kasten <gkasten@google.com> Increase normal mixer's pipe to fast mixer

Change-Id: I330925c7d07b6adb30b773bda3657e4efef9ae9b
udioFlinger.cpp
44a957f06400a338e7af20b3d16c4c4ae22a673c 16-May-2012 Eric Laurent <elaurent@google.com> Fix static track activity ref counting

When a static AudioTrack underruns, it means that playback is over.
As apps do not necessarily stop playback explicitly, AudioFlinger
should call stopOutput() to decrease activity ref count in
audio policy manager.

Bug 6486311.

Change-Id: I1ea722c443780329ded6310c958b24726e918d16
udioFlinger.cpp
udioFlinger.h
2986460984580833161bdaabc7f17da1005a8961 09-May-2012 Eric Laurent <elaurent@google.com> Fix issues with synchronous record start.

- Added a timeout in case the trigger event is never fired.
- Extend AudioRecord obtainBuffer() timeout in case of
synchronous start to avoid spurious warning.
- Make sure that the event is triggered if the track is
destroyed.
- Reject event if the triggering track is in an incompatible state.

Also fix a problem when restoring a static AudioTrack after
a mediaserver crash.

Bug 6449468.

Change-Id: Ib36e11111fb88f73caa31dcb0622792737d57a4b
udioFlinger.cpp
udioFlinger.h
4adcede0dc54a85c31abaf139921aebd7a072d8e 14-May-2012 Glenn Kasten <gkasten@google.com> Reduce video frame drop rate

The video playback engine depends on having relatively precise audio
progress updates for its A/V sync and frame drop calculations. For small
audio HAL buffer sizes, this was not a problem, but when the HAL buffer
size was > 12 ms, the normal mix buffer size became > 24 ms and this
then caused video problems. The new formula tries to keep the normal
mix buffer size within a closer tolerance of 20 ms to 24 ms.

Also use consistent term: multiplier instead of multiple.

Bug: 6479613
Change-Id: I903bad74461908e8c8f0a61e99ab5e24d5c44433
udioFlinger.cpp
09474df67278c0cd621b57c4aef1deaec4d8447f 10-May-2012 Glenn Kasten <gkasten@google.com> Improve underrun handling for fast tracks

Maintain more accurate accounting of type of underrun.
Automatically remove track from active list after a series of "empty" underruns.

Change-Id: If042bf80e1790dcaaf195c99dc9c0ed9b55382c1
udioFlinger.cpp
udioFlinger.h
astMixer.cpp
astMixer.h
d08f48c2ad2941d62b313007955c7145075d562c 02-May-2012 Glenn Kasten <gkasten@google.com> Fix stopping process for fast tracks

Previously, the state of a fast track "wiggled" back and forth at the end.

Now it goes through these transitions:
active -> stopping_1 -> stopping_2 -> stopped

This CL is only for fast tracks, and does not change how
normal tracks work.

Change-Id: Icc414f2b48c46dda63cfa6373ca22d033dd21cd4
udioFlinger.cpp
udioFlinger.h
808e7d16504cbe5b28bb88c31afb2542ab488965 12-May-2012 Eric Laurent <elaurent@google.com> AudioFlinger: fix global effects suspend logic

Audio effects on the output mix should not be suspended when effects
on the output stage (post processing) are enabled.

Change-Id: I2e1c08fa9358ea3cbaec68856738d504b1be54e4
udioFlinger.cpp
e58ccce45598bcf4b4874b0e87cd1eb8d05ba9a9 12-May-2012 Glenn Kasten <gkasten@google.com> Fix 2 bugs in fast mixer statistics

Was losing the upper half of the bounds, and MHz was off.

Change-Id: I61c98027b35ce7c3578ea6f3acf05aa5c48a5831
astMixer.cpp
d8e6fd35ec2b59ee7d873daf1f1d9d348221c7bc 07-May-2012 Glenn Kasten <gkasten@google.com> Use audio tag for system tracing

Disabled by default; uncomment ATRACE_TAG to enable

Change-Id: I99af894022a859ee5644bd853cfd8a48e4735ff9
udioFlinger.cpp
astMixer.cpp
42d45cfd0c3d62357a6549c62f535e4d4fe08d91 02-May-2012 Glenn Kasten <gkasten@google.com> Update fast mixer statistics

Compute statistics on fast mixer elapsed time and CPU load per cycle using a
simple moving average rather than by fixed blocks. This has a couple advantages:
- remove burstiness of CPU usage due to former floating-point calculations in fast mixer
- gives us flexibility in how to report (e.g. could report over just the last 1 second)

Disadvantage is increased RAM, and since the samples are not updated
atomically, it is possible to have an error in the statistics. This
should not be much of an issue due to the relatively large number of samples.

Also add CPU raw ns and adjusted MHz statistics.

Change-Id: Iaa2cd13f18250c3162aff40409b3694b769d9505
astMixer.cpp
astMixer.h
e213c86d36414a8fc75e37c52999522fe09c7328 25-Apr-2012 Glenn Kasten <gkasten@google.com> dumpsys fCnt and flags

Previously displayed TrackBase::mFrameCount but not control block frameCount.
Now displays both.

Also display the track flags in control block.

Change-Id: Ie53781d4784633d78b6f928d69ebd494d8f110ec
udioFlinger.cpp
31dfd1db7a4d2228d9642008af6f3dd744368eb6 01-May-2012 Glenn Kasten <gkasten@google.com> Disable fast track log spam

except for "denied by client" and "denied by server"

Change-Id: I133ab747933729cc1f386813ee06ece055bdb294
udioFlinger.cpp
810280460da5000785662f6c5b0c7ff3ee0a4cb3 01-May-2012 Glenn Kasten <gkasten@google.com> Temporary fix for both normal tracks & fast tracks

If there is at least one active fast track, it forces a mixer
status of ready, which messes up the logic for normal track underruns.

Change-Id: I9de2fcaef090e2c2f99682333af3d3dd618b0d6b
udioFlinger.cpp
udioFlinger.h
288ed2103d96f3aabd7e6bea3c080ab6db164049 26-Apr-2012 Glenn Kasten <gkasten@google.com> Fix race condition for non-started fast tracks

This required re-implementing how fast tracks are considered active.
Now, they use the same logic as normal tracks, except underrun is ignored.

Other changes:
- add framesReady() to AudioBufferProvider interface
- rebased
- add track underrun counter state to fast mixer dump state
- move dumpsys header to Track::appendDumpHeader()
so it closer to where tracks are dumped
- display track state in dumpsys as a character code
- measure and display warmup time and cycles in dumpsys
- copy in the presentation complete code
- add ExtendedAudioBufferProvider for framesReady() which returns size_t
- simplify underrun tracking
- deferred reset track after stop()
- add comments

Change-Id: I7db8821bc565230ec76da1f9380fe3fb09735e5b
udioFlinger.cpp
udioFlinger.h
xtendedAudioBufferProvider.h
astMixer.cpp
astMixer.h
astMixerState.h
ourceAudioBufferProvider.cpp
ourceAudioBufferProvider.h
83faee053cfd4251dbb591b62039f563ffdac399 28-Apr-2012 Eric Laurent <elaurent@google.com> AudioFlinger: fix stop detection for static tracks

The end of playback and end of presentation detection was broken for
static AudioTracks (tracks using shared memory buffers passed by client).

The mixer should not wait for a minimal amount of frames to be available to mix
a static track otherwise the last frames might never be consumed.

A static track should be removed from active list in case of underrun even if not
stopped().

Issue 6411521.

Change-Id: I66a2c1a77e98149e5049a223a6f04c3b8c5ad11a
udioFlinger.cpp
udioFlinger.h
300a2ee9327c05fbf9d3a5fd595b558097c7c5e8 25-Apr-2012 Glenn Kasten <gkasten@google.com> Fast mixer configuration

Add compile-time option for when to use fast mixer.

Double HAL frame count for fast tracks due to SRC, and make the normal
frame count multiplier an even number for compatibility. Sample rate
conversion can result in underruns if the HAL frame count is used as is,
due to jitter.

Change-Id: Ia1f8da1b8ac247d9807acfce3c318161db000905
udioFlinger.cpp
da747447c1d4b5205469b4e94485b8769df57a97 26-Apr-2012 Eric Laurent <elaurent@google.com> AudioFlinger: fix tracks ready for mixing logic.

Commit fec279f5 broke the logic allowing to wait for an application
to provide frames for mixing in the case of several active tracks.

This was causing audio gaps when playing music and superposing a
sound Fx (keyboard clicks...).

Issue 6185007.

Change-Id: Id0fad150d0b615646d6b1387c0de8ca944d228f6
udioFlinger.cpp
udioFlinger.h
e0fa467e1150c65a7b1b1ed904c579b40f97c9df 24-Apr-2012 Glenn Kasten <gkasten@google.com> Move frame count calculations for fast tracks

For fast tracks: move the default and minimum frame count calculations
from client to server. If accepted, the default and minimum frame count
is the fast mixer (HAL) frame count. If denied, the default and minimum
frame count is the same as it currently is for normal tracks.

For normal tracks: there is no change yet, preserve legacy behavior for
now but add a FIXME to change this later.

Bug fix: the test for buffer alignment matches channelCount was wrong.

Bug fix: check for 8-bit data in shared memory, which isn't supported.

Optimizations:
- in set(), only call AudioSystem::getOutputSamplingRate() when needed
- in createTrack_l(), only call AudioSystem::getSamplingRate() and
AudioSystem::getFrameCount() when needed

Change-Id: I79d2fe507db1a8f7bb094c71da8a129951dbb82f
udioFlinger.cpp
1dc28b794587be22c90a97070d928f94586db638 24-Apr-2012 Glenn Kasten <gkasten@google.com> Use scheduling policy service

Change-Id: I3c09da1dc0de5039d0c15ce7fb2bc373fa398712
ndroid.mk
udioFlinger.cpp
SchedulingPolicyService.cpp
SchedulingPolicyService.h
chedulingPolicyService.cpp
chedulingPolicyService.h
58912562617941964939a4182cda71eaeb153d4b 03-Apr-2012 Glenn Kasten <gkasten@google.com> AudioFlinger normal mixer uses FastMixer

Change-Id: I3131bb22d2d057e9197a2ebfa6aa1cfaab9e5321
ndroid.mk
udioFlinger.cpp
udioFlinger.h
oaker.h
3acbd053c842e76e1a40fc8a0bf62de87eebf00f 28-Feb-2012 Glenn Kasten <gkasten@google.com> Configure policy of mediaserver threads

Change-Id: Ifd825590ba36996064a458f64453a94b84722cb0
ndroid.mk
udioFlinger.cpp
udioFlinger.h
c95cfbb87d0ac5e773037019a96bfc29972d4b4e 12-Apr-2012 John Grossman <johngro@google.com> TimedAudioTrack: Optimize the queue trim operation.

Hand merge from ics-aah

> TimedAudioTrack: Optimize the queue trim operation.
>
> Don't perform the end PTS calculation for each buffer during trimming.
> Instead, only calculate the ending PTS of a buffer if there is no next
> buffer in the queue. This optimization assumes that the buffers being
> queued are in monotonic media time order (a fair assumption for now)
> and that the timestamps in the audio are contiguous (not a requirement
> for this API, but a reality of how it is being used right now).
>
> In the case where the audio is discontinuous on purpose, it is
> that this optimization will cause the system hold one extra buffer
> which it could have safely trimmed. It should not be much of an issue
> since in real life the audio is almost always contiguous, and as long
> as the media clock is running and the mixer is mixing, the buffer will
> be used up and discard as part of the normal flow anyway.
>
> Change-Id: I00061e85ee7d5651fcf80751646c7d7415894a14
> Signed-off-by: John Grossman <johngro@google.com>

Change-Id: I0054b58e1389fa005aa990cb5710caf4af7b706a
Signed-off-by: John Grossman <johngro@google.com>
udioFlinger.cpp
8d314b709fdd81bb64bdaa8d72a0b19c355cefb9 19-Apr-2012 John Grossman <johngro@google.com> TimedAudioTrack: Fix continuity threshold handling.

Hand merge from ics-aah

> TimedAudioTrack: Fix continuity threshold handling.
>
> Fix issues with continuity threshold handling; notably
> + If the steady-state continuity threshold is exceeded, be sure to
> clear the on-time flag. Failure to do this will result in the
> system picking a new mix point which simply satisfies the
> steady-state continuity threshold instead of the startup threshold.
> Since we are putting a discontinuity in presentation anyway, we
> really want to pick a perfect point, not just an OK point.
> + Tighten the steady-state continuity threshold. It was currently set
> to 100mSec which is enormous. 4mSec (the new setting) is much more
> appropriate. On systems with a VCXO (like tungsten) this should
> never be wrong by more than a sample. If TimedAudioTracks are ever
> to be used on VCXO-less systems, this threshold should probably be a
> a parameter configurable by applications on a track by track basis
> so they can make the tradeoff between allowed error and frequency of
> disruptive corrections.
> + Reset the on-time flag if the mixer provides no PTS during a mix
> operation. This makes for a convenient way for the HAL to reset
> timed tracks when it makes changes for delay compensation across
> multiple outputs.
>
> Change-Id: I2cb23de5a3d1f75618abc1c8ab903db883837aa8
> Signed-off-by: John Grossman <johngro@google.com>

Change-Id: Ibd28c9d290494b0b19eb01caf2d9bfdef606a9b4
Signed-off-by: John Grossman <johngro@google.com>
udioFlinger.cpp
21e8c50bd13ebe44f3088e26c9c6df0e163c469c 12-Apr-2012 Glenn Kasten <gkasten@google.com> FastMixer update

Updates:
- Add support for mono fast tracks
- Add support for optional sample rate conversion on fast tracks
- Log sample rate and frame count
- Enable statistics

Change-Id: Ife014edf4f452da361f3eaaae19209ef6ff6958b
ndroid.mk
astMixer.cpp
astMixer.h
astMixerState.cpp
astMixerState.h
9bd23229fdec1657398abc682ccccfce1c95f8aa 16-Apr-2012 Jean-Michel Trivi <jmtrivi@google.com> Fix multichannel downmix pause bug on video player

Pausing a video player will cause the track audio mixer to be
disabled, which causes the downmixer to be deleted. When reenabled,
the track channel mask hasn't changed but the downmixer is there
anymore.
Fixed by:
- instanciating a downmixer when the AudioMixer track
gets initialized (in getTrackName(), now taking a channel mask
as input), and deleted when in deleteTrackName().
- when the channel changes on a track, check whether it
needs a downmixer or not. Preparing a track for downmix
automatically removes the old downmixer if there was one.

Also: initialize the track downmixerBufferProvider field
when AudioMixer is instanciated, so we can safely call
delete on it in AudioMixer's destructor, in case
deleteTrackName() wasn't called before the mixer was
destroyed.

Change-Id: I589b0781cda5b3c82f85b561c52b08546cac21f8
udioFlinger.cpp
udioMixer.cpp
udioMixer.h
astMixer.cpp
0ca3cf94c0dfc173ad7886ae162c4b67067539f6 18-Apr-2012 Eric Laurent <elaurent@google.com> rename audio policy output flags

Change-Id: I27c46bd1d1b2b5f96b87af7d05b951fef18a1312
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
acb86cccbd9d245439a04cef0bcefa589addaa4c 16-Apr-2012 Jean-Michel Trivi <jmtrivi@google.com> Configure the resampler with the correct channel count when downmixing

When a track needs to be downmixed and resampled, it gets downmixed
first before being resampled. Therefore the resampler needs to
be configured with the channel count of the output of the downmixer
instead of that of the track.
Removed frame size checks that don't apply anymore now that we support
frame sizes that are not powers of 2 (e.g. 12 for 5.1 16bits), and
changed test performed for every buffer during playback into an
assert.

Change-Id: Ia220f00ee382f4f7848b661c58555bdca664e194
udioFlinger.cpp
udioMixer.cpp
97b5d0d5b5ef766eb5dd680d05a5d199662d4ae0 24-Mar-2012 Glenn Kasten <gkasten@google.com> Fast mixer

Change-Id: I61552f83507e08e4c706076b9fb15362869e6265
ndroid.mk
astMixer.cpp
astMixer.h
astMixerState.cpp
astMixerState.h
tateQueueInstantiations.cpp
0845682ff93c9765b74b53dc404d0954efc28c2e 18-Apr-2012 Glenn Kasten <gkasten@google.com> Merge "Add template class StateQueue"
dc998c809e084b617990b281e2ed5271830cc2e0 24-Mar-2012 Glenn Kasten <gkasten@google.com> Add template class StateQueue

Change-Id: Iccc5eb42bc295a22b2e429a4551f083cd7b6831a
ndroid.mk
tateQueue.cpp
tateQueue.h
f7ffb8bf0a58037f0bc9662c5275005a4e539948 14-Apr-2012 Eric Laurent <elaurent@google.com> audioflinger: update to new audio HAL.

Updated audio flinger to new function prototypes
for open_output_stream() and open_input_stream().

Check audio hw device version when loading a module and
reject devices with a version different from current one.

Change-Id: I9d4c81a1f59a15db78b3989417c2a411c638fe88
udioFlinger.cpp
4e2293f29f2e719af1245d365747ea06d074b345 12-Apr-2012 Glenn Kasten <gkasten@google.com> AudioMixer new cmd: remove sample rate converter

Add a new command REMOVE to remove any sample rate converter
on a track, without having to delete the track name.
Add comments.
Remove some dead code.
Fix whitespace and comparison to NULL.

Change-Id: Id55a23ab5ee673189e99675b4e6fa5df7b617987
udioMixer.cpp
udioMixer.h
a5e821439996de6005b2fa36b3bdd31f003ce23f 16-Apr-2012 Eric Laurent <elaurent@google.com> AudioMixer: fix crash in destructor

Commit deeb1282 made that track->resampler is only set to NULL when
getTrackName() is called. It remains uninitialized for all unused tracks
causing a crash when deleted by Audiomixer destructor.

Issue 6309441.

Change-Id: I49451387a6afe81299b8368ef206524df32f74c4
udioMixer.cpp
b388e531613730572067e193b6b66afb5d042233 14-Apr-2012 Eric Laurent <elaurent@google.com> Fix ALOG_ASSERT in AudioFlinger

Fix broken ALOG_ASSERT in updateFramesPendingAfterTrim_l() introduced by
commit 1c345196.

Change-Id: Ie1b2653069283f23ff0367f2628828e37fb0749c
udioFlinger.cpp
d3030da2ac3c0ebb8b7bdf38418263caf405b863 12-Apr-2012 John Grossman <johngro@google.com> Fix the build

forgot to upload final fixup during merge. sry about that

Change-Id: I2ddd2c08d8efa83c0a8d1e378ae4c28686145154
udioFlinger.cpp
1c345196edc61694f29307a1826a64a0d26028dc 27-Mar-2012 John Grossman <johngro@google.com> TimedAudio: Track of the number of pending frames.

This is a manual merge from ics-aah

> TimedAudio: Track of the number of pending frames.
>
> Keep track of the number of frames pending in the timed audio queue so
> we can implement framesReady in O(1) time instead of O(N). This
> change partially addresses bug 6020970; the bug will be completely
> addressed once this change has been up-integrated into master.
>
> Change-Id: I599eb15ea1f6d715b97b30e65214fb6fadd169df
> Signed-off-by: John Grossman <johngro@google.com>

Change-Id: I6cbbbc3afc8efd066fe94865326ede0c6b3db2bd
Signed-off-by: John Grossman <johngro@google.com>
udioFlinger.cpp
udioFlinger.h
9fbdee13d09447550dd22ae72c2dbabdce7f0a80 27-Mar-2012 John Grossman <johngro@google.com> TimedAudio: Fix a cause of audio popping.

This is a manual merge from ics-aah

> TimedAudio: Fix a cause of audio popping.
>
> Fix an issue with buffer lifecycle management which could cause audio
> pops on timed outputs. There were two issues at work here.
>
> 1) During trim operations for the queued timed audio data, buffers
> were being trimmed based on their starting PTS instead of when the
> chunk of audio data actually ended. This means that if you have a
> very large chunk of audio data (larger than the mixer lead time),
> then a buffer at the head of the queue could be eligible to be
> trimmed before its data had been completely mixed into the output
> stream, even though the output stream was fully buffered and in no
> danger of underflow.
> 2) The implementation of getNextBuffer and releaseBuffer for timed
> audio tracks was not keeping anything like a reference to the data
> that it handed out to the mixer. The original architecture here
> seemed to be expecting a ring buffer design, but timed audio tracks
> use a packet based design. Pieces of packets are handed out to the
> mixer which then frequently will hold onto that chunk of data
> across two mix operations, using the first part of the chunk to
> finish a mix buffer and then using the end of the chunk for the
> start of the next mix buffer. If the buffer that the mixer is
> holding a piece of got trimmed before the start of the next mix
> operation, it would return to its heap and could be filled with who
> knows what by the time it actually got mixed. On debug builds,
> they seem to get zero'ed out as they go back to the heap causing
> obvious pops in presentation.
>
> This change addresses both issues. Trim operations are now based on
> ending presentation time for a chunk of audio, not the start. Also,
> when the head of the queue is in flight to the mixer, it can no longer
> be trimmed immediately, merely flagged for trim by the mixer when the
> mixer finally does call releaseBuffer.
>
> Signed-off-by: John Grossman <johngro@google.com>
> Change-Id: Ia1ba08cb9dea35a698723ab2d9bcbf804f1682fe

Change-Id: I2c5e2f0375c410f0de075886aac56ff6317b144c
Signed-off-by: John Grossman <johngro@google.com>
udioFlinger.cpp
udioFlinger.h
3f9c84c0a5af83fceb8669390e2d71b75ec7b550 04-Apr-2012 Eric Laurent <elaurent@google.com> audio pre processing: test code for dual mic

Added functional test code to validate effect API for
multi mic simplementations.

Also fixed warning in AudioFlinger.

Change-Id: I07be4d2e4d17791d3626c804ba3e9f87ff26d05a
udioFlinger.cpp
7d5b26230a179cd7bcc01f6578cd80d8c15a92a5 05-Apr-2012 Jean-Michel Trivi <jmtrivi@google.com> AudioMixer uses downmix effect for multichannel content

In the AudioMixer structure associated with each track, add an object
that acts as the buffer provider when the track has more than two
channels of input in the mixer. This object, DownmixerBufferProvider,
gets audio from the actual buffer provider of the track, and applies
a downmix effect on it.
The downmix effect is created and configured when the track gets
created in AudioFlinger, which causes AudioMixer::getTrackName()
to be called with the new track's channel mask. It is released
when the track is disabled in the mixer.

Change-Id: I05281ed5f61bef663a8af7ca7d5ceac3517c82db
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
3f502bfc6d04d08369cf147284c5c4c2ac7c9a0e 06-Apr-2012 Glenn Kasten <gkasten@google.com> Merge "Non-blocking audio I/O interface, WIP"
a4c5a550e2a3bc237179b8684e51718e05894492 29-Mar-2012 Eric Laurent <elaurent@google.com> audio policy: load audio hw modules.

Audio HW modules are now loaded upon request from audio policy manager
according to the configuration in audio_policy.conf.
Removed hard coded HW module loading by AudioFlinger at init time.
Added methods to IAudioFlinger and AudioPolicyInterface
to control the loading of audio HW modules.
Added methods to open an output or input stream on a specific hw module.

Change-Id: I361b294ece1a9b56b2fb39cc64259dbb73b804f4
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
1a9ed11a472493cac7f6dfcbfac2064526a493ed 21-Mar-2012 Eric Laurent <elaurent@google.com> audio policy: add configuration file

removed outputs to stream mapping cache in audio system: the output for a
given stream type must always be queried from audio policy manager as the cache
is not always updated fast enough by audioflinger callback.

removed AudioFlinger::PlaybackThread::setStreamValid() not used anymore if
stream to output mapping is not cached.

Change-Id: Ieca720c0b292181f81247259c8a44359bc74c66b
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
73d227557ba5192735356bacab9f77b44980793b 19-Mar-2012 Glenn Kasten <gkasten@google.com> AudioFlinger track flags and server's fast policy

Change-Id: I72358c8e6829d173b3e60ced8a8babc089869fac
udioFlinger.cpp
udioFlinger.h
0bf65bdde04b8e66c998ff37e2b2afafddddfa33 29-Feb-2012 Glenn Kasten <gkasten@google.com> const methods and comments

Change-Id: Ifd16750174fdb15b72507787502b587562ffc99e
udioFlinger.cpp
udioFlinger.h
010662326b9c43c703725f933e95e0897f8a6bdd 27-Feb-2012 Glenn Kasten <gkasten@google.com> Non-blocking audio I/O interface, WIP

Yet another abstraction similar to AudioTrack::Buffer and AudioBufferProvider,
but with support for streaming, non-blocking, and eventually PTS.

This is intended to be used as follows:
- primary HAL output stream implements a Sink
- primary HAL input stream implements a Source
- Pipe implements a Sink
- PipeReader implements a Source or TimedSource (not shown yet),
which supports "read at PTS"
- fast AudioTrack on server side will implement a Source using cblk
- normal AudioTrack on server side will not be changed initially
- fast AudioRecord on server side will implement a Sink using cblk
- normal AudioRecord on server side will not be changed initially
- fast mixer thread will read from Sources and write to a Sink,
or (unlikely) implement a Source and multiple Sinks
- Visualization and PCM logger will read from Source or TimedSource
- A2DP normal mixer will be connected directly to its output stream
and there will be a kind of OutputTrack for duplication that will
read from a Sink with non-blocking write fed by the fast mixer.

Patch set 3 changes:
- Add more implementations of NBAIO interfaces:
added SourceAudioBufferProvider, MonoPipe, MonoPipeReader.
- Added Format_sampleRate and Format_channelCount.
- Extract out the roundUp() method.
- Respond to most comments from previous code review.
- The new classes are untested.

Patch set 4 changes:
- Fix bugs in MonoPipe::write() and MonoPipeReader::read()
- Fix bug initializing mFrameBitShift too early
- renamed roundUp() to roundup()
- Fix Android.mk
- Add LOG_TAG an LOG_NDEBUG, use ALOG_ASSERT and utils/Log.h instead of assert
- Fix build warnings
- Move constructor and destructor bodies from .h to .cpp
- Line length 100
- Following naming conventions for #include double-include protector macros
- Include what you use
- More NBAIO logging
- MonoPipe write can be blocking

Patch set 5 changes:
- Address code review comments
- Use a static library so unused implementations don't take memory
- Comment out libsndfile dependency
- Remove debugging LOGV and LOG_NDEBUG

Patch set 6 changes (would be 6 at old location, actually 2 at new location):
- Address code review comments on patchset 5
- For MonoPipe, allow the full pipe to be used, no need to omit one slot
- Don't do atomic releasing stores unless needed

Still to do:
- I'm not happy with the Pipe class names
- Update build/ for new static library?

Change-Id: Ie6c61f05ce06b676b033be448a8ef9025a2ffcfd
ndroid.mk
udioBufferProviderSource.cpp
udioBufferProviderSource.h
udioStreamInSource.cpp
udioStreamInSource.h
udioStreamOutSink.cpp
udioStreamOutSink.h
ibsndfileSink.cpp
ibsndfileSink.h
ibsndfileSource.cpp
ibsndfileSource.h
onoPipe.cpp
onoPipe.h
onoPipeReader.cpp
onoPipeReader.h
BAIO.cpp
BAIO.h
ipe.cpp
ipe.h
ipeReader.cpp
ipeReader.h
ourceAudioBufferProvider.cpp
ourceAudioBufferProvider.h
oundup.c
oundup.h
deeb1282621f3177ad667360b40eef8e4fedb298 25-Mar-2012 Glenn Kasten <gkasten@google.com> AudioMixer default track parameters

Move the default initialization of track parameters from the AudioMixer
constructor to getTrackName(). This fixes a bug where the defaults were
only valid the first time a name was allocated.

Also added a switch case for parameter FORMAT.

Change-Id: I07abd3aaf7f4efe9825a761d2bc662aaee2c6db0
udioMixer.cpp
a1472d9883e35edd280201c8be3191695007dfd4 30-Mar-2012 Marco Nelissen <marcone@google.com> Make AudioTrack/AudioRecord handle more than 2^32 frames

b/6160363
Change-Id: I471815012c6a113ec2c4dd7676e8fa288a70bc76
udioFlinger.cpp
a011e35b22f95f558d81dc9c94b68b1465c4661d 30-Mar-2012 Eric Laurent <elaurent@google.com> implemented synchronous audio capture

Added the infrastructure to support the synchronization of playback and
capture actions on specific events.
The first requirement for this feature is to synchronize the audio capture
start with the full rendering of a given audio content.
The applications can further be extended to other use cases
(synchronized playback start...) by adding new synchronization events and
new synchronous control methods on player or recorders.

Also added a method to query the audio session from a ToneGenerator.

Change-Id: I51f1167290d9cafdf2fbcdf9e4785156973af44c
udioFlinger.cpp
udioFlinger.h
b83d38feeeb88a8a2a6219e1fca2480b5a14fb0d 26-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "IAudioFlinger::createTrack and openRecord flags"
d12c68ad699ce0ed822a4d4db86e8e02324c6b03 23-Mar-2012 Glenn Kasten <gkasten@google.com> Revert "AudioFlinger does not need libmedia any more"

This reverts commit c920dee060ac69684be33210ee44b99a5fc3e8b2
ndroid.mk
4f5da11df06802856bf526f16563df7d5755f653 22-Mar-2012 Glenn Kasten <gkasten@google.com> AudioFlinger does not need libmedia any more

Change-Id: Ifd2c61882109ec36ca68072a2bf6506e08c8cf34
ndroid.mk
c5c49398584f2399af905a931e556ed6e0a29cd4 21-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Clean up Track constructor"
ccf89b54f973f11082150d02ed957f7e967fbc8b 21-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "AudioMixer can be configured for fewer max tracks"
63c1faa8dea7feb90255d31ef2a133d8f2818844 21-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Update comments"
7153494670bdac8b650cb10b8b1838651e0ca418 21-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Whitespace"
a26ff6f22f4e86d09514c2819237bd9748455018 21-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "new doesn't fail on Android"
9a5f413a21b320fea0607e653bc75b1a4f0e7a2e 21-Mar-2012 Eric Laurent <elaurent@google.com> am a48285c4: am 165ee4c5: am 14958e21: Merge "audioflinger: fix issue with camcorder and A2DP" into ics-mr1

* commit 'a48285c4f22ffc43f1771ebd1ff35dcec48db2c7':
audioflinger: fix issue with camcorder and A2DP
5c94b6c7689a335e26a86e8a0d04b56dc627738e 21-Mar-2012 Glenn Kasten <gkasten@google.com> AudioMixer can be configured for fewer max tracks

Change-Id: I371b17cef071d083eecf35cd3627a3adff907a33
udioMixer.cpp
udioMixer.h
f99590187e2e3f1cf6f093063170edec269cac5d 19-Mar-2012 Glenn Kasten <gkasten@google.com> Clean up Track constructor

The 'thread' parameter can never be NULL.
Use constructor initialization list when possible.
Make more members const.
Only put the relevant code under "if (mCblk != NULL)".
Add comment about track name leak.

Change-Id: Ib963390a69bed1999638cc982a759edd1d5f4712
udioFlinger.cpp
udioFlinger.h
ea7939a079b3600cab955760839b021326f8cfc3 14-Mar-2012 Glenn Kasten <gkasten@google.com> Whitespace

Fix indentation, and add blank lines in key places for clarity

Change-Id: I57a0a8142394f83203161aa9b8aa9276abf3ed7c
udioFlinger.cpp
udioMixer.cpp
2ee367e444e7b62e02bde8a2e47603a9ad342c6e 20-Mar-2012 Glenn Kasten <gkasten@google.com> Add libmedia_native

Change-Id: I3ac357c78fb89f108d15c6e5b9fa317de0e9fb9a
ndroid.mk
17a736c3e1d062d7fc916329eb32aef8935614af 14-Feb-2012 Glenn Kasten <gkasten@google.com> Update comments

Change-Id: I327663a020670d0a72ff57bd0b682e2ce0528650
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
a03567676e8766828ff970b87e13bc4c97b23473 19-Mar-2012 Glenn Kasten <gkasten@google.com> new doesn't fail on Android

Change-Id: I5079a3bf31097dd0807b2d806d5f8d3cff2077ab
udioFlinger.cpp
a075db4ff9b086ac2885df77bb6da0869293df92 06-Mar-2012 Glenn Kasten <gkasten@google.com> IAudioFlinger::createTrack and openRecord flags

createTrack and openRecord don't need the "old" flags parameter,
which was either audio_policy_output_t or audio_in_acoustics_t
shifted left by 16 bits. But they do need "new" flags, which
are defined by the application use case. Initially, the only
application use case flag is timed output, but others are planned.

For output, the audio_policy_output_t flags are passed to
AudioSystem::getOutput, which returns an audio_io_handle_t, and that
handle is then passed to createTrack. So createTrack doesn't need the
old flags parameter.

For input, the audio_in_acoustics_t flags are passed to
AudioSystem::getInput, which returns an audio_io_handle_t, and that
handle is then passed to openRecord. So openRecord doesn't need the
old flags parameter.

Change-Id: I18a9870911846cca69d420c19fe6a9face2fe8c4
udioFlinger.cpp
udioFlinger.h
9d7b4c074205609271f61e1a4741ac0c524a1795 19-Mar-2012 Eric Laurent <elaurent@google.com> am 14958e21: Merge "audioflinger: fix issue with camcorder and A2DP" into ics-mr1

* commit '14958e21c12f922d7501d32c3bec05109eb342d5':
audioflinger: fix issue with camcorder and A2DP
89d94e79dad032fb18ddc655e6068e4231d3f0aa 17-Mar-2012 Eric Laurent <elaurent@google.com> audioflinger: fix issue with camcorder and A2DP

Some audio HALs do not support well a device selection of 0 (no device)
received on an input stream.

This can happen because of a problem in the audioflinger code that handles
the forwarding of the output device selection to the record thread for use by
the pre processing modules that need it. If the output device is 0 (meaning
no op, which happens when stopping playback over A2DP) audioflinger could not
detect it was an output device selection and would forward it to the input
stream (see AudioFlinger::setParameters() and RecordThread::checkForNewParameters_l().

Issue 6179641.

Change-Id: Idae534521866538e0d12ba259a2834f402a922e2
udioFlinger.cpp
b12153e36ae5e514d96c77d660b327d1a8f5000f 16-Mar-2012 Glenn Kasten <gkasten@google.com> Add libmedia_native

Change-Id: Ib8cff8abd73723b793f08da99ad59549f219e0e7
ndroid.mk
33b383948e8f270bff30378476f00dce289004eb 13-Mar-2012 Glenn Kasten <gkasten@google.com> Remove dependency on audio_* location

Change-Id: I4bc66115fcb9ba22b057bd72db3f561dcb18a0d8
ndroid.mk
dfaf549e3e310bc22444f4404b19f4907b24c286 15-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "AudioFlinger playback thread CPU measurement in Hz"
190a46f7c84e160386610c0c4cecb9767fb5503b 06-Mar-2012 Glenn Kasten <gkasten@google.com> AudioFlinger playback thread CPU measurement in Hz

Log statistics on CPU usage in Hz in addition to wall clock time

Use CPU statistics for all playback threads, not just MIXER
(but they are disabled by default by a compile-time debug macro).

ThreadCpuUsage library:
- Move statistics out of the library and leave that up to the caller
- Add API to determine a CPU's frequency

Change-Id: Ia1011123146e641fcf210ef26e78ae2b4d3b64ad
udioFlinger.cpp
3b229ed97c0dfc85a8cf881341e29e595e0edea7 14-Mar-2012 Eric Laurent <elaurent@google.com> Merge "audioflinger: more info in dumpsys"
612bbb57c59397a540e96f06bdd16e437a583af5 14-Mar-2012 Eric Laurent <elaurent@google.com> audioflinger: more info in dumpsys

Added TID and io handle to AudioFlinger threads dump.

Change-Id: Ib1a856f3bad55c73e4c395b5e59d57435f4b9a4c
udioFlinger.cpp
d3cee2f0f649c01e1153d593cbe723887b8e0ba0 14-Mar-2012 Glenn Kasten <gkasten@google.com> Break circular dependency on media player service

Bug: 6165157
Change-Id: I3c85bbcaf31f3cb9a009e273f7b6284015eb3bd8
udioFlinger.cpp
e53b9ead781c36e96d6b6f012ddffc93a3d80f0d 13-Mar-2012 Glenn Kasten <gkasten@google.com> Whitespace and indentation

Fix indentation to be multiple of 4.
Make it easier to search:
sp< not sp < to
"switch (...)" instead of "switch(...)" (also "if" and "while")
Remove redundant blank line at start or EOF.
Remove whitespace at end of line.
Remove extra blank lines where they don't add value.

Use git diff -b or -w to verify.

Change-Id: I966b7ba852faa5474be6907fb212f5e267c2874e
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
udioResampler.cpp
udioResampler.h
udioResamplerCubic.h
udioResamplerSinc.cpp
fd83fbf5ead098070bae674b20e6f87f45ab5d4c 13-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Clean up assertion checks"
aa4397f07c43bd83bc3100b749401dc3d15e7622 13-Mar-2012 Glenn Kasten <gkasten@google.com> Fix bug where mMixerStatus was set to IDLE

Change-Id: I55df1738fb7ba17ba6caeea6a17557526eac17a7
udioFlinger.cpp
5798d4ebf236357a4b13246f40e52b90a34d09a4 08-Mar-2012 Glenn Kasten <gkasten@google.com> Clean up assertion checks

Use ALOG_ASSERT instead of assert.
Use compile-time asserts where appropriate.
Fix typo in an ALOGV.

Change-Id: I58f1c1ffc14319a022c88b5a88b8d0368660da8b
udioFlinger.cpp
udioMixer.cpp
73f4bc33e0d458933460250a47c64aa868c05f97 09-Mar-2012 Glenn Kasten <gkasten@google.com> Inline applyVolume() into threadLoop_mix()

Also the declaration of applyVolume in PlaybackThread was dead.

Change-Id: I4b1a9848d07d3d7f340baea05b17f667c78df868
udioFlinger.cpp
udioFlinger.h
470aa50c36089fbe0427557f7cf4464dd26a1c52 12-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Remove unnecessary friend declarations"
2d6ef93773465cd3e66146fac35050a472c589f7 12-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Remove virtual from methods that don't need it"
66fcab972e9218d47c58a915f391b2f48a09903a 24-Feb-2012 Glenn Kasten <gkasten@google.com> Merge dup code at thread entry and param change

This CL is mostly just cleanup, but there are a couple of fixes marked
"FIX" below.

Merge the duplicate code that was at the beginning of threadLoop() and
after a parameter change. cacheParameters_l() is now called at entry to
threadLoop() and after any parameter change. It re-calculates all values
that are derived from parameters, and caches them in instance variables.

updateWaitTime_l():
- FIX activeSleepTime depends on mWaitTimeMs, which was initially set
to infinity. updateWaitTime_l() was not called at entry to
threadLoop(), so activeSleepTime was not set correctly before the
first parameter change.

- FIX reversed the order of calls after parameter change
for the same reason so that updateWaitTime_l() is called before
calculating values that are derived from wait time.

- marked it private since now it's only called from DuplicatingThread

Change-Id: If2607d2ed66c6893d910433e48208a93c41fb7e9
udioFlinger.cpp
udioFlinger.h
18868c5db2f90309c6d11e5837822135e4a0c0fa 07-Mar-2012 Glenn Kasten <gkasten@google.com> Use audio_policy_output_flags_t consistently

This affects:
- IAudioFlinger::openOutput
- AudioTrack::AudioTrack
- AudioTrack::set
- apps that call these

Change-Id: I26fb281bac6cb87593d17697bc9cb37a835af205
udioFlinger.cpp
udioFlinger.h
d69549665d412f1f6ebad48ad8cd05133ada8728 09-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Replace hard-coded 3 by FCC_2 to simplify searches"
688aac7675f18bdd7bff13334759e20bc4e6c390 09-Mar-2012 Glenn Kasten <gkasten@google.com> Remove virtual from methods that don't need it

Change-Id: I30e17e61aae25b036436c0e270313c80c43e5f06
udioFlinger.h
1998661fdb6b0b5ae103e047e3d653c5da1b99e3 09-Mar-2012 Glenn Kasten <gkasten@google.com> Remove unnecessary friend declarations

Add comments to the remaining friends, so we know what is left if we
decide to remove them later.

Change-Id: I1de929257dc4700960f77902cda3d303177c72cf
udioFlinger.h
083c154162c88a9f63aeaa10a4b52dd454bda9ff 09-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Don't ask policy manager about invalid stream type"
b3dfcf483a96816fe2e949dd86fed26e52ad7404 09-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "AudioPolicyService InputDesc minor cleanup"
a19ffb656616feec70613ba67ddfe15a504a4e76 09-Mar-2012 Eric Laurent <elaurent@google.com> Merge "audio policy: use audio_devices_t when appropriate"
81872a2ce65653ae980621ba2907da56a83ba9a7 08-Mar-2012 Glenn Kasten <gkasten@google.com> AudioPolicyService InputDesc minor cleanup

Add a non-default constructor to set the mSessionId, and make mSessionId const.

Remove explicit clear on mEffects - it is automatically cleared by the destructor.

AudioPolicyService::setPreProcessorEnabled:
- parameter is const *
- use an alias instead of making a Vector copy

Destructor doesn't need to be virtual since there are no subclasses.

Change-Id: Ibc3c3bea8259839430b1cf5356186c7d96f1082f
udioPolicyService.cpp
udioPolicyService.h
53d76dbe7c55821e89d9da02e7a563f7fb45de87 08-Mar-2012 Glenn Kasten <gkasten@google.com> Replace hard-coded 3 by FCC_2 to simplify searches

Change-Id: I92881d04e8378307f849fb343071a58d181a68b4
udioFlinger.cpp
udioFlinger.h
6374252107fd6539397598195ea6defd5870fafb 08-Mar-2012 Eric Laurent <elaurent@google.com> audio policy: use audio_devices_t when appropriate

Change-Id: I1b3a5879e81c789fb53d356af3d3a1ee2dca955f
udioPolicyService.cpp
udioPolicyService.h
fec279f5a0bfaa2a42e91ab6dfa0282baeee308b 08-Mar-2012 Glenn Kasten <gkasten@google.com> Mixer status cleanup

Use mPrevMixerStatus for DirectOutputThread also.
Remove the MIXER_CONTINUE logic and use MIXER_IDLE instead.
Rename the field mixerStatus to mMixerStatus.
Rename local variable back to mixerStatus.

Change-Id: I0a8145fc856c6c5ff8b784b6176ef3c4d8eb7408
udioFlinger.cpp
udioFlinger.h
b071e9bc248865ef87a339044c0c5cbabfac175c 08-Mar-2012 Glenn Kasten <gkasten@google.com> Cleanup DirectOutputThread::mActiveTrack

Rename activeTrack to mActiveTrack.
Release the reference earlier, at the end of threadLoop_mix().
This allows the field to be made private and to
move the declaration from PlaybackThread to DirectOutputThread.

Change-Id: I02be7a254638f7d85e92aaf0002d20ca0092a5c3
udioFlinger.cpp
udioFlinger.h
639dbee79140956c43926344c23af765f6e0c9a5 07-Mar-2012 Glenn Kasten <gkasten@google.com> Don't ask policy manager about invalid stream type

Change-Id: If50fbff9d34045d1398984da48da7e6428a74491
udioFlinger.cpp
b279312a9038b9c5b9b05b31b1b1db86f748efd8 08-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "IAudioFlingerClient::ioConfigChanged param2 const"
fa26a859bacb597587a8f49acfc3127351fa688c 06-Mar-2012 Glenn Kasten <gkasten@google.com> Isolate references to outputTracks/mOutputTracks

Move all references to DuplicatingThread::outputTracks and
DuplicatingThread::mOutputTracks from the common threadLoop() into
virtual methods. This allows them to be moved from PlaybackThread to
DuplicatingThread, and to be marked private.

Also use vector assignment to copy mOutputTracks to outputTracks.

Change-Id: Ieb1cf1ad36b8a65143e61e6c92a65fb43427e5e2
udioFlinger.cpp
udioFlinger.h
a13ad6e84db128eadf23b154d3346f0bb473a5f7 07-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Make applyVolume private to DirectOutputThread"
d4513b09123deebf8023b73a82d2d46d35806cea 07-Mar-2012 Glenn Kasten <gkasten@google.com> Make applyVolume private to DirectOutputThread

Change-Id: I7ca4a59505857cbd106b6f274c66e9580dead271
udioFlinger.cpp
udioFlinger.h
a3707a280177e934a1e0a15660d9176663b7fc17 07-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Add comments about sequence for setting parameters"
1465f0c3df04c3166155a852a6a5c10069c1fd0a 06-Mar-2012 Glenn Kasten <gkasten@google.com> Merge the calls to prepareTracks_l

Change-Id: I1dd759581333e2908d980180d44db7bf5ed6591d
udioFlinger.cpp
udioFlinger.h
b81cc8c6f3eec9edb255ea99b6a6f243585b1e38 01-Mar-2012 Glenn Kasten <gkasten@google.com> IAudioFlingerClient::ioConfigChanged param2 const

The 3rd parameter (param2) to AudioFlingerClient::ioConfigChanged
is used as an input. So changed it from void * to const void *.
It is then cast to const OutputDescriptor *
or const audio_stream_type_t * depending on the event.

Change-Id: Ieec0d284f139b74b3389b5ef69c7935a8e5650ee
udioFlinger.cpp
udioFlinger.h
f8edf68a1e39da273eafe8c85bdbedc26636c4ec 07-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Rename fields of AudioSessionRef"
cbc52bfb3b51c81c945b1e35990324bde892829a 01-Mar-2012 Glenn Kasten <gkasten@google.com> Add comments about sequence for setting parameters

Change-Id: Iffa59a34c3c47bdc1d3234cdcb4d8ff99c102825
udioFlinger.h
92b8360fe9c3174dc0edaaab4b746d8a3d3f831f 07-Mar-2012 Glenn Kasten <gkasten@google.com> Merge "Fix indentation for re-organized code"
438b036deaf4413503567a75a2861c000d21da5b 06-Mar-2012 Glenn Kasten <gkasten@google.com> Rename updateWaitTime since a lock is held

Change-Id: I9bb978cbd0debf5b21676467060f72eebafea3e6
udioFlinger.cpp
udioFlinger.h
952eeb27682a9b2ddfa761f24b6eb5e18fe5d814 06-Mar-2012 Glenn Kasten <gkasten@google.com> Fix indentation for re-organized code

Change-Id: I63471cebdbd095b7ad4e481611b785f9b02c7941
udioFlinger.cpp
012ca6b4f69fb24385025c0e84b8f816525a3032 06-Mar-2012 Glenn Kasten <gkasten@google.com> Rename fields of AudioSessionRef

Change-Id: I9f2a66094135c4ac6bec2d3e9db3ac5fbf988ede
udioFlinger.cpp
udioFlinger.h
000f0e39b4d0c88441297a05ab5f8da6832c1640 02-Mar-2012 Glenn Kasten <gkasten@google.com> threadLoop merge

Change-Id: Id8e6330ac6be76f9c2debba94f856de87e2d98f7
udioFlinger.cpp
udioFlinger.h
3030fcefcfcfc48789612659206b957cd0489a54 01-Mar-2012 Eric Laurent <elaurent@google.com> renamed audio policy output flag.

Renamed AUDIO_POLICY_OUTPUT_FLAG_INDIRECT to AUDIO_POLICY_OUTPUT_FLAG_NONE
which is more appropriate.

Change-Id: Ia14d60397df0f2dcd9bea0186400a09da35bc104
udioPolicyService.h
e8286332f3817a8b7cc4cfd8f6450a3913533660 29-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Shorten thread names"
3e07470f3b122097cacfe5b85cdb1359279a2f33 29-Feb-2012 Glenn Kasten <gkasten@google.com> Prepare for threadLoop merge - active tracks

Continued work on making the copies of threadLoop more similar:
- Remove alias for mActiveTracks in MixerThread and DuplicatingThread.
- Pull in declaration of activeTrack in DirectOutputThread.
- Remove redundant parameter of prepareTracks_l().
- Comment prepareTracks_l().

Change-Id: If1087c1902b454acec01ddfdd9f055f0ca7abf04
udioFlinger.cpp
udioFlinger.h
bc4b08ba67a0245e092aee8f08ba30ef22d421bf 29-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Update AudioFlinger comments"
91cda8bdf8358a8b977a44e016b60a70bc1a5ee9 29-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Pull in declaration of effectChains to inner block"
73ca0f5837d5448f7a5eb159a09cd0ebe82b4de9 29-Feb-2012 Glenn Kasten <gkasten@google.com> Pull in declaration of effectChains to inner block

Change-Id: I09eacf72124942abd604132b9f4e774b1236fcf3
udioFlinger.cpp
c455fe9727d361076b7cead3efdac2d32a1a1d6d 29-Feb-2012 Glenn Kasten <gkasten@google.com> mSuspend comments and usage

Emphasize that playbackthread::mSuspend is a counter, not a bool

Change-Id: I7188e56814e1c54dbc65e560f3627f138257d644
udioFlinger.cpp
udioFlinger.h
688a64030834ea2f52cc9765676ddf6aa34df767 29-Feb-2012 Glenn Kasten <gkasten@google.com> Mark similar and different sections in threadLoop

Most of these comments will be removed after the threadLoop merge.

Note: the trivial change in assignments to mixBufferSize, and the
comments about "tracks to remove" is to make them all identical.

Change-Id: I3b1a33a7f2cd12ad557a1986bb71f6171161974a
udioFlinger.cpp
d805b718b1fd2d5407ef665c8d4bb42e63dc71a9 25-Feb-2012 Glenn Kasten <gkasten@google.com> Update AudioFlinger comments

Add comments to enum mixer_state
Note side-effect of lockEffectChains_l
Fix a typo

Change-Id: Ibd51678bac2193201cbcbe081ff5664046fbc494
udioFlinger.h
480b46802bef1371d5caa16ad5454fce04769c57 28-Feb-2012 Glenn Kasten <gkasten@google.com> Shorten thread names

prctl(PR_SET_NAME) limits to 15 characters. Before we had names like
"Binder Thread #" and the counter was cut off :-( Also remove redundant
"thread" at end of name; it's always a thread.

Change-Id: I1f99c2730ba0787ed9b59c15914356cddf698e2f
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
a3873833d518e032138cf70188b6f33cd7acec3d 28-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Unlock effect chains in the middle of two if's"
3e9c3a1d34960cd258f294d31135ab6bf76179d5 28-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Simplify removeNotificationClient"
a17c820c556fddf7ddd96b82b3e9874e340ffafd 28-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "AudioFlinger const methods and parameters"
cfbd62616ab2b12f0fee603658f04e5827cc7f8f 28-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Fix theoretical race condition in addOutputTrack"
fadb2c73fce479205432652530663e1e90fd546c 28-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "AudioBufferProvider comments and cleanup"
843a12d146bd64642bf85a4e56c274246e3893a6 27-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Fix tracking of hardware state for dump"
e628d515888baadba75442128678e747e930ed58 27-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Make threadLoop() logs identical"
d3cee0b1f77baa4fb7a049eb757e9f5006890726 27-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Move declaration of mixerStatus to inner block"
a3b09254d44cd8d66ec947abe547538c4cfeaa89 20-Jan-2012 Glenn Kasten <gkasten@google.com> Simplify removeNotificationClient

No need to check for presence of item before removing
(but we do lose the log of the previous value).

Change-Id: I2838430824de5f257f2ee15db0c22b1920c67d08
udioFlinger.cpp
02fe1bf923bbe5789202dbd5810e2c04794562e6 25-Feb-2012 Glenn Kasten <gkasten@google.com> AudioFlinger const methods and parameters

Change-Id: I93ec28024005ed23aa141518092a012a4a7c44c5
udioFlinger.cpp
udioFlinger.h
c0b52836d07f823732f0ff98ca5ca9d7f5730cb8 24-Feb-2012 Glenn Kasten <gkasten@google.com> Make threadLoop() logs identical

Change the wording of the logs in the various copies of threadLoop()
to be identical. This will make it easier to merge them soon.

Change-Id: Idfa181e437738712c784dc7f746cac79f83d2931
udioFlinger.cpp
5d4eeeaf76ebe177b43e87b2a9df5e55e39021f0 24-Feb-2012 Glenn Kasten <gkasten@google.com> Move declaration of mixerStatus to inner block

mixerStatus was being declared (and initialized) too early,
which also resulted in a duplicate initialization. Moved
the declaration into the block where it is actually used.

Change-Id: Ifdcfefe362a5efe3493dd616cdb44645c6f9aed5
udioFlinger.cpp
37d825e72a6c606553a745da1212590a425996d3 24-Feb-2012 Glenn Kasten <gkasten@google.com> Pull out duplicated copies of silent mode check

Also fix the error handling for the property_get.

This is part of preparation for the threadLoop() merge.

Change-Id: I6405190ea18146d1271575e1dfe9f279e8f36b17
udioFlinger.cpp
udioFlinger.h
04743e99e71c0da012508c7119f414027654ee94 24-Feb-2012 Glenn Kasten <gkasten@google.com> Unlock effect chains in the middle of two if's

As part of the upcoming threadLoop() merge, this CL makes it clearer
what are the similar and different parts before and after unlocking
effect chains.

In each threadLoop(), the old code was:

if (sleepTime == 0) {
// A
unlockEffectChains(effectChains);
// B
} else {
unlockEffectChains(effectChains);
// C
}

The new code is:

if (sleepTime == 0) {
// A
}
unlockEffectChains(effectChains);
if (sleepTime == 0) {
// B
} else {
// C
}

Also this is slightly slower by one "if", it has the advantage of making
it much more obvious about what is done before and after the unlock,
and also to see the similarities and differences among the various
copies of threadLoop().

Change-Id: I7bf4369d2dcb072573ec43b7e52c637f0097dc00
udioFlinger.cpp
5ce96d97feafc6989f6141bb2633eae3d87ddf28 24-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Pull CPU statistics code out of threadLoop()"
b6b740629c9f11535086e744465bada03f26df11 24-Feb-2012 Glenn Kasten <gkasten@google.com> Fix theoretical race condition in addOutputTrack

This is not a real race, because addOutputTrack was only called in two
places, and in both places there could be no other threads referencing
the DuplicatingThread instance.

Those two places are:
- the DuplicatingThread constructor, which is of course safe
- openDuplicateOutput - this is safe because it's called immediately
after the new DuplicatingThread, and there are no sp<> either in the
constructor or here which could cause onFirstRef() to do Thread::run().

But for safety in case addOutputTrack is ever called somewhere else,
or there are sp<> created earlier, it is safer to take the thread lock.

Change-Id: I1502d014fa37ec5dbf4bf40d3e2884af311cd5e9
udioFlinger.cpp
83efdd0fc08cd5aedf50b45741a8a87be8dc4b41 24-Feb-2012 Glenn Kasten <gkasten@google.com> Pull CPU statistics code out of threadLoop()

This is to prepare for the threadLoop() merge

Change-Id: I118c7d5c6b011b5d5b95ec7d63fb03feb166a9cf
udioFlinger.cpp
01c4ebf6b794493898114a502ed36de13137f7e5 22-Feb-2012 Glenn Kasten <gkasten@google.com> AudioBufferProvider comments and cleanup

Add comments about which methods implement the AudioBufferProvider interface.

Simplified the definition of kInvalidPts. <stdint.h> is very hard to work
with, there seems to be no way to use it reliably to get INT64_MAX without
having a separate source file, which is ugly because it means kInvalidPts
is not a compile-time constant. So I just deleted AudioBufferProvider.cpp
and used a hard-coded constant instead.

Added a default constructor for Buffer so that the fields aren't random
(especially .raw which is used to determine if the buffer is valid).

Make the pts for getNextBuffer default to kInvalidPTS so code that
doesn't need a pts doesn't have to specify a value.

Rename the parameter to AudioMixer::setBufferProvider to make it clearer.

Change-Id: I87e7290884d4ed975b019f62d1ab6ae2bc5065a5
ndroid.mk
udioBufferProvider.cpp
udioBufferProvider.h
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
8abf44d2f2bcd20a2835570efe89d89c19db426a 02-Feb-2012 Glenn Kasten <gkasten@google.com> Fix tracking of hardware state for dump

At end of AudioFlinger::onFirstRef(), the hardware status was being left
in wrong state. It should be AUDIO_HW_IDLE but was AUDIO_HW_INIT.

mHardwareStatus was being set to AUDIO_HW_OUTPUT_OPEN too early, and so
a return would leave it in the wrong state until next hardware operation.

Take the hardware lock for dev->get_parameters, and update mHardwareStatus
before and after.

Keep hardware lock only for the duration of the dev->set_parameters.

Rename two constants in enum hardware_call_state to have the prefix
AUDIO_HW so they follow the naming conventions.

Add comments.

Change-Id: I6c7450b11f9b13adaeef9cec874333e478a58fc0
udioFlinger.cpp
udioFlinger.h
5cf034d92d901169ca6e36c90475f40715827fcd 21-Feb-2012 Glenn Kasten <gkasten@google.com> Remove TrackBase::mFlags

The bit-field TrackBase::mFlags was supposed to have track-specific
flags in the upper 16 bits, and system flags in the lower 16 bits.

The upper 16 bits of mFlags were initialized in the TrackBase
constructor from the flags parameter of IAudioFlinger::createTrack()
and IAudioFlinger::openRecord(), and the lower 16 bits were cleared.

However, the upper 16 bits of mFlags were never acccessed again.
So really there are no track-specific flags. I left the flags
in the parameter list of createTrack() and openRecord() but made a
note that these should be removed eventually as they are dead.

This leaves only the one system flag "step server failed". I replaced
the bit-field mFlags by bool mStepServerFailed, which is simpler and
slightly faster.

Change-Id: I6650f5487be72791b4a67d73adcd10ffa04e2aa5
udioFlinger.cpp
udioFlinger.h
d6fd85a157ce2054b2304e6d171fa87ae09c363d 22-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Avoid wp<>::unsafe_get() with a few exceptions"
9eaa55756c5b245970447019250ce852f5189525 20-Jan-2012 Glenn Kasten <gkasten@google.com> Avoid wp<>::unsafe_get() with a few exceptions

Avoid using wp<>::unsafe_get() except in a log, and other specific cases
when it's known to be safe.

Use more specific subclass types for parameters to avoid down-casts.

When a constructor or method parameter is "this" of an object that is
currently being constructed, it's better to use a raw pointer rather
than either sp<> or wp<>.

Using the raw pointer is safe, provided either:
- it is "this" of an object being constructed (which has sp<> refcount of 0),
- or the caller already holds an sp<>

The raw pointer is simpler and faster, and it avoids the problem of the
sp<> reference count being incremented and then decremented to zero on
scope exit, which would cause the object's destructor to run while the
object is still being constructed.

Also removed some dead code per a review comment.

Change-Id: I7375f64da3aec11b928c33cb01faff186252ef5e
udioFlinger.cpp
udioFlinger.h
f063b49e95c28d63a58215ebda892a5fee4204cc 18-Feb-2012 Glenn Kasten <gkasten@google.com> Fix build warning

warning: pointer of type 'void *' used in arithmetic
warning: enumeral and non-enumeral type in conditional expression

Change-Id: I7b8d626a636145ef648e3b5d0e77068216dd012e
udioFlinger.cpp
3b81acab52b7140c1b8b20be2d67be3e221637e7 28-Jan-2012 Glenn Kasten <gkasten@google.com> Remove bit fields to improve performance

uint16_t enabled is (mostly) changed to bool in a separate CL

Change-Id: Ied9f8c034b2479cee9a8778cee7b8ff92ae75b7b
udioFlinger.cpp
udioMixer.cpp
udioMixer.h
1b094ee8f7fe7eca65bf3d2f983ba95eef6db93d 17-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Simplify code"
a111792f1314479c649d1d44c30c2caf70c00c2a 26-Jan-2012 Glenn Kasten <gkasten@google.com> Simplify code

Use DefaultKeyedVector::valueFor to avoid extra test
Make local variables as local as possible
No double parentheses
No typedef for single use
No parentheses around indirect function call
No AudioFlinger:: prefix when not needed
Remove unnecessary casts
Remove block with only one line

Saves 128 bytes

Change-Id: I3a87430eeb01b81e7b81a1c38f6fdd3274ec48f3
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
udioPolicyService.cpp
29dcfcd66d884801e9907d04e81d407ee770802c 17-Feb-2012 Mike Lockwood <lockwood@google.com> Merge "Put a bandaid on a segfault in timed audio track handling."
fe5b3ba4b332d5fc9aa4f453434329b9f38768c2 13-Feb-2012 John Grossman <johngro@google.com> Put a bandaid on a segfault in timed audio track handling.

Add a bandaid to prevent a segfault which can occur while handling
timed audio buffers. There is a deeper problem which should
eventually be addressed, but for now this fix should prevent any
crashing.

The deeper problem is as follows.

When the AudioFlinger mixer gets data to mix from an AudioTrack, it
ends up getting a structure filled out which points into an IMemory
region owned by the AudioTrack. Unfortunately, this structure is not
holding a refcount on the IMemory which it points into. If the
IMemory refcount hits 0 and the chunk of RAM is retuned to the binder
heap it came from, there can still be a Buffer object being held by
the AudioFlinger mixer which points into the region of memory which
was retuned to the binfer heap. If AF reads from this buffer, it
could read corrupt data (if the region of memory gets handed back out
to a writer), or it could segfault (if the heap has been freed and the
pages unmapped). Similar problems could happen if AF attempts to
write to the buffer, heap corruption in one case, segfaulting in the
other.

In the past, this has not been an issue for AF, because tracks
allocate a single IMemory (which serves as a ring buffer) and the
IMemory lives for as long as the track lives. As an artifact of the
way the code came out, the mixer cannot be holding a Buffer structure
pointing into the IMemory which used to be owned by a track if the
track no longer exists. Tracks cannot come into or out of existence
during a mix operation, which is the only thing which makes this safe.

TimedTracks work differently, however. Timed tracks each allocate a
small binder heap, and then hand out IMemory instances broken out of
this heap. The heap lives as long as the track, so the worst which
could happen here is that a TimedTrack's IMemory gets returned to the
heap while there is still a buffer structure in flight pointing into
the memory region, then the region gets handed out again and
overwritten by new data causing the mixer to mix the wrong audio. The
timing to cause this to happen is very difficult to encounter, and you
to generate the timing conditions required, you need to be in a pretty
bad failure state where audio is already breaking up and skipping, so
its unlikely that anyone would notice (which is why I'm band-aiding
the segfault and letting the deeper issue slide for now).

In general, however, it might be a good idea to revisit this buffering
design. On principal, if someone is going to hold pointers into a
refcounted object, they should be holding a ref on the object at the
same time. Failure to do this will usually lead to a situation where
there are corruption or segfault issues, or to a system where the
refcounted object's lifetime must be implicitly managed very carefully
in ways which are usually non-obvious and are easy to break by new
engineers on a project.

Change-Id: Ib391075395ed0ef46a03c37aa38a82d09e88abeb
udioFlinger.cpp
9fda4b87441fe17d90d8144639c9de6d9022c3c0 02-Feb-2012 Glenn Kasten <gkasten@google.com> Fixed possible heap corruption in EffectDesc

"EffectDesc *effect = new EffectDesc(*effects[i]);" was relying on the
default copy constructor for EffectDesc, but the default copy constructor
does a member-by-member copy. This works OK for mUuid, but a member
copy of mName and mParams shares pointers. This could result in heap
corruption later on due to a double free. Changed to add an explicit
copy constructor that does a deep copy of both mName and mParams.

A malloc() and strdup() were being freed by delete, but the correct
matching API for these is free(). Fortunately our current memory runtime
implementation ignores the difference. Changed to use free().

EffectDesc and InputSourceDesc member fields were being torn down by
the code that does delete. Changed to do the tear-down in ~EffectDesc()
and ~InputSourceDesc().

Added constructor EffectDesc() with name and UUID parameters, rather
than having caller fill in the object after construction.

Made ~EffectDesc() and ~InputSourceDesc() non-virtual to save memory,
since they have no subclasses.

Change-Id: Ibb5cc2e6760d72e0c4cf537068ac4432c717bafd
udioPolicyService.cpp
udioPolicyService.h
ef7740be67a4d7b6b033ebed59c3d4a9c74a2c18 09-Feb-2012 John Grossman <johngro@google.com> Fix a segfault in AudioFlinger.

Check the string returned by a HAL's implementation of get_parameters
for NULL before attempting to make use of it. That way, we won't
bring down the mediaserver because of a poorly written HAL.

Change-Id: Ic99d7b004520d7d6347842a681c0595e889b68ea
Signed-off-by: John Grossman <johngro@google.com>
udioFlinger.cpp
4ff14bae91075eb274eb1c2975982358946e7e63 09-Feb-2012 John Grossman <johngro@google.com> Upintegrate Audio Flinger changes from ICS_AAH

Bring in changes to audio flinger made to support timed audio tracks
and HW master volume control.

Change-Id: Ide52d48809bdbed13acf35fd59b24637e35064ae
Signed-off-by: John Grossman <johngro@google.com>
ndroid.mk
udioBufferProvider.cpp
udioBufferProvider.h
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
udioResampler.cpp
udioResampler.h
udioResamplerCubic.cpp
udioResamplerSinc.cpp
6dad4378f2a78d967defc8912ecf47f6ed117584 14-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Fix races related to volume and mute"
d9b9b8d09e7471b0ffa21cfa9f944ef4ad300a71 14-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Update comments"
99e53b86eebb605b70dd7591b89bf61a9414ed0e 19-Jan-2012 Glenn Kasten <gkasten@google.com> Update comments

We no longer put the filename at start of file.

Change-Id: Ic435b159a23105681e3d4a6cb1ac097bc853302e
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
8d6a2449a91f5116d7243ab039393195ebd663fe 08-Feb-2012 Glenn Kasten <gkasten@google.com> Use size_t and ssize_t with Vector

Use size_t with size() and ssize_t with indexOfKey(). Exception:
use ssize_t for backwards loops, and indices that are overloaded as a
marker or error code.

Change-Id: Ibf2a360af4539b72b09c818dda22ea2a0de92431
udioFlinger.cpp
udioPolicyService.cpp
6dbc1359f778575d09d6da722b060a6d72c2e7c5 02-Feb-2012 Glenn Kasten <gkasten@google.com> AudioRecord and AudioTrack client tid

Inform AudioFlinger of the tid of the callback thread.

Change-Id: I670df92dd06749b057238b48ed1094b13aab720b
udioFlinger.cpp
udioFlinger.h
44deb053252a3bd2f57a007ab9560f4924f62394 06-Feb-2012 Glenn Kasten <gkasten@google.com> Factor out and speed up permission-checking code

Use the caching permission check for dump to save IPC.

Cache getpid() to save kernel call for other permission checks.

The C runtime library getpid() can't cache due to a fork
race condition, but we know that mediaserver doesn't fork.

Don't construct String16 on the stack.

Change-Id: I6be6161dae5155d39ba6ed6228e7683e67be34ed
ndroid.mk
udioFlinger.cpp
udioPolicyService.cpp
erviceUtilities.cpp
erviceUtilities.h
2b213bc220768d2b984239511cd4554a96bc0079 02-Feb-2012 Glenn Kasten <gkasten@google.com> mAudioHwDevs and related cleanup

Inline AudioFlinger::initCheck and remove unnecessary lock.

Remove redundant check of mAudioHwDevs.size().

No need to lock mHardwareLock for each device separately
during initialization.

Use size_t not int to loop through Vector, since size() returns size_t.

Add missing hardware lock for get_mic_mute() and get_input_buffer_size().

Add comments.

Change-Id: Iafae78ef78bbf65f703d99fcc27c2f4ff221aedc
udioFlinger.cpp
udioFlinger.h
b6333aa8317ce5162ab006c4baed6b0890936dc7 11-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Simplify ThreadBase::exit() aka requestExitAndWait"
3a144d08b713e3c0f6b7b8e95bc42cef5886f4fa 11-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Disable HQ resamplers for now until qualified"
0d9302d7830b46542821b3e5f3e4f96942bd3cb3 11-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Move header declarations around for clarity"
858df80948ee64f478782a6a6c06533ba1651ef1 11-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Camel case readability & private disconnect(bool)"
95a87908ddf240760e8e8b35a6cafcc149c7f33f 11-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Remove aliasing"
c8ad36bbb30e99e49026cba78e5e0f83db5cb0f6 11-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Use mul from audioutils"
31f0acff69efd46897221d847becca79ab15105f 11-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Mark fields const if only set in constructor"
b28686f95daee16edeb5f39af2cd5274ac3dc99f 06-Jan-2012 Glenn Kasten <gkasten@google.com> Simplify ThreadBase::exit() aka requestExitAndWait

We can remove mExiting and use Thread::exitPending() instead.

The local sp<> on "this" in exit() is not needed, since the caller must
also hold an sp<> in order to be calling us. (Unless it was using a raw
pointer, but that would be dangerous for other reasons.)

Add comment explaining the mLock in exit().

Change-Id: I319e5107533a1a7cdbd13c292685f3e2be60f6c4
udioFlinger.cpp
udioFlinger.h
9d1f02d74fd395ec4de6861147da289423f0ab6f 09-Feb-2012 Glenn Kasten <gkasten@google.com> Follow raw pointer and sp<> conventions

Unconditional delete for raw pointers.
Use "if (sp != 0)" not "if (sp.get() != 0)" or "if (sp != NULL)".
Use "if (raw != NULL)" not "if (raw)".

Change-Id: I531a8da7c37149261ed2f34b862ec4896a4b785b
udioPolicyService.cpp
0ba18ec1b343a8de70924f87630dd1f329b00fe6 10-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "No newline or space at end of ALOG format string"
12018d80add66f5558675614d73fa6549150806e 10-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Move declaration of stream_type_t up earlier"
8b5980798ca06e57b1284e6e23fa220e1207bf41 10-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Fix typos in ALOG for pid vs tid"
cdf2158f3b9498d6cd0eb228d8bee16e32399e16 02-Feb-2012 Glenn Kasten <gkasten@google.com> Disable HQ resamplers for now until qualified

This saves about 6500 bytes.

Change-Id: I87102fe561c95c19c9e615dea3de914f96639257
ndroid.mk
udioResampler.cpp
2f732eb768004c6362fae8a02c60b69c9400b032 26-Jan-2012 Glenn Kasten <gkasten@google.com> Move header declarations around for clarity

Put IAudioFlinger methods in binder opcode order.
Move hardware call state closer to where it is used.
getMode() and btNrecIsOff() are private.

Change-Id: Ie50340b396c39c763f2b155cbc08da8a0d0f2424
udioFlinger.h
004f719467c498942c40de9f260be601ee45e630 30-Jan-2012 Glenn Kasten <gkasten@google.com> Mark fields const if only set in constructor

Change-Id: Iacd06bb9efaf708cf965033be1f2297b58f7f75c
udioResampler.h
d198b61603d5fa9298edea4ddb5852ea45159906 02-Feb-2012 Glenn Kasten <gkasten@google.com> Remove aliasing

Code was aliasing mBuffer as buffer, but continuing to use both buffer
and mBuffer after that point. This was at best misleading, and at worst
could confuse the compiler into generating bad code. There was no
performance advantage to the alias, in fact removing it saves 16 bytes.

Change-Id: I55023ddba465d9be82f66745b088d18af658ac60
udioResamplerSinc.cpp
58123c3a8b5f34f9d1f70264a3c568ed90288501 03-Feb-2012 Glenn Kasten <gkasten@google.com> Camel case readability & private disconnect(bool)

Change-Id: If66516ed2703e048c5e6ccc6cd431446a024f4a1
udioFlinger.cpp
udioFlinger.h
5b9ff43995f6a6b819d9ad37dd8cdc5ad4a088d7 09-Feb-2012 Glenn Kasten <gkasten@google.com> Use mul from audioutils

I verified that the disassembled output is identical.

Change-Id: I34a76f0842ebc4aef2c923e079e38d0bc1f98b5c
udioFlinger.cpp
23d82a9bc9a43b49ba684ba40875b91db310d3b9 03-Feb-2012 Glenn Kasten <gkasten@google.com> Fix typos in ALOG for pid vs tid

Change-Id: I6dc70f137d0ff8a86427ab8882a81886e1de0782
udioFlinger.cpp
udioPolicyService.cpp
90bebef5669a9385c706b042d146a31dca2e5d9b 28-Jan-2012 Glenn Kasten <gkasten@google.com> No newline or space at end of ALOG format string

Change-Id: I0bef580cbc818cb7c87aea23919d26f1446cec32
udioFlinger.cpp
udioResampler.cpp
udioResamplerCubic.cpp
6637baae4244aec731c4014da72418d330636ae1 09-Jan-2012 Glenn Kasten <gkasten@google.com> Fix races related to volume and mute

Fix race conditions when setting master volume, master mute, stream
volume, stream mute for a playback thread, and when reading stream
volume of a playback thread. Lock order is AudioFlinger, then thread.

Rename streamVolumeInternal to streamVolume_l, comment, and use it to
implement streamVolume().

Code size reduction:
- Remove dead code: AudioFlinger::PlaybackThread::masterVolume, masterMute, streamMute.
- Change return type of non-binder methods that always succeed from status_t to void.
- Remove virtual from volume and mute methods that don't need it.

This change saves 228 bytes but decreases performance of binder operations
due to the added locks.

Change-Id: Iac75abc1f54784873a667d1981b2e08f8f31e5c9
udioFlinger.cpp
udioFlinger.h
b7bf796b758e144f94f6ed4d16c21bf22a118fb3 08-Feb-2012 Glenn Kasten <gkasten@google.com> Move declaration of stream_type_t up earlier

stream_type_t is used by AudioFlinger class, so it should be declared there.
This way we don't have to peek into PlaybackThread to get the declaration.

Change-Id: Ie08bab1604699214d1e8df2d48d3fbfbbc436e96
udioFlinger.h
02bbd20cece1785c223ac4ca2ddc635931a80673 08-Feb-2012 Glenn Kasten <gkasten@google.com> Rename type() to streamType()

This avoids possible confusion with thread's type().
Also remove redundant cast "(audio_stream_type_t)".

Change-Id: I320b9177b6c267a102d215f002228bcf988c437a
udioFlinger.cpp
udioFlinger.h
98ec94c5854daccc3474758524e7f4adfe535ce0 25-Jan-2012 Glenn Kasten <gkasten@google.com> Combine duplicate code & document wp<> in mClients

Change-Id: Iea8cfe8e57563337fb2484a1246ef79d6ad3db18
udioFlinger.cpp
udioFlinger.h
72ef00de10fa95bfcb948ed88ab9b7a177ed0b48 17-Jan-2012 Glenn Kasten <gkasten@google.com> Use audio_io_handle_t consistently instead of int

Other:
- add a comment to nextUniqueId
- made ThreadBase::mId const, since it is only assigned in constructor.

Change-Id: I4e8b7bec4e45badcde6274d574b8a9aabd046837
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
dbfafaffe2e97eaf8d74ec6b6c468418a1ad2443 26-Jan-2012 Glenn Kasten <gkasten@google.com> Simplify destructors

Remove explicit clear() when the order doesn't matter.

Change-Id: I5931bc7ef5f681c7ce329aa9ec0a6e46d34a56c5
udioFlinger.cpp
5e92a7861196ddae14638d4b7a63fc4892b7ef59 30-Jan-2012 Glenn Kasten <gkasten@google.com> Effect UUID inputs passed by pointer are const

Change-Id: I1f5c338bcb7368e3dd8cd5f804b2e6d9fbe087f8
udioFlinger.cpp
udioFlinger.h
0a20fa9c41c96e31fa20e071074a4b6e7f6c41c3 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Use pid_t not int"
b61ec89bb0c701b3bd06eb658f854230681f8b39 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Don't double destruct audio_track_cblk_t"
63d2daed17ab749baa80bc808fb5083b688b771b 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "AudioFlinger methods const and inline"
86feafe15b3f9609e1e9f64184688c2b6f2e4834 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Use virtual destructors"
e616d4e6de6d53ddebbc3d7fb381af94589c2232 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Improve performance for sp<> on stack"
1579d7948117e3e6541b0cfda02cc5234a3280ea 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Use 0 not NULL for sp<> and wp<>"
b5a66e15f371143f48665bbd462d75309582845d 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Use bool instead of int"
e98bbd36d67243fe987b09904956550a68af1cc7 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Declare more IAudioFlinger methods const"
1a0ae5be3d1273cba12584b33830d859510fbf82 03-Feb-2012 Glenn Kasten <gkasten@google.com> Don't double destruct audio_track_cblk_t

Fortunately audio_track_cblk_t doesn't have a destructor, but for clarity
remove the double destruction.

Also add warning not to add any virtuals to audio_track_cblk_t.

Change-Id: I70ebe1a70460c7002145b2cdf10f9f137396e6f3
udioFlinger.cpp
bb001926447d0b7dc71ca8bb3c9856f3136d8f4c 03-Feb-2012 Glenn Kasten <gkasten@google.com> Use pid_t not int

Change-Id: Iad1c2fd4152e94080ad8c65c13ddf4519fc2ed27
udioFlinger.cpp
d5e54f7a36daedc3b2a642d1499c262da04e6280 26-Jan-2012 Glenn Kasten <gkasten@google.com> Remove dead code

mFormat is unused in resampler
mClientTid is unused
local variable pid is unused in dump

Change-Id: Ib156e38029366620bfeff2a13e73471867155a5b
udioFlinger.cpp
udioFlinger.h
udioResampler.cpp
udioResampler.h
f587ba5b991c7cd91e4df093d0d796bd419e5d67 27-Jan-2012 Glenn Kasten <gkasten@google.com> Declare more IAudioFlinger methods const

This is just documentation, as C++ method const-ness doesn't mean anything
for a binder API. Instead, here const means "no side effects".

Change-Id: Iaa9cd2fe477db10ae9a40cac4f79f0faa9b4e5e6
udioFlinger.cpp
udioFlinger.h
4c340c6521b634f159d2d6bc4e9359226fd8edf8 27-Jan-2012 Glenn Kasten <gkasten@google.com> Use bool instead of int

The .h is not modified to avoid increasing data size.

Change-Id: Ide4a821a5b16424ffa03471dfff98dc3e9b5f751
udioMixer.cpp
c59c004a3a6042c0990d71179f88eee2ce781e3c 02-Feb-2012 Glenn Kasten <gkasten@google.com> AudioFlinger methods const and inline

This saves 1063 bytes and probably improves performance.

Change-Id: I11cf0dfd925fbaec75e3d1b806852a538eae5518
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
udioResampler.h
c19e22450e6e3d07594c935c7a9522e85e909e82 30-Jan-2012 Glenn Kasten <gkasten@google.com> Use virtual destructors

It turns out to be just a comment, as all except AudioMixer are RefBase.

There are only a few performance-sensitive cases where it's worth thinking
about whether you need a virtual destructor, and the headache usually
outweighs the benefit.

Change-Id: I716292f9556ec17c29ce8c76ac8ae602cb496533
udioFlinger.h
udioMixer.h
udioResamplerSinc.h
7378ca506e4e20c2b2d4e94a131cf1b95831adb5 20-Jan-2012 Glenn Kasten <gkasten@google.com> Use 0 not NULL for sp<> and wp<>

Change-Id: Id1f0c89acefaceed6cb9ca7c165fce895e46d85b
udioFlinger.cpp
udioPolicyService.cpp
787bae0578fbaab6219ebf23494866b224d01438 03-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Use audio_in_acoustics_t consistently"
ff3c83e04ae459c4252b86dd4440b4e37ee92c16 03-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Use ToneGenerator::tone_type consistently"
a0d68338a88c2ddb4502f95017b546d603ef1ec7 28-Jan-2012 Glenn Kasten <gkasten@google.com> Use NULL not 0 for raw pointers

Use if (p != NULL) instead of if (ptr)

Change-Id: Iaec3413a59ccbf233c98fcd918cc7d70ac5da9fa
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
87f155d6655b2d3b27e69281a29e85c6407e4d26 03-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "For performance, return large objects by reference"
f81e97e4ec8b01965a5b36987f886cf5001f71ff 03-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "No need to check a wp<> for 0 before promote()"
84afa3b51ac48f84ed62489529ce78cba7fca00e 26-Jan-2012 Glenn Kasten <gkasten@google.com> Constructor initialization and const fields

In constructors, initialize member fields in the initialization list
rather than constructor body where possible. This allows more fields
to be const, provided they are never modified.

Also initialize POD fields in constructor, unless it's obvious they
don't need to be initialized. In that case, put a comment instead.

Remove explicit clear() in destructors on fields that are now const.

Give AudioSessionRef a default constructor, so it's immutable fields can
be marked const.

Add comment about ~TrackBase() trick.

Initialize fields in declaration order to make it easier to confirm that
all fields are set.

Move initialization of mHardwareStatus from onFirstRef() to constructor.

Use NULL not 0 to initialize raw pointers in initialization list.

Rename field mClient to mAudioFlingerClient, and getter from client()
to audioFlingerClient().

Change-Id: Ib36cf6ed32f3cd19003f40a5d84046eb4c122052
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
5c0ad10b14ec2287f90f95912d98e66eef006e2a 03-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Cleanup thread types"
62da7fbd60bee2dd57f503126266e9f04311d400 03-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Make AudioTrack control block volume field private"
d45ee9d9d61af0791c7c3c51f8d4fe6794ef02a5 02-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Fix const sp<>& in parameter list and return value"
d05397144be774f2f3623c754e865f51753e4e31 30-Jan-2012 Glenn Kasten <gkasten@google.com> For performance, return large objects by reference

Change-Id: Ibf737018ef1d3c7d717584615dcb2d4ecdb50c99
udioFlinger.cpp
udioFlinger.h
090f01963e215f895020a31e22368cd44e086ce3 30-Jan-2012 Glenn Kasten <gkasten@google.com> Improve performance for sp<> on stack

Combine default constructor for sp<> immediately followed by assignment,
as the reference-counting is relatively slow. Also return sp<> directly
rather than via local variable, for the same reason.

Change-Id: If55931f1e407994f6591ddde41b53db72fb4fc40
udioFlinger.cpp
435dbe6c3ecd04bcb4bd80584064e287ebccd720 30-Jan-2012 Glenn Kasten <gkasten@google.com> Fix const sp<>& in parameter list and return value

EffectModule::addHandle and Client::heap() were declared incorrectly.

As a parameter, an sp<> should be & for efficiency, and for input
parameters it should also be const to protect the caller's value.

But as a return value, an sp<> should have neither const or &. The "e"
in "return e;" might be located on the stack, and if there is "&" then
the caller would see the address of a variable which no longer exists.
Also, an & would make it hard to do "return 0;".
A "const" without & is meaningless in the return type.
(In this particular case, the "e" is a member field, so it was safe.)

Change-Id: I3df5f294214eb15a9d4d596c6d5ef29de97b5c27
udioFlinger.cpp
udioFlinger.h
e9dd0176933d6233916c84e18f3e8c0d644ca05d 28-Jan-2012 Glenn Kasten <gkasten@google.com> Unconditional delete

Don't check that pointer is non-NULL before delete.

Don't leave deleted member fields non-NULL, except in a destructor,
since it could be misleading in a dump or debugger. (mRsmpOutBuffer)

Change-Id: Ic0492a6b752f74a67f4c96dfb89ca2de4e69eecf
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
77c1119ea0b5cb32287088ceeeb7e3b6bd14a85d 25-Jan-2012 Glenn Kasten <gkasten@google.com> No need to check a wp<> for 0 before promote()

Also remove unnecessary wp<> local variable.

Change-Id: I620e67b5d559d28616f8e00609a525cfe19c5ddc
udioFlinger.cpp
3d2f877c1cb4e4ae4ddde7f57f4353de9341f11b 28-Jan-2012 Glenn Kasten <gkasten@google.com> Use ToneGenerator::tone_type consistently

Also remove defaults in startToneCommand(), they're not needed and the
default for tone type was nonsense.

Change-Id: I70fa8cee4f3dbb8c66ceb3719c8d3d2f447f05b9
udioPolicyService.cpp
udioPolicyService.h
de9719b3ec71472e6bf75117152176af51d1a515 27-Jan-2012 Glenn Kasten <gkasten@google.com> Use audio_in_acoustics_t consistently

Change-Id: I0a9dd668fb2e57b1c3ece3190588194974b99062
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
fd267d7cf640225bb57f0ed1af44efc153275f6d 27-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use audio_source_t consistently"
a3a2cd4072aaa2d93c91251a786eb7323f8d2c27 27-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "AudioStreamIn and AudioStreamOut"
6f5980b75df837231365d238c1b0d6f386363fbb 27-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Declare methods in binder opcode order"
28f52c84c22e129063a576e1269a39ae0cc0bfb3 27-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use enum effect_state consistently"
114c458f2b80a252ec627add1d5fda2093c79068 27-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use enum track_state consistently"
eba51fb3a361f67a6a64d5a16eba6084fe27d60e 23-Jan-2012 Glenn Kasten <gkasten@google.com> Use audio_source_t consistently

Was a mix of audio_source_t, uint8_t, and int.

Related fixes:
- fix comments in MediaRecorder.java
- AudioPolicyService server side was not checking source parameter at
all, so if the client wrapper was bypassed, invalid values could be
passed into audio HAL
- JNI android_media_AudioRecord_setup was checking source for positive
values, but not negative values. This test is redundant, since already
checked at Java and now checked by AudioPolicyService also, but might
as well make it correct.

Change-Id: Ie5e25d646dcd59a86d7985aa46cfcb4a1ba64a4a
udioPolicyService.cpp
udioPolicyService.h
aed850d0d3b3c8cf3feaf1438076f33db2a60946 26-Jan-2012 Glenn Kasten <gkasten@google.com> AudioStreamIn and AudioStreamOut

These are immutable, so make the fields const.
getOutput() and getInput() methods are now const.

Change-Id: I128246ebd56ea50b3e542be43f2aa1bcb55f1373
udioFlinger.cpp
udioFlinger.h
23bb8becff20449a9b1647d5a1a99b14c83f0cce 26-Jan-2012 Glenn Kasten <gkasten@google.com> Cleanup thread types

Use type_t instead of int for thread types.
Initialize ThreadBase::mType in constructor and make it const.

Change-Id: I43d141388b9639e4783c30b97dbda5688bf7555f
udioFlinger.cpp
udioFlinger.h
90716c5728b37637b2d0a730a721bfc9fad299e0 26-Jan-2012 Glenn Kasten <gkasten@google.com> Declare methods in binder opcode order

This makes it easier to compare interface and implementation.

Change-Id: Ie060e43dec348902abcf40f5a610cec639d6d0d3
udioFlinger.cpp
udioFlinger.h
29c23c3aee5ae799b3480dc6876a46c46b019710 26-Jan-2012 Glenn Kasten <gkasten@google.com> Use enum mixer_state consistently

Change-Id: I5b71ed20f939dfc4b98143334b7aa064d282f584
udioFlinger.cpp
udioFlinger.h
28243dd563fee1c82f0fff6cc27b5cbf21fa2585 26-Jan-2012 Glenn Kasten <gkasten@google.com> Use enum effect_state consistently

Also fix indentation

Change-Id: I393ef9e37ffceed5ad4a78df439726ae1fe139df
udioFlinger.h
b853e986caf43408ad95b9014f194aadff385e3c 26-Jan-2012 Glenn Kasten <gkasten@google.com> Use enum track_state consistently

Change-Id: Ie5ebb7befa092e1de1e4df9c6e2d51e6bcfd176a
udioFlinger.cpp
udioFlinger.h
9365ea9bf2e439b3e71abbabe22ce7382ebc4b3a 25-Jan-2012 Eric Laurent <elaurent@google.com> am 535b0264: am 7eeaf3f0: Merge "AudioFlinger: refine mixer sleep time logic" into ics-mr1

* commit '535b0264a4cfa790e549bd9cd09980788f1375f4':
AudioFlinger: refine mixer sleep time logic
84e19873fde204d73628ba1b5ca9e3f5778574fa 24-Jan-2012 Eric Laurent <elaurent@google.com> am 7eeaf3f0: Merge "AudioFlinger: refine mixer sleep time logic" into ics-mr1

* commit '7eeaf3f07aa6fb10639d9f96c1367eb98c3e8839':
AudioFlinger: refine mixer sleep time logic
7c5aea0a8d9b422999483f96a2566f77ff11abf2 24-Jan-2012 Eric Laurent <elaurent@google.com> am 41773d46: Merge "DO NOT MERGE Revert "Revert "AudioFlinger: mix track only when really ready (2)""" into ics-mr1

* commit '41773d46556aa47d4322ff89fdaf7d1345c2d1f2':
DO NOT MERGE Revert "Revert "AudioFlinger: mix track only when really ready (2)""
21e4b6ed00e814bffc70895847a4944d7a190020 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
udioFlinger.cpp
eaa0b5cc2f7723e9b25298126d0dcb48c56d5dac 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
udioFlinger.cpp
udioFlinger.h
15dfda272eec983508b89fb8bc9ca6f2bb825496 24-Jan-2012 Justin Ho <justinho@google.com> am fee5a860: Merge "DO NOT MERGE Revert "AudioFlinger: mix track only when really ready (2)"" into ics-mr1

* commit 'fee5a860a8355cda071ff23644e943414ba7f65d':
DO NOT MERGE Revert "AudioFlinger: mix track only when really ready (2)"
7baf7894bc2f1a62440f381eeb50143f210a5d61 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
udioFlinger.cpp
udioFlinger.h
335787fe43596f38ea2fa50b24c54d0823a3fb1d 21-Jan-2012 Glenn Kasten <gkasten@google.com> Remove AudioFlinger dependencies on client

Change-Id: Ibb591e41a3ca5d7015e2b66b98b8fef5f415fb37
udioFlinger.cpp
udioFlinger.h
83d86538c4c479a9225c75ab27938e8f05abb9c8 17-Jan-2012 Glenn Kasten <gkasten@google.com> Make AudioTrack control block volume field private

This is part of the process of abstracting the control block
to make it easier to maintain.

Change-Id: Idb8f461e68dab3bcf268159cc0781651c6fb7094
udioFlinger.cpp
58f30210ea540b6ce5aa6a46330cd3499483cb97 12-Jan-2012 Glenn Kasten <gkasten@google.com> Use audio_format_t consistently, continued

Was int or uint32_t.

When AudioFlinger::format can't determine the correct format,
return INVALID rather than DEFAULT.

Init mFormat to INVALID rather than DEFAULT in the constructor.
Subclass constructors will set mFormat to the correct value.

Change-Id: I9b62640aa107d24d2d27925f5563d0d7407d1b73
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
d967f0a099db2b71597a3127134afd4a46287a4a 20-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Remove redundant get()"
7fc9a6fdf146ded90b51c52f4a05d797294dcb85 10-Jan-2012 Glenn Kasten <gkasten@google.com> Remove redundant get()

get() is almost always unnecessary, except in a LOG.
Also no need to check for != 0 before calling get().

Change-Id: Ib06e7a503f86cf102f09acc1ffb2ad085025516d
udioFlinger.cpp
ea3cc3bca949139e401b77f2ac0cce7ac6e76f8f 20-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Remove dead setRingerMode(mode, mask)"
a3db30f7c53936a3acb87d2c44807ee2f0cfa16e 20-Jan-2012 Jean-Baptiste Queru <jbq@google.com> am 9d25b82d: Merge "Rename LOG_ASSERT to ALOG_ASSERT"

* commit '9d25b82d280c2d979d500e7da4447148f32f820b':
Rename LOG_ASSERT to ALOG_ASSERT
d746737921074e2a6c39c52b06022c5166689df5 20-Jan-2012 Jean-Baptiste Queru <jbq@google.com> am 6df477be: Merge "Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF)"

* commit '6df477be186233e36fc370c4d2db6c1ed928a740':
Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF)
daef36f5d4934bd055c694a8d54b86e2b50a6159 20-Jan-2012 Jean-Baptiste Queru <jbq@google.com> am a826f9e2: Merge "Rename (IF_)LOGW(_IF) to (IF_)ALOGW(_IF)"

* commit 'a826f9e2c4f6329d8d48c927f6e942e78ffaf92f':
Rename (IF_)LOGW(_IF) to (IF_)ALOGW(_IF)
3734cbca25c6d902677cfb5e59dff7a1cb17a45d 20-Jan-2012 Jean-Baptiste Queru <jbq@google.com> am 4f367f33: Merge "Rename (IF_)LOGI(_IF) to (IF_)ALOGI(_IF)"

* commit '4f367f3387887c538c81c34cc8becaea6fa5e430':
Rename (IF_)LOGI(_IF) to (IF_)ALOGI(_IF)
e744a90eb52bf9547848c08380cfb7ba7e63ffbc 20-Jan-2012 Jean-Baptiste Queru <jbq@google.com> am ba7f0d2a: Merge "Rename (IF_)LOGD(_IF) to (IF_)ALOGD(_IF)"

* commit 'ba7f0d2a03643ce429421b81febf18fd50473070':
Rename (IF_)LOGD(_IF) to (IF_)ALOGD(_IF)
ca05a87f4c69670a06bdee4b4f98bcdcd838beda 20-Jan-2012 Jean-Baptiste Queru <jbq@google.com> Merge ee4618bc

Change-Id: Ie1dc6ad38e7c30636d80f6caef11cf6673144940
39fd8eb956dea32692d3d72b10b64a8597df0a40 09-Jan-2012 Steve Block <steveblock@google.com> Rename LOG_ASSERT to ALOG_ASSERT

Change-Id: Ie2c7ea6560656d65bad791a61996174c75677517
udioResampler.cpp
udioResamplerCubic.cpp
9a8ded7348c5b2302dd27b285b395416bc842c49 06-Jan-2012 Steve Block <steveblock@google.com> Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF)

Change-Id: I1de629b4632a4b3187ca1a28d6416daccd35f924
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
udioResampler.cpp
aa70226152d2084f85a96b52359dbc8476a86a45 06-Jan-2012 Steve Block <steveblock@google.com> Rename (IF_)LOGW(_IF) to (IF_)ALOGW(_IF)

Change-Id: I8fbdfa7a7581f481968dbb65aa40f7042936d7cb
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
udioResamplerCubic.cpp
53feeb42c721e8fc9285e35e679906a951f3277c 04-Jan-2012 Steve Block <steveblock@google.com> Rename (IF_)LOGI(_IF) to (IF_)ALOGI(_IF)

Change-Id: I26f76452ac49e2890b14d133c065493d8df0fb4a
udioFlinger.cpp
udioPolicyService.cpp
52546c0ef96aa3e7e21482e0f9b6e982557c8da9 20-Dec-2011 Steve Block <steveblock@google.com> Rename (IF_)LOGD(_IF) to (IF_)ALOGD(_IF)

Change-Id: I44f267700356967dc51e8f85ebf457dc85cfb229
udioFlinger.cpp
udioMixer.cpp
udioResampler.cpp
3812256de32e73e38ba16e50ac0451c10223d4eb 20-Oct-2011 Steve Block <steveblock@google.com> Rename (IF_)LOGV(_IF) to (IF_)ALOGV(_IF)

Change-Id: I5321ebd12e9c6248a108529e82c4e1af2a4405e3
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
udioResampler.cpp
aeeb7e219e34d2d657d829913659a4e10e976375 19-Jan-2012 Eric Laurent <elaurent@google.com> resolved conflicts for merge of 05683c85 to master

Change-Id: I7846b7da8c5813b7a9b1f3f71aede0229689ff0d
86905f445c96743b037eed6360afa956a85b019c 19-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Add units to time periods"
ca42b286a162f5cd6a4a916bfe429abe95780730 19-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use const const strings for arrays and pointers to strings"
22ecc912a87099cff8cadc424cd12f85c118673f 09-Jan-2012 Glenn Kasten <gkasten@google.com> Add units to time periods

Change-Id: Ib980e2676cecf5d9b0c2e388da6dc8e370df8abb
udioPolicyService.cpp
8dad0e31c2366c501bd1d600261d0af35a6ca786 09-Jan-2012 Glenn Kasten <gkasten@google.com> Use const const strings for arrays and pointers to strings

Change-Id: I0a073e17ebf6ad59e7edbedac104c6fa4bcaf9c9
udioPolicyService.cpp
udioPolicyService.h
f1d4592d4c3c99ebab55559e164ff102e825283e 14-Jan-2012 Glenn Kasten <gkasten@google.com> For booleans, use ! instead of == false

Change-Id: Ibc115936d2d0b0b7744ebe9b52839ea5b42c4edd
udioFlinger.cpp
udioPolicyService.cpp
0b07b8085d7b837b4dd5f09e0c8c39408f6bdbf7 18-Jan-2012 Glenn Kasten <gkasten@google.com> Remove dead setRingerMode(mode, mask)

Change-Id: Ia4cc8be8424a40b3dcb7ebd0264fdff4e5247f7f
udioPolicyService.cpp
udioPolicyService.h
2774144fa8283f1a7b43e17a53c97dec0c366dd3 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
udioFlinger.cpp
udioFlinger.h
04eaf3e5f20d7faa956c0d672024ffb5117f4c26 18-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Track volume cleanup"
63ad6aacc6ce6b729bf25f41376cfea731a2c1eb 18-Jan-2012 Eric Laurent <elaurent@google.com> Merge "audio framework: manage stream volume per device"
b1cf75c4935001f61057989ee3cf27bbf09ecd9c 17-Jan-2012 Glenn Kasten <gkasten@google.com> Track volume cleanup

Always read and write track volumes atomically. In most places this was
already being done, but there were a couple places where the left and
right channels were read independently.

Changed constant MAX_GAIN_INT to be a uint32_t instead of a float.
It is always used as a uint32_t in comparisons and assignments.
Use MAX_GAIN_INT in more places.

Now that volume is always accessed atomically, removed the union
and alias for uint16_t volume[2], and kept only volumeLR.

Removed volatile as it's meaningless.

In AudioFlinger, clamp the track volumes read from shared memory
before applying master and stream volume.

Change-Id: If65e2b27e5bc3db5bf75540479843041b58433f0
udioFlinger.cpp
83844cc2f95dc279015b47fd1e18c7cb4eabe9a1 19-Nov-2011 Eric Laurent <elaurent@google.com> audio framework: manage stream volume per device

Improve volume management by keeping track of volume for each type
of device independently.
Volume for each stream (MUSIC, RINGTONE, VOICE_CALL...) is now maintained
per device.

The main changes are:
- AudioService now keeps tracks of stream volumes per device:
volume indexes are kept in a HashMap < device , index>.
active device is queried from policy manager when a volume change request
is received
initalization, mute and unmute happen on all device simultaneously
- Settings: suffixes is added to volume keys to store each device
volume independently.
- AudioSystem/AudioPolicyService/AudioPolicyInterface: added a device argument
to setStreamVolumeIndex() and getStreamVolumeIndex() to address each
device independently.
- AudioPolicyManagerBase: keep track of stream volumes for each device
and apply volume according to current device selection.

Change-Id: I61ef1c45caadca04d16363bca4140e0f81901b3f
udioPolicyService.cpp
udioPolicyService.h
ad0f6cc5e115ca167ff122c83451b46d85c590ac 17-Jan-2012 Glenn Kasten <gkasten@google.com> Remove dead setVolume() and mVolume[2]

Change-Id: I94b835434093e920432614eb5007101e87758f32
udioFlinger.cpp
udioFlinger.h
0696400a6bb9abbed62b3b9c6aa105495dc600a2 17-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use audio_mode_t consistently"
263709e7be37c7040aaef385bc5c9389a9b5f514 06-Jan-2012 Glenn Kasten <gkasten@google.com> Check stream type in AudioFlinger::createTrack

A bad parameter to AudioFlinger::createTrack could cause mediaserver to crash.

Other AudioFlinger stream type cleanup:
- Simplify range check for audio_stream_type_t
- Add comment about mStreamTypes array initialization.

Change-Id: Ia33aa1cce0fdd694b08d9288816ffc097a9543d0
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
3944e0326a286bcb931551e61e79c033b10d09d4 17-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Fix locking for mMasterVolume and mMute"
613882293184e575a44bff681a3decaefe889e69 17-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use size_t for frame size"
0107954f72153db747a3727dc1157e9236dfed90 17-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use audio_stream_type_t consistently"
9806710f5d6722cfc5783c7eca3512451a0f2035 13-Dec-2011 Glenn Kasten <gkasten@google.com> Fix locking for mMasterVolume and mMute

mMasterVolume and mMute are both protected by mutex in AudioFlinger class, but
there were two places where they were accessed without a mutex.

Also make AudioFlinger::mMasterMute private not protected.

Change-Id: Ia3897daeb5c50313df5bcc071824357526237f3e
udioFlinger.cpp
udioFlinger.h
05632a5fa4b88ca474294887fc92a9fcdf0e2352 03-Jan-2012 Glenn Kasten <gkasten@google.com> AudioTrack and AudioFlinger send level cleanup

Add an API to control block for getting/setting send level.
This allow us to make the mSendLevel field private.

Document the lack of barriers.

Use 0.0f to initialize floating-point values (for doc only).

Change-Id: I59f83b00adeb89eeee227e7648625d9a835be7a4
udioFlinger.cpp
b9980659501d0428d65d8292f3c32da69d37fbd2 11-Jan-2012 Glenn Kasten <gkasten@google.com> Use size_t for frame size

except in the control block, where we don't have room.

In AudioFlinger::ThreadBase::TrackBase::getBuffer,
read the frame size from control block only once.

Change-Id: Id6c4bccd4ed3e07d91df6bbea43bae45524f9f4e
udioFlinger.cpp
udioFlinger.h
fff6d715a8db0daf08a50634f242c40268de3d49 13-Jan-2012 Glenn Kasten <gkasten@google.com> Use audio_stream_type_t consistently

At native level it was a mixture of audio_stream_type_t, int, uint32_t,
and uint8_t. Java is still int. Also fixed a couple of hard-coded -1
instead of AUDIO_STREAM_DEFAULT, and in startToneCommand a hard-coded 0
instead of AUDIO_STREAM_VOICE_CALL.

Change-Id: Ia33bfd70edca8c2daec9052984b369cd8eee2a83
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
f78aee70d15daf4690de7e7b4983ee68b0d1381d 04-Jan-2012 Glenn Kasten <gkasten@google.com> Use audio_mode_t consistently

It was int or uint32_t.
Also make getMode() const.

Change-Id: Ibe45aadbf413b9158e4dd17f2b3bcc6355288d37
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
e3a067f8bc98134941ee1a4da8c2a92a15aaa9cc 11-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Simplify range check for audio_mode_t"
c40256146bee58bff09e1c16ef99ea06d31f89f9 11-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use correct type for hardware call state"
2ea3410d0d3d592ce30c3ba0ce3e0e63b1244057 11-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use consistent style of & reference for AutoMutex"
9770988e61961d34033fd2c12f0de85a267df68f 11-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "AudioFlinger new can't fail"
02b2d2dddc9be339cf7647d4ead53cecd1c51038 11-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Fix build warning"
930f4caa1e311ef7ff538c421a324396157eb24f 07-Jan-2012 Glenn Kasten <gkasten@google.com> Simplify range check for audio_mode_t

AudioSystem::setMode previously allowed negative modes, but these were
then rejected by AudioFlinger.

Now negative modes (including AUDIO_MODE_INVALID and AUDIO_MODE_CURRENT)
are explicitly disallowed.

Change-Id: I0bac8fea737c8eb1f5b6afbb893e48739f88d745
udioFlinger.cpp
udioPolicyService.cpp
c1dc1cb1d1eaf84e88669f1a5f22579a0d9237c2 09-Jan-2012 Steve Block <steveblock@google.com> Rename LOG_ASSERT to ALOG_ASSERT DO NOT MERGE

See https://android-git.corp.google.com/g/157519

Bug: 5449033
Change-Id: I8ceb2dba1b031a0fd68d15d146960d9ced62bbf3
udioFlinger.cpp
udioResampler.cpp
udioResamplerCubic.cpp
5f29ca38b71506ad7c7cb9925efbddf588e9655b 09-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "By convention const goes before the type specifier"
25b248eb52a0a16adaef6b79c9d92cb88b9a2bc2 04-Jan-2012 Glenn Kasten <gkasten@google.com> Use cached reference to media.player service

This save unnecessary binder calls

Change-Id: I93a60efc54d9c8fb8fab706cd4477bbfd00ffec8
udioFlinger.cpp
879bc64e43d62f2690c77a3282cef2e45d1b76e9 09-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Replace loop by __builtin_ctz"
febdbfec3b1ed0e20aa4f10bfdd82702d3e41f4b 09-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "suspended() and isSuspended() are const"
29357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47 06-Jan-2012 Steve Block <steveblock@google.com> Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE

See https://android-git.corp.google.com/g/#/c/157220

Bug: 5449033
Change-Id: Ic9c19d30693bd56755f55906127cd6bd7126096c
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
udioResampler.cpp
4a6f02833d8421b7d9b20f89729d8bb03b8b8102 07-Jan-2012 Glenn Kasten <gkasten@google.com> AudioFlinger new can't fail

Change-Id: I7dae05a5ea1c962a9975386eab1fedbbe106ffba
udioFlinger.cpp
a7d8d6fc5e102a08b262a1b78aa1abeeb097d9e4 06-Jan-2012 Glenn Kasten <gkasten@google.com> Use consistent style of & reference for AutoMutex

AutoMutex, which is a typedef for Mutex::Autolock, is overloaded for
either a reference (&) or pointer (*) parameter, but we prefer to use
the reference form when the mutex is known at compile time.

Change-Id: I3515e6d6ab7959b2356a27fa3b04fd49e42cb31e
udioFlinger.cpp
a4454b4765c5905f14186893b0688be375642283 04-Jan-2012 Glenn Kasten <gkasten@google.com> Use correct type for hardware call state

Change-Id: Ic6d98b129e3ec653df1d8f7e829adf8dccb4f378
udioFlinger.cpp
udioFlinger.h
54c3b66444ebfb9f2265ee70ac3b76ccefa0506a 06-Jan-2012 Glenn Kasten <gkasten@google.com> By convention const goes before the type specifier

Change-Id: I70203abd6a6f54e5bd9f1412800cc01212157e58
udioFlinger.h
udioMixer.cpp
udioMixer.h
udioResamplerSinc.cpp
udioResamplerSinc.h
f9a27779634ce3a01e5957f234cd04eba74fa07f 06-Jan-2012 Glenn Kasten <gkasten@google.com> Fix build warning

Change-Id: Ic99608d0c14ed56c02f036e0bbaaae1b16bab8ba
udioMixer.cpp
5ff1dd576bb93c45b44088a51544a18fc43ebf58 06-Jan-2012 Steve Block <steveblock@google.com> Rename (IF_)LOGW(_IF) to (IF_)ALOGW(_IF) DO NOT MERGE

See https://android-git.corp.google.com/g/157065

Bug: 5449033
Change-Id: I00a4b904f9449e6f93b7fd35eac28640d7929e69
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
udioResamplerCubic.cpp
98dd542ffcd3424b1da58bd273c0c1ff5b8c8960 15-Dec-2011 Glenn Kasten <gkasten@google.com> Replace loop by __builtin_ctz

Using the builtin is faster on some platforms, for example on ARM it's
19 instructions instead of 13, and is O(1) instead of O(n). Of course,
track creation is an inherently slow operation, so this doesn't matter
much now. But if we add support for virtual tracks, then physical tracks
will be allocated/freed more frequently. Also just on principle ...

Change-Id: I3f590934092bd7a1869cbedbc7357928aa5cc8ff
udioMixer.cpp
8a08dcc0a5de19a904e77d5f31bed3dff9a59890 05-Jan-2012 Steve Block <steveblock@google.com> Merge "Rename (IF_)LOGI(_IF) to (IF_)ALOGI(_IF) DO NOT MERGE"
a3a854868a80fd9b9b8720e06a172754943f9417 04-Jan-2012 Glenn Kasten <gkasten@google.com> suspended() and isSuspended() are const

Change-Id: I04b95970b5a645b64e7e64fffd46d868354dda66
udioFlinger.cpp
udioFlinger.h
88592eccaf6afcddd5f985955be92fe25205c680 05-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Remove the notion of "active track" from mixer"
a2a0a5d7d56baa831870f4bf2a0d942a477d92ef 05-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use the standard CC_LIKELY and CC_UNLIKELY macros"
f6b1678f8f508b447155a81b44e214475ab634a8 15-Dec-2011 Glenn Kasten <gkasten@google.com> Use the standard CC_LIKELY and CC_UNLIKELY macros

Several source files privately defined macros LIKELY and UNLIKELY in terms
of __builtin_expect. But <cutils/compiler.h> already has CC_LIKELY and
CC_UNLIKELY which are intended for this purpose. So rename the private
uses to use the standard names.

In addition, AudioFlinger was relying on the macro expanding to extra ( ).

Change-Id: I2494e087a0c0cac0ac998335f5e9c8ad02955873
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
7ab41c9f773ba599646f1b0d00955c1be80f92fd 05-Jan-2012 Eric Laurent <elaurent@google.com> resolved conflicts for merge of 1a4b9939 to master

Change-Id: I0c910d391a38a916d8431f7d1f5b82e39e1a66c2
df64d15042bbd5e0e4933ac49bf3c177dd94752c 04-Jan-2012 Steve Block <steveblock@google.com> Rename (IF_)LOGI(_IF) to (IF_)ALOGI(_IF) DO NOT MERGE

See https://android-git.corp.google.com/g/156801

Bug: 5449033
Change-Id: Ib08fe86d23db91ee153e9f91a99a35c42b9208ea
udioFlinger.cpp
udioPolicyService.cpp
b8a805261bf0282e992d3608035e47d05a898710 20-Dec-2011 Steve Block <steveblock@google.com> Rename (IF_)LOGD(_IF) to (IF_)ALOGD(_IF) DO NOT MERGE

See https://android-git.corp.google.com/g/156016

Bug: 5449033
Change-Id: I4c4e33bb9df3e39e11cd985e193e6fbab4635298
udioFlinger.cpp
udioMixer.cpp
udioResampler.cpp
071ccd5a9702500f3f7d62ef881300914926184d 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
udioFlinger.cpp
udioMixer.cpp
udioMixer.h
udioResampler.h
9c56d4ae6212c21ce5fd71ed534eb195983a07c1 20-Dec-2011 Glenn Kasten <gkasten@google.com> Remove the notion of "active track" from mixer

This is a first step towards making the mixer more object-oriented.

Change-Id: Ifd445d0e471023a7f5c82e934736ffc95ba1b05b
udioFlinger.cpp
udioMixer.cpp
udioMixer.h
12d9702773c8a3242a44dd6528126c9ff0dade43 20-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Remove dead code"
bbaf8673f1d1dd79d1b7f474ca7111da58e84aff 20-Dec-2011 Eric Laurent <elaurent@google.com> Merge "audio effects: rename configure command"
3d5188bd6abe55898f10a0edf3c05aff8aa2ef67 17-Dec-2011 Eric Laurent <elaurent@google.com> audio effects: rename configure command

Renamed audio effect library interface command for audio format
configuration from EFFECT_CMD_CONFIGURE to EFFECT_CMD_SET_CONFIG.
This makes the naming more consistent with other exixsting commands
and allow adding a new command to get the configuration (EFFECT_CMD_GET_CONFIG).
Same change for reverse channel configuration renamed from
EFFECT_CMD_CONFIGURE_REVERSE to EFFECT_CMD_SET_CONFIG_REVERSE.

Implemented EFFECT_CMD_GET_CONFIG in exisitng effect libraries.

Change-Id: Ia7b1c620f13797fe5aceb3b0b4acbacce09fb067
udioFlinger.cpp
81a028fef62bcadf13fc8550067a3d29c918b3ca 15-Dec-2011 Glenn Kasten <gkasten@google.com> Remove dead code

Change-Id: Icf23f7f90fdeb660f4015f22cf239e6d05f5d03c
udioMixer.cpp
udioMixer.h
f602a5f7f29e694a7da4c143737b74501c00477d 17-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Use constants for 2 and 32"
d1e672acd8fa1af899f85ee2321327237028adf8 17-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Extract out audio DSP code to utility library"
bf71f1e7948406492376c6cbd5e6a30c8cb670e4 13-Dec-2011 Glenn Kasten <gkasten@google.com> Use constants for 2 and 32

Change-Id: If820dfd58b6df258570750610a07af99598d9e53
udioMixer.cpp
udioMixer.h
b92bc47a05925c29efef0d66711b6d3f17f406e7 16-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Use switch in AudioMixer::setParameter"
788040c5189bbdaf567ce4b29ffd1db08ea1020c 05-May-2011 Glenn Kasten <gkasten@google.com> Use switch in AudioMixer::setParameter

Replace series of if/then/elses by easier-to-read switch. Also return
void instead of status_t, since callers weren't checking it. Assert on
bad input parameters.

Change-Id: Ie1f0a297977b28501d20e1af819afed9b4750616
udioMixer.cpp
udioMixer.h
237a624f674800d2300806b115eee8c9bb7db033 16-Dec-2011 Glenn Kasten <gkasten@google.com> deleteTrackName now asserts on bad input parameter

This is safe, as the input parameter is always track->name(),
which must be valid.

Change-Id: Iea8ea3a5706c27026335526ba8851030d00681f8
udioMixer.cpp
3b21c50ef95fe4e7ac3426ca14b365749e66ff08 15-Dec-2011 Glenn Kasten <gkasten@google.com> Extract out audio DSP code to utility library

Change-Id: Ib8ce72028a7ea30e82baa518e381370e820ebbd0
ndroid.mk
udioFlinger.cpp
udioMixer.cpp
udioMixer.h
6d4bf6eda04888144ec59cba4816a2cbb79b9e5c 16-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "setActiveTrack and setBufferProvider can't fail"
b87c068727a15a3d3f0bfdcb758c76a097f5e869 16-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Simplify enable/disable mixing"
079123ee3d2e20bbc17a7ddbd96ca46bed27898f 16-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Improve resistance to leaks for ConfigEvent"
26fa039c3752eaaf74d1be53d9795f48e9f43de3 16-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Use NULL not 0 for pointers"
fba380a0b2c62684ce4272a05165965bae29d6a1 16-Dec-2011 Glenn Kasten <gkasten@google.com> setActiveTrack and setBufferProvider can't fail

Return void, not status_t, from setActiveTrack and setBufferProvider.

These methods returned status_t, but the callers never checked the
return value. Since these aren't externally visible APIs, they now
return void, and assert on bad input parameters.

Change-Id: I530ed29484596ae41e8659826ca425149c51c2a1
udioMixer.cpp
udioMixer.h
1c48c3c61970527b97892ab6a2daae8eaac26964 15-Dec-2011 Glenn Kasten <gkasten@google.com> Simplify enable/disable mixing

The MIXING enum isn't needed, and now returns void instead of status_t.

Change-Id: Ibe4ec24081d75ad4ab78b9c7191fc9077959c4e9
udioFlinger.cpp
udioMixer.cpp
udioMixer.h
f3990f2cc8fd824ae52a880a7b22248e1bdfb192 13-Dec-2011 Glenn Kasten <gkasten@google.com> Improve resistance to leaks for ConfigEvent

A Vector of pointers is risky, as there is no ownership (and the
ThreadBase destructor was not deleting them, so if there were any left
over at end it would leak). Replaced by a Vector of values.

Change-Id: Iddde72dc30134adfcf724dec26cbe0a742509b8c
udioFlinger.cpp
udioFlinger.h
e0feee3da22beeffbd9357540e265f13b2119cbb 13-Dec-2011 Glenn Kasten <gkasten@google.com> Use NULL not 0 for pointers

Change-Id: Iab3f9abbdab617dc5a599e657ec46a0b0a002eef
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
42968939dfce0954d6540011199045ec4ed7de80 15-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Fix indentation and whitespace"
a06a9a50b37d60e9c43c9de9f8ea3a8649cd5691 15-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Improve AudioFlinger error logging"
53a166cabc956529d2336b04c26b9c03b550ab38 15-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "AudioMixer uninitialized simple fields"
0cfd8231e4c489392809bf44c174315df2690145 13-Dec-2011 Glenn Kasten <gkasten@google.com> AudioMixer uninitialized simple fields

Change-Id: I47e3849f048d4d990c9634f9c8a2ca2de0339e93
udioMixer.cpp
d879601ace079e3c0aed79cf3fa5fb4db6ad4a9f 28-Oct-2011 Glenn Kasten <gkasten@google.com> Improve AudioFlinger error logging

Change-Id: I8ce9aff4038cd7fa0067600faa8080b137db1939
udioFlinger.cpp
2eda60a8485cfe70a60e72156beffdc470ecb093 15-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Audio C++ comments"
c5ac4cb3a5124860ccfc7e4ff66251c55a5595ca 12-Dec-2011 Glenn Kasten <gkasten@google.com> Fix indentation and whitespace

Use git diff -w to verify.

Change-Id: Ib65be0a1ecf65d6cad516110604e3855bf68a638
udioFlinger.cpp
udioMixer.cpp
c23bd9b5b9e4be9c395789810fdd8522296fc50c 15-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Use const char correctly in AudioFlinger"
e5dfcd8c6792c4b64120fd03708729b70a887f2a 15-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Use units after all times"
b299dc4ded29a226daac07f195d1558e660d2f9f 15-Dec-2011 Glenn Kasten <gkasten@google.com> Merge "Remove redundant clear()"
362c4e697d8e9c034e964ac7b40227e054491547 14-Dec-2011 Glenn Kasten <gkasten@google.com> Audio C++ comments

Change-Id: I84906ebb9dfcfa5b96b287d18364b407f02a30c1
udioFlinger.cpp
udioMixer.h
d1d8f23dde239289ba8c0de0944baaca3586c880 08-Jul-2011 Glenn Kasten <gkasten@google.com> Fix includes

Remove unused #include dlfcn.h

Add #include String8.h
Forward class declaration is only for references and pointers.
In this case, we need the full class declaration,
and were incorrectly depending on another header file to do it.

Change-Id: Iff65cceb3982698cc1ebaeec405695fc190c03ff
udioPolicyService.cpp
udioPolicyService.h
91eb8bfbe253a6b6fe1aa23fb884a601c28991c4 13-Dec-2011 Glenn Kasten <gkasten@google.com> Remove redundant clear()

Change-Id: Ie5e4e63cbc8fa85ef50451dddf8f149fa864b132
udioFlinger.cpp
ec1d6b5e17281a066d618f7fcd2b63b3ce11f421 12-Dec-2011 Glenn Kasten <gkasten@google.com> Use const char correctly in AudioFlinger

Use const char [] instead of const char * to eliminate unnecessary pointer.
Make the array audio_interfaces also const, in addition to the strings.

Change-Id: I31f33d1dcb9a657ee136f4280fd2d46492496831
udioFlinger.cpp
7dede876998ff56351d495ec3a798c1b131193e8 13-Dec-2011 Glenn Kasten <gkasten@google.com> Use units after all times

Change-Id: I48d3f29c37228b5d03189e4c9600824c9360cac9
udioFlinger.cpp
2013d4d159bfc29b4143d3b5fd4735f51a03684c 06-Dec-2011 Eric Laurent <elaurent@google.com> am 5433e25f: am 7b6aff23: Merge "audioflinger: fix audio skipping over A2DP" into ics-mr1

* commit '5433e25f6ce013860ff2a074ad8d1158cc39ab91':
audioflinger: fix audio skipping over A2DP
162b40bbaf3c3a24f61a6636bef6f80a9c0a31dd 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
udioFlinger.cpp
udioFlinger.h
926798f8c21ab002d9797ef8973852a2612c1f75 23-Nov-2011 Eric Laurent <elaurent@google.com> am f6422f5f: am 20398fac: Merge "audioflinger: reduce sleep time to avoid underrun" into ics-mr1

* commit 'f6422f5f5d04aab47f8f36a0ea92e2140bed0105':
audioflinger: reduce sleep time to avoid underrun
7cafbb32999049873d4746ba83bd20c88abe6ce6 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
udioFlinger.cpp
c23e2f2464eb3748599d47af7d8986b856f3c179 17-Nov-2011 Glenn Kasten <gkasten@google.com> Bug 5522189 re-enable ARM opts but disable inline

PIE did not work together with inlining. This change combines (almost
all of) the performance benefits of ARM optimizations together with PIE.

Change-Id: I4594d33ae5a0a7bac327ae08e30fb35343a06256
udioResampler.cpp
c4795ecad4e5a0b3ec54862a40c82ef1ba53cd59 14-Nov-2011 Eric Laurent <elaurent@google.com> am 25924f8f: am 030bb998: Merge "audioflinger: fix noise when skipping to next song" into ics-mr1

* commit '25924f8f6c0a4ca4a2eb257b72d9625f69d2525e':
audioflinger: fix noise when skipping to next song
544fe9b6e9325701df4ab8c1d29774fc13c4cf6c 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
udioFlinger.cpp
udioFlinger.h
6977ca7d5ffdbc1610a95c74653b1fbe6a665f32 10-Nov-2011 Eric Laurent <elaurent@google.com> am db7d79e6: am 2b7f91b9: Merge "Fix regression for SoundPool playback" into ics-mr1

* commit 'db7d79e6f1e1860a9bfe4756a03c753435fd0ddf':
Fix regression for SoundPool playback
a47b69c6f7c6fe0044ebcb2d0790ce3548de56fd 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
udioFlinger.cpp
3b86c964df855a9740c446e984309b719c3ec37c 08-Nov-2011 Eric Laurent <elaurent@google.com> am f3a892ab: Merge "AudioFlinger: mix track only when really ready" into ics-mr1

* commit 'f3a892ab9347ce733b81ccb4913a91c586f8f367':
AudioFlinger: mix track only when really ready
3dbe3201479828e84abe02e1fdd0a5d414c0ddb8 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
udioFlinger.cpp
305f4b6dabe500b97062e72049a296d0699243d7 28-Oct-2011 Glenn Kasten <gkasten@google.com> Bug 5522189 temporary workaround

Change-Id: I21d91d7a24df7bb6e7fc3d0fbc4786d55391fc0e
udioResampler.cpp
3856b090cd04ba5dd4a59a12430ed724d5995909 20-Oct-2011 Steve Block <steveblock@google.com> Rename (IF_)LOGV(_IF) to (IF_)ALOGV(_IF) DO NOT MERGE

See https://android-git.corp.google.com/g/#/c/143865

Bug: 5449033
Change-Id: I0122812ed6ff6f5b59fe4a43ab8bff0577adde0a
udioFlinger.cpp
udioMixer.cpp
udioPolicyService.cpp
udioResampler.cpp
a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3 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
udioFlinger.cpp
udioFlinger.h
5c4e818c39ac2d2739675fe907904a874f7623c5 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
udioFlinger.cpp
ec35a1416472865dbebc22b10199ad718ed2cc95 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
udioFlinger.cpp
udioFlinger.h
9d18ec574f5d847a86a21594ac39394ef5b108fc 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
udioFlinger.cpp
6bffdb8b598a2399e57f6ca48660fb7bdb2490b5 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
udioFlinger.cpp
eb8b914ad9d4331e1cdf4346731770ce69fd0e77 16-Sep-2011 Nick Kralevich <nnk@google.com> AudioResampler: use relative instead of absolute labels

This change is needed to allow Android to compile with -fPIE
Bug: 5328392

Change-Id: I84d947975776800a7b79c6ac75a881af461a631c
udioResampler.cpp
60cd0a0d488e604d27fc7dbb02b00348693dfde2 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
udioFlinger.cpp
b76e90de3c64626fe07a68469d0a59a31c8efb6b 30-Aug-2011 Eric Laurent <elaurent@google.com> Merge "226483: A2DP connected, but music out to speaker"
9f6530f53ae9eda43f4e7c1cb30d2379db00aa00 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
udioFlinger.cpp
udioFlinger.h
bee5337da7659b3b7128622ba1f42618b11df5be 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
udioFlinger.cpp
udioFlinger.h
a1884f9e9ec3836683efd7eb333ee442e8bc9d56 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
udioFlinger.cpp
a5cc7cce9b8aee73b08f6532710e186c02fdd1c0 03-Aug-2011 Eric Laurent <elaurent@google.com> Issue 5081351: isWiredHeadsetOn() permission.

AudioManager.isWiredHeadsetOn() should not require permission MODIFY_AUDIO_SETTINGS.
Remove permission checks on all getters in audio policy manager as permission enforcement
is really usefull for setters.
Also deprecate AudioManager.isWiredHeadsetOn() which name and implementation are deceptive.

Change-Id: I38f8df7c26c0d417bf0e2b74e4c11c2d143f2ecd
udioPolicyService.cpp
0270b188aa3929cc512ec6869caba1d6b60cc08c 12-Aug-2011 Marco Nelissen <marcone@google.com> Don't remove effects on session 0

b/5159902
Change-Id: Id6f29fb1c687069f7480dd81d4745a558f202226
udioFlinger.cpp
db7c079f284f6e91266f6653ae0ec198b1c5006e 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
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
3a34befc6fb04a4945a849e8bda8b84e4bf973fe 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
udioFlinger.cpp
udioFlinger.h
c3e6572e0ff535932b1f6ffb7bcf5acd891675fb 08-Aug-2011 Eric Laurent <elaurent@google.com> Merge "AudioFlinger: protect input/output stream access"
b8ba0a979067a4efb0b3819bf17770793e41c15e 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
udioFlinger.cpp
udioFlinger.h
59bd0da8373af0e5159b799495fda51e03120ea4 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
udioFlinger.cpp
udioFlinger.h
59255e4fc7d8ff52874b85b1988dc0785140cf81 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
udioFlinger.cpp
udioFlinger.h
6dbe883644940badc684957cfc381bfd115f205e 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
udioFlinger.cpp
a7280a59259018d997896c043fd2db95f631f12e 27-Jul-2011 Eric Laurent <elaurent@google.com> Merge "AudioFlinger: fix crash when deleting pre process."
ec437d8d3db79459d7b19e1734e6fe309bd621e8 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
udioFlinger.cpp
udioFlinger.h
feb0db689c17dced50afaee54c659f1676e2d505 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
ndroid.mk
udioFlinger.cpp
udioFlinger.h
57dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfc 24-Jul-2011 Eric Laurent <elaurent@google.com> Added APIs for audio preprocessing

Added APIs to control pre processes applied on captured audio.
Those APIs are still hidden until reviewed by API council.

Three types of standard pre processes are supported:
- Automatic Gain Control (AGC) by AutomaticGainControl class
- Acoustic Echo Cancellation (AEC) by AcousticEchoCanceler class
- Noise Suppression (NS) by NoiseSuppressor class

A method is added to AudioEffect class to query audio pre processings
applied by default by the platform on a given AudioRecord session ID.

Change-Id: I0b9fceeb8c704dd06319c3b52b85c96fe871d51d
udioPolicyService.cpp
udioPolicyService.h
1d2bff0e588afe183a1baaae731519b4e957bbdb 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
udioFlinger.cpp
udioFlinger.h
edc15ad8fcde12dc4f642d80d077239b1532eeca 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
udioFlinger.cpp
7c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745 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
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
e0b5bb23f0a26d248275d203885b820659da7320 16-Jul-2011 Glenn Kasten <gkasten@google.com> Merge "Log CPU usage"
4d8d0c30abfa4b8d75866d42094cc797e05068fa 09-Jul-2011 Glenn Kasten <gkasten@google.com> Log CPU usage

Change-Id: Ie447e59be139153e526b7ad467c46c659d26816f
ndroid.mk
udioFlinger.cpp
81eedd1746be590d5d506dfb9ff23619f9d9898f 13-Jul-2011 Mike Lockwood <lockwood@android.com> Remove some #ifdef HAVE_ANDROID_OS that were needed for the simulator build

Change-Id: I13d9f251f86c05ae5405f37adbf6b8e9660935ba
Signed-off-by: Mike Lockwood <lockwood@android.com>
udioPolicyService.cpp
5e0067b486c3862316aa1f293cf9690c0cf54bda 12-Jul-2011 Jeff Brown <jeffbrown@google.com> Remove the simulator target from all makefiles.
Bug: 5010576

Change-Id: I04d722f258951a3078fe07899f5bbe8aac02a8e8
ndroid.mk
6c21234e3d254fc58227cd2063500a0dcd173689 08-Jul-2011 Glenn Kasten <gkasten@google.com> Merge "Fix build warning; LOG_TAG was misplaced"
5159c7ec97b575c0486159f0543d2da90c3c3b68 08-Jul-2011 Glenn Kasten <gkasten@google.com> Fix build warning; LOG_TAG was misplaced

Change-Id: I4fb0590f626445188f9053367707878b2fa0fa30
udioResamplerCubic.cpp
6d8b694d999e9be7d5dcc336535832a80fb6f61f 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
ndroid.mk
udioFlinger.cpp
671a636931295d9c33ffca74551a804479d01241 17-Jun-2011 Eric Laurent <elaurent@google.com> Added audio_bytes_per_sample() helper function

Change-Id: Ibfcd75c4c241a53d5f052c25ada091904991048a
udioFlinger.cpp
7394a4f358fa9908a9f0a7c954b65c399f4268e6 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>
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
0512ab559d4670c2204078470d7ef5d376811c57 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
udioFlinger.cpp
udioPolicyService.cpp
0d255b2d9061ba31f13ada3fc0f7e51916407176 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
udioFlinger.cpp
udioFlinger.h
udioMixer.cpp
udioMixer.h
65580f9adf6c4d98449ad0716488f9fe3869aa5a 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
udioFlinger.cpp
udioFlinger.h
e1315cf0b63b4c14a77046519e6b01f6f60d74b0 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
udioFlinger.cpp
udioFlinger.h
162f7d15ac5c8c23d1c3de171239f3a4e6e06b2a 23-May-2011 Glenn Kasten <gkasten@google.com> Merge "HAVE_ANDROID_OS AUDIOFLINGER_SECURITY_ENABLED dead"
6708b9a3fb654f5623ba5a696288fdba310a5e1a 13-May-2011 Eric Laurent <elaurent@google.com> Merge "Fix audio effect framework issues"
b469b9490b3cd9e0f0466d9b9ab228f6c793b82e 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
udioFlinger.cpp
udioFlinger.h
64760240f931714858a59c1579f07264d7182ba2 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>
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
249c6a61f21bc90e25e4b77f18c98af1ac363e69 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
udioFlinger.cpp
5a61d2f277af3098fc10b2881babca16391362da 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>
udioFlinger.cpp
udioFlinger.h
799a70e7028a4d714436c3a744a775acfbd31aae 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>
udioFlinger.cpp
udioFlinger.h
fce7a473248381cc83a01855f92581077d3c9ee2 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>
ndroid.mk
udioFlinger.cpp
udioFlinger.h
udioPolicyService.cpp
udioPolicyService.h
6b80e0be94d3f92ec4aa2b7cace816780d3f338d 20-Apr-2011 Dima Zavin <dima@android.com> audioflinger: move legacy audio hw/policy out to libhardware_legacy

Change-Id: I4adcec73d3c08bcbe15bb19e1ba2ff18b195af45
Signed-off-by: Dima Zavin <dima@android.com>
2dpAudioInterface.cpp
2dpAudioInterface.h
ndroid.mk
udioDumpInterface.cpp
udioDumpInterface.h
udioHardwareGeneric.cpp
udioHardwareGeneric.h
udioHardwareInterface.cpp
udioHardwareStub.cpp
udioHardwareStub.h
udioPolicyManagerBase.cpp
dab0bea38ab2c2d6b52907b7f5684834c4979251 26-Apr-2011 Eric Laurent <elaurent@google.com> am 48dca4de: am 969357e3: am 223995dc: Fix issue 4335692: HDMI media volume

* commit '48dca4de70890d324b5830a58bb9fa273164151a':
Fix issue 4335692: HDMI media volume
5bfdfd1e7b4514c6f6143b6b97ef37013f6e53a9 26-Apr-2011 Eric Laurent <elaurent@google.com> am 969357e3: am 223995dc: Fix issue 4335692: HDMI media volume

* commit '969357e31c93e168e7a4cb3b41c33a6ec26f4a26':
Fix issue 4335692: HDMI media volume
023eeac54c428d78b755fa3c856f20d17abb8a40 25-Apr-2011 Eric Laurent <elaurent@google.com> Fix issue 4335692: HDMI media volume

Forced music stream volume to max when not muted and output device is HDMI.

Change-Id: Ibd287cea8ae1d3f36fea6651a113bd5cf2dbad13
udioPolicyManagerBase.cpp
5820e52f9bf3c40839d33457975b6c9629ab1c79 12-Apr-2011 Brad Fitzpatrick <bradfitz@android.com> am 07c25b65: am 4430670f: am ca7ad44a: Merge "audioflinger: Enable ARMv5TE optimized resampler"

* commit '07c25b651216daac884bd503c02b788418165b50':
audioflinger: Enable ARMv5TE optimized resampler
4d0243980123378e9dd69022bf4ddca729d84126 12-Apr-2011 Brad Fitzpatrick <bradfitz@android.com> am 4430670f: am ca7ad44a: Merge "audioflinger: Enable ARMv5TE optimized resampler"

* commit '4430670f48f75661293371dab8db55865f5f56e0':
audioflinger: Enable ARMv5TE optimized resampler
0c0a1c0c37dbd2646a732da706d6777283c83e44 06-Apr-2011 Jim Huang <jim.huang@linaro.org> audioflinger: Enable ARMv5TE optimized resampler

Previously, the optimized asm option is only enabled when
__ARM_ARCH_5E__ is defined, which is assigned in armv5te.mk
rather than armv7-a series targets. This patch checks the ARM CPU
feature about half-word multiply instructions to enable ARMv5TE
resampler optimization routines properly.

Change-Id: I4c5a5d8c932416f23bedb0b389db958349f21ea4
udioResampler.cpp
c30268b9d118309a0514bcf280a03ee69f81403f 06-Apr-2011 Glenn Kasten <gkasten@google.com> Merge "Miscellaneous code cleanup in audio framework"
4bcae82f9b07d1a39956c45a6f5bec0b696c4dd1 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
udioFlinger.cpp
udioPolicyManagerBase.cpp
38ccae2c0324daa305f3fe77d25fdf5edec0b0e1 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
udioFlinger.cpp
33797ea64d067dfeaacbfd7ebe7f3383b73961b5 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
udioFlinger.cpp
ce80563f6fb49b0c40281f9a527e288799b4a577 15-Mar-2011 Eric Laurent <elaurent@google.com> Improvement for issue 3489986: BT SCO volume

This change makes sure that the VOICE_CALL stream volume tracks
the BLUETOOTH_SCO stream volume when SCO audio is enabled.
The down link audio volume now reflects what is being displayed
when pressing volume hard keys on the device while in a video chat
with a BT SCO headset.

Volume settings on the headset and the device are still independent as
we do not support handsfree profile yet.

Change-Id: Ie0d2714730ea359b9318b9cbe6f0b2557ef0f976
udioPolicyManagerBase.cpp
4f46fed004b76d462ef859aa94a3c056b0e79b60 03-Mar-2011 Gloria Wang <gwang@google.com> Merge "- 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()"
9ee159b79022b2e1a050acb3890ce948e99e9ccb 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
udioFlinger.cpp
1c4967155109ab083a4149347596f7ebd3662a67 03-Mar-2011 Eric Laurent <elaurent@google.com> Merge "Fix issue 3388775."
c0bff9b96152179650dc9508799a38e35ef2a321 01-Mar-2011 Eric Laurent <elaurent@google.com> Merge "Fix issue 3479042."
532492cd60a3ee2613cd3d664c9f4581d9929bc5 01-Mar-2011 Eric Laurent <elaurent@google.com> Fix issue 3388775.

Do not select A2DP output for media strategy when it is suspended because
BT SCO is active. Media audio will be routed to speakers or SCO HS
(depending on phone state and activity on stream VOICE_CALL) which is less
confusing than not hearing anything while music progress bar is moving.

Change-Id: Iff8cc1ea9bf9bde0b33035c4d91398db0934b836
udioPolicyManagerBase.cpp
243f5f91755c01614a8cafe90b0806396e22d553 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
udioFlinger.cpp
udioMixer.cpp
udioMixer.h
udioResampler.cpp
udioResampler.h
043b22dbe3b98a8fdd6b0ea77df4089ff44b6539 28-Feb-2011 Jean-Michel Trivi <jmtrivi@google.com> Fix bug 3376700 Volume too loud at lowest setting

Change volume attenuation curve to provide more attenuation at
low volume settings, and finer steps at high volume.
See bug entry for link to doc with curve values.

Change-Id: I750548b2161a4c550ef982ba793156e4518119e8
udioPolicyManagerBase.cpp
586b21780680c4d19723b5a9484e55ec47464c5f 11-Feb-2011 Eric Laurent <elaurent@google.com> Fix issue 3400751.

Add a delay before restoring output path when a notification ends so that
short sounds can be heard on proper device before the path is actualy switched.

Change-Id: I1d2dd8e7e28e15fbcab344256f88499b26297372
udioPolicyManagerBase.cpp
727a6f859841a1d421b680f56d4d4ca5ff8c6e4b 11-Feb-2011 Eric Laurent <elaurent@google.com> Merge "Fix issue 3425342."
12932bfdc7163e654d5ef25f1cb1802ded2704f1 11-Feb-2011 Eric Laurent <elaurent@google.com> Fix issue 3425342.

Change the device selection order as follows to enable easier use of
A2DP while the device is docked:
1 - wired Headset
2 - A2DP Headset
3 - SPDIF/HDMI
4 - Dock

Also do not limit notifications volume when on dock.

Change-Id: I55ea6bea9f2d9ff284b54023e541b2788d0f1eb8
udioPolicyManagerBase.cpp
6b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3 04-Feb-2011 Glenn Kasten <gkasten@google.com> Bug 3352047 Wrong message when adjusting volume

Add hidden AudioManager.getDevicesForStream and output device codes.

Change-Id: I4d1c1d3b6a077cd117720817d1f733dda557b947
udioPolicyManagerBase.cpp
udioPolicyService.cpp
udioPolicyService.h
8473bb556421ac08f4e03abd5d149852114c9238 07-Feb-2011 Brad Fitzpatrick <bradfitz@android.com> am be806fe8: am cc8f87e9: am f664d6f9: am b083d3b8: Merge "Initialize resampling buffer per track."

* commit 'be806fe8c1c7bb3ae70ae27dce41d672410af26a':
Initialize resampling buffer per track.
802da7bc462f6f9df6e681cc75c51dc0a056a4a1 04-Feb-2011 Glenn Kasten <gkasten@google.com> Merge "Bug 3366668 Use BinderService template"
e08d819989d394ed171ba6f1e6d0fa14c29fc42d 04-Feb-2011 Brad Fitzpatrick <bradfitz@android.com> am cc8f87e9: am f664d6f9: am b083d3b8: Merge "Initialize resampling buffer per track."

* commit 'cc8f87e9410dd4de9a2fda4738429e6c6087c789':
Initialize resampling buffer per track.
e26308ad434c575b2985ac442d2990bb1bc19f5d 04-Feb-2011 Brad Fitzpatrick <bradfitz@android.com> am b083d3b8: Merge "Initialize resampling buffer per track."

* commit 'b083d3b816378ef3b9dceb33b2c2e20510b2632b':
Initialize resampling buffer per track.
2151d7b8c2dd77c9887691db30396937be778141 04-Feb-2011 Yuuhi Yamaguchi <yuuhi.x.yamaguchi@sonyericsson.com> Initialize resampling buffer per track.

When resampling too short sound, AudioMixer uses previous
tracks buffer. So we re-initialize the temporary buffer per
loop to avoid it.

Change-Id: I55a59a3b14faa8445e09c450478fe79cef704760
udioMixer.cpp
117cd9286424888c1c5bf202ebf1e08ae1e6affe 04-Feb-2011 Glenn Kasten <gkasten@google.com> Merge "Bug 3366885 Remove LVMX switch"
8782cb4dc783cdcac8498148ab1894b4780c18df 04-Feb-2011 Eric Laurent <elaurent@google.com> am 6f1bd261: am 9c0a1003: Merge "Fix issue 3371080" into honeycomb

* commit '6f1bd261b7fd86ac7817ca061dfb55b95150b836':
Fix issue 3371080
db130fbd3ccd37e247e49494a84f8a9841ecd593 04-Feb-2011 Glenn Kasten <gkasten@google.com> Bug 3366885 Remove LVMX switch

Change-Id: I0bf98c6f85f00b3296874571e1c049dcc4e2fcca
ndroid.mk
udioFlinger.cpp
udioFlinger.h
d2dcb08808aed82218b258726fa66f8e095a3f9c 04-Feb-2011 Glenn Kasten <gkasten@google.com> Bug 3366668 Use BinderService template

Change-Id: I93d7f3fc9dc9b6a365723d8a51a73a5aabdb4f93
udioPolicyService.cpp
udioPolicyService.h
eda6c364c253ba97ee45a3adeb8c2b45db1f81db 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
udioFlinger.cpp
udioFlinger.h
udioPolicyManagerBase.cpp
udioPolicyService.cpp
udioPolicyService.h
2a30be33a39b07bf4f945d9506ffda0fd076e6c2 29-Jan-2011 Jean-Baptiste Queru <jbq@google.com> Merge 0ef57993 from gingerbread

Change-Id: If10fee1ae387a8130356dd62fe678495402d5edf
144f78906f1eefaf8cbde9298a1422fcea094447 29-Jan-2011 Jean-Baptiste Queru <jbq@google.com> am 4eeb1047: Merge 13212f83 from gingerbread-plus-aosp

* commit '4eeb10470ffafe8c508027f363ac66b58da5bf00':
Fix issue 2988031.
2ef89309d41daac3d69fa78b31cd09cb2c262ca1 29-Jan-2011 Jean-Baptiste Queru <jbq@google.com> Merge 13212f83 from gingerbread-plus-aosp

Change-Id: I9a8ee0c7e7896aea85e7a7c18ee82927091cb670
5092d8c066a1a98343bbc16e33a6753e577b5e7f 27-Jan-2011 Eric Laurent <elaurent@google.com> Fix issue 2988031.

Limit SYSTEM stream volume when a headset is connected and music is playing.

Change-Id: Ieb44ae5bb53ffa9cd5fe8e317798eed279b78df8
udioPolicyManagerBase.cpp
bfa2f13fd3f463dbceea4d3a18c3124e70df0a05 15-Nov-2010 Jean-Michel Trivi <jmtrivi@google.com> do not merge bug 3370834 Cherrypick from master

Cherripick from master CL 79833, 79417, 78864, 80332, 87500

Add new audio mode and recording source 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.

Add a recording source used to designate a recording stream for
voice communications such as VoIP.

Update the platform-independent audio policy manager to pass the
nature of the audio recording source to the audio policy client
interface through the AudioPolicyClientInterface::setParameters()
method.

SIP calls should set the audio mode to MODE_IN_COMMUNICATION,
Audio mode MODE_IN_CALL is reserved for telephony.

SIP: Enable built-in echo canceler if available.
1. Always initialize AudioRecord with VOICE_COMMUNICATION.
2. If echo canceler is available, disable our echo suppressor.

Note that this CL is intentionally not correcting the
getAudioSourceMax() return value in MediaRecorder.java as the
new source is hidden here.

Change-Id: Ie68cd03c50553101aa2ad838fe9459b2cf151bc8
udioFlinger.cpp
udioHardwareInterface.cpp
udioPolicyManagerBase.cpp
61dca6702ce50d937fc764c55bb0842b40dcd0e4 25-Jan-2011 Jean-Michel Trivi <jmtrivi@google.com> Bug 3376700 Add support in APM for stream-specific volume curves

The stream volume was handled the same way for all different stream,
the only potential difference between each of them being the number
of steps available to the user to change the volume. This was
mapped to 99 steps of 0.5dB amplitude, offering a maximum attenuation
of -49.5dB.
This change consists in defining for each stream a curve with two
knees (3 segments) for conversion from volume index to attenuation.
This curve is defined in the AudioPolicyManager in
initializeVolumeCurves(), and can therefore be overridden by the
platform.
Note that this change doesn't modify the volume curves: this CL
enables the curves to be changed by overriding this default
behavior.

Change-Id: I575b66799c52df2906db248943b15120b8a79ea2
udioPolicyManagerBase.cpp
b517e006b51c95db9c44bf5f104f562d431ae597 20-Jan-2011 Eric Laurent <elaurent@google.com> do not merge - 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: If4ca75601ea69a088d0f71d88aec53e90a1dec89
udioFlinger.cpp
73337489229cc9b50371c7a9fcd86e9f00ea46d0 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
udioFlinger.cpp
935752053ef2691dbb6d5a6d149e0e362c6e3c74 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
udioFlinger.cpp
udioPolicyManagerBase.cpp
udioPolicyService.cpp
eb0d0c48ebfcee5e8141ae25fe42a9eac6aae230 10-Jan-2011 Eric Laurent <elaurent@google.com> Fix issue 3317627.

The fix consists in selecting the digital audio device (SPDIF/HDMI)
when available if the routing strategy is STRATEGY_PHONE.

Change-Id: Ie500ae92f5c01f2511988543852ba559c6e5994b
udioPolicyManagerBase.cpp
626c85f3a9ec8e34a1e4af31eddf118d75ee6416 17-Dec-2010 Eric Laurent <elaurent@google.com> Fix issue 3217707.

The problem is that when the A2DP headset is disconnected, there is a transition
period during which the A2DP sink pumps data at a very high pace.
This makes that:
1 the audio flinger mixer thread spins and starves binder threads thus delaying
the completion of the A2DP output stream shutdown
2 we read the audio http audio stream faster than normal and we reach the end of stream
for audio while video is still playing if the streamed file is small enough.

The fix consists in detecting abnormal short write intervals and sleep to restore
a normal write pace.

Change-Id: Iab127882494ab0e26266371dc0ce5c2ff6fa476e
2dpAudioInterface.cpp
2dpAudioInterface.h
0b456a6a33de8cb7c641724579382a31a1beaa2c 16-Dec-2010 Eric Laurent <elaurent@google.com> Fix speakerphone routing to analog dock

The audio routing policy when speakerphone is on and a dock with built-in
speakers is connected should be to output audio to teh dock speakers

Also removed route to SCO car kit if forced usage is not SCO as the SCO
socket might not be established.

Change-Id: I1aa2954092e28de935304b90f7a7a64d661934c7
udioPolicyManagerBase.cpp
f3a8d32fd475ec68d966fa6f12a4c975ba80b659 15-Dec-2010 Eric Laurent <elaurent@google.com> Change audio routing policy for HDMI

HDMI device should have a higher priority than analog dock audio but a lower priority
than wired headsets.
Also modified AudioService so that HDMI is mapped to DEVICE_OUT_AUX_DIGITAL device and not
DEVICE_OUT_DGTL_DOCK_HEADSET as before to enable discrimination between SPDIF going to
digital dock and SPIDF going to HDMI.

Change-Id: I887d0c73479784dd2edaf41ce1a7d8d0bdcbb4bd
udioPolicyManagerBase.cpp
b3fd981d5f8bbf629dd8a07b06b4b656b70cb944 10-Dec-2010 Eric Laurent <elaurent@google.com> Fix audio mode log.

Since the new audio mode IN_COMMUNICATION was added, the audio mode log
was broken.

Change-Id: I4fdafc3b98a1b0ceb55058a9e47fed99b3dbe6ad
udioHardwareInterface.cpp
ed7c671a57f89d389c9d6cd67e0698f160f69916 01-Dec-2010 Eric Laurent <elaurent@google.com> Fix issue 2641884: Bluetooth volume is dependent on in call volume.

The problem is that the code in AudioPolicyManagerBase::checkAndSetVolume() that forces
voice volume to max when setting bluetooth SCO volume is not called if the bluetooth stream
volume did not actually change. So even if we re apply volumes when switching to bluetooth
device, the volume voice volume is not changed and remains what it was when routed to earpiece
What makes things worse on Passion is that stream volumes are limited when connected to bluetooth
and their actual value does not change as soon as they exceed the limit threshold.

Change-Id: Id7c317db45b392a1c20dca2859678e3c64a371ed
udioPolicyManagerBase.cpp
094b148b8587a67c19585e2af2cc7b53868bfb89 01-Dec-2010 Eric Laurent <elaurent@google.com> resolved conflicts for merge of 0d28be68 to master

Change-Id: Iec5f810c366d3e1c14a6f6294b0aea4ffb30ae3e
075a1f660b77fe47b165db1aff97cdd05e300391 02-Nov-2010 Eric Laurent <elaurent@google.com> Fix issue 3142808.

There is a bug in the way audio policy manager handles A2DP interface suspend/restore
when SCO is used. This bug is not new but has been triggered by a change in the timing
of the events received by audio policy manager when a call is setup and torn down
introduced by commit 164a8f86c7e48992691368c4895709c3bdb835a4.

The fix consists in grouping the control of A2DP suspended state in a single function
that is called systematically when conditions affecting this state are changed:
- call state change
- device connection/disconnection
- change in forced usage.

Change-Id: I46ee2399ee5547b60511fc6cfd32e2720091b0f8
udioPolicyManagerBase.cpp
32cb1ba657a1094bb815f4d39f3e4bf12ce8437e 24-Nov-2010 Eric Laurent <elaurent@google.com> Fix issue 3225810.

Take a wake lock whenever A2DP output stream is active.

Change-Id: Ie50e6d4cb34c8a1ba97b301ef25e10aeb153d8f3
2dpAudioInterface.cpp
2dpAudioInterface.h
f5aafb209d01ba2ab6cb55d1a12cfc653e2b4be0 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
udioFlinger.cpp
udioFlinger.h
f1fb01a7f00b8da90a36268aba8584a872e99175 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
udioFlinger.cpp
udioPolicyManagerBase.cpp
56ecd20263d7f63476f756fc5d8b043b325c7bfb 09-Nov-2010 Jean-Michel Trivi <jmtrivi@google.com> Add support for audio recording source in generic audio policy mgr.

Update the platform-independent audio policy manager to pass the
nature of the audio recording source to the audio policy client
interface through the AudioPolicyClientInterface::setParameters()
method.

Change-Id: I6b4fd0f8a3acea0d7d30bbad98edd1977dc012bf
udioPolicyManagerBase.cpp
c643d77a099b0e86ad12de9b498f6f780e03184e 09-Nov-2010 Jean-Michel Trivi <jmtrivi@google.com> Add recording source for voice communication

Add a recording source used to designate a recording stream for
voice communications such as VoIP.

Change-Id: I4091d67069b1a0170c1a5ca5e6acd51eb0aa08f9
udioPolicyManagerBase.cpp
b235dee7be544a6c990ba4f8d89ab03e38c826f8 06-Oct-2010 Praveen Bharathi <pbharathi@motorola.com> Added support for dock headset observer

Change-Id: I06b2e65e3bfa10735e6c7fd3349afa9ae7d45292
Signed-off-by: Praveen Bharathi <pbharathi@motorola.com>
udioPolicyManagerBase.cpp
173e75df12ad5398f3650a30e430dcac0cbcf278 07-Oct-2010 Eric Laurent <elaurent@google.com> am ce2e2184: am 37947afe: Merge "Fixed AudioFlinger not always pausing tracks" into gingerbread

Merge commit 'ce2e2184bbc5530f4fac3220fdf3d1b3fc08a4c3'

* commit 'ce2e2184bbc5530f4fac3220fdf3d1b3fc08a4c3':
Fixed AudioFlinger not always pausing tracks
af59ce2407fa4e6e5d8f1664a4df2daf1badd407 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
udioFlinger.cpp
9ad6e8bd9fab860e639f6ce95479e4b2a9b03ff5 01-Oct-2010 Eric Laurent <elaurent@google.com> am de12c3cf: am 220ab887: Merge "Issue 3032913: improve AudioTrack recovery time" into gingerbread

Merge commit 'de12c3cf56e3f27b2efc60eeae8b5e422747f2b9'

* commit 'de12c3cf56e3f27b2efc60eeae8b5e422747f2b9':
Issue 3032913: improve AudioTrack recovery time
44d9848d6656777a18019223e0d35f2fcc67719a 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
udioFlinger.cpp
9e2e2d2bc86372bde4673c31ef416b2f29d87ac2 29-Sep-2010 Eric Laurent <elaurent@google.com> am b047e3cd: am aeb2c62e: Merge "Fix several audio effects problems." into gingerbread

Merge commit 'b047e3cdf24b32e26f366fcd4cd0eee8ae6c592c'

* commit 'b047e3cdf24b32e26f366fcd4cd0eee8ae6c592c':
Fix several audio effects problems.
dac69110ed1073bf0a9827a3f78698896dd05d97 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
udioFlinger.cpp
f43c92f8d7b1d81cc7248031970d68dc65579be0 24-Sep-2010 Eric Laurent <elaurent@google.com> am 692dfafe: am 880dfe4f: Merge "Fix issue 3007862" into gingerbread

Merge commit '692dfafe02d04cdbab5367546e166580c92e4d2e'

* commit '692dfafe02d04cdbab5367546e166580c92e4d2e':
Fix issue 3007862
84e9a10fde8a4ae3da4f88d7911c154933aa457f 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
udioFlinger.cpp
cc08406f74b67b1b7e532ef8ed534c0476ced636 23-Sep-2010 Eric Laurent <elaurent@google.com> am 11746caa: am 08959c63: Merge "Request permission for global audio effects." into gingerbread

Merge commit '11746caaa852984ff186bf5b8807e2c14cd7c1bc'

* commit '11746caaa852984ff186bf5b8807e2c14cd7c1bc':
Request permission for global audio effects.
fac4895de4ae63928ff0cf2ccece106eb6d33f72 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
udioFlinger.cpp
d20b4cfde2848052cf93ed13df14d75347ec64fd 13-Sep-2010 Eric Laurent <elaurent@google.com> am 4d987850: am bd2e9ec6: Merge "Fix volume problems with insert revert" into gingerbread

Merge commit '4d9878502f7661ed34540a485a5942d859e209c7'

* commit '4d9878502f7661ed34540a485a5942d859e209c7':
Fix volume problems with insert revert
e0aed6ddcb4e3c301b80aa26706b6052dab42c41 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
udioFlinger.cpp
e5fe2601b25e3220c3c4cfb79695ddb8a2f817ac 02-Sep-2010 Eric Laurent <elaurent@google.com> am 937056c1: am 32ec1ad1: Merge "Fix problem in AudioEffect::command() status." into gingerbread

Merge commit '937056c1a7ce71e6881305a31f76e62a76685f24'

* commit '937056c1a7ce71e6881305a31f76e62a76685f24':
Fix problem in AudioEffect::command() status.
aeae3de947fa0b1e670c8472b32288962f97b4f5 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
udioFlinger.cpp
1040127473ee48c1c3b8c279ae05d38dbfb6e4c2 01-Sep-2010 Eric Laurent <elaurent@google.com> am 55e79374: am f560ceab: Merge "Audio Effects: fix problems in volume control." into gingerbread

Merge commit '55e7937462d107b469a58651d3d51e15086f8e9e'

* commit '55e7937462d107b469a58651d3d51e15086f8e9e':
Audio Effects: fix problems in volume control.
8f45bd725549436eeacd12ee69349e2332ed8da5 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
udioFlinger.cpp
udioFlinger.h
ea798dd9f37b34acfa3cf8d945dbe7f7e90e7196 31-Aug-2010 Eric Laurent <elaurent@google.com> am 44217848: am ae6bdc23: Merge "Fix issue 2952766." into gingerbread

Merge commit '4421784895a58bb7bcf90236a9e443b372b5b80e'

* commit '4421784895a58bb7bcf90236a9e443b372b5b80e':
Fix issue 2952766.
c1c88e27a6f07a530fca184f515c16d51e46d56f 28-Aug-2010 Eric Laurent <elaurent@google.com> Fix issue 2952766.

The problem is that the audio policy manager does not handle the input devices
when forced use for telephony is changed.
The problem does not appear in a call over PSTN becasue only teh output devices drives the
routing of in call audio to/from the base band.

The fix consists in modifying AudioPolicyManagerBase::setForceUse() to check for active inputs
and update the input device if needed.

Change-Id: I0d36d1f5eef1cce527929180c29b025439902f10
udioPolicyManagerBase.cpp
69e0b8c5556df1d4db1a730db1c13409a96749c7 21-Aug-2010 Eric Laurent <elaurent@google.com> am 3a899b85: am 0b9a12bf: Merge "Fix issue 2929440" into gingerbread

Merge commit '3a899b85102f6d51585b3d46ced3038c8602f202'

* commit '3a899b85102f6d51585b3d46ced3038c8602f202':
Fix issue 2929440
25cbe0ecd6df8be7e40537c5d85c82f105038479 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
udioFlinger.cpp
udioFlinger.h
a1a6cba3664a04d214b372526658ba227e4d5366 14-Aug-2010 Eric Laurent <elaurent@google.com> am f28608cd: am c8d0d630: Merge "Fix issue 2909189: System property ro.audio.silent no longer mutes system." into gingerbread

Merge commit 'f28608cdf4f6a0075d0811ccd32123baf4daec31'

* commit 'f28608cdf4f6a0075d0811ccd32123baf4daec31':
Fix issue 2909189: System property ro.audio.silent no longer mutes system.
571d49c1c316f5e07b74ed7b5df6bdec7cbc1a14 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
udioFlinger.cpp
bc417c0531332635df9525df4683274a08fb987f 10-Aug-2010 Eric Laurent <elaurent@google.com> am 1ece7d68: am 2a6b80bc: Fixed several audio effects problems.

Merge commit '1ece7d6873027068a3e7b055597045e9387b217c'

* commit '1ece7d6873027068a3e7b055597045e9387b217c':
Fixed several audio effects problems.
8569f0d3bf4c6787707e348a7cf73b9c4199cb32 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
udioFlinger.cpp
e679114b6c7e087a59c2b2c3b55603c43da4ef38 29-Jul-2010 Eric Laurent <elaurent@google.com> am ba676a00: am a54d7d3d: Fixed underrun in audioflinger mixer.

Merge commit 'ba676a00c1b9ba59b30fe805b83d03d1768fffbd'

* commit 'ba676a00c1b9ba59b30fe805b83d03d1768fffbd':
Fixed underrun in audioflinger mixer.
60e182437228312cc28469a5b0dfde77ac848e1a 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
udioFlinger.cpp
cc759794489c2c39aaef229fba4ace32e394bb81 29-Jul-2010 Eric Laurent <elaurent@google.com> am 45dc4f82: am 493941b8: Allow creation of an audio effect on a session with no audio tracks.

Merge commit '45dc4f82a00e52b12389b22a7cfbbee5609e8e28'

* commit '45dc4f82a00e52b12389b22a7cfbbee5609e8e28':
Allow creation of an audio effect on a session with no audio tracks.
39e94f8f723d445447fdee0822291e664b631f60 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
udioFlinger.cpp
udioFlinger.h
ed0de3c123aaa86147993721d4794648a65aab75 28-Jul-2010 Eric Laurent <elaurent@google.com> am 6fa88882: am 62d83a0c: Merge "Audio effects: modified command() parameter types." into gingerbread

Merge commit '6fa8888254deb4961dc64c6ac03dc103c9cd8bcf'

* commit '6fa8888254deb4961dc64c6ac03dc103c9cd8bcf':
Audio effects: modified command() parameter types.
25f4395b932fa9859a6e91ba77c5d20d009da64a 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
udioFlinger.cpp
udioFlinger.h
8184a5734690b30f4de0f6b6c16daf1e089f67df 20-Jul-2010 Eric Laurent <elaurent@google.com> resolved conflicts for merge of dd206093 to master

Change-Id: I21dd2321a4839d034d49092baccbf40986f17dae
de070137f11d346fba77605bd76a44c040a618fc 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
udioFlinger.cpp
udioFlinger.h
udioPolicyManagerBase.cpp
udioPolicyService.cpp
udioPolicyService.h
bbf6dcd2aa8eb877e6412aaade25a077f62a6284 19-Jul-2010 Eric Laurent <elaurent@google.com> am 3c6ea955: am 7203272f: Merge "Fixed problems in audio effect volume control." into gingerbread

Merge commit '3c6ea95553d3a0e416874c583a41efff3f6fbc57'

* commit '3c6ea95553d3a0e416874c583a41efff3f6fbc57':
Fixed problems in audio effect volume control.
f997cabca292d70d078ae828e21c28e6df62995f 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
udioFlinger.cpp
udioFlinger.h
521bcb0ff5054e5be40f5194026da3463504ae3b 16-Jul-2010 Eric Laurent <elaurent@google.com> am f16b3f10: am b0374a0e: Merge "Several improvements in audio effects volume control." into gingerbread

Merge commit 'f16b3f104f60738447db60bcf2c44c7610e17199'

* commit 'f16b3f104f60738447db60bcf2c44c7610e17199':
Several improvements in audio effects volume control.
cab112421da6e8eac19ffddbbe3d76067cffee78 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
udioFlinger.cpp
udioFlinger.h
c0b9c87b2581af430e143822918935d15ac69911 15-Jul-2010 Mathias Agopian <mathias@google.com> am c74034b6: am 24651682: added BinderService<> template to help creating native binder services

Merge commit 'c74034b6bf0940dc80c4d4efa1e677ad0d2dfd6c'

* commit 'c74034b6bf0940dc80c4d4efa1e677ad0d2dfd6c':
added BinderService<> template to help creating native binder services
094c96da874d84eae46f76cc036fa7b7993eb999 15-Jul-2010 Mathias Agopian <mathias@google.com> am 78983a91: am 4055b780: Merge "move native services under services/" into gingerbread

Merge commit '78983a9133d3dd3f08b1ec462a7e2f9e7bfa9e2f'

* commit '78983a9133d3dd3f08b1ec462a7e2f9e7bfa9e2f':
move native services under services/
5462fc9a38fa8c9dff434cd53fa5fb1782ae3042 15-Jul-2010 Mathias Agopian <mathias@google.com> added BinderService<> template to help creating native binder services

Change-Id: Id980899d2647b56479f8a27c89eaa949f9209dfe
udioFlinger.cpp
udioFlinger.h
65ab47156e1c7dfcd8cc4266253a5ff30219e7f0 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
2dpAudioInterface.cpp
2dpAudioInterface.h
ndroid.mk
udioBufferProvider.h
udioDumpInterface.cpp
udioDumpInterface.h
udioFlinger.cpp
udioFlinger.h
udioHardwareGeneric.cpp
udioHardwareGeneric.h
udioHardwareInterface.cpp
udioHardwareStub.cpp
udioHardwareStub.h
udioMixer.cpp
udioMixer.h
udioPolicyManagerBase.cpp
udioPolicyService.cpp
udioPolicyService.h
udioResampler.cpp
udioResampler.h
udioResamplerCubic.cpp
udioResamplerCubic.h
udioResamplerSinc.cpp
udioResamplerSinc.h