blob: 8e6a683eec11b12a4d95c68b5285c98d3d6a2696 [file] [log] [blame]
Haoxiang Li830834b2020-03-05 15:54:34 -08001/*
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#define LOG_TAG "SurroundViewService"
17
18#include <android-base/logging.h>
19
20#include "CoreLibSetupHelper.h"
21#include "SurroundViewService.h"
22
23using namespace android_auto::surround_view;
24
25namespace android {
26namespace hardware {
27namespace automotive {
28namespace sv {
29namespace V1_0 {
30namespace implementation {
31
32std::mutex SurroundViewService::sLock;
33sp<SurroundViewService> SurroundViewService::sService;
34sp<SurroundView2dSession> SurroundViewService::sSurroundView2dSession;
35sp<SurroundView3dSession> SurroundViewService::sSurroundView3dSession;
36
37const std::string kCameraIds[] = {"0", "1", "2", "3"};
38
39sp<SurroundViewService> SurroundViewService::getInstance() {
40 std::scoped_lock<std::mutex> lock(sLock);
41 if (sService == nullptr) {
42 sService = new SurroundViewService();
43 }
44 return sService;
45}
46
47Return<void> SurroundViewService::getCameraIds(getCameraIds_cb _hidl_cb) {
48 hidl_vec<hidl_string> cameraIds = {kCameraIds[0], kCameraIds[1],
49 kCameraIds[2], kCameraIds[3]};
50 _hidl_cb(cameraIds);
51 return {};
52}
53
54Return<void> SurroundViewService::start2dSession(start2dSession_cb _hidl_cb) {
55 LOG(DEBUG) << __FUNCTION__;
56 std::scoped_lock<std::mutex> lock(sLock);
57
58 if (sSurroundView2dSession != nullptr) {
59 LOG(WARNING) << "Only one 2d session is supported at the same time";
60 _hidl_cb(nullptr, SvResult::INTERNAL_ERROR);
61 } else {
62 sSurroundView2dSession = new SurroundView2dSession();
63 _hidl_cb(sSurroundView2dSession, SvResult::OK);
64 }
65 return {};
66}
67
68Return<SvResult> SurroundViewService::stop2dSession(
69 const sp<ISurroundView2dSession>& sv2dSession) {
70 LOG(DEBUG) << __FUNCTION__;
71 std::scoped_lock<std::mutex> lock(sLock);
72
73 if (sv2dSession != nullptr && sv2dSession == sSurroundView2dSession) {
74 sSurroundView2dSession = nullptr;
75 return SvResult::OK;
76 } else {
77 LOG(ERROR) << __FUNCTION__ << ": Invalid argument";
78 return SvResult::INVALID_ARG;
79 }
80}
81
82Return<void> SurroundViewService::start3dSession(start3dSession_cb _hidl_cb) {
83 LOG(DEBUG) << __FUNCTION__;
84 std::scoped_lock<std::mutex> lock(sLock);
85
86 if (sSurroundView3dSession != nullptr) {
87 LOG(WARNING) << "Only one 3d session is supported at the same time";
88 _hidl_cb(nullptr, SvResult::INTERNAL_ERROR);
89 } else {
90 sSurroundView3dSession = new SurroundView3dSession();
91 _hidl_cb(sSurroundView3dSession, SvResult::OK);
92 }
93 return {};
94}
95
96Return<SvResult> SurroundViewService::stop3dSession(
97 const sp<ISurroundView3dSession>& sv3dSession) {
98 LOG(DEBUG) << __FUNCTION__;
99 std::scoped_lock<std::mutex> lock(sLock);
100
101 if (sv3dSession != nullptr && sv3dSession == sSurroundView3dSession) {
102 sSurroundView3dSession = nullptr;
103 return SvResult::OK;
104 } else {
105 LOG(ERROR) << __FUNCTION__ << ": Invalid argument";
106 return SvResult::INVALID_ARG;
107 }
108}
109
110} // namespace implementation
111} // namespace V1_0
112} // namespace sv
113} // namespace automotive
114} // namespace hardware
115} // namespace android
116