audio_writer.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _AUDIO_WRITER_H_
  13. #define _AUDIO_WRITER_H_
  14. #include "osi_api.h"
  15. #include "osi_byte_buf.h"
  16. OSI_EXTERN_C_BEGIN
  17. /**
  18. * \brief forward declaration
  19. */
  20. struct auWriter;
  21. /**
  22. * \brief forward declaration
  23. */
  24. struct osiPipe;
  25. /**
  26. * \brief audio writer operations
  27. */
  28. typedef struct
  29. {
  30. /** delete the audio writer */
  31. void (*destroy)(struct auWriter *d);
  32. /** refer to \p auWriterWrite */
  33. int (*write)(struct auWriter *d, const void *buf, unsigned size);
  34. /** refer to \p auWriterSeek */
  35. int (*seek)(struct auWriter *d, int offset, int whence);
  36. } auWriterOps_t;
  37. /**
  38. * \brief audio writer base
  39. *
  40. * Audio writer is an abstraction of file. The basic operation is to write
  41. * to the writer. And the writer doesn't care about the content.
  42. *
  43. * When implement an audio writer, the first field should be
  44. * <tt>const auWriterOps_t *</tt>.
  45. */
  46. typedef struct auWriter
  47. {
  48. auWriterOps_t ops; ///< audio writer operations
  49. } auWriter_t;
  50. /**
  51. * \brief delete the audio writer
  52. *
  53. * When \p d is NULL, nothing will be done.
  54. *
  55. * \param d audio writer
  56. */
  57. void auWriterDelete(auWriter_t *d);
  58. /**
  59. * \brief write data to audio writer
  60. *
  61. * \param d audio writer
  62. * \param buf buf to be written, can't be NULL if \p size is not 0.
  63. * \param size buf size
  64. * \return
  65. * - the size written to audio writer, which may be less than \p size.
  66. * - -1 for invalid parameters, or write error
  67. */
  68. int auWriterWrite(auWriter_t *d, const void *buf, unsigned size);
  69. /**
  70. * \brief whether the audio writer support seek
  71. *
  72. * When \p seek function pointer is NULL, it is not seekable.
  73. *
  74. * \param d audio writer
  75. * \return
  76. * - true if the audio writer supports seek
  77. * - false if the audio writer doesn't support seek
  78. */
  79. bool auWriterIsSeekable(auWriter_t *d);
  80. /**
  81. * \brief audio writer seek
  82. *
  83. * Macros for \p whence are defined in <tt>stdio.h</tt>.
  84. *
  85. * \param d audio writer
  86. * \param offset offset according to the directive whence
  87. * \param whence SEEK_SET, SEEK_CUR, SEEK_END
  88. * \return
  89. * - offset location from the beginning of writer on success.
  90. * - -1 on error.
  91. */
  92. int auWriterSeek(auWriter_t *d, int offset, int whence);
  93. /**
  94. * \brief opaque data strcture of file based audio writer
  95. */
  96. typedef struct auFileWriter auFileWriter_t;
  97. /**
  98. * \brief create a file based audio writer
  99. *
  100. * When \p fname doesn't exist, it will be created. When \p fname exists,
  101. * the file will be truncated to zero length.
  102. *
  103. * \param fname file name
  104. * \return
  105. * - the created audio writer
  106. * - NULL if invalid parameter, or out of memory
  107. */
  108. auFileWriter_t *auFileWriterCreate(const char *fname);
  109. /**
  110. * \brief opaque data structure of memory based audio writer
  111. */
  112. typedef struct auMemWriter auMemWriter_t;
  113. /**
  114. * \brief create a memory based audio writer
  115. *
  116. * The memory is dynamic allocated at initialization.
  117. *
  118. * \param max_size maximum memory size, 0 for no limitation
  119. * \return
  120. * - the created audio writer
  121. * - NULL if out of memory
  122. */
  123. auMemWriter_t *auMemWriterCreate(unsigned max_size);
  124. /**
  125. * \brief get buffer of memory based audio writer
  126. *
  127. * The buffer pointer may be changed, except the special case mentioned above,
  128. * \p init_size is the same as \p max_size.
  129. *
  130. * \param d memory based audio writer
  131. * \return
  132. * - buffer pointer and size.
  133. */
  134. osiBuffer_t auMemWriterGetBuf(auMemWriter_t *d);
  135. /**
  136. * \brief opaque data structure for pip based audio writer
  137. */
  138. typedef struct auPipeWriter auPipeWriter_t;
  139. /**
  140. * \brief create a pipe based audio writer
  141. *
  142. * Pipe base audio writer will decouple audio data producing and consuming.
  143. * Seek is unsupported in pipe based audio writer. Audio writer will just
  144. * access the writer side of pipe.
  145. *
  146. * \param pipe the pipe to be write
  147. * \return
  148. * - the created audio writer
  149. * - NULL if out of memory, or invalid parameter
  150. */
  151. auPipeWriter_t *auPipeWriterCreate(struct osiPipe *pipe);
  152. /**
  153. * \brief set wait timeout for audio pipe writer
  154. *
  155. * By default, audio pipe write won't wait and will return immediately even
  156. * the pipe is full, or not enough for the requested byte count. This can
  157. * set the wait timeout, 0 for not waiting and \p OSI_WAIT_FOREVER for
  158. * infinite wait until the requested data are written.
  159. *
  160. * \param d the audio pipe writer
  161. * \param timeout wait timeout
  162. */
  163. void auPipeWriterSetWait(auWriter_t *d, unsigned timeout);
  164. /**
  165. * \brief opaque data structure of dummy audio writer
  166. *
  167. * Dummy writer will drop all incoming data, just provides writer APIs.
  168. * Typically, it will only be used for debug purpose.
  169. */
  170. typedef struct auDummyWriter auDummyWriter_t;
  171. /**
  172. * \brief create a dummy audio writer
  173. *
  174. * \return
  175. * - the created audio writer
  176. * - NULL if out of memory
  177. */
  178. auDummyWriter_t *auDummyWriterCreate(void);
  179. OSI_EXTERN_C_END
  180. #endif