master_port.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_MASTER_PORT_H__
  20. #define __PJMEDIA_MASTER_PORT_H__
  21. /**
  22. * @file master_port.h
  23. * @brief Master port.
  24. */
  25. #include <pjmedia/port.h>
  26. /**
  27. * @defgroup PJMEDIA_MASTER_PORT Master Port
  28. * @ingroup PJMEDIA_PORT_CLOCK
  29. * @brief Thread based media clock provider
  30. * @{
  31. *
  32. * A master port has two media ports connected to it, and by convention
  33. * thay are called downstream and upstream ports. The media stream flowing to
  34. * the downstream port is called encoding or send direction, and media stream
  35. * flowing to the upstream port is called decoding or receive direction
  36. * (imagine the downstream as stream to remote endpoint, and upstream as
  37. * local media port; media flowing to remote endpoint (downstream) will need
  38. * to be encoded before it is transmitted to remote endpoint).
  39. *
  40. * A master port internally has an instance of @ref PJMEDIA_CLOCK, which
  41. * provides the essensial timing for the master port. The @ref PJMEDIA_CLOCK
  42. * runs asynchronously, and whenever a clock <b>tick</b> expires, a callback
  43. * will be called, and the master port performs the following tasks:
  44. * - it calls <b><tt>get_frame()</tt></b> from the downstream port,
  45. * when give the frame to the upstream port by calling <b><tt>put_frame
  46. * </tt></b> to the upstream port, and
  47. * - performs the same task, but on the reverse direction (i.e. get the stream
  48. * from upstream port and give it to the downstream port).
  49. *
  50. * Because master port enables media stream to flow automatically, it is
  51. * said that the master port supplies @ref PJMEDIA_PORT_CLOCK to the
  52. * media ports interconnection.
  53. *
  54. */
  55. PJ_BEGIN_DECL
  56. /**
  57. * Opaque declaration for master port.
  58. */
  59. typedef struct pjmedia_master_port pjmedia_master_port;
  60. /**
  61. * Create a master port.
  62. *
  63. * @param pool Pool to allocate master port from.
  64. * @param u_port Upstream port.
  65. * @param d_port Downstream port.
  66. * @param options Options flags, from bitmask combinations from
  67. * pjmedia_clock_options.
  68. * @param p_m Pointer to receive the master port instance.
  69. *
  70. * @return PJ_SUCCESS on success.
  71. */
  72. PJ_DECL(pj_status_t) pjmedia_master_port_create(pj_pool_t *pool,
  73. pjmedia_port *u_port,
  74. pjmedia_port *d_port,
  75. unsigned options,
  76. pjmedia_master_port **p_m);
  77. /**
  78. * Start the media flow.
  79. *
  80. * @param m The master port.
  81. *
  82. * @return PJ_SUCCESS on success.
  83. */
  84. PJ_DECL(pj_status_t) pjmedia_master_port_start(pjmedia_master_port *m);
  85. /**
  86. * Stop the media flow.
  87. *
  88. * @param m The master port.
  89. *
  90. * @return PJ_SUCCESS on success.
  91. */
  92. PJ_DECL(pj_status_t) pjmedia_master_port_stop(pjmedia_master_port *m);
  93. /**
  94. * Poll the master port clock and execute the callback when the clock tick has
  95. * elapsed. This operation is only valid if the master port is created with
  96. * #PJMEDIA_CLOCK_NO_ASYNC flag.
  97. *
  98. * @param m The master port.
  99. * @param wait If non-zero, then the function will block until
  100. * a clock tick elapsed and callback has been called.
  101. * @param ts Optional argument to receive the current
  102. * timestamp.
  103. *
  104. * @return Non-zero if clock tick has elapsed, or FALSE if
  105. * the function returns before a clock tick has
  106. * elapsed.
  107. */
  108. PJ_DECL(pj_bool_t) pjmedia_master_port_wait(pjmedia_master_port *m,
  109. pj_bool_t wait,
  110. pj_timestamp *ts);
  111. /**
  112. * Change the upstream port. Note that application is responsible to destroy
  113. * current upstream port (the one that is going to be replaced with the
  114. * new port).
  115. *
  116. * @param m The master port.
  117. * @param port Port to be used for upstream port.
  118. *
  119. * @return PJ_SUCCESS on success.
  120. */
  121. PJ_DECL(pj_status_t) pjmedia_master_port_set_uport(pjmedia_master_port *m,
  122. pjmedia_port *port);
  123. /**
  124. * Get the upstream port.
  125. *
  126. * @param m The master port.
  127. *
  128. * @return The upstream port.
  129. */
  130. PJ_DECL(pjmedia_port*) pjmedia_master_port_get_uport(pjmedia_master_port*m);
  131. /**
  132. * Change the downstream port. Note that application is responsible to destroy
  133. * current downstream port (the one that is going to be replaced with the
  134. * new port).
  135. *
  136. * @param m The master port.
  137. * @param port Port to be used for downstream port.
  138. *
  139. * @return PJ_SUCCESS on success.
  140. */
  141. PJ_DECL(pj_status_t) pjmedia_master_port_set_dport(pjmedia_master_port *m,
  142. pjmedia_port *port);
  143. /**
  144. * Get the downstream port.
  145. *
  146. * @param m The master port.
  147. *
  148. * @return The downstream port.
  149. */
  150. PJ_DECL(pjmedia_port*) pjmedia_master_port_get_dport(pjmedia_master_port*m);
  151. /**
  152. * Destroy the master port, and optionally destroy the upstream and
  153. * downstream ports.
  154. *
  155. * @param m The master port.
  156. * @param destroy_ports If non-zero, the function will destroy both
  157. * upstream and downstream ports too.
  158. *
  159. * @return PJ_SUCCESS on success.
  160. */
  161. PJ_DECL(pj_status_t) pjmedia_master_port_destroy(pjmedia_master_port *m,
  162. pj_bool_t destroy_ports);
  163. PJ_END_DECL
  164. /**
  165. * @}
  166. */
  167. #endif /* __PJMEDIA_MASTER_PORT_H__ */