Commit ba9d6c5b authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Refactoring.

parent edf0c135
...@@ -43,7 +43,7 @@ void clear_list(gf *const *src, uint8_t k) ...@@ -43,7 +43,7 @@ void clear_list(gf *const *src, uint8_t k)
} }
} }
void PrrtBlock_free(PrrtBlock *mblock) void PrrtBlock_destroy(PrrtBlock *mblock)
{ {
while(List_count(mblock->dataPackets) > 0) { while(List_count(mblock->dataPackets) > 0) {
PrrtPacket *pkt = List_shift(mblock->dataPackets); PrrtPacket *pkt = List_shift(mblock->dataPackets);
...@@ -60,7 +60,7 @@ void PrrtBlock_free(PrrtBlock *mblock) ...@@ -60,7 +60,7 @@ void PrrtBlock_free(PrrtBlock *mblock)
free(mblock); free(mblock);
} }
int PrrtBlock_alloc(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t base_seqno) int PrrtBlock_create(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t base_seqno)
{ {
mblock->codingParams = *cpar; mblock->codingParams = *cpar;
mblock->dataPackets = List_create(); mblock->dataPackets = List_create();
...@@ -186,9 +186,7 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) ...@@ -186,9 +186,7 @@ void PrrtBlock_decode(PrrtBlock *block_ptr)
PrrtCoder_decode(coder, fec, idx_p, length); PrrtCoder_decode(coder, fec, idx_p, length);
for(j = 0; j < k; j++) { for(j = 0; j < k; j++) {
PrrtPacket *packet = calloc(1, sizeof(PrrtPacket)); PrrtPacket *packet = PrrtPacket_create_data_packet(0, fec[j], length, (uint16_t) (block_ptr->baseSequenceNumber + j));
check_mem(packet);
PrrtPacket_create_data_packet(packet, 0, fec[j], length, (uint16_t) (block_ptr->baseSequenceNumber + j));
PrrtBlock_insert_data_packet(block_ptr, packet); PrrtBlock_insert_data_packet(block_ptr, packet);
} }
......
...@@ -18,12 +18,12 @@ typedef struct { ...@@ -18,12 +18,12 @@ typedef struct {
/** /**
* Allocate space for a block. * Allocate space for a block.
*/ */
int PrrtBlock_alloc(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t base_seqno); int PrrtBlock_create(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t base_seqno);
/** /**
* Frees the PrrtBlock data structure. * Frees the PrrtBlock data structure.
*/ */
void PrrtBlock_free(PrrtBlock *mblock); void PrrtBlock_destroy(PrrtBlock *mblock);
int PrrtBlock_insert_data_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket); int PrrtBlock_insert_data_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket);
int PrrtBlock_insert_redundancy_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket); int PrrtBlock_insert_redundancy_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket);
......
...@@ -15,11 +15,11 @@ void *encode_redundancy_header(void *buf_ptr, const void *payload); ...@@ -15,11 +15,11 @@ void *encode_redundancy_header(void *buf_ptr, const void *payload);
void *encode_feedback_header(void *buf_ptr, const void *payload); void *encode_feedback_header(void *buf_ptr, const void *payload);
void *decode_data_header(void *buf_ptr, const void *payload_ptr); void *decode_data_header(void *dstBuffer, const void *srcBuffer);
void *decode_redundancy_header(void *buf_ptr, const void *payload_ptr); void *decode_redundancy_header(void *dstBuffer, const void *srcBuffer);
void *decode_feedback_header(void *buf_ptr, const void *payload_ptr); void *decode_feedback_header(void *dstBuffer, const void *srcBuffer);
uint8_t PrrtPacket_type(PrrtPacket *packet_ptr) uint8_t PrrtPacket_type(PrrtPacket *packet_ptr)
{ {
...@@ -106,6 +106,23 @@ PrrtPacket *PrrtPacket_copy(PrrtPacket *original) ...@@ -106,6 +106,23 @@ PrrtPacket *PrrtPacket_copy(PrrtPacket *original)
PERROR("Not enough memory for packet copies."); PERROR("Not enough memory for packet copies.");
} }
PrrtPacket *create_header(uint8_t priority, uint16_t seqno, uint32_t size, uint8_t type, uint8_t index)
{
PrrtPacket *packet = calloc(1, sizeof(PrrtPacket));
check_mem(packet);
packet->type_priority = type << 4;
packet->type_priority |= priority & 0x0F;
packet->index = index;
packet->seqno = seqno;
packet->payload_len = size;
return packet;
error:
PERROR("Could not create packet.%s", "");
}
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
{ {
void *payload = packet_ptr->payload; void *payload = packet_ptr->payload;
...@@ -243,33 +260,33 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) ...@@ -243,33 +260,33 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet)
return buf_ptr; return buf_ptr;
} }
int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) int PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket)
{ {
uint32_t payload_len = (uint32_t) (buf_size - PRRT_PACKET_GENERAL_HEADER_SIZE); uint32_t payload_len = (uint32_t) (srcBufferSize - PRRT_PACKET_GENERAL_HEADER_SIZE);
packet_ptr->type_priority = *(uint8_t *) buf_ptr; targetPacket->type_priority = *(uint8_t *) srcBuffer;
buf_ptr += 1; srcBuffer += 1;
uint8_t *index_ptr = (uint8_t *) buf_ptr; uint8_t *index_ptr = (uint8_t *) srcBuffer;
packet_ptr->index = *index_ptr; targetPacket->index = *index_ptr;
buf_ptr += 1; srcBuffer += 1;
uint16_t *seqno_prt = (uint16_t *) buf_ptr; uint16_t *seqno_prt = (uint16_t *) srcBuffer;
packet_ptr->seqno = ntohs(*seqno_prt); targetPacket->seqno = ntohs(*seqno_prt);
buf_ptr += 2; srcBuffer += 2;
void *payload_buffer = calloc(1, payload_len); void *payload_buffer = calloc(1, payload_len);
check_mem(payload_buffer); check_mem(payload_buffer);
packet_ptr->payload = payload_buffer; targetPacket->payload = payload_buffer;
packet_ptr->payload_len = payload_len; targetPacket->payload_len = payload_len;
if(PrrtPacket_type(packet_ptr) == PACKET_TYPE_DATA) { if(PrrtPacket_type(targetPacket) == PACKET_TYPE_DATA) {
buf_ptr = decode_data_header(buf_ptr, payload_buffer); srcBuffer = decode_data_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(packet_ptr, buf_ptr, PRRT_PACKET_DATA_HEADER_SIZE); PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_DATA_HEADER_SIZE);
} else if(PrrtPacket_type(packet_ptr)) { } else if(PrrtPacket_type(targetPacket)) {
buf_ptr = decode_redundancy_header(buf_ptr, payload_buffer); srcBuffer = decode_redundancy_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(packet_ptr, buf_ptr, PRRT_PACKET_REDUNDANCY_HEADER_SIZE); PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if(PrrtPacket_type(packet_ptr) == PACKET_TYPE_FEEDBACK) { } else if(PrrtPacket_type(targetPacket) == PACKET_TYPE_FEEDBACK) {
buf_ptr = decode_feedback_header(buf_ptr, payload_buffer); srcBuffer = decode_feedback_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(packet_ptr, buf_ptr, PRRT_PACKET_FEEDBACK_HEADER_SIZE); PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_FEEDBACK_HEADER_SIZE);
} else { } else {
printf("NOT IMPLEMENTED\n"); printf("NOT IMPLEMENTED\n");
} }
...@@ -279,203 +296,181 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) ...@@ -279,203 +296,181 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
void *decode_redundancy_header(void *buf_ptr, const void *payload_ptr) void *decode_redundancy_header(void *dstBuffer, const void *srcBuffer)
{ {
PrrtPacketRedundancyPayload *redundancyPayload = (PrrtPacketRedundancyPayload *) payload_ptr; PrrtPacketRedundancyPayload *redundancyPayload = (PrrtPacketRedundancyPayload *) srcBuffer;
uint16_t *baseSeqNo = (uint16_t *) buf_ptr; uint16_t *baseSeqNo = (uint16_t *) dstBuffer;
redundancyPayload->base_seqno = ntohs(*baseSeqNo); redundancyPayload->base_seqno = ntohs(*baseSeqNo);
buf_ptr += 2; dstBuffer += 2;
uint8_t *n = (uint8_t *) buf_ptr; uint8_t *n = (uint8_t *) dstBuffer;
redundancyPayload->n = *n; redundancyPayload->n = *n;
buf_ptr += 1; dstBuffer += 1;
uint8_t *k = (uint8_t *) buf_ptr; uint8_t *k = (uint8_t *) dstBuffer;
redundancyPayload->k = *k; redundancyPayload->k = *k;
buf_ptr += 1; dstBuffer += 1;
return buf_ptr; return dstBuffer;
} }
void *decode_feedback_header(void *buf_ptr, const void *payload_ptr) void *decode_feedback_header(void *dstBuffer, const void *srcBuffer)
{ {
PrrtPacketFeedbackPayload *feedback_payload = (PrrtPacketFeedbackPayload *) payload_ptr; PrrtPacketFeedbackPayload *feedback_payload = (PrrtPacketFeedbackPayload *) srcBuffer;
uint32_t *receiver_addr = (uint32_t *) buf_ptr; uint32_t *receiverAddr = (uint32_t *) dstBuffer;
feedback_payload->receiver_addr = ntohl(*receiver_addr); feedback_payload->receiver_addr = ntohl(*receiverAddr);
buf_ptr += 4; dstBuffer += 4;
uint32_t *group_round_trip_time = (uint32_t *) buf_ptr; uint32_t *groupRoundTripTime = (uint32_t *) dstBuffer;
feedback_payload->group_round_trip_time = ntohl(*group_round_trip_time); feedback_payload->group_round_trip_time = ntohl(*groupRoundTripTime);
buf_ptr += 4; dstBuffer += 4;
uint32_t *forward_trip_time = (uint32_t *) buf_ptr; uint32_t *forwardTripTime = (uint32_t *) dstBuffer;
feedback_payload->forward_trip_time = ntohl(*forward_trip_time); feedback_payload->forward_trip_time = ntohl(*forwardTripTime);
buf_ptr += 4; dstBuffer += 4;
uint32_t *packet_loss_rate = (uint32_t *) buf_ptr; uint32_t *packetLossRate = (uint32_t *) dstBuffer;
feedback_payload->packet_loss_rate = ntohl(*packet_loss_rate); feedback_payload->packet_loss_rate = ntohl(*packetLossRate);
buf_ptr += 4; dstBuffer += 4;
uint16_t *gap = (uint16_t *) buf_ptr; uint16_t *gap = (uint16_t *) dstBuffer;
feedback_payload->gap = ntohs(*gap); feedback_payload->gap = ntohs(*gap);
buf_ptr += 2; dstBuffer += 2;
uint16_t *ngap = (uint16_t *) buf_ptr; uint16_t *ngap = (uint16_t *) dstBuffer;
feedback_payload->ngap = ntohs(*ngap); feedback_payload->ngap = ntohs(*ngap);
buf_ptr += 2; dstBuffer += 2;
uint16_t *burst = (uint16_t *) buf_ptr; uint16_t *burst = (uint16_t *) dstBuffer;
feedback_payload->burst = ntohs(*burst); feedback_payload->burst = ntohs(*burst);
buf_ptr += 2; dstBuffer += 2;
uint16_t *nburst = (uint16_t *) buf_ptr; uint16_t *nburst = (uint16_t *) dstBuffer;
feedback_payload->nburst = ntohs(*nburst); feedback_payload->nburst = ntohs(*nburst);
buf_ptr += 2; dstBuffer += 2;
uint32_t *bandwidth_estimate = (uint32_t *) buf_ptr; uint32_t *bandwidthEstimate = (uint32_t *) dstBuffer;
feedback_payload->bandwidth_estimate = ntohl(*bandwidth_estimate); feedback_payload->bandwidth_estimate = ntohl(*bandwidthEstimate);
buf_ptr += 4; dstBuffer += 4;
uint32_t *buffer_feedback = (uint32_t *) buf_ptr; uint32_t *bufferFeedback = (uint32_t *) dstBuffer;
feedback_payload->buffer_feedback = ntohl(*buffer_feedback); feedback_payload->buffer_feedback = ntohl(*bufferFeedback);
buf_ptr += 4; dstBuffer += 4;
return buf_ptr; return dstBuffer;
} }
void *decode_data_header(void *buf_ptr, const void *payload_ptr) void *decode_data_header(void *dstBuffer, const void *srcBuffer)
{ {
PrrtPacketDataPayload *data_payload = (PrrtPacketDataPayload *) payload_ptr; PrrtPacketDataPayload *data_payload = (PrrtPacketDataPayload *) srcBuffer;
uint32_t *timestamp = (uint32_t *) buf_ptr; uint32_t *timestamp = (uint32_t *) dstBuffer;
data_payload->timestamp = ntohl(*timestamp); data_payload->timestamp = ntohl(*timestamp);
buf_ptr += 4; dstBuffer += 4;
uint16_t *group_round_trip_time = (uint16_t *) buf_ptr; uint16_t *group_round_trip_time = (uint16_t *) dstBuffer;
data_payload->group_round_trip_time = ntohs(*group_round_trip_time); data_payload->group_round_trip_time = ntohs(*group_round_trip_time);
buf_ptr += 2; dstBuffer += 2;
uint16_t *packet_timeout = (uint16_t *) buf_ptr; uint16_t *packet_timeout = (uint16_t *) dstBuffer;
data_payload->packet_timeout = ntohs(*packet_timeout); data_payload->packet_timeout = ntohs(*packet_timeout);
buf_ptr += 2; dstBuffer += 2;
uint16_t *decoding_timeout = (uint16_t *) buf_ptr; uint16_t *decoding_timeout = (uint16_t *) dstBuffer;
data_payload->decoding_timeout = ntohs(*decoding_timeout); data_payload->decoding_timeout = ntohs(*decoding_timeout);
buf_ptr += 2; dstBuffer += 2;
uint16_t *feedback_timeout = (uint16_t *) buf_ptr; uint16_t *feedback_timeout = (uint16_t *) dstBuffer;
data_payload->feedback_timeout = ntohs(*feedback_timeout); data_payload->feedback_timeout = ntohs(*feedback_timeout);
buf_ptr += 2; dstBuffer += 2;
return buf_ptr; return dstBuffer;
} }
int PrrtPacket_destroy(PrrtPacket *packet_ptr) int PrrtPacket_destroy(PrrtPacket *packet)
{ {
if(packet_ptr->payload != NULL) { if(packet->payload != NULL) {
free(packet_ptr->payload); free(packet->payload);
} }
free(packet_ptr); free(packet);
return 0; return 0;
} }
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr, PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer, uint32_t payloadLength,
uint32_t data_len, uint16_t seqno) uint16_t sequenceNumber)
{ {
uint32_t payload_length = (uint32_t) (data_len + PRRT_PACKET_DATA_HEADER_SIZE); PrrtPacket *packet = create_header(priority, sequenceNumber,
(uint32_t) (payloadLength + PRRT_PACKET_DATA_HEADER_SIZE), PACKET_TYPE_DATA, 0);
packet_ptr->type_priority = PACKET_TYPE_DATA << 4;
packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = 0;
packet_ptr->seqno = seqno;
void *content_buf = calloc(1, payload_length); PrrtPacketDataPayload *dataPayload = calloc(1, packet->payload_len);
check_mem(content_buf); check_mem(dataPayload);
packet->payload = dataPayload;
PrrtPacketDataPayload *source_payload = content_buf;
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
unsigned long time_in_micros = (unsigned long) (1000000 * tv.tv_sec + tv.tv_usec); unsigned long time_in_micros = (unsigned long) (1000000 * tv.tv_sec + tv.tv_usec);
source_payload->timestamp = (uint32_t) time_in_micros; dataPayload->timestamp = (uint32_t) time_in_micros;
source_payload->group_round_trip_time = 95; // TODO: payload->rtt = CURRENT ESTIMATE dataPayload->group_round_trip_time = 95; // TODO: payload->rtt = CURRENT ESTIMATE
source_payload->packet_timeout = 110; // TODO: payload->packet_timeout = NOW + maximum delay dataPayload->packet_timeout = 110; // TODO: payload->packet_timeout = NOW + maximum delay
source_payload->decoding_timeout = 150; // TODO: payload->decoding_timeout dataPayload->decoding_timeout = 150; // TODO: payload->decoding_timeout
source_payload->feedback_timeout = 170; // TODO: payload->feedback_timer dataPayload->feedback_timeout = 170; // TODO: payload->feedback_timer
PrrtPacket_copy_buffer_to_payload(packet, payloadPointer, PRRT_PACKET_DATA_HEADER_SIZE)
packet_ptr->payload = content_buf; return packet;
packet_ptr->payload_len = payload_length;
PrrtPacket_copy_buffer_to_payload(packet_ptr, data_ptr, PRRT_PACKET_DATA_HEADER_SIZE)
error: error:
return -1; PERROR("Could not create packet.");
} }
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t data_len, PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadPointer, uint32_t payloadLength,
uint16_t seqno, uint8_t index, uint16_t base_seqno, uint16_t sequenceNumber, uint8_t index, uint16_t baseSequenceNumber,
PrrtCodingParams codingParams) PrrtCodingParams codingParams)
{ {
uint32_t payload_length = (uint32_t) (data_len + PRRT_PACKET_REDUNDANCY_HEADER_SIZE); PrrtPacket *packet = create_header(priority, sequenceNumber,
(uint32_t) (payloadLength + PRRT_PACKET_REDUNDANCY_HEADER_SIZE),
PrrtPacket *packet_ptr = calloc(1, sizeof(PrrtPacket)); PACKET_TYPE_REDUNDANCY, index);
check_mem(packet_ptr);
packet_ptr->type_priority = PACKET_TYPE_REDUNDANCY << 4;
packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = index;
packet_ptr->seqno = seqno;
void *content_buf = calloc(1, PRRT_PACKET_REDUNDANCY_HEADER_SIZE + data_len); PrrtPacketRedundancyPayload *redundancyPayload = calloc(1, packet->payload_len);
check_mem(content_buf); check_mem(redundancyPayload);
packet->payload = redundancyPayload;
PrrtPacketRedundancyPayload *redundancy_payload = content_buf; redundancyPayload->base_seqno = baseSequenceNumber;
redundancyPayload->k = codingParams.k;
redundancyPayload->n = codingParams.n;
PrrtPacket_copy_buffer_to_payload(packet, payloadPointer, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
redundancy_payload->base_seqno = base_seqno; return packet;
redundancy_payload->k = codingParams.k;
redundancy_payload->n = codingParams.n;
packet_ptr->payload = content_buf;
packet_ptr->payload_len = payload_length;
PrrtPacket_copy_buffer_to_payload(packet_ptr, data_ptr, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
return packet_ptr;
error: error:
return NULL; return NULL;
} }
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time, PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t sequenceNumber,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap, uint32_t roundTripTime, uint32_t forwardTripTime, uint32_t packetLossRate,
uint16_t ngap, uint16_t gap, uint16_t ngap, uint16_t burst, uint16_t nburst,
uint16_t burst, uint16_t nburst, uint32_t bandwidth, uint32_t bandwidth, uint32_t bufferFeedback)
uint32_t buffer_feedback)
{ {
PrrtPacket *packet_ptr = calloc(1, sizeof(PrrtPacket)); PrrtPacket *packet = create_header(priority, sequenceNumber, PRRT_PACKET_FEEDBACK_HEADER_SIZE, PACKET_TYPE_FEEDBACK,
check_mem(packet_ptr); index);
packet_ptr->type_priority = PACKET_TYPE_FEEDBACK << 4;
packet_ptr->type_priority |= priority & 0x0F; PrrtPacketFeedbackPayload *payload = calloc(1, packet->payload_len);
packet_ptr->index = index;
packet_ptr->seqno = seqno;
PrrtPacketFeedbackPayload *payload = calloc(1, PRRT_PACKET_FEEDBACK_HEADER_SIZE);
check_mem(payload); check_mem(payload);
packet->payload = payload;
payload->group_round_trip_time = round_trip_time; payload->group_round_trip_time = roundTripTime;
payload->forward_trip_time = forward_trip_time; payload->forward_trip_time = forwardTripTime;
payload->packet_loss_rate = packet_loss_rate; payload->packet_loss_rate = packetLossRate;
payload->gap = gap; payload->gap = gap;
payload->ngap = ngap; payload->ngap = ngap;
payload->burst = burst; payload->burst = burst;
payload->nburst = nburst; payload->nburst = nburst;
payload->bandwidth_estimate = bandwidth; payload->bandwidth_estimate = bandwidth;
payload->buffer_feedback = buffer_feedback; payload->buffer_feedback = bufferFeedback;
packet_ptr->payload = (void *) payload;
packet_ptr->payload_len = (uint32_t) (PRRT_PACKET_FEEDBACK_HEADER_SIZE);
return packet_ptr; return packet;
error: error:
return NULL; return NULL;
......
...@@ -63,20 +63,19 @@ uint16_t PrrtPacket_size(PrrtPacket *packet_ptr); ...@@ -63,20 +63,19 @@ uint16_t PrrtPacket_size(PrrtPacket *packet_ptr);
int PrrtPacket_print(PrrtPacket *packet_ptr); int PrrtPacket_print(PrrtPacket *packet_ptr);
PrrtPacket *PrrtPacket_copy(PrrtPacket *original); PrrtPacket *PrrtPacket_copy(PrrtPacket *original);
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr, PrrtPacket * PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer, uint32_t payloadLength, uint16_t sequenceNumber);
uint32_t data_len, uint16_t seqno);
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time, PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t sequenceNumber, uint32_t roundTripTime,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap, uint32_t forwardTripTime, uint32_t packetLossRate, uint16_t gap,
uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth, uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback); uint32_t bufferFeedback);
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t data_len, PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadPointer, uint32_t payloadLength,
uint16_t seqno, uint8_t index, uint16_t base_seqno, PrrtCodingParams codingParams); uint16_t sequenceNumber, uint8_t index, uint16_t baseSequenceNumber, PrrtCodingParams codingParams);
int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr); int PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr); int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet_ptr); int PrrtPacket_destroy(PrrtPacket *packet);
#define PrrtPacket_copy_payload_to_buffer(dst, packet, header_size) memcpy(dst, packet->payload + header_size, packet->payload_len - header_size); #define PrrtPacket_copy_payload_to_buffer(dst, packet, header_size) memcpy(dst, packet->payload + header_size, packet->payload_len - header_size);
#define PrrtPacket_copy_buffer_to_payload(packet, src, header_size) memcpy(packet->payload + header_size, src, packet->payload_len - header_size); #define PrrtPacket_copy_buffer_to_payload(packet, src, header_size) memcpy(packet->payload + header_size, src, packet->payload_len - header_size);
......
...@@ -43,7 +43,7 @@ void decode_block(PrrtSocket *sock_ptr, uint16_t base_seqno) ...@@ -43,7 +43,7 @@ void decode_block(PrrtSocket *sock_ptr, uint16_t base_seqno)
} }
} }
PrrtBlock_free(block); PrrtBlock_destroy(block);
sock_ptr->blockStore = BPTree_delete(sock_ptr->blockStore, base_seqno); sock_ptr->blockStore = BPTree_delete(sock_ptr->blockStore, base_seqno);
} }
...@@ -142,7 +142,7 @@ void *receive_data_loop(void *ptr) ...@@ -142,7 +142,7 @@ void *receive_data_loop(void *ptr)
block = calloc(1, sizeof(PrrtBlock)); block = calloc(1, sizeof(PrrtBlock));
check_mem(block); check_mem(block);
PrrtBlock_alloc(block, cpar, redundancyPayload->base_seqno); PrrtBlock_create(block, cpar, redundancyPayload->base_seqno);
free(cpar); free(cpar);
sock_ptr->blockStore = BPTree_insert(sock_ptr->blockStore, redundancyPayload->base_seqno, sock_ptr->blockStore = BPTree_insert(sock_ptr->blockStore, redundancyPayload->base_seqno,
block); block);
......
...@@ -57,7 +57,9 @@ void * send_data_loop(void *ptr) { ...@@ -57,7 +57,9 @@ void * send_data_loop(void *ptr) {
pthread_mutex_lock(&sock_ptr->closingMutex); pthread_mutex_lock(&sock_ptr->closingMutex);
if(sock_ptr->closing) { if(sock_ptr->closing) {
free(cpar); free(cpar);
PrrtBlock_free(block); if(block != NULL) {
PrrtBlock_destroy(