aboutsummaryrefslogtreecommitdiffstats
path: root/evs
diff options
context:
space:
mode:
authorHaoxiang Li <haoxiangl@google.com>2019-08-30 15:27:22 -0700
committerHaoxiang Li <haoxiangl@google.com>2019-09-12 18:09:28 -0700
commit91178bc1306c454e97dfd28eaed8cd41243fcaae (patch)
treecc939c1fbb8ce55bc3a3d5c24f5ba3656c9b5f4f /evs
parentbf812e02e5735f82f45c6a148576ceccf354da47 (diff)
downloadplatform_packages_services_Car-91178bc1306c454e97dfd28eaed8cd41243fcaae.tar.gz
platform_packages_services_Car-91178bc1306c454e97dfd28eaed8cd41243fcaae.tar.bz2
platform_packages_services_Car-91178bc1306c454e97dfd28eaed8cd41243fcaae.zip
Add StreamHandlerManager class.
Add StreamHandlerManager class, so different use case can share the same StreamHandler for one camera. Test: build and run on Hawk device Bug: 130246434 Change-Id: I7ce1db4e3b6160be00219d957e462ae18fbf14bd
Diffstat (limited to 'evs')
-rw-r--r--evs/support_library/Android.bp1
-rw-r--r--evs/support_library/DisplayUseCase.h1
-rw-r--r--evs/support_library/StreamHandlerManager.cpp54
-rw-r--r--evs/support_library/StreamHandlerManager.h47
-rw-r--r--evs/support_library/VideoTex.cpp4
5 files changed, 105 insertions, 2 deletions
diff --git a/evs/support_library/Android.bp b/evs/support_library/Android.bp
index 388de2201..6de9595d3 100644
--- a/evs/support_library/Android.bp
+++ b/evs/support_library/Android.bp
@@ -28,6 +28,7 @@ cc_library_shared {
"TexWrapper.cpp",
"VideoTex.cpp",
"StreamHandler.cpp",
+ "StreamHandlerManager.cpp",
"FormatConvert.cpp",
"DisplayUseCase.cpp",
"Utils.cpp",
diff --git a/evs/support_library/DisplayUseCase.h b/evs/support_library/DisplayUseCase.h
index 4d6f12b9e..04e7539b3 100644
--- a/evs/support_library/DisplayUseCase.h
+++ b/evs/support_library/DisplayUseCase.h
@@ -27,7 +27,6 @@
#include "BaseUseCase.h"
#include "ConfigManager.h"
#include "RenderBase.h"
-#include "StreamHandler.h"
namespace android {
namespace automotive {
diff --git a/evs/support_library/StreamHandlerManager.cpp b/evs/support_library/StreamHandlerManager.cpp
new file mode 100644
index 000000000..135334c83
--- /dev/null
+++ b/evs/support_library/StreamHandlerManager.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "StreamHandlerManager.h"
+
+namespace android {
+namespace automotive {
+namespace evs {
+namespace support {
+
+sp<StreamHandlerManager> StreamHandlerManager::sInstance;
+
+sp<StreamHandlerManager> StreamHandlerManager::getInstance() {
+ if (sInstance == nullptr) {
+ ALOGD("Creating new StreamHandlerManager instance");
+ sInstance = new StreamHandlerManager();
+ }
+ return sInstance;
+}
+
+sp<StreamHandler> StreamHandlerManager::getStreamHandler(sp<IEvsCamera> pCamera) {
+ // Use camera Id as the key to the map
+ std::string cameraId;
+ pCamera.get()->getCameraInfo([&cameraId](CameraDesc desc) {
+ cameraId = desc.cameraId;
+ });
+
+ auto result = mStreamHandlers.find(cameraId);
+ if (result == mStreamHandlers.end()) {
+ sp<StreamHandler> handler = new StreamHandler(pCamera);
+ mStreamHandlers.emplace(cameraId, handler);
+ return handler;
+ } else {
+ return result->second;
+ }
+}
+
+} // namespace support
+} // namespace evs
+} // namespace automotive
+} // namespace android
diff --git a/evs/support_library/StreamHandlerManager.h b/evs/support_library/StreamHandlerManager.h
new file mode 100644
index 000000000..dddc10063
--- /dev/null
+++ b/evs/support_library/StreamHandlerManager.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CAR_LIB_EVS_SUPPORT_STREAMHANDLERMANAGER_H
+#define CAR_LIB_EVS_SUPPORT_STREAMHANDLERMANAGER_H
+
+#include <utils/RefBase.h>
+#include <unordered_map>
+#include "StreamHandler.h"
+
+namespace android {
+namespace automotive {
+namespace evs {
+namespace support {
+
+using ::android::sp;
+
+class StreamHandlerManager : public android::RefBase {
+public:
+ static sp<StreamHandlerManager> getInstance();
+ sp<StreamHandler> getStreamHandler(sp<IEvsCamera> pCamera);
+
+private:
+ static sp<StreamHandlerManager> sInstance;
+
+ std::unordered_map<std::string, sp<StreamHandler>> mStreamHandlers;
+};
+
+} // namespace support
+} // namespace evs
+} // namespace automotive
+} // namespace android
+
+#endif //CAR_LIB_EVS_SUPPORT_STREAMHANDLERMANAGER_H
diff --git a/evs/support_library/VideoTex.cpp b/evs/support_library/VideoTex.cpp
index 81bff24ed..9d2b019ea 100644
--- a/evs/support_library/VideoTex.cpp
+++ b/evs/support_library/VideoTex.cpp
@@ -24,6 +24,7 @@
#include "VideoTex.h"
#include "glError.h"
+#include "StreamHandlerManager.h"
#include <ui/GraphicBuffer.h>
#include <ui/GraphicBufferAllocator.h>
@@ -229,7 +230,8 @@ VideoTex* createVideoTexture(sp<IEvsEnumerator> pEnum,
}
// Initialize the stream that will help us update this texture's contents
- sp<StreamHandler> pStreamHandler = new StreamHandler(pCamera);
+ sp<StreamHandler> pStreamHandler =
+ StreamHandlerManager::getInstance()->getStreamHandler(pCamera);
if (pStreamHandler.get() == nullptr) {
ALOGE("failed to allocate FrameHandler");
return nullptr;