• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3  */
4 /*
5  * Copyright (C) 2023 Huawei Device Co., Ltd.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef AVCODEC_SAMPLE_LOG_H
20 #define AVCODEC_SAMPLE_LOG_H
21 
22 #include <hilog/log.h>
23 #include <cinttypes>
24 
25 #undef LOG_DOMAIN
26 #define LOG_DOMAIN 0x0002B66
27 #define LOG_TAG "LppPlayerNdk_xtsDemo"
28 #define LOG_MSG_TAG "LppPlayerNdk_"
29 
30 #define LOGI(format, ...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, 0xFF00, LOG_MSG_TAG, format, ##__VA_ARGS__))
31 #define LOGE(format, ...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, LOG_MSG_TAG, format, ##__VA_ARGS__))
32 #define LOGD(format, ...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, 0xFF00, LOG_MSG_TAG, format, ##__VA_ARGS__))
33 
34 #define AVCODEC_SAMPLE_LOG_FREQ_LIMIT(frequency)               \
35     if (1) {                                                   \
36         thread_local uint64_t currentTimes = 0;                \
37         if (currentTimes++ % ((uint64_t)(frequency)) != 0) {   \
38             return;                                             \
39         }                                                      \
40     }
41 
42 #define AVCODEC_SAMPLE_LOG(func, fmt, args...)                 \
43     do {                                                       \
44         (void)func(LOG_APP, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args);   \
45     } while (0)
46 
47 #define AVCODEC_SAMPLE_LOGF(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_FATAL, fmt, ##__VA_ARGS__)
48 #define AVCODEC_SAMPLE_LOGE(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_ERROR, fmt, ##__VA_ARGS__)
49 #define AVCODEC_SAMPLE_LOGW(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_WARN,  fmt, ##__VA_ARGS__)
50 #define AVCODEC_SAMPLE_LOGI(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_INFO,  fmt, ##__VA_ARGS__)
51 #define AVCODEC_SAMPLE_LOGD(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_DEBUG, fmt, ##__VA_ARGS__)
52 #define AVCODEC_SAMPLE_LOGD_LIMIT(frequency, fmt, ...)         \
53     do {                                                       \
54         AVCODEC_SAMPLE_LOG_FREQ_LIMIT(frequency);              \
55         AVCODEC_SAMPLE_LOGD(fmt, ##__VA_ARGS__);               \
56     } while (0)
57 
58 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)          \
59     do {                                                       \
60         if (!(cond)) {                                         \
61             AVCODEC_SAMPLE_LOGE(fmt, ##__VA_ARGS__);           \
62             return ret;                                        \
63         }                                                      \
64     } while (0)
65 
66 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)                   \
67     do {                                                       \
68         if (!(cond)) {                                         \
69             AVCODEC_SAMPLE_LOGE(fmt, ##__VA_ARGS__);           \
70             return;                                            \
71         }                                                      \
72     } while (0)
73 
74 #define CHECK_AND_BREAK_LOG(cond, fmt, ...)                    \
75     if (1) {                                                   \
76         if (!(cond)) {                                         \
77             AVCODEC_SAMPLE_LOGW(fmt, ##__VA_ARGS__);           \
78             break;                                             \
79         }                                                      \
80     } else void (0)
81 
82 #define CHECK_AND_CONTINUE_LOG(cond, fmt, ...)                 \
83     if (1) {                                                   \
84         if (!(cond)) {                                         \
85             AVCODEC_SAMPLE_LOGW(fmt, ##__VA_ARGS__);           \
86             continue;                                          \
87         }                                                      \
88     } else void (0)
89 
90 #endif // AVCODEC_SAMPLE_LOG_H