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 20 #include <android/hardware/automotive/evs/1.0/types.h> 21 #include <android/hardware/automotive/evs/1.0/IEvsCamera.h> 22 #include <ui/GraphicBuffer.h> 23 24 #include <thread> 25 #include <list> 26 27 28 using namespace ::android::hardware::automotive::evs::V1_0; 29 using ::android::hardware::Return; 30 using ::android::hardware::hidl_handle; 31 32 namespace android { 33 namespace automotive { 34 namespace evs { 35 namespace V1_0 { 36 namespace implementation { 37 38 39 class VirtualCamera; // From VirtualCamera.h 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: HalCamera(sp<IEvsCamera> hwCamera)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 getHwCamera()55 sp<IEvsCamera> getHwCamera() { return mHwCamera; }; getClientCount()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 63 // Methods from ::android::hardware::automotive::evs::V1_0::ICarCameraStream follow. 64 Return<void> deliverFrame(const BufferDesc& buffer) override; 65 66 private: 67 sp<IEvsCamera> mHwCamera; 68 std::list<wp<VirtualCamera>> mClients; // Weak pointers -> objects destruct if client dies 69 70 enum { 71 STOPPED, 72 RUNNING, 73 STOPPING, 74 } mStreamState = STOPPED; 75 76 struct FrameRecord { 77 uint32_t frameId; 78 uint32_t refCount; FrameRecordFrameRecord79 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 91