~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kmix/mixer_pulse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *              KMix -- KDE's full featured mini mixer
3
 
 *
4
 
 *
5
 
 *              Copyright (C) 2008 Helio Chissini de Castro <helio@kde.org>
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Library General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2 of the License, or (at your option) any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Library General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Library General Public
18
 
 * License along with this program; if not, write to the Free
19
 
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
 */
21
 
 
22
 
#include <cstdlib>
23
 
 
24
 
#include "mixer_pulse.h"
25
 
#include "mixer.h"
26
 
 
27
 
static pa_context *context = NULL;
28
 
static pa_glib_mainloop *mainloop = NULL;
29
 
 
30
 
Mixer_Backend* PULSE_getMixer( Mixer *mixer, int devnum )
31
 
{
32
 
   Mixer_Backend *l_mixer;
33
 
   l_mixer = new Mixer_PULSE( mixer, devnum );
34
 
   return l_mixer;
35
 
}
36
 
 
37
 
 
38
 
Mixer_PULSE::Mixer_PULSE(Mixer *mixer, int devnum) : Mixer_Backend(mixer, devnum)
39
 
{
40
 
   if ( devnum == -1 )
41
 
      m_devnum = 0;
42
 
}
43
 
 
44
 
Mixer_PULSE::~Mixer_PULSE()
45
 
{
46
 
   close();
47
 
}
48
 
 
49
 
int Mixer_PULSE::open()
50
 
{
51
 
    kDebug(67100) <<  "Trying Pulse sink";
52
 
    mainloop = pa_glib_mainloop_new(g_main_context_default());
53
 
    g_assert(mainloop);
54
 
    pa_mainloop_api *api = pa_glib_mainloop_get_api(mainloop);
55
 
    g_assert(api);
56
 
 
57
 
    context = pa_context_new(api, "KMix KDE 4");
58
 
    g_assert(context);
59
 
      //return Mixer::ERR_OPEN;
60
 
 
61
 
/* 
62
 
      //
63
 
      // Mixer is open. Now define all of the mix devices.
64
 
      //
65
 
 
66
 
         for ( int idx = 0; idx < numDevs; idx++ )
67
 
         {
68
 
            Volume vol( 2, AUDIO_MAX_GAIN );
69
 
            QString id;
70
 
            id.setNum(idx);
71
 
            MixDevice* md = new MixDevice( _mixer, id,
72
 
               QString(MixerDevNames[idx]), MixerChannelTypes[idx]);
73
 
            md->addPlaybackVolume(vol);
74
 
            md->setRecSource( isRecsrcHW( idx ) );
75
 
            m_mixDevices.append( md );
76
 
         }
77
 
*/
78
 
 
79
 
    m_mixerName = "PULSE Audio Mixer";
80
 
 
81
 
    m_isOpen = true;
82
 
 
83
 
    return 0;
84
 
}
85
 
 
86
 
int Mixer_PULSE::close()
87
 
{
88
 
    if (context)
89
 
    {
90
 
        pa_context_unref(context);
91
 
        context = NULL;
92
 
    }
93
 
    if (mainloop)
94
 
    {
95
 
        pa_glib_mainloop_free(mainloop);
96
 
        mainloop = NULL;
97
 
    }
98
 
    return 1;
99
 
}
100
 
 
101
 
int Mixer_PULSE::readVolumeFromHW( const QString& id, MixDevice *md )
102
 
{
103
 
/*   audio_info_t audioinfo;
104
 
   uint_t devMask = MixerSunPortMasks[devnum];
105
 
 
106
 
   Volume& volume = md->playbackVolume();
107
 
   int devnum = id2num(id);
108
 
   //
109
 
   // Read the current audio information from the driver
110
 
   //
111
 
   if ( ioctl( fd, AUDIO_GETINFO, &audioinfo ) < 0 )
112
 
   {
113
 
      return( Mixer::ERR_READ );
114
 
   }
115
 
   else
116
 
   {
117
 
      //
118
 
      // Extract the appropriate fields based on the requested device
119
 
      //
120
 
      switch ( devnum )
121
 
      {
122
 
         case MIXERDEV_MASTER_VOLUME :
123
 
            volume.setSwitchActivated( audioinfo.output_muted );
124
 
            GainBalanceToVolume( audioinfo.play.gain,
125
 
                                 audioinfo.play.balance,
126
 
                                 volume );
127
 
            break;
128
 
 
129
 
         case MIXERDEV_RECORD_MONITOR :
130
 
            md->setMuted(false);
131
 
            volume.setAllVolumes( audioinfo.monitor_gain );
132
 
            break;
133
 
 
134
 
         case MIXERDEV_INTERNAL_SPEAKER :
135
 
         case MIXERDEV_HEADPHONE :
136
 
         case MIXERDEV_LINE_OUT :
137
 
            md->setMuted( (audioinfo.play.port & devMask) ? false : true );
138
 
            GainBalanceToVolume( audioinfo.play.gain,
139
 
                                 audioinfo.play.balance,
140
 
                                 volume );
141
 
            break;
142
 
 
143
 
         case MIXERDEV_MICROPHONE :
144
 
         case MIXERDEV_LINE_IN :
145
 
         case MIXERDEV_CD :
146
 
            md->setMuted( (audioinfo.record.port & devMask) ? false : true );
147
 
            GainBalanceToVolume( audioinfo.record.gain,
148
 
                                 audioinfo.record.balance,
149
 
                                 volume );
150
 
            break;
151
 
 
152
 
         default :
153
 
            return Mixer::ERR_READ;
154
 
      }
155
 
      return 0;
156
 
   }*/
157
 
   return 0;
158
 
}
159
 
 
160
 
int Mixer_PULSE::writeVolumeToHW( const QString& id, MixDevice *md )
161
 
{
162
 
/*   uint_t gain;
163
 
   uchar_t balance;
164
 
   uchar_t mute;
165
 
 
166
 
   Volume& volume = md->playbackVolume();
167
 
   int devnum = id2num(id);
168
 
   //
169
 
   // Convert the Volume(left vol, right vol) to the Gain/Balance Sun uses
170
 
   //
171
 
   VolumeToGainBalance( volume, gain, balance );
172
 
   mute = md->isMuted() ? 1 : 0;
173
 
 
174
 
   //
175
 
   // Read the current audio settings from the hardware
176
 
   //
177
 
   audio_info_t audioinfo;
178
 
   if ( ioctl( fd, AUDIO_GETINFO, &audioinfo ) < 0 )
179
 
   {
180
 
      return( Mixer::ERR_READ );
181
 
   }
182
 
 
183
 
   //
184
 
   // Now, based on the devnum that we are writing to, update the appropriate
185
 
   // volume field and twiddle the appropriate bitmask to enable/mute the
186
 
   // device as necessary.
187
 
   //
188
 
   switch ( devnum )
189
 
   {
190
 
      case MIXERDEV_MASTER_VOLUME :
191
 
         audioinfo.play.gain = gain;
192
 
         audioinfo.play.balance = balance;
193
 
         audioinfo.output_muted = mute;
194
 
         break;
195
 
 
196
 
      case MIXERDEV_RECORD_MONITOR :
197
 
         audioinfo.monitor_gain = gain;
198
 
         // no mute or balance for record monitor
199
 
         break;
200
 
 
201
 
      case MIXERDEV_INTERNAL_SPEAKER :
202
 
      case MIXERDEV_HEADPHONE :
203
 
      case MIXERDEV_LINE_OUT :
204
 
         audioinfo.play.gain = gain;
205
 
         audioinfo.play.balance = balance;
206
 
         if ( mute )
207
 
            audioinfo.play.port &= ~MixerSunPortMasks[devnum];
208
 
         else
209
 
            audioinfo.play.port |= MixerSunPortMasks[devnum];
210
 
         break;
211
 
 
212
 
      case MIXERDEV_MICROPHONE :
213
 
      case MIXERDEV_LINE_IN :
214
 
      case MIXERDEV_CD :
215
 
         audioinfo.record.gain = gain;
216
 
         audioinfo.record.balance = balance;
217
 
         if ( mute )
218
 
            audioinfo.record.port &= ~MixerSunPortMasks[devnum];
219
 
         else
220
 
            audioinfo.record.port |= MixerSunPortMasks[devnum];
221
 
         break;
222
 
 
223
 
      default :
224
 
         return Mixer::ERR_READ;
225
 
   }
226
 
 
227
 
   //
228
 
   // Now that we've updated the audioinfo struct, write it back to the hardware
229
 
   //
230
 
   if ( ioctl( fd, AUDIO_SETINFO, &audioinfo ) < 0 )
231
 
   {
232
 
      return( Mixer::ERR_WRITE );
233
 
   }
234
 
   else
235
 
   {
236
 
      return 0;
237
 
   }*/
238
 
   return 0;
239
 
}
240
 
 
241
 
void Mixer_PULSE::setRecsrcHW( const QString& /*id*/, bool /* on */ )
242
 
{
243
 
   return;
244
 
}
245
 
 
246
 
bool Mixer_PULSE::isRecsrcHW( const QString& id )
247
 
{
248
 
/*   int devnum = id2num(id);
249
 
   switch ( devnum )
250
 
   {
251
 
      case MIXERDEV_MICROPHONE :
252
 
      case MIXERDEV_LINE_IN :
253
 
      case MIXERDEV_CD :
254
 
         return true;
255
 
 
256
 
      default :
257
 
         return false;
258
 
   }*/
259
 
   return false;
260
 
}
261
 
 
262
 
 
263
 
QString PULSE_getDriverName() {
264
 
        return "PulseAudio";
265
 
}
266
 
 
267
 
QString Mixer_PULSE::getDriverName()
268
 
{
269
 
        return "PulseAudio";
270
 
}
271