History

changed class name to AudioStreamStats, reverted ScriptEngine packing back to QDataStream

wangyix committed 12 years ago

Commit de3c1eb1 parent c3f57177 files · +34 −41Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 7 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+17−24
@@ -458,54 +458,47 @@ void ScriptEngine::run() { · 457 unmodified lines
458 _numAvatarSoundSentBytes = 0;458 _numAvatarSoundSentBytes = 0;
459 }459 }
460 }460 }
461
462 QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame
463 ? PacketTypeSilentAudioFrame
464 : PacketTypeMicrophoneAudioNoEcho);
461 465
462 char audioPacket[MAX_PACKET_SIZE];466 QDataStream packetStream(&audioPacket, QIODevice::Append);
463 467
464 // pack header468 // pack a placeholder value for sequence number for now, will be packed when destination node is known
465 int numBytesPacketHeader = populatePacketHeader(audioPacket, silentFrame469 int numPreSequenceNumberBytes = audioPacket.size();
466 ? PacketTypeSilentAudioFrame470 packetStream << (quint16)0;
467 : PacketTypeMicrophoneAudioNoEcho);
468 char* dataAt = audioPacket + numBytesPacketHeader;
469
470 // skip over sequence number for now; will be packed when destination node is known
471 char* sequenceAt = dataAt;
472 dataAt += sizeof(quint16);
473 471
474 // use the orientation and position of this avatar for the source of this audio472 // use the orientation and position of this avatar for the source of this audio
475 memcpy(dataAt, &_avatarData->getPosition(), sizeof(glm::vec3));473 packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3));
476 dataAt += sizeof(glm::vec3);
477
478 glm::quat headOrientation = _avatarData->getHeadOrientation();474 glm::quat headOrientation = _avatarData->getHeadOrientation();
479 memcpy(dataAt, &headOrientation, sizeof(glm::quat));475 packetStream.writeRawData(reinterpret_cast<const char*>(&headOrientation), sizeof(glm::quat));
480 dataAt += sizeof(glm::quat);
481 476
482 if (silentFrame) {477 if (silentFrame) {
483 if (!_isListeningToAudioStream) {478 if (!_isListeningToAudioStream) {
484 // if we have a silent frame and we're not listening then just send nothing and break out of here479 // if we have a silent frame and we're not listening then just send nothing and break out of here
485 break;480 break;
486 }481 }
482
487 // write the number of silent samples so the audio-mixer can uphold timing483 // write the number of silent samples so the audio-mixer can uphold timing
488 memcpy(dataAt, &SCRIPT_AUDIO_BUFFER_SAMPLES, sizeof(int16_t));484 packetStream.writeRawData(reinterpret_cast<const char*>(&SCRIPT_AUDIO_BUFFER_SAMPLES), sizeof(int16_t));
489 dataAt += sizeof(int16_t);
490 } else if (nextSoundOutput) {485 } else if (nextSoundOutput) {
491 // write the raw audio data486 // write the raw audio data
492 int numAvailableBytes = numAvailableSamples * sizeof(int16_t);487 packetStream.writeRawData(reinterpret_cast<const char*>(nextSoundOutput),
493 memcpy(dataAt, nextSoundOutput, numAvailableBytes);488 numAvailableSamples * sizeof(int16_t));
494 dataAt += numAvailableBytes;
495 }489 }
496 490
497 // write audio packet to AudioMixer nodes491 // write audio packet to AudioMixer nodes
498 int audioPacketSize = dataAt - audioPacket;
499 NodeList* nodeList = NodeList::getInstance();492 NodeList* nodeList = NodeList::getInstance();
500 foreach(const SharedNodePointer& node, nodeList->getNodeHash()) {493 foreach(const SharedNodePointer& node, nodeList->getNodeHash()) {
501 // only send to nodes of type AudioMixer494 // only send to nodes of type AudioMixer
502 if (node->getType() == NodeType::AudioMixer) {495 if (node->getType() == NodeType::AudioMixer) {
503 // pack sequence number496 // pack sequence number
504 quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++;497 quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++;
505 memcpy(sequenceAt, &sequence, sizeof(quint16));498 memcpy(audioPacket.data() + numPreSequenceNumberBytes, &sequence, sizeof(quint16));
506 499
507 // send audio packet500 // send audio packet
508 nodeList->writeDatagram(audioPacket, audioPacketSize, node);501 nodeList->writeDatagram(audioPacket, node);
509 }502 }
510 }503 }
511 }504 }