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_MEDIA_FRAME_PIPELINE_H 17 #define OHOS_SHARING_MEDIA_FRAME_PIPELINE_H 18 19 #include <cstdint> 20 #include <list> 21 #include <shared_mutex> 22 #include <string> 23 #include "frame.h" 24 25 namespace OHOS { 26 namespace Sharing { 27 28 class FrameDestination; 29 class FrameSource : public std::enable_shared_from_this<FrameSource> { 30 public: 31 FrameSource() = default; 32 virtual ~FrameSource(); 33 34 void AddAudioDestination(std::shared_ptr<FrameDestination> dst); 35 void RemoveAudioDestination(std::shared_ptr<FrameDestination> dst); 36 37 protected: 38 void DeliverFrame(const Frame::Ptr &frame); 39 40 private: 41 std::shared_mutex audioDstsMutex_; 42 std::list<std::shared_ptr<FrameDestination>> audioDsts_; 43 }; 44 45 class FrameDestination { 46 public: 47 FrameDestination() = default; 48 virtual ~FrameDestination() = default; 49 50 virtual void OnFrame(const Frame::Ptr &frame) = 0; 51 52 void UnsetAudioSource(); 53 void SetAudioSource(std::shared_ptr<FrameSource> src); 54 HasAudioSource()55 bool HasAudioSource() 56 { 57 return audioSrc_ != nullptr; 58 } 59 60 private: 61 std::shared_mutex audioSrcMutex_; 62 std::shared_ptr<FrameSource> audioSrc_ = nullptr; 63 }; 64 } // namespace Sharing 65 } // namespace OHOS 66 #endif