Ignore:
Timestamp:
Oct 25, 2011 9:35:11 AM (13 years ago)
Author:
bennylp
Message:

Re #1400: enhancements to video operations in pjsua application

File:
1 edited

Legend:

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

    r3841 r3850  
    5353}; 
    5454 
     55/* Video settings */ 
     56struct app_vid 
     57{ 
     58    unsigned                vid_cnt; 
     59    int                     vcapture_dev; 
     60    int                     vrender_dev; 
     61    pj_bool_t               in_auto_show; 
     62    pj_bool_t               out_auto_transmit; 
     63}; 
    5564 
    5665/* Pjsua application data */ 
     
    125134    pjmedia_port           *ring_port; 
    126135 
    127     int                     vcapture_dev, vrender_dev; 
     136    struct app_vid          vid; 
    128137} app_config; 
    129138 
     
    392401        pjsua_buddy_config_default(&cfg->buddy_cfg[i]); 
    393402 
    394     cfg->vcapture_dev = PJSUA_INVALID_ID; 
    395     cfg->vrender_dev = PJSUA_INVALID_ID; 
     403    cfg->vid.vcapture_dev = PJMEDIA_VID_DEFAULT_CAPTURE_DEV; 
     404    cfg->vid.vrender_dev = PJMEDIA_VID_DEFAULT_RENDER_DEV; 
    396405} 
    397406 
     
    13891398 
    13901399        case OPT_CAPTURE_DEV: 
    1391             cfg->capture_dev = atoi(pj_optarg); 
     1400            cfg->vid.vcapture_dev = atoi(pj_optarg); 
    13921401            break; 
    13931402 
    13941403        case OPT_PLAYBACK_DEV: 
    1395             cfg->playback_dev = atoi(pj_optarg); 
     1404            cfg->vid.vrender_dev = atoi(pj_optarg); 
    13961405            break; 
    13971406 
     
    14471456            break; 
    14481457        case OPT_VIDEO: 
    1449             ++cur_acc->max_video_cnt; 
    1450             cur_acc->vid_in_auto_show = PJ_TRUE; 
    1451             cur_acc->vid_out_auto_transmit = PJ_TRUE; 
    1452             PJ_TODO(implement_pjsua_option_for_vid_auto_show_and_transmit); 
     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; 
    14531461            break; 
    14541462        case OPT_EXTRA_AUDIO: 
     
    14571465 
    14581466        case OPT_VCAPTURE_DEV: 
    1459             cfg->vcapture_dev = atoi(pj_optarg); 
    1460             cur_acc->vid_cap_dev = cfg->vcapture_dev; 
     1467            cfg->vid.vcapture_dev = atoi(pj_optarg); 
     1468            cur_acc->vid_cap_dev = cfg->vid.vcapture_dev; 
    14611469            break; 
    14621470 
    14631471        case OPT_VRENDER_DEV: 
    1464             cfg->vrender_dev = atoi(pj_optarg); 
    1465             cur_acc->vid_rend_dev = cfg->vrender_dev; 
     1472            cfg->vid.vrender_dev = atoi(pj_optarg); 
     1473            cur_acc->vid_rend_dev = cfg->vid.vrender_dev; 
    14661474            break; 
    14671475 
     
    20422050    } 
    20432051 
    2044     if (config->vcapture_dev != PJSUA_INVALID_ID) { 
    2045         pj_ansi_sprintf(line, "--vcapture-dev %d\n", config->vcapture_dev); 
     2052    if (config->vid.vcapture_dev != PJMEDIA_VID_DEFAULT_CAPTURE_DEV) { 
     2053        pj_ansi_sprintf(line, "--vcapture-dev %d\n", config->vid.vcapture_dev); 
    20462054        pj_strcat2(&cfg, line); 
    20472055    } 
    2048     if (config->vrender_dev != PJSUA_INVALID_ID) { 
    2049         pj_ansi_sprintf(line, "--vrender-dev %d\n", config->vrender_dev); 
     2056    if (config->vid.vrender_dev != PJMEDIA_VID_DEFAULT_RENDER_DEV) { 
     2057        pj_ansi_sprintf(line, "--vrender-dev %d\n", config->vid.vrender_dev); 
    20502058        pj_strcat2(&cfg, line); 
    20512059    } 
     
    34193427    puts("|                                                                             |"); 
    34203428    puts("| vid help                  Show this help screen                             |"); 
     3429    puts("| vid acc show              Show current account video settings               |"); 
     3430    puts("| vid acc enable|disable    Enable or disable video on current account        |"); 
     3431    puts("| vid acc autorx on|off     Automatically show incoming video on/off          |"); 
     3432    puts("| vid acc autotx on|off     Automatically offer video on/off                  |"); 
     3433    puts("| vid acc cap ID            Set default capture device for current acc        |"); 
     3434    puts("| vid acc rend ID           Set default renderer device for current acc       |"); 
    34213435    puts("| vid call rx on|off N      Enable/disable video rx for stream N in curr call |"); 
    34223436    puts("| vid call tx on|off N      Enable/disable video tx for stream N in curr call |"); 
     
    38483862} 
    38493863 
     3864static void app_config_init_video(pjsua_acc_config *acc_cfg) 
     3865{ 
     3866    acc_cfg->max_video_cnt = app_config.vid.vid_cnt; 
     3867    acc_cfg->vid_in_auto_show = app_config.vid.in_auto_show; 
     3868    acc_cfg->vid_out_auto_transmit = app_config.vid.out_auto_transmit; 
     3869    acc_cfg->vid_cap_dev = app_config.vid.vcapture_dev; 
     3870    acc_cfg->vid_rend_dev = app_config.vid.vrender_dev; 
     3871} 
     3872 
     3873static void app_config_show_video(int acc_id, const pjsua_acc_config *acc_cfg) 
     3874{ 
     3875    PJ_LOG(3,(THIS_FILE, 
     3876              "Account %d:\n" 
     3877              "  Video count:      %d\n" 
     3878              "  RX auto show:     %d\n" 
     3879              "  TX auto transmit: %d\n" 
     3880              "  Capture dev:      %d\n" 
     3881              "  Render dev:       %d", 
     3882              acc_id, 
     3883              acc_cfg->max_video_cnt, 
     3884              acc_cfg->vid_in_auto_show, 
     3885              acc_cfg->vid_out_auto_transmit, 
     3886              acc_cfg->vid_cap_dev, 
     3887              acc_cfg->vid_rend_dev)); 
     3888} 
     3889 
    38503890static void vid_handle_menu(char *menuin) 
    38513891{ 
     
    38623902    if (argc == 1 || strcmp(argv[1], "help")==0) { 
    38633903        vid_show_help(); 
     3904    } else if (strcmp(argv[1], "acc")==0) { 
     3905        pjsua_acc_config acc_cfg; 
     3906        pj_bool_t changed = PJ_FALSE; 
     3907 
     3908        pjsua_acc_get_config(current_acc, &acc_cfg); 
     3909 
     3910        if (argc == 3 && strcmp(argv[2], "show")==0) { 
     3911            app_config_show_video(current_acc, &acc_cfg); 
     3912 
     3913        } else if (argc == 3 && (strcmp(argv[2], "enable")==0 || 
     3914                                 strcmp(argv[2], "disable")==0)) 
     3915        { 
     3916            int enabled = (strcmp(argv[2], "enable")==0); 
     3917            acc_cfg.max_video_cnt = (enabled ? 1 : 0); 
     3918            if (enabled) { 
     3919                app_config_init_video(&acc_cfg); 
     3920                acc_cfg.max_video_cnt = (enabled ? 1 : 0); 
     3921            } 
     3922            changed = PJ_TRUE; 
     3923        } else if (argc == 4 && strcmp(argv[2], "autorx")==0) { 
     3924            int on = (strcmp(argv[3], "on")==0); 
     3925            acc_cfg.vid_in_auto_show = on; 
     3926            changed = PJ_TRUE; 
     3927        } else if (argc == 4 && strcmp(argv[2], "autotx")==0) { 
     3928            int on = (strcmp(argv[3], "on")==0); 
     3929            acc_cfg.vid_out_auto_transmit = on; 
     3930            changed = PJ_TRUE; 
     3931        } else if (argc == 4 && strcmp(argv[2], "cap")==0) { 
     3932            int dev = atoi(argv[3]); 
     3933            acc_cfg.vid_cap_dev = dev; 
     3934            changed = PJ_TRUE; 
     3935        } else if (argc == 4 && strcmp(argv[2], "rend")==0) { 
     3936            int dev = atoi(argv[3]); 
     3937            acc_cfg.vid_rend_dev = dev; 
     3938            changed = PJ_TRUE; 
     3939        } else { 
     3940            goto on_error; 
     3941        } 
     3942 
     3943        if (changed) { 
     3944            pj_status_t status = pjsua_acc_modify(current_acc, &acc_cfg); 
     3945            if (status != PJ_SUCCESS) 
     3946                PJ_PERROR(1,(THIS_FILE, status, "Error modifying account %d", 
     3947                             current_acc)); 
     3948        } 
     3949 
    38643950    } else if (strcmp(argv[1], "call")==0) { 
    38653951        pjsua_call_vid_strm_op_param param; 
     3952        pj_status_t status = PJ_SUCCESS; 
    38663953 
    38673954        pjsua_call_vid_strm_op_param_default(&param); 
     
    38823969            else param.dir = (si.info.vid.dir & PJMEDIA_DIR_ENCODING); 
    38833970 
    3884             pjsua_call_set_vid_strm(current_call, PJSUA_CALL_VID_STRM_CHANGE_DIR, &param); 
     3971            status = pjsua_call_set_vid_strm(current_call, 
     3972                                             PJSUA_CALL_VID_STRM_CHANGE_DIR, 
     3973                                             &param); 
    38853974        } 
    38863975        else if (argc == 5 && strcmp(argv[2], "tx")==0) { 
     
    38913980            param.med_idx = atoi(argv[4]); 
    38923981 
    3893             pjsua_call_set_vid_strm(current_call, op, &param); 
     3982            status = pjsua_call_set_vid_strm(current_call, op, &param); 
    38943983        } 
    38953984        else if (argc == 3 && strcmp(argv[2], "add")==0) { 
    3896             pjsua_call_set_vid_strm(current_call, PJSUA_CALL_VID_STRM_ADD, NULL); 
     3985            status = pjsua_call_set_vid_strm(current_call, 
     3986                                             PJSUA_CALL_VID_STRM_ADD, NULL); 
    38973987        } 
    38983988        else if (argc >= 3 &&  
     
    39053995            param.med_idx = argc >= 4? atoi(argv[3]) : -1; 
    39063996            param.dir = PJMEDIA_DIR_ENCODING_DECODING; 
    3907             pjsua_call_set_vid_strm(current_call, op, &param); 
     3997            status = pjsua_call_set_vid_strm(current_call, op, &param); 
    39083998        } 
    39093999        else if (argc >= 3 && strcmp(argv[2], "cap")==0) { 
    39104000            param.med_idx = argc >= 4? atoi(argv[3]) : -1; 
    39114001            param.cap_dev = argc >= 5? atoi(argv[4]) : PJMEDIA_VID_DEFAULT_CAPTURE_DEV; 
    3912             pjsua_call_set_vid_strm(current_call, PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV, &param); 
     4002            status = pjsua_call_set_vid_strm(current_call, 
     4003                                             PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV, 
     4004                                             &param); 
    39134005        } else 
    39144006            goto on_error; 
     4007 
     4008        if (status != PJ_SUCCESS) { 
     4009            PJ_PERROR(1,(THIS_FILE, status, "Error modifying video stream")); 
     4010        } 
     4011 
    39154012    } else if (argc >= 3 && strcmp(argv[1], "dev")==0) { 
    39164013        if (strcmp(argv[2], "list")==0) { 
     
    39414038            goto on_error; 
    39424039    } else if (strcmp(argv[1], "win")==0) { 
     4040        pj_status_t status = PJ_SUCCESS; 
     4041 
    39434042        if (argc==3 && strcmp(argv[2], "list")==0) { 
    39444043            pjsua_vid_win_id wids[PJSUA_MAX_VID_WINS]; 
     
    39624061            pj_bool_t show = (strcmp(argv[2], "show")==0); 
    39634062            pjsua_vid_win_id wid = atoi(argv[3]); 
    3964             pjsua_vid_win_set_show(wid, show); 
     4063            status = pjsua_vid_win_set_show(wid, show); 
    39654064        } else if (argc==6 && strcmp(argv[2], "move")==0) { 
    39664065            pjsua_vid_win_id wid = atoi(argv[3]); 
     
    39694068            pos.x = atoi(argv[4]); 
    39704069            pos.y = atoi(argv[5]); 
    3971             pjsua_vid_win_set_pos(wid, &pos); 
     4070            status = pjsua_vid_win_set_pos(wid, &pos); 
    39724071        } else if (argc==6 && strcmp(argv[2], "resize")==0) { 
    39734072            pjsua_vid_win_id wid = atoi(argv[3]); 
     
    39764075            size.w = atoi(argv[4]); 
    39774076            size.h = atoi(argv[5]); 
    3978             pjsua_vid_win_set_size(wid, &size); 
     4077            status = pjsua_vid_win_set_size(wid, &size); 
    39794078        } else if (strcmp(argv[2], "arrange")==0) { 
    39804079            arrange_window(PJSUA_INVALID_ID); 
    39814080        } else 
    39824081            goto on_error; 
     4082 
     4083        if (status != PJ_SUCCESS) { 
     4084            PJ_PERROR(1,(THIS_FILE, status, "Window operation error")); 
     4085        } 
     4086 
    39834087    } else if (strcmp(argv[1], "codec")==0) { 
    39844088        pjmedia_vid_codec_info ci[PJMEDIA_CODEC_MGR_MAX_CODECS]; 
     
    54215525        /* Add local account */ 
    54225526        pjsua_acc_add_local(transport_id, PJ_TRUE, &aid); 
     5527        if (PJMEDIA_HAS_VIDEO) { 
     5528            pjsua_acc_config acc_cfg; 
     5529            pjsua_acc_get_config(aid, &acc_cfg); 
     5530            app_config_init_video(&acc_cfg); 
     5531            pjsua_acc_modify(aid, &acc_cfg); 
     5532        } 
    54235533        //pjsua_acc_set_transport(aid, transport_id); 
    54245534        pjsua_acc_set_online_status(current_acc, PJ_TRUE); 
     
    54545564        /* Add local account */ 
    54555565        pjsua_acc_add_local(transport_id, PJ_TRUE, &aid); 
     5566        if (PJMEDIA_HAS_VIDEO) { 
     5567            pjsua_acc_config acc_cfg; 
     5568            pjsua_acc_get_config(aid, &acc_cfg); 
     5569            app_config_init_video(&acc_cfg); 
     5570            pjsua_acc_modify(aid, &acc_cfg); 
     5571        } 
    54565572        //pjsua_acc_set_transport(aid, transport_id); 
    54575573        pjsua_acc_set_online_status(current_acc, PJ_TRUE); 
     
    55805696            goto on_error; 
    55815697    } 
    5582  
    5583 #if PJSUA_HAS_VIDEO 
    5584     if (app_config.vcapture_dev != PJSUA_INVALID_ID || 
    5585         app_config.vrender_dev  != PJSUA_INVALID_ID)  
    5586     { 
    5587         //status = pjsua_vid_set_dev(app_config.vcapture_dev, 
    5588         //                         app_config.vrender_dev); 
    5589         PJ_TODO(vid_implement_pjsua_vid_set_dev); 
    5590         if (status != PJ_SUCCESS) 
    5591             goto on_error; 
    5592     } 
    5593 #endif 
    55945698 
    55955699    return PJ_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.