Statistics
| Branch: | Revision:

streamers / dumbstreamer.c @ 46c24e94

History | View | Annotate | Download (2.46 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

    
14
#include <net_helper.h>
15
#include <topmanager.h>
16

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

    
20
static const char *my_iface = "eth0";
21
static int port = 6666;
22
static int srv_port;
23
static const char *srv_ip = "";
24
static int period = 500;
25
static int chunks_per_second = 4;
26
static int multiply = 1;
27
static int buff_size = 8;
28
static const char *fname = "input.mpg";
29
static bool loop_input = false;
30

    
31
static void cmdline_parse(int argc, char *argv[])
32
{
33
  int o;
34

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

    
70
        exit(-1);
71
    }
72
  }
73
}
74

    
75
static struct nodeID *init(void)
76
{
77
  struct nodeID *myID;
78
  char *my_addr = iface_addr(my_iface);
79

    
80
  if (my_addr == NULL) {
81
    fprintf(stderr, "Cannot find network interface %s\n", my_iface);
82

    
83
    return NULL;
84
  }
85

    
86
  myID = net_helper_init(my_addr, port);
87
  if (myID == NULL) {
88
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
89
    free(my_addr);
90

    
91
    return NULL;
92
  }
93
  free(my_addr);
94
  topInit(myID);
95

    
96
  return myID;
97
}
98

    
99

    
100
int main(int argc, char *argv[])
101
{
102
  struct nodeID *my_sock;
103

    
104
  cmdline_parse(argc, argv);
105

    
106
  my_sock = init();
107
  if (my_sock == NULL) {
108
    return -1;
109
  }
110
  if (srv_port != 0) {
111
    struct nodeID *srv;
112

    
113
    srv = create_node(srv_ip, srv_port);
114
    if (srv == NULL) {
115
      fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
116

    
117
      return -1;
118
    }
119
    topAddNeighbour(srv);
120

    
121
    loop(my_sock, 1000000 / chunks_per_second, buff_size);
122
  }
123

    
124
  source_loop(fname, my_sock, period * 1000, multiply, loop_input);
125

    
126
  return 0;
127
}