Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.14 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 8b70c289 Luca Abeni
13
struct output_stream {
14
  struct dechunkiser_ctx *c;
15
  struct dechunkiser_iface *out;
16
};
17 c0c735aa Luca Abeni
18 e296176d Luca Abeni
struct output_stream *out_stream_init(const char *fname, const char *config)
19 c0c735aa Luca Abeni
{
20 fd1d8d92 Luca Abeni
  struct tag *cfg_tags;
21 8b70c289 Luca Abeni
  struct output_stream *res;
22
23
  res = malloc(sizeof(struct output_stream));
24
  if (res == NULL) {
25
    return NULL;
26
  }
27 fd1d8d92 Luca Abeni
28 89aef955 Luca Abeni
#ifdef AVF
29 8b70c289 Luca Abeni
  res->out = &out_avf;
30 89aef955 Luca Abeni
#else
31 8b70c289 Luca Abeni
  res->out = &out_raw;
32 89aef955 Luca Abeni
#endif
33 fd1d8d92 Luca Abeni
  cfg_tags = config_parse(config);
34
  if (cfg_tags) {
35
    const char *type;
36
37
    type = config_value_str(cfg_tags, "dechunkiser");
38
    if (type && !strcmp(type, "raw")) {
39 8b70c289 Luca Abeni
      res->out = &out_raw;
40 fd1d8d92 Luca Abeni
    }
41
  }
42 dcc42706 Luca Abeni
  free(cfg_tags);
43 c0c735aa Luca Abeni
44 8b70c289 Luca Abeni
  res->c = res->out->open(fname, config);
45
  if (res->c == NULL) {
46
    free(res);
47
48
    return NULL;
49
  }
50
51
  return res;
52 c0c735aa Luca Abeni
}
53
54 386bce8c Luca Abeni
void out_stream_close(struct output_stream *s)
55
{
56 8b70c289 Luca Abeni
  s->out->close(s->c);
57
  free(s);
58 386bce8c Luca Abeni
}
59
60 0c461e28 Luca Abeni
void chunk_write(struct output_stream *o, const struct chunk *c)
61 c0c735aa Luca Abeni
{
62 8b70c289 Luca Abeni
  o->out->write(o->c, c->id, c->data, c->size);
63 c0c735aa Luca Abeni
}