mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 07:22:19 +02:00
have RenderingClient handle returned audio frames
This commit is contained in:
parent
5716f576b7
commit
25016ef157
6 changed files with 89 additions and 10 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <QtCore/QThread>
|
||||
|
||||
#include <AddressManager.h>
|
||||
#include <HifiSockAddr.h>
|
||||
#include <NodeList.h>
|
||||
#include <PacketHeaders.h>
|
||||
|
||||
|
@ -47,6 +48,17 @@ void Client::setupNetworking() {
|
|||
connect(nodeList.data(), &NodeList::limitOfSilentDomainCheckInsReached, nodeList.data(), &NodeList::reset);
|
||||
}
|
||||
|
||||
void Client::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) {
|
||||
PacketType incomingType = packetTypeForPacket(incomingPacket);
|
||||
// only process this packet if we have a match on the packet version
|
||||
switch (incomingType) {
|
||||
default:
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
nodeList->processNodeData(senderSockAddr, incomingPacket);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Client::processDatagrams() {
|
||||
HifiSockAddr senderSockAddr;
|
||||
|
||||
|
@ -58,16 +70,9 @@ void Client::processDatagrams() {
|
|||
incomingPacket.resize(nodeList->getNodeSocket().pendingDatagramSize());
|
||||
nodeList->getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(),
|
||||
senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer());
|
||||
|
||||
|
||||
if (nodeList->packetVersionAndHashMatch(incomingPacket)) {
|
||||
|
||||
PacketType incomingType = packetTypeForPacket(incomingPacket);
|
||||
// only process this packet if we have a match on the packet version
|
||||
switch (incomingType) {
|
||||
default:
|
||||
nodeList->processNodeData(senderSockAddr, incomingPacket);
|
||||
break;
|
||||
}
|
||||
processVerifiedPacket(senderSockAddr, incomingPacket);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,14 +14,17 @@
|
|||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <HifiSockAddr.h>
|
||||
|
||||
class QThread;
|
||||
|
||||
class Client : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Client(QObject* parent = 0);
|
||||
private:
|
||||
protected:
|
||||
void setupNetworking();
|
||||
virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket);
|
||||
private slots:
|
||||
void processDatagrams();
|
||||
};
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QtCore/QThread>
|
||||
#include <QtWidgets/QInputDialog>
|
||||
|
||||
#include <AudioClient.h>
|
||||
#include <NodeList.h>
|
||||
|
||||
#include "RenderingClient.h"
|
||||
|
@ -20,4 +22,65 @@ RenderingClient::RenderingClient(QObject *parent) :
|
|||
{
|
||||
// tell the NodeList which node types all rendering clients will want to know about
|
||||
DependencyManager::get<NodeList>()->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer);
|
||||
|
||||
// get our audio client setup on its own thread
|
||||
QThread* audioThread = new QThread(this);
|
||||
auto audioClient = DependencyManager::set<AudioClient>();
|
||||
|
||||
audioClient->moveToThread(audioThread);
|
||||
connect(audioThread, &QThread::started, audioClient.data(), &AudioClient::start);
|
||||
|
||||
audioThread->start();
|
||||
}
|
||||
|
||||
RenderingClient::~RenderingClient() {
|
||||
auto audioClient = DependencyManager::get<AudioClient>();
|
||||
|
||||
// stop the audio client
|
||||
QMetaObject::invokeMethod(audioClient.data(), "stop", Qt::BlockingQueuedConnection);
|
||||
|
||||
// ask the audio thread to quit and wait until it is done
|
||||
audioClient->thread()->quit();
|
||||
audioClient->thread()->wait();
|
||||
}
|
||||
|
||||
void RenderingClient::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) {
|
||||
PacketType incomingType = packetTypeForPacket(incomingPacket);
|
||||
// only process this packet if we have a match on the packet version
|
||||
switch (incomingType) {
|
||||
case PacketTypeAudioEnvironment:
|
||||
case PacketTypeAudioStreamStats:
|
||||
case PacketTypeMixedAudio:
|
||||
case PacketTypeSilentAudioFrame: {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
if (incomingType == PacketTypeAudioStreamStats) {
|
||||
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "parseAudioStreamStatsPacket",
|
||||
Qt::QueuedConnection,
|
||||
Q_ARG(QByteArray, incomingPacket));
|
||||
} else if (incomingType == PacketTypeAudioEnvironment) {
|
||||
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "parseAudioEnvironmentData",
|
||||
Qt::QueuedConnection,
|
||||
Q_ARG(QByteArray, incomingPacket));
|
||||
} else {
|
||||
qDebug() << "Processing received audio of" << incomingPacket.size();
|
||||
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "addReceivedAudioToStream",
|
||||
Qt::QueuedConnection,
|
||||
Q_ARG(QByteArray, incomingPacket));
|
||||
}
|
||||
|
||||
// update having heard from the audio-mixer and record the bytes received
|
||||
SharedNodePointer audioMixer = nodeList->sendingNodeForPacket(incomingPacket);
|
||||
|
||||
if (audioMixer) {
|
||||
audioMixer->setLastHeardMicrostamp(usecTimestampNow());
|
||||
audioMixer->recordBytesReceived(incomingPacket.size());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Client::processVerifiedPacket(senderSockAddr, incomingPacket);
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -19,6 +19,9 @@ class RenderingClient : public Client {
|
|||
Q_OBJECT
|
||||
public:
|
||||
RenderingClient(QObject* parent = 0);
|
||||
~RenderingClient();
|
||||
private:
|
||||
virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket);
|
||||
};
|
||||
|
||||
#endif // hifi_RenderingClient_h
|
||||
|
|
|
@ -5,6 +5,9 @@ setup_hifi_library(Network Multimedia)
|
|||
|
||||
link_hifi_libraries(audio)
|
||||
|
||||
# append audio includes to our list of includes to bubble
|
||||
list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${HIFI_LIBRARY_DIR}/audio/src")
|
||||
|
||||
set(GVERB_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/gverb")
|
||||
|
||||
# As Gverb is currently the only reverb library, it's required.
|
||||
|
|
|
@ -378,9 +378,11 @@ void AudioClient::start() {
|
|||
|
||||
if (!inputFormatSupported) {
|
||||
qDebug() << "Unable to set up audio input because of a problem with input format.";
|
||||
qDebug() << "The closest format available is" << inputDeviceInfo.nearestFormat(_desiredInputFormat);
|
||||
}
|
||||
if (!outputFormatSupported) {
|
||||
qDebug() << "Unable to set up audio output because of a problem with output format.";
|
||||
qDebug() << "The closest format available is" << outputDeviceInfo.nearestFormat(_desiredOutputFormat);
|
||||
}
|
||||
|
||||
if (_audioInput) {
|
||||
|
|
Loading…
Reference in a new issue