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 55#ifndef OWT_WASM_BINDING_H_
66#define OWT_WASM_BINDING_H_
77
8- #include < emscripten/bind.h>
98#include " talk/owt/sdk/wasm/media_session.h"
109#include " talk/owt/sdk/wasm/rtp_video_receiver.h"
1110
@@ -14,9 +13,11 @@ namespace wasm {
1413
1514EMSCRIPTEN_BINDINGS (Owt) {
1615 emscripten::class_<MediaSession>(" MediaSession" )
17- .constructor <>( )
16+ .smart_ptr <std::shared_ptr<MediaSession>>( " MediaSession " )
1817 .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 ());
2021 emscripten::class_<RtpVideoReceiver>(" RtpVideoReceiver" )
2122 .smart_ptr <std::shared_ptr<RtpVideoReceiver>>(" RtpVideoReceiver" )
2223 .function (" onRtpPacket" , &RtpVideoReceiver::OnRtpPacket,
Original file line number Diff line number Diff line change 22//
33// SPDX-License-Identifier: Apache-2.0
44
5- #include < emscripten/bind.h>
65#include < iostream>
7- #include " third_party/webrtc/rtc_base/strings/json.h"
86#include " talk/owt/sdk/wasm/binding.h"
97
108int 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 ();
1710 return 0 ;
1811}
Original file line number Diff line number Diff line change 99
1010namespace owt {
1111namespace wasm {
12+
1213MediaSession::MediaSession ()
1314 : task_queue_factory_(webrtc::CreateTaskQueueStdlibFactory()),
1415 event_log_factory_ (std::make_unique<webrtc::RtcEventLogFactory>(
@@ -50,6 +51,16 @@ std::shared_ptr<RtpVideoReceiver> MediaSession::CreateRtpVideoReceiver(
5051 return video_receiver_;
5152}
5253
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+
5364void MediaSession::SetRtcpCallback (emscripten::val callback) {
5465 rtcp_callback_ = callback;
5566}
Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ class MediaSession : public webrtc::Transport {
1818 public:
1919 explicit MediaSession ();
2020 virtual ~MediaSession () = default ;
21+
22+ static MediaSession* Get ();
23+
2124 std::shared_ptr<RtpVideoReceiver> CreateRtpVideoReceiver (
2225 uint32_t remote_ssrc);
2326 void SetRtcpCallback (emscripten::val callback);
You can’t perform that action at this time.
0 commit comments