audio: Fix crash in flinger during monkey runs

The trackrefptr in DirectTrack descriptor can be invalid and
this can result in a crash is stability runs. Add check for
validity of the trackrefptr before accessing it

Change-Id: I4c7fbff022f381f9d2cdbf0fc04ade8defbb2195
(cherry picked from commit 66917496a28241bf38f117cb05b5810021a185a0)
(cherry picked from commit e1c916bb324f4f6f7923b8e4b2a9c436a65534ff)
(cherry picked from commit dc983d3efd2a5ec3435246d4d2a2e1b4265b5f22)
audio: Remove assert for corrupt clips for AMRNB

Corrupt AMR NB clips were crashing media player
This was due to the assert in the AMRNB decoder.
To avoid this, post error and exit if corrupt
clip is played.
CRs-Fixed: 486681

Change-Id: I8f6809a896b91aaffa8f5ae17d8ae4a3920a4b73
(cherry picked from commit e4d611bee82ed1a7414a45ec0e72aa43cf13c751)
(cherry picked from commit 3276f106bec5eb19d2c3102fa9431f9621842bc5)
(cherry picked from commit 450d2230af162f29926be1475ff87e81d6d3f52d)
audio: Use High Quality resampler

Use very high quality resampler to upsample to 48KHz sample
rate.
CRs-fixed: 416730

Change-Id: I30420cbaa8f6d34e2bce408494cc08cb00b175a3
(cherry picked from commit 2904e01dd4a3921b7bc0bec71f63f4757204408b)
(cherry picked from commit 0302cfba74b948e5fb3b2adbcb9330b5dcc36595)
(cherry picked from commit 955a6569ab9d28fbfd6e1e234f06016fcbe5fb6b)
libstagefright: Add interlaced video support

- Adds call to set output buffer size on the native window

Change-Id: I4754e1f1d4d0bba375f719240499ef58c9e87ca2
(cherry picked from commit 63452051ea03bc48af85bd58767fd2a9b0ae13b6)
(cherry picked from commit 856b08a0c452a5d1e0b02487bcbebc44e55fd3e7)
(cherry picked from commit 8f445b519a7c3d107f4180ead01c9722b12b0adf)
libstagefright: optimize thumbnail generation path

- Checking for YUV420SP format support is not intended for software
  decoders and can be skipped. This avoids unnecessary creation of
  hardware decoders for checking supported output formats.
- Change the flag from kPreferSoftwareCodecs to kSoftwareCodecsOnly.
  This will force software codecs to be tried first and not just "prefer"
  which helps when a software codec for a particular type of codec (like
  divx) doesn't exist and avods creation of hardware codecs twice in case
  of hardware failure.

Change-Id: I682bca5b6bac5a56f46fe3655cd722fe5f08e1e6
(cherry picked from commit 78231ae0b4a7032c01c70b96191e6996d0462586)
(cherry picked from commit d35b1c63bb782dce49779839f496aaf927a3ae75)
(cherry picked from commit f1f3390ff2cf401a77b9f898e51b40f6e3f585ba)
ExtendedCodec: Enable timestamp reordering for MPEG4 codec type clips

MPEG4 codec type video clips can contain B frames. This change will
enable timestamp reordering for all MPEG4 codec type clips

CRs-Fixed: 539036

Change-Id: I7682a3781e6aa1b8e73418e4e73ee266c6338770
(cherry picked from commit 8d52ec137be60676c310bda168e8ce18d22dc534)
(cherry picked from commit 3b47eeb2cb5d595f2e755dcaa9e564eac8cbf33d)
(cherry picked from commit 9b47486f507fe834e4c5ab51524be8aa91df875b)
libstagefright: Use proper ctts offset

Calculate ctts offset as difference between composition
time and decoding time, and avoid adding kMaxCttsOffsetTimeUs
as it increases the sample timestamp by the same amount
which leads to av sync loss.

CRs-Fixed: 524739
Change-Id: I75a1bb594536623e3a445af2ee1ceb0cf0926a6e
(cherry picked from commit 863cb2bae6015b32c9ad12f074394c9a54c7bc47)
(cherry picked from commit 8e0e1a4330babf3c38152d48db1f2edf4db7a659)
(cherry picked from commit 87b09615f9473e369883142009d4035e37a2a806)
libstagefright: Fallback to software encoder for high resolutions

Add error check conditions to fallback to software encoder if
q6 encoder fails in configure codec. Q6 encoder fails
for resolutions greater than FWVGA

Change-Id: I4d765f45cd3b9c128260e7c96f139b671950d0ce

CRs-Fixed: 511608
(cherry picked from commit adbc58323ada4d9eb7473eb355f00b6d40825aaf)
(cherry picked from commit d5cb4f1f488b7dce47d9e1a8e4c37cfa4f43357d)
(cherry picked from commit 36b30a3be7f3658600ff9b068a341da55dde14b7)
libvideoeditor: use vWidth and vHeight for buffer allocation

Change-Id: I2ab01b8ef79a3ad9b1eb737b2e9f1211a6e668c2
 - video editor detects crop information from decoder, crop
   width and height will override metadata width and height.
 - decoder is capable of sending crop information where
   crop width and height are smaller than actual resolution.
 - use actual metadata width and height for calculating
   buffer size.
CRs-Fixed: 452511
(cherry picked from commit 93432b8b1c29b2dd62fad923ffa622b002311fa8)
(cherry picked from commit de34cceeb13eead49daf4a47f28bf49286917101)
(cherry picked from commit 865f7b2e0f034b0aea09ef5b13f401c776585bf2)
libstagefright: post video events dynamically - calculate amount of time to delay video event after renderusing the formula: delay = (us between frames)-(us taken by event)-(lateness)

Change-Id: I136ee19520200b26058099f88c8979d1e4e34e23
(cherry picked from commit 61ef39e403f708b014ca434eec35056815558deb)
(cherry picked from commit eb7422fb58a6f95f385574c4d845754db8da6b1f)
(cherry picked from commit 427260792cfa7a53fb27808ac24600a3ebfa7ca2)
frameworks/av: fix meta MIME type failure in MPEG4Writer

- MIME type info included in source->getFormat()
  is not updated properly because only temp
  variable is updated in AudioSource::getFormat().
  MIME type string contains garbage value and it
  results in invalid audio formats.
  MPEG4Writer returns ERROR_UNSUPPORTED and tunnel
  mode recording with 3gpp format fails
- Fix this issue by assigning return value of
  getFormat() to a local variable, and check the
  return value of findCString.

Change-Id: Iac167f0cf6d851604310ac371f059ab927cc362c
(cherry picked from commit 82afc116b9f8877ce60d8f5a9bde056e856d5b7e)
(cherry picked from commit b0e001df3dbe75f1be9300231615638a1f870995)
(cherry picked from commit 619602306b55061a4dabc922011e176eac487502)
audioflinger: Fix for removing noise while resuming playback after pause

-Issue: While resuming playback after pausing and seeking to backward,
there is a noise.
-Rootcause: When Resuming a Playback after Pausing and seeking,
AudioResampler's reset() function is resetting their member
variables but derived classes' s member variable are not resetting.
This is causing a noise in Playback because AudioResamplerSinc,
AudioResamplerOrder1 and AudioResamplerCubic's member variables
pointing to some previous state/values.
-Fix: To reset the derived class member variables,
override the reset function in all the derived classes.

CRs-Fixed: 482838

Change-Id: Ie023cb005b3085da411971a543f5a4290daab137
(cherry picked from commit 685bc9eac4bed32dd00fcb1e71f042b7e52e6958)
(cherry picked from commit 427702f0826c3f2b8b9173de70b31666666d9a19)
(cherry picked from commit 9c64f7ed9aba2c705168b8cdb94f98d85cf7da44)
(cherry picked from commit 296c767b6a9356855fa24fedf368ad52c367d348)
frameworks/av: AAC CSD support for MediaCodec path

- AudioFlush CTS test case is failing for AAC

- AAC Codec specific data is missing for
MediaCodec path for AAC if we use Qualcomm
ExtendedExtractor for demuxing

- Added CSD buffer while converting from
metadata to message , which can be used by
ACodec/MediaCodec

Change-Id: Ic8197138f5107f2a6026c28847e74987d91acc16
CRs-Fixed: 509575
(cherry picked from commit ae1b84bc3ead6a94e1383974e1bcba786b8e9354)
(cherry picked from commit 9e6ee7ae52b3bcb3cc76011d849e14a18f55bce5)
(cherry picked from commit 7edbc7b3a79cc65e355b8aa6025de15930fd0a2a)
libstagefright: Reset the decoder while performing seek

-Observed noise when seeking to beginning of file for the recorded
AMR clip.
-While performing seek, the AMR decoder states are not being reset.
In AMR decoder, the current frame output is predicted using the states
from previous frame. If these states are not cleared, it might cause
noise when seek is performed.
-Fixed by resetting the decoder when seek is issued and port flush
completion is notified to the decoder.

CRs-Fixed: 500851
Change-Id: Ia8480b88521abc09c8b01d6052df4730a0359518
(cherry picked from commit df2b77618d69ac10f1c41ffd5eedb92dd43e161d)
(cherry picked from commit 654f3ad1192bd210b27dbfe29f3cf75a4a3774d8)
(cherry picked from commit 6374b1a4bbf6e853d7214eee6c7177251d246c58)
libstagefright: notify updated stride to NativeWindow for DRC  -Notify updated stride after resolution switch to NativeWindow  to re-interpret the buffer layout  -CRs-fixed: 534910

Change-Id: I4c1427a4826c8d29f93064c34eb3e2eaeef434d7
(cherry picked from commit f93a1ed7561a3a29b73466054e8c43dcbb4c9a1e)
(cherry picked from commit fc948d949de674c4d978b9ca87dea039f4aa86bd)
(cherry picked from commit e5954f19fc67414620ce582a361dd09f5444a01c)
libstagefright: Fix crash in media server mpeg2 playback. -There is a check in dequeueAccessUnitMPEGAudio function inESQueue that  time stamp returned by fetchTimeStamp is alwaysgreater than 0 -In the current scenario, valid time stamp set on the firstframe is  getting replaced in the sub sequent code by -1. -Fix is to reset the flag after first frame is identified CRs-Fixed: 512218

Change-Id: I1be136fb8c8c3a88f46b88f42a1f200582fd1086
(cherry picked from commit 275b8f8d4047346fea7450b97a004c4e43e9a72b)
(cherry picked from commit 2a2bc3622413ac1d0304cffaec9603de77d5228d)
(cherry picked from commit 7836a4a64b3afb56689bc7384cb3dcdaa5a454c0)
frameworks/av: Fix for failure in CTS MediaRecorderTest cases

 -Issue: MediaRecorder CTS test cases are failing.

 -Root Cause: Running the CTS test "testRecorderRandomAction" at beginning
  sets the huge file size and stargeFrightRecorder set the 64 bit file
  offset.
  In MPEG4 writer estimateMoovBoxSize depends on a static const
  variable which uses this file offset info.
  As the variable to calculate estimateMoovBoxSize is static const it
  remains same for next media recording session even if file size is small.

 -Fix: Don't use static const variable which is used to calculate
  estimateMoovBoxSize as its value may change depending on file offsets.

Change-Id: I6bd859fcd7951a4e78abc50bc99dab38e8284877
(cherry picked from commit 0542e6f3af9e17559542764856f430ceaa255cac)
(cherry picked from commit 48fda261ceba7ed1c38c09e3282e9f9147bc03a0)
(cherry picked from commit 70af301150f7a5829f490b44da5caa596da76fa6)
audioflinger: Fix monkey crash in audioflinger set parameter.

-Track ref ptr is initialized to direct track pointer only in create
 Direct Track although the descriptor is created in open Output
-If there is a set parameter coming in during this time it could
 result in a crash as track ref ptr is not initialized.
-Initialize track ref ptr to NULL when descriptor is created.

Change-Id: Iee887baee45a9e7b381f6e2ea2ab523a23689f6b
(cherry picked from commit 10d4ae79b727f7191484f3adda13f9bba9d62c09)
(cherry picked from commit 7d130a825ad58e44b04cce4a4e3f4e4919337a7b)
(cherry picked from commit 0b72bac19b8f8988e385b06ede234ca80e2e2e07)
libstagefright: Flush the pending buffers when EOS is received

For the use case where the first frame in the buffer is EOS, decode
the aac config frame buffer to update the sample rate and channel
mode and flush out the buffer.
CRs-Fixed: 459334

Change-Id: I175dc531e00ec36a366a818366fa869cd6ccf5a1
(cherry picked from commit 2fe2d542b8c38cf9a585415256af9129ead5524a)
(cherry picked from commit 1a5104bde0b2bc7bf8321f67c7b02f24758233bf)
(cherry picked from commit e2c7e384d7bee7229a09c06d333d29397e15e3c0)
audio: Adding support for SRS effects

-Add support for SRS Trumedia post processing effects

Change-Id: I41b8983e1a59f5a84e10a21418d7731e6d8ec430
(cherry picked from commit 5b7c47861ce5e4afee2a3ce8e956e0cfec10cf29)
(cherry picked from commit e0ff892f774310e921f9926748ed9a3fe9784af3)
(cherry picked from commit 6d92096966d3dd16f5d08556e3b1273041d1cf58)