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
stagefright: Restore setting start-source-delta in Awesomeplayer

to account for the startup delay; failing to do so will
increase lateness (by startup) and drop frames

CRs-Fixed: 716459

Change-Id: I9a65a8125be079aaafb959fbb8012adba1ecd485
audio: Fixed time stamps for AMR WB buffers

- Time stamps are given in milli seconds in AudioSource but it is
  expected to be in micro seconds
- Fix is to convert it to micro seconds

Change-Id: Ib52d7ed6ca1d1ff798f804ef58c2cef7d9bd0455
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 for B-frames.

CRs-Fixed: 524739
Change-Id: I75a1bb594536623e3a445af2ee1ceb0cf0926a6e
audio: Fix for failure in CTS MediaRecorderTest cases

 -Issue: MediaRecorder CTS test cases are failing.

 -Running the CTS test "testRecorderRandomAction" at
  beginning sets the huge file size and StageFrightRecorder
  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.

 CRS-Fixed: 629448

Change-Id: Icdb8658a69667663ba686ae51755f461dd35712c
libstagefright: Fix to handle EAGAIN error on first read to source

 -Some of AV streaming clips are not played
 -In streaming use case when source does not have sufficent data it
  return error EAGAIN on first read request, player ignore this error
  and treat it as a first buffer.
 -Make the read request again to source on EAGAIN error.

Change-Id: I3feaccce757c17c4e80e6d62375c3d700ca29e72
audio:Avoid VideoLagUpdate if there is no AudioPlayer

-When AudioTrack is failed to initialized, mAudioPlayer
 is deleted in onVideoEvent but onVideoLagUpdate() is still
 trying to access mAudioPlayer which is leading to a crash.
 The function onVideoLagUpdate() is used to notify if video
 is lagging behind audio. So this function is no longer
 valid if AudioPlayer is deleted.

-Fix is to add a check for AudioPlayer in onVideoLagUpdate,
 which will avoid onVideoLagUpdate() if there is no
 AudioPlayer

Change-Id: Ie8dbfc1995a3da88a4a435ec2de86b1c22a07c65
CRs-Fixed: 647200
libstagefright: Fix incorrect progress bar display during device switch

 -During offload to nonoffload playback switch (speakr to a2dp)
  audiotear down happens which reset current postion and duration.
 -do not reset the file duration during audio tear down and return
  the cached current position if audioplayer is not created.

Change-Id: I924d270d57aee1a9e79cea1c33bbd6bb731b201d
frameworks/av: Avoid timestamp query to AudioPlayer during reset

-Timestamp query while in reset leads to ANR in few cases.
-Destruction of mutex in AudioTrack destructor during reset and
trying to lock the destroyed mutex as part of getPosition() call
in parallel leads to ANR.
-Avoid querying for timestamp in case reset operation is in progress.
Instead use mAudioTearDownPosition to retrieve current playback
position.

Change-Id: Ifaa7f6236ebce1b27a0cca621bbb188c94af142d
frameworks/av: Fix LOG_NDEBUG compilation errors

Cleans up undefined references due to scope & naming

Conflicts:
media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
Change-Id: Ib342e57c69353fb873c6c0e7ba66e62983676f61
libmedia: Add support for LCH tones

- Add the INCALL_MUSIC flag for tracks
  created for INCALL_MUSIC stream.
- Adding tones to the ToneGenerator that are
  to be used for Local Call Hold.

Change-Id: If4092630ec67b11fd2844d0218639a2c5ae6b687
libstagefright: Fix crash due to race condition

Crash occurs due to race condition between ACodec
and MediaCodec updating buffer metadata, as ACodec
overrides "omxFlags" field updated by MediaCodec,
which asserts that the "omxFields" field be present
while processing the buffer.

Added change to serialize the metadata update by
ACodedc and MediaCodec

Change-Id: Ib555490233c2bb227d2ff604ed6b01c80717d2ce
CRs-Fixed: 717809
CRs-Fixed: 714606
AppOps: Fix audio permission check.

Audio permission should be checked for applications initializing audio.
For video only case this check should not be executed.

Change-Id: I0fd2fa1d6c54a303551564e1a278e8b49b837f90
libstagefright: Add support for PCM in offload path

- If compress offload fails try to offload PCM
- Set PCM offload format if the audio mime is RAW/PCM

Change-Id: Ibab5cb2d73edd6e2e38cd32c05ef27612cbe1425
libstagefright: Enable logs for Bandwidth switch

Enabled logging for Bandwidth switch and printing segment information

Change-Id: I232eb09a145d65889986b1c434a2c008ae08225c
CRs-Fixed: 645106
audioflinger: update track ready condition

Signal track ready if the track isStopping().

Change-Id: Ie279995d5f90fa8211a20dfbeacc1cf9b921d0bf
CRs-Fixed: 592189
 libstagefright: Signal input EOS after last buffer is released

-In offload playback, sink stop is called at EOS from the sink call
 back when input EOS is reached. This is called before the last
 buffer is released.
-During seek to the end of clip ,drain can complete even before
 last buffer is released. This can cause playback to switch to
 next stream.
-Fix by ensuring sink stop is called only after the last buffer is
 released.

CRs-Fixed: 607104
Change-Id: I9cc45cc25b5f87dd878b26f76ea741323a0242a6
libstagefright/omx: Fix CallbackDispatcher dereference in callback.

findDispatcher can return NULL. Check for NULL.

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

-Sometimes shutter sound is getting recorded because
 current kAutoRampStartUs is not sufficient to mute the
 shutter sound

-Fix is to increase the kAutoRampStartUs to 500ms.

Change-Id: Id37b48c4bb7b5c903ef502f933eaff7be0ea566c
CRs-Fixed: 636491
libstagefright: fix ITTIAM MPEG4 1080p thumbnail issue

on target with ITTIAM, YUV420P if supported is preferred color
format for thumbnail generation, while YUV420SP is set by
default in ITTIAM decoder. Enable thumbnail mode to force
output format to be YUV420P in ITTIAM decoder.

Change-Id: Iff7b5277db3c01cc58d53904d1b8f635e6113542
CRs-Fixed: 675900