mem_port.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJMEDIA_MEM_PORT_H__
  20. #define __PJMEDIA_MEM_PORT_H__
  21. /**
  22. * @file mem_port.h
  23. * @brief Memory based media playback/capture port
  24. */
  25. #include <pjmedia/port.h>
  26. PJ_BEGIN_DECL
  27. /**
  28. * @defgroup PJMEDIA_MEM_PLAYER Memory/Buffer-based Playback Port
  29. * @ingroup PJMEDIA_PORT
  30. * @brief Media playback from a fixed size memory buffer
  31. * @{
  32. *
  33. * A memory/buffer based playback port is used to play media from a fixed
  34. * size buffer. This is useful over @ref PJMEDIA_FILE_PLAY for
  35. * situation where filesystems are not available in the target system.
  36. */
  37. /**
  38. * Memory player options.
  39. */
  40. enum pjmedia_mem_player_option
  41. {
  42. /**
  43. * Tell the memory player to return NULL frame when the whole
  44. * buffer has been played instead of rewinding the buffer back
  45. * to start position.
  46. */
  47. PJMEDIA_MEM_NO_LOOP = 1
  48. };
  49. /**
  50. * Create the buffer based playback to play the media from the specified
  51. * buffer.
  52. *
  53. * @param pool Pool to allocate memory for the port structure.
  54. * @param buffer The buffer to play the media from, which should
  55. * be available throughout the life time of the port.
  56. * The player plays the media directly from this
  57. * buffer (i.e. no copying is done).
  58. * @param size The size of the buffer, in bytes.
  59. * @param clock_rate Sampling rate.
  60. * @param channel_count Number of channels.
  61. * @param samples_per_frame Number of samples per frame.
  62. * @param bits_per_sample Number of bits per sample.
  63. * @param options Option flags, see #pjmedia_mem_player_option
  64. * @param p_port Pointer to receive the port instance.
  65. *
  66. * @return PJ_SUCCESS on success, or the appropriate
  67. * error code.
  68. */
  69. PJ_DECL(pj_status_t) pjmedia_mem_player_create(pj_pool_t *pool,
  70. const void *buffer,
  71. pj_size_t size,
  72. unsigned clock_rate,
  73. unsigned channel_count,
  74. unsigned samples_per_frame,
  75. unsigned bits_per_sample,
  76. unsigned options,
  77. pjmedia_port **p_port );
  78. #if !DEPRECATED_FOR_TICKET_2251
  79. /**
  80. * Register a callback to be called when the buffer reading has reached the
  81. * end of buffer. If the player is set to play repeatedly, then the callback
  82. * will be called multiple times. Note that only one callback can be
  83. * registered for each player port.
  84. *
  85. * @param port The memory player port.
  86. * @param user_data User data to be specified in the callback
  87. * @param cb Callback to be called. If the callback returns non-
  88. * PJ_SUCCESS, the playback will stop. Note that if
  89. * application destroys the player port in the callback,
  90. * it must return non-PJ_SUCCESS here.
  91. *
  92. * @return PJ_SUCCESS on success.
  93. */
  94. PJ_DECL(pj_status_t)
  95. pjmedia_mem_player_set_eof_cb( pjmedia_port *port,
  96. void *user_data,
  97. pj_status_t (*cb)(pjmedia_port *port,
  98. void *usr_data));
  99. #endif
  100. /**
  101. * Register a callback to be called when the buffer reading has reached the
  102. * end of buffer. If the player is set to play repeatedly, then the callback
  103. * will be called multiple times. Note that only one callback can be
  104. * registered for each player port.
  105. *
  106. * @param port The memory player port.
  107. * @param user_data User data to be specified in the callback
  108. * @param cb Callback to be called. Note that if
  109. * application wishes to stop the playback, it
  110. * can disconnect the port in the callback, and
  111. * only after all connections have been removed
  112. * could the application safely destroy the port.
  113. *
  114. * @return PJ_SUCCESS on success.
  115. */
  116. PJ_DECL(pj_status_t)
  117. pjmedia_mem_player_set_eof_cb2(pjmedia_port *port,
  118. void *user_data,
  119. void (*cb)(pjmedia_port *port,
  120. void *usr_data));
  121. /**
  122. * @}
  123. */
  124. /**
  125. * @defgroup PJMEDIA_MEM_CAPTURE Memory/Buffer-based Capture Port
  126. * @ingroup PJMEDIA_PORT
  127. * @brief Media capture to fixed size memory buffer
  128. * @{
  129. *
  130. * A memory based capture is used to save media streams to a fixed size
  131. * buffer. This is useful over @ref PJMEDIA_FILE_REC for
  132. * situation where filesystems are not available in the target system.
  133. */
  134. /**
  135. * Create media port to capture/record media into a fixed size buffer.
  136. *
  137. * @param pool Pool to allocate memory for the port structure.
  138. * @param buffer The buffer to record the media to, which should
  139. * be available throughout the life time of the port.
  140. * @param size The maximum size of the buffer, in bytes.
  141. * @param clock_rate Sampling rate.
  142. * @param channel_count Number of channels.
  143. * @param samples_per_frame Number of samples per frame.
  144. * @param bits_per_sample Number of bits per sample.
  145. * @param options Option flags.
  146. * @param p_port Pointer to receive the port instance.
  147. *
  148. * @return PJ_SUCCESS on success, or the appropriate
  149. * error code.
  150. */
  151. PJ_DECL(pj_status_t) pjmedia_mem_capture_create(pj_pool_t *pool,
  152. void *buffer,
  153. pj_size_t size,
  154. unsigned clock_rate,
  155. unsigned channel_count,
  156. unsigned samples_per_frame,
  157. unsigned bits_per_sample,
  158. unsigned options,
  159. pjmedia_port **p_port);
  160. #if !DEPRECATED_FOR_TICKET_2251
  161. /**
  162. * Register a callback to be called when no space left in the buffer.
  163. * Note that when a callback is registered, this callback will also be
  164. * called when application destroys the port and the callback has not
  165. * been called before.
  166. *
  167. * @param port The memory recorder port.
  168. * @param user_data User data to be specified in the callback
  169. * @param cb Callback to be called. If the callback returns non-
  170. * PJ_SUCCESS, the recording will stop. In other cases
  171. * recording will be restarted and the rest of the frame
  172. * will be stored starting from the beginning of the
  173. * buffer. Note that if application destroys the capture
  174. * port in the callback, it must return non-PJ_SUCCESS
  175. * here.
  176. *
  177. * @return PJ_SUCCESS on success.
  178. */
  179. PJ_DECL(pj_status_t)
  180. pjmedia_mem_capture_set_eof_cb(pjmedia_port *port,
  181. void *user_data,
  182. pj_status_t (*cb)(pjmedia_port *port,
  183. void *usr_data));
  184. #endif
  185. /**
  186. * Register a callback to be called when no space left in the buffer.
  187. *
  188. * @param port The memory recorder port.
  189. * @param user_data User data to be specified in the callback
  190. * @param cb Callback to be called. Note that if
  191. * application wishes to stop the recording, it
  192. * can disconnect the port in the callback, and
  193. * only after all connections have been removed
  194. * could the application safely destroy the port.
  195. *
  196. * @return PJ_SUCCESS on success.
  197. */
  198. PJ_DECL(pj_status_t)
  199. pjmedia_mem_capture_set_eof_cb2(pjmedia_port *port,
  200. void *user_data,
  201. void (*cb)(pjmedia_port *port,
  202. void *usr_data));
  203. /**
  204. * Return the current size of the recorded data in the buffer.
  205. *
  206. * @param port The memory recorder port.
  207. * @return The size of buffer data..
  208. */
  209. PJ_DECL(pj_size_t)
  210. pjmedia_mem_capture_get_size(pjmedia_port *port);
  211. /**
  212. * @}
  213. */
  214. PJ_END_DECL
  215. #endif /* __PJMEDIA_MEM_PORT_H__ */