mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:49:24 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into proto-received-message
This commit is contained in:
commit
07d21514c5
43 changed files with 577 additions and 488 deletions
|
@ -27,12 +27,14 @@
|
||||||
|
|
||||||
#include <recording/Deck.h>
|
#include <recording/Deck.h>
|
||||||
#include <recording/Recorder.h>
|
#include <recording/Recorder.h>
|
||||||
|
#include <recording/Frame.h>
|
||||||
|
|
||||||
#include <WebSocketServerClass.h>
|
#include <WebSocketServerClass.h>
|
||||||
#include <EntityScriptingInterface.h> // TODO: consider moving to scriptengine.h
|
#include <EntityScriptingInterface.h> // TODO: consider moving to scriptengine.h
|
||||||
|
|
||||||
#include "avatars/ScriptableAvatar.h"
|
#include "avatars/ScriptableAvatar.h"
|
||||||
#include "RecordingScriptingInterface.h"
|
#include "RecordingScriptingInterface.h"
|
||||||
|
#include "AbstractAudioInterface.h"
|
||||||
|
|
||||||
#include "Agent.h"
|
#include "Agent.h"
|
||||||
|
|
||||||
|
@ -170,15 +172,37 @@ void Agent::run() {
|
||||||
_scriptEngine->setParent(this); // be the parent of the script engine so it gets moved when we do
|
_scriptEngine->setParent(this); // be the parent of the script engine so it gets moved when we do
|
||||||
|
|
||||||
// setup an Avatar for the script to use
|
// setup an Avatar for the script to use
|
||||||
ScriptableAvatar scriptedAvatar(_scriptEngine.get());
|
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
||||||
scriptedAvatar.setForceFaceTrackerConnected(true);
|
connect(_scriptEngine.get(), SIGNAL(update(float)), scriptedAvatar.data(), SLOT(update(float)), Qt::ConnectionType::QueuedConnection);
|
||||||
|
scriptedAvatar->setForceFaceTrackerConnected(true);
|
||||||
|
|
||||||
// call model URL setters with empty URLs so our avatar, if user, will have the default models
|
// call model URL setters with empty URLs so our avatar, if user, will have the default models
|
||||||
scriptedAvatar.setFaceModelURL(QUrl());
|
scriptedAvatar->setFaceModelURL(QUrl());
|
||||||
scriptedAvatar.setSkeletonModelURL(QUrl());
|
scriptedAvatar->setSkeletonModelURL(QUrl());
|
||||||
|
|
||||||
// give this AvatarData object to the script engine
|
// give this AvatarData object to the script engine
|
||||||
setAvatarData(&scriptedAvatar, "Avatar");
|
_scriptEngine->registerGlobalObject("Avatar", scriptedAvatar.data());
|
||||||
|
|
||||||
|
|
||||||
|
using namespace recording;
|
||||||
|
static const FrameType AVATAR_FRAME_TYPE = Frame::registerFrameType(AvatarData::FRAME_NAME);
|
||||||
|
// FIXME how to deal with driving multiple avatars locally?
|
||||||
|
Frame::registerFrameHandler(AVATAR_FRAME_TYPE, [this, scriptedAvatar](Frame::ConstPointer frame) {
|
||||||
|
AvatarData::fromFrame(frame->data, *scriptedAvatar);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
using namespace recording;
|
||||||
|
static const FrameType AUDIO_FRAME_TYPE = Frame::registerFrameType(AudioConstants::AUDIO_FRAME_NAME);
|
||||||
|
Frame::registerFrameHandler(AUDIO_FRAME_TYPE, [this, &scriptedAvatar](Frame::ConstPointer frame) {
|
||||||
|
const QByteArray& audio = frame->data;
|
||||||
|
static quint16 audioSequenceNumber{ 0 };
|
||||||
|
Transform audioTransform;
|
||||||
|
audioTransform.setTranslation(scriptedAvatar->getPosition());
|
||||||
|
audioTransform.setRotation(scriptedAvatar->getOrientation());
|
||||||
|
AbstractAudioInterface::emitAudioPacket(audio.data(), audio.size(), audioSequenceNumber, audioTransform, PacketType::MicrophoneAudioNoEcho);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
|
auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
|
||||||
_scriptEngine->registerGlobalObject("AvatarList", avatarHashMap.data());
|
_scriptEngine->registerGlobalObject("AvatarList", avatarHashMap.data());
|
||||||
|
@ -218,6 +242,10 @@ void Agent::run() {
|
||||||
QObject::connect(_scriptEngine.get(), &ScriptEngine::update, this, &Agent::processAgentAvatarAndAudio);
|
QObject::connect(_scriptEngine.get(), &ScriptEngine::update, this, &Agent::processAgentAvatarAndAudio);
|
||||||
|
|
||||||
_scriptEngine->run();
|
_scriptEngine->run();
|
||||||
|
|
||||||
|
Frame::clearFrameHandler(AUDIO_FRAME_TYPE);
|
||||||
|
Frame::clearFrameHandler(AVATAR_FRAME_TYPE);
|
||||||
|
|
||||||
setFinished(true);
|
setFinished(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +267,6 @@ void Agent::setIsAvatar(bool isAvatar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_isAvatar) {
|
if (!_isAvatar) {
|
||||||
DependencyManager::get<RecordingScriptingInterface>()->setControlledAvatar(nullptr);
|
|
||||||
|
|
||||||
if (_avatarIdentityTimer) {
|
if (_avatarIdentityTimer) {
|
||||||
_avatarIdentityTimer->stop();
|
_avatarIdentityTimer->stop();
|
||||||
|
@ -255,34 +282,30 @@ void Agent::setIsAvatar(bool isAvatar) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::setAvatarData(AvatarData* avatarData, const QString& objectName) {
|
|
||||||
_avatarData = avatarData;
|
|
||||||
_scriptEngine->registerGlobalObject(objectName, avatarData);
|
|
||||||
DependencyManager::get<RecordingScriptingInterface>()->setControlledAvatar(avatarData);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Agent::sendAvatarIdentityPacket() {
|
void Agent::sendAvatarIdentityPacket() {
|
||||||
if (_isAvatar && _avatarData) {
|
if (_isAvatar) {
|
||||||
_avatarData->sendIdentityPacket();
|
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
||||||
|
scriptedAvatar->sendIdentityPacket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::sendAvatarBillboardPacket() {
|
void Agent::sendAvatarBillboardPacket() {
|
||||||
if (_isAvatar && _avatarData) {
|
if (_isAvatar) {
|
||||||
_avatarData->sendBillboardPacket();
|
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
||||||
|
scriptedAvatar->sendBillboardPacket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Agent::processAgentAvatarAndAudio(float deltaTime) {
|
void Agent::processAgentAvatarAndAudio(float deltaTime) {
|
||||||
if (!_scriptEngine->isFinished() && _isAvatar && _avatarData) {
|
if (!_scriptEngine->isFinished() && _isAvatar) {
|
||||||
|
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
||||||
const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * AudioConstants::SAMPLE_RATE)
|
const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * AudioConstants::SAMPLE_RATE)
|
||||||
/ (1000 * 1000)) + 0.5);
|
/ (1000 * 1000)) + 0.5);
|
||||||
const int SCRIPT_AUDIO_BUFFER_BYTES = SCRIPT_AUDIO_BUFFER_SAMPLES * sizeof(int16_t);
|
const int SCRIPT_AUDIO_BUFFER_BYTES = SCRIPT_AUDIO_BUFFER_SAMPLES * sizeof(int16_t);
|
||||||
|
|
||||||
QByteArray avatarByteArray = _avatarData->toByteArray(true, randFloat() < AVATAR_SEND_FULL_UPDATE_RATIO);
|
QByteArray avatarByteArray = scriptedAvatar->toByteArray(true, randFloat() < AVATAR_SEND_FULL_UPDATE_RATIO);
|
||||||
_avatarData->doneEncoding(true);
|
scriptedAvatar->doneEncoding(true);
|
||||||
|
|
||||||
static AvatarDataSequenceNumber sequenceNumber = 0;
|
static AvatarDataSequenceNumber sequenceNumber = 0;
|
||||||
auto avatarPacket = NLPacket::create(PacketType::AvatarData, avatarByteArray.size() + sizeof(sequenceNumber));
|
auto avatarPacket = NLPacket::create(PacketType::AvatarData, avatarByteArray.size() + sizeof(sequenceNumber));
|
||||||
|
@ -347,8 +370,8 @@ void Agent::processAgentAvatarAndAudio(float deltaTime) {
|
||||||
audioPacket->writePrimitive(SCRIPT_AUDIO_BUFFER_SAMPLES);
|
audioPacket->writePrimitive(SCRIPT_AUDIO_BUFFER_SAMPLES);
|
||||||
|
|
||||||
// use the orientation and position of this avatar for the source of this audio
|
// use the orientation and position of this avatar for the source of this audio
|
||||||
audioPacket->writePrimitive(_avatarData->getPosition());
|
audioPacket->writePrimitive(scriptedAvatar->getPosition());
|
||||||
glm::quat headOrientation = _avatarData->getHeadOrientation();
|
glm::quat headOrientation = scriptedAvatar->getHeadOrientation();
|
||||||
audioPacket->writePrimitive(headOrientation);
|
audioPacket->writePrimitive(headOrientation);
|
||||||
|
|
||||||
}else if (nextSoundOutput) {
|
}else if (nextSoundOutput) {
|
||||||
|
@ -356,8 +379,8 @@ void Agent::processAgentAvatarAndAudio(float deltaTime) {
|
||||||
audioPacket->writePrimitive((quint8)0);
|
audioPacket->writePrimitive((quint8)0);
|
||||||
|
|
||||||
// use the orientation and position of this avatar for the source of this audio
|
// use the orientation and position of this avatar for the source of this audio
|
||||||
audioPacket->writePrimitive(_avatarData->getPosition());
|
audioPacket->writePrimitive(scriptedAvatar->getPosition());
|
||||||
glm::quat headOrientation = _avatarData->getHeadOrientation();
|
glm::quat headOrientation = scriptedAvatar->getHeadOrientation();
|
||||||
audioPacket->writePrimitive(headOrientation);
|
audioPacket->writePrimitive(headOrientation);
|
||||||
|
|
||||||
// write the raw audio data
|
// write the raw audio data
|
||||||
|
|
|
@ -68,13 +68,11 @@ private:
|
||||||
MixedAudioStream _receivedAudioStream;
|
MixedAudioStream _receivedAudioStream;
|
||||||
float _lastReceivedAudioLoudness;
|
float _lastReceivedAudioLoudness;
|
||||||
|
|
||||||
void setAvatarData(AvatarData* avatarData, const QString& objectName);
|
|
||||||
void setAvatarSound(Sound* avatarSound) { _avatarSound = avatarSound; }
|
void setAvatarSound(Sound* avatarSound) { _avatarSound = avatarSound; }
|
||||||
|
|
||||||
void sendAvatarIdentityPacket();
|
void sendAvatarIdentityPacket();
|
||||||
void sendAvatarBillboardPacket();
|
void sendAvatarBillboardPacket();
|
||||||
|
|
||||||
AvatarData* _avatarData = nullptr;
|
|
||||||
bool _isListeningToAudioStream = false;
|
bool _isListeningToAudioStream = false;
|
||||||
Sound* _avatarSound = nullptr;
|
Sound* _avatarSound = nullptr;
|
||||||
int _numAvatarSoundSentBytes = 0;
|
int _numAvatarSoundSentBytes = 0;
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "AssignmentActionFactory.h"
|
#include "AssignmentActionFactory.h"
|
||||||
|
|
||||||
#include "AssignmentClient.h"
|
#include "AssignmentClient.h"
|
||||||
|
#include "avatars/ScriptableAvatar.h"
|
||||||
|
|
||||||
const QString ASSIGNMENT_CLIENT_TARGET_NAME = "assignment-client";
|
const QString ASSIGNMENT_CLIENT_TARGET_NAME = "assignment-client";
|
||||||
const long long ASSIGNMENT_REQUEST_INTERVAL_MSECS = 1 * 1000;
|
const long long ASSIGNMENT_REQUEST_INTERVAL_MSECS = 1 * 1000;
|
||||||
|
@ -48,6 +49,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
|
||||||
|
|
||||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
|
|
||||||
|
auto scriptableAvatar = DependencyManager::set<ScriptableAvatar>();
|
||||||
auto addressManager = DependencyManager::set<AddressManager>();
|
auto addressManager = DependencyManager::set<AddressManager>();
|
||||||
|
|
||||||
// create a NodeList as an unassigned client, must be after addressManager
|
// create a NodeList as an unassigned client, must be after addressManager
|
||||||
|
|
|
@ -644,188 +644,187 @@ void AudioMixer::sendStatsPacket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioMixer::run() {
|
void AudioMixer::run() {
|
||||||
|
|
||||||
|
qDebug() << "Waiting for connection to domain to request settings from domain-server.";
|
||||||
|
|
||||||
|
// wait until we have the domain-server settings, otherwise we bail
|
||||||
|
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||||
|
connect(&domainHandler, &DomainHandler::settingsReceived, this, &AudioMixer::domainSettingsRequestComplete);
|
||||||
|
connect(&domainHandler, &DomainHandler::settingsReceiveFail, this, &AudioMixer::domainSettingsRequestFailed);
|
||||||
|
|
||||||
ThreadedAssignment::commonInit(AUDIO_MIXER_LOGGING_TARGET_NAME, NodeType::AudioMixer);
|
ThreadedAssignment::commonInit(AUDIO_MIXER_LOGGING_TARGET_NAME, NodeType::AudioMixer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioMixer::domainSettingsRequestComplete() {
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
||||||
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
|
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
|
||||||
|
|
||||||
nodeList->linkedDataCreateCallback = [](Node* node) {
|
nodeList->linkedDataCreateCallback = [](Node* node) {
|
||||||
node->setLinkedData(new AudioMixerClientData());
|
node->setLinkedData(new AudioMixerClientData());
|
||||||
};
|
};
|
||||||
|
|
||||||
// wait until we have the domain-server settings, otherwise we bail
|
|
||||||
DomainHandler& domainHandler = nodeList->getDomainHandler();
|
|
||||||
|
|
||||||
qDebug() << "Waiting for domain settings from domain-server.";
|
|
||||||
|
|
||||||
// block until we get the settingsRequestComplete signal
|
|
||||||
QEventLoop loop;
|
|
||||||
connect(&domainHandler, &DomainHandler::settingsReceived, &loop, &QEventLoop::quit);
|
|
||||||
connect(&domainHandler, &DomainHandler::settingsReceiveFail, &loop, &QEventLoop::quit);
|
|
||||||
domainHandler.requestDomainSettings();
|
|
||||||
loop.exec();
|
|
||||||
|
|
||||||
if (domainHandler.getSettingsObject().isEmpty()) {
|
DomainHandler& domainHandler = nodeList->getDomainHandler();
|
||||||
qDebug() << "Failed to retreive settings object from domain-server. Bailing on assignment.";
|
|
||||||
setFinished(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QJsonObject& settingsObject = domainHandler.getSettingsObject();
|
const QJsonObject& settingsObject = domainHandler.getSettingsObject();
|
||||||
|
|
||||||
// check the settings object to see if we have anything we can parse out
|
// check the settings object to see if we have anything we can parse out
|
||||||
parseSettingsObject(settingsObject);
|
parseSettingsObject(settingsObject);
|
||||||
|
|
||||||
|
// queue up a connection to start broadcasting mixes now that we're ready to go
|
||||||
|
QMetaObject::invokeMethod(this, "broadcastMixes", Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioMixer::broadcastMixes() {
|
||||||
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
||||||
int nextFrame = 0;
|
int nextFrame = 0;
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
int usecToSleep = AudioConstants::NETWORK_FRAME_USECS;
|
int usecToSleep = AudioConstants::NETWORK_FRAME_USECS;
|
||||||
|
|
||||||
const int TRAILING_AVERAGE_FRAMES = 100;
|
const int TRAILING_AVERAGE_FRAMES = 100;
|
||||||
int framesSinceCutoffEvent = TRAILING_AVERAGE_FRAMES;
|
int framesSinceCutoffEvent = TRAILING_AVERAGE_FRAMES;
|
||||||
|
|
||||||
while (!_isFinished) {
|
while (!_isFinished) {
|
||||||
const float STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.10f;
|
const float STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.10f;
|
||||||
const float BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.20f;
|
const float BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.20f;
|
||||||
|
|
||||||
const float RATIO_BACK_OFF = 0.02f;
|
const float RATIO_BACK_OFF = 0.02f;
|
||||||
|
|
||||||
const float CURRENT_FRAME_RATIO = 1.0f / TRAILING_AVERAGE_FRAMES;
|
const float CURRENT_FRAME_RATIO = 1.0f / TRAILING_AVERAGE_FRAMES;
|
||||||
const float PREVIOUS_FRAMES_RATIO = 1.0f - CURRENT_FRAME_RATIO;
|
const float PREVIOUS_FRAMES_RATIO = 1.0f - CURRENT_FRAME_RATIO;
|
||||||
|
|
||||||
if (usecToSleep < 0) {
|
if (usecToSleep < 0) {
|
||||||
usecToSleep = 0;
|
usecToSleep = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_trailingSleepRatio = (PREVIOUS_FRAMES_RATIO * _trailingSleepRatio)
|
_trailingSleepRatio = (PREVIOUS_FRAMES_RATIO * _trailingSleepRatio)
|
||||||
+ (usecToSleep * CURRENT_FRAME_RATIO / (float) AudioConstants::NETWORK_FRAME_USECS);
|
+ (usecToSleep * CURRENT_FRAME_RATIO / (float) AudioConstants::NETWORK_FRAME_USECS);
|
||||||
|
|
||||||
float lastCutoffRatio = _performanceThrottlingRatio;
|
float lastCutoffRatio = _performanceThrottlingRatio;
|
||||||
bool hasRatioChanged = false;
|
bool hasRatioChanged = false;
|
||||||
|
|
||||||
if (framesSinceCutoffEvent >= TRAILING_AVERAGE_FRAMES) {
|
if (framesSinceCutoffEvent >= TRAILING_AVERAGE_FRAMES) {
|
||||||
if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) {
|
if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) {
|
||||||
// we're struggling - change our min required loudness to reduce some load
|
// we're struggling - change our min required loudness to reduce some load
|
||||||
_performanceThrottlingRatio = _performanceThrottlingRatio + (0.5f * (1.0f - _performanceThrottlingRatio));
|
_performanceThrottlingRatio = _performanceThrottlingRatio + (0.5f * (1.0f - _performanceThrottlingRatio));
|
||||||
|
|
||||||
qDebug() << "Mixer is struggling, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
qDebug() << "Mixer is struggling, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
||||||
<< lastCutoffRatio << "and is now" << _performanceThrottlingRatio;
|
<< lastCutoffRatio << "and is now" << _performanceThrottlingRatio;
|
||||||
hasRatioChanged = true;
|
hasRatioChanged = true;
|
||||||
} else if (_trailingSleepRatio >= BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD && _performanceThrottlingRatio != 0) {
|
} else if (_trailingSleepRatio >= BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD && _performanceThrottlingRatio != 0) {
|
||||||
// we've recovered and can back off the required loudness
|
// we've recovered and can back off the required loudness
|
||||||
_performanceThrottlingRatio = _performanceThrottlingRatio - RATIO_BACK_OFF;
|
_performanceThrottlingRatio = _performanceThrottlingRatio - RATIO_BACK_OFF;
|
||||||
|
|
||||||
if (_performanceThrottlingRatio < 0) {
|
if (_performanceThrottlingRatio < 0) {
|
||||||
_performanceThrottlingRatio = 0;
|
_performanceThrottlingRatio = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Mixer is recovering, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
qDebug() << "Mixer is recovering, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
||||||
<< lastCutoffRatio << "and is now" << _performanceThrottlingRatio;
|
<< lastCutoffRatio << "and is now" << _performanceThrottlingRatio;
|
||||||
hasRatioChanged = true;
|
hasRatioChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasRatioChanged) {
|
if (hasRatioChanged) {
|
||||||
// set out min audability threshold from the new ratio
|
// set out min audability threshold from the new ratio
|
||||||
_minAudibilityThreshold = LOUDNESS_TO_DISTANCE_RATIO / (2.0f * (1.0f - _performanceThrottlingRatio));
|
_minAudibilityThreshold = LOUDNESS_TO_DISTANCE_RATIO / (2.0f * (1.0f - _performanceThrottlingRatio));
|
||||||
qDebug() << "Minimum audability required to be mixed is now" << _minAudibilityThreshold;
|
qDebug() << "Minimum audability required to be mixed is now" << _minAudibilityThreshold;
|
||||||
|
|
||||||
framesSinceCutoffEvent = 0;
|
framesSinceCutoffEvent = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasRatioChanged) {
|
if (!hasRatioChanged) {
|
||||||
++framesSinceCutoffEvent;
|
++framesSinceCutoffEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
if (now - _lastPerSecondCallbackTime > USECS_PER_SECOND) {
|
if (now - _lastPerSecondCallbackTime > USECS_PER_SECOND) {
|
||||||
perSecondActions();
|
perSecondActions();
|
||||||
_lastPerSecondCallbackTime = now;
|
_lastPerSecondCallbackTime = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeList->eachNode([&](const SharedNodePointer& node) {
|
nodeList->eachNode([&](const SharedNodePointer& node) {
|
||||||
|
|
||||||
if (node->getLinkedData()) {
|
if (node->getLinkedData()) {
|
||||||
AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData();
|
AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData();
|
||||||
|
|
||||||
// this function will attempt to pop a frame from each audio stream.
|
// this function will attempt to pop a frame from each audio stream.
|
||||||
// a pointer to the popped data is stored as a member in InboundAudioStream.
|
// a pointer to the popped data is stored as a member in InboundAudioStream.
|
||||||
// That's how the popped audio data will be read for mixing (but only if the pop was successful)
|
// That's how the popped audio data will be read for mixing (but only if the pop was successful)
|
||||||
nodeData->checkBuffersBeforeFrameSend();
|
nodeData->checkBuffersBeforeFrameSend();
|
||||||
|
|
||||||
// if the stream should be muted, send mute packet
|
// if the stream should be muted, send mute packet
|
||||||
if (nodeData->getAvatarAudioStream()
|
if (nodeData->getAvatarAudioStream()
|
||||||
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
||||||
auto mutePacket = NLPacket::create(PacketType::NoisyMute, 0);
|
auto mutePacket = NLPacket::create(PacketType::NoisyMute, 0);
|
||||||
nodeList->sendPacket(std::move(mutePacket), *node);
|
nodeList->sendPacket(std::move(mutePacket), *node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->getType() == NodeType::Agent && node->getActiveSocket()
|
if (node->getType() == NodeType::Agent && node->getActiveSocket()
|
||||||
&& nodeData->getAvatarAudioStream()) {
|
&& nodeData->getAvatarAudioStream()) {
|
||||||
|
|
||||||
int streamsMixed = prepareMixForListeningNode(node.data());
|
int streamsMixed = prepareMixForListeningNode(node.data());
|
||||||
|
|
||||||
std::unique_ptr<NLPacket> mixPacket;
|
std::unique_ptr<NLPacket> mixPacket;
|
||||||
|
|
||||||
if (streamsMixed > 0) {
|
if (streamsMixed > 0) {
|
||||||
int mixPacketBytes = sizeof(quint16) + AudioConstants::NETWORK_FRAME_BYTES_STEREO;
|
int mixPacketBytes = sizeof(quint16) + AudioConstants::NETWORK_FRAME_BYTES_STEREO;
|
||||||
mixPacket = NLPacket::create(PacketType::MixedAudio, mixPacketBytes);
|
mixPacket = NLPacket::create(PacketType::MixedAudio, mixPacketBytes);
|
||||||
|
|
||||||
// pack sequence number
|
// pack sequence number
|
||||||
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
||||||
mixPacket->writePrimitive(sequence);
|
mixPacket->writePrimitive(sequence);
|
||||||
|
|
||||||
// pack mixed audio samples
|
// pack mixed audio samples
|
||||||
mixPacket->write(reinterpret_cast<char*>(_mixSamples),
|
mixPacket->write(reinterpret_cast<char*>(_mixSamples),
|
||||||
AudioConstants::NETWORK_FRAME_BYTES_STEREO);
|
AudioConstants::NETWORK_FRAME_BYTES_STEREO);
|
||||||
} else {
|
} else {
|
||||||
int silentPacketBytes = sizeof(quint16) + sizeof(quint16);
|
int silentPacketBytes = sizeof(quint16) + sizeof(quint16);
|
||||||
mixPacket = NLPacket::create(PacketType::SilentAudioFrame, silentPacketBytes);
|
mixPacket = NLPacket::create(PacketType::SilentAudioFrame, silentPacketBytes);
|
||||||
|
|
||||||
// pack sequence number
|
// pack sequence number
|
||||||
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
||||||
mixPacket->writePrimitive(sequence);
|
mixPacket->writePrimitive(sequence);
|
||||||
|
|
||||||
// pack number of silent audio samples
|
// pack number of silent audio samples
|
||||||
quint16 numSilentSamples = AudioConstants::NETWORK_FRAME_SAMPLES_STEREO;
|
quint16 numSilentSamples = AudioConstants::NETWORK_FRAME_SAMPLES_STEREO;
|
||||||
mixPacket->writePrimitive(numSilentSamples);
|
mixPacket->writePrimitive(numSilentSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send audio environment
|
// Send audio environment
|
||||||
sendAudioEnvironmentPacket(node);
|
sendAudioEnvironmentPacket(node);
|
||||||
|
|
||||||
// send mixed audio packet
|
// send mixed audio packet
|
||||||
nodeList->sendPacket(std::move(mixPacket), *node);
|
nodeList->sendPacket(std::move(mixPacket), *node);
|
||||||
nodeData->incrementOutgoingMixedAudioSequenceNumber();
|
nodeData->incrementOutgoingMixedAudioSequenceNumber();
|
||||||
|
|
||||||
// send an audio stream stats packet if it's time
|
// send an audio stream stats packet if it's time
|
||||||
if (_sendAudioStreamStats) {
|
if (_sendAudioStreamStats) {
|
||||||
nodeData->sendAudioStreamStatsPackets(node);
|
nodeData->sendAudioStreamStatsPackets(node);
|
||||||
_sendAudioStreamStats = false;
|
_sendAudioStreamStats = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
++_sumListeners;
|
++_sumListeners;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
++_numStatFrames;
|
++_numStatFrames;
|
||||||
|
|
||||||
// since we're a while loop we need to help Qt's event processing
|
// since we're a while loop we need to help Qt's event processing
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
if (_isFinished) {
|
if (_isFinished) {
|
||||||
// at this point the audio-mixer is done
|
// at this point the audio-mixer is done
|
||||||
// check if we have a deferred delete event to process (which we should once finished)
|
// check if we have a deferred delete event to process (which we should once finished)
|
||||||
QCoreApplication::sendPostedEvents(this, QEvent::DeferredDelete);
|
QCoreApplication::sendPostedEvents(this, QEvent::DeferredDelete);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
usecToSleep = (++nextFrame * AudioConstants::NETWORK_FRAME_USECS) - timer.nsecsElapsed() / 1000; // ns to us
|
usecToSleep = (++nextFrame * AudioConstants::NETWORK_FRAME_USECS) - timer.nsecsElapsed() / 1000; // ns to us
|
||||||
|
|
||||||
if (usecToSleep > 0) {
|
if (usecToSleep > 0) {
|
||||||
usleep(usecToSleep);
|
usleep(usecToSleep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,10 +40,13 @@ public slots:
|
||||||
static const InboundAudioStream::Settings& getStreamSettings() { return _streamSettings; }
|
static const InboundAudioStream::Settings& getStreamSettings() { return _streamSettings; }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void broadcastMixes();
|
||||||
void handleNodeAudioPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
|
void handleNodeAudioPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
|
||||||
void handleMuteEnvironmentPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
|
void handleMuteEnvironmentPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void domainSettingsRequestComplete();
|
||||||
|
|
||||||
/// adds one stream to the mix for a listening node
|
/// adds one stream to the mix for a listening node
|
||||||
int addStreamToMixForListeningNodeWithStream(AudioMixerClientData* listenerNodeData,
|
int addStreamToMixForListeningNodeWithStream(AudioMixerClientData* listenerNodeData,
|
||||||
const QUuid& streamUUID,
|
const QUuid& streamUUID,
|
||||||
|
|
|
@ -71,7 +71,6 @@ const float BILLBOARD_AND_IDENTITY_SEND_PROBABILITY = 1.0f / 187.0f;
|
||||||
// 1) use the view frustum to cull those avatars that are out of view. Since avatar data doesn't need to be present
|
// 1) use the view frustum to cull those avatars that are out of view. Since avatar data doesn't need to be present
|
||||||
// if the avatar is not in view or in the keyhole.
|
// if the avatar is not in view or in the keyhole.
|
||||||
void AvatarMixer::broadcastAvatarData() {
|
void AvatarMixer::broadcastAvatarData() {
|
||||||
|
|
||||||
int idleTime = QDateTime::currentMSecsSinceEpoch() - _lastFrameTimestamp;
|
int idleTime = QDateTime::currentMSecsSinceEpoch() - _lastFrameTimestamp;
|
||||||
|
|
||||||
++_numStatFrames;
|
++_numStatFrames;
|
||||||
|
@ -513,15 +512,15 @@ void AvatarMixer::sendStatsPacket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarMixer::run() {
|
void AvatarMixer::run() {
|
||||||
|
qDebug() << "Waiting for connection to domain to request settings from domain-server.";
|
||||||
|
|
||||||
|
// wait until we have the domain-server settings, otherwise we bail
|
||||||
|
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||||
|
connect(&domainHandler, &DomainHandler::settingsReceived, this, &AvatarMixer::domainSettingsRequestComplete);
|
||||||
|
connect(&domainHandler, &DomainHandler::settingsReceiveFail, this, &AvatarMixer::domainSettingsRequestFailed);
|
||||||
|
|
||||||
ThreadedAssignment::commonInit(AVATAR_MIXER_LOGGING_NAME, NodeType::AvatarMixer);
|
ThreadedAssignment::commonInit(AVATAR_MIXER_LOGGING_NAME, NodeType::AvatarMixer);
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
|
||||||
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
|
|
||||||
|
|
||||||
nodeList->linkedDataCreateCallback = [] (Node* node) {
|
|
||||||
node->setLinkedData(new AvatarMixerClientData());
|
|
||||||
};
|
|
||||||
|
|
||||||
// setup the timer that will be fired on the broadcast thread
|
// setup the timer that will be fired on the broadcast thread
|
||||||
_broadcastTimer = new QTimer;
|
_broadcastTimer = new QTimer;
|
||||||
_broadcastTimer->setInterval(AVATAR_DATA_SEND_INTERVAL_MSECS);
|
_broadcastTimer->setInterval(AVATAR_DATA_SEND_INTERVAL_MSECS);
|
||||||
|
@ -530,33 +529,24 @@ void AvatarMixer::run() {
|
||||||
// connect appropriate signals and slots
|
// connect appropriate signals and slots
|
||||||
connect(_broadcastTimer, &QTimer::timeout, this, &AvatarMixer::broadcastAvatarData, Qt::DirectConnection);
|
connect(_broadcastTimer, &QTimer::timeout, this, &AvatarMixer::broadcastAvatarData, Qt::DirectConnection);
|
||||||
connect(&_broadcastThread, SIGNAL(started()), _broadcastTimer, SLOT(start()));
|
connect(&_broadcastThread, SIGNAL(started()), _broadcastTimer, SLOT(start()));
|
||||||
|
}
|
||||||
|
|
||||||
// wait until we have the domain-server settings, otherwise we bail
|
void AvatarMixer::domainSettingsRequestComplete() {
|
||||||
DomainHandler& domainHandler = nodeList->getDomainHandler();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
|
||||||
qDebug() << "Waiting for domain settings from domain-server.";
|
|
||||||
|
nodeList->linkedDataCreateCallback = [] (Node* node) {
|
||||||
// block until we get the settingsRequestComplete signal
|
node->setLinkedData(new AvatarMixerClientData());
|
||||||
|
};
|
||||||
QEventLoop loop;
|
|
||||||
connect(&domainHandler, &DomainHandler::settingsReceived, &loop, &QEventLoop::quit);
|
|
||||||
connect(&domainHandler, &DomainHandler::settingsReceiveFail, &loop, &QEventLoop::quit);
|
|
||||||
domainHandler.requestDomainSettings();
|
|
||||||
loop.exec();
|
|
||||||
|
|
||||||
if (domainHandler.getSettingsObject().isEmpty()) {
|
|
||||||
qDebug() << "Failed to retreive settings object from domain-server. Bailing on assignment.";
|
|
||||||
setFinished(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse the settings to pull out the values we need
|
// parse the settings to pull out the values we need
|
||||||
parseDomainServerSettings(domainHandler.getSettingsObject());
|
parseDomainServerSettings(nodeList->getDomainHandler().getSettingsObject());
|
||||||
|
|
||||||
// start the broadcastThread
|
// start the broadcastThread
|
||||||
_broadcastThread.start();
|
_broadcastThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AvatarMixer::parseDomainServerSettings(const QJsonObject& domainSettings) {
|
void AvatarMixer::parseDomainServerSettings(const QJsonObject& domainSettings) {
|
||||||
const QString AVATAR_MIXER_SETTINGS_KEY = "avatar_mixer";
|
const QString AVATAR_MIXER_SETTINGS_KEY = "avatar_mixer";
|
||||||
const QString NODE_SEND_BANDWIDTH_KEY = "max_node_send_bandwidth";
|
const QString NODE_SEND_BANDWIDTH_KEY = "max_node_send_bandwidth";
|
||||||
|
|
|
@ -36,6 +36,7 @@ private slots:
|
||||||
void handleAvatarIdentityPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
void handleAvatarIdentityPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||||
void handleAvatarBillboardPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
void handleAvatarBillboardPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||||
void handleKillAvatarPacket(QSharedPointer<ReceivedMessage> message);
|
void handleKillAvatarPacket(QSharedPointer<ReceivedMessage> message);
|
||||||
|
void domainSettingsRequestComplete();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void broadcastAvatarData();
|
void broadcastAvatarData();
|
||||||
|
|
|
@ -15,10 +15,6 @@
|
||||||
|
|
||||||
#include "ScriptableAvatar.h"
|
#include "ScriptableAvatar.h"
|
||||||
|
|
||||||
ScriptableAvatar::ScriptableAvatar(ScriptEngine* scriptEngine) : _scriptEngine(scriptEngine), _animation(NULL) {
|
|
||||||
connect(_scriptEngine, SIGNAL(update(float)), this, SLOT(update(float)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// hold and priority unused but kept so that client side JS can run.
|
// hold and priority unused but kept so that client side JS can run.
|
||||||
void ScriptableAvatar::startAnimation(const QString& url, float fps, float priority,
|
void ScriptableAvatar::startAnimation(const QString& url, float fps, float priority,
|
||||||
bool loop, bool hold, float firstFrame, float lastFrame, const QStringList& maskedJoints) {
|
bool loop, bool hold, float firstFrame, float lastFrame, const QStringList& maskedJoints) {
|
||||||
|
|
|
@ -16,11 +16,10 @@
|
||||||
#include <AvatarData.h>
|
#include <AvatarData.h>
|
||||||
#include <ScriptEngine.h>
|
#include <ScriptEngine.h>
|
||||||
|
|
||||||
class ScriptableAvatar : public AvatarData {
|
class ScriptableAvatar : public AvatarData, public Dependency{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ScriptableAvatar(ScriptEngine* scriptEngine);
|
|
||||||
|
|
||||||
/// Allows scripts to run animations.
|
/// Allows scripts to run animations.
|
||||||
Q_INVOKABLE void startAnimation(const QString& url, float fps = 30.0f, float priority = 1.0f, bool loop = false,
|
Q_INVOKABLE void startAnimation(const QString& url, float fps = 30.0f, float priority = 1.0f, bool loop = false,
|
||||||
bool hold = false, float firstFrame = 0.0f, float lastFrame = FLT_MAX, const QStringList& maskedJoints = QStringList());
|
bool hold = false, float firstFrame = 0.0f, float lastFrame = FLT_MAX, const QStringList& maskedJoints = QStringList());
|
||||||
|
@ -31,7 +30,6 @@ private slots:
|
||||||
void update(float deltatime);
|
void update(float deltatime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScriptEngine* _scriptEngine;
|
|
||||||
AnimationPointer _animation;
|
AnimationPointer _animation;
|
||||||
AnimationDetails _animationDetails;
|
AnimationDetails _animationDetails;
|
||||||
QStringList _maskedJoints;
|
QStringList _maskedJoints;
|
||||||
|
|
|
@ -253,7 +253,7 @@ void EntityServer::pruneDeletedEntities() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectionObject) {
|
void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectionObject) {
|
||||||
bool wantEditLogging = false;
|
bool wantEditLogging = false;
|
||||||
readOptionBool(QString("wantEditLogging"), settingsSectionObject, wantEditLogging);
|
readOptionBool(QString("wantEditLogging"), settingsSectionObject, wantEditLogging);
|
||||||
qDebug("wantEditLogging=%s", debug::valueOf(wantEditLogging));
|
qDebug("wantEditLogging=%s", debug::valueOf(wantEditLogging));
|
||||||
|
@ -265,6 +265,4 @@ bool EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectio
|
||||||
EntityTreePointer tree = std::static_pointer_cast<EntityTree>(_tree);
|
EntityTreePointer tree = std::static_pointer_cast<EntityTree>(_tree);
|
||||||
tree->setWantEditLogging(wantEditLogging);
|
tree->setWantEditLogging(wantEditLogging);
|
||||||
tree->setWantTerseEditLogging(wantTerseEditLogging);
|
tree->setWantTerseEditLogging(wantTerseEditLogging);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
virtual int sendSpecialPackets(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) override;
|
virtual int sendSpecialPackets(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) override;
|
||||||
|
|
||||||
virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) override;
|
virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) override;
|
||||||
virtual bool readAdditionalConfiguration(const QJsonObject& settingsSectionObject) override;
|
virtual void readAdditionalConfiguration(const QJsonObject& settingsSectionObject) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void pruneDeletedEntities();
|
void pruneDeletedEntities();
|
||||||
|
|
|
@ -317,6 +317,7 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool showStats = false;
|
bool showStats = false;
|
||||||
|
QString persistFile = "/" + getPersistFilename();
|
||||||
|
|
||||||
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
||||||
if (url.path() == "/") {
|
if (url.path() == "/") {
|
||||||
|
@ -326,6 +327,18 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
_tree->resetEditStats();
|
_tree->resetEditStats();
|
||||||
resetSendingStats();
|
resetSendingStats();
|
||||||
showStats = true;
|
showStats = true;
|
||||||
|
} else if ((url.path() == persistFile) || (url.path() == persistFile + "/")) {
|
||||||
|
if (_persistFileDownload) {
|
||||||
|
QByteArray persistFileContents = getPersistFileContents();
|
||||||
|
if (persistFileContents.length() > 0) {
|
||||||
|
connection->respond(HTTPConnection::StatusCode200, persistFileContents, qPrintable(getPersistFileMimeType()));
|
||||||
|
} else {
|
||||||
|
connection->respond(HTTPConnection::StatusCode500, HTTPConnection::StatusCode500);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
connection->respond(HTTPConnection::StatusCode403, HTTPConnection::StatusCode403); // not allowed
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +380,12 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
statsString += getFileLoadTime();
|
statsString += getFileLoadTime();
|
||||||
statsString += "\r\n";
|
statsString += "\r\n";
|
||||||
|
|
||||||
|
if (_persistFileDownload) {
|
||||||
|
statsString += QString("Persist file: <a href='%1'>%1</a>\r\n").arg(persistFile);
|
||||||
|
} else {
|
||||||
|
statsString += QString("Persist file: %1\r\n").arg(persistFile);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
statsString += "Octree file not yet loaded...\r\n";
|
statsString += "Octree file not yet loaded...\r\n";
|
||||||
}
|
}
|
||||||
|
@ -932,31 +951,14 @@ bool OctreeServer::readOptionString(const QString& optionName, const QJsonObject
|
||||||
return optionAvailable;
|
return optionAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OctreeServer::readConfiguration() {
|
void OctreeServer::readConfiguration() {
|
||||||
// if the assignment had a payload, read and parse that
|
// if the assignment had a payload, read and parse that
|
||||||
if (getPayload().size() > 0) {
|
if (getPayload().size() > 0) {
|
||||||
parsePayload();
|
parsePayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QJsonObject& settingsObject = DependencyManager::get<NodeList>()->getDomainHandler().getSettingsObject();
|
||||||
|
|
||||||
// wait until we have the domain-server settings, otherwise we bail
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
|
||||||
DomainHandler& domainHandler = nodeList->getDomainHandler();
|
|
||||||
|
|
||||||
qDebug() << "Waiting for domain settings from domain-server.";
|
|
||||||
|
|
||||||
// block until we get the settingsRequestComplete signal
|
|
||||||
QEventLoop loop;
|
|
||||||
connect(&domainHandler, &DomainHandler::settingsReceived, &loop, &QEventLoop::quit);
|
|
||||||
connect(&domainHandler, &DomainHandler::settingsReceiveFail, &loop, &QEventLoop::quit);
|
|
||||||
domainHandler.requestDomainSettings();
|
|
||||||
loop.exec();
|
|
||||||
|
|
||||||
if (domainHandler.getSettingsObject().isEmpty()) {
|
|
||||||
qDebug() << "Failed to retreive settings object from domain-server. Bailing on assignment.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QJsonObject& settingsObject = domainHandler.getSettingsObject();
|
|
||||||
QString settingsKey = getMyDomainSettingsKey();
|
QString settingsKey = getMyDomainSettingsKey();
|
||||||
QJsonObject settingsSectionObject = settingsObject[settingsKey].toObject();
|
QJsonObject settingsSectionObject = settingsObject[settingsKey].toObject();
|
||||||
_settings = settingsSectionObject; // keep this for later
|
_settings = settingsSectionObject; // keep this for later
|
||||||
|
@ -1026,7 +1028,8 @@ bool OctreeServer::readConfiguration() {
|
||||||
_wantBackup = !noBackup;
|
_wantBackup = !noBackup;
|
||||||
qDebug() << "wantBackup=" << _wantBackup;
|
qDebug() << "wantBackup=" << _wantBackup;
|
||||||
|
|
||||||
//qDebug() << "settingsSectionObject:" << settingsSectionObject;
|
readOptionBool(QString("persistFileDownload"), settingsSectionObject, _persistFileDownload);
|
||||||
|
qDebug() << "persistFileDownload=" << _persistFileDownload;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug("persistFilename= DISABLED");
|
qDebug("persistFilename= DISABLED");
|
||||||
|
@ -1064,79 +1067,79 @@ bool OctreeServer::readConfiguration() {
|
||||||
packetsPerSecondTotalMax, _packetsTotalPerInterval);
|
packetsPerSecondTotalMax, _packetsTotalPerInterval);
|
||||||
|
|
||||||
|
|
||||||
return readAdditionalConfiguration(settingsSectionObject);
|
readAdditionalConfiguration(settingsSectionObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OctreeServer::run() {
|
void OctreeServer::run() {
|
||||||
|
|
||||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
|
||||||
packetReceiver.registerListener(getMyQueryMessageType(), this, "handleOctreeQueryPacket");
|
|
||||||
packetReceiver.registerListener(PacketType::OctreeDataNack, this, "handleOctreeDataNackPacket");
|
|
||||||
packetReceiver.registerListener(PacketType::JurisdictionRequest, this, "handleJurisdictionRequestPacket");
|
|
||||||
|
|
||||||
_safeServerName = getMyServerName();
|
_safeServerName = getMyServerName();
|
||||||
|
|
||||||
// Before we do anything else, create our tree...
|
// Before we do anything else, create our tree...
|
||||||
OctreeElement::resetPopulationStatistics();
|
OctreeElement::resetPopulationStatistics();
|
||||||
_tree = createTree();
|
_tree = createTree();
|
||||||
_tree->setIsServer(true);
|
_tree->setIsServer(true);
|
||||||
|
|
||||||
// make sure our NodeList knows what type we are
|
qDebug() << "Waiting for connection to domain to request settings from domain-server.";
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
|
||||||
nodeList->setOwnerType(getMyNodeType());
|
// wait until we have the domain-server settings, otherwise we bail
|
||||||
|
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||||
|
connect(&domainHandler, &DomainHandler::settingsReceived, this, &OctreeServer::domainSettingsRequestComplete);
|
||||||
|
connect(&domainHandler, &DomainHandler::settingsReceiveFail, this, &OctreeServer::domainSettingsRequestFailed);
|
||||||
|
|
||||||
// use common init to setup common timers and logging
|
// use common init to setup common timers and logging
|
||||||
commonInit(getMyLoggingServerTargetName(), getMyNodeType());
|
commonInit(getMyLoggingServerTargetName(), getMyNodeType());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreeServer::domainSettingsRequestComplete() {
|
||||||
|
|
||||||
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
||||||
// we need to ask the DS about agents so we can ping/reply with them
|
// we need to ask the DS about agents so we can ping/reply with them
|
||||||
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
|
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
|
||||||
|
|
||||||
// read the configuration from either the payload or the domain server configuration
|
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||||
if (!readConfiguration()) {
|
packetReceiver.registerListener(getMyQueryMessageType(), this, "handleOctreeQueryPacket");
|
||||||
qDebug() << "OctreeServer bailing on run since readConfiguration has failed.";
|
packetReceiver.registerListener(PacketType::OctreeDataNack, this, "handleOctreeDataNackPacket");
|
||||||
setFinished(true);
|
packetReceiver.registerListener(PacketType::JurisdictionRequest, this, "handleJurisdictionRequestPacket");
|
||||||
return; // bailing on run, because readConfiguration failed
|
|
||||||
}
|
readConfiguration();
|
||||||
|
|
||||||
beforeRun(); // after payload has been processed
|
beforeRun(); // after payload has been processed
|
||||||
|
|
||||||
connect(nodeList.data(), SIGNAL(nodeAdded(SharedNodePointer)), SLOT(nodeAdded(SharedNodePointer)));
|
connect(nodeList.data(), SIGNAL(nodeAdded(SharedNodePointer)), SLOT(nodeAdded(SharedNodePointer)));
|
||||||
connect(nodeList.data(), SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
|
connect(nodeList.data(), SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nodeList->linkedDataCreateCallback = [] (Node* node) {
|
nodeList->linkedDataCreateCallback = [] (Node* node) {
|
||||||
OctreeQueryNode* newQueryNodeData = _instance->createOctreeQueryNode();
|
OctreeQueryNode* newQueryNodeData = _instance->createOctreeQueryNode();
|
||||||
newQueryNodeData->init();
|
newQueryNodeData->init();
|
||||||
node->setLinkedData(newQueryNodeData);
|
node->setLinkedData(newQueryNodeData);
|
||||||
};
|
};
|
||||||
|
|
||||||
srand((unsigned)time(0));
|
srand((unsigned)time(0));
|
||||||
|
|
||||||
// if we want Persistence, set up the local file and persist thread
|
// if we want Persistence, set up the local file and persist thread
|
||||||
if (_wantPersist) {
|
if (_wantPersist) {
|
||||||
|
|
||||||
// now set up PersistThread
|
// now set up PersistThread
|
||||||
_persistThread = new OctreePersistThread(_tree, _persistFilename, _persistInterval,
|
_persistThread = new OctreePersistThread(_tree, _persistFilename, _persistInterval,
|
||||||
_wantBackup, _settings, _debugTimestampNow, _persistAsFileType);
|
_wantBackup, _settings, _debugTimestampNow, _persistAsFileType);
|
||||||
_persistThread->initialize(true);
|
_persistThread->initialize(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiSockAddr senderSockAddr;
|
|
||||||
|
|
||||||
// set up our jurisdiction broadcaster...
|
// set up our jurisdiction broadcaster...
|
||||||
if (_jurisdiction) {
|
if (_jurisdiction) {
|
||||||
_jurisdiction->setNodeType(getMyNodeType());
|
_jurisdiction->setNodeType(getMyNodeType());
|
||||||
}
|
}
|
||||||
_jurisdictionSender = new JurisdictionSender(_jurisdiction, getMyNodeType());
|
_jurisdictionSender = new JurisdictionSender(_jurisdiction, getMyNodeType());
|
||||||
_jurisdictionSender->initialize(true);
|
_jurisdictionSender->initialize(true);
|
||||||
|
|
||||||
// set up our OctreeServerPacketProcessor
|
// set up our OctreeServerPacketProcessor
|
||||||
_octreeInboundPacketProcessor = new OctreeInboundPacketProcessor(this);
|
_octreeInboundPacketProcessor = new OctreeInboundPacketProcessor(this);
|
||||||
_octreeInboundPacketProcessor->initialize(true);
|
_octreeInboundPacketProcessor->initialize(true);
|
||||||
|
|
||||||
// Convert now to tm struct for local timezone
|
// Convert now to tm struct for local timezone
|
||||||
tm* localtm = localtime(&_started);
|
tm* localtm = localtime(&_started);
|
||||||
const int MAX_TIME_LENGTH = 128;
|
const int MAX_TIME_LENGTH = 128;
|
||||||
|
@ -1148,6 +1151,7 @@ void OctreeServer::run() {
|
||||||
if (gmtm) {
|
if (gmtm) {
|
||||||
strftime(utcBuffer, MAX_TIME_LENGTH, " [%m/%d/%Y %X UTC]", gmtm);
|
strftime(utcBuffer, MAX_TIME_LENGTH, " [%m/%d/%Y %X UTC]", gmtm);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Now running... started at: " << localBuffer << utcBuffer;
|
qDebug() << "Now running... started at: " << localBuffer << utcBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,9 @@ public:
|
||||||
bool isInitialLoadComplete() const { return (_persistThread) ? _persistThread->isInitialLoadComplete() : true; }
|
bool isInitialLoadComplete() const { return (_persistThread) ? _persistThread->isInitialLoadComplete() : true; }
|
||||||
bool isPersistEnabled() const { return (_persistThread) ? true : false; }
|
bool isPersistEnabled() const { return (_persistThread) ? true : false; }
|
||||||
quint64 getLoadElapsedTime() const { return (_persistThread) ? _persistThread->getLoadElapsedTime() : 0; }
|
quint64 getLoadElapsedTime() const { return (_persistThread) ? _persistThread->getLoadElapsedTime() : 0; }
|
||||||
|
QString getPersistFilename() const { return (_persistThread) ? _persistThread->getPersistFilename() : ""; }
|
||||||
|
QString getPersistFileMimeType() const { return (_persistThread) ? _persistThread->getPersistFileMimeType() : "text/plain"; }
|
||||||
|
QByteArray getPersistFileContents() const { return (_persistThread) ? _persistThread->getPersistFileContents() : QByteArray(); }
|
||||||
|
|
||||||
// Subclasses must implement these methods
|
// Subclasses must implement these methods
|
||||||
virtual OctreeQueryNode* createOctreeQueryNode() = 0;
|
virtual OctreeQueryNode* createOctreeQueryNode() = 0;
|
||||||
|
@ -126,6 +129,7 @@ public slots:
|
||||||
void sendStatsPacket();
|
void sendStatsPacket();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void domainSettingsRequestComplete();
|
||||||
void handleOctreeQueryPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
void handleOctreeQueryPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||||
void handleOctreeDataNackPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
void handleOctreeDataNackPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||||
void handleJurisdictionRequestPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
void handleJurisdictionRequestPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||||
|
@ -135,8 +139,8 @@ protected:
|
||||||
bool readOptionBool(const QString& optionName, const QJsonObject& settingsSectionObject, bool& result);
|
bool readOptionBool(const QString& optionName, const QJsonObject& settingsSectionObject, bool& result);
|
||||||
bool readOptionInt(const QString& optionName, const QJsonObject& settingsSectionObject, int& result);
|
bool readOptionInt(const QString& optionName, const QJsonObject& settingsSectionObject, int& result);
|
||||||
bool readOptionString(const QString& optionName, const QJsonObject& settingsSectionObject, QString& result);
|
bool readOptionString(const QString& optionName, const QJsonObject& settingsSectionObject, QString& result);
|
||||||
bool readConfiguration();
|
void readConfiguration();
|
||||||
virtual bool readAdditionalConfiguration(const QJsonObject& settingsSectionObject) { return true; };
|
virtual void readAdditionalConfiguration(const QJsonObject& settingsSectionObject) { };
|
||||||
void parsePayload();
|
void parsePayload();
|
||||||
void initHTTPManager(int port);
|
void initHTTPManager(int port);
|
||||||
void resetSendingStats();
|
void resetSendingStats();
|
||||||
|
@ -173,6 +177,7 @@ protected:
|
||||||
|
|
||||||
int _persistInterval;
|
int _persistInterval;
|
||||||
bool _wantBackup;
|
bool _wantBackup;
|
||||||
|
bool _persistFileDownload;
|
||||||
QString _backupExtensionFormat;
|
QString _backupExtensionFormat;
|
||||||
int _backupInterval;
|
int _backupInterval;
|
||||||
int _maxBackupVersions;
|
int _maxBackupVersions;
|
||||||
|
|
|
@ -476,6 +476,14 @@
|
||||||
"default": "",
|
"default": "",
|
||||||
"advanced": true
|
"advanced": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "persistFileDownload",
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "Persist File Download",
|
||||||
|
"help": "Includes a download link to the persist file in the server status page.",
|
||||||
|
"default": false,
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "wantEditLogging",
|
"name": "wantEditLogging",
|
||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
var PARAMS_SCRIPT_URL = Script.resolvePath('recordingEntityScript.js');
|
||||||
var rotation = Quat.safeEulerAngles(Camera.getOrientation());
|
var rotation = Quat.safeEulerAngles(Camera.getOrientation());
|
||||||
rotation = Quat.fromPitchYawRollDegrees(0, rotation.y, 0);
|
rotation = Quat.fromPitchYawRollDegrees(0, rotation.y, 0);
|
||||||
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(6, Quat.getFront(rotation)));
|
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(6, Quat.getFront(rotation)));
|
||||||
|
@ -17,5 +18,6 @@ var recordAreaEntity = Entities.addEntity({
|
||||||
blue: 255
|
blue: 255
|
||||||
},
|
},
|
||||||
visible: true,
|
visible: true,
|
||||||
script: "https://hifi-public.s3.amazonaws.com/sam/record/recordingEntityScript.js",
|
script: PARAMS_SCRIPT_URL,
|
||||||
|
ignoreForCollision: true,
|
||||||
});
|
});
|
|
@ -12,31 +12,25 @@
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
|
||||||
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/utils.js");
|
|
||||||
|
|
||||||
var insideRecorderArea = false;
|
|
||||||
var enteredInTime = false;
|
|
||||||
var isAvatarRecording = false;
|
|
||||||
var _this;
|
var _this;
|
||||||
|
var isAvatarRecording = false;
|
||||||
|
var channel = "groupRecordingChannel";
|
||||||
|
var startMessage = "RECONDING STARTED";
|
||||||
|
var stopMessage = "RECONDING ENDED";
|
||||||
|
|
||||||
function recordingEntity() {
|
function recordingEntity() {
|
||||||
_this = this;
|
_this = this;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function receivingMessage(channel, message, senderID) {
|
||||||
var isRecordingStarted = getEntityCustomData("recordingKey", _this.entityID, { isRecordingStarted: false }).isRecordingStarted;
|
print("message received on channel:" + channel + ", message:" + message + ", senderID:" + senderID);
|
||||||
if (isRecordingStarted && !isAvatarRecording) {
|
if(message === startMessage) {
|
||||||
_this.startRecording();
|
_this.startRecording();
|
||||||
} else if ((!isRecordingStarted && isAvatarRecording) || (isAvatarRecording && !insideRecorderArea)) {
|
} else if(message === stopMessage) {
|
||||||
_this.stopRecording();
|
_this.stopRecording();
|
||||||
} else if (!isRecordingStarted && insideRecorderArea && !enteredInTime) {
|
|
||||||
//if an avatar enters the zone while a recording is started he will be able to participate to the next group recording
|
|
||||||
enteredInTime = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,37 +39,29 @@
|
||||||
preload: function (entityID) {
|
preload: function (entityID) {
|
||||||
print("RECORDING ENTITY PRELOAD");
|
print("RECORDING ENTITY PRELOAD");
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
|
||||||
var entityProperties = Entities.getEntityProperties(_this.entityID);
|
var entityProperties = Entities.getEntityProperties(_this.entityID);
|
||||||
if (!entityProperties.ignoreForCollisions) {
|
if (!entityProperties.ignoreForCollisions) {
|
||||||
Entities.editEntity(_this.entityID, { ignoreForCollisions: true });
|
Entities.editEntity(_this.entityID, { ignoreForCollisions: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
//print(JSON.stringify(entityProperties));
|
Messages.messageReceived.connect(receivingMessage);
|
||||||
var recordingKey = getEntityCustomData("recordingKey", _this.entityID, undefined);
|
|
||||||
if (recordingKey === undefined) {
|
|
||||||
setEntityCustomData("recordingKey", _this.entityID, { isRecordingStarted: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
Script.update.connect(update);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
enterEntity: function (entityID) {
|
enterEntity: function (entityID) {
|
||||||
print("entering in the recording area");
|
print("entering in the recording area");
|
||||||
insideRecorderArea = true;
|
Messages.subscribe(channel);
|
||||||
var isRecordingStarted = getEntityCustomData("recordingKey", _this.entityID, { isRecordingStarted: false }).isRecordingStarted;
|
|
||||||
if (!isRecordingStarted) {
|
|
||||||
//i'm in the recording area in time (before the event starts)
|
|
||||||
enteredInTime = true;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
leaveEntity: function (entityID) {
|
leaveEntity: function (entityID) {
|
||||||
print("leaving the recording area");
|
print("leaving the recording area");
|
||||||
insideRecorderArea = false;
|
_this.stopRecording();
|
||||||
enteredInTime = false;
|
Messages.unsubscribe(channel);
|
||||||
},
|
},
|
||||||
|
|
||||||
startRecording: function (entityID) {
|
startRecording: function (entityID) {
|
||||||
if (enteredInTime && !isAvatarRecording) {
|
if (!isAvatarRecording) {
|
||||||
print("RECORDING STARTED");
|
print("RECORDING STARTED");
|
||||||
Recording.startRecording();
|
Recording.startRecording();
|
||||||
isAvatarRecording = true;
|
isAvatarRecording = true;
|
||||||
|
@ -86,7 +72,6 @@
|
||||||
if (isAvatarRecording) {
|
if (isAvatarRecording) {
|
||||||
print("RECORDING ENDED");
|
print("RECORDING ENDED");
|
||||||
Recording.stopRecording();
|
Recording.stopRecording();
|
||||||
Recording.loadLastRecording();
|
|
||||||
isAvatarRecording = false;
|
isAvatarRecording = false;
|
||||||
recordingFile = Window.save("Save recording to file", "./groupRecording", "Recordings (*.hfr)");
|
recordingFile = Window.save("Save recording to file", "./groupRecording", "Recordings (*.hfr)");
|
||||||
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
||||||
|
@ -94,13 +79,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
unload: function (entityID) {
|
unload: function (entityID) {
|
||||||
print("RECORDING ENTITY UNLOAD");
|
print("RECORDING ENTITY UNLOAD");
|
||||||
Script.update.disconnect(update);
|
_this.stopRecording();
|
||||||
|
Messages.unsubscribe(channel);
|
||||||
|
Messages.messageReceived.disconnect(receivingMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return new recordingEntity();
|
return new recordingEntity();
|
||||||
});
|
});
|
|
@ -5,18 +5,15 @@
|
||||||
// Created by Alessandro Signa on 11/12/15.
|
// Created by Alessandro Signa on 11/12/15.
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Run this script to find the recorder (created by crateRecorder.js) and drive the start/end of the recording for anyone who is inside the box
|
// Run this script to spawn a box (recorder) and drive the start/end of the recording for anyone who is inside the box
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
|
|
||||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||||
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/toolBars.js");
|
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/toolBars.js");
|
||||||
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/utils.js");
|
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/utils.js");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var rotation = Quat.safeEulerAngles(Camera.getOrientation());
|
var rotation = Quat.safeEulerAngles(Camera.getOrientation());
|
||||||
rotation = Quat.fromPitchYawRollDegrees(0, rotation.y, 0);
|
rotation = Quat.fromPitchYawRollDegrees(0, rotation.y, 0);
|
||||||
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(rotation)));
|
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(rotation)));
|
||||||
|
@ -28,27 +25,9 @@ var COLOR_TOOL_BAR = { red: 0, green: 0, blue: 0 };
|
||||||
|
|
||||||
var toolBar = null;
|
var toolBar = null;
|
||||||
var recordIcon;
|
var recordIcon;
|
||||||
|
|
||||||
var isRecordingEntityFound = false;
|
|
||||||
|
|
||||||
var isRecording = false;
|
var isRecording = false;
|
||||||
|
var channel = "groupRecordingChannel";
|
||||||
var recordAreaEntity = null;
|
Messages.subscribe(channel);
|
||||||
findRecorder();
|
|
||||||
|
|
||||||
function findRecorder() {
|
|
||||||
foundEntities = Entities.findEntities(MyAvatar.position, 50);
|
|
||||||
for (var i = 0; i < foundEntities.length; i++) {
|
|
||||||
var name = Entities.getEntityProperties(foundEntities[i], "name").name;
|
|
||||||
if (name === "recorderEntity") {
|
|
||||||
recordAreaEntity = foundEntities[i];
|
|
||||||
isRecordingEntityFound = true;
|
|
||||||
print("Found recorder Entity!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setupToolBar();
|
setupToolBar();
|
||||||
|
|
||||||
function setupToolBar() {
|
function setupToolBar() {
|
||||||
|
@ -58,9 +37,7 @@ function setupToolBar() {
|
||||||
}
|
}
|
||||||
Tool.IMAGE_HEIGHT /= 2;
|
Tool.IMAGE_HEIGHT /= 2;
|
||||||
Tool.IMAGE_WIDTH /= 2;
|
Tool.IMAGE_WIDTH /= 2;
|
||||||
|
|
||||||
toolBar = new ToolBar(0, 100, ToolBar.HORIZONTAL); //put the button in the up-left corner
|
toolBar = new ToolBar(0, 100, ToolBar.HORIZONTAL); //put the button in the up-left corner
|
||||||
|
|
||||||
toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
|
toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
|
||||||
|
|
||||||
recordIcon = toolBar.addTool({
|
recordIcon = toolBar.addTool({
|
||||||
|
@ -70,7 +47,7 @@ function setupToolBar() {
|
||||||
width: Tool.IMAGE_WIDTH,
|
width: Tool.IMAGE_WIDTH,
|
||||||
height: Tool.IMAGE_HEIGHT,
|
height: Tool.IMAGE_HEIGHT,
|
||||||
alpha: Recording.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
alpha: Recording.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
||||||
visible: isRecordingEntityFound,
|
visible: true,
|
||||||
}, true, isRecording);
|
}, true, isRecording);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,24 +56,22 @@ function mousePressEvent(event) {
|
||||||
if (recordIcon === toolBar.clicked(clickedOverlay, false)) {
|
if (recordIcon === toolBar.clicked(clickedOverlay, false)) {
|
||||||
if (!isRecording) {
|
if (!isRecording) {
|
||||||
print("I'm the master. I want to start recording");
|
print("I'm the master. I want to start recording");
|
||||||
|
var message = "RECONDING STARTED";
|
||||||
|
Messages.sendMessage(channel, message);
|
||||||
isRecording = true;
|
isRecording = true;
|
||||||
setEntityCustomData("recordingKey", recordAreaEntity, {isRecordingStarted: true});
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print("I want to stop recording");
|
print("I want to stop recording");
|
||||||
|
var message = "RECONDING ENDED";
|
||||||
|
Messages.sendMessage(channel, message);
|
||||||
isRecording = false;
|
isRecording = false;
|
||||||
setEntityCustomData("recordingKey", recordAreaEntity, {isRecordingStarted: false});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
toolBar.cleanup();
|
toolBar.cleanup();
|
||||||
|
Messages.unsubscribe(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(cleanup);
|
||||||
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
Script.scriptEnding.connect(cleanup);
|
|
||||||
Controller.mousePressEvent.connect(mousePressEvent);
|
|
||||||
|
|
40
examples/tests/lodTest.js
Normal file
40
examples/tests/lodTest.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// lodTest.js
|
||||||
|
// examples/tests
|
||||||
|
//
|
||||||
|
// Created by Ryan Huffman on 11/19/15.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
var MIN_DIM = 0.001;
|
||||||
|
var MAX_DIM = 2.0;
|
||||||
|
var NUM_SPHERES = 20;
|
||||||
|
|
||||||
|
// Rough estimate of the width the spheres will span, not taking into account MIN_DIM
|
||||||
|
var WIDTH = MAX_DIM * NUM_SPHERES;
|
||||||
|
|
||||||
|
var entities = [];
|
||||||
|
var right = Quat.getRight(Camera.orientation);
|
||||||
|
// Starting position will be 30 meters in front of the camera
|
||||||
|
var position = Vec3.sum(Camera.position, Vec3.multiply(30, Quat.getFront(Camera.orientation)));
|
||||||
|
position = Vec3.sum(position, Vec3.multiply(-WIDTH/2, right));
|
||||||
|
|
||||||
|
for (var i = 0; i < NUM_SPHERES; ++i) {
|
||||||
|
var dim = (MAX_DIM - MIN_DIM) * ((i + 1) / NUM_SPHERES);
|
||||||
|
entities.push(Entities.addEntity({
|
||||||
|
type: "Sphere",
|
||||||
|
dimensions: { x: dim, y: dim, z: dim },
|
||||||
|
position: position,
|
||||||
|
}));
|
||||||
|
|
||||||
|
position = Vec3.sum(position, Vec3.multiply(dim * 2, right));
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function() {
|
||||||
|
for (var i = 0; i < entities.length; ++i) {
|
||||||
|
Entities.deleteEntity(entities[i]);
|
||||||
|
}
|
||||||
|
})
|
24
examples/tests/playbackAcTest.js
Normal file
24
examples/tests/playbackAcTest.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var origin = {x: 512, y: 512, z: 512};
|
||||||
|
var millisecondsToWaitBeforeStarting = 2 * 1000; // To give the various servers a chance to start.
|
||||||
|
var millisecondsToWaitBeforeEnding = 30 * 1000;
|
||||||
|
|
||||||
|
Avatar.skeletonModelURL = "https://hifi-public.s3.amazonaws.com/marketplace/contents/dd03b8e3-52fb-4ab3-9ac9-3b17e00cd85d/98baa90b3b66803c5d7bd4537fca6993.fst"; //lovejoy
|
||||||
|
Avatar.displayName = "AC Avatar";
|
||||||
|
Agent.isAvatar = true;
|
||||||
|
|
||||||
|
Script.setTimeout(function () {
|
||||||
|
Avatar.position = origin;
|
||||||
|
Recording.loadRecording("d:/hifi.rec");
|
||||||
|
Recording.setPlayerLoop(true);
|
||||||
|
Recording.startPlaying();
|
||||||
|
}, millisecondsToWaitBeforeStarting);
|
||||||
|
|
||||||
|
|
||||||
|
Script.setTimeout(function () {
|
||||||
|
print("Stopping script");
|
||||||
|
Agent.isAvatar = false;
|
||||||
|
Recording.stopPlaying();
|
||||||
|
Script.stop();
|
||||||
|
}, millisecondsToWaitBeforeEnding);
|
|
@ -454,6 +454,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
audioIO->setOrientationGetter([this]{ return getMyAvatar()->getOrientationForAudio(); });
|
audioIO->setOrientationGetter([this]{ return getMyAvatar()->getOrientationForAudio(); });
|
||||||
|
|
||||||
audioIO->moveToThread(audioThread);
|
audioIO->moveToThread(audioThread);
|
||||||
|
recording::Frame::registerFrameHandler(AudioConstants::AUDIO_FRAME_NAME, [=](recording::Frame::ConstPointer frame) {
|
||||||
|
audioIO->handleRecordedAudioInput(frame->data);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(audioIO.data(), &AudioClient::inputReceived, [](const QByteArray& audio){
|
||||||
|
static auto recorder = DependencyManager::get<recording::Recorder>();
|
||||||
|
if (recorder->isRecording()) {
|
||||||
|
static const recording::FrameType AUDIO_FRAME_TYPE = recording::Frame::registerFrameType(AudioConstants::AUDIO_FRAME_NAME);
|
||||||
|
recorder->recordFrame(AUDIO_FRAME_TYPE, audio);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
auto& audioScriptingInterface = AudioScriptingInterface::getInstance();
|
auto& audioScriptingInterface = AudioScriptingInterface::getInstance();
|
||||||
|
|
||||||
|
@ -743,10 +754,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog);
|
connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog);
|
||||||
applicationUpdater->checkForUpdate();
|
applicationUpdater->checkForUpdate();
|
||||||
|
|
||||||
// Assign MyAvatar to th eRecording Singleton
|
|
||||||
DependencyManager::get<RecordingScriptingInterface>()->setControlledAvatar(getMyAvatar());
|
|
||||||
|
|
||||||
|
|
||||||
// Now that menu is initalized we can sync myAvatar with it's state.
|
// Now that menu is initalized we can sync myAvatar with it's state.
|
||||||
getMyAvatar()->updateMotionBehaviorFromMenu();
|
getMyAvatar()->updateMotionBehaviorFromMenu();
|
||||||
|
|
||||||
|
@ -841,8 +848,6 @@ void Application::cleanupBeforeQuit() {
|
||||||
#ifdef HAVE_IVIEWHMD
|
#ifdef HAVE_IVIEWHMD
|
||||||
DependencyManager::get<EyeTracker>()->setEnabled(false, true);
|
DependencyManager::get<EyeTracker>()->setEnabled(false, true);
|
||||||
#endif
|
#endif
|
||||||
DependencyManager::get<RecordingScriptingInterface>()->setControlledAvatar(nullptr);
|
|
||||||
|
|
||||||
AnimDebugDraw::getInstance().shutdown();
|
AnimDebugDraw::getInstance().shutdown();
|
||||||
|
|
||||||
// FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete:
|
// FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete:
|
||||||
|
|
|
@ -39,10 +39,10 @@
|
||||||
#include <recording/Recorder.h>
|
#include <recording/Recorder.h>
|
||||||
#include <recording/Clip.h>
|
#include <recording/Clip.h>
|
||||||
#include <recording/Frame.h>
|
#include <recording/Frame.h>
|
||||||
#include "devices/Faceshift.h"
|
#include <RecordingScriptingInterface.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "devices/Faceshift.h"
|
||||||
#include "AvatarManager.h"
|
#include "AvatarManager.h"
|
||||||
#include "Environment.h"
|
#include "Environment.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
@ -127,6 +127,65 @@ MyAvatar::MyAvatar(RigPointer rig) :
|
||||||
_characterController.setEnabled(true);
|
_characterController.setEnabled(true);
|
||||||
|
|
||||||
_bodySensorMatrix = deriveBodyFromHMDSensor();
|
_bodySensorMatrix = deriveBodyFromHMDSensor();
|
||||||
|
|
||||||
|
using namespace recording;
|
||||||
|
|
||||||
|
auto player = DependencyManager::get<Deck>();
|
||||||
|
auto recorder = DependencyManager::get<Recorder>();
|
||||||
|
connect(player.data(), &Deck::playbackStateChanged, [=] {
|
||||||
|
if (player->isPlaying()) {
|
||||||
|
auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
|
||||||
|
if (recordingInterface->getPlayFromCurrentLocation()) {
|
||||||
|
setRecordingBasis();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearRecordingBasis();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(recorder.data(), &Recorder::recordingStateChanged, [=] {
|
||||||
|
if (recorder->isRecording()) {
|
||||||
|
setRecordingBasis();
|
||||||
|
} else {
|
||||||
|
clearRecordingBasis();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
static const recording::FrameType AVATAR_FRAME_TYPE = recording::Frame::registerFrameType(AvatarData::FRAME_NAME);
|
||||||
|
Frame::registerFrameHandler(AVATAR_FRAME_TYPE, [=](Frame::ConstPointer frame) {
|
||||||
|
static AvatarData dummyAvatar;
|
||||||
|
AvatarData::fromFrame(frame->data, dummyAvatar);
|
||||||
|
if (getRecordingBasis()) {
|
||||||
|
dummyAvatar.setRecordingBasis(getRecordingBasis());
|
||||||
|
} else {
|
||||||
|
dummyAvatar.clearRecordingBasis();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
|
||||||
|
if (recordingInterface->getPlayerUseHeadModel() && dummyAvatar.getFaceModelURL().isValid() &&
|
||||||
|
(dummyAvatar.getFaceModelURL() != getFaceModelURL())) {
|
||||||
|
// FIXME
|
||||||
|
//myAvatar->setFaceModelURL(_dummyAvatar.getFaceModelURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recordingInterface->getPlayerUseSkeletonModel() && dummyAvatar.getSkeletonModelURL().isValid() &&
|
||||||
|
(dummyAvatar.getSkeletonModelURL() != getSkeletonModelURL())) {
|
||||||
|
// FIXME
|
||||||
|
//myAvatar->useFullAvatarURL()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recordingInterface->getPlayerUseDisplayName() && dummyAvatar.getDisplayName() != getDisplayName()) {
|
||||||
|
setDisplayName(dummyAvatar.getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
setPosition(dummyAvatar.getPosition());
|
||||||
|
setOrientation(dummyAvatar.getOrientation());
|
||||||
|
|
||||||
|
// FIXME attachments
|
||||||
|
// FIXME joints
|
||||||
|
// FIXME head lean
|
||||||
|
// FIXME head orientation
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
MyAvatar::~MyAvatar() {
|
MyAvatar::~MyAvatar() {
|
||||||
|
|
|
@ -56,7 +56,7 @@ PreferencesDialog::PreferencesDialog(QWidget* parent) :
|
||||||
|
|
||||||
// move dialog to left side
|
// move dialog to left side
|
||||||
move(parentWidget()->geometry().topLeft());
|
move(parentWidget()->geometry().topLeft());
|
||||||
setFixedHeight(parentWidget()->size().height() - PREFERENCES_HEIGHT_PADDING);
|
resize(sizeHint().width(), parentWidget()->size().height() - PREFERENCES_HEIGHT_PADDING);
|
||||||
|
|
||||||
UIUtil::scaleWidgetFontSizes(this);
|
UIUtil::scaleWidgetFontSizes(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ extern "C" {
|
||||||
#include <SettingHandle.h>
|
#include <SettingHandle.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <UUID.h>
|
#include <UUID.h>
|
||||||
|
#include <Transform.h>
|
||||||
|
|
||||||
#include "AudioInjector.h"
|
#include "AudioInjector.h"
|
||||||
#include "AudioConstants.h"
|
#include "AudioConstants.h"
|
||||||
|
@ -839,93 +840,27 @@ void AudioClient::handleAudioInput() {
|
||||||
_inputRingBuffer.shiftReadPosition(inputSamplesRequired);
|
_inputRingBuffer.shiftReadPosition(inputSamplesRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitAudioPacket(networkAudioSamples);
|
auto packetType = _shouldEchoToServer ?
|
||||||
}
|
PacketType::MicrophoneAudioWithEcho : PacketType::MicrophoneAudioNoEcho;
|
||||||
}
|
|
||||||
|
|
||||||
void AudioClient::emitAudioPacket(const int16_t* audioData, PacketType packetType) {
|
if (_lastInputLoudness == 0) {
|
||||||
static std::mutex _mutex;
|
packetType = PacketType::SilentAudioFrame;
|
||||||
using Locker = std::unique_lock<std::mutex>;
|
|
||||||
|
|
||||||
// FIXME recorded audio isn't guaranteed to have the same stereo state
|
|
||||||
// as the current system
|
|
||||||
const int numNetworkBytes = _isStereoInput
|
|
||||||
? AudioConstants::NETWORK_FRAME_BYTES_STEREO
|
|
||||||
: AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL;
|
|
||||||
const int numNetworkSamples = _isStereoInput
|
|
||||||
? AudioConstants::NETWORK_FRAME_SAMPLES_STEREO
|
|
||||||
: AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL;
|
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
|
||||||
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
|
||||||
|
|
||||||
if (audioMixer && audioMixer->getActiveSocket()) {
|
|
||||||
Locker lock(_mutex);
|
|
||||||
if (!_audioPacket) {
|
|
||||||
// we don't have an audioPacket yet - set that up now
|
|
||||||
_audioPacket = NLPacket::create(PacketType::MicrophoneAudioWithEcho);
|
|
||||||
}
|
}
|
||||||
|
Transform audioTransform;
|
||||||
glm::vec3 headPosition = _positionGetter();
|
audioTransform.setTranslation(_positionGetter());
|
||||||
glm::quat headOrientation = _orientationGetter();
|
audioTransform.setRotation(_orientationGetter());
|
||||||
quint8 isStereo = _isStereoInput ? 1 : 0;
|
// FIXME find a way to properly handle both playback audio and user audio concurrently
|
||||||
|
emitAudioPacket(networkAudioSamples, numNetworkBytes, _outgoingAvatarAudioSequenceNumber, audioTransform, packetType);
|
||||||
if (packetType == PacketType::Unknown) {
|
|
||||||
if (_lastInputLoudness == 0) {
|
|
||||||
_audioPacket->setType(PacketType::SilentAudioFrame);
|
|
||||||
} else {
|
|
||||||
if (_shouldEchoToServer) {
|
|
||||||
_audioPacket->setType(PacketType::MicrophoneAudioWithEcho);
|
|
||||||
} else {
|
|
||||||
_audioPacket->setType(PacketType::MicrophoneAudioNoEcho);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_audioPacket->setType(packetType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset the audio packet so we can start writing
|
|
||||||
_audioPacket->reset();
|
|
||||||
|
|
||||||
// write sequence number
|
|
||||||
_audioPacket->writePrimitive(_outgoingAvatarAudioSequenceNumber);
|
|
||||||
|
|
||||||
if (_audioPacket->getType() == PacketType::SilentAudioFrame) {
|
|
||||||
// pack num silent samples
|
|
||||||
quint16 numSilentSamples = numNetworkSamples;
|
|
||||||
_audioPacket->writePrimitive(numSilentSamples);
|
|
||||||
} else {
|
|
||||||
// set the mono/stereo byte
|
|
||||||
_audioPacket->writePrimitive(isStereo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pack the three float positions
|
|
||||||
_audioPacket->writePrimitive(headPosition);
|
|
||||||
|
|
||||||
// pack the orientation
|
|
||||||
_audioPacket->writePrimitive(headOrientation);
|
|
||||||
|
|
||||||
if (_audioPacket->getType() != PacketType::SilentAudioFrame) {
|
|
||||||
// audio samples have already been packed (written to networkAudioSamples)
|
|
||||||
_audioPacket->setPayloadSize(_audioPacket->getPayloadSize() + numNetworkBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int leadingBytes = sizeof(quint16) + sizeof(glm::vec3) + sizeof(glm::quat) + sizeof(quint8);
|
|
||||||
int16_t* const networkAudioSamples = (int16_t*)(_audioPacket->getPayload() + leadingBytes);
|
|
||||||
memcpy(networkAudioSamples, audioData, numNetworkBytes);
|
|
||||||
|
|
||||||
_stats.sentPacket();
|
_stats.sentPacket();
|
||||||
|
|
||||||
nodeList->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendAudioPacket);
|
|
||||||
|
|
||||||
nodeList->sendUnreliablePacket(*_audioPacket, *audioMixer);
|
|
||||||
|
|
||||||
_outgoingAvatarAudioSequenceNumber++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::handleRecordedAudioInput(const QByteArray& audio) {
|
void AudioClient::handleRecordedAudioInput(const QByteArray& audio) {
|
||||||
emitAudioPacket((int16_t*)audio.data(), PacketType::MicrophoneAudioWithEcho);
|
Transform audioTransform;
|
||||||
|
audioTransform.setTranslation(_positionGetter());
|
||||||
|
audioTransform.setRotation(_orientationGetter());
|
||||||
|
// FIXME check a flag to see if we should echo audio?
|
||||||
|
emitAudioPacket(audio.data(), audio.size(), _outgoingAvatarAudioSequenceNumber, audioTransform, PacketType::MicrophoneAudioWithEcho);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer) {
|
void AudioClient::processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer) {
|
||||||
|
|
|
@ -74,9 +74,10 @@ class QAudioInput;
|
||||||
class QAudioOutput;
|
class QAudioOutput;
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
|
|
||||||
|
|
||||||
typedef struct ty_gverb ty_gverb;
|
typedef struct ty_gverb ty_gverb;
|
||||||
|
|
||||||
|
class Transform;
|
||||||
class NLPacket;
|
class NLPacket;
|
||||||
|
|
||||||
class AudioClient : public AbstractAudioInterface, public Dependency {
|
class AudioClient : public AbstractAudioInterface, public Dependency {
|
||||||
|
@ -212,7 +213,6 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void emitAudioPacket(const int16_t* audioData, PacketType packetType = PacketType::Unknown);
|
|
||||||
void outputFormatChanged();
|
void outputFormatChanged();
|
||||||
|
|
||||||
QByteArray firstInputFrame;
|
QByteArray firstInputFrame;
|
||||||
|
@ -319,8 +319,6 @@ private:
|
||||||
void checkDevices();
|
void checkDevices();
|
||||||
|
|
||||||
bool _hasReceivedFirstPacket = false;
|
bool _hasReceivedFirstPacket = false;
|
||||||
|
|
||||||
std::unique_ptr<NLPacket> _audioPacket;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
61
libraries/audio/src/AbstractAudioInterface.cpp
Normal file
61
libraries/audio/src/AbstractAudioInterface.cpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
//
|
||||||
|
// Created by Bradley Austin Davis on 2015/11/18
|
||||||
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "AbstractAudioInterface.h"
|
||||||
|
|
||||||
|
#include <QtCore/QSharedPointer>
|
||||||
|
|
||||||
|
#include <Node.h>
|
||||||
|
#include <NodeType.h>
|
||||||
|
#include <DependencyManager.h>
|
||||||
|
#include <NodeList.h>
|
||||||
|
#include <NLPacket.h>
|
||||||
|
#include <Transform.h>
|
||||||
|
|
||||||
|
#include "AudioConstants.h"
|
||||||
|
|
||||||
|
void AbstractAudioInterface::emitAudioPacket(const void* audioData, size_t bytes, quint16& sequenceNumber, const Transform& transform, PacketType packetType) {
|
||||||
|
static std::mutex _mutex;
|
||||||
|
using Locker = std::unique_lock<std::mutex>;
|
||||||
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
||||||
|
if (audioMixer && audioMixer->getActiveSocket()) {
|
||||||
|
Locker lock(_mutex);
|
||||||
|
static std::unique_ptr<NLPacket> audioPacket = NLPacket::create(PacketType::Unknown);
|
||||||
|
quint8 isStereo = bytes == AudioConstants::NETWORK_FRAME_BYTES_STEREO ? 1 : 0;
|
||||||
|
audioPacket->setType(packetType);
|
||||||
|
// reset the audio packet so we can start writing
|
||||||
|
audioPacket->reset();
|
||||||
|
// write sequence number
|
||||||
|
audioPacket->writePrimitive(sequenceNumber++);
|
||||||
|
if (audioPacket->getType() == PacketType::SilentAudioFrame) {
|
||||||
|
// pack num silent samples
|
||||||
|
quint16 numSilentSamples = isStereo ?
|
||||||
|
AudioConstants::NETWORK_FRAME_SAMPLES_STEREO :
|
||||||
|
AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL;
|
||||||
|
audioPacket->writePrimitive(numSilentSamples);
|
||||||
|
} else {
|
||||||
|
// set the mono/stereo byte
|
||||||
|
audioPacket->writePrimitive(isStereo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pack the three float positions
|
||||||
|
audioPacket->writePrimitive(transform.getTranslation());
|
||||||
|
// pack the orientation
|
||||||
|
audioPacket->writePrimitive(transform.getRotation());
|
||||||
|
|
||||||
|
if (audioPacket->getType() != PacketType::SilentAudioFrame) {
|
||||||
|
// audio samples have already been packed (written to networkAudioSamples)
|
||||||
|
audioPacket->setPayloadSize(audioPacket->getPayloadSize() + bytes);
|
||||||
|
static const int leadingBytes = sizeof(quint16) + sizeof(glm::vec3) + sizeof(glm::quat) + sizeof(quint8);
|
||||||
|
memcpy(audioPacket->getPayload() + leadingBytes, audioData, bytes);
|
||||||
|
}
|
||||||
|
nodeList->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendAudioPacket);
|
||||||
|
nodeList->sendUnreliablePacket(*audioPacket, *audioMixer);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,16 +15,21 @@
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtMultimedia/qaudiooutput.h>
|
#include <QtMultimedia/qaudiooutput.h>
|
||||||
|
|
||||||
|
#include <udt/PacketHeaders.h>
|
||||||
|
|
||||||
#include "AudioInjectorOptions.h"
|
#include "AudioInjectorOptions.h"
|
||||||
|
|
||||||
class AudioInjector;
|
class AudioInjector;
|
||||||
class AudioInjectorLocalBuffer;
|
class AudioInjectorLocalBuffer;
|
||||||
|
class Transform;
|
||||||
|
|
||||||
class AbstractAudioInterface : public QObject {
|
class AbstractAudioInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AbstractAudioInterface(QObject* parent = 0) : QObject(parent) {};
|
AbstractAudioInterface(QObject* parent = 0) : QObject(parent) {};
|
||||||
|
|
||||||
|
static void emitAudioPacket(const void* audioData, size_t bytes, quint16& sequenceNumber, const Transform& transform, PacketType packetType);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool outputLocalInjector(bool isStereo, AudioInjector* injector) = 0;
|
virtual bool outputLocalInjector(bool isStereo, AudioInjector* injector) = 0;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,9 @@ namespace AudioConstants {
|
||||||
const int SAMPLE_RATE = 24000;
|
const int SAMPLE_RATE = 24000;
|
||||||
|
|
||||||
typedef int16_t AudioSample;
|
typedef int16_t AudioSample;
|
||||||
|
|
||||||
|
static const char* AUDIO_FRAME_NAME = "com.highfidelity.recording.Audio";
|
||||||
|
|
||||||
const int NETWORK_FRAME_BYTES_STEREO = 1024;
|
const int NETWORK_FRAME_BYTES_STEREO = 1024;
|
||||||
const int NETWORK_FRAME_SAMPLES_STEREO = NETWORK_FRAME_BYTES_STEREO / sizeof(AudioSample);
|
const int NETWORK_FRAME_SAMPLES_STEREO = NETWORK_FRAME_BYTES_STEREO / sizeof(AudioSample);
|
||||||
const int NETWORK_FRAME_BYTES_PER_CHANNEL = 512;
|
const int NETWORK_FRAME_BYTES_PER_CHANNEL = 512;
|
||||||
|
|
|
@ -23,7 +23,9 @@ const char* HTTPConnection::StatusCode301 = "301 Moved Permanently";
|
||||||
const char* HTTPConnection::StatusCode302 = "302 Found";
|
const char* HTTPConnection::StatusCode302 = "302 Found";
|
||||||
const char* HTTPConnection::StatusCode400 = "400 Bad Request";
|
const char* HTTPConnection::StatusCode400 = "400 Bad Request";
|
||||||
const char* HTTPConnection::StatusCode401 = "401 Unauthorized";
|
const char* HTTPConnection::StatusCode401 = "401 Unauthorized";
|
||||||
|
const char* HTTPConnection::StatusCode403 = "403 Forbidden";
|
||||||
const char* HTTPConnection::StatusCode404 = "404 Not Found";
|
const char* HTTPConnection::StatusCode404 = "404 Not Found";
|
||||||
|
const char* HTTPConnection::StatusCode500 = "500 Internal server error";
|
||||||
const char* HTTPConnection::DefaultContentType = "text/plain; charset=ISO-8859-1";
|
const char* HTTPConnection::DefaultContentType = "text/plain; charset=ISO-8859-1";
|
||||||
|
|
||||||
HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) :
|
HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) :
|
||||||
|
|
|
@ -47,7 +47,9 @@ public:
|
||||||
static const char* StatusCode302;
|
static const char* StatusCode302;
|
||||||
static const char* StatusCode400;
|
static const char* StatusCode400;
|
||||||
static const char* StatusCode401;
|
static const char* StatusCode401;
|
||||||
|
static const char* StatusCode403;
|
||||||
static const char* StatusCode404;
|
static const char* StatusCode404;
|
||||||
|
static const char* StatusCode500;
|
||||||
static const char* DefaultContentType;
|
static const char* DefaultContentType;
|
||||||
|
|
||||||
/// WebSocket close status codes.
|
/// WebSocket close status codes.
|
||||||
|
|
|
@ -38,12 +38,17 @@ DomainHandler::DomainHandler(QObject* parent) :
|
||||||
_icePeer(this),
|
_icePeer(this),
|
||||||
_isConnected(false),
|
_isConnected(false),
|
||||||
_settingsObject(),
|
_settingsObject(),
|
||||||
_failedSettingsRequests(0)
|
_settingsTimer(this)
|
||||||
{
|
{
|
||||||
_sockAddr.setObjectName("DomainServer");
|
_sockAddr.setObjectName("DomainServer");
|
||||||
|
|
||||||
// if we get a socket that make sure our NetworkPeer ping timer stops
|
// if we get a socket that make sure our NetworkPeer ping timer stops
|
||||||
connect(this, &DomainHandler::completedSocketDiscovery, &_icePeer, &NetworkPeer::stopPingTimer);
|
connect(this, &DomainHandler::completedSocketDiscovery, &_icePeer, &NetworkPeer::stopPingTimer);
|
||||||
|
|
||||||
|
// setup a timeout for failure on settings requests
|
||||||
|
static const int DOMAIN_SETTINGS_TIMEOUT_MS = 5000;
|
||||||
|
_settingsTimer.setInterval(DOMAIN_SETTINGS_TIMEOUT_MS);
|
||||||
|
connect(&_settingsTimer, &QTimer::timeout, this, &DomainHandler::settingsReceiveFail);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainHandler::disconnect() {
|
void DomainHandler::disconnect() {
|
||||||
|
@ -80,13 +85,16 @@ void DomainHandler::sendDisconnectPacket() {
|
||||||
|
|
||||||
void DomainHandler::clearSettings() {
|
void DomainHandler::clearSettings() {
|
||||||
_settingsObject = QJsonObject();
|
_settingsObject = QJsonObject();
|
||||||
_failedSettingsRequests = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainHandler::softReset() {
|
void DomainHandler::softReset() {
|
||||||
qCDebug(networking) << "Resetting current domain connection information.";
|
qCDebug(networking) << "Resetting current domain connection information.";
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
clearSettings();
|
clearSettings();
|
||||||
|
|
||||||
|
// cancel the failure timeout for any pending requests for settings
|
||||||
|
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::AutoConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainHandler::hardReset() {
|
void DomainHandler::hardReset() {
|
||||||
|
@ -250,35 +258,35 @@ void DomainHandler::requestDomainSettings() {
|
||||||
|
|
||||||
NodeType_t owningNodeType = DependencyManager::get<NodeList>()->getOwnerType();
|
NodeType_t owningNodeType = DependencyManager::get<NodeList>()->getOwnerType();
|
||||||
if (owningNodeType == NodeType::Agent) {
|
if (owningNodeType == NodeType::Agent) {
|
||||||
// for now the agent nodes don't need any settings - this allows local assignment-clients
|
// for now the agent nodes don't need any domain settings
|
||||||
// to connect to a domain that is using automatic networking (since we don't have TCP hole punch yet)
|
|
||||||
_settingsObject = QJsonObject();
|
_settingsObject = QJsonObject();
|
||||||
emit settingsReceived(_settingsObject);
|
emit settingsReceived(_settingsObject);
|
||||||
} else {
|
} else {
|
||||||
if (_settingsObject.isEmpty()) {
|
qCDebug(networking) << "Requesting settings from domain server";
|
||||||
qCDebug(networking) << "Requesting settings from domain server";
|
|
||||||
|
Assignment::Type assignmentType = Assignment::typeForNodeType(DependencyManager::get<NodeList>()->getOwnerType());
|
||||||
Assignment::Type assignmentType = Assignment::typeForNodeType(DependencyManager::get<NodeList>()->getOwnerType());
|
|
||||||
|
auto packet = NLPacket::create(PacketType::DomainSettingsRequest, sizeof(assignmentType), true, false);
|
||||||
auto packet = NLPacket::create(PacketType::DomainSettingsRequest, sizeof(assignmentType), true, false);
|
packet->writePrimitive(assignmentType);
|
||||||
packet->writePrimitive(assignmentType);
|
|
||||||
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
nodeList->sendPacket(std::move(packet), _sockAddr);
|
||||||
nodeList->sendPacket(std::move(packet), _sockAddr);
|
|
||||||
}
|
_settingsTimer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainHandler::processSettingsPacketList(QSharedPointer<ReceivedMessage> packetList) {
|
void DomainHandler::processSettingsPacketList(QSharedPointer<ReceivedMessage> packetList) {
|
||||||
qCDebug(networking) << "Got settings!! " << packetList->getMessage().size();
|
// stop our settings timer since we successfully requested the settings we need
|
||||||
|
_settingsTimer.stop();
|
||||||
|
|
||||||
auto data = packetList->getMessage();
|
auto data = packetList->getMessage();
|
||||||
|
|
||||||
qCDebug(networking) << "Received domain settings: \n" << QString(data);
|
|
||||||
|
|
||||||
_settingsObject = QJsonDocument::fromJson(data).object();
|
_settingsObject = QJsonDocument::fromJson(data).object();
|
||||||
|
|
||||||
// reset failed settings requests to 0, we got them
|
if (!_settingsObject.isEmpty()) {
|
||||||
_failedSettingsRequests = 0;
|
qCDebug(networking) << "Received domain settings: \n" << _settingsObject;
|
||||||
|
}
|
||||||
|
|
||||||
emit settingsReceived(_settingsObject);
|
emit settingsReceived(_settingsObject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,8 +128,8 @@ private:
|
||||||
NetworkPeer _icePeer;
|
NetworkPeer _icePeer;
|
||||||
bool _isConnected;
|
bool _isConnected;
|
||||||
QJsonObject _settingsObject;
|
QJsonObject _settingsObject;
|
||||||
int _failedSettingsRequests;
|
|
||||||
QString _pendingPath;
|
QString _pendingPath;
|
||||||
|
QTimer _settingsTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_DomainHandler_h
|
#endif // hifi_DomainHandler_h
|
||||||
|
|
|
@ -77,6 +77,9 @@ void ThreadedAssignment::commonInit(const QString& targetName, NodeType_t nodeTy
|
||||||
connect(_domainServerTimer, SIGNAL(timeout()), this, SLOT(checkInWithDomainServerOrExit()));
|
connect(_domainServerTimer, SIGNAL(timeout()), this, SLOT(checkInWithDomainServerOrExit()));
|
||||||
_domainServerTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);
|
_domainServerTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);
|
||||||
|
|
||||||
|
// send a domain-server check in immediately
|
||||||
|
checkInWithDomainServerOrExit();
|
||||||
|
|
||||||
// move the domain server time to the NL so check-ins fire from there
|
// move the domain server time to the NL so check-ins fire from there
|
||||||
_domainServerTimer->moveToThread(nodeList->thread());
|
_domainServerTimer->moveToThread(nodeList->thread());
|
||||||
|
|
||||||
|
@ -130,3 +133,8 @@ void ThreadedAssignment::checkInWithDomainServerOrExit() {
|
||||||
DependencyManager::get<NodeList>()->sendDomainServerCheckIn();
|
DependencyManager::get<NodeList>()->sendDomainServerCheckIn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThreadedAssignment::domainSettingsRequestFailed() {
|
||||||
|
qDebug() << "Failed to retreive settings object from domain-server. Bailing on assignment.";
|
||||||
|
setFinished(true);
|
||||||
|
}
|
||||||
|
|
|
@ -42,7 +42,10 @@ protected:
|
||||||
bool _isFinished;
|
bool _isFinished;
|
||||||
QTimer* _domainServerTimer = nullptr;
|
QTimer* _domainServerTimer = nullptr;
|
||||||
QTimer* _statsTimer = nullptr;
|
QTimer* _statsTimer = nullptr;
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void domainSettingsRequestFailed();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void startSendingStats();
|
void startSendingStats();
|
||||||
void stopSendingStats();
|
void stopSendingStats();
|
||||||
|
|
|
@ -395,7 +395,7 @@ bool SendQueue::isInactive(bool sentAPacket) {
|
||||||
|
|
||||||
#ifdef UDT_CONNECTION_DEBUG
|
#ifdef UDT_CONNECTION_DEBUG
|
||||||
qCDebug(networking) << "SendQueue to" << _destination << "reached" << NUM_TIMEOUTS_BEFORE_INACTIVE << "timeouts"
|
qCDebug(networking) << "SendQueue to" << _destination << "reached" << NUM_TIMEOUTS_BEFORE_INACTIVE << "timeouts"
|
||||||
<< "and 5s before receiving any ACK/NAK and is now inactive. Stopping.";
|
<< "and 5s before receiving any ACK/NAK and is now inactive. Stopping.";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
deactivate();
|
deactivate();
|
||||||
|
@ -427,9 +427,9 @@ bool SendQueue::isInactive(bool sentAPacket) {
|
||||||
if (cvStatus == std::cv_status::timeout) {
|
if (cvStatus == std::cv_status::timeout) {
|
||||||
#ifdef UDT_CONNECTION_DEBUG
|
#ifdef UDT_CONNECTION_DEBUG
|
||||||
qCDebug(networking) << "SendQueue to" << _destination << "has been empty for"
|
qCDebug(networking) << "SendQueue to" << _destination << "has been empty for"
|
||||||
<< EMPTY_QUEUES_INACTIVE_TIMEOUT.count()
|
<< EMPTY_QUEUES_INACTIVE_TIMEOUT.count()
|
||||||
<< "seconds and receiver has ACKed all packets."
|
<< "seconds and receiver has ACKed all packets."
|
||||||
<< "The queue is now inactive and will be stopped.";
|
<< "The queue is now inactive and will be stopped.";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Deactivate queue
|
// Deactivate queue
|
||||||
|
|
|
@ -24,7 +24,7 @@ const int HALF_TREE_SCALE = TREE_SCALE / 2;
|
||||||
const float DEFAULT_OCTREE_SIZE_SCALE = TREE_SCALE * 400.0f;
|
const float DEFAULT_OCTREE_SIZE_SCALE = TREE_SCALE * 400.0f;
|
||||||
|
|
||||||
// This is used in the LOD Tools to translate between the size scale slider and the values used to set the OctreeSizeScale
|
// This is used in the LOD Tools to translate between the size scale slider and the values used to set the OctreeSizeScale
|
||||||
const float MAX_LOD_SIZE_MULTIPLIER = 800.0f;
|
const float MAX_LOD_SIZE_MULTIPLIER = 4000.0f;
|
||||||
|
|
||||||
const int NUMBER_OF_CHILDREN = 8;
|
const int NUMBER_OF_CHILDREN = 8;
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,15 @@ OctreePersistThread::OctreePersistThread(OctreePointer tree, const QString& file
|
||||||
_filename = sansExt + "." + _persistAsFileType;
|
_filename = sansExt + "." + _persistAsFileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString OctreePersistThread::getPersistFileMimeType() const {
|
||||||
|
if (_persistAsFileType == "json") {
|
||||||
|
return "application/json";
|
||||||
|
} if (_persistAsFileType == "json.gz") {
|
||||||
|
return "application/zip";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
void OctreePersistThread::parseSettings(const QJsonObject& settings) {
|
void OctreePersistThread::parseSettings(const QJsonObject& settings) {
|
||||||
if (settings["backups"].isArray()) {
|
if (settings["backups"].isArray()) {
|
||||||
const QJsonArray& backupRules = settings["backups"].toArray();
|
const QJsonArray& backupRules = settings["backups"].toArray();
|
||||||
|
@ -229,6 +238,15 @@ void OctreePersistThread::aboutToFinish() {
|
||||||
_stopThread = true;
|
_stopThread = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray OctreePersistThread::getPersistFileContents() const {
|
||||||
|
QByteArray fileContents;
|
||||||
|
QFile file(_filename);
|
||||||
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
|
fileContents = file.readAll();
|
||||||
|
}
|
||||||
|
return fileContents;
|
||||||
|
}
|
||||||
|
|
||||||
void OctreePersistThread::persist() {
|
void OctreePersistThread::persist() {
|
||||||
if (_tree->isDirty()) {
|
if (_tree->isDirty()) {
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,10 @@ public:
|
||||||
|
|
||||||
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
||||||
|
|
||||||
|
QString getPersistFilename() const { return _filename; }
|
||||||
|
QString getPersistFileMimeType() const;
|
||||||
|
QByteArray getPersistFileContents() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadCompleted();
|
void loadCompleted();
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,25 @@ Frame::Handler Frame::registerFrameHandler(FrameType type, Handler handler) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Frame::Handler Frame::registerFrameHandler(const QString& frameTypeName, Handler handler) {
|
||||||
|
auto frameType = registerFrameType(frameTypeName);
|
||||||
|
return registerFrameHandler(frameType, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Frame::clearFrameHandler(FrameType type) {
|
||||||
|
Locker lock(mutex);
|
||||||
|
auto iterator = handlerMap.find(type);
|
||||||
|
if (iterator != handlerMap.end()) {
|
||||||
|
handlerMap.erase(iterator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Frame::clearFrameHandler(const QString& frameTypeName) {
|
||||||
|
auto frameType = registerFrameType(frameTypeName);
|
||||||
|
clearFrameHandler(frameType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Frame::handleFrame(const Frame::ConstPointer& frame) {
|
void Frame::handleFrame(const Frame::ConstPointer& frame) {
|
||||||
Handler handler;
|
Handler handler;
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,9 +55,12 @@ public:
|
||||||
: FrameHeader(type, timeOffset), data(data) { }
|
: FrameHeader(type, timeOffset), data(data) { }
|
||||||
|
|
||||||
static FrameType registerFrameType(const QString& frameTypeName);
|
static FrameType registerFrameType(const QString& frameTypeName);
|
||||||
|
static Handler registerFrameHandler(FrameType type, Handler handler);
|
||||||
|
static Handler registerFrameHandler(const QString& frameTypeName, Handler handler);
|
||||||
|
static void clearFrameHandler(FrameType type);
|
||||||
|
static void clearFrameHandler(const QString& frameTypeName);
|
||||||
static QMap<QString, FrameType> getFrameTypes();
|
static QMap<QString, FrameType> getFrameTypes();
|
||||||
static QMap<FrameType, QString> getFrameTypeNames();
|
static QMap<FrameType, QString> getFrameTypeNames();
|
||||||
static Handler registerFrameHandler(FrameType type, Handler handler);
|
|
||||||
static void handleFrame(const ConstPointer& frame);
|
static void handleFrame(const ConstPointer& frame);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -72,16 +72,17 @@ FileFrameHeaderList parseFrameHeaders(uchar* const start, const qint64& size) {
|
||||||
results.push_back(header);
|
results.push_back(header);
|
||||||
}
|
}
|
||||||
qDebug() << "Parsed source data into " << results.size() << " frames";
|
qDebug() << "Parsed source data into " << results.size() << " frames";
|
||||||
int i = 0;
|
// int i = 0;
|
||||||
for (const auto& frameHeader : results) {
|
// for (const auto& frameHeader : results) {
|
||||||
qDebug() << "Frame " << i++ << " time " << frameHeader.timeOffset;
|
// qDebug() << "Frame " << i++ << " time " << frameHeader.timeOffset << " Type " << frameHeader.type;
|
||||||
}
|
// }
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileClip::FileClip(const QString& fileName) : _file(fileName) {
|
FileClip::FileClip(const QString& fileName) : _file(fileName) {
|
||||||
auto size = _file.size();
|
auto size = _file.size();
|
||||||
|
qDebug() << "Opening file of size: " << size;
|
||||||
bool opened = _file.open(QIODevice::ReadOnly);
|
bool opened = _file.open(QIODevice::ReadOnly);
|
||||||
if (!opened) {
|
if (!opened) {
|
||||||
qCWarning(recordingLog) << "Unable to open file " << fileName;
|
qCWarning(recordingLog) << "Unable to open file " << fileName;
|
||||||
|
|
|
@ -15,43 +15,16 @@
|
||||||
#include <recording/Clip.h>
|
#include <recording/Clip.h>
|
||||||
#include <recording/Frame.h>
|
#include <recording/Frame.h>
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
// FiXME
|
|
||||||
//#include <AudioClient.h>
|
|
||||||
#include <AudioConstants.h>
|
|
||||||
#include <Transform.h>
|
#include <Transform.h>
|
||||||
|
|
||||||
#include "ScriptEngineLogging.h"
|
#include "ScriptEngineLogging.h"
|
||||||
|
|
||||||
typedef int16_t AudioSample;
|
|
||||||
|
|
||||||
|
|
||||||
using namespace recording;
|
using namespace recording;
|
||||||
|
|
||||||
// FIXME move to somewhere audio related?
|
|
||||||
static const QString AUDIO_FRAME_NAME = "com.highfidelity.recording.Audio";
|
|
||||||
|
|
||||||
RecordingScriptingInterface::RecordingScriptingInterface() {
|
RecordingScriptingInterface::RecordingScriptingInterface() {
|
||||||
static const recording::FrameType AVATAR_FRAME_TYPE = recording::Frame::registerFrameType(AvatarData::FRAME_NAME);
|
|
||||||
// FIXME how to deal with driving multiple avatars locally?
|
|
||||||
Frame::registerFrameHandler(AVATAR_FRAME_TYPE, [this](Frame::ConstPointer frame) {
|
|
||||||
processAvatarFrame(frame);
|
|
||||||
});
|
|
||||||
|
|
||||||
static const recording::FrameType AUDIO_FRAME_TYPE = recording::Frame::registerFrameType(AUDIO_FRAME_NAME);
|
|
||||||
Frame::registerFrameHandler(AUDIO_FRAME_TYPE, [this](Frame::ConstPointer frame) {
|
|
||||||
processAudioFrame(frame);
|
|
||||||
});
|
|
||||||
|
|
||||||
_player = DependencyManager::get<Deck>();
|
_player = DependencyManager::get<Deck>();
|
||||||
_recorder = DependencyManager::get<Recorder>();
|
_recorder = DependencyManager::get<Recorder>();
|
||||||
|
|
||||||
// FIXME : Disabling Sound
|
|
||||||
// auto audioClient = DependencyManager::get<AudioClient>();
|
|
||||||
// connect(audioClient.data(), &AudioClient::inputReceived, this, &RecordingScriptingInterface::processAudioInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RecordingScriptingInterface::setControlledAvatar(AvatarData* avatar) {
|
|
||||||
_controlledAvatar = avatar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecordingScriptingInterface::isPlaying() const {
|
bool RecordingScriptingInterface::isPlaying() const {
|
||||||
|
@ -92,12 +65,6 @@ void RecordingScriptingInterface::startPlaying() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Playback from the current position
|
|
||||||
if (_playFromCurrentLocation && _controlledAvatar) {
|
|
||||||
_dummyAvatar.setRecordingBasis(std::make_shared<Transform>(_controlledAvatar->getTransform()));
|
|
||||||
} else {
|
|
||||||
_dummyAvatar.clearRecordingBasis();
|
|
||||||
}
|
|
||||||
_player->play();
|
_player->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,12 +143,6 @@ void RecordingScriptingInterface::startRecording() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_recordingEpoch = Frame::epochForFrameTime(0);
|
|
||||||
|
|
||||||
if (_controlledAvatar) {
|
|
||||||
_controlledAvatar->setRecordingBasis();
|
|
||||||
}
|
|
||||||
|
|
||||||
_recorder->start();
|
_recorder->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,10 +150,6 @@ void RecordingScriptingInterface::stopRecording() {
|
||||||
_recorder->stop();
|
_recorder->stop();
|
||||||
_lastClip = _recorder->getClip();
|
_lastClip = _recorder->getClip();
|
||||||
_lastClip->seek(0);
|
_lastClip->seek(0);
|
||||||
|
|
||||||
if (_controlledAvatar) {
|
|
||||||
_controlledAvatar->clearRecordingBasis();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordingScriptingInterface::saveRecording(const QString& filename) {
|
void RecordingScriptingInterface::saveRecording(const QString& filename) {
|
||||||
|
@ -225,50 +182,3 @@ void RecordingScriptingInterface::loadLastRecording() {
|
||||||
_player->play();
|
_player->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordingScriptingInterface::processAvatarFrame(const Frame::ConstPointer& frame) {
|
|
||||||
Q_ASSERT(QThread::currentThread() == thread());
|
|
||||||
|
|
||||||
if (!_controlledAvatar) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AvatarData::fromFrame(frame->data, _dummyAvatar);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (_useHeadModel && _dummyAvatar.getFaceModelURL().isValid() &&
|
|
||||||
(_dummyAvatar.getFaceModelURL() != _controlledAvatar->getFaceModelURL())) {
|
|
||||||
// FIXME
|
|
||||||
//myAvatar->setFaceModelURL(_dummyAvatar.getFaceModelURL());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_useSkeletonModel && _dummyAvatar.getSkeletonModelURL().isValid() &&
|
|
||||||
(_dummyAvatar.getSkeletonModelURL() != _controlledAvatar->getSkeletonModelURL())) {
|
|
||||||
// FIXME
|
|
||||||
//myAvatar->useFullAvatarURL()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_useDisplayName && _dummyAvatar.getDisplayName() != _controlledAvatar->getDisplayName()) {
|
|
||||||
_controlledAvatar->setDisplayName(_dummyAvatar.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
_controlledAvatar->setPosition(_dummyAvatar.getPosition());
|
|
||||||
_controlledAvatar->setOrientation(_dummyAvatar.getOrientation());
|
|
||||||
|
|
||||||
// FIXME attachments
|
|
||||||
// FIXME joints
|
|
||||||
// FIXME head lean
|
|
||||||
// FIXME head orientation
|
|
||||||
}
|
|
||||||
|
|
||||||
void RecordingScriptingInterface::processAudioInput(const QByteArray& audio) {
|
|
||||||
if (_recorder->isRecording()) {
|
|
||||||
static const recording::FrameType AUDIO_FRAME_TYPE = recording::Frame::registerFrameType(AUDIO_FRAME_NAME);
|
|
||||||
_recorder->recordFrame(AUDIO_FRAME_TYPE, audio);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RecordingScriptingInterface::processAudioFrame(const recording::FrameConstPointer& frame) {
|
|
||||||
// auto audioClient = DependencyManager::get<AudioClient>();
|
|
||||||
// audioClient->handleRecordedAudioInput(frame->data);
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
#define hifi_RecordingScriptingInterface_h
|
#define hifi_RecordingScriptingInterface_h
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
#include <recording/Forward.h>
|
#include <recording/Forward.h>
|
||||||
#include <recording/Frame.h>
|
#include <recording/Frame.h>
|
||||||
#include <AvatarData.h>
|
|
||||||
|
|
||||||
class RecordingScriptingInterface : public QObject, public Dependency {
|
class RecordingScriptingInterface : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -24,8 +24,6 @@ class RecordingScriptingInterface : public QObject, public Dependency {
|
||||||
public:
|
public:
|
||||||
RecordingScriptingInterface();
|
RecordingScriptingInterface();
|
||||||
|
|
||||||
void setControlledAvatar(AvatarData* avatar);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadRecording(const QString& filename);
|
void loadRecording(const QString& filename);
|
||||||
|
|
||||||
|
@ -41,12 +39,19 @@ public slots:
|
||||||
void setPlayerVolume(float volume);
|
void setPlayerVolume(float volume);
|
||||||
void setPlayerAudioOffset(float audioOffset);
|
void setPlayerAudioOffset(float audioOffset);
|
||||||
void setPlayerTime(float time);
|
void setPlayerTime(float time);
|
||||||
void setPlayFromCurrentLocation(bool playFromCurrentLocation);
|
|
||||||
void setPlayerLoop(bool loop);
|
void setPlayerLoop(bool loop);
|
||||||
|
|
||||||
void setPlayerUseDisplayName(bool useDisplayName);
|
void setPlayerUseDisplayName(bool useDisplayName);
|
||||||
void setPlayerUseAttachments(bool useAttachments);
|
void setPlayerUseAttachments(bool useAttachments);
|
||||||
void setPlayerUseHeadModel(bool useHeadModel);
|
void setPlayerUseHeadModel(bool useHeadModel);
|
||||||
void setPlayerUseSkeletonModel(bool useSkeletonModel);
|
void setPlayerUseSkeletonModel(bool useSkeletonModel);
|
||||||
|
void setPlayFromCurrentLocation(bool playFromCurrentLocation);
|
||||||
|
|
||||||
|
bool getPlayerUseDisplayName() { return _useDisplayName; }
|
||||||
|
bool getPlayerUseAttachments() { return _useAttachments; }
|
||||||
|
bool getPlayerUseHeadModel() { return _useHeadModel; }
|
||||||
|
bool getPlayerUseSkeletonModel() { return _useSkeletonModel; }
|
||||||
|
bool getPlayFromCurrentLocation() { return _playFromCurrentLocation; }
|
||||||
|
|
||||||
void startRecording();
|
void startRecording();
|
||||||
void stopRecording();
|
void stopRecording();
|
||||||
|
@ -57,22 +62,13 @@ public slots:
|
||||||
void saveRecording(const QString& filename);
|
void saveRecording(const QString& filename);
|
||||||
void loadLastRecording();
|
void loadLastRecording();
|
||||||
|
|
||||||
signals:
|
protected:
|
||||||
void playbackStateChanged();
|
|
||||||
// Should this occur for any frame or just for seek calls?
|
|
||||||
void playbackPositionChanged();
|
|
||||||
void looped();
|
|
||||||
|
|
||||||
private:
|
|
||||||
using Mutex = std::recursive_mutex;
|
using Mutex = std::recursive_mutex;
|
||||||
using Locker = std::unique_lock<Mutex>;
|
using Locker = std::unique_lock<Mutex>;
|
||||||
using Flag = std::atomic<bool>;
|
using Flag = std::atomic<bool>;
|
||||||
void processAvatarFrame(const recording::FrameConstPointer& frame);
|
|
||||||
void processAudioFrame(const recording::FrameConstPointer& frame);
|
|
||||||
void processAudioInput(const QByteArray& audioData);
|
|
||||||
QSharedPointer<recording::Deck> _player;
|
QSharedPointer<recording::Deck> _player;
|
||||||
QSharedPointer<recording::Recorder> _recorder;
|
QSharedPointer<recording::Recorder> _recorder;
|
||||||
quint64 _recordingEpoch { 0 };
|
|
||||||
|
|
||||||
Flag _playFromCurrentLocation { true };
|
Flag _playFromCurrentLocation { true };
|
||||||
Flag _useDisplayName { false };
|
Flag _useDisplayName { false };
|
||||||
|
@ -80,8 +76,6 @@ private:
|
||||||
Flag _useAttachments { false };
|
Flag _useAttachments { false };
|
||||||
Flag _useSkeletonModel { false };
|
Flag _useSkeletonModel { false };
|
||||||
recording::ClipPointer _lastClip;
|
recording::ClipPointer _lastClip;
|
||||||
AvatarData _dummyAvatar;
|
|
||||||
AvatarData* _controlledAvatar;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_RecordingScriptingInterface_h
|
#endif // hifi_RecordingScriptingInterface_h
|
||||||
|
|
|
@ -117,7 +117,7 @@ Transform Transform::fromJson(const QJsonValue& json) {
|
||||||
result.setTranslation(vec3FromJsonValue(obj[JSON_TRANSLATION]));
|
result.setTranslation(vec3FromJsonValue(obj[JSON_TRANSLATION]));
|
||||||
}
|
}
|
||||||
if (obj.contains(JSON_SCALE)) {
|
if (obj.contains(JSON_SCALE)) {
|
||||||
result.setScale(vec3FromJsonValue(obj[JSON_TRANSLATION]));
|
result.setScale(vec3FromJsonValue(obj[JSON_SCALE]));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue