audio: Fixup BT A2DP for QCOM A-family

A- Family doesn't support separate output for a2dp , removed the
getA2dpOutput(). getDeviceForStrategy() is selecting the proper
device using mA2dpSuspended flag.

Change-Id: I0721e5cb9943f888645f6220334ee6707df96e0b
stagefright: Add more latency profiling

Measuring the startup latency from StagefrightRecoder start to
first frame camera callback. Also add profiling to CameraSource
start and StagefrightRecoder start.
Add profiling to measure reconfig.

Change-Id: I037da0b9bfbcea01522b19310d142247d4f02e96
stagefright: extendedstats: Synchronize logging mechanism

Add a lock to all public functions of extendedstats to prevent
clients from modifying the same resource at the same time. For example
two clients can call getLogEntry and without locks one will end
up traversing the vector while the other is modifying it, leading
to a crash.

Change-Id: I908e0ebcc01026c258554214338f43c5d1226eb7
libstagefright: Small buffer hint for PCM offload

Audioplayer when explicitly requesting PCM offload
needs to inform audio track that small buffers have
to be used. This is required to make sure that pcm
offloaded tracks work very similar to deep buffer
path. This hint is passed to the HAL which makes
the write calls are blocking. Handle the new
properties for pcm 16 and 24 bit offload in policy
manager

CRs-fixed: 749148
Change-Id: Ia7b2260ec6e4821a7dbbfcc3ec7719c334aa40f6
audio: Force audio to Speaker if requested during VOIP call

getDeviceForStrategy is returning AUDIO_DEVICE_OUT_USB even
when setForceUse is called with Speaker during VOIP call.
Actual Intention is to route audio for phone strategy to USB
device even after setForceUse is called with Speaker when not
in voice call. It is supposed to exclude VOIP call too

Added additional check for MODE_IN_COMMUNICATION so that
it returns SPEAKER when setForceUse is called with speaker

CRs-Fixed: 762521
Change-Id: I1c51128cc1c7bfce1cf6f1fde60b428d3a9379fc
Prevent ANR when AudioTrack is paused or re-routed

If ClientProxy was interrupted by AudioTrack::pause() just before futex syscall() in obtainBuffer() was called,
It will not call releaseBuffer to wake up AudioTrackThread.
It puts the AudioTrackThread to sleep and then a deadlock occurs.

In this case, CBLK_INTERRUPT flags can't prevent a deadlock,
so this patch set mFutex to FUTEX_WAKE during interrupt() to avoid deadlock.

A similar problem could occur due to re-route or recovery after mediaserver death.

Bug: 18641665
Change-Id: I66fcae43af9a91eb55f6cdb52c644ee6c0999772
Truncate file before recording into it.

Recording into an existing file of non-zero length could leave old
data in the file after the recording ends. Best case that wastes
space, worst case it results in a file that's considered corrupt
on playback.

Change-Id: I2c77a107603b2b36790958360ff0856c2b28d677
Fix AAC recording issue

Fix uninitialized variable that caused ADTS recording to incorrectly
specify LTP object in the header.

Bug: 17895547
Change-Id: I75650f4963f4f371cd191bc635e32c9ab17fa8c9
libstagefright: Fix heap corruption from AudioSource

AudioSource allocates memory for member variable
mTempBuf in its constructor and deallocates during
reset, but mTempBuf can be dereferenced on event
EVENT_NEW_POS even after reset, since AudioRecord
instance can post this event while exiting threadloop
even after stop is called on AudioRecord.
Also reset is called from destructor only if mStarted
is true, which means the memory can miss deallocation
if start is not called before AudioSource instance is
destroyed.
Moving deallocation of mTempBuf to destructor
will solve both the issues.

Change-Id: Ie42f0894e6b3e7c7ea734814ab90d46ee2d7c753
Stagefright: use get(Input/Output)Buffer in async mode

Non-async mode uses get(Input/Output)Buffers to get the
buffer handles at start; buffer-IDs obtained after
dequeue() are used to directly reference the handles.
In async mode, MediaCodec calls-back when an input/output
is available. Relying on the initial buffer-list can lead
to race conditions when buffers are allocated or changed.
Hence use get(Input/Output)Buffer to query the buffer
handle each time and just-in-time.

CRs-Fixed: 765324
Change-Id: Ifc0b7558564a57bd9316d0f80ae9cf88dfd6a1f3
libstagefright: Fixed PCM Offload format check

Small buffer hint is getting enabled for other formats
too due to in-correct checks in AudioTrack and AudioPlayer

Fixed the checks so that it gets enabled only for PCM
Offload formats

CRs-Fixed: 767824

Change-Id: I46cce8d66d0299c8ec8b8b12592c69cfe0abde18
stagefright: Allow deep buffer mode for audio-only playback

 * NuPlayer is used across the board now, allow deep buffer for
   audio tracks if offload isn't available.

Change-Id: I0ad6bbcaa29d44d47b37b2f2d08a2af43c3fced5
stagefright: Cleanup of PCM offload checks

 * Put the checks in a single place.

Change-Id: I2d0d5b542593896e78bf989296de1a1d1e3a4963
Fix video/audio sync issue when audio track is changed

After user resumes playback in short period of time after audio track
switching, audio decoder will be null due to failure of fetching
stream type. However current routine is to resume video playback even
though audio decoder is null, which causes video/audio sync problem.

Change-Id: I4efeff18f55d46daa34ead71f77dbfa1016798a2
NuPlayer: Disable widevine flag for L3 content

Disable widevine flag for L3 content. This is
needed because Generic source considers widevine
playback to be L1 by default, without checking if
secure buffers are requested by the widevine source.

Change-Id: I4e33836dfa98554d5ae0cb8cc01c1c960ba86fb1
stagefright: Fix QCOM_BSP ifdef

Change-Id: I57d3f4111017ef23a1928e8d0caab0a1e0bded37
Revert "libstagefright: Fix QCOM_BSP_LEGACY cflags"

* This is unneeded now that the flags are set in build makefile

This reverts commit 965f5389194fe9922ddea75564ea72e4fba39f96.

Change-Id: I7b849bf2b8442b576d1c2bee26795ffdb90581b1
stagefright: Remove unnecessary QCOM_BSP flag

* Already provided by build makefile

Change-Id: Ica244932f82c93e0f883c603261d16c764a375f1
Merge remote-tracking branch 'upstream/cm-12.0' into cm-12.0