frameworks/av: Update to caf/kk_2.7_rb1.10

audio: Add track to trackToRemove list when it is terminated

- PlaybackThread loop is continuing for direct output even after
  the track is terminated by the client. This is causing 2 direct
  tracks being active when client starts another session
- Fix is add the terminated track to tracksToRemove list so that
  this track is destroyed properly

  CRs-Fixed: 566808

Change-Id: I65f565d9c3a00e071174659ffb92f711dfd8742a

audio: Fixed framecount in AudioRecord

- Incorrect frameCount is passed to AudioRecordClientProxy,
  which is used while user side pointer is incremented
  This is causing distortion in SIP call
- Fix is to use frameCount of the shared block instead of
  frameCount passed by the client
- InputBytes initialization is also done in AudioFlinger

CRs-Fixed: 568988

Change-Id: Iab32234b198ff4d792eea4c4a82097028089013d

audio: update setParameter command time properly

-setParameter is getting delayed regardless of delay is
 present or not. Because setparameter command time is always
 getting updated with wrong values(previous values) with any
 commands.
-Fix is to restrict the updation of command->mTime always.
 Added check to update command->mTime, only when identical
 commands are present.

Change-Id: I10b94b19f64ef4f15495d34f009238a691d1b36c
CRs-Fixed: 568318, 569010

audio: Initialize LPA variables in audioflinger

 - During initialization of audioflinger, a number of
variables related to LPA are not set to default values.
This causes an undesired side effect that the first
effect in the effect chain is considered to be LPA
enabled. Since LPA does not execute effect processing,
switching xLoud on/off does nothing
 - Fixed by initializing member variables in audioflinger.

Change-Id: Ide06fb0e6804558388e6610cc7686f168591e4a5

scale the kMaxCttsOffsetTimeUs for HFR recording

-timestampUs & decodingTimeUs are scaled for HFR recording
-the difference between these is compared against non-scaled
constant(kMaxCttsOffsetTimeUs).
-fix provided to scale this constant(kMaxCttsOffsetTimeUs)
-and compare against the scaled time difference.

Change-Id: I08188423008d8f6a4824f2748d56a1e355d39a89
CRs-Fixed: 566695

AudioFlinger.cpp - audioConfigChanged_l set for srs Tunnel Device Switch

 - During device switch we were only setting the route
   but was not calling audioConfigChanged_l
 - Hence the effects for the new device would apply only
   when there is a config change.
 - Now we call audioConfigChanged_l during device switch
   setPrameter so that the new effects will be apply as
   soon as device is switched.

Change-Id: I641cd8a7d6ffb7423ccfaa45e4c29b1b5352e61e
CRs-Fixed: 548021

Revert "frameworks/av: AAC CSD support for MediaCodec path"

This reverts commit Ic8197138f5107f2a6026c28847e74987d91acc16
Currently AAC CSD is retrieved in MediaCodec using
kKeyAacCodecSpecificData. This support was added as part of
commit Id046b0d4bf96f029c1b6b5d78d753073e38ac841.

Change-Id: I54bc6204c1fe88f4e4545f501e6bd1bb2a8beaf9
CRs-Fixed: 527284
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 84df353..a3ee6c2 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -567,7 +567,7 @@
     void *buffers = (char*)cblk + sizeof(audio_track_cblk_t);
 
     // update proxy
-    mProxy = new AudioRecordClientProxy(cblk, buffers, mFrameCount, mFrameSize);
+    mProxy = new AudioRecordClientProxy(cblk, buffers, mCblk->frameCount_, mFrameSize);
     mProxy->setEpoch(epoch);
     mProxy->setMinimum(mNotificationFramesAct);
 
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 596a069..06a7beb 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -2301,6 +2301,7 @@
              * Decoding time: decodingTimeUs
              * Composition time offset = composition time - decoding time
              */
+            int64_t tmpCttsOffsetTimeUs;
             int64_t decodingTimeUs;
             CHECK(meta_data->findInt64(kKeyDecodingTime, &decodingTimeUs));
 #ifdef QCOM_HARDWARE
@@ -2310,7 +2311,9 @@
             decodingTimeUs -= previousPausedDurationUs;
             cttsOffsetTimeUs =
                     timestampUs - decodingTimeUs;
-            CHECK_GE(kMaxCttsOffsetTimeUs, decodingTimeUs - timestampUs);
+            tmpCttsOffsetTimeUs = kMaxCttsOffsetTimeUs;
+            ExtendedUtils::HFR::reCalculateTimeStamp(mMeta, tmpCttsOffsetTimeUs);
+            CHECK_GE(tmpCttsOffsetTimeUs, decodingTimeUs - timestampUs);
             timestampUs = decodingTimeUs;
             ALOGV("decoding time: %lld and ctts offset time: %lld",
                 timestampUs, cttsOffsetTimeUs);
diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp
index 124205c..09c9b3e 100755
--- a/media/libstagefright/Utils.cpp
+++ b/media/libstagefright/Utils.cpp
@@ -36,10 +36,6 @@
 #include <media/stagefright/ExtendedCodec.h>
 #endif
 
-#ifdef ENABLE_AV_ENHANCEMENTS
-#include "QCMetaData.h"
-#endif
-
 namespace android {
 
 uint16_t U16_AT(const uint8_t *ptr) {
@@ -135,30 +131,6 @@
         if (meta->findInt32(kKeyIsADTS, &isADTS)) {
             msg->setInt32("is-adts", true);
         }
-
-#ifdef ENABLE_AV_ENHANCEMENTS
-        uint32_t type;
-        const void *data;
-        size_t size;
-
-        if (meta->findData(kKeyAacCodecSpecificData, &type, &data, &size)) {
-            if (size > 0 && data != NULL) {
-                sp<ABuffer> buffer = new ABuffer(size);
-                if (buffer != NULL) {
-                    memcpy(buffer->data(), data, size);
-                    buffer->meta()->setInt32("csd", true);
-                    buffer->meta()->setInt64("timeUs", 0);
-                    msg->setBuffer("csd-0", buffer);
-                }
-                else {
-                    ALOGE("kKeyAacCodecSpecificData ABuffer Allocation failed");
-                }
-            }
-            else {
-                ALOGE("Not a valid data pointer or size == 0");
-            }
-       }
-#endif
     }
 
     int32_t maxInputSize;
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 28715d6..a00e42e 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -191,6 +191,9 @@
     Mutex::Autolock _l(mLock);
 
     /* TODO: move all this work into an Init() function */
+    mLPASessionId = -2; // -2 is invalid session ID
+    mIsEffectConfigChanged = false;
+    mLPAEffectChain = NULL;
     char val_str[PROPERTY_VALUE_MAX] = { 0 };
     if (property_get("ro.audio.flinger_standbytime_ms", val_str, NULL) >= 0) {
         uint32_t int_val;
@@ -1127,6 +1130,8 @@
 #ifdef SRS_PROCESSING
                 ALOGV("setParameters:: routing change to device %d", device);
                 POSTPRO_PATCH_ICS_OUTPROC_MIX_ROUTE(desc->trackRefPtr, param, device);
+                if(desc->flag & AUDIO_OUTPUT_FLAG_TUNNEL)
+                    audioConfigChanged_l(AudioSystem::EFFECT_CONFIG_CHANGED, 0, NULL);
 #endif
                 if(mLPAEffectChain != NULL){
                     mLPAEffectChain->setDevice_l(device);
diff --git a/services/audioflinger/AudioPolicyService.cpp b/services/audioflinger/AudioPolicyService.cpp
index de21985..4cb6df5 100644
--- a/services/audioflinger/AudioPolicyService.cpp
+++ b/services/audioflinger/AudioPolicyService.cpp
@@ -1033,7 +1033,9 @@
             } else {
                 data2->mKeyValuePairs = param2.toString();
             }
-            command->mTime = command2->mTime;
+            if (!strcmp(data2->mKeyValuePairs.string(), data->mKeyValuePairs.string())){
+                command->mTime = command2->mTime;
+            }
             // force delayMs to non 0 so that code below does not request to wait for
             // command status as the command is now delayed
             delayMs = 1;
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index aa9097b..7559d4c 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -3718,7 +3718,8 @@
                 // TODO: implement behavior for compressed audio
                 size_t audioHALFrames = (latency_l() * mSampleRate) / 1000;
                 size_t framesWritten = mBytesWritten / mFrameSize;
-                if (mStandby || track->presentationComplete(framesWritten, audioHALFrames)) {
+                if (mStandby || track->presentationComplete(framesWritten, audioHALFrames) ||
+                        track->isTerminated()) {
                     if (track->isStopped()) {
                         track->reset();
                     }