indent -kr -i8 -l100

This commit is contained in:
Wim Taymans 2017-05-25 16:23:13 +02:00
parent 11f23a3ffa
commit d1a06ae247
28 changed files with 7034 additions and 10381 deletions

File diff suppressed because it is too large Load diff

View file

@ -23,11 +23,9 @@
extern const struct spa_handle_factory spa_audiomixer_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
{
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:

File diff suppressed because it is too large Load diff

View file

@ -23,11 +23,9 @@
extern const struct spa_handle_factory spa_audiotestsrc_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
{
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:

View file

@ -32,490 +32,478 @@
#define MAX_BUFFERS 32
struct buffer {
struct spa_buffer *outbuf;
bool outstanding;
struct buffer *next;
struct spa_buffer *outbuf;
bool outstanding;
struct buffer *next;
};
struct port {
bool have_format;
struct spa_video_info current_format;
bool have_buffers;
struct buffer buffers[MAX_BUFFERS];
struct spa_port_info info;
struct spa_port_io *io;
bool have_format;
struct spa_video_info current_format;
bool have_buffers;
struct buffer buffers[MAX_BUFFERS];
struct spa_port_info info;
struct spa_port_io *io;
};
struct type {
uint32_t node;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_command_node command_node;
uint32_t node;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_command_node command_node;
};
static inline void
init_type (struct type *type, struct spa_type_map *map)
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
spa_type_media_type_map (map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype);
spa_type_format_video_map (map, &type->format_video);
spa_type_command_node_map (map, &type->command_node);
type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video);
spa_type_command_node_map(map, &type->command_node);
}
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct spa_node_callbacks callbacks;
void *user_data;
struct spa_node_callbacks callbacks;
void *user_data;
struct port in_ports[1];
struct port out_ports[1];
struct port in_ports[1];
struct port out_ports[1];
bool started;
bool started;
};
static int
spa_ffmpeg_dec_node_get_props (struct spa_node *node,
struct spa_props **props)
static int spa_ffmpeg_dec_node_get_props(struct spa_node *node, struct spa_props **props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int spa_ffmpeg_dec_node_set_props(struct spa_node *node, const struct spa_props *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int spa_ffmpeg_dec_node_send_command(struct spa_node *node, struct spa_command *command)
{
struct impl *this;
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
this->started = false;
} else
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_set_props (struct spa_node *node,
const struct spa_props *props)
spa_ffmpeg_dec_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size,
void *user_data)
{
return SPA_RESULT_NOT_IMPLEMENTED;
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = *callbacks;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_send_command (struct spa_node *node,
struct spa_command *command)
spa_ffmpeg_dec_node_get_n_ports(struct spa_node *node,
uint32_t * n_input_ports,
uint32_t * max_input_ports,
uint32_t * n_output_ports,
uint32_t * max_output_ports)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
this->started = true;
}
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
this->started = false;
}
else
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_set_callbacks (struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size,
void *user_data)
spa_ffmpeg_dec_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports,
uint32_t * input_ids,
uint32_t n_output_ports,
uint32_t * output_ids)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0;
this = SPA_CONTAINER_OF (node, struct impl, node);
this->callbacks = *callbacks;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_get_n_ports (struct spa_node *node,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_get_port_ids (struct spa_node *node,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
spa_ffmpeg_dec_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_remove_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
spa_ffmpeg_dec_node_remove_port(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_port_enum_formats (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_format **format,
const struct spa_format *filter,
uint32_t index)
spa_ffmpeg_dec_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_format **format,
const struct spa_format *filter,
uint32_t index)
{
//struct impl *this;
//struct impl *this;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
//this = SPA_CONTAINER_OF (node, struct impl, node);
//this = SPA_CONTAINER_OF (node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
switch (index) {
case 0:
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = NULL;
switch (index) {
case 0:
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = NULL;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_port_set_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
const struct spa_format *format)
spa_ffmpeg_dec_node_port_set_format(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
const struct spa_format *format)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (format == NULL) {
port->have_format = false;
return SPA_RESULT_OK;
} else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE (format),
SPA_FORMAT_MEDIA_SUBTYPE (format), };
if (format == NULL) {
port->have_format = false;
return SPA_RESULT_OK;
} else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE(format),
};
if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
port->current_format = info;
port->have_format = true;
}
}
return SPA_RESULT_OK;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
port->current_format = info;
port->have_format = true;
}
}
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_port_get_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_format **format)
spa_ffmpeg_dec_node_port_get_format(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_format **format)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
*format = NULL;
*format = NULL;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_port_get_info (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_port_info **info)
spa_ffmpeg_dec_node_port_get_info(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_port_info **info)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_port_enum_params (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t index,
struct spa_param **param)
spa_ffmpeg_dec_node_port_enum_params(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t index,
struct spa_param **param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_port_set_param (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_param *param)
spa_ffmpeg_dec_node_port_set_param(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_param *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_port_use_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
spa_ffmpeg_dec_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (node, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(node, direction, port_id))
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_port_alloc_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t *n_buffers)
spa_ffmpeg_dec_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t * n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_port_set_io (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_port_io *io)
spa_ffmpeg_dec_node_port_set_io(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_port_io *io)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int spa_ffmpeg_dec_node_process_input(struct spa_node *node)
{
return SPA_RESULT_INVALID_PORT;
}
static int spa_ffmpeg_dec_node_process_output(struct spa_node *node)
{
struct impl *this;
struct port *port;
struct spa_port_io *output;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF(node, struct impl, node);
port = &this->out_ports[0];
if ((output = port->io) == NULL)
return SPA_RESULT_ERROR;
if (!port->have_format) {
output->status = SPA_RESULT_NO_FORMAT;
return SPA_RESULT_ERROR;
}
output->status = SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_process_input (struct spa_node *node)
spa_ffmpeg_dec_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
{
return SPA_RESULT_INVALID_PORT;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_process_output (struct spa_node *node)
spa_ffmpeg_dec_node_port_send_command(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_command *command)
{
struct impl *this;
struct port *port;
struct spa_port_io *output;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
port = &this->out_ports[0];
if ((output = port->io) == NULL)
return SPA_RESULT_ERROR;
if (!port->have_format) {
output->status = SPA_RESULT_NO_FORMAT;
return SPA_RESULT_ERROR;
}
output->status = SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_dec_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_port_send_command (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_command *command)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static const struct spa_node ffmpeg_dec_node = {
sizeof (struct spa_node),
NULL,
spa_ffmpeg_dec_node_get_props,
spa_ffmpeg_dec_node_set_props,
spa_ffmpeg_dec_node_send_command,
spa_ffmpeg_dec_node_set_callbacks,
spa_ffmpeg_dec_node_get_n_ports,
spa_ffmpeg_dec_node_get_port_ids,
spa_ffmpeg_dec_node_add_port,
spa_ffmpeg_dec_node_remove_port,
spa_ffmpeg_dec_node_port_enum_formats,
spa_ffmpeg_dec_node_port_set_format,
spa_ffmpeg_dec_node_port_get_format,
spa_ffmpeg_dec_node_port_get_info,
spa_ffmpeg_dec_node_port_enum_params,
spa_ffmpeg_dec_node_port_set_param,
spa_ffmpeg_dec_node_port_use_buffers,
spa_ffmpeg_dec_node_port_alloc_buffers,
spa_ffmpeg_dec_node_port_set_io,
spa_ffmpeg_dec_node_port_reuse_buffer,
spa_ffmpeg_dec_node_port_send_command,
spa_ffmpeg_dec_node_process_input,
spa_ffmpeg_dec_node_process_output,
sizeof(struct spa_node),
NULL,
spa_ffmpeg_dec_node_get_props,
spa_ffmpeg_dec_node_set_props,
spa_ffmpeg_dec_node_send_command,
spa_ffmpeg_dec_node_set_callbacks,
spa_ffmpeg_dec_node_get_n_ports,
spa_ffmpeg_dec_node_get_port_ids,
spa_ffmpeg_dec_node_add_port,
spa_ffmpeg_dec_node_remove_port,
spa_ffmpeg_dec_node_port_enum_formats,
spa_ffmpeg_dec_node_port_set_format,
spa_ffmpeg_dec_node_port_get_format,
spa_ffmpeg_dec_node_port_get_info,
spa_ffmpeg_dec_node_port_enum_params,
spa_ffmpeg_dec_node_port_set_param,
spa_ffmpeg_dec_node_port_use_buffers,
spa_ffmpeg_dec_node_port_alloc_buffers,
spa_ffmpeg_dec_node_port_set_io,
spa_ffmpeg_dec_node_port_reuse_buffer,
spa_ffmpeg_dec_node_port_send_command,
spa_ffmpeg_dec_node_process_input,
spa_ffmpeg_dec_node_process_output,
};
static int
spa_ffmpeg_dec_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
spa_ffmpeg_dec_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
struct impl *this;
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (struct impl *) handle;
this = (struct impl *) handle;
if (interface_id == this->type.node)
*interface = &this->node;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
if (interface_id == this->type.node)
*interface = &this->node;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
int
spa_ffmpeg_dec_init (struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
spa_ffmpeg_dec_init(struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
struct impl *this;
uint32_t i;
struct impl *this;
uint32_t i;
handle->get_interface = spa_ffmpeg_dec_get_interface;
handle->get_interface = spa_ffmpeg_dec_get_interface;
this = (struct impl *) handle;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
init_type (&this->type, this->map);
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
init_type(&this->type, this->map);
this->node = ffmpeg_dec_node;
this->node = ffmpeg_dec_node;
this->in_ports[0].info.flags = 0;
this->out_ports[0].info.flags = 0;
this->in_ports[0].info.flags = 0;
this->out_ports[0].info.flags = 0;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}

View file

@ -32,495 +32,467 @@
#define MAX_BUFFERS 32
struct buffer {
struct spa_buffer buffer;
struct spa_meta metas[1];
struct spa_meta_header header;
struct spa_data datas[1];
struct spa_buffer *imported;
bool outstanding;
struct buffer *next;
struct spa_buffer buffer;
struct spa_meta metas[1];
struct spa_meta_header header;
struct spa_data datas[1];
struct spa_buffer *imported;
bool outstanding;
struct buffer *next;
};
struct port {
bool have_format;
struct spa_video_info current_format;
bool have_buffers;
struct buffer buffers[MAX_BUFFERS];
struct spa_port_info info;
struct spa_port_io *io;
bool have_format;
struct spa_video_info current_format;
bool have_buffers;
struct buffer buffers[MAX_BUFFERS];
struct spa_port_info info;
struct spa_port_io *io;
};
struct type {
uint32_t node;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_command_node command_node;
uint32_t node;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_command_node command_node;
};
static inline void
init_type (struct type *type, struct spa_type_map *map)
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
spa_type_media_type_map (map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype);
spa_type_format_video_map (map, &type->format_video);
spa_type_command_node_map (map, &type->command_node);
type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video);
spa_type_command_node_map(map, &type->command_node);
}
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct spa_node_callbacks callbacks;
void *user_data;
struct spa_node_callbacks callbacks;
void *user_data;
struct port in_ports[1];
struct port out_ports[1];
struct port in_ports[1];
struct port out_ports[1];
bool started;
bool started;
};
static int
spa_ffmpeg_enc_node_get_props (struct spa_node *node,
struct spa_props **props)
static int spa_ffmpeg_enc_node_get_props(struct spa_node *node, struct spa_props **props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int spa_ffmpeg_enc_node_set_props(struct spa_node *node, const struct spa_props *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int spa_ffmpeg_enc_node_send_command(struct spa_node *node, struct spa_command *command)
{
struct impl *this;
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
this->started = false;
} else
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_set_props (struct spa_node *node,
const struct spa_props *props)
spa_ffmpeg_enc_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size, void *user_data)
{
return SPA_RESULT_NOT_IMPLEMENTED;
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = *callbacks;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_send_command (struct spa_node *node,
struct spa_command *command)
spa_ffmpeg_enc_node_get_n_ports(struct spa_node *node,
uint32_t * n_input_ports,
uint32_t * max_input_ports,
uint32_t * n_output_ports, uint32_t * max_output_ports)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
this->started = true;
}
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
this->started = false;
}
else
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_set_callbacks (struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size,
void *user_data)
spa_ffmpeg_enc_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports,
uint32_t * input_ids,
uint32_t n_output_ports, uint32_t * output_ids)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0;
this = SPA_CONTAINER_OF (node, struct impl, node);
this->callbacks = *callbacks;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_get_n_ports (struct spa_node *node,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_get_port_ids (struct spa_node *node,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
spa_ffmpeg_enc_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_remove_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
spa_ffmpeg_enc_node_remove_port(struct spa_node *node,
enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_port_enum_formats (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_format **format,
const struct spa_format *filter,
uint32_t index)
spa_ffmpeg_enc_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_format **format,
const struct spa_format *filter, uint32_t index)
{
//struct impl *this;
//struct port *port;
//struct impl *this;
//struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
//this = SPA_CONTAINER_OF (node, struct impl, node);
//this = SPA_CONTAINER_OF (node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
//port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
//port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
switch (index) {
case 0:
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = NULL;
switch (index) {
case 0:
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = NULL;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_port_set_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
const struct spa_format *format)
spa_ffmpeg_enc_node_port_set_format(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags, const struct spa_format *format)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (format == NULL) {
port->have_format = false;
return SPA_RESULT_OK;
} else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE (format),
SPA_FORMAT_MEDIA_SUBTYPE (format), };
if (format == NULL) {
port->have_format = false;
return SPA_RESULT_OK;
} else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE(format),
};
if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
port->current_format = info;
port->have_format = true;
}
}
return SPA_RESULT_OK;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
port->current_format = info;
port->have_format = true;
}
}
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_port_get_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_format **format)
spa_ffmpeg_enc_node_port_get_format(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, const struct spa_format **format)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
*format = NULL;
*format = NULL;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_port_get_info (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_port_info **info)
spa_ffmpeg_enc_node_port_get_info(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, const struct spa_port_info **info)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_port_enum_params (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t index,
struct spa_param **param)
spa_ffmpeg_enc_node_port_enum_params(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, uint32_t index, struct spa_param **param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_port_set_param (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_param *param)
spa_ffmpeg_enc_node_port_set_param(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, const struct spa_param *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_port_use_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
spa_ffmpeg_enc_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers, uint32_t n_buffers)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (node, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(node, direction, port_id))
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_port_alloc_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t *n_buffers)
spa_ffmpeg_enc_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
uint32_t n_params,
struct spa_buffer **buffers, uint32_t * n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_port_set_io (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_port_io *io)
spa_ffmpeg_enc_node_port_set_io(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, struct spa_port_io *io)
{
struct impl *this;
struct port *port;
struct impl *this;
struct port *port;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
spa_ffmpeg_enc_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
spa_ffmpeg_enc_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_port_send_command (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_command *command)
spa_ffmpeg_enc_node_port_send_command(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, struct spa_command *command)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_enc_node_process_input (struct spa_node *node)
static int spa_ffmpeg_enc_node_process_input(struct spa_node *node)
{
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_INVALID_PORT;
}
static int
spa_ffmpeg_enc_node_process_output (struct spa_node *node)
static int spa_ffmpeg_enc_node_process_output(struct spa_node *node)
{
struct impl *this;
struct port *port;
struct spa_port_io *output;
struct impl *this;
struct port *port;
struct spa_port_io *output;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this = SPA_CONTAINER_OF(node, struct impl, node);
if ((output = this->out_ports[0].io) == NULL)
return SPA_RESULT_OK;
if ((output = this->out_ports[0].io) == NULL)
return SPA_RESULT_OK;
port = &this->out_ports[0];
port = &this->out_ports[0];
if (!port->have_format) {
output->status = SPA_RESULT_NO_FORMAT;
return SPA_RESULT_ERROR;
}
output->status = SPA_RESULT_OK;
if (!port->have_format) {
output->status = SPA_RESULT_NO_FORMAT;
return SPA_RESULT_ERROR;
}
output->status = SPA_RESULT_OK;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static const struct spa_node ffmpeg_enc_node = {
sizeof (struct spa_node),
NULL,
spa_ffmpeg_enc_node_get_props,
spa_ffmpeg_enc_node_set_props,
spa_ffmpeg_enc_node_send_command,
spa_ffmpeg_enc_node_set_callbacks,
spa_ffmpeg_enc_node_get_n_ports,
spa_ffmpeg_enc_node_get_port_ids,
spa_ffmpeg_enc_node_add_port,
spa_ffmpeg_enc_node_remove_port,
spa_ffmpeg_enc_node_port_enum_formats,
spa_ffmpeg_enc_node_port_set_format,
spa_ffmpeg_enc_node_port_get_format,
spa_ffmpeg_enc_node_port_get_info,
spa_ffmpeg_enc_node_port_enum_params,
spa_ffmpeg_enc_node_port_set_param,
spa_ffmpeg_enc_node_port_use_buffers,
spa_ffmpeg_enc_node_port_alloc_buffers,
spa_ffmpeg_enc_node_port_set_io,
spa_ffmpeg_enc_node_port_reuse_buffer,
spa_ffmpeg_enc_node_port_send_command,
spa_ffmpeg_enc_node_process_input,
spa_ffmpeg_enc_node_process_output,
sizeof(struct spa_node),
NULL,
spa_ffmpeg_enc_node_get_props,
spa_ffmpeg_enc_node_set_props,
spa_ffmpeg_enc_node_send_command,
spa_ffmpeg_enc_node_set_callbacks,
spa_ffmpeg_enc_node_get_n_ports,
spa_ffmpeg_enc_node_get_port_ids,
spa_ffmpeg_enc_node_add_port,
spa_ffmpeg_enc_node_remove_port,
spa_ffmpeg_enc_node_port_enum_formats,
spa_ffmpeg_enc_node_port_set_format,
spa_ffmpeg_enc_node_port_get_format,
spa_ffmpeg_enc_node_port_get_info,
spa_ffmpeg_enc_node_port_enum_params,
spa_ffmpeg_enc_node_port_set_param,
spa_ffmpeg_enc_node_port_use_buffers,
spa_ffmpeg_enc_node_port_alloc_buffers,
spa_ffmpeg_enc_node_port_set_io,
spa_ffmpeg_enc_node_port_reuse_buffer,
spa_ffmpeg_enc_node_port_send_command,
spa_ffmpeg_enc_node_process_input,
spa_ffmpeg_enc_node_process_output,
};
static int
spa_ffmpeg_enc_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
spa_ffmpeg_enc_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
struct impl *this;
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (struct impl *) handle;
this = (struct impl *) handle;
if (interface_id == this->type.node)
*interface = &this->node;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
if (interface_id == this->type.node)
*interface = &this->node;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
int
spa_ffmpeg_enc_init (struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
spa_ffmpeg_enc_init(struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support, uint32_t n_support)
{
struct impl *this;
uint32_t i;
struct impl *this;
uint32_t i;
handle->get_interface = spa_ffmpeg_enc_get_interface;
handle->get_interface = spa_ffmpeg_enc_get_interface;
this = (struct impl *) handle;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
this->node = ffmpeg_enc_node;
this->node = ffmpeg_enc_node;
this->in_ports[0].info.flags = 0;
this->out_ports[0].info.flags = 0;
this->in_ports[0].info.flags = 0;
this->out_ports[0].info.flags = 0;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}

View file

@ -25,92 +25,89 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
int spa_ffmpeg_dec_init (struct spa_handle *handle, const struct spa_dict *info, const struct spa_support *support, uint32_t n_support);
int spa_ffmpeg_enc_init (struct spa_handle *handle, const struct spa_dict *info, const struct spa_support *support, uint32_t n_support);
int spa_ffmpeg_dec_init(struct spa_handle *handle, const struct spa_dict *info,
const struct spa_support *support, uint32_t n_support);
int spa_ffmpeg_enc_init(struct spa_handle *handle, const struct spa_dict *info,
const struct spa_support *support, uint32_t n_support);
static int
ffmpeg_dec_init (const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
ffmpeg_dec_init(const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return spa_ffmpeg_dec_init (handle, info, support, n_support);
return spa_ffmpeg_dec_init(handle, info, support, n_support);
}
static int
ffmpeg_enc_init (const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
ffmpeg_enc_init(const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return spa_ffmpeg_enc_init (handle, info, support, n_support);
return spa_ffmpeg_enc_init(handle, info, support, n_support);
}
static const struct spa_interface_info ffmpeg_interfaces[] =
{
{ SPA_TYPE__Node,
},
static const struct spa_interface_info ffmpeg_interfaces[] = {
{SPA_TYPE__Node, },
};
static int
ffmpeg_enum_interface_info (const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
ffmpeg_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
{
if (factory == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (factory == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (index >= 1)
return SPA_RESULT_ENUM_END;
if (index >= 1)
return SPA_RESULT_ENUM_END;
*info = &ffmpeg_interfaces[index];
*info = &ffmpeg_interfaces[index];
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
int
spa_handle_factory_enum (const struct spa_handle_factory **factory,
uint32_t index)
int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
{
static const AVCodec *c = NULL;
static int ci = 0;
static struct spa_handle_factory f;
static char name[128];
static const AVCodec *c = NULL;
static int ci = 0;
static struct spa_handle_factory f;
static char name[128];
av_register_all();
av_register_all();
if (index == 0) {
c = av_codec_next (NULL);
ci = 0;
}
while (index > ci && c) {
c = av_codec_next (c);
ci++;
}
if (c == NULL)
return SPA_RESULT_ENUM_END;
if (index == 0) {
c = av_codec_next(NULL);
ci = 0;
}
while (index > ci && c) {
c = av_codec_next(c);
ci++;
}
if (c == NULL)
return SPA_RESULT_ENUM_END;
if (av_codec_is_encoder (c)) {
snprintf (name, 128, "ffenc_%s", c->name);
f.init = ffmpeg_enc_init;
}
else {
snprintf (name, 128, "ffdec_%s", c->name);
f.init = ffmpeg_dec_init;
}
f.name = name;
f.info = NULL;
f.enum_interface_info = ffmpeg_enum_interface_info;
if (av_codec_is_encoder(c)) {
snprintf(name, 128, "ffenc_%s", c->name);
f.init = ffmpeg_enc_init;
} else {
snprintf(name, 128, "ffdec_%s", c->name);
f.init = ffmpeg_dec_init;
}
f.name = name;
f.info = NULL;
f.enum_interface_info = ffmpeg_enum_interface_info;
*factory = &f;
*factory = &f;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}

View file

@ -1,528 +0,0 @@
/* Spa Libva Decoder
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <spa/node.h>
#include <spa/video/format.h>
typedef struct _SpaLibvaDec SpaLibvaDec;
typedef struct {
SpaProps props;
} SpaLibvaDecProps;
static void
reset_libva_dec_props (SpaLibvaDecProps *props)
{
}
#define INPUT_PORT_ID 0
#define OUTPUT_PORT_ID 1
#define IS_VALID_PORT(id) ((id) < 2)
#define MAX_BUFFERS 32
typedef struct _LibvaBuffer LibvaBuffer;
struct _LibvaBuffer {
SpaBuffer buffer;
SpaMeta metas[1];
SpaMetaHeader header;
SpaData datas[1];
SpaLibvaDec *dec;
SpaBuffer *imported;
bool outstanding;
LibvaBuffer *next;
};
typedef struct {
SpaVideoRawFormat raw_format[2];
SpaFormat *current_format;
bool have_buffers;
LibvaBuffer buffers[MAX_BUFFERS];
SpaPortInfo info;
SpaPortStatus status;
} SpaLibvaState;
struct _SpaLibvaDec {
SpaHandle handle;
SpaLibvaDecProps props[2];
SpaNodeEventCallback event_cb;
void *user_data;
SpaLibvaState state[2];
};
enum {
PROP_ID_LAST,
};
static const SpaPropInfo prop_info[] =
{
{ 0, },
};
static int
spa_libva_dec_node_get_props (SpaHandle *handle,
SpaProps **props)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_set_props (SpaHandle *handle,
const SpaProps *props)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaDecProps *p = &this->props[1];
int res;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (props == NULL) {
reset_libva_dec_props (p);
return SPA_RESULT_OK;
}
res = spa_props_copy_values (props, &p->props);
return res;
}
static int
spa_libva_dec_node_send_command (SpaHandle *handle,
SpaCommand *command)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (command->type) {
case SPA_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
case SPA_COMMAND_START:
if (this->event_cb) {
SpaNodeEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_NODE_EVENT_TYPE_STARTED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_STOP:
if (this->event_cb) {
SpaNodeEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_NODE_EVENT_TYPE_STOPPED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_FLUSH:
case SPA_COMMAND_DRAIN:
case SPA_COMMAND_MARKER:
return SPA_RESULT_NOT_IMPLEMENTED;
}
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_set_event_callback (SpaHandle *handle,
SpaNodeEventCallback event,
void *user_data)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this->event_cb = event;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_get_n_ports (SpaHandle *handle,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_get_port_ids (SpaHandle *handle,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_add_port (SpaHandle *handle,
SpaDirection direction,
uint32_t *port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_remove_port (SpaHandle *handle,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_enum_formats (SpaHandle *handle,
uint32_t port_id,
uint32_t index,
SpaFormat **format)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
switch (index) {
case 0:
spa_video_raw_format_init (&state->raw_format[0]);
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = &state->raw_format[0].format;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_set_format (SpaHandle *handle,
uint32_t port_id,
bool test_only,
const SpaFormat *format)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
int res;
SpaFormat *f, *tf;
size_t fs;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (format == NULL) {
state->current_format = NULL;
return SPA_RESULT_OK;
}
if (format->media_type == SPA_MEDIA_TYPE_VIDEO) {
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
if ((res = spa_video_raw_format_parse (format, &state->raw_format[0]) < 0))
return res;
f = &state->raw_format[0].format;
tf = &state->raw_format[1].format;
fs = sizeof (SpaVideoRawFormat);
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!test_only) {
memcpy (tf, f, fs);
state->current_format = tf;
}
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_get_format (SpaHandle *handle,
uint32_t port_id,
const SpaFormat **format)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (state->current_format == NULL)
return SPA_RESULT_NO_FORMAT;
*format = state->current_format;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_get_info (SpaHandle *handle,
uint32_t port_id,
const SpaPortInfo **info)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*info = &this->state[port_id].info;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_get_props (SpaHandle *handle,
uint32_t port_id,
SpaProps **props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_set_props (SpaHandle *handle,
uint32_t port_id,
const SpaProps *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_get_status (SpaHandle *handle,
uint32_t port_id,
const SpaPortStatus **status)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*status = &this->state[port_id].status;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_use_buffers (SpaHandle *handle,
uint32_t port_id,
SpaBuffer **buffers,
uint32_t n_buffers)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_alloc_buffers (SpaHandle *handle,
uint32_t port_id,
SpaParam **params,
uint32_t n_params,
SpaBuffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_push_input (SpaHandle *handle,
uint32_t n_info,
SpaInputInfo *info)
{
return SPA_RESULT_INVALID_PORT;
}
static int
spa_libva_dec_node_port_pull_output (SpaHandle *handle,
uint32_t n_info,
SpaOutputInfo *info)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
uint32_t i;
bool have_error = false;
if (handle == NULL || n_info == 0 || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
for (i = 0; i < n_info; i++) {
if (info[i].port_id != OUTPUT_PORT_ID) {
info[i].status = SPA_RESULT_INVALID_PORT;
have_error = true;
continue;
}
state = &this->state[info[i].port_id];
if (state->current_format == NULL) {
info[i].status = SPA_RESULT_NO_FORMAT;
have_error = true;
continue;
}
info[i].status = SPA_RESULT_OK;
}
if (have_error)
return SPA_RESULT_ERROR;
return SPA_RESULT_OK;
}
static const SpaNode libva_dec_node = {
sizeof (SpaNode),
spa_libva_dec_node_get_props,
spa_libva_dec_node_set_props,
spa_libva_dec_node_send_command,
spa_libva_dec_node_set_event_callback,
spa_libva_dec_node_get_n_ports,
spa_libva_dec_node_get_port_ids,
spa_libva_dec_node_add_port,
spa_libva_dec_node_remove_port,
spa_libva_dec_node_port_enum_formats,
spa_libva_dec_node_port_set_format,
spa_libva_dec_node_port_get_format,
spa_libva_dec_node_port_get_info,
spa_libva_dec_node_port_get_props,
spa_libva_dec_node_port_set_props,
spa_libva_dec_node_port_use_buffers,
spa_libva_dec_node_port_alloc_buffers,
spa_libva_dec_node_port_get_status,
spa_libva_dec_node_port_push_input,
spa_libva_dec_node_port_pull_output,
};
static int
spa_libva_dec_get_interface (SpaHandle *handle,
uint32_t interface_id,
const void **interface)
{
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (interface_id) {
case SPA_INTERFACE_ID_NODE:
*interface = &libva_dec_node;
break;
default:
return SPA_RESULT_UNKNOWN_INTERFACE;
}
return SPA_RESULT_OK;
}
SpaHandle *
spa_libva_dec_new (void)
{
SpaHandle *handle;
SpaLibvaDec *this;
handle = calloc (1, sizeof (SpaLibvaDec));
handle->get_interface = spa_libva_dec_get_interface;
this = (SpaLibvaDec *) handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_libva_dec_props (&this->props[1]);
this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[INPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
this->state[OUTPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[OUTPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
return handle;
}

View file

@ -1,530 +0,0 @@
/* Spa Libva Encoder
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <spa/node.h>
#include <spa/video/format.h>
typedef struct _SpaLibvaEnc SpaLibvaEnc;
typedef struct {
SpaProps props;
} SpaLibvaEncProps;
static void
reset_libva_enc_props (SpaLibvaEncProps *props)
{
}
#define INPUT_PORT_ID 0
#define OUTPUT_PORT_ID 1
#define IS_VALID_PORT(id) ((id) < 2)
#define MAX_BUFFERS 32
typedef struct _LibvaBuffer LibvaBuffer;
struct _LibvaBuffer {
SpaBuffer buffer;
SpaMeta metas[1];
SpaMetaHeader header;
SpaData datas[1];
SpaLibvaEnc *enc;
SpaBuffer *imported;
bool outstanding;
LibvaBuffer *next;
};
typedef struct {
SpaVideoRawFormat raw_format[2];
SpaFormat *current_format;
bool have_buffers;
LibvaBuffer buffers[MAX_BUFFERS];
SpaPortInfo info;
SpaAllocParam *params[1];
SpaAllocParamBuffers param_buffers;
SpaPortStatus status;
} SpaLibvaState;
struct _SpaLibvaEnc {
SpaHandle handle;
SpaLibvaEncProps props[2];
SpaEventCallback event_cb;
void *user_data;
SpaLibvaState state[2];
};
enum {
PROP_ID_LAST,
};
static const SpaPropInfo prop_info[] =
{
{ 0, },
};
static int
spa_libva_enc_node_get_props (SpaHandle *handle,
SpaProps **props)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_set_props (SpaHandle *handle,
const SpaProps *props)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaEncProps *p = &this->props[1];
int res;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (props == NULL) {
reset_libva_enc_props (p);
return SPA_RESULT_OK;
}
res = spa_props_copy_values (props, &p->props);
return res;
}
static int
spa_libva_enc_node_send_command (SpaHandle *handle,
SpaCommand *command)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (command->type) {
case SPA_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
case SPA_COMMAND_START:
if (this->event_cb) {
SpaEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_EVENT_TYPE_STARTED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_STOP:
if (this->event_cb) {
SpaEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_EVENT_TYPE_STOPPED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_FLUSH:
case SPA_COMMAND_DRAIN:
case SPA_COMMAND_MARKER:
return SPA_RESULT_NOT_IMPLEMENTED;
}
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_set_event_callback (SpaHandle *handle,
SpaEventCallback event,
void *user_data)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this->event_cb = event;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_get_n_ports (SpaHandle *handle,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_get_port_ids (SpaHandle *handle,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_add_port (SpaHandle *handle,
SpaDirection direction,
uint32_t *port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_remove_port (SpaHandle *handle,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_enum_formats (SpaHandle *handle,
uint32_t port_id,
uint32_t index,
SpaFormat **format)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
switch (index) {
case 0:
spa_video_raw_format_init (&state->raw_format[0]);
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = &state->raw_format[0].format;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_set_format (SpaHandle *handle,
uint32_t port_id,
bool test_only,
const SpaFormat *format)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
int res;
SpaFormat *f, *tf;
size_t fs;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (format == NULL) {
state->current_format = NULL;
return SPA_RESULT_OK;
}
if (format->media_type == SPA_MEDIA_TYPE_VIDEO) {
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
if ((res = spa_video_raw_format_parse (format, &state->raw_format[0]) < 0))
return res;
f = &state->raw_format[0].format;
tf = &state->raw_format[1].format;
fs = sizeof (SpaVideoRawFormat);
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!test_only) {
memcpy (tf, f, fs);
state->current_format = tf;
}
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_get_format (SpaHandle *handle,
uint32_t port_id,
const SpaFormat **format)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (state->current_format == NULL)
return SPA_RESULT_NO_FORMAT;
*format = state->current_format;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_get_info (SpaHandle *handle,
uint32_t port_id,
const SpaPortInfo **info)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*info = &this->state[port_id].info;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_get_props (SpaHandle *handle,
uint32_t port_id,
SpaProps **props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_set_props (SpaHandle *handle,
uint32_t port_id,
const SpaProps *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_get_status (SpaHandle *handle,
uint32_t port_id,
const SpaPortStatus **status)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*status = &this->state[port_id].status;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_use_buffers (SpaHandle *handle,
uint32_t port_id,
SpaBuffer **buffers,
uint32_t n_buffers)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_alloc_buffers (SpaHandle *handle,
uint32_t port_id,
SpaAllocParam **params,
uint32_t n_params,
SpaBuffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_push_input (SpaHandle *handle,
uint32_t n_info,
SpaInputInfo *info)
{
return SPA_RESULT_INVALID_PORT;
}
static int
spa_libva_enc_node_port_pull_output (SpaHandle *handle,
uint32_t n_info,
SpaOutputInfo *info)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
uint32_t i;
bool have_error = false;
if (handle == NULL || n_info == 0 || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
for (i = 0; i < n_info; i++) {
if (info[i].port_id != OUTPUT_PORT_ID) {
info[i].status = SPA_RESULT_INVALID_PORT;
have_error = true;
continue;
}
state = &this->state[info[i].port_id];
if (state->current_format == NULL) {
info[i].status = SPA_RESULT_NO_FORMAT;
have_error = true;
continue;
}
info[i].status = SPA_RESULT_OK;
}
if (have_error)
return SPA_RESULT_ERROR;
return SPA_RESULT_OK;
}
static const SpaNode libva_enc_node = {
sizeof (SpaNode),
spa_libva_enc_node_get_props,
spa_libva_enc_node_set_props,
spa_libva_enc_node_send_command,
spa_libva_enc_node_set_event_callback,
spa_libva_enc_node_get_n_ports,
spa_libva_enc_node_get_port_ids,
spa_libva_enc_node_add_port,
spa_libva_enc_node_remove_port,
spa_libva_enc_node_port_enum_formats,
spa_libva_enc_node_port_set_format,
spa_libva_enc_node_port_get_format,
spa_libva_enc_node_port_get_info,
spa_libva_enc_node_port_get_props,
spa_libva_enc_node_port_set_props,
spa_libva_enc_node_port_use_buffers,
spa_libva_enc_node_port_alloc_buffers,
spa_libva_enc_node_port_get_status,
spa_libva_enc_node_port_push_input,
spa_libva_enc_node_port_pull_output,
};
static int
spa_libva_enc_get_interface (SpaHandle *handle,
uint32_t interface_id,
const void **interface)
{
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (interface_id) {
case SPA_INTERFACE_ID_NODE:
*interface = &libva_enc_node;
break;
default:
return SPA_RESULT_UNKNOWN_INTERFACE;
}
return SPA_RESULT_OK;
}
SpaHandle *
spa_libva_enc_new (void)
{
SpaHandle *handle;
SpaLibvaEnc *this;
handle = calloc (1, sizeof (SpaLibvaEnc));
handle->get_interface = spa_libva_enc_get_interface;
this = (SpaLibvaEnc *) handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_libva_enc_props (&this->props[1]);
this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[INPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
this->state[OUTPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[OUTPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
return handle;
}

View file

@ -1,96 +0,0 @@
/* Spa V4l2 support
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <spa/plugin.h>
#include <spa/node.h>
SpaHandle * spa_libva_dec_new (void);
SpaHandle * spa_libva_enc_new (void);
static int
libva_dec_instantiate (const struct spa_handle_factory *factory,
SpaHandle **handle)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
*handle = spa_libva_dec_new ();
return SPA_RESULT_OK;
}
static int
libva_enc_instantiate (const struct spa_handle_factory *factory,
SpaHandle **handle)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
*handle = spa_libva_enc_new ();
return SPA_RESULT_OK;
}
static const struct spa_interface_info libva_interfaces[] =
{
{ SPA_INTERFACE_ID_NODE,
SPA_INTERFACE_ID_NODE_NAME,
SPA_INTERFACE_ID_NODE_DESCRIPTION,
},
};
static int
libva_enum_interface_info (const struct spa_handle_factory *factory,
uint32_t index,
const struct spa_interface_info **info)
{
if (index >= 1)
return SPA_RESULT_ENUM_END;
*info = &libva_interfaces[index];
return SPA_RESULT_OK;
}
static const struct spa_handle_factory factories[] =
{
{ "libva-dec",
NULL,
libva_dec_instantiate,
libva_enum_interface_info,
},
{ "libva-enc",
NULL,
libva_enc_instantiate,
libva_enum_interface_info,
}
};
int
spa_handle_factory_enum (uint32_t index,
const struct spa_handle_factory **factory)
{
if (index >= 2)
return SPA_RESULT_ENUM_END;
*factory = &factories[index];
return SPA_RESULT_OK;
}

View file

@ -1,11 +0,0 @@
libva_sources = ['libva.c',
'libva-dec.c',
'libva-enc.c']
libvalib = shared_library('spa-libva',
libva_sources,
include_directories : inc,
dependencies : libva_dep,
link_with : spalib,
install : true,
install_dir : '@0@/spa'.format(get_option('libdir')))

File diff suppressed because it is too large Load diff

View file

@ -1,38 +0,0 @@
/*
* Copyright © 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _VAAPI_RECORDER_H_
#define _VAAPI_RECORDER_H_
struct vaapi_recorder;
struct vaapi_recorder *
vaapi_recorder_create(int drm_fd, int width, int height, const char *filename);
void
vaapi_recorder_destroy(struct vaapi_recorder *r);
int
vaapi_recorder_frame(struct vaapi_recorder *r, int fd, int stride);
#endif /* _VAAPI_RECORDER_H_ */

View file

@ -3,8 +3,6 @@ subdir('audiomixer')
subdir('audiotestsrc')
subdir('ffmpeg')
subdir('test')
#subdir('libva')
subdir('videotestsrc')
subdir('volume')
subdir('v4l2')
subdir('xv')

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -24,11 +24,9 @@ extern const struct spa_handle_factory spa_fakesrc_factory;
extern const struct spa_handle_factory spa_fakesink_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
{
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:

View file

@ -36,390 +36,386 @@
extern const struct spa_handle_factory spa_v4l2_source_factory;
struct item {
struct spa_monitor_item *item;
struct udev_device *udevice;
struct spa_monitor_item *item;
struct udev_device *udevice;
};
struct type {
uint32_t handle_factory;
struct spa_type_monitor monitor;
uint32_t handle_factory;
struct spa_type_monitor monitor;
};
static inline void
init_type (struct type *type, struct spa_type_map *map)
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->handle_factory = spa_type_map_get_id (map, SPA_TYPE__HandleFactory);
spa_type_monitor_map (map, &type->monitor);
type->handle_factory = spa_type_map_get_id(map, SPA_TYPE__HandleFactory);
spa_type_monitor_map(map, &type->monitor);
}
struct impl {
struct spa_handle handle;
struct spa_monitor monitor;
struct spa_handle handle;
struct spa_monitor monitor;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct spa_loop *main_loop;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct spa_loop *main_loop;
struct spa_monitor_callbacks callbacks;
void *user_data;
struct spa_monitor_callbacks callbacks;
void *user_data;
struct udev* udev;
struct udev_monitor *umonitor;
struct udev_enumerate *enumerate;
uint32_t index;
struct udev_list_entry *devices;
uint8_t item_buffer[4096];
struct udev *udev;
struct udev_monitor *umonitor;
struct udev_enumerate *enumerate;
uint32_t index;
struct udev_list_entry *devices;
uint8_t item_buffer[4096];
struct item uitem;
struct item uitem;
struct spa_source source;
struct spa_source source;
};
static int
impl_udev_open (struct impl *this)
static int impl_udev_open(struct impl *this)
{
if (this->udev != NULL)
return SPA_RESULT_OK;
if (this->udev != NULL)
return SPA_RESULT_OK;
this->udev = udev_new ();
this->udev = udev_new();
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static void
fill_item (struct impl *this, struct item *item, struct udev_device *udevice)
static void fill_item(struct impl *this, struct item *item, struct udev_device *udevice)
{
const char *str, *name;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[3];
const char *str, *name;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[3];
if (item->udevice)
udev_device_unref (item->udevice);
item->udevice = udevice;
if (udevice == NULL)
return;
if (item->udevice)
udev_device_unref(item->udevice);
item->udevice = udevice;
if (udevice == NULL)
return;
name = udev_device_get_property_value (item->udevice, "ID_V4L_PRODUCT");
if (!(name && *name)) {
name = udev_device_get_property_value (item->udevice, "ID_MODEL_FROM_DATABASE");
if (!(name && *name)) {
name = udev_device_get_property_value (item->udevice, "ID_MODEL_ENC");
if (!(name && *name)) {
name = udev_device_get_property_value (item->udevice, "ID_MODEL");
}
}
}
if (!(name && *name))
name = "Unknown";
name = udev_device_get_property_value(item->udevice, "ID_V4L_PRODUCT");
if (!(name && *name)) {
name = udev_device_get_property_value(item->udevice, "ID_MODEL_FROM_DATABASE");
if (!(name && *name)) {
name = udev_device_get_property_value(item->udevice, "ID_MODEL_ENC");
if (!(name && *name)) {
name = udev_device_get_property_value(item->udevice, "ID_MODEL");
}
}
}
if (!(name && *name))
name = "Unknown";
spa_pod_builder_init (&b, this->item_buffer, sizeof (this->item_buffer));
spa_pod_builder_init(&b, this->item_buffer, sizeof(this->item_buffer));
spa_pod_builder_push_object (&b, &f[0], 0, this->type.monitor.MonitorItem);
spa_pod_builder_push_object(&b, &f[0], 0, this->type.monitor.MonitorItem);
spa_pod_builder_add (&b,
SPA_POD_PROP (&f[1], this->type.monitor.id, 0, SPA_POD_TYPE_STRING, 1, udev_device_get_syspath (item->udevice)),
SPA_POD_PROP (&f[1], this->type.monitor.flags, 0, SPA_POD_TYPE_INT, 1, 0),
SPA_POD_PROP (&f[1], this->type.monitor.state, 0, SPA_POD_TYPE_INT, 1, SPA_MONITOR_ITEM_STATE_AVAILABLE),
SPA_POD_PROP (&f[1], this->type.monitor.name, 0, SPA_POD_TYPE_STRING, 1, name),
SPA_POD_PROP (&f[1], this->type.monitor.klass, 0, SPA_POD_TYPE_STRING, 1, "Video/Source"),
SPA_POD_PROP (&f[1], this->type.monitor.factory, 0, SPA_POD_TYPE_POINTER, 1, this->type.handle_factory,
&spa_v4l2_source_factory),
0);
spa_pod_builder_add (&b,
SPA_POD_TYPE_PROP, &f[1], this->type.monitor.info, 0,
SPA_POD_TYPE_STRUCT, 1, &f[2], 0);
spa_pod_builder_add(&b,
SPA_POD_PROP(&f[1], this->type.monitor.id, 0, SPA_POD_TYPE_STRING, 1,
udev_device_get_syspath(item->udevice)),
SPA_POD_PROP(&f[1], this->type.monitor.flags, 0, SPA_POD_TYPE_INT, 1,
0),
SPA_POD_PROP(&f[1], this->type.monitor.state, 0, SPA_POD_TYPE_INT, 1,
SPA_MONITOR_ITEM_STATE_AVAILABLE),
SPA_POD_PROP(&f[1], this->type.monitor.name, 0, SPA_POD_TYPE_STRING, 1,
name),
SPA_POD_PROP(&f[1], this->type.monitor.klass, 0, SPA_POD_TYPE_STRING, 1,
"Video/Source"),
SPA_POD_PROP(&f[1], this->type.monitor.factory, 0, SPA_POD_TYPE_POINTER, 1,
this->type.handle_factory, &spa_v4l2_source_factory),
0);
spa_pod_builder_add(&b,
SPA_POD_TYPE_PROP, &f[1], this->type.monitor.info, 0,
SPA_POD_TYPE_STRUCT, 1, &f[2], 0);
spa_pod_builder_add (&b,
SPA_POD_TYPE_STRING, "udev-probed", SPA_POD_TYPE_STRING, "1",
SPA_POD_TYPE_STRING, "device.api", SPA_POD_TYPE_STRING, "v4l2",
SPA_POD_TYPE_STRING, "device.path", SPA_POD_TYPE_STRING, udev_device_get_devnode (item->udevice),
0);
spa_pod_builder_add(&b,
SPA_POD_TYPE_STRING, "udev-probed", SPA_POD_TYPE_STRING, "1",
SPA_POD_TYPE_STRING, "device.api", SPA_POD_TYPE_STRING, "v4l2",
SPA_POD_TYPE_STRING, "device.path", SPA_POD_TYPE_STRING,
udev_device_get_devnode(item->udevice), 0);
str = udev_device_get_property_value (item->udevice, "ID_PATH");
if (!(str && *str))
str = udev_device_get_syspath (item->udevice);
if (str && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.bus_path", SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_syspath (item->udevice)) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "sysfs.path", SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value (item->udevice, "ID_ID")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "udev.id", SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value (item->udevice, "ID_BUS")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.bus", SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value (item->udevice, "SUBSYSTEM")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.subsystem", SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value (item->udevice, "ID_VENDOR_ID")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.vendor.id", SPA_POD_TYPE_STRING, str, 0);
}
str = udev_device_get_property_value (item->udevice, "ID_VENDOR_FROM_DATABASE");
if (!(str && *str)) {
str = udev_device_get_property_value (item->udevice, "ID_VENDOR_ENC");
if (!(str && *str)) {
str = udev_device_get_property_value (item->udevice, "ID_VENDOR");
}
}
if (str && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.vendor.name", SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value (item->udevice, "ID_MODEL_ID")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.product.id", SPA_POD_TYPE_STRING, str, 0);
}
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.product.name", SPA_POD_TYPE_STRING, name, 0);
if ((str = udev_device_get_property_value (item->udevice, "ID_SERIAL")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.serial", SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value (item->udevice, "ID_V4L_CAPABILITIES")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.capabilities", SPA_POD_TYPE_STRING, str, 0);
}
str = udev_device_get_property_value(item->udevice, "ID_PATH");
if (!(str && *str))
str = udev_device_get_syspath(item->udevice);
if (str && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.bus_path", SPA_POD_TYPE_STRING,
str, 0);
}
if ((str = udev_device_get_syspath(item->udevice)) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "sysfs.path", SPA_POD_TYPE_STRING,
str, 0);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_ID")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "udev.id", SPA_POD_TYPE_STRING,
str, 0);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_BUS")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.bus", SPA_POD_TYPE_STRING,
str, 0);
}
if ((str = udev_device_get_property_value(item->udevice, "SUBSYSTEM")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.subsystem",
SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_VENDOR_ID")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.vendor.id",
SPA_POD_TYPE_STRING, str, 0);
}
str = udev_device_get_property_value(item->udevice, "ID_VENDOR_FROM_DATABASE");
if (!(str && *str)) {
str = udev_device_get_property_value(item->udevice, "ID_VENDOR_ENC");
if (!(str && *str)) {
str = udev_device_get_property_value(item->udevice, "ID_VENDOR");
}
}
if (str && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.vendor.name",
SPA_POD_TYPE_STRING, str, 0);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_MODEL_ID")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.product.id",
SPA_POD_TYPE_STRING, str, 0);
}
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.product.name", SPA_POD_TYPE_STRING,
name, 0);
if ((str = udev_device_get_property_value(item->udevice, "ID_SERIAL")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.serial", SPA_POD_TYPE_STRING,
str, 0);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_V4L_CAPABILITIES")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.capabilities",
SPA_POD_TYPE_STRING, str, 0);
}
spa_pod_builder_add (&b,
-SPA_POD_TYPE_STRUCT, &f[2],
-SPA_POD_TYPE_PROP, &f[1],
0);
spa_pod_builder_add(&b, -SPA_POD_TYPE_STRUCT, &f[2], -SPA_POD_TYPE_PROP, &f[1], 0);
spa_pod_builder_pop (&b, &f[0]);
spa_pod_builder_pop(&b, &f[0]);
item->item = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_monitor_item);
item->item = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_monitor_item);
}
static void
impl_on_fd_events (struct spa_source *source)
static void impl_on_fd_events(struct spa_source *source)
{
struct impl *this = source->data;
struct udev_device *dev;
struct spa_event *event;
const char *action;
uint32_t type;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[1];
uint8_t buffer[4096];
struct impl *this = source->data;
struct udev_device *dev;
struct spa_event *event;
const char *action;
uint32_t type;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[1];
uint8_t buffer[4096];
dev = udev_monitor_receive_device (this->umonitor);
fill_item (this, &this->uitem, dev);
if (dev == NULL)
return;
dev = udev_monitor_receive_device(this->umonitor);
fill_item(this, &this->uitem, dev);
if (dev == NULL)
return;
if ((action = udev_device_get_action (dev)) == NULL)
action = "change";
if ((action = udev_device_get_action(dev)) == NULL)
action = "change";
if (strcmp (action, "add") == 0) {
type = this->type.monitor.Added;
} else if (strcmp (action, "change") == 0) {
type = this->type.monitor.Changed;
} else if (strcmp (action, "remove") == 0) {
type = this->type.monitor.Removed;
} else
return;
if (strcmp(action, "add") == 0) {
type = this->type.monitor.Added;
} else if (strcmp(action, "change") == 0) {
type = this->type.monitor.Changed;
} else if (strcmp(action, "remove") == 0) {
type = this->type.monitor.Removed;
} else
return;
spa_pod_builder_init (&b, buffer, sizeof (buffer));
spa_pod_builder_object (&b, &f[0], 0, type,
SPA_POD_TYPE_POD, this->uitem.item);
spa_pod_builder_init(&b, buffer, sizeof(buffer));
spa_pod_builder_object(&b, &f[0], 0, type, SPA_POD_TYPE_POD, this->uitem.item);
event = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_event);
this->callbacks.event (&this->monitor, event, this->user_data);
event = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_event);
this->callbacks.event(&this->monitor, event, this->user_data);
}
static int
impl_monitor_set_callbacks (struct spa_monitor *monitor,
const struct spa_monitor_callbacks *callbacks,
size_t callbacks_size,
void *user_data)
impl_monitor_set_callbacks(struct spa_monitor *monitor,
const struct spa_monitor_callbacks *callbacks,
size_t callbacks_size, void *user_data)
{
int res;
struct impl *this;
int res;
struct impl *this;
spa_return_val_if_fail (monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (monitor, struct impl, monitor);
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
if (callbacks) {
this->callbacks = *callbacks;
this->user_data = user_data;
if (callbacks) {
this->callbacks = *callbacks;
this->user_data = user_data;
if ((res = impl_udev_open (this)) < 0)
return res;
if ((res = impl_udev_open(this)) < 0)
return res;
this->umonitor = udev_monitor_new_from_netlink (this->udev, "udev");
if (!this->umonitor)
return SPA_RESULT_ERROR;
this->umonitor = udev_monitor_new_from_netlink(this->udev, "udev");
if (!this->umonitor)
return SPA_RESULT_ERROR;
udev_monitor_filter_add_match_subsystem_devtype (this->umonitor,
"video4linux",
NULL);
udev_monitor_filter_add_match_subsystem_devtype(this->umonitor,
"video4linux", NULL);
udev_monitor_enable_receiving (this->umonitor);
this->source.func = impl_on_fd_events;
this->source.data = this;
this->source.fd = udev_monitor_get_fd (this->umonitor);;
this->source.mask = SPA_IO_IN | SPA_IO_ERR;
udev_monitor_enable_receiving(this->umonitor);
this->source.func = impl_on_fd_events;
this->source.data = this;
this->source.fd = udev_monitor_get_fd(this->umonitor);;
this->source.mask = SPA_IO_IN | SPA_IO_ERR;
spa_loop_add_source (this->main_loop, &this->source);
} else {
spa_zero (this->callbacks);
spa_loop_remove_source (this->main_loop, &this->source);
}
spa_loop_add_source(this->main_loop, &this->source);
} else {
spa_zero(this->callbacks);
spa_loop_remove_source(this->main_loop, &this->source);
}
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
impl_monitor_enum_items (struct spa_monitor *monitor,
struct spa_monitor_item **item,
uint32_t index)
impl_monitor_enum_items(struct spa_monitor *monitor, struct spa_monitor_item **item, uint32_t index)
{
int res;
struct impl *this;
struct udev_device *dev;
int res;
struct impl *this;
struct udev_device *dev;
spa_return_val_if_fail (monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (item != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(item != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (monitor, struct impl, monitor);
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
if ((res = impl_udev_open (this)) < 0)
return res;
if ((res = impl_udev_open(this)) < 0)
return res;
if (index == 0) {
if (this->enumerate)
udev_enumerate_unref (this->enumerate);
this->enumerate = udev_enumerate_new (this->udev);
if (index == 0) {
if (this->enumerate)
udev_enumerate_unref(this->enumerate);
this->enumerate = udev_enumerate_new(this->udev);
udev_enumerate_add_match_subsystem (this->enumerate, "video4linux");
udev_enumerate_scan_devices (this->enumerate);
udev_enumerate_add_match_subsystem(this->enumerate, "video4linux");
udev_enumerate_scan_devices(this->enumerate);
this->devices = udev_enumerate_get_list_entry (this->enumerate);
this->index = 0;
}
while (index > this->index && this->devices) {
this->devices = udev_list_entry_get_next (this->devices);
this->index++;
}
if (this->devices == NULL) {
fill_item (this, &this->uitem, NULL);
return SPA_RESULT_ENUM_END;
}
this->devices = udev_enumerate_get_list_entry(this->enumerate);
this->index = 0;
}
while (index > this->index && this->devices) {
this->devices = udev_list_entry_get_next(this->devices);
this->index++;
}
if (this->devices == NULL) {
fill_item(this, &this->uitem, NULL);
return SPA_RESULT_ENUM_END;
}
dev = udev_device_new_from_syspath (this->udev,
udev_list_entry_get_name (this->devices));
dev = udev_device_new_from_syspath(this->udev, udev_list_entry_get_name(this->devices));
fill_item (this, &this->uitem, dev);
if (dev == NULL)
return SPA_RESULT_ENUM_END;
fill_item(this, &this->uitem, dev);
if (dev == NULL)
return SPA_RESULT_ENUM_END;
*item = this->uitem.item;
*item = this->uitem.item;
this->devices = udev_list_entry_get_next (this->devices);
this->index++;
this->devices = udev_list_entry_get_next(this->devices);
this->index++;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static const struct spa_monitor impl_monitor = {
NULL,
sizeof (struct spa_monitor),
impl_monitor_set_callbacks,
impl_monitor_enum_items,
NULL,
sizeof(struct spa_monitor),
impl_monitor_set_callbacks,
impl_monitor_enum_items,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle;
if (interface_id == this->type.monitor.Monitor)
*interface = &this->monitor;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return SPA_RESULT_OK;
}
static int impl_clear(struct spa_handle *handle)
{
return SPA_RESULT_OK;
}
static int
impl_init(const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
struct impl *this;
uint32_t i;
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear, this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
this->main_loop = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
if (this->main_loop == NULL) {
spa_log_error(this->log, "a main-loop is needed");
return SPA_RESULT_ERROR;
}
init_type(&this->type, this->map);
this->monitor = impl_monitor;
return SPA_RESULT_OK;
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Monitor,},
};
static int
impl_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
{
struct impl *this;
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (index < 0 || index >= SPA_N_ELEMENTS(impl_interfaces))
return SPA_RESULT_ENUM_END;
this = (struct impl *) handle;
*info = &impl_interfaces[index];
if (interface_id == this->type.monitor.Monitor)
*interface = &this->monitor;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
static int
impl_clear (struct spa_handle *handle)
{
return SPA_RESULT_OK;
}
static int
impl_init (const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
struct impl *this;
uint32_t i;
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear,
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
this->main_loop = support[i].data;
}
if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
if (this->main_loop == NULL) {
spa_log_error (this->log, "a main-loop is needed");
return SPA_RESULT_ERROR;
}
init_type (&this->type, this->map);
this->monitor = impl_monitor;
return SPA_RESULT_OK;
}
static const struct spa_interface_info impl_interfaces[] =
{
{ SPA_TYPE__Monitor, },
};
static int
impl_enum_interface_info (const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
{
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (index < 0 || index >= SPA_N_ELEMENTS (impl_interfaces))
return SPA_RESULT_ENUM_END;
*info = &impl_interfaces[index];
return SPA_RESULT_OK;
}
const struct spa_handle_factory spa_v4l2_monitor_factory =
{ NAME,
NULL,
sizeof (struct impl),
impl_init,
impl_enum_interface_info,
const struct spa_handle_factory spa_v4l2_monitor_factory = {
NAME,
NULL,
sizeof(struct impl),
impl_init,
impl_enum_interface_info,
};

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -23,11 +23,9 @@
extern const struct spa_handle_factory spa_videotestsrc_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
{
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:

File diff suppressed because it is too large Load diff

View file

@ -22,12 +22,9 @@
extern const struct spa_handle_factory spa_volume_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
{
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:

File diff suppressed because it is too large Load diff

View file

@ -1,10 +0,0 @@
xv_sources = ['xv.c',
'xv-sink.c']
xvlib = shared_library('spa-xv',
xv_sources,
include_directories : [spa_inc, spa_libinc],
dependencies : xv_dep,
link_with : spalib,
install : true,
install_dir : '@0@/spa'.format(get_option('libdir')))

View file

@ -1,605 +0,0 @@
/* Spa Xv Sink
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <spa/type-map.h>
#include <spa/log.h>
#include <spa/list.h>
#include <spa/node.h>
#include <spa/video/format-utils.h>
#include <lib/props.h>
static const char default_device[] = "/dev/video0";
struct props {
char device[64];
char device_name[128];
int device_fd;
};
static void
reset_props (struct props *props)
{
strncpy (props->device, default_device, 64);
}
#define MAX_BUFFERS 32
struct buffer {
struct spa_buffer buffer;
struct spa_meta meta[1];
struct spa_meta_header header;
struct spa_data data[1];
struct spa_list link;
bool outstanding;
};
struct port {
bool opened;
int fd;
struct spa_port_io *io;
bool have_format;
uint8_t format_buffer[1024];
struct spa_video_info current_format;
struct spa_port_info info;
struct buffer buffers[MAX_BUFFERS];
struct spa_list ready;
};
struct type {
uint32_t node;
uint32_t props;
uint32_t prop_device;
uint32_t prop_device_name;
uint32_t prop_device_fd;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_command_node command_node;
};
static inline void
init_type (struct type *type, struct spa_type_map *map)
{
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
type->props = spa_type_map_get_id (map, SPA_TYPE__Props);
type->prop_device = spa_type_map_get_id (map, SPA_TYPE_PROPS__device);
type->prop_device_name = spa_type_map_get_id (map, SPA_TYPE_PROPS__deviceName);
type->prop_device_fd = spa_type_map_get_id (map, SPA_TYPE_PROPS__deviceFd);
spa_type_media_type_map (map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype);
spa_type_format_video_map (map, &type->format_video);
spa_type_command_node_map (map, &type->command_node);
}
struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
uint8_t props_buffer[512];
struct props props;
struct spa_node_callbacks callbacks;
void *user_data;
struct port in_ports[1];
};
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) == 0)
#include "xv-utils.c"
#define PROP(f,key,type,...) \
SPA_POD_PROP (f,key,0,type,1,__VA_ARGS__)
#define PROP_R(f,key,type,...) \
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_READONLY,type,1,__VA_ARGS__)
static int
spa_xv_sink_node_get_props (struct spa_node *node,
struct spa_props **props)
{
struct impl *this;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2];
if (node == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0], this->type.props,
PROP (&f[1], this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP_R (&f[1], this->type.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP_R (&f[1], this->type.prop_device_fd, SPA_POD_TYPE_INT, this->props.device_fd));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_props);
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_set_props (struct spa_node *node,
const struct spa_props *props)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (props == NULL) {
reset_props (&this->props);
} else {
spa_props_query (props,
this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
0);
}
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_send_command (struct spa_node *node,
struct spa_command *command)
{
struct impl *this;
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
spa_xv_start (this);
}
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
spa_xv_stop (this);
}
else
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_set_callbacks (struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size,
void *user_data)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this->callbacks = *callbacks;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_get_n_ports (struct spa_node *node,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 0;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 0;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_get_port_ids (struct spa_node *node,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_remove_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_enum_formats (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_format **format,
const struct spa_format *filter,
uint32_t index)
{
//struct impl *this;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
//this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
switch (index) {
case 0:
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = NULL;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_set_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
const struct spa_format *format)
{
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
if (format == NULL) {
port->have_format = false;
return SPA_RESULT_OK;
} else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE (format),
SPA_FORMAT_MEDIA_SUBTYPE (format), };
if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (spa_xv_set_format (this, &info, flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY) < 0)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
port->current_format = info;
port->have_format = true;
}
}
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_get_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_format **format)
{
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
*format = NULL;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_get_info (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_port_info **info)
{
struct impl *this;
struct port *port;
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
*info = &port->info;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_enum_params (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t index,
struct spa_param **param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_set_param (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_param *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_use_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_alloc_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_set_io (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_port_io *io)
{
struct impl *this;
struct port *port;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
port->io = io;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_send_command (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_command *command)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_process_input (struct spa_node *node)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_process_output (struct spa_node *node)
{
return SPA_RESULT_INVALID_PORT;
}
static const struct spa_node xvsink_node = {
sizeof (struct spa_node),
NULL,
spa_xv_sink_node_get_props,
spa_xv_sink_node_set_props,
spa_xv_sink_node_send_command,
spa_xv_sink_node_set_callbacks,
spa_xv_sink_node_get_n_ports,
spa_xv_sink_node_get_port_ids,
spa_xv_sink_node_add_port,
spa_xv_sink_node_remove_port,
spa_xv_sink_node_port_enum_formats,
spa_xv_sink_node_port_set_format,
spa_xv_sink_node_port_get_format,
spa_xv_sink_node_port_get_info,
spa_xv_sink_node_port_enum_params,
spa_xv_sink_node_port_set_param,
spa_xv_sink_node_port_use_buffers,
spa_xv_sink_node_port_alloc_buffers,
spa_xv_sink_node_port_set_io,
spa_xv_sink_node_port_reuse_buffer,
spa_xv_sink_node_port_send_command,
spa_xv_sink_node_process_input,
spa_xv_sink_node_process_output,
};
static int
spa_xv_sink_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{
struct impl *this;
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (struct impl *) handle;
if (interface_id == this->type.node)
*interface = &this->node;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return SPA_RESULT_OK;
}
static int
xv_sink_clear (struct spa_handle *handle)
{
return SPA_RESULT_OK;
}
static int
xv_sink_init (const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
struct impl *this;
uint32_t i;
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_xv_sink_get_interface;
handle->clear = xv_sink_clear;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
init_type (&this->type, this->map);
this->node = xvsink_node;
reset_props (&this->props);
this->in_ports[0].info.flags = 0;
return SPA_RESULT_OK;
}
static const struct spa_interface_info xv_sink_interfaces[] =
{
{ SPA_TYPE__Node, },
};
static int
xv_sink_enum_interface_info (const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
{
if (factory == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (index) {
case 0:
*info = &xv_sink_interfaces[index];
break;
default:
return SPA_RESULT_ENUM_END;
}
return SPA_RESULT_OK;
}
const struct spa_handle_factory spa_xv_sink_factory =
{
"xv-sink",
NULL,
sizeof (struct impl),
xv_sink_init,
xv_sink_enum_interface_info,
};

View file

@ -1,62 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <poll.h>
#define CLEAR(x) memset(&(x), 0, sizeof(x))
static int
spa_xv_open (struct impl *this)
{
struct port *port = &this->in_ports[0];
if (port->opened)
return 0;
port->opened = true;
return 0;
}
static int
spa_xv_set_format (struct impl *this, struct spa_video_info *info, bool try_only)
{
if (spa_xv_open (this) < 0)
return -1;
return 0;
}
static int
spa_xv_close (struct impl *this)
{
struct port *port = &this->in_ports[0];
if (!port->opened)
return 0;
port->opened = false;
return 0;
}
static int
spa_xv_start (struct impl *this)
{
if (spa_xv_open (this) < 0)
return -1;
return 0;
}
static int
spa_xv_stop (struct impl *this)
{
spa_xv_close (this);
return 0;
}

View file

@ -1,40 +0,0 @@
/* Spa Xv support
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <spa/plugin.h>
#include <spa/node.h>
extern const struct spa_handle_factory spa_xv_sink_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
{
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:
*factory = &spa_xv_sink_factory;
break;
default:
return SPA_RESULT_ENUM_END;
}
return SPA_RESULT_OK;
}