framework/av: Check for NULL pointer of mCblk and zero division error

latency calculation happens in two places: AudioTrack::latency() and
AudioTrack::dump(). Need to add null pointer and zero division check on
both of these places.

Change-Id: I9cbe8c1c00a390cd626bdbf202124f27e60eb3e3
Fixed-CRs: 548514
audioflinger: do not use raw pointer for tracks

Commit 9da3d95 surfaced a problem caused by the use of a raw
pointer to a track in offload thread implementation.

Pointers to tracks should always be weak or strong pointers.

Bug: 11708529.
Change-Id: Ic48632532d186c9be8261f73cefdf824b9fbbd2b
audioflinger: SRS effects are not working for LPA

    -Issue: If SRS effects are applied on LPA playback,
     in ARM side there is a delay of 4-5 seconds for effects
     application
    -Root cause: In applyEffects SRS effects are applied first and
     then Android effects are applied.
     In case of active android effects, SRS effects are called
     first and then android effects are called, so buffer with
     SRS effects is getting overwritten with buffer with
     android effects.
     If there are no android effects applied then all
     the SRS effects are overwritten with decoded data.
     So until next write call, SRS effects are not applied and hence delay
     of 4-5 seconds
    -Fix: In applyEffects first apply android effects and then
     apply SRS effects

Change-Id: I36b2133256d168f06b13c3d4a2bad00312d571ac
CRs-Fixed: 566278
audio: Supress redundant effect config events in short duration

Distortion sound persists for the whole song when re-enabling effect in
LPA playback mode till switch to next song. And pop noise is quite obvious
when enable/disable effects in LPA.

As the design of LPA, EffectsThreadEntry() loop is used to handle effect
config changes through applying effects with new config on dsp pcm buffers.
However, it can't handle too many config change events in a short time,
and effect with new configuration will be applied on part of dsp buffers.

Filter out redundant effect config events that come too closely to avoid
applying effect on dsp buffer in vain.

Change-Id: If8915b1d068724d5976e1519ec57e3c08cf89c9d
CRs-Fixed: 562806, 563418
framework/av: Fix for frame drop in video playback

- Breaks in video playback seen in video clips having audio content
  with sampling rates less than 16kHz.
- While extrapolating real time with system time, the real time is wrongly
  caped.
- Fix this issue by limiting the extrapolated real time only when EOS
  is reached.

Change-Id: I95b6a8f7f1f1fd561c92955cf52151ae2890c9a7
CRs-Fixed: 400398
audioflinger: Add Null pointer check while enabling effects for LPA

- MediaServer is crashing when disabling effects after mediaplayer
object is released.
- EffectChain pointer is de-referenced without NULL check, hence
leading to a mediaserver crash.
- Adding a NULL pointer check before using EffectChain object.

Change-Id: If5ff469445246028046ba65e5ddf3300180318c2
CRs-Fixed: 583305
Audio: Tunnel Exception for ER AAC ELD profile format

- some m4a clips are not working properly

- ADSP audio decoders don't support ER AAC ELD support

- Added tunnel exception for ER AAC ELD format.
  Added AACProfile metadata support for MKVExtractor

Change-Id: I2f6fe721b05377dfe0f24ea0ad1f6c4a885d576d
audio: Check the return code of MediaWriter::start

- Return code of MediaWriter::start method is not checked
  in startRawAudioRecording. Due to this, sound recorder
  application is not receiving the error whenever there is
  an error in starting of the recording
- Fix is to check the error and return it back to
  the client accordingly

Change-Id: I15916211da7a2eb0f27fbf9d4151410a8bdfdd42
CRs-Fixed: 591788
audio: Use composition instead of multiple inheritance

- AudioTrack is derived from BnDirectTrackClient along
  with RefBase to receive the notifications from
  AudioFlinger in tunnel/LPA mode. This is breaking
  binary compatibility for the clients which use native
  AudioTrack directly instead of Java based AudioTrack
  API
- Fix is to use composition here instead of inheritance

Change-Id: I9fd2c61cff5629924e3b08f63559679e0263bcfd
AudioMixer: fix artifact on 2 short sounds

On multiple devices, when 2 short sounds are played simultaneously, there will be artifact
on the speaker due to the buffer not being cleared.

A common example of this is lockscreen sounds during music playback.

Change-Id: Ifcdbbd7e443aa78ef392f14003d498404f2e4d3a

Conflicts:
	services/audioflinger/AudioMixer.cpp
mediaserver: conditionally launch ListenService

Conditionally instantiate ListenService from MediaService.
ListenServiceruns as a singleton in its own thread that calls
AudioHAL which in turn accesses Listen Driver. It is the entry
point from Application processes that want so execute Listen
commands and receive Voice detection events. It manages Listen
application resources and global states across all Listen
applications.

ListenService is similar to AudioFlinger. That is why it is
instantiated from MediaServer. Listenservice talks to AudioHAL
to deal with concurrent usage of mic.

Change-Id: I71c346bb16e0ed3a7aae9c908e03c7f1c694fe0a
update offloaded audio track sampling rate

AudioPlayer must read the sampling rate from offloaded audio sinks
whenever a new time position is computed as the decoder can update
the sampling rate on the fly.

Change-Id: I997e5248cfd4017aeceb4e11689324ded2a5bc88
AudioTrack: fix position callback after restore

When restoring an AudioTrack, the next position callback point
should not be modified and set ahead of current buffer head.
Otherwise, as frames are dropped, the new position is never reached
and an application relying on position callbacks to reload the buffer
would be stalled.

Bug: 11868603.
Change-Id: I93b2a311642a0c89944b78bcc0482d4ceed98ae4
fix deadlock issues that arise when there are simultaneous
effect control interface calls to proxy and to
non sub-effect wrappers(eg., bundlewrapper) from audioflinger
Also, return NO_ERROR when CMD_OFFLOAD succeeds

Whenever there are parallel calls to proxy and non sub-effects wrappers,
some of the calls are not completed. This is due to deadlock arsing out
of Proxy waiting for the subeffect call to return and subeffect waiting
for proxy to release lock.
The call flow is changed to a cleaner and simple one - Proxy gets the
aeli(effect library info) of subeffects during the EffectGetSubEffects()
call. Therby, proxy will manage the sub effects by itself rather than
going through effects factory.

Signed-off-by: jpadmana <jayashree.r.padmanaban@intel.com>
Bug: 12424044
Change-Id: I16852222f1d0e94e433a19177729323a4bb1c090
audioflinger: fix static track end detection

If a static track is not a fast track,
prepareTracks_l() must rely on framesReady() to
detect end of buffer and remove the track from the active
track list.
Failing to do so results in the track staying active but
not processed by the mixer because in underrun. This leaves the
mix buffer content uninitialized and causes the effect process
function to accumulate its output onto undefined data.

Bug: 12013676.
Change-Id: Iad72c921fa18d34811abf7d1073890c093a27725
AudioTrack: Never try to use the fast path if resampling is required

Unless AudioFlinger was built with FAST_TRACKS_AT_NON_NATIVE_SAMPLE_RATE
enabled, AudioFlinger would deny using the fast path (and internally
fall back to the normal codepath) when it realized that resampling
was required. Since the buffer size calculations within AudioFlinger
don't take resampling into account properly (see the calculation
below "AUDIO_OUTPUT_FLAG_FAST denied" in audioflinger/Threads.cpp,
just below the hunk that this patch changes), make sure AudioTrack
doesn't try to use the fast path if resampling is required.

This removes the possibility to enable
FAST_TRACKS_AT_NON_NATIVE_SAMPLE_RATE in AudioFlinger since it
AudioTrack now won't even try to use the fast path for content
that requires resampling, regardless of the AudioFlinger configuration.

Change-Id: Icf0f8ad50bf0fdb84657f518c0120aa0535f23f9
AudioFlinger: Remove code for supporting resampling in fast tracks

This isn't used at the moment.

Change-Id: I4e0fb2af5f7d959dbafd5ddb7defa1c6b8e8636a
audioflinger: Power hints for audio activity

 * Take 2, now with 100% less crashes!

Change-Id: I48fb0d2e3cfc64f46d99f177b4cf3fe842d06df4
libstagefright: Fix ANR issue in HTTP Streaming

The root cause of the ANRs during this usecase is the
blocking nature of the read calls on the network data
source due to which application thread gets blocked on
some lock in framework.

Fixes ANR during seek/pause during HTTP streaming
* Non-blocking read implmentation for NuCachedSource2
* Other framework related changes to handle underruns

Change-Id: Ief280b7e23727606746e1ca2bf4caa4a3044b7bc
Add 2 APIs (suspend/resume) in MediaPlayer

- API:suspend() will just pause the player and release all the decoders
  to replace release() which will release the whole player
- API:resume() will just init the decoders again,
  then start() will be called to start to play the streaming
- Add a check in AwesomePlayer::onVideoEvent()
  to make sure the first seek operation will always seek the next i-frame

Change-Id: Ie4c82906a2a056378119921a656128ebdc1007c4