Merge "ExternalCameraHAL: dup fd when creating AIDL NativeHandle" into main am: dc543a304b

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/3011694

Change-Id: I6e3a394f5eb9b99b64feedf442c5e99bafb41ec3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2024-03-26 00:04:17 +00:00 committed by Automerger Merge Worker
commit f1b6d2b424
3 changed files with 24 additions and 22 deletions

View file

@ -789,8 +789,10 @@ Status ExternalCameraDeviceSession::switchToOffline(
outputBuffer.bufferId = buffer.bufferId;
outputBuffer.status = BufferStatus::ERROR;
if (buffer.acquireFence >= 0) {
outputBuffer.releaseFence.fds.resize(1);
outputBuffer.releaseFence.fds.at(0).set(buffer.acquireFence);
native_handle_t* handle = native_handle_create(/*numFds*/ 1, /*numInts*/ 0);
handle->data[0] = buffer.acquireFence;
outputBuffer.releaseFence = android::dupToAidl(handle);
native_handle_delete(handle);
}
} else {
offlineBuffers.push_back(buffer);
@ -1768,8 +1770,10 @@ Status ExternalCameraDeviceSession::processCaptureRequestError(
result.outputBuffers[i].bufferId = req->buffers[i].bufferId;
result.outputBuffers[i].status = BufferStatus::ERROR;
if (req->buffers[i].acquireFence >= 0) {
result.outputBuffers[i].releaseFence.fds.resize(1);
result.outputBuffers[i].releaseFence.fds.at(0).set(req->buffers[i].acquireFence);
native_handle_t* handle = native_handle_create(/*numFds*/ 1, /*numInts*/ 0);
handle->data[0] = req->buffers[i].acquireFence;
result.outputBuffers[i].releaseFence = android::dupToAidl(handle);
native_handle_delete(handle);
}
}
@ -1813,16 +1817,20 @@ Status ExternalCameraDeviceSession::processCaptureResult(std::shared_ptr<HalRequ
if (req->buffers[i].fenceTimeout) {
result.outputBuffers[i].status = BufferStatus::ERROR;
if (req->buffers[i].acquireFence >= 0) {
result.outputBuffers[i].releaseFence.fds.resize(1);
result.outputBuffers[i].releaseFence.fds.at(0).set(req->buffers[i].acquireFence);
native_handle_t* handle = native_handle_create(/*numFds*/ 1, /*numInts*/ 0);
handle->data[0] = req->buffers[i].acquireFence;
result.outputBuffers[i].releaseFence = android::dupToAidl(handle);
native_handle_delete(handle);
}
notifyError(req->frameNumber, req->buffers[i].streamId, ErrorCode::ERROR_BUFFER);
} else {
result.outputBuffers[i].status = BufferStatus::OK;
// TODO: refactor
if (req->buffers[i].acquireFence >= 0) {
result.outputBuffers[i].releaseFence.fds.resize(1);
result.outputBuffers[i].releaseFence.fds.at(0).set(req->buffers[i].acquireFence);
native_handle_t* handle = native_handle_create(/*numFds*/ 1, /*numInts*/ 0);
handle->data[0] = req->buffers[i].acquireFence;
result.outputBuffers[i].releaseFence = android::dupToAidl(handle);
native_handle_delete(handle);
}
}
}

View file

@ -110,7 +110,7 @@ Status ExternalCameraOfflineSession::processCaptureResult(std::shared_ptr<HalReq
if (req->buffers[i].acquireFence >= 0) {
native_handle_t* handle = native_handle_create(/*numFds*/ 1, /*numInts*/ 0);
handle->data[0] = req->buffers[i].acquireFence;
result.outputBuffers[i].releaseFence = android::makeToAidl(handle);
result.outputBuffers[i].releaseFence = android::dupToAidl(handle);
}
notifyError(req->frameNumber, req->buffers[i].streamId, ErrorCode::ERROR_BUFFER);
} else {
@ -119,7 +119,7 @@ Status ExternalCameraOfflineSession::processCaptureResult(std::shared_ptr<HalReq
if (req->buffers[i].acquireFence >= 0) {
native_handle_t* handle = native_handle_create(/*numFds*/ 1, /*numInts*/ 0);
handle->data[0] = req->buffers[i].acquireFence;
outputBuffer.releaseFence = android::makeToAidl(handle);
outputBuffer.releaseFence = android::dupToAidl(handle);
}
}
}
@ -247,7 +247,7 @@ Status ExternalCameraOfflineSession::processCaptureRequestError(
if (req->buffers[i].acquireFence >= 0) {
native_handle_t* handle = native_handle_create(/*numFds*/ 1, /*numInts*/ 0);
handle->data[0] = req->buffers[i].acquireFence;
outputBuffer.releaseFence = makeToAidl(handle);
outputBuffer.releaseFence = dupToAidl(handle);
}
}

View file

@ -750,18 +750,12 @@ Size getMaxThumbnailResolution(const common::V1_0::helper::CameraMetadata& chars
void freeReleaseFences(std::vector<CaptureResult>& results) {
for (auto& result : results) {
native_handle_t* inputReleaseFence =
::android::makeFromAidl(result.inputBuffer.releaseFence);
if (inputReleaseFence != nullptr) {
native_handle_close(inputReleaseFence);
native_handle_delete(inputReleaseFence);
}
// NativeHandles free fd's on desctruction. Simply delete the objects!
result.inputBuffer.releaseFence.fds.clear(); // Implicitly closes fds
result.inputBuffer.releaseFence.ints.clear();
for (auto& buf : result.outputBuffers) {
native_handle_t* outReleaseFence = ::android::makeFromAidl(buf.releaseFence);
if (outReleaseFence != nullptr) {
native_handle_close(outReleaseFence);
native_handle_delete(outReleaseFence);
}
buf.releaseFence.fds.clear(); // Implicitly closes fds
buf.releaseFence.ints.clear();
}
}
}