1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #include "base_consumer.h"
17 #include "common/common_macro.h"
18 
19 namespace OHOS {
20 namespace Sharing {
21 
BaseConsumer()22 BaseConsumer::BaseConsumer()
23 {
24     SHARING_LOGD("consumerId: %{public}u.", GetId());
25 }
26 
~BaseConsumer()27 BaseConsumer::~BaseConsumer()
28 {
29     SHARING_LOGD("consumerId: %{public}u.", GetId());
30 }
31 
SetConsumerListener(std::weak_ptr<IConsumerListener> listener)32 void BaseConsumer::SetConsumerListener(std::weak_ptr<IConsumerListener> listener)
33 {
34     SHARING_LOGD("trace.");
35     listener_ = listener;
36 }
37 
IsRunning()38 bool BaseConsumer::IsRunning()
39 {
40     SHARING_LOGD("trace.");
41     return isRunning_;
42 }
43 
IsPasued()44 bool BaseConsumer::IsPasued()
45 {
46     SHARING_LOGD("trace.");
47     return isPaused_;
48 }
49 
IsCapture()50 bool BaseConsumer::IsCapture()
51 {
52     SHARING_LOGD("trace.");
53     return false;
54 }
55 
GetSinkAgentId()56 uint32_t BaseConsumer::GetSinkAgentId()
57 {
58     SHARING_LOGD("trace.");
59     return sinkAgentId_;
60 }
61 
SetSinkAgentId(uint32_t agentId)62 void BaseConsumer::SetSinkAgentId(uint32_t agentId)
63 {
64     SHARING_LOGD("trace.");
65     sinkAgentId_ = agentId;
66 }
67 
GetAudioTrack() const68 const AudioTrack &BaseConsumer::GetAudioTrack() const
69 {
70     SHARING_LOGD("trace.");
71     return audioTrack_;
72 }
73 
GetVideoTrack() const74 const VideoTrack &BaseConsumer::GetVideoTrack() const
75 {
76     SHARING_LOGD("trace.");
77     return videoTrack_;
78 }
79 
Notify(ProsumerStatusMsg::Ptr &statusMsg)80 void BaseConsumer::Notify(ProsumerStatusMsg::Ptr &statusMsg)
81 {
82     SHARING_LOGD("trace.");
83     RETURN_IF_NULL(statusMsg);
84     statusMsg->prosumerId = GetId();
85     statusMsg->agentId = GetSinkAgentId();
86 
87     auto listener = listener_.lock();
88     if (listener) {
89         listener->OnConsumerNotify(statusMsg);
90     }
91 }
92 
NotifyPrivateEvent(EventMsg::Ptr eventMsg)93 void BaseConsumer::NotifyPrivateEvent(EventMsg::Ptr eventMsg)
94 {
95     SHARING_LOGD("trace.");
96     RETURN_IF_NULL(eventMsg);
97     auto pMsg = std::make_shared<ProsumerStatusMsg>();
98     pMsg->prosumerId = GetId();
99     pMsg->agentId = GetSinkAgentId();
100     pMsg->status = PROSUMER_NOTIFY_PRIVATE_EVENT;
101     pMsg->eventMsg = std::move(eventMsg);
102 
103     auto listener = listener_.lock();
104     if (listener) {
105         listener->OnConsumerNotify(pMsg);
106     }
107 }
108 
109 } // namespace Sharing
110 } // namespace OHOS