~ubuntu-branches/ubuntu/precise/gst-plugins-base0.10/precise-updates

« back to all changes in this revision

Viewing changes to ext/alsa/gstalsamixer.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2011-12-12 12:40:13 UTC
  • mfrom: (36.1.15 experimental)
  • Revision ID: package-import@ubuntu.com-20111212124013-onyadfb150d8c5dk
Tags: 0.10.35.2-2
* debian/libgstreamer-plugins-base.install:
  + Add license translations file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include "config.h"
35
35
#endif
36
36
 
 
37
/* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
 
38
 * with newer GLib versions (>= 2.31.0) */
 
39
#define GLIB_DISABLE_DEPRECATION_WARNINGS
 
40
 
37
41
#include "gstalsamixer.h"
 
42
#include "gst/glib-compat-private.h"
38
43
#include <errno.h>
39
44
 
40
45
static void gst_alsa_mixer_update_option (GstAlsaMixer * mixer,
130
135
 
131
136
  count = snd_mixer_get_count (handle);
132
137
 
133
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
138
  GST_ALSA_MIXER_LOCK (mixer);
134
139
 
135
140
  /* Check if we have a playback mixer labelled as 'Master' */
136
141
  element = snd_mixer_first_elem (handle);
137
142
  for (i = 0; i < count; i++) {
138
143
    if (snd_mixer_selem_has_playback_volume (element) &&
139
144
        strcmp (snd_mixer_selem_get_name (element), "Master") == 0) {
140
 
      g_static_rec_mutex_unlock (mixer->rec_mutex);
 
145
      GST_ALSA_MIXER_UNLOCK (mixer);
141
146
      return element;
142
147
    }
143
148
    element = snd_mixer_elem_next (element);
148
153
  for (i = 0; i < count; i++) {
149
154
    if (snd_mixer_selem_has_playback_volume (element) &&
150
155
        strcmp (snd_mixer_selem_get_name (element), "Front") == 0) {
151
 
      g_static_rec_mutex_unlock (mixer->rec_mutex);
 
156
      GST_ALSA_MIXER_UNLOCK (mixer);
152
157
      return element;
153
158
    }
154
159
    element = snd_mixer_elem_next (element);
159
164
  for (i = 0; i < count; i++) {
160
165
    if (snd_mixer_selem_has_playback_volume (element) &&
161
166
        strcmp (snd_mixer_selem_get_name (element), "PCM") == 0) {
162
 
      g_static_rec_mutex_unlock (mixer->rec_mutex);
 
167
      GST_ALSA_MIXER_UNLOCK (mixer);
163
168
      return element;
164
169
    }
165
170
    element = snd_mixer_elem_next (element);
170
175
  for (i = 0; i < count; i++) {
171
176
    if (snd_mixer_selem_has_playback_volume (element) &&
172
177
        strcmp (snd_mixer_selem_get_name (element), "Speaker") == 0) {
173
 
      g_static_rec_mutex_unlock (mixer->rec_mutex);
 
178
      GST_ALSA_MIXER_UNLOCK (mixer);
174
179
      return element;
175
180
    }
176
181
    element = snd_mixer_elem_next (element);
183
188
    if (snd_mixer_selem_has_playback_volume (element) &&
184
189
        snd_mixer_selem_has_playback_switch (element) &&
185
190
        !snd_mixer_selem_is_playback_mono (element)) {
186
 
      g_static_rec_mutex_unlock (mixer->rec_mutex);
 
191
      GST_ALSA_MIXER_UNLOCK (mixer);
187
192
      return element;
188
193
    }
189
194
    element = snd_mixer_elem_next (element);
194
199
  for (i = 0; i < count; i++) {
195
200
    if (snd_mixer_selem_has_playback_volume (element) &&
196
201
        snd_mixer_selem_has_playback_switch (element)) {
197
 
      g_static_rec_mutex_unlock (mixer->rec_mutex);
 
202
      GST_ALSA_MIXER_UNLOCK (mixer);
198
203
      return element;
199
204
    }
200
205
    element = snd_mixer_elem_next (element);
204
209
  element = snd_mixer_first_elem (handle);
205
210
  for (i = 0; i < count; i++) {
206
211
    if (snd_mixer_selem_has_playback_volume (element)) {
207
 
      g_static_rec_mutex_unlock (mixer->rec_mutex);
 
212
      GST_ALSA_MIXER_UNLOCK (mixer);
208
213
      return element;
209
214
    }
210
215
    element = snd_mixer_elem_next (element);
211
216
  }
212
217
 
213
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
218
  GST_ALSA_MIXER_UNLOCK (mixer);
214
219
  /* Looks like we're out of luck ... */
215
220
  return NULL;
216
221
}
222
227
 
223
228
  g_return_if_fail (mixer != NULL);
224
229
 
225
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
230
  GST_ALSA_MIXER_LOCK (mixer);
226
231
 
227
232
  for (item = mixer->tracklist; item != NULL; item = item->next) {
228
233
    if (GST_IS_ALSA_MIXER_TRACK (item->data)) {
238
243
    }
239
244
  }
240
245
 
241
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
246
  GST_ALSA_MIXER_UNLOCK (mixer);
242
247
}
243
248
 
244
249
static int
287
292
  if (mixer->tracklist)
288
293
    return;
289
294
 
290
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
295
  GST_ALSA_MIXER_LOCK (mixer);
291
296
 
292
297
  master = gst_alsa_mixer_find_master_mixer (mixer, mixer->handle);
293
298
 
409
414
    snd_mixer_elem_set_callback_private (temp, mixer);
410
415
  }
411
416
 
412
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
417
  GST_ALSA_MIXER_UNLOCK (mixer);
413
418
}
414
419
 
415
420
static void
421
426
  GstAlsaMixer *mixer = (GstAlsaMixer *) data;
422
427
  gint ret;
423
428
 
424
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
429
  GST_ALSA_MIXER_LOCK (mixer);
425
430
 
426
431
  nfds = snd_mixer_poll_descriptors_count (mixer->handle);
427
432
  if (nfds <= 0) {
428
433
    GST_ERROR ("snd_mixer_poll_descriptors_count <= 0: %d", nfds);
429
434
    /* FIXME: sleep ? stop monitoring ? */
430
 
    g_static_rec_mutex_unlock (mixer->rec_mutex);
 
435
    GST_ALSA_MIXER_UNLOCK (mixer);
431
436
    return;
432
437
  }
433
438
 
439
444
    GST_ELEMENT_ERROR (mixer, RESOURCE, READ, (NULL), ("alsa error: %s",
440
445
            snd_strerror (rnfds)));
441
446
    gst_task_pause (mixer->task);
442
 
    g_static_rec_mutex_unlock (mixer->rec_mutex);
 
447
    GST_ALSA_MIXER_UNLOCK (mixer);
443
448
    return;
444
449
  }
445
450
 
447
452
  pfds[rnfds].events = POLLIN | POLLPRI | POLLHUP | POLLERR;
448
453
  pfds[rnfds].revents = 0;
449
454
 
450
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
455
  GST_ALSA_MIXER_UNLOCK (mixer);
451
456
 
452
457
  GST_LOG ("task loop");
453
458
  ret = poll (pfds, rnfds + 1, -1);
458
463
    return;
459
464
  }
460
465
 
461
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
466
  GST_ALSA_MIXER_LOCK (mixer);
462
467
 
463
468
  ret =
464
469
      snd_mixer_poll_descriptors_revents (mixer->handle, pfds, nfds, &revents);
474
479
    gst_task_pause (mixer->task);
475
480
  }
476
481
 
477
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
482
  GST_ALSA_MIXER_UNLOCK (mixer);
478
483
}
479
484
 
480
485
/* API */
491
496
  if (pipe (ret->pfd) == -1)
492
497
    goto error;
493
498
 
494
 
  ret->rec_mutex = g_new (GStaticRecMutex, 1);
495
 
  g_static_rec_mutex_init (ret->rec_mutex);
496
 
 
497
 
  ret->task_mutex = g_new (GStaticRecMutex, 1);
498
 
  g_static_rec_mutex_init (ret->task_mutex);
 
499
#if !GLIB_CHECK_VERSION (2, 31, 0)
 
500
  g_static_rec_mutex_init (&ret->rec_mutex);
 
501
#else
 
502
  g_rec_mutex_init (&ret->rec_mutex);
 
503
#endif
 
504
  g_static_rec_mutex_init (&ret->task_mutex);
499
505
 
500
506
  ret->task = gst_task_create (task_monitor_alsa, ret);
501
 
  gst_task_set_lock (ret->task, ret->task_mutex);
 
507
  gst_task_set_lock (ret->task, &ret->task_mutex);
502
508
 
503
509
  ret->device = g_strdup (device);
504
510
  ret->dir = dir;
540
546
    mixer->task = NULL;
541
547
  }
542
548
 
543
 
  g_static_rec_mutex_free (mixer->task_mutex);
544
 
  g_free (mixer->task_mutex);
545
 
  mixer->task_mutex = NULL;
 
549
  g_static_rec_mutex_free (&mixer->task_mutex);
546
550
 
547
551
  if (mixer->pfd[0] > 0) {
548
552
    close (mixer->pfd[0]);
579
583
    snd_mixer_close (mixer->handle);
580
584
    mixer->handle = NULL;
581
585
  }
582
 
 
583
 
  g_static_rec_mutex_free (mixer->rec_mutex);
584
 
  g_free (mixer->rec_mutex);
585
 
  mixer->rec_mutex = NULL;
 
586
#if !GLIB_CHECK_VERSION (2, 31, 0)
 
587
  g_static_rec_mutex_free (&mixer->rec_mutex);
 
588
#else
 
589
  g_rec_mutex_clear (&mixer->rec_mutex);
 
590
#endif
586
591
 
587
592
  g_free (mixer);
588
593
}
606
611
 
607
612
  g_return_if_fail (mixer->handle != NULL);
608
613
 
609
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
614
  GST_ALSA_MIXER_LOCK (mixer);
610
615
 
611
616
  gst_alsa_mixer_track_update (alsa_track);
612
617
 
642
647
        volumes[i] = alsa_track->volumes[i];
643
648
    }
644
649
  }
645
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
650
  GST_ALSA_MIXER_UNLOCK (mixer);
646
651
}
647
652
 
648
653
static gboolean
670
675
 
671
676
  g_return_if_fail (mixer->handle != NULL);
672
677
 
673
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
678
  GST_ALSA_MIXER_LOCK (mixer);
674
679
 
675
680
  gst_alsa_mixer_track_update (alsa_track);
676
681
 
718
723
        alsa_track->volumes[i] = volumes[i];
719
724
    }
720
725
  }
721
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
726
  GST_ALSA_MIXER_UNLOCK (mixer);
722
727
}
723
728
 
724
729
void
729
734
 
730
735
  g_return_if_fail (mixer->handle != NULL);
731
736
 
732
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
737
  GST_ALSA_MIXER_LOCK (mixer);
733
738
 
734
739
  gst_alsa_mixer_track_update (alsa_track);
735
740
 
736
741
  if (! !(mute) == ! !(track->flags & GST_MIXER_TRACK_MUTE)) {
737
 
    g_static_rec_mutex_unlock (mixer->rec_mutex);
 
742
    GST_ALSA_MIXER_UNLOCK (mixer);
738
743
    return;
739
744
  }
740
745
  if (mute) {
765
770
 
766
771
    for (i = 0; i < ((GstMixerTrack *) ctrl_track)->num_channels; i++) {
767
772
      long vol =
768
 
          mute ? ((GstMixerTrack *) ctrl_track)->
769
 
          min_volume : ctrl_track->volumes[i];
 
773
          mute ? ((GstMixerTrack *) ctrl_track)->min_volume : ctrl_track->
 
774
          volumes[i];
770
775
      snd_mixer_selem_set_playback_volume (ctrl_track->element, i, vol);
771
776
    }
772
777
  }
773
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
778
  GST_ALSA_MIXER_UNLOCK (mixer);
774
779
}
775
780
 
776
781
void
781
786
 
782
787
  g_return_if_fail (mixer->handle != NULL);
783
788
 
784
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
789
  GST_ALSA_MIXER_LOCK (mixer);
785
790
 
786
791
  gst_alsa_mixer_track_update (alsa_track);
787
792
 
788
793
  if (! !(record) == ! !(track->flags & GST_MIXER_TRACK_RECORD)) {
789
 
    g_static_rec_mutex_unlock (mixer->rec_mutex);
 
794
    GST_ALSA_MIXER_UNLOCK (mixer);
790
795
    return;
791
796
  }
792
797
 
800
805
    snd_mixer_selem_set_capture_switch_all (alsa_track->element,
801
806
        record ? 1 : 0);
802
807
 
803
 
    /* update all tracks in same exlusive cswitch group */
 
808
    /* update all tracks in same exclusive cswitch group */
804
809
    if (alsa_track->alsa_flags & GST_ALSA_MIXER_TRACK_CSWITCH_EXCL) {
805
810
      GList *item;
806
811
 
826
831
      snd_mixer_selem_set_capture_volume (alsa_track->element, i, vol);
827
832
    }
828
833
  }
829
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
834
  GST_ALSA_MIXER_UNLOCK (mixer);
830
835
}
831
836
 
832
837
void
848
853
  if (idx == -1)
849
854
    return;
850
855
 
851
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
856
  GST_ALSA_MIXER_LOCK (mixer);
852
857
  snd_mixer_selem_set_enum_item (alsa_opts->element, 0, idx);
853
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
858
  GST_ALSA_MIXER_UNLOCK (mixer);
854
859
}
855
860
 
856
861
const gchar *
861
866
  GstAlsaMixerOptions *alsa_opts = GST_ALSA_MIXER_OPTIONS (opts);
862
867
 
863
868
  g_return_val_if_fail (mixer->handle != NULL, NULL);
864
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
869
  GST_ALSA_MIXER_LOCK (mixer);
865
870
  ret = snd_mixer_selem_get_enum_item (alsa_opts->element, 0, &idx);
866
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
871
  GST_ALSA_MIXER_UNLOCK (mixer);
867
872
  if (ret == 0)
868
873
    return g_list_nth_data (opts->values, idx);
869
874
  else
890
895
    GST_WARNING ("Cannot send update notifications, no GstMixer * given");
891
896
    return;
892
897
  }
893
 
  g_static_rec_mutex_lock (mixer->rec_mutex);
 
898
  GST_ALSA_MIXER_LOCK (mixer);
894
899
  ret = snd_mixer_selem_get_enum_item (alsa_opts->element, 0, &idx);
895
 
  g_static_rec_mutex_unlock (mixer->rec_mutex);
 
900
  GST_ALSA_MIXER_UNLOCK (mixer);
896
901
  if (ret == 0) {
897
902
    option = g_list_nth_data (GST_MIXER_OPTIONS (alsa_opts)->values, idx);
898
903
    gst_mixer_option_changed (mixer->interface, GST_MIXER_OPTIONS (alsa_opts),