Commit 5fb9a18d authored by rna's avatar rna Committed by Andreas Schmidt

Target delay is set upon socket creation.

parent 33d2a19e
......@@ -114,7 +114,7 @@ cdef extern from "proto/socket.h":
ctypedef prrtSocket PrrtSocket
cdef PrrtSocket* PrrtSocket_create(bint isSender)
cdef PrrtSocket* PrrtSocket_create(bint isSender, const uint32_t target_delay)
bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port)
int PrrtSocket_close(const PrrtSocket *sock_ptr)
int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port)
......
......@@ -3,14 +3,14 @@
#include "../util/dbg.h"
#include "applicationConstraints.h"
PrrtApplicationConstraints *PrrtApplicationConstraints_create()
PrrtApplicationConstraints *PrrtApplicationConstraints_create(prrtTimedelta_t target_delay_us)
{
PrrtApplicationConstraints *constraints = calloc(1, sizeof(PrrtApplicationConstraints));
check_mem(constraints);
pthread_mutex_init(&constraints->lock, NULL);
constraints->targetDelay_us = 1000*1000;
constraints->targetDelay_us = target_delay_us;
constraints->queue_size = 1000;
return constraints;
......@@ -35,14 +35,6 @@ prrtTimedelta_t PrrtApplicationConstraints_get_target_delay(PrrtApplicationConst
return targetDelay;
}
bool PrrtApplicationConstraints_set_target_delay(PrrtApplicationConstraints *applicationConstraints, prrtTimedelta_t targetDelay)
{
pthread_mutex_lock(&applicationConstraints->lock);
applicationConstraints->targetDelay_us = targetDelay;
pthread_mutex_unlock(&applicationConstraints->lock);
return true;
}
uint32_t PrrtApplicationConstraints_get_app_queue_size(PrrtApplicationConstraints *applicationConstraints)
{
pthread_mutex_lock(&applicationConstraints->lock);
......
......@@ -9,11 +9,10 @@ typedef struct applicationConstraints {
pthread_mutex_t lock;
} PrrtApplicationConstraints;
PrrtApplicationConstraints *PrrtApplicationConstraints_create(void);
PrrtApplicationConstraints *PrrtApplicationConstraints_create(prrtTimedelta_t target_delay_us);
bool PrrtApplicationConstraints_destroy(PrrtApplicationConstraints *applicationConstraints);
prrtTimedelta_t PrrtApplicationConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints);
bool PrrtApplicationConstraints_set_target_delay(PrrtApplicationConstraints *applicationConstraints, prrtTimedelta_t targetDelay);
uint32_t PrrtApplicationConstraints_get_app_queue_size(PrrtApplicationConstraints *applicationConstraints);
bool PrrtApplicationConstraints_set_app_queue_size(PrrtApplicationConstraints *applicationConstraints, uint32_t size);
......
......@@ -17,7 +17,7 @@
#include "socket.h"
#include "receiver.h"
PrrtSocket *PrrtSocket_create(const bool is_sender) {
PrrtSocket *PrrtSocket_create(const bool is_sender, prrtTimedelta_t target_delay_us) {
assert(sizeof(float) == 4);
PrrtSocket *sock_ptr = (PrrtSocket *) calloc(1, sizeof(PrrtSocket));
check_mem(sock_ptr);
......@@ -35,7 +35,8 @@ PrrtSocket *PrrtSocket_create(const bool is_sender) {
sock_ptr->sequenceNumberRedundancy = 1;
sock_ptr->csi = PrrtChannelStateInformation_create();
sock_ptr->applicationConstraints = PrrtApplicationConstraints_create();
check(target_delay_us < HALF_TIMESTAMP, "Specify target delay between 0 and %i", HALF_TIMESTAMP-1)
sock_ptr->applicationConstraints = PrrtApplicationConstraints_create(target_delay_us);
sock_ptr->packetTimeoutTable = PrrtPacketTimeoutTable_create();
......@@ -365,12 +366,7 @@ uint32_t PrrtSocket_get_sock_opt(PrrtSocket *sock_ptr, const char *name) {
}
bool PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const char *name, const uint32_t value) {
if (strcmp(name, "targetdelay") == 0) {
if (value > HALF_TIMESTAMP) {
PERROR("Invalid targetdelay. Too big.")
}
PrrtApplicationConstraints_set_target_delay(sock_ptr->applicationConstraints, value);
} else if (strcmp(name, "app_queue_size")) {
if (strcmp(name, "app_queue_size")) {
PrrtApplicationConstraints_set_app_queue_size(sock_ptr->applicationConstraints, value);
Pipe_set_size(sock_ptr->sendDataQueue, value);
} else {
......
......@@ -68,7 +68,7 @@ typedef struct prrtSocket {
} PrrtSocket;
PrrtSocket *PrrtSocket_create(const bool is_sender);
PrrtSocket *PrrtSocket_create(const bool is_sender, prrtTimedelta_t target_delay_us);
bool PrrtSocket_bind(PrrtSocket *sock_ptr, const char *ipAddress, const uint16_t port);
......
......@@ -73,8 +73,9 @@ cdef class PrrtSocket:
cdef cprrt.PrrtSocket* _c_socket
cdef bint isSender
def __cinit__(self, port, isSender):
self._c_socket = cprrt.PrrtSocket_create(isSender)
def __cinit__(self, port, isSender, target_delay = 1):
target_delay_us = target_delay * 1000**2
self._c_socket = cprrt.PrrtSocket_create(isSender, target_delay_us)
cprrt.PrrtSocket_bind(self._c_socket, "0.0.0.0", port)
self.isSender = isSender
......@@ -89,12 +90,7 @@ cdef class PrrtSocket:
def __get__(self):
if not self.isSender:
raise Exception("Not a sender.")
return cprrt.PrrtSocket_get_sock_opt(self._c_socket, "targetdelay")
def __set__(self, value):
if not self.isSender:
raise Exception("Not a sender.")
cprrt.PrrtSocket_set_sock_opt(self._c_socket, "targetdelay", value)
return cprrt.PrrtSocket_get_sock_opt(self._c_socket, "targetdelay") * 0.000001
property app_queue_size:
def __get__(self):
......
......@@ -37,9 +37,9 @@ int main(int argc, char *const argv[]) {
}
#endif
sock = PrrtSocket_create(false);
check(PrrtSocket_bind(sock, "0.0.0.0", port), "bind failed");
sock = PrrtSocket_create(false, HALF_TIMESTAMP-1);
check(sock != NULL, "Could not create socket.");
check(PrrtSocket_bind(sock, "0.0.0.0", port), "bind failed");
XlapTimestampTable *tstable_data = malloc(sizeof(XlapTimestampTable));
XlapTimestampTable *tstable_redundancy = malloc(sizeof(XlapTimestampTable));
......
......@@ -31,8 +31,8 @@ int main(int argc, char *const argv[]) {
uint16_t local_port = 6000;
PrrtSocket *socket = PrrtSocket_create(true);
PrrtSocket_set_sock_opt(socket, "targetdelay", (uint32_t) 60 * 1000 * 1000);
PrrtSocket *socket = PrrtSocket_create(true, 60 * 1000 * 1000);
check(socket != NULL, "Socket create failed.");
//PrrtSocket_set_coding_parameters(socket, 1, 1); // comment this line to re-enable coding.
check(PrrtSocket_bind(socket, "0.0.0.0", local_port), "bind failed");
......
......@@ -36,8 +36,7 @@ class ReceiverThread(threading.Thread):
class SenderThread(threading.Thread):
def __init__(self, seqnoDigits, packetCount):
threading.Thread.__init__(self)
self.sock = prrt.PrrtSocket(7005, True)
self.sock.target_delay = 0.1 * 1000**2
self.sock = prrt.PrrtSocket(7005, True, 0.1)
self.packetCount = packetCount
self.seqnoDigits = seqnoDigits
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment