mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 05:50:19 +02:00
Merge branch 'master' of https://github.com/worklist/hifi
This commit is contained in:
commit
1003393101
30 changed files with 260 additions and 264 deletions
|
@ -675,27 +675,6 @@ void* animateVoxels(void* args) {
|
|||
::voxelEditPacketSender->process();
|
||||
}
|
||||
processesPerAnimate++;
|
||||
|
||||
if (::shouldShowPacketsPerSecond) {
|
||||
float lifetimeSeconds = ::voxelEditPacketSender->getLifetimeInSeconds();
|
||||
int targetPPS = ::voxelEditPacketSender->getPacketsPerSecond();
|
||||
float lifetimePPS = ::voxelEditPacketSender->getLifetimePPS();
|
||||
float lifetimeBPS = ::voxelEditPacketSender->getLifetimeBPS();
|
||||
uint64_t totalPacketsSent = ::voxelEditPacketSender->getLifetimePacketsSent();
|
||||
uint64_t totalBytesSent = ::voxelEditPacketSender->getLifetimeBytesSent();
|
||||
|
||||
float lifetimePPSQueued = ::voxelEditPacketSender->getLifetimePPSQueued();
|
||||
float lifetimeBPSQueued = ::voxelEditPacketSender->getLifetimeBPSQueued();
|
||||
uint64_t totalPacketsQueued = ::voxelEditPacketSender->getLifetimePacketsQueued();
|
||||
uint64_t totalBytesQueued = ::voxelEditPacketSender->getLifetimeBytesQueued();
|
||||
|
||||
uint64_t packetsPending = ::voxelEditPacketSender->packetsToSendCount();
|
||||
|
||||
printf("lifetime=%f secs packetsSent=%lld, bytesSent=%lld targetPPS=%d pps=%f bps=%f\n",
|
||||
lifetimeSeconds, totalPacketsSent, totalBytesSent, targetPPS, lifetimePPS, lifetimeBPS);
|
||||
printf("packetsPending=%lld packetsQueued=%lld, bytesQueued=%lld ppsQueued=%f bpsQueued=%f\n",
|
||||
packetsPending, totalPacketsQueued, totalBytesQueued, lifetimePPSQueued, lifetimeBPSQueued);
|
||||
}
|
||||
}
|
||||
// dynamically sleep until we need to fire off the next set of voxels
|
||||
uint64_t usecToSleep = PROCESSING_INTERVAL_USECS - (usecTimestampNow() - lastProcessTime);
|
||||
|
|
|
@ -94,7 +94,8 @@ void AudioMixerClientData::pushBuffersAfterFrameSend() {
|
|||
audioBuffer->shiftReadPosition(NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||
|
||||
audioBuffer->setWillBeAddedToMix(false);
|
||||
} else if (audioBuffer->hasStarted() && audioBuffer->isStarved()) {
|
||||
} else if (audioBuffer->getType() == PositionalAudioRingBuffer::Injector
|
||||
&& audioBuffer->hasStarted() && audioBuffer->isStarved()) {
|
||||
// this is an empty audio buffer that has starved, safe to delete
|
||||
delete audioBuffer;
|
||||
_ringBuffers.erase(_ringBuffers.begin() + i);
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
//
|
||||
// collidingParticles.js
|
||||
// hifi
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/31/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
// This is an example script that creates a couple particles, and sends them on a collision course.
|
||||
// One of the particles has a script that when it collides with another particle, it swaps colors with that particle.
|
||||
// The other particle has a script that when it collides with another particle it set's it's script to a suicide script.
|
||||
//
|
||||
//
|
||||
|
||||
var currentIteration = 0;
|
||||
var NUM_ITERATIONS_BEFORE_SEND = 15; // every 1/4th seconds send another
|
||||
|
||||
|
@ -17,11 +30,6 @@ var gravity = {
|
|||
var damping = 0.1;
|
||||
|
||||
var scriptA = " " +
|
||||
//" function update() { " +
|
||||
//" print('update()\\n'); " +
|
||||
//" var color = { red: 255, green: 127 + (Math.random() * 128), blue: 0 };" +
|
||||
//" Particle.setColor(color); " +
|
||||
//" } " +
|
||||
" function collisionWithParticle(other) { " +
|
||||
" print('collisionWithParticle(other.getID()=' + other.getID() + ')...'); " +
|
||||
" print('myID=' + Particle.getID() + '\\n'); " +
|
||||
|
@ -33,40 +41,16 @@ var scriptA = " " +
|
|||
" Particle.setColor(otherColor); " +
|
||||
" other.setColor(myColor); " +
|
||||
" } " +
|
||||
" function collisionWithVoxel(voxel) { " +
|
||||
" print('collisionWithVoxel(voxel)... '); " +
|
||||
" print('myID=' + Particle.getID() + '\\n'); " +
|
||||
" var voxelColor = voxel.getColor();" +
|
||||
" print('voxelColor=' + voxelColor.red + ', ' + voxelColor.green + ', ' + voxelColor.blue + '\\n'); " +
|
||||
" var myColor = Particle.getColor();" +
|
||||
" print('myColor=' + myColor.red + ', ' + myColor.green + ', ' + myColor.blue + '\\n'); " +
|
||||
" Particle.setColor(voxelColor); " +
|
||||
" } " +
|
||||
" Particle.collisionWithParticle.connect(collisionWithParticle); " +
|
||||
" Particle.collisionWithVoxel.connect(collisionWithVoxel); " +
|
||||
" ";
|
||||
|
||||
var scriptB = " " +
|
||||
" function collisionWithParticle(other) { " +
|
||||
" print('collisionWithParticle(other.getID()=' + other.getID() + ')...'); " +
|
||||
" print('myID=' + Particle.getID() + '\\n'); " +
|
||||
" var myPosition = Particle.getPosition();" +
|
||||
" var myRadius = Particle.getRadius();" +
|
||||
" var myColor = Particle.getColor();" +
|
||||
" Voxels.queueDestructiveVoxelAdd(myPosition.x, myPosition.y, myPosition.z, myRadius, myColor.red, myColor.green, myColor.blue); " +
|
||||
" Particle.setScript('Particle.setShouldDie(true);'); " +
|
||||
" } " +
|
||||
" function collisionWithVoxel(voxel) { " +
|
||||
" print('collisionWithVoxel(voxel)... '); " +
|
||||
" print('myID=' + Particle.getID() + '\\n'); " +
|
||||
" var voxelColor = voxel.getColor();" +
|
||||
" print('voxelColor=' + voxelColor.red + ', ' + voxelColor.green + ', ' + voxelColor.blue + '\\n'); " +
|
||||
" var myColor = Particle.getColor();" +
|
||||
" print('myColor=' + myColor.red + ', ' + myColor.green + ', ' + myColor.blue + '\\n'); " +
|
||||
" Particle.setColor(voxelColor); " +
|
||||
" } " +
|
||||
" Particle.collisionWithParticle.connect(collisionWithParticle); " +
|
||||
" Particle.collisionWithVoxel.connect(collisionWithVoxel); " +
|
||||
" ";
|
||||
|
||||
var color = {
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
//
|
||||
// gun.js
|
||||
// hifi
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/31/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
// This is an example script that turns the hydra controllers into a particle gun.
|
||||
// It reads the controller, watches for trigger pulls, and launches particles.
|
||||
// The particles it creates have a script that when they collide with Voxels, the
|
||||
// particle will change it's color to match the voxel it hits, and then delete the
|
||||
// voxel.
|
||||
//
|
||||
//
|
||||
|
||||
// initialize our triggers
|
||||
var triggerPulled = new Array();
|
||||
var numberOfTriggers = Controller.getNumberOfTriggers();
|
||||
|
@ -9,9 +24,6 @@ function checkController() {
|
|||
var numberOfTriggers = Controller.getNumberOfTriggers();
|
||||
var numberOfSpatialControls = Controller.getNumberOfSpatialControls();
|
||||
var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers;
|
||||
//print("numberOfTriggers:" + numberOfTriggers + "\n");
|
||||
//print("numberOfSpatialControls:" + numberOfSpatialControls + "\n");
|
||||
//print("controllersPerTrigger:" + controllersPerTrigger + "\n");
|
||||
|
||||
// this is expected for hydras
|
||||
if (numberOfTriggers == 2 && controllersPerTrigger == 2) {
|
||||
|
@ -71,6 +83,8 @@ function checkController() {
|
|||
var color = { red: 128, green: 128, blue: 128 };
|
||||
var damping = 0; // no damping
|
||||
var inHand = false;
|
||||
|
||||
// This is the script for the particles that this gun shoots.
|
||||
var script =
|
||||
" function collisionWithVoxel(voxel) { " +
|
||||
" print('collisionWithVoxel(voxel)... '); " +
|
||||
|
|
|
@ -33,7 +33,7 @@ bool VoxelHideShowThread::process() {
|
|||
|
||||
bool showExtraDebugging = Application::getInstance()->getLogger()->extraDebugging();
|
||||
if (showExtraDebugging && elapsed > USECS_PER_FRAME) {
|
||||
printf("VoxelHideShowThread::process()... checkForCulling took %llu\n", elapsed);
|
||||
qDebug() << "VoxelHideShowThread::process()... checkForCulling took " << elapsed << "\n";
|
||||
}
|
||||
|
||||
if (isStillRunning()) {
|
||||
|
|
|
@ -127,11 +127,10 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
// use the threadSound static method to inject the catch sound
|
||||
// pass an AudioInjectorOptions struct to set position and disable loopback
|
||||
AudioInjectorOptions injectorOptions;
|
||||
injectorOptions.position = targetPosition;
|
||||
injectorOptions.shouldLoopback = false;
|
||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
||||
|
||||
AudioInjector::threadSound(&_catchSound, injectorOptions);
|
||||
injectorOptions.setPosition(newPosition);
|
||||
injectorOptions.setLoopbackAudioInterface(app->getAudio());
|
||||
|
||||
AudioScriptingInterface::playSound(&_catchSound, &injectorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,11 +215,10 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
// use the threadSound static method to inject the throw sound
|
||||
// pass an AudioInjectorOptions struct to set position and disable loopback
|
||||
AudioInjectorOptions injectorOptions;
|
||||
injectorOptions.position = targetPosition;
|
||||
injectorOptions.shouldLoopback = false;
|
||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
||||
injectorOptions.setPosition(ballPosition);
|
||||
injectorOptions.setLoopbackAudioInterface(app->getAudio());
|
||||
|
||||
AudioInjector::threadSound(&_throwSound, injectorOptions);
|
||||
AudioScriptingInterface::playSound(&_throwSound, &injectorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <SharedUtil.h>
|
||||
|
||||
#include <AvatarData.h>
|
||||
#include <AudioInjector.h>
|
||||
#include <AudioScriptingInterface.h>
|
||||
#include <HandData.h>
|
||||
#include <ParticleEditHandle.h>
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ bool Controller::computeStars(unsigned numStars, unsigned seed) {
|
|||
|
||||
this->retile(numStars, _tileResolution);
|
||||
|
||||
qDebug("Total time to generate stars: %llu msec\n", (usecTimestampNow() - usecTimestamp(&startTime)) / 1000);
|
||||
qDebug() << "Total time to generate stars: " << ((usecTimestampNow() - usecTimestamp(&startTime)) / 1000) << " msec\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ void Generator::computeStarPositions(InputVertices& destination, unsigned limit,
|
|||
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
|
||||
}
|
||||
|
||||
qDebug("Took %llu msec to generate stars.\n", (usecTimestampNow() - usecTimestamp(&startTime)) / 1000);
|
||||
qDebug() << "Total time to generate stars: " << ((usecTimestampNow() - usecTimestamp(&startTime)) / 1000) << " msec\n";
|
||||
}
|
||||
|
||||
// computeStarColor
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <NodeList.h>
|
||||
|
@ -18,33 +18,11 @@
|
|||
|
||||
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
||||
|
||||
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
|
||||
_thread(NULL),
|
||||
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
|
||||
_sound(sound),
|
||||
_volume(injectorOptions.volume),
|
||||
_shouldLoopback(injectorOptions.shouldLoopback),
|
||||
_position(injectorOptions.position),
|
||||
_orientation(injectorOptions.orientation),
|
||||
_loopbackAudioInterface(injectorOptions.loopbackAudioInterface)
|
||||
_options(injectorOptions)
|
||||
{
|
||||
_thread = new QThread();
|
||||
|
||||
// we want to live on our own thread
|
||||
moveToThread(_thread);
|
||||
}
|
||||
|
||||
void AudioInjector::threadSound(Sound* sound, AudioInjectorOptions injectorOptions) {
|
||||
AudioInjector* injector = new AudioInjector(sound, injectorOptions);
|
||||
|
||||
// start injecting when the injector thread starts
|
||||
connect(injector->_thread, SIGNAL(started()), injector, SLOT(injectAudio()));
|
||||
|
||||
// connect the right slots and signals so that the AudioInjector is killed once the injection is complete
|
||||
connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater()));
|
||||
connect(injector, SIGNAL(finished()), injector->_thread, SLOT(quit()));
|
||||
connect(injector->_thread, SIGNAL(finished()), injector->_thread, SLOT(deleteLater()));
|
||||
|
||||
injector->_thread->start();
|
||||
}
|
||||
|
||||
const uchar MAX_INJECTOR_VOLUME = 0xFF;
|
||||
|
@ -56,9 +34,9 @@ void AudioInjector::injectAudio() {
|
|||
// make sure we actually have samples downloaded to inject
|
||||
if (soundByteArray.size()) {
|
||||
// give our sample byte array to the local audio interface, if we have it, so it can be handled locally
|
||||
if (_loopbackAudioInterface) {
|
||||
if (_options.getLoopbackAudioInterface()) {
|
||||
// assume that localAudioInterface could be on a separate thread, use Qt::AutoConnection to handle properly
|
||||
QMetaObject::invokeMethod(_loopbackAudioInterface, "handleAudioByteArray",
|
||||
QMetaObject::invokeMethod(_options.getLoopbackAudioInterface(), "handleAudioByteArray",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QByteArray, soundByteArray));
|
||||
|
||||
|
@ -85,16 +63,17 @@ void AudioInjector::injectAudio() {
|
|||
currentPacketPosition += rfcStreamUUID.size();
|
||||
|
||||
// pack the flag for loopback
|
||||
memcpy(currentPacketPosition, &_shouldLoopback, sizeof(_shouldLoopback));
|
||||
currentPacketPosition += sizeof(_shouldLoopback);
|
||||
bool loopbackFlag = (_options.getLoopbackAudioInterface() == NULL);
|
||||
memcpy(currentPacketPosition, &loopbackFlag, sizeof(loopbackFlag));
|
||||
currentPacketPosition += sizeof(loopbackFlag);
|
||||
|
||||
// pack the position for injected audio
|
||||
memcpy(currentPacketPosition, &_position, sizeof(_position));
|
||||
currentPacketPosition += sizeof(_position);
|
||||
memcpy(currentPacketPosition, &_options.getPosition(), sizeof(_options.getPosition()));
|
||||
currentPacketPosition += sizeof(_options.getPosition());
|
||||
|
||||
// pack our orientation for injected audio
|
||||
memcpy(currentPacketPosition, &_orientation, sizeof(_orientation));
|
||||
currentPacketPosition += sizeof(_orientation);
|
||||
memcpy(currentPacketPosition, &_options.getOrientation(), sizeof(_options.getOrientation()));
|
||||
currentPacketPosition += sizeof(_options.getOrientation());
|
||||
|
||||
// pack zero for radius
|
||||
float radius = 0;
|
||||
|
@ -102,7 +81,7 @@ void AudioInjector::injectAudio() {
|
|||
currentPacketPosition += sizeof(radius);
|
||||
|
||||
// pack 255 for attenuation byte
|
||||
uchar volume = MAX_INJECTOR_VOLUME * _volume;
|
||||
uchar volume = MAX_INJECTOR_VOLUME * _options.getVolume();
|
||||
memcpy(currentPacketPosition, &volume, sizeof(volume));
|
||||
currentPacketPosition += sizeof(volume);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__AudioInjector__
|
||||
|
@ -15,39 +15,20 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include "AudioInjectorOptions.h"
|
||||
#include "Sound.h"
|
||||
|
||||
class AbstractAudioInterface;
|
||||
|
||||
struct AudioInjectorOptions {
|
||||
AudioInjectorOptions() : position(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
volume(1.0f),
|
||||
orientation(glm::quat()),
|
||||
shouldLoopback(true),
|
||||
loopbackAudioInterface(NULL) {};
|
||||
|
||||
glm::vec3 position;
|
||||
float volume;
|
||||
const glm::quat orientation;
|
||||
bool shouldLoopback;
|
||||
AbstractAudioInterface* loopbackAudioInterface;
|
||||
};
|
||||
class AudioScriptingInterface;
|
||||
|
||||
class AudioInjector : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void threadSound(Sound* sound, AudioInjectorOptions injectorOptions = AudioInjectorOptions());
|
||||
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||
private:
|
||||
AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions);
|
||||
|
||||
QThread* _thread;
|
||||
Sound* _sound;
|
||||
float _volume;
|
||||
uchar _shouldLoopback;
|
||||
glm::vec3 _position;
|
||||
glm::quat _orientation;
|
||||
AbstractAudioInterface* _loopbackAudioInterface;
|
||||
private slots:
|
||||
AudioInjectorOptions _options;
|
||||
public slots:
|
||||
void injectAudio();
|
||||
signals:
|
||||
void finished();
|
||||
|
|
26
libraries/audio/src/AudioInjectorOptions.cpp
Normal file
26
libraries/audio/src/AudioInjectorOptions.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// AudioInjectorOptions.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "AudioInjectorOptions.h"
|
||||
|
||||
AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
|
||||
QObject(parent),
|
||||
_position(0.0f, 0.0f, 0.0f),
|
||||
_volume(1.0f),
|
||||
_orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
_loopbackAudioInterface(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
|
||||
_position = other._position;
|
||||
_volume = other._volume;
|
||||
_orientation = other._orientation;
|
||||
_loopbackAudioInterface = other._loopbackAudioInterface;
|
||||
}
|
48
libraries/audio/src/AudioInjectorOptions.h
Normal file
48
libraries/audio/src/AudioInjectorOptions.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// AudioInjectorOptions.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__AudioInjectorOptions__
|
||||
#define __hifi__AudioInjectorOptions__
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
#include "AbstractAudioInterface.h"
|
||||
|
||||
class AudioInjectorOptions : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
|
||||
public:
|
||||
AudioInjectorOptions(QObject* parent = 0);
|
||||
AudioInjectorOptions(const AudioInjectorOptions& other);
|
||||
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
void setPosition(const glm::vec3& position) { _position = position; }
|
||||
|
||||
float getVolume() const { return _volume; }
|
||||
void setVolume(float volume) { _volume = volume; }
|
||||
|
||||
const glm::quat& getOrientation() const { return _orientation; }
|
||||
void setOrientation(const glm::quat& orientation) { _orientation = orientation; }
|
||||
|
||||
AbstractAudioInterface* getLoopbackAudioInterface() const { return _loopbackAudioInterface; }
|
||||
void setLoopbackAudioInterface(AbstractAudioInterface* loopbackAudioInterface)
|
||||
{ _loopbackAudioInterface = loopbackAudioInterface; }
|
||||
private:
|
||||
glm::vec3 _position;
|
||||
float _volume;
|
||||
glm::quat _orientation;
|
||||
AbstractAudioInterface* _loopbackAudioInterface;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__AudioInjectorOptions__) */
|
|
@ -107,8 +107,6 @@ qint64 AudioRingBuffer::writeData(const char* data, qint64 maxSize) {
|
|||
_isStarved = true;
|
||||
}
|
||||
|
||||
_hasStarted = true;
|
||||
|
||||
if (_endOfLastWrite + samplesToCopy <= _buffer + _sampleCapacity) {
|
||||
memcpy(_endOfLastWrite, data, samplesToCopy * sizeof(int16_t));
|
||||
} else {
|
||||
|
|
28
libraries/audio/src/AudioScriptingInterface.cpp
Normal file
28
libraries/audio/src/AudioScriptingInterface.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// AudioScriptingInterface.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "AudioScriptingInterface.h"
|
||||
|
||||
void AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
|
||||
|
||||
AudioInjector* injector = new AudioInjector(sound, *injectorOptions);
|
||||
|
||||
QThread* injectorThread = new QThread();
|
||||
|
||||
injector->moveToThread(injectorThread);
|
||||
|
||||
// start injecting when the injector thread starts
|
||||
connect(injectorThread, SIGNAL(started()), injector, SLOT(injectAudio()));
|
||||
|
||||
// connect the right slots and signals so that the AudioInjector is killed once the injection is complete
|
||||
connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater()));
|
||||
connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit()));
|
||||
connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater()));
|
||||
|
||||
injectorThread->start();
|
||||
}
|
23
libraries/audio/src/AudioScriptingInterface.h
Normal file
23
libraries/audio/src/AudioScriptingInterface.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// AudioScriptingInterface.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__AudioScriptingInterface__
|
||||
#define __hifi__AudioScriptingInterface__
|
||||
|
||||
#include "AudioInjector.h"
|
||||
#include "Sound.h"
|
||||
|
||||
const AudioInjectorOptions DEFAULT_INJECTOR_OPTIONS;
|
||||
|
||||
class AudioScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
static void playSound(Sound* sound, const AudioInjectorOptions* injectorOptions = NULL);
|
||||
|
||||
};
|
||||
#endif /* defined(__hifi__AudioScriptingInterface__) */
|
|
@ -48,8 +48,6 @@ int InjectedAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes
|
|||
unsigned int attenuationByte = *(currentBuffer++);
|
||||
_attenuationRatio = attenuationByte / (float) MAX_INJECTOR_VOLUME;
|
||||
|
||||
qDebug() << "Copying" << numBytes - (currentBuffer - sourceBuffer) << "for injected ring buffer\n";
|
||||
|
||||
currentBuffer += writeData((char*) currentBuffer, numBytes - (currentBuffer - sourceBuffer));
|
||||
|
||||
return currentBuffer - sourceBuffer;
|
||||
|
|
|
@ -66,6 +66,10 @@ bool PositionalAudioRingBuffer::shouldBeAddedToMix(int numJitterBufferSamples) {
|
|||
} else {
|
||||
// good buffer, add this to the mix
|
||||
_isStarved = false;
|
||||
|
||||
// since we've read data from ring buffer at least once - we've started
|
||||
_hasStarted = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
|
@ -12,7 +12,9 @@
|
|||
|
||||
#include "Sound.h"
|
||||
|
||||
Sound::Sound(const QUrl& sampleURL) {
|
||||
Sound::Sound(const QUrl& sampleURL, QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
// assume we have a QApplication or QCoreApplication instance and use the
|
||||
// QNetworkAccess manager to grab the raw audio file at the given URL
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__Sound__
|
||||
|
@ -16,7 +16,7 @@ class QNetworkReply;
|
|||
class Sound : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Sound(const QUrl& sampleURL);
|
||||
Sound(const QUrl& sampleURL, QObject* parent = 0);
|
||||
|
||||
const QByteArray& getByteArray() { return _byteArray; }
|
||||
private:
|
||||
|
|
|
@ -68,9 +68,9 @@ void OctreeInboundPacketProcessor::processPacket(const HifiSockAddr& senderSockA
|
|||
uint64_t lockWaitTime = 0;
|
||||
|
||||
if (_myServer->wantsDebugReceiving()) {
|
||||
printf("PROCESSING THREAD: got '%c' packet - %d command from client "
|
||||
"receivedBytes=%ld sequence=%d transitTime=%llu usecs\n",
|
||||
packetType, _receivedPacketCount, packetLength, sequence, transitTime);
|
||||
qDebug() << "PROCESSING THREAD: got '" << packetType << "' packet - " << _receivedPacketCount
|
||||
<< " command from client receivedBytes=" << packetLength
|
||||
<< " sequence=" << sequence << " transitTime=" << transitTime << " usecs\n";
|
||||
}
|
||||
int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt);
|
||||
unsigned char* editData = (unsigned char*)&packetData[atByte];
|
||||
|
|
|
@ -51,12 +51,12 @@ bool OctreePersistThread::process() {
|
|||
qDebug("Nodes after loading scene %lu nodes %lu internal %lu leaves\n", nodeCount, internalNodeCount, leafNodeCount);
|
||||
|
||||
double usecPerGet = (double)OctreeElement::getGetChildAtIndexTime() / (double)OctreeElement::getGetChildAtIndexCalls();
|
||||
qDebug("getChildAtIndexCalls=%llu getChildAtIndexTime=%llu perGet=%lf \n",
|
||||
OctreeElement::getGetChildAtIndexTime(), OctreeElement::getGetChildAtIndexCalls(), usecPerGet);
|
||||
qDebug() << "getChildAtIndexCalls=" << OctreeElement::getGetChildAtIndexCalls()
|
||||
<< " getChildAtIndexTime=" << OctreeElement::getGetChildAtIndexTime() << " perGet=" << usecPerGet << " \n";
|
||||
|
||||
double usecPerSet = (double)OctreeElement::getSetChildAtIndexTime() / (double)OctreeElement::getSetChildAtIndexCalls();
|
||||
qDebug("setChildAtIndexCalls=%llu setChildAtIndexTime=%llu perSet=%lf\n",
|
||||
OctreeElement::getSetChildAtIndexTime(), OctreeElement::getSetChildAtIndexCalls(), usecPerSet);
|
||||
qDebug() << "setChildAtIndexCalls=" << OctreeElement::getSetChildAtIndexCalls()
|
||||
<< " setChildAtIndexTime=" << OctreeElement::getSetChildAtIndexTime() << " perset=" << usecPerSet << " \n";
|
||||
|
||||
_initialLoadComplete = true;
|
||||
_lastCheck = usecTimestampNow(); // we just loaded, no need to save again
|
||||
|
|
|
@ -128,11 +128,9 @@ int OctreeSendThread::handlePacketSend(Node* node, OctreeQueryNode* nodeData, in
|
|||
_totalBytes += nodeData->getPacketLength();
|
||||
_totalPackets++;
|
||||
if (debug) {
|
||||
qDebug("Adding stats to packet at %llu [%llu]: sequence: %d size:%d [%llu] wasted bytes:%d [%llu]\n",
|
||||
now,
|
||||
_totalPackets,
|
||||
sequence, nodeData->getPacketLength(), _totalBytes,
|
||||
thisWastedBytes, _totalWastedBytes);
|
||||
qDebug() << "Adding stats to packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
|
||||
" size: " << nodeData->getPacketLength() << " [" << _totalBytes <<
|
||||
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]\n";
|
||||
}
|
||||
|
||||
// actually send it
|
||||
|
@ -153,11 +151,9 @@ int OctreeSendThread::handlePacketSend(Node* node, OctreeQueryNode* nodeData, in
|
|||
_totalBytes += statsMessageLength;
|
||||
_totalPackets++;
|
||||
if (debug) {
|
||||
qDebug("Sending separate stats packet at %llu [%llu]: size:%d [%llu] wasted bytes:%d [%llu]\n",
|
||||
now,
|
||||
_totalPackets,
|
||||
statsMessageLength, _totalBytes,
|
||||
thisWastedBytes, _totalWastedBytes);
|
||||
qDebug() << "Sending separate stats packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
|
||||
" size: " << statsMessageLength << " [" << _totalBytes <<
|
||||
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]\n";
|
||||
}
|
||||
|
||||
trueBytesSent += statsMessageLength;
|
||||
|
@ -175,11 +171,9 @@ int OctreeSendThread::handlePacketSend(Node* node, OctreeQueryNode* nodeData, in
|
|||
_totalBytes += nodeData->getPacketLength();
|
||||
_totalPackets++;
|
||||
if (debug) {
|
||||
qDebug("Sending packet at %llu [%llu]: sequence: %d size:%d [%llu] wasted bytes:%d [%llu]\n",
|
||||
now,
|
||||
_totalPackets,
|
||||
sequence, nodeData->getPacketLength(), _totalBytes,
|
||||
thisWastedBytes, _totalWastedBytes);
|
||||
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
|
||||
" size: " << nodeData->getPacketLength() << " [" << _totalBytes <<
|
||||
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]\n";
|
||||
}
|
||||
}
|
||||
nodeData->stats.markAsSent();
|
||||
|
@ -197,11 +191,9 @@ int OctreeSendThread::handlePacketSend(Node* node, OctreeQueryNode* nodeData, in
|
|||
_totalBytes += nodeData->getPacketLength();
|
||||
_totalPackets++;
|
||||
if (debug) {
|
||||
qDebug("Sending packet at %llu [%llu]: sequence:%d size:%d [%llu] wasted bytes:%d [%llu]\n",
|
||||
now,
|
||||
_totalPackets,
|
||||
sequence, nodeData->getPacketLength(), _totalBytes,
|
||||
thisWastedBytes, _totalWastedBytes);
|
||||
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
|
||||
" size: " << nodeData->getPacketLength() << " [" << _totalBytes <<
|
||||
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -327,8 +319,13 @@ int OctreeSendThread::packetDistributor(Node* node, OctreeQueryNode* nodeData, b
|
|||
packetsSentThisInterval += handlePacketSend(node, nodeData, trueBytesSent, truePacketsSent);
|
||||
|
||||
if (_myServer->wantsDebugSending()) {
|
||||
qDebug("Scene completed at %llu encodeTime:%lu sleepTime:%lu elapsed:%lu Packets:%llu Bytes:%llu Wasted:%llu\n",
|
||||
usecTimestampNow(), encodeTime, sleepTime, elapsedTime, _totalPackets, _totalBytes, _totalWastedBytes);
|
||||
qDebug() << "Scene completed at " << usecTimestampNow()
|
||||
<< "encodeTime:" << encodeTime
|
||||
<< " sleepTime:" << sleepTime
|
||||
<< " elapsed:" << elapsedTime
|
||||
<< " Packets:" << _totalPackets
|
||||
<< " Bytes:" << _totalBytes
|
||||
<< " Wasted:" << _totalWastedBytes << "\n";
|
||||
}
|
||||
|
||||
// start tracking our stats
|
||||
|
@ -341,8 +338,10 @@ int OctreeSendThread::packetDistributor(Node* node, OctreeQueryNode* nodeData, b
|
|||
}
|
||||
|
||||
if (_myServer->wantsDebugSending()) {
|
||||
qDebug("Scene started at %llu Packets:%llu Bytes:%llu Wasted:%llu\n",
|
||||
usecTimestampNow(),_totalPackets,_totalBytes,_totalWastedBytes);
|
||||
qDebug() << "Scene started at " << usecTimestampNow()
|
||||
<< " Packets:" << _totalPackets
|
||||
<< " Bytes:" << _totalBytes
|
||||
<< " Wasted:" << _totalWastedBytes << "\n";
|
||||
}
|
||||
|
||||
::startSceneSleepTime = _usleepTime;
|
||||
|
|
|
@ -514,7 +514,7 @@ void OctreeServer::processDatagram(const QByteArray& dataByteArray, const HifiSo
|
|||
if (packetType == getMyQueryMessageType()) {
|
||||
bool debug = false;
|
||||
if (debug) {
|
||||
qDebug("Got PACKET_TYPE_VOXEL_QUERY at %llu.\n", usecTimestampNow());
|
||||
qDebug() << "Got PACKET_TYPE_VOXEL_QUERY at " << usecTimestampNow() << "\n";
|
||||
}
|
||||
|
||||
int numBytesPacketHeader = numBytesForPacketHeader((unsigned char*) dataByteArray.data());
|
||||
|
|
|
@ -100,8 +100,10 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, unsigned c
|
|||
uint64_t createdAt = (*((uint64_t*)(buffer + numBytesPacketHeader + sizeof(sequence))));
|
||||
uint64_t queuedAt = usecTimestampNow();
|
||||
uint64_t transitTime = queuedAt - createdAt;
|
||||
printf("OctreeEditPacketSender::queuePacketToNode() queued %c - command to node bytes=%ld sequence=%d transitTimeSoFar=%llu usecs\n",
|
||||
buffer[0], length, sequence, transitTime);
|
||||
qDebug() << "OctreeEditPacketSender::queuePacketToNode() queued " << buffer[0] <<
|
||||
" - command to node bytes=" << length <<
|
||||
" sequence=" << sequence <<
|
||||
" transitTimeSoFar=" << transitTime << " usecs\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -458,9 +458,9 @@ void Particle::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssiz
|
|||
const bool wantDebug = false;
|
||||
if (wantDebug) {
|
||||
qDebug("Particle::adjustEditPacketForClockSkew()...\n");
|
||||
qDebug(" lastEditedInLocalTime: %llu\n", lastEditedInLocalTime);
|
||||
qDebug(" clockSkew: %d\n", clockSkew);
|
||||
qDebug(" lastEditedInServerTime: %llu\n", lastEditedInServerTime);
|
||||
qDebug() << " lastEditedInLocalTime: " << lastEditedInLocalTime << "\n";
|
||||
qDebug() << " clockSkew: " << clockSkew << "\n";
|
||||
qDebug() << " lastEditedInServerTime: " << lastEditedInServerTime << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,14 +481,6 @@ void Particle::update() {
|
|||
bool shouldDie = getShouldDie() || (!isInHand && !isStillMoving && isReallyOld);
|
||||
setShouldDie(shouldDie);
|
||||
|
||||
const bool wantDebug = false;
|
||||
if (wantDebug) {
|
||||
printf("Particle::update()... timeElapsed: %f lifeTime:%f editedAgo:%f "
|
||||
"isInHand:%s isStillMoveing:%s isReallyOld:%s shouldDie:%s\n",
|
||||
timeElapsed, getLifetime(), getEditedAgo(), debug::valueOf(isInHand), debug::valueOf(isStillMoving),
|
||||
debug::valueOf(isReallyOld), debug::valueOf(shouldDie));
|
||||
}
|
||||
|
||||
runUpdateScript(); // allow the javascript to alter our state
|
||||
|
||||
// If the ball is in hand, it doesn't move or have gravity effect it
|
||||
|
|
|
@ -20,12 +20,20 @@
|
|||
#include <UUID.h>
|
||||
#include <VoxelConstants.h>
|
||||
|
||||
#include <Sound.h>
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
int ScriptEngine::_scriptNumber = 1;
|
||||
VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface;
|
||||
ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface;
|
||||
|
||||
static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* engine) {
|
||||
QUrl soundURL = QUrl(context->argument(0).toString());
|
||||
QScriptValue soundScriptValue = engine->newQObject(new Sound(soundURL), QScriptEngine::ScriptOwnership);
|
||||
|
||||
return soundScriptValue;
|
||||
}
|
||||
|
||||
ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems,
|
||||
const char* scriptMenuName, AbstractMenuInterface* menu,
|
||||
|
@ -82,6 +90,8 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents) {
|
|||
return true;
|
||||
}
|
||||
|
||||
Q_SCRIPT_DECLARE_QMETAOBJECT(AudioInjectorOptions, QObject*)
|
||||
|
||||
void ScriptEngine::run() {
|
||||
_isRunning = true;
|
||||
QScriptEngine engine;
|
||||
|
@ -101,6 +111,17 @@ void ScriptEngine::run() {
|
|||
QScriptValue particleScripterValue = engine.newQObject(&_particlesScriptingInterface);
|
||||
engine.globalObject().setProperty("Particles", particleScripterValue);
|
||||
|
||||
|
||||
QScriptValue soundConstructorValue = engine.newFunction(soundConstructor);
|
||||
QScriptValue soundMetaObject = engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue);
|
||||
engine.globalObject().setProperty("Sound", soundMetaObject);
|
||||
|
||||
QScriptValue injectionOptionValue = engine.scriptValueFromQMetaObject<AudioInjectorOptions>();
|
||||
engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue);
|
||||
|
||||
QScriptValue audioScriptingInterfaceValue = engine.newQObject(&_audioScriptingInterface);
|
||||
engine.globalObject().setProperty("Audio", audioScriptingInterfaceValue);
|
||||
|
||||
if (_controllerScriptingInterface) {
|
||||
QScriptValue controllerScripterValue = engine.newQObject(_controllerScriptingInterface);
|
||||
engine.globalObject().setProperty("Controller", controllerScripterValue);
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
#include <QtCore/QUrl>
|
||||
|
||||
#include <AbstractMenuInterface.h>
|
||||
#include <AudioScriptingInterface.h>
|
||||
#include <ParticlesScriptingInterface.h>
|
||||
#include <VoxelsScriptingInterface.h>
|
||||
|
||||
#include "AbstractControllerScriptingInterface.h"
|
||||
|
||||
const QString NO_SCRIPT("");
|
||||
|
@ -61,6 +63,7 @@ private:
|
|||
static VoxelsScriptingInterface _voxelsScriptingInterface;
|
||||
static ParticlesScriptingInterface _particlesScriptingInterface;
|
||||
AbstractControllerScriptingInterface* _controllerScriptingInterface;
|
||||
AudioScriptingInterface _audioScriptingInterface;
|
||||
bool _wantMenuItems;
|
||||
QString _scriptMenuName;
|
||||
AbstractMenuInterface* _menu;
|
||||
|
|
|
@ -41,11 +41,9 @@ PacketSender::PacketSender(PacketSenderNotify* notify, int packetsPerSecond) :
|
|||
_totalPacketsQueued(0),
|
||||
_totalBytesQueued(0)
|
||||
{
|
||||
//printf("PacketSender[%p] created... \n", this);
|
||||
}
|
||||
|
||||
PacketSender::~PacketSender() {
|
||||
//printf("PacketSender::~PacketSender[%p] destroyed... \n", this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,11 +137,6 @@ bool PacketSender::nonThreadedProcess() {
|
|||
const uint64_t USECS_PER_SECOND = 1000 * 1000;
|
||||
const float ZERO_RESET_CALLS_PER_SECOND = 1; // used in guard against divide by zero
|
||||
|
||||
bool wantDebugging = false;
|
||||
if (wantDebugging) {
|
||||
printf("\n\nPacketSender::nonThreadedProcess() _packets.size()=%ld\n",_packets.size());
|
||||
}
|
||||
|
||||
// keep track of our process call times, so we have a reliable account of how often our caller calls us
|
||||
uint64_t elapsedSinceLastCall = now - _lastProcessCallTime;
|
||||
_lastProcessCallTime = now;
|
||||
|
@ -153,24 +146,10 @@ bool PacketSender::nonThreadedProcess() {
|
|||
const int TRUST_AVERAGE_AFTER = AVERAGE_CALL_TIME_SAMPLES * 2;
|
||||
if (_usecsPerProcessCallHint == 0 || _averageProcessCallTime.getSampleCount() > TRUST_AVERAGE_AFTER) {
|
||||
averageCallTime = _averageProcessCallTime.getAverage();
|
||||
|
||||
if (wantDebugging) {
|
||||
printf("averageCallTime = _averageProcessCallTime.getAverage() =%f\n",averageCallTime);
|
||||
}
|
||||
|
||||
} else {
|
||||
averageCallTime = _usecsPerProcessCallHint;
|
||||
|
||||
if (wantDebugging) {
|
||||
printf("averageCallTime = _usecsPerProcessCallHint =%f\n",averageCallTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (wantDebugging) {
|
||||
printf("elapsedSinceLastCall=%llu averageCallTime=%f\n",elapsedSinceLastCall, averageCallTime);
|
||||
}
|
||||
|
||||
if (_packets.size() == 0) {
|
||||
// in non-threaded mode, if there's nothing to do, just return, keep running till they terminate us
|
||||
return isStillRunning();
|
||||
|
@ -202,25 +181,15 @@ bool PacketSender::nonThreadedProcess() {
|
|||
// packets per second send rate.
|
||||
float callsPerSecond = USECS_PER_SECOND / averageCallTime;
|
||||
|
||||
if (wantDebugging) {
|
||||
printf("PacketSender::process() USECS_PER_SECOND=%llu averageCallTime=%f callsPerSecond=%f\n",
|
||||
USECS_PER_SECOND, averageCallTime, callsPerSecond );
|
||||
}
|
||||
|
||||
// theoretically we could get called less than 1 time per second... but since we're using floats, it really shouldn't be
|
||||
// possible to get 0 calls per second, but we will guard agains that here, just in case.
|
||||
if (callsPerSecond == 0) {
|
||||
callsPerSecond = ZERO_RESET_CALLS_PER_SECOND;
|
||||
qDebug("PacketSender::nonThreadedProcess() UNEXPECTED:callsPerSecond==0, assuming ZERO_RESET_CALLS_PER_SECOND\n");
|
||||
}
|
||||
|
||||
// This is the average number of packets per call...
|
||||
averagePacketsPerCall = _packetsPerSecond / callsPerSecond;
|
||||
packetsToSendThisCall = averagePacketsPerCall;
|
||||
if (wantDebugging) {
|
||||
printf("PacketSender::process() averageCallTime=%f averagePacketsPerCall=%f packetsToSendThisCall=%d\n",
|
||||
averageCallTime, averagePacketsPerCall, packetsToSendThisCall);
|
||||
}
|
||||
|
||||
// if we get called more than 1 per second, we want to mostly divide the packets evenly across the calls...
|
||||
// but we want to track the remainder and make sure over the course of a second, we are sending the target PPS
|
||||
|
@ -252,83 +221,33 @@ bool PacketSender::nonThreadedProcess() {
|
|||
// than 5 times per second) This gives us sufficient smoothing in our packet adjustments
|
||||
float callIntervalsPerReset = fmax(callsPerSecond, MIN_CALL_INTERVALS_PER_RESET);
|
||||
|
||||
if (wantDebugging) {
|
||||
printf("about to check interval... callsPerSecond=%f elapsedSinceLastPPSCheck=%llu checkInterval=%f\n",
|
||||
callsPerSecond, elapsedSinceLastCheck, (averageCallTime * CALL_INTERVALS_TO_CHECK));
|
||||
}
|
||||
|
||||
if (elapsedSinceLastCheck > (averageCallTime * CALL_INTERVALS_TO_CHECK)) {
|
||||
|
||||
if (wantDebugging) {
|
||||
printf(">>>>>>>>>>>>>>> check interval... _packetsOverCheckInterval=%d elapsedSinceLastPPSCheck=%llu\n",
|
||||
_packetsOverCheckInterval, elapsedSinceLastCheck);
|
||||
}
|
||||
|
||||
float ppsOverCheckInterval = (float)_packetsOverCheckInterval;
|
||||
float ppsExpectedForCheckInterval = (float)_packetsPerSecond * ((float)elapsedSinceLastCheck / (float)USECS_PER_SECOND);
|
||||
|
||||
if (wantDebugging) {
|
||||
printf(">>>>>>>>>>>>>>> check interval... ppsOverCheckInterval=%f ppsExpectedForCheckInterval=%f\n",
|
||||
ppsOverCheckInterval, ppsExpectedForCheckInterval);
|
||||
}
|
||||
|
||||
if (ppsOverCheckInterval < ppsExpectedForCheckInterval) {
|
||||
int adjust = ppsExpectedForCheckInterval - ppsOverCheckInterval;
|
||||
packetsToSendThisCall += adjust;
|
||||
if (wantDebugging) {
|
||||
qDebug("Lower pps [%f] than expected [%f] over check interval [%llu], adjusting UP by %d.\n",
|
||||
ppsOverCheckInterval, ppsExpectedForCheckInterval, elapsedSinceLastCheck, adjust);
|
||||
}
|
||||
} else if (ppsOverCheckInterval > ppsExpectedForCheckInterval) {
|
||||
int adjust = ppsOverCheckInterval - ppsExpectedForCheckInterval;
|
||||
packetsToSendThisCall -= adjust;
|
||||
if (wantDebugging) {
|
||||
qDebug("Higher pps [%f] than expected [%f] over check interval [%llu], adjusting DOWN by %d.\n",
|
||||
ppsOverCheckInterval, ppsExpectedForCheckInterval, elapsedSinceLastCheck, adjust);
|
||||
}
|
||||
} else {
|
||||
if (wantDebugging) {
|
||||
qDebug("pps [%f] is expected [%f] over check interval [%llu], NO ADJUSTMENT.\n",
|
||||
ppsOverCheckInterval, ppsExpectedForCheckInterval, elapsedSinceLastCheck);
|
||||
}
|
||||
}
|
||||
|
||||
// now, do we want to reset the check interval? don't want to completely reset, because we would still have
|
||||
// a rounding error. instead, we check to see that we've passed the reset interval (which is much larger than
|
||||
// the check interval), and on those reset intervals we take the second half average and keep that for the next
|
||||
// interval window...
|
||||
if (wantDebugging) {
|
||||
printf(">>>>>>>>>>> RESET >>>>>>>>>>>>>>> Should we reset? callsPerSecond=%f elapsedSinceLastPPSCheck=%llu resetInterval=%f\n",
|
||||
callsPerSecond, elapsedSinceLastCheck, (averageCallTime * callIntervalsPerReset));
|
||||
}
|
||||
|
||||
if (elapsedSinceLastCheck > (averageCallTime * callIntervalsPerReset)) {
|
||||
|
||||
if (wantDebugging) {
|
||||
printf(">>>>>>>>>>> RESET >>>>>>>>>>>>>>> elapsedSinceLastCheck/2=%llu _packetsOverCheckInterval/2=%d\n",
|
||||
(elapsedSinceLastCheck / 2), (_packetsOverCheckInterval / 2));
|
||||
}
|
||||
|
||||
// Keep average packets and time for "second half" of check interval
|
||||
_lastPPSCheck += (elapsedSinceLastCheck / 2);
|
||||
_packetsOverCheckInterval = (_packetsOverCheckInterval / 2);
|
||||
|
||||
elapsedSinceLastCheck = now - _lastPPSCheck;
|
||||
|
||||
if (wantDebugging) {
|
||||
printf(">>>>>>>>>>> RESET >>>>>>>>>>>>>>> NEW _lastPPSCheck=%llu elapsedSinceLastCheck=%llu _packetsOverCheckInterval=%d\n",
|
||||
_lastPPSCheck, elapsedSinceLastCheck, _packetsOverCheckInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int packetsLeft = _packets.size();
|
||||
|
||||
if (wantDebugging) {
|
||||
printf("packetsSentThisCall=%d packetsToSendThisCall=%d packetsLeft=%d\n",
|
||||
packetsSentThisCall, packetsToSendThisCall, packetsLeft);
|
||||
}
|
||||
|
||||
// Now that we know how many packets to send this call to process, just send them.
|
||||
while ((packetsSentThisCall < packetsToSendThisCall) && (packetsLeft > 0)) {
|
||||
lock();
|
||||
|
@ -347,10 +266,6 @@ bool PacketSender::nonThreadedProcess() {
|
|||
_totalPacketsSent++;
|
||||
_totalBytesSent += temporary.getLength();
|
||||
|
||||
if (wantDebugging) {
|
||||
printf("nodeSocket->send()... packetsSentThisCall=%d _packetsOverCheckInterval=%d\n",
|
||||
packetsSentThisCall, _packetsOverCheckInterval);
|
||||
}
|
||||
if (_notify) {
|
||||
_notify->packetSentNotification(temporary.getLength());
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#define hifi_RegisteredMetaTypes_h
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
#include "SharedUtil.h"
|
||||
|
|
Loading…
Reference in a new issue