From aff7f4943498e1088f4f6369570d87fe2fe3a916 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Mon, 30 Mar 2020 14:03:08 +0800 Subject: [PATCH 01/85] fixes --- sdk/c_headers_test.c | 3 --- sdk/dotnet/unity/unity.msbuildproj | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/sdk/c_headers_test.c b/sdk/c_headers_test.c index 073b2f24b7..5bba96b31b 100644 --- a/sdk/c_headers_test.c +++ b/sdk/c_headers_test.c @@ -5,9 +5,6 @@ * found in the LICENSE.pixiv file in the root of the source tree. */ -#include "sdk/c/api/task_queue/queued_task.h" -#include "sdk/c/api/task_queue/task_queue_base.h" -#include "sdk/c/api/task_queue/task_queue_factory.h" #include "sdk/c/api/video/video_buffer.h" #include "sdk/c/api/video/video_frame.h" #include "sdk/c/api/video/video_rotation.h" diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index c4f8832182..6a14241dd8 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -9,7 +9,7 @@ bin/ - Debug + Release $(BaseOutputPath)$(Configuration)/ @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - Android;Ios;LinuxX64;MacX64;WinX64 + LinuxX64;WinX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From 6cd2dc7c315ac73d1b517d66a31e9601f542206d Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 15:04:51 +0800 Subject: [PATCH 02/85] add ice candidate --- sdk/c/api/peer_connection_interface.cc | 12 ++++++++++++ sdk/dotnet/webrtc/api/media_stream_interface.cs | 4 ++-- sdk/dotnet/webrtc/api/peer_connection_interface.cs | 10 +++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/peer_connection_interface.cc b/sdk/c/api/peer_connection_interface.cc index 4a3ff579c7..b9253e2999 100644 --- a/sdk/c/api/peer_connection_interface.cc +++ b/sdk/c/api/peer_connection_interface.cc @@ -324,6 +324,18 @@ webrtcPeerConnectionInterfaceAddTrack(WebrtcPeerConnectionInterface* connection, return cresult; } +RTC_EXPORT extern "C" bool +webrtcPeerConnectionInterfaceAddICECandidate(WebrtcPeerConnectionInterface* connection, + const char* sdpMid, + size_t sdpMLineIndex, + const char* candidate) { + webrtc::SdpParseError error; + webrtc::IceCandidateInterface * can = webrtc::CreateIceCandidate(sdp_mid, sdp_mlineindex, sdp, &error); + + return rtc::ToCplusplus(connection) + ->AddIceCandidate(can); +} + RTC_EXPORT extern "C" void webrtcPeerConnectionInterfaceClose( WebrtcPeerConnectionInterface* connection) { rtc::ToCplusplus(connection)->Close(); diff --git a/sdk/dotnet/webrtc/api/media_stream_interface.cs b/sdk/dotnet/webrtc/api/media_stream_interface.cs index 54aa3cb512..11c07f1a8e 100644 --- a/sdk/dotnet/webrtc/api/media_stream_interface.cs +++ b/sdk/dotnet/webrtc/api/media_stream_interface.cs @@ -338,8 +338,8 @@ private static extern void webrtcAudioTrackSinkInterfaceOnData( IntPtr audioData, int bitsPerSample, int sampleRate, - [MarshalAs(UnmanagedType.SysUInt)] int numberOfChannels, - [MarshalAs(UnmanagedType.SysUInt)] int numberOfFrames + [MarshalAs(UnmanagedType.U4)] int numberOfChannels, + [MarshalAs(UnmanagedType.U4)] int numberOfFrames ); public static void OnData( diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index 5d30fb6a24..8759a1797d 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -849,7 +849,15 @@ private static extern WebrtcAddTrackResult webrtcPeerConnectionInterfaceAddTrack IntPtr connection, IntPtr track, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] string[] data, - [MarshalAs(UnmanagedType.SysUInt)] int size + [MarshalAs(UnmanagedType.U4)] int size + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern bool webrtcPeerConnectionInterfaceAddICECandidate( + IntPtr connection, + [MarshalAs(UnmanagedType.LPStr)] string sdpMid, + [MarshalAs(UnmanagedType.U4)] int sdpMLineIndex, + [MarshalAs(UnmanagedType.LPStr)] string candidate ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] From 7928b1596a32c09c3a20542e66d1ed0fe40552f7 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 15:08:40 +0800 Subject: [PATCH 03/85] fix --- sdk/c/api/peer_connection_interface.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/peer_connection_interface.cc b/sdk/c/api/peer_connection_interface.cc index b9253e2999..533b066c2e 100644 --- a/sdk/c/api/peer_connection_interface.cc +++ b/sdk/c/api/peer_connection_interface.cc @@ -328,12 +328,12 @@ RTC_EXPORT extern "C" bool webrtcPeerConnectionInterfaceAddICECandidate(WebrtcPeerConnectionInterface* connection, const char* sdpMid, size_t sdpMLineIndex, - const char* candidate) { + const char* sdp) { webrtc::SdpParseError error; - webrtc::IceCandidateInterface * can = webrtc::CreateIceCandidate(sdp_mid, sdp_mlineindex, sdp, &error); + webrtc::IceCandidateInterface * candidate = webrtc::CreateIceCandidate(sdpMid, sdpMLineIndex, sdp, &error); return rtc::ToCplusplus(connection) - ->AddIceCandidate(can); + ->AddIceCandidate(candidate); } RTC_EXPORT extern "C" void webrtcPeerConnectionInterfaceClose( From 2172dfa183f85c038ca552f52e0fb001b4ef3fba Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 16:59:32 +0800 Subject: [PATCH 04/85] updates --- sdk/dotnet/webrtc/api/peer_connection_interface.cs | 14 +++++++++++++- sdk/dotnet/webrtc/rtc_base.cs | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index 8759a1797d..c03f9b0a5c 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -857,7 +857,7 @@ private static extern bool webrtcPeerConnectionInterfaceAddICECandidate( IntPtr connection, [MarshalAs(UnmanagedType.LPStr)] string sdpMid, [MarshalAs(UnmanagedType.U4)] int sdpMLineIndex, - [MarshalAs(UnmanagedType.LPStr)] string candidate + [MarshalAs(UnmanagedType.LPStr)] string sdp ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] @@ -924,6 +924,18 @@ public static RtcErrorOr AddTrack( return new RtcErrorOr(error, value); } + public static bool AddICECandidate(this IPeerConnectionInterface connection, + string sdpMid, + int sdpMlineIndex, + string sdp) + { + var result = webrtcPeerConnectionInterfaceAddICECandidate( + connection.Ptr, sdpMid, sdpMlineIndex, sdp); + + return result; + } + + public static void Close(this IPeerConnectionInterface connection) { webrtcPeerConnectionInterfaceClose(connection.Ptr); diff --git a/sdk/dotnet/webrtc/rtc_base.cs b/sdk/dotnet/webrtc/rtc_base.cs index 36869809bc..73ea8d26e0 100644 --- a/sdk/dotnet/webrtc/rtc_base.cs +++ b/sdk/dotnet/webrtc/rtc_base.cs @@ -137,6 +137,10 @@ internal DisposablePtr() ~DisposablePtr() { + if (_ptr == IntPtr.Zero) + { + return; + } FreePtr(); } From 8a0996710581885c3da0c7e22ac974ebca5521fe Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 19:26:39 +0800 Subject: [PATCH 05/85] Add resolve method to ice candidate --- sdk/c/api/jsep.cc | 23 +++++++++++++++++------ sdk/dotnet/webrtc/api/jsep.cs | 17 ++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 29da980bff..7ca6f05a0c 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -91,13 +91,24 @@ extern "C" void webrtcDeleteSessionDescriptionInterface( delete rtc::ToCplusplus(desc); } -extern "C" bool webrtcIceCandidateInterfaceToString( +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 _sdpMid = new std::string(); + int _sdpMLineIndex = new std::int32_t(); + auto _sdp = new std::string(); + *sdpMid = rtc::ToC(_sdpMid); + *sdpMLineIndex = rtc::ToC(_sdpMLineIndex); + *sdp = rtc::ToC(_sdp); + + c->ToString(_sdpMid); + _sdpMLineIndex = c->sdp_mline_index; + c->ToString(_sdp); auto s = new std::string(); *out = rtc::ToC(s); return rtc::ToCplusplus(candidate)->ToString(s); diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 2c99089e1d..6b42269832 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -240,18 +240,21 @@ public IceCandidateInterface(IntPtr ptr) public static class IceCandidateInterfaceExtension { [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern bool webrtcIceCandidateInterfaceToString( + private static extern bool webrtcIceCandidateInterfaceResolve( IntPtr ptr, - out IntPtr result + out IntPtr sdpMid, + out int sdpMLineIndex, + out IntPtr sdp ); - public static bool TryToString( - this IIceCandidateInterface candidate, out string s) + public static bool Resolve( + this IIceCandidateInterface candidate, out string sdpMid, out int sdpMLineIndex, out string sdp) { - var result = webrtcIceCandidateInterfaceToString( - candidate.Ptr, out var webrtcString); + var result = webrtcIceCandidateInterfaceResolve( + candidate.Ptr, out var _sdpMid, out sdpMLineIndex, out var _sdp); - s = Rtc.Interop.String.MoveToString(webrtcString); + sdpMid = Rtc.Interop.String.MoveToString(_sdpMid); + sdp = Rtc.Interop.String.MoveToString(_sdp); return result; } From 3e3ea15cf60722fd8a1c2a4d0d3610cac60d3e1e Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 19:29:10 +0800 Subject: [PATCH 06/85] fixes --- sdk/c/api/jsep.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 7ca6f05a0c..5c727f9111 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -100,7 +100,7 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( auto c = rtc::ToCplusplus(candidate); auto _sdpMid = new std::string(); - int _sdpMLineIndex = new std::int32_t(); + int _sdpMLineIndex; auto _sdp = new std::string(); *sdpMid = rtc::ToC(_sdpMid); *sdpMLineIndex = rtc::ToC(_sdpMLineIndex); @@ -108,10 +108,8 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( c->ToString(_sdpMid); _sdpMLineIndex = c->sdp_mline_index; - c->ToString(_sdp); - auto s = new std::string(); - *out = rtc::ToC(s); - return rtc::ToCplusplus(candidate)->ToString(s); + + return c->ToString(_sdp); } extern "C" WebrtcCreateSessionDescriptionObserver* From 7db767e536575edda1e45c823f53673800c4e60e Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 19:52:17 +0800 Subject: [PATCH 07/85] try again --- sdk/c/api/jsep.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 5c727f9111..55085ddd13 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -99,17 +99,12 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( ) { auto c = rtc::ToCplusplus(candidate); - auto _sdpMid = new std::string(); - int _sdpMLineIndex; - auto _sdp = new std::string(); - *sdpMid = rtc::ToC(_sdpMid); - *sdpMLineIndex = rtc::ToC(_sdpMLineIndex); - *sdp = rtc::ToC(_sdp); + *sdpMLineIndex = c->sdp_mline_index(); + *sdpMid = rtc::ToC(c->sdp_mid()); - c->ToString(_sdpMid); - _sdpMLineIndex = c->sdp_mline_index; - - return c->ToString(_sdp); + auto s = new std::string(); + *sdp = rtc::ToC(s); + return c->ToString(s); } extern "C" WebrtcCreateSessionDescriptionObserver* From 91079d52cb2ddecaf3b4e315af3e3e77c3a0b7c1 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 20:19:47 +0800 Subject: [PATCH 08/85] try2 --- sdk/c/api/jsep.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 55085ddd13..02bfab30ae 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -99,8 +99,9 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( ) { auto c = rtc::ToCplusplus(candidate); - *sdpMLineIndex = c->sdp_mline_index(); - *sdpMid = rtc::ToC(c->sdp_mid()); + *sdpMLineIndex = &c->sdp_mline_index(); + auto g = &c->sdp_mid(); + *sdpMid = rtc::ToC(g); auto s = new std::string(); *sdp = rtc::ToC(s); From d63efc3fbbc4da8995578130804ddd729deda1eb Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 20:22:16 +0800 Subject: [PATCH 09/85] try 3 --- sdk/c/api/jsep.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 02bfab30ae..dad090c15e 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -99,9 +99,11 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( ) { auto c = rtc::ToCplusplus(candidate); - *sdpMLineIndex = &c->sdp_mline_index(); - auto g = &c->sdp_mid(); - *sdpMid = rtc::ToC(g); + auto i = c->sdp_mline_index(); + *sdpMLineIndex = &i; + + auto g = c->sdp_mid(); + *sdpMid = rtc::ToC(&g); auto s = new std::string(); *sdp = rtc::ToC(s); From ae621a0e168b3a1dddac7822680cb3be68af356c Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 20:28:23 +0800 Subject: [PATCH 10/85] m --- sdk/c/api/jsep.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/jsep.h b/sdk/c/api/jsep.h index 20e42ec1a4..d165a55d05 100644 --- a/sdk/c/api/jsep.h +++ b/sdk/c/api/jsep.h @@ -60,9 +60,11 @@ RTC_EXPORT void webrtcCreateSessionDescriptionObserverRelease( RTC_EXPORT void webrtcDeleteSessionDescriptionInterface( WebrtcSessionDescriptionInterface* desc); -RTC_EXPORT bool webrtcIceCandidateInterfaceToString( +RTC_EXPORT bool webrtcIceCandidateInterfaceResolve( const WebrtcIceCandidateInterface* candidate, - RtcString** out); + RtcString** sdpMid, + int ** sdpMLineIndex, + RtcString** sdp); RTC_EXPORT WebrtcCreateSessionDescriptionObserver* webrtcNewCreateSessionDescriptionObserver( From 226b6dce376d26818bd530f07bf6f25df69011b0 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 20:43:40 +0800 Subject: [PATCH 11/85] xcv --- sdk/c/api/jsep.cc | 4 ++-- sdk/c/api/jsep.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index dad090c15e..19169d1c0e 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -94,13 +94,13 @@ extern "C" void webrtcDeleteSessionDescriptionInterface( extern "C" bool webrtcIceCandidateInterfaceResolve( const WebrtcIceCandidateInterface* candidate, RtcString** sdpMid, - int** sdpMLineIndex, + int* sdpMLineIndex, RtcString** sdp ) { auto c = rtc::ToCplusplus(candidate); auto i = c->sdp_mline_index(); - *sdpMLineIndex = &i; + sdpMLineIndex = &i; auto g = c->sdp_mid(); *sdpMid = rtc::ToC(&g); diff --git a/sdk/c/api/jsep.h b/sdk/c/api/jsep.h index d165a55d05..c89a07fafc 100644 --- a/sdk/c/api/jsep.h +++ b/sdk/c/api/jsep.h @@ -63,7 +63,7 @@ RTC_EXPORT void webrtcDeleteSessionDescriptionInterface( RTC_EXPORT bool webrtcIceCandidateInterfaceResolve( const WebrtcIceCandidateInterface* candidate, RtcString** sdpMid, - int ** sdpMLineIndex, + int* sdpMLineIndex, RtcString** sdp); RTC_EXPORT WebrtcCreateSessionDescriptionObserver* From f9f2217fc33b6a837cc2278a0c38155426971e18 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 21:12:23 +0800 Subject: [PATCH 12/85] a --- sdk/c/api/jsep.cc | 6 ++++-- sdk/dotnet/unity/unity.msbuildproj | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 19169d1c0e..3ad1568a9e 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -99,11 +99,13 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( ) { auto c = rtc::ToCplusplus(candidate); + auto i = c->sdp_mline_index(); sdpMLineIndex = &i; - auto g = c->sdp_mid(); - *sdpMid = rtc::ToC(&g); + auto g = new std::string(); + g = c->sdp_mid(); + *sdpMid = rtc::ToC(g); auto s = new std::string(); *sdp = rtc::ToC(s); diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 6a14241dd8..5e035e7e18 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;WinX64 + WinX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From 1c644abee167bc12d355e63957ca9084a6a3707e Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 21:40:31 +0800 Subject: [PATCH 13/85] a --- sdk/c/api/jsep.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 3ad1568a9e..58663280da 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -103,10 +103,12 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( auto i = c->sdp_mline_index(); sdpMLineIndex = &i; - auto g = new std::string(); - g = c->sdp_mid(); - *sdpMid = rtc::ToC(g); - + auto g = c->sdp_mid(); + if (g.empty()) { + g = ""; + } + *sdpMid = rtc::ToC(&g); + auto s = new std::string(); *sdp = rtc::ToC(s); return c->ToString(s); From 00e174a4b6a0161e86a75f31cabf818d2c372467 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 21:49:32 +0800 Subject: [PATCH 14/85] a --- sdk/c/api/jsep.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 58663280da..3700807483 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -103,12 +103,10 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( auto i = c->sdp_mline_index(); sdpMLineIndex = &i; - auto g = c->sdp_mid(); - if (g.empty()) { - g = ""; - } - *sdpMid = rtc::ToC(&g); - + auto g = new std::string(); + *sdpMid = rtc::ToC(g); + g.assign(c->sdp_mid()); + auto s = new std::string(); *sdp = rtc::ToC(s); return c->ToString(s); From 809ec5189ea70500c82da50d6c99e51d3150b2af Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 1 Apr 2020 21:50:23 +0800 Subject: [PATCH 15/85] h --- sdk/c/api/jsep.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 3700807483..20857f8763 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -105,7 +105,7 @@ extern "C" bool webrtcIceCandidateInterfaceResolve( auto g = new std::string(); *sdpMid = rtc::ToC(g); - g.assign(c->sdp_mid()); + g->assign(c->sdp_mid()); auto s = new std::string(); *sdp = rtc::ToC(s); From 95aff5b4445962d51f4d198f9ba6d5b16d66bfe7 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 15:32:41 +0800 Subject: [PATCH 16/85] datachannel stuff --- sdk/c/api/data_channel_interface.cc | 7 +++ sdk/c/api/data_channel_interface.h | 3 ++ .../webrtc/api/data_channel_interface.cs | 21 ++++++-- sdk/dotnet/webrtc/api/jsep.cs | 48 +++++++++++++++++++ sdk/dotnet/webrtc/api/rtc_databuffer.cs | 42 ++++++++++++++++ 5 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 sdk/dotnet/webrtc/api/rtc_databuffer.cs diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 75bf7fa36b..5e4c0d4e0a 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -7,7 +7,14 @@ #include "sdk/c/api/data_channel_interface.h" + + RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel) { rtc::ToCplusplus(channel)->Release(); } + +extern "C" RtcString* WebrtcDataChannelLabel( + const WebrtcDataChannelInterface* channel) { + return rtc::ToC(new auto(rtc::ToCplusplus(channel)->label())); +} diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index c929bf619f..36649d7a22 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -18,6 +18,9 @@ extern "C" { RTC_C_CLASS(webrtc::DataChannelInterface, WebrtcDataChannelInterface) +RTC_EXPORT RtcString* webrtcDataChannelLabel( + const WebrtcDataChannelInterface* channel); + RTC_EXPORT void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel); diff --git a/sdk/dotnet/webrtc/api/data_channel_interface.cs b/sdk/dotnet/webrtc/api/data_channel_interface.cs index 76cf3a88b1..7a1c80ba0e 100644 --- a/sdk/dotnet/webrtc/api/data_channel_interface.cs +++ b/sdk/dotnet/webrtc/api/data_channel_interface.cs @@ -3,8 +3,8 @@ * * 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. - */ - + */ +using Pixiv.Rtc; using System; using System.Runtime.InteropServices; @@ -21,7 +21,7 @@ public interface IDisposableDataChannelInterface : } public sealed class DisposableDataChannelInterface : - Rtc.DisposablePtr, IDisposableDataChannelInterface + DisposablePtr, IDisposableDataChannelInterface { IntPtr IDataChannelInterface.Ptr => Ptr; @@ -33,8 +33,21 @@ internal DisposableDataChannelInterface(IntPtr ptr) private protected override void FreePtr() { Interop.DataChannelInterface.Release(Ptr); - } + } } + public static class DataChannelInterfaceExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcDataChannelLabel( + IntPtr ptr + ); + + public static string Label(this IDisposableDataChannelInterface channel) + { + return Rtc.Interop.String.MoveToString( + webrtcDataChannelLabel(channel.Ptr)); + } + } } namespace Pixiv.Webrtc.Interop diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 6b42269832..639d600fa7 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -23,11 +23,21 @@ public interface ICreateSessionDescriptionObserver IntPtr Ptr { get; } } + public interface IDataChannelObserver + { + IntPtr Ptr { get; } + } + public interface IDisposableCreateSessionDescriptionObserver : ICreateSessionDescriptionObserver, Rtc.IDisposable { } + public interface IDisposableDataChannelObserver : + IDataChannelObserver, Rtc.IDisposable + { + } + public interface IDisposableIceCandidateInterface : IIceCandidateInterface, Rtc.IDisposable { @@ -54,6 +64,13 @@ public interface IManagedCreateSessionDescriptionObserver void OnFailure(RtcError error); } + public interface IManagedDataChannelObserver + { + void OnStateChange(DisposableDataChannelInterface desc); + + + } + public interface IManagedSetSessionDescriptionObserver { void OnSuccess(); @@ -70,6 +87,31 @@ public interface ISetSessionDescriptionObserver IntPtr Ptr { get; } } + public sealed class DisposableDataChannelObserver: DisposablePtr, IDisposableDataChannelObserver + { + IntPtr IDataChannelObserver.Ptr => Ptr; + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void DestructionHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void StateChangeHandler(IntPtr context, IntPtr state); + + [MonoPInvokeCallback(typeof(StateChangeHandler))] + private static void OnStateChange(IntPtr context, IntPtr state) + { + var handle = (GCHandle)context; + + ((IManagedDataChannelObserver)handle.Target).OnStateChange( + new DisposableDataChannelInterface(state) + ); + } + private protected override void FreePtr() + { + Interop.DataChannelObserver.Release(Ptr); + } + } + public sealed class DisposableCreateSessionDescriptionObserver : DisposablePtr, IDisposableCreateSessionDescriptionObserver { @@ -312,6 +354,12 @@ public static class CreateSessionDescriptionObserver public static extern void Release(IntPtr ptr); } + public static class DataChannelObserver + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] + public static extern void Release(IntPtr ptr); + } + public static class SessionDescriptionInterface { [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteSessionDescriptionInterface")] diff --git a/sdk/dotnet/webrtc/api/rtc_databuffer.cs b/sdk/dotnet/webrtc/api/rtc_databuffer.cs new file mode 100644 index 0000000000..cce80eeaef --- /dev/null +++ b/sdk/dotnet/webrtc/api/rtc_databuffer.cs @@ -0,0 +1,42 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace Pixiv.Webrtc +{ + public readonly struct RTCDataBuffer { + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcRTCDataChannelMessage(IntPtr ptr, out int len); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern bool webrtcRTCDataChannelMessageIsBinary(IntPtr ptr); + + public bool isBinary { get; } + public byte[] Data { get; } + public string Text { get; } + + public RTCDataBuffer(IntPtr ptr) + { + int len; + var messagePtr = webrtcRTCDataChannelMessage(ptr, out len); + isBinary = webrtcRTCDataChannelMessageIsBinary(ptr); + Data = new byte[len]; + Marshal.Copy(messagePtr, Data, 0, len); + Text = ""; + if (!isBinary) + { + Text = UTF8Encoding.UTF8.GetString(Data); + } + } + } +} + +namespace Pixiv.Webrtc.Interop +{ + public static class RtcDataBuffer + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteRTCDataBuffer")] + public static extern void Delete(IntPtr ptr); + } +} From 5a6e66e217bfd728f8a3ed631f80bbd83b2e6f0d Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 15:39:33 +0800 Subject: [PATCH 17/85] a --- sdk/c/api/data_channel_interface.cc | 2 +- sdk/c/api/data_channel_interface.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 5e4c0d4e0a..ce132dbbc3 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -14,7 +14,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( rtc::ToCplusplus(channel)->Release(); } -extern "C" RtcString* WebrtcDataChannelLabel( +RTC_EXPORT extern "C" RtcString* WebrtcDataChannelLabel( const WebrtcDataChannelInterface* channel) { return rtc::ToC(new auto(rtc::ToCplusplus(channel)->label())); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 36649d7a22..d7fe297742 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -20,7 +20,7 @@ RTC_C_CLASS(webrtc::DataChannelInterface, WebrtcDataChannelInterface) RTC_EXPORT RtcString* webrtcDataChannelLabel( const WebrtcDataChannelInterface* channel); - + RTC_EXPORT void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel); From 096ffcdb58232fb5e0f6f53480432f0e91057632 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 15:45:33 +0800 Subject: [PATCH 18/85] cap W --- sdk/c/api/data_channel_interface.cc | 2 +- sdk/c/api/data_channel_interface.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index ce132dbbc3..9508b933db 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -14,7 +14,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( rtc::ToCplusplus(channel)->Release(); } -RTC_EXPORT extern "C" RtcString* WebrtcDataChannelLabel( +RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( const WebrtcDataChannelInterface* channel) { return rtc::ToC(new auto(rtc::ToCplusplus(channel)->label())); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index d7fe297742..c9ae67f6ae 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -18,10 +18,10 @@ extern "C" { RTC_C_CLASS(webrtc::DataChannelInterface, WebrtcDataChannelInterface) -RTC_EXPORT RtcString* webrtcDataChannelLabel( +RTC_EXPORT void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel); -RTC_EXPORT void webrtcDataChannelInterfaceRelease( +RTC_EXPORT RtcString* webrtcDataChannelLabel( const WebrtcDataChannelInterface* channel); #ifdef __cplusplus From d25f92786727152faca28d61ec5bc3580b8d6685 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 16:25:44 +0800 Subject: [PATCH 19/85] add status --- sdk/c/api/data_channel_interface.cc | 7 +++++-- sdk/c/api/data_channel_interface.h | 3 +++ sdk/dotnet/webrtc/api/data_channel_interface.cs | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 9508b933db..72b5e07988 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -7,8 +7,6 @@ #include "sdk/c/api/data_channel_interface.h" - - RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel) { rtc::ToCplusplus(channel)->Release(); @@ -18,3 +16,8 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( const WebrtcDataChannelInterface* channel) { return rtc::ToC(new auto(rtc::ToCplusplus(channel)->label())); } + +RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( + const WebrtcDataChannelInterface* channel) { + return rtc::ToC(new auto(rtc::ToCplusplus(channel)->DataStateString())); +} diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index c9ae67f6ae..51b90ead79 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -24,6 +24,9 @@ RTC_EXPORT void webrtcDataChannelInterfaceRelease( RTC_EXPORT RtcString* webrtcDataChannelLabel( const WebrtcDataChannelInterface* channel); +RTC_EXPORT RtcString* webrtcDataChannelStatus( + const WebrtcDataChannelInterface* channel); + #ifdef __cplusplus } #endif diff --git a/sdk/dotnet/webrtc/api/data_channel_interface.cs b/sdk/dotnet/webrtc/api/data_channel_interface.cs index 7a1c80ba0e..da143d11d9 100644 --- a/sdk/dotnet/webrtc/api/data_channel_interface.cs +++ b/sdk/dotnet/webrtc/api/data_channel_interface.cs @@ -40,13 +40,24 @@ public static class DataChannelInterfaceExtension [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr webrtcDataChannelLabel( IntPtr ptr - ); + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcDataChannelStatus( + IntPtr ptr + ); public static string Label(this IDisposableDataChannelInterface channel) { return Rtc.Interop.String.MoveToString( webrtcDataChannelLabel(channel.Ptr)); } + + public static string Status(this IDisposableDataChannelInterface channel) + { + return Rtc.Interop.String.MoveToString( + webrtcDataChannelStatus(channel.Ptr)); + } } } From 29bd31c63611679db2253261d8440c153d9fd933 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 16:33:13 +0800 Subject: [PATCH 20/85] a --- sdk/c/api/data_channel_interface.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 72b5e07988..764fa678ac 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -19,5 +19,5 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel) { - return rtc::ToC(new auto(rtc::ToCplusplus(channel)->DataStateString())); + return rtc::ToC(new auto(rtc::ToCplusplus(WebrtcDataChannelInterface->DataStateString(channel->state())))); } From 1457a8926806b6165c4a901931f1a0b3b28fc498 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 16:35:15 +0800 Subject: [PATCH 21/85] a --- sdk/c/api/data_channel_interface.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 764fa678ac..a997371e22 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -19,5 +19,5 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel) { - return rtc::ToC(new auto(rtc::ToCplusplus(WebrtcDataChannelInterface->DataStateString(channel->state())))); + return rtc::ToC(new auto(WebrtcDataChannelInterface->DataStateString(rtc::ToCplusplus(channel)->state()))); } From 52342cc5312bf4e9974a45a47af6a65431773272 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 16:44:28 +0800 Subject: [PATCH 22/85] a --- sdk/c/api/data_channel_interface.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index a997371e22..82069ebd9e 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -19,5 +19,7 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel) { - return rtc::ToC(new auto(WebrtcDataChannelInterface->DataStateString(rtc::ToCplusplus(channel)->state()))); + auto chan = rtc::ToCplusplus(channel); + auto sState = chan->DataStateString(chan->state()); + return rtc::ToC(std::string(sState)); } From 14ea6d23df4cb81e829e787b5cebd8484872b7e5 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 16:45:11 +0800 Subject: [PATCH 23/85] b --- sdk/c/api/data_channel_interface.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 82069ebd9e..20941a884c 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -21,5 +21,5 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel) { auto chan = rtc::ToCplusplus(channel); auto sState = chan->DataStateString(chan->state()); - return rtc::ToC(std::string(sState)); + return rtc::ToC(new std::string(sState)); } From 898f36c3d96580253f0fd136d941b80ad08fc05c Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:20:10 +0800 Subject: [PATCH 24/85] send data --- sdk/c/api/data_channel_interface.cc | 19 +++++++++++++ sdk/c/api/data_channel_interface.h | 10 +++++++ .../webrtc/api/data_channel_interface.cs | 28 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 20941a884c..9da06a29ab 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -23,3 +23,22 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( auto sState = chan->DataStateString(chan->state()); return rtc::ToC(new std::string(sState)); } + +RTC_EXPORT extern "C" bool webrtcDataChannelSendText( + const WebrtcDataChannelInterface* channel, + const char* text + ) { + auto chan = rtc::ToCplusplus(channel); + return chan->Send(webrtc::DataBuffer(text)); +} + +RTC_EXPORT extern "C" bool webrtcDataChannelSendData( + const WebrtcDataChannelInterface* channel, + const void* data, + size_t len + ) { + auto chan = rtc::ToCplusplus(channel); + rtc::CopyOnWriteBuffer writeBuffer(data, len); + return chan->Send(webrtc::DataBuffer(writeBuffer, true)); +} + diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 51b90ead79..8be81ed7d2 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -27,6 +27,16 @@ RTC_EXPORT RtcString* webrtcDataChannelLabel( RTC_EXPORT RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel); +RTC_EXPORT bool webrtcDataChannelSendText( + const WebrtcDataChannelInterface* channel, + const char* text); + +RTC_EXPORT RtcString* webrtcDataChannelSendData( + const WebrtcDataChannelInterface* channel, + const void* data, + size_t len); + + #ifdef __cplusplus } #endif diff --git a/sdk/dotnet/webrtc/api/data_channel_interface.cs b/sdk/dotnet/webrtc/api/data_channel_interface.cs index da143d11d9..1d8085161d 100644 --- a/sdk/dotnet/webrtc/api/data_channel_interface.cs +++ b/sdk/dotnet/webrtc/api/data_channel_interface.cs @@ -47,6 +47,16 @@ private static extern IntPtr webrtcDataChannelStatus( IntPtr ptr ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern bool webrtcDataChannelSendText( + IntPtr ptr, string text + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern bool webrtcDataChannelSendData( + IntPtr ptr, IntPtr data, int len + ); + public static string Label(this IDisposableDataChannelInterface channel) { return Rtc.Interop.String.MoveToString( @@ -58,6 +68,24 @@ public static string Status(this IDisposableDataChannelInterface channel) return Rtc.Interop.String.MoveToString( webrtcDataChannelStatus(channel.Ptr)); } + + public static bool Send(this IDisposableDataChannelInterface channel, byte[] data) + { + var handle = GCHandle.Alloc(data, GCHandleType.Pinned); + try + { + return webrtcDataChannelSendData(channel.Ptr, handle.AddrOfPinnedObject(), data.Length); + } + finally + { + handle.Free(); + } + } + + public static bool Send(this IDisposableDataChannelInterface channel, string text) + { + return webrtcDataChannelSendText(channel.Ptr, text); + } } } From 3091c066ce18a6c04ef91a24f43a891f4e1e2962 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:26:21 +0800 Subject: [PATCH 25/85] send updates --- sdk/c/api/data_channel_interface.cc | 10 ++++++---- sdk/c/api/data_channel_interface.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 9da06a29ab..8ec39713a6 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -29,16 +29,18 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendText( const char* text ) { auto chan = rtc::ToCplusplus(channel); - return chan->Send(webrtc::DataBuffer(text)); + auto db = webrtc::DataBuffer(text); + return chan->Send(&db); } RTC_EXPORT extern "C" bool webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, - const void* data, + const char* data, size_t len ) { auto chan = rtc::ToCplusplus(channel); - rtc::CopyOnWriteBuffer writeBuffer(data, len); - return chan->Send(webrtc::DataBuffer(writeBuffer, true)); + auto writeBuffer(data, len); + auto db = webrtc::DataBuffer(writeBuffer, true); + return chan->Send(&db); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 8be81ed7d2..2cd141c6fd 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -33,7 +33,7 @@ RTC_EXPORT bool webrtcDataChannelSendText( RTC_EXPORT RtcString* webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, - const void* data, + const char* data, size_t len); From 79cce047d78c7255ffc0765cf1a34407f46b2107 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:34:05 +0800 Subject: [PATCH 26/85] a --- sdk/c/api/data_channel_interface.cc | 2 +- sdk/c/api/data_channel_interface.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 8ec39713a6..6ef011de12 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -40,7 +40,7 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendData( ) { auto chan = rtc::ToCplusplus(channel); auto writeBuffer(data, len); - auto db = webrtc::DataBuffer(writeBuffer, true); + const webrtc::DataBuffer db = webrtc::DataBuffer(writeBuffer, true); return chan->Send(&db); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 2cd141c6fd..e2fdf81c16 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -31,7 +31,7 @@ RTC_EXPORT bool webrtcDataChannelSendText( const WebrtcDataChannelInterface* channel, const char* text); -RTC_EXPORT RtcString* webrtcDataChannelSendData( +RTC_EXPORT bool webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, const char* data, size_t len); From bd345debf4671c867b6b787ab409c0718592c903 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:38:25 +0800 Subject: [PATCH 27/85] c --- sdk/c/api/data_channel_interface.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 6ef011de12..04bb3eaabe 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -39,7 +39,7 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendData( size_t len ) { auto chan = rtc::ToCplusplus(channel); - auto writeBuffer(data, len); + rtc::CopyOnWriteBuffer writeBuffer(data, len); const webrtc::DataBuffer db = webrtc::DataBuffer(writeBuffer, true); return chan->Send(&db); } From b9dfc75a2f6be870149810cf229745199b7583cc Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:43:03 +0800 Subject: [PATCH 28/85] d --- sdk/c/api/data_channel_interface.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 04bb3eaabe..1acf8c2f9b 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -30,7 +30,8 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendText( ) { auto chan = rtc::ToCplusplus(channel); auto db = webrtc::DataBuffer(text); - return chan->Send(&db); + auto res = chan->Send(&db); + return res; } RTC_EXPORT extern "C" bool webrtcDataChannelSendData( @@ -41,6 +42,8 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendData( auto chan = rtc::ToCplusplus(channel); rtc::CopyOnWriteBuffer writeBuffer(data, len); const webrtc::DataBuffer db = webrtc::DataBuffer(writeBuffer, true); - return chan->Send(&db); + auto res = chan->Send(&db); + return res; + } From 8fc55d073311b0f3a4e0e11c89d08ff6f466255c Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:46:29 +0800 Subject: [PATCH 29/85] d --- sdk/c/api/data_channel_interface.cc | 10 ++++------ sdk/c/api/data_channel_interface.h | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 1acf8c2f9b..0feeeffaf4 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -24,17 +24,16 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( return rtc::ToC(new std::string(sState)); } -RTC_EXPORT extern "C" bool webrtcDataChannelSendText( +RTC_EXPORT extern "C" const bool webrtcDataChannelSendText( const WebrtcDataChannelInterface* channel, const char* text ) { auto chan = rtc::ToCplusplus(channel); auto db = webrtc::DataBuffer(text); - auto res = chan->Send(&db); - return res; + return chan->Send(&db); } -RTC_EXPORT extern "C" bool webrtcDataChannelSendData( +RTC_EXPORT extern "C" const bool webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, const char* data, size_t len @@ -42,8 +41,7 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendData( auto chan = rtc::ToCplusplus(channel); rtc::CopyOnWriteBuffer writeBuffer(data, len); const webrtc::DataBuffer db = webrtc::DataBuffer(writeBuffer, true); - auto res = chan->Send(&db); - return res; + return chan->Send(&db); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index e2fdf81c16..91c9701c4e 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -27,11 +27,11 @@ RTC_EXPORT RtcString* webrtcDataChannelLabel( RTC_EXPORT RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel); -RTC_EXPORT bool webrtcDataChannelSendText( +RTC_EXPORT const bool webrtcDataChannelSendText( const WebrtcDataChannelInterface* channel, const char* text); -RTC_EXPORT bool webrtcDataChannelSendData( +RTC_EXPORT const bool webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, const char* data, size_t len); From 1001d33b5447b43ce5b6257b0ac7102a39a7139c Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:50:31 +0800 Subject: [PATCH 30/85] g --- sdk/c/api/data_channel_interface.cc | 4 ++-- sdk/c/api/data_channel_interface.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 0feeeffaf4..6833582c9a 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -24,7 +24,7 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( return rtc::ToC(new std::string(sState)); } -RTC_EXPORT extern "C" const bool webrtcDataChannelSendText( +RTC_EXPORT extern "C" bool webrtcDataChannelSendText( const WebrtcDataChannelInterface* channel, const char* text ) { @@ -33,7 +33,7 @@ RTC_EXPORT extern "C" const bool webrtcDataChannelSendText( return chan->Send(&db); } -RTC_EXPORT extern "C" const bool webrtcDataChannelSendData( +RTC_EXPORT extern "C" bool webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, const char* data, size_t len diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 91c9701c4e..e2fdf81c16 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -27,11 +27,11 @@ RTC_EXPORT RtcString* webrtcDataChannelLabel( RTC_EXPORT RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel); -RTC_EXPORT const bool webrtcDataChannelSendText( +RTC_EXPORT bool webrtcDataChannelSendText( const WebrtcDataChannelInterface* channel, const char* text); -RTC_EXPORT const bool webrtcDataChannelSendData( +RTC_EXPORT bool webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, const char* data, size_t len); From 5eafce27a9604d63a6bf09b62c64e713c919f0d8 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:54:14 +0800 Subject: [PATCH 31/85] h --- sdk/c/api/data_channel_interface.cc | 10 +++++----- sdk/c/api/data_channel_interface.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 6833582c9a..5d55b5acb0 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -24,24 +24,24 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( return rtc::ToC(new std::string(sState)); } -RTC_EXPORT extern "C" bool webrtcDataChannelSendText( +RTC_EXPORT extern "C" void webrtcDataChannelSendText( const WebrtcDataChannelInterface* channel, const char* text ) { auto chan = rtc::ToCplusplus(channel); auto db = webrtc::DataBuffer(text); - return chan->Send(&db); + chan->Send(&db); } -RTC_EXPORT extern "C" bool webrtcDataChannelSendData( +RTC_EXPORT extern "C" void webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, const char* data, size_t len ) { auto chan = rtc::ToCplusplus(channel); rtc::CopyOnWriteBuffer writeBuffer(data, len); - const webrtc::DataBuffer db = webrtc::DataBuffer(writeBuffer, true); - return chan->Send(&db); + auto db = webrtc::DataBuffer(writeBuffer, true); + chan->Send(&db); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index e2fdf81c16..4937fb6bb3 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -27,11 +27,11 @@ RTC_EXPORT RtcString* webrtcDataChannelLabel( RTC_EXPORT RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel); -RTC_EXPORT bool webrtcDataChannelSendText( +RTC_EXPORT void webrtcDataChannelSendText( const WebrtcDataChannelInterface* channel, const char* text); -RTC_EXPORT bool webrtcDataChannelSendData( +RTC_EXPORT void webrtcDataChannelSendData( const WebrtcDataChannelInterface* channel, const char* data, size_t len); From 2141efb1f88033f13e55d10561e39e42b2f8a380 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 17:56:53 +0800 Subject: [PATCH 32/85] j --- sdk/c/api/data_channel_interface.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 5d55b5acb0..92fc4800a7 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -29,7 +29,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelSendText( const char* text ) { auto chan = rtc::ToCplusplus(channel); - auto db = webrtc::DataBuffer(text); + const auto db = webrtc::DataBuffer(text); chan->Send(&db); } @@ -40,7 +40,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelSendData( ) { auto chan = rtc::ToCplusplus(channel); rtc::CopyOnWriteBuffer writeBuffer(data, len); - auto db = webrtc::DataBuffer(writeBuffer, true); + const auto db = webrtc::DataBuffer(writeBuffer, true); chan->Send(&db); } From 72bab18d73626ad47afe79f19fa316d471e2eb67 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 18:01:37 +0800 Subject: [PATCH 33/85] k --- sdk/c/api/data_channel_interface.cc | 4 ++-- sdk/c/api/data_channel_interface.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 92fc4800a7..8c6bece247 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -25,7 +25,7 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( } RTC_EXPORT extern "C" void webrtcDataChannelSendText( - const WebrtcDataChannelInterface* channel, + WebrtcDataChannelInterface* channel, const char* text ) { auto chan = rtc::ToCplusplus(channel); @@ -34,7 +34,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelSendText( } RTC_EXPORT extern "C" void webrtcDataChannelSendData( - const WebrtcDataChannelInterface* channel, + WebrtcDataChannelInterface* channel, const char* data, size_t len ) { diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 4937fb6bb3..37d91e3917 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -28,11 +28,11 @@ RTC_EXPORT RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel); RTC_EXPORT void webrtcDataChannelSendText( - const WebrtcDataChannelInterface* channel, + WebrtcDataChannelInterface* channel, const char* text); RTC_EXPORT void webrtcDataChannelSendData( - const WebrtcDataChannelInterface* channel, + WebrtcDataChannelInterface* channel, const char* data, size_t len); From 5cb04b3691cc72c7787fca1fef1efbb910385f94 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 18:02:41 +0800 Subject: [PATCH 34/85] l --- sdk/c/api/data_channel_interface.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 8c6bece247..edfab2dbbf 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -30,7 +30,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelSendText( ) { auto chan = rtc::ToCplusplus(channel); const auto db = webrtc::DataBuffer(text); - chan->Send(&db); + chan->Send(db); } RTC_EXPORT extern "C" void webrtcDataChannelSendData( @@ -41,7 +41,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelSendData( auto chan = rtc::ToCplusplus(channel); rtc::CopyOnWriteBuffer writeBuffer(data, len); const auto db = webrtc::DataBuffer(writeBuffer, true); - chan->Send(&db); + chan->Send(db); } From 7cf67e417e72e4d6f152f5f8b965c5168b3406a6 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 2 Apr 2020 18:04:35 +0800 Subject: [PATCH 35/85] m --- sdk/c/api/data_channel_interface.cc | 8 ++++---- sdk/c/api/data_channel_interface.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index edfab2dbbf..8c703b1a76 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -24,16 +24,16 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( return rtc::ToC(new std::string(sState)); } -RTC_EXPORT extern "C" void webrtcDataChannelSendText( +RTC_EXPORT extern "C" bool webrtcDataChannelSendText( WebrtcDataChannelInterface* channel, const char* text ) { auto chan = rtc::ToCplusplus(channel); const auto db = webrtc::DataBuffer(text); - chan->Send(db); + return chan->Send(db); } -RTC_EXPORT extern "C" void webrtcDataChannelSendData( +RTC_EXPORT extern "C" bool webrtcDataChannelSendData( WebrtcDataChannelInterface* channel, const char* data, size_t len @@ -41,7 +41,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelSendData( auto chan = rtc::ToCplusplus(channel); rtc::CopyOnWriteBuffer writeBuffer(data, len); const auto db = webrtc::DataBuffer(writeBuffer, true); - chan->Send(db); + return chan->Send(db); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 37d91e3917..3e58f63e87 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -27,11 +27,11 @@ RTC_EXPORT RtcString* webrtcDataChannelLabel( RTC_EXPORT RtcString* webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel); -RTC_EXPORT void webrtcDataChannelSendText( +RTC_EXPORT bool webrtcDataChannelSendText( WebrtcDataChannelInterface* channel, const char* text); -RTC_EXPORT void webrtcDataChannelSendData( +RTC_EXPORT bool webrtcDataChannelSendData( WebrtcDataChannelInterface* channel, const char* data, size_t len); From f9264443f366c0e7c6f77a0ebc679b8d2eb8eb2e Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 12:01:31 +0800 Subject: [PATCH 36/85] add callback code --- sdk/c/api/data_channel_interface.cc | 59 ++ sdk/c/api/data_channel_interface.h | 9 +- .../webrtc/api/data_channel_interface.cs | 7 +- sdk/dotnet/webrtc/api/jsep.cs | 793 ++++++++++-------- 4 files changed, 503 insertions(+), 365 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 8c703b1a76..02169a53eb 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -7,6 +7,47 @@ #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 { + functions_->on_message(context_, buffer.binary, buffer.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_; + }; +} + +struct WebrtcDataChannelObserverFunctions { + void (*on_destruction)(void*); + void (*on_state_change)(void*); + void (*on_message)(void*, bool binary, void* data, size_t len); + void (*on_buffered_amount_change)(void*, uint64_t); +}; + RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel) { rtc::ToCplusplus(channel)->Release(); @@ -42,6 +83,24 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendData( rtc::CopyOnWriteBuffer writeBuffer(data, len); const auto db = webrtc::DataBuffer(writeBuffer, true); return chan->Send(db); + } + +RTC_EXPORT extern "C" WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( + WebrtcDataChannelInterface* channel, + const struct WebrtcDataChannelObserverFunctions* functions) { + + auto chan = rtc::ToCplusplus(channel); + auto obs = new webrtc::DelegatingDataChannelObserver(channel, functions); + chan->RegisterObserver(obs); + return obs; +} +RTC_EXPORT extern "C" void webrtcDataChannelUnregisterObserver( + WebrtcDataChannelInterface* channel + ) { + auto chan = rtc::ToCplusplus(channel); + chan->UnregisterObserver(); } + + diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 3e58f63e87..0e3846e25a 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -15,8 +15,8 @@ extern "C" { #endif - RTC_C_CLASS(webrtc::DataChannelInterface, WebrtcDataChannelInterface) +RTC_C_CLASS(webrtc::DataChannelObserver, WebrtcDataChannelObserver) RTC_EXPORT void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel); @@ -36,6 +36,13 @@ RTC_EXPORT bool webrtcDataChannelSendData( const char* data, size_t len); +RTC_EXPORT WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( + WebrtcDataChannelInterface* channel, + const struct WebrtcDataChannelObserverFunctions* functions); + +RTC_EXPORT void webrtcDataChannelUnRegisterCallback( + WebrtcDataChannelInterface* channel); + #ifdef __cplusplus } diff --git a/sdk/dotnet/webrtc/api/data_channel_interface.cs b/sdk/dotnet/webrtc/api/data_channel_interface.cs index 1d8085161d..55349de2ed 100644 --- a/sdk/dotnet/webrtc/api/data_channel_interface.cs +++ b/sdk/dotnet/webrtc/api/data_channel_interface.cs @@ -24,7 +24,7 @@ public sealed class DisposableDataChannelInterface : DisposablePtr, IDisposableDataChannelInterface { IntPtr IDataChannelInterface.Ptr => Ptr; - + internal DisposableDataChannelInterface(IntPtr ptr) { Ptr = ptr; @@ -37,6 +37,11 @@ private protected override void FreePtr() } public static class DataChannelInterfaceExtension { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcDataChannelRegisterObserver(IntPtr s, IntPtr o); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcDataChannelUnRegisterObserver(IntPtr s); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr webrtcDataChannelLabel( IntPtr ptr diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 639d600fa7..96e8ab6a01 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -1,374 +1,441 @@ -/* - * Copyright 2019 pixiv Inc. 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. - */ - -using Pixiv.Rtc; -using System; -using System.Runtime.InteropServices; - -namespace Pixiv.Webrtc -{ - public enum SdpType - { - Offer, - PrAnswer, - Answer - } - - public interface ICreateSessionDescriptionObserver - { - IntPtr Ptr { get; } - } - +/* + * Copyright 2019 pixiv Inc. 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. + */ + +using Pixiv.Rtc; +using System; +using System.Runtime.InteropServices; + +namespace Pixiv.Webrtc +{ + public enum SdpType + { + Offer, + PrAnswer, + Answer + } + + public interface ICreateSessionDescriptionObserver + { + IntPtr Ptr { get; } + } + + public interface IRTCDataBufferInterface + { + IntPtr Ptr { get; } + } + + public sealed class RTCDataBufferInterface : IRTCDataBufferInterface + { + public IntPtr Ptr { get; } + + public RTCDataBufferInterface(IntPtr ptr) + { + Ptr = ptr; + } + } + + public interface IManagedDataChannelObserver + { + void OnStateChange(); + void OnMessage(RTCDataBufferInterface buffer); + void OnBufferedAmountChange(UInt64 sent_data_size); + } + + public interface IDisposableCreateSessionDescriptionObserver : + ICreateSessionDescriptionObserver, Rtc.IDisposable + { + } + public interface IDataChannelObserver { IntPtr Ptr { get; } - } - - public interface IDisposableCreateSessionDescriptionObserver : - ICreateSessionDescriptionObserver, Rtc.IDisposable - { - } - - public interface IDisposableDataChannelObserver : - IDataChannelObserver, Rtc.IDisposable - { - } - - public interface IDisposableIceCandidateInterface : - IIceCandidateInterface, Rtc.IDisposable - { - } - - public interface IDisposableSessionDescriptionInterface : - ISessionDescriptionInterface, Rtc.IDisposable - { - } - - public interface IDisposableSetSessionDescriptionObserver : - ISetSessionDescriptionObserver, Rtc.IDisposable - { - } - - public interface IIceCandidateInterface - { - IntPtr Ptr { get; } - } - - public interface IManagedCreateSessionDescriptionObserver - { - void OnSuccess(DisposableSessionDescriptionInterface desc); - void OnFailure(RtcError error); - } - - public interface IManagedDataChannelObserver - { - void OnStateChange(DisposableDataChannelInterface desc); - - - } - - public interface IManagedSetSessionDescriptionObserver - { - void OnSuccess(); - void OnFailure(RtcError error); - } - - public interface ISessionDescriptionInterface - { - IntPtr Ptr { get; } - } - - public interface ISetSessionDescriptionObserver - { - IntPtr Ptr { get; } - } - + } + + public interface IDisposableDataChannelObserver : + IDataChannelObserver, Rtc.IDisposable + { + } + + public interface IDisposableIceCandidateInterface : + IIceCandidateInterface, Rtc.IDisposable + { + } + + public interface IDisposableSessionDescriptionInterface : + ISessionDescriptionInterface, Rtc.IDisposable + { + } + + public interface IDisposableSetSessionDescriptionObserver : + ISetSessionDescriptionObserver, Rtc.IDisposable + { + } + + public interface IIceCandidateInterface + { + IntPtr Ptr { get; } + } + + public interface IManagedCreateSessionDescriptionObserver + { + void OnSuccess(DisposableSessionDescriptionInterface desc); + void OnFailure(RtcError error); + } + + public interface IManagedSetSessionDescriptionObserver + { + void OnSuccess(); + void OnFailure(RtcError error); + } + + public interface ISessionDescriptionInterface + { + IntPtr Ptr { get; } + } + + public interface ISetSessionDescriptionObserver + { + IntPtr Ptr { get; } + } + public sealed class DisposableDataChannelObserver: DisposablePtr, IDisposableDataChannelObserver { IntPtr IDataChannelObserver.Ptr => Ptr; - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcDataChannelObserver( + IntPtr context, + IntPtr functions + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void DestructionHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void OnBufferedAmountChangeHandler(IntPtr context, ulong sent_data_size); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void OnMessageHandler(IntPtr context, RTCDataBufferInterface buffer); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void OnStateChangeHandler(IntPtr context); + + private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( + (DestructionHandler)OnDestruction, + (OnBufferedAmountChangeHandler)OnBufferedAmountChange, + (OnMessageHandler)OnMessage, + (OnStateChangeHandler)OnStateChange + ); + + + + [MonoPInvokeCallback(typeof(OnStateChangeHandler))] + private static void OnStateChange(IntPtr context) + { + var handle = (GCHandle)context; + + ((IManagedDataChannelObserver)handle.Target).OnStateChange(); + } + + [MonoPInvokeCallback(typeof(OnMessageHandler))] + private static void OnMessage(IntPtr context, RTCDataBufferInterface buffer) + { + var handle = (GCHandle)context; + + ((IManagedDataChannelObserver)handle.Target).OnMessage(buffer); + } + + [MonoPInvokeCallback(typeof(OnBufferedAmountChangeHandler))] + private static void OnBufferedAmountChange(IntPtr context, ulong sent_data_size) + { + var handle = (GCHandle)context; + + ((IManagedDataChannelObserver)handle.Target).OnBufferedAmountChange(sent_data_size); + } + + private protected override void FreePtr() + { + Interop.DataChannelObserver.Release(Ptr); + } + + [MonoPInvokeCallback(typeof(DestructionHandler))] + private static void OnDestruction(IntPtr context) + { + ((GCHandle)context).Free(); + } + + public DisposableDataChannelObserver( + IManagedDataChannelObserver implementation) + { + Ptr = webrtcDataChannelObserver( + (IntPtr)GCHandle.Alloc(implementation), + s_functions.Ptr + ); + } + + } + + public sealed class DisposableCreateSessionDescriptionObserver : + DisposablePtr, IDisposableCreateSessionDescriptionObserver + { + IntPtr ICreateSessionDescriptionObserver.Ptr => Ptr; + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void DestructionHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void SuccessHandler(IntPtr context, IntPtr desc); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void FailureHandler(IntPtr context, RtcError error); + + private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( + (DestructionHandler)OnDestruction, + (SuccessHandler)OnSuccess, + (FailureHandler)OnFailure + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcNewCreateSessionDescriptionObserver( + IntPtr context, + IntPtr functions + ); + + [MonoPInvokeCallback(typeof(DestructionHandler))] + private static void OnDestruction(IntPtr context) + { + ((GCHandle)context).Free(); + } + + [MonoPInvokeCallback(typeof(SuccessHandler))] + private static void OnSuccess(IntPtr context, IntPtr desc) + { + var handle = (GCHandle)context; + + ((IManagedCreateSessionDescriptionObserver)handle.Target).OnSuccess( + new DisposableSessionDescriptionInterface(desc) + ); + } + + [MonoPInvokeCallback(typeof(FailureHandler))] + private static void OnFailure(IntPtr context, RtcError error) + { + var handle = (GCHandle)context; + + ((IManagedCreateSessionDescriptionObserver)handle.Target).OnFailure( + error + ); + } + + public DisposableCreateSessionDescriptionObserver(IntPtr ptr) + { + Ptr = ptr; + } + + public DisposableCreateSessionDescriptionObserver( + IManagedCreateSessionDescriptionObserver implementation) + { + Ptr = webrtcNewCreateSessionDescriptionObserver( + (IntPtr)GCHandle.Alloc(implementation), + s_functions.Ptr + ); + } + + private protected override void FreePtr() + { + Interop.CreateSessionDescriptionObserver.Release(Ptr); + } + } + + public sealed class DisposableSessionDescriptionInterface : + DisposablePtr, IDisposableSessionDescriptionInterface + { + IntPtr ISessionDescriptionInterface.Ptr => Ptr; + + public DisposableSessionDescriptionInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.SessionDescriptionInterface.Delete(Ptr); + } + } + + public sealed class DisposableSetSessionDescriptionObserver : + DisposablePtr, IDisposableSetSessionDescriptionObserver + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void DestructionHandler(IntPtr context); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void StateChangeHandler(IntPtr context, IntPtr state); - - [MonoPInvokeCallback(typeof(StateChangeHandler))] - private static void OnStateChange(IntPtr context, IntPtr state) - { - var handle = (GCHandle)context; - - ((IManagedDataChannelObserver)handle.Target).OnStateChange( - new DisposableDataChannelInterface(state) - ); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void SuccessHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void FailureHandler(IntPtr context, RtcError error); + + private static FunctionPtrArray s_functions = new FunctionPtrArray( + (DestructionHandler)OnDestruction, + (SuccessHandler)OnSuccess, + (FailureHandler)OnFailure + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcNewSetSessionDescriptionObserver( + IntPtr context, + IntPtr functions + ); + + [MonoPInvokeCallback(typeof(DestructionHandler))] + private static void OnDestruction(IntPtr context) + { + ((GCHandle)context).Free(); + } + + [MonoPInvokeCallback(typeof(SuccessHandler))] + private static void OnSuccess(IntPtr context) + { + var handle = (GCHandle)context; + ((IManagedSetSessionDescriptionObserver)handle.Target).OnSuccess(); } - private protected override void FreePtr() - { - Interop.DataChannelObserver.Release(Ptr); + + [MonoPInvokeCallback(typeof(FailureHandler))] + private static void OnFailure(IntPtr context, RtcError error) + { + var handle = (GCHandle)context; + + ((IManagedSetSessionDescriptionObserver)handle.Target).OnFailure( + error + ); } - } - - public sealed class DisposableCreateSessionDescriptionObserver : - DisposablePtr, IDisposableCreateSessionDescriptionObserver - { - IntPtr ICreateSessionDescriptionObserver.Ptr => Ptr; - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void DestructionHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void SuccessHandler(IntPtr context, IntPtr desc); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcError error); - - private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( - (DestructionHandler)OnDestruction, - (SuccessHandler)OnSuccess, - (FailureHandler)OnFailure - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcNewCreateSessionDescriptionObserver( - IntPtr context, - IntPtr functions - ); - - [MonoPInvokeCallback(typeof(DestructionHandler))] - private static void OnDestruction(IntPtr context) - { - ((GCHandle)context).Free(); - } - - [MonoPInvokeCallback(typeof(SuccessHandler))] - private static void OnSuccess(IntPtr context, IntPtr desc) - { - var handle = (GCHandle)context; - - ((IManagedCreateSessionDescriptionObserver)handle.Target).OnSuccess( - new DisposableSessionDescriptionInterface(desc) - ); - } - - [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcError error) - { - var handle = (GCHandle)context; - - ((IManagedCreateSessionDescriptionObserver)handle.Target).OnFailure( - error - ); - } - - public DisposableCreateSessionDescriptionObserver(IntPtr ptr) - { - Ptr = ptr; - } - - public DisposableCreateSessionDescriptionObserver( - IManagedCreateSessionDescriptionObserver implementation) - { - Ptr = webrtcNewCreateSessionDescriptionObserver( - (IntPtr)GCHandle.Alloc(implementation), - s_functions.Ptr - ); - } - - private protected override void FreePtr() - { - Interop.CreateSessionDescriptionObserver.Release(Ptr); - } - } - - public sealed class DisposableSessionDescriptionInterface : - DisposablePtr, IDisposableSessionDescriptionInterface - { - IntPtr ISessionDescriptionInterface.Ptr => Ptr; - - public DisposableSessionDescriptionInterface(IntPtr ptr) - { - Ptr = ptr; - } - - private protected override void FreePtr() - { - Interop.SessionDescriptionInterface.Delete(Ptr); - } - } - - public sealed class DisposableSetSessionDescriptionObserver : - DisposablePtr, IDisposableSetSessionDescriptionObserver - { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void DestructionHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void SuccessHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcError error); - - private static FunctionPtrArray s_functions = new FunctionPtrArray( - (DestructionHandler)OnDestruction, - (SuccessHandler)OnSuccess, - (FailureHandler)OnFailure - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcNewSetSessionDescriptionObserver( - IntPtr context, - IntPtr functions - ); - - [MonoPInvokeCallback(typeof(DestructionHandler))] - private static void OnDestruction(IntPtr context) - { - ((GCHandle)context).Free(); - } - - [MonoPInvokeCallback(typeof(SuccessHandler))] - private static void OnSuccess(IntPtr context) - { - var handle = (GCHandle)context; - ((IManagedSetSessionDescriptionObserver)handle.Target).OnSuccess(); - } - - [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcError error) - { - var handle = (GCHandle)context; - - ((IManagedSetSessionDescriptionObserver)handle.Target).OnFailure( - error - ); - } - - IntPtr ISetSessionDescriptionObserver.Ptr => Ptr; - - public DisposableSetSessionDescriptionObserver(IntPtr ptr) - { - Ptr = ptr; - } - - public DisposableSetSessionDescriptionObserver( - IManagedSetSessionDescriptionObserver implementation) - { - Ptr = webrtcNewSetSessionDescriptionObserver( - (IntPtr)GCHandle.Alloc(implementation), - s_functions.Ptr - ); - } - - private protected override void FreePtr() - { - Interop.SetSessionDescriptionObserver.Release(Ptr); - } - } - - public sealed class IceCandidateInterface : IIceCandidateInterface - { - public IntPtr Ptr { get; } - - public IceCandidateInterface(IntPtr ptr) - { - Ptr = ptr; - } - } - - public static class IceCandidateInterfaceExtension - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern bool webrtcIceCandidateInterfaceResolve( - IntPtr ptr, - out IntPtr sdpMid, - out int sdpMLineIndex, - out IntPtr sdp - ); - - public static bool Resolve( - this IIceCandidateInterface candidate, out string sdpMid, out int sdpMLineIndex, out string sdp) - { - var result = webrtcIceCandidateInterfaceResolve( - candidate.Ptr, out var _sdpMid, out sdpMLineIndex, out var _sdp); - - sdpMid = Rtc.Interop.String.MoveToString(_sdpMid); - sdp = Rtc.Interop.String.MoveToString(_sdp); - - return result; - } - } - - public static class SessionDescription - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcCreateSessionDescription( - SdpType type, - string sdp, - IntPtr error - ); - - public static DisposableSessionDescriptionInterface Create( - SdpType type, - string sdp, - IntPtr error) - { - var ptr = webrtcCreateSessionDescription(type, sdp, error); - - return ptr == IntPtr.Zero ? - null : new DisposableSessionDescriptionInterface(ptr); - } - } - - public static class SessionDescriptionInterfaceExtension - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - private static extern bool webrtcSessionDescriptionInterfaceToString( - IntPtr ptr, - out IntPtr result - ); - - public static bool TryToString( - this ISessionDescriptionInterface desc, - out string s) - { - var result = webrtcSessionDescriptionInterfaceToString( - desc.Ptr, out var webrtcString); - - s = Rtc.Interop.String.MoveToString(webrtcString); - - return result; - } - } -} - -namespace Pixiv.Webrtc.Interop -{ - public static class CreateSessionDescriptionObserver - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcCreateSessionDescriptionObserverRelease")] - public static extern void Release(IntPtr ptr); - } - - public static class DataChannelObserver - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] - public static extern void Release(IntPtr ptr); - } - - public static class SessionDescriptionInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteSessionDescriptionInterface")] - public static extern void Delete(IntPtr ptr); - } - - public static class SetSessionDescriptionObserver - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcSetSessionDescriptionObserverRelease")] - public static extern void Release(IntPtr ptr); - } -} + + IntPtr ISetSessionDescriptionObserver.Ptr => Ptr; + + public DisposableSetSessionDescriptionObserver(IntPtr ptr) + { + Ptr = ptr; + } + + public DisposableSetSessionDescriptionObserver( + IManagedSetSessionDescriptionObserver implementation) + { + Ptr = webrtcNewSetSessionDescriptionObserver( + (IntPtr)GCHandle.Alloc(implementation), + s_functions.Ptr + ); + } + + private protected override void FreePtr() + { + Interop.SetSessionDescriptionObserver.Release(Ptr); + } + } + + public sealed class IceCandidateInterface : IIceCandidateInterface + { + public IntPtr Ptr { get; } + + public IceCandidateInterface(IntPtr ptr) + { + Ptr = ptr; + } + } + + public static class IceCandidateInterfaceExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern bool webrtcIceCandidateInterfaceResolve( + IntPtr ptr, + out IntPtr sdpMid, + out int sdpMLineIndex, + out IntPtr sdp + ); + + public static bool Resolve( + this IIceCandidateInterface candidate, out string sdpMid, out int sdpMLineIndex, out string sdp) + { + var result = webrtcIceCandidateInterfaceResolve( + candidate.Ptr, out var _sdpMid, out sdpMLineIndex, out var _sdp); + + sdpMid = Rtc.Interop.String.MoveToString(_sdpMid); + sdp = Rtc.Interop.String.MoveToString(_sdp); + + return result; + } + } + + public static class SessionDescription + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcCreateSessionDescription( + SdpType type, + string sdp, + IntPtr error + ); + + public static DisposableSessionDescriptionInterface Create( + SdpType type, + string sdp, + IntPtr error) + { + var ptr = webrtcCreateSessionDescription(type, sdp, error); + + return ptr == IntPtr.Zero ? + null : new DisposableSessionDescriptionInterface(ptr); + } + } + + public static class SessionDescriptionInterfaceExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.I1)] + private static extern bool webrtcSessionDescriptionInterfaceToString( + IntPtr ptr, + out IntPtr result + ); + + public static bool TryToString( + this ISessionDescriptionInterface desc, + out string s) + { + var result = webrtcSessionDescriptionInterfaceToString( + desc.Ptr, out var webrtcString); + + s = Rtc.Interop.String.MoveToString(webrtcString); + + return result; + } + } +} + +namespace Pixiv.Webrtc.Interop +{ + public static class CreateSessionDescriptionObserver + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcCreateSessionDescriptionObserverRelease")] + public static extern void Release(IntPtr ptr); + } + + public static class DataChannelObserver + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] + public static extern void Release(IntPtr ptr); + } + + public static class SessionDescriptionInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteSessionDescriptionInterface")] + public static extern void Delete(IntPtr ptr); + } + + public static class SetSessionDescriptionObserver + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcSetSessionDescriptionObserverRelease")] + public static extern void Release(IntPtr ptr); + } +} From a4b68f412c385eeefe96ccb39aaf5aec863378c0 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 12:08:54 +0800 Subject: [PATCH 37/85] fix --- sdk/c/api/data_channel_interface.cc | 7 +------ sdk/c/api/data_channel_interface.h | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 02169a53eb..2bfd1f8235 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -41,12 +41,7 @@ class DelegatingDataChannelObserver }; } -struct WebrtcDataChannelObserverFunctions { - void (*on_destruction)(void*); - void (*on_state_change)(void*); - void (*on_message)(void*, bool binary, void* data, size_t len); - void (*on_buffered_amount_change)(void*, uint64_t); -}; + RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel) { diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 0e3846e25a..f364261565 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -18,6 +18,13 @@ extern "C" { 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, void* data, size_t len); + void (*on_buffered_amount_change)(void*, uint64_t); +}; + RTC_EXPORT void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel); From d3e504f991064b382c0f8de26be4f88e17c6fc72 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 12:17:09 +0800 Subject: [PATCH 38/85] fix 2 --- sdk/c/api/data_channel_interface.cc | 3 ++- sdk/c/api/data_channel_interface.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 2bfd1f8235..59bde30d27 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -28,7 +28,8 @@ class DelegatingDataChannelObserver } void OnMessage(const DataBuffer& buffer) override { - functions_->on_message(context_, buffer.binary, buffer.data, buffer.size); + auto * data = buffer.data.data(); + functions_->on_message(context_, buffer.binary, data, buffer.size()); } void OnBufferedAmountChange(uint64_t sent_data_size) override { diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index f364261565..9b9d4f6578 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -21,7 +21,7 @@ RTC_C_CLASS(webrtc::DataChannelObserver, WebrtcDataChannelObserver) struct WebrtcDataChannelObserverFunctions { void (*on_destruction)(void*); void (*on_state_change)(void*); - void (*on_message)(void*, bool binary, void* data, size_t len); + void (*on_message)(void*, bool binary, const uint8_t* data, size_t len); void (*on_buffered_amount_change)(void*, uint64_t); }; From 8da0703a5abb6d18bbee453c22834c0deec19f66 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 12:21:40 +0800 Subject: [PATCH 39/85] fix3 --- sdk/c/api/data_channel_interface.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 59bde30d27..18122fd214 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -88,7 +88,8 @@ RTC_EXPORT extern "C" WebrtcDataChannelObserver* webrtcDataChannelRegisterObserv auto chan = rtc::ToCplusplus(channel); auto obs = new webrtc::DelegatingDataChannelObserver(channel, functions); chan->RegisterObserver(obs); - return obs; + auto o = rtc::ToC(obs); + return o; } RTC_EXPORT extern "C" void webrtcDataChannelUnregisterObserver( From 2cc718f2d3cb2d9a384b138a8412bdfe6ea58932 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 13:46:52 +0800 Subject: [PATCH 40/85] fixes --- sdk/c/api/data_channel_interface.cc | 3 ++- sdk/c/api/data_channel_interface.h | 1 + .../webrtc/api/data_channel_interface.cs | 15 ++++++++++- sdk/dotnet/webrtc/api/jsep.cs | 27 ++++++++++++------- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 18122fd214..3b3e560805 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -82,11 +82,12 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendData( } RTC_EXPORT extern "C" WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( + void* context, WebrtcDataChannelInterface* channel, const struct WebrtcDataChannelObserverFunctions* functions) { auto chan = rtc::ToCplusplus(channel); - auto obs = new webrtc::DelegatingDataChannelObserver(channel, functions); + auto obs = new webrtc::DelegatingDataChannelObserver(context, functions); chan->RegisterObserver(obs); auto o = rtc::ToC(obs); return o; diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 9b9d4f6578..e92a52ddf7 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -44,6 +44,7 @@ RTC_EXPORT bool webrtcDataChannelSendData( size_t len); RTC_EXPORT WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( + void* context, WebrtcDataChannelInterface* channel, const struct WebrtcDataChannelObserverFunctions* functions); diff --git a/sdk/dotnet/webrtc/api/data_channel_interface.cs b/sdk/dotnet/webrtc/api/data_channel_interface.cs index 55349de2ed..b9bbb99d4d 100644 --- a/sdk/dotnet/webrtc/api/data_channel_interface.cs +++ b/sdk/dotnet/webrtc/api/data_channel_interface.cs @@ -33,7 +33,15 @@ internal DisposableDataChannelInterface(IntPtr ptr) private protected override void FreePtr() { Interop.DataChannelInterface.Release(Ptr); - } + } + + public IntPtr GetPtr + { + get + { + return Ptr; + } + } } public static class DataChannelInterfaceExtension { @@ -91,6 +99,11 @@ public static bool Send(this IDisposableDataChannelInterface channel, string tex { return webrtcDataChannelSendText(channel.Ptr, text); } + + public static void UnRegisterObserver(this IDisposableDataChannelInterface channel) + { + webrtcDataChannelUnRegisterObserver(channel.Ptr); + } } } diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 96e8ab6a01..955f30e9e4 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -40,8 +40,9 @@ public RTCDataBufferInterface(IntPtr ptr) public interface IManagedDataChannelObserver { + DisposableDataChannelInterface DataChannel { get; } void OnStateChange(); - void OnMessage(RTCDataBufferInterface buffer); + void OnMessage(bool binary, IntPtr data, int data_size); void OnBufferedAmountChange(UInt64 sent_data_size); } @@ -107,8 +108,9 @@ public sealed class DisposableDataChannelObserver: DisposablePtr, IDisposableDat IntPtr IDataChannelObserver.Ptr => Ptr; [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcDataChannelObserver( + private static extern IntPtr webrtcDataChannelRegisterObserver( IntPtr context, + IntPtr dataChannel, IntPtr functions ); @@ -119,20 +121,18 @@ IntPtr functions private delegate void OnBufferedAmountChangeHandler(IntPtr context, ulong sent_data_size); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void OnMessageHandler(IntPtr context, RTCDataBufferInterface buffer); + private delegate void OnMessageHandler(IntPtr context, bool binary, IntPtr data, int data_size); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void OnStateChangeHandler(IntPtr context); private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, - (OnBufferedAmountChangeHandler)OnBufferedAmountChange, + (OnStateChangeHandler)OnStateChange, (OnMessageHandler)OnMessage, - (OnStateChangeHandler)OnStateChange + (OnBufferedAmountChangeHandler)OnBufferedAmountChange ); - - [MonoPInvokeCallback(typeof(OnStateChangeHandler))] private static void OnStateChange(IntPtr context) { @@ -142,11 +142,11 @@ private static void OnStateChange(IntPtr context) } [MonoPInvokeCallback(typeof(OnMessageHandler))] - private static void OnMessage(IntPtr context, RTCDataBufferInterface buffer) + private static void OnMessage(IntPtr context, bool binary, IntPtr data, int data_size) { var handle = (GCHandle)context; - ((IManagedDataChannelObserver)handle.Target).OnMessage(buffer); + ((IManagedDataChannelObserver)handle.Target).OnMessage(binary, data, data_size); } [MonoPInvokeCallback(typeof(OnBufferedAmountChangeHandler))] @@ -171,12 +171,19 @@ private static void OnDestruction(IntPtr context) public DisposableDataChannelObserver( IManagedDataChannelObserver implementation) { - Ptr = webrtcDataChannelObserver( + DataChannel = implementation.DataChannel; + Ptr = webrtcDataChannelRegisterObserver( (IntPtr)GCHandle.Alloc(implementation), + implementation.DataChannel.GetPtr, s_functions.Ptr ); } + public DisposableDataChannelInterface DataChannel + { + get; private set; + } + } public sealed class DisposableCreateSessionDescriptionObserver : From 3ad8f825bf60192cf2f1b998b32a87b8156b8083 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 15:28:03 +0800 Subject: [PATCH 41/85] return state enum --- sdk/c/api/data_channel_interface.cc | 5 ++--- sdk/c/api/data_channel_interface.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 3b3e560805..0a0b9a6c35 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -54,11 +54,10 @@ RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( return rtc::ToC(new auto(rtc::ToCplusplus(channel)->label())); } -RTC_EXPORT extern "C" RtcString* webrtcDataChannelStatus( +RTC_EXPORT extern "C" int webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel) { auto chan = rtc::ToCplusplus(channel); - auto sState = chan->DataStateString(chan->state()); - return rtc::ToC(new std::string(sState)); + return chan->state(); } RTC_EXPORT extern "C" bool webrtcDataChannelSendText( diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index e92a52ddf7..4f8875e5ec 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -31,7 +31,7 @@ RTC_EXPORT void webrtcDataChannelInterfaceRelease( RTC_EXPORT RtcString* webrtcDataChannelLabel( const WebrtcDataChannelInterface* channel); -RTC_EXPORT RtcString* webrtcDataChannelStatus( +RTC_EXPORT int webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel); RTC_EXPORT bool webrtcDataChannelSendText( From 164d80611acfd2434cb601ef4bf3d4fc4aa8b7db Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 15:40:54 +0800 Subject: [PATCH 42/85] update status for enum --- sdk/dotnet/webrtc/api/data_channel_interface.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/dotnet/webrtc/api/data_channel_interface.cs b/sdk/dotnet/webrtc/api/data_channel_interface.cs index b9bbb99d4d..c134bb1f0f 100644 --- a/sdk/dotnet/webrtc/api/data_channel_interface.cs +++ b/sdk/dotnet/webrtc/api/data_channel_interface.cs @@ -56,7 +56,7 @@ IntPtr ptr ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcDataChannelStatus( + private static extern int webrtcDataChannelStatus( IntPtr ptr ); @@ -76,10 +76,9 @@ public static string Label(this IDisposableDataChannelInterface channel) webrtcDataChannelLabel(channel.Ptr)); } - public static string Status(this IDisposableDataChannelInterface channel) + public static int Status(this IDisposableDataChannelInterface channel) { - return Rtc.Interop.String.MoveToString( - webrtcDataChannelStatus(channel.Ptr)); + return webrtcDataChannelStatus(channel.Ptr); } public static bool Send(this IDisposableDataChannelInterface channel, byte[] data) From b1d89c9e5d33e645ec876af67f927439f3437bc8 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 3 Apr 2020 20:35:15 +0800 Subject: [PATCH 43/85] test --- sdk/c/api/media_stream_interface.cc | 5 +++++ sdk/dotnet/webrtc/api/media_stream_interface.cs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/media_stream_interface.cc b/sdk/c/api/media_stream_interface.cc index 99cc05d8f9..39360a5c1d 100644 --- a/sdk/c/api/media_stream_interface.cc +++ b/sdk/c/api/media_stream_interface.cc @@ -8,6 +8,8 @@ #include "api/media_stream_interface.h" #include "rtc_base/ref_counted_object.h" #include "sdk/c/api/media_stream_interface.h" +#include +using namespace std; namespace webrtc { @@ -78,6 +80,9 @@ extern "C" void webrtcAudioTrackSinkInterfaceOnData( int sample_rate, size_t number_of_channels, size_t number_of_frames) { + + string strMytestString("hello world"); + cout << strMytestString; rtc::ToCplusplus(sink)->OnData(audio_data, bits_per_sample, sample_rate, number_of_channels, number_of_frames); } diff --git a/sdk/dotnet/webrtc/api/media_stream_interface.cs b/sdk/dotnet/webrtc/api/media_stream_interface.cs index 11c07f1a8e..1f93d663bc 100644 --- a/sdk/dotnet/webrtc/api/media_stream_interface.cs +++ b/sdk/dotnet/webrtc/api/media_stream_interface.cs @@ -338,8 +338,8 @@ private static extern void webrtcAudioTrackSinkInterfaceOnData( IntPtr audioData, int bitsPerSample, int sampleRate, - [MarshalAs(UnmanagedType.U4)] int numberOfChannels, - [MarshalAs(UnmanagedType.U4)] int numberOfFrames + int numberOfChannels, + int numberOfFrames ); public static void OnData( From dad791be2b63122a62926e4e76757ce4870123ca Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sat, 4 Apr 2020 14:11:04 +0800 Subject: [PATCH 44/85] try fix audio --- sdk/c/api/data_channel_interface.h | 2 +- sdk/c/api/media_stream_interface.cc | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 4f8875e5ec..ad6b9ad1a7 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -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. diff --git a/sdk/c/api/media_stream_interface.cc b/sdk/c/api/media_stream_interface.cc index 39360a5c1d..39ed1bf02d 100644 --- a/sdk/c/api/media_stream_interface.cc +++ b/sdk/c/api/media_stream_interface.cc @@ -8,8 +8,6 @@ #include "api/media_stream_interface.h" #include "rtc_base/ref_counted_object.h" #include "sdk/c/api/media_stream_interface.h" -#include -using namespace std; namespace webrtc { @@ -24,11 +22,11 @@ class DelegatingAudioSourceInterface : public AudioSourceInterface { ~DelegatingAudioSourceInterface() { functions_->on_destruction(context_); } - void RegisterObserver(ObserverInterface* observer) { + void RegisterAudioObserver(ObserverInterface* observer) { functions_->register_observer(context_, rtc::ToC(observer)); } - void UnregisterObserver(ObserverInterface* observer) { + void UnregisterAudioObserver(ObserverInterface* observer) { functions_->unregister_observer(context_, rtc::ToC(observer)); } @@ -80,9 +78,6 @@ extern "C" void webrtcAudioTrackSinkInterfaceOnData( int sample_rate, size_t number_of_channels, size_t number_of_frames) { - - string strMytestString("hello world"); - cout << strMytestString; rtc::ToCplusplus(sink)->OnData(audio_data, bits_per_sample, sample_rate, number_of_channels, number_of_frames); } From 4904566d3f5b978d06f4faf81025e1c6b18734a2 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sat, 4 Apr 2020 14:15:26 +0800 Subject: [PATCH 45/85] sdf --- sdk/c/api/media_stream_interface.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/media_stream_interface.cc b/sdk/c/api/media_stream_interface.cc index 39ed1bf02d..99cc05d8f9 100644 --- a/sdk/c/api/media_stream_interface.cc +++ b/sdk/c/api/media_stream_interface.cc @@ -22,11 +22,11 @@ class DelegatingAudioSourceInterface : public AudioSourceInterface { ~DelegatingAudioSourceInterface() { functions_->on_destruction(context_); } - void RegisterAudioObserver(ObserverInterface* observer) { + void RegisterObserver(ObserverInterface* observer) { functions_->register_observer(context_, rtc::ToC(observer)); } - void UnregisterAudioObserver(ObserverInterface* observer) { + void UnregisterObserver(ObserverInterface* observer) { functions_->unregister_observer(context_, rtc::ToC(observer)); } From 612e06101aa9171d7e59166e526532a811af9898 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sat, 4 Apr 2020 15:16:01 +0800 Subject: [PATCH 46/85] code cleanup --- sdk/c/api/data_channel_interface.cc | 4 +- .../webrtc/api/peer_connection_interface.cs | 4 +- sdk/dotnet/webrtc/api/rtc_databuffer.cs | 42 ------------------- sdk/dotnet/webrtc/webrtc.csproj | 5 ++- 4 files changed, 7 insertions(+), 48 deletions(-) delete mode 100644 sdk/dotnet/webrtc/api/rtc_databuffer.cs diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 0a0b9a6c35..4de4321984 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -1,5 +1,5 @@ /* - * 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. @@ -42,8 +42,6 @@ class DelegatingDataChannelObserver }; } - - RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel) { rtc::ToCplusplus(channel)->Release(); diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index c03f9b0a5c..8b92752d98 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -849,14 +849,14 @@ private static extern WebrtcAddTrackResult webrtcPeerConnectionInterfaceAddTrack IntPtr connection, IntPtr track, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] string[] data, - [MarshalAs(UnmanagedType.U4)] int size + int size ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern bool webrtcPeerConnectionInterfaceAddICECandidate( IntPtr connection, [MarshalAs(UnmanagedType.LPStr)] string sdpMid, - [MarshalAs(UnmanagedType.U4)] int sdpMLineIndex, + int sdpMLineIndex, [MarshalAs(UnmanagedType.LPStr)] string sdp ); diff --git a/sdk/dotnet/webrtc/api/rtc_databuffer.cs b/sdk/dotnet/webrtc/api/rtc_databuffer.cs deleted file mode 100644 index cce80eeaef..0000000000 --- a/sdk/dotnet/webrtc/api/rtc_databuffer.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Text; - -namespace Pixiv.Webrtc -{ - public readonly struct RTCDataBuffer { - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcRTCDataChannelMessage(IntPtr ptr, out int len); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern bool webrtcRTCDataChannelMessageIsBinary(IntPtr ptr); - - public bool isBinary { get; } - public byte[] Data { get; } - public string Text { get; } - - public RTCDataBuffer(IntPtr ptr) - { - int len; - var messagePtr = webrtcRTCDataChannelMessage(ptr, out len); - isBinary = webrtcRTCDataChannelMessageIsBinary(ptr); - Data = new byte[len]; - Marshal.Copy(messagePtr, Data, 0, len); - Text = ""; - if (!isBinary) - { - Text = UTF8Encoding.UTF8.GetString(Data); - } - } - } -} - -namespace Pixiv.Webrtc.Interop -{ - public static class RtcDataBuffer - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteRTCDataBuffer")] - public static extern void Delete(IntPtr ptr); - } -} diff --git a/sdk/dotnet/webrtc/webrtc.csproj b/sdk/dotnet/webrtc/webrtc.csproj index 9d66ea38c5..a0f9b1e46b 100644 --- a/sdk/dotnet/webrtc/webrtc.csproj +++ b/sdk/dotnet/webrtc/webrtc.csproj @@ -11,9 +11,12 @@ WebRTC 77.0.0.0 pixiv Inc. - © pixiv Inc. 2019 + © pixiv Inc. 2019 WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs. 7.3 netstandard2.0 + + + From 6294d5740e22fb3ff2df38b0b3e6f7febb4ec387 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 10:51:08 +0800 Subject: [PATCH 47/85] release datachannel --- sdk/c/api/data_channel_interface.cc | 13 ++++++++++++- sdk/c/api/jsep.h | 5 +++++ sdk/dotnet/webrtc/api/jsep.cs | 6 ------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 4de4321984..89a67000fe 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -97,5 +97,16 @@ RTC_EXPORT extern "C" void webrtcDataChannelUnregisterObserver( chan->UnregisterObserver(); } +extern "C" void webrtcDataChannelObserverRelease( + const WebrtcDataChannelObserver* observer) { + rtc::ToCplusplus(observer)->Release(); +} - +namespace Pixiv.Webrtc.Interop +{ + public static class DataChannelObserver + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] + public static extern void Release(IntPtr ptr); + } +} \ No newline at end of file diff --git a/sdk/c/api/jsep.h b/sdk/c/api/jsep.h index c89a07fafc..d84491be6a 100644 --- a/sdk/c/api/jsep.h +++ b/sdk/c/api/jsep.h @@ -37,6 +37,8 @@ RTC_C_CLASS(webrtc::CreateSessionDescriptionObserver, RTC_C_CLASS(webrtc::SetSessionDescriptionObserver, WebrtcSetSessionDescriptionObserver) + + struct WebrtcCreateSessionDescriptionObserverFunctions { void (*on_destruction)(void*); void (*on_success)(void*, WebrtcSessionDescriptionInterface*); @@ -54,6 +56,9 @@ RTC_EXPORT WebrtcSessionDescriptionInterface* webrtcCreateSessionDescription( const char* sdp, WebrtcSdpParseError** error); +RTC_EXPORT void webrtcDataChannelObserverRelease( + const WebrtcDataChannelObserver* observer); + RTC_EXPORT void webrtcCreateSessionDescriptionObserverRelease( const WebrtcCreateSessionDescriptionObserver* observer); diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 955f30e9e4..f54cb13bab 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -428,12 +428,6 @@ public static class CreateSessionDescriptionObserver public static extern void Release(IntPtr ptr); } - public static class DataChannelObserver - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] - public static extern void Release(IntPtr ptr); - } - public static class SessionDescriptionInterface { [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteSessionDescriptionInterface")] From 4121d659c4949b6c2fe3af2c5a4a005d32a1e365 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 10:56:33 +0800 Subject: [PATCH 48/85] add cs call --- sdk/c/api/jsep.h | 2 -- sdk/dotnet/webrtc/api/jsep.cs | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/c/api/jsep.h b/sdk/c/api/jsep.h index d84491be6a..ad1567a630 100644 --- a/sdk/c/api/jsep.h +++ b/sdk/c/api/jsep.h @@ -37,8 +37,6 @@ RTC_C_CLASS(webrtc::CreateSessionDescriptionObserver, RTC_C_CLASS(webrtc::SetSessionDescriptionObserver, WebrtcSetSessionDescriptionObserver) - - struct WebrtcCreateSessionDescriptionObserverFunctions { void (*on_destruction)(void*); void (*on_success)(void*, WebrtcSessionDescriptionInterface*); diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index f54cb13bab..955f30e9e4 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -428,6 +428,12 @@ public static class CreateSessionDescriptionObserver public static extern void Release(IntPtr ptr); } + public static class DataChannelObserver + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] + public static extern void Release(IntPtr ptr); + } + public static class SessionDescriptionInterface { [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteSessionDescriptionInterface")] From 081025ddb12b5232a0b8c71d02d6dc5de14cf04d Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 10:58:37 +0800 Subject: [PATCH 49/85] move header call --- sdk/c/api/data_channel_interface.h | 3 +++ sdk/c/api/jsep.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index ad6b9ad1a7..7f0999e455 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -25,6 +25,9 @@ struct WebrtcDataChannelObserverFunctions { void (*on_buffered_amount_change)(void*, uint64_t); }; +RTC_EXPORT void webrtcDataChannelObserverRelease( + const WebrtcDataChannelObserver* observer); + RTC_EXPORT void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel); diff --git a/sdk/c/api/jsep.h b/sdk/c/api/jsep.h index ad1567a630..c89a07fafc 100644 --- a/sdk/c/api/jsep.h +++ b/sdk/c/api/jsep.h @@ -54,9 +54,6 @@ RTC_EXPORT WebrtcSessionDescriptionInterface* webrtcCreateSessionDescription( const char* sdp, WebrtcSdpParseError** error); -RTC_EXPORT void webrtcDataChannelObserverRelease( - const WebrtcDataChannelObserver* observer); - RTC_EXPORT void webrtcCreateSessionDescriptionObserverRelease( const WebrtcCreateSessionDescriptionObserver* observer); From 4da9eaf656b80a6580ffeb29af233838ff092721 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 11:08:34 +0800 Subject: [PATCH 50/85] fixes --- sdk/c/api/data_channel_interface.cc | 9 --------- sdk/dotnet/webrtc/api/jsep.cs | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index 89a67000fe..d7ba0ff084 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -101,12 +101,3 @@ extern "C" void webrtcDataChannelObserverRelease( const WebrtcDataChannelObserver* observer) { rtc::ToCplusplus(observer)->Release(); } - -namespace Pixiv.Webrtc.Interop -{ - public static class DataChannelObserver - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] - public static extern void Release(IntPtr ptr); - } -} \ No newline at end of file diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 955f30e9e4..8b9c1494ac 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -114,6 +114,15 @@ private static extern IntPtr webrtcDataChannelRegisterObserver( IntPtr functions ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcDataChannelUnRegisterObserver( + IntPtr context + ); + public void Unregister() + { + webrtcDataChannelUnRegisterObserver(Ptr); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void DestructionHandler(IntPtr context); From 783973b7212aaaa778b4714e70e394bb86c13494 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 11:24:18 +0800 Subject: [PATCH 51/85] fixes --- sdk/c/api/data_channel_interface.cc | 4 ++-- sdk/c/api/data_channel_interface.h | 2 +- sdk/dotnet/webrtc/api/jsep.cs | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index d7ba0ff084..bd11bbb6ab 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -97,7 +97,7 @@ RTC_EXPORT extern "C" void webrtcDataChannelUnregisterObserver( chan->UnregisterObserver(); } -extern "C" void webrtcDataChannelObserverRelease( +extern "C" void webrtcDataChannelObserverDelete( const WebrtcDataChannelObserver* observer) { - rtc::ToCplusplus(observer)->Release(); + delete rtc::ToCplusplus(observer); } diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index 7f0999e455..f184290271 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -25,7 +25,7 @@ struct WebrtcDataChannelObserverFunctions { void (*on_buffered_amount_change)(void*, uint64_t); }; -RTC_EXPORT void webrtcDataChannelObserverRelease( +RTC_EXPORT void webrtcDataChannelObserverDelete( const WebrtcDataChannelObserver* observer); RTC_EXPORT void webrtcDataChannelInterfaceRelease( diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 8b9c1494ac..b236cafac1 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -118,10 +118,6 @@ IntPtr functions private static extern IntPtr webrtcDataChannelUnRegisterObserver( IntPtr context ); - public void Unregister() - { - webrtcDataChannelUnRegisterObserver(Ptr); - } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void DestructionHandler(IntPtr context); @@ -168,7 +164,8 @@ private static void OnBufferedAmountChange(IntPtr context, ulong sent_data_size) private protected override void FreePtr() { - Interop.DataChannelObserver.Release(Ptr); + webrtcDataChannelUnRegisterObserver(Ptr); + Interop.DataChannelObserver.Delete(Ptr); } [MonoPInvokeCallback(typeof(DestructionHandler))] @@ -439,8 +436,8 @@ public static class CreateSessionDescriptionObserver public static class DataChannelObserver { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverRelease")] - public static extern void Release(IntPtr ptr); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverDelete")] + public static extern void Delete(IntPtr ptr); } public static class SessionDescriptionInterface From 46ed2ee1b58d8fde9d3a5b0c03825b23f4951de1 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 11:27:46 +0800 Subject: [PATCH 52/85] remove delete --- sdk/c/api/data_channel_interface.cc | 5 ----- sdk/c/api/data_channel_interface.h | 3 --- sdk/dotnet/webrtc/api/jsep.cs | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index bd11bbb6ab..fb61d7836f 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -96,8 +96,3 @@ RTC_EXPORT extern "C" void webrtcDataChannelUnregisterObserver( auto chan = rtc::ToCplusplus(channel); chan->UnregisterObserver(); } - -extern "C" void webrtcDataChannelObserverDelete( - const WebrtcDataChannelObserver* observer) { - delete rtc::ToCplusplus(observer); -} diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index f184290271..ad6b9ad1a7 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -25,9 +25,6 @@ struct WebrtcDataChannelObserverFunctions { void (*on_buffered_amount_change)(void*, uint64_t); }; -RTC_EXPORT void webrtcDataChannelObserverDelete( - const WebrtcDataChannelObserver* observer); - RTC_EXPORT void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel); diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index b236cafac1..57f302f836 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -165,7 +165,7 @@ private static void OnBufferedAmountChange(IntPtr context, ulong sent_data_size) private protected override void FreePtr() { webrtcDataChannelUnRegisterObserver(Ptr); - Interop.DataChannelObserver.Delete(Ptr); + DataChannel.Dispose(); } [MonoPInvokeCallback(typeof(DestructionHandler))] From c5ba7f0800c977eca9737dd62deb1938dd814821 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 11:32:26 +0800 Subject: [PATCH 53/85] fix callback name --- sdk/c/api/data_channel_interface.h | 2 +- sdk/dotnet/webrtc/api/jsep.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/c/api/data_channel_interface.h b/sdk/c/api/data_channel_interface.h index ad6b9ad1a7..a67e677be3 100644 --- a/sdk/c/api/data_channel_interface.h +++ b/sdk/c/api/data_channel_interface.h @@ -48,7 +48,7 @@ RTC_EXPORT WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( WebrtcDataChannelInterface* channel, const struct WebrtcDataChannelObserverFunctions* functions); -RTC_EXPORT void webrtcDataChannelUnRegisterCallback( +RTC_EXPORT void webrtcDataChannelUnregisterObserver( WebrtcDataChannelInterface* channel); diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 57f302f836..68dfd00e71 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -115,7 +115,7 @@ IntPtr functions ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcDataChannelUnRegisterObserver( + private static extern IntPtr webrtcDataChannelUnregisterObserver( IntPtr context ); @@ -164,7 +164,7 @@ private static void OnBufferedAmountChange(IntPtr context, ulong sent_data_size) private protected override void FreePtr() { - webrtcDataChannelUnRegisterObserver(Ptr); + webrtcDataChannelUnregisterObserver(Ptr); DataChannel.Dispose(); } From 2ebc766fbf4c81bfbf125438d627201fee9b076d Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 11:50:02 +0800 Subject: [PATCH 54/85] fix naming --- sdk/dotnet/webrtc/api/jsep.cs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 68dfd00e71..6cf6cf1be7 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -107,17 +107,7 @@ public sealed class DisposableDataChannelObserver: DisposablePtr, IDisposableDat { IntPtr IDataChannelObserver.Ptr => Ptr; - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcDataChannelRegisterObserver( - IntPtr context, - IntPtr dataChannel, - IntPtr functions - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcDataChannelUnregisterObserver( - IntPtr context - ); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void DestructionHandler(IntPtr context); @@ -164,7 +154,7 @@ private static void OnBufferedAmountChange(IntPtr context, ulong sent_data_size) private protected override void FreePtr() { - webrtcDataChannelUnregisterObserver(Ptr); + Interop.DataChannel.UnregisterObserver(DataChannel.GetPtr); DataChannel.Dispose(); } @@ -178,7 +168,7 @@ public DisposableDataChannelObserver( IManagedDataChannelObserver implementation) { DataChannel = implementation.DataChannel; - Ptr = webrtcDataChannelRegisterObserver( + Ptr = Interop.DataChannel.RegisterObserver( (IntPtr)GCHandle.Alloc(implementation), implementation.DataChannel.GetPtr, s_functions.Ptr @@ -434,10 +424,19 @@ public static class CreateSessionDescriptionObserver public static extern void Release(IntPtr ptr); } - public static class DataChannelObserver + public static class DataChannel { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelObserverDelete")] - public static extern void Delete(IntPtr ptr); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelRegisterObserver")] + public static extern IntPtr RegisterObserver( + IntPtr context, + IntPtr dataChannel, + IntPtr functions + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelUnregisterObserver")] + public static extern void UnregisterObserver( + IntPtr context + ); } public static class SessionDescriptionInterface From 2b63289975231824ad29cb13dd1a92e704704ad4 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 15:36:19 +0800 Subject: [PATCH 55/85] Add linux build --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 5e035e7e18..6a14241dd8 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - WinX64 + LinuxX64;WinX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From 7333aad4d558862d60cc42977806d18058cbaf7c Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 5 Apr 2020 15:51:47 +0800 Subject: [PATCH 56/85] target x86 --- sdk/dotnet/unity/unity.msbuildproj | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 6a14241dd8..216f2e206c 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;WinX64 + LinuxX64;LinuxX86;WinX64;WinX86 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) @@ -28,7 +28,7 @@ "$(OutputPath.Replace('\', '\\').Replace('"', '\"'))" "$(Targets.Replace('\', '\\').Replace('"', '\"'))" - + + + + + + + + + + + Date: Sun, 5 Apr 2020 19:04:17 +0800 Subject: [PATCH 57/85] remove linux x86 --- sdk/dotnet/unity/unity.msbuildproj | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 216f2e206c..e544d4e348 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;LinuxX86;WinX64;WinX86 + LinuxX64;WinX64;WinX86 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) @@ -28,7 +28,7 @@ "$(OutputPath.Replace('\', '\\').Replace('"', '\"'))" "$(Targets.Replace('\', '\\').Replace('"', '\"'))" - + - - - - - Date: Sun, 5 Apr 2020 19:34:54 +0800 Subject: [PATCH 58/85] x86 win build update --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index e544d4e348..031d9572c4 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -92,7 +92,7 @@ Command="gn gen "--args=is_debug=$(IsDebug) rtc_enable_symbol_export=true target_os=\"win\" target_cpu=\"x86\"" --root=$(EscapedMSBuildThisFileDirectory)../../.. $(EscapedIntermediateOutputPath)win_x86" Condition="!Exists('$(IntermediateOutputPath)win_x86/build.ninja')" /> - + Date: Sun, 5 Apr 2020 19:38:32 +0800 Subject: [PATCH 59/85] remove x86 license generation --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 031d9572c4..1a1f5a6e7c 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -28,7 +28,7 @@ "$(OutputPath.Replace('\', '\\').Replace('"', '\"'))" "$(Targets.Replace('\', '\\').Replace('"', '\"'))" - + Date: Sun, 5 Apr 2020 19:40:43 +0800 Subject: [PATCH 60/85] add license --- sdk/dotnet/unity/unity.msbuildproj | 2 +- tools_webrtc/unity/generate_licenses.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 1a1f5a6e7c..031d9572c4 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -28,7 +28,7 @@ "$(OutputPath.Replace('\', '\\').Replace('"', '\"'))" "$(Targets.Replace('\', '\\').Replace('"', '\"'))" - + Date: Tue, 7 Apr 2020 20:35:40 +0800 Subject: [PATCH 61/85] add dummy audio devices --- sdk/dotnet/unity/unity.msbuildproj | 2 +- .../webrtc/api/media_stream_interface.cs | 4 +- .../webrtc/api/peer_connection_interface.cs | 2033 +++++++++-------- 3 files changed, 1023 insertions(+), 1016 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 031d9572c4..3368dde8a7 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -82,7 +82,7 @@ diff --git a/sdk/dotnet/webrtc/api/media_stream_interface.cs b/sdk/dotnet/webrtc/api/media_stream_interface.cs index 1f93d663bc..67d14d422c 100644 --- a/sdk/dotnet/webrtc/api/media_stream_interface.cs +++ b/sdk/dotnet/webrtc/api/media_stream_interface.cs @@ -347,8 +347,8 @@ public static void OnData( IntPtr audioData, int bitsPerSample, int sampleRate, - int numberOfChannels, - int numberOfFrames) + [MarshalAs(UnmanagedType.U4)] Int32 numberOfChannels, + [MarshalAs(UnmanagedType.U4)] Int32 numberOfFrames) { webrtcAudioTrackSinkInterfaceOnData( sink.Ptr, diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index 8b92752d98..b6f2f3aa3d 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -1,1015 +1,1022 @@ -/* - * Copyright 2019 pixiv Inc. 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. - */ - -using Pixiv.Cricket; -using Pixiv.Rtc; -using System; -using System.Runtime.InteropServices; - -namespace Pixiv.Webrtc -{ - public enum SdpSemantics - { - PlanB, - UnifiedPlan - } - - public interface IDisposablePeerConnectionFactoryInterface : - IPeerConnectionFactoryInterface, Rtc.IDisposable - { - } - - public interface IDisposablePeerConnectionInterface : - IPeerConnectionInterface, Rtc.IDisposable - { - } - - public interface IDisposablePeerConnectionObserver : - IPeerConnectionObserver, Rtc.IDisposable - { - } - - public interface IManagedPeerConnectionObserver - { - void OnSignalingChange(PeerConnectionInterface.SignalingState newState); - void OnAddStream(DisposableMediaStreamInterface stream); - void OnRemoveStream(DisposableMediaStreamInterface stream); - void OnDataChannel(DisposableDataChannelInterface dataChannel); - void OnRenegotiationNeeded(); - void OnIceConnectionChange(PeerConnectionInterface.IceConnectionState newState); - void OnStandardizedIceConnectionChange(PeerConnectionInterface.IceConnectionState newState); - void OnConnectionChange(); - void OnIceGatheringChange(PeerConnectionInterface.IceGatheringState newState); - void OnIceCandidate(IceCandidateInterface candidate); - void OnIceCandidatesRemoved(DisposableCandidate[] candidates); - void OnIceConnectionReceivingChange(bool receiving); - void OnAddTrack(DisposableRtpReceiverInterface receiver, DisposableMediaStreamInterface[] streams); - void OnTrack(DisposableRtpTransceiverInterface transceiver); - void OnRemoveTrack(DisposableRtpReceiverInterface receiver); - void OnInterestingUsage(int usagePattern); - } - - public interface IPeerConnectionFactoryInterface - { - IntPtr Ptr { get; } - } - - public interface IPeerConnectionInterface - { - IntPtr Ptr { get; } - } - - public interface IPeerConnectionObserver - { - IntPtr Ptr { get; } - } - - public sealed class DisposablePeerConnectionFactoryInterface : - DisposablePtr, IDisposablePeerConnectionFactoryInterface - { - IntPtr IPeerConnectionFactoryInterface.Ptr => Ptr; - - public DisposablePeerConnectionFactoryInterface(IntPtr ptr) - { - Ptr = ptr; - } - - private protected override void FreePtr() - { - Interop.PeerConnectionFactoryInterface.Release(Ptr); - } - } - - public sealed class DisposablePeerConnectionInterface : - DisposablePtr, IDisposablePeerConnectionInterface - { - IntPtr IPeerConnectionInterface.Ptr => Ptr; - - public DisposablePeerConnectionInterface(IntPtr ptr) - { - Ptr = ptr; - } - - private protected override void FreePtr() - { - Interop.PeerConnectionInterface.Release(Ptr); - } - } - - public sealed class DisposablePeerConnectionObserver : - DisposablePtr, IDisposablePeerConnectionObserver - { - IntPtr IPeerConnectionObserver.Ptr => Ptr; - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void DestructionHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void SignalingChangeHandler( - IntPtr context, - PeerConnectionInterface.SignalingState newState - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void AddStreamHandler( - IntPtr context, - IntPtr stream - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void RemoveStreamHandler( - IntPtr context, - IntPtr stream - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void DataChannelHandler( - IntPtr context, - IntPtr dataChannel - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void RenegotiationNeededHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void IceConnectionChangeHandler( - IntPtr context, - PeerConnectionInterface.IceConnectionState newState - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void StandardizedIceConnectionChangeHandler( - IntPtr context, - PeerConnectionInterface.IceConnectionState newState - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void ConnectionChangeHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void IceGatheringChangeHandler( - IntPtr context, - PeerConnectionInterface.IceGatheringState newState - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void IceCandidateHandler( - IntPtr context, - IntPtr candidate - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void IceCandidatesRemovedHandler( - IntPtr context, - IntPtr data, - [MarshalAs(UnmanagedType.SysUInt)] int size - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void IceConnectionReceivingChangeHandler( - IntPtr context, - bool receiving - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void AddTrackHandler( - IntPtr context, - IntPtr receiver, - IntPtr data, - [MarshalAs(UnmanagedType.SysUInt)] int size - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void TrackHandler( - IntPtr context, - IntPtr transceiver - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void RemoveTrackHandler( - IntPtr context, - IntPtr receiver - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void InterestingUsageHandler( - IntPtr context, - int usagePattern - ); - - private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( - (DestructionHandler)OnDestruction, - (SignalingChangeHandler)OnSignalingChange, - (AddStreamHandler)OnAddStream, - (RemoveStreamHandler)OnRemoveStream, - (DataChannelHandler)OnDataChannel, - (RenegotiationNeededHandler)OnRenegotiationNeeded, - (IceConnectionChangeHandler)OnIceConnectionChange, - (StandardizedIceConnectionChangeHandler)OnStandardizedIceConnectionChange, - (ConnectionChangeHandler)OnConnectionChange, - (IceGatheringChangeHandler)OnIceGatheringChange, - (IceCandidateHandler)OnIceCandidate, - (IceCandidatesRemovedHandler)OnIceCandidatesRemoved, - (IceConnectionReceivingChangeHandler)OnIceConnectionReceivingChange, - (AddTrackHandler)OnAddTrack, - (TrackHandler)OnTrack, - (RemoveTrackHandler)OnRemoveTrack, - (InterestingUsageHandler)OnInterestingUsage - ); - - private static IManagedPeerConnectionObserver GetContextTarget( - IntPtr context) - { - return (IManagedPeerConnectionObserver)((GCHandle)context).Target; - } - - [MonoPInvokeCallback(typeof(DestructionHandler))] - private static void OnDestruction(IntPtr context) - { - ((GCHandle)context).Free(); - } - - [MonoPInvokeCallback(typeof(SignalingChangeHandler))] - private static void OnSignalingChange( - IntPtr context, - PeerConnectionInterface.SignalingState newState) - { - GetContextTarget(context).OnSignalingChange(newState); - } - - [MonoPInvokeCallback(typeof(AddStreamHandler))] - private static void OnAddStream(IntPtr context, IntPtr stream) - { - GetContextTarget(context).OnAddStream( - new DisposableMediaStreamInterface(stream) - ); - } - - [MonoPInvokeCallback(typeof(RemoveStreamHandler))] - private static void OnRemoveStream(IntPtr context, IntPtr stream) - { - GetContextTarget(context).OnRemoveStream( - new DisposableMediaStreamInterface(stream) - ); - } - - [MonoPInvokeCallback(typeof(DataChannelHandler))] - private static void OnDataChannel(IntPtr context, IntPtr dataChannel) - { - GetContextTarget(context).OnDataChannel( - new DisposableDataChannelInterface(dataChannel) - ); - } - - [MonoPInvokeCallback(typeof(RenegotiationNeededHandler))] - private static void OnRenegotiationNeeded(IntPtr context) - { - GetContextTarget(context).OnRenegotiationNeeded(); - } - - [MonoPInvokeCallback(typeof(IceConnectionChangeHandler))] - private static void OnIceConnectionChange( - IntPtr context, - PeerConnectionInterface.IceConnectionState newState) - { - GetContextTarget(context).OnIceConnectionChange(newState); - } - - [MonoPInvokeCallback(typeof(StandardizedIceConnectionChangeHandler))] - private static void OnStandardizedIceConnectionChange( - IntPtr context, - PeerConnectionInterface.IceConnectionState newState) - { - GetContextTarget(context).OnStandardizedIceConnectionChange( - newState - ); - } - - [MonoPInvokeCallback(typeof(ConnectionChangeHandler))] - private static void OnConnectionChange(IntPtr context) - { - GetContextTarget(context).OnConnectionChange(); - } - - [MonoPInvokeCallback(typeof(IceGatheringChangeHandler))] - private static void OnIceGatheringChange( - IntPtr context, - PeerConnectionInterface.IceGatheringState newState) - { - GetContextTarget(context).OnIceGatheringChange(newState); - } - - [MonoPInvokeCallback(typeof(IceCandidateHandler))] - private static void OnIceCandidate(IntPtr context, IntPtr candidate) - { - GetContextTarget(context).OnIceCandidate( - new IceCandidateInterface(candidate) - ); - } - - [MonoPInvokeCallback(typeof(IceCandidatesRemovedHandler))] - private static void OnIceCandidatesRemoved( - IntPtr context, - IntPtr data, - int size) - { - var sizeOfIntPtr = Marshal.SizeOf(); - var candidates = new DisposableCandidate[size]; - - for (var index = 0; index < size; index++) - { - var ptr = Marshal.ReadIntPtr(data); - candidates[index] = new DisposableCandidate(ptr); - data += sizeOfIntPtr; - } - - GetContextTarget(context).OnIceCandidatesRemoved(candidates); - } - - [MonoPInvokeCallback(typeof(IceConnectionReceivingChangeHandler))] - private static void OnIceConnectionReceivingChange( - IntPtr context, - bool receiving) - { - GetContextTarget(context).OnIceConnectionReceivingChange( - receiving - ); - } - - [MonoPInvokeCallback(typeof(AddTrackHandler))] - private static void OnAddTrack( - IntPtr context, - IntPtr receiver, - IntPtr data, - int size) - { - var sizeOfIntPtr = Marshal.SizeOf(); - var streams = new DisposableMediaStreamInterface[size]; - - for (var index = 0; index < size; index++) - { - var ptr = Marshal.ReadIntPtr(data); - streams[index] = new DisposableMediaStreamInterface(ptr); - data += sizeOfIntPtr; - } - - GetContextTarget(context).OnAddTrack( - new DisposableRtpReceiverInterface(receiver), - streams - ); - } - - [MonoPInvokeCallback(typeof(TrackHandler))] - private static void OnTrack(IntPtr context, IntPtr transceiver) - { - GetContextTarget(context).OnTrack( - new DisposableRtpTransceiverInterface(transceiver) - ); - } - - [MonoPInvokeCallback(typeof(RemoveTrackHandler))] - private static void OnRemoveTrack(IntPtr context, IntPtr receiver) - { - GetContextTarget(context).OnRemoveTrack( - new DisposableRtpReceiverInterface(receiver) - ); - } - - [MonoPInvokeCallback(typeof(InterestingUsageHandler))] - private static void OnInterestingUsage(IntPtr context, int usagePattern) - { - GetContextTarget(context).OnInterestingUsage(usagePattern); - } - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcNewPeerConnectionObserver( - IntPtr context, - IntPtr functions - ); - - public DisposablePeerConnectionObserver( - IManagedPeerConnectionObserver managed) - { - Ptr = webrtcNewPeerConnectionObserver( - (IntPtr)GCHandle.Alloc(managed), - s_functions.Ptr - ); - } - - private protected override void FreePtr() - { - Interop.PeerConnectionObserver.Delete(Ptr); - } - } - - public sealed class PeerConnectionDependencies - { - public IPeerConnectionObserver Observer { get; set; } - - public IDisposablePortAllocator Allocator { get; set; } - - public IDisposableAsyncResolverFactory AsyncResolverFactory - { get; set; } - - public IDisposableRtcCertificateGeneratorInterface CertGenerator - { get; set; } - - public IDisposableSslCertificateVerifier TlsCertVerifier { get; set; } - - public IDisposableVideoBitrateAllocatorFactory VideoBitrateAllocatorFactory - { get; set; } - } - - public static class PeerConnectionFactoryInterfaceExtension - { - [Flags] - private enum WebrtcRTCConfigurationFlags - { - Dscp = 1 << 1, - CpuAdaptation = 1 << 2, - SuspendBelowMinBitrate = 1 << 3, - PrerendererSmoothing = 1 << 4, - ExperimentCpuLoadEstimator = 1 << 5 - } - - private struct WebrtcIceServer - { - public IntPtr Uri; - public IntPtr Urls; - public UIntPtr UrlsSize; - public IntPtr Username; - public IntPtr Password; - public PeerConnectionInterface.TlsCertPolicy TlsCertPolicy; - public IntPtr Hostname; - public IntPtr TlsAlpnProtocols; - public UIntPtr TlsAlpnProtocolsSize; - public IntPtr TlsEllipticCurves; - public UIntPtr TlsEllipticCurvesSize; - } - - private struct WebrtcPeerConnectionDependencies - { - public IntPtr Observer; - public IntPtr Allocator; - public IntPtr AsyncResolverFactory; - public IntPtr CertGenerator; - public IntPtr TlsCertVerifier; - public IntPtr VideoBitrateAllocatorFactory; - } - - private struct WebrtcRTCConfiguration - { - [MarshalAs(UnmanagedType.I4)] - public WebrtcRTCConfigurationFlags Flags; - public int AudioRtcpReportIntervalMs; - public int VideoRtcpReportIntervalMs; - public IntPtr Servers; - public UIntPtr ServersSize; - public PeerConnectionInterface.IceTransportsType Type; - public PeerConnectionInterface.BundlePolicy BundlePolicy; - public PeerConnectionInterface.RtcpMuxPolicy RtcpMuxPolicy; - public IntPtr Certificates; - public UIntPtr CertificatesSize; - public int IceCandidatePoolSize; - public SdpSemantics SdpSemantics; - } - - private static IntPtr StringArrayToHGlobalAnsiArrayPtr(string[] array) - { - var sizeOfIntPtr = Marshal.SizeOf(); - var ptr = Marshal.AllocHGlobal(array.Length * sizeOfIntPtr); - - for (var index = 0; index < array.Length; index++) - { - Marshal.WriteIntPtr( - ptr, - index * sizeOfIntPtr, - Marshal.StringToHGlobalAnsi(array[index]) - ); - } - - return ptr; - } - - private static void FreeHGlobalAnsiArrayPtr(IntPtr ptr, string[] array) - { - var sizeOfIntPtr = Marshal.SizeOf(); - - for (var index = 0; index < array.Length; index++) - { - Marshal.FreeHGlobal(Marshal.ReadIntPtr( - ptr, - index * sizeOfIntPtr - )); - } - - Marshal.FreeHGlobal(ptr); - } - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( - IntPtr factory, - in WebrtcRTCConfiguration configuration, - in WebrtcPeerConnectionDependencies dependencies); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( - IntPtr factory, - string label, - IntPtr source); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( - IntPtr factory, - string label, - IntPtr source); - - public static DisposablePeerConnectionInterface CreatePeerConnection( - this IPeerConnectionFactoryInterface factory, - PeerConnectionInterface.RtcConfiguration configuration, - PeerConnectionDependencies dependencies) - { - var servers = new WebrtcIceServer[configuration.Servers.Length]; - var sizeOfPtr = Marshal.SizeOf(); - var unmanagedConfiguration = new WebrtcRTCConfiguration(); - var unmanagedDependencies = new WebrtcPeerConnectionDependencies(); - - if (configuration.Dscp) - { - unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.Dscp; - } - - if (configuration.CpuAdaptation) - { - unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.CpuAdaptation; - } - - if (configuration.SuspendBelowMinBitrate) - { - unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.SuspendBelowMinBitrate; - } - - if (configuration.PrerendererSmoothing) - { - unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.PrerendererSmoothing; - } - - if (configuration.ExperimentCpuLoadEstimator) - { - unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.ExperimentCpuLoadEstimator; - } - - unmanagedConfiguration.AudioRtcpReportIntervalMs = configuration.AudioRtcpReportIntervalMs; - unmanagedConfiguration.VideoRtcpReportIntervalMs = configuration.VideoRtcpReportIntervalMs; - unmanagedConfiguration.ServersSize = new UIntPtr((uint)configuration.Servers.Length); - unmanagedConfiguration.Type = configuration.Type; - unmanagedConfiguration.BundlePolicy = configuration.BundlePolicy; - unmanagedConfiguration.RtcpMuxPolicy = configuration.RtcpMuxPolicy; - unmanagedConfiguration.CertificatesSize = new UIntPtr((uint)configuration.Certificates.Length); - unmanagedConfiguration.IceCandidatePoolSize = configuration.IceCandidatePoolSize; - unmanagedConfiguration.SdpSemantics = configuration.SdpSemantics; - - unmanagedDependencies.Observer = dependencies.Observer.Ptr; - - var serversHandle = GCHandle.Alloc(servers, GCHandleType.Pinned); - - for (var index = 0; index < configuration.Servers.Length; index++) - { - var server = configuration.Servers[index]; - ref var unmanagedServer = ref servers[index]; - - unmanagedServer.UrlsSize = new UIntPtr((uint)server.Urls.Length); - unmanagedServer.TlsCertPolicy = server.TlsCertPolicy; - unmanagedServer.TlsAlpnProtocolsSize = new UIntPtr((uint)server.TlsAlpnProtocols.Length); - unmanagedServer.TlsEllipticCurvesSize = new UIntPtr((uint)server.TlsEllipticCurves.Length); - - unmanagedServer.Uri = Marshal.StringToHGlobalAnsi(server.Uri); - unmanagedServer.Urls = StringArrayToHGlobalAnsiArrayPtr(server.Urls); - unmanagedServer.Username = Marshal.StringToHGlobalAnsi(server.Username); - unmanagedServer.Password = Marshal.StringToHGlobalAnsi(server.Password); - unmanagedServer.Hostname = Marshal.StringToHGlobalAnsi(server.Hostname); - unmanagedServer.TlsAlpnProtocols = StringArrayToHGlobalAnsiArrayPtr(server.TlsAlpnProtocols); - unmanagedServer.TlsEllipticCurves = StringArrayToHGlobalAnsiArrayPtr(server.TlsEllipticCurves); - } - - var certificatesCursor = Marshal.AllocHGlobal(sizeOfPtr * configuration.Certificates.Length); - unmanagedConfiguration.Certificates = certificatesCursor; - - try - { - if (dependencies.Allocator != null) - { - unmanagedDependencies.Allocator = dependencies.Allocator.Ptr; - dependencies.Allocator.ReleasePtr(); - } - - if (dependencies.AsyncResolverFactory != null) - { - unmanagedDependencies.AsyncResolverFactory = dependencies.AsyncResolverFactory.Ptr; - dependencies.AsyncResolverFactory.ReleasePtr(); - } - - if (dependencies.CertGenerator != null) - { - unmanagedDependencies.CertGenerator = dependencies.CertGenerator.Ptr; - dependencies.CertGenerator.ReleasePtr(); - } - - if (dependencies.TlsCertVerifier != null) - { - unmanagedDependencies.TlsCertVerifier = dependencies.TlsCertVerifier.Ptr; - dependencies.TlsCertVerifier.ReleasePtr(); - } - - if (dependencies.VideoBitrateAllocatorFactory != null) - { - unmanagedDependencies.VideoBitrateAllocatorFactory = dependencies.VideoBitrateAllocatorFactory.Ptr; - dependencies.VideoBitrateAllocatorFactory.ReleasePtr(); - } - - unmanagedConfiguration.Servers = serversHandle.AddrOfPinnedObject(); - - foreach (var certificate in configuration.Certificates) - { - Marshal.WriteIntPtr(certificatesCursor, certificate.Ptr); - certificatesCursor += sizeOfPtr; - } - - return new DisposablePeerConnectionInterface( - webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( - factory.Ptr, - unmanagedConfiguration, - unmanagedDependencies - ) - ); - } - finally - { - for (var index = 0; index < configuration.Servers.Length; index++) - { - var server = configuration.Servers[index]; - ref var unmanagedServer = ref servers[index]; - - FreeHGlobalAnsiArrayPtr( - unmanagedServer.TlsEllipticCurves, - server.TlsEllipticCurves - ); - - FreeHGlobalAnsiArrayPtr( - unmanagedServer.TlsAlpnProtocols, - server.TlsAlpnProtocols - ); - - FreeHGlobalAnsiArrayPtr( - unmanagedServer.Urls, - server.Urls - ); - - Marshal.FreeHGlobal(unmanagedServer.Hostname); - Marshal.FreeHGlobal(unmanagedServer.Password); - Marshal.FreeHGlobal(unmanagedServer.Username); - Marshal.FreeHGlobal(unmanagedServer.Uri); - } - - Marshal.FreeHGlobal(unmanagedConfiguration.Certificates); - serversHandle.Free(); - } - } - - public static DisposableAudioTrackInterface CreateAudioTrack( - this IPeerConnectionFactoryInterface factory, - string label, - IAudioSourceInterface source) - { - return new DisposableAudioTrackInterface( - Interop.AudioTrackInterface.ToWebrtcMediaStreamTrackInterface( - webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( - factory.Ptr, - label, - source.Ptr - ) - ) - ); - } - - public static DisposableVideoTrackInterface CreateVideoTrack( - this IPeerConnectionFactoryInterface factory, - string label, - IVideoTrackSourceInterface source) - { - return new DisposableVideoTrackInterface( - Interop.VideoTrackInterface.ToWebrtcMediaStreamTrackInterface( - webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( - factory.Ptr, - label, - source.Ptr - ) - ) - ); - } - } - - public static class PeerConnectionInterface - { - public enum SignalingState - { - Stable, - HaveLocalOffer, - HaveLocalPrAnswer, - HaveRemoteOffer, - HaveRemotePrAnswer, - Closed, - } - - public enum IceGatheringState - { - New, - Gathering, - Complete - } - - public enum IceConnectionState - { - New, - Checking, - Connected, - Completed, - Failed, - Disconnected, - Closed, - Max, - } - - public enum IceTransportsType - { - None, - Relay, - NoHost, - All - } - - public enum BundlePolicy - { - Balanced, - MaxBundle, - MaxCompat - } - - public enum RtcpMuxPolicy - { - Negotiate, - Require, - } - - public enum TlsCertPolicy - { - Secure, - InsecureNoCheck - } - - public sealed class IceServer - { - public string Uri { get; set; } - public string[] Urls { get; set; } = new string[0]; - public string Username { get; set; } - public string Password { get; set; } - public TlsCertPolicy TlsCertPolicy { get; set; } = - TlsCertPolicy.Secure; - public string Hostname { get; set; } - public string[] TlsAlpnProtocols { get; set; } = new string[0]; - public string[] TlsEllipticCurves { get; set; } = new string[0]; - } - - public sealed class RtcConfiguration - { - public bool Dscp { get; set; } - public bool CpuAdaptation { get; set; } - public bool SuspendBelowMinBitrate { get; set; } - public bool PrerendererSmoothing { get; set; } - public bool ExperimentCpuLoadEstimator { get; set; } - public int AudioRtcpReportIntervalMs { get; set; } = 5000; - public int VideoRtcpReportIntervalMs { get; set; } = 1000; - public IceServer[] Servers { get; set; } = new IceServer[0]; - public IceTransportsType Type { get; set; } = IceTransportsType.All; - public BundlePolicy BundlePolicy { get; set; } = - BundlePolicy.Balanced; - public RtcpMuxPolicy RtcpMuxPolicy { get; set; } = - RtcpMuxPolicy.Require; - public IRtcCertificate[] Certificates { get; set; } = - new IRtcCertificate[0]; - public int IceCandidatePoolSize { get; set; } = 0; - public SdpSemantics SdpSemantics; - } - - [StructLayout(LayoutKind.Sequential)] - public sealed class RtcOfferAnswerOptions - { - public const int Undefined = -1; - public const int MaxOfferToReceiveMedia = 1; - public const int OfferToReceiveMediaTrue = 1; - - public int OfferToReceiveVideo { get; set; } = Undefined; - public int OfferToReceiveAudio { get; set; } = Undefined; - - [field: MarshalAs(UnmanagedType.I1)] - public bool VoiceActivityDetection { get; set; } = true; - - [field: MarshalAs(UnmanagedType.I1)] - public bool IceRestart { get; set; } = false; - - [field: MarshalAs(UnmanagedType.I1)] - public bool UseRtpMux { get; set; } = true; - - [field: MarshalAs(UnmanagedType.I1)] - public bool RawPacketizationForVideo { get; set; } = false; - - public int NumSimulcastLayers { get; set; } = 1; - - [field: MarshalAs(UnmanagedType.I1)] - public bool UseObsoleteSctpSdp = false; - } - } - - public static class PeerConnectionInterfaceExtension - { - private readonly struct WebrtcAddTrackResult - { -#pragma warning disable 0649 - public readonly IntPtr Error; - public readonly IntPtr Value; -#pragma warning restore 0649 - } - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern WebrtcAddTrackResult webrtcPeerConnectionInterfaceAddTrack( - IntPtr connection, - IntPtr track, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] string[] data, - int size - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern bool webrtcPeerConnectionInterfaceAddICECandidate( - IntPtr connection, - [MarshalAs(UnmanagedType.LPStr)] string sdpMid, - int sdpMLineIndex, - [MarshalAs(UnmanagedType.LPStr)] string sdp - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcPeerConnectionInterfaceCreateAnswer( - IntPtr connection, - IntPtr observer, - PeerConnectionInterface.RtcOfferAnswerOptions options - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcPeerConnectionInterfaceCreateOffer( - IntPtr connection, - IntPtr observer, - PeerConnectionInterface.RtcOfferAnswerOptions options - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcPeerConnectionInterfaceClose( - IntPtr connection - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcPeerConnectionInterfaceSetAudioRecording( - IntPtr connection, - [MarshalAs(UnmanagedType.I1)] bool recording - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcPeerConnectionInterfaceSetLocalDescription( - IntPtr connection, - IntPtr observer, - IntPtr desc - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcPeerConnectionInterfaceSetRemoteDescription( - IntPtr connection, - IntPtr observer, - IntPtr desc - ); - - public static RtcErrorOr AddTrack( - this IPeerConnectionInterface connection, - IMediaStreamTrackInterface track, - string[] streamIds) - { - RtcError error; - - var result = webrtcPeerConnectionInterfaceAddTrack( - connection.Ptr, track.Ptr, streamIds, streamIds.Length); - - try - { - error = new RtcError(result.Error); - } - finally - { - Interop.RtcError.Delete(result.Error); - } - - var value = error.Type == RtcErrorType.None ? - new DisposableRtpSenderInterface(result.Value) : null; - - return new RtcErrorOr(error, value); - } - - public static bool AddICECandidate(this IPeerConnectionInterface connection, - string sdpMid, - int sdpMlineIndex, - string sdp) - { - var result = webrtcPeerConnectionInterfaceAddICECandidate( +/* + * Copyright 2019 pixiv Inc. 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. + */ + +using Pixiv.Cricket; +using Pixiv.Rtc; +using System; +using System.Runtime.InteropServices; + +namespace Pixiv.Webrtc +{ + public enum SdpSemantics + { + PlanB, + UnifiedPlan + } + + public interface IDisposablePeerConnectionFactoryInterface : + IPeerConnectionFactoryInterface, Rtc.IDisposable + { + } + + public interface IDisposablePeerConnectionInterface : + IPeerConnectionInterface, Rtc.IDisposable + { + } + + public interface IDisposablePeerConnectionObserver : + IPeerConnectionObserver, Rtc.IDisposable + { + } + + public interface IManagedPeerConnectionObserver + { + void OnSignalingChange(PeerConnectionInterface.SignalingState newState); + void OnAddStream(DisposableMediaStreamInterface stream); + void OnRemoveStream(DisposableMediaStreamInterface stream); + void OnDataChannel(DisposableDataChannelInterface dataChannel); + void OnRenegotiationNeeded(); + void OnIceConnectionChange(PeerConnectionInterface.IceConnectionState newState); + void OnStandardizedIceConnectionChange(PeerConnectionInterface.IceConnectionState newState); + void OnConnectionChange(); + void OnIceGatheringChange(PeerConnectionInterface.IceGatheringState newState); + void OnIceCandidate(IceCandidateInterface candidate); + void OnIceCandidatesRemoved(DisposableCandidate[] candidates); + void OnIceConnectionReceivingChange(bool receiving); + void OnAddTrack(DisposableRtpReceiverInterface receiver, DisposableMediaStreamInterface[] streams); + void OnTrack(DisposableRtpTransceiverInterface transceiver); + void OnRemoveTrack(DisposableRtpReceiverInterface receiver); + void OnInterestingUsage(int usagePattern); + } + + public interface IPeerConnectionFactoryInterface + { + IntPtr Ptr { get; } + } + + public interface IPeerConnectionInterface + { + IntPtr Ptr { get; } + } + + public interface IPeerConnectionObserver + { + IntPtr Ptr { get; } + } + + public sealed class DisposablePeerConnectionFactoryInterface : + DisposablePtr, IDisposablePeerConnectionFactoryInterface + { + IntPtr IPeerConnectionFactoryInterface.Ptr => Ptr; + + public DisposablePeerConnectionFactoryInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.PeerConnectionFactoryInterface.Release(Ptr); + } + } + + public sealed class DisposablePeerConnectionInterface : + DisposablePtr, IDisposablePeerConnectionInterface + { + IntPtr IPeerConnectionInterface.Ptr => Ptr; + + public DisposablePeerConnectionInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.PeerConnectionInterface.Release(Ptr); + } + } + + public sealed class DisposablePeerConnectionObserver : + DisposablePtr, IDisposablePeerConnectionObserver + { + IntPtr IPeerConnectionObserver.Ptr => Ptr; + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void DestructionHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void SignalingChangeHandler( + IntPtr context, + PeerConnectionInterface.SignalingState newState + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void AddStreamHandler( + IntPtr context, + IntPtr stream + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void RemoveStreamHandler( + IntPtr context, + IntPtr stream + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void DataChannelHandler( + IntPtr context, + IntPtr dataChannel + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void RenegotiationNeededHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void IceConnectionChangeHandler( + IntPtr context, + PeerConnectionInterface.IceConnectionState newState + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void StandardizedIceConnectionChangeHandler( + IntPtr context, + PeerConnectionInterface.IceConnectionState newState + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void ConnectionChangeHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void IceGatheringChangeHandler( + IntPtr context, + PeerConnectionInterface.IceGatheringState newState + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void IceCandidateHandler( + IntPtr context, + IntPtr candidate + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void IceCandidatesRemovedHandler( + IntPtr context, + IntPtr data, + [MarshalAs(UnmanagedType.U4)] Int32 size + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void IceConnectionReceivingChangeHandler( + IntPtr context, + bool receiving + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void AddTrackHandler( + IntPtr context, + IntPtr receiver, + IntPtr data, + [MarshalAs(UnmanagedType.U4)] Int32 size + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void TrackHandler( + IntPtr context, + IntPtr transceiver + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void RemoveTrackHandler( + IntPtr context, + IntPtr receiver + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void InterestingUsageHandler( + IntPtr context, + int usagePattern + ); + + private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( + (DestructionHandler)OnDestruction, + (SignalingChangeHandler)OnSignalingChange, + (AddStreamHandler)OnAddStream, + (RemoveStreamHandler)OnRemoveStream, + (DataChannelHandler)OnDataChannel, + (RenegotiationNeededHandler)OnRenegotiationNeeded, + (IceConnectionChangeHandler)OnIceConnectionChange, + (StandardizedIceConnectionChangeHandler)OnStandardizedIceConnectionChange, + (ConnectionChangeHandler)OnConnectionChange, + (IceGatheringChangeHandler)OnIceGatheringChange, + (IceCandidateHandler)OnIceCandidate, + (IceCandidatesRemovedHandler)OnIceCandidatesRemoved, + (IceConnectionReceivingChangeHandler)OnIceConnectionReceivingChange, + (AddTrackHandler)OnAddTrack, + (TrackHandler)OnTrack, + (RemoveTrackHandler)OnRemoveTrack, + (InterestingUsageHandler)OnInterestingUsage + ); + + private static IManagedPeerConnectionObserver GetContextTarget( + IntPtr context) + { + return (IManagedPeerConnectionObserver)((GCHandle)context).Target; + } + + [MonoPInvokeCallback(typeof(DestructionHandler))] + private static void OnDestruction(IntPtr context) + { + ((GCHandle)context).Free(); + } + + [MonoPInvokeCallback(typeof(SignalingChangeHandler))] + private static void OnSignalingChange( + IntPtr context, + PeerConnectionInterface.SignalingState newState) + { + GetContextTarget(context).OnSignalingChange(newState); + } + + [MonoPInvokeCallback(typeof(AddStreamHandler))] + private static void OnAddStream(IntPtr context, IntPtr stream) + { + GetContextTarget(context).OnAddStream( + new DisposableMediaStreamInterface(stream) + ); + } + + [MonoPInvokeCallback(typeof(RemoveStreamHandler))] + private static void OnRemoveStream(IntPtr context, IntPtr stream) + { + GetContextTarget(context).OnRemoveStream( + new DisposableMediaStreamInterface(stream) + ); + } + + [MonoPInvokeCallback(typeof(DataChannelHandler))] + private static void OnDataChannel(IntPtr context, IntPtr dataChannel) + { + GetContextTarget(context).OnDataChannel( + new DisposableDataChannelInterface(dataChannel) + ); + } + + [MonoPInvokeCallback(typeof(RenegotiationNeededHandler))] + private static void OnRenegotiationNeeded(IntPtr context) + { + GetContextTarget(context).OnRenegotiationNeeded(); + } + + [MonoPInvokeCallback(typeof(IceConnectionChangeHandler))] + private static void OnIceConnectionChange( + IntPtr context, + PeerConnectionInterface.IceConnectionState newState) + { + GetContextTarget(context).OnIceConnectionChange(newState); + } + + [MonoPInvokeCallback(typeof(StandardizedIceConnectionChangeHandler))] + private static void OnStandardizedIceConnectionChange( + IntPtr context, + PeerConnectionInterface.IceConnectionState newState) + { + GetContextTarget(context).OnStandardizedIceConnectionChange( + newState + ); + } + + [MonoPInvokeCallback(typeof(ConnectionChangeHandler))] + private static void OnConnectionChange(IntPtr context) + { + GetContextTarget(context).OnConnectionChange(); + } + + [MonoPInvokeCallback(typeof(IceGatheringChangeHandler))] + private static void OnIceGatheringChange( + IntPtr context, + PeerConnectionInterface.IceGatheringState newState) + { + GetContextTarget(context).OnIceGatheringChange(newState); + } + + [MonoPInvokeCallback(typeof(IceCandidateHandler))] + private static void OnIceCandidate(IntPtr context, IntPtr candidate) + { + GetContextTarget(context).OnIceCandidate( + new IceCandidateInterface(candidate) + ); + } + + [MonoPInvokeCallback(typeof(IceCandidatesRemovedHandler))] + private static void OnIceCandidatesRemoved( + IntPtr context, + IntPtr data, + [MarshalAs(UnmanagedType.U4)] Int32 size) + { + var sizeOfIntPtr = Marshal.SizeOf(); + var candidates = new DisposableCandidate[size]; + + for (var index = 0; index < size; index++) + { + var ptr = Marshal.ReadIntPtr(data); + candidates[index] = new DisposableCandidate(ptr); + data += sizeOfIntPtr; + } + + GetContextTarget(context).OnIceCandidatesRemoved(candidates); + } + + [MonoPInvokeCallback(typeof(IceConnectionReceivingChangeHandler))] + private static void OnIceConnectionReceivingChange( + IntPtr context, + bool receiving) + { + GetContextTarget(context).OnIceConnectionReceivingChange( + receiving + ); + } + + [MonoPInvokeCallback(typeof(AddTrackHandler))] + private static void OnAddTrack( + IntPtr context, + IntPtr receiver, + IntPtr data, + [MarshalAs(UnmanagedType.U4)] Int32 size) + { + var sizeOfIntPtr = Marshal.SizeOf(); + var streams = new DisposableMediaStreamInterface[size]; + + for (var index = 0; index < size; index++) + { + var ptr = Marshal.ReadIntPtr(data); + streams[index] = new DisposableMediaStreamInterface(ptr); + data += sizeOfIntPtr; + } + + GetContextTarget(context).OnAddTrack( + new DisposableRtpReceiverInterface(receiver), + streams + ); + } + + [MonoPInvokeCallback(typeof(TrackHandler))] + private static void OnTrack(IntPtr context, IntPtr transceiver) + { + GetContextTarget(context).OnTrack( + new DisposableRtpTransceiverInterface(transceiver) + ); + } + + [MonoPInvokeCallback(typeof(RemoveTrackHandler))] + private static void OnRemoveTrack(IntPtr context, IntPtr receiver) + { + GetContextTarget(context).OnRemoveTrack( + new DisposableRtpReceiverInterface(receiver) + ); + } + + [MonoPInvokeCallback(typeof(InterestingUsageHandler))] + private static void OnInterestingUsage(IntPtr context, int usagePattern) + { + GetContextTarget(context).OnInterestingUsage(usagePattern); + } + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcNewPeerConnectionObserver( + IntPtr context, + IntPtr functions + ); + + public DisposablePeerConnectionObserver( + IManagedPeerConnectionObserver managed) + { + try + { + Ptr = webrtcNewPeerConnectionObserver( + (IntPtr)GCHandle.Alloc(managed), + s_functions.Ptr + ); + } + catch(Exception ex) + { + var m = ex.Message; + } + } + + private protected override void FreePtr() + { + Interop.PeerConnectionObserver.Delete(Ptr); + } + } + + public sealed class PeerConnectionDependencies + { + public IPeerConnectionObserver Observer { get; set; } + + public IDisposablePortAllocator Allocator { get; set; } + + public IDisposableAsyncResolverFactory AsyncResolverFactory + { get; set; } + + public IDisposableRtcCertificateGeneratorInterface CertGenerator + { get; set; } + + public IDisposableSslCertificateVerifier TlsCertVerifier { get; set; } + + public IDisposableVideoBitrateAllocatorFactory VideoBitrateAllocatorFactory + { get; set; } + } + + public static class PeerConnectionFactoryInterfaceExtension + { + [Flags] + private enum WebrtcRTCConfigurationFlags + { + Dscp = 1 << 1, + CpuAdaptation = 1 << 2, + SuspendBelowMinBitrate = 1 << 3, + PrerendererSmoothing = 1 << 4, + ExperimentCpuLoadEstimator = 1 << 5 + } + + private struct WebrtcIceServer + { + public IntPtr Uri; + public IntPtr Urls; + public UIntPtr UrlsSize; + public IntPtr Username; + public IntPtr Password; + public PeerConnectionInterface.TlsCertPolicy TlsCertPolicy; + public IntPtr Hostname; + public IntPtr TlsAlpnProtocols; + public UIntPtr TlsAlpnProtocolsSize; + public IntPtr TlsEllipticCurves; + public UIntPtr TlsEllipticCurvesSize; + } + + private struct WebrtcPeerConnectionDependencies + { + public IntPtr Observer; + public IntPtr Allocator; + public IntPtr AsyncResolverFactory; + public IntPtr CertGenerator; + public IntPtr TlsCertVerifier; + public IntPtr VideoBitrateAllocatorFactory; + } + + private struct WebrtcRTCConfiguration + { + [MarshalAs(UnmanagedType.I4)] + public WebrtcRTCConfigurationFlags Flags; + public int AudioRtcpReportIntervalMs; + public int VideoRtcpReportIntervalMs; + public IntPtr Servers; + public UIntPtr ServersSize; + public PeerConnectionInterface.IceTransportsType Type; + public PeerConnectionInterface.BundlePolicy BundlePolicy; + public PeerConnectionInterface.RtcpMuxPolicy RtcpMuxPolicy; + public IntPtr Certificates; + public UIntPtr CertificatesSize; + public int IceCandidatePoolSize; + public SdpSemantics SdpSemantics; + } + + private static IntPtr StringArrayToHGlobalAnsiArrayPtr(string[] array) + { + var sizeOfIntPtr = Marshal.SizeOf(); + var ptr = Marshal.AllocHGlobal(array.Length * sizeOfIntPtr); + + for (var index = 0; index < array.Length; index++) + { + Marshal.WriteIntPtr( + ptr, + index * sizeOfIntPtr, + Marshal.StringToHGlobalAnsi(array[index]) + ); + } + + return ptr; + } + + private static void FreeHGlobalAnsiArrayPtr(IntPtr ptr, string[] array) + { + var sizeOfIntPtr = Marshal.SizeOf(); + + for (var index = 0; index < array.Length; index++) + { + Marshal.FreeHGlobal(Marshal.ReadIntPtr( + ptr, + index * sizeOfIntPtr + )); + } + + Marshal.FreeHGlobal(ptr); + } + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( + IntPtr factory, + in WebrtcRTCConfiguration configuration, + in WebrtcPeerConnectionDependencies dependencies); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( + IntPtr factory, + string label, + IntPtr source); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( + IntPtr factory, + string label, + IntPtr source); + + public static DisposablePeerConnectionInterface CreatePeerConnection( + this IPeerConnectionFactoryInterface factory, + PeerConnectionInterface.RtcConfiguration configuration, + PeerConnectionDependencies dependencies) + { + var servers = new WebrtcIceServer[configuration.Servers.Length]; + var sizeOfPtr = Marshal.SizeOf(); + var unmanagedConfiguration = new WebrtcRTCConfiguration(); + var unmanagedDependencies = new WebrtcPeerConnectionDependencies(); + + if (configuration.Dscp) + { + unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.Dscp; + } + + if (configuration.CpuAdaptation) + { + unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.CpuAdaptation; + } + + if (configuration.SuspendBelowMinBitrate) + { + unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.SuspendBelowMinBitrate; + } + + if (configuration.PrerendererSmoothing) + { + unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.PrerendererSmoothing; + } + + if (configuration.ExperimentCpuLoadEstimator) + { + unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.ExperimentCpuLoadEstimator; + } + + unmanagedConfiguration.AudioRtcpReportIntervalMs = configuration.AudioRtcpReportIntervalMs; + unmanagedConfiguration.VideoRtcpReportIntervalMs = configuration.VideoRtcpReportIntervalMs; + unmanagedConfiguration.ServersSize = new UIntPtr((uint)configuration.Servers.Length); + unmanagedConfiguration.Type = configuration.Type; + unmanagedConfiguration.BundlePolicy = configuration.BundlePolicy; + unmanagedConfiguration.RtcpMuxPolicy = configuration.RtcpMuxPolicy; + unmanagedConfiguration.CertificatesSize = new UIntPtr((uint)configuration.Certificates.Length); + unmanagedConfiguration.IceCandidatePoolSize = configuration.IceCandidatePoolSize; + unmanagedConfiguration.SdpSemantics = configuration.SdpSemantics; + + unmanagedDependencies.Observer = dependencies.Observer.Ptr; + + var serversHandle = GCHandle.Alloc(servers, GCHandleType.Pinned); + + for (var index = 0; index < configuration.Servers.Length; index++) + { + var server = configuration.Servers[index]; + ref var unmanagedServer = ref servers[index]; + + unmanagedServer.UrlsSize = new UIntPtr((uint)server.Urls.Length); + unmanagedServer.TlsCertPolicy = server.TlsCertPolicy; + unmanagedServer.TlsAlpnProtocolsSize = new UIntPtr((uint)server.TlsAlpnProtocols.Length); + unmanagedServer.TlsEllipticCurvesSize = new UIntPtr((uint)server.TlsEllipticCurves.Length); + + unmanagedServer.Uri = Marshal.StringToHGlobalAnsi(server.Uri); + unmanagedServer.Urls = StringArrayToHGlobalAnsiArrayPtr(server.Urls); + unmanagedServer.Username = Marshal.StringToHGlobalAnsi(server.Username); + unmanagedServer.Password = Marshal.StringToHGlobalAnsi(server.Password); + unmanagedServer.Hostname = Marshal.StringToHGlobalAnsi(server.Hostname); + unmanagedServer.TlsAlpnProtocols = StringArrayToHGlobalAnsiArrayPtr(server.TlsAlpnProtocols); + unmanagedServer.TlsEllipticCurves = StringArrayToHGlobalAnsiArrayPtr(server.TlsEllipticCurves); + } + + var certificatesCursor = Marshal.AllocHGlobal(sizeOfPtr * configuration.Certificates.Length); + unmanagedConfiguration.Certificates = certificatesCursor; + + try + { + if (dependencies.Allocator != null) + { + unmanagedDependencies.Allocator = dependencies.Allocator.Ptr; + dependencies.Allocator.ReleasePtr(); + } + + if (dependencies.AsyncResolverFactory != null) + { + unmanagedDependencies.AsyncResolverFactory = dependencies.AsyncResolverFactory.Ptr; + dependencies.AsyncResolverFactory.ReleasePtr(); + } + + if (dependencies.CertGenerator != null) + { + unmanagedDependencies.CertGenerator = dependencies.CertGenerator.Ptr; + dependencies.CertGenerator.ReleasePtr(); + } + + if (dependencies.TlsCertVerifier != null) + { + unmanagedDependencies.TlsCertVerifier = dependencies.TlsCertVerifier.Ptr; + dependencies.TlsCertVerifier.ReleasePtr(); + } + + if (dependencies.VideoBitrateAllocatorFactory != null) + { + unmanagedDependencies.VideoBitrateAllocatorFactory = dependencies.VideoBitrateAllocatorFactory.Ptr; + dependencies.VideoBitrateAllocatorFactory.ReleasePtr(); + } + + unmanagedConfiguration.Servers = serversHandle.AddrOfPinnedObject(); + + foreach (var certificate in configuration.Certificates) + { + Marshal.WriteIntPtr(certificatesCursor, certificate.Ptr); + certificatesCursor += sizeOfPtr; + } + + return new DisposablePeerConnectionInterface( + webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( + factory.Ptr, + unmanagedConfiguration, + unmanagedDependencies + ) + ); + } + finally + { + for (var index = 0; index < configuration.Servers.Length; index++) + { + var server = configuration.Servers[index]; + ref var unmanagedServer = ref servers[index]; + + FreeHGlobalAnsiArrayPtr( + unmanagedServer.TlsEllipticCurves, + server.TlsEllipticCurves + ); + + FreeHGlobalAnsiArrayPtr( + unmanagedServer.TlsAlpnProtocols, + server.TlsAlpnProtocols + ); + + FreeHGlobalAnsiArrayPtr( + unmanagedServer.Urls, + server.Urls + ); + + Marshal.FreeHGlobal(unmanagedServer.Hostname); + Marshal.FreeHGlobal(unmanagedServer.Password); + Marshal.FreeHGlobal(unmanagedServer.Username); + Marshal.FreeHGlobal(unmanagedServer.Uri); + } + + Marshal.FreeHGlobal(unmanagedConfiguration.Certificates); + serversHandle.Free(); + } + } + + public static DisposableAudioTrackInterface CreateAudioTrack( + this IPeerConnectionFactoryInterface factory, + string label, + IAudioSourceInterface source) + { + return new DisposableAudioTrackInterface( + Interop.AudioTrackInterface.ToWebrtcMediaStreamTrackInterface( + webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( + factory.Ptr, + label, + source.Ptr + ) + ) + ); + } + + public static DisposableVideoTrackInterface CreateVideoTrack( + this IPeerConnectionFactoryInterface factory, + string label, + IVideoTrackSourceInterface source) + { + return new DisposableVideoTrackInterface( + Interop.VideoTrackInterface.ToWebrtcMediaStreamTrackInterface( + webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( + factory.Ptr, + label, + source.Ptr + ) + ) + ); + } + } + + public static class PeerConnectionInterface + { + public enum SignalingState + { + Stable, + HaveLocalOffer, + HaveLocalPrAnswer, + HaveRemoteOffer, + HaveRemotePrAnswer, + Closed, + } + + public enum IceGatheringState + { + New, + Gathering, + Complete + } + + public enum IceConnectionState + { + New, + Checking, + Connected, + Completed, + Failed, + Disconnected, + Closed, + Max, + } + + public enum IceTransportsType + { + None, + Relay, + NoHost, + All + } + + public enum BundlePolicy + { + Balanced, + MaxBundle, + MaxCompat + } + + public enum RtcpMuxPolicy + { + Negotiate, + Require, + } + + public enum TlsCertPolicy + { + Secure, + InsecureNoCheck + } + + public sealed class IceServer + { + public string Uri { get; set; } + public string[] Urls { get; set; } = new string[0]; + public string Username { get; set; } + public string Password { get; set; } + public TlsCertPolicy TlsCertPolicy { get; set; } = + TlsCertPolicy.Secure; + public string Hostname { get; set; } + public string[] TlsAlpnProtocols { get; set; } = new string[0]; + public string[] TlsEllipticCurves { get; set; } = new string[0]; + } + + public sealed class RtcConfiguration + { + public bool Dscp { get; set; } + public bool CpuAdaptation { get; set; } + public bool SuspendBelowMinBitrate { get; set; } + public bool PrerendererSmoothing { get; set; } + public bool ExperimentCpuLoadEstimator { get; set; } + public int AudioRtcpReportIntervalMs { get; set; } = 5000; + public int VideoRtcpReportIntervalMs { get; set; } = 1000; + public IceServer[] Servers { get; set; } = new IceServer[0]; + public IceTransportsType Type { get; set; } = IceTransportsType.All; + public BundlePolicy BundlePolicy { get; set; } = + BundlePolicy.Balanced; + public RtcpMuxPolicy RtcpMuxPolicy { get; set; } = + RtcpMuxPolicy.Require; + public IRtcCertificate[] Certificates { get; set; } = + new IRtcCertificate[0]; + public int IceCandidatePoolSize { get; set; } = 0; + public SdpSemantics SdpSemantics; + } + + [StructLayout(LayoutKind.Sequential)] + public sealed class RtcOfferAnswerOptions + { + public const int Undefined = -1; + public const int MaxOfferToReceiveMedia = 1; + public const int OfferToReceiveMediaTrue = 1; + + public int OfferToReceiveVideo { get; set; } = Undefined; + public int OfferToReceiveAudio { get; set; } = Undefined; + + [field: MarshalAs(UnmanagedType.I1)] + public bool VoiceActivityDetection { get; set; } = true; + + [field: MarshalAs(UnmanagedType.I1)] + public bool IceRestart { get; set; } = false; + + [field: MarshalAs(UnmanagedType.I1)] + public bool UseRtpMux { get; set; } = true; + + [field: MarshalAs(UnmanagedType.I1)] + public bool RawPacketizationForVideo { get; set; } = false; + + public int NumSimulcastLayers { get; set; } = 1; + + [field: MarshalAs(UnmanagedType.I1)] + public bool UseObsoleteSctpSdp = false; + } + } + + public static class PeerConnectionInterfaceExtension + { + private readonly struct WebrtcAddTrackResult + { +#pragma warning disable 0649 + public readonly IntPtr Error; + public readonly IntPtr Value; +#pragma warning restore 0649 + } + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern WebrtcAddTrackResult webrtcPeerConnectionInterfaceAddTrack( + IntPtr connection, + IntPtr track, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] string[] data, + [MarshalAs(UnmanagedType.U4)] Int32 size + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern bool webrtcPeerConnectionInterfaceAddICECandidate( + IntPtr connection, + [MarshalAs(UnmanagedType.LPStr)] string sdpMid, + int sdpMLineIndex, + [MarshalAs(UnmanagedType.LPStr)] string sdp + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcPeerConnectionInterfaceCreateAnswer( + IntPtr connection, + IntPtr observer, + PeerConnectionInterface.RtcOfferAnswerOptions options + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcPeerConnectionInterfaceCreateOffer( + IntPtr connection, + IntPtr observer, + PeerConnectionInterface.RtcOfferAnswerOptions options + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcPeerConnectionInterfaceClose( + IntPtr connection + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcPeerConnectionInterfaceSetAudioRecording( + IntPtr connection, + [MarshalAs(UnmanagedType.I1)] bool recording + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcPeerConnectionInterfaceSetLocalDescription( + IntPtr connection, + IntPtr observer, + IntPtr desc + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcPeerConnectionInterfaceSetRemoteDescription( + IntPtr connection, + IntPtr observer, + IntPtr desc + ); + + public static RtcErrorOr AddTrack( + this IPeerConnectionInterface connection, + IMediaStreamTrackInterface track, + string[] streamIds) + { + RtcError error; + + var result = webrtcPeerConnectionInterfaceAddTrack( + connection.Ptr, track.Ptr, streamIds, streamIds.Length); + + try + { + error = new RtcError(result.Error); + } + finally + { + Interop.RtcError.Delete(result.Error); + } + + var value = error.Type == RtcErrorType.None ? + new DisposableRtpSenderInterface(result.Value) : null; + + return new RtcErrorOr(error, value); + } + + public static bool AddICECandidate(this IPeerConnectionInterface connection, + string sdpMid, + int sdpMlineIndex, + string sdp) + { + var result = webrtcPeerConnectionInterfaceAddICECandidate( connection.Ptr, sdpMid, sdpMlineIndex, sdp); - return result; - } - - - public static void Close(this IPeerConnectionInterface connection) - { - webrtcPeerConnectionInterfaceClose(connection.Ptr); - } - - public static void CreateAnswer( - this IPeerConnectionInterface connection, - ICreateSessionDescriptionObserver observer, - PeerConnectionInterface.RtcOfferAnswerOptions options) - { - webrtcPeerConnectionInterfaceCreateAnswer( - connection.Ptr, observer.Ptr, options); - } - - public static void CreateOffer( - this IPeerConnectionInterface connection, - ICreateSessionDescriptionObserver observer, - PeerConnectionInterface.RtcOfferAnswerOptions options) - { - webrtcPeerConnectionInterfaceCreateOffer( - connection.Ptr, observer.Ptr, options); - } - - public static void SetAudioRecording( - this IPeerConnectionInterface connection, - bool recording) - { - webrtcPeerConnectionInterfaceSetAudioRecording( - connection.Ptr, - recording - ); - } - - public static void SetLocalDescription( - this IPeerConnectionInterface connection, - ISetSessionDescriptionObserver observer, - IDisposableSessionDescriptionInterface desc) - { - webrtcPeerConnectionInterfaceSetLocalDescription( - connection.Ptr, observer.Ptr, desc.Ptr); - - desc.ReleasePtr(); - } - - public static void SetRemoteDescription( - this IPeerConnectionInterface connection, - ISetSessionDescriptionObserver observer, - IDisposableSessionDescriptionInterface desc) - { - webrtcPeerConnectionInterfaceSetRemoteDescription( - connection.Ptr, observer.Ptr, desc.Ptr); - - desc.ReleasePtr(); - } - } -} - -namespace Pixiv.Webrtc.Interop -{ - public static class PeerConnectionFactoryInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcPeerConnectionFactoryInterfaceRelease")] - public static extern void Release(IntPtr factory); - } - - public static class PeerConnectionInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcPeerConnectionInterfaceRelease")] - public static extern void Release(IntPtr ptr); - } - - public static class PeerConnectionObserver - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeletePeerConnectionObserver")] - public static extern void Delete(IntPtr observer); - } -} + return result; + } + + + public static void Close(this IPeerConnectionInterface connection) + { + webrtcPeerConnectionInterfaceClose(connection.Ptr); + } + + public static void CreateAnswer( + this IPeerConnectionInterface connection, + ICreateSessionDescriptionObserver observer, + PeerConnectionInterface.RtcOfferAnswerOptions options) + { + webrtcPeerConnectionInterfaceCreateAnswer( + connection.Ptr, observer.Ptr, options); + } + + public static void CreateOffer( + this IPeerConnectionInterface connection, + ICreateSessionDescriptionObserver observer, + PeerConnectionInterface.RtcOfferAnswerOptions options) + { + webrtcPeerConnectionInterfaceCreateOffer( + connection.Ptr, observer.Ptr, options); + } + + public static void SetAudioRecording( + this IPeerConnectionInterface connection, + bool recording) + { + webrtcPeerConnectionInterfaceSetAudioRecording( + connection.Ptr, + recording + ); + } + + public static void SetLocalDescription( + this IPeerConnectionInterface connection, + ISetSessionDescriptionObserver observer, + IDisposableSessionDescriptionInterface desc) + { + webrtcPeerConnectionInterfaceSetLocalDescription( + connection.Ptr, observer.Ptr, desc.Ptr); + + desc.ReleasePtr(); + } + + public static void SetRemoteDescription( + this IPeerConnectionInterface connection, + ISetSessionDescriptionObserver observer, + IDisposableSessionDescriptionInterface desc) + { + webrtcPeerConnectionInterfaceSetRemoteDescription( + connection.Ptr, observer.Ptr, desc.Ptr); + + desc.ReleasePtr(); + } + } +} + +namespace Pixiv.Webrtc.Interop +{ + public static class PeerConnectionFactoryInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcPeerConnectionFactoryInterfaceRelease")] + public static extern void Release(IntPtr factory); + } + + public static class PeerConnectionInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcPeerConnectionInterfaceRelease")] + public static extern void Release(IntPtr ptr); + } + + public static class PeerConnectionObserver + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeletePeerConnectionObserver")] + public static extern void Delete(IntPtr observer); + } +} From b4ae6d722fd5146aefbb85b360d2b65d8e628676 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Tue, 7 Apr 2020 21:03:41 +0800 Subject: [PATCH 62/85] add to other builds --- sdk/dotnet/unity/unity.msbuildproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 3368dde8a7..0c5aaf7513 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;WinX64;WinX86 + LinuxX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) @@ -67,7 +67,7 @@ @@ -89,7 +89,7 @@ From 190bd4783486daccd4bead0ffad7279e327f11a1 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 1 May 2020 09:57:54 +0800 Subject: [PATCH 63/85] fix marshalling --- sdk/dotnet/unity/unity.msbuildproj | 2 +- .../webrtc/api/data_channel_interface.cs | 154 +++++++++--------- .../webrtc/api/media_stream_interface.cs | 31 +++- .../webrtc/api/peer_connection_interface.cs | 20 ++- 4 files changed, 114 insertions(+), 93 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 0c5aaf7513..c0c827debb 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -74,7 +74,7 @@ diff --git a/sdk/dotnet/webrtc/api/data_channel_interface.cs b/sdk/dotnet/webrtc/api/data_channel_interface.cs index c134bb1f0f..a3f4abe653 100644 --- a/sdk/dotnet/webrtc/api/data_channel_interface.cs +++ b/sdk/dotnet/webrtc/api/data_channel_interface.cs @@ -1,102 +1,102 @@ -/* - * Copyright 2019 pixiv Inc. 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. +/* + * Copyright 2019 pixiv Inc. 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. */ -using Pixiv.Rtc; -using System; -using System.Runtime.InteropServices; - -namespace Pixiv.Webrtc -{ - public interface IDataChannelInterface - { - IntPtr Ptr { get; } - } - - public interface IDisposableDataChannelInterface : - IDataChannelInterface, Rtc.IDisposable - { - } - - public sealed class DisposableDataChannelInterface : - DisposablePtr, IDisposableDataChannelInterface - { - IntPtr IDataChannelInterface.Ptr => Ptr; - - internal DisposableDataChannelInterface(IntPtr ptr) - { - Ptr = ptr; - } - - private protected override void FreePtr() - { - Interop.DataChannelInterface.Release(Ptr); - } - +using Pixiv.Rtc; +using System; +using System.Runtime.InteropServices; + +namespace Pixiv.Webrtc +{ + public interface IDataChannelInterface + { + IntPtr Ptr { get; } + } + + public interface IDisposableDataChannelInterface : + IDataChannelInterface, Rtc.IDisposable + { + } + + public sealed class DisposableDataChannelInterface : + DisposablePtr, IDisposableDataChannelInterface + { + IntPtr IDataChannelInterface.Ptr => Ptr; + + internal DisposableDataChannelInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.DataChannelInterface.Release(Ptr); + } + public IntPtr GetPtr { get { return Ptr; } - } - } - public static class DataChannelInterfaceExtension + } + } + public static class DataChannelInterfaceExtension { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr webrtcDataChannelRegisterObserver(IntPtr s, IntPtr o); - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern void webrtcDataChannelUnRegisterObserver(IntPtr s); - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcDataChannelLabel( - IntPtr ptr + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcDataChannelLabel( + IntPtr ptr ); - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern int webrtcDataChannelStatus( IntPtr ptr - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern bool webrtcDataChannelSendText( IntPtr ptr, string text - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern bool webrtcDataChannelSendData( IntPtr ptr, IntPtr data, int len - ); - - public static string Label(this IDisposableDataChannelInterface channel) - { - return Rtc.Interop.String.MoveToString( - webrtcDataChannelLabel(channel.Ptr)); + ); + + public static string Label(this IDisposableDataChannelInterface channel) + { + return Rtc.Interop.String.MoveToString( + webrtcDataChannelLabel(channel.Ptr)); } - public static int Status(this IDisposableDataChannelInterface channel) - { - return webrtcDataChannelStatus(channel.Ptr); + public static int Status(this IDisposableDataChannelInterface channel) + { + return webrtcDataChannelStatus(channel.Ptr); } - public static bool Send(this IDisposableDataChannelInterface channel, byte[] data) - { - var handle = GCHandle.Alloc(data, GCHandleType.Pinned); + public static bool Send(this IDisposableDataChannelInterface channel, byte[] data) + { + var handle = GCHandle.Alloc(data, GCHandleType.Pinned); try { return webrtcDataChannelSendData(channel.Ptr, handle.AddrOfPinnedObject(), data.Length); - } + } finally { handle.Free(); - } + } } - public static bool Send(this IDisposableDataChannelInterface channel, string text) + public static bool Send(this IDisposableDataChannelInterface channel, string text) { - return webrtcDataChannelSendText(channel.Ptr, text); + return webrtcDataChannelSendText(channel.Ptr, text); } public static void UnRegisterObserver(this IDisposableDataChannelInterface channel) @@ -104,13 +104,13 @@ public static void UnRegisterObserver(this IDisposableDataChannelInterface chann webrtcDataChannelUnRegisterObserver(channel.Ptr); } } -} - -namespace Pixiv.Webrtc.Interop -{ - public static class DataChannelInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelInterfaceRelease")] - public static extern void Release(IntPtr ptr); - } -} +} + +namespace Pixiv.Webrtc.Interop +{ + public static class DataChannelInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelInterfaceRelease")] + public static extern void Release(IntPtr ptr); + } +} diff --git a/sdk/dotnet/webrtc/api/media_stream_interface.cs b/sdk/dotnet/webrtc/api/media_stream_interface.cs index 67d14d422c..908b0d38a5 100644 --- a/sdk/dotnet/webrtc/api/media_stream_interface.cs +++ b/sdk/dotnet/webrtc/api/media_stream_interface.cs @@ -308,8 +308,8 @@ public delegate void ManagedDataHandler( IntPtr audioData, int bitsPerSample, int sampleRate, - int numberOfChannels, - int numberOfFrame + UIntPtr numberOfChannels, + UIntPtr numberOfFrames ); public IntPtr Ptr { get; } @@ -347,16 +347,35 @@ public static void OnData( IntPtr audioData, int bitsPerSample, int sampleRate, - [MarshalAs(UnmanagedType.U4)] Int32 numberOfChannels, - [MarshalAs(UnmanagedType.U4)] Int32 numberOfFrames) + int numberOfChannels, + int numberOfFrames) { + UIntPtr castedNumberOfChannels; + UIntPtr castedNumberOfFrames; + try + { + castedNumberOfChannels = (UIntPtr)numberOfChannels; + } + catch (OverflowException inner) + { + throw new ArgumentOutOfRangeException(nameof(numberOfChannels), inner); + } + + try + { + castedNumberOfFrames = (UIntPtr)numberOfFrames; + } + catch (OverflowException inner) + { + throw new ArgumentOutOfRangeException(nameof(castedNumberOfFrames), inner); + } webrtcAudioTrackSinkInterfaceOnData( sink.Ptr, audioData, bitsPerSample, sampleRate, - numberOfChannels, - numberOfFrames + castedNumberOfChannels, + castedNumberOfFrames ); } } diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index b6f2f3aa3d..723979844b 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -166,7 +166,7 @@ IntPtr candidate private delegate void IceCandidatesRemovedHandler( IntPtr context, IntPtr data, - [MarshalAs(UnmanagedType.U4)] Int32 size + UIntPtr size ); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -180,7 +180,7 @@ private delegate void AddTrackHandler( IntPtr context, IntPtr receiver, IntPtr data, - [MarshalAs(UnmanagedType.U4)] Int32 size + UIntPtr size ); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -315,12 +315,13 @@ private static void OnIceCandidate(IntPtr context, IntPtr candidate) private static void OnIceCandidatesRemoved( IntPtr context, IntPtr data, - [MarshalAs(UnmanagedType.U4)] Int32 size) + UIntPtr nativeSize) { + var size = (ulong)nativeSize; var sizeOfIntPtr = Marshal.SizeOf(); var candidates = new DisposableCandidate[size]; - for (var index = 0; index < size; index++) + for (ulong index = 0; index < size; index++) { var ptr = Marshal.ReadIntPtr(data); candidates[index] = new DisposableCandidate(ptr); @@ -345,12 +346,13 @@ private static void OnAddTrack( IntPtr context, IntPtr receiver, IntPtr data, - [MarshalAs(UnmanagedType.U4)] Int32 size) + UIntPtr nativeSize) { + var size = (ulong)nativeSize; var sizeOfIntPtr = Marshal.SizeOf(); var streams = new DisposableMediaStreamInterface[size]; - for (var index = 0; index < size; index++) + for (ulong index = 0; index < size; index++) { var ptr = Marshal.ReadIntPtr(data); streams[index] = new DisposableMediaStreamInterface(ptr); @@ -856,7 +858,7 @@ private static extern WebrtcAddTrackResult webrtcPeerConnectionInterfaceAddTrack IntPtr connection, IntPtr track, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] string[] data, - [MarshalAs(UnmanagedType.U4)] Int32 size + UIntPtr size ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] @@ -912,9 +914,9 @@ public static RtcErrorOr AddTrack( string[] streamIds) { RtcError error; - + var size = new UIntPtr((ulong)streamIds.LongLength); var result = webrtcPeerConnectionInterfaceAddTrack( - connection.Ptr, track.Ptr, streamIds, streamIds.Length); + connection.Ptr, track.Ptr, streamIds, size); try { From c4d560835937ee2b6a83c6e85f8c053a25051b24 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 8 Jul 2020 09:45:57 +0800 Subject: [PATCH 64/85] updates --- media/base/video_adapter.cc | 28 +- .../webrtc/api/media_stream_interface.cs | 1104 ++++++++--------- 2 files changed, 567 insertions(+), 565 deletions(-) diff --git a/media/base/video_adapter.cc b/media/base/video_adapter.cc index c4f281980c..999579b2ae 100644 --- a/media/base/video_adapter.cc +++ b/media/base/video_adapter.cc @@ -220,22 +220,24 @@ bool VideoAdapter::AdaptFrameResolution(int in_width, const Fraction scale = FindScale((*cropped_width) * (*cropped_height), target_pixel_count, max_pixel_count); - // Make sure the resulting dimensions are aligned correctly to be nice to - // hardware encoders. - *out_width = - roundUp(*cropped_width * scale.numerator, - scale.denominator * required_resolution_alignment_, - in_width * scale.numerator) / scale.denominator; - *out_height = - roundUp(*cropped_height * scale.numerator, - scale.denominator * required_resolution_alignment_, - in_height * scale.numerator) / scale.denominator; + // Adjust cropping slightly to get even integer output size and a perfect + // scale factor. Make sure the resulting dimensions are aligned correctly + // to be nice to hardware encoders. + *cropped_width = + roundUp(*cropped_width, + scale.denominator * required_resolution_alignment_, in_width); + *cropped_height = + roundUp(*cropped_height, + scale.denominator * required_resolution_alignment_, in_height); + RTC_DCHECK_EQ(0, *cropped_width % scale.denominator); + RTC_DCHECK_EQ(0, *cropped_height % scale.denominator); + + // Calculate final output size. + *out_width = *cropped_width / scale.denominator * scale.numerator; + *out_height = *cropped_height / scale.denominator * scale.numerator; RTC_DCHECK_EQ(0, *out_width % required_resolution_alignment_); RTC_DCHECK_EQ(0, *out_height % required_resolution_alignment_); - *cropped_width = (*out_width * scale.denominator + scale.numerator - 1) / scale.numerator; - *cropped_height = (*out_height * scale.denominator + scale.numerator - 1) / scale.numerator; - ++frames_out_; if (scale.numerator != scale.denominator) ++frames_scaled_; diff --git a/sdk/dotnet/webrtc/api/media_stream_interface.cs b/sdk/dotnet/webrtc/api/media_stream_interface.cs index 908b0d38a5..9feed7599f 100644 --- a/sdk/dotnet/webrtc/api/media_stream_interface.cs +++ b/sdk/dotnet/webrtc/api/media_stream_interface.cs @@ -1,554 +1,554 @@ -/* - * Copyright 2019 pixiv Inc. 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. - */ - -using Pixiv.Rtc; -using System; -using System.Runtime.InteropServices; - -namespace Pixiv.Webrtc -{ - public interface IAudioSourceInterface : IMediaSourceInterface - { - new IntPtr Ptr { get; } - } - - public interface IAudioTrackInterface - { - IntPtr Ptr { get; } - } - - public interface IAudioTrackSinkInterface - { - IntPtr Ptr { get; } - } - - public interface IDisposableAudioSourceInterface : - IAudioSourceInterface, IDisposableMediaSourceInterface - { - } - - public interface IDisposableAudioTrackInterface : - IAudioTrackInterface, Rtc.IDisposable - { - } - - public interface IDisposableAudioTrackSinkInterface : - IAudioTrackSinkInterface, Rtc.IDisposable - { - } - - public interface IDisposableMediaSourceInterface : - IMediaSourceInterface, Rtc.IDisposable - { - } - - public interface IDisposableMediaStreamInterface : - IMediaStreamInterface, Rtc.IDisposable - { - } - - public interface IDisposableMediaStreamTrackInterface : - IMediaStreamTrackInterface, Rtc.IDisposable - { - } - - public interface IDisposableVideoTrackSourceInterface : - IDisposableMediaSourceInterface, IVideoTrackSourceInterface - { - } - - public interface IDisposableVideoTrackInterface : - IVideoTrackInterface, IDisposableMediaStreamTrackInterface - { - } - - public interface IManagedNotifierInterface - { - void RegisterObserver(ObserverInterface observer); - void UnregisterObserver(ObserverInterface observer); - } - - public interface IManagedMediaSourceInterface : IManagedNotifierInterface - { - MediaSourceInterface.SourceState State { get; } - bool Remote { get; } - } - - public interface IManagedAudioSourceInterface : - IManagedMediaSourceInterface - { - void AddSink(AudioTrackSinkInterface sink); - void RemoveSink(AudioTrackSinkInterface sink); - } - - public interface IMediaSourceInterface - { - IntPtr Ptr { get; } - } - - public interface IMediaStreamInterface - { - IntPtr Ptr { get; } - } - - public interface IMediaStreamTrackInterface - { - IntPtr Ptr { get; } - } - - public interface IObserverInterface - { - IntPtr Ptr { get; } - } - - public interface IVideoTrackInterface : IMediaStreamTrackInterface - { - new IntPtr Ptr { get; } - } - - public interface IVideoTrackSourceInterface : IMediaSourceInterface - { - new IntPtr Ptr { get; } - } - - public sealed class DisposableMediaSourceInterface : - DisposablePtr, IDisposableMediaSourceInterface - { - IntPtr IMediaSourceInterface.Ptr => Ptr; - - public DisposableMediaSourceInterface(IntPtr ptr) - { - Ptr = ptr; - } - - private protected override void FreePtr() - { - Interop.MediaSourceInterface.Release(Ptr); - } - } - - public sealed class DisposableMediaStreamInterface : - DisposablePtr, IDisposableMediaStreamInterface - { - IntPtr IMediaStreamInterface.Ptr => Ptr; - - public DisposableMediaStreamInterface(IntPtr ptr) - { - Ptr = ptr; - } - - private protected override void FreePtr() - { - Interop.MediaStreamInterface.Release(Ptr); - } - } - - public abstract class DisposableMediaStreamTrackInterface : - DisposablePtr, IDisposableMediaStreamTrackInterface - { - IntPtr IMediaStreamTrackInterface.Ptr => Ptr; - - internal DisposableMediaStreamTrackInterface() - { - } - - private protected override void FreePtr() - { - Interop.MediaStreamTrackInterface.Release(Ptr); - } - } - - public sealed class DisposableVideoTrackInterface : - DisposableMediaStreamTrackInterface, IDisposableVideoTrackInterface - { - IntPtr IVideoTrackInterface.Ptr => - Interop.VideoTrackInterface.FromWebrtcMediaStreamTrackInterface( - ((IMediaStreamTrackInterface)this).Ptr); - - internal DisposableVideoTrackInterface(IntPtr ptr) - { - Ptr = ptr; - } - } - - public sealed class DisposableAudioTrackInterface : - DisposableMediaStreamTrackInterface, IDisposableAudioTrackInterface - { - IntPtr IAudioTrackInterface.Ptr => - Interop.AudioTrackInterface.FromWebrtcMediaStreamTrackInterface( - ((IMediaStreamTrackInterface)this).Ptr); - - internal DisposableAudioTrackInterface(IntPtr ptr) - { - Ptr = ptr; - } - } - - public sealed class DisposableAudioSourceInterface : - DisposablePtr, IDisposableAudioSourceInterface - { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void DestructionHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate MediaSourceInterface.SourceState StateHandler( - IntPtr context - ); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool RemoteHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void ObserverHandler(IntPtr context, IntPtr observer); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void SinkHandler(IntPtr context, IntPtr sink); - - private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( - (DestructionHandler)OnDestruction, - (ObserverHandler)RegisterObserver, - (ObserverHandler)UnregisterObserver, - (StateHandler)State, - (RemoteHandler)Remote, - (SinkHandler)AddSink, - (SinkHandler)RemoveSink - ); - - [MonoPInvokeCallback(typeof(DestructionHandler))] - private static void OnDestruction(IntPtr context) - { - ((GCHandle)context).Free(); - } - - [MonoPInvokeCallback(typeof(ObserverHandler))] - private static void RegisterObserver(IntPtr context, IntPtr observer) - { - var target = ((GCHandle)context).Target; - var source = (IManagedAudioSourceInterface)target; - source.RegisterObserver(new ObserverInterface(observer)); - } - - [MonoPInvokeCallback(typeof(ObserverHandler))] - private static void UnregisterObserver(IntPtr context, IntPtr observer) - { - var target = ((GCHandle)context).Target; - var source = (IManagedAudioSourceInterface)target; - source.UnregisterObserver(new ObserverInterface(observer)); - } - - [MonoPInvokeCallback(typeof(StateHandler))] - private static MediaSourceInterface.SourceState State(IntPtr context) - { - var target = ((GCHandle)context).Target; - return ((IManagedAudioSourceInterface)target).State; - } - - [MonoPInvokeCallback(typeof(RemoteHandler))] - private static bool Remote(IntPtr context) - { - var target = ((GCHandle)context).Target; - return ((IManagedAudioSourceInterface)target).Remote; - } - - [MonoPInvokeCallback(typeof(SinkHandler))] - private static void AddSink(IntPtr context, IntPtr sinkPtr) - { - var target = ((GCHandle)context).Target; - var sink = new AudioTrackSinkInterface(sinkPtr); - ((IManagedAudioSourceInterface)target).AddSink(sink); - } - - [MonoPInvokeCallback(typeof(SinkHandler))] - private static void RemoveSink(IntPtr context, IntPtr sinkPtr) - { - var target = ((GCHandle)context).Target; - var sink = new AudioTrackSinkInterface(sinkPtr); - ((IManagedAudioSourceInterface)target).RemoveSink(sink); - } - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcNewAudioSourceInterface( - IntPtr context, - IntPtr functions - ); - - IntPtr IMediaSourceInterface.Ptr => - Interop.AudioSourceInterface.ToWebrtcMediaSourceInterface( - ((IAudioSourceInterface)this).Ptr - ); - - IntPtr IAudioSourceInterface.Ptr => Ptr; - - public DisposableAudioSourceInterface( - IManagedAudioSourceInterface managed) - { - Ptr = webrtcNewAudioSourceInterface( - (IntPtr)GCHandle.Alloc(managed), - s_functions.Ptr - ); - } - - private protected override void FreePtr() - { - Interop.MediaSourceInterface.Release( - Interop.AudioSourceInterface.ToWebrtcMediaSourceInterface( - Ptr - ) - ); - } - } - - public sealed class AudioTrackSinkInterface : IAudioTrackSinkInterface - { - public delegate void ManagedDataHandler( - IntPtr audioData, - int bitsPerSample, - int sampleRate, - UIntPtr numberOfChannels, - UIntPtr numberOfFrames - ); - - public IntPtr Ptr { get; } - - public AudioTrackSinkInterface(IntPtr ptr) - { - Ptr = ptr; - } - } - - public sealed class ObserverInterface : IObserverInterface - { - public IntPtr Ptr { get; } - - public ObserverInterface(IntPtr ptr) - { - Ptr = ptr; - } - } - - public static class AudioTrackSinkInterfaceExtension - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcAudioTrackSinkInterfaceOnData( - IntPtr sink, - IntPtr audioData, - int bitsPerSample, - int sampleRate, - int numberOfChannels, - int numberOfFrames - ); - - public static void OnData( - this IAudioTrackSinkInterface sink, - IntPtr audioData, - int bitsPerSample, - int sampleRate, - int numberOfChannels, - int numberOfFrames) - { - UIntPtr castedNumberOfChannels; +/* + * Copyright 2019 pixiv Inc. 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. + */ + +using Pixiv.Rtc; +using System; +using System.Runtime.InteropServices; + +namespace Pixiv.Webrtc +{ + public interface IAudioSourceInterface : IMediaSourceInterface + { + new IntPtr Ptr { get; } + } + + public interface IAudioTrackInterface + { + IntPtr Ptr { get; } + } + + public interface IAudioTrackSinkInterface + { + IntPtr Ptr { get; } + } + + public interface IDisposableAudioSourceInterface : + IAudioSourceInterface, IDisposableMediaSourceInterface + { + } + + public interface IDisposableAudioTrackInterface : + IAudioTrackInterface, Rtc.IDisposable + { + } + + public interface IDisposableAudioTrackSinkInterface : + IAudioTrackSinkInterface, Rtc.IDisposable + { + } + + public interface IDisposableMediaSourceInterface : + IMediaSourceInterface, Rtc.IDisposable + { + } + + public interface IDisposableMediaStreamInterface : + IMediaStreamInterface, Rtc.IDisposable + { + } + + public interface IDisposableMediaStreamTrackInterface : + IMediaStreamTrackInterface, Rtc.IDisposable + { + } + + public interface IDisposableVideoTrackSourceInterface : + IDisposableMediaSourceInterface, IVideoTrackSourceInterface + { + } + + public interface IDisposableVideoTrackInterface : + IVideoTrackInterface, IDisposableMediaStreamTrackInterface + { + } + + public interface IManagedNotifierInterface + { + void RegisterObserver(ObserverInterface observer); + void UnregisterObserver(ObserverInterface observer); + } + + public interface IManagedMediaSourceInterface : IManagedNotifierInterface + { + MediaSourceInterface.SourceState State { get; } + bool Remote { get; } + } + + public interface IManagedAudioSourceInterface : + IManagedMediaSourceInterface + { + void AddSink(AudioTrackSinkInterface sink); + void RemoveSink(AudioTrackSinkInterface sink); + } + + public interface IMediaSourceInterface + { + IntPtr Ptr { get; } + } + + public interface IMediaStreamInterface + { + IntPtr Ptr { get; } + } + + public interface IMediaStreamTrackInterface + { + IntPtr Ptr { get; } + } + + public interface IObserverInterface + { + IntPtr Ptr { get; } + } + + public interface IVideoTrackInterface : IMediaStreamTrackInterface + { + new IntPtr Ptr { get; } + } + + public interface IVideoTrackSourceInterface : IMediaSourceInterface + { + new IntPtr Ptr { get; } + } + + public sealed class DisposableMediaSourceInterface : + DisposablePtr, IDisposableMediaSourceInterface + { + IntPtr IMediaSourceInterface.Ptr => Ptr; + + public DisposableMediaSourceInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.MediaSourceInterface.Release(Ptr); + } + } + + public sealed class DisposableMediaStreamInterface : + DisposablePtr, IDisposableMediaStreamInterface + { + IntPtr IMediaStreamInterface.Ptr => Ptr; + + public DisposableMediaStreamInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.MediaStreamInterface.Release(Ptr); + } + } + + public abstract class DisposableMediaStreamTrackInterface : + DisposablePtr, IDisposableMediaStreamTrackInterface + { + IntPtr IMediaStreamTrackInterface.Ptr => Ptr; + + internal DisposableMediaStreamTrackInterface() + { + } + + private protected override void FreePtr() + { + Interop.MediaStreamTrackInterface.Release(Ptr); + } + } + + public sealed class DisposableVideoTrackInterface : + DisposableMediaStreamTrackInterface, IDisposableVideoTrackInterface + { + IntPtr IVideoTrackInterface.Ptr => + Interop.VideoTrackInterface.FromWebrtcMediaStreamTrackInterface( + ((IMediaStreamTrackInterface)this).Ptr); + + internal DisposableVideoTrackInterface(IntPtr ptr) + { + Ptr = ptr; + } + } + + public sealed class DisposableAudioTrackInterface : + DisposableMediaStreamTrackInterface, IDisposableAudioTrackInterface + { + IntPtr IAudioTrackInterface.Ptr => + Interop.AudioTrackInterface.FromWebrtcMediaStreamTrackInterface( + ((IMediaStreamTrackInterface)this).Ptr); + + internal DisposableAudioTrackInterface(IntPtr ptr) + { + Ptr = ptr; + } + } + + public sealed class DisposableAudioSourceInterface : + DisposablePtr, IDisposableAudioSourceInterface + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void DestructionHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate MediaSourceInterface.SourceState StateHandler( + IntPtr context + ); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate bool RemoteHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void ObserverHandler(IntPtr context, IntPtr observer); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void SinkHandler(IntPtr context, IntPtr sink); + + private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( + (DestructionHandler)OnDestruction, + (ObserverHandler)RegisterObserver, + (ObserverHandler)UnregisterObserver, + (StateHandler)State, + (RemoteHandler)Remote, + (SinkHandler)AddSink, + (SinkHandler)RemoveSink + ); + + [MonoPInvokeCallback(typeof(DestructionHandler))] + private static void OnDestruction(IntPtr context) + { + ((GCHandle)context).Free(); + } + + [MonoPInvokeCallback(typeof(ObserverHandler))] + private static void RegisterObserver(IntPtr context, IntPtr observer) + { + var target = ((GCHandle)context).Target; + var source = (IManagedAudioSourceInterface)target; + source.RegisterObserver(new ObserverInterface(observer)); + } + + [MonoPInvokeCallback(typeof(ObserverHandler))] + private static void UnregisterObserver(IntPtr context, IntPtr observer) + { + var target = ((GCHandle)context).Target; + var source = (IManagedAudioSourceInterface)target; + source.UnregisterObserver(new ObserverInterface(observer)); + } + + [MonoPInvokeCallback(typeof(StateHandler))] + private static MediaSourceInterface.SourceState State(IntPtr context) + { + var target = ((GCHandle)context).Target; + return ((IManagedAudioSourceInterface)target).State; + } + + [MonoPInvokeCallback(typeof(RemoteHandler))] + private static bool Remote(IntPtr context) + { + var target = ((GCHandle)context).Target; + return ((IManagedAudioSourceInterface)target).Remote; + } + + [MonoPInvokeCallback(typeof(SinkHandler))] + private static void AddSink(IntPtr context, IntPtr sinkPtr) + { + var target = ((GCHandle)context).Target; + var sink = new AudioTrackSinkInterface(sinkPtr); + ((IManagedAudioSourceInterface)target).AddSink(sink); + } + + [MonoPInvokeCallback(typeof(SinkHandler))] + private static void RemoveSink(IntPtr context, IntPtr sinkPtr) + { + var target = ((GCHandle)context).Target; + var sink = new AudioTrackSinkInterface(sinkPtr); + ((IManagedAudioSourceInterface)target).RemoveSink(sink); + } + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcNewAudioSourceInterface( + IntPtr context, + IntPtr functions + ); + + IntPtr IMediaSourceInterface.Ptr => + Interop.AudioSourceInterface.ToWebrtcMediaSourceInterface( + ((IAudioSourceInterface)this).Ptr + ); + + IntPtr IAudioSourceInterface.Ptr => Ptr; + + public DisposableAudioSourceInterface( + IManagedAudioSourceInterface managed) + { + Ptr = webrtcNewAudioSourceInterface( + (IntPtr)GCHandle.Alloc(managed), + s_functions.Ptr + ); + } + + private protected override void FreePtr() + { + Interop.MediaSourceInterface.Release( + Interop.AudioSourceInterface.ToWebrtcMediaSourceInterface( + Ptr + ) + ); + } + } + + public sealed class AudioTrackSinkInterface : IAudioTrackSinkInterface + { + public delegate void ManagedDataHandler( + IntPtr audioData, + int bitsPerSample, + int sampleRate, + UIntPtr numberOfChannels, + UIntPtr numberOfFrames + ); + + public IntPtr Ptr { get; } + + public AudioTrackSinkInterface(IntPtr ptr) + { + Ptr = ptr; + } + } + + public sealed class ObserverInterface : IObserverInterface + { + public IntPtr Ptr { get; } + + public ObserverInterface(IntPtr ptr) + { + Ptr = ptr; + } + } + + public static class AudioTrackSinkInterfaceExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcAudioTrackSinkInterfaceOnData( + IntPtr sink, + IntPtr audioData, + int bitsPerSample, + int sampleRate, + UIntPtr numberOfChannels, + UIntPtr numberOfFrames + ); + + public static void OnData( + this IAudioTrackSinkInterface sink, + IntPtr audioData, + int bitsPerSample, + int sampleRate, + int numberOfChannels, + int numberOfFrames) + { + UIntPtr castedNumberOfChannels; UIntPtr castedNumberOfFrames; - try - { - castedNumberOfChannels = (UIntPtr)numberOfChannels; - } - catch (OverflowException inner) - { - throw new ArgumentOutOfRangeException(nameof(numberOfChannels), inner); - } - - try - { - castedNumberOfFrames = (UIntPtr)numberOfFrames; - } - catch (OverflowException inner) - { - throw new ArgumentOutOfRangeException(nameof(castedNumberOfFrames), inner); - } - webrtcAudioTrackSinkInterfaceOnData( - sink.Ptr, - audioData, - bitsPerSample, - sampleRate, + try + { + castedNumberOfChannels = (UIntPtr)numberOfChannels; + } + catch (OverflowException inner) + { + throw new ArgumentOutOfRangeException(nameof(numberOfChannels), inner); + } + + try + { + castedNumberOfFrames = (UIntPtr)numberOfFrames; + } + catch (OverflowException inner) + { + throw new ArgumentOutOfRangeException(nameof(castedNumberOfFrames), inner); + } + webrtcAudioTrackSinkInterfaceOnData( + sink.Ptr, + audioData, + bitsPerSample, + sampleRate, castedNumberOfChannels, - castedNumberOfFrames - ); - } - } - - public static class MediaSourceInterface - { - public enum SourceState - { - Initializing, - Live, - Enabled, - Muted - } - } - - public static class AudioTrackInterfaceExtension - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcAudioTrackInterfaceAddSink( - IntPtr track, - IntPtr sink - ); - - public static void AddSink( - this IAudioTrackInterface track, - IAudioTrackSinkInterface sink) - { - webrtcAudioTrackInterfaceAddSink(track.Ptr, sink.Ptr); - } - } - - public static class MediaStreamTrackInterfaceExtension - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcMediaStreamTrackInterfaceId( - IntPtr ptr - ); - - public static string ID(this IMediaStreamTrackInterface track) - { - return Rtc.Interop.String.MoveToString( - webrtcMediaStreamTrackInterfaceId(track.Ptr)); - } - } - - public static class VideoTrackInterfaceExtension - { - private struct RtcVideoSinkWants - { - [MarshalAs(UnmanagedType.I1)] - public bool RotationApplied; - - [MarshalAs(UnmanagedType.I1)] - public bool BlackFrames; - - [MarshalAs(UnmanagedType.I1)] - public bool HasTargetPixelCount; - - public int MaxPixelCount; - public int TargetPixelCount; - public int MaxFramerateFps; - } - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcVideoTrackInterfaceAddOrUpdateSink( - IntPtr stream, - IntPtr sink, - in RtcVideoSinkWants wants - ); - - public static void AddOrUpdateSink( - this IVideoTrackInterface track, - IVideoSinkInterface sink, - VideoSinkWants wants) - { - var unmanagedWants = new RtcVideoSinkWants(); - - unmanagedWants.RotationApplied = wants.RotationApplied; - unmanagedWants.BlackFrames = wants.BlackFrames; - unmanagedWants.HasTargetPixelCount = wants.TargetPixelCount.HasValue; - unmanagedWants.MaxPixelCount = wants.MaxPixelCount; - unmanagedWants.MaxFramerateFps = wants.MaxFramerateFps; - - if (wants.TargetPixelCount.HasValue) - { - unmanagedWants.TargetPixelCount = (int)wants.TargetPixelCount; - } - - webrtcVideoTrackInterfaceAddOrUpdateSink( - track.Ptr, - sink.Ptr, - unmanagedWants - ); - } - } -} - -namespace Pixiv.Webrtc.Interop -{ - public static class AudioSourceInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcAudioSourceInterfaceToWebrtcMediaSourceInterface")] - public static extern IntPtr ToWebrtcMediaSourceInterface(IntPtr ptr); - } - - public static class AudioTrackInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamTrackInterfaceToWebrtcAudioTrackInterface")] - public static extern IntPtr FromWebrtcMediaStreamTrackInterface(IntPtr ptr); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcAudioTrackInterfaceToWebrtcMediaStreamTrackInterface")] - public static extern IntPtr ToWebrtcMediaStreamTrackInterface(IntPtr ptr); - } - - public static class MediaSourceInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaSourceInterfaceRelease")] - public static extern void Release(IntPtr ptr); - } - - public static class MediaStreamInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamInterfaceRelease")] - public static extern void Release(IntPtr ptr); - } - - public static class MediaStreamTrackInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcMediaStreamTrackInterfaceKAudioKind(); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcMediaStreamTrackInterfaceKVideoKind(); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr webrtcMediaStreamTrackInterfaceKind( - IntPtr ptr - ); - - public static DisposableMediaStreamTrackInterface WrapDisposable( - IntPtr ptr) - { - var kind = webrtcMediaStreamTrackInterfaceKind(ptr); - - if (kind == webrtcMediaStreamTrackInterfaceKAudioKind()) - { - return new DisposableAudioTrackInterface(ptr); - } - - if (kind == webrtcMediaStreamTrackInterfaceKVideoKind()) - { - return new DisposableVideoTrackInterface(ptr); - } - - throw new ArgumentException(nameof(ptr)); - } - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamTrackInterfaceRelease")] - public static extern void Release(IntPtr ptr); - } - - public static class VideoTrackInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamTrackInterfaceToWebrtcVideoTrackInterface")] - public static extern IntPtr FromWebrtcMediaStreamTrackInterface(IntPtr track); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcVideoTrackInterfaceToWebrtcMediaStreamTrackInterface")] - public static extern IntPtr ToWebrtcMediaStreamTrackInterface(IntPtr track); - } - - public static class VideoTrackSourceInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaSourceInterfaceToWebrtcVideoTrackSourceInterface")] - public static extern IntPtr FromWebrtcMediaSourceInterface(IntPtr ptr); - } -} + castedNumberOfFrames + ); + } + } + + public static class MediaSourceInterface + { + public enum SourceState + { + Initializing, + Live, + Enabled, + Muted + } + } + + public static class AudioTrackInterfaceExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcAudioTrackInterfaceAddSink( + IntPtr track, + IntPtr sink + ); + + public static void AddSink( + this IAudioTrackInterface track, + IAudioTrackSinkInterface sink) + { + webrtcAudioTrackInterfaceAddSink(track.Ptr, sink.Ptr); + } + } + + public static class MediaStreamTrackInterfaceExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcMediaStreamTrackInterfaceId( + IntPtr ptr + ); + + public static string ID(this IMediaStreamTrackInterface track) + { + return Rtc.Interop.String.MoveToString( + webrtcMediaStreamTrackInterfaceId(track.Ptr)); + } + } + + public static class VideoTrackInterfaceExtension + { + private struct RtcVideoSinkWants + { + [MarshalAs(UnmanagedType.I1)] + public bool RotationApplied; + + [MarshalAs(UnmanagedType.I1)] + public bool BlackFrames; + + [MarshalAs(UnmanagedType.I1)] + public bool HasTargetPixelCount; + + public int MaxPixelCount; + public int TargetPixelCount; + public int MaxFramerateFps; + } + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcVideoTrackInterfaceAddOrUpdateSink( + IntPtr stream, + IntPtr sink, + in RtcVideoSinkWants wants + ); + + public static void AddOrUpdateSink( + this IVideoTrackInterface track, + IVideoSinkInterface sink, + VideoSinkWants wants) + { + var unmanagedWants = new RtcVideoSinkWants(); + + unmanagedWants.RotationApplied = wants.RotationApplied; + unmanagedWants.BlackFrames = wants.BlackFrames; + unmanagedWants.HasTargetPixelCount = wants.TargetPixelCount.HasValue; + unmanagedWants.MaxPixelCount = wants.MaxPixelCount; + unmanagedWants.MaxFramerateFps = wants.MaxFramerateFps; + + if (wants.TargetPixelCount.HasValue) + { + unmanagedWants.TargetPixelCount = (int)wants.TargetPixelCount; + } + + webrtcVideoTrackInterfaceAddOrUpdateSink( + track.Ptr, + sink.Ptr, + unmanagedWants + ); + } + } +} + +namespace Pixiv.Webrtc.Interop +{ + public static class AudioSourceInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcAudioSourceInterfaceToWebrtcMediaSourceInterface")] + public static extern IntPtr ToWebrtcMediaSourceInterface(IntPtr ptr); + } + + public static class AudioTrackInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamTrackInterfaceToWebrtcAudioTrackInterface")] + public static extern IntPtr FromWebrtcMediaStreamTrackInterface(IntPtr ptr); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcAudioTrackInterfaceToWebrtcMediaStreamTrackInterface")] + public static extern IntPtr ToWebrtcMediaStreamTrackInterface(IntPtr ptr); + } + + public static class MediaSourceInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaSourceInterfaceRelease")] + public static extern void Release(IntPtr ptr); + } + + public static class MediaStreamInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamInterfaceRelease")] + public static extern void Release(IntPtr ptr); + } + + public static class MediaStreamTrackInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcMediaStreamTrackInterfaceKAudioKind(); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcMediaStreamTrackInterfaceKVideoKind(); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcMediaStreamTrackInterfaceKind( + IntPtr ptr + ); + + public static DisposableMediaStreamTrackInterface WrapDisposable( + IntPtr ptr) + { + var kind = webrtcMediaStreamTrackInterfaceKind(ptr); + + if (kind == webrtcMediaStreamTrackInterfaceKAudioKind()) + { + return new DisposableAudioTrackInterface(ptr); + } + + if (kind == webrtcMediaStreamTrackInterfaceKVideoKind()) + { + return new DisposableVideoTrackInterface(ptr); + } + + throw new ArgumentException(nameof(ptr)); + } + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamTrackInterfaceRelease")] + public static extern void Release(IntPtr ptr); + } + + public static class VideoTrackInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaStreamTrackInterfaceToWebrtcVideoTrackInterface")] + public static extern IntPtr FromWebrtcMediaStreamTrackInterface(IntPtr track); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcVideoTrackInterfaceToWebrtcMediaStreamTrackInterface")] + public static extern IntPtr ToWebrtcMediaStreamTrackInterface(IntPtr track); + } + + public static class VideoTrackSourceInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcMediaSourceInterfaceToWebrtcVideoTrackSourceInterface")] + public static extern IntPtr FromWebrtcMediaSourceInterface(IntPtr ptr); + } +} From b534d6fb56f8f573ffbcd56917b908c5c01b626e Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 8 Jul 2020 10:14:17 +0800 Subject: [PATCH 65/85] update error handler --- sdk/dotnet/webrtc/api/jsep.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 6cf6cf1be7..f79549481d 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -194,7 +194,7 @@ public sealed class DisposableCreateSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context, IntPtr desc); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcError error); + private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -225,12 +225,12 @@ private static void OnSuccess(IntPtr context, IntPtr desc) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcError error) + private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) { var handle = (GCHandle)context; ((IManagedCreateSessionDescriptionObserver)handle.Target).OnFailure( - error + new RtcError(type, Marshal.PtrToStringAnsi(message)) ); } @@ -280,7 +280,7 @@ public sealed class DisposableSetSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcError error); + private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); private static FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -308,12 +308,12 @@ private static void OnSuccess(IntPtr context) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcError error) + private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) { var handle = (GCHandle)context; ((IManagedSetSessionDescriptionObserver)handle.Target).OnFailure( - error + new RtcError(type, Marshal.PtrToStringAnsi(message)) ); } From c7a449afb5538a4b885e7625b4b3a88c362426ed Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 8 Jul 2020 11:24:49 +0800 Subject: [PATCH 66/85] add build platforms --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index c0c827debb..e765672a9a 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64 + LinuxX64;WinX64;WinX86; ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From 4dba8803afc9f96f7cadd96a3e200bb7cb54827b Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 8 Jul 2020 14:54:45 +0800 Subject: [PATCH 67/85] remove x86 --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index e765672a9a..8b7da478a2 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;WinX64;WinX86; + LinuxX64;WinX64; ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From 4c60739cdde7e644db4a6bf381865ba58643a2bd Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Wed, 8 Jul 2020 16:06:00 +0800 Subject: [PATCH 68/85] remove winx64 --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 8b7da478a2..a1ce0ea2aa 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;WinX64; + LinuxX64; ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From baef370e181e2ef3ff5be134c28c991da1728ac6 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 10 Jul 2020 12:56:17 +0800 Subject: [PATCH 69/85] remove ; --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index a1ce0ea2aa..c0c827debb 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64; + LinuxX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From ac923d23ca8f90c5b2b97c43f9d4930fe029bf4b Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 10 Jul 2020 12:57:14 +0800 Subject: [PATCH 70/85] add winx64 --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index c0c827debb..a70d536a4f 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64 + LinuxX64;WinX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From 17b9bd469e8c34dbb28635ce9abd02b9ecfd145d Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 10 Jul 2020 13:48:16 +0800 Subject: [PATCH 71/85] Revert "update error handler" This reverts commit b534d6fb56f8f573ffbcd56917b908c5c01b626e. --- sdk/dotnet/webrtc/api/jsep.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index f79549481d..6cf6cf1be7 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -194,7 +194,7 @@ public sealed class DisposableCreateSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context, IntPtr desc); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); + private delegate void FailureHandler(IntPtr context, RtcError error); private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -225,12 +225,12 @@ private static void OnSuccess(IntPtr context, IntPtr desc) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) + private static void OnFailure(IntPtr context, RtcError error) { var handle = (GCHandle)context; ((IManagedCreateSessionDescriptionObserver)handle.Target).OnFailure( - new RtcError(type, Marshal.PtrToStringAnsi(message)) + error ); } @@ -280,7 +280,7 @@ public sealed class DisposableSetSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); + private delegate void FailureHandler(IntPtr context, RtcError error); private static FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -308,12 +308,12 @@ private static void OnSuccess(IntPtr context) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) + private static void OnFailure(IntPtr context, RtcError error) { var handle = (GCHandle)context; ((IManagedSetSessionDescriptionObserver)handle.Target).OnFailure( - new RtcError(type, Marshal.PtrToStringAnsi(message)) + error ); } From 4255836e4e303f98dc43d20b2b949a712539ccbe Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 10 Jul 2020 17:34:20 +0800 Subject: [PATCH 72/85] add turn server --- sdk/c/api/create_turn_server.cc | 67 +++++++++++++++++++++ sdk/c/api/create_turn_server.h | 22 +++++++ sdk/dotnet/unity/unity.msbuildproj | 2 +- sdk/dotnet/webrtc/api/create_turn_server.cs | 14 +++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 sdk/c/api/create_turn_server.cc create mode 100644 sdk/c/api/create_turn_server.h create mode 100644 sdk/dotnet/webrtc/api/create_turn_server.cs diff --git a/sdk/c/api/create_turn_server.cc b/sdk/c/api/create_turn_server.cc new file mode 100644 index 0000000000..b58759d741 --- /dev/null +++ b/sdk/c/api/create_turn_server.cc @@ -0,0 +1,67 @@ +/* + * Copyright 2012 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include +#include + +#include "p2p/base/basic_packet_socket_factory.h" +#include "p2p/base/port_interface.h" +#include "p2p/base/turn_server.h" +#include "rtc_base/async_udp_socket.h" +#include "rtc_base/ip_address.h" +#include "rtc_base/socket_address.h" +#include "rtc_base/socket_server.h" +#include "rtc_base/thread.h" + +extern "C" void +webrtcCreateTURNServer( + const char* local_addr, + const char* ip_addr) { + + rtc::SocketAddress int_addr; + if (!int_addr.FromString(local_addr)) { + //local_addr = localhost:8091 + std::cerr << "Unable to parse socket address: " << local_addr << std::endl; + return; + } + + rtc::IPAddress ext_addr; + if (!IPFromString(ip_addr, &ext_addr)) { + //ip_addr = localhost + std::cerr << "Unable to parse IP address: " << ip_addr << std::endl; + return; + } + + rtc::Thread* main = rtc::Thread::Current(); + rtc::AsyncUDPSocket* int_socket = + rtc::AsyncUDPSocket::Create(main->socketserver(), int_addr); + if (!int_socket) { + std::cerr << "Failed to create a UDP socket bound at" << int_addr.ToString() + << std::endl; + return; + } + + cricket::TurnServer server(main); + + TurnFileAuth auth(std::map()); + server.set_realm("Agent"); + server.set_software("Agent"); + server.set_auth_hook(&auth); + server.AddInternalSocket(int_socket, cricket::PROTO_UDP); + server.SetExternalSocketFactory(new rtc::BasicPacketSocketFactory(), + rtc::SocketAddress(ext_addr, 0)); + + std::cout << "Listening internally at " << int_addr.ToString() << std::endl; + + main->Run(); +} diff --git a/sdk/c/api/create_turn_server.h b/sdk/c/api/create_turn_server.h new file mode 100644 index 0000000000..1137af86f6 --- /dev/null +++ b/sdk/c/api/create_turn_server.h @@ -0,0 +1,22 @@ +/* + * Copyright 2019 pixiv Inc. 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/interop.h" + +#ifdef __cplusplus +extern "C" { +#endif + +RTC_EXPORT void webrtcCreateTURNServer( + const char* local_addr, + const char* ip_addr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index a70d536a4f..c0c827debb 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;WinX64 + LinuxX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) diff --git a/sdk/dotnet/webrtc/api/create_turn_server.cs b/sdk/dotnet/webrtc/api/create_turn_server.cs new file mode 100644 index 0000000000..c7257f55a9 --- /dev/null +++ b/sdk/dotnet/webrtc/api/create_turn_server.cs @@ -0,0 +1,14 @@ +using Pixiv.Rtc; +using System; +using System.Runtime.InteropServices; + +namespace Pixiv.Webrtc +{ + public static class TurnServer + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcCreateTURNServer( + string local_addr, + string ip_addr); + } +} From 6be96031466e082ed72fcdbe7b9a851778137a35 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Fri, 10 Jul 2020 17:51:21 +0800 Subject: [PATCH 73/85] fark --- sdk/dotnet/unity/unity.msbuildproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index c0c827debb..aafdd79ccb 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64 + LinuxX64;WinX64;WinX86 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From b6e46dd3ecb58b6c4e570c74fdcda415b5b4e603 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Tue, 14 Jul 2020 11:17:25 +0800 Subject: [PATCH 74/85] add turn server --- p2p/BUILD.gn | 1 - p2p/base/turn_server.cc | 2 +- p2p/base/turn_server.h | 6 ++ rtc_base/BUILD.gn | 1 - rtc_base/virtual_socket_server.cc | 3 +- sdk/c/BUILD.gn | 1 + sdk/c/api/BUILD.gn | 14 +++++ sdk/c/api/create_turn_server.cc | 66 ++++++++++++++++----- sdk/c/api/create_turn_server.h | 7 ++- sdk/c_headers_test.c | 1 + sdk/dotnet/unity/unity.msbuildproj | 2 +- sdk/dotnet/webrtc/api/create_turn_server.cs | 7 ++- 12 files changed, 85 insertions(+), 26 deletions(-) diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn index 3ef59f3c5d..da2801ce9b 100644 --- a/p2p/BUILD.gn +++ b/p2p/BUILD.gn @@ -239,7 +239,6 @@ if (rtc_include_tests) { } rtc_source_set("p2p_server_utils") { - testonly = true sources = [ "base/relay_server.cc", "base/relay_server.h", diff --git a/p2p/base/turn_server.cc b/p2p/base/turn_server.cc index cd00e5fdef..119c9cacbf 100644 --- a/p2p/base/turn_server.cc +++ b/p2p/base/turn_server.cc @@ -464,7 +464,7 @@ TurnServerAllocation* TurnServer::CreateAllocation(TurnServerConnection* conn, RTC_DCHECK(thread_checker_.IsCurrent()); rtc::AsyncPacketSocket* external_socket = (external_socket_factory_) - ? external_socket_factory_->CreateUdpSocket(external_addr_, 0, 0) + ? external_socket_factory_->CreateUdpSocket(external_addr_, min_udp_port_, max_udp_port_) : NULL; if (!external_socket) { return NULL; diff --git a/p2p/base/turn_server.h b/p2p/base/turn_server.h index 7308cd529a..1bd0eccfd0 100644 --- a/p2p/base/turn_server.h +++ b/p2p/base/turn_server.h @@ -191,6 +191,10 @@ class TurnServer : public sigslot::has_slots<> { RTC_DCHECK(thread_checker_.IsCurrent()); realm_ = realm; } + void set_port_range(size_t min_udp_port, size_t max_udp_port){ + min_udp_port_ = min_udp_port; + max_udp_port_ = max_udp_port; + } // Gets/sets the value for the SOFTWARE attribute for TURN messages. const std::string& software() const { @@ -336,6 +340,8 @@ class TurnServer : public sigslot::has_slots<> { std::vector> sockets_to_delete_; std::unique_ptr external_socket_factory_; rtc::SocketAddress external_addr_; + size_t min_udp_port_ = 0; + size_t max_udp_port_ = 0; AllocationMap allocations_; diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 7b0108d45d..f5c7e900b5 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -1007,7 +1007,6 @@ rtc_source_set("testclient") { } rtc_source_set("rtc_base_tests_utils") { - testonly = true sources = [ "cpu_time.cc", "cpu_time.h", diff --git a/rtc_base/virtual_socket_server.cc b/rtc_base/virtual_socket_server.cc index 83cf05827a..8c7ebb96e4 100644 --- a/rtc_base/virtual_socket_server.cc +++ b/rtc_base/virtual_socket_server.cc @@ -1026,10 +1026,9 @@ void VirtualSocketServer::UpdateDelayDistribution() { } } -static double PI = 4 * atan(1.0); - static double Normal(double x, double mean, double stddev) { double a = (x - mean) * (x - mean) / (2 * stddev * stddev); + double PI = 4 * atan(1.0); return exp(-a) / (stddev * sqrt(2 * PI)); } diff --git a/sdk/c/BUILD.gn b/sdk/c/BUILD.gn index 93b3827073..bd51633744 100644 --- a/sdk/c/BUILD.gn +++ b/sdk/c/BUILD.gn @@ -12,6 +12,7 @@ rtc_source_set("c") { deps = [ "api:audio_codecs", "api:create_peerconnection_factory", + "api:create_turn_server", "api:libjingle_peerconnection_api", "api:video_codecs", "api/video:video_frame", diff --git a/sdk/c/api/BUILD.gn b/sdk/c/api/BUILD.gn index 8b5e1d57e5..4f164b967b 100644 --- a/sdk/c/api/BUILD.gn +++ b/sdk/c/api/BUILD.gn @@ -63,3 +63,17 @@ rtc_source_set("video_codecs") { "../../../api/video_codecs:builtin_video_encoder_factory", ] } + +rtc_source_set("create_turn_server") { + sources = [ + "create_turn_server.cc", + "create_turn_server.h", + ] + deps = [ + "../../../p2p:p2p_server_utils", + "../../../p2p:rtc_p2p", + "../../../pc:rtc_pc", + "../../../rtc_base", + "../../../rtc_base:rtc_base_approved", + ] +} diff --git a/sdk/c/api/create_turn_server.cc b/sdk/c/api/create_turn_server.cc index b58759d741..efdc3ff8ad 100644 --- a/sdk/c/api/create_turn_server.cc +++ b/sdk/c/api/create_turn_server.cc @@ -7,8 +7,6 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ - -#include #include #include #include @@ -22,46 +20,82 @@ #include "rtc_base/socket_address.h" #include "rtc_base/socket_server.h" #include "rtc_base/thread.h" +#include "rtc_base/string_encode.h" +#include "create_turn_server.h" + + +namespace { +class TurnFileAuth : public cricket::TurnAuthInterface { + public: + explicit TurnFileAuth(std::map name_to_key) + : name_to_key_(std::move(name_to_key)) {} + + virtual bool GetKey(const std::string& username, + const std::string& realm, + std::string* key) { + auto it = name_to_key_.find(username); + std::cerr << "TURN: Welcome " << username << std::endl; + if (it == name_to_key_.end()) { + return false; + } + *key = it->second; + return true; + } -extern "C" void -webrtcCreateTURNServer( + private: + const std::map name_to_key_; +}; + +} // namespace + +RTC_EXPORT extern "C" void webrtcCreateTURNServer( + RtcThread* network_thread, const char* local_addr, - const char* ip_addr) { + const char* ip_addr, + size_t min_port, + size_t max_port) { + + rtc::Thread* thread = rtc::ToCplusplus(network_thread); + //rtc::Thread* thread = rtc::Thread::Current(); rtc::SocketAddress int_addr; if (!int_addr.FromString(local_addr)) { - //local_addr = localhost:8091 std::cerr << "Unable to parse socket address: " << local_addr << std::endl; return; } rtc::IPAddress ext_addr; if (!IPFromString(ip_addr, &ext_addr)) { - //ip_addr = localhost std::cerr << "Unable to parse IP address: " << ip_addr << std::endl; return; } - rtc::Thread* main = rtc::Thread::Current(); rtc::AsyncUDPSocket* int_socket = - rtc::AsyncUDPSocket::Create(main->socketserver(), int_addr); + rtc::AsyncUDPSocket::Create(thread->socketserver(), int_addr); if (!int_socket) { - std::cerr << "Failed to create a UDP socket bound at" << int_addr.ToString() + std::cerr << "Failed to create a UDP socket bound at " << int_addr.ToString() << std::endl; return; } - cricket::TurnServer server(main); - - TurnFileAuth auth(std::map()); + cricket::TurnServer server(thread); + std::string pwd = "a8a16ccd399c0a716e1bca6be0016d6f"; + char buf[32]; + size_t len = rtc::hex_decode(buf, sizeof(buf), pwd.data(),pwd.size()); + std::map usrs = { + {"user",std::string(buf, len)} + }; + TurnFileAuth auth(usrs); server.set_realm("Agent"); server.set_software("Agent"); + server.set_port_range(min_port,max_port); + std::cerr << "Set TURN min port to " << min_port << std::endl; + std::cerr << "Set TURN max port to " << max_port << std::endl; server.set_auth_hook(&auth); server.AddInternalSocket(int_socket, cricket::PROTO_UDP); server.SetExternalSocketFactory(new rtc::BasicPacketSocketFactory(), rtc::SocketAddress(ext_addr, 0)); - std::cout << "Listening internally at " << int_addr.ToString() << std::endl; - - main->Run(); + std::cout << "TURN Listening at " << int_addr.ToString() << std::endl; + thread->Run(); } diff --git a/sdk/c/api/create_turn_server.h b/sdk/c/api/create_turn_server.h index 1137af86f6..68b41884c5 100644 --- a/sdk/c/api/create_turn_server.h +++ b/sdk/c/api/create_turn_server.h @@ -6,17 +6,20 @@ */ #include "sdk/c/interop.h" +#include "sdk/c/rtc_base/thread.h" #ifdef __cplusplus extern "C" { #endif RTC_EXPORT void webrtcCreateTURNServer( + RtcThread* network_thread, const char* local_addr, - const char* ip_addr); + const char* ip_addr, + size_t min_port, + size_t max_port); #ifdef __cplusplus } #endif -#endif diff --git a/sdk/c_headers_test.c b/sdk/c_headers_test.c index 5bba96b31b..7ec675b20c 100644 --- a/sdk/c_headers_test.c +++ b/sdk/c_headers_test.c @@ -15,6 +15,7 @@ #include "sdk/c/api/video/video_sink_interface.h" #include "sdk/c/api/audio_codecs.h" #include "sdk/c/api/create_peerconnection_factory.h" +#include "sdk/c/api/create_turn_server.h" #include "sdk/c/api/data_channel_interface.h" #include "sdk/c/api/jsep.h" #include "sdk/c/api/rtc_error.h" diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index aafdd79ccb..9c87ef50ed 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - LinuxX64;WinX64;WinX86 + WinX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) diff --git a/sdk/dotnet/webrtc/api/create_turn_server.cs b/sdk/dotnet/webrtc/api/create_turn_server.cs index c7257f55a9..f9c082923d 100644 --- a/sdk/dotnet/webrtc/api/create_turn_server.cs +++ b/sdk/dotnet/webrtc/api/create_turn_server.cs @@ -7,8 +7,11 @@ namespace Pixiv.Webrtc public static class TurnServer { [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern void webrtcCreateTURNServer( + public static extern void webrtcCreateTURNServer( + IntPtr thread, string local_addr, - string ip_addr); + string ip_addr, + int min_port, + int max_port); } } From cb34f26e86e6d1f068dd070d37b0368d6bff3cce Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 16 Jul 2020 12:45:54 +0800 Subject: [PATCH 75/85] remove debug info --- sdk/c/api/create_turn_server.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sdk/c/api/create_turn_server.cc b/sdk/c/api/create_turn_server.cc index efdc3ff8ad..a463843f64 100644 --- a/sdk/c/api/create_turn_server.cc +++ b/sdk/c/api/create_turn_server.cc @@ -56,8 +56,6 @@ RTC_EXPORT extern "C" void webrtcCreateTURNServer( size_t max_port) { rtc::Thread* thread = rtc::ToCplusplus(network_thread); - //rtc::Thread* thread = rtc::Thread::Current(); - rtc::SocketAddress int_addr; if (!int_addr.FromString(local_addr)) { std::cerr << "Unable to parse socket address: " << local_addr << std::endl; @@ -89,13 +87,9 @@ RTC_EXPORT extern "C" void webrtcCreateTURNServer( server.set_realm("Agent"); server.set_software("Agent"); server.set_port_range(min_port,max_port); - std::cerr << "Set TURN min port to " << min_port << std::endl; - std::cerr << "Set TURN max port to " << max_port << std::endl; server.set_auth_hook(&auth); server.AddInternalSocket(int_socket, cricket::PROTO_UDP); server.SetExternalSocketFactory(new rtc::BasicPacketSocketFactory(), rtc::SocketAddress(ext_addr, 0)); - - std::cout << "TURN Listening at " << int_addr.ToString() << std::endl; thread->Run(); } From 9c3dbcb288ee5bfb9ef7366b8ef40c27f3ebf6e4 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 3 Sep 2020 08:37:56 +0800 Subject: [PATCH 76/85] updates to managed code --- sdk/dotnet/unity/unity.msbuildproj | 6 +- .../api/create_peerconnection_factory.cs | 41 ++- sdk/dotnet/webrtc/api/jsep.cs | 23 +- .../webrtc/api/media_stream_interface.cs | 47 ++- .../webrtc/api/peer_connection_interface.cs | 294 ++++++++++++++---- .../webrtc/api/rtp_receiver_interface.cs | 11 +- .../webrtc/api/rtp_transceiver_interface.cs | 11 +- sdk/dotnet/webrtc/api/video/i420_buffer.cs | 13 + sdk/dotnet/webrtc/api/video/video_buffer.cs | 7 + sdk/dotnet/webrtc/api/video/video_frame.cs | 92 +++++- sdk/dotnet/webrtc/common_video.cs | 26 +- .../media/base/adapted_video_track_source.cs | 5 + sdk/dotnet/webrtc/modules.cs | 5 + sdk/dotnet/webrtc/rtc_base.cs | 29 +- 14 files changed, 507 insertions(+), 103 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 9c87ef50ed..3f7c932614 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - WinX64 + ;WinX64;WinX86; ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) @@ -39,12 +39,12 @@ - + diff --git a/sdk/dotnet/webrtc/api/create_peerconnection_factory.cs b/sdk/dotnet/webrtc/api/create_peerconnection_factory.cs index 2d87f7b293..7954212a97 100644 --- a/sdk/dotnet/webrtc/api/create_peerconnection_factory.cs +++ b/sdk/dotnet/webrtc/api/create_peerconnection_factory.cs @@ -61,22 +61,33 @@ public static DisposablePeerConnectionFactoryInterface Create( videoDecoderFactory.ReleasePtr(); } - return new DisposablePeerConnectionFactoryInterface( - webrtcCreatePeerConnectionFactory( - networkThread == null ? IntPtr.Zero : networkThread.Ptr, - workerThread == null ? IntPtr.Zero : workerThread.Ptr, - signalingThread == null ? IntPtr.Zero : signalingThread.Ptr, - defaultAdm == null ? IntPtr.Zero : defaultAdm.Ptr, - audioEncoderFactory == null ? - IntPtr.Zero : audioEncoderFactory.Ptr, - audioDecoderFactory == null ? - IntPtr.Zero : audioDecoderFactory.Ptr, - videoEncoderFactoryPtr, - videoDecoderFactoryPtr, - audioMixer == null ? IntPtr.Zero : audioMixer.Ptr, - audioProcessing == null ? IntPtr.Zero : audioProcessing.Ptr - ) + var factory = webrtcCreatePeerConnectionFactory( + networkThread == null ? IntPtr.Zero : networkThread.Ptr, + workerThread == null ? IntPtr.Zero : workerThread.Ptr, + signalingThread == null ? IntPtr.Zero : signalingThread.Ptr, + defaultAdm == null ? IntPtr.Zero : defaultAdm.Ptr, + audioEncoderFactory == null ? + IntPtr.Zero : audioEncoderFactory.Ptr, + audioDecoderFactory == null ? + IntPtr.Zero : audioDecoderFactory.Ptr, + videoEncoderFactoryPtr, + videoDecoderFactoryPtr, + audioMixer == null ? IntPtr.Zero : audioMixer.Ptr, + audioProcessing == null ? IntPtr.Zero : audioProcessing.Ptr ); + + GC.KeepAlive(networkThread); + GC.KeepAlive(workerThread); + GC.KeepAlive(signalingThread); + GC.KeepAlive(defaultAdm); + GC.KeepAlive(audioEncoderFactory); + GC.KeepAlive(audioDecoderFactory); + GC.KeepAlive(videoEncoderFactory); + GC.KeepAlive(videoDecoderFactory); + GC.KeepAlive(audioMixer); + GC.KeepAlive(audioProcessing); + + return new DisposablePeerConnectionFactoryInterface(factory); } } } diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index 6cf6cf1be7..bf03408d5f 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -194,7 +194,7 @@ public sealed class DisposableCreateSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context, IntPtr desc); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcError error); + private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -225,12 +225,12 @@ private static void OnSuccess(IntPtr context, IntPtr desc) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcError error) + private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) { var handle = (GCHandle)context; ((IManagedCreateSessionDescriptionObserver)handle.Target).OnFailure( - error + new RtcError(type, Marshal.PtrToStringAnsi(message)) ); } @@ -280,7 +280,7 @@ public sealed class DisposableSetSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcError error); + private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); private static FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -308,12 +308,12 @@ private static void OnSuccess(IntPtr context) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcError error) + private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) { var handle = (GCHandle)context; ((IManagedSetSessionDescriptionObserver)handle.Target).OnFailure( - error + new RtcError(type, Marshal.PtrToStringAnsi(message)) ); } @@ -362,6 +362,11 @@ out IntPtr sdp public static bool Resolve( this IIceCandidateInterface candidate, out string sdpMid, out int sdpMLineIndex, out string sdp) { + if (candidate == null) + { + throw new ArgumentNullException(nameof(candidate)); + } + var result = webrtcIceCandidateInterfaceResolve( candidate.Ptr, out var _sdpMid, out sdpMLineIndex, out var _sdp); @@ -406,9 +411,13 @@ public static bool TryToString( this ISessionDescriptionInterface desc, out string s) { + if (desc == null) + { + throw new ArgumentNullException(nameof(desc)); + } var result = webrtcSessionDescriptionInterfaceToString( desc.Ptr, out var webrtcString); - + GC.KeepAlive(desc); s = Rtc.Interop.String.MoveToString(webrtcString); return result; diff --git a/sdk/dotnet/webrtc/api/media_stream_interface.cs b/sdk/dotnet/webrtc/api/media_stream_interface.cs index 9feed7599f..9d4c0c211b 100644 --- a/sdk/dotnet/webrtc/api/media_stream_interface.cs +++ b/sdk/dotnet/webrtc/api/media_stream_interface.cs @@ -352,6 +352,11 @@ public static void OnData( { UIntPtr castedNumberOfChannels; UIntPtr castedNumberOfFrames; + + if (sink == null) + { + throw new ArgumentNullException(nameof(sink)); + } try { castedNumberOfChannels = (UIntPtr)numberOfChannels; @@ -377,6 +382,8 @@ public static void OnData( castedNumberOfChannels, castedNumberOfFrames ); + + GC.KeepAlive(sink); } } @@ -403,7 +410,19 @@ public static void AddSink( this IAudioTrackInterface track, IAudioTrackSinkInterface sink) { + if (track == null) + { + throw new ArgumentNullException(nameof(track)); + } + + if (sink == null) + { + throw new ArgumentNullException(nameof(sink)); + } + webrtcAudioTrackInterfaceAddSink(track.Ptr, sink.Ptr); + GC.KeepAlive(track); + GC.KeepAlive(sink); } } @@ -416,8 +435,14 @@ IntPtr ptr public static string ID(this IMediaStreamTrackInterface track) { - return Rtc.Interop.String.MoveToString( - webrtcMediaStreamTrackInterfaceId(track.Ptr)); + if (track == null) + { + throw new ArgumentNullException(nameof(track)); + } + var id = webrtcMediaStreamTrackInterfaceId(track.Ptr); + GC.KeepAlive(track); + + return Rtc.Interop.String.MoveToString(id); } } @@ -451,6 +476,21 @@ public static void AddOrUpdateSink( IVideoSinkInterface sink, VideoSinkWants wants) { + if (track == null) + { + throw new ArgumentNullException(nameof(track)); + } + + if (sink == null) + { + throw new ArgumentNullException(nameof(sink)); + } + + if (wants == null) + { + throw new ArgumentNullException(nameof(wants)); + } + var unmanagedWants = new RtcVideoSinkWants(); unmanagedWants.RotationApplied = wants.RotationApplied; @@ -469,6 +509,9 @@ public static void AddOrUpdateSink( sink.Ptr, unmanagedWants ); + + GC.KeepAlive(track); + GC.KeepAlive(sink); } } } diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index 723979844b..8c906d2c4e 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -542,7 +542,32 @@ public static DisposablePeerConnectionInterface CreatePeerConnection( PeerConnectionInterface.RtcConfiguration configuration, PeerConnectionDependencies dependencies) { - var servers = new WebrtcIceServer[configuration.Servers.Length]; + if (factory == null) + { + throw new ArgumentNullException(nameof(factory)); + } + + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + if (configuration.Servers == null) + { + throw new ArgumentException("Servers property is null", nameof(configuration)); + } + + if (configuration.Certificates == null) + { + throw new ArgumentException("Certificates property is null", nameof(configuration)); + } + + if (dependencies == null) + { + throw new ArgumentNullException(nameof(dependencies)); + } + + var servers = new WebrtcIceServer[configuration.Servers.LongLength]; var sizeOfPtr = Marshal.SizeOf(); var unmanagedConfiguration = new WebrtcRTCConfiguration(); var unmanagedDependencies = new WebrtcPeerConnectionDependencies(); @@ -586,30 +611,41 @@ public static DisposablePeerConnectionInterface CreatePeerConnection( var serversHandle = GCHandle.Alloc(servers, GCHandleType.Pinned); - for (var index = 0; index < configuration.Servers.Length; index++) - { - var server = configuration.Servers[index]; - ref var unmanagedServer = ref servers[index]; - - unmanagedServer.UrlsSize = new UIntPtr((uint)server.Urls.Length); - unmanagedServer.TlsCertPolicy = server.TlsCertPolicy; - unmanagedServer.TlsAlpnProtocolsSize = new UIntPtr((uint)server.TlsAlpnProtocols.Length); - unmanagedServer.TlsEllipticCurvesSize = new UIntPtr((uint)server.TlsEllipticCurves.Length); - - unmanagedServer.Uri = Marshal.StringToHGlobalAnsi(server.Uri); - unmanagedServer.Urls = StringArrayToHGlobalAnsiArrayPtr(server.Urls); - unmanagedServer.Username = Marshal.StringToHGlobalAnsi(server.Username); - unmanagedServer.Password = Marshal.StringToHGlobalAnsi(server.Password); - unmanagedServer.Hostname = Marshal.StringToHGlobalAnsi(server.Hostname); - unmanagedServer.TlsAlpnProtocols = StringArrayToHGlobalAnsiArrayPtr(server.TlsAlpnProtocols); - unmanagedServer.TlsEllipticCurves = StringArrayToHGlobalAnsiArrayPtr(server.TlsEllipticCurves); - } - var certificatesCursor = Marshal.AllocHGlobal(sizeOfPtr * configuration.Certificates.Length); unmanagedConfiguration.Certificates = certificatesCursor; try { + for (var index = 0; index < configuration.Servers.Length; index++) + { + var server = configuration.Servers[index]; + ref var unmanagedServer = ref servers[index]; + + if (server.Urls == null) + { + throw new ArgumentException("Urls property of an element of Server property is null", nameof(configuration)); + } + + if (server.TlsAlpnProtocols == null) + { + throw new ArgumentException("TlsAlpnProtocols property of an element of Server property is null", nameof(configuration)); + } + + unmanagedServer.UrlsSize = new UIntPtr((ulong)server.Urls.LongLength); + unmanagedServer.TlsCertPolicy = server.TlsCertPolicy; + unmanagedServer.TlsAlpnProtocolsSize = new UIntPtr((uint)server.TlsAlpnProtocols.Length); + unmanagedServer.TlsEllipticCurvesSize = new UIntPtr((uint)server.TlsEllipticCurves.Length); + + unmanagedServer.Uri = Marshal.StringToHGlobalAnsi(server.Uri); + unmanagedServer.Urls = StringArrayToHGlobalAnsiArrayPtr(server.Urls); + unmanagedServer.Username = Marshal.StringToHGlobalAnsi(server.Username); + unmanagedServer.Password = Marshal.StringToHGlobalAnsi(server.Password); + unmanagedServer.Hostname = Marshal.StringToHGlobalAnsi(server.Hostname); + unmanagedServer.TlsAlpnProtocols = StringArrayToHGlobalAnsiArrayPtr(server.TlsAlpnProtocols); + unmanagedServer.TlsEllipticCurves = StringArrayToHGlobalAnsiArrayPtr(server.TlsEllipticCurves); + } + + if (dependencies.Allocator != null) { unmanagedDependencies.Allocator = dependencies.Allocator.Ptr; @@ -644,17 +680,24 @@ public static DisposablePeerConnectionInterface CreatePeerConnection( foreach (var certificate in configuration.Certificates) { + if (certificate == null) + { + throw new ArgumentException("An element of Certificates property is null", nameof(configuration)); + } Marshal.WriteIntPtr(certificatesCursor, certificate.Ptr); certificatesCursor += sizeOfPtr; } - return new DisposablePeerConnectionInterface( - webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( - factory.Ptr, - unmanagedConfiguration, - unmanagedDependencies - ) - ); + var connection = webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( + factory.Ptr, + unmanagedConfiguration, + unmanagedDependencies + ); + + GC.KeepAlive(factory); + GC.KeepAlive(configuration); + + return new DisposablePeerConnectionInterface(connection); } finally { @@ -662,26 +705,50 @@ public static DisposablePeerConnectionInterface CreatePeerConnection( { var server = configuration.Servers[index]; ref var unmanagedServer = ref servers[index]; + if (unmanagedServer.TlsEllipticCurves != IntPtr.Zero) + { + FreeHGlobalAnsiArrayPtr( + unmanagedServer.TlsEllipticCurves, + server.TlsEllipticCurves + ); + } + + if (unmanagedServer.TlsAlpnProtocols != IntPtr.Zero) + { + FreeHGlobalAnsiArrayPtr( + unmanagedServer.TlsAlpnProtocols, + server.TlsAlpnProtocols + ); + } + + if (unmanagedServer.Urls != IntPtr.Zero) + { + FreeHGlobalAnsiArrayPtr( + unmanagedServer.Urls, + server.Urls + ); + } + + if (unmanagedServer.Hostname != IntPtr.Zero) + { + Marshal.FreeHGlobal(unmanagedServer.Hostname); + } + + if (unmanagedServer.Password != IntPtr.Zero) + { + Marshal.FreeHGlobal(unmanagedServer.Password); + } + + if (unmanagedServer.Username != IntPtr.Zero) + { + Marshal.FreeHGlobal(unmanagedServer.Username); + } + + if (unmanagedServer.Uri != null) + { + Marshal.FreeHGlobal(unmanagedServer.Uri); + } - FreeHGlobalAnsiArrayPtr( - unmanagedServer.TlsEllipticCurves, - server.TlsEllipticCurves - ); - - FreeHGlobalAnsiArrayPtr( - unmanagedServer.TlsAlpnProtocols, - server.TlsAlpnProtocols - ); - - FreeHGlobalAnsiArrayPtr( - unmanagedServer.Urls, - server.Urls - ); - - Marshal.FreeHGlobal(unmanagedServer.Hostname); - Marshal.FreeHGlobal(unmanagedServer.Password); - Marshal.FreeHGlobal(unmanagedServer.Username); - Marshal.FreeHGlobal(unmanagedServer.Uri); } Marshal.FreeHGlobal(unmanagedConfiguration.Certificates); @@ -694,13 +761,28 @@ public static DisposableAudioTrackInterface CreateAudioTrack( string label, IAudioSourceInterface source) { + if (factory == null) + { + throw new ArgumentNullException(nameof(factory)); + } + + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + var track = webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( + factory.Ptr, + label, + source.Ptr + ); + + GC.KeepAlive(factory); + GC.KeepAlive(source); + return new DisposableAudioTrackInterface( Interop.AudioTrackInterface.ToWebrtcMediaStreamTrackInterface( - webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( - factory.Ptr, - label, - source.Ptr - ) + track ) ); } @@ -710,13 +792,27 @@ public static DisposableVideoTrackInterface CreateVideoTrack( string label, IVideoTrackSourceInterface source) { + if (factory == null) + { + throw new ArgumentNullException(nameof(factory)); + } + + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + var track = webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( + factory.Ptr, + label, + source.Ptr + ); + + GC.KeepAlive(factory); + GC.KeepAlive(source); return new DisposableVideoTrackInterface( Interop.VideoTrackInterface.ToWebrtcMediaStreamTrackInterface( - webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( - factory.Ptr, - label, - source.Ptr - ) + track ) ); } @@ -914,10 +1010,28 @@ public static RtcErrorOr AddTrack( string[] streamIds) { RtcError error; + + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + + if (track == null) + { + throw new ArgumentNullException(nameof(track)); + } + + if (streamIds == null) + { + throw new ArgumentNullException(nameof(streamIds)); + } var size = new UIntPtr((ulong)streamIds.LongLength); var result = webrtcPeerConnectionInterfaceAddTrack( connection.Ptr, track.Ptr, streamIds, size); + GC.KeepAlive(connection); + GC.KeepAlive(track); + try { error = new RtcError(result.Error); @@ -947,7 +1061,14 @@ public static bool AddICECandidate(this IPeerConnectionInterface connection, public static void Close(this IPeerConnectionInterface connection) { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + webrtcPeerConnectionInterfaceClose(connection.Ptr); + GC.KeepAlive(connection); + } public static void CreateAnswer( @@ -955,8 +1076,16 @@ public static void CreateAnswer( ICreateSessionDescriptionObserver observer, PeerConnectionInterface.RtcOfferAnswerOptions options) { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + webrtcPeerConnectionInterfaceCreateAnswer( connection.Ptr, observer.Ptr, options); + + GC.KeepAlive(connection); + GC.KeepAlive(observer); } public static void CreateOffer( @@ -964,18 +1093,37 @@ public static void CreateOffer( ICreateSessionDescriptionObserver observer, PeerConnectionInterface.RtcOfferAnswerOptions options) { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + + if (observer == null) + { + throw new ArgumentNullException(nameof(observer)); + } + webrtcPeerConnectionInterfaceCreateOffer( connection.Ptr, observer.Ptr, options); + + GC.KeepAlive(connection); + GC.KeepAlive(observer); } public static void SetAudioRecording( this IPeerConnectionInterface connection, bool recording) { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + webrtcPeerConnectionInterfaceSetAudioRecording( connection.Ptr, recording ); + GC.KeepAlive(connection); } public static void SetLocalDescription( @@ -983,9 +1131,27 @@ public static void SetLocalDescription( ISetSessionDescriptionObserver observer, IDisposableSessionDescriptionInterface desc) { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + + if (observer == null) + { + throw new ArgumentNullException(nameof(observer)); + } + + if (desc == null) + { + throw new ArgumentNullException(nameof(desc)); + } + webrtcPeerConnectionInterfaceSetLocalDescription( connection.Ptr, observer.Ptr, desc.Ptr); + GC.KeepAlive(connection); + GC.KeepAlive(observer); + desc.ReleasePtr(); } @@ -994,9 +1160,25 @@ public static void SetRemoteDescription( ISetSessionDescriptionObserver observer, IDisposableSessionDescriptionInterface desc) { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + + if (observer == null) + { + throw new ArgumentNullException(nameof(observer)); + } + + if (desc == null) + { + throw new ArgumentNullException(nameof(desc)); + } webrtcPeerConnectionInterfaceSetRemoteDescription( connection.Ptr, observer.Ptr, desc.Ptr); + GC.KeepAlive(connection); + GC.KeepAlive(observer); desc.ReleasePtr(); } } diff --git a/sdk/dotnet/webrtc/api/rtp_receiver_interface.cs b/sdk/dotnet/webrtc/api/rtp_receiver_interface.cs index 7f414b8dad..9272ace6be 100644 --- a/sdk/dotnet/webrtc/api/rtp_receiver_interface.cs +++ b/sdk/dotnet/webrtc/api/rtp_receiver_interface.cs @@ -46,8 +46,15 @@ IntPtr ptr public static DisposableMediaStreamTrackInterface Track( this IRtpReceiverInterface receiver) { - return Interop.MediaStreamTrackInterface.WrapDisposable( - webrtcRtpReceiverInterfaceTrack(receiver.Ptr)); + if (receiver == null) + { + throw new ArgumentNullException(nameof(receiver)); + } + + var track = webrtcRtpReceiverInterfaceTrack(receiver.Ptr); + GC.KeepAlive(receiver); + + return Interop.MediaStreamTrackInterface.WrapDisposable(track); } } } diff --git a/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs b/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs index 3e41471cc1..e659b1a7b4 100644 --- a/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs +++ b/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs @@ -46,8 +46,15 @@ IntPtr ptr public static DisposableRtpReceiverInterface Receiver( this IRtpTransceiverInterface transceiver) { - return new DisposableRtpReceiverInterface( - webrtcRtpTransceiverInterfaceReceiver(transceiver.Ptr)); + if (transceiver == null) + { + throw new ArgumentNullException(nameof(transceiver)); + } + + var receiver = webrtcRtpTransceiverInterfaceReceiver(transceiver.Ptr); + GC.KeepAlive(receiver); + + return new DisposableRtpReceiverInterface(receiver); } } } diff --git a/sdk/dotnet/webrtc/api/video/i420_buffer.cs b/sdk/dotnet/webrtc/api/video/i420_buffer.cs index a35a0dac85..84827d2350 100644 --- a/sdk/dotnet/webrtc/api/video/i420_buffer.cs +++ b/sdk/dotnet/webrtc/api/video/i420_buffer.cs @@ -94,7 +94,20 @@ IntPtr src public static void ScaleFrom( this II420Buffer dest, II420BufferInterface src) { + if (dest == null) + { + throw new ArgumentNullException(nameof(dest)); + } + + if (src == null) + { + throw new ArgumentNullException(nameof(src)); + } + webrtcI420BufferScaleFrom(dest.Ptr, src.Ptr); + + GC.KeepAlive(dest); + GC.KeepAlive(src); } } } diff --git a/sdk/dotnet/webrtc/api/video/video_buffer.cs b/sdk/dotnet/webrtc/api/video/video_buffer.cs index 7d0b3fa3df..7da25f1b96 100644 --- a/sdk/dotnet/webrtc/api/video/video_buffer.cs +++ b/sdk/dotnet/webrtc/api/video/video_buffer.cs @@ -65,7 +65,14 @@ IntPtr buffer public static DisposableVideoFrame MoveFrame( this IVideoBufferInterface buffer) { + if (buffer == null) + { + throw new ArgumentNullException(nameof(buffer)); + } + + var frame = webrtcVideoBufferInterfaceMoveFrame(buffer.Ptr); + GC.KeepAlive(buffer); return frame == IntPtr.Zero ? null : new DisposableVideoFrame(frame); diff --git a/sdk/dotnet/webrtc/api/video/video_frame.cs b/sdk/dotnet/webrtc/api/video/video_frame.cs index 6d64bb287a..ccd9d55071 100644 --- a/sdk/dotnet/webrtc/api/video/video_frame.cs +++ b/sdk/dotnet/webrtc/api/video/video_frame.cs @@ -58,19 +58,41 @@ public static class ReadOnlyVideoFrameExtension private static extern int webrtcVideoFrameHeight(IntPtr ptr); public static int Width(this IReadOnlyVideoFrame frame) - { - return webrtcVideoFrameWidth(frame.Ptr); + { + if (frame == null) + { + throw new ArgumentNullException(nameof(frame)); + } + var width = webrtcVideoFrameWidth(frame.Ptr); + GC.KeepAlive(frame); + + return width; } public static int Height(this IReadOnlyVideoFrame frame) - { - return webrtcVideoFrameHeight(frame.Ptr); + { + if (frame == null) + { + throw new ArgumentNullException(nameof(frame)); + } + var height = webrtcVideoFrameHeight(frame.Ptr); + GC.KeepAlive(frame); + + return height; } public static uint Size(this IReadOnlyVideoFrame frame) - { - return (uint)webrtcVideoFrameWidth(frame.Ptr) * - (uint)webrtcVideoFrameHeight(frame.Ptr); + { + if (frame == null) + { + throw new ArgumentNullException(nameof(frame)); + } + + var width = (uint)webrtcVideoFrameWidth(frame.Ptr); + var height = (uint)webrtcVideoFrameHeight(frame.Ptr); + GC.KeepAlive(frame); + + return width * height; } } @@ -167,52 +189,100 @@ ushort id public static DisposableVideoFrame Build( this VideoFrame.IBuilder builder) - { - return new DisposableVideoFrame( - webrtcVideoFrameBuilderBuild(builder.Ptr)); + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + var frame = webrtcVideoFrameBuilderBuild(builder.Ptr); + GC.KeepAlive(builder); + + return new DisposableVideoFrame(frame); } public static void SetVideoFrameBuffer( this VideoFrame.IBuilder builder, IVideoFrameBuffer value) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + webrtcVideoFrameBuilder_set_video_frame_buffer( builder.Ptr, value.Ptr); + GC.KeepAlive(builder); + GC.KeepAlive(value); } public static void SetTimestampMs( this VideoFrame.IBuilder builder, long value) { - webrtcVideoFrameBuilder_set_timestamp_ms(builder.Ptr, value); + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + webrtcVideoFrameBuilder_set_timestamp_ms(builder.Ptr, value); + GC.KeepAlive(builder); } public static void SetTimstampRtp( this VideoFrame.IBuilder builder, uint value) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } webrtcVideoFrameBuilder_set_timestamp_rtp(builder.Ptr, value); + GC.KeepAlive(builder); } public static void SetNtpTimeMs( this VideoFrame.IBuilder builder, long value) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } webrtcVideoFrameBuilder_set_ntp_time_ms(builder.Ptr, value); + GC.KeepAlive(builder); } public static void SetRotation( this VideoFrame.IBuilder builder, VideoRotation value) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } webrtcVideoFrameBuilder_set_rotation(builder.Ptr, value); + GC.KeepAlive(builder); } public static void SetColorSpace( this VideoFrame.IBuilder builder, IntPtr value) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } webrtcVideoFrameBuilder_set_color_space(builder.Ptr, value); + GC.KeepAlive(builder); } public static void SetID( this VideoFrame.IBuilder builder, ushort value) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } webrtcVideoFrameBuilder_set_id(builder.Ptr, value); + GC.KeepAlive(builder); } } } diff --git a/sdk/dotnet/webrtc/common_video.cs b/sdk/dotnet/webrtc/common_video.cs index da71398bf5..59ee2726c2 100644 --- a/sdk/dotnet/webrtc/common_video.cs +++ b/sdk/dotnet/webrtc/common_video.cs @@ -58,11 +58,20 @@ public static bool ConvertFromI420( int dstSampleSize, IntPtr dstFrame) { - return webrtcConvertFromI420( + if (srcFrame == null) + { + throw new ArgumentNullException(nameof(srcFrame)); + } + + var result = webrtcConvertFromI420( srcFrame.Ptr, dstVideoType, dstSampleSize, - dstFrame) == 0; + dstFrame); + + GC.KeepAlive(srcFrame); + + return result == 0; } public static bool ConvertToI420( @@ -75,7 +84,12 @@ public static bool ConvertToI420( int cropX, int cropY) { - return webrtcConvertToI420( + if (dstFrame == null) + { + throw new ArgumentNullException(nameof(dstFrame)); + } + + var result = webrtcConvertToI420( srcVideoType, srcSampleSize, srcWidth, @@ -83,7 +97,11 @@ public static bool ConvertToI420( srcFrame, dstFrame.Ptr, cropX, - cropY) == 0; + cropY); + + GC.KeepAlive(dstFrame); + + return result == 0; } } } diff --git a/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs b/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs index 4bf77abf67..542c59ce81 100644 --- a/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs +++ b/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs @@ -152,7 +152,12 @@ private protected override void FreePtr() protected void OnFrame(IVideoFrame frame) { + if (frame == null) + { + throw new ArgumentNullException(nameof(frame)); + } rtcAdaptedVideoTrackSourceOnFrame(Ptr, frame.Ptr); + GC.KeepAlive(frame); } protected bool AdaptFrame( diff --git a/sdk/dotnet/webrtc/modules.cs b/sdk/dotnet/webrtc/modules.cs index 0c2b098567..033d333b06 100644 --- a/sdk/dotnet/webrtc/modules.cs +++ b/sdk/dotnet/webrtc/modules.cs @@ -80,6 +80,11 @@ IntPtr builder public static DisposableAudioProcessing Create( this IAudioProcessingBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return new DisposableAudioProcessing( webrtcAudioProcessingBuilderCreate(builder.Ptr) ); diff --git a/sdk/dotnet/webrtc/rtc_base.cs b/sdk/dotnet/webrtc/rtc_base.cs index 73ea8d26e0..b5fa3f808e 100644 --- a/sdk/dotnet/webrtc/rtc_base.cs +++ b/sdk/dotnet/webrtc/rtc_base.cs @@ -228,7 +228,13 @@ public static class MessageQueueExtension public static void Quit(this IMessageQueue queue) { + if (queue == null) + { + throw new ArgumentNullException(nameof(queue)); + } + rtcMessageQueueQuit(queue.Ptr); + GC.KeepAlive(queue); } } @@ -242,12 +248,19 @@ public static class ThreadExtension public static void Run(this IThread thread) { + if (thread == null) + { + throw new ArgumentNullException(nameof(thread)); + } + rtcThreadRun(thread.Ptr); + GC.KeepAlive(thread); } public static void Start(this IThread thread) { rtcThreadStart(thread.Ptr); + GC.KeepAlive(thread); } } @@ -265,12 +278,26 @@ IntPtr ptr public static void UnwrapCurrentThread(this IThreadManager manager) { + if (manager == null) + { + throw new ArgumentNullException(nameof(manager)); + } + rtcThreadManagerUnwrapCurrentThread(manager.Ptr); + GC.KeepAlive(manager); } public static Thread WrapCurrentThread(this IThreadManager manager) { - return new Thread(rtcThreadManagerWrapCurrentThread(manager.Ptr)); + if (manager == null) + { + throw new ArgumentNullException(nameof(manager)); + } + + var thread = rtcThreadManagerWrapCurrentThread(manager.Ptr); + GC.KeepAlive(manager); + + return new Thread(thread); } } } From 7f9cb99478a044393e670db6784990cb99a2da05 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Thu, 3 Sep 2020 11:13:44 +0800 Subject: [PATCH 77/85] fixes for msbuild --- sdk/dotnet/unity/unity.msbuildproj | 6 +++--- sdk/dotnet/webrtc/webrtc.csproj | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 3f7c932614..fcb9e65bd0 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - ;WinX64;WinX86; + WinX64;WinX86 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) @@ -39,12 +39,12 @@ - + Targets="Build" /> diff --git a/sdk/dotnet/webrtc/webrtc.csproj b/sdk/dotnet/webrtc/webrtc.csproj index a0f9b1e46b..7d07331761 100644 --- a/sdk/dotnet/webrtc/webrtc.csproj +++ b/sdk/dotnet/webrtc/webrtc.csproj @@ -15,8 +15,6 @@ WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs. 7.3 netstandard2.0 + false - - - From 437a40d23ef5abd53f476f1aff1f2f9db93acbe5 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 6 Sep 2020 08:03:48 +0800 Subject: [PATCH 78/85] various updates --- api/jsep.h | 2 +- sdk/c/api/data_channel_interface.cc | 14 +- sdk/c/api/jsep.cc | 99 +++++-- sdk/c/api/jsep.h | 40 ++- sdk/c/api/peer_connection_interface.cc | 63 ++-- sdk/c/api/peer_connection_interface.h | 24 +- sdk/c/api/rtp_sender_interface.cc | 31 ++ sdk/c/api/rtp_sender_interface.h | 22 +- sdk/dotnet/unity/unity.msbuildproj | 14 +- sdk/dotnet/webrtc/api/jsep.cs | 271 +++++++++--------- sdk/dotnet/webrtc/api/jsep_dc.cs | 142 +++++++++ .../webrtc/api/media_stream_interface.cs | 3 + .../webrtc/api/peer_connection_interface.cs | 113 ++++++-- sdk/dotnet/webrtc/api/rtp_sender_interface.cs | 168 ++++++++--- .../webrtc/api/rtp_transceiver_interface.cs | 2 +- 15 files changed, 741 insertions(+), 267 deletions(-) create mode 100644 sdk/dotnet/webrtc/api/jsep_dc.cs diff --git a/api/jsep.h b/api/jsep.h index 110c1c03a3..7a25a64513 100644 --- a/api/jsep.h +++ b/api/jsep.h @@ -110,7 +110,7 @@ enum class SdpType { // Description must be treated as an SDP final answer, and the offer- // answer exchange must be considered complete after receiving this. - kAnswer = WEBRTC_SDP_TYPE_ANSER + kAnswer = WEBRTC_SDP_TYPE_ANSWER }; // Returns the string form of the given SDP type. String forms are defined in diff --git a/sdk/c/api/data_channel_interface.cc b/sdk/c/api/data_channel_interface.cc index fb61d7836f..ff8c8ecea9 100644 --- a/sdk/c/api/data_channel_interface.cc +++ b/sdk/c/api/data_channel_interface.cc @@ -42,23 +42,23 @@ class DelegatingDataChannelObserver }; } -RTC_EXPORT extern "C" void webrtcDataChannelInterfaceRelease( +extern "C" void webrtcDataChannelInterfaceRelease( const WebrtcDataChannelInterface* channel) { rtc::ToCplusplus(channel)->Release(); } -RTC_EXPORT extern "C" RtcString* webrtcDataChannelLabel( +extern "C" RtcString* webrtcDataChannelLabel( const WebrtcDataChannelInterface* channel) { return rtc::ToC(new auto(rtc::ToCplusplus(channel)->label())); } -RTC_EXPORT extern "C" int webrtcDataChannelStatus( +extern "C" int webrtcDataChannelStatus( const WebrtcDataChannelInterface* channel) { auto chan = rtc::ToCplusplus(channel); return chan->state(); } -RTC_EXPORT extern "C" bool webrtcDataChannelSendText( +extern "C" bool webrtcDataChannelSendText( WebrtcDataChannelInterface* channel, const char* text ) { @@ -67,7 +67,7 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendText( return chan->Send(db); } -RTC_EXPORT extern "C" bool webrtcDataChannelSendData( +extern "C" bool webrtcDataChannelSendData( WebrtcDataChannelInterface* channel, const char* data, size_t len @@ -78,7 +78,7 @@ RTC_EXPORT extern "C" bool webrtcDataChannelSendData( return chan->Send(db); } -RTC_EXPORT extern "C" WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( +extern "C" WebrtcDataChannelObserver* webrtcDataChannelRegisterObserver( void* context, WebrtcDataChannelInterface* channel, const struct WebrtcDataChannelObserverFunctions* functions) { @@ -90,7 +90,7 @@ RTC_EXPORT extern "C" WebrtcDataChannelObserver* webrtcDataChannelRegisterObserv return o; } -RTC_EXPORT extern "C" void webrtcDataChannelUnregisterObserver( +extern "C" void webrtcDataChannelUnregisterObserver( WebrtcDataChannelInterface* channel ) { auto chan = rtc::ToCplusplus(channel); diff --git a/sdk/c/api/jsep.cc b/sdk/c/api/jsep.cc index 20857f8763..15588fcf59 100644 --- a/sdk/c/api/jsep.cc +++ b/sdk/c/api/jsep.cc @@ -67,6 +67,21 @@ class DelegatingSetSessionDescriptionObserver }; } +extern "C" WebrtcIceCandidateInterface* webrtcCreateIceCandidate( + const char* sdp_mid, + int sdp_mline_index, + const char* sdp, + WebrtcSdpParseError** cerror) { + webrtc::SdpParseError* error = nullptr; + if (cerror) { + error = new webrtc::SdpParseError(); + *cerror = rtc::ToC(error); + } + + return rtc::ToC( + webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, sdp, error)); +} + extern "C" WebrtcSessionDescriptionInterface* webrtcCreateSessionDescription( enum WebrtcSdpType ctype, const char* sdp, @@ -86,30 +101,36 @@ extern "C" void webrtcCreateSessionDescriptionObserverRelease( rtc::ToCplusplus(observer)->Release(); } +extern "C" void webrtcDeleteIceCandidateInterface( + WebrtcIceCandidateInterface* candidate) { + delete rtc::ToCplusplus(candidate); +} + extern "C" void webrtcDeleteSessionDescriptionInterface( WebrtcSessionDescriptionInterface* desc) { delete rtc::ToCplusplus(desc); } -extern "C" bool webrtcIceCandidateInterfaceResolve( - const WebrtcIceCandidateInterface* candidate, - RtcString** sdpMid, - int* sdpMLineIndex, - RtcString** sdp - ) { +extern "C" RtcString* webrtcIceCandidateInterfaceSdp_mid( + const WebrtcIceCandidateInterface* candidate) { + return rtc::ToC(new auto(rtc::ToCplusplus(candidate)->sdp_mid())); +} - auto c = rtc::ToCplusplus(candidate); - - auto i = c->sdp_mline_index(); - sdpMLineIndex = &i; +extern "C" int webrtcIceCandidateInterfaceSdp_mline_index( + const WebrtcIceCandidateInterface* candidate) { + return rtc::ToCplusplus(candidate)->sdp_mline_index(); +} + +extern "C" bool webrtcIceCandidateInterfaceToString( + const WebrtcIceCandidateInterface* candidate, + RtcString** out) { + if (!out) { + return false; + } - auto g = new std::string(); - *sdpMid = rtc::ToC(g); - g->assign(c->sdp_mid()); - auto s = new std::string(); - *sdp = rtc::ToC(s); - return c->ToString(s); + *out = rtc::ToC(s); + return rtc::ToCplusplus(candidate)->ToString(s); } extern "C" WebrtcCreateSessionDescriptionObserver* @@ -137,6 +158,24 @@ webrtcNewSetSessionDescriptionObserver( static_cast(observer)); } +extern "C" enum WebrtcOptionalSdpType webrtcSdpTypeFromString( + const char* type_str) { + auto optional = webrtc::SdpTypeFromString(type_str); + + return optional.has_value() ? + static_cast(optional.value()) : + WEBRTC_OPTIONAL_SDP_TYPE_NULLOPT; +} + +extern "C" const char* webrtcSdpTypeToString(enum WebrtcSdpType type) { + return webrtc::SdpTypeToString(static_cast(type)); +} + +extern "C" enum WebrtcSdpType webrtcSessionDescriptionInterfaceGetType( + const WebrtcSessionDescriptionInterface* desc) { + return static_cast(rtc::ToCplusplus(desc)->GetType()); +} + extern "C" bool webrtcSessionDescriptionInterfaceToString( const WebrtcSessionDescriptionInterface* desc, RtcString** out) { @@ -153,3 +192,31 @@ extern "C" void webrtcSetSessionDescriptionObserverRelease( const WebrtcSetSessionDescriptionObserver* observer) { rtc::ToCplusplus(observer)->Release(); } + + + + + + + + +extern "C" bool webrtcIceCandidateInterfaceResolve( + const WebrtcIceCandidateInterface* candidate, + 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(); + *sdp = rtc::ToC(s); + return c->ToString(s); +} diff --git a/sdk/c/api/jsep.h b/sdk/c/api/jsep.h index c89a07fafc..021428a68b 100644 --- a/sdk/c/api/jsep.h +++ b/sdk/c/api/jsep.h @@ -13,7 +13,14 @@ enum WebrtcSdpType { WEBRTC_SDP_TYPE_OFFER, WEBRTC_SDP_TYPE_PR_ANSWER, - WEBRTC_SDP_TYPE_ANSER + WEBRTC_SDP_TYPE_ANSWER +}; + +enum WebrtcOptionalSdpType { + WEBRTC_OPTIONAL_SDP_TYPE_OFFER = WEBRTC_SDP_TYPE_OFFER, + WEBRTC_OPTIONAL_SDP_TYPE_PR_ANSWER = WEBRTC_SDP_TYPE_PR_ANSWER, + WEBRTC_OPTIONAL_SDP_TYPE_ANSWER = WEBRTC_SDP_TYPE_ANSWER, + WEBRTC_OPTIONAL_SDP_TYPE_NULLOPT }; #ifdef __cplusplus @@ -49,6 +56,12 @@ struct WebrtcSetSessionDescriptionObserverFunctions { void (*on_failure)(void*, enum WebrtcRTCErrorType, const char*); }; +RTC_EXPORT WebrtcIceCandidateInterface* webrtcCreateIceCandidate( + const char* sdp_mid, + int sdp_mline_index, + const char* sdp, + WebrtcSdpParseError** error); + RTC_EXPORT WebrtcSessionDescriptionInterface* webrtcCreateSessionDescription( enum WebrtcSdpType type, const char* sdp, @@ -57,14 +70,21 @@ RTC_EXPORT WebrtcSessionDescriptionInterface* webrtcCreateSessionDescription( RTC_EXPORT void webrtcCreateSessionDescriptionObserverRelease( const WebrtcCreateSessionDescriptionObserver* observer); +RTC_EXPORT void webrtcDeleteIceCandidateInterface( + WebrtcIceCandidateInterface* candidate); + RTC_EXPORT void webrtcDeleteSessionDescriptionInterface( WebrtcSessionDescriptionInterface* desc); -RTC_EXPORT bool webrtcIceCandidateInterfaceResolve( +RTC_EXPORT RtcString* webrtcIceCandidateInterfaceSdp_mid( + const WebrtcIceCandidateInterface* candidate); + +RTC_EXPORT int webrtcIceCandidateInterfaceSdp_mline_index( + const WebrtcIceCandidateInterface* candidate); + +RTC_EXPORT bool webrtcIceCandidateInterfaceToString( const WebrtcIceCandidateInterface* candidate, - RtcString** sdpMid, - int* sdpMLineIndex, - RtcString** sdp); + RtcString** out); RTC_EXPORT WebrtcCreateSessionDescriptionObserver* webrtcNewCreateSessionDescriptionObserver( @@ -76,6 +96,14 @@ webrtcNewSetSessionDescriptionObserver( void* context, const struct WebrtcSetSessionDescriptionObserverFunctions* functions); +RTC_EXPORT enum WebrtcOptionalSdpType +webrtcSdpTypeFromString(const char* type_str); + +RTC_EXPORT const char* webrtcSdpTypeToString(enum WebrtcSdpType type); + +RTC_EXPORT enum WebrtcSdpType webrtcSessionDescriptionInterfaceGetType( + const WebrtcSessionDescriptionInterface* desc); + RTC_EXPORT bool webrtcSessionDescriptionInterfaceToString( const WebrtcSessionDescriptionInterface* desc, RtcString** out); @@ -87,4 +115,4 @@ RTC_EXPORT void webrtcSetSessionDescriptionObserverRelease( } #endif -#endif +#endif \ No newline at end of file diff --git a/sdk/c/api/peer_connection_interface.cc b/sdk/c/api/peer_connection_interface.cc index 533b066c2e..1ad749348f 100644 --- a/sdk/c/api/peer_connection_interface.cc +++ b/sdk/c/api/peer_connection_interface.cc @@ -4,7 +4,7 @@ * 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 #include "api/peer_connection_interface.h" #include "sdk/c/api/peer_connection_interface.h" @@ -145,12 +145,12 @@ class DelegatingPeerConnectionObserver : public PeerConnectionObserver { } -RTC_EXPORT extern "C" void webrtcDeletePeerConnectionObserver( +extern "C" void webrtcDeletePeerConnectionObserver( WebrtcPeerConnectionObserver* observer) { delete rtc::ToCplusplus(observer); } -RTC_EXPORT extern "C" WebrtcPeerConnectionObserver* +extern "C" WebrtcPeerConnectionObserver* webrtcNewPeerConnectionObserver( void* context, const struct WebrtcPeerConnectionObserverFunctions* functions) { @@ -158,7 +158,7 @@ webrtcNewPeerConnectionObserver( new webrtc::DelegatingPeerConnectionObserver(context, functions))); } -RTC_EXPORT extern "C" WebrtcPeerConnectionInterface* +extern "C" WebrtcPeerConnectionInterface* webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( WebrtcPeerConnectionFactoryInterface* factory, const struct WebrtcPeerConnectionInterfaceRTCConfiguration* cconfiguration, @@ -183,7 +183,12 @@ webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( configuration.set_experiment_cpu_load_estimator( cconfiguration->flags & - WEBRTC_RTC_CONFIGURaTION_FLAG_EXPERIMENT_CPU_LOAD_ESTIMATOR); + WEBRTC_RTC_CONFIGURATION_FLAG_EXPERIMENT_CPU_LOAD_ESTIMATOR); + + if (cconfiguration->flags & WEBRTC_RTC_CONFIGURATION_FLAG_OVERRIDE_ENABLE_DTLS_SRTP) { + auto flag = cconfiguration->flags & WEBRTC_RTC_CONFIGURATION_FLAG_ENABLE_DTLS_SRTP; + configuration.enable_dtls_srtp = flag != 0; + } configuration.set_audio_rtcp_report_interval_ms( cconfiguration->audio_rtcp_report_interval_ms); @@ -274,7 +279,7 @@ webrtcPeerConnectionFactoryInterfaceCreatePeerConnection( return rtc::ToC(connection.release()); } -RTC_EXPORT extern "C" WebrtcAudioTrackInterface* +extern "C" WebrtcAudioTrackInterface* webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( WebrtcPeerConnectionFactoryInterface* factory, const char* label, @@ -284,7 +289,7 @@ webrtcPeerConnectionFactoryInterfaceCreateAudioTrack( .release()); } -RTC_EXPORT extern "C" WebrtcVideoTrackInterface* +extern "C" WebrtcVideoTrackInterface* webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( WebrtcPeerConnectionFactoryInterface* factory, const char* label, @@ -294,12 +299,12 @@ webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( .release()); } -RTC_EXPORT extern "C" void webrtcPeerConnectionFactoryInterfaceRelease( +extern "C" void webrtcPeerConnectionFactoryInterfaceRelease( const WebrtcPeerConnectionFactoryInterface* factory) { rtc::ToCplusplus(factory)->Release(); } -RTC_EXPORT extern "C" WebrtcPeerConnectionInterfaceAddTrackResult +extern "C" WebrtcPeerConnectionInterfaceAddTrackResult webrtcPeerConnectionInterfaceAddTrack(WebrtcPeerConnectionInterface* connection, WebrtcMediaStreamTrackInterface* track, const char* const* data, @@ -324,24 +329,19 @@ webrtcPeerConnectionInterfaceAddTrack(WebrtcPeerConnectionInterface* connection, return cresult; } -RTC_EXPORT extern "C" bool -webrtcPeerConnectionInterfaceAddICECandidate(WebrtcPeerConnectionInterface* connection, - const char* sdpMid, - size_t sdpMLineIndex, - const char* sdp) { - webrtc::SdpParseError error; - webrtc::IceCandidateInterface * candidate = webrtc::CreateIceCandidate(sdpMid, sdpMLineIndex, sdp, &error); - - return rtc::ToCplusplus(connection) - ->AddIceCandidate(candidate); +extern "C" bool webrtcPeerConnectionInterfaceAddIceCandidate( + WebrtcPeerConnectionInterface* connection, + const WebrtcIceCandidateInterface* candidate) { + return rtc::ToCplusplus(connection)->AddIceCandidate( + rtc::ToCplusplus(candidate)); } -RTC_EXPORT extern "C" void webrtcPeerConnectionInterfaceClose( +extern "C" void webrtcPeerConnectionInterfaceClose( WebrtcPeerConnectionInterface* connection) { rtc::ToCplusplus(connection)->Close(); } -RTC_EXPORT extern "C" void webrtcPeerConnectionInterfaceCreateAnswer( +extern "C" void webrtcPeerConnectionInterfaceCreateAnswer( WebrtcPeerConnectionInterface* connection, WebrtcCreateSessionDescriptionObserver* observer, const struct WebrtcPeerConnectionInterfaceRTCOfferAnswerOptions* options) { @@ -357,6 +357,11 @@ extern "C" void webrtcPeerConnectionInterfaceCreateOffer( ->CreateOffer(rtc::ToCplusplus(observer), *options); } +extern "C" WebrtcRtpSenderInterfaces* webrtcPeerConnectionInterfaceGetSenders( + const WebrtcPeerConnectionInterface* connection) { + return rtc::ToC(new auto(rtc::ToCplusplus(connection)->GetSenders())); +} + extern "C" void webrtcPeerConnectionInterfaceRelease( const WebrtcPeerConnectionInterface* connection) { rtc::ToCplusplus(connection)->Release(); @@ -384,3 +389,19 @@ extern "C" void webrtcPeerConnectionInterfaceSetRemoteDescription( ->SetRemoteDescription(rtc::ToCplusplus(observer), rtc::ToCplusplus(desc)); } + +extern "C" void webrtcRtpSenderInterfacesMove( + WebrtcRtpSenderInterfaces* ccplusplus, + WebrtcRtpSenderInterface** c) { + auto cplusplusRaw = rtc::ToCplusplus(ccplusplus); + auto cplusplus = std::unique_ptr>>(cplusplusRaw); + + for (size_t index = 0; index < cplusplus->size(); index++) { + c[index] = rtc::ToC((*cplusplus)[index].release()); + } +} + +extern "C" size_t webrtcRtpSenderInterfacesSize( + const WebrtcRtpSenderInterfaces* interfaces) { + return rtc::ToCplusplus(interfaces)->size(); +} diff --git a/sdk/c/api/peer_connection_interface.h b/sdk/c/api/peer_connection_interface.h index 8cee9d5af3..7ec66cbb96 100644 --- a/sdk/c/api/peer_connection_interface.h +++ b/sdk/c/api/peer_connection_interface.h @@ -33,7 +33,9 @@ enum { WEBRTC_RTC_CONFIGURATION_FLAG_CPU_ADAPTATION = 1 << 2, WEBRTC_RTC_CONFIGURATION_FLAG_SUSPEND_BELOW_MIN_BITRATE = 1 << 3, WEBRTC_RTC_CONFIGURATION_FLAG_PRERENDERER_SMOOTHING = 1 << 4, - WEBRTC_RTC_CONFIGURaTION_FLAG_EXPERIMENT_CPU_LOAD_ESTIMATOR = 1 << 5, + WEBRTC_RTC_CONFIGURATION_FLAG_EXPERIMENT_CPU_LOAD_ESTIMATOR = 1 << 5, + WEBRTC_RTC_CONFIGURATION_FLAG_OVERRIDE_ENABLE_DTLS_SRTP = 1 << 6, + WEBRTC_RTC_CONFIGURATION_FLAG_ENABLE_DTLS_SRTP = 1 << 7, }; enum WebrtcSdpSemantics { @@ -169,6 +171,9 @@ struct WebrtcPeerConnectionInterfaceRTCOfferAnswerOptions { extern "C" { #endif +RTC_C_CLASS(std::vector>, + WebrtcRtpSenderInterfaces) + RTC_C_CLASS(webrtc::PeerConnectionObserver, WebrtcPeerConnectionObserver) RTC_C_CLASS(webrtc::PeerConnectionInterface, WebrtcPeerConnectionInterface) @@ -269,6 +274,9 @@ struct WebrtcPeerConnectionObserverFunctions { RTC_EXPORT void webrtcDeletePeerConnectionObserver( WebrtcPeerConnectionObserver* observer); + +RTC_EXPORT void webrtcDeleteRtpSenderInterfaces( + WebrtcRtpSenderInterfaces* interfaces); RTC_EXPORT WebrtcPeerConnectionObserver* webrtcNewPeerConnectionObserver( void* context, @@ -294,6 +302,10 @@ webrtcPeerConnectionFactoryInterfaceCreateVideoTrack( RTC_EXPORT void webrtcPeerConnectionFactoryInterfaceRelease( const WebrtcPeerConnectionFactoryInterface* factory); + +RTC_EXPORT bool webrtcPeerConnectionInterfaceAddIceCandidate( + WebrtcPeerConnectionInterface* connection, + const WebrtcIceCandidateInterface* candidate); RTC_EXPORT struct WebrtcPeerConnectionInterfaceAddTrackResult webrtcPeerConnectionInterfaceAddTrack(WebrtcPeerConnectionInterface* connection, @@ -313,6 +325,9 @@ RTC_EXPORT void webrtcPeerConnectionInterfaceCreateOffer( WebrtcPeerConnectionInterface* connection, WebrtcCreateSessionDescriptionObserver* observer, const struct WebrtcPeerConnectionInterfaceRTCOfferAnswerOptions* options); + +RTC_EXPORT WebrtcRtpSenderInterfaces* webrtcPeerConnectionInterfaceGetSenders( + const WebrtcPeerConnectionInterface* connection); RTC_EXPORT void webrtcPeerConnectionInterfaceRelease( const WebrtcPeerConnectionInterface* connection); @@ -331,6 +346,13 @@ RTC_EXPORT void webrtcPeerConnectionInterfaceSetRemoteDescription( WebrtcSetSessionDescriptionObserver* observer, WebrtcSessionDescriptionInterface* desc); +RTC_EXPORT void webrtcRtpSenderInterfacesMove( + WebrtcRtpSenderInterfaces* cplusplus, + WebrtcRtpSenderInterface** c); + +RTC_EXPORT size_t webrtcRtpSenderInterfacesSize( + const WebrtcRtpSenderInterfaces* interfaces); + #ifdef __cplusplus } #endif diff --git a/sdk/c/api/rtp_sender_interface.cc b/sdk/c/api/rtp_sender_interface.cc index 57904aa515..dc0500c77c 100644 --- a/sdk/c/api/rtp_sender_interface.cc +++ b/sdk/c/api/rtp_sender_interface.cc @@ -7,7 +7,38 @@ #include "sdk/c/api/rtp_sender_interface.h" +extern "C" void webrtcDeleteRtpSenderInterfaceStreamIds( + WebrtcRtpSenderInterfaceStreamIds* ids) { + delete rtc::ToCplusplus(ids); +} + extern "C" void webrtcRtpSenderInterfaceRelease( const WebrtcRtpSenderInterface* sender) { rtc::ToCplusplus(sender)->Release(); } + +extern "C" WebrtcRtpSenderInterfaceStreamIds* webrtcRtpSenderInterfaceStream_ids( + const WebrtcRtpSenderInterface* sender) { + return rtc::ToC(new auto(rtc::ToCplusplus(sender)->stream_ids())); +} + +extern "C" WebrtcMediaStreamTrackInterface* webrtcRtpSenderInterfaceTrack( + const WebrtcRtpSenderInterface* sender) { + return rtc::ToC(rtc::ToCplusplus(sender)->track()); +} + +extern "C" void webrtcRtpSenderInterfaceStreamIdsData( + WebrtcRtpSenderInterfaceStreamIds* ids, + const char** data) { + auto cplusplusRaw = rtc::ToCplusplus(ids); + auto cplusplus = std::unique_ptr>(cplusplusRaw); + + for (size_t index = 0; index < cplusplus->size(); index++) { + data[index] = (*cplusplus)[index].c_str(); + } +} + +extern "C" size_t webrtcRtpSenderInterfaceStreamIdsSize( + const WebrtcRtpSenderInterfaceStreamIds* ids) { + return rtc::ToCplusplus(ids)->size(); +} \ No newline at end of file diff --git a/sdk/c/api/rtp_sender_interface.h b/sdk/c/api/rtp_sender_interface.h index 639a142a66..c2f5abe5a7 100644 --- a/sdk/c/api/rtp_sender_interface.h +++ b/sdk/c/api/rtp_sender_interface.h @@ -9,20 +9,40 @@ #define SDK_C_API_RTP_SENDER_INTERFACE_H_ #include "sdk/c/interop.h" +#include "sdk/c/api/media_stream_interface.h" #ifdef __cplusplus #include "api/rtp_sender_interface.h" extern "C" { +#else +#include #endif +RTC_C_CLASS(std::vector, WebrtcRtpSenderInterfaceStreamIds) RTC_C_CLASS(webrtc::RtpSenderInterface, WebrtcRtpSenderInterface) +RTC_EXPORT void webrtcDeleteRtpSenderInterfaceStreamIds( + WebrtcRtpSenderInterfaceStreamIds* ids); + RTC_EXPORT void webrtcRtpSenderInterfaceRelease( const WebrtcRtpSenderInterface* sender); +RTC_EXPORT WebrtcRtpSenderInterfaceStreamIds* webrtcRtpSenderInterfaceStream_ids( + const WebrtcRtpSenderInterface* sender); + +RTC_EXPORT WebrtcMediaStreamTrackInterface* webrtcRtpSenderInterfaceTrack( + const WebrtcRtpSenderInterface* sender); + +RTC_EXPORT void webrtcRtpSenderInterfaceStreamIdsData( + WebrtcRtpSenderInterfaceStreamIds* ids, + const char** data); + +RTC_EXPORT size_t webrtcRtpSenderInterfaceStreamIdsSize( + const WebrtcRtpSenderInterfaceStreamIds* ids); + #ifdef __cplusplus } #endif -#endif +#endif \ No newline at end of file diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index fcb9e65bd0..0dd8f615f0 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -9,7 +9,7 @@ bin/ - Release + Debug $(BaseOutputPath)$(Configuration)/ @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - WinX64;WinX86 + WinX64 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) @@ -29,7 +29,7 @@ "$(Targets.Replace('\', '\\').Replace('"', '\"'))" - + @@ -67,14 +67,14 @@ @@ -82,14 +82,14 @@ diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index bf03408d5f..f2e6dc7b13 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -23,44 +23,11 @@ public interface ICreateSessionDescriptionObserver IntPtr Ptr { get; } } - public interface IRTCDataBufferInterface - { - IntPtr Ptr { get; } - } - - public sealed class RTCDataBufferInterface : IRTCDataBufferInterface - { - public IntPtr Ptr { get; } - - public RTCDataBufferInterface(IntPtr ptr) - { - Ptr = ptr; - } - } - - public interface IManagedDataChannelObserver - { - DisposableDataChannelInterface DataChannel { get; } - void OnStateChange(); - void OnMessage(bool binary, IntPtr data, int data_size); - void OnBufferedAmountChange(UInt64 sent_data_size); - } - public interface IDisposableCreateSessionDescriptionObserver : ICreateSessionDescriptionObserver, Rtc.IDisposable { } - public interface IDataChannelObserver - { - IntPtr Ptr { get; } - } - - public interface IDisposableDataChannelObserver : - IDataChannelObserver, Rtc.IDisposable - { - } - public interface IDisposableIceCandidateInterface : IIceCandidateInterface, Rtc.IDisposable { @@ -103,85 +70,6 @@ public interface ISetSessionDescriptionObserver IntPtr Ptr { get; } } - public sealed class DisposableDataChannelObserver: DisposablePtr, IDisposableDataChannelObserver - { - IntPtr IDataChannelObserver.Ptr => Ptr; - - - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void DestructionHandler(IntPtr context); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void OnBufferedAmountChangeHandler(IntPtr context, ulong sent_data_size); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void OnMessageHandler(IntPtr context, bool binary, IntPtr data, int data_size); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void OnStateChangeHandler(IntPtr context); - - private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( - (DestructionHandler)OnDestruction, - (OnStateChangeHandler)OnStateChange, - (OnMessageHandler)OnMessage, - (OnBufferedAmountChangeHandler)OnBufferedAmountChange - ); - - [MonoPInvokeCallback(typeof(OnStateChangeHandler))] - private static void OnStateChange(IntPtr context) - { - var handle = (GCHandle)context; - - ((IManagedDataChannelObserver)handle.Target).OnStateChange(); - } - - [MonoPInvokeCallback(typeof(OnMessageHandler))] - private static void OnMessage(IntPtr context, bool binary, IntPtr data, int data_size) - { - var handle = (GCHandle)context; - - ((IManagedDataChannelObserver)handle.Target).OnMessage(binary, data, data_size); - } - - [MonoPInvokeCallback(typeof(OnBufferedAmountChangeHandler))] - private static void OnBufferedAmountChange(IntPtr context, ulong sent_data_size) - { - var handle = (GCHandle)context; - - ((IManagedDataChannelObserver)handle.Target).OnBufferedAmountChange(sent_data_size); - } - - private protected override void FreePtr() - { - Interop.DataChannel.UnregisterObserver(DataChannel.GetPtr); - DataChannel.Dispose(); - } - - [MonoPInvokeCallback(typeof(DestructionHandler))] - private static void OnDestruction(IntPtr context) - { - ((GCHandle)context).Free(); - } - - public DisposableDataChannelObserver( - IManagedDataChannelObserver implementation) - { - DataChannel = implementation.DataChannel; - Ptr = Interop.DataChannel.RegisterObserver( - (IntPtr)GCHandle.Alloc(implementation), - implementation.DataChannel.GetPtr, - s_functions.Ptr - ); - } - - public DisposableDataChannelInterface DataChannel - { - get; private set; - } - - } - public sealed class DisposableCreateSessionDescriptionObserver : DisposablePtr, IDisposableCreateSessionDescriptionObserver { @@ -194,7 +82,7 @@ public sealed class DisposableCreateSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context, IntPtr desc); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); + private delegate void FailureHandler(IntPtr context, RtcError error); private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -225,12 +113,12 @@ private static void OnSuccess(IntPtr context, IntPtr desc) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) + private static void OnFailure(IntPtr context, RtcError error) { var handle = (GCHandle)context; ((IManagedCreateSessionDescriptionObserver)handle.Target).OnFailure( - new RtcError(type, Marshal.PtrToStringAnsi(message)) + error ); } @@ -254,6 +142,22 @@ private protected override void FreePtr() } } + public sealed class DisposableIceCandidateInterface : + DisposablePtr, IDisposableIceCandidateInterface + { + IntPtr IIceCandidateInterface.Ptr => Ptr; + + public DisposableIceCandidateInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.IceCandidateInterface.Delete(Ptr); + } + } + public sealed class DisposableSessionDescriptionInterface : DisposablePtr, IDisposableSessionDescriptionInterface { @@ -280,7 +184,7 @@ public sealed class DisposableSetSessionDescriptionObserver : private delegate void SuccessHandler(IntPtr context); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void FailureHandler(IntPtr context, RtcErrorType type, IntPtr message); + private delegate void FailureHandler(IntPtr context, RtcError error); private static FunctionPtrArray s_functions = new FunctionPtrArray( (DestructionHandler)OnDestruction, @@ -308,12 +212,12 @@ private static void OnSuccess(IntPtr context) } [MonoPInvokeCallback(typeof(FailureHandler))] - private static void OnFailure(IntPtr context, RtcErrorType type, IntPtr message) + private static void OnFailure(IntPtr context, RtcError error) { var handle = (GCHandle)context; ((IManagedSetSessionDescriptionObserver)handle.Target).OnFailure( - new RtcError(type, Marshal.PtrToStringAnsi(message)) + error ); } @@ -349,34 +253,108 @@ public IceCandidateInterface(IntPtr ptr) } } + public static class IceCandidate + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcCreateIceCandidate( + string sdpMid, + int sdpMlineIndex, + string sdp, + IntPtr error + ); + + public static DisposableIceCandidateInterface Create( + string sdpMid, + int sdpMlineIndex, + string sdp, + IntPtr error) + { + var ptr = webrtcCreateIceCandidate( + sdpMid, sdpMlineIndex, sdp, error); + + return ptr == IntPtr.Zero ? + null : new DisposableIceCandidateInterface(ptr); + } + } + public static class IceCandidateInterfaceExtension { [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern bool webrtcIceCandidateInterfaceResolve( + private static extern bool webrtcIceCandidateInterfaceToString( IntPtr ptr, - out IntPtr sdpMid, - out int sdpMLineIndex, - out IntPtr sdp + out IntPtr result ); - public static bool Resolve( - this IIceCandidateInterface candidate, out string sdpMid, out int sdpMLineIndex, out string sdp) + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcIceCandidateInterfaceSdp_mid( + IntPtr ptr + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern int webrtcIceCandidateInterfaceSdp_mline_index( + IntPtr ptr + ); + + public static string SdpMid(this IIceCandidateInterface candidate) { if (candidate == null) { throw new ArgumentNullException(nameof(candidate)); } - var result = webrtcIceCandidateInterfaceResolve( - candidate.Ptr, out var _sdpMid, out sdpMLineIndex, out var _sdp); + var ptr = webrtcIceCandidateInterfaceSdp_mid(candidate.Ptr); + GC.KeepAlive(candidate); + return Rtc.Interop.String.MoveToString(ptr); + } + + public static int SdpMlineIndex(this IIceCandidateInterface candidate) + { + if (candidate == null) + { + throw new ArgumentNullException(nameof(candidate)); + } - sdpMid = Rtc.Interop.String.MoveToString(_sdpMid); - sdp = Rtc.Interop.String.MoveToString(_sdp); + return webrtcIceCandidateInterfaceSdp_mline_index(candidate.Ptr); + } + + public static bool TryToString( + this IIceCandidateInterface candidate, out string s) + { + if (candidate == null) + { + throw new ArgumentNullException(nameof(candidate)); + } + + var result = webrtcIceCandidateInterfaceToString( + candidate.Ptr, out var webrtcString); + + GC.KeepAlive(candidate); + s = Rtc.Interop.String.MoveToString(webrtcString); return result; } } + public static class SdpTypeExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern int webrtcSdpTypeFromString(string typeStr); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcSdpTypeToString(SdpType type); + + public static SdpType? FromString(string typeStr) + { + var type = webrtcSdpTypeFromString(typeStr); + return type == 3 ? default(SdpType?) : (SdpType)type; + } + + public static string ToSdpString(this SdpType type) + { + return Marshal.PtrToStringAnsi(webrtcSdpTypeToString(type)); + } + } + public static class SessionDescription { [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] @@ -400,6 +378,11 @@ public static DisposableSessionDescriptionInterface Create( public static class SessionDescriptionInterfaceExtension { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern SdpType webrtcSessionDescriptionInterfaceGetType( + IntPtr ptr + ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] private static extern bool webrtcSessionDescriptionInterfaceToString( @@ -407,6 +390,19 @@ private static extern bool webrtcSessionDescriptionInterfaceToString( out IntPtr result ); + public static SdpType GetSdpType(this ISessionDescriptionInterface desc) + { + if (desc == null) + { + throw new ArgumentNullException(nameof(desc)); + } + + var result = webrtcSessionDescriptionInterfaceGetType(desc.Ptr); + GC.KeepAlive(desc); + + return result; + } + public static bool TryToString( this ISessionDescriptionInterface desc, out string s) @@ -415,8 +411,10 @@ public static bool TryToString( { throw new ArgumentNullException(nameof(desc)); } + var result = webrtcSessionDescriptionInterfaceToString( desc.Ptr, out var webrtcString); + GC.KeepAlive(desc); s = Rtc.Interop.String.MoveToString(webrtcString); @@ -433,19 +431,10 @@ public static class CreateSessionDescriptionObserver public static extern void Release(IntPtr ptr); } - public static class DataChannel + public static class IceCandidateInterface { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelRegisterObserver")] - public static extern IntPtr RegisterObserver( - IntPtr context, - IntPtr dataChannel, - IntPtr functions - ); - - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelUnregisterObserver")] - public static extern void UnregisterObserver( - IntPtr context - ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeleteIceCandidateInterface")] + public static extern void Delete(IntPtr ptr); } public static class SessionDescriptionInterface @@ -459,4 +448,4 @@ public static class SetSessionDescriptionObserver [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcSetSessionDescriptionObserverRelease")] public static extern void Release(IntPtr ptr); } -} +} \ No newline at end of file diff --git a/sdk/dotnet/webrtc/api/jsep_dc.cs b/sdk/dotnet/webrtc/api/jsep_dc.cs new file mode 100644 index 0000000000..9c038a06fb --- /dev/null +++ b/sdk/dotnet/webrtc/api/jsep_dc.cs @@ -0,0 +1,142 @@ +/* + * Copyright 2019 pixiv Inc. 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. + */ + +using Pixiv.Rtc; +using System; +using System.Runtime.InteropServices; + +namespace Pixiv.Webrtc +{ + public interface IRTCDataBufferInterface + { + IntPtr Ptr { get; } + } + + public sealed class RTCDataBufferInterface : IRTCDataBufferInterface + { + public IntPtr Ptr { get; } + + public RTCDataBufferInterface(IntPtr ptr) + { + Ptr = ptr; + } + } + + public interface IManagedDataChannelObserver + { + DisposableDataChannelInterface DataChannel { get; } + void OnStateChange(); + void OnMessage(bool binary, IntPtr data, int data_size); + void OnBufferedAmountChange(UInt64 sent_data_size); + } + + public interface IDataChannelObserver + { + IntPtr Ptr { get; } + } + + public interface IDisposableDataChannelObserver : + IDataChannelObserver, Rtc.IDisposable + { + } + + public sealed class DisposableDataChannelObserver : DisposablePtr, IDisposableDataChannelObserver + { + IntPtr IDataChannelObserver.Ptr => Ptr; + + + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void DestructionHandler(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void OnBufferedAmountChangeHandler(IntPtr context, ulong sent_data_size); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void OnMessageHandler(IntPtr context, bool binary, IntPtr data, int data_size); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void OnStateChangeHandler(IntPtr context); + + private static readonly FunctionPtrArray s_functions = new FunctionPtrArray( + (DestructionHandler)OnDestruction, + (OnStateChangeHandler)OnStateChange, + (OnMessageHandler)OnMessage, + (OnBufferedAmountChangeHandler)OnBufferedAmountChange + ); + + [MonoPInvokeCallback(typeof(OnStateChangeHandler))] + private static void OnStateChange(IntPtr context) + { + var handle = (GCHandle)context; + + ((IManagedDataChannelObserver)handle.Target).OnStateChange(); + } + + [MonoPInvokeCallback(typeof(OnMessageHandler))] + private static void OnMessage(IntPtr context, bool binary, IntPtr data, int data_size) + { + var handle = (GCHandle)context; + + ((IManagedDataChannelObserver)handle.Target).OnMessage(binary, data, data_size); + } + + [MonoPInvokeCallback(typeof(OnBufferedAmountChangeHandler))] + private static void OnBufferedAmountChange(IntPtr context, ulong sent_data_size) + { + var handle = (GCHandle)context; + + ((IManagedDataChannelObserver)handle.Target).OnBufferedAmountChange(sent_data_size); + } + + private protected override void FreePtr() + { + Interop.DataChannel.UnregisterObserver(DataChannel.GetPtr); + DataChannel.Dispose(); + } + + [MonoPInvokeCallback(typeof(DestructionHandler))] + private static void OnDestruction(IntPtr context) + { + ((GCHandle)context).Free(); + } + + public DisposableDataChannelObserver( + IManagedDataChannelObserver implementation) + { + DataChannel = implementation.DataChannel; + Ptr = Interop.DataChannel.RegisterObserver( + (IntPtr)GCHandle.Alloc(implementation), + implementation.DataChannel.GetPtr, + s_functions.Ptr + ); + } + + public DisposableDataChannelInterface DataChannel + { + get; private set; + } + + } +} +namespace Pixiv.Webrtc.Interop +{ + public static class DataChannel + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelRegisterObserver")] + public static extern IntPtr RegisterObserver( + IntPtr context, + IntPtr dataChannel, + IntPtr functions + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDataChannelUnregisterObserver")] + public static extern void UnregisterObserver( + IntPtr context + ); + } +} diff --git a/sdk/dotnet/webrtc/api/media_stream_interface.cs b/sdk/dotnet/webrtc/api/media_stream_interface.cs index 9d4c0c211b..43319c0f23 100644 --- a/sdk/dotnet/webrtc/api/media_stream_interface.cs +++ b/sdk/dotnet/webrtc/api/media_stream_interface.cs @@ -357,6 +357,7 @@ public static void OnData( { throw new ArgumentNullException(nameof(sink)); } + try { castedNumberOfChannels = (UIntPtr)numberOfChannels; @@ -374,6 +375,7 @@ public static void OnData( { throw new ArgumentOutOfRangeException(nameof(castedNumberOfFrames), inner); } + webrtcAudioTrackSinkInterfaceOnData( sink.Ptr, audioData, @@ -439,6 +441,7 @@ public static string ID(this IMediaStreamTrackInterface track) { throw new ArgumentNullException(nameof(track)); } + var id = webrtcMediaStreamTrackInterfaceId(track.Ptr); GC.KeepAlive(track); diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index 8c906d2c4e..d0ae8c0b91 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -403,7 +403,7 @@ public DisposablePeerConnectionObserver( s_functions.Ptr ); } - catch(Exception ex) + catch (Exception ex) { var m = ex.Message; } @@ -442,7 +442,9 @@ private enum WebrtcRTCConfigurationFlags CpuAdaptation = 1 << 2, SuspendBelowMinBitrate = 1 << 3, PrerendererSmoothing = 1 << 4, - ExperimentCpuLoadEstimator = 1 << 5 + ExperimentCpuLoadEstimator = 1 << 5, + OverrideEnableDtlsSrtp = 1 << 6, + EnableDtlsSrtp = 1 << 7, } private struct WebrtcIceServer @@ -597,6 +599,16 @@ public static DisposablePeerConnectionInterface CreatePeerConnection( unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.ExperimentCpuLoadEstimator; } + if (configuration.EnableDtlsSrtp.HasValue) + { + unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.OverrideEnableDtlsSrtp; + + if (configuration.EnableDtlsSrtp.Value) + { + unmanagedConfiguration.Flags |= WebrtcRTCConfigurationFlags.EnableDtlsSrtp; + } + } + unmanagedConfiguration.AudioRtcpReportIntervalMs = configuration.AudioRtcpReportIntervalMs; unmanagedConfiguration.VideoRtcpReportIntervalMs = configuration.VideoRtcpReportIntervalMs; unmanagedConfiguration.ServersSize = new UIntPtr((uint)configuration.Servers.Length); @@ -908,6 +920,7 @@ public sealed class RtcConfiguration new IRtcCertificate[0]; public int IceCandidatePoolSize { get; set; } = 0; public SdpSemantics SdpSemantics; + public bool? EnableDtlsSrtp { get; set; } } [StructLayout(LayoutKind.Sequential)] @@ -950,19 +963,21 @@ private readonly struct WebrtcAddTrackResult } [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern WebrtcAddTrackResult webrtcPeerConnectionInterfaceAddTrack( + private static extern void webrtcDeleteRtpSenderInterfaces( + IntPtr interfaces); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern bool webrtcPeerConnectionInterfaceAddIceCandidate( IntPtr connection, - IntPtr track, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] string[] data, - UIntPtr size + IntPtr candidate ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] - private static extern bool webrtcPeerConnectionInterfaceAddICECandidate( + private static extern WebrtcAddTrackResult webrtcPeerConnectionInterfaceAddTrack( IntPtr connection, - [MarshalAs(UnmanagedType.LPStr)] string sdpMid, - int sdpMLineIndex, - [MarshalAs(UnmanagedType.LPStr)] string sdp + IntPtr track, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] string[] data, + UIntPtr size ); [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] @@ -984,12 +999,28 @@ private static extern void webrtcPeerConnectionInterfaceClose( IntPtr connection ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcPeerConnectionInterfaceGetSenders( + IntPtr connection + ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern void webrtcPeerConnectionInterfaceSetAudioRecording( IntPtr connection, [MarshalAs(UnmanagedType.I1)] bool recording ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcRtpSenderInterfacesMove( + IntPtr cplusplus, + IntPtr c + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern UIntPtr webrtcRtpSenderInterfacesSize( + IntPtr interfaces + ); + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] private static extern void webrtcPeerConnectionInterfaceSetLocalDescription( IntPtr connection, @@ -1047,18 +1078,29 @@ public static RtcErrorOr AddTrack( return new RtcErrorOr(error, value); } - public static bool AddICECandidate(this IPeerConnectionInterface connection, - string sdpMid, - int sdpMlineIndex, - string sdp) + public static bool AddIceCandidate( + this IPeerConnectionInterface connection, + IIceCandidateInterface candidate) { - var result = webrtcPeerConnectionInterfaceAddICECandidate( - connection.Ptr, sdpMid, sdpMlineIndex, sdp); + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + + if (candidate == null) + { + throw new ArgumentNullException(nameof(candidate)); + } + + var result = webrtcPeerConnectionInterfaceAddIceCandidate( + connection.Ptr, candidate.Ptr); + + GC.KeepAlive(connection); + GC.KeepAlive(candidate); return result; } - public static void Close(this IPeerConnectionInterface connection) { if (connection == null) @@ -1110,6 +1152,41 @@ public static void CreateOffer( GC.KeepAlive(observer); } + public static DisposableRtpSenderInterface[] GetSenders( + this IPeerConnectionInterface connection) + { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + + var cplusplus = + webrtcPeerConnectionInterfaceGetSenders(connection.Ptr); + GC.KeepAlive(connection); + var left = (long)webrtcRtpSenderInterfacesSize(cplusplus); + var interfaces = new DisposableRtpSenderInterface[left]; + var c = new IntPtr[left]; + + var handle = GCHandle.Alloc(c, GCHandleType.Pinned); + try + { + var addr = handle.AddrOfPinnedObject(); + webrtcRtpSenderInterfacesMove(cplusplus, addr); + } + finally + { + handle.Free(); + } + + while (left > 0) + { + left--; + interfaces[left] = new DisposableRtpSenderInterface(c[left]); + } + + return interfaces; + } + public static void SetAudioRecording( this IPeerConnectionInterface connection, bool recording) @@ -1203,4 +1280,4 @@ public static class PeerConnectionObserver [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcDeletePeerConnectionObserver")] public static extern void Delete(IntPtr observer); } -} +} \ No newline at end of file diff --git a/sdk/dotnet/webrtc/api/rtp_sender_interface.cs b/sdk/dotnet/webrtc/api/rtp_sender_interface.cs index 46e3d130da..ff62ce45c4 100644 --- a/sdk/dotnet/webrtc/api/rtp_sender_interface.cs +++ b/sdk/dotnet/webrtc/api/rtp_sender_interface.cs @@ -1,47 +1,121 @@ -/* - * Copyright 2019 pixiv Inc. 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. - */ - -using System; -using System.Runtime.InteropServices; - -namespace Pixiv.Webrtc -{ - public interface IDisposableRtpSenderInterface : - IRtpSenderInterface, Rtc.IDisposable - { - } - - public interface IRtpSenderInterface - { - IntPtr Ptr { get; } - } - - public sealed class DisposableRtpSenderInterface : - Rtc.DisposablePtr, IDisposableRtpSenderInterface - { - IntPtr IRtpSenderInterface.Ptr => Ptr; - - public DisposableRtpSenderInterface(IntPtr ptr) - { - Ptr = ptr; - } - - private protected override void FreePtr() - { - Interop.RtpSenderInterface.Release(Ptr); - } - } -} - -namespace Pixiv.Webrtc.Interop -{ - public static class RtpSenderInterface - { - [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcRtpSenderInterfaceRelease")] - public static extern void Release(IntPtr ptr); - } -} +/* + * Copyright 2019 pixiv Inc. 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. + */ + +using System; +using System.Runtime.InteropServices; + +namespace Pixiv.Webrtc +{ + public interface IDisposableRtpSenderInterface : + IRtpSenderInterface, Rtc.IDisposable + { + } + + public interface IRtpSenderInterface + { + IntPtr Ptr { get; } + } + + public sealed class DisposableRtpSenderInterface : + Rtc.DisposablePtr, IDisposableRtpSenderInterface + { + IntPtr IRtpSenderInterface.Ptr => Ptr; + + public DisposableRtpSenderInterface(IntPtr ptr) + { + Ptr = ptr; + } + + private protected override void FreePtr() + { + Interop.RtpSenderInterface.Release(Ptr); + } + } + + public static class RtpSenderInterfaceExtension + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcDeleteRtpSenderInterfaceStreamIds( + IntPtr ids + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcRtpSenderInterfaceStream_ids( + IntPtr sender + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr webrtcRtpSenderInterfaceTrack( + IntPtr sender + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern void webrtcRtpSenderInterfaceStreamIdsData( + IntPtr ids, + IntPtr data + ); + + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl)] + private static extern UIntPtr webrtcRtpSenderInterfaceStreamIdsSize( + IntPtr ids + ); + + public static string[] StreamIds(this IRtpSenderInterface sender) + { + var ids = webrtcRtpSenderInterfaceStream_ids(sender.Ptr); + try + { + GC.KeepAlive(sender); + + var left = (long)webrtcRtpSenderInterfaceStreamIdsSize(ids); + var data = new IntPtr[left]; + var results = new string[left]; + + var handle = GCHandle.Alloc(data, GCHandleType.Pinned); + try + { + var addr = handle.AddrOfPinnedObject(); + webrtcRtpSenderInterfaceStreamIdsData(ids, addr); + } + finally + { + handle.Free(); + } + + while (left > 0) + { + left--; + results[left] = Marshal.PtrToStringAnsi(data[left]); + } + + return results; + } + finally + { + webrtcDeleteRtpSenderInterfaceStreamIds(ids); + } + } + + public static DisposableMediaStreamTrackInterface Track( + this IRtpSenderInterface sender + ) + { + var ptr = webrtcRtpSenderInterfaceTrack(sender.Ptr); + GC.KeepAlive(sender); + return Interop.MediaStreamTrackInterface.WrapDisposable(ptr); + } + } +} + +namespace Pixiv.Webrtc.Interop +{ + public static class RtpSenderInterface + { + [DllImport(Dll.Name, CallingConvention = CallingConvention.Cdecl, EntryPoint = "webrtcRtpSenderInterfaceRelease")] + public static extern void Release(IntPtr ptr); + } +} \ No newline at end of file diff --git a/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs b/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs index e659b1a7b4..4d945a46a2 100644 --- a/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs +++ b/sdk/dotnet/webrtc/api/rtp_transceiver_interface.cs @@ -52,7 +52,7 @@ public static DisposableRtpReceiverInterface Receiver( } var receiver = webrtcRtpTransceiverInterfaceReceiver(transceiver.Ptr); - GC.KeepAlive(receiver); + GC.KeepAlive(transceiver); return new DisposableRtpReceiverInterface(receiver); } From bfff25e4727a4f28b1749fbd586b559b8ad1d4ec Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Sun, 6 Sep 2020 08:42:00 +0800 Subject: [PATCH 79/85] updates --- sdk/dotnet/unity/unity.msbuildproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 0dd8f615f0..d26028302a 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -9,7 +9,7 @@ bin/ - Debug + Release $(BaseOutputPath)$(Configuration)/ @@ -19,7 +19,7 @@ $([System.IO.Path]::GetFullPath('$(OutputPath)')) true false - WinX64 + WinX64;WinX86 ;$(Targets); "$(FullIntermediateOutputPath.Replace('\', '\\').Replace('"', '\"'))" $(FullOutputPath.Replace('\', '\\').Replace('"', '\"')) From e663995ffdeb229c025c230f67644704f93c3ded Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Mon, 7 Sep 2020 20:07:01 +0800 Subject: [PATCH 80/85] add flags for h264 compilation --- sdk/dotnet/unity/unity.msbuildproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index d26028302a..61f34c728b 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -67,14 +67,14 @@ From 76ed06e74fff821329e7bbf6465e9487dbe0aa62 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Mon, 22 Feb 2021 09:07:00 +0800 Subject: [PATCH 81/85] updates --- .../win/dxgi_output_duplicator.cc | 6 +++--- sdk/BUILD.gn | 6 ++++-- sdk/dotnet/webrtc/api/jsep.cs | 1 + .../webrtc/api/peer_connection_interface.cs | 4 ++-- sdk/dotnet/webrtc/rtc_base.cs | 7 +++++-- .../api/peerconnection/RTCAudioDeviceModule.h | 1 + .../api/peerconnection/RTCAudioDeviceModule.mm | 16 ---------------- .../peerconnection/RTCPeerConnectionFactory.h | 1 - .../peerconnection/RTCPeerConnectionFactory.mm | 2 ++ 9 files changed, 18 insertions(+), 26 deletions(-) diff --git a/modules/desktop_capture/win/dxgi_output_duplicator.cc b/modules/desktop_capture/win/dxgi_output_duplicator.cc index db7ba251c2..f2e9656670 100644 --- a/modules/desktop_capture/win/dxgi_output_duplicator.cc +++ b/modules/desktop_capture/win/dxgi_output_duplicator.cc @@ -273,7 +273,7 @@ bool DxgiOutputDuplicator::DoDetectUpdatedRegion( return false; } - if (metadata_.capacity() < frame_info.TotalMetadataBufferSize) { + if (metadata_.size() < frame_info.TotalMetadataBufferSize) { metadata_.clear(); // Avoid data copy metadata_.reserve(frame_info.TotalMetadataBufferSize); } @@ -283,7 +283,7 @@ bool DxgiOutputDuplicator::DoDetectUpdatedRegion( reinterpret_cast(metadata_.data()); size_t move_rects_count = 0; _com_error error = duplication_->GetFrameMoveRects( - static_cast(metadata_.capacity()), move_rects, &buff_size); + static_cast(metadata_.size()), move_rects, &buff_size); if (error.Error() != S_OK) { RTC_LOG(LS_ERROR) << "Failed to get move rectangles, error " << error.ErrorMessage() << ", code " << error.Error(); @@ -294,7 +294,7 @@ bool DxgiOutputDuplicator::DoDetectUpdatedRegion( RECT* dirty_rects = reinterpret_cast(metadata_.data() + buff_size); size_t dirty_rects_count = 0; error = duplication_->GetFrameDirtyRects( - static_cast(metadata_.capacity()) - buff_size, dirty_rects, + static_cast(metadata_.size()) - buff_size, dirty_rects, &buff_size); if (error.Error() != S_OK) { RTC_LOG(LS_ERROR) << "Failed to get dirty rectangles, error " diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 1ff81e3e71..9369f445f5 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -796,9 +796,7 @@ if (is_ios || is_mac) { "..:no_global_constructors", ] sources = [ - "objc/api/peerconnection/RTCAudioDeviceModule+Private.h", "objc/api/peerconnection/RTCAudioDeviceModule.h", - "objc/api/peerconnection/RTCAudioDeviceModule.mm", "objc/api/peerconnection/RTCAudioSource+Private.h", "objc/api/peerconnection/RTCAudioSource.h", "objc/api/peerconnection/RTCAudioSource.mm", @@ -954,6 +952,10 @@ if (is_ios || is_mac) { ] if (is_ios) { + sources += [ + "objc/api/peerconnection/RTCAudioDeviceModule+Private.h", + "objc/api/peerconnection/RTCAudioDeviceModule.mm", + ] deps += [ ":native_api_audio_device_module" ] } } diff --git a/sdk/dotnet/webrtc/api/jsep.cs b/sdk/dotnet/webrtc/api/jsep.cs index f2e6dc7b13..7ec44b1021 100644 --- a/sdk/dotnet/webrtc/api/jsep.cs +++ b/sdk/dotnet/webrtc/api/jsep.cs @@ -8,6 +8,7 @@ using Pixiv.Rtc; using System; using System.Runtime.InteropServices; +using System.Threading.Tasks; namespace Pixiv.Webrtc { diff --git a/sdk/dotnet/webrtc/api/peer_connection_interface.cs b/sdk/dotnet/webrtc/api/peer_connection_interface.cs index d0ae8c0b91..9bd625bf59 100644 --- a/sdk/dotnet/webrtc/api/peer_connection_interface.cs +++ b/sdk/dotnet/webrtc/api/peer_connection_interface.cs @@ -930,8 +930,8 @@ public sealed class RtcOfferAnswerOptions public const int MaxOfferToReceiveMedia = 1; public const int OfferToReceiveMediaTrue = 1; - public int OfferToReceiveVideo { get; set; } = Undefined; - public int OfferToReceiveAudio { get; set; } = Undefined; + public int OfferToReceiveVideo { get; set; } = 0; + public int OfferToReceiveAudio { get; set; } = 0; [field: MarshalAs(UnmanagedType.I1)] public bool VoiceActivityDetection { get; set; } = true; diff --git a/sdk/dotnet/webrtc/rtc_base.cs b/sdk/dotnet/webrtc/rtc_base.cs index b5fa3f808e..0dcf81331c 100644 --- a/sdk/dotnet/webrtc/rtc_base.cs +++ b/sdk/dotnet/webrtc/rtc_base.cs @@ -161,8 +161,11 @@ public virtual void ReleasePtr() { _ptr = IntPtr.Zero; GC.SuppressFinalize(this); - } - } + } + + } + + public sealed class DisposableThread : DisposablePtr, IDisposableThread { diff --git a/sdk/objc/api/peerconnection/RTCAudioDeviceModule.h b/sdk/objc/api/peerconnection/RTCAudioDeviceModule.h index 5c643aabba..9c47f8bdb4 100644 --- a/sdk/objc/api/peerconnection/RTCAudioDeviceModule.h +++ b/sdk/objc/api/peerconnection/RTCAudioDeviceModule.h @@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN RTC_OBJC_EXPORT +NS_CLASS_AVAILABLE_IOS(2_0) @interface RTCAudioDeviceModule : NSObject - (void)deliverRecordedData:(CMSampleBufferRef)sampleBuffer; diff --git a/sdk/objc/api/peerconnection/RTCAudioDeviceModule.mm b/sdk/objc/api/peerconnection/RTCAudioDeviceModule.mm index 518d75a5e3..f3275e0624 100644 --- a/sdk/objc/api/peerconnection/RTCAudioDeviceModule.mm +++ b/sdk/objc/api/peerconnection/RTCAudioDeviceModule.mm @@ -11,47 +11,31 @@ #include "rtc_base/ref_counted_object.h" @implementation RTCAudioDeviceModule { -#if defined(WEBRTC_IOS) rtc::scoped_refptr _nativeModule; -#endif } - (instancetype)init { -#if defined(WEBRTC_IOS) self = [super init]; _nativeModule = new rtc::RefCountedObject(); return self; -#else - return nullptr; -#endif } - (void)deliverRecordedData:(CMSampleBufferRef)sampleBuffer { -#if defined(WEBRTC_IOS) _nativeModule->OnDeliverRecordedExternalData(sampleBuffer); -#endif } - (void)setAudioUnitSubType:(OSType)audioUnitSubType { -#if defined(WEBRTC_IOS) _nativeModule->SetAudioUnitSubType(audioUnitSubType); -#endif } - (OSType)audioUnitSubType { -#if defined(WEBRTC_IOS) return _nativeModule->GetAudioUnitSubType(); -#else - return kAudioUnitSubType_VoiceProcessingIO; -#endif } #pragma mark - Private -#if defined(WEBRTC_IOS) - (rtc::scoped_refptr)nativeModule { return _nativeModule; } -#endif @end diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h index b0c545a155..5bf1622c61 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h @@ -40,7 +40,6 @@ RTC_OBJC_EXPORT - (instancetype)initWithEncoderFactory:(nullable id)encoderFactory decoderFactory:(nullable id)decoderFactory - audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule; /** Initialize an RTCAudioSource with constraints. */ - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)constraints; diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm index c12105ab04..930888745f 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm @@ -120,6 +120,7 @@ - (instancetype)initWithEncoderFactory:(nullable id)enco mediaTransportFactory:nullptr]; } +#if defined(WEBRTC_IOS) - (instancetype)initWithEncoderFactory:(nullable id)encoderFactory decoderFactory:(nullable id)decoderFactory audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule { @@ -143,6 +144,7 @@ - (instancetype)initWithEncoderFactory:(nullable id)enco mediaTransportFactory:nullptr]; #endif } +#endif - (instancetype)initNative { if (self = [super init]) { From 15179cd0791acb199630d004bcd04d86a233358c Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Mon, 22 Feb 2021 14:19:40 +0800 Subject: [PATCH 82/85] remove webrtc proj build --- sdk/dotnet/unity/unity.msbuildproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index 61f34c728b..c0cbafaf8f 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -80,14 +80,14 @@ - + - + From ba03c79861a5042bcd486a34a48d4d76f76156e8 Mon Sep 17 00:00:00 2001 From: Sean Tearney Date: Mon, 22 Feb 2021 14:20:23 +0800 Subject: [PATCH 83/85] remove tabs --- sdk/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 9369f445f5..875f709382 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -952,7 +952,7 @@ if (is_ios || is_mac) { ] if (is_ios) { - sources += [ + sources += [ "objc/api/peerconnection/RTCAudioDeviceModule+Private.h", "objc/api/peerconnection/RTCAudioDeviceModule.mm", ] From fd161e7cbe219b14bb094e0e055e82e72c83bc7d Mon Sep 17 00:00:00 2001 From: sean tearney Date: Fri, 24 Feb 2023 15:56:21 +0800 Subject: [PATCH 84/85] update sources update object recognition --- .gclient | 1 + sdk/dotnet/unity/unity.msbuildproj | 2 +- .../.vs/webrtc/DesignTimeBuild/.dtbcache.v2 | Bin 0 -> 47719 bytes .../media/base/adapted_video_track_source.cs | 21 +++++++++++++----- sdk/dotnet/webrtc/rtc_base.cs | 20 +++++++++-------- 5 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 .gclient create mode 100644 sdk/dotnet/webrtc/.vs/webrtc/DesignTimeBuild/.dtbcache.v2 diff --git a/.gclient b/.gclient new file mode 100644 index 0000000000..d7647d7bac --- /dev/null +++ b/.gclient @@ -0,0 +1 @@ +'solutions=[{name:src,url:https://www.github.com/ispysoftware/webrtc@origin/nudi}]' \ No newline at end of file diff --git a/sdk/dotnet/unity/unity.msbuildproj b/sdk/dotnet/unity/unity.msbuildproj index c0cbafaf8f..8f27b0674d 100644 --- a/sdk/dotnet/unity/unity.msbuildproj +++ b/sdk/dotnet/unity/unity.msbuildproj @@ -9,7 +9,7 @@ bin/ - Release + Release $(BaseOutputPath)$(Configuration)/ diff --git a/sdk/dotnet/webrtc/.vs/webrtc/DesignTimeBuild/.dtbcache.v2 b/sdk/dotnet/webrtc/.vs/webrtc/DesignTimeBuild/.dtbcache.v2 new file mode 100644 index 0000000000000000000000000000000000000000..756dc65393a2657c888240f03e6dc62ad2d0728e GIT binary patch literal 47719 zcmdU23wRt=*`7e5H=taFg0;nRwKU1*(yJ9hlD4t*mJ6k@CCu*5rqk^1Y-eVZE~Rp* zh=_;<5fKp)5fKp)5fKp)5fKp)5fKp)5fPCSN5l)i{_i>S&F;*}2J(!V;s5*e-7h=m z-8tWP?&r)o-|V%UqA2@xXsOb`S#5>#oc48nXDPEzEa|ySyPDptwHpOn)eF`-)wFdr z*P+^~vd3~YXKBj*>r7*dmbRDcg#pbhntH)jPDr(6TU(pcYI<=d(Y#<`WAlR6MXANv zL~B+}w=8N&sHvt*Mq8Z8E^5uTG^N#qsx>WcZOJyZBr>X&)|7*J+&0~MZOJZ{>=mX_ zDk`fwmL%!2l`QJp^r56>rju4?Fqtvzf@UX&wUlY6lSXPwQW%uPMaxzT8P&`*)i+Xj zeI}PvCfR058~-g+df`oPIn9k;+ZU43U%6tAh^OdvOMG6j>YJSdg zJ*Qc7j@hoWPPCo8RTo`xex_ zaa_7DT&T9DTNfl2H@9ewixw;D#4GD-KZL$(d>5)J^Nbyr%IWmNRH8YXO=r*sW?B=< zz{IQEQ?_g^U*A?N@|IiMW(&o8M_sO}-%_8bhY2A{ixrvrR8i49@&O{hC9HC+PqESF!z1qlVIo?GV4GaAWI%Zw~GnG6WixxC*T4W{#)lAHZXxq48g}#$-RQW(RENFP_D08aEsWyw;;a!_3VVuI zXIjA_0@+m!4w@6L2IQhMr(96;Sd{866>Kc&3tLY0TB%@I(2$Vph0!%qD{@APuSBV0 z!KPi!Y5ZZ9+wOXe)EJzgW#QJ_wnUaiL8bl6Hi3|!5h1gu6q6O5+tBCpM_z9Jq^QIN z463h^g0_Xrpy(FXy4H%dLeqWpC#sOQuoevRn~@mjV<&liFuDb&psw|NB0$-~%bd61 zG$zY$T-g35x`DN%_NjW2+b8nM8(7z-1kD;>(UbG6KeAc{oq6V*L>bk!)~{~Z;YoB& z8Pt`E)rN}Zz7W3=VIR*%*U`q+ z8XY_l=4_3!EnBVS4YRyjEf%#5Zz$Z+!RggDViaK_Owyt>X`NmqGrFs0h>H`UdZdj( zUm>p+P^vO+s`uEYrsn0wpe8A3TDZm_y2bXB^uktQhPT+xFZfjs+i~V2D@a1+&TT~+ zW4iUio2SWv6JbhpV*sHown(bjUzQWu;Ee$SA$}vUJ0;YDW^_Y-q3ZgQW|q|y4I{lF ze=ukw%s3;mVzowd_dKnprU~DJ3XktWpWKf}*PwERSK4+_lpC)>^)C8V4_k$!>#ez# ze5;_?Gg+$aD)D;j(ZPOm!agOAZbBvW)$C!z#J13^VdmX+7d{*DCRDX4ezU^nQnUqZ zowqRQFJSzlU-hs#5?!0blUo|JZ>-j9Ur^ADkSj%cq>WOywzZ^L^gP+?AGm>D!2bgq zdNl0C)a|lptGwNd+y*ZoXhXQ!MRa>Agr-J%5c|=E1>T+t-*vwMVXJa<^K`E01}(Kx zQ!|=b-2y9&@#g7caQuda9ehMLnI)xrD0A9#I<~+Gv%JY{O-9hDaK$a!)(g4i8RcK* z4q7u2W<=P3l=6I&uUlm*{RdqPsy@E4mAsZ1U4>tp;wO~cy{|m^y(Y_dJ!nA4o+G-Q z{5XHY&#ZVGcD#@H|qahW93s>8k~5IRZYf37!}=g zoR8u84hRe55#GCqO!B7Va$wMuaP4k%PksE_x<;)Qi$1PR-cz43SwZ8%P1EDZCwIfq z82RJ|22BZ+DU zyKu_SG>Vm~!wZ-<6BvWzH!N&{yCAxKm1Ah_ZRe3!W^Ac_kQ0P%=lhx8{;*3P5w`EN zYiW&t)LrR^rNE#m;kv2_2Y;k33a2nisBk#+{SWi2jXpvP$-wI^KOy@-v1AN5r-2 zS^X(__hD6KL_8L2B8-c!Pxsay>)Ugxo_8yt*QZNienZ0U!ilaxR+Tl&McaU*j^gHW zeOqq8z?$o3vdk-xZ$|c;+7$9YUUUVrw)X9o`xMM8kYlp^#)a*|qdU%9TkXz5+Q@j1 zVK&pK<&CKmVP@RLwb~>Grf;(V9=Ctjjfv#sciG2)&**&c|nWT+^R&kkA@$Ms}Ho3 z-VT&NNYIFoOZL%iGYjY{FME4k+gPLtu`Rk~2cdSiHc-l`ro4B{TXq7KpEES0N%<uT_)6f`)|5oCw>4O3`vH32YSf_Ml59)q5n#worQpqw9NoS_>lseUBU% zG$mX&8b=j!^^;t@V1C>gAyN<0?v{JPJm)t=1b@ zdfRI8J*e>b(pz5gitdRU{9|T}VYlD#p19GqiBLScl=fETyp+cGFbd0?Y@*vA#1$4h z#QC!)Z-0Nf^ecUt_7QyJ6+CRObG>DEXhnFnfQM~8;9`5`n$BK$ixSS; z(YpvA+6@>K)i*19xMET-_u+m(4W6@tCJD4DPvPSQ1g5Tt6Ua-{Hfi*??fQW0*y zaYVIO_%^R_+j6>UDf<+vZs)O1pzK!<72#9ewPg;!6r?0ZQxX!TX*8utqBM`DG)t70 z(Uca6(mI;bDp3}UrYs0hkUcVmU-BE>R6ojSe#uMyHaMFvpNWU*zG8DQ<&0NsjNwAg zP&1Y?ivrrwRp103g_B=6OMxE?;q{$LUB=yPCbl9}^VS!SS3E1ZT9b8@bl0AaRW*5s z1huYml-=9VJ=b(eFW!LQ(`fE^-e~Zqq+%we%zd*L8F11&D5a24Rds#p>_^-6e3zy+ z6pXY{$m#>il!g*!YFTZ*GPMB*(s9-zGhdm5@L|;~EJ-YEOdN-gCjLQxH8nOaQl>Rz zOSxPTjk1Nmxevw+yu{B_4rtI!)4S-qew>FsW7 z?_Ao^d1Bv+rMyMxZClgP*4^R%yQ#m?|25Iy*uS>Be?@m^TW@D~FeEW%NYj`h&0~hN zj2Y58X2^muLSTe1MA^?x9yFji15cnZJyzb`5Jo>n;B_rG**$^`@b)a zIH@5MD=?Bzek<f+I0EYI*liJ`YZ2cG*Mcq@#T zoUMxlIQOkkq`GZF=S%{#RG|Gz_#I5g(xLhzmz+Ug z6nhr%jS6FVZH~PxRy``mGP3Yz1RkQLHJ|_E*oz@oz}ty65Jw}xhY+!JSDtHK9^sjB zSms424H1T8i96_AS9D;p6y~6h)u5l;QXG~C72uhDPAsiiFkb15UMypCc;w^jL8i}9 zY&=6^DPqY7XDpqWq=Mf8>y|i59pdLjEtV3FxTGYGrDg}C4LT-`r-}tNkebz42FyVX z{Ej|j=}{1UEti~U#ZmA0DRC*zw8R(5i1izA6eZ1P6pSQ<1D zv$xAqByTMJrHD4@WpOZ$gys&1cxMqy#o>`vTpGsGNbwkJcp{8t7$D-V?KUvB)UNpV zi=_~Ai>02>j;j!R-tt6gjxE;8xgcJLVp$2~Y3%nL7RzvpM~a=DHT}!QGS(plJi~o{ z;9@J-u-}V5z6R6p>>-xo<@10hYEmrEEwP`#@60Tg66K3injgmj{r;U| z={dcKW%olo)h~^;#K{_vW#^c>Z7=}2m)iR`#URF+uA6BT`s8a^i^v2-JqxWylSk0G)2pJ=j2 z`}T-sc{J#sf;WuuEPw~&m4=Y9jO4~}Um?o-);LzVswcB~vd8kAr5dH=KO&aiuo`>S z)k93B?TuVB#8Sh3wpTqU#GL1@4i$$7ap!r(H9;(^x!7wIbR`hW%2)N6zi3BddF10A z*^gzF!GGL77VEt6dMuAvcx3TD809gJI+-5JrbHfdaH`0=p;!hTJnG=F?^xO*5v_Di zJGP`o&M?gsO-~_#V%nx=V1P&{WN`vbQ)ts9NG^;e2I! zL&?rA!rh7`Tj&5c&Uw9{TehB_r|jFn57EJ^7Js$-l7%>bys-gqlMv@q-7}AGs)ToL zIJ3HkpY6znw2$$CwEaqpzeQj2<0waSHbKX%mdQ_^OC7W?Dz2HExXAi4KL`y#eMn3G|n398Jtw+SB?-@;N8sD`iq)oBC3M>Mj8LDXZl!n z$t?6Ebr3thflvx}Q~T4KRs1&BuXCsK&`aEZI{)PsODl5jKHiu9OuF*hJZx0^E%C0^ z;BWWmbT`;8^Owrv7IXMDt|+XkXc~x7*l616evyHdXiU3^R7-1kd9@jg<}iLs9&GWW z=2D=Dj|bu;Lcyx_^F#R0hxCkQB=wf2#{N_(ivyNCUXf~Ui1_pc`F`XEW%-eE{-fE| z+xbF#KNafw?`j&hyMBmYA1?pe(hGw@bLWnth-W}S(oq#se@chxC>?lxDL+MO1j?K! zWv-spQZ^%PXpsb=xlTJ9JZ-!naWtP!yD@mD#N_y<5XOuTgM0 zV=6vSK~d+Gy}J1e_bdvS(gi;WHeSD{9NfW=J!8u}`D3U=bBGjBz10Cy2;VKE$aJ4Z zy}ZR}v-&J8qfExi%MeP4G98D$)25C_7$=RVo~s zc~5aL-xh*olU*|K+^fbj4IW>O!hle6A6gdo)S28~%Aw)Ylo{fnB|Q3iAqR9>UHM{8 zPwRHBEK-ptiE#D+wI+$X?YYL-fCKKzfnHnB)kEeK;T;$qPFEqFD`hlZ>}*Tfo08M} z+PTdiI-`0t<0NfJ%PEtD(UXM1(>rvlm{ZFl(*4_Ul)JCkYv2Hvwpuj@HB;HkD~~Rn zGuEkP?kPc;>HE@a^psN7!m$@l6rXaEcZ7T3E}NT5C!O=HVc#r?N0#E=X5%?qU67VPB zW#G>MzyB)$14e+q01oh1U1@BW4FuLJn6{0}~M zhx|7rkLy1GPXlE)H>?hFH-O)NcSwH!Nsv5_Js|f4`0pk|@;JC&Q}8!WPp;QkI(hnl zs!YYlGyrsEI=_H_&OxwQIgiz`-PrDI(%<)Idt6$#i|yIQCbKDQPc{{p#-_8q*xqa( z2VZ8eec66&e|Es7bsuF1URwA1R(8;d4tty9u!Gq_4m-pV|M&$5-`y`WiE${KDKTae z<1k{pogF4I4kN}aV!VURk{GjyF`F23*ldY0n;3@^F&43f5@R7T787F$TP!ga6Jsec z-p!UujHSd_MvV8cWfEfyj8<#8^d)lh`VWv5FY0iLr*QmKdvvv6dL?*jkCPmKf`a z(aqLNjP=CmAx1Cjkr+M1=p)9-tWRR}5n}@}PGK7)#s*?+B*v+1qr})qjMIpbWT#1t z(}=N&7^kyM5@QoF`iXG{>z5e)#88QmVyeVYiIFBohNUG&niv`}vP_d08Ziclv6&4> zi~(Zk#Mr`giJ=o?kQg~OC@}_!ktarh zEMk<1F~mv|qeP5hVr*l>5@VPcWn!Gk$`YeYjP1lYi*1(}+ljG*81G{{B*qS6oK1{# z*x3@}Y+{^CjPuyJ660KA>?Fqf*-nYElNjd{;{)t`iE%zLE+EDS*##2g0%BZ9j1RF3 zCB}usxQG}ZW*13}i->VCF+RdBmKYZk;}T+glwBe*E+NJ)VqD60NsL{@xQrMdW0y&c z%ZPC~F+R>Nml&55;|gMYf?Xjot{}#h#P}q;Qes?5jH`(8DRz~_xQZB86XVnDYKd_* zF|HxTXV^6o;~HXION`I5YbD0D#JG+apJUfajO&PTJuyDdu9q0s6XOPAe1Y8{F>WBn zjl}pOyHR4?NQ|3^@g;VX#JGtVHxuK_>}H8^Gcj%<##h)a65|$P+)9kEvRfs_t;D#E z7++(zNsQZwaXT@-&Tf|&w-e(IVtj+$Au;YC#+}6YCc9H&+)0ePi196Um&CY>7e2AjX5l_#t~xVmwHUhlueb_K?JQh!_tO4P#P}t9Qer$wjHih4EB2Jc zc#0TL6XVzHX^HVPF`gmDZ`d;u;~8Q+ON`&LXC=n7#CVPvzhloyjOU2)JTZRHo|hQU z6XOM9{DHk7F>}84ZGBI8u24k;Cj8}*; zLX5w#5s5KE42KwhWsbyf2@ZRe7=L50N{mPDtQOsgB24zX9= z$leh9)Q!x5*tc$EKZyP7Mh<{Dux{iaajUn9&x6J1A^7BT@lHPLW-}pXI_xlr!yGmX zVwS^ZL(F#A;Sh&AY%auHhaCxVq{EJeIND*yLLBR`c@Xm)HXmZX!x|tO9F~AcIIJ0> z*w)NTSRX{6!!|%{aM(tOjSf2v;xvbCg4pD+eu#dDsSv8e z(hzBfX%L#j1|S9;rbFls8-y5iSRNwpFayGH*j9+G4znOEhm{~o4jYCTc32sr?6B<+ z+a0z8Vu!=dhB(_{=R%z8u$>S)9d)k1!eLiJT>7w`9Cj_lwGO)u;yQ<24{^Q2 zZh*MKVK+kD=&+k0ZgSYo5H~yQ7KmFMb}PiK4!aHFHiz8~al6CrfVjh9cS79hu)84c za@gGvcRTDJh!=8Y6!eLKBJn68fAf9sA(-2QP>=}q>9QG{4vkrR>;yH&s5AnRi zUVwPPVJ||w=&+X{UUJyW5HCCI6^K_HHUcr?FbBdxwT5`rVXr~F=8Vh~b>vWd?qdI0 zF6t%KPt;BJZ(czUa|2i4x2U)yZ?ALMWM^a+u6~S7S&1v}sNdx7r) g_W|Dn?gzdPJOKOvco6s@@DT7L;NiLx&N=6Q0qNV0pa1{> literal 0 HcmV?d00001 diff --git a/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs b/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs index 542c59ce81..0890875e9c 100644 --- a/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs +++ b/sdk/dotnet/webrtc/media/base/adapted_video_track_source.cs @@ -81,15 +81,24 @@ IntPtr functions [MonoPInvokeCallback(typeof(DestructionHandler))] private static void OnDestruction(IntPtr context) { - var handle = (GCHandle)context; - var source = (AdaptedVideoTrackSource)handle.Target; - - if (source._handle.IsAllocated) + try { - source._handle.Free(); + var handle = (GCHandle)context; + var source = (AdaptedVideoTrackSource)handle.Target; + if (source != null) + { + if (source._handle.IsAllocated) + { + source._handle.Free(); + } + } + + handle.Free(); } + catch + { - handle.Free(); + } } [MonoPInvokeCallback(typeof(SourceStateGetter))] diff --git a/sdk/dotnet/webrtc/rtc_base.cs b/sdk/dotnet/webrtc/rtc_base.cs index 0dcf81331c..bdaedf478a 100644 --- a/sdk/dotnet/webrtc/rtc_base.cs +++ b/sdk/dotnet/webrtc/rtc_base.cs @@ -137,11 +137,11 @@ internal DisposablePtr() ~DisposablePtr() { - if (_ptr == IntPtr.Zero) - { - return; - } - FreePtr(); + //if (_ptr == IntPtr.Zero) + //{ + // return; + //} + //FreePtr(); } public void Dispose() @@ -162,10 +162,7 @@ public virtual void ReleasePtr() _ptr = IntPtr.Zero; GC.SuppressFinalize(this); } - - } - - + } public sealed class DisposableThread : DisposablePtr, IDisposableThread { @@ -262,6 +259,11 @@ public static void Run(this IThread thread) public static void Start(this IThread thread) { + if (thread == null) + { + throw new ArgumentNullException(nameof(thread)); + } + rtcThreadStart(thread.Ptr); GC.KeepAlive(thread); } From 65e1c57d33be2fb411eecec46518f1c77ed76805 Mon Sep 17 00:00:00 2001 From: sean tearney Date: Mon, 10 Jul 2023 12:33:42 +0800 Subject: [PATCH 85/85] bug fixes, playback timing update --- sdk/dotnet/webrtc/api/video/video_frame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/dotnet/webrtc/api/video/video_frame.cs b/sdk/dotnet/webrtc/api/video/video_frame.cs index ccd9d55071..16824197c1 100644 --- a/sdk/dotnet/webrtc/api/video/video_frame.cs +++ b/sdk/dotnet/webrtc/api/video/video_frame.cs @@ -219,14 +219,14 @@ public static void SetVideoFrameBuffer( GC.KeepAlive(value); } - public static void SetTimestampMs( + public static void SetTimestampUs( this VideoFrame.IBuilder builder, long value) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } - webrtcVideoFrameBuilder_set_timestamp_ms(builder.Ptr, value); + webrtcVideoFrameBuilder_set_timestamp_us(builder.Ptr, value); GC.KeepAlive(builder); }