summaryrefslogtreecommitdiff
path: root/media/eco/include
diff options
context:
space:
mode:
authorHangyu Kuang <hkuang@google.com>2019-02-21 10:22:49 -0800
committerHangyu Kuang <hkuang@google.com>2019-03-05 13:23:52 -0800
commit52cc6a407e54af6f9dd0123f82fbbe4892fef176 (patch)
treeab91d03052e883c0234ab818251e1da502a0a954 /media/eco/include
parent26773e831e6b4198f4c9c326b79f6c9e21f96b96 (diff)
downloadav-52cc6a407e54af6f9dd0123f82fbbe4892fef176.tar.gz
Add the skeleton of ECOService.
ECO service is a low-level service that relays encoder feedback information from vendor's encoder firmware to camera HAL. During runtime, ECO service can provide most up-to-date encoder feedback, such as bit-rate and quantization parameters (QP) to camera services. It enables any ISP modules under camera HAL to perform real-time adaption of the encoder states and optimize end-to-end capture and encoder quality in a closed-loop manner. ECO service consists of the following three components: 1) ECOService where the core service logic will run and make the decision. In Service 1.0, it will send the encoder config to the listener upon start and then keep monitoring the per-frame encoding result from the provider. If the QP or bitrate go beyond some threashold, it will notify the listener. 2) ECOServiceStatsProvider which will provide the stats to the ECOService and drive the decision. 3) ECOServiceEventListener which will listen to the decisions or events from ECO service. 4) ECOData is the container for all the data/msg between these three components. Bug: 117877984 Test: Compile the ECOService. Change-Id: I74aac04ec2d85fdb7f3eaa584d2c44e20d9d7f99
Diffstat (limited to 'media/eco/include')
-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
4 files changed, 488 insertions, 0 deletions
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_