Statistics
| Branch: | Revision:

streamers / streamer.c @ 613263e9

History | View | Annotate | Download (2.85 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 = NULL;
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;
86

    
87
  if (my_iface) {
88
    my_addr = iface_addr(my_iface);
89
  } else {
90
    my_addr = default_ip_addr(my_iface);
91
  }
92

    
93
  if (my_addr == NULL) {
94
    fprintf(stderr, "Cannot find network interface %s\n", my_iface);
95

    
96
    return NULL;
97
  }
98
  for (i=0;i<3;i++)
99
          bind_msg_type(msgTypes[i]);
100
  myID = net_helper_init(my_addr, port);
101
  if (myID == NULL) {
102
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
103
    free(my_addr);
104

    
105
    return NULL;
106
  }
107
  free(my_addr);
108
  topInit(myID);
109

    
110
  output_init(outbuff_size);
111

    
112
  return myID;
113
}
114

    
115

    
116
int main(int argc, char *argv[])
117
{
118
  struct nodeID *my_sock;
119

    
120
  cmdline_parse(argc, argv);
121

    
122
  my_sock = init();
123
  if (my_sock == NULL) {
124
    return -1;
125
  }
126
  if (srv_port != 0) {
127
    struct nodeID *srv;
128

    
129
    srv = create_node(srv_ip, srv_port);
130
    if (srv == NULL) {
131
      fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
132

    
133
      return -1;
134
    }
135
    topAddNeighbour(srv);
136

    
137
    loop(my_sock, 1000000 / chunks_per_second, buff_size);
138
  }
139

    
140
  source_loop(fname, my_sock, period * 1000, multiply, loop_input);
141

    
142
  return 0;
143
}