blob: de7e5fd449bcc4d037612bdaea269de73b93cdc3 [file] [log] [blame]
Anders Carlsson73119182018-03-15 09:41:03 +01001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080017#include "api/peer_connection_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010018#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/critical_section.h"
Anders Carlsson73119182018-03-15 09:41:03 +010020#include "rtc_base/thread_checker.h"
21
22@class RTCVideoCapturer;
23@protocol RTCVideoRenderer;
24
25namespace webrtc_examples {
26
27class ObjCCallClient {
28 public:
29 ObjCCallClient();
30
31 void Call(RTCVideoCapturer* capturer, id<RTCVideoRenderer> remote_renderer);
32 void Hangup();
33
34 private:
35 class PCObserver : public webrtc::PeerConnectionObserver {
36 public:
37 explicit PCObserver(ObjCCallClient* client);
38
Jonas Olssona4d87372019-07-05 19:08:33 +020039 void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;
40 void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
Anders Carlsson73119182018-03-15 09:41:03 +010041 void OnRenegotiationNeeded() override;
42 void OnIceConnectionChange(
43 webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
44 void OnIceGatheringChange(
45 webrtc::PeerConnectionInterface::IceGatheringState new_state) override;
Jonas Olssona4d87372019-07-05 19:08:33 +020046 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
Anders Carlsson73119182018-03-15 09:41:03 +010047
48 private:
49 const ObjCCallClient* client_;
50 };
51
52 void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
53 void CreatePeerConnection() RTC_RUN_ON(thread_checker_);
54 void Connect() RTC_RUN_ON(thread_checker_);
55
56 rtc::ThreadChecker thread_checker_;
57
58 bool call_started_ RTC_GUARDED_BY(thread_checker_);
59
60 const std::unique_ptr<PCObserver> pc_observer_;
61
Jonas Olssona4d87372019-07-05 19:08:33 +020062 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_ RTC_GUARDED_BY(thread_checker_);
Anders Carlsson73119182018-03-15 09:41:03 +010063 std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_);
64 std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_);
Jonas Olssona4d87372019-07-05 19:08:33 +020065 std::unique_ptr<rtc::Thread> signaling_thread_ RTC_GUARDED_BY(thread_checker_);
Anders Carlsson73119182018-03-15 09:41:03 +010066
67 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_
68 RTC_GUARDED_BY(thread_checker_);
69 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_
70 RTC_GUARDED_BY(thread_checker_);
71
72 rtc::CriticalSection pc_mutex_;
Jonas Olssona4d87372019-07-05 19:08:33 +020073 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ RTC_GUARDED_BY(pc_mutex_);
Anders Carlsson73119182018-03-15 09:41:03 +010074};
75
76} // namespace webrtc_examples
77
78#endif // EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_