1 /* 2 * Copyright (c) 2006-2025 RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2025-03-04 wumingzi add doxygen comments. 9 */ 10 #ifndef __DEV_AUDIO_PIPE_H__ 11 #define __DEV_AUDIO_PIPE_H__ 12 13 /** 14 * Pipe Device 15 */ 16 #include <rtdevice.h> 17 18 #ifndef RT_PIPE_BUFSZ 19 #define PIPE_BUFSZ 512 20 #else 21 #define PIPE_BUFSZ RT_PIPE_BUFSZ 22 #endif 23 24 /** 25 * @brief Portal device 26 */ 27 struct rt_audio_portal_device 28 { 29 struct rt_device parent; 30 struct rt_device *write_dev; 31 struct rt_device *read_dev; 32 }; 33 34 /** 35 * @brief Aduio pipe flags 36 */ 37 enum rt_audio_pipe_flag 38 { 39 40 RT_PIPE_FLAG_NONBLOCK_RDWR = 0x00, /**< both read and write won't block */ 41 RT_PIPE_FLAG_BLOCK_RD = 0x01, /**< read would block */ 42 RT_PIPE_FLAG_BLOCK_WR = 0x02, /**< write would block */ 43 RT_PIPE_FLAG_FORCE_WR = 0x04, /**< write to this pipe will discard some data when the pipe is full. 44 * When this flag is set, RT_PIPE_FLAG_BLOCK_WR will be ignored since write 45 * operation will always be success. */ 46 }; 47 48 /** 49 * @brief Audio buffer info 50 * 51 * The preferred number and size of audio pipeline buffer for the audio device, it 52 * will be used in rt_audio_replay struct. 53 * 54 */ 55 struct rt_audio_pipe 56 { 57 struct rt_device parent; 58 59 struct rt_ringbuffer ringbuffer; /**< ring buffer in pipe device */ 60 61 rt_int32_t flag; 62 63 rt_list_t suspended_read_list; /**< suspended thread list for reading */ 64 rt_list_t suspended_write_list; /**< suspended thread list for writing */ 65 66 struct rt_audio_portal_device *write_portal; 67 struct rt_audio_portal_device *read_portal; 68 }; 69 70 #define PIPE_CTRL_GET_SPACE 0x14 /**< get the remaining size of a pipe device */ 71 72 rt_err_t rt_audio_pipe_init(struct rt_audio_pipe *pipe, 73 const char *name, 74 rt_int32_t flag, 75 rt_uint8_t *buf, 76 rt_size_t size); 77 rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe); 78 #ifdef RT_USING_HEAP 79 rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size); 80 void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe); 81 #endif /* RT_USING_HEAP */ 82 83 #endif /* __DEV_AUDIO_PIPE_H__ */