[Spice-commits] 3 commits - server/sound.c
Frediano Ziglio
fziglio at kemper.freedesktop.org
Mon Nov 14 21:59:37 UTC 2016
server/sound.c | 131 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 65 insertions(+), 66 deletions(-)
New commits:
commit 1a68768415abaa1884808c79662c7b5d2f671f28
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Mon Nov 14 21:54:28 2016 +0000
sound: Remove sin field from SpicePlaybackState and SpiceRecordState
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index 1d071e7..6aa9e06 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -166,12 +166,10 @@ struct SndWorker {
struct SpicePlaybackState {
struct SndWorker worker;
- SpicePlaybackInstance *sin;
};
struct SpiceRecordState {
struct SndWorker worker;
- SpiceRecordInstance *sin;
};
typedef struct RecordChannel {
@@ -190,6 +188,8 @@ typedef struct RecordChannel {
static SndWorker *workers;
static void snd_receive(SndChannel *channel);
+static void snd_playback_start(SpicePlaybackState *st);
+static void snd_record_start(SpiceRecordState *st);
static SndChannel *snd_channel_ref(SndChannel *channel)
{
@@ -1035,25 +1035,29 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *si
snd_playback_send_mute(playback_channel);
}
-SPICE_GNUC_VISIBLE void spice_server_playback_start(SpicePlaybackInstance *sin)
+static void snd_playback_start(SpicePlaybackState *st)
{
- SndChannel *channel = sin->st->worker.connection;
- PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+ SndChannel *channel = st->worker.connection;
- sin->st->worker.active = 1;
+ st->worker.active = 1;
if (!channel)
return;
- spice_assert(!playback_channel->base.active);
+ spice_assert(!channel->active);
reds_disable_mm_time(snd_channel_get_server(channel));
- playback_channel->base.active = TRUE;
- if (!playback_channel->base.client_active) {
- snd_set_command(&playback_channel->base, SND_PLAYBACK_CTRL_MASK);
- snd_playback_send(&playback_channel->base);
+ channel->active = TRUE;
+ if (!channel->client_active) {
+ snd_set_command(channel, SND_PLAYBACK_CTRL_MASK);
+ snd_playback_send(channel);
} else {
- playback_channel->base.command &= ~SND_PLAYBACK_CTRL_MASK;
+ channel->command &= ~SND_PLAYBACK_CTRL_MASK;
}
}
+SPICE_GNUC_VISIBLE void spice_server_playback_start(SpicePlaybackInstance *sin)
+{
+ return snd_playback_start(sin->st);
+}
+
SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
{
SndChannel *channel = sin->st->worker.connection;
@@ -1245,7 +1249,7 @@ static void snd_set_playback_peer(RedChannel *channel, RedClient *client, RedsSt
}
if (worker->active) {
- spice_server_playback_start(st->sin);
+ snd_playback_start(st);
}
snd_playback_send(worker->connection);
}
@@ -1299,26 +1303,31 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_mute(SpiceRecordInstance *sin, u
snd_record_send_mute(record_channel);
}
-SPICE_GNUC_VISIBLE void spice_server_record_start(SpiceRecordInstance *sin)
+static void snd_record_start(SpiceRecordState *st)
{
- SndChannel *channel = sin->st->worker.connection;
+ SndChannel *channel = st->worker.connection;
RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
- sin->st->worker.active = 1;
+ st->worker.active = 1;
if (!channel)
return;
- spice_assert(!record_channel->base.active);
- record_channel->base.active = TRUE;
+ spice_assert(!channel->active);
record_channel->read_pos = record_channel->write_pos = 0; //todo: improve by
//stream generation
- if (!record_channel->base.client_active) {
- snd_set_command(&record_channel->base, SND_RECORD_CTRL_MASK);
- snd_record_send(&record_channel->base);
+ channel->active = TRUE;
+ if (!channel->client_active) {
+ snd_set_command(channel, SND_RECORD_CTRL_MASK);
+ snd_record_send(channel);
} else {
- record_channel->base.command &= ~SND_RECORD_CTRL_MASK;
+ channel->command &= ~SND_RECORD_CTRL_MASK;
}
}
+SPICE_GNUC_VISIBLE void spice_server_record_start(SpiceRecordInstance *sin)
+{
+ snd_record_start(sin->st);
+}
+
SPICE_GNUC_VISIBLE void spice_server_record_stop(SpiceRecordInstance *sin)
{
SndChannel *channel = sin->st->worker.connection;
@@ -1465,7 +1474,7 @@ static void snd_set_record_peer(RedChannel *channel, RedClient *client, RedsStre
on_new_record_channel(worker, &record_channel->base);
if (worker->active) {
- spice_server_record_start(st->sin);
+ snd_record_start(st);
}
snd_record_send(worker->connection);
}
@@ -1513,7 +1522,6 @@ void snd_attach_playback(RedsState *reds, SpicePlaybackInstance *sin)
ClientCbs client_cbs = { NULL, };
sin->st = spice_new0(SpicePlaybackState, 1);
- sin->st->sin = sin;
playback_worker = &sin->st->worker;
playback_worker->frequency = SND_CODEC_CELT_PLAYBACK_FREQ; /* Default to the legacy rate */
@@ -1543,7 +1551,6 @@ void snd_attach_record(RedsState *reds, SpiceRecordInstance *sin)
ClientCbs client_cbs = { NULL, };
sin->st = spice_new0(SpiceRecordState, 1);
- sin->st->sin = sin;
record_worker = &sin->st->worker;
record_worker->frequency = SND_CODEC_CELT_PLAYBACK_FREQ; /* Default to the legacy rate */
commit e4a1b5a9e64056872d08ca400eca1797341bb8f4
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Fri Nov 11 17:57:54 2016 +0000
sound: Reuse code for spice_server_get_best_{record,playback}_rate
These function were really similar.
Factor out a new snd_get_best_rate to avoid code duplication.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index 4f30713..1d071e7 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1375,14 +1375,11 @@ SPICE_GNUC_VISIBLE uint32_t spice_server_record_get_samples(SpiceRecordInstance
return len;
}
-SPICE_GNUC_VISIBLE uint32_t spice_server_get_best_playback_rate(SpicePlaybackInstance *sin)
+static uint32_t snd_get_best_rate(SndChannel *channel, uint32_t cap_opus)
{
int client_can_opus = TRUE;
- if (sin && sin->st->worker.connection) {
- SndChannel *channel = sin->st->worker.connection;
- PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
- client_can_opus = red_channel_client_test_remote_cap(playback_channel->base.channel_client,
- SPICE_PLAYBACK_CAP_OPUS);
+ if (channel) {
+ client_can_opus = red_channel_client_test_remote_cap(channel->channel_client, cap_opus);
}
if (client_can_opus && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, SND_CODEC_ANY_FREQUENCY))
@@ -1400,6 +1397,11 @@ static void snd_set_rate(SndWorker *worker, uint32_t frequency, uint32_t cap_opu
}
}
+SPICE_GNUC_VISIBLE uint32_t spice_server_get_best_playback_rate(SpicePlaybackInstance *sin)
+{
+ return snd_get_best_rate(sin ? sin->st->worker.connection : NULL, SPICE_PLAYBACK_CAP_OPUS);
+}
+
SPICE_GNUC_VISIBLE void spice_server_set_playback_rate(SpicePlaybackInstance *sin, uint32_t frequency)
{
snd_set_rate(&sin->st->worker, frequency, SPICE_PLAYBACK_CAP_OPUS);
@@ -1407,18 +1409,7 @@ SPICE_GNUC_VISIBLE void spice_server_set_playback_rate(SpicePlaybackInstance *si
SPICE_GNUC_VISIBLE uint32_t spice_server_get_best_record_rate(SpiceRecordInstance *sin)
{
- int client_can_opus = TRUE;
- if (sin && sin->st->worker.connection) {
- SndChannel *channel = sin->st->worker.connection;
- RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
- client_can_opus = red_channel_client_test_remote_cap(record_channel->base.channel_client,
- SPICE_RECORD_CAP_OPUS);
- }
-
- if (client_can_opus && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, SND_CODEC_ANY_FREQUENCY))
- return SND_CODEC_OPUS_PLAYBACK_FREQ;
-
- return SND_CODEC_CELT_PLAYBACK_FREQ;
+ return snd_get_best_rate(sin ? sin->st->worker.connection : NULL, SPICE_RECORD_CAP_OPUS);
}
SPICE_GNUC_VISIBLE void spice_server_set_record_rate(SpiceRecordInstance *sin, uint32_t frequency)
commit 20c984d769a44500db03c57c96985b9beaf993ba
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Fri Nov 11 15:08:38 2016 +0000
sound: Move frequency field to SndWorker
This field is common to SpicePlaybackState and SpiceRecordState
which are based on SndWorker.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index ccdfc10..4f30713 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -161,18 +161,17 @@ struct SndWorker {
int active;
SpiceVolumeState volume;
+ uint32_t frequency;
};
struct SpicePlaybackState {
struct SndWorker worker;
SpicePlaybackInstance *sin;
- uint32_t frequency;
};
struct SpiceRecordState {
struct SndWorker worker;
SpiceRecordInstance *sin;
- uint32_t frequency;
};
typedef struct RecordChannel {
@@ -394,11 +393,12 @@ static int snd_record_handle_message(SndChannel *channel, size_t size, uint32_t
return snd_record_handle_write((RecordChannel *)channel, size, message);
case SPICE_MSGC_RECORD_MODE: {
SpiceMsgcRecordMode *mode = (SpiceMsgcRecordMode *)message;
- SpiceRecordState *st = SPICE_CONTAINEROF(channel->worker, SpiceRecordState, worker);
+ SndWorker *worker = channel->worker;
record_channel->mode_time = mode->time;
if (mode->mode != SPICE_AUDIO_DATA_MODE_RAW) {
- if (snd_codec_is_capable(mode->mode, st->frequency)) {
- if (snd_codec_create(&record_channel->codec, mode->mode, st->frequency, SND_CODEC_DECODE) == SND_CODEC_OK) {
+ if (snd_codec_is_capable(mode->mode, worker->frequency)) {
+ if (snd_codec_create(&record_channel->codec, mode->mode, worker->frequency,
+ SND_CODEC_DECODE) == SND_CODEC_OK) {
record_channel->mode = mode->mode;
} else {
spice_printerr("create decoder failed");
@@ -647,7 +647,6 @@ static int snd_playback_send_latency(PlaybackChannel *playback_channel)
static int snd_playback_send_start(PlaybackChannel *playback_channel)
{
SndChannel *channel = (SndChannel *)playback_channel;
- SpicePlaybackState *st = SPICE_CONTAINEROF(channel->worker, SpicePlaybackState, worker);
SpiceMsgPlaybackStart start;
if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_START)) {
@@ -655,7 +654,7 @@ static int snd_playback_send_start(PlaybackChannel *playback_channel)
}
start.channels = SPICE_INTERFACE_PLAYBACK_CHAN;
- start.frequency = st->frequency;
+ start.frequency = channel->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();
@@ -689,7 +688,6 @@ static int snd_playback_send_ctl(PlaybackChannel *playback_channel)
static int snd_record_send_start(RecordChannel *record_channel)
{
SndChannel *channel = (SndChannel *)record_channel;
- SpiceRecordState *st = SPICE_CONTAINEROF(channel->worker, SpiceRecordState, worker);
SpiceMsgRecordStart start;
if (!snd_reset_send_data(channel, SPICE_MSG_RECORD_START)) {
@@ -697,7 +695,7 @@ static int snd_record_send_start(RecordChannel *record_channel)
}
start.channels = SPICE_INTERFACE_RECORD_CHAN;
- start.frequency = st->frequency;
+ start.frequency = channel->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);
@@ -1230,11 +1228,12 @@ static void snd_set_playback_peer(RedChannel *channel, RedClient *client, RedsSt
SPICE_PLAYBACK_CAP_OPUS);
int playback_compression =
reds_config_get_playback_compression(red_channel_get_server(channel));
- int desired_mode = snd_desired_audio_mode(playback_compression, st->frequency,
+ int desired_mode = snd_desired_audio_mode(playback_compression, worker->frequency,
client_can_celt, client_can_opus);
playback_channel->mode = SPICE_AUDIO_DATA_MODE_RAW;
if (desired_mode != SPICE_AUDIO_DATA_MODE_RAW) {
- if (snd_codec_create(&playback_channel->codec, desired_mode, st->frequency, SND_CODEC_ENCODE) == SND_CODEC_OK) {
+ if (snd_codec_create(&playback_channel->codec, desired_mode, worker->frequency,
+ SND_CODEC_ENCODE) == SND_CODEC_OK) {
playback_channel->mode = desired_mode;
} else {
spice_printerr("create encoder failed");
@@ -1392,12 +1391,18 @@ SPICE_GNUC_VISIBLE uint32_t spice_server_get_best_playback_rate(SpicePlaybackIns
return SND_CODEC_CELT_PLAYBACK_FREQ;
}
+static void snd_set_rate(SndWorker *worker, uint32_t frequency, uint32_t cap_opus)
+{
+ RedChannel *channel = 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);
+ }
+}
+
SPICE_GNUC_VISIBLE void spice_server_set_playback_rate(SpicePlaybackInstance *sin, uint32_t frequency)
{
- RedChannel *channel = sin->st->worker.base_channel;
- sin->st->frequency = frequency;
- if (channel && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, frequency))
- red_channel_set_cap(channel, SPICE_PLAYBACK_CAP_OPUS);
+ snd_set_rate(&sin->st->worker, frequency, SPICE_PLAYBACK_CAP_OPUS);
}
SPICE_GNUC_VISIBLE uint32_t spice_server_get_best_record_rate(SpiceRecordInstance *sin)
@@ -1418,10 +1423,7 @@ SPICE_GNUC_VISIBLE uint32_t spice_server_get_best_record_rate(SpiceRecordInstanc
SPICE_GNUC_VISIBLE void spice_server_set_record_rate(SpiceRecordInstance *sin, uint32_t frequency)
{
- RedChannel *channel = sin->st->worker.base_channel;
- sin->st->frequency = frequency;
- if (channel && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, frequency))
- red_channel_set_cap(channel, SPICE_RECORD_CAP_OPUS);
+ snd_set_rate(&sin->st->worker, frequency, SPICE_RECORD_CAP_OPUS);
}
static void on_new_record_channel(SndWorker *worker, SndChannel *snd_channel)
@@ -1522,7 +1524,7 @@ void snd_attach_playback(RedsState *reds, SpicePlaybackInstance *sin)
sin->st = spice_new0(SpicePlaybackState, 1);
sin->st->sin = sin;
playback_worker = &sin->st->worker;
- sin->st->frequency = SND_CODEC_CELT_PLAYBACK_FREQ; /* Default to the legacy rate */
+ playback_worker->frequency = SND_CODEC_CELT_PLAYBACK_FREQ; /* Default to the legacy rate */
// TODO: Make RedChannel base of worker? instead of assigning it to channel->data
channel = dummy_channel_new(reds, SPICE_CHANNEL_PLAYBACK, 0);
@@ -1552,7 +1554,7 @@ void snd_attach_record(RedsState *reds, SpiceRecordInstance *sin)
sin->st = spice_new0(SpiceRecordState, 1);
sin->st->sin = sin;
record_worker = &sin->st->worker;
- sin->st->frequency = SND_CODEC_CELT_PLAYBACK_FREQ; /* Default to the legacy rate */
+ record_worker->frequency = SND_CODEC_CELT_PLAYBACK_FREQ; /* Default to the legacy rate */
// TODO: Make RedChannel base of worker? instead of assigning it to channel->data
channel = dummy_channel_new(reds, SPICE_CHANNEL_RECORD, 0);
@@ -1617,12 +1619,11 @@ void snd_set_playback_compression(int on)
g_object_get(now->base_channel, "channel-type", &type, NULL);
if (type == SPICE_CHANNEL_PLAYBACK && now->connection) {
PlaybackChannel* playback = (PlaybackChannel*)now->connection;
- SpicePlaybackState *st = SPICE_CONTAINEROF(now, SpicePlaybackState, worker);
int client_can_celt = red_channel_client_test_remote_cap(playback->base.channel_client,
SPICE_PLAYBACK_CAP_CELT_0_5_1);
int client_can_opus = red_channel_client_test_remote_cap(playback->base.channel_client,
SPICE_PLAYBACK_CAP_OPUS);
- int desired_mode = snd_desired_audio_mode(on, st->frequency,
+ int desired_mode = snd_desired_audio_mode(on, now->frequency,
client_can_opus, client_can_celt);
if (playback->mode != desired_mode) {
playback->mode = desired_mode;
More information about the Spice-commits
mailing list