void fsBinaryStream::encode_message(std::string &msg_out, const fsTrackingData           &tracking_data) {
    Size start = msg_out.size();

    BlockHeader header(fsMsg::MSG_OUT_TRACKING_STATE);
    write_pod(msg_out, header);

    uint16_t N_blocks = 5;
    write_pod(msg_out, N_blocks);
    encodeInfo(       msg_out, tracking_data);
    encodePose(       msg_out, tracking_data);
    encodeBlendshapes(msg_out, tracking_data);
    encodeEyeGaze(    msg_out, tracking_data);
    encodeMarkers(    msg_out, tracking_data);

    update_msg_size(msg_out, start);
}
Exemple #2
0
void
DecodingTable::setDecodingTable(uint k, DecodeableSubstr* substrs)
{
	assert (k <= MAXK);

	this->k = k;
	this->bytesStream = 0;

	// Scanning the table and building its compact representation
	uint entries = pow(2, this->k);
	endings = new BitString(entries);

	map<vector<uchar>, uint> tmp;
	map<vector<uchar>, uint>::iterator it;

	// Collecting all different decodeable substrings in the representation
	for (uint i=0; i<entries; i++)
	{
		if (substrs[i].length > 0)
		{
			// Check if the entry has been previously found
			it = tmp.find(substrs[i].substr);

			if (it == tmp.end())
			{
				// New substring
				tmp.insert(pair<vector<uchar>, uint> (substrs[i].substr, i));
			}
			else
			{
				// Although the substring was found, we must
				// check its jumping information because an
				// end-substring can be similar than a regular
				// one and its information must prevail
				if (substrs[it->second].special)
				{
					tmp.erase(substrs[i].substr);
					tmp.insert(pair<vector<uchar>, uint> (substrs[i].substr, i));
				}
			}
		}
	}

	table = new uint[entries];

	size_t reservedStream = entries;
	stream = new uchar[reservedStream];
	stream[bytesStream] = (uchar)0; bytesStream++;

	// Serializing the table
	for (uint i=0; i<entries; i++)
	{
		if (substrs[i].dbits > 0)
		{
			// Checking the available space in the stream 
			// and realloc if required
			while ((bytesStream+substrs[i].dbits+1) > reservedStream)
				reservedStream = Reallocate(&stream, reservedStream);

			if (substrs[i].length > 0)
			{
				// Regular entry
				it = tmp.find(substrs[i].substr);

				if (!substrs[it->second].encoded)
				{
					table[i] = bytesStream;
					substrs[it->second].position = table[i];
					substrs[it->second].encoded = true;

					stream[bytesStream] = encodeInfo(substrs[i].length, substrs[it->second].dbits);
					bytesStream++;

					for (uint j=0; j<substrs[i].length; j++)
						stream[bytesStream+j] = substrs[i].substr[j];
					bytesStream += substrs[i].length;
				}
				else table[i] = substrs[it->second].position;

				if (substrs[it->second].ending) endings->setBit(i);
			}
			else
			{
				// Entry pointing to a decoding subtree
				table[i] = bytesStream;

				stream[bytesStream] = encodeInfo(substrs[i].length, substrs[i].dbits);
				bytesStream++;

				bytesStream += VByte::encode(substrs[i].ptr, stream+bytesStream);
			}
		}
		else table[i] = 0;
	}
}