Commit Graph

14 Commits

Author SHA1 Message Date
Tang Lee
ba1854fb0e ExternalCameraHAL: fix CTS failures with callback for errors
For every request, either requestStreamBuffers fails or
handling of the requested buffer fails, always trigger
the processCaptureResult callback by notifying the request
is ready. This avoids the errors like the service side
receives fewer results than the requests and waits until
timeout.

Bug: 299182874
Test: cts
cts-tradefed run cts \
  --include-filter  "CtsCameraTestCases android.hardware.camera2.cts.RobustnessTest" \
  --include-filter "CtsCameraTestCases android.hardware.camera2.cts.PerformanceTest" \
  --include-filter "CtsCameraTestCases android.hardware.camera2.cts.StillCaptureTest" \
  --include-filter "CtsCameraTestCases android.hardware.camera2.cts.SurfaceViewPreviewTest" \
  --include-filter "CtsCameraTestCases android.hardware.cts.CameraGLTest" \
  --include-filter "CtsCameraTestCases android.hardware.cts.LegacyCameraPerformanceTest" \

Change-Id: I86ba422524e79af6b318b50bd6eebe2cb27fa50a
2024-02-01 00:36:22 +00:00
Tang Lee
ef97150dc9 ExternalCameraHAL: improve buffer and error handling
After enabling HALL Buffer Management, it requires more careful
error handling and syncing. Process the buffer request error correctly.
Handle the lock and states correctly.

Bug: 299182874
Test: CTS passed, expecially
./cts-tradefed run cts -m CtsCameraTestCases -t android.hardware.camera2.cts.NativeCameraDeviceTest
./cts-tradefed run cts -m CtsCameraTestCases -t android.hardware.camera2.cts.RobustnessTest

Change-Id: I04d8e19a2ee78580e54340378122c724a3de8edb
2024-01-30 04:07:35 +00:00
Avichal Rakesh
43549d934e ExternalCameraHAL: Skip importing buffer from capture request
ExternalCameraHAL supports HAL buffer management which means
cameraservice will not send it an output buffer along with the
capture request, and the HAL has the freedom to request an
output buffer when an output buffer is needed.

As a remnant of migration from HIDL to AIDL, the
ExternalCameraHAL still attempted to import buffers that
the cameraservice has sent with the CaptureRequest. However,
with HAL buffer manager enabled, this buffer is always null and
results in the HAL failing to process the capture request.

This CL removes the logic for importing output buffers when
processing capture requests from the cameraservice, and lets
the HAL call requestStreamBuffers when it needs an output buffer.

Bug: 299182874
Test: VTS Tests now pass
Change-Id: I00654836b7ae91a91a2afa4b149712977e07dcc5
2024-01-29 15:08:19 -08:00
Avichal Rakesh
ce54ff9989 ExternalCameraHAL: Prevent memory leak when manipulating native_handle
native_handle objects created by makeFromAidl need to be deleted
with native_handle_delete. Not doing so leads to a memory leak
every time makeFromAidl is called.

This CL ensures that native_handle_delete is called on the
return value of makeFromAidl wherever it is used.

Bug: 305638723
Test: n/a. No functional change.
Change-Id: Ia99ba6e3abbdf7dec75383450a60c944b92a9c74
2024-01-12 17:34:59 -08:00
Avichal Rakesh
31437d0f3c ExternalCameraHAL: dup fd when creating AIDL NativeHandle
AIDL's NativeHandle do not have a concept of unowned file
descriptors. If a NativeHandle object is created with an
fd, NativeHandle implicitly assumes ownership of the fd.
When passing fds over binder, ExternalCameraHAL used
makeToAidl which which accidentally transferred ownership
to the AIDL objects. Additionally, NativeHandles close
owned fds on destruction, which led to multiple closure
of fences.

This CL changes the logic to use dupToAidl to ensure that
NativeHandle objects are given ownership of a duped fds
and don't interfere with any of the fds used for internal
bookkeeping.

Bug: 313115623
Test: Verified by partner that ExternalCameraHAL no longer
      double closes fds.
Change-Id: Ic406634de6f22a290abb414e80a7747927368b68
2024-01-12 17:34:51 -08:00
Avichal Rakesh
56d9580dcf Merge "ExternalCameraHAL: Fix memory leak when copying buffer fence" into main am: 634ecd5da0 am: aba897e523 am: a11d57f607
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2817883

Change-Id: I168257bac3466f67fdb90da573402c0775a20f28
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-15 23:47:47 +00:00
Avichal Rakesh
1fa4142e1a ExternalCameraHAL: Fix memory leak when copying buffer fence
Pointer to native_handle_t created using native_handle_create should
be cleaned up using native_handle_delete even if the fds in the
native_handle is no longer managed by it. ExternalCameraDeviceSession
creates native_handle_t as an intermediate to convert to AIDL
NativeHandle but doesn't call native_handle_delete on the
intermediate object which led to memory leaks.

This CL removes the intermediate object and copies the fence fd
directly.

Bug: 305638723
Test: No functional change. Compilation successful.
Change-Id: Ie3c558ee1ae6d2e84053b65eed7db179118395bb
2023-11-03 16:16:57 -07:00
Devin Moore
523660cd87 Revert "Revert "Convert from HIDL mapper to libui GraphicBufferM..."
Revert submission 24913374-revert-24747509-camera_fail2-OVHUVTAXRP

Reason for revert: 32-bit TV build is fixed with `%zu` instead of `%lu` for size_t argument.

Reverted changes: /q/submissionid:24913374-revert-24747509-camera_fail2-OVHUVTAXRP

Change-Id: I16287ce2dbea034db41450a3a5e9c3f729e76335
2023-10-02 15:55:11 +00:00
Michael Stokes
49ba82ce11 Revert "Convert from HIDL mapper to libui GraphicBufferMapper"
Revert submission 24747509-camera_fail2

Reason for revert: DroidMonitor-triggered revert due to breakage
b/302990858.

This may cause CtsAppOpsTestCases b/300115646 to fail again,
unfortunately (b/300115646).

Bug: 302990858
Reverted changes: /q/submissionid:24747509-camera_fail2

Change-Id: I0191b3ee88846f5b2c6e37ebd6be6d1369d9dba9
2023-10-02 09:56:59 +00:00
Devin Moore
5e154097aa Convert from HIDL mapper to libui GraphicBufferMapper
HIDL mapper HAL is deprecated and instead of adding more support for the
new replacement explicitly, we can move the GraphicBufferMapper which
handles all of the backwards compatbility with the HIDL HALs for us.

Test: atest CtsCameraTestCases CtsAppOpsTestCases
Bug: 285605852
Bug: 300115646

Change-Id: Ib97e429a0f3dd1c66ec008fbf3860c9c5667bddd
2023-09-19 21:56:38 +00:00
Tang Lee
65382f6a50 Fix external camera HAL crashes
External USB camera hal service crashes when disconnecting the camera.
ExternalCameraDeviceSession's desctructor is called and deletes mLock,
but mBufferRequestThread is still running and waiting on the same
mLock, which causes the "pthread_mutex_lock called on a destroyed
mutex" error.

Fix the issue by stopping the thread in destructor. Also refactors the
functions and remove unused conditions.

Bug: 289741662
Test: Test with USB camera
Change-Id: I06b1ff6e192a4bca16822785d65d68a6aae53414
2023-08-01 10:32:46 +00:00
Avichal Rakesh
740c256079 Clean up external HAL reference implementation.
This CL cleans up the reference external HAL implementation.
Specifically, it makes the following changes:

  - Removes mSupportBufMgr from ExternalCameraDeviceSession as it never
    needed to be used.
  - Makes ExternalCameraOfflineSession final to prevent other classes
    from accidentally inheriting from it. ExternalCameraOfflineSession
    calls the virtual function `close()` on destruction which depends on
    the implementation details of other virtual functions.

Bug: 219974678
Test: Builds successfully
Change-Id: I645f8164cd2426219943d9407f0c282c468c90d3
2023-01-05 01:51:01 -08:00
Greg Kaiser
9b77fd1272 Fix NULL check
We were checking 'info' twice and not checking 'msgs'.  So we
fix that up, and fix a typo in the message.

Bug: 219974678
Test: TreeHugger
Change-Id: Ia52178b758dc3d9753731b043da01743ff59e10c
2022-12-05 17:06:02 -08:00
Avichal Rakesh
e1857f8dbd Migrate reference external HAL implementation to AIDL
Android T migrated the HAL interface to AIDL, but the reference HAL
was never updated to use AIDL. This CL migrates the reference
HAL implementation for external cameras to use AIDL as well. The
external HAL uses V4L2 standard to expose USB cameras to the
cameraserver.

The reference HAL implementation for internal camera was dropped
because it is not possible to write a generic HAL that works with some
large percentage of internal cameras.

Bug: 219974678
Test: Existing CTS tests pass with external camera connected.
Change-Id: I35f3dc32c16670eca7735a4ac00fed3daf36aa65
2022-12-01 05:09:18 -08:00