summaryrefslogtreecommitdiffstats
path: root/sys/oss
diff options
context:
space:
mode:
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>2004-12-16 11:34:54 +0000
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>2004-12-16 11:34:54 +0000
commit64ed8f9735cea27f22c10aa0b3c83197c232b012 (patch)
tree19a0139ef96dc547e574593f5b1061e267be6870 /sys/oss
parent6e1fa8a5bf1f3a8b668887e6593c8c9122771430 (diff)
sys/oss/: fixes #159433. Also add missing copyright header to oss_probe.c.
Original commit message from CVS: Reviewed by: Ronald S. Bultje <rbultje@ronald.bitfreak.net> * sys/oss/gstosselement.c: (gst_osselement_probe_caps): * sys/oss/oss_probe.c: (main): Check for mono/stereo support (similar to samplerate probing), fixes #159433. Also add missing copyright header to oss_probe.c.
Diffstat (limited to 'sys/oss')
-rw-r--r--sys/oss/gstosselement.c44
-rw-r--r--sys/oss/oss_probe.c48
2 files changed, 87 insertions, 5 deletions
diff --git a/sys/oss/gstosselement.c b/sys/oss/gstosselement.c
index 839366b9..b2d65261 100644
--- a/sys/oss/gstosselement.c
+++ b/sys/oss/gstosselement.c
@@ -1,8 +1,9 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wim.taymans@chello.be>
+ * 2004 Toni Willberg <toniw@iki.fi>
*
- * gstosssink.c:
+ * gstosselement.c:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -1060,15 +1061,31 @@ gst_osselement_probe_caps (GstOssElement * oss)
GstStructure *structure;
unsigned int format_bit;
unsigned int format_mask;
+
GstCaps *caps;
+ gboolean mono_supported = FALSE;
+ gboolean stereo_supported = FALSE;
+ int n_channels;
+
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 */
+
+ /* check if the device supports mono, stereo or both */
+ n_channels = 1;
+ ret = ioctl (oss->fd, SNDCTL_DSP_CHANNELS, &n_channels);
+ if (n_channels == 1)
+ mono_supported = TRUE;
+
+ n_channels = 2;
+ ret = ioctl (oss->fd, SNDCTL_DSP_CHANNELS, &n_channels);
+ if (n_channels == 2)
+ stereo_supported = TRUE;
format_mask = AFMT_U8 | AFMT_S16_LE | AFMT_S16_BE | AFMT_S8 |
AFMT_U16_LE | AFMT_U16_BE;
@@ -1084,7 +1101,12 @@ gst_osselement_probe_caps (GstOssElement * oss)
probe = g_new0 (GstOssProbe, 1);
probe->fd = oss->fd;
probe->format = format_bit;
- probe->n_channels = 2;
+
+ if (stereo_supported) {
+ probe->n_channels = 2;
+ } else {
+ probe->n_channels = 1;
+ }
ret = gst_osselement_rate_probe_check (probe);
if (probe->min == -1 || probe->max == -1) {
@@ -1118,7 +1140,21 @@ gst_osselement_probe_caps (GstOssElement * oss)
g_free (probe);
structure = gst_osselement_get_format_structure (format_bit);
- gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
+
+ if (mono_supported && stereo_supported) {
+ gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, 2,
+ NULL);
+ } else if (mono_supported) {
+ gst_structure_set (structure, "channels", G_TYPE_INT, 1, NULL);
+ } else if (stereo_supported) {
+ gst_structure_set (structure, "channels", G_TYPE_INT, 2, NULL);
+ } else {
+ /* falling back to [1,2] because we don't know what breaks if we abort here */
+ GST_ERROR (_("Your OSS device doesn't support mono or stereo."));
+ 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);
diff --git a/sys/oss/oss_probe.c b/sys/oss/oss_probe.c
index 5b0d1284..1d54a607 100644
--- a/sys/oss/oss_probe.c
+++ b/sys/oss/oss_probe.c
@@ -1,3 +1,24 @@
+/* GStreamer
+ * Copyright (C) 2004 David Schleef
+ * 2004 Toni Willberg <toniw@iki.fi>
+ *
+ * oss_probe.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"
@@ -52,9 +73,12 @@ int
main (int argc, char *argv[])
{
int fd;
- int i;
+ int i, ret;
Probe *probe;
+ gboolean mono_supported = FALSE;
+ gboolean stereo_supported = FALSE;
+
fd = open ("/dev/dsp", O_RDWR);
if (fd < 0) {
perror ("/dev/dsp");
@@ -64,7 +88,29 @@ main (int argc, char *argv[])
probe = g_new0 (Probe, 1);
probe->fd = fd;
probe->format = AFMT_S16_LE;
+
+ /* check if the device supports mono, stereo or both */
+ probe->n_channels = 1;
+ ret = ioctl (fd, SNDCTL_DSP_CHANNELS, &probe->n_channels);
+ if (probe->n_channels == 1)
+ mono_supported = TRUE;
+
probe->n_channels = 2;
+ ret = ioctl (fd, SNDCTL_DSP_CHANNELS, &probe->n_channels);
+ if (probe->n_channels == 2)
+ stereo_supported = TRUE;
+
+ if (mono_supported && stereo_supported) {
+ g_print ("The device supports mono and stereo.\n");
+ } else if (mono_supported) {
+ g_print ("The device supports only mono.\n");
+ } else if (stereo_supported) {
+ g_print ("The device supports only stereo.\n");
+ } else {
+ /* exit with error */
+ g_error
+ ("The device doesn't support mono or stereo. This should not happen.\n");
+ }
probe_check (probe);
g_array_sort (probe->rates, int_compare);