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));
261 gst_oss4_property_probe_find_device_name_nofd (GST_OBJECT (oss),
263 g_value_set_string (value, name);
267 g_value_set_string (value, oss->device_name);
270 GST_OBJECT_UNLOCK (oss);
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
279 gst_oss4_source_getcaps (GstBaseSrc * bsrc)
284 oss = GST_OSS4_SOURCE (bsrc);
287 caps = gst_caps_copy (gst_oss4_audio_get_template_caps ());
288 } else if (oss->probed_caps) {
289 caps = gst_caps_copy (oss->probed_caps);
291 caps = gst_oss4_audio_probe_caps (GST_OBJECT (oss), oss->fd);
292 if (caps != NULL && !gst_caps_is_empty (caps)) {
293 oss->probed_caps = gst_caps_copy (caps);
300 /* note: we must not take the object lock here unless we fix up get_property */
302 gst_oss4_source_open (GstAudioSrc * asrc, gboolean silent_errors)
308 oss = GST_OSS4_SOURCE (asrc);
311 device = g_strdup (oss->device);
313 device = gst_oss4_audio_find_device (GST_OBJECT_CAST (oss));
315 /* desperate times, desperate measures */
317 device = g_strdup ("/dev/dsp0");
319 GST_INFO_OBJECT (oss, "Trying to open OSS4 device '%s'", device);
321 /* we open in non-blocking mode even if we don't really want to do writes
322 * non-blocking because we can't be sure that this is really a genuine
323 * OSS4 device with well-behaved drivers etc. We really don't want to
324 * hang forever under any circumstances. */
325 oss->fd = open (device, O_RDONLY | O_NONBLOCK, 0);
337 GST_INFO_OBJECT (oss, "Opened device");
339 /* Make sure it's OSS4. If it's old OSS, let osssink handle it */
340 if (!gst_oss4_audio_check_version (GST_OBJECT_CAST (oss), oss->fd))
343 /* now remove the non-blocking flag. */
344 mode = fcntl (oss->fd, F_GETFL);
346 if (fcntl (oss->fd, F_SETFL, mode) < 0) {
347 /* some drivers do no support unsetting the non-blocking flag, try to
348 * close/open the device then. This is racy but we error out properly. */
349 GST_WARNING_OBJECT (oss, "failed to unset O_NONBLOCK (buggy driver?), "
350 "will try to re-open device now");
351 gst_oss4_source_close (asrc);
352 if ((oss->fd = open (device, O_RDONLY, 0)) == -1)
356 oss->open_device = device;
358 /* not using ENGINEINFO here because it sometimes returns a different and
359 * less useful name than AUDIOINFO for the same device */
360 if (!gst_oss4_property_probe_find_device_name (GST_OBJECT (oss), oss->fd,
361 oss->open_device, &oss->device_name)) {
362 oss->device_name = NULL;
370 if (!silent_errors) {
371 GST_ELEMENT_ERROR (oss, RESOURCE, BUSY,
372 (_("Could not open audio device for playback. "
373 "Device is being used by another application.")), (NULL));
380 if (!silent_errors) {
381 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
382 (_("Could not open audio device for playback."
383 "You don't have permission to open the device.")),
391 if (!silent_errors) {
392 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
393 (_("Could not open audio device for playback.")), GST_ERROR_SYSTEM);
400 gst_oss4_source_close (asrc);
401 if (!silent_errors) {
402 GST_ELEMENT_ERROR (oss, RESOURCE, OPEN_READ,
403 (_("Could not open audio device for playback."
404 "This version of the Open Sound System is not supported by this "
405 "element.")), ("Try the 'osssink' element instead"));
412 if (!silent_errors) {
413 GST_ELEMENT_ERROR (oss, RESOURCE, SETTINGS, (NULL),
414 ("Unable to set device %s into non-blocking mode: %s",
415 oss->device, g_strerror (errno)));
423 gst_oss4_source_open_func (GstAudioSrc * asrc)
425 return gst_oss4_source_open (asrc, FALSE);
429 gst_oss4_source_free_mixer_tracks (GstOss4Source * oss)
431 g_list_foreach (oss->tracks, (GFunc) g_object_unref, NULL);
432 g_list_free (oss->tracks);
437 gst_oss4_source_close (GstAudioSrc * asrc)
441 oss = GST_OSS4_SOURCE (asrc);
444 GST_DEBUG_OBJECT (oss, "closing device");
449 oss->bytes_per_sample = 0;
451 gst_caps_replace (&oss->probed_caps, NULL);
453 g_free (oss->open_device);
454 oss->open_device = NULL;
456 g_free (oss->device_name);
457 oss->device_name = NULL;
459 gst_oss4_source_free_mixer_tracks (oss);
465 gst_oss4_source_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
469 oss = GST_OSS4_SOURCE (asrc);
471 if (!gst_oss4_audio_set_format (GST_OBJECT_CAST (oss), oss->fd, spec)) {
472 GST_WARNING_OBJECT (oss, "Couldn't set requested format %" GST_PTR_FORMAT,
477 oss->bytes_per_sample = spec->bytes_per_sample;
482 gst_oss4_source_unprepare (GstAudioSrc * asrc)
484 /* could do a SNDCTL_DSP_HALT, but the OSS manual recommends a close/open,
485 * since HALT won't properly reset some devices, apparently */
487 if (!gst_oss4_source_close (asrc))
490 if (!gst_oss4_source_open_func (asrc))
498 GST_DEBUG_OBJECT (asrc, "Couldn't close the audio device");
503 GST_DEBUG_OBJECT (asrc, "Couldn't reopen the audio device");
509 gst_oss4_source_read (GstAudioSrc * asrc, gpointer data, guint length)
514 oss = GST_OSS4_SOURCE_CAST (asrc);
516 n = read (oss->fd, data, length);
517 GST_LOG_OBJECT (asrc, "%u bytes, %u samples", n, n / oss->bytes_per_sample);
519 if (G_UNLIKELY (n < 0)) {
523 /* This is the most likely cause, I think */
524 GST_ELEMENT_ERROR (asrc, RESOURCE, READ,
525 (_("Recording is not supported by this audio device.")),
526 ("read: %s (device: %s) (maybe this is an output-only device?)",
527 g_strerror (errno), oss->open_device));
531 GST_ELEMENT_ERROR (asrc, RESOURCE, READ,
532 (_("Error recording from audio device.")),
533 ("read: %s (device: %s)", g_strerror (errno), oss->open_device));
543 gst_oss4_source_delay (GstAudioSrc * asrc)
545 audio_buf_info info = { 0, };
549 oss = GST_OSS4_SOURCE_CAST (asrc);
551 if (ioctl (oss->fd, SNDCTL_DSP_GETISPACE, &info) == -1) {
552 GST_LOG_OBJECT (oss, "GETISPACE failed: %s", g_strerror (errno));
556 delay = (info.fragstotal * info.fragsize) - info.bytes;
557 GST_LOG_OBJECT (oss, "fragstotal:%d, fragsize:%d, bytes:%d, delay:%d",
558 info.fragstotal, info.fragsize, info.bytes, delay);
563 gst_oss4_source_reset (GstAudioSrc * asrc)
565 /* There's nothing we can do here really: OSS can't handle access to the
566 * same device/fd from multiple threads and might deadlock or blow up in
567 * other ways if we try an ioctl SNDCTL_DSP_HALT or similar */
570 /* GstMixer interface, which we abuse here for input selection, because we
571 * don't have a proper interface for that and because that's what
572 * gnome-sound-recorder does. */
574 /* GstMixerTrack is a plain GObject, so let's just use the GLib macro here */
575 G_DEFINE_TYPE (GstOss4SourceInput, gst_oss4_source_input, GST_TYPE_MIXER_TRACK);
578 gst_oss4_source_input_class_init (GstOss4SourceInputClass * klass)
580 /* nothing to do here */
584 gst_oss4_source_input_init (GstOss4SourceInput * i)
586 /* nothing to do here */
592 gst_ossmixer_ensure_track_list (GstOssMixer * mixer)
596 g_return_if_fail (mixer->fd != -1);
598 if (mixer->tracklist)
601 /* find master volume */
602 if (mixer->devmask & SOUND_MASK_VOLUME)
603 master = SOUND_MIXER_VOLUME;
604 else if (mixer->devmask & SOUND_MASK_PCM)
605 master = SOUND_MIXER_PCM;
606 else if (mixer->devmask & SOUND_MASK_SPEAKER)
607 master = SOUND_MIXER_SPEAKER; /* doubtful... */
608 /* else: no master, so we won't set any */
610 /* build track list */
611 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
612 if (mixer->devmask & (1 << i)) {
613 GstMixerTrack *track;
614 gboolean input = FALSE, stereo = FALSE, record = FALSE;
616 /* track exists, make up capabilities */
617 if (MASK_BIT_IS_SET (mixer->stereomask, i))
619 if (MASK_BIT_IS_SET (mixer->recmask, i))
621 if (MASK_BIT_IS_SET (mixer->recdevs, i))
624 /* do we want mixer in our list? */
625 if (!((mixer->dir & GST_OSS_MIXER_CAPTURE && input == TRUE) ||
626 (mixer->dir & GST_OSS_MIXER_PLAYBACK && i != SOUND_MIXER_PCM)))
627 /* the PLAYBACK case seems hacky, but that's how 0.8 had it */
630 /* add track to list */
631 track = gst_ossmixer_track_new (mixer->fd, i, stereo ? 2 : 1,
632 (record ? GST_MIXER_TRACK_RECORD : 0) |
633 (input ? GST_MIXER_TRACK_INPUT :
634 GST_MIXER_TRACK_OUTPUT) |
635 ((master != i) ? 0 : GST_MIXER_TRACK_MASTER));
636 mixer->tracklist = g_list_append (mixer->tracklist, track);
641 /* unused with G_DISABLE_* */
642 static G_GNUC_UNUSED gboolean
643 gst_ossmixer_contains_track (GstOssMixer * mixer, GstOssMixerTrack * osstrack)
647 for (item = mixer->tracklist; item != NULL; item = item->next)
648 if (item->data == osstrack)
655 gst_ossmixer_list_tracks (GstOssMixer * mixer)
657 gst_ossmixer_ensure_track_list (mixer);
659 return (const GList *) mixer->tracklist;
663 gst_ossmixer_get_volume (GstOssMixer * mixer,
664 GstMixerTrack * track, gint * volumes)
667 GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
669 g_return_if_fail (mixer->fd != -1);
670 g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
672 if (track->flags & GST_MIXER_TRACK_MUTE) {
673 volumes[0] = osstrack->lvol;
674 if (track->num_channels == 2) {
675 volumes[1] = osstrack->rvol;
679 if (ioctl (mixer->fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
680 g_warning ("Error getting recording device (%d) volume: %s",
681 osstrack->track_num, g_strerror (errno));
685 osstrack->lvol = volumes[0] = (volume & 0xff);
686 if (track->num_channels == 2) {
687 osstrack->rvol = volumes[1] = ((volume >> 8) & 0xff);
693 gst_ossmixer_set_mute (GstOssMixer * mixer, GstMixerTrack * track,
697 GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
699 g_return_if_fail (mixer->fd != -1);
700 g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
705 volume = (osstrack->lvol & 0xff);
706 if (MASK_BIT_IS_SET (mixer->stereomask, osstrack->track_num)) {
707 volume |= ((osstrack->rvol & 0xff) << 8);
711 if (ioctl (mixer->fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
712 g_warning ("Error setting mixer recording device volume (0x%x): %s",
713 volume, g_strerror (errno));
718 track->flags |= GST_MIXER_TRACK_MUTE;
720 track->flags &= ~GST_MIXER_TRACK_MUTE;
726 gst_oss4_source_mixer_get_current_input (GstOss4Source * oss)
730 if (ioctl (oss->fd, SNDCTL_DSP_GET_RECSRC, &cur) == -1 || cur < 0)
737 gst_oss4_source_mixer_update_record_flags (GstOss4Source * oss, gint cur_route)
739 const gchar *cur_name = "";
742 for (t = oss->tracks; t != NULL; t = t->next) {
743 GstMixerTrack *track = t->data;
745 if (GST_OSS4_SOURCE_INPUT (track)->route == cur_route) {
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 */
750 cur_name = track->label;
752 if (GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) {
753 track->flags &= ~GST_MIXER_TRACK_RECORD;
754 /* no point in sending a mixer-record-changes message here */
763 gst_oss4_source_mixer_list_tracks (GstMixer * mixer)
765 oss_mixer_enuminfo names = { 0, };
767 const gchar *cur_name;
768 GList *tracks = NULL;
771 g_return_val_if_fail (mixer != NULL, NULL);
772 g_return_val_if_fail (GST_IS_OSS4_SOURCE (mixer), NULL);
773 g_return_val_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer), NULL);
775 oss = GST_OSS4_SOURCE (mixer);
777 if (oss->tracks != NULL && oss->tracks_static)
780 if (ioctl (oss->fd, SNDCTL_DSP_GET_RECSRC_NAMES, &names) == -1)
781 goto get_recsrc_names_error;
783 oss->tracks_static = (names.version == 0);
785 GST_INFO_OBJECT (oss, "%d inputs (list is static: %s):", names.nvalues,
786 (oss->tracks_static) ? "yes" : "no");
788 for (i = 0; i < MIN (names.nvalues, OSS_ENUM_MAXVALUE + 1); ++i) {
789 GstMixerTrack *track;
791 track = g_object_new (GST_TYPE_OSS4_SOURCE_INPUT, NULL);
792 track->label = g_strdup (&names.strings[names.strindex[i]]);
793 track->flags = GST_MIXER_TRACK_INPUT;
794 track->num_channels = 2;
795 track->min_volume = 0;
796 track->max_volume = 100;
797 GST_OSS4_SOURCE_INPUT (track)->route = i;
799 GST_INFO_OBJECT (oss, " [%d] %s", i, track->label);
800 tracks = g_list_append (tracks, track);
803 gst_oss4_source_free_mixer_tracks (oss);
804 oss->tracks = tracks;
808 /* update RECORD flags */
809 cur = gst_oss4_source_mixer_get_current_input (oss);
810 cur_name = gst_oss4_source_mixer_update_record_flags (oss, cur);
811 GST_DEBUG_OBJECT (oss, "current input route: %d (%s)", cur, cur_name);
813 return (const GList *) oss->tracks;
816 get_recsrc_names_error:
818 GST_WARNING_OBJECT (oss, "GET_RECSRC_NAMES failed: %s", g_strerror (errno));
824 gst_oss4_source_mixer_set_volume (GstMixer * mixer, GstMixerTrack * track,
830 g_return_if_fail (mixer != NULL);
831 g_return_if_fail (track != NULL);
832 g_return_if_fail (GST_IS_MIXER_TRACK (track));
833 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
834 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
836 oss = GST_OSS4_SOURCE (mixer);
838 cur = gst_oss4_source_mixer_get_current_input (oss);
839 if (cur != GST_OSS4_SOURCE_INPUT (track)->route) {
840 GST_DEBUG_OBJECT (oss, "track not selected input route, ignoring request");
844 new_vol = (volumes[1] << 8) | volumes[0];
845 if (ioctl (oss->fd, SNDCTL_DSP_SETRECVOL, &new_vol) == -1) {
846 GST_WARNING_OBJECT (oss, "SETRECVOL failed: %s", g_strerror (errno));
851 gst_oss4_source_mixer_get_volume (GstMixer * mixer, GstMixerTrack * track,
857 g_return_if_fail (mixer != NULL);
858 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
859 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
861 oss = GST_OSS4_SOURCE (mixer);
863 cur = gst_oss4_source_mixer_get_current_input (oss);
864 if (cur != GST_OSS4_SOURCE_INPUT (track)->route) {
870 if (ioctl (oss->fd, SNDCTL_DSP_GETRECVOL, &vol) == -1 || vol < 0) {
871 GST_WARNING_OBJECT (oss, "GETRECVOL failed: %s", g_strerror (errno));
875 volumes[0] = MIN (100, vol & 0xff);
876 volumes[1] = MIN (100, (vol >> 8) & 0xff);
882 gst_oss4_source_mixer_set_record (GstMixer * mixer, GstMixerTrack * track,
886 const gchar *cur_name;
889 g_return_if_fail (mixer != NULL);
890 g_return_if_fail (track != NULL);
891 g_return_if_fail (GST_IS_MIXER_TRACK (track));
892 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
893 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
895 oss = GST_OSS4_SOURCE (mixer);
897 cur = gst_oss4_source_mixer_get_current_input (oss);
899 /* stop recording for an input that's not selected anyway => nothing to do */
900 if (!record && cur != GST_OSS4_SOURCE_INPUT (track)->route)
903 /* select recording for an input that's already selected => nothing to do
904 * (or should we mess with the recording volume in this case maybe?) */
905 if (record && cur == GST_OSS4_SOURCE_INPUT (track)->route)
908 /* make current input stop recording: we can't really make an input stop
909 * recording, we can only select an input FOR recording, so we'll just ignore
910 * all requests to stop for now */
912 GST_WARNING_OBJECT (oss, "Can't un-select an input as such, only switch "
913 "to a different input source");
914 /* FIXME: set recording volume to 0 maybe? */
916 int new_route = GST_OSS4_SOURCE_INPUT (track)->route;
918 /* select this input for recording */
920 if (ioctl (oss->fd, SNDCTL_DSP_SET_RECSRC, &new_route) == -1) {
921 GST_WARNING_OBJECT (oss, "Could not select input %d for recording: %s",
922 new_route, g_strerror (errno));
930 cur_name = gst_oss4_source_mixer_update_record_flags (oss, cur);
931 GST_DEBUG_OBJECT (oss, "active input route: %d (%s)", cur, cur_name);
935 gst_oss4_source_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track,
940 g_return_if_fail (mixer != NULL);
941 g_return_if_fail (track != NULL);
942 g_return_if_fail (GST_IS_MIXER_TRACK (track));
943 g_return_if_fail (GST_IS_OSS4_SOURCE (mixer));
944 g_return_if_fail (GST_OSS4_SOURCE_IS_OPEN (mixer));
946 oss = GST_OSS4_SOURCE (mixer);
948 /* FIXME: implement gst_oss4_source_mixer_set_mute() - what to do here? */
949 /* oss4_mixer_set_mute (mixer->mixer, track, mute); */
953 gst_oss4_source_mixer_interface_init (GstMixerClass * klass)
955 GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;
957 klass->list_tracks = gst_oss4_source_mixer_list_tracks;
958 klass->set_volume = gst_oss4_source_mixer_set_volume;
959 klass->get_volume = gst_oss4_source_mixer_get_volume;
960 klass->set_mute = gst_oss4_source_mixer_set_mute;
961 klass->set_record = gst_oss4_source_mixer_set_record;
964 /* Implement the horror that is GstImplementsInterface */
967 gst_oss4_source_mixer_supported (GstImplementsInterface * iface,
973 g_return_val_if_fail (GST_IS_OSS4_SOURCE (iface), FALSE);
974 g_return_val_if_fail (iface_type == GST_TYPE_MIXER, FALSE);
976 oss = GST_OSS4_SOURCE (iface);
978 GST_OBJECT_LOCK (oss);
979 is_open = GST_OSS4_SOURCE_IS_OPEN (iface);
980 GST_OBJECT_UNLOCK (oss);
986 gst_oss4_source_mixer_implements_interface_init (GstImplementsInterfaceClass *
989 klass->supported = gst_oss4_source_mixer_supported;
993 gst_oss4_source_init_interfaces (GType type)
995 static const GInterfaceInfo implements_iface_info = {
996 (GInterfaceInitFunc) gst_oss4_source_mixer_implements_interface_init,
1000 static const GInterfaceInfo mixer_iface_info = {
1001 (GInterfaceInitFunc) gst_oss4_source_mixer_interface_init,
1006 g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE,
1007 &implements_iface_info);
1008 g_type_add_interface_static (type, GST_TYPE_MIXER, &mixer_iface_info);
1010 gst_oss4_add_property_probe_interface (type);