1 /* 2 * Copyright (c) 2024-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 FILTERS_VIDEO_RESIZE_FILTER_H 17 #define FILTERS_VIDEO_RESIZE_FILTER_H 18 19 #include <cstring> 20 #include "filter/filter.h" 21 #include "osal/task/task.h" 22 #include "common/status.h" 23 #include "common/log.h" 24 25 namespace OHOS { 26 namespace Media { 27 #ifdef USE_VIDEO_PROCESSING_ENGINE 28 namespace VideoProcessingEngine { 29 class DetailEnhancerVideo; 30 } 31 #endif 32 namespace Pipeline { 33 class VideoResizeFilter : public Filter, public std::enable_shared_from_this<VideoResizeFilter> { 34 public: 35 explicit VideoResizeFilter(std::string name, FilterType type); 36 ~VideoResizeFilter() override; 37 Status SetCodecFormat(const std::shared_ptr<Meta> &format); 38 void Init(const std::shared_ptr<EventReceiver> &receiver, 39 const std::shared_ptr<FilterCallback> &callback) override; 40 Status Configure(const std::shared_ptr<Meta> ¶meter); 41 sptr<Surface> GetInputSurface(); 42 Status SetOutputSurface(sptr<Surface> surface, int32_t width, int32_t height); 43 Status DoPrepare() override; 44 Status DoStart() override; 45 Status DoPause() override; 46 Status DoResume() override; 47 Status DoStop() override; 48 Status DoFlush() override; 49 Status DoRelease() override; 50 Status NotifyNextFilterEos(); 51 void SetParameter(const std::shared_ptr<Meta> ¶meter) override; 52 void GetParameter(std::shared_ptr<Meta> ¶meter) override; 53 Status LinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override; 54 Status UpdateNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override; 55 Status UnLinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override; 56 FilterType GetFilterType(); 57 void OnLinkedResult(const sptr<AVBufferQueueProducer> &outputBufferQueue, std::shared_ptr<Meta> &meta); 58 void OnUpdatedResult(std::shared_ptr<Meta> &meta); 59 void OnUnlinkedResult(std::shared_ptr<Meta> &meta); 60 void OnOutputBufferAvailable(uint32_t index, uint32_t flag); 61 void SetFaultEvent(const std::string &errMsg); 62 void SetFaultEvent(const std::string &errMsg, int32_t ret); 63 void SetCallingInfo(int32_t appUid, int32_t appPid, const std::string &bundleName, uint64_t instanceId); 64 65 protected: 66 Status OnLinked(StreamType inType, const std::shared_ptr<Meta> &meta, 67 const std::shared_ptr<FilterLinkCallback> &callback) override; 68 Status OnUpdated(StreamType inType, const std::shared_ptr<Meta> &meta, 69 const std::shared_ptr<FilterLinkCallback> &callback) override; 70 Status OnUnLinked(StreamType inType, const std::shared_ptr<FilterLinkCallback>& callback) override; 71 72 private: 73 void ReleaseBuffer(); 74 std::string name_; 75 FilterType filterType_; 76 77 std::shared_ptr<EventReceiver> eventReceiver_; 78 std::shared_ptr<FilterCallback> filterCallback_; 79 80 std::shared_ptr<FilterLinkCallback> onLinkedResultCallback_; 81 82 #ifdef USE_VIDEO_PROCESSING_ENGINE 83 std::shared_ptr<VideoProcessingEngine::DetailEnhancerVideo> videoEnhancer_; 84 #endif 85 86 std::string codecMimeType_; 87 std::shared_ptr<Meta> configureParameter_; 88 89 std::shared_ptr<Filter> nextFilter_; 90 91 std::mutex releaseBufferMutex_; 92 std::condition_variable releaseBufferCondition_; 93 std::shared_ptr<Task> releaseBufferTask_{nullptr}; 94 std::vector<uint32_t> indexs_; 95 int64_t eosPts_ {UINT32_MAX}; 96 int64_t frameNum_ {UINT32_MAX}; 97 std::atomic<int64_t> currentFrameNum_ = 0; 98 std::atomic<bool> isThreadExit_ = true; 99 100 std::string bundleName_; 101 uint64_t instanceId_{0}; 102 int32_t appUid_ {0}; 103 int32_t appPid_ {0}; 104 }; 105 } // namespace Pipeline 106 } // namespace MEDIA 107 } // namespace OHOS 108 #endif // FILTERS_VIDEO_RESIZE_FILTER_H