Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | #ifndef __PJMEDIA_MEDIAMGR_H__ |
| 21 | #define __PJMEDIA_MEDIAMGR_H__ |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * @file endpoint.h |
| 26 | * @brief Media endpoint. |
| 27 | */ |
| 28 | /** |
| 29 | * @defgroup PJMED_ENDPT The Endpoint |
| 30 | * @{ |
| 31 | * |
| 32 | * The media endpoint acts as placeholder for endpoint capabilities. Each |
| 33 | * media endpoint will have a codec manager to manage list of codecs installed |
| 34 | * in the endpoint and a sound device factory. |
| 35 | * |
| 36 | * A reference to media endpoint instance is required when application wants |
| 37 | * to create a media session (#pjmedia_session_create()). |
| 38 | */ |
| 39 | |
| 40 | #include <pjmedia/codec.h> |
| 41 | #include <pjmedia/sdp.h> |
| 42 | #include <pjmedia/transport.h> |
| 43 | |
| 44 | |
| 45 | PJ_BEGIN_DECL |
| 46 | |
| 47 | /** |
| 48 | * This enumeration describes various flags that can be set or retrieved in |
| 49 | * the media endpoint, by using pjmedia_endpt_set_flag() and |
| 50 | * pjmedia_endpt_get_flag() respectively. |
| 51 | */ |
| 52 | typedef enum pjmedia_endpt_flag |
| 53 | { |
| 54 | /** |
| 55 | * This flag controls whether telephony-event should be offered in SDP. |
| 56 | * Value is boolean. |
| 57 | */ |
| 58 | PJMEDIA_ENDPT_HAS_TELEPHONE_EVENT_FLAG |
| 59 | |
| 60 | } pjmedia_endpt_flag; |
| 61 | |
| 62 | |
| 63 | /** |
| 64 | * Type of callback to register to pjmedia_endpt_atexit(). |
| 65 | */ |
| 66 | typedef void (*pjmedia_endpt_exit_callback)(pjmedia_endpt *endpt); |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * Create an instance of media endpoint. |
| 71 | * |
| 72 | * @param pf Pool factory, which will be used by the media endpoint |
| 73 | * throughout its lifetime. |
| 74 | * @param ioqueue Optional ioqueue instance to be registered to the |
| 75 | * endpoint. The ioqueue instance is used to poll all RTP |
| 76 | * and RTCP sockets. If this argument is NULL, the |
| 77 | * endpoint will create an internal ioqueue instance. |
| 78 | * @param worker_cnt Specify the number of worker threads to be created |
| 79 | * to poll the ioqueue. |
| 80 | * @param p_endpt Pointer to receive the endpoint instance. |
| 81 | * |
| 82 | * @return PJ_SUCCESS on success. |
| 83 | */ |
| 84 | PJ_DECL(pj_status_t) pjmedia_endpt_create( pj_pool_factory *pf, |
| 85 | pj_ioqueue_t *ioqueue, |
| 86 | unsigned worker_cnt, |
| 87 | pjmedia_endpt **p_endpt); |
| 88 | |
| 89 | /** |
| 90 | * Destroy media endpoint instance. |
| 91 | * |
| 92 | * @param endpt Media endpoint instance. |
| 93 | * |
| 94 | * @return PJ_SUCCESS on success. |
| 95 | */ |
| 96 | PJ_DECL(pj_status_t) pjmedia_endpt_destroy(pjmedia_endpt *endpt); |
| 97 | |
| 98 | /** |
| 99 | * Change the value of a flag. |
| 100 | * |
| 101 | * @param endpt Media endpoint. |
| 102 | * @param flag The flag. |
| 103 | * @param value Pointer to the value to be set. |
| 104 | * |
| 105 | * @reurn PJ_SUCCESS on success. |
| 106 | */ |
| 107 | PJ_DECL(pj_status_t) pjmedia_endpt_set_flag(pjmedia_endpt *endpt, |
| 108 | pjmedia_endpt_flag flag, |
| 109 | const void *value); |
| 110 | |
| 111 | /** |
| 112 | * Retrieve the value of a flag. |
| 113 | * |
| 114 | * @param endpt Media endpoint. |
| 115 | * @param flag The flag. |
| 116 | * @param value Pointer to store the result. |
| 117 | * |
| 118 | * @return PJ_SUCCESS on success. |
| 119 | */ |
| 120 | PJ_DECL(pj_status_t) pjmedia_endpt_get_flag(pjmedia_endpt *endpt, |
| 121 | pjmedia_endpt_flag flag, |
| 122 | void *value); |
| 123 | |
| 124 | /** |
| 125 | * Get the ioqueue instance of the media endpoint. |
| 126 | * |
| 127 | * @param endpt The media endpoint instance. |
| 128 | * |
| 129 | * @return The ioqueue instance of the media endpoint. |
| 130 | */ |
| 131 | PJ_DECL(pj_ioqueue_t*) pjmedia_endpt_get_ioqueue(pjmedia_endpt *endpt); |
| 132 | |
| 133 | |
| 134 | /** |
| 135 | * Get the number of worker threads on the media endpoint |
| 136 | * |
| 137 | * @param endpt The media endpoint instance. |
| 138 | * @return The number of worker threads on the media endpoint |
| 139 | */ |
| 140 | PJ_DECL(unsigned) pjmedia_endpt_get_thread_count(pjmedia_endpt *endpt); |
| 141 | |
| 142 | /** |
| 143 | * Get a reference to one of the worker threads of the media endpoint |
| 144 | * |
| 145 | * @param endpt The media endpoint instance. |
| 146 | * @param index The index of the thread: 0<= index < thread_cnt |
| 147 | * |
| 148 | * @return pj_thread_t or NULL |
| 149 | */ |
| 150 | PJ_DECL(pj_thread_t*) pjmedia_endpt_get_thread(pjmedia_endpt *endpt, |
| 151 | unsigned index); |
| 152 | |
| 153 | /** |
| 154 | * Stop and destroy the worker threads of the media endpoint |
| 155 | * |
| 156 | * @param endpt The media endpoint instance. |
| 157 | * |
| 158 | * @return PJ_SUCCESS on success. |
| 159 | */ |
| 160 | PJ_DECL(pj_status_t) pjmedia_endpt_stop_threads(pjmedia_endpt *endpt); |
| 161 | |
| 162 | |
| 163 | /** |
| 164 | * Request the media endpoint to create pool. |
| 165 | * |
| 166 | * @param endpt The media endpoint instance. |
| 167 | * @param name Name to be assigned to the pool. |
| 168 | * @param initial Initial pool size, in bytes. |
| 169 | * @param increment Increment size, in bytes. |
| 170 | * |
| 171 | * @return Memory pool. |
| 172 | */ |
| 173 | PJ_DECL(pj_pool_t*) pjmedia_endpt_create_pool( pjmedia_endpt *endpt, |
| 174 | const char *name, |
| 175 | pj_size_t initial, |
| 176 | pj_size_t increment); |
| 177 | |
| 178 | /** |
| 179 | * Get the codec manager instance of the media endpoint. |
| 180 | * |
| 181 | * @param endpt The media endpoint instance. |
| 182 | * |
| 183 | * @return The instance of codec manager belonging to |
| 184 | * this media endpoint. |
| 185 | */ |
| 186 | PJ_DECL(pjmedia_codec_mgr*) pjmedia_endpt_get_codec_mgr(pjmedia_endpt *endpt); |
| 187 | |
| 188 | |
| 189 | /** |
| 190 | * Create a SDP session description that describes the endpoint |
| 191 | * capability. |
| 192 | * |
| 193 | * @param endpt The media endpoint. |
| 194 | * @param pool Pool to use to create the SDP descriptor. |
| 195 | * @param stream_cnt Number of elements in the sock_info array. This |
| 196 | * also denotes the maximum number of streams (i.e. |
| 197 | * the "m=" lines) that will be created in the SDP. |
| 198 | * By convention, if this value is greater than one, |
| 199 | * the first media will be audio and the remaining |
| 200 | * media is video. |
| 201 | * @param sock_info Array of socket transport information. One |
| 202 | * transport is needed for each media stream, and |
| 203 | * each transport consists of an RTP and RTCP socket |
| 204 | * pair. |
| 205 | * @param p_sdp Pointer to receive SDP session descriptor. |
| 206 | * |
| 207 | * @return PJ_SUCCESS on success. |
| 208 | */ |
| 209 | PJ_DECL(pj_status_t) pjmedia_endpt_create_sdp( pjmedia_endpt *endpt, |
| 210 | pj_pool_t *pool, |
| 211 | unsigned stream_cnt, |
| 212 | const pjmedia_sock_info sock_info[], |
| 213 | pjmedia_sdp_session **p_sdp ); |
| 214 | |
| 215 | /** |
| 216 | * Create a "blank" SDP session description. The SDP will contain basic SDP |
| 217 | * fields such as origin, time, and name, but without any media lines. |
| 218 | * |
| 219 | * @param endpt The media endpoint. |
| 220 | * @param pool Pool to allocate memory from. |
| 221 | * @param sess_name Optional SDP session name, or NULL to use default |
| 222 | * value. |
| 223 | * @param origin Address to put in the origin field. |
| 224 | * @param p_sdp Pointer to receive the created SDP session. |
| 225 | * |
| 226 | * @return PJ_SUCCESS on success, or the appropriate error code. |
| 227 | */ |
| 228 | PJ_DECL(pj_status_t) pjmedia_endpt_create_base_sdp(pjmedia_endpt *endpt, |
| 229 | pj_pool_t *pool, |
| 230 | const pj_str_t *sess_name, |
| 231 | const pj_sockaddr *origin, |
| 232 | pjmedia_sdp_session **p_sdp); |
| 233 | |
| 234 | /** |
| 235 | * Create SDP media line for audio media. |
| 236 | * |
| 237 | * @param endpt The media endpoint. |
| 238 | * @param pool Pool to allocate memory from. |
| 239 | * @param si Socket information. |
| 240 | * @param options Option flags, must be zero for now. |
| 241 | * @param p_m Pointer to receive the created SDP media. |
| 242 | * |
| 243 | * @return PJ_SUCCESS on success, or the appropriate error code. |
| 244 | */ |
| 245 | PJ_DECL(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt, |
| 246 | pj_pool_t *pool, |
| 247 | const pjmedia_sock_info*si, |
| 248 | unsigned options, |
| 249 | pjmedia_sdp_media **p_m); |
| 250 | |
| 251 | /** |
| 252 | * Create SDP media line for video media. |
| 253 | * |
| 254 | * @param endpt The media endpoint. |
| 255 | * @param pool Pool to allocate memory from. |
| 256 | * @param si Socket information. |
| 257 | * @param options Option flags, must be zero for now. |
| 258 | * @param p_m Pointer to receive the created SDP media. |
| 259 | * |
| 260 | * @return PJ_SUCCESS on success, or the appropriate error code. |
| 261 | */ |
| 262 | PJ_DECL(pj_status_t) pjmedia_endpt_create_video_sdp(pjmedia_endpt *endpt, |
| 263 | pj_pool_t *pool, |
| 264 | const pjmedia_sock_info*si, |
| 265 | unsigned options, |
| 266 | pjmedia_sdp_media **p_m); |
| 267 | |
| 268 | /** |
| 269 | * Dump media endpoint capabilities. |
| 270 | * |
| 271 | * @param endpt The media endpoint. |
| 272 | * |
| 273 | * @return PJ_SUCCESS on success. |
| 274 | */ |
| 275 | PJ_DECL(pj_status_t) pjmedia_endpt_dump(pjmedia_endpt *endpt); |
| 276 | |
| 277 | |
| 278 | /** |
| 279 | * Register cleanup function to be called by media endpoint when |
| 280 | * #pjmedia_endpt_destroy() is called. Note that application should not |
| 281 | * use or access any endpoint resource (such as pool, ioqueue) from within |
| 282 | * the callback as such resource may have been released when the callback |
| 283 | * function is invoked. |
| 284 | * |
| 285 | * @param endpt The media endpoint. |
| 286 | * @param func The function to be registered. |
| 287 | * |
| 288 | * @return PJ_SUCCESS on success. |
| 289 | */ |
| 290 | PJ_DECL(pj_status_t) pjmedia_endpt_atexit(pjmedia_endpt *endpt, |
| 291 | pjmedia_endpt_exit_callback func); |
| 292 | |
| 293 | |
| 294 | |
| 295 | PJ_END_DECL |
| 296 | |
| 297 | |
| 298 | /** |
| 299 | * @} |
| 300 | */ |
| 301 | |
| 302 | |
| 303 | |
| 304 | #endif /* __PJMEDIA_MEDIAMGR_H__ */ |