• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Description: Cast engine related common data stucture definitions.
15  * Author: zhangge
16  * Create: 2022-06-15
17  */
18 
19 #ifndef CAST_ENGINE_COMMON_H
20 #define CAST_ENGINE_COMMON_H
21 
22 #include <array>
23 #include <map>
24 #include <string>
25 
26 #include <message_parcel.h>
27 #define EXPORT __attribute__((visibility("default")))
28 
29 namespace OHOS {
30 namespace CastEngine {
31 enum class EXPORT DeviceType {
32     DEVICE_OTHERS = 0,
33     DEVICE_SCREEN_PLAYER = 1,
34     DEVICE_HW_TV = 2,
35     DEVICE_SOUND_BOX = 3,
36     DEVICE_HICAR = 4,
37     DEVICE_MATEBOOK = 5,
38     DEVICE_PAD = 6,
39     DEVICE_CAST_PLUS = 7,
40     DEVICE_TYPE_2IN1 = 8,
41     DEVICE_SMART_SCREEN_UNF = 9,
42     DEVICE_PAD_IN_CAR = 10,
43     DEVICE_SUPER_LAUNCHER = 11,
44     DEVICE_CAR_MULTI_SCREEN_PLAY = 12,
45 };
46 
IsDeviceType(int32_t type)47 inline bool EXPORT IsDeviceType(int32_t type)
48 {
49     return (type >= static_cast<int32_t>(DeviceType::DEVICE_OTHERS)) &&
50         (type <= static_cast<int32_t>(DeviceType::DEVICE_CAR_MULTI_SCREEN_PLAY));
51 }
52 
53 enum class EXPORT SubDeviceType {
54     SUB_DEVICE_DEFAULT = 0,
55     SUB_DEVICE_MATEBOOK_PAD = 51,
56     SUB_DEVICE_CAST_PLUS_WHITEBOARD = 0x00B2
57 };
58 
IsSubDeviceType(int32_t type)59 inline bool EXPORT IsSubDeviceType(int32_t type)
60 {
61     return (type == static_cast<int32_t>(SubDeviceType::SUB_DEVICE_DEFAULT)) ||
62         (type == static_cast<int32_t>(SubDeviceType::SUB_DEVICE_MATEBOOK_PAD)) ||
63         (type == static_cast<int32_t>(SubDeviceType::SUB_DEVICE_CAST_PLUS_WHITEBOARD));
64 }
65 
66 enum class EXPORT TriggerType {
67     UNSPEC_TAG = 0,
68     PASSIVE_MATCH_TAG = 1,
69     ACTIVE_MATCH_TAG = 2,
70     PASSIVE_BIND_TAG = 3,
71 };
72 
IsTriggerType(int32_t type)73 inline bool EXPORT IsTriggerType(int32_t type)
74 {
75     return (type >= static_cast<int32_t>(TriggerType::UNSPEC_TAG)) &&
76         (type <= static_cast<int32_t>(TriggerType::PASSIVE_BIND_TAG));
77 }
78 
79 enum class EXPORT DeviceState {
80     CONNECTING,
81     CONNECTED,
82     PAUSED,
83     PLAYING,
84     DISCONNECTING,
85     DISCONNECTED,
86     STREAM,
87     AUTHING,
88     DEVICE_STATE_MAX,
89 };
90 
91 enum class EXPORT DeviceGrabState {
92     GRAB_ALLOWED,
93     GRAB_NOT_ALLOWED,
94     GRABING,
95     NO_GRAB,
96 };
97 
98 enum ConnectEvent : int {
99     AUTH_START,
100     AUTH_SUCCESS,
101     AUTH_FILED,
102     CONNECT_START,
103     CONNECT_FAIL,
104     CONNECT_SUCCESS,
105     DISCONNECT_START,
106 };
107 
108 /*
109  * code =0 -> no specific events
110  * code >0 -> regular events
111  *   code = 1xxxx -> regular events
112  * code <0 -> error events
113  *   code = -1xxxx -> error called from DM
114  *   code = -2xxxx -> error called from cast session
115  */
116 enum class EXPORT EventCode {
117     UNKNOWN_EVENT = -99999,
118     ERR_CONNECTION_FAILED = -20000,
119     ERR_PIN_CODE_RETRY_COUNT_EXCEEDED = -10000,
120     ERR_CANCEL_BY_SINK = -10001,
121     ERR_DISTRUST_BY_SINK = -10002,
122     ERR_SINK_TIMEOUT = -10003,
123     DEFAULT_EVENT = 0,
124     EVT_TRUST_BY_SINK = 10000,
125     EVT_CANCEL_BY_SOURCE = 10001,
126     EVT_AUTHENTICATION_COMPLETED = 10002,
127     EVT_SHOW_AUTHORIZE_UI = 10003
128 };
129 
130 const EXPORT std::array<std::string, static_cast<size_t>(DeviceState::DEVICE_STATE_MAX)> DEVICE_STATE_STRING = {
131     "CONNECTING", "CONNECTED", "PAUSED", "PLAYING", "DISCONNECTING", "DISCONNECTED", "STREAM",
132     "AUTHING",
133 };
134 
IsDeviceState(int32_t state)135 inline bool EXPORT IsDeviceState(int32_t state)
136 {
137     return (state >= static_cast<int32_t>(DeviceState::CONNECTING)) &&
138         (state < static_cast<int32_t>(DeviceState::DEVICE_STATE_MAX));
139 }
140 
141 enum class EXPORT ServiceStatus {
142     DISCONNECTED,
143     DISCONNECTING,
144     CONNECTING,
145     CONNECTED,
146 };
147 
IsServiceStatus(int32_t status)148 inline bool EXPORT IsServiceStatus(int32_t status)
149 {
150     return (status >= static_cast<int32_t>(ServiceStatus::DISCONNECTED)) &&
151         (status <= static_cast<int32_t>(ServiceStatus::CONNECTED));
152 }
153 
154 enum class EXPORT DeviceStatusState {
155     DEVICE_AVAILABLE,
156     DEVICE_CONNECTED,
157     DEVICE_DISCONNECTED,
158     DEVICE_CONNECT_REQ,
159 };
160 
IsDeviceStatus(int32_t status)161 inline bool EXPORT IsDeviceStatus(int32_t status)
162 {
163     return (status >= static_cast<int32_t>(DeviceStatusState::DEVICE_AVAILABLE)) &&
164         (status <= static_cast<int32_t>(DeviceStatusState::DEVICE_CONNECT_REQ));
165 }
166 
167 enum class EXPORT PropertyType {
168     VIDEO_SIZE,
169     VIDEO_FPS,
170     WINDOW_SIZE,
171 };
172 
IsPropertyType(int32_t type)173 inline bool EXPORT IsPropertyType(int32_t type)
174 {
175     return (type >= static_cast<int32_t>(PropertyType::VIDEO_SIZE)) &&
176         (type <= static_cast<int32_t>(PropertyType::WINDOW_SIZE));
177 }
178 
179 enum class EXPORT ChannelType {
180     SOFT_BUS,
181     LEGACY_CHANNEL,
182 };
183 
IsChannelType(int32_t type)184 inline bool EXPORT IsChannelType(int32_t type)
185 {
186     return (type == static_cast<int32_t>(ChannelType::SOFT_BUS)) ||
187         (type == static_cast<int32_t>(ChannelType::LEGACY_CHANNEL));
188 }
189 
190 enum class EXPORT CapabilityType {
191     CAST_PLUS,
192     DLNA,
193 };
194 
195 enum class EXPORT ProtocolType {
196     CAST_PLUS_MIRROR = 1 << 0,
197     CAST_PLUS_STREAM = 1 << 1,
198     MIRACAST = 1 << 2,
199     DLNA = 1 << 3,
200     COOPERATION_LEGACY = 1 << 4,
201     COOPERATION = 1 << 5,
202     HICAR = 1 << 6,
203     SUPER_LAUNCHER = 1 << 7,
204     CAST_COOPERATION = 1 << 8,
205 };
206 
IsProtocolType(int32_t type)207 inline bool EXPORT IsProtocolType(int32_t type)
208 {
209     return (static_cast<uint32_t>(type) & (static_cast<uint32_t>(ProtocolType::CAST_PLUS_MIRROR) |
210         static_cast<uint32_t>(ProtocolType::CAST_PLUS_STREAM) |
211         static_cast<uint32_t>(ProtocolType::MIRACAST) |
212         static_cast<uint32_t>(ProtocolType::DLNA) |
213         static_cast<uint32_t>(ProtocolType::COOPERATION) |
214         static_cast<uint32_t>(ProtocolType::HICAR) |
215         static_cast<uint32_t>(ProtocolType::SUPER_LAUNCHER) |
216         static_cast<uint32_t>(ProtocolType::COOPERATION_LEGACY) |
217         static_cast<uint32_t>(ProtocolType::CAST_COOPERATION))) != 0;
218 }
219 
220 enum class EXPORT EndType {
221     CAST_SINK = 0x10,
222     CAST_SOURCE = 0x11,
223 };
224 
IsEndType(int32_t type)225 inline bool EXPORT IsEndType(int32_t type)
226 {
227     return (type == static_cast<int32_t>(EndType::CAST_SINK)) || (type == static_cast<int32_t>(EndType::CAST_SOURCE));
228 }
229 
230 struct EXPORT DeviceStateInfo {
231     DeviceState deviceState{ DeviceState::DISCONNECTED };
232     std::string deviceId{};
233     EventCode eventCode{ EventCode::DEFAULT_EVENT };
234 };
235 
236 struct EXPORT VideoSize {
237     uint32_t width;
238     uint32_t height;
239 };
240 
241 struct EXPORT WindowProperty {
242     uint32_t startX;
243     uint32_t startY;
244     uint32_t width;
245     uint32_t height;
246 };
247 
248 struct EXPORT PropertyContainer {
249     PropertyType type;
250     union {
251         VideoSize videoSize;
252         uint32_t videoFps;
253         WindowProperty windowProperty;
254     };
255 };
256 
257 enum class EXPORT ColorStandard {
258     BT709 = 1,
259     BT601_PAL = 2,
260     BT601_NTSC = 3,
261     BT2020 = 6,
262 };
263 
IsColorStandard(int32_t color)264 inline bool EXPORT IsColorStandard(int32_t color)
265 {
266     return (color == static_cast<int32_t>(ColorStandard::BT709)) ||
267         (color == static_cast<int32_t>(ColorStandard::BT601_PAL)) ||
268         (color == static_cast<int32_t>(ColorStandard::BT601_NTSC)) ||
269         (color == static_cast<int32_t>(ColorStandard::BT2020));
270 }
271 
272 enum class EXPORT VideoCodecType {
273     H264 = 1,
274     H265 = 2,
275 };
276 
IsVideoCodecType(int32_t type)277 inline bool EXPORT IsVideoCodecType(int32_t type)
278 {
279     return (type == static_cast<int32_t>(VideoCodecType::H264)) || type == static_cast<int32_t>(VideoCodecType::H265);
280 }
281 
282 struct EXPORT AudioProperty {
283     uint32_t sampleRate;
284     uint8_t sampleBitWidth;
285     uint32_t channelConfig;
286     uint32_t bitrate;
287     uint32_t codec;
288 };
289 
290 struct EXPORT VideoProperty {
291     uint32_t videoWidth{ 0 };
292     uint32_t videoHeight{ 0 };
293     uint32_t fps{ 0 };
294     VideoCodecType codecType{ VideoCodecType::H264 };
295     uint32_t gop{ 0 };
296     uint32_t bitrate{ 0 };
297     uint32_t minBitrate{ 0 };
298     uint32_t maxBitrate{ 0 };
299     uint32_t dpi{ 0 };
300     ColorStandard colorStandard{ ColorStandard::BT709 };
301     uint32_t screenWidth{ 0 };
302     uint32_t screenHeight{ 0 };
303     uint32_t profile{ 0 };
304     uint32_t level{ 0 };
305 };
306 
307 struct EXPORT CastSessionProperty {
308     ProtocolType protocolType{ ProtocolType::CAST_PLUS_MIRROR };
309     EndType endType{ EndType::CAST_SINK };
310     AudioProperty audioProperty;
311     VideoProperty videoProperty;
312     WindowProperty windowProperty;
313 };
314 
315 struct EXPORT CastLocalDevice {
316     std::string deviceId;
317     std::string deviceName;
318     DeviceType deviceType;
319     SubDeviceType subDeviceType;
320     std::string ipAddress;
321     TriggerType triggerType;
322     std::string authData;
323 };
324 
325 struct EXPORT AuthInfo {
326     int authMode;
327     uint32_t authCode;
328     std::string deviceId;
329 };
330 
331 struct EXPORT CastRemoteDevice {
332     std::string deviceId;
333     std::string deviceName;
334     DeviceType deviceType;
335     SubDeviceType subDeviceType;
336     std::string ipAddress;
337     ChannelType channelType;
338     CapabilityType capability;
339     std::string networkId{ "" };
340     std::string localIpAddress{ "" };
341     uint32_t sessionKeyLength{ 0 };
342     const uint8_t *sessionKey{ nullptr };
343 };
344 
345 enum class EXPORT CastMode {
346     MIRROR_CAST = 1,
347     APP_CAST = 2,
348 };
349 
350 // Parameters for cast mode
351 const std::string EXPORT KEY_BUNDLE_NAME = "bundleName";
352 const std::string EXPORT KEY_PID = "pid";
353 const std::string EXPORT KEY_UID = "uid";
354 const std::string EXPORT KEY_APP_MIN_COMPATIBLE_VERSION = "minCompatibleVersionCode";
355 const std::string EXPORT KEY_APP_TARGET_VERSION = "targetVersion";
356 const int EXPORT MAX_DEVICE_NUM = 100;
357 const int32_t EXPORT MAX_FILE_NUM = 16 * 1024;
358 
359 enum class EXPORT EventId {
360     EVENT_BEGIN = 1,
361     STREAM_BEGIN = 2000,
362     STEAM_DEVICE_DISCONNECTED,
363     STREAM_END = 2999,
364     EVENT_END = 5000,
365 };
366 
IsEventId(int32_t state)367 inline bool EXPORT IsEventId(int32_t state)
368 {
369     return (state > static_cast<int32_t>(EventId::EVENT_BEGIN)) && (state < static_cast<int32_t>(EventId::EVENT_END));
370 }
371 
372 struct EXPORT MediaInfo {
373     std::string mediaId;
374     std::string mediaName;
375     std::string mediaUrl;
376     std::string mediaType;
377     size_t mediaSize;
378     uint32_t startPosition;
379     uint32_t duration;
380     uint32_t closingCreditsPosition;
381     std::string albumCoverUrl;
382     std::string albumTitle;
383     std::string mediaArtist;
384     std::string lrcUrl;
385     std::string lrcContent;
386     std::string appIconUrl;
387     std::string appName;
388 };
389 
390 struct EXPORT MediaInfoHolder {
391     uint32_t currentIndex;
392     std::vector<MediaInfo> mediaInfoList;
393     uint32_t progressRefreshInterval;
394 };
395 
396 struct EXPORT AppInfo {
397     int32_t appUid;
398     uint32_t appTokenId;
399     int32_t appPid;
400 };
401 
402 // <source file, <fd, target file path>>
403 using FileFdMap = std::map<std::string, std::pair<int, std::string>>;
404 
405 // <fd, file path>
406 using RcvFdFileMap = std::map<int, std::string>;
407 
408 enum class EXPORT PlayerStates {
409     PLAYER_STATE_ERROR = 0,
410     PLAYER_IDLE = 1,
411     PLAYER_INITIALIZED = 2,
412     PLAYER_PREPARING = 3,
413     PLAYER_PREPARED = 4,
414     PLAYER_STARTED = 5,
415     PLAYER_PAUSED = 6,
416     PLAYER_STOPPED = 7,
417     PLAYER_PLAYBACK_COMPLETE = 8,
418     PLAYER_RELEASED = 9,
419     PLAYER_BUFFERING = 100,
420 };
421 
422 enum class EXPORT HmosPlayerStates {
423     STATE_IDLE = 1,
424     STATE_BUFFERING = 2,
425     STATE_READY = 3,
426     STATE_ENDED = 4
427 };
428 
429 enum class EXPORT LoopMode {
430     LOOP_MODE_SEQUENCE = 0,
431     LOOP_MODE_SINGLE = 1,
432     LOOP_MODE_LIST = 2,
433     LOOP_MODE_SHUFFLE = 3
434 };
435 
436 enum class EXPORT PlaybackSpeed {
437     SPEED_FORWARD_0_75_X = 0,
438     SPEED_FORWARD_1_00_X = 1,
439     SPEED_FORWARD_1_25_X = 2,
440     SPEED_FORWARD_1_75_X = 3,
441     SPEED_FORWARD_2_00_X = 4
442 };
443 
444 inline constexpr int EXPORT INVALID_ID = -1;
445 inline constexpr int EXPORT INVALID_PORT = -1;
446 inline constexpr int EXPORT INVALID_VALUE = -1;
447 inline constexpr int EXPORT DECIMALISM = 10;
448 inline constexpr int EXPORT SUBSYS_CASTPLUS_SYS_ABILITY_ID_BEGIN = 0x00010000;
449 inline constexpr int EXPORT CAST_ENGINE_SA_ID = 5526; // 65546
450 inline constexpr int EXPORT SUBSYS_CASTPLUS_SYS_ABILITY_ID_END = 0x0001001f;
451 } // namespace CastEngine
452 } // namespace OHOS
453 
454 #endif
455