summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-03-07 04:08:30 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-03-07 04:08:30 +0000
commit96efecb72eee3cd9a2ddce0696d7745418fe7388 (patch)
tree03dd1aa61f801516a2e08dacc72b347751b8c8d7
parent7d9962ee57bbf85c655c7f72fb9c34f5550ba368 (diff)
parentbfe261f3cb32d20117cfb8f080c22daa99815f25 (diff)
downloadav-96efecb72eee3cd9a2ddce0696d7745418fe7388.tar.gz
Snap for 5357520 from bfe261f3cb32d20117cfb8f080c22daa99815f25 to qt-release
Change-Id: I4089f47624795f6e78a975b8561d59edde883134
-rw-r--r--media/eco/.clang-format33
-rw-r--r--media/eco/Android.bp52
-rw-r--r--media/eco/ECOData.cpp47
-rw-r--r--media/eco/ECOService.cpp71
-rw-r--r--media/eco/OWNERS2
-rw-r--r--media/eco/aidl/android/media/eco/ECOData.aidl20
-rw-r--r--media/eco/aidl/android/media/eco/IECOService.aidl64
-rw-r--r--media/eco/aidl/android/media/eco/IECOServiceInfoListener.aidl57
-rw-r--r--media/eco/aidl/android/media/eco/IECOServiceStatsProvider.aidl49
-rw-r--r--media/eco/aidl/android/media/eco/IECOSession.aidl107
-rw-r--r--media/eco/include/eco/ECOData.h76
-rw-r--r--media/eco/include/eco/ECODataKey.h93
-rw-r--r--media/eco/include/eco/ECOService.h69
-rw-r--r--media/eco/include/eco/ECOServiceConstants.h250
14 files changed, 990 insertions, 0 deletions
diff --git a/media/eco/.clang-format b/media/eco/.clang-format
new file mode 100644
index 0000000..b043d46
--- /dev/null
+++ b/media/eco/.clang-format
@@ -0,0 +1,33 @@
+---
+BasedOnStyle: Google
+AllowShortFunctionsOnASingleLine: Inline
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: true
+BinPackArguments: true
+BinPackParameters: true
+CommentPragmas: NOLINT:.*
+ContinuationIndentWidth: 8
+DerivePointerAlignment: false
+IndentWidth: 4
+PointerAlignment: Left
+TabWidth: 4
+
+# Deviations from the above file:
+# "Don't indent the section label"
+AccessModifierOffset: -4
+# "Each line of text in your code should be at most 100 columns long."
+ColumnLimit: 100
+# "Constructor initializer lists can be all on one line or with subsequent
+# lines indented eight spaces.". clang-format does not support having the colon
+# on the same line as the constructor function name, so this is the best
+# approximation of that rule, which makes all entries in the list (except the
+# first one) have an eight space indentation.
+ConstructorInitializerIndentWidth: 6
+# There is nothing in go/droidcppstyle about case labels, but there seems to be
+# more code that does not indent the case labels in frameworks/base.
+IndentCaseLabels: false
+# There have been some bugs in which subsequent formatting operations introduce
+# weird comment jumps.
+ReflowComments: false
+# Android does support C++11 now.
+Standard: Cpp11
diff --git a/media/eco/Android.bp b/media/eco/Android.bp
new file mode 100644
index 0000000..ddd01e9
--- /dev/null
+++ b/media/eco/Android.bp
@@ -0,0 +1,52 @@
+cc_library_shared {
+name:
+ "libmedia_ecoservice",
+ vendor_available: true,
+
+ srcs: [
+ "aidl/android/media/eco/IECOService.aidl",
+ "aidl/android/media/eco/IECOSession.aidl",
+ "aidl/android/media/eco/IECOServiceStatsProvider.aidl",
+ "aidl/android/media/eco/IECOServiceInfoListener.aidl",
+ "ECOData.cpp",
+ "ECOService.cpp",
+ ],
+
+ aidl: {
+ local_include_dirs: ["include","aidl"],
+ export_aidl_headers: true,
+ },
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
+ local_include_dirs: [
+ "include",
+ ],
+
+ shared_libs: [
+ "libbinder",
+ "libcutils",
+ "liblog",
+ "libutils",
+ ],
+
+ export_include_dirs: [
+ "include"
+ ],
+
+ sanitize: {
+ misc_undefined: [
+ "unsigned-integer-overflow",
+ "signed-integer-overflow",
+ ],
+ cfi: false, // true,
+ diag: {
+ cfi: false, // true,
+ },
+ },
+
+ ldflags: ["-Wl,-Bsymbolic"],
+} \ No newline at end of file
diff --git a/media/eco/ECOData.cpp b/media/eco/ECOData.cpp
new file mode 100644
index 0000000..bb3fe1a
--- /dev/null
+++ b/media/eco/ECOData.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "ECOData"
+
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <binder/Parcel.h>
+
+#include "eco/ECOData.h"
+
+namespace android {
+namespace media {
+namespace eco {
+
+using namespace ::android;
+
+status_t ECOData::readFromParcel(const Parcel* parcel) {
+ parcel->readInt32(&mDataType);
+ parcel->readInt64(&mDataTimeUs);
+ return NO_ERROR;
+}
+
+status_t ECOData::writeToParcel(Parcel* parcel) const {
+ parcel->writeInt32(mDataType);
+ parcel->writeInt64(mDataTimeUs);
+ return NO_ERROR;
+}
+
+} // namespace eco
+} // namespace media
+} // namespace android \ No newline at end of file
diff --git a/media/eco/ECOService.cpp b/media/eco/ECOService.cpp
new file mode 100644
index 0000000..5b591ac
--- /dev/null
+++ b/media/eco/ECOService.cpp
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "ECOService"
+
+#include "eco/ECOService.h"
+#include <binder/BinderService.h>
+#include <cutils/atomic.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <algorithm>
+#include <climits>
+#include <cstring>
+#include <ctime>
+#include <string>
+
+namespace android {
+namespace media {
+namespace eco {
+
+// ----------------------------------------------------------------------------
+// Logging support -- this is for debugging only
+// Use "adb shell dumpsys media.ecoservice -v 1" to change it.
+volatile int32_t gLogLevel = 0;
+
+#define LOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__);
+#define LOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__);
+
+static void setLogLevel(int level) {
+ android_atomic_write(level, &gLogLevel);
+}
+
+// Convenience methods for constructing binder::Status objects for error returns
+
+#define STATUS_ERROR(errorCode, errorString) \
+ binder::Status::fromServiceSpecificError( \
+ errorCode, String8::format("%s:%d: %s", __FUNCTION__, __LINE__, errorString))
+
+#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
+ binder::Status::fromServiceSpecificError( \
+ errorCode, \
+ String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, __VA_ARGS__))
+
+// ----------------------------------------------------------------------------
+
+ECOService::ECOService() : BnECOService() {
+ ALOGD("ECOService created");
+ setLogLevel(10);
+}
+
+/*virtual*/ void ECOService::binderDied(const wp<IBinder>& /*who*/) {}
+
+} // namespace eco
+} // namespace media
+} // namespace android \ No newline at end of file
diff --git a/media/eco/OWNERS b/media/eco/OWNERS
new file mode 100644
index 0000000..2239c4f
--- /dev/null
+++ b/media/eco/OWNERS
@@ -0,0 +1,2 @@
+hkuang@google.com
+derekpang@google.com \ No newline at end of file
diff --git a/media/eco/aidl/android/media/eco/ECOData.aidl b/media/eco/aidl/android/media/eco/ECOData.aidl
new file mode 100644
index 0000000..162cd89
--- /dev/null
+++ b/media/eco/aidl/android/media/eco/ECOData.aidl
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+package android.media.eco;
+
+/** @hide */
+parcelable ECOData cpp_header "eco/ECOData.h"; \ No newline at end of file
diff --git a/media/eco/aidl/android/media/eco/IECOService.aidl b/media/eco/aidl/android/media/eco/IECOService.aidl
new file mode 100644
index 0000000..995abad
--- /dev/null
+++ b/media/eco/aidl/android/media/eco/IECOService.aidl
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+package android.media.eco;
+
+import android.media.eco.ECOData;
+import android.media.eco.IECOServiceStatsProvider;
+import android.media.eco.IECOServiceInfoListener;
+import android.media.eco.IECOSession;
+
+/**
+ * Binder interface for ECO (Encoder Camera Optimization) service.
+ * @hide
+ */
+interface IECOService {
+ /**
+ * All ECO service Binder calls may return a ServiceSpecificException with the following error
+ * codes.
+ */
+ const int ERROR_PERMISSION_DENIED = 1;
+ const int ERROR_ALREADY_EXISTS = 2;
+ const int ERROR_ILLEGAL_ARGUMENT = 3;
+ const int ERROR_DISCONNECTED = 4;
+ const int ERROR_INVALID_OPERATION = 5;
+ const int ERROR_UNSUPPORTED = 6;
+
+ /**
+ * Obtains an IECOSession from the ECO service.
+ *
+ * <p>ECOService will first check if the requested session already existed. If not, it will
+ * create and return the new session. This should be called by IECOServiceStatsProvider or
+ * IECOServiceInfoListener to obtain an ECOSession interface upon start.</p>
+ *
+ * @param width Width of the requested video session (in pixel).
+ * @param height Height of the requested video session (in pixel).
+ * @param isCameraRecording A boolean indicates whether the session is for camera recording.
+ *
+ * @return IECOSession The session instance created by the ECOService.
+ */
+ IECOSession obtainSession(int width, int height, boolean isCameraRecording);
+
+ /**
+ * Return the total number of sessions inside ECO service.
+ */
+ int getNumOfSessions();
+
+ /**
+ * Return a list containing all ECOSessions.
+ */
+ List<IBinder> getSessions();
+}
diff --git a/media/eco/aidl/android/media/eco/IECOServiceInfoListener.aidl b/media/eco/aidl/android/media/eco/IECOServiceInfoListener.aidl
new file mode 100644
index 0000000..a4757aa
--- /dev/null
+++ b/media/eco/aidl/android/media/eco/IECOServiceInfoListener.aidl
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+package android.media.eco;
+
+import android.media.eco.ECOData;
+
+/**
+ * Binder interface for ECO service information listener.
+*
+* {@hide}
+*/
+interface IECOServiceInfoListener {
+ /**
+ * All listener Binder calls may return a ServiceSpecificException with the following error
+ * codes.
+ */
+ const int ERROR_PERMISSION_DENIED = 1;
+ const int ERROR_ILLEGAL_ARGUMENT = 2;
+ const int ERROR_INVALID_OPERATION = 3;
+ const int ERROR_UNSUPPORTED = 4;
+
+ /**
+ * Constants for the type of the listener.
+ */
+ const int STATS_PROVIDER_TYPE_UNKNOWN = 1;
+ const int STATS_LISTENER_TYPE_VIDEO_ENCODER = 2;
+ const int STATS_LISTENER_TYPE_CAMERA = 3;
+
+ /**
+ * Return the type of the listener.
+ */
+ int getType();
+
+ /**
+ * Return the name of the listener.
+ */
+ String getName();
+
+ /**
+ * Handle the new info from ECOSession. This should only be called by ECOSession.
+ */
+ oneway void onNewInfo(in ECOData newInfo);
+} \ No newline at end of file
diff --git a/media/eco/aidl/android/media/eco/IECOServiceStatsProvider.aidl b/media/eco/aidl/android/media/eco/IECOServiceStatsProvider.aidl
new file mode 100644
index 0000000..7e7937d
--- /dev/null
+++ b/media/eco/aidl/android/media/eco/IECOServiceStatsProvider.aidl
@@ -0,0 +1,49 @@
+/*
+* 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.
+*/
+
+package android.media.eco;
+
+/**
+* An interface for providers that provides various statistics to ECO service.
+* {@hide}
+*/
+interface IECOServiceStatsProvider {
+ /**
+ * All provider Binder calls may return a ServiceSpecificException with the following error
+ * codes.
+ */
+ const int ERROR_PERMISSION_DENIED = 1;
+ const int ERROR_ILLEGAL_ARGUMENT = 2;
+ const int ERROR_INVALID_OPERATION = 3;
+ const int ERROR_UNSUPPORTED = 4;
+
+ /**
+ * Constants for the type of the provider.
+ */
+ const int STATS_PROVIDER_TYPE_UNKNOWN = 1;
+ const int STATS_PROVIDER_TYPE_VIDEO_ENCODER = 2;
+ const int STATS_PROVIDER_TYPE_CAMERA = 3;
+
+ /**
+ * Return the type of the provider.
+ */
+ int getType();
+
+ /**
+ * Return the name of the provider.
+ */
+ String getName();
+}
diff --git a/media/eco/aidl/android/media/eco/IECOSession.aidl b/media/eco/aidl/android/media/eco/IECOSession.aidl
new file mode 100644
index 0000000..341b24d
--- /dev/null
+++ b/media/eco/aidl/android/media/eco/IECOSession.aidl
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+
+package android.media.eco;
+
+import android.media.eco.ECOData;
+import android.media.eco.IECOServiceStatsProvider;
+import android.media.eco.IECOServiceInfoListener;
+
+/**
+ * Binder interface for ECO Session.
+ * @hide
+ */
+interface IECOSession {
+ /**
+ * All ECO session Binder calls may return a ServiceSpecificException with the following error
+ * codes.
+ */
+ const int ERROR_PERMISSION_DENIED = 1;
+ const int ERROR_ALREADY_EXISTS = 2;
+ const int ERROR_ILLEGAL_ARGUMENT = 3;
+ const int ERROR_DISCONNECTED = 4;
+ const int ERROR_INVALID_OPERATION = 5;
+ const int ERROR_UNSUPPORTED = 6;
+
+ /**
+ * Adds an ECOServiceStasProvider.
+ *
+ * <p>This is called by ECOServiceStasProvider to add itself to the ECOSession.</p>
+ *
+ * @param provider Provider that implements IECOServiceStatsProvider interface.
+ * @param options Options that specifies the types of the stats that the provider is going to
+ * provide.
+ *
+ * @return true if the provider was successfully added, false otherwise.
+ */
+ boolean addStatsProvider(IECOServiceStatsProvider provider, in ECOData options);
+
+ /**
+ * Removes an ECOServiceStasProvider from ECOSession.
+ *
+ * @param provider Provider that implements IECOServiceStatsProvider interface.
+ *
+ * @return true if the provider was successfully removed, false otherwise.
+ */
+ boolean removeStatsProvider(IECOServiceStatsProvider provider);
+
+ /**
+ * Registers an ECOServiceInfoListener.
+ *
+ * <p>This is called by IECOServiceInfoListener to add itself to the ECOSession.</p>
+ *
+ * @param listener Listener that implements IECOServiceInfoListener interface.
+ * @param options Options that specifies the criteria for the data that the listener is
+ * interested in.
+ *
+ * @return true if the listener was successfully added, false otherwise.
+ */
+ boolean addInfoListener(IECOServiceInfoListener listener, in ECOData options);
+
+ /**
+ * Removes an ECOServiceInfoListener from ECOSession.
+ *
+ * @param listener Listener that implements IECOServiceInfoListener interface.
+ *
+ * @return true if the listener was successfully removed, false otherwise.
+ */
+ boolean removeInfoListener(IECOServiceInfoListener listener);
+
+ /**
+ * Push new stats to the ECOSession. This should only be called by IECOServiceStatsProvider.
+ */
+ boolean pushNewStats(in ECOData newStats);
+
+ /**
+ * Return the width in pixels.
+ */
+ int getWidth();
+
+ /**
+ * Return the height in pixels.
+ */
+ int getHeight();
+
+ /**
+ * Query the number of listeners that a session has.
+ */
+ int getNumOfListeners();
+
+ /**
+ * Query the number of providers that a session has.
+ */
+ int getNumOfProviders();
+}
diff --git a/media/eco/include/eco/ECOData.h b/media/eco/include/eco/ECOData.h
new file mode 100644
index 0000000..9c17320
--- /dev/null
+++ b/media/eco/include/eco/ECOData.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_MEDIA_ECO_DATA_H_
+#define ANDROID_MEDIA_ECO_DATA_H_
+
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+
+namespace android {
+namespace media {
+namespace eco {
+
+/**
+* ECOData is the container for all messages passed between different components in ECOService.
+* All messages in ECOServices are represented by a list of key-value pairs.
+* For example:
+* "bit-rate" -> 22000000
+* "Provider-Name" -> "QCOM-Video-Encoder".
+* "avg-frame-qp" -> 40
+* ECOData follows the same design pattern of AMessage and Metadata in Media Framework.
+* TODO(hkuang): Add the implementation and sample usage.
+*/
+class ECOData : public Parcelable {
+public:
+ ECOData() : mDataType(0), mDataTimeUs(-1) {}
+ ECOData(int32_t type) : mDataType(type), mDataTimeUs(-1) {}
+ ECOData(int32_t type, int64_t timeUs) : mDataType(type), mDataTimeUs(timeUs) {}
+
+ // Constants for mDataType.
+ enum {
+ DATA_TYPE_UNKNOWN = 0,
+ /* Data sent from the ECOServiceStatsProvider to ECOService. */
+ DATA_TYPE_STATS = 1,
+ /* Data sent from the ECOService to ECOServiceInfoListener. */
+ DATA_TYPE_INFO = 2,
+ /* Configuration data sent by ECOServiceStatsProvider when connects with ECOService. */
+ DATA_TYPE_STATS_PROVIDER_OPTON = 3,
+ /* Configuration data sent by ECOServiceInfoListener when connects with ECOService. */
+ DATA_TYPE_INFO_LISTENER_OPTON = 4,
+ };
+
+ /**
+ * Serialization over Binder
+ */
+ status_t readFromParcel(const Parcel* parcel) override;
+ status_t writeToParcel(Parcel* parcel) const override;
+
+private:
+ /* The type of the data */
+ int32_t mDataType;
+
+ // The timestamp time associated with the data in microseconds. The timestamp should be in
+ // boottime time base. This is only used when the data type is stats or info. -1 means
+ // unavailable.
+ int64_t mDataTimeUs;
+};
+
+} // namespace eco
+} // namespace media
+} // namespace android
+
+#endif // ANDROID_MEDIA_ECO_DATA_H_
diff --git a/media/eco/include/eco/ECODataKey.h b/media/eco/include/eco/ECODataKey.h
new file mode 100644
index 0000000..7945ea0
--- /dev/null
+++ b/media/eco/include/eco/ECODataKey.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ANDROID_MEDIA_ECO_DATA_KEY_H_
+#define ANDROID_MEDIA_ECO_DATA_KEY_H_
+
+#include <stdint.h>
+#include <sys/mman.h>
+
+#include <android-base/unique_fd.h>
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+#include "ECOService.h"
+
+namespace android {
+namespace media {
+namespace eco {
+
+// ================================================================================================
+// Standard ECOService Stats keys. These keys are used in the ECOData sent from StatsProvider
+// to ECOService. Besides these standard keys, StatsProvider could also have their provider
+// specific keys.
+// ================================================================================================
+/* Keys for provider of type STATS_PROVIDER_TYPE_VIDEO_ENCODER. */
+constexpr char STATS_KEY_ENCODER_TYPE[] = "stats-encoder-type";
+constexpr char STATS_KEY_ENCODER_PROFILE[] = "stats-encoder-profile";
+constexpr char STATS_KEY_ENCODER_LEVEL[] = "stats-encoder-level";
+constexpr char STATS_KEY_ENCODER_TARGET_BITRATE_BPS[] = "stats-encoder-target-bitrate-bps";
+constexpr char STATS_KEY_ENCODER_KFI_FRAMES[] = "stats-encoder-kfi-frames";
+
+constexpr char STATS_KEY_FRAME_PTS_US[] = "stats-frame-pts-us";
+constexpr char STATS_KEY_FRAME_AVG_QP[] = "stats-frame-avg-qp";
+constexpr char STATS_KEY_FRAME_TYPE[] = "stats-frame-type";
+constexpr char STATS_KEY_FRAME_SIZE_BYTES[] = "stats-frame-size-bytes";
+
+// ================================================================================================
+// Standard ECOServiceStatsProvider option keys. These keys are used in the ECOData as an option
+// when StatsProvider connects with ECOService.
+// ================================================================================================
+constexpr char PROVIDER_KEY_NAME[] = "provider-name";
+constexpr char PROVIDER_KEY_TYPE[] = "provider-type";
+
+// ================================================================================================
+// Standard ECOServiceInfoListener option keys. These keys are used in the ECOData as option
+// when ECOServiceInfoListener connects with ECOService to specify the informations that the
+// listener wants to listen to.
+// ================================================================================================
+constexpr char LISTENER_KEY_LISTENER_NAME[] = "listener-name";
+constexpr char LISTENER_KEY_TYPE[] = "listener-type";
+// This key's value will be ECOData.
+constexpr char LISTENER_KEY_CRITERION[] = "listener-criterion";
+// Listener will receive notification when qp falls below this key's value.
+constexpr char LISTENER_KEY_CRITERION_QP_LOW[] = "listener-criterion-qp-low";
+// Listener will receive notification when qp goes beyond this key's value.
+constexpr char LISTENER_KEY_CRITERION_QP_HIGH[] = "listener-criterion-qp-high";
+// Listener will receive notification when bitrate goes beyond this key's value.
+constexpr char LISTENER_KEY_CRITERION_BITRATE_OVERSHOOT[] = "listener-criterion-bitrate-overshoot";
+// Listener will receive notification when bitrate falls below this key's value.
+constexpr char LISTENER_KEY_CRITERION_BITRATE_UNDERSHOOT[] =
+ "listener-criterion-bitrate-undershoot";
+
+// ================================================================================================
+// Standard ECOService Info keys. These keys are used in the ECOData sent from ECOService
+// to ECOServiceInfoListener. The information includes session informations and frame informations.
+// ================================================================================================
+constexpr char INFO_KEY_ENCODER_TYPE[] = "info-encoder-type";
+constexpr char INFO_KEY_ENCODER_PROFILE[] = "info-encoder-profile";
+constexpr char INFO_KEY_ENCODER_LEVEL[] = "info-encoder-level";
+constexpr char INFO_KEY_ENCODER_TARGET_BITRATE_BPS[] = "info-encoder-target-bitrate-bps";
+constexpr char INFO_KEY_ENCODER_KFI_FRAMES[] = "info-encoder-kfi-frames";
+
+constexpr char INFO_KEY_FRAME_AVG_QP[] = "info-frame-avg-qp";
+constexpr char INFO_KEY_FRAME_TYPE[] = "info-frame-type";
+constexpr char INFO_KEY_FRAME_SIZE_BYTES[] = "info-frame-size-bytes";
+constexpr char INFO_KEY_CURRENT_BITRATE_BPS[] = "info-current-bitrate-bps";
+
+} // namespace eco
+} // namespace media
+} // namespace android
+
+#endif // ANDROID_MEDIA_ECO_DATA_KEY_H_
diff --git a/media/eco/include/eco/ECOService.h b/media/eco/include/eco/ECOService.h
new file mode 100644
index 0000000..7b2ebfb
--- /dev/null
+++ b/media/eco/include/eco/ECOService.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_MEDIA_ECO_SERVICE_H_
+#define ANDROID_MEDIA_ECO_SERVICE_H_
+
+#include <android/media/eco/BnECOService.h>
+#include <binder/BinderService.h>
+
+#include "ECOData.h"
+
+namespace android {
+namespace media {
+namespace eco {
+
+typedef int32_t ecoservice_session_id_t;
+constexpr ecoservice_session_id_t kInvalidSessionId = -1;
+
+/**
+ * ECO (Encoder Camera Optimization) service.
+ *
+ * ECOService creates and manages EcoSession to relay feedback information between one or multiple
+ * ECOServiceStatsProvider and ECOServiceInfoListener. The relationship can be many-to-many. In
+ * general, ECOServiceStatsProvider extracts information from an encoder for a given encoding
+ * session. EcoSession then relays the encoder information to any subscribed
+ * ECOServiceInfoListener.
+ *
+ * Internally, ECOService creates an ECOSession for each encoding session. Upon start, both
+ * ECOServiceStatsProvider and ECOServiceInfoListener should call obtainSession to get the
+ * ECOSession instance. After that, ECOServiceStatsProvider should push Stats to ECOSession and
+ * ECOServiceInfoListener should listen to the info from ECOSession. Upon finish, both
+ * ECOServiceStatsProvider and ECOServiceInfoListener should remove themselves from ECOSession.
+ * Then ECOService will safely destroy the ECOSession.
+ */
+class ECOService : public BinderService<ECOService>,
+ public BnECOService,
+ public virtual IBinder::DeathRecipient {
+ friend class BinderService<ECOService>;
+
+public:
+ ECOService();
+ //TODO(hkuang): Add the implementation.
+
+ virtual ~ECOService() {}
+
+ // IBinder::DeathRecipient implementation
+ virtual void binderDied(const wp<IBinder>& who);
+
+private:
+};
+
+} // namespace eco
+} // namespace media
+} // namespace android
+
+#endif // ANDROID_MEDIA_ECO_SERVICE_H_
diff --git a/media/eco/include/eco/ECOServiceConstants.h b/media/eco/include/eco/ECOServiceConstants.h
new file mode 100644
index 0000000..c4cd72d
--- /dev/null
+++ b/media/eco/include/eco/ECOServiceConstants.h
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ANDROID_MEDIA_ECO_SERVICE_CONSTANTS_H_
+#define ANDROID_MEDIA_ECO_SERVICE_CONSTANTS_H_
+
+#include <stdint.h>
+#include <sys/mman.h>
+
+#include <ECOService.h>
+#include <android-base/unique_fd.h>
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+
+namespace android {
+namespace media {
+namespace eco {
+
+// Below constants are borrowed from
+// frameworks/av/media/libstagefright/include/media/stagefright/MediaCodecConstants.h
+
+// from MediaCodecInfo.java
+constexpr int32_t AVCProfileBaseline = 0x01;
+constexpr int32_t AVCProfileMain = 0x02;
+constexpr int32_t AVCProfileExtended = 0x04;
+constexpr int32_t AVCProfileHigh = 0x08;
+constexpr int32_t AVCProfileHigh10 = 0x10;
+constexpr int32_t AVCProfileHigh422 = 0x20;
+constexpr int32_t AVCProfileHigh444 = 0x40;
+constexpr int32_t AVCProfileConstrainedBaseline = 0x10000;
+constexpr int32_t AVCProfileConstrainedHigh = 0x80000;
+constexpr int32_t AVCLevel1 = 0x01;
+constexpr int32_t AVCLevel1b = 0x02;
+constexpr int32_t AVCLevel11 = 0x04;
+constexpr int32_t AVCLevel12 = 0x08;
+constexpr int32_t AVCLevel13 = 0x10;
+constexpr int32_t AVCLevel2 = 0x20;
+constexpr int32_t AVCLevel21 = 0x40;
+constexpr int32_t AVCLevel22 = 0x80;
+constexpr int32_t AVCLevel3 = 0x100;
+constexpr int32_t AVCLevel31 = 0x200;
+constexpr int32_t AVCLevel32 = 0x400;
+constexpr int32_t AVCLevel4 = 0x800;
+constexpr int32_t AVCLevel41 = 0x1000;
+constexpr int32_t AVCLevel42 = 0x2000;
+constexpr int32_t AVCLevel5 = 0x4000;
+constexpr int32_t AVCLevel51 = 0x8000;
+constexpr int32_t AVCLevel52 = 0x10000;
+constexpr int32_t AVCLevel6 = 0x20000;
+constexpr int32_t AVCLevel61 = 0x40000;
+constexpr int32_t AVCLevel62 = 0x80000;
+constexpr int32_t HEVCProfileMain = 0x01;
+constexpr int32_t HEVCProfileMain10 = 0x02;
+constexpr int32_t HEVCProfileMainStill = 0x04;
+constexpr int32_t HEVCProfileMain10HDR10 = 0x1000;
+constexpr int32_t HEVCProfileMain10HDR10Plus = 0x2000;
+constexpr int32_t HEVCMainTierLevel1 = 0x1;
+constexpr int32_t HEVCHighTierLevel1 = 0x2;
+constexpr int32_t HEVCMainTierLevel2 = 0x4;
+constexpr int32_t HEVCHighTierLevel2 = 0x8;
+constexpr int32_t HEVCMainTierLevel21 = 0x10;
+constexpr int32_t HEVCHighTierLevel21 = 0x20;
+constexpr int32_t HEVCMainTierLevel3 = 0x40;
+constexpr int32_t HEVCHighTierLevel3 = 0x80;
+constexpr int32_t HEVCMainTierLevel31 = 0x100;
+constexpr int32_t HEVCHighTierLevel31 = 0x200;
+constexpr int32_t HEVCMainTierLevel4 = 0x400;
+constexpr int32_t HEVCHighTierLevel4 = 0x800;
+constexpr int32_t HEVCMainTierLevel41 = 0x1000;
+constexpr int32_t HEVCHighTierLevel41 = 0x2000;
+constexpr int32_t HEVCMainTierLevel5 = 0x4000;
+constexpr int32_t HEVCHighTierLevel5 = 0x8000;
+constexpr int32_t HEVCMainTierLevel51 = 0x10000;
+constexpr int32_t HEVCHighTierLevel51 = 0x20000;
+constexpr int32_t HEVCMainTierLevel52 = 0x40000;
+constexpr int32_t HEVCHighTierLevel52 = 0x80000;
+constexpr int32_t HEVCMainTierLevel6 = 0x100000;
+constexpr int32_t HEVCHighTierLevel6 = 0x200000;
+constexpr int32_t HEVCMainTierLevel61 = 0x400000;
+constexpr int32_t HEVCHighTierLevel61 = 0x800000;
+constexpr int32_t HEVCMainTierLevel62 = 0x1000000;
+constexpr int32_t HEVCHighTierLevel62 = 0x2000000;
+
+inline static const char* asString_AVCProfile(int32_t i, const char* def = "??") {
+ switch (i) {
+ case AVCProfileBaseline:
+ return "Baseline";
+ case AVCProfileMain:
+ return "Main";
+ case AVCProfileExtended:
+ return "Extended";
+ case AVCProfileHigh:
+ return "High";
+ case AVCProfileHigh10:
+ return "High10";
+ case AVCProfileHigh422:
+ return "High422";
+ case AVCProfileHigh444:
+ return "High444";
+ case AVCProfileConstrainedBaseline:
+ return "ConstrainedBaseline";
+ case AVCProfileConstrainedHigh:
+ return "ConstrainedHigh";
+ default:
+ return def;
+ }
+}
+
+inline static const char* asString_AVCLevel(int32_t i, const char* def = "??") {
+ switch (i) {
+ case AVCLevel1:
+ return "1";
+ case AVCLevel1b:
+ return "1b";
+ case AVCLevel11:
+ return "1.1";
+ case AVCLevel12:
+ return "1.2";
+ case AVCLevel13:
+ return "1.3";
+ case AVCLevel2:
+ return "2";
+ case AVCLevel21:
+ return "2.1";
+ case AVCLevel22:
+ return "2.2";
+ case AVCLevel3:
+ return "3";
+ case AVCLevel31:
+ return "3.1";
+ case AVCLevel32:
+ return "3.2";
+ case AVCLevel4:
+ return "4";
+ case AVCLevel41:
+ return "4.1";
+ case AVCLevel42:
+ return "4.2";
+ case AVCLevel5:
+ return "5";
+ case AVCLevel51:
+ return "5.1";
+ case AVCLevel52:
+ return "5.2";
+ case AVCLevel6:
+ return "6";
+ case AVCLevel61:
+ return "6.1";
+ case AVCLevel62:
+ return "6.2";
+ default:
+ return def;
+ }
+}
+
+inline static const char* asString_HEVCProfile(int32_t i, const char* def = "??") {
+ switch (i) {
+ case HEVCProfileMain:
+ return "Main";
+ case HEVCProfileMain10:
+ return "Main10";
+ case HEVCProfileMainStill:
+ return "MainStill";
+ case HEVCProfileMain10HDR10:
+ return "Main10HDR10";
+ case HEVCProfileMain10HDR10Plus:
+ return "Main10HDR10Plus";
+ default:
+ return def;
+ }
+}
+
+inline static const char* asString_HEVCTierLevel(int32_t i, const char* def = "??") {
+ switch (i) {
+ case HEVCMainTierLevel1:
+ return "Main 1";
+ case HEVCHighTierLevel1:
+ return "High 1";
+ case HEVCMainTierLevel2:
+ return "Main 2";
+ case HEVCHighTierLevel2:
+ return "High 2";
+ case HEVCMainTierLevel21:
+ return "Main 2.1";
+ case HEVCHighTierLevel21:
+ return "High 2.1";
+ case HEVCMainTierLevel3:
+ return "Main 3";
+ case HEVCHighTierLevel3:
+ return "High 3";
+ case HEVCMainTierLevel31:
+ return "Main 3.1";
+ case HEVCHighTierLevel31:
+ return "High 3.1";
+ case HEVCMainTierLevel4:
+ return "Main 4";
+ case HEVCHighTierLevel4:
+ return "High 4";
+ case HEVCMainTierLevel41:
+ return "Main 4.1";
+ case HEVCHighTierLevel41:
+ return "High 4.1";
+ case HEVCMainTierLevel5:
+ return "Main 5";
+ case HEVCHighTierLevel5:
+ return "High 5";
+ case HEVCMainTierLevel51:
+ return "Main 5.1";
+ case HEVCHighTierLevel51:
+ return "High 5.1";
+ case HEVCMainTierLevel52:
+ return "Main 5.2";
+ case HEVCHighTierLevel52:
+ return "High 5.2";
+ case HEVCMainTierLevel6:
+ return "Main 6";
+ case HEVCHighTierLevel6:
+ return "High 6";
+ case HEVCMainTierLevel61:
+ return "Main 6.1";
+ case HEVCHighTierLevel61:
+ return "High 6.1";
+ case HEVCMainTierLevel62:
+ return "Main 6.2";
+ case HEVCHighTierLevel62:
+ return "High 6.2";
+ default:
+ return def;
+ }
+}
+
+}; // namespace eco
+
+} // namespace media
+} // namespace android
+} // namespace android
+
+#endif // ANDROID_MEDIA_ECO_SERVICE_CONSTANTS_H_