Commit d384f0e90a24c6a3cfd4f90ba6a66474c39dc10f
1 parent
3c7e3e11
代码优化
Showing
7 changed files
with
130 additions
and
53 deletions
.vscode/launch.json
.vscode/settings.json
... | ... | @@ -10,6 +10,57 @@ |
10 | 10 | "iostream": "cpp", |
11 | 11 | "thread": "cpp", |
12 | 12 | "nvdec.h": "c", |
13 | - "chrono": "cpp" | |
13 | + "chrono": "cpp", | |
14 | + "atomic": "cpp", | |
15 | + "bit": "cpp", | |
16 | + "*.tcc": "cpp", | |
17 | + "bitset": "cpp", | |
18 | + "cctype": "cpp", | |
19 | + "clocale": "cpp", | |
20 | + "cmath": "cpp", | |
21 | + "codecvt": "cpp", | |
22 | + "condition_variable": "cpp", | |
23 | + "cstdarg": "cpp", | |
24 | + "cstddef": "cpp", | |
25 | + "cstdint": "cpp", | |
26 | + "cstdio": "cpp", | |
27 | + "cstdlib": "cpp", | |
28 | + "cstring": "cpp", | |
29 | + "ctime": "cpp", | |
30 | + "cwchar": "cpp", | |
31 | + "cwctype": "cpp", | |
32 | + "deque": "cpp", | |
33 | + "map": "cpp", | |
34 | + "set": "cpp", | |
35 | + "unordered_map": "cpp", | |
36 | + "vector": "cpp", | |
37 | + "exception": "cpp", | |
38 | + "algorithm": "cpp", | |
39 | + "functional": "cpp", | |
40 | + "iterator": "cpp", | |
41 | + "memory": "cpp", | |
42 | + "memory_resource": "cpp", | |
43 | + "numeric": "cpp", | |
44 | + "optional": "cpp", | |
45 | + "random": "cpp", | |
46 | + "ratio": "cpp", | |
47 | + "system_error": "cpp", | |
48 | + "tuple": "cpp", | |
49 | + "type_traits": "cpp", | |
50 | + "utility": "cpp", | |
51 | + "fstream": "cpp", | |
52 | + "initializer_list": "cpp", | |
53 | + "iomanip": "cpp", | |
54 | + "istream": "cpp", | |
55 | + "limits": "cpp", | |
56 | + "mutex": "cpp", | |
57 | + "new": "cpp", | |
58 | + "ostream": "cpp", | |
59 | + "sstream": "cpp", | |
60 | + "stdexcept": "cpp", | |
61 | + "streambuf": "cpp", | |
62 | + "cfenv": "cpp", | |
63 | + "cinttypes": "cpp", | |
64 | + "__nullptr": "cpp" | |
14 | 65 | } |
15 | 66 | } |
16 | 67 | \ No newline at end of file | ... | ... |
src/FFCuContextManager.cpp
... | ... | @@ -19,7 +19,7 @@ AVBufferRef *FFCuContextManager::getCuCtx(string gpuid) |
19 | 19 | // 初始化硬件解码器 |
20 | 20 | if (av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_CUDA, gpuid.c_str(), nullptr, 0) < 0) |
21 | 21 | { |
22 | - cout << "Failed to create specified HW device."; | |
22 | + av_log(nullptr, AV_LOG_ERROR, "Failed to create specified HW device ! \n"); | |
23 | 23 | return nullptr; |
24 | 24 | } |
25 | 25 | ctxMap[gpuid] = hw_device_ctx; | ... | ... |
src/FFNvDecoder.cpp
... | ... | @@ -4,8 +4,6 @@ |
4 | 4 | #include <thread> |
5 | 5 | #include <fstream> |
6 | 6 | |
7 | -#include <chrono> | |
8 | - | |
9 | 7 | #include "FFCuContextManager.h" |
10 | 8 | |
11 | 9 | using namespace std; |
... | ... | @@ -23,7 +21,7 @@ static AVPixelFormat get_hw_format(AVCodecContext *avctx, const AVPixelFormat *p |
23 | 21 | return *p; |
24 | 22 | } |
25 | 23 | |
26 | - av_log(NULL, AV_LOG_ERROR, "Failed to get HW surface format. \n"); | |
24 | + av_log(nullptr, AV_LOG_ERROR, "Failed to get HW surface format. \n"); | |
27 | 25 | return AV_PIX_FMT_NONE; |
28 | 26 | } |
29 | 27 | |
... | ... | @@ -85,13 +83,13 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp) |
85 | 83 | fmt_ctx = avformat_alloc_context(); |
86 | 84 | const char* input_file = uri; |
87 | 85 | if (avformat_open_input(&fmt_ctx, input_file, nullptr, &options) != 0) { |
88 | - av_log(NULL, AV_LOG_ERROR, "Cannot open input file: %s \n", input_file); | |
86 | + av_log(nullptr, AV_LOG_ERROR, "Cannot open input file: %s \n", input_file); | |
89 | 87 | return false; |
90 | 88 | } |
91 | 89 | |
92 | 90 | // 查找流信息 |
93 | 91 | if (avformat_find_stream_info(fmt_ctx, nullptr) < 0) { |
94 | - av_log(NULL, AV_LOG_ERROR, "Cannot find input stream information ! \n"); | |
92 | + av_log(nullptr, AV_LOG_ERROR, "Cannot find input stream information ! \n"); | |
95 | 93 | return false; |
96 | 94 | } |
97 | 95 | |
... | ... | @@ -99,7 +97,7 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp) |
99 | 97 | AVCodec *decoder = nullptr; |
100 | 98 | stream_index = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &decoder, 0); |
101 | 99 | if (stream_index < 0) { |
102 | - av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file ! \n"); | |
100 | + av_log(nullptr, AV_LOG_ERROR, "Cannot find a video stream in the input file ! \n"); | |
103 | 101 | return false; |
104 | 102 | } |
105 | 103 | |
... | ... | @@ -120,7 +118,13 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp) |
120 | 118 | hw_pix_fmt = AV_PIX_FMT_CUDA; |
121 | 119 | |
122 | 120 | FFCuContextManager* pCtxMgr = FFCuContextManager::getInstance(); |
123 | - avctx->hw_device_ctx = av_buffer_ref(pCtxMgr->getCuCtx(gpuid)); | |
121 | + | |
122 | + AVBufferRef *hw_device_ctx = pCtxMgr->getCuCtx(gpuid); | |
123 | + if(nullptr == hw_device_ctx){ | |
124 | + av_log(nullptr, AV_LOG_ERROR, "create CUDA context failed ! \n"); | |
125 | + return false; | |
126 | + } | |
127 | + avctx->hw_device_ctx = av_buffer_ref(hw_device_ctx); | |
124 | 128 | if (nullptr == avctx->hw_device_ctx) |
125 | 129 | { |
126 | 130 | return false; |
... | ... | @@ -129,9 +133,9 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp) |
129 | 133 | // 打开解码器流 |
130 | 134 | AVDictionary *op = nullptr; |
131 | 135 | av_dict_set( &op, "gpu", gpuid, 0 ); |
132 | - av_dict_set( &op, "surfaces", "10", 0 ); | |
136 | + // av_dict_set( &op, "surfaces", "10", 0 ); | |
133 | 137 | if (avcodec_open2(avctx, vcodec, &op) < 0) { |
134 | - av_log(NULL, AV_LOG_ERROR, "Failed to open codec for stream ! \n"); | |
138 | + av_log(nullptr, AV_LOG_ERROR, "Failed to open codec for stream ! \n"); | |
135 | 139 | return false; |
136 | 140 | } |
137 | 141 | |
... | ... | @@ -161,14 +165,12 @@ void FFNvDecoder::start(){ |
161 | 165 | |
162 | 166 | static long long get_cur_time(){ |
163 | 167 | // 获取操作系统当前时间点(精确到微秒) |
164 | - chrono::time_point<chrono::system_clock, chrono::microseconds> tpMicro | |
165 | - = chrono::time_point_cast<chrono::microseconds>(chrono::system_clock::now()); | |
168 | + chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro | |
169 | + = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now()); | |
166 | 170 | // (微秒精度的)时间点 => (微秒精度的)时间戳 |
167 | - time_t totalMicroSeconds = tpMicro.time_since_epoch().count(); | |
171 | + time_t currentTime = tpMicro.time_since_epoch().count(); | |
168 | 172 | |
169 | - long long currentTime = ((long long)totalMicroSeconds)/1000; | |
170 | - | |
171 | - return currentTime; | |
173 | + return (long long )currentTime; | |
172 | 174 | } |
173 | 175 | |
174 | 176 | void FFNvDecoder::decode_thread() |
... | ... | @@ -209,7 +211,7 @@ void FFNvDecoder::decode_thread() |
209 | 211 | int result = av_read_frame(fmt_ctx, pkt); |
210 | 212 | if (result == AVERROR_EOF || result < 0) |
211 | 213 | { |
212 | - av_log(NULL, AV_LOG_ERROR, "Failed to read frame! \n"); | |
214 | + av_log(nullptr, AV_LOG_ERROR, "Failed to read frame! \n"); | |
213 | 215 | break; |
214 | 216 | } |
215 | 217 | |
... | ... | @@ -231,13 +233,13 @@ void FFNvDecoder::decode_thread() |
231 | 233 | if (stream_index == pkt->stream_index){ |
232 | 234 | result = avcodec_send_packet(avctx, pkt); |
233 | 235 | if (result < 0){ |
234 | - av_log(NULL, AV_LOG_ERROR, "Failed to send pkt: %d \n",result); | |
236 | + av_log(nullptr, AV_LOG_ERROR, "Failed to send pkt: %d \n",result); | |
235 | 237 | continue; |
236 | 238 | } |
237 | 239 | |
238 | 240 | result = avcodec_receive_frame(avctx, gpuFrame); |
239 | 241 | if ((result == AVERROR(EAGAIN) || result == AVERROR_EOF) || result < 0){ |
240 | - av_log(NULL, AV_LOG_ERROR, "Failed to receive frame: %d \n",result); | |
242 | + av_log(nullptr, AV_LOG_ERROR, "Failed to receive frame: %d \n",result); | |
241 | 243 | continue; |
242 | 244 | } |
243 | 245 | |
... | ... | @@ -269,7 +271,7 @@ void FFNvDecoder::decode_thread() |
269 | 271 | |
270 | 272 | decode_finished(); |
271 | 273 | |
272 | - av_log(NULL, AV_LOG_INFO, "decode thread exited. \n"); | |
274 | + av_log(nullptr, AV_LOG_INFO, "decode thread exited. \n"); | |
273 | 275 | } |
274 | 276 | |
275 | 277 | void FFNvDecoder::decode_finished() |
... | ... | @@ -304,7 +306,7 @@ void FFNvDecoder::post_decode_thread() |
304 | 306 | mFrameQueue.addHead(); |
305 | 307 | } |
306 | 308 | |
307 | - av_log(NULL, AV_LOG_INFO, "post decode thread exited. \n"); | |
309 | + av_log(nullptr, AV_LOG_INFO, "post decode thread exited. \n"); | |
308 | 310 | } |
309 | 311 | |
310 | 312 | void FFNvDecoder::close() |
... | ... | @@ -345,10 +347,10 @@ bool FFNvDecoder::isPausing(){ |
345 | 347 | |
346 | 348 | bool FFNvDecoder::getResolution( int &width, int &height ) |
347 | 349 | { |
348 | - if (avctx != nullptr) | |
350 | + if (stream != nullptr && stream->codecpar != nullptr) | |
349 | 351 | { |
350 | - width = avctx->width; | |
351 | - height = avctx->height; | |
352 | + width = stream->codecpar->width; | |
353 | + height = stream->codecpar->height; | |
352 | 354 | return true; |
353 | 355 | } |
354 | 356 | |
... | ... | @@ -376,7 +378,7 @@ int FFNvDecoder::getCachedQueueLength(){ |
376 | 378 | |
377 | 379 | FFImgInfo* FFNvDecoder::snapshot(const string& uri){ |
378 | 380 | |
379 | - AVFormatContext* ifmt_ctx = NULL; | |
381 | + AVFormatContext* ifmt_ctx = nullptr; | |
380 | 382 | AVCodecContext* codec_ctx = nullptr; |
381 | 383 | AVCodec* codec = nullptr; |
382 | 384 | AVPacket* pkt = nullptr; |
... | ... | @@ -385,36 +387,44 @@ FFImgInfo* FFNvDecoder::snapshot(const string& uri){ |
385 | 387 | int video_index = -1; |
386 | 388 | AVStream* st = nullptr; |
387 | 389 | SwsContext *img_convert_ctx = nullptr; |
388 | - uint8_t *buffer = NULL; | |
390 | + uint8_t *buffer = nullptr; | |
389 | 391 | int numBytes = 0; |
390 | 392 | |
391 | 393 | FFImgInfo* imgInfo = nullptr; |
392 | - | |
393 | - //av_register_all(); | |
394 | + | |
395 | + | |
394 | 396 | avformat_network_init(); |
395 | 397 | |
398 | + // 打开输入视频文件 | |
399 | + AVDictionary *options = nullptr; | |
400 | + av_dict_set( &options, "bufsize", "655360", 0 ); | |
401 | + av_dict_set( &options, "rtsp_transport", "tcp", 0 ); | |
402 | + // av_dict_set( &options, "listen_timeout", "30", 0 ); // 单位为s | |
403 | + av_dict_set( &options, "stimeout", "30000000", 0 ); // 单位为 百万分之一秒 | |
404 | + | |
396 | 405 | ///打开输入的流 |
397 | - int ret = avformat_open_input(&ifmt_ctx, uri.c_str(), NULL, NULL); | |
406 | + ifmt_ctx = avformat_alloc_context(); | |
407 | + int ret = avformat_open_input(&ifmt_ctx, uri.c_str(), nullptr, &options); | |
398 | 408 | if (ret != 0){ |
399 | - av_log(NULL, AV_LOG_ERROR, "Couldn't open input stream ! \n"); | |
409 | + av_log(nullptr, AV_LOG_ERROR, "Couldn't open input stream ! \n"); | |
400 | 410 | goto end_flag ; |
401 | 411 | } |
402 | 412 | |
403 | 413 | //查找流信息 |
404 | - if (avformat_find_stream_info(ifmt_ctx, NULL) < 0){ | |
405 | - av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information ! \n"); | |
414 | + if (avformat_find_stream_info(ifmt_ctx, nullptr) < 0){ | |
415 | + av_log(nullptr, AV_LOG_ERROR, "Couldn't find stream information ! \n"); | |
406 | 416 | goto end_flag ; |
407 | 417 | } |
408 | 418 | |
409 | 419 | //找到视频流索引 |
410 | - video_index = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); | |
420 | + video_index = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0); | |
411 | 421 | |
412 | 422 | st = ifmt_ctx->streams[video_index]; |
413 | 423 | |
414 | 424 | //找到解码器 |
415 | 425 | codec = avcodec_find_decoder(st->codecpar->codec_id); |
416 | 426 | if (!codec){ |
417 | - av_log(NULL, AV_LOG_ERROR, "Codec not found ! \n"); | |
427 | + av_log(nullptr, AV_LOG_ERROR, "Codec not found ! \n"); | |
418 | 428 | goto end_flag ; |
419 | 429 | } |
420 | 430 | |
... | ... | @@ -427,7 +437,7 @@ FFImgInfo* FFNvDecoder::snapshot(const string& uri){ |
427 | 437 | avcodec_parameters_to_context(codec_ctx, ifmt_ctx->streams[video_index]->codecpar); |
428 | 438 | |
429 | 439 | //打开解码器 |
430 | - if ((ret = avcodec_open2(codec_ctx, codec, NULL) < 0)){ | |
440 | + if ((ret = avcodec_open2(codec_ctx, codec, nullptr) < 0)){ | |
431 | 441 | goto end_flag ; |
432 | 442 | } |
433 | 443 | |
... | ... | @@ -439,7 +449,7 @@ FFImgInfo* FFNvDecoder::snapshot(const string& uri){ |
439 | 449 | av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, buffer, AV_PIX_FMT_BGR24, codec_ctx->width, codec_ctx->height, 1); |
440 | 450 | |
441 | 451 | img_convert_ctx = sws_getContext(codec_ctx->width, codec_ctx->height,codec_ctx->pix_fmt, codec_ctx->width, codec_ctx->height, AV_PIX_FMT_BGR24, |
442 | - SWS_BICUBIC, NULL, NULL, NULL); | |
452 | + SWS_BICUBIC, nullptr, nullptr, nullptr); | |
443 | 453 | |
444 | 454 | pkt = av_packet_alloc(); |
445 | 455 | frame = av_frame_alloc(); |
... | ... | @@ -449,7 +459,8 @@ FFImgInfo* FFNvDecoder::snapshot(const string& uri){ |
449 | 459 | if (ret >= 0){ |
450 | 460 | ret = avcodec_receive_frame(codec_ctx, frame); |
451 | 461 | if ((ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) || ret < 0){ |
452 | - av_log(NULL, AV_LOG_ERROR, "Failed to receive frame: %d \n", ret); | |
462 | + av_log(nullptr, AV_LOG_ERROR, "Failed to receive frame: %d \n", ret); | |
463 | + av_packet_unref(pkt); | |
453 | 464 | continue; |
454 | 465 | } |
455 | 466 | |
... | ... | @@ -459,10 +470,11 @@ FFImgInfo* FFNvDecoder::snapshot(const string& uri){ |
459 | 470 | imgInfo->pData = buffer; |
460 | 471 | imgInfo->height = codec_ctx->height; |
461 | 472 | imgInfo->width = codec_ctx->width; |
462 | - | |
463 | 473 | break; |
464 | 474 | } |
465 | 475 | } |
476 | + | |
477 | + av_packet_unref(pkt); | |
466 | 478 | } |
467 | 479 | |
468 | 480 | end_flag: |
... | ... | @@ -499,4 +511,4 @@ void FFNvDecoder::releaseFFImgInfo(FFImgInfo* info){ |
499 | 511 | delete info; |
500 | 512 | info = nullptr; |
501 | 513 | } |
502 | -} | |
503 | 514 | \ No newline at end of file |
515 | +} | ... | ... |
src/Makefile
... | ... | @@ -2,9 +2,6 @@ |
2 | 2 | XX = g++ |
3 | 3 | NVCC = nvcc |
4 | 4 | |
5 | - | |
6 | -DEFS= -DPOST_USE_RABBITMQ | |
7 | - | |
8 | 5 | PROJECT_ROOT= /mnt/e/fiss/FFNvDecoder |
9 | 6 | |
10 | 7 | DEPEND_DIR = $(PROJECT_ROOT)/bin |
... | ... | @@ -24,10 +21,10 @@ LIBSPATH= -L $(DEPEND_DIR)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilte |
24 | 21 | -L $(CUDA_ROOT)/lib64 -lcudart -lcurand -lcublas -lnvjpeg \ |
25 | 22 | -L /usr/lib/wsl/lib -lcuda -lnvcuvid\ |
26 | 23 | |
27 | -CFLAGS= -g -fPIC -O0 $(DEFS) $(INCLUDE) -pthread -lrt -lz -std=c++11 -fvisibility=hidden -Wl,-Bsymbolic -ldl | |
24 | +CFLAGS= -g -fPIC -O0 $(INCLUDE) -pthread -lrt -lz -std=c++11 -fvisibility=hidden -Wl,-Bsymbolic -ldl | |
28 | 25 | # -DUNICODE -D_UNICODE |
29 | 26 | |
30 | -NFLAGS_LIB=-g -c $(DEFS) -shared -Xcompiler -fPIC -Xcompiler -fvisibility=hidden | |
27 | +NFLAGS_LIB=-g -c -shared -Xcompiler -fPIC -Xcompiler -fvisibility=hidden | |
31 | 28 | NFLAGS = $(NFLAGS_LIB) $(INCLUDE) -std=c++11 |
32 | 29 | |
33 | 30 | SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) | ... | ... |
src/common/inc/helper_cuda_drvapi.h
... | ... | @@ -218,7 +218,8 @@ inline int gpuGetMaxGflopsDeviceIdDRV() |
218 | 218 | // Find the best major SM Architecture GPU device |
219 | 219 | while (current_device < device_count) |
220 | 220 | { |
221 | - checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_device)); | |
221 | + checkCudaErrors(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, current_device)); | |
222 | + checkCudaErrors(cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, current_device)); | |
222 | 223 | |
223 | 224 | if (major > 0 && major < 9999) |
224 | 225 | { |
... | ... | @@ -239,7 +240,9 @@ inline int gpuGetMaxGflopsDeviceIdDRV() |
239 | 240 | checkCudaErrors(cuDeviceGetAttribute(&clockRate, |
240 | 241 | CU_DEVICE_ATTRIBUTE_CLOCK_RATE, |
241 | 242 | current_device)); |
242 | - checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_device)); | |
243 | + | |
244 | + checkCudaErrors(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, current_device)); | |
245 | + checkCudaErrors(cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, current_device)); | |
243 | 246 | |
244 | 247 | int computeMode; |
245 | 248 | getCudaAttribute<int>(&computeMode, CU_DEVICE_ATTRIBUTE_COMPUTE_MODE, current_device); |
... | ... | @@ -317,7 +320,9 @@ inline int gpuGetMaxGflopsGLDeviceIdDRV() |
317 | 320 | while (current_device < device_count) |
318 | 321 | { |
319 | 322 | checkCudaErrors(cuDeviceGetName(deviceName, 256, current_device)); |
320 | - checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_device)); | |
323 | + | |
324 | + checkCudaErrors(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, current_device)); | |
325 | + checkCudaErrors(cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, current_device)); | |
321 | 326 | |
322 | 327 | #if CUDA_VERSION >= 3020 |
323 | 328 | checkCudaErrors(cuDeviceGetAttribute(&bTCC, CU_DEVICE_ATTRIBUTE_TCC_DRIVER, current_device)); |
... | ... | @@ -369,7 +374,9 @@ inline int gpuGetMaxGflopsGLDeviceIdDRV() |
369 | 374 | checkCudaErrors(cuDeviceGetAttribute(&clockRate, |
370 | 375 | CU_DEVICE_ATTRIBUTE_CLOCK_RATE, |
371 | 376 | current_device)); |
372 | - checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_device)); | |
377 | + | |
378 | + checkCudaErrors(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, current_device)); | |
379 | + checkCudaErrors(cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, current_device)); | |
373 | 380 | |
374 | 381 | #if CUDA_VERSION >= 3020 |
375 | 382 | checkCudaErrors(cuDeviceGetAttribute(&bTCC, CU_DEVICE_ATTRIBUTE_TCC_DRIVER, current_device)); |
... | ... | @@ -500,7 +507,9 @@ inline bool checkCudaCapabilitiesDRV(int major_version, int minor_version, int d |
500 | 507 | |
501 | 508 | checkCudaErrors(cuDeviceGet(&cuDevice, devID)); |
502 | 509 | checkCudaErrors(cuDeviceGetName(name, 100, cuDevice)); |
503 | - checkCudaErrors(cuDeviceComputeCapability(&major, &minor, devID)); | |
510 | + | |
511 | + checkCudaErrors(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, devID)); | |
512 | + checkCudaErrors(cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, devID)); | |
504 | 513 | |
505 | 514 | if ((major > major_version) || |
506 | 515 | (major == major_version && minor >= minor_version)) | ... | ... |
src/main.cpp
... | ... | @@ -164,7 +164,8 @@ void postDecoded0(const void * userPtr, AVFrame * gpuFrame){ |
164 | 164 | // string test_uri = "/home/cmhu/data/output_800x480.mp4"; |
165 | 165 | // string test_uri = "/home/cmhu/data/output_1920x1080.mp4"; |
166 | 166 | // string test_uri = "rtsp://176.10.0.2:8554/stream"; |
167 | -string test_uri = "/mnt/f/fiss/test_data/h265.mp4"; | |
167 | +// string test_uri = "/mnt/f/fiss/test_data/h265.mp4"; | |
168 | +string test_uri = "rtsp://176.10.0.4:8554/stream"; | |
168 | 169 | |
169 | 170 | void createDecode(int index){ |
170 | 171 | FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance(); |
... | ... | @@ -207,7 +208,10 @@ int CheckCUDAProperty( int devId ) |
207 | 208 | int major = 0, minor = 0; |
208 | 209 | CUresult rlt = CUDA_SUCCESS; |
209 | 210 | |
210 | - rlt = cuDeviceComputeCapability( &major, &minor, dev ); | |
211 | + rlt = cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, dev); | |
212 | + checkCudaErrors( rlt ); | |
213 | + | |
214 | + rlt = cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, dev); | |
211 | 215 | checkCudaErrors( rlt ); |
212 | 216 | |
213 | 217 | rlt = cuDeviceGetName( devName, sizeof( devName ), dev ); |
... | ... | @@ -260,6 +264,10 @@ int main(){ |
260 | 264 | // pDecManager->setDecKeyframe(config.name, true); |
261 | 265 | pDecManager->startDecodeByName(config.name); |
262 | 266 | |
267 | + int w,h; | |
268 | + pDecManager->getResolution(config.name, w,h); | |
269 | + printf( "%s : %dx%d\n", config.name.c_str() , w,h ); | |
270 | + | |
263 | 271 | pthread_t m_decode_thread; |
264 | 272 | pthread_create(&m_decode_thread,0, |
265 | 273 | [](void* arg) | ... | ... |