• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_SAMPLE_LOG_H
17 #define AVCODEC_SAMPLE_LOG_H
18 
19 #include <hilog/log.h>
20 #include <cinttypes>
21 
22 #undef LOG_DOMAIN
23 #define LOG_DOMAIN 0x0002B66
24 
25 #define AVCODEC_SAMPLE_LOG_FREQ_LIMIT(frequency)               \
26     if (1) {                                                   \
27         thread_local uint64_t currentTimes = 0;                \
28         if (currentTimes++ % ((uint64_t)(frequency)) != 0) {   \
29             break;                                             \
30         }                                                      \
31     }
32 
33 #define AVCODEC_SAMPLE_LOG(func, fmt, args...)                 \
34     do {                                                       \
35         (void)func(LOG_APP, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args);   \
36     } while (0)
37 
38 #define AVCODEC_SAMPLE_LOGF(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_FATAL, fmt, ##__VA_ARGS__)
39 #define AVCODEC_SAMPLE_LOGE(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_ERROR, fmt, ##__VA_ARGS__)
40 #define AVCODEC_SAMPLE_LOGW(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_WARN,  fmt, ##__VA_ARGS__)
41 #define AVCODEC_SAMPLE_LOGI(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_INFO,  fmt, ##__VA_ARGS__)
42 #define AVCODEC_SAMPLE_LOGD(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_DEBUG, fmt, ##__VA_ARGS__)
43 #define AVCODEC_SAMPLE_LOGD_LIMIT(frequency, fmt, ...)         \
44     do {                                                       \
45         AVCODEC_SAMPLE_LOG_FREQ_LIMIT(frequency);              \
46         AVCODEC_SAMPLE_LOGD(fmt, ##__VA_ARGS__);               \
47     } while (0)
48 
49 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)          \
50     do {                                                       \
51         if (!(cond)) {                                         \
52             AVCODEC_SAMPLE_LOGE(fmt, ##__VA_ARGS__);           \
53             return ret;                                        \
54         }                                                      \
55     } while (0)
56 
57 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)                   \
58     do {                                                       \
59         if (!(cond)) {                                         \
60             AVCODEC_SAMPLE_LOGE(fmt, ##__VA_ARGS__);           \
61             return;                                            \
62         }                                                      \
63     } while (0)
64 
65 #define CHECK_AND_BREAK_LOG(cond, fmt, ...)                    \
66     if (1) {                                                   \
67         if (!(cond)) {                                         \
68             AVCODEC_SAMPLE_LOGW(fmt, ##__VA_ARGS__);           \
69             break;                                             \
70         }                                                      \
71     } else void (0)
72 
73 #define CHECK_AND_CONTINUE_LOG(cond, fmt, ...)                 \
74     if (1) {                                                   \
75         if (!(cond)) {                                         \
76             AVCODEC_SAMPLE_LOGW(fmt, ##__VA_ARGS__);           \
77             continue;                                          \
78         }                                                      \
79     } else void (0)
80 
81 #endif // AVCODEC_SAMPLE_LOG_H