RESTRICT AUTOMERGE Remove Surround View Ref. Impl.
Remove the Surround View Ref. Impl and App under /services/Car
Ref. Impl. and App to be provided through a partner branch.
Bug: 192249648
Test: Verified build.
Change-Id: I683d4a29ab0f449e4974ec68c3f17c4b46f52fe7
diff --git a/cpp/surround_view/OWNERS b/cpp/surround_view/OWNERS
deleted file mode 100644
index 2c5c8a7..0000000
--- a/cpp/surround_view/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
-haoxiangl@google.com
-tanmayp@google.com
-swan@google.com
diff --git a/cpp/surround_view/app/Android.bp b/cpp/surround_view/app/Android.bp
deleted file mode 100644
index 76753d3..0000000
--- a/cpp/surround_view/app/Android.bp
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2020 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.
-//
-//
-
-//#################################
-package {
- default_applicable_licenses: ["Android-Apache-2.0"],
-}
-
-cc_binary {
- name: "sv_app",
-
- srcs: [
- "SurroundViewAppCommon.cpp",
- "SurroundViewServiceCallback.cpp",
- "shader.cpp",
- "sv_app.cpp",
- ],
-
- shared_libs: [
- "android.hardware.automotive.evs@1.1",
- "android.hardware.automotive.sv@1.0",
- "libEGL",
- "libGLESv2",
- "libbase",
- "libbinder",
- "libcutils",
- "libhardware",
- "libhidlbase",
- "libutils",
- "libui",
- ],
-
- static_libs: [
- "libjsoncpp",
- "libmath",
- ],
-
- strip: {
- keep_symbols: true,
- },
-
- init_rc: ["sv_app.rc"],
-
- cflags: [
- "-DLOG_TAG=\"SvApp\"",
- "-DGL_GLEXT_PROTOTYPES",
- "-DEGL_EGLEXT_PROTOTYPES",
- "-Wall",
- "-Werror",
- "-Wunused",
- "-Wunreachable-code",
- ],
-}
diff --git a/cpp/surround_view/app/SurroundViewAppCommon.cpp b/cpp/surround_view/app/SurroundViewAppCommon.cpp
deleted file mode 100644
index b1a2792..0000000
--- a/cpp/surround_view/app/SurroundViewAppCommon.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright 2020 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 "SurroundViewAppCommon.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace app {
-
-bool run2dSurroundView(sp<ISurroundViewService> pSurroundViewService, sp<IEvsDisplay> pDisplay) {
- LOG(INFO) << "Run 2d Surround View demo";
-
- // Call HIDL API "start2dSession"
- sp<ISurroundView2dSession> surroundView2dSession;
-
- SvResult svResult;
- pSurroundViewService->start2dSession(
- [&surroundView2dSession, &svResult](const sp<ISurroundView2dSession>& session,
- SvResult result) {
- surroundView2dSession = session;
- svResult = result;
- });
-
- if (surroundView2dSession == nullptr || svResult != SvResult::OK) {
- LOG(ERROR) << "Failed to start2dSession";
- return false;
- } else {
- LOG(INFO) << "start2dSession succeeded";
- }
-
- sp<SurroundViewServiceCallback> sv2dCallback =
- new SurroundViewServiceCallback(pDisplay, surroundView2dSession);
-
- // Start 2d stream with callback with default quality and resolution.
- // The quality is defaulted to be HIGH_QUALITY, and the default resolution
- // is set in the sv config file.
- if (surroundView2dSession->startStream(sv2dCallback) != SvResult::OK) {
- LOG(ERROR) << "Failed to start 2d stream";
- return false;
- }
-
- const int kTotalViewingTimeSecs = 10;
-
- // Let the SV algorithm run for HIGH_QUALITY until the wait time finishes
- std::this_thread::sleep_for(std::chrono::seconds(kTotalViewingTimeSecs));
-
- // Switch to low quality and lower resolution
- Sv2dConfig config = {.width = kLowResolutionWidth, .blending = SvQuality::LOW};
- if (surroundView2dSession->set2dConfig(config) != SvResult::OK) {
- LOG(ERROR) << "Failed to set2dConfig";
- return false;
- }
-
- // Let the SV algorithm run for LOW_QUALITY until the wait time finishes
- std::this_thread::sleep_for(std::chrono::seconds(kTotalViewingTimeSecs));
-
- // TODO(b/150412555): wait for the last frame
- // Stop the 2d stream and session
- surroundView2dSession->stopStream();
-
- pSurroundViewService->stop2dSession(surroundView2dSession);
- surroundView2dSession = nullptr;
-
- LOG(INFO) << "SV 2D session finished.";
-
- return true;
-};
-
-// Given a valid sv 3d session and pose, viewid and hfov parameters, sets the view.
-bool setView(sp<ISurroundView3dSession> surroundView3dSession, uint32_t viewId, uint32_t poseIndex,
- float hfov) {
- const View3d view3d = {
- .viewId = viewId,
- .pose =
- {
- .rotation = {.x = kPoseRot[poseIndex][0],
- .y = kPoseRot[poseIndex][1],
- .z = kPoseRot[poseIndex][2],
- .w = kPoseRot[poseIndex][3]},
- .translation = {.x = kPoseTrans[poseIndex][0],
- .y = kPoseTrans[poseIndex][1],
- .z = kPoseTrans[poseIndex][2]},
- },
- .horizontalFov = hfov,
- };
-
- const std::vector<View3d> views = {view3d};
- if (surroundView3dSession->setViews(views) != SvResult::OK) {
- return false;
- }
- return true;
-}
-
-bool run3dSurroundView(sp<ISurroundViewService> pSurroundViewService, sp<IEvsDisplay> pDisplay) {
- LOG(INFO) << "Run 3d Surround View demo";
-
- // Call HIDL API "start3dSession"
- sp<ISurroundView3dSession> surroundView3dSession;
-
- SvResult svResult;
- pSurroundViewService->start3dSession(
- [&surroundView3dSession, &svResult](const sp<ISurroundView3dSession>& session,
- SvResult result) {
- surroundView3dSession = session;
- svResult = result;
- });
-
- if (surroundView3dSession == nullptr || svResult != SvResult::OK) {
- LOG(ERROR) << "Failed to start3dSession";
- return false;
- } else {
- LOG(INFO) << "start3dSession succeeded";
- }
-
- sp<SurroundViewServiceCallback> sv3dCallback =
- new SurroundViewServiceCallback(pDisplay, surroundView3dSession);
-
- // A view must be set before the 3d stream is started.
- if (!setView(surroundView3dSession, /*viewId=*/0, /*poseIndex=*/0, kHorizontalFov)) {
- LOG(ERROR) << "Failed to setView of pose index :" << 0;
- return false;
- }
-
- // Start 3d stream with callback with default quality and resolution.
- // The quality is defaulted to be HIGH_QUALITY, and the default resolution
- // is set in the sv config file.
- if (surroundView3dSession->startStream(sv3dCallback) != SvResult::OK) {
- LOG(ERROR) << "Failed to start 3d stream";
- return false;
- }
-
- // Let the SV algorithm run for 10 seconds for HIGH_QUALITY
- const int kTotalViewingTimeSecs = 10;
- const std::chrono::milliseconds perPoseSleepTimeMs(kTotalViewingTimeSecs * 1000 / kPoseCount);
- // Iterate through the pre-set views.
- for (uint32_t i = 0; i < kPoseCount; i++) {
- if (!setView(surroundView3dSession, /*viewId=*/i, /*poseIndex=*/i, kHorizontalFov)) {
- LOG(WARNING) << "Failed to setView of pose index :" << i;
- }
- std::this_thread::sleep_for(perPoseSleepTimeMs);
- }
-
- // Switch to low quality and lower resolution
- Sv3dConfig config = {.width = kLowResolutionWidth,
- .height = kLowResolutionHeight,
- .carDetails = SvQuality::LOW};
-
- if (surroundView3dSession->set3dConfig(config) != SvResult::OK) {
- LOG(ERROR) << "Failed to set3dConfig";
- return false;
- }
-
- // Let the SV algorithm run for 10 seconds for LOW_QUALITY
- for (uint32_t i = 0; i < kPoseCount; i++) {
- if (!setView(surroundView3dSession, i + kPoseCount, i, kHorizontalFov)) {
- LOG(WARNING) << "Failed to setView of pose index :" << i;
- }
- std::this_thread::sleep_for(perPoseSleepTimeMs);
- }
-
- // TODO(b/150412555): wait for the last frame
- // Stop the 3d stream and session
- surroundView3dSession->stopStream();
-
- pSurroundViewService->stop3dSession(surroundView3dSession);
- surroundView3dSession = nullptr;
-
- LOG(DEBUG) << "SV 3D session finished.";
-
- return true;
-};
-} // namespace app
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/app/SurroundViewAppCommon.h b/cpp/surround_view/app/SurroundViewAppCommon.h
deleted file mode 100644
index 04e59fa..0000000
--- a/cpp/surround_view/app/SurroundViewAppCommon.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-#pragma once
-
-#include "SurroundViewServiceCallback.h"
-
-#include <android-base/logging.h>
-#include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundView2dSession.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundView3dSession.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewService.h>
-#include <hidl/HidlTransportSupport.h>
-#include <utils/Log.h>
-#include <utils/StrongPointer.h>
-
-#include <stdio.h>
-
-#include <thread>
-
-using namespace android::hardware::automotive::sv::V1_0;
-using namespace android::hardware::automotive::evs::V1_1;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace app {
-
-const int kLowResolutionWidth = 120;
-const int kLowResolutionHeight = 90;
-
-enum DemoMode {
- UNKNOWN,
- DEMO_2D,
- DEMO_3D,
-};
-
-const float kHorizontalFov = 90;
-
-// Number of views to generate.
-const uint32_t kPoseCount = 16;
-
-// Set of pose rotations expressed in quaternions.
-// Views are generated about a circle at a height about the car, point towards the center.
-const float kPoseRot[kPoseCount][4] = {{-0.251292, -0.251292, -0.660948, 0.660948},
- {0.197439, 0.295488, 0.777193, -0.519304},
- {0.135998, 0.328329, 0.86357, -0.357702},
- {0.0693313, 0.348552, 0.916761, -0.182355},
- {-7.76709e-09, 0.355381, 0.934722, 2.0429e-08},
- {-0.0693313, 0.348552, 0.916761, 0.182355},
- {-0.135998, 0.328329, 0.86357, 0.357702},
- {-0.197439, 0.295488, 0.777193, 0.519304},
- {-0.251292, 0.251292, 0.660948, 0.660948},
- {-0.295488, 0.197439, 0.519304, 0.777193},
- {-0.328329, 0.135998, 0.357702, 0.86357},
- {-0.348552, 0.0693313, 0.182355, 0.916761},
- {-0.355381, -2.11894e-09, -5.57322e-09, 0.934722},
- {-0.348552, -0.0693313, -0.182355, 0.916761},
- {-0.328329, -0.135998, -0.357702, 0.86357},
- {-0.295488, -0.197439, -0.519304, 0.777193}};
-
-// Set of pose translations i.e. positions of the views.
-// Views are generated about a circle at a height about the car, point towards the center.
-const float kPoseTrans[kPoseCount][4] = {{4, 0, 2.5},
- {3.69552, 1.53073, 2.5},
- {2.82843, 2.82843, 2.5},
- {1.53073, 3.69552, 2.5},
- {-1.74846e-07, 4, 2.5},
- {-1.53073, 3.69552, 2.5},
- {-2.82843, 2.82843, 2.5},
- {-3.69552, 1.53073, 2.5},
- {-4, -3.49691e-07, 2.5},
- {-3.69552, -1.53073, 2.5},
- {-2.82843, -2.82843, 2.5},
- {-1.53073, -3.69552, 2.5},
- {4.76995e-08, -4, 2.5},
- {1.53073, -3.69552, 2.5},
- {2.82843, -2.82843, 2.5},
- {3.69552, -1.53073, 2.5}};
-
-bool run2dSurroundView(sp<ISurroundViewService> pSurroundViewService, sp<IEvsDisplay> pDisplay);
-
-bool run3dSurroundView(sp<ISurroundViewService> pSurroundViewService, sp<IEvsDisplay> pDisplay);
-
-// Given a valid sv 3d session and pose, viewid and hfov parameters, sets the view.
-bool setView(sp<ISurroundView3dSession> surroundView3dSession, uint32_t viewId, uint32_t poseIndex,
- float hfov);
-
-} // namespace app
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/app/SurroundViewServiceCallback.cpp b/cpp/surround_view/app/SurroundViewServiceCallback.cpp
deleted file mode 100644
index a3ce519..0000000
--- a/cpp/surround_view/app/SurroundViewServiceCallback.cpp
+++ /dev/null
@@ -1,557 +0,0 @@
-/*
- * Copyright 2020 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 "SurroundViewServiceCallback.h"
-
-#include <android-base/logging.h>
-#include <math/mat4.h>
-#include <ui/GraphicBuffer.h>
-#include <utils/Log.h>
-
-#include "shader_simpleTex.h"
-#include "shader.h"
-
-using android::GraphicBuffer;
-using android::hardware::automotive::evs::V1_0::DisplayState;
-using android::hardware::automotive::evs::V1_0::EvsResult;
-using android::hardware::Return;
-using android::sp;
-using std::string;
-
-EGLDisplay SurroundViewServiceCallback::sGLDisplay;
-GLuint SurroundViewServiceCallback::sFrameBuffer;
-GLuint SurroundViewServiceCallback::sColorBuffer;
-GLuint SurroundViewServiceCallback::sDepthBuffer;
-GLuint SurroundViewServiceCallback::sTextureId;
-EGLImageKHR SurroundViewServiceCallback::sKHRimage;
-
-const char* SurroundViewServiceCallback::getEGLError(void) {
- switch (eglGetError()) {
- case EGL_SUCCESS:
- return "EGL_SUCCESS";
- case EGL_NOT_INITIALIZED:
- return "EGL_NOT_INITIALIZED";
- case EGL_BAD_ACCESS:
- return "EGL_BAD_ACCESS";
- case EGL_BAD_ALLOC:
- return "EGL_BAD_ALLOC";
- case EGL_BAD_ATTRIBUTE:
- return "EGL_BAD_ATTRIBUTE";
- case EGL_BAD_CONTEXT:
- return "EGL_BAD_CONTEXT";
- case EGL_BAD_CONFIG:
- return "EGL_BAD_CONFIG";
- case EGL_BAD_CURRENT_SURFACE:
- return "EGL_BAD_CURRENT_SURFACE";
- case EGL_BAD_DISPLAY:
- return "EGL_BAD_DISPLAY";
- case EGL_BAD_SURFACE:
- return "EGL_BAD_SURFACE";
- case EGL_BAD_MATCH:
- return "EGL_BAD_MATCH";
- case EGL_BAD_PARAMETER:
- return "EGL_BAD_PARAMETER";
- case EGL_BAD_NATIVE_PIXMAP:
- return "EGL_BAD_NATIVE_PIXMAP";
- case EGL_BAD_NATIVE_WINDOW:
- return "EGL_BAD_NATIVE_WINDOW";
- case EGL_CONTEXT_LOST:
- return "EGL_CONTEXT_LOST";
- default:
- return "Unknown error";
- }
-}
-
-const string SurroundViewServiceCallback::getGLFramebufferError(void) {
- switch (glCheckFramebufferStatus(GL_FRAMEBUFFER)) {
- case GL_FRAMEBUFFER_COMPLETE:
- return "GL_FRAMEBUFFER_COMPLETE";
- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
- return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
- return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
- case GL_FRAMEBUFFER_UNSUPPORTED:
- return "GL_FRAMEBUFFER_UNSUPPORTED";
- case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
- return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
- default:
- return std::to_string(glCheckFramebufferStatus(GL_FRAMEBUFFER));
- }
-}
-
-bool SurroundViewServiceCallback::prepareGL() {
- LOG(DEBUG) << __FUNCTION__;
-
- // Just trivially return success if we're already prepared
- if (sGLDisplay != EGL_NO_DISPLAY) {
- return true;
- }
-
- // Hardcoded to RGBx output display
- const EGLint config_attribs[] = {
- // Tag Value
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_NONE
- };
-
- // Select OpenGL ES v 3
- const EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
-
- // Set up our OpenGL ES context associated with the default display
- // (though we won't be visible)
- EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- if (display == EGL_NO_DISPLAY) {
- LOG(ERROR) << "Failed to get egl display";
- return false;
- }
-
- EGLint major = 0;
- EGLint minor = 0;
- if (!eglInitialize(display, &major, &minor)) {
- LOG(ERROR) << "Failed to initialize EGL: "
- << getEGLError();
- return false;
- } else {
- LOG(INFO) << "Initialized EGL at "
- << major
- << "."
- << minor;
- }
-
- // Select the configuration that "best" matches our desired characteristics
- EGLConfig egl_config;
- EGLint num_configs;
- if (!eglChooseConfig(display, config_attribs, &egl_config, 1,
- &num_configs)) {
- LOG(ERROR) << "eglChooseConfig() failed with error: "
- << getEGLError();
- return false;
- }
-
- // Create a placeholder pbuffer so we have a surface to bind -- we never intend
- // to draw to this because attachRenderTarget will be called first.
- EGLint surface_attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
- EGLSurface sPlaceholderSurface = eglCreatePbufferSurface(display, egl_config, surface_attribs);
- if (sPlaceholderSurface == EGL_NO_SURFACE) {
- LOG(ERROR) << "Failed to create OpenGL ES Placeholder surface: " << getEGLError();
- return false;
- } else {
- LOG(INFO) << "Placeholder surface looks good! :)";
- }
-
- //
- // Create the EGL context
- //
- EGLContext context = eglCreateContext(display, egl_config,
- EGL_NO_CONTEXT, context_attribs);
- if (context == EGL_NO_CONTEXT) {
- LOG(ERROR) << "Failed to create OpenGL ES Context: "
- << getEGLError();
- return false;
- }
-
- // Activate our render target for drawing
- if (!eglMakeCurrent(display, sPlaceholderSurface, sPlaceholderSurface, context)) {
- LOG(ERROR) << "Failed to make the OpenGL ES Context current: "
- << getEGLError();
- return false;
- } else {
- LOG(INFO) << "We made our context current! :)";
- }
-
- // Report the extensions available on this implementation
- const char* gl_extensions = (const char*) glGetString(GL_EXTENSIONS);
- LOG(INFO) << "GL EXTENSIONS:\n "
- << gl_extensions;
-
- // Reserve handles for the color and depth targets we'll be setting up
- glGenRenderbuffers(1, &sColorBuffer);
- glGenRenderbuffers(1, &sDepthBuffer);
-
- // Set up the frame buffer object we can modify and use for off screen
- // rendering
- glGenFramebuffers(1, &sFrameBuffer);
- glBindFramebuffer(GL_FRAMEBUFFER, sFrameBuffer);
-
- LOG(INFO) << "FrameBuffer is bound to "
- << sFrameBuffer;
-
- // New (from TextWrapper)
- glGenTextures(1, &sTextureId);
-
- // Now that we're assured success, store object handles we constructed
- sGLDisplay = display;
-
- GLuint mShaderProgram = 0;
- // Load our shader program if we don't have it already
- if (!mShaderProgram) {
- mShaderProgram = buildShaderProgram(kVtxShaderSimpleTexture,
- kPixShaderSimpleTexture,
- "simpleTexture");
- if (!mShaderProgram) {
- LOG(ERROR) << "Error building shader program";
- return false;
- }
- }
-
- // Select our screen space simple texture shader
- glUseProgram(mShaderProgram);
-
- // Set up the model to clip space transform (identity matrix if we're
- // modeling in screen space)
- GLint loc = glGetUniformLocation(mShaderProgram, "cameraMat");
- if (loc < 0) {
- LOG(ERROR) << "Couldn't set shader parameter 'cameraMat'";
- } else {
- const android::mat4 identityMatrix;
- glUniformMatrix4fv(loc, 1, false, identityMatrix.asArray());
- }
-
- GLint sampler = glGetUniformLocation(mShaderProgram, "tex");
- if (sampler < 0) {
- LOG(ERROR) << "Couldn't set shader parameter 'tex'";
- } else {
- // Tell the sampler we looked up from the shader to use texture slot 0
- // as its source
- glUniform1i(sampler, 0);
- }
-
- return true;
-}
-
-BufferDesc SurroundViewServiceCallback::convertBufferDesc(
- const BufferDesc_1_0& src) {
- BufferDesc dst = {};
- AHardwareBuffer_Desc* pDesc =
- reinterpret_cast<AHardwareBuffer_Desc *>(&dst.buffer.description);
- pDesc->width = src.width;
- pDesc->height = src.height;
- pDesc->layers = 1;
- pDesc->format = src.format;
- pDesc->usage = static_cast<uint64_t>(src.usage);
- pDesc->stride = src.stride;
-
- dst.buffer.nativeHandle = src.memHandle;
- dst.pixelSize = src.pixelSize;
- dst.bufferId = src.bufferId;
-
- return dst;
-}
-
-bool SurroundViewServiceCallback::attachRenderTarget(
- const BufferDesc& tgtBuffer) {
- const AHardwareBuffer_Desc* pDesc =
- reinterpret_cast<const AHardwareBuffer_Desc *>(
- &tgtBuffer.buffer.description);
- // Hardcoded to RGBx for now
- if (pDesc->format != HAL_PIXEL_FORMAT_RGBA_8888) {
- LOG(ERROR) << "Unsupported target buffer format";
- return false;
- }
-
- // create a GraphicBuffer from the existing handle
- sp<GraphicBuffer> pGfxBuffer =
- new GraphicBuffer(tgtBuffer.buffer.nativeHandle,
- GraphicBuffer::CLONE_HANDLE,
- pDesc->width,
- pDesc->height,
- pDesc->format,
- pDesc->layers,
- GRALLOC_USAGE_HW_RENDER,
- pDesc->stride);
- if (pGfxBuffer == nullptr) {
- LOG(ERROR) << "Failed to allocate GraphicBuffer to wrap image handle";
- return false;
- }
-
- // Get a GL compatible reference to the graphics buffer we've been given
- EGLint eglImageAttributes[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
- EGLClientBuffer clientBuf = static_cast<EGLClientBuffer>(
- pGfxBuffer->getNativeBuffer());
-
- // Destroy current KHR image due to new request.
- if (sKHRimage != EGL_NO_IMAGE_KHR) {
- eglDestroyImageKHR(sGLDisplay, sKHRimage);
- }
-
- sKHRimage = eglCreateImageKHR(sGLDisplay, EGL_NO_CONTEXT,
- EGL_NATIVE_BUFFER_ANDROID, clientBuf,
- eglImageAttributes);
- if (sKHRimage == EGL_NO_IMAGE_KHR) {
- LOG(ERROR) << "error creating EGLImage for target buffer: "
- << getEGLError();
- return false;
- }
-
- glBindFramebuffer(GL_FRAMEBUFFER, sFrameBuffer);
-
- // Construct a render buffer around the external buffer
- glBindRenderbuffer(GL_RENDERBUFFER, sColorBuffer);
- glEGLImageTargetRenderbufferStorageOES(
- GL_RENDERBUFFER, static_cast<GLeglImageOES>(sKHRimage));
- if (eglGetError() != EGL_SUCCESS) {
- LOG(INFO) << "glEGLImageTargetRenderbufferStorageOES => %s"
- << getEGLError();
- return false;
- }
-
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_RENDERBUFFER, sColorBuffer);
- if (eglGetError() != EGL_SUCCESS) {
- LOG(ERROR) << "glFramebufferRenderbuffer => %s", getEGLError();
- return false;
- }
-
- GLenum checkResult = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- if (checkResult != GL_FRAMEBUFFER_COMPLETE) {
- LOG(ERROR) << "Offscreen framebuffer not configured successfully ("
- << checkResult
- << ": "
- << getGLFramebufferError().c_str()
- << ")";
- if (eglGetError() != EGL_SUCCESS) {
- LOG(ERROR) << "glCheckFramebufferStatus => "
- << getEGLError();
- }
- return false;
- }
-
- // Set the viewport
- glViewport(0, 0, pDesc->width, pDesc->height);
-
- // We don't actually need the clear if we're going to cover the whole
- // screen anyway
- // Clear the color buffer
- glClearColor(0.8f, 0.1f, 0.2f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-
- return true;
-}
-
-void SurroundViewServiceCallback::detachRenderTarget() {
- // Drop our external render target
- if (sKHRimage != EGL_NO_IMAGE_KHR) {
- eglDestroyImageKHR(sGLDisplay, sKHRimage);
- sKHRimage = EGL_NO_IMAGE_KHR;
- }
-}
-
-SurroundViewServiceCallback::SurroundViewServiceCallback(
- sp<IEvsDisplay> pDisplay,
- sp<ISurroundViewSession> pSession) :
- mDisplay(pDisplay),
- mSession(pSession) {
- // Nothing but member initialization
-}
-
-Return<void> SurroundViewServiceCallback::notify(SvEvent svEvent) {
- // Waiting for STREAM_STARTED event.
- if (svEvent == SvEvent::STREAM_STARTED) {
- LOG(INFO) << "Received STREAM_STARTED event";
-
- // Set the display state to VISIBLE_ON_NEXT_FRAME
- if (mDisplay != nullptr) {
- Return<EvsResult> result =
- mDisplay->setDisplayState(DisplayState::VISIBLE_ON_NEXT_FRAME);
- if (result != EvsResult::OK) {
- LOG(ERROR) << "Failed to setDisplayState";
- }
- } else {
- LOG(WARNING) << "setDisplayState is ignored since EVS display"
- << " is null";
- }
-
- // Set up OpenGL (exit if fail)
- if (!prepareGL()) {
- LOG(ERROR) << "Error while setting up OpenGL!";
- exit(EXIT_FAILURE);
- }
- } else if (svEvent == SvEvent::CONFIG_UPDATED) {
- LOG(INFO) << "Received CONFIG_UPDATED event";
- } else if (svEvent == SvEvent::STREAM_STOPPED) {
- LOG(INFO) << "Received STREAM_STOPPED event";
- } else if (svEvent == SvEvent::FRAME_DROPPED) {
- LOG(INFO) << "Received FRAME_DROPPED event";
- } else if (svEvent == SvEvent::TIMEOUT) {
- LOG(INFO) << "Received TIMEOUT event";
- } else {
- LOG(INFO) << "Received unknown event";
- }
- return {};
-}
-
-Return<void> SurroundViewServiceCallback::receiveFrames(
- const SvFramesDesc& svFramesDesc) {
- LOG(INFO) << "Incoming frames with svBuffers size: "
- << svFramesDesc.svBuffers.size();
- if (svFramesDesc.svBuffers.size() == 0) {
- return {};
- }
-
- // Now we assume there is only one frame for both 2d and 3d.
- auto handle =
- svFramesDesc.svBuffers[0].hardwareBuffer.nativeHandle
- .getNativeHandle();
- const AHardwareBuffer_Desc* pDesc =
- reinterpret_cast<const AHardwareBuffer_Desc *>(
- &svFramesDesc.svBuffers[0].hardwareBuffer.description);
-
- LOG(INFO) << "App received frames";
- LOG(INFO) << "descData: "
- << pDesc->width
- << pDesc->height
- << pDesc->layers
- << pDesc->format
- << pDesc->usage
- << pDesc->stride;
- LOG(INFO) << "nativeHandle: "
- << handle;
-
- // Only process the frame when EVS display is valid. If
- // not, ignore the coming frame.
- if (mDisplay == nullptr) {
- LOG(WARNING) << "Display is not ready. Skip the frame";
- } else {
- // Get display buffer from EVS display
- BufferDesc_1_0 tgtBuffer = {};
- mDisplay->getTargetBuffer([&tgtBuffer](const BufferDesc_1_0& buff) {
- tgtBuffer = buff;
- });
-
- if (!attachRenderTarget(convertBufferDesc(tgtBuffer))) {
- LOG(ERROR) << "Failed to attach render target";
- return {};
- } else {
- LOG(INFO) << "Successfully attached render target";
- }
-
- // Render frame to EVS display
- LOG(INFO) << "Rendering to display buffer";
- sp<GraphicBuffer> graphicBuffer =
- new GraphicBuffer(handle,
- GraphicBuffer::CLONE_HANDLE,
- pDesc->width,
- pDesc->height,
- pDesc->format,
- pDesc->layers, // layer count
- pDesc->usage,
- pDesc->stride);
-
- EGLImageKHR KHRimage = EGL_NO_IMAGE_KHR;
-
- // Get a GL compatible reference to the graphics buffer we've been given
- EGLint eglImageAttributes[] = {
- EGL_IMAGE_PRESERVED_KHR,
- EGL_TRUE,
- EGL_NONE
- };
- EGLClientBuffer clientBuf = static_cast<EGLClientBuffer>(
- graphicBuffer->getNativeBuffer());
- KHRimage = eglCreateImageKHR(sGLDisplay, EGL_NO_CONTEXT,
- EGL_NATIVE_BUFFER_ANDROID, clientBuf,
- eglImageAttributes);
- if (KHRimage == EGL_NO_IMAGE_KHR) {
- const char *msg = getEGLError();
- LOG(ERROR) << "error creating EGLImage: "
- << msg;
- return {};
- } else {
- LOG(INFO) << "Successfully created EGLImage";
-
- // Update the texture handle we already created to refer to
- // this gralloc buffer
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, sTextureId);
- glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,
- static_cast<GLeglImageOES>(KHRimage));
-
- // Initialize the sampling properties (it seems the sample may
- // not work if this isn't done)
- // The user of this texture may very well want to set their own
- // filtering, but we're going to pay the (minor) price of
- // setting this up for them to avoid the dreaded "black image"
- // if they forget.
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GL_CLAMP_TO_EDGE);
- }
-
- // Bind the texture and assign it to the shader's sampler
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, sTextureId);
-
- // We want our image to show up opaque regardless of alpha values
- glDisable(GL_BLEND);
-
- // Draw a rectangle on the screen
- const GLfloat vertsCarPos[] = {
- -1.0, 1.0, 0.0f, // left top in window space
- 1.0, 1.0, 0.0f, // right top
- -1.0, -1.0, 0.0f, // left bottom
- 1.0, -1.0, 0.0f // right bottom
- };
- const GLfloat vertsCarTex[] = {
- 0.0f, 0.0f, // left top
- 1.0f, 0.0f, // right top
- 0.0f, 1.0f, // left bottom
- 1.0f, 1.0f // right bottom
- };
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertsCarPos);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vertsCarTex);
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(0);
- glDisableVertexAttribArray(1);
-
- // Now that everything is submitted, release our hold on the
- // texture resource
- detachRenderTarget();
-
- // Wait for the rendering to finish
- glFinish();
- detachRenderTarget();
-
- // Drop our external render target
- if (KHRimage != EGL_NO_IMAGE_KHR) {
- eglDestroyImageKHR(sGLDisplay, KHRimage);
- KHRimage = EGL_NO_IMAGE_KHR;
- }
-
- LOG(DEBUG) << "Rendering finished. Going to return the buffer";
-
- // Call HIDL API "doneWithFrames" to return the ownership
- // back to SV service
- if (mSession == nullptr) {
- LOG(WARNING) << "SurroundViewSession in callback is invalid";
- } else {
- mSession->doneWithFrames(svFramesDesc);
- }
-
- // Return display buffer back to EVS display
- mDisplay->returnTargetBufferForDisplay(tgtBuffer);
- }
- return {};
-}
diff --git a/cpp/surround_view/app/SurroundViewServiceCallback.h b/cpp/surround_view/app/SurroundViewServiceCallback.h
deleted file mode 100644
index 467c69a..0000000
--- a/cpp/surround_view/app/SurroundViewServiceCallback.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-#pragma once
-
-#include <stdio.h>
-
-#include <utils/StrongPointer.h>
-
-#include <android/hardware/automotive/sv/1.0/ISurroundViewService.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h>
-#include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
-#include <android/hardware_buffer.h>
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-#include <GLES3/gl3.h>
-#include <GLES3/gl3ext.h>
-
-using namespace android::hardware::automotive::sv::V1_0;
-using namespace android::hardware::automotive::evs::V1_1;
-
-using BufferDesc_1_0 = ::android::hardware::automotive::evs::V1_0::BufferDesc;
-
-class SurroundViewServiceCallback : public ISurroundViewStream {
-public:
- SurroundViewServiceCallback(android::sp<IEvsDisplay> pDisplay,
- android::sp<ISurroundViewSession> pSession);
-
- // Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewStream.
- android::hardware::Return<void> notify(SvEvent svEvent) override;
- android::hardware::Return<void> receiveFrames(const SvFramesDesc& svFramesDesc) override;
-
-private:
- static const char* getEGLError(void);
- static const std::string getGLFramebufferError(void);
-
- bool prepareGL();
- BufferDesc convertBufferDesc(const BufferDesc_1_0& src);
- bool attachRenderTarget(const BufferDesc& tgtBuffer);
- void detachRenderTarget();
-
- static EGLDisplay sGLDisplay;
- static GLuint sFrameBuffer;
- static GLuint sColorBuffer;
- static GLuint sDepthBuffer;
- static GLuint sTextureId;
- static EGLImageKHR sKHRimage;
-
- android::sp<IEvsDisplay> mDisplay;
- android::sp<ISurroundViewSession> mSession;
-};
diff --git a/cpp/surround_view/app/shader.cpp b/cpp/surround_view/app/shader.cpp
deleted file mode 100644
index 3ca6f74..0000000
--- a/cpp/surround_view/app/shader.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2020 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 "shader.h"
-
-#include <android-base/logging.h>
-#include <memory>
-#include <stdio.h>
-
-// Given shader source, load and compile it
-static GLuint loadShader(GLenum type, const char *shaderSrc, const char *name) {
- // Create the shader object
- GLuint shader = glCreateShader (type);
- if (shader == 0) {
- return 0;
- }
-
- // Load and compile the shader
- glShaderSource(shader, 1, &shaderSrc, nullptr);
- glCompileShader(shader);
-
- // Verify the compilation worked as expected
- GLint compiled = 0;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if (!compiled) {
- LOG(ERROR) << "Error compiling "
- << (type==GL_VERTEX_SHADER ? "vtx":"pxl")
- << " shader for "
- << name;
-
- GLint size = 0;
- glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &size);
- if (size > 0) {
- // Get and report the error message
- std::unique_ptr<char> infoLog(new char[size]);
- glGetShaderInfoLog(shader, size, NULL, infoLog.get());
- LOG(ERROR) << " msg:\n"
- << infoLog.get();
- }
-
- glDeleteShader(shader);
- return 0;
- }
-
- return shader;
-}
-
-
-// Create a program object given vertex and pixels shader source
-GLuint buildShaderProgram(const char* vtxSrc, const char* pxlSrc, const char* name) {
- GLuint program = glCreateProgram();
- if (program == 0) {
- LOG(ERROR) << "Failed to allocate program object";
- return 0;
- }
-
- // Compile the shaders and bind them to this program
- GLuint vertexShader = loadShader(GL_VERTEX_SHADER, vtxSrc, name);
- if (vertexShader == 0) {
- LOG(ERROR) << "Failed to load vertex shader";
- glDeleteProgram(program);
- return 0;
- }
- GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pxlSrc, name);
- if (pixelShader == 0) {
- LOG(ERROR) << "Failed to load pixel shader";
- glDeleteProgram(program);
- glDeleteShader(vertexShader);
- return 0;
- }
- glAttachShader(program, vertexShader);
- glAttachShader(program, pixelShader);
-
- // Link the program
- glLinkProgram(program);
- GLint linked = 0;
- glGetProgramiv(program, GL_LINK_STATUS, &linked);
- if (!linked) {
- LOG(ERROR) << "Error linking program.";
- GLint size = 0;
- glGetProgramiv(program, GL_INFO_LOG_LENGTH, &size);
- if (size > 0) {
- // Get and report the error message
- std::unique_ptr<char> infoLog(new char[size]);
- glGetProgramInfoLog(program, size, NULL, infoLog.get());
- LOG(ERROR) << " msg: "
- << infoLog.get();
- }
-
- glDeleteProgram(program);
- glDeleteShader(vertexShader);
- glDeleteShader(pixelShader);
- return 0;
- }
-
- return program;
-}
-
diff --git a/cpp/surround_view/app/shader.h b/cpp/surround_view/app/shader.h
deleted file mode 100644
index 63d5795..0000000
--- a/cpp/surround_view/app/shader.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2020 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 SHADER_H
-#define SHADER_H
-
-#include <GLES2/gl2.h>
-
-// Create a program object given vertex and pixels shader source
-GLuint buildShaderProgram(const char* vtxSrc, const char* pxlSrc, const char* name);
-
-#endif // SHADER_H
diff --git a/cpp/surround_view/app/shader_simpleTex.h b/cpp/surround_view/app/shader_simpleTex.h
deleted file mode 100644
index 4caf633..0000000
--- a/cpp/surround_view/app/shader_simpleTex.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2020 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 SHADER_SIMPLE_TEX_H
-#define SHADER_SIMPLE_TEX_H
-
-const char kVtxShaderSimpleTexture[] = ""
- "#version 300 es \n"
- "layout(location = 0) in vec4 posCoord; \n"
- "layout(location = 1) in vec2 texCoord; \n"
- "uniform mat4 cameraMat; \n"
- "out vec2 TexCoord; \n"
- "void main() \n"
- "{ \n"
- " gl_Position = cameraMat * posCoord; \n"
- " TexCoord = texCoord; \n"
- "} \n";
-
-const char kPixShaderSimpleTexture[] =
- "#version 300 es \n"
- "precision mediump float; \n"
- "uniform sampler2D texSampler; \n"
- "in vec2 TexCoord; \n"
- "out vec4 color; \n"
- "void main() \n"
- "{ \n"
- " vec4 texel = texture(texSampler, TexCoord); \n"
- " color = texel; \n"
- "} \n";
-
-#endif // SHADER_SIMPLE_TEX_H
diff --git a/cpp/surround_view/app/sv_app.cpp b/cpp/surround_view/app/sv_app.cpp
deleted file mode 100644
index d07671d..0000000
--- a/cpp/surround_view/app/sv_app.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2020 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 "SurroundViewAppCommon.h"
-#include "SurroundViewServiceCallback.h"
-
-// libhidl:
-using android::hardware::configureRpcThreadpool;
-using android::hardware::joinRpcThreadpool;
-
-using android::sp;
-using android::hardware::Return;
-using android::hardware::automotive::evs::V1_0::EvsResult;
-
-using BufferDesc_1_0 = android::hardware::automotive::evs::V1_0::BufferDesc;
-using DisplayState = android::hardware::automotive::evs::V1_0::DisplayState;
-
-using namespace android::hardware::automotive::sv::V1_0;
-using namespace android::hardware::automotive::evs::V1_1;
-using namespace android::hardware::automotive::sv::app;
-
-// Main entry point
-int main(int argc, char** argv) {
- // Start up
- LOG(INFO) << "SV app starting";
-
- DemoMode mode = UNKNOWN;
- for (int i=1; i< argc; i++) {
- if (strcmp(argv[i], "--use2d") == 0) {
- mode = DEMO_2D;
- } else if (strcmp(argv[i], "--use3d") == 0) {
- mode = DEMO_3D;
- } else {
- LOG(WARNING) << "Ignoring unrecognized command line arg: "
- << argv[i];
- }
- }
-
- if (mode == UNKNOWN) {
- LOG(ERROR) << "No demo mode is specified. Exiting";
- return EXIT_FAILURE;
- }
-
- // Set thread pool size to one to avoid concurrent events from the HAL.
- // This pool will handle the SurroundViewStream callbacks.
- configureRpcThreadpool(1, false /* callerWillJoin */);
-
- // Try to connect to EVS service
- LOG(INFO) << "Acquiring EVS Enumerator";
- sp<IEvsEnumerator> evs = IEvsEnumerator::getService();
- if (evs == nullptr) {
- LOG(ERROR) << "getService(default) returned NULL. Exiting.";
- return EXIT_FAILURE;
- }
-
- // Try to connect to SV service
- LOG(INFO) << "Acquiring SV Service";
- android::sp<ISurroundViewService> surroundViewService
- = ISurroundViewService::getService("default");
-
- if (surroundViewService == nullptr) {
- LOG(ERROR) << "getService(default) returned NULL.";
- return EXIT_FAILURE;
- } else {
- LOG(INFO) << "Get ISurroundViewService default";
- }
-
- // Connect to evs display
- int displayId;
- evs->getDisplayIdList([&displayId](auto idList) {
- displayId = idList[0];
- });
-
- LOG(INFO) << "Acquiring EVS Display with ID: "
- << displayId;
- sp<IEvsDisplay> display = evs->openDisplay_1_1(displayId);
- if (display == nullptr) {
- LOG(ERROR) << "EVS Display unavailable. Exiting.";
- return EXIT_FAILURE;
- }
-
- if (mode == DEMO_2D) {
- if (!run2dSurroundView(surroundViewService, display)) {
- LOG(ERROR) << "Something went wrong in 2d surround view demo. "
- << "Exiting.";
- return EXIT_FAILURE;
- }
- } else if (mode == DEMO_3D) {
- if (!run3dSurroundView(surroundViewService, display)) {
- LOG(ERROR) << "Something went wrong in 3d surround view demo. "
- << "Exiting.";
- return EXIT_FAILURE;
- }
- }
-
- evs->closeDisplay(display);
-
- LOG(DEBUG) << "SV sample app finished running successfully";
- return EXIT_SUCCESS;
-}
diff --git a/cpp/surround_view/app/sv_app.rc b/cpp/surround_view/app/sv_app.rc
deleted file mode 100644
index 74ad768..0000000
--- a/cpp/surround_view/app/sv_app.rc
+++ /dev/null
@@ -1,6 +0,0 @@
-service sv_app /system/bin/sv_app
- class hal
- priority -20
- user automotive_evs
- group automotive_evs
- disabled # will not automatically start with its class; must be explicitly started.
diff --git a/cpp/surround_view/sepolicy/file_contexts b/cpp/surround_view/sepolicy/file_contexts
deleted file mode 100644
index 34d2677..0000000
--- a/cpp/surround_view/sepolicy/file_contexts
+++ /dev/null
@@ -1,8 +0,0 @@
-
-###################################
-# Binaries associated with the Surround View
-#
-/system/bin/sv_app u:object_r:sv_app_exec:s0
-/vendor/bin/android\.automotive\.sv\.service@1\.[0-9]+-impl u:object_r:sv_service_impl_exec:s0
-
-###################################
diff --git a/cpp/surround_view/sepolicy/sv_app.te b/cpp/surround_view/sepolicy/sv_app.te
deleted file mode 100644
index b1aca2d..0000000
--- a/cpp/surround_view/sepolicy/sv_app.te
+++ /dev/null
@@ -1,9 +0,0 @@
-# surround view sample app
-type sv_app, domain, coredomain;
-
-# allow init to launch processes in this context
-type sv_app_exec, exec_type, file_type, system_file_type;
-init_daemon_domain(sv_app)
-
-# Allow use of binder
-binder_use(sv_app);
diff --git a/cpp/surround_view/sepolicy/sv_service_impl.te b/cpp/surround_view/sepolicy/sv_service_impl.te
deleted file mode 100644
index 2bff1f9..0000000
--- a/cpp/surround_view/sepolicy/sv_service_impl.te
+++ /dev/null
@@ -1,7 +0,0 @@
-# surround view default service implementation
-type sv_service_impl, domain;
-
-# allow init to launch processes in this context
-type sv_service_impl_exec, exec_type, file_type, vendor_file_type;
-init_daemon_domain(sv_service_impl)
-binder_use(sv_service_impl)
diff --git a/cpp/surround_view/service-impl/Android.bp b/cpp/surround_view/service-impl/Android.bp
deleted file mode 100644
index f2a4cbd..0000000
--- a/cpp/surround_view/service-impl/Android.bp
+++ /dev/null
@@ -1,463 +0,0 @@
-//
-// Copyright 2020 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.
-//
-
-package {
- default_applicable_licenses: ["Android-Apache-2.0"],
-}
-
-cc_library {
- name : "libobj_reader",
- vendor : true,
- srcs: [
- "MtlReader.cpp",
- "ObjReader.cpp",
- ],
- shared_libs : [
- "libbase",
- ]
-}
-
-cc_test{
- name : "obj_reader_tests",
- test_suites : ["device-tests"],
- vendor : true,
- srcs : ["ObjReaderTests.cpp"],
- shared_libs : [
- "libobj_reader",
- "libcutils",
- "libbase",
- "libutils",
- ],
- required: [
- "sample_car.obj",
- "sample_car_material.mtl",
- ],
-}
-
-// Library for IO Module.
-cc_library {
- name : "libio_module",
- vendor : true,
- srcs: [
- "ConfigReader.cpp",
- "CarModelConfigReader.cpp",
- "ConfigReaderUtil.cpp",
- "IOModule.cpp",
- ],
- shared_libs : [
- "libbase",
- "libobj_reader",
- "libtinyxml2",
- ]
-}
-
-cc_test{
- name : "io_module_tests",
- test_suites : ["device-tests"],
- vendor : true,
- srcs : [
- "CarModelConfigReaderTests.cpp",
- "ConfigReaderTests.cpp",
- ],
- shared_libs : [
- "libbase",
- "libcutils",
- "libio_module",
- "libobj_reader",
- "libtinyxml2",
- "libutils",
- ],
- required: [
- "sv_sample_car_model_config.xml",
- "sv_sample_config.xml",
- ],
-}
-
-cc_library{
- name : "libanimation_module",
- vendor : true,
- srcs : [
- "AnimationModule.cpp",
- ],
- shared_libs : [
- "android.hardware.automotive.vehicle@2.0",
- "libbase",
- "libhidlbase",
- "libutils",
- ],
-}
-
-cc_test{
- name : "animation_module_tests",
- test_suites : ["device-tests"],
- vendor : true,
- srcs : ["AnimationModuleTests.cpp"],
- shared_libs : [
- "android.hardware.automotive.vehicle@2.0",
- "libanimation_module",
- "libcutils",
- "libbase",
- "libhidlbase",
- "libhardware",
- "libutils",
- ],
-}
-
-cc_library{
- name : "libvhal_handler",
- vendor : true,
- srcs : [
- "VhalHandler.cpp",
- ],
- shared_libs : [
- "android.hardware.automotive.vehicle@2.0",
- "android.hidl.memory@1.0",
- "libcutils",
- "libbase",
- "libbinder",
- "libhidlbase",
- "libhardware",
- "libhidlmemory",
- "libui",
- "libutils",
- ],
-}
-
-cc_test{
- name : "vhal_handler_tests",
- test_suites : ["device-tests"],
- vendor : true,
- srcs : ["VhalHandlerTests.cpp"],
- shared_libs : [
- "android.hardware.automotive.vehicle@2.0",
- "libvhal_handler",
- "libcutils",
- "libbase",
- "libbinder",
- "libhidlbase",
- "libhardware",
- "libhidlmemory",
- "libui",
- "libutils",
- ],
-}
-
-cc_library{
- name : "libsvsession",
- vendor : true,
- srcs : [
- "CameraUtils.cpp",
- "SurroundView2dSession.cpp",
- "SurroundView3dSession.cpp",
- ],
- shared_libs : [
- "android.hardware.automotive.evs@1.0",
- "android.hardware.automotive.evs@1.1",
- "android.hardware.automotive.sv@1.0",
- "android.hardware.automotive.vehicle@2.0",
- "android.hidl.memory@1.0",
- "libanimation_module",
- "libbase",
- "libbinder",
- "libcamera_metadata",
- "libcore_lib_shared",
- "libcutils",
- "libhardware",
- "libhidlbase",
- "libhidlmemory",
- "libnativewindow",
- "libio_module",
- "libui",
- "libutils",
- "libvulkan",
- "libvhal_handler",
- ],
- required : [
- "cam0.png",
- "cam1.png",
- "cam2.png",
- "cam3.png",
- "sample_car.obj",
- "sample_car_material.mtl",
- "sv_sample_config.xml",
- "sv_sample_car_model_config.xml",
- ],
- // Disable builds except for arm64 and emulator devices
- enabled : false,
- arch : {
- arm64 : {
- enabled : true,
- },
- x86 : {
- enabled : true,
- },
- x86_64 : {
- enabled : true,
- },
- },
-}
-
-cc_test{
- name : "sv_2d_session_tests",
- test_suites : ["device-tests"],
- vendor : true,
- srcs : [
- "SurroundView2dSessionTests.cpp",
- "mock-evs/MockEvsCamera.cpp",
- "mock-evs/MockEvsEnumerator.cpp",
- "mock-evs/MockSurroundViewCallback.cpp",
- ],
- include_dirs: [
- "packages/services/Car/cpp/evs/sampleDriver",
- ],
- shared_libs : [
- "android.hardware.automotive.evs@1.0",
- "android.hardware.automotive.evs@1.1",
- "android.hardware.automotive.sv@1.0",
- "android.hardware.automotive.vehicle@2.0",
- "android.hidl.memory@1.0",
- "libanimation_module",
- "libbase",
- "libbinder",
- "libcamera_metadata",
- "libcore_lib_shared",
- "libcutils",
- "libevsconfigmanager",
- "libhardware",
- "libhidlbase",
- "libhidlmemory",
- "libio_module",
- "libsvsession",
- "libtinyxml2",
- "libui",
- "libutils",
- "libvhal_handler",
- ],
- // Disable builds except for arm64 and emulator devices
- enabled : false,
- arch : {
- arm64 : {
- enabled : true,
- },
- x86 : {
- enabled : true,
- },
- x86_64 : {
- enabled : true,
- },
- },
- required : [
- "sample_car.obj",
- "sample_car_material.mtl",
- "sv_sample_config.xml",
- "sv_sample_car_model_config.xml",
- ],
-}
-
-cc_test{
- name : "sv_3d_session_tests",
- test_suites : ["device-tests"],
- vendor : true,
- srcs : [
- "SurroundView3dSessionTests.cpp",
- "mock-evs/MockEvsCamera.cpp",
- "mock-evs/MockEvsEnumerator.cpp",
- "mock-evs/MockSurroundViewCallback.cpp",
- ],
- include_dirs: [
- "packages/services/Car/cpp/evs/sampleDriver",
- ],
- shared_libs : [
- "android.hardware.automotive.evs@1.0",
- "android.hardware.automotive.evs@1.1",
- "android.hardware.automotive.sv@1.0",
- "android.hardware.automotive.vehicle@2.0",
- "android.hidl.memory@1.0",
- "android.hidl.allocator@1.0",
- "libanimation_module",
- "libbase",
- "libbinder",
- "libcamera_metadata",
- "libcore_lib_shared",
- "libcutils",
- "libevsconfigmanager",
- "libhardware",
- "libhidlbase",
- "libhidlmemory",
- "libio_module",
- "libsvsession",
- "libtinyxml2",
- "libui",
- "libutils",
- "libvhal_handler",
- ],
- // Disable builds except for arm64 and emulator devices
- enabled : false,
- arch : {
- arm64 : {
- enabled : true,
- },
- x86 : {
- enabled : true,
- },
- x86_64 : {
- enabled : true,
- },
- },
- required : [
- "sample_car.obj",
- "sample_car_material.mtl",
- "sv_sample_config.xml",
- "sv_sample_car_model_config.xml",
- ],
-}
-
-cc_binary{
- name : "android.automotive.sv.service@1.0-impl",
- vendor : true,
- srcs : [
- "SurroundViewService.cpp",
- "service.cpp",
- ],
- init_rc : ["android.automotive.sv.service@1.0-impl.rc"],
- shared_libs : [
- "android.hardware.automotive.evs@1.1",
- "android.hardware.automotive.sv@1.0",
- "android.hardware.automotive.vehicle@2.0",
- "android.hidl.memory@1.0",
- "libanimation_module",
- "libbase",
- "libbinder",
- "libcamera_metadata",
- "libcore_lib_shared",
- "libcutils",
- "libhardware",
- "libhidlbase",
- "libhidlmemory",
- "libio_module",
- "libsvsession",
- "libui",
- "libutils",
- "libvhal_handler",
- ],
- cflags: ["-DLOG_TAG=\"SurroundViewService\""],
- required : [
- "cam0.png",
- "cam1.png",
- "cam2.png",
- "cam3.png",
- "sample_car.obj",
- "sample_car_material.mtl",
- "sv_sample_config.xml",
- "sv_sample_car_model_config.xml",
- ],
- // Disable builds except for arm64 and emulator devices
- enabled : false,
- arch : {
- arm64 : {
- enabled : true,
- },
- x86 : {
- enabled : true,
- },
- x86_64 : {
- enabled : true,
- },
- },
- vintf_fragments : [
- "manifest_android.hardware.automotive.sv@1.0.xml",
- ],
-}
-
-cc_prebuilt_library_shared{
- name : "libcore_lib_shared",
- proprietary : true,
- arch : {
- arm64 : {srcs : ["lib/arm64/libcore_lib_shared.so"]},
- x86 : {srcs : ["lib/x86/libcore_lib_shared.so"]},
- x86_64 : {srcs : ["lib/x86-64/libcore_lib_shared.so"]},
- },
- shared_libs : [
- "libutils",
- "libcutils",
- "libbase",
- "libEGL",
- "libGLESv2",
- "libGLESv3",
- "libc",
- "libm",
- "libdl",
- "libz",
- "liblog",
- "libvulkan",
- ],
-}
-
-prebuilt_etc{
- name : "cam0.png",
- soc_specific : true,
- src : "test_data/0.png",
- sub_dir : "automotive/sv",
-}
-
-prebuilt_etc{
- name : "cam1.png",
- soc_specific : true,
- src : "test_data/1.png",
- sub_dir : "automotive/sv",
-}
-
-prebuilt_etc{
- name : "cam2.png",
- soc_specific : true,
- src : "test_data/2.png",
- sub_dir : "automotive/sv",
-}
-
-prebuilt_etc {
- name :"cam3.png",
- soc_specific : true,
- src : "test_data/3.png",
- sub_dir : "automotive/sv",
-}
-
-prebuilt_etc {
- name : "sample_car.obj",
- soc_specific : true,
- src : "test_data/sample_car.obj",
- sub_dir : "automotive/sv",
-}
-
-prebuilt_etc {
- name : "sample_car_material.mtl",
- soc_specific : true,
- src: "test_data/sample_car_material.mtl",
- sub_dir: "automotive/sv",
-}
-
-prebuilt_etc {
- name : "sv_sample_config.xml",
- soc_specific : true,
- src : "test_data/sv_sample_config.xml",
- sub_dir : "automotive/sv",
-}
-
-prebuilt_etc {
- name:"sv_sample_car_model_config.xml",
- soc_specific : true,
- src : "test_data/sv_sample_car_model_config.xml",
- sub_dir : "automotive/sv",
-}
diff --git a/cpp/surround_view/service-impl/AnimationModule.cpp b/cpp/surround_view/service-impl/AnimationModule.cpp
deleted file mode 100644
index 2eecdb0..0000000
--- a/cpp/surround_view/service-impl/AnimationModule.cpp
+++ /dev/null
@@ -1,518 +0,0 @@
-/*
- * Copyright 2020 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 "AnimationModule.h"
-#include "MathHelp.h"
-
-#include <android-base/logging.h>
-#include <algorithm>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-std::array<float, 3> operator*(std::array<float, 3> lvector, float scalar) {
- return std::array<float, 3>{
- lvector[0] * scalar,
- lvector[1] * scalar,
- lvector[2] * scalar,
- };
-}
-
-inline float getRationalNumber(const Range& mappedRange, float percentage) {
- return mappedRange.start + (mappedRange.end - mappedRange.start) * percentage;
-}
-
-inline float getRationalNumber(const Range& mappedRange, const Range& rawRange, float rawValue) {
- if (0 == rawRange.end - rawRange.start) {
- return mappedRange.start;
- }
- const float percentage = (rawValue - rawRange.start) / (rawRange.end - rawRange.start);
- return mappedRange.start + (mappedRange.end - mappedRange.start) * percentage > 1
- ? 1
- : percentage < 0 ? 0 : percentage;
-}
-
-inline uint64_t getCombinedId(const VehiclePropValue& vhalValueFloat) {
- return static_cast<uint64_t>(vhalValueFloat.prop) << 32 | vhalValueFloat.areaId;
-}
-
-float getVhalValueFloat(const VehiclePropValue& vhalValue) {
- int32_t type = vhalValue.prop & 0x00FF0000;
- switch (type) {
- case (int32_t)VehiclePropertyType::BOOLEAN:
- return 0 == vhalValue.value.int32Values[0] ? 0.0f : 1.0f;
- case (int32_t)VehiclePropertyType::FLOAT:
- return vhalValue.value.floatValues[0];
- case (int32_t)VehiclePropertyType::INT32:
- return (float)vhalValue.value.int32Values[0];
- case (int32_t)VehiclePropertyType::INT64:
- return (float)vhalValue.value.int64Values[0];
- default:
- return 0;
- }
-}
-} // namespace
-
-AnimationModule::AnimationModule(const std::map<std::string, CarPart>& partsMap,
- const std::map<std::string, CarTexture>& texturesMap,
- const std::vector<AnimationInfo>& animations) :
- mIsCalled(false), mPartsMap(partsMap), mTexturesMap(texturesMap), mAnimations(animations) {
- mapVhalToParts();
- initCarPartStatus();
-}
-
-void AnimationModule::mapVhalToParts() {
- for (const auto& animationInfo : mAnimations) {
- auto partId = animationInfo.partId;
- for (const auto& gammaOp : animationInfo.gammaOpsMap) {
- if (mVhalToPartsMap.find(gammaOp.first) != mVhalToPartsMap.end()) {
- mVhalToPartsMap.at(gammaOp.first).insert(partId);
- } else {
- mVhalToPartsMap.emplace(
- std::make_pair(gammaOp.first, std::set<std::string>{partId}));
- }
- }
- for (const auto& textureOp : animationInfo.textureOpsMap) {
- if (mVhalToPartsMap.find(textureOp.first) != mVhalToPartsMap.end()) {
- mVhalToPartsMap.at(textureOp.first).insert(partId);
- } else {
- mVhalToPartsMap.emplace(
- std::make_pair(textureOp.first, std::set<std::string>{partId}));
- }
- }
- for (const auto& rotationOp : animationInfo.rotationOpsMap) {
- if (mVhalToPartsMap.find(rotationOp.first) != mVhalToPartsMap.end()) {
- mVhalToPartsMap.at(rotationOp.first).insert(partId);
- } else {
- mVhalToPartsMap.emplace(
- std::make_pair(rotationOp.first, std::set<std::string>{partId}));
- }
- }
- for (const auto& translationOp : animationInfo.translationOpsMap) {
- if (mVhalToPartsMap.find(translationOp.first) != mVhalToPartsMap.end()) {
- mVhalToPartsMap.at(translationOp.first).insert(partId);
- } else {
- mVhalToPartsMap.emplace(
- std::make_pair(translationOp.first, std::set<std::string>{partId}));
- }
- }
- mPartsToAnimationMap.emplace(std::make_pair(partId, animationInfo));
- }
-}
-
-void AnimationModule::initCarPartStatus() {
- for (const auto& part : mPartsMap) {
- // Get child parts list from mPartsToAnimationMap.
- std::vector<std::string> childIds;
- if (mPartsToAnimationMap.find(part.first) != mPartsToAnimationMap.end()) {
- childIds = mPartsToAnimationMap.at(part.first).childIds;
- }
-
- mCarPartsStatusMap.emplace(std::make_pair(part.first,
- CarPartStatus{
- .partId = part.first,
- .childIds = childIds,
- .parentModel = gMat4Identity,
- .localModel = gMat4Identity,
- .currentModel = gMat4Identity,
- .gamma = 1,
- }));
- }
-
- for (const auto& eachVhalToParts : mVhalToPartsMap) {
- for (const auto& part : eachVhalToParts.second) {
- if (mCarPartsStatusMap.at(part).vhalProgressMap.find(eachVhalToParts.first) !=
- mCarPartsStatusMap.at(part).vhalProgressMap.end()) {
- mCarPartsStatusMap.at(part).vhalProgressMap.at(eachVhalToParts.first) = 0.0f;
- } else {
- mCarPartsStatusMap.at(part).vhalProgressMap.emplace(
- std::make_pair(eachVhalToParts.first, 0.0f));
- }
- if (mCarPartsStatusMap.at(part).vhalOffMap.find(eachVhalToParts.first) !=
- mCarPartsStatusMap.at(part).vhalOffMap.end()) {
- mCarPartsStatusMap.at(part).vhalOffMap.at(eachVhalToParts.first) = true;
- } else {
- mCarPartsStatusMap.at(part).vhalOffMap.emplace(
- std::make_pair(eachVhalToParts.first, true));
- }
- }
- }
-}
-
-// This implementation assumes the tree level is small. If tree level is large,
-// we may need to traverse the tree once and process each node(part) during
-// the reaversal.
-void AnimationModule::updateChildrenParts(const std::string& partId, const Mat4x4& parentModel) {
- for (auto& childPart : mCarPartsStatusMap.at(partId).childIds) {
- mCarPartsStatusMap.at(childPart).parentModel = parentModel;
- mCarPartsStatusMap.at(childPart).currentModel =
- appendMat(mCarPartsStatusMap.at(childPart).localModel,
- mCarPartsStatusMap.at(childPart).parentModel);
- if (mUpdatedPartsMap.find(childPart) == mUpdatedPartsMap.end()) {
- AnimationParam animationParam(childPart);
- animationParam.SetModelMatrix(mCarPartsStatusMap.at(childPart).currentModel);
- mUpdatedPartsMap.emplace(std::make_pair(childPart, animationParam));
- } else { // existing part in the map
- mUpdatedPartsMap.at(childPart).SetModelMatrix(
- mCarPartsStatusMap.at(childPart).currentModel);
- }
- updateChildrenParts(childPart, mCarPartsStatusMap.at(childPart).currentModel);
- }
-}
-
-void AnimationModule::performGammaOp(const std::string& partId, uint64_t vhalProperty,
- const GammaOp& gammaOp) {
- CarPartStatus& currentCarPartStatus = mCarPartsStatusMap.at(partId);
- float& currentProgress = currentCarPartStatus.vhalProgressMap.at(vhalProperty);
- if (currentCarPartStatus.vhalOffMap.at(vhalProperty)) { // process off signal
- if (currentProgress > 0) { // part not rest
- if (0 == gammaOp.animationTime) {
- currentCarPartStatus.gamma = gammaOp.gammaRange.start;
- currentProgress = 0.0f;
- } else {
- const float progressDelta =
- (mCurrentCallTime - mLastCallTime) / gammaOp.animationTime;
- if (progressDelta > currentProgress) {
- currentCarPartStatus.gamma = gammaOp.gammaRange.start;
- currentProgress = 0.0f;
- } else {
- currentCarPartStatus.gamma =
- getRationalNumber(gammaOp.gammaRange, currentProgress - progressDelta);
- currentProgress -= progressDelta;
- }
- }
- } else {
- return;
- }
- } else { // regular signal process
- if (0 == gammaOp.animationTime) { // continuous value
- currentCarPartStatus.gamma =
- getRationalNumber(gammaOp.gammaRange, gammaOp.vhalRange,
- mVhalStatusMap.at(vhalProperty).vhalValueFloat);
- currentProgress = mVhalStatusMap.at(vhalProperty).vhalValueFloat;
- } else { // non-continuous value
- const float progressDelta = (mCurrentCallTime - mLastCallTime) / gammaOp.animationTime;
- if (gammaOp.type == ADJUST_GAMMA_ONCE) {
- if (progressDelta + currentCarPartStatus.vhalProgressMap.at(vhalProperty) > 1) {
- currentCarPartStatus.gamma = gammaOp.gammaRange.end;
- currentProgress = 1.0f;
- } else {
- currentCarPartStatus.gamma =
- getRationalNumber(gammaOp.gammaRange, currentProgress + progressDelta);
- currentProgress += progressDelta;
- }
- } else if (gammaOp.type == ADJUST_GAMMA_REPEAT) {
- if (progressDelta + currentCarPartStatus.vhalProgressMap.at(vhalProperty) > 1) {
- if (progressDelta + currentCarPartStatus.vhalProgressMap.at(vhalProperty) - 1 >
- 1) {
- currentCarPartStatus.gamma =
- currentCarPartStatus.vhalProgressMap.at(vhalProperty) > 0.5
- ? gammaOp.gammaRange.start
- : gammaOp.gammaRange.end;
- currentProgress =
- currentCarPartStatus.vhalProgressMap.at(vhalProperty) > 0.5 ? 0.0f
- : 1.0f;
- } else {
- currentCarPartStatus.gamma =
- getRationalNumber(gammaOp.gammaRange,
- progressDelta +
- currentCarPartStatus.vhalProgressMap.at(
- vhalProperty) -
- 1);
- currentProgress += progressDelta - 1;
- }
- } else {
- currentCarPartStatus.gamma =
- getRationalNumber(gammaOp.gammaRange, currentProgress + progressDelta);
- currentProgress += progressDelta;
- }
- } else {
- LOG(ERROR) << "Error type of gamma op: " << gammaOp.type;
- }
- }
- }
-
- if (mUpdatedPartsMap.find(partId) == mUpdatedPartsMap.end()) {
- AnimationParam animationParam(partId);
- animationParam.SetGamma(currentCarPartStatus.gamma);
- mUpdatedPartsMap.emplace(std::make_pair(partId, animationParam));
- } else { // existing part in the map
- mUpdatedPartsMap.at(partId).SetGamma(currentCarPartStatus.gamma);
- }
-}
-
-void AnimationModule::performTranslationOp(const std::string& partId, uint64_t vhalProperty,
- const TranslationOp& translationOp) {
- CarPartStatus& currentCarPartStatus = mCarPartsStatusMap.at(partId);
- float& currentProgress = currentCarPartStatus.vhalProgressMap.at(vhalProperty);
- if (currentCarPartStatus.vhalOffMap.at(vhalProperty)) { // process off signal
- if (currentProgress > 0) {
- // part not rest
- if (0 == translationOp.animationTime) {
- currentCarPartStatus.localModel = gMat4Identity;
- currentCarPartStatus.currentModel = currentCarPartStatus.parentModel;
- currentProgress = 0.0f;
- } else {
- const float progressDelta =
- (mCurrentCallTime - mLastCallTime) / translationOp.animationTime;
- float translationUnit =
- getRationalNumber(translationOp.translationRange,
- std::max(currentProgress - progressDelta, 0.0f));
- currentCarPartStatus.localModel =
- translationMatrixToMat4x4(translationOp.direction * translationUnit);
- currentCarPartStatus.currentModel = appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress = std::max(currentProgress - progressDelta, 0.0f);
- }
- } else {
- return;
- }
- } else { // regular signal process
- if (translationOp.type == TRANSLATION) {
- if (0 == translationOp.animationTime) {
- float translationUnit =
- getRationalNumber(translationOp.translationRange, translationOp.vhalRange,
- mVhalStatusMap.at(vhalProperty).vhalValueFloat);
- currentCarPartStatus.localModel =
- translationMatrixToMat4x4(translationOp.direction * translationUnit);
- currentCarPartStatus.currentModel = appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress = mVhalStatusMap.at(vhalProperty).vhalValueFloat;
- } else {
- float progressDelta =
- (mCurrentCallTime - mLastCallTime) / translationOp.animationTime;
- if (progressDelta + currentCarPartStatus.vhalProgressMap.at(vhalProperty) > 1) {
- float translationUnit = translationOp.translationRange.end;
-
- currentCarPartStatus.localModel =
- translationMatrixToMat4x4(translationOp.direction * translationUnit);
- currentCarPartStatus.currentModel =
- appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress = 1.0f;
- } else {
- float translationUnit = getRationalNumber(translationOp.translationRange,
- progressDelta + currentProgress);
- currentCarPartStatus.localModel =
- translationMatrixToMat4x4(translationOp.direction * translationUnit);
- currentCarPartStatus.currentModel =
- appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress += progressDelta;
- }
- }
- } else {
- LOG(ERROR) << "Error type of translation op: " << translationOp.type;
- }
- }
- if (mUpdatedPartsMap.find(partId) == mUpdatedPartsMap.end()) {
- AnimationParam animationParam(partId);
- animationParam.SetModelMatrix(currentCarPartStatus.currentModel);
- mUpdatedPartsMap.emplace(std::make_pair(partId, animationParam));
- } else { // existing part in the map
- mUpdatedPartsMap.at(partId).SetModelMatrix(currentCarPartStatus.currentModel);
- }
- updateChildrenParts(partId, currentCarPartStatus.currentModel);
-}
-
-void AnimationModule::performRotationOp(const std::string& partId, uint64_t vhalProperty,
- const RotationOp& rotationOp) {
- CarPartStatus& currentCarPartStatus = mCarPartsStatusMap.at(partId);
- float& currentProgress = currentCarPartStatus.vhalProgressMap.at(vhalProperty);
- if (currentCarPartStatus.vhalOffMap.at(vhalProperty)) {
- // process off signal
- if (currentProgress > 0) { // part not rest
- if (0 == rotationOp.animationTime) {
- currentCarPartStatus.localModel = gMat4Identity;
- currentCarPartStatus.currentModel = currentCarPartStatus.parentModel;
- currentProgress = 0.0f;
- } else {
- const float progressDelta =
- (mCurrentCallTime - mLastCallTime) / rotationOp.animationTime;
- if (progressDelta > currentProgress) {
- currentCarPartStatus.localModel = gMat4Identity;
- currentCarPartStatus.currentModel = currentCarPartStatus.parentModel;
- currentProgress = 0.0f;
- } else {
- float anlgeInDegree = getRationalNumber(rotationOp.rotationRange,
- currentProgress - progressDelta);
- currentCarPartStatus.localModel =
- rotationAboutPoint(anlgeInDegree, rotationOp.axis.rotationPoint,
- rotationOp.axis.axisVector);
- currentCarPartStatus.currentModel =
- appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress -= progressDelta;
- }
- }
- } else {
- return;
- }
- } else { // regular signal process
- if (rotationOp.type == ROTATION_ANGLE) {
- if (0 == rotationOp.animationTime) {
- float angleInDegree =
- getRationalNumber(rotationOp.rotationRange, rotationOp.vhalRange,
- mVhalStatusMap.at(vhalProperty).vhalValueFloat);
- currentCarPartStatus.localModel =
- rotationAboutPoint(angleInDegree, rotationOp.axis.rotationPoint,
- rotationOp.axis.axisVector);
- currentCarPartStatus.currentModel = appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress = mVhalStatusMap.at(vhalProperty).vhalValueFloat;
- } else {
- float progressDelta = (mCurrentCallTime - mLastCallTime) / rotationOp.animationTime;
- if (progressDelta + currentProgress > 1) {
- float angleInDegree = rotationOp.rotationRange.end;
- currentCarPartStatus.localModel =
- rotationAboutPoint(angleInDegree, rotationOp.axis.rotationPoint,
- rotationOp.axis.axisVector);
- currentCarPartStatus.currentModel =
- appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress = 1.0f;
- } else {
- float anlgeInDegree = getRationalNumber(rotationOp.rotationRange,
- currentProgress + progressDelta);
- currentCarPartStatus.localModel =
- rotationAboutPoint(anlgeInDegree, rotationOp.axis.rotationPoint,
- rotationOp.axis.axisVector);
- currentCarPartStatus.currentModel =
- appendMatrix(currentCarPartStatus.localModel,
- currentCarPartStatus.parentModel);
- currentProgress += progressDelta;
- }
- }
- } else if (rotationOp.type == ROTATION_SPEED) {
- float angleDelta = (mCurrentCallTime - mLastCallTime) *
- getRationalNumber(rotationOp.rotationRange, rotationOp.vhalRange,
- mVhalStatusMap.at(vhalProperty)
- .vhalValueFloat); // here vhalValueFloat unit is
- // radian/ms.
- currentCarPartStatus.localModel =
- appendMat(rotationAboutPoint(angleDelta, rotationOp.axis.rotationPoint,
- rotationOp.axis.axisVector),
- currentCarPartStatus.localModel);
- currentCarPartStatus.currentModel =
- appendMatrix(currentCarPartStatus.localModel, currentCarPartStatus.parentModel);
- currentProgress = 1.0f;
- } else {
- LOG(ERROR) << "Error type of rotation op: " << rotationOp.type;
- }
- }
- if (mUpdatedPartsMap.find(partId) == mUpdatedPartsMap.end()) {
- AnimationParam animationParam(partId);
- animationParam.SetModelMatrix(currentCarPartStatus.currentModel);
- mUpdatedPartsMap.emplace(std::make_pair(partId, animationParam));
- } else { // existing part in the map
- mUpdatedPartsMap.at(partId).SetModelMatrix(currentCarPartStatus.currentModel);
- }
- updateChildrenParts(partId, currentCarPartStatus.currentModel);
-}
-
-std::vector<AnimationParam> AnimationModule::getUpdatedAnimationParams(
- const std::vector<VehiclePropValue>& vehiclePropValue) {
- mLastCallTime = mCurrentCallTime;
- if (!mIsCalled) {
- mIsCalled = true;
- mLastCallTime = (float)elapsedRealtimeNano() / 1e6;
- }
-
- // get current time
- mCurrentCallTime = (float)elapsedRealtimeNano() / 1e6;
-
- // reset mUpdatedPartsMap
- mUpdatedPartsMap.clear();
-
- for (const auto& vhalSignal : vehiclePropValue) {
- // existing vhal signal
- const uint64_t combinedId = getCombinedId(vhalSignal);
- if (mVhalToPartsMap.find(combinedId) != mVhalToPartsMap.end()) {
- const float valueFloat = getVhalValueFloat(vhalSignal);
- if (mVhalStatusMap.find(combinedId) != mVhalStatusMap.end()) {
- mVhalStatusMap.at(combinedId).vhalValueFloat = valueFloat;
- } else {
- mVhalStatusMap.emplace(std::make_pair(combinedId,
- VhalStatus{
- .vhalValueFloat = valueFloat,
- }));
- }
- bool offStatus = 0 == valueFloat;
- for (const auto& eachPart : mVhalToPartsMap.at(combinedId)) {
- mCarPartsStatusMap.at(eachPart).vhalOffMap.at(combinedId) = offStatus;
- }
- }
- }
-
- for (auto& vhalStatus : mVhalStatusMap) {
- // VHAL signal not found in animation
- uint64_t vhalProperty = vhalStatus.first;
- if (mVhalToPartsMap.find(vhalProperty) == mVhalToPartsMap.end()) {
- LOG(WARNING) << "VHAL " << vhalProperty << " not processed.";
- } else { // VHAL signal found
- const auto& partsSet = mVhalToPartsMap.at(vhalProperty);
- for (const auto& partId : partsSet) {
- const auto& animationInfo = mPartsToAnimationMap.at(partId);
- if (animationInfo.gammaOpsMap.find(vhalProperty) !=
- animationInfo.gammaOpsMap.end()) {
- LOG(INFO) << "Processing VHAL " << vhalProperty << " for gamma op.";
- // TODO(b/158244276): add priority check.
- for (const auto& gammaOp : animationInfo.gammaOpsMap.at(vhalProperty)) {
- performGammaOp(partId, vhalProperty, gammaOp);
- }
- }
- if (animationInfo.textureOpsMap.find(vhalProperty) !=
- animationInfo.textureOpsMap.end()) {
- LOG(INFO) << "Processing VHAL " << vhalProperty << " for texture op.";
- LOG(INFO) << "Texture op currently not supported. Skipped.";
- // TODO(b158244721): do texture op.
- }
- if (animationInfo.rotationOpsMap.find(vhalProperty) !=
- animationInfo.rotationOpsMap.end()) {
- LOG(INFO) << "Processing VHAL " << vhalProperty << " for rotation op.";
- for (const auto& rotationOp : animationInfo.rotationOpsMap.at(vhalProperty)) {
- performRotationOp(partId, vhalProperty, rotationOp);
- }
- }
- if (animationInfo.translationOpsMap.find(vhalProperty) !=
- animationInfo.translationOpsMap.end()) {
- LOG(INFO) << "Processing VHAL " << vhalProperty << " for translation op.";
- for (const auto& translationOp :
- animationInfo.translationOpsMap.at(vhalProperty)) {
- performTranslationOp(partId, vhalProperty, translationOp);
- }
- }
- }
- }
- }
-
- std::vector<AnimationParam> output;
- for (auto& updatedPart : mUpdatedPartsMap) {
- output.push_back(updatedPart.second);
- }
- return output;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/AnimationModule.h b/cpp/surround_view/service-impl/AnimationModule.h
deleted file mode 100644
index de8dd35..0000000
--- a/cpp/surround_view/service-impl/AnimationModule.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_ANIMATION_H_
-#define SURROUND_VIEW_SERVICE_IMPL_ANIMATION_H_
-
-#include "IOModuleCommon.h"
-#include "core_lib.h"
-
-#include <utils/SystemClock.h>
-#include <cstdint>
-#include <map>
-#include <set>
-#include <vector>
-
-#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
-
-using namespace ::android::hardware::automotive::vehicle::V2_0;
-using namespace android_auto::surround_view;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Car animation class. It is constructed with textures, animations, and
-// vhal_handler. It automatically updates animation params when
-// GetUpdatedAnimationParams() is called.
-class AnimationModule {
-public:
- // Constructor.
- // |parts| is from I/O module. The key value is part id.
- // |textures| is from I/O module. The key value is texture id.
- // |animations| is from I/O module.
- AnimationModule(const std::map<std::string, CarPart>& partsMap,
- const std::map<std::string, CarTexture>& texturesMap,
- const std::vector<AnimationInfo>& animations);
-
- // Gets Animation parameters with input of VehiclePropValue.
- std::vector<AnimationParam> getUpdatedAnimationParams(
- const std::vector<VehiclePropValue>& vehiclePropValue);
-
-private:
- // Internal car part status.
- struct CarPartStatus {
- // Car part id.
- std::string partId;
-
- // Car part children ids.
- std::vector<std::string> childIds;
-
- // Parent model matrix.
- Mat4x4 parentModel;
-
- // Local model in local coordinate.
- Mat4x4 localModel;
-
- // Current status model matrix in global coordinate with
- // animations combined.
- // current_model = local_model * parent_model;
- Mat4x4 currentModel;
-
- // Gamma parameters.
- float gamma;
-
- // Texture id.
- std::string textureId;
-
- // Internal vhal percentage. Each car part maintain its own copy
- // the vhal percentage.
- // Key value is vhal property (combined with area id).
- std::map<uint64_t, float> vhalProgressMap;
-
- // Vhal off map. Key value is vhal property (combined with area id).
- // Assume off status when vhal value is 0.
- std::map<uint64_t, bool> vhalOffMap;
- };
-
- // Internal Vhal status.
- struct VhalStatus {
- float vhalValueFloat;
- };
-
- // Help function to get vhal to parts map.
- void mapVhalToParts();
-
- // Help function to init car part status for constructor.
- void initCarPartStatus();
-
- // Iteratively update children parts status if partent status is changed.
- void updateChildrenParts(const std::string& partId, const Mat4x4& parentModel);
-
- // Perform gamma opertion for the part with given vhal property.
- void performGammaOp(const std::string& partId, uint64_t vhalProperty, const GammaOp& gammaOp);
-
- // Perform translation opertion for the part with given vhal property.
- void performTranslationOp(const std::string& partId, uint64_t vhalProperty,
- const TranslationOp& translationOp);
-
- // Perform texture opertion for the part with given vhal property.
- // Not implemented yet.
- void performTextureOp(const std::string& partId, uint64_t vhalProperty,
- const TextureOp& textureOp);
-
- // Perform rotation opertion for the part with given vhal property.
- void performRotationOp(const std::string& partId, uint64_t vhalProperty,
- const RotationOp& rotationOp);
-
- // Last call time of GetUpdatedAnimationParams() in millisecond.
- float mLastCallTime;
-
- // Current call time of GetUpdatedAnimationParams() in millisecond.
- float mCurrentCallTime;
-
- // Flag indicating if GetUpdatedAnimationParams() was called before.
- bool mIsCalled;
-
- std::map<std::string, CarPart> mPartsMap;
-
- std::map<std::string, CarTexture> mTexturesMap;
-
- std::vector<AnimationInfo> mAnimations;
-
- std::map<std::string, AnimationInfo> mPartsToAnimationMap;
-
- std::map<uint64_t, VhalStatus> mVhalStatusMap;
-
- std::map<uint64_t, std::set<std::string>> mVhalToPartsMap;
-
- std::map<std::string, CarPartStatus> mCarPartsStatusMap;
-
- std::map<std::string, AnimationParam> mUpdatedPartsMap;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_ANIMATION_H_
diff --git a/cpp/surround_view/service-impl/AnimationModuleTests.cpp b/cpp/surround_view/service-impl/AnimationModuleTests.cpp
deleted file mode 100644
index 5d6e5d5..0000000
--- a/cpp/surround_view/service-impl/AnimationModuleTests.cpp
+++ /dev/null
@@ -1,439 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define LOG_TAG "AnimationModuleTests"
-
-#include "AnimationModule.h"
-#include "MathHelp.h"
-
-#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
-#include <gtest/gtest.h>
-#include <map>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-
-std::map<std::string, CarPart> getSampleCarPartsMap() {
- std::vector<std::string> carFrameChildPartIds{"front_left_door", "front_right_door",
- "front_left_blinker", "front_right_blinker",
- "sun_roof"};
-
- android_auto::surround_view::CarPart frame(std::vector<CarVertex>(),
- android_auto::surround_view::CarMaterial(),
- gMat4Identity, "root", carFrameChildPartIds);
-
- android_auto::surround_view::CarPart frameChild(std::vector<CarVertex>(),
- android_auto::surround_view::CarMaterial(),
- gMat4Identity, "frame",
- std::vector<std::string>());
-
- std::map<std::string, CarPart> sampleCarParts;
- sampleCarParts.emplace(std::make_pair("frame", frame));
- sampleCarParts.emplace(std::make_pair("front_left_door", frameChild));
- sampleCarParts.emplace(std::make_pair("front_right_door", frameChild));
- sampleCarParts.emplace(std::make_pair("front_left_blinker", frameChild));
- sampleCarParts.emplace(std::make_pair("front_right_blinker", frameChild));
- sampleCarParts.emplace(std::make_pair("sun_roof", frameChild));
- return sampleCarParts;
-}
-
-std::vector<AnimationInfo> getSampleAnimations() {
- AnimationInfo frameAnimation = AnimationInfo{
- .partId = "frame",
- .parentId = "root",
- .pose = gMat4Identity,
- };
-
- RotationOp frontLeftDoorRotationOp =
- RotationOp{.vhalProperty = (int64_t)(0x0200 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 | VehicleArea::DOOR)
- << 32 |
- (int64_t)(VehicleArea::DOOR),
- .type = AnimationType::ROTATION_ANGLE,
- .axis =
- RotationAxis{
- .axisVector = std::array<float, 3>{0.0f, 0.0f, 1.0f},
- .rotationPoint = std::array<float, 3>{-1.0f, 0.5f, 0.0f},
- },
- .animationTime = 2000,
- .rotationRange =
- Range{
- .start = 0.0f,
- .end = 90.0f,
- },
- .vhalRange = Range{
- .start = 0.0f,
- .end = (float)INT32_MAX,
- }};
-
- std::map<uint64_t, std::vector<RotationOp>> frontLeftDoorRotationOpsMap;
-
- frontLeftDoorRotationOpsMap.emplace(
- std::make_pair(frontLeftDoorRotationOp.vhalProperty,
- std::vector<RotationOp>{frontLeftDoorRotationOp}));
-
- AnimationInfo frontLeftDoorAnimation = AnimationInfo{
- .partId = "front_left_door",
- .parentId = "frame",
- .pose = gMat4Identity,
- .rotationOpsMap = frontLeftDoorRotationOpsMap,
- };
-
- RotationOp frontRightDoorRotationOp =
- RotationOp{.vhalProperty = (int64_t)(0x0201 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 | VehicleArea::DOOR)
- << 32 |
- (int64_t)(VehicleArea::DOOR),
- .type = AnimationType::ROTATION_ANGLE,
- .axis =
- RotationAxis{
- .axisVector = std::array<float, 3>{0.0f, 0.0f, 1.0f},
- .rotationPoint = std::array<float, 3>{1.0f, 0.5f, 0.0f},
- },
- .animationTime = 2000,
- .rotationRange =
- Range{
- .start = 0.0f,
- .end = -90.0f,
- },
- .vhalRange = Range{
- .start = 0.0f,
- .end = (float)INT32_MAX,
- }};
-
- std::map<uint64_t, std::vector<RotationOp>> frontRightDoorRotationOpsMap;
-
- frontRightDoorRotationOpsMap.emplace(
- std::make_pair(frontRightDoorRotationOp.vhalProperty,
- std::vector<RotationOp>{frontRightDoorRotationOp}));
-
- AnimationInfo frontRightDoorAnimation = AnimationInfo{
- .partId = "front_right_door",
- .parentId = "frame",
- .pose = gMat4Identity,
- .rotationOpsMap = frontRightDoorRotationOpsMap,
- };
-
- GammaOp frontLeftBlinkerGammaOp = GammaOp{
- .vhalProperty = (int64_t)(0x0300 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 | VehicleArea::GLOBAL)
- << 32 |
- (int64_t)(VehicleArea::GLOBAL),
- .type = AnimationType::ADJUST_GAMMA_REPEAT,
- .animationTime = 1000,
- .gammaRange =
- Range{
- .start = 1.0f,
- .end = 0.5f,
- },
- .vhalRange =
- Range{
- .start = 0.0f,
- .end = (float)INT32_MAX,
- },
- };
-
- std::map<uint64_t, std::vector<GammaOp>> frontLeftBlinkerGammaOpsMap;
-
- frontLeftBlinkerGammaOpsMap.emplace(
- std::make_pair(frontLeftBlinkerGammaOp.vhalProperty,
- std::vector<GammaOp>{frontLeftBlinkerGammaOp}));
-
- AnimationInfo frontLeftBlinkerAnimation = AnimationInfo{
- .partId = "front_left_blinker",
- .parentId = "frame",
- .pose = gMat4Identity,
- .gammaOpsMap = frontLeftBlinkerGammaOpsMap,
- };
-
- GammaOp frontRightBlinkerGammaOp = GammaOp{
- .vhalProperty = (int64_t)(0x0301 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 | VehicleArea::GLOBAL)
- << 32 |
- (int64_t)(VehicleArea::GLOBAL),
- .type = AnimationType::ADJUST_GAMMA_REPEAT,
- .animationTime = 1000,
- .gammaRange =
- Range{
- .start = 1.0f,
- .end = 0.5f,
- },
- .vhalRange =
- Range{
- .start = 0.0f,
- .end = (float)INT32_MAX,
- },
- };
-
- std::map<uint64_t, std::vector<GammaOp>> frontRightBlinkerGammaOpsMap;
-
- frontRightBlinkerGammaOpsMap.emplace(
- std::make_pair(frontRightBlinkerGammaOp.vhalProperty,
- std::vector<GammaOp>{frontRightBlinkerGammaOp}));
-
- AnimationInfo frontRightBlinkerAnimation = AnimationInfo{
- .partId = "front_right_blinker",
- .parentId = "frame",
- .pose = gMat4Identity,
- .gammaOpsMap = frontRightBlinkerGammaOpsMap,
- };
-
- TranslationOp sunRoofTranslationOp = TranslationOp{
- .vhalProperty = (int64_t)(0x0400 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 | VehicleArea::GLOBAL)
- << 32 |
- (int64_t)(VehicleArea::GLOBAL),
- .type = AnimationType::TRANSLATION,
- .direction = std::array<float, 3>{0.0f, -1.0f, 0.0f},
- .animationTime = 3000,
- .translationRange =
- Range{
- .start = 0.0f,
- .end = 0.5f,
- },
- .vhalRange =
- Range{
- .start = 0.0f,
- .end = (float)INT32_MAX,
- },
- };
-
- std::map<uint64_t, std::vector<TranslationOp>> sunRoofRotationOpsMap;
- sunRoofRotationOpsMap.emplace(std::make_pair(sunRoofTranslationOp.vhalProperty,
- std::vector<TranslationOp>{sunRoofTranslationOp}));
-
- AnimationInfo sunRoofAnimation = AnimationInfo{
- .partId = "sun_roof",
- .parentId = "frame",
- .pose = gMat4Identity,
- .translationOpsMap = sunRoofRotationOpsMap,
- };
-
- return std::vector<AnimationInfo>{frameAnimation,
- frontLeftDoorAnimation,
- frontRightDoorAnimation,
- frontLeftBlinkerAnimation,
- frontRightBlinkerAnimation,
- sunRoofAnimation};
-}
-
-TEST(AnimationModuleTests, EmptyVhalSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- std::vector<AnimationParam> result =
- animationModule.getUpdatedAnimationParams(std::vector<VehiclePropValue>());
- EXPECT_EQ(result.size(), 0);
-}
-
-TEST(AnimationModuleTests, LeftDoorAnimationOnceSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::DOOR,
- .prop = 0x0200 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::DOOR,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
-}
-
-TEST(AnimationModuleTests, LeftDoorAnimationTenTimesSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- for (int i = 0; i < 10; ++i) {
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::DOOR,
- .prop = 0x0200 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::DOOR,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
- }
-}
-
-TEST(AnimationModuleTests, RightDoorAnimationOnceSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::DOOR,
- .prop = 0x0201 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::DOOR,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
-}
-
-TEST(AnimationModuleTests, RightDoorAnimationTenTimesSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- for (int i = 0; i < 10; ++i) {
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::DOOR,
- .prop = 0x0201 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::DOOR,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
- }
-}
-
-TEST(AnimationModuleTests, LeftBlinkerAnimationOnceSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0300 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
-}
-
-TEST(AnimationModuleTests, LeftBlinkerAnimationTenTimesSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- for (int i = 0; i < 10; ++i) {
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0300 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
- }
-}
-
-TEST(AnimationModuleTests, RightBlinkerAnimationOnceSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0301 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
-}
-
-TEST(AnimationModuleTests, RightBlinkerAnimationTenTimesSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- for (int i = 0; i < 10; ++i) {
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0301 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
- }
-}
-
-TEST(AnimationModuleTests, SunRoofAnimationOnceSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0400 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
-}
-
-TEST(AnimationModuleTests, SunRoofAnimationTenTimesSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- for (int i = 0; i < 10; ++i) {
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0400 | VehiclePropertyGroup::SYSTEM | VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values = std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 1);
- }
-}
-
-TEST(AnimationModuleTests, All5PartsAnimationOnceSuccess) {
- AnimationModule animationModule(getSampleCarPartsMap(), std::map<std::string, CarTexture>(),
- getSampleAnimations());
- std::vector<AnimationParam> result = animationModule.getUpdatedAnimationParams(
- std::vector<VehiclePropValue>{VehiclePropValue{
- .areaId = (int32_t)VehicleArea::DOOR,
- .prop = 0x0200 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 |
- VehicleArea::DOOR,
- .value.int32Values =
- std::vector<int32_t>(1, INT32_MAX),
- },
- VehiclePropValue{
- .areaId = (int32_t)VehicleArea::DOOR,
- .prop = 0x0201 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 |
- VehicleArea::DOOR,
- .value.int32Values =
- std::vector<int32_t>(1, INT32_MAX),
- },
- VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0300 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values =
- std::vector<int32_t>(1, INT32_MAX),
- },
- VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0301 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values =
- std::vector<int32_t>(1, INT32_MAX),
- },
- VehiclePropValue{
- .areaId = (int32_t)VehicleArea::GLOBAL,
- .prop = 0x0400 | VehiclePropertyGroup::SYSTEM |
- VehiclePropertyType::INT32 |
- VehicleArea::GLOBAL,
- .value.int32Values =
- std::vector<int32_t>(1, INT32_MAX),
- }});
- EXPECT_EQ(result.size(), 5);
-}
-
-} // namespace
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/CameraUtils.cpp b/cpp/surround_view/service-impl/CameraUtils.cpp
deleted file mode 100644
index 0dd6226..0000000
--- a/cpp/surround_view/service-impl/CameraUtils.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2020 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 "CameraUtils.h"
-
-#include <android-base/logging.h>
-#include <android/hardware/automotive/evs/1.1/types.h>
-
-#include <math.h>
-
-using namespace android::hardware::automotive::evs::V1_1;
-
-using ::android::sp;
-using ::std::string;
-using ::std::vector;
-using ::std::map;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-bool isLogicalCamera(const camera_metadata_t* metadata) {
- if (metadata == nullptr) {
- // A logical camera device must have a valid camera metadata.
- return false;
- }
-
- // Looking for LOGICAL_MULTI_CAMERA capability from metadata.
- camera_metadata_ro_entry_t entry;
- int rc =
- find_camera_metadata_ro_entry(metadata,
- ANDROID_REQUEST_AVAILABLE_CAPABILITIES,
- &entry);
- if (0 != rc) {
- // No capabilities are found.
- return false;
- }
-
- for (size_t i = 0; i < entry.count; ++i) {
- uint8_t cap = entry.data.u8[i];
- if (cap ==
- ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA) {
- return true;
- }
- }
-
- return false;
-}
-
-vector<string> getPhysicalCameraIds(sp<IEvsCamera> camera) {
- if (camera == nullptr) {
- LOG(WARNING) << __FUNCTION__ << "The EVS camera object is invalid";
- return {};
- }
-
- CameraDesc desc;
- camera->getCameraInfo_1_1([&desc](const CameraDesc& info) {
- desc = info;
- });
-
- vector<string> physicalCameras;
- const camera_metadata_t* metadata =
- reinterpret_cast<camera_metadata_t*>(&desc.metadata[0]);
-
- if (!isLogicalCamera(metadata)) {
- // EVS assumes that the device w/o a valid metadata is a physical
- // device.
- LOG(INFO) << desc.v1.cameraId << " is not a logical camera device.";
- physicalCameras.emplace_back(desc.v1.cameraId);
- return physicalCameras;
- }
-
- // Look for physical camera identifiers
- camera_metadata_ro_entry entry;
- int rc =
- find_camera_metadata_ro_entry(metadata,
- ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS,
- &entry);
- if (rc != 0) {
- LOG(ERROR) << "No physical camera ID is found for "
- << desc.v1.cameraId;
- return {};
- }
-
- const uint8_t* ids = entry.data.u8;
- size_t start = 0;
- for (size_t i = 0; i < entry.count; ++i) {
- if (ids[i] == '\0') {
- if (start != i) {
- string id(reinterpret_cast<const char*>(ids + start));
- physicalCameras.emplace_back(id);
- }
- start = i + 1;
- }
- }
-
- LOG(INFO) << desc.v1.cameraId << " consists of " << physicalCameras.size()
- << " physical camera devices";
- return physicalCameras;
-}
-
-string tagToString(uint32_t tag) {
- switch (tag) {
- case ANDROID_LENS_DISTORTION:
- return "ANDROID_LENS_DISTORTION";
- case ANDROID_LENS_INTRINSIC_CALIBRATION:
- return "ANDROID_LENS_INTRINSIC_CALIBRATION";
- case ANDROID_LENS_POSE_TRANSLATION:
- return "ANDROID_LENS_POSE_TRANSLATION";
- case ANDROID_LENS_POSE_ROTATION:
- return "ANDROID_LENS_POSE_ROTATION";
- default:
- LOG(WARNING) << "Cannot recognize the tag: " << tag;
- return {};
- }
-}
-
-bool getParam(const camera_metadata_t* metadata,
- uint32_t tag,
- int size,
- float* param) {
- camera_metadata_ro_entry_t entry = camera_metadata_ro_entry_t();
- int rc = find_camera_metadata_ro_entry(metadata, tag, &entry);
-
- if (rc != 0) {
- LOG(ERROR) << "No metadata found for " << tagToString(tag);
- return false;
- }
-
- if (entry.count != size || entry.type != TYPE_FLOAT) {
- LOG(ERROR) << "Unexpected size or type for " << tagToString(tag);
- return false;
- }
-
- const float* lensParam = entry.data.f;
- for (int i = 0; i < size; i++) {
- param[i] = lensParam[i];
- }
- return true;
-}
-
-bool getAndroidCameraParams(sp<IEvsCamera> camera,
- const string& cameraId,
- AndroidCameraParams& params) {
- if (camera == nullptr) {
- LOG(WARNING) << __FUNCTION__ << "The EVS camera object is invalid";
- return {};
- }
-
- CameraDesc desc = {};
- camera->getPhysicalCameraInfo(cameraId, [&desc](const CameraDesc& info) {
- desc = info;
- });
-
- if (desc.metadata.size() == 0) {
- LOG(ERROR) << "No metadata found for " << desc.v1.cameraId;
- return false;
- }
-
- const camera_metadata_t* metadata =
- reinterpret_cast<camera_metadata_t*>(&desc.metadata[0]);
-
- // Look for ANDROID_LENS_DISTORTION
- if (!getParam(metadata,
- ANDROID_LENS_DISTORTION,
- kSizeLensDistortion,
- ¶ms.lensDistortion[0])) {
- return false;
- }
-
- // Look for ANDROID_LENS_INTRINSIC_CALIBRATION
- if (!getParam(metadata,
- ANDROID_LENS_INTRINSIC_CALIBRATION,
- kSizeLensIntrinsicCalibration,
- ¶ms.lensIntrinsicCalibration[0])) {
- return false;
- }
-
- // Look for ANDROID_LENS_POSE_TRANSLATION
- if (!getParam(metadata,
- ANDROID_LENS_POSE_TRANSLATION,
- kSizeLensPoseTranslation,
- ¶ms.lensPoseTranslation[0])) {
- return false;
- }
-
- // Look for ANDROID_LENS_POSE_ROTATION
- if (!getParam(metadata,
- ANDROID_LENS_POSE_ROTATION,
- kSizeLensPoseRotation,
- ¶ms.lensPoseRotation[0])) {
- return false;
- }
-
- return true;
-}
-
-vector<SurroundViewCameraParams> convertToSurroundViewCameraParams(
- const map<string, AndroidCameraParams>& androidCameraParamsMap) {
- vector<SurroundViewCameraParams> result;
-
- // TODO(b/156101189): the cameras are in random order now. They need to be
- // sorted based on the camera position info from config file.
- for (const auto& entry : androidCameraParamsMap) {
- SurroundViewCameraParams svParams;
-
- // Android Camera format for intrinsics: [f_x, f_y, c_x, c_y, s]
- //
- // To corelib:
- // SurroundViewCameraParams.intrinsics =
- // [ f_x, s, c_x,
- // 0, f_y, c_y,
- // 0, 0, 1 ];
- const float* intrinsics = &entry.second.lensIntrinsicCalibration[0];
- svParams.intrinsics[0] = intrinsics[0];
- svParams.intrinsics[1] = intrinsics[4];
- svParams.intrinsics[2] = intrinsics[2];
- svParams.intrinsics[3] = 0;
- svParams.intrinsics[4] = intrinsics[1];
- svParams.intrinsics[5] = intrinsics[3];
- svParams.intrinsics[6] = 0;
- svParams.intrinsics[7] = 0;
- svParams.intrinsics[8] = 1;
-
- // Android Camera format for lens distortion:
- // Radial: [kappa_1, kappa_2, kappa_3]
- // Tangential: [kappa_4, kappa_5]
- //
- // To corelib:
- // SurroundViewCameraParams.distortion =
- // [kappa_1, kappa_2, kappa_3, kappa_4];
- const float* distortion = &entry.second.lensDistortion[0];
- svParams.distorion[0] = distortion[0];
- svParams.distorion[1] = distortion[1];
- svParams.distorion[2] = distortion[2];
- svParams.distorion[3] = distortion[3];
-
- // Android Camera format for rotation:
- // quaternion coefficients (x,y,z,w)
- //
- // To corelib:
- // theta = 2 * acos(w)
- // a_x = x / sin(theta/2)
- // a_y = y / sin(theta/2)
- // a_z = z / sin(theta/2)
- // SurroundViewCameraParams.rvec =
- // [theta * a_x, theta * a_y, theta * a_z];
- const float* rotation = &entry.second.lensPoseRotation[0];
- const float theta = 2 * acos(rotation[3]);
- const float a_x = rotation[0] / sin(theta / 2);
- const float a_y = rotation[1] / sin(theta / 2);
- const float a_z = rotation[2] / sin(theta / 2);
- svParams.rvec[0] = theta * a_x;
- svParams.rvec[1] = theta * a_y;
- svParams.rvec[2] = theta * a_z;
-
- // Android Camera format for translation: Translation = (x,y,z)
- //
- // To corelib:
- // SurroundViewCameraParams.tvec = [x, y, z];
- const float* translation = &entry.second.lensPoseTranslation[0];
- svParams.tvec[0] = translation[0];
- svParams.tvec[1] = translation[1];
- svParams.tvec[2] = translation[2];
-
- LOG(INFO) << "Camera parameters for " << entry.first
- << " have been converted to SV core lib format successfully";
- result.emplace_back(svParams);
- }
-
- return result;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
diff --git a/cpp/surround_view/service-impl/CameraUtils.h b/cpp/surround_view/service-impl/CameraUtils.h
deleted file mode 100644
index 1fbc8d4..0000000
--- a/cpp/surround_view/service-impl/CameraUtils.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#pragma once
-
-#include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
-#include <system/camera_metadata.h>
-
-#include <string>
-#include <vector>
-
-#include "core_lib.h"
-
-using ::android::hardware::automotive::evs::V1_1::IEvsCamera;
-using ::android_auto::surround_view::SurroundViewCameraParams;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-const int kSizeLensDistortion = 5;
-const int kSizeLensIntrinsicCalibration = 5;
-const int kSizeLensPoseTranslation = 3;
-const int kSizeLensPoseRotation = 4;
-
-// Camera parameters that the Android Camera team defines.
-struct AndroidCameraParams {
- float lensDistortion[kSizeLensDistortion];
- float lensIntrinsicCalibration[kSizeLensIntrinsicCalibration];
- float lensPoseTranslation[kSizeLensPoseTranslation];
- float lensPoseRotation[kSizeLensPoseRotation];
-};
-
-// Gets the underlying physical camera ids for logical camera.
-// If the given camera is not a logical, its own id will be returned.
-std::vector<std::string> getPhysicalCameraIds(android::sp<IEvsCamera> camera);
-
-// Gets the intrinsic/extrinsic parameters for the given physical camera id.
-// Returns true if the parameters are obtained successfully. Returns false
-// otherwise.
-bool getAndroidCameraParams(android::sp<IEvsCamera> camera,
- const std::string& cameraId,
- AndroidCameraParams& params);
-
-// Converts the camera parameters from Android Camera format into Surround View
-// core lib format.
-std::vector<SurroundViewCameraParams> convertToSurroundViewCameraParams(
- const std::map<std::string, AndroidCameraParams>& androidCameraParamsMap);
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/CarModelConfigReader.cpp b/cpp/surround_view/service-impl/CarModelConfigReader.cpp
deleted file mode 100644
index 7be6cb0..0000000
--- a/cpp/surround_view/service-impl/CarModelConfigReader.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright 2020 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 "CarModelConfigReader.h"
-#include "ConfigReaderUtil.h"
-#include "MathHelp.h"
-#include "core_lib.h"
-
-#include <android-base/logging.h>
-#include <tinyxml2.h>
-#include <sstream>
-#include <string>
-#include <utility>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Macro returning IoStatus::ERROR_READ_ANIMATION if condition evaluates to false.
-#define RETURN_ERROR_STATUS_IF_FALSE(cond) \
- do { \
- if (!(cond)) { \
- return IOStatus::ERROR_READ_ANIMATION; \
- } \
- } while (0)
-
-using tinyxml2::XML_SUCCESS;
-using tinyxml2::XMLDocument;
-using tinyxml2::XMLElement;
-
-namespace {
-
-bool ReadValueHex(const XMLElement* parent, const char* elementName, uint32_t* hex) {
- const XMLElement* element = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &element));
- RETURN_IF_FALSE(ElementHasText(element));
- *hex = std::stoul(element->GetText(), nullptr, 16);
- return true;
-}
-
-bool ReadValueList(const XMLElement* parent, const char* elementName,
- std::vector<std::string>* valueList) {
- valueList->clear();
- for (const XMLElement* elem = parent->FirstChildElement(elementName); elem != nullptr;
- elem = elem->NextSiblingElement(elementName)) {
- RETURN_IF_FALSE(ElementHasText(elem));
- valueList->push_back(std::string(elem->GetText()));
- }
- return true;
-}
-
-// ReadValue for SurroundView2dParams::BlendingType.
-bool ReadAnimationType(const XMLElement* parent, const char* elementName, AnimationType* type) {
- const XMLElement* element = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &element));
- RETURN_IF_FALSE(ElementHasText(element));
- const std::string animationTypeStr(element->GetText());
-
- if (animationTypeStr == "RotationAngle") {
- *type = AnimationType::ROTATION_ANGLE;
- } else if (animationTypeStr == "RotationSpeed") {
- *type = AnimationType::ROTATION_SPEED;
- } else if (animationTypeStr == "Translation") {
- *type = AnimationType::TRANSLATION;
- } else if (animationTypeStr == "SwitchTextureOnce") {
- *type = AnimationType::SWITCH_TEXTURE_ONCE;
- } else if (animationTypeStr == "AdjustGammaOnce") {
- *type = AnimationType::ADJUST_GAMMA_ONCE;
- } else if (animationTypeStr == "SwitchTextureRepeat") {
- *type = AnimationType::SWITCH_TEXTURE_REPEAT;
- } else if (animationTypeStr == "AdjustGammaRepeat") {
- *type = AnimationType::ADJUST_GAMMA_REPEAT;
- } else {
- LOG(ERROR) << "Unknown AnimationType specified: " << animationTypeStr;
- return false;
- }
- return true;
-}
-
-bool ReadRange(const XMLElement* parent, const char* elementName, Range* range) {
- const XMLElement* rangeElem = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &rangeElem));
- {
- RETURN_IF_FALSE(ReadValue(rangeElem, "Start", &range->start));
- RETURN_IF_FALSE(ReadValue(rangeElem, "End", &range->end));
- }
- return true;
-}
-
-bool ReadFloat3(const XMLElement* parent, const char* elementName, std::array<float, 3>* float3) {
- const XMLElement* arrayElem = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &arrayElem));
- {
- RETURN_IF_FALSE(ReadValue(arrayElem, "X", &float3->at(0)));
- RETURN_IF_FALSE(ReadValue(arrayElem, "Y", &float3->at(1)));
- RETURN_IF_FALSE(ReadValue(arrayElem, "Z", &float3->at(2)));
- }
- return true;
-}
-
-// Generic template for reading a animation op, each op type must be specialized.
-template <typename OpType>
-bool ReadOp(const XMLElement* opElem, OpType* op) {
- (void)opElem;
- (void)op;
- LOG(ERROR) << "Unexpected internal error: Op type in not supported.";
- return false;
-}
-
-// Reads vhal property.
-bool ReadVhalProperty(const XMLElement* parent, const char* elementName, uint64_t* vhalProperty) {
- const XMLElement* vhalPropElem = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &vhalPropElem));
- {
- uint32_t propertyId;
- uint32_t areaId;
- RETURN_IF_FALSE(ReadValueHex(vhalPropElem, "PropertyId", &propertyId));
- RETURN_IF_FALSE(ReadValueHex(vhalPropElem, "AreaId", &areaId));
- *vhalProperty = (static_cast<uint64_t>(propertyId) << 32) | areaId;
- }
- return true;
-}
-
-template <>
-bool ReadOp<RotationOp>(const XMLElement* rotationOpElem, RotationOp* rotationOp) {
- RETURN_IF_FALSE(ReadVhalProperty(rotationOpElem, "VhalProperty", &rotationOp->vhalProperty));
-
- RETURN_IF_FALSE(ReadAnimationType(rotationOpElem, "AnimationType", &rotationOp->type));
-
- RETURN_IF_FALSE(ReadFloat3(rotationOpElem, "RotationAxis", &rotationOp->axis.axisVector));
-
- RETURN_IF_FALSE(ReadFloat3(rotationOpElem, "RotationPoint", &rotationOp->axis.rotationPoint));
-
- RETURN_IF_FALSE(
- ReadValue(rotationOpElem, "DefaultRotationValue", &rotationOp->defaultRotationValue));
-
- RETURN_IF_FALSE(ReadValue(rotationOpElem, "AnimationTimeMs", &rotationOp->animationTime));
-
- RETURN_IF_FALSE(ReadRange(rotationOpElem, "RotationRange", &rotationOp->rotationRange));
-
- RETURN_IF_FALSE(ReadRange(rotationOpElem, "VhalRange", &rotationOp->vhalRange));
-
- return true;
-}
-
-template <>
-bool ReadOp<TranslationOp>(const XMLElement* translationOpElem, TranslationOp* translationOp) {
- RETURN_IF_FALSE(
- ReadVhalProperty(translationOpElem, "VhalProperty", &translationOp->vhalProperty));
-
- RETURN_IF_FALSE(ReadAnimationType(translationOpElem, "AnimationType", &translationOp->type));
-
- RETURN_IF_FALSE(ReadFloat3(translationOpElem, "Direction", &translationOp->direction));
-
- RETURN_IF_FALSE(ReadValue(translationOpElem, "DefaultTranslationValue",
- &translationOp->defaultTranslationValue));
-
- RETURN_IF_FALSE(ReadValue(translationOpElem, "AnimationTimeMs", &translationOp->animationTime));
-
- RETURN_IF_FALSE(
- ReadRange(translationOpElem, "TranslationRange", &translationOp->translationRange));
-
- RETURN_IF_FALSE(ReadRange(translationOpElem, "VhalRange", &translationOp->vhalRange));
-
- return true;
-}
-
-template <>
-bool ReadOp<TextureOp>(const XMLElement* textureOpElem, TextureOp* textureOp) {
- RETURN_IF_FALSE(ReadVhalProperty(textureOpElem, "VhalProperty", &textureOp->vhalProperty));
-
- RETURN_IF_FALSE(ReadAnimationType(textureOpElem, "AnimationType", &textureOp->type));
-
- RETURN_IF_FALSE(ReadValue(textureOpElem, "DefaultTexture", &textureOp->defaultTexture));
-
- RETURN_IF_FALSE(ReadValue(textureOpElem, "AnimationTimeMs", &textureOp->animationTime));
-
- RETURN_IF_FALSE(ReadRange(textureOpElem, "TextureRange", &textureOp->textureRange));
-
- RETURN_IF_FALSE(ReadRange(textureOpElem, "VhalRange", &textureOp->vhalRange));
-
- return true;
-}
-
-template <>
-bool ReadOp<GammaOp>(const XMLElement* gammaOpElem, GammaOp* gammaOp) {
- RETURN_IF_FALSE(ReadVhalProperty(gammaOpElem, "VhalProperty", &gammaOp->vhalProperty));
-
- RETURN_IF_FALSE(ReadAnimationType(gammaOpElem, "AnimationType", &gammaOp->type));
-
- RETURN_IF_FALSE(ReadValue(gammaOpElem, "AnimationTimeMs", &gammaOp->animationTime));
-
- RETURN_IF_FALSE(ReadRange(gammaOpElem, "GammaRange", &gammaOp->gammaRange));
-
- RETURN_IF_FALSE(ReadRange(gammaOpElem, "VhalRange", &gammaOp->vhalRange));
-
- return true;
-}
-
-template <typename OpType>
-bool ReadAllOps(const XMLElement* animationElem, const char* elemName,
- std::map<uint64_t, std::vector<OpType>>* mapOps) {
- for (const XMLElement* elem = animationElem->FirstChildElement(elemName); elem != nullptr;
- elem = elem->NextSiblingElement(elemName)) {
- OpType op;
- RETURN_IF_FALSE(ReadOp(elem, &op));
- if (mapOps->find(op.vhalProperty) == mapOps->end()) {
- mapOps->emplace(op.vhalProperty, std::vector<OpType>());
- }
- mapOps->at(op.vhalProperty).push_back(op);
- }
- return true;
-}
-
-bool ReadAnimation(const XMLElement* animationElem, AnimationInfo* animationInfo) {
- RETURN_IF_FALSE(ReadValue(animationElem, "PartId", &animationInfo->partId));
- RETURN_IF_FALSE(ReadValue(animationElem, "ParentPartId", &animationInfo->parentId));
-
- // Child Part Ids (Optional)
- const XMLElement* childPartsElem = nullptr;
- GetElement(animationElem, "ChildParts", &childPartsElem);
- if (childPartsElem != nullptr) {
- RETURN_IF_FALSE(ReadValueList(childPartsElem, "PartId", &animationInfo->childIds));
- }
-
- // Set to the default Identity.
- animationInfo->pose = gMat4Identity;
-
- // All animation operations.
- RETURN_IF_FALSE(ReadAllOps(animationElem, "RotationOp", &animationInfo->rotationOpsMap));
- RETURN_IF_FALSE(ReadAllOps(animationElem, "TranslationOp", &animationInfo->translationOpsMap));
- RETURN_IF_FALSE(ReadAllOps(animationElem, "TextureOp", &animationInfo->textureOpsMap));
- RETURN_IF_FALSE(ReadAllOps(animationElem, "GammaOp", &animationInfo->gammaOpsMap));
- return true;
-}
-
-bool ReadAllAnimations(const XMLElement* rootElem, std::vector<AnimationInfo>* animations) {
- animations->clear();
- // Loop over animation elements.
- for (const XMLElement* elem = rootElem->FirstChildElement("Animation"); elem != nullptr;
- elem = elem->NextSiblingElement("Animation")) {
- AnimationInfo animationInfo;
- RETURN_IF_FALSE(ReadAnimation(elem, &animationInfo));
- animations->push_back(animationInfo);
- }
- return true;
-}
-
-} // namespace
-
-IOStatus ReadCarModelConfig(const std::string& carModelConfigFile,
- AnimationConfig* animationConfig) {
- XMLDocument xmlDoc;
-
- /* load and parse a configuration file */
- xmlDoc.LoadFile(carModelConfigFile.c_str());
- if (xmlDoc.ErrorID() != XML_SUCCESS) {
- LOG(ERROR) << "Failed to load and/or parse a configuration file, " << xmlDoc.ErrorStr();
- return IOStatus::ERROR_READ_ANIMATION;
- }
-
- const XMLElement* rootElem = xmlDoc.RootElement();
- if (strcmp(rootElem->Name(), "SurroundViewCarModelConfig")) {
- LOG(ERROR) << "Config file is not in the required format: " << carModelConfigFile;
- return IOStatus::ERROR_READ_ANIMATION;
- }
-
- // version
- RETURN_ERROR_STATUS_IF_FALSE(ReadValue(rootElem, "Version", &animationConfig->version));
-
- // animations
- RETURN_ERROR_STATUS_IF_FALSE(ReadAllAnimations(rootElem, &animationConfig->animations));
-
- return IOStatus::OK;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/CarModelConfigReader.h b/cpp/surround_view/service-impl/CarModelConfigReader.h
deleted file mode 100644
index c2e9049..0000000
--- a/cpp/surround_view/service-impl/CarModelConfigReader.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_CARMODELCONFIGREADER_H_
-#define SURROUND_VIEW_SERVICE_IMPL_CARMODELCONFIGREADER_H_
-
-#include <string>
-
-#include "IOModuleCommon.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-IOStatus ReadCarModelConfig(const std::string& carModelConfigFile,
- AnimationConfig* animationConfig);
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_CARMODELCONFIGREADER_H_
diff --git a/cpp/surround_view/service-impl/CarModelConfigReaderTests.cpp b/cpp/surround_view/service-impl/CarModelConfigReaderTests.cpp
deleted file mode 100644
index 81f8192..0000000
--- a/cpp/surround_view/service-impl/CarModelConfigReaderTests.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define LOG_TAG "IoModuleTests"
-
-#include "CarModelConfigReader.h"
-
-#include "MathHelp.h"
-#include "core_lib.h"
-
-#include <gtest/gtest.h>
-#include <string>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-
-TEST(CarModelConfigReaderTests, CarModelReadConfigSuccess) {
- AnimationConfig animationConfig;
- EXPECT_EQ(ReadCarModelConfig("/vendor/etc/automotive/sv/sv_sample_car_model_config.xml",
- &animationConfig),
- IOStatus::OK);
-
- EXPECT_EQ(animationConfig.version, "1.0");
-
- ASSERT_EQ(animationConfig.animations.size(), 2);
-
- {
- AnimationInfo doorAnimation = animationConfig.animations.at(0);
- EXPECT_EQ(doorAnimation.partId, "door");
- EXPECT_EQ(doorAnimation.childIds.size(), 1);
- EXPECT_EQ(doorAnimation.pose, gMat4Identity);
-
- EXPECT_EQ(doorAnimation.rotationOpsMap.size(), 1);
- {
- RotationOp rotationOp = (doorAnimation.rotationOpsMap.at(0x16000B0000000001)).at(0);
- EXPECT_EQ(rotationOp.vhalProperty, 0x16000B0000000001);
- EXPECT_EQ(rotationOp.type, AnimationType::ROTATION_ANGLE);
- EXPECT_EQ(rotationOp.animationTime, 2000);
- std::array<float, 3> axis = {0, 0, 1};
- EXPECT_EQ(rotationOp.axis.axisVector, axis);
- std::array<float, 3> point = {0, 0, 0};
- EXPECT_EQ(rotationOp.axis.rotationPoint, point);
- EXPECT_EQ(rotationOp.rotationRange.start, 0.0);
- EXPECT_EQ(rotationOp.rotationRange.end, 90.0);
- EXPECT_EQ(rotationOp.vhalRange.start, 0);
- EXPECT_EQ(rotationOp.vhalRange.end, 0x7FFFFFFF);
- }
- }
-
- {
- AnimationInfo windowAnimation = animationConfig.animations.at(1);
- EXPECT_EQ(windowAnimation.partId, "window");
- EXPECT_EQ(windowAnimation.childIds.size(), 0);
- EXPECT_EQ(windowAnimation.pose, gMat4Identity);
-
- EXPECT_EQ(windowAnimation.translationOpsMap.size(), 1);
- {
- TranslationOp translationOp =
- (windowAnimation.translationOpsMap.at(0x13000BC000000010)).at(0);
- EXPECT_EQ(translationOp.vhalProperty, 0x13000BC000000010);
- EXPECT_EQ(translationOp.type, AnimationType::TRANSLATION);
- EXPECT_EQ(translationOp.animationTime, 2000);
- std::array<float, 3> dir = {0.0, 0.0, -1.0};
- EXPECT_EQ(translationOp.direction, dir);
- EXPECT_EQ(translationOp.defaultTranslationValue, 0.0);
- EXPECT_EQ(translationOp.translationRange.start, 0.0);
- EXPECT_EQ(translationOp.translationRange.end, 1.0);
- EXPECT_EQ(translationOp.vhalRange.start, 0);
- EXPECT_EQ(translationOp.vhalRange.end, 0x7FFFFFFF);
- }
- }
-}
-
-} // namespace
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/ConfigReader.cpp b/cpp/surround_view/service-impl/ConfigReader.cpp
deleted file mode 100644
index cc1c81b..0000000
--- a/cpp/surround_view/service-impl/ConfigReader.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright 2020 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 "ConfigReader.h"
-#include "ConfigReaderUtil.h"
-#include "core_lib.h"
-
-#include <android-base/logging.h>
-#include <tinyxml2.h>
-#include <sstream>
-#include <string>
-#include <utility>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using tinyxml2::XML_SUCCESS;
-using tinyxml2::XMLDocument;
-using tinyxml2::XMLElement;
-
-using android_auto::surround_view::SurroundView2dParams;
-using android_auto::surround_view::SurroundView3dParams;
-
-namespace {
-
-// Macro returning IoStatus::ERROR_CONFIG_FILE_FORMAT if condition evaluates to false.
-#define RETURN_ERROR_STATUS_IF_FALSE(cond) \
- do { \
- if (!(cond)) { \
- return IOStatus::ERROR_CONFIG_FILE_FORMAT; \
- } \
- } while (0)
-
-// ReadValue for SurroundView2dParams::BlendingType.
-bool ReadValue2dBlendType(const XMLElement* parent, const char* elementName,
- SurroundView2dParams::BlendingType* value) {
- const XMLElement* element = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &element));
- RETURN_IF_FALSE(ElementHasText(element));
- const std::string blendingTypeStr(element->GetText());
-
- if (blendingTypeStr == "multiband") {
- *value = SurroundView2dParams::BlendingType::MULTIBAND;
- } else if (blendingTypeStr == "alpha") {
- *value = SurroundView2dParams::BlendingType::ALPHA;
- } else {
- LOG(ERROR) << "Unknown BlendingType specified: " << blendingTypeStr;
- return false;
- }
- return true;
-}
-
-bool ReadSvConfig2d(const XMLElement* parent, SvConfig2d* sv2dConfig) {
- RETURN_IF_FALSE(ReadValue(parent, "Sv2dEnabled", &sv2dConfig->sv2dEnabled));
- if (!sv2dConfig->sv2dEnabled) {
- return true;
- }
-
- SurroundView2dParams* sv2dParams = &sv2dConfig->sv2dParams;
- const XMLElement* param2dElem = nullptr;
- RETURN_IF_FALSE(GetElement(parent, "Sv2dParams", ¶m2dElem));
- {
- // OutputResolution
- const XMLElement* outputResolutionElem = nullptr;
- RETURN_IF_FALSE(GetElement(param2dElem, "OutputResolution", &outputResolutionElem));
- {
- RETURN_IF_FALSE(
- ReadValue(outputResolutionElem, "Width", &sv2dParams->resolution.width));
- RETURN_IF_FALSE(
- ReadValue(outputResolutionElem, "Height", &sv2dParams->resolution.height));
- }
-
- // GroundMapping
- const XMLElement* groundMappingElem = nullptr;
- RETURN_IF_FALSE(GetElement(param2dElem, "GroundMapping", &groundMappingElem));
- {
- RETURN_IF_FALSE(
- ReadValue(groundMappingElem, "Width", &sv2dParams->physical_size.width));
- RETURN_IF_FALSE(
- ReadValue(groundMappingElem, "Height", &sv2dParams->physical_size.height));
-
- // Center
- const XMLElement* centerElem = nullptr;
- RETURN_IF_FALSE(GetElement(groundMappingElem, "Center", ¢erElem));
- {
- RETURN_IF_FALSE(ReadValue(centerElem, "X", &sv2dParams->physical_center.x));
- RETURN_IF_FALSE(ReadValue(centerElem, "Y", &sv2dParams->physical_center.y));
- }
- }
-
- // Car Bounding Box
- const XMLElement* carBoundingBoxElem = nullptr;
- RETURN_IF_FALSE(GetElement(param2dElem, "CarBoundingBox", &carBoundingBoxElem));
- {
- RETURN_IF_FALSE(
- ReadValue(carBoundingBoxElem, "Width", &sv2dConfig->carBoundingBox.width));
- RETURN_IF_FALSE(
- ReadValue(carBoundingBoxElem, "Height", &sv2dConfig->carBoundingBox.height));
-
- // Center
- const XMLElement* leftTopCornerElem = nullptr;
- RETURN_IF_FALSE(GetElement(carBoundingBoxElem, "LeftTopCorner", &leftTopCornerElem));
- {
- RETURN_IF_FALSE(ReadValue(leftTopCornerElem, "X", &sv2dConfig->carBoundingBox.x));
- RETURN_IF_FALSE(ReadValue(leftTopCornerElem, "Y", &sv2dConfig->carBoundingBox.y));
- }
- }
-
- // Blending type
- const XMLElement* blendingTypeElem = nullptr;
- RETURN_IF_FALSE(GetElement(param2dElem, "BlendingType", &blendingTypeElem));
- {
- RETURN_IF_FALSE(ReadValue2dBlendType(blendingTypeElem, "HighQuality",
- &sv2dParams->high_quality_blending));
- RETURN_IF_FALSE(ReadValue2dBlendType(blendingTypeElem, "LowQuality",
- &sv2dParams->low_quality_blending));
- }
-
- // GPU Acceleration enabled or not
- RETURN_IF_FALSE(ReadValue(param2dElem, "GpuAccelerationEnabled",
- &sv2dParams->gpu_acceleration_enabled));
- }
- return true;
-}
-
-bool ReadSvConfig3d(const XMLElement* parent, SvConfig3d* sv3dConfig) {
- RETURN_IF_FALSE(ReadValue(parent, "Sv3dEnabled", &sv3dConfig->sv3dEnabled));
- if (!sv3dConfig->sv3dEnabled) {
- return true;
- }
- RETURN_IF_FALSE(ReadValue(parent, "Sv3dAnimationsEnabled", &sv3dConfig->sv3dAnimationsEnabled));
-
- if (sv3dConfig->sv3dAnimationsEnabled) {
- RETURN_IF_FALSE(ReadValue(parent, "CarModelConfigFile", &sv3dConfig->carModelConfigFile));
- }
-
- RETURN_IF_FALSE(ReadValue(parent, "CarModelObjFile", &sv3dConfig->carModelObjFile));
-
- SurroundView3dParams* sv3dParams = &sv3dConfig->sv3dParams;
- const XMLElement* param3dElem = nullptr;
- RETURN_IF_FALSE(GetElement(parent, "Sv3dParams", ¶m3dElem));
- {
- // OutputResolution
- const XMLElement* outputResolutionElem = nullptr;
- RETURN_IF_FALSE(GetElement(param3dElem, "OutputResolution", &outputResolutionElem));
- {
- RETURN_IF_FALSE(
- ReadValue(outputResolutionElem, "Width", &sv3dParams->resolution.width));
- RETURN_IF_FALSE(
- ReadValue(outputResolutionElem, "Height", &sv3dParams->resolution.height));
- }
-
- // Bowl Params
- const XMLElement* bowlParamsElem = nullptr;
- RETURN_IF_FALSE(GetElement(param3dElem, "BowlParams", &bowlParamsElem));
- {
- RETURN_IF_FALSE(ReadValue(bowlParamsElem, "PlaneRadius", &sv3dParams->plane_radius));
- RETURN_IF_FALSE(
- ReadValue(bowlParamsElem, "PlaneDivisions", &sv3dParams->plane_divisions));
- RETURN_IF_FALSE(ReadValue(bowlParamsElem, "CurveHeight", &sv3dParams->curve_height));
- RETURN_IF_FALSE(
- ReadValue(bowlParamsElem, "CurveDivisions", &sv3dParams->curve_divisions));
- RETURN_IF_FALSE(
- ReadValue(bowlParamsElem, "AngularDivisions", &sv3dParams->angular_divisions));
- RETURN_IF_FALSE(
- ReadValue(bowlParamsElem, "CurveCoefficient", &sv3dParams->curve_coefficient));
- }
-
- // High Quality details
- const XMLElement* highQualityDetailsElem = nullptr;
- GetElement(param3dElem, "HighQualityDetails", &highQualityDetailsElem);
- {
- RETURN_IF_FALSE(ReadValue(highQualityDetailsElem, "Shadows",
- &sv3dParams->high_details_shadows));
- RETURN_IF_FALSE(ReadValue(highQualityDetailsElem, "Reflections",
- &sv3dParams->high_details_reflections));
- }
- }
- return true;
-}
-
-bool ReadCameraConfig(const XMLElement* parent, CameraConfig* cameraConfig) {
- const XMLElement* cameraConfigElem = nullptr;
- RETURN_IF_FALSE(GetElement(parent, "CameraConfig", &cameraConfigElem));
- {
- // Evs Group Id
- RETURN_IF_FALSE(ReadValue(cameraConfigElem, "EvsGroupId", &cameraConfig->evsGroupId));
-
- // Evs Cameras Ids
- const XMLElement* cameraIdsElem = nullptr;
- RETURN_IF_FALSE(GetElement(cameraConfigElem, "EvsCameraIds", &cameraIdsElem));
- {
- cameraConfig->evsCameraIds.resize(4);
- RETURN_IF_FALSE(ReadValue(cameraIdsElem, "Front", &cameraConfig->evsCameraIds[0]));
- RETURN_IF_FALSE(ReadValue(cameraIdsElem, "Right", &cameraConfig->evsCameraIds[1]));
- RETURN_IF_FALSE(ReadValue(cameraIdsElem, "Rear", &cameraConfig->evsCameraIds[2]));
- RETURN_IF_FALSE(ReadValue(cameraIdsElem, "Left", &cameraConfig->evsCameraIds[3]));
- }
-
- // Masks (Optional).
- const XMLElement* masksElem = nullptr;
- GetElement(cameraConfigElem, "Masks", &masksElem);
- if (masksElem != nullptr) {
- cameraConfig->maskFilenames.resize(4);
- RETURN_IF_FALSE(ReadValue(masksElem, "Front", &cameraConfig->maskFilenames[0]));
- RETURN_IF_FALSE(ReadValue(masksElem, "Right", &cameraConfig->maskFilenames[1]));
- RETURN_IF_FALSE(ReadValue(masksElem, "Rear", &cameraConfig->maskFilenames[2]));
- RETURN_IF_FALSE(ReadValue(masksElem, "Left", &cameraConfig->maskFilenames[3]));
- }
- }
- return true;
-}
-
-} // namespace
-
-IOStatus ReadSurroundViewConfig(const std::string& configFile, SurroundViewConfig* svConfig) {
- XMLDocument xmlDoc;
-
- // load and parse a configuration file
- xmlDoc.LoadFile(configFile.c_str());
- if (xmlDoc.ErrorID() != XML_SUCCESS) {
- LOG(ERROR) << "Failed to load and/or parse a configuration file, " << xmlDoc.ErrorStr();
- return IOStatus::ERROR_READ_CONFIG_FILE;
- }
-
- const XMLElement* rootElem = xmlDoc.RootElement();
- if (strcmp(rootElem->Name(), "SurroundViewConfig")) {
- LOG(ERROR) << "Config file is not in the required format: " << configFile;
- return IOStatus::ERROR_READ_CONFIG_FILE;
- }
-
- // version
- RETURN_ERROR_STATUS_IF_FALSE(ReadValue(rootElem, "Version", &svConfig->version));
-
- // CameraConfig
- RETURN_ERROR_STATUS_IF_FALSE(ReadCameraConfig(rootElem, &svConfig->cameraConfig));
-
- // Surround View 2D
- RETURN_ERROR_STATUS_IF_FALSE(ReadSvConfig2d(rootElem, &svConfig->sv2dConfig));
-
- // Surround View 3D
- RETURN_ERROR_STATUS_IF_FALSE(ReadSvConfig3d(rootElem, &svConfig->sv3dConfig));
-
- return IOStatus::OK;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/ConfigReader.h b/cpp/surround_view/service-impl/ConfigReader.h
deleted file mode 100644
index 7bdbe2a..0000000
--- a/cpp/surround_view/service-impl/ConfigReader.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_CONFIGREADER_H_
-#define SURROUND_VIEW_SERVICE_IMPL_CONFIGREADER_H_
-
-#include <string>
-
-#include "IOModuleCommon.h"
-#include "core_lib.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Parses the surround view config xml into struct SurroundViewConfig.
-IOStatus ReadSurroundViewConfig(const std::string& configFile, SurroundViewConfig* svConfig);
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_CONFIGREADER_H_
diff --git a/cpp/surround_view/service-impl/ConfigReaderTests.cpp b/cpp/surround_view/service-impl/ConfigReaderTests.cpp
deleted file mode 100644
index 7d12322..0000000
--- a/cpp/surround_view/service-impl/ConfigReaderTests.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define LOG_TAG "ConfigReaderTests"
-
-#include "ConfigReader.h"
-
-#include "core_lib.h"
-
-#include <gtest/gtest.h>
-#include <string>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-
-using android_auto::surround_view::SurroundView2dParams;
-using android_auto::surround_view::SurroundView3dParams;
-
-TEST(ConfigReaderTests, ReadConfigSuccess) {
- SurroundViewConfig svConfig;
- EXPECT_EQ(ReadSurroundViewConfig("/vendor/etc/automotive/sv/sv_sample_config.xml", &svConfig),
- IOStatus::OK);
-
- EXPECT_EQ(svConfig.version, "1.0");
-
- // Camera config
- EXPECT_EQ(svConfig.cameraConfig.evsGroupId, "v4l2loopback_group0");
-
- // Camera Ids
- EXPECT_EQ(svConfig.cameraConfig.evsCameraIds[0], "/dev/video60");
- EXPECT_EQ(svConfig.cameraConfig.evsCameraIds[1], "/dev/video61");
- EXPECT_EQ(svConfig.cameraConfig.evsCameraIds[2], "/dev/video62");
- EXPECT_EQ(svConfig.cameraConfig.evsCameraIds[3], "/dev/video63");
-
- // Masks
- EXPECT_EQ(svConfig.cameraConfig.maskFilenames.size(), 4);
- EXPECT_EQ(svConfig.cameraConfig.maskFilenames[0], "/vendor/etc/automotive/sv/mask_front.png");
- EXPECT_EQ(svConfig.cameraConfig.maskFilenames[1], "/vendor/etc/automotive/sv/mask_right.png");
- EXPECT_EQ(svConfig.cameraConfig.maskFilenames[2], "/vendor/etc/automotive/sv/mask_rear.png");
- EXPECT_EQ(svConfig.cameraConfig.maskFilenames[3], "/vendor/etc/automotive/sv/mask_left.png");
-
- // Surround view 2D
- EXPECT_EQ(svConfig.sv2dConfig.sv2dEnabled, true);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.resolution.width, 768);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.resolution.height, 1024);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.physical_size.width, 9.0);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.physical_size.height, 12.0);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.physical_center.x, 0.0);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.physical_center.y, 0.0);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.gpu_acceleration_enabled, false);
- EXPECT_EQ(svConfig.sv2dConfig.carBoundingBox.width, 2.0);
- EXPECT_EQ(svConfig.sv2dConfig.carBoundingBox.height, 3.0);
- EXPECT_EQ(svConfig.sv2dConfig.carBoundingBox.x, 1.0);
- EXPECT_EQ(svConfig.sv2dConfig.carBoundingBox.y, 1.5);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.high_quality_blending,
- SurroundView2dParams::BlendingType::MULTIBAND);
- EXPECT_EQ(svConfig.sv2dConfig.sv2dParams.low_quality_blending,
- SurroundView2dParams::BlendingType::ALPHA);
-
- // Surround view 3D
- EXPECT_EQ(svConfig.sv3dConfig.sv3dEnabled, true);
- EXPECT_NE(svConfig.sv3dConfig.carModelConfigFile, "");
- EXPECT_NE(svConfig.sv3dConfig.carModelObjFile, "");
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.plane_radius, 8.0);
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.plane_divisions, 50);
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.curve_height, 6.0);
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.curve_divisions, 50);
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.angular_divisions, 90);
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.curve_coefficient, 3.0);
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.high_details_shadows, true);
- EXPECT_EQ(svConfig.sv3dConfig.sv3dParams.high_details_reflections, true);
-}
-
-} // namespace
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/ConfigReaderUtil.cpp b/cpp/surround_view/service-impl/ConfigReaderUtil.cpp
deleted file mode 100644
index e5fe7c4..0000000
--- a/cpp/surround_view/service-impl/ConfigReaderUtil.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2020 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 "ConfigReaderUtil.h"
-
-#include <android-base/logging.h>
-#include <tinyxml2.h>
-#include <utility>
-
-#include "core_lib.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using tinyxml2::XML_SUCCESS;
-using tinyxml2::XMLElement;
-
-bool ElementHasText(const XMLElement* element) {
- if (element->GetText() == "") {
- LOG(ERROR) << "Expected element to have text: " << element->Name();
- return false;
- }
- return true;
-}
-
-bool GetElement(const XMLElement* parent, const char* elementName, XMLElement const** element) {
- *element = parent->FirstChildElement(elementName);
- if (*element == nullptr) {
- LOG(ERROR) << "Expected element '" << elementName << "' in parent '" << parent->Name()
- << "' not found";
- return false;
- }
- return true;
-}
-
-bool ReadValue(const XMLElement* parent, const char* elementName, bool* value) {
- const XMLElement* element = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &element));
- if (element->QueryBoolText(value) != XML_SUCCESS) {
- LOG(ERROR) << "Failed to read valid boolean value from: " << element->Name();
- return false;
- }
- return true;
-}
-
-bool ReadValue(const XMLElement* parent, const char* elementName, std::string* value) {
- const XMLElement* element = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &element));
- RETURN_IF_FALSE(ElementHasText(element));
- *value = std::string(element->GetText());
- return true;
-}
-
-bool ReadValue(const XMLElement* parent, const char* elementName, float* value) {
- const XMLElement* element = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &element));
- if (element->QueryFloatText(value) != XML_SUCCESS) {
- LOG(ERROR) << "Failed to read valid float value from: " << element->Name();
- return false;
- }
- return true;
-}
-
-bool ReadValue(const XMLElement* parent, const char* elementName, int* value) {
- const XMLElement* element = nullptr;
- RETURN_IF_FALSE(GetElement(parent, elementName, &element));
- if (element->QueryIntText(value) != XML_SUCCESS) {
- LOG(ERROR) << "Failed to read valid int value from: " << element->Name();
- return false;
- }
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/ConfigReaderUtil.h b/cpp/surround_view/service-impl/ConfigReaderUtil.h
deleted file mode 100644
index 030cc0f..0000000
--- a/cpp/surround_view/service-impl/ConfigReaderUtil.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_CONFIGREADERUTIL_H_
-#define SURROUND_VIEW_SERVICE_IMPL_CONFIGREADERUTIL_H_
-
-#include <tinyxml2.h>
-#include <sstream>
-#include <string>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Macro returning false if condition evaluates to false.
-#define RETURN_IF_FALSE(cond) \
- do { \
- if (!(cond)) { \
- return false; \
- } \
- } while (0)
-
-// Returns true if element has text.
-bool ElementHasText(const tinyxml2::XMLElement* element);
-
-// Gets a xml element from the parent element, returns false if not found.
-bool GetElement(const tinyxml2::XMLElement* parent, const char* elementName,
- tinyxml2::XMLElement const** element);
-
-// Reads a boolean value from a element, returns false if not found.
-bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, bool* value);
-
-// Reads a string value from a element, returns false if not found.
-bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, std::string* value);
-
-// Reads a float value from a element, returns false if not found.
-bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, float* value);
-
-// Reads a int value from a element, returns false if not found.
-bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, int* value);
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_CONFIGREADERUTIL_H_
diff --git a/cpp/surround_view/service-impl/IOModule.cpp b/cpp/surround_view/service-impl/IOModule.cpp
deleted file mode 100644
index e1af11a..0000000
--- a/cpp/surround_view/service-impl/IOModule.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2020 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 <android-base/logging.h>
-
-#include "CarModelConfigReader.h"
-#include "ConfigReader.h"
-#include "IOModule.h"
-#include "ObjReader.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-IOModule::IOModule(const std::string& svConfigFile) :
- mSvConfigFile(svConfigFile), mIsInitialized(false) {}
-
-IOStatus IOModule::initialize() {
- if (mIsInitialized) {
- LOG(INFO) << "IOModule is already initialized.";
- return IOStatus::OK;
- }
-
- SurroundViewConfig svConfig;
- IOStatus status;
- if ((status = ReadSurroundViewConfig(mSvConfigFile, &svConfig)) != IOStatus::OK) {
- LOG(ERROR) << "ReadSurroundViewConfig() failed.";
- return status;
- }
-
- mIOModuleConfig.cameraConfig = svConfig.cameraConfig;
- mIOModuleConfig.sv2dConfig = svConfig.sv2dConfig;
- mIOModuleConfig.sv3dConfig = svConfig.sv3dConfig;
-
- if (mIOModuleConfig.sv3dConfig.sv3dEnabled) {
- // Read obj and mtl files.
- if (!ReadObjFromFile(svConfig.sv3dConfig.carModelObjFile,
- &mIOModuleConfig.carModelConfig.carModel.partsMap)) {
- LOG(ERROR) << "ReadObjFromFile() failed.";
- return IOStatus::ERROR_READ_CAR_MODEL;
- }
- // Read animations.
- if (mIOModuleConfig.sv3dConfig.sv3dAnimationsEnabled) {
- if ((status = ReadCarModelConfig(svConfig.sv3dConfig.carModelConfigFile,
- &mIOModuleConfig.carModelConfig.animationConfig)) !=
- IOStatus::OK) {
- LOG(ERROR) << "ReadObjFromFile() failed.";
- return status;
- }
- }
- }
- mIsInitialized = true;
- return IOStatus::OK;
-}
-
-bool IOModule::getConfig(IOModuleConfig* ioModuleConfig) {
- if (!mIsInitialized) {
- LOG(ERROR) << "IOModule not initalized.";
- return false;
- }
- *ioModuleConfig = mIOModuleConfig;
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/IOModule.h b/cpp/surround_view/service-impl/IOModule.h
deleted file mode 100644
index 2e19dc5..0000000
--- a/cpp/surround_view/service-impl/IOModule.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_IOMODULE_H_
-#define SURROUND_VIEW_SERVICE_IMPL_IOMODULE_H_
-
-#include "IOModuleCommon.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// I/O Module class processing all I/O related operations.
-class IOModule {
-public:
- // Constructor with file name( and path) of config file.
- IOModule(const std::string& svConfigFile);
-
- // Reads all config files and stores parsed results in mIOModuleConfig.
- IOStatus initialize();
-
- // Gets config data read from files. initialize must be called this.
- bool getConfig(IOModuleConfig* ioModuleConfig);
-
-private:
- // Config string filename.
- std::string mSvConfigFile;
-
- // Indicates initialize success/fail.
- bool mIsInitialized;
-
- // Stores the parsed config.
- IOModuleConfig mIOModuleConfig;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-#endif // SURROUND_VIEW_SERVICE_IMPL_IOMODULE_H_
diff --git a/cpp/surround_view/service-impl/IOModuleCommon.h b/cpp/surround_view/service-impl/IOModuleCommon.h
deleted file mode 100644
index 5550fd5..0000000
--- a/cpp/surround_view/service-impl/IOModuleCommon.h
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_IOMODULECOMMON_H_
-#define SURROUND_VIEW_SERVICE_IMPL_IOMODULECOMMON_H_
-
-#include <string>
-
-#include "core_lib.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Struct for camera related configurations.
-// Note: Does not include camera intrinsics and extrinsics, these are specified in EVS metadata.
-struct CameraConfig {
- // Id of logical group containing surronnd view cameras.
- std::string evsGroupId;
-
- // List of evs camera Ids in order: front, right, rear, left.
- std::vector<std::string> evsCameraIds;
-
- // In order: front, right, rear, left.
- std::vector<std::string> maskFilenames;
-};
-
-struct SvConfig2d {
- // Bool flag for surround view 2d.
- bool sv2dEnabled;
-
- // Surround view 2d params.
- android_auto::surround_view::SurroundView2dParams sv2dParams;
-
- // Car model bounding box for 2d surround view.
- // To be moved into sv 2d params.
- android_auto::surround_view::BoundingBox carBoundingBox;
-};
-
-struct SvConfig3d {
- // Bool flag for enabling/disabling surround view 3d.
- bool sv3dEnabled;
-
- // Bool flag for enabling/disabling animations.
- bool sv3dAnimationsEnabled;
-
- // Car model config file.
- std::string carModelConfigFile;
-
- // Car model obj file.
- std::string carModelObjFile;
-
- // Surround view 3d params.
- android_auto::surround_view::SurroundView3dParams sv3dParams;
-};
-
-// Main struct in which surround view config is parsed into.
-struct SurroundViewConfig {
- // Version info.
- std::string version;
-
- // Camera config.
- CameraConfig cameraConfig;
-
- // Surround view 2d config.
- SvConfig2d sv2dConfig;
-
- // Surround view 3d config.
- SvConfig3d sv3dConfig;
-};
-
-struct Range {
- // Range start.
- // Start value may be greater than end value.
- float start;
-
- // Range end.
- float end;
-};
-
-// Rotation axis
-struct RotationAxis {
- // Unit axis direction vector.
- std::array<float, 3> axisVector;
-
- // Rotate about this point.
- std::array<float, 3> rotationPoint;
-};
-
-enum AnimationType {
- // Rotate a part about an axis from a start to end angle.
- ROTATION_ANGLE = 0,
-
- // Continuously rotate a part about an axis by a specified angular speed.
- ROTATION_SPEED = 1,
-
- // Linearly translates a part from one point to another.
- TRANSLATION = 2,
-
- // Switch to another texture once.
- SWITCH_TEXTURE_ONCE = 3,
-
- // Adjust the brightness of the texture once.
- ADJUST_GAMMA_ONCE = 4,
-
- // Repeatedly toggle between two textures.
- SWITCH_TEXTURE_REPEAT = 5,
-
- // Repeatedly toggle between two gamma values.
- ADJUST_GAMMA_REPEAT = 6,
-};
-
-// Rotation operation
-struct RotationOp {
- // VHAL signal to trigger operation.
- uint64_t vhalProperty;
-
- // Rotation operation type.
- AnimationType type;
-
- // Rotation axis.
- RotationAxis axis;
-
- // Default rotation (angle/speed) value.
- // It is used for default rotation when the signal is on while vhal_range is
- // not provided.
- float defaultRotationValue;
-
- // Default animation time elapsed to finish the rotation operation.
- // It is ignored if VHAL provides continuous signal value.
- float animationTime;
-
- // physical rotation range with start mapped to vhal_range start and
- // end mapped to vhal_range end.
- Range rotationRange;
-
- // VHAL signal range.
- // Un-supported types: STRING, BYTES and VEC
- // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal
- // VehiclePropertyType
- Range vhalRange;
-};
-
-// Translation operation.
-struct TranslationOp {
- // VHAL signal to trigger operation.
- uint64_t vhalProperty;
-
- // Translation operation type.
- AnimationType type;
-
- // Unit direction vector.
- std::array<float, 3> direction;
-
- // Default translation value.
- // It is used for default translation when the signal is on while vhal_range
- // is not provided.
- float defaultTranslationValue;
-
- // Default animation time elapsed to finish the texture operation.
- // It is ignored if VHAL provides continuous signal value.
- float animationTime;
-
- // Physical translation range with start mapped to vhal_range start and
- // end mapped to vhal_range end.
- Range translationRange;
-
- // VHAL signal range.
- // Un-supported types: STRING, BYTES and VEC
- // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal
- // VehiclePropertyType
- Range vhalRange;
-};
-
-// Texture operation.
-struct TextureOp {
- // VHAL signal to trigger operation.
- uint64_t vhalProperty;
-
- // Texture operation type.
- AnimationType type;
-
- // Default texture id.
- // It is used as default texture when the signal is on while vhal_range is
- // not provided.
- std::string defaultTexture;
-
- // Default animation time elapsed to finish the texture operation.
- // Unit is milliseconds.
- // If the animation time is specified, the vhal_property is assumed to be
- // on/off type.
- // It is ignored if it is equal or less than zero and vhal_property is
- // assumed to provide continuous value.
- int animationTime;
-
- // texture range mapped to texture_ids[i].first.
- Range textureRange;
-
- // VHAL signal range.
- // Un-supported types: STRING, BYTES and VEC
- // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal
- // VehiclePropertyType
- Range vhalRange;
-
- // Texture ids for switching textures.
- // Applicable for animation types: kSwitchTextureOnce and
- // kSwitchTextureRepeated
- // 0 - n-1
- std::vector<std::pair<float, std::string>> textureIds;
-};
-
-// Gamma operation.
-struct GammaOp {
- // VHAL signal to trigger operation.
- uint64_t vhalProperty;
-
- // Texture operation type.
- // Applicable for animation types: kAdjustGammaOnce and kAdjustGammaRepeat.
- AnimationType type;
-
- // Default animation time elapsed to finish the gamma operation.
- // Unit is milliseconds.
- // If the animation time is specified, the vhal_property is assumed to be
- // on/off type.
- // It is ignored if it is equal or less than zero and vhal_property is
- // assumed to provide continuous value.
- int animationTime;
-
- // Gamma range with start mapped to vhal_range start and
- // end mapped to vhal_range end.
- Range gammaRange;
-
- // VHAL signal range.
- // Un-supported types: STRING, BYTES and VEC
- // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal
- // VehiclePropertyType
- Range vhalRange;
-};
-
-// Animation info of a car part
-struct AnimationInfo {
- // Car animation part id(name). It is a unique id.
- std::string partId;
-
- // Car part parent name.
- std::string parentId;
-
- // List of child Ids.
- std::vector<std::string> childIds;
-
- // Car part pose w.r.t parent's coordinate.
- android_auto::surround_view::Mat4x4 pose;
-
- // VHAL priority from high [0] to low [n-1]. Only VHALs specified in the
- // vector have priority.
- std::vector<uint64_t> vhalPriority;
-
- // TODO(b/158245554): simplify xxOpsMap data structs.
- // Map of gamma operations. Key value is VHAL property.
- std::map<uint64_t, std::vector<GammaOp>> gammaOpsMap;
-
- // Map of texture operations. Key value is VHAL property.
- std::map<uint64_t, std::vector<TextureOp>> textureOpsMap;
-
- // Map of rotation operations. Key value is VHAL property.
- // Multiple rotation ops are supported and will be simultaneously animated in
- // order if their rotation axis are different and rotation points are the
- // same.
- std::map<uint64_t, std::vector<RotationOp>> rotationOpsMap;
-
- // Map of translation operations. Key value is VHAL property.
- std::map<uint64_t, std::vector<TranslationOp>> translationOpsMap;
-};
-
-// Main struct in which surround view car model config is parsed into.
-struct AnimationConfig {
- std::string version;
-
- std::vector<AnimationInfo> animations;
-};
-
-// Car model.
-struct CarModel {
- // Car model parts map.
- std::map<std::string, android_auto::surround_view::CarPart> partsMap;
-
- // Car testures map.
- std::map<std::string, android_auto::surround_view::CarTexture> texturesMap;
-};
-
-struct CarModelConfig {
- CarModel carModel;
-
- AnimationConfig animationConfig;
-};
-
-struct IOModuleConfig {
- // Camera config.
- CameraConfig cameraConfig;
-
- // Surround view 2d config.
- SvConfig2d sv2dConfig;
-
- // Surround view 3d config.
- SvConfig3d sv3dConfig;
-
- // Car model config.
- CarModelConfig carModelConfig;
-};
-
-enum IOStatus : uint8_t {
- // OK ststus. ALL fields read and parsed.
- OK = 0,
-
- // Error status. Cannot read the config file (config file missing or not
- // accessible)
- ERROR_READ_CONFIG_FILE = 1,
-
- // Error ststus. Config file format doesn't match.
- ERROR_CONFIG_FILE_FORMAT = 2,
-
- // Warning status. Read car model (obj, mtl) error. Either the files are
- // missing or wrong format.
- ERROR_READ_CAR_MODEL = 3,
-
- // Warning status. Read animation config file error. Either the file is
- // missing or wrong format.
- ERROR_READ_ANIMATION = 4,
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_IOMODULECOMMON_H_
diff --git a/cpp/surround_view/service-impl/MathHelp.h b/cpp/surround_view/service-impl/MathHelp.h
deleted file mode 100644
index 6623594..0000000
--- a/cpp/surround_view/service-impl/MathHelp.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_MATH_HELP_H_
-#define SURROUND_VIEW_SERVICE_IMPL_MATH_HELP_H_
-
-#include "Matrix4x4.h"
-#include "core_lib.h"
-
-#include <android-base/logging.h>
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using android_auto::surround_view::Mat4x4;
-
-const int gMat4Size = 4 * 4 * sizeof(float);
-
-const Mat4x4 gMat4Identity = {1, 0, 0, /*tx=*/0.0, 0, 1, 0, /*ty=*/0,
- 0, 0, 1, /*tz=*/0.0, 0, 0, 0, 1};
-
-inline float degToRad(float angleInDegrees) {
- return 1.0f * angleInDegrees / 180 * M_PI;
-}
-
-typedef std::array<float, 3> VectorT;
-typedef std::array<float, 4> HomVectorT;
-typedef Matrix4x4<float> HomMatrixT;
-
-// Create a Translation matrix.
-inline HomMatrixT translationMatrix(const VectorT& v) {
- HomMatrixT m = HomMatrixT::identity();
- m.setRow(3, HomVectorT{v[0], v[1], v[2], 1});
- return m;
-}
-
-// Create a Rotation matrix.
-inline HomMatrixT rotationMatrix(const VectorT& v, float angle, int orientation) {
- const float c = cos(angle);
- const float s = orientation * sin(angle);
- const float t = 1 - c;
- const float tx = t * v[0];
- const float ty = t * v[1];
- const float tz = t * v[2];
- return HomMatrixT(tx * v[0] + c, tx * v[1] + s * v[2], tx * v[2] - s * v[1], 0,
- tx * v[1] - s * v[2], ty * v[1] + c, ty * v[2] + s * v[0], 0,
- tx * v[2] + s * v[1], ty * v[2] - s * v[0], tz * v[2] + c, 0, 0, 0, 0, 1);
-}
-
-inline Mat4x4 toMat4x4(const Matrix4x4F& matrix4x4F) {
- Mat4x4 mat4x4;
- memcpy(&mat4x4[0], matrix4x4F.transpose().data(), gMat4Size);
- return mat4x4;
-}
-
-inline Matrix4x4F toMatrix4x4F(const Mat4x4& mat4x4) {
- Matrix4x4F matrix4x4F;
- memcpy(matrix4x4F.data(), &mat4x4[0], gMat4Size);
-
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- if (matrix4x4F(i, j) != mat4x4[i * 4 + j]) {
- LOG(ERROR) << "Matrix error";
- }
- }
- }
- return matrix4x4F.transpose();
-}
-
-// Create a Rotation Matrix, around a unit vector by a ccw angle.
-inline Mat4x4 rotationMatrix(float angleInDegrees, const VectorT& axis) {
- return toMat4x4(rotationMatrix(axis, degToRad(angleInDegrees), 1));
-}
-
-inline Mat4x4 appendRotation(float angleInDegrees, const VectorT& axis, const Mat4x4& mat4) {
- return toMat4x4(toMatrix4x4F(mat4) * rotationMatrix(axis, degToRad(angleInDegrees), 1));
-}
-
-// Append mat_l * mat_r;
-inline Mat4x4 appendMat(const Mat4x4& matL, const Mat4x4& matR) {
- return toMat4x4(toMatrix4x4F(matL) * toMatrix4x4F(matR));
-}
-
-// Rotate about a point about a unit vector.
-inline Mat4x4 rotationAboutPoint(float angleInDegrees, const VectorT& point, const VectorT& axis) {
- VectorT pointInv = point;
- pointInv[0] *= -1;
- pointInv[1] *= -1;
- pointInv[2] *= -1;
- return toMat4x4(translationMatrix(pointInv) *
- rotationMatrix(axis, degToRad(angleInDegrees), 1) * translationMatrix(point));
-}
-
-inline Mat4x4 translationMatrixToMat4x4(const VectorT& translation) {
- return toMat4x4(translationMatrix(translation));
-}
-
-inline Mat4x4 appendTranslation(const VectorT& translation, const Mat4x4& mat4) {
- return toMat4x4(toMatrix4x4F(mat4) * translationMatrix(translation));
-}
-
-inline Mat4x4 appendMatrix(const Mat4x4& deltaMatrix, const Mat4x4& currentMatrix) {
- return toMat4x4(toMatrix4x4F(deltaMatrix) * toMatrix4x4F(currentMatrix));
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_MATH_HELP_H_
diff --git a/cpp/surround_view/service-impl/Matrix4x4.h b/cpp/surround_view/service-impl/Matrix4x4.h
deleted file mode 100644
index 8854e69..0000000
--- a/cpp/surround_view/service-impl/Matrix4x4.h
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_MATRIX4X4_H_
-#define SURROUND_VIEW_SERVICE_IMPL_MATRIX4X4_H_
-
-#include <array>
-#include <cassert>
-#include <cmath>
-#include <iosfwd>
-
-template <class VType>
-class Matrix4x4 {
-private:
- VType m[4][4];
-
-public:
- typedef Matrix4x4<VType> Self;
- typedef VType BaseType;
- typedef std::array<VType, 4> MVector;
-
- // Initialize the matrix to 0
- Matrix4x4() {
- m[0][3] = m[0][2] = m[0][1] = m[0][0] = VType();
- m[1][3] = m[1][2] = m[1][1] = m[1][0] = VType();
- m[2][3] = m[2][2] = m[2][1] = m[2][0] = VType();
- m[3][3] = m[3][2] = m[3][1] = m[3][0] = VType();
- }
-
- // Explicitly set every element on construction
- Matrix4x4(const VType& m00, const VType& m01, const VType& m02, const VType& m03,
- const VType& m10, const VType& m11, const VType& m12, const VType& m13,
- const VType& m20, const VType& m21, const VType& m22, const VType& m23,
- const VType& m30, const VType& m31, const VType& m32, const VType& m33) {
- m[0][0] = m00;
- m[0][1] = m01;
- m[0][2] = m02;
- m[0][3] = m03;
-
- m[1][0] = m10;
- m[1][1] = m11;
- m[1][2] = m12;
- m[1][3] = m13;
-
- m[2][0] = m20;
- m[2][1] = m21;
- m[2][2] = m22;
- m[2][3] = m23;
-
- m[3][0] = m30;
- m[3][1] = m31;
- m[3][2] = m32;
- m[3][3] = m33;
- }
-
- // Casting constructor
- template <class VType2>
- static Matrix4x4 cast(const Matrix4x4<VType2>& mb) {
- return Matrix4x4(static_cast<VType>(mb(0, 0)), static_cast<VType>(mb(0, 1)),
- static_cast<VType>(mb(0, 2)), static_cast<VType>(mb(0, 3)),
- static_cast<VType>(mb(1, 0)), static_cast<VType>(mb(1, 1)),
- static_cast<VType>(mb(1, 2)), static_cast<VType>(mb(1, 3)),
- static_cast<VType>(mb(2, 0)), static_cast<VType>(mb(2, 1)),
- static_cast<VType>(mb(2, 2)), static_cast<VType>(mb(2, 3)),
- static_cast<VType>(mb(3, 0)), static_cast<VType>(mb(3, 1)),
- static_cast<VType>(mb(3, 2)), static_cast<VType>(mb(3, 3)));
- }
-
- // Change the value of all the coefficients of the matrix
- inline Matrix4x4& set(const VType& m00, const VType& m01, const VType& m02, const VType& m03,
- const VType& m10, const VType& m11, const VType& m12, const VType& m13,
- const VType& m20, const VType& m21, const VType& m22, const VType& m23,
- const VType& m30, const VType& m31, const VType& m32, const VType& m33) {
- m[0][0] = m00;
- m[0][1] = m01;
- m[0][2] = m02;
- m[0][3] = m03;
-
- m[1][0] = m10;
- m[1][1] = m11;
- m[1][2] = m12;
- m[1][3] = m13;
-
- m[2][0] = m20;
- m[2][1] = m21;
- m[2][2] = m22;
- m[2][3] = m23;
-
- m[3][0] = m30;
- m[3][1] = m31;
- m[3][2] = m32;
- m[3][3] = m33;
- return (*this);
- }
-
- // Matrix addition
- inline Matrix4x4& operator+=(const Matrix4x4& addFrom) {
- m[0][0] += addFrom.m[0][0];
- m[0][1] += addFrom.m[0][1];
- m[0][2] += addFrom.m[0][2];
- m[0][3] += addFrom.m[0][3];
-
- m[1][0] += addFrom.m[1][0];
- m[1][1] += addFrom.m[1][1];
- m[1][2] += addFrom.m[1][2];
- m[1][3] += addFrom.m[1][3];
-
- m[2][0] += addFrom.m[2][0];
- m[2][1] += addFrom.m[2][1];
- m[2][2] += addFrom.m[2][2];
- m[2][3] += addFrom.m[2][3];
-
- m[3][0] += addFrom.m[3][0];
- m[3][1] += addFrom.m[3][1];
- m[3][2] += addFrom.m[3][2];
- m[3][3] += addFrom.m[3][3];
- return (*this);
- }
-
- // Matrix subtration
- inline Matrix4x4& operator-=(const Matrix4x4& subFrom) {
- m[0][0] -= subFrom.m[0][0];
- m[0][1] -= subFrom.m[0][1];
- m[0][2] -= subFrom.m[0][2];
- m[0][3] -= subFrom.m[0][3];
-
- m[1][0] -= subFrom.m[1][0];
- m[1][1] -= subFrom.m[1][1];
- m[1][2] -= subFrom.m[1][2];
- m[1][3] -= subFrom.m[1][3];
-
- m[2][0] -= subFrom.m[2][0];
- m[2][1] -= subFrom.m[2][1];
- m[2][2] -= subFrom.m[2][2];
- m[2][3] -= subFrom.m[2][3];
-
- m[3][0] -= subFrom.m[3][0];
- m[3][1] -= subFrom.m[3][1];
- m[3][2] -= subFrom.m[3][2];
- m[3][3] -= subFrom.m[3][3];
- return (*this);
- }
-
- // Matrix multiplication by a scalar
- inline Matrix4x4& operator*=(const VType& k) {
- m[0][0] *= k;
- m[0][1] *= k;
- m[0][2] *= k;
- m[0][3] *= k;
-
- m[1][0] *= k;
- m[1][1] *= k;
- m[1][2] *= k;
- m[1][3] *= k;
-
- m[2][0] *= k;
- m[2][1] *= k;
- m[2][2] *= k;
- m[2][3] *= k;
-
- m[3][0] *= k;
- m[3][1] *= k;
- m[3][2] *= k;
- m[3][3] *= k;
- return (*this);
- }
-
- // Matrix addition
- inline Matrix4x4 operator+(const Matrix4x4& mb) const { return Matrix4x4(*this) += mb; }
-
- // Matrix subtraction
- inline Matrix4x4 operator-(const Matrix4x4& mb) const { return Matrix4x4(*this) -= mb; }
-
- // Change the sign of all the coefficients in the matrix
- friend inline Matrix4x4 operator-(const Matrix4x4& vb) {
- return Matrix4x4(-vb.m[0][0], -vb.m[0][1], -vb.m[0][2], -vb.m[0][3], -vb.m[1][0],
- -vb.m[1][1], -vb.m[1][2], -vb.m[1][3], -vb.m[2][0], -vb.m[2][1],
- -vb.m[2][2], -vb.m[2][3], -vb.m[3][0], -vb.m[3][1], -vb.m[3][2],
- -vb.m[3][3]);
- }
-
- // Matrix multiplication by a scalar
- inline Matrix4x4 operator*(const VType& k) const { return Matrix4x4(*this) *= k; }
-
- // Multiplication by a scaler
- friend inline Matrix4x4 operator*(const VType& k, const Matrix4x4& mb) {
- return Matrix4x4(mb) * k;
- }
-
- // Matrix multiplication
- friend Matrix4x4 operator*(const Matrix4x4& a, const Matrix4x4& b) {
- return Matrix4x4::fromCols(a * b.col(0), a * b.col(1), a * b.col(2), a * b.col(3));
- }
-
- // Multiplication of a matrix by a vector
- friend MVector operator*(const Matrix4x4& a, const MVector& b) {
- return MVector{dotProd(a.row(0), b), dotProd(a.row(1), b), dotProd(a.row(2), b),
- dotProd(a.row(3), b)};
- }
-
- // Return the trace of the matrix
- inline VType trace() const { return m[0][0] + m[1][1] + m[2][2] + m[3][3]; }
-
- // Return a pointer to the data array for interface with other libraries
- // like opencv
- VType* data() { return reinterpret_cast<VType*>(m); }
- const VType* data() const { return reinterpret_cast<const VType*>(m); }
-
- // Return matrix element (i,j) with 0<=i<=3 0<=j<=3
- inline VType& operator()(const int i, const int j) {
- assert(i >= 0);
- assert(i < 4);
- assert(j >= 0);
- assert(j < 4);
- return m[i][j];
- }
-
- inline VType operator()(const int i, const int j) const {
- assert(i >= 0);
- assert(i < 4);
- assert(j >= 0);
- assert(j < 4);
- return m[i][j];
- }
-
- // Return matrix element (i/4,i%4) with 0<=i<=15 (access concatenated rows).
- inline VType& operator[](const int i) {
- assert(i >= 0);
- assert(i < 16);
- return reinterpret_cast<VType*>(m)[i];
- }
- inline VType operator[](const int i) const {
- assert(i >= 0);
- assert(i < 16);
- return reinterpret_cast<const VType*>(m)[i];
- }
-
- // Return the transposed matrix
- inline Matrix4x4 transpose() const {
- return Matrix4x4(m[0][0], m[1][0], m[2][0], m[3][0], m[0][1], m[1][1], m[2][1], m[3][1],
- m[0][2], m[1][2], m[2][2], m[3][2], m[0][3], m[1][3], m[2][3], m[3][3]);
- }
-
- // Returns the transpose of the matrix of the cofactors.
- // (Useful for inversion for example.)
- inline Matrix4x4 comatrixTransposed() const {
- const auto cof = [this](unsigned int row, unsigned int col) {
- unsigned int r0 = (row + 1) % 4;
- unsigned int r1 = (row + 2) % 4;
- unsigned int r2 = (row + 3) % 4;
- unsigned int c0 = (col + 1) % 4;
- unsigned int c1 = (col + 2) % 4;
- unsigned int c2 = (col + 3) % 4;
-
- VType minor = m[r0][c0] * (m[r1][c1] * m[r2][c2] - m[r2][c1] * m[r1][c2]) -
- m[r1][c0] * (m[r0][c1] * m[r2][c2] - m[r2][c1] * m[r0][c2]) +
- m[r2][c0] * (m[r0][c1] * m[r1][c2] - m[r1][c1] * m[r0][c2]);
- return (row + col) & 1 ? -minor : minor;
- };
-
- // Transpose
- return Matrix4x4(cof(0, 0), cof(1, 0), cof(2, 0), cof(3, 0), cof(0, 1), cof(1, 1),
- cof(2, 1), cof(3, 1), cof(0, 2), cof(1, 2), cof(2, 2), cof(3, 2),
- cof(0, 3), cof(1, 3), cof(2, 3), cof(3, 3));
- }
-
- // Return dot production of two the vectors
- static inline VType dotProd(const MVector& lhs, const MVector& rhs) {
- return lhs[0] * rhs[0] + lhs[1] * rhs[1] + lhs[2] * rhs[2] + lhs[3] * rhs[3];
- }
-
- // Return the 4D vector at row i
- inline MVector row(const int i) const {
- assert(i >= 0);
- assert(i < 4);
- return MVector{m[i][0], m[i][1], m[i][2], m[i][3]};
- }
-
- // Return the 4D vector at col i
- inline MVector col(const int i) const {
- assert(i >= 0);
- assert(i < 4);
- return MVector{m[0][i], m[1][i], m[2][i], m[3][i]};
- }
-
- // Create a matrix from 4 row vectors
- static inline Matrix4x4 fromRows(const MVector& v1, const MVector& v2, const MVector& v3,
- const MVector& v4) {
- return Matrix4x4(v1[0], v1[1], v1[2], v1[3], v2[0], v2[1], v2[2], v2[3], v3[0], v3[1],
- v3[2], v3[3], v4[0], v4[1], v4[2], v4[3]);
- }
-
- // Create a matrix from 3 column vectors
- static inline Matrix4x4 fromCols(const MVector& v1, const MVector& v2, const MVector& v3,
- const MVector& v4) {
- return Matrix4x4(v1[0], v2[0], v3[0], v4[0], v1[1], v2[1], v3[1], v4[1], v1[2], v2[2],
- v3[2], v4[2], v1[3], v2[3], v3[3], v4[3]);
- }
-
- // Set the vector in row i to be v1
- void setRow(int i, const MVector& v1) {
- assert(i >= 0);
- assert(i < 4);
- m[i][0] = v1[0];
- m[i][1] = v1[1];
- m[i][2] = v1[2];
- m[i][3] = v1[3];
- }
-
- // Set the vector in column i to be v1
- void setCol(int i, const MVector& v1) {
- assert(i >= 0);
- assert(i < 4);
- m[0][i] = v1[0];
- m[1][i] = v1[1];
- m[2][i] = v1[2];
- m[3][i] = v1[3];
- }
-
- // Return the identity matrix
- static inline Matrix4x4 identity() {
- return Matrix4x4(VType(1), VType(), VType(), VType(), VType(), VType(1), VType(), VType(),
- VType(), VType(), VType(1), VType(), VType(), VType(), VType(), VType(1));
- }
-
- // Return a matrix full of zeros
- static inline Matrix4x4 zero() { return Matrix4x4(); }
-
- // Return a diagonal matrix with the coefficients in v
- static inline Matrix4x4 diagonal(const MVector& v) {
- return Matrix4x4(v[0], VType(), VType(), VType(), //
- VType(), v[1], VType(), VType(), //
- VType(), VType(), v[2], VType(), //
- VType(), VType(), VType(), v[3]);
- }
-
- // Return the matrix vvT
- static Matrix4x4 sym4(const MVector& v) {
- return Matrix4x4(v[0] * v[0], v[0] * v[1], v[0] * v[2], v[0] * v[3], v[1] * v[0],
- v[1] * v[1], v[1] * v[2], v[1] * v[3], v[2] * v[0], v[2] * v[1],
- v[2] * v[2], v[2] * v[3], v[3] * v[0], v[3] * v[1], v[3] * v[2],
- v[3] * v[3]);
- }
-
- // Return the Frobenius norm of the matrix: sqrt(sum(aij^2))
- VType frobeniusNorm() const {
- VType sum = VType();
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- sum += m[i][j] * m[i][j];
- }
- }
- return std::sqrt(sum);
- }
-
- // Return true is one of the elements of the matrix is NaN
- bool isNaN() const {
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- if (isnan(m[i][j])) {
- return true;
- }
- }
- }
- return false;
- }
-
- friend bool operator==(const Matrix4x4& a, const Matrix4x4& b) {
- return a.m[0][0] == b.m[0][0] && a.m[0][1] == b.m[0][1] && a.m[0][2] == b.m[0][2] &&
- a.m[0][3] == b.m[0][3] && a.m[1][0] == b.m[1][0] && a.m[1][1] == b.m[1][1] &&
- a.m[1][2] == b.m[1][2] && a.m[1][3] == b.m[1][3] && a.m[2][0] == b.m[2][0] &&
- a.m[2][1] == b.m[2][1] && a.m[2][2] == b.m[2][2] && a.m[2][3] == b.m[2][3] &&
- a.m[3][0] == b.m[3][0] && a.m[3][1] == b.m[3][1] && a.m[3][2] == b.m[3][2] &&
- a.m[3][3] == b.m[3][3];
- }
-
- friend bool operator!=(const Matrix4x4& a, const Matrix4x4& b) { return !(a == b); }
-};
-
-typedef Matrix4x4<int> Matrix4x4I;
-typedef Matrix4x4<float> Matrix4x4F;
-typedef Matrix4x4<double> Matrix4x4D;
-
-#endif // #ifndef SURROUND_VIEW_SERVICE_IMPL_MATRIX4X4_H_
diff --git a/cpp/surround_view/service-impl/MtlReader.cpp b/cpp/surround_view/service-impl/MtlReader.cpp
deleted file mode 100644
index 7caccec..0000000
--- a/cpp/surround_view/service-impl/MtlReader.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright 2020 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 "MtlReader.h"
-
-#include <android-base/logging.h>
-#include <cstdio>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-namespace {
-
-constexpr int kCharBufferSize = 128;
-
-void ReadFloat3(FILE* file, float* value) {
- float temp[3];
- int res = fscanf(file, "%f %f %f", &temp[0], &temp[1], &temp[2]);
- 3 == res ? std::memcpy(value, temp, 3 * sizeof(float)) : nullptr;
-}
-
-void ReadFloat(FILE* file, float* value) {
- float temp;
- int res = fscanf(file, "%f", &temp);
- *value = res > 0 ? temp : -1;
-}
-
-void ReadInt(FILE* file, int* value) {
- int temp;
- int res = fscanf(file, "%d", &temp);
- *value = res > 0 ? temp : -1;
-}
-
-void ReadString(FILE* file, std::string* value) {
- char temp[kCharBufferSize];
- fscanf(file, "%s", temp);
- *value = temp;
-}
-} // namespace
-
-bool ReadMtlFromFile(const std::string& mtlFilename,
- std::map<std::string, MtlConfigParams>* params) {
- FILE* file = fopen(mtlFilename.c_str(), "r");
- if (!file) {
- LOG(ERROR) << "Failed to open mtl file: " << mtlFilename;
- return false;
- }
-
- std::string currentConfig;
- while (true) {
- char lineHeader[kCharBufferSize];
- // read the first word of the line
- int res = fscanf(file, "%s", lineHeader);
-
- if (res == EOF) {
- break; // EOF = End Of File. Quit the loop.
- }
-
- if (strcmp(lineHeader, "#") == 0) {
- fgets(lineHeader, sizeof(lineHeader), file);
- continue;
- }
- if (strcmp(lineHeader, "newmtl") == 0) {
- res = fscanf(file, "%s", lineHeader);
- if (params->find(lineHeader) != params->end()) {
- fclose(file);
- LOG(ERROR) << "Duplicated params of : " << lineHeader[0];
- return false;
- }
- currentConfig = lineHeader;
- continue;
- }
-
- if (strcmp(lineHeader, "Ns") == 0) {
- ReadFloat(file, &((*params)[currentConfig].ns));
- continue;
- }
- if (strcmp(lineHeader, "Ni") == 0) {
- ReadFloat(file, &((*params)[currentConfig].ni));
- continue;
- }
- if (strcmp(lineHeader, "d") == 0) {
- ReadFloat(file, &((*params)[currentConfig].d));
- continue;
- }
- if (strcmp(lineHeader, "Tr") == 0) {
- ReadFloat(file, &((*params)[currentConfig].tr));
- continue;
- }
- if (strcmp(lineHeader, "Tf") == 0) {
- ReadFloat3(file, (*params)[currentConfig].tf);
- continue;
- }
- if (strcmp(lineHeader, "illum") == 0) {
- ReadInt(file, &((*params)[currentConfig].illum));
- continue;
- }
- if (strcmp(lineHeader, "Ka") == 0) {
- ReadFloat3(file, (*params)[currentConfig].ka);
- continue;
- }
- if (strcmp(lineHeader, "Kd") == 0) {
- ReadFloat3(file, (*params)[currentConfig].kd);
- continue;
- }
- if (strcmp(lineHeader, "Ks") == 0) {
- ReadFloat3(file, (*params)[currentConfig].ks);
- continue;
- }
- if (strcmp(lineHeader, "Ke") == 0) {
- ReadFloat3(file, (*params)[currentConfig].ke);
- continue;
- }
- if (strcmp(lineHeader, "map_bump") == 0) {
- ReadString(file, &((*params)[currentConfig].mapBump));
- continue;
- }
- if (strcmp(lineHeader, "bump") == 0) {
- ReadString(file, &((*params)[currentConfig].bump));
- continue;
- }
- if (strcmp(lineHeader, "map_Ka") == 0) {
- ReadString(file, &((*params)[currentConfig].mapKa));
- continue;
- }
- if (strcmp(lineHeader, "map_Kd") == 0) {
- ReadString(file, &((*params)[currentConfig].mapKd));
- continue;
- }
- if (strcmp(lineHeader, "map_Ks") == 0) {
- ReadString(file, &((*params)[currentConfig].mapKs));
- continue;
- } else {
- LOG(WARNING) << "Unknown tag " << lineHeader << ". Skipped";
- fgets(lineHeader, sizeof(lineHeader), file);
- continue;
- }
- }
-
- fclose(file);
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/MtlReader.h b/cpp/surround_view/service-impl/MtlReader.h
deleted file mode 100644
index 3e19876..0000000
--- a/cpp/surround_view/service-impl/MtlReader.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_MTLREADER_H_
-#define SURROUND_VIEW_SERVICE_IMPL_MTLREADER_H_
-
-#include <map>
-#include <string>
-
-#include "core_lib.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Mtl defined params.
-struct MtlConfigParams {
- // Ns exponent
- // Specifies the specular exponent for the current material. This defines
- // the focus of the specular highlight.
- // Ns values normally range from 0 to 1000.
- float ns = -1;
-
- // optical_density
- // Specifies the optical density for the surface. This is also known as
- // index of refraction.
- // "optical_density" is the value for the optical density. The values can
- // range from 0.001 to 10. A value of 1.0 means that light does not bend
- // as it passes through an object. Increasing the optical_density
- // increases the amount of bending. Glass has an index of refraction of
- // about 1.5. Values of less than 1.0 produce bizarre results and are not
- // recommended.
- float ni = -1;
-
- // d defines the non-transparency of the material to be alpha.
- // The default is 1.0 (not transparent at all).
- // The quantities d and Tr are the opposites of each other.
- float d = -1;
-
- // The Tr statement specifies the transparency of the material to be alpha.
- // The default is 0.0 (not transparent at all).
- // The quantities d and Tr are the opposites of each other,
- float tr = -1;
-
- // The Tf statement specifies the transmission filter using RGB values.
- // "r g b" are the values for the red, green, and blue components of the
- // atmosphere. The g and b arguments are optional. If only r is
- // specified, then g, and b are assumed to be equal to r. The r g b values
- // are normally in the range of 0.0 to 1.0. Values outside this range
- // increase or decrease the relectivity accordingly.
- float tf[3] = {-1, -1, -1};
-
- // illum_#
- // The "illum" statement specifies the illumination model to use in the
- // material. Illumination models are mathematical equations that represent
- // various material lighting and shading effects.
- //
- // "illum_#"can be a number from 0 to 10. The illumination models are
- // summarized below;
- //
- // Illumination Properties that are turned on in the
- // model Property Editor
- //
- // 0 Color on and Ambient off
- // 1 Color on and Ambient on
- // 2 Highlight on
- // 3 Reflection on and Ray trace on
- // 4 Transparency: Glass on
- // Reflection: Ray trace on
- // 5 Reflection: Fresnel on and Ray trace on
- // 6 Transparency: Refraction on
- // Reflection: Fresnel off and Ray trace on
- // 7 Transparency: Refraction on
- // Reflection: Fresnel on and Ray trace on
- // 8 Reflection on and Ray trace off
- // 9 Transparency: Glass on
- // Reflection: Ray trace off
- // 10 Casts shadows onto invisible surfaces
- int illum = -1;
-
- // The Ka statement specifies the ambient reflectivity using RGB values.
- // "r g b" are the values for the red, green, and blue components of the
- // color. The g and b arguments are optional. If only r is specified,
- // then g, and b are assumed to be equal to r. The r g b values are
- // normally in the range of 0.0 to 1.0. Values outside this range increase
- // or decrease the relectivity accordingly.
- float ka[3] = {-1, -1, -1};
-
- // The Kd statement specifies the diffuse reflectivity using RGB values.
- // "r g b" are the values for the red, green, and blue components of the
- // atmosphere. The g and b arguments are optional. If only r is
- // specified, then g, and b are assumed to be equal to r. The r g b values
- // are normally in the range of 0.0 to 1.0. Values outside this range
- // increase or decrease the relectivity accordingly.
- float kd[3] = {-1, -1, -1};
-
- // The Ks statement specifies the specular reflectivity using RGB values.
- // "r g b" are the values for the red, green, and blue components of the
- // atmosphere. The g and b arguments are optional. If only r is
- // specified, then g, and b are assumed to be equal to r. The r g b values
- // are normally in the range of 0.0 to 1.0. Values outside this range
- // increase or decrease the relectivity accordingly.
- float ks[3] = {-1, -1, -1};
-
- // Emissive coeficient. It goes together with ambient, diffuse and specular
- // and represents the amount of light emitted by the material.
- float ke[3] = {-1, -1, -1};
-
- // Specifies that a color texture file or color procedural texture file is
- // linked to the specular reflectivity of the material. During rendering,
- // the map_Ks value is multiplied by the Ks value.
- std::string mapKs;
-
- // Specifies that a color texture file or a color procedural texture file
- // is applied to the ambient reflectivity of the material. During
- // rendering, the "map_Ka" value is multiplied by the "Ka" value.
- std::string mapKa;
-
- // Specifies that a color texture file or color procedural texture file is
- // linked to the diffuse reflectivity of the material. During rendering,
- // the map_Kd value is multiplied by the Kd value.
- std::string mapKd;
-
- // Same as bump
- std::string mapBump;
-
- // Specifies that a bump texture file or a bump procedural texture file is
- // linked to the material.
- std::string bump;
-
- MtlConfigParams& operator=(const MtlConfigParams& rhs) {
- ns = rhs.ns;
- ni = rhs.ni;
- d = rhs.d;
- tr = rhs.tr;
- std::memcpy(tf, rhs.tf, 3 * sizeof(float));
- illum = rhs.illum;
- std::memcpy(ka, rhs.ka, 3 * sizeof(float));
- std::memcpy(kd, rhs.kd, 3 * sizeof(float));
- std::memcpy(ks, rhs.ks, 3 * sizeof(float));
- std::memcpy(ke, rhs.ke, 3 * sizeof(float));
- mapKs = rhs.mapKs;
- mapKa = rhs.mapKa;
- mapKd = rhs.mapKd;
- mapBump = rhs.mapBump;
- bump = rhs.bump;
-
- return *this;
- }
-};
-
-// Reads mtl file associated with obj file.
-// |filename| is the full path and name of the obj file.
-bool ReadMtlFromFile(const std::string& mtlFilename,
- std::map<std::string, MtlConfigParams>* params);
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_MTLREADER_H_
diff --git a/cpp/surround_view/service-impl/ObjReader.cpp b/cpp/surround_view/service-impl/ObjReader.cpp
deleted file mode 100644
index dcb1973..0000000
--- a/cpp/surround_view/service-impl/ObjReader.cpp
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright 2020 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 "ObjReader.h"
-
-#include <array>
-#include <cstdio>
-#include <filesystem>
-#include <vector>
-
-#include "MtlReader.h"
-#include "core_lib.h"
-
-#include <android-base/logging.h>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using android_auto::surround_view::CarMaterial;
-using android_auto::surround_view::CarVertex;
-
-namespace {
-
-constexpr int kNumberOfVerticesPerFace = 3;
-constexpr int kNumberOfAxes = 3;
-constexpr int kCharBufferSize = 128;
-
-const std::array<float, 16> kMat4Identity = {
- /*row 0*/ 1, 0, 0, 0,
- /*row 1*/ 0, 1, 0, 0,
- /*row 2*/ 0, 0, 1, 0,
- /*row 3*/ 0, 0, 0, 1};
-
-// Copies face vertices parsed from obj to car vertices.
-void CopyFaceToCarVertex(const std::vector<std::array<float, kNumberOfAxes>>& currentVertices,
- const std::vector<std::array<float, kNumberOfAxes>>& currentTextures,
- const std::vector<std::array<float, kNumberOfAxes>>& currentNormals,
- int vertexId, int textureId, int normalId, CarVertex* carVertex) {
- std::memcpy(carVertex->pos.data(), currentVertices[vertexId - 1].data(),
- currentVertices[vertexId - 1].size() * sizeof(float));
-
- if (textureId != -1) {
- std::memcpy(carVertex->tex_coord.data(), currentTextures[textureId - 1].data(),
- 2 * sizeof(float));
- // Set texture coodinates as invalid.
- carVertex->tex_coord = {-1.0, -1.0};
- }
-
- std::memcpy(carVertex->normal.data(), currentNormals[normalId - 1].data(),
- currentNormals[normalId - 1].size() * sizeof(float));
-}
-
-} // namespace
-
-bool ReadObjFromFile(const std::string& objFilename, std::map<std::string, CarPart>* carPartsMap) {
- return ReadObjFromFile(objFilename, ReadObjOptions(), carPartsMap);
-}
-
-bool ReadObjFromFile(const std::string& objFilename, const ReadObjOptions& option,
- std::map<std::string, CarPart>* carPartsMap) {
- FILE* file = fopen(objFilename.c_str(), "r");
- if (!file) {
- LOG(ERROR) << "Failed to open obj file: " << objFilename;
- return false;
- }
-
- for (int i = 0; i < kNumberOfAxes; ++i) {
- if (option.coordinateMapping[i] >= kNumberOfAxes || option.coordinateMapping[i] < 0) {
- fclose(file);
- LOG(ERROR) << "coordinateMapping index must be less than 3 and greater or equal "
- "to 0.";
- return false;
- }
- }
-
- std::vector<std::array<float, kNumberOfAxes>> currentVertices;
- std::vector<std::array<float, kNumberOfAxes>> currentNormals;
- std::vector<std::array<float, kNumberOfAxes>> currentTextures;
- std::map<std::string, MtlConfigParams> mtlConfigParamsMap;
- std::string currentGroupName;
- MtlConfigParams currentMtlConfig;
-
- while (true) {
- char lineHeader[kCharBufferSize];
- // read the first word of the line
- int res = fscanf(file, "%s", lineHeader);
-
- if (res == EOF) {
- break; // EOF = End Of File. Quit the loop.
- }
- if (strcmp(lineHeader, "#") == 0) {
- fgets(lineHeader, sizeof(lineHeader), file);
- continue;
- }
-
- // TODO(b/156558814): add object type support.
- // TODO(b/156559272): add document for supported format.
- // Only single group per line is supported.
- if (strcmp(lineHeader, "g") == 0) {
- res = fscanf(file, "%s", lineHeader);
- currentGroupName = lineHeader;
- currentMtlConfig = MtlConfigParams();
-
- if (carPartsMap->find(currentGroupName) != carPartsMap->end()) {
- LOG(WARNING) << "Duplicate group name: " << currentGroupName
- << ". using car part name as: " << currentGroupName << "_dup";
- currentGroupName.append("_dup");
- }
- carPartsMap->emplace(
- std::make_pair(currentGroupName,
- CarPart((std::vector<CarVertex>()), CarMaterial(), kMat4Identity,
- std::string(), std::vector<std::string>())));
- continue;
- }
-
- // no "g" case, assign it as default.
- if (currentGroupName.empty()) {
- currentGroupName = "default";
- currentMtlConfig = MtlConfigParams();
- carPartsMap->emplace(
- std::make_pair(currentGroupName,
- CarPart((std::vector<CarVertex>()), CarMaterial(), kMat4Identity,
- std::string(), std::vector<std::string>())));
- }
-
- if (strcmp(lineHeader, "usemtl") == 0) {
- res = fscanf(file, "%s", lineHeader);
-
- // If material name not found.
- if (mtlConfigParamsMap.find(lineHeader) == mtlConfigParamsMap.end()) {
- carPartsMap->at(currentGroupName).material = CarMaterial();
- LOG(ERROR) << "Material not found: $0" << lineHeader;
- return false;
- }
-
- currentMtlConfig = mtlConfigParamsMap[lineHeader];
-
- carPartsMap->at(currentGroupName).material.ka = {currentMtlConfig.ka[0],
- currentMtlConfig.ka[1],
- currentMtlConfig.ka[2]};
-
- carPartsMap->at(currentGroupName).material.kd = {currentMtlConfig.kd[0],
- currentMtlConfig.kd[1],
- currentMtlConfig.kd[2]};
-
- carPartsMap->at(currentGroupName).material.ks = {currentMtlConfig.ks[0],
- currentMtlConfig.ks[1],
- currentMtlConfig.ks[2]};
-
- carPartsMap->at(currentGroupName).material.d = currentMtlConfig.d;
-
- carPartsMap->at(currentGroupName).material.textures.clear();
-
- continue;
- }
-
- if (strcmp(lineHeader, "mtllib") == 0) {
- res = fscanf(file, "%s", lineHeader);
- mtlConfigParamsMap.clear();
- std::string mtlFilename;
- if (option.mtlFilename.empty()) {
- mtlFilename = objFilename.substr(0, objFilename.find_last_of("/"));
- mtlFilename.append("/");
- mtlFilename.append(lineHeader);
- } else {
- mtlFilename = option.mtlFilename;
- }
- if (!ReadMtlFromFile(mtlFilename, &mtlConfigParamsMap)) {
- LOG(ERROR) << "Parse MTL file " << mtlFilename << " failed.";
- return false;
- }
- continue;
- }
-
- if (strcmp(lineHeader, "v") == 0) {
- std::array<float, kNumberOfAxes> pos;
- fscanf(file, "%f %f %f\n", &pos[option.coordinateMapping[0]],
- &pos[option.coordinateMapping[1]], &pos[option.coordinateMapping[2]]);
- for (int i = 0; i < kNumberOfAxes; ++i) {
- pos[i] *= option.scales[i];
- pos[i] += option.offsets[i];
- }
- currentVertices.push_back(pos);
- } else if (strcmp(lineHeader, "vt") == 0) {
- std::array<float, kNumberOfAxes> texture;
- fscanf(file, "%f %f %f\n", &texture[0], &texture[1], &texture[2]);
- currentTextures.push_back(texture);
- } else if (strcmp(lineHeader, "vn") == 0) {
- std::array<float, kNumberOfAxes> normal;
- fscanf(file, "%f %f %f\n", &normal[option.coordinateMapping[0]],
- &normal[option.coordinateMapping[1]], &normal[option.coordinateMapping[2]]);
- currentNormals.push_back(normal);
- } else if (strcmp(lineHeader, "f") == 0) {
- int vertexId[kNumberOfVerticesPerFace];
- int textureId[kNumberOfVerticesPerFace] = {-1, -1, -1};
- int normalId[kNumberOfVerticesPerFace];
-
- // Face vertices supported formats:
- // With texture: pos/texture/normal
- // Without texture: pos//normal
-
- // Scan first vertex position.
- int matches = fscanf(file, "%d/", &vertexId[0]);
-
- if (matches != 1) {
- LOG(WARNING) << "Face index error. Skipped.";
- fgets(lineHeader, sizeof(lineHeader), file);
- continue;
- }
-
- // Try scanning first two face 2 vertices with texture format present.
- bool isTexturePresent = true;
- matches = fscanf(file, "%d/%d %d/%d/%d", &textureId[0], &normalId[0], &vertexId[1],
- &textureId[1], &normalId[1]);
-
- // If 5 matches not found, try scanning first 2 face vertices without
- // texture format.
- if (matches != 5) {
- matches = fscanf(file, "/%d %d//%d", &normalId[0], &vertexId[1], &normalId[1]);
-
- // If 3 matches not found return with error.
- if (matches != 3) {
- LOG(WARNING) << "Face format not supported. Skipped.";
- fgets(lineHeader, sizeof(lineHeader), file);
- continue;
- }
-
- isTexturePresent = false;
- }
-
- // Copy first two face vertices to car vertices.
- std::array<CarVertex, kNumberOfVerticesPerFace> carVertices;
- CopyFaceToCarVertex(currentVertices, currentTextures, currentNormals, vertexId[0],
- textureId[0], normalId[0], &carVertices[0]);
- CopyFaceToCarVertex(currentVertices, currentTextures, currentNormals, vertexId[1],
- textureId[1], normalId[1], &carVertices[1]);
-
- // Add a triangle that the first two vertices make with every subsequent
- // face vertex 3 and onwards. Note this assumes the face is a convex
- // polygon.
- do {
- if (isTexturePresent) {
- matches = fscanf(file, " %d/%d/%d", &vertexId[2], &textureId[2], &normalId[2]);
- // Warn if un-expected number of matches.
- if (matches != 3 && matches != 0) {
- LOG(WARNING) << "Face matches, expected 3, read: " << matches;
- break;
- }
- } else {
- // Warn if un-expected number of matches.
- matches = fscanf(file, " %d//%d", &vertexId[2], &normalId[2]);
- if (matches != 2 && matches != 0) {
- LOG(WARNING) << "Face matches, expected 2, read: " << matches;
- break;
- }
- }
-
- if (matches == 0) {
- break;
- }
-
- CopyFaceToCarVertex(currentVertices, currentTextures, currentNormals, vertexId[2],
- textureId[2], normalId[2], &carVertices[2]);
-
- carPartsMap->at(currentGroupName).vertices.push_back(carVertices[0]);
- carPartsMap->at(currentGroupName).vertices.push_back(carVertices[1]);
- carPartsMap->at(currentGroupName).vertices.push_back(carVertices[2]);
-
- carVertices[1] = carVertices[2];
- } while (true);
-
- } else {
- // LOG(WARNING) << "Unknown tag " << lineHeader << ". Skipped";
- fgets(lineHeader, sizeof(lineHeader), file);
- continue;
- }
- }
-
- fclose(file);
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/ObjReader.h b/cpp/surround_view/service-impl/ObjReader.h
deleted file mode 100644
index c19be14..0000000
--- a/cpp/surround_view/service-impl/ObjReader.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_OBJREADER_H_
-#define SURROUND_VIEW_SERVICE_IMPL_OBJREADER_H_
-
-#include <map>
-#include <string>
-
-#include "core_lib.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using android_auto::surround_view::CarPart;
-
-// ReadObjOptions for processing obj's vertex coordinates.
-// Sequence of processing ReadObjOptions:
-// 1. coordinate_mapping
-// 2. scales
-// 3. offsets
-struct ReadObjOptions {
- // Maps obj coordinates to the output overlay coordinate.
- // 0 <-> x, 1 <-> y, 2 <-> z
- // Default is {0, 1, 2}, without coordinate changes.
- int coordinateMapping[3] = {0, 1, 2};
-
- // scale of each coordinate (after offsets).
- float scales[3] = {1.0f, 1.0f, 1.0f};
-
- // offset of each coordinate (after mapping).
- float offsets[3] = {0, 0, 0};
-
- // Optional mtl filename. String name is obj file is used if this is empty.
- std::string mtlFilename;
-};
-
-// Reads obj file to vector of OverlayVertex.
-// |obj_filename| is the full path and name of the obj file.
-// |car_parts_map| is a map containing all car parts.
-// Now it only supports two face formats:
-// 1. f x/x/x x/x/x x/x/x ...
-// 2. f x//x x//x x//x ...
-// b/
-bool ReadObjFromFile(const std::string& objFilename, std::map<std::string, CarPart>* carPartsMap);
-
-// Reads obj file to vector of OverlayVertex.
-// |obj_filename| is the full path and name of the obj file.
-// |option| provides optional changes on the coordinates.
-// |car_parts_map| is a map containing all car parts.
-bool ReadObjFromFile(const std::string& obFilename, const ReadObjOptions& option,
- std::map<std::string, CarPart>* carPartsMap);
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_OBJREADER_H_
diff --git a/cpp/surround_view/service-impl/ObjReaderTests.cpp b/cpp/surround_view/service-impl/ObjReaderTests.cpp
deleted file mode 100644
index 1c86737..0000000
--- a/cpp/surround_view/service-impl/ObjReaderTests.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define LOG_TAG "ObjReaderTests"
-
-#include "ObjReader.h"
-
-#include "MtlReader.h"
-#include "core_lib.h"
-
-#include <gtest/gtest.h>
-#include <map>
-#include <string>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-
-TEST(ObjParserTests, ReadObjFileSuccess) {
- std::map<std::string, CarPart> carPartsMap;
- EXPECT_TRUE(ReadObjFromFile("vendor/etc/automotive/sv/sample_car.obj", &carPartsMap));
- EXPECT_NE(carPartsMap.size(), 0);
-}
-
-} // namespace
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/SurroundView2dSession.cpp b/cpp/surround_view/service-impl/SurroundView2dSession.cpp
deleted file mode 100644
index 2d837e0..0000000
--- a/cpp/surround_view/service-impl/SurroundView2dSession.cpp
+++ /dev/null
@@ -1,919 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-#define ATRACE_TAG ATRACE_TAG_CAMERA
-
-#include "SurroundView2dSession.h"
-
-#include "CameraUtils.h"
-
-#include <android-base/logging.h>
-#include <android/hardware/camera/device/3.2/ICameraDevice.h>
-#include <android/hardware_buffer.h>
-#include <system/camera_metadata.h>
-#include <utils/SystemClock.h>
-#include <utils/Trace.h>
-#include <vndk/hardware_buffer.h>
-
-#include <thread>
-
-using ::std::adopt_lock;
-using ::std::lock;
-using ::std::lock_guard;
-using ::std::map;
-using ::std::mutex;
-using ::std::scoped_lock;
-using ::std::string;
-using ::std::thread;
-using ::std::unique_lock;
-using ::std::unique_ptr;
-using ::std::vector;
-
-using ::android::hardware::automotive::evs::V1_0::EvsResult;
-using ::android::hardware::camera::device::V3_2::Stream;
-
-using GraphicsPixelFormat = ::android::hardware::graphics::common::V1_0::PixelFormat;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Macro for obtaining a uint64_t memory_id from the camera index and buffer_id.
-#define GET_MEMORY_ID(cam_index, buffer_id) ((static_cast<uint64_t>(cam_index) << 32) | buffer_id)
-
-// TODO(b/158479099): There are a lot of redundant code between 2d and 3d.
-// Decrease the degree of redundancy.
-typedef struct {
- int32_t id;
- int32_t width;
- int32_t height;
- int32_t format;
- int32_t direction;
- int32_t framerate;
-} RawStreamConfig;
-
-static const size_t kStreamCfgSz = sizeof(RawStreamConfig) / sizeof(int32_t);
-static const int kInputNumChannels = 4;
-static const int kOutputNumChannels = 3;
-static const int kNumFrames = 4;
-static const int kSv2dViewId = 0;
-static const float kUndistortionScales[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-
-SurroundView2dSession::FramesHandler::FramesHandler(
- sp<IEvsCamera> pCamera, sp<SurroundView2dSession> pSession)
- : mCamera(pCamera),
- mSession(pSession) {}
-
-Return<void> SurroundView2dSession::FramesHandler::deliverFrame(
- const BufferDesc_1_0& bufDesc_1_0) {
- LOG(INFO) << "Ignores a frame delivered from v1.0 EVS service.";
- mCamera->doneWithFrame(bufDesc_1_0);
-
- return {};
-}
-
-Return<void> SurroundView2dSession::FramesHandler::deliverFrame_1_1(
- const hidl_vec<BufferDesc_1_1>& buffers) {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- LOG(INFO) << "Received " << buffers.size() << " frames from the camera";
- mSession->mSequenceId++;
-
- {
- scoped_lock<mutex> lock(mSession->mAccessLock);
- if (mSession->mProcessingEvsFrames) {
- LOG(WARNING) << "EVS frames are being processed. Skip frames:"
- << mSession->mSequenceId;
- mCamera->doneWithFrame_1_1(buffers);
- return {};
- } else {
- // Sets the flag to true immediately so the new coming frames will
- // be skipped.
- mSession->mProcessingEvsFrames = true;
- }
- }
-
- if (buffers.size() != kNumFrames) {
- scoped_lock<mutex> lock(mSession->mAccessLock);
- LOG(ERROR) << "The number of incoming frames is " << buffers.size()
- << ", which is different from the number " << kNumFrames
- << ", specified in config file";
- mSession->mProcessingEvsFrames = false;
- mCamera->doneWithFrame_1_1(buffers);
- return {};
- }
-
- {
- scoped_lock<mutex> lock(mSession->mAccessLock);
- vector<int> indices;
- for (const auto& id
- : mSession->mIOModuleConfig->cameraConfig.evsCameraIds) {
- for (int i = 0; i < kNumFrames; i++) {
- if (buffers[i].deviceId == id) {
- indices.emplace_back(i);
- break;
- }
- }
- }
-
- if (indices.size() != kNumFrames) {
- LOG(ERROR) << "The frames are not from the cameras we expected!";
- mSession->mProcessingEvsFrames = false;
- mCamera->doneWithFrame_1_1(buffers);
- return {};
- }
-
- if (mSession->mGpuAccelerationEnabled) {
- for (int i = 0; i < kNumFrames; i++) {
- LOG(DEBUG) << "Importing graphic buffer from camera ["
- << buffers[indices[i]].deviceId << "]";
- const AHardwareBuffer_Desc* pDesc = reinterpret_cast<const AHardwareBuffer_Desc*>(
- &buffers[indices[i]].buffer.description);
-
- AHardwareBuffer* hardwareBuffer;
- status_t status = AHardwareBuffer_createFromHandle(
- pDesc, buffers[indices[i]].buffer.nativeHandle,
- AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE, &hardwareBuffer);
-
- if (status != NO_ERROR) {
- LOG(ERROR) << "Can't create AHardwareBuffer from handle. Error: " << status;
- return {};
- }
-
- mSession->mInputPointers[i].gpu_data_pointer = static_cast<void*>(hardwareBuffer);
- // Set memory_id to enable buffer caching.
- // higher 32 bits are for camera index, lower 32 bits for bufferId.
- mSession->mInputPointers[i].memory_id
- = GET_MEMORY_ID(indices[i], buffers[indices[i]].bufferId);
-
- // Keep a reference to the EVS graphic buffers, so we can
- // release them after Surround View stitching is done.
- mSession->mEvsGraphicBuffers = buffers;
- }
- } else {
- for (int i = 0; i < kNumFrames; i++) {
- LOG(DEBUG) << "Copying buffer from camera [" << buffers[indices[i]].deviceId
- << "] to Surround View Service";
- mSession->copyFromBufferToPointers(buffers[indices[i]],
- mSession->mInputPointers[i]);
- }
-
- // On the CPU version, we do not need to hold the Graphic Buffers
- // any more since they are copied already.
- mCamera->doneWithFrame_1_1(buffers);
- }
- }
-
- // Notify the session that a new set of frames is ready
- mSession->mFramesSignal.notify_all();
-
- ATRACE_END();
-
- return {};
-}
-
-Return<void> SurroundView2dSession::FramesHandler::notify(const EvsEventDesc& event) {
- switch(event.aType) {
- case EvsEventType::STREAM_STOPPED:
- // The Surround View STREAM_STOPPED event is generated when the
- // service finished processing the queued frames. So it does not
- // rely on the Evs STREAM_STOPPED event.
- LOG(INFO) << "Received a STREAM_STOPPED event from Evs.";
- break;
-
- case EvsEventType::PARAMETER_CHANGED:
- LOG(INFO) << "Camera parameter " << std::hex << event.payload[0]
- << " is set to " << event.payload[1];
- break;
-
- // Below events are ignored in reference implementation.
- case EvsEventType::STREAM_STARTED:
- [[fallthrough]];
- case EvsEventType::FRAME_DROPPED:
- [[fallthrough]];
- case EvsEventType::TIMEOUT:
- LOG(INFO) << "Event " << std::hex << static_cast<unsigned>(event.aType)
- << "is received but ignored.";
- break;
- default:
- LOG(ERROR) << "Unknown event id: " << static_cast<unsigned>(event.aType);
- break;
- }
-
- return {};
-}
-
-bool SurroundView2dSession::copyFromBufferToPointers(
- BufferDesc_1_1 buffer, SurroundViewInputBufferPointers pointers) {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- AHardwareBuffer_Desc* pDesc =
- reinterpret_cast<AHardwareBuffer_Desc *>(&buffer.buffer.description);
-
- ATRACE_BEGIN("Create Graphic Buffer");
- // create a GraphicBuffer from the existing handle
- sp<GraphicBuffer> inputBuffer = new GraphicBuffer(
- buffer.buffer.nativeHandle, GraphicBuffer::CLONE_HANDLE, pDesc->width,
- pDesc->height, pDesc->format, pDesc->layers,
- GRALLOC_USAGE_HW_TEXTURE, pDesc->stride);
-
- if (inputBuffer == nullptr) {
- LOG(ERROR) << "Failed to allocate GraphicBuffer to wrap image handle";
- // Returning "true" in this error condition because we already released the
- // previous image (if any) and so the texture may change in unpredictable
- // ways now!
- return false;
- } else {
- LOG(INFO) << "Managed to allocate GraphicBuffer with "
- << " width: " << pDesc->width
- << " height: " << pDesc->height
- << " format: " << pDesc->format
- << " stride: " << pDesc->stride;
- }
- ATRACE_END();
-
- ATRACE_BEGIN("Lock input buffer (gpu to cpu)");
- // Lock the input GraphicBuffer and map it to a pointer. If we failed to
- // lock, return false.
- void* inputDataPtr;
- inputBuffer->lock(
- GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_NEVER,
- &inputDataPtr);
- if (!inputDataPtr) {
- LOG(ERROR) << "Failed to gain read access to GraphicBuffer";
- inputBuffer->unlock();
- return false;
- } else {
- LOG(INFO) << "Managed to get read access to GraphicBuffer";
- }
- ATRACE_END();
-
- ATRACE_BEGIN("Copy input data");
- // Both source and destination are with 4 channels
- memcpy(pointers.cpu_data_pointer, inputDataPtr,
- pDesc->height * pDesc->width * kInputNumChannels);
- LOG(DEBUG) << "Buffer copying finished";
- ATRACE_END();
-
- ATRACE_BEGIN("Unlock input buffer (cpu to gpu)");
- inputBuffer->unlock();
- ATRACE_END();
-
- // Paired with ATRACE_BEGIN in the beginning of the method.
- ATRACE_END();
-
- return true;
-}
-
-void SurroundView2dSession::processFrames() {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- while (true) {
- {
- unique_lock<mutex> lock(mAccessLock);
-
- if (mStreamState != RUNNING) {
- break;
- }
-
- mFramesSignal.wait(lock, [this]() { return mProcessingEvsFrames; });
- }
-
- handleFrames(mSequenceId);
-
- {
- // Set the boolean to false to receive the next set of frames.
- scoped_lock<mutex> lock(mAccessLock);
- mProcessingEvsFrames = false;
- }
- }
-
- // Notify the SV client that no new results will be delivered.
- LOG(DEBUG) << "Notify SvEvent::STREAM_STOPPED";
- mStream->notify(SvEvent::STREAM_STOPPED);
-
- {
- scoped_lock<mutex> lock(mAccessLock);
- mStreamState = STOPPED;
- mStream = nullptr;
- LOG(DEBUG) << "Stream marked STOPPED.";
- }
-
- ATRACE_END();
-}
-
-SurroundView2dSession::SurroundView2dSession(sp<IEvsEnumerator> pEvs,
- IOModuleConfig* pConfig)
- : mEvs(pEvs),
- mIOModuleConfig(pConfig),
- mStreamState(STOPPED) {}
-
-SurroundView2dSession::~SurroundView2dSession() {
- // In case the client did not call stopStream properly, we should stop the
- // stream explicitly. Otherwise the process thread will take forever to
- // join.
- stopStream();
-
- // Waiting for the process thread to finish the buffered frames.
- if (mProcessThread.joinable()) {
- mProcessThread.join();
- }
-
- mEvs->closeCamera(mCamera);
-
- // TODO(b/175176576): properly release the mInputPointers and mOutputPointer
-}
-
-// Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewSession
-Return<SvResult> SurroundView2dSession::startStream(
- const sp<ISurroundViewStream>& stream) {
- LOG(DEBUG) << __FUNCTION__;
- scoped_lock<mutex> lock(mAccessLock);
-
- if (!mIsInitialized && !initialize()) {
- LOG(ERROR) << "There is an error while initializing the use case. "
- << "Exiting";
- return SvResult::INTERNAL_ERROR;
- }
-
- if (mStreamState != STOPPED) {
- LOG(ERROR) << "Ignoring startVideoStream call"
- << "when a stream is already running.";
- return SvResult::INTERNAL_ERROR;
- }
-
- if (stream == nullptr) {
- LOG(ERROR) << "The input stream is invalid";
- return SvResult::INTERNAL_ERROR;
- }
- mStream = stream;
-
- mSequenceId = 0;
- startEvs();
-
- // TODO(b/158131080): the STREAM_STARTED event is not implemented in EVS
- // reference implementation yet. Once implemented, this logic should be
- // moved to EVS notify callback.
- LOG(DEBUG) << "Notify SvEvent::STREAM_STARTED";
- mStream->notify(SvEvent::STREAM_STARTED);
- mProcessingEvsFrames = false;
-
- // Start the frame generation thread
- mStreamState = RUNNING;
-
- mProcessThread = thread([this]() {
- processFrames();
- });
-
- return SvResult::OK;
-}
-
-Return<void> SurroundView2dSession::stopStream() {
- LOG(DEBUG) << __FUNCTION__;
- unique_lock<mutex> lock(mAccessLock);
-
- if (mStreamState == RUNNING) {
- // Tell the processFrames loop to stop processing frames
- mStreamState = STOPPING;
-
- // Stop the EVS stream asynchronizely
- mCamera->stopVideoStream();
- mFramesHandler = nullptr;
- }
-
- return {};
-}
-
-Return<void> SurroundView2dSession::doneWithFrames(
- const SvFramesDesc& svFramesDesc){
- LOG(DEBUG) << __FUNCTION__;
- scoped_lock <mutex> lock(mAccessLock);
-
- mFramesRecord.inUse = false;
-
- (void)svFramesDesc;
- return {};
-}
-
-// Methods from ISurroundView2dSession follow.
-Return<void> SurroundView2dSession::get2dMappingInfo(
- get2dMappingInfo_cb _hidl_cb) {
- LOG(DEBUG) << __FUNCTION__;
-
- _hidl_cb(mInfo);
- return {};
-}
-
-Return<SvResult> SurroundView2dSession::set2dConfig(
- const Sv2dConfig& sv2dConfig) {
- LOG(DEBUG) << __FUNCTION__;
- scoped_lock <mutex> lock(mAccessLock);
-
- if (sv2dConfig.width <=0 || sv2dConfig.width > 4096) {
- LOG(WARNING) << "The width of 2d config is out of the range (0, 4096]"
- << "Ignored!";
- return SvResult::INVALID_ARG;
- }
-
- mConfig.width = sv2dConfig.width;
- mConfig.blending = sv2dConfig.blending;
- mHeight = mConfig.width * mInfo.height / mInfo.width;
-
- if (mStream != nullptr) {
- LOG(DEBUG) << "Notify SvEvent::CONFIG_UPDATED";
- mStream->notify(SvEvent::CONFIG_UPDATED);
- }
-
- return SvResult::OK;
-}
-
-Return<void> SurroundView2dSession::get2dConfig(get2dConfig_cb _hidl_cb) {
- LOG(DEBUG) << __FUNCTION__;
-
- _hidl_cb(mConfig);
- return {};
-}
-
-Return<void> SurroundView2dSession::projectCameraPoints(const hidl_vec<Point2dInt>& points2dCamera,
- const hidl_string& cameraId,
- projectCameraPoints_cb _hidl_cb) {
- LOG(DEBUG) << __FUNCTION__;
- std::vector<Point2dFloat> outPoints;
- bool cameraIdFound = false;
- int cameraIndex = 0;
- // Note: mEvsCameraIds must be in the order front, right, rear, left.
- for (auto& evsCameraId : mEvsCameraIds) {
- if (cameraId == evsCameraId) {
- cameraIdFound = true;
- LOG(DEBUG) << "Camera id found for projection: " << cameraId;
- break;
- }
- cameraIndex++;
- }
-
- if (!cameraIdFound) {
- LOG(ERROR) << "Camera id not found for projection: " << cameraId;
- _hidl_cb(outPoints);
- return {};
- }
-
- int width = mConfig.width;
- int height = mHeight;
- for (const auto& cameraPoint : points2dCamera) {
- Point2dFloat outPoint = {false, 0.0, 0.0};
- // Check of the camear point is within the camera resolution bounds.
- if (cameraPoint.x < 0 || cameraPoint.x > width - 1 || cameraPoint.y < 0 ||
- cameraPoint.y > height - 1) {
- LOG(WARNING) << "Camera point (" << cameraPoint.x << ", " << cameraPoint.y
- << ") is out of camera resolution bounds.";
- outPoint.isValid = false;
- outPoints.push_back(outPoint);
- continue;
- }
-
- // Project points using mSurroundView function.
- const Coordinate2dInteger camPoint(cameraPoint.x, cameraPoint.y);
- Coordinate2dFloat projPoint2d(0.0, 0.0);
-
- outPoint.isValid =
- mSurroundView->GetProjectionPointFromRawCameraToSurroundView2d(camPoint,
- cameraIndex,
- &projPoint2d);
- outPoint.x = projPoint2d.x;
- outPoint.y = projPoint2d.y;
- outPoints.push_back(outPoint);
- }
-
- _hidl_cb(outPoints);
- return {};
-}
-
-// TODO(b/175176765): implement a GPU version of this method separately.
-bool SurroundView2dSession::handleFrames(int sequenceId) {
- LOG(INFO) << __FUNCTION__ << "Handling sequenceId " << sequenceId << ".";
-
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- // TODO(b/157498592): Now only one sets of EVS input frames and one SV
- // output frame is supported. Implement buffer queue for both of them.
- {
- scoped_lock<mutex> lock(mAccessLock);
-
- if (mFramesRecord.inUse) {
- LOG(DEBUG) << "Notify SvEvent::FRAME_DROPPED";
- mStream->notify(SvEvent::FRAME_DROPPED);
-
- // For GPU solution only (the frames were released already for CPU solution).
- if (mGpuAccelerationEnabled) {
- mCamera->doneWithFrame_1_1(mEvsGraphicBuffers);
- }
- return true;
- }
- }
-
- // TODO(b/175177030): modifying the width/length on the fly is not supported by the GPU approach
- // yet.
- if (!mGpuAccelerationEnabled) {
- if (mOutputWidth != mConfig.width || mOutputHeight != mHeight) {
- LOG(DEBUG) << "Config changed. Re-allocate memory."
- << " Old width: " << mOutputWidth << " Old height: " << mOutputHeight
- << " New width: " << mConfig.width << " New height: " << mHeight;
- delete[] static_cast<char*>(mOutputPointer.cpu_data_pointer);
- mOutputWidth = mConfig.width;
- mOutputHeight = mHeight;
- mOutputPointer.height = mOutputHeight;
- mOutputPointer.width = mOutputWidth;
- mOutputPointer.format = Format::RGB;
- mOutputPointer.cpu_data_pointer =
- static_cast<void*>(new char[mOutputHeight * mOutputWidth * kOutputNumChannels]);
-
- if (!mOutputPointer.cpu_data_pointer) {
- LOG(ERROR) << "Memory allocation failed. Exiting.";
- return false;
- }
-
- Size2dInteger size = Size2dInteger(mOutputWidth, mOutputHeight);
- mSurroundView->Update2dOutputResolution(size);
-
- mSvTexture = new GraphicBuffer(mOutputWidth, mOutputHeight, HAL_PIXEL_FORMAT_RGB_888, 1,
- GRALLOC_USAGE_HW_TEXTURE, "SvTexture");
- if (mSvTexture->initCheck() == OK) {
- LOG(INFO) << "Successfully allocated Graphic Buffer";
- } else {
- LOG(ERROR) << "Failed to allocate Graphic Buffer";
- return false;
- }
- }
- LOG(INFO) << "Output Pointer data format: " << mOutputPointer.format;
- }
-
- ATRACE_BEGIN("SV core lib method: Get2dSurroundView");
- const string gpuEnabledText = mGpuAccelerationEnabled ? " with GPU acceleration flag enabled"
- : " with GPU acceleration flag disabled";
- if (mSurroundView->Get2dSurroundView(mInputPointers, &mOutputPointer)) {
- LOG(INFO) << "Get2dSurroundView succeeded" << gpuEnabledText;
- } else {
- LOG(ERROR) << "Get2dSurroundView failed" << gpuEnabledText;
- }
- ATRACE_END();
-
- // For GPU solution only (the frames were released already for CPU solution).
- if (mGpuAccelerationEnabled) {
- ATRACE_BEGIN("Release the evs frames");
- mCamera->doneWithFrame_1_1(mEvsGraphicBuffers);
- ATRACE_END();
- }
-
- ANativeWindowBuffer* buffer;
- if (mGpuAccelerationEnabled) {
- buffer = mOutputHolder->getNativeBuffer();
- } else {
- ATRACE_BEGIN("Lock output texture (gpu to cpu)");
- void* textureDataPtr = nullptr;
- mSvTexture->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_NEVER,
- &textureDataPtr);
- ATRACE_END();
-
- if (!textureDataPtr) {
- LOG(ERROR) << "Failed to gain write access to GraphicBuffer!";
- return false;
- }
-
- ATRACE_BEGIN("Copy output result");
- // Note: there is a chance that the stride of the texture is not the same
- // as the width. For example, when the input frame is 1920 * 1080, the
- // width is 1080, but the stride is 2048. So we'd better copy the data line
- // by line, instead of single memcpy.
- uint8_t* writePtr = static_cast<uint8_t*>(textureDataPtr);
- uint8_t* readPtr = static_cast<uint8_t*>(mOutputPointer.cpu_data_pointer);
- const int readStride = mOutputWidth * kOutputNumChannels;
- const int writeStride = mSvTexture->getStride() * kOutputNumChannels;
- if (readStride == writeStride) {
- memcpy(writePtr, readPtr, readStride * mSvTexture->getHeight());
- } else {
- for (int i = 0; i < mSvTexture->getHeight(); i++) {
- memcpy(writePtr, readPtr, readStride);
- writePtr = writePtr + writeStride;
- readPtr = readPtr + readStride;
- }
- }
- LOG(DEBUG) << "memcpy finished";
- ATRACE_END();
-
- ATRACE_BEGIN("Unlock output texture (cpu to gpu)");
- mSvTexture->unlock();
- ATRACE_END();
-
- buffer = mSvTexture->getNativeBuffer();
- LOG(DEBUG) << "ANativeWindowBuffer->handle: " << buffer->handle;
- }
-
- {
- scoped_lock<mutex> lock(mAccessLock);
-
- mFramesRecord.frames.svBuffers.resize(1);
- SvBuffer& svBuffer = mFramesRecord.frames.svBuffers[0];
- svBuffer.viewId = kSv2dViewId;
- svBuffer.hardwareBuffer.nativeHandle = buffer->handle;
- AHardwareBuffer_Desc* pDesc =
- reinterpret_cast<AHardwareBuffer_Desc*>(
- &svBuffer.hardwareBuffer.description);
- if (mGpuAccelerationEnabled) {
- pDesc->width = mOutputPointer.width;
- pDesc->height = mOutputPointer.height;
- pDesc->stride = mOutputHolder->getStride();
- pDesc->format = HAL_PIXEL_FORMAT_RGBA_8888;
- } else {
- pDesc->width = mOutputWidth;
- pDesc->height = mOutputHeight;
- pDesc->stride = mSvTexture->getStride();
- pDesc->format = HAL_PIXEL_FORMAT_RGB_888;
- }
- pDesc->layers = 1;
- pDesc->usage = GRALLOC_USAGE_HW_TEXTURE;
- mFramesRecord.frames.timestampNs = elapsedRealtimeNano();
- mFramesRecord.frames.sequenceId = sequenceId;
-
- mFramesRecord.inUse = true;
- mStream->receiveFrames(mFramesRecord.frames);
- }
-
- ATRACE_END();
-
- return true;
-}
-
-// TODO(b/175176765): consider to HW-specific initialization procedures into
-// separate methods.
-bool SurroundView2dSession::initialize() {
- lock_guard<mutex> lock(mAccessLock, adopt_lock);
-
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- if (!setupEvs()) {
- LOG(ERROR) << "Failed to setup EVS components for 2d session";
- return false;
- }
-
- // TODO(b/150412555): ask core-lib team to add API description for "create"
- // method in the .h file.
- // The create method will never return a null pointer based the API
- // description.
- mSurroundView = unique_ptr<SurroundView>(Create());
-
- SurroundViewStaticDataParams params =
- SurroundViewStaticDataParams(mCameraParams,
- mIOModuleConfig->sv2dConfig.sv2dParams,
- mIOModuleConfig->sv3dConfig.sv3dParams,
- vector<float>(std::begin(kUndistortionScales),
- std::end(kUndistortionScales)),
- mIOModuleConfig->sv2dConfig.carBoundingBox,
- mIOModuleConfig->carModelConfig.carModel.texturesMap,
- mIOModuleConfig->carModelConfig.carModel.partsMap);
- mGpuAccelerationEnabled = mIOModuleConfig->sv2dConfig.sv2dParams.gpu_acceleration_enabled;
-
- ATRACE_BEGIN("SV core lib method: SetStaticData");
- mSurroundView->SetStaticData(params);
- ATRACE_END();
-
- ATRACE_BEGIN("SV core lib method: Start2dPipeline");
- const string gpuEnabledText = mGpuAccelerationEnabled ? "with GPU acceleration flag enabled"
- : "with GPU acceleration flag disabled";
- if (mSurroundView->Start2dPipeline()) {
- LOG(INFO) << "Start2dPipeline succeeded " << gpuEnabledText;
- } else {
- LOG(ERROR) << "Start2dPipeline failed " << gpuEnabledText;
- return false;
- }
- ATRACE_END();
-
- ATRACE_BEGIN("Allocate cpu buffers");
- mInputPointers.resize(kNumFrames);
- for (int i = 0; i < kNumFrames; i++) {
- mInputPointers[i].width = mCameraParams[i].size.width;
- mInputPointers[i].height = mCameraParams[i].size.height;
-
- // Only allocate CPU memory for CPU solution
- // For GPU solutions, the Graphic Buffers from EVS will be converted and
- // stored in gpu_data_pointer
- if (!mGpuAccelerationEnabled) {
- mInputPointers[i].format = Format::RGBA;
- mInputPointers[i].cpu_data_pointer =
- static_cast<void*>(new char[mInputPointers[i].width * mInputPointers[i].height *
- kInputNumChannels]);
- }
- }
- LOG(INFO) << "Allocated " << kNumFrames << " input pointers";
-
- mOutputWidth = mIOModuleConfig->sv2dConfig.sv2dParams.resolution.width;
- mOutputHeight = mIOModuleConfig->sv2dConfig.sv2dParams.resolution.height;
-
- mConfig.width = mOutputWidth;
- mConfig.blending = SvQuality::HIGH;
- mHeight = mOutputHeight;
-
- mOutputPointer.height = mOutputHeight;
- mOutputPointer.width = mOutputWidth;
-
- // Only allocate CPU memory for CPU solution
- if (!mGpuAccelerationEnabled) {
- mOutputPointer.format = Format::RGB;
- mOutputPointer.cpu_data_pointer =
- static_cast<void*>(new char[mOutputHeight * mOutputWidth * kOutputNumChannels]);
-
- if (!mOutputPointer.cpu_data_pointer) {
- LOG(ERROR) << "Memory allocation failed. Exiting.";
- return false;
- }
- }
- ATRACE_END();
-
- ATRACE_BEGIN("Allocate output texture");
- if (mGpuAccelerationEnabled) {
- mOutputHolder = new GraphicBuffer(mOutputWidth, mOutputHeight, HAL_PIXEL_FORMAT_RGBA_8888,
- 1, GRALLOC_USAGE_HW_TEXTURE, "SvOutputHolder");
- if (mOutputHolder->initCheck() == OK) {
- LOG(INFO) << "Successfully allocated Graphic Buffer for SvOutputHolder";
- } else {
- LOG(ERROR) << "Failed to allocate Graphic Buffer for SvOutputHolder";
- return false;
- }
- mOutputPointer.gpu_data_pointer = static_cast<void*>(mOutputHolder->toAHardwareBuffer());
- // Set output memory id one time to a one time unique value.
- // 0 to (kNumFrames - 1) are used for inputs, using kNumFrames as higher 32 bits.
- mOutputPointer.memory_id = GET_MEMORY_ID(kNumFrames, 0x00);
- } else {
- mSvTexture = new GraphicBuffer(mOutputWidth, mOutputHeight, HAL_PIXEL_FORMAT_RGB_888, 1,
- GRALLOC_USAGE_HW_TEXTURE, "SvTexture");
- if (mSvTexture->initCheck() == OK) {
- LOG(INFO) << "Successfully allocated Graphic Buffer";
- } else {
- LOG(ERROR) << "Failed to allocate Graphic Buffer";
- return false;
- }
- }
-
- // Note: sv2dParams is in meters while mInfo must be in milli-meters.
- mInfo.width = mIOModuleConfig->sv2dConfig.sv2dParams.physical_size.width * 1000.0;
- mInfo.height = mIOModuleConfig->sv2dConfig.sv2dParams.physical_size.height * 1000.0;
- mInfo.center.isValid = true;
- mInfo.center.x = mIOModuleConfig->sv2dConfig.sv2dParams.physical_center.x * 1000.0;
- mInfo.center.y = mIOModuleConfig->sv2dConfig.sv2dParams.physical_center.y * 1000.0;
-
- mIsInitialized = true;
-
- ATRACE_END();
-
- return true;
-}
-
-bool SurroundView2dSession::setupEvs() {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- // Reads the camera related information from the config object
- const string evsGroupId = mIOModuleConfig->cameraConfig.evsGroupId;
-
- // Setup for EVS
- LOG(INFO) << "Requesting camera list";
- mEvs->getCameraList_1_1(
- [this, evsGroupId] (hidl_vec<CameraDesc> cameraList) {
- LOG(INFO) << "Camera list callback received " << cameraList.size();
- for (auto&& cam : cameraList) {
- LOG(INFO) << "Found camera " << cam.v1.cameraId;
- if (cam.v1.cameraId == evsGroupId) {
- mCameraDesc = cam;
- }
- }
- });
-
- bool foundCfg = false;
- std::unique_ptr<Stream> targetCfg(new Stream());
-
- // This logic picks the configuration with the largest area that supports
- // RGBA8888 format
- int32_t maxArea = 0;
- camera_metadata_entry_t streamCfgs;
- if (!find_camera_metadata_entry(
- reinterpret_cast<camera_metadata_t *>(mCameraDesc.metadata.data()),
- ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
- &streamCfgs)) {
- // Stream configurations are found in metadata
- RawStreamConfig *ptr = reinterpret_cast<RawStreamConfig *>(
- streamCfgs.data.i32);
- for (unsigned idx = 0; idx < streamCfgs.count; idx += kStreamCfgSz) {
- if (ptr->direction ==
- ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT &&
- ptr->format == HAL_PIXEL_FORMAT_RGBA_8888) {
-
- if (ptr->width * ptr->height > maxArea) {
- targetCfg->id = ptr->id;
- targetCfg->width = ptr->width;
- targetCfg->height = ptr->height;
-
- // This client always wants below input data format
- targetCfg->format =
- static_cast<GraphicsPixelFormat>(
- HAL_PIXEL_FORMAT_RGBA_8888);
-
- maxArea = ptr->width * ptr->height;
-
- foundCfg = true;
- }
- }
- ++ptr;
- }
- } else {
- LOG(WARNING) << "No stream configuration data is found; "
- << "default parameters will be used.";
- }
-
- if (!foundCfg) {
- LOG(INFO) << "No config was found";
- targetCfg = nullptr;
- return false;
- }
-
- string camId = mCameraDesc.v1.cameraId.c_str();
- mCamera = mEvs->openCamera_1_1(camId.c_str(), *targetCfg);
- if (mCamera == nullptr) {
- LOG(ERROR) << "Failed to allocate EVS Camera interface for " << camId;
- return false;
- } else {
- LOG(INFO) << "Logical camera " << camId << " is opened successfully";
- }
-
- mEvsCameraIds = mIOModuleConfig->cameraConfig.evsCameraIds;
- if (mEvsCameraIds.size() < kNumFrames) {
- LOG(ERROR) << "Incorrect camera info is stored in the camera config";
- return false;
- }
-
- map<string, AndroidCameraParams> cameraIdToAndroidParameters;
- for (const auto& id : mEvsCameraIds) {
- AndroidCameraParams params;
- if (getAndroidCameraParams(mCamera, id, params)) {
- cameraIdToAndroidParameters.emplace(id, params);
- LOG(INFO) << "Camera parameters are fetched successfully for "
- << "physical camera: " << id;
- } else {
- LOG(ERROR) << "Failed to get camera parameters for "
- << "physical camera: " << id;
- return false;
- }
- }
-
- mCameraParams =
- convertToSurroundViewCameraParams(cameraIdToAndroidParameters);
-
- for (auto& camera : mCameraParams) {
- camera.size.width = targetCfg->width;
- camera.size.height = targetCfg->height;
- camera.circular_fov = 179;
- }
-
- // Add validity mask filenames.
- for (int i = 0; i < mCameraParams.size(); i++) {
- mCameraParams[i].validity_mask_filename = mIOModuleConfig->cameraConfig.maskFilenames[i];
- }
- ATRACE_END();
- return true;
-}
-
-bool SurroundView2dSession::startEvs() {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- mFramesHandler = new FramesHandler(mCamera, this);
- Return<EvsResult> result = mCamera->startVideoStream(mFramesHandler);
- if (result != EvsResult::OK) {
- LOG(ERROR) << "Failed to start video stream";
- return false;
- } else {
- LOG(INFO) << "Video stream was started successfully";
- }
-
- ATRACE_END();
-
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/SurroundView2dSession.h b/cpp/surround_view/service-impl/SurroundView2dSession.h
deleted file mode 100644
index e7a9e17..0000000
--- a/cpp/surround_view/service-impl/SurroundView2dSession.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#pragma once
-
-#include "IOModule.h"
-
-#include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
-#include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
-#include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
-#include <android/hardware/automotive/sv/1.0/types.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundView2dSession.h>
-
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-#include <ui/GraphicBuffer.h>
-
-#include <thread>
-
-using namespace ::android::hardware::automotive::evs::V1_1;
-using namespace ::android::hardware::automotive::sv::V1_0;
-using namespace ::android_auto::surround_view;
-
-using ::android::hardware::Return;
-using ::android::hardware::hidl_vec;
-using ::android::sp;
-using ::std::condition_variable;
-
-using BufferDesc_1_0 = ::android::hardware::automotive::evs::V1_0::BufferDesc;
-using BufferDesc_1_1 = ::android::hardware::automotive::evs::V1_1::BufferDesc;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-class SurroundView2dSession : public ISurroundView2dSession {
-
- /*
- * FramesHandler:
- * This class can be used to receive camera imagery from an IEvsCamera implementation. It will
- * hold onto the most recent image buffer, returning older ones.
- * Note that the video frames are delivered on a background thread, while the control interface
- * is actuated from the applications foreground thread.
- */
- class FramesHandler : public IEvsCameraStream {
- public:
- FramesHandler(sp<IEvsCamera> pCamera, sp<SurroundView2dSession> pSession);
-
- private:
- // Implementation for ::android::hardware::automotive::evs::V1_0::IEvsCameraStream
- Return<void> deliverFrame(const BufferDesc_1_0& buffer) override;
-
- // Implementation for ::android::hardware::automotive::evs::V1_1::IEvsCameraStream
- Return<void> deliverFrame_1_1(const hidl_vec<BufferDesc_1_1>& buffer) override;
- Return<void> notify(const EvsEventDesc& event) override;
-
- // Values initialized as startup
- sp <IEvsCamera> mCamera;
-
- sp<SurroundView2dSession> mSession;
- };
-
-public:
- SurroundView2dSession(sp<IEvsEnumerator> pEvs, IOModuleConfig* pConfig);
- ~SurroundView2dSession();
- bool initialize();
-
- // Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewSession.
- Return<SvResult> startStream(
- const sp<ISurroundViewStream>& stream) override;
- Return<void> stopStream() override;
- Return<void> doneWithFrames(const SvFramesDesc& svFramesDesc) override;
-
- // Methods from ISurroundView2dSession follow.
- Return<void> get2dMappingInfo(get2dMappingInfo_cb _hidl_cb) override;
- Return<SvResult> set2dConfig(const Sv2dConfig& sv2dConfig) override;
- Return<void> get2dConfig(get2dConfig_cb _hidl_cb) override;
- Return<void> projectCameraPoints(
- const hidl_vec<Point2dInt>& points2dCamera,
- const hidl_string& cameraId,
- projectCameraPoints_cb _hidl_cb) override;
-
-private:
- void processFrames();
-
- // Set up and open the Evs camera(s), triggered when session is created.
- bool setupEvs();
-
- // Start Evs camera video stream, triggered when SV stream is started.
- bool startEvs();
-
- bool handleFrames(int sequenceId);
-
- bool copyFromBufferToPointers(BufferDesc_1_1 buffer,
- SurroundViewInputBufferPointers pointers);
-
- enum StreamStateValues {
- STOPPED,
- RUNNING,
- STOPPING,
- DEAD,
- };
-
- // EVS Enumerator to control the start/stop of the Evs Stream
- sp<IEvsEnumerator> mEvs;
-
- IOModuleConfig* mIOModuleConfig;
-
- // Instance and metadata for the opened Evs Camera
- sp<IEvsCamera> mCamera;
- CameraDesc mCameraDesc;
- std::vector<SurroundViewCameraParams> mCameraParams;
-
- // Stream subscribed for the session.
- sp<ISurroundViewStream> mStream GUARDED_BY(mAccessLock);
- StreamStateValues mStreamState GUARDED_BY(mAccessLock);
-
- std::thread mProcessThread; // The thread we'll use to process frames
-
- // Reference to the inner class, to handle the incoming Evs frames
- sp<FramesHandler> mFramesHandler;
-
- // Used to signal a set of frames is ready
- condition_variable mFramesSignal GUARDED_BY(mAccessLock);
- bool mProcessingEvsFrames GUARDED_BY(mAccessLock);
-
- int mSequenceId;
-
- struct FramesRecord {
- SvFramesDesc frames;
- bool inUse = false;
- };
-
- FramesRecord mFramesRecord GUARDED_BY(mAccessLock);
-
- // Synchronization necessary to deconflict mCaptureThread from the main
- // service thread
- std::mutex mAccessLock;
-
- std::vector<std::string> mEvsCameraIds GUARDED_BY(mAccessLock);
-
- std::unique_ptr<SurroundView> mSurroundView GUARDED_BY(mAccessLock);
-
- std::vector<SurroundViewInputBufferPointers>
- mInputPointers GUARDED_BY(mAccessLock);
- SurroundViewResultPointer mOutputPointer GUARDED_BY(mAccessLock);
-
- Sv2dConfig mConfig GUARDED_BY(mAccessLock);
- int mHeight GUARDED_BY(mAccessLock);
-
- // TODO(b/158479099): Rename it to mMappingInfo
- Sv2dMappingInfo mInfo GUARDED_BY(mAccessLock);
- int mOutputWidth, mOutputHeight GUARDED_BY(mAccessLock);
- sp<GraphicBuffer> mOutputHolder;
-
- sp<GraphicBuffer> mSvTexture GUARDED_BY(mAccessLock);
-
- bool mIsInitialized GUARDED_BY(mAccessLock) = false;
-
- bool mGpuAccelerationEnabled;
- hidl_vec<BufferDesc_1_1> mEvsGraphicBuffers;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
diff --git a/cpp/surround_view/service-impl/SurroundView2dSessionTests.cpp b/cpp/surround_view/service-impl/SurroundView2dSessionTests.cpp
deleted file mode 100644
index a452ddf..0000000
--- a/cpp/surround_view/service-impl/SurroundView2dSessionTests.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define LOG_TAG "SurroundView2dSessionTests"
-
-#include "mock-evs/MockEvsEnumerator.h"
-#include "mock-evs/MockSurroundViewCallback.h"
-
-#include "IOModule.h"
-#include "SurroundView2dSession.h"
-
-#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
-
-#include <android-base/logging.h>
-
-#include <gtest/gtest.h>
-#include <time.h>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-
-const char* kSvConfigFilename = "vendor/etc/automotive/sv/sv_sample_config.xml";
-
-using android::hardware::automotive::sv::V1_0::Sv2dMappingInfo;
-using android::hardware::automotive::sv::V1_0::SvQuality;
-
-// Sv 2D output height and width set by the config file.
-const int kSv2dWidth = 768;
-const int kSv2dHeight = 1024;
-
-class SurroundView2dSessionTests : public ::testing::Test {
-protected:
- void SetUp() override {
- sp<IEvsEnumerator> fakeEvs = new MockEvsEnumerator();
- mIoModule = new IOModule(kSvConfigFilename);
- EXPECT_EQ(mIoModule->initialize(), IOStatus::OK);
-
- mIoModule->getConfig(&mIoModuleConfig);
-
- mSv2dSession = new SurroundView2dSession(fakeEvs, &mIoModuleConfig);
- EXPECT_TRUE(mSv2dSession->initialize());
- }
-
- IOModule* mIoModule;
- IOModuleConfig mIoModuleConfig;
- sp<SurroundView2dSession> mSv2dSession;
-};
-
-TEST_F(SurroundView2dSessionTests, startAndStopSurroundView2dSession) {
- sp<MockSurroundViewCallback> sv2dCallback =
- new MockSurroundViewCallback(mSv2dSession);
-
- EXPECT_EQ(mSv2dSession->startStream(sv2dCallback), SvResult::OK);
-
- sleep(5);
-
- mSv2dSession->stopStream();
-}
-
-TEST_F(SurroundView2dSessionTests, get2dMappingInfoSuccess) {
- Sv2dMappingInfo sv2dMappingInfo;
- mSv2dSession->get2dMappingInfo(
- [&sv2dMappingInfo](const Sv2dMappingInfo& mappingInfo) {
- sv2dMappingInfo = mappingInfo;
- });
-
- EXPECT_NE(sv2dMappingInfo.width, 0);
- EXPECT_NE(sv2dMappingInfo.height, 0);
- EXPECT_EQ(sv2dMappingInfo.center.x, 0.0f);
- EXPECT_EQ(sv2dMappingInfo.center.y, 0.0f);
-}
-
-TEST_F(SurroundView2dSessionTests, get2dConfigSuccess) {
- Sv2dConfig sv2dConfig;
- mSv2dSession->get2dConfig(
- [&sv2dConfig](const Sv2dConfig& config) {
- sv2dConfig = config;
- });
-
- EXPECT_EQ(sv2dConfig.width, kSv2dWidth);
- EXPECT_EQ(sv2dConfig.blending, SvQuality::HIGH);
-}
-
-// Sets a different config and checks of the received config matches.
-TEST_F(SurroundView2dSessionTests, setAndGet2dConfigSuccess) {
- // Set config.
- Sv2dConfig sv2dConfigSet = {kSv2dWidth / 2, SvQuality::LOW};
- EXPECT_EQ(mSv2dSession->set2dConfig(sv2dConfigSet), SvResult::OK);
-
- // Get config.
- Sv2dConfig sv2dConfigReceived;
- mSv2dSession->get2dConfig(
- [&sv2dConfigReceived](const Sv2dConfig& config) {
- sv2dConfigReceived = config;
- });
-
- EXPECT_EQ(sv2dConfigReceived.width, sv2dConfigSet.width);
- EXPECT_EQ(sv2dConfigReceived.blending, sv2dConfigSet.blending);
-}
-
-// Projects center of each cameras and checks if valid projected point is received.
-TEST_F(SurroundView2dSessionTests, projectPoints2dSuccess) {
- hidl_vec<Point2dInt> points2dCamera = {
- /*Center point*/{.x = kSv2dWidth / 2, .y = kSv2dHeight /2}
- };
-
- std::vector<hidl_string> cameraIds = {"/dev/video60", "/dev/video61", "/dev/video62" ,
- "/dev/video63"};
-
- for (int i = 0; i < cameraIds.size(); i++) {
- mSv2dSession->projectCameraPoints(points2dCamera, cameraIds[i],
- [](const hidl_vec<Point2dFloat>& projectedPoints) {
- EXPECT_TRUE(projectedPoints[0].isValid);
- });
- }
-}
-
-} // namespace
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/SurroundView3dSession.cpp b/cpp/surround_view/service-impl/SurroundView3dSession.cpp
deleted file mode 100644
index 7bb6f6d..0000000
--- a/cpp/surround_view/service-impl/SurroundView3dSession.cpp
+++ /dev/null
@@ -1,974 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-#define ATRACE_TAG ATRACE_TAG_CAMERA
-
-#include "SurroundView3dSession.h"
-
-#include "CameraUtils.h"
-#include "sv_3d_params.h"
-
-#include <android-base/logging.h>
-#include <android/hardware/camera/device/3.2/ICameraDevice.h>
-#include <android/hardware_buffer.h>
-#include <android/hidl/memory/1.0/IMemory.h>
-#include <hidlmemory/mapping.h>
-#include <system/camera_metadata.h>
-#include <utils/SystemClock.h>
-#include <utils/Trace.h>
-#include <vndk/hardware_buffer.h>
-
-#include <array>
-#include <set>
-#include <thread>
-
-using ::std::adopt_lock;
-using ::std::array;
-using ::std::lock;
-using ::std::lock_guard;
-using ::std::map;
-using ::std::mutex;
-using ::std::scoped_lock;
-using ::std::set;
-using ::std::string;
-using ::std::thread;
-using ::std::unique_lock;
-using ::std::unique_ptr;
-using ::std::vector;
-
-using ::android::hardware::automotive::evs::V1_0::EvsResult;
-using ::android::hardware::camera::device::V3_2::Stream;
-using ::android::hardware::hidl_memory;
-using ::android::hidl::memory::V1_0::IMemory;
-
-using GraphicsPixelFormat = ::android::hardware::graphics::common::V1_0::PixelFormat;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-typedef struct {
- int32_t id;
- int32_t width;
- int32_t height;
- int32_t format;
- int32_t direction;
- int32_t framerate;
-} RawStreamConfig;
-
-static const size_t kStreamCfgSz = sizeof(RawStreamConfig) / sizeof(int32_t);
-static const uint8_t kGrayColor = 128;
-static const int kNumFrames = 4;
-static const int kOutputNumChannels = 4;
-static const float kUndistortionScales[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-
-SurroundView3dSession::FramesHandler::FramesHandler(
- sp<IEvsCamera> pCamera, sp<SurroundView3dSession> pSession)
- : mCamera(pCamera),
- mSession(pSession) {}
-
-Return<void> SurroundView3dSession::FramesHandler::deliverFrame(
- const BufferDesc_1_0& bufDesc_1_0) {
- LOG(INFO) << "Ignores a frame delivered from v1.0 EVS service.";
- mCamera->doneWithFrame(bufDesc_1_0);
-
- return {};
-}
-
-Return<void> SurroundView3dSession::FramesHandler::deliverFrame_1_1(
- const hidl_vec<BufferDesc_1_1>& buffers) {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- LOG(INFO) << "Received " << buffers.size() << " frames from the camera";
- mSession->mSequenceId++;
-
- {
- scoped_lock<mutex> lock(mSession->mAccessLock);
- if (mSession->mProcessingEvsFrames) {
- LOG(WARNING) << "EVS frames are being processed. Skip frames:"
- << mSession->mSequenceId;
- mCamera->doneWithFrame_1_1(buffers);
- return {};
- } else {
- // Sets the flag to true immediately so the new coming frames will
- // be skipped.
- mSession->mProcessingEvsFrames = true;
- }
- }
-
- if (buffers.size() != kNumFrames) {
- scoped_lock<mutex> lock(mSession->mAccessLock);
- LOG(ERROR) << "The number of incoming frames is " << buffers.size()
- << ", which is different from the number " << kNumFrames
- << ", specified in config file";
- mSession->mProcessingEvsFrames = false;
- mCamera->doneWithFrame_1_1(buffers);
- return {};
- }
-
- {
- scoped_lock<mutex> lock(mSession->mAccessLock);
-
- // The incoming frames may not follow the same order as listed cameras.
- // We should re-order them following the camera ids listed in camera
- // config.
- vector<int> indices;
- for (const auto& id
- : mSession->mIOModuleConfig->cameraConfig.evsCameraIds) {
- for (int i = 0; i < kNumFrames; i++) {
- if (buffers[i].deviceId == id) {
- indices.emplace_back(i);
- break;
- }
- }
- }
-
- // If the size of indices is smaller than the kNumFrames, it means that
- // there is frame(s) that comes from different camera(s) than we
- // expected.
- if (indices.size() != kNumFrames) {
- LOG(ERROR) << "The frames are not from the cameras we expected!";
- mSession->mProcessingEvsFrames = false;
- mCamera->doneWithFrame_1_1(buffers);
- return {};
- }
-
- for (int i = 0; i < kNumFrames; i++) {
- LOG(DEBUG) << "Importing graphic buffer from camera [" << buffers[indices[i]].deviceId
- << "]";
- const AHardwareBuffer_Desc* pDesc = reinterpret_cast<const AHardwareBuffer_Desc*>(
- &buffers[indices[i]].buffer.description);
-
- AHardwareBuffer* hardwareBuffer;
- status_t status = AHardwareBuffer_createFromHandle(
- pDesc, buffers[indices[i]].buffer.nativeHandle,
- AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE, &hardwareBuffer);
-
- if (status != NO_ERROR) {
- LOG(ERROR) << "Can't create AHardwareBuffer from handle. Error: " << status;
- return {};
- }
-
- mSession->mInputPointers[i].gpu_data_pointer = static_cast<void*>(hardwareBuffer);
-
- // Keep a reference to the EVS graphic buffers, so we can
- // release them after Surround View stitching is done.
- mSession->mEvsGraphicBuffers = buffers;
- }
- }
-
- // Notify the session that a new set of frames is ready
- mSession->mFramesSignal.notify_all();
-
- ATRACE_END();
-
- return {};
-}
-
-Return<void> SurroundView3dSession::FramesHandler::notify(const EvsEventDesc& event) {
- switch(event.aType) {
- case EvsEventType::STREAM_STOPPED:
- // The Surround View STREAM_STOPPED event is generated when the
- // service finished processing the queued frames. So it does not
- // rely on the Evs STREAM_STOPPED event.
- LOG(INFO) << "Received a STREAM_STOPPED event from Evs.";
- break;
-
- case EvsEventType::PARAMETER_CHANGED:
- LOG(INFO) << "Camera parameter " << std::hex << event.payload[0]
- << " is set to " << event.payload[1];
- break;
-
- // Below events are ignored in reference implementation.
- case EvsEventType::STREAM_STARTED:
- [[fallthrough]];
- case EvsEventType::FRAME_DROPPED:
- [[fallthrough]];
- case EvsEventType::TIMEOUT:
- LOG(INFO) << "Event " << std::hex << static_cast<unsigned>(event.aType)
- << "is received but ignored.";
- break;
- default:
- LOG(ERROR) << "Unknown event id: " << static_cast<unsigned>(event.aType);
- break;
- }
-
- return {};
-}
-
-void SurroundView3dSession::processFrames() {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- ATRACE_BEGIN("SV core lib method: Start3dPipeline");
- if (mSurroundView->Start3dPipeline()) {
- LOG(INFO) << "Start3dPipeline succeeded";
- } else {
- LOG(ERROR) << "Start3dPipeline failed";
- return;
- }
- ATRACE_END();
-
- while (true) {
- {
- unique_lock<mutex> lock(mAccessLock);
-
- if (mStreamState != RUNNING) {
- break;
- }
-
- mFramesSignal.wait(lock, [this]() { return mProcessingEvsFrames; });
- }
-
- handleFrames(mSequenceId);
-
- {
- // Set the boolean to false to receive the next set of frames.
- scoped_lock<mutex> lock(mAccessLock);
- mProcessingEvsFrames = false;
- }
- }
-
- // Notify the SV client that no new results will be delivered.
- LOG(DEBUG) << "Notify SvEvent::STREAM_STOPPED";
- mStream->notify(SvEvent::STREAM_STOPPED);
-
- {
- scoped_lock<mutex> lock(mAccessLock);
- mStreamState = STOPPED;
- mStream = nullptr;
- LOG(DEBUG) << "Stream marked STOPPED.";
- }
-
- ATRACE_END();
-}
-
-SurroundView3dSession::SurroundView3dSession(sp<IEvsEnumerator> pEvs,
- VhalHandler* vhalHandler,
- AnimationModule* animationModule,
- IOModuleConfig* pConfig) :
- mEvs(pEvs),
- mStreamState(STOPPED),
- mVhalHandler(vhalHandler),
- mAnimationModule(animationModule),
- mIOModuleConfig(pConfig) {}
-
-SurroundView3dSession::~SurroundView3dSession() {
- // In case the client did not call stopStream properly, we should stop the
- // stream explicitly. Otherwise the process thread will take forever to
- // join.
- stopStream();
-
- // Waiting for the process thread to finish the buffered frames.
- if (mProcessThread.joinable()) {
- mProcessThread.join();
- }
-
- mEvs->closeCamera(mCamera);
-}
-
-// Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewSession.
-Return<SvResult> SurroundView3dSession::startStream(
- const sp<ISurroundViewStream>& stream) {
- LOG(DEBUG) << __FUNCTION__;
- scoped_lock<mutex> lock(mAccessLock);
-
- if (!mIsInitialized && !initialize()) {
- LOG(ERROR) << "There is an error while initializing the use case. "
- << "Exiting";
- return SvResult::INTERNAL_ERROR;
- }
-
- if (mStreamState != STOPPED) {
- LOG(ERROR) << "Ignoring startVideoStream call when a stream is "
- << "already running.";
- return SvResult::INTERNAL_ERROR;
- }
-
- if (mViews.empty()) {
- LOG(ERROR) << "No views have been set for current Surround View"
- << "3d Session. Please call setViews before starting"
- << "the stream.";
- return SvResult::VIEW_NOT_SET;
- }
-
- if (stream == nullptr) {
- LOG(ERROR) << "The input stream is invalid";
- return SvResult::INTERNAL_ERROR;
- }
- mStream = stream;
-
- mSequenceId = 0;
- startEvs();
-
- if (mVhalHandler != nullptr) {
- if (!mVhalHandler->startPropertiesUpdate()) {
- LOG(WARNING) << "VhalHandler cannot be started properly";
- }
- } else {
- LOG(WARNING) << "VhalHandler is null. Ignored";
- }
-
- // TODO(b/158131080): the STREAM_STARTED event is not implemented in EVS
- // reference implementation yet. Once implemented, this logic should be
- // moved to EVS notify callback.
- LOG(DEBUG) << "Notify SvEvent::STREAM_STARTED";
- mStream->notify(SvEvent::STREAM_STARTED);
- mProcessingEvsFrames = false;
-
- // Start the frame generation thread
- mStreamState = RUNNING;
-
- mProcessThread = thread([this]() {
- processFrames();
- });
-
- return SvResult::OK;
-}
-
-Return<void> SurroundView3dSession::stopStream() {
- LOG(DEBUG) << __FUNCTION__;
- unique_lock <mutex> lock(mAccessLock);
-
- if (mVhalHandler != nullptr) {
- mVhalHandler->stopPropertiesUpdate();
- } else {
- LOG(WARNING) << "VhalHandler is null. Ignored";
- }
-
- if (mStreamState == RUNNING) {
- // Tell the processFrames loop to stop processing frames
- mStreamState = STOPPING;
-
- // Stop the EVS stream asynchronizely
- mCamera->stopVideoStream();
- }
-
- return {};
-}
-
-Return<void> SurroundView3dSession::doneWithFrames(
- const SvFramesDesc& svFramesDesc){
- LOG(DEBUG) << __FUNCTION__;
- scoped_lock <mutex> lock(mAccessLock);
-
- mFramesRecord.inUse = false;
-
- (void)svFramesDesc;
- return {};
-}
-
-// Methods from ISurroundView3dSession follow.
-Return<SvResult> SurroundView3dSession::setViews(
- const hidl_vec<View3d>& views) {
- LOG(DEBUG) << __FUNCTION__;
- scoped_lock <mutex> lock(mAccessLock);
-
- if (views.size() == 0) {
- LOG(ERROR) << "Empty view argument, at-least one view is required.";
- return SvResult::VIEW_NOT_SET;
- }
-
- mViews.resize(views.size());
- for (int i=0; i<views.size(); i++) {
- mViews[i] = views[i];
- }
-
- return SvResult::OK;
-}
-
-Return<SvResult> SurroundView3dSession::set3dConfig(const Sv3dConfig& sv3dConfig) {
- LOG(DEBUG) << __FUNCTION__;
- scoped_lock <mutex> lock(mAccessLock);
-
- if (sv3dConfig.width <=0 || sv3dConfig.width > 4096) {
- LOG(WARNING) << "The width of 3d config is out of the range (0, 4096]"
- << "Ignored!";
- return SvResult::INVALID_ARG;
- }
-
- if (sv3dConfig.height <=0 || sv3dConfig.height > 4096) {
- LOG(WARNING) << "The height of 3d config is out of the range (0, 4096]"
- << "Ignored!";
- return SvResult::INVALID_ARG;
- }
-
- mConfig.width = sv3dConfig.width;
- mConfig.height = sv3dConfig.height;
- mConfig.carDetails = sv3dConfig.carDetails;
-
- if (mStream != nullptr) {
- LOG(DEBUG) << "Notify SvEvent::CONFIG_UPDATED";
- mStream->notify(SvEvent::CONFIG_UPDATED);
- }
-
- return SvResult::OK;
-}
-
-Return<void> SurroundView3dSession::get3dConfig(get3dConfig_cb _hidl_cb) {
- LOG(DEBUG) << __FUNCTION__;
-
- _hidl_cb(mConfig);
- return {};
-}
-
-bool VerifyAndGetOverlays(const OverlaysData& overlaysData, std::vector<Overlay>* svCoreOverlays) {
- // Clear the overlays.
- svCoreOverlays->clear();
-
- // Check size of shared memory matches overlaysMemoryDesc.
- const int kVertexSize = 16;
- const int kIdSize = 2;
- int memDescSize = 0;
- for (auto& overlayMemDesc : overlaysData.overlaysMemoryDesc) {
- memDescSize += kIdSize + kVertexSize * overlayMemDesc.verticesCount;
- }
- if (overlaysData.overlaysMemory.size() < memDescSize) {
- LOG(ERROR) << "Allocated shared memory size is less than overlaysMemoryDesc size.";
- return false;
- }
-
- // Map memory.
- sp<IMemory> pSharedMemory = mapMemory(overlaysData.overlaysMemory);
- if(pSharedMemory == nullptr) {
- LOG(ERROR) << "mapMemory failed.";
- return false;
- }
-
- // Get Data pointer.
- uint8_t* pData = static_cast<uint8_t*>(
- static_cast<void*>(pSharedMemory->getPointer()));
- if (pData == nullptr) {
- LOG(ERROR) << "Shared memory getPointer() failed.";
- return false;
- }
-
- int idOffset = 0;
- set<uint16_t> overlayIdSet;
- for (auto& overlayMemDesc : overlaysData.overlaysMemoryDesc) {
-
- if (overlayIdSet.find(overlayMemDesc.id) != overlayIdSet.end()) {
- LOG(ERROR) << "Duplicate id within memory descriptor.";
- svCoreOverlays->clear();
- return false;
- }
- overlayIdSet.insert(overlayMemDesc.id);
-
- if(overlayMemDesc.verticesCount < 3) {
- LOG(ERROR) << "Less than 3 vertices.";
- svCoreOverlays->clear();
- return false;
- }
-
- if (overlayMemDesc.overlayPrimitive == OverlayPrimitive::TRIANGLES &&
- overlayMemDesc.verticesCount % 3 != 0) {
- LOG(ERROR) << "Triangles primitive does not have vertices "
- << "multiple of 3.";
- svCoreOverlays->clear();
- return false;
- }
-
- const uint16_t overlayId = *((uint16_t*)(pData + idOffset));
-
- if (overlayId != overlayMemDesc.id) {
- LOG(ERROR) << "Overlay id mismatch " << overlayId << ", " << overlayMemDesc.id;
- svCoreOverlays->clear();
- return false;
- }
-
- // Copy over shared memory data to sv core overlays.
- Overlay svCoreOverlay;
- svCoreOverlay.id = overlayMemDesc.id;
- svCoreOverlay.vertices.resize(overlayMemDesc.verticesCount);
- uint8_t* verticesDataPtr = pData + idOffset + kIdSize;
- memcpy(svCoreOverlay.vertices.data(), verticesDataPtr,
- kVertexSize * overlayMemDesc.verticesCount);
- svCoreOverlays->push_back(svCoreOverlay);
-
- idOffset += kIdSize + (kVertexSize * overlayMemDesc.verticesCount);
- }
-
- return true;
-}
-
-Return<SvResult> SurroundView3dSession::updateOverlays(const OverlaysData& overlaysData) {
- LOG(DEBUG) << __FUNCTION__;
-
- scoped_lock <mutex> lock(mAccessLock);
- if(!VerifyAndGetOverlays(overlaysData, &mOverlays)) {
- LOG(ERROR) << "VerifyAndGetOverlays failed.";
- return SvResult::INVALID_ARG;
- }
-
- mOverlayIsUpdated = true;
- return SvResult::OK;
-}
-
-Return<void> SurroundView3dSession::projectCameraPointsTo3dSurface(
- const hidl_vec<Point2dInt>& cameraPoints, const hidl_string& cameraId,
- projectCameraPointsTo3dSurface_cb _hidl_cb) {
- LOG(DEBUG) << __FUNCTION__;
- bool cameraIdFound = false;
- int cameraIndex = 0;
- std::vector<Point3dFloat> points3d;
-
- // Note: mEvsCameraIds must be in the order front, right, rear, left.
- for (auto& evsCameraId : mEvsCameraIds) {
- if (cameraId == evsCameraId) {
- cameraIdFound = true;
- LOG(DEBUG) << "Camera id found for projection: " << cameraId;
- break;
- }
- cameraIndex++;
- }
-
- if (!cameraIdFound) {
- LOG(ERROR) << "Camera id not found for projection: " << cameraId;
- _hidl_cb(points3d);
- return {};
- }
-
- for (const auto& cameraPoint : cameraPoints) {
- Point3dFloat point3d = {false, 0.0, 0.0, 0.0};
-
- // Verify if camera point is within the camera resolution bounds.
- const Size2dInteger cameraSize = mCameraParams[cameraIndex].size;
- point3d.isValid = (cameraPoint.x >= 0 && cameraPoint.x < cameraSize.width &&
- cameraPoint.y >= 0 && cameraPoint.y < cameraSize.height);
- if (!point3d.isValid) {
- LOG(WARNING) << "Camera point (" << cameraPoint.x << ", " << cameraPoint.y
- << ") is out of camera resolution bounds.";
- points3d.push_back(point3d);
- continue;
- }
-
- // Project points using mSurroundView function.
- const Coordinate2dInteger camCoord(cameraPoint.x, cameraPoint.y);
- Coordinate3dFloat projPoint3d(0.0, 0.0, 0.0);
- point3d.isValid =
- mSurroundView->GetProjectionPointFromRawCameraToSurroundView3d(camCoord,
- cameraIndex,
- &projPoint3d);
- // Convert projPoint3d in meters to point3d which is in milli-meters.
- point3d.x = projPoint3d.x * 1000.0;
- point3d.y = projPoint3d.y * 1000.0;
- point3d.z = projPoint3d.z * 1000.0;
- points3d.push_back(point3d);
- }
- _hidl_cb(points3d);
- return {};
-}
-
-bool SurroundView3dSession::handleFrames(int sequenceId) {
- LOG(INFO) << __FUNCTION__ << "Handling sequenceId " << sequenceId << ".";
-
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- // TODO(b/157498592): Now only one sets of EVS input frames and one SV
- // output frame is supported. Implement buffer queue for both of them.
- {
- scoped_lock<mutex> lock(mAccessLock);
-
- if (mFramesRecord.inUse) {
- LOG(DEBUG) << "Notify SvEvent::FRAME_DROPPED";
- mStream->notify(SvEvent::FRAME_DROPPED);
- return true;
- }
-
- // Release the frames for GPU solution.
- mCamera->doneWithFrame_1_1(mEvsGraphicBuffers);
- }
-
- // If the width/height was changed, re-allocate the Graphic Buffer and
- // update the Surround View core lib.
- if (mOutputWidth != mConfig.width
- || mOutputHeight != mConfig.height) {
- mOutputWidth = mConfig.width;
- mOutputHeight = mConfig.height;
- mOutputPointer.height = mOutputHeight;
- mOutputPointer.width = mOutputWidth;
- mOutputPointer.format = Format::RGBA;
-
- Size2dInteger size = Size2dInteger(mOutputWidth, mOutputHeight);
- mSurroundView->Update3dOutputResolution(size);
-
- mSvTexture = new GraphicBuffer(mOutputWidth,
- mOutputHeight,
- HAL_PIXEL_FORMAT_RGBA_8888,
- 1,
- GRALLOC_USAGE_HW_TEXTURE,
- "SvTexture");
- if (mSvTexture->initCheck() == OK) {
- LOG(INFO) << "Successfully allocated Graphic Buffer";
- } else {
- LOG(ERROR) << "Failed to allocate Graphic Buffer";
- return false;
- }
- }
-
- ATRACE_BEGIN("SV core lib method: Set3dOverlay");
- // Set 3d overlays.
- {
- scoped_lock<mutex> lock(mAccessLock);
- if (mOverlayIsUpdated) {
- if (!mSurroundView->Set3dOverlay(mOverlays)) {
- LOG(ERROR) << "Set 3d overlays failed.";
- }
- mOverlayIsUpdated = false;
- }
- }
- ATRACE_END();
-
- ATRACE_BEGIN("VhalHandler method: getPropertyValues");
- // Get the latest VHal property values
- if (mVhalHandler != nullptr) {
- if (!mVhalHandler->getPropertyValues(&mPropertyValues)) {
- LOG(ERROR) << "Failed to get property values";
- }
- } else {
- LOG(WARNING) << "VhalHandler is null. Ignored";
- }
- ATRACE_END();
-
- ATRACE_BEGIN("AnimationModule method: getUpdatedAnimationParams");
- vector<AnimationParam> params;
- if (mAnimationModule != nullptr) {
- params = mAnimationModule->getUpdatedAnimationParams(mPropertyValues);
- } else {
- LOG(WARNING) << "AnimationModule is null. Ignored";
- }
- ATRACE_END();
-
- ATRACE_BEGIN("SV core lib method: SetAnimations");
- if (!params.empty()) {
- mSurroundView->SetAnimations(params);
- } else {
- LOG(INFO) << "AnimationParams is empty. Ignored";
- }
- ATRACE_END();
-
- // Get the view.
- // TODO(161399517): Only single view is currently supported, add support for multiple views.
- const View3d view3d = mViews[0];
- const RotationQuat quat = view3d.pose.rotation;
- const Translation trans = view3d.pose.translation;
- const std::array<float, 4> viewQuaternion = {quat.x, quat.y, quat.z, quat.w};
- const std::array<float, 3> viewTranslation = {trans.x, trans.y, trans.z};
-
- ATRACE_BEGIN("SV core lib method: Get3dSurroundView");
- if (mSurroundView->Get3dSurroundView(
- mInputPointers, viewQuaternion, viewTranslation, &mOutputPointer)) {
- LOG(INFO) << "Get3dSurroundView succeeded";
- } else {
- LOG(ERROR) << "Get3dSurroundView failed. "
- << "Using memset to initialize to gray.";
- memset(mOutputPointer.cpu_data_pointer, kGrayColor,
- mOutputHeight * mOutputWidth * kOutputNumChannels);
- }
- ATRACE_END();
-
- // Release the frames for GPU solution.
- ATRACE_BEGIN("Release the evs frames");
- mCamera->doneWithFrame_1_1(mEvsGraphicBuffers);
- ATRACE_END();
-
- ATRACE_BEGIN("Lock output texture (gpu to cpu)");
- void* textureDataPtr = nullptr;
- mSvTexture->lock(GRALLOC_USAGE_SW_WRITE_OFTEN
- | GRALLOC_USAGE_SW_READ_NEVER,
- &textureDataPtr);
- ATRACE_END();
-
- if (!textureDataPtr) {
- LOG(ERROR) << "Failed to gain write access to GraphicBuffer!";
- return false;
- }
-
- ATRACE_BEGIN("Copy output result");
- // Note: there is a chance that the stride of the texture is not the
- // same as the width. For example, when the input frame is 1920 * 1080,
- // the width is 1080, but the stride is 2048. So we'd better copy the
- // data line by line, instead of single memcpy.
- uint8_t* writePtr = static_cast<uint8_t*>(textureDataPtr);
- uint8_t* readPtr = static_cast<uint8_t*>(mOutputPointer.cpu_data_pointer);
- const int readStride = mOutputWidth * kOutputNumChannels;
- const int writeStride = mSvTexture->getStride() * kOutputNumChannels;
- if (readStride == writeStride) {
- memcpy(writePtr, readPtr, readStride * mSvTexture->getHeight());
- } else {
- for (int i=0; i<mSvTexture->getHeight(); i++) {
- memcpy(writePtr, readPtr, readStride);
- writePtr = writePtr + writeStride;
- readPtr = readPtr + readStride;
- }
- }
- LOG(INFO) << "memcpy finished!";
- ATRACE_END();
-
- ATRACE_BEGIN("Unlock output texture (cpu to gpu)");
- mSvTexture->unlock();
- ATRACE_END();
-
- ANativeWindowBuffer* buffer = mSvTexture->getNativeBuffer();
- LOG(DEBUG) << "ANativeWindowBuffer->handle: " << buffer->handle;
-
- {
- scoped_lock<mutex> lock(mAccessLock);
-
- mFramesRecord.frames.svBuffers.resize(1);
- SvBuffer& svBuffer = mFramesRecord.frames.svBuffers[0];
- svBuffer.viewId = 0;
- svBuffer.hardwareBuffer.nativeHandle = buffer->handle;
- AHardwareBuffer_Desc* pDesc =
- reinterpret_cast<AHardwareBuffer_Desc *>(
- &svBuffer.hardwareBuffer.description);
- pDesc->width = mOutputWidth;
- pDesc->height = mOutputHeight;
- pDesc->layers = 1;
- pDesc->usage = GRALLOC_USAGE_HW_TEXTURE;
- pDesc->stride = mSvTexture->getStride();
- pDesc->format = HAL_PIXEL_FORMAT_RGBA_8888;
- mFramesRecord.frames.timestampNs = elapsedRealtimeNano();
- mFramesRecord.frames.sequenceId = sequenceId;
-
- mFramesRecord.inUse = true;
- mStream->receiveFrames(mFramesRecord.frames);
- }
-
- ATRACE_END();
-
- return true;
-}
-
-bool SurroundView3dSession::initialize() {
- lock_guard<mutex> lock(mAccessLock, adopt_lock);
-
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- if (!setupEvs()) {
- LOG(ERROR) << "Failed to setup EVS components for 3d session";
- return false;
- }
-
- // TODO(b/150412555): ask core-lib team to add API description for "create"
- // method in the .h file.
- // The create method will never return a null pointer based the API
- // description.
- mSurroundView = unique_ptr<SurroundView>(Create());
-
- SurroundViewStaticDataParams params =
- SurroundViewStaticDataParams(
- mCameraParams,
- mIOModuleConfig->sv2dConfig.sv2dParams,
- mIOModuleConfig->sv3dConfig.sv3dParams,
- vector<float>(std::begin(kUndistortionScales),
- std::end(kUndistortionScales)),
- mIOModuleConfig->sv2dConfig.carBoundingBox,
- mIOModuleConfig->carModelConfig.carModel.texturesMap,
- mIOModuleConfig->carModelConfig.carModel.partsMap);
- ATRACE_BEGIN("SV core lib method: SetStaticData");
- mSurroundView->SetStaticData(params);
- ATRACE_END();
-
- ATRACE_BEGIN("Allocate cpu buffers");
-
- mInputPointers.resize(kNumFrames);
- for (int i = 0; i < kNumFrames; i++) {
- // We do not need to explicitly allocate cpu_data_pointer any more since the
- // input data handling is purely on GPU side now.
- mInputPointers[i].width = mCameraParams[i].size.width;
- mInputPointers[i].height = mCameraParams[i].size.height;
- mInputPointers[i].format = Format::RGBA;
- }
-
- mOutputWidth = mIOModuleConfig->sv3dConfig.sv3dParams.resolution.width;
- mOutputHeight = mIOModuleConfig->sv3dConfig.sv3dParams.resolution.height;
-
- mConfig.width = mOutputWidth;
- mConfig.height = mOutputHeight;
- mConfig.carDetails = SvQuality::HIGH;
-
- mOutputPointer.height = mOutputHeight;
- mOutputPointer.width = mOutputWidth;
- mOutputPointer.format = Format::RGBA;
- mOutputPointer.cpu_data_pointer =
- static_cast<void*>(new char[mOutputHeight * mOutputWidth * kOutputNumChannels]);
-
- if (!mOutputPointer.cpu_data_pointer) {
- LOG(ERROR) << "Memory allocation failed. Exiting.";
- return false;
- }
- ATRACE_END();
-
- ATRACE_BEGIN("Allocate output texture");
- mSvTexture = new GraphicBuffer(mOutputWidth,
- mOutputHeight,
- HAL_PIXEL_FORMAT_RGBA_8888,
- 1,
- GRALLOC_USAGE_HW_TEXTURE,
- "SvTexture");
-
- if (mSvTexture->initCheck() == OK) {
- LOG(INFO) << "Successfully allocated Graphic Buffer";
- } else {
- LOG(ERROR) << "Failed to allocate Graphic Buffer";
- return false;
- }
- ATRACE_END();
-
- mIsInitialized = true;
-
- ATRACE_END();
-
- return true;
-}
-
-bool SurroundView3dSession::setupEvs() {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- // Reads the camera related information from the config object
- const string evsGroupId = mIOModuleConfig->cameraConfig.evsGroupId;
-
- // Setup for EVS
- LOG(INFO) << "Requesting camera list";
- mEvs->getCameraList_1_1(
- [this, evsGroupId] (hidl_vec<CameraDesc> cameraList) {
- LOG(INFO) << "Camera list callback received " << cameraList.size();
- for (auto&& cam : cameraList) {
- LOG(INFO) << "Found camera " << cam.v1.cameraId;
- if (cam.v1.cameraId == evsGroupId) {
- mCameraDesc = cam;
- }
- }
- });
-
- bool foundCfg = false;
- std::unique_ptr<Stream> targetCfg(new Stream());
-
- // This logic picks the configuration with the largest area that supports
- // RGBA8888 format
- int32_t maxArea = 0;
- camera_metadata_entry_t streamCfgs;
- if (!find_camera_metadata_entry(
- reinterpret_cast<camera_metadata_t *>(mCameraDesc.metadata.data()),
- ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
- &streamCfgs)) {
- // Stream configurations are found in metadata
- RawStreamConfig *ptr = reinterpret_cast<RawStreamConfig *>(
- streamCfgs.data.i32);
- for (unsigned idx = 0; idx < streamCfgs.count; idx += kStreamCfgSz) {
- if (ptr->direction ==
- ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT &&
- ptr->format == HAL_PIXEL_FORMAT_RGBA_8888) {
-
- if (ptr->width * ptr->height > maxArea) {
- targetCfg->id = ptr->id;
- targetCfg->width = ptr->width;
- targetCfg->height = ptr->height;
-
- // This client always wants below input data format
- targetCfg->format =
- static_cast<GraphicsPixelFormat>(
- HAL_PIXEL_FORMAT_RGBA_8888);
-
- maxArea = ptr->width * ptr->height;
-
- foundCfg = true;
- }
- }
- ++ptr;
- }
- } else {
- LOG(WARNING) << "No stream configuration data is found; "
- << "default parameters will be used.";
- }
-
- if (!foundCfg) {
- LOG(INFO) << "No config was found";
- targetCfg = nullptr;
- return false;
- }
-
- string camId = mCameraDesc.v1.cameraId.c_str();
- mCamera = mEvs->openCamera_1_1(camId.c_str(), *targetCfg);
- if (mCamera == nullptr) {
- LOG(ERROR) << "Failed to allocate EVS Camera interface for " << camId;
- return false;
- } else {
- LOG(INFO) << "Logical camera " << camId << " is opened successfully";
- }
-
- mEvsCameraIds = mIOModuleConfig->cameraConfig.evsCameraIds;
- if (mEvsCameraIds.size() < kNumFrames) {
- LOG(ERROR) << "Incorrect camera info is stored in the camera config";
- return false;
- }
-
- map<string, AndroidCameraParams> cameraIdToAndroidParameters;
- for (const auto& id : mEvsCameraIds) {
- AndroidCameraParams params;
- if (getAndroidCameraParams(mCamera, id, params)) {
- cameraIdToAndroidParameters.emplace(id, params);
- LOG(INFO) << "Camera parameters are fetched successfully for "
- << "physical camera: " << id;
- } else {
- LOG(ERROR) << "Failed to get camera parameters for "
- << "physical camera: " << id;
- return false;
- }
- }
-
- mCameraParams =
- convertToSurroundViewCameraParams(cameraIdToAndroidParameters);
-
- for (auto& camera : mCameraParams) {
- camera.size.width = targetCfg->width;
- camera.size.height = targetCfg->height;
- camera.circular_fov = 179;
- }
-
- // Add validity mask filenames.
- for (int i = 0; i < mCameraParams.size(); i++) {
- mCameraParams[i].validity_mask_filename = mIOModuleConfig->cameraConfig.maskFilenames[i];
- }
- ATRACE_END();
- return true;
-}
-
-bool SurroundView3dSession::startEvs() {
- ATRACE_BEGIN(__PRETTY_FUNCTION__);
-
- mFramesHandler = new FramesHandler(mCamera, this);
- Return<EvsResult> result = mCamera->startVideoStream(mFramesHandler);
- if (result != EvsResult::OK) {
- LOG(ERROR) << "Failed to start video stream";
- return false;
- } else {
- LOG(INFO) << "Video stream was started successfully";
- }
-
- ATRACE_END();
-
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/SurroundView3dSession.h b/cpp/surround_view/service-impl/SurroundView3dSession.h
deleted file mode 100644
index 39bcfb8..0000000
--- a/cpp/surround_view/service-impl/SurroundView3dSession.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#pragma once
-
-#include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
-#include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
-#include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
-#include <android/hardware/automotive/sv/1.0/types.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundView3dSession.h>
-
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-#include "AnimationModule.h"
-#include "VhalHandler.h"
-
-#include <thread>
-
-#include <ui/GraphicBuffer.h>
-
-using namespace ::android::hardware::automotive::evs::V1_1;
-using namespace ::android::hardware::automotive::sv::V1_0;
-using namespace ::android::hardware::automotive::vehicle::V2_0;
-using namespace ::android_auto::surround_view;
-
-using ::android::hardware::Return;
-using ::android::hardware::hidl_vec;
-using ::android::sp;
-using ::std::condition_variable;
-
-using BufferDesc_1_0 = ::android::hardware::automotive::evs::V1_0::BufferDesc;
-using BufferDesc_1_1 = ::android::hardware::automotive::evs::V1_1::BufferDesc;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-class SurroundView3dSession : public ISurroundView3dSession {
-
- /*
- * FramesHandler:
- * This class can be used to receive camera imagery from an IEvsCamera implementation. It will
- * hold onto the most recent image buffer, returning older ones.
- * Note that the video frames are delivered on a background thread, while the control interface
- * is actuated from the applications foreground thread.
- */
- class FramesHandler : public IEvsCameraStream {
- public:
- FramesHandler(sp<IEvsCamera> pCamera, sp<SurroundView3dSession> pSession);
-
- private:
- // Implementation for ::android::hardware::automotive::evs::V1_0::IEvsCameraStream
- Return<void> deliverFrame(const BufferDesc_1_0& buffer) override;
-
- // Implementation for ::android::hardware::automotive::evs::V1_1::IEvsCameraStream
- Return<void> deliverFrame_1_1(const hidl_vec<BufferDesc_1_1>& buffer) override;
- Return<void> notify(const EvsEventDesc& event) override;
-
- // Values initialized as startup
- sp<IEvsCamera> mCamera;
-
- sp<SurroundView3dSession> mSession;
- };
-
-public:
- // TODO(b/158479099): use strong pointer for VhalHandler
- SurroundView3dSession(sp<IEvsEnumerator> pEvs,
- VhalHandler* vhalHandler,
- AnimationModule* animationModule,
- IOModuleConfig* pConfig);
- ~SurroundView3dSession();
- bool initialize();
-
- // Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewSession.
- Return<SvResult> startStream(
- const sp<ISurroundViewStream>& stream) override;
- Return<void> stopStream() override;
- Return<void> doneWithFrames(const SvFramesDesc& svFramesDesc) override;
-
- // Methods from ISurroundView3dSession follow.
- Return<SvResult> setViews(const hidl_vec<View3d>& views) override;
- Return<SvResult> set3dConfig(const Sv3dConfig& sv3dConfig) override;
- Return<void> get3dConfig(get3dConfig_cb _hidl_cb) override;
- Return<SvResult> updateOverlays(const OverlaysData& overlaysData);
- Return<void> projectCameraPointsTo3dSurface(
- const hidl_vec<Point2dInt>& cameraPoints,
- const hidl_string& cameraId,
- projectCameraPointsTo3dSurface_cb _hidl_cb);
-
-private:
- void processFrames();
-
- // Set up and open the Evs camera(s), triggered when session is created.
- bool setupEvs();
-
- // Start Evs camera video stream, triggered when SV stream is started.
- bool startEvs();
-
- bool handleFrames(int sequenceId);
-
- enum StreamStateValues {
- STOPPED,
- RUNNING,
- STOPPING,
- DEAD,
- };
-
- // EVS Enumerator to control the start/stop of the Evs Stream
- sp<IEvsEnumerator> mEvs;
-
- // Instance and metadata for the opened Evs Camera
- sp<IEvsCamera> mCamera;
- CameraDesc mCameraDesc;
- std::vector<SurroundViewCameraParams> mCameraParams;
-
- // Stream subscribed for the session.
- sp<ISurroundViewStream> mStream GUARDED_BY(mAccessLock);
- StreamStateValues mStreamState GUARDED_BY(mAccessLock);
-
- std::thread mProcessThread; // The thread we'll use to process frames
-
- // Reference to the inner class, to handle the incoming Evs frames
- sp<FramesHandler> mFramesHandler;
-
- // Used to signal a set of frames is ready
- condition_variable mFramesSignal GUARDED_BY(mAccessLock);
- bool mProcessingEvsFrames GUARDED_BY(mAccessLock);
-
- int mSequenceId;
-
- struct FramesRecord {
- SvFramesDesc frames;
- bool inUse = false;
- };
-
- FramesRecord mFramesRecord GUARDED_BY(mAccessLock);
-
- // Synchronization necessary to deconflict mCaptureThread from the main service thread
- std::mutex mAccessLock;
-
- std::vector<View3d> mViews GUARDED_BY(mAccessLock);
-
- Sv3dConfig mConfig GUARDED_BY(mAccessLock);
-
- std::vector<std::string> mEvsCameraIds GUARDED_BY(mAccessLock);
-
- std::unique_ptr<SurroundView> mSurroundView GUARDED_BY(mAccessLock);
-
- std::vector<SurroundViewInputBufferPointers>
- mInputPointers GUARDED_BY(mAccessLock);
- SurroundViewResultPointer mOutputPointer GUARDED_BY(mAccessLock);
- int mOutputWidth, mOutputHeight GUARDED_BY(mAccessLock);
-
- sp<GraphicBuffer> mSvTexture GUARDED_BY(mAccessLock);
-
- bool mIsInitialized GUARDED_BY(mAccessLock) = false;
-
- VhalHandler* mVhalHandler;
- AnimationModule* mAnimationModule;
- IOModuleConfig* mIOModuleConfig;
-
- std::vector<Overlay> mOverlays GUARDED_BY(mAccessLock);
- bool mOverlayIsUpdated GUARDED_BY(mAccessLock) = false;
-
- std::vector<VehiclePropValue> mPropertyValues;
-
- hidl_vec<BufferDesc_1_1> mEvsGraphicBuffers;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/SurroundView3dSessionTests.cpp b/cpp/surround_view/service-impl/SurroundView3dSessionTests.cpp
deleted file mode 100644
index afe8f07..0000000
--- a/cpp/surround_view/service-impl/SurroundView3dSessionTests.cpp
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define LOG_TAG "SurroundView3dSessionTests"
-
-#include "AnimationModule.h"
-#include "IOModule.h"
-#include "SurroundView3dSession.h"
-#include "VhalHandler.h"
-#include "mock-evs/MockEvsEnumerator.h"
-#include "mock-evs/MockSurroundViewCallback.h"
-
-#include <android-base/logging.h>
-#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
-#include <android/hidl/allocator/1.0/IAllocator.h>
-#include <android/hidl/memory/1.0/IMemory.h>
-#include <gtest/gtest.h>
-#include <hidlmemory/mapping.h>
-
-#include <time.h>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-
-using ::android::sp;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::automotive::sv::V1_0::OverlayMemoryDesc;
-using ::android::hidl::allocator::V1_0::IAllocator;
-using ::android::hidl::memory::V1_0::IMemory;
-
-const char* kSvConfigFilename = "vendor/etc/automotive/sv/sv_sample_config.xml";
-
-// Sv 3D output height and width set by the config file.
-const int kSv3dWidth = 1920;
-const int kSv3dHeight = 1080;
-
-// Constants for overlays.
-const int kVertexByteSize = (3 * sizeof(float)) + 4;
-const int kIdByteSize = 2;
-
-class SurroundView3dSessionTests : public ::testing::Test {
-protected:
- // Setup sv3d session without vhal and animations.
- void SetupSv3dSession() {
- mFakeEvs = new MockEvsEnumerator();
- mIoModule = new IOModule(kSvConfigFilename);
- EXPECT_EQ(mIoModule->initialize(), IOStatus::OK);
-
- mIoModule->getConfig(&mIoModuleConfig);
-
- mSv3dSession = new SurroundView3dSession(mFakeEvs, nullptr,
- nullptr,
- &mIoModuleConfig);
-
- EXPECT_TRUE(mSv3dSession->initialize());
- mSv3dCallback = new MockSurroundViewCallback(mSv3dSession);
- vector<View3d> views = {
- {
- .viewId = 0,
- .pose = {
- .rotation = {.x = 0, .y = 0, .z = 0, .w = 1.0f},
- .translation = {.x = 0, .y = 0, .z = 0},
- },
- .horizontalFov = 90,
- }};
- mSv3dSession->setViews(views);
- }
-
- // Setup sv3d session with vhal and animations.
- void SetupSv3dSessionVhalAnimation() {
- mFakeEvs = new MockEvsEnumerator();
- mIoModule = new IOModule(kSvConfigFilename);
- EXPECT_EQ(mIoModule->initialize(), IOStatus::OK);
-
- mIoModule->getConfig(&mIoModuleConfig);
-
- mVhalHandler = new VhalHandler();
- ASSERT_TRUE(mVhalHandler->initialize(VhalHandler::UpdateMethod::GET, 10));
-
- mAnimationModule = new AnimationModule(mIoModuleConfig.carModelConfig.carModel.partsMap,
- mIoModuleConfig.carModelConfig.carModel.texturesMap,
- mIoModuleConfig.carModelConfig.animationConfig.animations);
-
- const std::vector<uint64_t> animationPropertiesToRead =
- getAnimationPropertiesToRead(mIoModuleConfig.carModelConfig.animationConfig);
- ASSERT_TRUE(mVhalHandler->setPropertiesToRead(animationPropertiesToRead));
-
- mSv3dSessionAnimations = new SurroundView3dSession(mFakeEvs, mVhalHandler,
- mAnimationModule,
- &mIoModuleConfig);
-
- EXPECT_TRUE(mSv3dSessionAnimations->initialize());
-
- mSv3dCallbackAnimations = new MockSurroundViewCallback(mSv3dSessionAnimations);
- vector<View3d> views = {
- // View 0
- {
- .viewId = 0,
- .pose = {
- .rotation = {.x = 0, .y = 0, .z = 0, .w = 1.0f},
- .translation = {.x = 0, .y = 0, .z = 0},
- },
- .horizontalFov = 90,
- }};
-
- mSv3dSessionAnimations->setViews(views);
- }
-
- // Helper function to get list of vhal properties to read from car config file for animations.
- std::vector<uint64_t> getAnimationPropertiesToRead(const AnimationConfig& animationConfig) {
- std::set<uint64_t> propertiesSet;
- for (const auto& animation : animationConfig.animations) {
- for (const auto& opPair : animation.gammaOpsMap) {
- propertiesSet.insert(opPair.first);
- }
-
- for (const auto& opPair : animation.textureOpsMap) {
- propertiesSet.insert(opPair.first);
- }
-
- for (const auto& opPair : animation.rotationOpsMap) {
- propertiesSet.insert(opPair.first);
- }
-
- for (const auto& opPair : animation.translationOpsMap) {
- propertiesSet.insert(opPair.first);
- }
- }
- std::vector<uint64_t> propertiesToRead;
- propertiesToRead.assign(propertiesSet.begin(), propertiesSet.end());
- return propertiesToRead;
- }
-
- void TearDown() override {
- mSv3dSession = nullptr;
- mFakeEvs = nullptr;
- mSv3dCallback = nullptr;
- delete mVhalHandler;
- delete mAnimationModule;
- delete mIoModule;
- }
-
- sp<IEvsEnumerator> mFakeEvs;
- IOModule* mIoModule;
- IOModuleConfig mIoModuleConfig;
- sp<SurroundView3dSession> mSv3dSession;
- sp<MockSurroundViewCallback> mSv3dCallback;
-
- VhalHandler* mVhalHandler;
- AnimationModule* mAnimationModule;
- sp<SurroundView3dSession> mSv3dSessionAnimations;
- sp<MockSurroundViewCallback> mSv3dCallbackAnimations;
-};
-
-TEST_F(SurroundView3dSessionTests, startAndStop3dSession) {
- SetupSv3dSession();
- EXPECT_EQ(mSv3dSession->startStream(mSv3dCallback), SvResult::OK);
- sleep(5);
- mSv3dSession->stopStream();
- EXPECT_GT(mSv3dCallback->getReceivedFramesCount(), 0);
-}
-
-TEST_F(SurroundView3dSessionTests, get3dConfigSuccess) {
- SetupSv3dSession();
- Sv3dConfig sv3dConfig;
- mSv3dSession->get3dConfig([&sv3dConfig](const Sv3dConfig& config) { sv3dConfig = config; });
-
- EXPECT_EQ(sv3dConfig.width, kSv3dWidth);
- EXPECT_EQ(sv3dConfig.height, kSv3dHeight);
- EXPECT_EQ(sv3dConfig.carDetails, SvQuality::HIGH);
-}
-
-// Sets a different config and checks of the received config matches.
-TEST_F(SurroundView3dSessionTests, setAndGet3dConfigSuccess) {
- SetupSv3dSession();
- Sv3dConfig sv3dConfigSet = {kSv3dWidth / 2, kSv3dHeight / 2, SvQuality::LOW};
-
- EXPECT_EQ(mSv3dSession->set3dConfig(sv3dConfigSet), SvResult::OK);
-
- Sv3dConfig sv3dConfigReceived;
- mSv3dSession->get3dConfig(
- [&sv3dConfigReceived](const Sv3dConfig& config) { sv3dConfigReceived = config; });
-
- EXPECT_EQ(sv3dConfigReceived.width, sv3dConfigSet.width);
- EXPECT_EQ(sv3dConfigReceived.height, sv3dConfigSet.height);
- EXPECT_EQ(sv3dConfigReceived.carDetails, sv3dConfigSet.carDetails);
-}
-
-// Projects center of each cameras and checks if valid projected point is received.
-TEST_F(SurroundView3dSessionTests, projectPoints3dSuccess) {
- SetupSv3dSession();
- hidl_vec<Point2dInt> points2dCamera = {
- /*Center point*/ {.x = kSv3dWidth / 2, .y = kSv3dHeight / 2}};
-
- std::vector<hidl_string> cameraIds = {"/dev/video60", "/dev/video61", "/dev/video62",
- "/dev/video63"};
-
- for (int i = 0; i < cameraIds.size(); i++) {
- mSv3dSession
- ->projectCameraPointsTo3dSurface(points2dCamera, cameraIds[i],
- [](const hidl_vec<Point3dFloat>& projectedPoints) {
- EXPECT_TRUE(projectedPoints[0].isValid);
- });
- }
-}
-
-std::pair<hidl_memory, sp<IMemory>> GetMappedSharedMemory(int bytesSize) {
- const auto nullResult = std::make_pair(hidl_memory(), nullptr);
-
- sp<IAllocator> ashmemAllocator = IAllocator::getService("ashmem");
- if (ashmemAllocator.get() == nullptr) {
- return nullResult;
- }
-
- // Allocate shared memory.
- hidl_memory hidlMemory;
- bool allocateSuccess = false;
- Return<void> result =
- ashmemAllocator->allocate(bytesSize, [&](bool success, const hidl_memory& hidlMem) {
- if (!success) {
- return;
- }
- allocateSuccess = success;
- hidlMemory = hidlMem;
- });
-
- // Check result of allocated memory.
- if (!result.isOk() || !allocateSuccess) {
- return nullResult;
- }
-
- // Map shared memory.
- sp<IMemory> pIMemory = mapMemory(hidlMemory);
- if (pIMemory.get() == nullptr) {
- return nullResult;
- }
-
- return std::make_pair(hidlMemory, pIMemory);
-}
-
-void SetIndexOfOverlaysMemory(const std::vector<OverlayMemoryDesc>& overlaysMemDesc,
- sp<IMemory> pIMemory, int indexPosition, uint16_t indexValue) {
- // Count the number of vertices until the index.
- int totalVerticesCount = 0;
- for (int i = 0; i < indexPosition; i++) {
- totalVerticesCount += overlaysMemDesc[i].verticesCount;
- }
-
- const int indexBytePosition =
- (indexPosition * kIdByteSize) + (kVertexByteSize * totalVerticesCount);
-
- uint8_t* pSharedMemoryData = reinterpret_cast<uint8_t*>((void*)pIMemory->getPointer());
- pSharedMemoryData += indexBytePosition;
- uint16_t* pIndex16bit = reinterpret_cast<uint16_t*>(pSharedMemoryData);
-
- // Modify shared memory.
- pIMemory->update();
- *pIndex16bit = indexValue;
- pIMemory->commit();
-}
-
-std::pair<OverlaysData, sp<IMemory>> GetSampleOverlaysData() {
- OverlaysData overlaysData;
- overlaysData.overlaysMemoryDesc.resize(2);
-
- int sharedMemBytesSize = 0;
- OverlayMemoryDesc overlayMemDesc1, overlayMemDesc2;
- overlayMemDesc1.id = 0;
- overlayMemDesc1.verticesCount = 6;
- overlayMemDesc1.overlayPrimitive = OverlayPrimitive::TRIANGLES;
- overlaysData.overlaysMemoryDesc[0] = overlayMemDesc1;
- sharedMemBytesSize += kIdByteSize + kVertexByteSize * overlayMemDesc1.verticesCount;
-
- overlayMemDesc2.id = 1;
- overlayMemDesc2.verticesCount = 4;
- overlayMemDesc2.overlayPrimitive = OverlayPrimitive::TRIANGLES_STRIP;
- overlaysData.overlaysMemoryDesc[1] = overlayMemDesc2;
- sharedMemBytesSize += kIdByteSize + kVertexByteSize * overlayMemDesc2.verticesCount;
-
- std::pair<hidl_memory, sp<IMemory>> sharedMem = GetMappedSharedMemory(sharedMemBytesSize);
- sp<IMemory> pIMemory = sharedMem.second;
- if (pIMemory.get() == nullptr) {
- return std::make_pair(OverlaysData(), nullptr);
- }
-
- // Get pointer to shared memory data and set all bytes to 0.
- uint8_t* pSharedMemoryData = reinterpret_cast<uint8_t*>((void*)pIMemory->getPointer());
- pIMemory->update();
- memset(pSharedMemoryData, 0, sharedMemBytesSize);
- pIMemory->commit();
-
- std::vector<OverlayMemoryDesc> overlaysDesc = {overlayMemDesc1, overlayMemDesc2};
-
- // Set indexes in shared memory.
- SetIndexOfOverlaysMemory(overlaysDesc, pIMemory, 0, overlayMemDesc1.id);
- SetIndexOfOverlaysMemory(overlaysDesc, pIMemory, 1, overlayMemDesc2.id);
-
- overlaysData.overlaysMemoryDesc = overlaysDesc;
- overlaysData.overlaysMemory = sharedMem.first;
-
- return std::make_pair(overlaysData, pIMemory);
-}
-
-// Verifies a valid overlay can be updated while streaming.
-TEST_F(SurroundView3dSessionTests, updateOverlaysSuccess) {
- SetupSv3dSession();
- std::pair<OverlaysData, sp<IMemory>> overlaysData = GetSampleOverlaysData();
- ASSERT_NE(overlaysData.second, nullptr);
- EXPECT_EQ(mSv3dSession->startStream(mSv3dCallback), SvResult::OK);
- SvResult result = mSv3dSession->updateOverlays(overlaysData.first);
- mSv3dSession->stopStream();
- EXPECT_EQ(result, SvResult::OK);
-}
-
-// Setup sv 3d sessin with vhal and animations and verify frames are received successfully.
-TEST_F(SurroundView3dSessionTests, vhalAnimationSuccess) {
- SetupSv3dSessionVhalAnimation();
- EXPECT_EQ(mSv3dSessionAnimations->startStream(mSv3dCallbackAnimations), SvResult::OK);
- sleep(5);
- mSv3dSessionAnimations->stopStream();
- EXPECT_GT(mSv3dCallbackAnimations->getReceivedFramesCount(), 0);
-}
-
-} // namespace
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/SurroundViewService.cpp b/cpp/surround_view/service-impl/SurroundViewService.cpp
deleted file mode 100644
index e8a2ffd..0000000
--- a/cpp/surround_view/service-impl/SurroundViewService.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2020 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 <android-base/logging.h>
-
-#include "SurroundViewService.h"
-
-using namespace android_auto::surround_view;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-std::mutex SurroundViewService::sLock;
-sp<SurroundViewService> SurroundViewService::sService;
-sp<SurroundView2dSession> SurroundViewService::sSurroundView2dSession;
-sp<SurroundView3dSession> SurroundViewService::sSurroundView3dSession;
-
-const std::string kCameraIds[] = {"0", "1", "2", "3"};
-static const int kVhalUpdateRate = 10;
-
-SurroundViewService::SurroundViewService() :
- mVhalHandler(nullptr), mAnimationModule(nullptr), mIOModule(nullptr) {
- mVhalHandler = new VhalHandler();
- mIOModule = new IOModule("/vendor/etc/automotive/sv/sv_sample_config.xml");
-}
-
-SurroundViewService::~SurroundViewService() {
- if (mVhalHandler != nullptr) {
- delete mVhalHandler;
- }
-
- if (mIOModule != nullptr) {
- delete mIOModule;
- }
-
- if (mAnimationModule != nullptr) {
- delete mAnimationModule;
- }
-}
-
-sp<SurroundViewService> SurroundViewService::getInstance() {
- std::scoped_lock<std::mutex> lock(sLock);
- if (sService == nullptr) {
- sService = new SurroundViewService();
- if (!sService->initialize()) {
- LOG(ERROR) << "Cannot initialize the service properly";
- sService = nullptr;
- return nullptr;
- }
- }
- return sService;
-}
-
-std::vector<uint64_t> getAnimationPropertiesToRead(const AnimationConfig& animationConfig) {
- std::set<uint64_t> propertiesSet;
- for(const auto& animation: animationConfig.animations) {
- for(const auto& opPair : animation.gammaOpsMap) {
- propertiesSet.insert(opPair.first);
- }
-
- for(const auto& opPair : animation.textureOpsMap) {
- propertiesSet.insert(opPair.first);
- }
-
- for(const auto& opPair : animation.rotationOpsMap) {
- propertiesSet.insert(opPair.first);
- }
-
- for(const auto& opPair : animation.translationOpsMap) {
- propertiesSet.insert(opPair.first);
- }
- }
- std::vector<uint64_t> propertiesToRead;
- propertiesToRead.assign(propertiesSet.begin(), propertiesSet.end());
- return propertiesToRead;
-}
-
-bool SurroundViewService::initialize() {
- // Get the EVS manager service
- LOG(INFO) << "Acquiring EVS Enumerator";
- mEvs = IEvsEnumerator::getService("default");
- if (mEvs == nullptr) {
- LOG(ERROR) << "getService returned NULL. Exiting.";
- return false;
- }
-
- IOStatus status = mIOModule->initialize();
- if (status != IOStatus::OK) {
- LOG(ERROR) << "IO Module cannot be initialized properly";
- return false;
- }
-
- if (!mIOModule->getConfig(&mConfig)) {
- LOG(ERROR) << "Cannot parse Car Config file properly";
- return false;
- }
-
- // Since we only keep one instance of the SurroundViewService and initialize
- // method is always called after the constructor, it is safe to put the
- // allocation here and the de-allocation in service's constructor.
- mAnimationModule = new AnimationModule(
- mConfig.carModelConfig.carModel.partsMap,
- mConfig.carModelConfig.carModel.texturesMap,
- mConfig.carModelConfig.animationConfig.animations);
-
- // Initialize the VHal Handler with update method and rate.
- // TODO(b/157498592): The update rate should align with the EVS camera
- // update rate.
- if (mVhalHandler->initialize(VhalHandler::GET, kVhalUpdateRate)) {
- // Initialize the vhal handler properties to read.
- std::vector<uint64_t> propertiesToRead;
-
- // Add animation properties to read if 3d and animations are enabled.
- if (mConfig.sv3dConfig.sv3dEnabled && mConfig.sv3dConfig.sv3dAnimationsEnabled) {
- const std::vector<uint64_t> animationPropertiesToRead =
- getAnimationPropertiesToRead(mConfig.carModelConfig.animationConfig);
- propertiesToRead.insert(propertiesToRead.end(), animationPropertiesToRead.begin(),
- animationPropertiesToRead.end());
- }
-
- // Call vhal handler setPropertiesToRead with all properties.
- if (!mVhalHandler->setPropertiesToRead(propertiesToRead)) {
- LOG(WARNING) << "VhalHandler setPropertiesToRead failed.";
- }
- } else {
- LOG(WARNING) << "VhalHandler cannot be initialized properly";
- }
-
- return true;
-}
-
-Return<void> SurroundViewService::getCameraIds(getCameraIds_cb _hidl_cb) {
- hidl_vec<hidl_string> cameraIds = {kCameraIds[0], kCameraIds[1],
- kCameraIds[2], kCameraIds[3]};
- _hidl_cb(cameraIds);
- return {};
-}
-
-Return<void> SurroundViewService::start2dSession(start2dSession_cb _hidl_cb) {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(sLock);
-
- if (sSurroundView2dSession != nullptr) {
- LOG(WARNING) << "Only one 2d session is supported at the same time";
- _hidl_cb(nullptr, SvResult::INTERNAL_ERROR);
- } else {
- sSurroundView2dSession = new SurroundView2dSession(mEvs, &mConfig);
- if (sSurroundView2dSession->initialize()) {
- _hidl_cb(sSurroundView2dSession, SvResult::OK);
- } else {
- _hidl_cb(nullptr, SvResult::INTERNAL_ERROR);
- }
- }
- return {};
-}
-
-Return<SvResult> SurroundViewService::stop2dSession(
- const sp<ISurroundView2dSession>& sv2dSession) {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(sLock);
-
- if (sv2dSession != nullptr && sv2dSession == sSurroundView2dSession) {
- sSurroundView2dSession = nullptr;
- return SvResult::OK;
- } else {
- LOG(ERROR) << __FUNCTION__ << ": Invalid argument";
- return SvResult::INVALID_ARG;
- }
-}
-
-Return<void> SurroundViewService::start3dSession(start3dSession_cb _hidl_cb) {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(sLock);
-
- if (sSurroundView3dSession != nullptr) {
- LOG(WARNING) << "Only one 3d session is supported at the same time";
- _hidl_cb(nullptr, SvResult::INTERNAL_ERROR);
- } else {
- sSurroundView3dSession = new SurroundView3dSession(mEvs,
- mVhalHandler,
- mAnimationModule,
- &mConfig);
- if (sSurroundView3dSession->initialize()) {
- _hidl_cb(sSurroundView3dSession, SvResult::OK);
- } else {
- _hidl_cb(nullptr, SvResult::INTERNAL_ERROR);
- }
- }
- return {};
-}
-
-Return<SvResult> SurroundViewService::stop3dSession(
- const sp<ISurroundView3dSession>& sv3dSession) {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(sLock);
-
- if (sv3dSession != nullptr && sv3dSession == sSurroundView3dSession) {
- sSurroundView3dSession = nullptr;
- return SvResult::OK;
- } else {
- LOG(ERROR) << __FUNCTION__ << ": Invalid argument";
- return SvResult::INVALID_ARG;
- }
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/SurroundViewService.h b/cpp/surround_view/service-impl/SurroundViewService.h
deleted file mode 100644
index 6950a27..0000000
--- a/cpp/surround_view/service-impl/SurroundViewService.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#pragma once
-
-#include "SurroundView2dSession.h"
-#include "SurroundView3dSession.h"
-#include "AnimationModule.h"
-#include "IOModule.h"
-#include "VhalHandler.h"
-
-#include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
-#include <android/hardware/automotive/sv/1.0/types.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewService.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundView2dSession.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundView3dSession.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-#include <thread>
-
-using namespace ::android::hardware::automotive::evs::V1_1;
-using namespace ::android::hardware::automotive::sv::V1_0;
-using ::android::hardware::Return;
-using ::android::sp;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-class SurroundViewService : public ISurroundViewService {
-public:
- // Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewService follow.
- Return<void> getCameraIds(getCameraIds_cb _hidl_cb) override;
- Return<void> start2dSession(start2dSession_cb _hidl_cb) override;
- Return<SvResult> stop2dSession(
- const sp<ISurroundView2dSession>& sv2dSession) override;
-
- Return<void> start3dSession(start3dSession_cb _hidl_cb) override;
- Return<SvResult> stop3dSession(
- const sp<ISurroundView3dSession>& sv3dSession) override;
-
- static sp<SurroundViewService> getInstance();
-private:
- SurroundViewService();
- ~SurroundViewService();
-
- VhalHandler* mVhalHandler;
- AnimationModule* mAnimationModule;
- IOModule* mIOModule;
- IOModuleConfig mConfig;
-
- bool initialize();
- sp<IEvsEnumerator> mEvs;
-
- static std::mutex sLock;
- static sp<SurroundViewService> sService GUARDED_BY(sLock);
-
- static sp<SurroundView2dSession> sSurroundView2dSession GUARDED_BY(sLock);
- static sp<SurroundView3dSession> sSurroundView3dSession GUARDED_BY(sLock);
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/VhalHandler.cpp b/cpp/surround_view/service-impl/VhalHandler.cpp
deleted file mode 100644
index 79ced83..0000000
--- a/cpp/surround_view/service-impl/VhalHandler.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright 2020 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 "VhalHandler.h"
-
-#include <chrono>
-#include <cmath>
-#include <condition_variable>
-#include <mutex>
-
-#include <android-base/logging.h>
-#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
-#include <time.h>
-#include <utils/SystemClock.h>
-#include <utils/Timers.h>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using vehicle::V2_0::IVehicle;
-using vehicle::V2_0::StatusCode;
-using vehicle::V2_0::VehiclePropertyType;
-using vehicle::V2_0::VehiclePropValue;
-
-bool VhalHandler::initialize(UpdateMethod updateMethod, int rate) {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(mAccessLock);
-
- if (mIsInitialized) {
- LOG(ERROR) << "Vehicle Handler is already initialized.";
- return false;
- }
-
- LOG(INFO) << "Connecting to Vehicle HAL";
- mVhalServicePtr = IVehicle::getService();
- if (mVhalServicePtr.get() == nullptr) {
- LOG(ERROR) << "Vehicle HAL getService failed.";
- return false;
- }
-
- if (rate < 1 || rate > 100) {
- LOG(ERROR) << "Rate must be in the range [1, 100].";
- return false;
- }
-
- if (mUpdateMethod == UpdateMethod::SUBSCRIBE) {
- LOG(ERROR) << "Update method Subscribe is not currently implemented.";
- return false;
- }
-
- mUpdateMethod = updateMethod;
- mRate = rate;
- mIsInitialized = true;
- mIsUpdateActive = false;
-
- return true;
-}
-
-void VhalHandler::pollProperties() {
- LOG(DEBUG) << "Polling thread started.";
- while (true) {
- nsecs_t startTime = elapsedRealtimeNano();
-
- // Copy properties to read.
- std::vector<VehiclePropValue> propertiesToRead;
- int rate;
- {
- std::scoped_lock<std::mutex> lock(mAccessLock);
- if (!mIsUpdateActive) {
- LOG(DEBUG) << "Exiting polling thread.";
- break;
- }
- propertiesToRead = mPropertiesToRead;
- rate = mRate;
- }
-
- // Make get call for each VHAL property.
- // Write to back property values, note lock is not needed as only this thread uses it.
- std::vector<VehiclePropValue> vehiclePropValuesUpdated;
- for (auto& propertyToRead : propertiesToRead) {
- StatusCode statusResult;
- VehiclePropValue propValueResult;
- mVhalServicePtr->get(propertyToRead,
- [&statusResult,
- &propValueResult](StatusCode status,
- const VehiclePropValue& propValue) {
- statusResult = status;
- propValueResult = propValue;
- });
- if (statusResult != StatusCode::OK) {
- LOG(WARNING) << "Failed to read vhal property: " << propertyToRead.prop
- << ", with status code: " << static_cast<int32_t>(statusResult);
- } else {
- vehiclePropValuesUpdated.push_back(propValueResult);
- }
- }
-
- // Update property values by swapping with updated property values.
- {
- std::scoped_lock<std::mutex> lock(mAccessLock);
- std::swap(mPropertyValues, vehiclePropValuesUpdated);
- }
-
- std::unique_lock<std::mutex> sleepLock(mPollThreadSleepMutex);
- // Sleep to generate frames at kTargetFrameRate.
- // rate is number of updates per seconds,
- // Target time period between two updates in nano-seconds = (10 ^ 9) / rate.
- const nsecs_t kTargetRateNs = std::pow(10, 9) / mRate;
- const nsecs_t now = elapsedRealtimeNano();
- const nsecs_t workTimeNs = now - startTime;
- const nsecs_t sleepDurationNs = kTargetRateNs - workTimeNs;
- if (sleepDurationNs > 0) {
- // Sleep for sleepDurationNs or until a stop signal is received.
- mPollThreadCondition.wait_for(sleepLock, std::chrono::nanoseconds(sleepDurationNs),
- [this]() { return mPollStopSleeping; });
- }
- }
-}
-
-bool VhalHandler::startPropertiesUpdate() {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(mAccessLock);
-
- // Check Vhal service is initialized.
- if (!mIsInitialized) {
- LOG(ERROR) << "VHAL handler not initialized.";
- return false;
- }
-
- if (mIsUpdateActive) {
- LOG(ERROR) << "Polling is already started.";
- return false;
- }
-
- mIsUpdateActive = true;
-
- {
- std::scoped_lock<std::mutex> sleepLock(mPollThreadSleepMutex);
- mPollStopSleeping = false;
- }
-
- // Start polling thread if updated method is GET.
- if (mUpdateMethod == UpdateMethod::GET) {
- mPollingThread = std::thread([this]() { pollProperties(); });
- }
-
- return true;
-}
-
-bool VhalHandler::setPropertiesToRead(const std::vector<VehiclePropValue>& propertiesToRead) {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(mAccessLock);
-
- // Replace property ids to read.
- mPropertiesToRead = propertiesToRead;
-
- return true;
-}
-
-bool VhalHandler::setPropertiesToRead(const std::vector<uint64_t>& propertiesToRead) {
- LOG(DEBUG) << __FUNCTION__;
- std::vector<VehiclePropValue> vhalPropValues;
- for (const auto& property : propertiesToRead) {
- VehiclePropValue propValue;
- // Higher 32 bits = property id, lower 32 bits = area id.
- propValue.areaId = property & 0xFFFFFFFF;
- propValue.prop = (property >> 32) & 0xFFFFFFFF;
- vhalPropValues.push_back(propValue);
- }
- return setPropertiesToRead(vhalPropValues);
-}
-
-bool VhalHandler::getPropertyValues(std::vector<VehiclePropValue>* property_values) {
- LOG(DEBUG) << __FUNCTION__;
- std::scoped_lock<std::mutex> lock(mAccessLock);
-
- // Check Vhal service is initialized.
- if (!mIsInitialized) {
- LOG(ERROR) << "VHAL handler not initialized.";
- return false;
- }
-
- // Copy current property values to argument.
- *property_values = mPropertyValues;
-
- return true;
-}
-
-bool VhalHandler::stopPropertiesUpdate() {
- LOG(DEBUG) << __FUNCTION__;
- {
- std::scoped_lock<std::mutex> lock(mAccessLock);
-
- // Check Vhal service is initialized.
- if (!mIsInitialized) {
- LOG(ERROR) << "VHAL handler not initialized.";
- return false;
- }
-
- if (!mIsUpdateActive) {
- LOG(ERROR) << "Polling is already stopped.";
- return false;
- }
-
- mIsUpdateActive = false;
- }
-
- // Wake up the polling thread.
- {
- std::scoped_lock<std::mutex> sleepLock(mPollThreadSleepMutex);
- mPollStopSleeping = true;
- }
- mPollThreadCondition.notify_one();
-
- // Wait for polling thread to exit.
- mPollingThread.join();
-
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/VhalHandler.h b/cpp/surround_view/service-impl/VhalHandler.h
deleted file mode 100644
index 029e414..0000000
--- a/cpp/surround_view/service-impl/VhalHandler.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_VHALHANDLER_H_
-#define SURROUND_VIEW_SERVICE_IMPL_VHALHANDLER_H_
-
-#include <mutex>
-#include <thread>
-#include <vector>
-
-#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
-
-using android::sp;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// Vhal handler cache vhal properties needed and updates them at a fixed rate.
-class VhalHandler {
-public:
- // Enumeration for the method to use for updating the VHAL properties,
- enum UpdateMethod {
- // Makes a periodic get call in a polling thread.
- // Use when VHAL implementation does not support multiple clients in subscribe calls.
- GET = 0,
-
- // Subscribes to the VHAL properties, to receive values periodically in a callback.
- // Use when VHAL implementation support multiple clients in subscribe calls.
- // NOTE: Currently not implemented.
- SUBSCRIBE
- };
-
- // Empty vhal handler constructor.
- VhalHandler() : mIsInitialized(false), mUpdateMethod(GET), mRate(0), mIsUpdateActive(false) {}
-
- // Initializes the VHAL handler.
- // Valid range of rate is [1, 100] Hz.
- // For subscribe the rate must be within each properties min and maximum sampling rate.
- // For get, higher rate may result in excessive binder calls and increased latency.
- bool initialize(UpdateMethod updateMethod, int rate);
-
- // List of VHAL properties to read, can include vendor specific VHAL properties.
- // The updated method determines if properties are updated using get or subscribe calls.
- bool setPropertiesToRead(const std::vector<vehicle::V2_0::VehiclePropValue>& propertiesToRead);
-
- // Convenience function to set vhal properties in a format returned from IO Module.
- // uint64_t = (32 bits vhal property id) | (32 bits area id).
- bool setPropertiesToRead(const std::vector<uint64_t>& propertiesToRead);
-
- // Starts updating the VHAL properties with the specified rate.
- bool startPropertiesUpdate();
-
- // Gets the last updated VHAL property values.
- // property_values is empty if startPropertiesUpdate() has not been called.
- bool getPropertyValues(std::vector<vehicle::V2_0::VehiclePropValue>* property_values);
-
- // Stops updating the VHAL properties.
- // For Get method, waits for the polling thread to exit.
- bool stopPropertiesUpdate();
-
-private:
- // Thread function to poll properties.
- void pollProperties();
-
- // Pointer to VHAL service.
- sp<vehicle::V2_0::IVehicle> mVhalServicePtr;
-
- // Mutex for locking VHAL properties data.
- std::mutex mAccessLock;
-
- // Initialized parameters.
- bool mIsInitialized;
- UpdateMethod mUpdateMethod;
- int mRate;
- bool mIsUpdateActive;
-
- // GET method related data members.
- std::thread mPollingThread;
- std::mutex mPollThreadSleepMutex;
- std::condition_variable mPollThreadCondition;
- bool mPollStopSleeping;
-
- // List of properties to read.
- std::vector<vehicle::V2_0::VehiclePropValue> mPropertiesToRead;
-
- // Updated list of property values.
- std::vector<vehicle::V2_0::VehiclePropValue> mPropertyValues;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
-
-#endif // SURROUND_VIEW_SERVICE_IMPL_VHALHANDLER_H_
diff --git a/cpp/surround_view/service-impl/VhalHandlerTests.cpp b/cpp/surround_view/service-impl/VhalHandlerTests.cpp
deleted file mode 100644
index cd7c0e3..0000000
--- a/cpp/surround_view/service-impl/VhalHandlerTests.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define LOG_TAG "VhalHandlerTests"
-
-#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
-#include "VhalHandler.h"
-
-#include <gtest/gtest.h>
-#include <time.h>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-namespace {
-
-using vehicle::V2_0::VehicleArea;
-using vehicle::V2_0::VehicleProperty;
-
-void SetSamplePropertiesToRead(VhalHandler* vhalHandler) {
- std::vector<vehicle::V2_0::VehiclePropValue> propertiesToRead;
- vehicle::V2_0::VehiclePropValue propertyRead;
- propertyRead.prop = static_cast<int32_t>(VehicleProperty::INFO_MAKE);
- propertiesToRead.push_back(propertyRead);
- ASSERT_TRUE(vhalHandler->setPropertiesToRead(propertiesToRead));
-}
-
-void SetSamplePropertiesToReadInt64(VhalHandler* vhalHandler) {
- std::vector<uint64_t> propertiesToRead;
- uint64_t propertyInt64 = (static_cast<uint64_t>(VehicleProperty::INFO_MAKE) << 32) |
- static_cast<uint64_t>(VehicleArea::GLOBAL);
- propertiesToRead.push_back(propertyInt64);
- ASSERT_TRUE(vhalHandler->setPropertiesToRead(propertiesToRead));
-}
-
-TEST(VhalhandlerTests, UninitializedStartFail) {
- VhalHandler vhalHandler;
- ASSERT_FALSE(vhalHandler.startPropertiesUpdate());
-}
-
-TEST(VhalhandlerTests, StartStopSuccess) {
- VhalHandler vhalHandler;
- ASSERT_TRUE(vhalHandler.initialize(VhalHandler::UpdateMethod::GET, 10));
- SetSamplePropertiesToRead(&vhalHandler);
- ASSERT_TRUE(vhalHandler.startPropertiesUpdate());
- ASSERT_TRUE(vhalHandler.stopPropertiesUpdate());
-}
-
-TEST(VhalhandlerTests, StopTwiceFail) {
- VhalHandler vhalHandler;
- ASSERT_TRUE(vhalHandler.initialize(VhalHandler::UpdateMethod::GET, 10));
- SetSamplePropertiesToRead(&vhalHandler);
- ASSERT_TRUE(vhalHandler.startPropertiesUpdate());
- ASSERT_TRUE(vhalHandler.stopPropertiesUpdate());
- ASSERT_FALSE(vhalHandler.stopPropertiesUpdate());
-}
-
-TEST(VhalhandlerTests, NoStartFail) {
- VhalHandler vhalHandler;
- ASSERT_TRUE(vhalHandler.initialize(VhalHandler::UpdateMethod::GET, 10));
- SetSamplePropertiesToRead(&vhalHandler);
- ASSERT_FALSE(vhalHandler.stopPropertiesUpdate());
-}
-
-TEST(VhalhandlerTests, StartAgainSuccess) {
- VhalHandler vhalHandler;
- ASSERT_TRUE(vhalHandler.initialize(VhalHandler::UpdateMethod::GET, 10));
- SetSamplePropertiesToRead(&vhalHandler);
- ASSERT_TRUE(vhalHandler.startPropertiesUpdate());
- ASSERT_TRUE(vhalHandler.stopPropertiesUpdate());
- ASSERT_TRUE(vhalHandler.startPropertiesUpdate());
- ASSERT_TRUE(vhalHandler.stopPropertiesUpdate());
-}
-
-TEST(VhalhandlerTests, GetMethodSuccess) {
- VhalHandler vhalHandler;
- ASSERT_TRUE(vhalHandler.initialize(VhalHandler::UpdateMethod::GET, 10));
-
- SetSamplePropertiesToRead(&vhalHandler);
-
- ASSERT_TRUE(vhalHandler.startPropertiesUpdate());
- sleep(1);
- std::vector<vehicle::V2_0::VehiclePropValue> propertyValues;
- EXPECT_TRUE(vhalHandler.getPropertyValues(&propertyValues));
- EXPECT_EQ(propertyValues.size(), 1);
-
- EXPECT_TRUE(vhalHandler.stopPropertiesUpdate());
-}
-
-TEST(VhalhandlerTests, GetMethodInt64Success) {
- VhalHandler vhalHandler;
- ASSERT_TRUE(vhalHandler.initialize(VhalHandler::UpdateMethod::GET, 10));
-
- SetSamplePropertiesToReadInt64(&vhalHandler);
-
- ASSERT_TRUE(vhalHandler.startPropertiesUpdate());
- sleep(1);
- std::vector<vehicle::V2_0::VehiclePropValue> propertyValues;
- EXPECT_TRUE(vhalHandler.getPropertyValues(&propertyValues));
- EXPECT_EQ(propertyValues.size(), 1);
-
- EXPECT_TRUE(vhalHandler.stopPropertiesUpdate());
-}
-
-} // namespace
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/android.automotive.sv.service@1.0-impl.rc b/cpp/surround_view/service-impl/android.automotive.sv.service@1.0-impl.rc
deleted file mode 100644
index 4207e8f..0000000
--- a/cpp/surround_view/service-impl/android.automotive.sv.service@1.0-impl.rc
+++ /dev/null
@@ -1,5 +0,0 @@
-service sv_service_impl /vendor/bin/android.automotive.sv.service@1.0-impl
- class hal
- user automotive_evs
- group automotive_evs
- disabled
diff --git a/cpp/surround_view/service-impl/core_lib.h b/cpp/surround_view/service-impl/core_lib.h
deleted file mode 100644
index 0265ca8..0000000
--- a/cpp/surround_view/service-impl/core_lib.h
+++ /dev/null
@@ -1,928 +0,0 @@
-/*
- * Copyright 2020 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 WIRELESS_ANDROID_AUTOMOTIVE_CAML_SURROUND_VIEW_CORE_LIB_H_
-#define WIRELESS_ANDROID_AUTOMOTIVE_CAML_SURROUND_VIEW_CORE_LIB_H_
-
-#include <array>
-#include <cstdint>
-#include <map>
-#include <string>
-#include <vector>
-
-namespace android_auto {
-namespace surround_view {
-
-// bounding box (bb)
-// It is used to describe the car model bounding box in 3D.
-// It assumes z = 0 and only x, y are used in the struct.
-// Of course, it is compatible to the 2d version bounding box and may be used
-// for other bounding box purpose (e.g., 2d bounding box in image).
-struct BoundingBox {
- // (x,y) is bounding box's top left corner coordinate.
- float x;
- float y;
-
- // (width, height) is the size of the bounding box.
- float width;
- float height;
-
- BoundingBox() : x(0.0f), y(0.0f), width(0.0f), height(0.0f) {}
-
- BoundingBox(float x_, float y_, float width_, float height_) :
- x(x_), y(y_), width(width_), height(height_) {}
-
- BoundingBox(const BoundingBox& bb_) :
- x(bb_.x), y(bb_.y), width(bb_.width), height(bb_.height) {}
-
- // Checks if data is valid.
- bool IsValid() const { return width >= 0 && height >= 0; }
-
- bool operator==(const BoundingBox& rhs) const {
- return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height;
- }
-
- BoundingBox& operator=(const BoundingBox& rhs) {
- x = rhs.x;
- y = rhs.y;
- width = rhs.width;
- height = rhs.height;
- return *this;
- }
-};
-
-template <typename T>
-struct Coordinate2dBase {
- // x coordinate.
- T x;
-
- // y coordinate.
- T y;
-
- Coordinate2dBase() : x(0), y(0) {}
-
- Coordinate2dBase(T x_, T y_) : x(x_), y(y_) {}
-
- bool operator==(const Coordinate2dBase& rhs) const { return x == rhs.x && y == rhs.y; }
-
- Coordinate2dBase& operator=(const Coordinate2dBase& rhs) {
- x = rhs.x;
- y = rhs.y;
- return *this;
- }
-};
-
-// integer type size.
-typedef Coordinate2dBase<int> Coordinate2dInteger;
-
-// float type size.
-typedef Coordinate2dBase<float> Coordinate2dFloat;
-
-struct Coordinate3dFloat {
- // x coordinate.
- float x;
-
- // y coordinate.
- float y;
-
- // z coordinate.
- float z;
-
- Coordinate3dFloat() : x(0), y(0), z(0) {}
-
- Coordinate3dFloat(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {}
-
- bool operator==(const Coordinate3dFloat& rhs) const { return x == rhs.x && y == rhs.y; }
-
- Coordinate3dFloat& operator=(const Coordinate3dFloat& rhs) {
- x = rhs.x;
- y = rhs.y;
- return *this;
- }
-};
-
-// pixel weight used for illumination assessment
-struct PixelWeight {
- // x and y are the coordinates (absolute value) in image space.
- // pixel coordinate x in horizontal direction.
- float x;
-
- // pixel coordinate y in vertical direction.
- float y;
-
- // pixel weight, range in [0, 1].
- float weight;
-
- PixelWeight() : x(-1), y(-1), weight(0) {}
-
- PixelWeight(int x_, int y_, int weight_) : x(x_), y(y_), weight(weight_) {}
-
- bool operator==(const PixelWeight& rhs) const {
- return x == rhs.x && y == rhs.y && weight == rhs.weight;
- }
-
- PixelWeight& operator=(const PixelWeight& rhs) {
- x = rhs.x;
- y = rhs.y;
- weight = rhs.weight;
- return *this;
- }
-};
-
-// base size 2d type template.
-template <typename T>
-struct Size2dBase {
- // width of size.
- T width;
-
- // height of size.
- T height;
-
- Size2dBase() : width(0), height(0) {}
-
- Size2dBase(T width_, T height_) : width(width_), height(height_) {}
-
- bool IsValid() const { return width > 0 && height > 0; }
-
- bool operator==(const Size2dBase& rhs) const {
- return width == rhs.width && height == rhs.height;
- }
-
- Size2dBase& operator=(const Size2dBase& rhs) {
- width = rhs.width;
- height = rhs.height;
- return *this;
- }
-};
-
-// integer type size.
-typedef Size2dBase<int> Size2dInteger;
-
-// float type size.
-typedef Size2dBase<float> Size2dFloat;
-
-// surround view 2d parameters
-struct SurroundView2dParams {
- // surround view 2d image resolution (width, height).
- Size2dInteger resolution;
-
- // the physical size of surround view 2d area in surround view coordinate.
- // (surround view coordinate is defined as X rightward, Y forward and
- // the origin lies on the center of the (symmetric) bowl (ground).
- // When bowl is not used, surround view coordinate origin lies on the
- // center of car model bounding box.)
- // The unit should be consistent with camera extrinsics (translation).
- Size2dFloat physical_size;
-
- // the center of surround view 2d area in surround view coordinate
- // (consistent with extrinsics coordinate).
- Coordinate2dFloat physical_center;
-
- // Enumeration for list of 2d blending types.
- enum BlendingType { MULTIBAND = 0, ALPHA };
-
- // Blending type for high quality preset.
- BlendingType high_quality_blending;
-
- // Blending type for low quality preset.
- BlendingType low_quality_blending;
-
- // whether gpu acceleration is enabled or not
- bool gpu_acceleration_enabled;
-
- SurroundView2dParams() :
- resolution{0, 0},
- physical_size{0.0f, 0.0f},
- physical_center{0.0f, 0.0f},
- high_quality_blending(BlendingType::MULTIBAND),
- low_quality_blending(BlendingType::ALPHA),
- gpu_acceleration_enabled(false) {}
-
- SurroundView2dParams(Size2dInteger resolution_, Size2dFloat physical_size_,
- Coordinate2dFloat physical_center_,
- bool gpu_acceleration_enabled_ = false) :
- resolution(resolution_),
- physical_size(physical_size_),
- physical_center(physical_center_),
- high_quality_blending(BlendingType::MULTIBAND),
- low_quality_blending(BlendingType::ALPHA),
- gpu_acceleration_enabled(gpu_acceleration_enabled_) {}
-
- // Checks if data is valid.
- bool IsValid() const { return resolution.IsValid() && physical_size.IsValid(); }
-
- bool operator==(const SurroundView2dParams& rhs) const {
- return resolution == rhs.resolution && physical_size == rhs.physical_size &&
- physical_center == rhs.physical_center &&
- high_quality_blending == rhs.high_quality_blending &&
- low_quality_blending == rhs.low_quality_blending &&
- gpu_acceleration_enabled == rhs.gpu_acceleration_enabled;
- }
-
- SurroundView2dParams& operator=(const SurroundView2dParams& rhs) {
- resolution = rhs.resolution;
- physical_size = rhs.physical_size;
- physical_center = rhs.physical_center;
- high_quality_blending = rhs.high_quality_blending;
- low_quality_blending = rhs.low_quality_blending;
- gpu_acceleration_enabled = rhs.gpu_acceleration_enabled;
- return *this;
- }
-};
-
-// surround view 3d parameters
-struct SurroundView3dParams {
- // Bowl center is the origin of the surround view coordinate. If surround view
- // coordinate is different from the global one, a coordinate system
- // transformation function is required.
-
- // planar area radius.
- // Range in (0, +Inf).
- float plane_radius;
-
- // the number of divisions on the plane area of bowl, in the direction
- // of the radius.
- // Range in [1, +Inf).
- int plane_divisions;
-
- // bowl curve curve height.
- // Range in (0, +Inf).
- float curve_height;
-
- // the number of points on bowl curve curve along radius direction.
- // Range in [1, +Inf).
- int curve_divisions;
-
- // the number of points along circle (360 degrees)
- // Range in [1, +Inf).
- int angular_divisions;
-
- // the parabola coefficient of bowl curve curve.
- // The curve formula is z = a * (x^2 + y^2) for sqrt(x^2 + y^2) >
- // plane_radius; a is curve_coefficient.
- // Range in (0, +Inf).
- float curve_coefficient;
-
- // render output image size.
- Size2dInteger resolution;
-
- // Include shadows in high details preset.
- bool high_details_shadows;
-
- // Include reflections in high details preset.
- bool high_details_reflections;
-
- SurroundView3dParams() :
- plane_radius(0.0f),
- plane_divisions(0),
- curve_height(0.0f),
- curve_divisions(0),
- angular_divisions(0),
- curve_coefficient(0.0f),
- resolution(0, 0),
- high_details_shadows(true),
- high_details_reflections(true) {}
-
- SurroundView3dParams(float plane_radius_, int plane_divisions_, float curve_height_,
- int curve_divisions_, int angular_divisions_, float curve_coefficient_,
- Size2dInteger resolution_) :
- plane_radius(plane_radius_),
- plane_divisions(plane_divisions_),
- curve_height(curve_height_),
- curve_divisions(curve_divisions_),
- angular_divisions(angular_divisions_),
- curve_coefficient(curve_coefficient_),
- resolution(resolution_),
- high_details_shadows(true),
- high_details_reflections(true) {}
-
- // Checks if data is valid.
- bool IsValid() const {
- return plane_radius > 0 && plane_divisions > 0 && curve_height > 0 &&
- angular_divisions > 0 && curve_coefficient > 0 && curve_divisions > 0 &&
- resolution.IsValid();
- }
-
- bool operator==(const SurroundView3dParams& rhs) const {
- return plane_radius == rhs.plane_radius && plane_divisions == rhs.plane_divisions &&
- curve_height == rhs.curve_height && curve_divisions == rhs.curve_divisions &&
- angular_divisions == rhs.angular_divisions &&
- curve_coefficient == rhs.curve_coefficient && resolution == rhs.resolution &&
- high_details_shadows == rhs.high_details_shadows &&
- high_details_reflections == rhs.high_details_reflections;
- }
-
- SurroundView3dParams& operator=(const SurroundView3dParams& rhs) {
- plane_radius = rhs.plane_radius;
- plane_divisions = rhs.plane_divisions;
- curve_height = rhs.curve_height;
- curve_divisions = rhs.curve_divisions;
- angular_divisions = rhs.angular_divisions;
- curve_coefficient = rhs.curve_coefficient;
- resolution = rhs.resolution;
- high_details_shadows = rhs.high_details_shadows;
- high_details_reflections = rhs.high_details_reflections;
- return *this;
- }
-};
-
-// surround view camera parameters with native types only.
-struct SurroundViewCameraParams {
- // All calibration data |intrinsics|, |rvec| and |tvec|
- // follow OpenCV format excepting using native arrays, refer:
- // https://docs.opencv.org/3.4.0/db/d58/group__calib3d__fisheye.html
- // camera intrinsics. It is the 1d array of camera matrix(3X3) with row first.
- float intrinsics[9];
-
- // lens distortion parameters.
- float distorion[4];
-
- // rotation vector.
- float rvec[3];
-
- // translation vector.
- float tvec[3];
-
- // camera image size (width, height).
- Size2dInteger size;
-
- // fisheye circular fov.
- float circular_fov;
-
- // Full path and filename to the validity mask image file.
- // Mask specifies the valid region of pixels within input camera image.
- std::string validity_mask_filename;
-
- bool operator==(const SurroundViewCameraParams& rhs) const {
- return (0 == std::memcmp(intrinsics, rhs.intrinsics, 9 * sizeof(float))) &&
- (0 == std::memcmp(distorion, rhs.distorion, 4 * sizeof(float))) &&
- (0 == std::memcmp(rvec, rhs.rvec, 3 * sizeof(float))) &&
- (0 == std::memcmp(tvec, rhs.tvec, 3 * sizeof(float))) && size == rhs.size &&
- circular_fov == rhs.circular_fov;
- }
-
- SurroundViewCameraParams& operator=(const SurroundViewCameraParams& rhs) {
- std::memcpy(intrinsics, rhs.intrinsics, 9 * sizeof(float));
- std::memcpy(distorion, rhs.distorion, 4 * sizeof(float));
- std::memcpy(rvec, rhs.rvec, 3 * sizeof(float));
- std::memcpy(tvec, rhs.tvec, 3 * sizeof(float));
- size = rhs.size;
- circular_fov = rhs.circular_fov;
- return *this;
- }
-};
-
-// 3D vertex of an overlay object.
-struct OverlayVertex {
- // Position in 3d coordinates in world space in order X,Y,Z.
- float pos[3];
- // RGBA values, A is used for transparency.
- uint8_t rgba[4];
-
- bool operator==(const OverlayVertex& rhs) const {
- return (0 == std::memcmp(pos, rhs.pos, 3 * sizeof(float))) &&
- (0 == std::memcmp(rgba, rhs.rgba, 4 * sizeof(uint8_t)));
- }
-
- OverlayVertex& operator=(const OverlayVertex& rhs) {
- std::memcpy(pos, rhs.pos, 3 * sizeof(float));
- std::memcpy(rgba, rhs.rgba, 4 * sizeof(uint8_t));
- return *this;
- }
-};
-
-// Overlay is a list of vertices (may be a single or multiple objects in scene)
-// coming from a single source or type of sensor.
-struct Overlay {
- // Uniqiue Id identifying each overlay.
- uint16_t id;
-
- // List of overlay vertices. 3 consecutive vertices form a triangle.
- std::vector<OverlayVertex> vertices;
-
- // Constructor initializing all member.
- Overlay(uint16_t id_, const std::vector<OverlayVertex>& vertices_) {
- id = id_;
- vertices = vertices_;
- }
-
- // Default constructor.
- Overlay() {
- id = 0;
- vertices = std::vector<OverlayVertex>();
- }
-};
-
-// ----------- Structs related to car model ---------------
-
-// 3D Vertex of a car model with normal and optionally texture coordinates.
-struct CarVertex {
- // 3d position in (x, y, z).
- std::array<float, 3> pos;
-
- // unit normal at vertex, used for diffuse shading.
- std::array<float, 3> normal;
-
- // texture coordinates, valid in range [0, 1]. (-1, -1) implies no
- // texture sampling. Note: only a single texture coordinate is currently
- // supported per vertex. This struct will need to be extended with another
- // tex_coord if multiple textures are needed per vertex.
- std::array<float, 2> tex_coord;
-
- // Default constructor.
- CarVertex() {
- pos = {0, 0, 0};
- normal = {1, 0, 0};
- tex_coord = {-1.0f, -1.0f};
- }
-
- CarVertex(const std::array<float, 3>& _pos, const std::array<float, 3>& _normal,
- const std::array<float, 2> _tex_coord) :
- pos(_pos), normal(_normal), tex_coord(_tex_coord) {}
-};
-
-// Type of texture (color, bump, procedural etc.)
-// Currently only color is supported.
-enum CarTextureType : uint32_t {
- // Texture map is applied to all color parameters: Ka, Kd and Ks.
- // Data type of texture is RGB with each channel a uint8_t.
- kKa = 0,
- kKd,
- kKs,
-
- // Texture for bump maps. Data type is 3 channel float.
- kBumpMap
-};
-
-// Textures to be used for rendering car model.
-struct CarTexture {
- // Type and number of channels are dependant on each car texture type.
- int width;
- int height;
- int channels;
- int bytes_per_channel;
- uint8_t* data;
-
- CarTexture() {
- width = 0;
- height = 0;
- channels = 0;
- bytes_per_channel = 0;
- data = nullptr;
- }
-};
-
-// Material parameters for a car part.
-// Refer to MTL properties: http://paulbourke.net/dataformats/mtl/
-struct CarMaterial {
- // Illumination model - 0, 1, 2 currently supported
- // 0 = Color on and Ambient off
- // 1 = Color on and Ambient on
- // 2 = Highlight on
- // 3 = Reflection on and Ray trace on
- // 4 - 10 = Reflection/Transparency options not supported,
- // Will default to option 3.
- uint8_t illum;
-
- std::array<float, 3> ka; // Ambient RGB [0, 1]
- std::array<float, 3> kd; // Diffuse RGB [0, 1]
- std::array<float, 3> ks; // Specular RGB [0, 1]
-
- // Dissolve factor [0, 1], 0 = full transparent, 1 = full opaque.
- float d;
-
- // Specular exponent typically range from 0 to 1000.
- // A high exponent results in a tight, concentrated highlight.
- float ns;
-
- // Set default values of material.
- CarMaterial() {
- illum = 0; // Color on, ambient off
- ka = {0.0f, 0.0f, 0.0f}; // No ambient.
- kd = {0.0f, 0.0f, 0.0f}; // No dissolve.
- ks = {0.0f, 0.0f, 0.0f}; // No specular.
- d = 1.0f; // Fully opaque.
- ns = 0; // No specular exponent.
- }
-
- // Map for texture type to a string id of a texture.
- std::map<CarTextureType, std::string> textures;
-};
-
-// Type alias for 4x4 homogenous matrix, in row-major order.
-using Mat4x4 = std::array<float, 16>;
-
-// Represents a part of a car model.
-// Each car part is a object in the car that is individually animated and
-// has the same illumination properties. A car part may contain sub parts.
-struct CarPart {
- // Car part vertices.
- std::vector<CarVertex> vertices;
-
- // Properties/attributes describing car material.
- CarMaterial material;
-
- // Model matrix to transform the car part from object space to its parent's
- // coordinate space.
- // The car's vertices are transformed by performing:
- // parent_model_mat * model_mat * car_part_vertices to transform them to the
- // global coordinate space.
- // Model matrix must be a homogenous matrix with orthogonal rotation matrix.
- Mat4x4 model_mat;
-
- // Id of parent part. Parent part's model matrix is used to animate this part.
- // empty string implies the part has no parent.
- std::string parent_part_id;
-
- // Ids of child parts. If current part is animated all its child parts
- // are animated as well. Empty vector implies part has not children.
- std::vector<std::string> child_part_ids;
-
- CarPart(const std::vector<CarVertex>& car_vertices, const CarMaterial& car_material,
- const Mat4x4& car_model_mat, std::string car_parent_part_id,
- const std::vector<std::string>& car_child_part_ids) :
- vertices(car_vertices),
- material(car_material),
- model_mat(car_model_mat),
- parent_part_id(car_parent_part_id),
- child_part_ids(car_child_part_ids) {}
-
- CarPart& operator=(const CarPart& car_part) {
- this->vertices = car_part.vertices;
- this->material = car_part.material;
- this->model_mat = car_part.model_mat;
- this->parent_part_id = car_part.parent_part_id;
- this->child_part_ids = car_part.child_part_ids;
- return *this;
- }
-};
-
-struct AnimationParam {
- // part id
- std::string part_id;
-
- // model matrix.
- Mat4x4 model_matrix;
-
- // bool flag indicating if the model matrix is updated from last
- // SetAnimations() call.
- bool is_model_update;
-
- // gamma.
- float gamma;
-
- // bool flag indicating if gamma is updated from last
- // SetAnimations() call.
- bool is_gamma_update;
-
- // texture id.
- std::string texture_id;
-
- // bool flag indicating if texture is updated from last
- // SetAnimations() call.
- bool is_texture_update;
-
- // Default constructor, no animations are updated.
- AnimationParam() {
- is_model_update = false;
- is_gamma_update = false;
- is_texture_update = false;
- }
-
- // Constructor with car part name.
- explicit AnimationParam(const std::string& _part_id) :
- part_id(_part_id),
- is_model_update(false),
- is_gamma_update(false),
- is_texture_update(false) {}
-
- void SetModelMatrix(const Mat4x4& model_mat) {
- is_model_update = true;
- model_matrix = model_mat;
- }
-
- void SetGamma(float gamma_value) {
- is_gamma_update = true;
- gamma = gamma_value;
- }
-
- void SetTexture(const std::string& tex_id) {
- is_texture_update = true;
- texture_id = tex_id;
- }
-};
-
-enum Format {
- GRAY = 0,
- RGB = 1,
- RGBA = 2,
-};
-
-// collection of surround view static data params.
-struct SurroundViewStaticDataParams {
- std::vector<SurroundViewCameraParams> cameras_params;
-
- // surround view 2d parameters.
- SurroundView2dParams surround_view_2d_params;
-
- // surround view 3d parameters.
- SurroundView3dParams surround_view_3d_params;
-
- // undistortion focal length scales.
- std::vector<float> undistortion_focal_length_scales;
-
- // car model bounding box for 2d surround view.
- BoundingBox car_model_bb;
-
- // map of texture name to a car texture. Lists all textures to be
- // used for car model rendering.
- std::map<std::string, CarTexture> car_textures;
-
- // map of car id to a car part. Lists all car parts to be used
- // for car model rendering.
- std::map<std::string, CarPart> car_parts;
-
- SurroundViewStaticDataParams(const std::vector<SurroundViewCameraParams>& sv_cameras_params,
- const SurroundView2dParams& sv_2d_params,
- const SurroundView3dParams& sv_3d_params,
- const std::vector<float>& scales, const BoundingBox& bb,
- const std::map<std::string, CarTexture>& textures,
- const std::map<std::string, CarPart>& parts) :
- cameras_params(sv_cameras_params),
- surround_view_2d_params(sv_2d_params),
- surround_view_3d_params(sv_3d_params),
- undistortion_focal_length_scales(scales),
- car_model_bb(bb),
- car_textures(textures),
- car_parts(parts) {}
-};
-
-// Constant used as an invalid memory id for SurroundViewInputBufferPointers and
-// SurroundViewResultPointer. Setting to `memory_id` to kInvalidMemoryId implies
-// no caching is performed.
-const uint64_t kInvalidMemoryId = UINT64_MAX;
-
-// Currently we keep both cpu and gpu data pointers, and only one of them should
-// be valid at a certain point. Also, users are responsible to allocate and
-// de-allocate the pointers.
-// TODO(b/174778117): consider use only one data pointer once GPU migration is
-// done.
-// TODO(b/184870125): Consider merging with SurroundViewInputBufferPointers.
-struct SurroundViewInputBufferPointers {
- void* gpu_data_pointer;
- void* cpu_data_pointer;
- Format format;
- int width;
- int height;
- // Unique identifier for the CPU/GPU data buffer. If memory id is the same as
- // a previously provided input buffer, cached intermediate allocated data will
- // be used for faster operation. If `memory_id` is kInvalidMemoryId no caching
- // is performed. Currently supported: SV2D GPU pipeline with
- // `gpu_data_pointer`.
- // Recommend the `memory_id` provided by client to be created as:
- // ((camera_index) << 32 ) | (graphics_buffer_id).
- uint64_t memory_id;
- SurroundViewInputBufferPointers() :
- gpu_data_pointer(nullptr),
- cpu_data_pointer(nullptr),
- width(0),
- height(0),
- memory_id(kInvalidMemoryId) {}
- SurroundViewInputBufferPointers(void* gpu_data_pointer_, void* cpu_data_pointer_,
- Format format_, int width_, int height_,
- uint64_t memory_id_ = kInvalidMemoryId) :
- gpu_data_pointer(gpu_data_pointer_),
- cpu_data_pointer(cpu_data_pointer_),
- format(format_),
- width(width_),
- height(height_),
- memory_id(memory_id_) {}
-};
-
-// Currently we keep both cpu and gpu data pointers, and only one of them should
-// be valid at a certain point. Users need to check null before they make use of
-// the data pointers.
-// TODO(b/174778117): consider use only one data pointer once GPU migration is
-// done.
-// TODO(b/184870125): Consider merging with SurroundViewInputBufferPointers.
-struct SurroundViewResultPointer {
- void* gpu_data_pointer;
- void* cpu_data_pointer;
- Format format;
- int width;
- int height;
- bool is_data_preallocated;
- // Unique identifier for the CPU/GPU data buffer. If memory id is the same as
- // a previously provided result buffer, cached intermediate allocated data
- // will be used for faster operation. If memory_id is kInvalidMemoryId no
- // caching is performed. Currently supported: SV2D GPU pipeline with
- // 'gpu_data_pointer'.
- // Recommend the `memory_id` provided by client to be created as:
- // ((camera_index) << 32 ) | (graphics_buffer_id).
- uint64_t memory_id;
- SurroundViewResultPointer() :
- gpu_data_pointer(nullptr),
- cpu_data_pointer(nullptr),
- width(0),
- height(0),
- is_data_preallocated(false),
- memory_id(kInvalidMemoryId) {}
-
- // Constructor with result cpu data pointer being allocated within core lib.
- // Use for cases when no already existing buffer is available.
- SurroundViewResultPointer(Format format_, int width_, int height_) :
- format(format_), width(width_), height(height_) {
- // default formate is gray.
- const int byte_per_pixel = format_ == RGB ? 3 : format_ == RGBA ? 4 : 1;
- cpu_data_pointer = static_cast<void*>(new char[width * height * byte_per_pixel]);
- gpu_data_pointer = nullptr;
- is_data_preallocated = false;
- memory_id = kInvalidMemoryId;
- }
-
- // Constructor with pre-allocated data.
- // Use for cases when results must be added to an existing allocated buffer.
- // Example, pre-allocated buffer of a display.
- SurroundViewResultPointer(void* gpu_data_pointer_, void* cpu_data_pointer_, Format format_,
- int width_, int height_) :
- gpu_data_pointer(gpu_data_pointer_),
- cpu_data_pointer(cpu_data_pointer_),
- format(format_),
- width(width_),
- height(height_),
- is_data_preallocated(true),
- memory_id(kInvalidMemoryId) {}
-
- ~SurroundViewResultPointer() {
- if (cpu_data_pointer) {
- if (!is_data_preallocated) {
- delete[] static_cast<char*>(cpu_data_pointer);
- }
- cpu_data_pointer = nullptr;
- }
- }
-};
-
-// External renderer configuration for SV3D.
-struct RendererInfo {
- // Enumeration for the rendering API to be used.
- enum RenderingApi { OPENGLES, VULKAN };
-
- // Rendering API used external renderer.
- // OpenGLES is supported as an external renderer.
- // Vulkan is currently not supported as an external renderer.
- RenderingApi api;
-
- // OpenGLES version >= 3.1 is supported.
- int version_major;
- int version_minor;
-};
-
-// Initialization info for external OpenGLES rendering.
-struct OpenGlInitInfo {
- // Type EGLDisplay
- void* egl_display;
-
- // Type EGLSurface
- void* egl_surface;
-
- // Type EGLContext
- void* egl_context;
-};
-
-class SurroundView {
-public:
- virtual ~SurroundView() = default;
-
- // Sets SurroundView static data.
- // For details of SurroundViewStaticDataParams, please refer to the
- // definition.
- virtual bool SetStaticData(const SurroundViewStaticDataParams& static_data_params) = 0;
-
- // Starts 2d pipeline. Returns false if error occurs.
- virtual bool Start2dPipeline() = 0;
-
- // Starts 3d pipeline. Returns false if error occurs.
- virtual bool Start3dPipeline() = 0;
-
- // Starts Surround View 3D pipeline to render into an external OpenGLES scene.
- // `external_renderer_info` - contains data structs specifying the external
- // renderer initialization information.
- // `opengl_init_info` - contains the OpenGLES structs required for
- // initialization. Returns false if error occurs.
- virtual bool Start3dPipelineExternal(const RendererInfo& external_renderer_info,
- const OpenGlInitInfo& opengl_init_info) = 0;
-
- // Stops 2d pipleline. It releases resource owned by the pipeline.
- // Returns false if error occurs.
- virtual void Stop2dPipeline() = 0;
-
- // Stops 3d pipeline. It releases resource owned by the pipeline.
- virtual void Stop3dPipeline() = 0;
-
- // Updates 2d output resolution on-the-fly. Starts2dPipeline() must be called
- // before this can be called. For quality assurance, the |resolution| should
- // not be larger than the original one. This call is not thread safe and there
- // is no sync between Get2dSurroundView() and this call.
- virtual bool Update2dOutputResolution(const Size2dInteger& resolution) = 0;
-
- // Updates 3d output resolution on-the-fly. Starts3dPipeline() must be called
- // before this can be called. For quality assurance, the |resolution| should
- // not be larger than the original one. This call is not thread safe and there
- // is no sync between Get3dSurroundView() and this call.
- virtual bool Update3dOutputResolution(const Size2dInteger& resolution) = 0;
-
- // Projects camera's pixel location to surround view 2d image location.
- // |camera_point| is the pixel location in raw camera's space.
- // |camera_index| is the camera's index.
- // |surround_view_2d_point| is the surround view 2d image pixel location.
- virtual bool GetProjectionPointFromRawCameraToSurroundView2d(
- const Coordinate2dInteger& camera_point, int camera_index,
- Coordinate2dFloat* surround_view_2d_point) = 0;
-
- // Projects camera's pixel location to surround view 3d bowl coordinate.
- // |camera_point| is the pixel location in raw camera's space.
- // |camera_index| is the camera's index.
- // |surround_view_3d_point| is the surround view 3d vertex.
- virtual bool GetProjectionPointFromRawCameraToSurroundView3d(
- const Coordinate2dInteger& camera_point, int camera_index,
- Coordinate3dFloat* surround_view_3d_point) = 0;
-
- // Gets 2d surround view image.
- // It takes input_pointers as input, and output is result_pointer.
- // Please refer to the definition of SurroundViewInputBufferPointers and
- // SurroundViewResultPointer.
- virtual bool Get2dSurroundView(
- const std::vector<SurroundViewInputBufferPointers>& input_pointers,
- SurroundViewResultPointer* result_pointer) = 0;
-
- // Gets 3d surround view image.
- // It takes |input_pointers| and |view_matrix| as input, and output is
- // |result_pointer|. |view_matrix| is 4 x 4 matrix.
- // Please refer to the definition of
- // SurroundViewInputBufferPointers and
- // SurroundViewResultPointer.
- virtual bool Get3dSurroundView(
- const std::vector<SurroundViewInputBufferPointers>& input_pointers,
- const std::array<std::array<float, 4>, 4>& view_matrix,
- SurroundViewResultPointer* result_pointer) = 0;
-
- // Gets 3d surround view image overload.
- // It takes |input_pointers|, |quaternion| and |translation| as input,
- // and output is |result_pointer|.
- // |quaternion| is 4 x 1 array (X, Y, Z, W).
- // It is required to be unit quaternion as rotation quaternion.
- // |translation| is 3 X 1 array (x, y, z).
- // Please refer to the definition of
- // SurroundViewInputBufferPointers and
- // SurroundViewResultPointer.
- virtual bool Get3dSurroundView(
- const std::vector<SurroundViewInputBufferPointers>& input_pointers,
- const std::array<float, 4>& quaternion, const std::array<float, 3>& translation,
- SurroundViewResultPointer* result_pointer) = 0;
-
- // Updates the Surround View 3D Bowl in an external renderer scene with the
- // images provided by `input_pointers` and view in `view_matrix`.
- // Call is only valid if pipeline is started with Start3dPipelineExternal().
- virtual bool Update3dSurroundViewExternal(
- const std::vector<SurroundViewInputBufferPointers>& input_pointers,
- const std::array<std::array<float, 4>, 4>& view_matrix) = 0;
-
- // Sets 3d overlays.
- virtual bool Set3dOverlay(const std::vector<Overlay>& overlays) = 0;
-
- // Animates a set of car parts.
- // Only updated car parts are included.
- // |car_animations| is a vector of AnimationParam specifying updated
- // car parts with updated animation parameters.
- virtual bool SetAnimations(const std::vector<AnimationParam>& car_animations) = 0;
-
- // for test only.
- virtual std::vector<SurroundViewInputBufferPointers> ReadImages(const char* filename0,
- const char* filename1,
- const char* filename2,
- const char* filename3) = 0;
-
- virtual void WriteImage(const SurroundViewResultPointer result_pointerer,
- const char* filename) = 0;
-};
-
-SurroundView* Create();
-
-} // namespace surround_view
-} // namespace android_auto
-
-#endif // WIRELESS_ANDROID_AUTOMOTIVE_CAML_SURROUND_VIEW_CORE_LIB_H_
diff --git a/cpp/surround_view/service-impl/lib/arm64/libcore_lib_shared.so b/cpp/surround_view/service-impl/lib/arm64/libcore_lib_shared.so
deleted file mode 100755
index 6c4927b..0000000
--- a/cpp/surround_view/service-impl/lib/arm64/libcore_lib_shared.so
+++ /dev/null
Binary files differ
diff --git a/cpp/surround_view/service-impl/lib/x86-64/libcore_lib_shared.so b/cpp/surround_view/service-impl/lib/x86-64/libcore_lib_shared.so
deleted file mode 100755
index d718426..0000000
--- a/cpp/surround_view/service-impl/lib/x86-64/libcore_lib_shared.so
+++ /dev/null
Binary files differ
diff --git a/cpp/surround_view/service-impl/lib/x86/libcore_lib_shared.so b/cpp/surround_view/service-impl/lib/x86/libcore_lib_shared.so
deleted file mode 100755
index dd4eb11..0000000
--- a/cpp/surround_view/service-impl/lib/x86/libcore_lib_shared.so
+++ /dev/null
Binary files differ
diff --git a/cpp/surround_view/service-impl/manifest_android.hardware.automotive.sv@1.0.xml b/cpp/surround_view/service-impl/manifest_android.hardware.automotive.sv@1.0.xml
deleted file mode 100644
index f9e4548..0000000
--- a/cpp/surround_view/service-impl/manifest_android.hardware.automotive.sv@1.0.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright 2020 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.
--->
-<manifest version="1.0" type="device" >
- <hal format="hidl">
- <name>android.hardware.automotive.sv</name>
- <transport>hwbinder</transport>
- <version>1.0</version>
- <interface>
- <name>ISurroundViewService</name>
- <instance>default</instance>
- </interface>
- </hal>
-</manifest>
diff --git a/cpp/surround_view/service-impl/mock-evs/MockEvsCamera.cpp b/cpp/surround_view/service-impl/mock-evs/MockEvsCamera.cpp
deleted file mode 100644
index 76ed76f..0000000
--- a/cpp/surround_view/service-impl/mock-evs/MockEvsCamera.cpp
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * Copyright 2020 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 "MockEvsCamera.h"
-
-#include <stdlib.h>
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-// TODO(b/159733690): the number should come from xml
-const int kFramesCount = 4;
-const int kFrameGenerationDelayMillis = 30;
-
-// Evs Camera Id names defined in sv_sample_config.xml.
-const char kEvsCameraDeviceIdNames[4][20] = {
- "/dev/video60", "/dev/video61", "/dev/video62", "/dev/video63"
-};
-
-
-MockEvsCamera::MockEvsCamera(const string& cameraId, const Stream& streamCfg) {
- mConfigManager = ConfigManager::Create();
-
- mStreamCfg.height = streamCfg.height;
- mStreamCfg.width = streamCfg.width;
-
- mCameraDesc.v1.cameraId = cameraId;
- unique_ptr<ConfigManager::CameraGroupInfo>& cameraGroupInfo =
- mConfigManager->getCameraGroupInfo(mCameraDesc.v1.cameraId);
- if (cameraGroupInfo != nullptr) {
- mCameraDesc.metadata.setToExternal(
- (uint8_t*)cameraGroupInfo->characteristics,
- get_camera_metadata_size(cameraGroupInfo->characteristics));
- }
-}
-
-Return<void> MockEvsCamera::getCameraInfo(getCameraInfo_cb _hidl_cb) {
- // Not implemented.
-
- (void)_hidl_cb;
- return {};
-}
-
-Return<EvsResult> MockEvsCamera::setMaxFramesInFlight(uint32_t bufferCount) {
- // Not implemented.
-
- (void)bufferCount;
- return EvsResult::OK;
-}
-
-Return<EvsResult> MockEvsCamera::startVideoStream(
- const ::android::sp<IEvsCameraStream_1_0>& stream) {
- LOG(INFO) << __FUNCTION__;
- scoped_lock<mutex> lock(mAccessLock);
-
- mStream = IEvsCameraStream_1_1::castFrom(stream).withDefault(nullptr);
-
- if (mStreamState != STOPPED) {
- LOG(ERROR) << "Ignoring startVideoStream call when a stream is "
- << "already running.";
- return EvsResult::STREAM_ALREADY_RUNNING;
- }
-
- // Start the frame generation thread
- mStreamState = RUNNING;
- mCaptureThread = thread([this]() { generateFrames(); });
-
- return EvsResult::OK;
-}
-
-Return<void> MockEvsCamera::doneWithFrame(const BufferDesc_1_0& buffer) {
- // Not implemented.
-
- (void)buffer;
- return {};
-}
-
-Return<void> MockEvsCamera::stopVideoStream() {
- LOG(INFO) << __FUNCTION__;
-
- unique_lock<mutex> lock(mAccessLock);
- if (mStreamState == RUNNING) {
- // Tell the GenerateFrames loop we want it to stop
- mStreamState = STOPPING;
- // Block outside the mutex until the "stop" flag has been acknowledged
- // We won't send any more frames, but the client might still get some
- // already in flight
- LOG(DEBUG) << __FUNCTION__ << ": Waiting for stream thread to end...";
- lock.unlock();
- mCaptureThread.join();
- lock.lock();
- mStreamState = STOPPED;
- mStream = nullptr;
- LOG(DEBUG) << "Stream marked STOPPED.";
- }
- return {};
-}
-
-Return<int32_t> MockEvsCamera::getExtendedInfo(uint32_t opaqueIdentifier) {
- // Not implemented.
-
- (void)opaqueIdentifier;
- return 0;
-}
-
-Return<EvsResult> MockEvsCamera::setExtendedInfo(uint32_t opaqueIdentifier,
- int32_t opaqueValue) {
- // Not implemented.
-
- (void)opaqueIdentifier;
- (void)opaqueValue;
- return EvsResult::OK;
-}
-
-Return<void> MockEvsCamera::getCameraInfo_1_1(getCameraInfo_1_1_cb _hidl_cb) {
- _hidl_cb(mCameraDesc);
- return {};
-}
-
-Return<void> MockEvsCamera::getPhysicalCameraInfo(
- const hidl_string& deviceId, getPhysicalCameraInfo_cb _hidl_cb) {
- CameraDesc_1_1 desc = {};
- desc.v1.cameraId = deviceId;
-
- unique_ptr<ConfigManager::CameraInfo>& cameraInfo =
- mConfigManager->getCameraInfo(deviceId);
- if (cameraInfo != nullptr) {
- desc.metadata.setToExternal(
- (uint8_t*)cameraInfo->characteristics,
- get_camera_metadata_size(cameraInfo->characteristics));
- }
-
- _hidl_cb(desc);
-
- return {};
-}
-
-Return<EvsResult> MockEvsCamera::doneWithFrame_1_1(
- const hardware::hidl_vec<BufferDesc_1_1>& buffer) {
- // Not implemented.
-
- (void)buffer;
- return EvsResult::OK;
-}
-
-Return<EvsResult> MockEvsCamera::setMaster() {
- // Not implemented.
-
- return EvsResult::OK;
-}
-
-Return<EvsResult> MockEvsCamera::forceMaster(
- const sp<IEvsDisplay_1_0>& display) {
- // Not implemented.
-
- (void)display;
- return EvsResult::OK;
-}
-
-Return<EvsResult> MockEvsCamera::unsetMaster() {
- // Not implemented.
-
- return EvsResult::OK;
-}
-
-Return<void> MockEvsCamera::getParameterList(getParameterList_cb _hidl_cb) {
- // Not implemented.
-
- (void)_hidl_cb;
- return {};
-}
-
-Return<void> MockEvsCamera::getIntParameterRange(
- CameraParam id, getIntParameterRange_cb _hidl_cb) {
- // Not implemented.
-
- (void)id;
- (void)_hidl_cb;
- return {};
-}
-
-Return<void> MockEvsCamera::setIntParameter(CameraParam id, int32_t value,
- setIntParameter_cb _hidl_cb) {
- // Not implemented.
-
- (void)id;
- (void)value;
- (void)_hidl_cb;
- return {};
-}
-
-Return<void> MockEvsCamera::getIntParameter(
- CameraParam id, getIntParameter_cb _hidl_cb) {
- // Not implemented.
-
- (void)id;
- (void)_hidl_cb;
- return {};
-}
-
-Return<EvsResult> MockEvsCamera::setExtendedInfo_1_1(
- uint32_t opaqueIdentifier, const hidl_vec<uint8_t>& opaqueValue) {
- // Not implemented.
-
- (void)opaqueIdentifier;
- (void)opaqueValue;
- return EvsResult::OK;
-}
-
-Return<void> MockEvsCamera::getExtendedInfo_1_1(
- uint32_t opaqueIdentifier, getExtendedInfo_1_1_cb _hidl_cb) {
- // Not implemented.
-
- (void)opaqueIdentifier;
- (void)_hidl_cb;
- return {};
-}
-
-Return<void> MockEvsCamera::importExternalBuffers(
- const hidl_vec<BufferDesc_1_1>& buffers,
- importExternalBuffers_cb _hidl_cb) {
- // Not implemented.
-
- (void)buffers;
- (void)_hidl_cb;
- return {};
-}
-
-void MockEvsCamera::initializeFrames(int framesCount) {
- LOG(INFO) << "StreamCfg width: " << mStreamCfg.width
- << " height: " << mStreamCfg.height;
-
- string label = "EmptyBuffer_";
- mGraphicBuffers.resize(framesCount);
- mBufferDescs.resize(framesCount);
- for (int i = 0; i < framesCount; i++) {
- mGraphicBuffers[i] = new GraphicBuffer(mStreamCfg.width,
- mStreamCfg.height,
- HAL_PIXEL_FORMAT_RGBA_8888,
- 1,
- GRALLOC_USAGE_HW_TEXTURE,
- label + (char)(i + 48));
- mBufferDescs[i].buffer.nativeHandle =
- mGraphicBuffers[i]->getNativeBuffer()->handle;
- mBufferDescs[i].deviceId = kEvsCameraDeviceIdNames[i];
- AHardwareBuffer_Desc* pDesc =
- reinterpret_cast<AHardwareBuffer_Desc*>(
- &mBufferDescs[i].buffer.description);
- pDesc->width = mStreamCfg.width;
- pDesc->height = mStreamCfg.height;
- pDesc->layers = 1;
- pDesc->usage = GRALLOC_USAGE_HW_TEXTURE;
- pDesc->stride = mGraphicBuffers[i]->getStride();
- pDesc->format = HAL_PIXEL_FORMAT_RGBA_8888;
- }
-}
-
-void MockEvsCamera::generateFrames() {
- initializeFrames(kFramesCount);
-
- while (true) {
- {
- scoped_lock<mutex> lock(mAccessLock);
- if (mStreamState != RUNNING) {
- // Break out of our main thread loop
- LOG(INFO) << "StreamState does not equal to RUNNING. "
- << "Exiting the loop";
- break;
- }
- }
-
- mStream->deliverFrame_1_1(mBufferDescs);
- std::this_thread::sleep_for(
- std::chrono::milliseconds(kFrameGenerationDelayMillis));
- }
-
- {
- scoped_lock<mutex> lock(mAccessLock);
-
- if (mStream != nullptr) {
- LOG(DEBUG) << "Notify EvsEventType::STREAM_STOPPED";
-
- EvsEventDesc evsEventDesc;
- evsEventDesc.aType = EvsEventType::STREAM_STOPPED;
- mStream->notify(evsEventDesc);
- } else {
- LOG(WARNING) << "EVS stream is not valid any more. "
- << "The notify call is ignored.";
- }
- }
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/mock-evs/MockEvsCamera.h b/cpp/surround_view/service-impl/mock-evs/MockEvsCamera.h
deleted file mode 100644
index e06a474..0000000
--- a/cpp/surround_view/service-impl/mock-evs/MockEvsCamera.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#pragma once
-
-#include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
-#include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
-#include <android/hardware/automotive/evs/1.1/IEvsDisplay.h>
-#include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
-
-#include <ConfigManager.h>
-
-#include <ui/GraphicBuffer.h>
-
-#include <mutex>
-#include <thread>
-
-using ::android::hardware::automotive::evs::V1_0::EvsResult;
-using ::android::hardware::automotive::evs::V1_1::CameraParam;
-using ::android::hardware::automotive::evs::V1_1::EvsEventDesc;
-using ::android::hardware::automotive::evs::V1_1::EvsEventType;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using BufferDesc_1_0 = ::android::hardware::automotive::evs::V1_0::BufferDesc;
-using BufferDesc_1_1 = ::android::hardware::automotive::evs::V1_1::BufferDesc;
-using CameraDesc_1_1 = ::android::hardware::automotive::evs::V1_1::CameraDesc;
-using IEvsCamera_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCamera;
-using IEvsCamera_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCamera;
-using IEvsCameraStream_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCameraStream;
-using IEvsCameraStream_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCameraStream;
-using IEvsDisplay_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsDisplay;
-using IEvsEnumerator_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsEnumerator;
-
-// A simplified implementation for Evs Camera. Only necessary methods are
-// implemented.
-class MockEvsCamera : public IEvsCamera_1_1 {
-public:
- MockEvsCamera(const std::string& cameraId, const Stream& streamCfg);
-
- // Methods from ::android::hardware::automotive::evs::V1_0::IEvsCamera follow.
- Return<void> getCameraInfo(getCameraInfo_cb _hidl_cb) override;
- Return<EvsResult> setMaxFramesInFlight(uint32_t bufferCount) override;
- Return<EvsResult> startVideoStream(const ::android::sp<IEvsCameraStream_1_0>& stream) override;
- Return<void> doneWithFrame(const BufferDesc_1_0& buffer) override;
- Return<void> stopVideoStream() override;
- Return<int32_t> getExtendedInfo(uint32_t opaqueIdentifier) override;
- Return<EvsResult> setExtendedInfo(uint32_t opaqueIdentifier, int32_t opaqueValue) override;
-
- // Methods from ::android::hardware::automotive::evs::V1_1::IEvsCamera follow.
- Return<void> getCameraInfo_1_1(getCameraInfo_1_1_cb _hidl_cb) override;
- Return<void> getPhysicalCameraInfo(const hidl_string& deviceId,
- getPhysicalCameraInfo_cb _hidl_cb) override;
- Return<EvsResult> doneWithFrame_1_1(const hardware::hidl_vec<BufferDesc_1_1>& buffer) override;
- Return<EvsResult> pauseVideoStream() override { return EvsResult::UNDERLYING_SERVICE_ERROR; }
- Return<EvsResult> resumeVideoStream() override { return EvsResult::UNDERLYING_SERVICE_ERROR; }
- Return<EvsResult> setMaster() override;
- Return<EvsResult> forceMaster(const sp<IEvsDisplay_1_0>& display) override;
- Return<EvsResult> unsetMaster() override;
- Return<void> getParameterList(getParameterList_cb _hidl_cb) override;
- Return<void> getIntParameterRange(CameraParam id, getIntParameterRange_cb _hidl_cb) override;
- Return<void> setIntParameter(CameraParam id, int32_t value,
- setIntParameter_cb _hidl_cb) override;
- Return<void> getIntParameter(CameraParam id, getIntParameter_cb _hidl_cb) override;
- Return<EvsResult> setExtendedInfo_1_1(uint32_t opaqueIdentifier,
- const hidl_vec<uint8_t>& opaqueValue) override;
- Return<void> getExtendedInfo_1_1(uint32_t opaqueIdentifier,
- getExtendedInfo_1_1_cb _hidl_cb) override;
- Return<void> importExternalBuffers(const hidl_vec<BufferDesc_1_1>& buffers,
- importExternalBuffers_cb _hidl_cb) override;
-
-private:
- void initializeFrames(int framesCount);
- void generateFrames();
-
- std::unique_ptr<ConfigManager> mConfigManager;
-
- std::mutex mAccessLock;
-
- enum StreamStateValues {
- STOPPED,
- RUNNING,
- STOPPING,
- DEAD,
- };
- StreamStateValues mStreamState GUARDED_BY(mAccessLock);
- Stream mStreamCfg;
-
- std::vector<android::sp<GraphicBuffer>> mGraphicBuffers;
- std::vector<BufferDesc_1_1> mBufferDescs;
- CameraDesc_1_1 mCameraDesc;
-
- std::string mCameraId;
- std::thread mCaptureThread; // The thread we'll use to synthesize frames
-
- android::sp<IEvsCameraStream_1_1> mStream;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/mock-evs/MockEvsEnumerator.cpp b/cpp/surround_view/service-impl/mock-evs/MockEvsEnumerator.cpp
deleted file mode 100644
index 136a81a..0000000
--- a/cpp/surround_view/service-impl/mock-evs/MockEvsEnumerator.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2020 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 "MockEvsEnumerator.h"
-#include "MockEvsCamera.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using ::android::sp;
-
-using CameraDesc_1_0 = ::android::hardware::automotive::evs::V1_0::CameraDesc;
-using CameraDesc_1_1 = ::android::hardware::automotive::evs::V1_1::CameraDesc;
-
-MockEvsEnumerator::MockEvsEnumerator() {
- mConfigManager = ConfigManager::Create();
-}
-
-Return<void> MockEvsEnumerator::getCameraList(getCameraList_cb _hidl_cb) {
- // Not implemented.
-
- (void)_hidl_cb;
- return {};
-}
-
-Return<sp<IEvsCamera_1_0>> MockEvsEnumerator::openCamera(
- const hidl_string& cameraId) {
- // Not implemented.
-
- (void)cameraId;
- return nullptr;
-}
-
-Return<void> MockEvsEnumerator::closeCamera(
- const sp<IEvsCamera_1_0>& virtualCamera) {
- // Not implemented.
-
- (void)virtualCamera;
- return {};
-}
-
-Return<sp<IEvsDisplay_1_0>> MockEvsEnumerator::openDisplay() {
- // Not implemented.
-
- return nullptr;
-}
-
-Return<void> MockEvsEnumerator::closeDisplay(
- const sp<IEvsDisplay_1_0>& display) {
- // Not implemented.
-
- (void)display;
- return {};
-}
-
-Return<EvsDisplayState> MockEvsEnumerator::getDisplayState() {
- // Not implemented.
-
- return EvsDisplayState::DEAD;
-}
-
-Return<void> MockEvsEnumerator::getCameraList_1_1(
- getCameraList_1_1_cb _hidl_cb) {
- // We only take camera group into consideration here.
- vector<string> cameraGroupIdList = mConfigManager->getCameraGroupIdList();
- LOG(INFO) << "getCameraGroupIdList: " << cameraGroupIdList.size();
- for (int i = 0; i < cameraGroupIdList.size(); i++) {
- LOG(INFO) << "Camera[" << i << "]: " << cameraGroupIdList[i];
- }
-
- vector<CameraDesc_1_1> hidlCameras;
- for (int i = 0; i < cameraGroupIdList.size(); i++) {
- CameraDesc_1_1 desc = {};
- desc.v1.cameraId = cameraGroupIdList[i];
- unique_ptr<ConfigManager::CameraGroupInfo>& cameraGroupInfo =
- mConfigManager->getCameraGroupInfo(cameraGroupIdList[i]);
- if (cameraGroupInfo != nullptr) {
- desc.metadata.setToExternal(
- (uint8_t*)cameraGroupInfo->characteristics,
- get_camera_metadata_size(cameraGroupInfo->characteristics));
- } else {
- LOG(WARNING) << "Cannot find camera info for "
- << cameraGroupIdList[i];
- }
- hidlCameras.emplace_back(desc);
- }
- _hidl_cb(hidlCameras);
-
- return {};
-}
-
-Return<sp<IEvsCamera_1_1>> MockEvsEnumerator::openCamera_1_1(
- const hidl_string& cameraId, const Stream& streamCfg) {
- LOG(INFO) << __FUNCTION__ << ": " << streamCfg.width << ", " << streamCfg.height;
- return new MockEvsCamera(cameraId, streamCfg);
-}
-
-Return<void> MockEvsEnumerator::getDisplayIdList(getDisplayIdList_cb _list_cb) {
- // Not implemented.
-
- (void)_list_cb;
- return {};
-}
-
-Return<sp<IEvsDisplay_1_1>> MockEvsEnumerator::openDisplay_1_1(uint8_t id) {
- // Not implemented.
-
- (void)id;
- return nullptr;
-}
-
-Return<void> MockEvsEnumerator::getUltrasonicsArrayList(
- getUltrasonicsArrayList_cb _hidl_cb) {
- // Not implemented.
-
- (void)_hidl_cb;
- return {};
-}
-
-Return<sp<IEvsUltrasonicsArray>> MockEvsEnumerator::openUltrasonicsArray(
- const hidl_string& ultrasonicsArrayId) {
- // Not implemented.
-
- (void)ultrasonicsArrayId;
- return nullptr;
-}
-
-Return<void> MockEvsEnumerator::closeUltrasonicsArray(
- const ::android::sp<IEvsUltrasonicsArray>& evsUltrasonicsArray) {
- // Not implemented.
-
- (void)evsUltrasonicsArray;
- return {};
-}
-
-Return<void> MockEvsEnumerator::debug(
- const hidl_handle& fd, const hidl_vec<hidl_string>& options) {
- // Not implemented.
-
- (void)fd;
- (void)options;
- return {};
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/mock-evs/MockEvsEnumerator.h b/cpp/surround_view/service-impl/mock-evs/MockEvsEnumerator.h
deleted file mode 100644
index 7c1f8b0..0000000
--- a/cpp/surround_view/service-impl/mock-evs/MockEvsEnumerator.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#pragma once
-
-#include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
-#include <android/hardware/automotive/evs/1.1/IEvsDisplay.h>
-#include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
-#include <android/hardware/camera/device/3.2/ICameraDevice.h>
-#include <system/camera_metadata.h>
-
-#include <ConfigManager.h>
-
-using namespace ::android::hardware::automotive::evs::V1_1;
-using ::android::hardware::camera::device::V3_2::Stream;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-using EvsDisplayState = ::android::hardware::automotive::evs::V1_0::DisplayState;
-using IEvsCamera_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCamera;
-using IEvsCamera_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCamera;
-using IEvsDisplay_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsDisplay;
-using IEvsDisplay_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsDisplay;
-using IEvsEnumerator_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsEnumerator;
-
-class MockEvsEnumerator : public IEvsEnumerator_1_1 {
-public:
- MockEvsEnumerator();
-
- // Methods from ::android::hardware::automotive::evs::V1_0::IEvsEnumerator follow.
- Return<void> getCameraList(getCameraList_cb _hidl_cb) override;
- Return<sp<IEvsCamera_1_0>> openCamera(const hidl_string& cameraId) override;
- Return<void> closeCamera(const ::android::sp<IEvsCamera_1_0>& virtualCamera) override;
- Return<sp<IEvsDisplay_1_0>> openDisplay() override;
- Return<void> closeDisplay(const ::android::sp<IEvsDisplay_1_0>& display) override;
- Return<EvsDisplayState> getDisplayState() override;
-
- // Methods from ::android::hardware::automotive::evs::V1_1::IEvsEnumerator follow.
- Return<void> getCameraList_1_1(getCameraList_1_1_cb _hidl_cb) override;
- Return<sp<IEvsCamera_1_1>> openCamera_1_1(const hidl_string& cameraId,
- const Stream& streamCfg) override;
- Return<bool> isHardware() override { return false; }
- Return<void> getDisplayIdList(getDisplayIdList_cb _list_cb) override;
- Return<sp<IEvsDisplay_1_1>> openDisplay_1_1(uint8_t id) override;
- Return<void> getUltrasonicsArrayList(getUltrasonicsArrayList_cb _hidl_cb) override;
- Return<sp<IEvsUltrasonicsArray>> openUltrasonicsArray(
- const hidl_string& ultrasonicsArrayId) override;
- Return<void> closeUltrasonicsArray(
- const ::android::sp<IEvsUltrasonicsArray>& evsUltrasonicsArray) override;
-
- // Methods from ::android.hidl.base::V1_0::IBase follow.
- Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
-
-private:
- std::unique_ptr<ConfigManager> mConfigManager;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/mock-evs/MockSurroundViewCallback.cpp b/cpp/surround_view/service-impl/mock-evs/MockSurroundViewCallback.cpp
deleted file mode 100644
index 60108e6..0000000
--- a/cpp/surround_view/service-impl/mock-evs/MockSurroundViewCallback.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2020 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 "MockSurroundViewCallback.h"
-
-#include <android-base/logging.h>
-
-#include <thread>
-
-using ::android::sp;
-using ::android::hardware::Return;
-
-using ::std::thread;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-MockSurroundViewCallback::MockSurroundViewCallback(
- sp<ISurroundViewSession> pSession) :
- mSession(pSession) {}
-
-Return<void> MockSurroundViewCallback::notify(SvEvent svEvent) {
- LOG(INFO) << __FUNCTION__ << "SvEvent received: " << (int)svEvent;
- return {};
-}
-
-Return<void> MockSurroundViewCallback::receiveFrames(
- const SvFramesDesc& svFramesDesc) {
- LOG(INFO) << __FUNCTION__ << svFramesDesc.svBuffers.size()
- << " frames are received";
-
- // Increment the count of received frames.
- {
- std::scoped_lock<std::mutex> lock(mAccessLock);
- mReceivedFramesCount++;
- }
-
- // Create a separate thread to return the frames to the session. This
- // simulates the behavior of oneway HIDL method call.
- thread mockHidlThread([this, &svFramesDesc]() {
- mSession->doneWithFrames(svFramesDesc);
- });
- mockHidlThread.detach();
- return {};
-}
-
-int MockSurroundViewCallback::getReceivedFramesCount() {
- {
- std::scoped_lock<std::mutex> lock(mAccessLock);
- return mReceivedFramesCount;
- }
-}
-
-void MockSurroundViewCallback::clearReceivedFramesCount() {
- {
- std::scoped_lock<std::mutex> lock(mAccessLock);
- mReceivedFramesCount = 0;
- }
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/mock-evs/MockSurroundViewCallback.h b/cpp/surround_view/service-impl/mock-evs/MockSurroundViewCallback.h
deleted file mode 100644
index 238e41a..0000000
--- a/cpp/surround_view/service-impl/mock-evs/MockSurroundViewCallback.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#pragma once
-
-#include <android/hardware/automotive/sv/1.0/ISurroundViewService.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h>
-
-#include <ui/GraphicBuffer.h>
-
-#include <mutex>
-#include <thread>
-
-using namespace android::hardware::automotive::sv::V1_0;
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace sv {
-namespace V1_0 {
-namespace implementation {
-
-class MockSurroundViewCallback : public ISurroundViewStream {
-public:
- MockSurroundViewCallback(android::sp<ISurroundViewSession> pSession);
-
- // Methods from ::android::hardware::automotive::sv::V1_0::ISurroundViewStream.
- android::hardware::Return<void> notify(SvEvent svEvent) override;
- android::hardware::Return<void> receiveFrames(const SvFramesDesc& svFramesDesc) override;
-
- // Methods to get and clear the mReceivedFramesCount.
- int getReceivedFramesCount();
- void clearReceivedFramesCount();
-private:
- std::mutex mAccessLock;
- android::sp<ISurroundViewSession> mSession;
-
- // Keeps a count of the number of calls made to receiveFrames().
- int mReceivedFramesCount GUARDED_BY(mAccessLock) = 0;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace sv
-} // namespace automotive
-} // namespace hardware
-} // namespace android
diff --git a/cpp/surround_view/service-impl/service.cpp b/cpp/surround_view/service-impl/service.cpp
deleted file mode 100644
index b7d82f7..0000000
--- a/cpp/surround_view/service-impl/service.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2020 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.
- */
-
-#define ATRACE_TAG ATRACE_TAG_CAMERA
-
-#include <android-base/logging.h>
-#include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h>
-#include <android/hardware_buffer.h>
-#include <hidl/HidlTransportSupport.h>
-#include <thread>
-#include <ui/GraphicBuffer.h>
-#include <utils/Errors.h>
-#include <utils/StrongPointer.h>
-#include <utils/SystemClock.h>
-#include <utils/Trace.h>
-
-#include "SurroundViewService.h"
-
-// libhidl:
-using android::hardware::configureRpcThreadpool;
-using android::hardware::joinRpcThreadpool;
-
-// implementation:
-using android::hardware::automotive::sv::V1_0::implementation::SurroundViewService;
-
-int main() {
- LOG(INFO) << "ISurroundViewService default implementation is starting";
- android::sp<ISurroundViewService> service = SurroundViewService::getInstance();
-
- configureRpcThreadpool(1, true /* callerWillJoin */);
-
- ATRACE_BEGIN("SurroundViewServiceImpl: registerAsService");
-
- // Register our service -- if somebody is already registered by our name,
- // they will be killed (their thread pool will throw an exception).
- android::status_t status = service->registerAsService();
-
- if (status != android::OK) {
- LOG(ERROR) << "Could not register default Surround View Service. Status: "
- << status;
- }
-
- ATRACE_END();
-
- joinRpcThreadpool();
-
- // In normal operation, we don't expect the thread pool to exit
- LOG(ERROR) << "Surround View Service is shutting down";
- return 1;
-}
diff --git a/cpp/surround_view/service-impl/sv_3d_params.h b/cpp/surround_view/service-impl/sv_3d_params.h
deleted file mode 100644
index 0b6c223..0000000
--- a/cpp/surround_view/service-impl/sv_3d_params.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2020 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 SV_3D_PARAMS_H
-#define SV_3D_PARAMS_H
-
-#include <vector>
-#include <hidl/HidlSupport.h>
-
-using ::android::hardware::hidl_vec;
-
-static std::vector<android::hardware::hidl_vec<float>> kRecViews = {
- {0, 1, -0, -0, -0.747409, 0, 0.664364, 1.32873, 0.664364, -0, 0.747409, -4.52598, 0, 0, 0, 1},
- {-0.382683, 0.92388, 0, -0, -0.690516, -0.286021, 0.664364, 1.32873, 0.613792, 0.254241, 0.747409, -4.52598, 0, 0, 0, 1},
- {-0.707107, 0.707107, 0, -0, -0.528498, -0.528498, 0.664364, 1.32873, 0.469776, 0.469776, 0.747409, -4.52598, 0, 0, 0, 1},
- {-0.92388, 0.382683, 0, -1.19209e-07, -0.286021, -0.690516, 0.664364, 1.32873, 0.254241, 0.613792, 0.747409, -4.52598, 0, 0, 0, 1},
- {-1, -4.37114e-08, 0, -0, 3.26703e-08, -0.747409, 0.664364, 1.32873, -2.90403e-08, 0.664364, 0.747409, -4.52598, 0, 0, 0, 1},
- {-0.92388, -0.382683, 0, -0, 0.286021, -0.690516, 0.664364, 1.32873, -0.254241, 0.613792, 0.747409, -4.52598, 0, 0, 0, 1},
- {-0.707107, -0.707107, 0, -0, 0.528498, -0.528498, 0.664364, 1.32873, -0.469776, 0.469776, 0.747409, -4.52598, 0, 0, 0, 1},
- {-0.382683, -0.92388, 0, 1.19209e-07, 0.690516, -0.286021, 0.664364, 1.32873, -0.613792, 0.254241, 0.747409, -4.52598, 0, 0, 0, 1},
- {8.74228e-08, -1, 0, -0, 0.747409, 6.53406e-08, 0.664364, 1.32873, -0.664364, -5.80805e-08, 0.747409, -4.52598, 0, 0, 0, 1},
- {0.382683, -0.92388, 0, 1.19209e-07, 0.690516, 0.286021, 0.664364, 1.32873, -0.613792, -0.254241, 0.747409, -4.52598, 0, 0, 0, 1},
- {0.707107, -0.707107, 0, 1.19209e-07, 0.528498, 0.528498, 0.664364, 1.32873, -0.469776, -0.469776, 0.747409, -4.52598, 0, 0, 0, 1},
- {0.92388, -0.382684, 0, 1.19209e-07, 0.286021, 0.690516, 0.664364, 1.32873, -0.254241, -0.613792, 0.747409, -4.52598, 0, 0, 0, 1},
- {1, 1.19249e-08, -0, 3.55271e-15, -8.91277e-09, 0.747409, 0.664364, 1.32873, 7.92246e-09, -0.664364, 0.747409, -4.52598, 0, 0, 0, 1},
- {0.92388, 0.382684, -0, -0, -0.286021, 0.690516, 0.664364, 1.32873, 0.254241, -0.613792, 0.747409, -4.52598, 0, 0, 0, 1},
- {0.707107, 0.707107, -0, -1.19209e-07, -0.528498, 0.528498, 0.664364, 1.32873, 0.469776, -0.469776, 0.747409, -4.52598, 0, 0, 0, 1},
- {0.382683, 0.92388, -0, -1.19209e-07, -0.690516, 0.286021, 0.664364, 1.32873, 0.613792, -0.254241, 0.747409, -4.52598, 0, 0, 0, 1},
-};
-
-#endif // SV_3D_PARAMS_H
-
diff --git a/cpp/surround_view/service-impl/test_data/0.png b/cpp/surround_view/service-impl/test_data/0.png
deleted file mode 100644
index 283751b..0000000
--- a/cpp/surround_view/service-impl/test_data/0.png
+++ /dev/null
Binary files differ
diff --git a/cpp/surround_view/service-impl/test_data/1.png b/cpp/surround_view/service-impl/test_data/1.png
deleted file mode 100644
index 55abd66..0000000
--- a/cpp/surround_view/service-impl/test_data/1.png
+++ /dev/null
Binary files differ
diff --git a/cpp/surround_view/service-impl/test_data/2.png b/cpp/surround_view/service-impl/test_data/2.png
deleted file mode 100644
index c66dd61..0000000
--- a/cpp/surround_view/service-impl/test_data/2.png
+++ /dev/null
Binary files differ
diff --git a/cpp/surround_view/service-impl/test_data/3.png b/cpp/surround_view/service-impl/test_data/3.png
deleted file mode 100644
index f9d2c60..0000000
--- a/cpp/surround_view/service-impl/test_data/3.png
+++ /dev/null
Binary files differ
diff --git a/cpp/surround_view/service-impl/test_data/sample_car.obj b/cpp/surround_view/service-impl/test_data/sample_car.obj
deleted file mode 100644
index 3600a7b..0000000
--- a/cpp/surround_view/service-impl/test_data/sample_car.obj
+++ /dev/null
@@ -1,64 +0,0 @@
-# Sample Car Model Obj files
-# Consist of cubes representing a car part
-
-mtllib sample_car_material.mtl
-
-# Car Door Object
-v 0.0 0.0 0.0
-v 0.0 0.0 1.0
-v 0.0 1.0 0.0
-v 0.0 1.0 1.0
-v 1.0 0.0 0.0
-v 1.0 0.0 1.0
-v 1.0 1.0 0.0
-v 1.0 1.0 1.0
-vn 0.0 0.0 1.0
-vn 0.0 0.0 -1.0
-vn 0.0 1.0 0.0
-vn 0.0 -1.0 0.0
-vn 1.0 0.0 0.0
-vn -1.0 0.0 0.0
-g door
-usemtl door
-f 1//2 7//2 5//2
-f 1//2 3//2 7//2
-f 1//6 4//6 3//6
-f 1//6 2//6 4//6
-f 3//3 8//3 7//3
-f 3//3 4//3 8//3
-f 5//5 7//5 8//5
-f 5//5 8//5 6//5
-f 1//4 5//4 6//4
-f 1//4 6//4 2//4
-f 2//1 6//1 8//1
-f 2//1 8//1 4//1
-
-# Car Window Object
-v 0.0 0.0 0.0
-v 0.0 0.0 -1.0
-v 0.0 -1.0 0.0
-v 0.0 -1.0 1.0
-v -1.0 0.0 0.0
-v -1.0 0.0 -1.0
-v -1.0 -1.0 0.0
-v -1.0 -1.0 -1.0
-vn 0.0 0.0 1.0
-vn 0.0 0.0 -1.0
-vn 0.0 1.0 0.0
-vn 0.0 -1.0 0.0
-vn 1.0 0.0 0.0
-vn -1.0 0.0 0.0
-g window
-usemtl window
-f 1//2 7//2 5//2
-f 1//2 3//2 7//2
-f 1//6 4//6 3//6
-f 1//6 2//6 4//6
-f 3//3 8//3 7//3
-f 3//3 4//3 8//3
-f 5//5 7//5 8//5
-f 5//5 8//5 6//5
-f 1//4 5//4 6//4
-f 1//4 6//4 2//4
-f 2//1 6//1 8//1
-f 2//1 8//1 4//1
diff --git a/cpp/surround_view/service-impl/test_data/sample_car_material.mtl b/cpp/surround_view/service-impl/test_data/sample_car_material.mtl
deleted file mode 100644
index aaa2f1b..0000000
--- a/cpp/surround_view/service-impl/test_data/sample_car_material.mtl
+++ /dev/null
@@ -1,18 +0,0 @@
-# Sample material file for car model.
-# referenced by sample_car.obj
-
-newmtl door
- d 1.0000
- illum 1
- Ka 0.5000 0.5000 0.5000
- Kd 1.0000 1.0000 1.0000
- Ks 1.0000 1.0000 1.0000
- ns 0.0000
-
-newmtl window
- d 1.0000
- illum 1
- Ka 0.5000 0.5000 0.5000
- Kd 1.0000 0.0000 0.0000
- Ks 1.0000 1.0000 1.0000
- ns 0.0000
diff --git a/cpp/surround_view/service-impl/test_data/sv_sample_car_model_config.xml b/cpp/surround_view/service-impl/test_data/sv_sample_car_model_config.xml
deleted file mode 100644
index 60541a8..0000000
--- a/cpp/surround_view/service-impl/test_data/sv_sample_car_model_config.xml
+++ /dev/null
@@ -1,79 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<SurroundViewCarModelConfig>
- <Version>1.0</Version>
-
- <!-- Rotation animation for door -->
- <Animation>
- <PartId>door</PartId>
- <ChildParts>
- <PartId>window</PartId>
- </ChildParts>
- <ParentPartId>car_frame</ParentPartId>
- <RotationOp>
- <VhalProperty>
- <!-- Uses VHAL Property DOOR_POS -->
- <PropertyId>0x16000B00</PropertyId>
- <!-- AreadId = VehicleAreaDoor::ROW_1_LEFT -->
- <AreaId>0x00000001</AreaId>
- </VhalProperty>
- <AnimationType>RotationAngle</AnimationType>
- <AnimationTimeMs>2000</AnimationTimeMs>
- <RotationAxis>
- <X>0.0</X>
- <Y>0.0</Y>
- <Z>1.0</Z>
- </RotationAxis>
- <RotationPoint>
- <X>0.0</X>
- <Y>0.0</Y>
- <Z>0.0</Z>
- </RotationPoint>
- <DefaultRotationValue>0.0</DefaultRotationValue>
- <RotationRange>
- <Start>0.0</Start>
- <End>90</End>
- </RotationRange>
- <VhalRange>
- <!-- 0 => door closed -->
- <Start>0x00000000</Start>
- <!-- INT32_MAX => door fully open -->
- <End>0x7FFFFFFF</End>
- </VhalRange>
- </RotationOp>
- </Animation>
-
- <!-- Translation animation for window -->
- <Animation>
- <PartId>window</PartId>
- <ParentPartId>window</ParentPartId>
- <ChildParts>
- </ChildParts>
- <TranslationOp>
- <VhalProperty>
- <!-- Uses VHAL Property WINDOW_POS -->
- <PropertyId>0x13000BC0</PropertyId>
- <!-- AreaId = VehicleAreaWindow::ROW_1_LEFT -->
- <AreaId>0x00000010</AreaId>
- </VhalProperty>
- <AnimationType>Translation</AnimationType>
- <AnimationTimeMs>2000</AnimationTimeMs>
- <Direction>
- <X>0.0</X>
- <Y>0.0</Y>
- <Z>-1.0</Z>
- </Direction>
- <DefaultTranslationValue>0.0</DefaultTranslationValue>
- <TranslationRange>
- <Start>0.0</Start>
- <End>1.0</End>
- </TranslationRange>
- <VhalRange>
- <!-- 0 => window up/closed -->
- <Start>0x00000000</Start>
- <!-- INT32_MAX => window down/open -->
- <End>0x7FFFFFFF</End>
- </VhalRange>
- </TranslationOp>
- </Animation>
-
-</SurroundViewCarModelConfig>
diff --git a/cpp/surround_view/service-impl/test_data/sv_sample_config.xml b/cpp/surround_view/service-impl/test_data/sv_sample_config.xml
deleted file mode 100644
index 1a92bee..0000000
--- a/cpp/surround_view/service-impl/test_data/sv_sample_config.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<SurroundViewConfig>
- <Version>1.0</Version>
-
- <CameraConfig>
- <EvsGroupId>v4l2loopback_group0</EvsGroupId>
- <EvsCameraIds>
- <Front>/dev/video60</Front>
- <Right>/dev/video61</Right>
- <Rear>/dev/video62</Rear>
- <Left>/dev/video63</Left>
- </EvsCameraIds>
- <Masks>
- <Front>/vendor/etc/automotive/sv/mask_front.png</Front>
- <Right>/vendor/etc/automotive/sv/mask_right.png</Right>
- <Rear>/vendor/etc/automotive/sv/mask_rear.png</Rear>
- <Left>/vendor/etc/automotive/sv/mask_left.png</Left>
- </Masks>
- </CameraConfig>
-
- <Sv2dEnabled>true</Sv2dEnabled>
- <Sv2dParams>
- <OutputResolution>
- <Width>1200</Width>
- <Height>1600</Height>
- </OutputResolution>
- <GroundMapping>
- <Width>9.0</Width>
- <Height>12.0</Height>
- <Center>
- <X>0.0</X>
- <Y>0.0</Y>
- </Center>
- </GroundMapping>
- <CarBoundingBox>
- <Width>2.0</Width>
- <Height>3.0</Height>
- <LeftTopCorner>
- <X>1.0</X>
- <Y>1.5</Y>
- </LeftTopCorner>
- </CarBoundingBox>
- <BlendingType>
- <HighQuality>multiband</HighQuality>
- <LowQuality>alpha</LowQuality>
- </BlendingType>
- <GpuAccelerationEnabled>true</GpuAccelerationEnabled>
- </Sv2dParams>
-
- <Sv3dEnabled>true</Sv3dEnabled>
- <Sv3dAnimationsEnabled>true</Sv3dAnimationsEnabled>
- <CarModelConfigFile>/vendor/etc/automotive/sv/sv_sample_car_model_config.xml</CarModelConfigFile>
- <CarModelObjFile>/vendor/etc/automotive/sv/sample_car.obj</CarModelObjFile>
- <Sv3dParams>
- <OutputResolution>
- <Width>1920</Width>
- <Height>1080</Height>
- </OutputResolution>
- <BowlParams>
- <PlaneRadius>8.0</PlaneRadius>
- <PlaneDivisions>50</PlaneDivisions>
- <CurveHeight>6.0</CurveHeight>
- <CurveDivisions>50</CurveDivisions>
- <AngularDivisions>90</AngularDivisions>
- <CurveCoefficient>3.0</CurveCoefficient>
- </BowlParams>
- <HighQualityDetails>
- <Shadows>true</Shadows>
- <Reflections>true</Reflections>
- </HighQualityDetails>
- </Sv3dParams>
-</SurroundViewConfig>