コード例 #1
0
ファイル: screenphone.cpp プロジェクト: lmedeiros/softphone
void ScreenPhone::setNetworkRates()
{
    if(this->active_channel() == 1 && this->m_c1_call_id >= 0 && this->m_c1_state != "available")
    {
        static char c1_buffer[1024*1];
        pjsua_call_dump(this->m_c1_call_id, PJ_TRUE, c1_buffer, sizeof(c1_buffer), "  ");

        pjsua_call_info cinfo;
        pjsua_call_get_info(this->m_c1_call_id, &cinfo);

        if(!controller->telApi->has_srtp)
        {
            pjsua_stream_info stat;
            pjsua_call_get_stream_info(this->m_c1_call_id, cinfo.media[0].index, &stat);

            QString codec(stat.info.aud.fmt.encoding_name.ptr);
            codec = codec.mid(0,codec.indexOf("strm")).remove(QRegExp("[^a-zA-Z\\d\\s]"));

            pjsua_stream_stat stream_stat;
            pjsua_call_get_stream_stat(this->m_c1_call_id, cinfo.media[0].index, &stream_stat);

            this->m_c1_latency = QString::number(stream_stat.rtcp.rtt.last/1000);
            this->setC1_stream_info(codec.append("(").append(this->m_c1_latency).append(" ms) ").append(controller->telApi->m_transport.toUpper()));
        }
        else
        {
            this->setC1_stream_info("SRTP Encrypted Call");
        }

        QStringList qbuff = QString(c1_buffer).split("\n");

        //qDebug() << "RTT ::::: " << QString::number(stream_stat.rtcp.rtt.last);
        qDebug() << "RTT ::::: " << QString(c1_buffer);

        this->setC1_downrate(qbuff[5].mid(qbuff[5].indexOf("@avg=")+5).split('/')[1]);
        this->setC1_uprate(qbuff[11].mid(qbuff[11].indexOf("@avg=")+5).split('/')[1]);

        this->setC1_loss(qbuff[6].mid(qbuff[6].indexOf("loss=")+5).split(',')[0]);

        memset(&c1_buffer[0], 0, sizeof(c1_buffer));

        return;
    }

    if(this->active_channel() == 2 && this->m_c2_call_id >= 0 && this->m_c2_state != "available")
    {
        static char c2_buffer[1024*1];
        pjsua_call_dump(this->m_c2_call_id, PJ_TRUE, c2_buffer, sizeof(c2_buffer), "  ");

        pjsua_call_info cinfo;
        pjsua_call_get_info(this->m_c2_call_id, &cinfo);

        if(!controller->telApi->has_srtp)
        {
            pjsua_stream_info stat;
            pjsua_call_get_stream_info(this->m_c2_call_id, cinfo.media[0].index, &stat);

            QString codec(stat.info.aud.fmt.encoding_name.ptr);
            codec = codec.mid(0,codec.indexOf("strm")).remove(QRegExp("[^a-zA-Z\\d\\s]"));

            pjsua_stream_stat stream_stat;
            pjsua_call_get_stream_stat(this->m_c2_call_id, cinfo.media[0].index, &stream_stat);

            this->m_c2_latency = QString::number(stream_stat.rtcp.rtt.last/1000);
            this->setC2_stream_info(codec.append("(").append(this->m_c2_latency).append(" ms) ").append(controller->telApi->m_transport.toUpper()));
        }
        else
        {
            this->setC1_stream_info("SRTP Encrypted Call");
        }

        QStringList qbuff = QString(c2_buffer).split("\n");
        this->setC2_downrate(qbuff[5].mid(qbuff[5].indexOf("@avg=")+5).split('/')[1]);
        this->setC2_uprate(qbuff[11].mid(qbuff[11].indexOf("@avg=")+5).split('/')[1]);

        this->setC2_loss(qbuff[6].mid(qbuff[6].indexOf("loss=")+5).split(',')[0]);

        memset(&c2_buffer[0], 0, sizeof(c2_buffer));

        return;
    }

    this->m_c1_latency = "0";
    this->m_c2_latency = "0";

    this->setC1_downrate("0");
    this->setC1_uprate("0");
    this->setC2_downrate("0");
    this->setC2_uprate("0");
}
コード例 #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'"));
}
コード例 #3
0
ファイル: screenphone.cpp プロジェクト: lmedeiros/softphone
void ScreenPhone::register_call(pjsua_call_id call_id, const QString &account_id)
{
    pjsua_call_info call_info;
    pjsua_call_get_info(call_id, &call_info);

    QString tx = "0";
    QString rx = "0";
    QString local_loss = "0";
    QString remote_loss = "0";
    QString codec = "N/A";

    QString callDuration = QString::number(call_info.connect_duration.sec);

    if(callDuration.toInt() > 0)
    {
        pjsua_stream_stat stream_stat;
        pjsua_call_get_stream_stat(call_id, call_info.media[0].index, &stream_stat);

        pjsua_stream_info stream_info;
        pjsua_call_get_stream_info(call_id, call_info.media[0].index, &stream_info);

        codec = (stream_info.info.aud.fmt.encoding_name.ptr);
        codec = codec.mid(0,codec.indexOf("strm")).remove(QRegExp("[^a-zA-Z\\d\\s]"));
        tx = QString::number(stream_stat.rtcp.rx.bytes);
        rx = QString::number(stream_stat.rtcp.tx.bytes);
        local_loss = QString::number(stream_stat.rtcp.rx.loss);
        remote_loss = QString::number(stream_stat.rtcp.tx.loss);
    }

    QString linfo = QString(call_info.local_info.ptr);

    QString cinfo = QString(call_info.remote_info.ptr);
    cinfo = cinfo.mid(0, cinfo.indexOf("@"));
    cinfo = cinfo.mid(cinfo.indexOf(":")+1);

    QString callerId = QString(call_info.remote_info.ptr).mid(0, QString(call_info.remote_info.ptr).indexOf("<")).replace("\"","");
    callerId = callerId.mid(0, callerId.indexOf("@"));
    callerId = callerId.mid(callerId.indexOf(":")+1);

    QString callType;

    QStringList callContactInfo = this->getContact(cinfo);

    if(call_info.role==0)
    {
        callType = "OUT";
        if(call_info.connect_duration.sec==0)
        {
            callType = "FAIL";
        }
    }
    else if(call_info.role==1)
    {
        callType = "IN";
        if(call_info.connect_duration.sec==0)
        {
            this->setMiss_notify(true);
            callType = "MISS";
        }
    }

    if(!controller->screenLog->insertLog(linfo, cinfo, callType, QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"), callDuration, account_id, ((callContactInfo[5]==0) ? callerId : callContactInfo[0]) , callContactInfo[4], callContactInfo[2], rx, tx, "N/A", local_loss, remote_loss, codec, callContactInfo[5], callContactInfo[6])) qDebug() << "Error when register the call";
}