summaryrefslogtreecommitdiff
path: root/cras/src/server/buffer_share.h
blob: c61c7a07849a11a035627c0312b1b77454d85b3f (plain)
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
/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef BUFFER_SHARE_H_
#define BUFFER_SHARE_H_

#define INITIAL_ID_SIZE 3

struct id_offset {
	unsigned int used;
	unsigned int id;
	unsigned int offset;
	void *data;
};

struct buffer_share {
	unsigned int buf_sz;
	unsigned int id_sz;
	struct id_offset *wr_idx;
};

/*
 * Creates a buffer share object.  This object is used to manage the read or
 * write offsets of several users in one shared buffer.
 */
struct buffer_share *buffer_share_create(unsigned int buf_sz);

/* Destroys a buffer_share returned from buffer_share_create. */
void buffer_share_destroy(struct buffer_share *mix);

/* Adds an ID that shares the buffer. */
int buffer_share_add_id(struct buffer_share *mix, unsigned int id, void *data);

/* Removes an ID that shares the buffer. */
int buffer_share_rm_id(struct buffer_share *mix, unsigned int id);

/* Updates the offset of the given user into the shared buffer. */
int buffer_share_offset_update(struct buffer_share *mix, unsigned int id,
			       unsigned int frames);

/*
 * Updates the write point to the minimum offset from all users.
 * Returns the number of minimum number of frames written.
 */
unsigned int buffer_share_get_new_write_point(struct buffer_share *mix);

/*
 * The amount by which the user given by id is ahead of the current write
 * point.
 */
unsigned int buffer_share_id_offset(const struct buffer_share *mix,
				    unsigned int id);

/*
 * Gets the data pointer for given id.
 */
void *buffer_share_get_data(const struct buffer_share *mix, unsigned int id);

#endif /* BUFFER_SHARE_H_ */