summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHangyu Kuang <hkuang@google.com>2019-04-16 14:38:57 -0700
committerHangyu Kuang <hkuang@google.com>2019-04-19 14:07:51 -0700
commite4ac05b6892711fa43eb1d59c7846deb20026ae7 (patch)
tree1205592b44f27012cc8f397763719f0fd3b4f2a8
parentd8104e370b890f3d7a43282f13d4855847a318cb (diff)
downloadav-e4ac05b6892711fa43eb1d59c7846deb20026ae7.tar.gz
ECOService: Add ECOService implementation.
Also add unit test for it. Bug: 117877984 Test: Unit test. Change-Id: I5900c2bc628d850278bf8d742d09fb15cff3c078
-rw-r--r--media/eco/ECOService.cpp92
-rw-r--r--media/eco/ECOSession.cpp18
-rw-r--r--media/eco/include/eco/ECOService.h63
-rw-r--r--media/eco/include/eco/ECOSession.h20
-rw-r--r--media/eco/tests/Android.bp19
-rw-r--r--media/eco/tests/EcoServiceTest.cpp228
-rw-r--r--media/eco/tests/EcoSessionTest.cpp7
-rw-r--r--media/eco/tests/FakeECOServiceInfoListener.cpp10
-rw-r--r--media/eco/tests/FakeECOServiceInfoListener.h4
-rw-r--r--media/eco/tests/FakeECOServiceStatsProvider.cpp15
-rw-r--r--media/eco/tests/FakeECOServiceStatsProvider.h5
-rw-r--r--media/eco/tests/run_all_unit_tests.sh2
12 files changed, 449 insertions, 34 deletions
diff --git a/media/eco/ECOService.cpp b/media/eco/ECOService.cpp
index 1d4012d..0c25c7e 100644
--- a/media/eco/ECOService.cpp
+++ b/media/eco/ECOService.cpp
@@ -56,21 +56,93 @@ ECOService::ECOService() : BnECOService() {
}
/*virtual*/ ::android::binder::Status ECOService::obtainSession(
- int32_t /* width */, int32_t /* height */, bool /* isCameraRecording */,
- ::android::sp<::android::media::eco::IECOSession>* /* _aidl_return */) {
- //TODO(hkuang): Add implementation.
- return STATUS_ERROR(ERROR_UNSUPPORTED, "Not implemented yet");
+ int32_t width, int32_t height, bool isCameraRecording,
+ ::android::sp<::android::media::eco::IECOSession>* _aidl_return) {
+ ALOGI("ECOService::obtainSession w: %d, h: %d, isCameraRecording: %d", width, height,
+ isCameraRecording);
+
+ if (width <= 0) {
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Width can not be <= 0");
+ }
+
+ if (height <= 0) {
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Height can not be <= 0");
+ }
+
+ if (!isCameraRecording) {
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Only support camera recording");
+ }
+
+ SessionConfig newCfg(width, height, isCameraRecording);
+
+ ALOGD("session count is %zu", mSessionConfigToSessionMap.size());
+
+ Mutex::Autolock lock(mServiceLock);
+ bool foundSession = false;
+ // Instead of looking up the map directly, take the chance to scan the map and evict all the
+ // invalid sessions.
+ SanitizeSession([&](MapIterType iter) {
+ if (iter->first == newCfg) {
+ sp<IECOSession> session = iter->second.promote();
+ foundSession = true;
+ *_aidl_return = session;
+ }
+ });
+
+ if (foundSession) {
+ return binder::Status::ok();
+ }
+
+ // Create a new session and add it to the record.
+ *_aidl_return = ECOSession::createECOSession(width, height, isCameraRecording);
+ if (*_aidl_return == nullptr) {
+ ALOGE("ECOService failed to create ECOSession w: %d, h: %d, isCameraRecording: %d", width,
+ height, isCameraRecording);
+ return STATUS_ERROR(ERROR_UNSUPPORTED, "Failed to create eco session");
+ }
+ // Insert the new session into the map.
+ mSessionConfigToSessionMap[newCfg] = *_aidl_return;
+
+ return binder::Status::ok();
}
-/*virtual*/ ::android::binder::Status ECOService::getNumOfSessions(int32_t* /* _aidl_return */) {
- //TODO(hkuang): Add implementation.
- return STATUS_ERROR(ERROR_UNSUPPORTED, "Not implemented yet");
+/*virtual*/ ::android::binder::Status ECOService::getNumOfSessions(int32_t* _aidl_return) {
+ Mutex::Autolock lock(mServiceLock);
+ SanitizeSession(std::function<void(MapIterType it)>()); // empty callback
+ *_aidl_return = mSessionConfigToSessionMap.size();
+ return binder::Status::ok();
}
/*virtual*/ ::android::binder::Status ECOService::getSessions(
- ::std::vector<::android::sp<::android::IBinder>>* /* _aidl_return */) {
- //TODO(hkuang): Add implementation.
- return STATUS_ERROR(ERROR_UNSUPPORTED, "Not implemented yet");
+ ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) {
+ // Clear all the entries in the vector.
+ _aidl_return->clear();
+
+ Mutex::Autolock lock(mServiceLock);
+ SanitizeSession([&](MapIterType iter) {
+ sp<IECOSession> session = iter->second.promote();
+ _aidl_return->push_back(IInterface::asBinder(session));
+ });
+ return binder::Status::ok();
+}
+
+inline bool isEmptySession(const android::wp<IECOSession>& entry) {
+ sp<IECOSession> session = entry.promote();
+ return session == nullptr;
+}
+
+void ECOService::SanitizeSession(
+ const std::function<void(std::unordered_map<SessionConfig, wp<IECOSession>,
+ SessionConfigHash>::iterator it)>& callback) {
+ for (auto it = mSessionConfigToSessionMap.begin(), end = mSessionConfigToSessionMap.end();
+ it != end;) {
+ if (isEmptySession(it->second)) {
+ it = mSessionConfigToSessionMap.erase(it);
+ } else {
+ if(callback != nullptr) { callback(it); };
+ it++;
+ }
+ }
}
/*virtual*/ void ECOService::binderDied(const wp<IBinder>& /*who*/) {}
diff --git a/media/eco/ECOSession.cpp b/media/eco/ECOSession.cpp
index 8bf34b1..6540c17 100644
--- a/media/eco/ECOSession.cpp
+++ b/media/eco/ECOSession.cpp
@@ -56,7 +56,7 @@ sp<ECOSession> ECOSession::createECOSession(int32_t width, int32_t height, bool
// TODO(hkuang): Support the same resolution as in EAF. Also relax the isCameraRecording
// as encoder may not konw it is from camera for some usage cases.
if (width > 1280 || height > 720 || width == 0 || height == 0 || isCameraRecording == false) {
- ALOGD("Failed to create ECOSession with w: %d, h: %d, isCameraRecording: %d", width, height,
+ ALOGE("Failed to create ECOSession with w: %d, h: %d, isCameraRecording: %d", width, height,
isCameraRecording);
return nullptr;
}
@@ -72,7 +72,7 @@ ECOSession::ECOSession(int32_t width, int32_t height, bool isCameraRecording)
mWidth(width),
mHeight(height),
mIsCameraRecording(isCameraRecording) {
- ALOGD("ECOSession created with w: %d, h: %d, isCameraRecording: %d", mWidth, mHeight,
+ ALOGI("ECOSession created with w: %d, h: %d, isCameraRecording: %d", mWidth, mHeight,
mIsCameraRecording);
}
@@ -92,6 +92,8 @@ void ECOSession::stop() {
ECOSession::~ECOSession() {
stop();
+ ALOGI("ECOSession destroyed with w: %d, h: %d, isCameraRecording: %d", mWidth, mHeight,
+ mIsCameraRecording);
}
// static
@@ -262,6 +264,12 @@ Status ECOSession::addStatsProvider(
return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Provider config is invalid");
}
+ ::android::String16 name;
+ provider->getName(&name);
+
+ ALOGD("Stats provider name: %s uid: %d pid %d", ::android::String8(name).string(),
+ IPCThreadState::self()->getCallingUid(), IPCThreadState::self()->getCallingPid());
+
mProvider = provider;
*status = true;
return binder::Status::ok();
@@ -315,6 +323,12 @@ Status ECOSession::addInfoListener(
return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "listener config is not valid");
}
+ ::android::String16 name;
+ listener->getName(&name);
+
+ ALOGD("Info listener name: %s uid: %d pid %d", ::android::String8(name).string(),
+ IPCThreadState::self()->getCallingUid(), IPCThreadState::self()->getCallingPid());
+
mListener = listener;
*status = true;
return binder::Status::ok();
diff --git a/media/eco/include/eco/ECOService.h b/media/eco/include/eco/ECOService.h
index 21278a0..3fa0535 100644
--- a/media/eco/include/eco/ECOService.h
+++ b/media/eco/include/eco/ECOService.h
@@ -18,12 +18,21 @@
#define ANDROID_MEDIA_ECO_SERVICE_H_
#include <android/media/eco/BnECOService.h>
+#include <android/media/eco/BnECOSession.h>
#include <binder/BinderService.h>
+#include <list>
+
+#include "eco/ECOService.h"
+#include "eco/ECOSession.h"
+
namespace android {
namespace media {
namespace eco {
+using android::sp;
+using android::binder::Status;
+
/**
* ECO (Encoder Camera Optimization) service.
*
@@ -47,18 +56,15 @@ class ECOService : public BinderService<ECOService>,
public:
ECOService();
- //TODO(hkuang): Add the implementation.
- virtual ~ECOService() {}
+ virtual ~ECOService() = default;
- virtual ::android::binder::Status obtainSession(
- int32_t width, int32_t height, bool isCameraRecording,
- ::android::sp<::android::media::eco::IECOSession>* _aidl_return);
+ virtual Status obtainSession(int32_t width, int32_t height, bool isCameraRecording,
+ sp<IECOSession>* _aidl_return);
- virtual ::android::binder::Status getNumOfSessions(int32_t* _aidl_return);
+ virtual Status getNumOfSessions(int32_t* _aidl_return);
- virtual ::android::binder::Status getSessions(
- ::std::vector<::android::sp<::android::IBinder>>* _aidl_return);
+ virtual Status getSessions(::std::vector<sp<IBinder>>* _aidl_return);
// Implementation of BinderService<T>
static char const* getServiceName() { return "media.ecoservice"; }
@@ -67,6 +73,47 @@ public:
virtual void binderDied(const wp<IBinder>& who);
private:
+ // Lock guarding ECO service state
+ Mutex mServiceLock;
+
+ struct SessionConfig {
+ int32_t mWidth;
+ int32_t mHeight;
+ bool mIsCameraRecording;
+
+ SessionConfig(int w, int h, bool isCameraRecording)
+ : mWidth(w), mHeight(h), mIsCameraRecording(isCameraRecording) {}
+
+ bool operator==(const SessionConfig& cfg) {
+ return mWidth == cfg.mWidth && mHeight == cfg.mHeight &&
+ mIsCameraRecording == cfg.mIsCameraRecording;
+ }
+ };
+
+ friend bool operator==(const SessionConfig& p1, const SessionConfig& p2) {
+ return p1.mWidth == p2.mWidth && p1.mHeight == p2.mHeight &&
+ p1.mIsCameraRecording == p2.mIsCameraRecording;
+ }
+
+ // Hash function for mSessionConfigToSessionMap.
+ // TODO(hkuang): Add test for this hash function.
+ struct SessionConfigHash {
+ size_t operator()(const SessionConfig& cfg) const {
+ // Generate a hash by bit shifting and concatenation.
+ return cfg.mWidth | (cfg.mHeight << 16) | ((int32_t)cfg.mIsCameraRecording << 31);
+ }
+ };
+
+ // Map from SessionConfig to session.
+ std::unordered_map<SessionConfig, wp<IECOSession>, SessionConfigHash>
+ mSessionConfigToSessionMap;
+
+ using MapIterType =
+ std::unordered_map<SessionConfig, wp<IECOSession>, SessionConfigHash>::iterator;
+
+ // A helpful function to traverse the mSessionConfigToSessionMap, remove the entry that
+ // does not exist any more and call |callback| when the entry is valid.
+ void SanitizeSession(const std::function<void(MapIterType it)>& callback);
};
} // namespace eco
diff --git a/media/eco/include/eco/ECOSession.h b/media/eco/include/eco/ECOSession.h
index 9453448..ee08495 100644
--- a/media/eco/include/eco/ECOSession.h
+++ b/media/eco/include/eco/ECOSession.h
@@ -55,21 +55,18 @@ class ECOSession : public BinderService<ECOSession>,
public:
virtual ~ECOSession();
- virtual Status addStatsProvider(
- const sp<::android::media::eco::IECOServiceStatsProvider>& provider,
- const ::android::media::eco::ECOData& statsConfig, /*out*/ bool* status);
+ virtual Status addStatsProvider(const sp<IECOServiceStatsProvider>& provider,
+ const ECOData& statsConfig, /*out*/ bool* status);
- virtual Status removeStatsProvider(const sp<::android::media::eco::IECOServiceStatsProvider>&,
- bool*);
+ virtual Status removeStatsProvider(const sp<IECOServiceStatsProvider>&, bool*);
- virtual Status addInfoListener(const sp<::android::media::eco::IECOServiceInfoListener>&,
- const ::android::media::eco::ECOData& listenerConfig,
+ virtual Status addInfoListener(const sp<IECOServiceInfoListener>&,
+ const ECOData& listenerConfig,
/*out*/ bool* status);
- virtual Status removeInfoListener(const sp<::android::media::eco::IECOServiceInfoListener>&,
- bool*);
+ virtual Status removeInfoListener(const sp<IECOServiceInfoListener>&, bool*);
- virtual Status pushNewStats(const ::android::media::eco::ECOData&, bool*);
+ virtual Status pushNewStats(const ECOData&, bool*);
virtual Status getWidth(int32_t* _aidl_return);
@@ -85,6 +82,9 @@ public:
// Grant permission to EcoSessionTest to run test.
friend class EcoSessionTest;
+ // Let ECOService create the session.
+ friend class ECOService;
+
protected:
static android::sp<ECOSession> createECOSession(int32_t width, int32_t height,
bool isCameraRecording);
diff --git a/media/eco/tests/Android.bp b/media/eco/tests/Android.bp
index 430998b..6eb3015 100644
--- a/media/eco/tests/Android.bp
+++ b/media/eco/tests/Android.bp
@@ -35,4 +35,23 @@ cc_test {
"liblog",
"libmedia_ecoservice",
],
+}
+
+cc_test {
+ name: "EcoServiceTest",
+ vendor: true,
+ defaults: ["libmedia_ecoservice_tests_defaults"],
+ srcs: [
+ "EcoServiceTest.cpp",
+ "FakeECOServiceStatsProvider.cpp",
+ "FakeECOServiceInfoListener.cpp",
+ ],
+
+ shared_libs: [
+ "libbinder",
+ "libcutils",
+ "libutils",
+ "liblog",
+ "libmedia_ecoservice",
+ ],
} \ No newline at end of file
diff --git a/media/eco/tests/EcoServiceTest.cpp b/media/eco/tests/EcoServiceTest.cpp
new file mode 100644
index 0000000..ad8530f
--- /dev/null
+++ b/media/eco/tests/EcoServiceTest.cpp
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Unit Test for ECOService.
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "ECOServiceTest"
+
+#include <android-base/unique_fd.h>
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+#include <cutils/ashmem.h>
+#include <gtest/gtest.h>
+#include <math.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <utils/Log.h>
+
+#include "FakeECOServiceInfoListener.h"
+#include "FakeECOServiceStatsProvider.h"
+#include "eco/ECOService.h"
+#include "eco/ECOUtils.h"
+
+namespace android {
+namespace media {
+namespace eco {
+
+using ::android::IBinder;
+using android::sp;
+using ::android::binder::Status;
+
+namespace {
+
+static constexpr uint32_t kTestWidth = 1280;
+static constexpr uint32_t kTestHeight = 720;
+static constexpr bool kIsCameraRecording = true;
+static constexpr float kFrameRate = 30.0f;
+
+} // namespace anonymous
+
+// A helper class to help create ECOService and manage ECOService.
+class EcoServiceTest : public ::testing::Test {
+public:
+ EcoServiceTest() { ALOGD("EcoServiceTest created"); }
+
+ sp<IECOService> createService() {
+ android::sp<android::IServiceManager> sm = android::defaultServiceManager();
+ assert(sm != 0);
+ android::sp<android::IBinder> binder = sm->getService(String16("media.ecoservice"));
+
+ if (binder == 0) {
+ ALOGE("Failed to connect to ecoservice");
+ return nullptr;
+ } else {
+ ALOGD("Successfully connect to ecoservice");
+ }
+
+ mECOService = android::interface_cast<IECOService>(binder);
+ return mECOService;
+ }
+
+ ~EcoServiceTest() { ALOGD("EcoServiceTest destroyed"); }
+
+private:
+ sp<IECOService> mECOService = nullptr;
+};
+
+TEST_F(EcoServiceTest, NormalObtainSessionWithInvalidWidth) {
+ sp<IECOService> service = createService();
+ EXPECT_TRUE(service != nullptr);
+
+ // Provider obtains the session from the service.
+ sp<IECOSession> session = nullptr;
+
+ service->obtainSession(-1 /* width */, kTestHeight, kIsCameraRecording, &session);
+ EXPECT_FALSE(session);
+}
+
+TEST_F(EcoServiceTest, NormalObtainSessionWithInvalidHeight) {
+ sp<IECOService> service = createService();
+
+ // Provider obtains the session from the service.
+ sp<IECOSession> session = nullptr;
+
+ service->obtainSession(kTestWidth, -1 /* height */, kIsCameraRecording, &session);
+ EXPECT_FALSE(session);
+}
+
+TEST_F(EcoServiceTest, NormalObtainSessionWithInvalidCameraRecording) {
+ sp<IECOService> service = createService();
+
+ // Provider obtains the session from the service.
+ sp<IECOSession> session = nullptr;
+
+ service->obtainSession(kTestWidth, kTestHeight, false /* isCameraRecording */, &session);
+ EXPECT_FALSE(session);
+}
+
+TEST_F(EcoServiceTest, NormalObtainSingleSession) {
+ sp<IECOService> service = createService();
+ EXPECT_TRUE(service != nullptr);
+
+ // Provider obtains the session from the service.
+ sp<IECOSession> session = nullptr;
+
+ service->obtainSession(kTestWidth, kTestHeight, kIsCameraRecording, &session);
+ EXPECT_TRUE(session);
+}
+
+TEST_F(EcoServiceTest, NormalObtainSessionTwice) {
+ sp<IECOService> service = createService();
+ EXPECT_TRUE(service != nullptr);
+
+ // Provider obtains the session from the service.
+ sp<IECOSession> session1 = nullptr;
+
+ service->obtainSession(kTestWidth, kTestHeight, kIsCameraRecording, &session1);
+ EXPECT_TRUE(session1);
+
+ sp<IECOSession> session2 = nullptr;
+
+ service->obtainSession(kTestWidth, kTestHeight, kIsCameraRecording, &session2);
+ EXPECT_TRUE(session2);
+
+ // The two session instances should be the same.
+ EXPECT_TRUE(IInterface::asBinder(session1) == IInterface::asBinder(session2));
+}
+
+TEST_F(EcoServiceTest, ObtainTwoSessions) {
+ sp<IECOService> service = createService();
+ EXPECT_TRUE(service != nullptr);
+
+ // Provider obtains the session from the service.
+ sp<IECOSession> session1 = nullptr;
+
+ service->obtainSession(kTestWidth, kTestHeight, kIsCameraRecording, &session1);
+ EXPECT_TRUE(session1);
+
+ sp<IECOSession> session2 = nullptr;
+
+ service->obtainSession(kTestWidth - 1, kTestHeight - 1, kIsCameraRecording, &session2);
+ EXPECT_TRUE(session2);
+
+ // The two session instances must not be the same.
+ EXPECT_TRUE(IInterface::asBinder(session1) != IInterface::asBinder(session2));
+
+ // Check the session number.
+ int32_t count = 0;
+ service->getNumOfSessions(&count);
+ EXPECT_EQ(count, 2);
+
+ // Get the list of sessions from service.
+ std::vector<sp<IBinder>> sessionList;
+ service->getSessions(&sessionList);
+ bool foundFirstSession = false, foundSecondSession = false;
+
+ for (std::vector<sp<IBinder>>::iterator it = sessionList.begin(); it != sessionList.end();
+ ++it) {
+ if (IInterface::asBinder(session1) == it->get()) {
+ foundFirstSession = true;
+ }
+ if (IInterface::asBinder(session2) == it->get()) {
+ foundSecondSession = true;
+ }
+ }
+
+ // Expect found both sessions.
+ EXPECT_TRUE(foundFirstSession);
+ EXPECT_TRUE(foundSecondSession);
+}
+
+TEST_F(EcoServiceTest, TestNormalFlowWithOneListenerAndOneProvider) {
+ sp<IECOService> service = createService();
+ EXPECT_TRUE(service != nullptr);
+
+ // Provider obtains the session from the service.
+ sp<IECOSession> session = nullptr;
+
+ service->obtainSession(kTestWidth, kTestHeight, kIsCameraRecording, &session);
+ EXPECT_TRUE(session);
+
+ // Create provider and add it to the session.
+ sp<FakeECOServiceStatsProvider> fakeProvider = new FakeECOServiceStatsProvider(
+ kTestWidth, kTestHeight, kIsCameraRecording, kFrameRate);
+ fakeProvider->setECOSession(session);
+
+ ECOData providerConfig(ECOData::DATA_TYPE_STATS_PROVIDER_CONFIG,
+ systemTime(SYSTEM_TIME_BOOTTIME));
+ providerConfig.setString(KEY_PROVIDER_NAME, "FakeECOServiceStatsProvider");
+ providerConfig.setInt32(KEY_PROVIDER_TYPE,
+ ECOServiceStatsProvider::STATS_PROVIDER_TYPE_VIDEO_ENCODER);
+ bool res;
+ Status status = session->addStatsProvider(fakeProvider, providerConfig, &res);
+
+ // Create listener and add it to the session.
+ sp<FakeECOServiceInfoListener> fakeListener =
+ new FakeECOServiceInfoListener(kTestWidth, kTestHeight, kIsCameraRecording);
+ fakeListener->setECOSession(session);
+
+ // Create the listener config.
+ ECOData listenerConfig(ECOData::DATA_TYPE_INFO_LISTENER_CONFIG,
+ systemTime(SYSTEM_TIME_BOOTTIME));
+ listenerConfig.setString(KEY_LISTENER_NAME, "FakeECOServiceInfoListener");
+ listenerConfig.setInt32(KEY_LISTENER_TYPE, ECOServiceInfoListener::INFO_LISTENER_TYPE_CAMERA);
+
+ // Specify the qp thresholds for receiving notification.
+ listenerConfig.setInt32(KEY_LISTENER_QP_BLOCKINESS_THRESHOLD, 40);
+ listenerConfig.setInt32(KEY_LISTENER_QP_CHANGE_THRESHOLD, 5);
+
+ status = session->addInfoListener(fakeListener, listenerConfig, &res);
+}
+
+} // namespace eco
+} // namespace media
+} // namespace android
diff --git a/media/eco/tests/EcoSessionTest.cpp b/media/eco/tests/EcoSessionTest.cpp
index e917331..901a22b 100644
--- a/media/eco/tests/EcoSessionTest.cpp
+++ b/media/eco/tests/EcoSessionTest.cpp
@@ -75,7 +75,8 @@ TEST_F(EcoSessionTest, TestConstructorWithInvalidParameters) {
nullptr);
// Expects failure as ECOService1.0 will only support up to 720P and camera recording case.
- EXPECT_TRUE(createSession(1920 /* width */, 1080 /* height */, false /* isCameraRecording */) == nullptr);
+ EXPECT_TRUE(createSession(1920 /* width */, 1080 /* height */, false /* isCameraRecording */) ==
+ nullptr);
EXPECT_TRUE(createSession(1920 /* width */, -1 /* height */, true /* isCameraRecording */) ==
nullptr);
@@ -246,7 +247,9 @@ TEST_F(EcoSessionTest, TestSessionWithProviderAndListenerSimpleTest) {
});
// Inject the session stats into the ECOSession through fakeProvider.
- SimpleEncoderConfig sessionEncoderConfig("google-avc", CodecTypeAVC, AVCProfileHigh, AVCLevel52, kTargetBitrateBps, kKeyFrameIntervalFrames, kFrameRate);
+ SimpleEncoderConfig sessionEncoderConfig("google-avc", CodecTypeAVC, AVCProfileHigh, AVCLevel52,
+ kTargetBitrateBps, kKeyFrameIntervalFrames,
+ kFrameRate);
fakeProvider->injectSessionStats(sessionEncoderConfig.toEcoData(ECOData::DATA_TYPE_STATS));
// Wait as ECOService may take some time to process.
diff --git a/media/eco/tests/FakeECOServiceInfoListener.cpp b/media/eco/tests/FakeECOServiceInfoListener.cpp
index 76319b8..2a4a285 100644
--- a/media/eco/tests/FakeECOServiceInfoListener.cpp
+++ b/media/eco/tests/FakeECOServiceInfoListener.cpp
@@ -46,6 +46,13 @@ FakeECOServiceInfoListener::FakeECOServiceInfoListener(int32_t width, int32_t he
mHeight, mIsCameraRecording);
}
+FakeECOServiceInfoListener::FakeECOServiceInfoListener(int32_t width, int32_t height,
+ bool isCameraRecording)
+ : mWidth(width), mHeight(height), mIsCameraRecording(isCameraRecording) {
+ ALOGD("FakeECOServiceInfoListener construct with w: %d, h: %d, isCameraRecording: %d", mWidth,
+ mHeight, mIsCameraRecording);
+}
+
FakeECOServiceInfoListener::~FakeECOServiceInfoListener() {
ALOGD("FakeECOServiceInfoListener destructor");
}
@@ -54,7 +61,8 @@ Status FakeECOServiceInfoListener::getType(int32_t* /*_aidl_return*/) {
return binder::Status::ok();
}
-Status FakeECOServiceInfoListener::getName(::android::String16* /*_aidl_return*/) {
+Status FakeECOServiceInfoListener::getName(::android::String16* _aidl_return) {
+ *_aidl_return = String16("FakeECOServiceInfoListener");
return binder::Status::ok();
}
diff --git a/media/eco/tests/FakeECOServiceInfoListener.h b/media/eco/tests/FakeECOServiceInfoListener.h
index c828990..9974b63 100644
--- a/media/eco/tests/FakeECOServiceInfoListener.h
+++ b/media/eco/tests/FakeECOServiceInfoListener.h
@@ -54,6 +54,10 @@ public:
FakeECOServiceInfoListener(int32_t width, int32_t height, bool isCameraRecording,
sp<IECOSession> session);
+ FakeECOServiceInfoListener(int32_t width, int32_t height, bool isCameraRecording);
+
+ void setECOSession(android::sp<IECOSession> session) { mECOSession = session; }
+
virtual ~FakeECOServiceInfoListener();
virtual Status getType(int32_t* _aidl_return);
diff --git a/media/eco/tests/FakeECOServiceStatsProvider.cpp b/media/eco/tests/FakeECOServiceStatsProvider.cpp
index 4114549..883a830 100644
--- a/media/eco/tests/FakeECOServiceStatsProvider.cpp
+++ b/media/eco/tests/FakeECOServiceStatsProvider.cpp
@@ -49,6 +49,18 @@ FakeECOServiceStatsProvider::FakeECOServiceStatsProvider(int32_t width, int32_t
mWidth, mHeight, mIsCameraRecording, mFrameRate);
}
+FakeECOServiceStatsProvider::FakeECOServiceStatsProvider(int32_t width, int32_t height,
+ bool isCameraRecording, float frameRate)
+ : mWidth(width),
+ mHeight(height),
+ mIsCameraRecording(isCameraRecording),
+ mFrameRate(frameRate),
+ mFrameNumber(0) {
+ ALOGD("FakeECOServiceStatsProvider construct with w: %d, h: %d, isCameraRecording: %d, "
+ "frameRate: %f",
+ mWidth, mHeight, mIsCameraRecording, mFrameRate);
+}
+
FakeECOServiceStatsProvider::~FakeECOServiceStatsProvider() {
ALOGD("FakeECOServiceStatsProvider destructor");
}
@@ -57,7 +69,8 @@ Status FakeECOServiceStatsProvider::getType(int32_t* /*_aidl_return*/) {
return binder::Status::ok();
}
-Status FakeECOServiceStatsProvider::getName(::android::String16* /*_aidl_return*/) {
+Status FakeECOServiceStatsProvider::getName(::android::String16* _aidl_return) {
+ *_aidl_return = String16("FakeECOServiceStatsProvider");
return binder::Status::ok();
}
diff --git a/media/eco/tests/FakeECOServiceStatsProvider.h b/media/eco/tests/FakeECOServiceStatsProvider.h
index dbc4d7b..e514605 100644
--- a/media/eco/tests/FakeECOServiceStatsProvider.h
+++ b/media/eco/tests/FakeECOServiceStatsProvider.h
@@ -56,6 +56,11 @@ public:
FakeECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording,
float frameRate, android::sp<IECOSession> session);
+ FakeECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording,
+ float frameRate);
+
+ void setECOSession(android::sp<IECOSession> session) { mECOSession = session; }
+
// Helper function to inject session stats to the FakeECOServiceStatsProvider so provider
// could push to the service.
bool injectSessionStats(const ECOData& stats);
diff --git a/media/eco/tests/run_all_unit_tests.sh b/media/eco/tests/run_all_unit_tests.sh
index a27844e..7cbe27b 100644
--- a/media/eco/tests/run_all_unit_tests.sh
+++ b/media/eco/tests/run_all_unit_tests.sh
@@ -9,3 +9,5 @@ adb root && adb wait-for-device remount && adb sync
adb shell /data/nativetest/EcoDataTest/EcoDataTest
adb shell /data/nativetest/EcoSessionTest/EcoSessionTest
+#ECOService test lives in vendor side.
+adb shell data/nativetest/vendor/EcoServiceTest/EcoServiceTest