1049e185fSopenharmony_ci/* 2049e185fSopenharmony_ci * Copyright (C) 2021-2024 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 OHOS_MEDIA_LOG_H 17049e185fSopenharmony_ci#define OHOS_MEDIA_LOG_H 18049e185fSopenharmony_ci 19049e185fSopenharmony_ci#include <hilog/log.h> 20049e185fSopenharmony_ci#include <cinttypes> 21049e185fSopenharmony_ci 22049e185fSopenharmony_ci#ifdef OHOS_MEDIA_LOG_DFX 23049e185fSopenharmony_ci#include "dfx_log_dump.h" 24049e185fSopenharmony_ci#endif 25049e185fSopenharmony_ci 26049e185fSopenharmony_cinamespace OHOS { 27049e185fSopenharmony_ci 28049e185fSopenharmony_ci#undef LOG_DOMAIN_PLAYER 29049e185fSopenharmony_ci#define LOG_DOMAIN_PLAYER 0xD002B2B 30049e185fSopenharmony_ci#undef LOG_DOMAIN_RECORDER 31049e185fSopenharmony_ci#define LOG_DOMAIN_RECORDER 0xD002B2C 32049e185fSopenharmony_ci#undef LOG_DOMAIN_METADATA 33049e185fSopenharmony_ci#define LOG_DOMAIN_METADATA 0xD002B2D 34049e185fSopenharmony_ci#undef LOG_DOMAIN_SCREENCAPTURE 35049e185fSopenharmony_ci#define LOG_DOMAIN_SCREENCAPTURE 0xD002B2E 36049e185fSopenharmony_ci#undef LOG_DOMAIN_SOUNDPOOL 37049e185fSopenharmony_ci#define LOG_DOMAIN_SOUNDPOOL 0xD002B2F 38049e185fSopenharmony_ci#undef LOG_DOMAIN_AUDIO_NAPI 39049e185fSopenharmony_ci#define LOG_DOMAIN_AUDIO_NAPI 0xD002B20 40049e185fSopenharmony_ci#undef LOG_DOMAIN_VIDEOEDITOR 41049e185fSopenharmony_ci#define LOG_DOMAIN_VIDEOEDITOR 0xD002B3C 42049e185fSopenharmony_ci 43049e185fSopenharmony_ci#undef LOG_TAG 44049e185fSopenharmony_ci#define LOG_TAG LABEL.tag 45049e185fSopenharmony_ci#undef LOG_DOMAIN 46049e185fSopenharmony_ci#define LOG_DOMAIN LABEL.domain 47049e185fSopenharmony_ci#undef LOG_TYPE 48049e185fSopenharmony_ci#define LOG_TYPE LABEL.type 49049e185fSopenharmony_ci 50049e185fSopenharmony_ci#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 51049e185fSopenharmony_ci 52049e185fSopenharmony_ci#define MEDIA_LOG(func, fmt, args...) \ 53049e185fSopenharmony_ci do { \ 54049e185fSopenharmony_ci if (LABEL.tag != nullptr) { \ 55049e185fSopenharmony_ci (void)func(LOG_TYPE, "#%{public}d " fmt, __LINE__, ##args); \ 56049e185fSopenharmony_ci } \ 57049e185fSopenharmony_ci } while (0) 58049e185fSopenharmony_ci 59049e185fSopenharmony_ci#ifdef OHOS_MEDIA_LOG_DFX 60049e185fSopenharmony_ci#define DUMP_LOG(level, fmt, args...) \ 61049e185fSopenharmony_ci do { \ 62049e185fSopenharmony_ci (void)OHOS::Media::DfxLogDump::GetInstance().SaveLog(level, LABEL, "{%s():%d} " fmt, __FUNCTION__, __LINE__, \ 63049e185fSopenharmony_ci ##args); \ 64049e185fSopenharmony_ci } while (0); 65049e185fSopenharmony_ci#define MEDIA_LOGD(fmt, ...) \ 66049e185fSopenharmony_ci DUMP_LOG("LOGD", fmt, ##__VA_ARGS__) \ 67049e185fSopenharmony_ci MEDIA_LOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 68049e185fSopenharmony_ci#define MEDIA_LOGI(fmt, ...) \ 69049e185fSopenharmony_ci DUMP_LOG("LOGI", fmt, ##__VA_ARGS__) \ 70049e185fSopenharmony_ci MEDIA_LOG(HILOG_INFO, fmt, ##__VA_ARGS__) 71049e185fSopenharmony_ci#define MEDIA_LOGW(fmt, ...) \ 72049e185fSopenharmony_ci DUMP_LOG("LOGW", fmt, ##__VA_ARGS__) \ 73049e185fSopenharmony_ci MEDIA_LOG(HILOG_WARN, fmt, ##__VA_ARGS__) 74049e185fSopenharmony_ci#define MEDIA_LOGE(fmt, ...) \ 75049e185fSopenharmony_ci DUMP_LOG("LOGE", fmt, ##__VA_ARGS__) \ 76049e185fSopenharmony_ci MEDIA_LOG(HILOG_ERROR, fmt, ##__VA_ARGS__) 77049e185fSopenharmony_ci#define MEDIA_LOGF(fmt, ...) \ 78049e185fSopenharmony_ci DUMP_LOG("LOGF", fmt, ##__VA_ARGS__) \ 79049e185fSopenharmony_ci MEDIA_LOG(HILOG_FATAL, fmt, ##__VA_ARGS__) 80049e185fSopenharmony_ci#else 81049e185fSopenharmony_ci#define MEDIA_LOGD(fmt, ...) MEDIA_LOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 82049e185fSopenharmony_ci#define MEDIA_LOGI(fmt, ...) MEDIA_LOG(HILOG_INFO, fmt, ##__VA_ARGS__) 83049e185fSopenharmony_ci#define MEDIA_LOGW(fmt, ...) MEDIA_LOG(HILOG_WARN, fmt, ##__VA_ARGS__) 84049e185fSopenharmony_ci#define MEDIA_LOGE(fmt, ...) MEDIA_LOG(HILOG_ERROR, fmt, ##__VA_ARGS__) 85049e185fSopenharmony_ci#define MEDIA_LOGF(fmt, ...) MEDIA_LOG(HILOG_FATAL, fmt, ##__VA_ARGS__) 86049e185fSopenharmony_ci#endif 87049e185fSopenharmony_ci 88049e185fSopenharmony_ci#define MEDIA_LOG_PRERELEASE(op, fmt, args...) \ 89049e185fSopenharmony_ci do { \ 90049e185fSopenharmony_ci op(LOG_ONLY_PRERELEASE, "#%{public}d " fmt, __LINE__, ##args); \ 91049e185fSopenharmony_ci } while (0) 92049e185fSopenharmony_ci 93049e185fSopenharmony_ci#define MEDIA_LOGI_NO_RELEASE(fmt, ...) MEDIA_LOG_PRERELEASE(HILOG_INFO, fmt, ##__VA_ARGS__) 94049e185fSopenharmony_ci#define MEDIA_LOGW_NO_RELEASE(fmt, ...) MEDIA_LOG_PRERELEASE(HILOG_WARN, fmt, ##__VA_ARGS__) 95049e185fSopenharmony_ci#define MEDIA_LOGE_NO_RELEASE(fmt, ...) MEDIA_LOG_PRERELEASE(HILOG_ERROR, fmt, ##__VA_ARGS__) 96049e185fSopenharmony_ci#define MEDIA_LOGF_NO_RELEASE(fmt, ...) MEDIA_LOG_PRERELEASE(HILOG_FATAL, fmt, ##__VA_ARGS__) 97049e185fSopenharmony_ci 98049e185fSopenharmony_ci#define CHECK_AND_RETURN(cond) \ 99049e185fSopenharmony_ci do { \ 100049e185fSopenharmony_ci if (!(cond)) { \ 101049e185fSopenharmony_ci MEDIA_LOGE_NO_RELEASE("%{public}s, check failed!", #cond); \ 102049e185fSopenharmony_ci return; \ 103049e185fSopenharmony_ci } \ 104049e185fSopenharmony_ci } while (0) 105049e185fSopenharmony_ci 106049e185fSopenharmony_ci#define CHECK_AND_RETURN_RET(cond, ret) \ 107049e185fSopenharmony_ci do { \ 108049e185fSopenharmony_ci if (!(cond)) { \ 109049e185fSopenharmony_ci MEDIA_LOGE_NO_RELEASE("%{public}s, check failed! ret = %{public}s", #cond, #ret); \ 110049e185fSopenharmony_ci return ret; \ 111049e185fSopenharmony_ci } \ 112049e185fSopenharmony_ci } while (0) 113049e185fSopenharmony_ci 114049e185fSopenharmony_ci#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 115049e185fSopenharmony_ci do { \ 116049e185fSopenharmony_ci if (!(cond)) { \ 117049e185fSopenharmony_ci MEDIA_LOGE(fmt, ##__VA_ARGS__); \ 118049e185fSopenharmony_ci return ret; \ 119049e185fSopenharmony_ci } \ 120049e185fSopenharmony_ci } while (0) 121049e185fSopenharmony_ci 122049e185fSopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 123049e185fSopenharmony_ci do { \ 124049e185fSopenharmony_ci if (!(cond)) { \ 125049e185fSopenharmony_ci MEDIA_LOGE(fmt, ##__VA_ARGS__); \ 126049e185fSopenharmony_ci return; \ 127049e185fSopenharmony_ci } \ 128049e185fSopenharmony_ci } while (0) 129049e185fSopenharmony_ci 130049e185fSopenharmony_ci#define CHECK_AND_BREAK_LOG(cond, fmt, ...) \ 131049e185fSopenharmony_ci if (1) { \ 132049e185fSopenharmony_ci if (!(cond)) { \ 133049e185fSopenharmony_ci MEDIA_LOGE(fmt, ##__VA_ARGS__); \ 134049e185fSopenharmony_ci break; \ 135049e185fSopenharmony_ci } \ 136049e185fSopenharmony_ci } else \ 137049e185fSopenharmony_ci void(0) 138049e185fSopenharmony_ci 139049e185fSopenharmony_ci#define CHECK_AND_BREAK(cond) \ 140049e185fSopenharmony_ci if (1) { \ 141049e185fSopenharmony_ci if (!(cond)) { \ 142049e185fSopenharmony_ci MEDIA_LOGE_NO_RELEASE("%{public}s, check failed!", #cond); \ 143049e185fSopenharmony_ci break; \ 144049e185fSopenharmony_ci } \ 145049e185fSopenharmony_ci } else \ 146049e185fSopenharmony_ci void(0) 147049e185fSopenharmony_ci 148049e185fSopenharmony_ci#define CHECK_AND_CONTINUE(cond) \ 149049e185fSopenharmony_ci if (1) { \ 150049e185fSopenharmony_ci if (!(cond)) { \ 151049e185fSopenharmony_ci MEDIA_LOGE_NO_RELEASE("%{public}s, check failed!", #cond); \ 152049e185fSopenharmony_ci continue; \ 153049e185fSopenharmony_ci } \ 154049e185fSopenharmony_ci } else \ 155049e185fSopenharmony_ci void(0) 156049e185fSopenharmony_ci 157049e185fSopenharmony_ci#define CHECK_AND_CONTINUE_LOG(cond, fmt, ...) \ 158049e185fSopenharmony_ci if (1) { \ 159049e185fSopenharmony_ci if (!(cond)) { \ 160049e185fSopenharmony_ci MEDIA_LOGE(fmt, ##__VA_ARGS__); \ 161049e185fSopenharmony_ci continue; \ 162049e185fSopenharmony_ci } \ 163049e185fSopenharmony_ci } else \ 164049e185fSopenharmony_ci void(0) 165049e185fSopenharmony_ci 166049e185fSopenharmony_ci#define TRUE_LOG(cond, func, fmt, ...) \ 167049e185fSopenharmony_ci if (1) { \ 168049e185fSopenharmony_ci if ((cond)) { \ 169049e185fSopenharmony_ci func(fmt, ##__VA_ARGS__); \ 170049e185fSopenharmony_ci } \ 171049e185fSopenharmony_ci } else \ 172049e185fSopenharmony_ci void(0) 173049e185fSopenharmony_ci 174049e185fSopenharmony_ci#define POINTER_MASK 0x00FFFFFF 175049e185fSopenharmony_ci#define FAKE_POINTER(addr) (POINTER_MASK & reinterpret_cast<uintptr_t>(addr)) 176049e185fSopenharmony_ci} // namespace OHOS 177049e185fSopenharmony_ci#endif // OHOS_MEDIA_LOG_H 178