Ignore:
Timestamp:
Sep 15, 2007 8:55:00 AM (17 years ago)
Author:
bennylp
Message:

Implemented ticket #373: Packet loss simulation in PJMEDIA ICE transport

File:
1 edited

Legend:

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

    r1435 r1436  
    2121#include <pj/assert.h> 
    2222#include <pj/log.h> 
     23#include <pj/rand.h> 
     24 
    2325 
    2426struct transport_ice 
     
    3335    pj_sockaddr_in       remote_rtp; 
    3436    pj_sockaddr_in       remote_rtcp; 
     37 
     38    unsigned             tx_drop_pct;   /**< Percent of tx pkts to drop.    */ 
     39    unsigned             rx_drop_pct;   /**< Percent of rx pkts to drop.    */ 
    3540 
    3641    void               (*rtp_cb)(void*, 
     
    651656{ 
    652657    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     658 
     659    /* Simulate packet lost on TX direction */ 
     660    if (tp_ice->tx_drop_pct) { 
     661        if ((pj_rand() % 100) <= (int)tp_ice->tx_drop_pct) { 
     662            PJ_LOG(5,(tp_ice->ice_st->obj_name,  
     663                      "TX RTP packet dropped because of pkt lost " 
     664                      "simulation")); 
     665            return PJ_SUCCESS; 
     666        } 
     667    } 
     668 
    653669    return pj_ice_strans_sendto(tp_ice->ice_st, 1,  
    654670                                pkt, size, &tp_ice->remote_rtp, 
     
    679695    struct transport_ice *tp_ice = (struct transport_ice*) ice_st->user_data; 
    680696 
    681     if (comp_id==1 && tp_ice->rtp_cb) 
     697    if (comp_id==1 && tp_ice->rtp_cb) { 
     698 
     699        /* Simulate packet lost on RX direction */ 
     700        if (tp_ice->rx_drop_pct) { 
     701            if ((pj_rand() % 100) <= (int)tp_ice->rx_drop_pct) { 
     702                PJ_LOG(5,(ice_st->obj_name,  
     703                          "RX RTP packet dropped because of pkt lost " 
     704                          "simulation")); 
     705                return; 
     706            } 
     707        } 
     708 
    682709        (*tp_ice->rtp_cb)(tp_ice->stream, pkt, size); 
    683     else if (comp_id==2 && tp_ice->rtcp_cb) 
     710 
     711    } else if (comp_id==2 && tp_ice->rtcp_cb) 
    684712        (*tp_ice->rtcp_cb)(tp_ice->stream, pkt, size); 
    685713 
     
    734762 
    735763 
     764/* Simulate lost */ 
     765PJ_DEF(pj_status_t) pjmedia_ice_simulate_lost( pjmedia_transport *tp, 
     766                                               pjmedia_dir dir, 
     767                                               unsigned pct_lost) 
     768{ 
     769    struct transport_ice *ice = (struct transport_ice*) tp; 
     770 
     771    PJ_ASSERT_RETURN(tp && pct_lost <= 100, PJ_EINVAL); 
     772 
     773    if (dir & PJMEDIA_DIR_ENCODING) 
     774        ice->tx_drop_pct = pct_lost; 
     775 
     776    if (dir & PJMEDIA_DIR_DECODING) 
     777        ice->rx_drop_pct = pct_lost; 
     778 
     779    return PJ_SUCCESS; 
     780} 
     781 
Note: See TracChangeset for help on using the changeset viewer.