Skip to content

Commit 87b7721

Browse files
committed
Enable other misc checks
1 parent 1f92e25 commit 87b7721

9 files changed

Lines changed: 44 additions & 41 deletions

.clang-tidy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Checks: >
33
-clang-analyzer-*,
44
clang-diagnostic-*,
55
google-*,
6-
misc-include-cleaner,
6+
misc-*,
7+
-misc-non-private-member-variables-in-classes,
78
readability-*,
89
-readability-identifier-length,
910
-readability-magic-numbers,
@@ -18,7 +19,7 @@ CheckOptions:
1819
readability-identifier-naming.EnumConstantCase: CamelCase
1920
readability-identifier-naming.FunctionCase: lower_case
2021
readability-identifier-naming.GlobalConstantCase: CamelCase
21-
readability-identifier-naming.StaticConstantCase: CamelCase
22+
readability-identifier-naming.StaticConstantCase: lower_case
2223
readability-identifier-naming.StaticVariableCase: lower_case
2324
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
2425
readability-identifier-naming.MacroDefinitionIgnoredRegexp: '^[A-Z]+(_[A-Z]+)*_$'

src/multipart_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void MultipartStream::send_part_header(
7676
snprintf(
7777
stamp, sizeof(stamp), "%.06lf",
7878
std::chrono::duration_cast<std::chrono::duration<double>>(time.time_since_epoch()).count());
79-
std::shared_ptr<std::vector<async_web_server_cpp::HttpHeader>> headers(
79+
const std::shared_ptr<std::vector<async_web_server_cpp::HttpHeader>> headers(
8080
new std::vector<async_web_server_cpp::HttpHeader>());
8181
headers->push_back(async_web_server_cpp::HttpHeader("Content-type", type));
8282
headers->push_back(async_web_server_cpp::HttpHeader("X-Timestamp", stamp));
@@ -88,7 +88,7 @@ void MultipartStream::send_part_header(
8888

8989
void MultipartStream::send_part_footer(const std::chrono::steady_clock::time_point & time)
9090
{
91-
std::shared_ptr<std::string> str(new std::string("\r\n--" + boundary_ + "\r\n"));
91+
const std::shared_ptr<std::string> str(new std::string("\r\n--" + boundary_ + "\r\n"));
9292
PendingFooter pf;
9393
pf.timestamp = time;
9494
pf.contents = str;

src/streamers/image_transport_streamer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void ImageTransportStreamerBase::start()
118118
return;
119119
}
120120

121-
image_transport::TransportHints hints(node.get(), default_transport_);
121+
const image_transport::TransportHints hints(node.get(), default_transport_);
122122
auto tnat = node->get_topic_names_and_types();
123123
inactive_ = true;
124124
for (auto topic_and_types : tnat) {
@@ -190,8 +190,8 @@ void ImageTransportStreamerBase::image_callback(const sensor_msgs::msg::Image::C
190190
cv::Mat img;
191191
try {
192192
img = decode_image(msg);
193-
int input_width = img.cols;
194-
int input_height = img.rows;
193+
const int input_width = img.cols;
194+
const int input_height = img.rows;
195195

196196
if (output_width_ == -1) {
197197
output_width_ = input_width;
@@ -206,10 +206,10 @@ void ImageTransportStreamerBase::image_callback(const sensor_msgs::msg::Image::C
206206
cv::flip(img, img, 1);
207207
}
208208

209-
std::scoped_lock lock(send_mutex_); // protects output_size_image_
209+
const std::scoped_lock lock(send_mutex_); // protects output_size_image_
210210
if (output_width_ != input_width || output_height_ != input_height) {
211211
cv::Mat img_resized;
212-
cv::Size new_size(output_width_, output_height_);
212+
const cv::Size new_size(output_width_, output_height_);
213213
cv::resize(img, img_resized, new_size);
214214
output_size_image_ = img_resized;
215215
} else {
@@ -243,7 +243,7 @@ void ImageTransportStreamerBase::try_send_image(
243243
rclcpp::Node & node)
244244
{
245245
try {
246-
std::scoped_lock lock(send_mutex_);
246+
const std::scoped_lock lock(send_mutex_);
247247
send_image(img, std::chrono::steady_clock::now());
248248
} catch (boost::system::system_error & e) {
249249
// happens when client disconnects
@@ -268,7 +268,7 @@ cv::Mat ImageTransportStreamerBase::decode_image(
268268
{
269269
if (msg->encoding.find("F") != std::string::npos) {
270270
// scale floating point images
271-
cv::Mat float_image_bridge = cv_bridge::toCvCopy(msg, msg->encoding)->image;
271+
const cv::Mat float_image_bridge = cv_bridge::toCvCopy(msg, msg->encoding)->image;
272272
cv::Mat_<float> float_image = float_image_bridge;
273273
double max_val;
274274
cv::minMaxIdx(float_image, 0, &max_val);

src/streamers/jpeg_streamers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MjpegStreamer::MjpegStreamer(
6969
MjpegStreamer::~MjpegStreamer()
7070
{
7171
this->inactive_ = true;
72-
std::scoped_lock lock(send_mutex_); // protects send_image.
72+
const std::scoped_lock lock(send_mutex_); // protects send_image.
7373
}
7474

7575
void MjpegStreamer::send_image(
@@ -106,7 +106,7 @@ JpegSnapshotStreamer::JpegSnapshotStreamer(
106106
JpegSnapshotStreamer::~JpegSnapshotStreamer()
107107
{
108108
this->inactive_ = true;
109-
std::scoped_lock lock(send_mutex_); // protects send_image.
109+
const std::scoped_lock lock(send_mutex_); // protects send_image.
110110
}
111111

112112
void JpegSnapshotStreamer::send_image(

src/streamers/libav_streamer.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,22 @@ LibavStreamerBase::~LibavStreamerBase()
112112
}
113113
}
114114

115+
namespace {
115116
// output callback for ffmpeg IO context
116117
#if LIBAVFORMAT_VERSION_MAJOR < 61 // NOLINT(misc-include-cleaner)
117-
static int dispatch_output_packet(void * opaque, uint8_t * buffer, int buffer_size)
118+
int dispatch_output_packet(void * opaque, uint8_t * buffer, int buffer_size)
118119
#else
119-
static int dispatch_output_packet(void * opaque, const uint8_t * buffer, int buffer_size)
120+
int dispatch_output_packet(void * opaque, const uint8_t * buffer, int buffer_size)
120121
#endif
121122
{
122-
async_web_server_cpp::HttpConnectionPtr connection =
123+
const async_web_server_cpp::HttpConnectionPtr connection =
123124
*(static_cast<async_web_server_cpp::HttpConnectionPtr *>(opaque));
124125
std::vector<uint8_t> encoded_frame;
125126
encoded_frame.assign(buffer, buffer + buffer_size);
126127
connection->write_and_clear(encoded_frame);
127128
return 0;
128129
}
130+
} // namespace
129131

130132
void LibavStreamerBase::initialize(const cv::Mat & /* img */)
131133
{
@@ -145,7 +147,7 @@ void LibavStreamerBase::initialize(const cv::Mat & /* img */)
145147
}
146148

147149
// Set up custom IO callback.
148-
size_t io_buffer_size = 3 * 1024; // 3M seen elsewhere and adjudged good
150+
const size_t io_buffer_size = 3 * 1024; // 3M seen elsewhere and adjudged good
149151
io_buffer_ = new unsigned char[io_buffer_size];
150152
AVIOContext * io_ctx = avio_alloc_context(
151153
io_buffer_, io_buffer_size, AVIO_FLAG_WRITE,
@@ -255,13 +257,13 @@ void LibavStreamerBase::send_image(
255257
const cv::Mat & img,
256258
const std::chrono::steady_clock::time_point & time)
257259
{
258-
std::scoped_lock lock(encode_mutex_);
260+
const std::scoped_lock lock(encode_mutex_);
259261
if (!first_image_received_) {
260262
first_image_received_ = true;
261263
first_image_time_ = time;
262264
}
263265

264-
AVPixelFormat input_coding_format = AV_PIX_FMT_BGR24;
266+
const AVPixelFormat input_coding_format = AV_PIX_FMT_BGR24;
265267

266268
AVFrame * raw_frame = av_frame_alloc();
267269
av_image_fill_arrays(
@@ -270,7 +272,7 @@ void LibavStreamerBase::send_image(
270272

271273
// Convert from opencv to libav
272274
if (sws_context_ == nullptr) {
273-
static int sws_flags = SWS_BICUBIC;
275+
static const int sws_flags = SWS_BICUBIC;
274276
sws_context_ = sws_getContext(
275277
output_width_, output_height_, input_coding_format, output_width_,
276278
output_height_, codec_context_->pix_fmt, sws_flags, NULL, NULL, NULL);
@@ -310,7 +312,7 @@ void LibavStreamerBase::send_image(
310312
}
311313

312314
if (got_packet) {
313-
double seconds = std::chrono::duration_cast<std::chrono::duration<double>>(
315+
const double seconds = std::chrono::duration_cast<std::chrono::duration<double>>(
314316
time - first_image_time_).count();
315317
// Encode video at 1/0.95 to minimize delay
316318
pkt->pts = static_cast<int64_t>(seconds / av_q2d(video_stream_->time_base) * 0.95);

src/streamers/png_streamers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ PngStreamer::PngStreamer(
7474
PngStreamer::~PngStreamer()
7575
{
7676
this->inactive_ = true;
77-
std::scoped_lock lock(send_mutex_); // protects send_image.
77+
const std::scoped_lock lock(send_mutex_); // protects send_image.
7878
}
7979

8080
cv::Mat PngStreamer::decode_image(const sensor_msgs::msg::Image::ConstSharedPtr & msg)
@@ -121,7 +121,7 @@ PngSnapshotStreamer::PngSnapshotStreamer(
121121
PngSnapshotStreamer::~PngSnapshotStreamer()
122122
{
123123
this->inactive_ = true;
124-
std::scoped_lock lock(send_mutex_); // protects send_image.
124+
const std::scoped_lock lock(send_mutex_); // protects send_image.
125125
}
126126

127127
cv::Mat PngSnapshotStreamer::decode_image(const sensor_msgs::msg::Image::ConstSharedPtr & msg)

src/streamers/ros_compressed_streamer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ RosCompressedStreamer::RosCompressedStreamer(
171171
RosCompressedStreamer::~RosCompressedStreamer()
172172
{
173173
this->inactive_ = true;
174-
std::scoped_lock lock(send_mutex_); // protects send_image.
174+
const std::scoped_lock lock(send_mutex_); // protects send_image.
175175
}
176176

177177
void RosCompressedStreamer::start()
@@ -194,7 +194,7 @@ void RosCompressedStreamer::restream_frame(std::chrono::duration<double> max_age
194194
}
195195

196196
if (last_frame_ + max_age < std::chrono::steady_clock::now()) {
197-
std::scoped_lock lock(send_mutex_);
197+
const std::scoped_lock lock(send_mutex_);
198198
// don't update last_frame, it may remain an old value.
199199
send_image(last_msg_, std::chrono::steady_clock::now());
200200
}
@@ -239,7 +239,7 @@ void RosCompressedStreamer::send_image(
239239
void RosCompressedStreamer::image_callback(
240240
const sensor_msgs::msg::CompressedImage::ConstSharedPtr msg)
241241
{
242-
std::scoped_lock lock(send_mutex_); // protects last_msg_ and last_frame_
242+
const std::scoped_lock lock(send_mutex_); // protects last_msg_ and last_frame_
243243
last_msg_ = msg;
244244
last_frame_ = std::chrono::steady_clock::now();
245245
send_image(last_msg_, last_frame_);
@@ -259,7 +259,7 @@ std::shared_ptr<StreamerInterface> RosCompressedStreamerFactory::create_streamer
259259
return nullptr;
260260
}
261261

262-
std::string topic = request.get_query_param_value_or_default("topic", "");
262+
const std::string topic = request.get_query_param_value_or_default("topic", "");
263263
if (!has_compressed_topic(*node_locked, topic)) {
264264
RCLCPP_WARN(
265265
node_locked->get_logger().get_child("RosCompressedStreamerFactory"),
@@ -383,7 +383,7 @@ RosCompressedSnapshotStreamerFactory::create_streamer(
383383
return nullptr;
384384
}
385385

386-
std::string topic = request.get_query_param_value_or_default("topic", "");
386+
const std::string topic = request.get_query_param_value_or_default("topic", "");
387387
if (!has_compressed_topic(*node_locked, topic)) {
388388
RCLCPP_WARN(
389389
node_locked->get_logger().get_child("RosCompressedSnapshotStreamerFactory"),

src/streamers/vp8_streamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void Vp8Streamer::initialize_encoder()
8080
}
8181

8282
// Buffering settings
83-
int bufsize = 10;
83+
const int bufsize = 10;
8484
codec_context_->rc_buffer_size = bufsize;
8585
codec_context_->rc_initial_buffer_occupancy = bufsize; // bitrate/3;
8686
av_opt_set_int(codec_context_->priv_data, "bufsize", bufsize, 0);

src/web_video_server.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ WebVideoServer::~WebVideoServer()
156156

157157
void WebVideoServer::restream_frames(std::chrono::duration<double> max_age)
158158
{
159-
std::scoped_lock lock(streamers_mutex_);
159+
const std::scoped_lock lock(streamers_mutex_);
160160

161161
for (auto & streamer : streamers_) {
162162
streamer->restream_frame(max_age);
@@ -165,7 +165,7 @@ void WebVideoServer::restream_frames(std::chrono::duration<double> max_age)
165165

166166
void WebVideoServer::cleanup_inactive_streams()
167167
{
168-
std::unique_lock lock(streamers_mutex_, std::try_to_lock);
168+
const std::unique_lock lock(streamers_mutex_, std::try_to_lock);
169169
if (lock) {
170170
auto new_end = std::partition(
171171
streamers_.begin(), streamers_.end(),
@@ -201,12 +201,12 @@ bool WebVideoServer::handle_stream(
201201
async_web_server_cpp::HttpConnectionPtr connection, const char * begin,
202202
const char * end)
203203
{
204-
std::string type = request.get_query_param_value_or_default("type", default_stream_type_);
204+
const std::string type = request.get_query_param_value_or_default("type", default_stream_type_);
205205
if (streamer_factories_.find(type) != streamer_factories_.end()) {
206-
std::shared_ptr<StreamerInterface> streamer = streamer_factories_[type]->create_streamer(
206+
const std::shared_ptr<StreamerInterface> streamer = streamer_factories_[type]->create_streamer(
207207
request, connection, weak_from_this());
208208
streamer->start();
209-
std::scoped_lock lock(streamers_mutex_);
209+
const std::scoped_lock lock(streamers_mutex_);
210210
streamers_.push_back(streamer);
211211
} else {
212212
async_web_server_cpp::HttpReply::stock_reply(async_web_server_cpp::HttpReply::not_found)(
@@ -220,13 +220,13 @@ bool WebVideoServer::handle_snapshot(
220220
async_web_server_cpp::HttpConnectionPtr connection, const char * begin,
221221
const char * end)
222222
{
223-
std::string type = request.get_query_param_value_or_default("type", default_snapshot_type_);
223+
const std::string type = request.get_query_param_value_or_default("type", default_snapshot_type_);
224224
if (snapshot_streamer_factories_.find(type) != snapshot_streamer_factories_.end()) {
225-
std::shared_ptr<StreamerInterface> streamer =
225+
const std::shared_ptr<StreamerInterface> streamer =
226226
snapshot_streamer_factories_[type]->create_streamer(
227227
request, connection, weak_from_this());
228228
streamer->start();
229-
std::scoped_lock lock(streamers_mutex_);
229+
const std::scoped_lock lock(streamers_mutex_);
230230
streamers_.push_back(streamer);
231231
} else {
232232
async_web_server_cpp::HttpReply::stock_reply(async_web_server_cpp::HttpReply::not_found)(
@@ -240,9 +240,9 @@ bool WebVideoServer::handle_stream_viewer(
240240
async_web_server_cpp::HttpConnectionPtr connection, const char * begin,
241241
const char * end)
242242
{
243-
std::string type = request.get_query_param_value_or_default("type", default_stream_type_);
243+
const std::string type = request.get_query_param_value_or_default("type", default_stream_type_);
244244
if (streamer_factories_.find(type) != streamer_factories_.end()) {
245-
std::string topic = request.get_query_param_value_or_default("topic", "");
245+
const std::string topic = request.get_query_param_value_or_default("topic", "");
246246

247247
async_web_server_cpp::HttpReply::builder(async_web_server_cpp::HttpReply::ok)
248248
.header("Connection", "close")
@@ -274,7 +274,7 @@ bool WebVideoServer::handle_list_streams(
274274

275275
for (const auto & factory_pair : streamer_factories_) {
276276
RCLCPP_DEBUG(get_logger(), "Getting topics from factory: %s", factory_pair.first.c_str());
277-
std::vector<std::string> factory_topics =
277+
const std::vector<std::string> factory_topics =
278278
factory_pair.second->get_available_topics(*this);
279279
RCLCPP_DEBUG(
280280
get_logger(), "Factory %s returned %zu topics",
@@ -288,7 +288,7 @@ bool WebVideoServer::handle_list_streams(
288288

289289
for (const auto & factory_pair : snapshot_streamer_factories_) {
290290
RCLCPP_DEBUG(get_logger(), "Getting topics from factory: %s", factory_pair.first.c_str());
291-
std::vector<std::string> factory_topics =
291+
const std::vector<std::string> factory_topics =
292292
factory_pair.second->get_available_topics(*this);
293293
RCLCPP_DEBUG(
294294
get_logger(), "Factory %s returned %zu topics",

0 commit comments

Comments
 (0)