Statistics
| Branch: | Revision:

grapes / src / Tests / chunkiser_test.c @ 9c68eee7

History | View | Annotate | Download (2.65 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, "f:rRdlavV")) != -1) {
36
    switch(o) {
37
      case 'f':
38
        out_ptr = addopt(out_opts, out_ptr, "format", optarg);
39
        break;
40
      case 'r':
41
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
42
        break;
43
      case 'R':
44
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
45
        out_ptr = addopt(out_opts, out_ptr, "payload", "avf");
46
        break;
47
      case 'd':
48
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "dummy");
49
        break;
50
      case 'a':
51
        in_ptr = addopt(in_opts, in_ptr, "media", "audio");
52
        out_ptr = addopt(out_opts, out_ptr, "media", "audio");
53
        break;
54
      case 'v':
55
        in_ptr = addopt(in_opts, in_ptr, "media", "video");
56
        out_ptr = addopt(out_opts, out_ptr, "media", "video");
57
        break;
58
      case 'V':
59
        in_ptr = addopt(in_opts, in_ptr, "media", "av");
60
        out_ptr = addopt(out_opts, out_ptr, "media", "av");
61
        break;
62
      default:
63
        fprintf(stderr, "Error: unknown option %c\n", o);
64

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

    
69
  return optind - 1;
70
}
71

    
72
int main(int argc, char *argv[])
73
{
74
  int period, done, id;
75
  struct input_stream *input;
76
  struct output_stream *output;
77

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

    
81
    return -1;
82
  }
83
  argv += cmdline_parse(argc, argv);
84
  input = input_stream_open(argv[1], &period, in_opts);
85
  if (input == NULL) {
86
    fprintf(stderr, "Cannot open input %s\n", argv[1]);
87

    
88
    return -1;
89
  }
90
  output = out_stream_init(argv[2], out_opts);
91
  if (output == NULL) {
92
    fprintf(stderr, "Cannot open output %s\n", argv[2]);
93

    
94
    return -1;
95
  }
96

    
97
  done = 0; id = 0;
98
  while(!done) {
99
    int res;
100
    struct chunk c;
101

    
102
    c.id = id;
103
    res = chunkise(input, &c);
104
    if (res > 0) {
105
      fprintf(stderr,"chunk %d: %d %llu\n", id++, c.size, c.timestamp);
106
      chunk_write(output, &c);
107
    } else if (res < 0) {
108
      done = 1;
109
    }
110
    free(c.data);
111
  }
112
  input_stream_close(input);
113
  out_stream_close(output);
114

    
115
  return 0;
116
}