Statistics
| Branch: | Revision:

grapes / src / Tests / chunkiser_test.c @ c4d3fd11

History | View | Annotate | Download (2.96 KB)

1
/*
2
 *  Copyright (c) 2010 Csaba Kiraly
3
 *  Copyright (c) 2010 Luca Abeni
4
 *
5
 *  This is free software; see gpl-3.0.txt
6
 */
7

    
8
#include <unistd.h>
9
#include <stdio.h>
10
#include <stdint.h>
11
#include <stdlib.h>
12
#include <sys/types.h>
13

    
14
#include "chunk.h"
15
#include "chunkiser.h"
16

    
17
static char out_opts[1024];
18
static char *out_ptr = out_opts;
19
static char in_opts[1024];
20
static char *in_ptr = in_opts;
21

    
22
static char *addopt(char *opts, char *opts_ptr, const char *tag, const char *value)
23
{
24
  if (opts_ptr != opts) {
25
    *opts_ptr++ = ',';
26
  }
27
  opts_ptr += sprintf(opts_ptr, "%s=%s", tag, value);
28
  return opts_ptr;
29
}
30

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

    
35
  while ((o = getopt(argc, argv, "u:f:rRdlavVU")) != -1) {
36
    switch(o) {
37
      case 'u':
38
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "udp");
39
        in_ptr = addopt(in_opts, in_ptr, "port1", optarg);
40
        break;
41
      case 'f':
42
        out_ptr = addopt(out_opts, out_ptr, "format", optarg);
43
        break;
44
      case 'r':
45
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
46
        break;
47
      case 'R':
48
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
49
        out_ptr = addopt(out_opts, out_ptr, "payload", "avf");
50
        break;
51
      case 'U':
52
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
53
        out_ptr = addopt(out_opts, out_ptr, "payload", "udp");
54
        break;
55
      case 'd':
56
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "dummy");
57
        break;
58
      case 'a':
59
        in_ptr = addopt(in_opts, in_ptr, "media", "audio");
60
        out_ptr = addopt(out_opts, out_ptr, "media", "audio");
61
        break;
62
      case 'v':
63
        in_ptr = addopt(in_opts, in_ptr, "media", "video");
64
        out_ptr = addopt(out_opts, out_ptr, "media", "video");
65
        break;
66
      case 'V':
67
        in_ptr = addopt(in_opts, in_ptr, "media", "av");
68
        out_ptr = addopt(out_opts, out_ptr, "media", "av");
69
        break;
70
      default:
71
        fprintf(stderr, "Error: unknown option %c\n", o);
72

    
73
        exit(-1);
74
    }
75
  }
76

    
77
  return optind - 1;
78
}
79

    
80
int main(int argc, char *argv[])
81
{
82
  int period, done, id;
83
  struct input_stream *input;
84
  struct output_stream *output;
85

    
86
  if (argc < 3) {
87
    fprintf(stderr, "Usage: %s <input> <output>\n", argv[0]);
88

    
89
    return -1;
90
  }
91
  argv += cmdline_parse(argc, argv);
92
  input = input_stream_open(argv[1], &period, in_opts);
93
  if (input == NULL) {
94
    fprintf(stderr, "Cannot open input %s\n", argv[1]);
95

    
96
    return -1;
97
  }
98
  output = out_stream_init(argv[2], out_opts);
99
  if (output == NULL) {
100
    fprintf(stderr, "Cannot open output %s\n", argv[2]);
101

    
102
    return -1;
103
  }
104

    
105
  done = 0; id = 0;
106
  while(!done) {
107
    int res;
108
    struct chunk c;
109

    
110
    c.id = id;
111
    res = chunkise(input, &c);
112
    if (res > 0) {
113
      fprintf(stderr,"chunk %d: %d %llu\n", id++, c.size, c.timestamp);
114
      chunk_write(output, &c);
115
    } else if (res < 0) {
116
      done = 1;
117
    }
118
    free(c.data);
119
  }
120
  input_stream_close(input);
121
  out_stream_close(output);
122

    
123
  return 0;
124
}