Permalink
Browse files

Fix alignment and copy size for legacy QCOM OMX

Change-Id: I6d13c67601da0f0c35d3dd455401f982406cefe3
  • Loading branch information...
1 parent 76db918 commit 976d7e9c8d842aecc5f8f1a0a9754428d8f2523c @grigorig committed Jan 19, 2013
Showing with 11 additions and 10 deletions.
  1. +11 −10 media/libstagefright/colorconversion/SoftwareRenderer.cpp
@@ -42,6 +42,11 @@ static bool runningInEmulator() {
return (property_get("ro.kernel.qemu", prop, NULL) > 0);
}
+static int ALIGN(int x, int y) {
+ // y must be a power of 2.
+ return (x + y - 1) & ~(y - 1);
+}
+
SoftwareRenderer::SoftwareRenderer(
const sp<ANativeWindow> &nativeWindow, const sp<MetaData> &meta)
: mConverter(NULL),
@@ -90,9 +95,9 @@ SoftwareRenderer::SoftwareRenderer(
case OMX_QCOM_COLOR_FormatYVU420SemiPlanar:
{
halFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
- bufWidth = (mCropWidth + 1) & ~1;
- bufHeight = (mCropHeight + 1) & ~1;
- mAlign = ((mWidth + 15) & -16) * ((mHeight + 15) & -16);
+ bufWidth = ALIGN(mCropWidth, 16);
+ bufHeight = ALIGN(mCropHeight, 2);
+ mAlign = ALIGN(mWidth, 16) * ALIGN(mHeight, 16);
break;
}
#endif
@@ -168,11 +173,6 @@ SoftwareRenderer::~SoftwareRenderer() {
mConverter = NULL;
}
-static int ALIGN(int x, int y) {
- // y must be a power of 2.
- return (x + y - 1) & ~(y - 1);
-}
-
void SoftwareRenderer::render(
const void *data, size_t size, void *platformPrivate) {
ANativeWindowBuffer *buf;
@@ -236,10 +236,11 @@ void SoftwareRenderer::render(
uint8_t *src_u = src_y + mAlign;
uint8_t *dst_y = (uint8_t *)dst;
uint8_t *dst_u = dst_y + buf->stride * buf->height;
+ size_t bufsz = ALIGN(mCropWidth, 16) * ALIGN(mCropHeight, 2);
// Legacy codec doesn't return crop params. Ignore it for speedup :)
- memcpy(dst_y, src_y, mCropWidth * mCropHeight);
- memcpy(dst_u, src_u, mCropWidth * mCropHeight / 2);
+ memcpy(dst_y, src_y, bufsz);
+ memcpy(dst_u, src_u, bufsz / 2);
/*for(size_t y = 0; y < mCropHeight; ++y) {
memcpy(dst_y, src_y, mCropWidth);

2 comments on commit 976d7e9

C3C0 replied Jan 19, 2013

Great job, man :)
Gonna try it on my ParanoidJelly 4.1.2.

C3C0 replied Jan 19, 2013

Just to confirm it seems to be working great :)
Huge thanks.

Please sign in to comment.