Statistics
| Branch: | Revision:

grapes / src / Chunkiser / output-stream.c @ f57424db

History | View | Annotate | Download (1.53 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
extern struct dechunkiser_iface out_dummy;
14

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

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

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

    
30
#ifdef AVF
31
  res->out = &out_avf;
32
#else
33
  res->out = &out_raw;
34
#endif
35
  cfg_tags = config_parse(config);
36
  if (cfg_tags) {
37
    const char *type;
38

    
39
    type = config_value_str(cfg_tags, "dechunkiser");
40
    if (type && !strcmp(type, "raw")) {
41
      res->out = &out_raw;
42
    } else if (type && !strcmp(type, "udp")) {
43
      res->out = &out_udp;
44
    } else if (type && !strcmp(type, "dummy")) {
45
      res->out = &out_dummy;
46
    } else if (type && !strcmp(type, "avf")) {
47
#ifdef AVF
48
      res->out = &out_avf;
49
#else
50
      free(res);
51
      free(cfg_tags);
52

    
53
      return NULL;
54
#endif
55
    }
56
  }
57
  free(cfg_tags);
58

    
59
  res->c = res->out->open(fname, config);
60
  if (res->c == NULL) {
61
    free(res);
62

    
63
    return NULL;
64
  }
65

    
66
  return res;
67
}
68

    
69
void out_stream_close(struct output_stream *s)
70
{
71
  s->out->close(s->c);
72
  free(s);
73
}
74

    
75
void chunk_write(struct output_stream *o, const struct chunk *c)
76
{
77
  o->out->write(o->c, c->id, c->data, c->size);
78
}