Do small changes

This commit is contained in:
John Zhao 2018-06-01 07:09:03 +00:00
parent c5dd47708e
commit a0cf8fd902
2 changed files with 18 additions and 6 deletions

View File

@ -26,6 +26,7 @@
#include "internal/motions.h" #include "internal/motions.h"
#include "internal/streams.h" #include "internal/streams.h"
#include "internal/strings.h" #include "internal/strings.h"
#include "internal/times.h"
#include "internal/types.h" #include "internal/types.h"
#include "uvc/uvc.h" #include "uvc/uvc.h"
@ -419,13 +420,18 @@ void Device::StartVideoStreaming() {
static std::uint8_t drop_count = 1; static std::uint8_t drop_count = 1;
if (drop_count > 0) { if (drop_count > 0) {
--drop_count; --drop_count;
continuation();
return; return;
} }
// auto &&time_beg = times::now();
if (streams_->PushStream(Capabilities::STEREO, data)) { if (streams_->PushStream(Capabilities::STEREO, data)) {
CallbackPushedStreamData(Stream::LEFT); CallbackPushedStreamData(Stream::LEFT);
CallbackPushedStreamData(Stream::RIGHT); CallbackPushedStreamData(Stream::RIGHT);
} }
continuation(); continuation();
// VLOG(2) << "Stereo video callback cost "
// << times::count<times::milliseconds>(times::now() - time_beg)
// << " ms";
}); });
} else { } else {
LOG(FATAL) << "Not any stream capabilities are supported by this device"; LOG(FATAL) << "Not any stream capabilities are supported by this device";

View File

@ -259,20 +259,26 @@ void Streams::AllocStreamData(
void Streams::AllocStreamData( void Streams::AllocStreamData(
const Stream &stream, const StreamRequest &request, const Format &format) { const Stream &stream, const StreamRequest &request, const Format &format) {
stream_data_t data; stream_data_t data;
if (stream == Stream::LEFT || stream == Stream::RIGHT) {
data.img = std::make_shared<ImgData>();
} else {
data.img = nullptr;
}
if (HasStreamDatas(stream)) { if (HasStreamDatas(stream)) {
// If cached equal to limits_max, drop the oldest one. // If cached equal to limits_max, drop the oldest one.
if (stream_datas_map_.at(stream).size() == GetStreamDataMaxSize(stream)) { if (stream_datas_map_.at(stream).size() == GetStreamDataMaxSize(stream)) {
auto &&datas = stream_datas_map_[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()); datas.erase(datas.begin());
VLOG(2) << "Stream data of " << stream << " is dropped as out of limits"; 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<ImgData>();
}
} else {
data.img = nullptr;
}
if (!data.frame) { if (!data.frame) {
data.frame = std::make_shared<frame_t>( data.frame = std::make_shared<frame_t>(
request.width, request.height, format, nullptr); request.width, request.height, format, nullptr);