• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "sharing_sink_hisysevent.h"
17 #include "hisysevent.h"
18 #include "sharing_log.h"
19 #include "utils/utils.h"
20 
21 namespace OHOS {
22 namespace Sharing {
23 
24 static constexpr char SHARING_SINK_DFX_DOMAIN_NAME[] = "WIFI_DISPLAY";
25 static constexpr char SHARING_SINK_EVENT_NAME[] = "MIRACAST_SINK_BEHAVIOR";
26 static constexpr char SHARING_SINK_ORG_PKG[] = "wifi_display_sink";
27 static constexpr char SHARING_SINK_HOST_PKG[] = "cast_engine_service";
28 static constexpr char SHARING_SINK_LOCAL_DEV_TYPE[] = "09C";
29 static constexpr uint8_t DECODE_TIME_MAP_CAPACITY = 60;
30 static constexpr int32_t DECODE_TIME_OUT = 300 * 1000; // 300ms
31 static constexpr uint8_t FREEZE_COUNT = 5;
32 static constexpr int32_t REPORT_INTERVAL_MS = 10 * 60 * 1000; // 10min
33 
GetInstance()34 WfdSinkHiSysEvent& WfdSinkHiSysEvent::GetInstance()
35 {
36     static WfdSinkHiSysEvent instance;
37     return instance;
38 }
39 
SetHiSysEventDevInfo(WfdSinkHiSysEvent::SinkHisyseventDevInfo devInfo)40 void WfdSinkHiSysEvent::SetHiSysEventDevInfo(WfdSinkHiSysEvent::SinkHisyseventDevInfo devInfo)
41 {
42     devInfo_.localDevName = GetAnonyDevName(devInfo.localDevName).c_str();
43     devInfo_.localIp = GetAnonymousIp(devInfo.localIp).c_str();
44     devInfo_.localWifiMac = GetAnonymousMAC(devInfo.localWifiMac).c_str();
45     devInfo_.localNetId = devInfo.localNetId;
46     devInfo_.peerDevName = GetAnonyDevName(devInfo.peerDevName).c_str();
47     devInfo_.peerIp = GetAnonymousIp(devInfo.peerIp).c_str();
48     devInfo_.peerWifiMac = GetAnonymousMAC(devInfo.peerWifiMac).c_str();
49     devInfo_.peerNetId = devInfo.peerNetId;
50 }
51 
GetStartTime(std::chrono::system_clock::time_point startTime)52 void WfdSinkHiSysEvent::GetStartTime(std::chrono::system_clock::time_point startTime)
53 {
54     startTime_ = std::chrono::duration_cast<std::chrono::seconds>(startTime.time_since_epoch()).count();
55 }
56 
ChangeHisysEventScene(SinkBizScene scene)57 void WfdSinkHiSysEvent::ChangeHisysEventScene(SinkBizScene scene)
58 {
59     sinkBizScene_ = static_cast<int32_t>(scene);
60 }
61 
StartReport(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage,SinkStageRes sinkStageRes)62 void WfdSinkHiSysEvent::StartReport(const std::string &funcName, const std::string &toCallpkg,
63                                     SinkStage sinkStage, SinkStageRes sinkStageRes)
64 {
65     if (sinkBizScene_ == static_cast<int32_t>(SinkBizScene::ESTABLISH_MIRRORING)) {
66         hiSysEventStart_ = true;
67         Reset();
68     }
69     if (hiSysEventStart_ == false) {
70         SHARING_LOGE("func:%{public}s, sinkStage:%{public}d, scece is Invalid", funcName.c_str(), sinkStage);
71         return;
72     }
73     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
74                     "FUNC_NAME", funcName.c_str(),
75                     "BIZ_SCENE", sinkBizScene_,
76                     "BIZ_STAGE", static_cast<int32_t>(sinkStage),
77                     "STAGE_RES", static_cast<int32_t>(sinkStageRes),
78                     "BIZ_STATE", static_cast<int32_t>(SinkBIZState::BIZ_STATE_BEGIN),
79                     "ORG_PKG", SHARING_SINK_ORG_PKG,
80                     "HOST_PKG", SHARING_SINK_HOST_PKG,
81                     "TO_CALL_PKG", toCallpkg.c_str(),
82                     "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
83                     "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
84                     "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
85                     "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
86                     "LOCAL_IP", devInfo_.localIp.c_str(),
87                     "PEER_NET_ID", devInfo_.peerNetId.c_str(),
88                     "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
89                     "PEER_IP", devInfo_.peerIp.c_str(),
90                     "PEER_DEV_NAME", devInfo_.peerDevName.c_str());
91 }
92 
Report(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage,SinkStageRes sinkStageRes)93 void WfdSinkHiSysEvent::Report(const std::string &funcName, const std::string &toCallpkg,
94                                SinkStage sinkStage, SinkStageRes sinkStageRes)
95 {
96     if (hiSysEventStart_ == false) {
97         SHARING_LOGE("func:%{public}s, sinkStage:%{public}d, scece is Invalid", funcName.c_str(), sinkStage);
98         return;
99     }
100     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
101                     "FUNC_NAME", funcName.c_str(),
102                     "BIZ_SCENE", sinkBizScene_,
103                     "BIZ_STAGE", static_cast<int32_t>(sinkStage),
104                     "STAGE_RES", static_cast<int32_t>(sinkStageRes),
105                     "ORG_PKG", SHARING_SINK_ORG_PKG,
106                     "HOST_PKG", SHARING_SINK_HOST_PKG,
107                     "TO_CALL_PKG", toCallpkg.c_str(),
108                     "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
109                     "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
110                     "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
111                     "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
112                     "LOCAL_IP", devInfo_.localIp.c_str(),
113                     "PEER_NET_ID", devInfo_.peerNetId.c_str(),
114                     "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
115                     "PEER_IP", devInfo_.peerIp.c_str(),
116                     "PEER_DEV_NAME", devInfo_.peerDevName.c_str());
117 }
118 
FirstSceneEndReport(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage,SinkStageRes sinkStageRes)119 void WfdSinkHiSysEvent::FirstSceneEndReport(const std::string &funcName, const std::string &toCallpkg,
120                                             SinkStage sinkStage, SinkStageRes sinkStageRes)
121 {
122     if (hiSysEventStart_ == false) {
123         SHARING_LOGE("func:%{public}s, sinkStage:%{public}d, scece is Invalid", funcName.c_str(), sinkStage);
124         return;
125     }
126     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
127                     "FUNC_NAME", funcName.c_str(),
128                     "BIZ_SCENE", sinkBizScene_,
129                     "BIZ_STAGE", static_cast<int32_t>(sinkStage),
130                     "STAGE_RES", static_cast<int32_t>(sinkStageRes),
131                     "BIZ_STATE", static_cast<int32_t>(SinkBIZState::BIZ_STATE_END),
132                     "ORG_PKG", SHARING_SINK_ORG_PKG,
133                     "HOST_PKG", SHARING_SINK_HOST_PKG,
134                     "TO_CALL_PKG", toCallpkg.c_str(),
135                     "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
136                     "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
137                     "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
138                     "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
139                     "LOCAL_IP", devInfo_.localIp.c_str(),
140                     "PEER_NET_ID", devInfo_.peerNetId.c_str(),
141                     "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
142                     "PEER_IP", devInfo_.peerIp.c_str(),
143                     "PEER_DEV_NAME", devInfo_.peerDevName.c_str());
144 }
145 
ThirdSceneEndReport(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage)146 void WfdSinkHiSysEvent::ThirdSceneEndReport(const std::string &funcName, const std::string &toCallpkg,
147                                             SinkStage sinkStage)
148 {
149     if (hiSysEventStart_ == false) {
150         SHARING_LOGE("func:%{public}s, sinkStage:%{public}d, scece is Invalid", funcName.c_str(), sinkStage);
151         return;
152     }
153     std::chrono::system_clock::time_point endTimePoint = std::chrono::system_clock::now();
154     int32_t endTime = std::chrono::duration_cast<std::chrono::seconds>(endTimePoint.time_since_epoch()).count();
155     int32_t duration = endTime - startTime_;
156 
157     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
158                     "FUNC_NAME", funcName.c_str(),
159                     "BIZ_SCENE", static_cast<int32_t>(SinkBizScene::DISCONNECT_MIRRORING),
160                     "BIZ_STAGE", static_cast<int32_t>(SinkStage::DISCONNECT_COMPLETE),
161                     "STAGE_RES", static_cast<int32_t>(SinkStageRes::SUCCESS),
162                     "BIZ_STATE", static_cast<int32_t>(SinkBIZState::BIZ_STATE_END),
163                     "ORG_PKG", SHARING_SINK_ORG_PKG,
164                     "HOST_PKG", SHARING_SINK_HOST_PKG,
165                     "TO_CALL_PKG", toCallpkg.c_str(),
166                     "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
167                     "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
168                     "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
169                     "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
170                     "LOCAL_IP", devInfo_.localIp.c_str(),
171                     "PEER_NET_ID", devInfo_.peerNetId.c_str(),
172                     "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
173                     "PEER_IP", devInfo_.peerIp.c_str(),
174                     "PEER_DEV_NAME", devInfo_.peerDevName.c_str(),
175                     "SERVICE_DURATION", duration);
176     hiSysEventStart_ = false;
177 }
178 
ReportEstablishMirroringError(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage,SinkErrorCode errorCode,int32_t duration)179 void WfdSinkHiSysEvent::ReportEstablishMirroringError(const std::string &funcName, const std::string &toCallpkg,
180     SinkStage sinkStage, SinkErrorCode errorCode, int32_t duration)
181 {
182     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME,
183         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
184         "FUNC_NAME", funcName.c_str(),
185         "BIZ_SCENE", sinkBizScene_,
186         "BIZ_STAGE", static_cast<int32_t>(sinkStage),
187         "STAGE_RES", static_cast<int32_t>(SinkStageRes::FAIL),
188         "ERROR_CODE", static_cast<int32_t>(errorCode),
189         "BIZ_STATE", static_cast<int32_t>(SinkBIZState::BIZ_STATE_END),
190         "ORG_PKG", SHARING_SINK_ORG_PKG,
191         "HOST_PKG", SHARING_SINK_HOST_PKG,
192         "TO_CALL_PKG", toCallpkg.c_str(),
193         "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
194         "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
195         "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
196         "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
197         "LOCAL_IP", devInfo_.localIp.c_str(),
198         "PEER_NET_ID", devInfo_.peerNetId.c_str(),
199         "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
200         "PEER_IP", devInfo_.peerIp.c_str(),
201         "PEER_DEV_NAME", devInfo_.peerDevName.c_str());
202 }
203 
ReportStabilityError(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage,SinkErrorCode errorCode)204 void WfdSinkHiSysEvent::ReportStabilityError(const std::string &funcName, const std::string &toCallpkg,
205     SinkStage sinkStage, SinkErrorCode errorCode)
206 {
207     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME,
208         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
209         "FUNC_NAME", funcName.c_str(),
210         "BIZ_SCENE", sinkBizScene_,
211         "BIZ_STAGE", static_cast<int32_t>(sinkStage),
212         "STAGE_RES", static_cast<int32_t>(SinkStageRes::FAIL),
213         "ERROR_CODE", static_cast<int32_t>(errorCode),
214         "ORG_PKG", SHARING_SINK_ORG_PKG,
215         "HOST_PKG", SHARING_SINK_HOST_PKG,
216         "TO_CALL_PKG", toCallpkg.c_str(),
217         "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
218         "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
219         "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
220         "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
221         "LOCAL_IP", devInfo_.localIp.c_str(),
222         "PEER_NET_ID", devInfo_.peerNetId.c_str(),
223         "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
224         "PEER_IP", devInfo_.peerIp.c_str(),
225         "PEER_DEV_NAME", devInfo_.peerDevName.c_str());
226 }
227 
ReportDisconnectError(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage,SinkErrorCode errorCode,int32_t duration)228 void WfdSinkHiSysEvent::ReportDisconnectError(const std::string &funcName, const std::string &toCallpkg,
229     SinkStage sinkStage, SinkErrorCode errorCode, int32_t duration)
230 {
231     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME,
232         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
233         "FUNC_NAME", funcName.c_str(),
234         "BIZ_SCENE", sinkBizScene_,
235         "BIZ_STAGE", static_cast<int32_t>(sinkStage),
236         "STAGE_RES", static_cast<int32_t>(SinkStageRes::FAIL),
237         "ERROR_CODE", static_cast<int32_t>(errorCode),
238         "BIZ_STATE", static_cast<int32_t>(SinkBIZState::BIZ_STATE_END),
239         "ORG_PKG", SHARING_SINK_ORG_PKG,
240         "HOST_PKG", SHARING_SINK_HOST_PKG,
241         "TO_CALL_PKG", toCallpkg.c_str(),
242         "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
243         "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
244         "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
245         "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
246         "LOCAL_IP", devInfo_.localIp.c_str(),
247         "PEER_NET_ID", devInfo_.peerNetId.c_str(),
248         "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
249         "PEER_IP", devInfo_.peerIp.c_str(),
250         "PEER_DEV_NAME", devInfo_.peerDevName.c_str(),
251         "SERVICE_DURATION", duration);
252 }
253 
254 
ReportError(const std::string & funcName,const std::string & toCallpkg,SinkStage sinkStage,SinkErrorCode errorCode)255 void WfdSinkHiSysEvent::ReportError(const std::string &funcName, const std::string &toCallpkg,
256                                     SinkStage sinkStage, SinkErrorCode errorCode)
257 {
258     if (hiSysEventStart_ == false) {
259         SHARING_LOGE("func:%{public}s, sinkStage:%{public}d, scece is Invalid", funcName.c_str(), sinkStage);
260         return;
261     }
262 
263     std::chrono::system_clock::time_point endTimePoint = std::chrono::system_clock::now();
264     int endTime = std::chrono::duration_cast<std::chrono::seconds>(endTimePoint.time_since_epoch()).count();
265     int32_t duration = endTime - startTime_;
266 
267     switch (static_cast<SinkBizScene>(sinkBizScene_)) {
268         case SinkBizScene::ESTABLISH_MIRRORING:
269             ReportEstablishMirroringError(funcName, toCallpkg, sinkStage, errorCode, duration);
270             hiSysEventStart_ = false;
271             break;
272         case SinkBizScene::MIRRORING_STABILITY:
273             ReportStabilityError(funcName, toCallpkg, sinkStage, errorCode);
274             break;
275         case SinkBizScene::DISCONNECT_MIRRORING:
276             ReportDisconnectError(funcName, toCallpkg, sinkStage, errorCode, duration);
277             hiSysEventStart_ = false;
278             break;
279         default:
280             break;
281     }
282 }
283 
P2PReportError(const std::string & funcName,SinkErrorCode errorCode)284 void WfdSinkHiSysEvent::P2PReportError(const std::string &funcName, SinkErrorCode errorCode)
285 {
286     HiSysEventWrite(SHARING_SINK_DFX_DOMAIN_NAME, SHARING_SINK_EVENT_NAME, HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
287                     "FUNC_NAME", funcName.c_str(),
288                     "BIZ_SCENE", static_cast<int32_t>(SinkBizScene::ESTABLISH_MIRRORING),
289                     "BIZ_STAGE", static_cast<int32_t>(SinkStage::P2P_CONNECT_SUCCESS),
290                     "STAGE_RES", static_cast<int32_t>(SinkStageRes::FAIL),
291                     "ERROR_CODE", static_cast<int32_t>(errorCode),
292                     "ORG_PKG", SHARING_SINK_ORG_PKG,
293                     "HOST_PKG", SHARING_SINK_HOST_PKG,
294                     "TO_CALL_PKG", "wpa_supplicant",
295                     "LOCAL_NET_ID", devInfo_.localNetId.c_str(),
296                     "LOCAL_WIFI_MAC", devInfo_.localWifiMac.c_str(),
297                     "LOCAL_DEV_NAME", devInfo_.localDevName.c_str(),
298                     "LOCAL_DEV_TYPE", SHARING_SINK_LOCAL_DEV_TYPE,
299                     "LOCAL_IP", devInfo_.localIp.c_str(),
300                     "PEER_NET_ID", devInfo_.peerNetId.c_str(),
301                     "PEER_WIFI_MAC", devInfo_.peerWifiMac.c_str(),
302                     "PEER_IP", devInfo_.peerIp.c_str(),
303                     "PEER_DEV_NAME", devInfo_.peerDevName.c_str());
304 }
305 
GetCurrentScene()306 int32_t WfdSinkHiSysEvent::GetCurrentScene()
307 {
308     return sinkBizScene_;
309 }
310 
ReportDecodeError(MediaReportType type)311 void WfdSinkHiSysEvent::ReportDecodeError(MediaReportType type)
312 {
313     if (hiSysEventStart_ == false) {
314         return;
315     }
316 
317     std::chrono::system_clock::time_point nowTimePoint = std::chrono::system_clock::now();
318     int64_t nowTime = std::chrono::duration_cast<std::chrono::milliseconds>(nowTimePoint.time_since_epoch()).count();
319     if (lastFreezeReportTime_ == 0 || nowTime < lastFreezeReportTime_) {
320         lastFreezeReportTime_ = nowTime;
321     }
322 
323     if ((nowTime - lastFreezeReportTime_) >= REPORT_INTERVAL_MS) {
324         Reset();
325     }
326 
327     if (isFreezeReportInTenMinute) {
328         return;
329     }
330 
331     if (type == MediaReportType::AUDIO) {
332         audioFreezeCount_++;
333     }
334     if (type == MediaReportType::VIDEO) {
335         videoFreezeCount_++;
336     }
337     if (audioFreezeCount_ >= FREEZE_COUNT) {
338         ReportStabilityError(__func__, "", SinkStage::AUDIO_DECODE, SinkErrorCode::WIFI_DISPLAY_AUDIO_DECODE_TIMEOUT);
339         lastFreezeReportTime_ = nowTime;
340         isFreezeReportInTenMinute = true;
341         SHARING_LOGE("ReportStabilityError audioFreeze");
342     }
343     if (videoFreezeCount_ >= FREEZE_COUNT) {
344         ReportStabilityError(__func__, "", SinkStage::VIDEO_DECODE, SinkErrorCode::WIFI_DISPLAY_VIDEO_DECODE_TIMEOUT);
345         lastFreezeReportTime_ = nowTime;
346         isFreezeReportInTenMinute = true;
347         SHARING_LOGE("ReportStabilityError videoFreeze");
348     }
349 }
350 
RecordMediaDecodeStartTime(MediaReportType type,uint64_t pts)351 void WfdSinkHiSysEvent::RecordMediaDecodeStartTime(MediaReportType type, uint64_t pts)
352 {
353     std::unique_lock<std::mutex> decodeLock(decodeMutex_);
354     if (type == MediaReportType::AUDIO) {
355         RecordDecordStartTime(pts, audioDecoderTime_);
356     } else if (type == MediaReportType::VIDEO) {
357         RecordDecordStartTime(pts, videoDecoderTime_);
358     } else {
359         SHARING_LOGD("not process");
360     }
361 }
362 
MediaDecodeTimProc(MediaReportType type,uint64_t pts)363 void WfdSinkHiSysEvent::MediaDecodeTimProc(MediaReportType type, uint64_t pts)
364 {
365     std::unique_lock<std::mutex> decodeLock(decodeMutex_);
366     if (type == MediaReportType::AUDIO) {
367         ReportDecodeTime(pts, audioDecoderTime_, type);
368     } else if (type == MediaReportType::VIDEO) {
369         ReportDecodeTime(pts, videoDecoderTime_, type);
370     } else {
371         SHARING_LOGD("not process");
372     }
373 }
374 
Reset()375 void WfdSinkHiSysEvent::Reset()
376 {
377     isFreezeReportInTenMinute = false;
378     lastFreezeReportTime_ = 0;
379     videoDecoderTime_.clear();
380     audioDecoderTime_.clear();
381     videoFreezeCount_ = 0;
382     audioFreezeCount_ = 0;
383 }
384 
GetCurTimeInUs()385 uint64_t WfdSinkHiSysEvent::GetCurTimeInUs()
386 {
387     return std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now())
388         .time_since_epoch()
389         .count();
390 }
391 
RecordDecordStartTime(uint64_t pts,std::map<uint64_t,uint64_t> & decodeMap)392 void WfdSinkHiSysEvent::RecordDecordStartTime(uint64_t pts, std::map<uint64_t, uint64_t> &decodeMap)
393 {
394     if (decodeMap.size() >= DECODE_TIME_MAP_CAPACITY) {
395         decodeMap.clear();
396     }
397     decodeMap[pts] = GetCurTimeInUs();
398 }
399 
ReportDecodeTime(uint64_t pts,std::map<uint64_t,uint64_t> & decodeMap,MediaReportType type)400 void WfdSinkHiSysEvent::ReportDecodeTime(uint64_t pts, std::map<uint64_t, uint64_t> &decodeMap, MediaReportType type)
401 {
402     uint64_t decodeEndTime = GetCurTimeInUs();
403     auto decodeStartTime = decodeMap.find(pts);
404     if (decodeStartTime == decodeMap.end()) {
405         return;
406     }
407     if (decodeEndTime >= decodeStartTime->second) {
408         auto interval = decodeEndTime - decodeStartTime->second;
409         if (interval > DECODE_TIME_OUT) {
410             SHARING_LOGE("decode time out type %{public}d, time %{public}" PRIu64, type, interval);
411             decodeMap.erase(decodeStartTime);
412             ReportDecodeError(type);
413             return;
414         }
415     }
416     decodeMap.erase(decodeStartTime);
417 }
418 
419 } // namespace Sharing
420 } // namespace OHOS