From c7051fcffbca6d8b420fb3ea500d07f24e820073 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 1 Mar 2019 12:36:51 -0500 Subject: [PATCH] TT#50652 use hash table for AVCodec ID lookup Change-Id: I716a7640ceed6dd3ba459688e9f89d2ef8f76f16 --- lib/codeclib.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/codeclib.c b/lib/codeclib.c index 90e734085..492636dd9 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -375,6 +375,7 @@ static codec_def_t __codec_defs[] = { static GHashTable *codecs_ht; +static GHashTable *codecs_ht_by_av; @@ -388,13 +389,7 @@ const codec_def_t *codec_find(const str *name, enum media_type type) { } const codec_def_t *codec_find_by_av(enum AVCodecID id) { - // XXX hash this - for (int i = 0; i < G_N_ELEMENTS(__codec_defs); i++) { - codec_def_t *def = &__codec_defs[i]; - if (def->avcodec_id == id) - return def; - } - return NULL; + return g_hash_table_lookup(codecs_ht_by_av, GINT_TO_POINTER(id)); } enum media_type codec_get_type(const str *type) { @@ -724,6 +719,7 @@ void codeclib_init(int print) { av_log_set_callback(avlog_ilog); codecs_ht = g_hash_table_new(str_hash, str_equal); + codecs_ht_by_av = g_hash_table_new(g_direct_hash, g_direct_equal); for (int i = 0; i < G_N_ELEMENTS(__codec_defs); i++) { // add to hash table @@ -732,6 +728,11 @@ void codeclib_init(int print) { assert(g_hash_table_lookup(codecs_ht, &def->rtpname_str) == NULL); g_hash_table_insert(codecs_ht, &def->rtpname_str, def); + if (def->avcodec_id >= 0) { + if (g_hash_table_lookup(codecs_ht_by_av, GINT_TO_POINTER(def->avcodec_id)) == NULL) + g_hash_table_insert(codecs_ht_by_av, GINT_TO_POINTER(def->avcodec_id), def); + } + // init undefined member vars if (!def->clockrate_mult) def->clockrate_mult = 1;