1 /* GStreamer OSS4 audio source
2 * Copyright (C) 2007-2008 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:element-oss4src
22 * @short_description: record sound from your sound card using OSS4
26 * This element lets you record sound using the Open Sound System (OSS)
29 * <title>Example pipelines</title>
32 * gst-launch -v oss4src ! queue ! audioconvert ! vorbisenc ! oggmux ! filesink location=mymusic.ogg
34 * will record sound from your sound card using OSS4 and encode it to an
35 * Ogg/Vorbis file (this will only work if your mixer settings are right
36 * and the right inputs areenabled etc.)
43 /* FIXME: make sure we're not doing ioctls from the app thread (e.g. via the
44 * mixer interface) while recording */
50 #include <sys/types.h>
52 #include <sys/ioctl.h>
58 #include <gst/interfaces/mixer.h>
59 #include <gst/gst-i18n-plugin.h>
61 #define NO_LEGACY_MIXER
62 #include "oss4-audio.h"
63 #include "oss4-source.h"
64 #include "oss4-property-probe.h"
65 #include "oss4-soundcard.h"
67 #define GST_OSS4_SOURCE_IS_OPEN(src) (GST_OSS4_SOURCE(src)->fd != -1)
69 GST_DEBUG_CATEGORY_EXTERN (oss4src_debug);
70 #define GST_CAT_DEFAULT oss4src_debug
72 #define DEFAULT_DEVICE NULL
73 #define DEFAULT_DEVICE_NAME NULL
82 static void gst_oss4_source_init_interfaces (GType type);
84 GST_BOILERPLATE_FULL (GstOss4Source, gst_oss4_source, GstAudioSrc,
85 GST_TYPE_AUDIO_SRC, gst_oss4_source_init_interfaces);
87 static void gst_oss4_source_get_property (GObject * object, guint prop_id,
88 GValue * value, GParamSpec * pspec);
89 static void gst_oss4_source_set_property (GObject * object, guint prop_id,
90 const GValue * value, GParamSpec * pspec);
92 static void gst_oss4_source_dispose (GObject * object);
93 static void gst_oss4_source_finalize (GstOss4Source * osssrc);
95 static GstCaps *gst_oss4_source_getcaps (GstBaseSrc * bsrc);
97 static gboolean gst_oss4_source_open (GstAudioSrc * asrc,
98 gboolean silent_errors);
99 static gboolean gst_oss4_source_open_func (GstAudioSrc * asrc);
100 static gboolean gst_oss4_source_close (GstAudioSrc * asrc);
101 static gboolean gst_oss4_source_prepare (GstAudioSrc * asrc,
102 GstRingBufferSpec * spec);
103 static gboolean gst_oss4_source_unprepare (GstAudioSrc * asrc);
104 static guint gst_oss4_source_read (GstAudioSrc * asrc, gpointer data,
106 static guint gst_oss4_source_delay (GstAudioSrc * asrc);
107 static void gst_oss4_source_reset (GstAudioSrc * asrc);
110 gst_oss4_source_base_init (gpointer g_class)
112 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
113 GstPadTemplate *templ;
115 gst_element_class_set_details_simple (element_class,
116 "OSS v4 Audio Source", "Source/Audio",
117 "Capture from a sound card via OSS version 4",
118 "Tim-Philipp Müller <tim centricular net>");
120 templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
121 gst_oss4_audio_get_template_caps ());
122 gst_element_class_add_pad_template (element_class, templ);
125 gst_oss4_source_class_init (GstOss4SourceClass * klass)
127 GObjectClass *gobject_class;
128 GstElementClass *gstelement_class;
129 GstBaseSrcClass *gstbasesrc_class;
130 GstBaseAudioSrcClass *gstbaseaudiosrc_class;
131 GstAudioSrcClass *gstaudiosrc_class;
133 gobject_class = (GObjectClass *) klass;
134 gstelement_class = (GstElementClass *) klass;
135 gstbasesrc_class = (GstBaseSrcClass *) klass;
136 gstbaseaudiosrc_class = (GstBaseAudioSrcClass *) klass;
137 gstaudiosrc_class = (GstAudioSrcClass *) klass;
139 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_oss4_source_dispose);
140 gobject_class->finalize =
141 (GObjectFinalizeFunc) GST_DEBUG_FUNCPTR (gst_oss4_source_finalize);
142 gobject_class->get_property =
143 GST_DEBUG_FUNCPTR (gst_oss4_source_get_property);
144 gobject_class->set_property =
145 GST_DEBUG_FUNCPTR (gst_oss4_source_set_property);
147 gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_oss4_source_getcaps);
149 gstaudiosrc_class->open = GST_DEBUG_FUNCPTR (gst_oss4_source_open_func);
150 gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR (gst_oss4_source_prepare);
151 gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR (gst_oss4_source_unprepare);
152 gstaudiosrc_class->close = GST_DEBUG_FUNCPTR (gst_oss4_source_close);
153 gstaudiosrc_class->read = GST_DEBUG_FUNCPTR (gst_oss4_source_read);
154 gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR (gst_oss4_source_delay);
155 gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_oss4_source_reset);
157 g_object_class_install_property (gobject_class, PROP_DEVICE,
158 g_param_spec_string ("device", "Device",
159 "OSS4 device (e.g. /dev/oss/hdaudio0/pcm0 or /dev/dspN) "
160 "(NULL = use first available device)",
161 DEFAULT_DEVICE, G_PARAM_READWRITE));
163 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
164 g_param_spec_string ("device-name", "Device name",
165 "Human-readable name of the sound device", DEFAULT_DEVICE_NAME,
170 gst_oss4_source_init (GstOss4Source * osssrc, GstOss4SourceClass * g_class)
174 device = g_getenv ("AUDIODEV");
176 device = DEFAULT_DEVICE;
179 osssrc->device = g_strdup (device);
180 osssrc->device_name = g_strdup (DEFAULT_DEVICE_NAME);
181 osssrc->device_name = NULL;
185 gst_oss4_source_finalize (GstOss4Source * oss)
187 g_free (oss->device);
190 g_list_free (oss->property_probe_list);
191 oss->property_probe_list = NULL;
193 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) (oss));
197 gst_oss4_source_dispose (GObject * object)
199 GstOss4Source *oss = GST_OSS4_SOURCE (object);
201 if (oss->probed_caps) {
202 gst_caps_unref (oss->probed_caps);
203 oss->probed_caps = NULL;
206 G_OBJECT_CLASS (parent_class)->dispose (object);
210 gst_oss4_source_set_property (GObject * object, guint prop_id,
211 const GValue * value, GParamSpec * pspec)
215 oss = GST_OSS4_SOURCE (object);
219 GST_OBJECT_LOCK (oss);
221 g_free (oss->device);
222 oss->device = g_value_dup_string (value);
223 g_free (oss->device_name);
224 oss->device_name = NULL;
226 g_warning ("%s: can't change \"device\" property while audio source "
227 "is open", GST_OBJECT_NAME (oss));
229 GST_OBJECT_UNLOCK (oss);
232 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
238 gst_oss4_source_get_property (GObject * object, guint prop_id,
239 GValue * value, GParamSpec * pspec)
243 oss = GST_OSS4_SOURCE (object);
247 GST_OBJECT_LOCK (oss);
248 g_value_set_string (value, oss->device);
249 GST_OBJECT_UNLOCK (oss);
251 case PROP_DEVICE_NAME:
252 GST_OBJECT_LOCK (oss);
253 /* If device is set, try to retrieve the name even if we're not open */
254 if (oss->fd == -1 && oss->device != NULL) {
255 if (gst_oss4_source_open (GST_AUDIO_SRC (oss), TRUE)) {
256 g_value_set_string (value, oss->device_name);
257 gst_oss4_source_close (GST_AUDIO_SRC (oss));
259 g_value_set_string (value, NULL);
262 g_value_set_string (value, oss->device_name);
264 GST_OBJECT_UNLOCK (oss);
267 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
273 gst_oss4_source_getcaps (GstBaseSrc * bsrc)
278 oss = GST_OSS4_SOURCE (bsrc);
281 caps = gst_caps_copy (gst_oss4_audio_get_template_caps ());
282 } else if (oss->probed_caps) {
283 caps = gst_caps_copy (oss->probed_caps);
285 caps = gst_oss4_audio_probe_caps (GST_OBJECT (oss), oss->fd);
286 if (caps != NULL && !gst_caps_is_empty (caps)) {
287 oss->probed_caps = gst_caps_copy (caps);
294 /* note: we must not take the object lock here unless we fix up get_property */
296 gst_oss4_source_open (GstAudioSrc * asrc, gboolean silent_errors)
302 oss = GST_OSS4_SOURCE (asrc);
305 device = g_strdup (oss->device);
307 device = gst_oss4_audio_find_device (GST_OBJECT_CAST (oss));
309 /* desperate times, desperate measures */
311 device = g_strdup ("/dev/dsp0");
313 GST_INFO_OBJECT (oss, "Trying to open OSS4 device '%s'", device);
315 /* we open in non-blocking mode even if we don't really want to do writes
316 * non-blocking because we can't be sure that this is really a genuine
317 * OSS4 device with well-behaved drivers etc. We really don't want to
318 * hang forever under any circumstances. */
319 oss->fd = open (device, O_RDONLY | O_NONBLOCK, 0);
331 GST_INFO_OBJECT (oss, "Opened device");
333 /* Make sure it's OSS4. If it's old OSS, let osssink handle it */
334 if (!gst_oss4_audio_check_version (GST_OBJECT_CAST (oss), oss->fd))
337 /* now remove the non-blocking flag. */
338 mode = fcntl (oss->fd, F_GETFL);
340 if (fcntl (oss->fd, F_SETFL, mode) < 0) {
341 /* some drivers do no support unsetting the non-blocking flag, try to
342 * close/open the device then. This is racy but we error out properly. */
343 GST_WARNING_OBJECT (oss, "failed to unset O_NONBLOCK (buggy driver?), "
344 "will try to re-open device now");
345 gst_oss4_source_close (asrc);
346 if ((oss->fd = open (device, O_RDONLY, 0)) == -1)
350 oss->open_device = device;
352 /* not using ENGINEINFO here because it sometimes returns a different and
353 * less useful name than AUDIOINFO for the same device */
354 if (!gst_oss4_property_probe_find_device_name (GST_OBJECT (oss), oss->fd,
355 oss->open_device, &oss->device_name)) {
356 oss->device_name = NULL;
364 if (!silent_errors) {
365 GST_ELEMENT_ERROR (oss, RESOURCE, BUSY,
366 (_("Could not open audio device for playback. "
367 "Device is being used by another application.")), (NULL));
374 if (!silent_errors) {
375 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
376 (_("Could not open audio device for playback."
377 "You don't have permission to open the device.")),
385 if (!silent_errors) {
386 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
387 (_("Could not open audio device for playback.")), GST_ERROR_SYSTEM);
394 gst_oss4_source_close (asrc);
395 if (!silent_errors) {
396 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
397 (_("Could not open audio device for playback."
398 "This version of the Open Sound System is not supported by this "
399 "element.")), ("Try the 'osssink' element instead"));
406 if (!silent_errors) {
407 GST_ELEMENT_ERROR (oss, RESOURCE, SETTINGS, (NULL),
408 ("Unable to set device %s into non-blocking mode: %s",
409 oss->device, g_strerror (errno)));
417 gst_oss4_source_open_func (GstAudioSrc * asrc)
419 return gst_oss4_source_open (asrc, FALSE);
423 gst_oss4_source_free_mixer_tracks (GstOss4Source * oss)
425 g_list_foreach (oss->tracks, (GFunc) g_object_unref, NULL);
426 g_list_free (oss->tracks);
431 gst_oss4_source_close (GstAudioSrc * asrc)
435 oss = GST_OSS4_SOURCE (asrc);
438 GST_DEBUG_OBJECT (oss, "closing device");
443 oss->bytes_per_sample = 0;
445 gst_caps_replace (&oss->probed_caps, NULL);
447 g_free (oss->open_device);
448 oss->open_device = NULL;
450 g_free (oss->device_name);
451 oss->device_name = NULL;
453 gst_oss4_source_free_mixer_tracks (oss);
459 gst_oss4_source_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
463 oss = GST_OSS4_SOURCE (asrc);
465 if (!gst_oss4_audio_set_format (GST_OBJECT_CAST (oss), oss->fd, spec)) {
466 GST_WARNING_OBJECT (oss, "Couldn't set requested format %" GST_PTR_FORMAT,
471 oss->bytes_per_sample = spec->bytes_per_sample;
476 gst_oss4_source_unprepare (GstAudioSrc * asrc)
478 /* could do a SNDCTL_DSP_HALT, but the OSS manual recommends a close/open,
479 * since HALT won't properly reset some devices, apparently */
481 if (!gst_oss4_source_close (asrc))
484 if (!gst_oss4_source_open_func (asrc))
492 GST_DEBUG_OBJECT (asrc, "Couldn't close the audio device");
497 GST_DEBUG_OBJECT (asrc, "Couldn't reopen the audio device");
503 gst_oss4_source_read (GstAudioSrc * asrc, gpointer data, guint length)
508 oss = GST_OSS4_SOURCE_CAST (asrc);
510 n = read (oss->fd, data, length);
511 GST_LOG_OBJECT (asrc, "%u bytes, %u samples", n, n / oss->bytes_per_sample);
513 if (G_UNLIKELY (n < 0)) {
517 /* This is the most likely cause, I think */
518 GST_ELEMENT_ERROR (asrc, RESOURCE, READ,
519 (_("Recording is not supported by this audio device.")),
520 ("read: %s (device: %s) (maybe this is an output-only device?)",
521 g_strerror (errno), oss->open_device));
525 GST_ELEMENT_ERROR (asrc, RESOURCE, READ,
526 (_("Error recording from audio device.")),
527 ("read: %s (device: %s)", g_strerror (errno), oss->open_device));
537 gst_oss4_source_delay (GstAudioSrc * asrc)
539 audio_buf_info info = { 0, };
543 oss = GST_OSS4_SOURCE_CAST (asrc);
545 if (ioctl (oss->fd, SNDCTL_DSP_GETISPACE, &info) == -1) {
546 GST_LOG_OBJECT (oss, "GETISPACE failed: %s", g_strerror (errno));
550 delay = (info.fragstotal * info.fragsize) - info.bytes;
551 GST_LOG_OBJECT (oss, "fragstotal:%d, fragsize:%d, bytes:%d, delay:%d",
552 info.fragstotal, info.fragsize, info.bytes, delay);
557 gst_oss4_source_reset (GstAudioSrc * asrc)
559 /* There's nothing we can do here really: OSS can't handle access to the
560 * same device/fd from multiple threads and might deadlock or blow up in
561 * other ways if we try an ioctl SNDCTL_DSP_HALT or similar */
564 /* GstMixer interface, which we abuse here for input selection, because we
565 * don't have a proper interface for that and because that's what
566 * gnome-sound-recorder does. */
568 /* GstMixerTrack is a plain GObject, so let's just use the GLib macro here */
569 G_DEFINE_TYPE (GstOss4SourceInput, gst_oss4_source_input, GST_TYPE_MIXER_TRACK);
572 gst_oss4_source_input_class_init (GstOss4SourceInputClass * klass)
574 /* nothing to do here */
578 gst_oss4_source_input_init (GstOss4SourceInput * i)
580 /* nothing to do here */
586 gst_ossmixer_ensure_track_list (GstOssMixer * mixer)
590 g_return_if_fail (mixer->fd != -1);
592 if (mixer->tracklist)
595 /* find master volume */
596 if (mixer->devmask & SOUND_MASK_VOLUME)
597 master = SOUND_MIXER_VOLUME;
598 else if (mixer->devmask & SOUND_MASK_PCM)
599 master = SOUND_MIXER_PCM;
600 else if (mixer->devmask & SOUND_MASK_SPEAKER)
601 master = SOUND_MIXER_SPEAKER; /* doubtful... */
602 /* else: no master, so we won't set any */
604 /* build track list */
605 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
606 if (mixer->devmask & (1 << i)) {
607 GstMixerTrack *track;
608 gboolean input = FALSE, stereo = FALSE, record = FALSE;
610 /* track exists, make up capabilities */
611 if (MASK_BIT_IS_SET (mixer->stereomask, i))
613 if (MASK_BIT_IS_SET (mixer->recmask, i))
615 if (MASK_BIT_IS_SET (mixer->recdevs, i))
618 /* do we want mixer in our list? */
619 if (!((mixer->dir & GST_OSS_MIXER_CAPTURE && input == TRUE) ||
620 (mixer->dir & GST_OSS_MIXER_PLAYBACK && i != SOUND_MIXER_PCM)))
621 /* the PLAYBACK case seems hacky, but that's how 0.8 had it */
624 /* add track to list */
625 track = gst_ossmixer_track_new (mixer->fd, i, stereo ? 2 : 1,
626 (record ? GST_MIXER_TRACK_RECORD : 0) |
627 (input ? GST_MIXER_TRACK_INPUT :
628 GST_MIXER_TRACK_OUTPUT) |
629 ((master != i) ? 0 : GST_MIXER_TRACK_MASTER));
630 mixer->tracklist = g_list_append (mixer->tracklist, track);
635 /* unused with G_DISABLE_* */
636 static G_GNUC_UNUSED gboolean
637 gst_ossmixer_contains_track (GstOssMixer * mixer, GstOssMixerTrack * osstrack)
641 for (item = mixer->tracklist; item != NULL; item = item->next)
642 if (item->data == osstrack)
649 gst_ossmixer_list_tracks (GstOssMixer * mixer)
651 gst_ossmixer_ensure_track_list (mixer);
653 return (const GList *) mixer->tracklist;
657 gst_ossmixer_get_volume (GstOssMixer * mixer,
658 GstMixerTrack * track, gint * volumes)
661 GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
663 g_return_if_fail (mixer->fd != -1);
664 g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
666 if (track->flags & GST_MIXER_TRACK_MUTE) {
667 volumes[0] = osstrack->lvol;
668 if (track->num_channels == 2) {
669 volumes[1] = osstrack->rvol;
673 if (ioctl (mixer->fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
674 g_warning ("Error getting recording device (%d) volume: %s",
675 osstrack->track_num, g_strerror (errno));
679 osstrack->lvol = volumes[0] = (volume & 0xff);
680 if (track->num_channels == 2) {
681 osstrack->rvol = volumes[1] = ((volume >> 8) & 0xff);
687 gst_ossmixer_set_mute (GstOssMixer * mixer, GstMixerTrack * track,
691 GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
693 g_return_if_fail (mixer->fd != -1);
694 g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
699 volume = (osstrack->lvol & 0xff);
700 if (MASK_BIT_IS_SET (mixer->stereomask, osstrack->track_num)) {
701 volume |= ((osstrack->rvol & 0xff) << 8);
705 if (ioctl (mixer->fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
706 g_warning ("Error setting mixer recording device volume (0x%x): %s",
707 volume, g_strerror (errno));
712 track->flags |= GST_MIXER_TRACK_MUTE;
714 track->flags &= ~GST_MIXER_TRACK_MUTE;
720 gst_oss4_source_mixer_get_current_input (GstOss4Source * oss)
724 if (ioctl (oss->fd, SNDCTL_DSP_GET_RECSRC, &cur) == -1 || cur < 0)
731 gst_oss4_source_mixer_update_record_flags (GstOss4Source * oss, gint cur_route)
733 const gchar *cur_name = "";
736 for (t = oss->tracks; t != NULL; t = t->next) {
737 GstMixerTrack *track = t->data;
739 if (GST_OSS4_SOURCE_INPUT (track)->route == cur_route) {
740 if (!GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) {
741 track->flags |= GST_MIXER_TRACK_RECORD;
742 /* no point in sending a mixer-record-changes message here */
744 cur_name = track->label;
746 if (GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) {
747 track->flags &= ~GST_MIXER_TRACK_RECORD;
748 /* no point in sending a mixer-record-changes message here */
757 gst_oss4_source_mixer_list_tracks (GstMixer * mixer)
759 oss_mixer_enuminfo names = { 0, };
761 const gchar *cur_name;
762 GList *tracks = NULL;
765 g_return_val_if_fail (mixer != NULL, NULL);
766 g_return_val_if_fail (GST_IS_OSS4_SOURCE (mixer), NULL);
767 g_return_val_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer), NULL);
769 oss = GST_OSS4_SOURCE (mixer);
771 if (oss->tracks != NULL && oss->tracks_static)
774 if (ioctl (oss->fd, SNDCTL_DSP_GET_RECSRC_NAMES, &names) == -1)
775 goto get_recsrc_names_error;
777 oss->tracks_static = (names.version == 0);
779 GST_INFO_OBJECT (oss, "%d inputs (list is static: %s):", names.nvalues,
780 (oss->tracks_static) ? "yes" : "no");
782 for (i = 0; i < MIN (names.nvalues, OSS_ENUM_MAXVALUE + 1); ++i) {
783 GstMixerTrack *track;
785 track = g_object_new (GST_TYPE_OSS4_SOURCE_INPUT, NULL);
786 track->label = g_strdup (&names.strings[names.strindex[i]]);
787 track->flags = GST_MIXER_TRACK_INPUT;
788 track->num_channels = 2;
789 track->min_volume = 0;
790 track->max_volume = 100;
791 GST_OSS4_SOURCE_INPUT (track)->route = i;
793 GST_INFO_OBJECT (oss, " [%d] %s", i, track->label);
794 tracks = g_list_append (tracks, track);
797 gst_oss4_source_free_mixer_tracks (oss);
798 oss->tracks = tracks;
802 /* update RECORD flags */
803 cur = gst_oss4_source_mixer_get_current_input (oss);
804 cur_name = gst_oss4_source_mixer_update_record_flags (oss, cur);
805 GST_DEBUG_OBJECT (oss, "current input route: %d (%s)", cur, cur_name);
807 return (const GList *) oss->tracks;
810 get_recsrc_names_error:
812 GST_WARNING_OBJECT (oss, "GET_RECSRC_NAMES failed: %s", g_strerror (errno));
818 gst_oss4_source_mixer_set_volume (GstMixer * mixer, GstMixerTrack * track,
824 g_return_if_fail (mixer != NULL);
825 g_return_if_fail (track != NULL);
826 g_return_if_fail (GST_IS_MIXER_TRACK (track));
827 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
828 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
830 oss = GST_OSS4_SOURCE (mixer);
832 cur = gst_oss4_source_mixer_get_current_input (oss);
833 if (cur != GST_OSS4_SOURCE_INPUT (track)->route) {
834 GST_DEBUG_OBJECT (oss, "track not selected input route, ignoring request");
838 new_vol = (volumes[1] << 8) | volumes[0];
839 if (ioctl (oss->fd, SNDCTL_DSP_SETRECVOL, &new_vol) == -1) {
840 GST_WARNING_OBJECT (oss, "SETRECVOL failed: %s", g_strerror (errno));
845 gst_oss4_source_mixer_get_volume (GstMixer * mixer, GstMixerTrack * track,
851 g_return_if_fail (mixer != NULL);
852 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
853 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
855 oss = GST_OSS4_SOURCE (mixer);
857 cur = gst_oss4_source_mixer_get_current_input (oss);
858 if (cur != GST_OSS4_SOURCE_INPUT (track)->route) {
864 if (ioctl (oss->fd, SNDCTL_DSP_GETRECVOL, &vol) == -1 || vol < 0) {
865 GST_WARNING_OBJECT (oss, "GETRECVOL failed: %s", g_strerror (errno));
869 volumes[0] = MIN (100, vol & 0xff);
870 volumes[1] = MIN (100, (vol >> 8) & 0xff);
876 gst_oss4_source_mixer_set_record (GstMixer * mixer, GstMixerTrack * track,
880 const gchar *cur_name;
883 g_return_if_fail (mixer != NULL);
884 g_return_if_fail (track != NULL);
885 g_return_if_fail (GST_IS_MIXER_TRACK (track));
886 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
887 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
889 oss = GST_OSS4_SOURCE (mixer);
891 cur = gst_oss4_source_mixer_get_current_input (oss);
893 /* stop recording for an input that's not selected anyway => nothing to do */
894 if (!record && cur != GST_OSS4_SOURCE_INPUT (track)->route)
897 /* select recording for an input that's already selected => nothing to do
898 * (or should we mess with the recording volume in this case maybe?) */
899 if (record && cur == GST_OSS4_SOURCE_INPUT (track)->route)
902 /* make current input stop recording: we can't really make an input stop
903 * recording, we can only select an input FOR recording, so we'll just ignore
904 * all requests to stop for now */
906 GST_WARNING_OBJECT (oss, "Can't un-select an input as such, only switch "
907 "to a different input source");
908 /* FIXME: set recording volume to 0 maybe? */
910 int new_route = GST_OSS4_SOURCE_INPUT (track)->route;
912 /* select this input for recording */
914 if (ioctl (oss->fd, SNDCTL_DSP_SET_RECSRC, &new_route) == -1) {
915 GST_WARNING_OBJECT (oss, "Could not select input %d for recording: %s",
916 new_route, g_strerror (errno));
924 cur_name = gst_oss4_source_mixer_update_record_flags (oss, cur);
925 GST_DEBUG_OBJECT (oss, "active input route: %d (%s)", cur, cur_name);
929 gst_oss4_source_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track,
934 g_return_if_fail (mixer != NULL);
935 g_return_if_fail (track != NULL);
936 g_return_if_fail (GST_IS_MIXER_TRACK (track));
937 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
938 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
940 oss = GST_OSS4_SOURCE (mixer);
942 /* FIXME: implement gst_oss4_source_mixer_set_mute() - what to do here? */
943 /* oss4_mixer_set_mute (mixer->mixer, track, mute); */
947 gst_oss4_source_mixer_interface_init (GstMixerClass * klass)
949 GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;
951 klass->list_tracks = gst_oss4_source_mixer_list_tracks;
952 klass->set_volume = gst_oss4_source_mixer_set_volume;
953 klass->get_volume = gst_oss4_source_mixer_get_volume;
954 klass->set_mute = gst_oss4_source_mixer_set_mute;
955 klass->set_record = gst_oss4_source_mixer_set_record;
958 /* Implement the horror that is GstImplementsInterface */
961 gst_oss4_source_mixer_supported (GstImplementsInterface * iface,
967 g_return_val_if_fail (GST_IS_OSS4_SOURCE (iface), FALSE);
968 g_return_val_if_fail (iface_type == GST_TYPE_MIXER, FALSE);
970 oss = GST_OSS4_SOURCE (iface);
972 GST_OBJECT_LOCK (oss);
973 is_open = GST_OSS4_SOURCE_IS_OPEN (iface);
974 GST_OBJECT_UNLOCK (oss);
980 gst_oss4_source_mixer_implements_interface_init (GstImplementsInterfaceClass *
983 klass->supported = gst_oss4_source_mixer_supported;
987 gst_oss4_source_init_interfaces (GType type)
989 static const GInterfaceInfo implements_iface_info = {
990 (GInterfaceInitFunc) gst_oss4_source_mixer_implements_interface_init,
994 static const GInterfaceInfo mixer_iface_info = {
995 (GInterfaceInitFunc) gst_oss4_source_mixer_interface_init,
1000 g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE,
1001 &implements_iface_info);
1002 g_type_add_interface_static (type, GST_TYPE_MIXER, &mixer_iface_info);
1004 gst_oss4_add_property_probe_interface (type);