Ignore:
Timestamp:
Dec 1, 2011 10:49:07 AM (12 years ago)
Author:
ming
Message:

Closed #1420: Add support for event manager

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/vid_port.c

    r3758 r3893  
    6262    pjmedia_conversion_param conv_param; 
    6363 
    64     pjmedia_event_publisher    epub; 
    65     pjmedia_event_subscription esub_dev; 
    66     pjmedia_event_subscription esub_client_port; 
    67  
    6864    pjmedia_clock           *clock; 
    6965    pjmedia_clock_src        clocksrc; 
     
    9591                                       void *user_data, 
    9692                                       pjmedia_frame *frame); 
    97 static pj_status_t vidstream_event_cb(pjmedia_event_subscription *esub, 
    98                                       pjmedia_event *event); 
    99 static pj_status_t client_port_event_cb(pjmedia_event_subscription *esub, 
    100                                         pjmedia_event *event); 
     93static pj_status_t vidstream_event_cb(pjmedia_event *event, 
     94                                      void *user_data); 
     95static pj_status_t client_port_event_cb(pjmedia_event *event, 
     96                                        void *user_data); 
    10197 
    10298static void enc_clock_cb(const pj_timestamp *ts, void *user_data); 
     
    207203    vp->dir = prm->vidparam.dir; 
    208204//    vp->cap_size = vfd->size; 
    209     pjmedia_event_publisher_init(&vp->epub, SIGNATURE); 
    210205 
    211206    vparam = prm->vidparam; 
     
    273268 
    274269    /* Subscribe to device's events */ 
    275     pjmedia_event_subscription_init(&vp->esub_dev, vidstream_event_cb, vp); 
    276     pjmedia_event_subscribe( 
    277             pjmedia_vid_dev_stream_get_event_publisher(vp->strm), 
    278             &vp->esub_dev); 
     270    pjmedia_event_subscribe(NULL, vp->pool, &vidstream_event_cb, 
     271                            vp, vp->strm); 
    279272 
    280273    if (vp->dir & PJMEDIA_DIR_CAPTURE) { 
     
    371364} 
    372365 
    373 PJ_DEF(pjmedia_event_publisher*) 
    374 pjmedia_vid_port_get_event_publisher(pjmedia_vid_port *vid_port) 
    375 { 
    376     PJ_ASSERT_RETURN(vid_port, NULL); 
    377     return &vid_port->epub; 
    378 } 
    379  
    380366PJ_DEF(pjmedia_vid_dev_stream*) 
    381367pjmedia_vid_port_get_stream(pjmedia_vid_port *vp) 
     
    420406                                              pj_bool_t destroy) 
    421407{ 
    422     pjmedia_event_publisher *epub; 
    423  
    424408    PJ_ASSERT_RETURN(vp && vp->role==ROLE_ACTIVE, PJ_EINVAL); 
    425409    vp->destroy_client_port = destroy; 
     
    427411 
    428412    /* Subscribe to client port's events */ 
    429     epub = pjmedia_port_get_event_publisher(port); 
    430     if (epub) { 
    431         pjmedia_event_subscription_init(&vp->esub_client_port, 
    432                                         &client_port_event_cb, 
    433                                         vp); 
    434         pjmedia_event_subscribe(epub, &vp->esub_client_port); 
    435     } 
     413    pjmedia_event_subscribe(NULL, vp->pool, &client_port_event_cb, vp, 
     414                            vp->client_port); 
     415 
    436416    return PJ_SUCCESS; 
    437417} 
     
    442422    PJ_ASSERT_RETURN(vp && vp->role==ROLE_ACTIVE, PJ_EINVAL); 
    443423 
    444     if (vp->client_port) { 
    445         pjmedia_event_unsubscribe(&vp->esub_client_port); 
    446         vp->client_port = NULL; 
    447     } 
     424    pjmedia_event_unsubscribe(NULL, &client_port_event_cb, vp, 
     425                              vp->client_port); 
     426    vp->client_port = NULL; 
     427 
    448428    return PJ_SUCCESS; 
    449429} 
     
    511491    } 
    512492    if (vp->strm) { 
     493        pjmedia_event_unsubscribe(NULL, &vidstream_event_cb, vp, vp->strm); 
    513494        pjmedia_vid_dev_stream_destroy(vp->strm); 
    514495        vp->strm = NULL; 
    515496    } 
    516497    if (vp->client_port) { 
     498        pjmedia_event_unsubscribe(NULL, &client_port_event_cb, vp, 
     499                                  vp->client_port); 
    517500        if (vp->destroy_client_port) 
    518501            pjmedia_port_destroy(vp->client_port); 
     
    561544 
    562545/* Handle event from vidstream */ 
    563 static pj_status_t vidstream_event_cb(pjmedia_event_subscription *esub, 
    564                                       pjmedia_event *event) 
    565 { 
    566     pjmedia_vid_port *vp = (pjmedia_vid_port*)esub->user_data; 
     546static pj_status_t vidstream_event_cb(pjmedia_event *event, 
     547                                      void *user_data) 
     548{ 
     549    pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data; 
    567550     
    568551    /* Just republish the event to our client */ 
    569     return pjmedia_event_publish(&vp->epub, event); 
    570 } 
    571  
    572 static pj_status_t client_port_event_cb(pjmedia_event_subscription *esub, 
    573                                         pjmedia_event *event) 
    574 { 
    575     pjmedia_vid_port *vp = (pjmedia_vid_port*)esub->user_data; 
     552    return pjmedia_event_publish(NULL, vp, event, 0); 
     553} 
     554 
     555static pj_status_t client_port_event_cb(pjmedia_event *event, 
     556                                        void *user_data) 
     557{ 
     558    pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data; 
    576559 
    577560    if (event->type == PJMEDIA_EVENT_FMT_CHANGED) { 
     
    579562        pj_status_t status; 
    580563         
    581         ++event->proc_cnt; 
    582  
    583564        pjmedia_vid_port_stop(vp); 
    584565         
     
    634615    } 
    635616     
    636     /* Republish the event */ 
    637     return pjmedia_event_publish(&vp->epub, event); 
     617    /* Republish the event, post the event to the event manager 
     618     * to avoid deadlock if vidport is trying to stop the clock. 
     619     */ 
     620    return pjmedia_event_publish(NULL, vp, event, 
     621                                 PJMEDIA_EVENT_PUBLISH_POST_EVENT); 
    638622} 
    639623 
Note: See TracChangeset for help on using the changeset viewer.