blob: e48aae47e1e9efd964199feca6ddb7d76ba4599f [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
17#include "api/peerconnectioninterface.h"
18#include "rtc_base/criticalsection.h"
19#include "rtc_base/scoped_ref_ptr.h"
20#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
39 void OnSignalingChange(
40 webrtc::PeerConnectionInterface::SignalingState new_state) override;
41 void OnDataChannel(
42 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
43 void OnRenegotiationNeeded() override;
44 void OnIceConnectionChange(
45 webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
46 void OnIceGatheringChange(
47 webrtc::PeerConnectionInterface::IceGatheringState new_state) override;
48 void OnIceCandidate(
49 const webrtc::IceCandidateInterface* candidate) override;
50
51 private:
52 const ObjCCallClient* client_;
53 };
54
55 void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
56 void CreatePeerConnection() RTC_RUN_ON(thread_checker_);
57 void Connect() RTC_RUN_ON(thread_checker_);
58
59 rtc::ThreadChecker thread_checker_;
60
61 bool call_started_ RTC_GUARDED_BY(thread_checker_);
62
63 const std::unique_ptr<PCObserver> pc_observer_;
64
65 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_
66 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_
70 RTC_GUARDED_BY(thread_checker_);
71
72 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_
73 RTC_GUARDED_BY(thread_checker_);
74 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_
75 RTC_GUARDED_BY(thread_checker_);
76
77 rtc::CriticalSection pc_mutex_;
78 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
79 RTC_GUARDED_BY(pc_mutex_);
80};
81
82} // namespace webrtc_examples
83
84#endif // EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_