2001-12-23 00:25:30 +00:00
|
|
|
/*
|
2003-01-27 12:59:24 +00:00
|
|
|
* Copyright (C) 2001 CodeFactory AB
|
|
|
|
* Copyright (C) 2001 Thomas Nyberg <thomas@codefactory.se>
|
|
|
|
* Copyright (C) 2001-2002 Andy Wingo <apwingo@eos.ncsu.edu>
|
2003-02-09 22:47:34 +00:00
|
|
|
* Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
2003-01-27 12:59:24 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2003-07-19 23:22:47 +00:00
|
|
|
* modify it under the terms of the GNU Library General Public
|
2003-01-27 12:59:24 +00:00
|
|
|
* 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
|
2003-07-25 18:43:15 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
2003-01-27 12:59:24 +00:00
|
|
|
*
|
2003-07-19 23:22:47 +00:00
|
|
|
* You should have received a copy of the GNU Library General Public
|
2003-01-27 12:59:24 +00:00
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2003-11-16 00:40:01 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-11-16 00:40:01 +00:00
|
|
|
|
2002-05-27 04:48:57 +00:00
|
|
|
#include <sys/time.h>
|
2001-12-23 00:25:30 +00:00
|
|
|
|
ext/alsa/gstalsa.c: Alsa should trigger an error if it failed opening the audio device.
Original commit message from CVS:
2004-02-16 Julien MOUTTE <julien@moutte.net>
* ext/alsa/gstalsa.c: (gst_alsa_open_audio),
(gst_alsa_timestamp_to_bytes): Alsa should trigger an error if it
failed opening the audio device.
* sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new),
(gst_ximagesink_ximage_destroy), (gst_ximagesink_ximage_put),
(gst_ximagesink_xwindow_new), (gst_ximagesink_xwindow_destroy),
(gst_ximagesink_xwindow_resize), (gst_ximagesink_xwindow_clear),
(gst_ximagesink_renegotiate_size), (gst_ximagesink_handle_xevents),
(gst_ximagesink_xcontext_get), (gst_ximagesink_xcontext_clear),
(gst_ximagesink_change_state), (gst_ximagesink_chain),
(gst_ximagesink_set_xwindow_id): Clearing window in READY TO PAUSED.
Removing some useless g_return_if_fail like wingo suggested.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xvimage_new),
(gst_xvimagesink_xvimage_destroy), (gst_xvimagesink_xvimage_put),
(gst_xvimagesink_xwindow_new), (gst_xvimagesink_xwindow_destroy),
(gst_xvimagesink_xwindow_resize), (gst_xvimagesink_xwindow_clear),
(gst_xvimagesink_update_colorbalance),
(gst_xvimagesink_handle_xevents), (gst_xvimagesink_xcontext_get),
(gst_xvimagesink_xcontext_clear),
(gst_xvimagesink_get_fourcc_from_caps),
(gst_xvimagesink_change_state), (gst_xvimagesink_chain),
(gst_xvimagesink_set_xwindow_id),
(gst_xvimagesink_colorbalance_list_channels),
(gst_xvimagesink_colorbalance_set_value),
(gst_xvimagesink_colorbalance_get_value): Clearing window in READY TO
PAUSED. Removing some useless g_return_if_fail like wingo suggested.
2004-02-16 16:24:51 +00:00
|
|
|
#include "gst/gst-i18n-plugin.h"
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
#include "gst/propertyprobe/propertyprobe.h"
|
2003-11-16 00:40:01 +00:00
|
|
|
#include "gstalsa.h"
|
|
|
|
#include "gstalsaclock.h"
|
2003-12-06 00:02:20 +00:00
|
|
|
#include "gstalsamixer.h"
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
#define ALSA_DEBUG_FLUSH(this) G_STMT_START{ \
|
|
|
|
gchar *__str; \
|
|
|
|
ssize_t __size; \
|
|
|
|
__size = snd_output_buffer_string (this->out, &__str); \
|
|
|
|
if (__size > 0) { \
|
|
|
|
GST_DEBUG_OBJECT (this, "%*s", __size, __str); \
|
|
|
|
if (snd_output_flush (this->out) != 0) \
|
|
|
|
GST_ERROR_OBJECT (this, "error flushing output buffer"); \
|
|
|
|
} \
|
|
|
|
}G_STMT_END
|
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
/* GObject functions */
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_alsa_class_init (gpointer g_class, gpointer class_data);
|
|
|
|
static void gst_alsa_init (GstAlsa * this);
|
|
|
|
static void gst_alsa_dispose (GObject * object);
|
|
|
|
static void gst_alsa_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_alsa_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
2001-12-23 00:25:30 +00:00
|
|
|
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
/* interface */
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_alsa_probe_interface_init (GstPropertyProbeInterface * iface);
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
/* GStreamer functions for pads and state changing */
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstPad *gst_alsa_request_new_pad (GstElement * element,
|
|
|
|
GstPadTemplate * templ, const gchar * name);
|
|
|
|
static GstElementStateReturn gst_alsa_change_state (GstElement * element);
|
|
|
|
static GstClock *gst_alsa_get_clock (GstElement * element);
|
|
|
|
static void gst_alsa_set_clock (GstElement * element, GstClock * clock);
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
/* ALSA setup / start / stop functions */
|
2004-03-14 22:34:34 +00:00
|
|
|
static gboolean gst_alsa_probe_hw_params (GstAlsa * this,
|
|
|
|
GstAlsaFormat * format);
|
|
|
|
static gboolean gst_alsa_set_hw_params (GstAlsa * this);
|
|
|
|
static gboolean gst_alsa_set_sw_params (GstAlsa * this);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static gboolean gst_alsa_open_audio (GstAlsa * this);
|
|
|
|
static gboolean gst_alsa_start_audio (GstAlsa * this);
|
|
|
|
static gboolean gst_alsa_drain_audio (GstAlsa * this);
|
|
|
|
static gboolean gst_alsa_stop_audio (GstAlsa * this);
|
|
|
|
static gboolean gst_alsa_close_audio (GstAlsa * this);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
/* GStreamer querying, conversion, and format functions */
|
2004-03-14 22:34:34 +00:00
|
|
|
static const GstFormat *gst_alsa_get_formats (GstPad * pad);
|
|
|
|
static gboolean gst_alsa_convert (GstAlsa * this,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
|
|
|
|
static gboolean gst_alsa_pad_convert (GstPad * pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
|
|
|
|
static const GstQueryType *gst_alsa_get_query_types (GstPad * pad);
|
|
|
|
static gboolean gst_alsa_query_func (GstElement * element,
|
|
|
|
GstQueryType type, GstFormat * format, gint64 * value);
|
|
|
|
static gboolean gst_alsa_query (GstElement * element,
|
|
|
|
GstQueryType type, GstFormat * format, gint64 * value);
|
|
|
|
static gboolean gst_alsa_pad_query (GstPad * pad,
|
|
|
|
GstQueryType type, GstFormat * format, gint64 * value);
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
/*** TYPE FUNCTIONS ***********************************************************/
|
2001-12-23 00:25:30 +00:00
|
|
|
|
|
|
|
GType
|
2003-01-19 23:23:30 +00:00
|
|
|
gst_alsa_get_type (void)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-01-27 12:59:24 +00:00
|
|
|
static GType alsa_type = 0;
|
|
|
|
|
|
|
|
if (!alsa_type) {
|
|
|
|
static const GTypeInfo alsa_info = {
|
|
|
|
sizeof (GstAlsaClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2003-11-11 00:38:11 +00:00
|
|
|
gst_alsa_class_init,
|
2003-01-27 12:59:24 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstAlsa),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_alsa_init,
|
|
|
|
};
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
static const GInterfaceInfo alsa_probe_info = {
|
|
|
|
(GInterfaceInitFunc) gst_alsa_probe_interface_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
alsa_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstAlsa", &alsa_info, 0);
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
|
|
|
|
g_type_add_interface_static (alsa_type,
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_TYPE_PROPERTY_PROBE, &alsa_probe_info);
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
return alsa_type;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
/*** GOBJECT FUNCTIONS ********************************************************/
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_DEVICE,
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
ARG_DEVICE_NAME,
|
2003-01-27 12:59:24 +00:00
|
|
|
ARG_PERIODCOUNT,
|
2003-02-09 22:47:34 +00:00
|
|
|
ARG_PERIODSIZE,
|
|
|
|
ARG_BUFFERSIZE,
|
2003-03-22 01:17:06 +00:00
|
|
|
ARG_AUTORECOVER,
|
2003-04-13 14:21:02 +00:00
|
|
|
ARG_MMAP,
|
|
|
|
ARG_MAXDISCONT
|
2003-01-27 12:59:24 +00:00
|
|
|
};
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
static GstElement *parent_class = NULL;
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
static void
|
2003-11-11 00:38:11 +00:00
|
|
|
gst_alsa_class_init (gpointer g_class, gpointer class_data)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-01-27 12:59:24 +00:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GstElementClass *element_class;
|
2003-11-11 00:38:11 +00:00
|
|
|
GstAlsaClass *klass;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
klass = (GstAlsaClass *) g_class;
|
2003-11-11 00:38:11 +00:00
|
|
|
object_class = (GObjectClass *) g_class;
|
|
|
|
element_class = (GstElementClass *) g_class;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
|
|
|
if (parent_class == NULL)
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
2003-03-19 21:33:52 +00:00
|
|
|
object_class->dispose = gst_alsa_dispose;
|
2003-01-27 12:59:24 +00:00
|
|
|
object_class->get_property = gst_alsa_get_property;
|
|
|
|
object_class->set_property = gst_alsa_set_property;
|
|
|
|
|
2003-11-11 00:38:11 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_DEVICE,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_string ("device", "Device",
|
2004-03-15 19:32:28 +00:00
|
|
|
"ALSA device, as defined in an asoundrc",
|
|
|
|
"default", G_PARAM_READWRITE));
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_DEVICE_NAME,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_string ("device_name", "Device name",
|
2004-03-15 19:32:28 +00:00
|
|
|
"Name of the device", NULL, G_PARAM_READABLE));
|
2003-11-11 00:38:11 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_PERIODCOUNT,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_int ("period-count", "Period count",
|
2004-03-15 19:32:28 +00:00
|
|
|
"Number of hardware buffers to use",
|
|
|
|
2, 64, 2, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2003-11-11 00:38:11 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_PERIODSIZE,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_int ("period-size", "Period size",
|
2004-03-15 19:32:28 +00:00
|
|
|
"Number of frames (samples on each channel) in one hardware period",
|
|
|
|
2, 8192, 8192, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2003-11-11 00:38:11 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_BUFFERSIZE,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_int ("buffer-size", "Buffer size",
|
2004-03-15 19:32:28 +00:00
|
|
|
"Number of frames the hardware buffer can hold",
|
|
|
|
4, 65536, 16384, G_PARAM_READWRITE));
|
2003-11-11 00:38:11 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_AUTORECOVER,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_boolean ("autorecover", "Automatic xrun recovery",
|
2004-03-15 19:32:28 +00:00
|
|
|
"When TRUE tries to reduce processor load on xruns",
|
|
|
|
TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2003-11-11 00:38:11 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_MMAP,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_boolean ("mmap", "Use mmap'ed access",
|
2004-03-15 19:32:28 +00:00
|
|
|
"Wether to use mmap (faster) or standard read/write (more compatible)",
|
|
|
|
TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2003-11-11 00:38:11 +00:00
|
|
|
g_object_class_install_property (object_class, ARG_MAXDISCONT,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_uint64 ("max-discont", "Maximum Discontinuity",
|
2004-03-15 19:32:28 +00:00
|
|
|
"GStreamer timeunits before the timestamp syncing starts dropping/inserting samples",
|
|
|
|
/* rounding errors */ 1000, GST_SECOND, GST_ALSA_DEFAULT_DISCONT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
element_class->change_state = GST_DEBUG_FUNCPTR (gst_alsa_change_state);
|
|
|
|
element_class->query = GST_DEBUG_FUNCPTR (gst_alsa_query);
|
2003-05-15 16:32:22 +00:00
|
|
|
element_class->request_new_pad = GST_DEBUG_FUNCPTR (gst_alsa_request_new_pad);
|
2004-03-14 22:34:34 +00:00
|
|
|
element_class->set_clock = GST_DEBUG_FUNCPTR (gst_alsa_set_clock);
|
|
|
|
element_class->get_clock = GST_DEBUG_FUNCPTR (gst_alsa_get_clock);
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_init (GstAlsa * this)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
this->device = g_strdup ("default");
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-05-10 11:37:35 +00:00
|
|
|
GST_FLAG_SET (this, GST_ELEMENT_EVENT_AWARE);
|
2003-01-27 12:59:24 +00:00
|
|
|
GST_FLAG_SET (this, GST_ELEMENT_THREAD_SUGGESTED);
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-03-19 21:33:52 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_dispose (GObject * object)
|
2003-03-19 21:33:52 +00:00
|
|
|
{
|
|
|
|
GstAlsa *this = GST_ALSA (object);
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
g_free (this->device);
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
if (this->clock)
|
2003-05-10 11:37:35 +00:00
|
|
|
gst_object_unparent (GST_OBJECT (this->clock));
|
2003-03-27 00:17:26 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2003-03-19 21:33:52 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2001-12-23 00:25:30 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-01-27 12:59:24 +00:00
|
|
|
GstAlsa *this;
|
2003-02-09 22:47:34 +00:00
|
|
|
gint buffer_size;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
|
|
|
this = (GstAlsa *) object;
|
|
|
|
switch (prop_id) {
|
2004-03-14 22:34:34 +00:00
|
|
|
case ARG_DEVICE:
|
|
|
|
if (this->device)
|
2004-03-15 19:32:28 +00:00
|
|
|
g_free (this->device);
|
2004-03-14 22:34:34 +00:00
|
|
|
this->device = g_strdup (g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case ARG_PERIODCOUNT:
|
|
|
|
g_return_if_fail (!GST_FLAG_IS_SET (this, GST_ALSA_RUNNING));
|
|
|
|
this->period_count = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_PERIODSIZE:
|
|
|
|
g_return_if_fail (!GST_FLAG_IS_SET (this, GST_ALSA_RUNNING));
|
|
|
|
this->period_size = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_BUFFERSIZE:
|
|
|
|
g_return_if_fail (!GST_FLAG_IS_SET (this, GST_ALSA_RUNNING));
|
|
|
|
buffer_size = g_value_get_int (value);
|
|
|
|
this->period_count = buffer_size / this->period_size;
|
|
|
|
break;
|
|
|
|
case ARG_AUTORECOVER:
|
|
|
|
this->autorecover = g_value_get_boolean (value);
|
|
|
|
return;
|
|
|
|
case ARG_MMAP:
|
|
|
|
this->mmap = g_value_get_boolean (value);
|
|
|
|
return;
|
|
|
|
case ARG_MAXDISCONT:
|
|
|
|
this->max_discont = (GstClockTime) g_value_get_uint64 (value);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
return;
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_STATE (this) == GST_STATE_NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GST_FLAG_IS_SET (this, GST_ALSA_RUNNING)) {
|
|
|
|
gst_alsa_stop_audio (this);
|
2003-03-24 03:45:45 +00:00
|
|
|
gst_alsa_start_audio (this);
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-01-27 12:59:24 +00:00
|
|
|
GstAlsa *this;
|
|
|
|
|
|
|
|
this = (GstAlsa *) object;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2004-03-14 22:34:34 +00:00
|
|
|
case ARG_DEVICE:
|
|
|
|
g_value_set_string (value, this->device);
|
|
|
|
break;
|
|
|
|
case ARG_DEVICE_NAME:
|
2004-03-15 06:34:44 +00:00
|
|
|
g_value_set_string (value, this->cardname);
|
2004-03-14 22:34:34 +00:00
|
|
|
break;
|
|
|
|
case ARG_PERIODCOUNT:
|
|
|
|
g_value_set_int (value, this->period_count);
|
|
|
|
break;
|
|
|
|
case ARG_PERIODSIZE:
|
|
|
|
g_value_set_int (value, this->period_size);
|
|
|
|
break;
|
|
|
|
case ARG_BUFFERSIZE:
|
|
|
|
g_value_set_int (value, this->period_size * this->period_count);
|
|
|
|
break;
|
|
|
|
case ARG_AUTORECOVER:
|
|
|
|
g_value_set_boolean (value, this->autorecover);
|
|
|
|
break;
|
|
|
|
case ARG_MMAP:
|
|
|
|
g_value_set_boolean (value, this->mmap);
|
|
|
|
break;
|
|
|
|
case ARG_MAXDISCONT:
|
|
|
|
g_value_set_uint64 (value, (guint64) this->max_discont);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-19 23:23:30 +00:00
|
|
|
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
static const GList *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_probe_get_properties (GstPropertyProbe * probe)
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
{
|
|
|
|
GObjectClass *klass = G_OBJECT_GET_CLASS (probe);
|
|
|
|
static GList *list = NULL;
|
|
|
|
|
|
|
|
if (!list) {
|
2004-03-14 22:34:34 +00:00
|
|
|
list = g_list_append (NULL, g_object_class_find_property (klass, "device"));
|
|
|
|
}
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2004-04-30 01:20:54 +00:00
|
|
|
static void
|
|
|
|
device_list (snd_pcm_stream_t stream, GstAlsaClass * klass)
|
|
|
|
{
|
|
|
|
snd_ctl_t *handle;
|
|
|
|
int card, err, dev;
|
|
|
|
snd_ctl_card_info_t *info;
|
|
|
|
snd_pcm_info_t *pcminfo;
|
2004-05-09 00:30:06 +00:00
|
|
|
gboolean mixer = (stream == -1);
|
|
|
|
|
|
|
|
if (stream == -1)
|
|
|
|
stream = 0;
|
2004-04-30 01:20:54 +00:00
|
|
|
|
|
|
|
snd_ctl_card_info_alloca (&info);
|
|
|
|
snd_pcm_info_alloca (&pcminfo);
|
|
|
|
card = -1;
|
|
|
|
|
|
|
|
if (snd_card_next (&card) < 0 || card < 0) {
|
|
|
|
/* no soundcard found */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (card >= 0) {
|
|
|
|
char name[32];
|
|
|
|
|
|
|
|
sprintf (name, "hw:%d", card);
|
|
|
|
if ((err = snd_ctl_open (&handle, name, 0)) < 0) {
|
|
|
|
goto next_card;
|
|
|
|
}
|
|
|
|
if ((err = snd_ctl_card_info (handle, info)) < 0) {
|
|
|
|
snd_ctl_close (handle);
|
|
|
|
goto next_card;
|
|
|
|
}
|
|
|
|
|
2004-05-09 00:30:06 +00:00
|
|
|
if (mixer) {
|
|
|
|
klass->devices = g_list_append (klass->devices, g_strdup (name));
|
|
|
|
} else {
|
|
|
|
dev = -1;
|
|
|
|
while (1) {
|
|
|
|
gchar *gst_device;
|
|
|
|
|
|
|
|
snd_ctl_pcm_next_device (handle, &dev);
|
|
|
|
|
|
|
|
if (dev < 0)
|
|
|
|
break;
|
|
|
|
snd_pcm_info_set_device (pcminfo, dev);
|
|
|
|
snd_pcm_info_set_subdevice (pcminfo, 0);
|
|
|
|
snd_pcm_info_set_stream (pcminfo, stream);
|
|
|
|
if ((err = snd_ctl_pcm_info (handle, pcminfo)) < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_device = g_strdup_printf ("hw:%d,%d", card, dev);
|
|
|
|
klass->devices = g_list_append (klass->devices, gst_device);
|
2004-04-30 01:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
snd_ctl_close (handle);
|
|
|
|
next_card:
|
|
|
|
if (snd_card_next (&card) < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_class_probe_devices (GstAlsaClass * klass, gboolean check)
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
{
|
|
|
|
static gboolean init = FALSE;
|
|
|
|
|
|
|
|
/* I'm pretty sure ALSA has a good way to do this. However, their cool
|
|
|
|
* auto-generated documentation is pretty much useless if you try to
|
|
|
|
* do function-wise look-ups. */
|
|
|
|
|
|
|
|
if (!init && !check) {
|
2004-05-09 00:30:06 +00:00
|
|
|
snd_pcm_stream_t mode = -1;
|
2004-04-29 00:40:14 +00:00
|
|
|
const GList *templates;
|
|
|
|
|
|
|
|
/* we assume one pad template at max [zero=mixer] */
|
|
|
|
templates =
|
|
|
|
gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS (klass));
|
|
|
|
if (templates) {
|
|
|
|
if (GST_PAD_TEMPLATE_DIRECTION (templates->data) == GST_PAD_SRC)
|
|
|
|
mode = SND_PCM_STREAM_CAPTURE;
|
|
|
|
else
|
|
|
|
mode = SND_PCM_STREAM_PLAYBACK;
|
|
|
|
}
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
|
2004-04-30 01:20:54 +00:00
|
|
|
device_list (mode, klass);
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
|
|
|
|
init = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return init;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GValueArray *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_class_list_devices (GstAlsaClass * klass)
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
{
|
|
|
|
GValueArray *array;
|
|
|
|
GValue value = { 0 };
|
|
|
|
GList *item;
|
|
|
|
|
|
|
|
if (!klass->devices)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
array = g_value_array_new (g_list_length (klass->devices));
|
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
|
|
for (item = klass->devices; item != NULL; item = item->next) {
|
|
|
|
g_value_set_string (&value, item->data);
|
|
|
|
g_value_array_append (array, &value);
|
|
|
|
}
|
|
|
|
g_value_unset (&value);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
return array;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_probe_probe_property (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
{
|
|
|
|
GstAlsaClass *klass = GST_ALSA_GET_CLASS (probe);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
gst_alsa_class_probe_devices (klass, FALSE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_probe_needs_probe (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
{
|
|
|
|
GstAlsaClass *klass = GST_ALSA_GET_CLASS (probe);
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
ret = !gst_alsa_class_probe_devices (klass, TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GValueArray *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_probe_get_values (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
{
|
|
|
|
GstAlsaClass *klass = GST_ALSA_GET_CLASS (probe);
|
|
|
|
GValueArray *array = NULL;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
array = gst_alsa_class_list_devices (klass);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_probe_interface_init (GstPropertyProbeInterface * iface)
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
{
|
|
|
|
iface->get_properties = gst_alsa_probe_get_properties;
|
|
|
|
iface->probe_property = gst_alsa_probe_probe_property;
|
2004-03-14 22:34:34 +00:00
|
|
|
iface->needs_probe = gst_alsa_probe_needs_probe;
|
|
|
|
iface->get_values = gst_alsa_probe_get_values;
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
}
|
|
|
|
|
2003-05-15 16:32:22 +00:00
|
|
|
/*** GSTREAMER PAD / QUERY / CONVERSION / STATE FUNCTIONS *********************/
|
2003-04-24 00:03:06 +00:00
|
|
|
|
|
|
|
static GstPad *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_request_new_pad (GstElement * element, GstPadTemplate * templ,
|
|
|
|
const gchar * name)
|
2003-02-27 23:13:22 +00:00
|
|
|
{
|
2003-04-24 00:03:06 +00:00
|
|
|
GstAlsa *this;
|
2003-12-06 00:02:20 +00:00
|
|
|
gint track = 0;
|
2003-04-24 00:03:06 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail ((this = GST_ALSA (element)), NULL);
|
|
|
|
g_return_val_if_fail (!GST_FLAG_IS_SET (element, GST_ALSA_RUNNING), NULL);
|
|
|
|
|
|
|
|
if (name) {
|
2003-12-06 00:02:20 +00:00
|
|
|
/* locate the track number in the requested pad name. */
|
2004-03-14 22:34:34 +00:00
|
|
|
track = (gint) strtol (name + (strchr (templ->name_template, '%') -
|
2004-03-15 19:32:28 +00:00
|
|
|
templ->name_template), NULL, 0);
|
2003-12-06 00:02:20 +00:00
|
|
|
if (track < 1 || track >= GST_ALSA_MAX_TRACKS) {
|
|
|
|
GST_INFO_OBJECT (this, "invalid track requested. (%d)", track);
|
2003-04-24 00:03:06 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
/* make sure the requested track is free. */
|
|
|
|
if (track > 0 || this->pad[track] != NULL) {
|
|
|
|
GST_INFO_OBJECT (this, "requested track %d already in use.", track);
|
2003-04-24 00:03:06 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
/* if the user doesn't care, use the lowest available track number */
|
|
|
|
if (track == 0) {
|
|
|
|
for (track = 1; track < GST_ALSA_MAX_TRACKS; track++) {
|
2004-03-14 22:34:34 +00:00
|
|
|
if (this->pad[track] != NULL)
|
2004-03-15 19:32:28 +00:00
|
|
|
goto found_track;
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
found_track:
|
|
|
|
this->pad[track] = gst_pad_new_from_template (templ, name);
|
|
|
|
|
|
|
|
gst_pad_set_link_function (this->pad[track], gst_alsa_link);
|
|
|
|
gst_pad_set_getcaps_function (this->pad[track], gst_alsa_get_caps);
|
2004-03-09 21:29:56 +00:00
|
|
|
gst_pad_set_fixate_function (this->pad[track], gst_alsa_fixate);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT (this), this->pad[track]);
|
|
|
|
|
|
|
|
gst_pad_set_convert_function (this->pad[track], gst_alsa_pad_convert);
|
|
|
|
gst_pad_set_query_function (this->pad[track], gst_alsa_pad_query);
|
|
|
|
gst_pad_set_query_type_function (this->pad[track], gst_alsa_get_query_types);
|
|
|
|
gst_pad_set_formats_function (this->pad[track], gst_alsa_get_formats);
|
|
|
|
|
|
|
|
return this->pad[track];
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* gets the matching alsa format or NULL if none matches */
|
|
|
|
static GstAlsaFormat *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_get_format (const GstStructure * structure)
|
2003-01-27 12:59:24 +00:00
|
|
|
{
|
2003-07-06 20:49:52 +00:00
|
|
|
const gchar *mimetype;
|
2003-04-24 00:03:06 +00:00
|
|
|
GstAlsaFormat *ret;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!(ret = g_new (GstAlsaFormat, 1)))
|
2003-04-24 00:03:06 +00:00
|
|
|
return NULL;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* we have to differentiate between int and float formats */
|
2003-12-22 01:47:09 +00:00
|
|
|
mimetype = gst_structure_get_name (structure);
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!strncmp (mimetype, "audio/x-raw-int", 15)) {
|
2003-04-24 00:03:06 +00:00
|
|
|
gboolean sign;
|
2003-07-06 20:49:52 +00:00
|
|
|
gint width, depth, endianness;
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
/* extract the needed information from the cap */
|
|
|
|
if (!(gst_structure_get_int (structure, "width", &width) &&
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_structure_get_int (structure, "depth", &depth) &&
|
|
|
|
gst_structure_get_boolean (structure, "signed", &sign)))
|
2004-03-14 22:34:34 +00:00
|
|
|
goto error;
|
2003-07-19 23:22:47 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* extract endianness if needed */
|
|
|
|
if (width > 8) {
|
2003-12-22 01:47:09 +00:00
|
|
|
if (!gst_structure_get_int (structure, "endianness", &endianness))
|
2004-03-15 19:32:28 +00:00
|
|
|
goto error;
|
2003-07-19 23:22:47 +00:00
|
|
|
} else {
|
2003-04-24 00:03:06 +00:00
|
|
|
endianness = G_BYTE_ORDER;
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|
2003-07-19 23:22:47 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
ret->format =
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_pcm_build_linear_format (depth, width, sign ? 0 : 1,
|
|
|
|
endianness == G_LITTLE_ENDIAN ? 0 : 1);
|
2003-07-19 23:22:47 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
} else if (!strncmp (mimetype, "audio/x-raw-float", 17)) {
|
2003-07-19 23:22:47 +00:00
|
|
|
gint width;
|
2003-04-24 00:03:06 +00:00
|
|
|
|
|
|
|
/* get layout */
|
2003-12-22 01:47:09 +00:00
|
|
|
if (!gst_structure_get_int (structure, "width", &width))
|
2003-04-24 00:03:06 +00:00
|
|
|
goto error;
|
2003-07-19 23:22:47 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* match layout to format wrt to endianness */
|
2003-07-19 23:22:47 +00:00
|
|
|
if (width == 32) {
|
2003-04-24 00:03:06 +00:00
|
|
|
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
|
2004-03-15 19:32:28 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_FLOAT_LE;
|
2003-04-24 00:03:06 +00:00
|
|
|
} else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
|
2004-03-15 19:32:28 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_FLOAT_BE;
|
2003-04-24 00:03:06 +00:00
|
|
|
} else {
|
2004-03-15 19:32:28 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_FLOAT;
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|
2003-07-19 23:22:47 +00:00
|
|
|
} else if (width == 64) {
|
2003-04-24 00:03:06 +00:00
|
|
|
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
|
2004-03-15 19:32:28 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_FLOAT64_LE;
|
2003-04-24 00:03:06 +00:00
|
|
|
} else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
|
2004-03-15 19:32:28 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_FLOAT64_BE;
|
2003-04-24 00:03:06 +00:00
|
|
|
} else {
|
2004-03-15 19:32:28 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_FLOAT64;
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto error;
|
2003-03-18 22:07:56 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
} else if (!strncmp (mimetype, "audio/x-alaw", 12)) {
|
2003-07-06 20:49:52 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_A_LAW;
|
2004-03-14 22:34:34 +00:00
|
|
|
} else if (!strncmp (mimetype, "audio/x-mulaw", 13)) {
|
2003-07-06 20:49:52 +00:00
|
|
|
ret->format = SND_PCM_FORMAT_MU_LAW;
|
2003-07-19 23:22:47 +00:00
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
|
|
|
|
/* get rate and channels */
|
2003-12-22 01:47:09 +00:00
|
|
|
if (!(gst_structure_get_int (structure, "rate", &ret->rate) &&
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_structure_get_int (structure, "channels", &ret->channels)))
|
2003-04-24 00:03:06 +00:00
|
|
|
goto error;
|
2003-07-19 23:22:47 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
return ret;
|
2003-07-19 23:22:47 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
error:
|
|
|
|
g_free (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_formats_match (GstAlsaFormat * one, GstAlsaFormat * two)
|
2003-04-24 00:03:06 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
if (one == two)
|
|
|
|
return TRUE;
|
|
|
|
if (one == NULL || two == NULL)
|
|
|
|
return FALSE;
|
2003-07-19 23:22:47 +00:00
|
|
|
return (one->format == two->format) &&
|
2004-03-14 22:34:34 +00:00
|
|
|
(one->rate == two->rate) && (one->channels == two->channels);
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* get props for a spec */
|
2003-07-06 20:49:52 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_alsa_get_caps_internal (snd_pcm_format_t format)
|
2003-04-24 00:03:06 +00:00
|
|
|
{
|
|
|
|
if (format == SND_PCM_FORMAT_A_LAW) {
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_caps_new_simple ("audio/x-alaw", NULL);
|
2003-04-24 00:03:06 +00:00
|
|
|
} else if (format == SND_PCM_FORMAT_MU_LAW) {
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_caps_new_simple ("audio/x-mulaw", NULL);
|
2003-04-24 00:03:06 +00:00
|
|
|
} else if (snd_pcm_format_linear (format)) {
|
|
|
|
/* int */
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure = gst_structure_new ("audio/x-raw-int",
|
2004-03-15 19:32:28 +00:00
|
|
|
"width", G_TYPE_INT, (gint) snd_pcm_format_physical_width (format),
|
|
|
|
"depth", G_TYPE_INT, (gint) snd_pcm_format_width (format),
|
|
|
|
"signed", G_TYPE_BOOLEAN,
|
|
|
|
snd_pcm_format_signed (format) == 1 ? TRUE : FALSE,
|
|
|
|
NULL);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* endianness */
|
|
|
|
if (snd_pcm_format_physical_width (format) > 8) {
|
|
|
|
switch (snd_pcm_format_little_endian (format)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case 0:
|
|
|
|
gst_structure_set (structure, "endianness", G_TYPE_INT, G_BIG_ENDIAN,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
gst_structure_set (structure, "endianness", G_TYPE_INT,
|
|
|
|
G_LITTLE_ENDIAN, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING
|
|
|
|
("Unknown byte order in sound driver. Continuing by assuming system byte order.");
|
|
|
|
gst_structure_set (structure, "endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
NULL);
|
|
|
|
break;
|
2003-03-27 00:17:26 +00:00
|
|
|
}
|
2003-03-19 21:33:52 +00:00
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_caps_new_full (structure, NULL);
|
2003-04-24 00:03:06 +00:00
|
|
|
} else if (snd_pcm_format_float (format)) {
|
|
|
|
/* no float with non-platform endianness */
|
|
|
|
if (!snd_pcm_format_cpu_endian (format))
|
|
|
|
return NULL;
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_caps_new_simple ("audio/x-raw-float",
|
2004-03-15 19:32:28 +00:00
|
|
|
"width", G_TYPE_INT, (gint) snd_pcm_format_width (format),
|
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER, NULL);
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
return NULL;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
static inline void
|
2004-03-14 22:34:34 +00:00
|
|
|
add_channels (GstStructure * structure, gint min_rate, gint max_rate,
|
2003-12-22 01:47:09 +00:00
|
|
|
gint min_channels, gint max_channels)
|
|
|
|
{
|
2003-04-24 00:03:06 +00:00
|
|
|
if (min_rate < 0) {
|
2003-12-22 01:47:09 +00:00
|
|
|
min_rate = GST_ALSA_MIN_RATE;
|
|
|
|
max_rate = GST_ALSA_MAX_RATE;
|
|
|
|
}
|
2004-06-09 17:06:40 +00:00
|
|
|
if (max_rate < 0 || min_rate == max_rate) {
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_set (structure, "rate", G_TYPE_INT, min_rate, NULL);
|
2003-02-27 23:13:22 +00:00
|
|
|
} else {
|
2004-06-09 17:06:40 +00:00
|
|
|
/* just to be sure */
|
|
|
|
if (min_rate > max_rate) {
|
|
|
|
gint temp;
|
|
|
|
|
|
|
|
GST_ERROR
|
|
|
|
("minimum rate > maximum rate (%d > %d), please fix your soundcard drivers",
|
|
|
|
min_rate, max_rate);
|
|
|
|
temp = min_rate;
|
|
|
|
min_rate = max_rate;
|
|
|
|
max_rate = temp;
|
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, min_rate,
|
2004-03-15 19:32:28 +00:00
|
|
|
max_rate, NULL);
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
if (min_channels < 0) {
|
2003-12-22 01:47:09 +00:00
|
|
|
min_channels = 1;
|
|
|
|
max_channels = GST_ALSA_MAX_CHANNELS;
|
|
|
|
}
|
2004-06-09 17:06:40 +00:00
|
|
|
if (max_channels < 0 || min_channels == max_channels) {
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_set (structure, "channels", G_TYPE_INT, min_channels, NULL);
|
2003-04-24 00:03:06 +00:00
|
|
|
} else {
|
2004-06-09 17:06:40 +00:00
|
|
|
/* just to be sure */
|
|
|
|
if (min_channels > max_channels) {
|
|
|
|
gint temp;
|
|
|
|
|
|
|
|
GST_ERROR
|
|
|
|
("minimum channels > maximum channels (%d > %d), please fix your soundcard drivers",
|
|
|
|
min_channels, max_channels);
|
|
|
|
temp = min_channels;
|
|
|
|
min_channels = max_channels;
|
|
|
|
max_channels = temp;
|
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE,
|
2004-03-15 19:32:28 +00:00
|
|
|
min_channels, max_channels, NULL);
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all available caps.
|
|
|
|
* @format: SND_PCM_FORMAT_UNKNOWN for all formats, desired format else
|
|
|
|
* @rate: allowed rates if < 0, else desired rate
|
|
|
|
* @channels: all allowed values for channels if < 0, else desired channels
|
|
|
|
*/
|
2003-11-16 00:40:01 +00:00
|
|
|
GstCaps *
|
2003-04-24 00:03:06 +00:00
|
|
|
gst_alsa_caps (snd_pcm_format_t format, gint rate, gint channels)
|
2003-03-22 01:17:06 +00:00
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
GstCaps *ret_caps;
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
if (format != SND_PCM_FORMAT_UNKNOWN) {
|
|
|
|
/* there are some caps set already */
|
2003-07-06 20:49:52 +00:00
|
|
|
ret_caps = gst_alsa_get_caps_internal (format);
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* we can never use a format we can't set caps for */
|
2003-07-06 20:49:52 +00:00
|
|
|
g_assert (ret_caps != NULL);
|
2003-12-22 01:47:09 +00:00
|
|
|
g_assert (gst_caps_get_size (ret_caps) == 1);
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
add_channels (gst_caps_get_structure (ret_caps, 0), rate, -1, channels, -1);
|
2003-03-22 01:17:06 +00:00
|
|
|
} else {
|
2003-04-24 00:03:06 +00:00
|
|
|
int i;
|
2003-07-06 20:49:52 +00:00
|
|
|
GstCaps *temp;
|
2003-03-26 22:24:35 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
ret_caps = gst_caps_new_empty ();
|
2003-04-24 00:03:06 +00:00
|
|
|
for (i = 0; i <= SND_PCM_FORMAT_LAST; i++) {
|
2003-07-06 20:49:52 +00:00
|
|
|
temp = gst_alsa_get_caps_internal (i);
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* can be NULL, because not all alsa formats can be specified as caps */
|
2003-12-22 01:47:09 +00:00
|
|
|
if (temp != NULL) {
|
2004-03-15 19:32:28 +00:00
|
|
|
g_assert (gst_caps_get_size (temp) == 1);
|
|
|
|
add_channels (gst_caps_get_structure (temp, 0), rate, -1, channels, -1);
|
|
|
|
gst_caps_append (ret_caps, temp);
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2004-05-16 16:41:15 +00:00
|
|
|
gst_caps_do_simplify (ret_caps);
|
2003-04-24 00:03:06 +00:00
|
|
|
return ret_caps;
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* Return better caps when device is open */
|
2003-11-16 00:40:01 +00:00
|
|
|
GstCaps *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_get_caps (GstPad * pad)
|
2003-03-18 22:07:56 +00:00
|
|
|
{
|
2003-04-24 00:03:06 +00:00
|
|
|
GstAlsa *this;
|
|
|
|
snd_pcm_hw_params_t *hw_params;
|
|
|
|
snd_pcm_format_mask_t *mask;
|
|
|
|
int i;
|
|
|
|
unsigned int min_rate, max_rate;
|
|
|
|
gint min_channels, max_channels;
|
|
|
|
GstCaps *ret = NULL;
|
2003-04-13 04:13:12 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
2003-03-18 22:07:56 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
this = GST_ALSA (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (!GST_FLAG_IS_SET (this, GST_ALSA_OPEN))
|
2003-12-22 16:38:00 +00:00
|
|
|
return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad)));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
snd_pcm_hw_params_alloca (&hw_params);
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_any (this->handle, hw_params),
|
2004-03-14 22:34:34 +00:00
|
|
|
"Broken configuration for this PCM: %s");
|
2003-04-24 00:03:06 +00:00
|
|
|
|
|
|
|
if (((GstElement *) this)->numpads > 1) {
|
|
|
|
min_channels = 1;
|
|
|
|
max_channels = -1;
|
|
|
|
} else {
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_get_channels_min (hw_params, &min_rate),
|
2004-03-15 19:32:28 +00:00
|
|
|
"Couldn't get minimum channel count for device %s: %s", this->device);
|
2003-04-24 00:03:06 +00:00
|
|
|
ERROR_CHECK (snd_pcm_hw_params_get_channels_max (hw_params, &max_rate),
|
2004-03-15 19:32:28 +00:00
|
|
|
"Couldn't get maximum channel count for device %s: %s", this->device);
|
2003-04-24 00:03:06 +00:00
|
|
|
min_channels = min_rate;
|
2004-03-14 22:34:34 +00:00
|
|
|
max_channels =
|
2004-03-15 19:32:28 +00:00
|
|
|
max_rate > GST_ALSA_MAX_CHANNELS ? GST_ALSA_MAX_CHANNELS : max_rate;
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_get_rate_min (hw_params, &min_rate, &i),
|
2004-03-14 22:34:34 +00:00
|
|
|
"Couldn't get minimum rate for device %s: %s", this->device);
|
2003-04-24 00:03:06 +00:00
|
|
|
min_rate = min_rate < GST_ALSA_MIN_RATE ? GST_ALSA_MIN_RATE : min_rate + i;
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_get_rate_max (hw_params, &max_rate, &i),
|
2004-03-14 22:34:34 +00:00
|
|
|
"Couldn't get maximum rate for device %s: %s", this->device);
|
2003-04-24 00:03:06 +00:00
|
|
|
max_rate = max_rate > GST_ALSA_MAX_RATE ? GST_ALSA_MAX_RATE : max_rate + i;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
snd_pcm_format_mask_alloca (&mask);
|
|
|
|
snd_pcm_hw_params_get_format_mask (hw_params, mask);
|
|
|
|
for (i = 0; i <= SND_PCM_FORMAT_LAST; i++) {
|
|
|
|
if (snd_pcm_format_mask_test (mask, i)) {
|
2003-07-07 00:34:24 +00:00
|
|
|
GstCaps *caps = gst_alsa_get_caps_internal (i);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* we can never use a format we can't set caps for */
|
2003-12-22 01:47:09 +00:00
|
|
|
if (caps != NULL) {
|
2004-03-15 19:32:28 +00:00
|
|
|
g_assert (gst_caps_get_size (caps) == 1);
|
|
|
|
add_channels (gst_caps_get_structure (caps, 0), min_rate, max_rate,
|
|
|
|
min_channels, max_channels);
|
|
|
|
if (ret) {
|
|
|
|
gst_caps_append (ret, caps);
|
|
|
|
} else {
|
|
|
|
ret = caps;
|
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-18 22:07:56 +00:00
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2003-12-22 16:38:00 +00:00
|
|
|
if (ret == NULL) {
|
|
|
|
GST_WARNING_OBJECT (this, "no supported caps found, returning empty caps");
|
|
|
|
return gst_caps_new_empty ();
|
|
|
|
} else {
|
2004-05-16 16:41:15 +00:00
|
|
|
G_GNUC_UNUSED gchar *str;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-05-16 16:41:15 +00:00
|
|
|
gst_caps_do_simplify (ret);
|
|
|
|
str = gst_caps_to_string (ret);
|
2003-12-22 16:38:00 +00:00
|
|
|
GST_LOG_OBJECT (this, "get_caps returns %s", str);
|
|
|
|
g_free (str);
|
|
|
|
return ret;
|
|
|
|
}
|
2003-03-18 22:07:56 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_alsa_fixate_to_mimetype (const GstCaps * caps, const gchar * mime)
|
2004-03-09 21:29:56 +00:00
|
|
|
{
|
2004-06-09 17:06:40 +00:00
|
|
|
GstCaps *try, *result;
|
2004-03-09 21:29:56 +00:00
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
try = gst_caps_new_simple (mime, NULL);
|
|
|
|
result = gst_caps_intersect (try, caps);
|
|
|
|
gst_caps_free (try);
|
|
|
|
if (gst_caps_is_empty (result)) {
|
|
|
|
gst_caps_free (result);
|
|
|
|
return NULL;
|
2004-03-09 21:29:56 +00:00
|
|
|
}
|
2004-06-09 17:06:40 +00:00
|
|
|
if (gst_caps_is_subset (caps, result)) {
|
|
|
|
/* we didn't reduce caps */
|
|
|
|
gst_caps_free (result);
|
|
|
|
return NULL;
|
2004-03-09 21:29:56 +00:00
|
|
|
}
|
2004-06-09 17:06:40 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_alsa_fixate_field_nearest_int (const GstCaps * caps,
|
|
|
|
const gchar * field_name, gint target)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
GstCaps *result;
|
|
|
|
GstCaps *smaller = gst_caps_new_empty ();
|
|
|
|
GstCaps *equal = gst_caps_new_empty ();
|
|
|
|
GstCaps *bigger = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
/* works like this: we fixate every structure and put them into one of those
|
|
|
|
* caps depending on what we fixated to. We then return the best caps that is
|
|
|
|
* not empty in the following order: equal, bigger, smaller
|
|
|
|
* We also make sure the caps were really reduced.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
|
|
|
gint fixated_to;
|
|
|
|
GstStructure *copy = gst_structure_copy (gst_caps_get_structure (caps, i));
|
|
|
|
|
|
|
|
gst_caps_structure_fixate_field_nearest_int (copy, field_name, target);
|
|
|
|
if (gst_structure_get_int (copy, field_name, &fixated_to)) {
|
|
|
|
if (fixated_to == target) {
|
|
|
|
gst_caps_append_structure (equal, copy);
|
|
|
|
} else if (fixated_to > target) {
|
|
|
|
gst_caps_append_structure (bigger, copy);
|
|
|
|
} else {
|
|
|
|
gst_caps_append_structure (smaller, copy);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* FIXME: what do we do here? Add to all or throw an error? */
|
|
|
|
g_return_val_if_reached (NULL);
|
2004-03-30 06:51:31 +00:00
|
|
|
}
|
2004-06-09 17:06:40 +00:00
|
|
|
}
|
|
|
|
if (!gst_caps_is_empty (equal)) {
|
|
|
|
gst_caps_free (bigger);
|
|
|
|
gst_caps_free (smaller);
|
|
|
|
result = equal;
|
2004-03-30 06:51:31 +00:00
|
|
|
} else {
|
2004-06-09 17:06:40 +00:00
|
|
|
gst_caps_free (equal);
|
|
|
|
if (!gst_caps_is_empty (bigger)) {
|
|
|
|
gst_caps_free (smaller);
|
|
|
|
result = bigger;
|
|
|
|
} else {
|
|
|
|
gst_caps_free (bigger);
|
|
|
|
if (gst_caps_is_empty (smaller)) {
|
|
|
|
gst_caps_free (smaller);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
result = smaller;
|
2004-03-30 06:51:31 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-09 17:06:40 +00:00
|
|
|
if (gst_caps_is_subset (caps, result)) {
|
|
|
|
/* we didn't reduce caps */
|
|
|
|
gst_caps_free (result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2004-03-09 21:29:56 +00:00
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
GstCaps *
|
|
|
|
gst_alsa_fixate (GstPad * pad, const GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstCaps *result;
|
|
|
|
const gchar *mime;
|
|
|
|
|
|
|
|
if ((result = gst_alsa_fixate_to_mimetype (caps, "audio/x-raw-int")))
|
|
|
|
return result;
|
|
|
|
if ((result = gst_alsa_fixate_to_mimetype (caps, "audio/x-raw-float")))
|
|
|
|
return result;
|
|
|
|
if ((result = gst_alsa_fixate_to_mimetype (caps, "audio/x-alaw")))
|
|
|
|
return result;
|
|
|
|
if ((result = gst_alsa_fixate_to_mimetype (caps, "audio/x-mulaw")))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* now we know there's only one mimetype in the caps */
|
|
|
|
/* FIXME: I should check this to be really sure I didn't mess up somewhere */
|
|
|
|
|
|
|
|
if ((result = gst_alsa_fixate_field_nearest_int (caps, "rate", 44100)))
|
|
|
|
return result;
|
|
|
|
if ((result = gst_alsa_fixate_field_nearest_int (caps, "channels", 2)))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
mime = gst_structure_get_name (gst_caps_get_structure (caps, 0));
|
|
|
|
if (g_str_equal (mime, "audio/x-raw-int")) {
|
|
|
|
if ((result = gst_alsa_fixate_field_nearest_int (caps, "width", 16)))
|
|
|
|
return result;
|
|
|
|
if ((result = gst_alsa_fixate_field_nearest_int (caps, "depth", 16)))
|
|
|
|
return result;
|
|
|
|
} else if (g_str_equal (mime, "audio/x-raw-float")) {
|
|
|
|
if ((result = gst_alsa_fixate_field_nearest_int (caps, "width", 32)))
|
|
|
|
return result;
|
|
|
|
}
|
2004-03-09 21:29:56 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* Negotiates the caps */
|
|
|
|
GstPadLinkReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_link (GstPad * pad, const GstCaps * caps)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-04-24 00:03:06 +00:00
|
|
|
GstAlsa *this;
|
|
|
|
GstAlsaFormat *format;
|
|
|
|
GstPadLinkReturn ret;
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
|
|
|
|
g_return_val_if_fail (pad != NULL, GST_PAD_LINK_REFUSED);
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
this = GST_ALSA (gst_pad_get_parent (pad));
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
if (this->handle == NULL)
|
|
|
|
if (!gst_alsa_open_audio (this))
|
2003-12-06 00:02:20 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2003-04-13 04:13:12 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
format = gst_alsa_get_format (gst_caps_get_structure (caps, 0));
|
|
|
|
if (format == NULL)
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_DEBUG ("found format %s", snd_pcm_format_name (format->format));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
if (!GST_FLAG_IS_SET (this, GST_ALSA_CAPS_NEGO)) {
|
|
|
|
gint i;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_FLAG_SET (this, GST_ALSA_CAPS_NEGO);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
if (gst_alsa_formats_match (this->format, format)) {
|
|
|
|
ret = GST_PAD_LINK_OK;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
if (!gst_alsa_probe_hw_params (this, format)) {
|
|
|
|
ret = GST_PAD_LINK_REFUSED;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
for (i = 0; i < ((GstElement *) this)->numpads; i++) {
|
|
|
|
g_assert (this->pad[i] != NULL);
|
|
|
|
if (this->pad[i] == pad)
|
2004-03-15 19:32:28 +00:00
|
|
|
continue;
|
2003-12-22 01:47:09 +00:00
|
|
|
if (gst_pad_try_set_caps (this->pad[i], caps) == GST_PAD_LINK_REFUSED) {
|
2004-03-15 19:32:28 +00:00
|
|
|
if (this->format) {
|
|
|
|
GstCaps *old =
|
|
|
|
gst_alsa_caps (this->format->format, this->format->rate,
|
|
|
|
this->format->channels);
|
|
|
|
|
|
|
|
for (--i; i >= 0; i--) {
|
|
|
|
if (gst_pad_try_set_caps (this->pad[i],
|
|
|
|
old) == GST_PAD_LINK_REFUSED) {
|
|
|
|
GST_ELEMENT_ERROR (this, CORE, NEGOTIATION, (NULL),
|
|
|
|
("could not reset caps to a sane value"));
|
|
|
|
gst_caps_free (old);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* FIXME: unset caps on pads somehow */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_caps_free (old);
|
|
|
|
ret = GST_PAD_LINK_REFUSED;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
2003-12-22 16:38:00 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-12-22 16:38:00 +00:00
|
|
|
GST_FLAG_UNSET (this, GST_ALSA_CAPS_NEGO);
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2003-12-22 16:38:00 +00:00
|
|
|
/* sync the params */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (GST_FLAG_IS_SET (this, GST_ALSA_RUNNING))
|
|
|
|
gst_alsa_stop_audio (this);
|
2003-12-22 16:38:00 +00:00
|
|
|
g_free (this->format);
|
|
|
|
this->format = format;
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_alsa_start_audio (this)) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (this, RESOURCE, SETTINGS, (NULL), (NULL));
|
2003-12-22 16:38:00 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2003-03-27 00:17:26 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
|
|
|
}
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2003-03-18 22:07:56 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
out:
|
|
|
|
g_free (format);
|
|
|
|
GST_FLAG_UNSET (this, GST_ALSA_CAPS_NEGO);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_change_state (GstElement * element)
|
2003-04-24 00:03:06 +00:00
|
|
|
{
|
2004-04-01 16:34:14 +00:00
|
|
|
int err = 0;
|
2003-04-24 00:03:06 +00:00
|
|
|
GstAlsa *this;
|
|
|
|
|
|
|
|
g_return_val_if_fail (element != NULL, FALSE);
|
|
|
|
this = GST_ALSA (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
2004-03-14 22:34:34 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
if (!(GST_FLAG_IS_SET (element, GST_ALSA_OPEN) ||
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_alsa_open_audio (this)))
|
|
|
|
return GST_STATE_FAILURE;
|
2004-03-14 22:34:34 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
if (!(GST_FLAG_IS_SET (element, GST_ALSA_RUNNING) ||
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_alsa_start_audio (this)))
|
|
|
|
return GST_STATE_FAILURE;
|
2004-06-23 18:08:26 +00:00
|
|
|
this->played = 0;
|
|
|
|
this->captured = 0;
|
2004-03-14 22:34:34 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
if (snd_pcm_state (this->handle) == SND_PCM_STATE_PAUSED) {
|
2004-03-15 19:32:28 +00:00
|
|
|
if ((err = snd_pcm_pause (this->handle, 0)) < 0) {
|
|
|
|
GST_ERROR_OBJECT (this, "Error unpausing sound: %s",
|
|
|
|
snd_strerror (err));
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
} else if (!(GST_FLAG_IS_SET (element, GST_ALSA_RUNNING) ||
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_alsa_start_audio (this))) {
|
|
|
|
return GST_STATE_FAILURE;
|
2003-03-27 00:17:26 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_clock_start (this->clock);
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
if (GST_ALSA_CAPS_IS_SET (this, GST_ALSA_CAPS_PAUSE)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
if (snd_pcm_state (this->handle) == SND_PCM_STATE_RUNNING) {
|
|
|
|
if ((err = snd_pcm_pause (this->handle, 1)) < 0) {
|
|
|
|
GST_ERROR_OBJECT (this, "Error pausing sound: %s",
|
|
|
|
snd_strerror (err));
|
2004-04-01 16:34:14 +00:00
|
|
|
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_PAUSE, 0);
|
|
|
|
goto cant_pause;
|
2004-03-15 19:32:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2004-04-01 16:34:14 +00:00
|
|
|
cant_pause:
|
2004-03-15 19:32:28 +00:00
|
|
|
/* if device doesn't know how to pause, we just stop */
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_ALSA_RUNNING))
|
|
|
|
gst_alsa_stop_audio (this);
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_clock_stop (this->clock);
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_ALSA_RUNNING))
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_alsa_stop_audio (this);
|
2004-03-14 22:34:34 +00:00
|
|
|
g_free (this->format);
|
|
|
|
this->format = NULL;
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_ALSA_OPEN))
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_alsa_close_audio (this);
|
2004-03-14 22:34:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
2003-03-10 21:30:00 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
2003-11-16 00:40:01 +00:00
|
|
|
|
|
|
|
static GstClock *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_get_clock (GstElement * element)
|
|
|
|
{
|
|
|
|
return GST_CLOCK (GST_ALSA (element)->clock);
|
|
|
|
}
|
2003-11-16 00:40:01 +00:00
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_set_clock (GstElement * element, GstClock * clock)
|
2004-03-15 19:32:28 +00:00
|
|
|
{ /* we need this function just so everybody knows we use a clock */
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/*** AUDIO PROCESSING *********************************************************/
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
inline snd_pcm_sframes_t
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_update_avail (GstAlsa * this)
|
2003-04-24 00:03:06 +00:00
|
|
|
{
|
2004-06-23 16:57:16 +00:00
|
|
|
snd_pcm_sframes_t avail = snd_pcm_avail_update (this->handle);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-06-23 16:57:16 +00:00
|
|
|
if (avail < 0) {
|
|
|
|
if (avail == -EPIPE) {
|
|
|
|
gst_alsa_xrun_recovery (this);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (this, "unknown ALSA avail_update return value (%d)",
|
|
|
|
(int) avail);
|
2003-04-24 00:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return avail;
|
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* returns TRUE, if the loop should go on */
|
2003-11-16 00:40:01 +00:00
|
|
|
inline gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_pcm_wait (GstAlsa * this)
|
2003-04-24 00:03:06 +00:00
|
|
|
{
|
|
|
|
int err;
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
if (snd_pcm_state (this->handle) == SND_PCM_STATE_RUNNING) {
|
|
|
|
if ((err = snd_pcm_wait (this->handle, 1000)) < 0) {
|
|
|
|
if (err == EINTR) {
|
2004-03-15 19:32:28 +00:00
|
|
|
/* happens mostly when run under gdb, or when exiting due to a signal */
|
|
|
|
GST_DEBUG ("got interrupted while waiting");
|
|
|
|
if (gst_element_interrupt (GST_ELEMENT (this))) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
2004-02-14 09:06:06 +00:00
|
|
|
if (!gst_alsa_xrun_recovery (this)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ERROR_OBJECT (this, "error waiting for alsa pcm: (%d: %s)", err,
|
|
|
|
snd_strerror (err));
|
|
|
|
return FALSE;
|
2004-02-14 09:06:06 +00:00
|
|
|
}
|
2003-03-10 21:30:00 +00:00
|
|
|
}
|
2003-03-18 22:07:56 +00:00
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/**
|
|
|
|
* error out or make sure we're in SND_PCM_STATE_RUNNING afterwards
|
|
|
|
* return FALSE if we're not
|
|
|
|
*/
|
2003-11-16 00:40:01 +00:00
|
|
|
inline gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_start (GstAlsa * this)
|
2003-04-24 00:03:06 +00:00
|
|
|
{
|
2004-06-23 18:08:26 +00:00
|
|
|
GstClockTime elemnow;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("Setting state to RUNNING");
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
switch (snd_pcm_state (this->handle)) {
|
2003-04-24 00:03:06 +00:00
|
|
|
case SND_PCM_STATE_XRUN:
|
|
|
|
gst_alsa_xrun_recovery (this);
|
|
|
|
return gst_alsa_start (this);
|
|
|
|
case SND_PCM_STATE_SETUP:
|
|
|
|
ERROR_CHECK (snd_pcm_prepare (this->handle), "error preparing: %s");
|
|
|
|
case SND_PCM_STATE_SUSPENDED:
|
|
|
|
case SND_PCM_STATE_PREPARED:
|
2004-06-23 18:08:26 +00:00
|
|
|
/* The strategy to recover the timestamps from the xrun is to take the
|
|
|
|
* current element time and pretend we just sent all the samples up to
|
|
|
|
* that time. This will result in an offset discontinuity in the next
|
|
|
|
* buffer along with the correct timestamp on that buffer, we only
|
|
|
|
* update the capture timestamps */
|
|
|
|
elemnow = gst_element_get_time (GST_ELEMENT (this));
|
|
|
|
this->captured = gst_alsa_timestamp_to_samples (this, elemnow);
|
2004-03-14 22:34:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_start (this->handle), "error starting playback: %s");
|
2003-04-24 00:03:06 +00:00
|
|
|
break;
|
|
|
|
case SND_PCM_STATE_PAUSED:
|
|
|
|
ERROR_CHECK (snd_pcm_pause (this->handle, 0), "error unpausing: %s");
|
|
|
|
break;
|
|
|
|
case SND_PCM_STATE_RUNNING:
|
|
|
|
break;
|
|
|
|
case SND_PCM_STATE_DRAINING:
|
|
|
|
case SND_PCM_STATE_OPEN:
|
|
|
|
/* this probably happens when someone replugged a pipeline and we're in a
|
|
|
|
really weird state because our cothread wasn't busted */
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
/* it's a bug when we get here */
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2003-02-27 23:13:22 +00:00
|
|
|
}
|
2003-04-24 00:03:06 +00:00
|
|
|
return TRUE;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
2004-02-14 09:06:06 +00:00
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_xrun_recovery (GstAlsa * this)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-01-27 12:59:24 +00:00
|
|
|
snd_pcm_status_t *status;
|
|
|
|
gint err;
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
snd_pcm_status_alloca (&status);
|
2002-05-21 05:38:38 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
if ((err = snd_pcm_status (this->handle, status)) < 0)
|
2003-10-12 17:03:59 +00:00
|
|
|
GST_ERROR_OBJECT (this, "status error: %s", snd_strerror (err));
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
if (snd_pcm_status_get_state (status) == SND_PCM_STATE_XRUN) {
|
2004-06-17 14:10:21 +00:00
|
|
|
|
2003-02-27 23:13:22 +00:00
|
|
|
/* if we're allowed to recover, ... */
|
2003-02-09 22:47:34 +00:00
|
|
|
if (this->autorecover) {
|
2003-02-27 23:13:22 +00:00
|
|
|
/* ... then increase the period size or buffer size / period count to
|
|
|
|
prevent further xruns (at the cost of increased latency and memory
|
|
|
|
usage). */
|
2003-02-09 22:47:34 +00:00
|
|
|
if (this->period_count >= 4) {
|
2004-03-15 19:32:28 +00:00
|
|
|
this->period_size *= 2;
|
|
|
|
this->period_count /= 2;
|
2003-02-09 22:47:34 +00:00
|
|
|
} else {
|
2004-03-15 19:32:28 +00:00
|
|
|
this->period_count *= 2;
|
2003-02-09 22:47:34 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2004-06-23 18:08:26 +00:00
|
|
|
/* prepare the device again */
|
|
|
|
if ((err = snd_pcm_prepare (this->handle)) < 0) {
|
|
|
|
GST_ERROR_OBJECT (this, "prepare error: %s", snd_strerror (err));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!gst_alsa_start (this)) {
|
|
|
|
GST_ELEMENT_ERROR (this, RESOURCE, FAILED, (NULL),
|
|
|
|
("Error starting audio after xrun"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (this, "XRun!!!! pretending we captured %lld samples",
|
|
|
|
this->captured);
|
|
|
|
} else {
|
|
|
|
if (!(gst_alsa_stop_audio (this) && gst_alsa_start_audio (this))) {
|
|
|
|
GST_ELEMENT_ERROR (this, RESOURCE, FAILED, (NULL),
|
|
|
|
("Error restarting audio after xrun"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
2004-02-14 09:06:06 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
2002-05-27 04:48:57 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
/*** AUDIO SETUP / START / STOP ***********************************************/
|
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_set_eos (GstAlsa * this)
|
2003-04-11 00:24:19 +00:00
|
|
|
{
|
|
|
|
gst_alsa_drain_audio (this);
|
|
|
|
gst_element_set_eos (GST_ELEMENT (this));
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_open_audio (GstAlsa * this)
|
2003-01-27 12:59:24 +00:00
|
|
|
{
|
2004-03-15 06:34:44 +00:00
|
|
|
snd_pcm_info_t *info;
|
2004-06-01 15:14:09 +00:00
|
|
|
int ret;
|
2004-03-15 06:34:44 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
g_assert (this != NULL);
|
|
|
|
g_assert (this->handle == NULL);
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-15 06:34:44 +00:00
|
|
|
/* If we have no pads, then we're apparently a mixer object,
|
|
|
|
* and that doesn't need a handle to the actual audio device. */
|
|
|
|
if (!gst_element_get_pad_list (GST_ELEMENT (this)))
|
|
|
|
return TRUE;
|
|
|
|
|
2004-03-24 18:48:55 +00:00
|
|
|
GST_INFO ("Opening alsa device \"%s\"...", this->device);
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-06-06 17:26:54 +00:00
|
|
|
ERROR_CHECK (snd_output_buffer_open (&this->out),
|
2004-03-14 22:34:34 +00:00
|
|
|
"error opening log output: %s");
|
|
|
|
|
2004-06-01 15:14:09 +00:00
|
|
|
if ((ret = snd_pcm_open (&this->handle, this->device,
|
|
|
|
GST_ALSA_GET_CLASS (this)->stream, SND_PCM_NONBLOCK)) < 0) {
|
|
|
|
/* ALSA inverts standard errno.h error codes */
|
|
|
|
switch (-ret) {
|
|
|
|
case EBUSY:
|
|
|
|
GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, BUSY,
|
|
|
|
(_("ALSA device \"%s\" is already in use by another program."),
|
|
|
|
this->device), (NULL));
|
|
|
|
break;
|
|
|
|
case EACCES:
|
|
|
|
case ETXTBSY:
|
|
|
|
GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, OPEN_READ_WRITE,
|
|
|
|
(_("Could not access ALSA device \"%s\", check its permissions."),
|
|
|
|
this->device), GST_ERROR_SYSTEM);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENXIO:
|
|
|
|
case ENODEV:
|
|
|
|
case ENOENT:
|
|
|
|
GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, BUSY,
|
|
|
|
(_("ALSA device \"%s\" does not exist."), this->device), (NULL));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, BUSY,
|
|
|
|
(_("ALSA device \"%s\" had an error."),
|
|
|
|
this->device), ("ALSA error %d: %s", ret, snd_strerror (ret)));
|
|
|
|
break;
|
|
|
|
}
|
ext/alsa/gstalsa.c: Alsa should trigger an error if it failed opening the audio device.
Original commit message from CVS:
2004-02-16 Julien MOUTTE <julien@moutte.net>
* ext/alsa/gstalsa.c: (gst_alsa_open_audio),
(gst_alsa_timestamp_to_bytes): Alsa should trigger an error if it
failed opening the audio device.
* sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new),
(gst_ximagesink_ximage_destroy), (gst_ximagesink_ximage_put),
(gst_ximagesink_xwindow_new), (gst_ximagesink_xwindow_destroy),
(gst_ximagesink_xwindow_resize), (gst_ximagesink_xwindow_clear),
(gst_ximagesink_renegotiate_size), (gst_ximagesink_handle_xevents),
(gst_ximagesink_xcontext_get), (gst_ximagesink_xcontext_clear),
(gst_ximagesink_change_state), (gst_ximagesink_chain),
(gst_ximagesink_set_xwindow_id): Clearing window in READY TO PAUSED.
Removing some useless g_return_if_fail like wingo suggested.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xvimage_new),
(gst_xvimagesink_xvimage_destroy), (gst_xvimagesink_xvimage_put),
(gst_xvimagesink_xwindow_new), (gst_xvimagesink_xwindow_destroy),
(gst_xvimagesink_xwindow_resize), (gst_xvimagesink_xwindow_clear),
(gst_xvimagesink_update_colorbalance),
(gst_xvimagesink_handle_xevents), (gst_xvimagesink_xcontext_get),
(gst_xvimagesink_xcontext_clear),
(gst_xvimagesink_get_fourcc_from_caps),
(gst_xvimagesink_change_state), (gst_xvimagesink_chain),
(gst_xvimagesink_set_xwindow_id),
(gst_xvimagesink_colorbalance_list_channels),
(gst_xvimagesink_colorbalance_set_value),
(gst_xvimagesink_colorbalance_get_value): Clearing window in READY TO
PAUSED. Removing some useless g_return_if_fail like wingo suggested.
2004-02-16 16:24:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-15 06:34:44 +00:00
|
|
|
snd_pcm_info_malloc (&info);
|
|
|
|
snd_pcm_info (this->handle, info);
|
|
|
|
this->cardname = g_strdup (snd_pcm_info_get_name (info));
|
|
|
|
snd_pcm_info_free (info);
|
ext/alsa/gstalsa.*: Add propertyprobe interface implementation, add some device-name property, all this so that it lo...
Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_type), (gst_alsa_class_init),
(gst_alsa_get_property), (gst_alsa_probe_get_properties),
(gst_alsa_class_probe_devices), (gst_alsa_class_list_devices),
(gst_alsa_probe_probe_property), (gst_alsa_probe_needs_probe),
(gst_alsa_probe_get_values), (gst_alsa_probe_interface_init),
(gst_alsa_open_audio), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
Add propertyprobe interface implementation, add some device-name
property, all this so that it looks good in gnome-volume-control.
2004-03-13 04:44:50 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
GST_FLAG_SET (this, GST_ALSA_OPEN);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
void
|
|
|
|
gst_alsa_sw_params_dump (GstAlsa * this, snd_pcm_sw_params_t * sw_params)
|
|
|
|
{
|
|
|
|
snd_pcm_sw_params_dump (sw_params, this->out);
|
|
|
|
ALSA_DEBUG_FLUSH (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_alsa_hw_params_dump (GstAlsa * this, snd_pcm_hw_params_t * hw_params)
|
|
|
|
{
|
|
|
|
snd_pcm_hw_params_dump (hw_params, this->out);
|
|
|
|
ALSA_DEBUG_FLUSH (this);
|
|
|
|
}
|
|
|
|
|
2003-03-24 03:45:45 +00:00
|
|
|
/* if someone finds an easy way to merge this with _set_hw_params, go ahead */
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_probe_hw_params (GstAlsa * this, GstAlsaFormat * format)
|
2003-03-24 03:45:45 +00:00
|
|
|
{
|
|
|
|
snd_pcm_hw_params_t *hw_params;
|
|
|
|
snd_pcm_uframes_t period_size;
|
|
|
|
unsigned int period_count;
|
2004-06-14 20:30:36 +00:00
|
|
|
unsigned int rate;
|
2003-03-24 03:45:45 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (this != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (format != NULL, FALSE);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-24 18:48:55 +00:00
|
|
|
GST_INFO ("Probing format: %s %dHz, %d channels",
|
2004-03-14 22:34:34 +00:00
|
|
|
snd_pcm_format_name (format->format), format->rate, format->channels);
|
2003-03-24 03:45:45 +00:00
|
|
|
|
|
|
|
snd_pcm_hw_params_alloca (&hw_params);
|
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_any (this->handle, hw_params));
|
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
gst_alsa_hw_params_dump (this, hw_params);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-03-24 03:45:45 +00:00
|
|
|
if (GST_ELEMENT (this)->numpads == 1) {
|
2004-06-06 17:26:54 +00:00
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_set_access (this->handle,
|
|
|
|
hw_params, this->
|
|
|
|
mmap ? SND_PCM_ACCESS_MMAP_INTERLEAVED :
|
|
|
|
SND_PCM_ACCESS_RW_INTERLEAVED));
|
2003-03-24 03:45:45 +00:00
|
|
|
} else {
|
2004-06-06 17:26:54 +00:00
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_set_access (this->handle,
|
|
|
|
hw_params, this->
|
|
|
|
mmap ? SND_PCM_ACCESS_MMAP_NONINTERLEAVED :
|
|
|
|
SND_PCM_ACCESS_RW_NONINTERLEAVED));
|
2003-03-24 03:45:45 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_set_format (this->handle, hw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
format->format));
|
2004-03-14 22:34:34 +00:00
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_set_channels (this->handle, hw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
format->channels));
|
2004-06-14 20:30:36 +00:00
|
|
|
/* FIXME: We should use snd_pcm_hw_params_set_rate instead of
|
|
|
|
* snd_pcm_hw_params_set_rate_near here. Unfortunately alsa fails in that case
|
|
|
|
* far more often and seems to handle this quite well. (Example: ENS1371
|
|
|
|
* driver on alsalib 1.0.5, kernel 2.6.6-mm5). If it sets far too wrong sample
|
|
|
|
* rates, we need to revert back to snd_pcm_hw_params_set_rate or check the
|
|
|
|
* rate that was set.
|
|
|
|
*/
|
|
|
|
rate = format->rate;
|
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_set_rate_near (this->handle, hw_params,
|
|
|
|
&rate, 0));
|
|
|
|
if (rate != format->rate)
|
|
|
|
GST_WARNING_OBJECT (this, "set rate (%u) differs from desired rate (%u)",
|
|
|
|
rate, format->rate);
|
2003-03-24 03:45:45 +00:00
|
|
|
|
|
|
|
period_count = this->period_count;
|
2004-03-14 22:34:34 +00:00
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_set_periods_near (this->handle,
|
2004-03-15 19:32:28 +00:00
|
|
|
hw_params, &period_count, 0));
|
2003-03-24 03:45:45 +00:00
|
|
|
period_size = this->period_size;
|
2004-03-14 22:34:34 +00:00
|
|
|
SIMPLE_ERROR_CHECK (snd_pcm_hw_params_set_period_size_near (this->handle,
|
2004-03-15 19:32:28 +00:00
|
|
|
hw_params, &period_size, 0));
|
2003-03-24 03:45:45 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-03-18 22:07:56 +00:00
|
|
|
/**
|
|
|
|
* You must set all hw parameters at once and can't use already set params and
|
|
|
|
* change them.
|
|
|
|
* Thx ALSA for not documenting this
|
|
|
|
*/
|
2003-02-09 22:47:34 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_set_hw_params (GstAlsa * this)
|
2003-02-09 22:47:34 +00:00
|
|
|
{
|
|
|
|
snd_pcm_hw_params_t *hw_params;
|
2004-06-14 20:30:36 +00:00
|
|
|
unsigned int rate;
|
2003-03-22 02:17:08 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
g_return_val_if_fail (this != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (this->handle != NULL, FALSE);
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
snd_pcm_hw_params_alloca (&hw_params);
|
2003-03-24 03:45:45 +00:00
|
|
|
ERROR_CHECK (snd_pcm_hw_params_any (this->handle, hw_params),
|
2004-03-14 22:34:34 +00:00
|
|
|
"Broken configuration for this PCM: %s");
|
2003-03-19 22:54:36 +00:00
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
if (this->format) {
|
|
|
|
GST_INFO ("Preparing format: %s %dHz, %d channels",
|
|
|
|
snd_pcm_format_name (this->format->format), this->format->rate,
|
|
|
|
this->format->channels);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
if (GST_ELEMENT (this)->numpads == 1) {
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_set_access (this->handle, hw_params, this->
|
|
|
|
mmap ? SND_PCM_ACCESS_MMAP_INTERLEAVED :
|
|
|
|
SND_PCM_ACCESS_RW_INTERLEAVED),
|
|
|
|
"This plugin does not support your harware: %s");
|
|
|
|
} else {
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_set_access (this->handle, hw_params, this->
|
|
|
|
mmap ? SND_PCM_ACCESS_MMAP_NONINTERLEAVED :
|
|
|
|
SND_PCM_ACCESS_RW_NONINTERLEAVED),
|
|
|
|
"This plugin does not support your harware: %s");
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_set_format (this->handle, hw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
this->format->format), "Sample format (%s) not available: %s",
|
|
|
|
snd_pcm_format_name (this->format->format));
|
2004-03-14 22:34:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_hw_params_set_channels (this->handle, hw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
this->format->channels), "Channels count (%d) not available: %s",
|
|
|
|
this->format->channels);
|
2004-06-14 20:30:36 +00:00
|
|
|
/* FIXME: We should use snd_pcm_hw_params_set_rate instead of
|
|
|
|
* snd_pcm_hw_params_set_rate_near here. Unfortunately alsa fails in that case
|
|
|
|
* far more often and seems to handle this quite well. (Example: ENS1371
|
|
|
|
* driver on alsalib 1.0.5, kernel 2.6.6-mm5). If it sets far too wrong sample
|
|
|
|
* rates, we need to revert back to snd_pcm_hw_params_set_rate or check the
|
|
|
|
* rate that was set.
|
|
|
|
*/
|
|
|
|
rate = this->format->rate;
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_set_rate_near (this->handle, hw_params,
|
|
|
|
&rate, 0), "error setting rate (%d): %s", this->format->rate);
|
|
|
|
if (rate != this->format->rate)
|
|
|
|
GST_WARNING_OBJECT (this, "set rate (%u) differs from desired rate (%u)",
|
|
|
|
rate, this->format->rate);
|
2004-06-09 17:06:40 +00:00
|
|
|
ERROR_CHECK (snd_pcm_hw_params_set_periods_near (this->handle, hw_params,
|
|
|
|
&this->period_count, 0), "error setting period count to %u: %s",
|
|
|
|
(guint) this->period_count);
|
|
|
|
ERROR_CHECK (snd_pcm_hw_params_set_period_size_near (this->handle,
|
|
|
|
hw_params, &this->period_size, 0),
|
|
|
|
"error setting period size to %u frames: %s",
|
|
|
|
(guint) this->period_size);
|
|
|
|
} else {
|
|
|
|
GST_INFO_OBJECT (this, "Preparing format: (none)");
|
2003-03-19 22:54:36 +00:00
|
|
|
}
|
2004-06-09 17:06:40 +00:00
|
|
|
gst_alsa_hw_params_dump (this, hw_params);
|
2003-02-09 22:47:34 +00:00
|
|
|
|
|
|
|
|
2003-03-24 03:45:45 +00:00
|
|
|
ERROR_CHECK (snd_pcm_hw_params (this->handle, hw_params),
|
2004-03-14 22:34:34 +00:00
|
|
|
"Could not set hardware parameters: %s");
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2003-03-18 22:07:56 +00:00
|
|
|
/* now get the pcm caps */
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_PAUSE,
|
|
|
|
snd_pcm_hw_params_can_pause (hw_params));
|
|
|
|
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_RESUME,
|
|
|
|
snd_pcm_hw_params_can_resume (hw_params));
|
|
|
|
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_SYNC_START,
|
|
|
|
snd_pcm_hw_params_can_sync_start (hw_params));
|
|
|
|
|
2003-03-22 01:17:06 +00:00
|
|
|
if (this->mmap) {
|
2003-04-24 00:03:06 +00:00
|
|
|
this->transmit = GST_ALSA_GET_CLASS (this)->transmit_mmap;
|
2003-03-22 01:17:06 +00:00
|
|
|
} else {
|
2003-04-24 00:03:06 +00:00
|
|
|
this->transmit = GST_ALSA_GET_CLASS (this)->transmit_rw;
|
2003-03-22 01:17:06 +00:00
|
|
|
}
|
2003-03-22 02:17:08 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
return TRUE;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-23 00:25:30 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_set_sw_params (GstAlsa * this)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-02-09 22:47:34 +00:00
|
|
|
snd_pcm_sw_params_t *sw_params;
|
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
if (!this->format) {
|
|
|
|
GST_LOG_OBJECT (this, "not setting sw params, we're not negotiated yet");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
snd_pcm_sw_params_alloca (&sw_params);
|
|
|
|
ERROR_CHECK (snd_pcm_sw_params_current (this->handle, sw_params),
|
2004-03-14 22:34:34 +00:00
|
|
|
"Could not get current software parameters: %s");
|
|
|
|
|
2004-06-09 17:06:40 +00:00
|
|
|
gst_alsa_sw_params_dump (this, sw_params);
|
2004-06-06 17:26:54 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_sw_params_set_silence_size (this->handle, sw_params, 0),
|
2004-03-14 22:34:34 +00:00
|
|
|
"could not set silence size: %s");
|
|
|
|
ERROR_CHECK (snd_pcm_sw_params_set_silence_threshold (this->handle, sw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
0), "could not set silence threshold: %s");
|
2004-03-14 22:34:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_sw_params_set_avail_min (this->handle, sw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
this->period_size), "could not set avail min: %s");
|
2003-03-18 22:07:56 +00:00
|
|
|
/* we start explicitly */
|
2004-03-14 22:34:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_sw_params_set_start_threshold (this->handle, sw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
this->period_size * this->period_count + 1),
|
2004-03-14 22:34:34 +00:00
|
|
|
"could not set start mode: %s");
|
|
|
|
ERROR_CHECK (snd_pcm_sw_params_set_stop_threshold (this->handle, sw_params,
|
2004-03-15 19:32:28 +00:00
|
|
|
this->period_size * this->period_count),
|
2004-03-14 22:34:34 +00:00
|
|
|
"could not set stop mode: %s");
|
|
|
|
ERROR_CHECK (snd_pcm_sw_params_set_xfer_align (this->handle, sw_params, 1),
|
|
|
|
"Unable to set transfer align for playback: %s");
|
2003-02-09 22:47:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_sw_params (this->handle, sw_params),
|
2004-03-14 22:34:34 +00:00
|
|
|
"could not set sw_params: %s");
|
2003-01-27 12:59:24 +00:00
|
|
|
return TRUE;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_start_audio (GstAlsa * this)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-03-24 03:45:45 +00:00
|
|
|
g_assert (GST_FLAG_IS_SET (this, GST_ALSA_OPEN));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-03-24 03:45:45 +00:00
|
|
|
if (!gst_alsa_set_hw_params (this))
|
2003-01-27 12:59:24 +00:00
|
|
|
return FALSE;
|
2003-02-09 22:47:34 +00:00
|
|
|
if (!gst_alsa_set_sw_params (this))
|
2004-06-06 17:26:54 +00:00
|
|
|
GST_WARNING_OBJECT (this,
|
|
|
|
"setting software parameters failed, we'll trust the defaults");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
GST_FLAG_SET (this, GST_ALSA_RUNNING);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_drain_audio (GstAlsa * this)
|
2003-04-11 00:24:19 +00:00
|
|
|
{
|
2003-02-09 22:47:34 +00:00
|
|
|
g_assert (this != NULL);
|
|
|
|
g_return_val_if_fail (this->handle != NULL, FALSE);
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("stopping alsa");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
switch (snd_pcm_state (this->handle)) {
|
|
|
|
case SND_PCM_STATE_XRUN:
|
|
|
|
case SND_PCM_STATE_RUNNING:
|
|
|
|
/* fall through - clock is already stopped when paused */
|
|
|
|
case SND_PCM_STATE_PAUSED:
|
|
|
|
/* snd_pcm_drain only works in blocking mode */
|
2004-03-14 22:34:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_nonblock (this->handle, 0),
|
2004-03-15 19:32:28 +00:00
|
|
|
"couldn't set blocking mode: %s");
|
2004-03-14 22:34:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_drain (this->handle),
|
2004-03-15 19:32:28 +00:00
|
|
|
"couldn't stop and drain buffer: %s");
|
2004-03-14 22:34:34 +00:00
|
|
|
ERROR_CHECK (snd_pcm_nonblock (this->handle, 1),
|
2004-03-15 19:32:28 +00:00
|
|
|
"couldn't set non-blocking mode: %s");
|
2003-04-24 00:03:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_FLAG_UNSET (this, GST_ALSA_RUNNING);
|
2003-01-27 12:59:24 +00:00
|
|
|
return TRUE;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_stop_audio (GstAlsa * this)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2003-01-27 12:59:24 +00:00
|
|
|
g_assert (this != NULL);
|
2003-02-09 22:47:34 +00:00
|
|
|
g_return_val_if_fail (this->handle != NULL, FALSE);
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("stopping alsa, skipping pending frames");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
switch (snd_pcm_state (this->handle)) {
|
|
|
|
case SND_PCM_STATE_XRUN:
|
|
|
|
case SND_PCM_STATE_RUNNING:
|
|
|
|
/* fall through - clock is already stopped when paused */
|
|
|
|
case SND_PCM_STATE_PAUSED:
|
|
|
|
ERROR_CHECK (snd_pcm_drop (this->handle),
|
2004-03-15 19:32:28 +00:00
|
|
|
"couldn't stop (dropping frames): %s");
|
2003-04-24 00:03:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2003-01-27 12:59:24 +00:00
|
|
|
}
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_FLAG_UNSET (this, GST_ALSA_RUNNING);
|
2003-02-09 22:47:34 +00:00
|
|
|
return TRUE;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_close_audio (GstAlsa * this)
|
2001-12-23 00:25:30 +00:00
|
|
|
{
|
2004-06-06 17:26:54 +00:00
|
|
|
gint err;
|
|
|
|
|
2004-03-15 06:34:44 +00:00
|
|
|
/* if there's no pads, we never open. So we don't close either. */
|
|
|
|
if (!gst_element_get_pad_list (GST_ELEMENT (this)))
|
|
|
|
return TRUE;
|
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
g_return_val_if_fail (this != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (this->handle != NULL, FALSE);
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2004-06-06 17:26:54 +00:00
|
|
|
ALSA_DEBUG_FLUSH (this);
|
|
|
|
err = snd_output_close (this->out);
|
|
|
|
if (err != 0)
|
|
|
|
GST_ERROR_OBJECT (this, "failed to close debugging output: %s",
|
|
|
|
snd_strerror (err));
|
2003-02-27 23:13:22 +00:00
|
|
|
ERROR_CHECK (snd_pcm_close (this->handle), "Error closing device: %s");
|
2003-01-19 23:23:30 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
this->handle = NULL;
|
2004-03-15 06:34:44 +00:00
|
|
|
if (this->cardname) {
|
|
|
|
g_free (this->cardname);
|
|
|
|
this->cardname = NULL;
|
|
|
|
}
|
2004-04-01 16:34:14 +00:00
|
|
|
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_PAUSE, 0);
|
|
|
|
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_RESUME, 0);
|
|
|
|
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_SYNC_START, 0);
|
2003-01-27 12:59:24 +00:00
|
|
|
GST_FLAG_UNSET (this, GST_ALSA_OPEN);
|
2003-02-27 23:13:22 +00:00
|
|
|
|
2003-01-27 12:59:24 +00:00
|
|
|
return TRUE;
|
2001-12-23 00:25:30 +00:00
|
|
|
}
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
/*** QUERYING/FORMAT/CONVERSION FUNCTIONS *************************************/
|
|
|
|
|
|
|
|
static const GstFormat *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_get_formats (GstPad * pad)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_DEFAULT,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0
|
|
|
|
};
|
2004-03-15 06:34:44 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_pad_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
return gst_alsa_convert (GST_ALSA (GST_PAD_PARENT (pad)), src_format,
|
|
|
|
src_value, dest_format, dest_value);
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_convert (GstAlsa * this, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
if (src_format == *dest_format) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (this->format == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value = gst_alsa_bytes_to_samples (this, (guint) src_value);
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = gst_alsa_bytes_to_timestamp (this, (guint) src_value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value =
|
|
|
|
gst_alsa_timestamp_to_samples (this, (GstClockTime) src_value);
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value =
|
|
|
|
gst_alsa_timestamp_to_bytes (this, (GstClockTime) src_value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = gst_alsa_samples_to_timestamp (this, (guint) src_value);
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = gst_alsa_samples_to_bytes (this, (guint) src_value);
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstQueryType *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_get_query_types (GstPad * pad)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
static const GstQueryType query_types[] = {
|
|
|
|
GST_QUERY_LATENCY,
|
|
|
|
GST_QUERY_POSITION,
|
|
|
|
0,
|
|
|
|
};
|
2004-03-15 06:34:44 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
return query_types;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_query_func (GstElement * element, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GstAlsa *this = GST_ALSA (element);
|
|
|
|
|
|
|
|
switch (type) {
|
2004-03-14 22:34:34 +00:00
|
|
|
case GST_QUERY_LATENCY:{
|
2003-12-06 00:02:20 +00:00
|
|
|
snd_pcm_sframes_t delay;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
ERROR_CHECK (snd_pcm_delay (this->handle, &delay),
|
2004-03-15 19:32:28 +00:00
|
|
|
"Error getting delay: %s");
|
2004-03-14 22:34:34 +00:00
|
|
|
res =
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_alsa_convert (this, GST_FORMAT_DEFAULT, (gint64) delay, format,
|
|
|
|
value);
|
2003-12-06 00:02:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_POSITION:
|
2004-03-14 22:34:34 +00:00
|
|
|
res =
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_alsa_convert (this, GST_FORMAT_TIME,
|
|
|
|
gst_element_get_time (GST_ELEMENT (this)), format, value);
|
2003-12-06 00:02:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_query (GstElement * element, GstQueryType type, GstFormat * format,
|
|
|
|
gint64 * value)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
return gst_alsa_pad_query (GST_ALSA (element)->pad[0], type, format, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_pad_query (GstPad * pad, GstQueryType type, GstFormat * format,
|
|
|
|
gint64 * value)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
if (gst_alsa_query_func (GST_PAD_PARENT (pad), type, format, value))
|
|
|
|
return TRUE;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK
|
|
|
|
&& gst_pad_query (gst_pad_get_peer (pad), type, format, value))
|
2003-12-06 00:02:20 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-04-13 04:13:12 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
inline snd_pcm_uframes_t
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_timestamp_to_samples (GstAlsa * this, GstClockTime time)
|
2003-04-13 04:13:12 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
return (snd_pcm_uframes_t) ((time * this->format->rate +
|
2004-03-15 19:32:28 +00:00
|
|
|
this->format->rate / 2) / GST_SECOND);
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
inline GstClockTime
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_samples_to_timestamp (GstAlsa * this, snd_pcm_uframes_t samples)
|
2003-04-13 04:13:12 +00:00
|
|
|
{
|
2004-06-07 01:41:37 +00:00
|
|
|
return ((GstClockTime) samples) * GST_SECOND / this->format->rate;
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
inline snd_pcm_uframes_t
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_bytes_to_samples (GstAlsa * this, guint bytes)
|
2003-04-13 04:13:12 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
return bytes / (snd_pcm_format_physical_width (this->format->format) / 8) /
|
|
|
|
(GST_ELEMENT (this)->numpads == 1 ? this->format->channels : 1);
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
inline guint
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_samples_to_bytes (GstAlsa * this, snd_pcm_uframes_t samples)
|
2003-04-13 04:13:12 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
return samples * snd_pcm_format_physical_width (this->format->format) / 8 *
|
|
|
|
(GST_ELEMENT (this)->numpads == 1 ? this->format->channels : 1);
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
inline GstClockTime
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_bytes_to_timestamp (GstAlsa * this, guint bytes)
|
2003-04-13 04:13:12 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
return gst_alsa_samples_to_timestamp (this, gst_alsa_bytes_to_samples (this,
|
2004-03-15 19:32:28 +00:00
|
|
|
bytes));
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
inline guint
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_timestamp_to_bytes (GstAlsa * this, GstClockTime time)
|
2003-04-13 04:13:12 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
return gst_alsa_samples_to_bytes (this, gst_alsa_timestamp_to_samples (this,
|
2004-03-15 19:32:28 +00:00
|
|
|
time));
|
2003-04-13 04:13:12 +00:00
|
|
|
}
|