diff --git a/webrtc-sys/src/nvidia/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp b/webrtc-sys/src/nvidia/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp index 1ee70c428..d0ebde515 100644 --- a/webrtc-sys/src/nvidia/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp +++ b/webrtc-sys/src/nvidia/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp @@ -521,7 +521,7 @@ int NvDecoder::HandlePictureDecode(CUVIDPICPARAMS *pPicParams) { } m_nPicNumInDecodeOrder[pPicParams->CurrPicIdx] = m_nDecodePicCnt++; CUDA_DRVAPI_CALL(cuCtxPushCurrent(m_cuContext)); - NVDEC_API_CALL(cuvidDecodePicture(m_hDecoder, pPicParams)); + cuvidDecodePicture(m_hDecoder, pPicParams); if (m_bForce_zero_latency && ((!pPicParams->field_pic_flag) || (pPicParams->second_field))) { CUVIDPARSERDISPINFO dispInfo; diff --git a/webrtc-sys/src/nvidia/cuda_context.cpp b/webrtc-sys/src/nvidia/cuda_context.cpp index 82c21df2b..006e15519 100644 --- a/webrtc-sys/src/nvidia/cuda_context.cpp +++ b/webrtc-sys/src/nvidia/cuda_context.cpp @@ -61,16 +61,58 @@ static bool load_cuda_modules() { return true; } +static bool check_cuda_device() { + int device_count = 0; + int driver_version = 0; + + CUCTX_CUDA_CALL_ERROR(cuDriverGetVersion(&driver_version)); + if (kRequiredDriverVersion > driver_version) { + RTC_LOG(LS_ERROR) + << "CUDA driver version is not higher than the required version. " + << driver_version; + return false; + } + + CUresult result = cuInit(0); + if (result != CUDA_SUCCESS) { + RTC_LOG(LS_ERROR) << "Failed to initialize CUDA."; + return false; + } + + result = cuDeviceGetCount(&device_count); + if (result != CUDA_SUCCESS) { + RTC_LOG(LS_ERROR) << "Failed to get CUDA device count."; + return false; + } + + if (device_count == 0) { + RTC_LOG(LS_ERROR) << "No CUDA devices found."; + return false; + } + + return true; +} + +CudaContext* CudaContext::GetInstance() { + static CudaContext instance; + return &instance; +} + +bool CudaContext::IsAvailable() { + return load_cuda_modules() && check_cuda_device(); +} + bool CudaContext::Initialize() { // Initialize CUDA context bool success = load_cuda_modules(); if (!success) { - std::cout << "Failed to load CUDA modules. maybe the NVIDIA driver is not installed?" << std::endl; + RTC_LOG(LS_ERROR) << "Failed to load CUDA modules. maybe the NVIDIA driver " + "is not installed?"; return false; } - int numDevices = 0; + int num_devices = 0; CUdevice cu_device = 0; CUcontext context = nullptr; @@ -84,7 +126,23 @@ bool CudaContext::Initialize() { return false; } - CUCTX_CUDA_CALL_ERROR(cuInit(0)); + CUresult result = cuInit(0); + if (result != CUDA_SUCCESS) { + RTC_LOG(LS_ERROR) << "Failed to initialize CUDA."; + return false; + } + + result = cuDeviceGetCount(&num_devices); + if (result != CUDA_SUCCESS) { + RTC_LOG(LS_ERROR) << "Failed to get CUDA device count."; + return false; + } + + if (num_devices == 0) { + RTC_LOG(LS_ERROR) << "No CUDA devices found."; + return false; + } + CUCTX_CUDA_CALL_ERROR(cuDeviceGet(&cu_device, 0)); char device_name[80]; @@ -104,6 +162,22 @@ bool CudaContext::Initialize() { return true; } +CUcontext CudaContext::GetContext() const { + RTC_DCHECK(cu_context_ != nullptr); + // Ensure the context is current + CUcontext current; + if (cuCtxGetCurrent(¤t) != CUDA_SUCCESS) { + throw; + } + if (cu_context_ == current) { + return cu_context_; + } + if (cuCtxSetCurrent(cu_context_) != CUDA_SUCCESS) { + throw; + } + return cu_context_; +} + void CudaContext::Shutdown() { // Shutdown CUDA context if (cu_context_) { diff --git a/webrtc-sys/src/nvidia/cuda_context.h b/webrtc-sys/src/nvidia/cuda_context.h index 6011c10ee..2c6622d6f 100644 --- a/webrtc-sys/src/nvidia/cuda_context.h +++ b/webrtc-sys/src/nvidia/cuda_context.h @@ -8,12 +8,15 @@ namespace livekit { class CudaContext { public: CudaContext() = default; - ~CudaContext() { Shutdown(); } + ~CudaContext() = default; + static bool IsAvailable(); + + static CudaContext* GetInstance(); bool Initialize(); bool IsInitialized() const { return cu_context_ != nullptr; } - CUcontext GetContext() const { return cu_context_; } - CUdevice GetDevice() const { return cu_device_; } + CUcontext GetContext() const; + void Shutdown(); private: diff --git a/webrtc-sys/src/nvidia/h264_encoder_impl.cpp b/webrtc-sys/src/nvidia/h264_encoder_impl.cpp index cd8ed881c..dade3f0d3 100644 --- a/webrtc-sys/src/nvidia/h264_encoder_impl.cpp +++ b/webrtc-sys/src/nvidia/h264_encoder_impl.cpp @@ -248,7 +248,6 @@ int32_t NvidiaH264EncoderImpl::InitEncode( int32_t NvidiaH264EncoderImpl::RegisterEncodeCompleteCallback( EncodedImageCallback* callback) { - RTC_DCHECK(callback); encoded_image_callback_ = callback; return WEBRTC_VIDEO_CODEC_OK; } diff --git a/webrtc-sys/src/nvidia/nvidia_decoder_factory.cpp b/webrtc-sys/src/nvidia/nvidia_decoder_factory.cpp index 2d0b397c8..00fde1026 100644 --- a/webrtc-sys/src/nvidia/nvidia_decoder_factory.cpp +++ b/webrtc-sys/src/nvidia/nvidia_decoder_factory.cpp @@ -3,7 +3,6 @@ #include #include -#include #include "cuda_context.h" #include "h264_decoder_impl.h" @@ -65,7 +64,7 @@ std::vector SupportedNvDecoderCodecs(CUcontext context) { } NvidiaVideoDecoderFactory::NvidiaVideoDecoderFactory() - : cu_context_(std::make_unique()) { + : cu_context_(livekit::CudaContext::GetInstance()) { if (cu_context_->Initialize()) { supported_formats_ = SupportedNvDecoderCodecs(cu_context_->GetContext()); } else { @@ -78,12 +77,11 @@ NvidiaVideoDecoderFactory::NvidiaVideoDecoderFactory() NvidiaVideoDecoderFactory::~NvidiaVideoDecoderFactory() {} bool NvidiaVideoDecoderFactory::IsSupported() { - // Check if the CUDA context can be initialized. - auto cu_context = std::make_unique(); - if (!cu_context->Initialize()) { - std::cout << "Failed to initialize CUDA context." << std::endl; + if (!livekit::CudaContext::IsAvailable()) { + RTC_LOG(LS_WARNING) << "Cuda Context is not available."; return false; } + std::cout << "Nvidia Decoder is supported." << std::endl; return true; } @@ -96,7 +94,7 @@ std::unique_ptr NvidiaVideoDecoderFactory::Create( if (format.IsSameCodec(supported_format)) { // If the format is supported, create and return the encoder. if (!cu_context_) { - cu_context_ = std::make_unique(); + cu_context_ = livekit::CudaContext::GetInstance(); if (!cu_context_->Initialize()) { RTC_LOG(LS_ERROR) << "Failed to initialize CUDA context."; return nullptr; diff --git a/webrtc-sys/src/nvidia/nvidia_decoder_factory.h b/webrtc-sys/src/nvidia/nvidia_decoder_factory.h index 28094467b..979a432d4 100644 --- a/webrtc-sys/src/nvidia/nvidia_decoder_factory.h +++ b/webrtc-sys/src/nvidia/nvidia_decoder_factory.h @@ -26,7 +26,7 @@ class NvidiaVideoDecoderFactory : public VideoDecoderFactory { private: std::vector supported_formats_; - std::unique_ptr cu_context_; + livekit::CudaContext* cu_context_; }; } // namespace webrtc diff --git a/webrtc-sys/src/nvidia/nvidia_encoder_factory.cpp b/webrtc-sys/src/nvidia/nvidia_encoder_factory.cpp index 8d4e563f2..a30c96f9f 100644 --- a/webrtc-sys/src/nvidia/nvidia_encoder_factory.cpp +++ b/webrtc-sys/src/nvidia/nvidia_encoder_factory.cpp @@ -1,7 +1,6 @@ #include "nvidia_encoder_factory.h" #include -#include #include "cuda_context.h" #include "h264_encoder_impl.h" @@ -30,10 +29,8 @@ NvidiaVideoEncoderFactory::NvidiaVideoEncoderFactory() { NvidiaVideoEncoderFactory::~NvidiaVideoEncoderFactory() {} bool NvidiaVideoEncoderFactory::IsSupported() { - // Check if the CUDA context can be initialized. - auto cu_context = std::make_unique(); - if (!cu_context->Initialize()) { - std::cout << "Failed to initialize CUDA context." << std::endl; + if (!livekit::CudaContext::IsAvailable()) { + RTC_LOG(LS_WARNING) << "Cuda Context is not available."; return false; } @@ -49,7 +46,7 @@ std::unique_ptr NvidiaVideoEncoderFactory::Create( if (format.IsSameCodec(supported_format)) { // If the format is supported, create and return the encoder. if (!cu_context_) { - cu_context_ = std::make_unique(); + cu_context_ = livekit::CudaContext::GetInstance(); if (!cu_context_->Initialize()) { RTC_LOG(LS_ERROR) << "Failed to initialize CUDA context."; return nullptr; diff --git a/webrtc-sys/src/nvidia/nvidia_encoder_factory.h b/webrtc-sys/src/nvidia/nvidia_encoder_factory.h index b18c49ca0..785924d01 100644 --- a/webrtc-sys/src/nvidia/nvidia_encoder_factory.h +++ b/webrtc-sys/src/nvidia/nvidia_encoder_factory.h @@ -34,7 +34,7 @@ class NvidiaVideoEncoderFactory : public VideoEncoderFactory { private: std::vector supported_formats_; - std::unique_ptr cu_context_; + livekit::CudaContext* cu_context_ = nullptr; }; } // namespace webrtc diff --git a/webrtc-sys/src/vaapi/h264_encoder_impl.cpp b/webrtc-sys/src/vaapi/h264_encoder_impl.cpp index b2232bdcd..dfa75d335 100644 --- a/webrtc-sys/src/vaapi/h264_encoder_impl.cpp +++ b/webrtc-sys/src/vaapi/h264_encoder_impl.cpp @@ -163,7 +163,6 @@ int32_t VAAPIH264EncoderWrapper::InitEncode( int32_t VAAPIH264EncoderWrapper::RegisterEncodeCompleteCallback( EncodedImageCallback* callback) { - RTC_DCHECK(callback); encoded_image_callback_ = callback; return WEBRTC_VIDEO_CODEC_OK; } diff --git a/webrtc-sys/src/vaapi/vaapi_display_drm.cpp b/webrtc-sys/src/vaapi/vaapi_display_drm.cpp index ca382a769..e6b02911e 100644 --- a/webrtc-sys/src/vaapi/vaapi_display_drm.cpp +++ b/webrtc-sys/src/vaapi/vaapi_display_drm.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #ifdef IN_LIBVA #include "va/drm/va_drm.h" @@ -111,7 +110,8 @@ namespace livekit { bool VaapiDisplayDrm::Open() { va_display_ = va_open_display_drm(&drm_fd_); if (!va_display_) { - std::cout << "Failed to open VA display. Maybe the AMD video driver or libva-dev/libdrm-dev is not installed?" << std::endl; + RTC_LOG(LS_ERROR) << "Failed to open VA drm display. Maybe the AMD video " + "driver or libva-dev/libdrm-dev is not installed?"; return false; } return true; diff --git a/webrtc-sys/src/vaapi/vaapi_encoder_factory.cpp b/webrtc-sys/src/vaapi/vaapi_encoder_factory.cpp index 83c29a645..3a5f41d9b 100644 --- a/webrtc-sys/src/vaapi/vaapi_encoder_factory.cpp +++ b/webrtc-sys/src/vaapi/vaapi_encoder_factory.cpp @@ -1,17 +1,17 @@ #include "vaapi_encoder_factory.h" #include +#include #include "h264_encoder_impl.h" - -#include +#include "rtc_base/logging.h" #if defined(WIN32) #include "vaapi_display_win32.h" using VaapiDisplay = livekit::VaapiDisplayWin32; #elif defined(__linux__) #include "vaapi_display_drm.h" -using VaapiDisplay = livekit::VaapiDisplayDrm ; +using VaapiDisplay = livekit::VaapiDisplayDrm; #endif namespace webrtc { @@ -41,7 +41,7 @@ bool VAAPIVideoEncoderFactory::IsSupported() { // This could involve checking if the VAAPI display can be opened. VaapiDisplay vaapi_display; if (!vaapi_display.Open()) { - std::cerr << "Failed to open VAAPI display." << std::endl; + RTC_LOG(LS_WARNING) << "Failed to open VAAPI display."; return false; } diff --git a/webrtc-sys/test/CMakeLists.txt b/webrtc-sys/test/CMakeLists.txt index 07af2c706..ed47a648e 100644 --- a/webrtc-sys/test/CMakeLists.txt +++ b/webrtc-sys/test/CMakeLists.txt @@ -41,7 +41,7 @@ add_definitions(-DWEBRTC_LIBRARY_IMPL) add_definitions(-DWEBRTC_ENABLE_AVX2) include_directories( - "${CMAKE_CURRENT_SOURCE_DIR}/../libwebrtc/linux-x64-release/include" + "${CMAKE_CURRENT_SOURCE_DIR}/../libwebrtc/linux-x64-debug/include" "${CMAKE_CURRENT_SOURCE_DIR}/../libwebrtc/linux-x64-release/include/third_party/abseil-cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../libwebrtc/linux-x64-release/include/third_party/libyuv/include" "${CMAKE_CURRENT_SOURCE_DIR}/../src/nvidia/NvCodec/include" @@ -63,19 +63,19 @@ add_executable(${BINARY_NAME} "fileutils.cc" "cpu/cpu_linux.cc" - #"benchmark_nvidia.cc" - #"../src/nvidia/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp" - #"../src/nvidia/NvCodec/NvCodec/NvEncoder/NvEncoder.cpp" - #"../src/nvidia/NvCodec/NvCodec/NvEncoder/NvEncoderCuda.cpp" - #"../src/nvidia/h264_encoder_impl.cpp" - #"../src/nvidia/h264_decoder_impl.cpp" - #"../src/nvidia/nvidia_decoder_factory.cpp" - #"../src/nvidia/nvidia_encoder_factory.cpp" - #"../src/nvidia/cuda_context.cpp" - #"../src/nvidia/implib/libcuda.so.init.c" - #"../src/nvidia/implib/libcuda.so.tramp.S" - #"../src/nvidia/implib/libnvcuvid.so.init.c" - #"../src/nvidia/implib/libnvcuvid.so.tramp.S" + "benchmark_nvidia.cc" + "../src/nvidia/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp" + "../src/nvidia/NvCodec/NvCodec/NvEncoder/NvEncoder.cpp" + "../src/nvidia/NvCodec/NvCodec/NvEncoder/NvEncoderCuda.cpp" + "../src/nvidia/h264_encoder_impl.cpp" + "../src/nvidia/h264_decoder_impl.cpp" + "../src/nvidia/nvidia_decoder_factory.cpp" + "../src/nvidia/nvidia_encoder_factory.cpp" + "../src/nvidia/cuda_context.cpp" + "../src/nvidia/implib/libcuda.so.init.c" + "../src/nvidia/implib/libcuda.so.tramp.S" + "../src/nvidia/implib/libnvcuvid.so.init.c" + "../src/nvidia/implib/libnvcuvid.so.tramp.S" "benchmark_vaapi.cc" "../src/vaapi/vaapi_display_drm.cpp" @@ -89,4 +89,4 @@ add_executable(${BINARY_NAME} ) target_link_libraries(${BINARY_NAME} ${CMAKE_THREAD_LIBS_INIT}) -target_link_libraries(${BINARY_NAME} dl) \ No newline at end of file +target_link_libraries(${BINARY_NAME} dl) diff --git a/webrtc-sys/test/benchmark.cc b/webrtc-sys/test/benchmark.cc index 5ae4df619..b66e2ec96 100644 --- a/webrtc-sys/test/benchmark.cc +++ b/webrtc-sys/test/benchmark.cc @@ -87,13 +87,15 @@ VideoEncodeCompleteCallback::OnEncodedImage( Benchmark::Benchmark() : _resultsFileName(webrtc::test::OutputPath() + "benchmark.txt"), - _codecName("Default") {} + _codecName("Default"), + _env(webrtc::CreateEnvironment()) {} Benchmark::Benchmark(std::string name, std::string description) : _name(name), _description(description), _resultsFileName(webrtc::test::OutputPath() + "benchmark.txt"), - _codecName("Default") {} + _codecName("Default"), + _env(webrtc::CreateEnvironment()) {} Benchmark::Benchmark(std::string name, std::string description, @@ -103,7 +105,8 @@ Benchmark::Benchmark(std::string name, _description(description), _resultsFileName(resultsFileName), _codecName(codecName), - _cpu(webrtc::CpuWrapper::CreateCpu()) {} + _cpu(webrtc::CpuWrapper::CreateCpu()), + _env(webrtc::CreateEnvironment()) {} void Benchmark::Perform() { std::vector sources; @@ -113,12 +116,12 @@ void Benchmark::Perform() { sources.push_back(new const VideoSource( webrtc::test::ProjectRootPath() + "resources/FourPeople_1280x720_30.yuv", kWHD)); - sources.push_back( - new const VideoSource(webrtc::test::ProjectRootPath() + - "resources/Big_Buck_Bunny_1920x1080_30.yuv", - kWFullHD)); + //sources.push_back( + // new const VideoSource(webrtc::test::ProjectRootPath() + + // "resources/Big_Buck_Bunny_1920x1080_30.yuv", + // kWFullHD)); - const VideoSize size[] = {kWHD, kWFullHD}; + const VideoSize size[] = {kWHD}; const int frameRate[] = {30}; // Specifies the framerates for which to perform a speed test. const bool speedTestMask[] = {true}; @@ -231,12 +234,12 @@ void Benchmark::Perform() { } void Benchmark::PerformNormalTest() { - _encoder = GetNewEncoder(); + _encoder = GetNewEncoder(_env); _lengthSourceFrame = _target->GetFrameLength(); CodecSettings(_target->GetWidth(), _target->GetHeight(), _target->GetFrameRate(), _bitRate); Setup(); - std::unique_ptr waitEvent = std::make_unique(); + std::unique_ptr waitEvent = std::make_unique(); //_inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _encoder->InitEncode(&_inst, 4, 1440); CodecSpecific_InitBitrate(); @@ -301,7 +304,7 @@ void Benchmark::Teardown() { } void Benchmark::CodecSpecific_InitBitrate() { - webrtc::SimulcastRateAllocator init_allocator(_inst); + webrtc::SimulcastRateAllocator init_allocator(_env,_inst); if (_bitRate == 0) { VideoBitrateAllocation allocation = @@ -328,7 +331,7 @@ bool Benchmark::Encode() { return true; } // TODO: build video frame from buffer ptr. - rtc::scoped_refptr buffer( + webrtc::scoped_refptr buffer( webrtc::I420Buffer::Create(_inst.width, _inst.height)); buffer->InitializeData(); @@ -346,7 +349,7 @@ bool Benchmark::Encode() { return true; } _encodeCompleteTime = 0; - _encodeTimes[inputVideoBuffer.timestamp()] = tGetTime(); + _encodeTimes[inputVideoBuffer.rtp_timestamp()] = tGetTime(); std::vector frame_types(1, VideoFrameType::kVideoFrameDelta); // check SLI queue @@ -387,9 +390,9 @@ bool Benchmark::Encode() { if (_encodeCompleteTime > 0) { _totalEncodeTime += - _encodeCompleteTime - _encodeTimes[inputVideoBuffer.timestamp()]; + _encodeCompleteTime - _encodeTimes[inputVideoBuffer.rtp_timestamp()]; } else { - _totalEncodeTime += tGetTime() - _encodeTimes[inputVideoBuffer.timestamp()]; + _totalEncodeTime += tGetTime() - _encodeTimes[inputVideoBuffer.rtp_timestamp()]; } assert(ret >= 0); return false; diff --git a/webrtc-sys/test/benchmark.h b/webrtc-sys/test/benchmark.h index a86f6b737..2ae2900b9 100644 --- a/webrtc-sys/test/benchmark.h +++ b/webrtc-sys/test/benchmark.h @@ -18,6 +18,7 @@ #include #include "cpu/cpu_linux.h" +#include "api/environment/environment_factory.h" #include "modules/include/module_common_types.h" #include "modules/video_coding/include/video_codec_interface.h" #include "rtc_base/synchronization/mutex.h" @@ -98,7 +99,7 @@ class Benchmark { std::string description, std::string resultsFileName, std::string codecName); - virtual webrtc::VideoEncoder* GetNewEncoder() = 0; + virtual webrtc::VideoEncoder* GetNewEncoder(webrtc::Environment &env) = 0; virtual void PerformNormalTest(); virtual void CodecSpecific_InitBitrate(); static const char* GetMagicStr() { return "#!benchmark1.0"; } @@ -167,7 +168,7 @@ class Benchmark { std::string _inname; std::string _outname; webrtc::VideoEncoder* _encoder; - webrtc::VideoDecoder* _decoder; + //webrtc::VideoDecoder* _decoder; uint32_t _bitRate; bool _appendNext = false; int _framecnt; @@ -207,6 +208,7 @@ class Benchmark { uint64_t _lastDecPictureId = 0; std::list _signalPLI; webrtc::CpuWrapper* _cpu; + webrtc::Environment _env; }; #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_FRAWEWORK_BENCHMARK_H_ diff --git a/webrtc-sys/test/benchmark_nvidia.cc b/webrtc-sys/test/benchmark_nvidia.cc index c5e5dbef2..168988bfb 100644 --- a/webrtc-sys/test/benchmark_nvidia.cc +++ b/webrtc-sys/test/benchmark_nvidia.cc @@ -24,7 +24,7 @@ NvidiaBenchmark::NvidiaBenchmark(std::string name, : Benchmark(name, description, resultsFileName, "nvidia_bitstream_output.h264") {} -VideoEncoder* NvidiaBenchmark::GetNewEncoder() { +VideoEncoder* NvidiaBenchmark::GetNewEncoder(webrtc::Environment &env) { if (!NvidiaVideoEncoderFactory::IsSupported()) { fprintf(stderr, "NVIDIA is not supported on this system.\n"); return nullptr; @@ -34,13 +34,13 @@ VideoEncoder* NvidiaBenchmark::GetNewEncoder() { _factory = std::make_unique(); } std::map baselineParameters = { - {"profile-level-id", "4d0032"}, + {"profile-level-id", "42e01f"}, {"level-asymmetry-allowed", "1"}, {"packetization-mode", "1"}, }; auto format = SdpVideoFormat("H264", baselineParameters); - auto enc = _factory->Create(webrtc::CreateEnvironment(), format); + auto enc = _factory->Create(env, format); if (!enc) { fprintf(stderr, "Failed to create H264 encoder.\n"); return nullptr; diff --git a/webrtc-sys/test/benchmark_nvidia.h b/webrtc-sys/test/benchmark_nvidia.h index 167fb383f..3c9271743 100644 --- a/webrtc-sys/test/benchmark_nvidia.h +++ b/webrtc-sys/test/benchmark_nvidia.h @@ -16,7 +16,7 @@ class NvidiaBenchmark : public Benchmark { } protected: - webrtc::VideoEncoder* GetNewEncoder() override; + webrtc::VideoEncoder* GetNewEncoder(webrtc::Environment &env) override; private: std::unique_ptr _encoder; diff --git a/webrtc-sys/test/benchmark_openh264.cc b/webrtc-sys/test/benchmark_openh264.cc index 59a2adbcd..383f969f6 100644 --- a/webrtc-sys/test/benchmark_openh264.cc +++ b/webrtc-sys/test/benchmark_openh264.cc @@ -23,8 +23,8 @@ OpenH264Benchmark::OpenH264Benchmark(std::string name, std::string resultsFileName) : Benchmark(name, description, resultsFileName, "openh264_bitstream_output.h264") {} -VideoEncoder* OpenH264Benchmark::GetNewEncoder() { - auto enc = CreateH264Encoder(webrtc::CreateEnvironment()); +VideoEncoder* OpenH264Benchmark::GetNewEncoder(webrtc::Environment &env) { + auto enc = CreateH264Encoder(env); if (!enc) { fprintf(stderr, "Failed to create H264 encoder.\n"); return nullptr; diff --git a/webrtc-sys/test/benchmark_openh264.h b/webrtc-sys/test/benchmark_openh264.h index 36caed5dd..f1eb1abb9 100644 --- a/webrtc-sys/test/benchmark_openh264.h +++ b/webrtc-sys/test/benchmark_openh264.h @@ -15,7 +15,7 @@ class OpenH264Benchmark : public Benchmark { } protected: - webrtc::VideoEncoder* GetNewEncoder() override; + webrtc::VideoEncoder* GetNewEncoder(webrtc::Environment &env) override; private: std::unique_ptr _encoder; diff --git a/webrtc-sys/test/benchmark_vaapi.cc b/webrtc-sys/test/benchmark_vaapi.cc index 030e734cb..7c3f0971b 100644 --- a/webrtc-sys/test/benchmark_vaapi.cc +++ b/webrtc-sys/test/benchmark_vaapi.cc @@ -23,7 +23,7 @@ VaapiBenchmark::VaapiBenchmark(std::string name, std::string resultsFileName) : Benchmark(name, description, resultsFileName, "vaapi_bitstream_output.h264") {} -VideoEncoder* VaapiBenchmark::GetNewEncoder() { +VideoEncoder* VaapiBenchmark::GetNewEncoder(webrtc::Environment &env) { if (!VAAPIVideoEncoderFactory::IsSupported()) { fprintf(stderr, "VAAPI is not supported on this system.\n"); return nullptr; @@ -38,7 +38,7 @@ VideoEncoder* VaapiBenchmark::GetNewEncoder() { }; auto format = SdpVideoFormat("H264", baselineParameters); - auto enc = _factory->Create(webrtc::CreateEnvironment(), format); + auto enc = _factory->Create(env, format); if (!enc) { fprintf(stderr, "Failed to create H264 encoder.\n"); return nullptr; diff --git a/webrtc-sys/test/benchmark_vaapi.h b/webrtc-sys/test/benchmark_vaapi.h index e72a44964..95ec057b9 100644 --- a/webrtc-sys/test/benchmark_vaapi.h +++ b/webrtc-sys/test/benchmark_vaapi.h @@ -16,7 +16,7 @@ class VaapiBenchmark : public Benchmark { } protected: - webrtc::VideoEncoder* GetNewEncoder() override; + webrtc::VideoEncoder* GetNewEncoder(webrtc::Environment &env) override; private: std::unique_ptr _encoder; diff --git a/webrtc-sys/test/test_main.cc b/webrtc-sys/test/test_main.cc index 1623e6903..6b8209f6d 100644 --- a/webrtc-sys/test/test_main.cc +++ b/webrtc-sys/test/test_main.cc @@ -1,4 +1,4 @@ -//#include "benchmark_nvidia.h" +#include "benchmark_nvidia.h" #include "benchmark_openh264.h" #include "benchmark_vaapi.h" #include "stdio.h" @@ -6,8 +6,8 @@ int main(int argc, char** argv) { std::vector benchmarks; - //benchmarks.push_back(new NvidiaBenchmark()); - benchmarks.push_back(new VaapiBenchmark()); + benchmarks.push_back(new NvidiaBenchmark()); + //benchmarks.push_back(new VaapiBenchmark()); benchmarks.push_back(new OpenH264Benchmark()); for (auto benchmark : benchmarks) {