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

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

Powered by Google App Engine
This is Rietveld 408576698