2002-02-03 20:04:07 +00:00
|
|
|
/* GStreamer
|
2005-05-10 20:10:43 +00:00
|
|
|
* Copyright (C) <2005> Arwed v. Merkatz <v.merkatz@gmx.net>
|
|
|
|
*
|
|
|
|
* Roughly based on the gstreamer 0.8 esdsink plugin:
|
2001-12-20 23:13:50 +00:00
|
|
|
* Copyright (C) <2001> Richard Boulton <richard-gst@tartarus.org>
|
|
|
|
*
|
2005-05-10 20:10:43 +00:00
|
|
|
* esdsink.c: an EsounD audio sink
|
2001-12-20 23:13:50 +00:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-20 23:13:50 +00:00
|
|
|
#include "esdsink.h"
|
|
|
|
#include <esd.h>
|
2003-06-29 19:46:12 +00:00
|
|
|
#include <unistd.h>
|
2003-07-17 08:08:09 +00:00
|
|
|
#include <errno.h>
|
2001-12-20 23:13:50 +00:00
|
|
|
|
2004-01-23 15:34:50 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (esd_debug);
|
2004-01-23 15:37:12 +00:00
|
|
|
#define GST_CAT_DEFAULT esd_debug
|
2004-01-23 15:34:50 +00:00
|
|
|
|
2001-12-20 23:13:50 +00:00
|
|
|
/* elementfactory information */
|
|
|
|
static GstElementDetails esdsink_details = {
|
|
|
|
"Esound audio sink",
|
2002-04-20 21:42:51 +00:00
|
|
|
"Sink/Audio",
|
2001-12-20 23:13:50 +00:00
|
|
|
"Plays audio to an esound server",
|
2005-05-10 20:10:43 +00:00
|
|
|
"Arwed von Merkatz <v.merkatz@gmx.net>",
|
2001-12-20 23:13:50 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2006-03-21 18:12:59 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_HOST
|
2001-12-20 23:13:50 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
|
|
|
|
"signed = (boolean) TRUE, "
|
|
|
|
"width = (int) 16, "
|
2005-05-10 20:10:43 +00:00
|
|
|
"depth = (int) 16, "
|
|
|
|
"rate = (int) [ 1, MAX ], "
|
|
|
|
"channels = (int) [ 1, 2 ]; "
|
|
|
|
"audio/x-raw-int, "
|
|
|
|
"signed = (boolean) { true, false }, "
|
|
|
|
"width = (int) 8, "
|
|
|
|
"depth = (int) 8, "
|
|
|
|
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static void gst_esdsink_base_init (gpointer g_class);
|
2005-05-10 20:10:43 +00:00
|
|
|
static void gst_esdsink_class_init (GstEsdSinkClass * klass);
|
|
|
|
static void gst_esdsink_init (GstEsdSink * esdsink);
|
2006-03-21 18:12:59 +00:00
|
|
|
static void gst_esdsink_finalize (GObject * object);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
static GstCaps *gst_esdsink_getcaps (GstBaseSink * bsink);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-08 16:43:47 +00:00
|
|
|
static gboolean gst_esdsink_open (GstAudioSink * asink);
|
2005-05-10 20:10:43 +00:00
|
|
|
static gboolean gst_esdsink_close (GstAudioSink * asink);
|
2005-08-08 16:43:47 +00:00
|
|
|
static gboolean gst_esdsink_prepare (GstAudioSink * asink,
|
|
|
|
GstRingBufferSpec * spec);
|
|
|
|
static gboolean gst_esdsink_unprepare (GstAudioSink * asink);
|
2005-05-10 20:10:43 +00:00
|
|
|
static guint gst_esdsink_write (GstAudioSink * asink, gpointer data,
|
|
|
|
guint length);
|
|
|
|
static guint gst_esdsink_delay (GstAudioSink * asink);
|
|
|
|
static void gst_esdsink_reset (GstAudioSink * asink);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
static void gst_esdsink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_esdsink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2001-12-20 23:13:50 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-20 23:13:50 +00:00
|
|
|
GType
|
|
|
|
gst_esdsink_get_type (void)
|
|
|
|
{
|
|
|
|
static GType esdsink_type = 0;
|
|
|
|
|
|
|
|
if (!esdsink_type) {
|
|
|
|
static const GTypeInfo esdsink_info = {
|
2005-05-10 20:10:43 +00:00
|
|
|
sizeof (GstEsdSinkClass),
|
2003-11-01 15:28:33 +00:00
|
|
|
gst_esdsink_base_init,
|
2001-12-20 23:13:50 +00:00
|
|
|
NULL,
|
2005-05-10 20:10:43 +00:00
|
|
|
(GClassInitFunc) gst_esdsink_class_init,
|
2001-12-20 23:13:50 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2005-05-10 20:10:43 +00:00
|
|
|
sizeof (GstEsdSink),
|
2001-12-20 23:13:50 +00:00
|
|
|
0,
|
2005-05-10 20:10:43 +00:00
|
|
|
(GInstanceInitFunc) gst_esdsink_init,
|
2001-12-20 23:13:50 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
esdsink_type =
|
2005-07-10 12:52:20 +00:00
|
|
|
g_type_register_static (GST_TYPE_AUDIO_SINK, "GstEsdSink",
|
|
|
|
&esdsink_info, 0);
|
2001-12-20 23:13:50 +00:00
|
|
|
}
|
|
|
|
return esdsink_type;
|
|
|
|
}
|
|
|
|
|
2003-11-01 15:28:33 +00:00
|
|
|
static void
|
|
|
|
gst_esdsink_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&sink_factory));
|
2003-11-01 15:28:33 +00:00
|
|
|
gst_element_class_set_details (element_class, &esdsink_details);
|
|
|
|
}
|
|
|
|
|
2001-12-20 23:13:50 +00:00
|
|
|
static void
|
2005-05-10 20:10:43 +00:00
|
|
|
gst_esdsink_class_init (GstEsdSinkClass * klass)
|
2001-12-20 23:13:50 +00:00
|
|
|
{
|
2005-05-10 20:10:43 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
|
|
|
GstBaseAudioSinkClass *gstbaseaudiosink_class;
|
|
|
|
GstAudioSinkClass *gstaudiosink_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
|
|
|
gstbaseaudiosink_class = (GstBaseAudioSinkClass *) klass;
|
|
|
|
gstaudiosink_class = (GstAudioSinkClass *) klass;
|
|
|
|
|
2005-07-10 12:52:20 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_AUDIO_SINK);
|
2005-05-10 20:10:43 +00:00
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
gobject_class->finalize = gst_esdsink_finalize;
|
2005-05-10 20:10:43 +00:00
|
|
|
|
|
|
|
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_esdsink_getcaps);
|
|
|
|
|
|
|
|
gstaudiosink_class->open = GST_DEBUG_FUNCPTR (gst_esdsink_open);
|
|
|
|
gstaudiosink_class->close = GST_DEBUG_FUNCPTR (gst_esdsink_close);
|
2005-08-08 16:43:47 +00:00
|
|
|
gstaudiosink_class->prepare = GST_DEBUG_FUNCPTR (gst_esdsink_prepare);
|
|
|
|
gstaudiosink_class->unprepare = GST_DEBUG_FUNCPTR (gst_esdsink_unprepare);
|
2005-05-10 20:10:43 +00:00
|
|
|
gstaudiosink_class->write = GST_DEBUG_FUNCPTR (gst_esdsink_write);
|
|
|
|
gstaudiosink_class->delay = GST_DEBUG_FUNCPTR (gst_esdsink_delay);
|
|
|
|
gstaudiosink_class->reset = GST_DEBUG_FUNCPTR (gst_esdsink_reset);
|
2001-12-20 23:13:50 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_esdsink_set_property;
|
|
|
|
gobject_class->get_property = gst_esdsink_get_property;
|
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
/* default value is filled in the _init method */
|
|
|
|
g_object_class_install_property (gobject_class, PROP_HOST,
|
|
|
|
g_param_spec_string ("host", "Host",
|
|
|
|
"The host running the esound daemon", NULL, G_PARAM_READWRITE));
|
2001-12-20 23:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-05-10 20:10:43 +00:00
|
|
|
gst_esdsink_init (GstEsdSink * esdsink)
|
2001-12-20 23:13:50 +00:00
|
|
|
{
|
|
|
|
esdsink->fd = -1;
|
2005-05-10 20:10:43 +00:00
|
|
|
esdsink->ctrl_fd = -1;
|
2006-03-21 18:12:59 +00:00
|
|
|
esdsink->host = g_strdup (g_getenv ("ESPEAKER"));
|
2001-12-20 23:13:50 +00:00
|
|
|
}
|
|
|
|
|
Fixes: #151879, #151881, #151882, #151883, #151884, #151886, #151887, #152102, #152247.
Original commit message from CVS:
Fixes: #151879, #151881, #151882, #151883, #151884, #151886,
#151887, #152102, #152247.
* examples/indexing/indexmpeg.c: 64-bit warning fixes.
* examples/seeking/cdparanoia.c: same
* examples/seeking/cdplayer.c: same
* examples/seeking/seek.c: same
* examples/seeking/spider_seek.c: same
* examples/seeking/vorbisfile.c: same
* examples/stats/mp2ogg.c: same
* ext/esd/esdsink.c: (gst_esdsink_class_init),
(gst_esdsink_dispose): Dispose of element properly.
* ext/ivorbis/vorbisfile.c: (gst_ivorbisfile_seek): 64-bit warning
fixes.
* ext/nas/nassink.c: (gst_nassink_class_init),
(gst_nassink_dispose): Dispose of element correctly.
* gst/wavenc/gstwavenc.c: (gst_wavenc_chain): Fix leak.
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new), (gst_ximagesink_ximage_destroy):
Fix 64-bit warning.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_destroy):
Fix 64-bit warning.
2004-09-12 22:57:26 +00:00
|
|
|
static void
|
2006-03-21 18:12:59 +00:00
|
|
|
gst_esdsink_finalize (GObject * object)
|
Fixes: #151879, #151881, #151882, #151883, #151884, #151886, #151887, #152102, #152247.
Original commit message from CVS:
Fixes: #151879, #151881, #151882, #151883, #151884, #151886,
#151887, #152102, #152247.
* examples/indexing/indexmpeg.c: 64-bit warning fixes.
* examples/seeking/cdparanoia.c: same
* examples/seeking/cdplayer.c: same
* examples/seeking/seek.c: same
* examples/seeking/spider_seek.c: same
* examples/seeking/vorbisfile.c: same
* examples/stats/mp2ogg.c: same
* ext/esd/esdsink.c: (gst_esdsink_class_init),
(gst_esdsink_dispose): Dispose of element properly.
* ext/ivorbis/vorbisfile.c: (gst_ivorbisfile_seek): 64-bit warning
fixes.
* ext/nas/nassink.c: (gst_nassink_class_init),
(gst_nassink_dispose): Dispose of element correctly.
* gst/wavenc/gstwavenc.c: (gst_wavenc_chain): Fix leak.
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new), (gst_ximagesink_ximage_destroy):
Fix 64-bit warning.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_destroy):
Fix 64-bit warning.
2004-09-12 22:57:26 +00:00
|
|
|
{
|
2005-05-10 20:10:43 +00:00
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (object);
|
Fixes: #151879, #151881, #151882, #151883, #151884, #151886, #151887, #152102, #152247.
Original commit message from CVS:
Fixes: #151879, #151881, #151882, #151883, #151884, #151886,
#151887, #152102, #152247.
* examples/indexing/indexmpeg.c: 64-bit warning fixes.
* examples/seeking/cdparanoia.c: same
* examples/seeking/cdplayer.c: same
* examples/seeking/seek.c: same
* examples/seeking/spider_seek.c: same
* examples/seeking/vorbisfile.c: same
* examples/stats/mp2ogg.c: same
* ext/esd/esdsink.c: (gst_esdsink_class_init),
(gst_esdsink_dispose): Dispose of element properly.
* ext/ivorbis/vorbisfile.c: (gst_ivorbisfile_seek): 64-bit warning
fixes.
* ext/nas/nassink.c: (gst_nassink_class_init),
(gst_nassink_dispose): Dispose of element correctly.
* gst/wavenc/gstwavenc.c: (gst_wavenc_chain): Fix leak.
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new), (gst_ximagesink_ximage_destroy):
Fix 64-bit warning.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_destroy):
Fix 64-bit warning.
2004-09-12 22:57:26 +00:00
|
|
|
|
|
|
|
g_free (esdsink->host);
|
2004-11-01 11:02:31 +00:00
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
Fixes: #151879, #151881, #151882, #151883, #151884, #151886, #151887, #152102, #152247.
Original commit message from CVS:
Fixes: #151879, #151881, #151882, #151883, #151884, #151886,
#151887, #152102, #152247.
* examples/indexing/indexmpeg.c: 64-bit warning fixes.
* examples/seeking/cdparanoia.c: same
* examples/seeking/cdplayer.c: same
* examples/seeking/seek.c: same
* examples/seeking/spider_seek.c: same
* examples/seeking/vorbisfile.c: same
* examples/stats/mp2ogg.c: same
* ext/esd/esdsink.c: (gst_esdsink_class_init),
(gst_esdsink_dispose): Dispose of element properly.
* ext/ivorbis/vorbisfile.c: (gst_ivorbisfile_seek): 64-bit warning
fixes.
* ext/nas/nassink.c: (gst_nassink_class_init),
(gst_nassink_dispose): Dispose of element correctly.
* gst/wavenc/gstwavenc.c: (gst_wavenc_chain): Fix leak.
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new), (gst_ximagesink_ximage_destroy):
Fix 64-bit warning.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_destroy):
Fix 64-bit warning.
2004-09-12 22:57:26 +00:00
|
|
|
}
|
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_esdsink_getcaps (GstBaseSink * bsink)
|
|
|
|
{
|
2005-08-08 16:43:47 +00:00
|
|
|
GstEsdSink *esdsink;
|
|
|
|
GstPadTemplate *pad_template;
|
2005-05-10 20:10:43 +00:00
|
|
|
GstCaps *caps = NULL;
|
2005-08-08 17:27:28 +00:00
|
|
|
gint i;
|
2005-08-08 16:43:47 +00:00
|
|
|
esd_server_info_t *server_info;
|
|
|
|
|
|
|
|
esdsink = GST_ESDSINK (bsink);
|
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
GST_DEBUG_OBJECT (esdsink, "getcaps called");
|
|
|
|
|
2005-08-08 16:43:47 +00:00
|
|
|
pad_template = gst_static_pad_template_get (&sink_factory);
|
|
|
|
caps = gst_caps_copy (gst_pad_template_get_caps (pad_template));
|
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
/* no fd, we're done with the template caps */
|
|
|
|
if (esdsink->ctrl_fd < 0)
|
|
|
|
goto done;
|
2005-05-10 20:10:43 +00:00
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
/* get server info */
|
2005-05-10 20:10:43 +00:00
|
|
|
server_info = esd_get_server_info (esdsink->ctrl_fd);
|
2006-03-21 18:12:59 +00:00
|
|
|
if (!server_info)
|
|
|
|
goto no_info;
|
2005-05-10 20:10:43 +00:00
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
GST_DEBUG_OBJECT (esdsink, "got server info rate: %i", server_info->rate);
|
2005-08-08 17:27:28 +00:00
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
for (i = 0; i < caps->structs->len; i++) {
|
|
|
|
GstStructure *s;
|
|
|
|
|
|
|
|
s = gst_caps_get_structure (caps, i);
|
|
|
|
gst_structure_set (s, "rate", G_TYPE_INT, server_info->rate, NULL);
|
|
|
|
}
|
|
|
|
esd_free_server_info (server_info);
|
2005-08-08 17:27:28 +00:00
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
done:
|
|
|
|
return caps;
|
2005-08-08 17:27:28 +00:00
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
/* ERRORS */
|
|
|
|
no_info:
|
|
|
|
{
|
2005-08-08 16:43:47 +00:00
|
|
|
GST_WARNING_OBJECT (esdsink, "couldn't get server info!");
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_esdsink_open (GstAudioSink * asink)
|
|
|
|
{
|
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (asink);
|
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
GST_DEBUG_OBJECT (esdsink, "open");
|
|
|
|
|
2005-08-08 16:43:47 +00:00
|
|
|
esdsink->ctrl_fd = esd_open_sound (esdsink->host);
|
|
|
|
if (esdsink->ctrl_fd < 0)
|
|
|
|
goto couldnt_connect;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
/* ERRORS */
|
2005-08-08 16:43:47 +00:00
|
|
|
couldnt_connect:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (esdsink, RESOURCE, OPEN_WRITE, (NULL),
|
|
|
|
("can't open connection to esound server"));
|
|
|
|
return FALSE;
|
2005-05-10 20:10:43 +00:00
|
|
|
}
|
2001-12-20 23:13:50 +00:00
|
|
|
}
|
2003-07-17 08:08:09 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
static gboolean
|
2005-08-08 16:43:47 +00:00
|
|
|
gst_esdsink_close (GstAudioSink * asink)
|
|
|
|
{
|
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (asink);
|
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
GST_DEBUG_OBJECT (esdsink, "close");
|
|
|
|
|
2005-08-08 16:43:47 +00:00
|
|
|
esd_close (esdsink->ctrl_fd);
|
2006-03-21 18:12:59 +00:00
|
|
|
esdsink->ctrl_fd = -1;
|
2005-08-08 16:43:47 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_esdsink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec)
|
2003-07-17 08:08:09 +00:00
|
|
|
{
|
2005-05-10 20:10:43 +00:00
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (asink);
|
2006-03-23 20:12:47 +00:00
|
|
|
esd_format_t esdformat;
|
2003-07-17 08:08:09 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
/* Name used by esound for this connection. */
|
2005-12-16 21:57:51 +00:00
|
|
|
const char connname[] = "GStreamer";
|
2006-03-23 20:12:47 +00:00
|
|
|
guint latency;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (esdsink, "prepare");
|
2003-07-17 08:08:09 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
/* Bitmap describing audio format. */
|
2006-03-23 20:12:47 +00:00
|
|
|
esdformat = ESD_STREAM | ESD_PLAY;
|
2003-07-17 08:08:09 +00:00
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
switch (spec->depth) {
|
|
|
|
case 8:
|
|
|
|
esdformat |= ESD_BITS8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
esdformat |= ESD_BITS16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto unsupported_depth;
|
2005-05-10 20:10:43 +00:00
|
|
|
}
|
2003-07-04 07:32:19 +00:00
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
switch (spec->channels) {
|
|
|
|
case 1:
|
|
|
|
esdformat |= ESD_MONO;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
esdformat |= ESD_STEREO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto unsupported_channels;
|
2005-05-10 20:10:43 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
GST_INFO_OBJECT (esdsink,
|
|
|
|
"attempting to open data connection to esound server");
|
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
esdsink->fd =
|
|
|
|
esd_play_stream (esdformat, spec->rate, esdsink->host, connname);
|
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
if ((esdsink->fd < 0) || (esdsink->ctrl_fd < 0))
|
|
|
|
goto cannot_open;
|
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
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");
|
2006-03-21 18:12:59 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2006-03-23 20:12:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-03-21 18:12:59 +00:00
|
|
|
cannot_open:
|
|
|
|
{
|
2005-05-10 20:10:43 +00:00
|
|
|
GST_ELEMENT_ERROR (esdsink, RESOURCE, OPEN_WRITE, (NULL),
|
|
|
|
("can't open connection to esound server"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-07-04 07:32:19 +00:00
|
|
|
}
|
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
static gboolean
|
2005-08-08 16:43:47 +00:00
|
|
|
gst_esdsink_unprepare (GstAudioSink * asink)
|
2003-07-04 07:32:19 +00:00
|
|
|
{
|
2005-05-10 20:10:43 +00:00
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (asink);
|
2003-07-04 07:32:19 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
if ((esdsink->fd < 0) && (esdsink->ctrl_fd < 0))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
close (esdsink->fd);
|
|
|
|
esdsink->fd = -1;
|
2003-07-04 07:32:19 +00:00
|
|
|
|
2006-03-23 20:12:47 +00:00
|
|
|
GST_INFO_OBJECT (esdsink, "closed sound device");
|
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
return TRUE;
|
2003-07-04 07:32:19 +00:00
|
|
|
}
|
|
|
|
|
2001-12-20 23:13:50 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
static guint
|
|
|
|
gst_esdsink_write (GstAudioSink * asink, gpointer data, guint length)
|
|
|
|
{
|
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (asink);
|
|
|
|
gint to_write = 0;
|
2001-12-20 23:13:50 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
to_write = length;
|
2004-01-29 23:20:45 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
while (to_write > 0) {
|
|
|
|
int done;
|
2003-07-04 07:32:19 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
done = write (esdsink->fd, data, to_write);
|
2003-07-17 08:08:09 +00:00
|
|
|
|
2006-03-21 18:12:59 +00:00
|
|
|
if (done < 0)
|
|
|
|
goto write_error;
|
2005-05-10 20:10:43 +00:00
|
|
|
|
|
|
|
to_write -= done;
|
|
|
|
data += done;
|
2001-12-20 23:13:50 +00:00
|
|
|
}
|
2005-05-10 20:10:43 +00:00
|
|
|
return length;
|
2006-03-21 18:12:59 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
write_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (esdsink, RESOURCE, WRITE,
|
|
|
|
("Failed to write data to the esound daemon"), GST_ERROR_SYSTEM);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-05-10 20:10:43 +00:00
|
|
|
}
|
2003-07-17 08:08:09 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
static guint
|
|
|
|
gst_esdsink_delay (GstAudioSink * asink)
|
|
|
|
{
|
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (asink);
|
2006-03-23 20:12:47 +00:00
|
|
|
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);
|
2003-07-17 08:08:09 +00:00
|
|
|
|
2005-05-10 20:10:43 +00:00
|
|
|
return latency;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_esdsink_reset (GstAudioSink * asink)
|
|
|
|
{
|
2006-03-23 20:12:47 +00:00
|
|
|
GST_DEBUG_OBJECT (asink, "reset called");
|
2001-12-20 23:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdsink_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-20 23:13:50 +00:00
|
|
|
{
|
2005-05-10 20:10:43 +00:00
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (object);
|
2001-12-20 23:13:50 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2006-03-21 18:12:59 +00:00
|
|
|
case PROP_HOST:
|
2004-03-14 22:34:33 +00:00
|
|
|
g_free (esdsink->host);
|
2006-03-21 18:12:59 +00:00
|
|
|
esdsink->host = g_value_dup_string (value);
|
2001-12-20 23:13:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdsink_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-20 23:13:50 +00:00
|
|
|
{
|
2005-05-10 20:10:43 +00:00
|
|
|
GstEsdSink *esdsink = GST_ESDSINK (object);
|
2001-12-20 23:13:50 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2006-03-21 18:12:59 +00:00
|
|
|
case PROP_HOST:
|
2001-12-20 23:13:50 +00:00
|
|
|
g_value_set_string (value, esdsink->host);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-15 07:52:10 +00:00
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdsink_factory_init (GstPlugin * plugin)
|
2001-12-20 23:13:50 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_element_register (plugin, "esdsink", GST_RANK_NONE,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_ESDSINK))
|
2003-11-01 15:28:33 +00:00
|
|
|
return FALSE;
|
2001-12-20 23:13:50 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|