slinfactory.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2005, Anthony Minessale II
  5. *
  6. * Anthony Minessale <anthmct@yahoo.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. /*! \file
  19. * \brief A machine to gather up arbitrary frames and convert them
  20. * to raw slinear on demand.
  21. */
  22. #ifndef _ASTERISK_SLINFACTORY_H
  23. #define _ASTERISK_SLINFACTORY_H
  24. #include "asterisk/format.h"
  25. #if defined(__cplusplus) || defined(c_plusplus)
  26. extern "C" {
  27. #endif
  28. #define AST_SLINFACTORY_MAX_HOLD 1280
  29. struct ast_slinfactory {
  30. AST_LIST_HEAD_NOLOCK(, ast_frame) queue; /*!< A list of unaltered frames */
  31. struct ast_trans_pvt *trans; /*!< Translation path that converts fed frames into signed linear */
  32. short hold[AST_SLINFACTORY_MAX_HOLD]; /*!< Hold for audio that no longer belongs to a frame (ie: if only some samples were taken from a frame) */
  33. short *offset; /*!< Offset into the hold where audio begins */
  34. size_t holdlen; /*!< Number of samples currently in the hold */
  35. unsigned int size; /*!< Number of samples currently in the factory */
  36. struct ast_format *format; /*!< Current format the translation path is converting from */
  37. struct ast_format *output_format; /*!< The output format desired */
  38. };
  39. /*!
  40. * \brief Initialize a slinfactory
  41. *
  42. * \param sf The slinfactory to initialize
  43. *
  44. * \return Nothing
  45. */
  46. void ast_slinfactory_init(struct ast_slinfactory *sf);
  47. /*!
  48. * \brief Initialize a slinfactory
  49. *
  50. * \param sf The slinfactory to initialize
  51. * \param slin_out the slinear output format desired.
  52. *
  53. * \return 0 on success, non-zero on failure
  54. */
  55. int ast_slinfactory_init_with_format(struct ast_slinfactory *sf, struct ast_format *slin_out);
  56. /*!
  57. * \brief Destroy the contents of a slinfactory
  58. *
  59. * \param sf The slinfactory that is no longer needed
  60. *
  61. * This function will free any memory allocated for the contents of the
  62. * slinfactory. It does not free the slinfactory itself. If the sf is
  63. * malloc'd, then it must be explicitly free'd after calling this function.
  64. *
  65. * \return Nothing
  66. */
  67. void ast_slinfactory_destroy(struct ast_slinfactory *sf);
  68. /*!
  69. * \brief Feed audio into a slinfactory
  70. *
  71. * \param sf The slinfactory to feed into
  72. * \param f Frame containing audio to feed in
  73. *
  74. * \return Number of frames currently in factory
  75. */
  76. int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f);
  77. /*!
  78. * \brief Read samples from a slinfactory
  79. *
  80. * \param sf The slinfactory to read from
  81. * \param buf Buffer to put samples into
  82. * \param samples Number of samples wanted
  83. *
  84. * \return Number of samples read
  85. */
  86. int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples);
  87. /*!
  88. * \brief Retrieve number of samples currently in a slinfactory
  89. *
  90. * \param sf The slinfactory to peek into
  91. *
  92. * \return Number of samples in slinfactory
  93. */
  94. unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf);
  95. /*!
  96. * \brief Flush the contents of a slinfactory
  97. *
  98. * \param sf The slinfactory to flush
  99. *
  100. * \return Nothing
  101. */
  102. void ast_slinfactory_flush(struct ast_slinfactory *sf);
  103. #if defined(__cplusplus) || defined(c_plusplus)
  104. }
  105. #endif
  106. #endif /* _ASTERISK_SLINFACTORY_H */