我试图clone的音频流模型的QTCpsocket,但现在使用QUdpsocket (虚拟连接),虽然它看起来是正在执行的代码,但实际上,它没有做的工作,我无法获得流音频捕获;
的主要关注点是:是否可以使用QUDpsocket?启动QAudioOutput?
但是,要清楚地指出,这段代码在TCP socket中运行得很好!
代码片段:
在server.h文件
private:
QUdpSocket *socketUDP;在.CPP文件中
udpServer::udpServer(QObject *parent) : QObject(parent)
{
socketUDP = new QUdpSocket(this);
serverAddress = QHostAddress("192.168.1.8");
//socketUDP->bind(serverAddress, 1357);
socketUDP->bind(1357, QUdpSocket::ShareAddress);
socketUDP->open(QIODevice::ReadOnly);
connect(socketUDP, &QUdpSocket::readyRead, this, &udpServer::playStreamedAudio);
}然后是playstream()方法:
void udpServer::playStreamedAudio() {
// set the QAudioFormat parameters of output audio device.
my_QAudioFormat = new QAudioFormat;
my_QAudioFormat->setSampleRate(48000);
my_QAudioFormat->setChannelCount(1);
my_QAudioFormat->setSampleSize(8);
my_QAudioFormat->setCodec("audio/pcm");
my_QAudioFormat->setByteOrder(QAudioFormat::LittleEndian);
my_QAudioFormat->setSampleType(QAudioFormat::UnSignedInt);
//
// get default audio output device
audiOutputDevice = QAudioDeviceInfo::defaultOutputDevice();
audiooutput = new QAudioOutput(audiOutputDevice,my_QAudioFormat, this);
// attach to socket!
qDebug() << "Playaing AudioStream";
socketUDP->open(QIODevice::ReadOnly);
audiooutput->start(socketUDP); // the Audio output device shall listen to server socket for audio
}发布于 2017-12-30 15:48:40
结果表明,UDP套接字可能不适合作为QioDevices接口。似乎他们不是故意的,包最好是写到一个文件,然后处理。
https://stackoverflow.com/questions/47983619
复制相似问题