Initial Room
Switching computer
This commit is contained in:
@@ -68,11 +68,18 @@ pub mod ffi {
|
||||
observer: Box<SetRemoteSdpObserverWrapper>,
|
||||
) -> UniquePtr<NativeSetRemoteSdpObserverHandle>;
|
||||
|
||||
fn create_ice_candidate(sdp_mid: String, sdp_mline_index: i32, sdp: String) -> Result<UniquePtr<IceCandidate>>;
|
||||
fn create_session_description(sdp_type: SdpType, sdp: String) -> Result<UniquePtr<SessionDescription>>;
|
||||
fn create_ice_candidate(
|
||||
sdp_mid: String,
|
||||
sdp_mline_index: i32,
|
||||
sdp: String,
|
||||
) -> Result<UniquePtr<IceCandidate>>;
|
||||
fn create_session_description(
|
||||
sdp_type: SdpType,
|
||||
sdp: String,
|
||||
) -> Result<UniquePtr<SessionDescription>>;
|
||||
|
||||
fn _unique_ice_candidate() -> UniquePtr<IceCandidate>; // Ignore
|
||||
fn _unique_session_description() -> UniquePtr<SessionDescription>; // Ignore
|
||||
fn _unique_session_description() -> UniquePtr<SessionDescription>; // Ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +87,11 @@ impl Error for ffi::SdpParseError {}
|
||||
|
||||
impl Display for ffi::SdpParseError {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
write!(f, "SdpParseError occurred {}: {}", self.line, self.description)
|
||||
write!(
|
||||
f,
|
||||
"SdpParseError occurred {}: {}",
|
||||
self.line, self.description
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,10 +112,7 @@ impl ffi::SdpParseError {
|
||||
let line = String::from(&value[8..line_length]);
|
||||
let description = String::from(&value[line_length..]);
|
||||
|
||||
Self {
|
||||
line,
|
||||
description,
|
||||
}
|
||||
Self { line, description }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod candidate;
|
||||
pub mod data_channel;
|
||||
pub mod jsep;
|
||||
pub mod media_stream_interface;
|
||||
pub mod media_stream;
|
||||
pub mod peer_connection;
|
||||
pub mod peer_connection_factory;
|
||||
pub mod rtc_error;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Created by Théo Monnom on 31/08/2022.
|
||||
//
|
||||
|
||||
#include "livekit/media_stream.h"
|
||||
|
||||
namespace livekit {
|
||||
|
||||
MediaStreamTrack::MediaStreamTrack(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track)
|
||||
: track_(std::move(track)) {}
|
||||
|
||||
rust::String MediaStreamTrack::kind() const {
|
||||
return track_->kind();
|
||||
}
|
||||
|
||||
rust::String MediaStreamTrack::id() const {
|
||||
return track_->id();
|
||||
}
|
||||
|
||||
bool MediaStreamTrack::enabled() const {
|
||||
return track_->enabled();
|
||||
}
|
||||
|
||||
bool MediaStreamTrack::set_enabled(bool enable) {
|
||||
return track_->set_enabled(enable);
|
||||
}
|
||||
|
||||
TrackState MediaStreamTrack::state() const {
|
||||
return static_cast<TrackState>(track_->state());
|
||||
}
|
||||
|
||||
MediaStream::MediaStream(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream)
|
||||
: media_stream_(std::move(stream)) {}
|
||||
|
||||
rust::String MediaStream::id() const {
|
||||
return media_stream_->id();
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
@@ -0,0 +1,36 @@
|
||||
#[cxx::bridge(namespace = "livekit")]
|
||||
pub mod ffi {
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(i32)]
|
||||
pub enum TrackState {
|
||||
Live,
|
||||
Ended,
|
||||
}
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("livekit/media_stream.h");
|
||||
|
||||
type MediaStreamTrack;
|
||||
type MediaStream;
|
||||
|
||||
fn kind(self: &MediaStreamTrack) -> String;
|
||||
fn id(self: &MediaStreamTrack) -> String;
|
||||
fn enabled(self: &MediaStreamTrack) -> bool;
|
||||
fn set_enabled(self: Pin<&mut MediaStreamTrack>, enable: bool) -> bool;
|
||||
fn state(self: &MediaStreamTrack) -> TrackState;
|
||||
|
||||
fn id(self: &MediaStream) -> String;
|
||||
|
||||
fn _unique_media_stream_track() -> UniquePtr<MediaStreamTrack>; // Ignore
|
||||
fn _unique_media_stream() -> UniquePtr<MediaStream>; // Ignore
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for ffi::MediaStreamTrack {}
|
||||
|
||||
unsafe impl Send for ffi::MediaStreamTrack {}
|
||||
|
||||
unsafe impl Sync for ffi::MediaStream {}
|
||||
|
||||
unsafe impl Send for ffi::MediaStream {}
|
||||
@@ -1,12 +0,0 @@
|
||||
//
|
||||
// Created by Théo Monnom on 31/08/2022.
|
||||
//
|
||||
|
||||
#include "livekit/media_stream_interface.h"
|
||||
|
||||
namespace livekit {
|
||||
|
||||
MediaStreamInterface::MediaStreamInterface(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream)
|
||||
: media_stream_(std::move(stream)) {}
|
||||
} // namespace livekit
|
||||
@@ -1,10 +0,0 @@
|
||||
#[cxx::bridge(namespace = "livekit")]
|
||||
pub mod ffi {
|
||||
unsafe extern "C++" {
|
||||
include!("livekit/media_stream_interface.h");
|
||||
|
||||
type MediaStreamInterface;
|
||||
|
||||
fn _unique_media_stream() -> UniquePtr<MediaStreamInterface>; // Ignore
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "livekit/peer_connection.h"
|
||||
#include "livekit/media_stream.h"
|
||||
|
||||
#include "libwebrtc-sys/src/peer_connection.rs.h"
|
||||
#include "livekit/rtc_error.h"
|
||||
@@ -142,12 +143,12 @@ void NativePeerConnectionObserver::OnSignalingChange(
|
||||
|
||||
void NativePeerConnectionObserver::OnAddStream(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
|
||||
observer_->on_add_stream(std::make_unique<MediaStreamInterface>(stream));
|
||||
observer_->on_add_stream(std::make_unique<MediaStream>(stream));
|
||||
}
|
||||
|
||||
void NativePeerConnectionObserver::OnRemoveStream(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
|
||||
observer_->on_remove_stream(std::make_unique<MediaStreamInterface>(stream));
|
||||
observer_->on_remove_stream(std::make_unique<MediaStream>(stream));
|
||||
}
|
||||
|
||||
void NativePeerConnectionObserver::OnDataChannel(
|
||||
@@ -241,7 +242,7 @@ void NativePeerConnectionObserver::OnAddTrack(
|
||||
rust::Vec<MediaStreamPtr> vec;
|
||||
|
||||
for (const auto& item : streams) {
|
||||
vec.push_back(MediaStreamPtr{std::make_unique<MediaStreamInterface>(item)});
|
||||
vec.push_back(MediaStreamPtr{std::make_unique<MediaStream>(item)});
|
||||
}
|
||||
|
||||
observer_->on_add_track(std::make_unique<RtpReceiver>(receiver),
|
||||
|
||||
@@ -6,7 +6,7 @@ use cxx::UniquePtr;
|
||||
use crate::candidate::ffi::Candidate;
|
||||
use crate::data_channel::ffi::DataChannel;
|
||||
use crate::jsep::ffi::IceCandidate;
|
||||
use crate::media_stream_interface::ffi::MediaStreamInterface;
|
||||
use crate::media_stream::ffi::MediaStream;
|
||||
use crate::rtc_error::ffi::RTCError;
|
||||
use crate::rtp_receiver::ffi::RtpReceiver;
|
||||
use crate::rtp_transceiver::ffi::RtpTransceiver;
|
||||
@@ -83,7 +83,7 @@ pub mod ffi {
|
||||
// Wrapper to opaque C++ objects
|
||||
// https://github.com/dtolnay/cxx/issues/741
|
||||
struct MediaStreamPtr {
|
||||
pub ptr: UniquePtr<MediaStreamInterface>,
|
||||
pub ptr: UniquePtr<MediaStream>,
|
||||
}
|
||||
|
||||
struct CandidatePtr {
|
||||
@@ -96,7 +96,7 @@ pub mod ffi {
|
||||
include!("livekit/data_channel.h");
|
||||
include!("livekit/rtp_receiver.h");
|
||||
include!("livekit/rtp_transceiver.h");
|
||||
include!("livekit/media_stream_interface.h");
|
||||
include!("livekit/media_stream.h");
|
||||
include!("livekit/candidate.h");
|
||||
include!("libwebrtc-sys/src/rtc_error.rs.h");
|
||||
|
||||
@@ -106,7 +106,7 @@ pub mod ffi {
|
||||
type DataChannel = crate::data_channel::ffi::DataChannel;
|
||||
type RtpReceiver = crate::rtp_receiver::ffi::RtpReceiver;
|
||||
type RtpTransceiver = crate::rtp_transceiver::ffi::RtpTransceiver;
|
||||
type MediaStreamInterface = crate::media_stream_interface::ffi::MediaStreamInterface;
|
||||
type MediaStream = crate::media_stream::ffi::MediaStream;
|
||||
type NativeCreateSdpObserverHandle = crate::jsep::ffi::NativeCreateSdpObserverHandle;
|
||||
type NativeSetLocalSdpObserverHandle = crate::jsep::ffi::NativeSetLocalSdpObserverHandle;
|
||||
type NativeSetRemoteSdpObserverHandle = crate::jsep::ffi::NativeSetRemoteSdpObserverHandle;
|
||||
@@ -194,14 +194,8 @@ pub mod ffi {
|
||||
type PeerConnectionObserverWrapper;
|
||||
|
||||
fn on_signaling_change(self: &PeerConnectionObserverWrapper, new_state: SignalingState);
|
||||
fn on_add_stream(
|
||||
self: &PeerConnectionObserverWrapper,
|
||||
stream: UniquePtr<MediaStreamInterface>,
|
||||
);
|
||||
fn on_remove_stream(
|
||||
self: &PeerConnectionObserverWrapper,
|
||||
stream: UniquePtr<MediaStreamInterface>,
|
||||
);
|
||||
fn on_add_stream(self: &PeerConnectionObserverWrapper, stream: UniquePtr<MediaStream>);
|
||||
fn on_remove_stream(self: &PeerConnectionObserverWrapper, stream: UniquePtr<MediaStream>);
|
||||
fn on_data_channel(
|
||||
self: &PeerConnectionObserverWrapper,
|
||||
data_channel: UniquePtr<DataChannel>,
|
||||
@@ -317,8 +311,8 @@ impl AddIceCandidateObserverWrapper {
|
||||
|
||||
pub trait PeerConnectionObserver: Send + Sync {
|
||||
fn on_signaling_change(&self, new_state: ffi::SignalingState);
|
||||
fn on_add_stream(&self, stream: UniquePtr<MediaStreamInterface>);
|
||||
fn on_remove_stream(&self, stream: UniquePtr<MediaStreamInterface>);
|
||||
fn on_add_stream(&self, stream: UniquePtr<MediaStream>);
|
||||
fn on_remove_stream(&self, stream: UniquePtr<MediaStream>);
|
||||
fn on_data_channel(&self, data_channel: UniquePtr<DataChannel>);
|
||||
fn on_renegotiation_needed(&self);
|
||||
fn on_negotiation_needed_event(&self, event: u32);
|
||||
@@ -338,11 +332,7 @@ pub trait PeerConnectionObserver: Send + Sync {
|
||||
fn on_ice_candidates_removed(&self, removed: Vec<UniquePtr<Candidate>>);
|
||||
fn on_ice_connection_receiving_change(&self, receiving: bool);
|
||||
fn on_ice_selected_candidate_pair_changed(&self, event: ffi::CandidatePairChangeEvent);
|
||||
fn on_add_track(
|
||||
&self,
|
||||
receiver: UniquePtr<RtpReceiver>,
|
||||
streams: Vec<UniquePtr<MediaStreamInterface>>,
|
||||
);
|
||||
fn on_add_track(&self, receiver: UniquePtr<RtpReceiver>, streams: Vec<UniquePtr<MediaStream>>);
|
||||
fn on_track(&self, transceiver: UniquePtr<RtpTransceiver>);
|
||||
fn on_remove_track(&self, receiver: UniquePtr<RtpReceiver>);
|
||||
fn on_interesting_usage(&self, usage_pattern: i32);
|
||||
@@ -366,13 +356,13 @@ impl PeerConnectionObserverWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_add_stream(&self, stream: UniquePtr<MediaStreamInterface>) {
|
||||
fn on_add_stream(&self, stream: UniquePtr<MediaStream>) {
|
||||
unsafe {
|
||||
(*self.observer).on_add_stream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_remove_stream(&self, stream: UniquePtr<MediaStreamInterface>) {
|
||||
fn on_remove_stream(&self, stream: UniquePtr<MediaStream>) {
|
||||
unsafe {
|
||||
(*self.observer).on_remove_stream(stream);
|
||||
}
|
||||
|
||||
@@ -35,12 +35,14 @@ pub mod ffi {
|
||||
|
||||
type PeerConnection = crate::peer_connection::ffi::PeerConnection;
|
||||
type NativePeerConnectionObserver =
|
||||
crate::peer_connection::ffi::NativePeerConnectionObserver;
|
||||
crate::peer_connection::ffi::NativePeerConnectionObserver;
|
||||
type PeerConnectionFactory;
|
||||
type NativeRTCConfiguration;
|
||||
type RTCRuntime = crate::webrtc::ffi::RTCRuntime;
|
||||
|
||||
fn create_peer_connection_factory(runtime: SharedPtr<RTCRuntime>) -> UniquePtr<PeerConnectionFactory>;
|
||||
fn create_peer_connection_factory(
|
||||
runtime: SharedPtr<RTCRuntime>,
|
||||
) -> UniquePtr<PeerConnectionFactory>;
|
||||
fn create_rtc_configuration(conf: RTCConfiguration) -> UniquePtr<NativeRTCConfiguration>;
|
||||
|
||||
/// SAFETY
|
||||
|
||||
@@ -8,4 +8,9 @@ namespace livekit {
|
||||
RtpReceiver::RtpReceiver(
|
||||
rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver)
|
||||
: receiver_(std::move(receiver)) {}
|
||||
|
||||
std::unique_ptr<MediaStreamTrack> RtpReceiver::track() const {
|
||||
return std::make_unique<MediaStreamTrack>(receiver_->track());
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
@@ -2,9 +2,17 @@
|
||||
pub mod ffi {
|
||||
unsafe extern "C++" {
|
||||
include!("livekit/rtp_receiver.h");
|
||||
include!("livekit/media_stream.h");
|
||||
|
||||
type MediaStreamTrack = crate::media_stream::ffi::MediaStreamTrack;
|
||||
type RtpReceiver;
|
||||
|
||||
fn track(self: &RtpReceiver) -> UniquePtr<MediaStreamTrack>;
|
||||
|
||||
fn _unique_rtp_receiver() -> UniquePtr<RtpReceiver>; // Ignore
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for ffi::RtpReceiver {}
|
||||
|
||||
unsafe impl Send for ffi::RtpReceiver {}
|
||||
Reference in New Issue
Block a user