@@ -1281,30 +1281,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
return 0;
}
-static CompressedImage mapAndroidBlobBuffer(const buffer_handle_t camera3buffer)
-{
- CompressedImage img;
-
- /* ANDROID_JPEG_MAX_SIZE */
- unsigned int length = int32_t{13 << 20};
-
- /* Take only the first plane */
- void *memory = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED,
- camera3buffer->data[0], 0);
-
- img.length = length;
- img.data = static_cast<unsigned char*>(memory);
-
- return img;
-}
-
-static void unmapAndroidBlobBuffer(CompressedImage *img)
-{
- munmap(img->data, img->length);
- img->data = nullptr;
- img->length = 0;
-}
-
void CameraDevice::requestComplete(Request *request)
{
const std::map<Stream *, FrameBuffer *> &buffers = request->buffers();
@@ -1341,19 +1317,22 @@ void CameraDevice::requestComplete(Request *request)
continue;
}
- CompressedImage output = mapAndroidBlobBuffer(*descriptor->buffers[i].buffer);
- if (output.data == MAP_FAILED) {
- LOG(HAL, Error) << "Failed to mmap android blob buffer of length " << output.length;
+ MappedCamera3Buffer mapped(*descriptor->buffers[i].buffer, PROT_READ|PROT_WRITE);
+ if (!mapped.isValid()) {
+ LOG(HAL, Error) << "Failed to mmap android blob buffer";
continue;
}
+ CompressedImage output;
+ output.data = static_cast<unsigned char *>(mapped.maps()[0].address);
+ output.length = mapped.maps()[0].length;
+
int ret = compressor->compress(buffer, &output);
if (ret) {
LOG(HAL, Error) << "Failed to compress stream image";
status = CAMERA3_BUFFER_STATUS_ERROR;
}
- unmapAndroidBlobBuffer(&output);
}
/* Prepare to call back the Android camera stack. */
Utilise the MappedBuffer interface to map each of the planes provided in the Camera3 buffer to facilitate use in software streams. The buffers will be automatically unmapped when the object goes out of scope or is deleted. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> --- This shows how the MappedCamera3Buffer which was posted as part of the MappedBuffer series can get used. Originally my aim was to pass a MappedBuffer in place of creating a CompressedImage object, but passing in a MappedBuffer alone restricts passing back how many bytes were consumed, and I expect other meta-data might be needed, so I anticipate needing more than just a function return value soon. (i.e. so I don't yet think I can just return the compressed image size in the return value, but maybe it might end up being possible/cleaner to do that...) src/android/camera_device.cpp | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-)