This repository was archived by the owner on Oct 25, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +19
-11
lines changed Expand file tree Collapse file tree 4 files changed +19
-11
lines changed Original file line number Diff line number Diff line change 5
5
#ifndef OWT_WASM_BINDING_H_
6
6
#define OWT_WASM_BINDING_H_
7
7
8
- #include < emscripten/bind.h>
9
8
#include " talk/owt/sdk/wasm/media_session.h"
10
9
#include " talk/owt/sdk/wasm/rtp_video_receiver.h"
11
10
@@ -14,9 +13,11 @@ namespace wasm {
14
13
15
14
EMSCRIPTEN_BINDINGS (Owt) {
16
15
emscripten::class_<MediaSession>(" MediaSession" )
17
- .constructor <>( )
16
+ .smart_ptr <std::shared_ptr<MediaSession>>( " MediaSession " )
18
17
.function (" createRtpVideoReceiver" , &MediaSession::CreateRtpVideoReceiver)
19
- .function (" setRtcpCallback" , &MediaSession::SetRtcpCallback);
18
+ .function (" setRtcpCallback" , &MediaSession::SetRtcpCallback)
19
+ .class_function (" get" , &MediaSession::Get,
20
+ emscripten::allow_raw_pointers ());
20
21
emscripten::class_<RtpVideoReceiver>(" RtpVideoReceiver" )
21
22
.smart_ptr <std::shared_ptr<RtpVideoReceiver>>(" RtpVideoReceiver" )
22
23
.function (" onRtpPacket" , &RtpVideoReceiver::OnRtpPacket,
Original file line number Diff line number Diff line change 2
2
//
3
3
// SPDX-License-Identifier: Apache-2.0
4
4
5
- #include < emscripten/bind.h>
6
5
#include < iostream>
7
- #include " third_party/webrtc/rtc_base/strings/json.h"
8
6
#include " talk/owt/sdk/wasm/binding.h"
9
7
10
8
int main (int argc, char ** argv) {
11
- Json::Value in_s (" foo" );
12
- std::string out;
13
- rtc::GetStringFromJson (in_s, &out);
14
- std::cout << out << std::endl;
15
-
16
- printf (" WASM main.\n " );
9
+ owt::wasm::MediaSession::Get ();
17
10
return 0 ;
18
11
}
Original file line number Diff line number Diff line change 9
9
10
10
namespace owt {
11
11
namespace wasm {
12
+
12
13
MediaSession::MediaSession ()
13
14
: task_queue_factory_(webrtc::CreateTaskQueueStdlibFactory()),
14
15
event_log_factory_ (std::make_unique<webrtc::RtcEventLogFactory>(
@@ -50,6 +51,16 @@ std::shared_ptr<RtpVideoReceiver> MediaSession::CreateRtpVideoReceiver(
50
51
return video_receiver_;
51
52
}
52
53
54
+ std::once_flag create_media_session_flag;
55
+ std::shared_ptr<MediaSession> media_session;
56
+
57
+ MediaSession* MediaSession::Get () {
58
+ std::call_once (create_media_session_flag,
59
+ [] { media_session = std::make_shared<MediaSession>(); });
60
+ return media_session.get ();
61
+ }
62
+
63
+
53
64
void MediaSession::SetRtcpCallback (emscripten::val callback) {
54
65
rtcp_callback_ = callback;
55
66
}
Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ class MediaSession : public webrtc::Transport {
18
18
public:
19
19
explicit MediaSession ();
20
20
virtual ~MediaSession () = default ;
21
+
22
+ static MediaSession* Get ();
23
+
21
24
std::shared_ptr<RtpVideoReceiver> CreateRtpVideoReceiver (
22
25
uint32_t remote_ssrc);
23
26
void SetRtcpCallback (emscripten::val callback);
You can’t perform that action at this time.
0 commit comments