From a0cf8fd90215ba23d3d313510536831b59525940 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Fri, 1 Jun 2018 07:09:03 +0000 Subject: [PATCH] Do small changes --- src/device/device.cc | 6 ++++++ src/internal/streams.cc | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/device/device.cc b/src/device/device.cc index d22cbd8..207497f 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -26,6 +26,7 @@ #include "internal/motions.h" #include "internal/streams.h" #include "internal/strings.h" +#include "internal/times.h" #include "internal/types.h" #include "uvc/uvc.h" @@ -419,13 +420,18 @@ void Device::StartVideoStreaming() { static std::uint8_t drop_count = 1; if (drop_count > 0) { --drop_count; + continuation(); return; } + // auto &&time_beg = times::now(); if (streams_->PushStream(Capabilities::STEREO, data)) { CallbackPushedStreamData(Stream::LEFT); CallbackPushedStreamData(Stream::RIGHT); } continuation(); + // VLOG(2) << "Stereo video callback cost " + // << times::count(times::now() - time_beg) + // << " ms"; }); } else { LOG(FATAL) << "Not any stream capabilities are supported by this device"; diff --git a/src/internal/streams.cc b/src/internal/streams.cc index 93f79f2..4b049e3 100644 --- a/src/internal/streams.cc +++ b/src/internal/streams.cc @@ -259,20 +259,26 @@ void Streams::AllocStreamData( void Streams::AllocStreamData( const Stream &stream, const StreamRequest &request, const Format &format) { stream_data_t data; - if (stream == Stream::LEFT || stream == Stream::RIGHT) { - data.img = std::make_shared(); - } else { - data.img = nullptr; - } + if (HasStreamDatas(stream)) { // If cached equal to limits_max, drop the oldest one. if (stream_datas_map_.at(stream).size() == GetStreamDataMaxSize(stream)) { auto &&datas = stream_datas_map_[stream]; - data.frame = datas.front().frame; // reuse this frame + // reuse the dropped data + data.img = datas.front().img; + data.frame = datas.front().frame; datas.erase(datas.begin()); VLOG(2) << "Stream data of " << stream << " is dropped as out of limits"; } } + + if (stream == Stream::LEFT || stream == Stream::RIGHT) { + if(!data.img) { + data.img = std::make_shared(); + } + } else { + data.img = nullptr; + } if (!data.frame) { data.frame = std::make_shared( request.width, request.height, format, nullptr);