Changeset 3905


Ignore:
Timestamp:
Dec 9, 2011 5:15:39 AM (12 years ago)
Author:
ming
Message:

Re #1420: Create a pool for the event manager so subscriber doesn't need to supply its own pool.

Location:
pjproject/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/event.h

    r3901 r3905  
    332332 * 
    333333 * @param mgr           The event manager. 
    334  * @param pool          Pool to allocate memory from. 
    335334 * @param cb            The callback function to receive the event. 
    336335 * @param user_data     The user data to be associated with the callback 
     
    341340 */ 
    342341PJ_DECL(pj_status_t) pjmedia_event_subscribe(pjmedia_event_mgr *mgr, 
    343                                              pj_pool_t *pool, 
    344342                                             pjmedia_event_cb *cb, 
    345343                                             void *user_data, 
  • pjproject/trunk/pjmedia/src/pjmedia/event.c

    r3899 r3905  
    5050struct pjmedia_event_mgr 
    5151{ 
     52    pj_pool_t      *pool; 
    5253    pj_thread_t    *thread;             /**< worker thread.             */ 
    5354    pj_bool_t       is_quitting; 
     
    5758    event_queue    *pub_ev_queue;       /**< publish() event queue.     */ 
    5859    esub            esub_list;          /**< list of subscribers.       */ 
     60    esub            free_esub_list;     /**< list of subscribers.       */ 
    5961    esub           *th_next_sub,        /**< worker thread's next sub.  */ 
    6062                   *pub_next_sub;       /**< publish() next sub.        */ 
     
    155157 
    156158    mgr = PJ_POOL_ZALLOC_T(pool, pjmedia_event_mgr); 
     159    mgr->pool = pj_pool_create(pool->factory, "evt mgr", 500, 500, NULL); 
    157160    pj_list_init(&mgr->esub_list); 
     161    pj_list_init(&mgr->free_esub_list); 
    158162 
    159163    if (!(options & PJMEDIA_EVENT_MGR_NO_THREAD)) { 
    160         status = pj_sem_create(pool, "ev_sem", 0, MAX_EVENTS + 1, &mgr->sem); 
     164        status = pj_sem_create(mgr->pool, "ev_sem", 0, MAX_EVENTS + 1, 
     165                               &mgr->sem); 
    161166        if (status != PJ_SUCCESS) 
    162167            return status; 
    163168 
    164         status = pj_thread_create(pool, "ev_thread", &event_worker_thread, 
     169        status = pj_thread_create(mgr->pool, "ev_thread", 
     170                                  &event_worker_thread, 
    165171                                  mgr, 0, 0, &mgr->thread); 
    166172        if (status != PJ_SUCCESS) { 
     
    170176    } 
    171177 
    172     status = pj_mutex_create_recursive(pool, "ev_mutex", &mgr->mutex); 
     178    status = pj_mutex_create_recursive(mgr->pool, "ev_mutex", &mgr->mutex); 
    173179    if (status != PJ_SUCCESS) { 
    174180        pjmedia_event_mgr_destroy(mgr); 
     
    197203PJ_DEF(void) pjmedia_event_mgr_destroy(pjmedia_event_mgr *mgr) 
    198204{ 
    199     esub *sub; 
    200  
    201205    if (!mgr) mgr = pjmedia_event_mgr_instance(); 
    202206    PJ_ASSERT_ON_FAIL(mgr != NULL, return); 
     
    218222    } 
    219223 
    220     sub = mgr->esub_list.next; 
    221     while (sub != &mgr->esub_list) { 
    222         esub *next = sub->next; 
    223         pj_list_erase(sub); 
    224         sub = next; 
    225     } 
     224    if (mgr->pool) 
     225        pj_pool_release(mgr->pool); 
    226226 
    227227    if (event_manager_instance == mgr) 
     
    242242 
    243243PJ_DEF(pj_status_t) pjmedia_event_subscribe( pjmedia_event_mgr *mgr, 
    244                                              pj_pool_t *pool, 
    245244                                             pjmedia_event_cb *cb, 
    246245                                             void *user_data, 
     
    249248    esub *sub; 
    250249 
    251     PJ_ASSERT_RETURN(pool && cb, PJ_EINVAL); 
     250    PJ_ASSERT_RETURN(cb, PJ_EINVAL); 
    252251 
    253252    if (!mgr) mgr = pjmedia_event_mgr_instance(); 
     
    271270    } 
    272271 
    273     sub = PJ_POOL_ZALLOC_T(pool, esub); 
     272    if (mgr->free_esub_list.next != &mgr->free_esub_list) { 
     273        sub = mgr->free_esub_list.next; 
     274        pj_list_erase(sub); 
     275    } else 
     276        sub = PJ_POOL_ZALLOC_T(mgr->pool, esub); 
    274277    sub->cb = cb; 
    275278    sub->user_data = user_data; 
     
    310313                mgr->pub_next_sub = sub->next; 
    311314            pj_list_erase(sub); 
     315            pj_list_push_back(&mgr->free_esub_list, sub); 
    312316            if (user_data && epub) 
    313317                break; 
  • pjproject/trunk/pjmedia/src/pjmedia/vid_port.c

    r3893 r3905  
    268268 
    269269    /* Subscribe to device's events */ 
    270     pjmedia_event_subscribe(NULL, vp->pool, &vidstream_event_cb, 
     270    pjmedia_event_subscribe(NULL, &vidstream_event_cb, 
    271271                            vp, vp->strm); 
    272272 
     
    411411 
    412412    /* Subscribe to client port's events */ 
    413     pjmedia_event_subscribe(NULL, vp->pool, &client_port_event_cb, vp, 
     413    pjmedia_event_subscribe(NULL, &client_port_event_cb, vp, 
    414414                            vp->client_port); 
    415415 
  • pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c

    r3901 r3905  
    13621362 
    13631363    /* Subscribe to codec events */ 
    1364     pjmedia_event_subscribe(NULL, pool, &stream_event_cb, stream, 
     1364    pjmedia_event_subscribe(NULL, &stream_event_cb, stream, 
    13651365                            stream->codec); 
    13661366 
  • pjproject/trunk/pjmedia/src/test/vid_codec_test.c

    r3901 r3905  
    321321 
    322322        /* Subscribe to codec events */ 
    323         pjmedia_event_subscribe(NULL, pool, &codec_on_event, &codec_port_data, 
     323        pjmedia_event_subscribe(NULL, &codec_on_event, &codec_port_data, 
    324324                                codec); 
    325325    } 
  • pjproject/trunk/pjmedia/src/test/vid_dev_test.c

    r3893 r3905  
    161161 
    162162    /* Set event handler */ 
    163     pjmedia_event_subscribe(NULL, pool, &vid_event_cb, NULL, renderer); 
     163    pjmedia_event_subscribe(NULL, &vid_event_cb, NULL, renderer); 
    164164 
    165165    /* Connect capture to renderer */ 
  • pjproject/trunk/pjmedia/src/test/vid_port_test.c

    r3893 r3905  
    118118 
    119119    /* Set event handler */ 
    120     pjmedia_event_subscribe(NULL, pool, &vid_event_cb, NULL, renderer); 
     120    pjmedia_event_subscribe(NULL, &vid_event_cb, NULL, renderer); 
    121121 
    122122    /* Connect capture to renderer */ 
  • pjproject/trunk/pjsip-apps/src/samples/aviplay.c

    r3893 r3905  
    402402 
    403403        /* subscribe events */ 
    404         pjmedia_event_subscribe(NULL, pool, &avi_event_cb, &avi_port, 
     404        pjmedia_event_subscribe(NULL, &avi_event_cb, &avi_port, 
    405405                                renderer); 
    406406 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c

    r3901 r3905  
    830830#if ENABLE_EVENT 
    831831            /* Register to video events */ 
    832             pjmedia_event_subscribe(NULL, w->pool, &call_media_on_event, 
     832            pjmedia_event_subscribe(NULL, &call_media_on_event, 
    833833                                    call_med, w->vp_rend); 
    834834#endif 
     
    900900            w = &pjsua_var.win[wid]; 
    901901#if ENABLE_EVENT 
    902             pjmedia_event_subscribe(NULL, w->pool, &call_media_on_event, 
     902            pjmedia_event_subscribe(NULL, &call_media_on_event, 
    903903                                    call_med, w->vp_cap); 
    904904#endif 
     
    19091909 
    19101910#if ENABLE_EVENT 
    1911     pjmedia_event_subscribe(NULL, new_w->pool, &call_media_on_event, 
     1911    pjmedia_event_subscribe(NULL, &call_media_on_event, 
    19121912                            call_med, new_w->vp_cap); 
    19131913#endif 
     
    19511951#if ENABLE_EVENT 
    19521952    /* Resubscribe */ 
    1953     pjmedia_event_subscribe(NULL, w->pool, &call_media_on_event, 
     1953    pjmedia_event_subscribe(NULL, &call_media_on_event, 
    19541954                            call_med, w->vp_cap); 
    19551955#endif 
Note: See TracChangeset for help on using the changeset viewer.