1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 #include <android/hardware/camera/device/3.4/ICameraDeviceSession.h> 18 #include <android/hardware/graphics/mapper/2.0/IMapper.h> 19 #include <android/hardware/graphics/mapper/3.0/IMapper.h> 20 #include <android/hardware/graphics/mapper/4.0/IMapper.h> 21 #include "HandleImporter.h" 22 23 namespace android::hardware::camera::device::V3_4::implementation { 24 25 using ::android::hardware::camera::common::V1_0::helper::HandleImporter; 26 using ::android::hardware::camera::device::V3_2::StreamBuffer; 27 using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout; 28 29 // Small wrapper for allocating/freeing native handles 30 class ReleaseFence { 31 public: 32 ReleaseFence(int fence_fd); 33 ~ReleaseFence(); 34 handle()35 native_handle_t* handle() const { return handle_; } 36 37 private: 38 native_handle_t* handle_; 39 }; 40 41 // CachedStreamBuffer holds a buffer of camera3 stream. 42 class CachedStreamBuffer { 43 public: 44 CachedStreamBuffer(); 45 CachedStreamBuffer(const StreamBuffer& buffer); 46 // Not copyable 47 CachedStreamBuffer(const CachedStreamBuffer&) = delete; 48 CachedStreamBuffer& operator=(const CachedStreamBuffer&) = delete; 49 // ...but movable 50 CachedStreamBuffer(CachedStreamBuffer&& from) noexcept; 51 CachedStreamBuffer& operator=(CachedStreamBuffer&& from) noexcept; 52 53 ~CachedStreamBuffer(); 54 valid()55 bool valid() const { return buffer_ != nullptr; } bufferId()56 uint64_t bufferId() const { return buffer_id_; } streamId()57 int32_t streamId() const { return stream_id_; } acquireFence()58 int acquireFence() const { return acquire_fence_; } 59 60 void importFence(const native_handle_t* fence_handle); 61 // Acquire methods wait first on acquire fence and then return pointers to 62 // data. Data is nullptr if the wait timed out 63 YCbCrLayout acquireAsYUV(int32_t width, int32_t height, int timeout_ms); 64 void* acquireAsBlob(int32_t size, int timeout_ms); 65 int release(); 66 67 private: 68 buffer_handle_t buffer_; 69 uint64_t buffer_id_; 70 int32_t stream_id_; 71 int acquire_fence_; 72 }; 73 74 } // namespace android::hardware::camera::device::V3_4::implementation 75