1 /*
2  * Copyright 2018 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-ComponentInterface"
19 #include <android-base/logging.h>
20 
21 #include <codec2/hidl/1.0/Component.h>
22 #include <codec2/hidl/1.0/ComponentInterface.h>
23 #include <codec2/hidl/1.0/ComponentStore.h>
24 
25 #include <hidl/HidlBinderSupport.h>
26 #include <utils/Timers.h>
27 
28 #include <C2BqBufferPriv.h>
29 #include <C2Debug.h>
30 #include <C2PlatformSupport.h>
31 
32 #include <chrono>
33 #include <thread>
34 
35 namespace android {
36 namespace hardware {
37 namespace media {
38 namespace c2 {
39 namespace V1_0 {
40 namespace utils {
41 
42 using namespace ::android;
43 
44 namespace /* unnamed */ {
45 
46 // Implementation of ConfigurableC2Intf based on C2ComponentInterface
47 struct CompIntf : public ConfigurableC2Intf {
CompIntfandroid::hardware::media::c2::V1_0::utils::__anonabdf99c60111::CompIntf48     CompIntf(const std::shared_ptr<C2ComponentInterface>& intf) :
49         ConfigurableC2Intf{intf->getName(), intf->getId()},
50         mIntf{intf} {
51     }
52 
configandroid::hardware::media::c2::V1_0::utils::__anonabdf99c60111::CompIntf53     virtual c2_status_t config(
54             const std::vector<C2Param*>& params,
55             c2_blocking_t mayBlock,
56             std::vector<std::unique_ptr<C2SettingResult>>* const failures
57             ) override {
58         return mIntf->config_vb(params, mayBlock, failures);
59     }
60 
queryandroid::hardware::media::c2::V1_0::utils::__anonabdf99c60111::CompIntf61     virtual c2_status_t query(
62             const std::vector<C2Param::Index>& indices,
63             c2_blocking_t mayBlock,
64             std::vector<std::unique_ptr<C2Param>>* const params
65             ) const override {
66         return mIntf->query_vb({}, indices, mayBlock, params);
67     }
68 
querySupportedParamsandroid::hardware::media::c2::V1_0::utils::__anonabdf99c60111::CompIntf69     virtual c2_status_t querySupportedParams(
70             std::vector<std::shared_ptr<C2ParamDescriptor>>* const params
71             ) const override {
72         return mIntf->querySupportedParams_nb(params);
73     }
74 
querySupportedValuesandroid::hardware::media::c2::V1_0::utils::__anonabdf99c60111::CompIntf75     virtual c2_status_t querySupportedValues(
76             std::vector<C2FieldSupportedValuesQuery>& fields,
77             c2_blocking_t mayBlock) const override {
78         return mIntf->querySupportedValues_vb(fields, mayBlock);
79     }
80 
81 protected:
82     std::shared_ptr<C2ComponentInterface> mIntf;
83 };
84 
85 } // unnamed namespace
86 
87 // ComponentInterface
ComponentInterface(const std::shared_ptr<C2ComponentInterface> & intf,const std::shared_ptr<ParameterCache> & cache)88 ComponentInterface::ComponentInterface(
89         const std::shared_ptr<C2ComponentInterface>& intf,
90         const std::shared_ptr<ParameterCache>& cache)
91       : mInterface{intf},
92         mConfigurable{new CachedConfigurable(std::make_unique<CompIntf>(intf))} {
93     mInit = mConfigurable->init(cache);
94 }
95 
status() const96 c2_status_t ComponentInterface::status() const {
97     return mInit;
98 }
99 
getConfigurable()100 Return<sp<IConfigurable>> ComponentInterface::getConfigurable() {
101     return mConfigurable;
102 }
103 
104 }  // namespace utils
105 }  // namespace V1_0
106 }  // namespace c2
107 }  // namespace media
108 }  // namespace hardware
109 }  // namespace android
110 
111