Add the abstraction layer for the camera classes
Test: Build
Bug: 277861838
Change-Id: I2ca960022916ef5db2896625208e74d4c0db5d36
diff --git a/automotive/evs/aidl/impl/default/include/EvsCameraBase.h b/automotive/evs/aidl/impl/default/include/EvsCameraBase.h
new file mode 100644
index 0000000..c3e9dfc
--- /dev/null
+++ b/automotive/evs/aidl/impl/default/include/EvsCameraBase.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2023 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 <aidl/android/hardware/automotive/evs/BnEvsCamera.h>
+
+namespace aidl::android::hardware::automotive::evs::implementation {
+
+class EvsCameraBase : public evs::BnEvsCamera {
+ private:
+ using Base = evs::BnEvsCamera;
+ using Self = EvsCameraBase;
+
+ public:
+ using Base::Base;
+
+ ~EvsCameraBase() override = default;
+
+ virtual void shutdown() = 0;
+
+ protected:
+ // This is used for the derived classes and it prevents constructors from direct access
+ // while it allows this class to be instantiated via ndk::SharedRefBase::make<>.
+ struct Sigil {
+ explicit Sigil() = default;
+ };
+};
+
+} // namespace aidl::android::hardware::automotive::evs::implementation
diff --git a/automotive/evs/aidl/impl/default/include/EvsEnumerator.h b/automotive/evs/aidl/impl/default/include/EvsEnumerator.h
index 259c266..7202bf8 100644
--- a/automotive/evs/aidl/impl/default/include/EvsEnumerator.h
+++ b/automotive/evs/aidl/impl/default/include/EvsEnumerator.h
@@ -17,8 +17,8 @@
#pragma once
#include "ConfigManager.h"
+#include "EvsCameraBase.h"
#include "EvsGlDisplay.h"
-#include "EvsMockCamera.h"
#include <aidl/android/frameworks/automotive/display/ICarDisplayProxy.h>
#include <aidl/android/hardware/automotive/evs/BnEvsEnumerator.h>
@@ -72,7 +72,7 @@
private:
struct CameraRecord {
evs::CameraDesc desc;
- std::weak_ptr<EvsMockCamera> activeInstance;
+ std::weak_ptr<EvsCameraBase> activeInstance;
CameraRecord(const char* cameraId) : desc() { desc.id = cameraId; }
};
diff --git a/automotive/evs/aidl/impl/default/include/EvsMockCamera.h b/automotive/evs/aidl/impl/default/include/EvsMockCamera.h
index 7e010a2..c7b9e0f 100644
--- a/automotive/evs/aidl/impl/default/include/EvsMockCamera.h
+++ b/automotive/evs/aidl/impl/default/include/EvsMockCamera.h
@@ -17,8 +17,8 @@
#pragma once
#include "ConfigManager.h"
+#include "EvsCameraBase.h"
-#include <aidl/android/hardware/automotive/evs/BnEvsCamera.h>
#include <aidl/android/hardware/automotive/evs/BufferDesc.h>
#include <aidl/android/hardware/automotive/evs/CameraDesc.h>
#include <aidl/android/hardware/automotive/evs/CameraParam.h>
@@ -36,14 +36,7 @@
namespace aidl::android::hardware::automotive::evs::implementation {
-class EvsMockCamera : public evs::BnEvsCamera {
- // This prevents constructors from direct access while it allows this class to
- // be instantiated via ndk::SharedRefBase::make<>.
- private:
- struct Sigil {
- explicit Sigil() = default;
- };
-
+class EvsMockCamera : public EvsCameraBase {
public:
// Methods from ::android::hardware::automotive::evs::IEvsCamera follow.
ndk::ScopedAStatus doneWithFrame(const std::vector<evs::BufferDesc>& buffers) override;
@@ -81,7 +74,9 @@
EvsMockCamera& operator=(const EvsMockCamera&) = delete;
virtual ~EvsMockCamera() override;
- void shutdown();
+
+ // Methods from EvsCameraBase follow.
+ void shutdown() override;
const evs::CameraDesc& getDesc() { return mDescription; }
diff --git a/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp b/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp
index 3a81346..ec4b18f 100644
--- a/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp
+++ b/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp
@@ -17,6 +17,7 @@
#include "EvsEnumerator.h"
#include "ConfigManager.h"
+#include "EvsCameraBase.h"
#include "EvsGlDisplay.h"
#include "EvsMockCamera.h"
@@ -243,7 +244,7 @@
}
// Has this camera already been instantiated by another caller?
- std::shared_ptr<EvsMockCamera> pActiveCamera = pRecord->activeInstance.lock();
+ std::shared_ptr<EvsCameraBase> pActiveCamera = pRecord->activeInstance.lock();
if (pActiveCamera) {
LOG(WARNING) << "Killing previous camera because of new caller";
closeCamera(pActiveCamera);
@@ -273,7 +274,7 @@
pRecord->activeInstance = pActiveCamera;
if (!pActiveCamera) {
- LOG(ERROR) << "Failed to create new EvsMockCamera object for " << id;
+ LOG(ERROR) << "Failed to create new EVS camera object for " << id;
return ScopedAStatus::fromServiceSpecificError(
static_cast<int>(EvsResult::UNDERLYING_SERVICE_ERROR));
}
@@ -460,7 +461,7 @@
if (!pRecord) {
LOG(ERROR) << "Asked to close a camera whose name isn't recognized";
} else {
- std::shared_ptr<EvsMockCamera> pActiveCamera = pRecord->activeInstance.lock();
+ std::shared_ptr<EvsCameraBase> pActiveCamera = pRecord->activeInstance.lock();
if (!pActiveCamera) {
LOG(WARNING) << "Somehow a camera is being destroyed "
<< "when the enumerator didn't know one existed";