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
23 * This element lets you record sound using the Open Sound System (OSS)
27 * <title>Example pipelines</title>
29 * gst-launch -v oss4src ! queue ! audioconvert ! vorbisenc ! oggmux ! filesink location=mymusic.ogg
30 * ]| will record sound from your sound card using OSS4 and encode it to an
31 * Ogg/Vorbis file (this will only work if your mixer settings are right
32 * and the right inputs areenabled etc.)
38 /* FIXME: make sure we're not doing ioctls from the app thread (e.g. via the
39 * mixer interface) while recording */
45 #include <sys/types.h>
47 #include <sys/ioctl.h>
53 #include <gst/interfaces/mixer.h>
54 #include <gst/gst-i18n-plugin.h>
56 #define NO_LEGACY_MIXER
57 #include "oss4-audio.h"
58 #include "oss4-source.h"
59 #include "oss4-property-probe.h"
60 #include "oss4-soundcard.h"
62 #define GST_OSS4_SOURCE_IS_OPEN(src) (GST_OSS4_SOURCE(src)->fd != -1)
64 GST_DEBUG_CATEGORY_EXTERN (oss4src_debug);
65 #define GST_CAT_DEFAULT oss4src_debug
67 #define DEFAULT_DEVICE NULL
68 #define DEFAULT_DEVICE_NAME NULL
77 static void gst_oss4_source_init_interfaces (GType type);
79 GST_BOILERPLATE_FULL (GstOss4Source, gst_oss4_source, GstAudioSrc,
80 GST_TYPE_AUDIO_SRC, gst_oss4_source_init_interfaces);
82 static void gst_oss4_source_get_property (GObject * object, guint prop_id,
83 GValue * value, GParamSpec * pspec);
84 static void gst_oss4_source_set_property (GObject * object, guint prop_id,
85 const GValue * value, GParamSpec * pspec);
87 static void gst_oss4_source_dispose (GObject * object);
88 static void gst_oss4_source_finalize (GstOss4Source * osssrc);
90 static GstCaps *gst_oss4_source_getcaps (GstBaseSrc * bsrc);
92 static gboolean gst_oss4_source_open (GstAudioSrc * asrc,
93 gboolean silent_errors);
94 static gboolean gst_oss4_source_open_func (GstAudioSrc * asrc);
95 static gboolean gst_oss4_source_close (GstAudioSrc * asrc);
96 static gboolean gst_oss4_source_prepare (GstAudioSrc * asrc,
97 GstRingBufferSpec * spec);
98 static gboolean gst_oss4_source_unprepare (GstAudioSrc * asrc);
99 static guint gst_oss4_source_read (GstAudioSrc * asrc, gpointer data,
101 static guint gst_oss4_source_delay (GstAudioSrc * asrc);
102 static void gst_oss4_source_reset (GstAudioSrc * asrc);
105 gst_oss4_source_base_init (gpointer g_class)
107 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
108 GstPadTemplate *templ;
110 gst_element_class_set_details_simple (element_class,
111 "OSS v4 Audio Source", "Source/Audio",
112 "Capture from a sound card via OSS version 4",
113 "Tim-Philipp Müller <tim centricular net>");
115 templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
116 gst_oss4_audio_get_template_caps ());
117 gst_element_class_add_pad_template (element_class, templ);
121 gst_oss4_source_class_init (GstOss4SourceClass * klass)
123 GObjectClass *gobject_class;
124 GstElementClass *gstelement_class;
125 GstBaseSrcClass *gstbasesrc_class;
126 GstBaseAudioSrcClass *gstbaseaudiosrc_class;
127 GstAudioSrcClass *gstaudiosrc_class;
129 gobject_class = (GObjectClass *) klass;
130 gstelement_class = (GstElementClass *) klass;
131 gstbasesrc_class = (GstBaseSrcClass *) klass;
132 gstbaseaudiosrc_class = (GstBaseAudioSrcClass *) klass;
133 gstaudiosrc_class = (GstAudioSrcClass *) klass;
135 gobject_class->dispose = gst_oss4_source_dispose;
136 gobject_class->finalize = (GObjectFinalizeFunc) gst_oss4_source_finalize;
137 gobject_class->get_property = gst_oss4_source_get_property;
138 gobject_class->set_property = gst_oss4_source_set_property;
140 gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_oss4_source_getcaps);
142 gstaudiosrc_class->open = GST_DEBUG_FUNCPTR (gst_oss4_source_open_func);
143 gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR (gst_oss4_source_prepare);
144 gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR (gst_oss4_source_unprepare);
145 gstaudiosrc_class->close = GST_DEBUG_FUNCPTR (gst_oss4_source_close);
146 gstaudiosrc_class->read = GST_DEBUG_FUNCPTR (gst_oss4_source_read);
147 gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR (gst_oss4_source_delay);
148 gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_oss4_source_reset);
150 g_object_class_install_property (gobject_class, PROP_DEVICE,
151 g_param_spec_string ("device", "Device",
152 "OSS4 device (e.g. /dev/oss/hdaudio0/pcm0 or /dev/dspN) "
153 "(NULL = use first available device)",
154 DEFAULT_DEVICE, G_PARAM_READWRITE));
156 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
157 g_param_spec_string ("device-name", "Device name",
158 "Human-readable name of the sound device", DEFAULT_DEVICE_NAME,
163 gst_oss4_source_init (GstOss4Source * osssrc, GstOss4SourceClass * g_class)
167 device = g_getenv ("AUDIODEV");
169 device = DEFAULT_DEVICE;
172 osssrc->device = g_strdup (device);
173 osssrc->device_name = g_strdup (DEFAULT_DEVICE_NAME);
174 osssrc->device_name = NULL;
178 gst_oss4_source_finalize (GstOss4Source * oss)
180 g_free (oss->device);
183 g_list_free (oss->property_probe_list);
184 oss->property_probe_list = NULL;
186 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) (oss));
190 gst_oss4_source_dispose (GObject * object)
192 GstOss4Source *oss = GST_OSS4_SOURCE (object);
194 if (oss->probed_caps) {
195 gst_caps_unref (oss->probed_caps);
196 oss->probed_caps = NULL;
199 G_OBJECT_CLASS (parent_class)->dispose (object);
203 gst_oss4_source_set_property (GObject * object, guint prop_id,
204 const GValue * value, GParamSpec * pspec)
208 oss = GST_OSS4_SOURCE (object);
212 GST_OBJECT_LOCK (oss);
214 g_free (oss->device);
215 oss->device = g_value_dup_string (value);
216 g_free (oss->device_name);
217 oss->device_name = NULL;
219 g_warning ("%s: can't change \"device\" property while audio source "
220 "is open", GST_OBJECT_NAME (oss));
222 GST_OBJECT_UNLOCK (oss);
225 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
231 gst_oss4_source_get_property (GObject * object, guint prop_id,
232 GValue * value, GParamSpec * pspec)
236 oss = GST_OSS4_SOURCE (object);
240 GST_OBJECT_LOCK (oss);
241 g_value_set_string (value, oss->device);
242 GST_OBJECT_UNLOCK (oss);
244 case PROP_DEVICE_NAME:
245 GST_OBJECT_LOCK (oss);
246 /* If device is set, try to retrieve the name even if we're not open */
247 if (oss->fd == -1 && oss->device != NULL) {
248 if (gst_oss4_source_open (GST_AUDIO_SRC (oss), TRUE)) {
249 g_value_set_string (value, oss->device_name);
250 gst_oss4_source_close (GST_AUDIO_SRC (oss));
254 gst_oss4_property_probe_find_device_name_nofd (GST_OBJECT (oss),
256 g_value_set_string (value, name);
260 g_value_set_string (value, oss->device_name);
263 GST_OBJECT_UNLOCK (oss);
266 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
272 gst_oss4_source_getcaps (GstBaseSrc * bsrc)
277 oss = GST_OSS4_SOURCE (bsrc);
280 caps = gst_caps_copy (gst_oss4_audio_get_template_caps ());
281 } else if (oss->probed_caps) {
282 caps = gst_caps_copy (oss->probed_caps);
284 caps = gst_oss4_audio_probe_caps (GST_OBJECT (oss), oss->fd);
285 if (caps != NULL && !gst_caps_is_empty (caps)) {
286 oss->probed_caps = gst_caps_copy (caps);
293 /* note: we must not take the object lock here unless we fix up get_property */
295 gst_oss4_source_open (GstAudioSrc * asrc, gboolean silent_errors)
301 oss = GST_OSS4_SOURCE (asrc);
304 device = g_strdup (oss->device);
306 device = gst_oss4_audio_find_device (GST_OBJECT_CAST (oss));
308 /* desperate times, desperate measures */
310 device = g_strdup ("/dev/dsp0");
312 GST_INFO_OBJECT (oss, "Trying to open OSS4 device '%s'", device);
314 /* we open in non-blocking mode even if we don't really want to do writes
315 * non-blocking because we can't be sure that this is really a genuine
316 * OSS4 device with well-behaved drivers etc. We really don't want to
317 * hang forever under any circumstances. */
318 oss->fd = open (device, O_RDONLY | O_NONBLOCK, 0);
330 GST_INFO_OBJECT (oss, "Opened device");
332 /* Make sure it's OSS4. If it's old OSS, let osssink handle it */
333 if (!gst_oss4_audio_check_version (GST_OBJECT_CAST (oss), oss->fd))
336 /* now remove the non-blocking flag. */
337 mode = fcntl (oss->fd, F_GETFL);
339 if (fcntl (oss->fd, F_SETFL, mode) < 0) {
340 /* some drivers do no support unsetting the non-blocking flag, try to
341 * close/open the device then. This is racy but we error out properly. */
342 GST_WARNING_OBJECT (oss, "failed to unset O_NONBLOCK (buggy driver?), "
343 "will try to re-open device now");
344 gst_oss4_source_close (asrc);
345 if ((oss->fd = open (device, O_RDONLY, 0)) == -1)
349 oss->open_device = device;
351 /* not using ENGINEINFO here because it sometimes returns a different and
352 * less useful name than AUDIOINFO for the same device */
353 if (!gst_oss4_property_probe_find_device_name (GST_OBJECT (oss), oss->fd,
354 oss->open_device, &oss->device_name)) {
355 oss->device_name = NULL;
363 if (!silent_errors) {
364 GST_ELEMENT_ERROR (oss, RESOURCE, BUSY,
365 (_("Could not open audio device for playback. "
366 "Device is being used by another application.")), (NULL));
373 if (!silent_errors) {
374 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
375 (_("Could not open audio device for playback. "
376 "You don't have permission to open the device.")),
384 if (!silent_errors) {
385 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
386 (_("Could not open audio device for playback.")), GST_ERROR_SYSTEM);
393 gst_oss4_source_close (asrc);
394 if (!silent_errors) {
395 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
396 (_("Could not open audio device for playback. "
397 "This version of the Open Sound System is not supported by this "
398 "element.")), ("Try the 'osssink' element instead"));
405 if (!silent_errors) {
406 GST_ELEMENT_ERROR (oss, RESOURCE, SETTINGS, (NULL),
407 ("Unable to set device %s into non-blocking mode: %s",
408 oss->device, g_strerror (errno)));
416 gst_oss4_source_open_func (GstAudioSrc * asrc)
418 return gst_oss4_source_open (asrc, FALSE);
422 gst_oss4_source_free_mixer_tracks (GstOss4Source * oss)
424 g_list_foreach (oss->tracks, (GFunc) g_object_unref, NULL);
425 g_list_free (oss->tracks);
430 gst_oss4_source_close (GstAudioSrc * asrc)
434 oss = GST_OSS4_SOURCE (asrc);
437 GST_DEBUG_OBJECT (oss, "closing device");
442 oss->bytes_per_sample = 0;
444 gst_caps_replace (&oss->probed_caps, NULL);
446 g_free (oss->open_device);
447 oss->open_device = NULL;
449 g_free (oss->device_name);
450 oss->device_name = NULL;
452 gst_oss4_source_free_mixer_tracks (oss);
458 gst_oss4_source_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
462 oss = GST_OSS4_SOURCE (asrc);
464 if (!gst_oss4_audio_set_format (GST_OBJECT_CAST (oss), oss->fd, spec)) {
465 GST_WARNING_OBJECT (oss, "Couldn't set requested format %" GST_PTR_FORMAT,
470 oss->bytes_per_sample = spec->bytes_per_sample;
475 gst_oss4_source_unprepare (GstAudioSrc * asrc)
477 /* could do a SNDCTL_DSP_HALT, but the OSS manual recommends a close/open,
478 * since HALT won't properly reset some devices, apparently */
480 if (!gst_oss4_source_close (asrc))
483 if (!gst_oss4_source_open_func (asrc))
491 GST_DEBUG_OBJECT (asrc, "Couldn't close the audio device");
496 GST_DEBUG_OBJECT (asrc, "Couldn't reopen the audio device");
502 gst_oss4_source_read (GstAudioSrc * asrc, gpointer data, guint length)
507 oss = GST_OSS4_SOURCE_CAST (asrc);
509 n = read (oss->fd, data, length);
510 GST_LOG_OBJECT (asrc, "%u bytes, %u samples", n, n / oss->bytes_per_sample);
512 if (G_UNLIKELY (n < 0)) {
516 /* This is the most likely cause, I think */
517 GST_ELEMENT_ERROR (asrc, RESOURCE, READ,
518 (_("Recording is not supported by this audio device.")),
519 ("read: %s (device: %s) (maybe this is an output-only device?)",
520 g_strerror (errno), oss->open_device));
524 GST_ELEMENT_ERROR (asrc, RESOURCE, READ,
525 (_("Error recording from audio device.")),
526 ("read: %s (device: %s)", g_strerror (errno), oss->open_device));
536 gst_oss4_source_delay (GstAudioSrc * asrc)
538 audio_buf_info info = { 0, };
542 oss = GST_OSS4_SOURCE_CAST (asrc);
544 if (ioctl (oss->fd, SNDCTL_DSP_GETISPACE, &info) == -1) {
545 GST_LOG_OBJECT (oss, "GETISPACE failed: %s", g_strerror (errno));
549 delay = (info.fragstotal * info.fragsize) - info.bytes;
550 GST_LOG_OBJECT (oss, "fragstotal:%d, fragsize:%d, bytes:%d, delay:%d",
551 info.fragstotal, info.fragsize, info.bytes, delay);
556 gst_oss4_source_reset (GstAudioSrc * asrc)
558 /* There's nothing we can do here really: OSS can't handle access to the
559 * same device/fd from multiple threads and might deadlock or blow up in
560 * other ways if we try an ioctl SNDCTL_DSP_HALT or similar */
563 /* GstMixer interface, which we abuse here for input selection, because we
564 * don't have a proper interface for that and because that's what
565 * gnome-sound-recorder does. */
567 /* GstMixerTrack is a plain GObject, so let's just use the GLib macro here */
568 G_DEFINE_TYPE (GstOss4SourceInput, gst_oss4_source_input, GST_TYPE_MIXER_TRACK);
571 gst_oss4_source_input_class_init (GstOss4SourceInputClass * klass)
573 /* nothing to do here */
577 gst_oss4_source_input_init (GstOss4SourceInput * i)
579 /* nothing to do here */
585 gst_ossmixer_ensure_track_list (GstOssMixer * mixer)
589 g_return_if_fail (mixer->fd != -1);
591 if (mixer->tracklist)
594 /* find master volume */
595 if (mixer->devmask & SOUND_MASK_VOLUME)
596 master = SOUND_MIXER_VOLUME;
597 else if (mixer->devmask & SOUND_MASK_PCM)
598 master = SOUND_MIXER_PCM;
599 else if (mixer->devmask & SOUND_MASK_SPEAKER)
600 master = SOUND_MIXER_SPEAKER; /* doubtful... */
601 /* else: no master, so we won't set any */
603 /* build track list */
604 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
605 if (mixer->devmask & (1 << i)) {
606 GstMixerTrack *track;
607 gboolean input = FALSE, stereo = FALSE, record = FALSE;
609 /* track exists, make up capabilities */
610 if (MASK_BIT_IS_SET (mixer->stereomask, i))
612 if (MASK_BIT_IS_SET (mixer->recmask, i))
614 if (MASK_BIT_IS_SET (mixer->recdevs, i))
617 /* do we want mixer in our list? */
618 if (!((mixer->dir & GST_OSS_MIXER_CAPTURE && input == TRUE) ||
619 (mixer->dir & GST_OSS_MIXER_PLAYBACK && i != SOUND_MIXER_PCM)))
620 /* the PLAYBACK case seems hacky, but that's how 0.8 had it */
623 /* add track to list */
624 track = gst_ossmixer_track_new (mixer->fd, i, stereo ? 2 : 1,
625 (record ? GST_MIXER_TRACK_RECORD : 0) |
626 (input ? GST_MIXER_TRACK_INPUT :
627 GST_MIXER_TRACK_OUTPUT) |
628 ((master != i) ? 0 : GST_MIXER_TRACK_MASTER));
629 mixer->tracklist = g_list_append (mixer->tracklist, track);
634 /* unused with G_DISABLE_* */
635 static G_GNUC_UNUSED gboolean
636 gst_ossmixer_contains_track (GstOssMixer * mixer, GstOssMixerTrack * osstrack)
640 for (item = mixer->tracklist; item != NULL; item = item->next)
641 if (item->data == osstrack)
648 gst_ossmixer_list_tracks (GstOssMixer * mixer)
650 gst_ossmixer_ensure_track_list (mixer);
652 return (const GList *) mixer->tracklist;
656 gst_ossmixer_get_volume (GstOssMixer * mixer,
657 GstMixerTrack * track, gint * volumes)
660 GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
662 g_return_if_fail (mixer->fd != -1);
663 g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
665 if (track->flags & GST_MIXER_TRACK_MUTE) {
666 volumes[0] = osstrack->lvol;
667 if (track->num_channels == 2) {
668 volumes[1] = osstrack->rvol;
672 if (ioctl (mixer->fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
673 g_warning ("Error getting recording device (%d) volume: %s",
674 osstrack->track_num, g_strerror (errno));
678 osstrack->lvol = volumes[0] = (volume & 0xff);
679 if (track->num_channels == 2) {
680 osstrack->rvol = volumes[1] = ((volume >> 8) & 0xff);
686 gst_ossmixer_set_mute (GstOssMixer * mixer, GstMixerTrack * track,
690 GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
692 g_return_if_fail (mixer->fd != -1);
693 g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
698 volume = (osstrack->lvol & 0xff);
699 if (MASK_BIT_IS_SET (mixer->stereomask, osstrack->track_num)) {
700 volume |= ((osstrack->rvol & 0xff) << 8);
704 if (ioctl (mixer->fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
705 g_warning ("Error setting mixer recording device volume (0x%x): %s",
706 volume, g_strerror (errno));
711 track->flags |= GST_MIXER_TRACK_MUTE;
713 track->flags &= ~GST_MIXER_TRACK_MUTE;
719 gst_oss4_source_mixer_get_current_input (GstOss4Source * oss)
723 if (ioctl (oss->fd, SNDCTL_DSP_GET_RECSRC, &cur) == -1 || cur < 0)
730 gst_oss4_source_mixer_update_record_flags (GstOss4Source * oss, gint cur_route)
732 const gchar *cur_name = "";
735 for (t = oss->tracks; t != NULL; t = t->next) {
736 GstMixerTrack *track = t->data;
738 if (GST_OSS4_SOURCE_INPUT (track)->route == cur_route) {
739 if (!GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) {
740 track->flags |= GST_MIXER_TRACK_RECORD;
741 /* no point in sending a mixer-record-changes message here */
743 cur_name = track->label;
745 if (GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) {
746 track->flags &= ~GST_MIXER_TRACK_RECORD;
747 /* no point in sending a mixer-record-changes message here */
756 gst_oss4_source_mixer_list_tracks (GstMixer * mixer)
758 oss_mixer_enuminfo names = { 0, };
760 const gchar *cur_name;
761 GList *tracks = NULL;
764 g_return_val_if_fail (mixer != NULL, NULL);
765 g_return_val_if_fail (GST_IS_OSS4_SOURCE (mixer), NULL);
766 g_return_val_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer), NULL);
768 oss = GST_OSS4_SOURCE (mixer);
770 if (oss->tracks != NULL && oss->tracks_static)
773 if (ioctl (oss->fd, SNDCTL_DSP_GET_RECSRC_NAMES, &names) == -1)
774 goto get_recsrc_names_error;
776 oss->tracks_static = (names.version == 0);
778 GST_INFO_OBJECT (oss, "%d inputs (list is static: %s):", names.nvalues,
779 (oss->tracks_static) ? "yes" : "no");
781 for (i = 0; i < MIN (names.nvalues, OSS_ENUM_MAXVALUE + 1); ++i) {
782 GstMixerTrack *track;
784 track = g_object_new (GST_TYPE_OSS4_SOURCE_INPUT, NULL);
785 track->label = g_strdup (&names.strings[names.strindex[i]]);
786 track->flags = GST_MIXER_TRACK_INPUT;
787 track->num_channels = 2;
788 track->min_volume = 0;
789 track->max_volume = 100;
790 GST_OSS4_SOURCE_INPUT (track)->route = i;
792 GST_INFO_OBJECT (oss, " [%d] %s", i, track->label);
793 tracks = g_list_append (tracks, track);
796 gst_oss4_source_free_mixer_tracks (oss);
797 oss->tracks = tracks;
801 /* update RECORD flags */
802 cur = gst_oss4_source_mixer_get_current_input (oss);
803 cur_name = gst_oss4_source_mixer_update_record_flags (oss, cur);
804 GST_DEBUG_OBJECT (oss, "current input route: %d (%s)", cur, cur_name);
806 return (const GList *) oss->tracks;
809 get_recsrc_names_error:
811 GST_WARNING_OBJECT (oss, "GET_RECSRC_NAMES failed: %s", g_strerror (errno));
817 gst_oss4_source_mixer_set_volume (GstMixer * mixer, GstMixerTrack * track,
823 g_return_if_fail (mixer != NULL);
824 g_return_if_fail (track != NULL);
825 g_return_if_fail (GST_IS_MIXER_TRACK (track));
826 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
827 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
829 oss = GST_OSS4_SOURCE (mixer);
831 cur = gst_oss4_source_mixer_get_current_input (oss);
832 if (cur != GST_OSS4_SOURCE_INPUT (track)->route) {
833 GST_DEBUG_OBJECT (oss, "track not selected input route, ignoring request");
837 new_vol = (volumes[1] << 8) | volumes[0];
838 if (ioctl (oss->fd, SNDCTL_DSP_SETRECVOL, &new_vol) == -1) {
839 GST_WARNING_OBJECT (oss, "SETRECVOL failed: %s", g_strerror (errno));
844 gst_oss4_source_mixer_get_volume (GstMixer * mixer, GstMixerTrack * track,
850 g_return_if_fail (mixer != NULL);
851 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
852 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
854 oss = GST_OSS4_SOURCE (mixer);
856 cur = gst_oss4_source_mixer_get_current_input (oss);
857 if (cur != GST_OSS4_SOURCE_INPUT (track)->route) {
863 if (ioctl (oss->fd, SNDCTL_DSP_GETRECVOL, &vol) == -1 || vol < 0) {
864 GST_WARNING_OBJECT (oss, "GETRECVOL failed: %s", g_strerror (errno));
868 volumes[0] = MIN (100, vol & 0xff);
869 volumes[1] = MIN (100, (vol >> 8) & 0xff);
875 gst_oss4_source_mixer_set_record (GstMixer * mixer, GstMixerTrack * track,
879 const gchar *cur_name;
882 g_return_if_fail (mixer != NULL);
883 g_return_if_fail (track != NULL);
884 g_return_if_fail (GST_IS_MIXER_TRACK (track));
885 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
886 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
888 oss = GST_OSS4_SOURCE (mixer);
890 cur = gst_oss4_source_mixer_get_current_input (oss);
892 /* stop recording for an input that's not selected anyway => nothing to do */
893 if (!record && cur != GST_OSS4_SOURCE_INPUT (track)->route)
896 /* select recording for an input that's already selected => nothing to do
897 * (or should we mess with the recording volume in this case maybe?) */
898 if (record && cur == GST_OSS4_SOURCE_INPUT (track)->route)
901 /* make current input stop recording: we can't really make an input stop
902 * recording, we can only select an input FOR recording, so we'll just ignore
903 * all requests to stop for now */
905 GST_WARNING_OBJECT (oss, "Can't un-select an input as such, only switch "
906 "to a different input source");
907 /* FIXME: set recording volume to 0 maybe? */
909 int new_route = GST_OSS4_SOURCE_INPUT (track)->route;
911 /* select this input for recording */
913 if (ioctl (oss->fd, SNDCTL_DSP_SET_RECSRC, &new_route) == -1) {
914 GST_WARNING_OBJECT (oss, "Could not select input %d for recording: %s",
915 new_route, g_strerror (errno));
923 cur_name = gst_oss4_source_mixer_update_record_flags (oss, cur);
924 GST_DEBUG_OBJECT (oss, "active input route: %d (%s)", cur, cur_name);
928 gst_oss4_source_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track,
933 g_return_if_fail (mixer != NULL);
934 g_return_if_fail (track != NULL);
935 g_return_if_fail (GST_IS_MIXER_TRACK (track));
936 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
937 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
939 oss = GST_OSS4_SOURCE (mixer);
941 /* FIXME: implement gst_oss4_source_mixer_set_mute() - what to do here? */
942 /* oss4_mixer_set_mute (mixer->mixer, track, mute); */
946 gst_oss4_source_mixer_interface_init (GstMixerClass * klass)
948 GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;
950 klass->list_tracks = gst_oss4_source_mixer_list_tracks;
951 klass->set_volume = gst_oss4_source_mixer_set_volume;
952 klass->get_volume = gst_oss4_source_mixer_get_volume;
953 klass->set_mute = gst_oss4_source_mixer_set_mute;
954 klass->set_record = gst_oss4_source_mixer_set_record;
957 /* Implement the horror that is GstImplementsInterface */
960 gst_oss4_source_mixer_supported (GstImplementsInterface * iface,
966 g_return_val_if_fail (GST_IS_OSS4_SOURCE (iface), FALSE);
967 g_return_val_if_fail (iface_type == GST_TYPE_MIXER, FALSE);
969 oss = GST_OSS4_SOURCE (iface);
971 GST_OBJECT_LOCK (oss);
972 is_open = GST_OSS4_SOURCE_IS_OPEN (iface);
973 GST_OBJECT_UNLOCK (oss);
979 gst_oss4_source_mixer_implements_interface_init (GstImplementsInterfaceClass *
982 klass->supported = gst_oss4_source_mixer_supported;
986 gst_oss4_source_init_interfaces (GType type)
988 static const GInterfaceInfo implements_iface_info = {
989 (GInterfaceInitFunc) gst_oss4_source_mixer_implements_interface_init,
993 static const GInterfaceInfo mixer_iface_info = {
994 (GInterfaceInitFunc) gst_oss4_source_mixer_interface_init,
999 g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE,
1000 &implements_iface_info);
1001 g_type_add_interface_static (type, GST_TYPE_MIXER, &mixer_iface_info);
1003 gst_oss4_add_property_probe_interface (type);