summary refs log tree commit diff
path: root/pkgs/applications/networking/mumble/mumble-jack-support.patch
blob: 7c18a33193dfd1155140c00ee3d80038a4b7d03d (plain) (blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
The patch was created by Filipe Coelho (falkTX) of the KXStudio
project. http://kxstudio.sourceforge.net

diff -U 3 -H -d -r -N -- mumble-1.2.2.orig/src/mumble/JackAudio.cpp mumble-1.2.2/src/mumble/JackAudio.cpp
--- mumble-1.2.2.orig/src/mumble/JackAudio.cpp	1970-01-01 01:00:00.000000000 +0100
+++ mumble-1.2.2/src/mumble/JackAudio.cpp	2011-01-26 06:02:00.000000000 +0000
@@ -0,0 +1,314 @@
+/* Copyright (C) 2011, Benjamin Jemlich <pcgod@users.sourceforge.net>
+   Copyright (C) 2011, Filipe Coelho <falktx@gmail.com>
+
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   - Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+   - Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+   - Neither the name of the Mumble Developers nor the names of its
+     contributors may be used to endorse or promote products derived from this
+     software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "JackAudio.h"
+#include "User.h"
+#include "Global.h"
+#include "MainWindow.h"
+#include "Timer.h"
+
+#include <cstring>
+
+static JackAudioSystem *jasys = NULL;
+
+class JackAudioInputRegistrar : public AudioInputRegistrar {
+        public:
+                JackAudioInputRegistrar();
+                virtual AudioInput *create();
+                virtual const QList<audioDevice> getDeviceChoices();
+                virtual void setDeviceChoice(const QVariant &, Settings &);
+                virtual bool canEcho(const QString &) const;
+};
+
+class JackAudioOutputRegistrar : public AudioOutputRegistrar {
+        public:
+                JackAudioOutputRegistrar();
+                virtual AudioOutput *create();
+                virtual const QList<audioDevice> getDeviceChoices();
+                virtual void setDeviceChoice(const QVariant &, Settings &);
+};
+
+class JackAudioInit : public DeferInit {
+        public:
+                JackAudioInputRegistrar *airJackAudio;
+                JackAudioOutputRegistrar *aorJackAudio;
+                void initialize() {
+                        jasys = new JackAudioSystem();
+                        jasys->init_jack();
+                        jasys->qmWait.lock();
+                        jasys->qwcWait.wait(&jasys->qmWait, 1000);
+                        jasys->qmWait.unlock();
+                        if (jasys->bJackIsGood) {
+                                airJackAudio = new JackAudioInputRegistrar();
+                                aorJackAudio = new JackAudioOutputRegistrar();
+                        } else {
+                                airJackAudio = NULL;
+                                aorJackAudio = NULL;
+                                delete jasys;
+                                jasys = NULL;
+                        }
+                };
+                void destroy() {
+                        if (airJackAudio)
+                                delete airJackAudio;
+                        if (aorJackAudio)
+                                delete aorJackAudio;
+                        if (jasys) {
+                                jasys->close_jack();
+                                delete jasys;
+                                jasys = NULL;
+                        }
+                };
+};
+
+static JackAudioInit jackinit; //unused
+
+JackAudioSystem::JackAudioSystem() {
+        bJackIsGood = false;
+        iSampleRate = 0;
+}
+
+JackAudioSystem::~JackAudioSystem() {
+}
+
+void JackAudioSystem::init_jack()
+{
+        client = jack_client_open("mumble", JackNullOption, 0);
+
+        if (client) {
+                in_port = jack_port_register(client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
+                out_port = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+                jack_set_process_callback(client, process_callback, this);
+                jack_set_sample_rate_callback(client, srate_callback, this);
+                jack_on_shutdown(client, shutdown_callback, this);
+
+                iSampleRate = jack_get_sample_rate(client);
+
+                if (jack_activate(client) || in_port == NULL || out_port == NULL) {
+                    client = NULL;
+                    return;
+                }
+
+                int port_flags;
+                unsigned i = -1;
+                const char** ports = jack_get_ports(client, 0, 0, JackPortIsPhysical);
+
+                if (ports) {
+                    while (ports[++i])
+                    {
+                        jack_port_t* port = jack_port_by_name(client, ports[i]);
+                        port_flags = jack_port_flags(port);
+
+                        if (port_flags & (JackPortIsPhysical|JackPortIsOutput) && strstr(jack_port_type(port), "audio")) {
+                            jack_connect(client, ports[i], jack_port_name(in_port));
+                        }
+                        if (port_flags & (JackPortIsPhysical|JackPortIsInput) && strstr(jack_port_type(port), "audio")) {
+                            jack_connect(client, jack_port_name(out_port), ports[i]);
+                        }
+                    }
+                }
+
+                jack_free(ports);
+
+                // If we made it this far, then everything is okay
+                qhInput.insert(QString(), tr("Hardware Ports"));
+                qhOutput.insert(QString(), tr("Hardware Ports"));
+                bJackIsGood = true;
+
+            } else {
+                bJackIsGood = false;
+                client = NULL;
+            }
+}
+
+void JackAudioSystem::close_jack()
+{
+        if (client) {
+                jack_deactivate(client);
+                jack_client_close(client);
+                client = NULL;
+        }
+}
+
+int JackAudioSystem::process_callback(jack_nframes_t nframes, void *arg)
+{
+        JackAudioSystem *jas = (JackAudioSystem*)arg;
+
+        if (jas && jas->bJackIsGood) {
+                AudioInputPtr ai = g.ai;
+                AudioOutputPtr ao = g.ao;
+                JackAudioInput *jai = (JackAudioInput*)(ai.get());
+                JackAudioOutput *jao = (JackAudioOutput*)(ao.get());
+
+                if (jai && jai->bRunning && jai->iMicChannels > 0 && !jai->isFinished()) {
+                        void* input = jack_port_get_buffer(jas->in_port, nframes);
+                        if ((float*)input != 0)
+                            jai->addMic(input, nframes);
+                }
+
+                if (jao && jao->bRunning && jao->iChannels > 0 && !jao->isFinished()) {
+                        jack_default_audio_sample_t* output = (jack_default_audio_sample_t*)jack_port_get_buffer(jas->out_port, nframes);
+                        memset(output, 0, sizeof(jack_default_audio_sample_t)*nframes); //TEST
+                        jao->mix(output, nframes);
+                }
+        }
+
+        return 0;
+}
+
+int JackAudioSystem::srate_callback(jack_nframes_t frames, void *arg)
+{
+        JackAudioSystem *jas = (JackAudioSystem*)arg;
+        jas->iSampleRate = frames;
+        return 0;
+}
+
+void JackAudioSystem::shutdown_callback(void *arg)
+{
+        JackAudioSystem *jas = (JackAudioSystem*)arg;
+        jas->bJackIsGood = false;
+}
+
+JackAudioInputRegistrar::JackAudioInputRegistrar() : AudioInputRegistrar(QLatin1String("JACK"), 10) {
+}
+
+AudioInput *JackAudioInputRegistrar::create() {
+        return new JackAudioInput();
+}
+
+const QList<audioDevice> JackAudioInputRegistrar::getDeviceChoices() {
+        QList<audioDevice> qlReturn;
+
+        QStringList qlInputDevs = jasys->qhInput.keys();
+        qSort(qlInputDevs);
+
+        foreach(const QString &dev, qlInputDevs) {
+                qlReturn << audioDevice(jasys->qhInput.value(dev), dev);
+        }
+
+        return qlReturn;
+}
+
+void JackAudioInputRegistrar::setDeviceChoice(const QVariant &choice, Settings &s) {
+        Q_UNUSED(choice);
+        Q_UNUSED(s);
+}
+
+bool JackAudioInputRegistrar::canEcho(const QString &osys) const {
+        Q_UNUSED(osys);
+        return false;
+}
+
+JackAudioOutputRegistrar::JackAudioOutputRegistrar() : AudioOutputRegistrar(QLatin1String("JACK"), 10) {
+}
+
+AudioOutput *JackAudioOutputRegistrar::create() {
+        return new JackAudioOutput();
+}
+
+const QList<audioDevice> JackAudioOutputRegistrar::getDeviceChoices() {
+        QList<audioDevice> qlReturn;
+
+        QStringList qlOutputDevs = jasys->qhOutput.keys();
+        qSort(qlOutputDevs);
+
+        foreach(const QString &dev, qlOutputDevs) {
+                qlReturn << audioDevice(jasys->qhOutput.value(dev), dev);
+        }
+
+        return qlReturn;
+}
+
+void JackAudioOutputRegistrar::setDeviceChoice(const QVariant &choice, Settings &s) {
+        Q_UNUSED(choice);
+        Q_UNUSED(s);
+}
+
+JackAudioInput::JackAudioInput() {
+        bRunning = true;
+        iMicChannels = 0;
+};
+
+JackAudioInput::~JackAudioInput() {
+        bRunning = false;
+        iMicChannels = 0;
+        qmMutex.lock();
+        qwcWait.wakeAll();
+        qmMutex.unlock();
+        wait();
+}
+
+void JackAudioInput::run() {
+        if (jasys && jasys->bJackIsGood) {
+            iMicFreq = jasys->iSampleRate;
+            iMicChannels = 1;
+            eMicFormat = SampleFloat;
+            initializeMixer();
+        }
+
+        qmMutex.lock();
+        while (bRunning)
+                qwcWait.wait(&qmMutex);
+        qmMutex.unlock();
+}
+
+JackAudioOutput::JackAudioOutput() {
+        bRunning = true;
+        iChannels = 0;
+}
+
+JackAudioOutput::~JackAudioOutput() {
+        bRunning = false;
+        iChannels = 0;
+        qmMutex.lock();
+        qwcWait.wakeAll();
+        qmMutex.unlock();
+        wait();
+}
+
+void JackAudioOutput::run() {
+        if (jasys && jasys->bJackIsGood) {
+            unsigned int chanmasks[32];
+
+            chanmasks[0] = SPEAKER_FRONT_LEFT;
+            chanmasks[1] = SPEAKER_FRONT_RIGHT;
+
+            eSampleFormat = SampleFloat;
+            iMixerFreq = jasys->iSampleRate;
+            iChannels = 1;
+            initializeMixer(chanmasks);
+        }
+
+        qmMutex.lock();
+        while (bRunning)
+                qwcWait.wait(&qmMutex);
+        qmMutex.unlock();
+}
diff -U 3 -H -d -r -N -- mumble-1.2.2.orig/src/mumble/JackAudio.h mumble-1.2.2/src/mumble/JackAudio.h
--- mumble-1.2.2.orig/src/mumble/JackAudio.h	1970-01-01 01:00:00.000000000 +0100
+++ mumble-1.2.2/src/mumble/JackAudio.h	2011-01-26 06:03:58.000000000 +0000
@@ -0,0 +1,97 @@
+/* Copyright (C) 2011, Benjamin Jemlich <pcgod@users.sourceforge.net>
+   Copyright (C) 2011, Filipe Coelho <falktx@gmail.com>
+
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   - Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+   - Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+   - Neither the name of the Mumble Developers nor the names of its
+     contributors may be used to endorse or promote products derived from this
+     software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _JACKAUDIO_H
+#define _JACKAUDIO_H
+
+#include "AudioInput.h"
+#include "AudioOutput.h"
+#include <jack/jack.h>
+
+class JackAudioOutput;
+class JackAudioInput;
+
+class JackAudioSystem : public QObject {
+        private:
+                Q_OBJECT
+                Q_DISABLE_COPY(JackAudioSystem)
+        protected:
+                jack_client_t* client;
+                jack_port_t* in_port;
+                jack_port_t* out_port;
+
+                static int process_callback(jack_nframes_t nframes, void *arg);
+                static int srate_callback(jack_nframes_t frames, void *arg);
+                static void shutdown_callback(void *arg);
+        public:
+                QHash<QString, QString> qhInput;
+                QHash<QString, QString> qhOutput;
+                bool bJackIsGood;
+                int iSampleRate;
+                QMutex qmWait;
+                QWaitCondition qwcWait;
+
+                void init_jack();
+                void close_jack();
+
+                JackAudioSystem();
+                ~JackAudioSystem();
+};
+
+class JackAudioInput : public AudioInput {
+                friend class JackAudioSystem;
+        private:
+                Q_OBJECT
+                Q_DISABLE_COPY(JackAudioInput)
+        protected:
+                QMutex qmMutex;
+                QWaitCondition qwcWait;
+        public:
+                JackAudioInput();
+                ~JackAudioInput();
+                void run();
+};
+
+class JackAudioOutput : public AudioOutput {
+                friend class JackAudioSystem;
+        private:
+                Q_OBJECT
+                Q_DISABLE_COPY(JackAudioOutput)
+        protected:
+                QMutex qmMutex;
+                QWaitCondition qwcWait;
+        public:
+                JackAudioOutput();
+                ~JackAudioOutput();
+                void run();
+};
+
+#endif
diff -U 3 -H -d -r -N -- mumble-1.2.2.orig/src/mumble/mumble.pro mumble-1.2.2/src/mumble/mumble.pro
--- mumble-1.2.2.orig/src/mumble/mumble.pro	2010-02-09 16:34:51.000000000 +0000
+++ mumble-1.2.2/src/mumble/mumble.pro	2011-01-26 01:45:55.000000000 +0000
@@ -93,11 +93,17 @@
 unix {
   HAVE_PULSEAUDIO=$$system(pkg-config --modversion --silence-errors libpulse)
   HAVE_PORTAUDIO=$$system(pkg-config --modversion --silence-errors portaudio-2.0)
+  HAVE_JACKAUDIO=$$system(pkg-config --modversion --silence-errors jack)
 
   !isEmpty(HAVE_PORTAUDIO):!CONFIG(no-portaudio) {
     CONFIG *= portaudio
   }
 
+  !isEmpty(HAVE_JACKAUDIO):!CONFIG(no-jackaudio) {
+    CONFIG -= portaudio
+    CONFIG *= jackaudio
+  }
+
   !isEmpty(HAVE_PULSEAUDIO):!CONFIG(no-pulseaudio) {
     CONFIG -= portaudio
     CONFIG *= pulseaudio
@@ -110,6 +116,13 @@
     QMAKE_CXXFLAGS_DEBUG *= -I../../speex/include -I../../speexbuild
   }
 
+  jackaudio {
+        DEFINES *= USE_JACKAUDIO
+        PKGCONFIG *= jack
+        HEADERS *= JackAudio.h
+        SOURCES *= JackAudio.cpp
+  }
+
   CONFIG *= link_pkgconfig
 
   PKGCONFIG *= openssl sndfile