Ignore:
Timestamp:
Jul 12, 2011 9:08:56 AM (13 years ago)
Author:
bennylp
Message:

More on re #1284:

  • Replaced bit_info mechanism to report format change in codec with event
  • Updated vid_port, vid_codec_test, etc.
  • Add event publisher to vid_codec
  • Add event publisher to pjmedia_port
  • Add event publisher to vid_stream
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_port.c

    r3617 r3622  
    5757    pjmedia_conversion_param conv_param; 
    5858 
    59     pjmedia_event_publisher  epub; 
     59    pjmedia_event_publisher    epub; 
    6060    pjmedia_event_subscription esub_dev; 
     61    pjmedia_event_subscription esub_client_port; 
    6162 
    6263    pjmedia_clock           *clock; 
     
    9192static pj_status_t vidstream_event_cb(pjmedia_event_subscription *esub, 
    9293                                      pjmedia_event *event); 
     94static pj_status_t client_port_event_cb(pjmedia_event_subscription *esub, 
     95                                        pjmedia_event *event); 
    9396 
    9497static void enc_clock_cb(const pj_timestamp *ts, void *user_data); 
     
    398401                                              pj_bool_t destroy) 
    399402{ 
     403    pjmedia_event_publisher *epub; 
     404 
    400405    PJ_ASSERT_RETURN(vp && vp->role==ROLE_ACTIVE, PJ_EINVAL); 
    401406    vp->destroy_client_port = destroy; 
    402407    vp->client_port = port; 
     408 
     409    /* Subscribe to client port's events */ 
     410    epub = pjmedia_port_get_event_publisher(port); 
     411    if (epub) { 
     412        pjmedia_event_subscription_init(&vp->esub_client_port, 
     413                                        &client_port_event_cb, 
     414                                        vp); 
     415        pjmedia_event_subscribe(epub, &vp->esub_client_port); 
     416    } 
    403417    return PJ_SUCCESS; 
    404418} 
     
    408422{ 
    409423    PJ_ASSERT_RETURN(vp && vp->role==ROLE_ACTIVE, PJ_EINVAL); 
    410     vp->client_port = NULL; 
     424 
     425    if (vp->client_port) { 
     426        pjmedia_event_publisher *epub; 
     427 
     428        /* Unsubscribe event */ 
     429        epub = pjmedia_port_get_event_publisher(vp->client_port); 
     430        if (epub && vp->esub_client_port.user_data) { 
     431            pjmedia_event_unsubscribe(epub, &vp->esub_client_port); 
     432            pj_bzero(&vp->esub_client_port, sizeof(vp->esub_client_port)); 
     433        } 
     434        vp->client_port = NULL; 
     435    } 
    411436    return PJ_SUCCESS; 
    412437} 
     
    513538*/ 
    514539 
     540/* Handle event from vidstream */ 
    515541static pj_status_t vidstream_event_cb(pjmedia_event_subscription *esub, 
    516542                                      pjmedia_event *event) 
     
    538564} 
    539565 
    540 static pj_status_t detect_fmt_change(pjmedia_vid_port *vp, 
    541                                      pjmedia_frame *frame) 
    542 { 
    543     if (frame->bit_info & PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED) { 
     566static pj_status_t client_port_event_cb(pjmedia_event_subscription *esub, 
     567                                        pjmedia_event *event) 
     568{ 
     569    pjmedia_vid_port *vp = (pjmedia_vid_port*)esub->user_data; 
     570 
     571    if (event->type == PJMEDIA_EVENT_FMT_CHANGED) { 
    544572        const pjmedia_video_format_detail *vfd; 
    545         pjmedia_event pevent; 
    546573        pj_status_t status; 
     574 
     575        ++event->proc_cnt; 
    547576 
    548577        pjmedia_vid_port_stop(vp); 
     
    605634        } 
    606635 
    607         /* Notify application of the format change. */ 
    608         pjmedia_event_init(&pevent, PJMEDIA_EVENT_FMT_CHANGED, NULL, &vp->epub); 
    609         pjmedia_format_copy(&pevent.data.fmt_changed.new_fmt, 
    610                             &vp->client_port->info.fmt); 
    611         pjmedia_event_publish(&vp->epub, &pevent); 
    612  
    613636        pjmedia_vid_port_start(vp); 
    614637    } 
    615638 
    616     return PJ_SUCCESS; 
     639    /* Republish the event */ 
     640    return pjmedia_event_publish(&vp->epub, event); 
    617641} 
    618642 
     
    752776                    } 
    753777 
    754                     status = detect_fmt_change(vp, vp->frm_buf); 
    755                     if (status != PJ_SUCCESS) 
    756                         return; 
    757  
    758778                    pj_add_timestamp32(&vp->clocksrc.timestamp, 
    759779                                       frame_ts); 
     
    771791    pj_add_timestamp32(&vp->clocksrc.timestamp, frame_ts); 
    772792    pjmedia_clock_src_update(&vp->clocksrc, NULL); 
    773  
    774     status = detect_fmt_change(vp, vp->frm_buf); 
    775     if (status != PJ_SUCCESS) 
    776         return; 
    777793 
    778794    if (convert_frame(vp, vp->frm_buf, &frame) != PJ_SUCCESS) 
     
    821837    if (vp->role==ROLE_ACTIVE) { 
    822838        if (vp->client_port) { 
    823             pj_status_t status; 
    824  
    825             status = pjmedia_port_get_frame(vp->client_port, frame); 
    826             if (status != PJ_SUCCESS) 
    827                 return status; 
    828  
    829             return detect_fmt_change(vp, frame); 
     839            return pjmedia_port_get_frame(vp->client_port, frame); 
    830840        } 
    831841    } else { 
Note: See TracChangeset for help on using the changeset viewer.