ext/esd/esdsink.*: Fix esd choppy playback by configuring audiosink correctly. Fixes #325191

Original commit message from CVS:
* ext/esd/esdsink.c: (gst_esdsink_class_init),
(gst_esdsink_getcaps), (gst_esdsink_open), (gst_esdsink_close),
(gst_esdsink_prepare), (gst_esdsink_unprepare),
(gst_esdsink_delay), (gst_esdsink_reset):
* ext/esd/esdsink.h:
Fix esd choppy playback by configuring audiosink
correctly. Fixes #325191
This commit is contained in:
Wim Taymans 2006-03-23 20:12:47 +00:00
parent 38c2bcc170
commit 26aff02c8a
3 changed files with 85 additions and 21 deletions

View file

@ -1,3 +1,13 @@
2006-03-23 Wim Taymans <wim@fluendo.com>
* ext/esd/esdsink.c: (gst_esdsink_class_init),
(gst_esdsink_getcaps), (gst_esdsink_open), (gst_esdsink_close),
(gst_esdsink_prepare), (gst_esdsink_unprepare),
(gst_esdsink_delay), (gst_esdsink_reset):
* ext/esd/esdsink.h:
Fix esd choppy playback by configuring audiosink
correctly. Fixes #325191
2006-03-23 Tim-Philipp Müller <tim at centricular dot net> 2006-03-23 Tim-Philipp Müller <tim at centricular dot net>
* ext/libpng/gstpngdec.c: (gst_pngdec_change_state): * ext/libpng/gstpngdec.c: (gst_pngdec_change_state):

View file

@ -186,10 +186,10 @@ gst_esdsink_getcaps (GstBaseSink * bsink)
gint i; gint i;
esd_server_info_t *server_info; esd_server_info_t *server_info;
GST_DEBUG ("getcaps called");
esdsink = GST_ESDSINK (bsink); esdsink = GST_ESDSINK (bsink);
GST_DEBUG_OBJECT (esdsink, "getcaps called");
pad_template = gst_static_pad_template_get (&sink_factory); pad_template = gst_static_pad_template_get (&sink_factory);
caps = gst_caps_copy (gst_pad_template_get_caps (pad_template)); caps = gst_caps_copy (gst_pad_template_get_caps (pad_template));
@ -202,7 +202,7 @@ gst_esdsink_getcaps (GstBaseSink * bsink)
if (!server_info) if (!server_info)
goto no_info; goto no_info;
GST_DEBUG ("got server info rate: %i", server_info->rate); GST_DEBUG_OBJECT (esdsink, "got server info rate: %i", server_info->rate);
for (i = 0; i < caps->structs->len; i++) { for (i = 0; i < caps->structs->len; i++) {
GstStructure *s; GstStructure *s;
@ -229,6 +229,8 @@ gst_esdsink_open (GstAudioSink * asink)
{ {
GstEsdSink *esdsink = GST_ESDSINK (asink); GstEsdSink *esdsink = GST_ESDSINK (asink);
GST_DEBUG_OBJECT (esdsink, "open");
esdsink->ctrl_fd = esd_open_sound (esdsink->host); esdsink->ctrl_fd = esd_open_sound (esdsink->host);
if (esdsink->ctrl_fd < 0) if (esdsink->ctrl_fd < 0)
goto couldnt_connect; goto couldnt_connect;
@ -249,6 +251,8 @@ gst_esdsink_close (GstAudioSink * asink)
{ {
GstEsdSink *esdsink = GST_ESDSINK (asink); GstEsdSink *esdsink = GST_ESDSINK (asink);
GST_DEBUG_OBJECT (esdsink, "close");
esd_close (esdsink->ctrl_fd); esd_close (esdsink->ctrl_fd);
esdsink->ctrl_fd = -1; esdsink->ctrl_fd = -1;
@ -259,37 +263,78 @@ static gboolean
gst_esdsink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec) gst_esdsink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec)
{ {
GstEsdSink *esdsink = GST_ESDSINK (asink); GstEsdSink *esdsink = GST_ESDSINK (asink);
esd_format_t esdformat;
/* Name used by esound for this connection. */ /* Name used by esound for this connection. */
const char connname[] = "GStreamer"; const char connname[] = "GStreamer";
guint latency;
GST_DEBUG_OBJECT (esdsink, "prepare");
/* Bitmap describing audio format. */ /* Bitmap describing audio format. */
esd_format_t esdformat = ESD_STREAM | ESD_PLAY; esdformat = ESD_STREAM | ESD_PLAY;
if (spec->depth == 16) switch (spec->depth) {
esdformat |= ESD_BITS16; case 8:
else if (spec->depth == 8) { esdformat |= ESD_BITS8;
esdformat |= ESD_BITS8; break;
case 16:
esdformat |= ESD_BITS16;
break;
default:
goto unsupported_depth;
} }
if (spec->channels == 2) switch (spec->channels) {
esdformat |= ESD_STEREO; case 1:
else if (spec->channels == 1) { esdformat |= ESD_MONO;
esdformat |= ESD_MONO; break;
case 2:
esdformat |= ESD_STEREO;
break;
default:
goto unsupported_channels;
} }
GST_INFO ("attempting to open data connection to esound server"); GST_INFO_OBJECT (esdsink,
"attempting to open data connection to esound server");
esdsink->fd = esdsink->fd =
esd_play_stream (esdformat, spec->rate, esdsink->host, connname); esd_play_stream (esdformat, spec->rate, esdsink->host, connname);
if ((esdsink->fd < 0) || (esdsink->ctrl_fd < 0)) if ((esdsink->fd < 0) || (esdsink->ctrl_fd < 0))
goto cannot_open; goto cannot_open;
GST_INFO ("successfully opened connection to esound server"); esdsink->rate = spec->rate;
latency = esd_get_latency (esdsink->ctrl_fd);
latency = latency * 44100LL / esdsink->rate;
spec->segsize = 256 * spec->bytes_per_sample;
spec->segtotal = (latency / 256);
spec->silence_sample[0] = 0;
spec->silence_sample[1] = 0;
spec->silence_sample[2] = 0;
spec->silence_sample[3] = 0;
GST_INFO_OBJECT (esdsink, "successfully opened connection to esound server");
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
unsupported_depth:
{
GST_ELEMENT_ERROR (esdsink, STREAM, WRONG_TYPE, (NULL),
("can't handle sample depth of %d, only 8 or 16 supported",
spec->depth));
return FALSE;
}
unsupported_channels:
{
GST_ELEMENT_ERROR (esdsink, STREAM, WRONG_TYPE, (NULL),
("can't handle %d channels, only 1 or 2 supported", spec->channels));
return FALSE;
}
cannot_open: cannot_open:
{ {
GST_ELEMENT_ERROR (esdsink, RESOURCE, OPEN_WRITE, (NULL), GST_ELEMENT_ERROR (esdsink, RESOURCE, OPEN_WRITE, (NULL),
@ -309,7 +354,8 @@ gst_esdsink_unprepare (GstAudioSink * asink)
close (esdsink->fd); close (esdsink->fd);
esdsink->fd = -1; esdsink->fd = -1;
GST_INFO ("esdsink: closed sound device"); GST_INFO_OBJECT (esdsink, "closed sound device");
return TRUE; return TRUE;
} }
@ -348,16 +394,22 @@ static guint
gst_esdsink_delay (GstAudioSink * asink) gst_esdsink_delay (GstAudioSink * asink)
{ {
GstEsdSink *esdsink = GST_ESDSINK (asink); GstEsdSink *esdsink = GST_ESDSINK (asink);
guint latency = esd_get_latency (esdsink->ctrl_fd); guint latency;
latency = esd_get_latency (esdsink->ctrl_fd);
/* latency is measured in samples at a rate of 44100 */
latency = latency * 44100LL / esdsink->rate;
GST_DEBUG_OBJECT (asink, "got latency: %u", latency);
GST_DEBUG ("got latency: %u", latency);
return latency; return latency;
} }
static void static void
gst_esdsink_reset (GstAudioSink * asink) gst_esdsink_reset (GstAudioSink * asink)
{ {
GST_DEBUG ("reset called"); GST_DEBUG_OBJECT (asink, "reset called");
} }
static void static void

View file

@ -45,9 +45,11 @@ typedef struct _GstEsdSinkClass GstEsdSinkClass;
struct _GstEsdSink { struct _GstEsdSink {
GstAudioSink sink; GstAudioSink sink;
int fd; int fd;
int ctrl_fd; int ctrl_fd;
gchar *host; gchar *host;
guint rate;
}; };
struct _GstEsdSinkClass { struct _GstEsdSinkClass {