forked from thefangbear/libUDPStreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Library.h
92 lines (80 loc) · 2.41 KB
/
Library.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Created by Alex Fang on 2/20/17.
* Copyright (c) 2017 Conceptual Inertia, Inc. All rights reserved.
*
* License included in project root folder.
* Legal Contact: Conceptual-Inertia@magikpns.com
*/
#ifndef UDPSTREAMER_H
#define UDPSTREAMER_H
//========= INCLUDE ==============
#include "opencv2/opencv.hpp"
#include "PracticalSocket.h" // For UDPSocket and SocketException
#include "java/in_derros_jni_UDPStreamer.h"
#include <iostream> // For cout and cerr
#include <cstdlib> // For atoi()
//========= CONFIG ===============
#define FRAME_HEIGHT 720
#define FRAME_WIDTH 1280
#define FRAME_INTERVAL (1000/30)
#define PACK_SIZE 4096 //udp pack size; note that OSX limits < 8100 bytes
#define ENCODE_QUALITY 80
//========= NETWRK ===============
#define SERVER_PORT "1111"
#define CLIENT_PORT "33840"
#define SHORT_SERVER_PORT 1111
#define SHORT_CLIENT_PORT 88
#define SERVER_ADDRESS "192.168.1.213"
//#define SERVER_ADDRESS "localhost"
#define CAMERA_NUMBER 0
#define BUF_LEN 65540 // Larger than maximum UDP packet size
enum {
// default settings
eDefaultCameraNumber = 0,
eDefaultFrameWidth = 1280,
eDefaultFrameHeight = 720,
ePacketSize = 4096,
eEncodeQuality = 80,
eBufferLength = 65540
};
void initialize(int);
class Server {
public:
Server(unsigned short);
~Server();
cv::Mat Receive();
void Show(cv::Mat& m);
void ShowReceiveBlocking();
void WriteStreamedFrame(std::string path);
void ShowAndWrite(std::string path);
void Close();
private:
char buffer[ BUF_LEN ]; // Buffer for echo string
int recvMsgSize; // Size of received message
unsigned short serverPort; // Port of datagram source
UDPSocket serverSocket;
};
class Client {
public:
Client(std::string, unsigned short, int, int, int, int);
~Client();
cv::Mat Send();
vector<unsigned char> Send(cv::Mat& m);
void Send(vector<unsigned char>& m);
cv::Mat Capture();
void Write(std::string, cv::Mat& frame);
void Write(string path, vector<unsigned char> v);
void WriteAndSend(std::string, cv::Mat& frame);
void WriteAndSend(string path, vector<unsigned char> v);
void Close();
private:
std::string destAddr;
unsigned short destPort;
UDPSocket clientSocket;
cv::VideoCapture v;
int imageQuality;
int imageW;
int imageH;
std::vector<unsigned char> compress(cv::Mat m);
};
#endif // UDPSTREAMER_H