History log of /frameworks/av/media/libmedia/AudioRecord.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
c447ded04f11169e9b96b31cd196b2c4ffa9f31c 06-Jan-2015 Eric Laurent <elaurent@google.com> fix record from default input source

Commit caf7f48a0e broke capture from default
input source on some devices: the input source is now specified as part of
the audio attributes and the default source was not remapped to mic source.

Bug: 18736417.
Change-Id: I3f5da33cdb56f959aaef68ed1952342babc63aa0
/frameworks/av/media/libmedia/AudioRecord.cpp
caf7f48a0ef558689d39aafd187c1571ff4128b4 26-Nov-2014 Eric Laurent <elaurent@google.com> AudioRecord: use audio attributes instead of audio source.

Added AudioRecord constructor with audio attributes.
Replaced AudioPolicymanager::getInput() by getInputForAttr().

No new functionality for now.

Also:

- Fixed warnings in AudioPolicyManager
- Allocate audio session ID before calling getOutputForAttr() in
AudioTrack.

Bug: 16006090.
Change-Id: I15df21e4411db688e3096dd801cf579d76d81711
/frameworks/av/media/libmedia/AudioRecord.cpp
e83b55dc29ca16092ba02f36f55fa6e0e37fd78c 14-Nov-2014 Eric Laurent <elaurent@google.com> audio policy: new getOutputForAttr() prototype.

Update getOutputForAttr() prototype and group all logic
dealing with audio attributes to stream type conversion in
audio policy manager.

getOutputForAttr():
- specifies the audio session (for future use)
- returns a status code
- receives either stream type (for legacy) or audio attributes
- returns an updated streamtype

Remove logic dealing with legacy stream types to attributes conversion
from AudioTrack.

Use correct type for audio sessions in other APIs (startOutput() ...).

releaseOutput() specifies the audio session (for future use).

Bug: 18067208.

Change-Id: I1bfbe9626c04c7955d77f8a70aecfad2cb204817
/frameworks/av/media/libmedia/AudioRecord.cpp
4dc680607181e6a76f4e91a39366c4f5dfb7b03e 29-Jul-2014 Eric Laurent <elaurent@google.com> audio policy: pass session ID to capture activity methods

Indicate the audio session ID when calling getInput(),
startInput(), stopInput(), releaseInput().

Bug: 12378680.
Change-Id: I763793752f93e2f4e1445a5ab217c895af011038
/frameworks/av/media/libmedia/AudioRecord.cpp
de3f8392fbf380ba6f09d009b00d7172477389a2 28-Jul-2014 Eric Laurent <elaurent@google.com> rename AudioSystem::newAudioSessionId()

Rename AudioSystem::newAudioSessionId() to
AudioSystem::newAudioUniqueId() as it can be used
also for I/O handles.

Bug: 12378680.
Change-Id: I611ea3b5eb57a4b0774437f477ee87dc4ccc2cc2
/frameworks/av/media/libmedia/AudioRecord.cpp
7410591dad836434c72ddee66680802708b70c10 03-Jul-2014 Glenn Kasten <gkasten@google.com> Move AudioRecord frame count calculations to server

Buffer frame count and notification frame count
are now calculated by server instead of by client.
The server has more information and can do a better job.

Also fix a few bugs:

- If a fast track was re-created, even with same pipe depth, it would fail.
Now it can correctly re-create a fast track provided the pipe depth is same.

- Notification frame count for fast tracks was calculated by client
as 1/2 of the total frame count, which is a large value due to the pipe.
Now the notification frame count is set by server to the HAL frame count.
This should reduce latency for fast tracks.

- EVENT_OVERRUN were happening frequently when there was sample rate conversion,
because the client didn't know about the sample rate conversion,
and under-estimated the necessary buffer size. Now since server
calculates the buffer sizes, EVENT_OVERRUN is unlikely.

- RecordThread::createRecordTrack_l was checking for mono and stereo
for fast tracks. This is not necessary, and now we can handle a
multi-channel fast track.

Bug: 7498763
Change-Id: I0c581618e8db33084d5ff9ed50a592990c9749e8
/frameworks/av/media/libmedia/AudioRecord.cpp
b3b1660ecb67f61f9da54efced8677fa3a6f4863 16-Jul-2014 Glenn Kasten <gkasten@google.com> Add audio_input_flags_t to IAudioPolicyService::getInput

Change-Id: I9f37be05f8dc7b85a8827a94e76ca0f45453e170
/frameworks/av/media/libmedia/AudioRecord.cpp
7df8c0b799d8f52d6386e03313286dbd7d5cdc7c 03-Jul-2014 Glenn Kasten <gkasten@google.com> IAudioFlinger::openRecord now suggests notificationFrames

Change-Id: I08885cc381d03c522a23289e74f0e1ed46563863
/frameworks/av/media/libmedia/AudioRecord.cpp
34fb29696b0f3abf61b10f8d053b1f33d501de0a 19-Jun-2014 Mark Salyzyn <salyzyn@google.com> libmedia: 64-bit compile warnings

Change-Id: I600f062fa7148c01851023c1240c39939e648002
/frameworks/av/media/libmedia/AudioRecord.cpp
3bcffa136909c1fb6e88ee4efd12ccac18360a85 13-Jun-2014 Eric Laurent <elaurent@google.com> force command flush after releasing a reference to shared memory

After releasing a reference to a shared memory interface,
IPCThreadState::self()->flushCommands() must be called to ensure
that the corresponding reference is also cleared immediately in the
remote process. Otherwise the binder implementaiton will not
push the clear systematically causing the memory region not to be freed.

See issues 10711502 and 2801375.

Bug: 14057166.
Change-Id: If55f36f00d452d6cf00cf83bd2fba1c8f3abcb57
/frameworks/av/media/libmedia/AudioRecord.cpp
c263ca0ad8b6bdf5b0693996bc5f2f5916e0cd49 05-Jun-2014 Glenn Kasten <gkasten@google.com> Squashed commit of the following:

commit 9128d6ffec43731d723f9b394f243d940f4c7e41
Author: Glenn Kasten <gkasten@google.com>
Date: Tue May 13 10:38:42 2014 -0700

Use of fast capture by normal capture

Will only configure fast capture path if the input buffer size is less than
10 ms and the input sample rate is same as the primary output sample rate.

Change-Id: I4a7cdc6069d750845412c626d27e83f72a1ab397

commit 2e5e0806a5abe7499848358ef5fde5c26405000d
Author: Glenn Kasten <gkasten@google.com>
Date: Mon Jun 2 08:29:22 2014 -0700

Add mPrimaryOutputSampleRate

Change-Id: I46b527fc3f2b5a5720a74b4f0b9a8f2e0d570b09

commit baf1d73467923996d1b1f2a9237260cc5697e050
Author: Andy Hung <hunga@google.com>
Date: Fri May 30 10:42:03 2014 -0700

Change parameter type for volume to float in AudioMixer

Change-Id: I4da1505ce852505f86f8e5b87f60e8edceeb30e0

commit 40fe20fa9760cd03c69778c2021cf7a490d75ece
Author: Andy Hung <hunga@google.com>
Date: Fri May 30 10:35:47 2014 -0700

Rename UNITY_GAIN to UNITY_GAIN_INT in AudioMixer

Change-Id: Ic040311305026f0b4c4280a5b3bef7a447ac1da3

commit 37c9a2b49f876abc5ff537a9ec036d7f0a423775
Author: Andy Hung <hunga@google.com>
Date: Thu May 29 21:33:13 2014 -0700

Refactor setVolumeRampVariables in AudioMixer

Change-Id: I8fcf3101bcea292de7c65433fa578f1c9cdd0974

commit 397070eca31f121d5d3993de1bfea99aaea5d4f3
Author: Andy Hung <hunga@google.com>
Date: Thu May 29 18:52:38 2014 -0700

Fix floating point output from mixer

A buffer pointer was being erroneously reset to buffer start,
potentially causing an audio glitch. The floating point
output mode is not enabled at this time, but will be in
the future.

Change-Id: If8b6414d232f064f3a2e2c5a6da889a91b27fb24

commit 2e61aa5b33b2247bbc5d4eaa0b519df9accd4bbc
Author: Andy Hung <hunga@google.com>
Date: Fri May 23 21:22:17 2014 -0700

Add multiple format capability to FastMixer

Floating point data from MixerThread into FastMixer.
Multiple output format capability from FastMixer to Sink.

Change-Id: I0da17810ee71381a39a006c46faec71108d22c26

commit b9ea653c702a785bbd23a66c5e588d40b4192c4e
Author: Andy Hung <hunga@google.com>
Date: Thu May 29 15:53:09 2014 -0700

Avoid resetting BufferProviders in mixer unnecessarily

Change-Id: Iad85c4dfd21be1dbf89dc11906106b34219376f8

commit 7f1a6d6da21c616f80cf9ba21bea11b419ec561b
Author: Andy Hung <hunga@google.com>
Date: Tue May 27 12:32:17 2014 -0700

Update dynamic resampler buffer fetching

Make the criteria tight for fetching to avoid storing
excessive frame data internal to the resampler.
This should reduce jitter in frame delivery computation.

Bug: 14962343
Change-Id: I7adaf714d11c272696ccdbf218bda994c7217477

commit b5e4aac07b9a02f0c803c090058602b03ac09ebb
Author: Glenn Kasten <gkasten@google.com>
Date: Tue May 27 12:30:54 2014 -0700

Allow kFastTrackMultiplier to be specified per device

Change-Id: I4eaaaf038df720cec4f5d9221d1b632970f9e3dd

commit b93cd97a52af31122df2da2cc0415cda888c8c73
Author: Andy Hung <hunga@google.com>
Date: Fri May 23 21:13:31 2014 -0700

Rename mixBuffer to mMixerBuffer in FastMixer

Likewise mixBufferState becomes mMixerBufferState.
This harmonizes with the naming in AF::MixerThread.

Change-Id: I1255d7c07cc2c6ee925d7430925236d2bd163122

commit 8340758622b9711365a8801806cbdf934803c63f
Author: Andy Hung <hunga@google.com>
Date: Mon May 12 16:51:41 2014 -0700

Add multiple format capability to AudioMixer

Change-Id: I04ac1cafd90b6ed652f8d51888ad07576678f0bc
Signed-off-by: Andy Hung <hunga@google.com>

commit 6b695b9d094820c232a897a3fabbe83d2b7193fe
Author: Glenn Kasten <gkasten@google.com>
Date: Thu Mar 13 14:59:31 2014 -0700

Start adding FastCapture based on FastThread WIP

This version supports at most one fast capture client.

Change-Id: Idf609bfc80ae22433433d66a5232c043c65506df

commit e951ad05a2c388471d7e2806d91e7d51325a150a
Author: Glenn Kasten <gkasten@google.com>
Date: Mon May 12 11:06:26 2014 -0700

Move validation of frameCount from set to openRecord_l

This move is needed because frameCount is validated on server side for
fast tracks (as should be done for normal tracks too).

Change-Id: I6d99e80869fd90fab373cf60ef348c01f075fbca

commit 73e76992dbba794894837c38e5472312ea829cf3
Author: Glenn Kasten <gkasten@google.com>
Date: Tue May 13 10:41:52 2014 -0700

Allow track buffer "allocation" to be from pipe

Change-Id: Ib9ac170f8e8b7746b3588157a56cbee3b753a1cb

commit 60de1d7ded05c6304037d4858b401094b1d2b4d3
Author: Andy Hung <hunga@google.com>
Date: Fri May 9 15:02:21 2014 -0700

Add format parameter to getTrackName() and track_t

Change-Id: Ia152a839014e235fbfb656104c15d7c1b456d02e
Signed-off-by: Andy Hung <hunga@google.com>

Change-Id: Ied0ade8b25d23e89bb03319a7e3135c238f735b9
/frameworks/av/media/libmedia/AudioRecord.cpp
e541269be94f3a1072932d51537905b120ef4733 16-May-2014 Andy Hung <hunga@google.com> Use new channel count functions for audio masks

Change-Id: Ia658ab4b6320d19fdb50f123c930918724ff0ef3
Signed-off-by: Andy Hung <hunga@google.com>
/frameworks/av/media/libmedia/AudioRecord.cpp
d776ac63ce9c013c9626226e43f7db606e035838 07-May-2014 Glenn Kasten <gkasten@google.com> IAudioFlinger::openRecord returns IMemory(s)

openRecord() now explicitly returns the control block and data buffer
as separate IMemory references. If the IMemory for data buffer
is 0, this means it immediately follows the control block.

Change-Id: Ic098f88f0e037f8fbe30006689e18cacacf09d06
/frameworks/av/media/libmedia/AudioRecord.cpp
828f883a43f66f77d776a75d0ea2b87c7c826071 07-May-2014 Glenn Kasten <gkasten@google.com> Fix a couple of fast capture typo bugs

AudioRecord constructor was not passing flags through to set().
Server-side check was using wrong kind of channel mask.

Change-Id: Ifaa880ec323771e9fd168262be05f3e539f53390
/frameworks/av/media/libmedia/AudioRecord.cpp
142f519aa1acd5804d111e60d100f170fed28405 26-Mar-2014 Glenn Kasten <gkasten@google.com> Use symbol AUDIO_IO_HANDLE_NONE from <system/audio.h>

Change-Id: Id6b1aa17558eb73e17f22b8eab6cd02e00a96dff
/frameworks/av/media/libmedia/AudioRecord.cpp
879707057cde0a83b5f6143c918c66b8f4a97581 28-Feb-2014 Glenn Kasten <gkasten@google.com> Make openRecord_l more like createTrack_l for fast tracks: part 3

Create the callback thread earlier, before creating the IAudioRecord,
so that the thread's tid is available as a parameter to openRecord().

Also move initialization of mCbf to same point as in AudioTrack.cpp.

Change-Id: I61ea4c5e2724ccfc691aaf51bc02a7c10d5a7495
/frameworks/av/media/libmedia/AudioRecord.cpp
2c48f27be6b3ae58e451d9b56c1dfd00e606f345 27-Feb-2014 Glenn Kasten <gkasten@google.com> Make openRecord_l more like createTrack_l for fast tracks: part 2

Assume double-buffering because we don't know the true HAL sample rate,
and for fast tracks we must accomodate kernel scheduling and app
computation jitter.

Change-Id: I983d6048a8b4814cfa5bf789397cdd9f1572256c
/frameworks/av/media/libmedia/AudioRecord.cpp
33ca5cf8826f5fcd9c011e8d336138b62d982f2a 28-Feb-2014 Glenn Kasten <gkasten@google.com> Merge "Make openRecord_l more like createTrack_l for fast tracks: part 1"
bce50bfc3846ab008bafa75c5d3f29fd7b5395f7 28-Feb-2014 Glenn Kasten <gkasten@google.com> Fix type of AudioTrack/AudioRecord parameter frameCount

It's size_t consistently

Change-Id: I29638ef59ac773218025f2403a3508a307b487e0
/frameworks/av/media/libmedia/AudioRecord.cpp
838b3d8bafa4a781e277870dee4e0390165cff52 28-Feb-2014 Glenn Kasten <gkasten@google.com> Fix type of AudioTrack/AudioRecord parameter notificationFrames

It's uint32_t consistently

Change-Id: If8298c7e9aeea2b951fe47b675adbdf48d104846
/frameworks/av/media/libmedia/AudioRecord.cpp
c6ba823a397abf865b02f4f48fe18231f94d8e87 27-Feb-2014 Glenn Kasten <gkasten@google.com> Make openRecord_l more like createTrack_l for fast tracks: part 1

Use the transfer mode to distinguish use cases, as the presence of
a callback handler is not sufficient. For example, the track could be
configured for synchronous transfer with write() or read(), and also
have a callback handler for position updates. But that does not mean
the track can operate in fast track mode.

Change-Id: I2a7f1f0ca98e68efe180b524496985109d8ce291
/frameworks/av/media/libmedia/AudioRecord.cpp
c08d20b6a37122ebf116262c9372509ed060d4c1 25-Feb-2014 Glenn Kasten <gkasten@google.com> Simplify error handling after track creation

IAudioFlinger::createTrack and IAudioFlinger::openRecord
both guarantee that (status == OK) == (sp<> != 0).

Change-Id: I91cb4f7e843019efb65cace7ba146f7da7aa5b59
/frameworks/av/media/libmedia/AudioRecord.cpp
045e739161f5ae00321a6cfba20935abb791005b 26-Feb-2014 Glenn Kasten <gkasten@google.com> Move initialize of mInput to match AudioTrack

Change-Id: I4dc977f22f51cd618dc83d800b4b8756929a4612
/frameworks/av/media/libmedia/AudioRecord.cpp
f7cc3631c5c264e13ce8c6bc15bd829b2ff9b036 26-Feb-2014 Glenn Kasten <gkasten@google.com> Update comments to match AudioTrack

Change-Id: I7dd14eabd78c9130a157da2063a1d65ec4f9c65a
/frameworks/av/media/libmedia/AudioRecord.cpp
a5ed48d3476df7dd1e10b380a68e3333f2b646fd 26-Feb-2014 Glenn Kasten <gkasten@google.com> Move initialization of mRefreshRemaining to match AudioTrack

This also fixes a bug where, for a re-created IAudioRecord,
mRefreshRemaining was not being reset correctly.

Change-Id: I9f721a4edf92aab859cf3f247ab7f65562d14fb0
/frameworks/av/media/libmedia/AudioRecord.cpp
591d9a3652f868652ccc48dd9e9714f3a9813963 25-Feb-2014 Glenn Kasten <gkasten@google.com> Merge "mAudioRecord is always non-0 if set() is successful"
7c1b8941bb54e38f2a717e41af0d9565f5977c27 25-Feb-2014 Glenn Kasten <gkasten@google.com> Merge "Unify comments and whitespace between AudioTrack and AudioRecord"
882469cfe767188a4c67d2d83f3d72ab553a4818 25-Feb-2014 Glenn Kasten <gkasten@google.com> Merge "Update mReqFrameCount at same point in AudioTrack and AudioRecord"
99ef241a8d310b3319c02eac18de9bb7422c5ab0 25-Feb-2014 Glenn Kasten <gkasten@google.com> Merge "Permit AudioRecord to support non-linear formats in future"
9f474b7824abb0d5408d02e365cf37a986663979 25-Feb-2014 Glenn Kasten <gkasten@google.com> Merge "Simplify and cleanup error handling in AudioRecord::getMinFrameCount"
b42f318d9733f88c7eb9bedfd33b086b8ea5dff5 24-Feb-2014 Glenn Kasten <gkasten@google.com> Simplify and cleanup error handling in AudioRecord::getMinFrameCount

Change-Id: I8721ecedfb429c4e233453d1e768ddf69ecabbe4
/frameworks/av/media/libmedia/AudioRecord.cpp
089e87201522c8979ac8f00fa729e907f54c790b 25-Feb-2014 Glenn Kasten <gkasten@google.com> mAudioRecord is always non-0 if set() is successful

Change-Id: I0c2483210903c922f06f097ada373a37b9a90a02
/frameworks/av/media/libmedia/AudioRecord.cpp
5f631515d098c29603cda88f7a7e7580a2d55b57 25-Feb-2014 Glenn Kasten <gkasten@google.com> Unify comments and whitespace between AudioTrack and AudioRecord

Change-Id: I5320a6b2d7f7077cb12d7da4f2ca30a940100bf2
/frameworks/av/media/libmedia/AudioRecord.cpp
11cb175005db0090345f44bfa049b52fd8c809b8 25-Feb-2014 Glenn Kasten <gkasten@google.com> Update mReqFrameCount at same point in AudioTrack and AudioRecord

Change-Id: I12369dfbb9e75389f2cab015a706decdaf310a0d
/frameworks/av/media/libmedia/AudioRecord.cpp
c85df82b1e8b05714268926a8bb3deb9c65f9a22 25-Feb-2014 Glenn Kasten <gkasten@google.com> Permit AudioRecord to support non-linear formats in future

But still restricted to 16-bit PCM currently

Change-Id: I5df0e5033da9144ca73e44addf14a63d31406034
/frameworks/av/media/libmedia/AudioRecord.cpp
86f04663032ddaa25110149d709bbf896ad83b02 25-Feb-2014 Glenn Kasten <gkasten@google.com> Add log at entry to set() in AudioTrack and AudioRecord

Change-Id: Ife23b88474c1d62c0cf682c1a310d951f2c0f54a
/frameworks/av/media/libmedia/AudioRecord.cpp
6dd62fb91d82dedcfa3ab38c02eb0940b4ba932a 06-Dec-2013 Glenn Kasten <gkasten@google.com> Multi-client recording

Supports multiple clients both at native sample rate and with resampling.

Change-Id: Icea55b4fd30751761b7debaa3ce016c79e712d8d
/frameworks/av/media/libmedia/AudioRecord.cpp
d457c970c8d08519cd77280a90b61ae1e342cfe3 11-Feb-2014 Marco Nelissen <marcone@google.com> Track pid for each session

so they can be properly freed.

Change-Id: I6f389035bc29e74e7c367c1c6d0252b180f666b3
/frameworks/av/media/libmedia/AudioRecord.cpp
cac3daa6332bf6d1f7d26adc4a9915f3d7992dd9 07-Feb-2014 Glenn Kasten <gkasten@google.com> Use printf format %#x for audio_format_t in logs

Change-Id: I1c611d1037685d52ccc84efe0fccd6413ec938e9
/frameworks/av/media/libmedia/AudioRecord.cpp
b3b2e23fcf7e050710d23b82a6682c0f3d869b69 05-Feb-2014 Glenn Kasten <gkasten@google.com> Add AudioRecord::mReqFrameCount similar to AudioTrack

Change-Id: I62d6534a9581e84ae20c2422f7ad9aeda9b7c4df
/frameworks/av/media/libmedia/AudioRecord.cpp
0f11b51a57bc9062c4fe8af73747319cedabc5d6 01-Feb-2014 Glenn Kasten <gkasten@google.com> Fix unused parameter warnings in audio

Change-Id: I665ba3358dd9502f0adec70d486e7bf8a2e1b0fe
/frameworks/av/media/libmedia/AudioRecord.cpp
df576995a5aad3428aeeef765387d650945c161d 28-Jan-2014 Eric Laurent <elaurent@google.com> AudioTrack: fix obtainBuffer timeout calculation

AudioTrack::obtainBuffer() passes a pointer to a timeout
variable that has gone out of scope when calling
ClientProxy::obtainBuffer().

Same fix for AudioRecord.

Bug: 11968591.
Change-Id: I22af8f94fa2f8cc54ab5c25c89167c805e754317
/frameworks/av/media/libmedia/AudioRecord.cpp
38e905b3cbba4da443d799b16999989781afc6d8 13-Jan-2014 Glenn Kasten <gkasten@google.com> Refactor code related to I/O handles to reduce chance for leaks

The AudioRecord input handle code was refactored earlier
to fix a potential handle leak, and to simplify the code:
> Change-Id: I124dce344b1d11c2dd66ca5e2c9aec0c52c230e2

This changelist refactors AudioTrack similarly,
and adds further cleanup of both AudioTrack and AudioRecord.

We attempt to implement the rules for referencing counting I/O handles,
but there is still the possibility of a handle leak if the client process
dies after allocating the handle reference but before releasing it.
That issue is being tracked separately.

Details:
- AudioSystem::getOutput() is now called within createTrack_l
- restoreTrack_l was missing offload info
now it has the info available,
but is not yet being called for offloaded tracks
- AudioTrack::getOutput() is now const
- Remove getOutput_l()

Change-Id: I44a0a623d24fc5847bcac0939c276400568adbca
/frameworks/av/media/libmedia/AudioRecord.cpp
f0002d142e6d24c5438600b2c259679de710f8ac 24-Jan-2014 Glenn Kasten <gkasten@google.com> Merge "Replace control block frameCount_ by explicit in/out parameter"
3a0b6bd22aa32daa729b05c33896400807027eee 17-Jan-2014 Glenn Kasten <gkasten@google.com> Merge "Use uint32_t sequence numbers for IAudioRecord"
269a7e210949c4b28ba84dc71b9f99f6ef14f94e 17-Jan-2014 Glenn Kasten <gkasten@google.com> Merge "Cleanup loop termination logic in AudioRecord::obtainBuffer()"
6d88aaf9cd810d96a4888dff8bd33d44cd01ccaa 17-Jan-2014 Glenn Kasten <gkasten@google.com> Merge "AudioRecord: fix unwanted overrun when restarting"
6a507298357c9ff869b97db57a890e58bd6bdec0 17-Jan-2014 Glenn Kasten <gkasten@google.com> Merge "AudioRecord::getInputFramesLost() cleanup"
32a7e0a5f7b000951b9adb80b17796f35b024816 17-Jan-2014 Glenn Kasten <gkasten@google.com> Merge "Unify comments between AudioTrack and AudioRecord"
5e1f79baa5c7355effbd2c9183787d6604487908 15-Jan-2014 Glenn Kasten <gkasten@google.com> AudioRecord: fix unwanted overrun when restarting

Apply the same fix to AudioRecord as this CL did for AudioTrack:
> Change-Id: Id703f8dc092a6f07c905eee194054b4a978f979d

Details:
When restarting an AudioRecord from stopped state, it is necessary
to force refresh of mRemainingFrames by processAudioBuffer() as
the last read before stop() could be partial. No doing so will lead
into unnecessary sleep before filling the non contiguous part
of the buffer returned by obtainBuffer() when processAudioBuffer()
is executed for the first time after start().

Change-Id: I0ff04648e990e97bad5ea3db5be0c4151250d5e1
/frameworks/av/media/libmedia/AudioRecord.cpp
d8a9d0220e84ae0b5049385aa9b1a0d8ea02b5bb 15-Jan-2014 Glenn Kasten <gkasten@google.com> Cleanup loop termination logic in AudioRecord::obtainBuffer()

Apply the same change to AudioRecord, that was already done for AudioTrack in this CL:
> Change-Id: I0fc48117946364cb255afd653195498891f622bd

If the proxy->obtainBuffer at the end of the "do" loop fails with status
DEAD_OBJECT, and the restoreRecord_l during the next trip of the "do"
loop also fails, then the value of the buffer fields will be based on
the previous proxy->obtainBuffer that returned DEAD_OBJECT. This will
have cleared the buffer, but it's tricky. So instead explicitly clear
the buffer after restoreRecord_l, before breaking out of the loop.

Change-Id: Ifc97f2ab7b8195d6b149502bb5d765d2983b07be
/frameworks/av/media/libmedia/AudioRecord.cpp
8ff50e7526d24aca11713006933b8dcb64ef6be9 15-Jan-2014 Glenn Kasten <gkasten@google.com> Use uint32_t sequence numbers for IAudioRecord

This makes it the same as for IAudioTrack.

Previously we had a mix of int, int32_t and uint32_t,
which could cause comparisons to fail.

Change-Id: Ic72ef650ee81f65db11e42ed16d818fdf3e310f4
/frameworks/av/media/libmedia/AudioRecord.cpp
5f972c031d4061f4f037c9fda1ea4bd9b6a756cd 13-Jan-2014 Glenn Kasten <gkasten@google.com> AudioRecord::getInputFramesLost() cleanup

Fixed bug that if the binder call failed (for example if the
IAudioFlinger binder is dead), then getInputFramesLost was returning
garbage. Now it correctly returns zero, which is the error value for
this method.

The type declarations for getInputFramesLost were inconsistent:
a mixture of unsigned int, size_t, and uint32_t. Now it returns uint32_t
everywhere, which is what the underlying HAL API returns.

Added a FIXME about the side effect behavior. This will need review
for multi-client.

Change-Id: Ifa2e117a87dbd0c1f2c892a31d1c3dd919bf1a0a
/frameworks/av/media/libmedia/AudioRecord.cpp
5b27ccd67c845aa20a12a1fb58339e7e81e3d536 15-Jan-2014 Glenn Kasten <gkasten@google.com> Merge "Use AUDIO_SESSION_ALLOCATE instead of 0"
2b2165c75790050810460c8de3f414876bce4c0e 13-Jan-2014 Glenn Kasten <gkasten@google.com> Unify comments between AudioTrack and AudioRecord

Change-Id: I00a1025e2891a1c96218b3c2187eaddda6614ebc
/frameworks/av/media/libmedia/AudioRecord.cpp
41721bb796da589f8a669d1db7687a0da8f88761 13-Jan-2014 Glenn Kasten <gkasten@google.com> Fix race condition in AudioRecord::pause followed by start

Bug: 11148722
Change-Id: Ia1e14133d73ac301fe06a047e70a573911822630
/frameworks/av/media/libmedia/AudioRecord.cpp
aea7ea06394bcb155972d82055d4ea59962e4051 26-Jun-2013 Glenn Kasten <gkasten@google.com> Use AUDIO_SESSION_ALLOCATE instead of 0

Also fix a couple of places where we were using AUDIO_SESSION_OUTPUT_MIX,
which happens to also be equal to 0, but has a different meaning.

Change-Id: I90e39be3b89f5021a96d9e3b8d10929013ca977f
/frameworks/av/media/libmedia/AudioRecord.cpp
74935e44734c1ec235c2b6677db3e0dbefa5ddb8 19-Dec-2013 Glenn Kasten <gkasten@google.com> Replace control block frameCount_ by explicit in/out parameter

in IAudioFlinger::createTrack and IAudioFlinger::openRecord

Change-Id: I09c644c80e92c8e744b1b99055988a2588b2a83d
/frameworks/av/media/libmedia/AudioRecord.cpp
7c7be1e05634d96d08210efb4bdeb012ffba440d 20-Dec-2013 Glenn Kasten <gkasten@google.com> Fix some (but not all) unused parameter warnings

Change-Id: Ia99e23a0b46db3f3e6aa46f9018e63c14f4af369
/frameworks/av/media/libmedia/AudioRecord.cpp
e93cf2ca27ae6f4a81d4ef548bbf10a34db6d98f 24-Sep-2013 Glenn Kasten <gkasten@google.com> Cleanup openRecord error handling

Bug: 10888816
Change-Id: I84897dd7d30b370640b54e928f230604b873cb68
/frameworks/av/media/libmedia/AudioRecord.cpp
9d2c78c4798ffd8c276c1bf0eaa0b34bc255a2da 23-Sep-2013 Eric Laurent <elaurent@google.com> AudioTrack: fix music resume

Fix regression introduced by commit 5a6cd22 in AudioTrack resume:
the callback thread was not signaled if paused internaly.

Bug: 10895013.
Change-Id: Ic356b115132d6fccbcee2d9bb855e92671dc20c5
/frameworks/av/media/libmedia/AudioRecord.cpp
5a6cd224d07c05b496b6aca050ce5ecf96f125af 20-Sep-2013 Glenn Kasten <gkasten@google.com> Fix slow AudioTrack and AudioRecord destruction

There were two causes for the slowness:

When thread was paused, it used nanosleep and sleep. These usually
run to completion (except for POSIX signal, which we avoid because it
is low-level). Instead, replace the nanosleep and sleep by condition
timed wait, as that can be made to return early by a condition signal.
Another advantage of condition timed wait is that a condition wait was
already being used at top of thread loop, so it is a simpler change.

The AudioRecord destructor was missing a proxy interrupt that was correct
in AudioTrack. This proxy interrupt is needed in case another thread
is blocked in proxy obtainBuffer.

Does not address the 1 second polling for NS_WHENEVER.

Bug: 10822765
Change-Id: Id665994551e87e4d7da9c7b015f424fd7a0b5560
/frameworks/av/media/libmedia/AudioRecord.cpp
ac0bbe16f3eba46b3d8057b66c2aff9101fc6f7d 10-Aug-2013 Jeff Brown <jeffbrown@google.com> Fix potential leak of audio input handle.

The audio input handle is ultimately owned by the audio recorder
object but it could be dropped on the floor if an error occurred
before that object was fully initialized.

Rearranged some of the argument validation and merged getInput_l
with openRecord_l to simplify the code and prevent such a leak
from occurring.

Bug: 10265163
Change-Id: I124dce344b1d11c2dd66ca5e2c9aec0c52c230e2
/frameworks/av/media/libmedia/AudioRecord.cpp
4a0efb77198c69df711ab369ac482a42dbdfab07 09-Aug-2013 Glenn Kasten <gkasten@google.com> Fix regression for AudioRecord streaming callback mode

The notification period (frequency of client wakeups) was broken in
streaming callback mode. Fast tracks were OK, but non-fast tracks with
normal latency weren't getting woken up at all.

Bug: 10222943
Change-Id: Ife9a2f57fa73c6eb921f1c5ba62de0bfcc20557b
/frameworks/av/media/libmedia/AudioRecord.cpp
230c5bde2779c618b26edc73443280b2d9371c70 06-Aug-2013 Glenn Kasten <gkasten@google.com> Merge "AudioRecord notification frames"
33f3177c08d238285b296d137e527ec99e34228f 06-Aug-2013 Glenn Kasten <gkasten@google.com> Merge "AudioRecord::openRecord_l use flags"
743649fa70392b668377fb507d251b346c7b2769 06-Aug-2013 Glenn Kasten <gkasten@google.com> Merge "AudioRecord::openRecord_l now take flags"
3aa03e40668dd90390d9f1702f8c576e15b366c3 06-Aug-2013 Glenn Kasten <gkasten@google.com> Merge "IAudioFlinger::openRecord track_flags_t flags is in/out"
77baebfe89c99415a0ee4c2ea87bfd8a0f9e51f1 05-Aug-2013 Glenn Kasten <gkasten@google.com> Merge "AudioRecord::set and constructor now take flags"
f86b18b1ce3cf20a39aea1fcaf90ec66f9d6d63e 05-Aug-2013 Glenn Kasten <gkasten@google.com> Merge "AudioRecord callback thread waits for priority boost"
6c104a4a245ea72b7bdf8c7c016121189045d4bc 05-Aug-2013 Glenn Kasten <gkasten@google.com> Merge "AudioRecord has no default sample rate"
7cd9cf70e36ad4b8eb12e24f9adbbe6fd69edebd 01-Aug-2013 Glenn Kasten <gkasten@google.com> AudioRecord notification frames

Change-Id: I76ec536d1504eb9a558178b62bf225aace4b40d1
/frameworks/av/media/libmedia/AudioRecord.cpp
3151427b6b0adf99929433715bab6f1e505100c1 01-Aug-2013 Glenn Kasten <gkasten@google.com> AudioRecord::openRecord_l use flags

Use the flags to determine input parameters for IAudioFlinger::openRecord.

Change-Id: I98d2726503af75c8830ce80ceaf3b94a755b342f
/frameworks/av/media/libmedia/AudioRecord.cpp
73493688f4190f790ee15d9ca54831cd64f4e195 01-Aug-2013 Glenn Kasten <gkasten@google.com> AudioRecord::openRecord_l now take flags

The new parameter 'flags' of type audio_input_flags_t will be used for
requesting a fast track, but is currently ignored.

Change-Id: If68dfda8b2d4eaaca42927d721b4630c47f71f3b
/frameworks/av/media/libmedia/AudioRecord.cpp
eeca32671896739e84050da5992d5f151a1629de 01-Aug-2013 Glenn Kasten <gkasten@google.com> IAudioFlinger::openRecord track_flags_t flags is in/out

This will allow AudioFlinger to tell client it is denying a request.

Change-Id: Iff2be3ad6636371bbda9c9899a283c94620c1f06
/frameworks/av/media/libmedia/AudioRecord.cpp
27f7b2a8fe899565487d8a326676a5f7d0a05a37 01-Aug-2013 Glenn Kasten <gkasten@google.com> AudioRecord::set and constructor now take flags

The new optional parameter 'flags' of type audio_input_flags_t will be
used for requesting a fast track.

Change-Id: Ia7e070cb57c833e608352da354fb30dc26df6918
/frameworks/av/media/libmedia/AudioRecord.cpp
28f1351369682801e1bb40a835bdae3c97b73c1c 31-Jul-2013 Glenn Kasten <gkasten@google.com> AudioRecord callback thread waits for priority boost

Change-Id: Iae38fa4ac20a45751566169213a08a15deb0a2f6
/frameworks/av/media/libmedia/AudioRecord.cpp
954315a10089fa3684ac94db5be77c6655c08fc0 02-Aug-2013 Glenn Kasten <gkasten@google.com> Recording of non-linear formats is not supported

Such formats are already rejected in AudioRecord::set()

Change-Id: I5ba1fd9e4cd659e5226c75aa4f63e52f655e0521
/frameworks/av/media/libmedia/AudioRecord.cpp
f0f33c4acd231fa95deb9eeef2c46b0129e64463 31-Jul-2013 Glenn Kasten <gkasten@google.com> AudioRecord has no default sample rate

Change-Id: I72feefdd6f3a623fd3669b80d4b264518fdc0929
/frameworks/av/media/libmedia/AudioRecord.cpp
96f60d8f04432a1ed503b3e24d5736d28c63c9a2 12-Jul-2013 Glenn Kasten <gkasten@google.com> Rename control block flags to mFlags

Change-Id: I7b6d31e24531954ab1ecdf3ed56c19433700bd89
/frameworks/av/media/libmedia/AudioRecord.cpp
291bb6d8947c5b0c062f0895d623c529259bfa39 17-Jul-2013 Glenn Kasten <gkasten@google.com> AudioRecord and HAL input stream must be 16-bit PCM only

Currently there are 16-bit PCM assumptions in several places for capture:
- resampler API
- mRsmpInBuffer and mRsmpOutBuffer
- RecordThread::threadLoop upmix, downmix, and resampling
- possibly other places

Until those assumptions are removed, this CL enforces 16-bit PCM in both
client and server at all places where a format is checked.

Change-Id: I08b0570bff626ad0d341804825a72c14e61b4233
/frameworks/av/media/libmedia/AudioRecord.cpp
1ab85ec401801ef9a9184650d0f5a1639b45eeb9 31-May-2013 Glenn Kasten <gkasten@google.com> Include what is needed

Remove old includes.
Header files only include other header files that they directly need themselves.

Change-Id: Ic471386808d9f42ea19ccbd59cb50a5f83a89dd0
/frameworks/av/media/libmedia/AudioRecord.cpp
9f80dd223d83d9bb9077fb6baee056cee4eaf7e5 19-Dec-2012 Glenn Kasten <gkasten@google.com> New control block for AudioTrack and AudioRecord

Main differences between old and new control block:
- removes the mutex, which was a potential source of priority inversion
- circular indices into shared buffer, which is now always a power-of-2 size

Change-Id: I4e9b7fa99858b488ac98a441fa70e31dbba1b865
/frameworks/av/media/libmedia/AudioRecord.cpp
7c027248e1a4ccd5b22bc4deafb03e2d87ac8f38 26-Dec-2012 Glenn Kasten <gkasten@google.com> Consistent whitespace

Change-Id: I118cce68d3b777f9ec9b6bfb70367496422a40f2
/frameworks/av/media/libmedia/AudioRecord.cpp
c9b2e20f7c9a71e07ef398152709c76079decbcd 26-Feb-2013 Glenn Kasten <gkasten@google.com> Miscellaneous cleanup

Abbreviation framesReady to fRdy for new systrace.
Put inline const on one line.
Use local copy of mState in state.
Improve logging.
Line length 100.

Change-Id: I8201c3ce0e53fd464fd33d02544e52c342d40b68
/frameworks/av/media/libmedia/AudioRecord.cpp
2e4664677d72ce54201d3fd0beb0e10280add93c 10-Jan-2013 Glenn Kasten <gkasten@google.com> Fix AudioRecord

Bug: 7965744
Change-Id: Ic024e7fb32f7459b8093c2cf6cd5752aade21ddb
/frameworks/av/media/libmedia/AudioRecord.cpp
a589764c3c0617c7a8996e929ce2d6db1cc01d77 05-Jan-2013 Glenn Kasten <gkasten@google.com> Fix bug in AudioRecord() constructor

It was calling set() with wrong parameter list.
This goes back to commit be916aa1267e2e6b1c148f51d11bcbbc79cb864c from 2010.

Change-Id: I2f6917765baf58260bf35e89a2cc59c199734ff6
/frameworks/av/media/libmedia/AudioRecord.cpp
d5681bc9a38fe4cd1d591e6ae62b9c68fb851041 22-Dec-2012 Glenn Kasten <gkasten@google.com> Merge "Start isolating control block accesses in a proxy"
49d24d3fcd01aef0ec1fa4abd9c1b85473f64c0f 21-Dec-2012 Glenn Kasten <gkasten@google.com> Merge "Remove unnecessary parameter"
8d6cc842e8d525405c68e57fdf3bc5da0b4d7e87 03-Feb-2012 Glenn Kasten <gkasten@google.com> Remove unnecessary parameter

Just get the parameter on server side

Change-Id: I433a63104dbb257e0d862be2ab61847cb36d1c15
/frameworks/av/media/libmedia/AudioRecord.cpp
89b629b398e87095cf262692f4e476d605fe87ed 17-Dec-2012 Glenn Kasten <gkasten@google.com> Fix bug with discarded AudioRecord::read count

Formerly, if an AudioRecord::read() got a timeout on obtainBuffer()
after already successfully transferring some data, then it returned zero.
This had the effect of discarding a partial transfer, which resulted in
a gap in the audio data delivered to the app. Now if a timeout occurs
after a partial transfer, it returns that partial transfer count so that
no data is lost.

Change-Id: I0d9c2f4e495a400b56ef916a06613ba26537ca97
/frameworks/av/media/libmedia/AudioRecord.cpp
e3aa659e9cee7df5c12a80d285cc29ab3b2cbb39 04-Dec-2012 Glenn Kasten <gkasten@google.com> Start isolating control block accesses in a proxy

The proxy object will eventually be the only code that understands the
details of the control block. This should make it easier to change the
control block in the future.

Initial set of control block fields that are isolated:
- sample rate
- send level
- volume

Prepare for streaming/static separation by adding a union to the control
block for the new fields.

Fix bug in handling of max sample rate on a track. It was only checking
at re-configuration, not at each mix.

Simplify OutputTrack::obtainBuffer.

Change-Id: I2249f9d04f73a911a922ad1d7f6197292c74cd92
/frameworks/av/media/libmedia/AudioRecord.cpp
a42ff007a17d63df22c60dd5e5fd811ee45ca1b3 14-Nov-2012 Glenn Kasten <gkasten@google.com> Clean up channel count and channel mask

Channel count is uint32_t.
Remove redundant mask parameter to AudioTrack::createTrack_l()
and AudioRecord::openRecord_l().

Change-Id: I5dc2b18eb609b2c0dc3091994cbaa4628062c17f
/frameworks/av/media/libmedia/AudioRecord.cpp
aa25c0321bd4b9eb46a4d1cb4ac5fa47af30eeb4 17-Nov-2012 Glenn Kasten <gkasten@google.com> Merge ""if" statements use curly braces per media style"
b603744e96b07b1d5bf745bde593fb2c025cefcf 14-Nov-2012 Glenn Kasten <gkasten@google.com> Don't use control block frame count after create

This is part of a series to clean up the control block.

Change-Id: I7f4cb05aef63053f8e2ab05b286d302260ef4758
/frameworks/av/media/libmedia/AudioRecord.cpp
d65d73c4ae74d084751b417615a78cbe7a51372a 23-Jun-2012 Glenn Kasten <gkasten@google.com> "if" statements use curly braces per media style

Change-Id: I130e7849fd1da7a0b7fe56c3c53919d26e3843b8
/frameworks/av/media/libmedia/AudioRecord.cpp
e33054eb968cbf8ccaee1b0ff0301403902deed6 14-Nov-2012 Glenn Kasten <gkasten@google.com> Use size_t for frame counts

Also fix typo: bufferCount should be frameCount.

Change-Id: Ibed539504db75ef99dc21c8ff1bf2987122063a5
/frameworks/av/media/libmedia/AudioRecord.cpp
3b16c766d1ae2cfd8487e8ffb2b23936fc0a8e17 14-Nov-2012 Glenn Kasten <gkasten@google.com> Use uint32_t for sample rate

Change-Id: Ie240b48fb54b08359f69ecd4e5f8bda3d15cbe80
/frameworks/av/media/libmedia/AudioRecord.cpp
b36a7a68af073b1e7fd5cad6aa2c52223fd30efd 13-Nov-2012 Glenn Kasten <gkasten@google.com> Simplify AudioRecord::restoreTrack_l()

Finish removing CBLK_RESTORING and CBLK_RESTORED from control block flags,
and remove constant RESTORE_TIMEOUT_MS.

Also minor cleanup:
- Cache mCblk in local variable cblk and make cblk allocatable in a register.
- Use "iMem" for sp<IMemory>.
- Add missing error log to AudioRecord; it was already in AudioTrack.

This is part of a series to clean up the control block.

Change-Id: Ia5f5ab4763c392bc06a45851b167ddaee29e3455
/frameworks/av/media/libmedia/AudioRecord.cpp
83a0382dc17364567667a4e6135db43f5bd92efc 12-Nov-2012 Glenn Kasten <gkasten@google.com> Move frame size out of the control block

This is part of a series to clean up the control block.

Change-Id: Ifab1c42ac0f8be704e571b292713cd2250d12a3f
/frameworks/av/media/libmedia/AudioRecord.cpp
b929e417853694e37aba1ef4399f188987b709d9 08-Nov-2012 Glenn Kasten <gkasten@google.com> Move buffers pointer out of the control block

This is part of a series to clean up the control block.

Change-Id: Ie474557db7cb360f2d9a0f11600a68f5a3d46f07
/frameworks/av/media/libmedia/AudioRecord.cpp
864585df53eb97c31e77b3ad7c0d89e4f9b42588 07-Nov-2012 Glenn Kasten <gkasten@google.com> Remove CBLK_DIRECTION from control block flags

This is part of a series to clean up the control block.

Change-Id: I0265fece3247356b585d4d48fbda6f37aea8a851
/frameworks/av/media/libmedia/AudioRecord.cpp
26ba972eafde73a26271ecf027a1d5988ce50eb8 22-Jun-2012 Glenn Kasten <gkasten@google.com> Removed unused fields in AudioRecord::Buffer

Change-Id: I89fc6d8f695b48516d956b0a9a4a43d408f369f9
/frameworks/av/media/libmedia/AudioRecord.cpp
9c5fdd83f9b9f49be35107971feb33528d60b945 05-Nov-2012 Glenn Kasten <gkasten@google.com> Simplify control block flag names

Use only one symbol per flag

Change-Id: Ia3582e2134abd60c896d11337face65383e79c7c
/frameworks/av/media/libmedia/AudioRecord.cpp
85ab62c4b433df3f1a9826bed1c9bec07a86c750 01-Nov-2012 Glenn Kasten <gkasten@google.com> Line length 100

Change-Id: Ib28fd7b9ce951a6933f006e7f8812ba617625530
/frameworks/av/media/libmedia/AudioRecord.cpp
6f744d75d3439f7984245e3c489cc7cf91cea41c 06-Sep-2012 Eric Laurent <elaurent@google.com> AudioRecord: Fix minimum frame count calculation.

AudioRecord::set() was calling getMinFrameCount() with
a channel count instead of a channel mask.

Change-Id: Iabace7686426430fd53deac0c71b0c36aa64171c
/frameworks/av/media/libmedia/AudioRecord.cpp
955e78180ac6111c54f50930b0c4c12395e86cf7 21-Feb-2012 Glenn Kasten <gkasten@google.com> AudioRecord locking

Fix race conditions for EVENT_MARKER and EVENT_NEW_POS callbacks.
Marker and new position update fields are protected by lock.

getSampleRate() doesn't need a lock because it reads from shared memory
control block.

Enforce that the parameter passed with EVENT_MARKER and EVENT_NEW_POS
cannot not be changed by the callback handler, and will not change during
the call by another thread.

Session ID should never change; log if it does.

Change-Id: Ia2c63cf1a71b10bb06c37981bd76437f83fffa91
/frameworks/av/media/libmedia/AudioRecord.cpp
d64cd233eef39430561c1e1df423336a199cc5d7 21-Feb-2012 Glenn Kasten <gkasten@google.com> AudioRecord::stop() return void

like AudioTrack::stop()

Change-Id: Iab62f4665151345f1ad5874c97a21d1a331f0154
/frameworks/av/media/libmedia/AudioRecord.cpp
68337edf595a0c345ba4b8adcd4f1e541a1d7eb7 12-Jul-2012 Glenn Kasten <gkasten@google.com> AudioRecord client threading cleanup

Rename ClientRecordThread to AudioRecordThread to be more similar to
AudioTrack naming.

Only create the thread once, and use resume() and pause() for start()
and stop(). This will allow us to have a known client callback thread
tid that we can pass to AudioFlinger before start().

mActive:
Made mActive a bool not int.
mActive is protected by mLock; volatile is meaningless.
Fixed a few places where mActive was accessed without a lock:
- stopped()
- processAudioBuffer()
These aren't used internally, so no need for _l() versions.

Change-Id: I4b8a5c90f3a22d3894b344564cb1c5aef4f1fda2
/frameworks/av/media/libmedia/AudioRecord.cpp
04cd0186305e2b59d23c9147787046c6662029cc 25-Jun-2012 Glenn Kasten <gkasten@google.com> getMinFrameCount error handling

Convention is for "get" APIs that directly return status_t and indirectly
return a value via a pointer, to return BAD_VALUE if the pointer is NULL.
Also indirectly return 0 for other errors.

Change-Id: I1599f20ecb26e9723f9fb384ffbf911ff3a2ce1c
/frameworks/av/media/libmedia/AudioRecord.cpp
1879fff068422852c1483dcf8365c2ff0e2fadfc 12-Jul-2012 Glenn Kasten <gkasten@google.com> Add tid parameter to IAudioFlinger::openRecord

Not yet implemented

Change-Id: I35523fb15ad71727ecc9f4bb870f07e4b7397dc4
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
20010053daabfa43fcfe781bbf004473b4c08538 22-Jun-2012 Glenn Kasten <gkasten@google.com> Remove acoustics from AudioSystem::getInput()

Change-Id: I29fb3ee5664c1f0ee0409c1bb2be087ecca637db
/frameworks/av/media/libmedia/AudioRecord.cpp
624a7fcb377f2a40109c16de5109ae8ea1f67a69 22-Jun-2012 Glenn Kasten <gkasten@google.com> Use audio_channel_mask_t in AudioRecord

Change-Id: I9e1b918b2635d961604a4a9d88eb1c7179a167a7
/frameworks/av/media/libmedia/AudioRecord.cpp
868a6a357018e5872e064b7a13a9b891e2078962 22-Jun-2012 Glenn Kasten <gkasten@google.com> Include what you use

Change-Id: I12ef9367d05dbe069c037b1b4acd6347a8cf3ece
/frameworks/av/media/libmedia/AudioRecord.cpp
f92eec53f886f43e4374a36195be55f2a7bbcf36 07-Mar-2012 Glenn Kasten <gkasten@google.com> Remove AudioRecord record_flags

Change-Id: I021ddcc1bcb63132a4597d13e3d09db2a5f2c628
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
3acbd053c842e76e1a40fc8a0bf62de87eebf00f 28-Feb-2012 Glenn Kasten <gkasten@google.com> Configure policy of mediaserver threads

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

b/6160363
Change-Id: I471815012c6a113ec2c4dd7676e8fa288a70bc76
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
679ab0b0792846a89162ce41c953819d70030112 07-Mar-2012 Glenn Kasten <gkasten@google.com> Use AudioRecord::record_flags consistently

Change-Id: I6f369a2b99eb515603bc7d5629a07db2b96783fe
/frameworks/av/media/libmedia/AudioRecord.cpp
e8286332f3817a8b7cc4cfd8f6450a3913533660 29-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Shorten thread names"
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
/frameworks/av/media/libmedia/AudioRecord.cpp
606ee61616efdba4696ae591ad10a4be33d8c946 25-Feb-2012 Glenn Kasten <gkasten@google.com> AudioRecord const methods

Change-Id: Ifae4fd7820b650aaca2b13c8658c292db1c46c0f
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
4f9b0c54011eb8fd2ccfb393c2dcd51cd07800e0 08-Feb-2012 Glenn Kasten <gkasten@google.com> Merge "Remove dead mutex in AudioTrack/AudioRecord thread"
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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
83bc7f3cf78b28a818417f40a4f0c00593993366 04-Jan-2012 Glenn Kasten <gkasten@google.com> libmedia new can't fail on Android

Change-Id: Ie79dd5abb8078b35474bf0f1b3a6ff994a3a3360
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
d1a243e41caffa8fd346907eed4625c9c47c1a86 27-Jul-2011 Eric Laurent <elaurent@google.com> AudioRecord: Fix getInput()

AudioRecord::getInput() was issuing a query to get a new input stream from
audio policy service instead of returning the cached input stream in AudioRecord.

Change-Id: Ice324b7c60bc0898149023797bcb56a72091b9d3
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
68cbeba4e21aa53f52fb99b74dfa1910af31a3eb 23-Jun-2011 Glenn Kasten <gkasten@google.com> Merge "Fix warnings for uninitialized local variables"
d0965dde97f2815ae0a15fe6b40946f8a741a81e 23-Jun-2011 Glenn Kasten <gkasten@google.com> Fix warnings for uninitialized local variables

Change-Id: Ic9b03b0fd215444e76c7b7bebb385f7831c557e0
/frameworks/av/media/libmedia/AudioRecord.cpp
671a636931295d9c33ffca74551a804479d01241 17-Jun-2011 Eric Laurent <elaurent@google.com> Added audio_bytes_per_sample() helper function

Change-Id: Ibfcd75c4c241a53d5f052c25ada091904991048a
/frameworks/av/media/libmedia/AudioRecord.cpp
c6854100cea4fcd0f20cb2ac8235c02d1849b3a1 02-Jun-2011 Glenn Kasten <gkasten@google.com> Remove unnecessary level of priority indirection

Change-Id: I942d43973c20a7ace8b0d3f78b4da97e45e996c6
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
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>
/frameworks/av/media/libmedia/AudioRecord.cpp
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>
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
15304d601cbf83be6519ca53e1a26b97d50d0192 22-Jun-2010 Chia-chi Yeh <chiachi@android.com> media: add AudioRecord::getMinFrameCount().

Change-Id: I952071ab10aa49aa96b727d157b68470d69fff3d
/frameworks/av/media/libmedia/AudioRecord.cpp
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.

-AudioMixer
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
/frameworks/av/media/libmedia/AudioRecord.cpp
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
/frameworks/av/media/libmedia/AudioRecord.cpp
88335b1a749fe0157547907a2ce6c9632f4d2592 03-Mar-2010 Eric Laurent <elaurent@google.com> Fix issue 2428563: Camera rendered inoperable by voice call interruption.

The problem is that AudioRecord never exits read() when a timeout occurs while trying
to get new PCM data from audio hardware input buffer: it just keeps waiting and retrying until stop() is called.
In the same time, opencore AndroidAudioInput::audin_thread_func() loop cannot be exited when stuck
in AudioRecord::read() because the iExitAudioThread flag can only be sampled when AudioRecord::read()
returns. We remain stuck with the audio input thread running.

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

Also modified Audioflinger::RecordThread() loop so that we attempt to recover from HAL read errors.
In case of read error, the input stream is forced to standby so that next read attempt does a
reconfiguration and restart of the audio input device.
/frameworks/av/media/libmedia/AudioRecord.cpp
05bca2fde53bfe3063d2a0a877f2b6bfdd6052cf 26-Feb-2010 Eric Laurent <elaurent@google.com> Issue 2071329: audio track is shorter than video track for video capture on sholes

Add API to retrieve number of frames dropped by audio input kernel driver.

Submitted on behalf of Masaki Sato <masaki.sato@motorola.com>
/frameworks/av/media/libmedia/AudioRecord.cpp
867d2f6ce668968e463eb86b856d21525f12fd67 26-Jan-2010 Mathias Agopian <mathias@google.com> Simplify the MemoryDealer implementation

At some point the implementation became complicated because of
SurfaceFlinger's special needs, since we are now relying on gralloc
we can go back to much simpler MemoryDealer.

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

Removed MemoryDealer flags (READ_ONLY, PAGE_ALIGNED)

Removed a lot of unneeded code.
/frameworks/av/media/libmedia/AudioRecord.cpp
148b266afe2ac92b5616c24e8d5160e6f9242f69 05-Dec-2009 Eric Laurent <elaurent@google.com> Fix issue 2304669: VoiceIME: starting and canceling voice IME yields persistent "error 8" state on future attempts and breaks voice search.

Fixed AudioFlinger::openInput() broken in change ddb78e7753be03937ad57ce7c3c842c52bdad65e
so that an invalid IO handle (0) is returned in case of failure.
Applied the same correction to openOutput().
Modified RecordThread start procedure so that a failure occuring during the first read from audio input stream is detected and causes
the record start to fail.
Modified RecordThread stop procedure to make sure that audio input stream fd is closed before we exit the stop function.

Fixed AudioRecord JAVA and JNI implementation to take status of native AudioRecord::start() into account
and not change mRecordingState to RECORDSTATE_RECORDING if start fails.
/frameworks/av/media/libmedia/AudioRecord.cpp
6100d2d60517ff33ed8eb35d0b7ea63cde0831c9 19-Nov-2009 Eric Laurent <elaurent@google.com> Issue 2265163: Audio still reported routed through earpiece on sholes

This is a second attempt to fix the audio routed to earpiece syndrom.
The root cause identified this time is the crash of an application having an active AudioTrack playing on the VOICE_CALL stream type.
When this happens, the AudioTrack destructor is not called and the audio policy manager is not notified of the track stop.
Results a situation where the VOICE_CALL stream is considered as always in use by audio policy manager which makes that audio is routed to earpiece.

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

The same modification is made for AudioRecord although no bug related to record has been reported yet.
Also fixed a potential problem if record stop is called while the record thread is exiting.
/frameworks/av/media/libmedia/AudioRecord.cpp
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.
/frameworks/av/media/libmedia/AudioRecord.cpp
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()
/frameworks/av/media/libmedia/AudioRecord.cpp
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.
/frameworks/av/media/libmedia/AudioRecord.cpp
95634c8b6ad5419e310a5196bcc37f5988ed82da 26-May-2009 Android (Google) Code Review <android-gerrit@google.com> am de8268d6: Merge change 2331 into donut

Merge commit 'de8268d6d1cd168510c490b17e93154d2eab767c'

* commit 'de8268d6d1cd168510c490b17e93154d2eab767c':
Fix issue 1846343 - part 1
f5879c1448cc6aebc51b26d3ec2399d66144f8f4 22-May-2009 Eric Laurent <elaurent@google.com> Fix issue 1846343 - part 1

This change is the first part of a fix for issue 1846343, :
- Added new enum values for input sources in AudioRecord and MediaRecorder for voice uplink, downlink and uplink+downlink sources.
- renamed streamType to inputSource in all native functions handling audio record.

A second change is required in opencore author driver and android audio input to completely fix the issue.
/frameworks/av/media/libmedia/AudioRecord.cpp
7562408b2261d38415453378b6188f74fda99d88 20-May-2009 Mathias Agopian <mathias@google.com> move libbinder's header files under includes/binder
/frameworks/av/media/libmedia/AudioRecord.cpp
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

AudioFlinger:
- 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.

AudioSystem.java:
- correct typo in comment

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

AudioHardwareInterface:
- correct routeStrings[] table in AudioHardwareInteface.cpp
/frameworks/av/media/libmedia/AudioRecord.cpp
cd6725a333395ffeac3215ea4bf834a95aaa8def 25-Mar-2009 Eric Laurent <> Automated import from //branches/donutburger/...@142065,142065
/frameworks/av/media/libmedia/AudioRecord.cpp
7d563247cdac0509009d579bbf849157d47c38a9 25-Mar-2009 Jean-Michel Trivi <> Automated import from //branches/donutburger/...@141200,141200
/frameworks/av/media/libmedia/AudioRecord.cpp
89fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
/frameworks/av/media/libmedia/AudioRecord.cpp
15f767b960b38059a74a42a33e16d8df2aec8bc1 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
/frameworks/av/media/libmedia/AudioRecord.cpp
ad04d9201452001dbaac4349f084cc9316190b89 03-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@132589
/frameworks/av/media/libmedia/AudioRecord.cpp
99ffda877980468a9ae31e013cd10fb3645df1b0 03-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@137055
/frameworks/av/media/libmedia/AudioRecord.cpp
925a349b45d1d16eaaca6a1f4827191831271ca0 20-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@132569
/frameworks/av/media/libmedia/AudioRecord.cpp
7a2146d5807030b2629f347736be5301b61e8811 13-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@131421
/frameworks/av/media/libmedia/AudioRecord.cpp
5e07b5774c8b376776caa4f5b0a193767697e97e 11-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@130745
/frameworks/av/media/libmedia/AudioRecord.cpp
e5198b620a9a208ec59ea8457282404725f8ff6e 20-Jan-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@127101
/frameworks/av/media/libmedia/AudioRecord.cpp
7b5eb023f8d87cca6d830ae6c11c6aadbe02aca8 18-Dec-2008 The Android Open Source Project <initial-contribution@android.com> Code drop from //branches/cupcake/...@124589
/frameworks/av/media/libmedia/AudioRecord.cpp
2729ea9262ca60d93047e984739887cfc89e82eb 21-Oct-2008 The Android Open Source Project <initial-contribution@android.com> Initial Contribution
/frameworks/av/media/libmedia/AudioRecord.cpp