fix: datachannel deadlocks & dispose crashes (#87)

- Fix datachannel deadlock on dispose
- Fix audio device being disposed on the wrong thread
- Allow multiple RtcRuntime to be created (Useful for unit tests where we use multiple PeerConnectionFactory)
This commit is contained in:
Théo Monnom
2023-06-10 18:49:00 +02:00
committed by GitHub
parent ebbd93b2d8
commit 33dfcb27b0
9 changed files with 90 additions and 39 deletions
+1 -2
View File
@@ -40,6 +40,7 @@ class DataChannel {
explicit DataChannel(
std::shared_ptr<RtcRuntime> rtc_runtime,
rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel);
~DataChannel();
void register_observer(rust::Box<DataChannelObserverWrapper> observer) const;
void unregister_observer() const;
@@ -64,8 +65,6 @@ class NativeDataChannelObserver : public webrtc::DataChannelObserver {
NativeDataChannelObserver(rust::Box<DataChannelObserverWrapper> observer,
const DataChannel* dc);
~NativeDataChannelObserver();
void OnStateChange() override;
void OnMessage(const webrtc::DataBuffer& buffer) override;
void OnBufferedAmountChange(uint64_t sent_data_size) override;
@@ -48,6 +48,8 @@ class PeerConnection {
std::unique_ptr<NativePeerConnectionObserver> observer,
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection);
~PeerConnection();
void create_offer(
RtcOfferAnswerOptions options,
rust::Box<AsyncContext> ctx,
@@ -17,6 +17,8 @@
#pragma once
#include "api/peer_connection_interface.h"
#include "api/scoped_refptr.h"
#include "livekit/audio_device.h"
#include "media_stream.h"
#include "peer_connection.h"
#include "rtp_parameters.h"
@@ -57,6 +59,7 @@ class PeerConnectionFactory {
private:
std::shared_ptr<RtcRuntime> rtc_runtime_;
rtc::scoped_refptr<AudioDevice> audio_device_;
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_factory_;
};
+5 -3
View File
@@ -80,6 +80,8 @@ class RtcRuntime : public std::enable_shared_from_this<RtcRuntime> {
// have one livekit::VideoTrack associated with it).
// The only reason we to do that is to allow to add states inside our
// wrappers (e.g: the sinks_ member inside AudioTrack)
// DataChannel and the PeerConnectionFactory don't need to do this (There's no
// way to retrieve them after creation)
webrtc::Mutex mutex_;
std::vector<std::weak_ptr<MediaStreamTrack>> media_stream_tracks_;
// We don't have additonal state in RtpReceiver and RtpSender atm..
@@ -87,9 +89,9 @@ class RtcRuntime : public std::enable_shared_from_this<RtcRuntime> {
// std::vector<std::weak_ptr<RtpSender>> rtp_senders_;
#ifdef WEBRTC_WIN
rtc::WinsockInitializer winsock_;
rtc::PhysicalSocketServer ss_;
rtc::AutoSocketServerThread main_thread_{&ss_};
// rtc::WinsockInitializer winsock_;
// rtc::PhysicalSocketServer ss_;
// rtc::AutoSocketServerThread main_thread_{&ss_};
#endif
};