Skip to content

Commit

Permalink
Implement resolution degrade when network quality decreases
Browse files Browse the repository at this point in the history
  • Loading branch information
z-dule committed Jan 27, 2025
1 parent b8e08cb commit 955b932
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
51 changes: 45 additions & 6 deletions src/ccall/ccall.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static void destructor(void *arg)

list_flush(&ccall->sftl);
list_flush(&ccall->saved_partl);
list_flush(&ccall->videol);

mbuf_reset(&ccall->confpart_data);
}
Expand Down Expand Up @@ -1084,6 +1085,7 @@ static void ecall_quality_handler(struct icall *icall,
{
struct ccall *ccall = arg;
uint64_t tdiff;
bool dec_res = false;

if (!icall || !ccall)
return;
Expand All @@ -1092,15 +1094,43 @@ static void ecall_quality_handler(struct icall *icall,
return;

tdiff = tmr_jiffies() - ccall->last_ping;
if (ccall->expected_ping >= CCALL_QUALITY_POOR_MISSING)
downloss = 30;
else if (ccall->expected_ping > CCALL_QUALITY_MEDIUM_MISSING)
downloss = 10;

info("ccall(%p): ecall_quality_handler rtt=%d up=%d dn=%d "
"ping=%u pdiff=%llu\n",
ccall, rtt, uploss, downloss, ccall->expected_ping, tdiff);


if (downloss > 20) {
dec_res = true;
}
if (ccall->expected_ping >= CCALL_QUALITY_POOR_MISSING) {
dec_res = true;
downloss = 30;
}
else if (ccall->expected_ping > CCALL_QUALITY_MEDIUM_MISSING) {
dec_res = true;
downloss = 10;
}

if (dec_res) {
struct le *le;
bool update = false;

LIST_FOREACH(&ccall->videol, le) {
struct icall_client *cli = le->data;

if (cli->quality >= CCALL_RESOLUTION_HIGH) {
cli->quality = CCALL_RESOLUTION_LOW;
update = true;
}
}

if (update) {
ccall_request_video_streams((struct icall *)ccall,
&ccall->videol,
0);
}
}

ICALL_CALL_CB(ccall->icall, qualityh,
&ccall->icall,
userid,
Expand Down Expand Up @@ -1280,13 +1310,16 @@ int ccall_request_video_streams(struct icall *icall,
goto out;
}

list_flush(&ccall->videol);
str_dup(&msg->u.confstreams.mode, "list");
LIST_FOREACH(clientl, le) {
struct icall_client *cli = le->data;
struct userinfo *user;
uint32_t quality = (uint32_t)cli->quality;
struct icall_client *vinfo;

user = userlist_find_by_real(ccall->userl, cli->userid, cli->clientid);
user = userlist_find_by_real(ccall->userl,
cli->userid, cli->clientid);
if (user) {

sinfo = econn_stream_info_alloc(user->userid_hash, quality);
Expand All @@ -1296,6 +1329,12 @@ int ccall_request_video_streams(struct icall *icall,
}

list_append(&msg->u.confstreams.streaml, &sinfo->le, sinfo);

vinfo = icall_client_alloc(cli->userid,
cli->clientid);
vinfo->quality = cli->quality;

list_append(&ccall->videol, &vinfo->le, vinfo);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/ccall/ccall.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@

#define CCALL_MAX_VSTREAMS ( 9)

#define CCALL_RESOLUTION_ANY 0
/* low quality resolution */
#define CCALL_RESOLUTION_LOW 1
/* high quality resolution */
#define CCALL_RESOLUTION_HIGH 2


struct sftconfig {
struct le le;
char *url;
Expand Down Expand Up @@ -134,5 +141,6 @@ struct ccall {
uint64_t ts_start;
struct icall_metrics metrics;
bool inc_reconnects;
};

struct list videol;
};

0 comments on commit 955b932

Please sign in to comment.