History log of /frameworks/av/include/media/AudioTrack.h
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
c3ae93f21280859086ae371428ffd32f39e76d50 30-Jul-2012 Glenn Kasten <gkasten@google.com> Update audio comments

Change-Id: Ie7504d0ddb252f7e4d4f99ed0b44cfc7b1049816
a997e7a7c5aa2fc7e95316218316f8b7b98786ba 07-Aug-2012 Glenn Kasten <gkasten@google.com> Revert "Swap the order of creating IAudioTrack and thread"

This reverts commit 5d464eb0b8cffb994a754ff108795e858a882414.
It caused the wrong thread ID -1 to be passed to IAudioFlinger::createTrack().

Change-Id: Ic221d2bb4af572d3d2d752af19238c52f6728e3a
5d464eb0b8cffb994a754ff108795e858a882414 23-Jun-2012 Glenn Kasten <gkasten@google.com> Swap the order of creating IAudioTrack and thread

Simplifies the error recovery in case IAudioTrack fails.

Change-Id: I6aee41a2ac747a5689fb4836b04174e6107bf32f
28b76b334f92a15a2be3cc9e2f7d229a3275d1ac 04-Jul-2012 Glenn Kasten <gkasten@google.com> Use audio_channel_mask_t for channel mask

Change-Id: I1c1896da48983aa9f1462a4b471f910498816f60
d4070955e28ae62aa4be1657f9d32acde104bb86 12-Jul-2012 Glenn Kasten <gkasten@google.com> Remove dead code in libmedia

Change-Id: I7d8201590cda29c9fa99662a4fdba222091febfe
a636433cbd09c0708b85f337ef45c0cdef3bcb4d 19-Apr-2012 Glenn Kasten <gkasten@google.com> Use C APIs instead of C++ APIs for policy

The C++ APIs are going away.

Note: we use tid == 0 which is not supported yet by the C APIs,
do not submit this until that is added.

Change-Id: I0e90789e6c81c69f2544e899c52421ea5d1342be
3acbd053c842e76e1a40fc8a0bf62de87eebf00f 28-Feb-2012 Glenn Kasten <gkasten@google.com> Configure policy of mediaserver threads

Change-Id: Ifd825590ba36996064a458f64453a94b84722cb0
0ca3cf94c0dfc173ad7886ae162c4b67067539f6 18-Apr-2012 Eric Laurent <elaurent@google.com> rename audio policy output flags

Change-Id: I27c46bd1d1b2b5f96b87af7d05b951fef18a1312
4a4a0959bca78e03e3c3f486ba17829c28314d8c 19-Mar-2012 Glenn Kasten <gkasten@google.com> AudioTrack client fast policy

Change-Id: I42ce691df3f586ac061b62237f35a263a0116f1f
291f4d505aff81969e6666049d3cc3446f836af2 19-Mar-2012 Glenn Kasten <gkasten@google.com> Remove enforceFrameCount

It was only used to decide whether to issue a warning.
The warning was issued the first time track was created but
not at re-creation. Now it is a verbose message every time,
not a warning since it happens all the time with key clicks on A2DP.

Change-Id: I9d39f53c0a7eb84b666e55b1b76ff830cf8f37ba
ea7939a079b3600cab955760839b021326f8cfc3 14-Mar-2012 Glenn Kasten <gkasten@google.com> Whitespace

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

Change-Id: I57a0a8142394f83203161aa9b8aa9276abf3ed7c
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
d8d6185c978c9b27ca69e7791785e0983ed9e8b8 06-Mar-2012 Eric Laurent <elaurent@google.com> AudioTrack: relax check on minimum buffer size

Current AudioTrack implementation enforces that the requested audio
buffer size is at least corresponding the audio latency.
This requirement is too strong and leads to problems with current
stagefright and AudioSink implementations when playing over output
streams with long latency.

Ultimately, the AudioSink design should be changed to specify a minimum
buffer size in time or frames units but not in buffer count units.

Change-Id: I8ba603956f92ac49143a8249572665aa548f2f0f
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>
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
38f5d71e72f3b76c5b519614d27f051d53cd2712 08-Feb-2012 Glenn Kasten <gkasten@google.com> Remove dead code AudioTrack::getLoop

Change-Id: I868329c52f31bc20125f068500d8f892b4ec9796
4f9b0c54011eb8fd2ccfb393c2dcd51cd07800e0 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Remove dead mutex in AudioTrack/AudioRecord thread"
a5224f319e2ba4b51ddb4287705ccf8d4b8ecc51 04-Jan-2012 Glenn Kasten <gkasten@google.com> AudioTrack declare more methods const

Change-Id: I4999e984460893961d0d8092cff17f3cf07d7214
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
0e265cf36d201a7ccc0238b5c60b50f43d1dc450 02-Feb-2012 Glenn Kasten <gkasten@google.com> Remove dead mutex in AudioTrack/AudioRecord thread

The client callback threads had mutexes called AudioTrackThread::mLock
and ClientRecordThread::mLock. These mutexes were only used by start()
and stop(), and were unused by the thread itself. But start() and
stop() already have their own protection provided by AudioTrack::mLock
and AudioRecord::mLock. So the thread mutexes can be removed.

Change-Id: I098406d381645d77fba06a15511e179a327848ef
335787fe43596f38ea2fa50b24c54d0823a3fb1d 21-Jan-2012 Glenn Kasten <gkasten@google.com> Remove AudioFlinger dependencies on client

Change-Id: Ibb591e41a3ca5d7015e2b66b98b8fef5f415fb37
c813985abd8ba61e999b3505f6a332574f87a1be 18-Jan-2012 Andreas Huber <andih@google.com> Temporarily restore AudioSystem/AudioTrack APIs with their former signatures

until we get updated prebuilts from vendor.

Change-Id: I8aae81d2513edca0ab268053a11c8c4206879e61
613882293184e575a44bff681a3decaefe889e69 17-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use size_t for frame size"
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
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

Change-Id: Ia33bfd70edca8c2daec9052984b369cd8eee2a83
4cc55d53d542c4f4ed645738cebb65b9e7eb6c44 12-Jan-2012 Glenn Kasten <gkasten@google.com> Merge "Use audio_format_t consistently"
e1c3962e268ffc12bfd1bd9ea84da1f135f36960 04-Jan-2012 Glenn Kasten <gkasten@google.com> Use audio_format_t consistently

Was int, uint32_t, uint16_t, and uint8_t with 2-bit bitfield.
Also replace 0 by AUDIO_FORMAT_DEFAULT and replace 1 by

Change-Id: Ia8804f53f1725669e368857d5bb2044917e17975
9a2aaf927e56a4b4acab23ef16b3f133a9f48a63 03-Jan-2012 Glenn Kasten <gkasten@google.com> Clean up AudioTrack::mActive and stopped()

mActive is protected by mLock; volatile is meaningless on SMP.

Fixed a couple of places where mActive was accessed without a lock:
- stopped()
- processAudioBuffer()

Added stopped_l() for cases where we already hold the lock.

Made mActive a bool not int.

Moved down a lock in setPosition that was being acquired too early.

Change-Id: I73ff368e991c0db9f9472df0b3f96fd33fcc7311
362c4e697d8e9c034e964ac7b40227e054491547 14-Dec-2011 Glenn Kasten <gkasten@google.com> Audio C++ comments

Change-Id: I84906ebb9dfcfa5b96b287d18364b407f02a30c1
c9260c15c1e7e2743039c964b8769379a3fff332 28-Nov-2011 Glenn Kasten <gkasten@google.com> Merge "Make AudioTrack a RefBase so wrappers not needed"
879135196fd1c97deefc538c888037c56c2879a7 23-Jun-2011 Glenn Kasten <gkasten@google.com> Bug 4903178 Restore priority and cgroup on stop

On AudioTrack and AudioRecord stop or failed start, restore the priority
and cgroup of the caller to their previous values, rather than forcing
to NORMAL. Dependent on new thread APIs.

Also fixes bug where priority was set to AUDIO but cgroup not set.

Change-Id: Ib83893918fb4fdf57c6b87884b51038997a631d8
b68a91a70bc8d0d18e7404e14443d4e4020b3635 15-Nov-2011 Glenn Kasten <gkasten@google.com> Make AudioTrack a RefBase so wrappers not needed

Change-Id: I2305abe586ac41251af04a194bc818c110a1b293
cfe2ba6b01a258e39f9c215ffc7b750e0b68f708 14-Sep-2011 Eric Laurent <elaurent@google.com> Issue 5298399: Lost speech after a crash in gTalk.

Fixed problem in AudioTrack::restoreTrack_l() causing a permanent
failure if the IAudioTrack interface to AudioFlinger could not be
restored at the first attempt.

Change-Id: I039d4fe2dca8d3baf71f1a6c51119f27a67b6611
cd07594333cbe8b2c86c6609cce01a74d6cc33f8 26-Aug-2011 Jean-Michel Trivi <jmtrivi@google.com> Bug 4364249 Play position is 0 after flushing AudioTrack

AudioTrack::stop() is not synchronous, so a stop() followed
by flush(), which is synchronous, will not always report
a playhead position of 0 after being called.
This CL adds a flag to mark a track as flushed, and report the
correct playhead position in this state.
Bug 5217011 has been created to address the real issue in the
future, where flush could be made synchronous, to properly
address bug 4364249.

Change-Id: Icf989d41a6bcd5985bb87764c287f3edb7e26d12
d217a8c4632b3e3065f8c2a26b9ce4dc4c97171f 02-Jun-2011 Glenn Kasten <gkasten@google.com> Revert "Use AudioTrack::event_type not int in callback"

This reverts commit 2225e4b7049fa3fb9d39a068b8268b63c952d7c1
013b5a67d6f8e12a1b06e74863daec1bee4d99c1 05-May-2011 Glenn Kasten <gkasten@google.com> Use AudioTrack::event_type not int in callback

Change-Id: Ifefc708d46874e04fd0d01cb6e2d43b987ee796c
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
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>
1703cdfee717b1b312bf8979816a9e2f16a82e5d 07-Mar-2011 Eric Laurent <elaurent@google.com> Fix issue 3439872: video chat and bluetooth SCO

This change fixes the stability problems experienced when using
a bluetooth headset supporting both A2DP and SCO. Problems occur
when starting the video chat at which time the A2DP output is being
stopped to start SCO. At that time, active AudioTracks are invalidated
by AudioFlinger so that a new AudioTrack binder interface can be
recreated by the client process on the new mixer thread with correct parameters.
The problem was that the process to restore the binder interface was not
protected against concurrent requests which caused 2 binder interfaces
to be created sometimes. This could lead to permanent client deadlock
if one of the client threads was waiting for a condition of the first
created binder interface while the second one was created (as the AudioFlinger
would only signal conditions on the last one created).
This concurrent request situation is more likely to happen when a client
uses the JAVA AudioTrack as the JNI implementation uses simultaneously the
native AudioTrack callback and write push mechanisms. By doing so, the code
that checks if the binder interface should be restored (in obtainBuffer()) is
much more likely to be called concurrently from two different threads.

The fix consists in protecting the critical binder interface restore phase
with a flag in the AudioTrack control block. The first thread acting upon the binder
interface restore request will raise the flag and the second thread will just wait for
a condition to be signaled when the restore process is complete.

Also protected all accesses to the AudioTrack control block by a mutex to prevent
access while the track is being destroyed and restored. If a mutex cannot be held
(e.g because we call a callback function), acquire a strong reference on the IAudioTrack
to prevent its destruction while the cblk is being accessed.

Modified AudioTrack JNI to use GetByteArrayElements() instead of
GetPrimitiveArrayCritical() when writing audio buffers. Entering a critical section would
cause the JNI to abort if a mediaserver crash occurs during a write due to the AudioSystem
callback being called during the critical section when media server process restarts.
Anyway with current JNI implementation, either versions do not copy data most of the times
and the criticial version does not guaranty no data copy.

The same modifications have been made to AudioRecord.

Change-Id: Idc5aa711a04c3eee180cdd03f44fe17f3c4dcb52
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
2beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1 16-Jul-2010 Eric Laurent <elaurent@google.com> Added support for auxiliary audio effects to AudioTrack and MediaPlayer.

Added methods to AudioTrack and MediaPlayer java classes to enable use of
auxiliary audio effects. The effect can be attached and detached by specifying its
ID and the send level controlled.

Change-Id: Ie74ff54a453096a742688476f612ce355543b6f3
33005a932c60a0780fe9b7307d5988df3d9f6c26 16-Jun-2010 Chia-chi Yeh <chiachi@android.com> media: add AudioTrack::getMinFrameCount().

Change-Id: If15162583d1d16d89f59be0793106afe77417f35
be916aa1267e2e6b1c148f51d11bcbbc79cb864c 02-Jun-2010 Eric Laurent <elaurent@google.com> Issue 2667801: [Audio Effect Framework] AudioFlinger, AudioMixer AudioTrack modifications.

First drop of audio framework modifications for audio effects support.

- AudioTrack/AudioRecord:
Added support for auxiliary effects in AudioTrack
Added support for audio sessions
Fixed left right channel inversion in setVolume()

- IAudioFlinger:
Added interface methods for effect enumeraiton and instantiation
Added support for audio sessions.

- IAudioTrack:
Added method to attach auxiliary effect.

- AudioFlinger
Created new classes to control effect engines in effect library and manage effect connections to tracks or
output mix:
EffectModule: wrapper object controlling the effect engine implementation in the effect library. There
is one EffectModule per instance of an effect in a given audio session
EffectChain: group of effects associated to one audio session. There is one EffectChain per audio session.
EffectChain for session 0 is for output mix effects, other chains are attached to audio tracks
with same session ID. Each chain contains a variable number of EffectModules
EffectHandle: implements the IEffect interface. There is one EffectHandle object for each application
controlling (or using) an effect module. THe EffectModule maintians a list of EffectHandles.

Added support for effect modules and effect chains creation in PlaybackThread.
modified mixer thread loop to allow track volume control by effect modules and call effect processing.

Each track now specifies its output buffer used by mixer for accumulation
Modified mixer process functions to process tracks by groups of tracks with same buffer
Modified track process functions to support accumulation to auxiliary channel

Change-Id: I26d5f7c9e070a89bdd383e1a659f8b7ca150379c
d1b449aad6c087a69f5ec66b7facb2845b73f1cb 14-May-2010 Eric Laurent <elaurent@google.com> Fix issue 2553359: Pandora does not work well with Passion deskdock / Cardock.

The problem is due to a too big difference between the buffer size used at the hardware interface and at the A2DP interface.
When no resampling occurs we don't notice problems but the timing is very tight. As soon as resampling is activated, the AudioTrack underruns.
This is because the AudioTrack buffers are not resized when moving the AudioTrack from hardware to A2DP output.
The AudioTrack buffers are calculated based on a hardware output buffer size of 3072 bytes. Which is much less than the A2DP output buffer size (10240).

The solution consists in creating new tracks with new buffers in AudioFlinger when the A2DP output is opened
instead of just transfering active tracks from hardware output mixer thread to the new A2DP output mixer thread.
To avoid synchronization issues between mixer threads and client processes, this is done by invalidating tracks
by setting a flag in their control block and having AudioTrack release the handle on this track (IAudioTrack)
and create a new IAudioTrack when this flag is detected next time obtainBuffer() or start() is executed.

AudioFlinger modifications:
- invalidate the tracks when setStreamOutput() is called
- make sure that notifications of output opening/closing and change of stream type to output mapping are sent synchronously to client process.
This is necessary so that AudioSystem has the new stream to output mapping when the AudioTrack detects the invalidate flag in the client process.
Previously their were sent when the corresponding thread loop was executed.

AudioTrack modifications:
- move frame count calculation and verification from set() to createTrack() so that is is updated every time a new IAudioTrack is created.
- detect track invalidate flag in obtainBuffer() and start() and create a new IAudioTrack.

AudioTrackShared modifications
- group all flags (out, flowControlFlag, forceReady...) into a single bit filed to save space.

Change-Id: I9ac26b6192230627d35084e1449640caaf7d56ee
34f1d8ecd23169a5f299937e3aaf1bd7937578a0 04-Nov-2009 Eric Laurent <elaurent@google.com> Fix issue 2203561: Sholes: audio playing out of earpiece.

Create a new IAudioTrack interface to AudioFlinger when start() fails due to a broken pipe error.
Do the same if start fails due to the same error after time out in obtainBuffer().
Do not indicate that the AudioTrack is started to AudioPolicyManager if IAudioTrack start fails.
This avoids that an AudioTrack keeps a dead IAudioTrack after a media server crash.

Same modifications for AudioRecord.

Add a flag to ToneGenerator indicating that the callback thread can call Java. Without it, when the media server crashes and restarts, the AudioSystem error callback will crash in JNI if the IAudiotrack is created from AudioTrack callback thread.
c2f1f07084818942352c6bbfb36af9b6b330eb4e 17-Jul-2009 Eric Laurent <elaurent@google.com> Fix issue 1795088 Improve audio routing code

Initial commit for review.
Integrated comments after patch set 1 review.
Fixed lockup in AudioFlinger::ThreadBase::exit()
Fixed lockup when playing tone with AudioPlocyService startTone()
349dba337e07e129f6ba49a132999f0b73fedbe3 07-Jul-2009 Eric Laurent <elaurent@google.com> am 88e209dc: Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR

Merge commit '88e209dcf8c2ebddda5c272f46d1bd5478bc639c'

* commit '88e209dcf8c2ebddda5c272f46d1bd5478bc639c':
Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR
573266210fb2b2e7d86fbd46d0dfe16763611d91 07-Jul-2009 Eric Laurent <elaurent@google.com> Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR

Store sample rate on 32 bits instead of 16 bits in audio_track_cblk_t.
Removed sampleRate() methods from AudioTrack and AudioRecord: replaced by getSampleRate().
AudioTrack::setSampleRate() no returns a status.
7562408b2261d38415453378b6188f74fda99d88 20-May-2009 Mathias Agopian <mathias@google.com> move libbinder's header files under includes/binder
1dd70b9f04961a06fcb73a97fca10a53b3245d3c 21-Apr-2009 Eric Laurent <elaurent@google.com> Fix issue 1745312: Various cleanups in media framework

AudioTrack, AudioRecord:
- remove useless mAudioFlinger member of AudioTrack and AudioRecord.
- signal cblk.cv condition in stop() method to speed up stop completion.
- extend wait condition timeout in obtainBuffer() when waitCount is -1 to avoid waking up callback thread unnecessarily

- remove some warnings in AudioFlinger.cpp.
- remove function AudioFlinger::MixerThread::removetrack_l() as its content is never executed.
- remove useless call to setMasterVolume in AudioFlinger::handleForcedSpeakerRoute().
- Offset VOICE_CALL stream volume to reflect actual volume that is never 0 in hardware (this fix has been made in the open source): 0.01 + v * 0.99.

- correct typo in comment

IAudioflinger, IAudioFlingerClient:
- make AudioFlinger binder interfaces used for callbacks ONEWAY.

- correct routeStrings[] table in AudioHardwareInteface.cpp
2c22aeb65e801f663a754d043062f85e49f77739 25-Mar-2009 Jean-Michel Trivi <> Automated import from //branches/donutburger/...@140663,140663
89fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
15f767b960b38059a74a42a33e16d8df2aec8bc1 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
7a2146d5807030b2629f347736be5301b61e8811 13-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@131421
5e07b5774c8b376776caa4f5b0a193767697e97e 11-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@130745
e5198b620a9a208ec59ea8457282404725f8ff6e 20-Jan-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@127101
7b5eb023f8d87cca6d830ae6c11c6aadbe02aca8 18-Dec-2008 The Android Open Source Project <initial-contribution@android.com> Code drop from //branches/cupcake/...@124589
2729ea9262ca60d93047e984739887cfc89e82eb 21-Oct-2008 The Android Open Source Project <initial-contribution@android.com> Initial Contribution