Skip to content

Commit

Permalink
Fix most of cpplint errors
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/web_video_server/h264_streamer.hpp
#	include/web_video_server/image_streamer.hpp
#	include/web_video_server/jpeg_streamers.hpp
#	include/web_video_server/libav_streamer.hpp
#	include/web_video_server/multipart_stream.hpp
#	include/web_video_server/png_streamers.hpp
#	include/web_video_server/ros_compressed_streamer.hpp
#	include/web_video_server/vp9_streamer.hpp
#	include/web_video_server/web_video_server.hpp
#	src/web_video_server.cpp
  • Loading branch information
bjsowa committed Oct 8, 2024
1 parent 403b8d9 commit dc3db06
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 96 deletions.
12 changes: 7 additions & 5 deletions include/web_video_server/h264_streamer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef H264_STREAMERS_H_
#define H264_STREAMERS_H_
#ifndef WEB_VIDEO_SERVER__H264_STREAMER_HPP_
#define WEB_VIDEO_SERVER__H264_STREAMER_HPP_

#include <image_transport/image_transport.hpp>
#include <string>

#include "image_transport/image_transport.hpp"
#include "web_video_server/libav_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
Expand Down Expand Up @@ -62,6 +64,6 @@ class H264StreamerType : public LibavStreamerType
rclcpp::Node::SharedPtr node);
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__H264_STREAMER_HPP_
17 changes: 10 additions & 7 deletions include/web_video_server/image_streamer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef IMAGE_STREAMER_H_
#define IMAGE_STREAMER_H_
#ifndef WEB_VIDEO_SERVER__IMAGE_STREAMER_HPP_
#define WEB_VIDEO_SERVER__IMAGE_STREAMER_HPP_

#include <string>

#include <rclcpp/rclcpp.hpp>
#include <image_transport/image_transport.hpp>
#include <image_transport/transport_hints.hpp>
#include <opencv2/opencv.hpp>

#include "rclcpp/rclcpp.hpp"
#include "image_transport/image_transport.hpp"
#include "image_transport/transport_hints.hpp"
#include "web_video_server/utils.hpp"
#include "async_web_server_cpp/http_server.hpp"
#include "async_web_server_cpp/http_request.hpp"
Expand Down Expand Up @@ -124,6 +127,6 @@ class ImageStreamerType
virtual std::string create_viewer(const async_web_server_cpp::HttpRequest & request) = 0;
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__IMAGE_STREAMER_HPP_
12 changes: 7 additions & 5 deletions include/web_video_server/jpeg_streamers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef JPEG_STREAMERS_H_
#define JPEG_STREAMERS_H_
#ifndef WEB_VIDEO_SERVER__JPEG_STREAMERS_HPP_
#define WEB_VIDEO_SERVER__JPEG_STREAMERS_HPP_

#include <image_transport/image_transport.hpp>
#include <string>

#include "image_transport/image_transport.hpp"
#include "web_video_server/image_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
Expand Down Expand Up @@ -82,6 +84,6 @@ class JpegSnapshotStreamer : public ImageTransportImageStreamer
int quality_;
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__JPEG_STREAMERS_HPP_
20 changes: 11 additions & 9 deletions include/web_video_server/libav_streamer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef LIBAV_STREAMERS_H_
#define LIBAV_STREAMERS_H_

#include <image_transport/image_transport.hpp>
#include "web_video_server/image_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
#ifndef WEB_VIDEO_SERVER__LIBAV_STREAMER_HPP_
#define WEB_VIDEO_SERVER__LIBAV_STREAMER_HPP_

extern "C"
{
Expand All @@ -48,6 +43,13 @@ extern "C"
#include <libavutil/imgutils.h>
}

#include <string>

#include "image_transport/image_transport.hpp"
#include "web_video_server/image_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"

namespace web_video_server
{

Expand Down Expand Up @@ -110,6 +112,6 @@ class LibavStreamerType : public ImageStreamerType
const std::string content_type_;
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__LIBAV_STREAMER_HPP_
17 changes: 10 additions & 7 deletions include/web_video_server/multipart_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef MULTIPART_STREAM_H_
#define MULTIPART_STREAM_H_

#include <rclcpp/rclcpp.hpp>
#include <async_web_server_cpp/http_connection.hpp>
#ifndef WEB_VIDEO_SERVER__MULTIPART_STREAM_HPP_
#define WEB_VIDEO_SERVER__MULTIPART_STREAM_HPP_

#include <queue>
#include <memory>
#include <vector>
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "async_web_server_cpp/http_connection.hpp"

namespace web_video_server
{
Expand Down Expand Up @@ -75,6 +78,6 @@ class MultipartStream
std::queue<PendingFooter> pending_footers_;
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__MULTIPART_STREAM_HPP_
12 changes: 7 additions & 5 deletions include/web_video_server/png_streamers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef PNG_STREAMERS_H_
#define PNG_STREAMERS_H_
#ifndef WEB_VIDEO_SERVER__PNG_STREAMERS_HPP_
#define WEB_VIDEO_SERVER__PNG_STREAMERS_HPP_

#include <image_transport/image_transport.hpp>
#include <string>

#include "image_transport/image_transport.hpp"
#include "web_video_server/image_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
Expand Down Expand Up @@ -83,6 +85,6 @@ class PngSnapshotStreamer : public ImageTransportImageStreamer
int quality_;
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__PNG_STREAMERS_HPP_
12 changes: 7 additions & 5 deletions include/web_video_server/ros_compressed_streamer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef ROS_COMPRESSED_STREAMERS_H_
#define ROS_COMPRESSED_STREAMERS_H_
#ifndef WEB_VIDEO_SERVER__ROS_COMPRESSED_STREAMER_HPP_
#define WEB_VIDEO_SERVER__ROS_COMPRESSED_STREAMER_HPP_

#include <sensor_msgs/msg/compressed_image.hpp>
#include <string>

#include "sensor_msgs/msg/compressed_image.hpp"
#include "web_video_server/image_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
Expand Down Expand Up @@ -76,6 +78,6 @@ class RosCompressedStreamerType : public ImageStreamerType
std::string create_viewer(const async_web_server_cpp::HttpRequest & request);
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__ROS_COMPRESSED_STREAMER_HPP_
12 changes: 7 additions & 5 deletions include/web_video_server/vp8_streamer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef VP8_STREAMERS_H_
#define VP8_STREAMERS_H_
#ifndef WEB_VIDEO_SERVER__VP8_STREAMER_HPP_
#define WEB_VIDEO_SERVER__VP8_STREAMER_HPP_

#include <image_transport/image_transport.hpp>
#include <string>

#include "image_transport/image_transport.hpp"
#include "web_video_server/libav_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
Expand Down Expand Up @@ -65,6 +67,6 @@ class Vp8StreamerType : public LibavStreamerType
rclcpp::Node::SharedPtr node);
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__VP8_STREAMER_HPP_
10 changes: 5 additions & 5 deletions include/web_video_server/vp9_streamer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef VP9_STREAMERS_H_
#define VP9_STREAMERS_H_
#ifndef WEB_VIDEO_SERVER__VP9_STREAMER_HPP_
#define WEB_VIDEO_SERVER__VP9_STREAMER_HPP_

#include <image_transport/image_transport.hpp>
#include "image_transport/image_transport.hpp"
#include "web_video_server/libav_streamer.hpp"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
Expand Down Expand Up @@ -61,6 +61,6 @@ class Vp9StreamerType : public LibavStreamerType
rclcpp::Node::SharedPtr node);
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__VP9_STREAMER_HPP_
20 changes: 11 additions & 9 deletions include/web_video_server/web_video_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef WEB_VIDEO_SERVER_H_
#define WEB_VIDEO_SERVER_H_
#ifndef WEB_VIDEO_SERVER__WEB_VIDEO_SERVER_HPP_
#define WEB_VIDEO_SERVER__WEB_VIDEO_SERVER_HPP_

#include <rclcpp/rclcpp.hpp>
#include <map>
#include <string>
#include <vector>

#ifdef CV_BRIDGE_USES_OLD_HEADERS
#include <cv_bridge/cv_bridge.h>
#include "cv_bridge/cv_bridge.h"
#else
#include <cv_bridge/cv_bridge.hpp>
#include "cv_bridge/cv_bridge.hpp"
#endif

#include <vector>
#include "rclcpp/rclcpp.hpp"
#include "web_video_server/image_streamer.hpp"
#include "async_web_server_cpp/http_server.hpp"
#include "async_web_server_cpp/http_request.hpp"
Expand All @@ -59,7 +61,7 @@ class WebVideoServer
* @brief Constructor
* @return
*/
WebVideoServer(rclcpp::Node::SharedPtr & node);
explicit WebVideoServer(rclcpp::Node::SharedPtr & node);

/**
* @brief Destructor - Cleans up
Expand Down Expand Up @@ -121,6 +123,6 @@ class WebVideoServer
boost::mutex subscriber_mutex_;
};

}
} // namespace web_video_server

#endif
#endif // WEB_VIDEO_SERVER__WEB_VIDEO_SERVER_HPP_
2 changes: 1 addition & 1 deletion src/h264_streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ boost::shared_ptr<ImageStreamer> H264StreamerType::create_streamer(
return boost::shared_ptr<ImageStreamer>(new H264Streamer(request, connection, node));
}

}
} // namespace web_video_server
7 changes: 4 additions & 3 deletions src/image_streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ void ImageTransportImageStreamer::restreamFrame(double max_age)
try {
if (last_frame + rclcpp::Duration::from_seconds(max_age) < node_->now() ) {
boost::mutex::scoped_lock lock(send_mutex_);
sendImage(output_size_image, node_->now() ); // don't update last_frame, it may remain an old value.
// don't update last_frame, it may remain an old value.
sendImage(output_size_image, node_->now());
}
} catch (boost::system::system_error & e) {
// happens when client disconnects
Expand Down Expand Up @@ -183,7 +184,7 @@ void ImageTransportImageStreamer::imageCallback(const sensor_msgs::msg::Image::C
cv::flip(img, img, true);
}

boost::mutex::scoped_lock lock(send_mutex_); // protects output_size_image
boost::mutex::scoped_lock lock(send_mutex_); // protects output_size_image
if (output_width_ != input_width || output_height_ != input_height) {
cv::Mat img_resized;
cv::Size new_size(output_width_, output_height_);
Expand Down Expand Up @@ -228,4 +229,4 @@ void ImageTransportImageStreamer::imageCallback(const sensor_msgs::msg::Image::C
}
}

}
} // namespace web_video_server
8 changes: 4 additions & 4 deletions src/jpeg_streamers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MjpegStreamer::MjpegStreamer(
MjpegStreamer::~MjpegStreamer()
{
this->inactive_ = true;
boost::mutex::scoped_lock lock(send_mutex_); // protects sendImage.
boost::mutex::scoped_lock lock(send_mutex_); // protects sendImage.
}

void MjpegStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & time)
Expand Down Expand Up @@ -91,7 +91,7 @@ JpegSnapshotStreamer::JpegSnapshotStreamer(
JpegSnapshotStreamer::~JpegSnapshotStreamer()
{
this->inactive_ = true;
boost::mutex::scoped_lock lock(send_mutex_); // protects sendImage.
boost::mutex::scoped_lock lock(send_mutex_); // protects sendImage.
}

void JpegSnapshotStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & time)
Expand All @@ -104,7 +104,7 @@ void JpegSnapshotStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & t
cv::imencode(".jpeg", img, encoded_buffer, encode_params);

char stamp[20];
sprintf(stamp, "%.06lf", time.seconds());
snprintf(stamp, sizeof(stamp), "%.06lf", time.seconds());
async_web_server_cpp::HttpReply::builder(async_web_server_cpp::HttpReply::ok)
.header("Connection", "close")
.header("Server", "web_video_server")
Expand All @@ -121,4 +121,4 @@ void JpegSnapshotStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & t
inactive_ = true;
}

}
} // namespace web_video_server
8 changes: 4 additions & 4 deletions src/libav_streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "web_video_server/libav_streamer.hpp"
#include "async_web_server_cpp/http_reply.hpp"

/*https://stackoverflow.com/questions/46884682/error-in-building-opencv-with-ffmpeg*/
// https://stackoverflow.com/questions/46884682/error-in-building-opencv-with-ffmpeg
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER

Expand Down Expand Up @@ -84,7 +84,7 @@ static int dispatch_output_packet(void * opaque, uint8_t * buffer, int buffer_si
std::vector<uint8_t> encoded_frame;
encoded_frame.assign(buffer, buffer + buffer_size);
connection->write_and_clear(encoded_frame);
return 0; // TODO: can this fail?
return 0; // TODO: can this fail?
}

void LibavStreamer::initialize(const cv::Mat & img)
Expand Down Expand Up @@ -120,7 +120,7 @@ void LibavStreamer::initialize(const cv::Mat & img)
format_context_->max_interleave_delta = 0;

// Load codec
if (codec_name_.empty()) { // use default codec if none specified
if (codec_name_.empty()) { // use default codec if none specified
codec_ = avcodec_find_encoder(format_context_->oformat->video_codec);
} else {
codec_ = avcodec_find_encoder_by_name(codec_name_.c_str());
Expand Down Expand Up @@ -321,4 +321,4 @@ std::string LibavStreamerType::create_viewer(const async_web_server_cpp::HttpReq
return ss.str();
}

}
} // namespace web_video_server
Loading

0 comments on commit dc3db06

Please sign in to comment.