Пример #1
0
 Chunk::Chunk(const void *_p, uint32_t len){
   p = (const char *)_p;
   if (len && len < getPayloadSize() + 8){
     FAIL_MSG("Chunk %s (%" PRIu32 "b) does not fit in %" PRIu32 " bytes length!", getType().c_str(),
              getPayloadSize() + 8, len);
     p = 0;
   }
 }
Пример #2
0
__RSPacket* __RSPacketBuildData(__RSPacket* packet, const unsigned char* data, unsigned long length)
{
    if (packet == nil || data == nil || length == 0) return packet;
    __RSPacketInit(packet);
    if (length > getPayloadSize(packet))
    {
        length = getPayloadSize(packet);
    }
    memcpy(packet->payload.data, data, length);
    setDataLength(packet, length);
    return packet;
}
Пример #3
0
 void ListChunk::toPrettyString(std::ostream &o, size_t indent) const{
   o << std::string(indent, ' ') << "[" << getType() << "] " << getIdentifier() << " ("
     << (getPayloadSize() + 8) << "b):" << std::endl;
   indent += 2;
   uint32_t i = 12;
   uint32_t len = getPayloadSize() + 8;
   while (i + 8 <= len){
     const Chunk C(p + i);
     C.toPrettyString(o, indent);
     i += C.getPayloadSize() + 8;
     if (!C){return;}
   }
 }
Пример #4
0
int DeliverPacket::parse(const char* buf, size_t size) {
	int parsed = PayloadPacket::parse(buf, size);
	if (parsed == -1)
		return -1;
	// get the sender
	m_connection_id = buf[parsed];
	// get the message data
	uint32_t msg_start = parsed + 1;
	uint32_t msg_size = getPayloadSize() - 1;
	m_msg.reset(new std::string(msg_size, '\0'));
	std::copy(buf+msg_start, buf+msg_start+msg_size, (*m_msg).begin());
	return parsed + getPayloadSize();
}
Пример #5
0
int UserJoinedPacket::parse(const char* buf, size_t size) {
	int parsed = PayloadPacket::parse(buf, size);
	if (parsed == -1)
		return -1;
	// get the user that joined
	m_connection_id = buf[parsed];
	// get the master information
	m_master = buf[parsed+1];
	// get the userinfo
	uint32_t msg_start = parsed + 2;
	uint32_t msg_size = getPayloadSize() - 2;
	m_userinfo.reset(new std::string(msg_size, '\0'));
	std::copy(buf+msg_start, buf+msg_start+msg_size, (*m_userinfo).begin());
	return parsed + getPayloadSize();
}
Пример #6
0
unsigned long __RSPacketGetPacketSize(__RSPacket* packet)
{
    if (packet && isValidPacket(packet))
    {
        return getPayloadSize(packet);
    }
    return 0;
}
Пример #7
0
int RoutingPacket::parse(const char* buf, size_t size) {
	int parsed = PayloadPacket::parse(buf, size);
	if (parsed == -1)
		return -1;
	// get the recipients
	m_address_count = buf[parsed];
	if ((uint32_t)m_address_count + 1 > getPayloadSize())
		return -1;
	m_connection_ids.resize(m_address_count);
	std::copy(buf+parsed+1, buf+parsed+1+m_address_count, m_connection_ids.begin());
	// get the message data
	uint32_t msg_start = parsed+1+m_address_count;
	uint32_t msg_size = getPayloadSize() - 1 - m_address_count;
	m_msg.reset(new std::string(msg_size, '\0'));
	std::copy(buf+msg_start, buf+msg_start+msg_size, (*m_msg).begin());
	return parsed + getPayloadSize();
}
Пример #8
0
void AbstractAudioInterface::emitAudioPacket(const void* audioData, size_t bytes, quint16& sequenceNumber,
                                             const Transform& transform, glm::vec3 avatarBoundingBoxCorner, glm::vec3 avatarBoundingBoxScale,
                                             PacketType packetType, QString codecName) {
    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);
        auto audioPacket = NLPacket::create(packetType);

        // FIXME - this is not a good way to determine stereoness with codecs.... 
        quint8 isStereo = bytes == AudioConstants::NETWORK_FRAME_BYTES_STEREO ? 1 : 0;

        // write sequence number
        auto sequence = sequenceNumber++;
        audioPacket->writePrimitive(sequence);

        // write the codec
        audioPacket->writeString(codecName);

        if (packetType == 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());

        audioPacket->writePrimitive(avatarBoundingBoxCorner);
        audioPacket->writePrimitive(avatarBoundingBoxScale);


        if (audioPacket->getType() != PacketType::SilentAudioFrame) {
            // audio samples have already been packed (written to networkAudioSamples)
            int leadingBytes = audioPacket->getPayloadSize();
            audioPacket->setPayloadSize(leadingBytes + bytes);
            memcpy(audioPacket->getPayload() + leadingBytes, audioData, bytes);
        }
        nodeList->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendAudioPacket);
        nodeList->sendUnreliablePacket(*audioPacket, *audioMixer);
    }
}
Пример #9
0
 void Chunk::toPrettyString(std::ostream &o, size_t indent) const{
   if (!p){
     o << std::string(indent, ' ') << "INVALID CHUNK" << std::endl;
     return;
   }
   switch (Bit::btohl(p)){
   case 0x52494646lu: // RIFF
   case 0x4C495354lu: // LIST
     return ListChunk(p).toPrettyString(o, indent);
   case 0x666D7420: // "fmt "
     return fmt(p).toPrettyString(o, indent);
   case 0x66616374: // fact
     return fact(p).toPrettyString(o, indent);
   case 0x49534654: // ISFT
     return ISFT(p).toPrettyString(o, indent);
   default:
     o << std::string(indent, ' ') << "[" << getType() << "] UNIMPLEMENTED ("
       << (getPayloadSize() + 8) << "b)" << std::endl;
   }
 }
Пример #10
0
 void fmt::toPrettyString(std::ostream &o, size_t indent) const{
   o << std::string(indent, ' ') << "[" << getType() << "] (" << (getPayloadSize() + 8)
     << "b):" << std::endl;
   indent += 1;
   o << std::string(indent, ' ') << "Codec: " << getCodec() << " (" << getFormat() << ")"
     << std::endl;
   o << std::string(indent, ' ') << "Channels: " << getChannels() << std::endl;
   o << std::string(indent, ' ') << "Sample rate: " << getHz() << "Hz" << std::endl;
   o << std::string(indent, ' ') << "Bytes/s: " << getBPS() << std::endl;
   o << std::string(indent, ' ') << "Block size: " << getBlockSize() << " bytes" << std::endl;
   o << std::string(indent, ' ') << "Sample size: " << getSize() << " bits" << std::endl;
   if (getExtLen()){
     o << std::string(indent, ' ') << "-- extended " << getExtLen() << "bytes --" << std::endl;
     if (getExtLen() >= 2){
       o << std::string(indent, ' ') << "Valid bits: " << getValidBits() << std::endl;
     }
     if (getExtLen() >= 6){
       o << std::string(indent, ' ') << "Channel mask: " << getChannelMask() << std::endl;
     }
     if (getExtLen() >= 22){
       o << std::string(indent, ' ') << "GUID: " << getGUID() << std::endl;
     }
   }
 }
Пример #11
0
 void ISFT::toPrettyString(std::ostream &o, size_t indent) const{
   o << std::string(indent, ' ') << "[" << getType() << "] (" << (getPayloadSize() + 8)
     << "b):" << std::endl;
   indent += 1;
   o << std::string(indent, ' ') << "Software: " << getSoftware() << std::endl;
 }
Пример #12
0
 std::string ISFT::getSoftware() const{
   if (!p){return 0;}
   return std::string(p+8, getPayloadSize());
 }
Пример #13
0
 void fact::toPrettyString(std::ostream &o, size_t indent) const{
   o << std::string(indent, ' ') << "[" << getType() << "] (" << (getPayloadSize() + 8)
     << "b):" << std::endl;
   indent += 1;
   o << std::string(indent, ' ') << "Samples per channel: " << getSamplesPerChannel() << std::endl;
 }
Пример #14
0
 std::string fmt::getGUID() const{
   if (getPayloadSize() < 40 || getExtLen() < 22){return "";}
   return std::string(p + 32, 16);
 }
Пример #15
0
 uint32_t fmt::getChannelMask() const{
   if (getPayloadSize() < 24 || getExtLen() < 6){return 0;}
   return Bit::btohl_le(p + 28);
 }
Пример #16
0
 uint16_t fmt::getExtLen() const{
   if (getPayloadSize() < 18){return 0;}
   return Bit::btohs_le(p + 24);
 }
Пример #17
0
 uint16_t fmt::getValidBits() const{
   if (getPayloadSize() < 20 || getExtLen() < 2){return 0;}
   return Bit::btohs_le(p + 26);
 }
Пример #18
0
// Return reference to payload. Returns null if no payload
// jbodah
char *getPayload(packet *newPacket) {
  if( getPayloadSize( newPacket ) == 0 )
    return NULL ;
  return &newPacket->contents[5] ;
}