Make RefCountedObject require overriding virtual methods

Bug: webrtc:12701
Change-Id: Ia4ae4ad2e857cb8790d6ccfb6f88f07d52a8e91b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215967
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33831}
This commit is contained in:
Tomas Gunnarsson
2021-04-26 11:46:54 +02:00
committed by Commit Bot
parent 1959f8fedc
commit e249d195e0
11 changed files with 24 additions and 17 deletions

View File

@ -31,6 +31,10 @@ class RefCountedBase {
}
protected:
// Provided for internal webrtc subclasses for corner cases where it's
// necessary to know whether or not a reference is exclusively held.
bool HasOneRef() const { return ref_count_.HasOneRef(); }
virtual ~RefCountedBase() = default;
private:
@ -76,6 +80,10 @@ class RefCountedNonVirtual {
}
protected:
// Provided for internal webrtc subclasses for corner cases where it's
// necessary to know whether or not a reference is exclusively held.
bool HasOneRef() const { return ref_count_.HasOneRef(); }
~RefCountedNonVirtual() = default;
private:

View File

@ -23,7 +23,7 @@ namespace webrtc {
// SharedDesktopFrame is a DesktopFrame that may have multiple instances all
// sharing the same buffer.
class RTC_EXPORT SharedDesktopFrame : public DesktopFrame {
class RTC_EXPORT SharedDesktopFrame final : public DesktopFrame {
public:
~SharedDesktopFrame() override;
@ -51,7 +51,7 @@ class RTC_EXPORT SharedDesktopFrame : public DesktopFrame {
bool IsShared();
private:
typedef rtc::RefCountedObject<std::unique_ptr<DesktopFrame>> Core;
typedef rtc::FinalRefCountedObject<std::unique_ptr<DesktopFrame>> Core;
SharedDesktopFrame(rtc::scoped_refptr<Core> core);

View File

@ -592,6 +592,7 @@ rtc_library("webrtc_vp9") {
":webrtc_libvpx_interface",
":webrtc_vp9_helpers",
"../../api:fec_controller_api",
"../../api:refcountedbase",
"../../api:scoped_refptr",
"../../api/transport:field_trial_based_config",
"../../api/transport:webrtc_key_value_config",

View File

@ -15,7 +15,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/ref_counted_object.h"
#include "vpx/vpx_codec.h"
#include "vpx/vpx_decoder.h"
#include "vpx/vpx_frame_buffer.h"
@ -68,7 +67,7 @@ Vp9FrameBufferPool::GetFrameBuffer(size_t min_size) {
}
// Otherwise create one.
if (available_buffer == nullptr) {
available_buffer = new rtc::RefCountedObject<Vp9FrameBuffer>();
available_buffer = new Vp9FrameBuffer();
allocated_buffers_.push_back(available_buffer);
if (allocated_buffers_.size() > max_num_buffers_) {
RTC_LOG(LS_WARNING)

View File

@ -16,9 +16,9 @@
#include <vector>
#include "api/ref_counted_base.h"
#include "api/scoped_refptr.h"
#include "rtc_base/buffer.h"
#include "rtc_base/ref_count.h"
#include "rtc_base/synchronization/mutex.h"
struct vpx_codec_ctx;
@ -65,13 +65,14 @@ constexpr size_t kDefaultMaxNumBuffers = 68;
// vpx_codec_destroy(decoder_ctx);
class Vp9FrameBufferPool {
public:
class Vp9FrameBuffer : public rtc::RefCountInterface {
class Vp9FrameBuffer final
: public rtc::RefCountedNonVirtual<Vp9FrameBuffer> {
public:
uint8_t* GetData();
size_t GetDataSize() const;
void SetSize(size_t size);
virtual bool HasOneRef() const = 0;
using rtc::RefCountedNonVirtual<Vp9FrameBuffer>::HasOneRef;
private:
// Data as an easily resizable buffer.

View File

@ -18,7 +18,6 @@
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.h"
#include "rtc_base/ref_counted_object.h"
#include "rtc_base/time_utils.h"
#include "test/gtest.h"
@ -118,8 +117,7 @@ class FakeDtmfProvider : public DtmfProviderInterface {
class DtmfSenderTest : public ::testing::Test {
protected:
DtmfSenderTest()
: observer_(new rtc::RefCountedObject<FakeDtmfObserver>()),
provider_(new FakeDtmfProvider()) {
: observer_(new FakeDtmfObserver()), provider_(new FakeDtmfProvider()) {
provider_->SetCanInsertDtmf(true);
dtmf_ = DtmfSender::Create(rtc::Thread::Current(), provider_.get());
dtmf_->RegisterObserver(observer_.get());

View File

@ -17,7 +17,7 @@ namespace rtc {
AsyncInvoker::AsyncInvoker()
: pending_invocations_(0),
invocation_complete_(new RefCountedObject<Event>()),
invocation_complete_(make_ref_counted<Event>()),
destroying_(false) {}
AsyncInvoker::~AsyncInvoker() {

View File

@ -156,7 +156,7 @@ class AsyncInvoker : public MessageHandlerAutoCleanup {
// an AsyncClosure's destructor that's about to call
// "invocation_complete_->Set()", it's not dereferenced after being
// destroyed.
scoped_refptr<RefCountedObject<Event>> invocation_complete_;
rtc::Ref<Event>::Ptr invocation_complete_;
// This flag is used to ensure that if an application AsyncInvokes tasks that
// recursively AsyncInvoke other tasks ad infinitum, the cycle eventually

View File

@ -39,7 +39,7 @@ class AsyncClosure {
// an AsyncClosure's destructor that's about to call
// "invocation_complete_->Set()", it's not dereferenced after being
// destroyed.
scoped_refptr<RefCountedObject<Event>> invocation_complete_;
rtc::Ref<Event>::Ptr invocation_complete_;
};
// Simple closure that doesn't trigger a callback for the calling thread.

View File

@ -34,9 +34,9 @@ class RefCountedObject : public T {
std::forward<P1>(p1),
std::forward<Args>(args)...) {}
virtual void AddRef() const { ref_count_.IncRef(); }
void AddRef() const override { ref_count_.IncRef(); }
virtual RefCountReleaseStatus Release() const {
RefCountReleaseStatus Release() const override {
const auto status = ref_count_.DecRef();
if (status == RefCountReleaseStatus::kDroppedLastRef) {
delete this;
@ -53,7 +53,7 @@ class RefCountedObject : public T {
virtual bool HasOneRef() const { return ref_count_.HasOneRef(); }
protected:
virtual ~RefCountedObject() {}
~RefCountedObject() override {}
mutable webrtc::webrtc_impl::RefCounter ref_count_{0};

View File

@ -52,7 +52,7 @@ class VideoFrameMatcher {
rtc::scoped_refptr<VideoFrameBuffer> thumb;
int repeat_count = 0;
};
using DecodedFrame = rtc::RefCountedObject<DecodedFrameBase>;
using DecodedFrame = rtc::FinalRefCountedObject<DecodedFrameBase>;
struct CapturedFrame {
int id;
Timestamp capture_time = Timestamp::PlusInfinity();