stasis_app_recording.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. #ifndef _ASTERISK_STASIS_APP_RECORDING_H
  19. #define _ASTERISK_STASIS_APP_RECORDING_H
  20. /*! \file
  21. *
  22. * \brief Stasis Application Recording API. See \ref res_stasis "Stasis
  23. * Application API" for detailed documentation.
  24. *
  25. * \author David M. Lee, II <dlee@digium.com>
  26. * \since 12
  27. */
  28. #include "asterisk/app.h"
  29. #include "asterisk/stasis_app.h"
  30. /*! @{ */
  31. /*! \brief Structure representing a recording stored on disk */
  32. struct stasis_app_stored_recording;
  33. /*!
  34. * \brief Returns the filename for this recording, for use with streamfile.
  35. *
  36. * The returned string will be valid until the \a recording object is freed.
  37. *
  38. * \param recording Recording to query.
  39. * \return Absolute path to the recording file, without the extension.
  40. * \return \c NULL on error.
  41. */
  42. const char *stasis_app_stored_recording_get_file(
  43. struct stasis_app_stored_recording *recording);
  44. /*!
  45. * \brief Convert stored recording info to JSON.
  46. *
  47. * \param recording Recording to convert.
  48. * \return JSON representation.
  49. * \return \c NULL on error.
  50. */
  51. struct ast_json *stasis_app_stored_recording_to_json(
  52. struct stasis_app_stored_recording *recording);
  53. /*!
  54. * \brief Find all stored recordings on disk.
  55. *
  56. * \return Container of \ref stasis_app_stored_recording objects.
  57. * \return \c NULL on error.
  58. */
  59. struct ao2_container *stasis_app_stored_recording_find_all(void);
  60. /*!
  61. * \brief Creates a stored recording object, with the given name.
  62. *
  63. * \param name Name of the recording.
  64. * \return New recording object.
  65. * \return \c NULL if recording is not found. \c errno is set to indicate why
  66. * - \c ENOMEM - out of memeory
  67. * - \c EACCES - file permissions (or recording is outside the config dir)
  68. * - Any of the error codes for stat(), opendir(), readdir()
  69. */
  70. struct stasis_app_stored_recording *stasis_app_stored_recording_find_by_name(
  71. const char *name);
  72. /*!
  73. * \brief Copy a recording.
  74. *
  75. * \param src_recording The recording to copy
  76. * \param dst The destination of the recording to make
  77. * \param dst_recording If successful, the stored recording created as a result of the copy
  78. *
  79. * \retval 0 on success
  80. * \retval Non-zero on error
  81. */
  82. int stasis_app_stored_recording_copy(struct stasis_app_stored_recording *src_recording, const char *dst,
  83. struct stasis_app_stored_recording **dst_recording);
  84. /*!
  85. * \brief Delete a recording from disk.
  86. *
  87. * \param recording Recording to delete.
  88. * \return 0 on success.
  89. * \return Non-zero on error.
  90. */
  91. int stasis_app_stored_recording_delete(
  92. struct stasis_app_stored_recording *recording);
  93. /*! @} */
  94. /*! @{ */
  95. /*! Opaque struct for handling the recording of media to a file. */
  96. struct stasis_app_recording;
  97. /*! State of a recording operation */
  98. enum stasis_app_recording_state {
  99. /*! The recording has not started yet */
  100. STASIS_APP_RECORDING_STATE_QUEUED,
  101. /*! The media is currently recording */
  102. STASIS_APP_RECORDING_STATE_RECORDING,
  103. /*! The media is currently paused */
  104. STASIS_APP_RECORDING_STATE_PAUSED,
  105. /*! The media has stopped recording */
  106. STASIS_APP_RECORDING_STATE_COMPLETE,
  107. /*! The media has stopped recording, with error */
  108. STASIS_APP_RECORDING_STATE_FAILED,
  109. /*! The media has stopped recording, discard the recording file */
  110. STASIS_APP_RECORDING_STATE_CANCELED,
  111. /*! Sentinel */
  112. STASIS_APP_RECORDING_STATE_MAX,
  113. };
  114. /*! Valid operation for controlling a recording. */
  115. enum stasis_app_recording_media_operation {
  116. /*! Stop the recording, deleting the media file(s) */
  117. STASIS_APP_RECORDING_CANCEL,
  118. /*! Stop the recording. */
  119. STASIS_APP_RECORDING_STOP,
  120. /*! Pause the recording */
  121. STASIS_APP_RECORDING_PAUSE,
  122. /*! Unpause the recording */
  123. STASIS_APP_RECORDING_UNPAUSE,
  124. /*! Mute the recording (record silence) */
  125. STASIS_APP_RECORDING_MUTE,
  126. /*! Unmute the recording */
  127. STASIS_APP_RECORDING_UNMUTE,
  128. /*! Sentinel */
  129. STASIS_APP_RECORDING_OPER_MAX,
  130. };
  131. #define STASIS_APP_RECORDING_TERMINATE_INVALID 0
  132. #define STASIS_APP_RECORDING_TERMINATE_NONE -1
  133. #define STASIS_APP_RECORDING_TERMINATE_ANY -2
  134. struct stasis_app_recording_options {
  135. AST_DECLARE_STRING_FIELDS(
  136. AST_STRING_FIELD(name); /*!< name Name of the recording. */
  137. AST_STRING_FIELD(format); /*!< Format to be recorded (wav, gsm, etc.) */
  138. AST_STRING_FIELD(target); /*!< URI of what is being recorded */
  139. );
  140. /*! Number of seconds of silence before ending the recording. */
  141. int max_silence_seconds;
  142. /*! Maximum recording duration. 0 for no maximum. */
  143. int max_duration_seconds;
  144. /*! Which DTMF to use to terminate the recording
  145. * \c STASIS_APP_RECORDING_TERMINATE_NONE to terminate only on hangup
  146. * \c STASIS_APP_RECORDING_TERMINATE_ANY to terminate on any DTMF
  147. */
  148. char terminate_on;
  149. /*! How to handle recording when a file already exists */
  150. enum ast_record_if_exists if_exists;
  151. /*! If true, a beep is played at the start of recording */
  152. int beep:1;
  153. };
  154. /*!
  155. * \brief Allocate a recording options object.
  156. *
  157. * Clean up with ao2_cleanup().
  158. *
  159. * \param name Name of the recording.
  160. * \param format Format to record in.
  161. * \return Newly allocated options object.
  162. * \return \c NULL on error.
  163. */
  164. struct stasis_app_recording_options *stasis_app_recording_options_create(
  165. const char *name, const char *format);
  166. /*!
  167. * \brief Parse a string into the recording termination enum.
  168. *
  169. * \param str String to parse.
  170. * \return DTMF value to terminate on.
  171. * \return \c STASIS_APP_RECORDING_TERMINATE_NONE to not terminate on DTMF.
  172. * \return \c STASIS_APP_RECORDING_TERMINATE_ANY to terminate on any DTMF.
  173. * \return \c STASIS_APP_RECORDING_TERMINATE_INVALID if input was invalid.
  174. */
  175. char stasis_app_recording_termination_parse(const char *str);
  176. /*!
  177. * \brief Parse a string into the if_exists enum.
  178. *
  179. * \param str String to parse.
  180. * \return How to handle an existing file.
  181. * \return -1 on error.
  182. */
  183. enum ast_record_if_exists stasis_app_recording_if_exists_parse(
  184. const char *str);
  185. /*!
  186. * \brief Record media from a channel.
  187. *
  188. * A reference to the \a options object may be kept, so it MUST NOT be modified
  189. * after calling this function.
  190. *
  191. * On error, \c errno is set to indicate the failure reason.
  192. * - \c EINVAL: Invalid input.
  193. * - \c EEXIST: A recording with that name is in session.
  194. * - \c ENOMEM: Out of memory.
  195. *
  196. * \param control Control for \c res_stasis.
  197. * \param options Recording options.
  198. * \return Recording control object.
  199. * \return \c NULL on error.
  200. */
  201. struct stasis_app_recording *stasis_app_control_record(
  202. struct stasis_app_control *control,
  203. struct stasis_app_recording_options *options);
  204. /*!
  205. * \brief Gets the current state of a recording operation.
  206. *
  207. * \param recording Recording control object.
  208. * \return The state of the \a recording object.
  209. */
  210. enum stasis_app_recording_state stasis_app_recording_get_state(
  211. struct stasis_app_recording *recording);
  212. /*!
  213. * \brief Gets the unique name of a recording object.
  214. *
  215. * \param recording Recording control object.
  216. * \return \a recording's name.
  217. * \return \c NULL if \a recording ic \c NULL
  218. */
  219. const char *stasis_app_recording_get_name(
  220. struct stasis_app_recording *recording);
  221. /*!
  222. * \brief Finds the recording object with the given name.
  223. *
  224. * \param name Name of the recording object to find.
  225. * \return Associated \ref stasis_app_recording object.
  226. * \return \c NULL if \a name not found.
  227. */
  228. struct stasis_app_recording *stasis_app_recording_find_by_name(const char *name);
  229. /*!
  230. * \brief Construct a JSON model of a recording.
  231. *
  232. * \param recording Recording to conver.
  233. * \return JSON model.
  234. * \return \c NULL on error.
  235. */
  236. struct ast_json *stasis_app_recording_to_json(
  237. const struct stasis_app_recording *recording);
  238. /*!
  239. * \brief Possible results from a recording operation.
  240. */
  241. enum stasis_app_recording_oper_results {
  242. /*! Operation completed successfully. */
  243. STASIS_APP_RECORDING_OPER_OK,
  244. /*! Operation failed. */
  245. STASIS_APP_RECORDING_OPER_FAILED,
  246. /*! Operation failed b/c recording is not in session. */
  247. STASIS_APP_RECORDING_OPER_NOT_RECORDING,
  248. };
  249. /*!
  250. * \brief Controls the media for a given recording operation.
  251. *
  252. * \param recording Recording control object.
  253. * \param control Media control operation.
  254. * \return \c STASIS_APP_RECORDING_OPER_OK on success.
  255. * \return \ref stasis_app_recording_oper_results indicating failure.
  256. */
  257. enum stasis_app_recording_oper_results stasis_app_recording_operation(
  258. struct stasis_app_recording *recording,
  259. enum stasis_app_recording_media_operation operation);
  260. /*!
  261. * \brief Message type for recording updates. The data is an
  262. * \ref ast_channel_blob.
  263. */
  264. struct stasis_message_type *stasis_app_recording_snapshot_type(void);
  265. /*! @} */
  266. #endif /* _ASTERISK_STASIS_APP_RECORDING_H */