diff --git a/daemon/.ycm_extra_conf.py b/daemon/.ycm_extra_conf.py index eb01d3643..3a162e2dd 100644 --- a/daemon/.ycm_extra_conf.py +++ b/daemon/.ycm_extra_conf.py @@ -46,7 +46,7 @@ flags = [ '-DWITH_TRANSCODING', '-DHAVE_BCG729', '-DHAVE_MQTT', - '-DHAVE_CUDECS', + '-DHAVE_CODEC_CHAIN', '-D__csh_lookup(x)=str_hash(x)', '-DCSH_LOOKUP(x)=' + csh_lookup_str, '-O2', diff --git a/daemon/Makefile b/daemon/Makefile index 636c0dce0..2cfd958ff 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -75,7 +75,7 @@ endif ifeq ($(with_transcoding),yes) include ../lib/g729.Makefile -include ../lib/cudecs.Makefile +include ../lib/codec-chain.Makefile endif include ../lib/mqtt.Makefile diff --git a/lib/.ycm_extra_conf.py b/lib/.ycm_extra_conf.py index 79674acb1..7ec1e7c94 100644 --- a/lib/.ycm_extra_conf.py +++ b/lib/.ycm_extra_conf.py @@ -42,7 +42,7 @@ flags = [ '-DRE_PLUGIN_DIR="/usr/lib/rtpengine"', '-DWITH_IPTABLES_OPTION', '-DHAVE_BCG729', - '-DHAVE_CUDECS', + '-DHAVE_CODEC_CHAIN', '-D__csh_lookup(x)=str_hash(x)', '-DCSH_LOOKUP(x)=' + csh_lookup_str, '-O2', @@ -67,6 +67,10 @@ flags = [ 'c', ] +if 'CODEC_CHAIN_HOME' in os.environ: + flags.append('-I' + os.environ['CODEC_CHAIN_HOME'] + '/usr/include') + + if compilation_database_folder: database = ycm_core.CompilationDatabase(compilation_database_folder) else: diff --git a/lib/auxlib.c b/lib/auxlib.c index 61b1f964a..5da94de45 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -215,8 +215,8 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char { "thread-stack", 0,0, G_OPTION_ARG_INT, &rtpe_common_config_ptr->thread_stack, "Thread stack size in kB", "INT" }, { "poller-size", 0,0, G_OPTION_ARG_INT, &rtpe_common_config_ptr->poller_size, "Max poller items per iteration", "INT" }, { "evs-lib-path", 0,0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->evs_lib_path, "Location of .so for 3GPP EVS codec", "FILE" }, -#ifdef HAVE_CUDECS - { "cudecs-lib-path", 0,0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->cudecs_lib_path,"Location of .so for CUDA codecs", "FILE" }, +#ifdef HAVE_CODEC_CHAIN + { "codec-chain-lib-path",0,0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->codec_chain_lib_path,"Location of libcodec-chain.so", "FILE" }, #endif { NULL, } }; diff --git a/lib/auxlib.h b/lib/auxlib.h index a1dc03552..ce8767812 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -36,7 +36,7 @@ struct rtpengine_common_config { int poller_size; int max_log_line_length; char *evs_lib_path; - char *cudecs_lib_path; + char *codec_chain_lib_path; }; extern struct rtpengine_common_config *rtpe_common_config_ptr; diff --git a/lib/codec-chain.Makefile b/lib/codec-chain.Makefile new file mode 100644 index 000000000..6cf796d5e --- /dev/null +++ b/lib/codec-chain.Makefile @@ -0,0 +1,7 @@ +ifneq (,$(filter pkg.ngcp-rtpengine.codec-chain,${DEB_BUILD_PROFILES})) +ifneq (,$(wildcard $(CODEC_CHAIN_HOME)/usr/include/codec-chain/client.h)) +CFLAGS+= -DHAVE_CODEC_CHAIN -I$(CODEC_CHAIN_HOME)/usr/include +else ifneq (,$(wildcard /usr/include/codec-chain/client.h)) +CFLAGS+= -DHAVE_CODEC_CHAIN +endif +endif diff --git a/lib/codeclib.c b/lib/codeclib.c index 4f70c609a..c8386eb33 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -11,8 +11,9 @@ #include #endif #include -#ifdef HAVE_CUDECS -#include +#ifdef HAVE_CODEC_CHAIN +#include +#include #endif #include "str.h" #include "log.h" @@ -142,47 +143,49 @@ static select_encoder_format_f evs_select_encoder_format; -static void *cudecs_lib_handle; +static void *codec_chain_lib_handle; -#ifdef HAVE_CUDECS +#ifdef HAVE_CODEC_CHAIN -static gpu_init_fn *gpu_init; +static __typeof__(codec_chain_client_connect) *cc_client_connect; -static gpu_pcma2opus_runner_new_fn *gpu_pcma2opus_runner_new; -static gpu_pcmu2opus_runner_new_fn *gpu_pcmu2opus_runner_new; -static gpu_opus2pcma_runner_new_fn *gpu_opus2pcma_runner_new; -static gpu_opus2pcmu_runner_new_fn *gpu_opus2pcmu_runner_new; +static __typeof__(codec_chain_client_pcma2opus_runner_new) *cc_client_pcma2opus_runner_new; +static __typeof__(codec_chain_client_pcmu2opus_runner_new) *cc_client_pcmu2opus_runner_new; +static __typeof__(codec_chain_client_opus2pcma_runner_new) *cc_client_opus2pcma_runner_new; +static __typeof__(codec_chain_client_opus2pcmu_runner_new) *cc_client_opus2pcmu_runner_new; -static gpu_pcma2opus_runner_do_fn *gpu_pcma2opus_runner_do; -static gpu_pcmu2opus_runner_do_fn *gpu_pcmu2opus_runner_do; -static gpu_opus2pcma_runner_do_fn *gpu_opus2pcma_runner_do; -static gpu_opus2pcmu_runner_do_fn *gpu_opus2pcmu_runner_do; +static __typeof__(codec_chain_pcma2opus_runner_do) *cc_pcma2opus_runner_do; +static __typeof__(codec_chain_pcmu2opus_runner_do) *cc_pcmu2opus_runner_do; +static __typeof__(codec_chain_opus2pcma_runner_do) *cc_opus2pcma_runner_do; +static __typeof__(codec_chain_opus2pcmu_runner_do) *cc_opus2pcmu_runner_do; -static gpu_float2opus_new_fn *gpu_float2opus_new; -static gpu_opus2float_new_fn *gpu_opus2float_new; +static __typeof__(codec_chain_client_float2opus_new) *cc_client_float2opus_new; +static __typeof__(codec_chain_client_opus2float_new) *cc_client_opus2float_new; -static gpu_pcma2opus_runner *pcma2opus_runner; -static gpu_pcmu2opus_runner *pcmu2opus_runner; -static gpu_opus2pcmu_runner *opus2pcmu_runner; -static gpu_opus2pcma_runner *opus2pcma_runner; +static codec_chain_client *cc_client; + +static codec_chain_pcma2opus_runner *pcma2opus_runner; +static codec_chain_pcmu2opus_runner *pcmu2opus_runner; +static codec_chain_opus2pcmu_runner *opus2pcmu_runner; +static codec_chain_opus2pcma_runner *opus2pcma_runner; struct codec_chain_s { union { struct { - gpu_pcmu2opus_runner *runner; - gpu_float2opus *enc; + codec_chain_pcmu2opus_runner *runner; + codec_chain_float2opus *enc; } pcmu2opus; struct { - gpu_pcma2opus_runner *runner; - gpu_float2opus *enc; + codec_chain_pcma2opus_runner *runner; + codec_chain_float2opus *enc; } pcma2opus; struct { - gpu_opus2pcmu_runner *runner; - gpu_opus2float *dec; + codec_chain_opus2pcmu_runner *runner; + codec_chain_opus2float *dec; } opus2pcmu; struct { - gpu_opus2pcma_runner *runner; - gpu_opus2float *dec; + codec_chain_opus2pcma_runner *runner; + codec_chain_opus2float *dec; } opus2pcma; } u; AVPacket *avpkt; @@ -1225,8 +1228,8 @@ void codeclib_free(void) { avformat_network_deinit(); if (evs_lib_handle) dlclose(evs_lib_handle); - if (cudecs_lib_handle) - dlclose(cudecs_lib_handle); + if (codec_chain_lib_handle) + dlclose(codec_chain_lib_handle); } @@ -1275,22 +1278,32 @@ static void *dlsym_assert(void *handle, const char *sym, const char *fn) { } -#ifdef HAVE_CUDECS -static void cudecs_dlsym_resolve(const char *fn) { - gpu_init = dlsym_assert(cudecs_lib_handle, "gpu_init", fn); +#ifdef HAVE_CODEC_CHAIN +static void codec_chain_dlsym_resolve(const char *fn) { + cc_client_connect = dlsym_assert(codec_chain_lib_handle, "codec_chain_client_connect", fn); - gpu_pcma2opus_runner_new = dlsym_assert(cudecs_lib_handle, "gpu_pcma2opus_runner_new", fn); - gpu_pcmu2opus_runner_new = dlsym_assert(cudecs_lib_handle, "gpu_pcmu2opus_runner_new", fn); - gpu_opus2pcma_runner_new = dlsym_assert(cudecs_lib_handle, "gpu_opus2pcma_runner_new", fn); - gpu_opus2pcmu_runner_new = dlsym_assert(cudecs_lib_handle, "gpu_opus2pcmu_runner_new", fn); + cc_client_pcma2opus_runner_new = dlsym_assert(codec_chain_lib_handle, + "codec_chain_client_pcma2opus_runner_new", fn); + cc_client_pcmu2opus_runner_new = dlsym_assert(codec_chain_lib_handle, + "codec_chain_client_pcmu2opus_runner_new", fn); + cc_client_opus2pcma_runner_new = dlsym_assert(codec_chain_lib_handle, + "codec_chain_client_opus2pcma_runner_new", fn); + cc_client_opus2pcmu_runner_new = dlsym_assert(codec_chain_lib_handle, + "codec_chain_client_opus2pcmu_runner_new", fn); - gpu_pcma2opus_runner_do = dlsym_assert(cudecs_lib_handle, "gpu_pcma2opus_runner_do", fn); - gpu_pcmu2opus_runner_do = dlsym_assert(cudecs_lib_handle, "gpu_pcmu2opus_runner_do", fn); - gpu_opus2pcma_runner_do = dlsym_assert(cudecs_lib_handle, "gpu_opus2pcma_runner_do", fn); - gpu_opus2pcmu_runner_do = dlsym_assert(cudecs_lib_handle, "gpu_opus2pcmu_runner_do", fn); + cc_pcma2opus_runner_do = dlsym_assert(codec_chain_lib_handle, + "codec_chain_pcma2opus_runner_do", fn); + cc_pcmu2opus_runner_do = dlsym_assert(codec_chain_lib_handle, + "codec_chain_pcmu2opus_runner_do", fn); + cc_opus2pcma_runner_do = dlsym_assert(codec_chain_lib_handle, + "codec_chain_opus2pcma_runner_do", fn); + cc_opus2pcmu_runner_do = dlsym_assert(codec_chain_lib_handle, + "codec_chain_opus2pcmu_runner_do", fn); - gpu_float2opus_new = dlsym_assert(cudecs_lib_handle, "gpu_float2opus_new", fn); - gpu_opus2float_new = dlsym_assert(cudecs_lib_handle, "gpu_opus2float_new", fn); + cc_client_float2opus_new = dlsym_assert(codec_chain_lib_handle, + "codec_chain_client_float2opus_new", fn); + cc_client_opus2float_new = dlsym_assert(codec_chain_lib_handle, + "codec_chain_client_opus2float_new", fn); } #endif @@ -1307,31 +1320,33 @@ void codeclib_init(int print) { codecs_ht = g_hash_table_new(str_case_hash, str_case_equal); codecs_ht_by_av = g_hash_table_new(g_direct_hash, g_direct_equal); -#ifdef HAVE_CUDECS - if (rtpe_common_config_ptr->cudecs_lib_path) { - cudecs_lib_handle = dlopen(rtpe_common_config_ptr->cudecs_lib_path, RTLD_NOW | RTLD_LOCAL); - if (!cudecs_lib_handle) - die("Failed to load CUDA codecs .so '%s': %s", rtpe_common_config_ptr->cudecs_lib_path, +#ifdef HAVE_CODEC_CHAIN + if (rtpe_common_config_ptr->codec_chain_lib_path) { + codec_chain_lib_handle = dlopen(rtpe_common_config_ptr->codec_chain_lib_path, RTLD_NOW | RTLD_LOCAL); + if (!codec_chain_lib_handle) + die("Failed to load libcodec-chain.so '%s': %s", + rtpe_common_config_ptr->codec_chain_lib_path, dlerror()); - cudecs_dlsym_resolve(rtpe_common_config_ptr->cudecs_lib_path); + codec_chain_dlsym_resolve(rtpe_common_config_ptr->codec_chain_lib_path); - if (!gpu_init()) - die("Failed to initialise CUDA codecs"); + cc_client = cc_client_connect(4); + if (!cc_client) + die("Failed to connect to cudecsd"); - pcma2opus_runner = gpu_pcma2opus_runner_new(4, 3000, 160); + pcma2opus_runner = cc_client_pcma2opus_runner_new(cc_client, 4, 3000, 160); if (!pcma2opus_runner) die("Failed to initialise GPU pcma2opus"); - pcmu2opus_runner = gpu_pcmu2opus_runner_new(4, 3000, 160); + pcmu2opus_runner = cc_client_pcmu2opus_runner_new(cc_client, 4, 3000, 160); if (!pcmu2opus_runner) die("Failed to initialise GPU pcmu2opus"); - opus2pcmu_runner = gpu_opus2pcmu_runner_new(4, 3000, 160); + opus2pcmu_runner = cc_client_opus2pcmu_runner_new(cc_client, 4, 3000, 160); if (!opus2pcmu_runner) die("Failed to initialise GPU opus2pcmu"); - opus2pcma_runner = gpu_opus2pcma_runner_new(4, 3000, 160); + opus2pcma_runner = cc_client_opus2pcma_runner_new(cc_client, 4, 3000, 160); if (!opus2pcma_runner) die("Failed to initialise GPU opus2pcma"); @@ -4656,9 +4671,9 @@ static int evs_dtx(decoder_t *dec, GQueue *out, int ptime) { -#ifdef HAVE_CUDECS +#ifdef HAVE_CODEC_CHAIN int codec_chain_pcmu2opus_run(codec_chain_t *c, const str *data, unsigned long ts, AVPacket *pkt) { - ssize_t ret = gpu_pcmu2opus_runner_do(c->u.pcmu2opus.runner, c->u.pcmu2opus.enc, + ssize_t ret = cc_pcmu2opus_runner_do(c->u.pcmu2opus.runner, c->u.pcmu2opus.enc, (unsigned char *) data->s, data->len, pkt->data, pkt->size); assert(ret > 0); @@ -4671,7 +4686,7 @@ int codec_chain_pcmu2opus_run(codec_chain_t *c, const str *data, unsigned long t } int codec_chain_pcma2opus_run(codec_chain_t *c, const str *data, unsigned long ts, AVPacket *pkt) { - ssize_t ret = gpu_pcma2opus_runner_do(c->u.pcma2opus.runner, c->u.pcma2opus.enc, + ssize_t ret = cc_pcma2opus_runner_do(c->u.pcma2opus.runner, c->u.pcma2opus.enc, (unsigned char *) data->s, data->len, pkt->data, pkt->size); assert(ret > 0); @@ -4684,7 +4699,7 @@ int codec_chain_pcma2opus_run(codec_chain_t *c, const str *data, unsigned long t } int codec_chain_opus2pcmu_run(codec_chain_t *c, const str *data, unsigned long ts, AVPacket *pkt) { - ssize_t ret = gpu_opus2pcmu_runner_do(c->u.opus2pcmu.runner, c->u.opus2pcmu.dec, + ssize_t ret = cc_opus2pcmu_runner_do(c->u.opus2pcmu.runner, c->u.opus2pcmu.dec, (unsigned char *) data->s, data->len, pkt->data, pkt->size); assert(ret > 0); @@ -4697,7 +4712,7 @@ int codec_chain_opus2pcmu_run(codec_chain_t *c, const str *data, unsigned long t } int codec_chain_opus2pcma_run(codec_chain_t *c, const str *data, unsigned long ts, AVPacket *pkt) { - ssize_t ret = gpu_opus2pcma_runner_do(c->u.opus2pcma.runner, c->u.opus2pcma.dec, + ssize_t ret = cc_opus2pcma_runner_do(c->u.opus2pcma.runner, c->u.opus2pcma.dec, (unsigned char *) data->s, data->len, pkt->data, pkt->size); assert(ret > 0); @@ -4715,7 +4730,7 @@ int codec_chain_opus2pcma_run(codec_chain_t *c, const str *data, unsigned long t codec_chain_t *codec_chain_new(codec_def_t *src, format_t *src_format, codec_def_t *dst, format_t *dst_format, int bitrate, int ptime) { -#ifdef HAVE_CUDECS +#ifdef HAVE_CODEC_CHAIN if (!strcmp(dst->rtpname, "opus") && !strcmp(src->rtpname, "PCMA")) { if (src_format->clockrate != 8000) return NULL; @@ -4730,7 +4745,7 @@ codec_chain_t *codec_chain_new(codec_def_t *src, format_t *src_format, codec_def return NULL; codec_chain_t *ret = g_slice_alloc0(sizeof(*ret)); - ret->u.pcma2opus.enc = gpu_float2opus_new(bitrate); + ret->u.pcma2opus.enc = cc_client_float2opus_new(cc_client, bitrate); ret->u.pcma2opus.runner = pcma2opus_runner; ret->avpkt = av_packet_alloc(); ret->run = codec_chain_pcma2opus_run; @@ -4751,7 +4766,7 @@ codec_chain_t *codec_chain_new(codec_def_t *src, format_t *src_format, codec_def return NULL; codec_chain_t *ret = g_slice_alloc0(sizeof(*ret)); - ret->u.pcmu2opus.enc = gpu_float2opus_new(bitrate); + ret->u.pcmu2opus.enc = cc_client_float2opus_new(cc_client, bitrate); ret->u.pcmu2opus.runner = pcmu2opus_runner; ret->avpkt = av_packet_alloc(); ret->run = codec_chain_pcmu2opus_run; @@ -4772,7 +4787,7 @@ codec_chain_t *codec_chain_new(codec_def_t *src, format_t *src_format, codec_def return NULL; codec_chain_t *ret = g_slice_alloc0(sizeof(*ret)); - ret->u.opus2pcmu.dec = gpu_opus2float_new(); + ret->u.opus2pcmu.dec = cc_client_opus2float_new(cc_client); ret->u.opus2pcmu.runner = opus2pcmu_runner; ret->avpkt = av_packet_alloc(); ret->run = codec_chain_opus2pcmu_run; @@ -4793,7 +4808,7 @@ codec_chain_t *codec_chain_new(codec_def_t *src, format_t *src_format, codec_def return NULL; codec_chain_t *ret = g_slice_alloc0(sizeof(*ret)); - ret->u.opus2pcma.dec = gpu_opus2float_new(); + ret->u.opus2pcma.dec = cc_client_opus2float_new(cc_client); ret->u.opus2pcma.runner = opus2pcma_runner; ret->avpkt = av_packet_alloc(); ret->run = codec_chain_opus2pcma_run; @@ -4806,7 +4821,7 @@ codec_chain_t *codec_chain_new(codec_def_t *src, format_t *src_format, codec_def } AVPacket *codec_chain_input_data(codec_chain_t *c, const str *data, unsigned long ts) { -#ifdef HAVE_CUDECS +#ifdef HAVE_CODEC_CHAIN av_new_packet(c->avpkt, MAX_OPUS_FRAME_SIZE * MAX_OPUS_FRAMES_PER_PACKET + MAX_OPUS_HEADER_SIZE); int ret = c->run(c, data, ts, c->avpkt); diff --git a/lib/cudecs.Makefile b/lib/cudecs.Makefile deleted file mode 100644 index 5e9c08608..000000000 --- a/lib/cudecs.Makefile +++ /dev/null @@ -1,7 +0,0 @@ -ifneq (,$(filter pkg.ngcp-rtpengine.cudecs,${DEB_BUILD_PROFILES})) -ifneq (,$(wildcard $(CUDECS_HOME)/usr/include/cudecs/g711opus.h)) -CFLAGS+= -DHAVE_CUDECS -I$(CUDECS_HOME)/usr/include -else ifneq (,$(wildcard /usr/include/cudecs/g711opus.h)) -CFLAGS+= -DHAVE_CUDECS -endif -endif diff --git a/perf-tester/Makefile b/perf-tester/Makefile index b9df02d07..30836f89c 100644 --- a/perf-tester/Makefile +++ b/perf-tester/Makefile @@ -37,7 +37,7 @@ LDLIBS += $(shell pkg-config --libs ncursesw) LDLIBS += $(shell pkg-config --libs openssl) include ../lib/g729.Makefile -include ../lib/cudecs.Makefile +include ../lib/codec-chain.Makefile SRCS = main.c log.c LIBSRCS = codeclib.strhash.c loglib.c auxlib.c resample.c str.c dtmflib.c rtplib.c poller.c ssllib.c diff --git a/pkg/deb/generator.sh b/pkg/deb/generator.sh index ba5cd3ccd..6d0db9cc1 100755 --- a/pkg/deb/generator.sh +++ b/pkg/deb/generator.sh @@ -31,7 +31,7 @@ done < <(find debian -name '*links') echo "- Remove NGCP packages from control" sed -i -e '/ngcp-system-tools/d' debian/control -sed -i -e '/ngcp-libcudecs/d' debian/control +sed -i -e '/ngcp-libcodec-chain/d' debian/control echo "- Set package-specific homepage" sed -i -e 's,^Homepage:.*,Homepage: https://rtpengine.com/,' debian/control