Skip to content

Commit

Permalink
Merge pull request #16 from HolyWu/patch/cuda_threads
Browse files Browse the repository at this point in the history
Fix potential cuda initialization error
  • Loading branch information
myrsloik authored Jul 2, 2023
2 parents 71d1d02 + c9913b6 commit 1b16375
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,15 @@ void LWVideoDecoder::OpenFile(const std::string &SourceFile, const std::string &
if (avcodec_parameters_to_context(CodecContext, FormatContext->streams[TrackNumber]->codecpar) < 0)
throw VideoException("Could not copy video codec parameters");

if (Threads < 1)
Threads = static_cast<int>(std::thread::hardware_concurrency());
if (Threads < 1) {
int HardwareConcurrency = std::thread::hardware_concurrency();
if (Type != AV_HWDEVICE_TYPE_CUDA)
Threads = HardwareConcurrency;
else if (CodecContext->codec_id == AV_CODEC_ID_H264)
Threads = 1;
else
Threads = std::min(HardwareConcurrency, 2);
}
CodecContext->thread_count = Threads;

if (!VariableFormat) {
Expand Down

0 comments on commit 1b16375

Please sign in to comment.