Skip to content

Commit

Permalink
examples/hls2rtp: add OpenSSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
quarium committed Dec 3, 2024
1 parent 695e74e commit 0877540
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 30 deletions.
4 changes: 4 additions & 0 deletions examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ UPIPEOSX_LIBS = $(top_builddir)/lib/upipe-osx/libupipe_osx.la
UPIPEDVBCSA_LIBS = $(top_builddir)/lib/upipe-dvbcsa/libupipe_dvbcsa.la
UPIPEDVB_LIBS = $(top_builddir)/lib/upipe-dvb/libupipe_dvb.la
UPIPEBEARSSL_LIBS = $(top_builddir)/lib/upipe-bearssl/libupipe_bearssl.la
UPIPEOPENSSL_LIBS = $(top_builddir)/lib/upipe-openssl/libupipe_openssl.la

noinst_PROGRAMS =

Expand All @@ -29,6 +30,9 @@ rist_tx_LDADD = $(LDADD) $(UPUMPEV_LIBS) $(UPIPEMODULES_LIBS) $(UPIPEFILTERS_LIB
udpmulticat_LDADD = $(LDADD) $(UPUMPEV_LIBS) $(UPIPEMODULES_LIBS)
multicatudp_LDADD = $(LDADD) $(UPUMPEV_LIBS) $(UPIPEMODULES_LIBS) $(UPIPEPTHREAD_LIBS) -lpthread
hls2rtp_LDADD= $(LDADD) $(UPUMPEV_LIBS) $(UPIPEMODULES_LIBS) $(UPIPEFRAMERS_LIBS) $(UPIPETS_LIBS) $(UPIPEHLS_LIBS) $(UPIPEPTHREAD_LIBS) -lpthread
if HAVE_OPENSSL
hls2rtp_LDADD += $(UPIPEOPENSSL_LIBS)
endif
if HAVE_BEARSSL
hls2rtp_LDADD += $(UPIPEBEARSSL_LIBS)
endif
Expand Down
105 changes: 75 additions & 30 deletions examples/hls2rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
#include "upipe-pthread/uprobe_pthread_upump_mgr.h"
#include "upipe-pthread/upipe_pthread_transfer.h"
#include "upipe-pthread/umutex_pthread.h"
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
#include "upipe-openssl/uprobe_https_openssl.h"
#endif
#ifdef UPIPE_HAVE_BEARSSL_H
#include "upipe-bearssl/uprobe_https_bearssl.h"
#endif
Expand Down Expand Up @@ -1261,7 +1264,7 @@ enum opt {
OPT_MTU = 'M',
OPT_CONFORMANCE = 'K',

OPT_ID = 0x100,
OPT_ID = 0x100,
OPT_ADDR,
OPT_TS,
OPT_VIDEO_PORT,
Expand All @@ -1284,37 +1287,49 @@ enum opt {
OPT_DELAY,
OPT_QUIT_TIMEOUT,
OPT_USER_AGENT,
#ifdef UPIPE_HAVE_BEARSSL_H
OPT_USE_BEARSSL,
#endif
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
OPT_USE_OPENSSL,
#endif
};

static struct option options[] = {
{ "id", required_argument, NULL, OPT_ID },
{ "addr", required_argument, NULL, OPT_ADDR },
{ "ts", no_argument, NULL, OPT_TS },
{ "video-port", required_argument, NULL, OPT_VIDEO_PORT },
{ "audio-port", required_argument, NULL, OPT_AUDIO_PORT },
{ "no-video", no_argument, NULL, OPT_NO_VIDEO },
{ "no-audio", no_argument, NULL, OPT_NO_AUDIO },
{ "no-color", no_argument, NULL, OPT_NO_COLOR },
{ "rewrite-date", no_argument, NULL, OPT_REWRITE_DATE },
{ "verbose", no_argument, NULL, OPT_VERBOSE },
{ "seek", required_argument, NULL, OPT_SEEK },
{ "sequence", required_argument, NULL, OPT_SEQUENCE },
{ "bandwidth", required_argument, NULL, OPT_BANDWIDTH },
{ "time-limit", required_argument, NULL, OPT_TIME_LIMIT },
{ "rt-priority", required_argument, NULL, OPT_RT_PRIORITY },
{ "syslog-tag", required_argument, NULL, OPT_SYSLOG_TAG },
{ "mtu", required_argument, NULL, OPT_MTU },
{ "udp", no_argument, NULL, OPT_UDP },
{ "conformance", required_argument, NULL, OPT_CONFORMANCE },
{ "no-stdin", no_argument, NULL, OPT_NO_STDIN },
{ "dump", required_argument, NULL, OPT_DUMP },
{ "help", no_argument, NULL, OPT_HELP },
{ "mux-max-delay", required_argument, NULL, OPT_MUX_MAX_DELAY },
{ "min-deviation", required_argument, NULL, OPT_MIN_DEVIATION },
{ "delay", required_argument, NULL, OPT_DELAY },
{ "quit-timeout", required_argument, NULL, OPT_QUIT_TIMEOUT },
{ "user-agent", required_argument, NULL, OPT_USER_AGENT },
{ 0, 0, 0, 0 },
{"id", required_argument, NULL, OPT_ID},
{"addr", required_argument, NULL, OPT_ADDR},
{"ts", no_argument, NULL, OPT_TS},
{"video-port", required_argument, NULL, OPT_VIDEO_PORT},
{"audio-port", required_argument, NULL, OPT_AUDIO_PORT},
{"no-video", no_argument, NULL, OPT_NO_VIDEO},
{"no-audio", no_argument, NULL, OPT_NO_AUDIO},
{"no-color", no_argument, NULL, OPT_NO_COLOR},
{"rewrite-date", no_argument, NULL, OPT_REWRITE_DATE},
{"verbose", no_argument, NULL, OPT_VERBOSE},
{"seek", required_argument, NULL, OPT_SEEK},
{"sequence", required_argument, NULL, OPT_SEQUENCE},
{"bandwidth", required_argument, NULL, OPT_BANDWIDTH},
{"time-limit", required_argument, NULL, OPT_TIME_LIMIT},
{"rt-priority", required_argument, NULL, OPT_RT_PRIORITY},
{"syslog-tag", required_argument, NULL, OPT_SYSLOG_TAG},
{"mtu", required_argument, NULL, OPT_MTU},
{"udp", no_argument, NULL, OPT_UDP},
{"conformance", required_argument, NULL, OPT_CONFORMANCE},
{"no-stdin", no_argument, NULL, OPT_NO_STDIN},
{"dump", required_argument, NULL, OPT_DUMP},
{"help", no_argument, NULL, OPT_HELP},
{"mux-max-delay", required_argument, NULL, OPT_MUX_MAX_DELAY},
{"min-deviation", required_argument, NULL, OPT_MIN_DEVIATION},
{"delay", required_argument, NULL, OPT_DELAY},
{"quit-timeout", required_argument, NULL, OPT_QUIT_TIMEOUT},
{"user-agent", required_argument, NULL, OPT_USER_AGENT},
#ifdef UPIPE_HAVE_BEARSSL_H
{"use-bearssl", no_argument, NULL, OPT_USE_BEARSSL},
#endif
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
{"use-openssl", no_argument, NULL, OPT_USE_OPENSSL},
#endif
{0, 0, 0, 0},
};

UBASE_FMT_PRINTF(2, 3)
Expand Down Expand Up @@ -1354,6 +1369,14 @@ int main(int argc, char **argv)
enum upipe_ts_conformance conformance = UPIPE_TS_CONFORMANCE_AUTO;
bool no_stdin = false;

#ifdef UPIPE_HAVE_BEARSSL_H
bool use_bearssl = true;
#endif

#ifdef UPIPE_HAVE_OPENSSL_SSL_H
bool use_openssl = true;
#endif

/*
* parse options
*/
Expand Down Expand Up @@ -1458,7 +1481,21 @@ int main(int argc, char **argv)

case OPT_MISSING_ARG:
return usage(argv[0], "missing argument");

#ifdef UPIPE_HAVE_BEARSSL_H
case OPT_USE_BEARSSL:
use_bearssl = true;
use_openssl = false;
break;
#endif

#ifdef UPIPE_HAVE_OPENSSL_SSL_H
case OPT_USE_OPENSSL:
use_bearssl = false;
use_openssl = true;
break;
}
#endif
}

/*
Expand Down Expand Up @@ -1751,9 +1788,17 @@ int main(int argc, char **argv)
uprobe_init(&probe_src, catch_src, uprobe_use(main_probe));
uprobe_release(main_probe);
main_probe = &probe_src;

#ifdef UPIPE_HAVE_OPENSSL_SSL_H
if (use_openssl)
main_probe = uprobe_https_openssl_alloc(main_probe);
#endif

#ifdef UPIPE_HAVE_BEARSSL_H
main_probe = uprobe_https_bearssl_alloc(main_probe);
if (use_bearssl)
main_probe = uprobe_https_bearssl_alloc(main_probe);
#endif

{
struct upipe_mgr *upipe_auto_src_mgr = upipe_auto_src_mgr_alloc();
assert(upipe_auto_src_mgr);
Expand Down

0 comments on commit 0877540

Please sign in to comment.