Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 1 | /* st_buffering.h |
| 2 | * |
| 3 | * This file contains a sound trigger buffer abstraction. This |
| 4 | * abstraction represents a single circular buffer that is shared |
| 5 | * among various threads in the sound trigger HAL. |
| 6 | * |
| 7 | * Copyright (c) 2019, The Linux Foundation. All rights reserved. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions are |
| 11 | * met: |
| 12 | * * Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * * Redistributions in binary form must reproduce the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer in the documentation and/or other materials provided |
| 17 | * with the distribution. |
| 18 | * * Neither the name of The Linux Foundation nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 32 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
| 35 | #ifndef ST_BUFFERING_H |
| 36 | #define ST_BUFFERING_H |
| 37 | |
| 38 | #include <stdint.h> |
| 39 | #include <pthread.h> |
| 40 | |
| 41 | typedef struct st_buffer { |
| 42 | pthread_mutex_t lock; |
| 43 | uint8_t *buf_start; |
| 44 | uint8_t *buf_end; |
| 45 | uint8_t *rd_ptr; |
| 46 | uint8_t *wr_ptr; |
| 47 | uint32_t size; |
| 48 | uint32_t unread_bytes; |
| 49 | }st_buffer_t; |
| 50 | |
| 51 | st_buffer_t* st_buffer_init(uint32_t size); |
| 52 | void st_buffer_deinit(st_buffer_t *buf_obj); |
| 53 | void st_buffer_reset(st_buffer_t *buf_obj); |
| 54 | uint8_t* st_buffer_get_wr_ptr(st_buffer_t *buf_obj); |
| 55 | int st_buffer_write(st_buffer_t *buf_obj, uint8_t *src, uint32_t size); |
| 56 | int st_buffer_read(st_buffer_t *buf_obj, uint8_t *dst, uint32_t size, |
| 57 | uint8_t **rd_ptr, bool flush); |
| 58 | void st_buffer_flush(st_buffer_t *buf_obj, uint32_t size); |
| 59 | |
| 60 | #endif /* ST_BUFFERING_H */ |