1 /**
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef BASE_STREAM_GRAPH_H
18 #define BASE_STREAM_GRAPH_H
19 
20 #include <ImsMediaDefine.h>
21 #include <StreamScheduler.h>
22 #include <BaseNode.h>
23 #include <BaseSessionCallback.h>
24 #include <MediaQualityThreshold.h>
25 #include <RtpConfig.h>
26 #include <list>
27 
28 /**
29  * @class BaseStreamGraph
30  */
31 class BaseStreamGraph
32 {
33 protected:
34     virtual ImsMediaResult create(RtpConfig* config) = 0;
35     virtual ImsMediaResult update(RtpConfig* config) = 0;
36     void AddNode(BaseNode* pNode, bool bReverse = true);
37     void RemoveNode(BaseNode* pNode);
38     ImsMediaResult startNodes();
39     ImsMediaResult stopNodes();
40     void deleteNodes();
41     BaseNode* findNode(kBaseNodeId id);
42 
43 public:
44     /**
45      * @brief Construct
46      *
47      * @param callback Callback interface to send event to session
48      * @param localFd
49      */
50     BaseStreamGraph(BaseSessionCallback* callback, int localFd = 0);
51     virtual ~BaseStreamGraph();
52 
53     /**
54      * @brief Sets the local socket file descriptor
55      *
56      * @param localFd socket file descriptor to set
57      */
58     void setLocalFd(int localFd);
59 
60     /**
61      * @brief Gets the local socket file descriptor
62      *
63      * @return int The socket file descriptor
64      */
65     int getLocalFd();
66 
67     /**
68      * @brief Starts the nodes in the graph
69      *
70      * @return ImsMediaResult RESULT_SUCCESS when the start succeeded
71      */
72     virtual ImsMediaResult start();
73 
74     /**
75      * @brief Stops the nodes in the graph
76      *
77      * @return ImsMediaResult RESULT_SUCCESS when the stop succeeded
78      */
79     virtual ImsMediaResult stop();
80 
81     /**
82      * @brief Sets the stream state
83      *
84      * @param state state to update.
85      */
86     void setState(StreamState state);
87 
88     /**
89      * @brief Gets the stream state
90      *
91      * @return StreamState state of stream
92      */
93     StreamState getState();
94 
95     /**
96      * @brief Checks StreamGraph is same graph based on the parameter
97      *
98      * @param config RtpConfig for the StreamGraph operates nodes in the graph
99      * @return true The remote IP address and port number is same
100      * @return false The remote IP address or port number is not the same
101      */
102     virtual bool isSameGraph(RtpConfig* config) = 0;
103 
104     /**
105      * @brief Set the MediaQualityThreshold to the nodes.
106      *
107      * @param threshold threshold parameter to set.
108      */
109     virtual bool setMediaQualityThreshold(MediaQualityThreshold* threshold);
110 
111     /**
112      * @brief Handles event from the session or trigger by the other nodes
113      *
114      * @param type event type check kImsMediaInternalRequestType in ImsMediaDefine.h
115      * @param param1 parameter to set
116      * @param param2 parameter to set
117      * @return true The event sent to target node successfully
118      * @return false The event cannot pass to the target node
119      */
120     virtual bool OnEvent(int32_t type, uint64_t param1, uint64_t param2);
121 
122 protected:
123     BaseSessionCallback* mCallback;
124     int mLocalFd;
125     StreamState mGraphState;
126     std::list<BaseNode*> mListNodeToStart;
127     std::list<BaseNode*> mListNodeStarted;
128     std::shared_ptr<StreamScheduler> mScheduler;
129 };
130 
131 #endif