Revision 4cdd16a7

View differences:

include/chunkiser.h
34 34
struct input_stream *input_stream_open(const char *fname, int *period, const char *config);
35 35

  
36 36
/**
37
 * @brief Return the FDs used for input.
38
 *
39
 * Return a "-1 terminated" array of integers containing the FDs used for
40
 * reading an input stream. Such an array can be directly passed to wait4data()
41
 * as user_fds
42
 *
43
 * @param input_stream the pointer to the chunkiser context
44
 * @return the array with the input FDs on success, NULL on error or if
45
 *         such FDs are not available
46
 */
47
const int *input_get_fds(const struct input_stream *s);
48

  
49
/**
37 50
 * @brief Cleanup a chunkiser.
38 51
 * 
39 52
 * Close an A/V stream, and cleanup all the data structures related to the
src/Chunkiser/chunkiser_iface.h
4 4
  struct chunkiser_ctx *(*open)(const char *fname, int *period, const char *config);
5 5
  void (*close)(struct chunkiser_ctx *s);
6 6
  uint8_t *(*chunkise)(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts);
7
  const int *(*get_fds)(const struct chunkiser_ctx *s);
7 8
};
src/Chunkiser/input-stream-dumb.c
16 16
#include "config.h"
17 17

  
18 18
struct chunkiser_ctx {
19
  int fd;
20 19
  int chunk_size;
20
  int fds[2];
21 21
};
22 22
#define DEFAULT_CHUNK_SIZE 2 * 1024
23 23

  
......
31 31
    return NULL;
32 32
  }
33 33

  
34
  res->fd = open(fname, O_RDONLY);
35
  if (res->fd < 0) {
34
  res->fds[0] = open(fname, O_RDONLY);
35
  if (res->fds[0] < 0) {
36 36
    free(res);
37 37

  
38 38
    return NULL;
39 39
  }
40
  res->fds[1] = -1;
40 41

  
41 42
  *period = 0;
42 43
  res->chunk_size = DEFAULT_CHUNK_SIZE;
......
47 48
    config_value_int(cfg_tags, "chunk_size", &res->chunk_size);
48 49
    access_mode = config_value_str(cfg_tags, "mode");
49 50
    if (!strcmp(access_mode, "nonblock")) {
50
      fcntl(res->fd, F_SETFL, O_NONBLOCK);
51
      fcntl(res->fds[0], F_SETFL, O_NONBLOCK);
51 52
    }
52 53
  }
53 54
  free(cfg_tags);
......
57 58

  
58 59
static void dumb_close(struct chunkiser_ctx *s)
59 60
{
60
  close(s->fd);
61
  close(s->fds[0]);
61 62
  free(s);
62 63
}
63 64

  
......
72 73
    return NULL;
73 74
  }
74 75
  *ts = 0;
75
  *size = read(s->fd, res, s->chunk_size);
76
  *size = read(s->fds[0], res, s->chunk_size);
76 77

  
77 78
  return res;
78 79
}
79 80

  
81
const int *dumb_get_fds(const struct chunkiser_ctx *s)
82
{
83
  return s->fds;
84
}
85

  
80 86
struct chunkiser_iface in_dumb = {
81 87
  .open = dumb_open,
82 88
  .close = dumb_close,
83 89
  .chunkise = dumb_chunkise,
90
  .get_fds = dumb_get_fds,
84 91
};
85 92

  
86 93

  
src/Chunkiser/input-stream.c
74 74

  
75 75
  return 1;
76 76
}
77

  
78
const int *input_get_fds(const struct input_stream *s)
79
{
80
  if (s->in->get_fds) {
81
    return s->in->get_fds(s->c);
82
  }
83

  
84
  return NULL;
85
}
86

  

Also available in: Unified diff