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 '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.
Change-Id: I576178144ffd753b809e1c4ae269ffc3aa34b511
related-to-bug: 2686604
QA-Impact: well, ..., everything related to streaming mpeg4/aac content over http
Merge commit '1d628c5d3dd7998b29c339292a2dc391015d0782' into kraken
* commit '1d628c5d3dd7998b29c339292a2dc391015d0782':
Accept media files by file extension in case insensitive manner.
This code generates warnings when compiled with -Wformat-security,
and since it isn't being used, I figured it's better
to just delete it. As always, this code can be restored
by reverting this change.
Change-Id: I1da2049f41312b6eae5fa42892beb4a2036eb12f
Merge commit '28fadef2ede2d74e9526266e779553bbd1dc66f4' into kraken
* commit '28fadef2ede2d74e9526266e779553bbd1dc66f4':
Return a runtime error instead of asserting if the AACDecoder is passed an unsupported config.
Merge commit '3c78a1b58957e31d2991fb6a609abecbb1987b3b' into froyo-plus-aosp
* commit '3c78a1b58957e31d2991fb6a609abecbb1987b3b':
Return a runtime error instead of asserting if the AACDecoder is passed an unsupported config.
Merge commit 'bbafdc6403488b0f7ad564a5a0ff2eed5b87ab7b' into kraken
* commit 'bbafdc6403488b0f7ad564a5a0ff2eed5b87ab7b':
Don't clear the _data column in the audio_meta table, since it isn't
Merge commit 'b003ad17bffeba7875b9708ffeef2300ef28c916' into kraken
* commit 'b003ad17bffeba7875b9708ffeef2300ef28c916':
Support for customizable socket-read timeouts through the HTTP response.
Merge commit '227e443a43d70b9463b2e685688f73cfb1b72096' into kraken
* commit '227e443a43d70b9463b2e685688f73cfb1b72096':
Better seek handling and proper reset of the vorbis decoder after a discontinuity (seek)
Merge commit '0c73adb1dead4097b9c7dc04b8a547aaab817e85' into kraken
* commit '0c73adb1dead4097b9c7dc04b8a547aaab817e85':
Update javadoc in android.media.AudioManager to not hide the
Merge commit '836b2d75ef86487ecae0ae834ecbab324fd99471' into froyo-plus-aosp
* commit '836b2d75ef86487ecae0ae834ecbab324fd99471':
Don't clear the _data column in the audio_meta table, since it isn't
Merge commit 'e0dc80f878b56ed744bd06d341716fcfff4e3acc' into froyo-plus-aosp
* commit 'e0dc80f878b56ed744bd06d341716fcfff4e3acc':
Support for customizable socket-read timeouts through the HTTP response.
Merge commit 'd6ad7c85faf55fa8d0459f0fbc4fa32abdfefb6e' into froyo-plus-aosp
* commit 'd6ad7c85faf55fa8d0459f0fbc4fa32abdfefb6e':
Better seek handling and proper reset of the vorbis decoder after a discontinuity (seek)
Merge commit '3e90c76c12803cd1b116030fd124b7b870d25342' into froyo-plus-aosp
* commit '3e90c76c12803cd1b116030fd124b7b870d25342':
Update javadoc in android.media.AudioManager to not hide the
Specify a response header of "X-SocketTimeout: 15" to override the default timeout
of 5 secs with a timeout of 15 seconds. Specify a negative value to disable the
timeout altogether.
Change-Id: I545adf3d8b3f7efe5f8d081a641c6404440a77db
related-to-bug: 2675721
When the user selects a "Silent" notification sound, the Uri encoded
path is an empty string. Setting this Uri as the data source of the
MediaPlayer used to play notifications caused the completion listener
to not be called, which with the AudioFocus logic causes the Music
app to pause and never resume. The NotificationPlayer modifications
cause the MediaPlayer for the notification to only request audio
focus when the data source is not empty.
The audio focus code in AudioService is defensively synchronized
against a unique lock, and the exception observed in bug 2670395
is explicitely caught in case another edge case wasn't caught by
this fix.
The AudioFocus handling in AudioManager is modified so only the
requestAudioFocus and abandonAudioFocus methods are meant to be
used, as registerAudioFocusListener and unregisterAudioFocusListener
provided no additional functionality over the request/abandon
methods. abandonAudioFocus() also removes the listener from the
map in AudioManager since after abandonning focus, the listener
would no longer be called.
Change-Id: I3b553ee8a8163c25e01117d7e5479dd5fdfa7c6b
Merge commit '1707851090e6512a77247b0c260dd673ef687589' into kraken
* commit '1707851090e6512a77247b0c260dd673ef687589':
A new OggExtractor/VorbisDecoder combo to support approximate seeking.
Merge commit 'd13efb20089e44e6958cb9704864c03821f19e1c' into froyo-plus-aosp
* commit 'd13efb20089e44e6958cb9704864c03821f19e1c':
A new OggExtractor/VorbisDecoder combo to support approximate seeking.
- Potentially much shorter stts box if samples have roughly the same duration
- Potentially much shorter stsz box if all samples have the same size
Change-Id: I4f7663dd64285070995585a02bb3ba1e1049a0cf