Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.5 KB)

1 c0c735aa Luca Abeni
#include <stdint.h>
2 89aef955 Luca Abeni
#include <stdlib.h>
3 fd1d8d92 Luca Abeni
#include <string.h>
4 c0c735aa Luca Abeni
5 606948b2 Luca Abeni
#include "chunk.h"
6 fd1d8d92 Luca Abeni
#include "config.h"
7 c0c735aa Luca Abeni
#include "chunkiser.h"
8
#include "chunkiser_iface.h"
9
10
extern struct chunkiser_iface in_avf;
11 91e9c5d5 Luca Abeni
extern struct chunkiser_iface in_dummy;
12 fa87ad46 Luca Abeni
extern struct chunkiser_iface in_dumb;
13 c0c735aa Luca Abeni
14 fcc01ba5 Luca Abeni
struct input_stream {
15
  struct chunkiser_ctx *c;
16
  struct chunkiser_iface *in;
17
};
18 c0c735aa Luca Abeni
19
struct input_stream *input_stream_open(const char *fname, int *period, const char *config)
20
{
21 fd1d8d92 Luca Abeni
  struct tag *cfg_tags;
22 fcc01ba5 Luca Abeni
  struct input_stream *res;
23
24
  res = malloc(sizeof(struct input_stream));
25
  if (res == NULL) {
26
    return res;
27
  }
28 fd1d8d92 Luca Abeni
29 89aef955 Luca Abeni
#ifdef AVF
30 fcc01ba5 Luca Abeni
  res->in = &in_avf;
31 89aef955 Luca Abeni
#else
32 fa87ad46 Luca Abeni
  res->in = &in_dumb;
33 89aef955 Luca Abeni
#endif
34 fd1d8d92 Luca Abeni
  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 fcc01ba5 Luca Abeni
      res->in = &in_dummy;
41 fd1d8d92 Luca Abeni
    }
42 fa87ad46 Luca Abeni
    if (type && !strcmp(type, "dumb")) {
43
      res->in = &in_dumb;
44
    }
45 fd1d8d92 Luca Abeni
  }
46 dcc42706 Luca Abeni
  free(cfg_tags);
47 91e9c5d5 Luca Abeni
48 fcc01ba5 Luca Abeni
  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 c0c735aa Luca Abeni
}
57
58
void input_stream_close(struct input_stream *s)
59
{
60 fcc01ba5 Luca Abeni
  s->in->close(s->c);
61
  free(s);
62 c0c735aa Luca Abeni
}
63
64 606948b2 Luca Abeni
int chunkise(struct input_stream *s, struct chunk *c)
65 c0c735aa Luca Abeni
{
66 fcc01ba5 Luca Abeni
  c->data = s->in->chunkise(s->c, c->id, &c->size, &c->timestamp);
67 606948b2 Luca Abeni
  if (c->data == NULL) {
68
    if (c->size < 0) {
69
      return -1;
70
    }
71
72
    return 0;
73
  }
74
75
  return 1;
76 c0c735aa Luca Abeni
}
77 4cdd16a7 Luca Abeni
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
}