TT#30901 convert codec list to hash table

Change-Id: I0956b441101b4c33e0f186399ef5558f89744e12
changes/67/18767/5
Richard Fuchs 7 years ago
parent 82e0c55aae
commit ff0a46a053

1
daemon/.gitignore vendored

@ -9,3 +9,4 @@ loglib.c
rtplib.c rtplib.c
codeclib.c codeclib.c
resample.c resample.c
str.c

@ -63,11 +63,11 @@ LDFLAGS+= `pkg-config --libs libavfilter`
include ../lib/lib.Makefile include ../lib/lib.Makefile
SRCS= main.c kernel.c poller.c aux.c control_tcp.c streambuf.c call.c control_udp.c redis.c \ SRCS= main.c kernel.c poller.c aux.c control_tcp.c streambuf.c call.c control_udp.c redis.c \
bencode.c cookie_cache.c udp_listener.c control_ng.c sdp.c str.c stun.c rtcp.c \ bencode.c cookie_cache.c udp_listener.c control_ng.c sdp.c stun.c rtcp.c \
crypto.c rtp.c call_interfaces.c dtls.c log.c cli.c graphite.c ice.c socket.c \ crypto.c rtp.c call_interfaces.c dtls.c log.c cli.c graphite.c ice.c socket.c \
media_socket.c homer.c recording.c statistics.c cdr.c ssrc.c iptables.c tcp_listener.c \ media_socket.c homer.c recording.c statistics.c cdr.c ssrc.c iptables.c tcp_listener.c \
codec.c codec.c
LIBSRCS= loglib.c auxlib.c rtplib.c codeclib.c resample.c LIBSRCS= loglib.c auxlib.c rtplib.c codeclib.c resample.c str.c
OBJS= $(SRCS:.c=.o) $(LIBSRCS:.c=.o) OBJS= $(SRCS:.c=.o) $(LIBSRCS:.c=.o)

@ -18,8 +18,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "compat.h" #include "compat.h"
#include <openssl/rand.h> #include "auxlib.h"
#include <assert.h>
#if !(GLIB_CHECK_VERSION(2,30,0)) #if !(GLIB_CHECK_VERSION(2,30,0))
#define g_atomic_int_and(atomic, val) \ #define g_atomic_int_and(atomic, val) \
@ -195,10 +194,6 @@ INLINE int strmemcmp(const void *mem, int len, const char *str) {
return memcmp(mem, str, len); return memcmp(mem, str, len);
} }
INLINE void random_string(unsigned char *buf, int len) {
int ret = RAND_bytes(buf, len);
assert(ret == 1);
}
INLINE long unsigned int ssl_random() { INLINE long unsigned int ssl_random() {
long unsigned int ret; long unsigned int ret;
random_string((void *) &ret, sizeof(ret)); random_string((void *) &ret, sizeof(ret));

@ -2,6 +2,9 @@
#define _AUXLIB_H_ #define _AUXLIB_H_
#include <glib.h> #include <glib.h>
#include <assert.h>
#include "compat.h"
#include <openssl/rand.h>
struct rtpengine_common_config { struct rtpengine_common_config {
char *config_file; char *config_file;
@ -21,5 +24,9 @@ void config_load(int *argc, char ***argv, GOptionEntry *entries, const char *des
char *default_config, char *default_section, char *default_config, char *default_section,
struct rtpengine_common_config *); struct rtpengine_common_config *);
INLINE void random_string(unsigned char *buf, int len) {
int ret = RAND_bytes(buf, len);
assert(ret == 1);
}
#endif #endif

@ -31,7 +31,7 @@ packetizer_f packetizer_samplestream; // flat stream of samples
static const struct codec_def_s codecs[] = { static codec_def_t __codec_defs[] = {
{ {
.rtpname = "PCMA", .rtpname = "PCMA",
.avcodec_id = AV_CODEC_ID_PCM_ALAW, .avcodec_id = AV_CODEC_ID_PCM_ALAW,
@ -290,13 +290,13 @@ static const struct codec_def_s codecs[] = {
// XXX use hashtable for quicker lookup static GHashTable *codecs_ht;
const codec_def_t *codec_find(const str *name) { const codec_def_t *codec_find(const str *name) {
for (int i = 0; i < G_N_ELEMENTS(codecs); i++) { codec_def_t *ret = g_hash_table_lookup(codecs_ht, name);
if (!str_cmp(name, codecs[i].rtpname)) return ret;
return &codecs[i];
}
return NULL;
} }
@ -548,6 +548,15 @@ void codeclib_init() {
avfilter_register_all(); avfilter_register_all();
avformat_network_init(); avformat_network_init();
av_log_set_callback(avlog_ilog); av_log_set_callback(avlog_ilog);
codecs_ht = g_hash_table_new(str_hash, str_equal);
for (int i = 0; i < G_N_ELEMENTS(__codec_defs); i++) {
codec_def_t *def = &__codec_defs[i];
str_init(&def->rtpname_str, (char *) def->rtpname);
assert(g_hash_table_lookup(codecs_ht, &def->rtpname_str) == NULL);
g_hash_table_insert(codecs_ht, &def->rtpname_str, def);
}
} }

@ -40,6 +40,7 @@ struct codec_def_s {
const int default_ptime; const int default_ptime;
packetizer_f * const packetizer; packetizer_f * const packetizer;
const int bits_per_sample; const int bits_per_sample;
str rtpname_str;
}; };
struct format_s { struct format_s {

@ -1,5 +1,5 @@
#include "str.h" #include "str.h"
#include "aux.h" #include "auxlib.h"
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>

@ -9,3 +9,4 @@ loglib.c
rtplib.c rtplib.c
codeclib.c codeclib.c
resample.c resample.c
str.c

@ -11,6 +11,7 @@ CFLAGS+= `pkg-config --cflags libavutil`
CFLAGS+= `pkg-config --cflags libavresample` CFLAGS+= `pkg-config --cflags libavresample`
CFLAGS+= `pkg-config --cflags libavfilter` CFLAGS+= `pkg-config --cflags libavfilter`
CFLAGS+= `mysql_config --cflags` CFLAGS+= `mysql_config --cflags`
CFLAGS+= `pkg-config --cflags openssl`
LDFLAGS= -lm LDFLAGS= -lm
LDFLAGS+= `pkg-config --libs glib-2.0` LDFLAGS+= `pkg-config --libs glib-2.0`
@ -21,12 +22,13 @@ LDFLAGS+= `pkg-config --libs libavutil`
LDFLAGS+= `pkg-config --libs libavresample` LDFLAGS+= `pkg-config --libs libavresample`
LDFLAGS+= `pkg-config --libs libavfilter` LDFLAGS+= `pkg-config --libs libavfilter`
LDFLAGS+= `mysql_config --libs` LDFLAGS+= `mysql_config --libs`
LDFLAGS+= `pkg-config --libs openssl`
include ../lib/lib.Makefile include ../lib/lib.Makefile
SRCS= epoll.c garbage.c inotify.c main.c metafile.c stream.c recaux.c packet.c \ SRCS= epoll.c garbage.c inotify.c main.c metafile.c stream.c recaux.c packet.c \
decoder.c output.c mix.c db.c log.c forward.c decoder.c output.c mix.c db.c log.c forward.c
LIBSRCS= loglib.c auxlib.c rtplib.c codeclib.c resample.c LIBSRCS= loglib.c auxlib.c rtplib.c codeclib.c resample.c str.c
OBJS= $(SRCS:.c=.o) $(LIBSRCS:.c=.o) OBJS= $(SRCS:.c=.o) $(LIBSRCS:.c=.o)

Loading…
Cancel
Save