Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.41 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 "dechunkiser_iface.h"
9

    
10
extern struct dechunkiser_iface out_avf;
11
extern struct dechunkiser_iface out_raw;
12
extern struct dechunkiser_iface out_udp;
13

    
14
struct output_stream {
15
  struct dechunkiser_ctx *c;
16
  struct dechunkiser_iface *out;
17
};
18

    
19
struct output_stream *out_stream_init(const char *fname, const char *config)
20
{
21
  struct tag *cfg_tags;
22
  struct output_stream *res;
23

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

    
29
#ifdef AVF
30
  res->out = &out_avf;
31
#else
32
  res->out = &out_raw;
33
#endif
34
  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
      res->out = &out_raw;
41
    } else if (type && !strcmp(type, "udp")) {
42
      res->out = &out_udp;
43
    } 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
    }
53
  }
54
  free(cfg_tags);
55

    
56
  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
}
65

    
66
void out_stream_close(struct output_stream *s)
67
{
68
  s->out->close(s->c);
69
  free(s);
70
}
71

    
72
void chunk_write(struct output_stream *o, const struct chunk *c)
73
{
74
  o->out->write(o->c, c->id, c->data, c->size);
75
}