audio_pipe.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef __AUDIO_PIPE_H__
  2. #define __AUDIO_PIPE_H__
  3. /**
  4. * Pipe Device
  5. */
  6. #include <rtthread.h>
  7. #include <rtdevice.h>
  8. #ifndef RT_PIPE_BUFSZ
  9. #define PIPE_BUFSZ 512
  10. #else
  11. #define PIPE_BUFSZ RT_PIPE_BUFSZ
  12. #endif
  13. /* portal device */
  14. struct rt_audio_portal_device
  15. {
  16. struct rt_device parent;
  17. struct rt_device *write_dev;
  18. struct rt_device *read_dev;
  19. };
  20. enum rt_audio_pipe_flag
  21. {
  22. /* both read and write won't block */
  23. RT_PIPE_FLAG_NONBLOCK_RDWR = 0x00,
  24. /* read would block */
  25. RT_PIPE_FLAG_BLOCK_RD = 0x01,
  26. /* write would block */
  27. RT_PIPE_FLAG_BLOCK_WR = 0x02,
  28. /* write to this pipe will discard some data when the pipe is full.
  29. * When this flag is set, RT_PIPE_FLAG_BLOCK_WR will be ignored since write
  30. * operation will always be success. */
  31. RT_PIPE_FLAG_FORCE_WR = 0x04,
  32. };
  33. struct rt_audio_pipe
  34. {
  35. struct rt_device parent;
  36. /* ring buffer in pipe device */
  37. struct rt_ringbuffer ringbuffer;
  38. enum rt_audio_pipe_flag flag;
  39. /* suspended list */
  40. rt_list_t suspended_read_list;
  41. rt_list_t suspended_write_list;
  42. struct rt_audio_portal_device *write_portal;
  43. struct rt_audio_portal_device *read_portal;
  44. };
  45. #define PIPE_CTRL_GET_SPACE 0x14 /**< get the remaining size of a pipe device */
  46. rt_err_t rt_audio_pipe_init(struct rt_audio_pipe *pipe,
  47. const char *name,
  48. enum rt_audio_pipe_flag flag,
  49. rt_uint8_t *buf,
  50. rt_size_t size);
  51. rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe);
  52. #ifdef RT_USING_HEAP
  53. rt_err_t rt_audio_pipe_create(const char *name, enum rt_audio_pipe_flag flag, rt_size_t size);
  54. void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe);
  55. #endif
  56. #endif