audioflinger: forward device change to effects in direct thread

Device change during offload playback is not informed to effect chain
which causes effects still work on unexpected output devices. Add device
change notification in direct output thread.

CRs-Fixed: 630408

Change-Id: I094a99bdf540479cee2fca6614ec35c2fa7d6046
AudioTrack: When paused, return cached playback position

An offload output can be re-used between two audio tracks having
the same configuration. A timestamp query for a paused track
while the other is running would return an incorrect time.
To fix this, cache the playback position on a pause() and return
this time when requested until the track is resumed.

CRs-Fixed: 612943

Change-Id: I54b5a851ee3fa2ceadc37e3f5c6af4f37b8f404a
audio: mute duration at the beginning of recording

-AudioSource mutes for predefined duration (kAutoRampStartUs)
 at the beginning of a recording. Current kAutoRampStartUs
 is not sufficient to mute the shutter sound click on
 B-Family devices. Sometime shutter sound is getting recorded
 with the current kAutoRampStartUs.

-Issue with calculating muteDuration from getOutputLatency is,
 more delay is getting added for Bt(~1 sec) which is really not
 required.

-Fix is to use constant mute delay which is appropriate

Change-Id: Ied20dc44c56cc74c74fb001383d3c533cb54b632
CRs-Fixed: 636491
stagefright: Handle missing text track language

Only set timed text language if kKeyMediaLanguage is found.

Crs-Fixed: 641896

Change-Id: Ie471bc458e42f5728064e447ac5c33b07311d3fd
Fix kAutoRampDurationUs overflow issue

When kAutoRampDurationUs multiplies with mSampleRate, it overflows to int64.
Type cast it to int64 to make sure RampDurationUs properly.

BUg: 11162491
Change-Id: I4f93bc9acc8456e25623a9255ca7a5b206425009
audio: calculate mute duration using getOutputLatency

-AudioSource mutes for predefined duration
 (kAutoRampStartUs)  at the beginning of a recording.
 Since kAutoRampStartUs is zero, video recording tone
 is also getting recorded in the beggining.

-Fix is to get the output latency of current playback
 stream from audio system to calculate mute duration.

Change-Id: Ib9f4d38fcc8478d148719b70358644c581ba2f25
CRs-fixed: 615511
stagefright: Remove dead code

Change-Id: Ic543dfc5f1278dda1073e607fa9bdb381555256b
stagefright: enable traces for performance debugging

Trace number of video output buffers with OMXCodec, EBD,
FBD messages. Trace calculated sleep-delay in AwesomePlayer
and trace AudioPlayer::fillBuffer call.

Change-Id: Ib63fa4da48e690c79d57e134a6ad4519e396d198
libstagefright: Drain input buffer on resume

- Buffers returned from codec in paused state are not drained. When
codec is resumed these buffers are not drained until the next flush,
and may cause timed out issue.
- Added change to drain input buffers for sw decoders when resuming.

Change-Id: Ida2ab1d5dc3a1910accdd6fb89548262a912d8e7
CRs-Fixed: 569585, 574967
stagefright: ExtendedCodec: enable arbitrary/frame-by-frame mode

Based on the parser's hint, explicitly enable arbitrary or frame-
by-frame mode rather than assume component's default mode.

Change-Id: I0931b84f3757625d1e62311c2171ff48defcbe04
CRs-Fixed: 642025
stagefright: yield callbackDispatcher to writer safely

Dispatcher acquires the OMXCodec instance (add ref) and
removes ref each time it dispatches a message. If removing
of ref is not guarded by the lock, based on timing,
dispatcher thread might be the last one to own OMXCodec and
ends up deleting OMXCodec instance from its own context.
Destruction of OMXCodec from dispatcher's context will also
freeNode, remove dispatcher, forcing dispatch-thread to join
itself.
On Android, this will not block itself, but may lead
to a race condition where [b] comes before [a].
[a] wait for the thread to finish (join)
[b] return from destructor (delete object memory)

CRs-Fixed: 647460
Change-Id: I651f55a74dc0444d6d8d87a55cc6d27556fbb9f5
libstagefright/omx: Fix logic to handle dead observers.

  OMXNodeInstance freeNode tries to tear down OMX component
  if not in OMX_StateLoaded. It handles all other states except
  OMX_StatePause. This change adds OMX_StatePause handling.

Change-Id: I3bae2015c57b932186069756490c9bdf1f93eea4
StagefrightRecorder: Pause audio encoder on recorder pause

  When the recorder is paused, OMXCodec-based audio encoders will wait
  for output buffers, timing out after 3 seconds. Pause the audio encoder
  to avoid a timeout error.

CRs-Fixed: 634301
Change-Id: I99b95bf356f87e9c18c763c542cbfcc13bc54fb1
libstagefright: Copy the entire buffer from/to OMX component

Presence of OMX extradata in buffers isn't reflected as part of
nFilledLen.  To avoid omitting the extradata, copy the entire buffer.

Change-Id: Ib310dda3dc93693d4ab380912a9997d7ea120be1
stagefright: Handle acquireWakeLock failure case

When the power service is not running, acquireWakeLock fails, but
TimedEventQueue still keeps a reference count to a non-existent
wakelock. This causes an assertion failure when trying to free the
wakelock. Only increment the reference count and save the wakelock
reference on successful acquire.

CRs-Fixed: 640796
Change-Id: I441bf8d4c3520eb6ce8a378d2744913de0a44f55
audio: Fixed mBytesRemaining when partial buffers are sent

- When AudioFlinger writes partial buffers to HAL,
  write() on HAl returns period_size if bytes written
  are less than period_size. This is causing
  mBytesRemaining to be negative

- Fix is to check the return value of write() and
  set mBytesRemaining and mBytesWritten correctly

Change-Id: Ibd3cb138c0d4669e9e17c22f6b2c80804c6499a5
CRs-fixed: 611119
camera: add getBrightnessLumaTargetSet and getRawSize stubs for HTC hardware

Change-Id: Iddaee5376b7fef208d7619824b4b635faf75f0e7
libstagefright: Extended media support via FFMPEG

 * Original work by Michael Chen - https://github.com/omxcodec
 * Kitkat port from Android X86 project

libstagefright: add null checking to addPlugin

libstagefright: fix error handling of dlsym()

According 'man dlsym', a NULL return from dlsym() doesn't indicate an error.
The correct way to test for an error is to call dlerror() to clear any old
error conditions, then call dlsym(), and then call dlerror() again to check
whether its return value is not NULL.

libstagefright: add more media mimetypes

This is the first step to add the ffmpeg plugins.

libstagefright: add ExtractorPlugin

The patch allows to load an ExtractorPlugin to extend the functions of
DataSource::sniff and MediaExtractor. A plugin has to implement a C
function getExtractorPlugin to fill the MediaExtractor::Plugin struct.

The filename of the plugin could be specified by the
media.stagefright.extractor-plugin property.

Change-Id: I995a37a4f1ab4bba6ca3c24c7001a27a1e3ccb90

FLACExtractor: Add more sample rates support

In FLACExtractor.cpp, it has function to check file's sample rate.
If the input sample rate is not in its list, it will return "unsupported
sample rate" issue. Modify code to make other sample rates (100,1k,42k,46k)
pass the check

Issue: AXIA-1441
Change-Id: I48f91119275560ec6d00feb0dedc70d10aa55262
Signed-off-by: Xiaobing Feng <xiaobing.feng@windriver.com>
Signed-off-by: Matt Gumbel <matthew.k.gumbel@intel.com>

libstagefright: add ffmpeg components

libstagefright: add more decoders

Add support for wma, wmv, ra, ape, dts decoders.

Change-Id: Iaf48a806aa0cef7d9bcb848383fc3d778c8bd248

libstagefright: allow to use the extended extractor in priority

If the meta contains the string "extended-extractor-use",
use the extended extractor first.

add support for rv20, rv30

add ffmpeg heuristic decoder

Change-Id: I5eed11b563ca7f15d44bacfb795d6f3da08ab883

add HEVC(H.265) decoder and cleanup

Squashed the following commits of branch cm_maguro-10.1 from
https://github.com/omxcodec/android_frameworks_av.git
by Michael Chen <omxcodec@gmail.com>

defb904 remove MEDIA_MIMETYPE_AUDIO_MP2
8036958 add fetchUriFromFd func to get file name
91bc7d5 fix videoCompressionFormatString and audioCodingTypeString funcs
f03069f reset FRAME_DROP_FREQ to 0
718b99a add HEVC(H.265) decoder
84f8bf6 cleanup
f026c93 cleanup
440614a add debug info

Change-Id: Ie75db0778f633357e2280aef6d47a0fa3beb823e

AwesomePlayer: use AwesomeLocalRenderer for OMX.ffmpeg.* components

stagefright: Remove duplicate types from QC media defs

Change-Id: I50ecafe79a2985d0868a1ac82464d6ca448aa2c5
libstagefright: Re-introduce a QCOM_HARDWARE ifdef after the FFMPEG commit

Fixes a build error on non QCOM hardware.

Change-Id: I4a4268b351d0d8bf748dd03ccea0fbab20ed4314
DataSource: Remove global variables in DataSource related to sniff

Removed global variables related to sniff, and added Sniffer class
to implement the sniff functionality with non-static members.

Change-Id: I6fbd0ba5b686e09fda11d78cdd687a69c81a6bdf
CRs-Fixed: 567753