2002-03-02 15:20:05 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2001,2002> Richard Boulton <richard-gst@tartarus.org>
|
|
|
|
*
|
|
|
|
* Based on example.c:
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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
|
2003-07-15 07:52:10 +00:00
|
|
|
#include "esdmon.h"
|
2002-03-02 15:20:05 +00:00
|
|
|
#include <esd.h>
|
2003-06-29 19:46:12 +00:00
|
|
|
#include <unistd.h>
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* elementfactory information */
|
Define GstElementDetails as const and also static (when defined as global)
Original commit message from CVS:
* ext/aalib/gstaasink.c:
* ext/annodex/gstcmmldec.c:
* ext/annodex/gstcmmlenc.c:
* ext/cairo/gsttextoverlay.c:
* ext/cairo/gsttimeoverlay.c:
* ext/cdio/gstcdiocddasrc.c:
* ext/dv/gstdvdec.c:
* ext/dv/gstdvdemux.c:
* ext/esd/esdmon.c:
* ext/esd/esdsink.c:
* ext/flac/gstflacenc.c:
* ext/flac/gstflactag.c:
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_base_init):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init):
* ext/gdk_pixbuf/pixbufscale.c:
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/jpeg/gstjpegdec.c:
* ext/jpeg/gstjpegenc.c:
* ext/jpeg/gstsmokedec.c:
* ext/jpeg/gstsmokeenc.c:
* ext/libcaca/gstcacasink.c:
* ext/libmng/gstmngdec.c:
* ext/libmng/gstmngenc.c:
* ext/libpng/gstpngdec.c:
* ext/libpng/gstpngenc.c:
* ext/mikmod/gstmikmod.c:
* ext/raw1394/gstdv1394src.c:
* ext/shout2/gstshout2.c: (gst_shout2send_init):
* ext/shout2/gstshout2.h:
* ext/speex/gstspeexdec.c:
* ext/speex/gstspeexenc.c:
* gst/alpha/gstalpha.c:
* gst/alpha/gstalphacolor.c:
* gst/apetag/gstapedemux.c:
* gst/auparse/gstauparse.c:
* gst/autodetect/gstautoaudiosink.c:
(gst_auto_audio_sink_base_init):
* gst/autodetect/gstautovideosink.c:
(gst_auto_video_sink_base_init):
* gst/avi/gstavidemux.c: (gst_avi_demux_base_init):
* gst/avi/gstavimux.c: (gst_avimux_base_init):
* gst/cutter/gstcutter.c:
* gst/debug/breakmydata.c:
* gst/debug/efence.c:
* gst/debug/gstnavigationtest.c:
* gst/debug/gstnavseek.c:
* gst/debug/negotiation.c:
* gst/debug/progressreport.c:
* gst/debug/testplugin.c:
* gst/effectv/gstaging.c:
* gst/effectv/gstdice.c:
* gst/effectv/gstedge.c:
* gst/effectv/gstquark.c:
* gst/effectv/gstrev.c:
* gst/effectv/gstshagadelic.c:
* gst/effectv/gstvertigo.c:
* gst/effectv/gstwarp.c:
* gst/flx/gstflxdec.c:
* gst/goom/gstgoom.c:
* gst/icydemux/gsticydemux.c:
* gst/id3demux/gstid3demux.c:
* gst/interleave/deinterleave.c:
* gst/interleave/interleave.c:
* gst/law/alaw-decode.c: (gst_alawdec_base_init):
* gst/law/alaw-encode.c: (gst_alawenc_base_init):
* gst/law/mulaw-decode.c: (gst_mulawdec_base_init):
* gst/law/mulaw-encode.c: (gst_mulawenc_base_init):
* gst/level/gstlevel.c:
* gst/matroska/matroska-demux.c: (gst_matroska_demux_base_init):
* gst/matroska/matroska-mux.c: (gst_matroska_mux_base_init):
* gst/median/gstmedian.c:
* gst/monoscope/gstmonoscope.c:
* gst/multipart/multipartdemux.c:
* gst/multipart/multipartmux.c:
* gst/oldcore/gstaggregator.c:
* gst/oldcore/gstfdsink.c:
* gst/oldcore/gstmd5sink.c:
* gst/oldcore/gstmultifilesrc.c:
* gst/oldcore/gstpipefilter.c:
* gst/oldcore/gstshaper.c:
* gst/oldcore/gststatistics.c:
* gst/rtp/gstasteriskh263.c:
* gst/rtp/gstrtpL16depay.c:
* gst/rtp/gstrtpL16pay.c:
* gst/rtp/gstrtpamrdepay.c:
* gst/rtp/gstrtpamrpay.c:
* gst/rtp/gstrtpdepay.c:
* gst/rtp/gstrtpgsmpay.c:
* gst/rtp/gstrtph263pay.c:
* gst/rtp/gstrtph263pdepay.c:
* gst/rtp/gstrtph263ppay.c:
* gst/rtp/gstrtpilbcdepay.c:
* gst/rtp/gstrtpmp4gpay.c:
* gst/rtp/gstrtpmp4vdepay.c:
* gst/rtp/gstrtpmp4vpay.c:
* gst/rtp/gstrtpmpadepay.c:
* gst/rtp/gstrtpmpapay.c:
* gst/rtp/gstrtppcmadepay.c:
* gst/rtp/gstrtppcmapay.c:
* gst/rtp/gstrtppcmudepay.c:
* gst/rtp/gstrtppcmupay.c:
* gst/rtp/gstrtpspeexdepay.c:
* gst/rtp/gstrtpspeexpay.c:
* gst/rtsp/gstrtpdec.c:
* gst/rtsp/gstrtspsrc.c:
* gst/smpte/gstsmpte.c:
* gst/udp/gstdynudpsink.c:
* gst/udp/gstmultiudpsink.c:
* gst/udp/gstudpsink.c:
* gst/udp/gstudpsrc.c:
* gst/videobox/gstvideobox.c:
* gst/videofilter/gstgamma.c: (gst_gamma_base_init):
* gst/videofilter/gstvideobalance.c:
* gst/videofilter/gstvideoflip.c:
* gst/videofilter/gstvideotemplate.c:
(gst_videotemplate_base_init):
* gst/videomixer/videomixer.c:
* gst/wavparse/gstwavparse.c: (gst_wavparse_base_init),
(gst_wavparse_class_init), (gst_wavparse_dispose),
(gst_wavparse_reset), (gst_wavparse_init),
(gst_wavparse_perform_seek), (gst_wavparse_peek_chunk_info),
(gst_wavparse_peek_chunk), (gst_wavparse_stream_headers),
(gst_wavparse_parse_stream_init), (gst_wavparse_send_event),
(gst_wavparse_add_src_pad), (gst_wavparse_stream_data),
(gst_wavparse_chain), (gst_wavparse_srcpad_event),
(gst_wavparse_sink_activate), (gst_wavparse_sink_activate_pull),
(gst_wavparse_change_state):
* gst/wavparse/gstwavparse.h:
* sys/oss/gstossmixerelement.c:
* sys/oss/gstosssink.c:
* sys/oss/gstosssrc.c:
* sys/osxaudio/gstosxaudioelement.c:
* sys/osxaudio/gstosxaudiosink.c:
* sys/osxaudio/gstosxaudiosrc.c:
* sys/sunaudio/gstsunaudiomixer.c:
* sys/sunaudio/gstsunaudiosink.c:
Define GstElementDetails as const and also static (when defined as
global)
2006-04-25 21:39:46 +00:00
|
|
|
static const GstElementDetails esdmon_details =
|
2006-03-30 15:37:05 +00:00
|
|
|
GST_ELEMENT_DETAILS ("Esound audio monitor",
|
|
|
|
"Source/Audio",
|
|
|
|
"Monitors audio from an esound server",
|
|
|
|
"Richard Boulton <richard-gst@tartarus.org>");
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
/* Signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-03-02 15:20:05 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-03-02 15:20:05 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_DEPTH,
|
|
|
|
ARG_BYTESPERREAD,
|
|
|
|
ARG_CUROFFSET,
|
|
|
|
ARG_CHANNELS,
|
|
|
|
ARG_RATE,
|
2004-05-21 23:28:57 +00:00
|
|
|
ARG_HOST
|
2002-03-02 15:20:05 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
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, "
|
|
|
|
"depth = (int) 16, "
|
|
|
|
"rate = [ 8000, 96000 ], "
|
|
|
|
"channels = [ 1, 2 ]; "
|
|
|
|
"audio/x-raw-int, "
|
|
|
|
"signed = (boolean) FALSE, "
|
|
|
|
"width = (int) 8, "
|
|
|
|
"depth = (int) 8, " "rate = [ 8000, 96000 ], " "channels = [ 1, 2 ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static void gst_esdmon_base_init (gpointer g_class);
|
|
|
|
static void gst_esdmon_class_init (gpointer g_class, gpointer class_data);
|
|
|
|
static void gst_esdmon_init (GTypeInstance * instance, gpointer g_class);
|
|
|
|
|
|
|
|
static gboolean gst_esdmon_open_audio (GstEsdmon * src);
|
|
|
|
static void gst_esdmon_close_audio (GstEsdmon * src);
|
2005-09-02 15:44:50 +00:00
|
|
|
static GstStateChangeReturn gst_esdmon_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean gst_esdmon_sync_parms (GstEsdmon * esdmon);
|
|
|
|
|
|
|
|
static GstData *gst_esdmon_get (GstPad * pad);
|
|
|
|
|
|
|
|
static void gst_esdmon_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_esdmon_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_ESDMON_DEPTHS (gst_esdmon_depths_get_type())
|
|
|
|
static GType
|
|
|
|
gst_esdmon_depths_get_type (void)
|
|
|
|
{
|
|
|
|
static GType esdmon_depths_type = 0;
|
2006-05-10 10:29:54 +00:00
|
|
|
static const GEnumValue esdmon_depths[] = {
|
2005-11-22 18:11:58 +00:00
|
|
|
{8, "8 Bits", "8"},
|
|
|
|
{16, "16 Bits", "16"},
|
2002-03-02 15:20:05 +00:00
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2002-03-02 15:20:05 +00:00
|
|
|
if (!esdmon_depths_type) {
|
2004-03-14 22:34:33 +00:00
|
|
|
esdmon_depths_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_enum_register_static ("GstEsdmonDepths", esdmon_depths);
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
return esdmon_depths_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_ESDMON_CHANNELS (gst_esdmon_channels_get_type())
|
|
|
|
static GType
|
|
|
|
gst_esdmon_channels_get_type (void)
|
|
|
|
{
|
|
|
|
static GType esdmon_channels_type = 0;
|
2006-05-10 10:29:54 +00:00
|
|
|
static const GEnumValue esdmon_channels[] = {
|
2005-11-22 18:11:58 +00:00
|
|
|
{1, "Mono", "mono"},
|
|
|
|
{2, "Stereo", "stereo"},
|
2002-03-02 15:20:05 +00:00
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2002-03-02 15:20:05 +00:00
|
|
|
if (!esdmon_channels_type) {
|
2004-03-14 22:34:33 +00:00
|
|
|
esdmon_channels_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_enum_register_static ("GstEsdmonChannels", esdmon_channels);
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
return esdmon_channels_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-03-02 15:20:05 +00:00
|
|
|
/*static guint gst_esdmon_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_esdmon_get_type (void)
|
|
|
|
{
|
|
|
|
static GType esdmon_type = 0;
|
|
|
|
|
|
|
|
if (!esdmon_type) {
|
|
|
|
static const GTypeInfo esdmon_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstEsdmonClass),
|
2003-11-01 15:28:33 +00:00
|
|
|
gst_esdmon_base_init,
|
2002-03-02 15:20:05 +00:00
|
|
|
NULL,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_esdmon_class_init,
|
2002-03-02 15:20:05 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstEsdmon),
|
2002-03-02 15:20:05 +00:00
|
|
|
0,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_esdmon_init,
|
2002-03-02 15:20:05 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
esdmon_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstEsdmon", &esdmon_info, 0);
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
return esdmon_type;
|
|
|
|
}
|
|
|
|
|
2003-11-01 15:28:33 +00:00
|
|
|
static void
|
|
|
|
gst_esdmon_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 (&src_factory));
|
2003-11-01 15:28:33 +00:00
|
|
|
gst_element_class_set_details (element_class, &esdmon_details);
|
|
|
|
}
|
|
|
|
|
2002-03-02 15:20:05 +00:00
|
|
|
static void
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_esdmon_class_init (gpointer g_class, gpointer class_data)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
parent_class = g_type_class_peek_parent (g_class);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_BYTESPERREAD, g_param_spec_ulong ("bytes_per_read", "bytes_per_read", "bytes_per_read", 0, G_MAXULONG, 0, G_PARAM_READWRITE)); /* CHECKME */
|
|
|
|
g_object_class_install_property (gobject_class, ARG_CUROFFSET, g_param_spec_ulong ("curoffset", "curoffset", "curoffset", 0, G_MAXULONG, 0, G_PARAM_READABLE)); /* CHECKME */
|
|
|
|
g_object_class_install_property (gobject_class, ARG_DEPTH, g_param_spec_enum ("depth", "depth", "depth", GST_TYPE_ESDMON_DEPTHS, 16, G_PARAM_READWRITE)); /* CHECKME! */
|
|
|
|
g_object_class_install_property (gobject_class, ARG_CHANNELS, g_param_spec_enum ("channels", "channels", "channels", GST_TYPE_ESDMON_CHANNELS, 2, G_PARAM_READWRITE)); /* CHECKME! */
|
|
|
|
g_object_class_install_property (gobject_class, ARG_RATE, g_param_spec_int ("frequency", "frequency", "frequency", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
|
|
|
|
g_object_class_install_property (gobject_class, ARG_HOST, g_param_spec_string ("host", "host", "host", NULL, G_PARAM_READWRITE)); /* CHECKME */
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_esdmon_set_property;
|
|
|
|
gobject_class->get_property = gst_esdmon_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_esdmon_change_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdmon_init (GTypeInstance * instance, gpointer g_class)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
GstEsdmon *esdmon = GST_ESDMON (instance);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
esdmon->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template
|
|
|
|
(GST_ELEMENT_GET_CLASS (esdmon), "src"), "src");
|
|
|
|
gst_pad_set_get_function (esdmon->srcpad, gst_esdmon_get);
|
2004-01-02 07:09:23 +00:00
|
|
|
gst_pad_use_explicit_caps (esdmon->srcpad);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (esdmon), esdmon->srcpad);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
esdmon->fd = -1;
|
|
|
|
/* FIXME: get default from somewhere better than just putting them inline. */
|
|
|
|
esdmon->depth = 16;
|
|
|
|
esdmon->channels = 2;
|
|
|
|
esdmon->frequency = 44100;
|
|
|
|
esdmon->host = NULL;
|
|
|
|
esdmon->bytes_per_read = 4096;
|
|
|
|
esdmon->curoffset = 0;
|
|
|
|
esdmon->basetime = 0;
|
2002-03-02 15:51:47 +00:00
|
|
|
esdmon->samples_since_basetime = 0;
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdmon_sync_parms (GstEsdmon * esdmon)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (esdmon != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ESDMON (esdmon), FALSE);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (esdmon->fd == -1)
|
|
|
|
return TRUE;
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
/* Need to set fd to use new parameters: only way to do this is to reopen. */
|
|
|
|
gst_esdmon_close_audio (esdmon);
|
|
|
|
return gst_esdmon_open_audio (esdmon);
|
|
|
|
}
|
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
static GstData *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdmon_get (GstPad * pad)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
|
|
|
GstEsdmon *esdmon;
|
|
|
|
GstBuffer *buf;
|
|
|
|
glong readbytes;
|
|
|
|
glong readsamples;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
esdmon = GST_ESDMON (gst_pad_get_parent (pad));
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("attempting to read something from esdmon");
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
buf = gst_buffer_new ();
|
|
|
|
g_return_val_if_fail (buf, NULL);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_DATA (buf) = (gpointer) g_malloc (esdmon->bytes_per_read);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
readbytes = read (esdmon->fd, GST_BUFFER_DATA (buf), esdmon->bytes_per_read);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
if (readbytes == 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (esdmon));
|
|
|
|
return NULL;
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
if (!GST_PAD_CAPS (pad)) {
|
2004-04-05 17:47:30 +00:00
|
|
|
GstCaps *caps = gst_caps_new_simple ("audio/x-raw-int",
|
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"signed", G_TYPE_BOOLEAN, esdmon->depth == 8 ? FALSE : TRUE,
|
|
|
|
"width", G_TYPE_INT, esdmon->depth,
|
|
|
|
"depth", G_TYPE_INT, esdmon->depth,
|
|
|
|
"rate", G_TYPE_INT, esdmon->frequency,
|
|
|
|
"channels", G_TYPE_INT, esdmon->channels,
|
|
|
|
NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-03-02 15:20:05 +00:00
|
|
|
/* set caps on src pad */
|
2004-04-05 17:47:30 +00:00
|
|
|
if (gst_pad_set_explicit_caps (esdmon->srcpad, caps) <= 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (esdmon, CORE, NEGOTIATION, (NULL), (NULL));
|
2004-04-05 17:47:30 +00:00
|
|
|
gst_caps_free (caps);
|
2002-03-02 15:20:05 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-04-05 17:47:30 +00:00
|
|
|
gst_caps_free (caps);
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (buf) = readbytes;
|
|
|
|
GST_BUFFER_OFFSET (buf) = esdmon->curoffset;
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = esdmon->basetime +
|
2004-03-14 22:34:33 +00:00
|
|
|
esdmon->samples_since_basetime * GST_SECOND / esdmon->frequency;
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2002-03-02 15:51:47 +00:00
|
|
|
esdmon->curoffset += readbytes;
|
2002-03-02 15:20:05 +00:00
|
|
|
readsamples = readbytes / esdmon->channels;
|
2004-03-14 22:34:33 +00:00
|
|
|
if (esdmon->depth == 16)
|
|
|
|
readsamples /= 2;
|
2002-03-02 15:51:47 +00:00
|
|
|
esdmon->samples_since_basetime += readsamples;
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("pushed buffer from esdmon of %ld bytes, timestamp %"
|
|
|
|
G_GINT64_FORMAT, readbytes, GST_BUFFER_TIMESTAMP (buf));
|
close #333784 unref the result of gst_pad_get_parent() by: Christophe Fergeau.
Original commit message from CVS:
* ext/cairo/gsttextoverlay.c: (gst_text_overlay_setcaps):
* ext/esd/esdmon.c: (gst_esdmon_get):
* ext/flac/gstflactag.c: (gst_flac_tag_chain):
* ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_sink_setcaps),
(gst_gdk_pixbuf_sink_getcaps):
* ext/jpeg/gstjpegenc.c: (gst_jpegenc_getcaps),
(gst_jpegenc_setcaps):
* ext/jpeg/gstsmokedec.c: (gst_smokedec_chain):
* ext/jpeg/gstsmokeenc.c: (gst_smokeenc_getcaps),
(gst_smokeenc_setcaps):
* ext/libmng/gstmngdec.c: (gst_mngdec_sinklink),
(gst_mngdec_src_getcaps):
* ext/libmng/gstmngenc.c: (gst_mngenc_sinklink),
(gst_mngenc_chain):
* ext/libpng/gstpngenc.c: (gst_pngenc_setcaps):
* ext/mikmod/gstmikmod.c: (gst_mikmod_srclink):
* ext/speex/gstspeexdec.c: (speex_dec_convert),
(speex_dec_src_event), (speex_dec_chain):
* gst/avi/gstavimux.c: (gst_avimux_vidsinkconnect),
(gst_avimux_audsinkconnect), (gst_avimux_handle_event):
* gst/debug/negotiation.c: (gst_negotiation_getcaps),
(gst_negotiation_pad_link), (gst_negotiation_chain):
* gst/flx/gstflxdec.c: (gst_flxdec_src_query_handler),
(gst_flxdec_chain):
* gst/interleave/deinterleave.c: (deinterleave_sink_link),
(deinterleave_chain):
* gst/law/mulaw-encode.c: (mulawenc_setcaps):
* gst/median/gstmedian.c: (gst_median_link):
* gst/monoscope/gstmonoscope.c: (gst_monoscope_srcconnect),
(gst_monoscope_chain):
* gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_sinkconnect):
* gst/wavenc/gstwavenc.c: (gst_wavenc_sink_setcaps):
* sys/osxaudio/gstosxaudiosink.c: (gst_osxaudiosink_chain):
* sys/osxaudio/gstosxaudiosrc.c: (gst_osxaudiosrc_get):
close #333784 unref the result of gst_pad_get_parent()
by: Christophe Fergeau.
2006-03-13 15:49:08 +00:00
|
|
|
gst_object_unref (esdmon);
|
2003-10-08 16:08:18 +00:00
|
|
|
return GST_DATA (buf);
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdmon_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
|
|
|
GstEsdmon *esdmon;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_ESDMON (object));
|
|
|
|
esdmon = GST_ESDMON (object);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_BYTESPERREAD:
|
|
|
|
esdmon->bytes_per_read = g_value_get_ulong (value);
|
|
|
|
/* No need to sync params - will just happen on next read. */
|
|
|
|
break;
|
|
|
|
case ARG_DEPTH:
|
|
|
|
esdmon->depth = g_value_get_enum (value);
|
|
|
|
gst_esdmon_sync_parms (esdmon);
|
|
|
|
break;
|
|
|
|
case ARG_CHANNELS:
|
|
|
|
esdmon->channels = g_value_get_enum (value);
|
|
|
|
gst_esdmon_sync_parms (esdmon);
|
|
|
|
break;
|
|
|
|
case ARG_RATE:
|
|
|
|
/* Preserve the timestamps */
|
2004-03-14 22:34:33 +00:00
|
|
|
esdmon->basetime =
|
2004-03-15 19:32:27 +00:00
|
|
|
esdmon->samples_since_basetime * GST_SECOND / esdmon->frequency;
|
2002-03-02 15:51:47 +00:00
|
|
|
esdmon->samples_since_basetime = 0;
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
/* Set the new frequency */
|
|
|
|
esdmon->frequency = g_value_get_int (value);
|
|
|
|
gst_esdmon_sync_parms (esdmon);
|
|
|
|
break;
|
|
|
|
case ARG_HOST:
|
2004-03-14 22:34:33 +00:00
|
|
|
if (esdmon->host != NULL)
|
2004-03-15 19:32:27 +00:00
|
|
|
g_free (esdmon->host);
|
2002-03-02 15:20:05 +00:00
|
|
|
if (g_value_get_string (value) == NULL)
|
2004-03-15 19:32:27 +00:00
|
|
|
esdmon->host = NULL;
|
2002-03-02 15:20:05 +00:00
|
|
|
else
|
2004-03-15 19:32:27 +00:00
|
|
|
esdmon->host = g_strdup (g_value_get_string (value));
|
2002-03-02 15:20:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdmon_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
|
|
|
GstEsdmon *esdmon;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_ESDMON (object));
|
|
|
|
esdmon = GST_ESDMON (object);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_BYTESPERREAD:
|
|
|
|
g_value_set_ulong (value, esdmon->bytes_per_read);
|
|
|
|
break;
|
|
|
|
case ARG_CUROFFSET:
|
|
|
|
g_value_set_ulong (value, esdmon->curoffset);
|
|
|
|
break;
|
|
|
|
case ARG_DEPTH:
|
|
|
|
g_value_set_enum (value, esdmon->depth);
|
|
|
|
break;
|
|
|
|
case ARG_CHANNELS:
|
|
|
|
g_value_set_enum (value, esdmon->channels);
|
|
|
|
break;
|
|
|
|
case ARG_RATE:
|
|
|
|
g_value_set_int (value, esdmon->frequency);
|
|
|
|
break;
|
|
|
|
case ARG_HOST:
|
|
|
|
g_value_set_string (value, esdmon->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_esdmon_factory_init (GstPlugin * plugin)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
2003-11-01 15:28:33 +00:00
|
|
|
if (!gst_element_register (plugin, "esdmon", GST_RANK_NONE, GST_TYPE_ESDMON))
|
|
|
|
return FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-03-02 15:20:05 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdmon_open_audio (GstEsdmon * src)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
|
|
|
/* Name used by esound for this connection. */
|
2005-12-16 21:57:51 +00:00
|
|
|
const char connname[] = "GStreamer";
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
/* Bitmap describing audio format. */
|
|
|
|
esd_format_t esdformat = ESD_STREAM | ESD_PLAY;
|
|
|
|
|
|
|
|
g_return_val_if_fail (src->fd == -1, FALSE);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (src->depth == 16)
|
|
|
|
esdformat |= ESD_BITS16;
|
|
|
|
else if (src->depth == 8)
|
|
|
|
esdformat |= ESD_BITS8;
|
2002-03-02 15:20:05 +00:00
|
|
|
else {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("esdmon: invalid bit depth (%d)", src->depth);
|
2002-03-02 15:20:05 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (src->channels == 2)
|
|
|
|
esdformat |= ESD_STEREO;
|
|
|
|
else if (src->channels == 1)
|
|
|
|
esdformat |= ESD_MONO;
|
2002-03-02 15:20:05 +00:00
|
|
|
else {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("esdmon: invalid number of channels (%d)", src->channels);
|
2002-03-02 15:20:05 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("esdmon: attempting to open connection to esound server");
|
2004-03-14 22:34:33 +00:00
|
|
|
src->fd = esd_monitor_stream (esdformat, src->frequency, src->host, connname);
|
|
|
|
if (src->fd < 0) {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("esdmon: can't open connection to esound server");
|
2002-03-02 15:20:05 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-10-12 14:29:43 +00:00
|
|
|
GST_OBJECT_FLAG_SET (src, GST_ESDMON_OPEN);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_esdmon_close_audio (GstEsdmon * src)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (src->fd < 0)
|
|
|
|
return;
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
close (src->fd);
|
2002-03-02 15:20:05 +00:00
|
|
|
src->fd = -1;
|
|
|
|
|
2005-10-12 14:29:43 +00:00
|
|
|
GST_OBJECT_FLAG_UNSET (src, GST_ESDMON_OPEN);
|
2002-03-02 15:20:05 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("esdmon: closed sound device");
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_esdmon_change_state (GstElement * element, GstStateChange transition)
|
2002-03-02 15:20:05 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_ESDMON (element), FALSE);
|
|
|
|
|
|
|
|
/* if going down into NULL state, close the fd if it's open */
|
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
2005-10-12 14:29:43 +00:00
|
|
|
if (GST_OBJECT_FLAG_IS_SET (element, GST_ESDMON_OPEN))
|
2002-03-02 15:20:05 +00:00
|
|
|
gst_esdmon_close_audio (GST_ESDMON (element));
|
|
|
|
/* otherwise (READY or higher) we need to open the fd */
|
|
|
|
} else {
|
2005-10-12 14:29:43 +00:00
|
|
|
if (!GST_OBJECT_FLAG_IS_SET (element, GST_ESDMON_OPEN)) {
|
2002-03-02 15:20:05 +00:00
|
|
|
if (!gst_esdmon_open_audio (GST_ESDMON (element)))
|
2005-09-02 15:44:50 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
2005-09-02 15:44:50 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
return GST_STATE_CHANGE_SUCCESS;
|
2002-03-02 15:20:05 +00:00
|
|
|
}
|