summaryrefslogtreecommitdiffstats
path: root/sys/sunaudio/gstsunaudiomixer.c
blob: f7dd0d9b664b1dda33dbe2825f44146e74bd0c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * GStreamer - SunAudio mixer
 * Copyright (C) 2005,2006 Sun Microsystems, Inc.,
 *               Brian Cameron <brian.cameron@sun.com>
 *
 * 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.
 */

/**
 * SECTION:element-sunaudiomixer
 *
 * sunaudiomixer is an mixer that controls the sound input and output
 * levels with the Sun Audio interface available in Solaris.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gstsunaudiomixer.h"

static const GstElementDetails gst_sunaudiomixer_details =
GST_ELEMENT_DETAILS ("Sun Audio Mixer",
    "Generic/Audio",
    "Control sound input and output levels with Sun Audio",
    "Brian Cameron <brian.cameron@sun.com>");

GST_BOILERPLATE_WITH_INTERFACE (GstSunAudioMixer, gst_sunaudiomixer,
    GstElement, GST_TYPE_ELEMENT, GstMixer, GST_TYPE_MIXER, gst_sunaudiomixer);

GST_IMPLEMENT_SUNAUDIO_MIXER_CTRL_METHODS (GstSunAudioMixer, gst_sunaudiomixer);

static GstStateChangeReturn gst_sunaudiomixer_change_state (GstElement *
    element, GstStateChange transition);

static void
gst_sunaudiomixer_base_init (gpointer klass)
{
  gst_element_class_set_details (GST_ELEMENT_CLASS (klass),
      &gst_sunaudiomixer_details);
}

static void
gst_sunaudiomixer_class_init (GstSunAudioMixerClass * klass)
{
  GstElementClass *element_class;

  element_class = (GstElementClass *) klass;

  element_class->change_state = gst_sunaudiomixer_change_state;
}

static void
gst_sunaudiomixer_init (GstSunAudioMixer * this,
    GstSunAudioMixerClass * g_class)
{
  this->mixer = NULL;
}

static GstStateChangeReturn
gst_sunaudiomixer_change_state (GstElement * element, GstStateChange transition)
{
  GstSunAudioMixer *this = GST_SUNAUDIO_MIXER (element);

  switch (transition) {
    case GST_STATE_CHANGE_NULL_TO_READY:
      if (!this->mixer) {
        const char *audiodev;

        audiodev = g_getenv ("AUDIODEV");
        if (audiodev == NULL) {
          this->mixer = gst_sunaudiomixer_ctrl_new ("/dev/audioctl");
        } else {
          gchar *device = g_strdup_printf ("%sctl", audiodev);

          this->mixer = gst_sunaudiomixer_ctrl_new (device);
          g_free (device);
        }
      }
      break;
    case GST_STATE_CHANGE_READY_TO_NULL:
      if (this->mixer) {
        gst_sunaudiomixer_ctrl_free (this->mixer);
        this->mixer = NULL;
      }
      break;
    default:
      break;
  }

  if (GST_ELEMENT_CLASS (parent_class)->change_state)
    return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);

  return GST_STATE_CHANGE_SUCCESS;
}