Changeset 2582 for pjproject/trunk


Ignore:
Timestamp:
Apr 7, 2009 12:56:02 PM (15 years ago)
Author:
nanang
Message:

Ticket #781: Fixed conf bridge API functions to have mutex protection when accessing ports.

File:
1 edited

Legend:

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

    r2506 r2582  
    888888    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    889889 
     890    pj_mutex_lock(conf->mutex); 
     891 
    890892    /* Port must be valid. */ 
    891     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
     893    conf_port = conf->ports[slot]; 
     894    if (conf_port == NULL) { 
     895        pj_mutex_unlock(conf->mutex); 
     896        return PJ_EINVAL; 
     897    } 
    892898 
    893899    conf_port = conf->ports[slot]; 
     
    898904    if (rx != PJMEDIA_PORT_NO_CHANGE) 
    899905        conf_port->rx_setting = rx; 
     906 
     907    pj_mutex_unlock(conf->mutex); 
    900908 
    901909    return PJ_SUCCESS; 
     
    919927                     sink_slot<conf->max_ports, PJ_EINVAL); 
    920928 
    921     /* Ports must be valid. */ 
    922     PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL); 
    923     PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL); 
    924  
    925929    /* For now, level MUST be zero. */ 
    926930    PJ_ASSERT_RETURN(level == 0, PJ_EINVAL); 
     
    928932    pj_mutex_lock(conf->mutex); 
    929933 
     934    /* Ports must be valid. */ 
    930935    src_port = conf->ports[src_slot]; 
    931936    dst_port = conf->ports[sink_slot]; 
     937    if (!src_port || !dst_port) { 
     938        pj_mutex_unlock(conf->mutex); 
     939        return PJ_EINVAL; 
     940    } 
    932941 
    933942    /* Check if connection has been made */ 
     
    981990                     sink_slot<conf->max_ports, PJ_EINVAL); 
    982991 
     992    pj_mutex_lock(conf->mutex); 
     993 
    983994    /* Ports must be valid. */ 
    984     PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL); 
    985     PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL); 
    986  
    987     pj_mutex_lock(conf->mutex); 
    988  
    989995    src_port = conf->ports[src_slot]; 
    990996    dst_port = conf->ports[sink_slot]; 
     997    if (!src_port || !dst_port) { 
     998        pj_mutex_unlock(conf->mutex); 
     999        return PJ_EINVAL; 
     1000    } 
    9911001 
    9921002    /* Check if connection has been made */ 
     
    10591069    PJ_ASSERT_RETURN(conf && port < conf->max_ports, PJ_EINVAL); 
    10601070 
    1061     /* Port must be valid. */ 
    1062     PJ_ASSERT_RETURN(conf->ports[port] != NULL, PJ_EINVAL); 
    1063  
    10641071    /* Suspend the sound devices. 
    10651072     * Don't want to remove port while port is being accessed by sound 
     
    10691076    pj_mutex_lock(conf->mutex); 
    10701077 
     1078    /* Port must be valid. */ 
    10711079    conf_port = conf->ports[port]; 
     1080    if (conf_port == NULL) { 
     1081        pj_mutex_unlock(conf->mutex); 
     1082        return PJ_EINVAL; 
     1083    } 
     1084 
    10721085    conf_port->tx_setting = PJMEDIA_PORT_DISABLE; 
    10731086    conf_port->rx_setting = PJMEDIA_PORT_DISABLE; 
     
    11381151    PJ_ASSERT_RETURN(conf && p_count && ports, PJ_EINVAL); 
    11391152 
     1153    /* Lock mutex */ 
     1154    pj_mutex_lock(conf->mutex); 
     1155 
    11401156    for (i=0; i<conf->max_ports && count<*p_count; ++i) { 
    11411157        if (!conf->ports[i]) 
     
    11451161    } 
    11461162 
     1163    /* Unlock mutex */ 
     1164    pj_mutex_unlock(conf->mutex); 
     1165 
    11471166    *p_count = count; 
    11481167    return PJ_SUCCESS; 
     
    11611180    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    11621181 
     1182    /* Lock mutex */ 
     1183    pj_mutex_lock(conf->mutex); 
     1184 
    11631185    /* Port must be valid. */ 
    1164     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    1165  
    11661186    conf_port = conf->ports[slot]; 
     1187    if (conf_port == NULL) { 
     1188        pj_mutex_unlock(conf->mutex); 
     1189        return PJ_EINVAL; 
     1190    } 
    11671191 
    11681192    info->slot = slot; 
     
    11801204    info->rx_adj_level = conf_port->rx_adj_level - NORMAL_LEVEL; 
    11811205 
     1206    /* Unlock mutex */ 
     1207    pj_mutex_unlock(conf->mutex); 
     1208 
    11821209    return PJ_SUCCESS; 
    11831210} 
     
    11921219    PJ_ASSERT_RETURN(conf && size && info, PJ_EINVAL); 
    11931220 
     1221    /* Lock mutex */ 
     1222    pj_mutex_lock(conf->mutex); 
     1223 
    11941224    for (i=0; i<conf->max_ports && count<*size; ++i) { 
    11951225        if (!conf->ports[i]) 
     
    11991229        ++count; 
    12001230    } 
     1231 
     1232    /* Unlock mutex */ 
     1233    pj_mutex_unlock(conf->mutex); 
    12011234 
    12021235    *size = count; 
     
    12181251    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    12191252 
     1253    /* Lock mutex */ 
     1254    pj_mutex_lock(conf->mutex); 
     1255 
    12201256    /* Port must be valid. */ 
    1221     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    1222  
    12231257    conf_port = conf->ports[slot]; 
     1258    if (conf_port == NULL) { 
     1259        pj_mutex_unlock(conf->mutex); 
     1260        return PJ_EINVAL; 
     1261    } 
    12241262 
    12251263    if (tx_level != NULL) { 
     
    12291267    if (rx_level != NULL)  
    12301268        *rx_level = conf_port->rx_level; 
     1269 
     1270    /* Unlock mutex */ 
     1271    pj_mutex_unlock(conf->mutex); 
    12311272 
    12321273    return PJ_SUCCESS; 
     
    12461287    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    12471288 
    1248     /* Port must be valid. */ 
    1249     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    1250  
    12511289    /* Value must be from -128 to +127 */ 
    12521290    /* Disabled, you can put more than +127, at your own risk:  
     
    12551293    PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL); 
    12561294 
     1295    /* Lock mutex */ 
     1296    pj_mutex_lock(conf->mutex); 
     1297 
     1298    /* Port must be valid. */ 
    12571299    conf_port = conf->ports[slot]; 
     1300    if (conf_port == NULL) { 
     1301        pj_mutex_unlock(conf->mutex); 
     1302        return PJ_EINVAL; 
     1303    } 
    12581304 
    12591305    /* Set normalized adjustment level. */ 
    12601306    conf_port->rx_adj_level = adj_level + NORMAL_LEVEL; 
     1307 
     1308    /* Unlock mutex */ 
     1309    pj_mutex_unlock(conf->mutex); 
    12611310 
    12621311    return PJ_SUCCESS; 
     
    12761325    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    12771326 
    1278     /* Port must be valid. */ 
    1279     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    1280  
    12811327    /* Value must be from -128 to +127 */ 
    12821328    /* Disabled, you can put more than +127,, at your own risk: 
     
    12851331    PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL); 
    12861332 
     1333    /* Lock mutex */ 
     1334    pj_mutex_lock(conf->mutex); 
     1335 
     1336    /* Port must be valid. */ 
    12871337    conf_port = conf->ports[slot]; 
     1338    if (conf_port == NULL) { 
     1339        pj_mutex_unlock(conf->mutex); 
     1340        return PJ_EINVAL; 
     1341    } 
    12881342 
    12891343    /* Set normalized adjustment level. */ 
    12901344    conf_port->tx_adj_level = adj_level + NORMAL_LEVEL; 
     1345 
     1346    /* Unlock mutex */ 
     1347    pj_mutex_unlock(conf->mutex); 
    12911348 
    12921349    return PJ_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.