alsa_sound: fix a merge error which broke LPA functionality

Change-Id: Iccfdca5c81ca0f12a6cea9a1f78c34a1a1b14561
alsa_sound: Fix EOS - Seek issue.

Seeking to EOS in tunnel mode is causing no audio. This is because
zero length buffer is not handled properly.
Fix is to not send zer length buffer to driver if the queue is
already empty.

Change-Id: Ie598bc89e20e6c7c5a0d65b54ceeea6cade0087d
alsa_sound: Add miscellaneous fixes to AudioSessionOut.

- Remove reset from stop function. reset should be only called
  in the destructor as it closes all the threads and deallocates
  all the memory
- While iterating through the Device list, break out of the loop
  once the use case corresponding to the device is removed.

CRs-Fixed: 396029
Change-Id: Ifa449fc5aba93b3e88c52f55219110027e4a8684
(cherry picked from commit 991d9cae7c96338691ec2bbf2aad7ddc6328a6da)
Legacy QCOM audio does not support ext functions

Change-Id: Ia8d8062aa011044d93683b884f59432b03822c6a

Author:    Kevin Bruckert <agrabren@yahoo.com>

	modified:   msm8660/AudioHardware.cpp
Samsung msm8960: Add support for "Voice Earpiece Extra Gain" mode

Uses "Voice Earpiece Extra Gain" mode instead of "Voice Earpiece" during
voice calls when persist.audio.voc_ep.xgain=1.

Change-Id: I5d2e09ad59b77198a1c6f9fe2473bf9b05575a33
Legacy QCOM audio does not support ext functions

Change-Id: Ia8d8062aa011044d93683b884f59432b03822c6a

Author:    Kevin Bruckert <agrabren@yahoo.com>

	modified:   msm8660/AudioHardware.cpp
alsa_sound: Enhance support for dock audio.

- Adds SND_USE_CASE_DEV_DOCK to properly route audio based on
device's alsa use case definitions.
    - Ringtones always play on the device speaker, in case
    you have it docked, but your stereo turned off.
    - All other sounds get routed based on whether the dock
    is the configured output device based on DeviceSettings.

- Uses the new BOARD_HAVE_DOCK_USBAUDIO option to set
DOCK_USBAUDIO for rerouting to new dock use case.

Change-Id: Ib78907e376c852f4d2e30133c6eb34964a15d406
audio/msm8660: Fix audio routing issue during cam corder

- After cam corder recording, voice call is not routing to
  wired headset even if it is connected.
- When cam corder recording starts device switch to handset,
  and when it stops also remaining on same device, because
  active device is not updated based on policy after cam corder
  stops recording.
- Update the active device based on policy after cam corder
  recording and switch to higher priority device if available.

CRs-Fixed: 398301
(cherry picked from commit ad59eae61b2c3a5d98416d7164923651b52bdb7e)

Change-Id: I88f9abd07b6f5de04b7ee32b5610946730c55ab9
audio/msm8660: Fix to avoid routing in voice call

-If a device selected for media playback is other than the
current active device selected to route voice call, routing
is switched to that device.
-Avoid routing in such cases if device to route is different from
current device for voice call.

Change-Id: I6d4e7a667b1949a5bc45e19c2f7b3a4555b6bbfe
CRs-Fixed: 397595
audio/msm8660: LPA Audio HAL fixes for suspend and eos issue

-LPA playback reset is not called at end of clip as eos
from HAL doesn't gets generated if last write buffer
size is zero.
Fix this by posting eos to observer if bytes to write is zero.

-After suspend resume, playback of paused lpa clip is not
resumed if tried to play the clip.
Added isDriverStarted variable to maintain states of driver.

-Driver flush is not triggered sometimes during paused state
 and at the end of clips while LPA Player is waiting on fsync.
 This results in fsync to be blocked indefinitely and ANR is
 observed.
 Fix this problem by calling driver flush explicitly and pause
 the session if stream is in paused state

-If last buffer is written immediately after flush the last
 buffer is skipped and eos is triggered. The song doesn't
 switch to next clip because of this problem
 Fix this problem by triggering eos if last buffer is written
 immediately after flush

Change-Id: Id57cf830a411c199e1923f38740bbe0862eab7df
audio/msm8660: Fix the issue of voice call when HDMI connected

- Voice call is not working when HDMI cable is connected.
- When HDMI is connected getDeviceForStrategy is picking
  up HDMI rx as active device, because of this voice call
  is not working.
- Avoid updating the HDMI as active output device, when
  strategy is STRATGY_PHONE.

CRs-Fixed: 384324
(cherry picked from commit 815e0bfe786a4c7fca0bb4880b56519471dde386)

Change-Id: I76cf12ca0449569a83f5188e8b30db08ff86f584
audio/msm8660: Add support for audio effects for LPA clips

Change-Id: I04587005e2ec3b89ce933a607d1603c4766687d0
alsa_sound: A2DP playback changes on jellybean

-Re-design for A2DP playback for changes. Data is read from
 proxy port and written to A2DP HAL. A2DP output is opened
 and configured from 8960 AHAL.

Change-Id: Icb373f882a99ff2a091e32a902811226ada77140
(cherry picked from commit 7c733664750e8c0ba45e8282f5195d536db00520)

alsa_sound: Fix for no audio on A2DP after pause and resume

- No audio is heard on A2DP headset after resuming audio playback
  after pause for more than 5sec.
- On long pause, the output stream is set to standby and the A2DP
  playback thread is suspended. But while resuming the playback,
  A2DP thread is not restarted which results no audio on A2DP.
- Fixed the issue by starting A2DP playback on first write to
  audio HAL on resume.

(cherry picked from commit d3ae028c373135615cfeeef0d670fe27693f9d99)

Change-Id: I2c1ddf751630b459d59d9e2e7d3bcca94c7d4330

alsa_sound: Fix for audio not routed through WiFi display

- DEVICE_OUT_PROXY is overwritten by A2DP device
- Switch to A2DP device only when DEVICE_OUT_PROXY is not set

(cherry picked from commit 2361761fb4ee2417cf84e73125f875936d6a285f)

Change-Id: Iea5e9934a4939bd71575faca4fd9c3627b48f7fc

alsa_sound: Fix for audio loss during BT power ON/OFF

 -Currently when BT headset is powered off audio HAL does not
  stop A2DP playback thread as we are calling suspendA2DPplayback
  in standby function which is causing audio loss when BT is
  conencted back. This is because dorouting is not called when
  BT is reconnected and is not teared down path previously
 -Fixed by calling stopA2DPplaybcak in standby function which
  will stop A2DP playback and called dorouting again when BT is
  connected again.

CRs-fixed: 391103
(cherry picked from commit 015e6f3bafafb516c4b1c8684d194d279cc47ab9)
(cherry picked from commit f5ca1b342591e21ff8a879ce14d593d6f250b14d)

Change-Id: I8493229e79ea0633ec11599bcd78792015e599ab

audio/alsa_sound: Fix for audio routing to speaker after BT voice call drop

Steps to reproduce :
1. Connect and pair BT.
2. Make a MO Voice call.
3. Play Music. (Both voice call and music is routed to BT SCO)
4. Disconnect the Voice call.
5. Music resumes in speaker

Root cause of the problem :
When phoneState get changed, A2DP suspend flag should be updated first. Speaker was selected

How to fix the CR :
check for device and output changes with proper order

Change-Id: I5043b6807fa48145ded7a268223074a8cf693f69
CRs-Fixed: 392743
(cherry picked from commit 45c2afae5e720fa6c676812db1a7c26cb6899b35)

alsa_sound:Fix for LPA clips audio loss during BT power ON/OFF

-mRouteAudioToA2dp should not set to true in standby function
 which will close all A2DP streams.
-This is taken care  in stopA2dpplayback function so removed in standby.

Change-Id: I61f1b901261cab7ebad9d17491fb8158835aeba1
CRs-Fixed: 391103
(cherry picked from commit 709dd53cae31c31c501accb47026ed9fd00d5c68)

alsa_sound:Fix for voice+Music playback over BT

- Issue: Start Music playback,initiate MO/MT call,disconnect call
  and music should resume but Music plaback resumes and stops after
  1 or 2 secs.
- Rootcause is because of standby function called after 3 secs of voice call
  end which in turn calls stopA2dpPlayback function
- Fix: Deal with lowlatency use cases over BT seperately.

Change-Id: I79d65f72dffbdb32c1859fba6b3607c8afe5eb52
CRs-Fixed: 398060
(cherry picked from commit 76841ce85e73f3e333adf321d615cf4eec383e7f)
(cherry picked from commit fc8e6b8efddd690656fcb3c15c43196c7176067a)

alsa_sound: Fix for no audio in BT after standby is called.

When BT is connected, and there is no audio for three seconds,
standby is called. But pcm device close was bypassed in the case,
when BT device was connected. Due to this mRouteAudioToA2dp was not
getting set to true in subsequent playback and hence a2DpPlayback
was never getting started.

Make a fix to close pcm device even when BT device is connected

Change-Id: Ice455455063179c82640b9fef9fdab7c002b615c
CRs-Fixed: 409889
(cherry picked from commit 41d8544b953cc5f0f3d8ac0316df60ff631811fc)

alsa_sound: Fix for no audio in music+ringtone concurrency on A2DP

- While playing audio on A2DP, if we go to settings and select a
  ringtone, the audio is lost. Expected behavior is that the ringtone
  should be heard on both A2DP and Speaker and music playback muted.
- While A2DP playback thread is reading data from proxy, if the
  device switch is done from A2DP to A2DP+Speaker, the proxy device
  is disabled and re-enabled which results bad state the A2DP playback
  thread.
- Fixed by stopping A2dp playback and resuming after the routing is
  complete.

Change-Id: I413540404d173a6c0d15c7704ee6e2efeab0887e
CRs-Fixed: 392353

alsa_sound: Shush the logging

Change-Id: Ib6bdafc600b66489868b0b18846446bb08cc8426
audio/msm8660: Fix for Mute not working in VoIP call

- In VoIp call mute option is not working
- Due to wrong device selection, PCM recording path is selected, instead
  of MVS Tx path, for VoIP tx.
- Enable MVS Tx path for VoIP uplink.

CRs-Fixed: 406977
(cherry picked from commit 9941ecfadc64514f4de8f4962b238d623aac52ce)

Change-Id: I5e2525938107a0c6a7115038d85419c4b886d5fe
(cherry picked from commit b4f3bad309e6fd0a9b39c10a64ef3bcb1141b373)
Merge "audio/msm8660: Fix for Mute not working in VoIP call" into jellybean
alsa_sound: Re-add DOCK_USBAUDIO.

Change-Id: I7d8054c8e08a4607425dce61e461e11474f224a3
alsa_sound: Re-add HTC_AUDIO, SAMSUNG_AUDIO, and USE_A2220

Left out in Ib6bdafc600b66489868b0b18846446bb08cc8426's refactoring.
Fixes d2 speakerphone caller echo.
audio/msm8660: Add channel mask for voice call recording

- Voice call record is failed to record.
- In channel mask uplink and downlink entry is missing
- Add uplink/downlink in channel mask and voice call
  in global configuration.

CRs-Fixed: 382736
(cherry picked from commit 505ac6f14f1b70fb0f52bbf53c0ca844ae66d271)

Change-Id: Id3a1d5346b07addb0d44add3cd030c75e5c9e3d0
Merge remote-tracking branch 'cm/jellybean' into jb