Skip to content

Commit

Permalink
デバイスを掴まないようにする NoVideoDevice, NoAudioDevice を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Aug 30, 2023
1 parent 3637e4e commit 4ea9ecf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

## develop

- [ADD] ハードウェアエンコーダを利用するかどうかを設定する `UseHardwareEncoder` オプションを追加
- [ADD] デバイスを掴まないようにする `NoVideoDevice`, `NoAudioDevice` を追加
- @melpon
- [ADD] ハードウェアエンコーダを利用するかどうかを設定する `UseHardwareEncoder` を追加
- @melpon
- [UPDATE] SoraClientContext を利用してコードを短くする
- @melpon
Expand Down
4 changes: 4 additions & 0 deletions Sora/Sora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class Config
public SpotlightFocusRidType? SpotlightUnfocusRid;
public bool? Simulcast;
public SimulcastRidType? SimulcastRid = null;
public bool NoVideoDevice = false;
public bool NoAudioDevice = false;
public CapturerType CapturerType = Sora.CapturerType.DeviceCamera;
public UnityEngine.Camera UnityCamera = null;
public int UnityCameraRenderTargetDepthBuffer = 16;
Expand Down Expand Up @@ -282,6 +284,8 @@ public void Connect(Config config)
cc.simulcast = config.Simulcast.GetValueOrDefault();
cc.simulcast_rid = config.SimulcastRid == null ? "" : config.SimulcastRid.Value.ToString().ToLower();
cc.insecure = config.Insecure;
cc.no_video_device = config.NoVideoDevice;
cc.no_audio_device = config.NoAudioDevice;
cc.capturer_type = (int)config.CapturerType;
cc.unity_camera_texture = unityCameraTexture.ToInt64();
cc.video = config.Video;
Expand Down
2 changes: 2 additions & 0 deletions proto/sora_conf_internal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ message ConnectConfig {
bool enable_simulcast = 14;
bool simulcast = 15;
string simulcast_rid = 16;
bool no_video_device = 160;
bool no_audio_device = 161;
int32 capturer_type = 17;
int64 unity_camera_texture = 18;
string video_capturer_device = 19;
Expand Down
26 changes: 17 additions & 9 deletions src/sora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
#endif

unity_adm_ = CreateADM(
media_dependencies.task_queue_factory, false, cc.unity_audio_input,
cc.unity_audio_output, on_handle_audio_, cc.audio_recording_device,
cc.audio_playout_device, dependencies.worker_thread, worker_env,
worker_context);
media_dependencies.task_queue_factory, cc.no_audio_device,
cc.unity_audio_input, cc.unity_audio_output, on_handle_audio_,
cc.audio_recording_device, cc.audio_playout_device,
dependencies.worker_thread, worker_env, worker_context);
media_dependencies.adm = unity_adm_;

#if defined(SORA_UNITY_SDK_ANDROID)
Expand Down Expand Up @@ -279,11 +279,11 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
}

auto capturer = CreateVideoCapturer(
cc.capturer_type, (void*)cc.unity_camera_texture,
cc.capturer_type, (void*)cc.unity_camera_texture, cc.no_video_device,
cc.video_capturer_device, cc.video_width, cc.video_height, cc.video_fps,
on_frame, sora_context_->signaling_thread(), env, android_context,
unity_context_);
if (!capturer) {
if (!cc.no_video_device && !capturer) {
on_disconnect((int)sora_conf::ErrorCode::INTERNAL_ERROR,
"Capturer Init Failed");
return;
Expand All @@ -297,9 +297,12 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
audio_track_id, sora_context_->peer_connection_factory()
->CreateAudioSource(cricket::AudioOptions())
.get());
std::string video_track_id = rtc::CreateRandomString(16);
video_track_ = sora_context_->peer_connection_factory()->CreateVideoTrack(
video_track_id, capturer.get());

if (capturer) {
std::string video_track_id = rtc::CreateRandomString(16);
video_track_ = sora_context_->peer_connection_factory()->CreateVideoTrack(
video_track_id, capturer.get());
}
}

{
Expand Down Expand Up @@ -627,6 +630,7 @@ bool Sora::InitADM(rtc::scoped_refptr<webrtc::AudioDeviceModule> adm,
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> Sora::CreateVideoCapturer(
int capturer_type,
void* unity_camera_texture,
bool no_video_device,
std::string video_capturer_device,
int video_width,
int video_height,
Expand All @@ -637,6 +641,10 @@ rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> Sora::CreateVideoCapturer(
void* android_context,
UnityContext* unity_context) {
if (capturer_type == 0) {
if (no_video_device) {
return nullptr;
}

// 実カメラ(デバイス)を使う
sora::CameraDeviceCapturerConfig config;
config.width = video_width;
Expand Down
1 change: 1 addition & 0 deletions src/sora.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Sora : public std::enable_shared_from_this<Sora>,
CreateVideoCapturer(
int capturer_type,
void* unity_camera_texture,
bool no_video_device,
std::string video_capturer_device,
int video_width,
int video_height,
Expand Down

0 comments on commit 4ea9ecf

Please sign in to comment.