Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 71974f2

Browse files
committed
Enable NACK module.
1 parent 0f82778 commit 71974f2

File tree

6 files changed

+75
-25
lines changed

6 files changed

+75
-25
lines changed

talk/owt/sdk/wasm/binding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace wasm {
1515
EMSCRIPTEN_BINDINGS(Owt) {
1616
emscripten::class_<MediaSession>("MediaSession")
1717
.constructor<>()
18-
.function("createRtpVideoReceiver",
19-
&MediaSession::CreateRtpVideoReceiver);
18+
.function("createRtpVideoReceiver", &MediaSession::CreateRtpVideoReceiver)
19+
.function("setRtcpCallback", &MediaSession::SetRtcpCallback);
2020
emscripten::class_<RtpVideoReceiver>("RtpVideoReceiver")
2121
.smart_ptr<std::shared_ptr<RtpVideoReceiver>>("RtpVideoReceiver")
2222
.function("onRtpPacket", &RtpVideoReceiver::OnRtpPacket,

talk/owt/sdk/wasm/gn/wasm.gni

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ template("wasm_lib") {
6666
"MEMFS_APPEND_TO_TYPED_ARRAYS=1",
6767

6868
# Reduces global namespace pollution.
69-
# "-s",
70-
# "MODULARIZE=1",
69+
"-s",
70+
"MODULARIZE=1",
71+
72+
"-s",
73+
"EXPORT_ES6=1",
7174

7275
#"-fno-stack-protector",
7376

@@ -81,7 +84,7 @@ template("wasm_lib") {
8184
"--bind",
8285

8386
"-s",
84-
"PTHREAD_POOL_SIZE=2",
87+
"PTHREAD_POOL_SIZE=5",
8588

8689
"-pthread",
8790

talk/owt/sdk/wasm/media_session.cc

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,52 @@ MediaSession::MediaSession()
2020
receive_statistics_(
2121
webrtc::ReceiveStatistics::Create(webrtc::Clock::GetRealTimeClock())),
2222
receiver_process_thread_(nullptr),
23-
video_receiver_(nullptr) {
24-
RTC_LOG(LS_ERROR) << "Ctor of Media Session. " << __EMSCRIPTEN_PTHREADS__;
23+
video_receiver_(nullptr),
24+
rtcp_callback_(emscripten::val::null()) {
2525
rtc::ThreadManager::Instance()->WrapCurrentThread();
26-
receiver_process_thread_=webrtc::ProcessThread::Create("ReceiverProcessThread");
26+
receiver_process_thread_ =
27+
webrtc::ProcessThread::Create("ReceiverProcessThread");
2728
webrtc::Call::Config config(event_log_.get());
2829
config.task_queue_factory = task_queue_factory_.get();
2930
webrtc::FieldTrialBasedConfig trials;
3031
config.trials = &trials;
3132
call_ = std::unique_ptr<webrtc::Call>(webrtc::Call::Create(config));
3233
}
3334

34-
MediaSession::~MediaSession() {}
35-
3635
std::shared_ptr<RtpVideoReceiver> MediaSession::CreateRtpVideoReceiver() {
37-
webrtc::VideoReceiveStream::Config config(web_transport_session_.get());
36+
webrtc::VideoReceiveStream::Config config(this);
3837
config.rtp.local_ssrc = 1;
39-
// TODO: Get a message queue for receiver.
38+
// Same as `kNackRtpHistoryMs` in third_party/webrtc/media/engine/webrtc_voice_engine.cc.
39+
config.rtp.nack.rtp_history_ms = 5000;
40+
// TODO: Use call_->worker_thread() when libwebrtc is rolled to a newer version.
41+
webrtc::TaskQueueBase* current = webrtc::TaskQueueBase::Current();
42+
if (!current)
43+
current = rtc::ThreadManager::Instance()->CurrentThread();
44+
RTC_DCHECK(current);
4045
video_receiver_ = std::make_shared<RtpVideoReceiver>(
41-
web_transport_session_.get(), &config, receive_statistics_.get(),
42-
receiver_process_thread_.get(), web_transport_session_.get());
46+
current, this, &config, receive_statistics_.get(),
47+
receiver_process_thread_.get());
4348
return video_receiver_;
4449
}
4550

51+
void MediaSession::SetRtcpCallback(emscripten::val callback) {
52+
rtcp_callback_ = callback;
53+
}
54+
55+
bool MediaSession::SendRtp(const uint8_t* packet,
56+
size_t length,
57+
const webrtc::PacketOptions& options) {
58+
return false;
59+
}
60+
61+
bool MediaSession::SendRtcp(const uint8_t* packet, size_t length) {
62+
if (!rtcp_callback_) {
63+
return false;
64+
}
65+
emscripten::val buffer(emscripten::typed_memory_view(length, packet));
66+
rtcp_callback_(buffer);
67+
return true;
68+
}
69+
4670
} // namespace wasm
4771
} // namespace owt

talk/owt/sdk/wasm/media_session.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef OWT_WASM_MEDIASESSION_H_
66
#define OWT_WASM_MEDIASESSION_H_
77

8+
#include <emscripten/bind.h>
89
#include "call/call.h"
910
#include "talk/owt/sdk/wasm/rtp_video_receiver.h"
1011
#include "talk/owt/sdk/wasm/web_transport_session.h"
@@ -13,11 +14,18 @@
1314
namespace owt {
1415
namespace wasm {
1516
// Manages a media session between a web client and OWT server QUIC agent.
16-
class MediaSession {
17+
class MediaSession : public webrtc::Transport {
1718
public:
1819
explicit MediaSession();
19-
virtual ~MediaSession();
20+
virtual ~MediaSession() = default;
2021
std::shared_ptr<RtpVideoReceiver> CreateRtpVideoReceiver();
22+
void SetRtcpCallback(emscripten::val callback);
23+
24+
// Overrides webrtc::Transport.
25+
bool SendRtp(const uint8_t* packet,
26+
size_t length,
27+
const webrtc::PacketOptions& options) override;
28+
bool SendRtcp(const uint8_t* packet, size_t length) override;
2129

2230
private:
2331
std::unique_ptr<webrtc::TaskQueueFactory> task_queue_factory_;
@@ -28,6 +36,7 @@ class MediaSession {
2836
std::unique_ptr<webrtc::ReceiveStatistics> receive_statistics_;
2937
std::unique_ptr<webrtc::ProcessThread> receiver_process_thread_;
3038
std::shared_ptr<RtpVideoReceiver> video_receiver_;
39+
emscripten::val rtcp_callback_;
3140
};
3241

3342
} // namespace wasm

talk/owt/sdk/wasm/rtp_video_receiver.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ namespace owt {
1010
namespace wasm {
1111

1212
RtpVideoReceiver::RtpVideoReceiver(
13+
webrtc::TaskQueueBase* current_queue,
1314
webrtc::Transport* transport,
1415
const webrtc::VideoReceiveStream::Config* config,
1516
webrtc::ReceiveStatistics* rtp_receive_statistics,
16-
webrtc::ProcessThread* process_thread,
17-
webrtc::NackSender* nack_sender)
17+
webrtc::ProcessThread* process_thread)
1818
: receiver_(nullptr), complete_frame_callback_(emscripten::val::null()) {
1919
receiver_ = std::make_unique<webrtc::RtpVideoStreamReceiver2>(
20-
nullptr, webrtc::Clock::GetRealTimeClock(), transport, nullptr, nullptr,
21-
config, rtp_receive_statistics, nullptr, nullptr, process_thread,
22-
nack_sender, nullptr, this, nullptr, nullptr);
20+
current_queue, webrtc::Clock::GetRealTimeClock(), transport, nullptr,
21+
nullptr, config, rtp_receive_statistics, nullptr, nullptr, process_thread,
22+
this, nullptr, this, nullptr, nullptr);
2323
webrtc::VideoCodec codec;
2424
codec.codecType = webrtc::VideoCodecType::kVideoCodecH264;
2525
// TODO: Assign payload value dynamically according to server side
@@ -53,5 +53,14 @@ void RtpVideoReceiver::SetCompleteFrameCallback(emscripten::val callback) {
5353
complete_frame_callback_ = callback;
5454
}
5555

56+
void RtpVideoReceiver::SendNack(const std::vector<uint16_t>& sequence_numbers,
57+
bool buffering_allowed) {
58+
// Only buffering_allowed == true is supported. Same as
59+
// https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/video/video_receive_stream2.h;l=157;bpv=1;bpt=1
60+
RTC_DCHECK(buffering_allowed);
61+
RTC_LOG(LS_INFO)<<"Request packet rtx";
62+
receiver_->RequestPacketRetransmit(sequence_numbers);
63+
}
64+
5665
} // namespace wasm
5766
} // namespace owt

talk/owt/sdk/wasm/rtp_video_receiver.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
namespace owt {
1212
namespace wasm {
1313
class RtpVideoReceiver
14-
: public webrtc::RtpVideoStreamReceiver2::OnCompleteFrameCallback {
14+
: public webrtc::RtpVideoStreamReceiver2::OnCompleteFrameCallback,
15+
public webrtc::NackSender {
1516
public:
16-
explicit RtpVideoReceiver(webrtc::Transport* transport,
17+
explicit RtpVideoReceiver(webrtc::TaskQueueBase* current_queue,
18+
webrtc::Transport* transport,
1719
const webrtc::VideoReceiveStream::Config* config,
1820
webrtc::ReceiveStatistics* rtp_receive_statistics,
19-
webrtc::ProcessThread* process_thread,
20-
webrtc::NackSender* nack_sender);
21+
webrtc::ProcessThread* process_thread);
2122
virtual ~RtpVideoReceiver() {}
2223
virtual bool OnRtpPacket(uintptr_t packet_ptr, size_t packet_size);
2324

@@ -27,6 +28,10 @@ class RtpVideoReceiver
2728

2829
void SetCompleteFrameCallback(emscripten::val callback);
2930

31+
// Overrides webrtc::NackSender.
32+
void SendNack(const std::vector<uint16_t>& sequence_numbers,
33+
bool buffering_allowed) override;
34+
3035
private:
3136
std::unique_ptr<webrtc::RtpVideoStreamReceiver2> receiver_;
3237
emscripten::val complete_frame_callback_;

0 commit comments

Comments
 (0)