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 #ifndef FILTERS_SURFACE_DECODER_FILTER_H 16 #define FILTERS_SURFACE_DECODER_FILTER_H 17 18 #include <cstring> 19 #include "filter/filter.h" 20 #include "surface.h" 21 #include "meta/meta.h" 22 #include "meta/format.h" 23 #include "buffer/avbuffer.h" 24 #include "buffer/avallocator.h" 25 #include "buffer/avbuffer_queue.h" 26 #include "buffer/avbuffer_queue_producer.h" 27 #include "buffer/avbuffer_queue_consumer.h" 28 #include "common/status.h" 29 #include "common/log.h" 30 31 namespace OHOS { 32 namespace Media { 33 class SurfaceDecoderAdapter; 34 namespace Pipeline { 35 class SurfaceDecoderFilter : public Filter, public std::enable_shared_from_this<SurfaceDecoderFilter> { 36 public: 37 explicit SurfaceDecoderFilter(const std::string& name, FilterType type); 38 ~SurfaceDecoderFilter() override; 39 40 void Init(const std::shared_ptr<EventReceiver> &receiver, 41 const std::shared_ptr<FilterCallback> &callback) override; 42 Status Configure(const std::shared_ptr<Meta> ¶meter); 43 Status SetOutputSurface(sptr<Surface> surface); 44 Status NotifyNextFilterEos(int64_t pts, int64_t frameNum); 45 Status DoPrepare() override; 46 Status DoStart() override; 47 Status DoPause() override; 48 Status DoResume() override; 49 Status DoStop() override; 50 Status DoFlush() override; 51 Status DoRelease() override; 52 void SetParameter(const std::shared_ptr<Meta>& parameter) override; 53 void GetParameter(std::shared_ptr<Meta>& parameter) override; 54 Status LinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override; 55 Status UpdateNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override; 56 Status UnLinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override; 57 FilterType GetFilterType(); 58 void OnLinkedResult(const sptr<AVBufferQueueProducer> &outputBufferQueue, std::shared_ptr<Meta> &meta); 59 void OnUpdatedResult(std::shared_ptr<Meta> &meta); 60 void OnUnlinkedResult(std::shared_ptr<Meta> &meta); 61 sptr<AVBufferQueueProducer> GetInputBufferQueue(); 62 63 protected: 64 Status OnLinked(StreamType inType, const std::shared_ptr<Meta> &meta, 65 const std::shared_ptr<FilterLinkCallback> &callback) override; 66 Status OnUpdated(StreamType inType, const std::shared_ptr<Meta> &meta, 67 const std::shared_ptr<FilterLinkCallback> &callback) override; 68 Status OnUnLinked(StreamType inType, const std::shared_ptr<FilterLinkCallback>& callback) override; 69 70 private: 71 std::string name_; 72 FilterType filterType_ = FilterType::FILTERTYPE_MAX; 73 74 std::shared_ptr<EventReceiver> eventReceiver_{nullptr}; 75 std::shared_ptr<FilterCallback> filterCallback_{nullptr}; 76 std::shared_ptr<FilterLinkCallback> onLinkedResultCallback_{nullptr}; 77 std::shared_ptr<SurfaceDecoderAdapter> mediaCodec_{nullptr}; 78 79 std::string codecMimeType_; 80 std::shared_ptr<Meta> configureParameter_{nullptr}; 81 Format configFormat_{}; 82 83 std::shared_ptr<Filter> nextFilter_{nullptr}; 84 85 sptr<Surface> outputSurface_{nullptr}; 86 87 std::shared_ptr<Meta> meta_{nullptr}; 88 }; 89 } // namespace Pipeline 90 } // namespace Media 91 } // namespace OHOS 92 #endif // FILTERS_SURFACE_DECODER_FILTER_H 93