• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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  */
15 
16 #ifndef AVCODEC_DFX_H
17 #define AVCODEC_DFX_H
18 
19 #include <string>
20 #include <refbase.h>
21 #include "nocopyable.h"
22 #include "hisysevent.h"
23 
24 namespace OHOS {
25 namespace MediaAVCodec {
26 enum class FaultType : int32_t {
27     FAULT_TYPE_INVALID = -1,
28     FAULT_TYPE_FREEZE = 0,
29     FAULT_TYPE_CRASH = 1,
30     FAULT_TYPE_INNER_ERROR = 2,
31 };
32 
33 struct SubAbilityCount {
34     uint32_t codecCount = 0;
35     uint32_t muxerCount = 0;
36     uint32_t sourceCount = 0;
37     uint32_t demuxerCount = 0;
38     uint32_t codeclistCount = 0;
39 };
40 
41 class __attribute__((visibility("default"))) AVCodecEvent : public NoCopyable {
42 public:
43     AVCodecEvent() = default;
44     ~AVCodecEvent() = default;
45     bool CreateMsg(const char* format, ...) __attribute__((__format__(printf, 2, 3)));
46     void FaultEventWrite(const std::string& eventName,
47                          OHOS::HiviewDFX::HiSysEvent::EventType type,
48                          FaultType faultType,
49                          const std::string& module);
50 
51 private:
52     std::string msg_;
53 };
54 
55 __attribute__((visibility("default"))) void FaultEventWrite(FaultType faultType, const std::string& msg,
56                                                             const std::string& module);
57 __attribute__((visibility("default"))) void BehaviorEventWrite(uint32_t useTime, const std::string& module);
58 
59 #define AVCODEC_SYNC_TRACE AVCodecTrace trace(std::string(__FUNCTION__))
60 
61 class __attribute__((visibility("default"))) AVCodecTrace : public NoCopyable {
62 public:
63     explicit AVCodecTrace(const std::string& funcName);
64     static void TraceBegin(const std::string& funcName, int32_t taskId);
65     static void TraceEnd(const std::string& funcName, int32_t taskId);
66     static void CounterTrace(const std::string& varName, int32_t val);
67     ~AVCodecTrace();
68 
69 private:
70     bool isSync_ = false;
71 };
72 } // namespace MediaAVCodec
73 } // namespace OHOS
74 #endif // AVCODEC_DFX_H