summaryrefslogtreecommitdiff
path: root/media/jni/android_media_ImageReader.cpp
diff options
context:
space:
mode:
authorZhijun He <zhijunhe@google.com>2017-03-22 17:33:47 -0700
committerZhijun He <zhijunhe@google.com>2017-04-10 23:38:32 +0000
commit916d8ac650865cd05808d48bad68b69bebbc95ab (patch)
treef2eb0ef8b023735d10889f02b6764d054765aa1a /media/jni/android_media_ImageReader.cpp
parent04088837b5972930c1afc56b63d5217362eb13b0 (diff)
ImageReader/Writer: add usage flag support
Also add an ImageWriter ctor to take additional arugment (format) Test: ImageReader and Writer CTS tests Bug: 32766711 Change-Id: I99e3862dd5b9a85c9df7879c14c84b68a35718ec
Diffstat (limited to 'media/jni/android_media_ImageReader.cpp')
-rw-r--r--media/jni/android_media_ImageReader.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp
index f5e19f908d71..163c4b012262 100644
--- a/media/jni/android_media_ImageReader.cpp
+++ b/media/jni/android_media_ImageReader.cpp
@@ -31,6 +31,8 @@
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/android_view_Surface.h>
+#include <android_runtime/android_hardware_HardwareBuffer.h>
+#include <grallocusage/GrallocUsageConversion.h>
#include <jni.h>
#include <JNIHelp.h>
@@ -42,6 +44,7 @@
#define ANDROID_MEDIA_SURFACEIMAGE_BUFFER_JNI_ID "mNativeBuffer"
#define ANDROID_MEDIA_SURFACEIMAGE_TS_JNI_ID "mTimestamp"
+#define CONSUMER_BUFFER_USAGE_UNKNOWN 0;
// ----------------------------------------------------------------------------
using namespace android;
@@ -327,8 +330,8 @@ static void ImageReader_classInit(JNIEnv* env, jclass clazz)
"Can not find SurfacePlane constructor");
}
-static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz,
- jint width, jint height, jint format, jint maxImages)
+static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz, jint width, jint height,
+ jint format, jint maxImages, jlong ndkUsage)
{
status_t res;
int nativeFormat;
@@ -358,17 +361,29 @@ static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz,
width, height, format, maxImages, getpid(),
createProcessUniqueId());
uint32_t consumerUsage = GRALLOC_USAGE_SW_READ_OFTEN;
+ bool needUsageOverride = ndkUsage != CONSUMER_BUFFER_USAGE_UNKNOWN;
+ uint64_t outProducerUsage = 0;
+ uint64_t outConsumerUsage = 0;
+ android_hardware_HardwareBuffer_convertToGrallocUsageBits(&outProducerUsage, &outConsumerUsage,
+ ndkUsage, 0);
if (isFormatOpaque(nativeFormat)) {
// Use the SW_READ_NEVER usage to tell producer that this format is not for preview or video
// encoding. The only possibility will be ZSL output.
consumerUsage = GRALLOC_USAGE_SW_READ_NEVER;
+ if (needUsageOverride) {
+ consumerUsage = android_convertGralloc1To0Usage(0, outConsumerUsage);
+ }
+ } else if (needUsageOverride) {
+ ALOGW("Consumer usage override for non-opaque format is not implemented yet, "
+ "ignore the provided usage from the application");
}
bufferConsumer = new BufferItemConsumer(gbConsumer, consumerUsage, maxImages,
/*controlledByApp*/true);
if (bufferConsumer == nullptr) {
jniThrowExceptionFmt(env, "java/lang/RuntimeException",
- "Failed to allocate native buffer consumer for format 0x%x", nativeFormat);
+ "Failed to allocate native buffer consumer for format 0x%x and usage 0x%x",
+ nativeFormat, consumerUsage);
return;
}
ctx->setBufferConsumer(bufferConsumer);
@@ -788,7 +803,7 @@ static jint Image_getFormat(JNIEnv* env, jobject thiz, jint readerFormat)
static const JNINativeMethod gImageReaderMethods[] = {
{"nativeClassInit", "()V", (void*)ImageReader_classInit },
- {"nativeInit", "(Ljava/lang/Object;IIII)V", (void*)ImageReader_init },
+ {"nativeInit", "(Ljava/lang/Object;IIIIJ)V", (void*)ImageReader_init },
{"nativeClose", "()V", (void*)ImageReader_close },
{"nativeReleaseImage", "(Landroid/media/Image;)V", (void*)ImageReader_imageRelease },
{"nativeImageSetup", "(Landroid/media/Image;)I", (void*)ImageReader_imageSetup },