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 #ifndef OHOS_SHARING_BASE_PRODUCER_H 17 #define OHOS_SHARING_BASE_PRODUCER_H 18 19 #include <functional> 20 #include <memory> 21 #include <cstdint> 22 #include <string> 23 #include "buffer_dispatcher.h" 24 #include "common/event_channel.h" 25 #include "common/identifier.h" 26 #include "common/object.h" 27 #include "event/handle_event_base.h" 28 #include "mediachannel/media_channel_def.h" 29 #include "utils/data_buffer.h" 30 31 namespace OHOS { 32 namespace Sharing { 33 34 class IProducerListener { 35 public: 36 using Ptr = std::shared_ptr<IProducerListener>; 37 38 virtual ~IProducerListener() = default; 39 40 virtual void OnProducerNotify(ProsumerStatusMsg::Ptr &statusMsg) = 0; 41 }; 42 43 class BaseProducer : public Object, 44 public HandleEventBase, 45 public BufferReceiver { 46 public: 47 using Ptr = std::shared_ptr<BaseProducer>; 48 49 BaseProducer(); 50 ~BaseProducer() override; 51 52 virtual void SetSrcAgentId(uint32_t agentId); 53 void SetProducerListener(std::weak_ptr<IProducerListener> listener); 54 55 virtual bool IsRunning(); StartDispatchThread()56 virtual void StartDispatchThread(){}; 57 virtual void PublishOneFrame(const MediaData::Ptr &buff) = 0; 58 virtual void UpdateOperation(ProsumerStatusMsg::Ptr &statusMsg) = 0; 59 60 virtual int32_t Release() = 0; 61 virtual uint32_t GetSrcAgentId(); 62 63 protected: 64 void Notify(ProsumerStatusMsg::Ptr &statusMsg); 65 void NotifyPrivateEvent(EventMsg::Ptr eventMsg); 66 67 protected: 68 bool isInit_ = false; 69 bool isPaused_ = false; 70 bool isRunning_ = false; 71 uint32_t srcAgentId_ = INVALID_ID; 72 std::weak_ptr<IProducerListener> listener_; 73 }; 74 75 } // namespace Sharing 76 } // namespace OHOS 77 #endif