Squash upstream from CM for msm8660 device family

Revert "msm8660: Additional routing fixes"
 Makes updating the source go smoother

This reverts commit ed2b5940e2814015f63d605d05a4d77e8743ebf7.

audio/msm8660: Change default audio sample rate

Return Host PCM interface sample rate based on
AF resampler quality value.

(cherry picked from commit fbaba9b736d0b77c989c80946ffb7d105641c07d)

Change-Id: I204f423051d97be5ff4dfa9805406eca61a25966

audio/msm7627a: Fix for event thread not exiting

-Event thread never exits after lpa playback.
-In error case of GET_EVENT, it is checked against wrong
condition which is always false.
-Update the check condition to avoid such issues.

Change-Id: I8274a67791ba7656eb4031952ddc55ac919df60d

msm8660: Fix routing for all AudioSessionOut types

 * Pass the new output device around so that we're not always just using
   the one in the base class. This was preventing proper routing for
   all output streams.

Change-Id: I9019d46b1268a05c6c743e40e9198b6b4898b0de

audio/msm8660: Fix for voice call mute during voip

-Voice tx is muted when call is received while voip is active.
-After voice call is received, voip moves to standby and calls
setupDeviceforVoipCall with value as false. This will mute mic
during voice call.
-Return from setupDeviceforVoipCall without moving to normal mode
if called while in call.

Change-Id: I3dcd6dacd0d8b1242019e55d9d9be6909444e49d
CRs-Fixed: 451202

audio/msm8660: VOIP bringup and add support for vocoders.

(cherry picked from commit 7f22fe5517966549f96dd02ff577e0c222f35483)

Change-Id: I8fe9eef46b7513135eb363530f4343abfa6a0f10

audio/msm8660: Change getInputBufferSize to take channel count as parameter

- SoundRecorder fails to record.
- There is no need to calculate channel count
  from channel mask as getInputBufferSize api
  already gets channel count.
- Add fix to change getInputBufferSize api to
  take channel count as argument.

(cherry picked from commit 72553946d9cc82429f58ed8a7a5489ad38722b04)

Change-Id: I5d39f5cc3eee5860b717b0fa14af1590abfb2d04

msm8660: Reject PCM recording other than 8k during voice call

As there is no resampler on record path in ADSP, Recording session
other than 8k cannot be be supported during voice call otherwise
voice Tx gets muted due to afe reconfiguration for recording
session.

Added check to reject pcm recording session other than 8k if requested
during voice call.

(cherry picked from commit 1eca4191de742b13f02df2f15d6d0ba7598d2616)

Change-Id: I84656b6864dfdc4114b2d7c1762746d1456ee2b6
CRs-Fixed: 427931 432502

audio/msm8660: Fix for voice call mute during voip

-Voice tx is muted when call is received while voip is active.
-After voice call is received, voip moves to standby and calls
setupDeviceforVoipCall with value as false. This will mute mic
during voice call.
-Return from setupDeviceforVoipCall without moving to normal mode
if called while in call.

Change-Id: I3dcd6dacd0d8b1242019e55d9d9be6909444e49d
CRs-Fixed: 451202

audio/msm8660: Fix wrong condition for VOIP sampling rate

- Mediaserver crash is observed during voice call setup
- VOIP sampling rate is wrongly checked and error is returned
  for valid sampling rate also
- Fix this problem by removing the wrong check for sampling rate
  Select WB mode for 16K sampling rate and return proper buffer
  size in bufferSize function

Change-Id: Iabc9d0c79fee99954097d41662070131fa51e7b4
CRs-Fixed: 395816
(cherry picked from commit 4039c7258f9f0735c943eafb850734fd6d35f02a)
(cherry picked from commit 5579d45bae575b3a99cdc44bc4154555afe77d9b)

audio/msm8660: Set proper device for Voip routing commands

-Voice message doesn't switch to earpiece when switched from speaker
in Fetion apk.
-Device routing commands to streamOutDirect session use primary
output stream device set. This results in ignoring the device set
for voip session. Fetion uses music stream to play on speaker and
voice stream to route to earpiece.
-Fix this problem by setting device routed for streamOutDirect by
explicitly sending the output device value set in setParameters.
Also if the requested device is the same as current device, still
allow routing call to AudioHardware as current outputDesc might not
be updated with current active device always. In such cases if device
stored in outputDesc is same as newDevice it will still not allow
routing from current device. Since there is already a check in
AudioHardware to avoid routing multiple calls on same device,
removing this check is safe.

Change-Id: I934f3fcc5d77ffdb7634ba471d1cfd38682c6a61
CRs-Fixed: 444787

audio/msm8660: Fix for improper LPA playback after seek

-LPA playback is not in continuous manner when rapid seek is performed
and effects is turned on/off.
-After seek, mSkipwrite flag is set to skip the current buffer either
in bufferavailable or write. If returned from write there is a
mismatch in buffer maintenance between flinger and hal as flinger
is not aware of buffer skip and has already pushed back the buffer
into mEffectsPool.
-Return error in skip case to handle in flinger and re-arrange buffers
to original state in mEffectsPool to avoid any mismatch.
Also mReachedEOS was getting set after fsync i.e. after write_done of
last buffer is processed and hence EOS was not getting posted to the
above layers. Moved this to ahead of fsync to avoid issues.

CRs-Fixed: 454460, 453872, 453833

(cherry picked from commit 8af44e4b795d289315188a3879a07596454bc923)

Change-Id: I98821fb0c97fdfc4f8d27e4480877ed963e5a61e

audio/msm8660: Fix LPA playback issue after continuous seek

- Playback is not continuous after multiple forward/backward seek
  operations.
- After flush buffers are not maintained in correct order, which
  is causing some old data to be heard after flush.
- Maintain correct order of empty buffers after flush.

Change-Id: I40df9fde9b0a6e39803a509be34f2b73ef722c35
CRs-Fixed: 440952

audio/msm8660: Fix native crash during rapid seek operations

- Native crashes are observed during rapid seek, next and previous
  song switch operations
- There is some race condition between write and flush which results
  in adding a buffer multiple times to empty queue. This tries to
  free the buffer multiple times during reset and results in native
  crash
- Fix this issue by adding proper mutex in write and flush calls
  which synchronizes these operations and avoids crashes

CRs-Fixed: 450172
(cherry picked from commit a4413c7646320169bca133d1e7b32598ed4baa02)

Change-Id: I530d4018b221b57ec325dbe40b670ef49007aaa9

audio/msm8660: Fix dragging voice and deadlock in VOIP call.

- Dragging voice is heard at the far end due to wrong sampling
  rate configuration
- Input stream sampling rate for VOIP call is hardcoded to 8K
  Hence WB call uplink is also configured at 8K instead of 16K
- Set proper sampling rate instead of hardcoding the value

- Deadlock is observed sometimes during VOIP call setup
- VOIP call device setup is called by taking mLock which calls
  doRouting function which also acquires the same lock. This
  results in deadlock while read thread acquires the lock and
  write thread tries to call the device setup function
- Fix this issue by calling VOIP device setup function without
  acquiring the lock during call setup

(cherry picked from commit c259df62731724461959955b8d57972d300319dd)

Change-Id: I39f4c146cdb627f00c5e58d71abedf88ae2197b4
(cherry picked from commit d52665de514188208110860d681c67a419c7a452)

audio/msm7627a: Changes to support voip on different paths.

-Few apps in market use mvs path for tx while rx is regular
playback path. In such cases setupDeviceForVoipCall is not called
and mic is muted through out. In voipin read(), ensure
setupDeviceForVoipCall is called if no call was made earlier.
Also do not return from setupDeviceForVoipCall if setMode fails due
to same mode being set as mic state needs to be still updated.
Add proper return value in openInputStream to use resampler in audioflinger
for voip and voice concurrency.

CRs-Fixed: 467563
Change-Id: Id7b327310ea72c1727150dc877334476f2bfc3a0
(cherry picked from commit 79430b2ac2a420f28f73ae59ff40fb2928ba6931)

audio/msm8660: Fix for crash in Voip conference call

-Crash is observed in voip conference call using third party voip app.
-Directoutput is used across different voip sessions in openOutputStream
if already opened. Irrespective of this, in closeOutputStream
directoutput is deleted and if the same handle is accessed by another
voip session it leads to crash.
-Introduce reference count for directoutput and increment it for
each session. Similarly delete output only if reference count is zero
and no other session is accessing it.

Change-Id: Ic132172130ee4e0657345842ba4619d41db567b1
CRs-Fixed: 476899

msm8660: Additional routing fixes

 * Various cleanups.

Change-Id: I9019d46b1268a05c6c743e40e9198b6b4898b0de

audio/msm8660: Move fsync to LPA event thread

- Sometimes while LPA playback seek to last second, music lose
  control and "Music not responding" message pop-up to close.
- In last buffer case, call to fsync by releasing mutex lock
  after write to driver; meanwhile write done event is reached
  and EOS is triggered in event thread. Due to this LPA session
  reset is called and mutex lock goes out of scope. Due to this
  session is blocked on mutex as it is not able to acquire lock
  after fsync call in write.
- Call to fsync code is moved just before trigger to EOS after
  write done event in event thread so that EOS is posted only
  after complete playback of last buffer.

Change-Id: I48bc7f887b287957bf9d13ae00b94221295a7efd
CRs-Fixed: 457668

audio/msm8660: Ensure to check mvs fd value before voip read

-Voip read returns error continuously and sometimes increases
CPU usage blocking other processes.
-No check if mvs fd is valid or not before calling read and due
to this, it returns error whenever read is performed on an invalid
fd.
-Check for fd value before calling read and open mvs device and
configure it if fd is invalid.

CRs-Fixed: 472106
Change-Id: I70277a2de095a4f190d885fdeabe68040dbc4e12

msm8660: Add msm8660 hardware config and routing calls

 * This code was lost in the upstream merge.

Change-Id: Idb4ee2ec752110a269f5204c736a1a6930d3f010

mam8660: Cleanup makefile

Change-Id: I3dee08537f860c4e82cc104ee47966011feedefd

msm8660: Fix featurization of Samsung VOIP routing

Change-Id: Ibf25278f5ba182f453309e1d1793d107004fe52b

msm8660: Code cleanups, fix potential crashes

Change-Id: I5e75d1fb459d1231279c511d35a0b5d51b5d10e0

msm8660: Add AUDIO_DEVICE_IN_COMMUNICATION to primary input

 * In case the app requests a high input samplerate, we need to bypass
   the MVS route.

Change-Id: I413859be4794ee8f9c728a52aaf557954f6b7850