blob: 5f60378f77c62cda4a80e7a376f13a5c9ca3e3ae [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "CCodec"
19#include <utils/Log.h>
20
21#include <sstream>
22#include <thread>
23
24#include <C2Config.h>
25#include <C2Debug.h>
26#include <C2ParamInternal.h>
27#include <C2PlatformSupport.h>
28
29#include <android/IGraphicBufferSource.h>
30#include <android/IOMXBufferSource.h>
31#include <android/hardware/media/omx/1.0/IGraphicBufferSource.h>
32#include <android/hardware/media/omx/1.0/IOmx.h>
33#include <android-base/stringprintf.h>
34#include <cutils/properties.h>
35#include <gui/IGraphicBufferProducer.h>
36#include <gui/Surface.h>
37#include <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h>
38#include <media/omx/1.0/WGraphicBufferSource.h>
39#include <media/openmax/OMX_IndexExt.h>
40#include <media/stagefright/BufferProducerWrapper.h>
41#include <media/stagefright/MediaCodecConstants.h>
42#include <media/stagefright/PersistentSurface.h>
43#include <media/stagefright/codec2/1.0/InputSurface.h>
44
45#include "C2OMXNode.h"
46#include "CCodec.h"
47#include "CCodecBufferChannel.h"
48#include "InputSurfaceWrapper.h"
49
50extern "C" android::PersistentSurface *CreateInputSurface();
51
52namespace android {
53
54using namespace std::chrono_literals;
55using ::android::hardware::graphics::bufferqueue::V1_0::utils::H2BGraphicBufferProducer;
56using android::base::StringPrintf;
57using BGraphicBufferSource = ::android::IGraphicBufferSource;
Pawin Vongmasad0f0e142018-11-15 03:36:28 -080058using ::android::hardware::media::c2::V1_0::IInputSurface;
Pawin Vongmasa36653902018-11-15 00:10:25 -080059
60namespace {
61
62class CCodecWatchdog : public AHandler {
63private:
64 enum {
65 kWhatWatch,
66 };
67 constexpr static int64_t kWatchIntervalUs = 3300000; // 3.3 secs
68
69public:
70 static sp<CCodecWatchdog> getInstance() {
71 static sp<CCodecWatchdog> instance(new CCodecWatchdog);
72 static std::once_flag flag;
73 // Call Init() only once.
74 std::call_once(flag, Init, instance);
75 return instance;
76 }
77
78 ~CCodecWatchdog() = default;
79
80 void watch(sp<CCodec> codec) {
81 bool shouldPost = false;
82 {
83 Mutexed<std::set<wp<CCodec>>>::Locked codecs(mCodecsToWatch);
84 // If a watch message is in flight, piggy-back this instance as well.
85 // Otherwise, post a new watch message.
86 shouldPost = codecs->empty();
87 codecs->emplace(codec);
88 }
89 if (shouldPost) {
90 ALOGV("posting watch message");
91 (new AMessage(kWhatWatch, this))->post(kWatchIntervalUs);
92 }
93 }
94
95protected:
96 void onMessageReceived(const sp<AMessage> &msg) {
97 switch (msg->what()) {
98 case kWhatWatch: {
99 Mutexed<std::set<wp<CCodec>>>::Locked codecs(mCodecsToWatch);
100 ALOGV("watch for %zu codecs", codecs->size());
101 for (auto it = codecs->begin(); it != codecs->end(); ++it) {
102 sp<CCodec> codec = it->promote();
103 if (codec == nullptr) {
104 continue;
105 }
106 codec->initiateReleaseIfStuck();
107 }
108 codecs->clear();
109 break;
110 }
111
112 default: {
113 TRESPASS("CCodecWatchdog: unrecognized message");
114 }
115 }
116 }
117
118private:
119 CCodecWatchdog() : mLooper(new ALooper) {}
120
121 static void Init(const sp<CCodecWatchdog> &thiz) {
122 ALOGV("Init");
123 thiz->mLooper->setName("CCodecWatchdog");
124 thiz->mLooper->registerHandler(thiz);
125 thiz->mLooper->start();
126 }
127
128 sp<ALooper> mLooper;
129
130 Mutexed<std::set<wp<CCodec>>> mCodecsToWatch;
131};
132
133class C2InputSurfaceWrapper : public InputSurfaceWrapper {
134public:
135 explicit C2InputSurfaceWrapper(
136 const std::shared_ptr<Codec2Client::InputSurface> &surface) :
137 mSurface(surface) {
138 }
139
140 ~C2InputSurfaceWrapper() override = default;
141
142 status_t connect(const std::shared_ptr<Codec2Client::Component> &comp) override {
143 if (mConnection != nullptr) {
144 return ALREADY_EXISTS;
145 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800146 return toStatusT(comp->connectToInputSurface(mSurface, &mConnection));
Pawin Vongmasa36653902018-11-15 00:10:25 -0800147 }
148
149 void disconnect() override {
150 if (mConnection != nullptr) {
151 mConnection->disconnect();
152 mConnection = nullptr;
153 }
154 }
155
156 status_t start() override {
157 // InputSurface does not distinguish started state
158 return OK;
159 }
160
161 status_t signalEndOfInputStream() override {
162 C2InputSurfaceEosTuning eos(true);
163 std::vector<std::unique_ptr<C2SettingResult>> failures;
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800164 c2_status_t err = mSurface->config({&eos}, C2_MAY_BLOCK, &failures);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800165 if (err != C2_OK) {
166 return UNKNOWN_ERROR;
167 }
168 return OK;
169 }
170
171 status_t configure(Config &config __unused) {
172 // TODO
173 return OK;
174 }
175
176private:
177 std::shared_ptr<Codec2Client::InputSurface> mSurface;
178 std::shared_ptr<Codec2Client::InputSurfaceConnection> mConnection;
179};
180
181class GraphicBufferSourceWrapper : public InputSurfaceWrapper {
182public:
183// explicit GraphicBufferSourceWrapper(const sp<BGraphicBufferSource> &source) : mSource(source) {}
184 GraphicBufferSourceWrapper(
185 const sp<BGraphicBufferSource> &source,
186 uint32_t width,
187 uint32_t height)
188 : mSource(source), mWidth(width), mHeight(height) {
189 mDataSpace = HAL_DATASPACE_BT709;
190 }
191 ~GraphicBufferSourceWrapper() override = default;
192
193 status_t connect(const std::shared_ptr<Codec2Client::Component> &comp) override {
194 mNode = new C2OMXNode(comp);
195 mNode->setFrameSize(mWidth, mHeight);
196
197 // NOTE: we do not use/pass through color aspects from GraphicBufferSource as we
198 // communicate that directly to the component.
199 mSource->configure(mNode, mDataSpace);
200 return OK;
201 }
202
203 void disconnect() override {
204 if (mNode == nullptr) {
205 return;
206 }
207 sp<IOMXBufferSource> source = mNode->getSource();
208 if (source == nullptr) {
209 ALOGD("GBSWrapper::disconnect: node is not configured with OMXBufferSource.");
210 return;
211 }
212 source->onOmxIdle();
213 source->onOmxLoaded();
214 mNode.clear();
215 }
216
217 status_t GetStatus(const binder::Status &status) {
218 status_t err = OK;
219 if (!status.isOk()) {
220 err = status.serviceSpecificErrorCode();
221 if (err == OK) {
222 err = status.transactionError();
223 if (err == OK) {
224 // binder status failed, but there is no servie or transaction error
225 err = UNKNOWN_ERROR;
226 }
227 }
228 }
229 return err;
230 }
231
232 status_t start() override {
233 sp<IOMXBufferSource> source = mNode->getSource();
234 if (source == nullptr) {
235 return NO_INIT;
236 }
237 constexpr size_t kNumSlots = 16;
238 for (size_t i = 0; i < kNumSlots; ++i) {
239 source->onInputBufferAdded(i);
240 }
241
242 source->onOmxExecuting();
243 return OK;
244 }
245
246 status_t signalEndOfInputStream() override {
247 return GetStatus(mSource->signalEndOfInputStream());
248 }
249
250 status_t configure(Config &config) {
251 std::stringstream status;
252 status_t err = OK;
253
254 // handle each configuration granually, in case we need to handle part of the configuration
255 // elsewhere
256
257 // TRICKY: we do not unset frame delay repeating
258 if (config.mMinFps > 0 && config.mMinFps != mConfig.mMinFps) {
259 int64_t us = 1e6 / config.mMinFps + 0.5;
260 status_t res = GetStatus(mSource->setRepeatPreviousFrameDelayUs(us));
261 status << " minFps=" << config.mMinFps << " => repeatDelayUs=" << us;
262 if (res != OK) {
263 status << " (=> " << asString(res) << ")";
264 err = res;
265 }
266 mConfig.mMinFps = config.mMinFps;
267 }
268
269 // pts gap
270 if (config.mMinAdjustedFps > 0 || config.mFixedAdjustedFps > 0) {
271 if (mNode != nullptr) {
272 OMX_PARAM_U32TYPE ptrGapParam = {};
273 ptrGapParam.nSize = sizeof(OMX_PARAM_U32TYPE);
Wonsik Kim95ba0162019-03-19 15:51:54 -0700274 float gap = (config.mMinAdjustedFps > 0)
Pawin Vongmasa36653902018-11-15 00:10:25 -0800275 ? c2_min(INT32_MAX + 0., 1e6 / config.mMinAdjustedFps + 0.5)
276 : c2_max(0. - INT32_MAX, -1e6 / config.mFixedAdjustedFps - 0.5);
Wonsik Kim95ba0162019-03-19 15:51:54 -0700277 // float -> uint32_t is undefined if the value is negative.
278 // First convert to int32_t to ensure the expected behavior.
279 ptrGapParam.nU32 = int32_t(gap);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800280 (void)mNode->setParameter(
281 (OMX_INDEXTYPE)OMX_IndexParamMaxFrameDurationForBitrateControl,
282 &ptrGapParam, sizeof(ptrGapParam));
283 }
284 }
285
286 // max fps
287 // TRICKY: we do not unset max fps to 0 unless using fixed fps
Wonsik Kim95ba0162019-03-19 15:51:54 -0700288 if ((config.mMaxFps > 0 || (config.mFixedAdjustedFps > 0 && config.mMaxFps == -1))
Pawin Vongmasa36653902018-11-15 00:10:25 -0800289 && config.mMaxFps != mConfig.mMaxFps) {
290 status_t res = GetStatus(mSource->setMaxFps(config.mMaxFps));
291 status << " maxFps=" << config.mMaxFps;
292 if (res != OK) {
293 status << " (=> " << asString(res) << ")";
294 err = res;
295 }
296 mConfig.mMaxFps = config.mMaxFps;
297 }
298
299 if (config.mTimeOffsetUs != mConfig.mTimeOffsetUs) {
300 status_t res = GetStatus(mSource->setTimeOffsetUs(config.mTimeOffsetUs));
301 status << " timeOffset " << config.mTimeOffsetUs << "us";
302 if (res != OK) {
303 status << " (=> " << asString(res) << ")";
304 err = res;
305 }
306 mConfig.mTimeOffsetUs = config.mTimeOffsetUs;
307 }
308
309 if (config.mCaptureFps != mConfig.mCaptureFps || config.mCodedFps != mConfig.mCodedFps) {
310 status_t res =
311 GetStatus(mSource->setTimeLapseConfig(config.mCodedFps, config.mCaptureFps));
312 status << " timeLapse " << config.mCaptureFps << "fps as " << config.mCodedFps << "fps";
313 if (res != OK) {
314 status << " (=> " << asString(res) << ")";
315 err = res;
316 }
317 mConfig.mCaptureFps = config.mCaptureFps;
318 mConfig.mCodedFps = config.mCodedFps;
319 }
320
321 if (config.mStartAtUs != mConfig.mStartAtUs
322 || (config.mStopped != mConfig.mStopped && !config.mStopped)) {
323 status_t res = GetStatus(mSource->setStartTimeUs(config.mStartAtUs));
324 status << " start at " << config.mStartAtUs << "us";
325 if (res != OK) {
326 status << " (=> " << asString(res) << ")";
327 err = res;
328 }
329 mConfig.mStartAtUs = config.mStartAtUs;
330 mConfig.mStopped = config.mStopped;
331 }
332
333 // suspend-resume
334 if (config.mSuspended != mConfig.mSuspended) {
335 status_t res = GetStatus(mSource->setSuspend(config.mSuspended, config.mSuspendAtUs));
336 status << " " << (config.mSuspended ? "suspend" : "resume")
337 << " at " << config.mSuspendAtUs << "us";
338 if (res != OK) {
339 status << " (=> " << asString(res) << ")";
340 err = res;
341 }
342 mConfig.mSuspended = config.mSuspended;
343 mConfig.mSuspendAtUs = config.mSuspendAtUs;
344 }
345
346 if (config.mStopped != mConfig.mStopped && config.mStopped) {
347 status_t res = GetStatus(mSource->setStopTimeUs(config.mStopAtUs));
348 status << " stop at " << config.mStopAtUs << "us";
349 if (res != OK) {
350 status << " (=> " << asString(res) << ")";
351 err = res;
352 } else {
353 status << " delayUs";
354 res = GetStatus(mSource->getStopTimeOffsetUs(&config.mInputDelayUs));
355 if (res != OK) {
356 status << " (=> " << asString(res) << ")";
357 } else {
358 status << "=" << config.mInputDelayUs << "us";
359 }
360 mConfig.mInputDelayUs = config.mInputDelayUs;
361 }
362 mConfig.mStopAtUs = config.mStopAtUs;
363 mConfig.mStopped = config.mStopped;
364 }
365
366 // color aspects (android._color-aspects)
367
368 // consumer usage
369 ALOGD("ISConfig%s", status.str().c_str());
370 return err;
371 }
372
373private:
374 sp<BGraphicBufferSource> mSource;
375 sp<C2OMXNode> mNode;
376 uint32_t mWidth;
377 uint32_t mHeight;
378 Config mConfig;
379};
380
381class Codec2ClientInterfaceWrapper : public C2ComponentStore {
382 std::shared_ptr<Codec2Client> mClient;
383
384public:
385 Codec2ClientInterfaceWrapper(std::shared_ptr<Codec2Client> client)
386 : mClient(client) { }
387
388 virtual ~Codec2ClientInterfaceWrapper() = default;
389
390 virtual c2_status_t config_sm(
391 const std::vector<C2Param *> &params,
392 std::vector<std::unique_ptr<C2SettingResult>> *const failures) {
393 return mClient->config(params, C2_MAY_BLOCK, failures);
394 };
395
396 virtual c2_status_t copyBuffer(
397 std::shared_ptr<C2GraphicBuffer>,
398 std::shared_ptr<C2GraphicBuffer>) {
399 return C2_OMITTED;
400 }
401
402 virtual c2_status_t createComponent(
403 C2String, std::shared_ptr<C2Component> *const component) {
404 component->reset();
405 return C2_OMITTED;
406 }
407
408 virtual c2_status_t createInterface(
409 C2String, std::shared_ptr<C2ComponentInterface> *const interface) {
410 interface->reset();
411 return C2_OMITTED;
412 }
413
414 virtual c2_status_t query_sm(
415 const std::vector<C2Param *> &stackParams,
416 const std::vector<C2Param::Index> &heapParamIndices,
417 std::vector<std::unique_ptr<C2Param>> *const heapParams) const {
418 return mClient->query(stackParams, heapParamIndices, C2_MAY_BLOCK, heapParams);
419 }
420
421 virtual c2_status_t querySupportedParams_nb(
422 std::vector<std::shared_ptr<C2ParamDescriptor>> *const params) const {
423 return mClient->querySupportedParams(params);
424 }
425
426 virtual c2_status_t querySupportedValues_sm(
427 std::vector<C2FieldSupportedValuesQuery> &fields) const {
428 return mClient->querySupportedValues(fields, C2_MAY_BLOCK);
429 }
430
431 virtual C2String getName() const {
432 return mClient->getName();
433 }
434
435 virtual std::shared_ptr<C2ParamReflector> getParamReflector() const {
436 return mClient->getParamReflector();
437 }
438
439 virtual std::vector<std::shared_ptr<const C2Component::Traits>> listComponents() {
440 return std::vector<std::shared_ptr<const C2Component::Traits>>();
441 }
442};
443
444} // namespace
445
446// CCodec::ClientListener
447
448struct CCodec::ClientListener : public Codec2Client::Listener {
449
450 explicit ClientListener(const wp<CCodec> &codec) : mCodec(codec) {}
451
452 virtual void onWorkDone(
453 const std::weak_ptr<Codec2Client::Component>& component,
Wonsik Kimab34ed62019-01-31 15:28:46 -0800454 std::list<std::unique_ptr<C2Work>>& workItems) override {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800455 (void)component;
456 sp<CCodec> codec(mCodec.promote());
457 if (!codec) {
458 return;
459 }
Wonsik Kimab34ed62019-01-31 15:28:46 -0800460 codec->onWorkDone(workItems);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800461 }
462
463 virtual void onTripped(
464 const std::weak_ptr<Codec2Client::Component>& component,
465 const std::vector<std::shared_ptr<C2SettingResult>>& settingResult
466 ) override {
467 // TODO
468 (void)component;
469 (void)settingResult;
470 }
471
472 virtual void onError(
473 const std::weak_ptr<Codec2Client::Component>& component,
474 uint32_t errorCode) override {
475 // TODO
476 (void)component;
477 (void)errorCode;
478 }
479
480 virtual void onDeath(
481 const std::weak_ptr<Codec2Client::Component>& component) override {
482 { // Log the death of the component.
483 std::shared_ptr<Codec2Client::Component> comp = component.lock();
484 if (!comp) {
485 ALOGE("Codec2 component died.");
486 } else {
487 ALOGE("Codec2 component \"%s\" died.", comp->getName().c_str());
488 }
489 }
490
491 // Report to MediaCodec.
492 sp<CCodec> codec(mCodec.promote());
493 if (!codec || !codec->mCallback) {
494 return;
495 }
496 codec->mCallback->onError(DEAD_OBJECT, ACTION_CODE_FATAL);
497 }
498
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800499 virtual void onFrameRendered(uint64_t bufferQueueId,
500 int32_t slotId,
501 int64_t timestampNs) override {
502 // TODO: implement
503 (void)bufferQueueId;
504 (void)slotId;
505 (void)timestampNs;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800506 }
507
508 virtual void onInputBufferDone(
Wonsik Kimab34ed62019-01-31 15:28:46 -0800509 uint64_t frameIndex, size_t arrayIndex) override {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800510 sp<CCodec> codec(mCodec.promote());
511 if (codec) {
Wonsik Kimab34ed62019-01-31 15:28:46 -0800512 codec->onInputBufferDone(frameIndex, arrayIndex);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800513 }
514 }
515
516private:
517 wp<CCodec> mCodec;
518};
519
520// CCodecCallbackImpl
521
522class CCodecCallbackImpl : public CCodecCallback {
523public:
524 explicit CCodecCallbackImpl(CCodec *codec) : mCodec(codec) {}
525 ~CCodecCallbackImpl() override = default;
526
527 void onError(status_t err, enum ActionCode actionCode) override {
528 mCodec->mCallback->onError(err, actionCode);
529 }
530
531 void onOutputFramesRendered(int64_t mediaTimeUs, nsecs_t renderTimeNs) override {
532 mCodec->mCallback->onOutputFramesRendered(
533 {RenderedFrameInfo(mediaTimeUs, renderTimeNs)});
534 }
535
Pawin Vongmasa36653902018-11-15 00:10:25 -0800536 void onOutputBuffersChanged() override {
537 mCodec->mCallback->onOutputBuffersChanged();
538 }
539
540private:
541 CCodec *mCodec;
542};
543
544// CCodec
545
546CCodec::CCodec()
Wonsik Kimab34ed62019-01-31 15:28:46 -0800547 : mChannel(new CCodecBufferChannel(std::make_shared<CCodecCallbackImpl>(this))) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800548}
549
550CCodec::~CCodec() {
551}
552
553std::shared_ptr<BufferChannelBase> CCodec::getBufferChannel() {
554 return mChannel;
555}
556
557status_t CCodec::tryAndReportOnError(std::function<status_t()> job) {
558 status_t err = job();
559 if (err != C2_OK) {
560 mCallback->onError(err, ACTION_CODE_FATAL);
561 }
562 return err;
563}
564
565void CCodec::initiateAllocateComponent(const sp<AMessage> &msg) {
566 auto setAllocating = [this] {
567 Mutexed<State>::Locked state(mState);
568 if (state->get() != RELEASED) {
569 return INVALID_OPERATION;
570 }
571 state->set(ALLOCATING);
572 return OK;
573 };
574 if (tryAndReportOnError(setAllocating) != OK) {
575 return;
576 }
577
578 sp<RefBase> codecInfo;
579 CHECK(msg->findObject("codecInfo", &codecInfo));
580 // For Codec 2.0 components, componentName == codecInfo->getCodecName().
581
582 sp<AMessage> allocMsg(new AMessage(kWhatAllocate, this));
583 allocMsg->setObject("codecInfo", codecInfo);
584 allocMsg->post();
585}
586
587void CCodec::allocate(const sp<MediaCodecInfo> &codecInfo) {
588 if (codecInfo == nullptr) {
589 mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
590 return;
591 }
592 ALOGD("allocate(%s)", codecInfo->getCodecName());
593 mClientListener.reset(new ClientListener(this));
594
595 AString componentName = codecInfo->getCodecName();
596 std::shared_ptr<Codec2Client> client;
597
598 // set up preferred component store to access vendor store parameters
599 client = Codec2Client::CreateFromService("default", false);
600 if (client) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -0800601 ALOGI("setting up '%s' as default (vendor) store", client->getServiceName().c_str());
Pawin Vongmasa36653902018-11-15 00:10:25 -0800602 SetPreferredCodec2ComponentStore(
603 std::make_shared<Codec2ClientInterfaceWrapper>(client));
604 }
605
606 std::shared_ptr<Codec2Client::Component> comp =
607 Codec2Client::CreateComponentByName(
608 componentName.c_str(),
609 mClientListener,
610 &client);
611 if (!comp) {
612 ALOGE("Failed Create component: %s", componentName.c_str());
613 Mutexed<State>::Locked state(mState);
614 state->set(RELEASED);
615 state.unlock();
616 mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
617 state.lock();
618 return;
619 }
620 ALOGI("Created component [%s]", componentName.c_str());
621 mChannel->setComponent(comp);
622 auto setAllocated = [this, comp, client] {
623 Mutexed<State>::Locked state(mState);
624 if (state->get() != ALLOCATING) {
625 state->set(RELEASED);
626 return UNKNOWN_ERROR;
627 }
628 state->set(ALLOCATED);
629 state->comp = comp;
630 mClient = client;
631 return OK;
632 };
633 if (tryAndReportOnError(setAllocated) != OK) {
634 return;
635 }
636
637 // initialize config here in case setParameters is called prior to configure
638 Mutexed<Config>::Locked config(mConfig);
639 status_t err = config->initialize(mClient, comp);
640 if (err != OK) {
641 ALOGW("Failed to initialize configuration support");
642 // TODO: report error once we complete implementation.
643 }
644 config->queryConfiguration(comp);
645
646 mCallback->onComponentAllocated(componentName.c_str());
647}
648
649void CCodec::initiateConfigureComponent(const sp<AMessage> &format) {
650 auto checkAllocated = [this] {
651 Mutexed<State>::Locked state(mState);
652 return (state->get() != ALLOCATED) ? UNKNOWN_ERROR : OK;
653 };
654 if (tryAndReportOnError(checkAllocated) != OK) {
655 return;
656 }
657
658 sp<AMessage> msg(new AMessage(kWhatConfigure, this));
659 msg->setMessage("format", format);
660 msg->post();
661}
662
663void CCodec::configure(const sp<AMessage> &msg) {
664 std::shared_ptr<Codec2Client::Component> comp;
665 auto checkAllocated = [this, &comp] {
666 Mutexed<State>::Locked state(mState);
667 if (state->get() != ALLOCATED) {
668 state->set(RELEASED);
669 return UNKNOWN_ERROR;
670 }
671 comp = state->comp;
672 return OK;
673 };
674 if (tryAndReportOnError(checkAllocated) != OK) {
675 return;
676 }
677
678 auto doConfig = [msg, comp, this]() -> status_t {
679 AString mime;
680 if (!msg->findString("mime", &mime)) {
681 return BAD_VALUE;
682 }
683
684 int32_t encoder;
685 if (!msg->findInt32("encoder", &encoder)) {
686 encoder = false;
687 }
688
689 // TODO: read from intf()
690 if ((!encoder) != (comp->getName().find("encoder") == std::string::npos)) {
691 return UNKNOWN_ERROR;
692 }
693
694 int32_t storeMeta;
695 if (encoder
696 && msg->findInt32("android._input-metadata-buffer-type", &storeMeta)
697 && storeMeta != kMetadataBufferTypeInvalid) {
698 if (storeMeta != kMetadataBufferTypeANWBuffer) {
699 ALOGD("Only ANW buffers are supported for legacy metadata mode");
700 return BAD_VALUE;
701 }
702 mChannel->setMetaMode(CCodecBufferChannel::MODE_ANW);
703 }
704
705 sp<RefBase> obj;
706 sp<Surface> surface;
707 if (msg->findObject("native-window", &obj)) {
708 surface = static_cast<Surface *>(obj.get());
709 setSurface(surface);
710 }
711
712 Mutexed<Config>::Locked config(mConfig);
713 config->mUsingSurface = surface != nullptr;
714
Wonsik Kim1114eea2019-02-25 14:35:24 -0800715 // Enforce required parameters
716 int32_t i32;
717 float flt;
718 if (config->mDomain & Config::IS_AUDIO) {
719 if (!msg->findInt32(KEY_SAMPLE_RATE, &i32)) {
720 ALOGD("sample rate is missing, which is required for audio components.");
721 return BAD_VALUE;
722 }
723 if (!msg->findInt32(KEY_CHANNEL_COUNT, &i32)) {
724 ALOGD("channel count is missing, which is required for audio components.");
725 return BAD_VALUE;
726 }
727 if ((config->mDomain & Config::IS_ENCODER)
728 && !mime.equalsIgnoreCase(MEDIA_MIMETYPE_AUDIO_FLAC)
729 && !msg->findInt32(KEY_BIT_RATE, &i32)
730 && !msg->findFloat(KEY_BIT_RATE, &flt)) {
731 ALOGD("bitrate is missing, which is required for audio encoders.");
732 return BAD_VALUE;
733 }
734 }
735 if (config->mDomain & (Config::IS_IMAGE | Config::IS_VIDEO)) {
736 if (!msg->findInt32(KEY_WIDTH, &i32)) {
737 ALOGD("width is missing, which is required for image/video components.");
738 return BAD_VALUE;
739 }
740 if (!msg->findInt32(KEY_HEIGHT, &i32)) {
741 ALOGD("height is missing, which is required for image/video components.");
742 return BAD_VALUE;
743 }
744 if ((config->mDomain & Config::IS_ENCODER) && (config->mDomain & Config::IS_VIDEO)) {
745 if (!msg->findInt32(KEY_BIT_RATE, &i32)
746 && !msg->findFloat(KEY_BIT_RATE, &flt)) {
747 ALOGD("bitrate is missing, which is required for video encoders.");
748 return BAD_VALUE;
749 }
750 if (!msg->findInt32(KEY_I_FRAME_INTERVAL, &i32)
751 && !msg->findFloat(KEY_I_FRAME_INTERVAL, &flt)) {
752 ALOGD("I frame interval is missing, which is required for video encoders.");
753 return BAD_VALUE;
754 }
755 }
756 }
757
Pawin Vongmasa36653902018-11-15 00:10:25 -0800758 /*
759 * Handle input surface configuration
760 */
761 if ((config->mDomain & (Config::IS_VIDEO | Config::IS_IMAGE))
762 && (config->mDomain & Config::IS_ENCODER)) {
763 config->mISConfig.reset(new InputSurfaceWrapper::Config{});
764 {
765 config->mISConfig->mMinFps = 0;
766 int64_t value;
Chong Zhang038e8f82019-02-06 19:05:14 -0800767 if (msg->findInt64(KEY_REPEAT_PREVIOUS_FRAME_AFTER, &value) && value > 0) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800768 config->mISConfig->mMinFps = 1e6 / value;
769 }
Wonsik Kim95ba0162019-03-19 15:51:54 -0700770 if (!msg->findFloat(
771 KEY_MAX_FPS_TO_ENCODER, &config->mISConfig->mMaxFps)) {
772 config->mISConfig->mMaxFps = -1;
773 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800774 config->mISConfig->mMinAdjustedFps = 0;
775 config->mISConfig->mFixedAdjustedFps = 0;
Chong Zhang038e8f82019-02-06 19:05:14 -0800776 if (msg->findInt64(KEY_MAX_PTS_GAP_TO_ENCODER, &value)) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800777 if (value < 0 && value >= INT32_MIN) {
778 config->mISConfig->mFixedAdjustedFps = -1e6 / value;
Wonsik Kim95ba0162019-03-19 15:51:54 -0700779 config->mISConfig->mMaxFps = -1;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800780 } else if (value > 0 && value <= INT32_MAX) {
781 config->mISConfig->mMinAdjustedFps = 1e6 / value;
782 }
783 }
784 }
785
786 {
787 double value;
788 if (msg->findDouble("time-lapse-fps", &value)) {
789 config->mISConfig->mCaptureFps = value;
790 (void)msg->findAsFloat(KEY_FRAME_RATE, &config->mISConfig->mCodedFps);
791 }
792 }
793
794 {
795 config->mISConfig->mSuspended = false;
796 config->mISConfig->mSuspendAtUs = -1;
797 int32_t value;
Chong Zhang038e8f82019-02-06 19:05:14 -0800798 if (msg->findInt32(KEY_CREATE_INPUT_SURFACE_SUSPENDED, &value) && value) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800799 config->mISConfig->mSuspended = true;
800 }
801 }
802 }
803
804 /*
805 * Handle desired color format.
806 */
807 if ((config->mDomain & (Config::IS_VIDEO | Config::IS_IMAGE))) {
808 int32_t format = -1;
809 if (!msg->findInt32(KEY_COLOR_FORMAT, &format)) {
810 /*
811 * Also handle default color format (encoders require color format, so this is only
812 * needed for decoders.
813 */
814 if (!(config->mDomain & Config::IS_ENCODER)) {
815 format = (surface == nullptr) ? COLOR_FormatYUV420Planar : COLOR_FormatSurface;
816 }
817 }
818
819 if (format >= 0) {
820 msg->setInt32("android._color-format", format);
821 }
822 }
823
824 std::vector<std::unique_ptr<C2Param>> configUpdate;
Wonsik Kimaa484ac2019-02-13 16:54:02 -0800825 // NOTE: We used to ignore "video-bitrate" at configure; replicate
826 // the behavior here.
827 sp<AMessage> sdkParams = msg;
828 int32_t videoBitrate;
829 if (sdkParams->findInt32(PARAMETER_KEY_VIDEO_BITRATE, &videoBitrate)) {
830 sdkParams = msg->dup();
831 sdkParams->removeEntryAt(sdkParams->findEntryByName(PARAMETER_KEY_VIDEO_BITRATE));
832 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800833 status_t err = config->getConfigUpdateFromSdkParams(
Wonsik Kimaa484ac2019-02-13 16:54:02 -0800834 comp, sdkParams, Config::IS_CONFIG, C2_DONT_BLOCK, &configUpdate);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800835 if (err != OK) {
836 ALOGW("failed to convert configuration to c2 params");
837 }
838 err = config->setParameters(comp, configUpdate, C2_DONT_BLOCK);
839 if (err != OK) {
840 ALOGW("failed to configure c2 params");
841 return err;
842 }
843
844 std::vector<std::unique_ptr<C2Param>> params;
845 C2StreamUsageTuning::input usage(0u, 0u);
846 C2StreamMaxBufferSizeInfo::input maxInputSize(0u, 0u);
847
848 std::initializer_list<C2Param::Index> indices {
849 };
850 c2_status_t c2err = comp->query(
851 { &usage, &maxInputSize },
852 indices,
853 C2_DONT_BLOCK,
854 &params);
855 if (c2err != C2_OK && c2err != C2_BAD_INDEX) {
856 ALOGE("Failed to query component interface: %d", c2err);
857 return UNKNOWN_ERROR;
858 }
859 if (params.size() != indices.size()) {
860 ALOGE("Component returns wrong number of params: expected %zu actual %zu",
861 indices.size(), params.size());
862 return UNKNOWN_ERROR;
863 }
864 if (usage && (usage.value & C2MemoryUsage::CPU_READ)) {
865 config->mInputFormat->setInt32("using-sw-read-often", true);
866 }
867
868 // NOTE: we don't blindly use client specified input size if specified as clients
869 // at times specify too small size. Instead, mimic the behavior from OMX, where the
870 // client specified size is only used to ask for bigger buffers than component suggested
871 // size.
872 int32_t clientInputSize = 0;
873 bool clientSpecifiedInputSize =
874 msg->findInt32(KEY_MAX_INPUT_SIZE, &clientInputSize) && clientInputSize > 0;
875 // TEMP: enforce minimum buffer size of 1MB for video decoders
876 // and 16K / 4K for audio encoders/decoders
877 if (maxInputSize.value == 0) {
878 if (config->mDomain & Config::IS_AUDIO) {
879 maxInputSize.value = encoder ? 16384 : 4096;
880 } else if (!encoder) {
881 maxInputSize.value = 1048576u;
882 }
883 }
884
885 // verify that CSD fits into this size (if defined)
886 if ((config->mDomain & Config::IS_DECODER) && maxInputSize.value > 0) {
887 sp<ABuffer> csd;
888 for (size_t ix = 0; msg->findBuffer(StringPrintf("csd-%zu", ix).c_str(), &csd); ++ix) {
889 if (csd && csd->size() > maxInputSize.value) {
890 maxInputSize.value = csd->size();
891 }
892 }
893 }
894
895 // TODO: do this based on component requiring linear allocator for input
896 if ((config->mDomain & Config::IS_DECODER) || (config->mDomain & Config::IS_AUDIO)) {
897 if (clientSpecifiedInputSize) {
898 // Warn that we're overriding client's max input size if necessary.
899 if ((uint32_t)clientInputSize < maxInputSize.value) {
900 ALOGD("client requested max input size %d, which is smaller than "
901 "what component recommended (%u); overriding with component "
902 "recommendation.", clientInputSize, maxInputSize.value);
903 ALOGW("This behavior is subject to change. It is recommended that "
904 "app developers double check whether the requested "
905 "max input size is in reasonable range.");
906 } else {
907 maxInputSize.value = clientInputSize;
908 }
909 }
910 // Pass max input size on input format to the buffer channel (if supplied by the
911 // component or by a default)
912 if (maxInputSize.value) {
913 config->mInputFormat->setInt32(
914 KEY_MAX_INPUT_SIZE,
915 (int32_t)(c2_min(maxInputSize.value, uint32_t(INT32_MAX))));
916 }
917 }
918
919 if ((config->mDomain & (Config::IS_VIDEO | Config::IS_IMAGE))) {
920 // propagate HDR static info to output format for both encoders and decoders
921 // if component supports this info, we will update from component, but only the raw port,
922 // so don't propagate if component already filled it in.
923 sp<ABuffer> hdrInfo;
924 if (msg->findBuffer(KEY_HDR_STATIC_INFO, &hdrInfo)
925 && !config->mOutputFormat->findBuffer(KEY_HDR_STATIC_INFO, &hdrInfo)) {
926 config->mOutputFormat->setBuffer(KEY_HDR_STATIC_INFO, hdrInfo);
927 }
928
929 // Set desired color format from configuration parameter
930 int32_t format;
931 if (msg->findInt32("android._color-format", &format)) {
932 if (config->mDomain & Config::IS_ENCODER) {
933 config->mInputFormat->setInt32(KEY_COLOR_FORMAT, format);
934 } else {
935 config->mOutputFormat->setInt32(KEY_COLOR_FORMAT, format);
936 }
937 }
938 }
939
940 // propagate encoder delay and padding to output format
941 if ((config->mDomain & Config::IS_DECODER) && (config->mDomain & Config::IS_AUDIO)) {
942 int delay = 0;
943 if (msg->findInt32("encoder-delay", &delay)) {
944 config->mOutputFormat->setInt32("encoder-delay", delay);
945 }
946 int padding = 0;
947 if (msg->findInt32("encoder-padding", &padding)) {
948 config->mOutputFormat->setInt32("encoder-padding", padding);
949 }
950 }
951
952 // set channel-mask
953 if (config->mDomain & Config::IS_AUDIO) {
954 int32_t mask;
955 if (msg->findInt32(KEY_CHANNEL_MASK, &mask)) {
956 if (config->mDomain & Config::IS_ENCODER) {
957 config->mInputFormat->setInt32(KEY_CHANNEL_MASK, mask);
958 } else {
959 config->mOutputFormat->setInt32(KEY_CHANNEL_MASK, mask);
960 }
961 }
962 }
963
964 ALOGD("setup formats input: %s and output: %s",
965 config->mInputFormat->debugString().c_str(),
966 config->mOutputFormat->debugString().c_str());
967 return OK;
968 };
969 if (tryAndReportOnError(doConfig) != OK) {
970 return;
971 }
972
973 Mutexed<Config>::Locked config(mConfig);
974
975 mCallback->onComponentConfigured(config->mInputFormat, config->mOutputFormat);
976}
977
978void CCodec::initiateCreateInputSurface() {
979 status_t err = [this] {
980 Mutexed<State>::Locked state(mState);
981 if (state->get() != ALLOCATED) {
982 return UNKNOWN_ERROR;
983 }
984 // TODO: read it from intf() properly.
985 if (state->comp->getName().find("encoder") == std::string::npos) {
986 return INVALID_OPERATION;
987 }
988 return OK;
989 }();
990 if (err != OK) {
991 mCallback->onInputSurfaceCreationFailed(err);
992 return;
993 }
994
995 (new AMessage(kWhatCreateInputSurface, this))->post();
996}
997
Lajos Molnar47118272019-01-31 16:28:04 -0800998sp<PersistentSurface> CCodec::CreateOmxInputSurface() {
999 using namespace android::hardware::media::omx::V1_0;
1000 using namespace android::hardware::media::omx::V1_0::utils;
1001 using namespace android::hardware::graphics::bufferqueue::V1_0::utils;
1002 typedef android::hardware::media::omx::V1_0::Status OmxStatus;
1003 android::sp<IOmx> omx = IOmx::getService();
1004 typedef android::hardware::graphics::bufferqueue::V1_0::
1005 IGraphicBufferProducer HGraphicBufferProducer;
1006 typedef android::hardware::media::omx::V1_0::
1007 IGraphicBufferSource HGraphicBufferSource;
1008 OmxStatus s;
1009 android::sp<HGraphicBufferProducer> gbp;
1010 android::sp<HGraphicBufferSource> gbs;
1011 android::Return<void> transStatus = omx->createInputSurface(
1012 [&s, &gbp, &gbs](
1013 OmxStatus status,
1014 const android::sp<HGraphicBufferProducer>& producer,
1015 const android::sp<HGraphicBufferSource>& source) {
1016 s = status;
1017 gbp = producer;
1018 gbs = source;
1019 });
1020 if (transStatus.isOk() && s == OmxStatus::OK) {
1021 return new PersistentSurface(
1022 new H2BGraphicBufferProducer(gbp),
1023 sp<::android::IGraphicBufferSource>(new LWGraphicBufferSource(gbs)));
1024 }
1025
1026 return nullptr;
1027}
1028
1029sp<PersistentSurface> CCodec::CreateCompatibleInputSurface() {
1030 sp<PersistentSurface> surface(CreateInputSurface());
1031
1032 if (surface == nullptr) {
1033 surface = CreateOmxInputSurface();
1034 }
1035
1036 return surface;
1037}
1038
Pawin Vongmasa36653902018-11-15 00:10:25 -08001039void CCodec::createInputSurface() {
1040 status_t err;
1041 sp<IGraphicBufferProducer> bufferProducer;
1042
1043 sp<AMessage> inputFormat;
1044 sp<AMessage> outputFormat;
1045 {
1046 Mutexed<Config>::Locked config(mConfig);
1047 inputFormat = config->mInputFormat;
1048 outputFormat = config->mOutputFormat;
1049 }
1050
Lajos Molnar47118272019-01-31 16:28:04 -08001051 sp<PersistentSurface> persistentSurface = CreateCompatibleInputSurface();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001052
1053 if (persistentSurface->getHidlTarget()) {
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001054 sp<IInputSurface> hidlInputSurface = IInputSurface::castFrom(
Pawin Vongmasa36653902018-11-15 00:10:25 -08001055 persistentSurface->getHidlTarget());
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001056 if (!hidlInputSurface) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001057 ALOGE("Corrupted input surface");
1058 mCallback->onInputSurfaceCreationFailed(UNKNOWN_ERROR);
1059 return;
1060 }
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001061 std::shared_ptr<Codec2Client::InputSurface> inputSurface =
1062 std::make_shared<Codec2Client::InputSurface>(hidlInputSurface);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001063 err = setupInputSurface(std::make_shared<C2InputSurfaceWrapper>(
Pawin Vongmasa1c75a232019-01-09 04:41:52 -08001064 inputSurface));
1065 bufferProducer = inputSurface->getGraphicBufferProducer();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001066 } else {
1067 int32_t width = 0;
1068 (void)outputFormat->findInt32("width", &width);
1069 int32_t height = 0;
1070 (void)outputFormat->findInt32("height", &height);
1071 err = setupInputSurface(std::make_shared<GraphicBufferSourceWrapper>(
1072 persistentSurface->getBufferSource(), width, height));
1073 bufferProducer = persistentSurface->getBufferProducer();
1074 }
1075
1076 if (err != OK) {
1077 ALOGE("Failed to set up input surface: %d", err);
1078 mCallback->onInputSurfaceCreationFailed(err);
1079 return;
1080 }
1081
1082 mCallback->onInputSurfaceCreated(
1083 inputFormat,
1084 outputFormat,
1085 new BufferProducerWrapper(bufferProducer));
1086}
1087
1088status_t CCodec::setupInputSurface(const std::shared_ptr<InputSurfaceWrapper> &surface) {
1089 Mutexed<Config>::Locked config(mConfig);
1090 config->mUsingSurface = true;
1091
1092 // we are now using surface - apply default color aspects to input format - as well as
1093 // get dataspace
1094 bool inputFormatChanged = config->updateFormats(config->IS_INPUT);
1095 ALOGD("input format %s to %s",
1096 inputFormatChanged ? "changed" : "unchanged",
1097 config->mInputFormat->debugString().c_str());
1098
1099 // configure dataspace
1100 static_assert(sizeof(int32_t) == sizeof(android_dataspace), "dataspace size mismatch");
1101 android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
1102 (void)config->mInputFormat->findInt32("android._dataspace", (int32_t*)&dataSpace);
1103 surface->setDataSpace(dataSpace);
1104
1105 status_t err = mChannel->setInputSurface(surface);
1106 if (err != OK) {
1107 // undo input format update
1108 config->mUsingSurface = false;
1109 (void)config->updateFormats(config->IS_INPUT);
1110 return err;
1111 }
1112 config->mInputSurface = surface;
1113
1114 if (config->mISConfig) {
1115 surface->configure(*config->mISConfig);
1116 } else {
1117 ALOGD("ISConfig: no configuration");
1118 }
1119
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001120 return OK;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001121}
1122
1123void CCodec::initiateSetInputSurface(const sp<PersistentSurface> &surface) {
1124 sp<AMessage> msg = new AMessage(kWhatSetInputSurface, this);
1125 msg->setObject("surface", surface);
1126 msg->post();
1127}
1128
1129void CCodec::setInputSurface(const sp<PersistentSurface> &surface) {
1130 sp<AMessage> inputFormat;
1131 sp<AMessage> outputFormat;
1132 {
1133 Mutexed<Config>::Locked config(mConfig);
1134 inputFormat = config->mInputFormat;
1135 outputFormat = config->mOutputFormat;
1136 }
1137 auto hidlTarget = surface->getHidlTarget();
1138 if (hidlTarget) {
1139 sp<IInputSurface> inputSurface =
1140 IInputSurface::castFrom(hidlTarget);
1141 if (!inputSurface) {
1142 ALOGE("Failed to set input surface: Corrupted surface.");
1143 mCallback->onInputSurfaceDeclined(UNKNOWN_ERROR);
1144 return;
1145 }
1146 status_t err = setupInputSurface(std::make_shared<C2InputSurfaceWrapper>(
1147 std::make_shared<Codec2Client::InputSurface>(inputSurface)));
1148 if (err != OK) {
1149 ALOGE("Failed to set up input surface: %d", err);
1150 mCallback->onInputSurfaceDeclined(err);
1151 return;
1152 }
1153 } else {
1154 int32_t width = 0;
1155 (void)outputFormat->findInt32("width", &width);
1156 int32_t height = 0;
1157 (void)outputFormat->findInt32("height", &height);
1158 status_t err = setupInputSurface(std::make_shared<GraphicBufferSourceWrapper>(
1159 surface->getBufferSource(), width, height));
1160 if (err != OK) {
1161 ALOGE("Failed to set up input surface: %d", err);
1162 mCallback->onInputSurfaceDeclined(err);
1163 return;
1164 }
1165 }
1166 mCallback->onInputSurfaceAccepted(inputFormat, outputFormat);
1167}
1168
1169void CCodec::initiateStart() {
1170 auto setStarting = [this] {
1171 Mutexed<State>::Locked state(mState);
1172 if (state->get() != ALLOCATED) {
1173 return UNKNOWN_ERROR;
1174 }
1175 state->set(STARTING);
1176 return OK;
1177 };
1178 if (tryAndReportOnError(setStarting) != OK) {
1179 return;
1180 }
1181
1182 (new AMessage(kWhatStart, this))->post();
1183}
1184
1185void CCodec::start() {
1186 std::shared_ptr<Codec2Client::Component> comp;
1187 auto checkStarting = [this, &comp] {
1188 Mutexed<State>::Locked state(mState);
1189 if (state->get() != STARTING) {
1190 return UNKNOWN_ERROR;
1191 }
1192 comp = state->comp;
1193 return OK;
1194 };
1195 if (tryAndReportOnError(checkStarting) != OK) {
1196 return;
1197 }
1198
1199 c2_status_t err = comp->start();
1200 if (err != C2_OK) {
1201 mCallback->onError(toStatusT(err, C2_OPERATION_Component_start),
1202 ACTION_CODE_FATAL);
1203 return;
1204 }
1205 sp<AMessage> inputFormat;
1206 sp<AMessage> outputFormat;
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001207 status_t err2 = OK;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001208 {
1209 Mutexed<Config>::Locked config(mConfig);
1210 inputFormat = config->mInputFormat;
1211 outputFormat = config->mOutputFormat;
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001212 if (config->mInputSurface) {
1213 err2 = config->mInputSurface->start();
1214 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001215 }
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001216 if (err2 != OK) {
1217 mCallback->onError(err2, ACTION_CODE_FATAL);
1218 return;
1219 }
1220 err2 = mChannel->start(inputFormat, outputFormat);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001221 if (err2 != OK) {
1222 mCallback->onError(err2, ACTION_CODE_FATAL);
1223 return;
1224 }
1225
1226 auto setRunning = [this] {
1227 Mutexed<State>::Locked state(mState);
1228 if (state->get() != STARTING) {
1229 return UNKNOWN_ERROR;
1230 }
1231 state->set(RUNNING);
1232 return OK;
1233 };
1234 if (tryAndReportOnError(setRunning) != OK) {
1235 return;
1236 }
1237 mCallback->onStartCompleted();
1238
1239 (void)mChannel->requestInitialInputBuffers();
1240}
1241
1242void CCodec::initiateShutdown(bool keepComponentAllocated) {
1243 if (keepComponentAllocated) {
1244 initiateStop();
1245 } else {
1246 initiateRelease();
1247 }
1248}
1249
1250void CCodec::initiateStop() {
1251 {
1252 Mutexed<State>::Locked state(mState);
1253 if (state->get() == ALLOCATED
1254 || state->get() == RELEASED
1255 || state->get() == STOPPING
1256 || state->get() == RELEASING) {
1257 // We're already stopped, released, or doing it right now.
1258 state.unlock();
1259 mCallback->onStopCompleted();
1260 state.lock();
1261 return;
1262 }
1263 state->set(STOPPING);
1264 }
1265
1266 mChannel->stop();
1267 (new AMessage(kWhatStop, this))->post();
1268}
1269
1270void CCodec::stop() {
1271 std::shared_ptr<Codec2Client::Component> comp;
1272 {
1273 Mutexed<State>::Locked state(mState);
1274 if (state->get() == RELEASING) {
1275 state.unlock();
1276 // We're already stopped or release is in progress.
1277 mCallback->onStopCompleted();
1278 state.lock();
1279 return;
1280 } else if (state->get() != STOPPING) {
1281 state.unlock();
1282 mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
1283 state.lock();
1284 return;
1285 }
1286 comp = state->comp;
1287 }
1288 status_t err = comp->stop();
1289 if (err != C2_OK) {
1290 // TODO: convert err into status_t
1291 mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
1292 }
1293
1294 {
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001295 Mutexed<Config>::Locked config(mConfig);
1296 if (config->mInputSurface) {
1297 config->mInputSurface->disconnect();
1298 config->mInputSurface = nullptr;
1299 }
1300 }
1301 {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001302 Mutexed<State>::Locked state(mState);
1303 if (state->get() == STOPPING) {
1304 state->set(ALLOCATED);
1305 }
1306 }
1307 mCallback->onStopCompleted();
1308}
1309
1310void CCodec::initiateRelease(bool sendCallback /* = true */) {
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001311 bool clearInputSurfaceIfNeeded = false;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001312 {
1313 Mutexed<State>::Locked state(mState);
1314 if (state->get() == RELEASED || state->get() == RELEASING) {
1315 // We're already released or doing it right now.
1316 if (sendCallback) {
1317 state.unlock();
1318 mCallback->onReleaseCompleted();
1319 state.lock();
1320 }
1321 return;
1322 }
1323 if (state->get() == ALLOCATING) {
1324 state->set(RELEASING);
1325 // With the altered state allocate() would fail and clean up.
1326 if (sendCallback) {
1327 state.unlock();
1328 mCallback->onReleaseCompleted();
1329 state.lock();
1330 }
1331 return;
1332 }
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001333 if (state->get() == STARTING
1334 || state->get() == RUNNING
1335 || state->get() == STOPPING) {
1336 // Input surface may have been started, so clean up is needed.
1337 clearInputSurfaceIfNeeded = true;
1338 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001339 state->set(RELEASING);
1340 }
1341
Pawin Vongmasa1f213362019-01-24 06:59:16 -08001342 if (clearInputSurfaceIfNeeded) {
1343 Mutexed<Config>::Locked config(mConfig);
1344 if (config->mInputSurface) {
1345 config->mInputSurface->disconnect();
1346 config->mInputSurface = nullptr;
1347 }
1348 }
1349
Pawin Vongmasa36653902018-11-15 00:10:25 -08001350 mChannel->stop();
1351 // thiz holds strong ref to this while the thread is running.
1352 sp<CCodec> thiz(this);
1353 std::thread([thiz, sendCallback] { thiz->release(sendCallback); }).detach();
1354}
1355
1356void CCodec::release(bool sendCallback) {
1357 std::shared_ptr<Codec2Client::Component> comp;
1358 {
1359 Mutexed<State>::Locked state(mState);
1360 if (state->get() == RELEASED) {
1361 if (sendCallback) {
1362 state.unlock();
1363 mCallback->onReleaseCompleted();
1364 state.lock();
1365 }
1366 return;
1367 }
1368 comp = state->comp;
1369 }
1370 comp->release();
1371
1372 {
1373 Mutexed<State>::Locked state(mState);
1374 state->set(RELEASED);
1375 state->comp.reset();
1376 }
1377 if (sendCallback) {
1378 mCallback->onReleaseCompleted();
1379 }
1380}
1381
1382status_t CCodec::setSurface(const sp<Surface> &surface) {
1383 return mChannel->setSurface(surface);
1384}
1385
1386void CCodec::signalFlush() {
1387 status_t err = [this] {
1388 Mutexed<State>::Locked state(mState);
1389 if (state->get() == FLUSHED) {
1390 return ALREADY_EXISTS;
1391 }
1392 if (state->get() != RUNNING) {
1393 return UNKNOWN_ERROR;
1394 }
1395 state->set(FLUSHING);
1396 return OK;
1397 }();
1398 switch (err) {
1399 case ALREADY_EXISTS:
1400 mCallback->onFlushCompleted();
1401 return;
1402 case OK:
1403 break;
1404 default:
1405 mCallback->onError(err, ACTION_CODE_FATAL);
1406 return;
1407 }
1408
1409 mChannel->stop();
1410 (new AMessage(kWhatFlush, this))->post();
1411}
1412
1413void CCodec::flush() {
1414 std::shared_ptr<Codec2Client::Component> comp;
1415 auto checkFlushing = [this, &comp] {
1416 Mutexed<State>::Locked state(mState);
1417 if (state->get() != FLUSHING) {
1418 return UNKNOWN_ERROR;
1419 }
1420 comp = state->comp;
1421 return OK;
1422 };
1423 if (tryAndReportOnError(checkFlushing) != OK) {
1424 return;
1425 }
1426
1427 std::list<std::unique_ptr<C2Work>> flushedWork;
1428 c2_status_t err = comp->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
1429 {
1430 Mutexed<std::list<std::unique_ptr<C2Work>>>::Locked queue(mWorkDoneQueue);
1431 flushedWork.splice(flushedWork.end(), *queue);
1432 }
1433 if (err != C2_OK) {
1434 // TODO: convert err into status_t
1435 mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
1436 }
1437
1438 mChannel->flush(flushedWork);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001439
1440 {
1441 Mutexed<State>::Locked state(mState);
1442 state->set(FLUSHED);
1443 }
1444 mCallback->onFlushCompleted();
1445}
1446
1447void CCodec::signalResume() {
1448 auto setResuming = [this] {
1449 Mutexed<State>::Locked state(mState);
1450 if (state->get() != FLUSHED) {
1451 return UNKNOWN_ERROR;
1452 }
1453 state->set(RESUMING);
1454 return OK;
1455 };
1456 if (tryAndReportOnError(setResuming) != OK) {
1457 return;
1458 }
1459
1460 (void)mChannel->start(nullptr, nullptr);
1461
1462 {
1463 Mutexed<State>::Locked state(mState);
1464 if (state->get() != RESUMING) {
1465 state.unlock();
1466 mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
1467 state.lock();
1468 return;
1469 }
1470 state->set(RUNNING);
1471 }
1472
1473 (void)mChannel->requestInitialInputBuffers();
1474}
1475
Wonsik Kimaa484ac2019-02-13 16:54:02 -08001476void CCodec::signalSetParameters(const sp<AMessage> &msg) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001477 std::shared_ptr<Codec2Client::Component> comp;
1478 auto checkState = [this, &comp] {
1479 Mutexed<State>::Locked state(mState);
1480 if (state->get() == RELEASED) {
1481 return INVALID_OPERATION;
1482 }
1483 comp = state->comp;
1484 return OK;
1485 };
1486 if (tryAndReportOnError(checkState) != OK) {
1487 return;
1488 }
1489
Wonsik Kimaa484ac2019-02-13 16:54:02 -08001490 // NOTE: We used to ignore "bitrate" at setParameters; replicate
1491 // the behavior here.
1492 sp<AMessage> params = msg;
1493 int32_t bitrate;
1494 if (params->findInt32(KEY_BIT_RATE, &bitrate)) {
1495 params = msg->dup();
1496 params->removeEntryAt(params->findEntryByName(KEY_BIT_RATE));
1497 }
1498
Pawin Vongmasa36653902018-11-15 00:10:25 -08001499 Mutexed<Config>::Locked config(mConfig);
1500
1501 /**
1502 * Handle input surface parameters
1503 */
1504 if ((config->mDomain & (Config::IS_VIDEO | Config::IS_IMAGE))
1505 && (config->mDomain & Config::IS_ENCODER) && config->mInputSurface && config->mISConfig) {
Chong Zhang038e8f82019-02-06 19:05:14 -08001506 (void)params->findInt64(PARAMETER_KEY_OFFSET_TIME, &config->mISConfig->mTimeOffsetUs);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001507
1508 if (params->findInt64("skip-frames-before", &config->mISConfig->mStartAtUs)) {
1509 config->mISConfig->mStopped = false;
1510 } else if (params->findInt64("stop-time-us", &config->mISConfig->mStopAtUs)) {
1511 config->mISConfig->mStopped = true;
1512 }
1513
1514 int32_t value;
Chong Zhang038e8f82019-02-06 19:05:14 -08001515 if (params->findInt32(PARAMETER_KEY_SUSPEND, &value)) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001516 config->mISConfig->mSuspended = value;
1517 config->mISConfig->mSuspendAtUs = -1;
Chong Zhang038e8f82019-02-06 19:05:14 -08001518 (void)params->findInt64(PARAMETER_KEY_SUSPEND_TIME, &config->mISConfig->mSuspendAtUs);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001519 }
1520
1521 (void)config->mInputSurface->configure(*config->mISConfig);
1522 if (config->mISConfig->mStopped) {
1523 config->mInputFormat->setInt64(
1524 "android._stop-time-offset-us", config->mISConfig->mInputDelayUs);
1525 }
1526 }
1527
1528 std::vector<std::unique_ptr<C2Param>> configUpdate;
1529 (void)config->getConfigUpdateFromSdkParams(
1530 comp, params, Config::IS_PARAM, C2_MAY_BLOCK, &configUpdate);
1531 // Prefer to pass parameters to the buffer channel, so they can be synchronized with the frames.
1532 // Parameter synchronization is not defined when using input surface. For now, route
1533 // these directly to the component.
1534 if (config->mInputSurface == nullptr
1535 && (property_get_bool("debug.stagefright.ccodec_delayed_params", false)
1536 || comp->getName().find("c2.android.") == 0)) {
1537 mChannel->setParameters(configUpdate);
1538 } else {
1539 (void)config->setParameters(comp, configUpdate, C2_MAY_BLOCK);
1540 }
1541}
1542
1543void CCodec::signalEndOfInputStream() {
1544 mCallback->onSignaledInputEOS(mChannel->signalEndOfInputStream());
1545}
1546
1547void CCodec::signalRequestIDRFrame() {
1548 std::shared_ptr<Codec2Client::Component> comp;
1549 {
1550 Mutexed<State>::Locked state(mState);
1551 if (state->get() == RELEASED) {
1552 ALOGD("no IDR request sent since component is released");
1553 return;
1554 }
1555 comp = state->comp;
1556 }
1557 ALOGV("request IDR");
1558 Mutexed<Config>::Locked config(mConfig);
1559 std::vector<std::unique_ptr<C2Param>> params;
1560 params.push_back(
1561 std::make_unique<C2StreamRequestSyncFrameTuning::output>(0u, true));
1562 config->setParameters(comp, params, C2_MAY_BLOCK);
1563}
1564
Wonsik Kimab34ed62019-01-31 15:28:46 -08001565void CCodec::onWorkDone(std::list<std::unique_ptr<C2Work>> &workItems) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001566 if (!workItems.empty()) {
Wonsik Kimab34ed62019-01-31 15:28:46 -08001567 Mutexed<std::list<std::unique_ptr<C2Work>>>::Locked queue(mWorkDoneQueue);
1568 queue->splice(queue->end(), workItems);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001569 }
1570 (new AMessage(kWhatWorkDone, this))->post();
1571}
1572
Wonsik Kimab34ed62019-01-31 15:28:46 -08001573void CCodec::onInputBufferDone(uint64_t frameIndex, size_t arrayIndex) {
1574 mChannel->onInputBufferDone(frameIndex, arrayIndex);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001575}
1576
1577void CCodec::onMessageReceived(const sp<AMessage> &msg) {
1578 TimePoint now = std::chrono::steady_clock::now();
1579 CCodecWatchdog::getInstance()->watch(this);
1580 switch (msg->what()) {
1581 case kWhatAllocate: {
1582 // C2ComponentStore::createComponent() should return within 100ms.
1583 setDeadline(now, 150ms, "allocate");
1584 sp<RefBase> obj;
1585 CHECK(msg->findObject("codecInfo", &obj));
1586 allocate((MediaCodecInfo *)obj.get());
1587 break;
1588 }
1589 case kWhatConfigure: {
1590 // C2Component::commit_sm() should return within 5ms.
1591 setDeadline(now, 250ms, "configure");
1592 sp<AMessage> format;
1593 CHECK(msg->findMessage("format", &format));
1594 configure(format);
1595 break;
1596 }
1597 case kWhatStart: {
1598 // C2Component::start() should return within 500ms.
1599 setDeadline(now, 550ms, "start");
Pawin Vongmasa36653902018-11-15 00:10:25 -08001600 start();
1601 break;
1602 }
1603 case kWhatStop: {
1604 // C2Component::stop() should return within 500ms.
1605 setDeadline(now, 550ms, "stop");
1606 stop();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001607 break;
1608 }
1609 case kWhatFlush: {
1610 // C2Component::flush_sm() should return within 5ms.
1611 setDeadline(now, 50ms, "flush");
1612 flush();
1613 break;
1614 }
1615 case kWhatCreateInputSurface: {
1616 // Surface operations may be briefly blocking.
1617 setDeadline(now, 100ms, "createInputSurface");
1618 createInputSurface();
1619 break;
1620 }
1621 case kWhatSetInputSurface: {
1622 // Surface operations may be briefly blocking.
1623 setDeadline(now, 100ms, "setInputSurface");
1624 sp<RefBase> obj;
1625 CHECK(msg->findObject("surface", &obj));
1626 sp<PersistentSurface> surface(static_cast<PersistentSurface *>(obj.get()));
1627 setInputSurface(surface);
1628 break;
1629 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001630 case kWhatWorkDone: {
1631 std::unique_ptr<C2Work> work;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001632 bool shouldPost = false;
1633 {
1634 Mutexed<std::list<std::unique_ptr<C2Work>>>::Locked queue(mWorkDoneQueue);
1635 if (queue->empty()) {
1636 break;
1637 }
1638 work.swap(queue->front());
1639 queue->pop_front();
1640 shouldPost = !queue->empty();
1641 }
Pawin Vongmasa36653902018-11-15 00:10:25 -08001642 if (shouldPost) {
1643 (new AMessage(kWhatWorkDone, this))->post();
1644 }
1645
Pawin Vongmasa36653902018-11-15 00:10:25 -08001646 // handle configuration changes in work done
1647 Mutexed<Config>::Locked config(mConfig);
1648 bool changed = false;
1649 Config::Watcher<C2StreamInitDataInfo::output> initData =
1650 config->watch<C2StreamInitDataInfo::output>();
1651 if (!work->worklets.empty()
1652 && (work->worklets.front()->output.flags
1653 & C2FrameData::FLAG_DISCARD_FRAME) == 0) {
1654
1655 // copy buffer info to config
1656 std::vector<std::unique_ptr<C2Param>> updates =
1657 std::move(work->worklets.front()->output.configUpdate);
1658 unsigned stream = 0;
1659 for (const std::shared_ptr<C2Buffer> &buf : work->worklets.front()->output.buffers) {
1660 for (const std::shared_ptr<const C2Info> &info : buf->info()) {
1661 // move all info into output-stream #0 domain
1662 updates.emplace_back(C2Param::CopyAsStream(*info, true /* output */, stream));
1663 }
1664 for (const C2ConstGraphicBlock &block : buf->data().graphicBlocks()) {
1665 // ALOGV("got output buffer with crop %u,%u+%u,%u and size %u,%u",
1666 // block.crop().left, block.crop().top,
1667 // block.crop().width, block.crop().height,
1668 // block.width(), block.height());
1669 updates.emplace_back(new C2StreamCropRectInfo::output(stream, block.crop()));
1670 updates.emplace_back(new C2StreamPictureSizeInfo::output(
1671 stream, block.width(), block.height()));
1672 break; // for now only do the first block
1673 }
1674 ++stream;
1675 }
1676
1677 changed = config->updateConfiguration(updates, config->mOutputDomain);
1678
1679 // copy standard infos to graphic buffers if not already present (otherwise, we
1680 // may overwrite the actual intermediate value with a final value)
1681 stream = 0;
1682 const static std::vector<C2Param::Index> stdGfxInfos = {
1683 C2StreamRotationInfo::output::PARAM_TYPE,
1684 C2StreamColorAspectsInfo::output::PARAM_TYPE,
1685 C2StreamDataSpaceInfo::output::PARAM_TYPE,
1686 C2StreamHdrStaticInfo::output::PARAM_TYPE,
Pawin Vongmasa8be93112018-12-11 14:01:42 -08001687 C2StreamHdr10PlusInfo::output::PARAM_TYPE,
Pawin Vongmasa36653902018-11-15 00:10:25 -08001688 C2StreamPixelAspectRatioInfo::output::PARAM_TYPE,
1689 C2StreamSurfaceScalingInfo::output::PARAM_TYPE
1690 };
1691 for (const std::shared_ptr<C2Buffer> &buf : work->worklets.front()->output.buffers) {
1692 if (buf->data().graphicBlocks().size()) {
1693 for (C2Param::Index ix : stdGfxInfos) {
1694 if (!buf->hasInfo(ix)) {
1695 const C2Param *param =
1696 config->getConfigParameterValue(ix.withStream(stream));
1697 if (param) {
1698 std::shared_ptr<C2Param> info(C2Param::Copy(*param));
1699 buf->setInfo(std::static_pointer_cast<C2Info>(info));
1700 }
1701 }
1702 }
1703 }
1704 ++stream;
1705 }
1706 }
1707 mChannel->onWorkDone(
1708 std::move(work), changed ? config->mOutputFormat : nullptr,
Wonsik Kimab34ed62019-01-31 15:28:46 -08001709 initData.hasChanged() ? initData.update().get() : nullptr);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001710 break;
1711 }
1712 case kWhatWatch: {
1713 // watch message already posted; no-op.
1714 break;
1715 }
1716 default: {
1717 ALOGE("unrecognized message");
1718 break;
1719 }
1720 }
1721 setDeadline(TimePoint::max(), 0ms, "none");
1722}
1723
1724void CCodec::setDeadline(
1725 const TimePoint &now,
1726 const std::chrono::milliseconds &timeout,
1727 const char *name) {
1728 int32_t mult = std::max(1, property_get_int32("debug.stagefright.ccodec_timeout_mult", 1));
1729 Mutexed<NamedTimePoint>::Locked deadline(mDeadline);
1730 deadline->set(now + (timeout * mult), name);
1731}
1732
1733void CCodec::initiateReleaseIfStuck() {
1734 std::string name;
1735 bool pendingDeadline = false;
Wonsik Kimab34ed62019-01-31 15:28:46 -08001736 {
1737 Mutexed<NamedTimePoint>::Locked deadline(mDeadline);
Pawin Vongmasa36653902018-11-15 00:10:25 -08001738 if (deadline->get() < std::chrono::steady_clock::now()) {
1739 name = deadline->getName();
Pawin Vongmasa36653902018-11-15 00:10:25 -08001740 }
1741 if (deadline->get() != TimePoint::max()) {
1742 pendingDeadline = true;
1743 }
1744 }
1745 if (name.empty()) {
Wonsik Kimab34ed62019-01-31 15:28:46 -08001746 constexpr std::chrono::steady_clock::duration kWorkDurationThreshold = 3s;
1747 std::chrono::steady_clock::duration elapsed = mChannel->elapsed();
1748 if (elapsed >= kWorkDurationThreshold) {
1749 name = "queue";
1750 }
1751 if (elapsed > 0s) {
1752 pendingDeadline = true;
1753 }
1754 }
1755 if (name.empty()) {
Pawin Vongmasa36653902018-11-15 00:10:25 -08001756 // We're not stuck.
1757 if (pendingDeadline) {
1758 // If we are not stuck yet but still has deadline coming up,
1759 // post watch message to check back later.
1760 (new AMessage(kWhatWatch, this))->post();
1761 }
1762 return;
1763 }
1764
1765 ALOGW("previous call to %s exceeded timeout", name.c_str());
1766 initiateRelease(false);
1767 mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
1768}
1769
Pawin Vongmasa36653902018-11-15 00:10:25 -08001770} // namespace android
1771
1772extern "C" android::CodecBase *CreateCodec() {
1773 return new android::CCodec;
1774}
1775
Lajos Molnar47118272019-01-31 16:28:04 -08001776// Create Codec 2.0 input surface
Pawin Vongmasa36653902018-11-15 00:10:25 -08001777extern "C" android::PersistentSurface *CreateInputSurface() {
1778 // Attempt to create a Codec2's input surface.
1779 std::shared_ptr<android::Codec2Client::InputSurface> inputSurface =
1780 android::Codec2Client::CreateInputSurface();
Lajos Molnar47118272019-01-31 16:28:04 -08001781 if (!inputSurface) {
1782 return nullptr;
Pawin Vongmasa36653902018-11-15 00:10:25 -08001783 }
Lajos Molnar47118272019-01-31 16:28:04 -08001784 return new android::PersistentSurface(
1785 inputSurface->getGraphicBufferProducer(),
1786 static_cast<android::sp<android::hidl::base::V1_0::IBase>>(
1787 inputSurface->getHalInterface()));
Pawin Vongmasa36653902018-11-15 00:10:25 -08001788}
1789