mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-15 04:12:29 +00:00
v4l2: add Format on the node as well
So that we can see the format in pw-top
This commit is contained in:
parent
5a299e5685
commit
ec5f2d7337
|
@ -145,7 +145,8 @@ struct impl {
|
|||
#define NODE_PropInfo 0
|
||||
#define NODE_Props 1
|
||||
#define NODE_EnumFormat 2
|
||||
#define N_NODE_PARAMS 3
|
||||
#define NODE_Format 3
|
||||
#define N_NODE_PARAMS 4
|
||||
struct spa_param_info params[N_NODE_PARAMS];
|
||||
struct props props;
|
||||
|
||||
|
@ -167,6 +168,56 @@ struct impl {
|
|||
|
||||
#include "v4l2-utils.c"
|
||||
|
||||
static int port_get_format(struct port *port,
|
||||
uint32_t index,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **param,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct spa_pod_frame f;
|
||||
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (index > 0)
|
||||
return 0;
|
||||
|
||||
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, SPA_PARAM_Format);
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(port->current_format.media_type),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(port->current_format.media_subtype),
|
||||
0);
|
||||
|
||||
switch (port->current_format.media_subtype) {
|
||||
case SPA_MEDIA_SUBTYPE_raw:
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_VIDEO_format, SPA_POD_Id(port->current_format.info.raw.format),
|
||||
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&port->current_format.info.raw.size),
|
||||
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&port->current_format.info.raw.framerate),
|
||||
0);
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_mjpg:
|
||||
case SPA_MEDIA_SUBTYPE_jpeg:
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&port->current_format.info.mjpg.size),
|
||||
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&port->current_format.info.mjpg.framerate),
|
||||
0);
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_h264:
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&port->current_format.info.h264.size),
|
||||
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&port->current_format.info.h264.framerate),
|
||||
0);
|
||||
break;
|
||||
default:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
*param = spa_pod_builder_pop(builder, &f);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int impl_node_enum_params(void *object, int seq,
|
||||
uint32_t id, uint32_t start, uint32_t num,
|
||||
const struct spa_pod *filter)
|
||||
|
@ -177,6 +228,7 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
uint8_t buffer[1024];
|
||||
struct spa_result_node_params result;
|
||||
uint32_t count = 0;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(this != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
|
@ -239,6 +291,11 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
}
|
||||
case SPA_PARAM_EnumFormat:
|
||||
return spa_v4l2_enum_format(this, seq, start, num, filter);
|
||||
case SPA_PARAM_Format:
|
||||
if((res = port_get_format(GET_OUT_PORT(this, 0),
|
||||
result.index, filter, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
break;
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
@ -455,58 +512,6 @@ static int impl_node_remove_port(void *object,
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int port_get_format(void *object,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t index,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **param,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct impl *this = object;
|
||||
struct port *port = GET_PORT(this, direction, port_id);
|
||||
struct spa_pod_frame f;
|
||||
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (index > 0)
|
||||
return 0;
|
||||
|
||||
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, SPA_PARAM_Format);
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(port->current_format.media_type),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(port->current_format.media_subtype),
|
||||
0);
|
||||
|
||||
switch (port->current_format.media_subtype) {
|
||||
case SPA_MEDIA_SUBTYPE_raw:
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_VIDEO_format, SPA_POD_Id(port->current_format.info.raw.format),
|
||||
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&port->current_format.info.raw.size),
|
||||
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&port->current_format.info.raw.framerate),
|
||||
0);
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_mjpg:
|
||||
case SPA_MEDIA_SUBTYPE_jpeg:
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&port->current_format.info.mjpg.size),
|
||||
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&port->current_format.info.mjpg.framerate),
|
||||
0);
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_h264:
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&port->current_format.info.h264.size),
|
||||
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&port->current_format.info.h264.framerate),
|
||||
0);
|
||||
break;
|
||||
default:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
*param = spa_pod_builder_pop(builder, &f);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int impl_node_port_enum_params(void *object, int seq,
|
||||
enum spa_direction direction,
|
||||
uint32_t port_id,
|
||||
|
@ -544,8 +549,7 @@ static int impl_node_port_enum_params(void *object, int seq,
|
|||
return spa_v4l2_enum_format(this, seq, start, num, filter);
|
||||
|
||||
case SPA_PARAM_Format:
|
||||
if((res = port_get_format(this, direction, port_id,
|
||||
result.index, filter, ¶m, &b)) <= 0)
|
||||
if((res = port_get_format(port, result.index, filter, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
break;
|
||||
case SPA_PARAM_Buffers:
|
||||
|
@ -683,15 +687,19 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
}
|
||||
|
||||
done:
|
||||
this->info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS;
|
||||
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
||||
if (port->have_format) {
|
||||
port->params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
|
||||
port->params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
|
||||
this->params[NODE_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READ);
|
||||
} else {
|
||||
port->params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
||||
port->params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
||||
this->params[NODE_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, 0);
|
||||
}
|
||||
emit_port_info(this, port, false);
|
||||
emit_node_info(this, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1020,8 +1028,9 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->info.max_output_ports = 1;
|
||||
this->info.flags = SPA_NODE_FLAG_RT;
|
||||
this->params[NODE_PropInfo] = SPA_PARAM_INFO(SPA_PARAM_PropInfo, SPA_PARAM_INFO_READ);
|
||||
this->params[NODE_EnumFormat] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
||||
this->params[NODE_Props] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE);
|
||||
this->params[NODE_EnumFormat] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
||||
this->params[NODE_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, 0);
|
||||
this->info.params = this->params;
|
||||
this->info.n_params = N_NODE_PARAMS;
|
||||
reset_props(&this->props);
|
||||
|
|
Loading…
Reference in a new issue