Creating an ImageWriter into a SurfaceTexture with a format of choice

134 views
Skip to first unread message

micjan

unread,
Jun 19, 2018, 4:03:35 PM6/19/18
to android-platform
I'm trying to wrap an ImageWriter around a SurfaceTexture with a format set to the one I need.

mCreatedGPUSurface = new Surface(new SurfaceTexture(0));
setFormat(mCreatedGPUSurface, 640, 380, ImageFormat.YUV_420_888);
mImageWriter = ImageWriter.newInstance(mCreatedGPUSurface, 3);
Log.i("basicmediadecoder", "writer format: " + mImageWriter.getFormat());

setFormat is a native method in which I want to set the format of the Surface:

extern "C"
JNIEXPORT void JNICALL
Java_com_example_android_basicmediadecoder_MainActivity_setFormat(JNIEnv *env, jobject instance,
jobject surface, jint width,
jint height, jint format) {

ANativeWindow *window = NULL;
window = ANativeWindow_fromSurface(env, surface);

if (window != NULL) {
ANativeWindow_setBuffersGeometry(window, width, height, format);
int format = ANativeWindow_getFormat(window);
__android_log_print(ANDROID_LOG_INFO, "basicmediadecoder", "window format 0x%x",
format);
ANativeWindow_release(window);
} else {
__android_log_print(ANDROID_LOG_INFO, "basicmediadecoder", "error getting a window");
}

}

Looking in logcat, I'm getting the expected YUV format from the native function, but mImageWriter.getFormat() returns 1 (RGBA_8888) and not the expected YUV format:

06-18 11:48:22.420 16198-16198/com.example.android.basicmediadecoder I/basicmediadecoder: window format 0x23
    window format 0x23
06-18 11:48:22.421 16198-16198/com.example.android.basicmediadecoder I/basicmediadecoder: writer format: 1

Any clues? Is this not possible?


This message is intended for the use of only the person(s) ("intended recipient") to whom it is addressed. It may contain information that is privileged and confidential. Accordingly, any dissemination, distribution, copying or other use of this message or any of its content by any person other than the intended recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the intended recipient, please contact the sender as soon as possible.
Spectral Edge Ltd. Registered in England & Wales with Company Number 07538488. Registered address: Suite 7, Unit 16a Oakham Enterprise Park, Ashwell Road, Oakham, Rutland, LE15 7TU.
Reply all
Reply to author
Forward
0 new messages