From 377f9b21f1af3ed98f25ed4be852ec490af01532 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Tue, 12 Jun 2018 12:31:07 +0800 Subject: [PATCH] Check supports stream or not when get its data --- src/device/device.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/device/device.cc b/src/device/device.cc index 28d18d5..aff6132 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -54,6 +55,27 @@ struct DeviceModel { } }; +bool CheckSupports( + const Device *const device, const Stream &stream, bool fatal = true) { + if (device->Supports(stream)) { + return true; + } else { + auto &&supports = stream_supports_map.at(device->GetModel()); + std::ostringstream ss; + std::copy( + supports.begin(), supports.end(), + std::ostream_iterator(ss, ", ")); + if (fatal) { + LOG(FATAL) << "Unsupported stream: " << stream + << ". Please use these: " << ss.str(); + } else { + LOG(WARNING) << "Unsupported stream: " << stream + << ". Please use these: " << ss.str(); + } + return false; + } +} + } // namespace Device::Device(const Model &model, std::shared_ptr device) @@ -275,8 +297,7 @@ bool Device::RunOptionAction(const Option &option) const { void Device::SetStreamCallback( const Stream &stream, stream_callback_t callback, bool async) { - if (!Supports(stream)) { - LOG(WARNING) << "Unsupported stream: " << stream; + if (!CheckSupports(this, stream, false)) { return; } if (callback) { @@ -351,6 +372,7 @@ void Device::WaitForStreams() { std::vector Device::GetStreamDatas(const Stream &stream) { CHECK(video_streaming_); CHECK_NOTNULL(streams_); + CheckSupports(this, stream); std::lock_guard _(mtx_streams_); return streams_->GetStreamDatas(stream); } @@ -358,6 +380,7 @@ std::vector Device::GetStreamDatas(const Stream &stream) { device::StreamData Device::GetLatestStreamData(const Stream &stream) { CHECK(video_streaming_); CHECK_NOTNULL(streams_); + CheckSupports(this, stream); std::lock_guard _(mtx_streams_); return streams_->GetLatestStreamData(stream); }