Statistics
| Branch: | Revision:

streamers / dumbstreamer.c @ 4ffa877f

History | View | Annotate | Download (2.19 KB)

1
/*
2
 *  Copyright (c) 2009 Luca Abeni
3
 *
4
 *  This is free software; see GPL.txt
5
 */
6
#include <stdlib.h>
7
#include <stdint.h>
8
#include <stdio.h>
9
#include <string.h>
10
#include <getopt.h>
11

    
12
#include <net_helper.h>
13
#include <topmanager.h>
14

    
15
#include "net_helpers.h"
16
#include "loop.h"
17

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

    
28
static void cmdline_parse(int argc, char *argv[])
29
{
30
  int o;
31

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

    
64
        exit(-1);
65
    }
66
  }
67
}
68

    
69
static struct nodeID *init(void)
70
{
71
  struct nodeID *myID;
72
  char *my_addr = iface_addr(my_iface);
73

    
74
  myID = net_helper_init(my_addr, port);
75
  if (myID == NULL) {
76
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
77
    free(my_addr);
78

    
79
    return NULL;
80
  }
81
  free(my_addr);
82
  topInit(myID);
83

    
84
  return myID;
85
}
86

    
87

    
88
int main(int argc, char *argv[])
89
{
90
  struct nodeID *my_sock;
91

    
92
  cmdline_parse(argc, argv);
93

    
94
  my_sock = init();
95
  if (my_sock == NULL) {
96
    return -1;
97
  }
98
  if (srv_port != 0) {
99
    struct nodeID *srv;
100

    
101
    srv = create_node(srv_ip, srv_port);
102
    if (srv == NULL) {
103
      fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
104

    
105
      return -1;
106
    }
107
    topAddNeighbour(srv);
108

    
109
    loop(my_sock, 1000000 / chunks_per_second, buff_size);
110
  }
111

    
112
  source_loop(fname, my_sock, period * 1000, multiply);
113

    
114
  return 0;
115
}