summaryrefslogtreecommitdiff
path: root/examples/live_stream
diff options
context:
space:
mode:
authorJean-Baptiste Maillet <jean-baptiste.maillet@parrot.com>2014-11-17 18:15:49 +0100
committerJean-Baptiste Maillet <jean-baptiste.maillet@parrot.com>2014-11-17 18:15:49 +0100
commit195293b121ba94da0d11834b5abc72733d0a93f2 (patch)
tree3a527ba555a261982b98827d50d4a971a28d348c /examples/live_stream
parentf157349542ce5a5c03d8fe15c9c38c19eb570ad0 (diff)
downloadOpen-AVB-195293b121ba94da0d11834b5abc72733d0a93f2.tar.gz
live_stream listener: use same MRP code as simple_listener.
Build tested.
Diffstat (limited to 'examples/live_stream')
-rw-r--r--examples/live_stream/Makefile15
-rw-r--r--examples/live_stream/listener.c166
2 files changed, 11 insertions, 170 deletions
diff --git a/examples/live_stream/Makefile b/examples/live_stream/Makefile
index 68d874e4..f5ce53b0 100644
--- a/examples/live_stream/Makefile
+++ b/examples/live_stream/Makefile
@@ -11,14 +11,19 @@ talker: talker.o ../common/avb.o ../common/talker_mrp_client.o
talker.o: talker.c
gcc -c $(INCFLAGS) talker.c $(CFLAGS) $(EXTRA_FLAGS)
-../common/avb.o:
- make -C ../common/ avb.o
-
../common/talker_mrp_client.o:
make -C ../common/ talker_mrp_client.o
-listener:listener.c
- gcc -o listener $(INCFLAGS) listener.c $(CFLAGS) $(EXTRA_FLAGS)
+listener: listener.o ../common/avb.o ../common/listener_mrp_client.o
+
+listener.o: listener.c
+ gcc -c $(INCFLAGS) listener.c $(CFLAGS) $(EXTRA_FLAGS)
+
+../common/listener_mrp_client.o:
+ make -C ../common/ listener_mrp_client.o
+
+../common/avb.o:
+ make -C ../common/ avb.o
%: %.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) $(EXTRA_FLAGS) -o $@
diff --git a/examples/live_stream/listener.c b/examples/live_stream/listener.c
index 2aee4d09..b7b9426d 100644
--- a/examples/live_stream/listener.c
+++ b/examples/live_stream/listener.c
@@ -49,178 +49,14 @@
#include <sys/user.h>
#include "avb.h"
-
-/* global macros */
-#define MAX_FRAME_SIZE 1500
+#include "listener_mrp_client.h"
device_t igb_dev;
unsigned char DEST_ADDR[] = { 0x91, 0xE0, 0xF0, 0x00, 0x0E, 0x80 };
-unsigned char stream_id[8];
-
-int control_socket = 0;
-volatile int talker = 0;
-
#define USE_MRPD 1
-#ifdef USE_MRPD
-int msg_process(char *buf, int buflen)
-{
- uint32_t id;
- int j ;
- fprintf(stderr, "Msg: %s\n", buf);
- int l = 0;
- if ('S' == buf[l++] && 'N' == buf[l++] && 'E' == buf[l++] && 'T' == buf[++l]) {
- while ('S' != buf[l++]);
- l++;
- for(j = 0; j < 8 ; l+=2, j++)
- {
- sscanf(&buf[l],"%02x",&id);
- stream_id[j] = (unsigned char)id;
- }
- talker = 1;
- }
- return 0;
-}
-
-int recv_msg()
-{
- char *databuf;
- int bytes = 0;
-
- databuf = (char *)malloc(2000);
- if (NULL == databuf)
- return -1;
-
- memset(databuf, 0, 2000);
- bytes = recv(control_socket, databuf, 2000, 0);
- if (bytes <= -1) {
- free(databuf);
- return -1;
- }
- return msg_process(databuf, bytes);
-
-}
-
-int await_talker()
-{
- while (0 == talker)
- recv_msg();
- return 0;
-}
-
-int send_msg(char *data, int data_len)
-{
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(MRPD_PORT_DEFAULT);
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- inet_aton("127.0.0.1", &addr.sin_addr);
- if (-1 != control_socket)
- return (sendto(control_socket, data, data_len, 0, (struct sockaddr*)&addr, (socklen_t)sizeof(addr)));
- else
- return 0;
-}
-
-int mrp_disconnect()
-{
- int rc;
- char *msgbuf = malloc(1500);
- if (NULL == msgbuf)
- return -1;
- memset(msgbuf, 0, 1500);
- sprintf(msgbuf, "BYE");
- rc = send_msg(msgbuf, 1500);
-
- free(msgbuf);
- return rc;
-}
-
-int report_domain_status()
-{
- int rc;
- char* msgbuf = malloc(1500);
-
- if (NULL == msgbuf)
- return -1;
- memset(msgbuf, 0, 1500);
- sprintf(msgbuf, "S+D:C=6,P=3,V=0002");
-
- rc = send_msg(msgbuf, 1500);
-
- free(msgbuf);
- return rc;
-}
-
-int send_ready()
-{
- char *databuf;
- int rc;
- databuf = malloc(1500);
- if (NULL == databuf)
- return -1;
- memset(databuf, 0, 1500);
- sprintf(databuf, "S+L:L=%02x%02x%02x%02x%02x%02x%02x%02x, D=2",
- stream_id[0], stream_id[1],
- stream_id[2], stream_id[3],
- stream_id[4], stream_id[5],
- stream_id[6], stream_id[7]);
- rc = send_msg(databuf, 1500);
-
-#ifdef DEBUG
- fprintf(stdout,"Ready-Msg: %s\n", databuf);
-#endif
-
- free(databuf);
- return rc;
-}
-
-int send_leave()
-{
- char *databuf;
- int rc;
- databuf = malloc(1500);
- if (NULL == databuf)
- return -1;
- memset(databuf, 0, 1500);
- sprintf(databuf, "S-L:L=%02x%02x%02x%02x%02x%02x%02x%02x, D=3",
- stream_id[0], stream_id[1],
- stream_id[2], stream_id[3],
- stream_id[4], stream_id[5],
- stream_id[6], stream_id[7]);
- rc = send_msg(databuf, 1500);
- free(databuf);
- return rc;
-}
-
-int create_socket()
-{
- struct sockaddr_in addr;
- control_socket = socket(AF_INET, SOCK_DGRAM, 0);
-
- /** in POSIX fd 0,1,2 are reserved */
- if (2 > control_socket) {
- if (-1 > control_socket)
- close(control_socket);
- return -EINVAL;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(0);
-
- if(0 > (bind(control_socket, (struct sockaddr*)&addr, sizeof(addr)))) {
- fprintf(stderr, "Could not bind socket.\n");
- close(control_socket);
- return -EINVAL;
- }
- return 0;
-}
-
-#endif
-
void sigint_handler(int signum)
{
fprintf(stderr, "got SIGINT\n");