UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ring_buffer.h
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2011-2019 CESNET, z. s. p. o.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, is permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * 3. Neither the name of CESNET nor the names of its contributors may be
22 * used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
27 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
29 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Provides abstraction for ring buffers.
41 * Note that it doesn't offer advanced synchronization primitives and
42 * therefore is mainly intended for one producer and one consumer.
43 */
44#ifndef __RING_BUFFER_H
45#define __RING_BUFFER_H
46
47#include "audio_buffer.h" // audio_buffer_api
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
57struct ring_buffer;
59
60struct ring_buffer *ring_buffer_init(int size);
61void ring_buffer_destroy(struct ring_buffer * ring);
62/*
63 * @param ring ring buffer structure
64 * @param out allocated buffer to read to
65 * @param max_len maximal amount of data
66 * @return actual data length read (ranges between 0 and max_len)
67 */
68int ring_buffer_read(struct ring_buffer * ring, char *out, int max_len);
69void ring_buffer_write(struct ring_buffer * ring, const char *in, int len);
70int ring_get_size(struct ring_buffer * ring);
76void ring_buffer_flush(struct ring_buffer *ring);
80int ring_get_current_size(struct ring_buffer * ring);
81
86
87
99int ring_get_read_regions(struct ring_buffer *ring, int max_len,
100 void **ptr1, int *size1,
101 void **ptr2, int *size2);
102
109void ring_advance_read_idx(struct ring_buffer *ring, int amount);
110
127int ring_get_write_regions(struct ring_buffer *ring, int requested_len,
128 void **ptr1, int *size1,
129 void **ptr2, int *size2);
130
138bool ring_advance_write_idx(struct ring_buffer *ring, int amount);
139
140void ring_fill(struct ring_buffer *ring, int c, int size);
141
143
144#ifdef __cplusplus
145}
146
147#include <memory>
148
150using ring_buffer_uniq = std::unique_ptr<ring_buffer, ring_buf_deleter>;
151
152#endif //__cplusplus
153
154#endif /* __RING_BUFFER_H */
int void size_t * len
std::unique_ptr< ring_buffer, ring_buf_deleter > ring_buffer_uniq
int ring_get_size(struct ring_buffer *ring)
int ring_get_current_size(struct ring_buffer *ring)
void ring_buffer_destroy(struct ring_buffer *ring)
struct audio_buffer_api ring_buffer_fns
struct ring_buffer * ring_buffer_init(int size)
bool ring_advance_write_idx(struct ring_buffer *ring, int amount)
int ring_get_write_regions(struct ring_buffer *ring, int requested_len, void **ptr1, int *size1, void **ptr2, int *size2)
void ring_advance_read_idx(struct ring_buffer *ring, int amount)
void ring_buffer_flush(struct ring_buffer *ring)
int ring_get_read_regions(struct ring_buffer *ring, int max_len, void **ptr1, int *size1, void **ptr2, int *size2)
int ring_buffer_read(struct ring_buffer *ring, char *out, int max_len)
void ring_buffer_write(struct ring_buffer *ring, const char *in, int len)
int ring_get_available_write_size(struct ring_buffer *ring)
void ring_fill(struct ring_buffer *ring, int c, int size)
void operator()(ring_buffer_t *ring)