Changeset 5676 for pjproject


Ignore:
Timestamp:
Oct 24, 2017 7:31:39 AM (6 years ago)
Author:
ming
Message:

Fixed #2052: Add option for pjsua callback on_stream_created to destroy application's supplied media port

Location:
pjproject/trunk/pjsip
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r5675 r5676  
    488488 
    489489 
     490/** 
     491 * Structure to be passed to on stream created callback. 
     492 * See #on_stream_created2(). 
     493 */ 
     494typedef struct pjsua_on_stream_created_param 
     495{ 
     496    /** 
     497     * The media stream, read-only. 
     498     */ 
     499    pjmedia_stream      *stream; 
     500 
     501    /** 
     502     * Stream index in the media session, read-only. 
     503     */ 
     504    unsigned             stream_idx; 
     505 
     506    /** 
     507     * Specify if PJSUA should take ownership of the port returned in 
     508     * the port parameter below. If set to PJ_TRUE, 
     509     * pjmedia_port_destroy() will be called on the port when it is 
     510     * no longer needed. 
     511     * 
     512     * Default: PJ_FALSE 
     513     */ 
     514    pj_bool_t            destroy_port; 
     515 
     516    /** 
     517     * On input, it specifies the media port of the stream. Application 
     518     * may modify this pointer to point to different media port to be 
     519     * registered to the conference bridge. 
     520     */ 
     521    pjmedia_port        *port; 
     522 
     523} pjsua_on_stream_created_param; 
     524 
     525 
    490526/**  
    491527 * Enumeration of media transport state types. 
     
    822858     * media port then will be added to the conference bridge instead. 
    823859     * 
     860     * Note: if implemented, #on_stream_created2() callback will be called 
     861     * instead of this one.  
     862     * 
    824863     * @param call_id       Call identification. 
    825864     * @param strm          Media stream. 
     
    834873                              unsigned stream_idx, 
    835874                              pjmedia_port **p_port); 
     875 
     876    /** 
     877     * Notify application when media session is created and before it is 
     878     * registered to the conference bridge. Application may return different 
     879     * media port if it has added media processing port to the stream. This 
     880     * media port then will be added to the conference bridge instead. 
     881     * 
     882     * @param call_id       Call identification. 
     883     * @param param         The on stream created callback parameter. 
     884     */ 
     885    void (*on_stream_created2)(pjsua_call_id call_id, 
     886                               pjsua_on_stream_created_param *param); 
    836887 
    837888    /** 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r5649 r5676  
    5252        struct { 
    5353            pjmedia_stream *stream;    /**< The audio stream.               */ 
     54            pjmedia_port   *media_port;/**< The media port.                 */ 
     55            pj_bool_t       destroy_port;/**< Destroy the media port?       */ 
    5456            int             conf_slot; /**< Slot # in conference bridge.    */ 
    5557        } a; 
  • pjproject/trunk/pjsip/include/pjsua2/call.hpp

    r5645 r5676  
    692692{ 
    693693    /** 
    694      * Media stream. 
     694     * Media stream, read-only. 
    695695     */ 
    696696    MediaStream stream; 
    697697     
    698698    /** 
    699      * Stream index in the media session. 
     699     * Stream index in the media session, read-only. 
    700700     */ 
    701701    unsigned    streamIdx; 
    702702     
     703    /** 
     704     * Specify if PJSUA2 should take ownership of the port returned in 
     705     * the pPort parameter below. If set to PJ_TRUE, 
     706     * pjmedia_port_destroy() will be called on the port when it is 
     707     * no longer needed. 
     708     * 
     709     * Default: PJ_FALSE 
     710     */ 
     711    bool        destroyPort; 
     712 
    703713    /** 
    704714     * On input, it specifies the media port of the stream. Application 
  • pjproject/trunk/pjsip/include/pjsua2/endpoint.hpp

    r5672 r5676  
    16651665                                    pj_pool_t *pool, 
    16661666                                    const pjmedia_sdp_session *rem_sdp); 
    1667     static void on_stream_created(pjsua_call_id call_id, 
    1668                                   pjmedia_stream *strm, 
    1669                                   unsigned stream_idx, 
    1670                                   pjmedia_port **p_port); 
     1667    static void on_stream_created2(pjsua_call_id call_id, 
     1668                                   pjsua_on_stream_created_param *param); 
    16711669    static void on_stream_destroyed(pjsua_call_id call_id, 
    16721670                                    pjmedia_stream *strm, 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c

    r5651 r5676  
    532532        } 
    533533 
     534        if (call_med->strm.a.media_port) { 
     535            if (call_med->strm.a.destroy_port) 
     536                pjmedia_port_destroy(call_med->strm.a.media_port); 
     537            call_med->strm.a.media_port = NULL; 
     538        } 
     539 
    534540        pjmedia_stream_destroy(strm); 
    535541        call_med->strm.a.stream = NULL; 
     
    576582{ 
    577583    pjsua_call *call = call_med->call; 
    578     pjmedia_port *media_port; 
    579584    unsigned strm_idx = call_med->idx; 
    580585    pj_status_t status = PJ_SUCCESS; 
     
    646651         * We need the port interface to add to the conference bridge. 
    647652         */ 
    648         pjmedia_stream_get_port(call_med->strm.a.stream, &media_port); 
     653        pjmedia_stream_get_port(call_med->strm.a.stream, 
     654                                &call_med->strm.a.media_port); 
    649655 
    650656        /* Notify application about stream creation. 
     
    652658         * media port 
    653659         */ 
    654         if (pjsua_var.ua_cfg.cb.on_stream_created) { 
    655             pjsua_var.ua_cfg.cb.on_stream_created(call->index, 
     660        if (pjsua_var.ua_cfg.cb.on_stream_created2) { 
     661            pjsua_on_stream_created_param prm; 
     662             
     663            prm.stream = call_med->strm.a.stream; 
     664            prm.stream_idx = strm_idx; 
     665            prm.destroy_port = PJ_FALSE; 
     666            prm.port = call_med->strm.a.media_port; 
     667            (*pjsua_var.ua_cfg.cb.on_stream_created2)(call->index, &prm); 
     668             
     669            call_med->strm.a.destroy_port = prm.destroy_port; 
     670            call_med->strm.a.media_port = prm.port; 
     671 
     672        } else if (pjsua_var.ua_cfg.cb.on_stream_created) { 
     673            (*pjsua_var.ua_cfg.cb.on_stream_created)(call->index, 
    656674                                                  call_med->strm.a.stream, 
    657                                                   strm_idx, &media_port); 
     675                                                  strm_idx, 
     676                                                  &call_med->strm.a.media_port); 
    658677        } 
    659678 
     
    672691                port_name = pj_str("call"); 
    673692            } 
    674             status = pjmedia_conf_add_port( pjsua_var.mconf, 
    675                                             call->inv->pool, 
    676                                             media_port, 
    677                                             &port_name, 
    678                                             (unsigned*) 
    679                                             &call_med->strm.a.conf_slot); 
     693            status = pjmedia_conf_add_port(pjsua_var.mconf, 
     694                                           call->inv->pool, 
     695                                           call_med->strm.a.media_port, 
     696                                           &port_name, 
     697                                           (unsigned*) 
     698                                           &call_med->strm.a.conf_slot); 
    680699            if (status != PJ_SUCCESS) { 
    681700                goto on_return; 
  • pjproject/trunk/pjsip/src/pjsua2/endpoint.cpp

    r5672 r5676  
    10711071} 
    10721072 
    1073 void Endpoint::on_stream_created(pjsua_call_id call_id, 
    1074                                  pjmedia_stream *strm, 
    1075                                  unsigned stream_idx, 
    1076                                  pjmedia_port **p_port) 
     1073void Endpoint::on_stream_created2(pjsua_call_id call_id, 
     1074                                  pjsua_on_stream_created_param *param) 
    10771075{ 
    10781076    Call *call = Call::lookup(call_id); 
     
    10821080     
    10831081    OnStreamCreatedParam prm; 
    1084     prm.stream = strm; 
    1085     prm.streamIdx = stream_idx; 
    1086     prm.pPort = (void *)*p_port; 
     1082    prm.stream = param->stream; 
     1083    prm.streamIdx = param->stream_idx; 
     1084    prm.destroyPort = param->destroy_port; 
     1085    prm.pPort = (MediaPort)param->port; 
    10871086     
    10881087    call->onStreamCreated(prm); 
    10891088     
    1090     if (prm.pPort != (void *)*p_port) 
    1091         *p_port = (pjmedia_port *)prm.pPort; 
     1089    param->destroy_port = prm.destroyPort; 
     1090    param->port = (pjmedia_port *)prm.pPort; 
    10921091} 
    10931092 
     
    15581557    ua_cfg.cb.on_call_media_state       = &Endpoint::on_call_media_state; 
    15591558    ua_cfg.cb.on_call_sdp_created       = &Endpoint::on_call_sdp_created; 
    1560     ua_cfg.cb.on_stream_created         = &Endpoint::on_stream_created; 
     1559    ua_cfg.cb.on_stream_created2        = &Endpoint::on_stream_created2; 
    15611560    ua_cfg.cb.on_stream_destroyed       = &Endpoint::on_stream_destroyed; 
    15621561    ua_cfg.cb.on_dtmf_digit             = &Endpoint::on_dtmf_digit; 
Note: See TracChangeset for help on using the changeset viewer.