1
0

audio_pipe.h 1.9 KB

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