CameraServer: auto-increment startAutomaticCapture(). (#468)

Also add GetServer() functions so the automatically created VideoSink can
be retrieved by user code if desired.
This commit is contained in:
Peter Johnson
2017-01-20 01:07:37 -07:00
committed by GitHub
parent ff141ab1ff
commit e375b4a9ff
3 changed files with 83 additions and 6 deletions

View File

@@ -486,7 +486,7 @@ CameraServer::CameraServer()
}
cs::UsbCamera CameraServer::StartAutomaticCapture() {
return StartAutomaticCapture(0);
return StartAutomaticCapture(m_defaultUsbDevice++);
}
cs::UsbCamera CameraServer::StartAutomaticCapture(int dev) {
@@ -659,6 +659,33 @@ void CameraServer::RemoveServer(llvm::StringRef name) {
m_sinks.erase(name);
}
cs::VideoSink CameraServer::GetServer() {
llvm::SmallString<64> name;
{
std::lock_guard<std::mutex> lock(m_mutex);
if (m_primarySourceName.empty()) {
wpi_setWPIErrorWithContext(CameraServerError, "no camera available");
return cs::VideoSink{};
}
name = "serve_";
name += m_primarySourceName;
}
return GetServer(name);
}
cs::VideoSink CameraServer::GetServer(llvm::StringRef name) {
std::lock_guard<std::mutex> lock(m_mutex);
auto it = m_sinks.find(name);
if (it == m_sinks.end()) {
llvm::SmallString<64> buf;
llvm::raw_svector_ostream err{buf};
err << "could not find server " << name;
wpi_setWPIErrorWithContext(CameraServerError, err.str());
return cs::VideoSink{};
}
return it->second;
}
void CameraServer::AddCamera(const cs::VideoSource& camera) {
std::string name = camera.GetName();
std::lock_guard<std::mutex> lock(m_mutex);