Merge "Fix race condition for non-started fast tracks" into jb-dev
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
index 3891809..6d304e0 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -75,9 +75,8 @@
     AUDIO_ENCODER_AMR_NB = 1,
     AUDIO_ENCODER_AMR_WB = 2,
     AUDIO_ENCODER_AAC = 3,
-    AUDIO_ENCODER_AAC_PLUS = 4,
-    AUDIO_ENCODER_EAAC_PLUS = 5,
-    AUDIO_ENCODER_AAC_ELD = 6,
+    AUDIO_ENCODER_HE_AAC = 4,
+    AUDIO_ENCODER_AAC_ELD = 5,
 
     AUDIO_ENCODER_LIST_END // must be the last - used to validate the audio encoder type
 };
diff --git a/media/libmedia/MediaProfiles.cpp b/media/libmedia/MediaProfiles.cpp
index c08f033..6929efa 100644
--- a/media/libmedia/MediaProfiles.cpp
+++ b/media/libmedia/MediaProfiles.cpp
@@ -44,7 +44,8 @@
     {"amrnb",  AUDIO_ENCODER_AMR_NB},
     {"amrwb",  AUDIO_ENCODER_AMR_WB},
     {"aac",    AUDIO_ENCODER_AAC},
-    {"aaceld", AUDIO_ENCODER_AAC_ELD},
+    {"heaac",  AUDIO_ENCODER_HE_AAC},
+    {"aaceld", AUDIO_ENCODER_AAC_ELD}
 };
 
 const MediaProfiles::NameToTagMap MediaProfiles::sFileFormatMap[] = {
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index b676cc7..727fd0d 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -820,10 +820,15 @@
             mime = MEDIA_MIMETYPE_AUDIO_AAC;
             encMeta->setInt32(kKeyAACProfile, OMX_AUDIO_AACObjectLC);
             break;
+        case AUDIO_ENCODER_HE_AAC:
+            mime = MEDIA_MIMETYPE_AUDIO_AAC;
+            encMeta->setInt32(kKeyAACProfile, OMX_AUDIO_AACObjectHE);
+            break;
         case AUDIO_ENCODER_AAC_ELD:
             mime = MEDIA_MIMETYPE_AUDIO_AAC;
             encMeta->setInt32(kKeyAACProfile, OMX_AUDIO_AACObjectELD);
             break;
+
         default:
             ALOGE("Unknown audio encoder: %d", mAudioEncoder);
             return NULL;
@@ -844,7 +849,6 @@
 
     OMXClient client;
     CHECK_EQ(client.connect(), (status_t)OK);
-
     sp<MediaSource> audioEncoder =
         OMXCodec::Create(client.interface(), encMeta,
                          true /* createEncoder */, audioSource);
@@ -859,6 +863,7 @@
     CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_AAC_ADTS);
 
     CHECK(mAudioEncoder == AUDIO_ENCODER_AAC ||
+          mAudioEncoder == AUDIO_ENCODER_HE_AAC ||
           mAudioEncoder == AUDIO_ENCODER_AAC_ELD);
     CHECK(mAudioSource != AUDIO_SOURCE_CNT);
 
@@ -977,7 +982,9 @@
     sp<MediaWriter> writer = new MPEG2TSWriter(mOutputFd);
 
     if (mAudioSource != AUDIO_SOURCE_CNT) {
-        if (mAudioEncoder != AUDIO_ENCODER_AAC) {
+        if (mAudioEncoder != AUDIO_ENCODER_AAC &&
+            mAudioEncoder != AUDIO_ENCODER_HE_AAC &&
+            mAudioEncoder != AUDIO_ENCODER_AAC_ELD) {
             return ERROR_UNSUPPORTED;
         }
 
@@ -1442,6 +1449,7 @@
         case AUDIO_ENCODER_AMR_NB:
         case AUDIO_ENCODER_AMR_WB:
         case AUDIO_ENCODER_AAC:
+        case AUDIO_ENCODER_HE_AAC:
         case AUDIO_ENCODER_AAC_ELD:
             break;
 
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index 2169cac..e2e5091 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -91,8 +91,6 @@
 LOCAL_STATIC_LIBRARIES := \
         libstagefright_color_conversion \
         libstagefright_aacenc \
-        libstagefright_avcenc \
-        libstagefright_m4vh263enc \
         libstagefright_matroska \
         libstagefright_timedtext \
         libvpx \
diff --git a/media/libstagefright/MediaCodecList.cpp b/media/libstagefright/MediaCodecList.cpp
index c39aa77..9f6d4a3 100644
--- a/media/libstagefright/MediaCodecList.cpp
+++ b/media/libstagefright/MediaCodecList.cpp
@@ -61,11 +61,6 @@
         // These are currently still used by the video editing suite.
 
         addMediaCodec(true /* encoder */, "AACEncoder", "audio/mp4a-latm");
-        addMediaCodec(true /* encoder */, "AVCEncoder", "video/avc");
-
-        addMediaCodec(true /* encoder */, "M4vH263Encoder");
-        addType("video/3gpp");
-        addType("video/mp4v-es");
 
         addMediaCodec(
                 false /* encoder */, "OMX.google.raw.decoder", "audio/raw");
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index fb6491b..791e044 100755
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -19,8 +19,6 @@
 #include <utils/Log.h>
 
 #include "include/AACEncoder.h"
-#include "include/AVCEncoder.h"
-#include "include/M4vH263Encoder.h"
 
 #include "include/ESDS.h"
 
@@ -67,8 +65,6 @@
 #define FACTORY_REF(name) { #name, Make##name },
 
 FACTORY_CREATE_ENCODER(AACEncoder)
-FACTORY_CREATE_ENCODER(AVCEncoder)
-FACTORY_CREATE_ENCODER(M4vH263Encoder)
 
 static sp<MediaSource> InstantiateSoftwareEncoder(
         const char *name, const sp<MediaSource> &source,
@@ -80,8 +76,6 @@
 
     static const FactoryInfo kFactoryInfo[] = {
         FACTORY_REF(AACEncoder)
-        FACTORY_REF(AVCEncoder)
-        FACTORY_REF(M4vH263Encoder)
     };
     for (size_t i = 0;
          i < sizeof(kFactoryInfo) / sizeof(kFactoryInfo[0]); ++i) {
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
index 547a554..bf7befd 100644
--- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
+++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
@@ -142,9 +142,9 @@
                 aacParams->nSampleRate = 44100;
                 aacParams->nFrameLength = 0;
             } else {
-                aacParams->nChannels = mStreamInfo->channelConfig;
-                aacParams->nSampleRate = mStreamInfo->aacSampleRate;
-                aacParams->nFrameLength = mStreamInfo->aacSamplesPerFrame;
+                aacParams->nChannels = mStreamInfo->numChannels;
+                aacParams->nSampleRate = mStreamInfo->sampleRate;
+                aacParams->nFrameLength = mStreamInfo->frameSize;
             }
 
             return OMX_ErrorNone;
@@ -175,7 +175,7 @@
                 pcmParams->nChannels = 1;
                 pcmParams->nSamplingRate = 44100;
             } else {
-                pcmParams->nChannels = mStreamInfo->channelConfig;
+                pcmParams->nChannels = mStreamInfo->numChannels;
                 pcmParams->nSamplingRate = mStreamInfo->sampleRate;
             }
 
@@ -185,6 +185,7 @@
         default:
             return SimpleSoftOMXComponent::internalGetParameter(index, params);
     }
+
 }
 
 OMX_ERRORTYPE SoftAAC2::internalSetParameter(
@@ -254,7 +255,6 @@
     UCHAR* inBuffer[FILEREAD_MAX_LAYERS];
     UINT inBufferLength[FILEREAD_MAX_LAYERS] = {0};
     UINT bytesValid[FILEREAD_MAX_LAYERS] = {0};
-    AAC_DECODER_ERROR decoderErr;
 
     List<BufferInfo *> &inQueue = getPortQueue(0);
     List<BufferInfo *> &outQueue = getPortQueue(1);
@@ -277,7 +277,6 @@
             notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, NULL);
             return;
         }
-
         inQueue.erase(inQueue.begin());
         info->mOwnedByUs = false;
         notifyEmptyBufferDone(header);
@@ -303,10 +302,16 @@
             // the AACDEC_FLUSH flag set
             INT_PCM *outBuffer =
                     reinterpret_cast<INT_PCM *>(outHeader->pBuffer + outHeader->nOffset);
-            decoderErr = aacDecoder_DecodeFrame(mAACDecoder,
-                                                outBuffer,
-                                                outHeader->nAllocLen,
-                                                AACDEC_FLUSH);
+            AAC_DECODER_ERROR decoderErr = aacDecoder_DecodeFrame(mAACDecoder,
+                                                                  outBuffer,
+                                                                  outHeader->nAllocLen,
+                                                                  AACDEC_FLUSH);
+            if (decoderErr != AAC_DEC_OK) {
+                mSignalledError = true;
+                notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, NULL);
+                return;
+            }
+
             outHeader->nFilledLen =
                     mStreamInfo->frameSize * sizeof(int16_t) * mStreamInfo->numChannels;
             outHeader->nFlags = OMX_BUFFERFLAG_EOS;
@@ -352,23 +357,27 @@
             inBufferLength[0] = inHeader->nFilledLen;
         }
 
-
         // Fill and decode
         INT_PCM *outBuffer = reinterpret_cast<INT_PCM *>(outHeader->pBuffer + outHeader->nOffset);
         bytesValid[0] = inBufferLength[0];
 
         int flags = mInputDiscontinuity ? AACDEC_INTR : 0;
         int prevSampleRate = mStreamInfo->sampleRate;
-        decoderErr = aacDecoder_Fill(mAACDecoder,
-                                     inBuffer,
-                                     inBufferLength,
-                                     bytesValid);
+        int prevNumChannels = mStreamInfo->numChannels;
 
-        decoderErr = aacDecoder_DecodeFrame(mAACDecoder,
-                                            outBuffer,
-                                            outHeader->nAllocLen,
-                                            flags);
+        AAC_DECODER_ERROR decoderErr = AAC_DEC_NOT_ENOUGH_BITS;
+        while (bytesValid[0] > 0 && decoderErr == AAC_DEC_NOT_ENOUGH_BITS) {
+            aacDecoder_Fill(mAACDecoder,
+                            inBuffer,
+                            inBufferLength,
+                            bytesValid);
 
+            decoderErr = aacDecoder_DecodeFrame(mAACDecoder,
+                                                outBuffer,
+                                                outHeader->nAllocLen,
+                                                flags);
+
+        }
         mInputDiscontinuity = false;
 
         /*
@@ -386,7 +395,8 @@
          * AAC+/eAAC+ until the first data frame is decoded.
          */
         if (mInputBufferCount <= 2) {
-            if (mStreamInfo->sampleRate != prevSampleRate) {
+            if (mStreamInfo->sampleRate != prevSampleRate ||
+                mStreamInfo->numChannels != prevNumChannels) {
                 // We're going to want to revisit this input buffer, but
                 // may have already advanced the offset. Undo that if
                 // necessary.
diff --git a/media/libstagefright/codecs/aacenc/SoftAACEncoder2.cpp b/media/libstagefright/codecs/aacenc/SoftAACEncoder2.cpp
index 4947fb2..7719435 100644
--- a/media/libstagefright/codecs/aacenc/SoftAACEncoder2.cpp
+++ b/media/libstagefright/codecs/aacenc/SoftAACEncoder2.cpp
@@ -239,7 +239,6 @@
             mBitRate = aacParams->nBitRate;
             mNumChannels = aacParams->nChannels;
             mSampleRate = aacParams->nSampleRate;
-
             if (aacParams->eAACProfile != OMX_AUDIO_AACObjectNull) {
                 mAACProfile = aacParams->eAACProfile;
             }
@@ -262,7 +261,6 @@
 
             mNumChannels = pcmParams->nChannels;
             mSampleRate = pcmParams->nSamplingRate;
-
             if (setAudioParams() != OK) {
                 return OMX_ErrorUndefined;
             }
@@ -275,7 +273,7 @@
     }
 }
 
-CHANNEL_MODE getChannelMode(OMX_U32 nChannels) {
+static CHANNEL_MODE getChannelMode(OMX_U32 nChannels) {
     CHANNEL_MODE chMode = MODE_INVALID;
     switch (nChannels) {
         case 1: chMode = MODE_1; break;
@@ -289,6 +287,19 @@
     return chMode;
 }
 
+static AUDIO_OBJECT_TYPE getAOTFromProfile(OMX_U32 profile) {
+    if (profile == OMX_AUDIO_AACObjectLC) {
+        return AOT_AAC_LC;
+    } else if (profile == OMX_AUDIO_AACObjectHE) {
+        return AOT_SBR;
+    } else if (profile == OMX_AUDIO_AACObjectELD) {
+        return AOT_ER_AAC_ELD;
+    } else {
+        ALOGW("Unsupported AAC profile - defaulting to AAC-LC");
+        return AOT_AAC_LC;
+    }
+}
+
 status_t SoftAACEncoder2::setAudioParams() {
     // We call this whenever sample rate, number of channels or bitrate change
     // in reponse to setParameter calls.
@@ -297,7 +308,7 @@
          mSampleRate, mNumChannels, mBitRate);
 
     if (AACENC_OK != aacEncoder_SetParam(mAACEncoder, AACENC_AOT,
-            mAACProfile == OMX_AUDIO_AACObjectELD ? AOT_ER_AAC_ELD : AOT_AAC_LC)) {
+            getAOTFromProfile(mAACProfile))) {
         ALOGE("Failed to set AAC encoder parameters");
         return UNKNOWN_ERROR;
     }
@@ -341,12 +352,17 @@
         }
 
         if (AACENC_OK != aacEncEncode(mAACEncoder, NULL, NULL, NULL, NULL)) {
-            ALOGE("Failed to initialize AAC encoder");
+            ALOGE("Unable to initialize encoder for profile / sample-rate / bit-rate / channels");
             notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
             mSignalledError = true;
             return;
         }
 
+        OMX_U32 actualBitRate  = aacEncoder_GetParam(mAACEncoder, AACENC_BITRATE);
+        if (mBitRate != actualBitRate) {
+            ALOGW("Requested bitrate %lu unsupported, using %lu", mBitRate, actualBitRate);
+        }
+
         AACENC_InfoStruct encInfo;
         if (AACENC_OK != aacEncInfo(mAACEncoder, &encInfo)) {
             ALOGE("Failed to get AAC encoder info");
@@ -373,7 +389,7 @@
     size_t numBytesPerInputFrame =
         mNumChannels * kNumSamplesPerFrame * sizeof(int16_t);
 
-    // BUGBUG: Fraunhofer's decoder chokes on large chunks of AAC-ELD
+    // Limit input size so we only get one ELD frame
     if (mAACProfile == OMX_AUDIO_AACObjectELD && numBytesPerInputFrame > 512) {
         numBytesPerInputFrame = 512;
     }
@@ -402,7 +418,7 @@
             }
 
             if (mInputFrame == NULL) {
-                mInputFrame = new int16_t[kNumSamplesPerFrame * mNumChannels];
+                mInputFrame = new int16_t[numBytesPerInputFrame / sizeof(int16_t)];
             }
 
             if (mInputSize == 0) {
@@ -490,6 +506,7 @@
         // Encode the mInputFrame, which is treated as a modulo buffer
         AACENC_ERROR encoderErr = AACENC_OK;
         size_t nOutputBytes = 0;
+
         do {
             memset(&outargs, 0, sizeof(outargs));
 
diff --git a/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp b/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp
deleted file mode 100644
index 7533f07..0000000
--- a/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp
+++ /dev/null
@@ -1,619 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "AVCEncoder"
-#include <utils/Log.h>
-
-#include "AVCEncoder.h"
-
-#include "avcenc_api.h"
-#include "avcenc_int.h"
-#include "OMX_Video.h"
-
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/MediaBufferGroup.h>
-#include <media/stagefright/MediaDefs.h>
-#include <media/stagefright/MediaErrors.h>
-#include <media/stagefright/MetaData.h>
-#include <media/stagefright/Utils.h>
-
-namespace android {
-
-static status_t ConvertOmxAvcProfileToAvcSpecProfile(
-        int32_t omxProfile, AVCProfile* pvProfile) {
-    ALOGV("ConvertOmxAvcProfileToAvcSpecProfile: %d", omxProfile);
-    switch (omxProfile) {
-        case OMX_VIDEO_AVCProfileBaseline:
-            *pvProfile = AVC_BASELINE;
-            return OK;
-        default:
-            ALOGE("Unsupported omx profile: %d", omxProfile);
-    }
-    return BAD_VALUE;
-}
-
-static status_t ConvertOmxAvcLevelToAvcSpecLevel(
-        int32_t omxLevel, AVCLevel *pvLevel) {
-    ALOGV("ConvertOmxAvcLevelToAvcSpecLevel: %d", omxLevel);
-    AVCLevel level = AVC_LEVEL5_1;
-    switch (omxLevel) {
-        case OMX_VIDEO_AVCLevel1:
-            level = AVC_LEVEL1_B;
-            break;
-        case OMX_VIDEO_AVCLevel1b:
-            level = AVC_LEVEL1;
-            break;
-        case OMX_VIDEO_AVCLevel11:
-            level = AVC_LEVEL1_1;
-            break;
-        case OMX_VIDEO_AVCLevel12:
-            level = AVC_LEVEL1_2;
-            break;
-        case OMX_VIDEO_AVCLevel13:
-            level = AVC_LEVEL1_3;
-            break;
-        case OMX_VIDEO_AVCLevel2:
-            level = AVC_LEVEL2;
-            break;
-        case OMX_VIDEO_AVCLevel21:
-            level = AVC_LEVEL2_1;
-            break;
-        case OMX_VIDEO_AVCLevel22:
-            level = AVC_LEVEL2_2;
-            break;
-        case OMX_VIDEO_AVCLevel3:
-            level = AVC_LEVEL3;
-            break;
-        case OMX_VIDEO_AVCLevel31:
-            level = AVC_LEVEL3_1;
-            break;
-        case OMX_VIDEO_AVCLevel32:
-            level = AVC_LEVEL3_2;
-            break;
-        case OMX_VIDEO_AVCLevel4:
-            level = AVC_LEVEL4;
-            break;
-        case OMX_VIDEO_AVCLevel41:
-            level = AVC_LEVEL4_1;
-            break;
-        case OMX_VIDEO_AVCLevel42:
-            level = AVC_LEVEL4_2;
-            break;
-        case OMX_VIDEO_AVCLevel5:
-            level = AVC_LEVEL5;
-            break;
-        case OMX_VIDEO_AVCLevel51:
-            level = AVC_LEVEL5_1;
-            break;
-        default:
-            ALOGE("Unknown omx level: %d", omxLevel);
-            return BAD_VALUE;
-    }
-    *pvLevel = level;
-    return OK;
-}
-
-inline static void ConvertYUV420SemiPlanarToYUV420Planar(
-        uint8_t *inyuv, uint8_t* outyuv,
-        int32_t width, int32_t height) {
-
-    int32_t outYsize = width * height;
-    uint32_t *outy =  (uint32_t *) outyuv;
-    uint16_t *outcb = (uint16_t *) (outyuv + outYsize);
-    uint16_t *outcr = (uint16_t *) (outyuv + outYsize + (outYsize >> 2));
-
-    /* Y copying */
-    memcpy(outy, inyuv, outYsize);
-
-    /* U & V copying */
-    uint32_t *inyuv_4 = (uint32_t *) (inyuv + outYsize);
-    for (int32_t i = height >> 1; i > 0; --i) {
-        for (int32_t j = width >> 2; j > 0; --j) {
-            uint32_t temp = *inyuv_4++;
-            uint32_t tempU = temp & 0xFF;
-            tempU = tempU | ((temp >> 8) & 0xFF00);
-
-            uint32_t tempV = (temp >> 8) & 0xFF;
-            tempV = tempV | ((temp >> 16) & 0xFF00);
-
-            // Flip U and V
-            *outcb++ = tempV;
-            *outcr++ = tempU;
-        }
-    }
-}
-
-static int32_t MallocWrapper(
-        void *userData, int32_t size, int32_t attrs) {
-    return reinterpret_cast<int32_t>(malloc(size));
-}
-
-static void FreeWrapper(void *userData, int32_t ptr) {
-    free(reinterpret_cast<void *>(ptr));
-}
-
-static int32_t DpbAllocWrapper(void *userData,
-        unsigned int sizeInMbs, unsigned int numBuffers) {
-    AVCEncoder *encoder = static_cast<AVCEncoder *>(userData);
-    CHECK(encoder != NULL);
-    return encoder->allocOutputBuffers(sizeInMbs, numBuffers);
-}
-
-static int32_t BindFrameWrapper(
-        void *userData, int32_t index, uint8_t **yuv) {
-    AVCEncoder *encoder = static_cast<AVCEncoder *>(userData);
-    CHECK(encoder != NULL);
-    return encoder->bindOutputBuffer(index, yuv);
-}
-
-static void UnbindFrameWrapper(void *userData, int32_t index) {
-    AVCEncoder *encoder = static_cast<AVCEncoder *>(userData);
-    CHECK(encoder != NULL);
-    return encoder->unbindOutputBuffer(index);
-}
-
-AVCEncoder::AVCEncoder(
-        const sp<MediaSource>& source,
-        const sp<MetaData>& meta)
-    : mSource(source),
-      mMeta(meta),
-      mNumInputFrames(-1),
-      mPrevTimestampUs(-1),
-      mStarted(false),
-      mInputBuffer(NULL),
-      mInputFrameData(NULL),
-      mGroup(NULL) {
-
-    ALOGI("Construct software AVCEncoder");
-
-    mHandle = new tagAVCHandle;
-    memset(mHandle, 0, sizeof(tagAVCHandle));
-    mHandle->AVCObject = NULL;
-    mHandle->userData = this;
-    mHandle->CBAVC_DPBAlloc = DpbAllocWrapper;
-    mHandle->CBAVC_FrameBind = BindFrameWrapper;
-    mHandle->CBAVC_FrameUnbind = UnbindFrameWrapper;
-    mHandle->CBAVC_Malloc = MallocWrapper;
-    mHandle->CBAVC_Free = FreeWrapper;
-
-    mInitCheck = initCheck(meta);
-}
-
-AVCEncoder::~AVCEncoder() {
-    ALOGV("Destruct software AVCEncoder");
-    if (mStarted) {
-        stop();
-    }
-
-    delete mEncParams;
-    delete mHandle;
-}
-
-status_t AVCEncoder::initCheck(const sp<MetaData>& meta) {
-    ALOGV("initCheck");
-    CHECK(meta->findInt32(kKeyWidth, &mVideoWidth));
-    CHECK(meta->findInt32(kKeyHeight, &mVideoHeight));
-    CHECK(meta->findInt32(kKeyFrameRate, &mVideoFrameRate));
-    CHECK(meta->findInt32(kKeyBitRate, &mVideoBitRate));
-
-    // XXX: Add more color format support
-    CHECK(meta->findInt32(kKeyColorFormat, &mVideoColorFormat));
-    if (mVideoColorFormat != OMX_COLOR_FormatYUV420Planar) {
-        if (mVideoColorFormat != OMX_COLOR_FormatYUV420SemiPlanar) {
-            ALOGE("Color format %d is not supported", mVideoColorFormat);
-            return BAD_VALUE;
-        }
-        // Allocate spare buffer only when color conversion is needed.
-        // Assume the color format is OMX_COLOR_FormatYUV420SemiPlanar.
-        mInputFrameData =
-            (uint8_t *) malloc((mVideoWidth * mVideoHeight * 3 ) >> 1);
-        CHECK(mInputFrameData);
-    }
-
-    // XXX: Remove this restriction
-    if (mVideoWidth % 16 != 0 || mVideoHeight % 16 != 0) {
-        ALOGE("Video frame size %dx%d must be a multiple of 16",
-            mVideoWidth, mVideoHeight);
-        return BAD_VALUE;
-    }
-
-    mEncParams = new tagAVCEncParam;
-    memset(mEncParams, 0, sizeof(mEncParams));
-    mEncParams->width = mVideoWidth;
-    mEncParams->height = mVideoHeight;
-    mEncParams->frame_rate = 1000 * mVideoFrameRate;  // In frames/ms!
-    mEncParams->rate_control = AVC_ON;
-    mEncParams->bitrate = mVideoBitRate;
-    mEncParams->initQP = 0;
-    mEncParams->init_CBP_removal_delay = 1600;
-    mEncParams->CPB_size = (uint32_t) (mVideoBitRate >> 1);
-
-    mEncParams->intramb_refresh = 0;
-    mEncParams->auto_scd = AVC_ON;
-    mEncParams->out_of_band_param_set = AVC_ON;
-    mEncParams->poc_type = 2;
-    mEncParams->log2_max_poc_lsb_minus_4 = 12;
-    mEncParams->delta_poc_zero_flag = 0;
-    mEncParams->offset_poc_non_ref = 0;
-    mEncParams->offset_top_bottom = 0;
-    mEncParams->num_ref_in_cycle = 0;
-    mEncParams->offset_poc_ref = NULL;
-
-    mEncParams->num_ref_frame = 1;
-    mEncParams->num_slice_group = 1;
-    mEncParams->fmo_type = 0;
-
-    mEncParams->db_filter = AVC_ON;
-    mEncParams->disable_db_idc = 0;
-
-    mEncParams->alpha_offset = 0;
-    mEncParams->beta_offset = 0;
-    mEncParams->constrained_intra_pred = AVC_OFF;
-
-    mEncParams->data_par = AVC_OFF;
-    mEncParams->fullsearch = AVC_OFF;
-    mEncParams->search_range = 16;
-    mEncParams->sub_pel = AVC_OFF;
-    mEncParams->submb_pred = AVC_OFF;
-    mEncParams->rdopt_mode = AVC_OFF;
-    mEncParams->bidir_pred = AVC_OFF;
-    int32_t nMacroBlocks = ((((mVideoWidth + 15) >> 4) << 4) *
-            (((mVideoHeight + 15) >> 4) << 4)) >> 8;
-    uint32_t *sliceGroup = (uint32_t *) malloc(sizeof(uint32_t) * nMacroBlocks);
-    for (int ii = 0, idx = 0; ii < nMacroBlocks; ++ii) {
-        sliceGroup[ii] = idx++;
-        if (idx >= mEncParams->num_slice_group) {
-            idx = 0;
-        }
-    }
-    mEncParams->slice_group = sliceGroup;
-
-    mEncParams->use_overrun_buffer = AVC_OFF;
-
-    // Set IDR frame refresh interval
-    int32_t iFramesIntervalSec;
-    CHECK(meta->findInt32(kKeyIFramesInterval, &iFramesIntervalSec));
-    if (iFramesIntervalSec < 0) {
-        mEncParams->idr_period = -1;
-    } else if (iFramesIntervalSec == 0) {
-        mEncParams->idr_period = 1;  // All I frames
-    } else {
-        mEncParams->idr_period =
-            (iFramesIntervalSec * mVideoFrameRate);
-    }
-    ALOGV("idr_period: %d, I-frames interval: %d seconds, and frame rate: %d",
-        mEncParams->idr_period, iFramesIntervalSec, mVideoFrameRate);
-
-    // Set profile and level
-    // If profile and level setting is not correct, failure
-    // is reported when the encoder is initialized.
-    mEncParams->profile = AVC_BASELINE;
-    mEncParams->level = AVC_LEVEL3_2;
-    int32_t profile, level;
-    if (meta->findInt32(kKeyVideoProfile, &profile)) {
-        if (OK != ConvertOmxAvcProfileToAvcSpecProfile(
-                        profile, &mEncParams->profile)) {
-            return BAD_VALUE;
-        }
-    }
-    if (meta->findInt32(kKeyVideoLevel, &level)) {
-        if (OK != ConvertOmxAvcLevelToAvcSpecLevel(
-                        level, &mEncParams->level)) {
-            return BAD_VALUE;
-        }
-    }
-
-
-    mFormat = new MetaData;
-    mFormat->setInt32(kKeyWidth, mVideoWidth);
-    mFormat->setInt32(kKeyHeight, mVideoHeight);
-    mFormat->setInt32(kKeyBitRate, mVideoBitRate);
-    mFormat->setInt32(kKeyFrameRate, mVideoFrameRate);
-    mFormat->setInt32(kKeyColorFormat, mVideoColorFormat);
-    mFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
-    mFormat->setCString(kKeyDecoderComponent, "AVCEncoder");
-    return OK;
-}
-
-status_t AVCEncoder::start(MetaData *params) {
-    ALOGV("start");
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mStarted) {
-        ALOGW("Call start() when encoder already started");
-        return OK;
-    }
-
-    AVCEnc_Status err;
-    err = PVAVCEncInitialize(mHandle, mEncParams, NULL, NULL);
-    if (err != AVCENC_SUCCESS) {
-        ALOGE("Failed to initialize the encoder: %d", err);
-        return UNKNOWN_ERROR;
-    }
-
-    mGroup = new MediaBufferGroup();
-    int32_t maxSize;
-    if (AVCENC_SUCCESS !=
-        PVAVCEncGetMaxOutputBufferSize(mHandle, &maxSize)) {
-        maxSize = 31584;  // Magic #
-    }
-    mGroup->add_buffer(new MediaBuffer(maxSize));
-
-    mSource->start(params);
-    mNumInputFrames = -2;  // 1st two buffers contain SPS and PPS
-    mStarted = true;
-    mSpsPpsHeaderReceived = false;
-    mReadyForNextFrame = true;
-    mIsIDRFrame = 0;
-
-    return OK;
-}
-
-status_t AVCEncoder::stop() {
-    ALOGV("stop");
-    if (!mStarted) {
-        ALOGW("Call stop() when encoder has not started");
-        return OK;
-    }
-
-    if (mInputBuffer) {
-        mInputBuffer->release();
-        mInputBuffer = NULL;
-    }
-
-    if (mGroup) {
-        delete mGroup;
-        mGroup = NULL;
-    }
-
-    if (mInputFrameData) {
-        delete mInputFrameData;
-        mInputFrameData = NULL;
-    }
-
-    PVAVCCleanUpEncoder(mHandle);
-    mSource->stop();
-    releaseOutputBuffers();
-    mStarted = false;
-
-    return OK;
-}
-
-void AVCEncoder::releaseOutputBuffers() {
-    ALOGV("releaseOutputBuffers");
-    for (size_t i = 0; i < mOutputBuffers.size(); ++i) {
-        MediaBuffer *buffer = mOutputBuffers.editItemAt(i);
-        buffer->setObserver(NULL);
-        buffer->release();
-    }
-    mOutputBuffers.clear();
-}
-
-sp<MetaData> AVCEncoder::getFormat() {
-    ALOGV("getFormat");
-    return mFormat;
-}
-
-status_t AVCEncoder::read(
-        MediaBuffer **out, const ReadOptions *options) {
-
-    CHECK(!options);
-    *out = NULL;
-
-    MediaBuffer *outputBuffer;
-    CHECK_EQ((status_t)OK, mGroup->acquire_buffer(&outputBuffer));
-    uint8_t *outPtr = (uint8_t *) outputBuffer->data();
-    uint32_t dataLength = outputBuffer->size();
-
-    if (!mSpsPpsHeaderReceived && mNumInputFrames < 0) {
-        // 4 bytes are reserved for holding the start code 0x00000001
-        // of the sequence parameter set at the beginning.
-        outPtr += 4;
-        dataLength -= 4;
-    }
-
-    int32_t type;
-    AVCEnc_Status encoderStatus = AVCENC_SUCCESS;
-
-    // Combine SPS and PPS and place them in the very first output buffer
-    // SPS and PPS are separated by start code 0x00000001
-    // Assume that we have exactly one SPS and exactly one PPS.
-    while (!mSpsPpsHeaderReceived && mNumInputFrames <= 0) {
-        encoderStatus = PVAVCEncodeNAL(mHandle, outPtr, &dataLength, &type);
-        if (encoderStatus == AVCENC_WRONG_STATE) {
-            mSpsPpsHeaderReceived = true;
-            CHECK_EQ(0, mNumInputFrames);  // 1st video frame is 0
-        } else {
-            switch (type) {
-                case AVC_NALTYPE_SPS:
-                    ++mNumInputFrames;
-                    memcpy((uint8_t *)outputBuffer->data(), "\x00\x00\x00\x01", 4);
-                    outputBuffer->set_range(0, dataLength + 4);
-                    outPtr += (dataLength + 4);  // 4 bytes for next start code
-                    dataLength = outputBuffer->size() -
-                            (outputBuffer->range_length() + 4);
-                    break;
-                case AVC_NALTYPE_PPS:
-                    ++mNumInputFrames;
-                    memcpy(((uint8_t *) outputBuffer->data()) +
-                            outputBuffer->range_length(),
-                            "\x00\x00\x00\x01", 4);
-                    outputBuffer->set_range(0,
-                            dataLength + outputBuffer->range_length() + 4);
-                    outputBuffer->meta_data()->setInt32(kKeyIsCodecConfig, 1);
-                    outputBuffer->meta_data()->setInt64(kKeyTime, 0);
-                    *out = outputBuffer;
-                    return OK;
-                default:
-                    ALOGE("Nal type (%d) other than SPS/PPS is unexpected", type);
-                    return UNKNOWN_ERROR;
-            }
-        }
-    }
-
-    // Get next input video frame
-    if (mReadyForNextFrame) {
-        if (mInputBuffer) {
-            mInputBuffer->release();
-            mInputBuffer = NULL;
-        }
-        status_t err = mSource->read(&mInputBuffer, options);
-        if (err != OK) {
-            if (err != ERROR_END_OF_STREAM) {
-                ALOGE("Failed to read input video frame: %d", err);
-            }
-            outputBuffer->release();
-            return err;
-        }
-
-        if (mInputBuffer->size() - ((mVideoWidth * mVideoHeight * 3) >> 1) != 0) {
-            outputBuffer->release();
-            mInputBuffer->release();
-            mInputBuffer = NULL;
-            return UNKNOWN_ERROR;
-        }
-
-        int64_t timeUs;
-        CHECK(mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
-        outputBuffer->meta_data()->setInt64(kKeyTime, timeUs);
-
-        // When the timestamp of the current sample is the same as
-        // that of the previous sample, the encoding of the sample
-        // is bypassed, and the output length is set to 0.
-        if (mNumInputFrames >= 1 && mPrevTimestampUs == timeUs) {
-            // Frame arrives too late
-            mInputBuffer->release();
-            mInputBuffer = NULL;
-            outputBuffer->set_range(0, 0);
-            *out = outputBuffer;
-            return OK;
-        }
-
-        // Don't accept out-of-order samples
-        CHECK(mPrevTimestampUs < timeUs);
-        mPrevTimestampUs = timeUs;
-
-        AVCFrameIO videoInput;
-        memset(&videoInput, 0, sizeof(videoInput));
-        videoInput.height = ((mVideoHeight  + 15) >> 4) << 4;
-        videoInput.pitch = ((mVideoWidth + 15) >> 4) << 4;
-        videoInput.coding_timestamp = (timeUs + 500) / 1000;  // in ms
-        uint8_t *inputData = (uint8_t *) mInputBuffer->data();
-
-        if (mVideoColorFormat != OMX_COLOR_FormatYUV420Planar) {
-            CHECK(mInputFrameData);
-            CHECK(mVideoColorFormat == OMX_COLOR_FormatYUV420SemiPlanar);
-            ConvertYUV420SemiPlanarToYUV420Planar(
-                inputData, mInputFrameData, mVideoWidth, mVideoHeight);
-            inputData = mInputFrameData;
-        }
-        CHECK(inputData != NULL);
-        videoInput.YCbCr[0] = inputData;
-        videoInput.YCbCr[1] = videoInput.YCbCr[0] + videoInput.height * videoInput.pitch;
-        videoInput.YCbCr[2] = videoInput.YCbCr[1] +
-            ((videoInput.height * videoInput.pitch) >> 2);
-        videoInput.disp_order = mNumInputFrames;
-
-        encoderStatus = PVAVCEncSetInput(mHandle, &videoInput);
-        if (encoderStatus == AVCENC_SUCCESS ||
-            encoderStatus == AVCENC_NEW_IDR) {
-            mReadyForNextFrame = false;
-            ++mNumInputFrames;
-            if (encoderStatus == AVCENC_NEW_IDR) {
-                mIsIDRFrame = 1;
-            }
-        } else {
-            if (encoderStatus < AVCENC_SUCCESS) {
-                outputBuffer->release();
-                return UNKNOWN_ERROR;
-            } else {
-                outputBuffer->set_range(0, 0);
-                *out = outputBuffer;
-                return OK;
-            }
-        }
-    }
-
-    // Encode an input video frame
-    CHECK(encoderStatus == AVCENC_SUCCESS ||
-          encoderStatus == AVCENC_NEW_IDR);
-    dataLength = outputBuffer->size();  // Reset the output buffer length
-    encoderStatus = PVAVCEncodeNAL(mHandle, outPtr, &dataLength, &type);
-    if (encoderStatus == AVCENC_SUCCESS) {
-        outputBuffer->meta_data()->setInt32(kKeyIsSyncFrame, mIsIDRFrame);
-        CHECK(NULL == PVAVCEncGetOverrunBuffer(mHandle));
-    } else if (encoderStatus == AVCENC_PICTURE_READY) {
-        CHECK(NULL == PVAVCEncGetOverrunBuffer(mHandle));
-        if (mIsIDRFrame) {
-            outputBuffer->meta_data()->setInt32(kKeyIsSyncFrame, mIsIDRFrame);
-            mIsIDRFrame = 0;
-            ALOGV("Output an IDR frame");
-        }
-        mReadyForNextFrame = true;
-        AVCFrameIO recon;
-        if (PVAVCEncGetRecon(mHandle, &recon) == AVCENC_SUCCESS) {
-            PVAVCEncReleaseRecon(mHandle, &recon);
-        }
-    } else {
-        dataLength = 0;
-        mReadyForNextFrame = true;
-    }
-    if (encoderStatus < AVCENC_SUCCESS) {
-        outputBuffer->release();
-        return UNKNOWN_ERROR;
-    }
-
-    outputBuffer->set_range(0, dataLength);
-    *out = outputBuffer;
-    return OK;
-}
-
-int32_t AVCEncoder::allocOutputBuffers(
-        unsigned int sizeInMbs, unsigned int numBuffers) {
-    CHECK(mOutputBuffers.isEmpty());
-    size_t frameSize = (sizeInMbs << 7) * 3;
-    for (unsigned int i = 0; i <  numBuffers; ++i) {
-        MediaBuffer *buffer = new MediaBuffer(frameSize);
-        buffer->setObserver(this);
-        mOutputBuffers.push(buffer);
-    }
-
-    return 1;
-}
-
-void AVCEncoder::unbindOutputBuffer(int32_t index) {
-    CHECK(index >= 0);
-}
-
-int32_t AVCEncoder::bindOutputBuffer(int32_t index, uint8_t **yuv) {
-    CHECK(index >= 0);
-    CHECK(index < (int32_t) mOutputBuffers.size());
-    int64_t timeUs;
-    CHECK(mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
-    mOutputBuffers[index]->meta_data()->setInt64(kKeyTime, timeUs);
-
-    *yuv = (uint8_t *) mOutputBuffers[index]->data();
-
-    return 1;
-}
-
-void AVCEncoder::signalBufferReturned(MediaBuffer *buffer) {
-}
-
-}  // namespace android
diff --git a/media/libstagefright/codecs/avc/enc/Android.mk b/media/libstagefright/codecs/avc/enc/Android.mk
index ee31ab2..48923cf 100644
--- a/media/libstagefright/codecs/avc/enc/Android.mk
+++ b/media/libstagefright/codecs/avc/enc/Android.mk
@@ -2,8 +2,6 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-    AVCEncoder.cpp \
-    SoftAVCEncoder.cpp \
     src/avcenc_api.cpp \
     src/bitstream_io.cpp \
     src/block.cpp \
diff --git a/media/libstagefright/codecs/m4v_h263/enc/Android.mk b/media/libstagefright/codecs/m4v_h263/enc/Android.mk
index e6aa563..484180d 100644
--- a/media/libstagefright/codecs/m4v_h263/enc/Android.mk
+++ b/media/libstagefright/codecs/m4v_h263/enc/Android.mk
@@ -2,8 +2,6 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-    M4vH263Encoder.cpp \
-    SoftMPEG4Encoder.cpp \
     src/bitstream_io.cpp \
     src/combined_encode.cpp \
     src/datapart_encode.cpp \
diff --git a/media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp b/media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp
deleted file mode 100644
index 20b0f8d..0000000
--- a/media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "M4vH263Encoder"
-#include <utils/Log.h>
-
-#include "M4vH263Encoder.h"
-
-#include "mp4enc_api.h"
-#include "OMX_Video.h"
-
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/MediaBufferGroup.h>
-#include <media/stagefright/MediaDefs.h>
-#include <media/stagefright/MediaErrors.h>
-#include <media/stagefright/MetaData.h>
-#include <media/stagefright/Utils.h>
-
-namespace android {
-
-static status_t ConvertOmxProfileLevel(
-        MP4EncodingMode mode,
-        int32_t omxProfile,
-        int32_t omxLevel,
-        ProfileLevelType* pvProfileLevel) {
-    ALOGV("ConvertOmxProfileLevel: %d/%d/%d", mode, omxProfile, omxLevel);
-    ProfileLevelType profileLevel;
-    if (mode == H263_MODE) {
-        switch (omxProfile) {
-            case OMX_VIDEO_H263ProfileBaseline:
-                if (omxLevel > OMX_VIDEO_H263Level45) {
-                    ALOGE("Unsupported level (%d) for H263", omxLevel);
-                    return BAD_VALUE;
-                } else {
-                    ALOGW("PV does not support level configuration for H263");
-                    profileLevel = CORE_PROFILE_LEVEL2;
-                    break;
-                }
-                break;
-            default:
-                ALOGE("Unsupported profile (%d) for H263", omxProfile);
-                return BAD_VALUE;
-        }
-    } else {  // MPEG4
-        switch (omxProfile) {
-            case OMX_VIDEO_MPEG4ProfileSimple:
-                switch (omxLevel) {
-                    case OMX_VIDEO_MPEG4Level0b:
-                        profileLevel = SIMPLE_PROFILE_LEVEL0;
-                        break;
-                    case OMX_VIDEO_MPEG4Level1:
-                        profileLevel = SIMPLE_PROFILE_LEVEL1;
-                        break;
-                    case OMX_VIDEO_MPEG4Level2:
-                        profileLevel = SIMPLE_PROFILE_LEVEL2;
-                        break;
-                    case OMX_VIDEO_MPEG4Level3:
-                        profileLevel = SIMPLE_PROFILE_LEVEL3;
-                        break;
-                    default:
-                        ALOGE("Unsupported level (%d) for MPEG4 simple profile",
-                            omxLevel);
-                        return BAD_VALUE;
-                }
-                break;
-            case OMX_VIDEO_MPEG4ProfileSimpleScalable:
-                switch (omxLevel) {
-                    case OMX_VIDEO_MPEG4Level0b:
-                        profileLevel = SIMPLE_SCALABLE_PROFILE_LEVEL0;
-                        break;
-                    case OMX_VIDEO_MPEG4Level1:
-                        profileLevel = SIMPLE_SCALABLE_PROFILE_LEVEL1;
-                        break;
-                    case OMX_VIDEO_MPEG4Level2:
-                        profileLevel = SIMPLE_SCALABLE_PROFILE_LEVEL2;
-                        break;
-                    default:
-                        ALOGE("Unsupported level (%d) for MPEG4 simple "
-                             "scalable profile", omxLevel);
-                        return BAD_VALUE;
-                }
-                break;
-            case OMX_VIDEO_MPEG4ProfileCore:
-                switch (omxLevel) {
-                    case OMX_VIDEO_MPEG4Level1:
-                        profileLevel = CORE_PROFILE_LEVEL1;
-                        break;
-                    case OMX_VIDEO_MPEG4Level2:
-                        profileLevel = CORE_PROFILE_LEVEL2;
-                        break;
-                    default:
-                        ALOGE("Unsupported level (%d) for MPEG4 core "
-                             "profile", omxLevel);
-                        return BAD_VALUE;
-                }
-                break;
-            case OMX_VIDEO_MPEG4ProfileCoreScalable:
-                switch (omxLevel) {
-                    case OMX_VIDEO_MPEG4Level1:
-                        profileLevel = CORE_SCALABLE_PROFILE_LEVEL1;
-                        break;
-                    case OMX_VIDEO_MPEG4Level2:
-                        profileLevel = CORE_SCALABLE_PROFILE_LEVEL2;
-                        break;
-                    case OMX_VIDEO_MPEG4Level3:
-                        profileLevel = CORE_SCALABLE_PROFILE_LEVEL3;
-                        break;
-                    default:
-                        ALOGE("Unsupported level (%d) for MPEG4 core "
-                             "scalable profile", omxLevel);
-                        return BAD_VALUE;
-                }
-                break;
-            default:
-                ALOGE("Unsupported MPEG4 profile (%d)", omxProfile);
-                return BAD_VALUE;
-        }
-    }
-
-    *pvProfileLevel = profileLevel;
-    return OK;
-}
-
-inline static void ConvertYUV420SemiPlanarToYUV420Planar(
-        uint8_t *inyuv, uint8_t* outyuv,
-        int32_t width, int32_t height) {
-
-    int32_t outYsize = width * height;
-    uint32_t *outy = (uint32_t *)  outyuv;
-    uint16_t *outcb = (uint16_t *) (outyuv + outYsize);
-    uint16_t *outcr = (uint16_t *) (outyuv + outYsize + (outYsize >> 2));
-
-    /* Y copying */
-    memcpy(outy, inyuv, outYsize);
-
-    /* U & V copying */
-    uint32_t *inyuv_4 = (uint32_t *) (inyuv + outYsize);
-    for (int32_t i = height >> 1; i > 0; --i) {
-        for (int32_t j = width >> 2; j > 0; --j) {
-            uint32_t temp = *inyuv_4++;
-            uint32_t tempU = temp & 0xFF;
-            tempU = tempU | ((temp >> 8) & 0xFF00);
-
-            uint32_t tempV = (temp >> 8) & 0xFF;
-            tempV = tempV | ((temp >> 16) & 0xFF00);
-
-            // Flip U and V
-            *outcb++ = tempV;
-            *outcr++ = tempU;
-        }
-    }
-}
-
-M4vH263Encoder::M4vH263Encoder(
-        const sp<MediaSource>& source,
-        const sp<MetaData>& meta)
-    : mSource(source),
-      mMeta(meta),
-      mNumInputFrames(-1),
-      mNextModTimeUs(0),
-      mPrevTimestampUs(-1),
-      mStarted(false),
-      mInputBuffer(NULL),
-      mInputFrameData(NULL),
-      mGroup(NULL) {
-
-    ALOGI("Construct software M4vH263Encoder");
-
-    mHandle = new tagvideoEncControls;
-    memset(mHandle, 0, sizeof(tagvideoEncControls));
-
-    mInitCheck = initCheck(meta);
-}
-
-M4vH263Encoder::~M4vH263Encoder() {
-    ALOGV("Destruct software M4vH263Encoder");
-    if (mStarted) {
-        stop();
-    }
-
-    delete mEncParams;
-    delete mHandle;
-}
-
-status_t M4vH263Encoder::initCheck(const sp<MetaData>& meta) {
-    ALOGV("initCheck");
-    CHECK(meta->findInt32(kKeyWidth, &mVideoWidth));
-    CHECK(meta->findInt32(kKeyHeight, &mVideoHeight));
-    CHECK(meta->findInt32(kKeyFrameRate, &mVideoFrameRate));
-    CHECK(meta->findInt32(kKeyBitRate, &mVideoBitRate));
-
-    // XXX: Add more color format support
-    CHECK(meta->findInt32(kKeyColorFormat, &mVideoColorFormat));
-    if (mVideoColorFormat != OMX_COLOR_FormatYUV420Planar) {
-        if (mVideoColorFormat != OMX_COLOR_FormatYUV420SemiPlanar) {
-            ALOGE("Color format %d is not supported", mVideoColorFormat);
-            return BAD_VALUE;
-        }
-        // Allocate spare buffer only when color conversion is needed.
-        // Assume the color format is OMX_COLOR_FormatYUV420SemiPlanar.
-        mInputFrameData =
-            (uint8_t *) malloc((mVideoWidth * mVideoHeight * 3 ) >> 1);
-        CHECK(mInputFrameData);
-    }
-
-    // XXX: Remove this restriction
-    if (mVideoWidth % 16 != 0 || mVideoHeight % 16 != 0) {
-        ALOGE("Video frame size %dx%d must be a multiple of 16",
-            mVideoWidth, mVideoHeight);
-        return BAD_VALUE;
-    }
-
-    mEncParams = new tagvideoEncOptions;
-    memset(mEncParams, 0, sizeof(tagvideoEncOptions));
-    if (!PVGetDefaultEncOption(mEncParams, 0)) {
-        ALOGE("Failed to get default encoding parameters");
-        return BAD_VALUE;
-    }
-
-    // Need to know which role the encoder is in.
-    // XXX: Set the mode proper for other types of applications
-    //      like streaming or video conference
-    const char *mime;
-    CHECK(meta->findCString(kKeyMIMEType, &mime));
-    CHECK(!strcmp(mime, MEDIA_MIMETYPE_VIDEO_MPEG4) ||
-          !strcmp(mime, MEDIA_MIMETYPE_VIDEO_H263));
-    if (!strcmp(mime, MEDIA_MIMETYPE_VIDEO_MPEG4)) {
-        mEncParams->encMode = COMBINE_MODE_WITH_ERR_RES;
-    } else {
-        mEncParams->encMode = H263_MODE;
-    }
-    mEncParams->encWidth[0] = mVideoWidth;
-    mEncParams->encHeight[0] = mVideoHeight;
-    mEncParams->encFrameRate[0] = mVideoFrameRate;
-    mEncParams->rcType = VBR_1;
-    mEncParams->vbvDelay = (float)5.0;
-
-    // Set profile and level
-    // If profile and level setting is not correct, failure
-    // is reported when the encoder is initialized.
-    mEncParams->profile_level = CORE_PROFILE_LEVEL2;
-    int32_t profile, level;
-    if (meta->findInt32(kKeyVideoProfile, &profile) &&
-        meta->findInt32(kKeyVideoLevel, &level)) {
-        if (OK != ConvertOmxProfileLevel(
-                        mEncParams->encMode, profile, level,
-                        &mEncParams->profile_level)) {
-            return BAD_VALUE;
-        }
-    }
-
-    mEncParams->packetSize = 32;
-    mEncParams->rvlcEnable = PV_OFF;
-    mEncParams->numLayers = 1;
-    mEncParams->timeIncRes = 1000;
-    mEncParams->tickPerSrc = mEncParams->timeIncRes / mVideoFrameRate;
-
-    mEncParams->bitRate[0] = mVideoBitRate;
-    mEncParams->iQuant[0] = 15;
-    mEncParams->pQuant[0] = 12;
-    mEncParams->quantType[0] = 0;
-    mEncParams->noFrameSkipped = PV_OFF;
-
-    // Set IDR frame refresh interval
-    int32_t iFramesIntervalSec;
-    CHECK(meta->findInt32(kKeyIFramesInterval, &iFramesIntervalSec));
-    if (iFramesIntervalSec < 0) {
-        mEncParams->intraPeriod = -1;
-    } else if (iFramesIntervalSec == 0) {
-        mEncParams->intraPeriod = 1;  // All I frames
-    } else {
-        mEncParams->intraPeriod =
-            (iFramesIntervalSec * mVideoFrameRate);
-    }
-
-    mEncParams->numIntraMB = 0;
-    mEncParams->sceneDetect = PV_ON;
-    mEncParams->searchRange = 16;
-    mEncParams->mv8x8Enable = PV_OFF;
-    mEncParams->gobHeaderInterval = 0;
-    mEncParams->useACPred = PV_ON;
-    mEncParams->intraDCVlcTh = 0;
-
-    mFormat = new MetaData;
-    mFormat->setInt32(kKeyWidth, mVideoWidth);
-    mFormat->setInt32(kKeyHeight, mVideoHeight);
-    mFormat->setInt32(kKeyBitRate, mVideoBitRate);
-    mFormat->setInt32(kKeyFrameRate, mVideoFrameRate);
-    mFormat->setInt32(kKeyColorFormat, mVideoColorFormat);
-
-    mFormat->setCString(kKeyMIMEType, mime);
-    mFormat->setCString(kKeyDecoderComponent, "M4vH263Encoder");
-    return OK;
-}
-
-status_t M4vH263Encoder::start(MetaData *params) {
-    ALOGV("start");
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mStarted) {
-        ALOGW("Call start() when encoder already started");
-        return OK;
-    }
-
-    if (!PVInitVideoEncoder(mHandle, mEncParams)) {
-        ALOGE("Failed to initialize the encoder");
-        return UNKNOWN_ERROR;
-    }
-
-    mGroup = new MediaBufferGroup();
-    int32_t maxSize;
-    if (!PVGetMaxVideoFrameSize(mHandle, &maxSize)) {
-        maxSize = 256 * 1024;  // Magic #
-    }
-    ALOGV("Max output buffer size: %d", maxSize);
-    mGroup->add_buffer(new MediaBuffer(maxSize));
-
-    mSource->start(params);
-    mNumInputFrames = -1;  // 1st frame contains codec specific data
-    mStarted = true;
-
-    return OK;
-}
-
-status_t M4vH263Encoder::stop() {
-    ALOGV("stop");
-    if (!mStarted) {
-        ALOGW("Call stop() when encoder has not started");
-        return OK;
-    }
-
-    if (mInputBuffer) {
-        mInputBuffer->release();
-        mInputBuffer = NULL;
-    }
-
-    if (mGroup) {
-        delete mGroup;
-        mGroup = NULL;
-    }
-
-    if (mInputFrameData) {
-        delete mInputFrameData;
-        mInputFrameData = NULL;
-    }
-
-    CHECK(PVCleanUpVideoEncoder(mHandle));
-
-    mSource->stop();
-    mStarted = false;
-
-    return OK;
-}
-
-sp<MetaData> M4vH263Encoder::getFormat() {
-    ALOGV("getFormat");
-    return mFormat;
-}
-
-status_t M4vH263Encoder::read(
-        MediaBuffer **out, const ReadOptions *options) {
-
-    *out = NULL;
-
-    MediaBuffer *outputBuffer;
-    CHECK_EQ((status_t)OK, mGroup->acquire_buffer(&outputBuffer));
-    uint8_t *outPtr = (uint8_t *) outputBuffer->data();
-    int32_t dataLength = outputBuffer->size();
-
-    // Output codec specific data
-    if (mNumInputFrames < 0) {
-        if (!PVGetVolHeader(mHandle, outPtr, &dataLength, 0)) {
-            ALOGE("Failed to get VOL header");
-            return UNKNOWN_ERROR;
-        }
-        ALOGV("Output VOL header: %d bytes", dataLength);
-        outputBuffer->meta_data()->setInt32(kKeyIsCodecConfig, 1);
-        outputBuffer->set_range(0, dataLength);
-        *out = outputBuffer;
-        ++mNumInputFrames;
-        return OK;
-    }
-
-    // Ready for accepting an input video frame
-    status_t err = mSource->read(&mInputBuffer, options);
-    if (OK != err) {
-        if (err != ERROR_END_OF_STREAM) {
-            ALOGE("Failed to read from data source");
-        }
-        outputBuffer->release();
-        return err;
-    }
-
-    if (mInputBuffer->size() - ((mVideoWidth * mVideoHeight * 3) >> 1) != 0) {
-        outputBuffer->release();
-        mInputBuffer->release();
-        mInputBuffer = NULL;
-        return UNKNOWN_ERROR;
-    }
-
-    int64_t timeUs;
-    CHECK(mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
-
-    // When the timestamp of the current sample is the same as that
-    // of the previous sample, encoding of the current sample is
-    // bypassed, and the output length of the sample is set to 0
-    if (mNumInputFrames >= 1 &&
-        (mNextModTimeUs > timeUs || mPrevTimestampUs == timeUs)) {
-        // Frame arrives too late
-        outputBuffer->set_range(0, 0);
-        *out = outputBuffer;
-        mInputBuffer->release();
-        mInputBuffer = NULL;
-        return OK;
-    }
-
-    // Don't accept out-of-order samples
-    CHECK(mPrevTimestampUs < timeUs);
-    mPrevTimestampUs = timeUs;
-
-    // Color convert to OMX_COLOR_FormatYUV420Planar if necessary
-    outputBuffer->meta_data()->setInt64(kKeyTime, timeUs);
-    uint8_t *inPtr = (uint8_t *) mInputBuffer->data();
-    if (mVideoColorFormat != OMX_COLOR_FormatYUV420Planar) {
-        CHECK(mInputFrameData);
-        CHECK(mVideoColorFormat == OMX_COLOR_FormatYUV420SemiPlanar);
-        ConvertYUV420SemiPlanarToYUV420Planar(
-            inPtr, mInputFrameData, mVideoWidth, mVideoHeight);
-        inPtr = mInputFrameData;
-    }
-    CHECK(inPtr != NULL);
-
-    // Ready for encoding a video frame
-    VideoEncFrameIO vin, vout;
-    vin.height = ((mVideoHeight + 15) >> 4) << 4;
-    vin.pitch  = ((mVideoWidth  + 15) >> 4) << 4;
-    vin.timestamp = (timeUs + 500) / 1000; // in ms
-    vin.yChan = inPtr;
-    vin.uChan = vin.yChan + vin.height * vin.pitch;
-    vin.vChan = vin.uChan + ((vin.height * vin.pitch) >> 2);
-    unsigned long modTimeMs = 0;
-    int32_t nLayer = 0;
-    MP4HintTrack hintTrack;
-    if (!PVEncodeVideoFrame(mHandle, &vin, &vout,
-            &modTimeMs, outPtr, &dataLength, &nLayer) ||
-        !PVGetHintTrack(mHandle, &hintTrack)) {
-        ALOGE("Failed to encode frame or get hink track at frame %lld",
-            mNumInputFrames);
-        outputBuffer->release();
-        mInputBuffer->release();
-        mInputBuffer = NULL;
-        return UNKNOWN_ERROR;
-    }
-    CHECK(NULL == PVGetOverrunBuffer(mHandle));
-    if (hintTrack.CodeType == 0) {  // I-frame serves as sync frame
-        outputBuffer->meta_data()->setInt32(kKeyIsSyncFrame, 1);
-    }
-
-    ++mNumInputFrames;
-    mNextModTimeUs = modTimeMs * 1000LL;
-    outputBuffer->set_range(0, dataLength);
-    *out = outputBuffer;
-    mInputBuffer->release();
-    mInputBuffer = NULL;
-    return OK;
-}
-
-void M4vH263Encoder::signalBufferReturned(MediaBuffer *buffer) {
-}
-
-}  // namespace android
diff --git a/media/libstagefright/include/AVCEncoder.h b/media/libstagefright/include/AVCEncoder.h
deleted file mode 100644
index 83e1f97..0000000
--- a/media/libstagefright/include/AVCEncoder.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef AVC_ENCODER_H_
-
-#define AVC_ENCODER_H_
-
-#include <media/stagefright/MediaBuffer.h>
-#include <media/stagefright/MediaSource.h>
-#include <utils/Vector.h>
-
-struct tagAVCHandle;
-struct tagAVCEncParam;
-
-namespace android {
-
-struct MediaBuffer;
-struct MediaBufferGroup;
-
-struct AVCEncoder : public MediaSource,
-                    public MediaBufferObserver {
-    AVCEncoder(const sp<MediaSource> &source,
-            const sp<MetaData>& meta);
-
-    virtual status_t start(MetaData *params);
-    virtual status_t stop();
-
-    virtual sp<MetaData> getFormat();
-
-    virtual status_t read(
-            MediaBuffer **buffer, const ReadOptions *options);
-
-    virtual void signalBufferReturned(MediaBuffer *buffer);
-
-    // Callbacks required by the encoder
-    int32_t allocOutputBuffers(unsigned int sizeInMbs, unsigned int numBuffers);
-    void    unbindOutputBuffer(int32_t index);
-    int32_t bindOutputBuffer(int32_t index, uint8_t **yuv);
-
-protected:
-    virtual ~AVCEncoder();
-
-private:
-    sp<MediaSource> mSource;
-    sp<MetaData>    mFormat;
-    sp<MetaData>    mMeta;
-
-    int32_t  mVideoWidth;
-    int32_t  mVideoHeight;
-    int32_t  mVideoFrameRate;
-    int32_t  mVideoBitRate;
-    int32_t  mVideoColorFormat;
-    int64_t  mNumInputFrames;
-    int64_t  mPrevTimestampUs;
-    status_t mInitCheck;
-    bool     mStarted;
-    bool     mSpsPpsHeaderReceived;
-    bool     mReadyForNextFrame;
-    int32_t  mIsIDRFrame;  // for set kKeyIsSyncFrame
-
-    tagAVCHandle          *mHandle;
-    tagAVCEncParam        *mEncParams;
-    MediaBuffer           *mInputBuffer;
-    uint8_t               *mInputFrameData;
-    MediaBufferGroup      *mGroup;
-    Vector<MediaBuffer *> mOutputBuffers;
-
-
-    status_t initCheck(const sp<MetaData>& meta);
-    void releaseOutputBuffers();
-
-    AVCEncoder(const AVCEncoder &);
-    AVCEncoder &operator=(const AVCEncoder &);
-};
-
-}  // namespace android
-
-#endif  // AVC_ENCODER_H_
diff --git a/media/libstagefright/include/M4vH263Encoder.h b/media/libstagefright/include/M4vH263Encoder.h
deleted file mode 100644
index dbe9fd0..0000000
--- a/media/libstagefright/include/M4vH263Encoder.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef M4V_H263_ENCODER_H_
-
-#define M4V_H263_ENCODER_H_
-
-#include <media/stagefright/MediaBuffer.h>
-#include <media/stagefright/MediaSource.h>
-
-struct tagvideoEncControls;
-struct tagvideoEncOptions;
-
-namespace android {
-
-struct MediaBuffer;
-struct MediaBufferGroup;
-
-struct M4vH263Encoder : public MediaSource,
-                    public MediaBufferObserver {
-    M4vH263Encoder(const sp<MediaSource> &source,
-            const sp<MetaData>& meta);
-
-    virtual status_t start(MetaData *params);
-    virtual status_t stop();
-
-    virtual sp<MetaData> getFormat();
-
-    virtual status_t read(
-            MediaBuffer **buffer, const ReadOptions *options);
-
-    virtual void signalBufferReturned(MediaBuffer *buffer);
-
-protected:
-    virtual ~M4vH263Encoder();
-
-private:
-    sp<MediaSource> mSource;
-    sp<MetaData>    mFormat;
-    sp<MetaData>    mMeta;
-
-    int32_t  mVideoWidth;
-    int32_t  mVideoHeight;
-    int32_t  mVideoFrameRate;
-    int32_t  mVideoBitRate;
-    int32_t  mVideoColorFormat;
-    int64_t  mNumInputFrames;
-    int64_t  mNextModTimeUs;
-    int64_t  mPrevTimestampUs;
-    status_t mInitCheck;
-    bool     mStarted;
-
-    tagvideoEncControls   *mHandle;
-    tagvideoEncOptions    *mEncParams;
-    MediaBuffer           *mInputBuffer;
-    uint8_t               *mInputFrameData;
-    MediaBufferGroup      *mGroup;
-
-    status_t initCheck(const sp<MetaData>& meta);
-    void releaseOutputBuffers();
-
-    M4vH263Encoder(const M4vH263Encoder &);
-    M4vH263Encoder &operator=(const M4vH263Encoder &);
-};
-
-}  // namespace android
-
-#endif  // M4V_H263_ENCODER_H_
diff --git a/media/libstagefright/mpeg2ts/ESQueue.cpp b/media/libstagefright/mpeg2ts/ESQueue.cpp
index 7fd99a8..1cab077 100644
--- a/media/libstagefright/mpeg2ts/ESQueue.cpp
+++ b/media/libstagefright/mpeg2ts/ESQueue.cpp
@@ -305,10 +305,7 @@
 }
 
 sp<ABuffer> ElementaryStreamQueue::dequeueAccessUnitAAC() {
-    Vector<size_t> ranges;
-    Vector<size_t> frameOffsets;
-    Vector<size_t> frameSizes;
-    size_t auSize = 0;
+    int64_t timeUs;
 
     size_t offset = 0;
     while (offset + 7 <= mBuffer->size()) {
@@ -332,6 +329,8 @@
             mFormat = MakeAACCodecSpecificData(
                     profile, sampling_freq_index, channel_configuration);
 
+            mFormat->setInt32(kKeyIsADTS, true);
+
             int32_t sampleRate;
             int32_t numChannels;
             CHECK(mFormat->findInt32(kKeySampleRate, &sampleRate));
@@ -367,10 +366,12 @@
 
         size_t headerSize = protection_absent ? 7 : 9;
 
-        ranges.push(aac_frame_length);
-        frameOffsets.push(offset + headerSize);
-        frameSizes.push(aac_frame_length - headerSize);
-        auSize += aac_frame_length - headerSize;
+        int64_t tmpUs = fetchTimestamp(aac_frame_length);
+        CHECK_GE(tmpUs, 0ll);
+
+        if (offset == 0) {
+            timeUs = tmpUs;
+        }
 
         offset += aac_frame_length;
     }
@@ -379,37 +380,14 @@
         return NULL;
     }
 
-    int64_t timeUs = -1;
-
-    for (size_t i = 0; i < ranges.size(); ++i) {
-        int64_t tmpUs = fetchTimestamp(ranges.itemAt(i));
-
-        if (i == 0) {
-            timeUs = tmpUs;
-        }
-    }
-
-    sp<ABuffer> accessUnit = new ABuffer(auSize);
-    size_t dstOffset = 0;
-    for (size_t i = 0; i < frameOffsets.size(); ++i) {
-        size_t frameOffset = frameOffsets.itemAt(i);
-
-        memcpy(accessUnit->data() + dstOffset,
-               mBuffer->data() + frameOffset,
-               frameSizes.itemAt(i));
-
-        dstOffset += frameSizes.itemAt(i);
-    }
+    sp<ABuffer> accessUnit = new ABuffer(offset);
+    memcpy(accessUnit->data(), mBuffer->data(), offset);
 
     memmove(mBuffer->data(), mBuffer->data() + offset,
             mBuffer->size() - offset);
     mBuffer->setRange(0, mBuffer->size() - offset);
 
-    if (timeUs >= 0) {
-        accessUnit->meta()->setInt64("timeUs", timeUs);
-    } else {
-        ALOGW("no time for AAC access unit");
-    }
+    accessUnit->meta()->setInt64("timeUs", timeUs);
 
     return accessUnit;
 }