Browse Source

TT#92250 allocate strings for hash table storage

closes #1091

Change-Id: Ia3384fc3eb640bb6c728ebde6e7bde09968eeb9a
pull/1093/head
Richard Fuchs 5 years ago
parent
commit
3893069fae
4 changed files with 27 additions and 22 deletions
  1. +4
    -2
      daemon/call.c
  2. +16
    -17
      daemon/codec.c
  3. +2
    -1
      daemon/sdp.c
  4. +5
    -2
      include/aux.h

+ 4
- 2
daemon/call.c View File

@ -740,8 +740,10 @@ struct call_media *call_media_new(struct call *call) {
med->call = call;
med->codecs_recv = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL);
med->codecs_send = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL);
med->codec_names_recv = g_hash_table_new_full(str_case_hash, str_case_equal, NULL, (void (*)(void*)) g_queue_free);
med->codec_names_send = g_hash_table_new_full(str_case_hash, str_case_equal, NULL, (void (*)(void*)) g_queue_free);
med->codec_names_recv = g_hash_table_new_full(str_case_hash, str_case_equal, free,
(void (*)(void*)) g_queue_free);
med->codec_names_send = g_hash_table_new_full(str_case_hash, str_case_equal, free,
(void (*)(void*)) g_queue_free);
return med;
}


+ 16
- 17
daemon/codec.c View File

@ -2219,9 +2219,9 @@ static struct rtp_payload_type *__rtp_payload_type_copy(const struct rtp_payload
}
static void __rtp_payload_type_add_name(GHashTable *ht, struct rtp_payload_type *pt)
{
GQueue *q = g_hash_table_lookup_queue_new(ht, &pt->encoding);
GQueue *q = g_hash_table_lookup_queue_new(ht, str_dup(&pt->encoding), free);
g_queue_push_tail(q, GUINT_TO_POINTER(pt->payload_type));
q = g_hash_table_lookup_queue_new(ht, &pt->encoding_with_params);
q = g_hash_table_lookup_queue_new(ht, str_dup(&pt->encoding_with_params), free);
g_queue_push_tail(q, GUINT_TO_POINTER(pt->payload_type));
}
static void __insert_codec_tracker(struct call_media *media, GList *link) {
@ -2242,7 +2242,8 @@ static void __insert_codec_tracker(struct call_media *media, GList *link) {
(GDestroyNotify) g_queue_free);
g_hash_table_replace(sct->supp_codecs, str_dup(&pt->encoding), clockrates);
}
GQueue *entries = g_hash_table_lookup_queue_new(clockrates, GUINT_TO_POINTER(pt->clock_rate));
GQueue *entries = g_hash_table_lookup_queue_new(clockrates, GUINT_TO_POINTER(pt->clock_rate),
NULL);
g_queue_push_tail(entries, link);
}
}
@ -2339,12 +2340,11 @@ static int __revert_codec_strip(GHashTable *stripped, GHashTable *masked, const
if (q) {
ilog(LOG_DEBUG, "Restoring codec '" STR_FORMAT "' from stripped codecs (%u payload types)",
STR_FMT(codec), q->length);
g_hash_table_steal(stripped, codec);
for (GList *l = q->head; l; l = l->next) {
struct rtp_payload_type *pt = l->data;
while (q->length) {
struct rtp_payload_type *pt = g_queue_pop_head(q);
__rtp_payload_type_add(media, other_media, pt);
}
g_queue_free(q);
g_hash_table_remove(stripped, codec);
ret = 1;
}
@ -2352,13 +2352,12 @@ static int __revert_codec_strip(GHashTable *stripped, GHashTable *masked, const
if (q) {
ilog(LOG_DEBUG, "Restoring codec '" STR_FORMAT "' from masked codecs (%u payload types)",
STR_FMT(codec), q->length);
g_hash_table_steal(masked, codec);
for (GList *l = q->head; l; l = l->next) {
struct rtp_payload_type *pt = l->data;
while (q->length) {
struct rtp_payload_type *pt = g_queue_pop_head(q);
pt->for_transcoding = 1;
__rtp_payload_type_add_recv(media, pt, 1);
}
g_queue_free(q);
g_hash_table_remove(masked, codec);
ret = 1;
}
@ -2540,8 +2539,8 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_
struct rtp_payload_type *pt;
static const str str_all = STR_CONST_INIT("all");
static const str str_full = STR_CONST_INIT("full");
GHashTable *stripped = g_hash_table_new_full(str_case_hash, str_case_equal, NULL, __payload_queue_free);
GHashTable *masked = g_hash_table_new_full(str_case_hash, str_case_equal, NULL, __payload_queue_free);
GHashTable *stripped = g_hash_table_new_full(str_case_hash, str_case_equal, free, __payload_queue_free);
GHashTable *masked = g_hash_table_new_full(str_case_hash, str_case_equal, free, __payload_queue_free);
int strip_all = 0, mask_all = 0;
// start fresh
@ -2581,9 +2580,9 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_
ilog(LOG_DEBUG, "Stripping codec '" STR_FORMAT "'",
STR_FMT(&pt->encoding_with_params));
codec_touched(pt, media);
GQueue *q = g_hash_table_lookup_queue_new(stripped, &pt->encoding);
GQueue *q = g_hash_table_lookup_queue_new(stripped, str_dup(&pt->encoding), free);
g_queue_push_tail(q, __rtp_payload_type_copy(pt));
q = g_hash_table_lookup_queue_new(stripped, &pt->encoding_with_params);
q = g_hash_table_lookup_queue_new(stripped, str_dup(&pt->encoding_with_params), free);
g_queue_push_tail(q, pt);
continue;
}
@ -2595,9 +2594,9 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_
ilog(LOG_DEBUG, "Masking codec '" STR_FORMAT "'",
STR_FMT(&pt->encoding_with_params));
codec_touched(pt, media);
GQueue *q = g_hash_table_lookup_queue_new(masked, &pt->encoding);
GQueue *q = g_hash_table_lookup_queue_new(masked, str_dup(&pt->encoding), free);
g_queue_push_tail(q, __rtp_payload_type_copy(pt));
q = g_hash_table_lookup_queue_new(stripped, &pt->encoding_with_params);
q = g_hash_table_lookup_queue_new(masked, str_dup(&pt->encoding_with_params), free);
g_queue_push_tail(q, __rtp_payload_type_copy(pt));
__rtp_payload_type_add_send(other_media, pt);
}


+ 2
- 1
daemon/sdp.c View File

@ -1144,7 +1144,8 @@ new_session:
/* attr_queue = g_hash_table_lookup_queue_new(attrs->name_lists_hash, &attr->name);
g_queue_push_tail(attr_queue, attr); */
attr_queue = g_hash_table_lookup_queue_new(attrs->id_lists_hash, &attr->attr);
attr_queue = g_hash_table_lookup_queue_new(attrs->id_lists_hash, &attr->attr,
NULL);
g_queue_push_tail(attr_queue, attr);
break;


+ 5
- 2
include/aux.h View File

@ -157,10 +157,13 @@ INLINE void g_tree_add_all(GTree *t, GQueue *q, void (*cb)(gpointer, gpointer))
/* GHASHTABLE */
INLINE GQueue *g_hash_table_lookup_queue_new(GHashTable *ht, void *key) {
INLINE GQueue *g_hash_table_lookup_queue_new(GHashTable *ht, void *key, GDestroyNotify free_func) {
GQueue *ret = g_hash_table_lookup(ht, key);
if (ret)
if (ret) {
if (free_func)
free_func(key);
return ret;
}
ret = g_queue_new();
g_hash_table_insert(ht, key, ret);
return ret;


Loading…
Cancel
Save