Changyeon Jo | c7deb56 | 2019-07-23 10:40:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
| 17 | #ifndef ANDROID_AUTOMOTIVE_EVS_V1_1_HALCAMERA_H |
| 18 | #define ANDROID_AUTOMOTIVE_EVS_V1_1_HALCAMERA_H |
| 19 | |
| 20 | #include <android/hardware/automotive/evs/1.1/types.h> |
| 21 | #include <android/hardware/automotive/evs/1.1/IEvsCamera.h> |
| 22 | #include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h> |
| 23 | #include <ui/GraphicBuffer.h> |
| 24 | |
| 25 | #include <thread> |
| 26 | #include <list> |
| 27 | |
| 28 | |
| 29 | using namespace ::android::hardware::automotive::evs::V1_1; |
| 30 | using ::android::hardware::Return; |
| 31 | using ::android::hardware::hidl_handle; |
| 32 | using ::android::hardware::automotive::evs::V1_0::EvsResult; |
| 33 | using IEvsCamera_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCamera; |
| 34 | using IEvsCamera_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCamera; |
| 35 | using BufferDesc_1_0 = ::android::hardware::automotive::evs::V1_0::BufferDesc; |
| 36 | using BufferDesc_1_1 = ::android::hardware::automotive::evs::V1_1::BufferDesc; |
| 37 | using IEvsCameraStream_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCameraStream; |
| 38 | using IEvsCameraStream_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCameraStream; |
| 39 | |
| 40 | namespace android { |
| 41 | namespace automotive { |
| 42 | namespace evs { |
| 43 | namespace V1_1 { |
| 44 | namespace implementation { |
| 45 | |
| 46 | |
| 47 | class VirtualCamera; // From VirtualCamera.h |
| 48 | |
| 49 | |
| 50 | // This class wraps the actual hardware IEvsCamera objects. There is a one to many |
| 51 | // relationship between instances of this class and instances of the VirtualCamera class. |
| 52 | // This class implements the IEvsCameraStream interface so that it can receive the video |
| 53 | // stream from the hardware camera and distribute it to the associated VirtualCamera objects. |
| 54 | class HalCamera : public IEvsCameraStream_1_1 { |
| 55 | public: |
| 56 | HalCamera(sp<IEvsCamera_1_1> hwCamera) : mHwCamera(hwCamera) {}; |
| 57 | |
| 58 | // Factory methods for client VirtualCameras |
| 59 | sp<VirtualCamera> makeVirtualCamera(); |
| 60 | void disownVirtualCamera(sp<VirtualCamera> virtualCamera); |
| 61 | |
| 62 | // Implementation details |
| 63 | sp<IEvsCamera_1_0> getHwCamera() { return mHwCamera; }; |
| 64 | unsigned getClientCount() { return mClients.size(); }; |
| 65 | bool changeFramesInFlight(int delta); |
| 66 | |
| 67 | Return<EvsResult> clientStreamStarting(); |
| 68 | void clientStreamEnding(); |
| 69 | Return<void> doneWithFrame(const BufferDesc_1_0& buffer); |
| 70 | Return<void> doneWithFrame(const BufferDesc_1_1& buffer); |
Changyeon Jo | 330d1c2 | 2019-07-30 11:58:41 -0700 | [diff] [blame^] | 71 | Return<EvsResult> setMaster(sp<VirtualCamera> virtualCamera); |
| 72 | Return<EvsResult> unsetMaster(sp<VirtualCamera> virtualCamera); |
| 73 | Return<EvsResult> setParameter(sp<VirtualCamera> virtualCamera, |
| 74 | CameraParam id, int32_t& value); |
| 75 | Return<EvsResult> getParameter(CameraParam id, int32_t& value); |
Changyeon Jo | c7deb56 | 2019-07-23 10:40:04 -0700 | [diff] [blame] | 76 | |
| 77 | // Methods from ::android::hardware::automotive::evs::V1_1::IEvsCameraStream follow. |
| 78 | Return<void> deliverFrame(const BufferDesc_1_0& buffer) override; |
| 79 | Return<void> notifyEvent(const EvsEvent& event) override; |
| 80 | |
| 81 | private: |
| 82 | sp<IEvsCamera_1_1> mHwCamera; |
| 83 | std::list<wp<VirtualCamera>> mClients; // Weak pointers -> objects destruct if client dies |
| 84 | |
| 85 | enum { |
| 86 | STOPPED, |
| 87 | RUNNING, |
| 88 | STOPPING, |
| 89 | } mStreamState = STOPPED; |
| 90 | |
| 91 | struct FrameRecord { |
| 92 | uint32_t frameId; |
| 93 | uint32_t refCount; |
| 94 | FrameRecord(uint32_t id) : frameId(id), refCount(0) {}; |
| 95 | }; |
| 96 | std::vector<FrameRecord> mFrames; |
Changyeon Jo | 330d1c2 | 2019-07-30 11:58:41 -0700 | [diff] [blame^] | 97 | wp<VirtualCamera> mMaster = nullptr; |
Changyeon Jo | c7deb56 | 2019-07-23 10:40:04 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace implementation |
| 101 | } // namespace V1_1 |
| 102 | } // namespace evs |
| 103 | } // namespace automotive |
| 104 | } // namespace android |
| 105 | |
| 106 | #endif // ANDROID_AUTOMOTIVE_EVS_V1_1_HALCAMERA_H |