MT#57977 convert call flags to uint bit field

Change-Id: Iad1fd0b00d847bc478dfeaafe9224a62a85e5b04
pull/1729/head
Richard Fuchs 2 years ago
parent 0e35f40233
commit 280795ddc9

@ -123,7 +123,7 @@ static int call_timer_delete_monologues(struct call *c) {
void call_make_own_foreign(struct call *c, bool foreign) {
statistics_update_foreignown_dec(c);
c->foreign_call = foreign ? 1 : 0;
bf_set_clear(&c->call_flags, CALL_FLAG_FOREIGN, foreign);
statistics_update_foreignown_inc(c);
}
@ -180,7 +180,7 @@ static void call_timer_iterator(struct call *c, struct iterator_helper *hlp) {
goto out;
// ignore media timeout if call was recently taken over
if (c->foreign_media && rtpe_now.tv_sec - c->last_signal <= rtpe_config.timeout)
if (CALL_ISSET(c, FOREIGN_MEDIA) && rtpe_now.tv_sec - c->last_signal <= rtpe_config.timeout)
goto out;
for (it = c->streams.head; it; it = it->next) {
@ -898,7 +898,7 @@ struct packet_stream *__packet_stream_new(struct call *call) {
recording_init_stream(stream);
stream->send_timer = send_timer_new(stream);
if (rtpe_config.jb_length && !call->disable_jb)
if (rtpe_config.jb_length && !CALL_ISSET(call, DISABLE_JB))
stream->jb = jitter_buffer_new(call);
return stream;
@ -2579,14 +2579,14 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct s
// reset offer ipv4/ipv6/mixed media stats
if (flags && flags->opmode == OP_OFFER) {
statistics_update_ip46_inc_dec(call, CMC_DECREMENT);
call->is_ipv4_media_offer = 0;
call->is_ipv6_media_offer = 0;
CALL_CLEAR(call, IPV4_OFFER);
CALL_CLEAR(call, IPV6_OFFER);
// reset answer ipv4/ipv6/mixed media stats
} else if (flags && flags->opmode == OP_ANSWER) {
statistics_update_ip46_inc_dec(call, CMC_DECREMENT);
call->is_ipv4_media_answer = 0;
call->is_ipv6_media_answer = 0;
CALL_CLEAR(call, IPV4_ANSWER);
CALL_CLEAR(call, IPV6_ANSWER);
}
__tos_change(call, flags);
@ -2859,15 +2859,15 @@ int monologue_offer_answer(struct call_monologue *monologues[2], GQueue *streams
if (media->desired_family->af == AF_INET) {
if (flags && flags->opmode == OP_OFFER) {
media->call->is_ipv4_media_offer = 1;
CALL_SET(media->call, IPV4_OFFER);
} else if (flags && flags->opmode == OP_ANSWER) {
media->call->is_ipv4_media_answer = 1;
CALL_SET(media->call, IPV4_ANSWER);
}
} else if (media->desired_family->af == AF_INET6) {
if (flags && flags->opmode == OP_OFFER) {
media->call->is_ipv6_media_offer = 1;
CALL_SET(media->call, IPV6_OFFER);
} else if (flags && flags->opmode == OP_ANSWER) {
media->call->is_ipv6_media_answer = 1;
CALL_SET(media->call, IPV6_ANSWER);
}
}
@ -2917,7 +2917,7 @@ int monologue_offer_answer(struct call_monologue *monologues[2], GQueue *streams
}
if (flags && flags->disable_jb && media->call)
media->call->disable_jb=1;
CALL_SET(media->call, DISABLE_JB);
__num_media_streams(media, num_ports_this);
__assign_stream_fds(media, &em->intf_sfds);
@ -4060,7 +4060,7 @@ restart:
g_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c));
RTPE_GAUGE_INC(total_sessions);
c->foreign_call = foreign ? 1 : 0;
bf_set_clear(&c->call_flags, CALL_FLAG_FOREIGN, foreign);
statistics_update_foreignown_inc(c);

@ -2027,7 +2027,7 @@ static const char *call_offer_answer_ng(struct ng_buffer *ngbuf, bencode_item_t
goto out;
if (flags.debug)
call->debug = 1;
CALL_SET(call, DEBUG);
if (rtpe_config.active_switchover && IS_FOREIGN_CALL(call))
call_make_own_foreign(call, false);
@ -2067,11 +2067,11 @@ static const char *call_offer_answer_ng(struct ng_buffer *ngbuf, bencode_item_t
detect_setup_recording(call, &flags);
if (flags.drop_traffic_start) {
call->drop_traffic = 1;
CALL_SET(call, DROP_TRAFFIC);
}
if (flags.drop_traffic_stop) {
call->drop_traffic = 0;
CALL_CLEAR(call, DROP_TRAFFIC);
}
ret = monologue_offer_answer(monologues, &streams, &flags);
@ -2625,7 +2625,7 @@ static const char *call_recording_common_ng(bencode_item_t *input, bencode_item_
static void start_recording_fn(bencode_item_t *input, struct call *call) {
str output_dest;
bencode_dictionary_get_str(input, "output-destination", &output_dest);
call->recording_on = 1;
CALL_SET(call, RECORDING_ON);
recording_start(call, NULL, &output_dest);
}
const char *call_start_recording_ng(bencode_item_t *input, bencode_item_t *output) {
@ -2634,7 +2634,7 @@ const char *call_start_recording_ng(bencode_item_t *input, bencode_item_t *outpu
static void pause_recording_fn(bencode_item_t *input, struct call *call) {
call->recording_on = 0;
CALL_CLEAR(call, RECORDING_ON);
recording_pause(call);
}
const char *call_pause_recording_ng(bencode_item_t *input, bencode_item_t *output) {
@ -2666,7 +2666,7 @@ static void stop_recording_fn(bencode_item_t *input, struct call *call) {
}
}
call->recording_on = 0;
CALL_CLEAR(call, RECORDING_ON);
recording_stop(call);
}
const char *call_stop_recording_ng(bencode_item_t *input, bencode_item_t *output) {
@ -2817,7 +2817,7 @@ const char *call_start_forwarding_ng(bencode_item_t *input, bencode_item_t *outp
}
else {
ilog(LOG_INFO, "Start forwarding (entire call)");
call->rec_forwarding = 1;
CALL_SET(call, REC_FORWARDING);
}
if (monologue)
@ -2846,7 +2846,7 @@ const char *call_stop_forwarding_ng(bencode_item_t *input, bencode_item_t *outpu
}
else {
ilog(LOG_INFO, "Stop forwarding (entire call)");
call->rec_forwarding = 0;
CALL_CLEAR(call, REC_FORWARDING);
if (flags.all == ALL_ALL) {
for (GList *l = call->monologues.head; l; l = l->next) {
monologue = l->data;

@ -1146,7 +1146,7 @@ static void cli_incoming_active_standby(struct cli_writer *cw, bool foreign) {
call_make_own_foreign(c, foreign);
c->last_signal = MAX(c->last_signal, rtpe_now.tv_sec);
if (!foreign) {
c->foreign_media = 1; // ignore timeout until we have media
CALL_SET(c, FOREIGN_MEDIA); // ignore timeout until we have media
c->last_signal++; // we are authoritative now
}
rwlock_unlock_w(&c->master_lock);
@ -1198,7 +1198,7 @@ static void cli_incoming_debug(str *instr, struct cli_writer *cw) {
return;
}
c->debug = flag;
bf_set_clear(&c->call_flags, CALL_FLAG_DEBUG, flag);
cw->cw_printf(cw, "%s debugging for call '" STR_FORMAT "'\n", flag ? "Enabled" : "Disabled",
STR_FMT(&callid));
@ -1531,7 +1531,7 @@ static void cli_incoming_call_debug(str *instr, struct cli_writer *cw) {
}
}
cw->call->debug = flag;
bf_set_clear(&cw->call->call_flags, CALL_FLAG_DEBUG, flag);
cw->cw_printf(cw, "%s debugging for call '" STR_FORMAT "'\n", flag ? "Enabled" : "Disabled",
STR_FMT(&cw->call->callid));

@ -184,9 +184,9 @@ int get_local_log_level(unsigned int subsystem_idx) {
}
if (!call)
return -1;
if (call->foreign_call)
if (CALL_ISSET(call, FOREIGN))
return 5 | LOG_FLAG_MAX;
if (call->debug)
if (CALL_ISSET(call, DEBUG))
return 8;
return -1;
}

@ -2771,9 +2771,9 @@ static int stream_packet(struct packet_handler_ctx *phc) {
if (!phc->mp.stream->selected_sfd)
goto out;
phc->mp.call->foreign_media = 0;
CALL_CLEAR(phc->mp.call, FOREIGN_MEDIA);
if (phc->mp.call->drop_traffic)
if (CALL_ISSET(phc->mp.call, DROP_TRAFFIC))
goto drop;
int stun_ret = media_demux_protocols(phc);
@ -3499,7 +3499,7 @@ enum thread_looper_action kernel_stats_updater(void) {
bool update = false;
if (diff_packets_in)
sfd->call->foreign_media = 0;
CALL_CLEAR(sfd->call, FOREIGN_MEDIA);
if (!ke->target.non_forwarding && diff_packets_in) {
for (GList *l = ps->rtp_sinks.head; l; l = l->next) {

@ -303,8 +303,8 @@ static void update_output_dest(struct call *call, const str *output_dest) {
// lock must be held
static void update_flags_proc(struct call *call, bool streams) {
append_meta_chunk_null(call->recording, "RECORDING %u", call->recording_on ? 1 : 0);
append_meta_chunk_null(call->recording, "FORWARDING %u", call->rec_forwarding ? 1 : 0);
append_meta_chunk_null(call->recording, "RECORDING %u", CALL_ISSET(call, RECORDING_ON));
append_meta_chunk_null(call->recording, "FORWARDING %u", CALL_ISSET(call, REC_FORWARDING));
if (!streams)
return;
for (GList *l = call->streams.head; l; l = l->next) {
@ -379,7 +379,7 @@ void recording_stop(struct call *call) {
return;
// check if all recording options are disabled
if (call->recording_on || call->rec_forwarding) {
if (CALL_ISSET(call, RECORDING_ON) || CALL_ISSET(call, REC_FORWARDING)) {
recording_update_flags(call, true);
return;
}
@ -400,7 +400,7 @@ void recording_pause(struct call *call) {
recording_update_flags(call, true);
}
void recording_discard(struct call *call) {
call->recording_on = 0;
CALL_CLEAR(call, RECORDING_ON);
if (!call->recording)
return;
ilog(LOG_NOTICE, "Turning off call recording and discarding outputs.");
@ -425,15 +425,15 @@ void detect_setup_recording(struct call *call, const struct sdp_ng_flags *flags)
const str *recordcall = &flags->record_call_str;
if (!str_cmp(recordcall, "yes") || !str_cmp(recordcall, "on") || flags->record_call) {
call->recording_on = 1;
CALL_SET(call, RECORDING_ON);
recording_start(call, NULL, &flags->output_dest);
}
else if (!str_cmp(recordcall, "no") || !str_cmp(recordcall, "off")) {
call->recording_on = 0;
CALL_CLEAR(call, RECORDING_ON);
recording_stop(call);
}
else if (!str_cmp(recordcall, "discard") || flags->discard_recording) {
call->recording_on = 0;
CALL_CLEAR(call, RECORDING_ON);
recording_discard(call);
}
else if (recordcall->len != 0)

@ -2681,7 +2681,7 @@ void redis_update_onekey(struct call *c, struct redis *r) {
if (!r)
return;
if (c->foreign_call)
if (IS_FOREIGN_CALL(c))
return;
LOCK(&r->lock);
@ -2730,7 +2730,7 @@ void redis_delete(struct call *c, struct redis *r) {
if (!r)
return;
if (c->foreign_call)
if (IS_FOREIGN_CALL(c))
return;
if (delete_async) {

@ -29,26 +29,26 @@ struct global_stats_counter rtpe_stats_intv; // calculated once per sec by `ca
// check not to multiple decrement or increment
void statistics_update_ip46_inc_dec(struct call* c, int op) {
// already incremented
if (op == CMC_INCREMENT && c->is_call_media_counted) {
if (op == CMC_INCREMENT && CALL_ISSET(c, MEDIA_COUNTED)) {
return ;
// already decremented
} else if (op == CMC_DECREMENT && !c->is_call_media_counted) {
} else if (op == CMC_DECREMENT && !CALL_ISSET(c, MEDIA_COUNTED)) {
return ;
}
// offer is ipv4 only
if (c->is_ipv4_media_offer && !c->is_ipv6_media_offer) {
if (CALL_ISSET(c, IPV4_OFFER) && !CALL_ISSET(c, IPV6_OFFER)) {
// answer is ipv4 only
if (c->is_ipv4_media_answer && !c->is_ipv6_media_answer) {
if (CALL_ISSET(c, IPV4_ANSWER) && !CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(ipv4_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is ipv6 only
} else if (!c->is_ipv4_media_answer && c->is_ipv6_media_answer) {
} else if (!CALL_ISSET(c, IPV4_ANSWER) && CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(mixed_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is both ipv4 and ipv6
} else if (c->is_ipv4_media_answer && c->is_ipv6_media_answer) {
} else if (CALL_ISSET(c, IPV4_ANSWER) && CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(ipv4_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is neither ipv4 nor ipv6
@ -57,17 +57,17 @@ void statistics_update_ip46_inc_dec(struct call* c, int op) {
}
// offer is ipv6 only
} else if (!c->is_ipv4_media_offer && c->is_ipv6_media_offer) {
} else if (!CALL_ISSET(c, IPV4_OFFER) && CALL_ISSET(c, IPV6_OFFER)) {
// answer is ipv4 only
if (c->is_ipv4_media_answer && !c->is_ipv6_media_answer) {
if (CALL_ISSET(c, IPV4_ANSWER) && !CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(mixed_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is ipv6 only
} else if (!c->is_ipv4_media_answer && c->is_ipv6_media_answer) {
} else if (!CALL_ISSET(c, IPV4_ANSWER) && CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(ipv6_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is both ipv4 and ipv6
} else if (c->is_ipv4_media_answer && c->is_ipv6_media_answer) {
} else if (CALL_ISSET(c, IPV4_ANSWER) && CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(ipv6_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is neither ipv4 nor ipv6
@ -76,17 +76,17 @@ void statistics_update_ip46_inc_dec(struct call* c, int op) {
}
// offer is both ipv4 and ipv6
} else if (c->is_ipv4_media_offer && c->is_ipv6_media_offer) {
} else if (CALL_ISSET(c, IPV4_OFFER) && CALL_ISSET(c, IPV6_OFFER)) {
// answer is ipv4 only
if (c->is_ipv4_media_answer && !c->is_ipv6_media_answer) {
if (CALL_ISSET(c, IPV4_ANSWER) && !CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(ipv4_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is ipv6 only
} else if (!c->is_ipv4_media_answer && c->is_ipv6_media_answer) {
} else if (!CALL_ISSET(c, IPV4_ANSWER) && CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(ipv6_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is both ipv4 and ipv6
} else if (c->is_ipv4_media_answer && c->is_ipv6_media_answer) {
} else if (CALL_ISSET(c, IPV4_ANSWER) && CALL_ISSET(c, IPV6_ANSWER)) {
RTPE_GAUGE_ADD(mixed_sessions, op == CMC_INCREMENT ? 1 : -1);
// answer is neither ipv4 nor ipv6
@ -100,7 +100,7 @@ void statistics_update_ip46_inc_dec(struct call* c, int op) {
}
// mark if incremented or decremented
c->is_call_media_counted = (op == CMC_INCREMENT) ? 1 : 0;
bf_set_clear(&c->call_flags, CALL_FLAG_MEDIA_COUNTED, op == CMC_INCREMENT);
}
void statistics_update_foreignown_dec(struct call* c) {

@ -94,7 +94,7 @@ enum {
#define RTP_LOOP_MAX_COUNT 30 /* number of consecutively detected dupes to trigger protection */
#endif
#define IS_FOREIGN_CALL(c) (c->foreign_call)
#define IS_FOREIGN_CALL(c) CALL_ISSET(c, FOREIGN)
#define IS_OWN_CALL(c) !IS_FOREIGN_CALL(c)
/* flags shared by several of the structs below */
@ -199,6 +199,20 @@ enum {
#define ML_FLAG_TRANSCODING 0x00200000
#define ML_FLAG_BLOCK_SHORT 0x00400000
/* struct call */
#define CALL_FLAG_IPV4_OFFER 0x00010000
#define CALL_FLAG_IPV6_OFFER 0x00020000
#define CALL_FLAG_IPV4_ANSWER 0x00040000
#define CALL_FLAG_IPV6_ANSWER 0x00080000
#define CALL_FLAG_MEDIA_COUNTED 0x00100000
#define CALL_FLAG_RECORDING_ON 0x00200000
#define CALL_FLAG_REC_FORWARDING 0x00400000
#define CALL_FLAG_DROP_TRAFFIC 0x00800000
#define CALL_FLAG_FOREIGN 0x01000000 // created_via_redis_notify call
#define CALL_FLAG_FOREIGN_MEDIA 0x02000000 // for calls taken over, tracks whether we have media
#define CALL_FLAG_DISABLE_JB 0x04000000
#define CALL_FLAG_DEBUG 0x08000000
/* access macros */
#define SP_ISSET(p, f) bf_isset(&(p)->sp_flags, SP_FLAG_ ## f)
#define SP_SET(p, f) bf_set(&(p)->sp_flags, SP_FLAG_ ## f)
@ -218,6 +232,11 @@ enum {
#define ML_ARESET2(p, f, g) bf_areset(&(p)->ml_flags, ML_FLAG_ ## f | ML_FLAG_ ## g)
#define ML_SET(p, f) bf_set(&(p)->ml_flags, ML_FLAG_ ## f)
#define ML_CLEAR(p, f) bf_clear(&(p)->ml_flags, ML_FLAG_ ## f)
#define CALL_ISSET(p, f) bf_isset(&(p)->call_flags, CALL_FLAG_ ## f)
#define CALL_ISSET2(p, f, g) bf_isset(&(p)->call_flags, CALL_FLAG_ ## f | CALL_FLAG_ ## g)
#define CALL_ARESET2(p, f, g) bf_areset(&(p)->call_flags, CALL_FLAG_ ## f | CALL_FLAG_ ## g)
#define CALL_SET(p, f) bf_set(&(p)->call_flags, CALL_FLAG_ ## f)
#define CALL_CLEAR(p, f) bf_clear(&(p)->call_flags, CALL_FLAG_ ## f)
enum block_dtmf_mode {
BLOCK_DTMF_OFF = 0,
@ -692,20 +711,7 @@ struct call {
bool block_media;
bool silence_media;
// ipv4/ipv6 media flags
unsigned int is_ipv4_media_offer:1;
unsigned int is_ipv6_media_offer:1;
unsigned int is_ipv4_media_answer:1;
unsigned int is_ipv6_media_answer:1;
unsigned int is_call_media_counted:1;
unsigned int recording_on:1;
unsigned int rec_forwarding:1;
unsigned int drop_traffic:1;
unsigned int foreign_call:1; // created_via_redis_notify call
unsigned int foreign_media:1; // for calls taken over, tracks whether we have media
unsigned int disable_jb:1;
unsigned int debug:1;
unsigned int call_flags;
};

Loading…
Cancel
Save