Ignore:
Timestamp:
Mar 13, 2007 1:10:27 PM (17 years ago)
Author:
bennylp
Message:

Fixed ticket #172: SDP media direction negotiation bug (thanks Phil Torre)

File:
1 edited

Legend:

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

    r974 r1058  
    369369                                   pjmedia_sdp_media *local) 
    370370{ 
    371    if (pjmedia_sdp_media_find_attr2(remote, "inactive", NULL) != NULL) { 
     371    pjmedia_dir old_dir = PJMEDIA_DIR_ENCODING_DECODING, 
     372                new_dir; 
     373 
     374    /* Get the media direction of local SDP */ 
     375    if (pjmedia_sdp_media_find_attr2(local, "sendonly", NULL)) 
     376        old_dir = PJMEDIA_DIR_ENCODING; 
     377    else if (pjmedia_sdp_media_find_attr2(local, "recvonly", NULL)) 
     378        old_dir = PJMEDIA_DIR_DECODING; 
     379    else if (pjmedia_sdp_media_find_attr2(local, "inactive", NULL)) 
     380        old_dir = PJMEDIA_DIR_NONE; 
     381 
     382    new_dir = old_dir; 
     383 
     384    /* Adjust local media direction based on remote media direction */ 
     385    if (pjmedia_sdp_media_find_attr2(remote, "inactive", NULL) != NULL) { 
    372386        /* If remote has "a=inactive", then local is inactive too */ 
    373387 
    374         pjmedia_sdp_attr *a; 
    375  
    376         remove_all_media_directions(local); 
    377  
    378         a = pjmedia_sdp_attr_create(pool, "inactive", NULL); 
    379         pjmedia_sdp_media_add_attr(local, a); 
     388        new_dir = PJMEDIA_DIR_NONE; 
    380389 
    381390    } else if(pjmedia_sdp_media_find_attr2(remote, "sendonly", NULL) != NULL) { 
    382391        /* If remote has "a=sendonly", then set local to "recvonly" if 
    383          * it is currently "sendrecv". 
     392         * it is currently "sendrecv". Otherwise if local is NOT "recvonly", 
     393         * then set local direction to "inactive". 
     394         */ 
     395        switch (old_dir) { 
     396        case PJMEDIA_DIR_ENCODING_DECODING: 
     397            new_dir = PJMEDIA_DIR_DECODING; 
     398            break; 
     399        case PJMEDIA_DIR_DECODING: 
     400            /* No change */ 
     401            break; 
     402        default: 
     403            new_dir = PJMEDIA_DIR_NONE; 
     404            break; 
     405        } 
     406 
     407    } else if(pjmedia_sdp_media_find_attr2(remote, "recvonly", NULL) != NULL) { 
     408        /* If remote has "a=recvonly", then set local to "sendonly" if 
     409         * it is currently "sendrecv". Otherwise if local is NOT "sendonly", 
     410         * then set local direction to "inactive" 
    384411         */ 
    385412     
    386         pjmedia_sdp_attr *a; 
     413        switch (old_dir) { 
     414        case PJMEDIA_DIR_ENCODING_DECODING: 
     415            new_dir = PJMEDIA_DIR_ENCODING; 
     416            break; 
     417        case PJMEDIA_DIR_ENCODING: 
     418            /* No change */ 
     419            break; 
     420        default: 
     421            new_dir = PJMEDIA_DIR_NONE; 
     422            break; 
     423        } 
     424 
     425    } else { 
     426        /* Remote indicates "sendrecv" capability. No change to local  
     427         * direction  
     428         */ 
     429    } 
     430 
     431    if (new_dir != old_dir) { 
     432        pjmedia_sdp_attr *a = NULL; 
    387433 
    388434        remove_all_media_directions(local); 
    389435 
    390         a = pjmedia_sdp_attr_create(pool, "recvonly", NULL); 
    391         pjmedia_sdp_media_add_attr(local, a); 
    392  
    393     } else if(pjmedia_sdp_media_find_attr2(remote, "recvonly", NULL) != NULL) { 
    394         /* If remote has "a=recvonly", then set local to "sendonly" if 
    395          * it is currently "sendrecv". 
    396          */ 
    397      
    398         pjmedia_sdp_attr *a; 
    399  
    400         remove_all_media_directions(local); 
    401  
    402         a = pjmedia_sdp_attr_create(pool, "sendonly", NULL); 
    403         pjmedia_sdp_media_add_attr(local, a); 
    404  
    405     } else if(pjmedia_sdp_media_find_attr2(remote, "sendrecv", NULL) != NULL) { 
    406  
    407         pjmedia_sdp_attr *a; 
    408  
    409         remove_all_media_directions(local); 
    410  
    411         a = pjmedia_sdp_attr_create(pool, "sendrecv", NULL); 
    412         pjmedia_sdp_media_add_attr(local, a); 
    413  
    414     } else { 
    415         /* Otherwise remote is set to "sendrecv". 
    416          */ 
    417         remove_all_media_directions(local); 
     436        switch (new_dir) { 
     437        case PJMEDIA_DIR_NONE: 
     438            a = pjmedia_sdp_attr_create(pool, "inactive", NULL); 
     439            break; 
     440        case PJMEDIA_DIR_ENCODING: 
     441            a = pjmedia_sdp_attr_create(pool, "sendonly", NULL); 
     442            break; 
     443        case PJMEDIA_DIR_DECODING: 
     444            a = pjmedia_sdp_attr_create(pool, "recvonly", NULL); 
     445            break; 
     446        default: 
     447            /* sendrecv */ 
     448            break; 
     449        } 
     450         
     451        if (a) { 
     452            pjmedia_sdp_media_add_attr(local, a); 
     453        } 
    418454    } 
    419455} 
Note: See TracChangeset for help on using the changeset viewer.