Skip to content

Commit

Permalink
MT#54294 convert cudecs usage to plugin
Browse files Browse the repository at this point in the history
*) Remove packaging for -gpu packages
*) Remove build profile restrictions, except for the build dependency
   itself
*) Remove script to generate dh fragments for -gpu packages
*) Convert --cudecs switch to a path argument pointing to the .so
*) Don't link against libcudecs during build
*) Only include the single types.h header needed for usage as a plugin
*) Resolve all symbols during startup after loading the .so

Change-Id: Ide99eec2156d5d3be8c40594391cb1603add4b16
  • Loading branch information
rfuchs committed Sep 21, 2023
1 parent f991930 commit b82b31e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 147 deletions.
94 changes: 2 additions & 92 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Testsuite: autopkgtest-pkg-dkms

Package: ngcp-rtpengine-daemon
Architecture: any
Build-Profiles: <!pkg.ngcp-rtpengine.cudecs>
Multi-Arch: foreign
Recommends:
ngcp-rtpengine-perftest,
Expand All @@ -76,7 +75,7 @@ Description: proxy for RTP and media streams used in NGCP, userspace part

Package: ngcp-rtpengine-recording-daemon
Architecture: any
Build-Profiles: <!pkg.ngcp-rtpengine.cudecs !pkg.ngcp-rtpengine.no-transcoding>
Build-Profiles: <!pkg.ngcp-rtpengine.no-transcoding>
Multi-Arch: foreign
Recommends:
ngcp-rtpengine-utils,
Expand All @@ -102,7 +101,6 @@ Description: IPtables extension module for the kernel-space NGCP media proxy

Package: ngcp-rtpengine
Architecture: all
Build-Profiles: <!pkg.ngcp-rtpengine.cudecs>
Multi-Arch: foreign
Depends:
ngcp-rtpengine-daemon (>= ${source:Version}),
Expand Down Expand Up @@ -150,7 +148,7 @@ Description: scripts and Perl modules for NGCP rtpengine

Package: ngcp-rtpengine-perftest
Architecture: any
Build-Profiles: <!pkg.ngcp-rtpengine.cudecs !pkg.ngcp-rtpengine.no-transcoding>
Build-Profiles: <!pkg.ngcp-rtpengine.no-transcoding>
Multi-Arch: foreign
Depends:
ngcp-rtpengine-perftest-data (= ${source:Version}),
Expand All @@ -172,91 +170,3 @@ Description: helper tool to test rtpengine transcoding performance - data files
base and produces performance and load statistics.
.
These are data files needed for the binary package.

Package: ngcp-rtpengine-daemon-gpu
Architecture: any
Build-Profiles: <pkg.ngcp-rtpengine.cudecs>
Multi-Arch: foreign
Conflicts:
ngcp-rtpengine-daemon,
Provides:
ngcp-rtpengine-daemon,
Recommends:
ngcp-rtpengine-perftest-gpu,
ngcp-rtpengine-recording-daemon-gpu,
ngcp-rtpengine-utils,
Suggests:
ngcp-system-tools,
Pre-Depends:
adduser,
${misc:Pre-Depends},
Depends:
iptables,
sysvinit-utils (>= 3.05-4~) | lsb-base (>= 3.0-6),
${misc:Depends},
${shlibs:Depends},
Description: proxy for RTP and media streams incl GPU transcoding, userspace part
This daemon handles the first stages of proxying media streams and talks to
the kernel part of the proxy for eventual high-performance packet forwarding.
This build includes support for GPU transcoding.

Package: ngcp-rtpengine-recording-daemon-gpu
Architecture: any
Multi-Arch: foreign
Build-Profiles: <pkg.ngcp-rtpengine.cudecs !pkg.ngcp-rtpengine.no-transcoding>
Conflicts:
ngcp-rtpengine-recording-daemon,
Provides:
ngcp-rtpengine-recording-daemon,
Recommends:
ngcp-rtpengine-utils,
Suggests:
ngcp-system-tools,
Depends:
nfs-common,
ngcp-rtpengine-daemon-gpu,
sysvinit-utils (>= 3.05-4~) | lsb-base (>= 3.0-6),
${misc:Depends},
${shlibs:Depends},
Description: recording daemon for RTP and media streams incl GPU transcodnig
This daemon handles the call recording (media intercept) component of rtpengine.
This build includes support for GPU transcoding.

Package: ngcp-rtpengine-gpu
Architecture: all
Build-Profiles: <pkg.ngcp-rtpengine.cudecs>
Multi-Arch: foreign
Conflicts:
ngcp-rtpengine,
Provides:
ngcp-rtpengine,
Depends:
ngcp-rtpengine-daemon-gpu (>= ${source:Version}),
ngcp-rtpengine-iptables (>= ${source:Version}),
ngcp-rtpengine-kernel-dkms (>= ${source:Version}),
ngcp-rtpengine-perftest-gpu (>= ${source:Version}),
ngcp-rtpengine-recording-daemon-gpu (>= ${source:Version}),
ngcp-rtpengine-utils (>= ${source:Version}),
${misc:Depends},
Description: NGCP RTP/media proxy incl GPU transcoding - meta package
This is a meta package for easy installation of all four parts of the NGCP
media proxy. It will install the user-space daemon, the kernel-space IPtables
module, the IPtables extension module and utility scripts.
This build includes support for GPU transcoding.

Package: ngcp-rtpengine-perftest-gpu
Architecture: any
Multi-Arch: foreign
Build-Profiles: <!pkg.ngcp-rtpengine.no-transcoding pkg.ngcp-rtpengine.cudecs>
Conflicts:
ngcp-rtpengine-perftest,
Provides:
ngcp-rtpengine-perftest,
Depends:
ngcp-rtpengine-perftest-data (= ${source:Version}),
${misc:Depends},
${shlibs:Depends},
Description: helper tool to test rtpengine transcoding performance incl GPU transcoding
This interactive tool simulates transcoding scenarios using the rtpengine code
base and produces performance and load statistics.
This build includes support for GPU transcoding.
28 changes: 0 additions & 28 deletions debian/generate-gpu-dh-fragments.sh

This file was deleted.

7 changes: 0 additions & 7 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,14 @@ export FIXTURES_PATH = /usr/share/rtpengine-perftest

execute_before_dh_auto_configure:
(cd debian && sh generate-systemd-templates.sh)
ifneq (,$(filter $(DEB_BUILD_PROFILES),pkg.ngcp-rtpengine.cudecs))
(cd debian && ./generate-gpu-dh-fragments.sh)
endif

execute_before_dh_auto_install-indep:
# markdown README
markdown README.md | gzip -9 > debian/README.html.gz
gzip -9 < README.md > debian/README.md.gz

execute_after_dh_installsystemd:
ifneq (,$(filter $(DEB_BUILD_PROFILES),pkg.ngcp-rtpengine.cudecs))
dh_installsystemd -pngcp-rtpengine-recording-daemon-gpu --name=ngcp-rtpengine-recording-nfs-mount
else
dh_installsystemd -pngcp-rtpengine-recording-daemon --name=ngcp-rtpengine-recording-nfs-mount
endif

override_dh_dkms:
dh_dkms -p$(DEB_SOURCE)-kernel-dkms -V $(DEB_VERSION_UPSTREAM)
2 changes: 1 addition & 1 deletion lib/auxlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
{ "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", 0,0, G_OPTION_ARG_NONE, &rtpe_common_config_ptr->cudecs, "Enable usage of CUDA codecs", NULL },
{ "cudecs-lib-path", 0,0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->cudecs_lib_path,"Location of .so for CUDA codecs", "FILE" },
#endif
{ NULL, }
};
Expand Down
2 changes: 1 addition & 1 deletion lib/auxlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct rtpengine_common_config {
int poller_size;
int max_log_line_length;
char *evs_lib_path;
int cudecs;
char *cudecs_lib_path;
};

extern struct rtpengine_common_config *rtpe_common_config_ptr;
Expand Down
70 changes: 56 additions & 14 deletions lib/codeclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#endif
#include <opus.h>
#ifdef HAVE_CUDECS
#include <cudecs/g711opus.h>
#include <cudecs/gpu-utils.h>
#include <cudecs/gpu-opus.h>
#include <cudecs/types.h>
#endif
#include "str.h"
#include "log.h"
Expand Down Expand Up @@ -143,8 +141,31 @@ static select_encoder_format_f evs_select_encoder_format;



struct codec_chain_s {
static void *cudecs_lib_handle;

#ifdef HAVE_CUDECS

static gpu_init_fn *gpu_init;

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 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 gpu_float2opus_new_fn *gpu_float2opus_new;
static gpu_opus2float_new_fn *gpu_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;

struct codec_chain_s {
union {
struct {
gpu_pcmu2opus_runner *runner;
Expand All @@ -165,8 +186,8 @@ struct codec_chain_s {
} u;
AVPacket *avpkt;
int (*run)(codec_chain_t *c, const str *data, unsigned long ts, AVPacket *);
#endif
};
#endif



Expand Down Expand Up @@ -271,14 +292,6 @@ static const codec_type_t codec_type_bcg729 = {
#endif


#ifdef HAVE_CUDECS
static gpu_pcma2opus_runner *pcma2opus_runner;
static gpu_pcmu2opus_runner *pcmu2opus_runner;
static gpu_opus2pcmu_runner *opus2pcmu_runner;
static gpu_opus2pcma_runner *opus2pcma_runner;
#endif



static struct codec_def_s __codec_defs[] = {
{
Expand Down Expand Up @@ -1211,6 +1224,8 @@ void codeclib_free(void) {
avformat_network_deinit();
if (evs_lib_handle)
dlclose(evs_lib_handle);
if (cudecs_lib_handle)
dlclose(cudecs_lib_handle);
}


Expand Down Expand Up @@ -1259,6 +1274,26 @@ 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);

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);

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);

gpu_float2opus_new = dlsym_assert(cudecs_lib_handle, "gpu_float2opus_new", fn);
gpu_opus2float_new = dlsym_assert(cudecs_lib_handle, "gpu_opus2float_new", fn);
}
#endif


void codeclib_init(int print) {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
av_register_all();
Expand All @@ -1272,7 +1307,14 @@ void codeclib_init(int print) {
codecs_ht_by_av = g_hash_table_new(g_direct_hash, g_direct_equal);

#ifdef HAVE_CUDECS
if (rtpe_common_config_ptr->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,
dlerror());

cudecs_dlsym_resolve(rtpe_common_config_ptr->cudecs_lib_path);

if (!gpu_init())
die("Failed to initialise CUDA codecs");

Expand Down
2 changes: 0 additions & 2 deletions lib/cudecs.Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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
LDLIBS+= -L$(CUDECS_HOME)/usr/lib -lcudecs
else ifneq (,$(wildcard /usr/include/cudecs/g711opus.h))
CFLAGS+= -DHAVE_CUDECS
LDLIBS+= -lcudecs
endif
endif
2 changes: 0 additions & 2 deletions pkg/deb/generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ 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 -n -e '/-gpu/ q; p' debian/control

echo "- Set package-specific homepage"
sed -i -e 's,^Homepage:.*,Homepage: https://rtpengine.com/,' debian/control

echo "- Add Conflicts with NGCP packages"
# TODO: prevent duplicate "Conflicts" when -gpu packages are left in place
while read -r line ; do
sed -i "/${line}$/ a Conflicts: ngcp-${line#Package: }" debian/control
done < <(awk '/Package:/' debian/control)
Expand Down

0 comments on commit b82b31e

Please sign in to comment.