1 /*
2  * Copyright (c) 2023-2023 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_CORE_PIPELINE_H
17 #define HISTREAMER_PIPELINE_CORE_PIPELINE_H
18 
19 #include <string>
20 #include <vector>
21 #include <memory>
22 #include "common/status.h"
23 #include "filter/filter.h"
24 #include "osal/task/mutex.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Pipeline {
29 class FilterCallback;
30 
31 class Pipeline : public EventReceiver {
32 public:
33     ~Pipeline();
34 
35     void Init(const std::shared_ptr<EventReceiver>& receiver,
36         const std::shared_ptr<FilterCallback>& callback, const std::string &playerId);
37 
38     Status Prepare();
39 
40     Status Start();
41 
42     Status Pause();
43 
44     Status Resume();
45 
46     Status Stop();
47 
48     Status Flush();
49 
50     Status Release();
51 
52     Status Preroll(bool render);
53 
54     Status SetPlayRange(int64_t start, int64_t end);
55 
56     Status AddHeadFilters(std::vector<std::shared_ptr<Filter>> filters);
57 
58     Status RemoveHeadFilter(const std::shared_ptr<Filter>& filter);
59 
60     Status LinkFilters(const std::shared_ptr<Filter>& preFilter,
61                        const std::vector<std::shared_ptr<Filter>>& filters, StreamType type);
62 
63     Status UpdateFilters(const std::shared_ptr<Filter>& preFilter,
64                          const std::vector<std::shared_ptr<Filter>>& filters, StreamType type);
65 
66     Status UnLinkFilters(const std::shared_ptr<Filter>& preFilter,
67                          const std::vector<std::shared_ptr<Filter>>& filters, StreamType type);
68 
69     void OnEvent(const Event& event) override;
70 
71     static int32_t GetNextPipelineId();
72 private:
73     std::string groupId_;
74     Mutex mutex_ {};
75     std::vector<std::shared_ptr<Filter>> filters_ {};
76     std::shared_ptr<EventReceiver> eventReceiver_ {nullptr};
77     std::shared_ptr<FilterCallback> filterCallback_ {nullptr};
78 };
79 } // namespace Pipeline
80 } // namespace Media
81 } // namespace OHOS
82 #endif // HISTREAMER_PIPELINE_CORE_PIPELINE_H
83