diff --git a/media/jni/android_media_ImageWriter.cpp b/media/jni/android_media_ImageWriter.cpp index 9e81dda662f77..7a0eeee17b0d2 100644 --- a/media/jni/android_media_ImageWriter.cpp +++ b/media/jni/android_media_ImageWriter.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -401,8 +402,28 @@ static jlong ImageWriter_init(JNIEnv* env, jobject thiz, jobject weakThiz, jobje return 0; } } else { + // Set consumer buffer format to user specified format + PublicFormat publicFormat = static_cast(userFormat); + int nativeFormat = mapPublicFormatToHalFormat(publicFormat); + android_dataspace nativeDataspace = mapPublicFormatToHalDataspace(publicFormat); + res = native_window_set_buffers_format(anw.get(), nativeFormat); + if (res != OK) { + ALOGE("%s: Unable to configure consumer native buffer format to %#x", + __FUNCTION__, nativeFormat); + jniThrowRuntimeException(env, "Failed to set Surface format"); + return 0; + } + + res = native_window_set_buffers_data_space(anw.get(), nativeDataspace); + if (res != OK) { + ALOGE("%s: Unable to configure consumer dataspace %#x", + __FUNCTION__, nativeDataspace); + jniThrowRuntimeException(env, "Failed to set Surface dataspace"); + return 0; + } surfaceFormat = userFormat; } + ctx->setBufferFormat(surfaceFormat); env->SetIntField(thiz, gImageWriterClassInfo.mWriterFormat, reinterpret_cast(surfaceFormat));