summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSrinath Arunachalam <Srinath.Arunachalam@harman.com>2015-08-20 15:43:41 -0600
committerSrinath Arunachalam <Srinath.Arunachalam@harman.com>2015-08-20 15:43:41 -0600
commit6ffd6d847c1a2cf9360cba9dd177b129887dd3ab (patch)
treeaceb68c4491c84e3596b3a9469635d5f0771d6e5 /examples
parent6f68df9f71b5967b8187650ae670f9e76b8a2135 (diff)
downloadOpen-AVB-6ffd6d847c1a2cf9360cba9dd177b129887dd3ab.tar.gz
Fixed build errors occuring as a result of change in talker_mrp_client.h and listener_mrp_client.h
Diffstat (limited to 'examples')
-rw-r--r--examples/jackd-listener/Makefile2
-rw-r--r--examples/jackd-listener/jack_listener.c113
-rw-r--r--examples/jackd-talker/Makefile3
-rw-r--r--examples/jackd-talker/jack.c29
-rw-r--r--examples/jackd-talker/jack.h3
-rwxr-xr-xexamples/jackd-talker/jackd_talker.c118
-rw-r--r--examples/live_stream/listener.c54
-rw-r--r--examples/live_stream/talker.c73
8 files changed, 244 insertions, 151 deletions
diff --git a/examples/jackd-listener/Makefile b/examples/jackd-listener/Makefile
index a9004923..b0208530 100644
--- a/examples/jackd-listener/Makefile
+++ b/examples/jackd-listener/Makefile
@@ -2,7 +2,7 @@ CC ?= gcc
OPT = -O2 -g
CFLAGS = $(OPT) -Wall -Wextra -Wno-parentheses -std=gnu99
INCFLAGS = -I../../daemons/mrpd -I../common -I../../daemons/common
-LDLIBS = -lpcap -lsndfile -ljack
+LDLIBS = -lpcap -lsndfile -ljack -lpthread
all: jack_listener
diff --git a/examples/jackd-listener/jack_listener.c b/examples/jackd-listener/jack_listener.c
index 1b0b51c7..103a52b8 100644
--- a/examples/jackd-listener/jack_listener.c
+++ b/examples/jackd-listener/jack_listener.c
@@ -54,6 +54,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define DEFAULT_RINGBUFFER_SIZE (32768)
#define MAX_SAMPLE_VALUE ((1U << ((sizeof(int32_t) * 8) -1)) -1)
+struct mrp_listener_ctx *ctx_sig;//Context pointer for signal handler
+
struct ethernet_header{
u_char dst[6];
u_char src[6];
@@ -95,17 +97,17 @@ void shutdown_and_exit(int sig)
fprintf(stdout,"Received signal %d:", sig);
fprintf(stdout,"Leaving...\n");
- if (0 != talker) {
- ret = send_leave();
+ if (0 != ctx_sig->talker) {
+ ret = send_leave(ctx_sig);
if (ret)
printf("send_leave failed\n");
}
- ret = mrp_disconnect();
+ ret = mrp_disconnect(ctx_sig);
if (ret)
printf("mrp_disconnect failed\n");
- close(control_socket);
+ close(ctx_sig->control_socket);
if (NULL != handle) {
pcap_breakloop(handle);
@@ -140,7 +142,7 @@ void pcap_callback(u_char* args, const struct pcap_pkthdr* packet_header, const
jack_default_audio_sample_t jackframe[CHANNELS];
int cnt;
static int total;
- (void) args; /* unused */
+ struct mrp_listener_ctx *ctx = (struct mrp_listener_ctx*) args;
(void) packet_header; /* unused */
eth_header = (struct ethernet_header*)(packet);
@@ -150,34 +152,34 @@ void pcap_callback(u_char* args, const struct pcap_pkthdr* packet_header, const
}
test_stream_id = (unsigned char*)(packet + ETHERNET_HEADER_SIZE + SEVENTEEN22_HEADER_PART1_SIZE);
- if (0 != memcmp(test_stream_id, stream_id, STREAM_ID_SIZE)) {
+ if (0 != memcmp(test_stream_id, ctx->stream_id, STREAM_ID_SIZE)) {
return;
}
-
+
mybuf = (uint32_t*) (packet + HEADER_SIZE);
-
- for(int i = 0; i < SAMPLES_PER_FRAME * CHANNELS; i+=CHANNELS) {
+
+ for(int i = 0; i < SAMPLES_PER_FRAME * CHANNELS; i+=CHANNELS) {
memcpy(&frame[0], &mybuf[i], sizeof(frame));
for(int j = 0; j < CHANNELS; j++) {
-
+
frame[j] = ntohl(frame[j]); /* convert to host-byte order */
frame[j] &= 0x00ffffff; /* ignore leading label */
frame[j] <<= 8; /* left-align remaining PCM-24 sample */
-
+
jackframe[j] = ((int32_t)frame[j])/(float)(MAX_SAMPLE_VALUE);
}
if ((cnt = jack_ringbuffer_write_space(ringbuffer)) >= SAMPLE_SIZE * CHANNELS) {
jack_ringbuffer_write(ringbuffer, (void*)&jackframe[0], SAMPLE_SIZE * CHANNELS);
-
+
} else {
fprintf(stdout, "Only %i bytes available after %i samples.\n", cnt, total);
}
if (jack_ringbuffer_write_space(ringbuffer) <= SAMPLE_SIZE * CHANNELS * DEFAULT_RINGBUFFER_SIZE / 4) {
- /** Ringbuffer has only 25% or less write space available, it's time to tell jackd
+ /** Ringbuffer has only 25% or less write space available, it's time to tell jackd
to read some data. */
ready = 1;
}
@@ -201,7 +203,7 @@ static int process_jack(jack_nframes_t nframes, void* arg)
}
for(size_t i = 0; i < nframes; i++) {
-
+
if (jack_ringbuffer_read_space(ringbuffer) >= SAMPLE_SIZE * CHANNELS) {
for(int j = 0; j < CHANNELS; j++){
@@ -221,13 +223,13 @@ static int process_jack(jack_nframes_t nframes, void* arg)
void jack_shutdown(void* arg)
{
- (void) arg; /* unused*/
+ (void)arg; /* unused*/
printf("JACK shutdown\n");
shutdown_and_exit(0);
}
-jack_client_t* init_jack(void)
+jack_client_t* init_jack(struct mrp_listener_ctx *ctx)
{
const char* client_name = "simple_listener";
const char* server_name = NULL;
@@ -250,8 +252,8 @@ jack_client_t* init_jack(void)
fprintf (stderr, "unique name `%s' assigned\n", client_name);
}
- jack_set_process_callback(client, process_jack, 0);
- jack_on_shutdown(client, jack_shutdown, 0);
+ jack_set_process_callback(client, process_jack, (void *)ctx);
+ jack_on_shutdown(client, jack_shutdown, (void *)ctx);
outputports = (jack_port_t**) malloc (CHANNELS * sizeof (jack_port_t*));
out = (jack_default_audio_sample_t**) malloc (CHANNELS * sizeof (jack_default_audio_sample_t*));
@@ -262,13 +264,13 @@ jack_client_t* init_jack(void)
memset(ringbuffer->buf, 0, ringbuffer->size);
for(int i = 0; i < CHANNELS; i++) {
-
+
char* portName;
if (asprintf(&portName, "output%d", i) < 0) {
fprintf(stderr, "could not create portname for port %d\n", i);
shutdown_and_exit(0);
- }
-
+ }
+
outputports[i] = jack_port_register (client, portName, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
if (NULL == outputports[i]) {
fprintf (stderr, "cannot register output port \"%d\"!\n", i);
@@ -278,13 +280,13 @@ jack_client_t* init_jack(void)
const char** ports;
if (jack_activate (client)) {
- fprintf (stderr, "cannot activate client\n");
+ fprintf (stderr, "cannot activate client\n");
shutdown_and_exit(0);
}
ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical|JackPortIsInput);
- if(NULL == ports) {
- fprintf (stderr, "no physical playback ports\n");
+ if(NULL == ports) {
+ fprintf (stderr, "no physical playback ports\n");
shutdown_and_exit(0);
}
@@ -306,17 +308,20 @@ int main(int argc, char *argv[])
char* dev = NULL;
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program comp_filter_exp; /** The compiled filter expression */
- char filter_exp[] = "ether dst 91:E0:F0:00:0e:80"; /** The filter expression */
+ char filter_exp[100]; /** The filter expression */
int rc;
-
+ struct mrp_listener_ctx *ctx = malloc(sizeof(struct mrp_listener_ctx));
+ struct mrp_domain_attr *class_a = malloc(sizeof(struct mrp_domain_attr));
+ struct mrp_domain_attr *class_b = malloc(sizeof(struct mrp_domain_attr));
+ ctx_sig = ctx;
signal(SIGINT, shutdown_and_exit);
-
+
int c;
- while((c = getopt(argc, argv, "hi:")) > 0)
+ while((c = getopt(argc, argv, "hi:")) > 0)
{
- switch (c)
+ switch (c)
{
- case 'h':
+ case 'h':
help();
break;
case 'i':
@@ -331,23 +336,51 @@ int main(int argc, char *argv[])
help();
}
- if (create_socket()) {
+ rc = mrp_listener_client_init(ctx);
+ if (rc)
+ {
+ printf("failed to initialize global variables\n");
+ return EXIT_FAILURE;
+ }
+
+ if (create_socket(ctx)) {
fprintf(stderr, "Socket creation failed.\n");
return errno;
}
- rc = report_domain_status();
+ rc = mrp_monitor(ctx);
+ if (rc)
+ {
+ printf("failed creating MRP monitor thread\n");
+ return EXIT_FAILURE;
+ }
+ rc=mrp_get_domain(ctx, class_a, class_b);
+ if (rc)
+ {
+ printf("failed calling mrp_get_domain()\n");
+ return EXIT_FAILURE;
+ }
+
+ printf("detected domain Class A PRIO=%d VID=%04x...\n",class_a->priority,class_a->vid);
+
+ rc = report_domain_status(class_a,ctx);
if (rc) {
printf("report_domain_status failed\n");
return EXIT_FAILURE;
}
- init_jack();
-
+ rc = join_vlan(class_a, ctx);
+ if (rc) {
+ printf("join_vlan failed\n");
+ return EXIT_FAILURE;
+ }
+
+ init_jack(ctx);
+
fprintf(stdout,"Waiting for talker...\n");
- await_talker();
+ await_talker(ctx);
- rc = send_ready();
+ rc = send_ready(ctx);
if (rc) {
printf("send_ready failed\n");
return EXIT_FAILURE;
@@ -382,6 +415,7 @@ int main(int argc, char *argv[])
}
/** compile and apply filter */
+ sprintf(filter_exp,"ether dst %02x:%02x:%02x:%02x:%02x:%02x",ctx->dst_mac[0],ctx->dst_mac[1],ctx->dst_mac[2],ctx->dst_mac[3],ctx->dst_mac[4],ctx->dst_mac[5]);
if (-1 == pcap_compile(handle, &comp_filter_exp, filter_exp, 0, PCAP_NETMASK_UNKNOWN)) {
fprintf(stderr, "Could not parse filter %s: %s.\n", filter_exp, pcap_geterr(handle));
shutdown_and_exit(0);
@@ -391,11 +425,14 @@ int main(int argc, char *argv[])
fprintf(stderr, "Could not install filter %s: %s.\n", filter_exp, pcap_geterr(handle));
shutdown_and_exit(0);
}
-
+
/** loop forever and call callback-function for every received packet */
- pcap_loop(handle, -1, pcap_callback, NULL);
+ pcap_loop(handle, -1, pcap_callback, (u_char*)ctx);
usleep(-1);
+ free(ctx);
+ free(class_a);
+ free(class_b);
return EXIT_SUCCESS;
}
diff --git a/examples/jackd-talker/Makefile b/examples/jackd-talker/Makefile
index 815235f0..1d4a84ba 100644
--- a/examples/jackd-talker/Makefile
+++ b/examples/jackd-talker/Makefile
@@ -1,6 +1,6 @@
CC ?= gcc
OPT = -O2 -g
-CFLAGS = $(OPT) -Wall -Wextra -Wno-parentheses -std=gnu99
+CFLAGS = $(OPT) $(INCFLAGS) -Wall -Wextra -Wno-parentheses -std=gnu99
INCFLAGS = -I../../lib/igb -I../../daemons/mrpd -I../common -I../../daemons/common
LDLIBS = -ligb -lpci -lrt -pthread -ljack
LDFLAGS = -L../../lib/igb
@@ -24,4 +24,3 @@ jackd_talker.o: jackd_talker.c defines.h jack.h
clean:
$(RM) jackd_talker
$(RM) `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
-
diff --git a/examples/jackd-talker/jack.c b/examples/jackd-talker/jack.c
index 214d3d11..dc0d621b 100644
--- a/examples/jackd-talker/jack.c
+++ b/examples/jackd-talker/jack.c
@@ -8,9 +8,8 @@
#include <jack/ringbuffer.h>
#include "jack.h"
#include "defines.h"
+#include "talker_mrp_client.h"
-extern volatile int halt_tx;
-extern volatile int listeners;
extern volatile int glob_unleash_jack;
static jack_port_t** inputports;
@@ -30,18 +29,18 @@ static int process(jack_nframes_t nframes, void* arg)
{
int cnt;
static int total;
- (void) arg; /* unused */
+ struct mrp_talker_ctx *ctx = (struct mrp_talker_ctx *) arg;
/* Do nothing until we're ready to begin. */
if (!glob_unleash_jack) {
printf ("nothing to do\n");
return 0;
}
-
+
for(int i = 0; i < CHANNELS; i++) {
in[i] = jack_port_get_buffer(inputports[i], nframes);
}
-
+
for (size_t i = 0; i < nframes; i++) {
for(int j = 0; j < CHANNELS; j++) {
total++;
@@ -54,7 +53,7 @@ static int process(jack_nframes_t nframes, void* arg)
} else {
printf ("Only %i bytes available after %i samples\n",
cnt, total);
- halt_tx = 1;
+ ctx->halt_tx = 1;
}
}
}
@@ -70,13 +69,13 @@ static int process(jack_nframes_t nframes, void* arg)
void jack_shutdown(void* arg)
{
- (void) arg; /* unused */
+ struct mrp_talker_ctx *ctx = (struct mrp_talker_ctx *) arg;
printf("JACK shutdown\n");
- halt_tx = 1;
+ ctx->halt_tx = 1;
}
-jack_client_t* init_jack(void)
+jack_client_t* init_jack(struct mrp_talker_ctx *ctx)
{
jack_client_t *client;
const char *client_name = "simple_talker";
@@ -98,8 +97,8 @@ jack_client_t* init_jack(void)
fprintf (stderr, "unique name `%s' assigned\n", client_name);
}
- jack_set_process_callback(client, process, 0);
- jack_on_shutdown(client, jack_shutdown, 0);
+ jack_set_process_callback(client, process, (void *)ctx);
+ jack_on_shutdown(client, jack_shutdown, (void *)ctx);
if (jack_activate (client))
fprintf (stderr, "cannot activate client");
@@ -115,15 +114,15 @@ jack_client_t* init_jack(void)
for(int i = 0; i < CHANNELS; i++)
{
char* portName;
- if (asprintf(&portName, "input%d", i) < 0)
+ if (asprintf(&portName, "input%d", i) < 0)
{
fprintf(stderr, "Could not create portname for port %d", i);
exit(EXIT_FAILURE);
- }
-
+ }
+
inputports[i] = jack_port_register (client, portName,
JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
- if (NULL == inputports[i])
+ if (NULL == inputports[i])
{
fprintf (stderr, "cannot register input port \"%d\"!\n", i);
jack_client_close (client);
diff --git a/examples/jackd-talker/jack.h b/examples/jackd-talker/jack.h
index c78dc1ab..1e96bfb0 100644
--- a/examples/jackd-talker/jack.h
+++ b/examples/jackd-talker/jack.h
@@ -2,9 +2,10 @@
#define _AVB_JACK_H
#define DEFAULT_RINGBUFFER_SIZE 32768
+extern struct mrp_talker_ctx *ctx;
/* Prototypes */
-jack_client_t* init_jack(void);
+jack_client_t* init_jack(struct mrp_talker_ctx *ctx);
void stop_jack(jack_client_t* client);
#endif /* _AVB_JACK_H */
diff --git a/examples/jackd-talker/jackd_talker.c b/examples/jackd-talker/jackd_talker.c
index 63041b2c..8403aebc 100755
--- a/examples/jackd-talker/jackd_talker.c
+++ b/examples/jackd-talker/jackd_talker.c
@@ -1,31 +1,31 @@
/******************************************************************************
- Copyright (c) 2012, Intel Corporation
+ Copyright (c) 2012, Intel Corporation
All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
+
+ 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,
+
+ 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
+
+ 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.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
+
+ 3. Neither the name of the Intel Corporation nor the names of its
+ contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 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)
+ 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 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.
@@ -64,8 +64,9 @@
#define RENDER_DELAY (XMIT_DELAY+2000000) /* us */
#define PACKET_IPG (125000) /* (1) packet every 125 usec */
#define PKT_SZ (100)
+volatile int *halt_tx_sig;//Global variable for signal handler
-typedef struct {
+typedef struct {
int64_t ml_phoffset;
int64_t ls_phoffset;
long double ml_freqoffset;
@@ -206,7 +207,7 @@ int gptpscaling(char *igb_mmap, gPtpTimeData *td)
void sigint_handler(int signum)
{
printf("got SIGINT\n");
- halt_tx = signum;
+ *halt_tx_sig = signum;
glob_unleash_jack = 0;
}
@@ -289,6 +290,7 @@ static void usage(void)
static void* packetizer_thread(void *arg) {
struct igb_packet *cleaned_packets;
+ struct mrp_talker_ctx *ctx = (struct mrp_talker_ctx *)arg;
six1883_sample *sample;
unsigned total_samples = 0;
int err;
@@ -305,7 +307,7 @@ static void* packetizer_thread(void *arg) {
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
pthread_mutex_lock(&threadLock);
- while (listeners && !halt_tx) {
+ while (ctx->listeners && !ctx->halt_tx) {
pthread_cond_wait(&dataReady, &threadLock);
while ((jack_ringbuffer_read_space(ringbuffer) >= bytes_to_read)) {
@@ -403,6 +405,9 @@ int main(int argc, char *argv[])
uint64_t update_8021as;
unsigned delta_8021as, delta_local;
jack_client_t* _jackclient;
+ struct mrp_talker_ctx *ctx = malloc(sizeof(struct mrp_talker_ctx));
+ struct mrp_domain_attr *class_a = malloc(sizeof(struct mrp_domain_attr));
+ struct mrp_domain_attr *class_b = malloc(sizeof(struct mrp_domain_attr));
for (;;) {
c = getopt(argc, argv, "hi:");
@@ -427,7 +432,14 @@ int main(int argc, char *argv[])
if (NULL == interface) {
usage();
}
- rc = mrp_connect();
+ rc = mrp_talker_client_init(ctx);
+ if (rc) {
+ printf("MRP talker client initialization failed\n");
+ return errno;
+ }
+ halt_tx_sig = &ctx->halt_tx;
+
+ rc = mrp_connect(ctx);
if (rc) {
printf("socket creation failed\n");
return errno;
@@ -457,28 +469,24 @@ int main(int argc, char *argv[])
usage();
}
- rc = mrp_monitor();
+ rc = mrp_get_domain(ctx, class_a, class_b);
if (rc) {
- printf("failed creating MRP monitor thread\n");
+ printf("failed calling msp_get_domain()\n");
return EXIT_FAILURE;
}
+ printf("detected domain Class A PRIO=%d VID=%04x...\n",class_a->priority,
+ class_a->vid);
- /*
- * should use mrp_get_domain() above but this is a simplification
- */
-
- domain_a_valid = 1;
- domain_class_a_id = MSRP_SR_CLASS_A;
- domain_class_a_priority = MSRP_SR_CLASS_A_PRIO;
- domain_class_a_vid = 2;
- printf("detected domain Class A PRIO=%d VID=%04x...\n", domain_class_a_priority,
- domain_class_a_vid);
-
- rc = mrp_register_domain(&domain_class_a_id, &domain_class_a_priority, &domain_class_a_vid);
+ rc = mrp_register_domain(class_a, ctx);
if (rc) {
printf("mrp_register_domain failed\n");
return EXIT_FAILURE;
}
+ rc = mrp_join_vlan(class_a, ctx);
+ if (rc) {
+ printf("mrp_join_vlan failed\n");
+ return EXIT_FAILURE;
+ }
igb_set_class_bandwidth(&glob_igb_dev, PACKET_IPG / 125000, 0, PKT_SZ - 22,
0);
@@ -515,9 +523,9 @@ int main(int argc, char *argv[])
((char *)glob_tmp_packet->vaddr)[12] = 0x81;
((char *)glob_tmp_packet->vaddr)[13] = 0x00;
((char *)glob_tmp_packet->vaddr)[14] =
- ((domain_class_a_priority << 13 | domain_class_a_vid)) >> 8;
+ ((ctx->domain_class_a_priority << 13 | ctx->domain_class_a_vid)) >> 8;
((char *)glob_tmp_packet->vaddr)[15] =
- ((domain_class_a_priority << 13 | domain_class_a_vid)) & 0xFF;
+ ((ctx->domain_class_a_priority << 13 | ctx->domain_class_a_vid)) & 0xFF;
((char *)glob_tmp_packet->vaddr)[16] = 0x22; /* 1722 eth type */
((char *)glob_tmp_packet->vaddr)[17] = 0xF0;
@@ -559,31 +567,32 @@ int main(int argc, char *argv[])
glob_free_packets = glob_tmp_packet;
}
- /*
- * subtract 16 bytes for the MAC header/Q-tag - pktsz is limited to the
+ /*
+ * subtract 16 bytes for the MAC header/Q-tag - pktsz is limited to the
* data payload of the ethernet frame .
*
* IPG is scaled to the Class (A) observation interval of packets per 125 usec
*/
- _jackclient = init_jack();
+ _jackclient = init_jack(ctx);
fprintf(stderr, "advertising stream ...\n");
- rc = mrp_advertise_stream(glob_stream_id, glob_dest_addr, domain_class_a_vid, PKT_SZ - 16,
- PACKET_IPG / 125000, domain_class_a_priority, 3900);
+ rc = mrp_advertise_stream(glob_stream_id, glob_dest_addr, PKT_SZ - 16,
+ PACKET_IPG / 125000, 3900, ctx);
if (rc) {
printf("mrp_advertise_stream failed\n");
return EXIT_FAILURE;
}
fprintf(stderr, "awaiting a listener ...\n");
- rc = mrp_await_listener(glob_stream_id);
+ rc = mrp_await_listener(glob_stream_id,ctx);
if (rc) {
printf("mrp_await_listener failed\n");
return EXIT_FAILURE;
}
+ ctx->listeners = 1;
printf("got a listener ...\n");
- halt_tx = 0;
+ ctx->halt_tx = 0;
if(-1 == gptpinit(&igb_shm_fd, &igb_mmap)) {
return EXIT_FAILURE;
@@ -607,28 +616,31 @@ int main(int argc, char *argv[])
rc = nice(-20);
- pthread_create (&glob_packetizer_id, NULL, packetizer_thread, NULL);
+ pthread_create (&glob_packetizer_id, NULL, packetizer_thread, (void *)ctx);
run_packetizer();
rc = nice(0);
stop_jack(_jackclient);
- if (halt_tx == 0)
+ if (ctx->halt_tx == 0)
printf("listener left ...\n");
- halt_tx = 1;
+ ctx->halt_tx = 1;
- rc = mrp_unadvertise_stream(glob_stream_id, glob_dest_addr, domain_class_a_vid, PKT_SZ - 16,
- PACKET_IPG / 125000, domain_class_a_priority, 3900);
+ rc = mrp_unadvertise_stream(glob_stream_id, glob_dest_addr, PKT_SZ - 16,
+ PACKET_IPG / 125000, 3900, ctx);
if (rc)
printf("mrp_unadvertise_stream failed\n");
igb_set_class_bandwidth(&glob_igb_dev, 0, 0, 0, 0); /* disable Qav */
- rc = mrp_disconnect();
+ rc = mrp_disconnect(ctx);
if (rc)
printf("mrp_disconnect failed\n");
+ free(ctx);
+ free(class_a);
+ free(class_b);
igb_dma_free_page(&glob_igb_dev, &a_page);
rc = gptpdeinit(&igb_shm_fd, &igb_mmap);
err = igb_detach(&glob_igb_dev);
diff --git a/examples/live_stream/listener.c b/examples/live_stream/listener.c
index a7ae7dd0..7ce12000 100644
--- a/examples/live_stream/listener.c
+++ b/examples/live_stream/listener.c
@@ -34,6 +34,7 @@
/* globals */
unsigned char glob_dest_addr[] = { 0x91, 0xE0, 0xF0, 0x00, 0x0E, 0x80 };
+struct mrp_listener_ctx *ctx_sig;//Context pointer for signal handler
void sigint_handler(int signum)
{
@@ -41,15 +42,18 @@ void sigint_handler(int signum)
fprintf(stderr, "Received signal %d:leaving...\n", signum);
#if USE_MRPD
- if (0 != talker) {
- ret = send_leave();
+ if (0 != ctx_sig->talker) {
+ ret = send_leave(ctx_sig);
if (ret)
printf("send_leave failed\n");
}
#endif /* USE_MRPD */
- if (2 > control_socket)
+ if (2 > ctx_sig->control_socket)
{
- close(control_socket);
+ close(ctx_sig->control_socket);
+ ret = mrp_disconnect(ctx_sig);
+ if (ret)
+ printf("mrp_disconnect failed\n");
}
exit(EXIT_SUCCESS);
}
@@ -69,6 +73,10 @@ int main(int argc, char *argv[ ])
unsigned char frame[MAX_FRAME_SIZE];
int size, length;
struct sched_param sched;
+ struct mrp_listener_ctx *ctx = malloc(sizeof(struct mrp_listener_ctx));
+ struct mrp_domain_attr *class_a = malloc(sizeof(struct mrp_domain_attr));
+ struct mrp_domain_attr *class_b = malloc(sizeof(struct mrp_domain_attr));
+ ctx_sig = ctx;
int rc;
if (argc < 2) {
@@ -78,20 +86,45 @@ int main(int argc, char *argv[ ])
signal(SIGINT, sigint_handler);
#if USE_MRPD
- if (create_socket()) {
+ rc = mrp_listener_client_init(ctx);
+ if (rc)
+ {
+ printf("failed to initialize global variables\n");
+ return EXIT_FAILURE;
+ }
+ if (create_socket(ctx)) {
fprintf(stderr, "Socket creation failed.\n");
return errno;
}
+ rc = mrp_monitor(ctx);
+ if (rc)
+ {
+ printf("failed creating MRP monitor thread\n");
+ return EXIT_FAILURE;
+ }
+ rc=mrp_get_domain(ctx, class_a, class_b);
+ if (rc)
+ {
+ printf("failed calling mrp_get_domain()\n");
+ return EXIT_FAILURE;
+ }
- rc = report_domain_status();
+ printf("detected domain Class A PRIO=%d VID=%04x...\n",class_a->priority,class_a->vid);
+
+ rc = report_domain_status(class_a,ctx);
if (rc) {
printf("report_domain_status failed\n");
return EXIT_FAILURE;
}
+ rc = join_vlan(class_a, ctx);
+ if (rc) {
+ printf("join_vlan failed\n");
+ return EXIT_FAILURE;
+ }
fprintf(stdout,"Waiting for talker...\n");
- await_talker();
- rc = send_ready();
+ await_talker(ctx);
+ rc = send_ready(ctx);
if (rc) {
printf("send_ready failed\n");
return EXIT_FAILURE;
@@ -174,8 +207,9 @@ int main(int argc, char *argv[ ])
usleep(100);
close(socket_descriptor);
+ free(ctx);
+ free(class_a);
+ free(class_b);
return EXIT_SUCCESS;
}
-
-
diff --git a/examples/live_stream/talker.c b/examples/live_stream/talker.c
index 320d347a..fb787c5d 100644
--- a/examples/live_stream/talker.c
+++ b/examples/live_stream/talker.c
@@ -39,6 +39,7 @@ unsigned char glob_station_addr[] = { 0, 0, 0, 0, 0, 0 };
unsigned char glob_stream_id[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
/* IEEE 1722 reserved address */
unsigned char glob_dest_addr[] = { 0x91, 0xE0, 0xF0, 0x00, 0x0E, 0x80 };
+volatile int *halt_tx_sig;//Global variable for signal handler
uint64_t reverse_64(uint64_t val)
{
@@ -59,7 +60,7 @@ uint64_t reverse_64(uint64_t val)
void sigint_handler(int signum)
{
fprintf(stderr, "got SIGINT\n");
- halt_tx = signum;
+ *halt_tx_sig = signum;
}
int get_mac_addr(int8_t *iface)
@@ -94,6 +95,7 @@ int main(int argc, char *argv[])
struct igb_packet *tmp_packet;
struct igb_packet *cleaned_packets;
struct igb_packet *free_packets;
+ struct mrp_talker_ctx *ctx = malloc(sizeof(struct mrp_talker_ctx));
six1883_header *h61883;
seventeen22_header *h1722;
unsigned i;
@@ -106,6 +108,8 @@ int main(int argc, char *argv[])
void *stream_packet;
long long int frame_sequence = 0;
struct sched_param sched;
+ struct mrp_domain_attr *class_a = malloc(sizeof(struct mrp_domain_attr));
+ struct mrp_domain_attr *class_b = malloc(sizeof(struct mrp_domain_attr));
if (argc < 2) {
fprintf(stderr,"%s <if_name> <payload>\n", argv[0]);
@@ -116,9 +120,14 @@ int main(int argc, char *argv[])
packet_size = atoi(argv[2]);;
glob_payload_length = atoi(argv[2]);;
packet_size += sizeof(six1883_header) + sizeof(seventeen22_header) + sizeof(eth_header);
-
+ err = mrp_talker_client_init(ctx);
+ if (err) {
+ printf("MRP talker client initialization failed\n");
+ return errno;
+ }
+ halt_tx_sig = &ctx->halt_tx;
#ifdef USE_MRPD
- err = mrp_connect();
+ err = mrp_connect(ctx);
if (err) {
fprintf(stderr, "socket creation failed\n");
return errno;
@@ -152,28 +161,24 @@ int main(int argc, char *argv[])
}
#ifdef USE_MRPD
- err = mrp_monitor();
+ err = mrp_get_domain(ctx, class_a, class_b);
if (err) {
- printf("failed creating MRP monitor thread\n");
+ printf("failed calling msp_get_domain()\n");
return EXIT_FAILURE;
}
+ fprintf(stderr, "detected domain Class A PRIO=%d VID=%04x...\n", class_a->priority,
+ class_a->vid);
- domain_a_valid = 1;
- domain_class_a_id = MSRP_SR_CLASS_A;
- domain_class_a_priority = MSRP_SR_CLASS_A_PRIO;
- domain_class_a_vid = 2;
- fprintf(stderr, "detected domain Class A PRIO=%d VID=%04x...\n", domain_class_a_priority,
- domain_class_a_vid);
-
- err = mrp_register_domain(&domain_class_a_id, &domain_class_a_priority, &domain_class_a_vid);
+ err = mrp_register_domain(class_a, ctx);
if (err) {
printf("mrp_register_domain failed\n");
return EXIT_FAILURE;
}
-
- domain_a_valid = 1;
- domain_class_a_vid = 2;
- fprintf(stderr, "detected domain Class A PRIO=%d VID=%04x...\n", domain_class_a_priority, domain_class_a_vid);
+ err = mrp_join_vlan(class_a, ctx);
+ if (err) {
+ printf("mrp_join_vlan failed\n");
+ return EXIT_FAILURE;
+ }
#endif
igb_set_class_bandwidth(&igb_dev, PACKET_IPG / 125000, 0, packet_size - 22, 0);
@@ -205,7 +210,7 @@ int main(int argc, char *argv[])
avb_set_1722_stream_id(h1722,reverse_64(STREAMID));
avb_set_1722_sid_valid(h1722, 0x1);
-
+
/*initalize h61883 header */
avb_initialize_61883_to_defaults(h61883);
avb_set_61883_format_tag(h61883, 0x1);
@@ -242,26 +247,29 @@ int main(int argc, char *argv[])
}
#ifdef USE_MRPD
- /*
- * subtract 16 bytes for the MAC header/Q-tag - pktsz is limited to the
+ /*
+ * subtract 16 bytes for the MAC header/Q-tag - pktsz is limited to the
* data payload of the ethernet frame .
*
* IPG is scaled to the Class (A) observation interval of packets per 125 usec
*/
fprintf(stderr, "advertising stream ...\n");
- err = mrp_advertise_stream(glob_stream_id, glob_dest_addr, domain_class_a_vid, packet_size - 16,
- PACKET_IPG / 125000, domain_class_a_priority, 3900);
+ err = mrp_advertise_stream(glob_stream_id, glob_dest_addr, packet_size - 16,
+ PACKET_IPG / 125000, 3900, ctx);
if (err) {
printf("mrp_advertise_stream failed\n");
return EXIT_FAILURE;
}
fprintf(stderr, "awaiting a listener ...\n");
- err = mrp_await_listener(glob_stream_id);
+ err = mrp_await_listener(glob_stream_id,ctx);
if (err) {
printf("mrp_await_listener failed\n");
return EXIT_FAILURE;
}
+ ctx->listeners = 1;
+ printf("got a listener ...\n");
+ ctx->halt_tx = 0;
#endif
@@ -269,7 +277,7 @@ int main(int argc, char *argv[])
sched.sched_priority = 1;
sched_setscheduler(0, SCHED_RR, &sched);
- while (listeners && !halt_tx)
+ while (ctx->listeners && !ctx->halt_tx)
{
tmp_packet = free_packets;
if (NULL == tmp_packet)
@@ -289,9 +297,9 @@ int main(int argc, char *argv[])
else
avb_set_1722_timestamp_valid(h1722, 1);
- data_ptr = (uint8_t *)((uint8_t*)stream_packet + sizeof(eth_header) + sizeof(seventeen22_header)
+ data_ptr = (uint8_t *)((uint8_t*)stream_packet + sizeof(eth_header) + sizeof(seventeen22_header)
+ sizeof(six1883_header));
-
+
read_bytes = read(0, (void *)data_ptr, glob_payload_length);
/* Error case while reading the input file */
if (read_bytes < 0) {
@@ -325,24 +333,27 @@ cleanup:
}
}
- if (halt_tx == 0)
+ if (ctx->halt_tx == 0)
fprintf(stderr, "listener left ...\n");
- halt_tx = 1;
+ ctx->halt_tx = 1;
sleep(1);
#ifdef USE_MRPD
- err = mrp_unadvertise_stream(glob_stream_id, glob_dest_addr, domain_class_a_vid, packet_size - 16,
- PACKET_IPG / 125000, domain_class_a_priority, 3900);
+ err = mrp_unadvertise_stream(glob_stream_id, glob_dest_addr, packet_size - 16,
+ PACKET_IPG / 125000, 3900, ctx);
if (err)
printf("mrp_unadvertise_stream failed\n");
#endif
/* disable Qav */
igb_set_class_bandwidth(&igb_dev, 0, 0, 0, 0);
#ifdef USE_MRPD
- err = mrp_disconnect();
+ err = mrp_disconnect(ctx);
if (err)
printf("mrp_disconnect failed\n");
#endif
+ free(ctx);
+ free(class_a);
+ free(class_b);
igb_dma_free_page(&igb_dev, &a_page);
err = igb_detach(&igb_dev);