xref: /aosp_15_r20/frameworks/av/media/codec2/hal/common/HalSelection.cpp (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
2  * Copyright 2023 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 "Codec2-HalSelection"
19 #include <android-base/logging.h>
20 
21 // NOTE: due to dependency from mainline modules cannot use libsysprop
22 // #include <android/sysprop/MediaProperties.sysprop.h>
23 #include <android-base/properties.h>
24 #include <android_media_codec.h>
25 #include <com_android_media_codec_flags.h>
26 
27 #include <codec2/common/HalSelection.h>
28 
29 namespace android {
30 
IsCodec2AidlHalSelected()31 bool IsCodec2AidlHalSelected() {
32     // For new devices with vendor software targeting 202404, we always want to
33     // use AIDL if it exists
34     constexpr int kAndroidApi202404 = 202404;
35     int vendorVersion = ::android::base::GetIntProperty("ro.vendor.api_level", -1);
36     if (!com::android::media::codec::flags::provider_->aidl_hal() &&
37         vendorVersion < kAndroidApi202404) {
38         // Cannot select AIDL if not enabled
39         return false;
40     }
41 #if 0
42     // NOTE: due to dependency from mainline modules cannot use libsysprop
43     using ::android::sysprop::MediaProperties::codec2_hal_selection;
44     using ::android::sysprop::MediaProperties::codec2_hal_selection_values;
45     constexpr codec2_hal_selection_values AIDL = codec2_hal_selection_values::AIDL;
46     constexpr codec2_hal_selection_values HIDL = codec2_hal_selection_values::HIDL;
47     codec2_hal_selection_values selection = codec2_hal_selection().value_or(HIDL);
48     switch (selection) {
49     case AIDL:
50         return true;
51     case HIDL:
52         return false;
53     default:
54         LOG(FATAL) << "Unexpected codec2 HAL selection value: " << (int)selection;
55     }
56 #else
57     std::string selection = ::android::base::GetProperty("media.c2.hal.selection", "hidl");
58     if (selection == "aidl") {
59         return true;
60     } else if (selection == "hidl") {
61         return false;
62     } else {
63         LOG(FATAL) << "Unexpected codec2 HAL selection value: " << selection;
64     }
65 #endif
66 
67     return false;
68 }
69 
IsCodec2AidlInputSurfaceSelected()70 bool IsCodec2AidlInputSurfaceSelected() {
71     if (!IsCodec2AidlHalSelected()) {
72         return false;
73     }
74 
75     int32_t inputSurfaceSetting = ::android::base::GetIntProperty(
76             "debug.stagefright.c2inputsurface", int32_t(0));
77     if (inputSurfaceSetting <= 0) {
78         return false;
79     }
80     if (!android::media::codec::provider_->aidl_hal_input_surface()) {
81         return false;
82     }
83     return true;
84 }
85 
86 }  // namespace android
87