- Timestamp:
- Dec 10, 2010 11:04:30 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/conf_switch.c
r2725 r3392 24 24 #include <pjmedia/silencedet.h> 25 25 #include <pjmedia/sound_port.h> 26 #include <pjmedia/stream.h>27 26 #include <pj/array.h> 28 27 #include <pj/assert.h> 29 28 #include <pj/log.h> 29 #include <pj/math.h> 30 30 #include <pj/pool.h> 31 31 #include <pj/string.h> … … 81 81 /* Shortcut for port info. */ 82 82 pjmedia_port_info *info; 83 unsigned samples_per_frame; 83 84 84 85 /* Calculated signal levels: */ … … 124 125 /* Prototypes */ 125 126 static pj_status_t put_frame(pjmedia_port *this_port, 126 constpjmedia_frame *frame);127 pjmedia_frame *frame); 127 128 static pj_status_t get_frame(pjmedia_port *this_port, 128 129 pjmedia_frame *frame); … … 167 168 conf_port->port = port; 168 169 conf_port->info = &port->info; 170 conf_port->samples_per_frame= PJMEDIA_PINFO_SAMPLES_PER_FRAME(&port->info); 169 171 170 172 /* Init pjmedia_frame structure in the TX buffer. */ … … 505 507 struct conf_port *src_port, *dst_port; 506 508 pj_bool_t start_sound = PJ_FALSE; 509 pjmedia_audio_format_detail *src_afd, *dst_afd; 507 510 unsigned i; 508 511 … … 524 527 } 525 528 529 src_afd = pjmedia_format_get_audio_format_detail(&src_port->info->fmt, 1); 530 dst_afd = pjmedia_format_get_audio_format_detail(&dst_port->info->fmt, 1); 531 526 532 /* Format must match. */ 527 if (src_port->info->f ormat.id != dst_port->info->format.id ||528 src_ port->info->format.bitrate != dst_port->info->format.bitrate)533 if (src_port->info->fmt.id != dst_port->info->fmt.id || 534 src_afd->avg_bps != dst_afd->avg_bps) 529 535 { 530 536 pj_mutex_unlock(conf->mutex); … … 533 539 534 540 /* Clock rate must match. */ 535 if (src_ port->info->clock_rate != dst_port->info->clock_rate) {541 if (src_afd->clock_rate != dst_afd->clock_rate) { 536 542 pj_mutex_unlock(conf->mutex); 537 543 return PJMEDIA_ENCCLOCKRATE; … … 539 545 540 546 /* Channel count must match. */ 541 if (src_ port->info->channel_count != dst_port->info->channel_count) {547 if (src_afd->channel_count != dst_afd->channel_count) { 542 548 pj_mutex_unlock(conf->mutex); 543 549 return PJMEDIA_ENCCLOCKRATE; … … 545 551 546 552 /* Source and sink ptime must be equal or a multiplication factor. */ 547 if ((src_port->info->samples_per_frame % 548 dst_port->info->samples_per_frame != 0) && 549 (dst_port->info->samples_per_frame % 550 src_port->info->samples_per_frame != 0)) 553 if ((src_afd->frame_time_usec % dst_afd->frame_time_usec != 0) && 554 (dst_afd->frame_time_usec % src_afd->frame_time_usec != 0)) 551 555 { 552 556 pj_mutex_unlock(conf->mutex); … … 830 834 { 831 835 struct conf_port *conf_port; 836 const pjmedia_audio_format_detail *afd; 832 837 833 838 /* Check arguments */ … … 843 848 return PJ_EINVAL; 844 849 } 850 851 afd = pjmedia_format_get_audio_format_detail(&conf_port->info->fmt, 1); 845 852 846 853 pj_bzero(info, sizeof(pjmedia_conf_port_info)); … … 853 860 info->listener_slots = conf_port->listener_slots; 854 861 info->transmitter_cnt = conf_port->transmitter_cnt; 855 info->clock_rate = conf_port->info->clock_rate;856 info->channel_count = conf_port->info->channel_count;857 info->samples_per_frame = conf_port-> info->samples_per_frame;858 info->bits_per_sample = conf_port->info->bits_per_sample;859 info->format = conf_port->port->info.f ormat;862 info->clock_rate = afd->clock_rate; 863 info->channel_count = afd->channel_count; 864 info->samples_per_frame = conf_port->samples_per_frame; 865 info->bits_per_sample = afd->bits_per_sample; 866 info->format = conf_port->port->info.fmt; 860 867 info->tx_adj_level = conf_port->tx_adj_level - NORMAL_LEVEL; 861 868 info->rx_adj_level = conf_port->rx_adj_level - NORMAL_LEVEL; … … 961 968 962 969 /* Level adjustment is applicable only for ports that work with raw PCM. */ 963 PJ_ASSERT_RETURN(conf_port->info->f ormat.id == PJMEDIA_FORMAT_L16,970 PJ_ASSERT_RETURN(conf_port->info->fmt.id == PJMEDIA_FORMAT_L16, 964 971 PJ_EIGNORED); 965 972 … … 1003 1010 1004 1011 /* Level adjustment is applicable only for ports that work with raw PCM. */ 1005 PJ_ASSERT_RETURN(conf_port->info->f ormat.id == PJMEDIA_FORMAT_L16,1012 PJ_ASSERT_RETURN(conf_port->info->fmt.id == PJMEDIA_FORMAT_L16, 1006 1013 PJ_EIGNORED); 1007 1014 … … 1047 1054 * samples per frame. 1048 1055 */ 1049 if (f_dst->samples_cnt >= cport_dst-> info->samples_per_frame)1056 if (f_dst->samples_cnt >= cport_dst->samples_per_frame) 1050 1057 { 1051 1058 if (cport_dst->slot) { … … 1059 1066 1060 1067 /* Update TX timestamp. */ 1061 pj_add_timestamp32(&cport_dst->ts_tx, 1062 cport_dst-> info->samples_per_frame);1068 pj_add_timestamp32(&cport_dst->ts_tx, 1069 cport_dst->samples_per_frame); 1063 1070 } 1064 1071 } … … 1076 1083 /* Copy frame to listener's TX buffer. */ 1077 1084 nsamples_to_copy = f_end - f_start; 1078 nsamples_req = cport_dst-> info->samples_per_frame -1085 nsamples_req = cport_dst->samples_per_frame - 1079 1086 (frm_dst->size>>1); 1080 1087 if (nsamples_to_copy > nsamples_req) … … 1113 1120 * samples per frame. 1114 1121 */ 1115 if ((frm_dst->size >> 1) == cport_dst-> info->samples_per_frame)1122 if ((frm_dst->size >> 1) == cport_dst->samples_per_frame) 1116 1123 { 1117 1124 if (cport_dst->slot) { … … 1124 1131 /* Update TX timestamp. */ 1125 1132 pj_add_timestamp32(&cport_dst->ts_tx, 1126 cport_dst-> info->samples_per_frame);1133 cport_dst->samples_per_frame); 1127 1134 } 1128 1135 } … … 1132 1139 /* Check port format. */ 1133 1140 if (cport_dst->port && 1134 cport_dst->port->info.f ormat.id == PJMEDIA_FORMAT_L16)1141 cport_dst->port->info.fmt.id == PJMEDIA_FORMAT_L16) 1135 1142 { 1136 1143 /* When there is already some samples in listener's TX buffer, … … 1139 1146 if (frm_dst->size != 0) { 1140 1147 pjmedia_zero_samples((pj_int16_t*)frm_dst->buf, 1141 cport_dst-> info->samples_per_frame -1148 cport_dst->samples_per_frame - 1142 1149 (frm_dst->size>>1)); 1143 1150 1144 1151 frm_dst->type = PJMEDIA_FRAME_TYPE_AUDIO; 1145 frm_dst->size = cport_dst-> info->samples_per_frame << 1;1152 frm_dst->size = cport_dst->samples_per_frame << 1; 1146 1153 if (cport_dst->slot) { 1147 1154 pjmedia_port_put_frame(cport_dst->port, frm_dst); … … 1153 1160 /* Update TX timestamp. */ 1154 1161 pj_add_timestamp32(&cport_dst->ts_tx, 1155 cport_dst-> info->samples_per_frame);1162 cport_dst->samples_per_frame); 1156 1163 } 1157 1164 } else { … … 1161 1168 frm_dst->type = PJMEDIA_FRAME_TYPE_EXTENDED; 1162 1169 pjmedia_frame_ext_append_subframe(f_dst, NULL, 0, (pj_uint16_t) 1163 (cport_dst-> info->samples_per_frame - f_dst->samples_cnt));1170 (cport_dst->samples_per_frame - f_dst->samples_cnt)); 1164 1171 if (cport_dst->slot) { 1165 1172 pjmedia_port_put_frame(cport_dst->port, frm_dst); … … 1172 1179 /* Update TX timestamp. */ 1173 1180 pj_add_timestamp32(&cport_dst->ts_tx, 1174 cport_dst-> info->samples_per_frame);1181 cport_dst->samples_per_frame); 1175 1182 } 1176 1183 } … … 1186 1193 1187 1194 /* Update TX timestamp. */ 1188 pj_add_timestamp32(&cport_dst->ts_tx, cport_dst-> info->samples_per_frame);1195 pj_add_timestamp32(&cport_dst->ts_tx, cport_dst->samples_per_frame); 1189 1196 } 1190 1197 } … … 1212 1219 for (i=1, ci=1; i<conf->max_ports && ci<conf->port_cnt; ++i) { 1213 1220 struct conf_port *cport = conf->ports[i]; 1221 unsigned master_samples_per_frame; 1214 1222 1215 1223 /* Skip empty port. */ … … 1220 1228 ++ci; 1221 1229 1230 master_samples_per_frame = PJMEDIA_PINFO_SAMPLES_PER_FRAME( 1231 &conf->master_port->info); 1232 1222 1233 /* Update clock of the port. */ 1223 pj_add_timestamp32(&cport->ts_clock, 1224 conf->master_port->info.samples_per_frame); 1234 pj_add_timestamp32(&cport->ts_clock, master_samples_per_frame); 1225 1235 1226 1236 /* Skip if we're not allowed to receive from this port or … … 1231 1241 { 1232 1242 cport->rx_level = 0; 1233 pj_add_timestamp32(&cport->ts_rx, 1234 conf->master_port->info.samples_per_frame); 1243 pj_add_timestamp32(&cport->ts_rx, master_samples_per_frame); 1235 1244 continue; 1236 1245 } … … 1246 1255 pj_int32_t level = 0; 1247 1256 1248 pj_add_timestamp32(&cport->ts_rx, cport-> info->samples_per_frame);1257 pj_add_timestamp32(&cport->ts_rx, cport->samples_per_frame); 1249 1258 1250 1259 f->buf = &conf->buf[sizeof(pjmedia_frame)]; 1251 f->size = cport-> info->samples_per_frame<<1;1260 f->size = cport->samples_per_frame<<1; 1252 1261 1253 1262 /* Get frame from port. */ … … 1303 1312 if (listener->tx_setting == PJMEDIA_PORT_DISABLE) { 1304 1313 pj_add_timestamp32(&listener->ts_tx, 1305 listener-> info->samples_per_frame);1314 listener->samples_per_frame); 1306 1315 listener->tx_level = 0; 1307 1316 continue; … … 1362 1371 1363 1372 pjmedia_port_put_frame(cport->port, &tmp_f); 1364 pj_add_timestamp32(&cport->ts_tx, cport-> info->samples_per_frame);1373 pj_add_timestamp32(&cport->ts_tx, cport->samples_per_frame); 1365 1374 } 1366 1375 } … … 1381 1390 unsigned samples_per_subframe; 1382 1391 1383 if (f_src_->samples_cnt < this_cport-> info->samples_per_frame) {1392 if (f_src_->samples_cnt < this_cport->samples_per_frame) { 1384 1393 f_dst->base.type = PJMEDIA_FRAME_TYPE_NONE; 1385 1394 f_dst->samples_cnt = 0; … … 1394 1403 1395 1404 1396 while (f_dst->samples_cnt < this_cport-> info->samples_per_frame) {1405 while (f_dst->samples_cnt < this_cport->samples_per_frame) { 1397 1406 sf = pjmedia_frame_ext_get_subframe(f_src_, i++); 1398 1407 pj_assert(sf); … … 1405 1414 1406 1415 } else if (f_src->type == PJMEDIA_FRAME_TYPE_AUDIO) { 1407 if ((f_src->size>>1) < this_cport-> info->samples_per_frame) {1416 if ((f_src->size>>1) < this_cport->samples_per_frame) { 1408 1417 frame->type = PJMEDIA_FRAME_TYPE_NONE; 1409 1418 frame->size = 0; … … 1413 1422 pjmedia_copy_samples((pj_int16_t*)frame->buf, 1414 1423 (pj_int16_t*)f_src->buf, 1415 this_cport-> info->samples_per_frame);1416 frame->size = this_cport-> info->samples_per_frame << 1;1424 this_cport->samples_per_frame); 1425 frame->size = this_cport->samples_per_frame << 1; 1417 1426 1418 1427 /* Shift left TX buffer. */ … … 1421 1430 pjmedia_move_samples((pj_int16_t*)f_src->buf, 1422 1431 (pj_int16_t*)f_src->buf + 1423 this_cport-> info->samples_per_frame,1432 this_cport->samples_per_frame, 1424 1433 f_src->size >> 1); 1425 1434 } else { /* PJMEDIA_FRAME_TYPE_NONE */ … … 1443 1452 */ 1444 1453 static pj_status_t put_frame(pjmedia_port *this_port, 1445 constpjmedia_frame *f)1454 pjmedia_frame *f) 1446 1455 { 1447 1456 pjmedia_conf *conf = (pjmedia_conf*) this_port->port_data.pdata; … … 1461 1470 } 1462 1471 1463 pj_add_timestamp32(&cport->ts_rx, cport-> info->samples_per_frame);1472 pj_add_timestamp32(&cport->ts_rx, cport->samples_per_frame); 1464 1473 1465 1474 /* Skip if this port is muted/disabled. */ … … 1527 1536 if (listener->tx_setting == PJMEDIA_PORT_DISABLE) { 1528 1537 pj_add_timestamp32(&listener->ts_tx, 1529 listener-> info->samples_per_frame);1538 listener->samples_per_frame); 1530 1539 listener->tx_level = 0; 1531 1540 continue; … … 1535 1544 if (listener == cport) { 1536 1545 pj_add_timestamp32(&listener->ts_tx, 1537 listener-> info->samples_per_frame);1546 listener->samples_per_frame); 1538 1547 listener->tx_level = 0; 1539 1548 continue;
Note: See TracChangeset
for help on using the changeset viewer.