• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "avcodec_common.h"
31 
32 namespace OHOS {
33 namespace Media {
34 class SurfaceDecoderAdapter;
35 namespace Pipeline {
36 class SurfaceDecoderFilter : public Filter, public std::enable_shared_from_this<SurfaceDecoderFilter> {
37 public:
38     explicit SurfaceDecoderFilter(const std::string& name, FilterType type);
39     ~SurfaceDecoderFilter() override;
40 
41     void Init(const std::shared_ptr<EventReceiver> &receiver,
42         const std::shared_ptr<FilterCallback> &callback) override;
43     Status Configure(const std::shared_ptr<Meta> &parameter);
44     Status SetOutputSurface(sptr<Surface> surface);
45     Status NotifyNextFilterEos(int64_t pts, int64_t frameNum);
46     Status DoPrepare() override;
47     Status DoStart() override;
48     Status DoPause() override;
49     Status DoResume() override;
50     Status DoStop() override;
51     Status DoFlush() override;
52     Status DoRelease() override;
53     void SetParameter(const std::shared_ptr<Meta>& parameter) override;
54     void GetParameter(std::shared_ptr<Meta>& parameter) override;
55     Status LinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override;
56     Status UpdateNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override;
57     Status UnLinkNext(const std::shared_ptr<Filter> &nextFilter, StreamType outType) override;
58     FilterType GetFilterType();
59     void OnLinkedResult(const sptr<AVBufferQueueProducer> &outputBufferQueue, std::shared_ptr<Meta> &meta);
60     void OnUpdatedResult(std::shared_ptr<Meta> &meta);
61     void OnUnlinkedResult(std::shared_ptr<Meta> &meta);
62     void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode);
63     sptr<AVBufferQueueProducer> GetInputBufferQueue();
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     std::string name_;
74     FilterType filterType_ = FilterType::FILTERTYPE_MAX;
75 
76     std::shared_ptr<EventReceiver> eventReceiver_{nullptr};
77     std::shared_ptr<FilterCallback> filterCallback_{nullptr};
78     std::shared_ptr<FilterLinkCallback> onLinkedResultCallback_{nullptr};
79     std::shared_ptr<SurfaceDecoderAdapter> mediaCodec_{nullptr};
80 
81     std::string codecMimeType_;
82     std::shared_ptr<Meta> configureParameter_{nullptr};
83     Format configFormat_{};
84 
85     std::shared_ptr<Filter> nextFilter_{nullptr};
86 
87     sptr<Surface> outputSurface_{nullptr};
88 
89     std::shared_ptr<Meta> meta_{nullptr};
90 };
91 } // namespace Pipeline
92 } // namespace Media
93 } // namespace OHOS
94 #endif // FILTERS_SURFACE_DECODER_FILTER_H
95