summaryrefslogtreecommitdiff
path: root/camera/device/3.4/default/CameraDeviceSession.cpp
diff options
context:
space:
mode:
authorYin-Chia Yeh <yinchiayeh@google.com>2018-08-03 11:50:47 -0700
committerYin-Chia Yeh <yinchiayeh@google.com>2018-08-03 12:38:30 -0700
commit7d1fdecea5bfa16ab7af3b0b98db1973c1775abd (patch)
tree820d83783f33f41986593f8cf3fda8917fe0048b /camera/device/3.4/default/CameraDeviceSession.cpp
parent72c7579c080a092fcab92c087a9fe7fe3ecd106e (diff)
Legacy camera shim: add option to free buffers earlier
This option allows HAL to opt in for the behavior that will free cached buffers earlier if the libhardware HAL implementation doesn't cache/reference the cached buffers internally. Test: buffers are freed earlier when the property is set Bug: 111850884 Change-Id: I3a10b288c7160c86dc7d3a30d04b5c4903917731
Diffstat (limited to 'camera/device/3.4/default/CameraDeviceSession.cpp')
-rw-r--r--camera/device/3.4/default/CameraDeviceSession.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/camera/device/3.4/default/CameraDeviceSession.cpp b/camera/device/3.4/default/CameraDeviceSession.cpp
index 6a18161f20..f2e031c674 100644
--- a/camera/device/3.4/default/CameraDeviceSession.cpp
+++ b/camera/device/3.4/default/CameraDeviceSession.cpp
@@ -154,6 +154,8 @@ Return<void> CameraDeviceSession::configureStreams_3_4(
// the corresponding resources of the deleted streams.
if (ret == OK) {
postProcessConfigurationLocked_3_4(requestedConfiguration);
+ } else {
+ postProcessConfigurationFailureLocked_3_4(requestedConfiguration);
}
if (ret == -EINVAL) {
@@ -215,6 +217,23 @@ bool CameraDeviceSession::preProcessConfigurationLocked_3_4(
(*streams)[i] = &mStreamMap[id];
}
+ if (mFreeBufEarly) {
+ // Remove buffers of deleted streams
+ for(auto it = mStreamMap.begin(); it != mStreamMap.end(); it++) {
+ int id = it->first;
+ bool found = false;
+ for (const auto& stream : requestedConfiguration.streams) {
+ if (id == stream.v3_2.id) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ // Unmap all buffers of deleted stream
+ cleanupBuffersLocked(id);
+ }
+ }
+ }
return true;
}
@@ -236,7 +255,9 @@ void CameraDeviceSession::postProcessConfigurationLocked_3_4(
// Unmap all buffers of deleted stream
// in case the configuration call succeeds and HAL
// is able to release the corresponding resources too.
- cleanupBuffersLocked(id);
+ if (!mFreeBufEarly) {
+ cleanupBuffersLocked(id);
+ }
it = mStreamMap.erase(it);
} else {
++it;
@@ -255,6 +276,26 @@ void CameraDeviceSession::postProcessConfigurationLocked_3_4(
mResultBatcher_3_4.setBatchedStreams(mVideoStreamIds);
}
+void CameraDeviceSession::postProcessConfigurationFailureLocked_3_4(
+ const StreamConfiguration& requestedConfiguration) {
+ if (mFreeBufEarly) {
+ // Re-build the buf cache entry for deleted streams
+ for(auto it = mStreamMap.begin(); it != mStreamMap.end(); it++) {
+ int id = it->first;
+ bool found = false;
+ for (const auto& stream : requestedConfiguration.streams) {
+ if (id == stream.v3_2.id) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ mCirculatingBuffers.emplace(id, CirculatingBuffers{});
+ }
+ }
+ }
+}
+
Return<void> CameraDeviceSession::processCaptureRequest_3_4(
const hidl_vec<V3_4::CaptureRequest>& requests,
const hidl_vec<V3_2::BufferCache>& cachesToRemove,