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

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

Powered by Google App Engine
This is Rietveld 408576698