dev_audio_pipe.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * Pipe Device
  14. */
  15. #include <rtdevice.h>
  16. #ifndef RT_PIPE_BUFSZ
  17. #define PIPE_BUFSZ 512
  18. #else
  19. #define PIPE_BUFSZ RT_PIPE_BUFSZ
  20. #endif
  21. /**
  22. * @brief Portal device
  23. */
  24. struct rt_audio_portal_device
  25. {
  26. struct rt_device parent;
  27. struct rt_device *write_dev;
  28. struct rt_device *read_dev;
  29. };
  30. /**
  31. * @brief Aduio pipe flags
  32. */
  33. enum rt_audio_pipe_flag
  34. {
  35. RT_PIPE_FLAG_NONBLOCK_RDWR = 0x00, /**< both read and write won't block */
  36. RT_PIPE_FLAG_BLOCK_RD = 0x01, /**< read would block */
  37. RT_PIPE_FLAG_BLOCK_WR = 0x02, /**< write would block */
  38. RT_PIPE_FLAG_FORCE_WR = 0x04, /**< write to this pipe will discard some data when the pipe is full.
  39. * When this flag is set, RT_PIPE_FLAG_BLOCK_WR will be ignored since write
  40. * operation will always be success. */
  41. };
  42. /**
  43. * @brief Audio buffer info
  44. *
  45. * The preferred number and size of audio pipeline buffer for the audio device, it
  46. * will be used in rt_audio_replay struct.
  47. *
  48. */
  49. struct rt_audio_pipe
  50. {
  51. struct rt_device parent;
  52. struct rt_ringbuffer ringbuffer; /**< ring buffer in pipe device */
  53. rt_int32_t flag;
  54. rt_list_t suspended_read_list; /**< suspended thread list for reading */
  55. rt_list_t suspended_write_list; /**< suspended thread list for writing */
  56. struct rt_audio_portal_device *write_portal;
  57. struct rt_audio_portal_device *read_portal;
  58. };
  59. #define PIPE_CTRL_GET_SPACE 0x14 /**< get the remaining size of a pipe device */
  60. rt_err_t rt_audio_pipe_init(struct rt_audio_pipe *pipe,
  61. const char *name,
  62. rt_int32_t flag,
  63. rt_uint8_t *buf,
  64. rt_size_t size);
  65. rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe);
  66. #ifdef RT_USING_HEAP
  67. rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size);
  68. void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe);
  69. #endif /* RT_USING_HEAP */
  70. #endif /* __DEV_AUDIO_PIPE_H__ */