Skip to content

Commit

Permalink
libwebrtc M121 に対応する
Browse files Browse the repository at this point in the history
  • Loading branch information
enm10k committed Jan 25, 2024
1 parent 706d793 commit 43ea5d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
9 changes: 0 additions & 9 deletions include/sora/sora_client_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ struct SoraClientContextConfig {
// false にするとソフトウェアエンコーダ/デコーダのみになる(H.264 は利用できない)
bool use_hardware_encoder = true;

// MediaEngineDependencies をカスタマイズするためのコールバック関数
// デフォルトの値が設定された上で、cricket::CreateMediaEngine を生成する直前に呼ばれる
std::function<void(const webrtc::PeerConnectionFactoryDependencies&,
cricket::MediaEngineDependencies&)>
configure_media_dependencies;

// PeerConnectionFactoryDependencies をカスタマイズするためのコールバック関数
// デフォルトの値が設定された上で、PeerConnectionFactory を生成する直前に呼ばれる
std::function<void(webrtc::PeerConnectionFactoryDependencies&)>
Expand All @@ -43,9 +37,6 @@ struct SoraClientContextConfig {
// 使い方:
// sora::SoraClientContextConfig context_config;
// // 必要なら context_config をカスタマイズする
// context_config.configure_media_dependencies =
// [](const webrtc::PeerConnectionFactoryDependencies& dep,
// cricket::MediaEngineDependencies& mdep) { ... };
// context_config.configure_dependencies = [](webrtc::PeerConnectionFactoryDependencies& dep) { ... };
// // Android に対応する場合は get_android_application_context を設定する
// context_config.get_android_application_context = [](void* env) { ... };
Expand Down
36 changes: 15 additions & 21 deletions src/sora_client_context.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#include <iostream>

#include "sora/sora_client_context.h"

// WebRTC
#include <api/create_peerconnection_factory.h>
#include <api/enable_media.h>
#include <api/environment/environment_factory.h>
#include <api/rtc_event_log/rtc_event_log_factory.h>
#include <api/task_queue/default_task_queue_factory.h>
#include <call/call_config.h>
#include <media/engine/webrtc_media_engine.h>
#include <modules/audio_device/include/audio_device.h>
#include <modules/audio_device/include/audio_device_factory.h>
#include <modules/audio_processing/include/audio_processing.h>
#include <modules/video_capture/video_capture.h>
#include <modules/video_capture/video_capture_factory.h>
#include <pc/media_factory.h>
#include <pc/video_track_source_proxy.h>
#include <rtc_base/logging.h>
#include <rtc_base/ssl_adapter.h>
Expand Down Expand Up @@ -55,17 +61,13 @@ std::shared_ptr<SoraClientContext> SoraClientContext::Create(
dependencies.worker_thread = c->worker_thread_.get();
dependencies.signaling_thread = c->signaling_thread_.get();
dependencies.task_queue_factory = webrtc::CreateDefaultTaskQueueFactory();
dependencies.call_factory = webrtc::CreateCallFactory();
dependencies.event_log_factory =
absl::make_unique<webrtc::RtcEventLogFactory>(
dependencies.task_queue_factory.get());

void* env = sora::GetJNIEnv();

// media_dependencies
cricket::MediaEngineDependencies media_dependencies;
media_dependencies.task_queue_factory = dependencies.task_queue_factory.get();
media_dependencies.adm = c->worker_thread_->BlockingCall([&] {
dependencies.adm = c->worker_thread_->BlockingCall([&] {
sora::AudioDeviceModuleConfig config;
if (!c->config_.use_audio_device) {
config.audio_layer = webrtc::AudioDeviceModule::kDummyAudio;
Expand All @@ -79,10 +81,8 @@ std::shared_ptr<SoraClientContext> SoraClientContext::Create(
return sora::CreateAudioDeviceModule(config);
});

media_dependencies.audio_encoder_factory =
sora::CreateBuiltinAudioEncoderFactory();
media_dependencies.audio_decoder_factory =
sora::CreateBuiltinAudioDecoderFactory();
dependencies.audio_encoder_factory = sora::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory = sora::CreateBuiltinAudioDecoderFactory();

std::shared_ptr<sora::CudaContext> cuda_context;
if (c->config_.use_hardware_encoder) {
Expand All @@ -95,33 +95,27 @@ std::shared_ptr<SoraClientContext> SoraClientContext::Create(
? sora::GetDefaultVideoEncoderFactoryConfig(cuda_context, env)
: sora::GetSoftwareOnlyVideoEncoderFactoryConfig();
config.use_simulcast_adapter = true;
media_dependencies.video_encoder_factory =
dependencies.video_encoder_factory =
absl::make_unique<sora::SoraVideoEncoderFactory>(std::move(config));
}
{
auto config =
c->config_.use_hardware_encoder
? sora::GetDefaultVideoDecoderFactoryConfig(cuda_context, env)
: sora::GetSoftwareOnlyVideoDecoderFactoryConfig();
media_dependencies.video_decoder_factory =
dependencies.video_decoder_factory =
absl::make_unique<sora::SoraVideoDecoderFactory>(std::move(config));
}

media_dependencies.audio_mixer = nullptr;
media_dependencies.audio_processing =
webrtc::AudioProcessingBuilder().Create();

if (c->config_.configure_media_dependencies) {
c->config_.configure_media_dependencies(dependencies, media_dependencies);
}

dependencies.media_engine =
cricket::CreateMediaEngine(std::move(media_dependencies));
dependencies.audio_mixer = nullptr;
dependencies.audio_processing = webrtc::AudioProcessingBuilder().Create();

if (c->config_.configure_dependencies) {
c->config_.configure_dependencies(dependencies);
}

webrtc::EnableMedia(dependencies);

c->factory_ = sora::CreateModularPeerConnectionFactoryWithContext(
std::move(dependencies), c->connection_context_);

Expand Down

0 comments on commit 43ea5d3

Please sign in to comment.