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 "rtc_base/synchronization/mutex.h" 22 #include "rtc_base/thread_checker.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(webrtc::PeerConnectionInterface::SignalingState new_state) override; 44 void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override; 45 void OnRenegotiationNeeded() override; 46 void OnIceConnectionChange( 47 webrtc::PeerConnectionInterface::IceConnectionState new_state) override; 48 void OnIceGatheringChange( 49 webrtc::PeerConnectionInterface::IceGatheringState new_state) override; 50 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; 51 52 private: 53 ObjCCallClient* const client_; 54 }; 55 56 void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_); 57 void CreatePeerConnection() RTC_RUN_ON(thread_checker_); 58 void Connect() RTC_RUN_ON(thread_checker_); 59 60 rtc::ThreadChecker thread_checker_; 61 62 bool call_started_ RTC_GUARDED_BY(thread_checker_); 63 64 const std::unique_ptr<PCObserver> pc_observer_; 65 66 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_ RTC_GUARDED_BY(thread_checker_); 67 std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_); 68 std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_); 69 std::unique_ptr<rtc::Thread> signaling_thread_ RTC_GUARDED_BY(thread_checker_); 70 71 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_ 72 RTC_GUARDED_BY(thread_checker_); 73 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_ 74 RTC_GUARDED_BY(thread_checker_); 75 76 webrtc::Mutex pc_mutex_; 77 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ RTC_GUARDED_BY(pc_mutex_); 78 }; 79 80 } // namespace webrtc_examples 81 82 #endif // EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_ 83