-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathviewer_udp_ocv.cpp
More file actions
68 lines (52 loc) · 2.2 KB
/
viewer_udp_ocv.cpp
File metadata and controls
68 lines (52 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), sendto(), and recvfrom() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#include <iostream>
#include <cstdio>
#include "config.h"
#include "data_source_ocv_avcodec.h"
#include "data_source_stdio_info.h"
#include "x264_destreamer.h"
using namespace std;
static void DieWithError(const char *errorMessage)
{
printf("%s\n",errorMessage);
exit(1);
}
#define MAXRECVSTRING 2550
int main(int numArgs, const char * argv[] )
{
int sock; /* Socket */
struct sockaddr_in broadcastAddr; /* Broadcast Address */
unsigned short broadcastPort = UDP_PORT_NUMBER; /* Port */
static uint8_t recvString[MAXRECVSTRING+1]; /* Buffer for received string */
int recvStringLen; /* Length of received string */
unsigned short port = UDP_PORT_NUMBER;
if( numArgs >= 2 )
broadcastPort = atoi( argv[1] );
/* Create a best-effort datagram socket using UDP */
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
DieWithError("socket() failed");
/* Construct bind structure */
memset(&broadcastAddr, 0, sizeof(broadcastAddr)); /* Zero out structure */
broadcastAddr.sin_family = AF_INET; /* Internet address family */
broadcastAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
broadcastAddr.sin_port = htons(broadcastPort); /* Broadcast port */
/* Bind to the broadcast port */
if (bind(sock, (struct sockaddr *) &broadcastAddr, sizeof(broadcastAddr)) < 0)
DieWithError("bind() failed");
data_source_ocv_avcodec oavc("output");
while(1)
{
/* Receive a single datagram from the server */
if ((recvStringLen = recvfrom(sock, recvString, MAXRECVSTRING, 0, NULL, 0)) < 0)
DieWithError("recvfrom() failed");
printf("Received: %i bytes\n", recvStringLen); /* Print the received string */
oavc.write( recvString, recvStringLen );
}
close(sock);
exit(0);
}