Statistics
| Branch: | Revision:

grapes / src / Chunkiser / output-stream.c @ 997c2b68

History | View | Annotate | Download (1.41 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 "dechunkiser_iface.h"
9
10
extern struct dechunkiser_iface out_avf;
11 91e9c5d5 Luca Abeni
extern struct dechunkiser_iface out_raw;
12 e7180bea Luca Abeni
extern struct dechunkiser_iface out_udp;
13 8b70c289 Luca Abeni
14
struct output_stream {
15
  struct dechunkiser_ctx *c;
16
  struct dechunkiser_iface *out;
17
};
18 c0c735aa Luca Abeni
19 e296176d Luca Abeni
struct output_stream *out_stream_init(const char *fname, const char *config)
20 c0c735aa Luca Abeni
{
21 fd1d8d92 Luca Abeni
  struct tag *cfg_tags;
22 8b70c289 Luca Abeni
  struct output_stream *res;
23
24
  res = malloc(sizeof(struct output_stream));
25
  if (res == NULL) {
26
    return NULL;
27
  }
28 fd1d8d92 Luca Abeni
29 89aef955 Luca Abeni
#ifdef AVF
30 8b70c289 Luca Abeni
  res->out = &out_avf;
31 89aef955 Luca Abeni
#else
32 8b70c289 Luca Abeni
  res->out = &out_raw;
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, "dechunkiser");
39
    if (type && !strcmp(type, "raw")) {
40 8b70c289 Luca Abeni
      res->out = &out_raw;
41 e7180bea Luca Abeni
    } else if (type && !strcmp(type, "udp")) {
42
      res->out = &out_udp;
43 54f6182b Luca Abeni
    } else if (type && !strcmp(type, "avf")) {
44
#ifdef AVF
45
      res->out = &out_avf;
46
#else
47
      free(res);
48
      free(cfg_tags);
49
50
      return NULL;
51
#endif
52 fd1d8d92 Luca Abeni
    }
53
  }
54 dcc42706 Luca Abeni
  free(cfg_tags);
55 c0c735aa Luca Abeni
56 8b70c289 Luca Abeni
  res->c = res->out->open(fname, config);
57
  if (res->c == NULL) {
58
    free(res);
59
60
    return NULL;
61
  }
62
63
  return res;
64 c0c735aa Luca Abeni
}
65
66 386bce8c Luca Abeni
void out_stream_close(struct output_stream *s)
67
{
68 8b70c289 Luca Abeni
  s->out->close(s->c);
69
  free(s);
70 386bce8c Luca Abeni
}
71
72 0c461e28 Luca Abeni
void chunk_write(struct output_stream *o, const struct chunk *c)
73 c0c735aa Luca Abeni
{
74 8b70c289 Luca Abeni
  o->out->write(o->c, c->id, c->data, c->size);
75 c0c735aa Luca Abeni
}