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 #ifndef HISTREAMER_PIPELINE_MUXER_FILTER_H 17 #define HISTREAMER_PIPELINE_MUXER_FILTER_H 18 #ifdef RECORDER_SUPPORT 19 #include "filter_base.h" 20 #include "plugin/core/muxer.h" 21 #include "plugin/core/plugin_info.h" 22 #include "plugin/interface/muxer_plugin.h" 23 #include "plugin/core/plugin_meta.h" 24 25 namespace OHOS { 26 namespace Media { 27 namespace Pipeline { 28 class DataSpliter; 29 class MuxerFilter : public FilterBase { 30 public: 31 explicit MuxerFilter(std::string name); 32 ~MuxerFilter() override; 33 34 void Init(EventReceiver* receiver, FilterCallback* callback) override; 35 36 bool Negotiate(const std::string& inPort, 37 const std::shared_ptr<const Plugin::Capability>& upstreamCap, 38 Plugin::Capability& negotiatedCap, 39 const Plugin::TagMap& upstreamParams, 40 Plugin::TagMap& downstreamParams) override; 41 42 bool Configure(const std::string &inPort, const std::shared_ptr<const Plugin::Meta> &upstreamMeta, 43 Plugin::TagMap &upstreamParams, Plugin::TagMap &downstreamParams) override; 44 45 ErrorCode SetOutputFormat(std::string containerMime); 46 ErrorCode AddTrack(std::shared_ptr<InPort>& trackPort); 47 ErrorCode SetMaxDuration(uint64_t maxDuration); 48 ErrorCode SetMaxSize(uint64_t maxSize); 49 ErrorCode StartNextSegment(); 50 ErrorCode SendEos(); 51 ErrorCode PushData(const std::string& inPort, const AVBufferPtr& buffer, int64_t offset) override; 52 ErrorCode Start() override; 53 private: 54 class MuxerDataSink : public Plugin::DataSinkHelper { 55 public: 56 Plugin::Status WriteAt(int64_t offset, const std::shared_ptr<Plugin::Buffer>& buffer) override; 57 MuxerFilter* muxerFilter_; 58 }; 59 60 struct TrackInfo { 61 int32_t trackId; 62 std::string inPort; 63 bool eos; 64 }; 65 66 int32_t GetTrackIdByInPort(const std::shared_ptr<InPort>& inPort); 67 int32_t UpdateTrackIdOfInPort(const std::shared_ptr<InPort>& inPort, int32_t trackId); 68 69 bool UpdateAndInitPluginByInfo(const std::shared_ptr<Plugin::PluginInfo>& selectedPluginInfo); 70 71 ErrorCode ConfigureToStart(); 72 ErrorCode AddTrackThenConfigure(const std::pair<std::string, Plugin::Meta>& metaPair); 73 74 bool AllTracksEos(); 75 void UpdateEosState(const std::string& inPort); 76 77 std::string containerMime_ {}; 78 std::vector<TrackInfo> trackInfos_ {}; 79 std::shared_ptr<Plugin::Muxer> plugin_ {}; 80 std::shared_ptr<Plugin::PluginInfo> targetPluginInfo_ {nullptr}; 81 std::shared_ptr<DataSpliter> dataSpliter_{}; 82 std::vector<std::pair<std::string, Capability>> capabilityCache_ {}; 83 std::vector<std::pair<std::string, Plugin::Meta>> metaCache_ {}; 84 bool hasWriteHeader_ {false}; 85 std::shared_ptr<MuxerDataSink> muxerDataSink_; 86 87 OSAL::Mutex pushDataMutex_; 88 bool eos_ {false}; 89 std::atomic<int> eosTrackCnt {0}; 90 }; 91 } // Pipeline 92 } // Media 93 } // OHOS 94 #endif 95 #endif // HISTREAMER_PIPELINE_MUXER_FILTER_H 96 97