Change preview player code also.
Adapt to 32 bit aligned decoder buffers
Change-Id: I631f7e60b8e424af496f45d0e5e292bf9e8a9dde
diff --git a/libvideoeditor/lvpp/PreviewPlayer.cpp b/libvideoeditor/lvpp/PreviewPlayer.cpp
index 2f46e4c..4738fdd 100755
--- a/libvideoeditor/lvpp/PreviewPlayer.cpp
+++ b/libvideoeditor/lvpp/PreviewPlayer.cpp
@@ -141,7 +141,9 @@
PreviewPlayer::PreviewPlayer()
: AwesomePlayer(),
mFrameRGBBuffer(NULL),
- mFrameYUVBuffer(NULL) {
+ mFrameYUVBuffer(NULL),
+ mReportedWidth(0),
+ mReportedHeight(0) {
mVideoRenderer = NULL;
mLastVideoBuffer = NULL;
@@ -308,6 +310,9 @@
mVideoSource = DummyVideoSource::Create(mVideoWidth, mVideoHeight,
mDurationUs, mUri);
+ mReportedWidth = mVideoWidth;
+ mReportedHeight = mVideoHeight;
+
setVideoSource(mVideoSource);
status_t err1 = mVideoSource->start();
if (err1 != OK) {
@@ -648,6 +653,9 @@
CHECK(mVideoTrack->getFormat()->findInt32(kKeyWidth, &mVideoWidth));
CHECK(mVideoTrack->getFormat()->findInt32(kKeyHeight, &mVideoHeight));
+ mReportedWidth = mVideoWidth;
+ mReportedHeight = mVideoHeight;
+
status_t err = mVideoSource->start();
if (err != OK) {
@@ -720,7 +728,10 @@
if (err == INFO_FORMAT_CHANGED) {
LOGV("LV PLAYER VideoSource signalled format change");
notifyVideoSize_l();
+ sp<MetaData> meta = mVideoSource->getFormat();
+ CHECK(meta->findInt32(kKeyWidth, &mReportedWidth));
+ CHECK(meta->findInt32(kKeyHeight, &mReportedHeight));
if (mVideoRenderer != NULL) {
mVideoRendererIsPreview = false;
initRenderer_l();
@@ -1397,7 +1408,7 @@
/* In plane*/
prepareYUV420ImagePlane(planeIn, mVideoWidth,
- mVideoHeight, (M4VIFI_UInt8 *)inBuffer);
+ mVideoHeight, (M4VIFI_UInt8 *)inBuffer, mReportedWidth, mReportedHeight);
// Set the output YUV420 plane to be compatible with YV12 format
// W & H even
@@ -1588,7 +1599,7 @@
postProcessParams.overlayFrameRGBBuffer = mFrameRGBBuffer;
postProcessParams.overlayFrameYUVBuffer = mFrameYUVBuffer;
mVideoRenderer->getBuffer(&(postProcessParams.pOutBuffer), &(postProcessParams.outBufferStride));
- err = applyEffectsAndRenderingMode(&postProcessParams);
+ err = applyEffectsAndRenderingMode(&postProcessParams, mReportedWidth, mReportedHeight);
return err;
}
@@ -1615,6 +1626,10 @@
if (err == INFO_FORMAT_CHANGED) {
LOGV("LV PLAYER VideoSource signalled format change");
notifyVideoSize_l();
+ sp<MetaData> meta = mVideoSource->getFormat();
+
+ CHECK(meta->findInt32(kKeyWidth, &mReportedWidth));
+ CHECK(meta->findInt32(kKeyHeight, &mReportedHeight));
if (mVideoRenderer != NULL) {
mVideoRendererIsPreview = false;
diff --git a/libvideoeditor/lvpp/PreviewPlayer.h b/libvideoeditor/lvpp/PreviewPlayer.h
index 214c136..ebbdec8 100755
--- a/libvideoeditor/lvpp/PreviewPlayer.h
+++ b/libvideoeditor/lvpp/PreviewPlayer.h
@@ -74,7 +74,7 @@
const char *uri, const KeyedVector<String8, String8> *headers);
//Added methods
- status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings,
+ status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings,
int nEffects);
status_t loadAudioMixSettings(M4xVSS_AudioMixingSettings* pAudioMixSettings);
status_t setAudioMixPCMFileHandle(M4OSA_Context pAudioMixPCMFileHandle);
@@ -185,6 +185,9 @@
uint32_t mOutputVideoWidth;
uint32_t mOutputVideoHeight;
+ int32_t mReportedWidth; //docoder reported width
+ int32_t mReportedHeight; //docoder reported height
+
uint32_t mStoryboardStartTimeMsec;
bool mIsVideoSourceJpg;
diff --git a/libvideoeditor/lvpp/VideoEditorPreviewController.cpp b/libvideoeditor/lvpp/VideoEditorPreviewController.cpp
index d862255..c079898 100755
--- a/libvideoeditor/lvpp/VideoEditorPreviewController.cpp
+++ b/libvideoeditor/lvpp/VideoEditorPreviewController.cpp
@@ -1174,7 +1174,7 @@
mTarget->getBufferYV12(&(postProcessParams.pOutBuffer), &(postProcessParams.outBufferStride));
- err = applyEffectsAndRenderingMode(&postProcessParams);
+ err = applyEffectsAndRenderingMode(&postProcessParams, mOutputVideoWidth, mOutputVideoHeight);
return err;
}
@@ -1273,7 +1273,7 @@
// In plane
prepareYUV420ImagePlane(planeIn, videoWidth,
- videoHeight, (M4VIFI_UInt8 *)inBuffer);
+ videoHeight, (M4VIFI_UInt8 *)inBuffer, videoWidth, videoHeight);
outputBufferWidth = mOutputVideoWidth;
outputBufferHeight = mOutputVideoHeight;
diff --git a/libvideoeditor/lvpp/VideoEditorTools.cpp b/libvideoeditor/lvpp/VideoEditorTools.cpp
index 99fc6b5..73362ad 100755
--- a/libvideoeditor/lvpp/VideoEditorTools.cpp
+++ b/libvideoeditor/lvpp/VideoEditorTools.cpp
@@ -2161,7 +2161,7 @@
}
*pContext = M4OSA_NULL ;
-
+
return err ;
}
@@ -2222,7 +2222,7 @@
M4OSA_UInt32 nb_planes;
M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext) ;
-
+
if(M4AIR_kYUV420AP == pC->m_inputFormat)
{
nb_planes = 4;
@@ -2395,7 +2395,7 @@
}
/**< Update state */
pC->m_state = M4AIR_kConfigured;
-
+
return M4NO_ERROR ;
}
@@ -3065,8 +3065,9 @@
}
M4OSA_Void prepareYUV420ImagePlane(M4VIFI_ImagePlane *plane,
- M4OSA_UInt32 width, M4OSA_UInt32 height, M4VIFI_UInt8 *buffer) {
-
+ M4OSA_UInt32 width, M4OSA_UInt32 height, M4VIFI_UInt8 *buffer,
+ M4OSA_UInt32 reportedWidth, M4OSA_UInt32 reportedHeight) {
+
//Y plane
plane[0].u_width = width;
plane[0].u_height = height;
@@ -3079,21 +3080,20 @@
plane[1].u_height = height/2;
plane[1].u_stride = plane[1].u_width;
plane[1].u_topleft = 0;
- plane[1].pac_data = buffer+(width*height);
+ plane[1].pac_data = buffer+(reportedWidth*reportedHeight);
// V Plane
plane[2].u_width = width/2;
plane[2].u_height = height/2;
plane[2].u_stride = plane[2].u_width;
plane[2].u_topleft = 0;
- plane[2].pac_data = buffer+(width*height+(width/2)*(height/2));
-
+ plane[2].pac_data = plane[1].pac_data + ((reportedWidth/2)*(reportedHeight/2));
}
M4OSA_Void prepareYV12ImagePlane(M4VIFI_ImagePlane *plane,
M4OSA_UInt32 width, M4OSA_UInt32 height, M4OSA_UInt32 stride,
M4VIFI_UInt8 *buffer) {
-
+
//Y plane
plane[0].u_width = width;
plane[0].u_height = height;
@@ -3119,13 +3119,13 @@
plane[2].pac_data = (buffer +
plane[0].u_height * android::PreviewRenderer::ALIGN(plane[0].u_stride, 16));
-
+
}
M4OSA_Void swapImagePlanes(
M4VIFI_ImagePlane *planeIn, M4VIFI_ImagePlane *planeOut,
M4VIFI_UInt8 *buffer1, M4VIFI_UInt8 *buffer2) {
-
+
planeIn[0].u_height = planeOut[0].u_height;
planeIn[0].u_width = planeOut[0].u_width;
planeIn[0].u_stride = planeOut[0].u_stride;
@@ -3167,7 +3167,7 @@
planeOut[0].u_width*planeOut[0].u_height +
planeOut[1].u_width*planeOut[1].u_height);
}
-
+
}
M4OSA_Void computePercentageDone(
@@ -3405,7 +3405,8 @@
return err;
}
-M4OSA_ERR applyEffectsAndRenderingMode(vePostProcessParams *params) {
+M4OSA_ERR applyEffectsAndRenderingMode(vePostProcessParams *params,
+ M4OSA_UInt32 reportedWidth, M4OSA_UInt32 reportedHeight) {
M4OSA_ERR err = M4NO_ERROR;
M4VIFI_ImagePlane planeIn[3], planeOut[3];
@@ -3441,12 +3442,12 @@
}
// Initialize the In plane
- prepareYUV420ImagePlane(planeIn, params->videoWidth,
- params->videoHeight, params->vidBuffer);
+ prepareYUV420ImagePlane(planeIn, params->videoWidth, params->videoHeight,
+ params->vidBuffer, reportedWidth, reportedHeight);
// Initialize the Out plane
- prepareYUV420ImagePlane(planeOut, params->videoWidth,
- params->videoHeight, (M4VIFI_UInt8 *)tempOutputBuffer);
+ prepareYUV420ImagePlane(planeOut, params->videoWidth, params->videoHeight,
+ (M4VIFI_UInt8 *)tempOutputBuffer, params->videoWidth, params->videoHeight);
// The planeIn contains the YUV420 input data to postprocessing node
// and planeOut will contain the YUV420 data with effect
diff --git a/libvideoeditor/lvpp/VideoEditorTools.h b/libvideoeditor/lvpp/VideoEditorTools.h
index 368047a..5140e8b 100755
--- a/libvideoeditor/lvpp/VideoEditorTools.h
+++ b/libvideoeditor/lvpp/VideoEditorTools.h
@@ -107,7 +107,8 @@
M4VIFI_ImagePlane *pPlaneOut);
M4OSA_Void prepareYUV420ImagePlane(M4VIFI_ImagePlane *plane,
- M4OSA_UInt32 width, M4OSA_UInt32 height, M4VIFI_UInt8 *buffer);
+ M4OSA_UInt32 width, M4OSA_UInt32 height, M4VIFI_UInt8 *buffer,
+ M4OSA_UInt32 reportedWidth, M4OSA_UInt32 reportedHeight);
M4OSA_Void prepareYV12ImagePlane(M4VIFI_ImagePlane *plane,
M4OSA_UInt32 width, M4OSA_UInt32 height, M4OSA_UInt32 stride, M4VIFI_UInt8 *buffer);
@@ -141,5 +142,7 @@
M4VIFI_ImagePlane *planeIn, M4VIFI_ImagePlane *planeOut,
M4VIFI_UInt8 *buffer1, M4VIFI_UInt8 *buffer2, M4VFL_CurtainParam* curtainParams);
-M4OSA_ERR applyEffectsAndRenderingMode(vePostProcessParams* params);
+M4OSA_ERR applyEffectsAndRenderingMode(vePostProcessParams *params,
+ M4OSA_UInt32 reportedWidth, M4OSA_UInt32 reportedHeight);
+
#endif // ANDROID_VE_TOOLS_H
diff --git a/libvideoeditor/vss/stagefrightshells/inc/VideoEditorVideoDecoder_internal.h b/libvideoeditor/vss/stagefrightshells/inc/VideoEditorVideoDecoder_internal.h
index 224a6d9..251fb4f 100755
--- a/libvideoeditor/vss/stagefrightshells/inc/VideoEditorVideoDecoder_internal.h
+++ b/libvideoeditor/vss/stagefrightshells/inc/VideoEditorVideoDecoder_internal.h
@@ -108,6 +108,8 @@
M4OSA_UInt32 mNbOutputFrames;
M4OSA_Double mFirstOutputCts;
M4OSA_Double mLastOutputCts;
+ M4OSA_Int32 mGivenWidth, mGivenHeight; //Used in case of
+ //INFO_FORMAT_CHANGED
} VideoEditorVideoDecoder_Context;
diff --git a/libvideoeditor/vss/stagefrightshells/src/VideoEditorVideoDecoder.cpp b/libvideoeditor/vss/stagefrightshells/src/VideoEditorVideoDecoder.cpp
index b362197..208a04e 100755
--- a/libvideoeditor/vss/stagefrightshells/src/VideoEditorVideoDecoder.cpp
+++ b/libvideoeditor/vss/stagefrightshells/src/VideoEditorVideoDecoder.cpp
@@ -721,6 +721,8 @@
int32_t width = 0;
int32_t height = 0;
int32_t frameSize = 0;
+ int32_t vWidth, vHeight;
+ int32_t cropLeft, cropTop, cropRight, cropBottom;
VIDEOEDITOR_CHECK(M4OSA_NULL != pContext, M4ERR_PARAMETER);
VIDEOEDITOR_CHECK(M4OSA_NULL != meta, M4ERR_PARAMETER);
@@ -729,10 +731,29 @@
pDecShellContext = (VideoEditorVideoDecoder_Context*)pContext;
- // Get the parameters
- success = meta->findInt32(kKeyWidth, &width);
- success &= meta->findInt32(kKeyHeight, &height);
+ success = meta->findInt32(kKeyWidth, &vWidth);
VIDEOEDITOR_CHECK(TRUE == success, M4ERR_PARAMETER);
+ success = meta->findInt32(kKeyHeight, &vHeight);
+ VIDEOEDITOR_CHECK(TRUE == success, M4ERR_PARAMETER);
+
+ pDecShellContext->mGivenWidth = vWidth;
+ pDecShellContext->mGivenHeight = vHeight;
+
+ if (!meta->findRect(
+ kKeyCropRect, &cropLeft, &cropTop, &cropRight, &cropBottom)) {
+
+ cropLeft = cropTop = 0;
+ cropRight = vWidth - 1;
+ cropBottom = vHeight - 1;
+
+ LOGI("got dimensions only %d x %d", width, height);
+ } else {
+ LOGI("got crop rect %d, %d, %d, %d",
+ cropLeft, cropTop, cropRight, cropBottom);
+ }
+
+ width = cropRight - cropLeft + 1;
+ height = cropBottom - cropTop + 1;
LOGV("VideoDecoder_configureFromMetadata : W=%d H=%d", width, height);
VIDEOEDITOR_CHECK((0 != width) && (0 != height), M4ERR_PARAMETER);
@@ -763,7 +784,8 @@
MAX_DEC_BUFFERS, (M4OSA_Char*)"VIDEOEDITOR_DecodedBufferPool");
VIDEOEDITOR_CHECK(M4NO_ERROR == err, err);
err = VIDEOEDITOR_BUFFER_initPoolBuffers(pDecShellContext->m_pDecBufferPool,
- frameSize + width * 2);
+ frameSize + pDecShellContext->mGivenWidth * 2);
+
VIDEOEDITOR_CHECK(M4NO_ERROR == err, err);
cleanUp:
@@ -876,6 +898,7 @@
pDecShellContext->mNbOutputFrames = 0;
pDecShellContext->mFirstOutputCts = -1;
pDecShellContext->mLastOutputCts = -1;
+ pDecShellContext->m_pDecBufferPool = M4OSA_NULL;
/**
* StageFright graph building
@@ -1197,11 +1220,27 @@
break;
}
case OMX_COLOR_FormatYUV420Planar:
- M4OSA_memcpy((M4OSA_MemAddr8)tmpDecBuffer->pData,
- (M4OSA_MemAddr8) pDecoderBuffer->data() +
- pDecoderBuffer->range_offset(),
- (M4OSA_UInt32)pDecoderBuffer->range_length());
+ {
+ int32_t width = pDecShellContext->m_pVideoStreamhandler->m_videoWidth;
+ int32_t height = pDecShellContext->m_pVideoStreamhandler->m_videoHeight;
+ int32_t yPlaneSize = width * height;
+ int32_t uvPlaneSize = width * height / 4;
+ int32_t offsetSrc = 0;
+
+ M4OSA_MemAddr8 pTmpBuff = (M4OSA_MemAddr8)pDecoderBuffer->data() + pDecoderBuffer->range_offset();
+
+ M4OSA_memcpy((M4OSA_MemAddr8)tmpDecBuffer->pData, pTmpBuff, yPlaneSize);
+
+ offsetSrc += pDecShellContext->mGivenWidth * pDecShellContext->mGivenHeight;
+ M4OSA_memcpy((M4OSA_MemAddr8)tmpDecBuffer->pData + yPlaneSize,
+ pTmpBuff + offsetSrc, uvPlaneSize);
+
+ offsetSrc += (pDecShellContext->mGivenWidth >> 1) * (pDecShellContext->mGivenHeight >> 1);
+ M4OSA_memcpy((M4OSA_MemAddr8)tmpDecBuffer->pData + yPlaneSize + uvPlaneSize,
+ pTmpBuff + offsetSrc, uvPlaneSize);
+
break;
+ }
default:
LOGV("VideoDecoder_decode: unexpected color format 0x%X",
pDecShellContext->decOuputColorFormat);