Skip to content

Commit

Permalink
Don't use std::optional and disable c++17
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Nov 19, 2024
1 parent ed719e5 commit 05614ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ pkg_check_modules(avformat libavformat REQUIRED)
pkg_check_modules(avutil libavutil REQUIRED)
pkg_check_modules(swscale libswscale REQUIRED)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

###################################################
## Declare things to be passed to other projects ##
###################################################
Expand Down
5 changes: 3 additions & 2 deletions include/web_video_server/libav_streamer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LIBAV_STREAMERS_H_
#define LIBAV_STREAMERS_H_

#include <optional>
#include <chrono>

#include <image_transport/image_transport.h>
#include "web_video_server/image_streamer.h"
Expand Down Expand Up @@ -47,8 +47,9 @@ class LibavStreamer : public ImageTransportImageStreamer
private:
AVFrame* frame_;
struct SwsContext* sws_context_;
std::optional<std::chrono::steady_clock::time_point> first_image_timestamp_;
boost::mutex encode_mutex_;
bool first_image_received_;
std::chrono::steady_clock::time_point first_image_time_;

std::string format_name_;
std::string codec_name_;
Expand Down
9 changes: 5 additions & 4 deletions src/libav_streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ LibavStreamer::LibavStreamer(const async_web_server_cpp::HttpRequest &request,
const std::string &format_name, const std::string &codec_name,
const std::string &content_type) :
ImageTransportImageStreamer(request, connection, nh), output_format_(0), format_context_(0), codec_(0), codec_context_(0), video_stream_(
0), frame_(0), sws_context_(0), first_image_timestamp_(std::nullopt), format_name_(
0), frame_(0), sws_context_(0), first_image_received_(false), first_image_time_(), format_name_(
format_name), codec_name_(codec_name), content_type_(content_type), opt_(0), io_buffer_(0)
{

Expand Down Expand Up @@ -261,8 +261,9 @@ void LibavStreamer::sendImage(
const std::chrono::steady_clock::time_point & time)
{
boost::mutex::scoped_lock lock(encode_mutex_);
if (!first_image_timestamp_.has_value()) {
first_image_timestamp_ = time;
if (!first_image_received_) {
first_image_received_ = true;
first_image_time_ = time;
}
std::vector<uint8_t> encoded_frame;
#if (LIBAVUTIL_VERSION_MAJOR < 53)
Expand Down Expand Up @@ -355,7 +356,7 @@ void LibavStreamer::sendImage(
uint8_t *output_buf;

double seconds = std::chrono::duration_cast<std::chrono::duration<double>>(time -
first_image_timestamp_.value()).count();
first_image_time_).count();
// Encode video at 1/0.95 to minimize delay
pkt.pts = (int64_t)(seconds / av_q2d(video_stream_->time_base) * 0.95);
if (pkt.pts <= 0)
Expand Down

0 comments on commit 05614ec

Please sign in to comment.