1 /*
2 * Copyright (c) 2021-2021 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 HST_LOG_TAG "PluginCoreViSink"
17
18 #include "video_sink.h"
19
20 #include "foundation/log.h"
21 #include "foundation/osal/thread/scoped_lock.h"
22 #include "interface/video_sink_plugin.h"
23 #include "plugin_core_utils.h"
24
25 using namespace OHOS::Media::Plugin;
26
VideoSink(uint32_t pkgVer,uint32_t apiVer,std::shared_ptr<VideoSinkPlugin> plugin)27 VideoSink::VideoSink(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr<VideoSinkPlugin> plugin)
28 : Base(pkgVer, apiVer, plugin), videoSink(std::move(plugin))
29 {
30 }
31
Pause()32 Status VideoSink::Pause()
33 {
34 MEDIA_LOG_I(PUBLIC_LOG_S " Enter.", __FUNCTION__);
35 OSAL::ScopedLock lock(stateChangeMutex_);
36 if (pluginState_ != State::RUNNING) {
37 MEDIA_LOG_I("plugin " PUBLIC_LOG_S " pause in status " PUBLIC_LOG_S ", ignore pause",
38 plugin_->GetName().c_str(), GetStateString(pluginState_.load()));
39 return Status::OK;
40 }
41 auto ret = videoSink->Pause();
42 LOG_WARN_IF_NOT_OK(plugin_, ret);
43 if (ret == Status::OK) {
44 pluginState_ = State::PAUSED;
45 }
46 MEDIA_LOG_I(PUBLIC_LOG_S " Exit.", __FUNCTION__);
47 return ret;
48 }
49
Resume()50 Status VideoSink::Resume()
51 {
52 MEDIA_LOG_I(PUBLIC_LOG_S " Enter.", __FUNCTION__);
53 OSAL::ScopedLock lock(stateChangeMutex_);
54 if (pluginState_ != State::PAUSED) {
55 MEDIA_LOG_I("plugin " PUBLIC_LOG_S " resume in status " PUBLIC_LOG_S ", ignore pause",
56 plugin_->GetName().c_str(), GetStateString(pluginState_.load()));
57 return Status::OK;
58 }
59 auto ret = videoSink->Resume();
60 LOG_WARN_IF_NOT_OK(plugin_, ret);
61 if (ret == Status::OK) {
62 pluginState_ = State::RUNNING;
63 }
64 MEDIA_LOG_I(PUBLIC_LOG_S " Exit.", __FUNCTION__);
65 return ret;
66 }
67
Flush()68 Status VideoSink::Flush()
69 {
70 return videoSink->Flush();
71 }
72
Write(const std::shared_ptr<Buffer> & input)73 Status VideoSink::Write(const std::shared_ptr<Buffer>& input)
74 {
75 return videoSink->Write(input);
76 }
77
GetLatency(uint64_t & hstTime)78 Status VideoSink::GetLatency(uint64_t& hstTime)
79 {
80 return videoSink->GetLatency(hstTime);
81 }