Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 2 | * Copyright 2018 The Android Open Source Project |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 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 "Codec2Client" |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 19 | #include <android-base/logging.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 20 | |
| 21 | #include <codec2/hidl/client.h> |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 22 | #include <C2Debug.h> |
| 23 | #include <C2BufferPriv.h> |
Lajos Molnar | 78aa7c9 | 2021-02-18 21:39:01 -0800 | [diff] [blame] | 24 | #include <C2Config.h> // for C2StreamUsageTuning |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 25 | #include <C2PlatformSupport.h> |
| 26 | |
| 27 | #include <android/hardware/media/bufferpool/2.0/IClientManager.h> |
| 28 | #include <android/hardware/media/c2/1.0/IComponent.h> |
| 29 | #include <android/hardware/media/c2/1.0/IComponentInterface.h> |
| 30 | #include <android/hardware/media/c2/1.0/IComponentListener.h> |
| 31 | #include <android/hardware/media/c2/1.0/IComponentStore.h> |
| 32 | #include <android/hardware/media/c2/1.0/IConfigurable.h> |
| 33 | #include <android/hidl/manager/1.2/IServiceManager.h> |
| 34 | |
| 35 | #include <android-base/properties.h> |
| 36 | #include <bufferpool/ClientManager.h> |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 37 | #include <codec2/hidl/1.0/types.h> |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 38 | #include <codec2/hidl/1.1/types.h> |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 39 | #include <codec2/hidl/1.2/types.h> |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 40 | #include <codec2/hidl/output.h> |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 41 | |
| 42 | #include <cutils/native_handle.h> |
| 43 | #include <gui/bufferqueue/2.0/B2HGraphicBufferProducer.h> |
| 44 | #include <gui/bufferqueue/2.0/H2BGraphicBufferProducer.h> |
Lajos Molnar | 78aa7c9 | 2021-02-18 21:39:01 -0800 | [diff] [blame] | 45 | #include <hardware/gralloc.h> // for GRALLOC_USAGE_* |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 46 | #include <hidl/HidlSupport.h> |
Lajos Molnar | 78aa7c9 | 2021-02-18 21:39:01 -0800 | [diff] [blame] | 47 | #include <system/window.h> // for NATIVE_WINDOW_QUERY_* |
| 48 | #include <media/stagefright/foundation/ADebug.h> // for asString(status_t) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 49 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 50 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 51 | #include <deque> |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 52 | #include <iterator> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 53 | #include <limits> |
| 54 | #include <map> |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 55 | #include <mutex> |
| 56 | #include <sstream> |
| 57 | #include <thread> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 58 | #include <type_traits> |
| 59 | #include <vector> |
| 60 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 61 | namespace android { |
| 62 | |
| 63 | using ::android::hardware::hidl_vec; |
| 64 | using ::android::hardware::hidl_string; |
| 65 | using ::android::hardware::Return; |
| 66 | using ::android::hardware::Void; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 67 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 68 | using namespace ::android::hardware::media::c2::V1_1; |
| 69 | using namespace ::android::hardware::media::c2::V1_1::utils; |
| 70 | using namespace ::android::hardware::media::bufferpool::V2_0; |
| 71 | using namespace ::android::hardware::media::bufferpool::V2_0::implementation; |
| 72 | |
Pawin Vongmasa | ef939bf | 2019-03-03 04:44:59 -0800 | [diff] [blame] | 73 | using HGraphicBufferProducer1 = ::android::hardware::graphics::bufferqueue:: |
| 74 | V1_0::IGraphicBufferProducer; |
| 75 | using HGraphicBufferProducer2 = ::android::hardware::graphics::bufferqueue:: |
| 76 | V2_0::IGraphicBufferProducer; |
| 77 | using B2HGraphicBufferProducer2 = ::android::hardware::graphics::bufferqueue:: |
| 78 | V2_0::utils::B2HGraphicBufferProducer; |
| 79 | using H2BGraphicBufferProducer2 = ::android::hardware::graphics::bufferqueue:: |
| 80 | V2_0::utils::H2BGraphicBufferProducer; |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 81 | using ::android::hardware::media::c2::V1_2::SurfaceSyncObj; |
Pawin Vongmasa | ef939bf | 2019-03-03 04:44:59 -0800 | [diff] [blame] | 82 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 83 | namespace /* unnamed */ { |
| 84 | |
| 85 | // c2_status_t value that corresponds to hwbinder transaction failure. |
| 86 | constexpr c2_status_t C2_TRANSACTION_FAILED = C2_CORRUPTED; |
| 87 | |
Lajos Molnar | 78aa7c9 | 2021-02-18 21:39:01 -0800 | [diff] [blame] | 88 | // By default prepare buffer to be displayed on any of the common surfaces |
| 89 | constexpr uint64_t kDefaultConsumerUsage = |
| 90 | (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER); |
| 91 | |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 92 | // Searches for a name in GetServiceNames() and returns the index found. If the |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 93 | // name is not found, the returned index will be equal to |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 94 | // GetServiceNames().size(). |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 95 | size_t getServiceIndex(char const* name) { |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 96 | std::vector<std::string> const& names = Codec2Client::GetServiceNames(); |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 97 | size_t i = 0; |
| 98 | for (; i < names.size(); ++i) { |
| 99 | if (name == names[i]) { |
| 100 | break; |
| 101 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 102 | } |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 103 | return i; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Pawin Vongmasa | 83d2c55 | 2020-03-05 04:36:08 -0800 | [diff] [blame] | 106 | class Client2Store : public C2ComponentStore { |
| 107 | std::shared_ptr<Codec2Client> mClient; |
| 108 | |
| 109 | public: |
| 110 | Client2Store(std::shared_ptr<Codec2Client> const& client) |
| 111 | : mClient(client) { } |
| 112 | |
| 113 | virtual ~Client2Store() = default; |
| 114 | |
| 115 | virtual c2_status_t config_sm( |
| 116 | std::vector<C2Param*> const ¶ms, |
| 117 | std::vector<std::unique_ptr<C2SettingResult>>* const failures) { |
| 118 | return mClient->config(params, C2_MAY_BLOCK, failures); |
| 119 | }; |
| 120 | |
| 121 | virtual c2_status_t copyBuffer( |
| 122 | std::shared_ptr<C2GraphicBuffer>, |
| 123 | std::shared_ptr<C2GraphicBuffer>) { |
| 124 | return C2_OMITTED; |
| 125 | } |
| 126 | |
| 127 | virtual c2_status_t createComponent( |
| 128 | C2String, std::shared_ptr<C2Component>* const component) { |
| 129 | component->reset(); |
| 130 | return C2_OMITTED; |
| 131 | } |
| 132 | |
| 133 | virtual c2_status_t createInterface( |
| 134 | C2String, std::shared_ptr<C2ComponentInterface>* const interface) { |
| 135 | interface->reset(); |
| 136 | return C2_OMITTED; |
| 137 | } |
| 138 | |
| 139 | virtual c2_status_t query_sm( |
| 140 | std::vector<C2Param*> const& stackParams, |
| 141 | std::vector<C2Param::Index> const& heapParamIndices, |
| 142 | std::vector<std::unique_ptr<C2Param>>* const heapParams) const { |
| 143 | return mClient->query(stackParams, heapParamIndices, C2_MAY_BLOCK, heapParams); |
| 144 | } |
| 145 | |
| 146 | virtual c2_status_t querySupportedParams_nb( |
| 147 | std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const { |
| 148 | return mClient->querySupportedParams(params); |
| 149 | } |
| 150 | |
| 151 | virtual c2_status_t querySupportedValues_sm( |
| 152 | std::vector<C2FieldSupportedValuesQuery>& fields) const { |
| 153 | return mClient->querySupportedValues(fields, C2_MAY_BLOCK); |
| 154 | } |
| 155 | |
| 156 | virtual C2String getName() const { |
| 157 | return mClient->getName(); |
| 158 | } |
| 159 | |
| 160 | virtual std::shared_ptr<C2ParamReflector> getParamReflector() const { |
| 161 | return mClient->getParamReflector(); |
| 162 | } |
| 163 | |
| 164 | virtual std::vector<std::shared_ptr<C2Component::Traits const>> listComponents() { |
| 165 | return std::vector<std::shared_ptr<C2Component::Traits const>>(); |
| 166 | } |
| 167 | }; |
| 168 | |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 169 | } // unnamed namespace |
| 170 | |
| 171 | // This class caches a Codec2Client object and its component traits. The client |
| 172 | // will be created the first time it is needed, and it can be refreshed if the |
| 173 | // service dies (by calling invalidate()). The first time listComponents() is |
| 174 | // called from the client, the result will be cached. |
| 175 | class Codec2Client::Cache { |
| 176 | // Cached client |
| 177 | std::shared_ptr<Codec2Client> mClient; |
| 178 | mutable std::mutex mClientMutex; |
| 179 | |
| 180 | // Cached component traits |
| 181 | std::vector<C2Component::Traits> mTraits; |
| 182 | std::once_flag mTraitsInitializationFlag; |
| 183 | |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 184 | // The index of the service. This is based on GetServiceNames(). |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 185 | size_t mIndex; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 186 | // Called by s() exactly once to initialize the cache. The index must be a |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 187 | // valid index into the vector returned by GetServiceNames(). Calling |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 188 | // init(index) will associate the cache to the service with name |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 189 | // GetServiceNames()[index]. |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 190 | void init(size_t index) { |
| 191 | mIndex = index; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | public: |
| 195 | Cache() = default; |
| 196 | |
| 197 | // Initializes mClient if needed, then returns mClient. |
| 198 | // If the service is unavailable but listed in the manifest, this function |
| 199 | // will block indefinitely. |
| 200 | std::shared_ptr<Codec2Client> getClient() { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 201 | std::scoped_lock lock{mClientMutex}; |
| 202 | if (!mClient) { |
| 203 | mClient = Codec2Client::_CreateFromIndex(mIndex); |
| 204 | } |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 205 | CHECK(mClient) << "Failed to create Codec2Client to service \"" |
| 206 | << GetServiceNames()[mIndex] << "\". (Index = " |
| 207 | << mIndex << ")."; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 208 | return mClient; |
| 209 | } |
| 210 | |
| 211 | // Causes a subsequent call to getClient() to create a new client. This |
| 212 | // function should be called after the service dies. |
| 213 | // |
| 214 | // Note: This function is called only by ForAllServices(). |
| 215 | void invalidate() { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 216 | std::scoped_lock lock{mClientMutex}; |
| 217 | mClient = nullptr; |
| 218 | } |
| 219 | |
| 220 | // Returns a list of traits for components supported by the service. This |
| 221 | // list is cached. |
| 222 | std::vector<C2Component::Traits> const& getTraits() { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 223 | std::call_once(mTraitsInitializationFlag, [this]() { |
| 224 | bool success{false}; |
| 225 | // Spin until _listComponents() is successful. |
| 226 | while (true) { |
| 227 | std::shared_ptr<Codec2Client> client = getClient(); |
| 228 | mTraits = client->_listComponents(&success); |
| 229 | if (success) { |
| 230 | break; |
| 231 | } |
Pawin Vongmasa | 21617db | 2020-04-24 06:16:42 -0700 | [diff] [blame] | 232 | invalidate(); |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 233 | using namespace std::chrono_literals; |
| 234 | static constexpr auto kServiceRetryPeriod = 5s; |
| 235 | LOG(INFO) << "Failed to retrieve component traits from service " |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 236 | "\"" << GetServiceNames()[mIndex] << "\". " |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 237 | "Retrying..."; |
| 238 | std::this_thread::sleep_for(kServiceRetryPeriod); |
| 239 | } |
| 240 | }); |
| 241 | return mTraits; |
| 242 | } |
| 243 | |
| 244 | // List() returns the list of all caches. |
| 245 | static std::vector<Cache>& List() { |
| 246 | static std::vector<Cache> sCaches{[]() { |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 247 | size_t numServices = GetServiceNames().size(); |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 248 | std::vector<Cache> caches(numServices); |
| 249 | for (size_t i = 0; i < numServices; ++i) { |
| 250 | caches[i].init(i); |
| 251 | } |
| 252 | return caches; |
| 253 | }()}; |
| 254 | return sCaches; |
| 255 | } |
| 256 | }; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 257 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 258 | // Codec2ConfigurableClient |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 259 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 260 | const C2String& Codec2ConfigurableClient::getName() const { |
| 261 | return mName; |
| 262 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 263 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 264 | Codec2ConfigurableClient::Codec2ConfigurableClient( |
| 265 | const sp<IConfigurable>& base) |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 266 | : mBase{base}, |
| 267 | mName{[base]() -> C2String { |
| 268 | C2String outName; |
| 269 | Return<void> transStatus = base->getName( |
| 270 | [&outName](const hidl_string& name) { |
| 271 | outName = name.c_str(); |
| 272 | }); |
| 273 | return transStatus.isOk() ? outName : ""; |
| 274 | }()} { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 277 | c2_status_t Codec2ConfigurableClient::query( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 278 | const std::vector<C2Param*> &stackParams, |
| 279 | const std::vector<C2Param::Index> &heapParamIndices, |
| 280 | c2_blocking_t mayBlock, |
| 281 | std::vector<std::unique_ptr<C2Param>>* const heapParams) const { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 282 | hidl_vec<ParamIndex> indices( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 283 | stackParams.size() + heapParamIndices.size()); |
| 284 | size_t numIndices = 0; |
| 285 | for (C2Param* const& stackParam : stackParams) { |
| 286 | if (!stackParam) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 287 | LOG(WARNING) << "query -- null stack param encountered."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 288 | continue; |
| 289 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 290 | indices[numIndices++] = static_cast<ParamIndex>(stackParam->index()); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 291 | } |
| 292 | size_t numStackIndices = numIndices; |
| 293 | for (const C2Param::Index& index : heapParamIndices) { |
| 294 | indices[numIndices++] = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 295 | static_cast<ParamIndex>(static_cast<uint32_t>(index)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 296 | } |
| 297 | indices.resize(numIndices); |
| 298 | if (heapParams) { |
| 299 | heapParams->reserve(heapParams->size() + numIndices); |
| 300 | } |
| 301 | c2_status_t status; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 302 | Return<void> transStatus = mBase->query( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 303 | indices, |
| 304 | mayBlock == C2_MAY_BLOCK, |
| 305 | [&status, &numStackIndices, &stackParams, heapParams]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 306 | Status s, const Params& p) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 307 | status = static_cast<c2_status_t>(s); |
| 308 | if (status != C2_OK && status != C2_BAD_INDEX) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 309 | LOG(DEBUG) << "query -- call failed: " |
| 310 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 311 | return; |
| 312 | } |
| 313 | std::vector<C2Param*> paramPointers; |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 314 | if (!parseParamsBlob(¶mPointers, p)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 315 | LOG(ERROR) << "query -- error while parsing params."; |
| 316 | status = C2_CORRUPTED; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 317 | return; |
| 318 | } |
| 319 | size_t i = 0; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 320 | for (auto it = paramPointers.begin(); |
| 321 | it != paramPointers.end(); ) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 322 | C2Param* paramPointer = *it; |
| 323 | if (numStackIndices > 0) { |
| 324 | --numStackIndices; |
| 325 | if (!paramPointer) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 326 | LOG(WARNING) << "query -- null stack param."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 327 | ++it; |
| 328 | continue; |
| 329 | } |
| 330 | for (; i < stackParams.size() && !stackParams[i]; ) { |
| 331 | ++i; |
| 332 | } |
| 333 | if (i >= stackParams.size()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 334 | LOG(ERROR) << "query -- unexpected error."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 335 | status = C2_CORRUPTED; |
| 336 | return; |
| 337 | } |
| 338 | if (stackParams[i]->index() != paramPointer->index()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 339 | LOG(WARNING) << "query -- param skipped: " |
| 340 | "index = " |
| 341 | << stackParams[i]->index() << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 342 | stackParams[i++]->invalidate(); |
| 343 | continue; |
| 344 | } |
| 345 | if (!stackParams[i++]->updateFrom(*paramPointer)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 346 | LOG(WARNING) << "query -- param update failed: " |
| 347 | "index = " |
| 348 | << paramPointer->index() << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 349 | } |
| 350 | } else { |
| 351 | if (!paramPointer) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 352 | LOG(WARNING) << "query -- null heap param."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 353 | ++it; |
| 354 | continue; |
| 355 | } |
| 356 | if (!heapParams) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 357 | LOG(WARNING) << "query -- " |
| 358 | "unexpected extra stack param."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 359 | } else { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 360 | heapParams->emplace_back( |
| 361 | C2Param::Copy(*paramPointer)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | ++it; |
| 365 | } |
| 366 | }); |
| 367 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 368 | LOG(ERROR) << "query -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 369 | return C2_TRANSACTION_FAILED; |
| 370 | } |
| 371 | return status; |
| 372 | } |
| 373 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 374 | c2_status_t Codec2ConfigurableClient::config( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 375 | const std::vector<C2Param*> ¶ms, |
| 376 | c2_blocking_t mayBlock, |
| 377 | std::vector<std::unique_ptr<C2SettingResult>>* const failures) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 378 | Params hidlParams; |
| 379 | if (!createParamsBlob(&hidlParams, params)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 380 | LOG(ERROR) << "config -- bad input."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 381 | return C2_TRANSACTION_FAILED; |
| 382 | } |
| 383 | c2_status_t status; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 384 | Return<void> transStatus = mBase->config( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 385 | hidlParams, |
| 386 | mayBlock == C2_MAY_BLOCK, |
| 387 | [&status, ¶ms, failures]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 388 | Status s, |
| 389 | const hidl_vec<SettingResult> f, |
| 390 | const Params& o) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 391 | status = static_cast<c2_status_t>(s); |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 392 | if (status != C2_OK && status != C2_BAD_INDEX) { |
| 393 | LOG(DEBUG) << "config -- call failed: " |
| 394 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 395 | } |
| 396 | size_t i = failures->size(); |
| 397 | failures->resize(i + f.size()); |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 398 | for (const SettingResult& sf : f) { |
| 399 | if (!objcpy(&(*failures)[i++], sf)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 400 | LOG(ERROR) << "config -- " |
| 401 | << "invalid SettingResult returned."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 405 | if (!updateParamsFromBlob(params, o)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 406 | LOG(ERROR) << "config -- " |
| 407 | << "failed to parse returned params."; |
| 408 | status = C2_CORRUPTED; |
| 409 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 410 | }); |
| 411 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 412 | LOG(ERROR) << "config -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 413 | return C2_TRANSACTION_FAILED; |
| 414 | } |
| 415 | return status; |
| 416 | } |
| 417 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 418 | c2_status_t Codec2ConfigurableClient::querySupportedParams( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 419 | std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const { |
| 420 | // TODO: Cache and query properly! |
| 421 | c2_status_t status; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 422 | Return<void> transStatus = mBase->querySupportedParams( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 423 | std::numeric_limits<uint32_t>::min(), |
| 424 | std::numeric_limits<uint32_t>::max(), |
| 425 | [&status, params]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 426 | Status s, |
| 427 | const hidl_vec<ParamDescriptor>& p) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 428 | status = static_cast<c2_status_t>(s); |
| 429 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 430 | LOG(DEBUG) << "querySupportedParams -- call failed: " |
| 431 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 432 | return; |
| 433 | } |
| 434 | size_t i = params->size(); |
| 435 | params->resize(i + p.size()); |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 436 | for (const ParamDescriptor& sp : p) { |
| 437 | if (!objcpy(&(*params)[i++], sp)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 438 | LOG(ERROR) << "querySupportedParams -- " |
| 439 | << "invalid returned ParamDescriptor."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 440 | return; |
| 441 | } |
| 442 | } |
| 443 | }); |
| 444 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 445 | LOG(ERROR) << "querySupportedParams -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 446 | return C2_TRANSACTION_FAILED; |
| 447 | } |
| 448 | return status; |
| 449 | } |
| 450 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 451 | c2_status_t Codec2ConfigurableClient::querySupportedValues( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 452 | std::vector<C2FieldSupportedValuesQuery>& fields, |
| 453 | c2_blocking_t mayBlock) const { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 454 | hidl_vec<FieldSupportedValuesQuery> inFields(fields.size()); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 455 | for (size_t i = 0; i < fields.size(); ++i) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 456 | if (!objcpy(&inFields[i], fields[i])) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 457 | LOG(ERROR) << "querySupportedValues -- bad input"; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 458 | return C2_TRANSACTION_FAILED; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | c2_status_t status; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 463 | Return<void> transStatus = mBase->querySupportedValues( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 464 | inFields, |
| 465 | mayBlock == C2_MAY_BLOCK, |
| 466 | [&status, &inFields, &fields]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 467 | Status s, |
| 468 | const hidl_vec<FieldSupportedValuesQueryResult>& r) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 469 | status = static_cast<c2_status_t>(s); |
| 470 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 471 | LOG(DEBUG) << "querySupportedValues -- call failed: " |
| 472 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 473 | return; |
| 474 | } |
| 475 | if (r.size() != fields.size()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 476 | LOG(ERROR) << "querySupportedValues -- " |
| 477 | "input and output lists " |
| 478 | "have different sizes."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 479 | status = C2_CORRUPTED; |
| 480 | return; |
| 481 | } |
| 482 | for (size_t i = 0; i < fields.size(); ++i) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 483 | if (!objcpy(&fields[i], inFields[i], r[i])) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 484 | LOG(ERROR) << "querySupportedValues -- " |
| 485 | "invalid returned value."; |
| 486 | status = C2_CORRUPTED; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 487 | return; |
| 488 | } |
| 489 | } |
| 490 | }); |
| 491 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 492 | LOG(ERROR) << "querySupportedValues -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 493 | return C2_TRANSACTION_FAILED; |
| 494 | } |
| 495 | return status; |
| 496 | } |
| 497 | |
| 498 | // Codec2Client::Component::HidlListener |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 499 | struct Codec2Client::Component::HidlListener : public IComponentListener { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 500 | std::weak_ptr<Component> component; |
| 501 | std::weak_ptr<Listener> base; |
| 502 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 503 | virtual Return<void> onWorkDone(const WorkBundle& workBundle) override { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 504 | std::list<std::unique_ptr<C2Work>> workItems; |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 505 | if (!objcpy(&workItems, workBundle)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 506 | LOG(DEBUG) << "onWorkDone -- received corrupted WorkBundle."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 507 | return Void(); |
| 508 | } |
| 509 | // release input buffers potentially held by the component from queue |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 510 | std::shared_ptr<Codec2Client::Component> strongComponent = |
| 511 | component.lock(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 512 | if (strongComponent) { |
Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 513 | strongComponent->handleOnWorkDone(workItems); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 514 | } |
| 515 | if (std::shared_ptr<Codec2Client::Listener> listener = base.lock()) { |
Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 516 | listener->onWorkDone(component, workItems); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 517 | } else { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 518 | LOG(DEBUG) << "onWorkDone -- listener died."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 519 | } |
| 520 | return Void(); |
| 521 | } |
| 522 | |
| 523 | virtual Return<void> onTripped( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 524 | const hidl_vec<SettingResult>& settingResults) override { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 525 | std::vector<std::shared_ptr<C2SettingResult>> c2SettingResults( |
| 526 | settingResults.size()); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 527 | for (size_t i = 0; i < settingResults.size(); ++i) { |
| 528 | std::unique_ptr<C2SettingResult> c2SettingResult; |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 529 | if (!objcpy(&c2SettingResult, settingResults[i])) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 530 | LOG(DEBUG) << "onTripped -- received corrupted SettingResult."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 531 | return Void(); |
| 532 | } |
| 533 | c2SettingResults[i] = std::move(c2SettingResult); |
| 534 | } |
| 535 | if (std::shared_ptr<Codec2Client::Listener> listener = base.lock()) { |
| 536 | listener->onTripped(component, c2SettingResults); |
| 537 | } else { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 538 | LOG(DEBUG) << "onTripped -- listener died."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 539 | } |
| 540 | return Void(); |
| 541 | } |
| 542 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 543 | virtual Return<void> onError(Status s, uint32_t errorCode) override { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 544 | LOG(DEBUG) << "onError --" |
| 545 | << " status = " << s |
| 546 | << ", errorCode = " << errorCode |
| 547 | << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 548 | if (std::shared_ptr<Listener> listener = base.lock()) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 549 | listener->onError(component, s == Status::OK ? |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 550 | errorCode : static_cast<c2_status_t>(s)); |
| 551 | } else { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 552 | LOG(DEBUG) << "onError -- listener died."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 553 | } |
| 554 | return Void(); |
| 555 | } |
| 556 | |
| 557 | virtual Return<void> onFramesRendered( |
| 558 | const hidl_vec<RenderedFrame>& renderedFrames) override { |
| 559 | std::shared_ptr<Listener> listener = base.lock(); |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 560 | if (!listener) { |
| 561 | LOG(DEBUG) << "onFramesRendered -- listener died."; |
| 562 | return Void(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 563 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 564 | for (const RenderedFrame& renderedFrame : renderedFrames) { |
| 565 | listener->onFrameRendered( |
| 566 | renderedFrame.bufferQueueId, |
| 567 | renderedFrame.slotId, |
| 568 | renderedFrame.timestampNs); |
| 569 | } |
| 570 | return Void(); |
| 571 | } |
| 572 | |
| 573 | virtual Return<void> onInputBuffersReleased( |
| 574 | const hidl_vec<InputBuffer>& inputBuffers) override { |
| 575 | std::shared_ptr<Listener> listener = base.lock(); |
| 576 | if (!listener) { |
| 577 | LOG(DEBUG) << "onInputBuffersReleased -- listener died."; |
| 578 | return Void(); |
| 579 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 580 | for (const InputBuffer& inputBuffer : inputBuffers) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 581 | LOG(VERBOSE) << "onInputBuffersReleased --" |
| 582 | " received death notification of" |
| 583 | " input buffer:" |
| 584 | " frameIndex = " << inputBuffer.frameIndex |
| 585 | << ", bufferIndex = " << inputBuffer.arrayIndex |
| 586 | << "."; |
Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 587 | listener->onInputBufferDone( |
| 588 | inputBuffer.frameIndex, inputBuffer.arrayIndex); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 589 | } |
| 590 | return Void(); |
| 591 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 592 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 593 | }; |
| 594 | |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 595 | // Codec2Client::Component::BufferPoolSender |
| 596 | struct Codec2Client::Component::BufferPoolSender : |
| 597 | hardware::media::c2::V1_1::utils::DefaultBufferPoolSender { |
| 598 | BufferPoolSender() |
| 599 | : hardware::media::c2::V1_1::utils::DefaultBufferPoolSender() { |
| 600 | } |
| 601 | }; |
| 602 | |
| 603 | // Codec2Client::Component::OutputBufferQueue |
| 604 | struct Codec2Client::Component::OutputBufferQueue : |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 605 | hardware::media::c2::OutputBufferQueue { |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 606 | OutputBufferQueue() |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 607 | : hardware::media::c2::OutputBufferQueue() { |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 608 | } |
| 609 | }; |
| 610 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 611 | // Codec2Client |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 612 | Codec2Client::Codec2Client(sp<Base> const& base, |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 613 | size_t serviceIndex) |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 614 | : Configurable{ |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 615 | [base]() -> sp<IConfigurable> { |
| 616 | Return<sp<IConfigurable>> transResult = |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 617 | base->getConfigurable(); |
| 618 | return transResult.isOk() ? |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 619 | static_cast<sp<IConfigurable>>(transResult) : |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 620 | nullptr; |
| 621 | }() |
| 622 | }, |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 623 | mBase1_0{base}, |
| 624 | mBase1_1{Base1_1::castFrom(base)}, |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 625 | mBase1_2{Base1_2::castFrom(base)}, |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 626 | mServiceIndex{serviceIndex} { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 627 | Return<sp<IClientManager>> transResult = base->getPoolClientManager(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 628 | if (!transResult.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 629 | LOG(ERROR) << "getPoolClientManager -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 630 | } else { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 631 | mHostPoolManager = static_cast<sp<IClientManager>>(transResult); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 635 | sp<Codec2Client::Base> const& Codec2Client::getBase() const { |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 636 | return mBase1_0; |
| 637 | } |
| 638 | |
| 639 | sp<Codec2Client::Base1_0> const& Codec2Client::getBase1_0() const { |
| 640 | return mBase1_0; |
| 641 | } |
| 642 | |
| 643 | sp<Codec2Client::Base1_1> const& Codec2Client::getBase1_1() const { |
| 644 | return mBase1_1; |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 647 | sp<Codec2Client::Base1_2> const& Codec2Client::getBase1_2() const { |
| 648 | return mBase1_2; |
| 649 | } |
| 650 | |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 651 | std::string const& Codec2Client::getServiceName() const { |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 652 | return GetServiceNames()[mServiceIndex]; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 655 | c2_status_t Codec2Client::createComponent( |
| 656 | const C2String& name, |
| 657 | const std::shared_ptr<Codec2Client::Listener>& listener, |
| 658 | std::shared_ptr<Codec2Client::Component>* const component) { |
| 659 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 660 | c2_status_t status; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 661 | sp<Component::HidlListener> hidlListener = new Component::HidlListener{}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 662 | hidlListener->base = listener; |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 663 | Return<void> transStatus; |
| 664 | if (mBase1_2) { |
| 665 | transStatus = mBase1_2->createComponent_1_2( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 666 | name, |
| 667 | hidlListener, |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 668 | ClientManager::getInstance(), |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 669 | [&status, component, hidlListener]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 670 | Status s, |
| 671 | const sp<IComponent>& c) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 672 | status = static_cast<c2_status_t>(s); |
| 673 | if (status != C2_OK) { |
| 674 | return; |
| 675 | } |
| 676 | *component = std::make_shared<Codec2Client::Component>(c); |
| 677 | hidlListener->component = *component; |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 678 | }); |
| 679 | } |
| 680 | else if (mBase1_1) { |
| 681 | transStatus = mBase1_1->createComponent_1_1( |
| 682 | name, |
| 683 | hidlListener, |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 684 | ClientManager::getInstance(), |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 685 | [&status, component, hidlListener]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 686 | Status s, |
| 687 | const sp<IComponent>& c) { |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 688 | status = static_cast<c2_status_t>(s); |
| 689 | if (status != C2_OK) { |
| 690 | return; |
| 691 | } |
| 692 | *component = std::make_shared<Codec2Client::Component>(c); |
| 693 | hidlListener->component = *component; |
| 694 | }); |
| 695 | } else if (mBase1_0) { // ver1_0 |
| 696 | transStatus = mBase1_0->createComponent( |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 697 | name, |
| 698 | hidlListener, |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 699 | ClientManager::getInstance(), |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 700 | [&status, component, hidlListener]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 701 | Status s, |
| 702 | const sp<hardware::media::c2::V1_0::IComponent>& c) { |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 703 | status = static_cast<c2_status_t>(s); |
| 704 | if (status != C2_OK) { |
| 705 | return; |
| 706 | } |
| 707 | *component = std::make_shared<Codec2Client::Component>(c); |
| 708 | hidlListener->component = *component; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 709 | }); |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 710 | } else { |
| 711 | status = C2_CORRUPTED; |
| 712 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 713 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 714 | LOG(ERROR) << "createComponent(" << name.c_str() |
| 715 | << ") -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 716 | return C2_TRANSACTION_FAILED; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 717 | } else if (status != C2_OK) { |
Pawin Vongmasa | 9aac304 | 2020-03-05 02:30:32 -0800 | [diff] [blame] | 718 | if (status == C2_NOT_FOUND) { |
| 719 | LOG(VERBOSE) << "createComponent(" << name.c_str() |
| 720 | << ") -- component not found."; |
| 721 | } else { |
| 722 | LOG(ERROR) << "createComponent(" << name.c_str() |
| 723 | << ") -- call failed: " << status << "."; |
| 724 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 725 | return status; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 726 | } else if (!*component) { |
| 727 | LOG(ERROR) << "createComponent(" << name.c_str() |
| 728 | << ") -- null component."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 729 | return C2_CORRUPTED; |
| 730 | } |
| 731 | |
| 732 | status = (*component)->setDeathListener(*component, listener); |
| 733 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 734 | LOG(ERROR) << "createComponent(" << name.c_str() |
| 735 | << ") -- failed to set up death listener: " |
| 736 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 737 | } |
| 738 | |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 739 | (*component)->mBufferPoolSender->setReceiver(mHostPoolManager); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 740 | return status; |
| 741 | } |
| 742 | |
| 743 | c2_status_t Codec2Client::createInterface( |
| 744 | const C2String& name, |
| 745 | std::shared_ptr<Codec2Client::Interface>* const interface) { |
| 746 | c2_status_t status; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 747 | Return<void> transStatus = mBase1_0->createInterface( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 748 | name, |
| 749 | [&status, interface]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 750 | Status s, |
| 751 | const sp<IComponentInterface>& i) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 752 | status = static_cast<c2_status_t>(s); |
| 753 | if (status != C2_OK) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 754 | return; |
| 755 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 756 | *interface = std::make_shared<Interface>(i); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 757 | }); |
| 758 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 759 | LOG(ERROR) << "createInterface(" << name.c_str() |
| 760 | << ") -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 761 | return C2_TRANSACTION_FAILED; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 762 | } else if (status != C2_OK) { |
Pawin Vongmasa | 9aac304 | 2020-03-05 02:30:32 -0800 | [diff] [blame] | 763 | if (status == C2_NOT_FOUND) { |
| 764 | LOG(VERBOSE) << "createInterface(" << name.c_str() |
| 765 | << ") -- component not found."; |
| 766 | } else { |
| 767 | LOG(ERROR) << "createInterface(" << name.c_str() |
| 768 | << ") -- call failed: " << status << "."; |
| 769 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 770 | return status; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 771 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 772 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 773 | return status; |
| 774 | } |
| 775 | |
| 776 | c2_status_t Codec2Client::createInputSurface( |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 777 | std::shared_ptr<InputSurface>* const inputSurface) { |
| 778 | c2_status_t status; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 779 | Return<void> transStatus = mBase1_0->createInputSurface( |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 780 | [&status, inputSurface]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 781 | Status s, |
| 782 | const sp<IInputSurface>& i) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 783 | status = static_cast<c2_status_t>(s); |
| 784 | if (status != C2_OK) { |
| 785 | return; |
| 786 | } |
| 787 | *inputSurface = std::make_shared<InputSurface>(i); |
| 788 | }); |
| 789 | if (!transStatus.isOk()) { |
| 790 | LOG(ERROR) << "createInputSurface -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 791 | return C2_TRANSACTION_FAILED; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 792 | } else if (status != C2_OK) { |
| 793 | LOG(DEBUG) << "createInputSurface -- call failed: " |
| 794 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 795 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 796 | return status; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 797 | } |
| 798 | |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 799 | std::vector<C2Component::Traits> const& Codec2Client::listComponents() const { |
| 800 | return Cache::List()[mServiceIndex].getTraits(); |
| 801 | } |
| 802 | |
| 803 | std::vector<C2Component::Traits> Codec2Client::_listComponents( |
| 804 | bool* success) const { |
| 805 | std::vector<C2Component::Traits> traits; |
| 806 | std::string const& serviceName = getServiceName(); |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 807 | Return<void> transStatus = mBase1_0->listComponents( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 808 | [&traits, &serviceName](Status s, |
| 809 | const hidl_vec<IComponentStore::ComponentTraits>& t) { |
| 810 | if (s != Status::OK) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 811 | LOG(DEBUG) << "_listComponents -- call failed: " |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 812 | << static_cast<c2_status_t>(s) << "."; |
| 813 | return; |
| 814 | } |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 815 | traits.resize(t.size()); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 816 | for (size_t i = 0; i < t.size(); ++i) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 817 | if (!objcpy(&traits[i], t[i])) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 818 | LOG(ERROR) << "_listComponents -- corrupted output."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 819 | return; |
| 820 | } |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 821 | traits[i].owner = serviceName; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 822 | } |
| 823 | }); |
| 824 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 825 | LOG(ERROR) << "_listComponents -- transaction failed."; |
| 826 | *success = false; |
| 827 | } else { |
| 828 | *success = true; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 829 | } |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 830 | return traits; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | c2_status_t Codec2Client::copyBuffer( |
| 834 | const std::shared_ptr<C2Buffer>& src, |
| 835 | const std::shared_ptr<C2Buffer>& dst) { |
| 836 | // TODO: Implement? |
| 837 | (void)src; |
| 838 | (void)dst; |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 839 | LOG(ERROR) << "copyBuffer not implemented"; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 840 | return C2_OMITTED; |
| 841 | } |
| 842 | |
| 843 | std::shared_ptr<C2ParamReflector> |
| 844 | Codec2Client::getParamReflector() { |
| 845 | // TODO: this is not meant to be exposed as C2ParamReflector on the client side; instead, it |
| 846 | // should reflect the HAL API. |
| 847 | struct SimpleParamReflector : public C2ParamReflector { |
| 848 | virtual std::unique_ptr<C2StructDescriptor> describe(C2Param::CoreIndex coreIndex) const { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 849 | hidl_vec<ParamIndex> indices(1); |
| 850 | indices[0] = static_cast<ParamIndex>(coreIndex.coreIndex()); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 851 | std::unique_ptr<C2StructDescriptor> descriptor; |
| 852 | Return<void> transStatus = mBase->getStructDescriptors( |
| 853 | indices, |
| 854 | [&descriptor]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 855 | Status s, |
| 856 | const hidl_vec<StructDescriptor>& sd) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 857 | c2_status_t status = static_cast<c2_status_t>(s); |
| 858 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 859 | LOG(DEBUG) << "SimpleParamReflector -- " |
| 860 | "getStructDescriptors() failed: " |
| 861 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 862 | descriptor.reset(); |
| 863 | return; |
| 864 | } |
| 865 | if (sd.size() != 1) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 866 | LOG(DEBUG) << "SimpleParamReflector -- " |
| 867 | "getStructDescriptors() " |
| 868 | "returned vector of size " |
| 869 | << sd.size() << ". " |
| 870 | "It should be 1."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 871 | descriptor.reset(); |
| 872 | return; |
| 873 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 874 | if (!objcpy(&descriptor, sd[0])) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 875 | LOG(DEBUG) << "SimpleParamReflector -- " |
| 876 | "getStructDescriptors() returned " |
| 877 | "corrupted data."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 878 | descriptor.reset(); |
| 879 | return; |
| 880 | } |
| 881 | }); |
Wonsik Kim | 492fecd | 2020-11-19 11:14:11 -0800 | [diff] [blame] | 882 | if (!transStatus.isOk()) { |
| 883 | LOG(DEBUG) << "SimpleParamReflector -- transaction failed: " |
| 884 | << transStatus.description(); |
| 885 | descriptor.reset(); |
| 886 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 887 | return descriptor; |
| 888 | } |
| 889 | |
| 890 | SimpleParamReflector(sp<Base> base) |
| 891 | : mBase(base) { } |
| 892 | |
| 893 | sp<Base> mBase; |
| 894 | }; |
| 895 | |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 896 | return std::make_shared<SimpleParamReflector>(mBase1_0); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 897 | }; |
| 898 | |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 899 | std::vector<std::string> const& Codec2Client::GetServiceNames() { |
| 900 | static std::vector<std::string> sServiceNames{[]() { |
| 901 | using ::android::hardware::media::c2::V1_0::IComponentStore; |
| 902 | using ::android::hidl::manager::V1_2::IServiceManager; |
| 903 | |
| 904 | while (true) { |
| 905 | sp<IServiceManager> serviceManager = IServiceManager::getService(); |
| 906 | CHECK(serviceManager) << "Hardware service manager is not running."; |
| 907 | |
| 908 | // There are three categories of services based on names. |
| 909 | std::vector<std::string> defaultNames; // Prefixed with "default" |
| 910 | std::vector<std::string> vendorNames; // Prefixed with "vendor" |
| 911 | std::vector<std::string> otherNames; // Others |
| 912 | Return<void> transResult; |
| 913 | transResult = serviceManager->listManifestByInterface( |
| 914 | IComponentStore::descriptor, |
| 915 | [&defaultNames, &vendorNames, &otherNames]( |
| 916 | hidl_vec<hidl_string> const& instanceNames) { |
| 917 | for (hidl_string const& instanceName : instanceNames) { |
| 918 | char const* name = instanceName.c_str(); |
| 919 | if (strncmp(name, "default", 7) == 0) { |
| 920 | defaultNames.emplace_back(name); |
| 921 | } else if (strncmp(name, "vendor", 6) == 0) { |
| 922 | vendorNames.emplace_back(name); |
| 923 | } else { |
| 924 | otherNames.emplace_back(name); |
| 925 | } |
| 926 | } |
| 927 | }); |
| 928 | if (transResult.isOk()) { |
| 929 | // Sort service names in each category. |
| 930 | std::sort(defaultNames.begin(), defaultNames.end()); |
| 931 | std::sort(vendorNames.begin(), vendorNames.end()); |
| 932 | std::sort(otherNames.begin(), otherNames.end()); |
| 933 | |
| 934 | // Concatenate the three lists in this order: default, vendor, |
| 935 | // other. |
| 936 | std::vector<std::string>& names = defaultNames; |
| 937 | names.reserve(names.size() + vendorNames.size() + otherNames.size()); |
| 938 | names.insert(names.end(), |
| 939 | std::make_move_iterator(vendorNames.begin()), |
| 940 | std::make_move_iterator(vendorNames.end())); |
| 941 | names.insert(names.end(), |
| 942 | std::make_move_iterator(otherNames.begin()), |
| 943 | std::make_move_iterator(otherNames.end())); |
| 944 | |
| 945 | // Summarize to logcat. |
| 946 | if (names.empty()) { |
| 947 | LOG(INFO) << "No Codec2 services declared in the manifest."; |
| 948 | } else { |
| 949 | std::stringstream stringOutput; |
| 950 | stringOutput << "Available Codec2 services:"; |
| 951 | for (std::string const& name : names) { |
| 952 | stringOutput << " \"" << name << "\""; |
| 953 | } |
| 954 | LOG(INFO) << stringOutput.str(); |
| 955 | } |
| 956 | |
| 957 | return names; |
| 958 | } |
| 959 | LOG(ERROR) << "Could not retrieve the list of service instances of " |
| 960 | << IComponentStore::descriptor |
| 961 | << ". Retrying..."; |
| 962 | } |
| 963 | }()}; |
| 964 | return sServiceNames; |
| 965 | } |
| 966 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 967 | std::shared_ptr<Codec2Client> Codec2Client::CreateFromService( |
Pawin Vongmasa | 83d2c55 | 2020-03-05 04:36:08 -0800 | [diff] [blame] | 968 | const char* name, |
| 969 | bool setAsPreferredCodec2ComponentStore) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 970 | size_t index = getServiceIndex(name); |
Pawin Vongmasa | 83d2c55 | 2020-03-05 04:36:08 -0800 | [diff] [blame] | 971 | if (index == GetServiceNames().size()) { |
| 972 | if (setAsPreferredCodec2ComponentStore) { |
| 973 | LOG(WARNING) << "CreateFromService(" << name |
| 974 | << ") -- preferred C2ComponentStore not set."; |
| 975 | } |
| 976 | return nullptr; |
| 977 | } |
| 978 | std::shared_ptr<Codec2Client> client = _CreateFromIndex(index); |
| 979 | if (setAsPreferredCodec2ComponentStore) { |
| 980 | SetPreferredCodec2ComponentStore( |
| 981 | std::make_shared<Client2Store>(client)); |
| 982 | LOG(INFO) << "CreateFromService(" << name |
| 983 | << ") -- service set as preferred C2ComponentStore."; |
| 984 | } |
| 985 | return client; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 986 | } |
| 987 | |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 988 | std::vector<std::shared_ptr<Codec2Client>> Codec2Client:: |
| 989 | CreateFromAllServices() { |
| 990 | std::vector<std::shared_ptr<Codec2Client>> clients( |
| 991 | GetServiceNames().size()); |
| 992 | for (size_t i = GetServiceNames().size(); i > 0; ) { |
| 993 | --i; |
| 994 | clients[i] = _CreateFromIndex(i); |
| 995 | } |
| 996 | return clients; |
| 997 | } |
| 998 | |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 999 | std::shared_ptr<Codec2Client> Codec2Client::_CreateFromIndex(size_t index) { |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 1000 | std::string const& name = GetServiceNames()[index]; |
Pawin Vongmasa | 9aac304 | 2020-03-05 02:30:32 -0800 | [diff] [blame] | 1001 | LOG(VERBOSE) << "Creating a Codec2 client to service \"" << name << "\""; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1002 | sp<Base> baseStore = Base::getService(name); |
| 1003 | CHECK(baseStore) << "Codec2 service \"" << name << "\"" |
| 1004 | " inaccessible for unknown reasons."; |
Pawin Vongmasa | 9aac304 | 2020-03-05 02:30:32 -0800 | [diff] [blame] | 1005 | LOG(VERBOSE) << "Client to Codec2 service \"" << name << "\" created"; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1006 | return std::make_shared<Codec2Client>(baseStore, index); |
| 1007 | } |
| 1008 | |
| 1009 | c2_status_t Codec2Client::ForAllServices( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1010 | const std::string &key, |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1011 | size_t numberOfAttempts, |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1012 | std::function<c2_status_t(const std::shared_ptr<Codec2Client>&)> |
| 1013 | predicate) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1014 | c2_status_t status = C2_NO_INIT; // no IComponentStores present |
| 1015 | |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1016 | // Cache the mapping key -> index of Codec2Client in Cache::List(). |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1017 | static std::mutex key2IndexMutex; |
| 1018 | static std::map<std::string, size_t> key2Index; |
| 1019 | |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1020 | // By default try all stores. However, try the last known client first. If |
| 1021 | // the last known client fails, retry once. We do this by pushing the last |
| 1022 | // known client in front of the list of all clients. |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1023 | std::deque<size_t> indices; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1024 | for (size_t index = Cache::List().size(); index > 0; ) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1025 | indices.push_front(--index); |
| 1026 | } |
| 1027 | |
| 1028 | bool wasMapped = false; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1029 | { |
| 1030 | std::scoped_lock lock{key2IndexMutex}; |
| 1031 | auto it = key2Index.find(key); |
| 1032 | if (it != key2Index.end()) { |
| 1033 | indices.push_front(it->second); |
| 1034 | wasMapped = true; |
| 1035 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1036 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1037 | |
| 1038 | for (size_t index : indices) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1039 | Cache& cache = Cache::List()[index]; |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1040 | for (size_t tries = numberOfAttempts; tries > 0; --tries) { |
| 1041 | std::shared_ptr<Codec2Client> client{cache.getClient()}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1042 | status = predicate(client); |
| 1043 | if (status == C2_OK) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1044 | std::scoped_lock lock{key2IndexMutex}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1045 | key2Index[key] = index; // update last known client index |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1046 | return C2_OK; |
Chih-Yu Huang | b8fe079 | 2020-12-07 17:14:55 +0900 | [diff] [blame] | 1047 | } else if (status == C2_NO_MEMORY) { |
| 1048 | return C2_NO_MEMORY; |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1049 | } else if (status == C2_TRANSACTION_FAILED) { |
| 1050 | LOG(WARNING) << "\"" << key << "\" failed for service \"" |
| 1051 | << client->getName() |
| 1052 | << "\" due to transaction failure. " |
| 1053 | << "(Service may have crashed.)" |
| 1054 | << (tries > 1 ? " Retrying..." : ""); |
| 1055 | cache.invalidate(); |
| 1056 | continue; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1057 | } |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1058 | if (wasMapped) { |
| 1059 | LOG(INFO) << "\"" << key << "\" became invalid in service \"" |
| 1060 | << client->getName() << "\". Retrying..."; |
| 1061 | wasMapped = false; |
| 1062 | } |
| 1063 | break; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1064 | } |
| 1065 | } |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1066 | return status; // return the last status from a valid client |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
Chih-Yu Huang | b8fe079 | 2020-12-07 17:14:55 +0900 | [diff] [blame] | 1069 | c2_status_t Codec2Client::CreateComponentByName( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1070 | const char* componentName, |
| 1071 | const std::shared_ptr<Listener>& listener, |
Chih-Yu Huang | b8fe079 | 2020-12-07 17:14:55 +0900 | [diff] [blame] | 1072 | std::shared_ptr<Component>* component, |
Pawin Vongmasa | 23c90c8 | 2019-09-03 00:44:42 -0700 | [diff] [blame] | 1073 | std::shared_ptr<Codec2Client>* owner, |
| 1074 | size_t numberOfAttempts) { |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1075 | std::string key{"create:"}; |
| 1076 | key.append(componentName); |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1077 | c2_status_t status = ForAllServices( |
| 1078 | key, |
| 1079 | numberOfAttempts, |
Chih-Yu Huang | b8fe079 | 2020-12-07 17:14:55 +0900 | [diff] [blame] | 1080 | [owner, component, componentName, &listener]( |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1081 | const std::shared_ptr<Codec2Client> &client) |
| 1082 | -> c2_status_t { |
| 1083 | c2_status_t status = client->createComponent(componentName, |
| 1084 | listener, |
Chih-Yu Huang | b8fe079 | 2020-12-07 17:14:55 +0900 | [diff] [blame] | 1085 | component); |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1086 | if (status == C2_OK) { |
| 1087 | if (owner) { |
| 1088 | *owner = client; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1089 | } |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1090 | } else if (status != C2_NOT_FOUND) { |
| 1091 | LOG(DEBUG) << "IComponentStore(" |
| 1092 | << client->getServiceName() |
| 1093 | << ")::createComponent(\"" << componentName |
| 1094 | << "\") returned status = " |
| 1095 | << status << "."; |
| 1096 | } |
| 1097 | return status; |
| 1098 | }); |
| 1099 | if (status != C2_OK) { |
| 1100 | LOG(DEBUG) << "Failed to create component \"" << componentName |
| 1101 | << "\" from all known services. " |
| 1102 | "Last returned status = " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1103 | } |
Chih-Yu Huang | b8fe079 | 2020-12-07 17:14:55 +0900 | [diff] [blame] | 1104 | return status; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | std::shared_ptr<Codec2Client::Interface> |
| 1108 | Codec2Client::CreateInterfaceByName( |
| 1109 | const char* interfaceName, |
Pawin Vongmasa | 23c90c8 | 2019-09-03 00:44:42 -0700 | [diff] [blame] | 1110 | std::shared_ptr<Codec2Client>* owner, |
| 1111 | size_t numberOfAttempts) { |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1112 | std::string key{"create:"}; |
| 1113 | key.append(interfaceName); |
| 1114 | std::shared_ptr<Interface> interface; |
| 1115 | c2_status_t status = ForAllServices( |
| 1116 | key, |
| 1117 | numberOfAttempts, |
| 1118 | [owner, &interface, interfaceName]( |
| 1119 | const std::shared_ptr<Codec2Client> &client) |
| 1120 | -> c2_status_t { |
| 1121 | c2_status_t status = client->createInterface(interfaceName, |
| 1122 | &interface); |
| 1123 | if (status == C2_OK) { |
| 1124 | if (owner) { |
| 1125 | *owner = client; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1126 | } |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1127 | } else if (status != C2_NOT_FOUND) { |
| 1128 | LOG(DEBUG) << "IComponentStore(" |
| 1129 | << client->getServiceName() |
| 1130 | << ")::createInterface(\"" << interfaceName |
| 1131 | << "\") returned status = " |
| 1132 | << status << "."; |
| 1133 | } |
| 1134 | return status; |
| 1135 | }); |
| 1136 | if (status != C2_OK) { |
| 1137 | LOG(DEBUG) << "Failed to create interface \"" << interfaceName |
| 1138 | << "\" from all known services. " |
| 1139 | "Last returned status = " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1140 | } |
Pawin Vongmasa | 1e7015a | 2019-10-09 02:15:50 -0700 | [diff] [blame] | 1141 | return interface; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1144 | std::vector<C2Component::Traits> const& Codec2Client::ListComponents() { |
| 1145 | static std::vector<C2Component::Traits> sList{[]() { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1146 | std::vector<C2Component::Traits> list; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1147 | for (Cache& cache : Cache::List()) { |
| 1148 | std::vector<C2Component::Traits> const& traits = cache.getTraits(); |
| 1149 | list.insert(list.end(), traits.begin(), traits.end()); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1150 | } |
| 1151 | return list; |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1152 | }()}; |
| 1153 | return sList; |
| 1154 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1155 | |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1156 | std::shared_ptr<Codec2Client::InputSurface> Codec2Client::CreateInputSurface( |
| 1157 | char const* serviceName) { |
Pawin Vongmasa | 1858832 | 2019-05-18 01:52:13 -0700 | [diff] [blame] | 1158 | int32_t inputSurfaceSetting = ::android::base::GetIntProperty( |
| 1159 | "debug.stagefright.c2inputsurface", int32_t(0)); |
| 1160 | if (inputSurfaceSetting <= 0) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1161 | return nullptr; |
| 1162 | } |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 1163 | size_t index = GetServiceNames().size(); |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1164 | if (serviceName) { |
| 1165 | index = getServiceIndex(serviceName); |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 1166 | if (index == GetServiceNames().size()) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1167 | LOG(DEBUG) << "CreateInputSurface -- invalid service name: \"" |
| 1168 | << serviceName << "\""; |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | std::shared_ptr<Codec2Client::InputSurface> inputSurface; |
Pawin Vongmasa | 270dd6a | 2019-04-06 04:41:15 -0700 | [diff] [blame] | 1173 | if (index != GetServiceNames().size()) { |
Pawin Vongmasa | 892c81d | 2019-03-12 00:56:50 -0700 | [diff] [blame] | 1174 | std::shared_ptr<Codec2Client> client = Cache::List()[index].getClient(); |
| 1175 | if (client->createInputSurface(&inputSurface) == C2_OK) { |
| 1176 | return inputSurface; |
| 1177 | } |
| 1178 | } |
| 1179 | LOG(INFO) << "CreateInputSurface -- attempting to create an input surface " |
| 1180 | "from all services..."; |
| 1181 | for (Cache& cache : Cache::List()) { |
| 1182 | std::shared_ptr<Codec2Client> client = cache.getClient(); |
| 1183 | if (client->createInputSurface(&inputSurface) == C2_OK) { |
| 1184 | LOG(INFO) << "CreateInputSurface -- input surface obtained from " |
| 1185 | "service \"" << client->getServiceName() << "\""; |
| 1186 | return inputSurface; |
| 1187 | } |
| 1188 | } |
| 1189 | LOG(WARNING) << "CreateInputSurface -- failed to create an input surface " |
| 1190 | "from all services"; |
| 1191 | return nullptr; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | // Codec2Client::Listener |
| 1195 | |
| 1196 | Codec2Client::Listener::~Listener() { |
| 1197 | } |
| 1198 | |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1199 | // Codec2Client::Interface |
| 1200 | Codec2Client::Interface::Interface(const sp<Base>& base) |
| 1201 | : Configurable{ |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1202 | [base]() -> sp<IConfigurable> { |
| 1203 | Return<sp<IConfigurable>> transResult = |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1204 | base->getConfigurable(); |
| 1205 | return transResult.isOk() ? |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1206 | static_cast<sp<IConfigurable>>(transResult) : |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1207 | nullptr; |
| 1208 | }() |
| 1209 | }, |
| 1210 | mBase{base} { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1211 | } |
| 1212 | |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1213 | // Codec2Client::Component |
| 1214 | Codec2Client::Component::Component(const sp<Base>& base) |
| 1215 | : Configurable{ |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1216 | [base]() -> sp<IConfigurable> { |
| 1217 | Return<sp<IComponentInterface>> transResult1 = |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1218 | base->getInterface(); |
| 1219 | if (!transResult1.isOk()) { |
| 1220 | return nullptr; |
| 1221 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1222 | Return<sp<IConfigurable>> transResult2 = |
| 1223 | static_cast<sp<IComponentInterface>>(transResult1)-> |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1224 | getConfigurable(); |
| 1225 | return transResult2.isOk() ? |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1226 | static_cast<sp<IConfigurable>>(transResult2) : |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1227 | nullptr; |
| 1228 | }() |
| 1229 | }, |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1230 | mBase1_0{base}, |
| 1231 | mBase1_1{Base1_1::castFrom(base)}, |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 1232 | mBase1_2{Base1_2::castFrom(base)}, |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1233 | mBufferPoolSender{std::make_unique<BufferPoolSender>()}, |
| 1234 | mOutputBufferQueue{std::make_unique<OutputBufferQueue>()} { |
| 1235 | } |
| 1236 | |
| 1237 | Codec2Client::Component::Component(const sp<Base1_1>& base) |
| 1238 | : Configurable{ |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1239 | [base]() -> sp<IConfigurable> { |
| 1240 | Return<sp<IComponentInterface>> transResult1 = |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1241 | base->getInterface(); |
| 1242 | if (!transResult1.isOk()) { |
| 1243 | return nullptr; |
| 1244 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1245 | Return<sp<IConfigurable>> transResult2 = |
| 1246 | static_cast<sp<IComponentInterface>>(transResult1)-> |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1247 | getConfigurable(); |
| 1248 | return transResult2.isOk() ? |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1249 | static_cast<sp<IConfigurable>>(transResult2) : |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1250 | nullptr; |
| 1251 | }() |
| 1252 | }, |
| 1253 | mBase1_0{base}, |
| 1254 | mBase1_1{base}, |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 1255 | mBase1_2{Base1_2::castFrom(base)}, |
| 1256 | mBufferPoolSender{std::make_unique<BufferPoolSender>()}, |
| 1257 | mOutputBufferQueue{std::make_unique<OutputBufferQueue>()} { |
| 1258 | } |
| 1259 | |
| 1260 | Codec2Client::Component::Component(const sp<Base1_2>& base) |
| 1261 | : Configurable{ |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1262 | [base]() -> sp<IConfigurable> { |
| 1263 | Return<sp<IComponentInterface>> transResult1 = |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 1264 | base->getInterface(); |
| 1265 | if (!transResult1.isOk()) { |
| 1266 | return nullptr; |
| 1267 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1268 | Return<sp<IConfigurable>> transResult2 = |
| 1269 | static_cast<sp<IComponentInterface>>(transResult1)-> |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 1270 | getConfigurable(); |
| 1271 | return transResult2.isOk() ? |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1272 | static_cast<sp<IConfigurable>>(transResult2) : |
Sungtak Lee | 8577dab | 2021-03-12 02:25:50 -0800 | [diff] [blame] | 1273 | nullptr; |
| 1274 | }() |
| 1275 | }, |
| 1276 | mBase1_0{base}, |
| 1277 | mBase1_1{base}, |
| 1278 | mBase1_2{base}, |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1279 | mBufferPoolSender{std::make_unique<BufferPoolSender>()}, |
| 1280 | mOutputBufferQueue{std::make_unique<OutputBufferQueue>()} { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | Codec2Client::Component::~Component() { |
| 1284 | } |
| 1285 | |
| 1286 | c2_status_t Codec2Client::Component::createBlockPool( |
| 1287 | C2Allocator::id_t id, |
| 1288 | C2BlockPool::local_id_t* blockPoolId, |
| 1289 | std::shared_ptr<Codec2Client::Configurable>* configurable) { |
| 1290 | c2_status_t status; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1291 | Return<void> transStatus = mBase1_0->createBlockPool( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1292 | static_cast<uint32_t>(id), |
| 1293 | [&status, blockPoolId, configurable]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1294 | Status s, |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1295 | uint64_t pId, |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1296 | const sp<IConfigurable>& c) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1297 | status = static_cast<c2_status_t>(s); |
| 1298 | configurable->reset(); |
| 1299 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1300 | LOG(DEBUG) << "createBlockPool -- call failed: " |
| 1301 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1302 | return; |
| 1303 | } |
| 1304 | *blockPoolId = static_cast<C2BlockPool::local_id_t>(pId); |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1305 | *configurable = std::make_shared<Configurable>(c); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1306 | }); |
| 1307 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1308 | LOG(ERROR) << "createBlockPool -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1309 | return C2_TRANSACTION_FAILED; |
| 1310 | } |
| 1311 | return status; |
| 1312 | } |
| 1313 | |
| 1314 | c2_status_t Codec2Client::Component::destroyBlockPool( |
| 1315 | C2BlockPool::local_id_t localId) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1316 | Return<Status> transResult = mBase1_0->destroyBlockPool( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1317 | static_cast<uint64_t>(localId)); |
| 1318 | if (!transResult.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1319 | LOG(ERROR) << "destroyBlockPool -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1320 | return C2_TRANSACTION_FAILED; |
| 1321 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1322 | return static_cast<c2_status_t>(static_cast<Status>(transResult)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1323 | } |
| 1324 | |
Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 1325 | void Codec2Client::Component::handleOnWorkDone( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1326 | const std::list<std::unique_ptr<C2Work>> &workItems) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1327 | // Output bufferqueue-based blocks' lifetime management |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1328 | mOutputBufferQueue->holdBufferQueueBlocks(workItems); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | c2_status_t Codec2Client::Component::queue( |
| 1332 | std::list<std::unique_ptr<C2Work>>* const items) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1333 | WorkBundle workBundle; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1334 | if (!objcpy(&workBundle, *items, mBufferPoolSender.get())) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1335 | LOG(ERROR) << "queue -- bad input."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1336 | return C2_TRANSACTION_FAILED; |
| 1337 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1338 | Return<Status> transStatus = mBase1_0->queue(workBundle); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1339 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1340 | LOG(ERROR) << "queue -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1341 | return C2_TRANSACTION_FAILED; |
| 1342 | } |
| 1343 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1344 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1345 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1346 | LOG(DEBUG) << "queue -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1347 | } |
| 1348 | return status; |
| 1349 | } |
| 1350 | |
| 1351 | c2_status_t Codec2Client::Component::flush( |
| 1352 | C2Component::flush_mode_t mode, |
| 1353 | std::list<std::unique_ptr<C2Work>>* const flushedWork) { |
| 1354 | (void)mode; // Flush mode isn't supported in HIDL yet. |
| 1355 | c2_status_t status; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1356 | Return<void> transStatus = mBase1_0->flush( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1357 | [&status, flushedWork]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1358 | Status s, const WorkBundle& wb) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1359 | status = static_cast<c2_status_t>(s); |
| 1360 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1361 | LOG(DEBUG) << "flush -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1362 | return; |
| 1363 | } |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1364 | if (!objcpy(flushedWork, wb)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1365 | status = C2_CORRUPTED; |
| 1366 | } else { |
| 1367 | status = C2_OK; |
| 1368 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1369 | }); |
| 1370 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1371 | LOG(ERROR) << "flush -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1372 | return C2_TRANSACTION_FAILED; |
| 1373 | } |
| 1374 | |
| 1375 | // Indices of flushed work items. |
| 1376 | std::vector<uint64_t> flushedIndices; |
| 1377 | for (const std::unique_ptr<C2Work> &work : *flushedWork) { |
| 1378 | if (work) { |
| 1379 | if (work->worklets.empty() |
| 1380 | || !work->worklets.back() |
| 1381 | || (work->worklets.back()->output.flags & |
| 1382 | C2FrameData::FLAG_INCOMPLETE) == 0) { |
| 1383 | // input is complete |
| 1384 | flushedIndices.emplace_back( |
| 1385 | work->input.ordinal.frameIndex.peeku()); |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1390 | // Output bufferqueue-based blocks' lifetime management |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1391 | mOutputBufferQueue->holdBufferQueueBlocks(*flushedWork); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1392 | |
| 1393 | return status; |
| 1394 | } |
| 1395 | |
| 1396 | c2_status_t Codec2Client::Component::drain(C2Component::drain_mode_t mode) { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1397 | Return<Status> transStatus = mBase1_0->drain( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1398 | mode == C2Component::DRAIN_COMPONENT_WITH_EOS); |
| 1399 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1400 | LOG(ERROR) << "drain -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1401 | return C2_TRANSACTION_FAILED; |
| 1402 | } |
| 1403 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1404 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1405 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1406 | LOG(DEBUG) << "drain -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1407 | } |
| 1408 | return status; |
| 1409 | } |
| 1410 | |
| 1411 | c2_status_t Codec2Client::Component::start() { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1412 | Return<Status> transStatus = mBase1_0->start(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1413 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1414 | LOG(ERROR) << "start -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1415 | return C2_TRANSACTION_FAILED; |
| 1416 | } |
| 1417 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1418 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1419 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1420 | LOG(DEBUG) << "start -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1421 | } |
| 1422 | return status; |
| 1423 | } |
| 1424 | |
| 1425 | c2_status_t Codec2Client::Component::stop() { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1426 | Return<Status> transStatus = mBase1_0->stop(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1427 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1428 | LOG(ERROR) << "stop -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1429 | return C2_TRANSACTION_FAILED; |
| 1430 | } |
| 1431 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1432 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1433 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1434 | LOG(DEBUG) << "stop -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1435 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1436 | return status; |
| 1437 | } |
| 1438 | |
| 1439 | c2_status_t Codec2Client::Component::reset() { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1440 | Return<Status> transStatus = mBase1_0->reset(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1441 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1442 | LOG(ERROR) << "reset -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1443 | return C2_TRANSACTION_FAILED; |
| 1444 | } |
| 1445 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1446 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1447 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1448 | LOG(DEBUG) << "reset -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1449 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1450 | return status; |
| 1451 | } |
| 1452 | |
| 1453 | c2_status_t Codec2Client::Component::release() { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1454 | Return<Status> transStatus = mBase1_0->release(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1455 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1456 | LOG(ERROR) << "release -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1457 | return C2_TRANSACTION_FAILED; |
| 1458 | } |
| 1459 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1460 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1461 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1462 | LOG(DEBUG) << "release -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1463 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1464 | return status; |
| 1465 | } |
| 1466 | |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1467 | c2_status_t Codec2Client::Component::configureVideoTunnel( |
| 1468 | uint32_t avSyncHwId, |
| 1469 | native_handle_t** sidebandHandle) { |
| 1470 | *sidebandHandle = nullptr; |
| 1471 | if (!mBase1_1) { |
| 1472 | return C2_OMITTED; |
| 1473 | } |
| 1474 | c2_status_t status{}; |
| 1475 | Return<void> transStatus = mBase1_1->configureVideoTunnel(avSyncHwId, |
| 1476 | [&status, sidebandHandle]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1477 | Status s, hardware::hidl_handle const& h) { |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1478 | status = static_cast<c2_status_t>(s); |
| 1479 | if (h.getNativeHandle()) { |
| 1480 | *sidebandHandle = native_handle_clone(h.getNativeHandle()); |
| 1481 | } |
| 1482 | }); |
| 1483 | if (!transStatus.isOk()) { |
| 1484 | LOG(ERROR) << "configureVideoTunnel -- transaction failed."; |
| 1485 | return C2_TRANSACTION_FAILED; |
| 1486 | } |
| 1487 | return status; |
| 1488 | } |
| 1489 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1490 | c2_status_t Codec2Client::Component::setOutputSurface( |
| 1491 | C2BlockPool::local_id_t blockPoolId, |
| 1492 | const sp<IGraphicBufferProducer>& surface, |
Sungtak Lee | db14cba | 2021-04-10 00:50:23 -0700 | [diff] [blame] | 1493 | uint32_t generation, |
| 1494 | int maxDequeueCount) { |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 1495 | uint64_t bqId = 0; |
| 1496 | sp<IGraphicBufferProducer> nullIgbp; |
| 1497 | sp<HGraphicBufferProducer2> nullHgbp; |
Pawin Vongmasa | 3866c7e | 2019-01-31 05:21:29 -0800 | [diff] [blame] | 1498 | |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 1499 | sp<HGraphicBufferProducer2> igbp = surface ? |
| 1500 | surface->getHalInterface<HGraphicBufferProducer2>() : nullHgbp; |
| 1501 | if (surface && !igbp) { |
Pawin Vongmasa | ef939bf | 2019-03-03 04:44:59 -0800 | [diff] [blame] | 1502 | igbp = new B2HGraphicBufferProducer2(surface); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1503 | } |
| 1504 | |
Sungtak Lee | fb57902 | 2022-05-10 06:36:15 +0000 | [diff] [blame] | 1505 | std::scoped_lock lock(mOutputMutex); |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 1506 | std::shared_ptr<SurfaceSyncObj> syncObj; |
| 1507 | |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 1508 | if (!surface) { |
Sungtak Lee | db14cba | 2021-04-10 00:50:23 -0700 | [diff] [blame] | 1509 | mOutputBufferQueue->configure(nullIgbp, generation, 0, maxDequeueCount, nullptr); |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 1510 | } else if (surface->getUniqueId(&bqId) != OK) { |
| 1511 | LOG(ERROR) << "setOutputSurface -- " |
| 1512 | "cannot obtain bufferqueue id."; |
| 1513 | bqId = 0; |
Sungtak Lee | db14cba | 2021-04-10 00:50:23 -0700 | [diff] [blame] | 1514 | mOutputBufferQueue->configure(nullIgbp, generation, 0, maxDequeueCount, nullptr); |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 1515 | } else { |
Sungtak Lee | db14cba | 2021-04-10 00:50:23 -0700 | [diff] [blame] | 1516 | mOutputBufferQueue->configure(surface, generation, bqId, maxDequeueCount, mBase1_2 ? |
| 1517 | &syncObj : nullptr); |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 1518 | } |
Lajos Molnar | 78aa7c9 | 2021-02-18 21:39:01 -0800 | [diff] [blame] | 1519 | |
| 1520 | // set consumer bits |
| 1521 | // TODO: should this get incorporated into setOutputSurface method so that consumer bits |
| 1522 | // can be set atomically? |
| 1523 | uint64_t consumerUsage = kDefaultConsumerUsage; |
| 1524 | { |
| 1525 | if (surface) { |
| 1526 | int usage = 0; |
| 1527 | status_t err = surface->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &usage); |
| 1528 | if (err != NO_ERROR) { |
| 1529 | ALOGD("setOutputSurface -- failed to get consumer usage bits (%d/%s). ignoring", |
| 1530 | err, asString(err)); |
| 1531 | } else { |
| 1532 | // Note: we are adding the default usage because components must support |
| 1533 | // producing output frames that can be displayed an all output surfaces. |
| 1534 | |
| 1535 | // TODO: do not set usage for tunneled scenario. It is unclear if consumer usage |
| 1536 | // is meaningful in a tunneled scenario; on one hand output buffers exist, but |
| 1537 | // they do not exist inside of C2 scope. Any buffer usage shall be communicated |
| 1538 | // through the sideband channel. |
| 1539 | |
| 1540 | // do an unsigned conversion as bit-31 may be 1 |
| 1541 | consumerUsage = (uint32_t)usage | kDefaultConsumerUsage; |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | C2StreamUsageTuning::output outputUsage{ |
| 1546 | 0u, C2AndroidMemoryUsage::FromGrallocUsage(consumerUsage).expected}; |
| 1547 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 1548 | c2_status_t err = config({&outputUsage}, C2_MAY_BLOCK, &failures); |
| 1549 | if (err != C2_OK) { |
| 1550 | ALOGD("setOutputSurface -- failed to set consumer usage (%d/%s)", |
| 1551 | err, asString(err)); |
| 1552 | } |
| 1553 | } |
| 1554 | ALOGD("setOutputSurface -- generation=%u consumer usage=%#llx%s", |
| 1555 | generation, (long long)consumerUsage, syncObj ? " sync" : ""); |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 1556 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1557 | Return<Status> transStatus = syncObj ? |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 1558 | mBase1_2->setOutputSurfaceWithSyncObj( |
| 1559 | static_cast<uint64_t>(blockPoolId), |
| 1560 | bqId == 0 ? nullHgbp : igbp, *syncObj) : |
| 1561 | mBase1_0->setOutputSurface( |
| 1562 | static_cast<uint64_t>(blockPoolId), |
| 1563 | bqId == 0 ? nullHgbp : igbp); |
Lajos Molnar | 78aa7c9 | 2021-02-18 21:39:01 -0800 | [diff] [blame] | 1564 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1565 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1566 | LOG(ERROR) << "setOutputSurface -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1567 | return C2_TRANSACTION_FAILED; |
| 1568 | } |
| 1569 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1570 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1571 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1572 | LOG(DEBUG) << "setOutputSurface -- call failed: " << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1573 | } |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 1574 | ALOGD("Surface configure completed"); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1575 | return status; |
| 1576 | } |
| 1577 | |
| 1578 | status_t Codec2Client::Component::queueToOutputSurface( |
| 1579 | const C2ConstGraphicBlock& block, |
| 1580 | const QueueBufferInput& input, |
| 1581 | QueueBufferOutput* output) { |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1582 | return mOutputBufferQueue->outputBuffer(block, input, output); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1583 | } |
| 1584 | |
Sungtak Lee | a714f11 | 2021-03-16 05:40:03 -0700 | [diff] [blame] | 1585 | void Codec2Client::Component::setOutputSurfaceMaxDequeueCount( |
| 1586 | int maxDequeueCount) { |
| 1587 | mOutputBufferQueue->updateMaxDequeueBufferCount(maxDequeueCount); |
| 1588 | } |
| 1589 | |
Sungtak Lee | c7da7a0 | 2022-05-05 08:45:33 +0000 | [diff] [blame] | 1590 | void Codec2Client::Component::stopUsingOutputSurface( |
| 1591 | C2BlockPool::local_id_t blockPoolId) { |
Sungtak Lee | fb57902 | 2022-05-10 06:36:15 +0000 | [diff] [blame] | 1592 | std::scoped_lock lock(mOutputMutex); |
Sungtak Lee | c7da7a0 | 2022-05-05 08:45:33 +0000 | [diff] [blame] | 1593 | mOutputBufferQueue->stop(); |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1594 | Return<Status> transStatus = mBase1_0->setOutputSurface( |
Sungtak Lee | c7da7a0 | 2022-05-05 08:45:33 +0000 | [diff] [blame] | 1595 | static_cast<uint64_t>(blockPoolId), nullptr); |
| 1596 | if (!transStatus.isOk()) { |
| 1597 | LOG(ERROR) << "setOutputSurface(stopUsingOutputSurface) -- transaction failed."; |
| 1598 | } else { |
| 1599 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1600 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Sungtak Lee | c7da7a0 | 2022-05-05 08:45:33 +0000 | [diff] [blame] | 1601 | if (status != C2_OK) { |
| 1602 | LOG(DEBUG) << "setOutputSurface(stopUsingOutputSurface) -- call failed: " |
| 1603 | << status << "."; |
| 1604 | } |
| 1605 | } |
| 1606 | } |
| 1607 | |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1608 | c2_status_t Codec2Client::Component::connectToInputSurface( |
| 1609 | const std::shared_ptr<InputSurface>& inputSurface, |
| 1610 | std::shared_ptr<InputSurfaceConnection>* connection) { |
| 1611 | c2_status_t status; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1612 | Return<void> transStatus = mBase1_0->connectToInputSurface( |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1613 | inputSurface->mBase, |
| 1614 | [&status, connection]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1615 | Status s, const sp<IInputSurfaceConnection>& c) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1616 | status = static_cast<c2_status_t>(s); |
| 1617 | if (status != C2_OK) { |
| 1618 | LOG(DEBUG) << "connectToInputSurface -- call failed: " |
| 1619 | << status << "."; |
| 1620 | return; |
| 1621 | } |
| 1622 | *connection = std::make_shared<InputSurfaceConnection>(c); |
| 1623 | }); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1624 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1625 | LOG(ERROR) << "connectToInputSurface -- transaction failed"; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1626 | return C2_TRANSACTION_FAILED; |
| 1627 | } |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1628 | return status; |
| 1629 | } |
| 1630 | |
| 1631 | c2_status_t Codec2Client::Component::connectToOmxInputSurface( |
Pawin Vongmasa | ef939bf | 2019-03-03 04:44:59 -0800 | [diff] [blame] | 1632 | const sp<HGraphicBufferProducer1>& producer, |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1633 | const sp<HGraphicBufferSource>& source, |
| 1634 | std::shared_ptr<InputSurfaceConnection>* connection) { |
| 1635 | c2_status_t status; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1636 | Return<void> transStatus = mBase1_0->connectToOmxInputSurface( |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1637 | producer, source, |
| 1638 | [&status, connection]( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1639 | Status s, const sp<IInputSurfaceConnection>& c) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1640 | status = static_cast<c2_status_t>(s); |
| 1641 | if (status != C2_OK) { |
| 1642 | LOG(DEBUG) << "connectToOmxInputSurface -- call failed: " |
| 1643 | << status << "."; |
| 1644 | return; |
| 1645 | } |
| 1646 | *connection = std::make_shared<InputSurfaceConnection>(c); |
| 1647 | }); |
| 1648 | if (!transStatus.isOk()) { |
| 1649 | LOG(ERROR) << "connectToOmxInputSurface -- transaction failed."; |
| 1650 | return C2_TRANSACTION_FAILED; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1651 | } |
| 1652 | return status; |
| 1653 | } |
| 1654 | |
| 1655 | c2_status_t Codec2Client::Component::disconnectFromInputSurface() { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1656 | Return<Status> transStatus = mBase1_0->disconnectFromInputSurface(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1657 | if (!transStatus.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1658 | LOG(ERROR) << "disconnectToInputSurface -- transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1659 | return C2_TRANSACTION_FAILED; |
| 1660 | } |
| 1661 | c2_status_t status = |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1662 | static_cast<c2_status_t>(static_cast<Status>(transStatus)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1663 | if (status != C2_OK) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1664 | LOG(DEBUG) << "disconnectFromInputSurface -- call failed: " |
| 1665 | << status << "."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1666 | } |
| 1667 | return status; |
| 1668 | } |
| 1669 | |
| 1670 | c2_status_t Codec2Client::Component::setDeathListener( |
| 1671 | const std::shared_ptr<Component>& component, |
| 1672 | const std::shared_ptr<Listener>& listener) { |
| 1673 | |
| 1674 | struct HidlDeathRecipient : public hardware::hidl_death_recipient { |
| 1675 | std::weak_ptr<Component> component; |
| 1676 | std::weak_ptr<Listener> base; |
| 1677 | |
| 1678 | virtual void serviceDied( |
| 1679 | uint64_t /* cookie */, |
| 1680 | const wp<::android::hidl::base::V1_0::IBase>& /* who */ |
| 1681 | ) override { |
| 1682 | if (std::shared_ptr<Codec2Client::Listener> listener = base.lock()) { |
| 1683 | listener->onDeath(component); |
| 1684 | } else { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1685 | LOG(DEBUG) << "onDeath -- listener died."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | }; |
| 1689 | |
| 1690 | sp<HidlDeathRecipient> deathRecipient = new HidlDeathRecipient(); |
| 1691 | deathRecipient->base = listener; |
| 1692 | deathRecipient->component = component; |
| 1693 | |
| 1694 | component->mDeathRecipient = deathRecipient; |
Pawin Vongmasa | bf69de9 | 2019-10-29 06:21:27 -0700 | [diff] [blame] | 1695 | Return<bool> transResult = component->mBase1_0->linkToDeath( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1696 | component->mDeathRecipient, 0); |
| 1697 | if (!transResult.isOk()) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1698 | LOG(ERROR) << "setDeathListener -- linkToDeath() transaction failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1699 | return C2_TRANSACTION_FAILED; |
| 1700 | } |
| 1701 | if (!static_cast<bool>(transResult)) { |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1702 | LOG(DEBUG) << "setDeathListener -- linkToDeath() call failed."; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1703 | return C2_CORRUPTED; |
| 1704 | } |
| 1705 | return C2_OK; |
| 1706 | } |
| 1707 | |
| 1708 | // Codec2Client::InputSurface |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1709 | Codec2Client::InputSurface::InputSurface(const sp<IInputSurface>& base) |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1710 | : Configurable{ |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1711 | [base]() -> sp<IConfigurable> { |
| 1712 | Return<sp<IConfigurable>> transResult = |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1713 | base->getConfigurable(); |
| 1714 | return transResult.isOk() ? |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1715 | static_cast<sp<IConfigurable>>(transResult) : |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1716 | nullptr; |
| 1717 | }() |
| 1718 | }, |
| 1719 | mBase{base}, |
| 1720 | mGraphicBufferProducer{new |
Pawin Vongmasa | ef939bf | 2019-03-03 04:44:59 -0800 | [diff] [blame] | 1721 | H2BGraphicBufferProducer2([base]() -> sp<HGraphicBufferProducer2> { |
| 1722 | Return<sp<HGraphicBufferProducer2>> transResult = |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1723 | base->getGraphicBufferProducer(); |
| 1724 | return transResult.isOk() ? |
Pawin Vongmasa | ef939bf | 2019-03-03 04:44:59 -0800 | [diff] [blame] | 1725 | static_cast<sp<HGraphicBufferProducer2>>(transResult) : |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1726 | nullptr; |
| 1727 | }())} { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1730 | sp<IGraphicBufferProducer> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1731 | Codec2Client::InputSurface::getGraphicBufferProducer() const { |
| 1732 | return mGraphicBufferProducer; |
| 1733 | } |
| 1734 | |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1735 | sp<IInputSurface> Codec2Client::InputSurface::getHalInterface() const { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1736 | return mBase; |
| 1737 | } |
| 1738 | |
| 1739 | // Codec2Client::InputSurfaceConnection |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1740 | Codec2Client::InputSurfaceConnection::InputSurfaceConnection( |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1741 | const sp<IInputSurfaceConnection>& base) |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1742 | : Configurable{ |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1743 | [base]() -> sp<IConfigurable> { |
| 1744 | Return<sp<IConfigurable>> transResult = |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1745 | base->getConfigurable(); |
| 1746 | return transResult.isOk() ? |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1747 | static_cast<sp<IConfigurable>>(transResult) : |
Pawin Vongmasa | 1c75a23 | 2019-01-09 04:41:52 -0800 | [diff] [blame] | 1748 | nullptr; |
| 1749 | }() |
| 1750 | }, |
| 1751 | mBase{base} { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | c2_status_t Codec2Client::InputSurfaceConnection::disconnect() { |
Kensuke Miyagi | 4380417 | 2022-12-10 01:55:17 +0000 | [diff] [blame] | 1755 | Return<Status> transResult = mBase->disconnect(); |
| 1756 | return static_cast<c2_status_t>(static_cast<Status>(transResult)); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | } // namespace android |