MT#55283 glib_json_builder_add_str hack

Avoids allocating and duplicating the string. Should be safe as all
strings that use it are allocated in read-write memory.

Requires changing some struct members to non-const.

Change-Id: Idc81a84a1454898c76d8514666c385307043bb6f
pull/1870/head
Richard Fuchs 8 months ago
parent 9fbddb2e5e
commit 7125f0f686

@ -334,14 +334,14 @@ static void janus_add_publisher_details(JsonBuilder *builder, struct call_monolo
json_builder_set_member_name(builder, "streams");
json_builder_begin_array(builder);
const str *a_codec = NULL, *v_codec = NULL;
str *a_codec = NULL, *v_codec = NULL;
for (unsigned int i = 0; i < ml->medias->len; i++) {
struct call_media *media = ml->medias->pdata[i];
if (!media)
continue;
const str *codec = NULL;
str *codec = NULL;
for (__auto_type k = media->codecs.codec_prefs.head; k; k = k->next) {
rtp_payload_type *pt = k->data;
codec = &pt->encoding;

@ -381,7 +381,7 @@ struct endpoint_map {
unsigned int unique_id;
struct endpoint endpoint;
unsigned int num_ports;
const struct logical_intf *logical_intf;
struct logical_intf *logical_intf;
sfd_intf_list_q intf_sfds; /* list of struct sfd_intf_list - contains stream_fd list */
unsigned int wildcard:1;
};
@ -487,7 +487,7 @@ struct call_media {
const struct transport_protocol *protocol;
str format_str;
sockfamily_t *desired_family;
const struct logical_intf *logical_intf;
struct logical_intf *logical_intf;
struct ice_agent *ice_agent;
@ -583,7 +583,7 @@ struct call_monologue {
struct timeval terminated; /* for CDR */
enum termination_reason term_reason;
sockfamily_t *desired_family;
const struct logical_intf *logical_intf;
struct logical_intf *logical_intf;
GHashTable *associated_tags;
GHashTable *subscribers_ht; /* for quick lookup */
medias_arr *medias;

@ -100,13 +100,11 @@ INLINE char *glib_json_print(JsonBuilder *builder) {
return result;
}
INLINE void glib_json_builder_add_str(JsonBuilder *builder, const str *s) {
// this is not optimal at all, but necessary due to glib's lack of "add_string_len_value" or similar
char *b = g_malloc(s->len + 1);
memcpy(b, s->s, s->len);
b[s->len] = '\0';
json_builder_add_string_value(builder, b);
g_free(b);
INLINE void glib_json_builder_add_str(JsonBuilder *builder, str *s) {
char ori = s->s[s->len];
s->s[s->len] = '\0';
json_builder_add_string_value(builder, s->s);
s->s[s->len] = ori;
}

@ -156,7 +156,7 @@ struct local_intf {
struct intf_spec *spec;
struct intf_address advertised_address;
unsigned int unique_id; /* starting with 0 - serves as preference */
const struct logical_intf *logical;
struct logical_intf *logical;
str ice_foundation;
struct interface_stats_block *stats;

Loading…
Cancel
Save