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
alsa_sound: 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
alsa_sound: 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
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
  alsa_sound: Fix to cache call state properly

  If the client sets call states for multiple sessions
  before setting the MODE_IN_CALL then the session ID and
  call state in HAL will get overwritten with default
  values improperly. Fix is to cache the session ID and
  call state properly.

Change-Id: I51732c778d06b2ad27db2020d26f78ba8a540290
Merge "  alsa_sound: Fix to cache call state properly"
Merge "alsa_sound: Fix for AV Sync related issues"
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
Merge "alsa_sound: Fix mExtOutMutex related lock issue"
audio: fix for audio loss in VR/A2DP concurrency

- Issue: VoiceRecgonition notification sound is
  not heard and there is audio loss in A2DP
  playback in VR/A2DP concurrency test cases.
- Rootcause: wrong device and usecase are used
  in AudioHardwareALSA::doRouting, the last item
  of mDeviceList is used blindly which contains
  wrong device/usecase.
- Fix: Add usecase as another input param in
  doRouting, and find matching device/usecase
  in mDeviceList before routing.

Change-Id: I6b73c34907cccb660cc125665e211252ecb759df
CRs-Fixed: 534424
CRs-Fixed: 532122

Conflicts:
	legacy/alsa_sound/AudioHardwareALSA.cpp
Merge "alsa_sound: Add wifi display to fixed volume devices"
Merge "audio: fix for audio loss in VR/A2DP concurrency"
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 "alsa_sound: Fix a memory leak"
Merge "audio: fix for unhandled NULL pointer in HAL"
Merge "alsa_sound: Fix for unhandled NULL pointer"
audio: fix for unhandled NULL pointer in HAL

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

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

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

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

alsa_sound: Fix to cache call state properly

  If the client sets call states for multiple sessions
  before setting the MODE_IN_CALL then the session ID and
  call state in HAL will get overwritten with default
  values improperly. Fix is to cache the session ID and
  call state properly.

Change-Id: I51732c778d06b2ad27db2020d26f78ba8a540290

Merge "  alsa_sound: Fix to cache call state properly"

Merge "alsa_sound: Fix for AV Sync related issues"

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

Merge "alsa_sound: Fix mExtOutMutex related lock issue"

audio: fix for audio loss in VR/A2DP concurrency

- Issue: VoiceRecgonition notification sound is
  not heard and there is audio loss in A2DP
  playback in VR/A2DP concurrency test cases.
- Rootcause: wrong device and usecase are used
  in AudioHardwareALSA::doRouting, the last item
  of mDeviceList is used blindly which contains
  wrong device/usecase.
- Fix: Add usecase as another input param in
  doRouting, and find matching device/usecase
  in mDeviceList before routing.

Change-Id: I6b73c34907cccb660cc125665e211252ecb759df
CRs-Fixed: 534424
CRs-Fixed: 532122

Merge "alsa_sound: Add wifi display to fixed volume devices"

Merge "audio: fix for audio loss in VR/A2DP concurrency"

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 "alsa_sound: Fix a memory leak"

Merge "audio: fix for unhandled NULL pointer in HAL"

Merge "alsa_sound: Fix for unhandled NULL pointer"

Merge remote-tracking branch 'caf/jb_2.6' into merge_caf

Test Plan: untested, unbuilt, unconfirmed lol

Reviewers: synergy

Differential Revision: http://review.codefirex.com/D55
Fix formatting to fix compile in CFX environment