From f4e3e2b83f577d8553e629d20ee49f5d783541e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Tue, 2 Feb 2021 11:37:39 +0100 Subject: [PATCH] Delete rtc::Callback0 and friends. Replaced with std::function. Bug: webrtc:6424 Change-Id: Iacc43822cb854ddde3cb1e5ddd863676cb07510a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205005 Reviewed-by: Philip Eliasson Reviewed-by: Tommi Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#33281} --- common_video/include/video_frame_buffer.h | 12 +- common_video/video_frame_buffer.cc | 20 +- media/base/media_channel.h | 1 - .../codecs/h264/h264_decoder_impl.cc | 10 +- .../multiplex/multiplex_decoder_adapter.cc | 1 - .../multiplex/multiplex_encoder_adapter.cc | 11 +- .../test/multiplex_adapter_unittest.cc | 8 +- .../codecs/vp9/libvpx_vp9_decoder.cc | 9 +- p2p/stunprober/stun_prober.h | 3 +- pc/video_rtp_track_source.h | 1 - rtc_base/BUILD.gn | 3 - rtc_base/callback.h | 250 ------------------ rtc_base/callback.h.pump | 104 -------- rtc_base/callback_unittest.cc | 128 --------- rtc_base/keep_ref_until_done.h | 36 --- sdk/android/native_api/video/video_source.cc | 1 + sdk/android/src/jni/pc/video.cc | 1 + sdk/android/src/jni/video_frame.cc | 2 +- sdk/android/src/jni/video_frame.h | 1 - test/frame_generator.cc | 4 +- 20 files changed, 42 insertions(+), 564 deletions(-) delete mode 100644 rtc_base/callback.h delete mode 100644 rtc_base/callback.h.pump delete mode 100644 rtc_base/callback_unittest.cc delete mode 100644 rtc_base/keep_ref_until_done.h diff --git a/common_video/include/video_frame_buffer.h b/common_video/include/video_frame_buffer.h index bc70f34ec8..593464abe4 100644 --- a/common_video/include/video_frame_buffer.h +++ b/common_video/include/video_frame_buffer.h @@ -12,10 +12,10 @@ #define COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ #include +#include #include "api/scoped_refptr.h" #include "api/video/video_frame_buffer.h" -#include "rtc_base/callback.h" #include "rtc_base/ref_counted_object.h" namespace webrtc { @@ -29,7 +29,7 @@ rtc::scoped_refptr WrapI420Buffer( int u_stride, const uint8_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used); + std::function no_longer_used); rtc::scoped_refptr WrapI444Buffer( int width, @@ -40,7 +40,7 @@ rtc::scoped_refptr WrapI444Buffer( int u_stride, const uint8_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used); + std::function no_longer_used); rtc::scoped_refptr WrapI420ABuffer( int width, @@ -53,7 +53,7 @@ rtc::scoped_refptr WrapI420ABuffer( int v_stride, const uint8_t* a_plane, int a_stride, - const rtc::Callback0& no_longer_used); + std::function no_longer_used); rtc::scoped_refptr WrapYuvBuffer( VideoFrameBuffer::Type type, @@ -65,7 +65,7 @@ rtc::scoped_refptr WrapYuvBuffer( int u_stride, const uint8_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used); + std::function no_longer_used); rtc::scoped_refptr WrapI010Buffer( int width, @@ -76,7 +76,7 @@ rtc::scoped_refptr WrapI010Buffer( int u_stride, const uint16_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used); + std::function no_longer_used); } // namespace webrtc diff --git a/common_video/video_frame_buffer.cc b/common_video/video_frame_buffer.cc index 8bbe7c8728..4358db5e76 100644 --- a/common_video/video_frame_buffer.cc +++ b/common_video/video_frame_buffer.cc @@ -30,7 +30,7 @@ class WrappedYuvBuffer : public Base { int u_stride, const uint8_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used) + std::function no_longer_used) : width_(width), height_(height), y_plane_(y_plane), @@ -70,7 +70,7 @@ class WrappedYuvBuffer : public Base { const int y_stride_; const int u_stride_; const int v_stride_; - rtc::Callback0 no_longer_used_cb_; + std::function no_longer_used_cb_; }; // Template to implement a wrapped buffer for a I4??BufferInterface. @@ -87,7 +87,7 @@ class WrappedYuvaBuffer : public WrappedYuvBuffer { int v_stride, const uint8_t* a_plane, int a_stride, - const rtc::Callback0& no_longer_used) + std::function no_longer_used) : WrappedYuvBuffer(width, height, y_plane, @@ -136,7 +136,7 @@ class WrappedYuv16BBuffer : public Base { int u_stride, const uint16_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used) + std::function no_longer_used) : width_(width), height_(height), y_plane_(y_plane), @@ -176,7 +176,7 @@ class WrappedYuv16BBuffer : public Base { const int y_stride_; const int u_stride_; const int v_stride_; - rtc::Callback0 no_longer_used_cb_; + std::function no_longer_used_cb_; }; class I010BufferBase : public I010BufferInterface { @@ -206,7 +206,7 @@ rtc::scoped_refptr WrapI420Buffer( int u_stride, const uint8_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used) { + std::function no_longer_used) { return rtc::scoped_refptr( new rtc::RefCountedObject>( width, height, y_plane, y_stride, u_plane, u_stride, v_plane, @@ -224,7 +224,7 @@ rtc::scoped_refptr WrapI420ABuffer( int v_stride, const uint8_t* a_plane, int a_stride, - const rtc::Callback0& no_longer_used) { + std::function no_longer_used) { return rtc::scoped_refptr( new rtc::RefCountedObject>( width, height, y_plane, y_stride, u_plane, u_stride, v_plane, @@ -240,7 +240,7 @@ rtc::scoped_refptr WrapI444Buffer( int u_stride, const uint8_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used) { + std::function no_longer_used) { return rtc::scoped_refptr( new rtc::RefCountedObject>( width, height, y_plane, y_stride, u_plane, u_stride, v_plane, @@ -257,7 +257,7 @@ rtc::scoped_refptr WrapYuvBuffer( int u_stride, const uint8_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used) { + std::function no_longer_used) { switch (type) { case VideoFrameBuffer::Type::kI420: return WrapI420Buffer(width, height, y_plane, y_stride, u_plane, u_stride, @@ -279,7 +279,7 @@ rtc::scoped_refptr WrapI010Buffer( int u_stride, const uint16_t* v_plane, int v_stride, - const rtc::Callback0& no_longer_used) { + std::function no_longer_used) { return rtc::scoped_refptr( new rtc::RefCountedObject>( width, height, y_plane, y_stride, u_plane, u_stride, v_plane, diff --git a/media/base/media_channel.h b/media/base/media_channel.h index 95e4cc7aa0..79b3c2bcc1 100644 --- a/media/base/media_channel.h +++ b/media/base/media_channel.h @@ -43,7 +43,6 @@ #include "modules/rtp_rtcp/include/report_block_data.h" #include "rtc_base/async_packet_socket.h" #include "rtc_base/buffer.h" -#include "rtc_base/callback.h" #include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/dscp.h" #include "rtc_base/logging.h" diff --git a/modules/video_coding/codecs/h264/h264_decoder_impl.cc b/modules/video_coding/codecs/h264/h264_decoder_impl.cc index 8c7a39b609..6f37b52fd8 100644 --- a/modules/video_coding/codecs/h264/h264_decoder_impl.cc +++ b/modules/video_coding/codecs/h264/h264_decoder_impl.cc @@ -32,7 +32,6 @@ extern "C" { #include "common_video/include/video_frame_buffer.h" #include "modules/video_coding/codecs/h264/h264_color_space.h" #include "rtc_base/checks.h" -#include "rtc_base/keep_ref_until_done.h" #include "rtc_base/logging.h" #include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/metrics.h" @@ -302,8 +301,9 @@ int32_t H264DecoderImpl::Decode(const EncodedImage& input_image, VideoFrame* input_frame = static_cast(av_buffer_get_opaque(av_frame_->buf[0])); RTC_DCHECK(input_frame); - const webrtc::I420BufferInterface* i420_buffer = - input_frame->video_frame_buffer()->GetI420(); + rtc::scoped_refptr frame_buffer = + input_frame->video_frame_buffer(); + const webrtc::I420BufferInterface* i420_buffer = frame_buffer->GetI420(); // When needed, FFmpeg applies cropping by moving plane pointers and adjusting // frame width/height. Ensure that cropped buffers lie within the allocated @@ -330,7 +330,9 @@ int32_t H264DecoderImpl::Decode(const EncodedImage& input_image, av_frame_->width, av_frame_->height, av_frame_->data[kYPlaneIndex], av_frame_->linesize[kYPlaneIndex], av_frame_->data[kUPlaneIndex], av_frame_->linesize[kUPlaneIndex], av_frame_->data[kVPlaneIndex], - av_frame_->linesize[kVPlaneIndex], rtc::KeepRefUntilDone(i420_buffer)); + av_frame_->linesize[kVPlaneIndex], + // To keep reference alive. + [frame_buffer] {}); if (preferred_output_format_ == VideoFrameBuffer::Type::kNV12) { const I420BufferInterface* cropped_i420 = cropped_buffer->GetI420(); diff --git a/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc b/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc index 426a9f80d1..8d23c6d858 100644 --- a/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc +++ b/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc @@ -17,7 +17,6 @@ #include "common_video/libyuv/include/webrtc_libyuv.h" #include "modules/video_coding/codecs/multiplex/include/augmented_video_frame_buffer.h" #include "modules/video_coding/codecs/multiplex/multiplex_encoded_image_packer.h" -#include "rtc_base/keep_ref_until_done.h" #include "rtc_base/logging.h" namespace webrtc { diff --git a/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc b/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc index 0620a788e3..040fe9cce5 100644 --- a/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc +++ b/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc @@ -18,7 +18,6 @@ #include "common_video/libyuv/include/webrtc_libyuv.h" #include "media/base/video_common.h" #include "modules/video_coding/codecs/multiplex/include/augmented_video_frame_buffer.h" -#include "rtc_base/keep_ref_until_done.h" #include "rtc_base/logging.h" namespace webrtc { @@ -204,16 +203,18 @@ int MultiplexEncoderAdapter::Encode( return rv; // Encode AXX - const I420ABufferInterface* yuva_buffer = + rtc::scoped_refptr frame_buffer = supports_augmented_data_ - ? augmented_video_frame_buffer->GetVideoFrameBuffer()->GetI420A() - : input_image.video_frame_buffer()->GetI420A(); + ? augmented_video_frame_buffer->GetVideoFrameBuffer() + : input_image.video_frame_buffer(); + const I420ABufferInterface* yuva_buffer = frame_buffer->GetI420A(); rtc::scoped_refptr alpha_buffer = WrapI420Buffer(input_image.width(), input_image.height(), yuva_buffer->DataA(), yuva_buffer->StrideA(), multiplex_dummy_planes_.data(), yuva_buffer->StrideU(), multiplex_dummy_planes_.data(), yuva_buffer->StrideV(), - rtc::KeepRefUntilDone(input_image.video_frame_buffer())); + // To keep reference alive. + [frame_buffer] {}); VideoFrame alpha_image = VideoFrame::Builder() .set_video_frame_buffer(alpha_buffer) .set_timestamp_rtp(input_image.timestamp()) diff --git a/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc b/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc index 770d8b596c..2e7b0cb3c0 100644 --- a/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc +++ b/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc @@ -38,7 +38,6 @@ #include "modules/video_coding/codecs/vp9/include/vp9.h" #include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_error_codes.h" -#include "rtc_base/keep_ref_until_done.h" #include "rtc_base/ref_counted_object.h" #include "test/gmock.h" #include "test/gtest.h" @@ -112,7 +111,9 @@ class TestMultiplexAdapter : public VideoCodecUnitTest, yuv_buffer->width(), yuv_buffer->height(), yuv_buffer->DataY(), yuv_buffer->StrideY(), yuv_buffer->DataU(), yuv_buffer->StrideU(), yuv_buffer->DataV(), yuv_buffer->StrideV(), yuv_buffer->DataY(), - yuv_buffer->StrideY(), rtc::KeepRefUntilDone(yuv_buffer)); + yuv_buffer->StrideY(), + // To keep reference alive. + [yuv_buffer] {}); return std::make_unique(VideoFrame::Builder() .set_video_frame_buffer(yuva_buffer) .set_timestamp_rtp(123) @@ -168,8 +169,7 @@ class TestMultiplexAdapter : public VideoCodecUnitTest, rtc::scoped_refptr axx_buffer = WrapI420Buffer( yuva_buffer->width(), yuva_buffer->height(), yuva_buffer->DataA(), yuva_buffer->StrideA(), yuva_buffer->DataU(), yuva_buffer->StrideU(), - yuva_buffer->DataV(), yuva_buffer->StrideV(), - rtc::KeepRefUntilDone(video_frame_buffer)); + yuva_buffer->DataV(), yuva_buffer->StrideV(), [video_frame_buffer] {}); return std::make_unique(VideoFrame::Builder() .set_video_frame_buffer(axx_buffer) .set_timestamp_rtp(123) diff --git a/modules/video_coding/codecs/vp9/libvpx_vp9_decoder.cc b/modules/video_coding/codecs/vp9/libvpx_vp9_decoder.cc index 0a99c6a46e..3500ef5919 100644 --- a/modules/video_coding/codecs/vp9/libvpx_vp9_decoder.cc +++ b/modules/video_coding/codecs/vp9/libvpx_vp9_decoder.cc @@ -22,7 +22,6 @@ #include "common_video/include/video_frame_buffer.h" #include "modules/video_coding/utility/vp9_uncompressed_header_parser.h" #include "rtc_base/checks.h" -#include "rtc_base/keep_ref_until_done.h" #include "rtc_base/logging.h" #include "third_party/libyuv/include/libyuv/convert.h" #include "vpx/vp8dx.h" @@ -277,7 +276,7 @@ int LibvpxVp9Decoder::ReturnFrame( // This buffer contains all of |img|'s image data, a reference counted // Vp9FrameBuffer. (libvpx is done with the buffers after a few // vpx_codec_decode calls or vpx_codec_destroy). - Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = + rtc::scoped_refptr img_buffer = static_cast(img->fb_priv); // The buffer can be used directly by the VideoFrame (without copy) by @@ -312,7 +311,7 @@ int LibvpxVp9Decoder::ReturnFrame( // WrappedI420Buffer's mechanism for allowing the release of its // frame buffer is through a callback function. This is where we // should release |img_buffer|. - rtc::KeepRefUntilDone(img_buffer)); + [img_buffer] {}); } } else if (img->fmt == VPX_IMG_FMT_I444) { img_wrapped_buffer = WrapI444Buffer( @@ -323,7 +322,7 @@ int LibvpxVp9Decoder::ReturnFrame( // WrappedI444Buffer's mechanism for allowing the release of its // frame buffer is through a callback function. This is where we // should release |img_buffer|. - rtc::KeepRefUntilDone(img_buffer)); + [img_buffer] {}); } else { RTC_LOG(LS_ERROR) << "Unsupported pixel format produced by the decoder: " @@ -339,7 +338,7 @@ int LibvpxVp9Decoder::ReturnFrame( reinterpret_cast(img->planes[VPX_PLANE_U]), img->stride[VPX_PLANE_U] / 2, reinterpret_cast(img->planes[VPX_PLANE_V]), - img->stride[VPX_PLANE_V] / 2, rtc::KeepRefUntilDone(img_buffer)); + img->stride[VPX_PLANE_V] / 2, [img_buffer] {}); break; default: RTC_LOG(LS_ERROR) << "Unsupported bit depth produced by the decoder: " diff --git a/p2p/stunprober/stun_prober.h b/p2p/stunprober/stun_prober.h index 0661a66349..4153fd6892 100644 --- a/p2p/stunprober/stun_prober.h +++ b/p2p/stunprober/stun_prober.h @@ -18,7 +18,6 @@ #include "api/sequence_checker.h" #include "rtc_base/async_invoker.h" #include "rtc_base/byte_buffer.h" -#include "rtc_base/callback.h" #include "rtc_base/constructor_magic.h" #include "rtc_base/ip_address.h" #include "rtc_base/network.h" @@ -40,7 +39,7 @@ class StunProber; static const int kMaxUdpBufferSize = 1200; -typedef rtc::Callback2 AsyncCallback; +typedef std::function AsyncCallback; enum NatType { NATTYPE_INVALID, diff --git a/pc/video_rtp_track_source.h b/pc/video_rtp_track_source.h index 3d734e06f1..47b7bc9eef 100644 --- a/pc/video_rtp_track_source.h +++ b/pc/video_rtp_track_source.h @@ -20,7 +20,6 @@ #include "api/video/video_source_interface.h" #include "media/base/video_broadcaster.h" #include "pc/video_track_source.h" -#include "rtc_base/callback.h" #include "rtc_base/constructor_magic.h" #include "rtc_base/synchronization/mutex.h" #include "rtc_base/system/no_unique_address.h" diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index b017d83f1c..49c73a1b47 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -972,7 +972,6 @@ rtc_library("rtc_base") { "helpers.h", "http_common.cc", "http_common.h", - "keep_ref_until_done.h", "mdns_responder_interface.h", "message_digest.cc", "message_digest.h", @@ -1043,7 +1042,6 @@ rtc_library("rtc_base") { include_dirs = [ "../../boringssl/src/include" ] } else { sources += [ - "callback.h", "log_sinks.cc", "log_sinks.h", "rolling_accumulator.h", @@ -1484,7 +1482,6 @@ if (rtc_include_tests) { defines = [] sources = [ - "callback_unittest.cc", "crc32_unittest.cc", "data_rate_limiter_unittest.cc", "fake_clock_unittest.cc", diff --git a/rtc_base/callback.h b/rtc_base/callback.h deleted file mode 100644 index 47512214e3..0000000000 --- a/rtc_base/callback.h +++ /dev/null @@ -1,250 +0,0 @@ -// This file was GENERATED by command: -// pump.py callback.h.pump -// DO NOT EDIT BY HAND!!! - -/* - * Copyright 2012 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. - */ - -// To generate callback.h from callback.h.pump, execute: -// ../third_party/googletest/src/googletest/scripts/pump.py callback.h.pump - -// Callbacks are callable object containers. They can hold a function pointer -// or a function object and behave like a value type. Internally, data is -// reference-counted, making copies and pass-by-value inexpensive. -// -// Callbacks are typed using template arguments. The format is: -// CallbackN -// where N is the number of arguments supplied to the callable object. -// Callbacks are invoked using operator(), just like a function or a function -// object. Default-constructed callbacks are "empty," and executing an empty -// callback does nothing. A callback can be made empty by assigning it from -// a default-constructed callback. -// -// Callbacks are similar in purpose to std::function (which isn't available on -// all platforms we support) and a lightweight alternative to sigslots. Since -// they effectively hide the type of the object they call, they're useful in -// breaking dependencies between objects that need to interact with one another. -// Notably, they can hold the results of Bind(), std::bind*, etc, without -// needing -// to know the resulting object type of those calls. -// -// Sigslots, on the other hand, provide a fuller feature set, such as multiple -// subscriptions to a signal, optional thread-safety, and lifetime tracking of -// slots. When these features are needed, choose sigslots. -// -// Example: -// int sqr(int x) { return x * x; } -// struct AddK { -// int k; -// int operator()(int x) const { return x + k; } -// } add_k = {5}; -// -// Callback1 my_callback; -// cout << my_callback.empty() << endl; // true -// -// my_callback = Callback1(&sqr); -// cout << my_callback.empty() << endl; // false -// cout << my_callback(3) << endl; // 9 -// -// my_callback = Callback1(add_k); -// cout << my_callback(10) << endl; // 15 -// -// my_callback = Callback1(); -// cout << my_callback.empty() << endl; // true - -#ifndef RTC_BASE_CALLBACK_H_ -#define RTC_BASE_CALLBACK_H_ - -#include "api/scoped_refptr.h" -#include "rtc_base/ref_count.h" -#include "rtc_base/ref_counted_object.h" - -namespace rtc { - -template -class Callback0 { - public: - // Default copy operations are appropriate for this class. - Callback0() {} - template - Callback0(const T& functor) - : helper_(new RefCountedObject >(functor)) {} - R operator()() { - if (empty()) - return R(); - return helper_->Run(); - } - bool empty() const { return !helper_; } - - private: - struct Helper : RefCountInterface { - virtual ~Helper() {} - virtual R Run() = 0; - }; - template - struct HelperImpl : Helper { - explicit HelperImpl(const T& functor) : functor_(functor) {} - virtual R Run() { return functor_(); } - T functor_; - }; - scoped_refptr helper_; -}; - -template -class Callback1 { - public: - // Default copy operations are appropriate for this class. - Callback1() {} - template - Callback1(const T& functor) - : helper_(new RefCountedObject >(functor)) {} - R operator()(P1 p1) { - if (empty()) - return R(); - return helper_->Run(p1); - } - bool empty() const { return !helper_; } - - private: - struct Helper : RefCountInterface { - virtual ~Helper() {} - virtual R Run(P1 p1) = 0; - }; - template - struct HelperImpl : Helper { - explicit HelperImpl(const T& functor) : functor_(functor) {} - virtual R Run(P1 p1) { return functor_(p1); } - T functor_; - }; - scoped_refptr helper_; -}; - -template -class Callback2 { - public: - // Default copy operations are appropriate for this class. - Callback2() {} - template - Callback2(const T& functor) - : helper_(new RefCountedObject >(functor)) {} - R operator()(P1 p1, P2 p2) { - if (empty()) - return R(); - return helper_->Run(p1, p2); - } - bool empty() const { return !helper_; } - - private: - struct Helper : RefCountInterface { - virtual ~Helper() {} - virtual R Run(P1 p1, P2 p2) = 0; - }; - template - struct HelperImpl : Helper { - explicit HelperImpl(const T& functor) : functor_(functor) {} - virtual R Run(P1 p1, P2 p2) { return functor_(p1, p2); } - T functor_; - }; - scoped_refptr helper_; -}; - -template -class Callback3 { - public: - // Default copy operations are appropriate for this class. - Callback3() {} - template - Callback3(const T& functor) - : helper_(new RefCountedObject >(functor)) {} - R operator()(P1 p1, P2 p2, P3 p3) { - if (empty()) - return R(); - return helper_->Run(p1, p2, p3); - } - bool empty() const { return !helper_; } - - private: - struct Helper : RefCountInterface { - virtual ~Helper() {} - virtual R Run(P1 p1, P2 p2, P3 p3) = 0; - }; - template - struct HelperImpl : Helper { - explicit HelperImpl(const T& functor) : functor_(functor) {} - virtual R Run(P1 p1, P2 p2, P3 p3) { return functor_(p1, p2, p3); } - T functor_; - }; - scoped_refptr helper_; -}; - -template -class Callback4 { - public: - // Default copy operations are appropriate for this class. - Callback4() {} - template - Callback4(const T& functor) - : helper_(new RefCountedObject >(functor)) {} - R operator()(P1 p1, P2 p2, P3 p3, P4 p4) { - if (empty()) - return R(); - return helper_->Run(p1, p2, p3, p4); - } - bool empty() const { return !helper_; } - - private: - struct Helper : RefCountInterface { - virtual ~Helper() {} - virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4) = 0; - }; - template - struct HelperImpl : Helper { - explicit HelperImpl(const T& functor) : functor_(functor) {} - virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4) { - return functor_(p1, p2, p3, p4); - } - T functor_; - }; - scoped_refptr helper_; -}; - -template -class Callback5 { - public: - // Default copy operations are appropriate for this class. - Callback5() {} - template - Callback5(const T& functor) - : helper_(new RefCountedObject >(functor)) {} - R operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { - if (empty()) - return R(); - return helper_->Run(p1, p2, p3, p4, p5); - } - bool empty() const { return !helper_; } - - private: - struct Helper : RefCountInterface { - virtual ~Helper() {} - virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) = 0; - }; - template - struct HelperImpl : Helper { - explicit HelperImpl(const T& functor) : functor_(functor) {} - virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { - return functor_(p1, p2, p3, p4, p5); - } - T functor_; - }; - scoped_refptr helper_; -}; -} // namespace rtc - -#endif // RTC_BASE_CALLBACK_H_ diff --git a/rtc_base/callback.h.pump b/rtc_base/callback.h.pump deleted file mode 100644 index dc5fb3ae1d..0000000000 --- a/rtc_base/callback.h.pump +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2012 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. - */ - -// To generate callback.h from callback.h.pump, execute: -// ../third_party/googletest/src/googletest/scripts/pump.py callback.h.pump - -// Callbacks are callable object containers. They can hold a function pointer -// or a function object and behave like a value type. Internally, data is -// reference-counted, making copies and pass-by-value inexpensive. -// -// Callbacks are typed using template arguments. The format is: -// CallbackN -// where N is the number of arguments supplied to the callable object. -// Callbacks are invoked using operator(), just like a function or a function -// object. Default-constructed callbacks are "empty," and executing an empty -// callback does nothing. A callback can be made empty by assigning it from -// a default-constructed callback. -// -// Callbacks are similar in purpose to std::function (which isn't available on -// all platforms we support) and a lightweight alternative to sigslots. Since -// they effectively hide the type of the object they call, they're useful in -// breaking dependencies between objects that need to interact with one another. -// Notably, they can hold the results of Bind(), std::bind*, etc, without needing -// to know the resulting object type of those calls. -// -// Sigslots, on the other hand, provide a fuller feature set, such as multiple -// subscriptions to a signal, optional thread-safety, and lifetime tracking of -// slots. When these features are needed, choose sigslots. -// -// Example: -// int sqr(int x) { return x * x; } -// struct AddK { -// int k; -// int operator()(int x) const { return x + k; } -// } add_k = {5}; -// -// Callback1 my_callback; -// cout << my_callback.empty() << endl; // true -// -// my_callback = Callback1(&sqr); -// cout << my_callback.empty() << endl; // false -// cout << my_callback(3) << endl; // 9 -// -// my_callback = Callback1(add_k); -// cout << my_callback(10) << endl; // 15 -// -// my_callback = Callback1(); -// cout << my_callback.empty() << endl; // true - -#ifndef RTC_BASE_CALLBACK_H_ -#define RTC_BASE_CALLBACK_H_ - -#include "rtc_base/ref_count.h" -#include "rtc_base/ref_counted_object.h" -#include "api/scoped_refptr.h" - -namespace rtc { - -$var n = 5 -$range i 0..n -$for i [[ -$range j 1..i - -template -class Callback$i { - public: - // Default copy operations are appropriate for this class. - Callback$i() {} - template Callback$i(const T& functor) - : helper_(new RefCountedObject< HelperImpl >(functor)) {} - R operator()($for j , [[P$j p$j]]) { - if (empty()) - return R(); - return helper_->Run($for j , [[p$j]]); - } - bool empty() const { return !helper_; } - - private: - struct Helper : RefCountInterface { - virtual ~Helper() {} - virtual R Run($for j , [[P$j p$j]]) = 0; - }; - template struct HelperImpl : Helper { - explicit HelperImpl(const T& functor) : functor_(functor) {} - virtual R Run($for j , [[P$j p$j]]) { - return functor_($for j , [[p$j]]); - } - T functor_; - }; - scoped_refptr helper_; -}; - -]] -} // namespace rtc - -#endif // RTC_BASE_CALLBACK_H_ diff --git a/rtc_base/callback_unittest.cc b/rtc_base/callback_unittest.cc deleted file mode 100644 index 8f736bdbfd..0000000000 --- a/rtc_base/callback_unittest.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2004 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 "rtc_base/callback.h" - -#include "rtc_base/keep_ref_until_done.h" -#include "rtc_base/ref_count.h" -#include "test/gtest.h" - -namespace rtc { - -namespace { - -void f() {} -int g() { - return 42; -} -int h(int x) { - return x * x; -} -void i(int& x) { - x *= x; -} // NOLINT: Testing refs - -class RefCountedBindTester : public RefCountInterface { - public: - RefCountedBindTester() : count_(0) {} - void AddRef() const override { ++count_; } - RefCountReleaseStatus Release() const override { - --count_; - return count_ == 0 ? RefCountReleaseStatus::kDroppedLastRef - : RefCountReleaseStatus::kOtherRefsRemained; - } - int RefCount() const { return count_; } - - private: - mutable int count_; -}; - -} // namespace - -TEST(CallbackTest, VoidReturn) { - Callback0 cb; - EXPECT_TRUE(cb.empty()); - cb(); // Executing an empty callback should not crash. - cb = Callback0(&f); - EXPECT_FALSE(cb.empty()); - cb(); -} - -TEST(CallbackTest, IntReturn) { - Callback0 cb; - EXPECT_TRUE(cb.empty()); - cb = Callback0(&g); - EXPECT_FALSE(cb.empty()); - EXPECT_EQ(42, cb()); - EXPECT_EQ(42, cb()); -} - -TEST(CallbackTest, OneParam) { - Callback1 cb1(&h); - EXPECT_FALSE(cb1.empty()); - EXPECT_EQ(9, cb1(-3)); - EXPECT_EQ(100, cb1(10)); - - // Try clearing a callback. - cb1 = Callback1(); - EXPECT_TRUE(cb1.empty()); - - // Try a callback with a ref parameter. - Callback1 cb2(&i); - int x = 3; - cb2(x); - EXPECT_EQ(9, x); - cb2(x); - EXPECT_EQ(81, x); -} - -TEST(KeepRefUntilDoneTest, simple) { - RefCountedBindTester t; - EXPECT_EQ(0, t.RefCount()); - { - Callback0 cb = KeepRefUntilDone(&t); - EXPECT_EQ(1, t.RefCount()); - cb(); - EXPECT_EQ(1, t.RefCount()); - cb(); - EXPECT_EQ(1, t.RefCount()); - } - EXPECT_EQ(0, t.RefCount()); -} - -TEST(KeepRefUntilDoneTest, copy) { - RefCountedBindTester t; - EXPECT_EQ(0, t.RefCount()); - Callback0 cb2; - { - Callback0 cb = KeepRefUntilDone(&t); - EXPECT_EQ(1, t.RefCount()); - cb2 = cb; - } - EXPECT_EQ(1, t.RefCount()); - cb2 = Callback0(); - EXPECT_EQ(0, t.RefCount()); -} - -TEST(KeepRefUntilDoneTest, scopedref) { - RefCountedBindTester t; - EXPECT_EQ(0, t.RefCount()); - { - scoped_refptr t_scoped_ref(&t); - Callback0 cb = KeepRefUntilDone(t_scoped_ref); - t_scoped_ref = nullptr; - EXPECT_EQ(1, t.RefCount()); - cb(); - EXPECT_EQ(1, t.RefCount()); - } - EXPECT_EQ(0, t.RefCount()); -} - -} // namespace rtc diff --git a/rtc_base/keep_ref_until_done.h b/rtc_base/keep_ref_until_done.h deleted file mode 100644 index 5ae0ed1b21..0000000000 --- a/rtc_base/keep_ref_until_done.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2015 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 RTC_BASE_KEEP_REF_UNTIL_DONE_H_ -#define RTC_BASE_KEEP_REF_UNTIL_DONE_H_ - -#include "api/scoped_refptr.h" -#include "rtc_base/callback.h" - -namespace rtc { - -// KeepRefUntilDone keeps a reference to |object| until the returned -// callback goes out of scope. If the returned callback is copied, the -// reference will be released when the last callback goes out of scope. -template -static inline Callback0 KeepRefUntilDone(ObjectT* object) { - scoped_refptr p(object); - return [p] {}; -} - -template -static inline Callback0 KeepRefUntilDone( - const scoped_refptr& object) { - return [object] {}; -} - -} // namespace rtc - -#endif // RTC_BASE_KEEP_REF_UNTIL_DONE_H_ diff --git a/sdk/android/native_api/video/video_source.cc b/sdk/android/native_api/video/video_source.cc index 1f4bc4dead..56a56722eb 100644 --- a/sdk/android/native_api/video/video_source.cc +++ b/sdk/android/native_api/video/video_source.cc @@ -10,6 +10,7 @@ #include "sdk/android/native_api/video/video_source.h" +#include "rtc_base/ref_counted_object.h" #include "sdk/android/src/jni/android_video_track_source.h" #include "sdk/android/src/jni/native_capturer_observer.h" diff --git a/sdk/android/src/jni/pc/video.cc b/sdk/android/src/jni/pc/video.cc index 605258436e..513a0059f2 100644 --- a/sdk/android/src/jni/pc/video.cc +++ b/sdk/android/src/jni/pc/video.cc @@ -16,6 +16,7 @@ #include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_encoder_factory.h" #include "rtc_base/logging.h" +#include "rtc_base/ref_counted_object.h" #include "sdk/android/native_api/jni/java_types.h" #include "sdk/android/src/jni/android_video_track_source.h" #include "sdk/android/src/jni/video_decoder_factory_wrapper.h" diff --git a/sdk/android/src/jni/video_frame.cc b/sdk/android/src/jni/video_frame.cc index be2df56e70..c92561afc2 100644 --- a/sdk/android/src/jni/video_frame.cc +++ b/sdk/android/src/jni/video_frame.cc @@ -15,8 +15,8 @@ #include "api/scoped_refptr.h" #include "common_video/include/video_frame_buffer.h" #include "rtc_base/checks.h" -#include "rtc_base/keep_ref_until_done.h" #include "rtc_base/logging.h" +#include "rtc_base/ref_counted_object.h" #include "rtc_base/time_utils.h" #include "sdk/android/generated_video_jni/VideoFrame_jni.h" #include "sdk/android/src/jni/jni_helpers.h" diff --git a/sdk/android/src/jni/video_frame.h b/sdk/android/src/jni/video_frame.h index 5e39b8a770..d1e463bba2 100644 --- a/sdk/android/src/jni/video_frame.h +++ b/sdk/android/src/jni/video_frame.h @@ -16,7 +16,6 @@ #include "api/video/video_frame.h" #include "api/video/video_frame_buffer.h" #include "api/video/video_rotation.h" -#include "rtc_base/callback.h" #include "sdk/android/src/jni/jni_helpers.h" namespace webrtc { diff --git a/test/frame_generator.cc b/test/frame_generator.cc index 4594e1de20..913a4fb589 100644 --- a/test/frame_generator.cc +++ b/test/frame_generator.cc @@ -21,7 +21,6 @@ #include "common_video/include/video_frame_buffer.h" #include "common_video/libyuv/include/webrtc_libyuv.h" #include "rtc_base/checks.h" -#include "rtc_base/keep_ref_until_done.h" #include "test/frame_utils.h" namespace webrtc { @@ -368,7 +367,8 @@ void ScrollingImageFrameGenerator::CropSourceToScrolledImage( &i420_buffer->DataY()[offset_y], i420_buffer->StrideY(), &i420_buffer->DataU()[offset_u], i420_buffer->StrideU(), &i420_buffer->DataV()[offset_v], i420_buffer->StrideV(), - KeepRefUntilDone(i420_buffer)), + // To keep reference alive. + [i420_buffer] {}), update_rect); }