1 /* 2 * Copyright (C) 2020 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 #pragma once 18 19 #include <android/hardware/automotive/sv/1.0/types.h> 20 #include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h> 21 #include <android/hardware/automotive/sv/1.0/ISurroundView2dSession.h> 22 #include <hidl/MQDescriptor.h> 23 #include <hidl/Status.h> 24 25 #include <thread> 26 27 using namespace ::android::hardware::automotive::sv::V1_0; 28 using ::android::hardware::Return; 29 using ::android::hardware::Void; 30 using ::android::hardware::hidl_vec; 31 using ::android::sp; 32 using ::std::mutex; 33 34 namespace android { 35 namespace hardware { 36 namespace automotive { 37 namespace sv { 38 namespace V1_0 { 39 namespace implementation { 40 41 class SurroundView2dSession : public ISurroundView2dSession { 42 public: 43 SurroundView2dSession(); 44 45 // Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewSession. 46 Return<SvResult> startStream( 47 const sp<ISurroundViewStream>& stream) override; 48 Return<void> stopStream() override; 49 Return<void> doneWithFrames(const SvFramesDesc& svFramesDesc) override; 50 51 // Methods from ISurroundView2dSession follow. 52 Return<void> get2dMappingInfo(get2dMappingInfo_cb _hidl_cb) override; 53 Return<SvResult> set2dConfig(const Sv2dConfig& sv2dConfig) override; 54 Return<void> get2dConfig(get2dConfig_cb _hidl_cb) override; 55 Return<void> projectCameraPoints( 56 const hidl_vec<Point2dInt>& points2dCamera, 57 const hidl_string& cameraId, 58 projectCameraPoints_cb _hidl_cb) override; 59 60 // TODO(tanmayp): Make private and add set/get method. 61 // Stream subscribed for the session. 62 sp<ISurroundViewStream> mStream; 63 64 private: 65 void generateFrames(); 66 67 enum StreamStateValues { 68 STOPPED, 69 RUNNING, 70 STOPPING, 71 DEAD, 72 }; 73 StreamStateValues mStreamState; 74 75 Sv2dConfig mConfig; 76 77 std::thread mCaptureThread; // The thread we'll use to synthesize frames 78 79 struct FramesRecord { 80 SvFramesDesc frames; 81 bool inUse = false; 82 }; 83 84 FramesRecord framesRecord; 85 86 // Synchronization necessary to deconflict mCaptureThread from the main service thread 87 std::mutex mAccessLock; 88 89 std::vector<std::string> mEvsCameraIds; 90 }; 91 92 } // namespace implementation 93 } // namespace V1_0 94 } // namespace sv 95 } // namespace automotive 96 } // namespace hardware 97 } // namespace android 98 99