Revision fcc01ba5 src/Chunkiser/input-stream.c

View differences:

src/Chunkiser/input-stream.c
10 10
extern struct chunkiser_iface in_avf;
11 11
extern struct chunkiser_iface in_dummy;
12 12

  
13
static struct chunkiser_iface *in;
13
struct input_stream {
14
  struct chunkiser_ctx *c;
15
  struct chunkiser_iface *in;
16
};
14 17

  
15 18
struct input_stream *input_stream_open(const char *fname, int *period, const char *config)
16 19
{
17 20
  struct tag *cfg_tags;
21
  struct input_stream *res;
22

  
23
  res = malloc(sizeof(struct input_stream));
24
  if (res == NULL) {
25
    return res;
26
  }
18 27

  
19 28
#ifdef AVF
20
  in = &in_avf;
29
  res->in = &in_avf;
21 30
#else
22
  in = &in_dummy;
31
  res->in = &in_dummy;
23 32
#endif
24 33
  cfg_tags = config_parse(config);
25

  
26 34
  if (cfg_tags) {
27 35
    const char *type;
28 36

  
29 37
    type = config_value_str(cfg_tags, "chunkiser");
30 38
    if (type && !strcmp(type, "dummy")) {
31
      in = &in_dummy;
39
      res->in = &in_dummy;
32 40
    }
33 41
  }
34 42
  free(cfg_tags);
35 43

  
36
  return in->open(fname, period, config);
44
  res->c = res->in->open(fname, period, config);
45
  if (res->c == NULL) {
46
    free(res);
47

  
48
    return NULL;
49
  }
50

  
51
  return res;
37 52
}
38 53

  
39 54
void input_stream_close(struct input_stream *s)
40 55
{
41
  return in->close(s);
56
  s->in->close(s->c);
57
  free(s);
42 58
}
43 59

  
44 60
int chunkise(struct input_stream *s, struct chunk *c)
45 61
{
46
  c->data = in->chunkise(s, c->id, &c->size, &c->timestamp);
62
  c->data = s->in->chunkise(s->c, c->id, &c->size, &c->timestamp);
47 63
  if (c->data == NULL) {
48 64
    if (c->size < 0) {
49 65
      return -1;

Also available in: Unified diff