@@ -115,20 +115,20 @@ by name from the Camera Manager, after making sure that at least one camera is
available.
.. code:: cpp
-
- if (cm->cameras().empty()) {
+ auto cameras = cm->cameras();
+ if (cameras.empty()) {
std::cout << "No cameras were identified on the system."
<< std::endl;
cm->stop();
return EXIT_FAILURE;
}
- std::string cameraId = cm->cameras()[0]->id();
+ std::string cameraId = cameras[0]->id();
camera = cm->get(cameraId);
/*
* Note that is equivalent to:
- * camera = cm->cameras()[0];
+ * camera = cameras[0];
*/
Once a camera has been selected an application needs to acquire an exclusive
@@ -39,8 +39,10 @@ CameraSession::CameraSession(CameraManager *cm,
{
char *endptr;
unsigned long index = strtoul(cameraId.c_str(), &endptr, 10);
- if (*endptr == '\0' && index > 0 && index <= cm->cameras().size())
- camera_ = cm->cameras()[index - 1];
+ auto cameras = cm->cameras();
+
+ if (*endptr == '\0' && index > 0 && index <= cameras.size())
+ camera_ = std::move(cameras[index - 1]);
else
camera_ = cm->get(cameraId);
@@ -385,13 +385,14 @@ gst_libcamera_src_open(GstLibcameraSrc *self)
return false;
}
} else {
- if (cm->cameras().empty()) {
+ auto cameras = cm->cameras();
+ if (cameras.empty()) {
GST_ELEMENT_ERROR(self, RESOURCE, NOT_FOUND,
("Could not find any supported camera on this system."),
("libcamera::CameraMananger::cameras() is empty"));
return false;
}
- cam = cm->cameras()[0];
+ cam = std::move(cameras[0]);
}
GST_INFO_OBJECT(self, "Using camera '%s'", cam->id().c_str());