From 46d4e577bceb12c9463fdf4ef1d9a9a348f13543 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 19 Sep 2014 20:53:09 +0200 Subject: AudioHandler, AudioInput, Opus ecoder code in place. --- .gitignore | 1 + configure.ac | 13 +++-- src/Makefile.am | 26 ++++++++-- src/audiohandler.cc | 52 ++++++++++++++++++++ src/audiohandler.h | 54 +++++++++++++++++++++ src/audioinput.cc | 51 ++++++++++++++++++++ src/audioinput.h | 44 +++++++++++++++++ src/frame.cc | 36 ++++++++++++++ src/frame.h | 45 ++++++++++++++++++ src/mainwindow.cc | 16 +++++-- src/mainwindow.h | 5 +- src/opusencoder.cc | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/opusencoder.h | 51 ++++++++++++++++++++ src/samplecache.cc | 71 ++++++++++++++++++++++++++++ src/samplecache.h | 51 ++++++++++++++++++++ src/simplertp.cc | 4 +- 16 files changed, 639 insertions(+), 14 deletions(-) create mode 100644 src/audiohandler.cc create mode 100644 src/audiohandler.h create mode 100644 src/audioinput.cc create mode 100644 src/audioinput.h create mode 100644 src/frame.cc create mode 100644 src/frame.h create mode 100644 src/opusencoder.cc create mode 100644 src/opusencoder.h create mode 100644 src/samplecache.cc create mode 100644 src/samplecache.h diff --git a/.gitignore b/.gitignore index 50ea780..1552af3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ missing qrc_* src/simplertp stamp-h1 +test-driver \ No newline at end of file diff --git a/configure.ac b/configure.ac index 00f54d1..36978fd 100644 --- a/configure.ac +++ b/configure.ac @@ -45,10 +45,15 @@ if (test "$QT_UIC" = ""); then AC_MSG_ERROR([QT4 uic is required.]) fi -#dnl ====================== -#dnl Check for libao -#dnl ====================== -#PKG_CHECK_MODULES(AO, ao >= 0.8.8) +dnl ====================== +dnl Check for libao +dnl ====================== +PKG_CHECK_MODULES(AO, ao >= 0.8.8) + +dnl ====================== +dnl Check for opus +dnl ====================== +PKG_CHECK_MODULES(OPUS, opus >= 1.0.2) dnl ====================== dnl Check for Jpeg library diff --git a/src/Makefile.am b/src/Makefile.am index e407edc..1b457ca 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,21 +1,37 @@ bin_PROGRAMS = simplertp simplertp_LDADD = $(QT_LIBS) $(AO_LIBS) $(V4LC_LIBS) -ljpeg \ - $(top_srcdir)/lrtp/src/liblrtp.la $(top_srcdir)/libaudioin/src/libaudioin.la \ + $(OPUS_LIBS) $(AO_LIBS) \ + $(top_srcdir)/lrtp/src/liblrtp.la \ + $(top_srcdir)/libaudioin/src/libaudioin.la \ $(shell ../tools/MocList o ) qrc_simplertp.o -simplertp_CXXFLAGS = $(QT_CFLAGS) $(AO_CFLAGS) $(V4LC_CFLAGS) -AM_CXXFLAGS = $(QT_CFLAGS) +simplertp_CXXFLAGS = $(QT_CFLAGS) $(AO_CFLAGS) $(V4LC_CFLAGS) \ + -I$(top_srcdir)/lrtp/src \ + -I$(top_srcdir)/libaudioin/src \ + $(OPUS_CFLAGS) $(AO_CFLAGS) + +AM_CXXFLAGS = $(simplertp_CXXFLAGS) simplertp_SOURCES = \ simplertp.cc \ mainwindow.cc \ - v4l.cc + v4l.cc \ + opusencoder.cc \ + samplecache.cc \ + frame.cc \ + audioinput.cc \ + audiohandler.cc EXTRA_DIST = \ simplertp.qrc mainwindow.h \ - v4l.h + v4l.h \ + opusencoder.h \ + samplecache.h \ + frame.h \ + audioinput.h \ + audiohandler.h simplertp_MOC = $(shell ../tools/MocList cc ) diff --git a/src/audiohandler.cc b/src/audiohandler.cc new file mode 100644 index 0000000..8deb414 --- /dev/null +++ b/src/audiohandler.cc @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiohandler.cc + * + * Fri Sep 19 19:58:05 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 "audiohandler.h" + +AudioHandler::AudioHandler(QString device) + : ai(device.toStdString().c_str()) +{ + start(); +} + +AudioHandler::~AudioHandler() +{ + running = false; + wait(); +} + +void AudioHandler::run() +{ + char pcm[4096]; + running = true; + + while(running) { + int sz = ai.getSamples(pcm, sizeof(pcm)); + printf("sz: %d\n", sz); + framelist_t fl = oe.encode(pcm, sz); + emit newAudio(fl); + } +} diff --git a/src/audiohandler.h b/src/audiohandler.h new file mode 100644 index 0000000..b61cfef --- /dev/null +++ b/src/audiohandler.h @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiohandler.h + * + * Fri Sep 19 19:58:05 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_AUDIOHANDLER_H__ +#define __SIMPLERTP_AUDIOHANDLER_H__ + +#include +#include + +#include "audioinput.h" +#include "opusencoder.h" + +class AudioHandler : public QThread { +Q_OBJECT +public: + AudioHandler(QString device); + ~AudioHandler(); + + void run(); + +signals: + void newAudio(framelist_t list); + +private: + AudioInput ai; + OpusEncoder oe; + + volatile bool running; +}; + +#endif/*__SIMPLERTP_AUDIOHANDLER_H__*/ diff --git a/src/audioinput.cc b/src/audioinput.cc new file mode 100644 index 0000000..8197193 --- /dev/null +++ b/src/audioinput.cc @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audioinput.cc + * + * Fri Sep 19 19:44:11 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 "audioinput.h" + +#include + +AudioInput::AudioInput(const char *device) +{ + int err; + ai = ai_init(&err, device, "", 48000, 1); + printf("ai_err: %d\n", err); +} + +AudioInput::~AudioInput() +{ + int err; + ai_close(&err, ai); + printf("ai_err: %d\n", err); +} + +int AudioInput::getSamples(void *pcm, size_t size) +{ + int err; + int ret = ai_read(&err, ai, pcm, size); + printf("ai_err: %d\n", err); + return ret; +} diff --git a/src/audioinput.h b/src/audioinput.h new file mode 100644 index 0000000..50e5f34 --- /dev/null +++ b/src/audioinput.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audioinput.h + * + * Fri Sep 19 19:44:11 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_AUDIOINPUT_H__ +#define __SIMPLERTP_AUDIOINPUT_H__ + +#include +#include + +class AudioInput { +public: + AudioInput(const char *device); + ~AudioInput(); + + int getSamples(void *pcm, size_t size); + +private: + struct ai_t *ai; +}; + +#endif/*__SIMPLERTP_AUDIOINPUT_H__*/ diff --git a/src/frame.cc b/src/frame.cc new file mode 100644 index 0000000..4801897 --- /dev/null +++ b/src/frame.cc @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * frame.cc + * + * Fri Sep 19 19:38:59 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 "frame.h" + +#include +#include + +Frame::Frame(size_t s) +{ + size = s; + data = (char*)malloc(size); +} diff --git a/src/frame.h b/src/frame.h new file mode 100644 index 0000000..f5faebd --- /dev/null +++ b/src/frame.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * frame.h + * + * Fri Sep 19 19:38:59 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_FRAME_H__ +#define __SIMPLERTP_FRAME_H__ + +#include +#include + +class Frame { +public: + Frame(size_t s); + char *data; + size_t size; +}; + +typedef QVector< Frame* > framelist_t; +typedef unsigned int samplerate_t; + +//void freeFramelist(framelist_t &list); + +#endif/*__SIMPLERTP_FRAME_H__*/ diff --git a/src/mainwindow.cc b/src/mainwindow.cc index e4df3f2..4dcac58 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -29,10 +29,15 @@ #include #include -MainWindow::MainWindow(QString v4ldev) - : v4l(v4ldev) +MainWindow::MainWindow(QString v4ldev, QString adev) + : v4l(v4ldev), ah(adev) { - connect(&v4l, SIGNAL(newImage(QImage)), this, SLOT(newImage(QImage))); + connect(&v4l, SIGNAL(newImage(QImage)), + this, SLOT(newImage(QImage))); + + connect(&ah, SIGNAL(newAudio(framelist_t)), + this, SLOT(newAudio(framelist_t))); + setCentralWidget(new QLabel()); } @@ -52,3 +57,8 @@ void MainWindow::newImage(QImage img) l->setPixmap(p); printf("Got one\n"); } + +void MainWindow::newAudio(framelist_t list) +{ + printf("audio: %d frames\n", list.size()); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index fb87dae..0ce1f4a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,17 +31,20 @@ #include #include "v4l.h" +#include "audiohandler.h" class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(QString v4ldev); + MainWindow(QString v4ldev, QString adev); public slots: void newImage(QImage img); + void newAudio(framelist_t list); private: V4L v4l; + AudioHandler ah; }; #endif/*__SIMPLERTP_MAINWINDOW_H__*/ diff --git a/src/opusencoder.cc b/src/opusencoder.cc new file mode 100644 index 0000000..77ea0d1 --- /dev/null +++ b/src/opusencoder.cc @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * opusencoder.cc + * + * Fri Sep 19 19:21:50 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 "opusencoder.h" + +#include +#include +#include + +#include "samplecache.h" + +#define OPUS_BITRATE 64000 + +struct opus_encoder_private_t { + OpusEncoder *ce; + SampleCache *cache; +}; + +OpusEncoder::OpusEncoder() +{ + prv = new struct opus_encoder_private_t; + + prv->cache = new SampleCache(5760 * 10); + + int error = 0; + + samplerate_t srate = opus_samplerate(); + + prv->ce = + opus_encoder_create(srate, 1/*channels()*/, OPUS_APPLICATION_AUDIO, &error); + if(!prv->ce || error != OPUS_OK) { + printf("srate: %d, ch: %d, Error: %d\n", srate, 1/*channels()*/, error); + //throw InitException(); + } + + // 500 to 512000 + opus_encoder_ctl(prv->ce, OPUS_SET_BITRATE(OPUS_BITRATE/*bitrate()*/)); + + // [0-10] with 10 representing the highest complexity. + opus_encoder_ctl(prv->ce, OPUS_SET_COMPLEXITY(10)); + + /* + printf("Encoder(fs: %d, ch: %d, bitrate: %d)\n", srate, channels(), + bitrate()); + */ +} + +OpusEncoder::~OpusEncoder() +{ + if(prv) { + if(prv->ce) opus_encoder_destroy(prv->ce); + if(prv->cache) delete prv->cache; + delete prv; + } +} + +unsigned int OpusEncoder::framesize() +{ + return opus_samplerate() / 1000 * OPUS_FRAME_SIZE; // 10ms audio data +} + +samplerate_t OpusEncoder::opus_samplerate() +{ + return 48000; +} + +framelist_t OpusEncoder::encode(const char *pcm, size_t size) +{ + framelist_t list; + + // printf("PCM size: %d\n", size); + + samplerate_t srate = opus_samplerate(); + + if(prv->ce == NULL) { + //throw InitException(); + printf("prv->ce == NULL\n"); + } + + size_t bytes_per_packet = ((OPUS_BITRATE/*bitrate()*/ *framesize())/srate+4)/8; + + prv->cache->addSamples((short*)pcm, size / sizeof(short)); + + //size_t p = 0; + opus_int16 *samples = new opus_int16[framesize()]; + while(prv->cache->cacheSize() >= framesize()) { + size_t sz = prv->cache->getSamples(samples, framesize()); + + Frame *frame = new Frame(bytes_per_packet); + + int n = opus_encode(prv->ce, samples, sz / 1/*channels()*//*sizeof(short)*/, + (unsigned char *)frame->data, (opus_int32)frame->size); + + //printf("Compressed to %d\n", n); + + if(n < 0) { + printf("n < 0\n"); + //throw EncodingException(); + } + + frame->size = n; + + list.push_back(frame); + } + delete[] samples; + + //printf("%d frames in list\n", list.size()); + + return list; +} diff --git a/src/opusencoder.h b/src/opusencoder.h new file mode 100644 index 0000000..b0e16fd --- /dev/null +++ b/src/opusencoder.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * opusencoder.h + * + * Fri Sep 19 19:21:49 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_OPUS_ENCODER_H__ +#define __SIMPLERTP_OPUS_ENCODER_H__ + +#include "frame.h" + +// Frame size 10ms +#define OPUS_FRAME_SIZE 10 + +struct opus_encoder_private_t; + +class OpusEncoder { +public: + OpusEncoder(); + ~OpusEncoder(); + + framelist_t encode(const char *pcm, size_t size); + + samplerate_t opus_samplerate(); + unsigned int framesize(); + +private: + struct opus_encoder_private_t *prv; +}; + +#endif/*__SIMPLERTP_OPUS_ENCODER_H__*/ diff --git a/src/samplecache.cc b/src/samplecache.cc new file mode 100644 index 0000000..c9dc372 --- /dev/null +++ b/src/samplecache.cc @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * samplecache.cc + * + * Fri Sep 19 19:36:13 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 "samplecache.h" + +#include + +SampleCache::SampleCache(size_t c) +{ + capacity = c; + cache = new sample_t[capacity]; + start = 0; + size = 0; +} + +SampleCache::~SampleCache() +{ + delete[] cache; +} + +void SampleCache::addSamples(sample_t *samples, size_t sz) +{ + for(size_t i = 0; i < sz; i++) { + cache[(start + size) % capacity] = samples[i]; + size++; + } +} + +size_t SampleCache::getSamples(sample_t *samples, size_t sz) +{ + size_t read = 0; + for(size_t i = 0; i < sz; i++) { + if(!size) break; + samples[i] = cache[start % capacity]; + read++; + start++; + size--; + } + + start %= capacity; + + return read; +} + +size_t SampleCache::cacheSize() +{ + return size; +} diff --git a/src/samplecache.h b/src/samplecache.h new file mode 100644 index 0000000..03ff756 --- /dev/null +++ b/src/samplecache.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * samplecache.h + * + * Fri Sep 19 19:36:12 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_SAMPLECACHE_H__ +#define __SIMPLERTP_SAMPLECACHE_H__ + +#include + +typedef short sample_t; + +class SampleCache { +public: + SampleCache(size_t capacity); + ~SampleCache(); + + void addSamples(sample_t *samples, size_t size); + size_t getSamples(sample_t *samples, size_t size); + + size_t cacheSize(); + +private: + sample_t *cache; + size_t start; + size_t size; + size_t capacity; +}; + +#endif/*__SIMPLERTP_SAMPLECACHE_H__*/ diff --git a/src/simplertp.cc b/src/simplertp.cc index d833cf1..837bec5 100644 --- a/src/simplertp.cc +++ b/src/simplertp.cc @@ -33,10 +33,12 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QString v4ldev = "/dev/video0"; + QString adev = "hw:2,0"; if(argc > 1) v4ldev = argv[1]; + if(argc > 2) adev = argv[2]; - MainWindow wnd(v4ldev); + MainWindow wnd(v4ldev, adev); wnd.show(); return app.exec(); -- cgit v1.2.3