Skip to content

Commit 0755df6

Browse files
committed
Don't use std::optional
1 parent 526572a commit 0755df6

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/web_video_server/libav_streamer.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ extern "C"
4242
#include <libavutil/imgutils.h>
4343
}
4444

45+
#include <chrono>
4546
#include <memory>
46-
#include <optional>
4747
#include <string>
4848

4949
#include "image_transport/image_transport.hpp"
@@ -79,8 +79,9 @@ class LibavStreamer : public ImageTransportImageStreamer
7979
private:
8080
AVFrame * frame_;
8181
struct SwsContext * sws_context_;
82-
std::optional<std::chrono::steady_clock::time_point> first_image_timestamp_;
8382
std::mutex encode_mutex_;
83+
bool first_image_received_;
84+
std::chrono::steady_clock::time_point first_image_time_;
8485

8586
std::string format_name_;
8687
std::string codec_name_;

src/libav_streamer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ LibavStreamer::LibavStreamer(
4545
const std::string & content_type)
4646
: ImageTransportImageStreamer(request, connection, node), format_context_(0), codec_(0),
4747
codec_context_(0), video_stream_(0), frame_(0), sws_context_(0),
48-
first_image_timestamp_(std::nullopt), format_name_(format_name), codec_name_(codec_name),
49-
content_type_(content_type), opt_(0), io_buffer_(0)
48+
first_image_received_(false), first_image_time_(), format_name_(format_name),
49+
codec_name_(codec_name), content_type_(content_type), opt_(0), io_buffer_(0)
5050
{
5151
bitrate_ = request.get_query_param_value_or_default<int>("bitrate", 100000);
5252
qmin_ = request.get_query_param_value_or_default<int>("qmin", 10);
@@ -220,8 +220,9 @@ void LibavStreamer::sendImage(
220220
const std::chrono::steady_clock::time_point & time)
221221
{
222222
std::scoped_lock lock(encode_mutex_);
223-
if (!first_image_timestamp_.has_value()) {
224-
first_image_timestamp_ = time;
223+
if (!first_image_received_) {
224+
first_image_received_ = true;
225+
first_image_time_ = time;
225226
}
226227

227228
AVPixelFormat input_coding_format = AV_PIX_FMT_BGR24;
@@ -277,7 +278,7 @@ void LibavStreamer::sendImage(
277278
uint8_t * output_buf;
278279

279280
double seconds = std::chrono::duration_cast<std::chrono::duration<double>>(
280-
time - first_image_timestamp_.value()).count();
281+
time - first_image_time_).count();
281282
// Encode video at 1/0.95 to minimize delay
282283
pkt->pts = (int64_t)(seconds / av_q2d(video_stream_->time_base) * 0.95);
283284
if (pkt->pts <= 0) {

0 commit comments

Comments
 (0)