1 /*
2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #define MEDIA_PIPELINE
17
18 #include <sys/time.h>
19 #include "filter/filter_factory.h"
20 #include "plugin/plugin_time.h"
21 #include "avcodec_errors.h"
22 #include "common/log.h"
23 #include "common/media_core.h"
24 #include "avcodec_info.h"
25 #include "avcodec_common.h"
26 #include "avcodec_errors.h"
27 #include "avcodec_list.h"
28 #include "video_decoder_adapter.h"
29 #include "decoder_surface_filter.h"
30 #include "osal/utils/util.h"
31 #include "parameters.h"
32
33 namespace {
34 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "DecoderSurfaceFilter" };
35 }
36
37 namespace OHOS {
38 namespace Media {
39 namespace Pipeline {
40 static const int64_t PLAY_RANGE_DEFAULT_VALUE = -1;
41 static const int64_t MICROSECONDS_CONVERT_UNIT = 1000; // ms change to us
42 static const uint32_t PREROLL_WAIT_TIME = 1000; // Lock wait for 1000ms.
43
44 static AutoRegisterFilter<DecoderSurfaceFilter> g_registerDecoderSurfaceFilter("builtin.player.videodecoder",
__anon84d9a2e10202(const std::string& name, const FilterType type) 45 FilterType::FILTERTYPE_VDEC, [](const std::string& name, const FilterType type) {
46 return std::make_shared<DecoderSurfaceFilter>(name, FilterType::FILTERTYPE_VDEC);
47 });
48
49 static const bool IS_FILTER_ASYNC = system::GetParameter("persist.media_service.async_filter", "1") == "1";
50
51 static const std::string VIDEO_INPUT_BUFFER_QUEUE_NAME = "VideoDecoderInputBufferQueue";
52
53 class DecoderSurfaceFilterLinkCallback : public FilterLinkCallback {
54 public:
DecoderSurfaceFilterLinkCallback(std::shared_ptr<DecoderSurfaceFilter> decoderSurfaceFilter)55 explicit DecoderSurfaceFilterLinkCallback(std::shared_ptr<DecoderSurfaceFilter> decoderSurfaceFilter)
56 : decoderSurfaceFilter_(decoderSurfaceFilter) {}
57
58 ~DecoderSurfaceFilterLinkCallback() = default;
59
OnLinkedResult(const sptr<AVBufferQueueProducer> & queue,std::shared_ptr<Meta> & meta)60 void OnLinkedResult(const sptr<AVBufferQueueProducer> &queue, std::shared_ptr<Meta> &meta) override
61 {
62 MEDIA_LOG_I("OnLinkedResult enter.");
63 decoderSurfaceFilter_->OnLinkedResult(queue, meta);
64 }
65
OnUnlinkedResult(std::shared_ptr<Meta> & meta)66 void OnUnlinkedResult(std::shared_ptr<Meta> &meta) override
67 {
68 decoderSurfaceFilter_->OnUnlinkedResult(meta);
69 }
70
OnUpdatedResult(std::shared_ptr<Meta> & meta)71 void OnUpdatedResult(std::shared_ptr<Meta> &meta) override
72 {
73 decoderSurfaceFilter_->OnUpdatedResult(meta);
74 }
75 private:
76 std::shared_ptr<DecoderSurfaceFilter> decoderSurfaceFilter_;
77 };
78
79 const std::unordered_map<VideoScaleType, OHOS::ScalingMode> SCALEMODE_MAP = {
80 { VideoScaleType::VIDEO_SCALE_TYPE_FIT, OHOS::SCALING_MODE_SCALE_TO_WINDOW },
81 { VideoScaleType::VIDEO_SCALE_TYPE_FIT_CROP, OHOS::SCALING_MODE_SCALE_CROP},
82 };
83
84 class FilterMediaCodecCallback : public OHOS::MediaAVCodec::MediaCodecCallback {
85 public:
FilterMediaCodecCallback(std::shared_ptr<DecoderSurfaceFilter> decoderSurfaceFilter)86 explicit FilterMediaCodecCallback(std::shared_ptr<DecoderSurfaceFilter> decoderSurfaceFilter)
87 : decoderSurfaceFilter_(decoderSurfaceFilter) {}
88
89 ~FilterMediaCodecCallback() = default;
90
OnError(MediaAVCodec::AVCodecErrorType errorType,int32_t errorCode)91 void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode) override
92 {
93 if (auto decoderSurfaceFilter = decoderSurfaceFilter_.lock()) {
94 decoderSurfaceFilter->OnError(errorType, errorCode);
95 } else {
96 MEDIA_LOG_I("invalid decoderSurfaceFilter");
97 }
98 }
99
OnOutputFormatChanged(const MediaAVCodec::Format & format)100 void OnOutputFormatChanged(const MediaAVCodec::Format &format) override
101 {
102 if (auto decoderSurfaceFilter = decoderSurfaceFilter_.lock()) {
103 decoderSurfaceFilter->OnOutputFormatChanged(format);
104 } else {
105 MEDIA_LOG_I("invalid decoderSurfaceFilter");
106 }
107 }
108
OnInputBufferAvailable(uint32_t index,std::shared_ptr<AVBuffer> buffer)109 void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override
110 {
111 }
112
OnOutputBufferAvailable(uint32_t index,std::shared_ptr<AVBuffer> buffer)113 void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override
114 {
115 if (auto decoderSurfaceFilter = decoderSurfaceFilter_.lock()) {
116 decoderSurfaceFilter->DrainOutputBuffer(index, buffer);
117 } else {
118 MEDIA_LOG_I("invalid decoderSurfaceFilter");
119 }
120 }
121
122 private:
123 std::weak_ptr<DecoderSurfaceFilter> decoderSurfaceFilter_;
124 };
125
126 class AVBufferAvailableListener : public OHOS::Media::IConsumerListener {
127 public:
AVBufferAvailableListener(std::shared_ptr<DecoderSurfaceFilter> decoderSurfaceFilter)128 explicit AVBufferAvailableListener(std::shared_ptr<DecoderSurfaceFilter> decoderSurfaceFilter)
129 {
130 decoderSurfaceFilter_ = decoderSurfaceFilter;
131 }
132 ~AVBufferAvailableListener() = default;
133
OnBufferAvailable()134 void OnBufferAvailable()
135 {
136 if (auto decoderSurfaceFilter = decoderSurfaceFilter_.lock()) {
137 decoderSurfaceFilter->HandleInputBuffer();
138 } else {
139 MEDIA_LOG_I("invalid videoDecoder");
140 }
141 }
142
143 private:
144 std::weak_ptr<DecoderSurfaceFilter> decoderSurfaceFilter_;
145 };
146
DecoderSurfaceFilter(const std::string & name,FilterType type)147 DecoderSurfaceFilter::DecoderSurfaceFilter(const std::string& name, FilterType type)
148 : Filter(name, type, IS_FILTER_ASYNC)
149 {
150 videoDecoder_ = std::make_shared<VideoDecoderAdapter>();
151 videoSink_ = std::make_shared<VideoSink>();
152 filterType_ = type;
153 }
154
~DecoderSurfaceFilter()155 DecoderSurfaceFilter::~DecoderSurfaceFilter()
156 {
157 MEDIA_LOG_I("~DecoderSurfaceFilter() enter.");
158 if (!IS_FILTER_ASYNC && !isThreadExit_) {
159 isThreadExit_ = true;
160 condBufferAvailable_.notify_all();
161 if (readThread_ != nullptr && readThread_->joinable()) {
162 readThread_->join();
163 readThread_ = nullptr;
164 }
165 }
166 videoDecoder_->Release();
167 MEDIA_LOG_I("~DecoderSurfaceFilter() exit.");
168 }
169
OnError(MediaAVCodec::AVCodecErrorType errorType,int32_t errorCode)170 void DecoderSurfaceFilter::OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode)
171 {
172 MEDIA_LOG_E("AVCodec error happened. ErrorType: %{public}d, errorCode: %{public}d",
173 static_cast<int32_t>(errorType), errorCode);
174 if (eventReceiver_ != nullptr) {
175 eventReceiver_->OnEvent({"DecoderSurfaceFilter", EventType::EVENT_ERROR, MSERR_EXT_API9_IO});
176 }
177 }
178
Init(const std::shared_ptr<EventReceiver> & receiver,const std::shared_ptr<FilterCallback> & callback)179 void DecoderSurfaceFilter::Init(const std::shared_ptr<EventReceiver> &receiver,
180 const std::shared_ptr<FilterCallback> &callback)
181 {
182 MEDIA_LOG_I("Init enter.");
183 eventReceiver_ = receiver;
184 filterCallback_ = callback;
185 videoSink_->SetEventReceiver(eventReceiver_);
186 FALSE_RETURN(videoDecoder_ != nullptr);
187 videoDecoder_->SetEventReceiver(eventReceiver_);
188 }
189
Configure(const std::shared_ptr<Meta> & parameter)190 Status DecoderSurfaceFilter::Configure(const std::shared_ptr<Meta> ¶meter)
191 {
192 MEDIA_LOG_I("Configure enter.");
193 configureParameter_ = parameter;
194 configFormat_.SetMeta(configureParameter_);
195 Status ret = videoDecoder_->Configure(configFormat_);
196 std::shared_ptr<MediaAVCodec::MediaCodecCallback> mediaCodecCallback
197 = std::make_shared<FilterMediaCodecCallback>(shared_from_this());
198 videoDecoder_->SetCallback(mediaCodecCallback);
199 return ret;
200 }
201
DoInitAfterLink()202 Status DecoderSurfaceFilter::DoInitAfterLink()
203 {
204 Status ret;
205 // create secure decoder for drm.
206 MEDIA_LOG_I("DoInit enter the codecMimeType_ is %{public}s", codecMimeType_.c_str());
207 if (videoDecoder_ != nullptr) {
208 videoDecoder_->SetCallingInfo(appUid_, appPid_, bundleName_, instanceId_);
209 }
210 if (isDrmProtected_ && svpFlag_) {
211 MEDIA_LOG_D("DecoderSurfaceFilter will create secure decoder for drm-protected videos");
212 std::string baseName = GetCodecName(codecMimeType_);
213 FALSE_RETURN_V_MSG(!baseName.empty(),
214 Status::ERROR_INVALID_PARAMETER, "get name by mime failed.");
215 std::string secureDecoderName = baseName + ".secure";
216 MEDIA_LOG_D("DecoderSurfaceFilter will create secure decoder %{public}s", secureDecoderName.c_str());
217 ret = videoDecoder_->Init(MediaAVCodec::AVCodecType::AVCODEC_TYPE_VIDEO_DECODER, false, secureDecoderName);
218 } else {
219 ret = videoDecoder_->Init(MediaAVCodec::AVCodecType::AVCODEC_TYPE_VIDEO_DECODER, true, codecMimeType_);
220 }
221
222 if (ret != Status::OK && eventReceiver_ != nullptr) {
223 MEDIA_LOG_E("Init decoder fail ret = %{public}d", ret);
224 eventReceiver_->OnEvent({"decoderSurface", EventType::EVENT_ERROR, MSERR_UNSUPPORT_VID_DEC_TYPE});
225 return Status::ERROR_UNSUPPORTED_FORMAT;
226 }
227
228 ret = Configure(meta_);
229 if (ret != Status::OK) {
230 eventReceiver_->OnEvent({"decoderSurface", EventType::EVENT_ERROR, MSERR_UNSUPPORT_VID_SRC_TYPE});
231 return Status::ERROR_UNSUPPORTED_FORMAT;
232 }
233 ParseDecodeRateLimit();
234 videoDecoder_->SetOutputSurface(videoSurface_);
235 if (isDrmProtected_) {
236 videoDecoder_->SetDecryptConfig(keySessionServiceProxy_, svpFlag_);
237 }
238 videoSink_->SetParameter(meta_);
239 return Status::OK;
240 }
241
DoPrepare()242 Status DecoderSurfaceFilter::DoPrepare()
243 {
244 MEDIA_LOG_I("Prepare enter.");
245 if (onLinkedResultCallback_ != nullptr) {
246 videoDecoder_->PrepareInputBufferQueue();
247 sptr<IConsumerListener> listener = new AVBufferAvailableListener(shared_from_this());
248 sptr<Media::AVBufferQueueConsumer> inputBufferQueueConsumer = videoDecoder_->GetBufferQueueConsumer();
249 inputBufferQueueConsumer->SetBufferAvailableListener(listener);
250 onLinkedResultCallback_->OnLinkedResult(videoDecoder_->GetBufferQueueProducer(), meta_);
251 }
252 isRenderStarted_ = false;
253 return Status::OK;
254 }
255
HandleInputBuffer()256 Status DecoderSurfaceFilter::HandleInputBuffer()
257 {
258 ProcessInputBuffer();
259 return Status::OK;
260 }
261
DoStart()262 Status DecoderSurfaceFilter::DoStart()
263 {
264 MEDIA_LOG_I("Start enter.");
265 if (isPaused_.load()) {
266 MEDIA_LOG_I("DoStart after pause to execute resume.");
267 return DoResume();
268 }
269 if (!IS_FILTER_ASYNC) {
270 isThreadExit_ = false;
271 isPaused_ = false;
272 readThread_ = std::make_unique<std::thread>(&DecoderSurfaceFilter::RenderLoop, this);
273 pthread_setname_np(readThread_->native_handle(), "RenderLoop");
274 }
275 return videoDecoder_->Start();
276 }
277
DoPause()278 Status DecoderSurfaceFilter::DoPause()
279 {
280 MEDIA_LOG_I("Pause enter.");
281 isPaused_ = true;
282 isFirstFrameAfterResume_ = false;
283 if (!IS_FILTER_ASYNC) {
284 condBufferAvailable_.notify_all();
285 }
286 videoSink_->ResetSyncInfo();
287 latestPausedTime_ = latestBufferTime_;
288 if (videoDecoder_ != nullptr) {
289 videoDecoder_->ResetRenderTime();
290 }
291 return Status::OK;
292 }
293
DoPauseDragging()294 Status DecoderSurfaceFilter::DoPauseDragging()
295 {
296 MEDIA_LOG_I("DoPauseDragging enter.");
297 DoPause();
298 {
299 std::unique_lock<std::mutex> lock(mutex_);
300 if (!outputBufferMap_.empty()) {
301 MEDIA_LOG_E("DoPauseDragging outputBufferMap_ size = %{public}zu", outputBufferMap_.size());
302 for (auto it = outputBufferMap_.begin(); it != outputBufferMap_.end(); ++it) {
303 videoDecoder_->ReleaseOutputBuffer(it->first, false);
304 }
305 outputBufferMap_.clear();
306 }
307 }
308 return Status::OK;
309 }
310
DoResume()311 Status DecoderSurfaceFilter::DoResume()
312 {
313 MEDIA_LOG_I("Resume enter.");
314 refreshTotalPauseTime_ = true;
315 isPaused_ = false;
316 isFirstFrameAfterResume_ = true;
317 if (!IS_FILTER_ASYNC) {
318 condBufferAvailable_.notify_all();
319 }
320 videoDecoder_->Start();
321 return Status::OK;
322 }
323
DoResumeDragging()324 Status DecoderSurfaceFilter::DoResumeDragging()
325 {
326 MEDIA_LOG_I("DoResumeDragging enter.");
327 refreshTotalPauseTime_ = true;
328 isPaused_ = false;
329 if (!IS_FILTER_ASYNC) {
330 condBufferAvailable_.notify_all();
331 }
332 videoDecoder_->Start();
333 return Status::OK;
334 }
335
DoStop()336 Status DecoderSurfaceFilter::DoStop()
337 {
338 MEDIA_LOG_I("Stop enter.");
339 latestBufferTime_ = HST_TIME_NONE;
340 latestPausedTime_ = HST_TIME_NONE;
341 totalPausedTime_ = 0;
342 refreshTotalPauseTime_ = false;
343 isPaused_ = false;
344 playRangeStartTime_ = PLAY_RANGE_DEFAULT_VALUE;
345 playRangeEndTime_ = PLAY_RANGE_DEFAULT_VALUE;
346
347 timeval tv;
348 gettimeofday(&tv, 0);
349 stopTime_ = (int64_t)tv.tv_sec * 1000000 + (int64_t)tv.tv_usec; // 1000000 means transfering from s to us.
350 videoSink_->ResetSyncInfo();
351 auto ret = videoDecoder_->Stop();
352 if (!IS_FILTER_ASYNC && !isThreadExit_.load()) {
353 isThreadExit_ = true;
354 condBufferAvailable_.notify_all();
355 if (readThread_ != nullptr && readThread_->joinable()) {
356 readThread_->join();
357 readThread_ = nullptr;
358 }
359 }
360 return ret;
361 }
362
DoFlush()363 Status DecoderSurfaceFilter::DoFlush()
364 {
365 MEDIA_LOG_I("Flush enter.");
366 videoDecoder_->Flush();
367 {
368 std::lock_guard<std::mutex> lock(mutex_);
369 outputBuffers_.clear();
370 outputBufferMap_.clear();
371 }
372 videoSink_->ResetSyncInfo();
373 return Status::OK;
374 }
375
DoRelease()376 Status DecoderSurfaceFilter::DoRelease()
377 {
378 MEDIA_LOG_I("Release enter.");
379 videoDecoder_->Release();
380 return Status::OK;
381 }
382
DoPreroll()383 Status DecoderSurfaceFilter::DoPreroll()
384 {
385 MEDIA_LOG_I("DoPreroll enter.");
386 std::lock_guard<std::mutex> lock(prerollMutex_);
387 Status ret = Status::OK;
388 FALSE_RETURN_V_MSG(!inPreroll_.load(), Status::OK, "DoPreroll in preroll now.");
389 inPreroll_.store(true);
390 prerollDone_.store(false);
391 eosNext_.store(false);
392 if (isPaused_.load()) {
393 ret = DoResume();
394 } else {
395 ret = DoStart();
396 }
397 if (ret != Status::OK) {
398 MEDIA_LOG_E("video decoder start failed, ret = %{public}d", ret);
399 eventReceiver_->OnEvent({"decoderSurface", EventType::EVENT_ERROR,
400 MSERR_VID_DEC_FAILED});
401 }
402 Filter::StartFilterTask();
403 return ret;
404 }
405
DoWaitPrerollDone(bool render)406 Status DecoderSurfaceFilter::DoWaitPrerollDone(bool render)
407 {
408 MEDIA_LOG_I("DoWaitPrerollDone enter.");
409 std::unique_lock<std::mutex> lock(prerollMutex_);
410 FALSE_RETURN_V(inPreroll_.load(), Status::OK);
411 if (prerollDone_.load() || isInterruptNeeded_.load()) {
412 MEDIA_LOG_I("Receive preroll frame before DoWaitPrerollDone.");
413 } else {
414 prerollDoneCond_.wait_for(lock, std::chrono::milliseconds(PREROLL_WAIT_TIME),
415 [this] () { return prerollDone_.load() || isInterruptNeeded_.load(); });
416 }
417 Filter::PauseFilterTask();
418 DoPause();
419 if (!prerollDone_.load()) {
420 MEDIA_LOG_E("No preroll frame received!");
421 inPreroll_.store(false);
422 prerollDone_.store(true);
423 eosNext_.store(false);
424 return Status::OK;
425 }
426 std::unique_lock<std::mutex> bufferLock(mutex_);
427 if (render && !eosNext_.load() && !outputBuffers_.empty()) {
428 std::pair<int, std::shared_ptr<AVBuffer>> nextTask = std::move(outputBuffers_.front());
429 outputBuffers_.pop_front();
430 videoDecoder_->ReleaseOutputBuffer(nextTask.first, true);
431 }
432 eosNext_.store(false);
433 if (!outputBuffers_.empty()) {
434 Filter::ProcessOutputBuffer(1, 0);
435 }
436 inPreroll_.store(false);
437 return Status::OK;
438 }
439
DoSetPerfRecEnabled(bool isPerfRecEnabled)440 Status DecoderSurfaceFilter::DoSetPerfRecEnabled(bool isPerfRecEnabled)
441 {
442 isPerfRecEnabled_ = isPerfRecEnabled;
443 Status res = Status::OK;
444 if (videoSink_ != nullptr) {
445 res = videoSink_->SetPerfRecEnabled(isPerfRecEnabled);
446 }
447 if (videoDecoder_ != nullptr) {
448 res = videoDecoder_->SetPerfRecEnabled(isPerfRecEnabled);
449 }
450 return res;
451 }
452
DoSetPlayRange(int64_t start,int64_t end)453 Status DecoderSurfaceFilter::DoSetPlayRange(int64_t start, int64_t end)
454 {
455 MEDIA_LOG_I("DoSetPlayRange enter.");
456 playRangeStartTime_ = start;
457 playRangeEndTime_ = end;
458 return Status::OK;
459 }
460
ConvertMediaScaleType(VideoScaleType scaleType)461 static OHOS::ScalingMode ConvertMediaScaleType(VideoScaleType scaleType)
462 {
463 if (SCALEMODE_MAP.find(scaleType) == SCALEMODE_MAP.end()) {
464 return OHOS::SCALING_MODE_SCALE_CROP;
465 }
466 return SCALEMODE_MAP.at(scaleType);
467 }
468
SetParameter(const std::shared_ptr<Meta> & parameter)469 void DecoderSurfaceFilter::SetParameter(const std::shared_ptr<Meta> ¶meter)
470 {
471 MEDIA_LOG_I("SetParameter enter parameter is valid: %{public}i", parameter != nullptr);
472 Format format;
473 if (parameter->Find(Tag::VIDEO_SCALE_TYPE) != parameter->end()) {
474 int32_t scaleType;
475 parameter->Get<Tag::VIDEO_SCALE_TYPE>(scaleType);
476 int32_t codecScalingMode = static_cast<int32_t>(ConvertMediaScaleType(static_cast<VideoScaleType>(scaleType)));
477 format.PutIntValue(Tag::VIDEO_SCALE_TYPE, codecScalingMode);
478 configFormat_.PutIntValue(Tag::VIDEO_SCALE_TYPE, codecScalingMode);
479 }
480 if (parameter->Find(Tag::VIDEO_FRAME_RATE) != parameter->end()) {
481 double rate = 0.0;
482 parameter->Get<Tag::VIDEO_FRAME_RATE>(rate);
483 if (rate < 0) {
484 if (configFormat_.GetDoubleValue(Tag::VIDEO_FRAME_RATE, rate)) {
485 MEDIA_LOG_W("rate is invalid, get frame rate from the original resource: %{public}f", rate);
486 }
487 }
488 if (rate <= 0) {
489 rate = 30.0; // 30.0 is the hisi default frame rate.
490 }
491 format.PutDoubleValue(Tag::VIDEO_FRAME_RATE, rate);
492 }
493 // cannot set parameter when codec at [ CONFIGURED / INITIALIZED ] state
494 auto ret = videoDecoder_->SetParameter(format);
495 if (ret == MediaAVCodec::AVCS_ERR_INVALID_STATE) {
496 MEDIA_LOG_W("SetParameter at invalid state");
497 videoDecoder_->Reset();
498 if (!IS_FILTER_ASYNC && !isThreadExit_.load()) {
499 Stop();
500 }
501 videoDecoder_->Configure(configFormat_);
502 videoDecoder_->SetOutputSurface(videoSurface_);
503 if (isDrmProtected_) {
504 videoDecoder_->SetDecryptConfig(keySessionServiceProxy_, svpFlag_);
505 }
506 }
507 videoDecoder_->SetParameter(format);
508 }
509
GetLagInfo(int32_t & lagTimes,int32_t & maxLagDuration,int32_t & avgLagDuration)510 Status DecoderSurfaceFilter::GetLagInfo(int32_t& lagTimes, int32_t& maxLagDuration, int32_t& avgLagDuration)
511 {
512 FALSE_RETURN_V(videoSink_ != nullptr, Status::ERROR_INVALID_OPERATION);
513 videoSink_->GetLagInfo(lagTimes, maxLagDuration, avgLagDuration);
514 return Status::OK;
515 }
516
GetParameter(std::shared_ptr<Meta> & parameter)517 void DecoderSurfaceFilter::GetParameter(std::shared_ptr<Meta> ¶meter)
518 {
519 MEDIA_LOG_I("GetParameter enter parameter is valid: %{public}i", parameter != nullptr);
520 }
521
SetCallingInfo(int32_t appUid,int32_t appPid,const std::string & bundleName,uint64_t instanceId)522 void DecoderSurfaceFilter::SetCallingInfo(int32_t appUid, int32_t appPid, const std::string& bundleName,
523 uint64_t instanceId)
524 {
525 appUid_ = appUid;
526 appPid_ = appPid;
527 bundleName_ = bundleName;
528 instanceId_ = instanceId;
529 }
530
SetInterruptState(bool isInterruptNeeded)531 void DecoderSurfaceFilter::SetInterruptState(bool isInterruptNeeded)
532 {
533 std::lock_guard<std::mutex> lock(prerollMutex_);
534 isInterruptNeeded_ = isInterruptNeeded;
535 prerollDoneCond_.notify_all();
536 }
537
LinkNext(const std::shared_ptr<Filter> & nextFilter,StreamType outType)538 Status DecoderSurfaceFilter::LinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType)
539 {
540 MEDIA_LOG_I("LinkNext enter, nextFilter is valid: %{public}i, outType: %{public}u",
541 nextFilter != nullptr, static_cast<uint32_t>(outType));
542 return Status::OK;
543 }
544
UpdateNext(const std::shared_ptr<Filter> & nextFilter,StreamType outType)545 Status DecoderSurfaceFilter::UpdateNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType)
546 {
547 return Status::OK;
548 }
549
UnLinkNext(const std::shared_ptr<Filter> & nextFilter,StreamType outType)550 Status DecoderSurfaceFilter::UnLinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType)
551 {
552 return Status::OK;
553 }
554
GetFilterType()555 FilterType DecoderSurfaceFilter::GetFilterType()
556 {
557 return filterType_;
558 }
559
GetCodecName(std::string mimeType)560 std::string DecoderSurfaceFilter::GetCodecName(std::string mimeType)
561 {
562 MEDIA_LOG_I("GetCodecName.");
563 std::string codecName;
564 auto codeclist = MediaAVCodec::AVCodecListFactory::CreateAVCodecList();
565 if (codeclist == nullptr) {
566 MEDIA_LOG_E("GetCodecName failed due to codeclist nullptr.");
567 return codecName;
568 }
569 MediaAVCodec::Format format;
570 format.PutStringValue("codec_mime", mimeType);
571 codecName = codeclist->FindDecoder(format);
572 return codecName;
573 }
574
OnLinked(StreamType inType,const std::shared_ptr<Meta> & meta,const std::shared_ptr<FilterLinkCallback> & callback)575 Status DecoderSurfaceFilter::OnLinked(StreamType inType, const std::shared_ptr<Meta> &meta,
576 const std::shared_ptr<FilterLinkCallback> &callback)
577 {
578 MEDIA_LOG_I("OnLinked enter.");
579 meta_ = meta;
580 FALSE_RETURN_V_MSG(meta->GetData(Tag::MIME_TYPE, codecMimeType_),
581 Status::ERROR_INVALID_PARAMETER, "get mime failed.");
582 onLinkedResultCallback_ = callback;
583 return Status::OK;
584 }
585
OnUpdated(StreamType inType,const std::shared_ptr<Meta> & meta,const std::shared_ptr<FilterLinkCallback> & callback)586 Status DecoderSurfaceFilter::OnUpdated(StreamType inType, const std::shared_ptr<Meta> &meta,
587 const std::shared_ptr<FilterLinkCallback> &callback)
588 {
589 return Status::OK;
590 }
591
OnUnLinked(StreamType inType,const std::shared_ptr<FilterLinkCallback> & callback)592 Status DecoderSurfaceFilter::OnUnLinked(StreamType inType, const std::shared_ptr<FilterLinkCallback>& callback)
593 {
594 return Status::OK;
595 }
596
OnLinkedResult(const sptr<AVBufferQueueProducer> & outputBufferQueue,std::shared_ptr<Meta> & meta)597 void DecoderSurfaceFilter::OnLinkedResult(const sptr<AVBufferQueueProducer> &outputBufferQueue,
598 std::shared_ptr<Meta> &meta)
599 {
600 MEDIA_LOG_I("OnLinkedResult enter.");
601 }
602
OnUpdatedResult(std::shared_ptr<Meta> & meta)603 void DecoderSurfaceFilter::OnUpdatedResult(std::shared_ptr<Meta> &meta)
604 {
605 }
606
OnUnlinkedResult(std::shared_ptr<Meta> & meta)607 void DecoderSurfaceFilter::OnUnlinkedResult(std::shared_ptr<Meta> &meta)
608 {
609 }
610
DoProcessOutputBuffer(int recvArg,bool dropFrame,bool byIdx,uint32_t idx,int64_t renderTime)611 Status DecoderSurfaceFilter::DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx,
612 int64_t renderTime)
613 {
614 MEDIA_LOG_D("DoProcessOutputBuffer idx " PUBLIC_LOG_U32 " renderTime " PUBLIC_LOG_D64, idx, renderTime);
615 FALSE_RETURN_V(!dropFrame, Status::OK);
616 uint32_t index = idx;
617 std::shared_ptr<AVBuffer> outputBuffer = nullptr;
618 bool acquireRes = AcquireNextRenderBuffer(byIdx, index, outputBuffer);
619 FALSE_RETURN_V(acquireRes, Status::OK);
620 ReleaseOutputBuffer(index, recvArg, outputBuffer, renderTime);
621 return Status::OK;
622 }
623
AcquireNextRenderBuffer(bool byIdx,uint32_t & index,std::shared_ptr<AVBuffer> & outBuffer)624 bool DecoderSurfaceFilter::AcquireNextRenderBuffer(bool byIdx, uint32_t &index, std::shared_ptr<AVBuffer> &outBuffer)
625 {
626 std::unique_lock<std::mutex> lock(mutex_);
627 if (!byIdx) {
628 FALSE_RETURN_V(!outputBuffers_.empty(), false);
629 std::pair<int, std::shared_ptr<AVBuffer>> task = std::move(outputBuffers_.front());
630 outputBuffers_.pop_front();
631 FALSE_RETURN_V(task.first >= 0, false);
632 index = static_cast<uint32_t>(task.first);
633 outBuffer = task.second;
634 if (isFirstFrameAfterResume_) {
635 videoSink_->UpdateTimeAnchorActually(outBuffer);
636 isFirstFrameAfterResume_ = false;
637 }
638 if (!outputBuffers_.empty()) {
639 std::pair<int, std::shared_ptr<AVBuffer>> nextTask = outputBuffers_.front();
640 RenderNextOutput(nextTask.first, nextTask.second);
641 }
642 return true;
643 }
644 FALSE_RETURN_V(outputBufferMap_.find(index) != outputBufferMap_.end(), false);
645 outBuffer = outputBufferMap_[index];
646 outputBufferMap_.erase(index);
647 return true;
648 }
649
ReleaseOutputBuffer(int index,bool render,const std::shared_ptr<AVBuffer> & outBuffer,int64_t renderTime)650 Status DecoderSurfaceFilter::ReleaseOutputBuffer(int index, bool render, const std::shared_ptr<AVBuffer> &outBuffer,
651 int64_t renderTime)
652 {
653 if (!isRenderStarted_.load() && render && !(outBuffer->flag_ & (uint32_t)(Plugins::AVBufferFlag::EOS))
654 && !isInSeekContinous_) {
655 isRenderStarted_ = true;
656 if (eventReceiver_ != nullptr) {
657 eventReceiver_->OnEvent({"video_sink", EventType::EVENT_VIDEO_RENDERING_START, Status::OK});
658 }
659 }
660 if ((playRangeEndTime_ != PLAY_RANGE_DEFAULT_VALUE) &&
661 (outBuffer->pts_ > playRangeEndTime_ * MICROSECONDS_CONVERT_UNIT)) {
662 MEDIA_LOG_I("ReleaseBuffer for eos, SetPlayRange start: " PUBLIC_LOG_D64 ", end: " PUBLIC_LOG_D64,
663 playRangeStartTime_, playRangeEndTime_);
664 if (eventReceiver_ != nullptr) {
665 Event event {
666 .srcFilter = "VideoSink",
667 .type = EventType::EVENT_COMPLETE,
668 };
669 eventReceiver_->OnEvent(event);
670 }
671 return Status::OK;
672 }
673 if (renderTime > 0L && render) {
674 videoDecoder_->RenderOutputBufferAtTime(index, renderTime);
675 } else if (outBuffer->pts_ < 0) {
676 MEDIA_LOG_W("Avoid render video frame with pts=" PUBLIC_LOG_D64, outBuffer->pts_);
677 videoDecoder_->ReleaseOutputBuffer(index, false);
678 } else {
679 videoDecoder_->ReleaseOutputBuffer(index, render);
680 }
681 if (!isInSeekContinous_) {
682 videoSink_->SetLastPts(outBuffer->pts_);
683 }
684 if ((outBuffer->flag_ & (uint32_t)(Plugins::AVBufferFlag::EOS)) && !isInSeekContinous_) {
685 ResetSeekInfo();
686 MEDIA_LOG_I("ReleaseBuffer for eos, index: %{public}u, bufferid: %{public}" PRIu64
687 ", pts: %{public}" PRIu64", flag: %{public}u", index, outBuffer->GetUniqueId(),
688 outBuffer->pts_, outBuffer->flag_);
689 if (eventReceiver_ != nullptr) {
690 Event event {
691 .srcFilter = "VideoSink",
692 .type = EventType::EVENT_COMPLETE,
693 };
694 eventReceiver_->OnEvent(event);
695 }
696 }
697 return Status::OK;
698 }
699
DoProcessInputBuffer(int recvArg,bool dropFrame)700 Status DecoderSurfaceFilter::DoProcessInputBuffer(int recvArg, bool dropFrame)
701 {
702 videoDecoder_->AquireAvailableInputBuffer();
703 return Status::OK;
704 }
705
CalculateNextRender(uint32_t index,std::shared_ptr<AVBuffer> & outputBuffer)706 int64_t DecoderSurfaceFilter::CalculateNextRender(uint32_t index, std::shared_ptr<AVBuffer> &outputBuffer)
707 {
708 int64_t waitTime = -1;
709 MEDIA_LOG_D("DrainOutputBuffer not seeking and render. pts: " PUBLIC_LOG_D64, outputBuffer->pts_);
710 videoSink_->SetFirstPts(outputBuffer->pts_);
711 waitTime = videoSink_->DoSyncWrite(outputBuffer);
712 return waitTime;
713 }
714
715 // async filter should call this function
RenderNextOutput(uint32_t index,std::shared_ptr<AVBuffer> & outputBuffer)716 void DecoderSurfaceFilter::RenderNextOutput(uint32_t index, std::shared_ptr<AVBuffer> &outputBuffer)
717 {
718 if (isInSeekContinous_) {
719 Filter::ProcessOutputBuffer(false, 0);
720 return;
721 }
722 int64_t waitTime = CalculateNextRender(index, outputBuffer);
723 MEDIA_LOG_D("RenderNextOutput enter. pts: " PUBLIC_LOG_D64" waitTime: " PUBLIC_LOG_D64,
724 outputBuffer->pts_, waitTime);
725 Filter::ProcessOutputBuffer(waitTime >= 0, waitTime);
726 }
727
ConsumeVideoFrame(uint32_t index,bool isRender,int64_t renderTimeNs)728 void DecoderSurfaceFilter::ConsumeVideoFrame(uint32_t index, bool isRender, int64_t renderTimeNs)
729 {
730 MEDIA_LOG_D("ConsumeVideoFrame idx " PUBLIC_LOG_U32 " renderTimeNs " PUBLIC_LOG_D64, index, renderTimeNs);
731 Filter::ProcessOutputBuffer(isRender, 0, true, index, renderTimeNs);
732 }
733
DrainOutputBuffer(uint32_t index,std::shared_ptr<AVBuffer> & outputBuffer)734 void DecoderSurfaceFilter::DrainOutputBuffer(uint32_t index, std::shared_ptr<AVBuffer> &outputBuffer)
735 {
736 std::unique_lock<std::mutex> lock(mutex_);
737 FALSE_RETURN_NOLOG(!DrainSeekContinuous(index, outputBuffer));
738 FALSE_RETURN_NOLOG(!DrainSeekClosest(index, outputBuffer));
739 FALSE_RETURN_NOLOG(!DrainPreroll(index, outputBuffer));
740 if (IS_FILTER_ASYNC && outputBuffers_.empty()) {
741 RenderNextOutput(index, outputBuffer);
742 }
743 outputBuffers_.push_back(make_pair(index, outputBuffer));
744 if (!IS_FILTER_ASYNC) {
745 condBufferAvailable_.notify_one();
746 }
747 }
748
RenderLoop()749 void DecoderSurfaceFilter::RenderLoop()
750 {
751 while (true) {
752 std::pair<int, std::shared_ptr<AVBuffer>> nextTask;
753 {
754 std::unique_lock<std::mutex> lock(mutex_);
755 condBufferAvailable_.wait(lock, [this] {
756 return (!outputBuffers_.empty() && !isPaused_.load()) || isThreadExit_.load();
757 });
758 if (isThreadExit_) {
759 MEDIA_LOG_I("Exit RenderLoop read thread.");
760 break;
761 }
762 nextTask = std::move(outputBuffers_.front());
763 outputBuffers_.pop_front();
764 }
765 int64_t waitTime = CalculateNextRender(nextTask.first, nextTask.second);
766 MEDIA_LOG_D("RenderLoop enter. pts: " PUBLIC_LOG_D64" waitTime:" PUBLIC_LOG_D64,
767 nextTask.second->pts_, waitTime);
768 if (waitTime > 0) {
769 OSAL::SleepFor(waitTime / 1000); // 1000 convert to ms
770 }
771 ReleaseOutputBuffer(nextTask.first, waitTime >= 0, nextTask.second, -1);
772 }
773 }
774
DrainSeekContinuous(uint32_t index,std::shared_ptr<AVBuffer> & outputBuffer)775 bool DecoderSurfaceFilter::DrainSeekContinuous(uint32_t index, std::shared_ptr<AVBuffer> &outputBuffer)
776 {
777 FALSE_RETURN_V_NOLOG(isInSeekContinous_, false);
778 bool isEOS = outputBuffer->flag_ & (uint32_t)(Plugins::AVBufferFlag::EOS);
779 FALSE_RETURN_V_NOLOG(!isEOS, false);
780 outputBufferMap_.insert(std::make_pair(index, outputBuffer));
781 std::shared_ptr<VideoFrameReadyCallback> videoFrameReadyCallback = nullptr;
782 {
783 std::unique_lock<std::mutex> draggingLock(draggingMutex_);
784 FALSE_RETURN_V_NOLOG(videoFrameReadyCallback_ != nullptr, false);
785 MEDIA_LOG_D("[drag_debug]DrainSeekContinuous dts: " PUBLIC_LOG_D64 ", pts: " PUBLIC_LOG_D64
786 " bufferIdx: " PUBLIC_LOG_D32,
787 outputBuffer->dts_, outputBuffer->pts_, index);
788 videoFrameReadyCallback = videoFrameReadyCallback_;
789 }
790 FALSE_RETURN_V_NOLOG(videoFrameReadyCallback != nullptr, false);
791 videoFrameReadyCallback->ConsumeVideoFrame(outputBuffer, index);
792 return true;
793 }
794
DrainPreroll(uint32_t index,std::shared_ptr<AVBuffer> & outputBuffer)795 bool DecoderSurfaceFilter::DrainPreroll(uint32_t index, std::shared_ptr<AVBuffer> &outputBuffer)
796 {
797 FALSE_RETURN_V_NOLOG(inPreroll_.load(), false);
798 if (prerollDone_.load()) {
799 outputBuffers_.push_back(make_pair(index, outputBuffer));
800 return true;
801 }
802 std::lock_guard<std::mutex> lock(prerollMutex_);
803 FALSE_RETURN_V_NOLOG(inPreroll_.load() && !prerollDone_.load(), false);
804 outputBuffers_.push_back(make_pair(index, outputBuffer));
805 bool isEOS = outputBuffer->flag_ & (uint32_t)(Plugins::AVBufferFlag::EOS);
806 eosNext_.store(isEOS);
807 prerollDone_.store(true);
808 MEDIA_LOG_I("receive preroll output, pts: " PUBLIC_LOG_D64 " bufferIdx: " PUBLIC_LOG_D32,
809 outputBuffer->pts_, index);
810 prerollDoneCond_.notify_all();
811 return true;
812 }
813
DrainSeekClosest(uint32_t index,std::shared_ptr<AVBuffer> & outputBuffer)814 bool DecoderSurfaceFilter::DrainSeekClosest(uint32_t index, std::shared_ptr<AVBuffer> &outputBuffer)
815 {
816 FALSE_RETURN_V_NOLOG(isSeek_, false);
817 bool isEOS = outputBuffer->flag_ & (uint32_t)(Plugins::AVBufferFlag::EOS);
818 if (outputBuffer->pts_ < seekTimeUs_ && !isEOS) {
819 videoDecoder_->ReleaseOutputBuffer(index, false);
820 return true;
821 }
822 MEDIA_LOG_I("Seek arrive target video pts: " PUBLIC_LOG_D64, seekTimeUs_);
823 isSeek_ = false;
824 return false;
825 }
826
SetVideoSurface(sptr<Surface> videoSurface)827 Status DecoderSurfaceFilter::SetVideoSurface(sptr<Surface> videoSurface)
828 {
829 if (!videoSurface) {
830 MEDIA_LOG_W("videoSurface is null");
831 return Status::ERROR_INVALID_PARAMETER;
832 }
833 videoSurface_ = videoSurface;
834 if (videoDecoder_ != nullptr) {
835 MEDIA_LOG_I("videoDecoder_ SetOutputSurface in");
836 int32_t res = videoDecoder_->SetOutputSurface(videoSurface_);
837 if (res != OHOS::MediaAVCodec::AVCodecServiceErrCode::AVCS_ERR_OK) {
838 MEDIA_LOG_E("videoDecoder_ SetOutputSurface error, result is " PUBLIC_LOG_D32, res);
839 return Status::ERROR_UNKNOWN;
840 }
841 }
842 MEDIA_LOG_I("SetVideoSurface success");
843 return Status::OK;
844 }
845
SetSyncCenter(std::shared_ptr<MediaSyncManager> syncCenter)846 void DecoderSurfaceFilter::SetSyncCenter(std::shared_ptr<MediaSyncManager> syncCenter)
847 {
848 MEDIA_LOG_I("SetSyncCenter enter");
849 FALSE_RETURN(videoDecoder_ != nullptr);
850 videoSink_->SetSyncCenter(syncCenter);
851 }
852
SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySessionProxy,bool svp)853 Status DecoderSurfaceFilter::SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySessionProxy,
854 bool svp)
855 {
856 MEDIA_LOG_I("SetDecryptConfig enter.");
857 if (keySessionProxy == nullptr) {
858 MEDIA_LOG_E("SetDecryptConfig keySessionProxy is nullptr.");
859 return Status::ERROR_INVALID_PARAMETER;
860 }
861 isDrmProtected_ = true;
862 keySessionServiceProxy_ = keySessionProxy;
863 svpFlag_ = svp;
864 return Status::OK;
865 }
866
SetSeekTime(int64_t seekTimeUs)867 void DecoderSurfaceFilter::SetSeekTime(int64_t seekTimeUs)
868 {
869 MEDIA_LOG_I("SetSeekTime enter.");
870 isSeek_ = true;
871 seekTimeUs_ = seekTimeUs;
872 }
873
ResetSeekInfo()874 void DecoderSurfaceFilter::ResetSeekInfo()
875 {
876 MEDIA_LOG_I("ResetSeekInfo enter.");
877 isSeek_ = false;
878 seekTimeUs_ = 0;
879 }
880
ParseDecodeRateLimit()881 void DecoderSurfaceFilter::ParseDecodeRateLimit()
882 {
883 MEDIA_LOG_I("ParseDecodeRateLimit entered.");
884 std::shared_ptr<MediaAVCodec::AVCodecList> codecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList();
885 if (codecList == nullptr) {
886 MEDIA_LOG_E("create avcodeclist failed.");
887 return;
888 }
889 int32_t height = 0;
890 bool ret = meta_->GetData(Tag::VIDEO_HEIGHT, height);
891 FALSE_RETURN_MSG(ret || height <= 0, "failed to get video height");
892 int32_t width = 0;
893 ret = meta_->GetData(Tag::VIDEO_WIDTH, width);
894 FALSE_RETURN_MSG(ret || width <= 0, "failed to get video width");
895
896 MediaAVCodec::CapabilityData *capabilityData = codecList->GetCapability(codecMimeType_, false,
897 MediaAVCodec::AVCodecCategory::AVCODEC_NONE);
898 std::shared_ptr<MediaAVCodec::VideoCaps> videoCap = std::make_shared<MediaAVCodec::VideoCaps>(capabilityData);
899 FALSE_RETURN_MSG(videoCap != nullptr, "failed to get videoCap instance");
900 const MediaAVCodec::Range &frameRange = videoCap->GetSupportedFrameRatesFor(width, height);
901 rateUpperLimit_ = frameRange.maxVal;
902 if (rateUpperLimit_ > 0) {
903 meta_->SetData(Tag::VIDEO_DECODER_RATE_UPPER_LIMIT, rateUpperLimit_);
904 }
905 }
906
GetDecRateUpperLimit()907 int32_t DecoderSurfaceFilter::GetDecRateUpperLimit()
908 {
909 return rateUpperLimit_;
910 }
911
GetIsSupportSeekWithoutFlush()912 bool DecoderSurfaceFilter::GetIsSupportSeekWithoutFlush()
913 {
914 std::shared_ptr<MediaAVCodec::AVCodecList> codecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList();
915 FALSE_RETURN_V_MSG_E(codecList != nullptr, false, "create avcodeclist failed");
916 MediaAVCodec::CapabilityData *capabilityData = codecList->GetCapability(codecMimeType_, false,
917 MediaAVCodec::AVCodecCategory::AVCODEC_NONE);
918 std::shared_ptr<MediaAVCodec::AVCodecInfo> videoCap = std::make_shared<MediaAVCodec::AVCodecInfo>(capabilityData);
919 FALSE_RETURN_V_MSG_E(videoCap != nullptr, false, "failed to get videoCap instance");
920 return videoCap->IsFeatureSupported(MediaAVCodec::AVCapabilityFeature::VIDEO_DECODER_SEEK_WITHOUT_FLUSH);
921 }
922
SetBitrateStart()923 void DecoderSurfaceFilter::SetBitrateStart()
924 {
925 bitrateChange_++;
926 }
927
OnOutputFormatChanged(const MediaAVCodec::Format & format)928 void DecoderSurfaceFilter::OnOutputFormatChanged(const MediaAVCodec::Format &format)
929 {
930 AutoLock lock(formatChangeMutex_);
931 int32_t width = 0;
932 format.GetIntValue("video_picture_width", width);
933 int32_t height = 0;
934 format.GetIntValue("video_picture_height", height);
935 MEDIA_LOG_I("OnOutputFormatChanged curW=" PUBLIC_LOG_D32 " curH=" PUBLIC_LOG_D32 " nextW=" PUBLIC_LOG_D32
936 " nextH=" PUBLIC_LOG_D32, surfaceWidth_, surfaceHeight_, width, height);
937 if (width <= 0 || height <= 0) {
938 MEDIA_LOG_W("invaild video size");
939 return;
940 }
941 if (surfaceWidth_ == 0 || surfaceWidth_ == 0) {
942 MEDIA_LOG_I("receive first output Format");
943 surfaceWidth_ = width;
944 surfaceHeight_ = height;
945 return;
946 }
947 if (surfaceWidth_ == width && surfaceHeight_ == height) {
948 MEDIA_LOG_W("receive the same output Format");
949 return;
950 }
951 surfaceWidth_ = width;
952 surfaceHeight_ = height;
953
954 MEDIA_LOG_I("ReportVideoSizeChange videoWidth: " PUBLIC_LOG_D32 " videoHeight: "
955 PUBLIC_LOG_D32, surfaceWidth_, surfaceHeight_);
956 std::pair<int32_t, int32_t> videoSize {surfaceWidth_, surfaceHeight_};
957 eventReceiver_->OnEvent({"DecoderSurfaceFilter", EventType::EVENT_RESOLUTION_CHANGE, videoSize});
958 }
959
OnDumpInfo(int32_t fd)960 void DecoderSurfaceFilter::OnDumpInfo(int32_t fd)
961 {
962 MEDIA_LOG_D("DecoderSurfaceFilter::OnDumpInfo called.");
963 if (videoDecoder_ != nullptr) {
964 videoDecoder_->OnDumpInfo(fd);
965 }
966 }
967
RegisterVideoFrameReadyCallback(std::shared_ptr<VideoFrameReadyCallback> & callback)968 void DecoderSurfaceFilter::RegisterVideoFrameReadyCallback(std::shared_ptr<VideoFrameReadyCallback> &callback)
969 {
970 std::unique_lock<std::mutex> draggingLock(draggingMutex_);
971 isInSeekContinous_ = true;
972 if (callback != nullptr) {
973 videoFrameReadyCallback_ = callback;
974 }
975 }
976
DeregisterVideoFrameReadyCallback()977 void DecoderSurfaceFilter::DeregisterVideoFrameReadyCallback()
978 {
979 std::unique_lock<std::mutex> draggingLock(draggingMutex_);
980 isInSeekContinous_ = false;
981 videoFrameReadyCallback_ = nullptr;
982 }
983
StartSeekContinous()984 Status DecoderSurfaceFilter::StartSeekContinous()
985 {
986 isInSeekContinous_ = true;
987 return Status::OK;
988 }
989
StopSeekContinous()990 Status DecoderSurfaceFilter::StopSeekContinous()
991 {
992 isInSeekContinous_ = false;
993 return Status::OK;
994 }
995 } // namespace Pipeline
996 } // namespace MEDIA
997 } // namespace OHOS
998