Changeset 2581


Ignore:
Timestamp:
Apr 7, 2009 11:08:21 AM (15 years ago)
Author:
nanang
Message:

Ticket #777: Rechecked & updated audio switch board functions to make sure they have mutex protection in accessing conf ports.

File:
1 edited

Legend:

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

    r2506 r2581  
    474474    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    475475 
     476    pj_mutex_lock(conf->mutex); 
     477 
    476478    /* Port must be valid. */ 
    477     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    478  
    479479    conf_port = conf->ports[slot]; 
     480    if (conf_port == NULL) { 
     481        pj_mutex_unlock(conf->mutex); 
     482        return PJ_EINVAL; 
     483    } 
    480484 
    481485    if (tx != PJMEDIA_PORT_NO_CHANGE) 
     
    484488    if (rx != PJMEDIA_PORT_NO_CHANGE) 
    485489        conf_port->rx_setting = rx; 
     490 
     491    pj_mutex_unlock(conf->mutex); 
    486492 
    487493    return PJ_SUCCESS; 
     
    505511                     sink_slot<conf->max_ports, PJ_EINVAL); 
    506512 
    507     /* Ports must be valid. */ 
    508     PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL); 
    509     PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL); 
    510  
    511513    /* For now, level MUST be zero. */ 
    512514    PJ_ASSERT_RETURN(level == 0, PJ_EINVAL); 
     
    514516    pj_mutex_lock(conf->mutex); 
    515517 
     518    /* Ports must be valid. */ 
    516519    src_port = conf->ports[src_slot]; 
    517520    dst_port = conf->ports[sink_slot]; 
     521    if (!src_port || !dst_port) { 
     522        pj_mutex_unlock(conf->mutex); 
     523        return PJ_EINVAL; 
     524    } 
    518525 
    519526    /* Format must match. */ 
     
    603610                     sink_slot<conf->max_ports, PJ_EINVAL); 
    604611 
     612    pj_mutex_lock(conf->mutex); 
     613 
    605614    /* Ports must be valid. */ 
    606     PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL); 
    607     PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL); 
    608  
    609     pj_mutex_lock(conf->mutex); 
    610  
    611615    src_port = conf->ports[src_slot]; 
    612616    dst_port = conf->ports[sink_slot]; 
     617    if (!src_port || !dst_port) { 
     618        pj_mutex_unlock(conf->mutex); 
     619        return PJ_EINVAL; 
     620    } 
    613621 
    614622    /* Check if connection has been made */ 
     
    686694    PJ_ASSERT_RETURN(conf && port < conf->max_ports, PJ_EINVAL); 
    687695 
    688     /* Port must be valid. */ 
    689     PJ_ASSERT_RETURN(conf->ports[port] != NULL, PJ_EINVAL); 
    690  
    691696    /* Suspend the sound devices. 
    692697     * Don't want to remove port while port is being accessed by sound 
     
    696701    pj_mutex_lock(conf->mutex); 
    697702 
     703    /* Port must be valid. */ 
    698704    conf_port = conf->ports[port]; 
     705    if (conf_port == NULL) { 
     706        pj_mutex_unlock(conf->mutex); 
     707        return PJ_EINVAL; 
     708    } 
     709 
    699710    conf_port->tx_setting = PJMEDIA_PORT_DISABLE; 
    700711    conf_port->rx_setting = PJMEDIA_PORT_DISABLE; 
     
    773784    PJ_ASSERT_RETURN(conf && p_count && ports, PJ_EINVAL); 
    774785 
     786    /* Lock mutex */ 
     787    pj_mutex_lock(conf->mutex); 
     788 
    775789    for (i=0; i<conf->max_ports && count<*p_count; ++i) { 
    776790        if (!conf->ports[i]) 
     
    780794    } 
    781795 
     796    /* Unlock mutex */ 
     797    pj_mutex_unlock(conf->mutex); 
     798 
    782799    *p_count = count; 
    783800    return PJ_SUCCESS; 
     
    796813    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    797814 
     815    /* Lock mutex */ 
     816    pj_mutex_lock(conf->mutex); 
     817 
    798818    /* Port must be valid. */ 
    799     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    800  
    801819    conf_port = conf->ports[slot]; 
     820    if (conf_port == NULL) { 
     821        pj_mutex_unlock(conf->mutex); 
     822        return PJ_EINVAL; 
     823    } 
    802824 
    803825    pj_bzero(info, sizeof(pjmedia_conf_port_info)); 
     
    818840    info->rx_adj_level = conf_port->rx_adj_level - NORMAL_LEVEL; 
    819841 
     842    /* Unlock mutex */ 
     843    pj_mutex_unlock(conf->mutex); 
     844 
    820845    return PJ_SUCCESS; 
    821846} 
     
    830855    PJ_ASSERT_RETURN(conf && size && info, PJ_EINVAL); 
    831856 
     857    /* Lock mutex */ 
     858    pj_mutex_lock(conf->mutex); 
     859 
    832860    for (i=0; i<conf->max_ports && count<*size; ++i) { 
    833861        if (!conf->ports[i]) 
     
    837865        ++count; 
    838866    } 
     867 
     868    /* Unlock mutex */ 
     869    pj_mutex_unlock(conf->mutex); 
    839870 
    840871    *size = count; 
     
    856887    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    857888 
     889    /* Lock mutex */ 
     890    pj_mutex_lock(conf->mutex); 
     891 
    858892    /* Port must be valid. */ 
    859     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    860  
    861893    conf_port = conf->ports[slot]; 
     894    if (conf_port == NULL) { 
     895        pj_mutex_unlock(conf->mutex); 
     896        return PJ_EINVAL; 
     897    } 
    862898 
    863899    if (tx_level != NULL) { 
     
    867903    if (rx_level != NULL)  
    868904        *rx_level = conf_port->rx_level; 
     905 
     906    /* Unlock mutex */ 
     907    pj_mutex_unlock(conf->mutex); 
    869908 
    870909    return PJ_SUCCESS; 
     
    883922    /* Check arguments */ 
    884923    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    885  
    886     /* Port must be valid. */ 
    887     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    888924 
    889925    /* Value must be from -128 to +127 */ 
     
    893929    PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL); 
    894930 
     931    /* Lock mutex */ 
     932    pj_mutex_lock(conf->mutex); 
     933 
     934    /* Port must be valid. */ 
    895935    conf_port = conf->ports[slot]; 
     936    if (conf_port == NULL) { 
     937        pj_mutex_unlock(conf->mutex); 
     938        return PJ_EINVAL; 
     939    } 
    896940 
    897941    /* Level adjustment is applicable only for ports that work with raw PCM. */ 
     
    902946    conf_port->rx_adj_level = adj_level + NORMAL_LEVEL; 
    903947 
     948    /* Unlock mutex */ 
     949    pj_mutex_unlock(conf->mutex); 
     950 
    904951    return PJ_SUCCESS; 
    905952} 
     
    917964    /* Check arguments */ 
    918965    PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL); 
    919  
    920     /* Port must be valid. */ 
    921     PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL); 
    922966 
    923967    /* Value must be from -128 to +127 */ 
     
    927971    PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL); 
    928972 
     973    /* Lock mutex */ 
     974    pj_mutex_lock(conf->mutex); 
     975 
     976    /* Port must be valid. */ 
    929977    conf_port = conf->ports[slot]; 
     978    if (conf_port == NULL) { 
     979        pj_mutex_unlock(conf->mutex); 
     980        return PJ_EINVAL; 
     981    } 
    930982 
    931983    /* Level adjustment is applicable only for ports that work with raw PCM. */ 
     
    935987    /* Set normalized adjustment level. */ 
    936988    conf_port->tx_adj_level = adj_level + NORMAL_LEVEL; 
     989 
     990    /* Unlock mutex */ 
     991    pj_mutex_unlock(conf->mutex); 
    937992 
    938993    return PJ_SUCCESS; 
     
    11261181    unsigned ci, i; 
    11271182     
    1128     /* Must lock mutex */ 
     1183    /* Lock mutex */ 
    11291184    pj_mutex_lock(conf->mutex); 
    11301185 
     
    13701425{ 
    13711426    pjmedia_conf *conf = (pjmedia_conf*) this_port->port_data.pdata; 
    1372     struct conf_port *cport = conf->ports[this_port->port_data.ldata]; 
     1427    struct conf_port *cport; 
    13731428    unsigned j; 
    13741429    pj_int32_t level = 0; 
     1430 
     1431    /* Lock mutex */ 
     1432    pj_mutex_lock(conf->mutex); 
     1433 
     1434    /* Get conf port of this port */ 
     1435    cport = conf->ports[this_port->port_data.ldata]; 
     1436    if (cport == NULL) { 
     1437        /* Unlock mutex */ 
     1438        pj_mutex_unlock(conf->mutex); 
     1439        return PJ_SUCCESS; 
     1440    } 
    13751441 
    13761442    pj_add_timestamp32(&cport->ts_rx, cport->info->samples_per_frame); 
     
    13791445    if (cport->rx_setting == PJMEDIA_PORT_DISABLE) { 
    13801446        cport->rx_level = 0; 
     1447        /* Unlock mutex */ 
     1448        pj_mutex_unlock(conf->mutex); 
    13811449        return PJ_SUCCESS; 
    13821450    } 
     
    13851453    if (cport->listener_cnt == 0) { 
    13861454        cport->rx_level = 0; 
     1455        /* Unlock mutex */ 
     1456        pj_mutex_unlock(conf->mutex); 
    13871457        return PJ_SUCCESS; 
    13881458    } 
     
    14611531    } 
    14621532 
     1533    /* Unlock mutex */ 
     1534    pj_mutex_unlock(conf->mutex); 
     1535 
    14631536    return PJ_SUCCESS; 
    14641537} 
Note: See TracChangeset for help on using the changeset viewer.