void QtDataXfer::processOutboundBytes(QByteArray outbound) { if(enabled) { std::string s = dataXferWrap.escapeDataOut( std::string{outbound.constData(), static_cast<std::string::size_type>(outbound.size())}); assert(s.size() <= std::numeric_limits<int>::max()); emit sendRawBytes(QByteArray{s.c_str(), static_cast<int>(s.size())}); } else emit sendRawBytes(outbound); }
//------------------------------------------------------------------------------ void ofxJitterNetworkSender::sendText(const string& txt) { m_messageHeader.id = SWAP32(JIT_MESSAGE_PACKET_ID); m_messageHeader.size = SWAP32(sizeof(long) + // size sizeof(long) + // ac sizeof(char) + // type sizeof(char)*txt.length() + // number sizeof(char)); // null terminator sendRawBytes((char *)&m_messageHeader.id, sizeof(long)); sendRawBytes((char *)&m_messageHeader.size, sizeof(long)); // the packet long messageSizeBytes = m_messageHeader.size; // 32-bit integer that contains the size of the serialized message in bytes. long ac = SWAP32(0); // Following that another 32-bit integer gives the argument count for the atoms. /// Following that comes the message atoms themselves, starting with the leading symbol if it exists. // Each atom is represented in memory first with a char that indicates what type of atom it is: // 's' for symbol, 'l' for long, and 'f' for float. // For long and float atoms, the next 4 bytes contain the value of the atom; // for symbol atoms a null terminated character string follows. char atomType = 's'; //'s' for symbol, 'l' for long, and 'f' for float. const char *cp = txt.c_str(); // seriously char nullTerm = '\0'; sendRawBytes((char *)&messageSizeBytes, sizeof(long)); sendRawBytes((char *)&ac, sizeof(long)); sendRawBytes((char *)&atomType, sizeof(char)); sendRawBytes((char *)cp, txt.length()*sizeof(char)); sendRawBytes((char *)&nullTerm, sizeof(char)); //readResponse(); }
//------------------------------------------------------------------------------ void ofxMatrixNetworkServer::sendDisconnect(int i) { //////SEND HANDSHAKE m_chunkHeader.id = SWAP32(JIT_MESSAGE_DISCONNECT_ID); m_chunkHeader.size = 0; sendRawBytes(i, (char *)(&m_chunkHeader), sizeof(t_jit_net_packet_header)); }
//------------------------------------------------------------------------------ void ofxMatrixNetworkServer::sendHandshake(int i) { //////SEND HANDSHAKE m_chunkHeader.id = SWAP32(JIT_MESSAGE_HANDSHAKE_ID); m_chunkHeader.size = 0; sendRawBytes(i, (char *)(&m_chunkHeader), sizeof(t_jit_net_packet_header)); }
//------------------------------------------------------------------------------ void ofxMatrixNetworkServer::sendFrame(const ofFloatPixelsRef pixels) { //for each connected client lets get the data being sent and lets print it to the screen for(unsigned int i = 0; i < (unsigned int)getLastID(); i++){ if(isClientConnected(i) && tx_valid[i] == 2){ tx_valid[i] = 1; int planecount = pixels.getNumChannels(); int dimcount = 2; // only sending 2d matrices from of int dim[dimcount]; dim[0] = pixels.getWidth(); dim[1] = pixels.getHeight(); int typeSize = pixels.getBytesPerChannel(); int type = JIT_MATRIX_TYPE_FLOAT32; makeMatrixHeader(planecount, typeSize, type, dim, dimcount); char *matrix = (char*)pixels.getPixels(); //////SEND ONE MATRIX sendRawBytes(i, (char *)(&m_chunkHeader), sizeof(t_jit_net_packet_header)); sendRawBytes(i, (char *)(&m_matrixHeader), sizeof(t_jit_net_packet_matrix)); //DELETE THIS LINE //int packSize = SWAP32(m_matrixHeader.dimstride[dimcount-1])*SWAP32(m_matrixHeader.dim[dimcount-1]); //ofLog(OF_LOG_NOTICE, "send frame to client: " + ofToString(i)); int vector = dim[0] * typeSize * planecount; for(int j = 0; j < dim[1]; j++){ sendRawBytes(i, matrix + j * vector, vector); } } } }
//------------------------------------------------------------------------------ void ofxJitterNetworkSender::sendFrame(const ofPixelsRef pixels) { int planecount = pixels.getNumChannels(); int dimcount = 2; // only sending 2d matrices from of int dim[dimcount]; dim[0] = pixels.getWidth(); dim[1] = pixels.getHeight(); int typeSize = pixels.getBytesPerChannel(); int type = JIT_MATRIX_TYPE_CHAR; makeMatrixHeader(planecount, typeSize, type, dim, dimcount); char *matrix = (char*)pixels.getPixels(); //////SEND ONE MATRIX sendRawBytes((char *)(&m_chunkHeader), sizeof(t_jit_net_packet_header)); sendRawBytes((char *)(&m_matrixHeader), sizeof(t_jit_net_packet_matrix)); int packSize = SWAP32(m_matrixHeader.dimstride[SWAP32(m_matrixHeader.dimcount)-1]) * SWAP32(m_matrixHeader.dim[SWAP32(m_matrixHeader.dimcount)-1]); sendRawBytes(matrix, packSize); }
void QtDataXfer::sendRawData(const std::string &bytes) { // For some reason Qt accepts an int, not an unsigned int assert(bytes.size() <= std::numeric_limits<int>::max()); emit sendRawBytes(QByteArray{bytes.c_str(), static_cast<int>(bytes.size())}); }