6
6
7
7
#include " cereal/visionipc/visionbuf.h"
8
8
9
+ #ifdef __APPLE__
10
+ #define HW_DEVICE_TYPE AV_HWDEVICE_TYPE_VIDEOTOOLBOX
11
+ #define HW_PIX_FMT AV_PIX_FMT_VIDEOTOOLBOX
12
+ #else
13
+ #define HW_DEVICE_TYPE AV_HWDEVICE_TYPE_CUDA
14
+ #define HW_PIX_FMT AV_PIX_FMT_CUDA
15
+ #endif
16
+
9
17
namespace {
10
18
11
19
struct buffer_data {
@@ -30,7 +38,7 @@ enum AVPixelFormat get_hw_format(AVCodecContext *ctx, const enum AVPixelFormat *
30
38
for (const enum AVPixelFormat *p = pix_fmts; *p != -1 ; p++) {
31
39
if (*p == *hw_pix_fmt) return *p;
32
40
}
33
- rWarning (" Please run replay with the --no-cuda flag!" );
41
+ rWarning (" Please run replay with the --no-hw-decoder flag!" );
34
42
// fallback to YUV420p
35
43
*hw_pix_fmt = AV_PIX_FMT_NONE;
36
44
return AV_PIX_FMT_YUV420P;
@@ -57,15 +65,15 @@ FrameReader::~FrameReader() {
57
65
}
58
66
}
59
67
60
- bool FrameReader::load (const std::string &url, bool no_cuda , std::atomic<bool > *abort, bool local_cache, int chunk_size, int retries) {
68
+ bool FrameReader::load (const std::string &url, bool no_hw_decoder , std::atomic<bool > *abort, bool local_cache, int chunk_size, int retries) {
61
69
FileReader f (local_cache, chunk_size, retries);
62
70
std::string data = f.read (url, abort );
63
71
if (data.empty ()) return false ;
64
72
65
- return load ((std::byte *)data.data (), data.size (), no_cuda , abort );
73
+ return load ((std::byte *)data.data (), data.size (), no_hw_decoder , abort );
66
74
}
67
75
68
- bool FrameReader::load (const std::byte *data, size_t size, bool no_cuda , std::atomic<bool > *abort) {
76
+ bool FrameReader::load (const std::byte *data, size_t size, bool no_hw_decoder , std::atomic<bool > *abort) {
69
77
input_ctx = avformat_alloc_context ();
70
78
if (!input_ctx) return false ;
71
79
@@ -106,9 +114,9 @@ bool FrameReader::load(const std::byte *data, size_t size, bool no_cuda, std::at
106
114
height = decoder_ctx->height ;
107
115
visionbuf_compute_aligned_width_and_height (width, height, &aligned_width, &aligned_height);
108
116
109
- if (has_cuda_device && !no_cuda ) {
110
- if (!initHardwareDecoder (AV_HWDEVICE_TYPE_CUDA )) {
111
- rWarning (" No CUDA capable device was found. fallback to CPU decoding." );
117
+ if (has_hw_decoder && !no_hw_decoder ) {
118
+ if (!initHardwareDecoder (HW_DEVICE_TYPE )) {
119
+ rWarning (" No device with hardware decoder found. fallback to CPU decoding." );
112
120
} else {
113
121
nv12toyuv_buffer.resize (getYUVSize ());
114
122
}
@@ -151,7 +159,7 @@ bool FrameReader::initHardwareDecoder(AVHWDeviceType hw_device_type) {
151
159
int ret = av_hwdevice_ctx_create (&hw_device_ctx, hw_device_type, nullptr , nullptr , 0 );
152
160
if (ret < 0 ) {
153
161
hw_pix_fmt = AV_PIX_FMT_NONE;
154
- has_cuda_device = false ;
162
+ has_hw_decoder = false ;
155
163
rWarning (" Failed to create specified HW device %d." , ret);
156
164
return false ;
157
165
}
@@ -219,7 +227,7 @@ AVFrame *FrameReader::decodeFrame(AVPacket *pkt) {
219
227
}
220
228
221
229
bool FrameReader::copyBuffers (AVFrame *f, uint8_t *rgb, uint8_t *yuv) {
222
- if (hw_pix_fmt == AV_PIX_FMT_CUDA ) {
230
+ if (hw_pix_fmt == HW_PIX_FMT ) {
223
231
uint8_t *y = yuv ? yuv : nv12toyuv_buffer.data ();
224
232
uint8_t *u = y + width * height;
225
233
uint8_t *v = u + (width / 2 ) * (height / 2 );
0 commit comments