-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathlogging.h
More file actions
66 lines (56 loc) · 2.33 KB
/
Copy pathlogging.h
File metadata and controls
66 lines (56 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include "libspdl/common/logging.h"
#include <fmt/core.h>
extern "C" {
#include <libavutil/attributes.h>
#include <libavutil/error.h>
}
namespace spdl::core::detail {
namespace {
// Replacement of av_err2str, which causes
// `error: taking address of temporary array`
// https://github.com/joncampbell123/composite-video-simulator/issues/5
av_always_inline std::string av_err2string(int errnum) {
char str[AV_ERROR_MAX_STRING_SIZE];
return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum);
}
} // namespace
template <typename... Args>
inline std::string av_error(int errnum, std::string_view tmp, Args&&... args) {
return fmt::format(
"{} ({})",
fmt::vformat(tmp, fmt::make_format_args(std::forward<Args>(args)...)),
av_err2string(errnum));
}
} // namespace spdl::core::detail
#define CHECK_AVERROR(expression, ...) \
if (int _errnum = expression; _errnum < 0) [[unlikely]] { \
SPDL_FAIL(::spdl::core::detail::av_error(_errnum, __VA_ARGS__)); \
}
#define CHECK_AVERROR_NUM(errnum, ...) \
if (errnum < 0) [[unlikely]] { \
SPDL_FAIL(::spdl::core::detail::av_error(errnum, __VA_ARGS__)); \
}
#define CHECK_AVALLOCATE(expression) \
[&]() { \
auto* p = expression; \
if (!p) [[unlikely]] { \
SPDL_FAIL("Allocation failed (" #expression ")"); \
} \
return p; \
}()
#define CHECK_AV_NON_NULL(expression) \
[&]() { \
auto* p = expression; \
if (!p) [[unlikely]] { \
SPDL_FAIL("Failed to retrieve a pointer (" #expression ")"); \
} \
return p; \
}()