1e0e9324cSopenharmony_ci/* 2e0e9324cSopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3e0e9324cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0e9324cSopenharmony_ci * you may not use this file except in compliance with the License. 5e0e9324cSopenharmony_ci * You may obtain a copy of the License at 6e0e9324cSopenharmony_ci * 7e0e9324cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0e9324cSopenharmony_ci * 9e0e9324cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0e9324cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0e9324cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0e9324cSopenharmony_ci * See the License for the specific language governing permissions and 13e0e9324cSopenharmony_ci * limitations under the License. 14e0e9324cSopenharmony_ci */ 15e0e9324cSopenharmony_ci 16e0e9324cSopenharmony_ci#include "base_consumer.h" 17e0e9324cSopenharmony_ci#include "common/common_macro.h" 18e0e9324cSopenharmony_ci 19e0e9324cSopenharmony_cinamespace OHOS { 20e0e9324cSopenharmony_cinamespace Sharing { 21e0e9324cSopenharmony_ci 22e0e9324cSopenharmony_ciBaseConsumer::BaseConsumer() 23e0e9324cSopenharmony_ci{ 24e0e9324cSopenharmony_ci SHARING_LOGD("consumerId: %{public}u.", GetId()); 25e0e9324cSopenharmony_ci} 26e0e9324cSopenharmony_ci 27e0e9324cSopenharmony_ciBaseConsumer::~BaseConsumer() 28e0e9324cSopenharmony_ci{ 29e0e9324cSopenharmony_ci SHARING_LOGD("consumerId: %{public}u.", GetId()); 30e0e9324cSopenharmony_ci} 31e0e9324cSopenharmony_ci 32e0e9324cSopenharmony_civoid BaseConsumer::SetConsumerListener(std::weak_ptr<IConsumerListener> listener) 33e0e9324cSopenharmony_ci{ 34e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 35e0e9324cSopenharmony_ci listener_ = listener; 36e0e9324cSopenharmony_ci} 37e0e9324cSopenharmony_ci 38e0e9324cSopenharmony_cibool BaseConsumer::IsRunning() 39e0e9324cSopenharmony_ci{ 40e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 41e0e9324cSopenharmony_ci return isRunning_; 42e0e9324cSopenharmony_ci} 43e0e9324cSopenharmony_ci 44e0e9324cSopenharmony_cibool BaseConsumer::IsPasued() 45e0e9324cSopenharmony_ci{ 46e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 47e0e9324cSopenharmony_ci return isPaused_; 48e0e9324cSopenharmony_ci} 49e0e9324cSopenharmony_ci 50e0e9324cSopenharmony_cibool BaseConsumer::IsCapture() 51e0e9324cSopenharmony_ci{ 52e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 53e0e9324cSopenharmony_ci return false; 54e0e9324cSopenharmony_ci} 55e0e9324cSopenharmony_ci 56e0e9324cSopenharmony_ciuint32_t BaseConsumer::GetSinkAgentId() 57e0e9324cSopenharmony_ci{ 58e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 59e0e9324cSopenharmony_ci return sinkAgentId_; 60e0e9324cSopenharmony_ci} 61e0e9324cSopenharmony_ci 62e0e9324cSopenharmony_civoid BaseConsumer::SetSinkAgentId(uint32_t agentId) 63e0e9324cSopenharmony_ci{ 64e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 65e0e9324cSopenharmony_ci sinkAgentId_ = agentId; 66e0e9324cSopenharmony_ci} 67e0e9324cSopenharmony_ci 68e0e9324cSopenharmony_ciconst AudioTrack &BaseConsumer::GetAudioTrack() const 69e0e9324cSopenharmony_ci{ 70e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 71e0e9324cSopenharmony_ci return audioTrack_; 72e0e9324cSopenharmony_ci} 73e0e9324cSopenharmony_ci 74e0e9324cSopenharmony_ciconst VideoTrack &BaseConsumer::GetVideoTrack() const 75e0e9324cSopenharmony_ci{ 76e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 77e0e9324cSopenharmony_ci return videoTrack_; 78e0e9324cSopenharmony_ci} 79e0e9324cSopenharmony_ci 80e0e9324cSopenharmony_civoid BaseConsumer::Notify(ProsumerStatusMsg::Ptr &statusMsg) 81e0e9324cSopenharmony_ci{ 82e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 83e0e9324cSopenharmony_ci RETURN_IF_NULL(statusMsg); 84e0e9324cSopenharmony_ci statusMsg->prosumerId = GetId(); 85e0e9324cSopenharmony_ci statusMsg->agentId = GetSinkAgentId(); 86e0e9324cSopenharmony_ci 87e0e9324cSopenharmony_ci auto listener = listener_.lock(); 88e0e9324cSopenharmony_ci if (listener) { 89e0e9324cSopenharmony_ci listener->OnConsumerNotify(statusMsg); 90e0e9324cSopenharmony_ci } 91e0e9324cSopenharmony_ci} 92e0e9324cSopenharmony_ci 93e0e9324cSopenharmony_civoid BaseConsumer::NotifyPrivateEvent(EventMsg::Ptr eventMsg) 94e0e9324cSopenharmony_ci{ 95e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 96e0e9324cSopenharmony_ci RETURN_IF_NULL(eventMsg); 97e0e9324cSopenharmony_ci auto pMsg = std::make_shared<ProsumerStatusMsg>(); 98e0e9324cSopenharmony_ci pMsg->prosumerId = GetId(); 99e0e9324cSopenharmony_ci pMsg->agentId = GetSinkAgentId(); 100e0e9324cSopenharmony_ci pMsg->status = PROSUMER_NOTIFY_PRIVATE_EVENT; 101e0e9324cSopenharmony_ci pMsg->eventMsg = std::move(eventMsg); 102e0e9324cSopenharmony_ci 103e0e9324cSopenharmony_ci auto listener = listener_.lock(); 104e0e9324cSopenharmony_ci if (listener) { 105e0e9324cSopenharmony_ci listener->OnConsumerNotify(pMsg); 106e0e9324cSopenharmony_ci } 107e0e9324cSopenharmony_ci} 108e0e9324cSopenharmony_ci 109e0e9324cSopenharmony_ci} // namespace Sharing 110e0e9324cSopenharmony_ci} // namespace OHOS