libvisiontransfer
7.1.0
|
Class for synchronous transfer of image pairs. More...
#include <visiontransfer/imagetransfer.h>
Classes | |
class | Pimpl |
Public Types | |
enum | TransferStatus { ALL_TRANSFERRED, PARTIAL_TRANSFER, NO_VALID_DATA, WOULD_BLOCK, NOT_CONNECTED } |
The result of a partial image transfer. More... | |
Public Member Functions | |
ImageTransfer (const char *address, const char *service="7681", ImageProtocol::ProtocolType protType=ImageProtocol::PROTOCOL_UDP, bool server=false, int bufferSize=1048576, int maxUdpPacketSize=1472) | |
Creates a new transfer object by manually specifying the target address. More... | |
ImageTransfer (const DeviceInfo &device, int bufferSize=1048576, int maxUdpPacketSize=1472) | |
Creates a new transfer object by using the device information from device enumeration. More... | |
void | setRawTransferData (const ImagePair &metaData, unsigned char *rawData, int firstTileWidth=0, int secondTileWidth=0, int validBytes=0x7FFFFFFF) |
Sets the raw pixel data for a partial image transmission. More... | |
void | setRawValidBytes (int validBytes) |
Updates the number of valid bytes in a partial raw transmission. More... | |
void | setTransferImagePair (const ImagePair &imagePair) |
Sets a new image pair that shall be transmitted. More... | |
TransferStatus | transferData () |
Performs a partial (or full) image transmission. More... | |
bool | receiveImagePair (ImagePair &imagePair) |
Waits for and receives a new image pair. More... | |
bool | receivePartialImagePair (ImagePair &imagePair, int &validRows, bool &complete) |
Returns the received image pair, even if it is not yet complete. More... | |
int | getNumDroppedFrames () const |
Returns the number of frames that have been dropped since connecting to the current remote host. More... | |
bool | tryAccept () |
Tries to accept a client connection. More... | |
bool | isConnected () const |
Returns true if a remote connection is established. More... | |
void | disconnect () |
Terminates the current connection. More... | |
std::string | getRemoteAddress () const |
Returns the address of the remote host. More... | |
Class for synchronous transfer of image pairs.
This class opens a network socket for delivering or receiving image pairs. All operations are performed synchronously, which means that they might block. The class encapsulates ImageProtocol.
This class is thread safe for as long as sending and receiving data each has its dedicated thread.
Definition at line 36 of file imagetransfer.h.
The result of a partial image transfer.
Definition at line 39 of file imagetransfer.h.
visiontransfer::ImageTransfer::ImageTransfer | ( | const char * | address, |
const char * | service = "7681" , |
||
ImageProtocol::ProtocolType | protType = ImageProtocol::PROTOCOL_UDP , |
||
bool | server = false , |
||
int | bufferSize = 1048576 , |
||
int | maxUdpPacketSize = 1472 |
||
) |
Creates a new transfer object by manually specifying the target address.
address | Address of the remote host to which a connection should be established. In server mode this can be a local interface address or NULL. |
service | The port number that should be used as string or as textual service name. |
protType | Specifies whether the UDP or TCP transport protocol shall be used. |
server | If set to true, this object will be a communication server. |
bufferSize | Buffer size for sending / receiving network data. |
maxUdpPacketSize | Maximum allowed size of a UDP packet when sending data. |
Definition at line 99 of file imagetransfer.cpp.
visiontransfer::ImageTransfer::ImageTransfer | ( | const DeviceInfo & | device, |
int | bufferSize = 1048576 , |
||
int | maxUdpPacketSize = 1472 |
||
) |
Creates a new transfer object by using the device information from device enumeration.
device | Information on the device to which a connection should be established. |
bufferSize | Buffer size for sending / receiving network data. |
maxUdpPacketSize | Maximum allowed size of a UDP packet when sending data. |
Definition at line 105 of file imagetransfer.cpp.
void visiontransfer::ImageTransfer::disconnect | ( | ) |
Terminates the current connection.
If connected to a remote host this connection will be closed.
Definition at line 148 of file imagetransfer.cpp.
int visiontransfer::ImageTransfer::getNumDroppedFrames | ( | ) | const |
Returns the number of frames that have been dropped since connecting to the current remote host.
Dropped frames are caused by dropped packets due to a poor network connection
Definition at line 140 of file imagetransfer.cpp.
std::string visiontransfer::ImageTransfer::getRemoteAddress | ( | ) | const |
Returns the address of the remote host.
Definition at line 152 of file imagetransfer.cpp.
bool visiontransfer::ImageTransfer::isConnected | ( | ) | const |
Returns true if a remote connection is established.
Definition at line 144 of file imagetransfer.cpp.
bool visiontransfer::ImageTransfer::receiveImagePair | ( | ImagePair & | imagePair | ) |
Waits for and receives a new image pair.
imagePair | Will be set to the received image pair. |
The received image pair is only valid until the next call of receiveImagePair(). The method will not block indefinitely, but return after a short timeout.
Definition at line 132 of file imagetransfer.cpp.
bool visiontransfer::ImageTransfer::receivePartialImagePair | ( | ImagePair & | imagePair, |
int & | validRows, | ||
bool & | complete | ||
) |
Returns the received image pair, even if it is not yet complete.
The received image pair is only valid until calling receivePartialImagePair() for the first time after the current image pair has been received completely. The method returns false if no image data has been received.
Please see ImageProtocol::getPartiallyReceivedImagePair() for further details.
Definition at line 136 of file imagetransfer.cpp.
void visiontransfer::ImageTransfer::setRawTransferData | ( | const ImagePair & | metaData, |
unsigned char * | rawData, | ||
int | firstTileWidth = 0 , |
||
int | secondTileWidth = 0 , |
||
int | validBytes = 0x7FFFFFFF |
||
) |
Sets the raw pixel data for a partial image transmission.
This method has to be used in conjunction with transferData(). Please see ImageProtocol::setRawTransferData() for further details.
Definition at line 115 of file imagetransfer.cpp.
void visiontransfer::ImageTransfer::setRawValidBytes | ( | int | validBytes | ) |
Updates the number of valid bytes in a partial raw transmission.
Please see ImageProtocol::setRawValidBytes() for further details.
Definition at line 120 of file imagetransfer.cpp.
void visiontransfer::ImageTransfer::setTransferImagePair | ( | const ImagePair & | imagePair | ) |
Sets a new image pair that shall be transmitted.
imagePair | The image pair that shall be transmitted. |
After setting the image pair, subsequent calls to transferData() are necessary for performing the image transmission.
Definition at line 124 of file imagetransfer.cpp.
ImageTransfer::TransferStatus visiontransfer::ImageTransfer::transferData | ( | ) |
Performs a partial (or full) image transmission.
The method transfers up to the specified number of valid bytes. It has to be called in cycles in order to transfer a full image pair. If there is no more data to be transferred, it will return TransferStatus::NO_VALID_DATA.
If the transfer is compete, the method will return TransferStatus::ALL_TRANSFERRED. If there remains outstanding data for this transfer, the return value will be TransferStatus::PARTIAL_TRANSFER. If the connection is no longer open, TransferStatus::CONNECTION_CLOSED is returned.
Even after a complete transfer this method should be continued to be called in case a packed needs to be retransmitted due to an unreliable network connection. Also for a communication server this method should be called frequently to accept incoming connections.
Definition at line 128 of file imagetransfer.cpp.
bool visiontransfer::ImageTransfer::tryAccept | ( | ) |
Tries to accept a client connection.
This method can only be used in TCP server mode. It shall be called in regular intervals to allow for client connections. The method is always non-blocking.
Definition at line 156 of file imagetransfer.cpp.