• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "HandleImporter.h"
19 
20 namespace android::hardware::camera::device::V3_4::implementation {
21 
22 using ::android::hardware::camera::common::V1_0::helper::HandleImporter;
23 using ::android::hardware::camera::device::V3_2::StreamBuffer;
24 
25 // Small wrapper for allocating/freeing native handles
26 class ReleaseFence {
27  public:
28   ReleaseFence(int fence_fd);
29   ~ReleaseFence();
30 
handle()31   native_handle_t* handle() const { return handle_; }
32 
33  private:
34   native_handle_t* handle_;
35 };
36 
37 // CachedStreamBuffer holds a buffer of camera3 stream.
38 class CachedStreamBuffer {
39  public:
40   CachedStreamBuffer();
41   CachedStreamBuffer(const StreamBuffer& buffer);
42   // Not copyable
43   CachedStreamBuffer(const CachedStreamBuffer&) = delete;
44   CachedStreamBuffer& operator=(const CachedStreamBuffer&) = delete;
45   // ...but movable
46   CachedStreamBuffer(CachedStreamBuffer&& from) noexcept;
47   CachedStreamBuffer& operator=(CachedStreamBuffer&& from) noexcept;
48 
49   ~CachedStreamBuffer();
50 
valid()51   bool valid() const { return buffer_ != nullptr; }
bufferId()52   uint64_t bufferId() const { return buffer_id_; }
streamId()53   int32_t streamId() const { return stream_id_; }
acquireFence()54   int acquireFence() const { return acquire_fence_; }
55 
56   void importFence(const native_handle_t* fence_handle);
57   // Acquire methods wait first on acquire fence and then return pointers to
58   // data. Data is nullptr if the wait timed out
59   YCbCrLayout acquireAsYUV(int32_t width, int32_t height, int timeout_ms);
60   void* acquireAsBlob(int32_t size, int timeout_ms);
61   int release();
62 
63  private:
64   buffer_handle_t buffer_;
65   uint64_t buffer_id_;
66   int32_t stream_id_;
67   int acquire_fence_;
68 };
69 
70 }  // namespace android::hardware::camera::device::V3_4::implementation
71