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_DATA_STREAM_ADAPTER_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ |
6 #define REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "remoting/protocol/stream_channel_factory.h" | 12 #include "remoting/protocol/stream_channel_factory.h" |
13 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h
" | 13 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h
" |
14 #include "third_party/webrtc/base/refcount.h" | 14 #include "third_party/webrtc/base/refcount.h" |
15 | 15 |
16 namespace rtc { | 16 namespace rtc { |
17 class PeerConnectionInterface; | 17 class PeerConnectionInterface; |
18 } // namespace rtc | 18 } // namespace rtc |
19 | 19 |
20 namespace remoting { | 20 namespace remoting { |
21 namespace protocol { | 21 namespace protocol { |
22 | 22 |
| 23 // WebrtcDataStreamAdapter is a StreamChannelFactory that creates channels that |
| 24 // send and receive data over PeerConnection data channels. |
23 class WebrtcDataStreamAdapter : public StreamChannelFactory { | 25 class WebrtcDataStreamAdapter : public StreamChannelFactory { |
24 public: | 26 public: |
25 WebrtcDataStreamAdapter(); | 27 WebrtcDataStreamAdapter(); |
26 ~WebrtcDataStreamAdapter() override; | 28 ~WebrtcDataStreamAdapter() override; |
27 | 29 |
| 30 // Initializes the adapter for |peer_connection|. If |outgoing| is set to true |
| 31 // all channels will be created as outgoing. Otherwise CreateChannel() will |
| 32 // wait for the other end to create connection. |
28 void Initialize( | 33 void Initialize( |
29 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection, | 34 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection, |
30 bool is_server); | 35 bool outgoing); |
31 | 36 |
| 37 // Called by WebrtcTransport. |
32 void OnIncomingDataChannel(webrtc::DataChannelInterface* data_channel); | 38 void OnIncomingDataChannel(webrtc::DataChannelInterface* data_channel); |
33 | 39 |
34 // StreamChannelFactory interface. | 40 // StreamChannelFactory interface. |
35 void CreateChannel(const std::string& name, | 41 void CreateChannel(const std::string& name, |
36 const ChannelCreatedCallback& callback) override; | 42 const ChannelCreatedCallback& callback) override; |
37 void CancelChannelCreation(const std::string& name) override; | 43 void CancelChannelCreation(const std::string& name) override; |
38 | 44 |
39 private: | 45 private: |
40 class Channel; | 46 class Channel; |
41 | 47 |
42 void OnChannelConnected(const ChannelCreatedCallback& connected_callback, | 48 void OnChannelConnected(const ChannelCreatedCallback& connected_callback, |
43 Channel* channel, | 49 Channel* channel, |
44 bool connected); | 50 bool connected); |
45 | 51 |
46 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 52 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
47 bool is_server_ = false; | 53 bool outgoing_ = false; |
48 | 54 |
49 std::map<std::string, Channel*> pending_channels_; | 55 std::map<std::string, Channel*> pending_channels_; |
50 | 56 |
51 base::WeakPtrFactory<WebrtcDataStreamAdapter> weak_factory_; | 57 base::WeakPtrFactory<WebrtcDataStreamAdapter> weak_factory_; |
52 | 58 |
53 DISALLOW_COPY_AND_ASSIGN(WebrtcDataStreamAdapter); | 59 DISALLOW_COPY_AND_ASSIGN(WebrtcDataStreamAdapter); |
54 }; | 60 }; |
55 | 61 |
56 } // namespace protocol | 62 } // namespace protocol |
57 } // namespace remoting | 63 } // namespace remoting |
58 | 64 |
59 #endif // REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ | 65 #endif // REMOTING_PROTOCOL_WEBRTC_DATA_STREAM_ADAPTER_H_ |
OLD | NEW |