summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/OMXCodec.cpp
diff options
context:
space:
mode:
authorcodeworkx <codeworkx@cyanogenmod.org>2012-11-24 14:39:44 +0100
committercodeworkx <codeworkx@cyanogenmod.org>2012-11-30 04:05:54 +0100
commit16be9b2826de9eb129c090b0e8edb75c6c63aad3 (patch)
treedcbd6946d8054ad6587efbbd46a12dcbbec0c24e /media/libstagefright/OMXCodec.cpp
parent001573b26e5ccfb6bee9a34837ec4f29d5f73f7f (diff)
downloadframeworks_av-16be9b2826de9eb129c090b0e8edb75c6c63aad3.zip
frameworks_av-16be9b2826de9eb129c090b0e8edb75c6c63aad3.tar.gz
frameworks_av-16be9b2826de9eb129c090b0e8edb75c6c63aad3.tar.bz2
exynos4: libstragefright: add support for samsung colorformat/omx/mfc
Source: http://git.insignal.co.kr/samsung/exynos/android/platform/frameworks/av/commit/?h=exynos-jb&id=1614612f7ca2a00473d202dbedcb135fadc608ad Change-Id: Ib40b3cfa1480ecbb69831e7967a81f63719e2ff7
Diffstat (limited to 'media/libstagefright/OMXCodec.cpp')
-rwxr-xr-xmedia/libstagefright/OMXCodec.cpp157
1 files changed, 154 insertions, 3 deletions
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 70de174..81f45f4 100755
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -44,8 +44,31 @@
#include "include/avc_utils.h"
+#ifdef USE_SAMSUNG_COLORFORMAT
+#include <sec_format.h>
+#endif
+
namespace android {
+#ifdef USE_SAMSUNG_COLORFORMAT
+static const int OMX_SEC_COLOR_FormatNV12TPhysicalAddress = 0x7F000001;
+static const int OMX_SEC_COLOR_FormatNV12LPhysicalAddress = 0x7F000002;
+static const int OMX_SEC_COLOR_FormatNV12LVirtualAddress = 0x7F000003;
+static const int OMX_SEC_COLOR_FormatNV12Tiled = 0x7FC00002;
+static int calc_plane(int width, int height)
+{
+ int mbX, mbY;
+
+ mbX = (width + 15)/16;
+ mbY = (height + 15)/16;
+
+ /* Alignment for interlaced processing */
+ mbY = (mbY + 1) / 2 * 2;
+
+ return (mbX * 16) * (mbY * 16);
+}
+#endif // USE_SAMSUNG_COLORFORMAT
+
// Treat time out as an error if we have not received any output
// buffers after 3 seconds.
const static int64_t kBufferFilledEventTimeOutNs = 3000000000LL;
@@ -691,6 +714,10 @@ status_t OMXCodec::setVideoPortFormatType(
return err;
}
+#ifdef USE_SAMSUNG_COLORFORMAT
+#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
+#endif
+
static size_t getFrameSize(
OMX_COLOR_FORMATTYPE colorFormat, int32_t width, int32_t height) {
switch (colorFormat) {
@@ -710,8 +737,20 @@ static size_t getFrameSize(
* this part in the future
*/
case OMX_COLOR_FormatAndroidOpaque:
+#ifdef USE_SAMSUNG_COLORFORMAT
+ case OMX_SEC_COLOR_FormatNV12TPhysicalAddress:
+ case OMX_SEC_COLOR_FormatNV12LPhysicalAddress:
+#endif
return (width * height * 3) / 2;
-
+#ifdef USE_SAMSUNG_COLORFORMAT
+
+ case OMX_SEC_COLOR_FormatNV12LVirtualAddress:
+ return ALIGN((ALIGN(width, 16) * ALIGN(height, 16)), 2048) + ALIGN((ALIGN(width, 16) * ALIGN(height >> 1, 8)), 2048);
+ case OMX_SEC_COLOR_FormatNV12Tiled:
+ static unsigned int frameBufferYSise = calc_plane(width, height);
+ static unsigned int frameBufferUVSise = calc_plane(width, height >> 1);
+ return (frameBufferYSise + frameBufferUVSise);
+#endif
default:
CHECK(!"Should not be here. Unsupported color format.");
break;
@@ -1218,7 +1257,21 @@ status_t OMXCodec::setVideoOutputFormat(
|| format.eColorFormat == OMX_COLOR_FormatCbYCrY
|| format.eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar
|| format.eColorFormat == OMX_QCOM_COLOR_FormatYVU420SemiPlanar
- || format.eColorFormat == OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka);
+ || format.eColorFormat == OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka
+#ifdef USE_SAMSUNG_COLORFORMAT
+ || format.eColorFormat == OMX_SEC_COLOR_FormatNV12TPhysicalAddress
+ || format.eColorFormat == OMX_SEC_COLOR_FormatNV12Tiled
+#endif
+ );
+
+#ifdef USE_SAMSUNG_COLORFORMAT
+ if (!strncmp("OMX.SEC.", mComponentName, 8)) {
+ if (mNativeWindow == NULL)
+ format.eColorFormat = OMX_COLOR_FormatYUV420Planar;
+ else
+ format.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
+ }
+#endif
int32_t colorFormat;
if (meta->findInt32(kKeyColorFormat, &colorFormat)
@@ -1263,7 +1316,11 @@ status_t OMXCodec::setVideoOutputFormat(
#if 1
// XXX Need a (much) better heuristic to compute input buffer sizes.
+#ifdef USE_SAMSUNG_COLORFORMAT
+ const size_t X = 64 * 8 * 1024;
+#else
const size_t X = 64 * 1024;
+#endif
if (def.nBufferSize < X) {
def.nBufferSize = X;
}
@@ -1709,11 +1766,22 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() {
return err;
}
+#ifndef USE_SAMSUNG_COLORFORMAT
err = native_window_set_buffers_geometry(
mNativeWindow.get(),
def.format.video.nFrameWidth,
def.format.video.nFrameHeight,
def.format.video.eColorFormat);
+#else
+ OMX_COLOR_FORMATTYPE eNativeColorFormat = def.format.video.eColorFormat;
+ setNativeWindowColorFormat(eNativeColorFormat);
+
+ err = native_window_set_buffers_geometry(
+ mNativeWindow.get(),
+ def.format.video.nFrameWidth,
+ def.format.video.nFrameHeight,
+ eNativeColorFormat);
+#endif
if (err != 0) {
ALOGE("native_window_set_buffers_geometry failed: %s (%d)",
@@ -1758,8 +1826,16 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() {
}
ALOGV("native_window_set_usage usage=0x%lx", usage);
+
+#ifdef EXYNOS4_ENHANCEMENTS
+ err = native_window_set_usage(
+ mNativeWindow.get(), usage | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
+ | GRALLOC_USAGE_HW_FIMC1 | GRALLOC_USAGE_HWC_HWOVERLAY);
+#else
err = native_window_set_usage(
mNativeWindow.get(), usage | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP);
+#endif
+
if (err != 0) {
ALOGE("native_window_set_usage failed: %s (%d)", strerror(-err), -err);
return err;
@@ -1855,6 +1931,30 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() {
return err;
}
+#ifdef USE_SAMSUNG_COLORFORMAT
+void OMXCodec::setNativeWindowColorFormat(OMX_COLOR_FORMATTYPE &eNativeColorFormat)
+{
+ // Convert OpenMAX color format to native color format
+ switch (eNativeColorFormat) {
+ // In case of SAMSUNG color format
+ case OMX_SEC_COLOR_FormatNV12TPhysicalAddress:
+ eNativeColorFormat = (OMX_COLOR_FORMATTYPE)HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED;
+ break;
+ case OMX_SEC_COLOR_FormatNV12Tiled:
+ eNativeColorFormat = (OMX_COLOR_FORMATTYPE)HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
+ break;
+ // In case of OpenMAX color formats
+ case OMX_COLOR_FormatYUV420SemiPlanar:
+ eNativeColorFormat = (OMX_COLOR_FORMATTYPE)HAL_PIXEL_FORMAT_YCbCr_420_SP;
+ break;
+ case OMX_COLOR_FormatYUV420Planar:
+ default:
+ eNativeColorFormat = (OMX_COLOR_FORMATTYPE)HAL_PIXEL_FORMAT_YCbCr_420_P;
+ break;
+ }
+}
+#endif // USE_SAMSUNG_COLORFORMAT
+
status_t OMXCodec::cancelBufferToNativeWindow(BufferInfo *info) {
CHECK_EQ((int)info->mStatus, (int)OWNED_BY_US);
CODEC_LOGV("Calling cancelBuffer on buffer %p", info->mBuffer);
@@ -3099,11 +3199,47 @@ bool OMXCodec::drainInputBuffer(BufferInfo *info) {
CHECK(info->mMediaBuffer == NULL);
info->mMediaBuffer = srcBuffer;
} else {
+#ifdef USE_SAMSUNG_COLORFORMAT
+ OMX_PARAM_PORTDEFINITIONTYPE def;
+ InitOMXParams(&def);
+ def.nPortIndex = kPortIndexInput;
+
+ status_t err = mOMX->getParameter(mNode, OMX_IndexParamPortDefinition,
+ &def, sizeof(def));
+ CHECK_EQ(err, (status_t)OK);
+
+ if (def.eDomain == OMX_PortDomainVideo) {
+ OMX_VIDEO_PORTDEFINITIONTYPE *videoDef = &def.format.video;
+ switch (videoDef->eColorFormat) {
+ case OMX_SEC_COLOR_FormatNV12LVirtualAddress: {
+ CHECK(srcBuffer->data() != NULL);
+ void *pSharedMem = (void *)(srcBuffer->data());
+ memcpy((uint8_t *)info->mData + offset,
+ (const void *)&pSharedMem, sizeof(void *));
+ break;
+ }
+ default:
+ CHECK(srcBuffer->data() != NULL);
+ memcpy((uint8_t *)info->mData + offset,
+ (const uint8_t *)srcBuffer->data()
+ + srcBuffer->range_offset(),
+ srcBuffer->range_length());
+ break;
+ }
+ } else {
+ CHECK(srcBuffer->data() != NULL);
+ memcpy((uint8_t *)info->mData + offset,
+ (const uint8_t *)srcBuffer->data()
+ + srcBuffer->range_offset(),
+ srcBuffer->range_length());
+ }
+#else
CHECK(srcBuffer->data() != NULL) ;
memcpy((uint8_t *)info->mData + offset,
(const uint8_t *)srcBuffer->data()
+ srcBuffer->range_offset(),
srcBuffer->range_length());
+#endif // USE_SAMSUNG_COLORFORMAT
}
int64_t lastBufferTimeUs;
@@ -4021,7 +4157,22 @@ static const char *colorFormatString(OMX_COLOR_FORMATTYPE type) {
if (type == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar) {
return "OMX_TI_COLOR_FormatYUV420PackedSemiPlanar";
- } else if (type == OMX_QCOM_COLOR_FormatYVU420SemiPlanar) {
+ }
+#ifdef USE_SAMSUNG_COLORFORMAT
+ if (type == OMX_SEC_COLOR_FormatNV12TPhysicalAddress) {
+ return "OMX_SEC_COLOR_FormatNV12TPhysicalAddress";
+ }
+ if (type == OMX_SEC_COLOR_FormatNV12LPhysicalAddress) {
+ return "OMX_SEC_COLOR_FormatNV12LPhysicalAddress";
+ }
+ if (type == OMX_SEC_COLOR_FormatNV12LVirtualAddress) {
+ return "OMX_SEC_COLOR_FormatNV12LVirtualAddress";
+ }
+ if (type == OMX_SEC_COLOR_FormatNV12Tiled) {
+ return "OMX_SEC_COLOR_FormatNV12Tiled";
+ }
+#endif // USE_SAMSUNG_COLORFORMAT
+ else if (type == OMX_QCOM_COLOR_FormatYVU420SemiPlanar) {
return "OMX_QCOM_COLOR_FormatYVU420SemiPlanar";
} else if (type < 0 || (size_t)type >= numNames) {
return "UNKNOWN";