OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_WEBRTC_TRANSPORT_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_TRANSPORT_H_ |
6 #define REMOTING_PROTOCOL_WEBRTC_TRANSPORT_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_TRANSPORT_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread.h" | |
13 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
14 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
15 #include "remoting/protocol/transport.h" | 14 #include "remoting/protocol/transport.h" |
16 #include "remoting/protocol/webrtc_data_stream_adapter.h" | 15 #include "remoting/protocol/webrtc_data_stream_adapter.h" |
17 #include "remoting/signaling/signal_strategy.h" | 16 #include "remoting/signaling/signal_strategy.h" |
18 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h
" | 17 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h
" |
19 | 18 |
20 namespace webrtc { | 19 namespace webrtc { |
21 class FakeAudioDeviceModule; | 20 class FakeAudioDeviceModule; |
22 } // namespace webrtc | 21 } // namespace webrtc |
23 | 22 |
24 namespace remoting { | 23 namespace remoting { |
25 namespace protocol { | 24 namespace protocol { |
26 | 25 |
27 class WebrtcTransport : public Transport, | 26 class WebrtcTransport : public Transport, |
28 public webrtc::PeerConnectionObserver { | 27 public webrtc::PeerConnectionObserver { |
29 public: | 28 public: |
30 WebrtcTransport( | 29 WebrtcTransport(rtc::Thread* worker_thread, |
31 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> | 30 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> |
32 port_allocator_factory, | 31 port_allocator_factory, |
33 TransportRole role, | 32 TransportRole role); |
34 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner); | |
35 ~WebrtcTransport() override; | 33 ~WebrtcTransport() override; |
36 | 34 |
| 35 webrtc::PeerConnectionInterface* peer_connection() { |
| 36 return peer_connection_; |
| 37 } |
| 38 webrtc::PeerConnectionFactoryInterface* peer_connection_factory() { |
| 39 return peer_connection_factory_; |
| 40 } |
| 41 |
37 // Transport interface. | 42 // Transport interface. |
38 void Start(EventHandler* event_handler, | 43 void Start(EventHandler* event_handler, |
39 Authenticator* authenticator) override; | 44 Authenticator* authenticator) override; |
40 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override; | 45 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override; |
41 StreamChannelFactory* GetStreamChannelFactory() override; | 46 StreamChannelFactory* GetStreamChannelFactory() override; |
42 StreamChannelFactory* GetMultiplexedChannelFactory() override; | 47 StreamChannelFactory* GetMultiplexedChannelFactory() override; |
43 | 48 |
44 private: | 49 private: |
45 void DoStart(rtc::Thread* worker_thread); | |
46 void OnLocalSessionDescriptionCreated( | 50 void OnLocalSessionDescriptionCreated( |
47 scoped_ptr<webrtc::SessionDescriptionInterface> description, | 51 scoped_ptr<webrtc::SessionDescriptionInterface> description, |
48 const std::string& error); | 52 const std::string& error); |
49 void OnLocalDescriptionSet(bool success, const std::string& error); | 53 void OnLocalDescriptionSet(bool success, const std::string& error); |
50 void OnRemoteDescriptionSet(bool success, const std::string& error); | 54 void OnRemoteDescriptionSet(bool send_answer, |
| 55 bool success, |
| 56 const std::string& error); |
51 | 57 |
52 // webrtc::PeerConnectionObserver interface. | 58 // webrtc::PeerConnectionObserver interface. |
53 void OnSignalingChange( | 59 void OnSignalingChange( |
54 webrtc::PeerConnectionInterface::SignalingState new_state) override; | 60 webrtc::PeerConnectionInterface::SignalingState new_state) override; |
55 void OnAddStream(webrtc::MediaStreamInterface* stream) override; | 61 void OnAddStream(webrtc::MediaStreamInterface* stream) override; |
56 void OnRemoveStream(webrtc::MediaStreamInterface* stream) override; | 62 void OnRemoveStream(webrtc::MediaStreamInterface* stream) override; |
57 void OnDataChannel(webrtc::DataChannelInterface* data_channel) override; | 63 void OnDataChannel(webrtc::DataChannelInterface* data_channel) override; |
58 void OnRenegotiationNeeded() override; | 64 void OnRenegotiationNeeded() override; |
59 void OnIceConnectionChange( | 65 void OnIceConnectionChange( |
60 webrtc::PeerConnectionInterface::IceConnectionState new_state) override; | 66 webrtc::PeerConnectionInterface::IceConnectionState new_state) override; |
61 void OnIceGatheringChange( | 67 void OnIceGatheringChange( |
62 webrtc::PeerConnectionInterface::IceGatheringState new_state) override; | 68 webrtc::PeerConnectionInterface::IceGatheringState new_state) override; |
63 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; | 69 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
64 | 70 |
| 71 void RequestNegotiation(); |
| 72 void SendOffer(); |
65 void EnsurePendingTransportInfoMessage(); | 73 void EnsurePendingTransportInfoMessage(); |
66 void SendTransportInfo(); | 74 void SendTransportInfo(); |
67 void AddPendingCandidatesIfPossible(); | 75 void AddPendingCandidatesIfPossible(); |
68 | 76 |
69 void Close(ErrorCode error); | 77 void Close(ErrorCode error); |
70 | 78 |
71 base::ThreadChecker thread_checker_; | 79 base::ThreadChecker thread_checker_; |
72 | 80 |
73 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> | 81 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> |
74 port_allocator_factory_; | 82 port_allocator_factory_; |
75 TransportRole role_; | 83 TransportRole role_; |
76 EventHandler* event_handler_ = nullptr; | 84 EventHandler* event_handler_ = nullptr; |
77 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; | 85 rtc::Thread* worker_thread_; |
78 | 86 |
79 scoped_ptr<webrtc::FakeAudioDeviceModule> fake_audio_device_module_; | 87 scoped_ptr<webrtc::FakeAudioDeviceModule> fake_audio_device_module_; |
80 | 88 |
81 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> | 89 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
82 peer_connection_factory_; | 90 peer_connection_factory_; |
83 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 91 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
84 | 92 |
| 93 bool negotiation_pending_ = false; |
| 94 |
85 scoped_ptr<buzz::XmlElement> pending_transport_info_message_; | 95 scoped_ptr<buzz::XmlElement> pending_transport_info_message_; |
86 base::OneShotTimer transport_info_timer_; | 96 base::OneShotTimer transport_info_timer_; |
87 | 97 |
88 ScopedVector<webrtc::IceCandidateInterface> pending_incoming_candidates_; | 98 ScopedVector<webrtc::IceCandidateInterface> pending_incoming_candidates_; |
89 | 99 |
90 std::list<rtc::scoped_refptr<webrtc::MediaStreamInterface>> | 100 std::list<rtc::scoped_refptr<webrtc::MediaStreamInterface>> |
91 unclaimed_streams_; | 101 unclaimed_streams_; |
92 | 102 |
93 WebrtcDataStreamAdapter data_stream_adapter_; | 103 WebrtcDataStreamAdapter data_stream_adapter_; |
94 | 104 |
95 base::WeakPtrFactory<WebrtcTransport> weak_factory_; | 105 base::WeakPtrFactory<WebrtcTransport> weak_factory_; |
96 | 106 |
97 DISALLOW_COPY_AND_ASSIGN(WebrtcTransport); | 107 DISALLOW_COPY_AND_ASSIGN(WebrtcTransport); |
98 }; | 108 }; |
99 | 109 |
100 class WebrtcTransportFactory : public TransportFactory { | 110 class WebrtcTransportFactory : public TransportFactory { |
101 public: | 111 public: |
102 WebrtcTransportFactory( | 112 WebrtcTransportFactory( |
| 113 rtc::Thread* worker_thread, |
103 SignalStrategy* signal_strategy, | 114 SignalStrategy* signal_strategy, |
104 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> | 115 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> |
105 port_allocator_factory, | 116 port_allocator_factory, |
106 TransportRole role); | 117 TransportRole role); |
107 ~WebrtcTransportFactory() override; | 118 ~WebrtcTransportFactory() override; |
108 | 119 |
109 // TransportFactory interface. | 120 // TransportFactory interface. |
110 scoped_ptr<Transport> CreateTransport() override; | 121 scoped_ptr<Transport> CreateTransport() override; |
111 | 122 |
112 private: | 123 private: |
| 124 rtc::Thread* worker_thread_; |
113 SignalStrategy* signal_strategy_; | 125 SignalStrategy* signal_strategy_; |
114 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> | 126 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> |
115 port_allocator_factory_; | 127 port_allocator_factory_; |
116 TransportRole role_; | 128 TransportRole role_; |
117 | 129 |
118 base::Thread worker_thread_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(WebrtcTransportFactory); | 130 DISALLOW_COPY_AND_ASSIGN(WebrtcTransportFactory); |
121 }; | 131 }; |
122 | 132 |
123 } // namespace protocol | 133 } // namespace protocol |
124 } // namespace remoting | 134 } // namespace remoting |
125 | 135 |
126 #endif // REMOTING_PROTOCOL_WEBRTC_TRANSPORT_H_ | 136 #endif // REMOTING_PROTOCOL_WEBRTC_TRANSPORT_H_ |
OLD | NEW |