Avoid more usage of implicit conversion from scoped_refptr<T> to T*

Update api/, call/, examples/ and rtc_tools/.

Bug: webrtc:13464
Change-Id: I7b0008cca68c579e89b45527a45300d1e67c3483
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260000
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36673}
This commit is contained in:
Niels Möller
2022-04-25 16:59:19 +02:00
committed by WebRTC LUCI CQ
parent e7d998cb64
commit df209e797b
10 changed files with 44 additions and 47 deletions

View File

@ -203,7 +203,7 @@ void VideoEncoderSoftwareFallbackWrapperTestBase::EncodeFrame(
int expected_ret) { int expected_ret) {
rtc::scoped_refptr<I420Buffer> buffer = rtc::scoped_refptr<I420Buffer> buffer =
I420Buffer::Create(codec_.width, codec_.height); I420Buffer::Create(codec_.width, codec_.height);
I420Buffer::SetBlack(buffer); I420Buffer::SetBlack(buffer.get());
std::vector<VideoFrameType> types(1, VideoFrameType::kVideoFrameKey); std::vector<VideoFrameType> types(1, VideoFrameType::kVideoFrameKey);
frame_ = frame_ =

View File

@ -79,7 +79,7 @@ std::string VideoEncoderConfig::ToString() const {
break; break;
} }
ss << ", encoder_specific_settings: "; ss << ", encoder_specific_settings: ";
ss << (encoder_specific_settings != NULL ? "(ptr)" : "NULL"); ss << (encoder_specific_settings != nullptr ? "(ptr)" : "NULL");
ss << ", min_transmit_bitrate_bps: " << min_transmit_bitrate_bps; ss << ", min_transmit_bitrate_bps: " << min_transmit_bitrate_bps;
ss << '}'; ss << '}';

View File

@ -113,7 +113,7 @@ void ResourceAdaptationProcessor::AddResource(
<< "Resource \"" << resource->Name() << "\" was already registered."; << "Resource \"" << resource->Name() << "\" was already registered.";
resources_.push_back(resource); resources_.push_back(resource);
} }
resource->SetResourceListener(resource_listener_delegate_); resource->SetResourceListener(resource_listener_delegate_.get());
RTC_LOG(LS_INFO) << "Registered resource \"" << resource->Name() << "\"."; RTC_LOG(LS_INFO) << "Registered resource \"" << resource->Name() << "\".";
} }

View File

@ -170,7 +170,7 @@ void AndroidCallClient::CreatePeerConnectionFactory() {
RTC_LOG(LS_INFO) << "Media engine created: " << pcf_deps.media_engine.get(); RTC_LOG(LS_INFO) << "Media engine created: " << pcf_deps.media_engine.get();
pcf_ = CreateModularPeerConnectionFactory(std::move(pcf_deps)); pcf_ = CreateModularPeerConnectionFactory(std::move(pcf_deps));
RTC_LOG(LS_INFO) << "PeerConnectionFactory created: " << pcf_; RTC_LOG(LS_INFO) << "PeerConnectionFactory created: " << pcf_.get();
} }
void AndroidCallClient::CreatePeerConnection() { void AndroidCallClient::CreatePeerConnection() {
@ -184,13 +184,13 @@ void AndroidCallClient::CreatePeerConnection() {
webrtc::PeerConnectionDependencies deps(pc_observer_.get()); webrtc::PeerConnectionDependencies deps(pc_observer_.get());
pc_ = pcf_->CreatePeerConnectionOrError(config, std::move(deps)).MoveValue(); pc_ = pcf_->CreatePeerConnectionOrError(config, std::move(deps)).MoveValue();
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_; RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track = rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track(
pcf_->CreateVideoTrack("video", video_source_); pcf_->CreateVideoTrack("video", video_source_.get()));
local_video_track->AddOrUpdateSink(local_sink_.get(), rtc::VideoSinkWants()); local_video_track->AddOrUpdateSink(local_sink_.get(), rtc::VideoSinkWants());
pc_->AddTransceiver(local_video_track); pc_->AddTransceiver(local_video_track);
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track; RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();
for (const rtc::scoped_refptr<webrtc::RtpTransceiverInterface>& tranceiver : for (const rtc::scoped_refptr<webrtc::RtpTransceiverInterface>& tranceiver :
pc_->GetTransceivers()) { pc_->GetTransceivers()) {
@ -200,7 +200,7 @@ void AndroidCallClient::CreatePeerConnection() {
track->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) { track->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) {
static_cast<webrtc::VideoTrackInterface*>(track.get()) static_cast<webrtc::VideoTrackInterface*>(track.get())
->AddOrUpdateSink(remote_sink_.get(), rtc::VideoSinkWants()); ->AddOrUpdateSink(remote_sink_.get(), rtc::VideoSinkWants());
RTC_LOG(LS_INFO) << "Remote video sink set up: " << track; RTC_LOG(LS_INFO) << "Remote video sink set up: " << track.get();
break; break;
} }
} }
@ -208,7 +208,7 @@ void AndroidCallClient::CreatePeerConnection() {
void AndroidCallClient::Connect() { void AndroidCallClient::Connect() {
webrtc::MutexLock lock(&pc_mutex_); webrtc::MutexLock lock(&pc_mutex_);
pc_->CreateOffer(rtc::make_ref_counted<CreateOfferObserver>(pc_), pc_->CreateOffer(rtc::make_ref_counted<CreateOfferObserver>(pc_).get(),
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions()); webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
} }
@ -258,7 +258,7 @@ void CreateOfferObserver::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
// Ownership of desc was transferred to us, now we transfer it forward. // Ownership of desc was transferred to us, now we transfer it forward.
pc_->SetLocalDescription( pc_->SetLocalDescription(
rtc::make_ref_counted<SetLocalSessionDescriptionObserver>(), desc); rtc::make_ref_counted<SetLocalSessionDescriptionObserver>().get(), desc);
// Generate a fake answer. // Generate a fake answer.
std::unique_ptr<webrtc::SessionDescriptionInterface> answer( std::unique_ptr<webrtc::SessionDescriptionInterface> answer(

View File

@ -50,10 +50,9 @@ class SetRemoteSessionDescriptionObserver : public webrtc::SetRemoteDescriptionO
void OnSetRemoteDescriptionComplete(webrtc::RTCError error) override; void OnSetRemoteDescriptionComplete(webrtc::RTCError error) override;
}; };
class SetLocalSessionDescriptionObserver : public webrtc::SetSessionDescriptionObserver { class SetLocalSessionDescriptionObserver : public webrtc::SetLocalDescriptionObserverInterface {
public: public:
void OnSuccess() override; void OnSetLocalDescriptionComplete(webrtc::RTCError error) override;
void OnFailure(webrtc::RTCError error) override;
}; };
} // namespace } // namespace
@ -134,7 +133,7 @@ void ObjCCallClient::CreatePeerConnectionFactory() {
dependencies.event_log_factory = dependencies.event_log_factory =
std::make_unique<webrtc::RtcEventLogFactory>(dependencies.task_queue_factory.get()); std::make_unique<webrtc::RtcEventLogFactory>(dependencies.task_queue_factory.get());
pcf_ = webrtc::CreateModularPeerConnectionFactory(std::move(dependencies)); pcf_ = webrtc::CreateModularPeerConnectionFactory(std::move(dependencies));
RTC_LOG(LS_INFO) << "PeerConnectionFactory created: " << pcf_; RTC_LOG(LS_INFO) << "PeerConnectionFactory created: " << pcf_.get();
} }
void ObjCCallClient::CreatePeerConnection() { void ObjCCallClient::CreatePeerConnection() {
@ -147,12 +146,12 @@ void ObjCCallClient::CreatePeerConnection() {
pcf_->SetOptions(options); pcf_->SetOptions(options);
webrtc::PeerConnectionDependencies pc_dependencies(pc_observer_.get()); webrtc::PeerConnectionDependencies pc_dependencies(pc_observer_.get());
pc_ = pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies)).MoveValue(); pc_ = pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies)).MoveValue();
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_; RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track = rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track =
pcf_->CreateVideoTrack("video", video_source_); pcf_->CreateVideoTrack("video", video_source_.get());
pc_->AddTransceiver(local_video_track); pc_->AddTransceiver(local_video_track);
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track; RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();
for (const rtc::scoped_refptr<webrtc::RtpTransceiverInterface>& tranceiver : for (const rtc::scoped_refptr<webrtc::RtpTransceiverInterface>& tranceiver :
pc_->GetTransceivers()) { pc_->GetTransceivers()) {
@ -160,7 +159,7 @@ void ObjCCallClient::CreatePeerConnection() {
if (track && track->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) { if (track && track->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) {
static_cast<webrtc::VideoTrackInterface*>(track.get()) static_cast<webrtc::VideoTrackInterface*>(track.get())
->AddOrUpdateSink(remote_sink_.get(), rtc::VideoSinkWants()); ->AddOrUpdateSink(remote_sink_.get(), rtc::VideoSinkWants());
RTC_LOG(LS_INFO) << "Remote video sink set up: " << track; RTC_LOG(LS_INFO) << "Remote video sink set up: " << track.get();
break; break;
} }
} }
@ -168,7 +167,7 @@ void ObjCCallClient::CreatePeerConnection() {
void ObjCCallClient::Connect() { void ObjCCallClient::Connect() {
webrtc::MutexLock lock(&pc_mutex_); webrtc::MutexLock lock(&pc_mutex_);
pc_->CreateOffer(rtc::make_ref_counted<CreateOfferObserver>(pc_), pc_->CreateOffer(rtc::make_ref_counted<CreateOfferObserver>(pc_).get(),
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions()); webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
} }
@ -214,7 +213,8 @@ void CreateOfferObserver::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
RTC_LOG(LS_INFO) << "Created offer: " << sdp; RTC_LOG(LS_INFO) << "Created offer: " << sdp;
// Ownership of desc was transferred to us, now we transfer it forward. // Ownership of desc was transferred to us, now we transfer it forward.
pc_->SetLocalDescription(rtc::make_ref_counted<SetLocalSessionDescriptionObserver>(), desc); pc_->SetLocalDescription(absl::WrapUnique(desc),
rtc::make_ref_counted<SetLocalSessionDescriptionObserver>());
// Generate a fake answer. // Generate a fake answer.
std::unique_ptr<webrtc::SessionDescriptionInterface> answer( std::unique_ptr<webrtc::SessionDescriptionInterface> answer(
@ -231,12 +231,8 @@ void SetRemoteSessionDescriptionObserver::OnSetRemoteDescriptionComplete(webrtc:
RTC_LOG(LS_INFO) << "Set remote description: " << error.message(); RTC_LOG(LS_INFO) << "Set remote description: " << error.message();
} }
void SetLocalSessionDescriptionObserver::OnSuccess() { void SetLocalSessionDescriptionObserver::OnSetLocalDescriptionComplete(webrtc::RTCError error) {
RTC_LOG(LS_INFO) << "Set local description success!"; RTC_LOG(LS_INFO) << "Set local description: " << error.message();
}
void SetLocalSessionDescriptionObserver::OnFailure(webrtc::RTCError error) {
RTC_LOG(LS_INFO) << "Set local description failure: " << error.message();
} }
} // namespace webrtc_examples } // namespace webrtc_examples

View File

@ -369,7 +369,7 @@ void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) {
} }
RTC_LOG(LS_INFO) << " Received session description :" << message; RTC_LOG(LS_INFO) << " Received session description :" << message;
peer_connection_->SetRemoteDescription( peer_connection_->SetRemoteDescription(
DummySetSessionDescriptionObserver::Create(), DummySetSessionDescriptionObserver::Create().get(),
session_description.release()); session_description.release());
if (type == webrtc::SdpType::kOffer) { if (type == webrtc::SdpType::kOffer) {
peer_connection_->CreateAnswer( peer_connection_->CreateAnswer(
@ -456,8 +456,9 @@ void Conductor::AddTracks() {
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
peer_connection_factory_->CreateAudioTrack( peer_connection_factory_->CreateAudioTrack(
kAudioLabel, peer_connection_factory_->CreateAudioSource( kAudioLabel,
cricket::AudioOptions()))); peer_connection_factory_->CreateAudioSource(cricket::AudioOptions())
.get()));
auto result_or_error = peer_connection_->AddTrack(audio_track, {kStreamId}); auto result_or_error = peer_connection_->AddTrack(audio_track, {kStreamId});
if (!result_or_error.ok()) { if (!result_or_error.ok()) {
RTC_LOG(LS_ERROR) << "Failed to add audio track to PeerConnection: " RTC_LOG(LS_ERROR) << "Failed to add audio track to PeerConnection: "
@ -468,8 +469,9 @@ void Conductor::AddTracks() {
CapturerTrackSource::Create(); CapturerTrackSource::Create();
if (video_device) { if (video_device) {
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_( rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_(
peer_connection_factory_->CreateVideoTrack(kVideoLabel, video_device)); peer_connection_factory_->CreateVideoTrack(kVideoLabel,
main_wnd_->StartLocalRenderer(video_track_); video_device.get()));
main_wnd_->StartLocalRenderer(video_track_.get());
result_or_error = peer_connection_->AddTrack(video_track_, {kStreamId}); result_or_error = peer_connection_->AddTrack(video_track_, {kStreamId});
if (!result_or_error.ok()) { if (!result_or_error.ok()) {
@ -563,7 +565,7 @@ void Conductor::UIThreadCallback(int msg_id, void* data) {
void Conductor::OnSuccess(webrtc::SessionDescriptionInterface* desc) { void Conductor::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
peer_connection_->SetLocalDescription( peer_connection_->SetLocalDescription(
DummySetSessionDescriptionObserver::Create(), desc); DummySetSessionDescriptionObserver::Create().get(), desc);
std::string sdp; std::string sdp;
desc->ToString(&sdp); desc->ToString(&sdp);
@ -574,7 +576,7 @@ void Conductor::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
std::unique_ptr<webrtc::SessionDescriptionInterface> session_description = std::unique_ptr<webrtc::SessionDescriptionInterface> session_description =
webrtc::CreateSessionDescription(webrtc::SdpType::kAnswer, sdp); webrtc::CreateSessionDescription(webrtc::SdpType::kAnswer, sdp);
peer_connection_->SetRemoteDescription( peer_connection_->SetRemoteDescription(
DummySetSessionDescriptionObserver::Create(), DummySetSessionDescriptionObserver::Create().get(),
session_description.release()); session_description.release());
return; return;
} }

View File

@ -103,7 +103,7 @@ int main(int argc, char* argv[]) {
PeerConnectionClient client; PeerConnectionClient client;
auto conductor = rtc::make_ref_counted<Conductor>(&client, &wnd); auto conductor = rtc::make_ref_counted<Conductor>(&client, &wnd);
socket_server.set_client(&client); socket_server.set_client(&client);
socket_server.set_conductor(conductor); socket_server.set_conductor(conductor.get());
thread.Run(); thread.Run();

View File

@ -98,7 +98,7 @@ std::string GetPeerConnectionString() {
class DummySetSessionDescriptionObserver class DummySetSessionDescriptionObserver
: public webrtc::SetSessionDescriptionObserver { : public webrtc::SetSessionDescriptionObserver {
public: public:
static DummySetSessionDescriptionObserver* Create() { static rtc::scoped_refptr<DummySetSessionDescriptionObserver> Create() {
return rtc::make_ref_counted<DummySetSessionDescriptionObserver>(); return rtc::make_ref_counted<DummySetSessionDescriptionObserver>();
} }
virtual void OnSuccess() { RTC_LOG(LS_INFO) << __FUNCTION__; } virtual void OnSuccess() { RTC_LOG(LS_INFO) << __FUNCTION__; }
@ -259,7 +259,7 @@ bool SimplePeerConnection::CreateAnswer() {
void SimplePeerConnection::OnSuccess( void SimplePeerConnection::OnSuccess(
webrtc::SessionDescriptionInterface* desc) { webrtc::SessionDescriptionInterface* desc) {
peer_connection_->SetLocalDescription( peer_connection_->SetLocalDescription(
DummySetSessionDescriptionObserver::Create(), desc); DummySetSessionDescriptionObserver::Create().get(), desc);
std::string sdp; std::string sdp;
desc->ToString(&sdp); desc->ToString(&sdp);
@ -350,7 +350,7 @@ bool SimplePeerConnection::SetRemoteDescription(const char* type,
} }
RTC_LOG(LS_INFO) << " Received session description :" << remote_desc; RTC_LOG(LS_INFO) << " Received session description :" << remote_desc;
peer_connection_->SetRemoteDescription( peer_connection_->SetRemoteDescription(
DummySetSessionDescriptionObserver::Create(), session_description); DummySetSessionDescriptionObserver::Create().get(), session_description);
return true; return true;
} }
@ -392,8 +392,7 @@ void SimplePeerConnection::SetAudioControl() {
if (tracks.empty()) if (tracks.empty())
return; return;
webrtc::AudioTrackInterface* audio_track = tracks[0]; rtc::scoped_refptr<webrtc::AudioTrackInterface>& audio_track = tracks[0];
std::string id = audio_track->id();
if (is_record_audio_) if (is_record_audio_)
audio_track->AddSink(this); audio_track->AddSink(this);
else else
@ -427,9 +426,9 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
g_peer_connection_factory->CreateAudioTrack( g_peer_connection_factory->CreateAudioTrack(
kAudioLabel, g_peer_connection_factory->CreateAudioSource( kAudioLabel,
cricket::AudioOptions()))); g_peer_connection_factory->CreateAudioSource(cricket::AudioOptions())
std::string id = audio_track->id(); .get()));
stream->AddTrack(audio_track); stream->AddTrack(audio_track);
if (!audio_only) { if (!audio_only) {
@ -470,7 +469,7 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
if (video_device) { if (video_device) {
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
g_peer_connection_factory->CreateVideoTrack(kVideoLabel, g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
video_device)); video_device.get()));
stream->AddTrack(video_track); stream->AddTrack(video_track);
} }
@ -481,7 +480,7 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
} }
} }
if (!peer_connection_->AddStream(stream)) { if (!peer_connection_->AddStream(stream.get())) {
RTC_LOG(LS_ERROR) << "Adding stream to PeerConnection failed"; RTC_LOG(LS_ERROR) << "Adding stream to PeerConnection failed";
} }

View File

@ -112,7 +112,7 @@ class SimplePeerConnection : public webrtc::PeerConnectionObserver,
std::unique_ptr<VideoObserver> local_video_observer_; std::unique_ptr<VideoObserver> local_video_observer_;
std::unique_ptr<VideoObserver> remote_video_observer_; std::unique_ptr<VideoObserver> remote_video_observer_;
webrtc::MediaStreamInterface* remote_stream_ = nullptr; rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream_ = nullptr;
webrtc::PeerConnectionInterface::RTCConfiguration config_; webrtc::PeerConnectionInterface::RTCConfiguration config_;
LOCALDATACHANNELREADY_CALLBACK OnLocalDataChannelReady = nullptr; LOCALDATACHANNELREADY_CALLBACK OnLocalDataChannelReady = nullptr;

View File

@ -173,7 +173,7 @@ int RunServer() {
peer_connection->CreateDataChannelOrError("benchmark", nullptr); peer_connection->CreateDataChannelOrError("benchmark", nullptr);
auto data_channel = dc_or_error.MoveValue(); auto data_channel = dc_or_error.MoveValue();
auto data_channel_observer = auto data_channel_observer =
std::make_unique<DataChannelObserverImpl>(data_channel); std::make_unique<DataChannelObserverImpl>(data_channel.get());
data_channel->RegisterObserver(data_channel_observer.get()); data_channel->RegisterObserver(data_channel_observer.get());
absl::Cleanup unregister_observer( absl::Cleanup unregister_observer(
[data_channel] { data_channel->UnregisterObserver(); }); [data_channel] { data_channel->UnregisterObserver(); });