Statistics
| Branch: | Revision:

grapes / include / chunkbuffer.h @ cb201402

History | View | Annotate | Download (3.03 KB)

1
#ifndef CHUNKBUFFER_H
2
#define CHUNKBUFFER_H
3

    
4
/** 
5
 * @file chunkbuffer.h
6
 *
7
 * This is the chunks buffer.
8
 * 
9
 * The chunks buffer is responsible for storing the chunks received by a
10
 * peer. Each chunk is stored until the chunk buffer decides to discard it
11
 * (for example, when some kind of playout delay is expired), then it
12
 * is removed from the buffer. The buffer makes its chunks available to
13
 * the output module and to the scheduler, in form of an ordered list (chunks
14
 * are ordered by timestamp). Since every chunk has a timestamp and a
15
 * sequence number (the chunk ID), the chunk buffer's clients
16
 * (scheduler and output module) can easily check if there are gaps in the
17
 * list.
18
 */
19

    
20
/**
21
 * Structure describing a chunk buffer. This is an opaque type.
22
 */
23
typedef struct chunk_buffer ChunkBuffer;
24

    
25

    
26
/**
27
 * Allocate a chunk buffer.
28
 *
29
 * Allocate and initialise a chunk buffer structure, and return a pointer to
30
 * it.
31
 *
32
 * @param config a text string containing some configuration parameters for
33
 *        the buffer, such as the playout delay and maybe some additional
34
 *        parameters (estimated size of the buffer, etc...)
35
 * @return a pointer to the allocated chunk buffer in case of success, NULL
36
 *         otherwise
37
 */
38
struct chunk_buffer *cb_init(const char *config);
39

    
40
/**
41
 * Add a chunk to a buffer.
42
 *
43
 * Insert a chunk in the given buffer. One or more chunks can be removed
44
 * from the buffer (if necessary, and according to the internal logic of
45
 * the chunk buffer) to create space for the new one.
46
 *
47
 * @param cb a pointer to the chunk buffer
48
 * @param c a pointer to the descriptor of the chunk to be inserted in the
49
 *        buffer
50
 * @return >=0 in case of success, < 0 in case of failure
51
 */
52
int cb_add_chunk(struct chunk_buffer *cb, const struct chunk *c);
53

    
54
/** 
55
 * Get the chunks from a buffer.
56
 *
57
 * Provide an (ordered) list of the chunks which are currently stored in
58
 * the specified chunk buffer. Such list is stored in a C arrary (so,
59
 * after calling chunks_array = cb_get_chunks(cb), chunks\_array[i]
60
 * contains the i^th chunk).
61
 *
62
 * @param cb a pointer to the chunks buffer
63
 * @param n a pointer to an integer variable where number of chunks
64
 *        will be stored
65
 * @return the chunks array if there are no failures and the buffer is not
66
 *         empty, NULL if the buffer is empty or in case of error (in case
67
 *         of error, n < 0; if the buffer is empty, n = 0).
68
 */
69
struct chunk *cb_get_chunks(const struct chunk_buffer *cb, int *n);
70

    
71
/**
72
 * Clear a chunk buffer
73
 *
74
 * Remove all the chunks from the specified chunk buffer.
75
 *
76
 * @param cb a pointer to the chunk buffer
77
 * @return >= 0 in case of success, < 0 in case of error.
78
 */
79
int cb_clear(struct chunk_buffer *cb);
80

    
81
/**
82
 * Destroy a chunk buffer
83
 *
84
 * Remove all the chunks from the specified chunk buffer,
85
 * and free all the memory dynamically allocated to it.
86
 *
87
 * @param cb a pointer to the chunk buffer
88
 */
89
void cb_destroy(struct chunk_buffer *cb);
90

    
91

    
92
/*
93
 * HA Functions
94
 */
95
const struct chunk *cb_get_chunk(const struct chunk_buffer *cb, int id);
96

    
97
#endif        /* CHUNKBUFFER_H */