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 #ifndef AVCODEC_LOG_H 16 #define AVCODEC_LOG_H 17 18 #include <hilog/log.h> 19 #include <cinttypes> 20 21 namespace OHOS { 22 namespace MediaAVCodec { 23 #undef LOG_DOMAIN 24 #define LOG_DOMAIN 0xD002BAC 25 26 #define AVCODEC_LOG_FREQ_LIMIT(frequency) \ 27 if (1) { \ 28 thread_local uint64_t currentTimes = 0; \ 29 if (currentTimes++ % ((uint64_t)(frequency)) != 0) { \ 30 break; \ 31 } \ 32 } 33 34 #define AVCODEC_LOG(func, fmt, args...) \ 35 do { \ 36 (void)func(LABEL, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args); \ 37 } while (0) 38 39 #define AVCODEC_LOGF(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Fatal, fmt, ##__VA_ARGS__) 40 #define AVCODEC_LOGE(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__) 41 #define AVCODEC_LOGW(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__) 42 #define AVCODEC_LOGI(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__) 43 #define AVCODEC_LOGD(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__) 44 #define AVCODEC_LOGD_LIMIT(frequency, fmt, ...) \ 45 do { \ 46 AVCODEC_LOG_FREQ_LIMIT(frequency); \ 47 AVCODEC_LOGD(fmt, ##__VA_ARGS__); \ 48 } while (0) 49 50 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 51 do { \ 52 if (!(cond)) { \ 53 AVCODEC_LOGE(fmt, ##__VA_ARGS__); \ 54 return ret; \ 55 } \ 56 } while (0) 57 58 #define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 59 do { \ 60 if (!(cond)) { \ 61 AVCODEC_LOGE(fmt, ##__VA_ARGS__); \ 62 return; \ 63 } \ 64 } while (0) 65 66 #define CHECK_AND_BREAK_LOG(cond, fmt, ...) \ 67 if (1) { \ 68 if (!(cond)) { \ 69 AVCODEC_LOGE(fmt, ##__VA_ARGS__); \ 70 break; \ 71 } \ 72 } else void (0) 73 74 #define CHECK_AND_CONTINUE_LOG(cond, fmt, ...) \ 75 if (1) { \ 76 if (!(cond)) { \ 77 AVCODEC_LOGE(fmt, ##__VA_ARGS__); \ 78 continue; \ 79 } \ 80 } else void (0) 81 82 #define POINTER_MASK 0x00FFFFFF 83 #define FAKE_POINTER(addr) (POINTER_MASK & reinterpret_cast<uintptr_t>(addr)) 84 } // namespace MediaAVCodec 85 } // namespace OHOS 86 #endif // AVCODEC_LOG_H