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 <philipel@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33281}
This commit is contained in:
@ -12,10 +12,10 @@
|
||||
#define COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <functional>
|
||||
|
||||
#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<I420BufferInterface> WrapI420Buffer(
|
||||
int u_stride,
|
||||
const uint8_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used);
|
||||
std::function<void()> no_longer_used);
|
||||
|
||||
rtc::scoped_refptr<I444BufferInterface> WrapI444Buffer(
|
||||
int width,
|
||||
@ -40,7 +40,7 @@ rtc::scoped_refptr<I444BufferInterface> WrapI444Buffer(
|
||||
int u_stride,
|
||||
const uint8_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used);
|
||||
std::function<void()> no_longer_used);
|
||||
|
||||
rtc::scoped_refptr<I420ABufferInterface> WrapI420ABuffer(
|
||||
int width,
|
||||
@ -53,7 +53,7 @@ rtc::scoped_refptr<I420ABufferInterface> WrapI420ABuffer(
|
||||
int v_stride,
|
||||
const uint8_t* a_plane,
|
||||
int a_stride,
|
||||
const rtc::Callback0<void>& no_longer_used);
|
||||
std::function<void()> no_longer_used);
|
||||
|
||||
rtc::scoped_refptr<PlanarYuvBuffer> WrapYuvBuffer(
|
||||
VideoFrameBuffer::Type type,
|
||||
@ -65,7 +65,7 @@ rtc::scoped_refptr<PlanarYuvBuffer> WrapYuvBuffer(
|
||||
int u_stride,
|
||||
const uint8_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used);
|
||||
std::function<void()> no_longer_used);
|
||||
|
||||
rtc::scoped_refptr<I010BufferInterface> WrapI010Buffer(
|
||||
int width,
|
||||
@ -76,7 +76,7 @@ rtc::scoped_refptr<I010BufferInterface> WrapI010Buffer(
|
||||
int u_stride,
|
||||
const uint16_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used);
|
||||
std::function<void()> no_longer_used);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ class WrappedYuvBuffer : public Base {
|
||||
int u_stride,
|
||||
const uint8_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used)
|
||||
std::function<void()> 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<void> no_longer_used_cb_;
|
||||
std::function<void()> no_longer_used_cb_;
|
||||
};
|
||||
|
||||
// Template to implement a wrapped buffer for a I4??BufferInterface.
|
||||
@ -87,7 +87,7 @@ class WrappedYuvaBuffer : public WrappedYuvBuffer<BaseWithA> {
|
||||
int v_stride,
|
||||
const uint8_t* a_plane,
|
||||
int a_stride,
|
||||
const rtc::Callback0<void>& no_longer_used)
|
||||
std::function<void()> no_longer_used)
|
||||
: WrappedYuvBuffer<BaseWithA>(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<void>& no_longer_used)
|
||||
std::function<void()> 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<void> no_longer_used_cb_;
|
||||
std::function<void()> no_longer_used_cb_;
|
||||
};
|
||||
|
||||
class I010BufferBase : public I010BufferInterface {
|
||||
@ -206,7 +206,7 @@ rtc::scoped_refptr<I420BufferInterface> WrapI420Buffer(
|
||||
int u_stride,
|
||||
const uint8_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used) {
|
||||
std::function<void()> no_longer_used) {
|
||||
return rtc::scoped_refptr<I420BufferInterface>(
|
||||
new rtc::RefCountedObject<WrappedYuvBuffer<I420BufferInterface>>(
|
||||
width, height, y_plane, y_stride, u_plane, u_stride, v_plane,
|
||||
@ -224,7 +224,7 @@ rtc::scoped_refptr<I420ABufferInterface> WrapI420ABuffer(
|
||||
int v_stride,
|
||||
const uint8_t* a_plane,
|
||||
int a_stride,
|
||||
const rtc::Callback0<void>& no_longer_used) {
|
||||
std::function<void()> no_longer_used) {
|
||||
return rtc::scoped_refptr<I420ABufferInterface>(
|
||||
new rtc::RefCountedObject<WrappedYuvaBuffer<I420ABufferInterface>>(
|
||||
width, height, y_plane, y_stride, u_plane, u_stride, v_plane,
|
||||
@ -240,7 +240,7 @@ rtc::scoped_refptr<I444BufferInterface> WrapI444Buffer(
|
||||
int u_stride,
|
||||
const uint8_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used) {
|
||||
std::function<void()> no_longer_used) {
|
||||
return rtc::scoped_refptr<I444BufferInterface>(
|
||||
new rtc::RefCountedObject<WrappedYuvBuffer<I444BufferBase>>(
|
||||
width, height, y_plane, y_stride, u_plane, u_stride, v_plane,
|
||||
@ -257,7 +257,7 @@ rtc::scoped_refptr<PlanarYuvBuffer> WrapYuvBuffer(
|
||||
int u_stride,
|
||||
const uint8_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used) {
|
||||
std::function<void()> 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<I010BufferInterface> WrapI010Buffer(
|
||||
int u_stride,
|
||||
const uint16_t* v_plane,
|
||||
int v_stride,
|
||||
const rtc::Callback0<void>& no_longer_used) {
|
||||
std::function<void()> no_longer_used) {
|
||||
return rtc::scoped_refptr<I010BufferInterface>(
|
||||
new rtc::RefCountedObject<WrappedYuv16BBuffer<I010BufferBase>>(
|
||||
width, height, y_plane, y_stride, u_plane, u_stride, v_plane,
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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<VideoFrame*>(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<VideoFrameBuffer> 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();
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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<VideoFrameBuffer> 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<I420BufferInterface> 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())
|
||||
|
||||
@ -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>(VideoFrame::Builder()
|
||||
.set_video_frame_buffer(yuva_buffer)
|
||||
.set_timestamp_rtp(123)
|
||||
@ -168,8 +169,7 @@ class TestMultiplexAdapter : public VideoCodecUnitTest,
|
||||
rtc::scoped_refptr<I420BufferInterface> 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>(VideoFrame::Builder()
|
||||
.set_video_frame_buffer(axx_buffer)
|
||||
.set_timestamp_rtp(123)
|
||||
|
||||
@ -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<Vp9FrameBufferPool::Vp9FrameBuffer> img_buffer =
|
||||
static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(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<const uint16_t*>(img->planes[VPX_PLANE_U]),
|
||||
img->stride[VPX_PLANE_U] / 2,
|
||||
reinterpret_cast<const uint16_t*>(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: "
|
||||
|
||||
@ -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<void, StunProber*, int> AsyncCallback;
|
||||
typedef std::function<void(StunProber*, int)> AsyncCallback;
|
||||
|
||||
enum NatType {
|
||||
NATTYPE_INVALID,
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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<ReturnType, ParamType1, ..., ParamTypeN>
|
||||
// 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<int, int> my_callback;
|
||||
// cout << my_callback.empty() << endl; // true
|
||||
//
|
||||
// my_callback = Callback1<int, int>(&sqr);
|
||||
// cout << my_callback.empty() << endl; // false
|
||||
// cout << my_callback(3) << endl; // 9
|
||||
//
|
||||
// my_callback = Callback1<int, int>(add_k);
|
||||
// cout << my_callback(10) << endl; // 15
|
||||
//
|
||||
// my_callback = Callback1<int, int>();
|
||||
// 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 R>
|
||||
class Callback0 {
|
||||
public:
|
||||
// Default copy operations are appropriate for this class.
|
||||
Callback0() {}
|
||||
template <class T>
|
||||
Callback0(const T& functor)
|
||||
: helper_(new RefCountedObject<HelperImpl<T> >(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 <class T>
|
||||
struct HelperImpl : Helper {
|
||||
explicit HelperImpl(const T& functor) : functor_(functor) {}
|
||||
virtual R Run() { return functor_(); }
|
||||
T functor_;
|
||||
};
|
||||
scoped_refptr<Helper> helper_;
|
||||
};
|
||||
|
||||
template <class R, class P1>
|
||||
class Callback1 {
|
||||
public:
|
||||
// Default copy operations are appropriate for this class.
|
||||
Callback1() {}
|
||||
template <class T>
|
||||
Callback1(const T& functor)
|
||||
: helper_(new RefCountedObject<HelperImpl<T> >(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 <class T>
|
||||
struct HelperImpl : Helper {
|
||||
explicit HelperImpl(const T& functor) : functor_(functor) {}
|
||||
virtual R Run(P1 p1) { return functor_(p1); }
|
||||
T functor_;
|
||||
};
|
||||
scoped_refptr<Helper> helper_;
|
||||
};
|
||||
|
||||
template <class R, class P1, class P2>
|
||||
class Callback2 {
|
||||
public:
|
||||
// Default copy operations are appropriate for this class.
|
||||
Callback2() {}
|
||||
template <class T>
|
||||
Callback2(const T& functor)
|
||||
: helper_(new RefCountedObject<HelperImpl<T> >(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 <class T>
|
||||
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> helper_;
|
||||
};
|
||||
|
||||
template <class R, class P1, class P2, class P3>
|
||||
class Callback3 {
|
||||
public:
|
||||
// Default copy operations are appropriate for this class.
|
||||
Callback3() {}
|
||||
template <class T>
|
||||
Callback3(const T& functor)
|
||||
: helper_(new RefCountedObject<HelperImpl<T> >(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 <class T>
|
||||
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> helper_;
|
||||
};
|
||||
|
||||
template <class R, class P1, class P2, class P3, class P4>
|
||||
class Callback4 {
|
||||
public:
|
||||
// Default copy operations are appropriate for this class.
|
||||
Callback4() {}
|
||||
template <class T>
|
||||
Callback4(const T& functor)
|
||||
: helper_(new RefCountedObject<HelperImpl<T> >(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 <class T>
|
||||
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> helper_;
|
||||
};
|
||||
|
||||
template <class R, class P1, class P2, class P3, class P4, class P5>
|
||||
class Callback5 {
|
||||
public:
|
||||
// Default copy operations are appropriate for this class.
|
||||
Callback5() {}
|
||||
template <class T>
|
||||
Callback5(const T& functor)
|
||||
: helper_(new RefCountedObject<HelperImpl<T> >(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 <class T>
|
||||
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> helper_;
|
||||
};
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_CALLBACK_H_
|
||||
@ -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<ReturnType, ParamType1, ..., ParamTypeN>
|
||||
// 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<int, int> my_callback;
|
||||
// cout << my_callback.empty() << endl; // true
|
||||
//
|
||||
// my_callback = Callback1<int, int>(&sqr);
|
||||
// cout << my_callback.empty() << endl; // false
|
||||
// cout << my_callback(3) << endl; // 9
|
||||
//
|
||||
// my_callback = Callback1<int, int>(add_k);
|
||||
// cout << my_callback(10) << endl; // 15
|
||||
//
|
||||
// my_callback = Callback1<int, int>();
|
||||
// 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 R$for j [[,
|
||||
class P$j]]>
|
||||
class Callback$i {
|
||||
public:
|
||||
// Default copy operations are appropriate for this class.
|
||||
Callback$i() {}
|
||||
template <class T> Callback$i(const T& functor)
|
||||
: helper_(new RefCountedObject< HelperImpl<T> >(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 <class T> 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> helper_;
|
||||
};
|
||||
|
||||
]]
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_CALLBACK_H_
|
||||
@ -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<void> cb;
|
||||
EXPECT_TRUE(cb.empty());
|
||||
cb(); // Executing an empty callback should not crash.
|
||||
cb = Callback0<void>(&f);
|
||||
EXPECT_FALSE(cb.empty());
|
||||
cb();
|
||||
}
|
||||
|
||||
TEST(CallbackTest, IntReturn) {
|
||||
Callback0<int> cb;
|
||||
EXPECT_TRUE(cb.empty());
|
||||
cb = Callback0<int>(&g);
|
||||
EXPECT_FALSE(cb.empty());
|
||||
EXPECT_EQ(42, cb());
|
||||
EXPECT_EQ(42, cb());
|
||||
}
|
||||
|
||||
TEST(CallbackTest, OneParam) {
|
||||
Callback1<int, int> cb1(&h);
|
||||
EXPECT_FALSE(cb1.empty());
|
||||
EXPECT_EQ(9, cb1(-3));
|
||||
EXPECT_EQ(100, cb1(10));
|
||||
|
||||
// Try clearing a callback.
|
||||
cb1 = Callback1<int, int>();
|
||||
EXPECT_TRUE(cb1.empty());
|
||||
|
||||
// Try a callback with a ref parameter.
|
||||
Callback1<void, int&> 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<void> 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<void> cb2;
|
||||
{
|
||||
Callback0<void> cb = KeepRefUntilDone(&t);
|
||||
EXPECT_EQ(1, t.RefCount());
|
||||
cb2 = cb;
|
||||
}
|
||||
EXPECT_EQ(1, t.RefCount());
|
||||
cb2 = Callback0<void>();
|
||||
EXPECT_EQ(0, t.RefCount());
|
||||
}
|
||||
|
||||
TEST(KeepRefUntilDoneTest, scopedref) {
|
||||
RefCountedBindTester t;
|
||||
EXPECT_EQ(0, t.RefCount());
|
||||
{
|
||||
scoped_refptr<RefCountedBindTester> t_scoped_ref(&t);
|
||||
Callback0<void> 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
|
||||
@ -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 <class ObjectT>
|
||||
static inline Callback0<void> KeepRefUntilDone(ObjectT* object) {
|
||||
scoped_refptr<ObjectT> p(object);
|
||||
return [p] {};
|
||||
}
|
||||
|
||||
template <class ObjectT>
|
||||
static inline Callback0<void> KeepRefUntilDone(
|
||||
const scoped_refptr<ObjectT>& object) {
|
||||
return [object] {};
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_KEEP_REF_UNTIL_DONE_H_
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user