Replaces SynchronousMethodCall with rtc::Thread::Invoke.
Given that we already have Thread:.Invoke that can be used with lambda, SynchronousMethodCall doesn't add any value. This simplification prepares for simulated time peer connection tests. Bug: webrtc:11255 Change-Id: I478a11f15e30e009dae4a3fee2120f6d7a03355f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165683 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30217}
This commit is contained in:

committed by
Commit Bot

parent
290de82b2a
commit
b0e0728159
@ -145,7 +145,6 @@ rtc_library("libjingle_peerconnection_api") {
|
|||||||
"peer_connection_interface.cc",
|
"peer_connection_interface.cc",
|
||||||
"peer_connection_interface.h",
|
"peer_connection_interface.h",
|
||||||
"peer_connection_proxy.h",
|
"peer_connection_proxy.h",
|
||||||
"proxy.cc",
|
|
||||||
"proxy.h",
|
"proxy.h",
|
||||||
"rtp_receiver_interface.cc",
|
"rtp_receiver_interface.cc",
|
||||||
"rtp_receiver_interface.h",
|
"rtp_receiver_interface.h",
|
||||||
|
37
api/proxy.cc
37
api/proxy.cc
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license
|
|
||||||
* that can be found in the LICENSE file in the root of the source
|
|
||||||
* tree. An additional intellectual property rights grant can be found
|
|
||||||
* in the file PATENTS. All contributing project authors may
|
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "api/proxy.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
SynchronousMethodCall::SynchronousMethodCall(rtc::MessageHandler* proxy)
|
|
||||||
: proxy_(proxy) {}
|
|
||||||
|
|
||||||
SynchronousMethodCall::~SynchronousMethodCall() = default;
|
|
||||||
|
|
||||||
void SynchronousMethodCall::Invoke(const rtc::Location& posted_from,
|
|
||||||
rtc::Thread* t) {
|
|
||||||
if (t->IsCurrent()) {
|
|
||||||
proxy_->OnMessage(nullptr);
|
|
||||||
} else {
|
|
||||||
t->Post(posted_from, this, 0);
|
|
||||||
e_.Wait(rtc::Event::kForever);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SynchronousMethodCall::OnMessage(rtc::Message*) {
|
|
||||||
proxy_->OnMessage(nullptr);
|
|
||||||
e_.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
} // namespace webrtc
|
|
243
api/proxy.h
243
api/proxy.h
@ -70,106 +70,6 @@ class Location;
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
template <typename R>
|
|
||||||
class ReturnType {
|
|
||||||
public:
|
|
||||||
template <typename C, typename M, typename... Args>
|
|
||||||
void Invoke(C* c, M m, Args&&... args) {
|
|
||||||
r_ = (c->*m)(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
R moved_result() { return std::move(r_); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
R r_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
class ReturnType<void> {
|
|
||||||
public:
|
|
||||||
template <typename C, typename M, typename... Args>
|
|
||||||
void Invoke(C* c, M m, Args&&... args) {
|
|
||||||
(c->*m)(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
void moved_result() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
class RTC_EXPORT SynchronousMethodCall : public rtc::MessageData,
|
|
||||||
public rtc::MessageHandler {
|
|
||||||
public:
|
|
||||||
explicit SynchronousMethodCall(rtc::MessageHandler* proxy);
|
|
||||||
~SynchronousMethodCall() override;
|
|
||||||
|
|
||||||
void Invoke(const rtc::Location& posted_from, rtc::Thread* t);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnMessage(rtc::Message*) override;
|
|
||||||
|
|
||||||
rtc::Event e_;
|
|
||||||
rtc::MessageHandler* proxy_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
template <typename C, typename R, typename... Args>
|
|
||||||
class MethodCall : public rtc::Message, public rtc::MessageHandler {
|
|
||||||
public:
|
|
||||||
typedef R (C::*Method)(Args...);
|
|
||||||
MethodCall(C* c, Method m, Args&&... args)
|
|
||||||
: c_(c),
|
|
||||||
m_(m),
|
|
||||||
args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
|
|
||||||
|
|
||||||
R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
|
|
||||||
internal::SynchronousMethodCall(this).Invoke(posted_from, t);
|
|
||||||
return r_.moved_result();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnMessage(rtc::Message*) { Invoke(std::index_sequence_for<Args...>()); }
|
|
||||||
|
|
||||||
template <size_t... Is>
|
|
||||||
void Invoke(std::index_sequence<Is...>) {
|
|
||||||
r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
|
|
||||||
}
|
|
||||||
|
|
||||||
C* c_;
|
|
||||||
Method m_;
|
|
||||||
ReturnType<R> r_;
|
|
||||||
std::tuple<Args&&...> args_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename C, typename R, typename... Args>
|
|
||||||
class ConstMethodCall : public rtc::Message, public rtc::MessageHandler {
|
|
||||||
public:
|
|
||||||
typedef R (C::*Method)(Args...) const;
|
|
||||||
ConstMethodCall(const C* c, Method m, Args&&... args)
|
|
||||||
: c_(c),
|
|
||||||
m_(m),
|
|
||||||
args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
|
|
||||||
|
|
||||||
R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
|
|
||||||
internal::SynchronousMethodCall(this).Invoke(posted_from, t);
|
|
||||||
return r_.moved_result();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnMessage(rtc::Message*) { Invoke(std::index_sequence_for<Args...>()); }
|
|
||||||
|
|
||||||
template <size_t... Is>
|
|
||||||
void Invoke(std::index_sequence<Is...>) {
|
|
||||||
r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
|
|
||||||
}
|
|
||||||
|
|
||||||
const C* c_;
|
|
||||||
Method m_;
|
|
||||||
ReturnType<R> r_;
|
|
||||||
std::tuple<Args&&...> args_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper macros to reduce code duplication.
|
// Helper macros to reduce code duplication.
|
||||||
#define PROXY_MAP_BOILERPLATE(c) \
|
#define PROXY_MAP_BOILERPLATE(c) \
|
||||||
template <class INTERNAL_CLASS> \
|
template <class INTERNAL_CLASS> \
|
||||||
@ -216,13 +116,11 @@ class ConstMethodCall : public rtc::Message, public rtc::MessageHandler {
|
|||||||
#define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
|
#define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
|
||||||
protected: \
|
protected: \
|
||||||
~c##ProxyWithInternal() { \
|
~c##ProxyWithInternal() { \
|
||||||
MethodCall<c##ProxyWithInternal, void> call( \
|
destructor_thread()->template Invoke<void>(RTC_FROM_HERE, \
|
||||||
this, &c##ProxyWithInternal::DestroyInternal); \
|
[&] { c_ = nullptr; }); \
|
||||||
call.Marshal(RTC_FROM_HERE, destructor_thread()); \
|
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
void DestroyInternal() { c_ = nullptr; } \
|
|
||||||
rtc::scoped_refptr<INTERNAL_CLASS> c_;
|
rtc::scoped_refptr<INTERNAL_CLASS> c_;
|
||||||
|
|
||||||
// Note: This doesn't use a unique_ptr, because it intends to handle a corner
|
// Note: This doesn't use a unique_ptr, because it intends to handle a corner
|
||||||
@ -233,13 +131,11 @@ class ConstMethodCall : public rtc::Message, public rtc::MessageHandler {
|
|||||||
#define OWNED_PROXY_MAP_BOILERPLATE(c) \
|
#define OWNED_PROXY_MAP_BOILERPLATE(c) \
|
||||||
public: \
|
public: \
|
||||||
~c##ProxyWithInternal() { \
|
~c##ProxyWithInternal() { \
|
||||||
MethodCall<c##ProxyWithInternal, void> call( \
|
destructor_thread()->template Invoke<void>(RTC_FROM_HERE, \
|
||||||
this, &c##ProxyWithInternal::DestroyInternal); \
|
[&] { delete c_; }); \
|
||||||
call.Marshal(RTC_FROM_HERE, destructor_thread()); \
|
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
void DestroyInternal() { delete c_; } \
|
|
||||||
INTERNAL_CLASS* c_;
|
INTERNAL_CLASS* c_;
|
||||||
|
|
||||||
#define BEGIN_SIGNALING_PROXY_MAP(c) \
|
#define BEGIN_SIGNALING_PROXY_MAP(c) \
|
||||||
@ -289,112 +185,95 @@ class ConstMethodCall : public rtc::Message, public rtc::MessageHandler {
|
|||||||
\
|
\
|
||||||
public: // NOLINTNEXTLINE
|
public: // NOLINTNEXTLINE
|
||||||
|
|
||||||
#define PROXY_METHOD0(r, method) \
|
#define PROXY_METHOD0_BASE(t, modifier, r, method) \
|
||||||
r method() override { \
|
r method() modifier override { \
|
||||||
MethodCall<C, r> call(c_, &C::method); \
|
return t->template Invoke<r>(RTC_FROM_HERE, [&] { return c_->method(); }); \
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PROXY_METHOD1_BASE(t, modifier, r, method, t1) \
|
||||||
|
r method(t1 a1) modifier override { \
|
||||||
|
return t->template Invoke<r>(RTC_FROM_HERE, \
|
||||||
|
[&] { return c_->method(std::move(a1)); }); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PROXY_METHOD2_BASE(t, modifier, r, method, t1, t2) \
|
||||||
|
r method(t1 a1, t2 a2) modifier override { \
|
||||||
|
return t->template Invoke<r>(RTC_FROM_HERE, [&] { \
|
||||||
|
return c_->method(std::move(a1), std::move(a2)); \
|
||||||
|
}); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PROXY_METHOD3_BASE(t, modifier, r, method, t1, t2, t3) \
|
||||||
|
r method(t1 a1, t2 a2, t3 a3) modifier override { \
|
||||||
|
return t->template Invoke<r>(RTC_FROM_HERE, [&] { \
|
||||||
|
return c_->method(std::move(a1), std::move(a2), std::move(a3)); \
|
||||||
|
}); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PROXY_METHOD4_BASE(t, modifier, r, method, t1, t2, t3, t4) \
|
||||||
|
r method(t1 a1, t2 a2, t3 a3, t4 a4) modifier override { \
|
||||||
|
return t->template Invoke<r>(RTC_FROM_HERE, [&] { \
|
||||||
|
return c_->method(std::move(a1), std::move(a2), std::move(a3), \
|
||||||
|
std::move(a4)); \
|
||||||
|
}); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PROXY_METHOD5_BASE(t, modifier, r, method, t1, t2, t3, t4, t5) \
|
||||||
|
r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) modifier override { \
|
||||||
|
return t->template Invoke<r>(RTC_FROM_HERE, [&] { \
|
||||||
|
return c_->method(std::move(a1), std::move(a2), std::move(a3), \
|
||||||
|
std::move(a4), std::move(a5)); \
|
||||||
|
}); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PROXY_METHOD0(r, method) \
|
||||||
|
PROXY_METHOD0_BASE(signaling_thread_, , r, method)
|
||||||
|
|
||||||
#define PROXY_CONSTMETHOD0(r, method) \
|
#define PROXY_CONSTMETHOD0(r, method) \
|
||||||
r method() const override { \
|
PROXY_METHOD0_BASE(signaling_thread_, const, r, method)
|
||||||
ConstMethodCall<C, r> call(c_, &C::method); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_METHOD1(r, method, t1) \
|
#define PROXY_METHOD1(r, method, t1) \
|
||||||
r method(t1 a1) override { \
|
PROXY_METHOD1_BASE(signaling_thread_, , r, method, t1)
|
||||||
MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_CONSTMETHOD1(r, method, t1) \
|
#define PROXY_CONSTMETHOD1(r, method, t1) \
|
||||||
r method(t1 a1) const override { \
|
PROXY_METHOD1_BASE(signaling_thread_, const, r, method, t1)
|
||||||
ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_METHOD2(r, method, t1, t2) \
|
#define PROXY_METHOD2(r, method, t1, t2) \
|
||||||
r method(t1 a1, t2 a2) override { \
|
PROXY_METHOD2_BASE(signaling_thread_, , r, method, t1, t2)
|
||||||
MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_METHOD3(r, method, t1, t2, t3) \
|
#define PROXY_METHOD3(r, method, t1, t2, t3) \
|
||||||
r method(t1 a1, t2 a2, t3 a3) override { \
|
PROXY_METHOD3_BASE(signaling_thread_, , r, method, t1, t2, t3)
|
||||||
MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2), std::move(a3)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
|
#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
|
||||||
r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
|
PROXY_METHOD4_BASE(signaling_thread_, , r, method, t1, t2, t3, t4)
|
||||||
MethodCall<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2), std::move(a3), \
|
|
||||||
std::move(a4)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
|
#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
|
||||||
r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
|
PROXY_METHOD5_BASE(signaling_thread_, , r, method, t1, t2, t3, t4, t5)
|
||||||
MethodCall<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2), std::move(a3), \
|
|
||||||
std::move(a4), std::move(a5)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define methods which should be invoked on the worker thread.
|
// Define methods which should be invoked on the worker thread.
|
||||||
#define PROXY_WORKER_METHOD0(r, method) \
|
#define PROXY_WORKER_METHOD0(r, method) \
|
||||||
r method() override { \
|
PROXY_METHOD0_BASE(worker_thread_, , r, method)
|
||||||
MethodCall<C, r> call(c_, &C::method); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_WORKER_CONSTMETHOD0(r, method) \
|
#define PROXY_WORKER_CONSTMETHOD0(r, method) \
|
||||||
r method() const override { \
|
PROXY_METHOD0_BASE(worker_thread_, const, r, method)
|
||||||
ConstMethodCall<C, r> call(c_, &C::method); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_WORKER_METHOD1(r, method, t1) \
|
#define PROXY_WORKER_METHOD1(r, method, t1) \
|
||||||
r method(t1 a1) override { \
|
PROXY_METHOD1_BASE(worker_thread_, , r, method, t1)
|
||||||
MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \
|
#define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \
|
||||||
r method(t1 a1) const override { \
|
PROXY_METHOD1_BASE(worker_thread_, const, r, method, t1)
|
||||||
ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_WORKER_METHOD2(r, method, t1, t2) \
|
#define PROXY_WORKER_METHOD2(r, method, t1, t2) \
|
||||||
r method(t1 a1, t2 a2) override { \
|
PROXY_METHOD2_BASE(worker_thread_, , r, method, t1, t2)
|
||||||
MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \
|
#define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \
|
||||||
r method(t1 a1, t2 a2) const override { \
|
PROXY_METHOD2_BASE(worker_thread_, const, r, method, t1, t2)
|
||||||
ConstMethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_WORKER_METHOD3(r, method, t1, t2, t3) \
|
#define PROXY_WORKER_METHOD3(r, method, t1, t2, t3) \
|
||||||
r method(t1 a1, t2 a2, t3 a3) override { \
|
PROXY_METHOD3_BASE(worker_thread_, , r, method, t1, t2, t3)
|
||||||
MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2), std::move(a3)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROXY_WORKER_CONSTMETHOD3(r, method, t1, t2) \
|
#define PROXY_WORKER_CONSTMETHOD3(r, method, t1, t2) \
|
||||||
r method(t1 a1, t2 a2, t3 a3) const override { \
|
PROXY_METHOD3_BASE(worker_thread_, const, r, method, t1, t2, t3)
|
||||||
ConstMethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
|
||||||
std::move(a2), std::move(a3)); \
|
|
||||||
return call.Marshal(RTC_FROM_HERE, worker_thread_); \
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
|
@ -55,9 +55,8 @@ CreateModularPeerConnectionFactory(
|
|||||||
std::move(dependencies)));
|
std::move(dependencies)));
|
||||||
// Call Initialize synchronously but make sure it is executed on
|
// Call Initialize synchronously but make sure it is executed on
|
||||||
// |signaling_thread|.
|
// |signaling_thread|.
|
||||||
MethodCall<PeerConnectionFactory, bool> call(
|
bool result = pc_factory->signaling_thread()->Invoke<bool>(
|
||||||
pc_factory.get(), &PeerConnectionFactory::Initialize);
|
RTC_FROM_HERE, [&] { return pc_factory->Initialize(); });
|
||||||
bool result = call.Marshal(RTC_FROM_HERE, pc_factory->signaling_thread());
|
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Reference in New Issue
Block a user