[Spice-devel] [PATCH spice-server 07/18] sound: Rename channel to client if variable used for clients
Frediano Ziglio
fziglio at redhat.com
Wed Nov 23 18:07:21 UTC 2016
Due to object rename using channel to store a client is
quite confusing.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/sound.c | 526 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 263 insertions(+), 263 deletions(-)
diff --git a/server/sound.c b/server/sound.c
index 256b3da..c985aae 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -75,13 +75,13 @@ enum PlaybackCommand {
typedef struct SndChannelClient SndChannelClient;
typedef void (*snd_channel_send_messages_proc)(void *in_channel);
-typedef int (*snd_channel_handle_message_proc)(SndChannelClient *channel, size_t size, uint32_t type, void *message);
-typedef void (*snd_channel_on_message_done_proc)(SndChannelClient *channel);
-typedef void (*snd_channel_cleanup_channel_proc)(SndChannelClient *channel);
+typedef int (*snd_channel_handle_message_proc)(SndChannelClient *client, size_t size, uint32_t type, void *message);
+typedef void (*snd_channel_on_message_done_proc)(SndChannelClient *client);
+typedef void (*snd_channel_cleanup_channel_proc)(SndChannelClient *client);
typedef struct SndChannel SndChannel;
-/* Connects an audio channel to a Spice client */
+/* Connects an audio client to a Spice client */
struct SndChannelClient {
RedsStream *stream;
SndChannel *worker;
@@ -122,7 +122,7 @@ typedef struct AudioFrame AudioFrame;
struct AudioFrame {
uint32_t time;
uint32_t samples[SND_CODEC_MAX_FRAME_SIZE];
- PlaybackChannelClient *channel;
+ PlaybackChannelClient *client;
AudioFrame *next;
};
@@ -178,135 +178,135 @@ typedef struct RecordChannelClient {
/* A list of all Spice{Playback,Record}State objects */
static SndChannel *snd_channels;
-static void snd_receive(SndChannelClient *channel);
+static void snd_receive(SndChannelClient *client);
static void snd_playback_start(SndChannel *worker);
static void snd_record_start(SndChannel *worker);
-static SndChannelClient *snd_channel_ref(SndChannelClient *channel)
+static SndChannelClient *snd_channel_ref(SndChannelClient *client)
{
- channel->refs++;
- return channel;
+ client->refs++;
+ return client;
}
-static SndChannelClient *snd_channel_unref(SndChannelClient *channel)
+static SndChannelClient *snd_channel_unref(SndChannelClient *client)
{
- if (!--channel->refs) {
- spice_printerr("SndChannelClient=%p freed", channel);
- free(channel);
+ if (!--client->refs) {
+ spice_printerr("SndChannelClient=%p freed", client);
+ free(client);
return NULL;
}
- return channel;
+ return client;
}
-static RedsState* snd_channel_get_server(SndChannelClient *channel)
+static RedsState* snd_channel_get_server(SndChannelClient *client)
{
- g_return_val_if_fail(channel != NULL, NULL);
- return red_channel_get_server(channel->worker->base_channel);
+ g_return_val_if_fail(client != NULL, NULL);
+ return red_channel_get_server(client->worker->base_channel);
}
-static void snd_disconnect_channel(SndChannelClient *channel)
+static void snd_disconnect_channel(SndChannelClient *client)
{
SndChannel *worker;
RedsState *reds;
RedChannel *red_channel;
uint32_t type;
- if (!channel || !channel->stream) {
+ if (!client || !client->stream) {
spice_debug("not connected");
return;
}
- red_channel = red_channel_client_get_channel(channel->channel_client);
- reds = snd_channel_get_server(channel);
+ red_channel = red_channel_client_get_channel(client->channel_client);
+ reds = snd_channel_get_server(client);
g_object_get(red_channel, "channel-type", &type, NULL);
spice_debug("SndChannelClient=%p rcc=%p type=%d",
- channel, channel->channel_client, type);
- worker = channel->worker;
- channel->cleanup(channel);
+ client, client->channel_client, type);
+ worker = client->worker;
+ client->cleanup(client);
red_channel_client_disconnect(worker->connection->channel_client);
worker->connection->channel_client = NULL;
- reds_core_watch_remove(reds, channel->stream->watch);
- channel->stream->watch = NULL;
- reds_stream_free(channel->stream);
- channel->stream = NULL;
- spice_marshaller_destroy(channel->send_data.marshaller);
- snd_channel_unref(channel);
+ reds_core_watch_remove(reds, client->stream->watch);
+ client->stream->watch = NULL;
+ reds_stream_free(client->stream);
+ client->stream = NULL;
+ spice_marshaller_destroy(client->send_data.marshaller);
+ snd_channel_unref(client);
worker->connection = NULL;
}
static void snd_playback_free_frame(PlaybackChannelClient *playback_client, AudioFrame *frame)
{
- frame->channel = playback_client;
+ frame->client = playback_client;
frame->next = playback_client->free_frames;
playback_client->free_frames = frame;
}
-static void snd_playback_on_message_done(SndChannelClient *channel)
+static void snd_playback_on_message_done(SndChannelClient *client)
{
- PlaybackChannelClient *playback_client = (PlaybackChannelClient *)channel;
+ PlaybackChannelClient *playback_client = (PlaybackChannelClient *)client;
if (playback_client->in_progress) {
snd_playback_free_frame(playback_client, playback_client->in_progress);
playback_client->in_progress = NULL;
if (playback_client->pending_frame) {
- channel->command |= SND_PLAYBACK_PCM_MASK;
+ client->command |= SND_PLAYBACK_PCM_MASK;
}
}
}
-static void snd_record_on_message_done(SndChannelClient *channel)
+static void snd_record_on_message_done(SndChannelClient *client)
{
}
-static int snd_send_data(SndChannelClient *channel)
+static int snd_send_data(SndChannelClient *client)
{
uint32_t n;
- if (!channel) {
+ if (!client) {
return FALSE;
}
- if (!(n = channel->send_data.size - channel->send_data.pos)) {
+ if (!(n = client->send_data.size - client->send_data.pos)) {
return TRUE;
}
- RedsState *reds = snd_channel_get_server(channel);
+ RedsState *reds = snd_channel_get_server(client);
for (;;) {
struct iovec vec[IOV_MAX];
int vec_size;
if (!n) {
- channel->on_message_done(channel);
+ client->on_message_done(client);
- if (channel->blocked) {
- channel->blocked = FALSE;
- reds_core_watch_update_mask(reds, channel->stream->watch, SPICE_WATCH_EVENT_READ);
+ if (client->blocked) {
+ client->blocked = FALSE;
+ reds_core_watch_update_mask(reds, client->stream->watch, SPICE_WATCH_EVENT_READ);
}
break;
}
- vec_size = spice_marshaller_fill_iovec(channel->send_data.marshaller,
- vec, IOV_MAX, channel->send_data.pos);
- n = reds_stream_writev(channel->stream, vec, vec_size);
+ vec_size = spice_marshaller_fill_iovec(client->send_data.marshaller,
+ vec, IOV_MAX, client->send_data.pos);
+ n = reds_stream_writev(client->stream, vec, vec_size);
if (n == -1) {
switch (errno) {
case EAGAIN:
- channel->blocked = TRUE;
- reds_core_watch_update_mask(reds, channel->stream->watch, SPICE_WATCH_EVENT_READ |
+ client->blocked = TRUE;
+ reds_core_watch_update_mask(reds, client->stream->watch, SPICE_WATCH_EVENT_READ |
SPICE_WATCH_EVENT_WRITE);
return FALSE;
case EINTR:
break;
case EPIPE:
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return FALSE;
default:
spice_printerr("%s", strerror(errno));
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return FALSE;
}
} else {
- channel->send_data.pos += n;
+ client->send_data.pos += n;
}
- n = channel->send_data.size - channel->send_data.pos;
+ n = client->send_data.size - client->send_data.pos;
}
return TRUE;
}
@@ -356,9 +356,9 @@ static int snd_record_handle_write(RecordChannelClient *record_client, size_t si
return TRUE;
}
-static int snd_playback_handle_message(SndChannelClient *channel, size_t size, uint32_t type, void *message)
+static int snd_playback_handle_message(SndChannelClient *client, size_t size, uint32_t type, void *message)
{
- if (!channel) {
+ if (!client) {
return FALSE;
}
@@ -372,19 +372,19 @@ static int snd_playback_handle_message(SndChannelClient *channel, size_t size, u
return TRUE;
}
-static int snd_record_handle_message(SndChannelClient *channel, size_t size, uint32_t type, void *message)
+static int snd_record_handle_message(SndChannelClient *client, size_t size, uint32_t type, void *message)
{
- RecordChannelClient *record_client = (RecordChannelClient *)channel;
+ RecordChannelClient *record_client = (RecordChannelClient *)client;
- if (!channel) {
+ if (!client) {
return FALSE;
}
switch (type) {
case SPICE_MSGC_RECORD_DATA:
- return snd_record_handle_write((RecordChannelClient *)channel, size, message);
+ return snd_record_handle_write((RecordChannelClient *)client, size, message);
case SPICE_MSGC_RECORD_MODE: {
SpiceMsgcRecordMode *mode = (SpiceMsgcRecordMode *)message;
- SndChannel *worker = channel->worker;
+ SndChannel *worker = client->worker;
record_client->mode_time = mode->time;
if (mode->mode != SPICE_AUDIO_DATA_MODE_RAW) {
if (snd_codec_is_capable(mode->mode, worker->frequency)) {
@@ -420,24 +420,24 @@ static int snd_record_handle_message(SndChannelClient *channel, size_t size, uin
return TRUE;
}
-static void snd_receive(SndChannelClient *channel)
+static void snd_receive(SndChannelClient *client)
{
SpiceDataHeaderOpaque *header;
- if (!channel) {
+ if (!client) {
return;
}
- header = &channel->channel_client->incoming.header;
+ header = &client->channel_client->incoming.header;
for (;;) {
ssize_t n;
- n = channel->receive_data.end - channel->receive_data.now;
+ n = client->receive_data.end - client->receive_data.now;
spice_warn_if_fail(n > 0);
- n = reds_stream_read(channel->stream, channel->receive_data.now, n);
+ n = reds_stream_read(client->stream, client->receive_data.now, n);
if (n <= 0) {
if (n == 0) {
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return;
}
spice_assert(n == -1);
@@ -447,54 +447,54 @@ static void snd_receive(SndChannelClient *channel)
case EINTR:
break;
case EPIPE:
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return;
default:
spice_printerr("%s", strerror(errno));
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return;
}
} else {
- channel->receive_data.now += n;
+ client->receive_data.now += n;
for (;;) {
- uint8_t *msg_start = channel->receive_data.message_start;
+ uint8_t *msg_start = client->receive_data.message_start;
uint8_t *data = msg_start + header->header_size;
size_t parsed_size;
uint8_t *parsed;
message_destructor_t parsed_free;
header->data = msg_start;
- n = channel->receive_data.now - msg_start;
+ n = client->receive_data.now - msg_start;
if (n < header->header_size ||
n < header->header_size + header->get_msg_size(header)) {
break;
}
- parsed = channel->parser((void *)data, data + header->get_msg_size(header),
+ parsed = client->parser((void *)data, data + header->get_msg_size(header),
header->get_msg_type(header),
SPICE_VERSION_MINOR, &parsed_size, &parsed_free);
if (parsed == NULL) {
spice_printerr("failed to parse message type %d", header->get_msg_type(header));
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return;
}
- if (!channel->handle_message(channel, parsed_size,
+ if (!client->handle_message(client, parsed_size,
header->get_msg_type(header), parsed)) {
free(parsed);
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return;
}
parsed_free(parsed);
- channel->receive_data.message_start = msg_start + header->header_size +
+ client->receive_data.message_start = msg_start + header->header_size +
header->get_msg_size(header);
}
- if (channel->receive_data.now == channel->receive_data.message_start) {
- channel->receive_data.now = channel->receive_data.buf;
- channel->receive_data.message_start = channel->receive_data.buf;
- } else if (channel->receive_data.now == channel->receive_data.end) {
- memcpy(channel->receive_data.buf, channel->receive_data.message_start, n);
- channel->receive_data.now = channel->receive_data.buf + n;
- channel->receive_data.message_start = channel->receive_data.buf;
+ if (client->receive_data.now == client->receive_data.message_start) {
+ client->receive_data.now = client->receive_data.buf;
+ client->receive_data.message_start = client->receive_data.buf;
+ } else if (client->receive_data.now == client->receive_data.end) {
+ memcpy(client->receive_data.buf, client->receive_data.message_start, n);
+ client->receive_data.now = client->receive_data.buf + n;
+ client->receive_data.message_start = client->receive_data.buf;
}
}
}
@@ -502,93 +502,93 @@ static void snd_receive(SndChannelClient *channel)
static void snd_event(int fd, int event, void *data)
{
- SndChannelClient *channel = data;
+ SndChannelClient *client = data;
if (event & SPICE_WATCH_EVENT_READ) {
- snd_receive(channel);
+ snd_receive(client);
}
if (event & SPICE_WATCH_EVENT_WRITE) {
- channel->send_messages(channel);
+ client->send_messages(client);
}
}
-static inline int snd_reset_send_data(SndChannelClient *channel, uint16_t verb)
+static inline int snd_reset_send_data(SndChannelClient *client, uint16_t verb)
{
SpiceDataHeaderOpaque *header;
- if (!channel) {
+ if (!client) {
return FALSE;
}
- header = &channel->channel_client->priv->send_data.header;
- spice_marshaller_reset(channel->send_data.marshaller);
- header->data = spice_marshaller_reserve_space(channel->send_data.marshaller,
+ header = &client->channel_client->priv->send_data.header;
+ spice_marshaller_reset(client->send_data.marshaller);
+ header->data = spice_marshaller_reserve_space(client->send_data.marshaller,
header->header_size);
- spice_marshaller_set_base(channel->send_data.marshaller,
+ spice_marshaller_set_base(client->send_data.marshaller,
header->header_size);
- channel->send_data.pos = 0;
+ client->send_data.pos = 0;
header->set_msg_size(header, 0);
header->set_msg_type(header, verb);
- channel->send_data.serial++;
- if (!channel->channel_client->priv->is_mini_header) {
- header->set_msg_serial(header, channel->send_data.serial);
+ client->send_data.serial++;
+ if (!client->channel_client->priv->is_mini_header) {
+ header->set_msg_serial(header, client->send_data.serial);
header->set_msg_sub_list(header, 0);
}
return TRUE;
}
-static int snd_begin_send_message(SndChannelClient *channel)
+static int snd_begin_send_message(SndChannelClient *client)
{
- SpiceDataHeaderOpaque *header = &channel->channel_client->priv->send_data.header;
+ SpiceDataHeaderOpaque *header = &client->channel_client->priv->send_data.header;
- spice_marshaller_flush(channel->send_data.marshaller);
- channel->send_data.size = spice_marshaller_get_total_size(channel->send_data.marshaller);
- header->set_msg_size(header, channel->send_data.size - header->header_size);
- return snd_send_data(channel);
+ spice_marshaller_flush(client->send_data.marshaller);
+ client->send_data.size = spice_marshaller_get_total_size(client->send_data.marshaller);
+ header->set_msg_size(header, client->send_data.size - header->header_size);
+ return snd_send_data(client);
}
-static int snd_channel_send_migrate(SndChannelClient *channel)
+static int snd_channel_send_migrate(SndChannelClient *client)
{
SpiceMsgMigrate migrate;
- if (!snd_reset_send_data(channel, SPICE_MSG_MIGRATE)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_MIGRATE)) {
return FALSE;
}
spice_debug(NULL);
migrate.flags = 0;
- spice_marshall_msg_migrate(channel->send_data.marshaller, &migrate);
+ spice_marshall_msg_migrate(client->send_data.marshaller, &migrate);
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
-static int snd_playback_send_migrate(PlaybackChannelClient *channel)
+static int snd_playback_send_migrate(PlaybackChannelClient *client)
{
- return snd_channel_send_migrate(&channel->base);
+ return snd_channel_send_migrate(&client->base);
}
-static int snd_send_volume(SndChannelClient *channel, uint32_t cap, int msg)
+static int snd_send_volume(SndChannelClient *client, uint32_t cap, int msg)
{
SpiceMsgAudioVolume *vol;
uint8_t c;
- SpiceVolumeState *st = &channel->worker->volume;
+ SpiceVolumeState *st = &client->worker->volume;
- if (!red_channel_client_test_remote_cap(channel->channel_client, cap)) {
+ if (!red_channel_client_test_remote_cap(client->channel_client, cap)) {
return TRUE;
}
vol = alloca(sizeof (SpiceMsgAudioVolume) +
st->volume_nchannels * sizeof (uint16_t));
- if (!snd_reset_send_data(channel, msg)) {
+ if (!snd_reset_send_data(client, msg)) {
return FALSE;
}
vol->nchannels = st->volume_nchannels;
for (c = 0; c < st->volume_nchannels; ++c) {
vol->volume[c] = st->volume[c];
}
- spice_marshall_SpiceMsgAudioVolume(channel->send_data.marshaller, vol);
+ spice_marshall_SpiceMsgAudioVolume(client->send_data.marshaller, vol);
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int snd_playback_send_volume(PlaybackChannelClient *playback_client)
@@ -597,22 +597,22 @@ static int snd_playback_send_volume(PlaybackChannelClient *playback_client)
SPICE_MSG_PLAYBACK_VOLUME);
}
-static int snd_send_mute(SndChannelClient *channel, uint32_t cap, int msg)
+static int snd_send_mute(SndChannelClient *client, uint32_t cap, int msg)
{
SpiceMsgAudioMute mute;
- SpiceVolumeState *st = &channel->worker->volume;
+ SpiceVolumeState *st = &client->worker->volume;
- if (!red_channel_client_test_remote_cap(channel->channel_client, cap)) {
+ if (!red_channel_client_test_remote_cap(client->channel_client, cap)) {
return TRUE;
}
- if (!snd_reset_send_data(channel, msg)) {
+ if (!snd_reset_send_data(client, msg)) {
return FALSE;
}
mute.mute = st->mute;
- spice_marshall_SpiceMsgAudioMute(channel->send_data.marshaller, &mute);
+ spice_marshall_SpiceMsgAudioMute(client->send_data.marshaller, &mute);
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int snd_playback_send_mute(PlaybackChannelClient *playback_client)
@@ -623,53 +623,53 @@ static int snd_playback_send_mute(PlaybackChannelClient *playback_client)
static int snd_playback_send_latency(PlaybackChannelClient *playback_client)
{
- SndChannelClient *channel = &playback_client->base;
+ SndChannelClient *client = &playback_client->base;
SpiceMsgPlaybackLatency latency_msg;
spice_debug("latency %u", playback_client->latency);
- if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_LATENCY)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_LATENCY)) {
return FALSE;
}
latency_msg.latency_ms = playback_client->latency;
- spice_marshall_msg_playback_latency(channel->send_data.marshaller, &latency_msg);
+ spice_marshall_msg_playback_latency(client->send_data.marshaller, &latency_msg);
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int snd_playback_send_start(PlaybackChannelClient *playback_client)
{
- SndChannelClient *channel = (SndChannelClient *)playback_client;
+ SndChannelClient *client = (SndChannelClient *)playback_client;
SpiceMsgPlaybackStart start;
- if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_START)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_START)) {
return FALSE;
}
start.channels = SPICE_INTERFACE_PLAYBACK_CHAN;
- start.frequency = channel->worker->frequency;
+ start.frequency = client->worker->frequency;
spice_assert(SPICE_INTERFACE_PLAYBACK_FMT == SPICE_INTERFACE_AUDIO_FMT_S16);
start.format = SPICE_AUDIO_FMT_S16;
start.time = reds_get_mm_time();
- spice_marshall_msg_playback_start(channel->send_data.marshaller, &start);
+ spice_marshall_msg_playback_start(client->send_data.marshaller, &start);
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int snd_playback_send_stop(PlaybackChannelClient *playback_client)
{
- SndChannelClient *channel = (SndChannelClient *)playback_client;
+ SndChannelClient *client = (SndChannelClient *)playback_client;
- if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_STOP)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_STOP)) {
return FALSE;
}
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int snd_playback_send_ctl(PlaybackChannelClient *playback_client)
{
- SndChannelClient *channel = (SndChannelClient *)playback_client;
+ SndChannelClient *client = (SndChannelClient *)playback_client;
- if ((channel->client_active = channel->active)) {
+ if ((client->client_active = client->active)) {
return snd_playback_send_start(playback_client);
} else {
return snd_playback_send_stop(playback_client);
@@ -678,38 +678,38 @@ static int snd_playback_send_ctl(PlaybackChannelClient *playback_client)
static int snd_record_send_start(RecordChannelClient *record_client)
{
- SndChannelClient *channel = (SndChannelClient *)record_client;
+ SndChannelClient *client = (SndChannelClient *)record_client;
SpiceMsgRecordStart start;
- if (!snd_reset_send_data(channel, SPICE_MSG_RECORD_START)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_RECORD_START)) {
return FALSE;
}
start.channels = SPICE_INTERFACE_RECORD_CHAN;
- start.frequency = channel->worker->frequency;
+ start.frequency = client->worker->frequency;
spice_assert(SPICE_INTERFACE_RECORD_FMT == SPICE_INTERFACE_AUDIO_FMT_S16);
start.format = SPICE_AUDIO_FMT_S16;
- spice_marshall_msg_record_start(channel->send_data.marshaller, &start);
+ spice_marshall_msg_record_start(client->send_data.marshaller, &start);
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int snd_record_send_stop(RecordChannelClient *record_client)
{
- SndChannelClient *channel = (SndChannelClient *)record_client;
+ SndChannelClient *client = (SndChannelClient *)record_client;
- if (!snd_reset_send_data(channel, SPICE_MSG_RECORD_STOP)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_RECORD_STOP)) {
return FALSE;
}
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int snd_record_send_ctl(RecordChannelClient *record_client)
{
- SndChannelClient *channel = (SndChannelClient *)record_client;
+ SndChannelClient *client = (SndChannelClient *)record_client;
- if ((channel->client_active = channel->active)) {
+ if ((client->client_active = client->active)) {
return snd_record_send_start(record_client);
} else {
return snd_record_send_stop(record_client);
@@ -739,21 +739,21 @@ static int snd_record_send_migrate(RecordChannelClient *record_client)
static int snd_playback_send_write(PlaybackChannelClient *playback_client)
{
- SndChannelClient *channel = (SndChannelClient *)playback_client;
+ SndChannelClient *client = (SndChannelClient *)playback_client;
AudioFrame *frame;
SpiceMsgPlaybackPacket msg;
- if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_DATA)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_DATA)) {
return FALSE;
}
frame = playback_client->in_progress;
msg.time = frame->time;
- spice_marshall_msg_playback_data(channel->send_data.marshaller, &msg);
+ spice_marshall_msg_playback_data(client->send_data.marshaller, &msg);
if (playback_client->mode == SPICE_AUDIO_DATA_MODE_RAW) {
- spice_marshaller_add_ref(channel->send_data.marshaller,
+ spice_marshaller_add_ref(client->send_data.marshaller,
(uint8_t *)frame->samples,
snd_codec_frame_size(playback_client->codec) * sizeof(frame->samples[0]));
}
@@ -763,80 +763,80 @@ static int snd_playback_send_write(PlaybackChannelClient *playback_client)
snd_codec_frame_size(playback_client->codec) * sizeof(frame->samples[0]),
playback_client->encode_buf, &n) != SND_CODEC_OK) {
spice_printerr("encode failed");
- snd_disconnect_channel(channel);
+ snd_disconnect_channel(client);
return FALSE;
}
- spice_marshaller_add_ref(channel->send_data.marshaller, playback_client->encode_buf, n);
+ spice_marshaller_add_ref(client->send_data.marshaller, playback_client->encode_buf, n);
}
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static int playback_send_mode(PlaybackChannelClient *playback_client)
{
- SndChannelClient *channel = (SndChannelClient *)playback_client;
+ SndChannelClient *client = (SndChannelClient *)playback_client;
SpiceMsgPlaybackMode mode;
- if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_MODE)) {
+ if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_MODE)) {
return FALSE;
}
mode.time = reds_get_mm_time();
mode.mode = playback_client->mode;
- spice_marshall_msg_playback_mode(channel->send_data.marshaller, &mode);
+ spice_marshall_msg_playback_mode(client->send_data.marshaller, &mode);
- return snd_begin_send_message(channel);
+ return snd_begin_send_message(client);
}
static void snd_playback_send(void* data)
{
PlaybackChannelClient *playback_client = (PlaybackChannelClient*)data;
- SndChannelClient *channel = (SndChannelClient*)playback_client;
+ SndChannelClient *client = (SndChannelClient*)playback_client;
if (!playback_client || !snd_send_data(data)) {
return;
}
- while (channel->command) {
- if (channel->command & SND_PLAYBACK_MODE_MASK) {
+ while (client->command) {
+ if (client->command & SND_PLAYBACK_MODE_MASK) {
if (!playback_send_mode(playback_client)) {
return;
}
- channel->command &= ~SND_PLAYBACK_MODE_MASK;
+ client->command &= ~SND_PLAYBACK_MODE_MASK;
}
- if (channel->command & SND_PLAYBACK_PCM_MASK) {
+ if (client->command & SND_PLAYBACK_PCM_MASK) {
spice_assert(!playback_client->in_progress && playback_client->pending_frame);
playback_client->in_progress = playback_client->pending_frame;
playback_client->pending_frame = NULL;
- channel->command &= ~SND_PLAYBACK_PCM_MASK;
+ client->command &= ~SND_PLAYBACK_PCM_MASK;
if (!snd_playback_send_write(playback_client)) {
spice_printerr("snd_send_playback_write failed");
return;
}
}
- if (channel->command & SND_CTRL_MASK) {
+ if (client->command & SND_CTRL_MASK) {
if (!snd_playback_send_ctl(playback_client)) {
return;
}
- channel->command &= ~SND_CTRL_MASK;
+ client->command &= ~SND_CTRL_MASK;
}
- if (channel->command & SND_VOLUME_MASK) {
+ if (client->command & SND_VOLUME_MASK) {
if (!snd_playback_send_volume(playback_client) ||
!snd_playback_send_mute(playback_client)) {
return;
}
- channel->command &= ~SND_VOLUME_MASK;
+ client->command &= ~SND_VOLUME_MASK;
}
- if (channel->command & SND_MIGRATE_MASK) {
+ if (client->command & SND_MIGRATE_MASK) {
if (!snd_playback_send_migrate(playback_client)) {
return;
}
- channel->command &= ~SND_MIGRATE_MASK;
+ client->command &= ~SND_MIGRATE_MASK;
}
- if (channel->command & SND_PLAYBACK_LATENCY_MASK) {
+ if (client->command & SND_PLAYBACK_LATENCY_MASK) {
if (!snd_playback_send_latency(playback_client)) {
return;
}
- channel->command &= ~SND_PLAYBACK_LATENCY_MASK;
+ client->command &= ~SND_PLAYBACK_LATENCY_MASK;
}
}
}
@@ -844,37 +844,37 @@ static void snd_playback_send(void* data)
static void snd_record_send(void* data)
{
RecordChannelClient *record_client = (RecordChannelClient*)data;
- SndChannelClient *channel = (SndChannelClient*)record_client;
+ SndChannelClient *client = (SndChannelClient*)record_client;
if (!record_client || !snd_send_data(data)) {
return;
}
- while (channel->command) {
- if (channel->command & SND_CTRL_MASK) {
+ while (client->command) {
+ if (client->command & SND_CTRL_MASK) {
if (!snd_record_send_ctl(record_client)) {
return;
}
- channel->command &= ~SND_CTRL_MASK;
+ client->command &= ~SND_CTRL_MASK;
}
- if (channel->command & SND_VOLUME_MASK) {
+ if (client->command & SND_VOLUME_MASK) {
if (!snd_record_send_volume(record_client) ||
!snd_record_send_mute(record_client)) {
return;
}
- channel->command &= ~SND_VOLUME_MASK;
+ client->command &= ~SND_VOLUME_MASK;
}
- if (channel->command & SND_MIGRATE_MASK) {
+ if (client->command & SND_MIGRATE_MASK) {
if (!snd_record_send_migrate(record_client)) {
return;
}
- channel->command &= ~SND_MIGRATE_MASK;
+ client->command &= ~SND_MIGRATE_MASK;
}
}
}
static SndChannelClient *__new_channel(SndChannel *worker, int size, uint32_t channel_id,
- RedClient *client,
+ RedClient *red_client,
RedsStream *stream,
int migrate,
snd_channel_send_messages_proc send_messages,
@@ -884,14 +884,14 @@ static SndChannelClient *__new_channel(SndChannel *worker, int size, uint32_t ch
uint32_t *common_caps, int num_common_caps,
uint32_t *caps, int num_caps)
{
- SndChannelClient *channel;
+ SndChannelClient *client;
int delay_val;
int flags;
#ifdef SO_PRIORITY
int priority;
#endif
int tos;
- MainChannelClient *mcc = red_client_get_main(client);
+ MainChannelClient *mcc = red_client_get_main(red_client);
RedsState *reds = red_channel_get_server(worker->base_channel);
spice_assert(stream);
@@ -929,39 +929,39 @@ static SndChannelClient *__new_channel(SndChannel *worker, int size, uint32_t ch
goto error1;
}
- spice_assert(size >= sizeof(*channel));
- channel = spice_malloc0(size);
- channel->refs = 1;
- channel->parser = spice_get_client_channel_parser(channel_id, NULL);
- channel->stream = stream;
- channel->worker = worker;
- channel->receive_data.message_start = channel->receive_data.buf;
- channel->receive_data.now = channel->receive_data.buf;
- channel->receive_data.end = channel->receive_data.buf + sizeof(channel->receive_data.buf);
- channel->send_data.marshaller = spice_marshaller_new();
+ spice_assert(size >= sizeof(*client));
+ client = spice_malloc0(size);
+ client->refs = 1;
+ client->parser = spice_get_client_channel_parser(channel_id, NULL);
+ client->stream = stream;
+ client->worker = worker;
+ client->receive_data.message_start = client->receive_data.buf;
+ client->receive_data.now = client->receive_data.buf;
+ client->receive_data.end = client->receive_data.buf + sizeof(client->receive_data.buf);
+ client->send_data.marshaller = spice_marshaller_new();
stream->watch = reds_core_watch_add(reds, stream->socket, SPICE_WATCH_EVENT_READ,
- snd_event, channel);
+ snd_event, client);
if (stream->watch == NULL) {
spice_printerr("watch_add failed, %s", strerror(errno));
goto error2;
}
- channel->send_messages = send_messages;
- channel->handle_message = handle_message;
- channel->on_message_done = on_message_done;
- channel->cleanup = cleanup;
+ client->send_messages = send_messages;
+ client->handle_message = handle_message;
+ client->on_message_done = on_message_done;
+ client->cleanup = cleanup;
- channel->channel_client =
- dummy_channel_client_create(worker->base_channel, client,
+ client->channel_client =
+ dummy_channel_client_create(worker->base_channel, red_client,
num_common_caps, common_caps, num_caps, caps);
- if (!channel->channel_client) {
+ if (!client->channel_client) {
goto error2;
}
- return channel;
+ return client;
error2:
- free(channel);
+ free(client);
error1:
reds_stream_free(stream);
@@ -986,12 +986,12 @@ static void snd_disconnect_channel_client(RedChannelClient *rcc)
}
}
-static void snd_set_command(SndChannelClient *channel, uint32_t command)
+static void snd_set_command(SndChannelClient *client, uint32_t command)
{
- if (!channel) {
+ if (!client) {
return;
}
- channel->command |= command;
+ client->command |= command;
}
SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *sin,
@@ -999,14 +999,14 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
uint16_t *volume)
{
SpiceVolumeState *st = &sin->st->worker.volume;
- SndChannelClient *channel = sin->st->worker.connection;
- PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(channel, PlaybackChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
st->volume_nchannels = nchannels;
free(st->volume);
st->volume = spice_memdup(volume, sizeof(uint16_t) * nchannels);
- if (!channel || nchannels == 0)
+ if (!client || nchannels == 0)
return;
snd_playback_send_volume(playback_client);
@@ -1015,12 +1015,12 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *sin, uint8_t mute)
{
SpiceVolumeState *st = &sin->st->worker.volume;
- SndChannelClient *channel = sin->st->worker.connection;
- PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(channel, PlaybackChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
st->mute = mute;
- if (!channel)
+ if (!client)
return;
snd_playback_send_mute(playback_client);
@@ -1028,19 +1028,19 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *si
static void snd_playback_start(SndChannel *worker)
{
- SndChannelClient *channel = worker->connection;
+ SndChannelClient *client = worker->connection;
worker->active = 1;
- if (!channel)
+ if (!client)
return;
- spice_assert(!channel->active);
- reds_disable_mm_time(snd_channel_get_server(channel));
- channel->active = TRUE;
- if (!channel->client_active) {
- snd_set_command(channel, SND_CTRL_MASK);
- snd_playback_send(channel);
+ spice_assert(!client->active);
+ reds_disable_mm_time(snd_channel_get_server(client));
+ client->active = TRUE;
+ if (!client->client_active) {
+ snd_set_command(client, SND_CTRL_MASK);
+ snd_playback_send(client);
} else {
- channel->command &= ~SND_CTRL_MASK;
+ client->command &= ~SND_CTRL_MASK;
}
}
@@ -1051,14 +1051,14 @@ SPICE_GNUC_VISIBLE void spice_server_playback_start(SpicePlaybackInstance *sin)
SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
{
- SndChannelClient *channel = sin->st->worker.connection;
- PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(channel, PlaybackChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
sin->st->worker.active = 0;
- if (!channel)
+ if (!client)
return;
spice_assert(playback_client->base.active);
- reds_enable_mm_time(snd_channel_get_server(channel));
+ reds_enable_mm_time(snd_channel_get_server(client));
playback_client->base.active = FALSE;
if (playback_client->base.client_active) {
snd_set_command(&playback_client->base, SND_CTRL_MASK);
@@ -1079,16 +1079,16 @@ SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
SPICE_GNUC_VISIBLE void spice_server_playback_get_buffer(SpicePlaybackInstance *sin,
uint32_t **frame, uint32_t *num_samples)
{
- SndChannelClient *channel = sin->st->worker.connection;
- PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(channel, PlaybackChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
- if (!channel || !playback_client->free_frames) {
+ if (!client || !playback_client->free_frames) {
*frame = NULL;
*num_samples = 0;
return;
}
spice_assert(playback_client->base.active);
- snd_channel_ref(channel);
+ snd_channel_ref(client);
*frame = playback_client->free_frames->samples;
playback_client->free_frames = playback_client->free_frames->next;
@@ -1101,12 +1101,12 @@ SPICE_GNUC_VISIBLE void spice_server_playback_put_samples(SpicePlaybackInstance
AudioFrame *frame;
frame = SPICE_CONTAINEROF(samples, AudioFrame, samples[0]);
- playback_client = frame->channel;
+ playback_client = frame->client;
spice_assert(playback_client);
if (!snd_channel_unref(&playback_client->base) ||
sin->st->worker.connection != &playback_client->base) {
- /* lost last reference, channel has been destroyed previously */
- spice_info("audio samples belong to a disconnected channel");
+ /* lost last reference, client has been destroyed previously */
+ spice_info("audio samples belong to a disconnected client");
return;
}
spice_assert(playback_client->base.active);
@@ -1178,12 +1178,12 @@ static void on_new_playback_channel(SndChannel *worker, SndChannelClient *snd_ch
}
}
-static void snd_playback_cleanup(SndChannelClient *channel)
+static void snd_playback_cleanup(SndChannelClient *client)
{
- PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(channel, PlaybackChannelClient, base);
+ PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
if (playback_client->base.active) {
- reds_enable_mm_time(snd_channel_get_server(channel));
+ reds_enable_mm_time(snd_channel_get_server(client));
}
snd_codec_destroy(&playback_client->codec);
@@ -1247,11 +1247,11 @@ static void snd_set_playback_peer(RedChannel *channel, RedClient *client, RedsSt
static void snd_record_migrate_channel_client(RedChannelClient *rcc)
{
SndChannel *worker;
- RedChannel *channel = red_channel_client_get_channel(rcc);
+ RedChannel *client = red_channel_client_get_channel(rcc);
spice_debug(NULL);
- spice_assert(channel);
- worker = (SndChannel *)g_object_get_data(G_OBJECT(channel), "sound-worker");
+ spice_assert(client);
+ worker = (SndChannel *)g_object_get_data(G_OBJECT(client), "sound-worker");
spice_assert(worker);
if (worker->connection) {
@@ -1266,14 +1266,14 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
uint16_t *volume)
{
SpiceVolumeState *st = &sin->st->worker.volume;
- SndChannelClient *channel = sin->st->worker.connection;
- RecordChannelClient *record_client = SPICE_CONTAINEROF(channel, RecordChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
st->volume_nchannels = nchannels;
free(st->volume);
st->volume = spice_memdup(volume, sizeof(uint16_t) * nchannels);
- if (!channel || nchannels == 0)
+ if (!client || nchannels == 0)
return;
snd_record_send_volume(record_client);
@@ -1282,12 +1282,12 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
SPICE_GNUC_VISIBLE void spice_server_record_set_mute(SpiceRecordInstance *sin, uint8_t mute)
{
SpiceVolumeState *st = &sin->st->worker.volume;
- SndChannelClient *channel = sin->st->worker.connection;
- RecordChannelClient *record_client = SPICE_CONTAINEROF(channel, RecordChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
st->mute = mute;
- if (!channel)
+ if (!client)
return;
snd_record_send_mute(record_client);
@@ -1295,21 +1295,21 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_mute(SpiceRecordInstance *sin, u
static void snd_record_start(SndChannel *worker)
{
- SndChannelClient *channel = worker->connection;
- RecordChannelClient *record_client = SPICE_CONTAINEROF(channel, RecordChannelClient, base);
+ SndChannelClient *client = worker->connection;
+ RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
worker->active = 1;
- if (!channel)
+ if (!client)
return;
- spice_assert(!channel->active);
+ spice_assert(!client->active);
record_client->read_pos = record_client->write_pos = 0; //todo: improve by
//stream generation
- channel->active = TRUE;
- if (!channel->client_active) {
- snd_set_command(channel, SND_CTRL_MASK);
- snd_record_send(channel);
+ client->active = TRUE;
+ if (!client->client_active) {
+ snd_set_command(client, SND_CTRL_MASK);
+ snd_record_send(client);
} else {
- channel->command &= ~SND_CTRL_MASK;
+ client->command &= ~SND_CTRL_MASK;
}
}
@@ -1320,11 +1320,11 @@ SPICE_GNUC_VISIBLE void spice_server_record_start(SpiceRecordInstance *sin)
SPICE_GNUC_VISIBLE void spice_server_record_stop(SpiceRecordInstance *sin)
{
- SndChannelClient *channel = sin->st->worker.connection;
- RecordChannelClient *record_client = SPICE_CONTAINEROF(channel, RecordChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
sin->st->worker.active = 0;
- if (!channel)
+ if (!client)
return;
spice_assert(record_client->base.active);
record_client->base.active = FALSE;
@@ -1339,13 +1339,13 @@ SPICE_GNUC_VISIBLE void spice_server_record_stop(SpiceRecordInstance *sin)
SPICE_GNUC_VISIBLE uint32_t spice_server_record_get_samples(SpiceRecordInstance *sin,
uint32_t *samples, uint32_t bufsize)
{
- SndChannelClient *channel = sin->st->worker.connection;
- RecordChannelClient *record_client = SPICE_CONTAINEROF(channel, RecordChannelClient, base);
+ SndChannelClient *client = sin->st->worker.connection;
+ RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
uint32_t read_pos;
uint32_t now;
uint32_t len;
- if (!channel)
+ if (!client)
return 0;
spice_assert(record_client->base.active);
@@ -1374,11 +1374,11 @@ SPICE_GNUC_VISIBLE uint32_t spice_server_record_get_samples(SpiceRecordInstance
return len;
}
-static uint32_t snd_get_best_rate(SndChannelClient *channel, uint32_t cap_opus)
+static uint32_t snd_get_best_rate(SndChannelClient *client, uint32_t cap_opus)
{
int client_can_opus = TRUE;
- if (channel) {
- client_can_opus = red_channel_client_test_remote_cap(channel->channel_client, cap_opus);
+ if (client) {
+ client_can_opus = red_channel_client_test_remote_cap(client->channel_client, cap_opus);
}
if (client_can_opus && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, SND_CODEC_ANY_FREQUENCY))
@@ -1389,10 +1389,10 @@ static uint32_t snd_get_best_rate(SndChannelClient *channel, uint32_t cap_opus)
static void snd_set_rate(SndChannel *worker, uint32_t frequency, uint32_t cap_opus)
{
- RedChannel *channel = worker->base_channel;
+ RedChannel *client = worker->base_channel;
worker->frequency = frequency;
- if (channel && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, frequency)) {
- red_channel_set_cap(channel, cap_opus);
+ if (client && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, frequency)) {
+ red_channel_set_cap(client, cap_opus);
}
}
@@ -1429,9 +1429,9 @@ static void on_new_record_channel(SndChannel *worker, SndChannelClient *snd_chan
}
}
-static void snd_record_cleanup(SndChannelClient *channel)
+static void snd_record_cleanup(SndChannelClient *client)
{
- RecordChannelClient *record_client = SPICE_CONTAINEROF(channel, RecordChannelClient, base);
+ RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
snd_codec_destroy(&record_client->codec);
}
--
2.7.4
More information about the Spice-devel
mailing list