1fa7767c5Sopenharmony_ci/*
2fa7767c5Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License.
5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at
6fa7767c5Sopenharmony_ci *
7fa7767c5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fa7767c5Sopenharmony_ci *
9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and
13fa7767c5Sopenharmony_ci * limitations under the License.
14fa7767c5Sopenharmony_ci */
15fa7767c5Sopenharmony_ci
16fa7767c5Sopenharmony_ci#ifndef HISTREAMER_FOUNDATION_LOG_H
17fa7767c5Sopenharmony_ci#define HISTREAMER_FOUNDATION_LOG_H
18fa7767c5Sopenharmony_ci
19fa7767c5Sopenharmony_ci#include <cinttypes>
20fa7767c5Sopenharmony_ci#include <string>
21fa7767c5Sopenharmony_ci
22fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS
23fa7767c5Sopenharmony_ci#include "hilog/log.h"
24fa7767c5Sopenharmony_ci#else
25fa7767c5Sopenharmony_ci#include "log_adapter.h"
26fa7767c5Sopenharmony_ci#endif
27fa7767c5Sopenharmony_ci
28fa7767c5Sopenharmony_ci// If file name and line number is need, #define HST_DEBUG at the beginning of the cpp file.
29fa7767c5Sopenharmony_ci#define HST_DEBUG
30fa7767c5Sopenharmony_ci
31fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS
32fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_SYSTEM_PLAYER
33fa7767c5Sopenharmony_ci#define LOG_DOMAIN_SYSTEM_PLAYER 0xD002B22
34fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_STREAM_SOURCE
35fa7767c5Sopenharmony_ci#define LOG_DOMAIN_STREAM_SOURCE 0xD002B23
36fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_FOUNDATION
37fa7767c5Sopenharmony_ci#define LOG_DOMAIN_FOUNDATION    0xD002B24
38fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_DEMUXER
39fa7767c5Sopenharmony_ci#define LOG_DOMAIN_DEMUXER       0xD002B3A
40fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_MUXER
41fa7767c5Sopenharmony_ci#define LOG_DOMAIN_MUXER         0xD002B3B
42fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_AUDIO
43fa7767c5Sopenharmony_ci#define LOG_DOMAIN_AUDIO         0xD002B31
44fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_PLAYER
45fa7767c5Sopenharmony_ci#define LOG_DOMAIN_PLAYER        0xD002B2B
46fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_RECORDER
47fa7767c5Sopenharmony_ci#define LOG_DOMAIN_RECORDER      0xD002B2C
48fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_SCREENCAPTURE
49fa7767c5Sopenharmony_ci#define LOG_DOMAIN_SCREENCAPTURE 0xD002B2E
50fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_HIPLAYER
51fa7767c5Sopenharmony_ci#define LOG_DOMAIN_HIPLAYER      0xD002B2D
52fa7767c5Sopenharmony_ci#undef LOG_DOMAIN_METADATA
53fa7767c5Sopenharmony_ci#define LOG_DOMAIN_METADATA      0xD002B2C
54fa7767c5Sopenharmony_ci#define PUBLIC_LOG "%{public}"
55fa7767c5Sopenharmony_ci#else
56fa7767c5Sopenharmony_ci#define PUBLIC_LOG "%"
57fa7767c5Sopenharmony_ci#endif
58fa7767c5Sopenharmony_ci
59fa7767c5Sopenharmony_ci#ifndef HST_LOG_TAG
60fa7767c5Sopenharmony_ci#define HST_LOG_TAG "NULL"
61fa7767c5Sopenharmony_ci#endif
62fa7767c5Sopenharmony_ci
63fa7767c5Sopenharmony_ci#define PUBLIC_LOG_C PUBLIC_LOG "c"
64fa7767c5Sopenharmony_ci#define PUBLIC_LOG_S PUBLIC_LOG "s"
65fa7767c5Sopenharmony_ci#define PUBLIC_LOG_D8 PUBLIC_LOG PRId8
66fa7767c5Sopenharmony_ci#define PUBLIC_LOG_D16 PUBLIC_LOG PRId16
67fa7767c5Sopenharmony_ci#define PUBLIC_LOG_D32 PUBLIC_LOG PRId32
68fa7767c5Sopenharmony_ci#define PUBLIC_LOG_D64 PUBLIC_LOG PRId64
69fa7767c5Sopenharmony_ci#define PUBLIC_LOG_U8 PUBLIC_LOG PRIu8
70fa7767c5Sopenharmony_ci#define PUBLIC_LOG_U16 PUBLIC_LOG PRIu16
71fa7767c5Sopenharmony_ci#define PUBLIC_LOG_U32 PUBLIC_LOG PRIu32
72fa7767c5Sopenharmony_ci#define PUBLIC_LOG_U64 PUBLIC_LOG PRIu64
73fa7767c5Sopenharmony_ci#define PUBLIC_LOG_F PUBLIC_LOG "f"
74fa7767c5Sopenharmony_ci#define PUBLIC_LOG_P PUBLIC_LOG "p"
75fa7767c5Sopenharmony_ci#define PUBLIC_LOG_ZU PUBLIC_LOG "zu"
76fa7767c5Sopenharmony_ci
77fa7767c5Sopenharmony_ci#undef LOG_TAG
78fa7767c5Sopenharmony_ci#define LOG_TAG LABEL.tag
79fa7767c5Sopenharmony_ci#undef LOG_DOMAIN
80fa7767c5Sopenharmony_ci#define LOG_DOMAIN LABEL.domain
81fa7767c5Sopenharmony_ci#undef LOG_TYPE
82fa7767c5Sopenharmony_ci#define LOG_TYPE LABEL.type
83fa7767c5Sopenharmony_ci
84fa7767c5Sopenharmony_ci
85fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS
86fa7767c5Sopenharmony_ci#ifndef HST_DEBUG
87fa7767c5Sopenharmony_ci#define HST_HILOG(op, fmt, args...)                              \
88fa7767c5Sopenharmony_ci    do {                                                         \
89fa7767c5Sopenharmony_ci        op(LOG_TYPE, PUBLIC_LOG_S ":" fmt, HST_LOG_TAG, ##args); \
90fa7767c5Sopenharmony_ci    } while (0)
91fa7767c5Sopenharmony_ci#else
92fa7767c5Sopenharmony_ci#define HST_HILOG(op, fmt, args...)                                                                     \
93fa7767c5Sopenharmony_ci    do {                                                                                                \
94fa7767c5Sopenharmony_ci        op(LOG_TYPE, "(" PUBLIC_LOG_S "(), " PUBLIC_LOG_D32 "): " fmt, __FUNCTION__, __LINE__, ##args); \
95fa7767c5Sopenharmony_ci    } while (0)
96fa7767c5Sopenharmony_ci#define HST_HILOG_SHORT(op, fmt, args...)                           \
97fa7767c5Sopenharmony_ci    do {                                                            \
98fa7767c5Sopenharmony_ci        op(LOG_TYPE, "#" PUBLIC_LOG_D32 " " fmt, __LINE__, ##args); \
99fa7767c5Sopenharmony_ci    } while (0)
100fa7767c5Sopenharmony_ci#define HST_HILOG_NO_RELEASE(op, fmt, args...)                                                                     \
101fa7767c5Sopenharmony_ci    do {                                                                                                           \
102fa7767c5Sopenharmony_ci        op(LOG_ONLY_PRERELEASE, "(" PUBLIC_LOG_S "(), " PUBLIC_LOG_D32 "): " fmt, __FUNCTION__, __LINE__, ##args); \
103fa7767c5Sopenharmony_ci    } while (0)
104fa7767c5Sopenharmony_ci
105fa7767c5Sopenharmony_ci#define HST_HILOG_TAG(op, fmt, args...)                               \
106fa7767c5Sopenharmony_ci    do {                                                              \
107fa7767c5Sopenharmony_ci        op(LOG_TYPE, "[" PUBLIC_LOG_S "]:" fmt, HST_LOG_TAG, ##args); \
108fa7767c5Sopenharmony_ci    } while (0)
109fa7767c5Sopenharmony_ci
110fa7767c5Sopenharmony_ci#define HST_HILOG_WITH_LEVEL_JUDGE(op1, op2, con, fmt, args...)                                              \
111fa7767c5Sopenharmony_ci    do {                                                                                                     \
112fa7767c5Sopenharmony_ci        if (!con) {                                                                                          \
113fa7767c5Sopenharmony_ci            op2(LOG_TYPE, "(" PUBLIC_LOG_S "(), " PUBLIC_LOG_D32 "): " fmt, __FUNCTION__, __LINE__, ##args); \
114fa7767c5Sopenharmony_ci        } else {                                                                                             \
115fa7767c5Sopenharmony_ci            op1(LOG_TYPE, "(" PUBLIC_LOG_S "(), " PUBLIC_LOG_D32 "): " fmt, __FUNCTION__, __LINE__, ##args); \
116fa7767c5Sopenharmony_ci        }                                                                                                    \
117fa7767c5Sopenharmony_ci    } while (0)
118fa7767c5Sopenharmony_ci#endif
119fa7767c5Sopenharmony_ci
120fa7767c5Sopenharmony_ci#define MEDIA_LOG_D(fmt, ...) HST_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
121fa7767c5Sopenharmony_ci#define MEDIA_LOG_I(fmt, ...) HST_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
122fa7767c5Sopenharmony_ci#define MEDIA_LOG_W(fmt, ...) HST_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
123fa7767c5Sopenharmony_ci#define MEDIA_LOG_E(fmt, ...) HST_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
124fa7767c5Sopenharmony_ci#define MEDIA_LOG_F(fmt, ...) HST_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
125fa7767c5Sopenharmony_ci#define MEDIA_LOG_I_NO_RELEASE(fmt, ...) HST_HILOG_NO_RELEASE(HILOG_INFO, fmt, ##__VA_ARGS__)
126fa7767c5Sopenharmony_ci#define MEDIA_LOG_W_NO_RELEASE(fmt, ...) HST_HILOG_NO_RELEASE(HILOG_WARN, fmt, ##__VA_ARGS__)
127fa7767c5Sopenharmony_ci#define MEDIA_LOG_E_NO_RELEASE(fmt, ...) HST_HILOG_NO_RELEASE(HILOG_ERROR, fmt, ##__VA_ARGS__)
128fa7767c5Sopenharmony_ci#define MEDIA_LOG_F_NO_RELEASE(fmt, ...) HST_HILOG_NO_RELEASE(HILOG_FATAL, fmt, ##__VA_ARGS__)
129fa7767c5Sopenharmony_ci#define MEDIA_LOG_D_SHORT(fmt, ...) HST_HILOG_SHORT(HILOG_DEBUG, fmt, ##__VA_ARGS__)
130fa7767c5Sopenharmony_ci#define MEDIA_LOG_I_SHORT(fmt, ...) HST_HILOG_SHORT(HILOG_INFO, fmt, ##__VA_ARGS__)
131fa7767c5Sopenharmony_ci#define MEDIA_LOG_W_SHORT(fmt, ...) HST_HILOG_SHORT(HILOG_WARN, fmt, ##__VA_ARGS__)
132fa7767c5Sopenharmony_ci#define MEDIA_LOG_E_SHORT(fmt, ...) HST_HILOG_SHORT(HILOG_ERROR, fmt, ##__VA_ARGS__)
133fa7767c5Sopenharmony_ci#define MEDIA_LOG_F_SHORT(fmt, ...) HST_HILOG_SHORT(HILOG_FATAL, fmt, ##__VA_ARGS__)
134fa7767c5Sopenharmony_ci#define MEDIA_LOG_I_FALSE_D(con, fmt, ...) \
135fa7767c5Sopenharmony_ci    HST_HILOG_WITH_LEVEL_JUDGE(HILOG_INFO, HILOG_DEBUG, con, fmt, ##__VA_ARGS__)
136fa7767c5Sopenharmony_ci
137fa7767c5Sopenharmony_ci#define HST_HILOG_T_WITH_LEVEL_JUDGE(op1, op2, con, fmt, args...)           \
138fa7767c5Sopenharmony_ci    do {                                                                    \
139fa7767c5Sopenharmony_ci        if (!con) {                                                         \
140fa7767c5Sopenharmony_ci            op2(LOG_TYPE, "[" PUBLIC_LOG_S "]:" fmt, HST_LOG_TAG, ##args);  \
141fa7767c5Sopenharmony_ci        } else {                                                            \
142fa7767c5Sopenharmony_ci            op1(LOG_TYPE, "[" PUBLIC_LOG_S "]:" fmt, HST_LOG_TAG, ##args);  \
143fa7767c5Sopenharmony_ci        }                                                                   \
144fa7767c5Sopenharmony_ci    } while (0)
145fa7767c5Sopenharmony_ci
146fa7767c5Sopenharmony_ci#define MEDIA_LOG_D_T(fmt, ...) HST_HILOG_TAG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
147fa7767c5Sopenharmony_ci#define MEDIA_LOG_I_T(fmt, ...) HST_HILOG_TAG(HILOG_INFO, fmt, ##__VA_ARGS__)
148fa7767c5Sopenharmony_ci#define MEDIA_LOG_W_T(fmt, ...) HST_HILOG_TAG(HILOG_WARN, fmt, ##__VA_ARGS__)
149fa7767c5Sopenharmony_ci#define MEDIA_LOG_E_T(fmt, ...) HST_HILOG_TAG(HILOG_ERROR, fmt, ##__VA_ARGS__)
150fa7767c5Sopenharmony_ci#define MEDIA_LOG_F_T(fmt, ...) HST_HILOG_TAG(HILOG_FATAL, fmt, ##__VA_ARGS__)
151fa7767c5Sopenharmony_ci#define MEDIA_LOG_I_FALSE_D_T(con, fmt, ...)                                      \
152fa7767c5Sopenharmony_ci    HST_HILOG_T_WITH_LEVEL_JUDGE(HILOG_INFO, HILOG_DEBUG, con, fmt, ##__VA_ARGS__)
153fa7767c5Sopenharmony_ci
154fa7767c5Sopenharmony_ci#define MEDIA_LOG_LIMIT(op, frequency, fmt, ...)             \
155fa7767c5Sopenharmony_ci    do {                                                     \
156fa7767c5Sopenharmony_ci        static uint64_t currentTimes = 0;                    \
157fa7767c5Sopenharmony_ci        if (currentTimes++ % ((uint32_t)(frequency)) == 0) { \
158fa7767c5Sopenharmony_ci            op(fmt, ##__VA_ARGS__);                          \
159fa7767c5Sopenharmony_ci        }                                                    \
160fa7767c5Sopenharmony_ci    } while (0)
161fa7767c5Sopenharmony_ci
162fa7767c5Sopenharmony_ci#define MEDIA_LOGE_LIMIT(frequency, fmt, ...) MEDIA_LOG_LIMIT(MEDIA_LOG_E, frequency, fmt, ##__VA_ARGS__)
163fa7767c5Sopenharmony_ci#define MEDIA_LOGW_LIMIT(frequency, fmt, ...) MEDIA_LOG_LIMIT(MEDIA_LOG_W, frequency, fmt, ##__VA_ARGS__)
164fa7767c5Sopenharmony_ci#define MEDIA_LOGI_LIMIT(frequency, fmt, ...) MEDIA_LOG_LIMIT(MEDIA_LOG_I, frequency, fmt, ##__VA_ARGS__)
165fa7767c5Sopenharmony_ci#define MEDIA_LOGD_LIMIT(frequency, fmt, ...) MEDIA_LOG_LIMIT(MEDIA_LOG_D, frequency, fmt, ##__VA_ARGS__)
166fa7767c5Sopenharmony_ci#endif
167fa7767c5Sopenharmony_ci
168fa7767c5Sopenharmony_ci// Control the MEDIA_LOG_D.
169fa7767c5Sopenharmony_ci// If MEDIA_LOG_D is needed, #define MEDIA_LOG_DEBUG 1 at the beginning of the cpp file.
170fa7767c5Sopenharmony_ci#ifndef MEDIA_LOG_DEBUG
171fa7767c5Sopenharmony_ci#define MEDIA_LOG_DEBUG 1
172fa7767c5Sopenharmony_ci#endif
173fa7767c5Sopenharmony_ci
174fa7767c5Sopenharmony_ci#if !MEDIA_LOG_DEBUG
175fa7767c5Sopenharmony_ci#undef MEDIA_LOG_D
176fa7767c5Sopenharmony_ci#define MEDIA_LOG_D(msg, ...) ((void)0)
177fa7767c5Sopenharmony_ci#endif
178fa7767c5Sopenharmony_ci
179fa7767c5Sopenharmony_ci// Control the debug detail logs MEDIA_LOG_DD.
180fa7767c5Sopenharmony_ci// If MEDIA_LOG_DD is needed, #define MEDIA_LOG_DEBUG_DETAIL 1 at the beginning of the cpp file.
181fa7767c5Sopenharmony_ci#ifndef MEDIA_LOG_DEBUG_DETAIL
182fa7767c5Sopenharmony_ci#define MEDIA_LOG_DEBUG_DETAIL 0
183fa7767c5Sopenharmony_ci#endif
184fa7767c5Sopenharmony_ci
185fa7767c5Sopenharmony_ci#if !MEDIA_LOG_DEBUG_DETAIL
186fa7767c5Sopenharmony_ci#undef MEDIA_LOG_DD
187fa7767c5Sopenharmony_ci#define MEDIA_LOG_DD(msg, ...) ((void)0)
188fa7767c5Sopenharmony_ci#else
189fa7767c5Sopenharmony_ci#undef MEDIA_LOG_DD
190fa7767c5Sopenharmony_ci#define MEDIA_LOG_DD MEDIA_LOG_D
191fa7767c5Sopenharmony_ci#endif
192fa7767c5Sopenharmony_ci
193fa7767c5Sopenharmony_ci#ifndef NOK_RETURN
194fa7767c5Sopenharmony_ci#define NOK_RETURN(exec)                                                           \
195fa7767c5Sopenharmony_ci    do {                                                                           \
196fa7767c5Sopenharmony_ci        Status returnValue = (exec);                                               \
197fa7767c5Sopenharmony_ci        if (returnValue != Status::OK) {                                           \
198fa7767c5Sopenharmony_ci            MEDIA_LOG_E("NOK_RETURN on Status(" PUBLIC_LOG_D32 ").", returnValue); \
199fa7767c5Sopenharmony_ci            return returnValue;                                                    \
200fa7767c5Sopenharmony_ci        }                                                                          \
201fa7767c5Sopenharmony_ci    } while (0)
202fa7767c5Sopenharmony_ci#endif
203fa7767c5Sopenharmony_ci
204fa7767c5Sopenharmony_ci#ifndef NOK_LOG
205fa7767c5Sopenharmony_ci#define NOK_LOG(exec)                                                           \
206fa7767c5Sopenharmony_ci    do {                                                                        \
207fa7767c5Sopenharmony_ci        Status returnValue = (exec);                                            \
208fa7767c5Sopenharmony_ci        if (returnValue != Status::OK) {                                        \
209fa7767c5Sopenharmony_ci            MEDIA_LOG_E("NOK_LOG on Status(" PUBLIC_LOG_D32 ").", returnValue); \
210fa7767c5Sopenharmony_ci        }                                                                       \
211fa7767c5Sopenharmony_ci    } while (0)
212fa7767c5Sopenharmony_ci#endif
213fa7767c5Sopenharmony_ci
214fa7767c5Sopenharmony_ci// If exec not return zero, then record the error code, especially when call system C function.
215fa7767c5Sopenharmony_ci#ifndef NZERO_LOG
216fa7767c5Sopenharmony_ci#define NZERO_LOG(exec)                                                                          \
217fa7767c5Sopenharmony_ci    do {                                                                                         \
218fa7767c5Sopenharmony_ci        int returnValue = (exec);                                                                \
219fa7767c5Sopenharmony_ci        if (returnValue != 0) {                                                                  \
220fa7767c5Sopenharmony_ci            MEDIA_LOG_E("NZERO_LOG when call (" #exec "), return " PUBLIC_LOG_D32, returnValue); \
221fa7767c5Sopenharmony_ci        }                                                                                        \
222fa7767c5Sopenharmony_ci    } while (0)
223fa7767c5Sopenharmony_ci#endif
224fa7767c5Sopenharmony_ci
225fa7767c5Sopenharmony_ci#ifndef NZERO_RETURN
226fa7767c5Sopenharmony_ci#define NZERO_RETURN(exec)                                                                          \
227fa7767c5Sopenharmony_ci    do {                                                                                            \
228fa7767c5Sopenharmony_ci        int returnValue = (exec);                                                                   \
229fa7767c5Sopenharmony_ci        if (returnValue != 0) {                                                                     \
230fa7767c5Sopenharmony_ci            MEDIA_LOG_E("NZERO_RETURN when call (" #exec "), return " PUBLIC_LOG_D32, returnValue); \
231fa7767c5Sopenharmony_ci            return returnValue;                                                                     \
232fa7767c5Sopenharmony_ci        }                                                                                           \
233fa7767c5Sopenharmony_ci    } while (0)
234fa7767c5Sopenharmony_ci#endif
235fa7767c5Sopenharmony_ci
236fa7767c5Sopenharmony_ci#ifndef NZERO_RETURN_V
237fa7767c5Sopenharmony_ci#define NZERO_RETURN_V(exec, ret)                                                                     \
238fa7767c5Sopenharmony_ci    do {                                                                                              \
239fa7767c5Sopenharmony_ci        int returnValue = (exec);                                                                     \
240fa7767c5Sopenharmony_ci        if (returnValue != 0) {                                                                       \
241fa7767c5Sopenharmony_ci            MEDIA_LOG_E("NZERO_RETURN_V when call (" #exec "), return " PUBLIC_LOG_D32, returnValue); \
242fa7767c5Sopenharmony_ci            return ret;                                                                               \
243fa7767c5Sopenharmony_ci        }                                                                                             \
244fa7767c5Sopenharmony_ci    } while (0)
245fa7767c5Sopenharmony_ci#endif
246fa7767c5Sopenharmony_ci
247fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN
248fa7767c5Sopenharmony_ci#define FALSE_RETURN(exec)                                 \
249fa7767c5Sopenharmony_ci    do {                                                   \
250fa7767c5Sopenharmony_ci        bool returnValue = (exec);                         \
251fa7767c5Sopenharmony_ci        if (!returnValue) {                                \
252fa7767c5Sopenharmony_ci            MEDIA_LOG_E_NO_RELEASE("FALSE_RETURN " #exec); \
253fa7767c5Sopenharmony_ci            return;                                        \
254fa7767c5Sopenharmony_ci        }                                                  \
255fa7767c5Sopenharmony_ci    } while (0)
256fa7767c5Sopenharmony_ci#endif
257fa7767c5Sopenharmony_ci
258fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_NOLOG
259fa7767c5Sopenharmony_ci#define FALSE_RETURN_NOLOG(exec)                                 \
260fa7767c5Sopenharmony_ci    do {                                                   \
261fa7767c5Sopenharmony_ci        bool returnValue = (exec);                         \
262fa7767c5Sopenharmony_ci        if (!returnValue) {                                \
263fa7767c5Sopenharmony_ci            return;                                        \
264fa7767c5Sopenharmony_ci        }                                                  \
265fa7767c5Sopenharmony_ci    } while (0)
266fa7767c5Sopenharmony_ci#endif
267fa7767c5Sopenharmony_ci
268fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_W
269fa7767c5Sopenharmony_ci#define FALSE_RETURN_W(exec)                    \
270fa7767c5Sopenharmony_ci    do {                                        \
271fa7767c5Sopenharmony_ci        bool returnValue = (exec);              \
272fa7767c5Sopenharmony_ci        if (!returnValue) {                     \
273fa7767c5Sopenharmony_ci            MEDIA_LOG_W("FALSE_RETURN " #exec); \
274fa7767c5Sopenharmony_ci            return;                             \
275fa7767c5Sopenharmony_ci        }                                       \
276fa7767c5Sopenharmony_ci    } while (0)
277fa7767c5Sopenharmony_ci#endif
278fa7767c5Sopenharmony_ci
279fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V
280fa7767c5Sopenharmony_ci#define FALSE_RETURN_V(exec, ret)                            \
281fa7767c5Sopenharmony_ci    do {                                                     \
282fa7767c5Sopenharmony_ci        bool returnValue = (exec);                           \
283fa7767c5Sopenharmony_ci        if (!returnValue) {                                  \
284fa7767c5Sopenharmony_ci            MEDIA_LOG_E_NO_RELEASE("FALSE_RETURN_V " #exec); \
285fa7767c5Sopenharmony_ci            return ret;                                      \
286fa7767c5Sopenharmony_ci        }                                                    \
287fa7767c5Sopenharmony_ci    } while (0)
288fa7767c5Sopenharmony_ci#endif
289fa7767c5Sopenharmony_ci
290fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V_NOLOG
291fa7767c5Sopenharmony_ci#define FALSE_RETURN_V_NOLOG(exec, ret)                            \
292fa7767c5Sopenharmony_ci    do {                                                     \
293fa7767c5Sopenharmony_ci        bool returnValue = (exec);                           \
294fa7767c5Sopenharmony_ci        if (!returnValue) {                                  \
295fa7767c5Sopenharmony_ci            return ret;                                      \
296fa7767c5Sopenharmony_ci        }                                                    \
297fa7767c5Sopenharmony_ci    } while (0)
298fa7767c5Sopenharmony_ci#endif
299fa7767c5Sopenharmony_ci
300fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V_W
301fa7767c5Sopenharmony_ci#define FALSE_RETURN_V_W(exec, ret)                 \
302fa7767c5Sopenharmony_ci    do {                                            \
303fa7767c5Sopenharmony_ci        bool returnValue = (exec);                  \
304fa7767c5Sopenharmony_ci        if (!returnValue) {                         \
305fa7767c5Sopenharmony_ci            MEDIA_LOG_W("FALSE_RETURN_V_W " #exec); \
306fa7767c5Sopenharmony_ci            return ret;                             \
307fa7767c5Sopenharmony_ci        }                                           \
308fa7767c5Sopenharmony_ci    } while (0)
309fa7767c5Sopenharmony_ci#endif
310fa7767c5Sopenharmony_ci
311fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_MSG
312fa7767c5Sopenharmony_ci#define FALSE_RETURN_MSG(exec, fmt, args...) \
313fa7767c5Sopenharmony_ci    do {                                     \
314fa7767c5Sopenharmony_ci        bool returnValue = (exec);           \
315fa7767c5Sopenharmony_ci        if (!returnValue) {                  \
316fa7767c5Sopenharmony_ci            MEDIA_LOG_E(fmt, ##args);        \
317fa7767c5Sopenharmony_ci            return;                          \
318fa7767c5Sopenharmony_ci        }                                    \
319fa7767c5Sopenharmony_ci    } while (0)
320fa7767c5Sopenharmony_ci#endif
321fa7767c5Sopenharmony_ci
322fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V_MSG_IMPL
323fa7767c5Sopenharmony_ci#define FALSE_RETURN_V_MSG_IMPL(loglevel, exec, ret, fmt, args...) \
324fa7767c5Sopenharmony_ci    do {                                                           \
325fa7767c5Sopenharmony_ci        bool returnValue = (exec);                                 \
326fa7767c5Sopenharmony_ci        if (!returnValue) {                                        \
327fa7767c5Sopenharmony_ci            loglevel(fmt, ##args);                                 \
328fa7767c5Sopenharmony_ci            return ret;                                            \
329fa7767c5Sopenharmony_ci        }                                                          \
330fa7767c5Sopenharmony_ci    } while (0)
331fa7767c5Sopenharmony_ci#endif
332fa7767c5Sopenharmony_ci
333fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V_MSG
334fa7767c5Sopenharmony_ci#define FALSE_RETURN_V_MSG(exec, ret, fmt, args...) FALSE_RETURN_V_MSG_IMPL(MEDIA_LOG_E, exec, ret, fmt, ##args)
335fa7767c5Sopenharmony_ci#endif
336fa7767c5Sopenharmony_ci
337fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V_MSG_D
338fa7767c5Sopenharmony_ci#define FALSE_RETURN_V_MSG_D(exec, ret, fmt, args...) FALSE_RETURN_V_MSG_IMPL(MEDIA_LOG_D, exec, ret, fmt, ##args)
339fa7767c5Sopenharmony_ci#endif
340fa7767c5Sopenharmony_ci
341fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V_MSG_W
342fa7767c5Sopenharmony_ci#define FALSE_RETURN_V_MSG_W(exec, ret, fmt, args...) FALSE_RETURN_V_MSG_IMPL(MEDIA_LOG_W, exec, ret, fmt, ##args)
343fa7767c5Sopenharmony_ci#endif
344fa7767c5Sopenharmony_ci
345fa7767c5Sopenharmony_ci#ifndef FALSE_RETURN_V_MSG_E
346fa7767c5Sopenharmony_ci#define FALSE_RETURN_V_MSG_E(exec, ret, fmt, args...) FALSE_RETURN_V_MSG_IMPL(MEDIA_LOG_E, exec, ret, fmt, ##args)
347fa7767c5Sopenharmony_ci#endif
348fa7767c5Sopenharmony_ci
349fa7767c5Sopenharmony_ci#ifndef FALSE_LOG
350fa7767c5Sopenharmony_ci#define FALSE_LOG(exec)                       \
351fa7767c5Sopenharmony_ci    do {                                      \
352fa7767c5Sopenharmony_ci        bool returnValue = (exec);            \
353fa7767c5Sopenharmony_ci        if (!returnValue) {                   \
354fa7767c5Sopenharmony_ci            MEDIA_LOG_E("FALSE_LOG: " #exec); \
355fa7767c5Sopenharmony_ci        }                                     \
356fa7767c5Sopenharmony_ci    } while (0)
357fa7767c5Sopenharmony_ci#endif
358fa7767c5Sopenharmony_ci
359fa7767c5Sopenharmony_ci#ifndef FALSE_LOG_MSG_IMPL
360fa7767c5Sopenharmony_ci#define FALSE_LOG_MSG_IMPL(loglevel, exec, fmt, args...) \
361fa7767c5Sopenharmony_ci    do {                                                 \
362fa7767c5Sopenharmony_ci        bool returnValue = (exec);                       \
363fa7767c5Sopenharmony_ci        if (!returnValue) {                              \
364fa7767c5Sopenharmony_ci            loglevel(fmt, ##args);                       \
365fa7767c5Sopenharmony_ci        }                                                \
366fa7767c5Sopenharmony_ci    } while (0)
367fa7767c5Sopenharmony_ci#endif
368fa7767c5Sopenharmony_ci
369fa7767c5Sopenharmony_ci#ifndef FALSE_LOG_MSG
370fa7767c5Sopenharmony_ci#define FALSE_LOG_MSG(exec, fmt, args...) FALSE_LOG_MSG_IMPL(MEDIA_LOG_E, exec, fmt, ##args)
371fa7767c5Sopenharmony_ci#endif
372fa7767c5Sopenharmony_ci
373fa7767c5Sopenharmony_ci#ifndef FALSE_LOG_MSG_W
374fa7767c5Sopenharmony_ci#define FALSE_LOG_MSG_W(exec, fmt, args...) FALSE_LOG_MSG_IMPL(MEDIA_LOG_W, exec, fmt, ##args)
375fa7767c5Sopenharmony_ci#endif
376fa7767c5Sopenharmony_ci
377fa7767c5Sopenharmony_ci#define POINTER_MASK 0x00FFFFFF
378fa7767c5Sopenharmony_ci#define FAKE_POINTER(addr) (POINTER_MASK & reinterpret_cast<uintptr_t>(addr))
379fa7767c5Sopenharmony_ci#endif  // HISTREAMER_FOUNDATION_LOG_H