Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (991 Bytes)

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
static struct chunkiser_iface *in;
14

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

    
19
#ifdef AVF
20
  in = &in_avf;
21
#else
22
  in = &in_dummy;
23
#endif
24
  cfg_tags = config_parse(config);
25

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

    
29
    type = config_value_str(cfg_tags, "chunkiser");
30
    if (type && !strcmp(type, "dummy")) {
31
      in = &in_dummy;
32
    }
33
  }
34

    
35
  return in->open(fname, period, config);
36
}
37

    
38
void input_stream_close(struct input_stream *s)
39
{
40
  return in->close(s);
41
}
42

    
43
int chunkise(struct input_stream *s, struct chunk *c)
44
{
45
  c->data = in->chunkise(s, c->id, &c->size, &c->timestamp);
46
  if (c->data == NULL) {
47
    if (c->size < 0) {
48
      return -1;
49
    }
50

    
51
    return 0;
52
  }
53

    
54
  return 1;
55
}