Statistics
| Branch: | Revision:

grapes / src / Chunkiser / input-stream.c @ fcc01ba5

History | View | Annotate | Download (1.25 KB)

1
#include <stdint.h>
2
#include <stdlib.h>
3
#include <string.h>
4

    
5
#include "chunk.h"
6
#include "config.h"
7
#include "chunkiser.h"
8
#include "chunkiser_iface.h"
9

    
10
extern struct chunkiser_iface in_avf;
11
extern struct chunkiser_iface in_dummy;
12

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

    
18
struct input_stream *input_stream_open(const char *fname, int *period, const char *config)
19
{
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
  }
27

    
28
#ifdef AVF
29
  res->in = &in_avf;
30
#else
31
  res->in = &in_dummy;
32
#endif
33
  cfg_tags = config_parse(config);
34
  if (cfg_tags) {
35
    const char *type;
36

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

    
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;
52
}
53

    
54
void input_stream_close(struct input_stream *s)
55
{
56
  s->in->close(s->c);
57
  free(s);
58
}
59

    
60
int chunkise(struct input_stream *s, struct chunk *c)
61
{
62
  c->data = s->in->chunkise(s->c, c->id, &c->size, &c->timestamp);
63
  if (c->data == NULL) {
64
    if (c->size < 0) {
65
      return -1;
66
    }
67

    
68
    return 0;
69
  }
70

    
71
  return 1;
72
}