예제 #1
0
void MainWin::preview()
{
    if (preview_on) {
	delete video_prev_;
	video_prev_ = NULL;

	pjsua_vid_preview_stop(DEFAULT_CAP_DEV);

	showStatus("Preview stopped");
	previewButton_->setText(tr("Start &Preview"));
    } else {
	pjsua_vid_win_id wid;
	pjsua_vid_win_info wi;
	pjsua_vid_preview_param pre_param;
	pj_status_t status;

	pjsua_vid_preview_param_default(&pre_param);
	pre_param.rend_id = DEFAULT_REND_DEV;
	pre_param.show = PJ_FALSE;

	status = pjsua_vid_preview_start(DEFAULT_CAP_DEV, &pre_param);
	if (status != PJ_SUCCESS) {
	    char errmsg[PJ_ERR_MSG_SIZE];
	    pj_strerror(status, errmsg, sizeof(errmsg));
	    QMessageBox::critical(0, "Error creating preview", errmsg);
	    return;
	}
	wid = pjsua_vid_preview_get_win(DEFAULT_CAP_DEV);
	pjsua_vid_win_get_info(wid, &wi);

	video_prev_ = new VidWin(&wi.hwnd);
        video_prev_->putIntoLayout(vbox_left);
	//Using this will cause SDL window to display blank
	//screen sometimes, probably because it's using different
	//X11 Display
	//status = pjsua_vid_win_set_show(wid, PJ_TRUE);
	//This is handled by VidWin now
	//video_prev_->show_sdl();
	showStatus("Preview started");

	previewButton_->setText(tr("Stop &Preview"));
    }
    preview_on = !preview_on;
}
예제 #2
0
static void vid_handle_menu(char *menuin)
{
    char *argv[8];
    int argc = 0;

    /* Tokenize */
    argv[argc] = strtok(menuin, " \t\r\n");
    while (argv[argc] && *argv[argc]) {
	argc++;
	argv[argc] = strtok(NULL, " \t\r\n");
    }

    if (argc == 1 || strcmp(argv[1], "help")==0) {
	vid_show_help();
    } else if (argc == 2 && (strcmp(argv[1], "enable")==0 ||
			     strcmp(argv[1], "disable")==0))
    {
	pj_bool_t enabled = (strcmp(argv[1], "enable")==0);
	app_config.vid.vid_cnt = (enabled ? 1 : 0);
	PJ_LOG(3,(THIS_FILE, "Video will be %s in next offer/answer",
		  (enabled?"enabled":"disabled")));
    } else if (strcmp(argv[1], "acc")==0) {
	pjsua_acc_config acc_cfg;
	pj_bool_t changed = PJ_FALSE;
	pj_pool_t *tmp_pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);

	pjsua_acc_get_config(current_acc, tmp_pool, &acc_cfg);

	if (argc == 3 && strcmp(argv[2], "show")==0) {
	    app_config_show_video(current_acc, &acc_cfg);
	} else if (argc == 4 && strcmp(argv[2], "autorx")==0) {
	    int on = (strcmp(argv[3], "on")==0);
	    acc_cfg.vid_in_auto_show = on;
	    changed = PJ_TRUE;
	} else if (argc == 4 && strcmp(argv[2], "autotx")==0) {
	    int on = (strcmp(argv[3], "on")==0);
	    acc_cfg.vid_out_auto_transmit = on;
	    changed = PJ_TRUE;
	} else if (argc == 4 && strcmp(argv[2], "cap")==0) {
	    int dev = atoi(argv[3]);
	    acc_cfg.vid_cap_dev = dev;
	    changed = PJ_TRUE;
	} else if (argc == 4 && strcmp(argv[2], "rend")==0) {
	    int dev = atoi(argv[3]);
	    acc_cfg.vid_rend_dev = dev;
	    changed = PJ_TRUE;
	} else {
	    pj_pool_release(tmp_pool);
	    goto on_error;
	}

	if (changed) {
	    pj_status_t status = pjsua_acc_modify(current_acc, &acc_cfg);
	    if (status != PJ_SUCCESS)
		PJ_PERROR(1,(THIS_FILE, status, "Error modifying account %d",
			     current_acc));
	}
	pj_pool_release(tmp_pool);

    } else if (strcmp(argv[1], "call")==0) {
	pjsua_call_vid_strm_op_param param;
	pj_status_t status = PJ_SUCCESS;

	pjsua_call_vid_strm_op_param_default(&param);

	if (argc == 5 && strcmp(argv[2], "rx")==0) {
	    pjsua_stream_info si;
	    pj_bool_t on = (strcmp(argv[3], "on") == 0);

	    param.med_idx = atoi(argv[4]);
	    if (pjsua_call_get_stream_info(current_call, param.med_idx, &si) ||
		si.type != PJMEDIA_TYPE_VIDEO)
	    {
		PJ_PERROR(1,(THIS_FILE, PJ_EINVAL, "Invalid stream"));
		return;
	    }

	    if (on) param.dir = (si.info.vid.dir | PJMEDIA_DIR_DECODING);
	    else param.dir = (si.info.vid.dir & PJMEDIA_DIR_ENCODING);

	    status = pjsua_call_set_vid_strm(current_call,
	                                     PJSUA_CALL_VID_STRM_CHANGE_DIR,
	                                     &param);
	}
	else if (argc == 5 && strcmp(argv[2], "tx")==0) {
	    pj_bool_t on = (strcmp(argv[3], "on") == 0);
	    pjsua_call_vid_strm_op op = on? PJSUA_CALL_VID_STRM_START_TRANSMIT :
					    PJSUA_CALL_VID_STRM_STOP_TRANSMIT;

	    param.med_idx = atoi(argv[4]);

	    status = pjsua_call_set_vid_strm(current_call, op, &param);
	}
	else if (argc == 3 && strcmp(argv[2], "add")==0) {
	    status = pjsua_call_set_vid_strm(current_call,
	                                     PJSUA_CALL_VID_STRM_ADD, NULL);
	}
	else if (argc >= 3 &&
		 (strcmp(argv[2], "disable")==0 || strcmp(argv[2], "enable")==0))
	{
	    pj_bool_t enable = (strcmp(argv[2], "enable") == 0);
	    pjsua_call_vid_strm_op op = enable? PJSUA_CALL_VID_STRM_CHANGE_DIR :
						PJSUA_CALL_VID_STRM_REMOVE;

	    param.med_idx = argc >= 4? atoi(argv[3]) : -1;
	    param.dir = PJMEDIA_DIR_ENCODING_DECODING;
	    status = pjsua_call_set_vid_strm(current_call, op, &param);
	}
	else if (argc >= 3 && strcmp(argv[2], "cap")==0) {
	    param.med_idx = argc >= 4? atoi(argv[3]) : -1;
	    param.cap_dev = argc >= 5? atoi(argv[4]) : PJMEDIA_VID_DEFAULT_CAPTURE_DEV;
	    status = pjsua_call_set_vid_strm(current_call,
	                                     PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV,
	                                     &param);
	} else
	    goto on_error;

	if (status != PJ_SUCCESS) {
	    PJ_PERROR(1,(THIS_FILE, status, "Error modifying video stream"));
	}

    } else if (argc >= 3 && strcmp(argv[1], "dev")==0) {
	if (strcmp(argv[2], "list")==0) {
	    vid_list_devs();
	} else if (strcmp(argv[2], "refresh")==0) {
	    pjmedia_vid_dev_refresh();
	} else if (strcmp(argv[2], "prev")==0) {
	    if (argc != 5) {
		goto on_error;
	    } else {
		pj_bool_t on = (strcmp(argv[3], "on") == 0);
		int dev_id = atoi(argv[4]);
		if (on) {
                    pjsua_vid_preview_param param;

                    pjsua_vid_preview_param_default(&param);
                    param.wnd_flags = PJMEDIA_VID_DEV_WND_BORDER |
                                      PJMEDIA_VID_DEV_WND_RESIZABLE;
		    pjsua_vid_preview_start(dev_id, &param);
		    arrange_window(pjsua_vid_preview_get_win(dev_id));
		} else {
		    pjsua_vid_win_id wid;
		    wid = pjsua_vid_preview_get_win(dev_id);
		    if (wid != PJSUA_INVALID_ID) {
			/* Preview window hiding once it is stopped is
			 * responsibility of app */
			pjsua_vid_win_set_show(wid, PJ_FALSE);
			pjsua_vid_preview_stop(dev_id);
		    }
		}
	    }
	} else
	    goto on_error;
    } else if (strcmp(argv[1], "win")==0) {
	pj_status_t status = PJ_SUCCESS;

	if (argc==3 && strcmp(argv[2], "list")==0) {
	    pjsua_vid_win_id wids[PJSUA_MAX_VID_WINS];
	    unsigned i, cnt = PJ_ARRAY_SIZE(wids);

	    pjsua_vid_enum_wins(wids, &cnt);

	    PJ_LOG(3,(THIS_FILE, "Found %d video windows:", cnt));
	    PJ_LOG(3,(THIS_FILE, "WID show    pos       size"));
	    PJ_LOG(3,(THIS_FILE, "------------------------------"));
	    for (i = 0; i < cnt; ++i) {
		pjsua_vid_win_info wi;
		pjsua_vid_win_get_info(wids[i], &wi);
		PJ_LOG(3,(THIS_FILE, "%3d   %c  (%d,%d)  %dx%d",
			  wids[i], (wi.show?'Y':'N'), wi.pos.x, wi.pos.y,
			  wi.size.w, wi.size.h));
	    }
	} else if (argc==4 && (strcmp(argv[2], "show")==0 ||
			       strcmp(argv[2], "hide")==0))
	{
	    pj_bool_t show = (strcmp(argv[2], "show")==0);
	    pjsua_vid_win_id wid = atoi(argv[3]);
	    status = pjsua_vid_win_set_show(wid, show);
	} else if (argc==6 && strcmp(argv[2], "move")==0) {
	    pjsua_vid_win_id wid = atoi(argv[3]);
	    pjmedia_coord pos;

	    pos.x = atoi(argv[4]);
	    pos.y = atoi(argv[5]);
	    status = pjsua_vid_win_set_pos(wid, &pos);
	} else if (argc==6 && strcmp(argv[2], "resize")==0) {
	    pjsua_vid_win_id wid = atoi(argv[3]);
	    pjmedia_rect_size size;

	    size.w = atoi(argv[4]);
	    size.h = atoi(argv[5]);
	    status = pjsua_vid_win_set_size(wid, &size);
	} else if (argc==3 && strcmp(argv[2], "arrange")==0) {
	    arrange_window(PJSUA_INVALID_ID);
	} else
	    goto on_error;

	if (status != PJ_SUCCESS) {
	    PJ_PERROR(1,(THIS_FILE, status, "Window operation error"));
	}

    } else if (strcmp(argv[1], "codec")==0) {
	pjsua_codec_info ci[PJMEDIA_CODEC_MGR_MAX_CODECS];
	unsigned count = PJ_ARRAY_SIZE(ci);
	pj_status_t status;

	if (argc==3 && strcmp(argv[2], "list")==0) {
	    status = pjsua_vid_enum_codecs(ci, &count);
	    if (status != PJ_SUCCESS) {
		PJ_PERROR(1,(THIS_FILE, status, "Error enumerating codecs"));
	    } else {
		unsigned i;
		PJ_LOG(3,(THIS_FILE, "Found %d video codecs:", count));
		PJ_LOG(3,(THIS_FILE, "codec id      prio  fps    bw(kbps)   size"));
		PJ_LOG(3,(THIS_FILE, "------------------------------------------"));
		for (i=0; i<count; ++i) {
		    pjmedia_vid_codec_param cp;
		    pjmedia_video_format_detail *vfd;

		    status = pjsua_vid_codec_get_param(&ci[i].codec_id, &cp);
		    if (status != PJ_SUCCESS)
			continue;

		    vfd = pjmedia_format_get_video_format_detail(&cp.enc_fmt,
								 PJ_TRUE);
		    PJ_LOG(3,(THIS_FILE, "%.*s%.*s %3d %7.2f  %4d/%4d  %dx%d",
			      (int)ci[i].codec_id.slen, ci[i].codec_id.ptr,
			      13-(int)ci[i].codec_id.slen, "                ",
			      ci[i].priority,
			      (vfd->fps.num*1.0/vfd->fps.denum),
			      vfd->avg_bps/1000, vfd->max_bps/1000,
			      vfd->size.w, vfd->size.h));
		}
	    }
	} else if (argc==5 && strcmp(argv[2], "prio")==0) {
	    pj_str_t cid;
	    int prio;
	    cid = pj_str(argv[3]);
	    prio = atoi(argv[4]);
	    status = pjsua_vid_codec_set_priority(&cid, (pj_uint8_t)prio);
	    if (status != PJ_SUCCESS)
		PJ_PERROR(1,(THIS_FILE, status, "Set codec priority error"));
	} else if (argc==6 && strcmp(argv[2], "fps")==0) {
	    pjmedia_vid_codec_param cp;
	    pj_str_t cid;
	    int M, N;
	    cid = pj_str(argv[3]);
	    M = atoi(argv[4]);
	    N = atoi(argv[5]);
	    status = pjsua_vid_codec_get_param(&cid, &cp);
	    if (status == PJ_SUCCESS) {
		cp.enc_fmt.det.vid.fps.num = M;
		cp.enc_fmt.det.vid.fps.denum = N;
		status = pjsua_vid_codec_set_param(&cid, &cp);
	    }
	    if (status != PJ_SUCCESS)
		PJ_PERROR(1,(THIS_FILE, status, "Set codec framerate error"));
	} else if (argc==6 && strcmp(argv[2], "bw")==0) {
	    pjmedia_vid_codec_param cp;
	    pj_str_t cid;
	    int M, N;
	    cid = pj_str(argv[3]);
	    M = atoi(argv[4]);
	    N = atoi(argv[5]);
	    status = pjsua_vid_codec_get_param(&cid, &cp);
	    if (status == PJ_SUCCESS) {
		cp.enc_fmt.det.vid.avg_bps = M * 1000;
		cp.enc_fmt.det.vid.max_bps = N * 1000;
		status = pjsua_vid_codec_set_param(&cid, &cp);
	    }
	    if (status != PJ_SUCCESS)
		PJ_PERROR(1,(THIS_FILE, status, "Set codec bitrate error"));
	} else if (argc==6 && strcmp(argv[2], "size")==0) {
	    pjmedia_vid_codec_param cp;
	    pj_str_t cid;
	    int M, N;
	    cid = pj_str(argv[3]);
	    M = atoi(argv[4]);
	    N = atoi(argv[5]);
	    status = pjsua_vid_codec_get_param(&cid, &cp);
	    if (status == PJ_SUCCESS) {
		cp.enc_fmt.det.vid.size.w = M;
		cp.enc_fmt.det.vid.size.h = N;
		status = pjsua_vid_codec_set_param(&cid, &cp);
	    }
	    if (status != PJ_SUCCESS)
		PJ_PERROR(1,(THIS_FILE, status, "Set codec size error"));
	} else
	    goto on_error;
    } else
	goto on_error;

    return;

on_error:
    PJ_LOG(1,(THIS_FILE, "Invalid command, use 'vid help'"));
}