-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsession_description.cpp
More file actions
194 lines (147 loc) · 5.03 KB
/
Copy pathsession_description.cpp
File metadata and controls
194 lines (147 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <cstdlib>
#include <cstring>
#include <string>
#include "talk/app/webrtc/jsep.h"
#include "talk/app/webrtc/peerconnectioninterface.h"
#include "constants.h"
#include "ref.h"
#include "session_description.h"
#include "media_constraints_prv.h"
extern "C" {
#include "_cgo_export.h"
using talk_base::scoped_refptr;
using talk_base::RefCountedObject;
using webrtc::PeerConnectionInterface;
void* c_SessionDescription_ToGo(const webrtc::SessionDescriptionInterface* desc);
webrtc::SessionDescriptionInterface* c_SessionDescription_ToWebRTC(
void* desc, webrtc::SdpParseError* error);
class setSessionDescriptionObserver : public webrtc::SetSessionDescriptionObserver {
public:
static scoped_refptr<setSessionDescriptionObserver> Create(Ref ref) {
RefCountedObject<setSessionDescriptionObserver>* implementation =
new RefCountedObject<setSessionDescriptionObserver>(ref);
return implementation;
}
setSessionDescriptionObserver(Ref ref) {
_ref = ref;
}
void OnSuccess() {
go_SetSessionDescription_OnSuccess(_ref);
}
void OnFailure(const std::string& error) {
go_SetSessionDescription_OnFailure(_ref, (char*)error.c_str());
}
protected:
~setSessionDescriptionObserver() {
go_Ref_Unregister(_ref);
}
private:
Ref _ref;
};
class createSessionDescriptionObserver : public webrtc::CreateSessionDescriptionObserver {
public:
static scoped_refptr<createSessionDescriptionObserver> Create(Ref ref) {
RefCountedObject<createSessionDescriptionObserver>* implementation =
new RefCountedObject<createSessionDescriptionObserver>(ref);
return implementation;
}
createSessionDescriptionObserver(Ref ref) {
_ref = ref;
}
void OnSuccess(webrtc::SessionDescriptionInterface* desc) {
go_CreateSessionDescription_OnSuccess(_ref, c_SessionDescription_ToGo(desc));
}
void OnFailure(const std::string& error) {
go_CreateSessionDescription_OnFailure(_ref, (char*)error.c_str());
}
protected:
~createSessionDescriptionObserver() {
go_Ref_Unregister(_ref);
}
private:
Ref _ref;
};
void* c_PeerConnection_GetLocalDescription(void* _pc)
{
if (_pc == NULL) return NULL;
PeerConnectionInterface* pc = (PeerConnectionInterface*)_pc;
return c_SessionDescription_ToGo(pc->local_description());
}
void* c_PeerConnection_GetRemoteDescription(void* _pc)
{
if (_pc == NULL) return NULL;
PeerConnectionInterface* pc = (PeerConnectionInterface*)_pc;
return c_SessionDescription_ToGo(pc->remote_description());
}
char* c_PeerConnection_SetLocalDescription(
void* _pc, Ref _ref, void* _sd)
{
if (_pc == NULL || _sd == NULL) return strdup(errNillNotAllowed);
webrtc::SdpParseError error;
PeerConnectionInterface* pc = (PeerConnectionInterface*)_pc;
webrtc::SessionDescriptionInterface* sd;
sd = c_SessionDescription_ToWebRTC(_sd, &error);
if (sd == NULL) {
return strdup(error.description.c_str());
}
scoped_refptr<setSessionDescriptionObserver> observer =
setSessionDescriptionObserver::Create(_ref);
pc->SetLocalDescription(observer, sd);
return NULL;
}
char* c_PeerConnection_SetRemoteDescription(
void* _pc, Ref _ref, void* _sd)
{
if (_pc == NULL || _sd == NULL) return strdup(errNillNotAllowed);
webrtc::SdpParseError error;
PeerConnectionInterface* pc = (PeerConnectionInterface*)_pc;
webrtc::SessionDescriptionInterface* sd;
sd = c_SessionDescription_ToWebRTC(_sd, &error);
if (sd == NULL) {
return strdup(error.description.c_str());
}
scoped_refptr<setSessionDescriptionObserver> observer =
setSessionDescriptionObserver::Create(_ref);
pc->SetRemoteDescription(observer, sd);
return NULL;
}
void c_PeerConnection_CreateOffer(
void* _pc, Ref _ref,
void* constraints, int nconstraints)
{
if (_pc == NULL) return;
PeerConnectionInterface* pc = (PeerConnectionInterface*)_pc;
void** rconstraints = (void**)constraints;
scoped_refptr<createSessionDescriptionObserver> observer =
createSessionDescriptionObserver::Create(_ref);
pc->CreateOffer(observer,
new MediaConstraints(rconstraints, nconstraints));
}
void c_PeerConnection_CreateAnswer(
void* _pc, Ref _ref,
void* constraints, int nconstraints)
{
if (_pc == NULL) return;
PeerConnectionInterface* pc = (PeerConnectionInterface*)_pc;
void** rconstraints = (void**)constraints;
scoped_refptr<createSessionDescriptionObserver> observer =
createSessionDescriptionObserver::Create(_ref);
pc->CreateAnswer(observer,
new MediaConstraints(rconstraints, nconstraints));
}
void* c_SessionDescription_ToGo(const webrtc::SessionDescriptionInterface* desc)
{
if (desc == NULL) return NULL;
std::string sdp;
std::string type = desc->type();
if (!desc->ToString(&sdp)) return NULL;
return go_SessionDescription_New((char*)type.c_str(), (char*)sdp.c_str());
}
webrtc::SessionDescriptionInterface* c_SessionDescription_ToWebRTC(
void* desc, webrtc::SdpParseError* error)
{
std::string type = go_SessionDescription_GetType(desc);
std::string sdp = go_SessionDescription_GetSdp(desc);
return webrtc::CreateSessionDescription(type, sdp, error);
}
} // extern "C"