summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--configure.ac2
-rw-r--r--sys/sunaudio/gstsunaudio.c224
3 files changed, 209 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index f563cf35..89545561 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2004-05-20 David Schleef <ds@schleef.org>
+ * configure.ac: Minor cosmetic change to convince the buildbot to
+ reautogen.
+ * sys/sunaudio/gstsunaudio.c: (gst_sunaudiosink_class_init),
+ (gst_sunaudiosink_init), (gst_sunaudiosink_getcaps),
+ (gst_sunaudiosink_pad_link), (gst_sunaudiosink_chain),
+ (gst_sunaudiosink_setparams), (gst_sunaudiosink_open),
+ (gst_sunaudiosink_close), (gst_sunaudiosink_change_state),
+ (gst_sunaudiosink_set_property), (gst_sunaudiosink_get_property):
+ More hacking. Plays audio now.
+
+2004-05-20 David Schleef <ds@schleef.org>
+
* configure.ac:
* sys/Makefile.am:
diff --git a/configure.ac b/configure.ac
index 446da114..eba293a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -471,7 +471,7 @@ GST_CHECK_FEATURE(QCAM, [QuickCam], qcamsrc, [
dnl *** Sun Audio ***
translit(dnm, m, l) AM_CONDITIONAL(USE_SUNAUDIO, true)
-GST_CHECK_FEATURE(SUNAUDIO, [Sun Audio], sunaudiosrc, [
+GST_CHECK_FEATURE(SUNAUDIO, [Sun Audio], sunaudiosink, [
AC_CHECK_HEADER(sys/audioio.h, HAVE_SUNAUDIO="yes", HAVE_SUNAUDIO="no")
])
diff --git a/sys/sunaudio/gstsunaudio.c b/sys/sunaudio/gstsunaudio.c
index b725a64b..b5df9c70 100644
--- a/sys/sunaudio/gstsunaudio.c
+++ b/sys/sunaudio/gstsunaudio.c
@@ -24,9 +24,11 @@
#endif
#include <gst/gst.h>
+#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
+#include <sys/audioio.h>
#define GST_TYPE_SUNAUDIOSINK \
@@ -48,6 +50,16 @@ struct _GstSunAudioSink
GstElement element;
GstPad *sinkpad;
+
+ char *device;
+ int fd;
+ audio_device_t dev;
+ audio_info_t info;
+
+ int channels;
+ int width;
+ int rate;
+ int buffer_size;
};
struct _GstSunAudioSinkClass
@@ -61,8 +73,7 @@ GType gst_gst_sunaudiosink_get_type (void);
static GstElementDetails plugin_details = {
"SunAudioSink",
"Sink/Audio",
- "This element acts like identity, except that one can control how "
- "sunaudiosink works",
+ "Audio sink for Sun Audio devices",
"David A. Schleef <ds@schleef.org>",
};
@@ -75,20 +86,28 @@ enum
enum
{
- ARG_0
+ ARG_0,
+ ARG_DEVICE,
+ ARG_BUFFER_SIZE
};
static GstStaticPadTemplate gst_sunaudiosink_sink_factory =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS_ANY);
+ GST_STATIC_CAPS ("audio/x-raw-int, "
+ "endianness = (int) BYTE_ORDER, "
+ "signed = (boolean) { TRUE, FALSE }, "
+ "width = (int) { 8, 16 }, "
+ "depth = (int) { 8, 16 }, "
+ "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]")
+ );
static void gst_sunaudiosink_base_init (gpointer g_class);
static void gst_sunaudiosink_class_init (GstSunAudioSinkClass * klass);
static void gst_sunaudiosink_init (GstSunAudioSink * filter);
-//static GstCaps *gst_sunaudiosink_getcaps (GstPad * pad);
+static GstCaps *gst_sunaudiosink_getcaps (GstPad * pad);
static GstPadLinkReturn gst_sunaudiosink_pad_link (GstPad * pad,
const GstCaps * caps);
@@ -97,7 +116,10 @@ static void gst_sunaudiosink_set_property (GObject * object, guint prop_id,
static void gst_sunaudiosink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
+static gboolean gst_sunaudiosink_setparams (GstSunAudioSink * sunaudiosink);
static void gst_sunaudiosink_chain (GstPad * pad, GstData * _data);
+static GstElementStateReturn gst_sunaudiosink_change_state (GstElement *
+ element);
static GstElementClass *parent_class = NULL;
@@ -156,46 +178,69 @@ gst_sunaudiosink_class_init (GstSunAudioSinkClass * klass)
gobject_class->set_property = gst_sunaudiosink_set_property;
gobject_class->get_property = gst_sunaudiosink_get_property;
+
+ gstelement_class->change_state = gst_sunaudiosink_change_state;
+
+ g_object_class_install_property (gobject_class, ARG_DEVICE,
+ g_param_spec_string ("device", "Device", "Audio Device (/dev/audio)",
+ "/dev/audio", G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, ARG_BUFFER_SIZE,
+ g_param_spec_int ("buffer_size", "Buffer Size", "Buffer Size",
+ 1, G_MAXINT, 64, G_PARAM_READWRITE));
}
static void
-gst_sunaudiosink_init (GstSunAudioSink * filter)
+gst_sunaudiosink_init (GstSunAudioSink * sunaudiosink)
{
- filter->sinkpad =
+ sunaudiosink->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get
(&gst_sunaudiosink_sink_factory), "sink");
- //gst_pad_set_getcaps_function (filter->sinkpad, gst_sunaudiosink_getcaps);
- gst_pad_set_link_function (filter->sinkpad, gst_sunaudiosink_pad_link);
+ gst_pad_set_getcaps_function (sunaudiosink->sinkpad,
+ gst_sunaudiosink_getcaps);
+ gst_pad_set_link_function (sunaudiosink->sinkpad, gst_sunaudiosink_pad_link);
- gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
- gst_pad_set_chain_function (filter->sinkpad, gst_sunaudiosink_chain);
+ gst_element_add_pad (GST_ELEMENT (sunaudiosink), sunaudiosink->sinkpad);
+ gst_pad_set_chain_function (sunaudiosink->sinkpad, gst_sunaudiosink_chain);
+
+ sunaudiosink->buffer_size = 64;
+ sunaudiosink->device = g_strdup ("/dev/audio");
}
-#if 0
static GstCaps *
gst_sunaudiosink_getcaps (GstPad * pad)
{
GstSunAudioSink *sunaudiosink = GST_SUNAUDIOSINK (gst_pad_get_parent (pad));
- GstPad *otherpad;
GstCaps *caps;
- caps = gst_pad_get_allowed_caps (otherpad);
-
+ caps = gst_caps_from_string ("audio/x-raw-int, "
+ "endianness = (int) BYTE_ORDER, "
+ "signed = (boolean) TRUE, "
+ "width = (int) 16, "
+ "depth = (int) 16, " "rate = (int) 44100, " "channels = (int) 1");
GST_ERROR ("getcaps called on %" GST_PTR_FORMAT ", returning %"
GST_PTR_FORMAT, pad, caps);
return caps;
}
-#endif
static GstPadLinkReturn
gst_sunaudiosink_pad_link (GstPad * pad, const GstCaps * caps)
{
- //GstSunAudioSink *sunaudiosink = GST_SUNAUDIOSINK (gst_pad_get_parent (pad));
- //GstPad *otherpad;
+ GstSunAudioSink *sunaudiosink = GST_SUNAUDIOSINK (gst_pad_get_parent (pad));
GstPadLinkReturn ret;
+ GstStructure *structure;
+
+ structure = gst_caps_get_structure (caps, 0);
- ret = GST_PAD_LINK_REFUSED;
+ gst_structure_get_int (structure, "rate", &sunaudiosink->rate);
+ gst_structure_get_int (structure, "width", &sunaudiosink->width);
+ gst_structure_get_int (structure, "channels", &sunaudiosink->channels);
+
+ if (gst_sunaudiosink_setparams (sunaudiosink)) {
+ ret = GST_PAD_LINK_OK;
+ } else {
+ ret = GST_PAD_LINK_REFUSED;
+ }
GST_ERROR ("pad_link called on %" GST_PTR_FORMAT " with caps %"
GST_PTR_FORMAT ", returning %d", pad, caps, ret);
@@ -203,35 +248,152 @@ gst_sunaudiosink_pad_link (GstPad * pad, const GstCaps * caps)
}
static void
-gst_sunaudiosink_chain (GstPad * pad, GstData * _data)
+gst_sunaudiosink_chain (GstPad * pad, GstData * data)
+{
+ GstSunAudioSink *sunaudiosink = GST_SUNAUDIOSINK (gst_pad_get_parent (pad));
+ GstBuffer *buffer = GST_BUFFER (data);
+ int ret;
+
+ if (GST_IS_EVENT (data)) {
+ g_assert (0);
+ } else {
+ ret = write (sunaudiosink->fd, GST_BUFFER_DATA (buffer),
+ GST_BUFFER_SIZE (buffer));
+ if (ret != GST_BUFFER_SIZE (buffer)) {
+ GST_ELEMENT_ERROR (sunaudiosink, RESOURCE, WRITE, (NULL),
+ ("%s", strerror (errno)));
+ }
+ }
+
+ gst_data_unref (data);
+}
+
+static gboolean
+gst_sunaudiosink_setparams (GstSunAudioSink * sunaudiosink)
{
- //GstSunAudioSink *sunaudiosink = GST_SUNAUDIOSINK (gst_pad_get_parent (pad));
+ audio_info_t ainfo;
+ int ret;
+
+ AUDIO_INITINFO (&ainfo);
+
+ ainfo.play.sample_rate = sunaudiosink->rate;
+ ainfo.play.channels = sunaudiosink->channels;
+ ainfo.play.precision = sunaudiosink->width;
+ ainfo.play.encoding = AUDIO_ENCODING_LINEAR;
+ ainfo.play.port = AUDIO_SPEAKER;
+ ainfo.play.buffer_size = sunaudiosink->buffer_size;
+ ainfo.output_muted = 0;
+
+ ret = ioctl (sunaudiosink->fd, AUDIO_SETINFO, &ainfo);
+ if (ret == -1) {
+ GST_ELEMENT_ERROR (sunaudiosink, RESOURCE, SETTINGS, (NULL), ("%s",
+ strerror (errno)));
+ return FALSE;
+ }
+ return TRUE;
}
-#if 0
static gboolean
gst_sunaudiosink_open (GstSunAudioSink * sunaudiosink)
{
const char *file;
+ int fd, ret;
file = "/dev/audio";
+ fd = open (file, O_WRONLY);
+ if (fd == -1) {
+ /* FIXME error */
+ return FALSE;
+ }
+
+ sunaudiosink->fd = fd;
+
+ ret = ioctl (fd, AUDIO_GETDEV, &sunaudiosink->dev);
+ if (ret == -1) {
+ GST_ELEMENT_ERROR (sunaudiosink, RESOURCE, SETTINGS, (NULL), ("%s",
+ strerror (errno)));
+ return FALSE;
+ }
+
+ GST_INFO ("name %s", sunaudiosink->dev.name);
+ GST_INFO ("version %s", sunaudiosink->dev.version);
+ GST_INFO ("config %s", sunaudiosink->dev.config);
- return FALSE;
+ ret = ioctl (fd, AUDIO_GETINFO, &sunaudiosink->info);
+ if (ret == -1) {
+ GST_ELEMENT_ERROR (sunaudiosink, RESOURCE, SETTINGS, (NULL), ("%s",
+ strerror (errno)));
+ return FALSE;
+ }
+
+ GST_INFO ("monitor_gain %d", sunaudiosink->info.monitor_gain);
+ GST_INFO ("output_muted %d", sunaudiosink->info.output_muted);
+ GST_INFO ("hw_features %08x", sunaudiosink->info.hw_features);
+ GST_INFO ("sw_features %08x", sunaudiosink->info.sw_features);
+ GST_INFO ("sw_features_enabled %08x", sunaudiosink->info.sw_features_enabled);
+
+ return TRUE;
+}
+
+static void
+gst_sunaudiosink_close (GstSunAudioSink * sunaudiosink)
+{
+ close (sunaudiosink->fd);
+}
+
+static GstElementStateReturn
+gst_sunaudiosink_change_state (GstElement * element)
+{
+ GstSunAudioSink *sunaudiosink = GST_SUNAUDIOSINK (element);
+
+ switch (GST_STATE_TRANSITION (element)) {
+ case GST_STATE_NULL_TO_READY:
+ if (!gst_sunaudiosink_open (sunaudiosink)) {
+ return GST_STATE_FAILURE;
+ }
+ break;
+ case GST_STATE_READY_TO_PAUSED:
+ break;
+ case GST_STATE_PAUSED_TO_PLAYING:
+ break;
+ case GST_STATE_PLAYING_TO_PAUSED:
+ break;
+ case GST_STATE_PAUSED_TO_READY:
+ break;
+ case GST_STATE_READY_TO_NULL:
+ gst_sunaudiosink_close (sunaudiosink);
+ break;
+ }
+
+ if (GST_ELEMENT_CLASS (parent_class)->change_state)
+ return GST_ELEMENT_CLASS (parent_class)->change_state (element);
+
+ return GST_STATE_SUCCESS;
}
-#endif
static void
gst_sunaudiosink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
- GstSunAudioSink *filter;
+ GstSunAudioSink *sunaudiosink;
g_return_if_fail (GST_IS_SUNAUDIOSINK (object));
- filter = GST_SUNAUDIOSINK (object);
+ sunaudiosink = GST_SUNAUDIOSINK (object);
switch (prop_id) {
+ case ARG_DEVICE:
+ if (gst_element_get_state (GST_ELEMENT (sunaudiosink)) == GST_STATE_NULL) {
+ g_free (sunaudiosink->device);
+ sunaudiosink->device = g_strdup (g_value_get_string (value));
+ }
+ break;
+ case ARG_BUFFER_SIZE:
+ if (gst_element_get_state (GST_ELEMENT (sunaudiosink)) == GST_STATE_NULL) {
+ sunaudiosink->buffer_size = g_value_get_int (value);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -242,12 +404,18 @@ static void
gst_sunaudiosink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
- GstSunAudioSink *filter;
+ GstSunAudioSink *sunaudiosink;
g_return_if_fail (GST_IS_SUNAUDIOSINK (object));
- filter = GST_SUNAUDIOSINK (object);
+ sunaudiosink = GST_SUNAUDIOSINK (object);
switch (prop_id) {
+ case ARG_DEVICE:
+ g_value_set_string (value, sunaudiosink->device);
+ break;
+ case ARG_BUFFER_SIZE:
+ g_value_set_int (value, sunaudiosink->buffer_size);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;