forked from shks/ofkTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofkUDPjpegReceiver.cpp
executable file
·63 lines (50 loc) · 1.45 KB
/
ofkUDPjpegReceiver.cpp
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
//
// ofkUDPjpegReceiver.cpp
//
// Created by Shunichi Kasahara on 11/23/12.
//
//
#include "ofkUDPjpegReceiver.h"
#define DEF_BUFSIZE (9216 * 4)
ofkUDPjpegReceiver::ofkUDPjpegReceiver():
mBufferSize(DEF_BUFSIZE)
{
}
void ofkUDPjpegReceiver::init(int port, int BufferSize)
{
udpConnect.Create(); // UDPソケットの作成
udpConnect.Bind(port); // ポート番号にバインドする
udpConnect.SetNonBlocking(true); // ノンブロッキングモードにする
udpConnect.SetReceiveBufferSize(BufferSize);
mBufferSize = BufferSize;
enable();
}
void ofkUDPjpegReceiver::update(ofEventArgs & args)
{
//2013.03.06 modify
//char revBuffer[mBufferSize];
char *revBuffer = new char[mBufferSize];
int ret = udpConnect.Receive(revBuffer,mBufferSize);
char address[255];
udpConnect.GetRemoteAddr(address);
string ip_String;
ip_String = address;
//CHECK THIS
if(ret != -1)
{
//Read Buffer
jpegVideoBuffer.set(revBuffer, mBufferSize);
//decode from Buffer into Jpeg
ofkPixelsWithIP decodedPix;
if( ofLoadImage(decodedPix, jpegVideoBuffer))
{
//decodedvideoImage.setFromPixels(re_pix);
decodedPix.IP = ip_String;
ofNotifyEvent(newReceivedPixelEvent,decodedPix,this);
}else
{
ofLog(OF_LOG_NOTICE, "Can not load from Buffer" + ofToString(ret));
}
}
delete[] revBuffer;
}