summaryrefslogtreecommitdiff
path: root/lib/avtp_pipeline/platform/Linux/avb_host/openavb_harness.c
blob: 4c89041da183b1e8d91294b7f86e0f21973b937f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
/*************************************************************************************************************
Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company
Copyright (c) 2016-2017, Harman International Industries, Incorporated
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Attributions: The inih library portion of the source code is licensed from
Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt.
Complete license and copyright information can be found at
https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175.
*************************************************************************************************************/

/*
* MODULE SUMMARY : Talker listener test host implementation.
*/

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include "openavb_tl_pub.h"
#include "openavb_osal_pub.h"
#include "openavb_plugin.h"
#include "openavb_trace_pub.h"
#ifdef AVB_FEATURE_GSTREAMER
#include <gst/gst.h>
#endif
#include <inttypes.h>

#define	AVB_LOG_COMPONENT	"TL Harness"
#include "openavb_log_pub.h"

bool bRunning = TRUE;

// Platform independent mapping modules
extern bool openavbMapPipeInitialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);
extern bool openavbMapAVTPAudioInitialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);
extern bool openavbMapCtrlInitialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);
extern bool openavbMapH264Initialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);
extern bool openavbMapMjpegInitialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);
extern bool openavbMapMpeg2tsInitialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);
extern bool openavbMapNullInitialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);
extern bool openavbMapUncmpAudioInitialize(media_q_t *pMediaQ, openavb_map_cb_t *pMapCB, U32 inMaxTransitUsec);

// Platform independent interface modules
extern bool openavbIntfEchoInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfCtrlInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfLoggerInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfNullInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfToneGenInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfViewerInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);

// Linux interface modules
extern bool openavbIntfAlsaInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfMpeg2tsFileInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfWavFileInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
#ifdef AVB_FEATURE_GSTREAMER
extern bool openavbIntfMpeg2tsGstInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfMjpegGstInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
extern bool openavbIntfH264RtpGstInitialize(media_q_t *pMediaQ, openavb_intf_cb_t *pIntfCB);
#endif


/***********************************************
 * Signal handler - used to respond to signals.
 * Allows graceful cleanup.
 */
static void openavbTLSigHandler(int signal)
{
	AVB_TRACE_ENTRY(AVB_TRACE_HOST);

	if (signal == SIGINT || signal == SIGTERM) {
		if (bRunning) {
			AVB_LOG_INFO("Host shutting down");
			bRunning = FALSE;
		}
		else {
			// Force shutdown
			exit(2);
		}
	}
	else if (signal == SIGUSR1) {
		AVB_LOG_DEBUG("Waking up streaming thread");
	}
	else {
		AVB_LOG_ERROR("Unexpected signal");
	}

	AVB_TRACE_EXIT(AVB_TRACE_HOST);
}

void openavbTlHarnessUsage(char *programName)
{
	printf(
		"\n"
		"Usage: %s [options] file...\n"
		"  -a val     Override stream address in each configuration file.\n"
		"  -h         Prints this message.\n"
		"  -i         Enables interactive mode.\n"
		"  -s val     Stream count. Starts 'val' number of streams for each configuration file. stream_uid will be overriden.\n"
		"  -d val     Last byte of destination address from static pool. Full address will be 91:e0:f0:00:fe:val.\n"
		"  -I val     Use given (val) interface globally, can be overriden by giving the ifname= option to the config line.\n"
		"  -l val     Filename of the log file to use.  If not specified, results will be logged to stderr.\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"
		"  %s listener.ini,stream_addr=84:7E:40:2C:8F:DE\n"
		"    Start 1 stream and override the sream_addr in the ini file.\n\n"
		"  %s -i -s 8 -a 84:7E:40:2C:8F:DE listener.ini\n"
		"    Work interactively with 8 streams overriding the stream_uid and stream_addr of each.\n\n"
		,
		programName, programName, programName, programName, programName, programName, programName);
}

void openavbTlHarnessMenu()
{
	printf(
		"\n"
		" MENU OPTIONS\n"
		" s            Start all streams\n"
		" t            Stop all streams\n"
		" l            List streams\n"
		" 0-99         Toggle the state of the numbered stream\n"
		" m            Display this menu\n"
		" z            Stats\n"
		" x            Exit\n"
		);
}


/**********************************************
 * main
 */
int main(int argc, char *argv[])
{
	AVB_TRACE_ENTRY(AVB_TRACE_HOST);

	// Command line vars
	char *programName;
	char *optStreamAddr = NULL;
	bool optInteractive = FALSE;
	int optStreamCount = 1;
	bool optStreamCountSet = FALSE;
	bool optDestAddrSet = FALSE;
	U8 destAddr[ETH_ALEN] = {0x91, 0xe0, 0xf0, 0x00, 0xfe, 0x00};
	char *optIfnameGlobal = NULL;
	char *optLogFileName = NULL;

	// Talker listener vars
	int iniIdx = 0;
	int iniCount = 0;
	int tlCount = 0;
	char **tlIniList = NULL;
	tl_handle_t *tlHandleList = NULL;

	// General vars
	int i1, i2;

	// Setup signal handler. Catch SIGINT and shutdown cleanly
	struct sigaction sa;
	sa.sa_handler = openavbTLSigHandler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0; // not SA_RESTART
	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);
	sigaction(SIGUSR1, &sa, NULL);

	// Ignore SIGPIPE signals.
	signal(SIGPIPE, SIG_IGN);

	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(openavbIntfToneGenInitialize);
	registerStaticIntfModule(openavbIntfViewerInitialize);
	registerStaticIntfModule(openavbIntfAlsaInitialize);
	registerStaticIntfModule(openavbIntfMpeg2tsFileInitialize);
	registerStaticIntfModule(openavbIntfWavFileInitialize);
#ifdef AVB_FEATURE_GSTREAMER
	registerStaticIntfModule(openavbIntfMjpegGstInitialize);
	registerStaticIntfModule(openavbIntfMpeg2tsGstInitialize);
	registerStaticIntfModule(openavbIntfH264RtpGstInitialize);
#endif
	// Process command line
	programName = strrchr(argv[0], '/');
	programName = programName ? programName + 1 : argv[0];

	if (argc < 2) {
		openavbTlHarnessUsage(programName);
		exit(-1);
	}

	bool optDone = FALSE;
	while (!optDone) {
		int opt = getopt(argc, argv, "a:his:d:I:l:");
		if (opt != EOF) {
			switch (opt) {
				case 'a':
					optStreamAddr = strdup(optarg);
					break;
				case 'i':
					optInteractive = TRUE;
					break;
				case 's':
					optStreamCount = atoi(optarg);
					optStreamCountSet = TRUE;
					break;
				case 'd':
					optDestAddrSet = TRUE;
					destAddr[5] = strtol(optarg, NULL, 0);
					break;
				case 'I':
					optIfnameGlobal = strdup(optarg);
					break;
				case 'l':
					optLogFileName = strdup(optarg);
					break;
				case '?':
				default:
					openavbTlHarnessUsage(programName);
					exit(-1);
			}
		}
		else {
			optDone = TRUE;
		}
	}

	osalAVBInitialize(optLogFileName, optIfnameGlobal);

	// Setup the talker listener counts and lists
	iniIdx = optind;
	iniCount = argc - iniIdx;
	tlCount = iniCount * optStreamCount;

	tlIniList = calloc(1, sizeof(char *) * tlCount);
	if (!tlIniList) {
		AVB_LOG_ERROR("Unable to allocate ini list");
		osalAVBFinalize();
		exit(-1);
	}

	tlHandleList = calloc(1, sizeof(tl_handle_t) * tlCount);
	if (!tlHandleList) {
		AVB_LOG_ERROR("Unable to allocate handle list");
		osalAVBFinalize();
		exit(-1);
	}

	if (!openavbTLInitialize(tlCount)) {
		AVB_LOG_ERROR("Unable to initialize talker listener library");
		osalAVBFinalize();
		exit(-1);
	}

	// Populate the ini file list
	int tlIndex = 0;
	for (i1 = 0; i1 < iniCount; i1++) {
		char iniFile[1024];
		char sStreamAddr[31] = "";
		char sDestAddr[29] = "";

		if (optStreamAddr) {
			snprintf(sStreamAddr, sizeof(sStreamAddr), ",stream_addr=%s", optStreamAddr);
		}

		if (optDestAddrSet) {
			snprintf(sDestAddr, sizeof(sDestAddr), ",dest_addr="ETH_FORMAT, ETH_OCTETS(destAddr));
		}

		if (!optStreamCountSet) {
			snprintf(iniFile, sizeof(iniFile), "%s%s%s", argv[i1 + iniIdx], sDestAddr, sStreamAddr);
			if (optIfnameGlobal && !strcasestr(iniFile, ",ifname=")) {
				snprintf(iniFile + strlen(iniFile), sizeof(iniFile), ",ifname=%s", optIfnameGlobal);
			}
			tlIniList[tlIndex++] = strdup(iniFile);
		}
		else {
			for (i2 = 0; i2 < optStreamCount; i2++) {
				snprintf(iniFile, sizeof(iniFile), "%s%s%s,stream_uid=%d", argv[i1 + iniIdx], sDestAddr, sStreamAddr, tlIndex);
				if (optIfnameGlobal && !strcasestr(iniFile, ",ifname=")) {
					snprintf(iniFile + strlen(iniFile), sizeof(iniFile), ",ifname=%s", optIfnameGlobal);
				}
				tlIniList[tlIndex++] = strdup(iniFile);
				if (optDestAddrSet) {
					destAddr[5]++;
					snprintf(sDestAddr, sizeof(sDestAddr), ",dest_addr="ETH_FORMAT, ETH_OCTETS(destAddr));
				}
			}
		}
	}

#ifdef AVB_FEATURE_GSTREAMER
	// If we're supporting the interface modules which use GStreamer,
	// initialize GStreamer here to avoid errors.
	gst_init(0, NULL);
#endif

	// Open all streams
	for (i1 = 0; i1 < tlCount; i1++) {
		printf("Opening: %s\n", tlIniList[i1]);
		tlHandleList[i1] = openavbTLOpen();
	}

	// Parse ini and configure all streams
	for (i1 = 0; i1 < tlCount; i1++) {
		printf("Configuring: %s\n", tlIniList[i1]);
		openavb_tl_cfg_t cfg;
		openavb_tl_cfg_name_value_t NVCfg;

		openavbTLInitCfg(&cfg);
		memset(&NVCfg, 0, sizeof(NVCfg));

		if (!openavbTLReadIniFileOsal(tlHandleList[i1], tlIniList[i1], &cfg, &NVCfg)) {
			printf("Error reading ini file: %s\n", tlIniList[i1]);
			osalAVBFinalize();
			exit(-1);
		}
		if (!openavbTLConfigure(tlHandleList[i1], &cfg, &NVCfg)) {
			printf("Error configuring: %s\n", tlIniList[i1]);
			osalAVBFinalize();
			exit(-1);
		}

		int i2;
		for (i2 = 0; i2 < NVCfg.nLibCfgItems; i2++) {
			free(NVCfg.libCfgNames[i2]);
			free(NVCfg.libCfgValues[i2]);
		}
	}

	if (!optInteractive) {
		// Non-interactive mode
		// Run any streams where the stop initial state was not requested.
		for (i1 = 0; i1 < tlCount; i1++) {
			if (openavbTLGetInitialState(tlHandleList[i1]) != TL_INIT_STATE_STOPPED) {
				printf("Starting: %s\n", tlIniList[i1]);
				openavbTLRun(tlHandleList[i1]);
			}
		}

		while (bRunning) {
			SLEEP_MSEC(1);
		}

		for (i1 = 0; i1 < tlCount; i1++) {
			if (tlHandleList[i1] && openavbTLIsRunning(tlHandleList[i1])) {
				printf("Stopping: %s\n", tlIniList[i1]);
				openavbTLStop(tlHandleList[i1]);
			}
		}
	}
	else {
		// Interactive mode

		// Run any streams where the running initial state was requested.
		for (i1 = 0; i1 < tlCount; i1++) {
			if (openavbTLGetInitialState(tlHandleList[i1]) == TL_INIT_STATE_RUNNING) {
				printf("Starting: %s\n", tlIniList[i1]);
				openavbTLRun(tlHandleList[i1]);
			}
		}

		openavbTlHarnessMenu();
		while (bRunning) {
			char buf[16];
			printf("> ");
			if (fgets(buf, sizeof(buf), stdin) == NULL) {
				openavbTlHarnessMenu();
				continue;
			}

			switch (buf[0]) {
				case 's':
					// Start all streams
					{
						int i1;
						for (i1 = 0; i1 < tlCount; i1++) {
							if (tlHandleList[i1] && !openavbTLIsRunning(tlHandleList[i1])) {
								printf("Starting: %s\n", tlIniList[i1]);
								openavbTLRun(tlHandleList[i1]);
							}
						}
					}
					break;
				case 't':
					// Stop all streams
					{
						int i1;
						for (i1 = 0; i1 < tlCount; i1++) {
							if (tlHandleList[i1] && openavbTLIsRunning(tlHandleList[i1])) {
								printf("Stopping: %s\n", tlIniList[i1]);
								openavbTLStop(tlHandleList[i1]);
							}
						}
					}
					break;
				case 'l':
					// List all streams
					{
						int i1;
						for (i1 = 0; i1 < tlCount; i1++) {
							if (tlHandleList[i1] && openavbTLIsRunning(tlHandleList[i1])) {
								printf("%02d: [Started] %s\n", i1, tlIniList[i1]);
							}
							else {
								printf("%02d: [Stopped] %s\n", i1, tlIniList[i1]);
							}
						}
					}
					break;
				case 'm':
					// Display menu
					openavbTlHarnessMenu();
					break;
				case 'z':
					// Stats
					{
						int i1;
						for (i1 = 0; i1 < tlCount; i1++) {
							if (tlHandleList[i1] && openavbTLIsRunning(tlHandleList[i1])) {
								printf("%02d: [Started] %s\n", i1, tlIniList[i1]);
								if (openavbTLGetRole(tlHandleList[i1]) == AVB_ROLE_TALKER) {
									printf("     Talker totals: calls=%" PRIu64 ", frames=%" PRIu64 ", late=%" PRIu64 ", bytes=%" PRIu64 "\n",
										openavbTLStat(tlHandleList[i1], TL_STAT_TX_CALLS),
										openavbTLStat(tlHandleList[i1], TL_STAT_TX_FRAMES),
										openavbTLStat(tlHandleList[i1], TL_STAT_TX_LATE),
										openavbTLStat(tlHandleList[i1], TL_STAT_TX_BYTES));
								}
								else if (openavbTLGetRole(tlHandleList[i1]) == AVB_ROLE_LISTENER) {
									printf("     Listener totals: calls=%" PRIu64 ", frames=%" PRIu64 ", lost=%" PRIu64 ", bytes=%" PRIu64 "\n",
										openavbTLStat(tlHandleList[i1], TL_STAT_RX_CALLS),
										openavbTLStat(tlHandleList[i1], TL_STAT_RX_FRAMES),
										openavbTLStat(tlHandleList[i1], TL_STAT_RX_LOST),
										openavbTLStat(tlHandleList[i1], TL_STAT_RX_BYTES));
								}
							}
							else {
								printf("%02d: [Stopped] %s\n", i1, tlIniList[i1]);
							}
						}
					}
					break;
				case 'x':
					// Exit
					{
						int i1;
						for (i1 = 0; i1 < tlCount; i1++) {
							if (tlHandleList[i1] && openavbTLIsRunning(tlHandleList[i1])) {
								printf("Stopping: %s\n", tlIniList[i1]);
								openavbTLStop(tlHandleList[i1]);
							}
						}
						bRunning = FALSE;
					}
					break;
				default:
					// Check for number
					{
						if (isdigit(buf[0])) {
							int idx = atoi(buf);
							if (idx < tlCount) {
								if (tlHandleList[idx] && openavbTLIsRunning(tlHandleList[idx])) {
									// Stop the stream
									printf("Stopping: %s\n", tlIniList[idx]);
									openavbTLStop(tlHandleList[idx]);
								}
								else {
									// Start the stream
									printf("Starting: %s\n", tlIniList[idx]);
									openavbTLRun(tlHandleList[idx]);
								}
							}
							else {
								openavbTlHarnessMenu();
							}
						}
						else {
							openavbTlHarnessMenu();
						}
					}
					break;
			}

		}
	}

	// Close the streams
	for (i1 = 0; i1 < tlCount; i1++) {
		if (tlHandleList[i1]) {
			printf("Closing: %s\n", tlIniList[i1]);

			openavbTLClose(tlHandleList[i1]);

			tlHandleList[i1] = NULL;
		}
	}

	openavbTLCleanup();

	for (i1 = 0; i1 < tlCount; i1++) {
		if (tlIniList[i1]) {
			free(tlIniList[i1]);
			tlIniList[i1] = NULL;
		}
	}

	if (tlIniList) {
		free(tlIniList);
		tlIniList = NULL;
	}

	if (tlHandleList) {
		free(tlHandleList);
		tlHandleList = NULL;
	}

	if (optStreamAddr) {
		free(optStreamAddr);
		optStreamAddr = NULL;
	}

	if (optLogFileName) {
		free(optLogFileName);
		optLogFileName = NULL;
	}

#ifdef AVB_FEATURE_GSTREAMER
	// If we're supporting the interface modules which use GStreamer,
	// De-initialize GStreamer to clean up resources.
	gst_deinit();
#endif

	osalAVBFinalize();
	AVB_TRACE_EXIT(AVB_TRACE_HOST);
	exit(0);
}