frameworks/av: Define MSM Audio parameters

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

(cherry picked from commit 8e943f5bd88bda87f1aa9230487a69372ad49cf7)
(cherry picked from commit 85f4743d12c13aab39ac712a9005632f427c1c43)
(cherry picked from commit 333ba54561c59049f695b07479afe1d5ed734d31)

Conflicts:
	include/media/AudioParameter.h
	media/libmedia/AudioParameter.cpp

Change-Id: Ide9a634435232df0f823422266915f52b7c89a81
audio: Initial changes for LPA/Tunnel

Initial changes to enable Tunnel/LPA feature

Change-Id: Id3df3b9ad1a11a045be7280a080a0ac166fcdfc6
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.
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.
Changes Cherry picked from Iea150f8d75aa9aa6d14da078695e920a3742dd81

Change-Id: I8b968ddad235f6e1a36404f0c9c6eda7cae41419
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
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: Id3702bbeb0212cbe92370416b83daf0e383d6e3c
frameworks/av: Enable subsystem re-start 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: I87f720f305765e00e12032eed3e018aeff952390
(cherry picked from commit 02861e0f092c46640576bb8c700418ed82c266c3)
(cherry picked from commit 5abe97aa9e103420813b87e7abb2b676ffe8d097)
(cherry picked from commit 9a27f1e6c449585095e518f0d2f44e621ef18f52)
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: I8328a738f9d8f5a16b449f649d8a3d0c29f8f2ca
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: enable tunnel mode based on flags

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

(cherry picked from commit 55a727f33978d374ffbdf612dd4a8560c3bffe3f)
(cherry picked from commit bb7234c9bb0505f3d6df998f84b9a062b206e097)

Change-Id: I78c39b2653e7bae6a6eae8de36fbcacbeb1e6686
audio: Initialize LPA variables in audioflinger

 - During initialization of audioflinger, a number of
variables related to LPA are not set to default values.
This causes an undesired side effect that the first
effect in the effect chain is considered to be LPA
enabled. Since LPA does not execute effect processing,
switching xLoud on/off does nothing.
 - Fixed by initializing member variables in audioflinger.

Change-Id: Ide06fb0e6804558388e6610cc7686f168591e4a5
AudioFlinger.cpp - audioConfigChanged_l set for srs Tunnel Device Switch

 - During device switch we were only setting the route
   but was not calling audioConfigChanged_l
 - Hence the effects for the new device would apply only
   when there is a config change
 - Now we call audioConfigChanged_l during device switch
   setPrameter so that the new effects will be apply as
   soon as device is switched.

CRs-Fixed: 548021

Conflicts:
	services/audioflinger/AudioFlinger.cpp

Change-Id: I641cd8a7d6ffb7423ccfaa45e4c29b1b5352e61e
audioflinger: SRS effects are not working for LPA

    -Issue: If SRS effects are applied on LPA playback,
     in ARM side there is a delay of 4-5 seconds for effects
     application
    -Root cause: In applyEffects SRS effects are applied first and
     then Android effects are applied.
     In case of active android effects, SRS effects are called
     first and then android effects are called, so buffer with
     SRS effects is getting overwritten with buffer with
     android effects.
     If there are no android effects applied then all
     the SRS effects are overwritten with decoded data.
     So until next write call, SRS effects are not applied and hence delay
     of 4-5 seconds.
    -Fix: In applyEffects first apply android effects and then
     apply SRS effects

Change-Id: I36b2133256d168f06b13c3d4a2bad00312d571ac
CRs-Fixed: 566278
audio: Supress redundant effect config events in short duration

Distortion sound persists for the whole song when re-enabling effect in
LPA playback mode till switch to next song. And pop noise is quite obvious
when enable/disable effects in LPA.

As the design of LPA, EffectsThreadEntry() loop is used to handle effect
config changes through applying effects with new config on dsp pcm buffers.
However, it can't handle too many config change events in a short time,
and effect with new configuration will be applied on part of dsp buffers.

Filter out redundant effect config events that come too closely to avoid
applying effect on dsp buffer in vain.

CRs-Fixed: 562806, 563418

Change-Id: If8915b1d068724d5976e1519ec57e3c08cf89c9d
audioflinger: Add Null pointer check while enabling effects for LPA

- MediaServer is crashing when disabling effects after mediaplayer
object is released.
- EffectChain pointer is de-referenced without NULL check, hence
leading to a mediaserver crash.
- Adding a NULL pointer check before using EffectChain object.

CRs-Fixed: 583305

Change-Id: If5ff469445246028046ba65e5ddf3300180318c2
audio: Use composition instead of multiple inheritance

- AudioTrack is derived from BnDirectTrackClient along
  with RefBase to receive the notifications from
  AudioFlinger in tunnel/LPA mode. This is breaking
  binary compatibility for the clients which use native
  AudioTrack directly instead of Java based AudioTrack
  API
- Fix is to use composition here instead of inheritance

CRs-fixed: 607574

Change-Id: I9fd2c61cff5629924e3b08f63559679e0263bcfd
audio: Added lock during closing of direct output

- Lock is missing when direct output is closed in
  closeOutput_nonvirtual. As mDirectAudioTracks is
  being modified in this function, we need a lock
  here to avoid synchronization issues when it is
  accessed from other methods in AudioFlinger
- Fix is protect direct audio track specific block
  with mLock

CRs-fixed: 611654

Change-Id: I88f489c3bbe21ecb198bd836c05b0bfa5826d3c6
audio: Add parameters for ADSP and SSR

Add msm specific parameters for ADSP and SSR

Change-Id: I73b4577df973f1ea80c25d371577eaf53b552e7a
Signed-off-by: cj360 <ayunker551@gmail.com>

Conflicts:
	include/media/AudioParameter.h
	media/libmedia/AudioParameter.cpp
audio: Changes to fix LPA/Tunnel device switch

 Since the LPA/Tunnel solution doesnt have a playback thread,
 audio patch fails to apply and route to new device.
 Added changes to call routing for LPA/Tunnel scenarios.

Change-Id: If12af0f78f4ba7a0b90e32411f77a7ffed7e6880
audio: Changes to enable BT A2DP

 For Proxy thread to be started , a2dp state has to updated from
 the audiopolicy.
 Now , added changes to send the BT A2DP status to audio HAL.

Change-Id: I599de562a8674ee611e10575fcc85e4715707a63