2018-11-04 10:19:17 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* plugins/VOIP/gui/audiodevicehelper.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2012 by Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2012-02-15 16:17:18 -05:00
|
|
|
#include "audiodevicehelper.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
AudioDeviceHelper::AudioDeviceHelper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-24 15:53:53 -04:00
|
|
|
QAudioInput* AudioDeviceHelper::getDefaultInputDevice()
|
|
|
|
{
|
2012-02-15 16:17:18 -05:00
|
|
|
QAudioFormat fmt;
|
2013-10-19 20:56:34 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
|
|
|
fmt.setSampleRate(16000);
|
|
|
|
fmt.setChannelCount(1);
|
|
|
|
#else
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setFrequency(16000);
|
|
|
|
fmt.setChannels(1);
|
2013-10-19 20:56:34 -04:00
|
|
|
#endif
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setSampleSize(16);
|
|
|
|
fmt.setSampleType(QAudioFormat::SignedInt);
|
|
|
|
fmt.setByteOrder(QAudioFormat::LittleEndian);
|
|
|
|
fmt.setCodec("audio/pcm");
|
|
|
|
|
|
|
|
QAudioDeviceInfo it, dev;
|
2012-09-24 15:53:53 -04:00
|
|
|
QList<QAudioDeviceInfo> input_list = QAudioDeviceInfo::availableDevices(QAudio::AudioInput) ;
|
2012-02-15 16:17:18 -05:00
|
|
|
|
|
|
|
dev = QAudioDeviceInfo::defaultInputDevice();
|
|
|
|
if (dev.deviceName() != "pulse") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, input_list) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() == "pulse") {
|
|
|
|
dev = it;
|
|
|
|
qDebug("Ok.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev.deviceName() == "null") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, input_list) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() != "null") {
|
|
|
|
dev = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cerr << "input device : " << dev.deviceName().toStdString() << std::endl;
|
|
|
|
return new QAudioInput(dev, fmt);
|
|
|
|
}
|
|
|
|
QAudioInput* AudioDeviceHelper::getPreferedInputDevice() {
|
|
|
|
return AudioDeviceHelper::getDefaultInputDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
QAudioOutput* AudioDeviceHelper::getDefaultOutputDevice() {
|
|
|
|
QAudioFormat fmt;
|
2013-10-19 20:56:34 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
|
|
|
fmt.setSampleRate(16000);
|
|
|
|
fmt.setChannelCount(1);
|
|
|
|
#else
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setFrequency(16000);
|
|
|
|
fmt.setChannels(1);
|
2013-10-19 20:56:34 -04:00
|
|
|
#endif
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setSampleSize(16);
|
|
|
|
fmt.setSampleType(QAudioFormat::SignedInt);
|
|
|
|
fmt.setByteOrder(QAudioFormat::LittleEndian);
|
|
|
|
fmt.setCodec("audio/pcm");
|
|
|
|
|
2012-09-24 15:53:53 -04:00
|
|
|
QList<QAudioDeviceInfo> list_output = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput) ;
|
|
|
|
|
2012-02-15 16:17:18 -05:00
|
|
|
QAudioDeviceInfo it, dev;
|
|
|
|
dev = QAudioDeviceInfo::defaultOutputDevice();
|
2012-09-24 15:53:53 -04:00
|
|
|
|
2012-02-15 16:17:18 -05:00
|
|
|
if (dev.deviceName() != "pulse") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, list_output) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() == "pulse") {
|
|
|
|
dev = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev.deviceName() == "null") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, list_output) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() != "null") {
|
|
|
|
dev = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cerr << "output device : " << dev.deviceName().toStdString() << std::endl;
|
|
|
|
return new QAudioOutput(dev, fmt);
|
|
|
|
}
|
|
|
|
QAudioOutput* AudioDeviceHelper::getPreferedOutputDevice() {
|
|
|
|
return AudioDeviceHelper::getDefaultOutputDevice();
|
|
|
|
}
|