Statistics
| Branch: | Revision:

grapes / src / Chunkiser / input-stream.c @ 734f6960

History | View | Annotate | Download (2.04 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
extern struct chunkiser_iface in_ts;
15
extern struct chunkiser_iface in_ipb;
16

    
17
struct input_stream {
18
  struct chunkiser_ctx *c;
19
  struct chunkiser_iface *in;
20
};
21

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

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

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

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

    
61
      return NULL;
62
#endif
63
    }
64
    if (type && !strcmp(type, "ipb")) {
65
#ifdef AVF
66
      res->in = &in_ipb;
67
#else
68
      free(res);
69
      free(cfg_tags);
70

    
71
      return NULL;
72
#endif
73
    }
74
  }
75
  free(cfg_tags);
76

    
77
  res->c = res->in->open(fname, period, config);
78
  if (res->c == NULL) {
79
    free(res);
80

    
81
    return NULL;
82
  }
83

    
84
  return res;
85
}
86

    
87
void input_stream_close(struct input_stream *s)
88
{
89
  s->in->close(s->c);
90
  free(s);
91
}
92

    
93
int chunkise(struct input_stream *s, struct chunk *c)
94
{
95
  c->data = s->in->chunkise(s->c, c->id, &c->size, &c->timestamp);
96
  if (c->data == NULL) {
97
    if (c->size < 0) {
98
      return -1;
99
    }
100

    
101
    return 0;
102
  }
103

    
104
  return 1;
105
}
106

    
107
const int *input_get_fds(const struct input_stream *s)
108
{
109
  if (s->in->get_fds) {
110
    return s->in->get_fds(s->c);
111
  }
112

    
113
  return NULL;
114
}
115