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