-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathwrapper.cpp
More file actions
74 lines (61 loc) · 2.16 KB
/
Copy pathwrapper.cpp
File metadata and controls
74 lines (61 loc) · 2.16 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
67
68
69
70
71
72
73
74
/*
* 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.
*/
#include "libspdl/cuda/nvdec/detail/wrapper.h"
#include "libspdl/core/detail/tracing.h"
#include "libspdl/cuda/detail/utils.h"
#include <fmt/core.h>
#include <fmt/format.h>
#include <glog/logging.h>
#include <cuda.h>
#define WARN_IF_NOT_SUCCESS(expr, msg) \
do { \
auto __status = expr; \
if (__status != CUDA_SUCCESS) { \
LOG(WARNING) << fmt::format( \
"{} ({}: {})", \
msg, \
spdl::cuda::detail::get_error_name(__status), \
spdl::cuda::detail::get_error_desc(__status)); \
} \
} while (0)
namespace spdl::cuda::detail {
void CUvideoparserDeleter::operator()(CUvideoparser p) {
WARN_IF_NOT_SUCCESS(
cuvidDestroyVideoParser(p), "Failed to destroy CUvideoparser.");
}
void CUvideodecoderDeleter::operator()(void* p) {
WARN_IF_NOT_SUCCESS(
cuvidDestroyDecoder((CUvideodecoder)p),
"Failed to destroy CUvideodecoder.");
}
void CUvideoctxlockDeleter::operator()(void* p) {
WARN_IF_NOT_SUCCESS(
cuvidCtxLockDestroy((CUvideoctxlock)p),
"Failed to create CUvideoctxlock.");
}
MapGuard::MapGuard(
CUvideodecoder dec,
CUVIDPROCPARAMS* proc_params,
int picture_index)
: decoder(dec) {
TRACE_EVENT("nvdec", "cuvidMapVideoFrame");
CHECK_CU(
cuvidMapVideoFrame(decoder, picture_index, &frame, &pitch, proc_params),
"Failed to map video frame.");
}
MapGuard::~MapGuard() {
TRACE_EVENT("nvdec", "cuvidUnmapVideoFrame");
auto status = cuvidUnmapVideoFrame(decoder, frame);
if (status != CUDA_SUCCESS) {
LOG(ERROR) << fmt::format(
"Failed to unmap video frame ({}: {})",
get_error_name(status),
get_error_desc(status));
}
}
} // namespace spdl::cuda::detail