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 dfx.
15 * Author: wangxueshuang
16 * Create: 2023-06-05
17 */
18
19 #ifndef CAST_ENGINE_DFX_H
20 #define CAST_ENGINE_DFX_H
21
22 #include <string>
23 #include <cast_engine_common.h>
24 #include "hisysevent.h"
25
26 #include "json.hpp"
27
28 namespace OHOS {
29 namespace CastEngine {
30 using nlohmann::json;
31
32 class CastEngineDfx {
33 public:
34 static void WriteErrorEvent(int32_t errorCode);
35 static void SetStreamInfo(const std::string &streamInfoKey, const std::string &streamInfoValue);
36 static void SetLocalDeviceInfo(const std::string &localDeviceInfoKey, const std::string &localDeviceInfoValue);
37 static void SetRemoteDeviceInfo(const std::string &remoteDeviceInfoKey, const std::string &remoteDeviceInfoValue);
38 static void SetConnectInfo(const std::string &connectInfoKey, const std::string &connectInfoValue);
39 static std::string GetStreamInfo();
40 static std::string GetLocalDeviceInfo();
41 static std::string GetRemoteDeviceInfo();
42 static std::string GetConnectInfo();
43 static std::string GetSequentialId();
44 static std::string GetBizPackageName();
45
46 private:
47 static json jsonSteamInfo_;
48 static json jsonLocalDeviceInfo_;
49 static json jsonRemoteDeviceInfo_;
50 static json jsonConnectInfo_;
51 static const std::string PACKAGE_NAME;
52 static const std::string SEQUENTIAL_ID_CHARS;
53 static const int SN_LENGTH = 32;
54 static const int SEQUENTIAL_ID_CHARS_LENGTH = 62;
55 };
56
57 // discovery fail error code
58 static const int32_t START_DISCOVERY_FAIL = 100;
59
60 // connection fail error code
61 static const int32_t AUTHENTICATE_DEVICE_FAIL = 200;
62 static const int32_t SOURCE_CREATE_SESSION_SERVER_FAIL = 201;
63 static const int32_t SINK_CREATE_SESSION_SERVER_FAIL = 202;
64 static const int32_t OPEN_SESSION_FAIL = 203;
65 static const int32_t SEND_CONSULTION_DATA_FAIL = 204;
66
67 // stream fail error code
68 static const int32_t PLAYER_INIT_FAIL = 300;
69
70 static constexpr char CAST_ENGINE_DFX_DOMAIN_NAME[] = "CAST_ENGINE";
71 static constexpr char ORG_PKG[] = "cast_engine_service";
72 static constexpr char EVENT_NAME[] = "CAST_PLUS_BEHAVIOR";
73 static constexpr char DEVICE_MANAGER_NAME[] = "deviceManager";
74 static constexpr char DSOFTBUS_NAME[] = "dsoftbus";
75 static constexpr char COLLABORATIONFWK_NAME[] = "CollaborationFwk";
76 static constexpr char HUAWEICAST_NAME[] = "com.huawei.hmos.huaweicast";
77
78 enum class BIZSceneStage : int32_t {
79 // scene1
80 START_DISCOVERY = 1,
81 DEVICE_DISCOVERY = 2,
82
83 DEVICE_AUTHENTICATION = 1,
84 ESTABLISH_CONSULT_SESSION = 2,
85 ESTABLISH_RTSP_CHANNEL = 3,
86
87 // scene2
88 ESTABLISH_AUDIO_CHANNEL = 4,
89 ESTABLISH_VIDEO_CHANNEL = 5,
90 ESTABLISH_REVERSE_CHNANEL = 6,
91 CAST_SUCCESS = 7,
92
93 // scene3
94 LOCAL_ESTABLISH_STREAM_CHANNEL = 4,
95 LOCAL_STREAM_PLAY_RESOURCE_SUCCESS = 5,
96
97 // scene4
98 ONLINE_STREAM_PLAY_RESOURCE_SUCCESS = 5,
99
100 // scene5
101 SINK_CONTROL = 1,
102 SOURCE_CONTROL = 2,
103 SINK_RESPONSE = 3,
104 SOURCE_RESPONSE = 4,
105
106 // scene6
107 COOPERATION_ESTABLISH_RTSP_CHANNEL = 1,
108 COOPERATION_ESTABLISH_VIDEO_CHANNEL = 2,
109 COOPERATION_ESTABLISH_REVERSE_CHNANEL = 3,
110 COOPERATION_CAST_SUCCESS = 4,
111
112 // scene7
113 SINK_SEND_REVERSE_EVENT = 1,
114 SOURCE_RECEIVE_REVERSE_EVENT = 2,
115 SOURCE_OUTPUT_VIDEO_FRAME = 3,
116 SINK_RECEIVE_VIDEO_FRAME = 4,
117 SINK_BEGIN_DECODE_VIDEO_FRAME = 5,
118 SINK_DISPLAY_VIDEO_FRAME = 6,
119
120 // scene8
121 START_DISCONNECT = 1,
122 DISCONNECT_END = 2,
123
124 DLNA_DEVICE_DISCOVERY = 501,
125 DLNA_DEVICE_CONNECT = 502,
126 DLNA_DEVICE_CAST = 503,
127 DLNA_ACQUIRE_RESOURCE_FINISH = 504,
128 DLNA_PLAY_RESOURCE_FINISH = 505,
129 MIRACAST_DEVICE_DISCOVERY = 601,
130 MIRACAST_DEVICE_CONNECT = 602,
131 MIRACAST_DATA_CONSULT = 603,
132 MIRACAST_AUDIO_VIDEO_CHANNEL_FINISH = 604,
133 MIRACAST_REVERSE_CHANNEL_FINISH = 605,
134 MIRACAST_AUDIO_VIDEO_PLAY_SUCCESS = 606
135 };
136
137 enum class BIZStateType : int32_t {
138 BIZ_STATE_BEGIN = 1,
139 BIZ_STATE_END
140 };
141
142 enum class StageResType : int32_t {
143 STAGE_RES_IDLE = 0,
144 STAGE_RES_SUCCESS,
145 STAGE_RES_FAILED,
146 STAGE_RES_CANCEL,
147 STAGE_RES_UNKNOWN
148 };
149
150 enum class BIZSceneType : int32_t {
151 DEVICE_DISCOVERY = 1,
152 CAST_MIRROR,
153 CAST_STREAM,
154 ONLINE_CAST_STREAM,
155 DUAL_POINTS_CONTROL,
156 COOPERATION,
157 REVERSE_CONTROL,
158 DEVICE_DISCONNECTED,
159 DLNA,
160 MIRACAST
161 };
162
163 static const uint8_t CAST_ENGINE_SYSTEM_ID = 208;
164 static const uint8_t CAST_ENGINE_CAST_PLUS_MODULE_ID = 10;
GetErrorCode(uint8_t systemID,uint8_t moduleID,uint16_t code)165 inline uint32_t GetErrorCode(uint8_t systemID, uint8_t moduleID, uint16_t code)
166 {
167 const int moduleIndex = 16;
168 const int systemIndex = 21;
169
170 uint32_t errorCode = systemID << systemIndex | moduleID << moduleIndex | code;
171 return errorCode;
172 }
173
GetAnonymousDeviceID(const std::string & deviceId)174 inline std::string GetAnonymousDeviceID(const std::string& deviceId)
175 {
176 const std::size_t minimumLen = 10;
177 const std::size_t subIndex = 5;
178
179 if (deviceId.empty() || deviceId.length() < minimumLen) {
180 return "unknown";
181 }
182 return deviceId.substr(0, subIndex) + "**" + deviceId.substr(deviceId.length() - subIndex);
183 }
184
185 int GetBIZSceneType(int protocols);
186
187 static int32_t CAST_RADAR_SUCCESS = 0;
188 using RadarParamInt = std::map<std::string, int32_t>;
189 using RadarParamString = std::map<std::string, std::string>;
190 void HiSysEventWriteWrap(const std::string& funcName, const RadarParamInt& paramInt,
191 const RadarParamString& paramStr);
192 } // namespace CastEngine
193 } // namespace OHOS
194
195 #endif // CAST_ENGINE_DFX_H
196