2015-06-30 18:06:36 +02:00
|
|
|
/* Pinos
|
2015-04-16 16:58:33 +02:00
|
|
|
* Copyright (C) 2015 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
#include <unistd.h>
|
2016-05-09 18:48:18 +02:00
|
|
|
#include <sys/socket.h>
|
2015-05-14 17:46:12 +02:00
|
|
|
#include <string.h>
|
2016-08-03 15:59:17 +02:00
|
|
|
#include <sys/mman.h>
|
2016-09-29 18:18:59 +02:00
|
|
|
#include <errno.h>
|
2016-05-09 18:48:18 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
#include "spa/lib/debug.h"
|
2016-08-05 16:39:26 +02:00
|
|
|
|
2016-02-01 15:40:48 +01:00
|
|
|
#include "pinos/client/pinos.h"
|
2016-11-16 16:57:47 +01:00
|
|
|
#include "pinos/client/array.h"
|
2016-10-17 18:29:05 +02:00
|
|
|
#include "pinos/client/connection.h"
|
2016-02-01 15:40:48 +01:00
|
|
|
#include "pinos/client/context.h"
|
|
|
|
|
#include "pinos/client/stream.h"
|
2016-08-05 16:39:26 +02:00
|
|
|
#include "pinos/client/format.h"
|
2016-10-17 12:20:49 +02:00
|
|
|
#include "pinos/client/serialize.h"
|
2016-11-07 10:24:13 +01:00
|
|
|
#include "pinos/client/transport.h"
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
#define MAX_BUFFER_SIZE 4096
|
2016-08-25 17:07:40 +02:00
|
|
|
#define MAX_FDS 32
|
2016-09-22 08:55:30 +02:00
|
|
|
#define MAX_INPUTS 64
|
|
|
|
|
#define MAX_OUTPUTS 64
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-07-28 21:19:20 +02:00
|
|
|
typedef struct {
|
2016-09-29 18:18:59 +02:00
|
|
|
uint32_t id;
|
|
|
|
|
int fd;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
void *ptr;
|
|
|
|
|
size_t size;
|
|
|
|
|
} MemId;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2016-07-28 21:19:20 +02:00
|
|
|
uint32_t id;
|
2016-08-24 16:26:58 +02:00
|
|
|
bool used;
|
2016-10-03 19:43:42 +02:00
|
|
|
void *buf_ptr;
|
2016-07-28 21:19:20 +02:00
|
|
|
SpaBuffer *buf;
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaData *datas;
|
2016-07-28 21:19:20 +02:00
|
|
|
} BufferId;
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
typedef struct
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStream this;
|
2015-05-27 18:16:52 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
SpaNodeState node_state;
|
2015-06-04 16:34:47 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
uint32_t seq;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
unsigned int n_possible_formats;
|
|
|
|
|
SpaFormat **possible_formats;
|
2015-05-27 18:16:52 +02:00
|
|
|
|
2016-08-05 16:39:26 +02:00
|
|
|
SpaFormat *format;
|
2016-08-05 19:46:37 +02:00
|
|
|
SpaPortInfo port_info;
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction;
|
2016-09-22 08:55:30 +02:00
|
|
|
uint32_t port_id;
|
|
|
|
|
uint32_t pending_seq;
|
2016-08-05 16:39:26 +02:00
|
|
|
|
|
|
|
|
PinosStreamFlags flags;
|
2015-05-27 18:16:52 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
bool disconnecting;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamMode mode;
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-10-14 19:23:05 +02:00
|
|
|
int rtfd;
|
2016-11-24 17:00:42 +01:00
|
|
|
SpaSource *rtsocket_source;
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosProxy *node_proxy;
|
2016-11-07 10:24:13 +01:00
|
|
|
PinosTransport *trans;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
SpaSource *timeout_source;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
PinosArray mem_ids;
|
|
|
|
|
PinosArray buffer_ids;
|
2016-11-24 17:00:42 +01:00
|
|
|
bool in_order;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
int64_t last_ticks;
|
|
|
|
|
int32_t last_rate;
|
|
|
|
|
int64_t last_monotonic;
|
|
|
|
|
} PinosStreamImpl;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-09-22 08:55:30 +02:00
|
|
|
static void
|
|
|
|
|
clear_buffers (PinosStream *stream)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
BufferId *bid;
|
2016-09-22 08:55:30 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_array_for_each (bid, &impl->buffer_ids) {
|
|
|
|
|
pinos_signal_emit (&stream->remove_buffer, stream, bid->id);
|
2016-09-22 08:55:30 +02:00
|
|
|
bid->buf = NULL;
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->buffer_ids.size = 0;
|
|
|
|
|
impl->in_order = true;
|
2015-06-12 12:10:27 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-04 16:34:47 +02:00
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (PinosStream *stream,
|
2015-08-26 17:11:10 +02:00
|
|
|
PinosStreamState state,
|
2016-11-24 17:00:42 +01:00
|
|
|
char *error)
|
2016-09-16 13:13:41 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
if (stream->state != state) {
|
|
|
|
|
if (stream->error)
|
|
|
|
|
free (stream->error);
|
|
|
|
|
stream->error = error;
|
|
|
|
|
stream->state = state;
|
|
|
|
|
pinos_signal_emit (&stream->state_changed, stream);
|
2016-09-16 13:13:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-30 10:50:45 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_stream_state_as_string:
|
|
|
|
|
* @state: a #PinosStreamState
|
|
|
|
|
*
|
|
|
|
|
* Return the string representation of @state.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the string representation of @state.
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
const char *
|
2015-09-30 10:50:45 +02:00
|
|
|
pinos_stream_state_as_string (PinosStreamState state)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
switch (state) {
|
|
|
|
|
case PINOS_STREAM_STATE_ERROR:
|
|
|
|
|
return "error";
|
|
|
|
|
case PINOS_STREAM_STATE_UNCONNECTED:
|
|
|
|
|
return "unconnected";
|
|
|
|
|
case PINOS_STREAM_STATE_CONNECTING:
|
|
|
|
|
return "connecting";
|
|
|
|
|
case PINOS_STREAM_STATE_CONFIGURE:
|
|
|
|
|
return "configure";
|
|
|
|
|
case PINOS_STREAM_STATE_READY:
|
|
|
|
|
return "ready";
|
|
|
|
|
case PINOS_STREAM_STATE_PAUSED:
|
|
|
|
|
return "paused";
|
|
|
|
|
case PINOS_STREAM_STATE_STREAMING:
|
|
|
|
|
return "streaming";
|
|
|
|
|
}
|
|
|
|
|
return "invalid-state";
|
2015-09-30 10:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_new:
|
|
|
|
|
* @context: a #PinosContext
|
2015-04-16 16:58:33 +02:00
|
|
|
* @name: a stream name
|
2015-08-26 15:44:29 +02:00
|
|
|
* @properties: (transfer full): stream properties
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* Make a new unconnected #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* Returns: a new unconnected #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*/
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *
|
2015-07-17 16:57:01 +02:00
|
|
|
pinos_stream_new (PinosContext *context,
|
2016-11-24 17:00:42 +01:00
|
|
|
const char *name,
|
2015-07-17 16:57:01 +02:00
|
|
|
PinosProperties *props)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl;
|
|
|
|
|
PinosStream *this;
|
|
|
|
|
|
|
|
|
|
impl = calloc (1, sizeof (PinosStreamImpl));
|
|
|
|
|
this = &impl->this;
|
|
|
|
|
pinos_log_debug ("stream %p: new", impl);
|
2015-08-26 15:44:29 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
this->context = context;
|
|
|
|
|
this->name = strdup (name);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
if (props == NULL) {
|
|
|
|
|
props = pinos_properties_new ("media.name", name, NULL);
|
|
|
|
|
} else if (!pinos_properties_get (props, "media.name")) {
|
|
|
|
|
pinos_properties_set (props, "media.name", name);
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
this->properties = props;
|
2015-07-28 17:05:03 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_signal_init (&this->destroy_signal);
|
|
|
|
|
pinos_signal_init (&this->state_changed);
|
|
|
|
|
pinos_signal_init (&this->format_changed);
|
|
|
|
|
pinos_signal_init (&this->add_buffer);
|
|
|
|
|
pinos_signal_init (&this->remove_buffer);
|
|
|
|
|
pinos_signal_init (&this->new_buffer);
|
2015-08-26 15:44:29 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
this->state = PINOS_STREAM_STATE_UNCONNECTED;
|
2015-08-26 15:44:29 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->node_state = SPA_NODE_STATE_INIT;
|
|
|
|
|
pinos_array_init (&impl->mem_ids);
|
|
|
|
|
pinos_array_ensure_size (&impl->mem_ids, sizeof (MemId) * 64);
|
|
|
|
|
pinos_array_init (&impl->buffer_ids);
|
|
|
|
|
pinos_array_ensure_size (&impl->buffer_ids, sizeof (BufferId) * 64);
|
|
|
|
|
impl->pending_seq = SPA_ID_INVALID;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
spa_list_insert (&context->stream_list, &this->link);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
return this;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
void
|
|
|
|
|
pinos_stream_destroy (PinosStream *stream)
|
2015-04-29 17:51:51 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
|
|
|
|
|
pinos_log_debug ("stream %p: destroy", stream);
|
|
|
|
|
|
|
|
|
|
pinos_signal_emit (&stream->destroy_signal, stream);
|
|
|
|
|
|
|
|
|
|
spa_list_remove (&stream->link);
|
|
|
|
|
|
|
|
|
|
if (impl->format)
|
|
|
|
|
free (impl->format);
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (stream->error)
|
|
|
|
|
free (stream->error);
|
|
|
|
|
|
|
|
|
|
pinos_array_clear (&impl->buffer_ids);
|
|
|
|
|
pinos_array_clear (&impl->mem_ids);
|
|
|
|
|
|
|
|
|
|
if (stream->properties)
|
|
|
|
|
pinos_properties_free (stream->properties);
|
|
|
|
|
|
|
|
|
|
if (stream->name)
|
|
|
|
|
free (stream->name);
|
|
|
|
|
|
|
|
|
|
free (impl);
|
2015-04-29 17:51:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-05 19:46:37 +02:00
|
|
|
static void
|
2016-11-24 17:00:42 +01:00
|
|
|
add_node_update (PinosStream *stream, uint32_t change_mask, bool flush)
|
2016-08-24 16:26:58 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
PinosMessageNodeUpdate nu = { 0, };
|
2016-08-24 16:26:58 +02:00
|
|
|
|
|
|
|
|
nu.change_mask = change_mask;
|
2016-11-03 19:41:53 +01:00
|
|
|
if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS)
|
2016-11-24 17:00:42 +01:00
|
|
|
nu.max_input_ports = impl->direction == SPA_DIRECTION_INPUT ? 1 : 0;
|
2016-11-03 19:41:53 +01:00
|
|
|
if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS)
|
2016-11-24 17:00:42 +01:00
|
|
|
nu.max_output_ports = impl->direction == SPA_DIRECTION_OUTPUT ? 1 : 0;
|
2016-08-24 16:26:58 +02:00
|
|
|
nu.props = NULL;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
|
|
|
|
pinos_proxy_send_message (impl->node_proxy,
|
|
|
|
|
PINOS_MESSAGE_NODE_UPDATE,
|
|
|
|
|
&nu,
|
|
|
|
|
flush);
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-22 08:55:30 +02:00
|
|
|
static void
|
2016-11-24 17:00:42 +01:00
|
|
|
add_state_change (PinosStream *stream, SpaNodeState state, bool flush)
|
2016-09-22 08:55:30 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
PinosMessageNodeStateChange sc;
|
2016-09-22 08:55:30 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (impl->node_state != state) {
|
|
|
|
|
sc.state = impl->node_state = state;
|
|
|
|
|
pinos_proxy_send_message (impl->node_proxy,
|
|
|
|
|
PINOS_MESSAGE_NODE_STATE_CHANGE,
|
|
|
|
|
&sc,
|
|
|
|
|
flush);
|
2016-09-26 12:15:52 +02:00
|
|
|
}
|
2016-09-22 08:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
static void
|
2016-11-24 17:00:42 +01:00
|
|
|
add_port_update (PinosStream *stream, uint32_t change_mask, bool flush)
|
2016-08-24 16:26:58 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
PinosMessagePortUpdate pu = { 0, };;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pu.direction = impl->direction;
|
|
|
|
|
pu.port_id = impl->port_id;
|
2016-08-24 16:26:58 +02:00
|
|
|
pu.change_mask = change_mask;
|
2016-11-03 19:41:53 +01:00
|
|
|
if (change_mask & PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS) {
|
2016-11-24 17:00:42 +01:00
|
|
|
pu.n_possible_formats = impl->n_possible_formats;
|
|
|
|
|
pu.possible_formats = impl->possible_formats;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
2016-11-03 19:41:53 +01:00
|
|
|
if (change_mask & PINOS_MESSAGE_PORT_UPDATE_FORMAT) {
|
2016-11-24 17:00:42 +01:00
|
|
|
pu.format = impl->format;
|
2016-09-22 08:55:30 +02:00
|
|
|
}
|
2016-08-24 16:26:58 +02:00
|
|
|
pu.props = NULL;
|
2016-11-03 19:41:53 +01:00
|
|
|
if (change_mask & PINOS_MESSAGE_PORT_UPDATE_INFO) {
|
2016-11-24 17:00:42 +01:00
|
|
|
pu.info = &impl->port_info;
|
2016-10-03 19:43:42 +02:00
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_proxy_send_message (impl->node_proxy,
|
|
|
|
|
PINOS_MESSAGE_PORT_UPDATE,
|
|
|
|
|
&pu,
|
|
|
|
|
flush);
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-07 10:24:13 +01:00
|
|
|
static inline void
|
|
|
|
|
send_need_input (PinosStream *stream)
|
2016-08-24 16:26:58 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-07 18:23:09 +01:00
|
|
|
uint8_t cmd = PINOS_TRANSPORT_CMD_NEED_DATA;
|
2016-11-24 17:00:42 +01:00
|
|
|
write (impl->rtfd, &cmd, 1);
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-12 12:28:51 +02:00
|
|
|
static void
|
2016-11-24 17:00:42 +01:00
|
|
|
add_request_clock_update (PinosStream *stream, bool flush)
|
2016-09-12 12:28:51 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
PinosMessageNodeEvent cne;
|
2016-09-12 12:28:51 +02:00
|
|
|
SpaNodeEventRequestClockUpdate rcu;
|
|
|
|
|
|
2016-10-24 15:30:15 +02:00
|
|
|
cne.event = &rcu.event;
|
|
|
|
|
rcu.event.type = SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE;
|
|
|
|
|
rcu.event.size = sizeof (rcu);
|
2016-09-12 12:28:51 +02:00
|
|
|
rcu.update_mask = SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME;
|
|
|
|
|
rcu.timestamp = 0;
|
|
|
|
|
rcu.offset = 0;
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_proxy_send_message (impl->node_proxy,
|
|
|
|
|
PINOS_MESSAGE_NODE_EVENT,
|
|
|
|
|
&cne,
|
|
|
|
|
flush);
|
2016-09-12 12:28:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-22 08:55:30 +02:00
|
|
|
static void
|
2016-11-24 17:00:42 +01:00
|
|
|
add_async_complete (PinosStream *stream,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
SpaResult res,
|
|
|
|
|
bool flush)
|
2016-09-22 08:55:30 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
PinosMessageNodeEvent cne;
|
2016-09-22 08:55:30 +02:00
|
|
|
SpaNodeEventAsyncComplete ac;
|
|
|
|
|
|
2016-10-24 15:30:15 +02:00
|
|
|
cne.event = &ac.event;
|
|
|
|
|
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
|
|
|
|
|
ac.event.size = sizeof (ac);
|
2016-09-22 08:55:30 +02:00
|
|
|
ac.seq = seq;
|
|
|
|
|
ac.res = res;
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_proxy_send_message (impl->node_proxy,
|
|
|
|
|
PINOS_MESSAGE_NODE_EVENT,
|
|
|
|
|
&cne,
|
|
|
|
|
flush);
|
2016-09-22 08:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
do_node_init (PinosStream *stream)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-09-22 08:55:30 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
add_node_update (stream, PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS |
|
2016-11-24 17:00:42 +01:00
|
|
|
PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS,
|
|
|
|
|
false);
|
2016-09-22 08:55:30 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->port_info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
2016-11-03 19:41:53 +01:00
|
|
|
add_port_update (stream, PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS |
|
2016-11-24 17:00:42 +01:00
|
|
|
PINOS_MESSAGE_PORT_UPDATE_INFO,
|
|
|
|
|
false);
|
|
|
|
|
add_state_change (stream, SPA_NODE_STATE_CONFIGURE, true);
|
|
|
|
|
}
|
2016-09-22 08:55:30 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
static void
|
|
|
|
|
on_timeout (SpaSource *source,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
PinosStream *stream = data;
|
2016-09-22 08:55:30 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
add_request_clock_update (stream, true);
|
2016-09-22 08:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-29 18:18:59 +02:00
|
|
|
static MemId *
|
|
|
|
|
find_mem (PinosStream *stream, uint32_t id)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
MemId *mid;
|
2016-09-29 18:18:59 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_array_for_each (mid, &impl->mem_ids) {
|
2016-09-29 18:18:59 +02:00
|
|
|
if (mid->id == id)
|
|
|
|
|
return mid;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 21:19:20 +02:00
|
|
|
static BufferId *
|
|
|
|
|
find_buffer (PinosStream *stream, uint32_t id)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (impl->in_order && pinos_array_check_index (&impl->buffer_ids, id, BufferId)) {
|
|
|
|
|
return pinos_array_get_unchecked (&impl->buffer_ids, id, BufferId);
|
2016-08-24 16:26:58 +02:00
|
|
|
} else {
|
2016-11-03 19:41:53 +01:00
|
|
|
BufferId *bid;
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_array_for_each (bid, &impl->buffer_ids) {
|
2016-08-24 16:26:58 +02:00
|
|
|
if (bid->id == id)
|
|
|
|
|
return bid;
|
|
|
|
|
}
|
2016-07-28 21:19:20 +02:00
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
static void
|
|
|
|
|
handle_rtnode_event (PinosStream *stream,
|
|
|
|
|
SpaNodeEvent *event)
|
|
|
|
|
{
|
|
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_INVALID:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_ERROR:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_BUFFERING:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
|
|
|
|
|
pinos_log_warn ("unexpected node event %d", event->type);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
|
|
|
|
|
pinos_log_warn ("unhandled node event %d", event->type);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
|
|
|
|
|
{
|
|
|
|
|
SpaNodeEventReuseBuffer *p = (SpaNodeEventReuseBuffer *) event;
|
|
|
|
|
BufferId *bid;
|
|
|
|
|
|
|
|
|
|
if (p->port_id != impl->port_id)
|
|
|
|
|
break;
|
|
|
|
|
if (impl->direction != SPA_DIRECTION_OUTPUT)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if ((bid = find_buffer (stream, p->buffer_id))) {
|
|
|
|
|
bid->used = FALSE;
|
|
|
|
|
pinos_signal_emit (&stream->new_buffer, stream, p->buffer_id);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_rtsocket_condition (SpaSource *source,
|
|
|
|
|
int fd,
|
|
|
|
|
SpaIO mask,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
PinosStream *stream = data;
|
|
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
|
|
|
|
|
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
|
|
|
|
|
pinos_log_warn ("got error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mask & SPA_IO_IN) {
|
|
|
|
|
uint8_t cmd;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
read (impl->rtfd, &cmd, 1);
|
|
|
|
|
|
|
|
|
|
if (cmd & PINOS_TRANSPORT_CMD_HAVE_DATA) {
|
|
|
|
|
BufferId *bid;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < impl->trans->area->n_inputs; i++) {
|
|
|
|
|
SpaPortInput *input = &impl->trans->inputs[i];
|
|
|
|
|
|
|
|
|
|
if (input->buffer_id == SPA_ID_INVALID)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if ((bid = find_buffer (stream, input->buffer_id))) {
|
|
|
|
|
for (i = 0; i < bid->buf->n_datas; i++) {
|
|
|
|
|
bid->buf->datas[i].size = bid->datas[i].size;
|
|
|
|
|
}
|
|
|
|
|
pinos_signal_emit (&stream->new_buffer, stream, bid->id);
|
|
|
|
|
}
|
|
|
|
|
input->buffer_id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
send_need_input (stream);
|
|
|
|
|
}
|
|
|
|
|
if (cmd & PINOS_TRANSPORT_CMD_HAVE_EVENT) {
|
|
|
|
|
SpaNodeEvent event;
|
|
|
|
|
while (pinos_transport_next_event (impl->trans, &event) == SPA_RESULT_OK) {
|
|
|
|
|
SpaNodeEvent *ev = alloca (event.size);
|
|
|
|
|
pinos_transport_parse_event (impl->trans, ev);
|
|
|
|
|
handle_rtnode_event (stream, ev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_socket (PinosStream *stream, gint rtfd)
|
|
|
|
|
{
|
|
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
struct timespec interval;
|
|
|
|
|
|
|
|
|
|
impl->rtfd = rtfd;
|
|
|
|
|
impl->rtsocket_source = pinos_loop_add_io (stream->context->loop,
|
|
|
|
|
impl->rtfd,
|
|
|
|
|
SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP,
|
|
|
|
|
false,
|
|
|
|
|
on_rtsocket_condition,
|
|
|
|
|
stream);
|
|
|
|
|
pinos_log_debug ("socket %d", impl->rtfd);
|
|
|
|
|
|
|
|
|
|
impl->timeout_source = pinos_loop_add_timer (stream->context->loop,
|
|
|
|
|
on_timeout,
|
|
|
|
|
stream);
|
|
|
|
|
interval.tv_sec = 0;
|
|
|
|
|
interval.tv_nsec = 100000000;
|
|
|
|
|
pinos_loop_update_timer (stream->context->loop,
|
|
|
|
|
impl->timeout_source,
|
|
|
|
|
NULL,
|
|
|
|
|
&interval,
|
|
|
|
|
false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
unhandle_socket (PinosStream *stream)
|
|
|
|
|
{
|
|
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
|
|
|
|
|
if (impl->rtsocket_source) {
|
|
|
|
|
pinos_loop_destroy_source (stream->context->loop, impl->rtsocket_source);
|
|
|
|
|
impl->rtsocket_source = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-09-09 16:05:58 +02:00
|
|
|
handle_node_event (PinosStream *stream,
|
|
|
|
|
SpaNodeEvent *event)
|
2016-10-14 19:23:05 +02:00
|
|
|
{
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_INVALID:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_ERROR:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_BUFFERING:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
|
|
|
|
|
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_warn ("unhandled node event %d", event->type);
|
2016-10-14 19:23:05 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 16:05:58 +02:00
|
|
|
static gboolean
|
|
|
|
|
handle_node_command (PinosStream *stream,
|
2016-09-22 08:55:30 +02:00
|
|
|
uint32_t seq,
|
2016-09-09 16:05:58 +02:00
|
|
|
SpaNodeCommand *command)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-09-09 16:05:58 +02:00
|
|
|
|
|
|
|
|
switch (command->type) {
|
|
|
|
|
case SPA_NODE_COMMAND_INVALID:
|
|
|
|
|
break;
|
|
|
|
|
case SPA_NODE_COMMAND_PAUSE:
|
|
|
|
|
{
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("stream %p: pause %d", stream, seq);
|
2016-09-09 16:05:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
add_state_change (stream, SPA_NODE_STATE_PAUSED, false);
|
|
|
|
|
add_async_complete (stream, seq, SPA_RESULT_OK, true);
|
2016-10-28 16:56:33 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL);
|
2016-09-09 16:05:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SPA_NODE_COMMAND_START:
|
|
|
|
|
{
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("stream %p: start %d", stream, seq);
|
2016-11-24 17:00:42 +01:00
|
|
|
add_state_change (stream, SPA_NODE_STATE_STREAMING, false);
|
|
|
|
|
add_async_complete (stream, seq, SPA_RESULT_OK, true);
|
2016-09-09 16:05:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (impl->direction == SPA_DIRECTION_INPUT)
|
2016-11-07 10:24:13 +01:00
|
|
|
send_need_input (stream);
|
2016-09-09 16:05:58 +02:00
|
|
|
|
|
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SPA_NODE_COMMAND_FLUSH:
|
|
|
|
|
case SPA_NODE_COMMAND_DRAIN:
|
|
|
|
|
case SPA_NODE_COMMAND_MARKER:
|
2016-09-22 08:55:30 +02:00
|
|
|
{
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_warn ("unhandled node command %d", command->type);
|
2016-11-24 17:00:42 +01:00
|
|
|
add_async_complete (stream, seq, SPA_RESULT_NOT_IMPLEMENTED, true);
|
2016-09-09 16:05:58 +02:00
|
|
|
break;
|
2016-09-22 08:55:30 +02:00
|
|
|
}
|
2016-09-09 16:05:58 +02:00
|
|
|
case SPA_NODE_COMMAND_CLOCK_UPDATE:
|
|
|
|
|
{
|
2016-10-24 15:30:15 +02:00
|
|
|
SpaNodeCommandClockUpdate *cu = (SpaNodeCommandClockUpdate *) command;
|
2016-09-13 17:43:57 +02:00
|
|
|
if (cu->flags & SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE) {
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_set (stream->properties,
|
2016-09-13 17:43:57 +02:00
|
|
|
"pinos.latency.is-live", "1");
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_setf (stream->properties,
|
2016-09-13 17:43:57 +02:00
|
|
|
"pinos.latency.min", "%"PRId64, cu->latency);
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->last_ticks = cu->ticks;
|
|
|
|
|
impl->last_rate = cu->rate;
|
|
|
|
|
impl->last_monotonic = cu->monotonic_time;
|
2016-09-09 16:05:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
static SpaResult
|
|
|
|
|
stream_dispatch_func (void *object,
|
|
|
|
|
PinosMessageType type,
|
|
|
|
|
void *message,
|
|
|
|
|
void *data)
|
2016-07-21 18:38:24 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStream *stream = data;
|
|
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case PINOS_MESSAGE_SYNC:
|
|
|
|
|
case PINOS_MESSAGE_SUBSCRIBE:
|
|
|
|
|
case PINOS_MESSAGE_CREATE_NODE:
|
|
|
|
|
case PINOS_MESSAGE_CREATE_CLIENT_NODE:
|
|
|
|
|
case PINOS_MESSAGE_NODE_UPDATE:
|
|
|
|
|
case PINOS_MESSAGE_PORT_UPDATE:
|
|
|
|
|
case PINOS_MESSAGE_PORT_STATUS_CHANGE:
|
|
|
|
|
case PINOS_MESSAGE_NODE_STATE_CHANGE:
|
|
|
|
|
pinos_log_warn ("got unexpected message %d", type);
|
|
|
|
|
break;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_NOTIFY_DONE:
|
|
|
|
|
pinos_log_warn ("notify done %d", type);
|
|
|
|
|
break;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_NOTIFY_GLOBAL:
|
|
|
|
|
pinos_log_warn ("notify global %d", type);
|
|
|
|
|
break;
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_NOTIFY_GLOBAL_REMOVE:
|
|
|
|
|
pinos_log_warn ("notify global %d", type);
|
|
|
|
|
break;
|
2016-07-21 18:38:24 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_CREATE_NODE_DONE:
|
|
|
|
|
pinos_log_warn ("create node done %d", type);
|
|
|
|
|
break;
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_CREATE_CLIENT_NODE_DONE:
|
2016-07-20 17:29:34 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosMessageCreateClientNodeDone *cnd = message;
|
|
|
|
|
|
|
|
|
|
pinos_log_warn ("create client node done %d", type);
|
|
|
|
|
handle_socket (stream, cnd->datafd);
|
|
|
|
|
do_node_init (stream);
|
2016-07-20 17:29:34 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_ADD_PORT:
|
|
|
|
|
case PINOS_MESSAGE_REMOVE_PORT:
|
|
|
|
|
pinos_log_warn ("add/remove port not supported");
|
2016-07-20 17:29:34 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_SET_FORMAT:
|
|
|
|
|
{
|
|
|
|
|
PinosMessageSetFormat *p = message;
|
|
|
|
|
gpointer mem;
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (impl->format)
|
|
|
|
|
free (impl->format);
|
|
|
|
|
mem = malloc (pinos_serialize_format_get_size (p->format));
|
|
|
|
|
impl->format = pinos_serialize_format_copy_into (mem, p->format);
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->pending_seq = p->seq;
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_signal_emit (&stream->format_changed, stream, impl->format);
|
|
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case PINOS_MESSAGE_SET_PROPERTY:
|
|
|
|
|
pinos_log_warn ("set property not implemented");
|
2016-11-07 10:24:13 +01:00
|
|
|
break;
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_ADD_MEM:
|
2016-11-07 10:24:13 +01:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosMessageAddMem *p = message;
|
|
|
|
|
MemId *m;
|
|
|
|
|
|
|
|
|
|
m = find_mem (stream, p->mem_id);
|
|
|
|
|
if (m) {
|
|
|
|
|
pinos_log_debug ("update mem %u, fd %d, flags %d, size %zd", p->mem_id, p->memfd, p->flags, p->size);
|
|
|
|
|
} else {
|
|
|
|
|
m = pinos_array_add (&impl->mem_ids, sizeof (MemId));
|
|
|
|
|
pinos_log_debug ("add mem %u, fd %d, flags %d, size %zd", p->mem_id, p->memfd, p->flags, p->size);
|
2016-11-07 10:24:13 +01:00
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
m->id = p->mem_id;
|
|
|
|
|
m->fd = p->memfd;
|
|
|
|
|
m->flags = p->flags;
|
|
|
|
|
m->ptr = NULL;
|
|
|
|
|
m->size = p->size;
|
2016-11-07 10:24:13 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_USE_BUFFERS:
|
|
|
|
|
{
|
|
|
|
|
PinosMessageUseBuffers *p = message;
|
|
|
|
|
BufferId *bid;
|
|
|
|
|
unsigned int i, j, len;
|
|
|
|
|
SpaBuffer *b;
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
/* clear previous buffers */
|
|
|
|
|
clear_buffers (stream);
|
2016-10-14 19:23:05 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
for (i = 0; i < p->n_buffers; i++) {
|
|
|
|
|
MemId *mid = find_mem (stream, p->buffers[i].mem_id);
|
|
|
|
|
if (mid == NULL) {
|
|
|
|
|
pinos_log_warn ("unknown memory id %u", mid->id);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (mid->ptr == NULL) {
|
|
|
|
|
mid->ptr = mmap (NULL, mid->size, PROT_READ | PROT_WRITE, MAP_SHARED, mid->fd, 0);
|
|
|
|
|
if (mid->ptr == MAP_FAILED) {
|
|
|
|
|
mid->ptr = NULL;
|
|
|
|
|
pinos_log_warn ("Failed to mmap memory %zd %p: %s", mid->size, mid, strerror (errno));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
len = pinos_array_get_len (&impl->buffer_ids, BufferId);
|
|
|
|
|
bid = pinos_array_add (&impl->buffer_ids, sizeof (BufferId));
|
|
|
|
|
|
|
|
|
|
bid->buf_ptr = SPA_MEMBER (mid->ptr, p->buffers[i].offset, void);
|
|
|
|
|
{
|
|
|
|
|
size_t size;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
SpaMeta *m;
|
|
|
|
|
|
|
|
|
|
b = bid->buf_ptr;
|
|
|
|
|
size = sizeof (SpaBuffer);
|
|
|
|
|
m = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
|
|
|
|
|
for (i = 0; i < b->n_metas; i++)
|
|
|
|
|
size += sizeof (SpaMeta) + m[i].size;
|
|
|
|
|
for (i = 0; i < b->n_datas; i++)
|
|
|
|
|
size += sizeof (SpaData);
|
|
|
|
|
|
|
|
|
|
b = bid->buf = g_memdup (bid->buf_ptr, size);
|
|
|
|
|
|
|
|
|
|
if (b->metas)
|
|
|
|
|
b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
|
|
|
|
|
if (b->datas) {
|
|
|
|
|
bid->datas = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (b->datas), SpaData);
|
|
|
|
|
b->datas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->datas), SpaData);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
bid->id = b->id;
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (bid->id != len) {
|
|
|
|
|
pinos_log_warn ("unexpected id %u found, expected %u", bid->id, len);
|
|
|
|
|
impl->in_order = FALSE;
|
|
|
|
|
}
|
|
|
|
|
pinos_log_debug ("add buffer %d %d %zd", mid->id, bid->id, p->buffers[i].offset);
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
for (j = 0; j < b->n_metas; j++) {
|
|
|
|
|
SpaMeta *m = &b->metas[j];
|
|
|
|
|
if (m->data)
|
|
|
|
|
m->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (m->data), void);
|
|
|
|
|
}
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
for (j = 0; j < b->n_datas; j++) {
|
|
|
|
|
SpaData *d = &b->datas[j];
|
|
|
|
|
|
|
|
|
|
switch (d->type) {
|
|
|
|
|
case SPA_DATA_TYPE_ID:
|
|
|
|
|
{
|
|
|
|
|
MemId *bmid = find_mem (stream, SPA_PTR_TO_UINT32 (d->data));
|
|
|
|
|
d->type = SPA_DATA_TYPE_MEMFD;
|
|
|
|
|
d->data = NULL;
|
|
|
|
|
d->fd = bmid->fd;
|
|
|
|
|
pinos_log_debug (" data %d %u -> fd %d", j, bmid->id, bmid->fd);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SPA_DATA_TYPE_MEMPTR:
|
|
|
|
|
{
|
|
|
|
|
d->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (d->data), void);
|
|
|
|
|
d->fd = -1;
|
|
|
|
|
pinos_log_debug (" data %d %u -> mem %p", j, bid->id, d->data);
|
|
|
|
|
break;
|
2016-11-07 10:24:13 +01:00
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
default:
|
|
|
|
|
pinos_log_warn ("unknown buffer data type %d", d->type);
|
|
|
|
|
break;
|
2016-11-07 10:24:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
|
|
|
|
|
pinos_signal_emit (&stream->add_buffer, stream, bid->id);
|
2016-11-07 10:24:13 +01:00
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
|
|
|
|
|
if (p->n_buffers) {
|
|
|
|
|
add_state_change (stream, SPA_NODE_STATE_PAUSED, false);
|
|
|
|
|
} else {
|
|
|
|
|
add_state_change (stream, SPA_NODE_STATE_READY, false);
|
2016-11-07 10:24:13 +01:00
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
add_async_complete (stream, p->seq, SPA_RESULT_OK, true);
|
|
|
|
|
|
|
|
|
|
if (p->n_buffers)
|
|
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL);
|
|
|
|
|
else
|
|
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
|
2016-10-14 19:23:05 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
case PINOS_MESSAGE_NODE_EVENT:
|
|
|
|
|
{
|
|
|
|
|
PinosMessageNodeEvent *p = message;
|
|
|
|
|
handle_node_event (stream, p->event);
|
2016-10-14 19:23:05 +02:00
|
|
|
break;
|
2016-11-24 17:00:42 +01:00
|
|
|
}
|
|
|
|
|
case PINOS_MESSAGE_NODE_COMMAND:
|
|
|
|
|
{
|
|
|
|
|
PinosMessageNodeCommand *p = message;
|
|
|
|
|
handle_node_command (stream, p->seq, p->command);
|
2016-10-14 19:23:05 +02:00
|
|
|
break;
|
2016-11-24 17:00:42 +01:00
|
|
|
}
|
|
|
|
|
case PINOS_MESSAGE_PORT_COMMAND:
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case PINOS_MESSAGE_TRANSPORT_UPDATE:
|
|
|
|
|
{
|
|
|
|
|
PinosMessageTransportUpdate *p = message;
|
|
|
|
|
PinosTransportInfo info;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
info.memfd = p->memfd;
|
|
|
|
|
if (info.memfd == -1)
|
|
|
|
|
break;
|
|
|
|
|
info.offset = p->offset;
|
|
|
|
|
info.size = p->size;
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (impl->trans)
|
|
|
|
|
pinos_transport_free (impl->trans);
|
|
|
|
|
impl->trans = pinos_transport_new_from_info (&info);
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_log_debug ("transport update %d %p", impl->rtfd, impl->trans);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case PINOS_MESSAGE_INVALID:
|
|
|
|
|
pinos_log_warn ("unhandled message %d", type);
|
|
|
|
|
break;
|
2016-07-20 17:29:34 +02:00
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
return SPA_RESULT_OK;
|
2015-04-29 17:51:51 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2016-05-06 13:01:52 +02:00
|
|
|
* pinos_stream_connect:
|
2015-07-07 16:46:23 +02:00
|
|
|
* @stream: a #PinosStream
|
2016-05-06 13:01:52 +02:00
|
|
|
* @direction: the stream direction
|
2016-08-18 12:43:25 +02:00
|
|
|
* @mode: a #PinosStreamMode
|
2016-05-06 13:01:52 +02:00
|
|
|
* @port_path: the port path to connect to or %NULL to get the default port
|
2015-07-07 16:46:23 +02:00
|
|
|
* @flags: a #PinosStreamFlags
|
2016-08-05 16:39:26 +02:00
|
|
|
* @possible_formats: (transfer full): a #GPtrArray with possible accepted formats
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2016-05-06 13:01:52 +02:00
|
|
|
* Connect @stream for input or output on @port_path.
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2016-08-18 12:43:25 +02:00
|
|
|
* When @mode is #PINOS_STREAM_MODE_BUFFER, you should connect to the new-buffer
|
|
|
|
|
* signal and use pinos_stream_capture_buffer() to get the latest metadata and
|
|
|
|
|
* data.
|
|
|
|
|
*
|
2015-04-16 16:58:33 +02:00
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
2016-05-06 13:01:52 +02:00
|
|
|
pinos_stream_connect (PinosStream *stream,
|
|
|
|
|
PinosDirection direction,
|
2016-08-18 12:43:25 +02:00
|
|
|
PinosStreamMode mode,
|
2016-05-06 13:01:52 +02:00
|
|
|
const gchar *port_path,
|
|
|
|
|
PinosStreamFlags flags,
|
2016-11-24 17:00:42 +01:00
|
|
|
unsigned int n_possible_formats,
|
|
|
|
|
SpaFormat **possible_formats)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
PinosMessageCreateClientNode ccn;
|
|
|
|
|
SpaDict dict;
|
|
|
|
|
SpaDictItem items[1];
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->direction = direction == PINOS_DIRECTION_INPUT ? SPA_DIRECTION_INPUT : SPA_DIRECTION_OUTPUT;
|
|
|
|
|
impl->port_id = 0;
|
|
|
|
|
impl->mode = mode;
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->flags = flags;
|
2016-05-05 13:31:18 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->n_possible_formats = n_possible_formats;
|
|
|
|
|
impl->possible_formats = possible_formats;
|
|
|
|
|
|
|
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_CONNECTING, NULL);
|
|
|
|
|
|
|
|
|
|
if (stream->properties == NULL)
|
|
|
|
|
stream->properties = pinos_properties_new (NULL, NULL);
|
|
|
|
|
if (port_path)
|
|
|
|
|
pinos_properties_set (stream->properties,
|
|
|
|
|
"pinos.target.node", port_path);
|
|
|
|
|
|
|
|
|
|
impl->node_proxy = pinos_proxy_new (stream->context,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
impl->node_proxy->dispatch_func = stream_dispatch_func;
|
|
|
|
|
impl->node_proxy->dispatch_data = impl;
|
|
|
|
|
|
|
|
|
|
ccn.seq = ++impl->seq;
|
|
|
|
|
ccn.name = "client-node";
|
|
|
|
|
dict.n_items = 1;
|
|
|
|
|
dict.items = items;
|
|
|
|
|
items[0].key = "pinos.target.node";
|
|
|
|
|
items[0].value = port_path;
|
|
|
|
|
ccn.props = &dict;
|
|
|
|
|
ccn.id = impl->node_proxy->id;
|
|
|
|
|
pinos_proxy_send_message (stream->context->core_proxy,
|
|
|
|
|
PINOS_MESSAGE_CREATE_CLIENT_NODE,
|
|
|
|
|
&ccn,
|
|
|
|
|
true);
|
|
|
|
|
|
|
|
|
|
return true;
|
2016-05-05 13:31:18 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
/**
|
2016-09-22 08:55:30 +02:00
|
|
|
* pinos_stream_finish_format:
|
2016-08-24 16:26:58 +02:00
|
|
|
* @stream: a #PinosStream
|
2016-09-22 08:55:30 +02:00
|
|
|
* @res: a #SpaResult
|
|
|
|
|
* @params: an array of pointers to #SpaAllocParam
|
|
|
|
|
* @n_params: number of elements in @params
|
|
|
|
|
*
|
|
|
|
|
* Complete the negotiation process with result code @res.
|
|
|
|
|
*
|
|
|
|
|
* This function should be called after notification of the format.
|
|
|
|
|
|
|
|
|
|
* When @res indicates success, @params contain the parameters for the
|
|
|
|
|
* allocation state.
|
2016-08-24 16:26:58 +02:00
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
2016-09-22 08:55:30 +02:00
|
|
|
pinos_stream_finish_format (PinosStream *stream,
|
|
|
|
|
SpaResult res,
|
|
|
|
|
SpaAllocParam **params,
|
|
|
|
|
unsigned int n_params)
|
2016-08-24 16:26:58 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->port_info.params = params;
|
|
|
|
|
impl->port_info.n_params = n_params;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-09-22 08:55:30 +02:00
|
|
|
if (SPA_RESULT_IS_OK (res)) {
|
2016-11-03 19:41:53 +01:00
|
|
|
add_port_update (stream, PINOS_MESSAGE_PORT_UPDATE_INFO |
|
2016-11-24 17:00:42 +01:00
|
|
|
PINOS_MESSAGE_PORT_UPDATE_FORMAT,
|
|
|
|
|
false);
|
|
|
|
|
if (impl->format) {
|
|
|
|
|
add_state_change (stream, SPA_NODE_STATE_READY, false);
|
2016-09-22 08:55:30 +02:00
|
|
|
} else {
|
|
|
|
|
clear_buffers (stream);
|
2016-11-24 17:00:42 +01:00
|
|
|
add_state_change (stream, SPA_NODE_STATE_CONFIGURE, false);
|
2016-09-22 08:55:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->port_info.params = NULL;
|
|
|
|
|
impl->port_info.n_params = 0;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
add_async_complete (stream, impl->pending_seq, res, true);
|
2016-09-22 08:55:30 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->pending_seq = SPA_ID_INVALID;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
return true;
|
2016-05-12 17:03:28 +02:00
|
|
|
}
|
2015-08-25 16:36:01 +02:00
|
|
|
|
2016-05-12 17:03:28 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_stream_start:
|
|
|
|
|
* @stream: a #PinosStream
|
|
|
|
|
*
|
2016-08-18 12:43:25 +02:00
|
|
|
* Start capturing from @stream.
|
2016-05-12 17:03:28 +02:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
2016-08-18 12:43:25 +02:00
|
|
|
pinos_stream_start (PinosStream *stream)
|
2016-05-12 17:03:28 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
return true;
|
2016-05-12 17:03:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_stream_stop:
|
|
|
|
|
* @stream: a #PinosStream
|
|
|
|
|
*
|
|
|
|
|
* Stop capturing from @stream.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
2016-05-12 17:03:28 +02:00
|
|
|
pinos_stream_stop (PinosStream *stream)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
return true;
|
2015-05-04 10:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_disconnect:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* Disconnect @stream.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_disconnect (PinosStream *stream)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->disconnecting = true;
|
2015-08-25 16:36:01 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
return true;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
|
|
|
|
pinos_stream_get_time (PinosStream *stream,
|
|
|
|
|
PinosTime *time)
|
2016-09-12 12:28:51 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
|
|
|
|
int64_t now, elapsed;
|
|
|
|
|
struct timespec ts;
|
2016-09-12 12:28:51 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
clock_gettime (CLOCK_MONOTONIC, &ts);
|
|
|
|
|
now = SPA_TIMESPEC_TO_TIME (&ts);
|
|
|
|
|
elapsed = (now - impl->last_monotonic) / 1000;
|
2016-09-12 12:28:51 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
time->ticks = impl->last_ticks + (elapsed * impl->last_rate) / SPA_USEC_PER_SEC;
|
|
|
|
|
time->rate = impl->last_rate;
|
2016-09-12 12:28:51 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
return true;
|
2016-09-12 12:28:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_stream_get_empty_buffer:
|
|
|
|
|
* @stream: a #PinosStream
|
|
|
|
|
*
|
|
|
|
|
* Get the id of an empty buffer that can be filled
|
|
|
|
|
*
|
|
|
|
|
* Returns: the id of an empty buffer or #SPA_ID_INVALID when no buffer is
|
|
|
|
|
* available.
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
uint32_t
|
2016-08-24 16:26:58 +02:00
|
|
|
pinos_stream_get_empty_buffer (PinosStream *stream)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-03 19:41:53 +01:00
|
|
|
BufferId *bid;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_array_for_each (bid, &impl->buffer_ids) {
|
2016-08-24 16:26:58 +02:00
|
|
|
if (!bid->used)
|
|
|
|
|
return bid->id;
|
|
|
|
|
}
|
|
|
|
|
return SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pinos_stream_recycle_buffer:
|
|
|
|
|
* @stream: a #PinosStream
|
|
|
|
|
* @id: a buffer id
|
|
|
|
|
*
|
|
|
|
|
* Recycle the buffer with @id.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
|
|
|
|
pinos_stream_recycle_buffer (PinosStream *stream,
|
|
|
|
|
uint32_t id)
|
2016-08-24 16:26:58 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-11-07 10:24:13 +01:00
|
|
|
SpaNodeEventReuseBuffer rb;
|
2016-11-07 18:23:09 +01:00
|
|
|
uint8_t cmd = PINOS_TRANSPORT_CMD_HAVE_EVENT;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-07 10:24:13 +01:00
|
|
|
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
|
|
|
|
|
rb.event.size = sizeof (rb);
|
2016-11-24 17:00:42 +01:00
|
|
|
rb.port_id = impl->port_id;
|
2016-11-07 10:24:13 +01:00
|
|
|
rb.buffer_id = id;
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_transport_add_event (impl->trans, &rb.event);
|
|
|
|
|
write (impl->rtfd, &cmd, 1);
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
return true;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2016-05-17 20:14:06 +02:00
|
|
|
* pinos_stream_peek_buffer:
|
2015-07-07 16:46:23 +02:00
|
|
|
* @stream: a #PinosStream
|
2016-08-24 16:26:58 +02:00
|
|
|
* @id: the buffer id
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2016-08-24 16:26:58 +02:00
|
|
|
* Get the buffer with @id from @stream. This function should be called from
|
2015-08-31 16:47:32 +02:00
|
|
|
* the new-buffer signal callback.
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2016-07-28 21:19:20 +02:00
|
|
|
* Returns: a #SpaBuffer or %NULL when there is no buffer.
|
2015-04-16 16:58:33 +02:00
|
|
|
*/
|
2016-07-28 21:19:20 +02:00
|
|
|
SpaBuffer *
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_stream_peek_buffer (PinosStream *stream,
|
|
|
|
|
uint32_t id)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-08-24 16:26:58 +02:00
|
|
|
BufferId *bid;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
if ((bid = find_buffer (stream, id)))
|
|
|
|
|
return bid->buf;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
/**
|
2015-08-31 16:47:32 +02:00
|
|
|
* pinos_stream_send_buffer:
|
2015-08-24 16:41:04 +02:00
|
|
|
* @stream: a #PinosStream
|
2016-08-24 16:26:58 +02:00
|
|
|
* @id: a buffer id
|
|
|
|
|
* @offset: the offset in the buffer
|
|
|
|
|
* @size: the size in the buffer
|
2015-08-24 16:41:04 +02:00
|
|
|
*
|
2016-08-24 16:26:58 +02:00
|
|
|
* Send a buffer with @id to @stream.
|
2015-08-31 16:47:32 +02:00
|
|
|
*
|
|
|
|
|
* For provider streams, this function should be called whenever there is a new frame
|
|
|
|
|
* available.
|
2015-05-11 18:23:24 +02:00
|
|
|
*
|
2016-08-24 16:26:58 +02:00
|
|
|
* Returns: %TRUE when @id was handled
|
2015-05-11 18:23:24 +02:00
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
bool
|
2016-08-24 16:26:58 +02:00
|
|
|
pinos_stream_send_buffer (PinosStream *stream,
|
2016-11-24 17:00:42 +01:00
|
|
|
uint32_t id)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
2016-08-24 16:26:58 +02:00
|
|
|
BufferId *bid;
|
2016-10-03 19:43:42 +02:00
|
|
|
guint i;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
|
|
|
|
if ((bid = find_buffer (stream, id))) {
|
2016-11-07 18:23:09 +01:00
|
|
|
uint8_t cmd = PINOS_TRANSPORT_CMD_HAVE_DATA;
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
bid->used = TRUE;
|
2016-10-03 19:43:42 +02:00
|
|
|
for (i = 0; i < bid->buf->n_datas; i++) {
|
|
|
|
|
bid->datas[i].size = bid->buf->datas[i].size;
|
|
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->trans->outputs[0].buffer_id = id;
|
|
|
|
|
impl->trans->outputs[0].status = SPA_RESULT_OK;
|
|
|
|
|
write (impl->rtfd, &cmd, 1);
|
|
|
|
|
return true;
|
2016-08-24 16:26:58 +02:00
|
|
|
} else {
|
2016-11-24 17:00:42 +01:00
|
|
|
return true;
|
2016-08-24 16:26:58 +02:00
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|