alsa_sound: 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
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: Usb headset support for VOIP call

 -When the USB headset is inserted after the VOIP call
 is initiated, TX voice is not heard. This is because
 initially the VOIPREC bit for usb headset is reset as
 the USb headset is not connected.But, even after the
 headset is connected this bit is not set.
 -Set the bit accordingly after the USB headset is connected

 CRs-Fixed: 525575

Change-Id: I81bf234cb6c8f97fb1f830fc8e32b9efad0716f9
alsa_sound: Configure the USB and PROXY device with proper sample rates

- For USB headset whose sample rate is other than the 8k/16k/48k
  which are supported by PROXY, ANR is observed while playback.
- getCap() function returning 0 sample rate if exact match of
  proxy supported rate is not found. This is causing device
  configuration failures in case of USB device, due to this
  playback thread closes the USB device and causes ANR.
- Fix is to configure the USB device with a sample rate supported
  by device and configure the PROXY at 48K.

CRs-Fixed: 521930
Change-Id: I8a51844d102f999618fa25f322d0ef17b38b826e
alsa_sound: Fix AV Sync in USB Playback by offsetting USB HAL latency

-There is delay in audio playback over USB causing AV Sync issues
-USB HAL latency added to USB Headset plaback

Change-Id: I28bf87b0bcb9c6227ef79fd9bf755e68489d4b7a
CRs-Fixed: 518470