-
Notifications
You must be signed in to change notification settings - Fork 36
Add Data Channel support #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: branch-heads/pixiv-m78
Are you sure you want to change the base?
Changes from 63 commits
aff7f49
6cd2dc7
7928b15
2172dfa
8a09967
3e3ea15
7db767e
91079d5
d63efc3
ae621a0
226b6dc
f9f2217
1c644ab
00e174a
809ec51
95aff5b
5a6e66e
096ffcd
d25f927
29bd31c
1457a89
52342cc
14ea6d2
898f36c
3091c06
79cce04
bd345de
b9dfc75
8fc55d0
1001d33
5eafce2
2141efb
72bab18
5cb04b3
7cf67e4
f926444
a4b68f4
d3e504f
8da0703
2cc718f
3ad8f82
164d806
b1d89c9
dad791b
4904566
612e061
6294d57
4121d65
081025d
4da9eaf
783973b
46ed2ee
c5ba7f0
2ebc766
2b63289
7333aad
17f38b4
6868ec8
bcc6712
a740903
a7a234a
b4ae6d7
190bd47
c4d5608
b534d6f
c7a449a
4dba880
4c60739
baef370
ac923d2
17b9bd4
4255836
6be9603
b6e46dd
cb34f26
9c3dbcb
7f9cb99
437a40d
bfff25e
e663995
76ed06e
15179cd
ba03c79
fd161e7
65e1c57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,98 @@ | ||
| /* | ||
| * Copyright 2019 pixiv Inc. All Rights Reserved. | ||
| * Copyright 2019 developerinabox. All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by a license that can be | ||
| * found in the LICENSE.pixiv file in the root of the source tree. | ||
| */ | ||
|
|
||
| #include "sdk/c/api/data_channel_interface.h" | ||
|
|
||
| namespace webrtc { | ||
|
|
||
| class DelegatingDataChannelObserver | ||
| : public DataChannelObserver { | ||
| public: | ||
| DelegatingDataChannelObserver( | ||
| void* context, | ||
| const struct WebrtcDataChannelObserverFunctions* functions) { | ||
| context_ = context; | ||
| functions_ = functions; | ||
| } | ||
|
|
||
| ~DelegatingDataChannelObserver() { | ||
| functions_->on_destruction(context_); | ||
| } | ||
|
|
||
| void OnStateChange() override { | ||
| functions_->on_state_change(context_); | ||
| } | ||
|
|
||
| void OnMessage(const DataBuffer& buffer) override { | ||
| auto * data = buffer.data.data(); | ||
| functions_->on_message(context_, buffer.binary, data, buffer.size()); | ||
| } | ||
|
|
||
| void OnBufferedAmountChange(uint64_t sent_data_size) override { | ||
| functions_->on_buffered_amount_change(context_, sent_data_size); | ||
| } | ||
|
|
||
| private: | ||
| void* context_; | ||
| const struct WebrtcDataChannelObserverFunctions* functions_; | ||
| }; | ||
| } | ||
|
|
||
| RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( | ||
| const WebrtcDataChannelInterface* channel) { | ||
| rtc::ToCplusplus(channel)->Release(); | ||
| } | ||
|
|
||
| RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( | ||
| const WebrtcDataChannelInterface* channel) { | ||
| return rtc::ToC(new auto(rtc::ToCplusplus(channel)->label())); | ||
| } | ||
|
|
||
| RTC_EXPORT extern "C" int webrtcDataChannelStatus( | ||
| const WebrtcDataChannelInterface* channel) { | ||
| auto chan = rtc::ToCplusplus(channel); | ||
| return chan->state(); | ||
| } | ||
|
|
||
| RTC_EXPORT extern "C" bool webrtcDataChannelSendText( | ||
| WebrtcDataChannelInterface* channel, | ||
| const char* text | ||
| ) { | ||
| auto chan = rtc::ToCplusplus(channel); | ||
| const auto db = webrtc::DataBuffer(text); | ||
| return chan->Send(db); | ||
| } | ||
|
|
||
| RTC_EXPORT extern "C" bool webrtcDataChannelSendData( | ||
| WebrtcDataChannelInterface* channel, | ||
| const char* data, | ||
| size_t len | ||
| ) { | ||
| auto chan = rtc::ToCplusplus(channel); | ||
| rtc::CopyOnWriteBuffer writeBuffer(data, len); | ||
| const auto db = webrtc::DataBuffer(writeBuffer, true); | ||
| return chan->Send(db); | ||
| } | ||
|
|
||
| RTC_EXPORT extern "C" WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( | ||
| void* context, | ||
| WebrtcDataChannelInterface* channel, | ||
| const struct WebrtcDataChannelObserverFunctions* functions) { | ||
|
|
||
| auto chan = rtc::ToCplusplus(channel); | ||
| auto obs = new webrtc::DelegatingDataChannelObserver(context, functions); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. It should have a dedicated function, something like |
||
| chan->RegisterObserver(obs); | ||
| auto o = rtc::ToC(obs); | ||
| return o; | ||
| } | ||
|
|
||
| RTC_EXPORT extern "C" void webrtcDataChannelUnregisterObserver( | ||
| WebrtcDataChannelInterface* channel | ||
| ) { | ||
| auto chan = rtc::ToCplusplus(channel); | ||
| chan->UnregisterObserver(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||
| /* | ||||||||||||
| * Copyright 2019 pixiv Inc. All Rights Reserved. | ||||||||||||
| * Copyright 2020 developerinabox. All Rights Reserved. | ||||||||||||
| * | ||||||||||||
| * Use of this source code is governed by a license that can be | ||||||||||||
| * found in the LICENSE.pixiv file in the root of the source tree. | ||||||||||||
|
|
@@ -15,12 +15,43 @@ | |||||||||||
|
|
||||||||||||
| extern "C" { | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| #endif | ||||||||||||
|
|
||||||||||||
| RTC_C_CLASS(webrtc::DataChannelInterface, WebrtcDataChannelInterface) | ||||||||||||
| RTC_C_CLASS(webrtc::DataChannelObserver, WebrtcDataChannelObserver) | ||||||||||||
|
|
||||||||||||
| struct WebrtcDataChannelObserverFunctions { | ||||||||||||
| void (*on_destruction)(void*); | ||||||||||||
| void (*on_state_change)(void*); | ||||||||||||
| void (*on_message)(void*, bool binary, const uint8_t* data, size_t len); | ||||||||||||
| void (*on_buffered_amount_change)(void*, uint64_t); | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| RTC_EXPORT void webrtcDataChannelInterfaceRelease( | ||||||||||||
| const WebrtcDataChannelInterface* channel); | ||||||||||||
|
|
||||||||||||
| RTC_EXPORT RtcString* webrtcDataChannelLabel( | ||||||||||||
| const WebrtcDataChannelInterface* channel); | ||||||||||||
|
|
||||||||||||
| RTC_EXPORT int webrtcDataChannelStatus( | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Follow the naming of the underlying function. It is crucial to make it easy to understand what feature it represents, especially because we do not provide additional documentations for the binding and users have to rely on the counterparts of the C++ APIs. If you think such renaming is strongly preferred, it should be submitted to the upstream and reviewed by its maintainers. |
||||||||||||
| const WebrtcDataChannelInterface* channel); | ||||||||||||
|
|
||||||||||||
| RTC_EXPORT bool webrtcDataChannelSendText( | ||||||||||||
| WebrtcDataChannelInterface* channel, | ||||||||||||
| const char* text); | ||||||||||||
|
|
||||||||||||
| RTC_EXPORT bool webrtcDataChannelSendData( | ||||||||||||
| WebrtcDataChannelInterface* channel, | ||||||||||||
| const char* data, | ||||||||||||
| size_t len); | ||||||||||||
|
|
||||||||||||
| RTC_EXPORT WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( | ||||||||||||
| void* context, | ||||||||||||
| WebrtcDataChannelInterface* channel, | ||||||||||||
| const struct WebrtcDataChannelObserverFunctions* functions); | ||||||||||||
|
|
||||||||||||
| RTC_EXPORT void webrtcDataChannelUnregisterObserver( | ||||||||||||
| WebrtcDataChannelInterface* channel); | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| #ifdef __cplusplus | ||||||||||||
| } | ||||||||||||
| #endif | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,16 +91,25 @@ extern "C" void webrtcDeleteSessionDescriptionInterface( | |
| delete rtc::ToCplusplus(desc); | ||
| } | ||
|
|
||
| extern "C" bool webrtcIceCandidateInterfaceToString( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave |
||
| extern "C" bool webrtcIceCandidateInterfaceResolve( | ||
| const WebrtcIceCandidateInterface* candidate, | ||
| RtcString** out) { | ||
| if (!out) { | ||
| return false; | ||
| } | ||
|
|
||
| RtcString** sdpMid, | ||
| int* sdpMLineIndex, | ||
| RtcString** sdp | ||
| ) { | ||
|
|
||
| auto c = rtc::ToCplusplus(candidate); | ||
|
|
||
| auto i = c->sdp_mline_index(); | ||
| sdpMLineIndex = &i; | ||
|
|
||
| auto g = new std::string(); | ||
| *sdpMid = rtc::ToC(g); | ||
| g->assign(c->sdp_mid()); | ||
|
|
||
| auto s = new std::string(); | ||
| *out = rtc::ToC(s); | ||
| return rtc::ToCplusplus(candidate)->ToString(s); | ||
| *sdp = rtc::ToC(s); | ||
| return c->ToString(s); | ||
| } | ||
|
|
||
| extern "C" WebrtcCreateSessionDescriptionObserver* | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -324,6 +324,18 @@ webrtcPeerConnectionInterfaceAddTrack(WebrtcPeerConnectionInterface* connection, | |||||
| return cresult; | ||||||
| } | ||||||
|
|
||||||
| RTC_EXPORT extern "C" bool | ||||||
| webrtcPeerConnectionInterfaceAddICECandidate(WebrtcPeerConnectionInterface* connection, | ||||||
|
||||||
| const char* sdpMid, | ||||||
|
||||||
| const char* sdpMid, | |
| const char* sdp_mid, |
Follow the style of C++ codes included in the upstream.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webrtc::CreateIceCandidate should have a dedicated C function.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| <Project> | ||
| <PropertyGroup> | ||
| <BaseOutputPath>bin/</BaseOutputPath> | ||
| <Configuration>Debug</Configuration> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not do that. Instead, you should pass |
||
| <Configuration>Release</Configuration> | ||
| <OutputPath>$(BaseOutputPath)$(Configuration)/</OutputPath> | ||
| </PropertyGroup> | ||
| <Import Project="$(MSBuildToolsPath)/Microsoft.Common.targets" /> | ||
|
|
@@ -19,7 +19,7 @@ | |
| <FullOutputPath>$([System.IO.Path]::GetFullPath('$(OutputPath)'))</FullOutputPath> | ||
| <IsDebug Condition="'$(Configuration)' == Debug">true</IsDebug> | ||
| <IsDebug Condition="'$(Configuration)' != Debug">false</IsDebug> | ||
| <Targets>Android;Ios;LinuxX64;MacX64;WinX64</Targets> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also should not happen. |
||
| <Targets>LinuxX64</Targets> | ||
| <ParsibleTargets>;$(Targets);</ParsibleTargets> | ||
| <EscapedFullIntermediateOutputPath>"$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))"</EscapedFullIntermediateOutputPath> | ||
| <EscapedFullOutputPath>$(FullOutputPath.Replace('\', '\\').Replace('"', '\"'))</EscapedFullOutputPath> | ||
|
|
@@ -28,7 +28,7 @@ | |
| <EscapedOutputPath>"$(OutputPath.Replace('\', '\\').Replace('"', '\"'))"</EscapedOutputPath> | ||
| <EscapedTargets>"$(Targets.Replace('\', '\\').Replace('"', '\"'))"</EscapedTargets> | ||
| </PropertyGroup> | ||
| <Target Name="Build" DependsOnTargets="BuildAndroid;BuildIos;BuildLinuxX64;BuildMacX64;BuildWinX64"> | ||
| <Target Name="Build" DependsOnTargets="BuildAndroid;BuildIos;BuildLinuxX64;BuildMacX64;BuildWinX64;BuildWinX86"> | ||
| <Exec Command="../../../tools_webrtc/unity/generate_licenses.py $(EscapedIntermediateOutputPath) $(EscapedOutputPath) $(EscapedTargets.Replace(';', '" "'))" /> | ||
| <Copy | ||
| DestinationFolder="$(OutputPath)" | ||
|
|
@@ -67,26 +67,33 @@ | |
| </Target> | ||
| <Target Condition="$(ParsibleTargets.Contains(';LinuxX64;'))" Name="BuildLinuxX64" DependsOnTargets="BuildExternal"> | ||
| <Exec | ||
| Command="gn gen "--args=is_debug=$(IsDebug) rtc_enable_symbol_export=true target_os=\"linux\" target_cpu=\"x64\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)linux_x64" | ||
| Command="gn gen "--args=is_debug=$(IsDebug) rtc_use_dummy_audio_file_devices=true rtc_enable_symbol_export=true target_os=\"linux\" target_cpu=\"x64\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)linux_x64" | ||
| Condition="!Exists('$(IntermediateOutputPath)linux_x64/build.ninja')" /> | ||
| <Exec Command="ninja -C $(EscapedIntermediateOutputPath)linux_x64 :jingle_peerconnection_so" /> | ||
| <Copy DestinationFolder="$(OutputPath)Runtime" SourceFiles="$(IntermediateOutputPath)linux_x64/libjingle_peerconnection_so.so;$(MSBuildThisFileDirectory)Runtime/libjingle_peerconnection_so.so.meta" /> | ||
| </Target> | ||
| <Target Condition="$(ParsibleTargets.Contains(';MacX64;'))" Name="BuildMacX64" DependsOnTargets="BuildExternal"> | ||
| <Exec | ||
| Command="gn gen "--args=is_debug=$(IsDebug) rtc_enable_symbol_export=true target_os=\"mac\" target_cpu=\"x64\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)mac_x64" | ||
| Command="gn gen "--args=is_debug=$(IsDebug) rtc_use_dummy_audio_file_devices=true rtc_enable_symbol_export=true target_os=\"mac\" target_cpu=\"x64\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)mac_x64" | ||
| Condition="!Exists('$(IntermediateOutputPath)mac_x64/build.ninja')" /> | ||
| <Exec Command="ninja -C $(EscapedIntermediateOutputPath)mac_x64 :jingle_peerconnection_so" /> | ||
| <Copy DestinationFiles="$(OutputPath)Runtime/jingle_peerconnection_so.dylib" SourceFiles="$(IntermediateOutputPath)mac_x64/libjingle_peerconnection_so.dylib" /> | ||
| <Copy DestinationFolder="$(OutputPath)Runtime" SourceFiles="$(MSBuildThisFileDirectory)Runtime/jingle_peerconnection_so.dylib.meta" /> | ||
| </Target> | ||
| <Target Condition="$(ParsibleTargets.Contains(';WinX64;'))" Name="BuildWinX64" DependsOnTargets="BuildExternal"> | ||
| <Exec | ||
| Command="gn gen "--args=is_debug=$(IsDebug) rtc_enable_symbol_export=true target_os=\"win\" target_cpu=\"x64\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)win_x64" | ||
| Command="gn gen "--args=is_debug=$(IsDebug) rtc_use_dummy_audio_file_devices=true rtc_enable_symbol_export=true target_os=\"win\" target_cpu=\"x64\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)win_x64" | ||
| Condition="!Exists('$(IntermediateOutputPath)win_x64/build.ninja')" /> | ||
| <Exec Command="ninja -C $(EscapedIntermediateOutputPath)win_x64 :jingle_peerconnection_so" /> | ||
| <Copy DestinationFolder="$(OutputPath)Runtime" SourceFiles="$(IntermediateOutputPath)win_x64/jingle_peerconnection_so.dll;$(MSBuildThisFileDirectory)Runtime/jingle_peerconnection_so.dll.meta" /> | ||
| </Target> | ||
| <Target Condition="$(ParsibleTargets.Contains(';WinX86;'))" Name="BuildWinX86" DependsOnTargets="BuildExternal"> | ||
|
||
| <Exec | ||
| Command="gn gen "--args=is_debug=$(IsDebug) rtc_use_dummy_audio_file_devices=true rtc_enable_symbol_export=true target_os=\"win\" target_cpu=\"x86\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)win_x86" | ||
| Condition="!Exists('$(IntermediateOutputPath)win_x86/build.ninja')" /> | ||
| <Exec Command="ninja -C $(EscapedIntermediateOutputPath)win_x86 :jingle_peerconnection_so" /> | ||
| <Copy DestinationFolder="$(OutputPath)Runtime/x86" SourceFiles="$(IntermediateOutputPath)win_x86/jingle_peerconnection_so.dll" /> | ||
| </Target> | ||
| <Target Name="Restore"> | ||
| <MSBuild | ||
| Projects="../webrtc/webrtc.csproj" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not short-circuit
webrtc::DataBufferandwebrtc::DataChannelInterface::Send. The strict one-to-one rule of these bindings allow to reuse them for different purposes. For example, the bindings would not serve for your purpose if they were designed to have convenient interfaces for the example Unity project we made. We need you to follow the rule even if it is so troublesome.