1 /* 2 * Copyright (C) 2024 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_SUBTITLE_SINK_FILTER_H 17 #define HISTREAMER_SUBTITLE_SINK_FILTER_H 18 19 #include <atomic> 20 21 #include "media_sync_manager.h" 22 #include "subtitle_sink.h" 23 #include "plugin/plugin_info.h" 24 #include "filter/filter.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Pipeline { 29 class SubtitleSinkFilter : public Filter, public std::enable_shared_from_this<SubtitleSinkFilter> { 30 public: 31 explicit SubtitleSinkFilter(const std::string& name, FilterType filterType = FilterType::FILTERTYPE_SSINK); 32 ~SubtitleSinkFilter() override; 33 34 void Init(const std::shared_ptr<EventReceiver>& receiver, const std::shared_ptr<FilterCallback>& callback) override; 35 36 Status DoInitAfterLink() override; 37 38 Status DoPrepare() override; 39 40 Status DoStart() override; 41 42 Status DoPause() override; 43 44 Status DoResume() override; 45 46 Status DoFlush() override; 47 48 Status DoStop() override; 49 50 Status DoRelease() override; 51 52 Status DoProcessInputBuffer(int recvArg, bool dropFrame) override; 53 54 void SetParameter(const std::shared_ptr<Meta>& meta) override; 55 56 void GetParameter(std::shared_ptr<Meta>& meta) override; 57 58 Status OnLinked(StreamType inType, const std::shared_ptr<Meta>& meta, 59 const std::shared_ptr<FilterLinkCallback>& callback) override; 60 61 void SetSyncCenter(std::shared_ptr<MediaSyncManager> syncCenter); 62 63 Status SetIsTransitent(bool isTransitent); 64 65 void NotifySeek(); 66 67 Status SetSpeed(float speed); 68 protected: 69 Status OnUpdated(StreamType inType, const std::shared_ptr<Meta>& meta, 70 const std::shared_ptr<FilterLinkCallback>& callback) override; 71 72 Status OnUnLinked(StreamType inType, const std::shared_ptr<FilterLinkCallback>& callback) override; 73 74 class AVBufferAvailableListener : public IConsumerListener { 75 public: 76 AVBufferAvailableListener(std::shared_ptr<SubtitleSinkFilter> subtitleSinkFilter); 77 78 void OnBufferAvailable() override; 79 private: 80 std::weak_ptr<SubtitleSinkFilter> subtitleSinkFilter_; 81 }; 82 83 private: 84 std::shared_ptr<SubtitleSink> subtitleSink_; 85 std::string name_; 86 FilterType filterType_ = FilterType::FILTERTYPE_SSINK; 87 FilterState state_ = FilterState::CREATED; 88 std::shared_ptr<Meta> trackMeta_; 89 std::shared_ptr<Meta> globalMeta_; 90 91 std::shared_ptr<EventReceiver> eventReceiver_; 92 std::shared_ptr<FilterCallback> filterCallback_; 93 94 std::shared_ptr<FilterLinkCallback> onLinkedResultCallback_; 95 sptr<AVBufferQueueConsumer> inputBufferQueueConsumer_; 96 int64_t frameCnt_ {0}; 97 98 float volume_ {-1.0f}; // default invalid value 99 std::atomic<bool> isThreadExit_ = true; 100 }; 101 } // namespace Pipeline 102 } // namespace Media 103 } // namespace OHOS 104 105 #endif // HISTREAMER_SUBTITLE_SINK_FILTER_H 106