Statistics
| Branch: | Revision:

streamers / streamer.c @ f0bb64e2

History | View | Annotate | Download (2.77 KB)

1
/*
2
 *  Copyright (c) 2010 Luca Abeni
3
 *  Copyright (c) 2010 Csaba Kiraly
4
 *
5
 *  This is free software; see gpl-3.0.txt
6
 */
7
#include <stdlib.h>
8
#include <stdint.h>
9
#include <stdio.h>
10
#include <stdbool.h>
11
#include <string.h>
12
#include <getopt.h>
13
#include <msg_types.h>
14
#include <net_helper.h>
15
#include <topmanager.h>
16

    
17
#include "net_helpers.h"
18
#include "loop.h"
19
#include "output.h"
20

    
21
static const char *my_iface = "eth0";
22
static int port = 6666;
23
static int srv_port;
24
static const char *srv_ip = "";
25
static int period = 40;
26
static int chunks_per_second = 25;
27
static int multiply = 1;
28
static int buff_size = 50;
29
static int outbuff_size = 25;
30
static const char *fname = "input.mpg";
31
static bool loop_input = false;
32
unsigned char msgTypes[] = {MSG_TYPE_TOPOLOGY,MSG_TYPE_CHUNK,MSG_TYPE_SIGNALLING};
33

    
34
static void cmdline_parse(int argc, char *argv[])
35
{
36
  int o;
37

    
38
  while ((o = getopt(argc, argv, "b:o:c:t:p:i:P:I:f:m:l")) != -1) {
39
    switch(o) {
40
      case 'b':
41
        buff_size = atoi(optarg);
42
        break;
43
      case 'o':
44
        outbuff_size = atoi(optarg);
45
        break;
46
      case 'c':
47
        chunks_per_second = atoi(optarg);
48
        break;
49
      case 'm':
50
        multiply = atoi(optarg);
51
        break;
52
      case 't':
53
        period = atoi(optarg);
54
        break;
55
      case 'p':
56
        srv_port = atoi(optarg);
57
        break;
58
      case 'i':
59
        srv_ip = strdup(optarg);
60
        break;
61
      case 'P':
62
        port =  atoi(optarg);
63
        break;
64
      case 'I':
65
        my_iface = strdup(optarg);
66
        break;
67
      case 'f':
68
        fname = strdup(optarg);
69
        break;
70
      case 'l':
71
        loop_input = true;
72
        break;
73
      default:
74
        fprintf(stderr, "Error: unknown option %c\n", o);
75

    
76
        exit(-1);
77
    }
78
  }
79
}
80

    
81
static struct nodeID *init(void)
82
{
83
  int i;
84
  struct nodeID *myID;
85
  char *my_addr = iface_addr(my_iface);
86

    
87
  if (my_addr == NULL) {
88
    fprintf(stderr, "Cannot find network interface %s\n", my_iface);
89

    
90
    return NULL;
91
  }
92
  for (i=0;i<3;i++)
93
          bind_msg_type(msgTypes[i]);
94
  myID = net_helper_init(my_addr, port);
95
  if (myID == NULL) {
96
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
97
    free(my_addr);
98

    
99
    return NULL;
100
  }
101
  free(my_addr);
102
  topInit(myID);
103

    
104
  output_init(outbuff_size);
105

    
106
  return myID;
107
}
108

    
109

    
110
int main(int argc, char *argv[])
111
{
112
  struct nodeID *my_sock;
113

    
114
  cmdline_parse(argc, argv);
115

    
116
  my_sock = init();
117
  if (my_sock == NULL) {
118
    return -1;
119
  }
120
  if (srv_port != 0) {
121
    struct nodeID *srv;
122

    
123
    srv = create_node(srv_ip, srv_port);
124
    if (srv == NULL) {
125
      fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
126

    
127
      return -1;
128
    }
129
    topAddNeighbour(srv);
130

    
131
    loop(my_sock, 1000000 / chunks_per_second, buff_size);
132
  }
133

    
134
  source_loop(fname, my_sock, period * 1000, multiply, loop_input);
135

    
136
  return 0;
137
}