blob: 0acf7d726c9a1d66f66a0da7a516c81c3b96e9cf [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08002 * Copyright 2018 The Android Open Source Project
Pawin Vongmasa36653902018-11-15 00:10:25 -08003 *
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 Vongmasa1c75a232019-01-09 04:41:52 -080019#include <android-base/logging.h>
Pawin Vongmasa36653902018-11-15 00:10:25 -080020
21#include <codec2/hidl/client.h>
Pawin Vongmasabf69de92019-10-29 06:21:27 -070022#include <C2Debug.h>
23#include <C2BufferPriv.h>
Lajos Molnar78aa7c92021-02-18 21:39:01 -080024#include <C2Config.h> // for C2StreamUsageTuning
Pawin Vongmasabf69de92019-10-29 06:21:27 -070025#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 Vongmasabf69de92019-10-29 06:21:27 -070037#include <codec2/hidl/1.0/types.h>
Pawin Vongmasabf69de92019-10-29 06:21:27 -070038#include <codec2/hidl/1.1/types.h>
Sungtak Lee8577dab2021-03-12 02:25:50 -080039#include <codec2/hidl/1.2/types.h>
Sungtak Leea714f112021-03-16 05:40:03 -070040#include <codec2/hidl/output.h>
Pawin Vongmasabf69de92019-10-29 06:21:27 -070041
42#include <cutils/native_handle.h>
43#include <gui/bufferqueue/2.0/B2HGraphicBufferProducer.h>
44#include <gui/bufferqueue/2.0/H2BGraphicBufferProducer.h>
Lajos Molnar78aa7c92021-02-18 21:39:01 -080045#include <hardware/gralloc.h> // for GRALLOC_USAGE_*
Pawin Vongmasabf69de92019-10-29 06:21:27 -070046#include <hidl/HidlSupport.h>
Lajos Molnar78aa7c92021-02-18 21:39:01 -080047#include <system/window.h> // for NATIVE_WINDOW_QUERY_*
48#include <media/stagefright/foundation/ADebug.h> // for asString(status_t)
Pawin Vongmasa36653902018-11-15 00:10:25 -080049
Sungtak Leea714f112021-03-16 05:40:03 -070050
Pawin Vongmasa36653902018-11-15 00:10:25 -080051#include <deque>
Pawin Vongmasa892c81d2019-03-12 00:56:50 -070052#include <iterator>
Pawin Vongmasa36653902018-11-15 00:10:25 -080053#include <limits>
54#include <map>
Pawin Vongmasa892c81d2019-03-12 00:56:50 -070055#include <mutex>
56#include <sstream>
57#include <thread>
Pawin Vongmasa36653902018-11-15 00:10:25 -080058#include <type_traits>
59#include <vector>
60
Pawin Vongmasa36653902018-11-15 00:10:25 -080061namespace android {
62
63using ::android::hardware::hidl_vec;
64using ::android::hardware::hidl_string;
65using ::android::hardware::Return;
66using ::android::hardware::Void;
Pawin Vongmasa36653902018-11-15 00:10:25 -080067
Pawin Vongmasabf69de92019-10-29 06:21:27 -070068using namespace ::android::hardware::media::c2::V1_1;
69using namespace ::android::hardware::media::c2::V1_1::utils;
Sungtak Leed3318082018-09-07 15:52:43 -070070using namespace ::android::hardware::media::bufferpool::V2_0;
71using namespace ::android::hardware::media::bufferpool::V2_0::implementation;
Pawin Vongmasa36653902018-11-15 00:10:25 -080072
Pawin Vongmasaef939bf2019-03-03 04:44:59 -080073using HGraphicBufferProducer1 = ::android::hardware::graphics::bufferqueue::
74 V1_0::IGraphicBufferProducer;
75using HGraphicBufferProducer2 = ::android::hardware::graphics::bufferqueue::
76 V2_0::IGraphicBufferProducer;
77using B2HGraphicBufferProducer2 = ::android::hardware::graphics::bufferqueue::
78 V2_0::utils::B2HGraphicBufferProducer;
79using H2BGraphicBufferProducer2 = ::android::hardware::graphics::bufferqueue::
80 V2_0::utils::H2BGraphicBufferProducer;
Sungtak Leea714f112021-03-16 05:40:03 -070081using ::android::hardware::media::c2::V1_2::SurfaceSyncObj;
Pawin Vongmasaef939bf2019-03-03 04:44:59 -080082
Pawin Vongmasa36653902018-11-15 00:10:25 -080083namespace /* unnamed */ {
84
85// c2_status_t value that corresponds to hwbinder transaction failure.
86constexpr c2_status_t C2_TRANSACTION_FAILED = C2_CORRUPTED;
87
Lajos Molnar78aa7c92021-02-18 21:39:01 -080088// By default prepare buffer to be displayed on any of the common surfaces
89constexpr uint64_t kDefaultConsumerUsage =
90 (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER);
91
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070092// Searches for a name in GetServiceNames() and returns the index found. If the
Pawin Vongmasa892c81d2019-03-12 00:56:50 -070093// name is not found, the returned index will be equal to
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070094// GetServiceNames().size().
Pawin Vongmasa892c81d2019-03-12 00:56:50 -070095size_t getServiceIndex(char const* name) {
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070096 std::vector<std::string> const& names = Codec2Client::GetServiceNames();
Pawin Vongmasa892c81d2019-03-12 00:56:50 -070097 size_t i = 0;
98 for (; i < names.size(); ++i) {
99 if (name == names[i]) {
100 break;
101 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800102 }
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700103 return i;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800104}
105
Pawin Vongmasa83d2c552020-03-05 04:36:08 -0800106class Client2Store : public C2ComponentStore {
107 std::shared_ptr<Codec2Client> mClient;
108
109public:
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 &params,
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 Vongmasa892c81d2019-03-12 00:56:50 -0700169} // 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.
175class 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 Vongmasa270dd6a2019-04-06 04:41:15 -0700184 // The index of the service. This is based on GetServiceNames().
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700185 size_t mIndex;
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700186 // Called by s() exactly once to initialize the cache. The index must be a
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700187 // valid index into the vector returned by GetServiceNames(). Calling
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700188 // init(index) will associate the cache to the service with name
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700189 // GetServiceNames()[index].
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700190 void init(size_t index) {
191 mIndex = index;
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700192 }
193
194public:
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 Vongmasa892c81d2019-03-12 00:56:50 -0700201 std::scoped_lock lock{mClientMutex};
202 if (!mClient) {
203 mClient = Codec2Client::_CreateFromIndex(mIndex);
204 }
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -0700205 CHECK(mClient) << "Failed to create Codec2Client to service \""
206 << GetServiceNames()[mIndex] << "\". (Index = "
207 << mIndex << ").";
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700208 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 Vongmasa892c81d2019-03-12 00:56:50 -0700216 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 Vongmasa892c81d2019-03-12 00:56:50 -0700223 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 Vongmasa21617db2020-04-24 06:16:42 -0700232 invalidate();
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700233 using namespace std::chrono_literals;
234 static constexpr auto kServiceRetryPeriod = 5s;
235 LOG(INFO) << "Failed to retrieve component traits from service "
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700236 "\"" << GetServiceNames()[mIndex] << "\". "
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700237 "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 Vongmasa270dd6a2019-04-06 04:41:15 -0700247 size_t numServices = GetServiceNames().size();
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700248 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 Vongmasa36653902018-11-15 00:10:25 -0800257
258// Codec2ConfigurableClient
259
260const C2String& Codec2ConfigurableClient::getName() const {
261 return mName;
262}
263
Pawin Vongmasa36653902018-11-15 00:10:25 -0800264Codec2ConfigurableClient::Codec2ConfigurableClient(
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800265 const sp<IConfigurable>& base)
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 Vongmasa36653902018-11-15 00:10:25 -0800275}
276
277c2_status_t Codec2ConfigurableClient::query(
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 {
282 hidl_vec<ParamIndex> indices(
283 stackParams.size() + heapParamIndices.size());
284 size_t numIndices = 0;
285 for (C2Param* const& stackParam : stackParams) {
286 if (!stackParam) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800287 LOG(WARNING) << "query -- null stack param encountered.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800288 continue;
289 }
290 indices[numIndices++] = static_cast<ParamIndex>(stackParam->index());
291 }
292 size_t numStackIndices = numIndices;
293 for (const C2Param::Index& index : heapParamIndices) {
294 indices[numIndices++] =
295 static_cast<ParamIndex>(static_cast<uint32_t>(index));
296 }
297 indices.resize(numIndices);
298 if (heapParams) {
299 heapParams->reserve(heapParams->size() + numIndices);
300 }
301 c2_status_t status;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800302 Return<void> transStatus = mBase->query(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800303 indices,
304 mayBlock == C2_MAY_BLOCK,
305 [&status, &numStackIndices, &stackParams, heapParams](
306 Status s, const Params& p) {
307 status = static_cast<c2_status_t>(s);
308 if (status != C2_OK && status != C2_BAD_INDEX) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800309 LOG(DEBUG) << "query -- call failed: "
310 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800311 return;
312 }
313 std::vector<C2Param*> paramPointers;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800314 if (!parseParamsBlob(&paramPointers, p)) {
315 LOG(ERROR) << "query -- error while parsing params.";
316 status = C2_CORRUPTED;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800317 return;
318 }
319 size_t i = 0;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800320 for (auto it = paramPointers.begin();
321 it != paramPointers.end(); ) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800322 C2Param* paramPointer = *it;
323 if (numStackIndices > 0) {
324 --numStackIndices;
325 if (!paramPointer) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800326 LOG(WARNING) << "query -- null stack param.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800327 ++it;
328 continue;
329 }
330 for (; i < stackParams.size() && !stackParams[i]; ) {
331 ++i;
332 }
333 if (i >= stackParams.size()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800334 LOG(ERROR) << "query -- unexpected error.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800335 status = C2_CORRUPTED;
336 return;
337 }
338 if (stackParams[i]->index() != paramPointer->index()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800339 LOG(WARNING) << "query -- param skipped: "
340 "index = "
341 << stackParams[i]->index() << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800342 stackParams[i++]->invalidate();
343 continue;
344 }
345 if (!stackParams[i++]->updateFrom(*paramPointer)) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800346 LOG(WARNING) << "query -- param update failed: "
347 "index = "
348 << paramPointer->index() << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800349 }
350 } else {
351 if (!paramPointer) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800352 LOG(WARNING) << "query -- null heap param.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800353 ++it;
354 continue;
355 }
356 if (!heapParams) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800357 LOG(WARNING) << "query -- "
358 "unexpected extra stack param.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800359 } else {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800360 heapParams->emplace_back(
361 C2Param::Copy(*paramPointer));
Pawin Vongmasa36653902018-11-15 00:10:25 -0800362 }
363 }
364 ++it;
365 }
366 });
367 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800368 LOG(ERROR) << "query -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800369 return C2_TRANSACTION_FAILED;
370 }
371 return status;
372}
373
374c2_status_t Codec2ConfigurableClient::config(
375 const std::vector<C2Param*> &params,
376 c2_blocking_t mayBlock,
377 std::vector<std::unique_ptr<C2SettingResult>>* const failures) {
378 Params hidlParams;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800379 if (!createParamsBlob(&hidlParams, params)) {
380 LOG(ERROR) << "config -- bad input.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800381 return C2_TRANSACTION_FAILED;
382 }
383 c2_status_t status;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800384 Return<void> transStatus = mBase->config(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800385 hidlParams,
386 mayBlock == C2_MAY_BLOCK,
387 [&status, &params, failures](
388 Status s,
389 const hidl_vec<SettingResult> f,
390 const Params& o) {
391 status = static_cast<c2_status_t>(s);
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800392 if (status != C2_OK && status != C2_BAD_INDEX) {
393 LOG(DEBUG) << "config -- call failed: "
394 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800395 }
396 size_t i = failures->size();
397 failures->resize(i + f.size());
398 for (const SettingResult& sf : f) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800399 if (!objcpy(&(*failures)[i++], sf)) {
400 LOG(ERROR) << "config -- "
401 << "invalid SettingResult returned.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800402 return;
403 }
404 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800405 if (!updateParamsFromBlob(params, o)) {
406 LOG(ERROR) << "config -- "
407 << "failed to parse returned params.";
408 status = C2_CORRUPTED;
409 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800410 });
411 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800412 LOG(ERROR) << "config -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800413 return C2_TRANSACTION_FAILED;
414 }
415 return status;
416}
417
418c2_status_t Codec2ConfigurableClient::querySupportedParams(
419 std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const {
420 // TODO: Cache and query properly!
421 c2_status_t status;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800422 Return<void> transStatus = mBase->querySupportedParams(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800423 std::numeric_limits<uint32_t>::min(),
424 std::numeric_limits<uint32_t>::max(),
425 [&status, params](
426 Status s,
427 const hidl_vec<ParamDescriptor>& p) {
428 status = static_cast<c2_status_t>(s);
429 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800430 LOG(DEBUG) << "querySupportedParams -- call failed: "
431 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800432 return;
433 }
434 size_t i = params->size();
435 params->resize(i + p.size());
436 for (const ParamDescriptor& sp : p) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800437 if (!objcpy(&(*params)[i++], sp)) {
438 LOG(ERROR) << "querySupportedParams -- "
439 << "invalid returned ParamDescriptor.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800440 return;
441 }
442 }
443 });
444 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800445 LOG(ERROR) << "querySupportedParams -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800446 return C2_TRANSACTION_FAILED;
447 }
448 return status;
449}
450
451c2_status_t Codec2ConfigurableClient::querySupportedValues(
452 std::vector<C2FieldSupportedValuesQuery>& fields,
453 c2_blocking_t mayBlock) const {
454 hidl_vec<FieldSupportedValuesQuery> inFields(fields.size());
455 for (size_t i = 0; i < fields.size(); ++i) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800456 if (!objcpy(&inFields[i], fields[i])) {
457 LOG(ERROR) << "querySupportedValues -- bad input";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800458 return C2_TRANSACTION_FAILED;
459 }
460 }
461
462 c2_status_t status;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800463 Return<void> transStatus = mBase->querySupportedValues(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800464 inFields,
465 mayBlock == C2_MAY_BLOCK,
466 [&status, &inFields, &fields](
467 Status s,
468 const hidl_vec<FieldSupportedValuesQueryResult>& r) {
469 status = static_cast<c2_status_t>(s);
470 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800471 LOG(DEBUG) << "querySupportedValues -- call failed: "
472 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800473 return;
474 }
475 if (r.size() != fields.size()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800476 LOG(ERROR) << "querySupportedValues -- "
477 "input and output lists "
478 "have different sizes.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800479 status = C2_CORRUPTED;
480 return;
481 }
482 for (size_t i = 0; i < fields.size(); ++i) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800483 if (!objcpy(&fields[i], inFields[i], r[i])) {
484 LOG(ERROR) << "querySupportedValues -- "
485 "invalid returned value.";
486 status = C2_CORRUPTED;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800487 return;
488 }
489 }
490 });
491 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800492 LOG(ERROR) << "querySupportedValues -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800493 return C2_TRANSACTION_FAILED;
494 }
495 return status;
496}
497
498// Codec2Client::Component::HidlListener
499struct Codec2Client::Component::HidlListener : public IComponentListener {
500 std::weak_ptr<Component> component;
501 std::weak_ptr<Listener> base;
502
503 virtual Return<void> onWorkDone(const WorkBundle& workBundle) override {
504 std::list<std::unique_ptr<C2Work>> workItems;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800505 if (!objcpy(&workItems, workBundle)) {
506 LOG(DEBUG) << "onWorkDone -- received corrupted WorkBundle.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800507 return Void();
508 }
509 // release input buffers potentially held by the component from queue
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800510 std::shared_ptr<Codec2Client::Component> strongComponent =
511 component.lock();
Pawin Vongmasa36653902018-11-15 00:10:25 -0800512 if (strongComponent) {
Wonsik Kimab34ed62019-01-31 15:28:46 -0800513 strongComponent->handleOnWorkDone(workItems);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800514 }
515 if (std::shared_ptr<Codec2Client::Listener> listener = base.lock()) {
Wonsik Kimab34ed62019-01-31 15:28:46 -0800516 listener->onWorkDone(component, workItems);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800517 } else {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800518 LOG(DEBUG) << "onWorkDone -- listener died.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800519 }
520 return Void();
521 }
522
523 virtual Return<void> onTripped(
524 const hidl_vec<SettingResult>& settingResults) override {
525 std::vector<std::shared_ptr<C2SettingResult>> c2SettingResults(
526 settingResults.size());
Pawin Vongmasa36653902018-11-15 00:10:25 -0800527 for (size_t i = 0; i < settingResults.size(); ++i) {
528 std::unique_ptr<C2SettingResult> c2SettingResult;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800529 if (!objcpy(&c2SettingResult, settingResults[i])) {
530 LOG(DEBUG) << "onTripped -- received corrupted SettingResult.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800531 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 Vongmasa1c75a232019-01-09 04:41:52 -0800538 LOG(DEBUG) << "onTripped -- listener died.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800539 }
540 return Void();
541 }
542
543 virtual Return<void> onError(Status s, uint32_t errorCode) override {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800544 LOG(DEBUG) << "onError --"
545 << " status = " << s
546 << ", errorCode = " << errorCode
547 << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800548 if (std::shared_ptr<Listener> listener = base.lock()) {
549 listener->onError(component, s == Status::OK ?
550 errorCode : static_cast<c2_status_t>(s));
551 } else {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800552 LOG(DEBUG) << "onError -- listener died.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800553 }
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 Vongmasa1c75a232019-01-09 04:41:52 -0800560 if (!listener) {
561 LOG(DEBUG) << "onFramesRendered -- listener died.";
562 return Void();
Pawin Vongmasa36653902018-11-15 00:10:25 -0800563 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800564 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 Vongmasa1c75a232019-01-09 04:41:52 -0800580 for (const InputBuffer& inputBuffer : inputBuffers) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800581 LOG(VERBOSE) << "onInputBuffersReleased --"
582 " received death notification of"
583 " input buffer:"
584 " frameIndex = " << inputBuffer.frameIndex
585 << ", bufferIndex = " << inputBuffer.arrayIndex
586 << ".";
Wonsik Kimab34ed62019-01-31 15:28:46 -0800587 listener->onInputBufferDone(
588 inputBuffer.frameIndex, inputBuffer.arrayIndex);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800589 }
590 return Void();
591 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800592
Pawin Vongmasa36653902018-11-15 00:10:25 -0800593};
594
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700595// Codec2Client::Component::BufferPoolSender
596struct 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
604struct Codec2Client::Component::OutputBufferQueue :
Sungtak Leea714f112021-03-16 05:40:03 -0700605 hardware::media::c2::OutputBufferQueue {
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700606 OutputBufferQueue()
Sungtak Leea714f112021-03-16 05:40:03 -0700607 : hardware::media::c2::OutputBufferQueue() {
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700608 }
609};
610
Pawin Vongmasa36653902018-11-15 00:10:25 -0800611// Codec2Client
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700612Codec2Client::Codec2Client(sp<Base> const& base,
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700613 size_t serviceIndex)
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800614 : Configurable{
615 [base]() -> sp<IConfigurable> {
616 Return<sp<IConfigurable>> transResult =
617 base->getConfigurable();
618 return transResult.isOk() ?
619 static_cast<sp<IConfigurable>>(transResult) :
620 nullptr;
621 }()
622 },
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700623 mBase1_0{base},
624 mBase1_1{Base1_1::castFrom(base)},
Sungtak Lee8577dab2021-03-12 02:25:50 -0800625 mBase1_2{Base1_2::castFrom(base)},
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700626 mServiceIndex{serviceIndex} {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800627 Return<sp<IClientManager>> transResult = base->getPoolClientManager();
628 if (!transResult.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800629 LOG(ERROR) << "getPoolClientManager -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800630 } else {
631 mHostPoolManager = static_cast<sp<IClientManager>>(transResult);
632 }
633}
634
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700635sp<Codec2Client::Base> const& Codec2Client::getBase() const {
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700636 return mBase1_0;
637}
638
639sp<Codec2Client::Base1_0> const& Codec2Client::getBase1_0() const {
640 return mBase1_0;
641}
642
643sp<Codec2Client::Base1_1> const& Codec2Client::getBase1_1() const {
644 return mBase1_1;
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700645}
646
Sungtak Lee8577dab2021-03-12 02:25:50 -0800647sp<Codec2Client::Base1_2> const& Codec2Client::getBase1_2() const {
648 return mBase1_2;
649}
650
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700651std::string const& Codec2Client::getServiceName() const {
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700652 return GetServiceNames()[mServiceIndex];
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700653}
654
Pawin Vongmasa36653902018-11-15 00:10:25 -0800655c2_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 Vongmasa36653902018-11-15 00:10:25 -0800660 c2_status_t status;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800661 sp<Component::HidlListener> hidlListener = new Component::HidlListener{};
Pawin Vongmasa36653902018-11-15 00:10:25 -0800662 hidlListener->base = listener;
Sungtak Lee8577dab2021-03-12 02:25:50 -0800663 Return<void> transStatus;
664 if (mBase1_2) {
665 transStatus = mBase1_2->createComponent_1_2(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800666 name,
667 hidlListener,
668 ClientManager::getInstance(),
669 [&status, component, hidlListener](
670 Status s,
671 const sp<IComponent>& c) {
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 Lee8577dab2021-03-12 02:25:50 -0800678 });
679 }
680 else if (mBase1_1) {
681 transStatus = mBase1_1->createComponent_1_1(
682 name,
683 hidlListener,
684 ClientManager::getInstance(),
685 [&status, component, hidlListener](
686 Status s,
687 const sp<IComponent>& c) {
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 Vongmasabf69de92019-10-29 06:21:27 -0700697 name,
698 hidlListener,
699 ClientManager::getInstance(),
700 [&status, component, hidlListener](
701 Status s,
702 const sp<hardware::media::c2::V1_0::IComponent>& c) {
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 Vongmasa36653902018-11-15 00:10:25 -0800709 });
Sungtak Lee8577dab2021-03-12 02:25:50 -0800710 } else {
711 status = C2_CORRUPTED;
712 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800713 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800714 LOG(ERROR) << "createComponent(" << name.c_str()
715 << ") -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800716 return C2_TRANSACTION_FAILED;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800717 } else if (status != C2_OK) {
Pawin Vongmasa9aac3042020-03-05 02:30:32 -0800718 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 Vongmasa36653902018-11-15 00:10:25 -0800725 return status;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800726 } else if (!*component) {
727 LOG(ERROR) << "createComponent(" << name.c_str()
728 << ") -- null component.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800729 return C2_CORRUPTED;
730 }
731
732 status = (*component)->setDeathListener(*component, listener);
733 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800734 LOG(ERROR) << "createComponent(" << name.c_str()
735 << ") -- failed to set up death listener: "
736 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800737 }
738
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700739 (*component)->mBufferPoolSender->setReceiver(mHostPoolManager);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800740 return status;
741}
742
743c2_status_t Codec2Client::createInterface(
744 const C2String& name,
745 std::shared_ptr<Codec2Client::Interface>* const interface) {
746 c2_status_t status;
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700747 Return<void> transStatus = mBase1_0->createInterface(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800748 name,
749 [&status, interface](
750 Status s,
751 const sp<IComponentInterface>& i) {
752 status = static_cast<c2_status_t>(s);
753 if (status != C2_OK) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800754 return;
755 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800756 *interface = std::make_shared<Interface>(i);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800757 });
758 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800759 LOG(ERROR) << "createInterface(" << name.c_str()
760 << ") -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800761 return C2_TRANSACTION_FAILED;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800762 } else if (status != C2_OK) {
Pawin Vongmasa9aac3042020-03-05 02:30:32 -0800763 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 Vongmasa1c75a232019-01-09 04:41:52 -0800770 return status;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800771 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800772
Pawin Vongmasa36653902018-11-15 00:10:25 -0800773 return status;
774}
775
776c2_status_t Codec2Client::createInputSurface(
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800777 std::shared_ptr<InputSurface>* const inputSurface) {
778 c2_status_t status;
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700779 Return<void> transStatus = mBase1_0->createInputSurface(
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800780 [&status, inputSurface](
781 Status s,
782 const sp<IInputSurface>& i) {
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 Vongmasa36653902018-11-15 00:10:25 -0800791 return C2_TRANSACTION_FAILED;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800792 } else if (status != C2_OK) {
793 LOG(DEBUG) << "createInputSurface -- call failed: "
794 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800795 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800796 return status;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800797}
798
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700799std::vector<C2Component::Traits> const& Codec2Client::listComponents() const {
800 return Cache::List()[mServiceIndex].getTraits();
801}
802
803std::vector<C2Component::Traits> Codec2Client::_listComponents(
804 bool* success) const {
805 std::vector<C2Component::Traits> traits;
806 std::string const& serviceName = getServiceName();
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700807 Return<void> transStatus = mBase1_0->listComponents(
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700808 [&traits, &serviceName](Status s,
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800809 const hidl_vec<IComponentStore::ComponentTraits>& t) {
810 if (s != Status::OK) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700811 LOG(DEBUG) << "_listComponents -- call failed: "
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800812 << static_cast<c2_status_t>(s) << ".";
813 return;
814 }
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700815 traits.resize(t.size());
Pawin Vongmasa36653902018-11-15 00:10:25 -0800816 for (size_t i = 0; i < t.size(); ++i) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700817 if (!objcpy(&traits[i], t[i])) {
818 LOG(ERROR) << "_listComponents -- corrupted output.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800819 return;
820 }
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700821 traits[i].owner = serviceName;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800822 }
823 });
824 if (!transStatus.isOk()) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700825 LOG(ERROR) << "_listComponents -- transaction failed.";
826 *success = false;
827 } else {
828 *success = true;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800829 }
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700830 return traits;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800831}
832
833c2_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 Vongmasa1c75a232019-01-09 04:41:52 -0800839 LOG(ERROR) << "copyBuffer not implemented";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800840 return C2_OMITTED;
841}
842
843std::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 {
849 hidl_vec<ParamIndex> indices(1);
850 indices[0] = static_cast<ParamIndex>(coreIndex.coreIndex());
851 std::unique_ptr<C2StructDescriptor> descriptor;
852 Return<void> transStatus = mBase->getStructDescriptors(
853 indices,
854 [&descriptor](
855 Status s,
856 const hidl_vec<StructDescriptor>& sd) {
857 c2_status_t status = static_cast<c2_status_t>(s);
858 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800859 LOG(DEBUG) << "SimpleParamReflector -- "
860 "getStructDescriptors() failed: "
861 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800862 descriptor.reset();
863 return;
864 }
865 if (sd.size() != 1) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800866 LOG(DEBUG) << "SimpleParamReflector -- "
867 "getStructDescriptors() "
868 "returned vector of size "
869 << sd.size() << ". "
870 "It should be 1.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800871 descriptor.reset();
872 return;
873 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800874 if (!objcpy(&descriptor, sd[0])) {
875 LOG(DEBUG) << "SimpleParamReflector -- "
876 "getStructDescriptors() returned "
877 "corrupted data.";
Pawin Vongmasa36653902018-11-15 00:10:25 -0800878 descriptor.reset();
879 return;
880 }
881 });
Wonsik Kim492fecd2020-11-19 11:14:11 -0800882 if (!transStatus.isOk()) {
883 LOG(DEBUG) << "SimpleParamReflector -- transaction failed: "
884 << transStatus.description();
885 descriptor.reset();
886 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800887 return descriptor;
888 }
889
890 SimpleParamReflector(sp<Base> base)
891 : mBase(base) { }
892
893 sp<Base> mBase;
894 };
895
Pawin Vongmasabf69de92019-10-29 06:21:27 -0700896 return std::make_shared<SimpleParamReflector>(mBase1_0);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800897};
898
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700899std::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 Vongmasa36653902018-11-15 00:10:25 -0800967std::shared_ptr<Codec2Client> Codec2Client::CreateFromService(
Pawin Vongmasa83d2c552020-03-05 04:36:08 -0800968 const char* name,
969 bool setAsPreferredCodec2ComponentStore) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -0700970 size_t index = getServiceIndex(name);
Pawin Vongmasa83d2c552020-03-05 04:36:08 -0800971 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 Vongmasa36653902018-11-15 00:10:25 -0800986}
987
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -0700988std::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 Vongmasa892c81d2019-03-12 00:56:50 -0700999std::shared_ptr<Codec2Client> Codec2Client::_CreateFromIndex(size_t index) {
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -07001000 std::string const& name = GetServiceNames()[index];
Pawin Vongmasa9aac3042020-03-05 02:30:32 -08001001 LOG(VERBOSE) << "Creating a Codec2 client to service \"" << name << "\"";
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001002 sp<Base> baseStore = Base::getService(name);
1003 CHECK(baseStore) << "Codec2 service \"" << name << "\""
1004 " inaccessible for unknown reasons.";
Pawin Vongmasa9aac3042020-03-05 02:30:32 -08001005 LOG(VERBOSE) << "Client to Codec2 service \"" << name << "\" created";
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001006 return std::make_shared<Codec2Client>(baseStore, index);
1007}
1008
1009c2_status_t Codec2Client::ForAllServices(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001010 const std::string &key,
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001011 size_t numberOfAttempts,
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001012 std::function<c2_status_t(const std::shared_ptr<Codec2Client>&)>
1013 predicate) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001014 c2_status_t status = C2_NO_INIT; // no IComponentStores present
1015
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001016 // Cache the mapping key -> index of Codec2Client in Cache::List().
Pawin Vongmasa36653902018-11-15 00:10:25 -08001017 static std::mutex key2IndexMutex;
1018 static std::map<std::string, size_t> key2Index;
1019
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001020 // 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 Vongmasa36653902018-11-15 00:10:25 -08001023 std::deque<size_t> indices;
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001024 for (size_t index = Cache::List().size(); index > 0; ) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001025 indices.push_front(--index);
1026 }
1027
1028 bool wasMapped = false;
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001029 {
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 Vongmasa36653902018-11-15 00:10:25 -08001036 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001037
1038 for (size_t index : indices) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001039 Cache& cache = Cache::List()[index];
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001040 for (size_t tries = numberOfAttempts; tries > 0; --tries) {
1041 std::shared_ptr<Codec2Client> client{cache.getClient()};
Pawin Vongmasa36653902018-11-15 00:10:25 -08001042 status = predicate(client);
1043 if (status == C2_OK) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001044 std::scoped_lock lock{key2IndexMutex};
Pawin Vongmasa36653902018-11-15 00:10:25 -08001045 key2Index[key] = index; // update last known client index
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001046 return C2_OK;
Chih-Yu Huangb8fe0792020-12-07 17:14:55 +09001047 } else if (status == C2_NO_MEMORY) {
1048 return C2_NO_MEMORY;
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001049 } 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 Vongmasa36653902018-11-15 00:10:25 -08001057 }
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001058 if (wasMapped) {
1059 LOG(INFO) << "\"" << key << "\" became invalid in service \""
1060 << client->getName() << "\". Retrying...";
1061 wasMapped = false;
1062 }
1063 break;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001064 }
1065 }
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001066 return status; // return the last status from a valid client
Pawin Vongmasa36653902018-11-15 00:10:25 -08001067}
1068
Chih-Yu Huangb8fe0792020-12-07 17:14:55 +09001069c2_status_t Codec2Client::CreateComponentByName(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001070 const char* componentName,
1071 const std::shared_ptr<Listener>& listener,
Chih-Yu Huangb8fe0792020-12-07 17:14:55 +09001072 std::shared_ptr<Component>* component,
Pawin Vongmasa23c90c82019-09-03 00:44:42 -07001073 std::shared_ptr<Codec2Client>* owner,
1074 size_t numberOfAttempts) {
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001075 std::string key{"create:"};
1076 key.append(componentName);
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001077 c2_status_t status = ForAllServices(
1078 key,
1079 numberOfAttempts,
Chih-Yu Huangb8fe0792020-12-07 17:14:55 +09001080 [owner, component, componentName, &listener](
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001081 const std::shared_ptr<Codec2Client> &client)
1082 -> c2_status_t {
1083 c2_status_t status = client->createComponent(componentName,
1084 listener,
Chih-Yu Huangb8fe0792020-12-07 17:14:55 +09001085 component);
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001086 if (status == C2_OK) {
1087 if (owner) {
1088 *owner = client;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001089 }
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001090 } 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 Vongmasa36653902018-11-15 00:10:25 -08001103 }
Chih-Yu Huangb8fe0792020-12-07 17:14:55 +09001104 return status;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001105}
1106
1107std::shared_ptr<Codec2Client::Interface>
1108 Codec2Client::CreateInterfaceByName(
1109 const char* interfaceName,
Pawin Vongmasa23c90c82019-09-03 00:44:42 -07001110 std::shared_ptr<Codec2Client>* owner,
1111 size_t numberOfAttempts) {
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001112 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 Vongmasa36653902018-11-15 00:10:25 -08001126 }
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001127 } 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 Vongmasa36653902018-11-15 00:10:25 -08001140 }
Pawin Vongmasa1e7015a2019-10-09 02:15:50 -07001141 return interface;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001142}
1143
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001144std::vector<C2Component::Traits> const& Codec2Client::ListComponents() {
1145 static std::vector<C2Component::Traits> sList{[]() {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001146 std::vector<C2Component::Traits> list;
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001147 for (Cache& cache : Cache::List()) {
1148 std::vector<C2Component::Traits> const& traits = cache.getTraits();
1149 list.insert(list.end(), traits.begin(), traits.end());
Pawin Vongmasa36653902018-11-15 00:10:25 -08001150 }
1151 return list;
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001152 }()};
1153 return sList;
1154}
Pawin Vongmasa36653902018-11-15 00:10:25 -08001155
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001156std::shared_ptr<Codec2Client::InputSurface> Codec2Client::CreateInputSurface(
1157 char const* serviceName) {
Pawin Vongmasa18588322019-05-18 01:52:13 -07001158 int32_t inputSurfaceSetting = ::android::base::GetIntProperty(
1159 "debug.stagefright.c2inputsurface", int32_t(0));
1160 if (inputSurfaceSetting <= 0) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001161 return nullptr;
1162 }
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -07001163 size_t index = GetServiceNames().size();
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001164 if (serviceName) {
1165 index = getServiceIndex(serviceName);
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -07001166 if (index == GetServiceNames().size()) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001167 LOG(DEBUG) << "CreateInputSurface -- invalid service name: \""
1168 << serviceName << "\"";
1169 }
1170 }
1171
1172 std::shared_ptr<Codec2Client::InputSurface> inputSurface;
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -07001173 if (index != GetServiceNames().size()) {
Pawin Vongmasa892c81d2019-03-12 00:56:50 -07001174 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 Vongmasa36653902018-11-15 00:10:25 -08001192}
1193
1194// Codec2Client::Listener
1195
1196Codec2Client::Listener::~Listener() {
1197}
1198
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001199// Codec2Client::Interface
1200Codec2Client::Interface::Interface(const sp<Base>& base)
1201 : Configurable{
1202 [base]() -> sp<IConfigurable> {
1203 Return<sp<IConfigurable>> transResult =
1204 base->getConfigurable();
1205 return transResult.isOk() ?
1206 static_cast<sp<IConfigurable>>(transResult) :
1207 nullptr;
1208 }()
1209 },
1210 mBase{base} {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001211}
1212
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001213// Codec2Client::Component
1214Codec2Client::Component::Component(const sp<Base>& base)
1215 : Configurable{
1216 [base]() -> sp<IConfigurable> {
1217 Return<sp<IComponentInterface>> transResult1 =
1218 base->getInterface();
1219 if (!transResult1.isOk()) {
1220 return nullptr;
1221 }
1222 Return<sp<IConfigurable>> transResult2 =
1223 static_cast<sp<IComponentInterface>>(transResult1)->
1224 getConfigurable();
1225 return transResult2.isOk() ?
1226 static_cast<sp<IConfigurable>>(transResult2) :
1227 nullptr;
1228 }()
1229 },
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001230 mBase1_0{base},
1231 mBase1_1{Base1_1::castFrom(base)},
Sungtak Lee8577dab2021-03-12 02:25:50 -08001232 mBase1_2{Base1_2::castFrom(base)},
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001233 mBufferPoolSender{std::make_unique<BufferPoolSender>()},
1234 mOutputBufferQueue{std::make_unique<OutputBufferQueue>()} {
1235}
1236
1237Codec2Client::Component::Component(const sp<Base1_1>& base)
1238 : Configurable{
1239 [base]() -> sp<IConfigurable> {
1240 Return<sp<IComponentInterface>> transResult1 =
1241 base->getInterface();
1242 if (!transResult1.isOk()) {
1243 return nullptr;
1244 }
1245 Return<sp<IConfigurable>> transResult2 =
1246 static_cast<sp<IComponentInterface>>(transResult1)->
1247 getConfigurable();
1248 return transResult2.isOk() ?
1249 static_cast<sp<IConfigurable>>(transResult2) :
1250 nullptr;
1251 }()
1252 },
1253 mBase1_0{base},
1254 mBase1_1{base},
Sungtak Lee8577dab2021-03-12 02:25:50 -08001255 mBase1_2{Base1_2::castFrom(base)},
1256 mBufferPoolSender{std::make_unique<BufferPoolSender>()},
1257 mOutputBufferQueue{std::make_unique<OutputBufferQueue>()} {
1258}
1259
1260Codec2Client::Component::Component(const sp<Base1_2>& base)
1261 : Configurable{
1262 [base]() -> sp<IConfigurable> {
1263 Return<sp<IComponentInterface>> transResult1 =
1264 base->getInterface();
1265 if (!transResult1.isOk()) {
1266 return nullptr;
1267 }
1268 Return<sp<IConfigurable>> transResult2 =
1269 static_cast<sp<IComponentInterface>>(transResult1)->
1270 getConfigurable();
1271 return transResult2.isOk() ?
1272 static_cast<sp<IConfigurable>>(transResult2) :
1273 nullptr;
1274 }()
1275 },
1276 mBase1_0{base},
1277 mBase1_1{base},
1278 mBase1_2{base},
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001279 mBufferPoolSender{std::make_unique<BufferPoolSender>()},
1280 mOutputBufferQueue{std::make_unique<OutputBufferQueue>()} {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001281}
1282
1283Codec2Client::Component::~Component() {
1284}
1285
1286c2_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 Vongmasabf69de92019-10-29 06:21:27 -07001291 Return<void> transStatus = mBase1_0->createBlockPool(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001292 static_cast<uint32_t>(id),
1293 [&status, blockPoolId, configurable](
1294 Status s,
1295 uint64_t pId,
1296 const sp<IConfigurable>& c) {
1297 status = static_cast<c2_status_t>(s);
1298 configurable->reset();
1299 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001300 LOG(DEBUG) << "createBlockPool -- call failed: "
1301 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001302 return;
1303 }
1304 *blockPoolId = static_cast<C2BlockPool::local_id_t>(pId);
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001305 *configurable = std::make_shared<Configurable>(c);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001306 });
1307 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001308 LOG(ERROR) << "createBlockPool -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001309 return C2_TRANSACTION_FAILED;
1310 }
1311 return status;
1312}
1313
1314c2_status_t Codec2Client::Component::destroyBlockPool(
1315 C2BlockPool::local_id_t localId) {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001316 Return<Status> transResult = mBase1_0->destroyBlockPool(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001317 static_cast<uint64_t>(localId));
1318 if (!transResult.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001319 LOG(ERROR) << "destroyBlockPool -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001320 return C2_TRANSACTION_FAILED;
1321 }
1322 return static_cast<c2_status_t>(static_cast<Status>(transResult));
1323}
1324
Wonsik Kimab34ed62019-01-31 15:28:46 -08001325void Codec2Client::Component::handleOnWorkDone(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001326 const std::list<std::unique_ptr<C2Work>> &workItems) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001327 // Output bufferqueue-based blocks' lifetime management
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001328 mOutputBufferQueue->holdBufferQueueBlocks(workItems);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001329}
1330
1331c2_status_t Codec2Client::Component::queue(
1332 std::list<std::unique_ptr<C2Work>>* const items) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001333 WorkBundle workBundle;
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001334 if (!objcpy(&workBundle, *items, mBufferPoolSender.get())) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001335 LOG(ERROR) << "queue -- bad input.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001336 return C2_TRANSACTION_FAILED;
1337 }
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001338 Return<Status> transStatus = mBase1_0->queue(workBundle);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001339 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001340 LOG(ERROR) << "queue -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001341 return C2_TRANSACTION_FAILED;
1342 }
1343 c2_status_t status =
1344 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1345 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001346 LOG(DEBUG) << "queue -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001347 }
1348 return status;
1349}
1350
1351c2_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 Vongmasabf69de92019-10-29 06:21:27 -07001356 Return<void> transStatus = mBase1_0->flush(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001357 [&status, flushedWork](
1358 Status s, const WorkBundle& wb) {
1359 status = static_cast<c2_status_t>(s);
1360 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001361 LOG(DEBUG) << "flush -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001362 return;
1363 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001364 if (!objcpy(flushedWork, wb)) {
1365 status = C2_CORRUPTED;
1366 } else {
1367 status = C2_OK;
1368 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001369 });
1370 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001371 LOG(ERROR) << "flush -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001372 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 Vongmasa36653902018-11-15 00:10:25 -08001390 // Output bufferqueue-based blocks' lifetime management
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001391 mOutputBufferQueue->holdBufferQueueBlocks(*flushedWork);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001392
1393 return status;
1394}
1395
1396c2_status_t Codec2Client::Component::drain(C2Component::drain_mode_t mode) {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001397 Return<Status> transStatus = mBase1_0->drain(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001398 mode == C2Component::DRAIN_COMPONENT_WITH_EOS);
1399 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001400 LOG(ERROR) << "drain -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001401 return C2_TRANSACTION_FAILED;
1402 }
1403 c2_status_t status =
1404 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1405 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001406 LOG(DEBUG) << "drain -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001407 }
1408 return status;
1409}
1410
1411c2_status_t Codec2Client::Component::start() {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001412 Return<Status> transStatus = mBase1_0->start();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001413 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001414 LOG(ERROR) << "start -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001415 return C2_TRANSACTION_FAILED;
1416 }
1417 c2_status_t status =
1418 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1419 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001420 LOG(DEBUG) << "start -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001421 }
1422 return status;
1423}
1424
1425c2_status_t Codec2Client::Component::stop() {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001426 Return<Status> transStatus = mBase1_0->stop();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001427 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001428 LOG(ERROR) << "stop -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001429 return C2_TRANSACTION_FAILED;
1430 }
1431 c2_status_t status =
1432 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1433 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001434 LOG(DEBUG) << "stop -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001435 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001436 return status;
1437}
1438
1439c2_status_t Codec2Client::Component::reset() {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001440 Return<Status> transStatus = mBase1_0->reset();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001441 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001442 LOG(ERROR) << "reset -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001443 return C2_TRANSACTION_FAILED;
1444 }
1445 c2_status_t status =
1446 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1447 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001448 LOG(DEBUG) << "reset -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001449 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001450 return status;
1451}
1452
1453c2_status_t Codec2Client::Component::release() {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001454 Return<Status> transStatus = mBase1_0->release();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001455 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001456 LOG(ERROR) << "release -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001457 return C2_TRANSACTION_FAILED;
1458 }
1459 c2_status_t status =
1460 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1461 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001462 LOG(DEBUG) << "release -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001463 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001464 return status;
1465}
1466
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001467c2_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](
1477 Status s, hardware::hidl_handle const& h) {
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 Vongmasa36653902018-11-15 00:10:25 -08001490c2_status_t Codec2Client::Component::setOutputSurface(
1491 C2BlockPool::local_id_t blockPoolId,
1492 const sp<IGraphicBufferProducer>& surface,
Sungtak Leedb14cba2021-04-10 00:50:23 -07001493 uint32_t generation,
1494 int maxDequeueCount) {
Sungtak Lee08515812019-06-05 11:16:32 -07001495 uint64_t bqId = 0;
1496 sp<IGraphicBufferProducer> nullIgbp;
1497 sp<HGraphicBufferProducer2> nullHgbp;
Pawin Vongmasa3866c7e2019-01-31 05:21:29 -08001498
Sungtak Lee08515812019-06-05 11:16:32 -07001499 sp<HGraphicBufferProducer2> igbp = surface ?
1500 surface->getHalInterface<HGraphicBufferProducer2>() : nullHgbp;
1501 if (surface && !igbp) {
Pawin Vongmasaef939bf2019-03-03 04:44:59 -08001502 igbp = new B2HGraphicBufferProducer2(surface);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001503 }
1504
Sungtak Leefb579022022-05-10 06:36:15 +00001505 std::scoped_lock lock(mOutputMutex);
Sungtak Leea714f112021-03-16 05:40:03 -07001506 std::shared_ptr<SurfaceSyncObj> syncObj;
1507
Sungtak Lee08515812019-06-05 11:16:32 -07001508 if (!surface) {
Sungtak Leedb14cba2021-04-10 00:50:23 -07001509 mOutputBufferQueue->configure(nullIgbp, generation, 0, maxDequeueCount, nullptr);
Sungtak Lee08515812019-06-05 11:16:32 -07001510 } else if (surface->getUniqueId(&bqId) != OK) {
1511 LOG(ERROR) << "setOutputSurface -- "
1512 "cannot obtain bufferqueue id.";
1513 bqId = 0;
Sungtak Leedb14cba2021-04-10 00:50:23 -07001514 mOutputBufferQueue->configure(nullIgbp, generation, 0, maxDequeueCount, nullptr);
Sungtak Lee08515812019-06-05 11:16:32 -07001515 } else {
Sungtak Leedb14cba2021-04-10 00:50:23 -07001516 mOutputBufferQueue->configure(surface, generation, bqId, maxDequeueCount, mBase1_2 ?
1517 &syncObj : nullptr);
Sungtak Lee08515812019-06-05 11:16:32 -07001518 }
Lajos Molnar78aa7c92021-02-18 21:39:01 -08001519
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 Lee08515812019-06-05 11:16:32 -07001556
Sungtak Leea714f112021-03-16 05:40:03 -07001557 Return<Status> transStatus = syncObj ?
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 Molnar78aa7c92021-02-18 21:39:01 -08001564
Pawin Vongmasa36653902018-11-15 00:10:25 -08001565 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001566 LOG(ERROR) << "setOutputSurface -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001567 return C2_TRANSACTION_FAILED;
1568 }
1569 c2_status_t status =
1570 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1571 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001572 LOG(DEBUG) << "setOutputSurface -- call failed: " << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001573 }
Sungtak Leea714f112021-03-16 05:40:03 -07001574 ALOGD("Surface configure completed");
Pawin Vongmasa36653902018-11-15 00:10:25 -08001575 return status;
1576}
1577
1578status_t Codec2Client::Component::queueToOutputSurface(
1579 const C2ConstGraphicBlock& block,
1580 const QueueBufferInput& input,
1581 QueueBufferOutput* output) {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001582 return mOutputBufferQueue->outputBuffer(block, input, output);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001583}
1584
Sungtak Leea714f112021-03-16 05:40:03 -07001585void Codec2Client::Component::setOutputSurfaceMaxDequeueCount(
1586 int maxDequeueCount) {
1587 mOutputBufferQueue->updateMaxDequeueBufferCount(maxDequeueCount);
1588}
1589
Sungtak Leec7da7a02022-05-05 08:45:33 +00001590void Codec2Client::Component::stopUsingOutputSurface(
1591 C2BlockPool::local_id_t blockPoolId) {
Sungtak Leefb579022022-05-10 06:36:15 +00001592 std::scoped_lock lock(mOutputMutex);
Sungtak Leec7da7a02022-05-05 08:45:33 +00001593 mOutputBufferQueue->stop();
1594 Return<Status> transStatus = mBase1_0->setOutputSurface(
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 =
1600 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1601 if (status != C2_OK) {
1602 LOG(DEBUG) << "setOutputSurface(stopUsingOutputSurface) -- call failed: "
1603 << status << ".";
1604 }
1605 }
1606}
1607
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001608c2_status_t Codec2Client::Component::connectToInputSurface(
1609 const std::shared_ptr<InputSurface>& inputSurface,
1610 std::shared_ptr<InputSurfaceConnection>* connection) {
1611 c2_status_t status;
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001612 Return<void> transStatus = mBase1_0->connectToInputSurface(
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001613 inputSurface->mBase,
1614 [&status, connection](
1615 Status s, const sp<IInputSurfaceConnection>& c) {
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 Vongmasa36653902018-11-15 00:10:25 -08001624 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001625 LOG(ERROR) << "connectToInputSurface -- transaction failed";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001626 return C2_TRANSACTION_FAILED;
1627 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001628 return status;
1629}
1630
1631c2_status_t Codec2Client::Component::connectToOmxInputSurface(
Pawin Vongmasaef939bf2019-03-03 04:44:59 -08001632 const sp<HGraphicBufferProducer1>& producer,
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001633 const sp<HGraphicBufferSource>& source,
1634 std::shared_ptr<InputSurfaceConnection>* connection) {
1635 c2_status_t status;
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001636 Return<void> transStatus = mBase1_0->connectToOmxInputSurface(
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001637 producer, source,
1638 [&status, connection](
1639 Status s, const sp<IInputSurfaceConnection>& c) {
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 Vongmasa36653902018-11-15 00:10:25 -08001651 }
1652 return status;
1653}
1654
1655c2_status_t Codec2Client::Component::disconnectFromInputSurface() {
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001656 Return<Status> transStatus = mBase1_0->disconnectFromInputSurface();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001657 if (!transStatus.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001658 LOG(ERROR) << "disconnectToInputSurface -- transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001659 return C2_TRANSACTION_FAILED;
1660 }
1661 c2_status_t status =
1662 static_cast<c2_status_t>(static_cast<Status>(transStatus));
1663 if (status != C2_OK) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001664 LOG(DEBUG) << "disconnectFromInputSurface -- call failed: "
1665 << status << ".";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001666 }
1667 return status;
1668}
1669
1670c2_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 Vongmasa1c75a232019-01-09 04:41:52 -08001685 LOG(DEBUG) << "onDeath -- listener died.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001686 }
1687 }
1688 };
1689
1690 sp<HidlDeathRecipient> deathRecipient = new HidlDeathRecipient();
1691 deathRecipient->base = listener;
1692 deathRecipient->component = component;
1693
1694 component->mDeathRecipient = deathRecipient;
Pawin Vongmasabf69de92019-10-29 06:21:27 -07001695 Return<bool> transResult = component->mBase1_0->linkToDeath(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001696 component->mDeathRecipient, 0);
1697 if (!transResult.isOk()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001698 LOG(ERROR) << "setDeathListener -- linkToDeath() transaction failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001699 return C2_TRANSACTION_FAILED;
1700 }
1701 if (!static_cast<bool>(transResult)) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001702 LOG(DEBUG) << "setDeathListener -- linkToDeath() call failed.";
Pawin Vongmasa36653902018-11-15 00:10:25 -08001703 return C2_CORRUPTED;
1704 }
1705 return C2_OK;
1706}
1707
1708// Codec2Client::InputSurface
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001709Codec2Client::InputSurface::InputSurface(const sp<IInputSurface>& base)
1710 : Configurable{
1711 [base]() -> sp<IConfigurable> {
1712 Return<sp<IConfigurable>> transResult =
1713 base->getConfigurable();
1714 return transResult.isOk() ?
1715 static_cast<sp<IConfigurable>>(transResult) :
1716 nullptr;
1717 }()
1718 },
1719 mBase{base},
1720 mGraphicBufferProducer{new
Pawin Vongmasaef939bf2019-03-03 04:44:59 -08001721 H2BGraphicBufferProducer2([base]() -> sp<HGraphicBufferProducer2> {
1722 Return<sp<HGraphicBufferProducer2>> transResult =
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001723 base->getGraphicBufferProducer();
1724 return transResult.isOk() ?
Pawin Vongmasaef939bf2019-03-03 04:44:59 -08001725 static_cast<sp<HGraphicBufferProducer2>>(transResult) :
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001726 nullptr;
1727 }())} {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001728}
1729
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001730sp<IGraphicBufferProducer>
Pawin Vongmasa36653902018-11-15 00:10:25 -08001731 Codec2Client::InputSurface::getGraphicBufferProducer() const {
1732 return mGraphicBufferProducer;
1733}
1734
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001735sp<IInputSurface> Codec2Client::InputSurface::getHalInterface() const {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001736 return mBase;
1737}
1738
1739// Codec2Client::InputSurfaceConnection
Pawin Vongmasa36653902018-11-15 00:10:25 -08001740Codec2Client::InputSurfaceConnection::InputSurfaceConnection(
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001741 const sp<IInputSurfaceConnection>& base)
1742 : Configurable{
1743 [base]() -> sp<IConfigurable> {
1744 Return<sp<IConfigurable>> transResult =
1745 base->getConfigurable();
1746 return transResult.isOk() ?
1747 static_cast<sp<IConfigurable>>(transResult) :
1748 nullptr;
1749 }()
1750 },
1751 mBase{base} {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001752}
1753
1754c2_status_t Codec2Client::InputSurfaceConnection::disconnect() {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001755 Return<Status> transResult = mBase->disconnect();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001756 return static_cast<c2_status_t>(static_cast<Status>(transResult));
1757}
1758
1759} // namespace android