stats: replace new with std::make_unique

apart from the certificate stats which need to update the
reference to the previous certificate stats in the chain.

BUG=None

Change-Id: I27f58084b849fd9afe236e5b57139bedb8eb1811
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/274175
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38026}
This commit is contained in:
Philipp Hancke 2022-09-06 11:55:31 +02:00 committed by WebRTC LUCI CQ
parent 839439ae84
commit b5cf12d9e8
3 changed files with 26 additions and 22 deletions

View file

@ -158,7 +158,7 @@ class RTC_EXPORT RTCStats {
const char this_class::kType[] = type_str; \ const char this_class::kType[] = type_str; \
\ \
std::unique_ptr<webrtc::RTCStats> this_class::copy() const { \ std::unique_ptr<webrtc::RTCStats> this_class::copy() const { \
return std::unique_ptr<webrtc::RTCStats>(new this_class(*this)); \ return std::make_unique<this_class>(*this); \
} \ } \
\ \
const char* this_class::type() const { return this_class::kType; } \ const char* this_class::type() const { return this_class::kType; } \
@ -189,7 +189,7 @@ class RTC_EXPORT RTCStats {
const char this_class::kType[] = type_str; \ const char this_class::kType[] = type_str; \
\ \
std::unique_ptr<webrtc::RTCStats> this_class::copy() const { \ std::unique_ptr<webrtc::RTCStats> this_class::copy() const { \
return std::unique_ptr<webrtc::RTCStats>(new this_class(*this)); \ return std::make_unique<this_class>(*this); \
} \ } \
\ \
const char* this_class::type() const { return this_class::kType; } \ const char* this_class::type() const { return this_class::kType; } \

View file

@ -360,10 +360,10 @@ std::unique_ptr<RTCCodecStats> CodecStatsFromRtpCodecParameters(
RTC_DCHECK_LE(codec_params.payload_type, 127); RTC_DCHECK_LE(codec_params.payload_type, 127);
RTC_DCHECK(codec_params.clock_rate); RTC_DCHECK(codec_params.clock_rate);
uint32_t payload_type = static_cast<uint32_t>(codec_params.payload_type); uint32_t payload_type = static_cast<uint32_t>(codec_params.payload_type);
std::unique_ptr<RTCCodecStats> codec_stats( std::unique_ptr<RTCCodecStats> codec_stats(std::make_unique<RTCCodecStats>(
new RTCCodecStats(RTCCodecStatsIDFromTransportAndCodecParameters( RTCCodecStatsIDFromTransportAndCodecParameters(direction, transport_id,
direction, transport_id, codec_params), codec_params),
timestamp_us)); timestamp_us));
codec_stats->payload_type = payload_type; codec_stats->payload_type = payload_type;
codec_stats->mime_type = codec_params.mime_type(); codec_stats->mime_type = codec_params.mime_type();
if (codec_params.clock_rate) { if (codec_params.clock_rate) {
@ -846,9 +846,11 @@ const std::string& ProduceIceCandidateStats(int64_t timestamp_us,
if (!stats) { if (!stats) {
std::unique_ptr<RTCIceCandidateStats> candidate_stats; std::unique_ptr<RTCIceCandidateStats> candidate_stats;
if (is_local) if (is_local)
candidate_stats.reset(new RTCLocalIceCandidateStats(id, timestamp_us)); candidate_stats =
std::make_unique<RTCLocalIceCandidateStats>(id, timestamp_us);
else else
candidate_stats.reset(new RTCRemoteIceCandidateStats(id, timestamp_us)); candidate_stats =
std::make_unique<RTCRemoteIceCandidateStats>(id, timestamp_us);
candidate_stats->transport_id = transport_id; candidate_stats->transport_id = transport_id;
if (is_local) { if (is_local) {
candidate_stats->network_type = candidate_stats->network_type =
@ -920,7 +922,7 @@ ProduceMediaStreamTrackStatsFromVoiceSenderInfo(
const cricket::VoiceSenderInfo& voice_sender_info, const cricket::VoiceSenderInfo& voice_sender_info,
int attachment_id) { int attachment_id) {
std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats( std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats(
new RTCMediaStreamTrackStats( std::make_unique<RTCMediaStreamTrackStats>(
RTCMediaStreamTrackStatsIDFromDirectionAndAttachment( RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
kDirectionOutbound, attachment_id), kDirectionOutbound, attachment_id),
timestamp_us, RTCMediaStreamTrackKind::kAudio)); timestamp_us, RTCMediaStreamTrackKind::kAudio));
@ -955,7 +957,7 @@ ProduceMediaStreamTrackStatsFromVoiceReceiverInfo(
// Since receiver tracks can't be reattached, we use the SSRC as // Since receiver tracks can't be reattached, we use the SSRC as
// an attachment identifier. // an attachment identifier.
std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats( std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats(
new RTCMediaStreamTrackStats( std::make_unique<RTCMediaStreamTrackStats>(
RTCMediaStreamTrackStatsIDFromDirectionAndAttachment( RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
kDirectionInbound, attachment_id), kDirectionInbound, attachment_id),
timestamp_us, RTCMediaStreamTrackKind::kAudio)); timestamp_us, RTCMediaStreamTrackKind::kAudio));
@ -1009,7 +1011,7 @@ ProduceMediaStreamTrackStatsFromVideoSenderInfo(
const cricket::VideoSenderInfo& video_sender_info, const cricket::VideoSenderInfo& video_sender_info,
int attachment_id) { int attachment_id) {
std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats( std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats(
new RTCMediaStreamTrackStats( std::make_unique<RTCMediaStreamTrackStats>(
RTCMediaStreamTrackStatsIDFromDirectionAndAttachment( RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
kDirectionOutbound, attachment_id), kDirectionOutbound, attachment_id),
timestamp_us, RTCMediaStreamTrackKind::kVideo)); timestamp_us, RTCMediaStreamTrackKind::kVideo));
@ -1038,7 +1040,7 @@ ProduceMediaStreamTrackStatsFromVideoReceiverInfo(
const cricket::VideoReceiverInfo& video_receiver_info, const cricket::VideoReceiverInfo& video_receiver_info,
int attachment_id) { int attachment_id) {
std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats( std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats(
new RTCMediaStreamTrackStats( std::make_unique<RTCMediaStreamTrackStats>(
RTCMediaStreamTrackStatsIDFromDirectionAndAttachment( RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
kDirectionInbound, attachment_id), kDirectionInbound, attachment_id),
timestamp_us, RTCMediaStreamTrackKind::kVideo)); timestamp_us, RTCMediaStreamTrackKind::kVideo));
@ -1667,8 +1669,8 @@ void RTCStatsCollector::ProduceDataChannelStats_s(
std::vector<DataChannelStats> data_stats = pc_->GetDataChannelStats(); std::vector<DataChannelStats> data_stats = pc_->GetDataChannelStats();
for (const auto& stats : data_stats) { for (const auto& stats : data_stats) {
std::unique_ptr<RTCDataChannelStats> data_channel_stats( std::unique_ptr<RTCDataChannelStats> data_channel_stats(
new RTCDataChannelStats("D" + rtc::ToString(stats.internal_id), std::make_unique<RTCDataChannelStats>(
timestamp_us)); "D" + rtc::ToString(stats.internal_id), timestamp_us));
data_channel_stats->label = std::move(stats.label); data_channel_stats->label = std::move(stats.label);
data_channel_stats->protocol = std::move(stats.protocol); data_channel_stats->protocol = std::move(stats.protocol);
data_channel_stats->data_channel_identifier = stats.id; data_channel_stats->data_channel_identifier = stats.id;
@ -1699,7 +1701,7 @@ void RTCStatsCollector::ProduceIceCandidateAndPairStats_n(
for (const auto& info : for (const auto& info :
channel_stats.ice_transport_stats.connection_infos) { channel_stats.ice_transport_stats.connection_infos) {
std::unique_ptr<RTCIceCandidatePairStats> candidate_pair_stats( std::unique_ptr<RTCIceCandidatePairStats> candidate_pair_stats(
new RTCIceCandidatePairStats( std::make_unique<RTCIceCandidatePairStats>(
RTCIceCandidatePairStatsIDFromConnectionInfo(info), RTCIceCandidatePairStatsIDFromConnectionInfo(info),
timestamp_us)); timestamp_us));
@ -1815,7 +1817,8 @@ void RTCStatsCollector::ProduceMediaStreamStats_s(
// Build stats for each stream ID known. // Build stats for each stream ID known.
for (auto& it : track_ids) { for (auto& it : track_ids) {
std::unique_ptr<RTCMediaStreamStats> stream_stats( std::unique_ptr<RTCMediaStreamStats> stream_stats(
new RTCMediaStreamStats("DEPRECATED_S" + it.first, timestamp_us)); std::make_unique<RTCMediaStreamStats>("DEPRECATED_S" + it.first,
timestamp_us));
stream_stats->stream_identifier = it.first; stream_stats->stream_identifier = it.first;
stream_stats->track_ids = it.second; stream_stats->track_ids = it.second;
report->AddStats(std::move(stream_stats)); report->AddStats(std::move(stream_stats));
@ -1953,7 +1956,7 @@ void RTCStatsCollector::ProducePeerConnectionStats_s(
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
std::unique_ptr<RTCPeerConnectionStats> stats( std::unique_ptr<RTCPeerConnectionStats> stats(
new RTCPeerConnectionStats("P", timestamp_us)); std::make_unique<RTCPeerConnectionStats>("P", timestamp_us));
stats->data_channels_opened = internal_record_.data_channels_opened; stats->data_channels_opened = internal_record_.data_channels_opened;
stats->data_channels_closed = internal_record_.data_channels_closed; stats->data_channels_closed = internal_record_.data_channels_closed;
report->AddStats(std::move(stats)); report->AddStats(std::move(stats));
@ -2200,9 +2203,10 @@ void RTCStatsCollector::ProduceTransportStats_n(
for (const cricket::TransportChannelStats& channel_stats : for (const cricket::TransportChannelStats& channel_stats :
transport_stats.channel_stats) { transport_stats.channel_stats) {
std::unique_ptr<RTCTransportStats> transport_stats( std::unique_ptr<RTCTransportStats> transport_stats(
new RTCTransportStats(RTCTransportStatsIDFromTransportChannel( std::make_unique<RTCTransportStats>(
transport_name, channel_stats.component), RTCTransportStatsIDFromTransportChannel(transport_name,
timestamp_us)); channel_stats.component),
timestamp_us));
transport_stats->packets_sent = transport_stats->packets_sent =
channel_stats.ice_transport_stats.packets_sent; channel_stats.ice_transport_stats.packets_sent;
transport_stats->packets_received = transport_stats->packets_received =

View file

@ -335,7 +335,7 @@ RTCLocalIceCandidateStats::RTCLocalIceCandidateStats(std::string&& id,
: RTCIceCandidateStats(std::move(id), timestamp_us, false) {} : RTCIceCandidateStats(std::move(id), timestamp_us, false) {}
std::unique_ptr<RTCStats> RTCLocalIceCandidateStats::copy() const { std::unique_ptr<RTCStats> RTCLocalIceCandidateStats::copy() const {
return std::unique_ptr<RTCStats>(new RTCLocalIceCandidateStats(*this)); return std::make_unique<RTCLocalIceCandidateStats>(*this);
} }
const char* RTCLocalIceCandidateStats::type() const { const char* RTCLocalIceCandidateStats::type() const {
@ -353,7 +353,7 @@ RTCRemoteIceCandidateStats::RTCRemoteIceCandidateStats(std::string&& id,
: RTCIceCandidateStats(std::move(id), timestamp_us, true) {} : RTCIceCandidateStats(std::move(id), timestamp_us, true) {}
std::unique_ptr<RTCStats> RTCRemoteIceCandidateStats::copy() const { std::unique_ptr<RTCStats> RTCRemoteIceCandidateStats::copy() const {
return std::unique_ptr<RTCStats>(new RTCRemoteIceCandidateStats(*this)); return std::make_unique<RTCRemoteIceCandidateStats>(*this);
} }
const char* RTCRemoteIceCandidateStats::type() const { const char* RTCRemoteIceCandidateStats::type() const {