mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-17 08:56:49 -05:00
libcamera: map controls to standard ids
Map the control id from libcamera to standard pipewire ones and vice versa.
This commit is contained in:
parent
50a1e2db22
commit
73cc5d1dde
1 changed files with 43 additions and 3 deletions
|
|
@ -35,6 +35,7 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <linux/media.h>
|
#include <linux/media.h>
|
||||||
|
#include <libcamera/control_ids.h>
|
||||||
|
|
||||||
int spa_libcamera_open(struct impl *impl)
|
int spa_libcamera_open(struct impl *impl)
|
||||||
{
|
{
|
||||||
|
|
@ -458,6 +459,38 @@ error:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
uint32_t id;
|
||||||
|
uint32_t spa_id;
|
||||||
|
} control_map[] = {
|
||||||
|
{ libcamera::controls::BRIGHTNESS, SPA_PROP_brightness },
|
||||||
|
{ libcamera::controls::CONTRAST, SPA_PROP_contrast },
|
||||||
|
{ libcamera::controls::SATURATION, SPA_PROP_saturation },
|
||||||
|
{ libcamera::controls::EXPOSURE_TIME, SPA_PROP_exposure },
|
||||||
|
{ libcamera::controls::ANALOGUE_GAIN, SPA_PROP_gain },
|
||||||
|
{ libcamera::controls::SHARPNESS, SPA_PROP_sharpness },
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint32_t control_to_prop_id(struct impl *impl, uint32_t control_id)
|
||||||
|
{
|
||||||
|
SPA_FOR_EACH_ELEMENT_VAR(control_map, c) {
|
||||||
|
if (c->id == control_id)
|
||||||
|
return c->spa_id;
|
||||||
|
}
|
||||||
|
return SPA_PROP_START_CUSTOM + control_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t prop_id_to_control(struct impl *impl, uint32_t prop_id)
|
||||||
|
{
|
||||||
|
SPA_FOR_EACH_ELEMENT_VAR(control_map, c) {
|
||||||
|
if (c->spa_id == prop_id)
|
||||||
|
return c->id;
|
||||||
|
}
|
||||||
|
if (prop_id >= SPA_PROP_START_CUSTOM)
|
||||||
|
return prop_id - SPA_PROP_START_CUSTOM;
|
||||||
|
return SPA_ID_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
spa_libcamera_enum_controls(struct impl *impl, struct port *port, int seq,
|
spa_libcamera_enum_controls(struct impl *impl, struct port *port, int seq,
|
||||||
uint32_t start, uint32_t num,
|
uint32_t start, uint32_t num,
|
||||||
|
|
@ -469,7 +502,7 @@ spa_libcamera_enum_controls(struct impl *impl, struct port *port, int seq,
|
||||||
struct spa_pod_frame f[2];
|
struct spa_pod_frame f[2];
|
||||||
struct spa_result_node_params result;
|
struct spa_result_node_params result;
|
||||||
struct spa_pod *ctrl;
|
struct spa_pod *ctrl;
|
||||||
uint32_t count = 0, skip;
|
uint32_t count = 0, skip, id;
|
||||||
int res;
|
int res;
|
||||||
const ControlId *ctrl_id;
|
const ControlId *ctrl_id;
|
||||||
ControlInfo ctrl_info;
|
ControlInfo ctrl_info;
|
||||||
|
|
@ -492,10 +525,12 @@ next:
|
||||||
ctrl_id = it->first;
|
ctrl_id = it->first;
|
||||||
ctrl_info = it->second;
|
ctrl_info = it->second;
|
||||||
|
|
||||||
|
id = control_to_prop_id(impl, ctrl_id->id());
|
||||||
|
|
||||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||||
spa_pod_builder_push_object(&b, &f[0], SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo);
|
spa_pod_builder_push_object(&b, &f[0], SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo);
|
||||||
spa_pod_builder_add(&b,
|
spa_pod_builder_add(&b,
|
||||||
SPA_PROP_INFO_id, SPA_POD_Id(ctrl_id->id()),
|
SPA_PROP_INFO_id, SPA_POD_Id(id),
|
||||||
SPA_PROP_INFO_description, SPA_POD_String(ctrl_id->name().c_str()),
|
SPA_PROP_INFO_description, SPA_POD_String(ctrl_id->name().c_str()),
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
|
@ -601,8 +636,13 @@ spa_libcamera_set_control(struct impl *impl, const struct spa_pod_prop *prop)
|
||||||
const ControlId *ctrl_id;
|
const ControlId *ctrl_id;
|
||||||
int res;
|
int res;
|
||||||
struct val d;
|
struct val d;
|
||||||
|
uint32_t control_id;
|
||||||
|
|
||||||
auto v = info.idmap().find(prop->key);
|
control_id = prop_id_to_control(impl, prop->key);
|
||||||
|
if (control_id == SPA_ID_INVALID)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
auto v = info.idmap().find(control_id);
|
||||||
if (v == info.idmap().end())
|
if (v == info.idmap().end())
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue