From 741daaf0393c4ba42c1bfc9c88907aaa09349987 Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Thu, 21 Mar 2019 14:37:36 +0100 Subject: [PATCH] Move rtc::FunctionView to the public API Bug: webrtc:10138 Change-Id: Icc25a2a277a9608701aaddd546882366739991ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/127898 Reviewed-by: Karl Wiberg Reviewed-by: Mirko Bonadei Commit-Queue: Artem Titov Cr-Commit-Position: refs/heads/master@{#27227} --- api/BUILD.gn | 12 ++ api/function_view.h | 130 ++++++++++++++++++ {rtc_base => api}/function_view_unittest.cc | 7 +- audio/BUILD.gn | 1 + audio/audio_send_stream.cc | 2 +- audio/channel_send.h | 2 +- logging/BUILD.gn | 1 + logging/rtc_event_log/rtc_event_processor.h | 2 +- modules/audio_coding/BUILD.gn | 1 + .../include/audio_coding_module.h | 2 +- modules/audio_processing/BUILD.gn | 1 + .../audio_processing/agc2/rnn_vad/BUILD.gn | 1 + .../agc2/rnn_vad/spectral_features_internal.h | 2 +- .../audio_processing/audio_processing_impl.h | 2 +- modules/desktop_capture/BUILD.gn | 2 + .../desktop_capture/linux/window_list_utils.h | 2 +- .../desktop_capture/mac/window_list_utils.h | 2 +- .../desktop_capture/screen_drawer_unittest.cc | 2 +- modules/rtp_rtcp/BUILD.gn | 1 + modules/rtp_rtcp/source/rtcp_packet.h | 2 +- pc/BUILD.gn | 2 + pc/peer_connection_wrapper.cc | 2 +- pc/peer_connection_wrapper.h | 2 +- rtc_base/BUILD.gn | 2 +- rtc_base/function_view.h | 117 +--------------- rtc_tools/BUILD.gn | 1 + rtc_tools/event_log_visualizer/analyzer.cc | 2 +- test/pc/e2e/api/BUILD.gn | 1 + .../api/peerconnection_quality_test_fixture.h | 2 +- 29 files changed, 175 insertions(+), 133 deletions(-) create mode 100644 api/function_view.h rename {rtc_base => api}/function_view_unittest.cc (95%) diff --git a/api/BUILD.gn b/api/BUILD.gn index ec03df3453..6b78a6c161 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -399,6 +399,16 @@ rtc_source_set("neteq_simulator_api") { ] } +rtc_source_set("function_view") { + visibility = [ "*" ] + sources = [ + "function_view.h", + ] + deps = [ + "../rtc_base:checks", + ] +} + if (rtc_include_tests) { if (rtc_enable_protobuf) { rtc_source_set("audioproc_f_api") { @@ -684,6 +694,7 @@ if (rtc_include_tests) { sources = [ "array_view_unittest.cc", + "function_view_unittest.cc", "rtc_error_unittest.cc", "rtp_parameters_unittest.cc", "test/loopback_media_transport_unittest.cc", @@ -691,6 +702,7 @@ if (rtc_include_tests) { deps = [ ":array_view", + ":function_view", ":libjingle_peerconnection_api", ":loopback_media_transport", "../rtc_base:checks", diff --git a/api/function_view.h b/api/function_view.h new file mode 100644 index 0000000000..5ae1bd6cfe --- /dev/null +++ b/api/function_view.h @@ -0,0 +1,130 @@ +/* + * Copyright 2016 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. + */ + +#ifndef API_FUNCTION_VIEW_H_ +#define API_FUNCTION_VIEW_H_ + +#include +#include + +#include "rtc_base/checks.h" + +// Just like std::function, FunctionView will wrap any callable and hide its +// actual type, exposing only its signature. But unlike std::function, +// FunctionView doesn't own its callable---it just points to it. Thus, it's a +// good choice mainly as a function argument when the callable argument will +// not be called again once the function has returned. +// +// Its constructors are implicit, so that callers won't have to convert lambdas +// and other callables to FunctionView explicitly. This is +// safe because FunctionView is only a reference to the real callable. +// +// Example use: +// +// void SomeFunction(rtc::FunctionView index_transform); +// ... +// SomeFunction([](int i) { return 2 * i + 1; }); +// +// Note: FunctionView is tiny (essentially just two pointers) and trivially +// copyable, so it's probably cheaper to pass it by value than by const +// reference. + +namespace rtc { + +template +class FunctionView; // Undefined. + +template +class FunctionView final { + public: + // Constructor for lambdas and other callables; it accepts every type of + // argument except those noted in its enable_if call. + template < + typename F, + typename std::enable_if< + // Not for function pointers; we have another constructor for that + // below. + !std::is_function::type>::type>::value && + + // Not for nullptr; we have another constructor for that below. + !std::is_same::type>::value && + + // Not for FunctionView objects; we have another constructor for that + // (the implicitly declared copy constructor). + !std::is_same::type>::type>::value>::type* = nullptr> + FunctionView(F&& f) + : call_(CallVoidPtr::type>) { + f_.void_ptr = &f; + } + + // Constructor that accepts function pointers. If the argument is null, the + // result is an empty FunctionView. + template < + typename F, + typename std::enable_if::type>::type>::value>::type* = + nullptr> + FunctionView(F&& f) + : call_(f ? CallFunPtr::type> : nullptr) { + f_.fun_ptr = reinterpret_cast(f); + } + + // Constructor that accepts nullptr. It creates an empty FunctionView. + template ::type>::value>::type* = nullptr> + FunctionView(F&& f) : call_(nullptr) {} + + // Default constructor. Creates an empty FunctionView. + FunctionView() : call_(nullptr) {} + + RetT operator()(ArgT... args) const { + RTC_DCHECK(call_); + return call_(f_, std::forward(args)...); + } + + // Returns true if we have a function, false if we don't (i.e., we're null). + explicit operator bool() const { return !!call_; } + + private: + union VoidUnion { + void* void_ptr; + void (*fun_ptr)(); + }; + + template + static RetT CallVoidPtr(VoidUnion vu, ArgT... args) { + return (*static_cast(vu.void_ptr))(std::forward(args)...); + } + template + static RetT CallFunPtr(VoidUnion vu, ArgT... args) { + return (reinterpret_cast::type>(vu.fun_ptr))( + std::forward(args)...); + } + + // A pointer to the callable thing, with type information erased. It's a + // union because we have to use separate types depending on if the callable + // thing is a function pointer or something else. + VoidUnion f_; + + // Pointer to a dispatch function that knows the type of the callable thing + // that's stored in f_, and how to call it. A FunctionView object is empty + // (null) iff call_ is null. + RetT (*call_)(VoidUnion, ArgT...); +}; + +} // namespace rtc + +#endif // API_FUNCTION_VIEW_H_ diff --git a/rtc_base/function_view_unittest.cc b/api/function_view_unittest.cc similarity index 95% rename from rtc_base/function_view_unittest.cc rename to api/function_view_unittest.cc index d91bac02e2..3abf0e3f68 100644 --- a/rtc_base/function_view_unittest.cc +++ b/api/function_view_unittest.cc @@ -11,7 +11,7 @@ #include #include -#include "rtc_base/function_view.h" +#include "api/function_view.h" #include "test/gtest.h" namespace rtc { @@ -97,8 +97,7 @@ TEST(FunctionViewTest, CopyConstructor) { TEST(FunctionViewTest, MoveConstructorIsCopy) { auto f17 = [] { return 17; }; rtc::FunctionView fv1(f17); - // NOLINTNEXTLINE(performance-move-const-arg) - rtc::FunctionView fv2(std::move(fv1)); + rtc::FunctionView fv2(std::move(fv1)); // NOLINT EXPECT_EQ(17, fv1()); EXPECT_EQ(17, fv2()); } @@ -122,7 +121,7 @@ TEST(FunctionViewTest, MoveAssignmentIsCopy) { rtc::FunctionView fv2(f23); EXPECT_EQ(17, fv1()); EXPECT_EQ(23, fv2()); - fv2 = std::move(fv1); // NOLINT(performance-move-const-arg) + fv2 = std::move(fv1); // NOLINT EXPECT_EQ(17, fv1()); EXPECT_EQ(17, fv2()); } diff --git a/audio/BUILD.gn b/audio/BUILD.gn index ce6525ed13..4fdb1f61ad 100644 --- a/audio/BUILD.gn +++ b/audio/BUILD.gn @@ -40,6 +40,7 @@ rtc_static_library("audio") { deps = [ "../api:array_view", "../api:call_api", + "../api:function_view", "../api:libjingle_peerconnection_api", "../api:rtp_headers", "../api:scoped_refptr", diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc index 6d16a48bbd..e9b89bee20 100644 --- a/audio/audio_send_stream.cc +++ b/audio/audio_send_stream.cc @@ -20,6 +20,7 @@ #include "api/audio_codecs/audio_format.h" #include "api/call/transport.h" #include "api/crypto/frame_encryptor_interface.h" +#include "api/function_view.h" #include "audio/audio_state.h" #include "audio/channel_send.h" #include "audio/conversion.h" @@ -33,7 +34,6 @@ #include "modules/audio_processing/include/audio_processing.h" #include "rtc_base/checks.h" #include "rtc_base/event.h" -#include "rtc_base/function_view.h" #include "rtc_base/logging.h" #include "rtc_base/strings/audio_format_to_string.h" #include "rtc_base/task_queue.h" diff --git a/audio/channel_send.h b/audio/channel_send.h index f6acd88f29..761e4b2566 100644 --- a/audio/channel_send.h +++ b/audio/channel_send.h @@ -18,11 +18,11 @@ #include "api/audio/audio_frame.h" #include "api/audio_codecs/audio_encoder.h" #include "api/crypto/crypto_options.h" +#include "api/function_view.h" #include "api/media_transport_interface.h" #include "api/task_queue/task_queue_factory.h" #include "modules/rtp_rtcp/include/rtp_rtcp.h" #include "modules/rtp_rtcp/source/rtp_sender_audio.h" -#include "rtc_base/function_view.h" namespace webrtc { diff --git a/logging/BUILD.gn b/logging/BUILD.gn index 6c072dd195..8edfe3cdd2 100644 --- a/logging/BUILD.gn +++ b/logging/BUILD.gn @@ -328,6 +328,7 @@ if (rtc_enable_protobuf) { ":rtc_event_log_impl_encoder", ":rtc_event_log_proto", ":rtc_stream_config", + "../api:function_view", "../api:libjingle_peerconnection_api", "../api:rtp_headers", "../api/units:data_rate", diff --git a/logging/rtc_event_log/rtc_event_processor.h b/logging/rtc_event_log/rtc_event_processor.h index dbbdff6730..4657f6ec15 100644 --- a/logging/rtc_event_log/rtc_event_processor.h +++ b/logging/rtc_event_log/rtc_event_processor.h @@ -18,8 +18,8 @@ #include #include "absl/memory/memory.h" +#include "api/function_view.h" #include "rtc_base/checks.h" -#include "rtc_base/function_view.h" namespace webrtc { diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn index 8575e71fb3..b19dcc049a 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -45,6 +45,7 @@ rtc_static_library("audio_coding") { "..:module_api", "..:module_api_public", "../../api:array_view", + "../../api:function_view", "../../api/audio:audio_frame_api", "../../api/audio_codecs:audio_codecs_api", "../../common_audio", diff --git a/modules/audio_coding/include/audio_coding_module.h b/modules/audio_coding/include/audio_coding_module.h index 0621473b68..8e0c4d55ed 100644 --- a/modules/audio_coding/include/audio_coding_module.h +++ b/modules/audio_coding/include/audio_coding_module.h @@ -19,9 +19,9 @@ #include "absl/types/optional.h" #include "api/audio_codecs/audio_decoder_factory.h" #include "api/audio_codecs/audio_encoder.h" +#include "api/function_view.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_coding/neteq/include/neteq.h" -#include "rtc_base/function_view.h" #include "system_wrappers/include/clock.h" namespace webrtc { diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn index f99c44dff9..d02406fccd 100644 --- a/modules/audio_processing/BUILD.gn +++ b/modules/audio_processing/BUILD.gn @@ -158,6 +158,7 @@ rtc_static_library("audio_processing") { ":noise_suppression_proxy", "../..:webrtc_common", "../../api:array_view", + "../../api:function_view", "../../api/audio:aec3_config", "../../api/audio:audio_frame_api", "../../api/audio:echo_control", diff --git a/modules/audio_processing/agc2/rnn_vad/BUILD.gn b/modules/audio_processing/agc2/rnn_vad/BUILD.gn index 3748a71b6b..221c3529ed 100644 --- a/modules/audio_processing/agc2/rnn_vad/BUILD.gn +++ b/modules/audio_processing/agc2/rnn_vad/BUILD.gn @@ -35,6 +35,7 @@ rtc_source_set("rnn_vad") { deps = [ "..:biquad_filter", "../../../../api:array_view", + "../../../../api:function_view", "../../../../common_audio/", "../../../../rtc_base:checks", "../../../../rtc_base:rtc_base_approved", diff --git a/modules/audio_processing/agc2/rnn_vad/spectral_features_internal.h b/modules/audio_processing/agc2/rnn_vad/spectral_features_internal.h index edfd18cc85..14ff56031f 100644 --- a/modules/audio_processing/agc2/rnn_vad/spectral_features_internal.h +++ b/modules/audio_processing/agc2/rnn_vad/spectral_features_internal.h @@ -16,8 +16,8 @@ #include #include "api/array_view.h" +#include "api/function_view.h" #include "modules/audio_processing/agc2/rnn_vad/common.h" -#include "rtc_base/function_view.h" namespace webrtc { namespace rnn_vad { diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h index 9b66c26e5e..f164407255 100644 --- a/modules/audio_processing/audio_processing_impl.h +++ b/modules/audio_processing/audio_processing_impl.h @@ -15,6 +15,7 @@ #include #include +#include "api/function_view.h" #include "modules/audio_processing/audio_buffer.h" #include "modules/audio_processing/include/aec_dump.h" #include "modules/audio_processing/include/audio_processing.h" @@ -22,7 +23,6 @@ #include "modules/audio_processing/render_queue_item_verifier.h" #include "modules/audio_processing/rms_level.h" #include "rtc_base/critical_section.h" -#include "rtc_base/function_view.h" #include "rtc_base/gtest_prod_util.h" #include "rtc_base/ignore_wundef.h" #include "rtc_base/swap_queue.h" diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn index 9e7f53c19e..57f7a343ed 100644 --- a/modules/desktop_capture/BUILD.gn +++ b/modules/desktop_capture/BUILD.gn @@ -47,6 +47,7 @@ if (rtc_include_tests) { sources = [] deps = [ + "../../api:function_view", "../../api:scoped_refptr", "../../rtc_base:checks", "//third_party/abseil-cpp/absl/memory", @@ -428,6 +429,7 @@ rtc_static_library("desktop_capture_generic") { deps = [ ":primitives", + "../../api:function_view", "../../api:refcountedbase", "../../api:scoped_refptr", "../../rtc_base", # TODO(kjellander): Cleanup in bugs.webrtc.org/3806. diff --git a/modules/desktop_capture/linux/window_list_utils.h b/modules/desktop_capture/linux/window_list_utils.h index 8c68106212..243680d34b 100644 --- a/modules/desktop_capture/linux/window_list_utils.h +++ b/modules/desktop_capture/linux/window_list_utils.h @@ -15,9 +15,9 @@ #include #include +#include "api/function_view.h" #include "modules/desktop_capture/desktop_geometry.h" #include "modules/desktop_capture/linux/x_atom_cache.h" -#include "rtc_base/function_view.h" namespace webrtc { diff --git a/modules/desktop_capture/mac/window_list_utils.h b/modules/desktop_capture/mac/window_list_utils.h index b54ca3d346..ea622c472b 100644 --- a/modules/desktop_capture/mac/window_list_utils.h +++ b/modules/desktop_capture/mac/window_list_utils.h @@ -13,11 +13,11 @@ #include +#include "api/function_view.h" #include "modules/desktop_capture/desktop_capture_types.h" #include "modules/desktop_capture/desktop_capturer.h" #include "modules/desktop_capture/desktop_geometry.h" #include "modules/desktop_capture/mac/desktop_configuration.h" -#include "rtc_base/function_view.h" namespace webrtc { diff --git a/modules/desktop_capture/screen_drawer_unittest.cc b/modules/desktop_capture/screen_drawer_unittest.cc index 2186ada3c5..0bb83767df 100644 --- a/modules/desktop_capture/screen_drawer_unittest.cc +++ b/modules/desktop_capture/screen_drawer_unittest.cc @@ -14,8 +14,8 @@ #include #include "absl/memory/memory.h" +#include "api/function_view.h" #include "rtc_base/checks.h" -#include "rtc_base/function_view.h" #include "rtc_base/logging.h" #include "rtc_base/platform_thread.h" #include "rtc_base/random.h" diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index ec84ed8c19..9fe7fdc7c9 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -91,6 +91,7 @@ rtc_source_set("rtp_rtcp_format") { "..:module_api_public", "../..:webrtc_common", "../../api:array_view", + "../../api:function_view", "../../api:libjingle_peerconnection_api", "../../api:rtp_headers", "../../api/audio_codecs:audio_codecs_api", diff --git a/modules/rtp_rtcp/source/rtcp_packet.h b/modules/rtp_rtcp/source/rtcp_packet.h index 94bf9f0823..d41afcb77c 100644 --- a/modules/rtp_rtcp/source/rtcp_packet.h +++ b/modules/rtp_rtcp/source/rtcp_packet.h @@ -15,8 +15,8 @@ #include #include "api/array_view.h" +#include "api/function_view.h" #include "rtc_base/buffer.h" -#include "rtc_base/function_view.h" namespace webrtc { namespace rtcp { diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 280e077096..2b4d111e89 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -355,6 +355,7 @@ if (rtc_include_tests) { ] deps = [ ":pc_test_utils", + "../api:function_view", "../api:libjingle_peerconnection_api", "../api:rtc_stats_api", "../api:scoped_refptr", @@ -490,6 +491,7 @@ if (rtc_include_tests) { "../api:create_peerconnection_factory", "../api:fake_frame_decryptor", "../api:fake_frame_encryptor", + "../api:function_view", "../api:libjingle_logging_api", "../api:libjingle_peerconnection_api", "../api:loopback_media_transport", diff --git a/pc/peer_connection_wrapper.cc b/pc/peer_connection_wrapper.cc index 6bfb59f935..74089f6f96 100644 --- a/pc/peer_connection_wrapper.cc +++ b/pc/peer_connection_wrapper.cc @@ -16,11 +16,11 @@ #include #include +#include "api/function_view.h" #include "api/set_remote_description_observer_interface.h" #include "pc/sdp_utils.h" #include "pc/test/fake_video_track_source.h" #include "rtc_base/checks.h" -#include "rtc_base/function_view.h" #include "rtc_base/gunit.h" #include "rtc_base/logging.h" #include "rtc_base/ref_counted_object.h" diff --git a/pc/peer_connection_wrapper.h b/pc/peer_connection_wrapper.h index d7f10b40db..fafee24b6f 100644 --- a/pc/peer_connection_wrapper.h +++ b/pc/peer_connection_wrapper.h @@ -16,6 +16,7 @@ #include #include "api/data_channel_interface.h" +#include "api/function_view.h" #include "api/jsep.h" #include "api/media_stream_interface.h" #include "api/media_types.h" @@ -26,7 +27,6 @@ #include "api/scoped_refptr.h" #include "api/stats/rtc_stats_report.h" #include "pc/test/mock_peer_connection_observers.h" -#include "rtc_base/function_view.h" namespace webrtc { diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index f4e9f7686e..5882ade663 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -79,6 +79,7 @@ rtc_source_set("rtc_base_approved") { ":safe_minmax", ":type_traits", "../api:array_view", + "../api:function_view", "../api:scoped_refptr", "../system_wrappers:field_trial", "experiments:field_trial_parser", @@ -1209,7 +1210,6 @@ if (rtc_include_tests) { "critical_section_unittest.cc", "event_tracer_unittest.cc", "event_unittest.cc", - "function_view_unittest.cc", "logging_unittest.cc", "numerics/histogram_percentile_counter_unittest.cc", "numerics/mod_ops_unittest.cc", diff --git a/rtc_base/function_view.h b/rtc_base/function_view.h index 91ab88e4fa..f465cc8f28 100644 --- a/rtc_base/function_view.h +++ b/rtc_base/function_view.h @@ -11,120 +11,9 @@ #ifndef RTC_BASE_FUNCTION_VIEW_H_ #define RTC_BASE_FUNCTION_VIEW_H_ -#include -#include +// This header is deprecated and will be removed. Please use the one, +// that is specified below instead. -#include "rtc_base/checks.h" - -// Just like std::function, FunctionView will wrap any callable and hide its -// actual type, exposing only its signature. But unlike std::function, -// FunctionView doesn't own its callable---it just points to it. Thus, it's a -// good choice mainly as a function argument when the callable argument will -// not be called again once the function has returned. -// -// Its constructors are implicit, so that callers won't have to convert lambdas -// and other callables to FunctionView explicitly. This is -// safe because FunctionView is only a reference to the real callable. -// -// Example use: -// -// void SomeFunction(rtc::FunctionView index_transform); -// ... -// SomeFunction([](int i) { return 2 * i + 1; }); -// -// Note: FunctionView is tiny (essentially just two pointers) and trivially -// copyable, so it's probably cheaper to pass it by value than by const -// reference. - -namespace rtc { - -template -class FunctionView; // Undefined. - -template -class FunctionView final { - public: - // Constructor for lambdas and other callables; it accepts every type of - // argument except those noted in its enable_if call. - template < - typename F, - typename std::enable_if< - // Not for function pointers; we have another constructor for that - // below. - !std::is_function::type>::type>::value && - - // Not for nullptr; we have another constructor for that below. - !std::is_same::type>::value && - - // Not for FunctionView objects; we have another constructor for that - // (the implicitly declared copy constructor). - !std::is_same::type>::type>::value>::type* = nullptr> - FunctionView(F&& f) - : call_(CallVoidPtr::type>) { - f_.void_ptr = &f; - } - - // Constructor that accepts function pointers. If the argument is null, the - // result is an empty FunctionView. - template < - typename F, - typename std::enable_if::type>::type>::value>::type* = - nullptr> - FunctionView(F&& f) - : call_(f ? CallFunPtr::type> : nullptr) { - f_.fun_ptr = reinterpret_cast(f); - } - - // Constructor that accepts nullptr. It creates an empty FunctionView. - template ::type>::value>::type* = nullptr> - FunctionView(F&& f) : call_(nullptr) {} - - // Default constructor. Creates an empty FunctionView. - FunctionView() : call_(nullptr) {} - - RetT operator()(ArgT... args) const { - RTC_DCHECK(call_); - return call_(f_, std::forward(args)...); - } - - // Returns true if we have a function, false if we don't (i.e., we're null). - explicit operator bool() const { return !!call_; } - - private: - union VoidUnion { - void* void_ptr; - void (*fun_ptr)(); - }; - - template - static RetT CallVoidPtr(VoidUnion vu, ArgT... args) { - return (*static_cast(vu.void_ptr))(std::forward(args)...); - } - template - static RetT CallFunPtr(VoidUnion vu, ArgT... args) { - return (reinterpret_cast::type>(vu.fun_ptr))( - std::forward(args)...); - } - - // A pointer to the callable thing, with type information erased. It's a - // union because we have to use separate types depending on if the callable - // thing is a function pointer or something else. - VoidUnion f_; - - // Pointer to a dispatch function that knows the type of the callable thing - // that's stored in f_, and how to call it. A FunctionView object is empty - // (null) iff call_ is null. - RetT (*call_)(VoidUnion, ArgT...); -}; - -} // namespace rtc +#include "api/function_view.h" #endif // RTC_BASE_FUNCTION_VIEW_H_ diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn index 6269f4c5f9..609598ffcd 100644 --- a/rtc_tools/BUILD.gn +++ b/rtc_tools/BUILD.gn @@ -299,6 +299,7 @@ if (!build_with_chromium) { deps = [ ":chart_proto", "../:webrtc_common", + "../api:function_view", # TODO(kwiberg): Remove this dependency. "../api/audio_codecs:audio_codecs_api", diff --git a/rtc_tools/event_log_visualizer/analyzer.cc b/rtc_tools/event_log_visualizer/analyzer.cc index 2023336235..304b2aa1c0 100644 --- a/rtc_tools/event_log_visualizer/analyzer.cc +++ b/rtc_tools/event_log_visualizer/analyzer.cc @@ -19,6 +19,7 @@ #include "absl/memory/memory.h" #include "absl/strings/string_view.h" +#include "api/function_view.h" #include "api/transport/field_trial_based_config.h" #include "api/transport/goog_cc_factory.h" #include "call/audio_receive_stream.h" @@ -54,7 +55,6 @@ #include "modules/rtp_rtcp/source/rtp_utility.h" #include "rtc_base/checks.h" #include "rtc_base/format_macros.h" -#include "rtc_base/function_view.h" #include "rtc_base/logging.h" #include "rtc_base/numerics/sequence_number_util.h" #include "rtc_base/rate_statistics.h" diff --git a/test/pc/e2e/api/BUILD.gn b/test/pc/e2e/api/BUILD.gn index 24c1cbf81c..9f5a83503f 100644 --- a/test/pc/e2e/api/BUILD.gn +++ b/test/pc/e2e/api/BUILD.gn @@ -58,6 +58,7 @@ rtc_source_set("peer_connection_quality_test_fixture_api") { ":video_quality_analyzer_api", "../../../../api:callfactory_api", "../../../../api:fec_controller_api", + "../../../../api:function_view", "../../../../api:libjingle_peerconnection_api", "../../../../api:simulated_network_api", "../../../../api/transport:network_control", diff --git a/test/pc/e2e/api/peerconnection_quality_test_fixture.h b/test/pc/e2e/api/peerconnection_quality_test_fixture.h index 6afaf093c2..586212517d 100644 --- a/test/pc/e2e/api/peerconnection_quality_test_fixture.h +++ b/test/pc/e2e/api/peerconnection_quality_test_fixture.h @@ -18,6 +18,7 @@ #include "api/async_resolver_factory.h" #include "api/call/call_factory_interface.h" #include "api/fec_controller.h" +#include "api/function_view.h" #include "api/media_transport_interface.h" #include "api/peer_connection_interface.h" #include "api/test/simulated_network.h" @@ -27,7 +28,6 @@ #include "api/video_codecs/video_encoder.h" #include "api/video_codecs/video_encoder_factory.h" #include "logging/rtc_event_log/rtc_event_log_factory_interface.h" -#include "rtc_base/function_view.h" #include "rtc_base/network.h" #include "rtc_base/rtc_certificate_generator.h" #include "rtc_base/ssl_certificate.h"