Skip to content

Commit

Permalink
sending additional info in the header
Browse files Browse the repository at this point in the history
  • Loading branch information
jendralhxr committed Aug 7, 2019
1 parent 0cff14c commit 77ff120
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config.h
Expand Up @@ -15,3 +15,5 @@
#define PACK_SIZE 4096 //udp pack size; note that OSX limits < 8100 bytes
#define ENCODE_QUALITY 90 // JPEG
#define BUF_LEN 65540 // Larger than maximum UDP packet size
#define INFO_LEN 256

17 changes: 14 additions & 3 deletions tisim-recv.cpp
Expand Up @@ -21,6 +21,12 @@
using namespace cv;
unsigned int frames_count;
struct timeval start, stop, timestamp;
int total_pack;

struct header{
int pack_num;
char info[INFO_LEN];
} img_header;

int main(int argc, char * argv[]) {

Expand Down Expand Up @@ -48,10 +54,15 @@ int main(int argc, char * argv[]) {
// Block until receive message from a client
do {
recvMsgSize = sock.recvFrom(buffer, BUF_LEN, sourceAddress, sourcePort);
} while (recvMsgSize > sizeof(int));
int total_pack = ((int * ) buffer)[0];
} while (recvMsgSize > sizeof(struct header));

memcpy(&img_header, buffer, sizeof(struct header));
total_pack = img_header.pack_num;
printf("%s",img_header.info);

// total_pack = ((int * ) buffer)[0];

// cout << "expecting length of packs:" << total_pack << endl;
cout << "expecting length of packs:" << total_pack << endl;
char * longbuf = new char[PACK_SIZE * total_pack];
for (int i = 0; i < total_pack; i++) {
recvMsgSize = sock.recvFrom(buffer, BUF_LEN, sourceAddress, sourcePort);
Expand Down
16 changes: 15 additions & 1 deletion tisim-send.cpp
Expand Up @@ -47,6 +47,11 @@ struct timeval timeout;
struct timeval start, stop, timestamp;
unsigned int frames_count;

struct header{
int pack_num;
char info[INFO_LEN];
} img_header;

string servAddress;
unsigned short servPort;
UDPSocket sock;
Expand Down Expand Up @@ -225,7 +230,16 @@ int capture_image(int fd){
int total_pack = 1 + (encoded.size() - 1) / PACK_SIZE;
int ibuf[1];
ibuf[0] = total_pack;
sock.sendTo(ibuf, sizeof(int), servAddress, 8080);

gettimeofday(&timestamp, NULL);

img_header.pack_num= total_pack;
sprintf(img_header.info, "timestamp %ld %ld\n",timestamp.tv_sec, timestamp.tv_usec);
//printf("%s",img_header.info);

sock.sendTo(&img_header, sizeof(struct header), servAddress, 8080);

//sock.sendTo(ibuf, sizeof(int), servAddress, 8080);
for (int i = 0; i < total_pack; i++) sock.sendTo( & encoded[i * PACK_SIZE], PACK_SIZE, servAddress, servPort);

waitKey(1);
Expand Down

0 comments on commit 77ff120

Please sign in to comment.