Deprecate rtc::RefCountInterface
and move usages to webrtc::RefCountInterface This CL also moves more stuff to webrtc:: and adds backwards compatible aliases for them. Bug: webrtc:42225969 Change-Id: Iefb8542cff793bd8aa46bef8f2f3c66a1e979d07 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353720 Reviewed-by: Florent Castelli <orphis@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42446}
This commit is contained in:
parent
1b26b72f30
commit
c74412b304
@ -15,6 +15,7 @@ rtc_source_set("resource_adaptation_api") {
|
||||
"resource.h",
|
||||
]
|
||||
deps = [
|
||||
"..:ref_count",
|
||||
"../../api:scoped_refptr",
|
||||
"../../rtc_base:checks",
|
||||
"../../rtc_base:refcount",
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
specific_include_rules = {
|
||||
"resource\.h": [
|
||||
# ref_count.h is a public_deps of rtc_base:refcount. Necessary because of
|
||||
# rtc::RefCountInterface.
|
||||
"+rtc_base/ref_count.h",
|
||||
],
|
||||
}
|
||||
@ -13,8 +13,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "api/ref_count.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "rtc_base/ref_count.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -50,7 +50,7 @@ class RTC_EXPORT ResourceListener {
|
||||
// The Resource is reference counted to prevent use-after-free when posting
|
||||
// between task queues. As such, the implementation MUST NOT make any
|
||||
// assumptions about which task queue Resource is destructed on.
|
||||
class RTC_EXPORT Resource : public rtc::RefCountInterface {
|
||||
class RTC_EXPORT Resource : public RefCountInterface {
|
||||
public:
|
||||
Resource();
|
||||
// Destruction may happen on any task queue.
|
||||
|
||||
@ -21,7 +21,7 @@ namespace webrtc {
|
||||
// WORK IN PROGRESS
|
||||
// This class is under development and is not yet intended for for use outside
|
||||
// of WebRtc/Libjingle.
|
||||
class AudioMixer : public rtc::RefCountInterface {
|
||||
class AudioMixer : public RefCountInterface {
|
||||
public:
|
||||
// A callback class that all mixer participants must inherit from/implement.
|
||||
class Source {
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
namespace webrtc {
|
||||
|
||||
// A factory that creates AudioEncoders.
|
||||
class AudioEncoderFactory : public rtc::RefCountInterface {
|
||||
class AudioEncoderFactory : public RefCountInterface {
|
||||
public:
|
||||
// Returns a prioritized list of audio codecs, to use for signaling etc.
|
||||
virtual std::vector<AudioCodecSpec> GetSupportedEncoders() = 0;
|
||||
|
||||
@ -27,7 +27,7 @@ namespace webrtc {
|
||||
// without it. You may assume that this interface will have the same lifetime
|
||||
// as the RTPReceiver it is attached to. It must only be attached to one
|
||||
// RTPReceiver. Additional data may be null.
|
||||
class FrameDecryptorInterface : public rtc::RefCountInterface {
|
||||
class FrameDecryptorInterface : public RefCountInterface {
|
||||
public:
|
||||
// The Status enum represents all possible states that can be
|
||||
// returned when attempting to decrypt a frame. kRecoverable indicates that
|
||||
|
||||
@ -24,7 +24,7 @@ namespace webrtc {
|
||||
// addition to the standard SRTP mechanism and is not intended to be used
|
||||
// without it. Implementations of this interface will have the same lifetime as
|
||||
// the RTPSenders it is attached to. Additional data may be null.
|
||||
class FrameEncryptorInterface : public rtc::RefCountInterface {
|
||||
class FrameEncryptorInterface : public RefCountInterface {
|
||||
public:
|
||||
~FrameEncryptorInterface() override {}
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
|
||||
namespace rtc {
|
||||
namespace webrtc {
|
||||
|
||||
namespace webrtc_make_ref_counted_internal {
|
||||
// Determines if the given class has AddRef and Release methods.
|
||||
@ -115,6 +115,56 @@ scoped_refptr<FinalRefCountedObject<T>> make_ref_counted(Args&&... args) {
|
||||
new FinalRefCountedObject<T>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
// Backwards compatibe aliases.
|
||||
// TODO: https://issues.webrtc.org/42225969 - deprecate and remove.
|
||||
namespace rtc {
|
||||
// This doesn't work:
|
||||
// template <typename T, typename... Args>
|
||||
// using make_ref_counted(Args&&... args) =
|
||||
// webrtc::make_ref_counted<T>(Args&&... args);
|
||||
// Instead, reproduce the templates.
|
||||
template <typename T,
|
||||
typename... Args,
|
||||
typename std::enable_if<
|
||||
std::is_convertible_v<T*, webrtc::RefCountInterface*> &&
|
||||
std::is_abstract_v<T>,
|
||||
T>::type* = nullptr>
|
||||
scoped_refptr<T> make_ref_counted(Args&&... args) {
|
||||
return webrtc::scoped_refptr<T>(
|
||||
new webrtc::RefCountedObject<T>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// `make_ref_counted` for complete classes that are not convertible to
|
||||
// RefCountInterface and already carry a ref count.
|
||||
template <typename T,
|
||||
typename... Args,
|
||||
typename std::enable_if<
|
||||
!std::is_convertible_v<T*, webrtc::RefCountInterface*> &&
|
||||
webrtc::webrtc_make_ref_counted_internal::HasAddRefAndRelease<
|
||||
T>::value,
|
||||
T>::type* = nullptr>
|
||||
scoped_refptr<T> make_ref_counted(Args&&... args) {
|
||||
return webrtc::scoped_refptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// `make_ref_counted` for complete classes that are not convertible to
|
||||
// RefCountInterface and have no ref count of their own.
|
||||
template <typename T,
|
||||
typename... Args,
|
||||
typename std::enable_if<
|
||||
!std::is_convertible_v<T*, webrtc::RefCountInterface*> &&
|
||||
!webrtc::webrtc_make_ref_counted_internal::
|
||||
HasAddRefAndRelease<T>::value,
|
||||
|
||||
T>::type* = nullptr>
|
||||
scoped_refptr<webrtc::FinalRefCountedObject<T>> make_ref_counted(
|
||||
Args&&... args) {
|
||||
return webrtc::scoped_refptr<FinalRefCountedObject<T>>(
|
||||
new webrtc::FinalRefCountedObject<T>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // API_MAKE_REF_COUNTED_H_
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
#include "rtc_base/ref_counter.h"
|
||||
|
||||
namespace rtc {
|
||||
namespace webrtc {
|
||||
|
||||
class RefCountedBase {
|
||||
public:
|
||||
@ -93,6 +93,14 @@ class RefCountedNonVirtual {
|
||||
mutable webrtc::webrtc_impl::RefCounter ref_count_{0};
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
// Backwards compatibe aliases.
|
||||
// TODO: https://issues.webrtc.org/42225969 - deprecate and remove.
|
||||
namespace rtc {
|
||||
using RefCountedBase = webrtc::RefCountedBase;
|
||||
template <typename T>
|
||||
using RefCountedNonVirtual = webrtc::RefCountedNonVirtual<T>;
|
||||
} // namespace rtc
|
||||
|
||||
#endif // API_REF_COUNTED_BASE_H_
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RTCStatsCollectorCallback : public rtc::RefCountInterface {
|
||||
class RTCStatsCollectorCallback : public RefCountInterface {
|
||||
public:
|
||||
~RTCStatsCollectorCallback() override = default;
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ namespace webrtc {
|
||||
// Abstract interface for buffer storage. Intended to support buffers owned by
|
||||
// external encoders with special release requirements, e.g, java encoders with
|
||||
// releaseOutputBuffer.
|
||||
class EncodedImageBufferInterface : public rtc::RefCountInterface {
|
||||
class EncodedImageBufferInterface : public RefCountInterface {
|
||||
public:
|
||||
virtual const uint8_t* data() const = 0;
|
||||
// TODO(bugs.webrtc.org/9378): Make interface essentially read-only, delete
|
||||
|
||||
@ -29,7 +29,7 @@ namespace webrtc {
|
||||
// AudioChannel represents a single media session and provides APIs over
|
||||
// AudioIngress and AudioEgress. Note that a single RTP stack is shared with
|
||||
// these two classes as it has both sending and receiving capabilities.
|
||||
class AudioChannel : public rtc::RefCountInterface {
|
||||
class AudioChannel : public RefCountInterface {
|
||||
public:
|
||||
AudioChannel(Transport* transport,
|
||||
uint32_t local_ssrc,
|
||||
|
||||
@ -84,7 +84,7 @@ class ResourceAdaptationProcessor : public ResourceAdaptationProcessorInterface,
|
||||
// If resource usage measurements happens off the adaptation task queue, this
|
||||
// class takes care of posting the measurement for the processor to handle it
|
||||
// on the adaptation task queue.
|
||||
class ResourceListenerDelegate : public rtc::RefCountInterface,
|
||||
class ResourceListenerDelegate : public RefCountInterface,
|
||||
public ResourceListener {
|
||||
public:
|
||||
explicit ResourceListenerDelegate(ResourceAdaptationProcessor* processor);
|
||||
|
||||
@ -23,7 +23,7 @@ class AudioTransport;
|
||||
|
||||
// AudioState holds the state which must be shared between multiple instances of
|
||||
// webrtc::Call for audio processing purposes.
|
||||
class AudioState : public rtc::RefCountInterface {
|
||||
class AudioState : public RefCountInterface {
|
||||
public:
|
||||
struct Config {
|
||||
Config();
|
||||
|
||||
@ -60,7 +60,7 @@ class WrappedYuvBuffer : public Base {
|
||||
int StrideV() const override { return v_stride_; }
|
||||
|
||||
private:
|
||||
friend class rtc::RefCountedObject<WrappedYuvBuffer>;
|
||||
friend class RefCountedObject<WrappedYuvBuffer>;
|
||||
|
||||
const int width_;
|
||||
const int height_;
|
||||
@ -182,7 +182,7 @@ class WrappedYuv16BBuffer : public Base {
|
||||
int StrideV() const override { return v_stride_; }
|
||||
|
||||
private:
|
||||
friend class rtc::RefCountedObject<WrappedYuv16BBuffer>;
|
||||
friend class RefCountedObject<WrappedYuv16BBuffer>;
|
||||
|
||||
const int width_;
|
||||
const int height_;
|
||||
|
||||
@ -19,37 +19,37 @@ namespace webrtc {
|
||||
|
||||
namespace {
|
||||
bool HasOneRef(const rtc::scoped_refptr<VideoFrameBuffer>& buffer) {
|
||||
// Cast to rtc::RefCountedObject is safe because this function is only called
|
||||
// Cast to RefCountedObject is safe because this function is only called
|
||||
// on locally created VideoFrameBuffers, which are either
|
||||
// `rtc::RefCountedObject<I420Buffer>`, `rtc::RefCountedObject<I444Buffer>` or
|
||||
// `rtc::RefCountedObject<NV12Buffer>`.
|
||||
// `RefCountedObject<I420Buffer>`, `RefCountedObject<I444Buffer>` or
|
||||
// `RefCountedObject<NV12Buffer>`.
|
||||
switch (buffer->type()) {
|
||||
case VideoFrameBuffer::Type::kI420: {
|
||||
return static_cast<rtc::RefCountedObject<I420Buffer>*>(buffer.get())
|
||||
return static_cast<RefCountedObject<I420Buffer>*>(buffer.get())
|
||||
->HasOneRef();
|
||||
}
|
||||
case VideoFrameBuffer::Type::kI444: {
|
||||
return static_cast<rtc::RefCountedObject<I444Buffer>*>(buffer.get())
|
||||
return static_cast<RefCountedObject<I444Buffer>*>(buffer.get())
|
||||
->HasOneRef();
|
||||
}
|
||||
case VideoFrameBuffer::Type::kI422: {
|
||||
return static_cast<rtc::RefCountedObject<I422Buffer>*>(buffer.get())
|
||||
return static_cast<RefCountedObject<I422Buffer>*>(buffer.get())
|
||||
->HasOneRef();
|
||||
}
|
||||
case VideoFrameBuffer::Type::kI010: {
|
||||
return static_cast<rtc::RefCountedObject<I010Buffer>*>(buffer.get())
|
||||
return static_cast<RefCountedObject<I010Buffer>*>(buffer.get())
|
||||
->HasOneRef();
|
||||
}
|
||||
case VideoFrameBuffer::Type::kI210: {
|
||||
return static_cast<rtc::RefCountedObject<I210Buffer>*>(buffer.get())
|
||||
return static_cast<RefCountedObject<I210Buffer>*>(buffer.get())
|
||||
->HasOneRef();
|
||||
}
|
||||
case VideoFrameBuffer::Type::kI410: {
|
||||
return static_cast<rtc::RefCountedObject<I410Buffer>*>(buffer.get())
|
||||
return static_cast<RefCountedObject<I410Buffer>*>(buffer.get())
|
||||
->HasOneRef();
|
||||
}
|
||||
case VideoFrameBuffer::Type::kNV12: {
|
||||
return static_cast<rtc::RefCountedObject<NV12Buffer>*>(buffer.get())
|
||||
return static_cast<RefCountedObject<NV12Buffer>*>(buffer.get())
|
||||
->HasOneRef();
|
||||
}
|
||||
default:
|
||||
@ -118,8 +118,8 @@ rtc::scoped_refptr<I420Buffer> VideoFrameBufferPool::CreateI420Buffer(
|
||||
// Cast is safe because the only way kI420 buffer is created is
|
||||
// in the same function below, where `RefCountedObject<I420Buffer>` is
|
||||
// created.
|
||||
rtc::RefCountedObject<I420Buffer>* raw_buffer =
|
||||
static_cast<rtc::RefCountedObject<I420Buffer>*>(existing_buffer.get());
|
||||
RefCountedObject<I420Buffer>* raw_buffer =
|
||||
static_cast<RefCountedObject<I420Buffer>*>(existing_buffer.get());
|
||||
// Creates a new scoped_refptr, which is also pointing to the same
|
||||
// RefCountedObject as buffer, increasing ref count.
|
||||
return rtc::scoped_refptr<I420Buffer>(raw_buffer);
|
||||
@ -149,8 +149,8 @@ rtc::scoped_refptr<I444Buffer> VideoFrameBufferPool::CreateI444Buffer(
|
||||
// Cast is safe because the only way kI444 buffer is created is
|
||||
// in the same function below, where |RefCountedObject<I444Buffer>|
|
||||
// is created.
|
||||
rtc::RefCountedObject<I444Buffer>* raw_buffer =
|
||||
static_cast<rtc::RefCountedObject<I444Buffer>*>(existing_buffer.get());
|
||||
RefCountedObject<I444Buffer>* raw_buffer =
|
||||
static_cast<RefCountedObject<I444Buffer>*>(existing_buffer.get());
|
||||
// Creates a new scoped_refptr, which is also pointing to the same
|
||||
// RefCountedObject as buffer, increasing ref count.
|
||||
return rtc::scoped_refptr<I444Buffer>(raw_buffer);
|
||||
@ -180,8 +180,8 @@ rtc::scoped_refptr<I422Buffer> VideoFrameBufferPool::CreateI422Buffer(
|
||||
// Cast is safe because the only way kI422 buffer is created is
|
||||
// in the same function below, where |RefCountedObject<I422Buffer>|
|
||||
// is created.
|
||||
rtc::RefCountedObject<I422Buffer>* raw_buffer =
|
||||
static_cast<rtc::RefCountedObject<I422Buffer>*>(existing_buffer.get());
|
||||
RefCountedObject<I422Buffer>* raw_buffer =
|
||||
static_cast<RefCountedObject<I422Buffer>*>(existing_buffer.get());
|
||||
// Creates a new scoped_refptr, which is also pointing to the same
|
||||
// RefCountedObject as buffer, increasing ref count.
|
||||
return rtc::scoped_refptr<I422Buffer>(raw_buffer);
|
||||
@ -211,8 +211,8 @@ rtc::scoped_refptr<NV12Buffer> VideoFrameBufferPool::CreateNV12Buffer(
|
||||
// Cast is safe because the only way kI420 buffer is created is
|
||||
// in the same function below, where `RefCountedObject<I420Buffer>` is
|
||||
// created.
|
||||
rtc::RefCountedObject<NV12Buffer>* raw_buffer =
|
||||
static_cast<rtc::RefCountedObject<NV12Buffer>*>(existing_buffer.get());
|
||||
RefCountedObject<NV12Buffer>* raw_buffer =
|
||||
static_cast<RefCountedObject<NV12Buffer>*>(existing_buffer.get());
|
||||
// Creates a new scoped_refptr, which is also pointing to the same
|
||||
// RefCountedObject as buffer, increasing ref count.
|
||||
return rtc::scoped_refptr<NV12Buffer>(raw_buffer);
|
||||
@ -242,8 +242,8 @@ rtc::scoped_refptr<I010Buffer> VideoFrameBufferPool::CreateI010Buffer(
|
||||
// Cast is safe because the only way kI010 buffer is created is
|
||||
// in the same function below, where |RefCountedObject<I010Buffer>|
|
||||
// is created.
|
||||
rtc::RefCountedObject<I010Buffer>* raw_buffer =
|
||||
static_cast<rtc::RefCountedObject<I010Buffer>*>(existing_buffer.get());
|
||||
RefCountedObject<I010Buffer>* raw_buffer =
|
||||
static_cast<RefCountedObject<I010Buffer>*>(existing_buffer.get());
|
||||
// Creates a new scoped_refptr, which is also pointing to the same
|
||||
// RefCountedObject as buffer, increasing ref count.
|
||||
return rtc::scoped_refptr<I010Buffer>(raw_buffer);
|
||||
@ -269,8 +269,8 @@ rtc::scoped_refptr<I210Buffer> VideoFrameBufferPool::CreateI210Buffer(
|
||||
// Cast is safe because the only way kI210 buffer is created is
|
||||
// in the same function below, where |RefCountedObject<I210Buffer>|
|
||||
// is created.
|
||||
rtc::RefCountedObject<I210Buffer>* raw_buffer =
|
||||
static_cast<rtc::RefCountedObject<I210Buffer>*>(existing_buffer.get());
|
||||
RefCountedObject<I210Buffer>* raw_buffer =
|
||||
static_cast<RefCountedObject<I210Buffer>*>(existing_buffer.get());
|
||||
// Creates a new scoped_refptr, which is also pointing to the same
|
||||
// RefCountedObject as buffer, increasing ref count.
|
||||
return rtc::scoped_refptr<I210Buffer>(raw_buffer);
|
||||
@ -296,8 +296,8 @@ rtc::scoped_refptr<I410Buffer> VideoFrameBufferPool::CreateI410Buffer(
|
||||
// Cast is safe because the only way kI410 buffer is created is
|
||||
// in the same function below, where |RefCountedObject<I410Buffer>|
|
||||
// is created.
|
||||
rtc::RefCountedObject<I410Buffer>* raw_buffer =
|
||||
static_cast<rtc::RefCountedObject<I410Buffer>*>(existing_buffer.get());
|
||||
RefCountedObject<I410Buffer>* raw_buffer =
|
||||
static_cast<RefCountedObject<I410Buffer>*>(existing_buffer.get());
|
||||
// Creates a new scoped_refptr, which is also pointing to the same
|
||||
// RefCountedObject as buffer, increasing ref count.
|
||||
return rtc::scoped_refptr<I410Buffer>(raw_buffer);
|
||||
|
||||
@ -3739,7 +3739,7 @@ TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) {
|
||||
}
|
||||
// The engine/channel should have dropped their references.
|
||||
EXPECT_EQ(adm.release()->Release(),
|
||||
rtc::RefCountReleaseStatus::kDroppedLastRef);
|
||||
webrtc::RefCountReleaseStatus::kDroppedLastRef);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ class AsyncAudioProcessing final {
|
||||
public:
|
||||
// Helper class passing AudioFrameProcessor and TaskQueueFactory into
|
||||
// AsyncAudioProcessing constructor.
|
||||
class Factory : public rtc::RefCountInterface {
|
||||
class Factory : public RefCountInterface {
|
||||
public:
|
||||
Factory(const Factory&) = delete;
|
||||
Factory& operator=(const Factory&) = delete;
|
||||
|
||||
@ -99,7 +99,7 @@ class ComRefCount : public T {
|
||||
|
||||
STDMETHOD_(ULONG, Release)() override {
|
||||
const auto status = ref_count_.DecRef();
|
||||
if (status == rtc::RefCountReleaseStatus::kDroppedLastRef) {
|
||||
if (status == RefCountReleaseStatus::kDroppedLastRef) {
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -44,8 +44,7 @@ namespace webrtc {
|
||||
// interferes with the operation of other PeerConnections.
|
||||
//
|
||||
// This class must be created and destroyed on the signaling thread.
|
||||
class ConnectionContext final
|
||||
: public rtc::RefCountedNonVirtual<ConnectionContext> {
|
||||
class ConnectionContext final : public RefCountedNonVirtual<ConnectionContext> {
|
||||
public:
|
||||
// Creates a ConnectionContext. May return null if initialization fails.
|
||||
// The Dependencies class allows simple management of all new dependencies
|
||||
@ -106,7 +105,7 @@ class ConnectionContext final
|
||||
ConnectionContext(const Environment& env,
|
||||
PeerConnectionFactoryDependencies* dependencies);
|
||||
|
||||
friend class rtc::RefCountedNonVirtual<ConnectionContext>;
|
||||
friend class RefCountedNonVirtual<ConnectionContext>;
|
||||
~ConnectionContext();
|
||||
|
||||
private:
|
||||
|
||||
@ -84,7 +84,7 @@ using ::testing::Values;
|
||||
cricket::MediaSendChannelInterface* SendChannelInternal(
|
||||
rtc::scoped_refptr<RtpTransceiverInterface> transceiver) {
|
||||
auto transceiver_with_internal = static_cast<
|
||||
rtc::RefCountedObject<RtpTransceiverProxyWithInternal<RtpTransceiver>>*>(
|
||||
RefCountedObject<RtpTransceiverProxyWithInternal<RtpTransceiver>>*>(
|
||||
transceiver.get());
|
||||
auto transceiver_internal =
|
||||
static_cast<RtpTransceiver*>(transceiver_with_internal->internal());
|
||||
@ -94,7 +94,7 @@ cricket::MediaSendChannelInterface* SendChannelInternal(
|
||||
cricket::MediaReceiveChannelInterface* ReceiveChannelInternal(
|
||||
rtc::scoped_refptr<RtpTransceiverInterface> transceiver) {
|
||||
auto transceiver_with_internal = static_cast<
|
||||
rtc::RefCountedObject<RtpTransceiverProxyWithInternal<RtpTransceiver>>*>(
|
||||
RefCountedObject<RtpTransceiverProxyWithInternal<RtpTransceiver>>*>(
|
||||
transceiver.get());
|
||||
auto transceiver_internal =
|
||||
static_cast<RtpTransceiver*>(transceiver_with_internal->internal());
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// class TestInterface : public rtc::RefCountInterface {
|
||||
// class TestInterface : public RefCountInterface {
|
||||
// public:
|
||||
// std::string FooA() = 0;
|
||||
// std::string FooB(bool arg1) const = 0;
|
||||
|
||||
@ -27,7 +27,7 @@ using ::testing::Return;
|
||||
namespace webrtc {
|
||||
|
||||
// Interface used for testing here.
|
||||
class FakeInterface : public rtc::RefCountInterface {
|
||||
class FakeInterface : public RefCountInterface {
|
||||
public:
|
||||
virtual void VoidMethod0() = 0;
|
||||
virtual std::string Method0() = 0;
|
||||
|
||||
@ -56,7 +56,7 @@ class RtpReceiverInternal;
|
||||
// Stats are gathered on the signaling, worker and network threads
|
||||
// asynchronously. The callback is invoked on the signaling thread. Resulting
|
||||
// reports are cached for `cache_lifetime_` ms.
|
||||
class RTCStatsCollector : public rtc::RefCountInterface {
|
||||
class RTCStatsCollector : public RefCountInterface {
|
||||
public:
|
||||
static rtc::scoped_refptr<RTCStatsCollector> Create(
|
||||
PeerConnectionInternal* pc,
|
||||
|
||||
@ -3759,7 +3759,7 @@ class FakeRTCStatsCollector : public RTCStatsCollector,
|
||||
// Satisfying the implementation of these methods and associating them with a
|
||||
// reference counter, will be done by RefCountedObject.
|
||||
virtual void AddRef() const = 0;
|
||||
virtual rtc::RefCountReleaseStatus Release() const = 0;
|
||||
virtual RefCountReleaseStatus Release() const = 0;
|
||||
|
||||
// RTCStatsCollectorCallback implementation.
|
||||
void OnStatsDelivered(
|
||||
|
||||
@ -18,8 +18,11 @@
|
||||
namespace rtc {
|
||||
|
||||
// TODO(bugs.webrtc.org/15622): Deprecate and remove these aliases.
|
||||
using webrtc::RefCountInterface;
|
||||
using webrtc::RefCountReleaseStatus;
|
||||
using RefCountInterface [[deprecated("Use webrtc::RefCountInterface")]] =
|
||||
webrtc::RefCountInterface;
|
||||
using RefCountReleaseStatus
|
||||
[[deprecated("Use webrtc::RefCountReleaseStatus")]] =
|
||||
webrtc::RefCountReleaseStatus;
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
#include "rtc_base/ref_count.h"
|
||||
#include "rtc_base/ref_counter.h"
|
||||
|
||||
namespace rtc {
|
||||
namespace webrtc {
|
||||
|
||||
template <class T>
|
||||
class RefCountedObject : public T {
|
||||
@ -84,6 +84,59 @@ class FinalRefCountedObject final : public T {
|
||||
mutable webrtc::webrtc_impl::RefCounter ref_count_{0};
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
// Backwards compatibe aliases.
|
||||
// TODO: https://issues.webrtc.org/42225969 - deprecate and remove.
|
||||
namespace rtc {
|
||||
// Because there are users of this template that use "friend
|
||||
// rtc::RefCountedObject<>" to give access to a private destructor, some
|
||||
// indirection is needed; "friend" declarations cannot span an "using"
|
||||
// declaration. Since a templated class on top of a templated class can't access
|
||||
// the subclass' protected members, we duplicate the entire class instead.
|
||||
template <class T>
|
||||
class RefCountedObject : public T {
|
||||
public:
|
||||
RefCountedObject() {}
|
||||
|
||||
RefCountedObject(const RefCountedObject&) = delete;
|
||||
RefCountedObject& operator=(const RefCountedObject&) = delete;
|
||||
|
||||
template <class P0>
|
||||
explicit RefCountedObject(P0&& p0) : T(std::forward<P0>(p0)) {}
|
||||
|
||||
template <class P0, class P1, class... Args>
|
||||
RefCountedObject(P0&& p0, P1&& p1, Args&&... args)
|
||||
: T(std::forward<P0>(p0),
|
||||
std::forward<P1>(p1),
|
||||
std::forward<Args>(args)...) {}
|
||||
|
||||
void AddRef() const override { ref_count_.IncRef(); }
|
||||
|
||||
webrtc::RefCountReleaseStatus Release() const override {
|
||||
const auto status = ref_count_.DecRef();
|
||||
if (status == webrtc::RefCountReleaseStatus::kDroppedLastRef) {
|
||||
delete this;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Return whether the reference count is one. If the reference count is used
|
||||
// in the conventional way, a reference count of 1 implies that the current
|
||||
// thread owns the reference and no other thread shares it. This call
|
||||
// performs the test for a reference count of one, and performs the memory
|
||||
// barrier needed for the owning thread to act on the object, knowing that it
|
||||
// has exclusive access to the object.
|
||||
virtual bool HasOneRef() const { return ref_count_.HasOneRef(); }
|
||||
|
||||
protected:
|
||||
~RefCountedObject() override {}
|
||||
|
||||
mutable webrtc::webrtc_impl::RefCounter ref_count_{0};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using FinalRefCountedObject = webrtc::FinalRefCountedObject<T>;
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_REF_COUNTED_OBJECT_H_
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
#include "rtc_base/ref_count.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace rtc {
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -172,4 +172,4 @@ TEST(RefCounted, SmartPointers) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
} // namespace webrtc
|
||||
|
||||
@ -34,7 +34,7 @@ class RefCounter {
|
||||
// Otherwise, returns kOtherRefsRemained (note that in case of multithreading,
|
||||
// some other caller may have dropped the last reference by the time this call
|
||||
// returns; all we know is that we didn't do it).
|
||||
rtc::RefCountReleaseStatus DecRef() {
|
||||
RefCountReleaseStatus DecRef() {
|
||||
// Use release-acquire barrier to ensure all actions on the protected
|
||||
// resource are finished before the resource can be freed.
|
||||
// When ref_count_after_subtract > 0, this function require
|
||||
@ -47,8 +47,8 @@ class RefCounter {
|
||||
int ref_count_after_subtract =
|
||||
ref_count_.fetch_sub(1, std::memory_order_acq_rel) - 1;
|
||||
return ref_count_after_subtract == 0
|
||||
? rtc::RefCountReleaseStatus::kDroppedLastRef
|
||||
: rtc::RefCountReleaseStatus::kOtherRefsRemained;
|
||||
? RefCountReleaseStatus::kDroppedLastRef
|
||||
: RefCountReleaseStatus::kOtherRefsRemained;
|
||||
}
|
||||
|
||||
// Return whether the reference count is one. If the reference count is used
|
||||
|
||||
@ -102,7 +102,7 @@ class WeakReference {
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
friend class FinalRefCountedObject<Flag>;
|
||||
friend class webrtc::FinalRefCountedObject<Flag>;
|
||||
|
||||
~Flag() = default;
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import java.nio.ByteBuffer;
|
||||
|
||||
/** Class with static JNI helper functions that are used in many places. */
|
||||
public class JniCommon {
|
||||
/** Functions to increment/decrement an rtc::RefCountInterface pointer. */
|
||||
/** Functions to increment/decrement an RefCountInterface pointer. */
|
||||
public static native void nativeAddRef(long refCountedPointer);
|
||||
public static native void nativeReleaseRef(long refCountedPointer);
|
||||
|
||||
|
||||
@ -17,14 +17,12 @@ namespace jni {
|
||||
|
||||
static void JNI_JniCommon_AddRef(JNIEnv* jni,
|
||||
jlong j_native_ref_counted_pointer) {
|
||||
reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
|
||||
->AddRef();
|
||||
reinterpret_cast<RefCountInterface*>(j_native_ref_counted_pointer)->AddRef();
|
||||
}
|
||||
|
||||
static void JNI_JniCommon_ReleaseRef(JNIEnv* jni,
|
||||
jlong j_native_ref_counted_pointer) {
|
||||
reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
|
||||
->Release();
|
||||
reinterpret_cast<RefCountInterface*>(j_native_ref_counted_pointer)->Release();
|
||||
}
|
||||
|
||||
static ScopedJavaLocalRef<jobject> JNI_JniCommon_AllocateByteBuffer(JNIEnv* jni,
|
||||
|
||||
@ -71,7 +71,7 @@ class MappableNativeBuffer : public VideoFrameBuffer {
|
||||
bool DidConvertToI420() const;
|
||||
|
||||
private:
|
||||
friend class rtc::RefCountedObject<MappableNativeBuffer>;
|
||||
friend class RefCountedObject<MappableNativeBuffer>;
|
||||
|
||||
class ScaledBuffer : public VideoFrameBuffer {
|
||||
public:
|
||||
@ -97,7 +97,7 @@ class MappableNativeBuffer : public VideoFrameBuffer {
|
||||
rtc::ArrayView<VideoFrameBuffer::Type> types) override;
|
||||
|
||||
private:
|
||||
friend class rtc::RefCountedObject<ScaledBuffer>;
|
||||
friend class RefCountedObject<ScaledBuffer>;
|
||||
|
||||
const rtc::scoped_refptr<MappableNativeBuffer> parent_;
|
||||
const int width_;
|
||||
|
||||
@ -91,7 +91,7 @@ class VideoEncoderConfig {
|
||||
// kept alive until all encoder_specific_settings go out of scope.
|
||||
// TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig
|
||||
// and use absl::optional for encoder_specific_settings instead.
|
||||
class EncoderSpecificSettings : public rtc::RefCountInterface {
|
||||
class EncoderSpecificSettings : public RefCountInterface {
|
||||
public:
|
||||
// TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is
|
||||
// not in use and encoder implementations ask for codec-specific structs
|
||||
@ -139,7 +139,7 @@ class VideoEncoderConfig {
|
||||
kScreen,
|
||||
};
|
||||
|
||||
class VideoStreamFactoryInterface : public rtc::RefCountInterface {
|
||||
class VideoStreamFactoryInterface : public RefCountInterface {
|
||||
public:
|
||||
// An implementation should return a std::vector<VideoStream> with the
|
||||
// wanted VideoStream settings for the given video resolution.
|
||||
|
||||
@ -152,7 +152,7 @@ class TestBuffer : public webrtc::I420Buffer {
|
||||
: I420Buffer(width, height), event_(event) {}
|
||||
|
||||
private:
|
||||
friend class rtc::RefCountedObject<TestBuffer>;
|
||||
friend class RefCountedObject<TestBuffer>;
|
||||
~TestBuffer() override {
|
||||
if (event_)
|
||||
event_->Set();
|
||||
@ -184,7 +184,7 @@ class FakeNativeBuffer : public webrtc::VideoFrameBuffer {
|
||||
}
|
||||
|
||||
private:
|
||||
friend class rtc::RefCountedObject<FakeNativeBuffer>;
|
||||
friend class RefCountedObject<FakeNativeBuffer>;
|
||||
~FakeNativeBuffer() override {
|
||||
if (event_)
|
||||
event_->Set();
|
||||
@ -216,7 +216,7 @@ class FakeNV12NativeBuffer : public webrtc::VideoFrameBuffer {
|
||||
const NV12BufferInterface* GetNV12() const { return nv12_buffer_.get(); }
|
||||
|
||||
private:
|
||||
friend class rtc::RefCountedObject<FakeNV12NativeBuffer>;
|
||||
friend class RefCountedObject<FakeNV12NativeBuffer>;
|
||||
~FakeNV12NativeBuffer() override {
|
||||
if (event_)
|
||||
event_->Set();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user