Check supports stream or not when get its data

This commit is contained in:
John Zhao 2018-06-12 12:31:07 +08:00
parent 591bbdd3e6
commit 377f9b21f1

View File

@ -16,6 +16,7 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
@ -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<Stream>(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 } // namespace
Device::Device(const Model &model, std::shared_ptr<uvc::device> device) Device::Device(const Model &model, std::shared_ptr<uvc::device> device)
@ -275,8 +297,7 @@ bool Device::RunOptionAction(const Option &option) const {
void Device::SetStreamCallback( void Device::SetStreamCallback(
const Stream &stream, stream_callback_t callback, bool async) { const Stream &stream, stream_callback_t callback, bool async) {
if (!Supports(stream)) { if (!CheckSupports(this, stream, false)) {
LOG(WARNING) << "Unsupported stream: " << stream;
return; return;
} }
if (callback) { if (callback) {
@ -351,6 +372,7 @@ void Device::WaitForStreams() {
std::vector<device::StreamData> Device::GetStreamDatas(const Stream &stream) { std::vector<device::StreamData> Device::GetStreamDatas(const Stream &stream) {
CHECK(video_streaming_); CHECK(video_streaming_);
CHECK_NOTNULL(streams_); CHECK_NOTNULL(streams_);
CheckSupports(this, stream);
std::lock_guard<std::mutex> _(mtx_streams_); std::lock_guard<std::mutex> _(mtx_streams_);
return streams_->GetStreamDatas(stream); return streams_->GetStreamDatas(stream);
} }
@ -358,6 +380,7 @@ std::vector<device::StreamData> Device::GetStreamDatas(const Stream &stream) {
device::StreamData Device::GetLatestStreamData(const Stream &stream) { device::StreamData Device::GetLatestStreamData(const Stream &stream) {
CHECK(video_streaming_); CHECK(video_streaming_);
CHECK_NOTNULL(streams_); CHECK_NOTNULL(streams_);
CheckSupports(this, stream);
std::lock_guard<std::mutex> _(mtx_streams_); std::lock_guard<std::mutex> _(mtx_streams_);
return streams_->GetLatestStreamData(stream); return streams_->GetLatestStreamData(stream);
} }