rist_receiver_data_read uses 100% of a core when no peers are configured or when a single peer is added and the return value of the API is not checked for errors
Using librist compiled from: cce678e, on Centos 7
Following the example of mpeg2rist, rist-utils, I have implemented a receiver using the rist_receiver_data_read function in a while loop but found it to be very cpu heavy. It maxes out a core no matter whether it is receiving data or not.
Unfortunately I can't use rist_receiver_data_callback_set instead because of project specific constraints.
The following can be used to produce this result:
#include <stdio.h>
#include <unistd.h>
#include <librist.h>
struct rist_receiver *recvCtx;
static int recvAuthCon(void *arg, const char* connecting_ip, uint16_t connecting_port, const char* local_ip, uint16_t local_port, struct rist_peer *peer) {
struct rist_receiver *ctx = (struct rist_receiver *)arg;
char message[500];
int ret = snprintf(message, 500, "auth,%s:%d,%s:%d", connecting_ip, connecting_port, local_ip, local_port);
struct rist_oob_block oob_block;
oob_block.peer = peer;
oob_block.payload = message;
oob_block.payload_len = ret;
rist_receiver_oob_write(ctx, &oob_block);
return 0;
}
static int recvAuthDisc(void *arg, struct rist_peer *peer) {
struct rist_receiver *ctx = (struct rist_receiver *)arg;
(void)ctx;
return 0;
}
static int recvOOBRec(void *arg, const struct rist_oob_block *oob_block) { return 0; }
void main() {
rist_receiver_create(&recvCtx, 1, RIST_LOG_DEBUG);
rist_receiver_auth_handler_set(recvCtx, recvAuthCon, recvAuthDisc, recvCtx);
rist_receiver_oob_callback_set(recvCtx, recvOOBRec, recvCtx);
rist_receiver_nack_type_set(recvCtx, RIST_NACK_RANGE);
const struct rist_peer_config tmp_peer_config = {
.version = RIST_PEER_CONFIG_VERSION,
.virt_dst_port = RIST_DEFAULT_VIRT_DST_PORT,
.recovery_mode = 0,
.recovery_maxbitrate = RIST_DEFAULT_RECOVERY_MAXBITRATE,
.recovery_maxbitrate_return = RIST_DEFAULT_RECOVERY_MAXBITRATE_RETURN,
.recovery_length_min = RIST_DEFAULT_RECOVERY_LENGHT_MIN,
.recovery_length_max = RIST_DEFAULT_RECOVERY_LENGHT_MAX,
.recovery_reorder_buffer = RIST_DEFAULT_RECOVERY_REORDER_BUFFER,
.recovery_rtt_min = RIST_DEFAULT_RECOVERY_RTT_MIN,
.recovery_rtt_max = RIST_DEFAULT_RECOVERY_RTT_MAX,
.weight = 0,
.buffer_bloat_mode = RIST_DEFAULT_BUFFER_BLOAT_MODE,
.buffer_bloat_limit = RIST_DEFAULT_BUFFER_BLOAT_LIMIT,
.buffer_bloat_hard_limit = RIST_DEFAULT_BUFFER_BLOAT_HARD_LIMIT,
.key_size = 128
};
const struct rist_peer_config *peer_config = &tmp_peer_config;
char *address = "rist://0.0.0.0:6000";
rist_parse_address(address, &peer_config);
struct rist_peer *peer;
rist_receiver_peer_create(recvCtx, &peer, peer_config);
rist_receiver_start(recvCtx);
for(;;) {
const struct rist_data_block *block;
rist_receiver_data_read(recvCtx, &block, 5);
if (block && block->payload) {
// Use payload
}
}
}
Edited by Sergio Ammirata