Skip to content

Commit 225e7d0

Browse files
Clang-tidy: additional checks (#107)
Added misc-const-correctness
1 parent c457bd4 commit 225e7d0

16 files changed

Lines changed: 106 additions & 108 deletions

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Checks: >
22
-*,
33
bugprone-*,
4+
misc-const-correctness,
45
performance-*,
56
modernize-*,
67
readability-misleading-indentation,

src/audio_frame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ AudioFrame::fromOwnedInfo(const proto::OwnedAudioFrameBuffer &owned) {
8383
}
8484

8585
{
86-
FfiHandle guard(static_cast<uintptr_t>(owned.handle().id()));
86+
const FfiHandle guard(static_cast<uintptr_t>(owned.handle().id()));
8787
// guard is destroyed at end of scope, which should call into the FFI to
8888
// drop the OwnedAudioFrameBuffer.
8989
}

src/audio_processing_module.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ AudioProcessingModule::AudioProcessingModule(const Options &options) {
3535
msg->set_high_pass_filter_enabled(options.high_pass_filter);
3636
msg->set_gain_controller_enabled(options.auto_gain_control);
3737

38-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
38+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
3939

4040
if (!resp.has_new_apm()) {
4141
throw std::runtime_error(
@@ -69,7 +69,7 @@ void AudioProcessingModule::processStream(AudioFrame &frame) {
6969
msg->set_sample_rate(static_cast<std::uint32_t>(frame.sample_rate()));
7070
msg->set_num_channels(static_cast<std::uint32_t>(frame.num_channels()));
7171

72-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
72+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
7373

7474
if (!resp.has_apm_process_stream()) {
7575
throw std::runtime_error(
@@ -101,7 +101,7 @@ void AudioProcessingModule::processReverseStream(AudioFrame &frame) {
101101
msg->set_sample_rate(static_cast<std::uint32_t>(frame.sample_rate()));
102102
msg->set_num_channels(static_cast<std::uint32_t>(frame.num_channels()));
103103

104-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
104+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
105105

106106
if (!resp.has_apm_process_reverse_stream()) {
107107
throw std::runtime_error(
@@ -125,7 +125,7 @@ void AudioProcessingModule::setStreamDelayMs(int delay_ms) {
125125
msg->set_apm_handle(static_cast<std::uint64_t>(handle_.get()));
126126
msg->set_delay_ms(delay_ms);
127127

128-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
128+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
129129

130130
if (!resp.has_apm_set_stream_delay()) {
131131
throw std::runtime_error(

src/audio_source.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ AudioSource::AudioSource(int sample_rate, int num_channels, int queue_size_ms)
5050
msg->set_num_channels(static_cast<std::uint32_t>(num_channels_));
5151
msg->set_queue_size_ms(static_cast<std::uint32_t>(queue_size_ms_));
5252

53-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
53+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
5454

5555
const auto &source_info = resp.new_audio_source().source();
5656
// Wrap FFI handle in RAII FfiHandle
@@ -62,9 +62,9 @@ double AudioSource::queuedDuration() const noexcept {
6262
return 0.0;
6363
}
6464

65-
double now = now_seconds();
66-
double elapsed = now - last_capture_;
67-
double remaining = q_size_ - elapsed;
65+
const double now = now_seconds();
66+
const double elapsed = now - last_capture_;
67+
const double remaining = q_size_ - elapsed;
6868
return remaining > 0.0 ? remaining : 0.0;
6969
}
7070

@@ -100,9 +100,9 @@ void AudioSource::captureFrame(const AudioFrame &frame, int timeout_ms) {
100100
}
101101

102102
// Queue tracking, same logic as before
103-
double now = now_seconds();
104-
double elapsed = (last_capture_ == 0.0) ? 0.0 : (now - last_capture_);
105-
double frame_duration = static_cast<double>(frame.samples_per_channel()) /
103+
const double now = now_seconds();
104+
const double elapsed = (last_capture_ == 0.0) ? 0.0 : (now - last_capture_);
105+
const double frame_duration = static_cast<double>(frame.samples_per_channel()) /
106106
static_cast<double>(sample_rate_);
107107
q_size_ += frame_duration - elapsed;
108108
if (q_size_ < 0.0) {
@@ -111,7 +111,7 @@ void AudioSource::captureFrame(const AudioFrame &frame, int timeout_ms) {
111111
last_capture_ = now;
112112

113113
// Build AudioFrameBufferInfo from the wrapper
114-
proto::AudioFrameBufferInfo buf = frame.toProto();
114+
const proto::AudioFrameBufferInfo buf = frame.toProto();
115115
// Use async FFI API and block until the callback completes
116116
auto fut = FfiClient::instance().captureAudioFrameAsync(handle_.get(), buf);
117117
if (timeout_ms == 0) {

src/ffi_client.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ FfiClient::sendRequest(const proto::FfiRequest &request) const {
200200
}
201201

202202
// Ensure we drop the handle exactly once on all paths
203-
FfiHandle handle_guard(static_cast<uintptr_t>(handle));
203+
const FfiHandle handle_guard(static_cast<uintptr_t>(handle));
204204
if (!resp_ptr || resp_len == 0) {
205205
throw std::runtime_error("FFI returned empty response bytes");
206206
}
@@ -403,7 +403,7 @@ FfiClient::connectAsync(const std::string &url, const std::string &token,
403403
}
404404

405405
try {
406-
proto::FfiResponse resp = sendRequest(req);
406+
const proto::FfiResponse resp = sendRequest(req);
407407
if (!resp.has_connect()) {
408408
logAndThrow("FfiResponse missing connect");
409409
}
@@ -501,7 +501,7 @@ FfiClient::publishTrackAsync(std::uint64_t local_participant_handle,
501501
return;
502502
}
503503

504-
proto::OwnedTrackPublication pub = cb.publication();
504+
const proto::OwnedTrackPublication &pub = cb.publication();
505505
pr.set_value(std::move(pub));
506506
});
507507

@@ -515,7 +515,7 @@ FfiClient::publishTrackAsync(std::uint64_t local_participant_handle,
515515
msg->mutable_options()->CopyFrom(optionProto);
516516

517517
try {
518-
proto::FfiResponse resp = sendRequest(req);
518+
const proto::FfiResponse resp = sendRequest(req);
519519
if (!resp.has_publish_track()) {
520520
logAndThrow("FfiResponse missing publish_track");
521521
}
@@ -560,7 +560,7 @@ FfiClient::unpublishTrackAsync(std::uint64_t local_participant_handle,
560560
msg->set_request_async_id(async_id);
561561

562562
try {
563-
proto::FfiResponse resp = sendRequest(req);
563+
const proto::FfiResponse resp = sendRequest(req);
564564
if (!resp.has_unpublish_track()) {
565565
logAndThrow("FfiResponse missing unpublish_track");
566566
}
@@ -611,7 +611,7 @@ std::future<void> FfiClient::publishDataAsync(
611611
}
612612

613613
try {
614-
proto::FfiResponse resp = sendRequest(req);
614+
const proto::FfiResponse resp = sendRequest(req);
615615
if (!resp.has_publish_data()) {
616616
logAndThrow("FfiResponse missing publish_data");
617617
}
@@ -665,7 +665,7 @@ FfiClient::publishDataTrackAsync(std::uint64_t local_participant_handle,
665665
msg->set_request_async_id(async_id);
666666

667667
try {
668-
proto::FfiResponse resp = sendRequest(req);
668+
const proto::FfiResponse resp = sendRequest(req);
669669
if (!resp.has_publish_data_track()) {
670670
cancelPendingByAsyncId(async_id);
671671
std::promise<Result<proto::OwnedLocalDataTrack, PublishDataTrackError>>
@@ -760,7 +760,7 @@ std::future<void> FfiClient::publishSipDtmfAsync(
760760
}
761761

762762
try {
763-
proto::FfiResponse resp = sendRequest(req);
763+
const proto::FfiResponse resp = sendRequest(req);
764764
if (!resp.has_publish_sip_dtmf()) {
765765
logAndThrow("FfiResponse missing publish_sip_dtmf");
766766
}
@@ -803,7 +803,7 @@ FfiClient::setLocalMetadataAsync(std::uint64_t local_participant_handle,
803803
msg->set_request_async_id(async_id);
804804

805805
try {
806-
proto::FfiResponse resp = sendRequest(req);
806+
const proto::FfiResponse resp = sendRequest(req);
807807
if (!resp.has_set_local_metadata()) {
808808
logAndThrow("FfiResponse missing set_local_metadata");
809809
}
@@ -848,7 +848,7 @@ FfiClient::captureAudioFrameAsync(std::uint64_t source_handle,
848848
msg->mutable_buffer()->CopyFrom(buffer);
849849

850850
try {
851-
proto::FfiResponse resp = sendRequest(req);
851+
const proto::FfiResponse resp = sendRequest(req);
852852
if (!resp.has_capture_audio_frame()) {
853853
logAndThrow("FfiResponse missing capture_audio_frame");
854854
}
@@ -902,7 +902,7 @@ FfiClient::performRpcAsync(std::uint64_t local_participant_handle,
902902
}
903903

904904
try {
905-
proto::FfiResponse resp = sendRequest(req);
905+
const proto::FfiResponse resp = sendRequest(req);
906906
if (!resp.has_perform_rpc()) {
907907
logAndThrow("FfiResponse missing perform_rpc");
908908
}
@@ -951,7 +951,7 @@ std::future<void> FfiClient::sendStreamHeaderAsync(
951951
}
952952

953953
try {
954-
proto::FfiResponse resp = sendRequest(req);
954+
const proto::FfiResponse resp = sendRequest(req);
955955
if (!resp.has_send_stream_header()) {
956956
logAndThrow("FfiResponse missing send_stream_header");
957957
}
@@ -1000,7 +1000,7 @@ std::future<void> FfiClient::sendStreamChunkAsync(
10001000
}
10011001

10021002
try {
1003-
proto::FfiResponse resp = sendRequest(req);
1003+
const proto::FfiResponse resp = sendRequest(req);
10041004
if (!resp.has_send_stream_chunk()) {
10051005
logAndThrow("FfiResponse missing send_stream_chunk");
10061006
}
@@ -1045,7 +1045,7 @@ FfiClient::sendStreamTrailerAsync(std::uint64_t local_participant_handle,
10451045
msg->set_request_async_id(async_id);
10461046

10471047
try {
1048-
proto::FfiResponse resp = sendRequest(req);
1048+
const proto::FfiResponse resp = sendRequest(req);
10491049
if (!resp.has_send_stream_trailer()) {
10501050
logAndThrow("FfiResponse missing send_stream_trailer");
10511051
}

src/ffi_handle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void FfiHandle::reset(uintptr_t new_handle) noexcept {
4040
}
4141

4242
uintptr_t FfiHandle::release() noexcept {
43-
uintptr_t old = handle_;
43+
const uintptr_t old = handle_;
4444
handle_ = 0;
4545
return old;
4646
}

src/local_audio_track.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::shared_ptr<LocalAudioTrack> LocalAudioTrack::createLocalAudioTrack(
3838
msg->set_name(name);
3939
msg->set_source_handle(static_cast<uint64_t>(source->ffi_handle_id()));
4040

41-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
41+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
4242
const proto::OwnedTrack &owned = resp.create_audio_track().track();
4343
FfiHandle handle(static_cast<uintptr_t>(owned.handle().id()));
4444
return std::shared_ptr<LocalAudioTrack>(

src/local_data_track.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LocalDataTrack::tryPush(const DataTrackFrame &frame) {
5252
pf->set_user_timestamp(frame.user_timestamp.value());
5353
}
5454

55-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
55+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
5656
const auto &r = resp.local_data_track_try_push();
5757
if (r.has_error()) {
5858
return Result<void, LocalDataTrackTryPushError>::failure(
@@ -84,7 +84,7 @@ bool LocalDataTrack::isPublished() const {
8484
auto *msg = req.mutable_local_data_track_is_published();
8585
msg->set_track_handle(static_cast<uint64_t>(handle_.get()));
8686

87-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
87+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
8888
return resp.local_data_track_is_published().is_published();
8989
}
9090

src/local_video_track.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::shared_ptr<LocalVideoTrack> LocalVideoTrack::createLocalVideoTrack(
3838
msg->set_name(name);
3939
msg->set_source_handle(static_cast<uint64_t>(source->ffi_handle_id()));
4040

41-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
41+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
4242
const proto::OwnedTrack &owned = resp.create_video_track().track();
4343
FfiHandle handle(static_cast<uintptr_t>(owned.handle().id()));
4444
return std::shared_ptr<LocalVideoTrack>(

src/remote_data_track.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool RemoteDataTrack::isPublished() const {
4242
auto *msg = req.mutable_remote_data_track_is_published();
4343
msg->set_track_handle(static_cast<uint64_t>(handle_.get()));
4444

45-
proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
45+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
4646
return resp.remote_data_track_is_published().is_published();
4747
}
4848

@@ -63,7 +63,7 @@ RemoteDataTrack::subscribe(const DataTrackStream::Options &options) {
6363
SubscribeDataTrackError>::failure(std::move(result).error());
6464
}
6565

66-
proto::OwnedDataTrackStream owned_sub = result.value();
66+
const proto::OwnedDataTrackStream owned_sub = result.value();
6767

6868
FfiHandle sub_handle(static_cast<uintptr_t>(owned_sub.handle().id()));
6969

0 commit comments

Comments
 (0)