client-node: remove transport area

We don't need the area anymore
This commit is contained in:
Wim Taymans 2018-04-12 10:12:40 +02:00
parent 10fff4b2f8
commit 03b914405d
8 changed files with 18 additions and 475 deletions

View file

@ -38,7 +38,6 @@
#include "pipewire/core.h"
#include "modules/spa/spa-node.h"
#include "client-node.h"
#include "transport.h"
/** \cond */
@ -141,8 +140,6 @@ struct impl {
struct node node;
struct pw_client_node_transport *transport;
struct pw_map io_map;
struct pw_memblock *io_areas;
@ -855,21 +852,15 @@ static int
impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
{
struct node *this;
struct impl *impl;
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (!CHECK_OUT_PORT(this, SPA_DIRECTION_OUTPUT, port_id))
return -EINVAL;
spa_log_trace(this->log, "reuse buffer %d", buffer_id);
pw_client_node_transport_add_message(impl->transport, (struct pw_client_node_message *)
&PW_CLIENT_NODE_MESSAGE_PORT_REUSE_BUFFER_INIT(port_id, buffer_id));
//send_process(this);
return 0;
return -ENOTSUP;
}
static int
@ -915,9 +906,6 @@ client_node_done(void *data, int seq, int res)
struct impl *impl = data;
struct node *this = &impl->node;
if (seq == 0 && res == 0 && impl->transport == NULL)
impl->transport = pw_client_node_transport_new();
this->callbacks->done(this->callbacks_data, seq, res);
}
@ -1176,8 +1164,7 @@ static void node_initialized(void *data)
pw_client_node_resource_transport(this->resource,
pw_global_get_id(pw_node_get_global(node)),
impl->other_fds[0],
impl->other_fds[1],
impl->transport);
impl->other_fds[1]);
}
static void node_free(void *data)
@ -1187,9 +1174,6 @@ static void node_free(void *data)
pw_log_debug("client-node %p: free", &impl->this);
node_clear(&impl->node);
if (impl->transport)
pw_client_node_transport_destroy(impl->transport);
spa_hook_remove(&impl->node_listener);
pw_array_clear(&impl->mems);

View file

@ -29,8 +29,6 @@
#include "extensions/protocol-native.h"
#include "extensions/client-node.h"
#include "transport.h"
static void
client_node_marshal_done(void *object, int seq, int res)
{
@ -188,33 +186,25 @@ static int client_node_demarshal_transport(void *object, void *data, size_t size
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t node_id, ridx, widx, memfd_idx;
uint32_t node_id, ridx, widx;
int readfd, writefd;
struct pw_client_node_transport_info info;
struct pw_client_node_transport *transport;
spa_pod_parser_init(&prs, data, size, 0);
if (spa_pod_parser_get(&prs,
"["
"i", &node_id,
"i", &ridx,
"i", &widx,
"i", &memfd_idx,
"i", &info.offset,
"i", &info.size, NULL) < 0)
"i", &widx, NULL) < 0)
return -EINVAL;
readfd = pw_protocol_native_get_proxy_fd(proxy, ridx);
writefd = pw_protocol_native_get_proxy_fd(proxy, widx);
info.memfd = pw_protocol_native_get_proxy_fd(proxy, memfd_idx);
if (readfd == -1 || writefd == -1 || info.memfd == -1)
if (readfd == -1 || writefd == -1)
return -EINVAL;
transport = pw_client_node_transport_new_from_info(&info);
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, transport, node_id,
readfd, writefd, transport);
readfd, writefd);
return 0;
}
@ -462,24 +452,17 @@ client_node_marshal_add_mem(void *object,
pw_protocol_native_end_resource(resource, b);
}
static void client_node_marshal_transport(void *object, uint32_t node_id, int readfd, int writefd,
struct pw_client_node_transport *transport)
static void client_node_marshal_transport(void *object, uint32_t node_id, int readfd, int writefd)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
struct pw_client_node_transport_info info;
pw_client_node_transport_get_info(transport, &info);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_TRANSPORT);
spa_pod_builder_struct(b,
"i", node_id,
"i", pw_protocol_native_add_resource_fd(resource, readfd),
"i", pw_protocol_native_add_resource_fd(resource, writefd),
"i", pw_protocol_native_add_resource_fd(resource, info.memfd),
"i", info.offset,
"i", info.size);
"i", pw_protocol_native_add_resource_fd(resource, writefd));
pw_protocol_native_end_resource(resource, b);
}

View file

@ -1,261 +0,0 @@
/* PipeWire
* 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 <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <spa/utils/ringbuffer.h>
#include <spa/node/io.h>
#include <pipewire/log.h>
#include <extensions/client-node.h>
#include "transport.h"
/** \cond */
#define INPUT_BUFFER_SIZE (1<<12)
#define OUTPUT_BUFFER_SIZE (1<<12)
struct transport {
struct pw_client_node_transport trans;
struct pw_memblock *mem;
size_t offset;
struct pw_client_node_message current;
uint32_t current_index;
};
/** \endcond */
static size_t area_get_size(void)
{
size_t size;
size = sizeof(struct spa_ringbuffer);
size += INPUT_BUFFER_SIZE;
size += sizeof(struct spa_ringbuffer);
size += OUTPUT_BUFFER_SIZE;
return size;
}
static void transport_setup_area(void *p, struct pw_client_node_transport *trans)
{
trans->input_buffer = p;
p = SPA_MEMBER(p, sizeof(struct spa_ringbuffer), void);
trans->input_data = p;
p = SPA_MEMBER(p, INPUT_BUFFER_SIZE, void);
trans->output_buffer = p;
p = SPA_MEMBER(p, sizeof(struct spa_ringbuffer), void);
trans->output_data = p;
p = SPA_MEMBER(p, OUTPUT_BUFFER_SIZE, void);
}
static void transport_reset_area(struct pw_client_node_transport *trans)
{
spa_ringbuffer_init(trans->input_buffer);
spa_ringbuffer_init(trans->output_buffer);
}
static void destroy(struct pw_client_node_transport *trans)
{
struct transport *impl = (struct transport *) trans;
pw_log_debug("transport %p: destroy", trans);
pw_memblock_free(impl->mem);
free(impl);
}
static int add_message(struct pw_client_node_transport *trans, struct pw_client_node_message *message)
{
struct transport *impl = (struct transport *) trans;
int32_t filled, avail;
uint32_t size, index;
if (impl == NULL || message == NULL)
return -EINVAL;
filled = spa_ringbuffer_get_write_index(trans->output_buffer, &index);
avail = OUTPUT_BUFFER_SIZE - filled;
size = SPA_POD_SIZE(message);
if (avail < size)
return -ENOSPC;
spa_ringbuffer_write_data(trans->output_buffer,
trans->output_data, OUTPUT_BUFFER_SIZE,
index & (OUTPUT_BUFFER_SIZE - 1), message, size);
spa_ringbuffer_write_update(trans->output_buffer, index + size);
return 0;
}
static int next_message(struct pw_client_node_transport *trans, struct pw_client_node_message *message)
{
struct transport *impl = (struct transport *) trans;
int32_t avail;
if (impl == NULL || message == NULL)
return -EINVAL;
avail = spa_ringbuffer_get_read_index(trans->input_buffer, &impl->current_index);
if (avail < sizeof(struct pw_client_node_message))
return 0;
spa_ringbuffer_read_data(trans->input_buffer,
trans->input_data, INPUT_BUFFER_SIZE,
impl->current_index & (INPUT_BUFFER_SIZE - 1),
&impl->current, sizeof(struct pw_client_node_message));
if (avail < SPA_POD_SIZE(&impl->current))
return 0;
*message = impl->current;
return 1;
}
static int parse_message(struct pw_client_node_transport *trans, void *message)
{
struct transport *impl = (struct transport *) trans;
uint32_t size;
if (impl == NULL || message == NULL)
return -EINVAL;
size = SPA_POD_SIZE(&impl->current);
spa_ringbuffer_read_data(trans->input_buffer,
trans->input_data, INPUT_BUFFER_SIZE,
impl->current_index & (INPUT_BUFFER_SIZE - 1), message, size);
spa_ringbuffer_read_update(trans->input_buffer, impl->current_index + size);
return 0;
}
/** Create a new transport
* \return a newly allocated \ref pw_client_node_transport
* \memberof pw_client_node_transport
*/
struct pw_client_node_transport *
pw_client_node_transport_new(void)
{
struct transport *impl;
struct pw_client_node_transport *trans;
impl = calloc(1, sizeof(struct transport));
if (impl == NULL)
return NULL;
pw_log_debug("transport %p: new", impl);
trans = &impl->trans;
impl->offset = 0;
if (pw_memblock_alloc(PW_MEMBLOCK_FLAG_WITH_FD |
PW_MEMBLOCK_FLAG_MAP_READWRITE |
PW_MEMBLOCK_FLAG_SEAL,
area_get_size(),
&impl->mem) < 0)
return NULL;
transport_setup_area(impl->mem->ptr, trans);
transport_reset_area(trans);
trans->destroy = destroy;
trans->add_message = add_message;
trans->next_message = next_message;
trans->parse_message = parse_message;
return trans;
}
struct pw_client_node_transport *
pw_client_node_transport_new_from_info(struct pw_client_node_transport_info *info)
{
struct transport *impl;
struct pw_client_node_transport *trans;
void *tmp;
int res;
impl = calloc(1, sizeof(struct transport));
if (impl == NULL)
return NULL;
trans = &impl->trans;
pw_log_debug("transport %p: new from info", impl);
if ((res = pw_memblock_import(PW_MEMBLOCK_FLAG_MAP_READWRITE |
PW_MEMBLOCK_FLAG_WITH_FD,
info->memfd,
info->offset,
info->size, &impl->mem)) < 0) {
pw_log_warn("transport %p: failed to map fd %d: %s", impl, info->memfd,
spa_strerror(res));
goto mmap_failed;
}
impl->offset = info->offset;
transport_setup_area(impl->mem->ptr, trans);
tmp = trans->output_buffer;
trans->output_buffer = trans->input_buffer;
trans->input_buffer = tmp;
tmp = trans->output_data;
trans->output_data = trans->input_data;
trans->input_data = tmp;
trans->destroy = destroy;
trans->add_message = add_message;
trans->next_message = next_message;
trans->parse_message = parse_message;
return trans;
mmap_failed:
free(impl);
errno = -res;
return NULL;
}
/** Get transport info
* \param trans the transport to get info of
* \param[out] info transport info
* \return 0 on success
*
* Fill \a info with the transport info of \a trans. This information can be
* passed to the client to set up the shared transport.
*
* \memberof pw_client_node_transport
*/
int pw_client_node_transport_get_info(struct pw_client_node_transport *trans,
struct pw_client_node_transport_info *info)
{
struct transport *impl = (struct transport *) trans;
info->memfd = impl->mem->fd;
info->offset = impl->offset;
info->size = impl->mem->size;
return 0;
}

View file

@ -1,54 +0,0 @@
/* PipeWire
* 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.
*/
#ifndef __PIPEWIRE_CLIENT_NODE_TRANSPORT_H__
#define __PIPEWIRE_CLIENT_NODE_TRANSPORT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include <spa/utils/defs.h>
#include <pipewire/mem.h>
/** information about the transport region \memberof pw_client_node */
struct pw_client_node_transport_info {
int memfd; /**< the memfd of the transport area */
uint32_t offset; /**< offset to map \a memfd at */
uint32_t size; /**< size of memfd mapping */
};
struct pw_client_node_transport *
pw_client_node_transport_new(void);
struct pw_client_node_transport *
pw_client_node_transport_new_from_info(struct pw_client_node_transport_info *info);
int
pw_client_node_transport_get_info(struct pw_client_node_transport *trans,
struct pw_client_node_transport_info *info);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __PIPEWIRE_CLIENT_NODE_TRANSPORT_H__ */