11#include <promeki/config.h>
19PROMEKI_NAMESPACE_BEGIN
76class SrtSocket :
public IODevice {
77 PROMEKI_OBJECT(SrtSocket, IODevice)
80 using UPtr = UniquePtr<SrtSocket>;
83 static constexpr int InvalidHandle = -1;
97 int64_t msSinceStart = 0;
103 uint64_t byteSent = 0;
105 uint64_t byteRecv = 0;
111 int pktRetransmitted = 0;
117 int pktRcvUndecrypt = 0;
121 double linkBandwidthMbps = 0.0;
123 double maxBandwidthMbps = 0.0;
125 int sendBufferBytes = 0;
127 int sendBufferMs = 0;
129 int recvBufferBytes = 0;
131 int recvBufferMs = 0;
157 SrtSocket(ObjectBase *parent =
nullptr);
171 SrtSocket(
int handle, ObjectBase *parent =
nullptr);
174 ~SrtSocket()
override;
188 Error open(OpenMode mode)
override;
194 Error close()
override;
197 bool isOpen()
const override;
211 int64_t read(
void *data, int64_t maxSize)
override;
224 int64_t write(
const void *data, int64_t maxSize)
override;
227 bool isSequential()
const override {
return true; }
240 Error bind(
const SocketAddress &address);
255 Error connectToHost(
const SocketAddress &address);
270 Error waitForConnected(
unsigned int timeoutMs = 0);
273 SocketAddress localAddress()
const {
return _localAddress; }
276 SocketAddress peerAddress()
const {
return _peerAddress; }
279 SocketState state()
const;
282 PROMEKI_SIGNAL(connected);
285 PROMEKI_SIGNAL(disconnected);
296 int handle()
const {
return _sock; }
314 int groupHandle()
const;
332 Error setLatency(
int ms);
335 int latency()
const {
return _latencyMs; }
349 Error setPayloadSize(
int bytes);
352 int payloadSize()
const {
return _payloadSize; }
359 Error setTransportType(TransportType type);
362 TransportType transportType()
const {
return _transportType; }
376 Error setPassphrase(
const String &passphrase);
379 bool hasPassphrase()
const {
return !_passphrase.isEmpty(); }
387 Error setEncryptionKeyLength(
int bytes);
390 int encryptionKeyLength()
const {
return _pbKeyLen; }
403 Error setStreamId(
const String &
id);
406 String streamId()
const;
413 Error setMaxBandwidth(int64_t bytesPerSec);
420 Error setReceiveBufferSize(
int bytes);
427 Error setSendBufferSize(
int bytes);
434 Error setReceiveTimeout(
int timeoutMs);
441 Error setSendTimeout(
int timeoutMs);
448 Error setConnectTimeout(
int timeoutMs);
464 Error setRendezvous(
bool enable);
467 bool isRendezvous()
const {
return _rendezvous; }
478 Error setNonBlocking(
bool enable);
484 String lastSrtError()
const {
return _lastError; }
502 Stats stats(
bool resetWindowed =
false)
const;
512 void updateLocalAddress();
521 void updatePeerAddress();
530 void captureLastError();
533 friend class SrtServer;
535 int _sock = InvalidHandle;
536 SocketAddress _localAddress;
537 SocketAddress _peerAddress;
541 int _latencyMs = 120;
542 int _payloadSize = 0;
544 bool _rendezvous =
false;
545 TransportType _transportType = Live;
554 Error applyPreConnectOptions();