Statistics
| Branch: | Revision:

grapes / src / Chunkiser / output-stream.c @ 176b8de8

History | View | Annotate | Download (1.74 KB)

1
#include <stdint.h>
2
#include <stdlib.h>
3
#include <string.h>
4

    
5
#include "chunk.h"
6
#include "grapes_config.h"
7
#include "chunkiser.h"
8
#include "dechunkiser_iface.h"
9

    
10
extern struct dechunkiser_iface out_play;
11
extern struct dechunkiser_iface out_avf;
12
extern struct dechunkiser_iface out_raw;
13
extern struct dechunkiser_iface out_udp;
14
extern struct dechunkiser_iface out_dummy;
15

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

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

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

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

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

    
54
      return NULL;
55
#endif
56
    } else if (type && !strcmp(type, "play")) {
57
#ifdef GTK
58
      res->out = &out_play;
59
#else
60
      free(res);
61
      free(cfg_tags);
62

    
63
      return NULL;
64
#endif
65
    }
66
  }
67
  free(cfg_tags);
68

    
69
  res->c = res->out->open(fname, config);
70
  if (res->c == NULL) {
71
    free(res);
72

    
73
    return NULL;
74
  }
75

    
76
  return res;
77
}
78

    
79
void out_stream_close(struct output_stream *s)
80
{
81
  s->out->close(s->c);
82
  free(s);
83
}
84

    
85
void chunk_write(struct output_stream *o, const struct chunk *c)
86
{
87
  o->out->write(o->c, c->id, c->data, c->size);
88
}