Skip to content

Instantly share code, notes, and snippets.

@fran6co
Created March 31, 2016 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fran6co/bc2b4ccfb4b28ec931131933a27775b6 to your computer and use it in GitHub Desktop.
Save fran6co/bc2b4ccfb4b28ec931131933a27775b6 to your computer and use it in GitHub Desktop.
int main () {
UDPSocket sock (9000);
sock.joinGroup("239.0.1.1");
const int PACK_SIZE = 4096;
const int BUF_LEN = 65540;
char buffer[BUF_LEN];
while(true) {
unsigned short sourcePort;
std::string sourceAddress;
int recvMsgSize = sock.recvFrom(buffer, BUF_LEN, sourceAddress, sourcePort);
if (recvMsgSize == sizeof(uint64_t)) {
uint64_t total_pack = reinterpret_cast<uint64_t*>(buffer)[0];
std::unique_ptr<char[]> longbuf (new char[PACK_SIZE * total_pack]);
for (int i = 0; i < total_pack; i++) {
recvMsgSize = sock.recvFrom(buffer, BUF_LEN, sourceAddress, sourcePort);
if (recvMsgSize != PACK_SIZE) {
break;
}
memcpy( & longbuf.get()[i * PACK_SIZE], buffer, PACK_SIZE);
}
if (recvMsgSize != PACK_SIZE) {
continue;
}
cv::Mat rawData (1, PACK_SIZE * total_pack, CV_8UC1, longbuf.get());
cv::Mat frame = imdecode(rawData, CV_LOAD_IMAGE_COLOR);
cv::imshow("debug", frame);
cv::waitKey(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment