endpoint.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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_MEDIAMGR_H__
  20. #define __PJMEDIA_MEDIAMGR_H__
  21. /**
  22. * @file endpoint.h
  23. * @brief Media endpoint.
  24. */
  25. /**
  26. * @defgroup PJMED_ENDPT The Endpoint
  27. * @{
  28. *
  29. * The media endpoint acts as placeholder for endpoint capabilities. Each
  30. * media endpoint will have a codec manager to manage list of codecs installed
  31. * in the endpoint and a sound device factory.
  32. *
  33. * A reference to media endpoint instance is required when application wants
  34. * to create a media session (#pjmedia_session_create()).
  35. */
  36. #include <pjmedia/codec.h>
  37. #include <pjmedia/sdp.h>
  38. #include <pjmedia/transport.h>
  39. #include <pjmedia-audiodev/audiodev.h>
  40. PJ_BEGIN_DECL
  41. /**
  42. * This enumeration describes various flags that can be set or retrieved in
  43. * the media endpoint, by using pjmedia_endpt_set_flag() and
  44. * pjmedia_endpt_get_flag() respectively.
  45. */
  46. typedef enum pjmedia_endpt_flag
  47. {
  48. /**
  49. * This flag controls whether telephony-event should be offered in SDP.
  50. * Value is boolean.
  51. */
  52. PJMEDIA_ENDPT_HAS_TELEPHONE_EVENT_FLAG
  53. } pjmedia_endpt_flag;
  54. /**
  55. * This structure specifies various settings that can be passed when creating
  56. * audio/video sdp.
  57. */
  58. typedef struct pjmedia_endpt_create_sdp_param
  59. {
  60. /**
  61. * Direction of the media.
  62. *
  63. * Default: PJMEDIA_DIR_ENCODING_DECODING
  64. */
  65. pjmedia_dir dir;
  66. } pjmedia_endpt_create_sdp_param;
  67. /**
  68. * Type of callback to register to pjmedia_endpt_atexit().
  69. */
  70. typedef void (*pjmedia_endpt_exit_callback)(pjmedia_endpt *endpt);
  71. /**
  72. * Call this function to initialize \a pjmedia_endpt_create_sdp_param with default
  73. * values.
  74. *
  75. * @param param The param to be initialized.
  76. */
  77. PJ_DECL(void)
  78. pjmedia_endpt_create_sdp_param_default(pjmedia_endpt_create_sdp_param *param);
  79. /**
  80. * Create an instance of media endpoint.
  81. *
  82. * @param pf Pool factory, which will be used by the media endpoint
  83. * throughout its lifetime.
  84. * @param ioqueue Optional ioqueue instance to be registered to the
  85. * endpoint. The ioqueue instance is used to poll all RTP
  86. * and RTCP sockets. If this argument is NULL, the
  87. * endpoint will create an internal ioqueue instance.
  88. * @param worker_cnt Specify the number of worker threads to be created
  89. * to poll the ioqueue.
  90. * @param p_endpt Pointer to receive the endpoint instance.
  91. *
  92. * @return PJ_SUCCESS on success.
  93. */
  94. PJ_DECL(pj_status_t) pjmedia_endpt_create2(pj_pool_factory *pf,
  95. pj_ioqueue_t *ioqueue,
  96. unsigned worker_cnt,
  97. pjmedia_endpt **p_endpt);
  98. /**
  99. * Create an instance of media endpoint and initialize audio subsystem.
  100. *
  101. * @param pf Pool factory, which will be used by the media endpoint
  102. * throughout its lifetime.
  103. * @param ioqueue Optional ioqueue instance to be registered to the
  104. * endpoint. The ioqueue instance is used to poll all RTP
  105. * and RTCP sockets. If this argument is NULL, the
  106. * endpoint will create an internal ioqueue instance.
  107. * @param worker_cnt Specify the number of worker threads to be created
  108. * to poll the ioqueue.
  109. * @param p_endpt Pointer to receive the endpoint instance.
  110. *
  111. * @return PJ_SUCCESS on success.
  112. */
  113. PJ_INLINE(pj_status_t) pjmedia_endpt_create(pj_pool_factory *pf,
  114. pj_ioqueue_t *ioqueue,
  115. unsigned worker_cnt,
  116. pjmedia_endpt **p_endpt)
  117. {
  118. /* This function is inlined to avoid build problem due to circular
  119. * dependency, i.e: this function prevents pjmedia's dependency on
  120. * pjmedia-audiodev.
  121. */
  122. pj_status_t status;
  123. /* Sound */
  124. status = pjmedia_aud_subsys_init(pf);
  125. if (status != PJ_SUCCESS)
  126. return status;
  127. status = pjmedia_endpt_create2(pf, ioqueue, worker_cnt, p_endpt);
  128. if (status != PJ_SUCCESS) {
  129. pjmedia_aud_subsys_shutdown();
  130. }
  131. return status;
  132. }
  133. /**
  134. * Destroy media endpoint instance.
  135. *
  136. * @param endpt Media endpoint instance.
  137. *
  138. * @return PJ_SUCCESS on success.
  139. */
  140. PJ_DECL(pj_status_t) pjmedia_endpt_destroy2(pjmedia_endpt *endpt);
  141. /**
  142. * Destroy media endpoint instance and shutdown audio subsystem.
  143. *
  144. * @param endpt Media endpoint instance.
  145. *
  146. * @return PJ_SUCCESS on success.
  147. */
  148. PJ_INLINE(pj_status_t) pjmedia_endpt_destroy(pjmedia_endpt *endpt)
  149. {
  150. /* This function is inlined to avoid build problem due to circular
  151. * dependency, i.e: this function prevents pjmedia's dependency on
  152. * pjmedia-audiodev.
  153. */
  154. pj_status_t status = pjmedia_endpt_destroy2(endpt);
  155. pjmedia_aud_subsys_shutdown();
  156. return status;
  157. }
  158. /**
  159. * Change the value of a flag.
  160. *
  161. * @param endpt Media endpoint.
  162. * @param flag The flag.
  163. * @param value Pointer to the value to be set.
  164. *
  165. * @return PJ_SUCCESS on success.
  166. */
  167. PJ_DECL(pj_status_t) pjmedia_endpt_set_flag(pjmedia_endpt *endpt,
  168. pjmedia_endpt_flag flag,
  169. const void *value);
  170. /**
  171. * Retrieve the value of a flag.
  172. *
  173. * @param endpt Media endpoint.
  174. * @param flag The flag.
  175. * @param value Pointer to store the result.
  176. *
  177. * @return PJ_SUCCESS on success.
  178. */
  179. PJ_DECL(pj_status_t) pjmedia_endpt_get_flag(pjmedia_endpt *endpt,
  180. pjmedia_endpt_flag flag,
  181. void *value);
  182. /**
  183. * Get the ioqueue instance of the media endpoint.
  184. *
  185. * @param endpt The media endpoint instance.
  186. *
  187. * @return The ioqueue instance of the media endpoint.
  188. */
  189. PJ_DECL(pj_ioqueue_t*) pjmedia_endpt_get_ioqueue(pjmedia_endpt *endpt);
  190. /**
  191. * Get the number of worker threads on the media endpoint
  192. *
  193. * @param endpt The media endpoint instance.
  194. * @return The number of worker threads on the media endpoint
  195. */
  196. PJ_DECL(unsigned) pjmedia_endpt_get_thread_count(pjmedia_endpt *endpt);
  197. /**
  198. * Get a reference to one of the worker threads of the media endpoint
  199. *
  200. * @param endpt The media endpoint instance.
  201. * @param index The index of the thread: 0<= index < thread_cnt
  202. *
  203. * @return pj_thread_t or NULL
  204. */
  205. PJ_DECL(pj_thread_t*) pjmedia_endpt_get_thread(pjmedia_endpt *endpt,
  206. unsigned index);
  207. /**
  208. * Stop and destroy the worker threads of the media endpoint
  209. *
  210. * @param endpt The media endpoint instance.
  211. *
  212. * @return PJ_SUCCESS on success.
  213. */
  214. PJ_DECL(pj_status_t) pjmedia_endpt_stop_threads(pjmedia_endpt *endpt);
  215. /**
  216. * Request the media endpoint to create pool.
  217. *
  218. * @param endpt The media endpoint instance.
  219. * @param name Name to be assigned to the pool.
  220. * @param initial Initial pool size, in bytes.
  221. * @param increment Increment size, in bytes.
  222. *
  223. * @return Memory pool.
  224. */
  225. PJ_DECL(pj_pool_t*) pjmedia_endpt_create_pool( pjmedia_endpt *endpt,
  226. const char *name,
  227. pj_size_t initial,
  228. pj_size_t increment);
  229. /**
  230. * Get the codec manager instance of the media endpoint.
  231. *
  232. * @param endpt The media endpoint instance.
  233. *
  234. * @return The instance of codec manager belonging to
  235. * this media endpoint.
  236. */
  237. PJ_DECL(pjmedia_codec_mgr*) pjmedia_endpt_get_codec_mgr(pjmedia_endpt *endpt);
  238. /**
  239. * Create a SDP session description that describes the endpoint
  240. * capability.
  241. *
  242. * @param endpt The media endpoint.
  243. * @param pool Pool to use to create the SDP descriptor.
  244. * @param stream_cnt Number of elements in the sock_info array. This
  245. * also denotes the maximum number of streams (i.e.
  246. * the "m=" lines) that will be created in the SDP.
  247. * By convention, if this value is greater than one,
  248. * the first media will be audio and the remaining
  249. * media is video.
  250. * @param sock_info Array of socket transport information. One
  251. * transport is needed for each media stream, and
  252. * each transport consists of an RTP and RTCP socket
  253. * pair.
  254. * @param p_sdp Pointer to receive SDP session descriptor.
  255. *
  256. * @return PJ_SUCCESS on success.
  257. */
  258. PJ_DECL(pj_status_t) pjmedia_endpt_create_sdp( pjmedia_endpt *endpt,
  259. pj_pool_t *pool,
  260. unsigned stream_cnt,
  261. const pjmedia_sock_info sock_info[],
  262. pjmedia_sdp_session **p_sdp );
  263. /**
  264. * Create a "blank" SDP session description. The SDP will contain basic SDP
  265. * fields such as origin, time, and name, but without any media lines.
  266. *
  267. * @param endpt The media endpoint.
  268. * @param pool Pool to allocate memory from.
  269. * @param sess_name Optional SDP session name, or NULL to use default
  270. * value.
  271. * @param origin Address to put in the origin field.
  272. * @param p_sdp Pointer to receive the created SDP session.
  273. *
  274. * @return PJ_SUCCESS on success, or the appropriate error code.
  275. */
  276. PJ_DECL(pj_status_t) pjmedia_endpt_create_base_sdp(pjmedia_endpt *endpt,
  277. pj_pool_t *pool,
  278. const pj_str_t *sess_name,
  279. const pj_sockaddr *origin,
  280. pjmedia_sdp_session **p_sdp);
  281. /**
  282. * Create SDP media line for audio media.
  283. *
  284. * @param endpt The media endpoint.
  285. * @param pool Pool to allocate memory from.
  286. * @param si Socket information.
  287. * @param options Options parameter, can be NULL. If set to NULL,
  288. * default values will be used.
  289. * @param p_m Pointer to receive the created SDP media.
  290. *
  291. * @return PJ_SUCCESS on success, or the appropriate error code.
  292. */
  293. PJ_DECL(pj_status_t)
  294. pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
  295. pj_pool_t *pool,
  296. const pjmedia_sock_info *si,
  297. const pjmedia_endpt_create_sdp_param *options,
  298. pjmedia_sdp_media **p_m);
  299. /**
  300. * Create SDP media line for video media.
  301. *
  302. * @param endpt The media endpoint.
  303. * @param pool Pool to allocate memory from.
  304. * @param si Socket information.
  305. * @param options Options parameter, can be NULL. If set to NULL,
  306. * default values will be used.
  307. * @param p_m Pointer to receive the created SDP media.
  308. *
  309. * @return PJ_SUCCESS on success, or the appropriate error code.
  310. */
  311. PJ_DECL(pj_status_t)
  312. pjmedia_endpt_create_video_sdp(pjmedia_endpt *endpt,
  313. pj_pool_t *pool,
  314. const pjmedia_sock_info *si,
  315. const pjmedia_endpt_create_sdp_param *options,
  316. pjmedia_sdp_media **p_m);
  317. /**
  318. * Dump media endpoint capabilities.
  319. *
  320. * @param endpt The media endpoint.
  321. *
  322. * @return PJ_SUCCESS on success.
  323. */
  324. PJ_DECL(pj_status_t) pjmedia_endpt_dump(pjmedia_endpt *endpt);
  325. /**
  326. * Register cleanup function to be called by media endpoint when
  327. * #pjmedia_endpt_destroy() is called. Note that application should not
  328. * use or access any endpoint resource (such as pool, ioqueue) from within
  329. * the callback as such resource may have been released when the callback
  330. * function is invoked.
  331. *
  332. * @param endpt The media endpoint.
  333. * @param func The function to be registered.
  334. *
  335. * @return PJ_SUCCESS on success.
  336. */
  337. PJ_DECL(pj_status_t) pjmedia_endpt_atexit(pjmedia_endpt *endpt,
  338. pjmedia_endpt_exit_callback func);
  339. PJ_END_DECL
  340. /**
  341. * @}
  342. */
  343. #endif /* __PJMEDIA_MEDIAMGR_H__ */