audio: Squashed commit of LPA and Tunnel feature from CAF

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: Iddaaa557c4d6cb2e44903b6eaeba35cb9315194d

frameworks/av: 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: I25a5431b659d9d07ed2791d90ec341ff26bd191f

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: I55687403b8ee77f4c04eeba63538fa5c3d6d43ed

frameworks/av: Fix the LPA-AudioEffects dead lock issue

- Issue:Deadlock occurs when the LPA clips are subjected to
  rapid next from BT device and simultaneously on/off the
  audio effects.
- Rootcause:some times flinger thread processing
  LPAPlayer/directtrack next deadlocks with the thread
  working on effect configuration as both of them
  contend for the audioflinger::mlock and effectmodule::mlock.
- Fix1:AudioFlinger::deleteEffectSession() not to acquire
  audioflinger:mLock  instead take the mLPAEffectChain.mlock.
- Fix2:ThreadBase::effectConfigChanged() not to acquire
  audioflinger::mlock.
CRs-Fixed: 477511

Change-Id: Ia0e6d72f467afce6de5e66c6cd6edbe0759d271b

audioflinger: 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

audioflinger: Support SRS Trumedia effects

Add support for SRS Trumedia post processing effects

Change-Id: I6718b0c90a199d53fe971a8a7c089e63b649c112

frameworks/av: Enable subsystem restart for LPA/Tunnel

-Audio Daemon in Audio HAL intimates AudioFlinger
 of ADSP status (online/offline) using set_paramaters.
-AudioFlinger send set_parameters to its clients
 which is DirectTrack used for LPA/Tunnel playback.
-In case of ADSP crash during LPA/Tunnel playback,
 clean up of DirectTrack is initiated.

Change-Id: If83102ddde1da880fb769d86a20884185c049bca

libstagefright: Create MP3 decoder libraries without OMX layer

- With the current MP3 OMX SW decoders, the decoding time
is increased w.r.t the libraries without OMX layer that are
present in GB. This increase in decoding time results reduction in
power savings in LPA mode.
- This commit is to remove OMX layer for MP3 to reduce the
power consumption in LPA mode

Change-Id: Ie194b11619de9ba43cd85dddbf7892239858945d

frameworks/av: Add metadata mode changes to LPAPlayer

-Seek to EOS was causing playback to hang for 3 seconds before
 switching to the next clip.
-This is because the lpa driver works on period size. Partial
 buffers are not handled.
 Add support for metadata mode changes to LPAPlayer to support
 partial frames.

CRs-Fixed: 458904 491077 490992
Change-Id: I8673756b54ae7bca18855d326c85ae1064652514

Conflicts:
	media/libstagefright/LPAPlayerALSA.cpp

frameworks/av: audiotrack state check during flush

-Audiotrack flush should be handled only on
 pause/stop state for non LPA/Tunnel playback
 as per AOSP

Change-Id: I112d71a465424dc81fc3acb9423f63cb9f84c2d7

AudioFlinger: SRS effect signal in case of Tunnel

send SRS effect signal to Direct Audio Track for tunnel
decoding
CRs-Fixed: 500015

Change-Id: I43d7296d0956c3b918681b9939c3f6a98b9a143a

libstagefright: TunnelPlayer: update condition to send SEEK_COMPLETE

- If the client tries to seek to 0 (e.g as a result of LOOPING)
  without ever calling getPosition(), we will always sent an
  immediate seek notification without seeking.
CRs-Fixed: 441411

Change-Id: I35b059448784324149890636933fdf9d536b2bb8

audioflinger:Set correct device while creating effects

Change-Id: Id2c96c1f1fe4cdfc2795c86caa050f31f15e7f8d
  -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

libstagefright: Fix ANR with rigorous rewind of 3gp LPA clips.

-ANR is seen with rigorous rewind of 3gp LPA clips.
-The lpa destructor waits for decoder thread to be killed when
 the thread function has not got the time-slice to execute after
 creation.
-Use mLock instead of extractor mutex. use mLock before signalling
 the thread to avoid indefinite wait.
CRs-Fixed: 491077 490992

Change-Id: Icf2ae64a379ff2b1260d34dd0e5c45f07f429718

Frameworks/av: 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.

(cherry picked from commit 011db22abf565dfbe7f9d0a5c7af7564587b3b48)
CRs-Fixed: 435661, 435664, 435680, 430309

Change-Id: I9e3e0a77ea64ef8c5afbe5a18ee583803a96c99d

audio: Compile AudioParameter as shared library

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

Change-Id: I8d78740ee0df456c8a305511d9335c228c9be3b0

audio: define QCOM audio parameters

- Define QCOM audio paramters for FM, VOIP,
  fluence, SSR, and etc.

Change-Id: Id708c22f7ebe96f1831095447560ff9376c73878