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
Merge commit 'c7388e3541c9f1d64dd13fc2de49ff77d8993fa5' into kraken
* commit 'c7388e3541c9f1d64dd13fc2de49ff77d8993fa5':
Make the SSID field of WifiConfiguration consistent with API description.
Merge commit '5f1beda18fc7709c2e61ace33607513770faf115' into froyo-plus-aosp
* commit '5f1beda18fc7709c2e61ace33607513770faf115':
Make the SSID field of WifiConfiguration consistent with API description.
Merge commit 'a5cd816c720ed87b91a33aa5d000a0d308c74453' into kraken
* commit 'a5cd816c720ed87b91a33aa5d000a0d308c74453':
Fix sampleTable instantiation, this makes sure that the sample table refers to the custom datasource that caches the metadata to prevent needless seeking.
Merge commit 'eb9128f9b0ee660504621381fd96f82d5bf8a3fd' into froyo-plus-aosp
* commit 'eb9128f9b0ee660504621381fd96f82d5bf8a3fd':
Fix sampleTable instantiation, this makes sure that the sample table refers to the custom datasource that caches the metadata to prevent needless seeking.
Merge commit '900b6157f5dee2ed7b2c73cf320b2baf293230ff' into kraken
* commit '900b6157f5dee2ed7b2c73cf320b2baf293230ff':
Only hold a weak pointer on SurfaceComposerClients
Merge commit 'fb580943133d3e9ad3e342b8038726b04686f283' into kraken
* commit 'fb580943133d3e9ad3e342b8038726b04686f283':
docs: fix broken link, reduce API info about backup and point to dev guide
Merge commit '826c9f7773188c2a7f48d5b2d1ae4612ec2bbb49' into froyo-plus-aosp
* commit '826c9f7773188c2a7f48d5b2d1ae4612ec2bbb49':
docs: fix broken link, reduce API info about backup and point to dev guide
Merge commit '55b7d1243f15395a102971e8fdc57444638729ac' into kraken
* commit '55b7d1243f15395a102971e8fdc57444638729ac':
SetLocaleByCarrier, only if its not an unknown carrier.
Merge commit '3d52305faa682366eb34c30892ddd2b390940048' into kraken
* commit '3d52305faa682366eb34c30892ddd2b390940048':
Doc change: adjustments to the api changes description
Merge commit '59cfe7137ca411bdbb5ffcdf418eecc55d65d09e' into froyo-plus-aosp
* commit '59cfe7137ca411bdbb5ffcdf418eecc55d65d09e':
Doc change: adjustments to the api changes description
Merge commit '6d8e4fd83bb7f4eabc942dd17fa229cf9baf5fcf' into kraken
* commit '6d8e4fd83bb7f4eabc942dd17fa229cf9baf5fcf':
docs: add dev guide for backup
Merge commit 'b83a283ac178ab0a72f1d811189d79b26097835e' into froyo-plus-aosp
* commit 'b83a283ac178ab0a72f1d811189d79b26097835e':
docs: add dev guide for backup
Merge commit '1d628c5d3dd7998b29c339292a2dc391015d0782' into kraken
* commit '1d628c5d3dd7998b29c339292a2dc391015d0782':
Accept media files by file extension in case insensitive manner.
Merge commit '9167ba50e4d7e08e02119d9c4a0f0392296cc3f1' into kraken
* commit '9167ba50e4d7e08e02119d9c4a0f0392296cc3f1':
Corrected debug message in WindowManager
Put the wifi status icon in the right place.
Some variables and structure members should be renamed to reflect the fact that they contain the
number of channels in a track (channel count) or the actual channels used by a track (channel mask).
Especially member "channels" of track control block (struct audio_track_cblk_t) is actually the
number of channels (channels count).
Change-Id: I220c8dede9fc00c8a5693389e790073b6ed307b8