1049e185fSopenharmony_ci/*
2049e185fSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3049e185fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4049e185fSopenharmony_ci * you may not use this file except in compliance with the License.
5049e185fSopenharmony_ci * You may obtain a copy of the License at
6049e185fSopenharmony_ci *
7049e185fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8049e185fSopenharmony_ci *
9049e185fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10049e185fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11049e185fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12049e185fSopenharmony_ci * See the License for the specific language governing permissions and
13049e185fSopenharmony_ci * limitations under the License.
14049e185fSopenharmony_ci */
15049e185fSopenharmony_ci
16049e185fSopenharmony_ci#ifndef MEDIA_DFX_H
17049e185fSopenharmony_ci#define MEDIA_DFX_H
18049e185fSopenharmony_ci
19049e185fSopenharmony_ci#include <cstring>
20049e185fSopenharmony_ci#include <list>
21049e185fSopenharmony_ci#include <memory>
22049e185fSopenharmony_ci#include <map>
23049e185fSopenharmony_ci#include <string>
24049e185fSopenharmony_ci#include <refbase.h>
25049e185fSopenharmony_ci#include "nocopyable.h"
26049e185fSopenharmony_ci#include "hisysevent.h"
27049e185fSopenharmony_ci#include "meta/meta.h"
28049e185fSopenharmony_ci#ifdef SUPPORT_JSON
29049e185fSopenharmony_ci#include "nlohmann/json.hpp"
30049e185fSopenharmony_ci#endif
31049e185fSopenharmony_ci#include <chrono>
32049e185fSopenharmony_ci#include <mutex>
33049e185fSopenharmony_ci
34049e185fSopenharmony_cinamespace OHOS {
35049e185fSopenharmony_cinamespace Media {
36049e185fSopenharmony_ci#ifdef SUPPORT_JSON
37049e185fSopenharmony_ciusing json = nlohmann::json;
38049e185fSopenharmony_ci#endif
39049e185fSopenharmony_cienum CallType {
40049e185fSopenharmony_ci    AVPLAYER,
41049e185fSopenharmony_ci    AVRECORDER,
42049e185fSopenharmony_ci    METADATA_RETRIEVER,
43049e185fSopenharmony_ci    IMAGE_GENERATER,
44049e185fSopenharmony_ci    AVDEMUXER,
45049e185fSopenharmony_ci    AVMUXER,
46049e185fSopenharmony_ci    VIDEO_DECODER,
47049e185fSopenharmony_ci    VIDEO_ENCODER,
48049e185fSopenharmony_ci    AUDIO_DECODER,
49049e185fSopenharmony_ci    AUDIO_ENCODER,
50049e185fSopenharmony_ci    SOUNDPOOL,
51049e185fSopenharmony_ci    SCREEN_CAPTRUER,
52049e185fSopenharmony_ci    AVTRANSCODER
53049e185fSopenharmony_ci};
54049e185fSopenharmony_ciclass __attribute__((visibility("default"))) MediaEvent : public NoCopyable {
55049e185fSopenharmony_cipublic:
56049e185fSopenharmony_ci    MediaEvent() = default;
57049e185fSopenharmony_ci    ~MediaEvent() = default;
58049e185fSopenharmony_ci    bool CreateMsg(const char *format, ...) __attribute__((__format__(printf, 2, 3)));
59049e185fSopenharmony_ci    void EventWrite(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
60049e185fSopenharmony_ci        std::string module);
61049e185fSopenharmony_ci    void EventWriteWithAppInfo(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
62049e185fSopenharmony_ci        std::string module, std::string status, int32_t appUid, int32_t appPid);
63049e185fSopenharmony_ci    void EventWriteBundleName(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
64049e185fSopenharmony_ci        std::string module, std::string status, int32_t appUid, int32_t appPid, std::string bundleName);
65049e185fSopenharmony_ci    void SourceEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, const std::string&
66049e185fSopenharmony_ci        appName, uint64_t instanceId, const std::string& callerType, int8_t sourceType, const std::string& sourceUrl,
67049e185fSopenharmony_ci        const std::string& errMsg);
68049e185fSopenharmony_ci    void ScreenCaptureEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
69049e185fSopenharmony_ci        const std::string& appName, uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode,
70049e185fSopenharmony_ci        const std::string& errMsg);
71049e185fSopenharmony_ci    void CommonStatisicsEventWrite(CallType callType, OHOS::HiviewDFX::HiSysEvent::EventType type,
72049e185fSopenharmony_ci        const std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<Meta>>>>& infoMap);
73049e185fSopenharmony_ciprivate:
74049e185fSopenharmony_ci    void StatisicsHiSysEventWrite(CallType callType, OHOS::HiviewDFX::HiSysEvent::EventType type,
75049e185fSopenharmony_ci        const std::vector<std::string>& infoArr);
76049e185fSopenharmony_ci#ifdef SUPPORT_JSON
77049e185fSopenharmony_ci    void ParseOneEvent(const std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>> &listPair, json& metaInfoJson);
78049e185fSopenharmony_ci#endif
79049e185fSopenharmony_ci    std::string msg_;
80049e185fSopenharmony_ci};
81049e185fSopenharmony_ci
82049e185fSopenharmony_ci
83049e185fSopenharmony_ci__attribute__((visibility("default"))) void BehaviorEventWrite(std::string status, std::string module);
84049e185fSopenharmony_ci__attribute__((visibility("default"))) void BehaviorEventWriteForScreenCapture(std::string status,
85049e185fSopenharmony_ci    std::string module, int32_t appUid, int32_t appPid);
86049e185fSopenharmony_ci__attribute__((visibility("default"))) void StatisticEventWriteBundleName(std::string status,
87049e185fSopenharmony_ci    std::string module);
88049e185fSopenharmony_ci__attribute__((visibility("default"))) void FaultEventWrite(std::string msg, std::string module);
89049e185fSopenharmony_ci__attribute__((visibility("default"))) void FaultSourceEventWrite(const std::string& appName, uint64_t instanceId,
90049e185fSopenharmony_ci    const std::string& callerType, int8_t sourceType, const std::string& sourceUrl, const std::string& errorMessage);
91049e185fSopenharmony_ci__attribute__((visibility("default"))) void FaultScreenCaptureEventWrite(const std::string& appName,
92049e185fSopenharmony_ci    uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode, const std::string& errorMessage);
93049e185fSopenharmony_ci__attribute__((visibility("default"))) int32_t CreateMediaInfo(CallType callType, int32_t uid, uint64_t instanceId);
94049e185fSopenharmony_ci__attribute__((visibility("default"))) int32_t AppendMediaInfo(const std::shared_ptr<Meta>& meta, uint64_t instanceId);
95049e185fSopenharmony_ci__attribute__((visibility("default"))) int32_t ReportMediaInfo(uint64_t instanceId);
96049e185fSopenharmony_ci
97049e185fSopenharmony_ciclass __attribute__((visibility("default"))) MediaTrace : public NoCopyable {
98049e185fSopenharmony_cipublic:
99049e185fSopenharmony_ci    explicit MediaTrace(const std::string &funcName);
100049e185fSopenharmony_ci    static void TraceBegin(const std::string &funcName, int32_t taskId);
101049e185fSopenharmony_ci    static void TraceEnd(const std::string &funcName, int32_t taskId);
102049e185fSopenharmony_ci    static void CounterTrace(const std::string &varName, int32_t val);
103049e185fSopenharmony_ci    ~MediaTrace();
104049e185fSopenharmony_ciprivate:
105049e185fSopenharmony_ci    bool isSync_ = false;
106049e185fSopenharmony_ci};
107049e185fSopenharmony_ci} // namespace Media
108049e185fSopenharmony_ci} // namespace OHOS
109049e185fSopenharmony_ci#endif // MEDIA_DFX_H