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