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)
Signed-off-by: cj360 <ayunker551@gmail.com>

Conflicts:
	services/audioflinger/AudioFlinger.cpp
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
Signed-off-by: cj360 <ayunker551@gmail.com>

Conflicts:
	services/audioflinger/Effects.cpp
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
added support for interlaced clip playback in LA.AF

Change-Id: I27bad0c6f7f1e02db3ad33afb2f4d27771322ef5