1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "ECOUtils"
19
20 #include "eco/ECOUtils.h"
21
22 #include <utils/Timers.h>
23
24 namespace android {
25 namespace media {
26 namespace eco {
27
28 // Convert this SimpleEncoderConfig to ECOData with dataType.
toEcoData(ECOData::ECODatatype dataType)29 ECOData SimpleEncoderConfig::toEcoData(ECOData::ECODatatype dataType) {
30 ECOData data(dataType, systemTime(SYSTEM_TIME_BOOTTIME));
31 data.setString(KEY_STATS_TYPE, VALUE_STATS_TYPE_SESSION);
32 data.setInt32(ENCODER_TYPE, mCodecType);
33 data.setInt32(ENCODER_PROFILE, mProfile);
34 data.setInt32(ENCODER_LEVEL, mLevel);
35 data.setInt32(ENCODER_TARGET_BITRATE_BPS, mTargetBitrate);
36 data.setInt32(ENCODER_KFI_FRAMES, mKeyFrameIntervalFrames);
37 data.setFloat(ENCODER_FRAMERATE_FPS, mFrameRateFps);
38 return data;
39 }
40
41 // Convert this SimpleEncodedFrameData to ECOData with dataType.
toEcoData(ECOData::ECODatatype dataType)42 ECOData SimpleEncodedFrameData::toEcoData(ECOData::ECODatatype dataType) {
43 ECOData data(dataType, systemTime(SYSTEM_TIME_BOOTTIME));
44 data.setString(KEY_STATS_TYPE, VALUE_STATS_TYPE_FRAME);
45 data.setInt32(FRAME_NUM, mFrameNum);
46 data.setInt8(FRAME_TYPE, mFrameType);
47 data.setInt64(FRAME_PTS_US, mFramePtsUs);
48 data.setInt32(FRAME_AVG_QP, mAvgQp);
49 data.setInt32(FRAME_SIZE_BYTES, mFrameSizeBytes);
50 return data;
51 }
52
copyKeyValue(const ECOData & src,ECOData * dst)53 bool copyKeyValue(const ECOData& src, ECOData* dst) {
54 if (src.isEmpty() || dst == nullptr) return false;
55 dst->mKeyValueStore = src.mKeyValueStore;
56 return true;
57 }
58
59 } // namespace eco
60 } // namespace media
61 } // namespace android