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/ISurroundView2dSession.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 SurroundView2dSession : public ISurroundView2dSession { |
| 45 | public: |
| 46 | SurroundView2dSession(); |
| 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 ISurroundView2dSession follow. |
| 55 | Return<void> get2dMappingInfo(get2dMappingInfo_cb _hidl_cb) override; |
| 56 | Return<SvResult> set2dConfig(const Sv2dConfig& sv2dConfig) override; |
| 57 | Return<void> get2dConfig(get2dConfig_cb _hidl_cb) override; |
| 58 | Return<void> projectCameraPoints( |
| 59 | const hidl_vec<Point2dInt>& points2dCamera, |
| 60 | const hidl_string& cameraId, |
| 61 | projectCameraPoints_cb _hidl_cb) override; |
| 62 | |
| 63 | private: |
| 64 | void generateFrames(); |
| 65 | bool initialize(); |
| 66 | |
| 67 | enum StreamStateValues { |
| 68 | STOPPED, |
| 69 | RUNNING, |
| 70 | STOPPING, |
| 71 | DEAD, |
| 72 | }; |
| 73 | StreamStateValues mStreamState GUARDED_BY(mAccessLock); |
| 74 | |
| 75 | // Stream subscribed for the session. |
| 76 | sp<ISurroundViewStream> mStream GUARDED_BY(mAccessLock); |
| 77 | |
| 78 | Sv2dConfig mConfig GUARDED_BY(mAccessLock); |
| 79 | int mHeight GUARDED_BY(mAccessLock); |
| 80 | Sv2dMappingInfo mInfo GUARDED_BY(mAccessLock); |
| 81 | |
| 82 | thread mCaptureThread GUARDED_BY(mAccessLock); |
| 83 | |
| 84 | struct FramesRecord { |
| 85 | SvFramesDesc frames; |
| 86 | bool inUse = false; |
| 87 | }; |
| 88 | |
| 89 | FramesRecord framesRecord GUARDED_BY(mAccessLock); |
| 90 | |
| 91 | // Synchronization necessary to deconflict mCaptureThread from the main |
| 92 | // service thread |
| 93 | mutex 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 |
| 115 | |