splitcomb.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_SPLITCOMB_H__
  20. #define __PJMEDIA_SPLITCOMB_H__
  21. /**
  22. * @file splitcomb.h
  23. * @brief Media channel splitter/combiner port.
  24. */
  25. #include <pjmedia/port.h>
  26. /**
  27. * @addtogroup PJMEDIA_SPLITCOMB Media channel splitter/combiner
  28. * @ingroup PJMEDIA_PORT
  29. * @brief Split and combine multiple mono-channel media ports into
  30. * a single multiple-channels media port
  31. * @{
  32. *
  33. * This section describes media port to split and combine media
  34. * channels in the stream.
  35. *
  36. * A splitter/combiner splits a single stereo/multichannels audio frame into
  37. * multiple audio frames to each channel when put_frame() is called,
  38. * and combines mono frames from each channel into a stereo/multichannel
  39. * frame when get_frame() is called. A common application for the splitter/
  40. * combiner is to split frames from stereo to mono and vise versa.
  41. */
  42. PJ_BEGIN_DECL
  43. /**
  44. * Create a media splitter/combiner with the specified parameters.
  45. * When the splitter/combiner is created, it creates an instance of
  46. * pjmedia_port. This media port represents the stereo/multichannel side
  47. * of the splitter/combiner. Application needs to supply the splitter/
  48. * combiner with a media port for each audio channels.
  49. *
  50. * @param pool Pool to allocate memory to create the splitter/
  51. * combiner.
  52. * @param clock_rate Audio clock rate/sampling rate.
  53. * @param channel_count Number of channels.
  54. * @param samples_per_frame Number of samples per frame.
  55. * @param bits_per_sample Bits per sample.
  56. * @param options Optional flags.
  57. * @param p_splitcomb Pointer to receive the splitter/combiner.
  58. *
  59. * @return PJ_SUCCESS on success, or the appropriate
  60. * error code.
  61. */
  62. PJ_DECL(pj_status_t) pjmedia_splitcomb_create(pj_pool_t *pool,
  63. unsigned clock_rate,
  64. unsigned channel_count,
  65. unsigned samples_per_frame,
  66. unsigned bits_per_sample,
  67. unsigned options,
  68. pjmedia_port **p_splitcomb);
  69. /**
  70. * Supply the splitter/combiner with media port for the specified channel
  71. * number. The media port will be called at the
  72. * same phase as the splitter/combiner; which means that when application
  73. * calls get_frame() of the splitter/combiner, it will call get_frame()
  74. * for all ports that have the same phase. And similarly for put_frame().
  75. *
  76. * @param splitcomb The splitter/combiner.
  77. * @param ch_num Audio channel starting number (zero based).
  78. * @param options Must be zero at the moment.
  79. * @param port The media port.
  80. *
  81. * @return PJ_SUCCESS on success, or the appropriate error
  82. * code.
  83. */
  84. PJ_DECL(pj_status_t) pjmedia_splitcomb_set_channel(pjmedia_port *splitcomb,
  85. unsigned ch_num,
  86. unsigned options,
  87. pjmedia_port *port);
  88. /**
  89. * Create a reverse phase media port for the specified channel number.
  90. * For channels with reversed phase, when application calls put_frame() to
  91. * the splitter/combiner, the splitter/combiner will only put the frame to
  92. * a buffer. Later on, when application calls get_frame() on the channel's
  93. * media port, it will return the frame that are available in the buffer.
  94. * The same process happens when application calls put_frame() to the
  95. * channel's media port, it will only put the frame to another buffer, which
  96. * will be returned when application calls get_frame() to the splitter's
  97. * media port. So this effectively reverse the phase of the media port.
  98. *
  99. * @param pool The pool to allocate memory for the port and
  100. * buffers.
  101. * @param splitcomb The splitter/combiner.
  102. * @param ch_num Audio channel starting number (zero based).
  103. * @param options Normally is zero, but the lower 8-bit of the
  104. * options can be used to specify the number of
  105. * buffers in the circular buffer. If zero, then
  106. * default number will be used (default: 8). The second
  107. * lowest 8 bits can be used to specify the options for
  108. * the underlying delay buffer (see
  109. * #pjmedia_delay_buf_flag for the possible options).
  110. * @param p_chport The media port created with reverse phase for
  111. * the specified audio channel.
  112. *
  113. * @return PJ_SUCCESS on success, or the appropriate error
  114. * code.
  115. */
  116. PJ_DECL(pj_status_t)
  117. pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
  118. pjmedia_port *splitcomb,
  119. unsigned ch_num,
  120. unsigned options,
  121. pjmedia_port **p_chport);
  122. PJ_END_DECL
  123. /**
  124. * @}
  125. */
  126. #endif /* __PJMEDIA_SPLITCOMB_H__ */