summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-09-24 08:46:35 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-09-24 08:46:35 +0200
commit80d60a1736ff82e65fd7634cd415779c47bc13ed (patch)
treeb781c10607a4a84f9a4dd26f1748d4794166e051
parent45cbd05e50d5786a4cc18729de64b45cc28d71ba (diff)
Virtualise backend and prepare for pulseaudio.
-rw-r--r--configure.ac10
-rw-r--r--src/Makefile.am12
-rw-r--r--src/audiobackend-alsa.cc (renamed from src/audioinput.cc)57
-rw-r--r--src/audiobackend-alsa.h48
-rw-r--r--src/audiobackend-pulse.cc73
-rw-r--r--src/audiobackend-pulse.h48
-rw-r--r--src/audiobackend.cc (renamed from src/audioinput.h)23
-rw-r--r--src/audiobackend.h44
-rw-r--r--src/audioinputhandler.cc9
-rw-r--r--src/audioinputhandler.h4
-rw-r--r--src/config.ini5
-rw-r--r--src/mainwindow.cc4
-rw-r--r--src/mainwindow.h2
-rw-r--r--src/simplertp.cc35
-rw-r--r--src/soundplayer.cc20
15 files changed, 328 insertions, 66 deletions
diff --git a/configure.ac b/configure.ac
index 2374032..48ef55d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,6 +56,16 @@ dnl ======================
PKG_CHECK_MODULES(OPUS, opus >= 1.0.2)
dnl ======================
+dnl Check for libpulse
+dnl ======================
+AC_ARG_WITH(pulse, [ --with-pulse Build with pulse support])
+if test x$with_pulse == xyes; then
+ PKG_CHECK_MODULES(PULSE, pulse >= 1.0.0)
+ AC_MSG_WARN([*** Building with libpulse support!])
+ CXXFLAGS="$CXXFLAGS -DWITH_PULSE"
+fi
+
+dnl ======================
dnl Check for Jpeg library
dnl ======================
AC_CHECK_HEADER(jpeglib.h, , AC_MSG_ERROR([*** libJpeg not found!]))
diff --git a/src/Makefile.am b/src/Makefile.am
index 5dcf5cf..0ad31cd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,13 +21,15 @@ simplertp_SOURCES = \
opusdecoder.cc \
samplecache.cc \
frame.cc \
- audioinput.cc \
audioinputhandler.cc \
audiooutputhandler.cc \
soundplayer.cc \
outputstreamer.cc \
inputstreamer.cc \
- videowidget.cc
+ videowidget.cc \
+ audiobackend.cc \
+ audiobackend-alsa.cc \
+ audiobackend-pulse.cc
simplertp_genkey_LDADD =
simplertp_genkey_CXXFLAGS =
@@ -42,13 +44,15 @@ EXTRA_DIST = \
opusdecoder.h \
samplecache.h \
frame.h \
- audioinput.h \
audioinputhandler.h \
audiooutputhandler.h \
soundplayer.h \
outputstreamer.h \
inputstreamer.h \
- videowidget.h
+ videowidget.h \
+ audiobackend.h \
+ audiobackend-alsa.h \
+ audiobackend-pulse.h
simplertp_MOC = $(shell ../tools/MocList cc )
diff --git a/src/audioinput.cc b/src/audiobackend-alsa.cc
index e0b4970..b4401ca 100644
--- a/src/audioinput.cc
+++ b/src/audiobackend-alsa.cc
@@ -1,8 +1,8 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
- * audioinput.cc
+ * audiobackend-alsa.cc
*
- * Fri Sep 19 19:44:11 CEST 2014
+ * Wed Sep 24 07:47:43 CEST 2014
* Copyright 2014 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,18 +24,36 @@
* along with SimpleRTP; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "audioinput.h"
+#include "audiobackend-alsa.h"
-#include <stdio.h>
+#include <memory.h>
#include "mediaconfig.h"
-AudioInput::AudioInput(const char *device)
+AudioBackendAlsa::AudioBackendAlsa(const char *device)
{
+ //
+ // LibAO:
+ //
+ ao_initialize();
+
+ ao_sample_format sf;
+ memset(&sf, 0, sizeof(sf));
+ sf.bits = 16;
+ sf.rate = SAMPLERATE;
+ sf.channels = 1;
+ sf.byte_format = AO_FMT_NATIVE;
+
+ dev = ao_open_live(ao_default_driver_id(), &sf, 0);
+
+ //
+ // LibAudioIn:
+ //
int err;
ai = ai_init(&err, device, "", SAMPLERATE, 1);
if(ai == NULL || err) {
- printf("ai_init: %d\n", err);
+ printf("ai_init: %d (device: %s)\n", err, device);
+ exit(1);
return;
}
@@ -46,8 +64,17 @@ AudioInput::AudioInput(const char *device)
}
}
-AudioInput::~AudioInput()
+AudioBackendAlsa::~AudioBackendAlsa()
{
+ //
+ // LibAO:
+ //
+ ao_close(dev);
+ ao_shutdown();
+
+ //
+ // LibAudioIn:
+ //
if(ai == NULL) {
printf("ai_err: no handle\n");
return;
@@ -58,15 +85,27 @@ AudioInput::~AudioInput()
if(err) printf("ai_err: %d\n", err);
}
-int AudioInput::getSamples(void *pcm, size_t size)
+int AudioBackendAlsa::read(char *pcm, size_t maxsize)
{
+ //
+ // LibAudioIn:
+ //
if(ai == NULL) {
printf("ai_err: no handle\n");
return 0;
}
int err;
- int ret = ai_read(&err, ai, pcm, size);
+ int ret = ai_read(&err, ai, pcm, maxsize);
if(err) printf("ai_read: %d\n", err);
return ret;
}
+
+int AudioBackendAlsa::write(const char *pcm, size_t size)
+{
+ //
+ // LibAO:
+ //
+ ao_play(dev, (char *)pcm, size);
+ return 0;
+}
diff --git a/src/audiobackend-alsa.h b/src/audiobackend-alsa.h
new file mode 100644
index 0000000..4a79a5d
--- /dev/null
+++ b/src/audiobackend-alsa.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * audiobackend-alsa.h
+ *
+ * Wed Sep 24 07:47:43 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of SimpleRTP.
+ *
+ * SimpleRTP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * SimpleRTP 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with SimpleRTP; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __SIMPLERTP_AUDIOBACKEND_ALSA_H__
+#define __SIMPLERTP_AUDIOBACKEND_ALSA_H__
+
+#include "audiobackend.h"
+
+#include <audioin.h>
+#include <ao/ao.h>
+
+class AudioBackendAlsa : public AudioBackend {
+public:
+ AudioBackendAlsa(const char *device);
+ ~AudioBackendAlsa();
+
+ int read(char *pcm, size_t maxsize);
+ int write(const char *pcm, size_t size);
+
+private:
+ struct ai_t *ai;
+ ao_device *dev;
+};
+
+#endif/*__SIMPLERTP_AUDIOBACKEND_ALSA_H__*/
diff --git a/src/audiobackend-pulse.cc b/src/audiobackend-pulse.cc
new file mode 100644
index 0000000..57d1a5c
--- /dev/null
+++ b/src/audiobackend-pulse.cc
@@ -0,0 +1,73 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * audiobackend-pulse.cc
+ *
+ * Wed Sep 24 07:47:47 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of SimpleRTP.
+ *
+ * SimpleRTP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * SimpleRTP 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with SimpleRTP; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "audiobackend-pulse.h"
+
+#ifdef WITH_PULSE
+
+/*
+Input example:
+http://freedesktop.org/software/pulseaudio/doxygen/pacat-simple_8c-example.html
+
+Output example:
+http://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html
+*/
+
+#include "mediaconfig.h"
+
+AudioBackendPulse::AudioBackendPulse(const char *device)
+{
+ // Initialise pulse here
+
+ //s = pa_simple_new(...);
+}
+
+AudioBackendPulse::~AudioBackendPulse()
+{
+ // Shut down pulse here
+
+ //pa_simple_free(s);
+}
+
+int AudioBackendPulse::read(char *pcm, size_t maxsize)
+{
+ // read maximum 'maxsize' bytes into pcm and return number of bytes read.
+
+ //pa_simple_read(...)
+
+ return 0;
+}
+
+int AudioBackendPulse::write(const char *pcm, size_t size)
+{
+ // write pcm to pulse
+
+ //pa_simple_write(...)
+
+ return 0;
+}
+
+#endif/*WITH_PULSE*/
diff --git a/src/audiobackend-pulse.h b/src/audiobackend-pulse.h
new file mode 100644
index 0000000..7dc2be8
--- /dev/null
+++ b/src/audiobackend-pulse.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * audiobackend-pulse.h
+ *
+ * Wed Sep 24 07:47:47 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of SimpleRTP.
+ *
+ * SimpleRTP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * SimpleRTP 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with SimpleRTP; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __SIMPLERTP_AUDIOBACKEND-PULSE_H__
+#define __SIMPLERTP_AUDIOBACKEND-PULSE_H__
+
+#ifdef WITH_PULSE
+
+#include <pulse/simple.h>
+
+class AudioBackendPulse : public AudioBackend {
+public:
+ AudioBackendPulse(const char *device);
+ ~AudioBackendPulse();
+
+ int read(char *pcm, size_t maxsize);
+ int write(const char *pcm, size_t size);
+
+private:
+ pa_simple *s;
+};
+
+#endif/*WITH_PULSE*/
+
+#endif/*__SIMPLERTP_AUDIOBACKEND-PULSE_H__*/
diff --git a/src/audioinput.h b/src/audiobackend.cc
index 50e5f34..fb0057f 100644
--- a/src/audioinput.h
+++ b/src/audiobackend.cc
@@ -1,8 +1,8 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
- * audioinput.h
+ * audiobackend.cc
*
- * Fri Sep 19 19:44:11 CEST 2014
+ * Wed Sep 24 08:01:03 CEST 2014
* Copyright 2014 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,21 +24,6 @@
* along with SimpleRTP; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#ifndef __SIMPLERTP_AUDIOINPUT_H__
-#define __SIMPLERTP_AUDIOINPUT_H__
+#include "audiobackend.h"
-#include <audioin.h>
-#include <stdlib.h>
-
-class AudioInput {
-public:
- AudioInput(const char *device);
- ~AudioInput();
-
- int getSamples(void *pcm, size_t size);
-
-private:
- struct ai_t *ai;
-};
-
-#endif/*__SIMPLERTP_AUDIOINPUT_H__*/
+AudioBackend *g_audiobackend = NULL;
diff --git a/src/audiobackend.h b/src/audiobackend.h
new file mode 100644
index 0000000..4c3232d
--- /dev/null
+++ b/src/audiobackend.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * audiobackend.h
+ *
+ * Wed Sep 24 07:46:35 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of SimpleRTP.
+ *
+ * SimpleRTP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * SimpleRTP 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with SimpleRTP; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __SIMPLERTP_AUDIOBACKEND_H__
+#define __SIMPLERTP_AUDIOBACKEND_H__
+
+#include <stdlib.h>
+
+class AudioBackend {
+public:
+ AudioBackend() {}
+ virtual ~AudioBackend() {}
+
+ virtual int read(char *pcm, size_t maxsize) = 0;
+ virtual int write(const char *pcm, size_t size) = 0;
+};
+
+// Declared in audiobackend.cc
+extern AudioBackend *g_audiobackend;
+
+#endif/*__SIMPLERTP_AUDIOBACKEND_H__*/
diff --git a/src/audioinputhandler.cc b/src/audioinputhandler.cc
index 95517f6..2961289 100644
--- a/src/audioinputhandler.cc
+++ b/src/audioinputhandler.cc
@@ -28,13 +28,14 @@
#include <QMetaType>
-AudioInputHandler::AudioInputHandler(QString device)
- : ai(device.toStdString().c_str())
+#include "audiobackend.h"
+
+AudioInputHandler::AudioInputHandler()
{
qRegisterMetaType<framelist_t>("framelist_t");
// Only start if we actually have an audio interface
- if(device != "") start();
+ if(g_audiobackend != NULL) start();
}
AudioInputHandler::~AudioInputHandler()
@@ -49,7 +50,7 @@ void AudioInputHandler::run()
running = true;
while(running) {
- int sz = ai.getSamples(pcm, sizeof(pcm));
+ int sz = g_audiobackend->read(pcm, sizeof(pcm));
//printf("sz: %d\n", sz);
if(sz > 0) {
framelist_t fl = oe.encode(pcm, sz);
diff --git a/src/audioinputhandler.h b/src/audioinputhandler.h
index dbf43e7..86ed99b 100644
--- a/src/audioinputhandler.h
+++ b/src/audioinputhandler.h
@@ -30,13 +30,12 @@
#include <QThread>
#include <QString>
-#include "audioinput.h"
#include "opusencoder.h"
class AudioInputHandler : public QThread {
Q_OBJECT
public:
- AudioInputHandler(QString device);
+ AudioInputHandler();
~AudioInputHandler();
void run();
@@ -45,7 +44,6 @@ signals:
void newAudio(framelist_t list);
private:
- AudioInput ai;
OpusEncoder oe;
volatile bool running;
diff --git a/src/config.ini b/src/config.ini
index 67893e6..d669668 100644
--- a/src/config.ini
+++ b/src/config.ini
@@ -3,8 +3,9 @@
#
[hardware]
-v4ldev="/dev/video0"
-adev="hw:1,0"
+audiobackend="alsa"
+audiodevice="hw:2,0"
+v4ldevice="/dev/video0"
[crypto]
key="123456789012345678901234567890123456789012345678901234567890"
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 81ea65c..30b6151 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -30,10 +30,10 @@
#include <stdio.h>
-MainWindow::MainWindow(QString v4ldev, QString adev,
+MainWindow::MainWindow(QString v4ldev,
OutputStreamer &os,
QList<InputStreamer*> &isl)
- : v4l(v4ldev), aih(adev), ostreamer(os), islist(isl)
+ : v4l(v4ldev), ostreamer(os), islist(isl)
{
/* // Self view:
connect(&v4l, SIGNAL(newImage(Frame)),
diff --git a/src/mainwindow.h b/src/mainwindow.h
index d8329bb..4235b0a 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -43,7 +43,7 @@
class MainWindow : public QMainWindow {
Q_OBJECT
public:
- MainWindow(QString v4ldev, QString adev,
+ MainWindow(QString v4ldev,
OutputStreamer &ostreamer,
QList<InputStreamer*> &islist);
diff --git a/src/simplertp.cc b/src/simplertp.cc
index 7d1dec1..3db28ce 100644
--- a/src/simplertp.cc
+++ b/src/simplertp.cc
@@ -31,13 +31,21 @@
#include "mainwindow.h"
+#include "audiobackend.h"
+#include "audiobackend-alsa.h"
+#ifdef WITH_PULSE
+#include "audiobackend-pulse.h"
+#endif/*WITH_PULSE*/
+
int main(int argc, char *argv[])
{
+/*
int pulse = system("pidof pulseaudio &> /dev/null");
if(WEXITSTATUS(pulse) == 0) {
printf("Pulse audio is running - simplertp wont work...\n");
return 1;
}
+*/
QApplication app(argc, argv);
@@ -48,11 +56,25 @@ int main(int argc, char *argv[])
QSettings settings(argv[1], QSettings::IniFormat);
- settings.beginGroup("hardware");
- QString v4ldev = settings.value("v4ldev", "/dev/video0").toString();
- QString adev = settings.value("adev", "hw:0,0").toString();
+ settings.beginGroup("hardware");
+ QString audiobackend = settings.value("audiobackend", "alsa").toString();
+ QString audiodevice = settings.value("audiodevice", "hw:0,0").toString();
+ QString v4ldevice = settings.value("v4ldevice", "/dev/video0").toString();
settings.endGroup();
+ if(audiobackend == "alsa") {
+ g_audiobackend = new AudioBackendAlsa(audiodevice.toStdString().c_str());
+ } else
+#ifdef WITH_PULSE
+ if(audiobackend == "pulse") {
+ g_audiobackend = new AudioBackendPulse(audiodevice.toStdString().c_str());
+ } else
+#endif/*WITH_PULSE*/
+ {
+ printf("Unknown audiobackend: %s\n", audiobackend.toStdString().c_str());
+ }
+
+
settings.beginGroup("crypto");
QString key = settings.value("key").toString();
unsigned int ssrc = settings.value("ssrc").toUInt();
@@ -84,7 +106,7 @@ int main(int argc, char *argv[])
}
settings.endGroup();
- MainWindow wnd(v4ldev, adev, os, islist);
+ MainWindow wnd(v4ldevice, os, islist);
wnd.show();
int ret = app.exec();
@@ -95,5 +117,10 @@ int main(int argc, char *argv[])
i++;
}
+ if(g_audiobackend) {
+ delete g_audiobackend;
+ g_audiobackend = NULL;
+ }
+
return ret;
}
diff --git a/src/soundplayer.cc b/src/soundplayer.cc
index 42196d4..aa05358 100644
--- a/src/soundplayer.cc
+++ b/src/soundplayer.cc
@@ -27,9 +27,7 @@
*/
#include "soundplayer.h"
-#include <ao/ao.h>
-
-#include "mediaconfig.h"
+#include "audiobackend.h"
#define BUFSZ 512
@@ -49,17 +47,6 @@ SoundPlayer::~SoundPlayer()
void SoundPlayer::run()
{
- ao_initialize();
-
- ao_sample_format sf;
- memset(&sf, 0, sizeof(sf));
- sf.bits = 16;
- sf.rate = SAMPLERATE;
- sf.channels = 1;
- sf.byte_format = AO_FMT_NATIVE;
-
- ao_device *dev = ao_open_live(ao_default_driver_id(), &sf, 0);
-
running = true;
short s[BUFSZ];
@@ -71,11 +58,8 @@ void SoundPlayer::run()
pread++;
}
- ao_play(dev, (char *)s, sizeof(s));
+ g_audiobackend->write((const char *)s, sizeof(s));
}
-
- ao_close(dev);
- ao_shutdown();
}
void SoundPlayer::playSamples(int peer, const char *pcm, size_t size)