frameworks/av: Add support for LPA and Tunnel Playback

-Add DirectTrack and DirectTrackClient
-DirectTrack enables client to create a direct
 output
-DirectTrackClient allows notifications to be sent to the
 client from DirectTrack.
-DirectTrack is being used for Low Power Audio
 playback and Tunnel Audio playback
Change-Id: I265ae1fa32c6fdd8be0382cc2b28605bc756a2f3
(cherry picked from commit b255c1963bb3af6f547b68d646737a7c92739555)
(cherry picked from commit 7cb21f77ae28f58da1cb8ba8f684b2968dcd4122)
(cherry picked from commit d4fa9e74c1ee1c2f7f7262c245da0b94dc0ac05b)
frameworks/av: port fixes in LPA and Tunnel mode playback

No History was maintained during porting. Updating the Description
and CR's of all the fixes.
Reference point: AU_LINUX_ANDROID_JB_MR1.04.02.02.049.366
LPA Mode:
LPAPlayer synchronization fixes.
Fixes for seek, pause/resume, EOS handling
Fixes for synchronization b/w the decoder thread, TimedEventQueue and player thread.
Convert mono to stereo for LPA clips - CRs-Fixed: 421639
Add support to change clip duration to enable LPA
Set correct device while creating effects - CRs-Fixed: 496866
Fix the LPA-AudioEffects dead lock issue - CRs-Fixed: 477511
fix volume not updated in pause state of direct track - CRs-Fixed: 490592
Tunnel Mode:
Use tunnel player only for music stream
Exceptions in using Tunnel mode decode - CRs-Fixed: 432080
Enable Tunnel Decode for select formats - CRs-Fixed:437651
Use software decoder for ADTS content. - CRs-fixed: 431096
Skip tunnel mode for playback through AudioCache - CRs-Fixed: 437539
Fix stability crash on tunnel playback. - CRs-Fixed: 498386
support multiple tunnel instances - CRs-Fixed: 483603
Fix ANR repeated next with tunnel clips on BT/AOA - CRs-Fixed: 482966
Update condition to ignore a seek request - CRs-Fixed: 461908
Return seek position until seek has been processed - CRs-Fixed: 454825
TunnelPlayer performance tweaks for audio video playback - CRs-Fixed: 444041
Stability fixes for Tunnel Player (part 2) - CRs-Fixed: 449122
Adjustment for TunnelPlayer buffer size - CRs-Fixed: 447274, 442365
Remove unnecessary code from TunnelPlayer - CRs-Fixed: 442365
update condition to send SEEK_COMPLETE - CRs-Fixed: 441411
Stop extractor source after start in TunnelPlayer - CRs-Fixed: 440239
Handling of EOS, and triggering EOS was wrong in TunnelPlayer.
EOS should not be posted till seek is complete
Disable tunnel mode playback for streaming use cases to avoid jittery playback
CRs-Fixed: 433346 432233 429868
APIs for returning correct timestamps were implemented
Check whether sink is open before flushing or closing it.
Check for mIsAudioRouted is good to know if we are closing it
Seekbar freezes after seek and pause
Check pause status before writing

Change-Id: Iea150f8d75aa9aa6d14da078695e920a3742dd81
(cherry picked from commit f7c9bafa439c5d52d945b966ba08cb16dfc34818)
(cherry picked from commit 68dee8112bbac7e0a70003175ed71b4e6a0376f4)
(cherry picked from commit 19c7fd3e330be551d477e8388b536294b1166a22)
frameworks/av: port fixes in LPA and Tunnel mode playback draft -2

 -LPAPlayer: Update condition to ignore seek CRs-Fixed: 453067
 -libstagefright: TunnelPlayer: update condition to send SEEK_COMPLETE
  CRs-Fixed: 441411
 -libstagefright: Fix ANR with rigorous rewind of 3gp LPA clips
  CRs-Fixed: 491077 490992
 -frameworks/av: Add  metadata mode changes to LPAPlayer
  CRs-Fixed: 458904 491077 490992

Change-Id: Ia89d7d6ac63b1267422a9138df9f98ef59b0ccb7
(cherry picked from commit 72f3bd4cddd3d93812692bffbfc19e2534477938)
(cherry picked from commit db6330d01d91d466d18c7714bd024a10fb009f57)
(cherry picked from commit 416e9ef0eed0ffa7b6e2c9d5a107d1ed2a94a624)
frameworks/av: port fixes in LPA effects

 -audio: fix for deadlock issue during LPA playback.
 -frameworks/av: Fix the LPA-AudioEffects dead lock issue CRs-Fixed: 477511
 -audioflinger: Fix pops in LPA while effects are applied CRs-Fixed: 526799
 -audioflinger: Fix delay in enabling effect for LPA CRs-Fixed: 525510

Change-Id: I92118b5cba17f5337608007052e7dc891d2d6b5b
(cherry picked from commit b24a38903f3fc2fd2bf7cc8fb71d50e1ff38162d)
(cherry picked from commit e8a1d6f80e64822d83f04f4f0704890644048189)
(cherry picked from commit 571f36890abe9f6b8bfe7341776cb5b3975bf952)
frameworks/av: Compile AudioParameter as shared library

- AudioParameter as shared lib is needed by BT,
  support in WFD source, SRS TruMedia

Change-Id: I30ee584ba7f45f5cafbdf07c45aa7429a84b1b49
(cherry picked from commit 30b89b3bfdafa2f3b877644400efbaefd6572f1e)
(cherry picked from commit 84c3b42f25a28d14426dba29276aae8c5ab795ce)
(cherry picked from commit 53c42631eeb1e13b786d9f4f616f38fe59690e4e)
audio : init rc to avoid effect's fault state

Effect command doesn't necessarily fill cmd return code into &cmdStatus,
so we should initialize cmdStatus to avoid uninitialized value propagates
to upper stack caller.

Change-Id: I2a2985e3010f0d7b8aedf9244a6faabdf05740ac
CRs-Fixed: 517766

Conflicts:
	services/audioflinger/Effects.cpp
(cherry picked from commit 708dd6e07fc363c76ee9d26a4bc6bb6d7cd3815e)
(cherry picked from commit 0f864db4f4c30c0f31a6998301dd4ec0098a5b24)
(cherry picked from commit 70047618259f68ce74349ed33edffd0ab5a467cc)
audio: Add pause support for hardware omx component

-ADSP doesn't enter sleep state after wma playback is paused
and power suspended.
-No support for NT session pause in case of hardware component.
NT session need to be paused to put ADSP into power collapse.
-Add support of pause in stagefright to ensure device enters
suspend mode. Also add intermediate states to avoid concurrency
issues between read and pause.

Change-Id: Ia0d77a3a0a344b8caad4f4d395641fd6a82f80b9
CRs-Fixed: 496256
(cherry picked from commit 369536f28349e7d1e3033c9d6205c692e32d0751)
(cherry picked from commit 1dcd1d7eba1d82c14961b05dab4e854ed2a979b3)
(cherry picked from commit 0a1b5cbced55d0718d96eccab9e2fe06aa68b199)
audio: Fix for race conditions in direct audio track

-Issue: Mediaserver crash is observed in direct track functions.
-Rootcause: Between write and flush functions, write and destructor
effectpool buffers are accessed without any synchronization that
might lead to operations on null buffers and cause crash.
-Fix: Use mEffectLock to synchronize access of effectpool buffers.

Change-Id: I5982e31fd6d292a9fe28dfee4cf75ebfe0ade5e6
CRs-Fixed: 515107
(cherry picked from commit b14c28f0d3b51ee989640aa46f3addcfabccb6be)
(cherry picked from commit 782f8512023facb1b655fb636bdcbd19af21b493)
(cherry picked from commit 1601287d6a06e11d782a821791bf1f5a9dcbd188)
audio: Fix to prevent deadlock in AudioEffects

-Write is blocked waiting for effect chain lock and this causes
decoder thread to wait indefintely.
-Sometimes it is observed that effectschain is locked before
mLPAEffectChain is initialized and but unlocking is skipped if
mLPAEffectChain is initialized in between.Due to this LPA
silence and framework reboot issues are observed as
applyEffectsOn() cannot acquire lock to progress further.
-Use flag to check if all effects have been locked and unlock
accordingly to prevent the deadlock scenario.
CRs-Fixed: 524759

Change-Id: I8ea0b1fc97de157b8254688b5471fd21bc9b565d
(cherry picked from commit 64dda9be5640f02c923cb7d5a08036ebb49ce86f)
(cherry picked from commit 9056fa50895243fbb1672eb117d60004757e7deb)
(cherry picked from commit b43e3b9859ddd90f512c80b637186f2a6e54a835)
audio: check for divide by zero possibilities

When output stream is not available to audioflinger
due to any reason, sampleRate and frameCount have
zero values when trying to create new Audiotrack.
This might result in divide by 0 situation.

Change-Id: If7fbcb6eb4cfcdba6d6bb3b4f758e46e4a57e37b
(cherry picked from commit d1576c1648a78354535fc9cd7130412f300864e5)
(cherry picked from commit 15b951bfcb2180f728669ab23ef0d6791fd790c2)
(cherry picked from commit c980dbea39f984a3c28e2694174e87b311e77308)
audio: Fix crash in flinger during monkey runs

The trackrefptr in DirectTrack descriptor can be invalid and
this can result in a crash is stability runs. Add check for
validity of the trackrefptr before accessing it

Change-Id: I4c7fbff022f381f9d2cdbf0fc04ade8defbb2195
(cherry picked from commit 66917496a28241bf38f117cb05b5810021a185a0)
(cherry picked from commit e1c916bb324f4f6f7923b8e4b2a9c436a65534ff)
(cherry picked from commit dc983d3efd2a5ec3435246d4d2a2e1b4265b5f22)
audio: Use High Quality resampler

Use very high quality resampler to upsample to 48KHz sample
rate.
CRs-fixed: 416730

Change-Id: I30420cbaa8f6d34e2bce408494cc08cb00b175a3
(cherry picked from commit 2904e01dd4a3921b7bc0bec71f63f4757204408b)
(cherry picked from commit 0302cfba74b948e5fb3b2adbcb9330b5dcc36595)
(cherry picked from commit 955a6569ab9d28fbfd6e1e234f06016fcbe5fb6b)
audioflinger: Fix monkey crash in audioflinger set parameter.

-Track ref ptr is initialized to direct track pointer only in create
 Direct Track although the descriptor is created in open Output
-If there is a set parameter coming in during this time it could
 result in a crash as track ref ptr is not initialized.
-Initialize track ref ptr to NULL when descriptor is created.

Change-Id: Iee887baee45a9e7b381f6e2ea2ab523a23689f6b
(cherry picked from commit 10d4ae79b727f7191484f3adda13f9bba9d62c09)
(cherry picked from commit 7d130a825ad58e44b04cce4a4e3f4e4919337a7b)
(cherry picked from commit 0b72bac19b8f8988e385b06ede234ca80e2e2e07)
audio: Do not apply effect on multichannel content

-Do not apply effect on multichannel content.
-Effects are applied only for mono or stereo.
CRs-Fixed: 484078

Change-Id: I623d40f926d5dd80e74f9aa2f98448158518047e
(cherry picked from commit b11bb5ec8184b0880a37b13033b22e255dbfccac)
(cherry picked from commit af7c6323538ad5b0e5a9f3efd2458cd44744c397)
(cherry picked from commit b984891aaade017a7fc9aad0c0d9f9398653cf71)
audioflinger:Set correct device while creating effects

 -Issue: Effectmodule is created with stale output device
  -Rootcause: While creating effects the output device set is
   output device of mixer thread, which is stale and
   not updated, so effects use the wrong/old device as
   the output device and leads to issue such as difference
   in volume level after setting correct device etc.
  -Fix: Cache the latest device value for direct track
   in a flinger member variable when setparameter of
   flinger is called with new device and
   audioflinger::openoutput is called.
   Use this cached value while creating effects

CRs-Fixed: 496866

Change-Id: I66f08b968c75e8a3b812aad7d91b20fd4557ba24
(cherry picked from commit 20d090b0a481722eede1ca01d38fddcd0977c633)
(cherry picked from commit b39d113f2bac7ca1df8ef144d81bdb28c32975d0)
(cherry picked from commit baf45ef7b6c12a1916d56ce37965de3d366b9f84)
frameworks/av: Initial bringup of voip and vocoders

-Add support for voip and vocoders.

Change-Id: Ibe6dfa100e564e057deebe1613cafd282ee2344e
(cherry picked from commit 96043bb0b5e93099bbbdd2a64c2b6039911c0ac3)
(cherry picked from commit 1682b8eb630c22b7ef0aa7a29746c6ce06118d95)
(cherry picked from commit bf72f4c502777df4703c345d1269057c57d11615)
audio: Fix a/v sync issue for playback over BT

-Audio and video are out of sync when a video is played/streamed
with a BT headset connected to the target.
-AudioTrack does not consider the BT latency.
-Latency of the BT stream added to the existing latency.

-query for tunnel mode latency
-During tunnel playback, we need to offset latency for audio plaback
 on BT devices by querying BT HAL.

Change-Id: I01a132687aec09cd2897039622daa35cff7ec409
(cherry picked from commit 9096501e28ecb56dc3a5a4d36d474b99804315cd)
(cherry picked from commit 29cb9299834d73a916b7a68617a32fb615c95d95)
(cherry picked from commit ca1f9dd47ca4299797e68029f3c260a5f291d3bd)
audio: AudioTrack constructor initialization

- Initialized few  member variables to null

Change-Id: I36fe9fd2f9e4c2b1967b8d9562ffcad635c6f686
(cherry picked from commit 673fd8919e310f3b2ecea082cfb9c2b08d00ad44)
(cherry picked from commit 75a64de910334e8cb12cfa0079910269e3f4e0e3)
audio: enable tunnel mode based on flags

- Enable tunnel mode playback based on flags defined
  in target board config file instead of checking
  target name.

Change-Id: I78c39b2653e7bae6a6eae8de36fbcacbeb1e6686

Conflicts:
	media/libstagefright/Android.mk
(cherry picked from commit 55a727f33978d374ffbdf612dd4a8560c3bffe3f)
(cherry picked from commit bb7234c9bb0505f3d6df998f84b9a062b206e097)
Revert "audio: add support for MSM audio formats"

This reverts commit b38e028676d93bbcc8e695b76bd6870113bdafd3.