transport_loop.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_TRANSPORT_LOOP_H__
  20. #define __PJMEDIA_TRANSPORT_LOOP_H__
  21. /**
  22. * @file transport_loop.h
  23. * @brief Loopback transport
  24. */
  25. #include <pjmedia/stream.h>
  26. /**
  27. * @defgroup PJMEDIA_TRANSPORT_LOOP Loopback Media Transport
  28. * @ingroup PJMEDIA_TRANSPORT
  29. * @brief Loopback transport for testing.
  30. * @{
  31. *
  32. * This is the loopback media transport, where packets sent to this transport
  33. * will be sent back to the streams attached to this transport. Unlike the
  34. * other PJMEDIA transports, the loop transport may be attached to multiple
  35. * streams (in other words, application should specify the same loop transport
  36. * instance when calling #pjmedia_stream_create()). Any RTP or RTCP packets
  37. * sent by one stream to this transport by default will be sent back to all
  38. * streams that are attached to this transport, including to the stream that
  39. * sends the packet. Application may individually select which stream to
  40. * receive packets by calling #pjmedia_transport_loop_disable_rx().
  41. */
  42. PJ_BEGIN_DECL
  43. /**
  44. * Settings to be given when creating loopback media transport. Application
  45. * should call #pjmedia_loop_tp_setting_default() to initialize this
  46. * structure with its default values.
  47. */
  48. typedef struct pjmedia_loop_tp_setting
  49. {
  50. /* Address family, which can be pj_AF_INET() for IPv4 or
  51. * pj_AF_INET6() for IPv6. Default is IPv4 (pj_AF_INET()).
  52. */
  53. int af;
  54. /* Optional local address which will be returned in the transport info.
  55. * If the string is empty, the address will be the default loopback
  56. * address (127.0.0.1 or ::1).
  57. *
  58. * Note that the address is used for info purpose only and no actual
  59. * resource will be allocated.
  60. *
  61. * Default is empty string.
  62. */
  63. pj_str_t addr;
  64. /* The port number for the RTP socket. The RTCP port number will be
  65. * set to one above RTP port. If zero, it will use the default port
  66. * number (4000).
  67. *
  68. * Note that no actual port will be allocated. Default is 4000.
  69. */
  70. int port;
  71. /* Setting whether attached streams will receive incoming packets.
  72. * Application can further customize the setting of a particular setting
  73. * using the API pjmedia_transport_loop_disable_rx().
  74. *
  75. * Default: PJ_FALSE;
  76. */
  77. pj_bool_t disable_rx;
  78. /*
  79. * Max number of attachments
  80. */
  81. unsigned max_attach_cnt;
  82. } pjmedia_loop_tp_setting;
  83. /**
  84. * Initialize loopback media transport setting with its default values.
  85. *
  86. * @param opt SRTP setting to be initialized.
  87. */
  88. PJ_DECL(void) pjmedia_loop_tp_setting_default(pjmedia_loop_tp_setting *opt);
  89. /**
  90. * Create the loopback transport.
  91. *
  92. * @param endpt The media endpoint instance.
  93. * @param p_tp Pointer to receive the transport instance.
  94. *
  95. * @return PJ_SUCCESS on success.
  96. */
  97. PJ_DECL(pj_status_t) pjmedia_transport_loop_create(pjmedia_endpt *endpt,
  98. pjmedia_transport **p_tp);
  99. /**
  100. * Create the loopback transport.
  101. *
  102. * @param endpt The media endpoint instance.
  103. * @param opt Optional settings. If NULL is given, default
  104. * settings will be used.
  105. * @param p_tp Pointer to receive the transport instance.
  106. *
  107. * @return PJ_SUCCESS on success.
  108. */
  109. PJ_DECL(pj_status_t)
  110. pjmedia_transport_loop_create2(pjmedia_endpt *endpt,
  111. const pjmedia_loop_tp_setting *opt,
  112. pjmedia_transport **p_tp);
  113. /**
  114. * Set the configuration of whether a stream will become the receiver of
  115. * incoming packets.
  116. *
  117. * @param tp The transport.
  118. * @param user The stream.
  119. * @param disabled PJ_TRUE to disable the receiving of packets, or
  120. * PJ_FALSE to enable it.
  121. */
  122. PJ_DECL(pj_status_t) pjmedia_transport_loop_disable_rx(pjmedia_transport *tp,
  123. void *user,
  124. pj_bool_t disabled);
  125. PJ_END_DECL
  126. /**
  127. * @}
  128. */
  129. #endif /* __PJMEDIA_TRANSPORT_LOOP_H__ */