objc_call_client.h (2940B)
1 /* 2 * Copyright 2018 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_ 12 #define EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_ 13 14 #include <memory> 15 #include <string> 16 17 #import "sdk/objc/base/RTCMacros.h" 18 19 #include "api/peer_connection_interface.h" 20 #include "api/scoped_refptr.h" 21 #include "api/sequence_checker.h" 22 #include "rtc_base/synchronization/mutex.h" 23 24 @class RTC_OBJC_TYPE(RTCVideoCapturer); 25 @protocol RTC_OBJC_TYPE 26 (RTCVideoRenderer); 27 28 namespace webrtc_examples { 29 30 class ObjCCallClient { 31 public: 32 ObjCCallClient(); 33 34 void Call(RTC_OBJC_TYPE(RTCVideoCapturer) * capturer, 35 id<RTC_OBJC_TYPE(RTCVideoRenderer)> remote_renderer); 36 void Hangup(); 37 38 private: 39 class PCObserver : public webrtc::PeerConnectionObserver { 40 public: 41 explicit PCObserver(ObjCCallClient* client); 42 43 void OnSignalingChange( 44 webrtc::PeerConnectionInterface::SignalingState new_state) override; 45 void OnDataChannel(webrtc::scoped_refptr<webrtc::DataChannelInterface> 46 data_channel) override; 47 void OnRenegotiationNeeded() override; 48 void OnIceConnectionChange( 49 webrtc::PeerConnectionInterface::IceConnectionState new_state) override; 50 void OnIceGatheringChange( 51 webrtc::PeerConnectionInterface::IceGatheringState new_state) override; 52 void OnIceCandidate(const webrtc::IceCandidate* candidate) override; 53 54 private: 55 ObjCCallClient* const client_; 56 }; 57 58 void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_); 59 void CreatePeerConnection() RTC_RUN_ON(thread_checker_); 60 void Connect() RTC_RUN_ON(thread_checker_); 61 62 webrtc::SequenceChecker thread_checker_; 63 64 bool call_started_ RTC_GUARDED_BY(thread_checker_); 65 66 const std::unique_ptr<PCObserver> pc_observer_; 67 68 webrtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_ 69 RTC_GUARDED_BY(thread_checker_); 70 std::unique_ptr<webrtc::Thread> network_thread_ 71 RTC_GUARDED_BY(thread_checker_); 72 std::unique_ptr<webrtc::Thread> worker_thread_ 73 RTC_GUARDED_BY(thread_checker_); 74 std::unique_ptr<webrtc::Thread> signaling_thread_ 75 RTC_GUARDED_BY(thread_checker_); 76 77 std::unique_ptr<webrtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_ 78 RTC_GUARDED_BY(thread_checker_); 79 webrtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_ 80 RTC_GUARDED_BY(thread_checker_); 81 82 webrtc::Mutex pc_mutex_; 83 webrtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ 84 RTC_GUARDED_BY(pc_mutex_); 85 }; 86 87 } // namespace webrtc_examples 88 89 #endif // EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_