• 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 #include "cast_data_source.h"
26 
27 #include <message_parcel.h>
28 #define EXPORT __attribute__((visibility("default")))
29 
30 namespace OHOS {
31 namespace CastEngine {
32 enum class EXPORT DeviceType {
33     DEVICE_OTHERS = 0,
34     DEVICE_SCREEN_PLAYER = 1,
35     DEVICE_HW_TV = 2,
36     DEVICE_SOUND_BOX = 3,
37     DEVICE_HICAR = 4,
38     DEVICE_MATEBOOK = 5,
39     DEVICE_PAD = 6,
40     DEVICE_CAST_PLUS = 7,
41     DEVICE_TYPE_2IN1 = 8,
42     DEVICE_SMART_SCREEN_UNF = 9,
43     DEVICE_PAD_IN_CAR = 10,
44     DEVICE_SUPER_LAUNCHER = 11,
45     DEVICE_CAR_MULTI_SCREEN_PLAY = 12,
46     DEVICE_MIRACAST = 13,
47 };
48 
49 inline constexpr int EXPORT INVALID_ID = -1;
50 
IsDeviceType(int32_t type)51 inline bool EXPORT IsDeviceType(int32_t type)
52 {
53     return (type >= static_cast<int32_t>(DeviceType::DEVICE_OTHERS)) &&
54         (type <= static_cast<int32_t>(DeviceType::DEVICE_MIRACAST));
55 }
56 
57 enum class EXPORT SubDeviceType {
58     SUB_DEVICE_DEFAULT = 0,
59     SUB_DEVICE_MATEBOOK_PAD = 51,
60     SUB_DEVICE_CAST_PLUS_WHITEBOARD = 0x00B2
61 };
62 
IsSubDeviceType(int32_t type)63 inline bool EXPORT IsSubDeviceType(int32_t type)
64 {
65     return (type == static_cast<int32_t>(SubDeviceType::SUB_DEVICE_DEFAULT)) ||
66         (type == static_cast<int32_t>(SubDeviceType::SUB_DEVICE_MATEBOOK_PAD)) ||
67         (type == static_cast<int32_t>(SubDeviceType::SUB_DEVICE_CAST_PLUS_WHITEBOARD));
68 }
69 
70 enum class EXPORT TriggerType {
71     UNSPEC_TAG = 0,
72     PASSIVE_MATCH_TAG = 1,
73     ACTIVE_MATCH_TAG = 2,
74     PASSIVE_BIND_TAG = 3,
75 };
76 
IsTriggerType(int32_t type)77 inline bool EXPORT IsTriggerType(int32_t type)
78 {
79     return (type >= static_cast<int32_t>(TriggerType::UNSPEC_TAG)) &&
80         (type <= static_cast<int32_t>(TriggerType::PASSIVE_BIND_TAG));
81 }
82 
83 enum class EXPORT DeviceState {
84     CONNECTING,
85     CONNECTED,
86     PAUSED,
87     PLAYING,
88     DISCONNECTING,
89     DISCONNECTED,
90     STREAM,
91     MIRROR_TO_UI,
92     UI_TO_MIRROR,
93     UICAST,
94     AUTHING,
95     MIRROR_TO_STREAM,
96     STREAM_TO_MIRROR,
97     DEVICE_STATE_MAX,
98 };
99 
100 enum EXPORT DeviceRemoveAction {
101     // device remove and stop playing.
102     ACTION_DISCONNECT = 0,
103     // device remove and keep playing.
104     ACTION_CONTINUE_PLAY = 1,
105 };
106 
107 enum class EXPORT DeviceGrabState {
108     GRAB_ALLOWED,
109     GRAB_NOT_ALLOWED,
110     GRABING,
111     NO_GRAB,
112 };
113 
114 enum ConnectStageResult : int32_t {
115     AUTHING,
116     AUTH_SUCCESS,
117     AUTH_FAILED,
118     CONNECT_START,
119     CONNECT_FAIL,
120     CONNECT_SUCCESS,
121     DISCONNECT_START,
122 };
123 
124 /*
125  * reason code for right process or user action
126  */
127 enum EXPORT ReasonCode {
128     REASON_DEFAULT = 0,
129     // Peer of sink click "TRUST", both permanently and temporarily.
130     REASON_TRUST_BY_SINK = 10000,
131     // Peer of source click "CANCEL pin code input".
132     REASON_CANCEL_BY_SOURCE = 10001,
133     // Peer of source input correct pin code and  click "CONFIRM".
134     REASON_BIND_COMPLETED = 10002,
135     // Start to show THREE-STATE window.
136     REASON_SHOW_TRUST_SELECT_UI = 10003,
137     // Process of bind is interrupted by user.
138     REASON_STOP_BIND_BY_SOURCE = 10004,
139     // Peer of source input wrong pin code over 3 times.
140     REASON_PIN_CODE_OVER_RETRY = 10005,
141     // Peer of sink click "CANCEL" during peer of source input pin code.
142     REASON_CANCEL_BY_SINK = 10006,
143     // Peer of sink click "DISTRUST" in THREE-STATE window.
144     REASON_DISTRUST_BY_SINK = 10007,
145     // user no action, so timeout
146     REASON_USER_TIMEOUT = 10008,
147     // Peer device is busy
148     REASON_DEVICE_IS_BUSY = 10009,
149 };
150 
151 const EXPORT std::array<std::string, static_cast<size_t>(DeviceState::DEVICE_STATE_MAX)> DEVICE_STATE_STRING = {
152     "CONNECTING", "CONNECTED", "PAUSED", "PLAYING", "DISCONNECTING", "DISCONNECTED", "STREAM",
153     "MIRROR_TO_UI", "UI_TO_MIRROR", "UICAST", "AUTHING",
154 };
155 
IsDeviceState(int32_t state)156 inline bool EXPORT IsDeviceState(int32_t state)
157 {
158     return (state >= static_cast<int32_t>(DeviceState::CONNECTING)) &&
159         (state < static_cast<int32_t>(DeviceState::DEVICE_STATE_MAX));
160 }
161 
162 enum class EXPORT ServiceStatus {
163     DISCONNECTED,
164     DISCONNECTING,
165     CONNECTING,
166     CONNECTED,
167 };
168 
IsServiceStatus(int32_t status)169 inline bool EXPORT IsServiceStatus(int32_t status)
170 {
171     return (status >= static_cast<int32_t>(ServiceStatus::DISCONNECTED)) &&
172         (status <= static_cast<int32_t>(ServiceStatus::CONNECTED));
173 }
174 
175 enum class EXPORT DeviceStatusState {
176     DEVICE_AVAILABLE,
177     DEVICE_CONNECTED,
178     DEVICE_DISCONNECTED,
179     DEVICE_CONNECT_REQ,
180 };
181 
IsDeviceStatus(int32_t status)182 inline bool EXPORT IsDeviceStatus(int32_t status)
183 {
184     return (status >= static_cast<int32_t>(DeviceStatusState::DEVICE_AVAILABLE)) &&
185         (status <= static_cast<int32_t>(DeviceStatusState::DEVICE_CONNECT_REQ));
186 }
187 
188 enum class EXPORT PropertyType {
189     VIDEO_SIZE,
190     VIDEO_FPS,
191     WINDOW_SIZE,
192 };
193 
IsPropertyType(int32_t type)194 inline bool EXPORT IsPropertyType(int32_t type)
195 {
196     return (type >= static_cast<int32_t>(PropertyType::VIDEO_SIZE)) &&
197         (type <= static_cast<int32_t>(PropertyType::WINDOW_SIZE));
198 }
199 
200 enum class EXPORT ChannelType {
201     SOFT_BUS,
202     LEGACY_CHANNEL,
203 };
204 
IsChannelType(int32_t type)205 inline bool EXPORT IsChannelType(int32_t type)
206 {
207     return (type == static_cast<int32_t>(ChannelType::SOFT_BUS)) ||
208         (type == static_cast<int32_t>(ChannelType::LEGACY_CHANNEL));
209 }
210 
211 enum class EXPORT CapabilityType {
212     CAST_PLUS,
213     DLNA,
214     CAST_AND_DLNA,
215 };
216 
IsCapabilityType(int32_t type)217 inline bool EXPORT IsCapabilityType(int32_t type)
218 {
219     return (type == static_cast<int32_t>(CapabilityType::CAST_PLUS)) ||
220         (type == static_cast<int32_t>(CapabilityType::DLNA)) ||
221         (type == static_cast<int32_t>(CapabilityType::CAST_AND_DLNA));
222 }
223 
224 enum class EXPORT ProtocolType {
225     CAST_PLUS_MIRROR = 1 << 0,
226     CAST_PLUS_STREAM = 1 << 1,
227     DLNA = 1 << 2,
228     MIRACAST = 1 << 3,
229     COOPERATION = 1 << 5,
230     HICAR = 1 << 6,
231     SUPER_LAUNCHER = 1 << 7,
232 };
233 
IsProtocolType(int32_t type)234 inline bool EXPORT IsProtocolType(int32_t type)
235 {
236     return (static_cast<uint32_t>(type) & (static_cast<uint32_t>(ProtocolType::CAST_PLUS_MIRROR) |
237         static_cast<uint32_t>(ProtocolType::CAST_PLUS_STREAM) |
238         static_cast<uint32_t>(ProtocolType::MIRACAST) |
239         static_cast<uint32_t>(ProtocolType::DLNA) |
240         static_cast<uint32_t>(ProtocolType::COOPERATION) |
241         static_cast<uint32_t>(ProtocolType::HICAR) |
242         static_cast<uint32_t>(ProtocolType::SUPER_LAUNCHER))) != 0;
243 }
244 
245 enum class EXPORT EndType {
246     CAST_SINK = 0x10,
247     CAST_SOURCE = 0x11,
248 };
249 
IsEndType(int32_t type)250 inline bool EXPORT IsEndType(int32_t type)
251 {
252     return (type == static_cast<int32_t>(EndType::CAST_SINK)) || (type == static_cast<int32_t>(EndType::CAST_SOURCE));
253 }
254 
255 struct EXPORT DeviceStateInfo {
256     DeviceState deviceState{ DeviceState::DISCONNECTED };
257     std::string deviceId{};
258     ReasonCode reasonCode{ ReasonCode::REASON_DEFAULT };
259 };
260 
261 struct EXPORT VideoSize {
262     uint32_t width;
263     uint32_t height;
264 };
265 
266 struct EXPORT WindowProperty {
267     uint32_t startX;
268     uint32_t startY;
269     uint32_t width;
270     uint32_t height;
271 };
272 
273 struct EXPORT PropertyContainer {
274     PropertyType type;
275     union {
276         VideoSize videoSize;
277         uint32_t videoFps;
278         WindowProperty windowProperty;
279     };
280 };
281 
282 enum class EXPORT ColorStandard {
283     BT709 = 1,
284     BT601_PAL = 2,
285     BT601_NTSC = 3,
286     BT2020 = 6,
287 };
288 
IsColorStandard(int32_t color)289 inline bool EXPORT IsColorStandard(int32_t color)
290 {
291     return (color == static_cast<int32_t>(ColorStandard::BT709)) ||
292         (color == static_cast<int32_t>(ColorStandard::BT601_PAL)) ||
293         (color == static_cast<int32_t>(ColorStandard::BT601_NTSC)) ||
294         (color == static_cast<int32_t>(ColorStandard::BT2020));
295 }
296 
297 enum class EXPORT VideoCodecType {
298     H264 = 1,
299     H265 = 2,
300 };
301 
IsVideoCodecType(int32_t type)302 inline bool EXPORT IsVideoCodecType(int32_t type)
303 {
304     return (type == static_cast<int32_t>(VideoCodecType::H264)) || type == static_cast<int32_t>(VideoCodecType::H265);
305 }
306 
307 struct EXPORT AudioProperty {
308     uint32_t sampleRate{ 0 };
309     uint8_t sampleBitWidth{ 0 };
310     uint32_t channelConfig{ 0 };
311     uint32_t bitrate{ 0 };
312     uint32_t codec{ 0 };
313 };
314 
315 struct EXPORT VideoProperty {
316     uint32_t videoWidth{ 0 };
317     uint32_t videoHeight{ 0 };
318     uint32_t fps{ 0 };
319     VideoCodecType codecType{ VideoCodecType::H264 };
320     int gop{ 0 };
321     uint32_t bitrate{ 0 };
322     uint32_t minBitrate{ 0 };
323     uint32_t maxBitrate{ 0 };
324     uint32_t dpi{ 0 };
325     ColorStandard colorStandard{ ColorStandard::BT709 };
326     uint32_t screenWidth{ 0 };
327     uint32_t screenHeight{ 0 };
328     uint32_t profile{ 0 };
329     uint32_t level{ 0 };
330 };
331 
332 typedef struct EXPORT {
333     int32_t uicastMainVersion;
334     int32_t uicastSubVersion;
335     int32_t appApiVersion;
336     uint32_t capability;
337     uint8_t featureEnable;
338 } UICastCapability;
339 
340 struct EXPORT CastSessionProperty {
341     ProtocolType protocolType{ ProtocolType::CAST_PLUS_MIRROR };
342     EndType endType{ EndType::CAST_SINK };
343     AudioProperty audioProperty;
344     VideoProperty videoProperty;
345     WindowProperty windowProperty;
346 };
347 
348 struct EXPORT CastLocalDevice {
349     std::string deviceId;
350     std::string deviceName;
351     DeviceType deviceType;
352     SubDeviceType subDeviceType;
353     std::string ipAddress;
354     TriggerType triggerType;
355     std::string authData;
356 };
357 
358 struct EXPORT AuthInfo {
359     int authMode;
360     uint32_t authCode;
361     std::string deviceId;
362 };
363 
364 struct EXPORT CastRemoteDevice {
365     std::string deviceId;
366     std::string deviceName;
367     DeviceType deviceType;
368     SubDeviceType subDeviceType;
369     std::string ipAddress;
370     ChannelType channelType;
371     CapabilityType capability;
372     uint32_t protocolCapabilities{ 0 };
373     std::string networkId{ "" };
374     std::string localIpAddress{ "" };
375     uint32_t sessionKeyLength{ 0 };
376     const uint8_t *sessionKey{ nullptr };
377     bool isLeagacy{ false };
378     int sessionId{ INVALID_ID };
379     std::vector<std::string> drmCapabilities;
380     uint32_t mediumTypes{ 0 };
381     std::string modelName;
382     std::string manufacturerName;
383     bool isTrushed;
384 };
385 
386 enum class EXPORT CastMode {
387     MIRROR_CAST = 1,
388     APP_CAST = 2,
389 };
390 
391 enum class EXPORT NotifyMediumType {
392     BLE = 1 << 0,
393     COAP = 1 << 1,
394 };
395 
396 // Parameters for cast mode
397 const std::string EXPORT KEY_BUNDLE_NAME = "bundleName";
398 const std::string EXPORT KEY_PID = "pid";
399 const std::string EXPORT KEY_UID = "uid";
400 const std::string EXPORT KEY_APP_MIN_COMPATIBLE_VERSION = "minCompatibleVersionCode";
401 const std::string EXPORT KEY_APP_TARGET_VERSION = "targetVersion";
402 const int EXPORT MAX_DEVICE_NUM = 100;
403 const int32_t EXPORT MAX_FILE_NUM = 16 * 1024;
404 
405 enum class EXPORT EventId {
406     EVENT_BEGIN = 1,
407     MIRROR_BEGIN = 1000,
408     MIRROR_SUPER_LAUNCHER_DISPLAY_CREATED,
409     MIRROR_HICAR_DISPLAY_CREATED,
410     MIRROR_HICAR_NOTIFY_SCREEN_PARAM,
411     CAST_CAPABILITY,
412     FIRST_FRAME_RENDER,
413     MIRROR_END = 1999,
414     STREAM_BEGIN = 2000,
415     STEAM_DEVICE_DISCONNECTED,
416     STREAM_END = 2999,
417     UICAST_BEGIN = 3000,
418     UICAST_NOTIFY_SWITCH_TO_UICAST,
419     UICAST_NOTIFY_SWITCH_TO_MIRROR,
420     UICAST_REQUEST_SOURCE_APP_RESOURCE,
421     UICAST_ACE_TRANS_FILES_FINISH,
422     UICAST_FIRST_RENDER_READY,
423     UICAST_SINK_PAGE_READY,
424     UICAST_DELIVER_SOURCE_PACKAGE_NAME,
425     UICAST_APP_TURN_TO_FOREGROUND,
426     UICAST_NOTIFY_UICAST_EXIT,
427     UICAST_EXCEPTION_OCCUR,
428     UICAST_NOTIFY_RESOURCE_PATH,
429     UICAST_RCV_RESOURCE_PATH,
430     UICAST_NOTIFY_DUMP_UITREE,
431     UICAST_END = 3999,
432     EVENT_END = 5000,
433 };
434 
IsEventId(int32_t state)435 inline bool EXPORT IsEventId(int32_t state)
436 {
437     return (state > static_cast<int32_t>(EventId::EVENT_BEGIN)) && (state < static_cast<int32_t>(EventId::EVENT_END));
438 }
439 
440 struct EXPORT MediaInfo {
441     std::string mediaId{ "" };
442     std::string mediaName{ "" };
443     std::string mediaUrl{ "" };
444     std::string mediaType{ "" };
445     size_t mediaSize{ 0 };
446     uint32_t startPosition{ 0 };
447     uint32_t duration{ 0 };
448     uint32_t closingCreditsPosition{ 0 };
449     std::string albumCoverUrl{ "" };
450     std::string albumTitle{ "" };
451     std::string mediaArtist{ "" };
452     std::string lrcUrl{ "" };
453     std::string lrcContent{ "" };
454     std::string appIconUrl{ "" };
455     std::string appName{ "" };
456     std::string drmType;
457     std::shared_ptr<ICastDataSource> dataSrc;
458 };
459 
460 struct EXPORT MediaInfoHolder {
461     uint32_t currentIndex;
462     std::vector<MediaInfo> mediaInfoList;
463     uint32_t progressRefreshInterval;
464 };
465 
466 struct EXPORT AppInfo {
467     int32_t appUid;
468     uint32_t appTokenId;
469     int32_t appPid;
470 };
471 
472 // <source file, <fd, target file path>>
473 using FileFdMap = std::map<std::string, std::pair<int, std::string>>;
474 
475 // <fd, file path>
476 using RcvFdFileMap = std::map<int, std::string>;
477 
478 enum class EXPORT PlayerStates {
479     PLAYER_STATE_ERROR = 0,
480     PLAYER_IDLE = 1,
481     PLAYER_INITIALIZED = 2,
482     PLAYER_PREPARING = 3,
483     PLAYER_PREPARED = 4,
484     PLAYER_STARTED = 5,
485     PLAYER_PAUSED = 6,
486     PLAYER_STOPPED = 7,
487     PLAYER_PLAYBACK_COMPLETE = 8,
488     PLAYER_RELEASED = 9,
489     PLAYER_BUFFERING = 100,
490 };
491 
492 enum class EXPORT HmosPlayerStates {
493     STATE_IDLE = 1,
494     STATE_BUFFERING = 2,
495     STATE_READY = 3,
496     STATE_ENDED = 4
497 };
498 
499 enum class EXPORT LoopMode {
500     LOOP_MODE_SEQUENCE = 0,
501     LOOP_MODE_SINGLE = 1,
502     LOOP_MODE_LIST = 2,
503     LOOP_MODE_SHUFFLE = 3
504 };
505 
506 struct EXPORT StreamCapability {
507     bool isPlaySupported{ false };
508     bool isPauseSupported{ false };
509     bool isStopSupported{ false };
510     bool isNextSupported{ false };
511     bool isPreviousSupported{ false };
512     bool isSeekSupported{ false };
513     bool isFastForwardSupported{ false };
514     bool isFastRewindSupported{ false };
515     bool isLoopModeSupported{ false };
516     bool isToggleFavoriteSupported{ false };
517     bool isSetVolumeSupported{ false };
518 };
519 
520 enum class EXPORT PlaybackSpeed {
521     SPEED_FORWARD_0_75_X = 0,
522     SPEED_FORWARD_1_00_X = 1,
523     SPEED_FORWARD_1_25_X = 2,
524     SPEED_FORWARD_1_75_X = 3,
525     SPEED_FORWARD_2_00_X = 4,
526     SPEED_FORWARD_0_50_X = 5,
527     SPEED_FORWARD_1_50_X = 6,
528 };
529 
530 enum class EXPORT LogCodeId {
531     OK = 0,
532     FULL = 1,
533     WRITE_FAIL = 2,
534     SEEK_FAIL = 3,
535     STOP_INDICATE = 4,
536     STOP_REPEAT = 5,
537     START_REPEAT = 6,
538     NOT_INIT = 7,
539     UID_MISMATCH = 8,
540 };
541 
542 inline constexpr int EXPORT INVALID_PORT = -1;
543 inline constexpr int EXPORT INVALID_VALUE = -1;
544 inline constexpr int EXPORT DECIMALISM = 10;
545 inline constexpr int EXPORT SUBSYS_CASTPLUS_SYS_ABILITY_ID_BEGIN = 0x00010000;
546 inline constexpr int EXPORT CAST_ENGINE_SA_ID = 5526; // cast_engine_service sa_id is 5526
547 inline constexpr int EXPORT SUBSYS_CASTPLUS_SYS_ABILITY_ID_END = 0x0001001f;
548 inline constexpr int EXPORT S_TO_MS = 1000;
549 } // namespace CastEngine
550 } // namespace OHOS
551 
552 #endif
553