Skip to content

Commit 5928db2

Browse files
committed
Work in Progress
1 parent e7c6abf commit 5928db2

File tree

6 files changed

+161
-2
lines changed

6 files changed

+161
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// PrivMX Endpoint Swift
3+
// Copyright © 2024 Simplito sp. z o.o.
4+
//
5+
// This file is part of PrivMX Platform (https://privmx.dev).
6+
// This software is Licensed under the MIT License.
7+
//
8+
// See the License for the specific language governing permissions and
9+
// limitations under the License.
10+
//
11+
12+
#include "WebRtcInterfaceInstance.hpp"
13+

Sources/PrivMXEndpointStreamsLow/include/WebRtcInterfaceInstance.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ typedef void(*UpdateSessionIdCallback)(const std::string&,const int64_t, const s
2828
typedef void(*CloseCallback)(const std::string&);
2929
typedef void(*UpdateKeysCallback)(const std::string&,const KeyVector&);
3030

31+
typedef int(*ConvertToRGBAImpl)(uint8_t*,int,int,int);
32+
33+
class FrameImpl : public endpoint::stream::Frame{
34+
ConvertToRGBAImpl cb;
35+
public:
36+
37+
FrameImpl(ConvertToRGBAImpl _imp) : cb(_imp) {}
38+
39+
int ConvertToRGBA(uint8_t* dst_argb, int dst_stride_argb,int dest_width, int dest_height) override{
40+
return cb(dst_argb,dst_stride_argb,dest_width,dest_height);
41+
}
42+
};
43+
3144
class WebRtcInterfaceInstance: public privmx::endpoint::stream::WebRTCInterface{
3245
public:
3346
virtual std::string createOfferAndSetLocalDescription(const std::string& streamRoomId) override {
@@ -79,6 +92,7 @@ class WebRtcInterfaceInstance: public privmx::endpoint::stream::WebRTCInterface{
7992

8093
};
8194

95+
using SharedWebRTCInterfaceInstance = std::shared_ptr<WebRtcInterfaceInstance>;
8296
}
8397
#endif // !_WebRtcInterfaceInstance_
8498

Sources/PrivMXEndpointSwift/Streams/PmxPeerConnectionObserver.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,52 @@ import Foundation
1414
import WebRTC
1515
import Synchronization
1616

17+
1718
public final class PmxPeerConnectionObserver:NSObject,RTCPeerConnectionDelegate, @unchecked Sendable{
19+
private var streamRoomId: String
20+
private var currentKeys = PMXKeyStore()
21+
22+
private var onFrameCallback: (Int64, Int64) -> Void
23+
24+
init(
25+
streamRoomId: String,
26+
currentKeys: PMXKeyStore = PMXKeyStore(),
27+
onConnectionSignalingStateChanged: ((RTCPeerConnection, RTCSignalingState) -> Void)? = nil,
28+
onConnectionPeerStateChanged: ((RTCPeerConnection, RTCPeerConnectionState) -> Void)? = nil,
29+
onStreamAdded: ((RTCPeerConnection, RTCMediaStream) -> Void)? = nil,
30+
onStreamRemoved: ((RTCPeerConnection, RTCMediaStream) -> Void)? = nil,
31+
onShouldRenegotiate: ((RTCPeerConnection) -> Void)? = nil,
32+
onIceCandidateErrorEvent: ((RTCPeerConnection, RTCIceCandidateErrorEvent) -> Void)? = nil,
33+
onIceConnectionStateChanged: ((RTCPeerConnection, RTCIceConnectionState) -> Void)? = nil,
34+
onIceGatheringStateChanged: ((RTCPeerConnection, RTCIceGatheringState) -> Void)? = nil,
35+
onIceCandidateGenerated: ((RTCPeerConnection, RTCIceCandidate) -> Void)? = nil,
36+
onIceCandidatesRemoved: ((RTCPeerConnection, [RTCIceCandidate]) -> Void)? = nil,
37+
onDataChannelOpened: ((RTCPeerConnection, RTCDataChannel) -> Void)? = nil,
38+
onStartedReceiving: ((RTCPeerConnection, RTCRtpTransceiver) -> Void)? = nil,
39+
onStoppedReceiving: ((RTCPeerConnection, RTCRtpReceiver) -> Void)? = nil,
40+
onTracksAdded: ((RTCPeerConnection, RTCRtpReceiver, [RTCMediaStream]) -> Void)? = nil,
41+
onTracksRemoved: ((RTCPeerConnection, RTCRtpReceiver) -> Void)? = nil,
42+
onLocalCandidateChanged: ((RTCPeerConnection, RTCIceCandidate, RTCIceCandidate, Int32, String) -> Void)? = nil
43+
) {
44+
self.streamRoomId = streamRoomId
45+
self.currentKeys = currentKeys
46+
self.onConnectionSignalingStateChanged = onConnectionSignalingStateChanged
47+
self.onConnectionPeerStateChanged = onConnectionPeerStateChanged
48+
self.onStreamAdded = onStreamAdded
49+
self.onStreamRemoved = onStreamRemoved
50+
self.onShouldRenegotiate = onShouldRenegotiate
51+
self.onIceCandidateErrorEvent = onIceCandidateErrorEvent
52+
self.onIceConnectionStateChanged = onIceConnectionStateChanged
53+
self.onIceGatheringStateChanged = onIceGatheringStateChanged
54+
self.onIceCandidateGenerated = onIceCandidateGenerated
55+
self.onIceCandidatesRemoved = onIceCandidatesRemoved
56+
self.onDataChannelOpened = onDataChannelOpened
57+
self.onStartedReceiving = onStartedReceiving
58+
self.onStoppedReceiving = onStoppedReceiving
59+
self.onTracksAdded = onTracksAdded
60+
self.onTracksRemoved = onTracksRemoved
61+
self.onLocalCandidateChanged = onLocalCandidateChanged
62+
}
1863

1964

2065
private var onConnectionSignalingStateChanged: ((RTCPeerConnection,RTCSignalingState)->Void)?

Sources/PrivMXEndpointSwift/Streams/StreamApi.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public actor StreamApi: @unchecked Sendable{
2121
private var api: privmx.NativeStreamApiLowWrapper
2222
private var peerConnectionFactory: RTCPeerConnectionFactory
2323
private var webRtcInstance: privmx.WebRtcInterfaceInstance
24+
2425

2526

2627
//private var notificationListenerId : Int
@@ -410,9 +411,9 @@ public actor StreamApi: @unchecked Sendable{
410411
}
411412
}
412413

414+
413415
public extension EventHandler{
414-
415-
416+
416417
static func isStreamRoomCreatedEvent(
417418
eventHolder: privmx.endpoint.core.EventHolder
418419
) throws -> Bool {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// PrivMX Endpoint Swift
3+
// Copyright © 2024 Simplito sp. z o.o.
4+
//
5+
// This file is part of PrivMX Platform (https://privmx.dev).
6+
// This software is Licensed under the MIT License.
7+
//
8+
// See the License for the specific language governing permissions and
9+
// limitations under the License.
10+
//
11+
12+
import Foundation
13+
import PrivMXEndpointSwiftNative
14+
import PrivMXEndpointStreamsLow
15+
16+
final class StreamData:Sendable{
17+
18+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// PrivMX Endpoint Swift
3+
// Copyright © 2024 Simplito sp. z o.o.
4+
//
5+
// This file is part of PrivMX Platform (https://privmx.dev).
6+
// This software is Licensed under the MIT License.
7+
//
8+
// See the License for the specific language governing permissions and
9+
// limitations under the License.
10+
//
11+
12+
import Foundation
13+
import PrivMXEndpointSwiftNative
14+
import PrivMXEndpointStreamsLow
15+
import WebRTC
16+
17+
class FrameImpl{
18+
private var _frame : RTCVideoFrame
19+
public var cxxImpl : privmx.FrameImpl
20+
init(_frame: RTCVideoFrame) {
21+
self._frame = _frame
22+
self.cxxImpl = privmx.FrameImpl{
23+
dst_argb,dst_stride_argb,dest_width,dest_height in
24+
25+
26+
27+
RTCYUVHelper.i420(
28+
toARGB: <#T##UnsafePointer<UInt8>!#>,
29+
srcStrideY: <#T##Int32#>,
30+
srcU: <#T##UnsafePointer<UInt8>!#>,
31+
srcStrideU: <#T##Int32#>,
32+
srcV: <#T##UnsafePointer<UInt8>!#>,
33+
srcStrideV: <#T##Int32#>,
34+
dstARGB: dst_argb,
35+
dstStrideARGB: dst_stride_argb,
36+
width: <#T##Int32#>,
37+
height: <#T##Int32#>)
38+
}
39+
}
40+
41+
}
42+
43+
public final class WebRTCNativeInterface: Sendable {
44+
nonisolated(unsafe) private var api : privmx.SharedWebRTCInterfaceInstance
45+
nonisolated(unsafe) private var peerConnectionFactory: RTCPeerConnectionFactory
46+
nonisolated(unsafe) private var constraints : RTCMediaConstraints
47+
nonisolated(unsafe) private var onTrickle : @Sendable (Int64, String) -> Void
48+
nonisolated(unsafe) private var peerConnectionManager: PeerConnectionManager
49+
50+
init(
51+
api: privmx.SharedWebRTCInterfaceInstance,
52+
peerConnectionFactory: RTCPeerConnectionFactory,
53+
constraints: RTCMediaConstraints,
54+
onTrickle: @escaping @Sendable (Int64, String) -> Void,
55+
peerConnectionManager: PeerConnectionManager) {
56+
self.api = api
57+
self.peerConnectionFactory = peerConnectionFactory
58+
self.constraints = constraints
59+
self.onTrickle = onTrickle
60+
self.peerConnectionManager = PeerConnectionManager(
61+
_createPeerConnection:{
62+
streamRoomId in
63+
peerConnectionFactory
64+
65+
},
66+
_onTrickle: onTrickle)
67+
}
68+
}

0 commit comments

Comments
 (0)