1 /*
2  * Copyright (c) 2021-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 STREAM_COMMON_H
17 #define STREAM_COMMON_H
18 
19 #include <string>
20 
21 namespace Communication {
22 namespace SoftBus {
23 enum Proto {
24     VTP,
25     TCP,
26 };
27 
28 // keep same with the SessionStatus of softbus.
29 enum StreamStatus {
30     STREAM_INIT,
31     STREAM_OPENING,
32     STREAM_OPENED,
33     STREAM_CONNECTING,
34     STREAM_CONNECTED,
35     STREAM_CLOSING,
36     STREAM_CLOSED,
37 };
38 
39 enum StreamOptionType {
40     /*
41      * values less than 1000 is used inside the softbus.
42      */
43     STREAM_OPTION_TYPE_MIN = 1000,
44 
45     /*
46      * for stream
47      */
48     BITRATE_INT,
49     BITRATE_MIN_INT,
50     BITRATE_MAX_INT,
51     /*
52      * MAX_FPS_INT: the max fps in dynamic frame rate scenes.
53      * FIXED_FPS_INT: the fps in fixed frame rate scenes.
54      */
55     MAX_FPS_INT,
56     FIXED_FPS_INT,
57     EXPECTED_FPS_INT,
58     /*
59      * for multistream.
60      * PRIORITY_INT: indicate the priority of per stream.
61      * STREAM_ID_INT: indicate the id of per stream.
62      */
63     PRIORITY_INT,
64     STREAM_ID_INT,
65     /*
66      * Reliability policy:
67      * 1. No packet is discarded.
68      * 2. Predict I frames and discard the previous P frames.
69      * 3. If the P-frame times out, the time is reported immediately to trigger
70      * the service to generate an I-frame. If no timeout occurs, the timeout value is 0.
71      */
72     RELIABILITY_INT,
73     FRAME_TIMEOUT_INT,
74 
75     STREAM_TYPE_INT,
76     COMPRESS_RATIO_INT,
77     STREAM_OPTIONS_MAX = 1400,
78 };
79 
80 // NOTICE: only RAW_STREAM is available in 11.1.0
81 enum StreamType {
82     INVALID = -1,
83     /*
84      * Send any segment of a frame each time.
85      * WARNING: In this mode, NO encryption or decryption is performed.
86      */
87     RAW_STREAM,
88     /*
89      * Send a whole video frame each time.
90      */
91     COMMON_VIDEO_STREAM,
92     /*
93      * Send a whole audio frame each time.
94      */
95     COMMON_AUDIO_STREAM,
96     /*
97      * Slice frame mode.
98      */
99     VIDEO_SLICE_STREAM,
100 };
101 
102 enum FrameType {
103     NONE,
104     VIDEO_I,
105     VIDEO_P,
106     VIDEO_MAX = 50,
107     RADIO = VIDEO_MAX + 1,
108     RADIO_MAX = 100,
109 };
110 
111 struct IpAndPort {
112     std::string ip = "";
113     int port = 0;
114 };
115 
116 enum ValueType {
117     UNKNOWN,
118     INT_TYPE,
119     STRING_TYPE,
120     BOOL_TYPE,
121 };
122 
123 // used for raw stream mode.
124 enum Scene {
125     UNKNOWN_SCENE,
126     COMPATIBLE_SCENE,
127     SOFTBUS_SCENE,
128 };
129 
130 struct StreamAttr {
131 public:
132     StreamAttr() = default;
133     ~StreamAttr() = default;
StreamAttrStreamAttr134     explicit StreamAttr(bool flag) : type_(BOOL_TYPE), boolVal_(flag) {}
StreamAttrStreamAttr135     explicit StreamAttr(int value) : type_(INT_TYPE), intVal_(value) {}
StreamAttrStreamAttr136     explicit StreamAttr(std::string str) : type_(STRING_TYPE), strVal_(str) {}
137 
GetTypeStreamAttr138     ValueType GetType() const
139     {
140         return type_;
141     }
142 
GetIntValueStreamAttr143     int GetIntValue() const
144     {
145         return intVal_;
146     }
147 
GetStrValueStreamAttr148     std::string GetStrValue() const
149     {
150         return strVal_;
151     }
152 
GetBoolValueStreamAttr153     bool GetBoolValue() const
154     {
155         return boolVal_;
156     }
157 
158 private:
159     ValueType type_ = UNKNOWN;
160 
161     int intVal_ = -1;
162     std::string strVal_ = "";
163     bool boolVal_ = false;
164 };
165 
166 static constexpr int ADDR_MAX_SIZE = sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255");
167 static constexpr int MAX_STREAM_LEN = 2 * 1024 * 1024;
168 } // namespace SoftBus
169 } // namespace Communication
170 
171 #endif //STREAM_COMMON_H
172