Skip to content

Commit

Permalink
Update libwebrtc and just use (amazing) SendAsync.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Mar 3, 2024
1 parent 4fe82d1 commit bb38736
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 176 deletions.
2 changes: 1 addition & 1 deletion min-webrtc/abseil-cpp
Submodule abseil-cpp updated 578 files
2 changes: 1 addition & 1 deletion min-webrtc/libsrtp
Submodule libsrtp updated from 5b7c74 to 17b2d5
19 changes: 10 additions & 9 deletions min-webrtc/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,32 @@ cflags += -I$(pwd)/webrtc
webrtc :=


# XXX: wrapping_async_dns_resolver.cc should have been deleted in 24510d43dccc88a47e2cd139b2190e25d4c7b700
webrtc += $(filter-out \
%/create_peerconnection_factory.cc \
%/field_trials_registry.cc \
%/wrapping_async_dns_resolver.cc \
,$(wildcard $(pwd)/webrtc/api/*.cc))

webrtc += $(wildcard $(pwd)/webrtc/api/crypto/*.cc)
webrtc += $(wildcard $(pwd)/webrtc/api/task_queue/*.cc)
webrtc += $(wildcard $(pwd)/webrtc/api/transport/*.cc)
webrtc += $(wildcard $(pwd)/webrtc/api/transport/media/*.cc)
webrtc += $(wildcard $(pwd)/webrtc/api/transport/rtp/*.cc)
webrtc += $(wildcard $(pwd)/webrtc/api/units/*.cc)

webrtc += $(pwd)/webrtc/api/field_trials_registry.cc

webrtc += $(pwd)/webrtc/api/audio_codecs/audio_codec_pair_id.cc
webrtc += $(pwd)/webrtc/api/audio_codecs/audio_encoder.cc

webrtc += $(pwd)/webrtc/api/call/transport.cc
webrtc += $(pwd)/webrtc/api/environment/environment_factory.cc
webrtc += $(pwd)/webrtc/api/numerics/samples_stats_counter.cc

webrtc += $(pwd)/webrtc/api/rtc_event_log/rtc_event.cc
webrtc += $(pwd)/webrtc/api/rtc_event_log/rtc_event_log.cc

webrtc += $(pwd)/webrtc/api/task_queue/pending_task_safety_flag.cc
webrtc += $(pwd)/webrtc/api/task_queue/task_queue_base.cc

webrtc += $(pwd)/webrtc/api/video/color_space.cc
webrtc += $(pwd)/webrtc/api/video/encoded_image.cc
webrtc += $(pwd)/webrtc/api/video/hdr_metadata.cc
Expand Down Expand Up @@ -103,8 +106,6 @@ webrtc += $(wildcard $(pwd)/webrtc/modules/rtp_rtcp/source/deprecated/*.cc)
webrtc += $(wildcard $(pwd)/webrtc/modules/rtp_rtcp/source/rtcp_packet/*.cc)
webrtc += $(wildcard $(pwd)/webrtc/modules/utility/source/*.cc)

webrtc += $(pwd)/webrtc/modules/utility/maybe_worker_thread.cc

webrtc += $(pwd)/webrtc/modules/video_coding/chain_diff_calculator.cc
webrtc += $(pwd)/webrtc/modules/video_coding/encoded_frame.cc
webrtc += $(pwd)/webrtc/modules/video_coding/frame_dependencies_calculator.cc
Expand Down Expand Up @@ -190,11 +191,11 @@ webrtc := $(filter-out $(pwd)/webrtc/rtc_base/system/%,$(webrtc))
source += $(pwd)/webrtc/rtc_base/system/file_wrapper.cc

webrtc := $(filter-out $(pwd)/webrtc/rtc_base/boringssl_%.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/rtc_base/%_gcd.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/rtc_base/%_libevent.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/%_gcd.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/%_libevent.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/%_libevent_experiment.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/rtc_base/mac_%.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/rtc_base/%_stdlib.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/rtc_base/%_win.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/%_win.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/rtc_base/win/%.cc,$(webrtc))
webrtc := $(filter-out $(pwd)/webrtc/rtc_base/win32%.cc,$(webrtc))

Expand Down
2 changes: 1 addition & 1 deletion min-webrtc/webrtc
Submodule webrtc updated from b459de to c8068f
66 changes: 66 additions & 0 deletions p2p/lwip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
set -e

function fix() {
sed -e '
s/PhysicalSocket/LwipSocket/g;
s/PHYSICAL/LOGICAL/g;
s/\<rtc\>/orc/g;
s/orc::/rtc::/g;
s/= {}/= {0}/g;
s/{}/= default;/g;
s/#include <fcntl.h>/#include <signal.h>/g;
s/#include "rtc_base\/physical_socket_server\.h"/#include "logical_.hpp"/g;
/#include <netinet\//d;
/#include <sys\//d;
s/defined(WEBRTC_USE_EPOLL)/0/g;
s/defined(WEBRTC_USE_POLL)/0/g;
s/defined(WEBRTC_POSIX)/1/g;
s/defined(WEBRTC_ANDROID)/0/g;
s/defined(WEBRTC_FUCHSIA)/0/g;
s/defined(WEBRTC_IOS)/0/g;
s/defined(WEBRTC_LINUX)/0/g;
s/defined(WEBRTC_MAC)/0/g;
s/defined(WEBRTC_WIN)/0/g;
s/defined(__native_client__)/0/g;
s/::accept(/::lwip_accept(/g;
s/::bind(/::lwip_bind(/g;
s/\<close(/lwip_close(/g;
s/::closesocket(/::lwip_close(/g;
s/::connect(/::lwip_connect(/g;
s/\<fcntl(/lwip_fcntl(/g;
s/::getpeername(/::lwip_getpeername(/g;
s/::getsockname(/::lwip_getsockname(/g;
s/\<getsockopt(/lwip_getsockopt(/g;
s/::listen(/::lwip_listen(/g;
s/read(/lwip_recv(/g;
s/::recv(/::lwip_recv(/g;
s/::recvfrom(/::lwip_recvfrom(/g;
s/::recvmsg(/::lwip_recvmsg(/g;
s/\<select(/lwip_select(/g;
s/::send(/::lwip_send(/g;
s/::sendto(/::lwip_sendto(/g;
s/::setsockopt(/::lwip_setsockopt(/g;
s/::socket(/::lwip_socket(/g;
s/write(/lwip_send(/g;
s/\<SO_TIMESTAMP\>/-1/g;
'
}

{
diff -ru source/lwip.hpp <(fix <../min-webrtc/webrtc/rtc_base/physical_socket_server.h) | colordiff
diff -ru source/lwip.cpp <(fix <../min-webrtc/webrtc/rtc_base/physical_socket_server.cc) | colordiff
} | nl | less -R

# e077ee472a6a14fb78aa59faa4549eea3a227958 <- remove IP_MTU

#/GetSocketRecvTimestamp(.*{/,/^}/s/^ .*/ return -1;/;
84 changes: 3 additions & 81 deletions p2p/source/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "channel.hpp"
#include "peer.hpp"
#include "pirate.hpp"
#include "tube.hpp"

namespace orc {
Expand Down Expand Up @@ -161,95 +160,18 @@ struct P {
}
};

struct SctpDataChannel$SendDataMessage { typedef bool (webrtc::SctpDataChannel::*type)(const webrtc::DataBuffer &, bool); };
template struct Pirate<SctpDataChannel$SendDataMessage, &webrtc::SctpDataChannel::SendDataMessage>;

struct SctpDataChannel$controller_ { typedef webrtc::SctpDataChannelControllerInterface *const (webrtc::SctpDataChannel::*type); };
template struct Pirate<SctpDataChannel$controller_, &webrtc::SctpDataChannel::controller_>;

struct DataChannelController$DataChannelSendData { typedef bool (webrtc::DataChannelController::*type)(int, const webrtc::SendDataParams &, const rtc::CopyOnWriteBuffer &, cricket::SendDataResult *); };
template struct Pirate<DataChannelController$DataChannelSendData, &webrtc::DataChannelController::DataChannelSendData>;

struct DataChannelController$network_thread { typedef rtc::Thread *(webrtc::DataChannelController::*type)() const; };
template struct Pirate<DataChannelController$network_thread, &webrtc::DataChannelController::network_thread>;

#if 0
struct SctpDataChannelTransport$sctp_transport_ { typedef cricket::SctpTransportInternal *const (webrtc::SctpDataChannelTransport::*type); };
template struct Pirate<SctpDataChannelTransport$sctp_transport_, &webrtc::SctpDataChannelTransport::sctp_transport_>;
#endif

task<void> Channel::Send(const Buffer &data) {
Trace("WebRTC", true, false, data);

const auto size(data.size());
rtc::CopyOnWriteBuffer buffer(size);
data.copy(buffer.MutableData(), size);

#if 1
static const webrtc::SendDataParams params([]() {
webrtc::SendDataParams params;
params.type = webrtc::DataMessageType::kBinary;
params.ordered = false;
params.max_rtx_count = 0;
return params;
}());
#endif

#if 0
co_await Post([&]() {
orc_assert(channel_ != nullptr);
#if 0
if (channel_->buffered_amount() == 0)
channel_->Send({buffer, true});
#else
const auto sctp(reinterpret_cast<webrtc::SctpDataChannel *const *>(channel_.get() + 1)[1]);
#if 0
sctp->Send({buffer, true});
#else
if (sctp->state() != webrtc::DataChannelInterface::kOpen)
return;
#if 0
if (!(sctp->*Loot<SctpDataChannel$SendDataMessage>::pointer)({buffer, true}, false))
return;
#else
const auto provider(sctp->*Loot<SctpDataChannel$controller_>::pointer);
cricket::SendDataResult result;
#if 0
provider->SendData(sctp->id(), params, buffer, &result);
#else
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
const auto controller(static_cast<webrtc::DataChannelController *>(provider));
(controller->*Loot<DataChannelController$DataChannelSendData>::pointer)(sctp->id(), params, buffer, &result);
#endif
#endif
#endif
#endif
});
#else
// XXX: is this safe?
orc_assert(channel_ != nullptr);
if (channel_->buffered_amount() == 0)
channel_->Send({buffer, true});

const auto sctp(reinterpret_cast<webrtc::SctpDataChannel *const *>(channel_.get() + 1)[1]);
const auto provider(sctp->*Loot<SctpDataChannel$controller_>::pointer);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
const auto controller(static_cast<webrtc::DataChannelController *>(provider));

co_await Post([&]() {
const auto interface(controller->data_channel_transport());
if (!interface->IsReadyToSend()) {
orc_trace();
return;
}
#if 1 // XXX
interface->SendData(sctp->id(), params, buffer);
#else
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
const auto transport(static_cast<webrtc::SctpDataChannelTransport *>(interface));
cricket::SendDataResult result;
(transport->*Loot<SctpDataChannelTransport$sctp_transport_>::pointer)->SendData(sctp->id(), params, buffer, &result);
#endif
}, *(controller->*Loot<DataChannelController$network_thread>::pointer)());
#endif
co_return;
}

task<std::string> Description(const S<Base> &base, std::vector<std::string> ice) {
Expand Down
Loading

0 comments on commit bb38736

Please sign in to comment.