Merge "mm-video: vidc: add support for opaque-format gralloc-buffers in encoding"
diff --git a/dashplayer/DashPlayer.cpp b/dashplayer/DashPlayer.cpp
index 7bf4187..2dbf530 100644
--- a/dashplayer/DashPlayer.cpp
+++ b/dashplayer/DashPlayer.cpp
@@ -360,6 +360,10 @@
                            mScanSourcesPending = true;
                     }
                }
+               if (mTimeDiscontinuityPending && mRenderer != NULL){
+                   mRenderer->signalTimeDiscontinuity();
+                   mTimeDiscontinuityPending = false;
+               }
             }
             break;
         }
@@ -785,10 +789,11 @@
             if (mDriver != NULL) {
                 sp<DashPlayerDriver> driver = mDriver.promote();
                 if (driver != NULL) {
-                    driver->notifySeekComplete();
                     if( newSeekTime >= 0 ) {
+                        mRenderer->notifySeekPosition(newSeekTime);
                         driver->notifyPosition( newSeekTime );
                         mSource->notifyRenderingPosition(newSeekTime);
+                        driver->notifySeekComplete();
                      }
                 }
             }
diff --git a/dashplayer/DashPlayerRenderer.cpp b/dashplayer/DashPlayerRenderer.cpp
index 42f146e..35b8fab 100644
--- a/dashplayer/DashPlayerRenderer.cpp
+++ b/dashplayer/DashPlayerRenderer.cpp
@@ -50,7 +50,8 @@
       mWasPaused(false),
       mLastPositionUpdateUs(-1ll),
       mVideoLateByUs(0ll),
-      mStats(NULL) {
+      mStats(NULL),
+      mSeekTimeUs(0){
 }
 
 DashPlayer::Renderer::~Renderer() {
@@ -107,6 +108,7 @@
     mAnchorTimeMediaUs = -1;
     mAnchorTimeRealUs = -1;
     mWasPaused = false;
+    mSeekTimeUs = 0;
     mSyncQueues = mHasAudio && mHasVideo;
     ALOGI("signalTimeDiscontinuity mHasAudio %d mHasVideo %d mSyncQueues %d",mHasAudio,mHasVideo,mSyncQueues);
 }
@@ -642,7 +644,7 @@
     }
     mLastPositionUpdateUs = nowUs;
 
-    int64_t positionUs = (nowUs - mAnchorTimeRealUs) + mAnchorTimeMediaUs;
+    int64_t positionUs = (mSeekTimeUs != 0) ? mSeekTimeUs : ((nowUs - mAnchorTimeRealUs) + mAnchorTimeMediaUs);
 
     sp<AMessage> notify = mNotify->dup();
     notify->setInt32("what", kWhatPosition);
@@ -651,6 +653,19 @@
     notify->post();
 }
 
+void DashPlayer::Renderer::notifySeekPosition(int64_t seekTime){
+  mSeekTimeUs = seekTime;
+  int64_t nowUs = ALooper::GetNowUs();
+  mLastPositionUpdateUs = nowUs;
+  sp<AMessage> notify = mNotify->dup();
+  notify->setInt32("what", kWhatPosition);
+  notify->setInt64("positionUs", seekTime);
+  notify->setInt64("videoLateByUs", mVideoLateByUs);
+  notify->post();
+
+}
+
+
 void DashPlayer::Renderer::onPause() {
     CHECK(!mPaused);
 
diff --git a/dashplayer/DashPlayerRenderer.h b/dashplayer/DashPlayerRenderer.h
index f465034..b71f460 100644
--- a/dashplayer/DashPlayerRenderer.h
+++ b/dashplayer/DashPlayerRenderer.h
@@ -55,6 +55,7 @@
 
     void pause();
     void resume();
+    void notifySeekPosition(int64_t seekTime);
 #endif /* QCOM_WFD_SINK */
     enum {
         kWhatEOS                = 'eos ',
@@ -101,6 +102,7 @@
 
     int64_t mAnchorTimeMediaUs;
     int64_t mAnchorTimeRealUs;
+    int64_t mSeekTimeUs;
 
     Mutex mFlushLock;  // protects the following 2 member vars.
     bool mFlushingAudio;
diff --git a/mm-core/inc/QOMX_AudioExtensions.h b/mm-core/inc/QOMX_AudioExtensions.h
index 642fe76..597ef8f 100755
--- a/mm-core/inc/QOMX_AudioExtensions.h
+++ b/mm-core/inc/QOMX_AudioExtensions.h
@@ -74,6 +74,7 @@
 #define OMX_QCOM_INDEX_PARAM_DAK_FADE        "OMX.Qualcomm.index.audio.dak_fade"

 #define OMX_QCOM_INDEX_PARAM_DAK_SEQ         "OMX.Qualcomm.index.audio.dak_seq"

 #define OMX_QCOM_INDEX_CONFIG_DUALMONO       "OMX.Qualcomm.index.audio.dualmono"

+#define OMX_QCOM_INDEX_CONFIG_AAC_SEL_MIX_COEF "OMX.Qualcomm.index.audio.aac_sel_mix_coef"
 

 typedef enum QOMX_AUDIO_AMRBANDMODETYPE {

     QOMX_AUDIO_AMRBandModeWB9              = 0x7F000001,/**< AMRWB Mode 9 = SID*/

diff --git a/mm-core/inc/QOMX_AudioIndexExtensions.h b/mm-core/inc/QOMX_AudioIndexExtensions.h
index a16f5f1..7aba765 100755
--- a/mm-core/inc/QOMX_AudioIndexExtensions.h
+++ b/mm-core/inc/QOMX_AudioIndexExtensions.h
@@ -70,6 +70,7 @@
     QOMX_IndexConfigAudioDualMono       = 0x7F200004, /**< "OMX.Qualcomm.index.audio.dualmono" */

     QOMX_IndexParamAudioAc3             = 0x7F200005, /**< "OMX.Qualcomm.index.audio.ac3" */

     QOMX_IndexParamAudioAc3PostProc     = 0x7F200006, /**< "OMX.Qualcomm.index.audio.postproc.ac3" */

+    QOMX_IndexParamAudioAacSelectMixCoef = 0x7F200007, /** "OMX.Qualcomm.index.audio.aac_sel_mix_coef**/
     QOMX_IndexParamAudioUnused          = 0x7F2FFFFF

 } QOMX_AUDIO_EXTENSIONS_INDEXTYPE;

 

diff --git a/mm-core/src/8974/qc_registry_table.c b/mm-core/src/8974/qc_registry_table.c
index 632df78..274aa8b 100755
--- a/mm-core/src/8974/qc_registry_table.c
+++ b/mm-core/src/8974/qc_registry_table.c
@@ -440,6 +440,22 @@
       "audio_encoder.amrnb"
     }
   },
+  {
+    "OMX.qcom.audio.decoder.amrwbplus",
+    NULL,   // Create instance function
+    // Unique instance handle
+    {
+     NULL,
+     NULL,
+     NULL,
+     NULL
+    },
+    NULL,   // Shared object library handle
+    "libOmxAmrwbplusDec.so",
+    {
+     "audio_decoder.awbplus"
+    }
+  },
  {
     "OMX.qcom.audio.decoder.aac",
     NULL,   // Create instance function
diff --git a/mm-core/src/8974/qc_registry_table_android.c b/mm-core/src/8974/qc_registry_table_android.c
index c3ace6b..9d90190 100644
--- a/mm-core/src/8974/qc_registry_table_android.c
+++ b/mm-core/src/8974/qc_registry_table_android.c
@@ -152,6 +152,22 @@
     }
   },
   {
+    "OMX.qcom.video.decoder.mpeg2.secure",
+    NULL, // Create instance function
+    // Unique instance handle
+    {
+      NULL,
+      NULL,
+      NULL,
+      NULL
+    },
+    NULL,   // Shared object library handle
+    "libOmxVdec.so",
+    {
+      "video_decoder.mpeg2"
+    }
+  },
+  {
     "OMX.qcom.video.decoder.vc1",
     NULL, // Create instance function
     // Unique instance handle
diff --git a/mm-video-v4l2/vidc/common/inc/extra_data_handler.h b/mm-video-v4l2/vidc/common/inc/extra_data_handler.h
index 3ad9dc4..64e0033 100644
--- a/mm-video-v4l2/vidc/common/inc/extra_data_handler.h
+++ b/mm-video-v4l2/vidc/common/inc/extra_data_handler.h
@@ -37,42 +37,13 @@
 #include<linux/msm_vidc_dec.h>
 #include<linux/msm_vidc_enc.h>
 
-
 #ifdef _ANDROID_
 extern "C" {
 #include<utils/Log.h>
 }
-#ifdef ENABLE_DEBUG_LOW
-#undef DEBUG_PRINT_LOW
-#define DEBUG_PRINT_LOW ALOGE
-#else
-#undef DEBUG_PRINT_LOW
-#define DEBUG_PRINT_LOW
-#endif
-#ifdef ENABLE_DEBUG_HIGH
-#undef DEBUG_PRINT_HIGH
-#define DEBUG_PRINT_HIGH ALOGE
-#else
-#undef DEBUG_PRINT_HIGH
-#define DEBUG_PRINT_HIGH
-#endif
-#ifdef ENABLE_DEBUG_ERROR
-#undef DEBUG_PRINT_ERROR
-#define DEBUG_PRINT_ERROR ALOGE
-#else
-#undef DEBUG_PRINT_ERROR
-#define DEBUG_PRINT_ERROR
-#endif
-
-#else //_ANDROID_
-#undef DEBUG_PRINT_LOW
-#undef DEBUG_PRINT_HIGH
-#undef DEBUG_PRINT_ERROR
-#define DEBUG_PRINT_LOW printf
-#define DEBUG_PRINT_HIGH printf
-#define DEBUG_PRINT_ERROR printf
 #endif // _ANDROID_
 
+#include "vidc_debug.h"
 #define SEI_PAYLOAD_FRAME_PACKING_ARRANGEMENT 0x2D
 #define H264_START_CODE 0x01
 #define NAL_TYPE_SEI 0x06
diff --git a/mm-video-v4l2/vidc/common/inc/vidc_debug.h b/mm-video-v4l2/vidc/common/inc/vidc_debug.h
new file mode 100644
index 0000000..9631135
--- /dev/null
+++ b/mm-video-v4l2/vidc/common/inc/vidc_debug.h
@@ -0,0 +1,61 @@
+/*--------------------------------------------------------------------------
+Copyright (c) 2013, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of The Linux Foundation nor
+      the names of its contributors may be used to endorse or promote
+      products derived from this software without specific prior written
+      permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+--------------------------------------------------------------------------*/
+
+#ifndef __VIDC_DEBUG_H__
+#define __VIDC_DEBUG_H__
+
+#ifdef _ANDROID_
+#include <cstdio>
+
+enum {
+   PRIO_ERROR=0x1,
+   PRIO_HIGH=0x2,
+   PRIO_LOW=0x4
+};
+
+extern int debug_level;
+
+#undef DEBUG_PRINT_ERROR
+#define DEBUG_PRINT_ERROR(fmt, args...) \
+      if (debug_level & PRIO_ERROR) \
+          ALOGE(fmt,##args)
+#undef DEBUG_PRINT_LOW
+#define DEBUG_PRINT_LOW(fmt, args...) \
+      if (debug_level & PRIO_LOW) \
+          ALOGD(fmt,##args)
+#undef DEBUG_PRINT_HIGH
+#define DEBUG_PRINT_HIGH(fmt, args...) \
+      if (debug_level & PRIO_HIGH) \
+          ALOGD(fmt,##args)
+#else
+#define DEBUG_PRINT_ERROR printf
+#define DEBUG_PRINT_LOW printf
+#define DEBUG_PRINT_HIGH printf
+#endif
+
+#endif
diff --git a/mm-video-v4l2/vidc/common/src/vidc_color_converter.cpp b/mm-video-v4l2/vidc/common/src/vidc_color_converter.cpp
index ac5b840..3377292 100644
--- a/mm-video-v4l2/vidc/common/src/vidc_color_converter.cpp
+++ b/mm-video-v4l2/vidc/common/src/vidc_color_converter.cpp
@@ -29,13 +29,7 @@
 #include <utils/Log.h>
 #include <gralloc_priv.h>
 #include "vidc_color_converter.h"
-#undef DEBUG_PRINT_LOW
-#undef DEBUG_PRINT_HIGH
-#undef DEBUG_PRINT_ERROR
-
-#define DEBUG_PRINT_LOW ALOGV
-#define DEBUG_PRINT_HIGH ALOGE
-#define DEBUG_PRINT_ERROR ALOGE
+#include "vidc_debug.h"
 
 omx_c2d_conv::omx_c2d_conv()
 {
diff --git a/mm-video-v4l2/vidc/vdec/Android.mk b/mm-video-v4l2/vidc/vdec/Android.mk
index f948249..a7b8f47 100755
--- a/mm-video-v4l2/vidc/vdec/Android.mk
+++ b/mm-video-v4l2/vidc/vdec/Android.mk
@@ -100,7 +100,6 @@
 #DRM include - Interface which loads the DRM library
 libmm-vdec-inc	        += $(OMX_VIDEO_PATH)/DivxDrmDecrypt/inc
 libmm-vdec-inc          += hardware/qcom/display/libgralloc
-libmm-vdec-inc          += hardware/qcom/display/libgenlock
 libmm-vdec-inc          += frameworks/native/include/media/openmax
 libmm-vdec-inc          += frameworks/native/include/media/hardware
 libmm-vdec-inc          += $(vdec-inc)
@@ -118,7 +117,6 @@
 LOCAL_PRELINK_MODULE    := false
 LOCAL_SHARED_LIBRARIES  := liblog libutils libbinder libcutils libdl
 
-LOCAL_SHARED_LIBRARIES += libgenlock
 LOCAL_SHARED_LIBRARIES  += libdivxdrmdecrypt
 LOCAL_SHARED_LIBRARIES  += libqdMetaData
 
@@ -159,7 +157,6 @@
 LOCAL_PRELINK_MODULE    := false
 LOCAL_SHARED_LIBRARIES  := liblog libutils libbinder libcutils libdl
 
-LOCAL_SHARED_LIBRARIES += libgenlock
 LOCAL_SHARED_LIBRARIES  += libdivxdrmdecrypt
 LOCAL_SHARED_LIBRARIES  += libqdMetaData
 
diff --git a/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h b/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
index 638f75a..4ddb997 100644
--- a/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
+++ b/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
@@ -73,10 +73,6 @@
 #include <poll.h>
 #define TIMEOUT 5000
 
-#else //_ANDROID_
-#define DEBUG_PRINT_LOW printf
-#define DEBUG_PRINT_HIGH printf
-#define DEBUG_PRINT_ERROR printf
 #endif // _ANDROID_
 
 #ifdef _MSM8974_
@@ -112,6 +108,7 @@
 #include "extra_data_handler.h"
 #include "ts_parser.h"
 #include "vidc_color_converter.h"
+#include "vidc_debug.h"
 extern "C" {
     OMX_API void * get_omx_component_factory_fn(void);
 }
diff --git a/mm-video-v4l2/vidc/vdec/inc/omx_vdec_hevc.h b/mm-video-v4l2/vidc/vdec/inc/omx_vdec_hevc.h
index 2182d5b..8907a56 100644
--- a/mm-video-v4l2/vidc/vdec/inc/omx_vdec_hevc.h
+++ b/mm-video-v4l2/vidc/vdec/inc/omx_vdec_hevc.h
@@ -72,10 +72,6 @@
 #include "hevc_utils.h"
 #define TIMEOUT 5000
 
-#else //_ANDROID_
-#define DEBUG_PRINT_LOW printf
-#define DEBUG_PRINT_HIGH printf
-#define DEBUG_PRINT_ERROR printf
 #endif // _ANDROID_
 
 
@@ -106,6 +102,7 @@
 #include "extra_data_handler.h"
 #include "ts_parser.h"
 #include "vidc_color_converter.h"
+#include "vidc_debug.h"
 extern "C" {
     OMX_API void * get_omx_component_factory_fn(void);
 }
diff --git a/mm-video-v4l2/vidc/vdec/src/frameparser.cpp b/mm-video-v4l2/vidc/vdec/src/frameparser.cpp
index 4f9dcf0..334ad92 100644
--- a/mm-video-v4l2/vidc/vdec/src/frameparser.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/frameparser.cpp
@@ -44,6 +44,7 @@
 
 #include "frameparser.h"
 //#include "omx_vdec.h"
+#include "vidc_debug.h"
 
 #ifdef _ANDROID_
 extern "C" {
@@ -51,14 +52,6 @@
 }
 #endif//_ANDROID_
 
-#undef DEBUG_PRINT_LOW
-#undef DEBUG_PRINT_HIGH
-#undef DEBUG_PRINT_ERROR
-
-#define DEBUG_PRINT_LOW ALOGV
-#define DEBUG_PRINT_HIGH ALOGV
-#define DEBUG_PRINT_ERROR ALOGE
-
 static unsigned char H264_mask_code[4] = {0xFF,0xFF,0xFF,0xFF};
 static unsigned char H264_start_code[4] = {0x00,0x00,0x00,0x01};
 
diff --git a/mm-video-v4l2/vidc/vdec/src/hevc_utils.cpp b/mm-video-v4l2/vidc/vdec/src/hevc_utils.cpp
index 6585ce0..46b4590 100644
--- a/mm-video-v4l2/vidc/vdec/src/hevc_utils.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/hevc_utils.cpp
@@ -47,6 +47,7 @@
 
 ========================================================================== */
 #include "hevc_utils.h"
+#include "vidc_debug.h"
 #include <string.h>
 #include <stdlib.h>
 #include <limits.h>
@@ -55,9 +56,6 @@
 #include <cutils/properties.h>
 #endif
 
-#define DEBUG_PRINT_LOW ALOGV
-#define DEBUG_PRINT_ERROR ALOGE
-
 
 /* =======================================================================
 
@@ -202,7 +200,7 @@
 
         m_forceToStichNextNAL = true;
     } else if (nalu_type <= NAL_UNIT_RESERVED_23) {
-        DEBUG_PRINT_LOW("\n AU Boundary with NAL type %d ",nal_unit.nalu_type);
+        DEBUG_PRINT_LOW("\n AU Boundary with NAL type %d ", nalu_type);
 
         if (!m_forceToStichNextNAL) {
             bFirstSliceInPic = ((buffer[pos+2] & 0x80)>>7);
diff --git a/mm-video-v4l2/vidc/vdec/src/mp4_utils.cpp b/mm-video-v4l2/vidc/vdec/src/mp4_utils.cpp
index d47179f..c919e13 100644
--- a/mm-video-v4l2/vidc/vdec/src/mp4_utils.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/mp4_utils.cpp
@@ -27,6 +27,7 @@
 --------------------------------------------------------------------------*/
 #include "mp4_utils.h"
 //#include "omx_vdec.h"
+#include "vidc_debug.h"
 # include <stdio.h>
 #ifdef _ANDROID_
 extern "C" {
@@ -34,14 +35,6 @@
 }
 #endif//_ANDROID_
 
-#undef DEBUG_PRINT_LOW
-#undef DEBUG_PRINT_HIGH
-#undef DEBUG_PRINT_ERROR
-
-#define DEBUG_PRINT_LOW ALOGV
-#define DEBUG_PRINT_HIGH ALOGV
-#define DEBUG_PRINT_ERROR ALOGE
-
 MP4_Utils::MP4_Utils()
 {
     m_SrcWidth = 0;
diff --git a/mm-video-v4l2/vidc/vdec/src/omx_vdec_hevc.cpp b/mm-video-v4l2/vidc/vdec/src/omx_vdec_hevc.cpp
index e9ed0be..98ffe90 100644
--- a/mm-video-v4l2/vidc/vdec/src/omx_vdec_hevc.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/omx_vdec_hevc.cpp
@@ -49,6 +49,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <media/msm_media_info.h>
+#include <qdMetaData.h>
 
 #ifndef _ANDROID_
 #include <sys/ioctl.h>
@@ -64,11 +65,6 @@
 #include <gralloc_priv.h>
 #endif
 
-#if defined (_ANDROID_ICS_)
-#include <genlock.h>
-#include <qdMetaData.h>
-#endif
-
 #ifdef _ANDROID_
 #include "DivXDrmDecrypt.h"
 #endif //_ANDROID_
@@ -133,6 +129,9 @@
 #define EXTRADATA_IDX(__num_planes) (__num_planes  - 1)
 
 #define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA)
+
+int debug_level = PRIO_ERROR;
+
 void* async_message_thread (void *input)
 {
     OMX_BUFFERHEADERTYPE *buffer;
@@ -550,6 +549,10 @@
     DEBUG_PRINT_HIGH("In OMX vdec Constructor");
 #ifdef _ANDROID_
     char property_value[PROPERTY_VALUE_MAX] = {0};
+    property_get("vidc.debug.level", property_value, "0");
+    debug_level = atoi(property_value);
+    property_value[0] = '\0';
+
     property_get("vidc.dec.debug.perf", property_value, "0");
     perf_flag = atoi(property_value);
     if (perf_flag) {
@@ -5312,25 +5315,6 @@
         return OMX_ErrorBadParameter;
     }
 
-    /* memcpy (&fillbuffer.buffer,ptr_outputbuffer,
-       sizeof(struct vdec_bufferpayload));
-       fillbuffer.client_data = bufferAdd;*/
-
-#ifdef _ANDROID_ICS_
-    if (m_enable_android_native_buffers) {
-        // Acquire a write lock on this buffer.
-        if (GENLOCK_NO_ERROR != genlock_lock_buffer(native_buffer[buffer - m_out_mem_ptr].nativehandle,
-                    GENLOCK_WRITE_LOCK, GENLOCK_MAX_TIMEOUT)) {
-            DEBUG_PRINT_ERROR("Failed to acquire genlock");
-            buffer->nFilledLen = 0;
-            m_cb.FillBufferDone (hComp,m_app_data,buffer);
-            pending_output_buffers--;
-            return OMX_ErrorInsufficientResources;
-        } else {
-            native_buffer[buffer - m_out_mem_ptr].inuse = true;
-        }
-    }
-#endif
     int rc = 0;
     struct v4l2_buffer buf;
     struct v4l2_plane plane[VIDEO_MAX_PLANES];
@@ -5370,22 +5354,6 @@
         /*TODO: How to handle this case */
         DEBUG_PRINT_ERROR("Failed to qbuf to driver");
     }
-    //#ifdef _ANDROID_ICS_
-    //  if (m_enable_android_native_buffers)
-    //  {
-    // Unlock the buffer
-    //     if (GENLOCK_NO_ERROR != genlock_unlock_buffer(native_buffer[buffer - m_out_mem_ptr].nativehandle)) {
-    //        DEBUG_PRINT_ERROR("Releasing genlock failed");
-    //        return OMX_ErrorInsufficientResources;
-    ///    } else {
-    //       native_buffer[buffer - m_out_mem_ptr].inuse = false;
-    //  }
-    // }
-    //#endif
-    //m_cb.FillBufferDone (hComp,m_app_data,buffer);
-    // pending_output_buffers--;
-    // return OMX_ErrorBadParameter;
-    //}
 return OMX_ErrorNone;
 }
 
@@ -5452,16 +5420,6 @@
         DEBUG_PRINT_LOW("Freeing the Output Memory\n");
         for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) {
             free_output_buffer (&m_out_mem_ptr[i]);
-#ifdef _ANDROID_ICS_
-            if (m_enable_android_native_buffers) {
-                if (native_buffer[i].inuse) {
-                    if (GENLOCK_NO_ERROR != genlock_unlock_buffer(native_buffer[i].nativehandle)) {
-                        DEBUG_PRINT_ERROR("Unlocking genlock failed");
-                    }
-                    native_buffer[i].inuse = false;
-                }
-            }
-#endif
         }
 #ifdef _ANDROID_ICS_
         memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
@@ -6046,18 +6004,6 @@
             ((OMX_QCOM_PLATFORM_PRIVATE_LIST *)
              buffer->pPlatformPrivate)->entryList->entry;
         DEBUG_PRINT_LOW("\n Before FBD callback Accessed Pmeminfo %d",pPMEMInfo->pmem_fd);
-#ifdef _ANDROID_ICS_
-        if (m_enable_android_native_buffers) {
-            if (native_buffer[buffer - m_out_mem_ptr].inuse) {
-                if (GENLOCK_NO_ERROR != genlock_unlock_buffer(native_buffer[buffer - m_out_mem_ptr].nativehandle)) {
-                    DEBUG_PRINT_ERROR("Unlocking genlock failed");
-                    return OMX_ErrorInsufficientResources;
-                } else {
-                    native_buffer[buffer - m_out_mem_ptr].inuse = false;
-                }
-            }
-        }
-#endif
         OMX_BUFFERHEADERTYPE *il_buffer;
         il_buffer = client_buffers.get_il_buf_hdr(buffer);
         if (il_buffer)
diff --git a/mm-video-v4l2/vidc/vdec/src/omx_vdec_msm8974.cpp b/mm-video-v4l2/vidc/vdec/src/omx_vdec_msm8974.cpp
index 6ae8397..bbff759 100644
--- a/mm-video-v4l2/vidc/vdec/src/omx_vdec_msm8974.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/omx_vdec_msm8974.cpp
@@ -61,14 +61,7 @@
 #undef USE_EGL_IMAGE_GPU
 #endif
 
-#if  defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
-#include <gralloc_priv.h>
-#endif
-
-#if defined (_ANDROID_ICS_)
-#include <genlock.h>
 #include <qdMetaData.h>
-#endif
 
 #ifdef _ANDROID_
 #include "DivXDrmDecrypt.h"
@@ -134,6 +127,9 @@
 #define EXTRADATA_IDX(__num_planes) (__num_planes  - 1)
 
 #define DEFAULT_EXTRADATA (OMX_INTERLACE_EXTRADATA)
+
+int debug_level = PRIO_ERROR;
+
 void* async_message_thread (void *input)
 {
     OMX_BUFFERHEADERTYPE *buffer;
@@ -538,6 +534,10 @@
     DEBUG_PRINT_HIGH("In OMX vdec Constructor");
 #ifdef _ANDROID_
     char property_value[PROPERTY_VALUE_MAX] = {0};
+    property_get("vidc.debug.level", property_value, "0");
+    debug_level = atoi(property_value);
+    property_value[0] = '\0';
+
     property_get("vidc.dec.debug.perf", property_value, "0");
     perf_flag = atoi(property_value);
     if (perf_flag) {
@@ -1140,22 +1140,6 @@
                                             DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
                                         }
 
-                                        if (pThis->drv_ctx.interlace != VDEC_InterlaceFrameProgressive) {
-                                            OMX_INTERLACETYPE format = (OMX_INTERLACETYPE)-1;
-                                            OMX_EVENTTYPE event = (OMX_EVENTTYPE)OMX_EventIndexsettingChanged;
-                                            if (pThis->drv_ctx.interlace == VDEC_InterlaceInterleaveFrameTopFieldFirst)
-                                                format = OMX_InterlaceInterleaveFrameTopFieldFirst;
-                                            else if (pThis->drv_ctx.interlace == VDEC_InterlaceInterleaveFrameBottomFieldFirst)
-                                                format = OMX_InterlaceInterleaveFrameBottomFieldFirst;
-                                            else //unsupported interlace format; raise a error
-                                                event = OMX_EventError;
-                                            if (pThis->m_cb.EventHandler) {
-                                                pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
-                                                        event, format, 0, NULL );
-                                            } else {
-                                                DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
-                                            }
-                                        }
                                         break;
 
                 case OMX_COMPONENT_GENERATE_EOS_DONE:
@@ -1180,15 +1164,6 @@
                                         pThis->omx_report_unsupported_setting();
                                         break;
 
-                case OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG: {
-                                            DEBUG_PRINT_HIGH("\n Rxd OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG");
-                                            if (pThis->m_cb.EventHandler) {
-                                                pThis->m_cb.EventHandler(&pThis->m_cmp, pThis->m_app_data,
-                                                        (OMX_EVENTTYPE)OMX_EventIndexsettingChanged, OMX_CORE_OUTPUT_PORT_INDEX, 0, NULL );
-                                            } else {
-                                                DEBUG_PRINT_ERROR("ERROR: %s()::EventHandler is NULL", __func__);
-                                            }
-                                        }
                 default:
                                         break;
             }
@@ -5519,25 +5494,6 @@
         return OMX_ErrorBadParameter;
     }
 
-    /* memcpy (&fillbuffer.buffer,ptr_outputbuffer,
-       sizeof(struct vdec_bufferpayload));
-       fillbuffer.client_data = bufferAdd;*/
-
-#ifdef _ANDROID_ICS_
-    if (m_enable_android_native_buffers) {
-        // Acquire a write lock on this buffer.
-        if (GENLOCK_NO_ERROR != genlock_lock_buffer(native_buffer[buffer - m_out_mem_ptr].nativehandle,
-                    GENLOCK_WRITE_LOCK, GENLOCK_MAX_TIMEOUT)) {
-            DEBUG_PRINT_ERROR("Failed to acquire genlock");
-            buffer->nFilledLen = 0;
-            m_cb.FillBufferDone (hComp,m_app_data,buffer);
-            pending_output_buffers--;
-            return OMX_ErrorInsufficientResources;
-        } else {
-            native_buffer[buffer - m_out_mem_ptr].inuse = true;
-        }
-    }
-#endif
     int rc = 0;
     struct v4l2_buffer buf;
     struct v4l2_plane plane[VIDEO_MAX_PLANES];
@@ -5577,22 +5533,6 @@
         /*TODO: How to handle this case */
         DEBUG_PRINT_ERROR("Failed to qbuf to driver");
     }
-    //#ifdef _ANDROID_ICS_
-    //  if (m_enable_android_native_buffers)
-    //  {
-    // Unlock the buffer
-    //     if (GENLOCK_NO_ERROR != genlock_unlock_buffer(native_buffer[buffer - m_out_mem_ptr].nativehandle)) {
-    //        DEBUG_PRINT_ERROR("Releasing genlock failed");
-    //        return OMX_ErrorInsufficientResources;
-    ///    } else {
-    //       native_buffer[buffer - m_out_mem_ptr].inuse = false;
-    //  }
-    // }
-    //#endif
-    //m_cb.FillBufferDone (hComp,m_app_data,buffer);
-    // pending_output_buffers--;
-    // return OMX_ErrorBadParameter;
-    //}
 return OMX_ErrorNone;
 }
 
@@ -5659,16 +5599,6 @@
         DEBUG_PRINT_LOW("Freeing the Output Memory\n");
         for (i = 0; i < drv_ctx.op_buf.actualcount; i++ ) {
             free_output_buffer (&m_out_mem_ptr[i]);
-#ifdef _ANDROID_ICS_
-            if (m_enable_android_native_buffers) {
-                if (native_buffer[i].inuse) {
-                    if (GENLOCK_NO_ERROR != genlock_unlock_buffer(native_buffer[i].nativehandle)) {
-                        DEBUG_PRINT_ERROR("Unlocking genlock failed");
-                    }
-                    native_buffer[i].inuse = false;
-                }
-            }
-#endif
         }
 #ifdef _ANDROID_ICS_
         memset(&native_buffer, 0, (sizeof(nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
@@ -6294,18 +6224,6 @@
             ((OMX_QCOM_PLATFORM_PRIVATE_LIST *)
              buffer->pPlatformPrivate)->entryList->entry;
         DEBUG_PRINT_LOW("\n Before FBD callback Accessed Pmeminfo %lu",pPMEMInfo->pmem_fd);
-#ifdef _ANDROID_ICS_
-        if (m_enable_android_native_buffers) {
-            if (native_buffer[buffer - m_out_mem_ptr].inuse) {
-                if (GENLOCK_NO_ERROR != genlock_unlock_buffer(native_buffer[buffer - m_out_mem_ptr].nativehandle)) {
-                    DEBUG_PRINT_ERROR("Unlocking genlock failed");
-                    return OMX_ErrorInsufficientResources;
-                } else {
-                    native_buffer[buffer - m_out_mem_ptr].inuse = false;
-                }
-            }
-        }
-#endif
         OMX_BUFFERHEADERTYPE *il_buffer;
         il_buffer = client_buffers.get_il_buf_hdr(buffer);
         if (il_buffer)
@@ -6525,12 +6443,36 @@
                         DEBUG_PRINT_HIGH("\n Crop information changed. W: %d --> %d, H: %d -> %d\n",
                                 omx->rectangle.nWidth, vdec_msg->msgdata.output_frame.framesize.right,
                                 omx->rectangle.nHeight, vdec_msg->msgdata.output_frame.framesize.bottom);
+                        if (vdec_msg->msgdata.output_frame.framesize.left + vdec_msg->msgdata.output_frame.framesize.right >=
+                            omx->drv_ctx.video_resolution.frame_width) {
+                            vdec_msg->msgdata.output_frame.framesize.left = 0;
+                            if (vdec_msg->msgdata.output_frame.framesize.right > omx->drv_ctx.video_resolution.frame_width) {
+                                vdec_msg->msgdata.output_frame.framesize.right =  omx->drv_ctx.video_resolution.frame_width;
+                            }
+                        }
+                        if (vdec_msg->msgdata.output_frame.framesize.top + vdec_msg->msgdata.output_frame.framesize.bottom >=
+                            omx->drv_ctx.video_resolution.frame_height) {
+                            vdec_msg->msgdata.output_frame.framesize.top = 0;
+                            if (vdec_msg->msgdata.output_frame.framesize.bottom > omx->drv_ctx.video_resolution.frame_height) {
+                                vdec_msg->msgdata.output_frame.framesize.bottom =  omx->drv_ctx.video_resolution.frame_height;
+                            }
+                        }
+                        DEBUG_PRINT_LOW("omx_vdec: Adjusted Dim L: %d, T: %d, R: %d, B: %d, W: %d, H: %d\n",
+                                        vdec_msg->msgdata.output_frame.framesize.left,
+                                        vdec_msg->msgdata.output_frame.framesize.top,
+                                        vdec_msg->msgdata.output_frame.framesize.right,
+                                        vdec_msg->msgdata.output_frame.framesize.bottom,
+                                        omx->drv_ctx.video_resolution.frame_width,
+                                        omx->drv_ctx.video_resolution.frame_height);
                         omx->rectangle.nLeft = vdec_msg->msgdata.output_frame.framesize.left;
                         omx->rectangle.nTop = vdec_msg->msgdata.output_frame.framesize.top;
                         omx->rectangle.nWidth = vdec_msg->msgdata.output_frame.framesize.right;
                         omx->rectangle.nHeight = vdec_msg->msgdata.output_frame.framesize.bottom;
                         format_notably_changed = 1;
                     }
+                    DEBUG_PRINT_HIGH("Left: %d, Right: %d, top: %d, Bottom: %d\n",
+                                      vdec_msg->msgdata.output_frame.framesize.left,vdec_msg->msgdata.output_frame.framesize.right,
+                                      vdec_msg->msgdata.output_frame.framesize.top, vdec_msg->msgdata.output_frame.framesize.bottom);
                     if (format_notably_changed) {
                         if (omx->is_video_session_supported()) {
                             omx->post_event (NULL, vdec_msg->status_code,
diff --git a/mm-video-v4l2/vidc/vdec/src/ts_parser.cpp b/mm-video-v4l2/vidc/vdec/src/ts_parser.cpp
index 9825348..fd941ff 100644
--- a/mm-video-v4l2/vidc/vdec/src/ts_parser.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/ts_parser.cpp
@@ -26,8 +26,10 @@
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 --------------------------------------------------------------------------*/
 #include "ts_parser.h"
+#include "vidc_debug.h"
 
-#define DEBUG ALOGE
+#define DEBUG DEBUG_PRINT_ERROR
+
 void omx_time_stamp_reorder::set_timestamp_reorder_mode(bool mode)
 {
     reorder_ts = mode;
diff --git a/mm-video-v4l2/vidc/venc/inc/omx_video_base.h b/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
index e63d671..aa15d0c 100644
--- a/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
+++ b/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
@@ -63,6 +63,7 @@
 #include <linux/videodev2.h>
 #include <dlfcn.h>
 #include "C2DColorConverter.h"
+#include "vidc_debug.h"
 
 #ifdef _ANDROID_
 using namespace android;
@@ -76,10 +77,6 @@
 
 #include <utils/Log.h>
 
-#else //_ANDROID_
-#define DEBUG_PRINT_LOW
-#define DEBUG_PRINT_HIGH
-#define DEBUG_PRINT_ERROR
 #endif // _ANDROID_
 
 #ifdef USE_ION
diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
index 7c7fc85..d9e5c84 100644
--- a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
+++ b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
@@ -50,6 +50,7 @@
 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION
 
 extern int m_pipe;
+int debug_level = PRIO_ERROR;
 
 // factory function executed by the core to create instances
 void *get_omx_component_factory_fn(void)
@@ -69,6 +70,10 @@
     mUseProxyColorFormat = false;
     get_syntaxhdr_enable = false;
 #endif
+    char property_value[PROPERTY_VALUE_MAX] = {0};
+    property_get("vidc.debug.level", property_value, "0");
+    debug_level = atoi(property_value);
+    property_value[0] = '\0';
 }
 
 omx_venc::~omx_venc()