1 /*
2  * Copyright (C) 2020 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 "ECOC2Utils"
19 #include "eco/ECOC2Utils.h"
20 
21 namespace android {
22 namespace media {
23 namespace eco {
24 
C2MediaType2ECOCodecType(std::shared_ptr<C2PortMediaTypeSetting::output> mediatype)25 int C2MediaType2ECOCodecType(std::shared_ptr<C2PortMediaTypeSetting::output> mediatype) {
26     std::string_view mime = mediatype->m.value;
27     if (!mime.compare("video/avc")) {
28         return CodecTypeAVC;
29     } else if (!mime.compare("video/hevc")) {
30         return CodecTypeHEVC;
31     }
32     return CodecTypeUnknown;
33 }
34 
C2Profile2ECOProfile(C2Config::profile_t profile)35 int C2Profile2ECOProfile(C2Config::profile_t profile) {
36     switch (profile) {
37         case PROFILE_AVC_BASELINE:
38             return AVCProfileBaseline;
39         case PROFILE_AVC_CONSTRAINED_BASELINE:
40             return AVCProfileConstrainedBaseline;
41         case PROFILE_AVC_MAIN:
42             return AVCProfileMain;
43         case PROFILE_AVC_HIGH:
44             return AVCProfileHigh;
45         case PROFILE_HEVC_MAIN:
46             return HEVCProfileMain;
47         default:
48             return 0;
49     }
50 }
51 
C2Level2ECOLevel(C2Config::level_t level)52 int C2Level2ECOLevel(C2Config::level_t level) {
53     switch (level) {
54         case LEVEL_AVC_1:
55             return AVCLevel1;
56         case LEVEL_AVC_1B:
57             return AVCLevel1b;
58         case LEVEL_AVC_1_1:
59             return AVCLevel11;
60         case LEVEL_AVC_1_2:
61             return AVCLevel12;
62         case LEVEL_AVC_1_3:
63             return AVCLevel13;
64         case LEVEL_AVC_2:
65             return AVCLevel2;
66         case LEVEL_AVC_2_1:
67             return AVCLevel21;
68         case LEVEL_AVC_2_2:
69             return AVCLevel22;
70         case LEVEL_AVC_3:
71             return AVCLevel3;
72         case LEVEL_AVC_3_1:
73             return AVCLevel31;
74         case LEVEL_AVC_3_2:
75             return AVCLevel32;
76         case LEVEL_AVC_4 :
77             return AVCLevel4;
78         case LEVEL_AVC_4_1:
79             return AVCLevel41;
80         case LEVEL_AVC_5:
81             return AVCLevel5;
82         case LEVEL_AVC_5_1:
83             return AVCLevel51;
84         case LEVEL_AVC_5_2:
85             return AVCLevel52;
86         case LEVEL_AVC_6:
87             return AVCLevel6;
88         case LEVEL_AVC_6_1:
89             return AVCLevel61;
90         case LEVEL_AVC_6_2:
91             return AVCLevel62;
92         case LEVEL_HEVC_MAIN_1:
93             return HEVCMainTierLevel1;
94         case LEVEL_HEVC_MAIN_2:
95             return HEVCMainTierLevel2;
96         case LEVEL_HEVC_MAIN_2_1:
97             return HEVCMainTierLevel21;
98         case LEVEL_HEVC_MAIN_3:
99             return HEVCMainTierLevel3;
100         case LEVEL_HEVC_MAIN_3_1:
101             return HEVCMainTierLevel31;
102         case LEVEL_HEVC_MAIN_4:
103             return HEVCMainTierLevel4;
104         case LEVEL_HEVC_MAIN_4_1:
105             return HEVCMainTierLevel41;
106         case LEVEL_HEVC_MAIN_5:
107             return HEVCMainTierLevel5;
108         case LEVEL_HEVC_MAIN_5_1:
109             return HEVCMainTierLevel51;
110         case LEVEL_HEVC_MAIN_5_2:
111             return HEVCMainTierLevel52;
112         case LEVEL_HEVC_MAIN_6:
113             return HEVCMainTierLevel6;
114         case LEVEL_HEVC_MAIN_6_1:
115             return HEVCMainTierLevel61;
116         case LEVEL_HEVC_MAIN_6_2:
117             return HEVCMainTierLevel62;
118         case LEVEL_HEVC_HIGH_4:
119             return HEVCHighTierLevel4;
120         case LEVEL_HEVC_HIGH_4_1:
121             return HEVCHighTierLevel41;
122         case LEVEL_HEVC_HIGH_5 :
123             return HEVCHighTierLevel5;
124         case LEVEL_HEVC_HIGH_5_1:
125             return HEVCHighTierLevel51;
126         case LEVEL_HEVC_HIGH_5_2:
127             return HEVCHighTierLevel52;
128         case LEVEL_HEVC_HIGH_6:
129             return HEVCHighTierLevel6;
130         case LEVEL_HEVC_HIGH_6_1:
131             return HEVCHighTierLevel61;
132         case LEVEL_HEVC_HIGH_6_2:
133             return HEVCHighTierLevel62;
134         default:
135             return 0;
136     }
137 }
138 
C2PictureType2ECOFrameType(C2Config::picture_type_t frametype)139 int C2PictureType2ECOFrameType(C2Config::picture_type_t frametype) {
140     switch (frametype) {
141         case I_FRAME:
142             return FrameTypeI;
143         case P_FRAME:
144             return FrameTypeP;
145         case B_FRAME:
146             return FrameTypeB;
147         default:
148             return FrameTypeUnknown;
149     }
150 }
151 
152 }  // namespace eco
153 }  // namespace media
154 }  // namespace android
155