Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: webrtc/examples/unityplugin/unity_plugin_apis.cc

Issue 2823783002: An example of Unity native plugin of webrtc for Windows OS (Closed)
Patch Set: review comments 2 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/examples/unityplugin/unity_plugin_apis.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 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 #include "webrtc/examples/unityplugin/unity_plugin_apis.h"
12
13 #include <map>
14 #include <string>
15
16 #include "webrtc/examples/unityplugin/simple_peer_connection.h"
17
18 namespace {
19 static int g_peer_connection_id = 1;
20 static std::map<int, rtc::scoped_refptr<SimplePeerConnection>>
21 g_SimplePeerConnection_map;
lliuu 2017/04/25 01:56:43 I think the notation style should be something lik
GeorgeZ 2017/04/25 23:52:45 Done.
22 } // namespace
23
24 int CreatePeerConnection() {
25 g_SimplePeerConnection_map[g_peer_connection_id] =
26 new rtc::RefCountedObject<SimplePeerConnection>();
27
28 if (!g_SimplePeerConnection_map[g_peer_connection_id]
29 ->InitializePeerConnection(false))
30 return -1;
31
32 return g_peer_connection_id++;
33 }
34
35 bool ClosePeerConnection(int peer_connection_id) {
36 if (!g_SimplePeerConnection_map.count(peer_connection_id))
37 return false;
38
39 g_SimplePeerConnection_map[peer_connection_id]->DeletePeerConnection();
40 g_SimplePeerConnection_map.erase(peer_connection_id);
41 return true;
42 }
43
44 bool AddStream(int peer_connection_id, bool audio_only) {
45 if (!g_SimplePeerConnection_map.count(peer_connection_id))
46 return false;
47
48 g_SimplePeerConnection_map[peer_connection_id]->AddStreams(audio_only);
49 return true;
50 }
51
52 bool AddDataChannel(int peer_connection_id) {
53 if (!g_SimplePeerConnection_map.count(peer_connection_id))
54 return false;
55
56 return g_SimplePeerConnection_map[peer_connection_id]->CreateDataChannel();
57 }
58
59 bool CreateOffer(int peer_connection_id) {
60 if (!g_SimplePeerConnection_map.count(peer_connection_id))
61 return false;
62
63 return g_SimplePeerConnection_map[peer_connection_id]->CreateOffer();
64 }
65
66 bool CreateAnswer(int peer_connection_id) {
67 if (!g_SimplePeerConnection_map.count(peer_connection_id))
68 return false;
69
70 return g_SimplePeerConnection_map[peer_connection_id]->CreateAnswer();
71 }
72
73 bool SendDataViaDataChannel(int peer_connection_id, const char* data) {
74 if (!g_SimplePeerConnection_map.count(peer_connection_id))
75 return false;
76
77 std::string s(data);
78 g_SimplePeerConnection_map[peer_connection_id]->SendDataViaDataChannel(s);
79
80 return true;
81 }
82
83 bool SetAudioControl(int peer_connection_id, bool is_mute, bool is_record) {
84 if (!g_SimplePeerConnection_map.count(peer_connection_id))
85 return false;
86
87 g_SimplePeerConnection_map[peer_connection_id]->SetAudioControl(is_mute,
88 is_record);
89 return true;
90 }
91
92 // Register callback functions.
93 bool RegisterOnVideoFramReady(int peer_connection_id,
94 VIDEOFRAMEREADY_CALLBACK callback) {
95 if (!g_SimplePeerConnection_map.count(peer_connection_id))
96 return false;
97
98 g_SimplePeerConnection_map[peer_connection_id]->RegisterOnVideoFramReady(
99 callback);
100 return true;
101 }
102
103 bool RegisterOnLocalDataChannelReady(int peer_connection_id,
104 LOCALDATACHANNELREADY_CALLBACK callback) {
105 if (!g_SimplePeerConnection_map.count(peer_connection_id))
106 return false;
107
108 g_SimplePeerConnection_map[peer_connection_id]
109 ->RegisterOnLocalDataChannelReady(callback);
110 return true;
111 }
112
113 bool RegisterOnDataFromDataChannelReady(
114 int peer_connection_id,
115 DATAFROMEDATECHANNELREADY_CALLBACK callback) {
116 if (!g_SimplePeerConnection_map.count(peer_connection_id))
117 return false;
118
119 g_SimplePeerConnection_map[peer_connection_id]
120 ->RegisterOnDataFromDataChannelReady(callback);
121 return true;
122 }
123
124 bool RegisterOnFailure(int peer_connection_id, FAILURE_CALLBACK callback) {
125 if (!g_SimplePeerConnection_map.count(peer_connection_id))
126 return false;
127
128 g_SimplePeerConnection_map[peer_connection_id]->RegisterOnFailure(callback);
129 return true;
130 }
131
132 bool RegisterOnAudioBusReady(int peer_connection_id,
133 AUDIOBUSREADY_CALLBACK callback) {
134 if (!g_SimplePeerConnection_map.count(peer_connection_id))
135 return false;
136
137 g_SimplePeerConnection_map[peer_connection_id]->RegisterOnAudioBusReady(
138 callback);
139 return true;
140 }
141
142 // Singnaling channel related functions.
143 bool RegisterOnLocalSdpReadytoSend(int peer_connection_id,
144 LOCALSDPREADYTOSEND_CALLBACK callback) {
145 if (!g_SimplePeerConnection_map.count(peer_connection_id))
146 return false;
147
148 g_SimplePeerConnection_map[peer_connection_id]->RegisterOnLocalSdpReadytoSend(
149 callback);
150 return true;
151 }
152
153 bool RegisterOnIceCandiateReadytoSend(
154 int peer_connection_id,
155 ICECANDIDATEREADYTOSEND_CALLBACK callback) {
156 if (!g_SimplePeerConnection_map.count(peer_connection_id))
157 return false;
158
159 g_SimplePeerConnection_map[peer_connection_id]
160 ->RegisterOnIceCandiateReadytoSend(callback);
161 return true;
162 }
163
164 int ReceivedSdp(int peer_connection_id, const char* sdp) {
165 // Create a SimplePeerConnection if no one exists.
166 int id = -1;
167 if (g_SimplePeerConnection_map.count(peer_connection_id)) {
168 id = peer_connection_id;
169 } else {
170 id = g_peer_connection_id++;
171 g_SimplePeerConnection_map[id] =
172 new rtc::RefCountedObject<SimplePeerConnection>();
173 if (!g_SimplePeerConnection_map[id]->InitializePeerConnection(true))
174 return -1;
175 }
176
177 g_SimplePeerConnection_map[id]->ReceivedSdp(sdp);
178 return id;
179 }
180
181 bool ReceivedIceCandidate(int peer_connection_id, const char* ice_candidate) {
182 if (!g_SimplePeerConnection_map.count(peer_connection_id))
183 return false;
184
185 return g_SimplePeerConnection_map[peer_connection_id]->ReceivedIceCandidate(
186 ice_candidate);
187 }
OLDNEW
« no previous file with comments | « webrtc/examples/unityplugin/unity_plugin_apis.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698