Scott Randolph | dcc3534 | 2017-01-19 13:33:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_0_HALCAMERA_H |
| 18 | #define ANDROID_AUTOMOTIVE_EVS_V1_0_HALCAMERA_H |
| 19 | |
Scott Randolph | f1b55e7 | 2017-03-01 20:35:44 -0800 | [diff] [blame] | 20 | #include <android/hardware/automotive/evs/1.0/types.h> |
| 21 | #include <android/hardware/automotive/evs/1.0/IEvsCamera.h> |
Scott Randolph | dcc3534 | 2017-01-19 13:33:42 -0800 | [diff] [blame] | 22 | #include <ui/GraphicBuffer.h> |
| 23 | |
| 24 | #include <thread> |
| 25 | #include <list> |
| 26 | |
Scott Randolph | f1b55e7 | 2017-03-01 20:35:44 -0800 | [diff] [blame] | 27 | using namespace ::android::hardware::automotive::evs::V1_0; |
Scott Randolph | dcc3534 | 2017-01-19 13:33:42 -0800 | [diff] [blame] | 28 | using ::android::hardware::Return; |
| 29 | using ::android::hardware::hidl_handle; |
| 30 | |
| 31 | namespace android { |
| 32 | namespace automotive { |
| 33 | namespace evs { |
| 34 | namespace V1_0 { |
| 35 | namespace implementation { |
| 36 | |
| 37 | |
| 38 | // From VirtualCamera.h |
| 39 | class VirtualCamera; |
| 40 | |
| 41 | |
| 42 | // This class wraps the actual hardware IEvsCamera objects. There is a one to many |
| 43 | // relationship between instances of this class and instances of the VirtualCamera class. |
| 44 | // This class implements the IEvsCameraStream interface so that it can receive the video |
| 45 | // stream from the hardware camera and distribute it to the associated VirtualCamera objects. |
| 46 | class HalCamera : public IEvsCameraStream { |
| 47 | public: |
| 48 | HalCamera(sp<IEvsCamera> hwCamera) : mHwCamera(hwCamera) {}; |
| 49 | |
| 50 | // Factory methods for client VirtualCameras |
| 51 | sp<VirtualCamera> makeVirtualCamera(); |
| 52 | void disownVirtualCamera(sp<VirtualCamera> virtualCamera); |
| 53 | |
| 54 | // Implementation details |
| 55 | sp<IEvsCamera> getHwCamera() { return mHwCamera; }; |
| 56 | unsigned getClientCount() { return mClients.size(); }; |
| 57 | bool changeFramesInFlight(int delta); |
| 58 | |
| 59 | Return<EvsResult> clientStreamStarting(); |
| 60 | void clientStreamEnding(); |
| 61 | Return<void> doneWithFrame(const BufferDesc& buffer); |
| 62 | |
Scott Randolph | f1b55e7 | 2017-03-01 20:35:44 -0800 | [diff] [blame] | 63 | // Methods from ::android::hardware::automotive::evs::V1_0::ICarCameraStream follow. |
Scott Randolph | dcc3534 | 2017-01-19 13:33:42 -0800 | [diff] [blame] | 64 | Return<void> deliverFrame(const BufferDesc& buffer) override; |
| 65 | |
| 66 | private: |
| 67 | sp<IEvsCamera> mHwCamera; |
Scott Randolph | 2980380 | 2017-01-25 13:11:51 -0800 | [diff] [blame] | 68 | std::list<wp<VirtualCamera>> mClients; // Weak pointers -> objects destruct if client dies |
Scott Randolph | dcc3534 | 2017-01-19 13:33:42 -0800 | [diff] [blame] | 69 | |
| 70 | enum { |
| 71 | STOPPED, |
| 72 | RUNNING, |
| 73 | STOPPING, |
| 74 | } mStreamState = STOPPED; |
| 75 | |
| 76 | struct FrameRecord { |
| 77 | uint32_t frameId; |
| 78 | uint32_t refCount; |
| 79 | FrameRecord(uint32_t id) : frameId(id), refCount(0) {}; |
| 80 | }; |
| 81 | std::vector<FrameRecord> mFrames; |
| 82 | }; |
| 83 | |
| 84 | } // namespace implementation |
| 85 | } // namespace V1_0 |
| 86 | } // namespace evs |
| 87 | } // namespace automotive |
| 88 | } // namespace android |
| 89 | |
| 90 | #endif // ANDROID_AUTOMOTIVE_EVS_V1_0_HALCAMERA_H |