stagefright: 24-bit audio support via offloading

 * PCM offload feature can handle 24 bit streams padded to 32 bits,
   bypassing resampling and truncation.
 * Add support for 32-bit padding in FLAC and WAV decoders
 * Refactor the FLACExtractor a little
 * Set flags where appropriate
 * Tested with 96KHz/192KHz 24-bit FLAC files on msm8974pro
 * Audiophiles, rejoice!

Change-Id: I87bfabd991da34fbb6115e69ee5a935d941c29da
stagefright: Fix compile for non-QCOM_HARDWARE

* AUDIO_FORMAT_FLAC is only defined for QCOM_HARDWARE, move it inside
  the AV_ENHANCEMENTS ifdef so only AV_ENHANCEMENTS enabled devices can
  possibly offload it.

Change-Id: I83c1d527527c2545c5cea599fb01632604c73c23
appop: protect mediaserver with OP_RECORD_AUDIO op check.

Some apps could use a binder to direct link to the mediaserver, bypassing
the android media framework security. Add an internal check to createTrack and openRecord
mediaserver's methods to protect them from undesired access.

Thanks to Blackphone for discovery and contribute this patch.

Change-Id: I12601d19ee093cf4c76ebf3a96aa63f6562dafac
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
libaudioflinger: add stock resampler in pcm offload path

- when samplerate changes in b\w playback, resampler should be plugged-in
  so that the o\p sample rate remains the same to h\w
- this resampler is only enabled on 16 bit PCM path, when channel count is
  <= 2 and channel count doesn't change mid-stream
- once the sample rate resets to original\initial sample rate, resampling
  should not be done
- by default this feature is disabled

Change-Id: Ic27bbf9174d0a83297ebc4418eebdc8850272a6b
frameworks/av: Add output close in AudioTrack destructor for offload case

Close audio output handle inside AudioTrack destructor for
offload case to make output handle close/open independent of
each other and support multiple concurrent offload plyabck
session.
This is controlled runtime based on system property:
audio.offload.multiple.enabled

Change-Id: I98b3a6fe03bfddca2ed01a2adc5a33e4ad540e67
stagefright: Handle offload fallback for 24-bit tracks

 * We need to carefully handle fallback in the 24-bit lossless
   sources for outputs such as A2DP, which cannot use PCM
   offload.
 * Clean up the code while in here as well.

Change-Id: I398d964a3c5b18f58fcc79376bc29222e796badc
Merge "appop: protect mediaserver with OP_RECORD_AUDIO op check." into cm-11.0
Revert "appop: protect mediaserver with OP_RECORD_AUDIO op check."

This reverts commit 688b6b46db58bceb8fa0e5b3a14ea192153c0fd3.

Change-Id: I8b1feb4eb22257024ef4426988be7d5f084df9db
Merge "Revert "appop: protect mediaserver with OP_RECORD_AUDIO op check."" into cm-11.0
audioflinger: exchange AUDIO_SOURCE_HOTWORD with AUDIO_SOURCE_VOICE_RECOGNITION for pre-kitkat blobs.

Change-Id: I6241cf6667c97dfd7fb1c238b1fbadea5cdb863e
appop: reimplement OP_RECORD_AUDIO op check in mediaserver

Obtain the real package name for the calling app from the packagemanager binder and
link to client registry. Also block only openRecord and createEffect (which are the
methods used to record audio), and ignore the createTrack that is used also by
legacy audio apps and isn't related to audio recording.

Change-Id: Iedd6022fab1efab47a29da7bd07e922dcdeb294c
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Camera: Add Samsung klte camera parameters

Change-Id: I3a30f901befc001a8be6788641226405c6d550ca
Merge "appop: reimplement OP_RECORD_AUDIO op check in mediaserver" into cm-11.0
video: Fix crash during video recording

In pause-resume scenario, MPEG4Writer::start is
called to resume recording, which also resets
start time for writer to -1. If this happens
between two tracks updating the writer start
time, it can end up having the larger of the
start time of the two tracks, which results in
crash later due to assert.

Added change to set mStartTimestampUs to -1 only
when writer is being started, and not resuming from
pause.

CRs-Fixed: 692122
Change-Id: Ia98656acfa3912876d01e92b36c5e06a8c84eb7b
StagefrightRecorder: correct the flow of resuming or stopping from pause

1. resume from pause: start the writer first, to avoid frames dropped by
writer due to writer is not started, which caused mosaic frames.

2. stop from pause:  don't start writer, just start encoders and sources,
to avoid unwanted frames are written into clips when stopping in
paused state.

3. recover the pause(dropping frames) in MPEG4Writer.

Change-Id: I4f8f275bce6ac7bc3d4f31f372cc86b362b6c587
CRs-Fixed: 695750 695745
libstagefright: fix issues in AH263Assembler

- if the received rtp packet belongs to the current
  candidate access unit but arrived later, this packet
  still needs to be inserted into this access unit before
  submitting it. Otherwise this incomplete unit would be
  sent to the decoder and cause some potential errors.

- move the functionality for checking the malformed packet
  and calculating the offset of the payload header to one
  function.

Crs-Fixed: 694476
Change-Id: Ie66524ac4b130c443c12bfb007593e5eb4a24019
frameworks/av: miscellaneous fixes

fixes for the following issues reported by KW

5978, 8879, 8880, 8881, 8882, 8883, 8889, 8890,
8892, 8893, 9200, 9201, 10210, 11223, 11224, 18001,
83677, 84525, 5897

Change-Id: I9bb98a07af97cbfc746b21738dfce7cd9e128c94
libstagefright: poke the udp hole twice for future incoming udp packets

- only firing off udp packets once to the source address or the endpoint
  could still be limited in some NAT network environment. As a result,
  client can't receive rtp packets over udp.

- send udp packets to both of the two addresses if they are available.

Change-Id: I7e8a0b36a82bcd85b307c9c15dcfee2bcd7e6030
rtsp: keep some damaged access unit to enhance fault tolerance

Make RTSPSource to accept some damaged access units of H263 to enhance
fault tolerance. Without this patch, damaged access can cause failure of
playback.

Change-Id: I905648f8b30fefa6ec8de18f943ede87641d7300
CRs-Fixed: 687252
Revert "appop: reimplement OP_RECORD_AUDIO op check in mediaserver"

 * This breaks various applications which use the effects API, like
   visualizers.

This reverts commit eb48405109a6a2d2a1d9cb2aaac36e5c71bb5f5b.

Change-Id: I7993aaff67a0aa5f815cc42d3670f3397d7582ac