Changeset 350 for pjproject/trunk/pjmedia/src/pjmedia/endpoint.c
- Timestamp:
- Mar 22, 2006 11:59:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/endpoint.c
r321 r350 20 20 #include <pjmedia/errno.h> 21 21 #include <pjmedia/sdp.h> 22 #include <pj/assert.h> 23 #include <pj/ioqueue.h> 24 #include <pj/log.h> 25 #include <pj/os.h> 26 #include <pj/pool.h> 22 27 #include <pj/sock.h> 23 #include <pj/pool.h>24 28 #include <pj/string.h> 25 #include <pj/assert.h>26 #include <pj/os.h>27 #include <pj/log.h>28 29 29 30 … … 66 67 67 68 69 /* Worker thread proc. */ 70 static int PJ_THREAD_FUNC worker_proc(void*); 71 72 73 #define MAX_THREADS 16 74 68 75 69 76 /** Concrete declaration of media endpoint. */ … … 78 85 /** Codec manager. */ 79 86 pjmedia_codec_mgr codec_mgr; 87 88 /** IOqueue instance. */ 89 pj_ioqueue_t *ioqueue; 90 91 /** Do we own the ioqueue? */ 92 pj_bool_t own_ioqueue; 93 94 /** Number of threads. */ 95 unsigned thread_cnt; 96 97 /** IOqueue polling thread, if any. */ 98 pj_thread_t *thread[MAX_THREADS]; 99 100 /** To signal polling thread to quit. */ 101 pj_bool_t quit_flag; 80 102 }; 81 103 … … 84 106 */ 85 107 PJ_DEF(pj_status_t) pjmedia_endpt_create(pj_pool_factory *pf, 108 pj_ioqueue_t *ioqueue, 109 unsigned worker_cnt, 86 110 pjmedia_endpt **p_endpt) 87 111 { 88 112 pj_pool_t *pool; 89 113 pjmedia_endpt *endpt; 114 unsigned i; 90 115 pj_status_t status; 91 116 … … 105 130 endpt->pool = pool; 106 131 endpt->pf = pf; 132 endpt->ioqueue = ioqueue; 133 endpt->thread_cnt = worker_cnt; 107 134 108 135 /* Sound */ … … 111 138 /* Init codec manager. */ 112 139 status = pjmedia_codec_mgr_init(&endpt->codec_mgr); 113 if (status != PJ_SUCCESS) { 114 pjmedia_snd_deinit(); 140 if (status != PJ_SUCCESS) 115 141 goto on_error; 116 } 117 118 /* Init and register G.711 codec. */ 119 #if 0 120 // Starting from 0.5.4, codec factory is registered by applications. 121 factory = pj_pool_alloc (endpt->pool, sizeof(pjmedia_codec_factory)); 122 123 status = g711_init_factory (factory, endpt->pool); 124 if (status != PJ_SUCCESS) { 125 pjmedia_snd_deinit(); 126 goto on_error; 127 } 128 129 status = pjmedia_codec_mgr_register_factory (&endpt->codec_mgr, factory); 130 if (status != PJ_SUCCESS) { 131 pjmedia_snd_deinit(); 132 goto on_error; 133 } 134 #endif 142 143 /* Create ioqueue if none is specified. */ 144 if (endpt->ioqueue == NULL) { 145 146 endpt->own_ioqueue = PJ_TRUE; 147 148 status = pj_ioqueue_create( endpt->pool, PJ_IOQUEUE_MAX_HANDLES, 149 &endpt->ioqueue); 150 if (status != PJ_SUCCESS) 151 goto on_error; 152 153 if (worker_cnt == 0) { 154 PJ_LOG(4,(THIS_FILE, "Warning: no worker thread is created in" 155 "media endpoint for internal ioqueue")); 156 } 157 } 158 159 /* Create worker threads if asked. */ 160 for (i=0; i<worker_cnt; ++i) { 161 status = pj_thread_create( endpt->pool, "media", &worker_proc, 162 endpt, 0, 0, &endpt->thread[i]); 163 if (status != PJ_SUCCESS) 164 goto on_error; 165 } 166 135 167 136 168 *p_endpt = endpt; … … 138 170 139 171 on_error: 172 173 /* Destroy threads */ 174 for (i=0; i<endpt->thread_cnt; ++i) { 175 if (endpt->thread[i]) { 176 pj_thread_destroy(endpt->thread[i]); 177 } 178 } 179 180 /* Destroy internal ioqueue */ 181 if (endpt->ioqueue && endpt->own_ioqueue) 182 pj_ioqueue_destroy(endpt->ioqueue); 183 184 pjmedia_snd_deinit(); 140 185 pj_pool_release(pool); 141 186 return status; … … 155 200 PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt) 156 201 { 202 unsigned i; 203 157 204 PJ_ASSERT_RETURN(endpt, PJ_EINVAL); 205 206 endpt->quit_flag = 1; 207 208 /* Destroy threads */ 209 for (i=0; i<endpt->thread_cnt; ++i) { 210 if (endpt->thread[i]) { 211 pj_thread_join(endpt->thread[i]); 212 pj_thread_destroy(endpt->thread[i]); 213 endpt->thread[i] = NULL; 214 } 215 } 216 217 /* Destroy internal ioqueue */ 218 if (endpt->ioqueue && endpt->own_ioqueue) { 219 pj_ioqueue_destroy(endpt->ioqueue); 220 endpt->ioqueue = NULL; 221 } 158 222 159 223 endpt->pf = NULL; … … 163 227 164 228 return PJ_SUCCESS; 229 } 230 231 232 /** 233 * Get the ioqueue instance of the media endpoint. 234 */ 235 PJ_DEF(pj_ioqueue_t*) pjmedia_endpt_get_ioqueue(pjmedia_endpt *endpt) 236 { 237 PJ_ASSERT_RETURN(endpt, NULL); 238 return endpt->ioqueue; 239 } 240 241 242 /** 243 * Worker thread proc. 244 */ 245 static int PJ_THREAD_FUNC worker_proc(void *arg) 246 { 247 pjmedia_endpt *endpt = arg; 248 249 while (!endpt->quit_flag) { 250 pj_time_val timeout = { 0, 500 }; 251 pj_ioqueue_poll(endpt->ioqueue, &timeout); 252 } 253 254 return 0; 165 255 } 166 256
Note: See TracChangeset
for help on using the changeset viewer.