cleanups: doc updates

This commit is contained in:
Wim Taymans 2016-06-03 23:58:34 +02:00
parent 613216613e
commit 82420e483d
8 changed files with 578 additions and 289 deletions

View file

@ -28,8 +28,8 @@ typedef struct _SpiALSASink SpiALSASink;
static const char default_device[] = "default";
static const uint32_t default_buffer_time = 40000;
static const uint32_t default_period_time = 20000;
static const uint32_t default_buffer_time = 10000;
static const uint32_t default_period_time = 5000;
static const bool default_period_event = 0;
typedef struct {
@ -93,9 +93,6 @@ struct _SpiALSASink {
bool activated;
SpiEvent *event;
SpiEvent last_event;
SpiEventCallback event_cb;
void *user_data;
@ -188,6 +185,9 @@ enum_param_info (const SpiParams *params,
unsigned int index,
const SpiParamInfo **info)
{
if (params == NULL || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (index >= PARAM_ID_LAST)
return SPI_RESULT_ENUM_END;
*info = &param_info[index];
@ -204,6 +204,9 @@ set_param (SpiParams *params,
SpiResult res = SPI_RESULT_OK;
SpiALSASinkParams *p = (SpiALSASinkParams *) params;
if (params == NULL || value == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (id) {
case PARAM_ID_DEVICE:
CHECK_TYPE (type, SPI_PARAM_TYPE_STRING);
@ -242,6 +245,9 @@ get_param (const SpiParams *params,
SpiResult res = SPI_RESULT_OK;
SpiALSASinkParams *p = (SpiALSASinkParams *) params;
if (params == NULL || type == NULL || size == NULL || value == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (id) {
case PARAM_ID_DEVICE:
*type = SPI_PARAM_TYPE_STRING;
@ -288,6 +294,9 @@ spi_alsa_sink_node_get_params (SpiNode *node,
static SpiALSASinkParams p;
SpiALSASink *this = (SpiALSASink *) node;
if (node == NULL || params == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
memcpy (&p, &this->params, sizeof (p));
*params = &p.param;
@ -304,6 +313,9 @@ spi_alsa_sink_node_set_params (SpiNode *node,
size_t size;
const void *value;
if (node == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (params == NULL) {
reset_alsa_sink_params (p);
return SPI_RESULT_OK;
@ -337,64 +349,61 @@ spi_alsa_sink_node_send_command (SpiNode *node,
SpiCommand *command)
{
SpiALSASink *this = (SpiALSASink *) node;
SpiResult res = SPI_RESULT_NOT_IMPLEMENTED;
if (node == NULL || command == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (command->type) {
case SPI_COMMAND_INVALID:
res = SPI_RESULT_INVALID_COMMAND;
break;
return SPI_RESULT_INVALID_COMMAND;
case SPI_COMMAND_ACTIVATE:
if (!this->activated) {
spi_alsa_open (this);
this->activated = true;
}
this->last_event.type = SPI_EVENT_TYPE_ACTIVATED;
this->last_event.data = NULL;
this->last_event.size = 0;
this->event = &this->last_event;
res = SPI_RESULT_HAVE_EVENT;
if (this->event_cb) {
SpiEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPI_EVENT_TYPE_ACTIVATED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (node, &event, this->user_data);
}
break;
case SPI_COMMAND_DEACTIVATE:
if (this->activated) {
spi_alsa_close (this);
this->activated = false;
}
this->last_event.type = SPI_EVENT_TYPE_DEACTIVATED;
this->last_event.data = NULL;
this->last_event.size = 0;
this->event = &this->last_event;
res = SPI_RESULT_HAVE_EVENT;
if (this->event_cb) {
SpiEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPI_EVENT_TYPE_DEACTIVATED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (node, &event, this->user_data);
}
break;
case SPI_COMMAND_START:
spi_alsa_start (this);
res = SPI_RESULT_OK;
break;
case SPI_COMMAND_STOP:
spi_alsa_stop (this);
res = SPI_RESULT_OK;
break;
case SPI_COMMAND_FLUSH:
break;
case SPI_COMMAND_DRAIN:
break;
case SPI_COMMAND_MARKER:
break;
return SPI_RESULT_NOT_IMPLEMENTED;
}
return res;
}
static SpiResult
spi_alsa_sink_node_get_event (SpiNode *node,
SpiEvent **event)
{
SpiALSASink *this = (SpiALSASink *) node;
if (this->event == NULL)
return SPI_RESULT_ERROR;
*event = this->event;
this->event = NULL;
return SPI_RESULT_OK;
}
@ -405,6 +414,9 @@ spi_alsa_sink_node_set_event_callback (SpiNode *node,
{
SpiALSASink *this = (SpiALSASink *) node;
if (node == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
this->event_cb = event;
this->user_data = user_data;
@ -418,10 +430,18 @@ spi_alsa_sink_node_get_n_ports (SpiNode *node,
unsigned int *n_output_ports,
unsigned int *max_output_ports)
{
*n_input_ports = 1;
*n_output_ports = 0;
*max_input_ports = 1;
*max_output_ports = 0;
if (node == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 0;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 0;
return SPI_RESULT_OK;
}
@ -432,6 +452,9 @@ spi_alsa_sink_node_get_port_ids (SpiNode *node,
unsigned int n_output_ports,
uint32_t *output_ids)
{
if (node == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0)
input_ids[0] = 0;
@ -545,6 +568,9 @@ enum_raw_format_param_info (const SpiParams *params,
unsigned int index,
const SpiParamInfo **info)
{
if (params == NULL || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (index >= 5)
return SPI_RESULT_ENUM_END;
*info = &raw_format_param_info[index];
@ -599,6 +625,9 @@ enum_mpeg_format_param_info (const SpiParams *params,
unsigned int index,
const SpiParamInfo **info)
{
if (params == NULL || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (index >= 4)
return SPI_RESULT_ENUM_END;
*info = &mpeg_format_param_info[index];
@ -618,6 +647,9 @@ set_format_param (SpiParams *params,
{
SpiALSASinkFormat *f = (SpiALSASinkFormat *) params;
if (params == NULL || value == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (id) {
case SPI_PARAM_ID_FORMAT:
CHECK_TYPE (type, SPI_PARAM_TYPE_STRING);
@ -665,6 +697,9 @@ get_format_param (const SpiParams *params,
{
SpiALSASinkFormat *f = (SpiALSASinkFormat *) params;
if (params == NULL || type == NULL || size == NULL || value == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (id) {
case SPI_PARAM_ID_MEDIA_TYPE:
CHECK_UNSET (f->unset_mask, 0);
@ -722,13 +757,16 @@ get_format_param (const SpiParams *params,
static SpiResult
spi_alsa_sink_node_enum_port_formats (SpiNode *node,
spi_alsa_sink_node_enum_port_formats (SpiNode *node,
uint32_t port_id,
unsigned int index,
SpiParams **format)
{
static SpiALSASinkFormat fmt;
if (node == NULL || format == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPI_RESULT_INVALID_PORT;
@ -767,11 +805,16 @@ spi_alsa_sink_node_set_port_format (SpiNode *node,
SpiParamType type;
size_t size;
const void *value;
SpiALSASinkFormat *fmt = &this->current_format;
SpiALSASinkFormat *fmt;
if (node == NULL || format == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPI_RESULT_INVALID_PORT;
fmt = &this->current_format;
if (format == NULL) {
fmt->param.get_param = NULL;
this->have_format = 0;
@ -834,6 +877,9 @@ spi_alsa_sink_node_get_port_format (SpiNode *node,
{
SpiALSASink *this = (SpiALSASink *) node;
if (node == NULL || format == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPI_RESULT_INVALID_PORT;
@ -850,6 +896,9 @@ spi_alsa_sink_node_get_port_info (SpiNode *node,
uint32_t port_id,
SpiPortInfo *info)
{
if (node == NULL || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPI_RESULT_INVALID_PORT;
@ -879,6 +928,9 @@ spi_alsa_sink_node_get_port_status (SpiNode *node,
uint32_t port_id,
SpiPortStatus *status)
{
if (node == NULL || status == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPI_RESULT_INVALID_PORT;
@ -888,34 +940,74 @@ spi_alsa_sink_node_get_port_status (SpiNode *node,
}
static SpiResult
spi_alsa_sink_node_send_port_data (SpiNode *node,
SpiDataInfo *data)
spi_alsa_sink_node_push_port_input (SpiNode *node,
unsigned int n_info,
SpiInputInfo *info)
{
SpiALSASink *this = (SpiALSASink *) node;
unsigned int i;
bool have_error = false, have_enough = false;
if (data->port_id != 0)
return SPI_RESULT_INVALID_PORT;
if (node == NULL || n_info == 0 || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (data->buffer != NULL) {
if (!this->have_format)
return SPI_RESULT_NO_FORMAT;
for (i = 0; i < n_info; i++) {
if (info[i].port_id != 0) {
info[i].status = SPI_RESULT_INVALID_PORT;
have_error = true;
continue;
}
if (this->input_buffer != NULL)
return SPI_RESULT_HAVE_ENOUGH_INPUT;
if (info[i].buffer != NULL) {
if (!this->have_format) {
info[i].status = SPI_RESULT_NO_FORMAT;
have_error = true;
continue;
}
this->input_buffer = spi_buffer_ref (data->buffer);
if (this->input_buffer != NULL) {
info[i].status = SPI_RESULT_HAVE_ENOUGH_INPUT;
have_enough = true;
continue;
}
this->input_buffer = spi_buffer_ref (info[i].buffer);
}
info[i].status = SPI_RESULT_OK;
}
if (have_error)
return SPI_RESULT_ERROR;
if (have_enough)
return SPI_RESULT_HAVE_ENOUGH_INPUT;
return SPI_RESULT_OK;
}
static SpiResult
spi_alsa_sink_node_receive_port_data (SpiNode *node,
unsigned int n_data,
SpiDataInfo *data)
spi_alsa_sink_node_pull_port_output (SpiNode *node,
unsigned int n_info,
SpiOutputInfo *info)
{
return SPI_RESULT_INVALID_PORT;
}
static SpiResult
spi_alsa_sink_node_enum_interface_info (SpiNode *node,
unsigned int index,
const SpiInterfaceInfo **info)
{
return SPI_RESULT_NOT_IMPLEMENTED;
}
static SpiResult
spi_alsa_sink_node_get_interface (SpiNode *node,
uint32_t interface_id,
void **interface)
{
return SPI_RESULT_NOT_IMPLEMENTED;
}
SpiNode *
spi_alsa_sink_new (void)
{
@ -927,7 +1019,6 @@ spi_alsa_sink_new (void)
node->get_params = spi_alsa_sink_node_get_params;
node->set_params = spi_alsa_sink_node_set_params;
node->send_command = spi_alsa_sink_node_send_command;
node->get_event = spi_alsa_sink_node_get_event;
node->set_event_callback = spi_alsa_sink_node_set_event_callback;
node->get_n_ports = spi_alsa_sink_node_get_n_ports;
node->get_port_ids = spi_alsa_sink_node_get_port_ids;
@ -940,8 +1031,10 @@ spi_alsa_sink_new (void)
node->get_port_params = spi_alsa_sink_node_get_port_params;
node->set_port_params = spi_alsa_sink_node_set_port_params;
node->get_port_status = spi_alsa_sink_node_get_port_status;
node->send_port_data = spi_alsa_sink_node_send_port_data;
node->receive_port_data = spi_alsa_sink_node_receive_port_data;
node->push_port_input = spi_alsa_sink_node_push_port_input;
node->pull_port_output = spi_alsa_sink_node_pull_port_output;
node->enum_interface_info = spi_alsa_sink_node_enum_interface_info;
node->get_interface = spi_alsa_sink_node_get_interface;
this = (SpiALSASink *) node;
this->params.param.enum_param_info = enum_param_info;