简体   繁体   English

Camera2和渲染脚本分配

[英]Camera2 and Renderscript Allocations

I'm trying to use an Allocation created with the USING_IO_INPUT flag to get images from the camera. 我正在尝试使用用USING_IO_INPUT标志创建的分配来从相机获取图像。 I'm setting it up as follows 我将其设置如下

Type.Builder yuvType = new Type.Builder(mRS, Element.YUV(mRS));
                yuvType.setYuvFormat(imageReaderFormat);
                yuvType.setX(mCameraWidth).setY(mCameraHeight);
mAllocation = Allocation.createTyped(mRS, yuvType.create(), Allocation
                        .MipmapControl.MIPMAP_NONE,
                        Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
mAllocation.setOnBufferAvailableListener(mOnBufferAllocationAvailable);

I'm adding the Allocation surface to a Preview Session, and getting the callbacks to my very simple function 我正在将“分配”表面添加到“预览会话”中,并将回调回调到我非常简单的函数中

public void onBufferAvailable(Allocation allocation) {
     allocation.ioReceive();
     //mPixels is properly initialised
     allocation.copyTo(mPixels);
}

This setup works on a Nexus 5X, but fails on a Nexus 4 running 5.1.1. 此设置适用于Nexus 5X,但不适用于运行5.1.1的Nexus 4。 When I call allocation.ioReceive() in the callback, I get a few warnings printed from the driver, and copying from the Allocation to a byte array results in garbage being copied. 当我在回调中调用allocation.ioReceive()时,我从驱动程序中收到了一些警告,并且从Allocation复制到字节数组会导致复制垃圾。

W/Adreno-RS: <rsdVendorAllocationUnMapQCOM:394>: NOT Found allocation map for alloc 0xa1761000
W/Adreno-GSL: <gsl_ldd_control:427>: ioctl fd 25 code 0xc01c0915 (IOCTL_KGSL_MAP_USER_MEM) failed: errno 22 Invalid argument
W/Adreno-RS: <rsdVendorAllocationMapQCOM:288>: gsl_memory_map_fd failed -5 hostptr: 0xa0112000 sz: 0 offset: 0 flags: 0x10c0b00 alloc: 0xa1761000

I am running the camera in a background thread, although onBufferAvailable gets called in the "RSMessageThread". 我运行在后台线程的摄像头,虽然onBufferAvailable在“RSMessageThread”被调用。

Is this problem related to the way I am setting the Allocations and the Camera Preview, or is it a bug in the driver? 此问题与我设置“分配”和“摄像机预览”的方式有关,还是驱动程序中的错误?

I see the same error message on a Samsung Galaxy S4 (Smart Phone), android version 5.0 (API 21), but do not with the identical application using camera2 and renderscript, on a Samsung Galaxy Tab 5 (Tablet), android version 5.1.1 (API 22). 我在Android版本5.0(API 21)的Samsung Galaxy S4(智能手机)上看到了相同的错误消息,但是在Android版本5.1的Samsung Galaxy Tab 5(Tablet)上,使用camera2和renderscript的应用程序却不相同。 1(API 22)。 I'm assuming it is an early implementation problem on the device vendors part. 我假设这是设备供应商方面的早期实施问题。

Have you tried the official HDR-viewfinder example ? 您是否尝试过HDR取景器的官方示例 If this works on the Nexus 4, then you can study that example. 如果此方法适用于Nexus 4,则可以研究该示例。

If not, you can try with my implementation YUV_420_888 to Bitmap that uses a different approach, not via YUV-allocations but via byte-allocation using the Information from the three image planes. 如果没有,您可以尝试使用不同的方法对位图执行YUV_420_888 ,而不是通过YUV分配,而是使用来自三个图像平面的信息通过字节分配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM