Camera: Fix processCaptureRequestBurstISO

android_convertGralloc1To0Usage() is used to convert gralloc1_usage(uint64_t) to gralloc_usage (int32_t),
then passed as a para in allocateGraphicBuffer(). But definition of allocateGraphicBuffer() is as
void CameraAidlTest::allocateGraphicBuffer(uint32_t width, uint32_t height, uint64_t usage, PixelFormat format, buffer_handle_t* buffer_handle).
The type of "usage" is uint64_t. So the convert (uint64_t -> int32_t -> uint64_t) will change usages(31 bit is 1)
such as 0x0000000080020b00 to 0xffffffff80020b00. It's unexpected.

Use ANDROID_NATIVE_UNSIGNED_CAST to fix the issue.

Bug: https://issuetracker.google.com/issues/330051542

Change-Id: I23dfd603be0da6864d1021a57c3c3ce76cb78bda
Signed-off-by: Fang Hui <hui.fang@nxp.com>
This commit is contained in:
Fang Hui
2024-03-19 19:23:36 +08:00
committed by Shuzhen Wang
parent bb35effe0d
commit f097c4d9bc
3 changed files with 27 additions and 24 deletions

View File

@@ -32,6 +32,7 @@
#include <torch_provider_cb.h>
#include <com_android_internal_camera_flags.h>
#include <list>
#include <nativebase/nativebase.h>
using ::aidl::android::hardware::camera::common::CameraDeviceStatus;
using ::aidl::android::hardware::camera::common::CameraResourceCost;
@@ -1622,9 +1623,9 @@ TEST_P(CameraAidlTest, processMultiCaptureRequestPreview) {
BufferStatus::OK, NativeHandle(), NativeHandle()};
} else {
allocateGraphicBuffer(previewStream.width, previewStream.height,
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStream.producerUsage),
static_cast<uint64_t>(halStream.consumerUsage)),
static_cast<uint64_t>(halStream.consumerUsage))),
halStream.overrideFormat, &buffer_handle);
graphicBuffers.push_back(buffer_handle);
outputBuffers[k] = {
@@ -1838,9 +1839,9 @@ TEST_P(CameraAidlTest, processUltraHighResolutionRequest) {
NativeHandle(), NativeHandle()};
} else {
allocateGraphicBuffer(previewStream.width, previewStream.height,
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStream.producerUsage),
static_cast<uint64_t>(halStream.consumerUsage)),
static_cast<uint64_t>(halStream.consumerUsage))),
halStream.overrideFormat, &buffer_handle);
graphicBuffers.push_back(buffer_handle);
outputBuffers[k] = {
@@ -2004,9 +2005,9 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) {
NativeHandle(), BufferStatus::OK,
NativeHandle(), NativeHandle()};
} else {
auto usage = android_convertGralloc1To0Usage(
auto usage = ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStream.producerUsage),
static_cast<uint64_t>(halStream.consumerUsage));
static_cast<uint64_t>(halStream.consumerUsage)));
allocateGraphicBuffer(previewStream.width, previewStream.height, usage,
halStream.overrideFormat, &buffer_handle);
@@ -2223,9 +2224,9 @@ TEST_P(CameraAidlTest, processCaptureRequestBurstISO) {
NativeHandle(), NativeHandle()};
} else {
allocateGraphicBuffer(previewStream.width, previewStream.height,
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStreams[0].producerUsage),
static_cast<uint64_t>(halStreams[0].consumerUsage)),
static_cast<uint64_t>(halStreams[0].consumerUsage))),
halStreams[0].overrideFormat, &buffers[i]);
outputBuffer = {halStreams[0].id, bufferId + i, ::android::makeToAidl(buffers[i]),
BufferStatus::OK, NativeHandle(), NativeHandle()};
@@ -2323,9 +2324,9 @@ TEST_P(CameraAidlTest, processCaptureRequestInvalidSinglePreview) {
bufferId = 0;
} else {
allocateGraphicBuffer(previewStream.width, previewStream.height,
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStreams[0].producerUsage),
static_cast<uint64_t>(halStreams[0].consumerUsage)),
static_cast<uint64_t>(halStreams[0].consumerUsage))),
halStreams[0].overrideFormat, &buffer_handle);
}
@@ -2446,9 +2447,9 @@ TEST_P(CameraAidlTest, switchToOffline) {
} else {
// jpeg buffer (w,h) = (blobLen, 1)
allocateGraphicBuffer(jpegBufferSize, /*height*/ 1,
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStream.producerUsage),
static_cast<uint64_t>(halStream.consumerUsage)),
static_cast<uint64_t>(halStream.consumerUsage))),
halStream.overrideFormat, &buffers[i]);
outputBuffer = {halStream.id, bufferId + i, ::android::makeToAidl(buffers[i]),
BufferStatus::OK, NativeHandle(), NativeHandle()};
@@ -2672,9 +2673,9 @@ TEST_P(CameraAidlTest, flushPreviewRequest) {
BufferStatus::OK, NativeHandle(), NativeHandle()};
} else {
allocateGraphicBuffer(previewStream.width, previewStream.height,
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStreams[0].producerUsage),
static_cast<uint64_t>(halStreams[0].consumerUsage)),
static_cast<uint64_t>(halStreams[0].consumerUsage))),
halStreams[0].overrideFormat, &buffer_handle);
outputBuffer = {halStreams[0].id, bufferId, ::android::makeToAidl(buffer_handle),
BufferStatus::OK, NativeHandle(), NativeHandle()};

View File

@@ -41,6 +41,7 @@
#include <regex>
#include <typeinfo>
#include "utils/Errors.h"
#include <nativebase/nativebase.h>
using ::aidl::android::hardware::camera::common::CameraDeviceStatus;
using ::aidl::android::hardware::camera::common::TorchModeStatus;
@@ -2263,8 +2264,8 @@ void CameraAidlTest::processCaptureRequestInternal(uint64_t bufferUsage,
/* We don't look at halStreamConfig.streams[0].consumerUsage
* since that is 0 for output streams
*/
android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStreams[0].producerUsage), bufferUsage),
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStreams[0].producerUsage), bufferUsage)),
halStreams[0].overrideFormat, &handle);
outputBuffer = {halStreams[0].id, bufferId, ::android::makeToAidl(handle),
@@ -2775,9 +2776,9 @@ void CameraAidlTest::processPreviewStabilizationCaptureRequestInternal(
/* We don't look at halStreamConfig.streams[0].consumerUsage
* since that is 0 for output streams
*/
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStreams[0].producerUsage),
GRALLOC1_CONSUMER_USAGE_HWCOMPOSER),
GRALLOC1_CONSUMER_USAGE_HWCOMPOSER)),
halStreams[0].overrideFormat, &buffer_handle);
outputBuffer = {halStreams[0].id, bufferId, ::android::makeToAidl(buffer_handle),
BufferStatus::OK, NativeHandle(), NativeHandle()};
@@ -3757,9 +3758,9 @@ void CameraAidlTest::processColorSpaceRequest(
NativeHandle(), BufferStatus::OK,
NativeHandle(), NativeHandle()};
} else {
auto usage = android_convertGralloc1To0Usage(
auto usage = ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStream.producerUsage),
static_cast<uint64_t>(halStream.consumerUsage));
static_cast<uint64_t>(halStream.consumerUsage)));
allocateGraphicBuffer(previewStream.width, previewStream.height, usage,
halStream.overrideFormat, &buffer_handle);
@@ -3913,9 +3914,9 @@ void CameraAidlTest::processZoomSettingsOverrideRequests(
NativeHandle(), NativeHandle()};
} else {
allocateGraphicBuffer(previewStream.width, previewStream.height,
android_convertGralloc1To0Usage(
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(
static_cast<uint64_t>(halStreams[0].producerUsage),
static_cast<uint64_t>(halStreams[0].consumerUsage)),
static_cast<uint64_t>(halStreams[0].consumerUsage))),
halStreams[0].overrideFormat, &buffers[i]);
outputBuffer = {halStreams[0].id, bufferId + i, ::android::makeToAidl(buffers[i]),
BufferStatus::OK, NativeHandle(), NativeHandle()};

View File

@@ -20,6 +20,7 @@
#include <aidlcommonsupport/NativeHandle.h>
#include <grallocusage/GrallocUsageConversion.h>
#include <cinttypes>
#include <nativebase/nativebase.h>
using ::aidl::android::hardware::camera::device::BufferStatus;
using ::aidl::android::hardware::camera::device::ErrorMsg;
@@ -143,8 +144,8 @@ ScopedAStatus DeviceCb::requestStreamBuffers(const std::vector<BufferRequest>& b
CameraAidlTest::allocateGraphicBuffer(
w, h,
android_convertGralloc1To0Usage(static_cast<uint64_t>(halStream.producerUsage),
static_cast<uint64_t>(halStream.consumerUsage)),
ANDROID_NATIVE_UNSIGNED_CAST(android_convertGralloc1To0Usage(static_cast<uint64_t>(halStream.producerUsage),
static_cast<uint64_t>(halStream.consumerUsage))),
halStream.overrideFormat, &handle);
StreamBuffer streamBuffer = StreamBuffer();