- Timestamp:
- Jul 15, 2011 7:41:02 AM (13 years ago)
- Location:
- pjproject/branches/projects/2.0-dev
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjsip-apps/src/pjsua/pjsua_app.c
r3652 r3657 3324 3324 puts("| |"); 3325 3325 puts("| vid help Show this help screen |"); 3326 puts("| vid call rx on|off Enable/disable incoming video for current call|");3327 puts("| vid call tx on|off Enable/disable video tx for current call|");3326 puts("| vid call rx on|off N Enable/disable video rx for stream N in curr call |"); 3327 puts("| vid call tx on|off N Enable/disable video tx for stream N in curr call |"); 3328 3328 puts("| vid call add Add video stream for current call |"); 3329 puts("| vid call enable/disable N Enable/disable stream #N for current call|");3330 puts("| vid call set-cap N ID Set capture dev ID for stream #N for current call|");3329 puts("| vid call enable/disable N Enable/disable stream #N in current call |"); 3330 puts("| vid call set-cap N ID Set capture dev ID for stream #N in current call |"); 3331 3331 puts("| vid dev list List all video devices |"); 3332 3332 puts("| vid dev refresh Refresh video device list |"); … … 3769 3769 pjsua_call_vid_strm_op_param param; 3770 3770 3771 if (argc == 4 && strcmp(argv[2], "rx")==0) { 3771 if (argc == 5 && strcmp(argv[2], "rx")==0) { 3772 pjsua_stream_info si; 3772 3773 pj_bool_t on = (strcmp(argv[3], "on") == 0); 3773 PJ_TODO(vid_enable_disable_video_RX_on_call); 3774 PJ_LOG(1,(THIS_FILE, "Not implemented")); 3774 3775 param.med_idx = atoi(argv[4]); 3776 if (pjsua_call_get_stream_info(current_call, param.med_idx, &si) || 3777 si.type != PJMEDIA_TYPE_VIDEO) 3778 { 3779 PJ_PERROR(1,(THIS_FILE, PJ_EINVAL, "Invalid stream")); 3780 return; 3781 } 3782 3783 if (on) param.dir = (si.info.vid.dir | PJMEDIA_DIR_DECODING); 3784 else param.dir = (si.info.vid.dir & PJMEDIA_DIR_ENCODING); 3785 3786 pjsua_call_set_vid_strm(current_call, PJSUA_CALL_VID_STRM_CHANGE_DIR, ¶m); 3775 3787 } 3776 else if (argc == 4&& strcmp(argv[2], "tx")==0) {3788 else if (argc == 5 && strcmp(argv[2], "tx")==0) { 3777 3789 pj_bool_t on = (strcmp(argv[3], "on") == 0); 3778 3790 pjsua_call_vid_strm_op op = on? PJSUA_CALL_VID_STRM_START_TRANSMIT : 3779 3791 PJSUA_CALL_VID_STRM_STOP_TRANSMIT; 3780 pjsua_call_set_vid_strm(current_call, op, NULL); 3792 3793 param.med_idx = atoi(argv[4]); 3794 3795 pjsua_call_set_vid_strm(current_call, op, ¶m); 3781 3796 } 3782 3797 else if (argc == 3 && strcmp(argv[2], "add")==0) { 3783 3798 pjsua_call_set_vid_strm(current_call, PJSUA_CALL_VID_STRM_ADD, NULL); 3784 3799 } 3785 else if (argc == 4&&3800 else if (argc >= 3 && 3786 3801 (strcmp(argv[2], "disable")==0 || strcmp(argv[2], "enable")==0)) 3787 3802 { 3788 3803 pj_bool_t enable = (strcmp(argv[2], "enable") == 0); 3789 pjsua_call_vid_strm_op op = enable? PJSUA_CALL_VID_STRM_ENABLE : 3790 PJSUA_CALL_VID_STRM_DISABLE; 3804 pjsua_call_vid_strm_op op = enable? PJSUA_CALL_VID_STRM_CHANGE_DIR : 3805 PJSUA_CALL_VID_STRM_REMOVE; 3806 3791 3807 param.med_idx = argc >= 4? atoi(argv[3]) : -1; 3808 param.dir = PJMEDIA_DIR_ENCODING_DECODING; 3792 3809 pjsua_call_set_vid_strm(current_call, op, ¶m); 3793 3810 } 3794 else if (argc == 5&& strcmp(argv[2], "set-cap")==0) {3811 else if (argc >= 3 && strcmp(argv[2], "set-cap")==0) { 3795 3812 param.med_idx = argc >= 4? atoi(argv[3]) : -1; 3796 3813 param.cap_dev = argc >= 5? atoi(argv[4]) : PJMEDIA_VID_DEFAULT_CAPTURE_DEV; … … 3798 3815 } else 3799 3816 goto on_error; 3800 } else if ( strcmp(argv[1], "dev")==0) {3817 } else if (argc >= 3 && strcmp(argv[1], "dev")==0) { 3801 3818 if (strcmp(argv[2], "list")==0) { 3802 3819 vid_list_devs(); -
pjproject/branches/projects/2.0-dev/pjsip/include/pjsua-lib/pjsua.h
r3652 r3657 382 382 383 383 /** 384 * Disable/remove an existing video stream.385 */ 386 PJSUA_CALL_VID_STRM_ DISABLE,387 388 /** 389 * Enablevideo stream.390 */ 391 PJSUA_CALL_VID_STRM_ ENABLE,392 393 /** 394 * Chang ingcapture device of a video stream.384 * Remove/disable an existing video stream. 385 */ 386 PJSUA_CALL_VID_STRM_REMOVE, 387 388 /** 389 * Change direction of a video stream. 390 */ 391 PJSUA_CALL_VID_STRM_CHANGE_DIR, 392 393 /** 394 * Change capture device of a video stream. 395 395 */ 396 396 PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV, … … 421 421 * This field is valid for all video stream operations, except 422 422 * PJSUA_CALL_VID_STRM_ADD. 423 * 424 * Default: -1 (first active video stream, or any first video stream 425 * if none is active) 423 426 */ 424 427 int med_idx; 428 429 /** 430 * Specify the media stream direction. 431 * 432 * This field is valid for the following video stream operations: 433 * PJSUA_CALL_VID_STRM_ADD and PJSUA_CALL_VID_STRM_CHANGE_DIR. 434 * 435 * Default: PJMEDIA_DIR_ENCODING_DECODING 436 */ 437 pjmedia_dir dir; 425 438 426 439 /** … … 430 443 * 431 444 * This field is valid for the following video stream operations: 432 * PJSUA_CALL_VID_STRM_ADD, PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV, and 433 * PJSUA_CALL_VID_STRM_START_TRANSMIT. 445 * PJSUA_CALL_VID_STRM_ADD and PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV. 446 * 447 * Default: capture device configured in account. 434 448 */ 435 449 pjmedia_vid_dev_index cap_dev; … … 3773 3787 * @param op The video stream operation to be performed, 3774 3788 * possible values are #pjsua_call_vid_strm_op. 3775 * @param param The parameters for the video stream operation. 3789 * @param param The parameters for the video stream operation, 3790 * or NULL for the default parameter values 3791 * (see #pjsua_call_vid_strm_op_param). 3776 3792 * 3777 3793 * @return PJ_SUCCESS on success or the appropriate error. -
pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_vid.c
r3656 r3657 777 777 pjmedia_event_unsubscribe(&call_med->esub_cap); 778 778 779 if (call_med->strm.v.cap_win_id != PJSUA_INVALID_ID) { 779 if (call_med->dir & PJMEDIA_DIR_ENCODING && 780 call_med->strm.v.cap_win_id != PJSUA_INVALID_ID) 781 { 780 782 pjmedia_port *media_port; 781 783 pjsua_vid_win *w = … … 794 796 } 795 797 796 if (call_med->strm.v.rdr_win_id != PJSUA_INVALID_ID) { 798 if (call_med->dir & PJMEDIA_DIR_DECODING && 799 call_med->strm.v.rdr_win_id != PJSUA_INVALID_ID) 800 { 797 801 dec_vid_win(call_med->strm.v.rdr_win_id); 798 802 } … … 1137 1141 /* Add a new video stream into a call */ 1138 1142 static pj_status_t call_add_video(pjsua_call *call, 1139 pjmedia_vid_dev_index cap_dev) 1143 pjmedia_vid_dev_index cap_dev, 1144 pjmedia_dir dir) 1140 1145 { 1141 1146 pj_pool_t *pool = call->inv->pool_prov; … … 1193 1198 sdp->media[sdp->media_count++] = sdp_m; 1194 1199 1200 /* Update media direction, if it is not 'sendrecv' */ 1201 if (dir != PJMEDIA_DIR_ENCODING_DECODING) { 1202 pjmedia_sdp_attr *a; 1203 1204 /* Remove sendrecv direction attribute, if any */ 1205 pjmedia_sdp_media_remove_all_attr(sdp_m, "sendrecv"); 1206 1207 if (dir == PJMEDIA_DIR_ENCODING) 1208 a = pjmedia_sdp_attr_create(pool, "sendonly", NULL); 1209 else if (dir == PJMEDIA_DIR_DECODING) 1210 a = pjmedia_sdp_attr_create(pool, "recvonly", NULL); 1211 else 1212 a = pjmedia_sdp_attr_create(pool, "inactive", NULL); 1213 1214 pjmedia_sdp_media_add_attr(sdp_m, a); 1215 } 1216 1195 1217 /* Update SDP media line by media transport */ 1196 1218 status = pjmedia_transport_encode_sdp(call_med->tp, pool, … … 1215 1237 1216 1238 1217 /* Modify a video stream from a call, i.e: enable/disable */ 1239 /* Modify a video stream from a call, i.e: update direction, 1240 * remove/disable. 1241 */ 1218 1242 static pj_status_t call_modify_video(pjsua_call *call, 1219 1243 int med_idx, 1220 pj_bool_t enable) 1244 pjmedia_dir dir, 1245 pj_bool_t remove) 1221 1246 { 1222 1247 pjsua_call_media *call_med; … … 1241 1266 return PJ_EINVAL; 1242 1267 1243 /* Verify if the stream already enabled/disabled */ 1244 if (( enable && call_med->dir != PJMEDIA_DIR_NONE) || 1245 (!enable && call_med->dir == PJMEDIA_DIR_NONE)) 1268 /* Verify if the stream dir is not changed */ 1269 if ((!remove && call_med->dir == dir) || 1270 ( remove && (call_med->tp_st == PJSUA_MED_TP_DISABLED || 1271 call_med->tp == NULL))) 1272 { 1246 1273 return PJ_SUCCESS; 1274 } 1247 1275 1248 1276 /* Get active local SDP */ … … 1253 1281 pj_assert(med_idx < (int)sdp->media_count); 1254 1282 1255 if ( enable) {1283 if (!remove) { 1256 1284 pjsua_acc_config *acc_cfg = &pjsua_var.acc[call->acc_id].cfg; 1257 1285 pj_pool_t *pool = call->inv->pool_prov; 1258 1286 pjmedia_sdp_media *sdp_m; 1259 pjmedia_transport_info tpinfo;1260 1287 1261 1288 status = pjsua_call_media_init(call_med, PJMEDIA_TYPE_VIDEO, … … 1266 1293 1267 1294 /* Init transport media */ 1268 status = pjmedia_transport_media_create(call_med->tp, pool, 0, 1269 NULL, call_med->idx); 1270 if (status != PJ_SUCCESS) 1271 goto on_error; 1272 1273 /* Get transport address info */ 1274 pjmedia_transport_info_init(&tpinfo); 1275 pjmedia_transport_get_info(call_med->tp, &tpinfo); 1276 1277 /* Create SDP media line */ 1278 status = pjmedia_endpt_create_video_sdp(pjsua_var.med_endpt, pool, 1279 &tpinfo.sock_info, 0, &sdp_m); 1280 if (status != PJ_SUCCESS) 1281 goto on_error; 1295 if (call_med->tp && call_med->tp_st == PJSUA_MED_TP_IDLE) { 1296 status = pjmedia_transport_media_create(call_med->tp, pool, 0, 1297 NULL, call_med->idx); 1298 if (status != PJ_SUCCESS) 1299 goto on_error; 1300 } 1301 1302 sdp_m = sdp->media[med_idx]; 1303 1304 /* Create new SDP media line if the stream is disabled */ 1305 if (sdp->media[med_idx]->desc.port == 0) { 1306 pjmedia_transport_info tpinfo; 1307 1308 /* Get transport address info */ 1309 pjmedia_transport_info_init(&tpinfo); 1310 pjmedia_transport_get_info(call_med->tp, &tpinfo); 1311 1312 status = pjmedia_endpt_create_video_sdp(pjsua_var.med_endpt, pool, 1313 &tpinfo.sock_info, 0, &sdp_m); 1314 if (status != PJ_SUCCESS) 1315 goto on_error; 1316 } 1317 1318 { 1319 pjmedia_sdp_attr *a; 1320 1321 /* Remove any direction attributes */ 1322 pjmedia_sdp_media_remove_all_attr(sdp_m, "sendrecv"); 1323 pjmedia_sdp_media_remove_all_attr(sdp_m, "sendonly"); 1324 pjmedia_sdp_media_remove_all_attr(sdp_m, "recvonly"); 1325 pjmedia_sdp_media_remove_all_attr(sdp_m, "inactive"); 1326 1327 /* Update media direction */ 1328 if (dir == PJMEDIA_DIR_ENCODING_DECODING) 1329 a = pjmedia_sdp_attr_create(pool, "sendrecv", NULL); 1330 else if (dir == PJMEDIA_DIR_ENCODING) 1331 a = pjmedia_sdp_attr_create(pool, "sendonly", NULL); 1332 else if (dir == PJMEDIA_DIR_DECODING) 1333 a = pjmedia_sdp_attr_create(pool, "recvonly", NULL); 1334 else 1335 a = pjmedia_sdp_attr_create(pool, "inactive", NULL); 1336 1337 pjmedia_sdp_media_add_attr(sdp_m, a); 1338 } 1282 1339 1283 1340 sdp->media[med_idx] = sdp_m; … … 1291 1348 on_error: 1292 1349 if (status != PJ_SUCCESS) { 1293 if (call_med->tp) {1294 pjmedia_transport_close(call_med->tp);1295 call_med->tp = call_med->tp_orig = NULL;1296 }1297 1350 return status; 1298 1351 } 1352 1299 1353 } else { 1354 1355 pj_pool_t *pool = call->inv->pool_prov; 1356 1300 1357 /* Mark media transport to disabled */ 1301 1358 // Don't close this here, as SDP negotiation has not been … … 1303 1360 call_med->tp_st = PJSUA_MED_TP_DISABLED; 1304 1361 1305 /* Disable the stream in SDP by setting port to 0 */ 1306 sdp->media[med_idx]->desc.port = 0; 1362 /* Deactivate the stream */ 1363 pjmedia_sdp_media_deactivate(pool, sdp->media[med_idx]); 1364 1307 1365 } 1308 1366 … … 1445 1503 1446 1504 1447 /* Start transmitting video stream in a call */1448 static pj_status_t call_s tart_tx_video(pjsua_call *call,1449 1450 pjmedia_vid_dev_index cap_dev)1505 /* Start/stop transmitting video stream in a call */ 1506 static pj_status_t call_set_tx_video(pjsua_call *call, 1507 int med_idx, 1508 pj_bool_t enable) 1451 1509 { 1452 1510 pjsua_call_media *call_med; … … 1468 1526 /* Verify if the stream is transmitting video */ 1469 1527 if (call_med->type != PJMEDIA_TYPE_VIDEO || 1470 ( call_med->dir & PJMEDIA_DIR_ENCODING) == 0)1528 (enable && (call_med->dir & PJMEDIA_DIR_ENCODING) == 0)) 1471 1529 { 1472 1530 return PJ_EINVAL; 1473 1531 } 1474 1532 1475 /* Apply the capture device, it may be changed! */ 1476 status = call_change_cap_dev(call, med_idx, cap_dev); 1477 if (status != PJ_SUCCESS) 1478 return status; 1479 1480 /* Start stream in encoding direction */ 1481 status = pjmedia_vid_stream_resume(call_med->strm.v.stream, 1482 PJMEDIA_DIR_ENCODING); 1483 if (status != PJ_SUCCESS) 1484 return status; 1485 1486 return PJ_SUCCESS; 1487 } 1488 1489 1490 /* Stop transmitting video stream in a call */ 1491 static pj_status_t call_stop_tx_video(pjsua_call *call, 1492 int med_idx) 1493 { 1494 pjsua_call_media *call_med; 1495 pj_status_t status; 1496 1497 /* Verify and normalize media index */ 1498 if (med_idx == -1) { 1499 int first_active; 1500 1501 call_get_vid_strm_info(call, &first_active, NULL, NULL, NULL); 1502 if (first_active == -1) 1503 return PJ_ENOTFOUND; 1504 1505 med_idx = first_active; 1506 } 1507 1508 call_med = &call->media[med_idx]; 1509 1510 /* Verify if the stream is transmitting video */ 1511 if (call_med->type != PJMEDIA_TYPE_VIDEO || 1512 (call_med->dir & PJMEDIA_DIR_ENCODING) == 0) 1513 { 1514 return PJ_EINVAL; 1515 } 1516 1517 /* Pause stream in encoding direction */ 1518 status = pjmedia_vid_stream_pause( call_med->strm.v.stream, 1519 PJMEDIA_DIR_ENCODING); 1520 if (status != PJ_SUCCESS) 1521 return status; 1522 1523 return PJ_SUCCESS; 1533 if (enable) { 1534 /* Start stream in encoding direction */ 1535 status = pjmedia_vid_stream_resume(call_med->strm.v.stream, 1536 PJMEDIA_DIR_ENCODING); 1537 } else { 1538 /* Pause stream in encoding direction */ 1539 status = pjmedia_vid_stream_pause( call_med->strm.v.stream, 1540 PJMEDIA_DIR_ENCODING); 1541 } 1542 1543 return status; 1524 1544 } 1525 1545 … … 1549 1569 param_.med_idx = -1; 1550 1570 param_.cap_dev = PJMEDIA_VID_DEFAULT_CAPTURE_DEV; 1571 param_.dir = PJMEDIA_DIR_ENCODING_DECODING; 1551 1572 } 1552 1573 … … 1572 1593 switch (op) { 1573 1594 case PJSUA_CALL_VID_STRM_ADD: 1574 status = call_add_video(call, param_.cap_dev );1595 status = call_add_video(call, param_.cap_dev, param_.dir); 1575 1596 break; 1576 case PJSUA_CALL_VID_STRM_ENABLE: 1577 status = call_modify_video(call, param_.med_idx, PJ_TRUE); 1597 case PJSUA_CALL_VID_STRM_REMOVE: 1598 status = call_modify_video(call, param_.med_idx, PJMEDIA_DIR_NONE, 1599 PJ_TRUE); 1578 1600 break; 1579 case PJSUA_CALL_VID_STRM_ DISABLE:1580 status = call_modify_video(call, param_.med_idx, PJ_FALSE);1601 case PJSUA_CALL_VID_STRM_CHANGE_DIR: 1602 status = call_modify_video(call, param_.med_idx, param_.dir, PJ_FALSE); 1581 1603 break; 1582 1604 case PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV: … … 1584 1606 break; 1585 1607 case PJSUA_CALL_VID_STRM_START_TRANSMIT: 1586 status = call_s tart_tx_video(call, param_.med_idx, param_.cap_dev);1608 status = call_set_tx_video(call, param_.med_idx, PJ_TRUE); 1587 1609 break; 1588 1610 case PJSUA_CALL_VID_STRM_STOP_TRANSMIT: 1589 status = call_s top_tx_video(call, param_.med_idx);1611 status = call_set_tx_video(call, param_.med_idx, PJ_FALSE); 1590 1612 break; 1591 1613 default:
Note: See TracChangeset
for help on using the changeset viewer.