audio: Fix mExtOutMutex related lock issue

-extoutThread was taken slightly longer than on MR1.
-On newer platform, It takes more time to write becausea2dp_write
is a blocking call and takes about 20 ms in every execution
-Because of this, the new stream that was coming in was not getting
the lock.
-To solve this, added a new lock that we acquire before write, and
this lock is taken only during A2DP disconnect since that is the only
case when we close the extoutput

Change-Id: I4ce0bcb17ba2e9fbd60aacd2315d92808509d150

Conflicts:

	legacy/alsa_sound/AudioHardwareALSA.cpp

Conflicts:
	legacy/alsa_sound/AudioHardwareALSA.cpp
audio: Fix for AV Sync related issues

-Fix buffer pointer mismatch in proxy
-There were glitches heard at times when listening
to music over Bluetooth
-The issue was due to slight scheduling delays. When proxy read
thread in the HAL wakes up, there might be more than one period
size worth of data in the proxy. This would result in the proxy
copying only one period but incrementing whatever is available and
subsequently leading to glitches.

-Increase extOutThread priority to URGENT_AUDIO to avoid
delays in proxy port read.

-query BT hal for audio latency for a2dpstream
-Set proper latency when audio is played on BT devices
by querying BT hal. This is needed for av sync over BT devices

-Calculate proxy port latency
-The latency of proxy port should be considered during playback
on these devices.

-Flush Proxy data at high water mark
-Delays in the system setup causes Proxy buffers to become very close
to full and leading to choppy audio, afterwards.
-Flush the data in the proxy whenever a limit [water mark] is
reached. The water mark is set to 40000 frames. This can, also, be
changed by modifying AFE_PROXY_HIGH_WATER_MARK_FRAME_COUNT

Change-Id: I55ffb93b16618d3e63fb93c66483286db058740f

Conflicts:
	legacy/alsa_sound/AudioHardwareALSA.cpp
alsa_sound: Add wifi display to fixed volume devices

Wifi display should be treated as device with fixed volume like HDMI.
User should not be able to change the volume on device. Volume
change should be supported only on the end device.

CRs-Fixed: 480334
Change-Id: I328cc9817fb0735fbfd67f14534cfad127026a44
  alsa_sound: Handle API sequence changes to setup
              voice path

  Earlier, setparameters() followed by setMode() is called
  from telephony to Audio HAL to setup voice path.
  Now, setParameters() API called by RIL instead of
  telephony.
  Make changes to handle the API sequence changes
  to setup voice path.

Change-Id: I12ed40662e06fb83f8b0e565d770fdcb77fdc853
Merge "audio: Fix mExtOutMutex related lock issue"
Merge "audio: Fix for AV Sync related issues"
Merge "alsa_sound: Add wifi display to fixed volume devices"
audio: Start proxy when external output is enabled

- Proxy thread is not getting started when BT Headset
  is connected in the middle of HDMI Music Playback
- startPlaybackOnExtOut_l is not getting called
  from doRouting in this case
- Fix is to call startPlaybackOnExtOut_l in all the
  usecases when the device is switched to external
  device

Change-Id: Iabbe63bc87db0d0cc9623d16a24825118efacd29
CRs-fixed: 520503
Merge "audio: Start proxy when external output is enabled"
Merge "  alsa_sound: Handle API sequence changes to setup               voice path"
alsa_sound: Fix for unhandled NULL pointer

-Passing NULL pointer to pcm_read()/pcm_write()/
 pcm_prepare() would crash, since it doesnt perform
 a NULL check before using the pointer, resulting
 in random crash
-Fix is to check whether handle is NULL or not.

Change-Id: I7061d40bddcaaae2145f5fc0a0229abeebead878
CRs-fixed: 549257
audio: fix for unhandled NULL pointer in HAL

- Check if handle is NULL before calling pcm_close
- Check if usecase is NULL before string comparison
  operations
- Disable unnecessary debug logs in HAL

Change-Id: I569cbf510c820e1a155abf3efb4bbb525e68aafb
audio: Fix for audio loss in FM and VR/A2DP concurrency

- Issue: VoiceRecgonition notification sound is
  not heard and there is audio loss in A2DP
  playback in VR/A2DP concurrency test cases.
  FM is not routing to BT when switched from
  Speaker.
- Rootcause: wrong device and usecase are used
  in AudioHardwareALSA::doRouting, the last item
  of mDeviceList is used blindly which contains
  wrong device/usecase.Audio HAL is overriding
  the active usecase based on the current output
  stream's usecase. But for FM an output stream
  won't be created. Hence Playback on BT is not
  started by audio HAL due to usecase mismatch.

- Fix: Add usecase as another input param in
  doRouting, and find matching device/usecase
  in mDeviceList before routing. Add check to
  avoid using output stream's usecase if FM is
  active.

Change-Id: Ic96373acba0ca94643f30040b5d9bf8cb87300c7
CRs-Fixed: 534424
CRs-Fixed: 532122
Remove AOSP reference to utils.mk

Remove function calls from AOSP code to utils.mk
& replace them with actual definition.

Change-Id: Ie0ae58e6eb4a4f54d58e15ac8f1d819dbdac5cd2
CRs-fixed: 566287
alsa_sound: Fix a memory leak

A pointer variable was not being freed up which is
causing memory leak.
This change is to fix the same.

Change-Id: I12728a4a75fb303d34d10657fe9cbc1b55c1687e
CRs-Fixed: 523572
Merge "audio: Fix for audio loss in FM and VR/A2DP concurrency"
Merge "Remove AOSP reference to utils.mk"
Merge "audio: fix for unhandled NULL pointer in HAL"
Merge "alsa_sound: Fix for unhandled NULL pointer"
audio: Choose Speaker instead of USB Headset on force use

- getNewDevice() is selecting USB Dock Headset when user
  forces it to be speaker during VOIP/VOICE call
- Fix is to return speaker as output device in this case
CRs-Fixed: 571801

Change-Id: I81cbcef17ac6d07ac0a174e4ab35c8f5c6426257