2000-12-29 05:38:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstaudiosink.c:
|
2000-01-30 09:03:00 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2000-02-27 23:18:38 +00:00
|
|
|
#include <sys/ioctl.h>
|
2000-01-30 09:03:00 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/soundcard.h>
|
2000-02-27 23:18:38 +00:00
|
|
|
#include <unistd.h>
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-09-07 20:35:15 +00:00
|
|
|
//#define DEBUG_ENABLED
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
#include <gstaudiosink.h>
|
|
|
|
#include <gst/meta/audioraw.h>
|
|
|
|
|
|
|
|
|
|
|
|
GstElementDetails gst_audiosink_details = {
|
|
|
|
"Audio Sink (OSS)",
|
|
|
|
"Sink/Audio",
|
|
|
|
"Output to a sound card via OSS",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void gst_audiosink_class_init (GstAudioSinkClass *klass);
|
|
|
|
static void gst_audiosink_init (GstAudioSink *audiosink);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static gboolean gst_audiosink_open_audio (GstAudioSink *sink);
|
|
|
|
static void gst_audiosink_close_audio (GstAudioSink *sink);
|
|
|
|
static GstElementStateReturn gst_audiosink_change_state (GstElement *element);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void gst_audiosink_set_arg (GtkObject *object, GtkArg *arg, guint id);
|
|
|
|
static void gst_audiosink_get_arg (GtkObject *object, GtkArg *arg, guint id);
|
2000-07-05 10:21:08 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void gst_audiosink_chain (GstPad *pad,GstBuffer *buf);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
/* AudioSink signals and args */
|
|
|
|
enum {
|
2000-07-05 10:21:08 +00:00
|
|
|
SIGNAL_HANDOFF,
|
2000-01-30 09:03:00 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
2000-07-05 10:21:08 +00:00
|
|
|
ARG_MUTE,
|
|
|
|
ARG_FORMAT,
|
|
|
|
ARG_CHANNELS,
|
|
|
|
ARG_FREQUENCY,
|
2000-01-30 09:03:00 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2000-12-13 19:29:35 +00:00
|
|
|
static GstPadFactory audiosink_sink_factory = {
|
|
|
|
"sink",
|
|
|
|
GST_PAD_FACTORY_SINK,
|
|
|
|
GST_PAD_FACTORY_ALWAYS,
|
2000-12-11 00:04:25 +00:00
|
|
|
"audio/raw",
|
|
|
|
"format", GST_PROPS_INT (AFMT_S16_LE),
|
|
|
|
"depth", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (8),
|
|
|
|
GST_PROPS_INT (16)
|
|
|
|
),
|
|
|
|
"rate", GST_PROPS_INT_RANGE (8000, 48000),
|
|
|
|
"channels", GST_PROPS_INT_RANGE (1, 2),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2000-10-11 19:30:07 +00:00
|
|
|
#define GST_TYPE_AUDIOSINK_FORMATS (gst_audiosink_formats_get_type())
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static GtkType
|
2000-10-11 19:30:07 +00:00
|
|
|
gst_audiosink_formats_get_type(void) {
|
|
|
|
static GtkType audiosink_formats_type = 0;
|
|
|
|
static GtkEnumValue audiosink_formats[] = {
|
|
|
|
{8, "8", "8 Bits"},
|
|
|
|
{16, "16", "16 Bits"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!audiosink_formats_type) {
|
|
|
|
audiosink_formats_type = gtk_type_register_enum("GstAudiosinkFormats", audiosink_formats);
|
|
|
|
}
|
|
|
|
return audiosink_formats_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_AUDIOSINK_CHANNELS (gst_audiosink_channels_get_type())
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static GtkType
|
2000-10-11 19:30:07 +00:00
|
|
|
gst_audiosink_channels_get_type(void) {
|
|
|
|
static GtkType audiosink_channels_type = 0;
|
|
|
|
static GtkEnumValue audiosink_channels[] = {
|
|
|
|
{1, "1", "Mono"},
|
|
|
|
{2, "2", "Stereo"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!audiosink_channels_type) {
|
|
|
|
audiosink_channels_type = gtk_type_register_enum("GstAudiosinkChannels", audiosink_channels);
|
|
|
|
}
|
|
|
|
return audiosink_channels_type;
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
2000-12-29 02:28:04 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2000-01-30 09:03:00 +00:00
|
|
|
static guint gst_audiosink_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2000-12-13 19:29:35 +00:00
|
|
|
static GstPadTemplate *gst_audiosink_sink_template;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
GtkType
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_audiosink_get_type (void)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
static GtkType audiosink_type = 0;
|
|
|
|
|
|
|
|
if (!audiosink_type) {
|
|
|
|
static const GtkTypeInfo audiosink_info = {
|
|
|
|
"GstAudioSink",
|
|
|
|
sizeof(GstAudioSink),
|
|
|
|
sizeof(GstAudioSinkClass),
|
|
|
|
(GtkClassInitFunc)gst_audiosink_class_init,
|
|
|
|
(GtkObjectInitFunc)gst_audiosink_init,
|
|
|
|
(GtkArgSetFunc)NULL,
|
|
|
|
(GtkArgGetFunc)NULL,
|
|
|
|
(GtkClassInitFunc)NULL,
|
|
|
|
};
|
2000-12-29 02:28:04 +00:00
|
|
|
audiosink_type = gtk_type_unique (GST_TYPE_ELEMENT, &audiosink_info);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return audiosink_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_audiosink_class_init (GstAudioSinkClass *klass)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GtkObjectClass *gtkobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gtkobject_class = (GtkObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
2000-12-29 02:28:04 +00:00
|
|
|
parent_class = gtk_type_class(GST_TYPE_ELEMENT);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
gtk_object_add_arg_type ("GstAudioSink::mute", GTK_TYPE_BOOL,
|
2000-07-05 10:21:08 +00:00
|
|
|
GTK_ARG_READWRITE, ARG_MUTE);
|
2000-11-25 14:18:47 +00:00
|
|
|
gtk_object_add_arg_type ("GstAudioSink::format", GST_TYPE_AUDIOSINK_FORMATS,
|
2000-07-05 10:21:08 +00:00
|
|
|
GTK_ARG_READWRITE, ARG_FORMAT);
|
2000-11-25 14:18:47 +00:00
|
|
|
gtk_object_add_arg_type ("GstAudioSink::channels", GST_TYPE_AUDIOSINK_CHANNELS,
|
2000-07-05 10:21:08 +00:00
|
|
|
GTK_ARG_READWRITE, ARG_CHANNELS);
|
2000-11-25 14:18:47 +00:00
|
|
|
gtk_object_add_arg_type ("GstAudioSink::frequency", GTK_TYPE_INT,
|
2000-07-05 10:21:08 +00:00
|
|
|
GTK_ARG_READWRITE, ARG_FREQUENCY);
|
|
|
|
|
|
|
|
gtkobject_class->set_arg = gst_audiosink_set_arg;
|
|
|
|
gtkobject_class->get_arg = gst_audiosink_get_arg;
|
|
|
|
|
|
|
|
gst_audiosink_signals[SIGNAL_HANDOFF] =
|
2000-01-30 09:03:00 +00:00
|
|
|
gtk_signal_new("handoff",GTK_RUN_LAST,gtkobject_class->type,
|
|
|
|
GTK_SIGNAL_OFFSET(GstAudioSinkClass,handoff),
|
2000-10-25 19:09:53 +00:00
|
|
|
gtk_marshal_NONE__NONE,GTK_TYPE_NONE,0);
|
2000-11-25 14:18:47 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
gtk_object_class_add_signals(gtkobject_class,gst_audiosink_signals,
|
|
|
|
LAST_SIGNAL);
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_audiosink_change_state;
|
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_audiosink_init (GstAudioSink *audiosink)
|
|
|
|
{
|
2000-12-13 19:29:35 +00:00
|
|
|
audiosink->sinkpad = gst_pad_new_from_template (gst_audiosink_sink_template, "sink");
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (audiosink), audiosink->sinkpad);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_pad_set_chain_function (audiosink->sinkpad, gst_audiosink_chain);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
audiosink->fd = -1;
|
2000-04-09 21:36:56 +00:00
|
|
|
audiosink->clock = gst_clock_get_system();
|
2000-12-25 01:33:06 +00:00
|
|
|
audiosink->format = 16;
|
|
|
|
audiosink->channels = 2;
|
|
|
|
audiosink->frequency = 44100;
|
2000-11-25 14:18:47 +00:00
|
|
|
|
|
|
|
gst_clock_register (audiosink->clock, GST_OBJECT (audiosink));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
GST_FLAG_SET (audiosink, GST_ELEMENT_THREAD_SUGGESTED);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_audiosink_sync_parms (GstAudioSink *audiosink)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
audio_buf_info ospace;
|
2000-04-09 21:36:56 +00:00
|
|
|
int frag;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (audiosink != NULL);
|
|
|
|
g_return_if_fail (GST_IS_AUDIOSINK (audiosink));
|
2000-09-27 19:33:10 +00:00
|
|
|
|
|
|
|
if (audiosink->fd == -1) return;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
ioctl (audiosink->fd,SNDCTL_DSP_RESET, 0);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
ioctl (audiosink->fd, SNDCTL_DSP_SETFMT, &audiosink->format);
|
|
|
|
ioctl (audiosink->fd, SNDCTL_DSP_CHANNELS, &audiosink->channels);
|
|
|
|
ioctl (audiosink->fd, SNDCTL_DSP_SPEED, &audiosink->frequency);
|
|
|
|
ioctl (audiosink->fd, SNDCTL_DSP_GETBLKSIZE, &frag);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
ioctl (audiosink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
g_print("audiosink: setting sound card to %dKHz %d bit %s (%d bytes buffer, %d fragment)\n",
|
2000-11-25 14:18:47 +00:00
|
|
|
audiosink->frequency, audiosink->format,
|
|
|
|
(audiosink->channels == 2) ? "stereo" : "mono", ospace.bytes, frag);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_audiosink_chain (GstPad *pad, GstBuffer *buf)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstAudioSink *audiosink;
|
|
|
|
MetaAudioRaw *meta;
|
2000-07-12 22:52:42 +00:00
|
|
|
gboolean in_flush;
|
|
|
|
audio_buf_info ospace;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-09-07 20:35:15 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
/* this has to be an audio buffer */
|
|
|
|
// g_return_if_fail(((GstMeta *)buf->meta)->type !=
|
|
|
|
//gst_audiosink_type_audio);
|
2000-11-25 14:18:47 +00:00
|
|
|
audiosink = GST_AUDIOSINK (pad->parent);
|
2000-01-30 09:03:00 +00:00
|
|
|
// g_return_if_fail(GST_FLAG_IS_SET(audiosink,GST_STATE_RUNNING));
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
if ((in_flush = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLUSH))) {
|
|
|
|
DEBUG ("audiosink: flush\n");
|
|
|
|
ioctl (audiosink->fd, SNDCTL_DSP_RESET, 0);
|
2000-07-12 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
meta = (MetaAudioRaw *)gst_buffer_get_first_meta (buf);
|
2000-01-30 09:03:00 +00:00
|
|
|
if (meta != NULL) {
|
|
|
|
if ((meta->format != audiosink->format) ||
|
|
|
|
(meta->channels != audiosink->channels) ||
|
2000-11-25 14:18:47 +00:00
|
|
|
(meta->frequency != audiosink->frequency))
|
|
|
|
{
|
|
|
|
audiosink->format = meta->format;
|
|
|
|
audiosink->channels = meta->channels;
|
2000-01-30 09:03:00 +00:00
|
|
|
audiosink->frequency = meta->frequency;
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_audiosink_sync_parms (audiosink);
|
2000-04-09 21:36:56 +00:00
|
|
|
g_print("audiosink: sound device set to format %d, %d channels, %dHz\n",
|
2000-11-25 14:18:47 +00:00
|
|
|
audiosink->format, audiosink->channels, audiosink->frequency);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
gtk_signal_emit (GTK_OBJECT (audiosink), gst_audiosink_signals[SIGNAL_HANDOFF],
|
2000-01-30 09:03:00 +00:00
|
|
|
audiosink);
|
2000-09-07 20:35:15 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
if (GST_BUFFER_DATA (buf) != NULL) {
|
|
|
|
gst_trace_add_entry(NULL, 0, buf, "audiosink: writing to soundcard");
|
2000-03-20 20:25:03 +00:00
|
|
|
//g_print("audiosink: writing to soundcard\n");
|
2000-04-09 21:36:56 +00:00
|
|
|
if (audiosink->fd > 2) {
|
2000-07-12 22:52:42 +00:00
|
|
|
if (!audiosink->mute) {
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_clock_wait (audiosink->clock, GST_BUFFER_TIMESTAMP (buf), GST_OBJECT (audiosink));
|
|
|
|
ioctl (audiosink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
|
|
|
|
DEBUG ("audiosink: (%d bytes buffer) %d %p %d\n", ospace.bytes,
|
|
|
|
audiosink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
|
|
|
write (audiosink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
2000-09-07 20:35:15 +00:00
|
|
|
//write(STDOUT_FILENO,GST_BUFFER_DATA(buf),GST_BUFFER_SIZE(buf));
|
2000-07-12 22:52:42 +00:00
|
|
|
}
|
2000-04-09 21:36:56 +00:00
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_buffer_unref (buf);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_audiosink_set_arg (GtkObject *object, GtkArg *arg, guint id)
|
|
|
|
{
|
2000-07-05 10:21:08 +00:00
|
|
|
GstAudioSink *audiosink;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIOSINK (object));
|
|
|
|
|
|
|
|
audiosink = GST_AUDIOSINK (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
switch(id) {
|
|
|
|
case ARG_MUTE:
|
2000-11-25 14:18:47 +00:00
|
|
|
audiosink->mute = GTK_VALUE_BOOL (*arg);
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
case ARG_FORMAT:
|
2000-11-25 14:18:47 +00:00
|
|
|
audiosink->format = GTK_VALUE_ENUM (*arg);
|
|
|
|
gst_audiosink_sync_parms (audiosink);
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
case ARG_CHANNELS:
|
2000-11-25 14:18:47 +00:00
|
|
|
audiosink->channels = GTK_VALUE_ENUM (*arg);
|
|
|
|
gst_audiosink_sync_parms (audiosink);
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
case ARG_FREQUENCY:
|
2000-11-25 14:18:47 +00:00
|
|
|
audiosink->frequency = GTK_VALUE_INT (*arg);
|
|
|
|
gst_audiosink_sync_parms (audiosink);
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_audiosink_get_arg (GtkObject *object, GtkArg *arg, guint id)
|
|
|
|
{
|
2000-07-05 10:21:08 +00:00
|
|
|
GstAudioSink *audiosink;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIOSINK (object));
|
|
|
|
|
|
|
|
audiosink = GST_AUDIOSINK (object);
|
2000-07-05 10:21:08 +00:00
|
|
|
|
|
|
|
switch(id) {
|
|
|
|
case ARG_MUTE:
|
2000-11-25 14:18:47 +00:00
|
|
|
GTK_VALUE_BOOL (*arg) = audiosink->mute;
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
case ARG_FORMAT:
|
2000-11-25 14:18:47 +00:00
|
|
|
GTK_VALUE_ENUM (*arg) = audiosink->format;
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
case ARG_CHANNELS:
|
2000-11-25 14:18:47 +00:00
|
|
|
GTK_VALUE_ENUM (*arg) = audiosink->channels;
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
case ARG_FREQUENCY:
|
2000-11-25 14:18:47 +00:00
|
|
|
GTK_VALUE_INT (*arg) = audiosink->frequency;
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audiosink_open_audio (GstAudioSink *sink)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (sink->fd == -1, FALSE);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_print ("audiosink: attempting to open sound device\n");
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
/* first try to open the sound card */
|
2000-11-25 14:18:47 +00:00
|
|
|
sink->fd = open("/dev/dsp", O_WRONLY);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
/* if we have it, set the default parameters and go have fun */
|
|
|
|
if (sink->fd > 0) {
|
|
|
|
/* set card state */
|
|
|
|
sink->format = AFMT_S16_LE;
|
|
|
|
sink->channels = 2; /* stereo */
|
|
|
|
sink->frequency = 44100;
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_audiosink_sync_parms (sink);
|
|
|
|
ioctl(sink->fd, SNDCTL_DSP_GETCAPS, &sink->caps);
|
2000-04-09 21:36:56 +00:00
|
|
|
|
|
|
|
g_print("audiosink: Capabilities\n");
|
2000-11-25 14:18:47 +00:00
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
if (sink->caps & DSP_CAP_DUPLEX) g_print("audiosink: Full duplex\n");
|
|
|
|
if (sink->caps & DSP_CAP_REALTIME) g_print("audiosink: Realtime\n");
|
|
|
|
if (sink->caps & DSP_CAP_BATCH) g_print("audiosink: Batch\n");
|
|
|
|
if (sink->caps & DSP_CAP_COPROC) g_print("audiosink: Has coprocessor\n");
|
|
|
|
if (sink->caps & DSP_CAP_TRIGGER) g_print("audiosink: Trigger\n");
|
|
|
|
if (sink->caps & DSP_CAP_MMAP) g_print("audiosink: Direct access\n");
|
2000-11-25 14:18:47 +00:00
|
|
|
|
2000-09-07 20:35:15 +00:00
|
|
|
g_print("audiosink: opened audio with fd=%d\n", sink->fd);
|
2000-11-25 14:18:47 +00:00
|
|
|
GST_FLAG_SET (sink, GST_AUDIOSINK_OPEN);
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_audiosink_close_audio (GstAudioSink *sink)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
if (sink->fd < 0) return;
|
|
|
|
|
|
|
|
close(sink->fd);
|
|
|
|
sink->fd = -1;
|
2000-11-25 14:18:47 +00:00
|
|
|
|
|
|
|
GST_FLAG_UNSET (sink, GST_AUDIOSINK_OPEN);
|
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
g_print("audiosink: closed sound device\n");
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_audiosink_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_AUDIOSINK (element), FALSE);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-21 03:57:51 +00:00
|
|
|
/* if going down into NULL state, close the file if it's open */
|
2000-11-25 14:18:47 +00:00
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_AUDIOSINK_OPEN))
|
|
|
|
gst_audiosink_close_audio (GST_AUDIOSINK (element));
|
2000-07-21 03:57:51 +00:00
|
|
|
/* otherwise (READY or higher) we need to open the sound card */
|
|
|
|
} else {
|
2000-11-25 14:18:47 +00:00
|
|
|
if (!GST_FLAG_IS_SET (element, GST_AUDIOSINK_OPEN)) {
|
|
|
|
if (!gst_audiosink_open_audio (GST_AUDIOSINK (element)))
|
2000-07-21 03:57:51 +00:00
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
2000-08-14 10:55:35 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
gboolean
|
|
|
|
gst_audiosink_factory_init (GstElementFactory *factory)
|
|
|
|
{
|
2000-12-13 19:29:35 +00:00
|
|
|
gst_audiosink_sink_template = gst_padtemplate_new (&audiosink_sink_factory);
|
|
|
|
gst_elementfactory_add_padtemplate (factory, gst_audiosink_sink_template);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|