channel-playback: support SPICE_MSG_PLAYBACK_LATENCY

Add a new property for minimum playback latency. This property is
updated with the value from SPICE_MSG_PLAYBACK_LATENCY.
I also increased the default latency from 100ms to 200ms in order to
be more robust to different bandwidth settings.
The patch also updates spice-common submodule.
This commit is contained in:
Yonit Halperin 2013-02-19 10:46:00 -05:00
parent edf1daf508
commit d628f055e8
2 changed files with 32 additions and 1 deletions

View File

@ -57,6 +57,7 @@ struct _SpicePlaybackChannelPrivate {
guint8 mute;
gboolean is_active;
guint32 latency;
guint32 min_latency;
};
G_DEFINE_TYPE(SpicePlaybackChannel, spice_playback_channel, SPICE_TYPE_CHANNEL)
@ -67,6 +68,7 @@ enum {
PROP_NCHANNELS,
PROP_VOLUME,
PROP_MUTE,
PROP_MIN_LATENCY,
};
/* Signals */
@ -85,11 +87,14 @@ static void spice_playback_handle_msg(SpiceChannel *channel, SpiceMsgIn *msg);
/* ------------------------------------------------------------------ */
#define SPICE_PLAYBACK_DEFAULT_LATENCY_MS 200
static void spice_playback_channel_reset_capabilities(SpiceChannel *channel)
{
if (!g_getenv("SPICE_DISABLE_CELT"))
spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_PLAYBACK_CAP_CELT_0_5_1);
spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_PLAYBACK_CAP_VOLUME);
spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_PLAYBACK_CAP_LATENCY);
}
static void spice_playback_channel_init(SpicePlaybackChannel *channel)
@ -138,6 +143,9 @@ static void spice_playback_channel_get_property(GObject *gobject,
case PROP_MUTE:
g_value_set_boolean(value, c->mute);
break;
case PROP_MIN_LATENCY:
g_value_set_uint(value, c->min_latency);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
break;
@ -218,12 +226,21 @@ static void spice_playback_channel_class_init(SpicePlaybackChannelClass *klass)
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(gobject_class, PROP_MIN_LATENCY,
g_param_spec_uint("min-latency",
"Playback min buffer size (ms)",
"Playback min buffer size (ms)",
0, G_MAXUINT32, SPICE_PLAYBACK_DEFAULT_LATENCY_MS,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* SpicePlaybackChannel::playback-start:
* @channel: the #SpicePlaybackChannel that emitted the signal
* @format: a #SPICE_AUDIO_FMT
* @channels: number of channels
* @rate: audio rate
* @latency: minimum playback latency in ms
*
* Notify when the playback should start, and provide audio format
* characteristics.
@ -299,6 +316,7 @@ struct SPICE_PLAYBACK_START {
gint format;
gint channels;
gint frequency;
gint latency;
};
struct SPICE_PLAYBACK_DATA {
@ -419,6 +437,7 @@ static void playback_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
c->frame_count = 0;
c->last_time = start->time;
c->is_active = TRUE;
c->min_latency = SPICE_PLAYBACK_DEFAULT_LATENCY_MS;
switch (c->mode) {
case SPICE_AUDIO_DATA_MODE_RAW:
@ -487,6 +506,17 @@ static void playback_handle_set_mute(SpiceChannel *channel, SpiceMsgIn *in)
g_object_notify_main_context(G_OBJECT(channel), "mute");
}
/* coroutine context */
static void playback_handle_set_latency(SpiceChannel *channel, SpiceMsgIn *in)
{
SpicePlaybackChannelPrivate *c = SPICE_PLAYBACK_CHANNEL(channel)->priv;
SpiceMsgPlaybackLatency *msg = spice_msg_in_parsed(in);
c->min_latency = msg->latency_ms;
SPICE_DEBUG("%s: notify latency update %u", __FUNCTION__, c->min_latency);
g_object_notify_main_context(G_OBJECT(channel), "min-latency");
}
static const spice_msg_handler playback_handlers[] = {
[ SPICE_MSG_PLAYBACK_DATA ] = playback_handle_data,
[ SPICE_MSG_PLAYBACK_MODE ] = playback_handle_mode,
@ -494,6 +524,7 @@ static const spice_msg_handler playback_handlers[] = {
[ SPICE_MSG_PLAYBACK_STOP ] = playback_handle_stop,
[ SPICE_MSG_PLAYBACK_VOLUME ] = playback_handle_set_volume,
[ SPICE_MSG_PLAYBACK_MUTE ] = playback_handle_set_mute,
[ SPICE_MSG_PLAYBACK_LATENCY ] = playback_handle_set_latency,
};
/* coroutine context */

@ -1 +1 @@
Subproject commit 7cdf8de00a573b6bdb4ec4582c87aa79b25796d3
Subproject commit 30e84783cad7a5d4cd345367a267cafbfd0571af