Revision fcc01ba5

View differences:

src/Chunkiser/chunkiser_iface.h
1
struct chunkiser_ctx;
2

  
1 3
struct chunkiser_iface {
2
  struct input_stream *(*open)(const char *fname, int *period, const char *config);
3
  void (*close)(struct input_stream *s);
4
  uint8_t *(*chunkise)(struct input_stream *s, int id, int *size, uint64_t *ts);
4
  struct chunkiser_ctx *(*open)(const char *fname, int *period, const char *config);
5
  void (*close)(struct chunkiser_ctx *s);
6
  uint8_t *(*chunkise)(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts);
5 7
};
src/Chunkiser/input-stream-avf.c
13 13
#include "chunkiser_iface.h"
14 14

  
15 15
#define STATIC_BUFF_SIZE 1000 * 1024
16
struct input_stream {
16
struct chunkiser_ctx {
17 17
  AVFormatContext *s;
18 18
  int loop;	//loop on input file infinitely
19 19
  int audio_stream;
......
106 106
  frame_header_write(data, size, pts, dts);
107 107
}
108 108

  
109
static int input_stream_rewind(struct input_stream *s)
109
static int input_stream_rewind(struct chunkiser_ctx *s)
110 110
{
111 111
    int ret;
112 112

  
......
119 119

  
120 120
/* Interface functions */
121 121

  
122
static struct input_stream *avf_open(const char *fname, int *period, const char *config)
122
static struct chunkiser_ctx *avf_open(const char *fname, int *period, const char *config)
123 123
{
124
  struct input_stream *desc;
124
  struct chunkiser_ctx *desc;
125 125
  int i, res;
126 126
  struct tag *cfg_tags;
127 127

  
128 128
  avcodec_register_all();
129 129
  av_register_all();
130 130

  
131
  desc = malloc(sizeof(struct input_stream));
131
  desc = malloc(sizeof(struct chunkiser_ctx));
132 132
  if (desc == NULL) {
133 133
    return NULL;
134 134
  }
......
182 182
  return desc;
183 183
}
184 184

  
185
static void avf_close(struct input_stream *s)
185
static void avf_close(struct chunkiser_ctx *s)
186 186
{
187 187
  int i;
188 188

  
......
195 195
  free(s);
196 196
}
197 197

  
198
static uint8_t *avf_chunkise(struct input_stream *s, int id, int *size, uint64_t *ts)
198
static uint8_t *avf_chunkise(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts)
199 199
{
200 200
    AVPacket pkt;
201 201
    int res;
src/Chunkiser/input-stream-dummy.c
11 11

  
12 12
#include "chunkiser_iface.h"
13 13

  
14
struct input_stream {
14
struct chunkiser_ctx {
15 15
  char buff[80];
16 16
};
17 17

  
18
static struct input_stream *open(const char *fname, int *period, const char *config)
18
static struct chunkiser_ctx *open(const char *fname, int *period, const char *config)
19 19
{
20 20
  fprintf(stderr, "WARNING: This is a dummy chunkiser, only good for debugging! Do not expect anything good from it!\n");
21 21
  *period = 40000;
22
  return malloc(sizeof(struct input_stream));
22
  return malloc(sizeof(struct chunkiser_ctx));
23 23
}
24 24

  
25
static void close(struct input_stream *s)
25
static void close(struct chunkiser_ctx *s)
26 26
{
27 27
  free(s);
28 28
}
29 29

  
30
static uint8_t *chunkise(struct input_stream *s, int id, int *size, uint64_t *ts)
30
static uint8_t *chunkise(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts)
31 31
{
32 32
  sprintf(s->buff, "Chunk %d", id);
33 33
  *ts = 40 * id * 1000;
src/Chunkiser/input-stream.c
10 10
extern struct chunkiser_iface in_avf;
11 11
extern struct chunkiser_iface in_dummy;
12 12

  
13
static struct chunkiser_iface *in;
13
struct input_stream {
14
  struct chunkiser_ctx *c;
15
  struct chunkiser_iface *in;
16
};
14 17

  
15 18
struct input_stream *input_stream_open(const char *fname, int *period, const char *config)
16 19
{
17 20
  struct tag *cfg_tags;
21
  struct input_stream *res;
22

  
23
  res = malloc(sizeof(struct input_stream));
24
  if (res == NULL) {
25
    return res;
26
  }
18 27

  
19 28
#ifdef AVF
20
  in = &in_avf;
29
  res->in = &in_avf;
21 30
#else
22
  in = &in_dummy;
31
  res->in = &in_dummy;
23 32
#endif
24 33
  cfg_tags = config_parse(config);
25

  
26 34
  if (cfg_tags) {
27 35
    const char *type;
28 36

  
29 37
    type = config_value_str(cfg_tags, "chunkiser");
30 38
    if (type && !strcmp(type, "dummy")) {
31
      in = &in_dummy;
39
      res->in = &in_dummy;
32 40
    }
33 41
  }
34 42
  free(cfg_tags);
35 43

  
36
  return in->open(fname, period, config);
44
  res->c = res->in->open(fname, period, config);
45
  if (res->c == NULL) {
46
    free(res);
47

  
48
    return NULL;
49
  }
50

  
51
  return res;
37 52
}
38 53

  
39 54
void input_stream_close(struct input_stream *s)
40 55
{
41
  return in->close(s);
56
  s->in->close(s->c);
57
  free(s);
42 58
}
43 59

  
44 60
int chunkise(struct input_stream *s, struct chunk *c)
45 61
{
46
  c->data = in->chunkise(s, c->id, &c->size, &c->timestamp);
62
  c->data = s->in->chunkise(s->c, c->id, &c->size, &c->timestamp);
47 63
  if (c->data == NULL) {
48 64
    if (c->size < 0) {
49 65
      return -1;

Also available in: Unified diff