MT#61822 switch to typed media_player_cache_ht

Change-Id: I04e8dd888fa65c4f43423693feb711af34030a84
pull/1897/head
Richard Fuchs 11 months ago
parent cd2c585958
commit 3694539bc5

@ -96,7 +96,15 @@ struct media_player_media_file {
}; };
static mutex_t media_player_cache_lock = MUTEX_STATIC_INIT; static mutex_t media_player_cache_lock = MUTEX_STATIC_INIT;
static GHashTable *media_player_cache; // keys and values only ever freed at shutdown static unsigned int media_player_cache_entry_hash(const struct media_player_cache_index *p);
static gboolean media_player_cache_entry_eq(const struct media_player_cache_index *A,
const struct media_player_cache_index *B);
static void media_player_cache_index_free(struct media_player_cache_index *p);
static void media_player_cache_entry_free(struct media_player_cache_entry *p);
TYPED_GHASHTABLE(media_player_cache_ht, struct media_player_cache_index, struct media_player_cache_entry,
media_player_cache_entry_hash, media_player_cache_entry_eq,
media_player_cache_index_free, media_player_cache_entry_free)
static media_player_cache_ht media_player_cache; // keys and values only ever freed at shutdown
TYPED_GHASHTABLE(media_player_media_files_ht, str, struct media_player_media_file, str_hash, str_equal, TYPED_GHASHTABLE(media_player_media_files_ht, str, struct media_player_media_file, str_hash, str_equal,
NULL, __obj_put); NULL, __obj_put);
@ -667,7 +675,7 @@ static bool media_player_cache_get_entry(struct media_player *mp,
mutex_lock(&media_player_cache_lock); mutex_lock(&media_player_cache_lock);
struct media_player_cache_entry *entry = mp->cache_entry struct media_player_cache_entry *entry = mp->cache_entry
= g_hash_table_lookup(media_player_cache, &lookup); = t_hash_table_lookup(media_player_cache, &lookup);
bool ret = true; // entry exists, use cached data bool ret = true; // entry exists, use cached data
if (entry) { if (entry) {
@ -708,7 +716,7 @@ static bool media_player_cache_get_entry(struct media_player *mp,
default:; default:;
} }
g_hash_table_insert(media_player_cache, ins_key, entry); t_hash_table_insert(media_player_cache, ins_key, entry);
entry->kernel_idx = -1; entry->kernel_idx = -1;
if (kernel.use_player) { if (kernel.use_player) {
@ -1952,8 +1960,7 @@ bool media_player_is_active(struct call_monologue *ml) {
return true; return true;
} }
static unsigned int media_player_cache_entry_hash(const void *p) { static unsigned int media_player_cache_entry_hash(const struct media_player_cache_index *i) {
const struct media_player_cache_index *i = p;
unsigned int ret; unsigned int ret;
switch (i->index.type) { switch (i->index.type) {
case MP_DB: case MP_DB:
@ -1970,8 +1977,9 @@ static unsigned int media_player_cache_entry_hash(const void *p) {
ret ^= i->index.type; ret ^= i->index.type;
return ret; return ret;
} }
static gboolean media_player_cache_entry_eq(const void *A, const void *B) { static gboolean media_player_cache_entry_eq(const struct media_player_cache_index *a,
const struct media_player_cache_index *a = A, *b = B; const struct media_player_cache_index *b)
{
if (a->index.type != b->index.type) if (a->index.type != b->index.type)
return FALSE; return FALSE;
switch (a->index.type) { switch (a->index.type) {
@ -1989,15 +1997,13 @@ static gboolean media_player_cache_entry_eq(const void *A, const void *B) {
} }
return str_equal(&a->dst_pt.encoding_with_full_params, &b->dst_pt.encoding_with_full_params); return str_equal(&a->dst_pt.encoding_with_full_params, &b->dst_pt.encoding_with_full_params);
} }
static void media_player_cache_index_free(void *p) { static void media_player_cache_index_free(struct media_player_cache_index *i) {
struct media_player_cache_index *i = p;
g_free(i->index.file.s); g_free(i->index.file.s);
payload_type_clear(&i->dst_pt); payload_type_clear(&i->dst_pt);
memory_arena_free(&i->arena); memory_arena_free(&i->arena);
g_slice_free1(sizeof(*i), i); g_slice_free1(sizeof(*i), i);
} }
static void media_player_cache_entry_free(void *p) { static void media_player_cache_entry_free(struct media_player_cache_entry *e) {
struct media_player_cache_entry *e = p;
t_ptr_array_free(e->packets, true); t_ptr_array_free(e->packets, true);
mutex_destroy(&e->lock); mutex_destroy(&e->lock);
g_free(e->info_str); g_free(e->info_str);
@ -2029,11 +2035,8 @@ bool media_player_start(struct media_player *mp) {
void media_player_init(void) { void media_player_init(void) {
#ifdef WITH_TRANSCODING #ifdef WITH_TRANSCODING
if (rtpe_config.player_cache) { if (rtpe_config.player_cache)
media_player_cache = g_hash_table_new_full(media_player_cache_entry_hash, media_player_cache = media_player_cache_ht_new();
media_player_cache_entry_eq, media_player_cache_index_free,
media_player_cache_entry_free);
}
timerthread_init(&media_player_thread, rtpe_config.media_num_threads, media_player_run); timerthread_init(&media_player_thread, rtpe_config.media_num_threads, media_player_run);
#endif #endif
@ -2044,8 +2047,8 @@ void media_player_free(void) {
#ifdef WITH_TRANSCODING #ifdef WITH_TRANSCODING
timerthread_free(&media_player_thread); timerthread_free(&media_player_thread);
if (media_player_cache) if (t_hash_table_is_set(media_player_cache))
g_hash_table_destroy(media_player_cache); t_hash_table_destroy(media_player_cache);
if (t_hash_table_is_set(media_player_media_files)) if (t_hash_table_is_set(media_player_media_files))
t_hash_table_destroy(media_player_media_files); t_hash_table_destroy(media_player_media_files);

Loading…
Cancel
Save