Statistics
| Branch: | Revision:

streamers / streamer.c @ 581339c4

History | View | Annotate | Download (3.01 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
#include "channel.h"
21

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

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

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

    
80
        exit(-1);
81
    }
82
  }
83

    
84
  if (!channel_get_name()) {
85
    channel_set_name("generic");
86
  }
87
}
88

    
89
static struct nodeID *init(void)
90
{
91
  int i;
92
  struct nodeID *myID;
93
  char *my_addr;
94

    
95
  if (my_iface) {
96
    my_addr = iface_addr(my_iface);
97
  } else {
98
    my_addr = default_ip_addr();
99
  }
100

    
101
  if (my_addr == NULL) {
102
    fprintf(stderr, "Cannot find network interface %s\n", my_iface);
103

    
104
    return NULL;
105
  }
106
  for (i=0;i<3;i++)
107
          bind_msg_type(msgTypes[i]);
108
  myID = net_helper_init(my_addr, port);
109
  if (myID == NULL) {
110
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
111
    free(my_addr);
112

    
113
    return NULL;
114
  }
115
  free(my_addr);
116
  topInit(myID, NULL, 0);
117

    
118
  output_init(outbuff_size);
119

    
120
  return myID;
121
}
122

    
123

    
124
int main(int argc, char *argv[])
125
{
126
  struct nodeID *my_sock;
127

    
128
  cmdline_parse(argc, argv);
129

    
130
  my_sock = init();
131
  if (my_sock == NULL) {
132
    return -1;
133
  }
134
  if (srv_port != 0) {
135
    struct nodeID *srv;
136

    
137
    srv = create_node(srv_ip, srv_port);
138
    if (srv == NULL) {
139
      fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
140

    
141
      return -1;
142
    }
143
    topAddNeighbour(srv, NULL, 0);
144

    
145
    loop(my_sock, 1000000 / chunks_per_second, buff_size);
146
  }
147

    
148
  source_loop(fname, my_sock, period * 1000, multiply, loop_input);
149

    
150
  return 0;
151
}