From db62a245f968159ea5ff8ad99afb4cd035e2304d Mon Sep 17 00:00:00 2001 From: Lakshman Gowda Date: Thu, 29 Sep 2011 17:47:35 -0700 Subject: [PATCH] Set crop params to ANative Window during Initialization. The native_window_set_crop() is called when port reconfig event callback comes from decoder's and crop parameters are changed from default getconfig() OMX_IndexConfigCommonOutputCrop values. Since the default crop params are same as port reconfig crop params, the native_window_set_crop() is not called, hence resulting in displaying the whole frame(paddedWidth x paddedHeight). By calling native_window_set_crop() during initilaization of output port of decoder ensures in setting up ANative window to crop region. Change-Id: I68926464a1f5c7e6053804615c8b9bd32ea85688 Signed-off-by: Lakshman Gowda --- include/media/stagefright/OMXCodec.h | 2 ++ media/libstagefright/OMXCodec.cpp | 38 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h index 21b8c74439160..0d5a72638686b 100644 --- a/include/media/stagefright/OMXCodec.h +++ b/include/media/stagefright/OMXCodec.h @@ -319,6 +319,8 @@ private: void initOutputFormat(const sp &inputFormat); status_t initNativeWindow(); + void initNativeWindowCrop(); + void dumpPortStatus(OMX_U32 portIndex); status_t configureCodec(const sp &meta); diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index ccc8a18aa6732..7c34257a383d1 100755 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -2351,22 +2351,6 @@ void OMXCodec::onEvent(OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2) { formatHasNotablyChanged(oldOutputFormat, mOutputFormat)) { mOutputPortSettingsHaveChanged = true; - if (mNativeWindow != NULL) { - int32_t left, top, right, bottom; - CHECK(mOutputFormat->findRect( - kKeyCropRect, - &left, &top, &right, &bottom)); - - android_native_rect_t crop; - crop.left = left; - crop.top = top; - crop.right = right + 1; - crop.bottom = bottom + 1; - - // We'll ignore any errors here, if the surface is - // already invalid, we'll know soon enough. - native_window_set_crop(mNativeWindow.get(), &crop); - } } else if (data2 == OMX_IndexConfigCommonScale) { OMX_CONFIG_SCALEFACTORTYPE scale; InitOMXParams(&scale); @@ -4183,6 +4167,24 @@ status_t OMXCodec::initNativeWindow() { return OK; } +void OMXCodec::initNativeWindowCrop() { + int32_t left, top, right, bottom; + + CHECK(mOutputFormat->findRect( + kKeyCropRect, + &left, &top, &right, &bottom)); + + android_native_rect_t crop; + crop.left = left; + crop.top = top; + crop.right = right + 1; + crop.bottom = bottom + 1; + + // We'll ignore any errors here, if the surface is + // already invalid, we'll know soon enough. + native_window_set_crop(mNativeWindow.get(), &crop); +} + void OMXCodec::initOutputFormat(const sp &inputFormat) { mOutputFormat = new MetaData; mOutputFormat->setCString(kKeyDecoderComponent, mComponentName); @@ -4366,6 +4368,10 @@ void OMXCodec::initOutputFormat(const sp &inputFormat) { video_def->nFrameWidth - 1, video_def->nFrameHeight - 1); } + + if (mNativeWindow != NULL) { + initNativeWindowCrop(); + } } break; }