Merge remote-tracking branch 'clement/protocol' into atp

This commit is contained in:
Stephen Birarda 2015-07-08 12:19:04 -07:00
commit 1e34a63234
5 changed files with 39 additions and 62 deletions

View file

@ -767,7 +767,7 @@ void AudioClient::handleAudioInput() {
while (_inputRingBuffer.samplesAvailable() >= inputSamplesRequired) {
const int numNetworkBytes = _isStereoInput
? AudioConstants::NETWORK_FRAME_BYTES_STEREO`
? AudioConstants::NETWORK_FRAME_BYTES_STEREO
: AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL;
const int numNetworkSamples = _isStereoInput
? AudioConstants::NETWORK_FRAME_SAMPLES_STEREO
@ -842,14 +842,13 @@ void AudioClient::handleAudioInput() {
glm::quat headOrientation = _orientationGetter();
quint8 isStereo = _isStereoInput ? 1 : 0;
PacketType::Value packetType;
if (_lastInputLoudness == 0) {
_audioPacket->setType(PacketType::SilentAudioFrame);
_audioPacket->setPacketType(PacketType::SilentAudioFrame);
} else {
if (_shouldEchoToServer) {
_audioPacket->setType(PacketType::MicrophoneAudioWithEcho);
_audioPacket->setPacketType(PacketType::MicrophoneAudioWithEcho);
} else {
_audioPacket->setType(PacketType::MicrophoneAudioNoEcho);
_audioPacket->setPacketType(PacketType::MicrophoneAudioNoEcho);
}
}
@ -857,23 +856,24 @@ void AudioClient::handleAudioInput() {
_audioPacket->reset();
// write sequence number
_audioPacket->write(&_outgoingAvatarAudioSequenceNumber, sizeof(quint16));
_audioPacket->write(reinterpret_cast<char*>(&_outgoingAvatarAudioSequenceNumber), sizeof(quint16));
if (packetType == PacketType::SilentAudioFrame) {
if (_audioPacket->getPacketType() == PacketType::SilentAudioFrame) {
// pack num silent samples
_audioPacket->write(&numSilentSamples, sizeof(quint16));
quint16 numSilentSamples = numNetworkSamples;
_audioPacket->write(reinterpret_cast<char*>(&numSilentSamples), sizeof(quint16));
} else {
// set the mono/stereo byte
_audioPacket->write(&isStereo, sizeof(isStereo));
_audioPacket->write(reinterpret_cast<char*>(&isStereo), sizeof(isStereo));
}
// pack the three float positions
_audioPacket->write(&headPosition, sizeof(headPosition));
_audioPacket->write(reinterpret_cast<char*>(&headPosition), sizeof(headPosition));
// pack the orientation
_audioPacket->write(&headOrientation, sizeof(headOrientation));
_audioPacket->write(reinterpret_cast<char*>(&headOrientation), sizeof(headOrientation));
if (packetType != PacketType::SilentAudioFrame) {
if (_audioPacket->getPacketType() != PacketType::SilentAudioFrame) {
// audio samples have already been packed (written to networkAudioSamples)
_audioPacket->setSizeUsed(_audioPacket->getSizeUsed() + numNetworkBytes);
}
@ -912,12 +912,12 @@ void AudioClient::sendMuteEnvironmentPacket() {
auto mutePacket = NLPacket::create(PacketType::MuteEnvironment, dataSize);
const float MUTE_RADIUS = 50;
float MUTE_RADIUS = 50;
glm::vec3 currentSourcePosition = _positionGetter();
mutePacket->write(&currentSourcePosition, sizeof(currentSourcePosition));
mutePacket->write(&MUTE_RADIUS, sizeof(MUTE_RADIUS));
mutePacket->write(reinterpret_cast<char*>(&currentSourcePosition), sizeof(currentSourcePosition));
mutePacket->write(reinterpret_cast<char*>(&MUTE_RADIUS), sizeof(MUTE_RADIUS));
// grab our audio mixer from the NodeList, if it exists
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);

View file

@ -75,6 +75,8 @@ typedef struct ty_gverb ty_gverb;
typedef glm::vec3 (*AudioPositionGetter)();
typedef glm::quat (*AudioOrientationGetter)();
class NLPacket;
class AudioClient : public AbstractAudioInterface, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY

View file

@ -268,49 +268,35 @@ bool JurisdictionMap::writeToFile(const char* filename) {
return true;
}
int JurisdictionMap::packEmptyJurisdictionIntoMessage(NodeType_t type, unsigned char* destinationBuffer, int availableBytes) {
unsigned char* bufferStart = destinationBuffer;
int headerLength = DependencyManager::get<NodeList>()->populatePacketHeader(reinterpret_cast<char*>(destinationBuffer),
PacketType::Jurisdiction);
destinationBuffer += headerLength;
std::unique_ptr<NLPacket> JurisdictionMap::packEmptyJurisdictionIntoMessage(NodeType_t type) {
int bytes = 0;
auto packet = NLPacket::create(PacketType::Jurisdiction);
// Pack the Node Type in first byte
memcpy(destinationBuffer, &type, sizeof(type));
destinationBuffer += sizeof(type);
packet->write(reinterpret_cast<char*>(&type), sizeof(type));
// No root or end node details to pack!
int bytes = 0;
memcpy(destinationBuffer, &bytes, sizeof(bytes));
destinationBuffer += sizeof(bytes);
packet->write(reinterpret_cast<char*>(&bytes), sizeof(bytes));
return destinationBuffer - bufferStart; // includes header!
return std::move(packet); // includes header!
}
int JurisdictionMap::packIntoMessage(unsigned char* destinationBuffer, int availableBytes) {
unsigned char* bufferStart = destinationBuffer;
int headerLength = DependencyManager::get<NodeList>()->populatePacketHeader(reinterpret_cast<char*>(destinationBuffer),
PacketType::Jurisdiction);
destinationBuffer += headerLength;
std::unique_ptr<NLPacket> JurisdictionMap::packIntoMessage() {
auto packet = NLPacket::create(PacketType::Jurisdiction);
// Pack the Node Type in first byte
NodeType_t type = getNodeType();
memcpy(destinationBuffer, &type, sizeof(type));
destinationBuffer += sizeof(type);
packet->write(reinterpret_cast<char*>(&type), sizeof(type));
// add the root jurisdiction
if (_rootOctalCode) {
size_t bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_rootOctalCode));
memcpy(destinationBuffer, &bytes, sizeof(bytes));
destinationBuffer += sizeof(bytes);
memcpy(destinationBuffer, _rootOctalCode, bytes);
destinationBuffer += bytes;
// No root or end node details to pack!
packet->write(reinterpret_cast<char*>(&bytes), sizeof(bytes));
packet->write(reinterpret_cast<char*>(_rootOctalCode), bytes);
// if and only if there's a root jurisdiction, also include the end nodes
int endNodeCount = _endNodes.size();
memcpy(destinationBuffer, &endNodeCount, sizeof(endNodeCount));
destinationBuffer += sizeof(endNodeCount);
packet->write(reinterpret_cast<char*>(&endNodeCount), sizeof(endNodeCount));
for (int i=0; i < endNodeCount; i++) {
unsigned char* endNodeCode = _endNodes[i];
@ -318,18 +304,15 @@ int JurisdictionMap::packIntoMessage(unsigned char* destinationBuffer, int avail
if (endNodeCode) {
bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(endNodeCode));
}
memcpy(destinationBuffer, &bytes, sizeof(bytes));
destinationBuffer += sizeof(bytes);
memcpy(destinationBuffer, endNodeCode, bytes);
destinationBuffer += bytes;
packet->write(reinterpret_cast<char*>(&bytes), sizeof(bytes));
packet->write(reinterpret_cast<char*>(endNodeCode), bytes);
}
} else {
int bytes = 0;
memcpy(destinationBuffer, &bytes, sizeof(bytes));
destinationBuffer += sizeof(bytes);
packet->write(reinterpret_cast<char*>(&bytes), sizeof(bytes));
}
return destinationBuffer - bufferStart; // includes header!
return std::move(packet); // includes header!
}
int JurisdictionMap::unpackFromMessage(const unsigned char* sourceBuffer, int availableBytes) {

View file

@ -61,10 +61,10 @@ public:
void copyContents(unsigned char* rootCodeIn, const std::vector<unsigned char*>& endNodesIn);
int unpackFromMessage(const unsigned char* sourceBuffer, int availableBytes);
int packIntoMessage(unsigned char* destinationBuffer, int availableBytes);
std::unique_ptr<NLPacket> packIntoMessage();
/// Available to pack an empty or unknown jurisdiction into a network packet, used when no JurisdictionMap is available
static int packEmptyJurisdictionIntoMessage(NodeType_t type, unsigned char* destinationBuffer, int availableBytes);
static std::unique_ptr<NLPacket> packEmptyJurisdictionIntoMessage(NodeType_t type);
void displayDebugDetails() const;

View file

@ -44,16 +44,8 @@ bool JurisdictionSender::process() {
// call our ReceivedPacketProcessor base class process so we'll get any pending packets
if (continueProcessing && (continueProcessing = ReceivedPacketProcessor::process())) {
// add our packet to our own queue, then let the PacketSender class do the rest of the work.
static unsigned char buffer[MAX_PACKET_SIZE];
unsigned char* bufferOut = &buffer[0];
int sizeOut = 0;
if (_jurisdictionMap) {
sizeOut = _jurisdictionMap->packIntoMessage(bufferOut, MAX_PACKET_SIZE);
} else {
sizeOut = JurisdictionMap::packEmptyJurisdictionIntoMessage(getNodeType(), bufferOut, MAX_PACKET_SIZE);
}
auto packet = (_jurisdictionMap) ? _jurisdictionMap->packIntoMessage()
: JurisdictionMap::packEmptyJurisdictionIntoMessage(getNodeType());
int nodeCount = 0;
lockRequestingNodes();
@ -64,7 +56,7 @@ bool JurisdictionSender::process() {
SharedNodePointer node = DependencyManager::get<NodeList>()->nodeWithUUID(nodeUUID);
if (node && node->getActiveSocket()) {
_packetSender.queuePacketForSending(node, QByteArray(reinterpret_cast<char *>(bufferOut), sizeOut));
_packetSender.queuePacketForSending(node, packet);
nodeCount++;
}
}