audio_pipe.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #ifndef __AUDIO_PIPE_H__
  10. #define __AUDIO_PIPE_H__
  11. /**
  12. * Pipe Device
  13. */
  14. #include <rtthread.h>
  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. /* portal device */
  22. struct rt_audio_portal_device
  23. {
  24. struct rt_device parent;
  25. struct rt_device *write_dev;
  26. struct rt_device *read_dev;
  27. };
  28. enum rt_audio_pipe_flag
  29. {
  30. /* both read and write won't block */
  31. RT_PIPE_FLAG_NONBLOCK_RDWR = 0x00,
  32. /* read would block */
  33. RT_PIPE_FLAG_BLOCK_RD = 0x01,
  34. /* write would block */
  35. RT_PIPE_FLAG_BLOCK_WR = 0x02,
  36. /* write to this pipe will discard some data when the pipe is full.
  37. * When this flag is set, RT_PIPE_FLAG_BLOCK_WR will be ignored since write
  38. * operation will always be success. */
  39. RT_PIPE_FLAG_FORCE_WR = 0x04,
  40. };
  41. struct rt_audio_pipe
  42. {
  43. struct rt_device parent;
  44. /* ring buffer in pipe device */
  45. struct rt_ringbuffer ringbuffer;
  46. rt_int32_t flag;
  47. /* suspended list */
  48. rt_list_t suspended_read_list;
  49. rt_list_t suspended_write_list;
  50. struct rt_audio_portal_device *write_portal;
  51. struct rt_audio_portal_device *read_portal;
  52. };
  53. #define PIPE_CTRL_GET_SPACE 0x14 /**< get the remaining size of a pipe device */
  54. rt_err_t rt_audio_pipe_init(struct rt_audio_pipe *pipe,
  55. const char *name,
  56. rt_int32_t flag,
  57. rt_uint8_t *buf,
  58. rt_size_t size);
  59. rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe);
  60. #ifdef RT_USING_HEAP
  61. rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size);
  62. void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe);
  63. #endif
  64. #endif