Ignore:
Timestamp:
Dec 1, 2011 9:06:14 AM (12 years ago)
Author:
nanang
Message:

Re #1419, implement media count manipulation per call basis:

  • moved the media count setting from account setting to call setting
  • introduced pjsua_call_setting, to be used by pjsua_call_make_call() and some new APIs: pjsua_call_answer2(), pjsua_call_reinvite2(), pjsua_call_update2()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r3875 r3891  
    135135 
    136136    struct app_vid          vid; 
     137    unsigned                aud_cnt; 
    137138} app_config; 
    138139 
     
    403404    cfg->vid.vcapture_dev = PJMEDIA_VID_DEFAULT_CAPTURE_DEV; 
    404405    cfg->vid.vrender_dev = PJMEDIA_VID_DEFAULT_RENDER_DEV; 
     406    cfg->aud_cnt = 1; 
    405407} 
    406408 
     
    14561458            break; 
    14571459        case OPT_VIDEO: 
    1458             app_config.vid.vid_cnt = 1; 
    1459             app_config.vid.in_auto_show = PJ_TRUE; 
    1460             app_config.vid.out_auto_transmit = PJ_TRUE; 
     1460            cfg->vid.vid_cnt = 1; 
     1461            cfg->vid.in_auto_show = PJ_TRUE; 
     1462            cfg->vid.out_auto_transmit = PJ_TRUE; 
    14611463            break; 
    14621464        case OPT_EXTRA_AUDIO: 
    1463             ++cur_acc->max_audio_cnt; 
     1465            cfg->aud_cnt++; 
    14641466            break; 
    14651467 
     
    17181720    if (acc_cfg->mwi_enabled) 
    17191721        pj_strcat2(result, "--mwi\n"); 
    1720  
    1721     /* Video & extra audio */ 
    1722     for (i=0; i<acc_cfg->max_video_cnt; ++i) { 
    1723         pj_strcat2(result, "--video\n"); 
    1724     } 
    1725     for (i=1; i<acc_cfg->max_audio_cnt; ++i) { 
    1726         pj_strcat2(result, "--extra-audio\n"); 
    1727     } 
    17281722} 
    17291723 
     
    18901884 
    18911885    pj_strcat2(&cfg, "\n#\n# Media settings:\n#\n"); 
     1886 
     1887    /* Video & extra audio */ 
     1888    for (i=0; i<config->vid.vid_cnt; ++i) { 
     1889        pj_strcat2(&cfg, "--video\n"); 
     1890    } 
     1891    for (i=1; i<config->aud_cnt; ++i) { 
     1892        pj_strcat2(&cfg, "--extra-audio\n"); 
     1893    } 
    18921894 
    18931895    /* SRTP */ 
     
    25762578     
    25772579    if (app_config.auto_answer > 0) { 
    2578         pjsua_call_answer(call_id, app_config.auto_answer, NULL, NULL); 
    2579     } 
    2580  
     2580        pjsua_call_setting call_opt; 
     2581 
     2582        pjsua_call_setting_default(&call_opt); 
     2583        call_opt.audio_cnt = app_config.aud_cnt; 
     2584        call_opt.video_cnt = app_config.vid.vid_cnt; 
     2585 
     2586        pjsua_call_answer2(call_id, &call_opt, app_config.auto_answer, NULL, NULL); 
     2587    } 
     2588     
    25812589    if (app_config.auto_answer < 200) { 
     2590        char notif_st[80] = {0}; 
     2591 
     2592#if PJSUA_HAS_VIDEO 
     2593        if (call_info.rem_offerer && call_info.rem_video_cnt) { 
     2594            snprintf(notif_st, sizeof(notif_st),  
     2595                     "To %s the video, type \"vid %s\" first, " 
     2596                     "before answering the call!\n", 
     2597                     (app_config.vid.vid_cnt? "reject":"accept"), 
     2598                     (app_config.vid.vid_cnt? "disable":"enable")); 
     2599        } 
     2600#endif 
     2601 
    25822602        PJ_LOG(3,(THIS_FILE, 
    25832603                  "Incoming call for account %d!\n" 
     2604                  "Media count: %d audio & %d video\n" 
     2605                  "%s" 
    25842606                  "From: %s\n" 
    25852607                  "To: %s\n" 
    25862608                  "Press a to answer or h to reject call", 
    25872609                  acc_id, 
     2610                  call_info.rem_audio_cnt, 
     2611                  call_info.rem_video_cnt, 
     2612                  notif_st, 
    25882613                  call_info.remote_info.ptr, 
    25892614                  call_info.local_info.ptr)); 
     
    28472872        pjsua_call_hangup(call_id, 500, &reason, NULL); 
    28482873    } 
     2874 
     2875#if PJSUA_HAS_VIDEO 
     2876    /* Check if remote has just tried to enable video */ 
     2877    if (call_info.rem_offerer && call_info.rem_video_cnt) 
     2878    { 
     2879        int vid_idx; 
     2880 
     2881        /* Check if there is active video */ 
     2882        vid_idx = pjsua_call_get_vid_stream_idx(call_id); 
     2883        if (vid_idx == -1 || call_info.media[vid_idx].dir == PJMEDIA_DIR_NONE) { 
     2884            PJ_LOG(3,(THIS_FILE, 
     2885                      "Just rejected incoming video offer on call %d" 
     2886                      "use \"vid call add\" to enable video!", 
     2887                      call_id)); 
     2888        } 
     2889    } 
     2890#endif 
    28492891} 
    28502892 
     
    34233465{ 
    34243466#if PJSUA_HAS_VIDEO 
     3467    pj_bool_t vid_enabled = (app_config.vid.vid_cnt > 0); 
     3468 
    34253469    puts("+=============================================================================+"); 
    34263470    puts("|                            Video commands:                                  |"); 
    34273471    puts("|                                                                             |"); 
    34283472    puts("| vid help                  Show this help screen                             |"); 
     3473    puts("| vid enable|disable        Enable or disable video in next offer/answer      |"); 
    34293474    puts("| vid acc show              Show current account video settings               |"); 
    3430     puts("| vid acc enable|disable    Enable or disable video on current account        |"); 
    34313475    puts("| vid acc autorx on|off     Automatically show incoming video on/off          |"); 
    34323476    puts("| vid acc autotx on|off     Automatically offer video on/off                  |"); 
     
    34363480    puts("| vid call tx on|off N      Enable/disable video tx for stream N in curr call |"); 
    34373481    puts("| vid call add              Add video stream for current call                 |"); 
    3438     puts("| vid call enable/disable N Enable/disable stream #N in current call          |"); 
     3482    puts("| vid call enable|disable N Enable/disable stream #N in current call          |"); 
    34393483    puts("| vid call cap N ID         Set capture dev ID for stream #N in current call  |"); 
    34403484    puts("| vid dev list              List all video devices                            |"); 
     
    34483492    puts("| vid win move ID X Y       Move window ID to position X,Y                    |"); 
    34493493    puts("| vid win resize ID w h     Resize window ID to the specified width, height   |"); 
     3494    puts("+=============================================================================+"); 
     3495    printf("| Video will be %s in the next offer/answer %s                            |\n", 
     3496           (vid_enabled? "enabled" : "disabled"), (vid_enabled? " " : "")); 
    34503497    puts("+=============================================================================+"); 
    34513498#endif 
     
    38643911static void app_config_init_video(pjsua_acc_config *acc_cfg) 
    38653912{ 
    3866     acc_cfg->max_video_cnt = app_config.vid.vid_cnt; 
    38673913    acc_cfg->vid_in_auto_show = app_config.vid.in_auto_show; 
    38683914    acc_cfg->vid_out_auto_transmit = app_config.vid.out_auto_transmit; 
     
    38803926    PJ_LOG(3,(THIS_FILE, 
    38813927              "Account %d:\n" 
    3882               "  Video count:      %d\n" 
    38833928              "  RX auto show:     %d\n" 
    38843929              "  TX auto transmit: %d\n" 
     
    38863931              "  Render dev:       %d", 
    38873932              acc_id, 
    3888               acc_cfg->max_video_cnt, 
    38893933              acc_cfg->vid_in_auto_show, 
    38903934              acc_cfg->vid_out_auto_transmit, 
     
    39073951    if (argc == 1 || strcmp(argv[1], "help")==0) { 
    39083952        vid_show_help(); 
     3953    } else if (argc == 2 && (strcmp(argv[1], "enable")==0 || 
     3954                             strcmp(argv[1], "disable")==0)) 
     3955    { 
     3956        pj_bool_t enabled = (strcmp(argv[1], "enable")==0); 
     3957        app_config.vid.vid_cnt = (enabled ? 1 : 0); 
     3958        PJ_LOG(3,(THIS_FILE, "Video will be %s in next offer/answer", 
     3959                  (enabled?"enabled":"disabled"))); 
    39093960    } else if (strcmp(argv[1], "acc")==0) { 
    39103961        pjsua_acc_config acc_cfg; 
     
    39153966        if (argc == 3 && strcmp(argv[2], "show")==0) { 
    39163967            app_config_show_video(current_acc, &acc_cfg); 
    3917  
    3918         } else if (argc == 3 && (strcmp(argv[2], "enable")==0 || 
    3919                                  strcmp(argv[2], "disable")==0)) 
    3920         { 
    3921             int enabled = (strcmp(argv[2], "enable")==0); 
    3922             acc_cfg.max_video_cnt = (enabled ? 1 : 0); 
    3923             if (enabled) { 
    3924                 app_config_init_video(&acc_cfg); 
    3925                 acc_cfg.max_video_cnt = (enabled ? 1 : 0); 
    3926             } 
    3927             changed = PJ_TRUE; 
    39283968        } else if (argc == 4 && strcmp(argv[2], "autorx")==0) { 
    39293969            int on = (strcmp(argv[3], "on")==0); 
     
    41664206    pjsua_call_info call_info; 
    41674207    pjsua_acc_info acc_info; 
    4168  
     4208    pjsua_call_setting call_opt; 
     4209 
     4210    pjsua_call_setting_default(&call_opt); 
     4211    call_opt.audio_cnt = app_config.aud_cnt; 
     4212    call_opt.video_cnt = app_config.vid.vid_cnt; 
    41694213 
    41704214    /* If user specifies URI to call, then call the URI */ 
    41714215    if (uri_to_call->slen) { 
    4172         pjsua_call_make_call( current_acc, uri_to_call, 0, NULL, NULL, NULL); 
     4216        pjsua_call_make_call( current_acc, uri_to_call, &call_opt, NULL, NULL, NULL); 
    41734217    } 
    41744218 
     
    42054249        } 
    42064250 
     4251        /* Update call setting */ 
     4252        pjsua_call_setting_default(&call_opt); 
     4253        call_opt.audio_cnt = app_config.aud_cnt; 
     4254        call_opt.video_cnt = app_config.vid.vid_cnt; 
     4255 
    42074256        switch (menuin[0]) { 
    42084257 
     
    42344283            pjsua_msg_data_init(&msg_data); 
    42354284            TEST_MULTIPART(&msg_data); 
    4236             pjsua_call_make_call( current_acc, &tmp, 0, NULL, &msg_data, NULL); 
     4285            pjsua_call_make_call( current_acc, &tmp, &call_opt, NULL, &msg_data, NULL); 
    42374286            break; 
    42384287 
     
    42664315                pj_status_t status; 
    42674316             
    4268                 status = pjsua_call_make_call(current_acc, &tmp, 0, NULL, 
     4317                status = pjsua_call_make_call(current_acc, &tmp, &call_opt, NULL, 
    42694318                                              NULL, NULL); 
    42704319                if (status != PJ_SUCCESS) 
     
    44034452                } 
    44044453 
    4405                 pjsua_call_answer(current_call, st_code, NULL, &msg_data); 
     4454                pjsua_call_answer2(current_call, &call_opt, st_code, NULL, &msg_data); 
    44064455            } 
    44074456 
     
    45924641                 * re-INVITE 
    45934642                 */ 
    4594                 pjsua_call_reinvite(current_call, PJ_TRUE, NULL); 
     4643                call_opt.flag |= PJSUA_CALL_UNHOLD; 
     4644                pjsua_call_reinvite2(current_call, &call_opt, NULL); 
    45954645 
    45964646            } else { 
     
    46054655            if (current_call != -1) { 
    46064656                 
    4607                 pjsua_call_update(current_call, 0, NULL); 
     4657                pjsua_call_update2(current_call, &call_opt, NULL); 
    46084658 
    46094659            } else { 
Note: See TracChangeset for help on using the changeset viewer.