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

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: Sync to head 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_peer_connection_map;
22 } // namespace
23
24 int CreatePeerConnection() {
25 g_peer_connection_map[g_peer_connection_id] =
26 new rtc::RefCountedObject<SimplePeerConnection>();
27
28 if (!g_peer_connection_map[g_peer_connection_id]->InitializePeerConnection(
29 false))
30 return -1;
31
32 return g_peer_connection_id++;
33 }
34
35 bool ClosePeerConnection(int peer_connection_id) {
36 if (!g_peer_connection_map.count(peer_connection_id))
37 return false;
38
39 g_peer_connection_map[peer_connection_id]->DeletePeerConnection();
40 g_peer_connection_map.erase(peer_connection_id);
41 return true;
42 }
43
44 bool AddStream(int peer_connection_id, bool audio_only) {
45 if (!g_peer_connection_map.count(peer_connection_id))
46 return false;
47
48 g_peer_connection_map[peer_connection_id]->AddStreams(audio_only);
49 return true;
50 }
51
52 bool AddDataChannel(int peer_connection_id) {
53 if (!g_peer_connection_map.count(peer_connection_id))
54 return false;
55
56 return g_peer_connection_map[peer_connection_id]->CreateDataChannel();
57 }
58
59 bool CreateOffer(int peer_connection_id) {
60 if (!g_peer_connection_map.count(peer_connection_id))
61 return false;
62
63 return g_peer_connection_map[peer_connection_id]->CreateOffer();
64 }
65
66 bool CreateAnswer(int peer_connection_id) {
67 if (!g_peer_connection_map.count(peer_connection_id))
68 return false;
69
70 return g_peer_connection_map[peer_connection_id]->CreateAnswer();
71 }
72
73 bool SendDataViaDataChannel(int peer_connection_id, const char* data) {
74 if (!g_peer_connection_map.count(peer_connection_id))
75 return false;
76
77 std::string s(data);
78 g_peer_connection_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_peer_connection_map.count(peer_connection_id))
85 return false;
86
87 g_peer_connection_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_peer_connection_map.count(peer_connection_id))
96 return false;
97
98 g_peer_connection_map[peer_connection_id]->RegisterOnVideoFramReady(callback);
99 return true;
100 }
101
102 bool RegisterOnLocalDataChannelReady(int peer_connection_id,
103 LOCALDATACHANNELREADY_CALLBACK callback) {
104 if (!g_peer_connection_map.count(peer_connection_id))
105 return false;
106
107 g_peer_connection_map[peer_connection_id]->RegisterOnLocalDataChannelReady(
108 callback);
109 return true;
110 }
111
112 bool RegisterOnDataFromDataChannelReady(
113 int peer_connection_id,
114 DATAFROMEDATECHANNELREADY_CALLBACK callback) {
115 if (!g_peer_connection_map.count(peer_connection_id))
116 return false;
117
118 g_peer_connection_map[peer_connection_id]->RegisterOnDataFromDataChannelReady(
119 callback);
120 return true;
121 }
122
123 bool RegisterOnFailure(int peer_connection_id, FAILURE_CALLBACK callback) {
124 if (!g_peer_connection_map.count(peer_connection_id))
125 return false;
126
127 g_peer_connection_map[peer_connection_id]->RegisterOnFailure(callback);
128 return true;
129 }
130
131 bool RegisterOnAudioBusReady(int peer_connection_id,
132 AUDIOBUSREADY_CALLBACK callback) {
133 if (!g_peer_connection_map.count(peer_connection_id))
134 return false;
135
136 g_peer_connection_map[peer_connection_id]->RegisterOnAudioBusReady(callback);
137 return true;
138 }
139
140 // Singnaling channel related functions.
141 bool RegisterOnLocalSdpReadytoSend(int peer_connection_id,
142 LOCALSDPREADYTOSEND_CALLBACK callback) {
143 if (!g_peer_connection_map.count(peer_connection_id))
144 return false;
145
146 g_peer_connection_map[peer_connection_id]->RegisterOnLocalSdpReadytoSend(
147 callback);
148 return true;
149 }
150
151 bool RegisterOnIceCandiateReadytoSend(
152 int peer_connection_id,
153 ICECANDIDATEREADYTOSEND_CALLBACK callback) {
154 if (!g_peer_connection_map.count(peer_connection_id))
155 return false;
156
157 g_peer_connection_map[peer_connection_id]->RegisterOnIceCandiateReadytoSend(
158 callback);
159 return true;
160 }
161
162 int ReceivedSdp(int peer_connection_id, const char* sdp) {
163 // Create a peer_connection if no one exists.
164 int id = -1;
165 if (g_peer_connection_map.count(peer_connection_id)) {
166 id = peer_connection_id;
167 } else {
168 id = g_peer_connection_id++;
169 g_peer_connection_map[id] =
170 new rtc::RefCountedObject<SimplePeerConnection>();
171 if (!g_peer_connection_map[id]->InitializePeerConnection(true))
172 return -1;
173 }
174
175 g_peer_connection_map[id]->ReceivedSdp(sdp);
176 return id;
177 }
178
179 bool ReceivedIceCandidate(int peer_connection_id, const char* ice_candidate) {
180 if (!g_peer_connection_map.count(peer_connection_id))
181 return false;
182
183 return g_peer_connection_map[peer_connection_id]->ReceivedIceCandidate(
184 ice_candidate);
185 }
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