Statistics
| Branch: | Revision:

grapes / src / Chunkiser / input-stream.c @ 54f6182b

History | View | Annotate | Download (1.75 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
extern struct chunkiser_iface in_udp;
14

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

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

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

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

    
39
    type = config_value_str(cfg_tags, "chunkiser");
40
    if (type && !strcmp(type, "dummy")) {
41
      res->in = &in_dummy;
42
    }
43
    if (type && !strcmp(type, "dumb")) {
44
      res->in = &in_dumb;
45
    }
46
    if (type && !strcmp(type, "udp")) {
47
      res->in = &in_udp;
48
    }
49
    if (type && !strcmp(type, "avf")) {
50
#ifdef AVF
51
      res->in = &in_avf;
52
#else
53
      free(res);
54
      free(cfg_tags);
55

    
56
      return NULL;
57
#endif
58
    }
59
  }
60
  free(cfg_tags);
61

    
62
  res->c = res->in->open(fname, period, config);
63
  if (res->c == NULL) {
64
    free(res);
65

    
66
    return NULL;
67
  }
68

    
69
  return res;
70
}
71

    
72
void input_stream_close(struct input_stream *s)
73
{
74
  s->in->close(s->c);
75
  free(s);
76
}
77

    
78
int chunkise(struct input_stream *s, struct chunk *c)
79
{
80
  c->data = s->in->chunkise(s->c, c->id, &c->size, &c->timestamp);
81
  if (c->data == NULL) {
82
    if (c->size < 0) {
83
      return -1;
84
    }
85

    
86
    return 0;
87
  }
88

    
89
  return 1;
90
}
91

    
92
const int *input_get_fds(const struct input_stream *s)
93
{
94
  if (s->in->get_fds) {
95
    return s->in->get_fds(s->c);
96
  }
97

    
98
  return NULL;
99
}
100