mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
spa: libcamera: use references when getting camera properties
The argument is not nullable, so use a const lvalue reference to express that clearly.
This commit is contained in:
parent
fc91f93af3
commit
41045c5e61
1 changed files with 14 additions and 22 deletions
|
|
@ -53,32 +53,25 @@ struct impl {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const libcamera::Span<const int64_t> cameraDevice(
|
static const libcamera::Span<const int64_t> cameraDevice(const Camera& camera)
|
||||||
const Camera *camera)
|
|
||||||
{
|
{
|
||||||
const ControlList &props = camera->properties();
|
if (auto devices = camera.properties().get(properties::SystemDevices))
|
||||||
|
|
||||||
if (auto devices = props.get(properties::SystemDevices))
|
|
||||||
return devices.value();
|
return devices.value();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string cameraModel(const Camera *camera)
|
static std::string cameraModel(const Camera& camera)
|
||||||
{
|
{
|
||||||
const ControlList &props = camera->properties();
|
if (auto model = camera.properties().get(properties::Model))
|
||||||
|
|
||||||
if (auto model = props.get(properties::Model))
|
|
||||||
return std::move(model.value());
|
return std::move(model.value());
|
||||||
|
|
||||||
return camera->id();
|
return camera.id();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *cameraLoc(const Camera *camera)
|
static const char *cameraLoc(const Camera& camera)
|
||||||
{
|
{
|
||||||
const ControlList &props = camera->properties();
|
if (auto location = camera.properties().get(properties::Location)) {
|
||||||
|
|
||||||
if (auto location = props.get(properties::Location)) {
|
|
||||||
switch (location.value()) {
|
switch (location.value()) {
|
||||||
case properties::CameraLocationFront:
|
case properties::CameraLocationFront:
|
||||||
return "front";
|
return "front";
|
||||||
|
|
@ -92,11 +85,9 @@ static const char *cameraLoc(const Camera *camera)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *cameraRot(const Camera *camera)
|
static const char *cameraRot(const Camera& camera)
|
||||||
{
|
{
|
||||||
const ControlList &props = camera->properties();
|
if (auto rotation = camera.properties().get(properties::Rotation)) {
|
||||||
|
|
||||||
if (auto rotation = props.get(properties::Rotation)) {
|
|
||||||
switch (rotation.value()) {
|
switch (rotation.value()) {
|
||||||
case 90:
|
case 90:
|
||||||
return "90";
|
return "90";
|
||||||
|
|
@ -121,6 +112,7 @@ static int emit_info(struct impl *impl, bool full)
|
||||||
struct spa_param_info params[2];
|
struct spa_param_info params[2];
|
||||||
char path[256], name[256], devices_str[256];
|
char path[256], name[256], devices_str[256];
|
||||||
struct spa_strbuf buf;
|
struct spa_strbuf buf;
|
||||||
|
Camera& camera = *impl->camera;
|
||||||
|
|
||||||
info = SPA_DEVICE_INFO_INIT();
|
info = SPA_DEVICE_INFO_INIT();
|
||||||
|
|
||||||
|
|
@ -133,19 +125,19 @@ static int emit_info(struct impl *impl, bool full)
|
||||||
ADD_ITEM(SPA_KEY_MEDIA_CLASS, "Video/Device");
|
ADD_ITEM(SPA_KEY_MEDIA_CLASS, "Video/Device");
|
||||||
ADD_ITEM(SPA_KEY_API_LIBCAMERA_PATH, impl->device_id.c_str());
|
ADD_ITEM(SPA_KEY_API_LIBCAMERA_PATH, impl->device_id.c_str());
|
||||||
|
|
||||||
if (auto location = cameraLoc(impl->camera.get()))
|
if (auto location = cameraLoc(camera))
|
||||||
ADD_ITEM(SPA_KEY_API_LIBCAMERA_LOCATION, location);
|
ADD_ITEM(SPA_KEY_API_LIBCAMERA_LOCATION, location);
|
||||||
if (auto rotation = cameraRot(impl->camera.get()))
|
if (auto rotation = cameraRot(camera))
|
||||||
ADD_ITEM(SPA_KEY_API_LIBCAMERA_ROTATION, rotation);
|
ADD_ITEM(SPA_KEY_API_LIBCAMERA_ROTATION, rotation);
|
||||||
|
|
||||||
const auto model = cameraModel(impl->camera.get());
|
const auto model = cameraModel(camera);
|
||||||
ADD_ITEM(SPA_KEY_DEVICE_PRODUCT_NAME, model.c_str());
|
ADD_ITEM(SPA_KEY_DEVICE_PRODUCT_NAME, model.c_str());
|
||||||
ADD_ITEM(SPA_KEY_DEVICE_DESCRIPTION, model.c_str());
|
ADD_ITEM(SPA_KEY_DEVICE_DESCRIPTION, model.c_str());
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "libcamera_device.%s", impl->device_id.c_str());
|
snprintf(name, sizeof(name), "libcamera_device.%s", impl->device_id.c_str());
|
||||||
ADD_ITEM(SPA_KEY_DEVICE_NAME, name);
|
ADD_ITEM(SPA_KEY_DEVICE_NAME, name);
|
||||||
|
|
||||||
auto device_numbers = cameraDevice(impl->camera.get());
|
auto device_numbers = cameraDevice(camera);
|
||||||
|
|
||||||
if (!device_numbers.empty()) {
|
if (!device_numbers.empty()) {
|
||||||
spa_strbuf_init(&buf, devices_str, sizeof(devices_str));
|
spa_strbuf_init(&buf, devices_str, sizeof(devices_str));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue