frameworks/av: Fix errors from upstream CAF merge

Change-Id: I1d1a515f75366ae8c1989aeea1eed0ef036ce96d
libstagefright: Add support for custom LPA buffer size

 * On msm8930, during playback over A2DP with DSP Manager effects enabled,
   there's a lot of stuttering with the default buffer size. Stock kernel
   used a buffer size of 32, but that caused no audio at all in CM because
   of mismatch in buffer size between kernel and user space. So up until
   now I've been using a buffer size of 256 to get audio working at all,
   but unfortunately it causes stuttering as mentioned. Hence add support
   for a custom buffer size so we can revert to stock value used in kernel,
   and enjoy no stuttering.

Change-Id: Id4d090bc6cf90782c24f3832a35ddeca43bd72fc
libstagefright: Fix timestamp corruption during offload playback

-Timestamp gets corrupted at EOS of offload playback.
-This happens because the number of samples played returned from
 HAL could be zero if playback has reached EOS and if compress
 handle is invalid / closed.
-If HAL has posted EOS  avoid the update of real time and media
 time with the timestamp from HAL.

CRs-Fixed: 570368
Change-Id: I5ea75f4eda1df0c110bce780e50e3c8ae9b4cd85
libstagefright: Fix intermittent pause during tunnel A-V playback

-Media time is used in onVideoEvent for A-V sync. In offload
 playback we only use realtime(time from DSP).
-Media time should be same as real time. If media time is not
 updated with the real time value A-V sync issues are seen.
-Update media time to real time value to avoid intermittent pause
 during playback.

CRs-Fixed: 572060
Change-Id: Ib1123b7554f3508230ca67cd20a68fa32c753057
audio: Fix for OMXCodec::read() getting blocked

- Sometimes notification sound is not heard if it is played
  and stopped multiple times in a short duration.
- If OMXCodec::read() gets blocked for filled buffers while
  in pause, it never returns as mFilledBuffers is always empty.
  Due to this AudioTrack destructor never exits as it waits for
  the AudioCallback thread to unblock it.
- Ensure OMXCodec::read() returns even if timeout occurs while
  in pause and handle the same in AudioPlayer by returning zero
  bytes in AudioCallback.
CRs-Fixed: 478768

Change-Id: I2ca40a673fdf95bccc3069a18b694670612a9895
frameworks_av: Support pre-KitKat audio blobs

Patch Set 2: Combined duplicated method

Change-Id: I6384c13b0944a25cdf0cb90031b2e3698bc3e78d
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
frameworks/av: Update to caf/kk_2.7_rb1.10

audio: Add track to trackToRemove list when it is terminated

- PlaybackThread loop is continuing for direct output even after
  the track is terminated by the client. This is causing 2 direct
  tracks being active when client starts another session
- Fix is add the terminated track to tracksToRemove list so that
  this track is destroyed properly

  CRs-Fixed: 566808

Change-Id: I65f565d9c3a00e071174659ffb92f711dfd8742a

audio: Fixed framecount in AudioRecord

- Incorrect frameCount is passed to AudioRecordClientProxy,
  which is used while user side pointer is incremented
  This is causing distortion in SIP call
- Fix is to use frameCount of the shared block instead of
  frameCount passed by the client
- InputBytes initialization is also done in AudioFlinger

CRs-Fixed: 568988

Change-Id: Iab32234b198ff4d792eea4c4a82097028089013d

audio: update setParameter command time properly

-setParameter is getting delayed regardless of delay is
 present or not. Because setparameter command time is always
 getting updated with wrong values(previous values) with any
 commands.
-Fix is to restrict the updation of command->mTime always.
 Added check to update command->mTime, only when identical
 commands are present.

Change-Id: I10b94b19f64ef4f15495d34f009238a691d1b36c
CRs-Fixed: 568318, 569010

audio: Initialize LPA variables in audioflinger

 - During initialization of audioflinger, a number of
variables related to LPA are not set to default values.
This causes an undesired side effect that the first
effect in the effect chain is considered to be LPA
enabled. Since LPA does not execute effect processing,
switching xLoud on/off does nothing
 - Fixed by initializing member variables in audioflinger.

Change-Id: Ide06fb0e6804558388e6610cc7686f168591e4a5

scale the kMaxCttsOffsetTimeUs for HFR recording

-timestampUs & decodingTimeUs are scaled for HFR recording
-the difference between these is compared against non-scaled
constant(kMaxCttsOffsetTimeUs).
-fix provided to scale this constant(kMaxCttsOffsetTimeUs)
-and compare against the scaled time difference.

Change-Id: I08188423008d8f6a4824f2748d56a1e355d39a89
CRs-Fixed: 566695

AudioFlinger.cpp - audioConfigChanged_l set for srs Tunnel Device Switch

 - During device switch we were only setting the route
   but was not calling audioConfigChanged_l
 - Hence the effects for the new device would apply only
   when there is a config change.
 - Now we call audioConfigChanged_l during device switch
   setPrameter so that the new effects will be apply as
   soon as device is switched.

Change-Id: I641cd8a7d6ffb7423ccfaa45e4c29b1b5352e61e
CRs-Fixed: 548021

Revert "frameworks/av: AAC CSD support for MediaCodec path"

This reverts commit Ic8197138f5107f2a6026c28847e74987d91acc16
Currently AAC CSD is retrieved in MediaCodec using
kKeyAacCodecSpecificData. This support was added as part of
commit Id046b0d4bf96f029c1b6b5d78d753073e38ac841.

CRs-Fixed: 527284
Change-Id: I54bc6204c1fe88f4e4545f501e6bd1bb2a8beaf9
libstagefright: Add legacy LPAPlayer

Ported from change 46451 / Ie2551345bbf047c022d1fecbb7cb2cc4a4c97d72 from cm-10.2

Change-Id: I6ad282993a843883c3b4c3257f5b730ea0d13307
stagefright: Conditionally build legacy audio stuff

 * The LPA and Tunnel mode code is entirely deprecated and breaks things
   for devices which don't use the legacy ALSA audio HAL.
 * Exclude this stuff unless explicitly requested.
 * Also enable rendering statistics for all.

Change-Id: I0aff39439884d27f1a7b30f56b604f6a43f1969a
stagefright: Clean up the ifdefs

 * This should get everything in line for now.

Change-Id: I3e8eaddeab34dbacb7138f9106f53ada404f7b4d
stagefright: Build fixes

 * Fix build without AV_ENHANCEMENTS on

Change-Id: I4bbf3f0a6f5894ddb33b62d99bced2f6247081db
FLAC coded file does not play (single metadata block files)

FLAC files which has the last metadata block flag set in
STREAMINFO were not playing. Sniff of FLAC is modified to
accomodate this set flag.

Change-Id: I76f216cc2cde6e10958324afbc704fc3e5a0e2bf
Author: Gurudatta Bhakte <gurudattax.bhakte@intel.com>
Signed-off-by: Gurudatta Bhakte <gurudattax.bhakte@intel.com>
Signed-off-by: Shuo Gao <shuo.gao@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 32421
Increase kFastTrackMultiplier from 1 to 2

Change-Id: I158f147295eebcea96e4047d7618069bc48bdd7d
AudioFlinger: Handle sound card status change

1) Update Audio HAL with sound card status change
2) Call invalidate tracks API on all playback threads so that the
   associated tracks can handle the sound card status change as a teardown
   event

Change-Id: I9b8c2244eb80cc08935144affe529591e0728616
audioflinger: check for condition before waiting

AsyncCallbackThread must check for any condition that
was already been satisfied before waiting.

CRs-Fixed: 581978
Change-Id: I7a37c03cddcf7fdaa61c826d71a4d527979ce9e1
audio: Modified API for compress voip formats

 - Modified API for supported compress voip formats.

Change-Id: I0165fc48bbe631d3febf2104e8a28708bf85ef23
audio: do not invalidate stream used by voip

During the process of invalidation of voip streams,
actual driver is not closed so when it tries to open again
getoutput fails as only one instance of voip can be created.
so do not invalidate the tracks used by voip driver.
CRs-Fixed: 494093

Change-Id: I42a962991ce1d586d87f4aecba19c0e5dde6b9dd
 audio: Fix framecount calculation in AudioFlinger

 -Sharedblock implementation expects the framecount to
  be round up to the next highest power of 2. This is
  not done in TrackBase for non-voip case which leads
  to shared block getting corrupted.
 -Fix is to round up the framecount in TrackBase for
  all the audio formats.

  CRs-Fixed:  571279, 573735

Change-Id: I0186bb0e04a080100b364aead447ff2fce495ca2
camera: Handle the num-jpegs-per-shutter mode

 * M7 will set this value to 1, but set the number of burst shots to 3.
 * We need to call takePicture on the hardware a number of times before
   accepting the jpeg.

Change-Id: I169ee3139e8643a39133d7385afe2f88982a1612
audioflinger: Fix for a deadlock

AudioFlinger enters a deadlock (with itself) on trying to free a
RecordTrack object that failed initialization. Clear this
bad object from the caller instead.

CRs-Fixed: 589020
Change-Id: I926f2beb922a70f6924e593e2bbf1a5b5df85b16