Skip to content

Commit 05614ec

Browse files
committed
Don't use std::optional and disable c++17
1 parent ed719e5 commit 05614ec

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ pkg_check_modules(avformat libavformat REQUIRED)
1414
pkg_check_modules(avutil libavutil REQUIRED)
1515
pkg_check_modules(swscale libswscale REQUIRED)
1616

17-
if(NOT CMAKE_CXX_STANDARD)
18-
set(CMAKE_CXX_STANDARD 17)
19-
endif()
20-
2117
###################################################
2218
## Declare things to be passed to other projects ##
2319
###################################################

include/web_video_server/libav_streamer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef LIBAV_STREAMERS_H_
22
#define LIBAV_STREAMERS_H_
33

4-
#include <optional>
4+
#include <chrono>
55

66
#include <image_transport/image_transport.h>
77
#include "web_video_server/image_streamer.h"
@@ -47,8 +47,9 @@ class LibavStreamer : public ImageTransportImageStreamer
4747
private:
4848
AVFrame* frame_;
4949
struct SwsContext* sws_context_;
50-
std::optional<std::chrono::steady_clock::time_point> first_image_timestamp_;
5150
boost::mutex encode_mutex_;
51+
bool first_image_received_;
52+
std::chrono::steady_clock::time_point first_image_time_;
5253

5354
std::string format_name_;
5455
std::string codec_name_;

src/libav_streamer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ LibavStreamer::LibavStreamer(const async_web_server_cpp::HttpRequest &request,
5353
const std::string &format_name, const std::string &codec_name,
5454
const std::string &content_type) :
5555
ImageTransportImageStreamer(request, connection, nh), output_format_(0), format_context_(0), codec_(0), codec_context_(0), video_stream_(
56-
0), frame_(0), sws_context_(0), first_image_timestamp_(std::nullopt), format_name_(
56+
0), frame_(0), sws_context_(0), first_image_received_(false), first_image_time_(), format_name_(
5757
format_name), codec_name_(codec_name), content_type_(content_type), opt_(0), io_buffer_(0)
5858
{
5959

@@ -261,8 +261,9 @@ void LibavStreamer::sendImage(
261261
const std::chrono::steady_clock::time_point & time)
262262
{
263263
boost::mutex::scoped_lock lock(encode_mutex_);
264-
if (!first_image_timestamp_.has_value()) {
265-
first_image_timestamp_ = time;
264+
if (!first_image_received_) {
265+
first_image_received_ = true;
266+
first_image_time_ = time;
266267
}
267268
std::vector<uint8_t> encoded_frame;
268269
#if (LIBAVUTIL_VERSION_MAJOR < 53)
@@ -355,7 +356,7 @@ void LibavStreamer::sendImage(
355356
uint8_t *output_buf;
356357

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

0 commit comments

Comments
 (0)