Fix a couple of nasty heap corruption bugs.

- When replacing the buffer pointer with another one, the allocated
  length wasn't updated. As the TI encoder relies of those being matched
up (it e.g. does a memset(pBuffer, 0, nAllocLen) at certain places), this
could lead to random memory being overwritten (or to a segfault when
reaching the end of the mapping)
- When replacing the buffer, the old buffer wasn't saved and restored
  before calling freeBuffer. This led to a different address passed to
free() than was returned by malloc(), could lead to all kinds of weird,
undefined behaviour.
Merge "Fix a couple of nasty heap corruption bugs." into ics
fixed typo in RIL_UNSOL_CDMA_PRL_CHANGED constant

Change-Id: I190022fc7fdd8b33a8ec14fdc712c1a99222b61f
clean up overridden unsolicited response

Problems fixed:
  - Cases 1031-1035 are now fully handled by RIL.java base class; override
    them here only for devices using GB radio libraries
  - Comments for cases 1031-1035 did not match the codes in ril.h (in ICS)
  - Case 1034 is RIL_CONNECTED - overriding it caused this message to be
    obscured and mRilVersion was never set and connection notification was
    not sent out (root cause for hanging SETUP_DATA_CALL on Skyrocket and Note)
  - Add case 1038 (DATA_NETWORK_STATE_CHANGED)

Change-Id: Ie0197446193111394833f40bfedf8e1516deb7db
Merge "clean up overridden unsolicited response" into ics
GlobalActions: Fix themeing of the ShutdownThread

Apply the correct UI context so the reboot dialog is properly
themed

Change-Id: I115c81538ab9c27223b2090279f877d5b68d6dd3
libstagefright: Squashed commit of updates from CodeAurora

libstagefright: Secure o/p buffers only when i/p buffers are secure

ION allocation fails on o/p buffers when i/p buffers are not secure. Disabling
secure allocation of o/p buffers when i/p buffers are not secure.

(cherry picked from commit ea10201ece24a3c61b79202b93e440eddb624d65)

Change-Id: I329c8428d3e528f7d177a64b8605090357f34035
CRs-Fixed: 336727

libstagefright: Synchronize access to OMX class member variables

- Protect mLiveNodes KeyedVector member variable in freeNode function
- This variable might be accessed concurrently if two OMXNodeInstance objects
  are freed.

(cherry picked from commit 796ea3f006ccac48a1fa1eae904667238c0ebbf6)

Change-Id: I01b12da57f44c1dfa978763c19de0041dc231b2b
CRs-Fixed: 332651

libstagefright: Fix HFR crash in MPEG4Writer

From ICS, for video kkeyframerate is used instead of kkeysamplerate. This
needed correction in MPEG4Writer.
kkeydecoding timestamp is used for sending the decoding timestamp. The
decoding timestamp had to updated for HFR.

Change-Id: I194a218b00ffcd41b1646a0c29c26a7a8f87e819

libstagefright: Increase bit rate for HFR recording

Increase bit rate for high frame rate (HFR) recording
feature to reflect the corresponding increase in frame rate

CRs-Fixed: 334201
(cherry picked from commit a5118e46646210f9e174c5d5db8c2cfa13e5bd65)

Change-Id: I1d77206e43d93ceef75a69113b124e2feb159663

libstagefright: Fix bitrate and I frame interval values for HFR mode

CRs-Fixed: 341667
(cherry picked from commit 331cf5e8dffb1bbd96a92a275730fd90d7d49b2c)

Change-Id: Icfd92689752951dbe6c2b659c9c4891ca30b8d62

libstagefright: Fix video encode I-frame interval setting

The i-frame interval setting is not configured properly when
b-frames are enabled.

Fixes the calculation for the i-frame interval setting when
b-frames are enabled.

CRs-Fixed: 348669
(cherry picked from commit 3fed07eac060215748b67e9d641f84bd684e6a2b)

Change-Id: Idbbeb1df638635336dd54dc2fe227d06a367ea79

libstagefright: Fix for b-frame encode and decode

- fix timestamp calculation during encode
  and playback for clips with b-frames

Change-Id: Ibe6658475c8bf9ceca05015b81536f6bac737da6

libstagefright: OMXCodec error handling fix

- Drop messages in OMXCodec ERROR state only for s/w OMX component

Change-Id: If9940f1f1429821587938fe005c526ab7559ff8e

libstagefright: Fix ANR issue for recording timelapse and b-frames videos.

CRs-Fixed: 340493
(cherry picked from commit 2f46989491d8f7f8ac480a39620803736101fd80)

Change-Id: I41ae8296fbc4cc480e7ad8ce4451c6fd5753d4b7

libstagefright: Free all video decoder output buffers on an error

- OMXCodec calls dequeueBuffer on the NativeWindow in a loop
  and registers output buffers with the OMX component
- If a dequeueBuffer fails, the buffers already registered
  with the OMX component were not getting freed laeding
  to a memory leak.

Change-Id: I56abc7577b10e7540bdd6488708ae6830b9d907b
CRs-Fixed: 351388
(cherry picked from commit 0d4e06d9a53240e0e7aca05a64faea353babb029)

libstagefright: Reset buffer size value with SurfaceTexture

- OMXCodec explicitly sets the decoder output buffer size using the
  native window perform API. (to accomodate extra-data)
- This size is reset only when the SurfaceTexture is destroyed.
- Unless reset, this size will be assumed for all output buffers
  if the SurfaceTexture is re-used.
CRs-Fixed: 337660

Change-Id: I28aed12ad02adeac61caffbb00e3082640a5f6d4
(cherry picked from commit 031e95469b897680670a2480e55be727d00bbd82)

libstagefright: Fix version and flag values for ctts box atom

- Write proper value for version 1 of ctts atom in MPEG4Writer
- Check against proper value for version 1 of ctts atom in SampleTable

CRs-Fixed: 340309
(cherry picked from commit 86de95c33ed597dc3b2f9b8db95c4115dfeb1c4b)

Change-Id: Iaa924870cadca501550d5ef838f4265a81c53d50

libstagefright: Add member variable to save arbitrary mode value

- Add member variable in OMXCodec to save aribtrary mode
  value. (default: true)
- Avoid overwriting the value of key kKeyUseArbitraryMode in
  track metadata. OMXCodec::Create gets a const pointer to
  the track metadata.

Change-Id: I94dd24933f112109a1469b2b2a24f0b82b19a104
CRs-Fixed: 340148
(cherry picked from commit e4c000bad2e669d156c82887070c5f37f7b1c00c)

libstagefright: Pass width and height in android_native_rect

- android_native_rect expects four fields; top, left, bottom, right.
- Contrary to what it looks like, the bottom and right fields
  are to be used as width & height (instead of co-ordinates)
- Fixing use of native_window_set_crop to use the adjusted values

(cherry picked from commit d1050e76b966a405e539a89a1aa2aee4c972b6ca)

Change-Id: I80f0de1c1e73d979f3499fcd0a7289e6ab00332b

libstagefright: Crop the native window with display resolution

We provide the native window with the display width and height in
set_geometry.  On the surfaceflinger side, they assume that this is
aligned, which causes problems for HDMI.  Instead we'll now pass in the
aligned stride and slice in native_window_set_geometry, then specify
the desired display width and height and call native_window_set_crop.

CRs-fixed: 332778
Change-Id: Iecfe11ded743715ea2eabad4a3fddbc1b04b5005
(cherry picked from commit 51b550aa2f6049a71261e2a5a76ae8a1450cd96b)

Conflicts:

	media/libstagefright/ACodec.cpp

libstagefright: Enable suspension policy

-ADSP did not enter suspend state after audio playback.
-No support for suspension policy in stagefright.
-Enable suspension policy for the OMX component to
take care of the power collapse in stagefright.
-Merged the three gingerbread changes 50118, 62031
 and 89989 for this

Change-Id: I92f545d2684dddb9ef398c93b8c941a6c842a9f9

Conflicts:

	media/libstagefright/OMXCodec.cpp

libstagefright: Encoder state check before calling OMX_FreeBuffer

- Add state check based on OMX IL specification before
  calling OMX_FreeBuffer.

CRs-Fixed: 337484
(cherry picked from commit d652e076b06bc6eb1a654e83e5229ffb09320668)

Change-Id: Ic958682fa792aa144774d71f34a182a00cb10efd

libstagefright: Fix for playback error during multiple play and pause

- When H/W decoder is used, in pause state empty this buffer is
not called from drainInputBuffer which blocks sending input
buffers to the omx component.
- When all the input buffers are processed by the omx component,
it keeps waiting for the new input buffers after resume.
- As the input buffers are not sent after resume, omx component
do not sent output since it does not have any input buffers to
decode. This is resulting in timeout on the output port.
- Modified IL client to fill all the empty input buffers at omx
start in case of H/W decoder.

CRs-Fixed: 340761
(cherry picked from commit 1ecd319917b0197c23fc53968065aac9380bad6b)

Change-Id: I530a4a91d91c01dd98fe6b818fe458dedb2ac9e0

libstagefright: Release output buffer when file limit is reached in recording

There is a memory leak in video recording when the
file size or duration limits are reached. The output
buffer copy is not released before exiting the track
thread in the mpeg4 writer.

To avoid the memory leak, the buffer copy is released
when a limit condition is detected in the mpeg4 writer.

Change-Id: Idfde2083fdd9997b3025c7c12e00f3ae4665b8da
CRs-Fixed: 315255
Merge "fixed typo in RIL_UNSOL_CDMA_PRL_CHANGED constant" into ics
Merge branch 'ics' of github.com:CyanogenMod/android_frameworks_base into opensensation