OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_ | 11 #ifndef WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_ |
12 #define WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_ | 12 #define WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/api/datachannelinterface.h" | 19 #include "webrtc/api/datachannelinterface.h" |
20 #include "webrtc/api/mediastreaminterface.h" | 20 #include "webrtc/api/mediastreaminterface.h" |
21 #include "webrtc/api/peerconnectioninterface.h" | 21 #include "webrtc/api/peerconnectioninterface.h" |
22 #include "webrtc/examples/unityplugin/unity_plugin_apis.h" | 22 #include "webrtc/examples/unityplugin/unity_plugin_apis.h" |
| 23 #include "webrtc/examples/unityplugin/video_observer.h" |
23 | 24 |
24 class SimplePeerConnection : public webrtc::PeerConnectionObserver, | 25 class SimplePeerConnection : public webrtc::PeerConnectionObserver, |
25 public webrtc::CreateSessionDescriptionObserver, | 26 public webrtc::CreateSessionDescriptionObserver, |
26 public webrtc::DataChannelObserver, | 27 public webrtc::DataChannelObserver, |
27 public webrtc::AudioTrackSinkInterface { | 28 public webrtc::AudioTrackSinkInterface { |
28 public: | 29 public: |
29 SimplePeerConnection() {} | 30 SimplePeerConnection() {} |
30 ~SimplePeerConnection() {} | 31 ~SimplePeerConnection() {} |
31 | 32 |
32 bool InitializePeerConnection(bool is_receiver); | 33 bool InitializePeerConnection(const char** turn_urls, |
| 34 const int no_of_urls, |
| 35 const char* username, |
| 36 const char* credential, |
| 37 bool is_receiver); |
33 void DeletePeerConnection(); | 38 void DeletePeerConnection(); |
34 void AddStreams(bool audio_only); | 39 void AddStreams(bool audio_only); |
35 bool CreateDataChannel(); | 40 bool CreateDataChannel(); |
36 bool CreateOffer(); | 41 bool CreateOffer(); |
37 bool CreateAnswer(); | 42 bool CreateAnswer(); |
38 bool SendDataViaDataChannel(const std::string& data); | 43 bool SendDataViaDataChannel(const std::string& data); |
39 void SetAudioControl(bool is_mute, bool is_record); | 44 void SetAudioControl(bool is_mute, bool is_record); |
40 | 45 |
41 // Register callback functions. | 46 // Register callback functions. |
42 void RegisterOnVideoFramReady(VIDEOFRAMEREADY_CALLBACK callback); | 47 void RegisterOnLocalI420FrameReady(I420FRAMEREADY_CALLBACK callback); |
| 48 void RegisterOnRemoteI420FrameReady(I420FRAMEREADY_CALLBACK callback); |
43 void RegisterOnLocalDataChannelReady(LOCALDATACHANNELREADY_CALLBACK callback); | 49 void RegisterOnLocalDataChannelReady(LOCALDATACHANNELREADY_CALLBACK callback); |
44 void RegisterOnDataFromDataChannelReady( | 50 void RegisterOnDataFromDataChannelReady( |
45 DATAFROMEDATECHANNELREADY_CALLBACK callback); | 51 DATAFROMEDATECHANNELREADY_CALLBACK callback); |
46 void RegisterOnFailure(FAILURE_CALLBACK callback); | 52 void RegisterOnFailure(FAILURE_CALLBACK callback); |
47 void RegisterOnAudioBusReady(AUDIOBUSREADY_CALLBACK callback); | 53 void RegisterOnAudioBusReady(AUDIOBUSREADY_CALLBACK callback); |
48 void RegisterOnLocalSdpReadytoSend(LOCALSDPREADYTOSEND_CALLBACK callback); | 54 void RegisterOnLocalSdpReadytoSend(LOCALSDPREADYTOSEND_CALLBACK callback); |
49 void RegisterOnIceCandiateReadytoSend( | 55 void RegisterOnIceCandiateReadytoSend( |
50 ICECANDIDATEREADYTOSEND_CALLBACK callback); | 56 ICECANDIDATEREADYTOSEND_CALLBACK callback); |
51 bool ReceivedSdp(const char* sdp); | 57 bool SetRemoteDescription(const char* type, const char* sdp); |
52 bool ReceivedIceCandidate(const char* ice_candidate); | 58 bool AddIceCandidate(const char* sdp, |
53 | 59 const int sdp_mlineindex, |
54 bool SetHeadPosition(float x, float y, float z); | 60 const char* sdp_mid); |
55 bool SetHeadRotation(float rx, float ry, float rz, float rw); | |
56 bool SetRemoteAudioPosition(float x, float y, float z); | |
57 bool SetRemoteAudioRotation(float rx, float ry, float rz, float rw); | |
58 | 61 |
59 protected: | 62 protected: |
60 bool CreatePeerConnection(bool receiver); | 63 // create a peerconneciton and add the turn servers info to the configuration. |
| 64 bool CreatePeerConnection(const char** turn_urls, |
| 65 const int no_of_urls, |
| 66 const char* username, |
| 67 const char* credential, |
| 68 bool is_receiver); |
61 void CloseDataChannel(); | 69 void CloseDataChannel(); |
62 std::unique_ptr<cricket::VideoCapturer> OpenVideoCaptureDevice(); | 70 std::unique_ptr<cricket::VideoCapturer> OpenVideoCaptureDevice(); |
63 void SetAudioControl(); | 71 void SetAudioControl(); |
64 | 72 |
65 // PeerConnectionObserver implementation. | 73 // PeerConnectionObserver implementation. |
66 void OnSignalingChange( | 74 void OnSignalingChange( |
67 webrtc::PeerConnectionInterface::SignalingState new_state) override {} | 75 webrtc::PeerConnectionInterface::SignalingState new_state) override {} |
68 void OnAddStream( | 76 void OnAddStream( |
69 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override; | 77 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override; |
70 void OnRemoveStream( | 78 void OnRemoveStream( |
(...skipping 25 matching lines...) Expand all Loading... |
96 | 104 |
97 // Get remote audio tracks ssrcs. | 105 // Get remote audio tracks ssrcs. |
98 std::vector<uint32_t> GetRemoteAudioTrackSsrcs(); | 106 std::vector<uint32_t> GetRemoteAudioTrackSsrcs(); |
99 | 107 |
100 private: | 108 private: |
101 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 109 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
102 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel_; | 110 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel_; |
103 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> > | 111 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> > |
104 active_streams_; | 112 active_streams_; |
105 | 113 |
| 114 std::unique_ptr<VideoObserver> local_video_observer_; |
| 115 std::unique_ptr<VideoObserver> remote_video_observer_; |
| 116 |
106 webrtc::MediaStreamInterface* remote_stream_ = nullptr; | 117 webrtc::MediaStreamInterface* remote_stream_ = nullptr; |
| 118 webrtc::PeerConnectionInterface::RTCConfiguration config_; |
107 | 119 |
108 VIDEOFRAMEREADY_CALLBACK OnVideoFrameReady = nullptr; | |
109 LOCALDATACHANNELREADY_CALLBACK OnLocalDataChannelReady = nullptr; | 120 LOCALDATACHANNELREADY_CALLBACK OnLocalDataChannelReady = nullptr; |
110 DATAFROMEDATECHANNELREADY_CALLBACK OnDataFromDataChannelReady = nullptr; | 121 DATAFROMEDATECHANNELREADY_CALLBACK OnDataFromDataChannelReady = nullptr; |
111 FAILURE_CALLBACK OnFailureMessage = nullptr; | 122 FAILURE_CALLBACK OnFailureMessage = nullptr; |
112 AUDIOBUSREADY_CALLBACK OnAudioReady = nullptr; | 123 AUDIOBUSREADY_CALLBACK OnAudioReady = nullptr; |
113 | 124 |
114 LOCALSDPREADYTOSEND_CALLBACK OnLocalSdpReady = nullptr; | 125 LOCALSDPREADYTOSEND_CALLBACK OnLocalSdpReady = nullptr; |
115 ICECANDIDATEREADYTOSEND_CALLBACK OnIceCandiateReady = nullptr; | 126 ICECANDIDATEREADYTOSEND_CALLBACK OnIceCandiateReady = nullptr; |
116 | 127 |
117 bool is_mute_audio_ = false; | 128 bool is_mute_audio_ = false; |
118 bool is_record_audio_ = false; | 129 bool is_record_audio_ = false; |
119 | 130 |
120 // disallow copy-and-assign | 131 // disallow copy-and-assign |
121 SimplePeerConnection(const SimplePeerConnection&) = delete; | 132 SimplePeerConnection(const SimplePeerConnection&) = delete; |
122 SimplePeerConnection& operator=(const SimplePeerConnection&) = delete; | 133 SimplePeerConnection& operator=(const SimplePeerConnection&) = delete; |
123 }; | 134 }; |
124 | 135 |
125 #endif // WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_ | 136 #endif // WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_ |
OLD | NEW |