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
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2001-12-23 00:25:30 +00:00
|
|
|
|
|
|
|
#ifndef __GST_ALSA_H__
|
|
|
|
#define __GST_ALSA_H__
|
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
#define ALSA_PCM_NEW_HW_PARAMS_API
|
|
|
|
#define ALSA_PCM_NEW_SW_PARAMS_API
|
|
|
|
|
2001-12-23 04:38:38 +00:00
|
|
|
#include <alsa/asoundlib.h>
|
2004-04-30 01:20:54 +00:00
|
|
|
#include <alsa/control.h>
|
|
|
|
#include <alsa/error.h>
|
2001-12-23 00:25:30 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
|
2003-11-18 15:32:52 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (alsa_debug);
|
2003-11-16 00:40:01 +00:00
|
|
|
#define GST_CAT_DEFAULT alsa_debug
|
2001-12-23 00:25:30 +00:00
|
|
|
|
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
/* error checking for standard alsa functions */
|
2003-12-27 17:19:29 +00:00
|
|
|
/* NOTE: these functions require a GObject *this and can only be used in
|
|
|
|
functions that return TRUE on success and FALSE on error */
|
2003-11-16 00:40:01 +00:00
|
|
|
#define SIMPLE_ERROR_CHECK(value) G_STMT_START{ \
|
2004-03-24 18:48:55 +00:00
|
|
|
int err = (value); \
|
|
|
|
if (err < 0) { \
|
|
|
|
GST_WARNING_OBJECT (this, "\"" #value "\": %s", snd_strerror (err)); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
2003-11-16 00:40:01 +00:00
|
|
|
}G_STMT_END
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-04-13 04:13:12 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
#ifdef G_HAVE_ISO_VARARGS
|
|
|
|
#define ERROR_CHECK(value, ...) G_STMT_START{ \
|
|
|
|
int err = (value); \
|
|
|
|
if (err < 0) { \
|
2003-12-27 17:19:29 +00:00
|
|
|
GST_WARNING_OBJECT (this, __VA_ARGS__, snd_strerror (err)); \
|
2003-11-16 00:40:01 +00:00
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
}G_STMT_END
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
#elif defined(G_HAVE_GNUC_VARARGS)
|
|
|
|
#define ERROR_CHECK(value, args...) G_STMT_START{ \
|
|
|
|
int err = (value); \
|
|
|
|
if (err < 0) { \
|
2003-12-27 17:19:29 +00:00
|
|
|
GST_WARNING_OBJECT (this, ## args, snd_strerror (err)); \
|
2003-11-16 00:40:01 +00:00
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
}G_STMT_END
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define ERROR_CHECK(value, args...) G_STMT_START{ \
|
|
|
|
int err = (value); \
|
|
|
|
if (err < 0) { \
|
2003-12-27 17:19:29 +00:00
|
|
|
GST_WARNING_OBJECT (this, snd_strerror (err)); \
|
2003-11-16 00:40:01 +00:00
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
}G_STMT_END
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define GST_ALSA_MIN_RATE 8000
|
|
|
|
#define GST_ALSA_MAX_RATE 192000
|
2004-03-15 16:32:55 +00:00
|
|
|
#define GST_ALSA_MAX_TRACKS 64 /* we don't support more than 64 tracks */
|
|
|
|
#define GST_ALSA_MAX_CHANNELS 32 /* tracks can have up to 32 channels */
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
/* Mono is 1 channel ; the 5.1 standard is 6 channels. The value for
|
|
|
|
GST_ALSA_MAX_CHANNELS comes from alsa/mixer.h. */
|
2003-04-13 04:13:12 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
/* Max allowed discontinuity in time units between timestamp and playback
|
|
|
|
pointer before killing/inserting samples. This should be big enough to allow
|
|
|
|
smoothing errors on different video formats. */
|
|
|
|
#define GST_ALSA_DEFAULT_DISCONT (GST_SECOND / 10)
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
2004-03-15 16:32:55 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
#define GST_ALSA(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, GST_TYPE_ALSA, GstAlsa))
|
|
|
|
#define GST_ALSA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST(klass, GST_TYPE_ALSA, GstAlsaClass))
|
|
|
|
#define GST_ALSA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ALSA, GstAlsaClass))
|
|
|
|
#define GST_IS_ALSA(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, GST_TYPE_ALSA))
|
|
|
|
#define GST_IS_ALSA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE(klass, GST_TYPE_ALSA))
|
|
|
|
#define GST_TYPE_ALSA (gst_alsa_get_type())
|
2004-03-15 16:32:55 +00:00
|
|
|
|
|
|
|
enum {
|
2003-01-27 12:59:24 +00:00
|
|
|
GST_ALSA_OPEN = GST_ELEMENT_FLAG_LAST,
|
|
|
|
GST_ALSA_RUNNING,
|
2003-03-18 22:07:56 +00:00
|
|
|
GST_ALSA_CAPS_NEGO,
|
2003-01-27 12:59:24 +00:00
|
|
|
GST_ALSA_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 3,
|
2001-12-23 00:25:30 +00:00
|
|
|
};
|
2003-11-16 00:40:01 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
typedef enum {
|
2003-03-18 22:07:56 +00:00
|
|
|
GST_ALSA_CAPS_PAUSE = 0,
|
|
|
|
GST_ALSA_CAPS_RESUME,
|
|
|
|
GST_ALSA_CAPS_SYNC_START
|
2004-03-15 16:32:55 +00:00
|
|
|
/* add more */
|
|
|
|
} GstAlsaPcmCaps;
|
2003-11-16 00:40:01 +00:00
|
|
|
|
|
|
|
#define GST_ALSA_CAPS_IS_SET(obj, flag) (GST_ALSA (obj)->pcm_caps & (1<<(flag)))
|
|
|
|
#define GST_ALSA_CAPS_SET(obj, flag, set) G_STMT_START{ \
|
|
|
|
if (set) { (GST_ALSA (obj)->pcm_caps |= (1<<(flag))); } \
|
|
|
|
else { (GST_ALSA (obj)->pcm_caps &= ~(1<<(flag))); } \
|
2003-03-18 22:07:56 +00:00
|
|
|
}G_STMT_END
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-11-18 15:32:52 +00:00
|
|
|
typedef struct _GstAlsaClock GstAlsaClock;
|
|
|
|
typedef struct _GstAlsaClockClass GstAlsaClockClass;
|
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
typedef struct _GstAlsa GstAlsa;
|
|
|
|
typedef struct _GstAlsaClass GstAlsaClass;
|
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
typedef int (*GstAlsaTransmitFunction) (GstAlsa *this, snd_pcm_sframes_t *avail);
|
2003-03-22 01:17:06 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
typedef struct {
|
|
|
|
snd_pcm_format_t format;
|
|
|
|
guint rate;
|
|
|
|
gint channels;
|
|
|
|
} GstAlsaFormat;
|
2003-04-22 18:28:33 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
struct _GstAlsa {
|
|
|
|
GstElement parent;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
/* array of GstAlsaPads */
|
2004-03-15 16:32:55 +00:00
|
|
|
GstPad * pad[GST_ALSA_MAX_TRACKS];
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
gchar * device;
|
2004-03-15 16:34:26 +00:00
|
|
|
gchar * cardname;
|
2004-03-15 16:32:55 +00:00
|
|
|
snd_pcm_t * handle;
|
|
|
|
guint pcm_caps; /* capabilities of the pcm device, see GstAlsaPcmCaps */
|
|
|
|
snd_output_t * out;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
GstAlsaFormat * format; /* NULL if undefined */
|
|
|
|
gboolean mmap; /* use mmap transmit (fast) or read/write (sloooow) */
|
|
|
|
GstAlsaTransmitFunction transmit;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2003-02-09 22:47:34 +00:00
|
|
|
/* latency / performance parameters */
|
2004-03-15 16:32:55 +00:00
|
|
|
snd_pcm_uframes_t period_size;
|
|
|
|
unsigned int period_count;
|
2003-01-27 12:59:24 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
gboolean autorecover;
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-04-13 04:13:12 +00:00
|
|
|
/* clocking */
|
2004-03-15 16:32:55 +00:00
|
|
|
GstAlsaClock * clock; /* our provided clock */
|
|
|
|
snd_pcm_uframes_t transmitted; /* samples transmitted since last sync
|
|
|
|
This thing actually is our master clock.
|
|
|
|
We will event insert silent samples or
|
|
|
|
drop some to sync to incoming timestamps.
|
|
|
|
*/
|
|
|
|
GstClockTime max_discont; /* max difference between current
|
|
|
|
playback timestamp and buffers timestamps
|
|
|
|
*/
|
2003-04-13 04:13:12 +00:00
|
|
|
};
|
2003-11-16 00:40:01 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
struct _GstAlsaClass {
|
|
|
|
GstElementClass parent_class;
|
2003-04-24 00:03:06 +00:00
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
snd_pcm_stream_t stream;
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-04-24 00:03:06 +00:00
|
|
|
/* different transmit functions */
|
2004-03-15 16:32:55 +00:00
|
|
|
GstAlsaTransmitFunction transmit_mmap;
|
|
|
|
GstAlsaTransmitFunction transmit_rw;
|
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
|
|
|
|
|
|
|
/* autodetected devices available */
|
|
|
|
GList *devices;
|
2003-04-24 00:03:06 +00:00
|
|
|
};
|
2001-12-23 00:25:30 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
GType gst_alsa_get_type (void);
|
|
|
|
|
2004-03-15 16:32:55 +00:00
|
|
|
void gst_alsa_set_eos (GstAlsa * this);
|
|
|
|
GstPadLinkReturn gst_alsa_link (GstPad * pad,
|
|
|
|
const GstCaps * caps);
|
|
|
|
GstCaps * gst_alsa_get_caps (GstPad * pad);
|
|
|
|
GstCaps * gst_alsa_fixate (GstPad * pad,
|
|
|
|
const GstCaps * caps);
|
|
|
|
GstCaps * gst_alsa_caps (snd_pcm_format_t format,
|
|
|
|
gint rate,
|
|
|
|
gint channels);
|
2003-11-16 00:40:01 +00:00
|
|
|
|
|
|
|
/* audio processing functions */
|
2004-03-15 16:32:55 +00:00
|
|
|
inline snd_pcm_sframes_t gst_alsa_update_avail (GstAlsa * this);
|
|
|
|
inline gboolean gst_alsa_pcm_wait (GstAlsa * this);
|
|
|
|
inline gboolean gst_alsa_start (GstAlsa * this);
|
|
|
|
gboolean gst_alsa_xrun_recovery (GstAlsa * this);
|
2003-11-16 00:40:01 +00:00
|
|
|
|
|
|
|
/* format conversions */
|
2004-03-15 16:32:55 +00:00
|
|
|
inline snd_pcm_uframes_t gst_alsa_timestamp_to_samples (GstAlsa * this,
|
|
|
|
GstClockTime time);
|
|
|
|
inline GstClockTime gst_alsa_samples_to_timestamp (GstAlsa * this,
|
|
|
|
snd_pcm_uframes_t samples);
|
|
|
|
inline snd_pcm_uframes_t gst_alsa_bytes_to_samples (GstAlsa * this,
|
|
|
|
guint bytes);
|
|
|
|
inline guint gst_alsa_samples_to_bytes (GstAlsa * this,
|
|
|
|
snd_pcm_uframes_t samples);
|
|
|
|
inline GstClockTime gst_alsa_bytes_to_timestamp (GstAlsa * this,
|
|
|
|
guint bytes);
|
|
|
|
inline guint gst_alsa_timestamp_to_bytes (GstAlsa * this,
|
|
|
|
GstClockTime time);
|
2003-11-16 00:40:01 +00:00
|
|
|
|
|
|
|
G_END_DECLS
|
2004-03-15 16:32:55 +00:00
|
|
|
|
2003-11-16 00:40:01 +00:00
|
|
|
#endif /* __GST_ALSA_H__ */
|