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