libstagefright: Filewrite in seperate thread for single video track

For files with single video track, the filewrite() and OMXRead()
operations are happening in the samethread. It impacts the
recording performance.

Hence moving filewrite to seperate thread for files with single
video track.

CRs-Fixed: 574807

Change-Id: I3a9bf7869e197973a85783510254cf66b8d1d91b
libstagefright: Delay release of wakelock

Delay release of wakelock till the last event
in the event queue of TimedEventQueue has been processed.
This ensures AP shutdown does not happen while an event
is ready but hasn't been processed yet.

CRs-Fixed: 583053
Change-Id: I597c0b9887b02b070c708401e5f3c40a0a2289d0
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
Fix aliasing violations (properly)

Big ups to Haruki Hasegawa for the 4.3 equivalent:
	10d8e90 - frameworks/av: Fix Visualizer's get/set parameter methods not worked bug

Signed-off-by: nuclearmistake <nuclearmistake@gmail.com>
Change-Id: Id914f57700c21b8fa2dc4c2ca3b1c8872bf31256

Conflicts:
	media/libmedia/Visualizer.cpp
HLS: Fixed rounding error with decimal segment duration

If segment duration is specified with decimal value only the
integer value will be used, causing the stream duration to
be wrong.

Reported to Android public issue tracker:
https://code.google.com/p/android/issues/detail?id=56223

Change-Id: I34fb7a81af6ad3d9a214228cfe3724636ebf5ab5
AudioMixer: clear disabled track buffer in process__genericNoResampling

This is done in all other processing functions except
process__genericNoResampling. On some device, this can cause garbage
sound to be played when 2 short tracks are started and stopped
nearly simultaneously.

Change-Id: I8a325175e8e326a638c7f29987ae272ae8af6b66
AudioFlinger: Take resampling into account when choosing the minimum frame count

If the caller tried to use the fast path with a sample rate
different from the device's native sample rate (not knowing whether
audio flinger supports resampling in the fast path or not, which
is a compile time define), make sure to set the frame count to
a value high enough.

If resampling from a higher sample rate to a lower (e.g. playing
back 48 kHz content on a device with a native sample rate of 44.1
kHz), the input number of frames needs to be higher than the
output block size, otherwise the resampler will occasionally
reuse input samples (leading to small ticking sounds with regular
intervals, and triggering the "desiredFrames <= cblk->frameCount_"
assert if built with debugging).

This should fix playback of 48 kHz PCM content via OpenSL ES on
Nexus 7 (2012/grouper) - verified on the emulator which showed
the same issue as the Nexus 7.

Increasing the minimum number of buffers from 2 to 3 is similar
to what is done in AudioTrack::createTrack_l.

Fixes: http://b.android.com/59453

Change-Id: I3ef7ea32826da5105f16423a9f333025f5aa0add

Conflicts:
	services/audioflinger/Threads.cpp
Frameworks: AudioFlinger: Fix effects memory leak

Patch by: csheng@marvell.com
Change-Id: I4e3032fb34643902f98e8fd7c8e894b6452324c9
Signed-off-by: Yu Yezhong <yuyezhong@gmail.com>
Fix c++11 narrowing

The best fix for these narrowing
violations is to use static casting

As an example, this change would the following for libnaio:
error: non-constant-expression cannot be narrowed from
type 'uint32_t' (aka 'unsigned int') to 'long' in initializer list

const struct timespec req = {0, ns};
                                ^~

Change-Id: I04ed1de4497dc19772194afef3ebf8fe0c8b82bc