dev_audio_pipe.h 2.2 KB

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