-
Notifications
You must be signed in to change notification settings - Fork 2
/
mixbuffer.h
76 lines (59 loc) · 2.17 KB
/
mixbuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright (C) 2010 bg <[email protected]>
*/
#ifndef CHAN_DONGLE_MIXBUFFER_H_INCLUDED
#define CHAN_DONGLE_MIXBUFFER_H_INCLUDED
#include "ast_config.h"
#include <asterisk/linkedlists.h> /* AST_LIST_ENTRY() AST_LIST_HEAD_NOLOCK() */
#include "ringbuffer.h"
struct mixstream {
AST_LIST_ENTRY(mixstream) entry;
size_t used; /*!< number of bytes used */
size_t write; /*!< write position */
};
struct mixbuffer {
AST_LIST_HEAD_NOLOCK(,mixstream) streams; /*!< list of stream descriptions */
struct ringbuffer rb; /*!< base */
unsigned attached; /*!< number of attached streams */
};
/* initialize mixbuffer */
INLINE_DECL void mixb_init(struct mixbuffer * mb, void * buf, size_t len)
{
AST_LIST_HEAD_INIT_NOLOCK(&mb->streams);
rb_init(&mb->rb, buf, len);
mb->attached = 0;
}
/* attach stream to mix buffer */
EXPORT_DECL void mixb_attach(struct mixbuffer * mb, struct mixstream * stream);
/* detach stream from mix buffer */
EXPORT_DECL void mixb_detach(struct mixbuffer * mb, struct mixstream * stream);
/* get amount of free bytes in buffer for specified stream */
INLINE_DECL size_t mixb_free (const struct mixbuffer * mb, const struct mixstream * stream)
{
return mb->rb.size - stream->used;
}
/* get bytes used i.e. now may bytes can read */
INLINE_DECL size_t mixb_used(const struct mixbuffer * mb)
{
return rb_used(&mb->rb);
}
/* advice read position */
EXPORT_DECL size_t mixb_read_upd(struct mixbuffer * mb, size_t len);
/* add data to mix buffer for specified stream */
EXPORT_DECL size_t mixb_write(struct mixbuffer * mb, struct mixstream * stream, const char * data, size_t len);
/* get data pointer and sizes in iov for all available for reading data in buffer */
INLINE_DECL int mixb_read_all_iov (const struct mixbuffer * mb, struct iovec iov[2])
{
return rb_read_all_iov(&mb->rb, iov);
}
/* get data pointer and sizes in iov only for first len bytes */
INLINE_DECL int mixb_read_n_iov (const struct mixbuffer * mb, struct iovec iov[2], size_t len)
{
return rb_read_n_iov(&mb->rb, iov, len);
}
/* get number of attached streams */
INLINE_DECL int mixb_streams (const struct mixbuffer * mb)
{
return mb->attached;
}
#endif /* CHAN_DONGLE_MIXBUFFER_H_INCLUDED */