fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
e33c5a9
main
1/* 2* Copyright 2023 LiveKit 3* 4* Licensed under the Apache License, Version 2.0 (the “License”); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an “AS IS” BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15*/ 16 17#pragma once 18 19#include <memory> 20 21#include "api/jsep.h" 22#include "api/ref_counted_base.h" 23#include "api/set_local_description_observer_interface.h" 24#include "api/set_remote_description_observer_interface.h" 25#include "api/stats/rtc_stats_collector_callback.h" 26#include "livekit/rtc_error.h" 27#include "rtc_base/ref_count.h" 28#include "rust/cxx.h" 29 30namespace livekit { 31class IceCandidate ; 32class SessionDescription ; 33};// namespace livekit 34#include "webrtc-sys/src/jsep.rs.h" 35 36namespace livekit { 37 38class PeerContext ; 39 40class IceCandidate { 41public : 42explicit IceCandidate ( 43std ::unique_ptr < webrtc ::IceCandidateInterface > ice_candidate ); 44 45rust ::String sdp_mid ()const ; 46int sdp_mline_index ()const ; 47rust ::String candidate ()const ;// TODO(theomonnom) Return livekit::Candidate 48// instead of rust::String 49 50rust ::String stringify ()const ; 51std ::unique_ptr < webrtc ::IceCandidateInterface > release (); 52 53private : 54std ::unique_ptr < webrtc ::IceCandidateInterface > ice_candidate_ ; 55}; 56 57std ::shared_ptr < IceCandidate > create_ice_candidate (rust ::String sdp_mid , 58int sdp_mline_index , 59rust ::String sdp ); 60 61static std ::shared_ptr < IceCandidate > _shared_ice_candidate () { 62return nullptr ;// Ignore 63} 64 65class SessionDescription { 66public : 67explicit SessionDescription ( 68std ::unique_ptr < webrtc ::SessionDescriptionInterface > session_description ); 69 70SdpType sdp_type ()const ; 71rust ::String stringify ()const ; 72std ::unique_ptr < SessionDescription > clone ()const ; 73std ::unique_ptr < webrtc ::SessionDescriptionInterface > release (); 74 75private : 76std ::unique_ptr < webrtc ::SessionDescriptionInterface > session_description_ ; 77}; 78 79std ::unique_ptr < SessionDescription > create_session_description ( 80SdpType type , 81rust ::String sdp ); 82 83static std ::unique_ptr < SessionDescription > _unique_session_description () { 84return nullptr ;// Ignore 85} 86 87class NativeCreateSdpObserver 88 :public webrtc ::CreateSessionDescriptionObserver { 89public : 90NativeCreateSdpObserver ( 91rust ::Box < PeerContext > ctx , 92rust ::Fn < void (rust ::Box < PeerContext > ctx , 93std ::unique_ptr < SessionDescription > )> on_success , 94rust ::Fn < void (rust ::Box < PeerContext > ctx ,RtcError )> on_error ); 95 96void OnSuccess (webrtc ::SessionDescriptionInterface * desc )override ; 97void OnFailure (webrtc ::RTCError error )override ; 98 99private : 100rust ::Box < PeerContext > ctx_ ; 101rust ::Fn < void (rust ::Box < PeerContext > ,std ::unique_ptr < SessionDescription > ) > 102on_success_; 103rust ::Fn < void (rust::Box < PeerContext > , RtcError) > on_error_; 104}; 105 106class NativeSetLocalSdpObserver 107: public webrtc::SetLocalDescriptionObserverInterface { 108public : 109NativeSetLocalSdpObserver ( 110rust ::Box < PeerContext > ctx, 111rust::Fn < void (rust::Box < PeerContext > , RtcError) > on_complete); 112 113void OnSetLocalDescriptionComplete ( webrtc ::RTCError error) override; 114 115private : 116rust ::Box < PeerContext > ctx_; 117rust ::Fn < void (rust::Box < PeerContext > , RtcError) > on_complete_; 118}; 119 120class NativeSetRemoteSdpObserver 121: public webrtc::SetRemoteDescriptionObserverInterface { 122public : 123NativeSetRemoteSdpObserver ( 124rust ::Box < PeerContext > ctx, 125rust::Fn < void (rust::Box < PeerContext > , RtcError) > on_complete); 126 127void OnSetRemoteDescriptionComplete ( webrtc ::RTCError error) override; 128 129private : 130rust ::Box < PeerContext > ctx_; 131rust ::Fn < void (rust::Box < PeerContext > , RtcError) > on_complete_; 132}; 133 134template < class T > // Context type 135class NativeRtcStatsCollector : public webrtc::RTCStatsCollectorCallback { 136public : 137NativeRtcStatsCollector( rust ::Box < T > ctx, 138rust::Fn < void (rust::Box < T > , rust::String) > on_stats) 139: ctx_( std :: move ( ctx )), on_stats_ (on_stats) {} 140 141void OnStatsDelivered ( 142const rtc ::scoped_refptr < const webrtc::RTCStatsReport >& report) override { 143on_stats_ ( std :: move (ctx_), report -> ToJson ()); 144} 145 146private : 147rust ::Box < T > ctx_; 148rust ::Fn < void (rust::Box < T > , rust::String) > on_stats_; 149}; 150 151} // namespace livekit