Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.04 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 05c9dabb Luca Abeni
extern struct chunkiser_iface in_udp;
14 f31ebd3b Luca Abeni
extern struct chunkiser_iface in_ts;
15 e669aa38 Luca Abeni
extern struct chunkiser_iface in_ipb;
16 c0c735aa Luca Abeni
17 fcc01ba5 Luca Abeni
struct input_stream {
18
  struct chunkiser_ctx *c;
19
  struct chunkiser_iface *in;
20
};
21 c0c735aa Luca Abeni
22
struct input_stream *input_stream_open(const char *fname, int *period, const char *config)
23
{
24 fd1d8d92 Luca Abeni
  struct tag *cfg_tags;
25 fcc01ba5 Luca Abeni
  struct input_stream *res;
26
27
  res = malloc(sizeof(struct input_stream));
28
  if (res == NULL) {
29
    return res;
30
  }
31 fd1d8d92 Luca Abeni
32 89aef955 Luca Abeni
#ifdef AVF
33 fcc01ba5 Luca Abeni
  res->in = &in_avf;
34 89aef955 Luca Abeni
#else
35 fa87ad46 Luca Abeni
  res->in = &in_dumb;
36 89aef955 Luca Abeni
#endif
37 fd1d8d92 Luca Abeni
  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 fcc01ba5 Luca Abeni
      res->in = &in_dummy;
44 fd1d8d92 Luca Abeni
    }
45 fa87ad46 Luca Abeni
    if (type && !strcmp(type, "dumb")) {
46
      res->in = &in_dumb;
47
    }
48 f31ebd3b Luca Abeni
    if (type && !strcmp(type, "ts")) {
49
      res->in = &in_ts;
50
    }
51 05c9dabb Luca Abeni
    if (type && !strcmp(type, "udp")) {
52
      res->in = &in_udp;
53
    }
54 54f6182b Luca Abeni
    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 e669aa38 Luca Abeni
    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 fd1d8d92 Luca Abeni
  }
75 dcc42706 Luca Abeni
  free(cfg_tags);
76 91e9c5d5 Luca Abeni
77 fcc01ba5 Luca Abeni
  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 c0c735aa Luca Abeni
}
86
87
void input_stream_close(struct input_stream *s)
88
{
89 fcc01ba5 Luca Abeni
  s->in->close(s->c);
90
  free(s);
91 c0c735aa Luca Abeni
}
92
93 606948b2 Luca Abeni
int chunkise(struct input_stream *s, struct chunk *c)
94 c0c735aa Luca Abeni
{
95 fcc01ba5 Luca Abeni
  c->data = s->in->chunkise(s->c, c->id, &c->size, &c->timestamp);
96 606948b2 Luca Abeni
  if (c->data == NULL) {
97
    if (c->size < 0) {
98
      return -1;
99
    }
100
101
    return 0;
102
  }
103
104
  return 1;
105 c0c735aa Luca Abeni
}
106 4cdd16a7 Luca Abeni
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
}