Haoxiang Li | 35d2a70 | 2020-04-10 01:19:32 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 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/ISurroundView3dSession.h> |
| 22 | #include <hidl/MQDescriptor.h> |
| 23 | #include <hidl/Status.h> |
| 24 | |
| 25 | #include "CoreLibSetupHelper.h" |
| 26 | #include <thread> |
| 27 | |
| 28 | #include <ui/GraphicBuffer.h> |
| 29 | |
| 30 | using namespace ::android::hardware::automotive::sv::V1_0; |
| 31 | using ::android::hardware::Return; |
| 32 | using ::android::hardware::hidl_vec; |
| 33 | using ::android::sp; |
| 34 | |
| 35 | using namespace android_auto::surround_view; |
| 36 | |
| 37 | namespace android { |
| 38 | namespace hardware { |
| 39 | namespace automotive { |
| 40 | namespace sv { |
| 41 | namespace V1_0 { |
| 42 | namespace implementation { |
| 43 | |
| 44 | class SurroundView3dSession : public ISurroundView3dSession { |
| 45 | public: |
| 46 | SurroundView3dSession(); |
| 47 | |
| 48 | // Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewSession. |
| 49 | Return<SvResult> startStream( |
| 50 | const sp<ISurroundViewStream>& stream) override; |
| 51 | Return<void> stopStream() override; |
| 52 | Return<void> doneWithFrames(const SvFramesDesc& svFramesDesc) override; |
| 53 | |
| 54 | // Methods from ISurroundView3dSession follow. |
| 55 | Return<SvResult> setViews(const hidl_vec<View3d>& views) override; |
| 56 | Return<SvResult> set3dConfig(const Sv3dConfig& sv3dConfig) override; |
| 57 | Return<void> get3dConfig(get3dConfig_cb _hidl_cb) override; |
| 58 | Return<SvResult> updateOverlays(const OverlaysData& overlaysData); |
| 59 | Return<void> projectCameraPointsTo3dSurface( |
| 60 | const hidl_vec<Point2dInt>& cameraPoints, |
| 61 | const hidl_string& cameraId, |
| 62 | projectCameraPointsTo3dSurface_cb _hidl_cb); |
| 63 | |
| 64 | private: |
| 65 | void generateFrames(); |
| 66 | bool initialize(); |
| 67 | |
| 68 | enum StreamStateValues { |
| 69 | STOPPED, |
| 70 | RUNNING, |
| 71 | STOPPING, |
| 72 | DEAD, |
| 73 | }; |
| 74 | |
| 75 | // Stream subscribed for the session. |
| 76 | sp<ISurroundViewStream> mStream GUARDED_BY(mAccessLock); |
| 77 | StreamStateValues mStreamState GUARDED_BY(mAccessLock); |
| 78 | |
| 79 | thread mCaptureThread; // The thread we'll use to synthesize frames |
| 80 | |
| 81 | struct FramesRecord { |
| 82 | SvFramesDesc frames; |
| 83 | bool inUse = false; |
| 84 | }; |
| 85 | |
| 86 | FramesRecord framesRecord GUARDED_BY(mAccessLock); |
| 87 | |
| 88 | // Synchronization necessary to deconflict mCaptureThread from the main service thread |
| 89 | mutex mAccessLock; |
| 90 | |
| 91 | vector<View3d> mViews GUARDED_BY(mAccessLock); |
| 92 | |
| 93 | Sv3dConfig mConfig GUARDED_BY(mAccessLock); |
| 94 | |
| 95 | vector<string> mEvsCameraIds GUARDED_BY(mAccessLock); |
| 96 | |
| 97 | unique_ptr<SurroundView> mSurroundView GUARDED_BY(mAccessLock); |
| 98 | |
| 99 | vector<SurroundViewInputBufferPointers> |
| 100 | mInputPointers GUARDED_BY(mAccessLock); |
| 101 | SurroundViewResultPointer mOutputPointer GUARDED_BY(mAccessLock); |
| 102 | int mOutputWidth, mOutputHeight GUARDED_BY(mAccessLock); |
| 103 | |
| 104 | sp<GraphicBuffer> mSvTexture GUARDED_BY(mAccessLock); |
| 105 | |
| 106 | bool mIsInitialized GUARDED_BY(mAccessLock) = false; |
| 107 | }; |
| 108 | |
| 109 | } // namespace implementation |
| 110 | } // namespace V1_0 |
| 111 | } // namespace sv |
| 112 | } // namespace automotive |
| 113 | } // namespace hardware |
| 114 | } // namespace android |