Talker / Listener example host application.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include "openavb_plugin.h"
#include "openavb_trace_pub.h"
#ifdef AVB_FEATURE_GSTREAMER
#include <gst/gst.h>
#endif
#define AVB_LOG_COMPONENT "TL Host"
#include "openavb_log_pub.h"
static void openavbTLSigHandler(int signal)
{
AVB_TRACE_ENTRY(AVB_TRACE_HOST);
if (signal == SIGINT) {
AVB_LOG_INFO("Host shutting down");
}
else if (signal == SIGUSR1) {
AVB_LOG_DEBUG("Waking up streaming thread");
}
else {
AVB_LOG_ERROR("Unexpected signal");
}
AVB_TRACE_EXIT(AVB_TRACE_HOST);
}
void openavbTlHostUsage(char *programName)
{
printf(
"\n"
"Usage: %s [options] file...\n"
" -I val Use given (val) interface globally, can be overriden by giving the ifname= option to the config line.\n"
"\n"
"Examples:\n"
" %s talker.ini\n"
" Start 1 stream with data from the ini file.\n\n"
" %s talker1.ini talker2.ini\n"
" Start 2 streams with data from the ini files.\n\n"
" %s -I eth0 talker1.ini talker2.ini\n"
" Start 2 streams with data from the ini files, both talkers use eth0 interface.\n\n"
" %s -I eth0 talker1.ini talker2.ini listener1.ini,ifname=pcap:eth0\n"
" Start 3 streams with data from the ini files, talkers 1&2 use eth0 interface, listener1 use pcap:eth0.\n\n"
,
programName, programName, programName, programName, programName);
}
int main(int argc, char *argv[])
{
AVB_TRACE_ENTRY(AVB_TRACE_HOST);
int iniIdx = 0;
char *programName;
char *optIfnameGlobal =
NULL;
programName = strrchr(argv[0], '/');
programName = programName ? programName + 1 : argv[0];
if (argc < 2) {
openavbTlHostUsage(programName);
exit(-1);
}
int i1;
while (!optDone) {
int opt = getopt(argc, argv, "hI:");
if (opt != EOF) {
switch (opt) {
case 'I':
optIfnameGlobal = strdup(optarg);
break;
case 'h':
default:
openavbTlHostUsage(programName);
exit(-1);
}
}
else {
}
}
osalAVBInitialize(optIfnameGlobal);
iniIdx = optind;
U32 tlCount = argc - iniIdx;
AVB_LOG_ERROR("Unable to initialize talker listener library");
osalAVBFinalize();
exit(-1);
}
bool err;
struct sigaction sa;
sa.sa_handler = openavbTLSigHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
err = sigaction(SIGINT, &sa,
NULL);
if (err)
{
AVB_LOG_ERROR("Failed to setup SIGINT handler");
osalAVBFinalize();
exit(-1);
}
err = sigaction(SIGUSR1, &sa,
NULL);
if (err)
{
AVB_LOG_ERROR("Failed to setup SIGUSR1 handler");
osalAVBFinalize();
exit(-1);
}
registerStaticMapModule(openavbMapPipeInitialize);
registerStaticMapModule(openavbMapAVTPAudioInitialize);
registerStaticMapModule(openavbMapCtrlInitialize);
registerStaticMapModule(openavbMapH264Initialize);
registerStaticMapModule(openavbMapMjpegInitialize);
registerStaticMapModule(openavbMapMpeg2tsInitialize);
registerStaticMapModule(openavbMapNullInitialize);
registerStaticMapModule(openavbMapUncmpAudioInitialize);
registerStaticIntfModule(openavbIntfEchoInitialize);
registerStaticIntfModule(openavbIntfCtrlInitialize);
registerStaticIntfModule(openavbIntfLoggerInitialize);
registerStaticIntfModule(openavbIntfNullInitialize);
registerStaticIntfModule(openavbIntfViewerInitialize);
registerStaticIntfModule(openavbIntfAlsaInitialize);
registerStaticIntfModule(openavbIntfMjpegGstInitialize);
registerStaticIntfModule(openavbIntfMpeg2tsFileInitialize);
registerStaticIntfModule(openavbIntfMpeg2tsGstInitialize);
registerStaticIntfModule(openavbIntfWavFileInitialize);
registerStaticIntfModule(openavbIntfH264RtpGstInitialize);
tlHandleList = calloc(1,
sizeof(
tl_handle_t) * tlCount);
for (i1 = 0; i1 < tlCount; i1++) {
}
for (i1 = 0; i1 < tlCount; i1++) {
char iniFile[1024];
snprintf(iniFile, sizeof(iniFile), "%s", argv[i1 + iniIdx]);
if (optIfnameGlobal && !strcasestr(iniFile, ",ifname=")) {
snprintf(iniFile + strlen(iniFile), sizeof(iniFile), ",ifname=%s", optIfnameGlobal);
}
memset(&NVCfg, 0, sizeof(NVCfg));
AVB_LOGF_ERROR("Error reading ini file: %s\n", argv[i1 + 1]);
osalAVBFinalize();
exit(-1);
}
AVB_LOGF_ERROR("Error configuring: %s\n", argv[i1 + 1]);
osalAVBFinalize();
exit(-1);
}
int i2;
}
}
#ifdef AVB_FEATURE_GSTREAMER
#endif
for (i1 = 0; i1 < tlCount; i1++) {
}
while (bRunning) {
sleep(1);
}
for (i1 = 0; i1 < tlCount; i1++) {
}
for (i1 = 0; i1 < tlCount; i1++) {
}
#ifdef AVB_FEATURE_GSTREAMER
gst_deinit();
#endif
osalAVBFinalize();
AVB_TRACE_EXIT(AVB_TRACE_HOST);
exit(0);
}