2003-09-13 01:22:59 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wim.taymans@chello.be>
|
|
|
|
*
|
|
|
|
* gstosssink.c:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2004-01-19 13:50:39 +00:00
|
|
|
#include "gst/gst-i18n-plugin.h"
|
2003-09-13 01:22:59 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/soundcard.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2003-11-06 09:55:24 +00:00
|
|
|
#include <gst/propertyprobe/propertyprobe.h>
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
#include "gstosselement.h"
|
|
|
|
#include "gstossmixer.h"
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-09-13 01:22:59 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_DEVICE,
|
|
|
|
ARG_MIXERDEV,
|
2003-10-10 12:24:20 +00:00
|
|
|
ARG_DEVICE_NAME,
|
2003-09-13 01:22:59 +00:00
|
|
|
};
|
|
|
|
|
2003-11-05 12:20:43 +00:00
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_osselement_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Audio Mixer (OSS)",
|
|
|
|
"Generic/Audio",
|
|
|
|
"OSS-based mixer element",
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
|
|
|
|
|
|
|
static void gst_osselement_base_init (GstOssElementClass * klass);
|
|
|
|
static void gst_osselement_class_init (GstOssElementClass * klass);
|
|
|
|
|
|
|
|
static void gst_ossprobe_interface_init (GstPropertyProbeInterface * iface);
|
|
|
|
static void gst_osselement_init (GstOssElement * oss);
|
|
|
|
static void gst_osselement_dispose (GObject * object);
|
|
|
|
|
|
|
|
static void gst_osselement_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_osselement_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
static GstElementStateReturn gst_osselement_change_state (GstElement * element);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
/*static guint gst_osssrc_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_get_type (void)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
static GType osselement_type = 0;
|
|
|
|
|
|
|
|
if (!osselement_type) {
|
|
|
|
static const GTypeInfo osselement_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstOssElementClass),
|
|
|
|
(GBaseInitFunc) gst_osselement_base_init,
|
2003-09-13 01:22:59 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_osselement_class_init,
|
2003-09-13 01:22:59 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstOssElement),
|
2003-09-13 01:22:59 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_osselement_init
|
2003-09-13 01:22:59 +00:00
|
|
|
};
|
|
|
|
static const GInterfaceInfo ossiface_info = {
|
|
|
|
(GInterfaceInitFunc) gst_oss_interface_init,
|
|
|
|
NULL,
|
ext/alsa/gstalsamixer.c: Setting mixer interface type to HARDWARE.
Original commit message from CVS:
2004-01-15 Julien MOUTTE <julien@moutte.net>
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_interface_init): Setting
mixer interface type to HARDWARE.
* gst-libs/gst/mixer/mixer.c: (gst_mixer_class_init): Adding a default
type to SOFTWARE.
* gst-libs/gst/mixer/mixer.h: Adding mixer interface type and macro.
* gst-libs/gst/mixer/mixertrack.h: Adding mixertrack flag SOFTWARE.
* gst/volume/gstvolume.c: (gst_volume_interface_supported),
(gst_volume_interface_init), (gst_volume_list_tracks),
(gst_volume_set_volume), (gst_volume_get_volume),
(gst_volume_set_mute), (gst_volume_mixer_init),
(gst_volume_dispose), (gst_volume_get_type), (volume_class_init),
(volume_init): Implementing mixer interface.
* gst/volume/gstvolume.h: Adding tracklist for mixer interface.
* sys/oss/gstosselement.c: (gst_osselement_get_type),
(gst_osselement_change_state): Removing some trailing commas in
structures.
* sys/oss/gstossmixer.c: (gst_ossmixer_interface_init): Setting mixer
interface type to HARDWARE.
* sys/v4l/gstv4lcolorbalance.c:
(gst_v4l_color_balance_interface_init): Setting colorbalance interface
type to HARDWARE.
* sys/v4l2/gstv4l2colorbalance.c:
(gst_v4l2_color_balance_interface_init): Setting colorbalance
interface type to HARDWARE.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_chain): use exactly the
same code than ximagesink for event handling.
2004-01-15 15:50:10 +00:00
|
|
|
NULL
|
2003-09-13 01:22:59 +00:00
|
|
|
};
|
|
|
|
static const GInterfaceInfo ossmixer_info = {
|
|
|
|
(GInterfaceInitFunc) gst_ossmixer_interface_init,
|
|
|
|
NULL,
|
ext/alsa/gstalsamixer.c: Setting mixer interface type to HARDWARE.
Original commit message from CVS:
2004-01-15 Julien MOUTTE <julien@moutte.net>
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_interface_init): Setting
mixer interface type to HARDWARE.
* gst-libs/gst/mixer/mixer.c: (gst_mixer_class_init): Adding a default
type to SOFTWARE.
* gst-libs/gst/mixer/mixer.h: Adding mixer interface type and macro.
* gst-libs/gst/mixer/mixertrack.h: Adding mixertrack flag SOFTWARE.
* gst/volume/gstvolume.c: (gst_volume_interface_supported),
(gst_volume_interface_init), (gst_volume_list_tracks),
(gst_volume_set_volume), (gst_volume_get_volume),
(gst_volume_set_mute), (gst_volume_mixer_init),
(gst_volume_dispose), (gst_volume_get_type), (volume_class_init),
(volume_init): Implementing mixer interface.
* gst/volume/gstvolume.h: Adding tracklist for mixer interface.
* sys/oss/gstosselement.c: (gst_osselement_get_type),
(gst_osselement_change_state): Removing some trailing commas in
structures.
* sys/oss/gstossmixer.c: (gst_ossmixer_interface_init): Setting mixer
interface type to HARDWARE.
* sys/v4l/gstv4lcolorbalance.c:
(gst_v4l_color_balance_interface_init): Setting colorbalance interface
type to HARDWARE.
* sys/v4l2/gstv4l2colorbalance.c:
(gst_v4l2_color_balance_interface_init): Setting colorbalance
interface type to HARDWARE.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_chain): use exactly the
same code than ximagesink for event handling.
2004-01-15 15:50:10 +00:00
|
|
|
NULL
|
2003-09-13 01:22:59 +00:00
|
|
|
};
|
2003-11-06 09:55:24 +00:00
|
|
|
static const GInterfaceInfo ossprobe_info = {
|
|
|
|
(GInterfaceInitFunc) gst_ossprobe_interface_init,
|
|
|
|
NULL,
|
ext/alsa/gstalsamixer.c: Setting mixer interface type to HARDWARE.
Original commit message from CVS:
2004-01-15 Julien MOUTTE <julien@moutte.net>
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_interface_init): Setting
mixer interface type to HARDWARE.
* gst-libs/gst/mixer/mixer.c: (gst_mixer_class_init): Adding a default
type to SOFTWARE.
* gst-libs/gst/mixer/mixer.h: Adding mixer interface type and macro.
* gst-libs/gst/mixer/mixertrack.h: Adding mixertrack flag SOFTWARE.
* gst/volume/gstvolume.c: (gst_volume_interface_supported),
(gst_volume_interface_init), (gst_volume_list_tracks),
(gst_volume_set_volume), (gst_volume_get_volume),
(gst_volume_set_mute), (gst_volume_mixer_init),
(gst_volume_dispose), (gst_volume_get_type), (volume_class_init),
(volume_init): Implementing mixer interface.
* gst/volume/gstvolume.h: Adding tracklist for mixer interface.
* sys/oss/gstosselement.c: (gst_osselement_get_type),
(gst_osselement_change_state): Removing some trailing commas in
structures.
* sys/oss/gstossmixer.c: (gst_ossmixer_interface_init): Setting mixer
interface type to HARDWARE.
* sys/v4l/gstv4lcolorbalance.c:
(gst_v4l_color_balance_interface_init): Setting colorbalance interface
type to HARDWARE.
* sys/v4l2/gstv4l2colorbalance.c:
(gst_v4l2_color_balance_interface_init): Setting colorbalance
interface type to HARDWARE.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_chain): use exactly the
same code than ximagesink for event handling.
2004-01-15 15:50:10 +00:00
|
|
|
NULL
|
2003-11-06 09:55:24 +00:00
|
|
|
};
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
osselement_type = g_type_register_static (GST_TYPE_ELEMENT,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstOssElement", &osselement_info, 0);
|
2003-09-13 01:22:59 +00:00
|
|
|
g_type_add_interface_static (osselement_type,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_IMPLEMENTS_INTERFACE, &ossiface_info);
|
2003-09-13 01:22:59 +00:00
|
|
|
g_type_add_interface_static (osselement_type,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_MIXER, &ossmixer_info);
|
2003-11-06 09:55:24 +00:00
|
|
|
g_type_add_interface_static (osselement_type,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_PROPERTY_PROBE, &ossprobe_info);
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return osselement_type;
|
|
|
|
}
|
|
|
|
|
2003-11-05 12:20:43 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_base_init (GstOssElementClass * klass)
|
2003-11-05 12:20:43 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
2003-11-06 10:21:14 +00:00
|
|
|
klass->device_combinations = NULL;
|
|
|
|
|
2003-11-05 12:20:43 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_osselement_details);
|
|
|
|
}
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_class_init (GstOssElementClass * klass)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE,
|
|
|
|
g_param_spec_string ("device", "Device", "OSS device (/dev/dspN usually)",
|
2004-03-15 19:32:27 +00:00
|
|
|
"default", G_PARAM_READWRITE));
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIXERDEV,
|
|
|
|
g_param_spec_string ("mixerdev", "Mixer device",
|
2004-03-15 19:32:27 +00:00
|
|
|
"OSS mixer device (/dev/mixerN usually)",
|
|
|
|
"default", G_PARAM_READWRITE));
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE_NAME,
|
|
|
|
g_param_spec_string ("device_name", "Device name", "Name of the device",
|
2004-03-15 19:32:27 +00:00
|
|
|
NULL, G_PARAM_READABLE));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
gobject_class->set_property = gst_osselement_set_property;
|
|
|
|
gobject_class->get_property = gst_osselement_get_property;
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class->dispose = gst_osselement_dispose;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_osselement_change_state;
|
|
|
|
}
|
|
|
|
|
2003-11-06 09:55:24 +00:00
|
|
|
static const GList *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossprobe_get_properties (GstPropertyProbe * probe)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
|
|
|
GObjectClass *klass = G_OBJECT_GET_CLASS (probe);
|
|
|
|
static GList *list = NULL;
|
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
list = g_list_append (NULL, g_object_class_find_property (klass, "device"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2004-02-29 10:43:03 +00:00
|
|
|
/* OSS (without devfs) allows at max. 16 devices */
|
|
|
|
#define MAX_OSS_DEVICES 16
|
|
|
|
|
2003-11-06 09:55:24 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_probe (gchar * device_base,
|
|
|
|
gint device_num, gchar ** name, dev_t * devno)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
2004-02-29 10:43:03 +00:00
|
|
|
gchar *device = NULL;
|
2003-11-06 09:55:24 +00:00
|
|
|
struct stat s;
|
|
|
|
|
2004-02-29 10:43:03 +00:00
|
|
|
if ((name == NULL) || (devno == NULL)) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
*name = NULL;
|
|
|
|
*devno = 0;
|
2003-11-06 09:55:24 +00:00
|
|
|
|
2004-02-29 10:43:03 +00:00
|
|
|
if (device_num == -1)
|
2003-11-06 09:55:24 +00:00
|
|
|
device = g_strdup (device_base);
|
2004-02-29 10:43:03 +00:00
|
|
|
else if ((device_num >= -1) && (device_num <= MAX_OSS_DEVICES)) {
|
2003-11-06 09:55:24 +00:00
|
|
|
device = g_strdup_printf ("%s%d", device_base, device_num);
|
2004-02-29 10:43:03 +00:00
|
|
|
} else {
|
|
|
|
goto end;
|
|
|
|
}
|
2003-11-06 09:55:24 +00:00
|
|
|
|
2004-04-12 19:41:34 +00:00
|
|
|
if (stat (device, &s) || !S_ISCHR (s.st_mode))
|
2003-11-06 09:55:24 +00:00
|
|
|
goto end;
|
|
|
|
|
2004-02-29 10:43:03 +00:00
|
|
|
*name = device;
|
|
|
|
*devno = s.st_rdev;
|
2004-03-14 22:34:33 +00:00
|
|
|
return;
|
2003-11-06 09:55:24 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
g_free (device);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GList *
|
|
|
|
device_combination_append (GList * device_combinations,
|
|
|
|
GstOssDeviceCombination * combi)
|
2004-02-29 10:43:03 +00:00
|
|
|
{
|
|
|
|
GList *it;
|
|
|
|
|
|
|
|
for (it = device_combinations; it != NULL; it = it->next) {
|
|
|
|
GstOssDeviceCombination *cur;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
cur = (GstOssDeviceCombination *) it->data;
|
2004-02-29 10:43:03 +00:00
|
|
|
if (cur->dev == combi->dev) {
|
|
|
|
return device_combinations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_list_append (device_combinations, combi);
|
|
|
|
}
|
|
|
|
|
2003-11-06 09:55:24 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_class_probe_devices (GstOssElementClass * klass, gboolean check)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
2004-01-22 20:51:08 +00:00
|
|
|
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
|
2003-11-06 09:55:24 +00:00
|
|
|
static gboolean init = FALSE;
|
2003-11-09 20:54:24 +00:00
|
|
|
static GList *device_combinations;
|
2004-01-22 20:51:08 +00:00
|
|
|
GList *padtempllist;
|
|
|
|
gint openmode = O_RDONLY;
|
|
|
|
gboolean mixer = FALSE;
|
|
|
|
|
|
|
|
/* Ok, so how do we open the device? We assume that we have (max.) one
|
|
|
|
* pad, and if this is a sinkpad, we're osssink (w). else, we're osssrc
|
|
|
|
* (r) */
|
|
|
|
padtempllist = gst_element_class_get_pad_template_list (eklass);
|
|
|
|
if (padtempllist != NULL) {
|
|
|
|
GstPadTemplate *firstpadtempl = padtempllist->data;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-22 20:51:08 +00:00
|
|
|
if (GST_PAD_TEMPLATE_DIRECTION (firstpadtempl) == GST_PAD_SINK) {
|
|
|
|
openmode = O_WRONLY;
|
|
|
|
}
|
|
|
|
mixer = TRUE;
|
|
|
|
}
|
2003-11-06 09:55:24 +00:00
|
|
|
|
|
|
|
if (!init && !check) {
|
2004-02-29 10:43:03 +00:00
|
|
|
#define MIXER 0
|
|
|
|
#define DSP 1
|
2004-03-14 22:34:33 +00:00
|
|
|
gchar *dev_base[][2] = { {"/dev/mixer", "/dev/dsp"}
|
|
|
|
,
|
|
|
|
{"/dev/sound/mixer", "/dev/sound/dsp"}
|
|
|
|
,
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
2003-11-06 09:55:24 +00:00
|
|
|
gint n;
|
2004-02-29 10:43:03 +00:00
|
|
|
gint base;
|
2003-11-06 09:55:24 +00:00
|
|
|
|
2003-11-09 20:54:24 +00:00
|
|
|
while (device_combinations) {
|
|
|
|
GList *item = device_combinations;
|
2003-11-06 10:21:14 +00:00
|
|
|
GstOssDeviceCombination *combi = item->data;
|
|
|
|
|
2003-11-09 20:54:24 +00:00
|
|
|
device_combinations = g_list_remove (device_combinations, item);
|
2003-11-06 10:21:14 +00:00
|
|
|
|
|
|
|
g_free (combi->dsp);
|
|
|
|
g_free (combi->mixer);
|
|
|
|
g_free (combi);
|
|
|
|
}
|
2003-11-06 09:55:24 +00:00
|
|
|
|
|
|
|
/* probe for all /dev entries */
|
2004-02-29 10:43:03 +00:00
|
|
|
for (base = 0; dev_base[base][DSP] != NULL; base++) {
|
2003-11-06 09:55:24 +00:00
|
|
|
gint fd;
|
|
|
|
|
2004-02-29 10:43:03 +00:00
|
|
|
for (n = -1; n < MAX_OSS_DEVICES; n++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
gchar *dsp = NULL;
|
|
|
|
gchar *mixer = NULL;
|
|
|
|
dev_t dsp_dev;
|
|
|
|
dev_t mixer_dev;
|
|
|
|
|
|
|
|
gst_osselement_probe (dev_base[base][DSP], n, &dsp, &dsp_dev);
|
|
|
|
if (dsp == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
gst_osselement_probe (dev_base[base][MIXER], n, &mixer, &mixer_dev);
|
|
|
|
/* does the device exist (can we open them)? */
|
|
|
|
|
|
|
|
/* we just check the dsp. we assume the mixer always works.
|
|
|
|
* we don't need a mixer anyway (says OSS)... If we are a
|
|
|
|
* mixer element, we use the mixer anyway. */
|
|
|
|
if ((fd = open (mixer ? mixer :
|
|
|
|
dsp, openmode | O_NONBLOCK)) > 0 || errno == EBUSY) {
|
|
|
|
GstOssDeviceCombination *combi;
|
|
|
|
|
|
|
|
if (fd > 0)
|
|
|
|
close (fd);
|
|
|
|
|
|
|
|
/* yay! \o/ */
|
|
|
|
combi = g_new0 (GstOssDeviceCombination, 1);
|
|
|
|
combi->dsp = dsp;
|
|
|
|
combi->mixer = mixer;
|
|
|
|
device_combinations = device_combination_append (device_combinations,
|
|
|
|
combi);
|
|
|
|
} else {
|
|
|
|
g_free (dsp);
|
|
|
|
g_free (mixer);
|
|
|
|
}
|
2003-11-06 09:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-06 09:55:24 +00:00
|
|
|
init = TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-09 20:54:24 +00:00
|
|
|
klass->device_combinations = device_combinations;
|
|
|
|
|
2003-11-06 09:55:24 +00:00
|
|
|
return init;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GValueArray *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_class_list_devices (GstOssElementClass * klass)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
|
|
|
GValueArray *array;
|
|
|
|
GValue value = { 0 };
|
|
|
|
GList *item;
|
|
|
|
|
|
|
|
if (!klass->device_combinations)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
array = g_value_array_new (g_list_length (klass->device_combinations));
|
|
|
|
item = klass->device_combinations;
|
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
|
|
while (item) {
|
|
|
|
GstOssDeviceCombination *combi = item->data;
|
|
|
|
|
|
|
|
g_value_set_string (&value, combi->dsp);
|
|
|
|
g_value_array_append (array, &value);
|
|
|
|
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossprobe_probe_property (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
|
|
|
GstOssElementClass *klass = GST_OSSELEMENT_GET_CLASS (probe);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
gst_osselement_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:33 +00:00
|
|
|
gst_ossprobe_needs_probe (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
|
|
|
GstOssElementClass *klass = GST_OSSELEMENT_GET_CLASS (probe);
|
2003-11-06 10:15:22 +00:00
|
|
|
gboolean ret = FALSE;
|
2003-11-06 09:55:24 +00:00
|
|
|
|
2003-11-06 10:15:22 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
ret = !gst_osselement_class_probe_devices (klass, TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2003-11-06 09:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GValueArray *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossprobe_get_values (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
|
|
|
GstOssElementClass *klass = GST_OSSELEMENT_GET_CLASS (probe);
|
|
|
|
GValueArray *array = NULL;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
array = gst_osselement_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:33 +00:00
|
|
|
gst_ossprobe_interface_init (GstPropertyProbeInterface * iface)
|
2003-11-06 09:55:24 +00:00
|
|
|
{
|
|
|
|
iface->get_properties = gst_ossprobe_get_properties;
|
|
|
|
iface->probe_property = gst_ossprobe_probe_property;
|
2004-03-14 22:34:33 +00:00
|
|
|
iface->needs_probe = gst_ossprobe_needs_probe;
|
|
|
|
iface->get_values = gst_ossprobe_get_values;
|
2003-11-06 09:55:24 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_osselement_init (GstOssElement * oss)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
oss->device = g_strdup ("/dev/dsp");
|
|
|
|
oss->mixer_dev = g_strdup ("/dev/mixer");
|
|
|
|
oss->fd = -1;
|
|
|
|
oss->mixer_fd = -1;
|
2003-10-09 22:02:37 +00:00
|
|
|
oss->tracklist = NULL;
|
2003-10-10 12:24:20 +00:00
|
|
|
oss->device_name = NULL;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
gst_osselement_reset (oss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_dispose (GObject * object)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
GstOssElement *oss = (GstOssElement *) object;
|
|
|
|
|
|
|
|
g_free (oss->device);
|
|
|
|
g_free (oss->mixer_dev);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void
|
|
|
|
gst_osselement_reset (GstOssElement * oss)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
oss->law = 0;
|
|
|
|
oss->endianness = G_BYTE_ORDER;
|
|
|
|
oss->sign = TRUE;
|
|
|
|
oss->width = 16;
|
|
|
|
oss->depth = 16;
|
|
|
|
oss->channels = 2;
|
|
|
|
oss->rate = 44100;
|
|
|
|
oss->fragment = 6;
|
|
|
|
oss->bps = 0;
|
|
|
|
|
|
|
|
/* AFMT_*_BE not available on all OSS includes (e.g. FBSD) */
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
oss->format = AFMT_S16_BE;
|
|
|
|
#else
|
|
|
|
oss->format = AFMT_S16_LE;
|
2004-03-14 22:34:33 +00:00
|
|
|
#endif /* WORDS_BIGENDIAN */
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ossformat_get (gint law, gint endianness, gboolean sign, gint width,
|
|
|
|
gint depth, gint * format, gint * bps)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (width != depth)
|
2003-09-13 01:22:59 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*bps = 1;
|
|
|
|
|
|
|
|
if (law == 0) {
|
|
|
|
if (width == 16) {
|
|
|
|
if (sign == TRUE) {
|
2004-03-15 19:32:27 +00:00
|
|
|
if (endianness == G_LITTLE_ENDIAN) {
|
|
|
|
*format = AFMT_S16_LE;
|
|
|
|
GST_DEBUG ("16 bit signed LE, no law (%d)", *format);
|
|
|
|
} else if (endianness == G_BIG_ENDIAN) {
|
|
|
|
*format = AFMT_S16_BE;
|
|
|
|
GST_DEBUG ("16 bit signed BE, no law (%d)", *format);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
if (endianness == G_LITTLE_ENDIAN) {
|
|
|
|
*format = AFMT_U16_LE;
|
|
|
|
GST_DEBUG ("16 bit unsigned LE, no law (%d)", *format);
|
|
|
|
} else if (endianness == G_BIG_ENDIAN) {
|
|
|
|
*format = AFMT_U16_BE;
|
|
|
|
GST_DEBUG ("16 bit unsigned BE, no law (%d)", *format);
|
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
*bps = 2;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else if (width == 8) {
|
2003-09-13 01:22:59 +00:00
|
|
|
if (sign == TRUE) {
|
2004-03-15 19:32:27 +00:00
|
|
|
*format = AFMT_S8;
|
|
|
|
GST_DEBUG ("8 bit signed, no law (%d)", *format);
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
*format = AFMT_U8;
|
|
|
|
GST_DEBUG ("8 bit unsigned, no law (%d)", *format);
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
*bps = 1;
|
|
|
|
}
|
|
|
|
} else if (law == 1) {
|
|
|
|
*format = AFMT_MU_LAW;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mu law (%d)", *format);
|
2003-09-13 01:22:59 +00:00
|
|
|
} else if (law == 2) {
|
|
|
|
*format = AFMT_A_LAW;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("a law (%d)", *format);
|
2003-09-13 01:22:59 +00:00
|
|
|
} else {
|
|
|
|
g_critical ("unknown law");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gboolean
|
|
|
|
gst_osselement_parse_caps (GstOssElement * oss, const GstCaps * caps)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
gint bps, format;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_structure_get_int (structure, "width", &oss->width);
|
|
|
|
gst_structure_get_int (structure, "depth", &oss->depth);
|
|
|
|
|
|
|
|
if (oss->width != oss->depth)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gst_structure_get_int (structure, "law", &oss->law);
|
|
|
|
gst_structure_get_int (structure, "endianness", &oss->endianness);
|
|
|
|
gst_structure_get_boolean (structure, "signed", &oss->sign);
|
|
|
|
|
|
|
|
if (!gst_ossformat_get (oss->law, oss->endianness, oss->sign,
|
2004-03-15 19:32:27 +00:00
|
|
|
oss->width, oss->depth, &format, &bps)) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("could not get format");
|
2003-09-13 01:22:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_structure_get_int (structure, "channels", &oss->channels);
|
|
|
|
gst_structure_get_int (structure, "rate", &oss->rate);
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
oss->bps = bps * oss->channels * oss->rate;
|
|
|
|
oss->format = format;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_FIXED_INT(caps, name, dest) \
|
|
|
|
G_STMT_START { \
|
|
|
|
if (gst_caps_has_fixed_property (caps, name)) \
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_get_int (structure, name, dest); \
|
2003-09-13 01:22:59 +00:00
|
|
|
} G_STMT_END
|
|
|
|
#define GET_FIXED_BOOLEAN(caps, name, dest) \
|
|
|
|
G_STMT_START { \
|
|
|
|
if (gst_caps_has_fixed_property (caps, name)) \
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_get_boolean (structure, name, dest); \
|
2003-09-13 01:22:59 +00:00
|
|
|
} G_STMT_END
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gboolean
|
|
|
|
gst_osselement_merge_fixed_caps (GstOssElement * oss, GstCaps * caps)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
gint bps, format;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
/* peel off fixed stuff from the caps */
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_structure_get_int (structure, "law", &oss->law);
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_get_int (structure, "endianness", &oss->endianness);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_structure_get_boolean (structure, "signed", &oss->sign);
|
|
|
|
gst_structure_get_int (structure, "width", &oss->width);
|
|
|
|
gst_structure_get_int (structure, "depth", &oss->depth);
|
|
|
|
|
|
|
|
if (!gst_ossformat_get (oss->law, oss->endianness, oss->sign,
|
2004-03-15 19:32:27 +00:00
|
|
|
oss->width, oss->depth, &format, &bps)) {
|
2004-03-14 22:34:33 +00:00
|
|
|
return FALSE;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_structure_get_int (structure, "rate", &oss->rate);
|
|
|
|
gst_structure_get_int (structure, "channels", &oss->channels);
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
oss->bps = bps * oss->channels * oss->rate;
|
|
|
|
oss->format = format;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gboolean
|
|
|
|
gst_osselement_sync_parms (GstOssElement * oss)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
audio_buf_info space;
|
|
|
|
int frag;
|
|
|
|
gint target_format;
|
|
|
|
gint target_channels;
|
|
|
|
gint target_rate;
|
|
|
|
gint fragscale, frag_ln;
|
|
|
|
|
|
|
|
if (oss->fd == -1)
|
|
|
|
return FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (oss->fragment >> 16)
|
|
|
|
frag = oss->fragment;
|
|
|
|
else
|
|
|
|
frag = 0x7FFF0000 | oss->fragment;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
GST_INFO
|
|
|
|
("osselement: setting sound card to %dHz %d format %s (%08x fragment)",
|
|
|
|
oss->rate, oss->format, (oss->channels == 2) ? "stereo" : "mono", frag);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
ioctl (oss->fd, SNDCTL_DSP_SETFRAGMENT, &frag);
|
|
|
|
ioctl (oss->fd, SNDCTL_DSP_RESET, 0);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
target_format = oss->format;
|
2003-09-13 01:22:59 +00:00
|
|
|
target_channels = oss->channels;
|
2004-03-14 22:34:33 +00:00
|
|
|
target_rate = oss->rate;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
ioctl (oss->fd, SNDCTL_DSP_SETFMT, &oss->format);
|
2003-09-13 01:22:59 +00:00
|
|
|
ioctl (oss->fd, SNDCTL_DSP_CHANNELS, &oss->channels);
|
2004-03-14 22:34:33 +00:00
|
|
|
ioctl (oss->fd, SNDCTL_DSP_SPEED, &oss->rate);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
ioctl (oss->fd, SNDCTL_DSP_GETBLKSIZE, &oss->fragment_size);
|
|
|
|
|
|
|
|
if (oss->mode == GST_OSSELEMENT_WRITE) {
|
|
|
|
ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &space);
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2003-09-13 01:22:59 +00:00
|
|
|
ioctl (oss->fd, SNDCTL_DSP_GETISPACE, &space);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate new fragment using a poor man's logarithm function */
|
|
|
|
fragscale = 1;
|
|
|
|
frag_ln = 0;
|
|
|
|
while (fragscale < space.fragsize) {
|
|
|
|
fragscale <<= 1;
|
|
|
|
frag_ln++;
|
|
|
|
}
|
|
|
|
oss->fragment = space.fragstotal << 16 | frag_ln;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
GST_INFO ("osselement: set sound card to %dHz, %d format, %s "
|
2004-03-14 22:34:33 +00:00
|
|
|
"(%d bytes buffer, %08x fragment)",
|
|
|
|
oss->rate, oss->format,
|
|
|
|
(oss->channels == 2) ? "stereo" : "mono", space.bytes, oss->fragment);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
oss->fragment_time = (GST_SECOND * oss->fragment_size) / oss->bps;
|
2004-04-18 20:14:36 +00:00
|
|
|
GST_INFO ("fragment time %u %" G_GUINT64_FORMAT,
|
2004-03-14 22:34:33 +00:00
|
|
|
oss->bps, oss->fragment_time);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (target_format != oss->format ||
|
|
|
|
target_channels != oss->channels || target_rate != oss->rate) {
|
2004-01-12 12:24:05 +00:00
|
|
|
if (target_channels != oss->channels)
|
2004-03-14 22:34:33 +00:00
|
|
|
g_warning
|
2004-03-15 19:32:27 +00:00
|
|
|
("couldn't set the right number of channels (wanted %d, got %d), enjoy the tone difference",
|
|
|
|
target_channels, oss->channels);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
if (target_rate < oss->rate - 1 || target_rate > oss->rate + 1)
|
2004-03-14 22:34:33 +00:00
|
|
|
g_warning
|
2004-03-15 19:32:27 +00:00
|
|
|
("couldn't set the right sample rate (wanted %d, got %d), enjoy the speed difference",
|
|
|
|
target_rate, oss->rate);
|
2004-01-12 12:24:05 +00:00
|
|
|
if (target_format != oss->format)
|
2004-02-25 17:45:54 +00:00
|
|
|
g_warning ("couldn't set requested OSS format, enjoy the noise :)");
|
2003-09-13 01:22:59 +00:00
|
|
|
/* we could eventually return FALSE here, or just do some additional tests
|
|
|
|
* to see that the frequencies don't differ too much etc.. */
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_open_audio (GstOssElement * oss)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
gint caps;
|
|
|
|
GstOssOpenMode mode = GST_OSSELEMENT_READ;
|
|
|
|
const GList *padlist;
|
|
|
|
|
|
|
|
g_return_val_if_fail (oss->fd == -1, FALSE);
|
|
|
|
GST_INFO ("osselement: attempting to open sound device");
|
|
|
|
|
|
|
|
/* Ok, so how do we open the device? We assume that we have (max.) one
|
|
|
|
* pad, and if this is a sinkpad, we're osssink (w). else, we're osssrc (r) */
|
|
|
|
padlist = gst_element_get_pad_list (GST_ELEMENT (oss));
|
|
|
|
if (padlist != NULL) {
|
|
|
|
GstPad *firstpad = padlist->data;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (GST_PAD_IS_SINK (firstpad)) {
|
|
|
|
mode = GST_OSSELEMENT_WRITE;
|
|
|
|
}
|
2003-10-26 12:16:43 +00:00
|
|
|
} else {
|
|
|
|
goto do_mixer;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* first try to open the sound card */
|
|
|
|
if (mode == GST_OSSELEMENT_WRITE) {
|
|
|
|
/* open non blocking first so that it returns immediatly with an error
|
|
|
|
* when we cannot get to the device */
|
|
|
|
oss->fd = open (oss->device, O_WRONLY | O_NONBLOCK);
|
|
|
|
|
|
|
|
if (oss->fd >= 0) {
|
|
|
|
close (oss->fd);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
/* re-open the sound device in blocking mode */
|
|
|
|
oss->fd = open (oss->device, O_WRONLY);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2003-09-13 01:22:59 +00:00
|
|
|
oss->fd = open (oss->device, O_RDONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oss->fd < 0) {
|
|
|
|
switch (errno) {
|
|
|
|
case EBUSY:
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_ELEMENT_ERROR (oss, RESOURCE, BUSY,
|
|
|
|
(_("OSS device \"%s\" is already in use by another program."),
|
|
|
|
oss->device), (NULL));
|
|
|
|
break;
|
2003-09-13 01:22:59 +00:00
|
|
|
case EACCES:
|
|
|
|
case ETXTBSY:
|
2004-03-15 19:32:27 +00:00
|
|
|
if (mode == GST_OSSELEMENT_WRITE)
|
|
|
|
GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_WRITE,
|
|
|
|
(_("Could not access device \"%s\", check its permissions."),
|
|
|
|
oss->device), GST_ERROR_SYSTEM);
|
|
|
|
else
|
|
|
|
GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
|
|
|
|
(_("Could not access device \"%s\", check its permissions."),
|
|
|
|
oss->device), GST_ERROR_SYSTEM);
|
|
|
|
break;
|
2003-09-13 01:22:59 +00:00
|
|
|
case ENXIO:
|
|
|
|
case ENODEV:
|
|
|
|
case ENOENT:
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_ELEMENT_ERROR (oss, RESOURCE, NOT_FOUND,
|
|
|
|
(_("Device \"%s\" does not exist."), oss->device),
|
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
break;
|
2003-09-13 01:22:59 +00:00
|
|
|
default:
|
2004-03-15 19:32:27 +00:00
|
|
|
/* FIXME: strerror is not threadsafe */
|
|
|
|
if (mode == GST_OSSELEMENT_WRITE)
|
|
|
|
GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_WRITE,
|
|
|
|
(_("Could not open device \"%s\" for writing."), oss->device),
|
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
else
|
|
|
|
GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
|
|
|
|
(_("Could not open device \"%s\" for reading."), oss->device),
|
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
break;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
oss->mode = mode;
|
|
|
|
|
|
|
|
/* we have it, set the default parameters and go have fun */
|
|
|
|
/* set card state */
|
|
|
|
ioctl (oss->fd, SNDCTL_DSP_GETCAPS, &caps);
|
|
|
|
|
|
|
|
GST_INFO ("osselement: Capabilities %08x", caps);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (caps & DSP_CAP_DUPLEX)
|
|
|
|
GST_INFO ("osselement: Full duplex");
|
|
|
|
if (caps & DSP_CAP_REALTIME)
|
|
|
|
GST_INFO ("osselement: Realtime");
|
|
|
|
if (caps & DSP_CAP_BATCH)
|
|
|
|
GST_INFO ("osselement: Batch");
|
|
|
|
if (caps & DSP_CAP_COPROC)
|
|
|
|
GST_INFO ("osselement: Has coprocessor");
|
|
|
|
if (caps & DSP_CAP_TRIGGER)
|
|
|
|
GST_INFO ("osselement: Trigger");
|
|
|
|
if (caps & DSP_CAP_MMAP)
|
|
|
|
GST_INFO ("osselement: Direct access");
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
#ifdef DSP_CAP_MULTI
|
2004-03-14 22:34:33 +00:00
|
|
|
if (caps & DSP_CAP_MULTI)
|
|
|
|
GST_INFO ("osselement: Multiple open");
|
2003-09-13 01:22:59 +00:00
|
|
|
#endif /* DSP_CAP_MULTI */
|
|
|
|
|
|
|
|
#ifdef DSP_CAP_BIND
|
2004-03-14 22:34:33 +00:00
|
|
|
if (caps & DSP_CAP_BIND)
|
|
|
|
GST_INFO ("osselement: Channel binding");
|
2003-09-13 01:22:59 +00:00
|
|
|
#endif /* DSP_CAP_BIND */
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
ioctl (oss->fd, SNDCTL_DSP_GETFMTS, &caps);
|
|
|
|
|
|
|
|
GST_INFO ("osselement: Formats %08x", caps);
|
|
|
|
if (caps & AFMT_MU_LAW)
|
|
|
|
GST_INFO ("osselement: MU_LAW");
|
|
|
|
if (caps & AFMT_A_LAW)
|
|
|
|
GST_INFO ("osselement: A_LAW");
|
|
|
|
if (caps & AFMT_IMA_ADPCM)
|
|
|
|
GST_INFO ("osselement: IMA_ADPCM");
|
|
|
|
if (caps & AFMT_U8)
|
|
|
|
GST_INFO ("osselement: U8");
|
|
|
|
if (caps & AFMT_S16_LE)
|
|
|
|
GST_INFO ("osselement: S16_LE");
|
|
|
|
if (caps & AFMT_S16_BE)
|
|
|
|
GST_INFO ("osselement: S16_BE");
|
|
|
|
if (caps & AFMT_S8)
|
|
|
|
GST_INFO ("osselement: S8");
|
|
|
|
if (caps & AFMT_U16_LE)
|
|
|
|
GST_INFO ("osselement: U16_LE");
|
|
|
|
if (caps & AFMT_U16_BE)
|
|
|
|
GST_INFO ("osselement: U16_BE");
|
|
|
|
if (caps & AFMT_MPEG)
|
|
|
|
GST_INFO ("osselement: MPEG");
|
2003-09-13 01:22:59 +00:00
|
|
|
#ifdef AFMT_AC3
|
2004-03-14 22:34:33 +00:00
|
|
|
if (caps & AFMT_AC3)
|
|
|
|
GST_INFO ("osselement: AC3");
|
2003-09-13 01:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_INFO ("osselement: opened audio (%s) with fd=%d", oss->device, oss->fd);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
oss->caps = caps;
|
|
|
|
|
2003-10-26 12:16:43 +00:00
|
|
|
do_mixer:
|
2003-09-13 01:22:59 +00:00
|
|
|
gst_ossmixer_build_list (oss);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_close_audio (GstOssElement * oss)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
2003-10-26 12:16:43 +00:00
|
|
|
gst_ossmixer_free_list (oss);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
if (oss->probed_caps) {
|
|
|
|
gst_caps_free (oss->probed_caps);
|
|
|
|
oss->probed_caps = NULL;
|
|
|
|
}
|
2003-10-26 12:16:43 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (oss->fd < 0)
|
2003-09-13 01:22:59 +00:00
|
|
|
return;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
close (oss->fd);
|
2003-09-13 01:22:59 +00:00
|
|
|
oss->fd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osselement_convert (GstOssElement * oss,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat * dest_format, gint64 * dest_value)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
if (src_format == *dest_format) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oss->bps == 0 || oss->channels == 0 || oss->width == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = src_value * GST_SECOND / oss->bps;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value = src_value / (oss->width * oss->channels / 8);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * oss->bps / GST_SECOND;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value = src_value * oss->rate / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = src_value * GST_SECOND / oss->rate;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * oss->width * oss->channels / 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_osselement_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
GstOssElement *oss = GST_OSSELEMENT (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
/* disallow changing the device while it is opened
|
|
|
|
get_property("device") should return the right one */
|
2003-10-28 20:19:13 +00:00
|
|
|
if (gst_element_get_state (GST_ELEMENT (oss)) == GST_STATE_NULL) {
|
2004-03-15 19:32:27 +00:00
|
|
|
g_free (oss->device);
|
|
|
|
oss->device = g_strdup (g_value_get_string (value));
|
|
|
|
|
|
|
|
/* let's assume that if we have a device map for the mixer,
|
|
|
|
* we're allowed to do all that automagically here */
|
|
|
|
if (GST_OSSELEMENT_GET_CLASS (oss)->device_combinations != NULL) {
|
|
|
|
GList *list = GST_OSSELEMENT_GET_CLASS (oss)->device_combinations;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
GstOssDeviceCombination *combi = list->data;
|
|
|
|
|
|
|
|
if (!strcmp (combi->dsp, oss->device)) {
|
|
|
|
g_free (oss->mixer_dev);
|
|
|
|
oss->mixer_dev = g_strdup (combi->mixer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ARG_MIXERDEV:
|
|
|
|
/* disallow changing the device while it is opened
|
|
|
|
get_property("mixerdev") should return the right one */
|
2003-10-28 20:19:13 +00:00
|
|
|
if (gst_element_get_state (GST_ELEMENT (oss)) == GST_STATE_NULL) {
|
2004-03-15 19:32:27 +00:00
|
|
|
g_free (oss->mixer_dev);
|
|
|
|
oss->mixer_dev = g_strdup (g_value_get_string (value));
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_osselement_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
GstOssElement *oss = GST_OSSELEMENT (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
g_value_set_string (value, oss->device);
|
|
|
|
break;
|
|
|
|
case ARG_MIXERDEV:
|
|
|
|
g_value_set_string (value, oss->mixer_dev);
|
|
|
|
break;
|
2003-10-10 12:24:20 +00:00
|
|
|
case ARG_DEVICE_NAME:
|
|
|
|
g_value_set_string (value, oss->device_name);
|
|
|
|
break;
|
2003-09-13 01:22:59 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_osselement_change_state (GstElement * element)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
GstOssElement *oss = GST_OSSELEMENT (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
if (!gst_osselement_open_audio (oss)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
return GST_STATE_FAILURE;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
GST_INFO ("osselement: opened sound device");
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
gst_osselement_close_audio (oss);
|
|
|
|
gst_osselement_reset (oss);
|
|
|
|
GST_INFO ("osselement: closed sound device");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* rate probing code */
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#include <sys/soundcard.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct _GstOssProbe GstOssProbe;
|
|
|
|
struct _GstOssProbe
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int format;
|
|
|
|
int n_channels;
|
|
|
|
GArray *rates;
|
|
|
|
int min;
|
|
|
|
int max;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _GstOssRange GstOssRange;
|
|
|
|
struct _GstOssRange
|
|
|
|
{
|
|
|
|
int min;
|
|
|
|
int max;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GstStructure *gst_osselement_get_format_structure (unsigned int
|
|
|
|
format_bit);
|
|
|
|
static gboolean gst_osselement_rate_probe_check (GstOssProbe * probe);
|
|
|
|
static int gst_osselement_rate_check_rate (GstOssProbe * probe, int irate);
|
|
|
|
static void gst_osselement_rate_add_range (GQueue * queue, int min, int max);
|
|
|
|
static void gst_osselement_rate_add_rate (GArray * array, int rate);
|
|
|
|
static int gst_osselement_rate_int_compare (gconstpointer a, gconstpointer b);
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_osselement_probe_caps (GstOssElement * oss)
|
|
|
|
{
|
|
|
|
GstOssProbe *probe;
|
|
|
|
int i;
|
|
|
|
gboolean ret;
|
|
|
|
GstStructure *structure;
|
|
|
|
unsigned int format_bit;
|
|
|
|
unsigned int format_mask;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
if (oss->probed_caps != NULL)
|
|
|
|
return;
|
|
|
|
if (oss->fd == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* FIXME test make sure we're not currently playing */
|
|
|
|
/* FIXME test both mono and stereo */
|
|
|
|
|
|
|
|
format_mask = AFMT_U8 | AFMT_S16_LE | AFMT_S16_BE | AFMT_S8 |
|
|
|
|
AFMT_U16_LE | AFMT_U16_BE;
|
|
|
|
format_mask &= oss->caps;
|
|
|
|
|
|
|
|
caps = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
/* assume that the most significant bit of format_mask is 0 */
|
2004-03-30 18:01:45 +00:00
|
|
|
for (format_bit = 1; format_bit <= format_mask; format_bit <<= 1) {
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
if (format_bit & format_mask) {
|
|
|
|
GValue rate_value = { 0 };
|
|
|
|
|
|
|
|
probe = g_new0 (GstOssProbe, 1);
|
|
|
|
probe->fd = oss->fd;
|
|
|
|
probe->format = format_bit;
|
|
|
|
probe->n_channels = 2;
|
|
|
|
|
|
|
|
ret = gst_osselement_rate_probe_check (probe);
|
|
|
|
if (probe->min == -1 || probe->max == -1) {
|
|
|
|
g_array_free (probe->rates, TRUE);
|
|
|
|
g_free (probe);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
GValue value = { 0 };
|
|
|
|
|
|
|
|
g_array_sort (probe->rates, gst_osselement_rate_int_compare);
|
|
|
|
|
|
|
|
g_value_init (&rate_value, GST_TYPE_LIST);
|
|
|
|
g_value_init (&value, G_TYPE_INT);
|
|
|
|
|
|
|
|
for (i = 0; i < probe->rates->len; i++) {
|
|
|
|
g_value_set_int (&value, g_array_index (probe->rates, int, i));
|
|
|
|
|
|
|
|
gst_value_list_append_value (&rate_value, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
} else {
|
|
|
|
/* one big range */
|
|
|
|
g_value_init (&rate_value, GST_TYPE_INT_RANGE);
|
|
|
|
gst_value_set_int_range (&rate_value, probe->min, probe->max);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_free (probe->rates, TRUE);
|
|
|
|
g_free (probe);
|
|
|
|
|
|
|
|
structure = gst_osselement_get_format_structure (format_bit);
|
|
|
|
gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
|
|
|
|
gst_structure_set_value (structure, "rate", &rate_value);
|
|
|
|
g_value_unset (&rate_value);
|
|
|
|
|
|
|
|
gst_caps_append_structure (caps, structure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-01 13:20:03 +00:00
|
|
|
if (gst_caps_is_empty (caps)) {
|
|
|
|
GST_ELEMENT_ERROR (oss, RESOURCE, SETTINGS,
|
|
|
|
(_("Your oss device could not be probed correctly")), (NULL));
|
|
|
|
return;
|
|
|
|
}
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
GST_DEBUG ("probed caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
oss->probed_caps = caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStructure *
|
|
|
|
gst_osselement_get_format_structure (unsigned int format_bit)
|
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
int endianness;
|
|
|
|
gboolean sign;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
switch (format_bit) {
|
|
|
|
case AFMT_U8:
|
|
|
|
endianness = 0;
|
|
|
|
sign = FALSE;
|
|
|
|
width = 8;
|
|
|
|
break;
|
|
|
|
case AFMT_S16_LE:
|
|
|
|
endianness = G_LITTLE_ENDIAN;
|
|
|
|
sign = TRUE;
|
|
|
|
width = 16;
|
|
|
|
break;
|
|
|
|
case AFMT_S16_BE:
|
|
|
|
endianness = G_BIG_ENDIAN;
|
|
|
|
sign = TRUE;
|
|
|
|
width = 16;
|
|
|
|
break;
|
|
|
|
case AFMT_S8:
|
|
|
|
endianness = 0;
|
|
|
|
sign = TRUE;
|
|
|
|
width = 8;
|
|
|
|
break;
|
|
|
|
case AFMT_U16_LE:
|
|
|
|
endianness = G_LITTLE_ENDIAN;
|
|
|
|
sign = FALSE;
|
|
|
|
width = 16;
|
|
|
|
break;
|
|
|
|
case AFMT_U16_BE:
|
|
|
|
endianness = G_BIG_ENDIAN;
|
|
|
|
sign = FALSE;
|
|
|
|
width = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
structure = gst_structure_new ("audio/x-raw-int",
|
|
|
|
"width", G_TYPE_INT, width,
|
|
|
|
"depth", G_TYPE_INT, width, "signed", G_TYPE_BOOLEAN, sign, NULL);
|
|
|
|
|
|
|
|
if (endianness) {
|
|
|
|
gst_structure_set (structure, "endianness", G_TYPE_INT, endianness, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return structure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_osselement_rate_probe_check (GstOssProbe * probe)
|
|
|
|
{
|
|
|
|
GstOssRange *range;
|
|
|
|
GQueue *ranges;
|
|
|
|
int exact_rates = 0;
|
|
|
|
gboolean checking_exact_rates = TRUE;
|
|
|
|
int n_checks = 0;
|
|
|
|
gboolean result = TRUE;
|
|
|
|
|
|
|
|
ranges = g_queue_new ();
|
|
|
|
|
|
|
|
probe->rates = g_array_new (FALSE, FALSE, sizeof (int));
|
|
|
|
|
|
|
|
probe->min = gst_osselement_rate_check_rate (probe, 1000);
|
|
|
|
n_checks++;
|
|
|
|
probe->max = gst_osselement_rate_check_rate (probe, 100000);
|
|
|
|
n_checks++;
|
|
|
|
if (probe->min == -1 || probe->max == -1) {
|
|
|
|
GST_DEBUG ("unexpected check_rate error");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_osselement_rate_add_range (ranges, probe->min + 1, probe->max - 1);
|
|
|
|
|
|
|
|
while ((range = g_queue_pop_head (ranges))) {
|
|
|
|
int min1;
|
|
|
|
int max1;
|
|
|
|
int mid;
|
|
|
|
int mid_ret;
|
|
|
|
|
2004-04-18 20:14:36 +00:00
|
|
|
GST_DEBUG ("checking [%d,%d]", range->min, range->max);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
|
|
|
|
mid = (range->min + range->max) / 2;
|
|
|
|
mid_ret = gst_osselement_rate_check_rate (probe, mid);
|
|
|
|
if (mid_ret == -1) {
|
|
|
|
/* FIXME ioctl returned an error. do something */
|
|
|
|
GST_DEBUG ("unexpected check_rate error");
|
|
|
|
}
|
|
|
|
n_checks++;
|
|
|
|
|
|
|
|
if (mid == mid_ret && checking_exact_rates) {
|
|
|
|
int max_exact_matches = 20;
|
|
|
|
|
|
|
|
exact_rates++;
|
|
|
|
if (exact_rates > max_exact_matches) {
|
2004-04-18 20:14:36 +00:00
|
|
|
GST_DEBUG ("got %d exact rates, assuming all are exact",
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
max_exact_matches);
|
|
|
|
result = FALSE;
|
|
|
|
g_free (range);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
checking_exact_rates = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assume that the rate is arithmetically rounded to the nearest
|
|
|
|
* supported rate. */
|
|
|
|
if (mid == mid_ret) {
|
|
|
|
min1 = mid - 1;
|
|
|
|
max1 = mid + 1;
|
|
|
|
} else {
|
|
|
|
if (mid < mid_ret) {
|
|
|
|
min1 = mid - (mid_ret - mid);
|
|
|
|
max1 = mid_ret + 1;
|
|
|
|
} else {
|
|
|
|
min1 = mid_ret - 1;
|
|
|
|
max1 = mid + (mid - mid_ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_osselement_rate_add_range (ranges, range->min, min1);
|
|
|
|
gst_osselement_rate_add_range (ranges, max1, range->max);
|
|
|
|
|
|
|
|
g_free (range);
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((range = g_queue_pop_head (ranges))) {
|
|
|
|
g_free (range);
|
|
|
|
}
|
|
|
|
g_queue_free (ranges);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osselement_rate_add_range (GQueue * queue, int min, int max)
|
|
|
|
{
|
|
|
|
if (min <= max) {
|
|
|
|
GstOssRange *range = g_new0 (GstOssRange, 1);
|
|
|
|
|
|
|
|
range->min = min;
|
|
|
|
range->max = max;
|
|
|
|
|
|
|
|
g_queue_push_tail (queue, range);
|
|
|
|
/* push_head also works, but has different probing behavior */
|
|
|
|
/*g_queue_push_head (queue, range); */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gst_osselement_rate_check_rate (GstOssProbe * probe, int irate)
|
|
|
|
{
|
|
|
|
int rate;
|
|
|
|
int format;
|
|
|
|
int n_channels;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
rate = irate;
|
|
|
|
format = probe->format;
|
|
|
|
n_channels = probe->n_channels;
|
|
|
|
|
2004-03-30 18:01:45 +00:00
|
|
|
GST_LOG ("checking format %d, channels %d, rate %d",
|
|
|
|
format, n_channels, rate);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
ret = ioctl (probe->fd, SNDCTL_DSP_SETFMT, &format);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
ret = ioctl (probe->fd, SNDCTL_DSP_CHANNELS, &n_channels);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
ret = ioctl (probe->fd, SNDCTL_DSP_SPEED, &rate);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
2004-04-18 20:14:36 +00:00
|
|
|
GST_DEBUG ("rate %d -> %d", irate, rate);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
|
|
|
|
if (rate == irate - 1 || rate == irate + 1) {
|
|
|
|
rate = irate;
|
|
|
|
}
|
|
|
|
gst_osselement_rate_add_rate (probe->rates, rate);
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osselement_rate_add_rate (GArray * array, int rate)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
for (i = 0; i < array->len; i++) {
|
|
|
|
val = g_array_index (array, int, i);
|
|
|
|
|
|
|
|
if (val == rate)
|
|
|
|
return;
|
|
|
|
}
|
2004-04-18 20:14:36 +00:00
|
|
|
GST_DEBUG ("supported rate: %d", rate);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
g_array_append_val (array, rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gst_osselement_rate_int_compare (gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
const int *va = (const int *) a;
|
|
|
|
const int *vb = (const int *) b;
|
|
|
|
|
|
|
|
if (*va < *vb)
|
|
|
|
return -1;
|
|
|
|
if (*va > *vb)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|