Skip to content

Commit

Permalink
Windows で動いてなかったのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Jan 30, 2025
1 parent 8f8972c commit 6a49dc3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SORA_CPP_SDK_VERSION=2025.2.0-canary.0
WEBRTC_BUILD_VERSION=m132.6834.5.4
WEBRTC_BUILD_VERSION=m132.6834.5.5
BOOST_VERSION=1.87.0
CMAKE_VERSION=3.31.4
CUDA_VERSION=11.8.0-1
Expand Down
2 changes: 1 addition & 1 deletion examples/VERSION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SORA_CPP_SDK_VERSION=2025.2.0-canary.0
WEBRTC_BUILD_VERSION=m132.6834.5.4
WEBRTC_BUILD_VERSION=m132.6834.5.5
BOOST_VERSION=1.87.0
CMAKE_VERSION=3.31.4
SDL2_VERSION=2.30.11
Expand Down
6 changes: 3 additions & 3 deletions include/sora/sora_video_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ struct VideoCodecCapability {
std::optional<std::string> nvcodec_gpu_device_name;
};
struct Codec {
Codec(webrtc::VideoCodecType type, bool decoder, bool encoder)
: type(type), decoder(decoder), encoder(encoder) {}
Codec(webrtc::VideoCodecType type, bool encoder, bool decoder)
: type(type), encoder(encoder), decoder(decoder) {}
webrtc::VideoCodecType type;
bool decoder;
bool encoder;
bool decoder;
Parameters parameters;
};
struct Engine {
Expand Down
34 changes: 15 additions & 19 deletions src/hwenc_nvcodec/nvcodec_video_codec.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#include "sora/hwenc_nvcodec/nvcodec_video_codec.h"

#include <iostream>

#include "sora/hwenc_nvcodec/nvcodec_video_decoder.h"
#include "sora/hwenc_nvcodec/nvcodec_video_encoder.h"

#include "../cuda_context_cuda.h"
#include "nvcodec_video_codec_cuda.h"

#if defined(_WIN32)
#include <d3d11.h>
#include <wrl.h>
#endif

namespace sora {

namespace {
Expand All @@ -14,22 +21,15 @@ sora::VideoCodecCapability::Parameters GetParameters(
std::shared_ptr<CudaContext> context) {
sora::VideoCodecCapability::Parameters p;
#if defined(_WIN32)
ComPtr<IDXGIFactory1> idxgi_factory;
Microsoft::WRL::ComPtr<IDXGIFactory1> idxgi_factory;
if (FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1),
(void**)idxgi_factory.GetAddressOf()))) {
return p;
}
ComPtr<IDXGIAdapter> idxgi_adapter;
if (!FAILED(idxgi_factory->EnumAdapters(0, idxgi_adapter.GetAddressOf()))) {
Microsoft::WRL::ComPtr<IDXGIAdapter> idxgi_adapter;
if (FAILED(idxgi_factory->EnumAdapters(0, idxgi_adapter.GetAddressOf()))) {
return p;
}
if (!FAILED(D3D11CreateDevice(idxgi_adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN,
NULL, 0, NULL, 0, D3D11_SDK_VERSION,
id3d11_device_.GetAddressOf(), NULL,
id3d11_context_.GetAddressOf()))) {
return p;
}

// 以下デバイス名を取得するだけの処理
DXGI_ADAPTER_DESC adapter_desc;
idxgi_adapter->GetDesc(&adapter_desc);
Expand All @@ -39,6 +39,10 @@ sora::VideoCodecCapability::Parameters GetParameters(
p.nvcodec_gpu_device_name = std::string(szDesc);
#endif
#if defined(__linux__)
if (context == nullptr) {
return p;
}

char name[80] = {};
GetNvCodecGpuDeviceName(context, name, sizeof(name));
if (name[0] != '\0') {
Expand All @@ -55,15 +59,7 @@ VideoCodecCapability::Engine GetNvCodecVideoCodecCapability(
std::shared_ptr<CudaContext> context) {
VideoCodecCapability::Engine engine(
VideoCodecImplementation::kNvidiaVideoCodecSdk);
if (context == nullptr) {
return engine;
}

// engine.parameters.version =
// std::to_string(ver.Major) + "." + std::to_string(ver.Minor);
// engine.parameters.vpl_impl =
// impl == MFX_IMPL_SOFTWARE ? "SOFTWARE" : "HARDWARE";
// engine.parameters.vpl_impl_value = (int)impl;
engine.parameters = GetParameters(context);

auto add = [&engine, &context](CudaVideoCodec type,
webrtc::VideoCodecType webrtc_type) {
Expand Down
27 changes: 23 additions & 4 deletions src/sora_video_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ void tag_invoke(const boost::json::value_from_tag&,
if (v.openh264_path) {
jo["openh264_path"] = *v.openh264_path;
}
if (v.vpl_impl) {
jo["vpl_impl"] = *v.vpl_impl;
}
if (v.vpl_impl_value) {
jo["vpl_impl_value"] = *v.vpl_impl_value;
}
if (v.nvcodec_gpu_device_name) {
jo["nvcodec_gpu_device_name"] = *v.nvcodec_gpu_device_name;
}
}

VideoCodecCapability::Parameters tag_invoke(
Expand All @@ -101,6 +110,16 @@ VideoCodecCapability::Parameters tag_invoke(
if (jv.at("openh264_path").is_string()) {
r.openh264_path = jv.at("openh264_path").as_string().c_str();
}
if (jv.at("vpl_impl").is_string()) {
r.vpl_impl = jv.at("vpl_impl").as_string().c_str();
}
if (jv.at("vpl_impl_value").is_int64()) {
r.vpl_impl_value = (int)jv.at("vpl_impl_value").as_int64();
}
if (jv.at("nvcodec_gpu_device_name").is_string()) {
r.nvcodec_gpu_device_name =
jv.at("nvcodec_gpu_device_name").as_string().c_str();
}
}
return r;
}
Expand All @@ -110,8 +129,8 @@ void tag_invoke(const boost::json::value_from_tag&,
const VideoCodecCapability::Codec& v) {
auto& jo = jv.emplace_object();
jo["type"] = boost::json::value_from(v.type);
jo["decoder"] = v.decoder;
jo["encoder"] = v.encoder;
jo["decoder"] = v.decoder;
jo["parameters"] = boost::json::value_from(v.parameters);
}
VideoCodecCapability::Codec tag_invoke(
Expand All @@ -124,12 +143,12 @@ VideoCodecCapability::Codec tag_invoke(
if (jv.at("type").is_string()) {
r.type = boost::json::value_to<webrtc::VideoCodecType>(jv.at("type"));
}
if (jv.at("decoder").is_bool()) {
r.decoder = jv.at("decoder").as_bool();
}
if (jv.at("encoder").is_bool()) {
r.encoder = jv.at("encoder").as_bool();
}
if (jv.at("decoder").is_bool()) {
r.decoder = jv.at("decoder").as_bool();
}
if (jv.at("params").is_object()) {
r.parameters = boost::json::value_to<VideoCodecCapability::Parameters>(
jv.at("parameters"));
Expand Down

0 comments on commit 6a49dc3

Please sign in to comment.