Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp committed Dec 3, 2024
1 parent cff8169 commit 7e49630
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
6 changes: 3 additions & 3 deletions webrtc-sys/include/livekit/video_decoder_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "api/video_codecs/video_decoder.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "absl/strings/numbers.h"
#include "absl/strings/match.h"

namespace livekit {
class VideoDecoderFactory : public webrtc::VideoDecoderFactory {
Expand All @@ -30,8 +30,8 @@ class VideoDecoderFactory : public webrtc::VideoDecoderFactory {
CodecSupport QueryCodecSupport(const webrtc::SdpVideoFormat& format,
bool reference_scaling) const override;

std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder(
const webrtc::SdpVideoFormat& format) override;
std::unique_ptr<webrtc::VideoDecoder> Create(
const webrtc::Environment& env, const webrtc::SdpVideoFormat& format) override;

private:
std::vector<std::unique_ptr<webrtc::VideoDecoderFactory>> factories_;
Expand Down
4 changes: 2 additions & 2 deletions webrtc-sys/include/livekit/video_encoder_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class VideoEncoderFactory : public webrtc::VideoEncoderFactory {
const webrtc::SdpVideoFormat& format,
absl::optional<std::string> scalability_mode) const override;

std::unique_ptr<webrtc::VideoEncoder> CreateVideoEncoder(
const webrtc::SdpVideoFormat& format);
std::unique_ptr<webrtc::VideoEncoder> Create(
const webrtc::Environment& env, const webrtc::SdpVideoFormat& format) override;

private:
std::unique_ptr<InternalFactory> internal_factory_;
Expand Down
27 changes: 10 additions & 17 deletions webrtc-sys/src/peer_connection_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/enable_media.h"
#include "api/rtc_event_log/rtc_event_log_factory.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/video_codecs/builtin_video_decoder_factory.h"
Expand All @@ -35,7 +36,6 @@
#include "livekit/video_decoder_factory.h"
#include "livekit/video_encoder_factory.h"
#include "livekit/webrtc.h"
#include "media/engine/webrtc_media_engine.h"
#include "rtc_base/thread.h"
#include "webrtc-sys/src/peer_connection.rs.h"
#include "webrtc-sys/src/peer_connection_factory.rs.h"
Expand All @@ -55,32 +55,25 @@ PeerConnectionFactory::PeerConnectionFactory(
dependencies.signaling_thread = rtc_runtime_->signaling_thread();
dependencies.socket_factory = rtc_runtime_->network_thread()->socketserver();
dependencies.task_queue_factory = webrtc::CreateDefaultTaskQueueFactory();
dependencies.event_log_factory = std::make_unique<webrtc::RtcEventLogFactory>(
dependencies.task_queue_factory.get());
dependencies.call_factory = webrtc::CreateCallFactory();
dependencies.event_log_factory = std::make_unique<webrtc::RtcEventLogFactory>();
dependencies.trials = std::make_unique<webrtc::FieldTrialBasedConfig>();

cricket::MediaEngineDependencies media_deps;
media_deps.task_queue_factory = dependencies.task_queue_factory.get();

audio_device_ = rtc_runtime_->worker_thread()->BlockingCall([&] {
return rtc::make_ref_counted<livekit::AudioDevice>(
media_deps.task_queue_factory);
dependencies.task_queue_factory);
});

media_deps.adm = audio_device_;
dependencies.adm = audio_device_;

media_deps.video_encoder_factory =
dependencies.video_encoder_factory =
std::move(std::make_unique<livekit::VideoEncoderFactory>());
media_deps.video_decoder_factory =
dependencies.video_decoder_factory =
std::move(std::make_unique<livekit::VideoDecoderFactory>());
media_deps.audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
media_deps.audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
media_deps.audio_processing = webrtc::AudioProcessingBuilder().Create();
media_deps.trials = dependencies.trials.get();

dependencies.media_engine = cricket::CreateMediaEngine(std::move(media_deps));
dependencies.audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
dependencies.audio_processing = webrtc::AudioProcessingBuilder().Create();

webrtc::EnableMedia(dependencies);
peer_factory_ =
webrtc::CreateModularPeerConnectionFactory(std::move(dependencies));

Expand Down
11 changes: 6 additions & 5 deletions webrtc-sys/src/video_decoder_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "livekit/video_decoder_factory.h"

#include "api/environment/environment.h"
#include "api/video_codecs/av1_profile.h"
#include "api/video_codecs/sdp_video_format.h"
#include "livekit/objc_video_factory.h"
Expand Down Expand Up @@ -69,7 +70,7 @@ std::vector<webrtc::SdpVideoFormat> VideoDecoderFactory::GetSupportedFormats()
formats.push_back(webrtc::SdpVideoFormat(cricket::kAv1CodecName));
formats.push_back(webrtc::SdpVideoFormat(
cricket::kAv1CodecName,
{{webrtc::kAV1FmtpProfile,
{{cricket::kAv1FmtpProfile,
AV1ProfileToString(webrtc::AV1Profile::kProfile1).data()}}));
#endif

Expand All @@ -92,17 +93,17 @@ VideoDecoderFactory::CodecSupport VideoDecoderFactory::QueryCodecSupport(
return codec_support;
}

std::unique_ptr<webrtc::VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
const webrtc::SdpVideoFormat& format) {
std::unique_ptr<webrtc::VideoDecoder> VideoDecoderFactory::Create(
const webrtc::Environment& env, const webrtc::SdpVideoFormat& format) {
for (const auto& factory : factories_) {
for (const auto& supported_format : factory->GetSupportedFormats()) {
if (supported_format.IsSameCodec(format))
return factory->CreateVideoDecoder(format);
return factory->Create(env, format);
}
}

if (absl::EqualsIgnoreCase(format.name, cricket::kVp8CodecName))
return webrtc::VP8Decoder::Create();
return webrtc::CreateVp8Decoder(env);
if (absl::EqualsIgnoreCase(format.name, cricket::kVp9CodecName))
return webrtc::VP9Decoder::Create();
if (absl::EqualsIgnoreCase(format.name, cricket::kH264CodecName))
Expand Down
4 changes: 2 additions & 2 deletions webrtc-sys/src/video_encoder_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ VideoEncoderFactory::CodecSupport VideoEncoderFactory::QueryCodecSupport(
return internal_factory_->QueryCodecSupport(format, scalability_mode);
}

std::unique_ptr<webrtc::VideoEncoder> VideoEncoderFactory::CreateVideoEncoder(
const webrtc::SdpVideoFormat& format) {
std::unique_ptr<webrtc::VideoEncoder> VideoEncoderFactory::Create(
const webrtc::Environment& env, const webrtc::SdpVideoFormat& format) {
std::unique_ptr<webrtc::VideoEncoder> encoder;
if (format.IsCodecInList(internal_factory_->GetSupportedFormats())) {
encoder = std::make_unique<webrtc::SimulcastEncoderAdapter>(
Expand Down

0 comments on commit 7e49630

Please sign in to comment.