1 /* 2 * Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development 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 #ifndef WFD_SINK_HISYS_EVENT_H 16 #define WFD_SINK_HISYS_EVENT_H 17 18 #include <map> 19 #include <mutex> 20 #include <string> 21 22 namespace OHOS { 23 namespace Sharing { 24 // 定义业务场景枚举 25 enum class SinkBizScene : int32_t { 26 ESTABLISH_MIRRORING = 1, // 建立miracast镜像投屏 27 MIRRORING_STABILITY = 2, // miracast镜像投屏稳定性 28 DISCONNECT_MIRRORING = 3 // 断开miracast镜像投屏 29 }; 30 31 // 定义业务阶段枚举 32 enum class SinkStage : int32_t { 33 // 建立miracast镜像投屏阶段 34 P2P_CONNECT_SUCCESS = 1, 35 SESSION_NEGOTIATION = 2, 36 SEND_M7_MSG = 3, 37 RECEIVE_DATA = 4, 38 FIRST_FRAME_PROCESSED = 5, 39 // miracast镜像投屏稳定性阶段 40 RECEIVE_DATA_STABILITY = 1, 41 RTP_DEMUX = 2, 42 VIDEO_DECODE = 3, 43 AUDIO_DECODE = 4, 44 AV_SYNC_PROCESS = 5, 45 // 断开miracast镜像投屏阶段 46 RECEIVE_DISCONNECT_EVENT = 1, 47 DISCONNECT_COMPLETE = 2 48 }; 49 50 // 定义阶段结果枚举 51 enum class SinkStageRes : int32_t { 52 START = 0, 53 SUCCESS = 1, 54 FAIL = 2, 55 CANCEL = 3 56 }; 57 58 enum class SinkBIZState : int32_t { 59 BIZ_STATE_BEGIN = 1, 60 BIZ_STATE_END = 2 61 }; 62 63 // 定义错误码枚举 64 enum class SinkErrorCode : int32_t { 65 // P2P连接失败错误码 66 WIFI_DISPLAY_P2P_FAILED = 476119140, 67 WIFI_DISPLAY_P2P_OPT_NOT_SUPPORTED, 68 WIFI_DISPLAY_P2P_OPT_INVALID_PARAM, 69 WIFI_DISPLAY_P2P_OPT_FORBID_AIRPLANE, 70 WIFI_DISPLAY_P2P_OPT_FORBID_POWSAVING, 71 WIFI_DISPLAY_P2P_OPT_PERMISSION_DENIED, 72 WIFI_DISPLAY_P2P_OPT_OPEN_FAIL_WHEN_CLOSING, 73 WIFI_DISPLAY_P2P_OPT_P2P_NOT_OPENED, 74 WIFI_DISPLAY_P2P_DISCONNECTED_STATE_CLOSED, 75 WIFI_DISPLAY_P2P_GCJOINGROUP_TIMEOUT, 76 //会话协商错误码 77 WIFI_DISPLAY_RTSP_KEEPALIVE_TIMEOUT = 476184676, 78 WIFI_DISPLAY_RTSP_FAILED, 79 WIFI_DISPLAY_TCP_FAILED, 80 WIFI_DISPLAY_UDP_FAILED, 81 WIFI_DISPLAY_VTP_FAILED, 82 WIFI_DISPLAY_DATA_INVALID, 83 WIFI_DISPLAY_LOCAL_IP_FAILED, 84 //音视频解码错误码 85 WIFI_DISPLAY_RTP_DATA_INVALID = 476250212, 86 WIFI_DISPLAY_VIDEO_DECODE_FAILED, 87 WIFI_DISPLAY_AUDIO_DECODE_FAILED, 88 WIFI_DISPLAY_VIDEO_DECODE_TIMEOUT, 89 WIFI_DISPLAY_AUDIO_DECODE_TIMEOUT, 90 WIFI_DISPLAY_SYNC_FAILED, 91 //系统模块错误码 92 WIFI_DISPLAY_GENERAL_ERROR = 476315748, 93 WIFI_DISPLAY_BAD_PARAMETER, 94 WIFI_DISPLAY_ADD_SURFACE_ERROR, 95 WIFI_DISPLAY_AGENT_ERROR, 96 WIFI_DISPLAY_CONSUMER_ERROR 97 }; 98 99 enum class MediaReportType : int32_t { 100 VIDEO, 101 AUDIO 102 }; 103 104 class WfdSinkHiSysEvent { 105 public: 106 107 WfdSinkHiSysEvent(const WfdSinkHiSysEvent&) = delete; 108 WfdSinkHiSysEvent& operator=(const WfdSinkHiSysEvent&) = delete; 109 110 static WfdSinkHiSysEvent &GetInstance(); 111 112 struct SinkHisyseventDevInfo { 113 std::string localNetId = ""; 114 std::string localWifiMac = ""; 115 std::string localDevName = ""; 116 std::string localIp = ""; 117 std::string peerNetId = ""; 118 std::string peerWifiMac = ""; 119 std::string peerIp = ""; 120 std::string peerDevName = ""; 121 }; 122 //获取对端设备信息 123 void SetHiSysEventDevInfo(SinkHisyseventDevInfo devInfo); 124 125 void GetStartTime(std::chrono::system_clock::time_point startTime); 126 127 void ReportEstablishMirroringError(const std::string &funcName, const std::string &toCallpkg, 128 SinkStage sinkStage, SinkErrorCode errorCode, int32_t duration); 129 130 void ReportStabilityError(const std::string &funcName, const std::string &toCallpkg, 131 SinkStage sinkStage, SinkErrorCode errorCode); 132 133 void ReportDisconnectError(const std::string &funcName, const std::string &toCallpkg, 134 SinkStage sinkStage, SinkErrorCode errorCode, int32_t duration); 135 136 // 开始打点 137 void StartReport(const std::string &funcName, const std::string &toCallpkg, 138 SinkStage sinkStage, SinkStageRes sinkStageRes); 139 140 void Report(const std::string &funcName, const std::string &toCallpkg, 141 SinkStage sinkStage, SinkStageRes sinkStageRes); 142 143 void FirstSceneEndReport(const std::string &funcName, const std::string &toCallpkg, 144 SinkStage sinkStage, SinkStageRes sinkStageRes); 145 146 void ThirdSceneEndReport(const std::string &funcName, const std::string &toCallpkg, SinkStage sinkStage); 147 148 void ReportError(const std::string &funcName, const std::string &toCallpkg, 149 SinkStage sinkStage, SinkErrorCode errorCode); 150 151 void P2PReportError(const std::string &funcName, SinkErrorCode errorCode); 152 153 //更换场景 154 void ChangeHisysEventScene(SinkBizScene scene); 155 156 int32_t GetCurrentScene(); 157 158 void RecordMediaDecodeStartTime(MediaReportType type, uint64_t pts); 159 160 void MediaDecodeTimProc(MediaReportType type, uint64_t pts); 161 162 void Reset(); 163 164 private: 165 uint64_t GetCurTimeInUs(); 166 void ReportDecodeError(MediaReportType type); 167 void RecordDecordStartTime(uint64_t pts, std::map<uint64_t, uint64_t>& decodeMap); 168 void ReportDecodeTime(uint64_t pts, std::map<uint64_t, uint64_t>& decodeMap, MediaReportType type); 169 170 private: 171 WfdSinkHiSysEvent() = default; 172 ~ WfdSinkHiSysEvent() = default; 173 SinkHisyseventDevInfo devInfo_; 174 175 int32_t sinkBizScene_ = 0; 176 bool hiSysEventStart_ = true; 177 int32_t startTime_ = 0; 178 179 uint32_t audioFreezeCount_ = 0; 180 uint32_t videoFreezeCount_ = 0; 181 int64_t lastFreezeReportTime_ = 0; 182 bool isFreezeReportInTenMinute = false; 183 std::map<uint64_t, uint64_t> audioDecoderTime_{}; 184 std::map<uint64_t, uint64_t> videoDecoderTime_{}; 185 std::mutex decodeMutex_{}; 186 }; 187 188 } // namespace Sharing 189 } // namespace OHOS 190 191 #endif // WFD_SINK_HISYS_EVENT_H