Statistics
| Branch: | Revision:

grapes / src / Chunkiser / input-stream.c @ 4cdd16a7

History | View | Annotate | Download (1.5 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
extern struct chunkiser_iface in_dumb;
13

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

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

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

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

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

    
48
  res->c = res->in->open(fname, period, config);
49
  if (res->c == NULL) {
50
    free(res);
51

    
52
    return NULL;
53
  }
54

    
55
  return res;
56
}
57

    
58
void input_stream_close(struct input_stream *s)
59
{
60
  s->in->close(s->c);
61
  free(s);
62
}
63

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

    
72
    return 0;
73
  }
74

    
75
  return 1;
76
}
77

    
78
const int *input_get_fds(const struct input_stream *s)
79
{
80
  if (s->in->get_fds) {
81
    return s->in->get_fds(s->c);
82
  }
83

    
84
  return NULL;
85
}
86