mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 07:53:08 +02:00
complete inital test of AudioInjector API
This commit is contained in:
parent
4c15c54535
commit
2409b5f784
5 changed files with 42 additions and 10 deletions
|
@ -22,6 +22,8 @@
|
||||||
const char ASSIGNMENT_CLIENT_TARGET_NAME[] = "assignment-client";
|
const char ASSIGNMENT_CLIENT_TARGET_NAME[] = "assignment-client";
|
||||||
const long long ASSIGNMENT_REQUEST_INTERVAL_MSECS = 1 * 1000;
|
const long long ASSIGNMENT_REQUEST_INTERVAL_MSECS = 1 * 1000;
|
||||||
|
|
||||||
|
int hifiSockAddrMeta = qRegisterMetaType<HifiSockAddr>("HifiSockAddr");
|
||||||
|
|
||||||
AssignmentClient::AssignmentClient(int &argc, char **argv,
|
AssignmentClient::AssignmentClient(int &argc, char **argv,
|
||||||
Assignment::Type requestAssignmentType,
|
Assignment::Type requestAssignmentType,
|
||||||
const HifiSockAddr& customAssignmentServerSocket,
|
const HifiSockAddr& customAssignmentServerSocket,
|
||||||
|
@ -31,7 +33,6 @@ AssignmentClient::AssignmentClient(int &argc, char **argv,
|
||||||
_currentAssignment(NULL)
|
_currentAssignment(NULL)
|
||||||
{
|
{
|
||||||
// register meta type is required for queued invoke method on Assignment subclasses
|
// register meta type is required for queued invoke method on Assignment subclasses
|
||||||
qRegisterMetaType<HifiSockAddr>("HifiSockAddr");
|
|
||||||
|
|
||||||
// set the logging target to the the CHILD_TARGET_NAME
|
// set the logging target to the the CHILD_TARGET_NAME
|
||||||
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
#include <AudioInjector.h>
|
||||||
#include <NodeTypes.h>
|
#include <NodeTypes.h>
|
||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
#include <OctalCode.h>
|
#include <OctalCode.h>
|
||||||
|
@ -1317,6 +1318,12 @@ void Application::timer() {
|
||||||
// ask the node list to check in with the domain server
|
// ask the node list to check in with the domain server
|
||||||
NodeList::getInstance()->sendDomainServerCheckIn();
|
NodeList::getInstance()->sendDomainServerCheckIn();
|
||||||
|
|
||||||
|
static AudioInjector testInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/throw.raw"));
|
||||||
|
|
||||||
|
if (testInjector.size()) {
|
||||||
|
testInjector.injectViaThread(&_audio);
|
||||||
|
}
|
||||||
|
|
||||||
// give the MyAvatar object position to the Profile so it can propagate to the data-server
|
// give the MyAvatar object position to the Profile so it can propagate to the data-server
|
||||||
_profile.updatePosition(_myAvatar.getPosition());
|
_profile.updatePosition(_myAvatar.getPosition());
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,4 +23,6 @@ public slots:
|
||||||
virtual void handleAudioByteArray(const QByteArray& audioByteArray) = 0;
|
virtual void handleAudioByteArray(const QByteArray& audioByteArray) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(AbstractAudioInterface*)
|
||||||
|
|
||||||
#endif /* defined(__hifi__AbstractAudioInterface__) */
|
#endif /* defined(__hifi__AbstractAudioInterface__) */
|
|
@ -14,9 +14,18 @@
|
||||||
|
|
||||||
#include "AudioInjector.h"
|
#include "AudioInjector.h"
|
||||||
|
|
||||||
AudioInjector::AudioInjector(const QUrl& sampleURL, QObject* parent) :
|
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
||||||
QObject(parent)
|
|
||||||
|
AudioInjector::AudioInjector(const QUrl& sampleURL) :
|
||||||
|
_sourceURL(sampleURL)
|
||||||
{
|
{
|
||||||
|
// we want to live on our own thread
|
||||||
|
moveToThread(&_thread);
|
||||||
|
connect(&_thread, SIGNAL(started()), this, SLOT(startDownload()));
|
||||||
|
_thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioInjector::startDownload() {
|
||||||
// assume we have a QApplication or QCoreApplication instance and use the
|
// assume we have a QApplication or QCoreApplication instance and use the
|
||||||
// QNetworkAccess manager to grab the raw audio file at the given URL
|
// QNetworkAccess manager to grab the raw audio file at the given URL
|
||||||
|
|
||||||
|
@ -24,7 +33,7 @@ AudioInjector::AudioInjector(const QUrl& sampleURL, QObject* parent) :
|
||||||
connect(manager, SIGNAL(finished(QNetworkReply*)),
|
connect(manager, SIGNAL(finished(QNetworkReply*)),
|
||||||
this, SLOT(replyFinished(QNetworkReply*)));
|
this, SLOT(replyFinished(QNetworkReply*)));
|
||||||
|
|
||||||
manager->get(QNetworkRequest(sampleURL));
|
manager->get(QNetworkRequest(_sourceURL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::replyFinished(QNetworkReply* reply) {
|
void AudioInjector::replyFinished(QNetworkReply* reply) {
|
||||||
|
@ -33,17 +42,21 @@ void AudioInjector::replyFinished(QNetworkReply* reply) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::injectViaThread(AbstractAudioInterface* localAudioInterface) {
|
void AudioInjector::injectViaThread(AbstractAudioInterface* localAudioInterface) {
|
||||||
|
// use Qt::AutoConnection so that this is called on our thread, if appropriate
|
||||||
|
QMetaObject::invokeMethod(this, "injectAudio", Qt::AutoConnection, Q_ARG(AbstractAudioInterface*, localAudioInterface));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioInjector::injectAudio(AbstractAudioInterface* localAudioInterface) {
|
||||||
|
|
||||||
// make sure we actually have samples downloaded to inject
|
// make sure we actually have samples downloaded to inject
|
||||||
if (_sampleByteArray.size()) {
|
if (_sampleByteArray.size()) {
|
||||||
// give our sample byte array to the local audio interface, if we have it, so it can be handled locally
|
// give our sample byte array to the local audio interface, if we have it, so it can be handled locally
|
||||||
if (localAudioInterface) {
|
if (localAudioInterface) {
|
||||||
// assume that localAudioInterface could be on a separate thread
|
// assume that localAudioInterface could be on a separate thread, use Qt::AutoConnection to handle properly
|
||||||
QMetaObject::invokeMethod(localAudioInterface, "handleAudioByteArray",
|
QMetaObject::invokeMethod(localAudioInterface, "handleAudioByteArray",
|
||||||
Qt::QueuedConnection,
|
Qt::AutoConnection,
|
||||||
Q_ARG(QByteArray, _sampleByteArray));
|
Q_ARG(QByteArray, _sampleByteArray));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup a new thread we can use for the injection
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,6 +10,8 @@
|
||||||
#define __hifi__AudioInjector__
|
#define __hifi__AudioInjector__
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QUrl>
|
||||||
|
|
||||||
class AbstractAudioInterface;
|
class AbstractAudioInterface;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
@ -17,14 +19,21 @@ class QNetworkReply;
|
||||||
class AudioInjector : public QObject {
|
class AudioInjector : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AudioInjector(const QUrl& sampleURL, QObject* parent = 0);
|
AudioInjector(const QUrl& sampleURL);
|
||||||
|
|
||||||
|
int size() const { return _sampleByteArray.size(); }
|
||||||
|
public slots:
|
||||||
void injectViaThread(AbstractAudioInterface* localAudioInterface = NULL);
|
void injectViaThread(AbstractAudioInterface* localAudioInterface = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray _sampleByteArray;
|
QByteArray _sampleByteArray;
|
||||||
|
QThread _thread;
|
||||||
|
QUrl _sourceURL;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void startDownload();
|
||||||
void replyFinished(QNetworkReply* reply);
|
void replyFinished(QNetworkReply* reply);
|
||||||
|
void injectAudio(AbstractAudioInterface* localAudioInterface);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__AudioInjector__) */
|
#endif /* defined(__hifi__AudioInjector__) */
|
||||||
|
|
Loading…
Reference in a new issue