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
(cherry picked from commit 30d2c70eb85f6030d07c9b8f01d1ede6f65078e0)
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
(cherry picked from commit 97f50613f0cb9305b93c63bf426c6b8aec9026c9)
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
(cherry picked from commit 6d8f3925157574e644807ab9b5dc5a8c09a4f57f)
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
(cherry picked from commit 907e920112a717afec25a97435ad8884afd6e3ab)
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
(cherry picked from commit 928223ddce7c34540e99e03cceebb2435ade319f)
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
(cherry picked from commit 1d61b42ba93c692aa77a179097344c4378142bb5)
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
(cherry picked from commit 54471cfd96a29537ab475eff1a70c7040241b52a)