clang-tidy: apply modernize-use-designated-initializer to examples/ net/ rtc_tools/ test

split from
  https://webrtc-review.googlesource.com/c/src/+/404061
see there for full history and manual changes

Bug: webrtc:424706384
Change-Id: I6e892f83a2366f78e5b911b2aa792b79f0ecf128
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/405062
Commit-Queue: Philipp Hancke <phancke@meta.com>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45407}
This commit is contained in:
Philipp Hancke 2025-08-20 14:10:25 -07:00 committed by WebRTC LUCI CQ
parent 1c0ba91c85
commit 08ddcf8140
17 changed files with 88 additions and 54 deletions

View File

@ -198,9 +198,9 @@ bool DataSocket::ParseMethodAndPath(const char* begin, size_t len) {
size_t method_name_len;
RequestMethod id;
} supported_methods[] = {
{"GET", 3, GET},
{"POST", 4, POST},
{"OPTIONS", 7, OPTIONS},
{.method_name = "GET", .method_name_len = 3, .id = GET},
{.method_name = "POST", .method_name_len = 4, .id = POST},
{.method_name = "OPTIONS", .method_name_len = 7, .id = OPTIONS},
};
const char* path = nullptr;
@ -277,7 +277,7 @@ bool ListeningSocket::Listen(unsigned short port) {
printf("setsockopt failed\n");
return false;
}
struct sockaddr_in addr = {0};
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(port);
@ -291,7 +291,7 @@ bool ListeningSocket::Listen(unsigned short port) {
DataSocket* ListeningSocket::Accept() const {
RTC_DCHECK(valid());
struct sockaddr_in addr = {0};
struct sockaddr_in addr = {};
socklen_t size = sizeof(addr);
NativeSocket client =
accept(socket_, reinterpret_cast<sockaddr*>(&addr), &size);

View File

@ -105,7 +105,7 @@ int main(int argc, char* argv[]) {
for (SocketArray::iterator i = sockets.begin(); i != sockets.end(); ++i)
FD_SET((*i)->socket(), &socket_set);
struct timeval timeout = {10, 0};
struct timeval timeout = {.tv_sec = 10, .tv_usec = 0};
if (select(FD_SETSIZE, &socket_set, nullptr, nullptr, &timeout) ==
SOCKET_ERROR) {
printf("select failed\n");

View File

@ -99,7 +99,7 @@ void CallbackDeferrer::OnError(ErrorKind error, absl::string_view message) {
Error error = std::get<Error>(std::move(data));
return cb.OnError(error.error, error.message);
},
Error{error, std::string(message)});
Error{.error = error, .message = std::string(message)});
}
void CallbackDeferrer::OnAborted(ErrorKind error, absl::string_view message) {
@ -109,7 +109,7 @@ void CallbackDeferrer::OnAborted(ErrorKind error, absl::string_view message) {
Error error = std::get<Error>(std::move(data));
return cb.OnAborted(error.error, error.message);
},
Error{error, std::string(message)});
Error{.error = error, .message = std::string(message)});
}
void CallbackDeferrer::OnConnected() {
@ -149,8 +149,8 @@ void CallbackDeferrer::OnStreamsResetFailed(
return cb.OnStreamsResetFailed(stream_reset.streams,
stream_reset.message);
},
StreamReset{{outgoing_streams.begin(), outgoing_streams.end()},
std::string(reason)});
StreamReset{.streams = {outgoing_streams.begin(), outgoing_streams.end()},
.message = std::string(reason)});
}
void CallbackDeferrer::OnStreamsResetPerformed(
@ -161,7 +161,8 @@ void CallbackDeferrer::OnStreamsResetPerformed(
StreamReset stream_reset = std::get<StreamReset>(std::move(data));
return cb.OnStreamsResetPerformed(stream_reset.streams);
},
StreamReset{{outgoing_streams.begin(), outgoing_streams.end()}});
StreamReset{
.streams = {outgoing_streams.begin(), outgoing_streams.end()}});
}
void CallbackDeferrer::OnIncomingStreamsReset(
@ -172,7 +173,8 @@ void CallbackDeferrer::OnIncomingStreamsReset(
StreamReset stream_reset = std::get<StreamReset>(std::move(data));
return cb.OnIncomingStreamsReset(stream_reset.streams);
},
StreamReset{{incoming_streams.begin(), incoming_streams.end()}});
StreamReset{
.streams = {incoming_streams.begin(), incoming_streams.end()}});
}
void CallbackDeferrer::OnBufferedAmountLow(StreamID stream_id) {

View File

@ -179,13 +179,19 @@ uint32_t GetDefaultTargetBitrate(const VideoCodecType codec,
// The three values are for H264/VP8, VP9 and AV1, respectively.
double bitrate[2][3];
} kBitrateTable[] = {
{0, {{77.5, 65.0, 60.0}, {100.0, 100.0, 100.0}}},
{240 * 160, {{77.5, 65.0, 60.0}, {115.0, 100.0, 100.0}}},
{320 * 240, {{165.0, 105.0, 105.0}, {230.0, 180.0, 180.0}}},
{480 * 270, {{195.0, 180.0, 180.0}, {320.0, 250, 250}}},
{640 * 480, {{550.0, 355.0, 342.5}, {690.0, 520, 520}}},
{1280 * 720, {{1700.0, 990.0, 800.0}, {2500.0, 1500, 1200}}},
{1920 * 1080, {{2480.0, 2060.0, 1500.0}, {4000.0, 3350.0, 2500.0}}},
{.area = 0, .bitrate = {{77.5, 65.0, 60.0}, {100.0, 100.0, 100.0}}},
{.area = 240 * 160,
.bitrate = {{77.5, 65.0, 60.0}, {115.0, 100.0, 100.0}}},
{.area = 320 * 240,
.bitrate = {{165.0, 105.0, 105.0}, {230.0, 180.0, 180.0}}},
{.area = 480 * 270,
.bitrate = {{195.0, 180.0, 180.0}, {320.0, 250, 250}}},
{.area = 640 * 480,
.bitrate = {{550.0, 355.0, 342.5}, {690.0, 520, 520}}},
{.area = 1280 * 720,
.bitrate = {{1700.0, 990.0, 800.0}, {2500.0, 1500, 1200}}},
{.area = 1920 * 1080,
.bitrate = {{2480.0, 2060.0, 1500.0}, {4000.0, 3350.0, 2500.0}}},
};
size_t codec_index = 0;
switch (codec) {

View File

@ -181,13 +181,16 @@ YuvFileGenerator::~YuvFileGenerator() {
FrameGeneratorInterface::VideoFrameData YuvFileGenerator::NextFrame() {
// Empty update by default.
VideoFrame::UpdateRect update_rect{0, 0, 0, 0};
VideoFrame::UpdateRect update_rect{
.offset_x = 0, .offset_y = 0, .width = 0, .height = 0};
if (current_display_count_ == 0) {
const bool got_new_frame = ReadNextFrame();
// Full update on a new frame from file.
if (got_new_frame) {
update_rect = VideoFrame::UpdateRect{0, 0, static_cast<int>(width_),
static_cast<int>(height_)};
update_rect = VideoFrame::UpdateRect{.offset_x = 0,
.offset_y = 0,
.width = static_cast<int>(width_),
.height = static_cast<int>(height_)};
}
}
if (++current_display_count_ >= frame_display_count_)
@ -247,13 +250,16 @@ NV12FileGenerator::~NV12FileGenerator() {
FrameGeneratorInterface::VideoFrameData NV12FileGenerator::NextFrame() {
// Empty update by default.
VideoFrame::UpdateRect update_rect{0, 0, 0, 0};
VideoFrame::UpdateRect update_rect{
.offset_x = 0, .offset_y = 0, .width = 0, .height = 0};
if (current_display_count_ == 0) {
const bool got_new_frame = ReadNextFrame();
// Full update on a new frame from file.
if (got_new_frame) {
update_rect = VideoFrame::UpdateRect{0, 0, static_cast<int>(width_),
static_cast<int>(height_)};
update_rect = VideoFrame::UpdateRect{.offset_x = 0,
.offset_y = 0,
.width = static_cast<int>(width_),
.height = static_cast<int>(height_)};
}
}
if (++current_display_count_ >= frame_display_count_)
@ -407,7 +413,10 @@ ScrollingImageFrameGenerator::NextFrame() {
if (!same_scroll_position) {
// If scrolling is not finished yet, force full frame update.
current_frame_.update_rect =
VideoFrame::UpdateRect{0, 0, target_width_, target_height_};
VideoFrame::UpdateRect{.offset_x = 0,
.offset_y = 0,
.width = target_width_,
.height = target_height_};
}
prev_frame_not_scrolled_ = cur_frame_not_scrolled;
@ -421,7 +430,8 @@ ScrollingImageFrameGenerator::GetResolution() const {
}
void ScrollingImageFrameGenerator::UpdateSourceFrame(size_t frame_num) {
VideoFrame::UpdateRect acc_update{0, 0, 0, 0};
VideoFrame::UpdateRect acc_update{
.offset_x = 0, .offset_y = 0, .width = 0, .height = 0};
while (current_frame_num_ != frame_num) {
current_source_frame_ = file_generator_.NextFrame();
if (current_source_frame_.update_rect) {
@ -452,8 +462,14 @@ void ScrollingImageFrameGenerator::CropSourceToScrolledImage(
VideoFrame::UpdateRect update_rect =
current_source_frame_.update_rect->IsEmpty()
? VideoFrame::UpdateRect{0, 0, 0, 0}
: VideoFrame::UpdateRect{0, 0, target_width_, target_height_};
? VideoFrame::UpdateRect{.offset_x = 0,
.offset_y = 0,
.width = 0,
.height = 0}
: VideoFrame::UpdateRect{.offset_x = 0,
.offset_y = 0,
.width = target_width_,
.height = target_height_};
current_frame_ = VideoFrameData(
WrapI420Buffer(target_width_, target_height_,
&i420_buffer->DataY()[offset_y], i420_buffer->StrideY(),

View File

@ -167,13 +167,14 @@ void TcpMessageRouteImpl::SendMessage(size_t size,
int64_t data_left = static_cast<int64_t>(size);
int64_t kMaxPacketSize = 1200;
int64_t kMinPacketSize = 4;
Message message{std::move(handler)};
Message message{.handler = std::move(handler)};
while (data_left > 0) {
int64_t packet_size = std::min(data_left, kMaxPacketSize);
int fragment_id = next_fragment_id_++;
pending_.push_back(MessageFragment{
fragment_id,
static_cast<size_t>(std::max(kMinPacketSize, packet_size))});
.fragment_id = fragment_id,
.size =
static_cast<size_t>(std::max(kMinPacketSize, packet_size))});
message.pending_fragment_ids.insert(fragment_id);
data_left -= packet_size;
}

View File

@ -683,7 +683,9 @@ std::optional<uint16_t> EmulatedEndpointImpl::BindReceiverInternal(
RTC_CHECK(port != 0) << "Can't find free port for receiver in endpoint "
<< options_.log_name << "; id=" << options_.id;
bool result =
port_to_receiver_.insert({port, {receiver, is_one_shot}}).second;
port_to_receiver_
.insert({port, {.receiver = receiver, .is_one_shot = is_one_shot}})
.second;
if (!result) {
RTC_LOG(LS_INFO) << "Can't bind receiver to used port " << desired_port
<< " in endpoint " << options_.log_name

View File

@ -134,7 +134,8 @@ std::optional<T> MaybeGetValue(const std::map<size_t, T>& map, size_t key) {
SamplesStatsCounter::StatsSample StatsSample(double value,
Timestamp sampling_time) {
return SamplesStatsCounter::StatsSample{value, sampling_time};
return SamplesStatsCounter::StatsSample{.value = value,
.time = sampling_time};
}
} // namespace

View File

@ -48,16 +48,17 @@ SamplesStatsCounter::StatsSample StatsSample(
double value,
Timestamp sampling_time,
std::map<std::string, std::string> metadata) {
return SamplesStatsCounter::StatsSample{value, sampling_time,
std::move(metadata)};
return {
.value = value, .time = sampling_time, .metadata = std::move(metadata)};
}
SamplesStatsCounter::StatsSample StatsSample(
TimeDelta duration,
Timestamp sampling_time,
std::map<std::string, std::string> metadata) {
return SamplesStatsCounter::StatsSample{duration.ms<double>(), sampling_time,
std::move(metadata)};
return {.value = duration.ms<double>(),
.time = sampling_time,
.metadata = std::move(metadata)};
}
FrameComparison ValidateFrameComparison(FrameComparison comparison) {

View File

@ -613,7 +613,7 @@ TEST(DefaultVideoQualityAnalyzerTest,
VideoFrame received_frame = frame;
// Shift frame by a few pixels.
test::CropRegion crop_region{0, 1, 3, 0};
test::CropRegion crop_region{.left = 0, .right = 1, .top = 3, .bottom = 0};
scoped_refptr<VideoFrameBuffer> cropped_buffer =
CropAndZoom(crop_region, received_frame.video_frame_buffer()->ToI420());
received_frame.set_video_frame_buffer(cropped_buffer);

View File

@ -149,7 +149,8 @@ EncodedImageExtractionResult SingleProcessEncodedImageDataInjector::ExtractData(
for (size_t i = 0; i <= max_spatial_index; ++i) {
out.SetSpatialLayerFrameSize(i, 0);
}
return EncodedImageExtractionResult{*id, out, true};
return EncodedImageExtractionResult{
.id = *id, .image = out, .discard = true};
}
// Make a pass from begin to end to restore origin payload and erase discarded
@ -179,7 +180,8 @@ EncodedImageExtractionResult SingleProcessEncodedImageDataInjector::ExtractData(
}
out.set_size(pos);
return EncodedImageExtractionResult{*id, out, discard};
return EncodedImageExtractionResult{
.id = *id, .image = out, .discard = discard};
}
SingleProcessEncodedImageDataInjector::ExtractionInfoVector::

View File

@ -31,8 +31,8 @@ EncodedImage VideoFrameTrackingIdInjector::InjectData(
EncodedImageExtractionResult VideoFrameTrackingIdInjector::ExtractData(
const EncodedImage& source) {
return EncodedImageExtractionResult{source.VideoFrameTrackingId(), source,
/*discard=*/false};
return EncodedImageExtractionResult{
.id = source.VideoFrameTrackingId(), .image = source, .discard = false};
}
} // namespace webrtc_pc_e2e

View File

@ -44,7 +44,8 @@ void AnalyzerHelper::AddTrackToStreamMapping(std::string track_id,
std::string stream_label) {
RTC_DCHECK_RUN_ON(&signaling_sequence_checker_);
track_to_stream_map_.insert(
{std::move(track_id), StreamInfo{stream_label, stream_label}});
{std::move(track_id), StreamInfo{.receiver_peer = stream_label,
.stream_label = stream_label}});
}
void AnalyzerHelper::AddTrackToStreamMapping(std::string track_id,
@ -52,8 +53,8 @@ void AnalyzerHelper::AddTrackToStreamMapping(std::string track_id,
std::string sync_group) {
RTC_DCHECK_RUN_ON(&signaling_sequence_checker_);
track_to_stream_map_.insert(
{std::move(track_id),
StreamInfo{std::move(stream_label), std::move(sync_group)}});
{std::move(track_id), StreamInfo{.receiver_peer = std::move(stream_label),
.stream_label = std::move(sync_group)}});
}
AnalyzerHelper::StreamInfo AnalyzerHelper::GetStreamInfoFromTrackId(

View File

@ -508,7 +508,7 @@ class PcapReader : public RtpFileReaderImpl {
*next_packet_pos = ftell(file_) + incl_len;
RtpPacketMarker marker = {0};
RtpPacketMarker marker = {};
marker.time_offset_ms = CalcTimeDelta(ts_sec, ts_usec, stream_start_ms);
TRY_PCAP(ReadPacketHeader(&marker));
marker.pos_in_file = ftell(file_);
@ -557,7 +557,7 @@ class PcapReader : public RtpFileReaderImpl {
TRY_PCAP(Read(&incl_len, false));
TRY_PCAP(Read(&orig_len, false));
RtpPacketMarker marker = {0};
RtpPacketMarker marker = {};
// Note: Wireshark writes nanoseconds most of the time, see comments in
// it's pcapio.c. We are only interesting in the time difference so
// truncating to uint32_t is ok.

View File

@ -90,12 +90,12 @@ absl::string_view FileName(absl::string_view path) {
}
bool FileExists(absl::string_view file_name) {
struct stat file_info = {0};
struct stat file_info = {.st_dev = 0};
return stat(std::string(file_name).c_str(), &file_info) == 0;
}
bool DirExists(absl::string_view directory_name) {
struct stat directory_info = {0};
struct stat directory_info = {.st_dev = 0};
return stat(std::string(directory_name).c_str(), &directory_info) == 0 &&
S_ISDIR(directory_info.st_mode);
}
@ -204,7 +204,7 @@ std::optional<std::vector<std::string>> ReadDirectory(absl::string_view path) {
bool CreateDir(absl::string_view directory_name) {
std::string directory_name_str(directory_name);
struct stat path_info = {0};
struct stat path_info = {.st_dev = 0};
// Check if the path exists already:
if (stat(directory_name_str.c_str(), &path_info) == 0) {
if (!S_ISDIR(path_info.st_mode)) {

View File

@ -56,8 +56,10 @@ Y4mFrameGenerator::Y4mFrameGenerator(absl::string_view filename,
}
Y4mFrameGenerator::VideoFrameData Y4mFrameGenerator::NextFrame() {
VideoFrame::UpdateRect update_rect{0, 0, static_cast<int>(width_),
static_cast<int>(height_)};
VideoFrame::UpdateRect update_rect{.offset_x = 0,
.offset_y = 0,
.width = static_cast<int>(width_),
.height = static_cast<int>(height_)};
scoped_refptr<I420Buffer> next_frame_buffer = frame_reader_->PullFrame();
if (!next_frame_buffer ||

View File

@ -848,7 +848,7 @@ class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
SamplesStatsCounter::StatsSample StatsSample(double value,
Timestamp time) const {
return SamplesStatsCounter::StatsSample{value, time};
return SamplesStatsCounter::StatsSample{.value = value, .time = time};
}
LimitedTaskQueue task_queue_;